@shardflux/sdk 0.14.0 → 0.16.0

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 (49) hide show
  1. package/CHANGELOG.md +85 -23
  2. package/README.md +226 -7
  3. package/dist/account.d.ts +2 -0
  4. package/dist/account.js +6 -0
  5. package/dist/cell.d.ts +27 -0
  6. package/dist/cell.js +71 -0
  7. package/dist/client.d.ts +54 -5
  8. package/dist/client.js +100 -7
  9. package/dist/computer.d.ts +153 -0
  10. package/dist/computer.js +229 -0
  11. package/dist/errors.d.ts +5 -1
  12. package/dist/errors.js +9 -0
  13. package/dist/executions.d.ts +2 -6
  14. package/dist/executions.js +9 -0
  15. package/dist/exit-code.d.ts +7 -0
  16. package/dist/exit-code.js +12 -0
  17. package/dist/generated/app-api.d.ts +1055 -119
  18. package/dist/generated/cell-api.d.ts +334 -0
  19. package/dist/http.d.ts +7 -1
  20. package/dist/http.js +34 -13
  21. package/dist/index.d.ts +13 -6
  22. package/dist/index.js +7 -2
  23. package/dist/ports.d.ts +7 -0
  24. package/dist/ports.js +1 -1
  25. package/dist/progress.d.ts +2 -2
  26. package/dist/progress.js +1 -1
  27. package/dist/templates.d.ts +12 -0
  28. package/dist/templates.js +9 -0
  29. package/dist/testing/index.d.ts +62 -0
  30. package/dist/testing/index.js +585 -0
  31. package/dist/testing/seed.d.ts +433 -0
  32. package/dist/testing/seed.js +449 -0
  33. package/dist/tools.d.ts +21 -3
  34. package/dist/tools.js +113 -22
  35. package/dist/tunnel-assets/linux-amd64.gz +0 -0
  36. package/dist/tunnel-assets/linux-arm64.gz +0 -0
  37. package/dist/tunnel-assets.d.ts +10 -0
  38. package/dist/tunnel-assets.js +11 -0
  39. package/dist/tunnel-packet.d.ts +3 -0
  40. package/dist/tunnel-packet.js +43 -0
  41. package/dist/tunnel-pty.d.ts +86 -0
  42. package/dist/tunnel-pty.js +243 -0
  43. package/dist/tunnels.d.ts +47 -0
  44. package/dist/tunnels.js +454 -0
  45. package/dist/workspace-ref.d.ts +87 -0
  46. package/dist/workspace-ref.js +173 -0
  47. package/dist/workspace.d.ts +40 -1
  48. package/dist/workspace.js +111 -2
  49. package/package.json +7 -2
@@ -731,6 +731,87 @@ export interface paths {
731
731
  patch?: never;
732
732
  trace?: never;
733
733
  };
734
+ "/v1/workspaces/{workspace_id}/computer": {
735
+ parameters: {
736
+ query?: never;
737
+ header?: never;
738
+ path: {
739
+ workspace_id: components["parameters"]["WorkspaceId"];
740
+ };
741
+ cookie?: never;
742
+ };
743
+ /**
744
+ * The workspace desktop's state (does not start it)
745
+ * @description Contracts §45.4. Tool `computer` (the token carries it only while the
746
+ * workspace's computer use is on, §45.1).
747
+ */
748
+ get: operations["computerStatus"];
749
+ put?: never;
750
+ /**
751
+ * Start the workspace desktop (no-op while it runs)
752
+ * @description The size applies when this call starts the desktop; a running desktop
753
+ * keeps its size (stop it first to change it). `409 conflict`
754
+ * `details.reason computer_use_unavailable` when the workspace's template
755
+ * cannot run a desktop.
756
+ */
757
+ post: operations["computerStart"];
758
+ /** Stop the workspace desktop (its windows close) */
759
+ delete: operations["computerStop"];
760
+ options?: never;
761
+ head?: never;
762
+ patch?: never;
763
+ trace?: never;
764
+ };
765
+ "/v1/workspaces/{workspace_id}/computer/actions": {
766
+ parameters: {
767
+ query?: never;
768
+ header?: never;
769
+ path: {
770
+ workspace_id: components["parameters"]["WorkspaceId"];
771
+ };
772
+ cookie?: never;
773
+ };
774
+ get?: never;
775
+ put?: never;
776
+ /**
777
+ * Run a batch of computer actions, optionally ending with a screenshot
778
+ * @description Contracts §45.3. Starts the desktop when it does not run. The actions
779
+ * run in order; the first failure stops the batch and the rest are
780
+ * reported `skipped`. An invalid batch runs nothing: `422
781
+ * validation_failed` with `details.index` (-1 for the batch itself).
782
+ */
783
+ post: operations["computerActions"];
784
+ delete?: never;
785
+ options?: never;
786
+ head?: never;
787
+ patch?: never;
788
+ trace?: never;
789
+ };
790
+ "/v1/workspaces/{workspace_id}/computer/stream": {
791
+ parameters: {
792
+ query?: never;
793
+ header?: never;
794
+ path: {
795
+ workspace_id: components["parameters"]["WorkspaceId"];
796
+ };
797
+ cookie?: never;
798
+ };
799
+ get?: never;
800
+ put?: never;
801
+ /**
802
+ * Start the desktop viewer on its guest port
803
+ * @description Contracts §45.5. Expose the returned port with the ports API and open a
804
+ * signed link whose `path` is the returned path. Port 61002 is view
805
+ * only (the guest drops input); 61003 lets the viewer use the desktop.
806
+ */
807
+ post: operations["computerStreamStart"];
808
+ /** End every view of the desktop */
809
+ delete: operations["computerStreamStop"];
810
+ options?: never;
811
+ head?: never;
812
+ patch?: never;
813
+ trace?: never;
814
+ };
734
815
  "/v1/workspaces/{workspace_id}/wake-hint": {
735
816
  parameters: {
736
817
  query?: never;
@@ -1490,6 +1571,111 @@ export interface components {
1490
1571
  }[];
1491
1572
  stderr?: string;
1492
1573
  };
1574
+ ComputerStartRequest: {
1575
+ /** @default 1280 */
1576
+ width?: number;
1577
+ /** @default 800 */
1578
+ height?: number;
1579
+ };
1580
+ ComputerStatus: {
1581
+ running: boolean;
1582
+ /** @example :1 */
1583
+ display?: string;
1584
+ width?: number;
1585
+ height?: number;
1586
+ /** Format: date-time */
1587
+ started_at?: string;
1588
+ /** @description The session command (window manager and panel). */
1589
+ session?: string;
1590
+ streams: {
1591
+ view: boolean;
1592
+ interactive: boolean;
1593
+ };
1594
+ };
1595
+ /**
1596
+ * @description One of Claude's computer toolset members with its parameters
1597
+ * (contracts §45.3). A parameter the action does not take is refused.
1598
+ */
1599
+ ComputerAction: {
1600
+ /** @enum {string} */
1601
+ action: "screenshot" | "zoom" | "left_click" | "right_click" | "middle_click" | "double_click" | "triple_click" | "left_click_drag" | "mouse_move" | "left_mouse_down" | "left_mouse_up" | "cursor_position" | "scroll" | "type" | "key" | "hold_key" | "wait";
1602
+ /** @description [x, y] screen pixels. */
1603
+ coordinate?: number[];
1604
+ start_coordinate?: number[];
1605
+ /** @description zoom: [x0, y0, x1, y1]. */
1606
+ region?: number[];
1607
+ /** @description type: the text; key/hold_key: key combinations; clicks, drag, scroll: modifiers held. */
1608
+ text?: string;
1609
+ /** @enum {string} */
1610
+ scroll_direction?: "up" | "down" | "left" | "right";
1611
+ scroll_amount?: number;
1612
+ /** @description Seconds (wait */
1613
+ duration?: number;
1614
+ repeat?: number;
1615
+ };
1616
+ ComputerActionsRequest: {
1617
+ actions: components["schemas"]["ComputerAction"][];
1618
+ /**
1619
+ * @description Append a screenshot after the last action that ran.
1620
+ * @default false
1621
+ */
1622
+ screenshot?: boolean;
1623
+ /** @default 250 */
1624
+ settle_ms?: number;
1625
+ /**
1626
+ * @default png
1627
+ * @enum {string}
1628
+ */
1629
+ format?: "png" | "jpeg";
1630
+ /**
1631
+ * @description jpeg only.
1632
+ * @default 80
1633
+ */
1634
+ quality?: number;
1635
+ };
1636
+ ComputerImage: {
1637
+ /** @enum {string} */
1638
+ format: "png" | "jpeg";
1639
+ width: number;
1640
+ height: number;
1641
+ data: string;
1642
+ };
1643
+ ComputerActionResult: {
1644
+ action: string;
1645
+ ok: boolean;
1646
+ /** @description cursor_position: X=…, Y=… */
1647
+ output?: string;
1648
+ image?: components["schemas"]["ComputerImage"];
1649
+ error?: {
1650
+ /** @enum {string} */
1651
+ code: "action_failed";
1652
+ message: string;
1653
+ };
1654
+ /** @description An earlier action of the batch failed; this one did not run. */
1655
+ skipped?: boolean;
1656
+ /** Format: int64 */
1657
+ took_ms: number;
1658
+ };
1659
+ ComputerActionsResult: {
1660
+ results: components["schemas"]["ComputerActionResult"][];
1661
+ screenshot?: components["schemas"]["ComputerImage"];
1662
+ cursor: number[];
1663
+ display: {
1664
+ width: number;
1665
+ height: number;
1666
+ };
1667
+ };
1668
+ ComputerStreamRequest: {
1669
+ /** @default false */
1670
+ interactive?: boolean;
1671
+ };
1672
+ ComputerStream: {
1673
+ /** @enum {integer} */
1674
+ port: 61002 | 61003;
1675
+ interactive: boolean;
1676
+ /** @description The viewer page */
1677
+ path: string;
1678
+ };
1493
1679
  BrowserScreenshotRequest: {
1494
1680
  url: string;
1495
1681
  /** @default 1280 */
@@ -2074,6 +2260,8 @@ export interface operations {
2074
2260
  parameters: {
2075
2261
  query?: {
2076
2262
  offset?: number;
2263
+ /** @description Opt-in output representation. binary sends a u64be log offset followed by up to 1 MiB raw bytes; control messages remain JSON. json (default) sends up to 64 KiB base64 chunks. */
2264
+ output_format?: "json" | "binary";
2077
2265
  ticket?: string;
2078
2266
  };
2079
2267
  header?: never;
@@ -2582,6 +2770,152 @@ export interface operations {
2582
2770
  default: components["responses"]["Error"];
2583
2771
  };
2584
2772
  };
2773
+ computerStatus: {
2774
+ parameters: {
2775
+ query?: never;
2776
+ header?: never;
2777
+ path: {
2778
+ workspace_id: components["parameters"]["WorkspaceId"];
2779
+ };
2780
+ cookie?: never;
2781
+ };
2782
+ requestBody?: never;
2783
+ responses: {
2784
+ /** @description Desktop state. */
2785
+ 200: {
2786
+ headers: {
2787
+ [name: string]: unknown;
2788
+ };
2789
+ content: {
2790
+ "application/json": components["schemas"]["ComputerStatus"];
2791
+ };
2792
+ };
2793
+ default: components["responses"]["Error"];
2794
+ };
2795
+ };
2796
+ computerStart: {
2797
+ parameters: {
2798
+ query?: never;
2799
+ header?: never;
2800
+ path: {
2801
+ workspace_id: components["parameters"]["WorkspaceId"];
2802
+ };
2803
+ cookie?: never;
2804
+ };
2805
+ requestBody?: {
2806
+ content: {
2807
+ "application/json": components["schemas"]["ComputerStartRequest"];
2808
+ };
2809
+ };
2810
+ responses: {
2811
+ /** @description Desktop state. */
2812
+ 200: {
2813
+ headers: {
2814
+ [name: string]: unknown;
2815
+ };
2816
+ content: {
2817
+ "application/json": components["schemas"]["ComputerStatus"];
2818
+ };
2819
+ };
2820
+ default: components["responses"]["Error"];
2821
+ };
2822
+ };
2823
+ computerStop: {
2824
+ parameters: {
2825
+ query?: never;
2826
+ header?: never;
2827
+ path: {
2828
+ workspace_id: components["parameters"]["WorkspaceId"];
2829
+ };
2830
+ cookie?: never;
2831
+ };
2832
+ requestBody?: never;
2833
+ responses: {
2834
+ /** @description Stopped */
2835
+ 204: {
2836
+ headers: {
2837
+ [name: string]: unknown;
2838
+ };
2839
+ content?: never;
2840
+ };
2841
+ default: components["responses"]["Error"];
2842
+ };
2843
+ };
2844
+ computerActions: {
2845
+ parameters: {
2846
+ query?: never;
2847
+ header?: never;
2848
+ path: {
2849
+ workspace_id: components["parameters"]["WorkspaceId"];
2850
+ };
2851
+ cookie?: never;
2852
+ };
2853
+ requestBody: {
2854
+ content: {
2855
+ "application/json": components["schemas"]["ComputerActionsRequest"];
2856
+ };
2857
+ };
2858
+ responses: {
2859
+ /** @description Per-action results. */
2860
+ 200: {
2861
+ headers: {
2862
+ [name: string]: unknown;
2863
+ };
2864
+ content: {
2865
+ "application/json": components["schemas"]["ComputerActionsResult"];
2866
+ };
2867
+ };
2868
+ default: components["responses"]["Error"];
2869
+ };
2870
+ };
2871
+ computerStreamStart: {
2872
+ parameters: {
2873
+ query?: never;
2874
+ header?: never;
2875
+ path: {
2876
+ workspace_id: components["parameters"]["WorkspaceId"];
2877
+ };
2878
+ cookie?: never;
2879
+ };
2880
+ requestBody?: {
2881
+ content: {
2882
+ "application/json": components["schemas"]["ComputerStreamRequest"];
2883
+ };
2884
+ };
2885
+ responses: {
2886
+ /** @description Viewer started. */
2887
+ 200: {
2888
+ headers: {
2889
+ [name: string]: unknown;
2890
+ };
2891
+ content: {
2892
+ "application/json": components["schemas"]["ComputerStream"];
2893
+ };
2894
+ };
2895
+ default: components["responses"]["Error"];
2896
+ };
2897
+ };
2898
+ computerStreamStop: {
2899
+ parameters: {
2900
+ query?: never;
2901
+ header?: never;
2902
+ path: {
2903
+ workspace_id: components["parameters"]["WorkspaceId"];
2904
+ };
2905
+ cookie?: never;
2906
+ };
2907
+ requestBody?: never;
2908
+ responses: {
2909
+ /** @description Viewers stopped. */
2910
+ 204: {
2911
+ headers: {
2912
+ [name: string]: unknown;
2913
+ };
2914
+ content?: never;
2915
+ };
2916
+ default: components["responses"]["Error"];
2917
+ };
2918
+ };
2585
2919
  workspaceWakeHint: {
2586
2920
  parameters: {
2587
2921
  query?: never;
package/dist/http.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { RetryRecord } from './progress.js';
2
- export declare const SDK_VERSION = "0.14.0";
2
+ export declare const SDK_VERSION = "0.16.0";
3
3
  export interface RequestOptions {
4
4
  query?: Record<string, string | number | boolean | undefined | null>;
5
5
  json?: unknown;
@@ -70,6 +70,12 @@ export declare const POOL_OPTIONS: {
70
70
  * native pooling. An explicitly supplied fetch is untouched. Idle pooled sockets do not keep the process alive.
71
71
  */
72
72
  export declare function defaultFetch(env?: Record<string, string | undefined> | undefined, undiciVersion?: string | undefined): typeof fetch;
73
+ /** Snapshot the caller's env; empty overrides keep a supplied env independent of process.env. */
74
+ export declare function proxyOptions(env: Record<string, string | undefined> | undefined): {
75
+ httpProxy: string;
76
+ httpsProxy: string;
77
+ noProxy: string;
78
+ };
73
79
  export declare function buildUrl(base: string, path: string, query?: RequestOptions['query']): string;
74
80
  /**
75
81
  * True when fetch failed because its connection closed or reset before a response arrived: what a request sees when
package/dist/http.js CHANGED
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { ShardfluxApiError, ShardfluxProtocolError, apiError, isErrorBody, isWorkingQuotaRefusal } from "./errors.js";
13
13
  import { describeFailure } from "./progress.js";
14
- export const SDK_VERSION = '0.14.0';
14
+ export const SDK_VERSION = '0.16.0';
15
15
  export const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
16
16
  /**
17
17
  * How long an idle pooled connection stays reusable (ms): 5 minutes, instead of undici's 4 s default, so the request
@@ -36,7 +36,7 @@ export const POOL_OPTIONS = {
36
36
  connect: { keepAlive: true, keepAliveInitialDelay: TCP_KEEPALIVE_INITIAL_DELAY_MS },
37
37
  };
38
38
  /** One private HTTP/1.1 pool on Node 26+, shared by SDK clients. No global dispatcher changes. */
39
- let nodeFetch;
39
+ const nodeFetches = new Map();
40
40
  /**
41
41
  * Reuses TLS connections. Node 26's bundled undici 8.9 can stall reused connections: use pinned undici with a
42
42
  * private HTTP/1.1-only dispatcher whose idle connections stay reusable for KEEP_ALIVE_TIMEOUT_MS. Other runtimes
@@ -46,27 +46,48 @@ let nodeFetch;
46
46
  export function defaultFetch(env = globalThis.process?.env, undiciVersion = globalThis.process?.versions?.undici) {
47
47
  // Why a fresh connection on Node 26 (its bundled HTTP client, measured): docs/progress/startup-latency.md.
48
48
  const base = (input, init) => fetch(input, init);
49
- if (env?.SHARDFLUX_HTTP_KEEPALIVE === '0')
49
+ const proxy = proxyOptions(env);
50
+ const useProxy = Boolean(proxy.httpProxy || proxy.httpsProxy || proxy.noProxy || env?.NODE_USE_ENV_PROXY === '1');
51
+ if (!useProxy && env?.SHARDFLUX_HTTP_KEEPALIVE === '0')
50
52
  return (input, init) => {
51
53
  const headers = new Headers(init?.headers);
52
54
  headers.set('connection', 'close');
53
55
  return base(input, { ...init, headers });
54
56
  };
55
- if (Number((undiciVersion ?? '').split('.')[0]) < 8 || !undiciVersion || env?.SHARDFLUX_HTTP_KEEPALIVE === '1')
57
+ if (!useProxy && (Number((undiciVersion ?? '').split('.')[0]) < 8 || !undiciVersion || env?.SHARDFLUX_HTTP_KEEPALIVE === '1'))
56
58
  return base;
59
+ const poolKey = useProxy ? JSON.stringify(proxy) : 'direct';
57
60
  return async (input, init) => {
58
- nodeFetch ??= import('undici').then(({ Agent, fetch: pooledFetch }) => {
59
- const dispatcher = new Agent({ ...POOL_OPTIONS, connect: { ...POOL_OPTIONS.connect } });
60
- return async (input, init) => {
61
- const response = await pooledFetch(input, { ...init, dispatcher });
62
- // Web-standard runtime shape; undici and DOM iterator declarations differ.
63
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- Required by consumers compiling with lib.dom instead of only Node types.
64
- return response;
65
- };
66
- });
61
+ let nodeFetch = nodeFetches.get(poolKey);
62
+ if (!nodeFetch) {
63
+ nodeFetch = import('undici').then(({ Agent, EnvHttpProxyAgent, fetch: pooledFetch }) => {
64
+ const options = { ...POOL_OPTIONS, connect: { ...POOL_OPTIONS.connect } };
65
+ const dispatcher = useProxy ? new EnvHttpProxyAgent({ ...options, ...proxy }) : new Agent(options);
66
+ return async (input, init) => {
67
+ const response = await pooledFetch(input, { ...init, dispatcher });
68
+ // Web-standard runtime shape; undici and DOM iterator declarations differ.
69
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- Required by consumers compiling with lib.dom instead of only Node types.
70
+ return response;
71
+ };
72
+ });
73
+ nodeFetches.set(poolKey, nodeFetch);
74
+ }
75
+ if (env?.SHARDFLUX_HTTP_KEEPALIVE === '0') {
76
+ const headers = new Headers(init?.headers);
77
+ headers.set('connection', 'close');
78
+ init = { ...init, headers };
79
+ }
67
80
  return (await nodeFetch)(input, init);
68
81
  };
69
82
  }
83
+ /** Snapshot the caller's env; empty overrides keep a supplied env independent of process.env. */
84
+ export function proxyOptions(env) {
85
+ return {
86
+ httpProxy: env?.http_proxy ?? env?.HTTP_PROXY ?? '',
87
+ httpsProxy: env?.https_proxy ?? env?.HTTPS_PROXY ?? '',
88
+ noProxy: env?.no_proxy ?? env?.NO_PROXY ?? '',
89
+ };
90
+ }
70
91
  export function buildUrl(base, path, query) {
71
92
  const u = new URL(base.replace(/\/+$/, '') + path);
72
93
  for (const [k, v] of Object.entries(query ?? {})) {
package/dist/index.d.ts CHANGED
@@ -14,8 +14,12 @@
14
14
  */
15
15
  export type { components, operations, paths } from './generated/app-api.js';
16
16
  export type { components as CellComponents, paths as CellPaths } from './generated/cell-api.js';
17
- export { BillingApi, Shardflux, WorkspacesApi, fetchBillingCatalog, pickByKey } from './client.js';
18
- export type { AgentSession, AllocationMode, BillingCatalog, BillingSubscription, Caps, CheckoutSession, DiskLayout, Entitlements, FindByKeyOptions, ForkTarget, Invoice, InvoicePage, LifetimeFilter, ListParams, Me, OpenParams, OpenResponse, Operation, Page, PortalSession, PurposeFilter, ResetWorkspaceBody, ResizeAppliesAt, ResizeCpu, ResizeDeferReason, ResizeDisk, ResizeLimitReason, ResizeMemory, ResizeParams, ResizeResult, ResizeResponse, ResumeAnswer, ResumeRequestOptions, ResumeResponse, ShardfluxOptions, SuspendRequest, SuspendWhenIdleOptions, SuspendWhenIdleResponse, SuspendWhenIdleResult, WaitOptions, WorkspaceInputs, WorkspaceLifetime, WorkspaceMemory, WorkspaceOrigin, WorkspacePurpose, WorkspaceView, } from './client.js';
17
+ export { ProjectsRetentionApi, BillingApi, Shardflux, WorkspacesApi, fetchBillingCatalog, pickByKey, workspace } from './client.js';
18
+ export { WorkspaceRef } from './workspace-ref.js';
19
+ export { ReverseTunnel, WorkspaceTunnels } from './tunnels.js';
20
+ export type { ReverseTunnelOptions, ReverseTunnelStats } from './tunnels.js';
21
+ export type { WorkspaceRefFiles, WorkspaceRefParams } from './workspace-ref.js';
22
+ export type { AgentSession, AllocationMode, ComputerUse, BillingCatalog, BillingSubscription, Caps, CheckoutSession, DiskLayout, Entitlements, FindByKeyOptions, ForkTarget, Invoice, InvoicePage, LifetimeFilter, ListParams, Me, RetentionPolicy, ProjectRetentionPolicy, OpenParams, OpenResponse, Operation, Page, PortalSession, PurposeFilter, ResetWorkspaceBody, ResizeAppliesAt, ResizeCpu, ResizeDeferReason, ResizeDisk, ResizeLimitReason, ResizeMemory, ResizeParams, ResizeResult, ResizeResponse, ResumeAnswer, ResumeRequestOptions, ResumeResponse, ShardfluxOptions, SuspendRequest, SuspendWhenIdleOptions, SuspendWhenIdleResponse, SuspendWhenIdleResult, WaitOptions, WorkspaceInputs, WorkspaceLifetime, WorkspaceMemory, WorkspaceOrigin, WorkspacePurpose, WorkspaceView, } from './client.js';
19
23
  export type { FinishedOperation, ForkOptions, LifecycleOptions, ResumeOptions, SuspendOptions, WaitedForkOptions, WaitedLifecycleOptions, WaitedResumeOptions, WaitedSuspendOptions } from './lifecycle.js';
20
24
  export { COLD_BOOT_REASONS, durabilityOf, formatTiming, hostLostOf, isDurable, lostSuspendOf } from './progress.js';
21
25
  export type { ColdBootReason, Durability, HostLost, LostSuspend, LifecycleAction, LifecyclePhase, LifecycleTiming, ProgressEvent, ProgressListener, RetryRecord, ServerTiming, TimingOutcome, TimingPhase, } from './progress.js';
@@ -30,7 +34,10 @@ export { tarEnd, tarHeader, tarPadding } from './tar.js';
30
34
  export type { TarEntry, TarEntryType } from './tar.js';
31
35
  export type { BuildFromFileEvent, BuildFromFileOptions, BuildFromFileResult, BuildFromRecipeOptions, BuilderAvailability, CreateDraftBody, CreateDraftParams, CreateTemplateBuildParams, CreateTestInstanceBody, CreateVersionTestInstanceBody, CreateVersionTestInstanceParams, DraftOpened, LocalUpload, DraftState, OpenTestInstanceParams, OrgTemplateStorage, PublishDraftBody, PublishDraftParams, PutUploadOptions, SaveAsTemplateBody, SaveAsTemplateParams, SaveAsTemplateResponse, TemplateBuild, TemplateBuildLogUrl, TemplateBuildRecipeV2, TemplateBuildRegistrationState, TemplateBuildState, TemplateCategory, TemplateDefaults, TemplateDefaultsInput, TemplateDetail, TemplateDiffChange, TemplateDiffEntry, TemplateDiffPage, TemplateDiffParams, TemplateDraft, TemplateDraftSummary, TemplateEgressDefault, TemplateFileEntry, TemplateFilePage, TemplateFilesParams, TemplateFilesSummary, TemplateInput, TemplateLanguage, TemplateLanguages, TemplateOwner, TemplatePackage, TemplatePackageEcosystem, TemplatePackagePage, TemplateRecipe, TemplateRecipeV2, TemplateRecipeV2File, TemplateService, TemplateSettings, TemplateSettingsInput, TemplateSource, TemplateStartCommand, TemplateStorage, TemplateStorageWarning, TemplateSummary, TemplateUpload, TemplateUploadRequest, TemplateUploadResponse, TemplateUploadResult, TemplateVersion, TemplateVersionImmutable, TemplateVersionRecipe, TemplateVersionState, UploadData, WaitForBuildOptions, WorkspaceStartup, } from './templates.js';
32
36
  export { WorkspacePorts } from './ports.js';
33
- export type { ExposePortResult, ExposedPort, PortCallbackResponse, PortCallbackUrl, PortLink, PortLinkOptions, PortLinkResponse, PortToken, PortTokenOptions, PortTokenResponse, PortView } from './ports.js';
37
+ export { exitCodePosix } from './exit-code.js';
38
+ export { COMPUTER_TOOLSET, WorkspaceComputer, computerToolset, decodeComputerImage } from './computer.js';
39
+ export type { BeforeComputerAction, ComputerActOptions, ComputerScreenshot, ComputerStream, ComputerStreamOptions, ComputerToolResult, ComputerToolsetOptions, ToolUseBlockLike } from './computer.js';
40
+ export type { ExposePortResult, ExposedPort, PortCallbackResponse, PortCallbackUrl, PortLink, PortEmbedOptions, PortLinkOptions, PortLinkResponse, PortToken, PortTokenOptions, PortTokenResponse, PortView } from './ports.js';
34
41
  export { SecretsApi, WorkspaceSecrets } from './secrets.js';
35
42
  export type { BoundSecretStatus, CreateOrganizationSecretParams, CreateSecretParams, Secret, SecretAccessEvent, SecretPermissions, SecretScope, SecretVersion, UpdateSecretParams, WorkspaceSecretBindings, } from './secrets.js';
36
43
  export { EgressPolicyApi } from './egress.js';
@@ -44,15 +51,15 @@ export type { HintOptions, HintResult, WakeOptions } from './workspace.js';
44
51
  export { CellClient, DEFAULT_TRANSITION_TIMEOUT_MS, cellPath, ndjson } from './cell.js';
45
52
  export { EXECUTION_ID, ExecutionResult, newExecutionId } from './executions.js';
46
53
  export type { ExecutionChange, ExecutionError, ExecutionGetOptions, ExecutionResultBody, ExecutionRunOptions, ExecutionState } from './executions.js';
47
- export type { TreeRevisionOptions, BrowserContent, BrowserContentRequest, BrowserScreenshotRequest, CellClientOptions, ExecSession, ExecStartRequest, MemoryGrow, BurstSummary, BurstError, FileEdit, FileInfo, FileList, FilePatchEdit, FilePatchParams, FilePatchRequest, FilePatchResult, FileReadResult, FileRevision, FileSearchMatch, FileSearchOptions, FileSearchRequest, FileSearchResponse, FileSearchResult, FileWriteResult, GitResult, GitStatus, OutputEvent, ProcessList, PtyOpenRequest, PtySession, Residency, ResourceHint, RunOptions, RunResult, ServedFrom, Signal, WakeHintResult, WorkspaceChange, WorkspaceChangeKind, WorkspaceChangesPage, WorkspaceChangesParams, WorkspaceChangesSummary, } from './cell.js';
54
+ export type { TreeRevisionOptions, BrowserContent, BrowserContentRequest, BrowserScreenshotRequest, CellClientOptions, ComputerAction, ComputerActionName, ComputerActionResult, ComputerActionsRequest, ComputerActionsResult, ComputerImage, ComputerStartRequest, ComputerStatus, ComputerStreamInfo, ExecSession, ExecStartRequest, MemoryGrow, BurstSummary, BurstError, FileEdit, FileInfo, FileList, FilePatchEdit, FilePatchParams, FilePatchRequest, FilePatchResult, FileReadResult, FileRevision, FileSearchMatch, FileSearchOptions, FileSearchRequest, FileSearchResponse, FileSearchResult, FileWriteResult, GitResult, GitStatus, OutputEvent, ProcessList, PtyOpenRequest, PtySession, Residency, ResourceHint, RunOptions, RunResult, ServedFrom, Signal, WakeHintResult, WorkspaceChange, WorkspaceChangeKind, WorkspaceChangesPage, WorkspaceChangesParams, WorkspaceChangesSummary, } from './cell.js';
48
55
  export { ToolTokenManager } from './tokens.js';
49
56
  export type { ToolName, ToolToken, ToolTokenOptions } from './tokens.js';
50
57
  export { ToolArgumentError, executeToolCall, toAnthropicTools, toOpenAITools, validateArgs, workspaceTools } from './tools.js';
51
- export type { AnthropicToolDefinition, JsonSchema, OpenAIChatToolDefinition, OpenAIResponsesToolDefinition, WorkspaceTool, WorkspaceToolsOptions } from './tools.js';
58
+ export type { AnthropicToolDefinition, JsonSchema, OpenAIChatToolDefinition, OpenAIResponsesToolDefinition, ToolTarget, WorkspaceTool, WorkspaceToolsOptions } from './tools.js';
52
59
  export { CaptureError, ToolCallCapture, captureTool } from './capture.js';
53
60
  export type { CallLike, CallRef, CaptureCall, CaptureErrorKind, CaptureEvent, CaptureFlushResult, CapturePart, CaptureSelector, CaptureSource, CaptureStats, CaptureStatus, DropReason, ToolCallCaptureOptions, WrapOptions, } from './capture.js';
54
61
  export type { AiSdkAdapter, AiSdkToolEndEvent, AnthropicAdapter, ClaudeAdapter, ClaudeCaptureHooks, ClaudeHookCallback, ClaudeHookMatcher, LangChainAdapter, LangChainToolHandler, MastraAdapter, MastraAfterToolCallContext, McpAdapter, OpenAIAgentsAdapter, } from './capture-adapters.js';
55
- export { DurabilityLostError, ExecStartError, NotSupportedForModeError, OperationFailedError, OperationTimeoutError, ShardfluxApiError, ShardfluxProtocolError, TreeRevisionMismatchError } from './errors.js';
62
+ export { FileNotFoundError, DurabilityLostError, ExecStartError, NotSupportedForModeError, OperationFailedError, OperationTimeoutError, ShardfluxApiError, ShardfluxProtocolError, TreeRevisionMismatchError } from './errors.js';
56
63
  export type { AppErrorCode, CellErrorCode, ErrorCode, ErrorReason, KnownErrorReason, WorkspaceMode } from './errors.js';
57
64
  export { SDK_VERSION } from './http.js';
58
65
  export { API_KEY_TOOL_PERMISSIONS, AccountApiKeysApi, AccountAuditApi, AccountAuthApi, AccountBillingApi, AccountExportsApi, AccountInvitationsApi, AccountMembersApi, AccountOrganizationsApi, AccountProjectsApi, AccountTemplatesApi, AccountTotpApi, AccountUserApi, CheckoutTimeoutError, OrganizationExportsApi, SESSION_TOKEN_PATTERN, ShardfluxAccount, isSessionToken, parseEmailToken, } from './account.js';
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- export { BillingApi, Shardflux, WorkspacesApi, fetchBillingCatalog, pickByKey } from "./client.js";
1
+ export { ProjectsRetentionApi, BillingApi, Shardflux, WorkspacesApi, fetchBillingCatalog, pickByKey, workspace } from "./client.js";
2
+ export { WorkspaceRef } from "./workspace-ref.js";
3
+ export { ReverseTunnel, WorkspaceTunnels } from "./tunnels.js";
2
4
  export { COLD_BOOT_REASONS, durabilityOf, formatTiming, hostLostOf, isDurable, lostSuspendOf } from "./progress.js";
3
5
  export { FEEDBACK_CATEGORIES, FEEDBACK_MESSAGE_MAX_LENGTH } from "./feedback.js";
4
6
  export { UsageApi } from "./usage.js";
@@ -6,6 +8,9 @@ export { TemplateBuildTimeoutError, TemplateBuildsApi, TemplateDraftApi, Templat
6
8
  export { TemplateFileError, packDirectory, parseTemplateText, readTemplateFile } from "./template-file.js";
7
9
  export { tarEnd, tarHeader, tarPadding } from "./tar.js";
8
10
  export { WorkspacePorts } from "./ports.js";
11
+ // Computer use (0.15.0+, contracts §45).
12
+ export { exitCodePosix } from "./exit-code.js";
13
+ export { COMPUTER_TOOLSET, WorkspaceComputer, computerToolset, decodeComputerImage } from "./computer.js";
9
14
  export { SecretsApi, WorkspaceSecrets } from "./secrets.js";
10
15
  export { EgressPolicyApi } from "./egress.js";
11
16
  export { VolumesApi } from "./volumes.js";
@@ -16,7 +21,7 @@ export { EXECUTION_ID, ExecutionResult, newExecutionId } from "./executions.js";
16
21
  export { ToolTokenManager } from "./tokens.js";
17
22
  export { ToolArgumentError, executeToolCall, toAnthropicTools, toOpenAITools, validateArgs, workspaceTools } from "./tools.js";
18
23
  export { CaptureError, ToolCallCapture, captureTool } from "./capture.js";
19
- export { DurabilityLostError, ExecStartError, NotSupportedForModeError, OperationFailedError, OperationTimeoutError, ShardfluxApiError, ShardfluxProtocolError, TreeRevisionMismatchError } from "./errors.js";
24
+ export { FileNotFoundError, DurabilityLostError, ExecStartError, NotSupportedForModeError, OperationFailedError, OperationTimeoutError, ShardfluxApiError, ShardfluxProtocolError, TreeRevisionMismatchError } from "./errors.js";
20
25
  export { SDK_VERSION } from "./http.js";
21
26
  export { API_KEY_TOOL_PERMISSIONS, AccountApiKeysApi, AccountAuditApi, AccountAuthApi, AccountBillingApi, AccountExportsApi, AccountInvitationsApi, AccountMembersApi, AccountOrganizationsApi, AccountProjectsApi, AccountTemplatesApi, AccountTotpApi, AccountUserApi, CheckoutTimeoutError, OrganizationExportsApi, SESSION_TOKEN_PATTERN, ShardfluxAccount, isSessionToken, parseEmailToken, } from "./account.js";
22
27
  export { codexIdentityProof } from "./codex-proof.js";
package/dist/ports.d.ts CHANGED
@@ -75,7 +75,14 @@ export interface PortTokenOptions {
75
75
  /** Lifetime in seconds: 60-86400 (default 3600). */
76
76
  ttlSeconds?: number;
77
77
  }
78
+ /** Origins allowed to frame the linked port (§48). Validated by the API. */
79
+ export interface PortEmbedOptions {
80
+ /** 1–10 distinct canonical HTTPS origins, without paths or wildcards; 256 characters each, 2048 total. */
81
+ origins: string[];
82
+ }
78
83
  export interface PortLinkOptions {
84
+ /** Opt in to a partitioned browser session and this frame allowlist. */
85
+ embed?: PortEmbedOptions;
79
86
  /** Lifetime of the link and of the browser session it starts, in seconds: 60-604800 (default 86400). */
80
87
  ttlSeconds?: number;
81
88
  /** Where the link lands: a path starting with one `/`, printable ASCII, query allowed (default `/`). */
package/dist/ports.js CHANGED
@@ -47,7 +47,7 @@ export class WorkspacePorts {
47
47
  }
48
48
  /** A signed link that opens the port in a browser. Share it like a password: anyone with it can open the port until it expires. */
49
49
  async link(port, opts = {}) {
50
- const body = await this.#ctx.http.json('POST', this.#path(port, '/links'), { json: { ...(opts.ttlSeconds !== undefined ? { ttl_seconds: opts.ttlSeconds } : {}), ...(opts.path !== undefined ? { path: opts.path } : {}) } }, this.#ctx.authorization);
50
+ const body = await this.#ctx.http.json('POST', this.#path(port, '/links'), { json: { ...(opts.embed !== undefined ? { embed: opts.embed } : {}), ...(opts.ttlSeconds !== undefined ? { ttl_seconds: opts.ttlSeconds } : {}), ...(opts.path !== undefined ? { path: opts.path } : {}) } }, this.#ctx.authorization);
51
51
  return { url: body.url, expiresAt: body.expires_at };
52
52
  }
53
53
  /** Creates the port's callback URL, or replaces it (the previous one stops working). Its secret is shown only here. */
@@ -18,7 +18,7 @@
18
18
  import type { components } from './generated/app-api.js';
19
19
  type Operation = components['schemas']['Operation'];
20
20
  /** The SDK call a trace follows. `wait` is a direct waitForOperation(); `token` a tool token fetched for tool calls. */
21
- export type LifecycleAction = 'open' | 'suspend' | 'resume' | 'snapshot' | 'fork' | 'delete' | 'close' | 'reset' | 'resize' | 'wake' | 'wait' | 'token';
21
+ export type LifecycleAction = 'open' | 'suspend' | 'resume' | 'snapshot' | 'fork' | 'delete' | 'close' | 'reset' | 'resize' | 'upgrade' | 'wake' | 'wait' | 'token';
22
22
  /**
23
23
  * - `request`: an API request that starts or joins the operation. A held open (`Prefer: wait`) spends the server's
24
24
  * hold here (reason `held`), so the states inside it show only in the server timing.
@@ -160,7 +160,7 @@ export interface LostSuspend {
160
160
  */
161
161
  export type ColdBootReason = (typeof COLD_BOOT_REASONS)[number] | (string & {});
162
162
  /** Every {@link ColdBootReason} this version knows (0.14.0+). */
163
- export declare const COLD_BOOT_REASONS: readonly ["runtime_changed", "host_lost", "runtime_retired"];
163
+ export declare const COLD_BOOT_REASONS: readonly ["runtime_changed", "host_lost", "runtime_retired", "upgraded"];
164
164
  /**
165
165
  * `result.host_lost` (0.13.1+), camelCased: the machine the workspace ran on failed. The workspace was moved to
166
166
  * `suspended` at that moment, and its next use (a resume, a tool call's wake, an open) restored it. See the lifecycle
package/dist/progress.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Every {@link ColdBootReason} this version knows (0.14.0+). */
2
- export const COLD_BOOT_REASONS = ['runtime_changed', 'host_lost', 'runtime_retired'];
2
+ export const COLD_BOOT_REASONS = ['runtime_changed', 'host_lost', 'runtime_retired', 'upgraded'];
3
3
  const DURABILITY_STATES = new Set(['pending', 'durable', 'lost']);
4
4
  /**
5
5
  * The durable copy of a suspend or fork operation (0.12.0+): `result.durability` camelCased, or null when the result has
@@ -215,6 +215,8 @@ export interface TemplateSummary {
215
215
  memory_mib: number | null;
216
216
  idle_policy: string | null;
217
217
  };
218
+ /** Computer use (0.15.0+, contracts §45.1): the template's switch for its workspaces (a workspace may override it). */
219
+ computer_use: boolean;
218
220
  open_version: TemplateVersion | null;
219
221
  /** The live draft (organization templates in dev mode), or null. */
220
222
  draft: TemplateDraftSummary | null;
@@ -900,6 +902,16 @@ export declare class TemplatesApi {
900
902
  includeArchived?: boolean;
901
903
  owner?: TemplateOwner;
902
904
  }): Promise<TemplateDetail>;
905
+ /**
906
+ * Computer use (0.15.0+, contracts §45.1): switches it on or off for every workspace of one of your organization's
907
+ * templates (a workspace may override it with setComputerUse). 403 for platform templates (switch a workspace on
908
+ * instead). Owners and admins (sessions) or API keys of the organization with a tool permission.
909
+ */
910
+ setComputerUse(slug: string, enabled: boolean, params?: {
911
+ organizationId?: string;
912
+ }): Promise<{
913
+ enabled: boolean;
914
+ }>;
903
915
  /** Like get() but resolves to null on 404 (unknown slug or outside the organization). */
904
916
  find(slug: string, params?: {
905
917
  organizationId?: string;
package/dist/templates.js CHANGED
@@ -693,6 +693,15 @@ export class TemplatesApi {
693
693
  const path = params.organizationId === undefined ? `/v1/templates/${enc(slug)}` : `/v1/organizations/${enc(params.organizationId)}/templates/${enc(slug)}`;
694
694
  return this.#ctx().http.json('GET', path, { query: { include_archived: params.includeArchived, owner: params.owner } }, this.#ctx().authorization);
695
695
  }
696
+ /**
697
+ * Computer use (0.15.0+, contracts §45.1): switches it on or off for every workspace of one of your organization's
698
+ * templates (a workspace may override it with setComputerUse). 403 for platform templates (switch a workspace on
699
+ * instead). Owners and admins (sessions) or API keys of the organization with a tool permission.
700
+ */
701
+ async setComputerUse(slug, enabled, params = {}) {
702
+ const path = params.organizationId === undefined ? `/v1/templates/${enc(slug)}/computer-use` : `/v1/organizations/${enc(params.organizationId)}/templates/${enc(slug)}/computer-use`;
703
+ return this.#ctx().http.json('PUT', path, { json: { enabled } }, this.#ctx().authorization);
704
+ }
696
705
  /** Like get() but resolves to null on 404 (unknown slug or outside the organization). */
697
706
  async find(slug, params = {}) {
698
707
  try {