quilt-sdk 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +128 -32
  2. package/package.json +15 -2
package/README.md CHANGED
@@ -1,51 +1,120 @@
1
1
  # quilt-sdk
2
2
 
3
- Type-safe TypeScript SDK for interacting with Quilt platform APIs.
3
+ Type-safe TypeScript SDK for Quilt production APIs.
4
4
 
5
- This package is the interaction plane for Quilt production APIs, including:
6
-
7
- - Core HTTP API resources (`containers`, `volumes`, `projects`, `clusters`, `functions`, etc.)
8
- - Production platform extensions (`platform` module: env/jobs/archive/ops/ICC and related endpoints)
9
- - Realtime APIs (SSE events and WebSocket terminal attach)
10
- - OpenAI-compatible tool schema export (`QUILT_TOOLS`)
5
+ `quilt-sdk` is the programmatic client for the live Quilt backend. It is intended to be the typed source of truth for production automation, not a thin convenience wrapper around ad hoc fetch calls.
11
6
 
12
7
  ## Install
13
8
 
9
+ ```bash
10
+ npm install quilt-sdk
11
+ ```
12
+
13
+ or
14
+
14
15
  ```bash
15
16
  bun add quilt-sdk
16
17
  ```
17
18
 
19
+ ## Requirements
20
+
21
+ - Node `>=20.10.0`
22
+ - Quilt backend URL, usually `https://backend.quilt.sh`
23
+ - either `QUILT_API_KEY` or `QUILT_JWT`
24
+
18
25
  ## Quick Start
19
26
 
20
27
  ```ts
21
28
  import { QuiltClient } from "quilt-sdk";
22
29
 
23
- const quilt = QuiltClient.connect({
24
- baseUrl: "https://backend.quilt.sh",
30
+ const client = QuiltClient.connect({
31
+ baseUrl: process.env.QUILT_BASE_URL ?? "https://backend.quilt.sh",
25
32
  apiKey: process.env.QUILT_API_KEY,
26
33
  });
27
34
 
28
- const containers = await quilt.containers.list();
29
- console.log(containers);
35
+ const health = await client.system.health();
36
+ const containers = await client.containers.list();
37
+
38
+ console.log(health.status);
39
+ console.log(containers.containers.length);
30
40
  ```
31
41
 
32
42
  ## Auth
33
43
 
34
44
  `QuiltClient.connect()` accepts:
35
45
 
36
- - `token` for bearer auth
37
46
  - `apiKey` for `X-Api-Key`
38
- - explicit `auth` union for advanced usage
47
+ - `token` for bearer auth
48
+ - `auth` for the explicit auth union when you need to control the transport directly
49
+
50
+ If both `apiKey` and `token` are provided, API key auth wins.
51
+
52
+ ## Core Client Shape
53
+
54
+ ```ts
55
+ import { QuiltClient } from "quilt-sdk";
56
+
57
+ const client = QuiltClient.connect({
58
+ baseUrl: "https://backend.quilt.sh",
59
+ apiKey: process.env.QUILT_API_KEY,
60
+ });
61
+ ```
62
+
63
+ Primary SDK surfaces:
64
+
65
+ - `client.system` for health, info, and activity
66
+ - `client.containers` for container lifecycle, exec, logs, metrics, snapshots, network, and GUI URLs
67
+ - `client.platform` for cross-cutting routes such as operations, env maps, archives, jobs, ICC, OCI, and helper control flows
68
+ - `client.volumes` for volume lifecycle and file browsing
69
+ - `client.clusters` for cluster, node, workload, placement, and join-token control-plane flows
70
+ - `client.agent` for join-token and node-token authenticated agent calls
71
+ - `client.functions` for serverless lifecycle, invoke, versions, invocations, and pool status
72
+ - `client.elasticity` for resize, pool targeting, and orchestrator-safe control actions
73
+ - `client.terminal` and `client.terminalRealtime` for terminal session lifecycle and WebSocket attach
74
+ - `client.events` for SSE streams
75
+ - `client.raw(...)` for authenticated access to backend routes that are intentionally still exposed as raw contract calls
76
+
77
+ ## Public Types
78
+
79
+ The SDK ships declarations automatically.
80
+
81
+ Use the client-owned type surface when you need explicit types:
39
82
 
40
- If both `token` and `apiKey` are provided, API key auth is used.
83
+ ```ts
84
+ import { QuiltClient } from "quilt-sdk";
85
+
86
+ const client = QuiltClient.connect({
87
+ apiKey: process.env.QUILT_API_KEY,
88
+ });
89
+
90
+ const options: QuiltClient.Options = {
91
+ baseUrl: "https://backend.quilt.sh",
92
+ apiKey: process.env.QUILT_API_KEY,
93
+ };
94
+
95
+ let invocation: QuiltClient.Functions.Invocation | null = null;
96
+ let resize: QuiltClient.Elasticity.ContainerResizeResponse | null = null;
97
+ ```
98
+
99
+ That keeps consumer imports simple while still exposing the production contract.
100
+
101
+ ## Execution Model
102
+
103
+ Use the SDK in the same execution style the backend expects:
104
+
105
+ - treat container lifecycle mutations as operation-driven when they return operation metadata
106
+ - treat exec as submit-and-track, not inline command execution
107
+ - use terminal attach and WebSocket flows for interactive sessions
108
+ - invoke a shell explicitly when shell parsing is required
109
+ - prefer typed module methods over `client.raw(...)`
41
110
 
42
111
  ## Realtime
43
112
 
44
113
  ### SSE
45
114
 
46
115
  ```ts
47
- const source = quilt.events.openEventSource();
48
- quilt.events.on(source, "container_update", (event) => {
116
+ const source = client.events.openEventSource();
117
+ client.events.on(source, "container_update", (event) => {
49
118
  console.log(event.data);
50
119
  });
51
120
  ```
@@ -53,40 +122,67 @@ quilt.events.on(source, "container_update", (event) => {
53
122
  ### WebSocket Terminal
54
123
 
55
124
  ```ts
56
- const ws = quilt.terminalRealtime.connect({ container_identifier: "ctr_123", cols: 120, rows: 30 });
125
+ const ws = client.terminalRealtime.connect({
126
+ container_identifier: "ctr_123",
127
+ cols: 120,
128
+ rows: 30,
129
+ });
130
+
57
131
  ws.addEventListener("message", (msg) => {
58
132
  if (typeof msg.data === "string") {
59
- const parsed = quilt.terminalRealtime.parseServerMessage(msg.data);
133
+ const parsed = client.terminalRealtime.parseServerMessage(msg.data);
60
134
  console.log(parsed);
61
135
  }
62
136
  });
63
137
  ```
64
138
 
65
- ## Production Platform Module
139
+ ## Examples
66
140
 
67
- The `platform` namespace exposes production endpoints that are part of live backend behavior and script-driven workflows, including:
141
+ The repo ships production-validated examples in [examples/README.md](/home/ubuntu/quilt-sdk/examples/README.md).
68
142
 
69
- - Container env, rename, archive, jobs, ready/resume/fork
70
- - Snapshot clone and operation status
71
- - Volume archive/files helpers
72
- - Network allocations and monitor process queries
73
- - ICC endpoints
143
+ Example files:
74
144
 
75
- ```ts
76
- const op = await quilt.containers.stop("ctr_123", "async");
77
- if ("operation_id" in (op as Record<string, unknown>)) {
78
- const done = await quilt.awaitOperation((op as { operation_id: string }).operation_id);
79
- console.log(done.status);
80
- }
145
+ - `examples/containers-volumes-and-network.ts`
146
+ - `examples/sdk-runtime-and-functions.ts`
147
+ - `examples/clusters-nodes-workloads-and-k8s.ts`
148
+ - `examples/terminal-and-icc.ts`
149
+ - `examples/elasticity-control.ts`
150
+ - `examples/lifecycle-and-failures.ts`
151
+
152
+ Run them from the repo root:
153
+
154
+ ```bash
155
+ bun run example:containers
156
+ bun run example:sdk
157
+ bun run example:clusters
158
+ bun run example:terminal
159
+ bun run example:elasticity
160
+ bun run example:lifecycle
161
+ bun run examples:all
162
+ ```
163
+
164
+ Expected environment variables:
165
+
166
+ ```text
167
+ QUILT_BASE_URL=https://backend.quilt.sh
168
+ QUILT_API_KEY=<api_key>
169
+ ```
170
+
171
+ Alternative auth:
172
+
173
+ ```text
174
+ QUILT_JWT=<jwt>
81
175
  ```
82
176
 
83
- ## Scripts
177
+ ## Repository Validation
84
178
 
85
179
  ```bash
86
180
  bun run lint
87
181
  bun run typecheck
182
+ bun run examples:typecheck
88
183
  bun run test
89
184
  bun run build
185
+ bun run examples:all
90
186
  ```
91
187
 
92
188
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quilt-sdk",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Fully type-safe TypeScript SDK for Quilt HTTP APIs",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,10 +22,18 @@
22
22
  "generate:types": "node ./scripts/generate-contract-types.mjs",
23
23
  "build": "bun run generate:types && tsc -p tsconfig.build.json",
24
24
  "typecheck": "bun run generate:types && tsc -p tsconfig.json --noEmit",
25
+ "examples:typecheck": "tsc -p tsconfig.examples.json --noEmit",
25
26
  "lint": "biome check .",
26
27
  "lint:fix": "biome check --write .",
27
28
  "test": "bun test",
28
29
  "test:coverage": "bun test --coverage",
30
+ "examples:all": "bun run example:containers && bun run example:sdk && bun run example:clusters && bun run example:terminal && bun run example:elasticity && bun run example:lifecycle",
31
+ "example:containers": "node --env-file=.env --import tsx examples/containers-volumes-and-network.ts",
32
+ "example:sdk": "node --env-file=.env --import tsx examples/sdk-runtime-and-functions.ts",
33
+ "example:clusters": "node --env-file=.env --import tsx examples/clusters-nodes-workloads-and-k8s.ts",
34
+ "example:terminal": "node --env-file=.env --import tsx examples/terminal-and-icc.ts",
35
+ "example:elasticity": "node --env-file=.env --import tsx examples/elasticity-control.ts",
36
+ "example:lifecycle": "node --env-file=.env --import tsx examples/lifecycle-and-failures.ts",
29
37
  "prepublishOnly": "bun run clean && bun run lint && bun run typecheck && bun run test && bun run build"
30
38
  },
31
39
  "keywords": ["quilt", "sdk", "api", "typescript", "bun"],
@@ -33,8 +41,13 @@
33
41
  "devDependencies": {
34
42
  "@biomejs/biome": "^1.9.4",
35
43
  "@types/node": "^24.0.0",
44
+ "@types/ws": "^8.18.1",
36
45
  "bun-types": "^1.3.0",
46
+ "eventsource": "^3.0.7",
37
47
  "openapi-typescript": "^7.6.1",
38
- "typescript": "^5.8.3"
48
+ "protobufjs": "^8.0.0",
49
+ "tsx": "^4.20.3",
50
+ "typescript": "^5.8.3",
51
+ "ws": "^8.20.0"
39
52
  }
40
53
  }