@shardflux/sdk 0.11.0 → 0.11.1
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.
- package/CHANGELOG.md +36 -27
- package/README.md +59 -59
- package/dist/account.d.ts +2 -2
- package/dist/account.js +1 -1
- package/dist/cell.d.ts +21 -21
- package/dist/cell.js +12 -12
- package/dist/client.d.ts +31 -31
- package/dist/client.js +17 -17
- package/dist/egress.d.ts +3 -3
- package/dist/errors.d.ts +18 -18
- package/dist/errors.js +11 -11
- package/dist/executions.d.ts +2 -2
- package/dist/feedback.d.ts +3 -3
- package/dist/generated/app-api.d.ts +1352 -21
- package/dist/http.d.ts +7 -11
- package/dist/http.js +8 -11
- package/dist/index.d.ts +1 -1
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.js +1 -1
- package/dist/progress.d.ts +21 -21
- package/dist/progress.js +10 -10
- package/dist/tar.d.ts +1 -1
- package/dist/tar.js +1 -1
- package/dist/template-file.d.ts +1 -1
- package/dist/template-file.js +1 -1
- package/dist/templates.d.ts +21 -21
- package/dist/templates.js +8 -8
- package/dist/tools.d.ts +3 -3
- package/dist/tools.js +4 -4
- package/dist/version-check.d.ts +1 -1
- package/dist/volumes.d.ts +1 -1
- package/dist/workspace.d.ts +20 -19
- package/dist/workspace.js +20 -19
- package/package.json +1 -1
package/dist/workspace.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface WakeOptions {
|
|
|
22
22
|
/** Progress of the wake: the resume request, observed states, conflicts retried, and `done` with the timing. */
|
|
23
23
|
onProgress?: ProgressListener;
|
|
24
24
|
/**
|
|
25
|
-
* The tool token the wake brings back (0.9.0): the held resume
|
|
25
|
+
* The tool token the wake brings back (0.9.0): the held resume returns one with the running
|
|
26
26
|
* workspace, for this agent label and tool set (defaults: those given to open()). It is kept for `cell()` clients of
|
|
27
27
|
* the same label and tools, whose next call then needs no token request. A `cell()` client's own wake passes its
|
|
28
28
|
* label and tools.
|
|
@@ -45,7 +45,7 @@ export interface HintOptions {
|
|
|
45
45
|
}
|
|
46
46
|
/** `workspace.hint()`: what the host found, or the background wake of a workspace that was not running. */
|
|
47
47
|
export interface HintResult {
|
|
48
|
-
/** The VM's residency when the hint arrived
|
|
48
|
+
/** The VM's residency when the hint arrived; null when the workspace was not running. */
|
|
49
49
|
residency: Residency | null;
|
|
50
50
|
/**
|
|
51
51
|
* The wake started in the background because the workspace was not running (409 `workspace_not_running`), else null.
|
|
@@ -84,11 +84,11 @@ export declare class Workspace {
|
|
|
84
84
|
get template(): WorkspaceView['template'];
|
|
85
85
|
get pendingReason(): string | null;
|
|
86
86
|
get activeOperation(): WorkspaceView['active_operation'];
|
|
87
|
-
/** persistent or session
|
|
87
|
+
/** persistent or session; immutable. A view without the field (older API) is persistent. */
|
|
88
88
|
get lifetime(): WorkspaceLifetime;
|
|
89
|
-
/** standard, template_draft or template_test
|
|
89
|
+
/** standard, template_draft or template_test. */
|
|
90
90
|
get purpose(): WorkspacePurpose;
|
|
91
|
-
/** legacy or layered
|
|
91
|
+
/** legacy or layered; reset, save-as-template and changes need layered. */
|
|
92
92
|
get diskLayout(): DiskLayout;
|
|
93
93
|
/** Sessions: seconds without activity after which the session ends (null for persistent workspaces). */
|
|
94
94
|
get idleTimeoutSeconds(): number | null;
|
|
@@ -97,7 +97,7 @@ export declare class Workspace {
|
|
|
97
97
|
/** How a session ended (closed, idle_timeout, draft_discarded); null while live or for a plain delete. */
|
|
98
98
|
get endedReason(): WorkspaceView['ended_reason'];
|
|
99
99
|
/**
|
|
100
|
-
* Start commands and services of the workspace's template version (0.7.0
|
|
100
|
+
* Start commands and services of the workspace's template version (0.7.0): `state` pending, running,
|
|
101
101
|
* ready or failed (the failed step, its exit code, reason and output tail). Null when the version has neither, or on
|
|
102
102
|
* an older API. A failed startup leaves the workspace running for inspection; the next open runs the failed step again.
|
|
103
103
|
*/
|
|
@@ -111,7 +111,7 @@ export declare class Workspace {
|
|
|
111
111
|
/** The raw view (GET /v1/workspaces/{id}). */
|
|
112
112
|
get data(): WorkspaceView;
|
|
113
113
|
/**
|
|
114
|
-
* `processful` (one VM keeps processes, memory and files) or `file_first` (0.9.0
|
|
114
|
+
* `processful` (one VM keeps processes, memory and files) or `file_first` (0.9.0: a versioned file
|
|
115
115
|
* tree, commands run as executions). Immutable. A view without the field (older API) is processful.
|
|
116
116
|
*/
|
|
117
117
|
get mode(): WorkspaceMode;
|
|
@@ -123,7 +123,7 @@ export declare class Workspace {
|
|
|
123
123
|
*/
|
|
124
124
|
get treeRevision(): number | null;
|
|
125
125
|
/**
|
|
126
|
-
* Executions of this file-first workspace
|
|
126
|
+
* Executions of this file-first workspace through `cell()`'s default client: `run(argv, opts)` runs
|
|
127
127
|
* a command in a fresh VM on the latest tree and returns an ExecutionResult (output, exit code, `changed`,
|
|
128
128
|
* `treeRevision`); `get(id, { waitMs })` reads one. See CellClient.executions.
|
|
129
129
|
*
|
|
@@ -154,7 +154,7 @@ export declare class Workspace {
|
|
|
154
154
|
suspend(opts: WaitedLifecycleOptions): Promise<FinishedOperation>;
|
|
155
155
|
suspend(opts?: LifecycleOptions): Promise<Operation>;
|
|
156
156
|
/**
|
|
157
|
-
* Suspends the workspace once it has been idle for `afterSeconds` (
|
|
157
|
+
* Suspends the workspace once it has been idle for `afterSeconds` (0..3600, 0 = as soon as it is idle; 0.9.0): call it when your agent's turn
|
|
158
158
|
* ends, so the workspace stops using RAM soon after instead of waiting out its idle policy. A command still running,
|
|
159
159
|
* an attached stream or a keepalive postpones the suspend until `afterSeconds` after it ends; the next tool call (the
|
|
160
160
|
* next turn) or a resume cancels it. Resolves with the recorded `suspendRequest` (also `workspace.suspendRequest`), or
|
|
@@ -172,7 +172,7 @@ export declare class Workspace {
|
|
|
172
172
|
/**
|
|
173
173
|
* Resumes a suspended workspace. Resolves when the resume is REQUESTED; with `{ wait: true }`, once the workspace runs.
|
|
174
174
|
* Tool calls wake a suspended workspace by themselves, so this is rarely needed. With `wait` (0.9.0) it is one held
|
|
175
|
-
* request
|
|
175
|
+
* request: the handle takes the running view and a tool token for `agentLabel`/`tools` (defaults:
|
|
176
176
|
* those given to open()), so `cell()` calls with that label and tools start at once. A workspace that is already
|
|
177
177
|
* running is ShardfluxApiError 409 `conflict` (`already_running`). The finished operation's `result.memory_restored`
|
|
178
178
|
* (also `lastTiming.server.memoryRestored`, 0.11.0+) is false when the resume booted the saved disk instead
|
|
@@ -210,7 +210,7 @@ export declare class Workspace {
|
|
|
210
210
|
close(opts: WaitedLifecycleOptions): Promise<FinishedOperation | null>;
|
|
211
211
|
close(opts?: LifecycleOptions): Promise<Operation | null>;
|
|
212
212
|
/**
|
|
213
|
-
* Wipes every change in this layered workspace and restarts it on its template (
|
|
213
|
+
* Wipes every change in this layered workspace and restarts it on its template (sends
|
|
214
214
|
* confirm_destructive). Returns the `reset` operation: requested, or with `{ wait: true }` finished. Tool tokens of
|
|
215
215
|
* the old epoch are dropped.
|
|
216
216
|
*/
|
|
@@ -229,7 +229,7 @@ export declare class Workspace {
|
|
|
229
229
|
captureToolCalls(opts?: ToolCallCaptureOptions): ToolCallCapture;
|
|
230
230
|
/** Internal: waits for tool-call capture writes recorded so far (workspaceTools calls it before each tool). */
|
|
231
231
|
[CAPTURE_BARRIER](): Promise<void> | undefined;
|
|
232
|
-
/** Saves this layered workspace as the next version of an organization template
|
|
232
|
+
/** Saves this layered workspace as the next version of an organization template. */
|
|
233
233
|
saveAsTemplate(params: SaveAsTemplateParams): Promise<SaveAsTemplateResponse>;
|
|
234
234
|
/**
|
|
235
235
|
* The workspace's changes against its template (cell gateway GET /v1/workspaces/{id}/changes; needs the `files` tool).
|
|
@@ -255,17 +255,18 @@ export declare class Workspace {
|
|
|
255
255
|
tools?: ToolName[];
|
|
256
256
|
} & CellClientOptions): CellClient;
|
|
257
257
|
/**
|
|
258
|
-
* Makes a suspended (or suspending/resuming) workspace run again and resolves once it does
|
|
258
|
+
* Makes a suspended (or suspending/resuming) workspace run again and resolves once it does: resume,
|
|
259
259
|
* or join the active resume/open; an active suspend (or other operation) is waited out first. Resolves `true` when it
|
|
260
260
|
* resumed or waited for a lifecycle operation, `false` when the workspace was already running. One deadline
|
|
261
261
|
* (`timeoutMs`, default 120 000 ms) covers every step. Throws OperationFailedError when the resume/open fails,
|
|
262
262
|
* OperationTimeoutError (naming the operation, its state and reason) when it is still queued, running or
|
|
263
263
|
* capacity_pending at the deadline, and any other API error (a conflict other than already_running /
|
|
264
|
-
* operation_in_progress) at once. Cell calls use it automatically when they meet `workspace_not_running`. A
|
|
265
|
-
*
|
|
266
|
-
* stays suspended with its state;
|
|
264
|
+
* operation_in_progress) at once. Cell calls use it automatically when they meet `workspace_not_running`. A queued
|
|
265
|
+
* resume has a deadline 15 minutes after it was created; past it, it fails with `capacity_unavailable`
|
|
266
|
+
* (OperationFailedError, `retryable`: nothing was started and the workspace stays suspended with its state; send it
|
|
267
|
+
* again).
|
|
267
268
|
*
|
|
268
|
-
* Since 0.9.0 the resume is held by the server until the workspace runs
|
|
269
|
+
* Since 0.9.0 the resume is held by the server until the workspace runs: one request returns the
|
|
269
270
|
* running workspace and a tool token for `agentLabel`/`tools`, which this handle keeps, so a tool call that woke the
|
|
270
271
|
* workspace is retried at once (refused call, resume, call). Timing: one `request` phase with reason `held`. A server
|
|
271
272
|
* that does not hold the request answers at once; the wake then waits for the operation and reads the view.
|
|
@@ -276,9 +277,9 @@ export declare class Workspace {
|
|
|
276
277
|
*/
|
|
277
278
|
wake(opts?: WakeOptions): Promise<boolean>;
|
|
278
279
|
/**
|
|
279
|
-
* Announces an imminent tool call (cell `POST /wake-hint
|
|
280
|
+
* Announces an imminent tool call (cell `POST /wake-hint`; 0.9.0+) so a parked workspace is restored
|
|
280
281
|
* ahead of it: call it when the model starts emitting a tool call, before its arguments are complete. The agent tools
|
|
281
|
-
* of `workspaceTools()` send it when a call starts. Cheap and
|
|
282
|
+
* of `workspaceTools()` send it when a call starts. Cheap and non-blocking: it returns what the host found. A workspace
|
|
282
283
|
* that is not running (suspended, or a token cannot be issued for it) is woken in the background (`wake`, not awaited
|
|
283
284
|
* here) so the call finds it running sooner. Other errors (network, auth) are thrown; callers that fire and forget
|
|
284
285
|
* should catch them.
|
package/dist/workspace.js
CHANGED
|
@@ -33,7 +33,7 @@ export class Workspace {
|
|
|
33
33
|
if (this.#treeRevision === null || rev > this.#treeRevision)
|
|
34
34
|
this.#treeRevision = rev;
|
|
35
35
|
}
|
|
36
|
-
/** The local refusal of a lifecycle call a file-first workspace does not have
|
|
36
|
+
/** The local refusal of a lifecycle call a file-first workspace does not have. */
|
|
37
37
|
#needsVm(operation) {
|
|
38
38
|
if (this.#view.mode !== 'file_first')
|
|
39
39
|
return null;
|
|
@@ -102,15 +102,15 @@ export class Workspace {
|
|
|
102
102
|
get activeOperation() {
|
|
103
103
|
return this.#view.active_operation;
|
|
104
104
|
}
|
|
105
|
-
/** persistent or session
|
|
105
|
+
/** persistent or session; immutable. A view without the field (older API) is persistent. */
|
|
106
106
|
get lifetime() {
|
|
107
107
|
return this.#view.lifetime ?? 'persistent';
|
|
108
108
|
}
|
|
109
|
-
/** standard, template_draft or template_test
|
|
109
|
+
/** standard, template_draft or template_test. */
|
|
110
110
|
get purpose() {
|
|
111
111
|
return this.#view.purpose ?? 'standard';
|
|
112
112
|
}
|
|
113
|
-
/** legacy or layered
|
|
113
|
+
/** legacy or layered; reset, save-as-template and changes need layered. */
|
|
114
114
|
get diskLayout() {
|
|
115
115
|
return this.#view.disk_layout ?? 'legacy';
|
|
116
116
|
}
|
|
@@ -127,7 +127,7 @@ export class Workspace {
|
|
|
127
127
|
return this.#view.ended_reason ?? null;
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
-
* Start commands and services of the workspace's template version (0.7.0
|
|
130
|
+
* Start commands and services of the workspace's template version (0.7.0): `state` pending, running,
|
|
131
131
|
* ready or failed (the failed step, its exit code, reason and output tail). Null when the version has neither, or on
|
|
132
132
|
* an older API. A failed startup leaves the workspace running for inspection; the next open runs the failed step again.
|
|
133
133
|
*/
|
|
@@ -147,7 +147,7 @@ export class Workspace {
|
|
|
147
147
|
return this.#view;
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
|
-
* `processful` (one VM keeps processes, memory and files) or `file_first` (0.9.0
|
|
150
|
+
* `processful` (one VM keeps processes, memory and files) or `file_first` (0.9.0: a versioned file
|
|
151
151
|
* tree, commands run as executions). Immutable. A view without the field (older API) is processful.
|
|
152
152
|
*/
|
|
153
153
|
get mode() {
|
|
@@ -163,7 +163,7 @@ export class Workspace {
|
|
|
163
163
|
return this.mode === 'file_first' ? this.#treeRevision : null;
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
166
|
-
* Executions of this file-first workspace
|
|
166
|
+
* Executions of this file-first workspace through `cell()`'s default client: `run(argv, opts)` runs
|
|
167
167
|
* a command in a fresh VM on the latest tree and returns an ExecutionResult (output, exit code, `changed`,
|
|
168
168
|
* `treeRevision`); `get(id, { waitMs })` reads one. See CellClient.executions.
|
|
169
169
|
*
|
|
@@ -204,7 +204,7 @@ export class Workspace {
|
|
|
204
204
|
return this.#ctx.workspaces.suspend(this.id, { ...this.#tracked(opts), [AFTER_WAIT]: this.#refreshAfterWait() });
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
207
|
-
* Suspends the workspace once it has been idle for `afterSeconds` (
|
|
207
|
+
* Suspends the workspace once it has been idle for `afterSeconds` (0..3600, 0 = as soon as it is idle; 0.9.0): call it when your agent's turn
|
|
208
208
|
* ends, so the workspace stops using RAM soon after instead of waiting out its idle policy. A command still running,
|
|
209
209
|
* an attached stream or a keepalive postpones the suspend until `afterSeconds` after it ends; the next tool call (the
|
|
210
210
|
* next turn) or a resume cancels it. Resolves with the recorded `suspendRequest` (also `workspace.suspendRequest`), or
|
|
@@ -237,7 +237,7 @@ export class Workspace {
|
|
|
237
237
|
const manager = this.tokens({ ...(opts.agentLabel !== undefined ? { agentLabel: opts.agentLabel } : {}), ...(opts.tools !== undefined ? { tools: opts.tools } : {}) });
|
|
238
238
|
return this.#ctx.workspaces.resume(this.id, { ...this.#tracked(opts), [AFTER_WAIT]: this.#refreshAfterWait(), [HELD_RESUME]: this.#heldTarget(manager) });
|
|
239
239
|
}
|
|
240
|
-
/** A held resume's 200
|
|
240
|
+
/** A held resume's 200 goes straight into this handle: the view, and the token for `manager`. */
|
|
241
241
|
#heldTarget(manager) {
|
|
242
242
|
return {
|
|
243
243
|
agentLabel: manager.agentLabel,
|
|
@@ -315,7 +315,7 @@ export class Workspace {
|
|
|
315
315
|
[CAPTURE_BARRIER]() {
|
|
316
316
|
return this.#ctx.captures.settle(this.id);
|
|
317
317
|
}
|
|
318
|
-
/** Saves this layered workspace as the next version of an organization template
|
|
318
|
+
/** Saves this layered workspace as the next version of an organization template. */
|
|
319
319
|
saveAsTemplate(params) {
|
|
320
320
|
const refusal = this.#needsVm('save_as_template');
|
|
321
321
|
if (refusal)
|
|
@@ -378,17 +378,18 @@ export class Workspace {
|
|
|
378
378
|
return c;
|
|
379
379
|
}
|
|
380
380
|
/**
|
|
381
|
-
* Makes a suspended (or suspending/resuming) workspace run again and resolves once it does
|
|
381
|
+
* Makes a suspended (or suspending/resuming) workspace run again and resolves once it does: resume,
|
|
382
382
|
* or join the active resume/open; an active suspend (or other operation) is waited out first. Resolves `true` when it
|
|
383
383
|
* resumed or waited for a lifecycle operation, `false` when the workspace was already running. One deadline
|
|
384
384
|
* (`timeoutMs`, default 120 000 ms) covers every step. Throws OperationFailedError when the resume/open fails,
|
|
385
385
|
* OperationTimeoutError (naming the operation, its state and reason) when it is still queued, running or
|
|
386
386
|
* capacity_pending at the deadline, and any other API error (a conflict other than already_running /
|
|
387
|
-
* operation_in_progress) at once. Cell calls use it automatically when they meet `workspace_not_running`. A
|
|
388
|
-
*
|
|
389
|
-
* stays suspended with its state;
|
|
387
|
+
* operation_in_progress) at once. Cell calls use it automatically when they meet `workspace_not_running`. A queued
|
|
388
|
+
* resume has a deadline 15 minutes after it was created; past it, it fails with `capacity_unavailable`
|
|
389
|
+
* (OperationFailedError, `retryable`: nothing was started and the workspace stays suspended with its state; send it
|
|
390
|
+
* again).
|
|
390
391
|
*
|
|
391
|
-
* Since 0.9.0 the resume is held by the server until the workspace runs
|
|
392
|
+
* Since 0.9.0 the resume is held by the server until the workspace runs: one request returns the
|
|
392
393
|
* running workspace and a tool token for `agentLabel`/`tools`, which this handle keeps, so a tool call that woke the
|
|
393
394
|
* workspace is retried at once (refused call, resume, call). Timing: one `request` phase with reason `held`. A server
|
|
394
395
|
* that does not hold the request answers at once; the wake then waits for the operation and reads the view.
|
|
@@ -398,7 +399,7 @@ export class Workspace {
|
|
|
398
399
|
* and the `done` progress event say so (`server.memoryRestored === false`, `server.resumePath` `cold_boot`).
|
|
399
400
|
*/
|
|
400
401
|
async wake(opts = {}) {
|
|
401
|
-
// A file-first workspace runs from creation and is never suspended
|
|
402
|
+
// A file-first workspace runs from creation and is never suspended: nothing to wake.
|
|
402
403
|
if (this.#view.mode === 'file_first')
|
|
403
404
|
return false;
|
|
404
405
|
const trace = new Trace('wake', combineListeners(this.#ctx.onProgress, this.#tracked(opts).onProgress), { workspaceId: this.id });
|
|
@@ -415,7 +416,7 @@ export class Workspace {
|
|
|
415
416
|
throw opts.signal.reason;
|
|
416
417
|
let active;
|
|
417
418
|
try {
|
|
418
|
-
// Held resume
|
|
419
|
+
// Held resume: answered once the workspace runs, with the view and a token; it returns the
|
|
419
420
|
// active resume/open when there is one, so concurrent wakes join a single operation. The request is made here
|
|
420
421
|
// rather than through resume() so the wake is one trace.
|
|
421
422
|
const waitS = Math.min(SERVER_WAIT_MAX_S, Math.floor((deadline - Date.now()) / 1000));
|
|
@@ -473,9 +474,9 @@ export class Workspace {
|
|
|
473
474
|
throw new Error(`workspace ${this.id} did not become runnable after repeated lifecycle conflicts`);
|
|
474
475
|
}
|
|
475
476
|
/**
|
|
476
|
-
* Announces an imminent tool call (cell `POST /wake-hint
|
|
477
|
+
* Announces an imminent tool call (cell `POST /wake-hint`; 0.9.0+) so a parked workspace is restored
|
|
477
478
|
* ahead of it: call it when the model starts emitting a tool call, before its arguments are complete. The agent tools
|
|
478
|
-
* of `workspaceTools()` send it when a call starts. Cheap and
|
|
479
|
+
* of `workspaceTools()` send it when a call starts. Cheap and non-blocking: it returns what the host found. A workspace
|
|
479
480
|
* that is not running (suspended, or a token cannot be issued for it) is woken in the background (`wake`, not awaited
|
|
480
481
|
* here) so the call finds it running sooner. Other errors (network, auth) are thrown; callers that fire and forget
|
|
481
482
|
* should catch them.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shardflux/sdk",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shardflux TypeScript SDK: open persistent agent workspaces by key and give your agent workspace tools (exec, files, processes, PTY, git, browser).",
|
|
6
6
|
"license": "Apache-2.0",
|