Skip to content

Commit 3b227ba

Browse files
committed
fix(sdk-ts): address review feedback
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 73235b6 commit 3b227ba

20 files changed

Lines changed: 727 additions & 91 deletions

‎.agents/skills/test-release-canary/SKILL.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ does not contribute to product usage metrics.
2323

2424
`install.sh` defaults to the *latest tagged* release — the canary is therefore checking that the most recent public release still installs, not the just-published `dev` build. The `kubernetes` job is the exception: it pins to `0.0.0-dev` chart + `:dev` images.
2525

26+
The canary does not install or import `@nvidia/openshell-sdk`. TypeScript SDK
27+
validation lives in the `TypeScript SDK` branch check, including a publish
28+
dry-run. The tagged release workflow publishes the package to GitHub Packages;
29+
verify that job directly when diagnosing SDK publication failures.
30+
2631
## Trigger paths
2732

2833
The workflow has two triggers:

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pip-delete-this-directory.txt
6565

6666
# Unit test / coverage reports
6767
coverage.out
68+
coverage/
6869
htmlcov/
6970
.tox/
7071
.nox/

‎AGENTS.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ These pipelines connect skills into end-to-end workflows. Individual skill files
5656
| `crates/openshell-supervisor-process/` | Process supervisor | Process lifecycle, namespace, and bypass monitoring |
5757
| `crates/openshell-vfio/` | VFIO support | PCI and GPU passthrough preparation and lifecycle |
5858
| `python/openshell/` | Python SDK | Python bindings and CLI packaging |
59+
| `sdk/typescript/` | TypeScript SDK | Native Connect client, curated sandbox API, and generated protobuf types |
5960
| `proto/` | Protobuf definitions | gRPC service contracts |
6061
| `deploy/` | Docker, Helm, K8s | Dockerfiles, Helm chart, manifests |
6162
| `docs/` | Published docs | MDX pages, navigation, and content assets |
@@ -213,6 +214,14 @@ ocsf_emit!(event);
213214
- Converters in `sdk/go/openshell/v1/internal/converter/` deep-copy slices and maps at boundaries.
214215
- Tests use bufconn for in-process gRPC and testify for assertions.
215216

217+
## TypeScript SDK (`sdk/typescript/`)
218+
219+
- Run `mise run sdk:ts:ci` for codegen, proto lint, Biome lint, type checking, unit tests, coverage, and build validation.
220+
- Proto bindings are generated with `mise run sdk:ts:proto` from the files selected in `sdk/typescript/buf.gen.yaml`.
221+
- Generated files under `sdk/typescript/src/gen/` are build outputs and must not be committed.
222+
- Keep the curated API free of generated wire types; expose full generated messages and RPCs through `@nvidia/openshell-sdk/raw`.
223+
- The release workflow publishes the package to GitHub Packages. Branch checks exercise the publish path with `npm publish --dry-run`.
224+
216225
## Python
217226

218227
- Always use `uv` for Python commands (e.g., `uv pip install`, `uv run`, `uv venv`)

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ Bazel does not yet cover `mise run gateway`, `mise run sandbox`, `mise run e2e`,
451451
| `crates/` | Rust crates |
452452
| `python/` | Python SDK and bindings |
453453
| `sdk/go/` | Go SDK (types, gRPC clients, converters) |
454+
| `sdk/typescript/` | TypeScript SDK (Connect client and generated protobuf bindings) |
454455
| `proto/` | Protocol buffer definitions |
455456
| `tasks/` | `mise` task definitions and build scripts |
456457
| `deploy/` | Dockerfiles, Helm chart, Kubernetes manifests |

‎architecture/build.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ OpenShell builds these main artifacts:
1212
|---|---|
1313
| Gateway binary | `crates/openshell-server` |
1414
| CLI package and Python SDK | `python/openshell` plus Rust binaries where packaged |
15+
| TypeScript SDK package | `sdk/typescript` |
1516
| Gateway container image | `deploy/docker/Dockerfile.gateway` |
1617
| Supervisor container image | `deploy/docker/Dockerfile.supervisor` |
1718
| Helm chart | `deploy/helm/openshell` |
@@ -213,6 +214,20 @@ pins them back in with `[tool.maturin].include` globs. The release workflows
213214
install each Linux wheel in a clean image and import `openshell.sandbox` as a
214215
smoke check.
215216

217+
## TypeScript SDK Packaging
218+
219+
The native TypeScript SDK in `sdk/typescript` uses Connect over the generated
220+
OpenShell protobuf surface. `sdk/typescript/buf.gen.yaml` selects the client
221+
proto closure, and `mise run sdk:ts:proto` generates gitignored sources under
222+
`src/gen`. TypeScript compilation includes those sources in `dist`, so package
223+
consumers do not run code generation.
224+
225+
Branch checks run `mise run sdk:ts:ci`, enforce an 80% line-coverage floor, and
226+
exercise version stamping plus `npm publish --dry-run`. Tagged releases publish
227+
`@nvidia/openshell-sdk` to GitHub Packages. The repository keeps package version
228+
`0.0.0`; the release task derives and temporarily stamps the npm version from
229+
the release tag.
230+
216231
## CI and E2E
217232

218233
Required checks run on GitHub Actions. Workflows that use NVIDIA self-hosted runners trigger from copy-pr-bot mirror branches, so trusted PRs are mirrored into `pull-request/<N>` branches before those workflows run. `main` also uses GitHub merge queue so the final queued integration commit is validated before it merges.

‎docs/index.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ navigation:
2525
title: "Observability"
2626
- folder: kubernetes
2727
title: "Kubernetes"
28+
- section: "SDKs"
29+
slug: sdks
30+
contents:
31+
- page: "TypeScript SDK"
32+
path: sdks/typescript.mdx
2833
- folder: reference
2934
title: "Reference"
3035
- folder: security

‎docs/sdks/typescript.mdx‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
title: "TypeScript SDK"
5+
description: "Install and use the native TypeScript SDK for sandbox lifecycle, exec, SSH sessions, and port forwarding."
6+
keywords: "NVIDIA OpenShell, TypeScript SDK, Node.js, Connect, sandbox"
7+
---
8+
9+
The native TypeScript SDK connects Node.js applications to an OpenShell
10+
gateway. It requires Node.js 20.3 or later.
11+
12+
Use the SDK and gateway from the same OpenShell release when possible. The raw
13+
types and RPC descriptors are generated from the protobuf definitions shipped
14+
with that release; curated methods remain compatible while their underlying
15+
RPC contracts remain compatible.
16+
17+
## Install the package
18+
19+
The pre-GA package is published through GitHub Packages. Configure the NVIDIA
20+
scope in your project-level `.npmrc`:
21+
22+
```text
23+
@nvidia:registry=https://npm.pkg.github.com
24+
```
25+
26+
Authenticate npm with a GitHub token that has `read:packages`, then install the
27+
SDK:
28+
29+
```shell
30+
npm install @nvidia/openshell-sdk
31+
```
32+
33+
## Connect to a gateway
34+
35+
Create a client with the gateway URL and its authentication material:
36+
37+
```typescript
38+
import { OpenShellClient } from "@nvidia/openshell-sdk";
39+
40+
const client = await OpenShellClient.connect({
41+
gateway: "https://gateway.example.com",
42+
oidcToken: process.env.OPENSHELL_TOKEN,
43+
});
44+
45+
const health = await client.health();
46+
console.log(health.status);
47+
```
48+
49+
`connect()` constructs a lazy client and does not issue a network request. Call
50+
`health()` when startup must verify gateway connectivity.
51+
52+
Choose one authentication mode:
53+
54+
- Set `clientCert` and `clientKey` together for mTLS. Use `caCert` to add a
55+
gateway CA certificate.
56+
- Set `oidcToken` for direct OIDC bearer authentication.
57+
- Set `edgeToken` for Cloudflare Access header authentication.
58+
59+
Tokens are static for the lifetime of a client. Create a new client when a
60+
token refreshes. The SDK refuses to send a token over plaintext HTTP to a
61+
non-loopback host unless `allowInsecureAuth` is set explicitly.
62+
63+
## Manage and execute in sandboxes
64+
65+
Use `client.sandbox` for lifecycle and exec operations:
66+
67+
```typescript
68+
const sandbox = await client.sandbox.create({
69+
image: "ghcr.io/nvidia/openshell-community/sandboxes/python:latest",
70+
});
71+
72+
await client.sandbox.waitReady(sandbox.name, 120);
73+
74+
const result = await client.sandbox.exec(sandbox.name, [
75+
"/bin/sh",
76+
"-c",
77+
"python --version",
78+
]);
79+
process.stdout.write(result.stdout);
80+
81+
await client.sandbox.delete(sandbox.name);
82+
await client.sandbox.waitDeleted(sandbox.name, 30);
83+
```
84+
85+
Pass an `AbortSignal` to wait, exec, interactive exec, and forward operations
86+
when the caller needs cancellation. `execStream()` yields stdout and stderr
87+
chunks followed by an in-band exit event. `execInteractive()` exposes raw
88+
stdin, resize, output, and completion primitives without taking ownership of
89+
terminal raw mode or signal forwarding.
90+
91+
## Forward a sandbox service
92+
93+
`forward()` creates a process-lifetime local TCP listener. Close the returned
94+
handle during application teardown:
95+
96+
```typescript
97+
const forward = await client.sandbox.forward(sandbox.name, {
98+
targetPort: 8000,
99+
onConnectionError: (error) => console.error(error),
100+
});
101+
102+
console.log(`http://${forward.localHost}:${forward.localPort}`);
103+
104+
await forward.close();
105+
await forward.closed;
106+
```
107+
108+
Calling `close()` more than once is safe. It cancels active forwarding RPCs,
109+
closes accepted sockets, and waits for their cleanup. The root client has no
110+
explicit close method because the Connect transport does not retain a dedicated
111+
session; close operation-scoped streams and forward handles instead.
112+
113+
## Use the raw gateway surface
114+
115+
Curated helpers cover sandbox lifecycle, exec, forwarding, SSH sessions,
116+
sandbox provider attachments, settings, and policy updates. Use `client.raw`
117+
for gateway RPCs that do not yet have a curated helper, and import their
118+
generated types from the raw entry point:
119+
120+
```typescript
121+
import type { GetGatewayConfigResponse } from "@nvidia/openshell-sdk/raw";
122+
123+
const config: GetGatewayConfigResponse = await client.raw.getGatewayConfig({});
124+
```
125+
126+
The raw entry point exposes generated wire types. Prefer curated helpers when
127+
they cover the operation because those helpers preserve the SDK error taxonomy
128+
and normalize protobuf values for TypeScript callers.

‎sdk/typescript/README.md‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ TypeScript client for the OpenShell gateway — thin, idiomatic bindings generat
44

55
Distributed via GitHub Packages. A public npm release under the same name follows once the npm org is in place; the install specifier and API are unchanged across that move.
66

7+
Use the SDK and gateway from the same OpenShell release when possible. The raw
8+
types and RPC descriptors are generated from the protobuf definitions in that
9+
release; curated methods remain compatible while those RPC contracts remain
10+
compatible.
11+
712
## Install
813

914
Published to GitHub Packages, so point the `@nvidia` scope at it with a project `.npmrc`:
@@ -39,6 +44,12 @@ console.log(result.stdout.toString())
3944
await client.sandbox.delete(sandbox.name)
4045
```
4146

47+
`connect()` constructs a lazy client; call `health()` when startup must verify
48+
gateway reachability. Authentication material is static for the client's
49+
lifetime, so create a new client after refreshing an OIDC or edge token. The
50+
root client has no explicit close method because Connect does not retain a
51+
dedicated session. Close operation-scoped streams and forward handles instead.
52+
4253
Express the create-time safety boundary with `policy`. Sandbox-scoped `setPolicy`
4354
cannot introduce static policy fields later, so set filesystem, landlock,
4455
process, and initial network policy at creation. For proto spec fields the
@@ -93,11 +104,17 @@ const code = await session.done
93104
`forward` binds a local TCP listener and tunnels each accepted connection into the sandbox for the lifetime of the Node process. Call `close()` on teardown.
94105

95106
```ts
96-
const fwd = await client.sandbox.forward(name, { targetPort: 8000 })
107+
const fwd = await client.sandbox.forward(name, {
108+
targetPort: 8000,
109+
onConnectionError: (error) => console.error(error),
110+
})
97111
// ... reach the sandbox service at 127.0.0.1:fwd.localPort ...
98112
await fwd.close()
99113
```
100114

115+
`close()` is idempotent. It cancels active forwarding RPCs, destroys accepted
116+
sockets, and waits for their cleanup.
117+
101118
## SSH sessions, providers, config and policy
102119

103120
```ts
@@ -162,7 +179,7 @@ mise run sdk:ts:proto # generate stubs from proto/ with buf
162179
mise run sdk:ts:format # Biome: format + safe fixes (writes)
163180
mise run sdk:ts:lint # Biome: lint + format check (read-only)
164181
mise run sdk:ts:typecheck # tsc --noEmit
165-
mise run sdk:ts:test # Vitest unit tests
182+
mise run sdk:ts:test # Vitest unit tests with an 80% line-coverage gate
166183
mise run sdk:ts:build # emit dist/
167184
```
168185

‎sdk/typescript/biome.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"useIgnoreFile": true
77
},
88
"files": {
9-
"includes": ["**", "!src/gen", "!dist"]
9+
"includes": ["**", "!src/gen", "!dist", "!coverage"]
1010
},
1111
"formatter": {
1212
"enabled": true,

‎sdk/typescript/buf.gen.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ inputs:
1616
- ../../proto/openshell.proto
1717
- ../../proto/sandbox.proto
1818
- ../../proto/datamodel.proto
19+
- ../../proto/options.proto
1920
plugins:
2021
- local: ./node_modules/.bin/protoc-gen-es
2122
out: src/gen

0 commit comments

Comments
 (0)