@shardflux/sdk 0.13.1 → 0.15.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.
@@ -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;
@@ -953,6 +1034,12 @@ export interface components {
953
1034
  burst_vcpus?: number;
954
1035
  /** @description The burst VM's memory in MiB (burst always only; default the host's, 8192), at most the plan's workspace memory ceiling. */
955
1036
  burst_memory_mib?: number;
1037
+ /**
1038
+ * @description Contracts §41.1: whether an elastic workspace's memory grows before the command starts. `heavy` grows it to the exec-start size first; `light` starts at once (pressure grows cover a spike); `auto` (default) grows only for a heavy command family (package installers, test runners, compilers, type checkers, bundlers). Changes only elastic workspaces in memory layout v2; any other value is 422 validation_failed (details.field resource_hint).
1039
+ * @default auto
1040
+ * @enum {string}
1041
+ */
1042
+ resource_hint?: "auto" | "light" | "heavy";
956
1043
  };
957
1044
  /** @description Names of customer secrets (contracts §17) to inject as environment variables NAME=value of this process only. The cell resolves them at session start through the API with the caller's tool token (permission-checked and audited by the API); values are never logged, persisted or returned by the cell. Any name the caller may not use (unknown, not permitted for this workspace/project/tool) refuses the whole start with 403 forbidden (details.reason secret_not_available, details.names); nothing is started. A name that is also a key of `env` is refused (422 validation_failed). Requires a workspace tool token (browser stream tickets cannot resolve secrets: 403, details.reason secret_refs_require_tool_token). Resolution failures: 401 (token revoked/expired), 409 stale_epoch, 429 rate_limited, 503 dependency_unavailable. A retried start with the same session_id re-resolves the names; if a value changed since the first start the host refuses the different request (409 conflict). */
958
1045
  SecretRefs: string[];
@@ -1484,6 +1571,111 @@ export interface components {
1484
1571
  }[];
1485
1572
  stderr?: string;
1486
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
+ };
1487
1679
  BrowserScreenshotRequest: {
1488
1680
  url: string;
1489
1681
  /** @default 1280 */
@@ -2576,6 +2768,152 @@ export interface operations {
2576
2768
  default: components["responses"]["Error"];
2577
2769
  };
2578
2770
  };
2771
+ computerStatus: {
2772
+ parameters: {
2773
+ query?: never;
2774
+ header?: never;
2775
+ path: {
2776
+ workspace_id: components["parameters"]["WorkspaceId"];
2777
+ };
2778
+ cookie?: never;
2779
+ };
2780
+ requestBody?: never;
2781
+ responses: {
2782
+ /** @description Desktop state. */
2783
+ 200: {
2784
+ headers: {
2785
+ [name: string]: unknown;
2786
+ };
2787
+ content: {
2788
+ "application/json": components["schemas"]["ComputerStatus"];
2789
+ };
2790
+ };
2791
+ default: components["responses"]["Error"];
2792
+ };
2793
+ };
2794
+ computerStart: {
2795
+ parameters: {
2796
+ query?: never;
2797
+ header?: never;
2798
+ path: {
2799
+ workspace_id: components["parameters"]["WorkspaceId"];
2800
+ };
2801
+ cookie?: never;
2802
+ };
2803
+ requestBody?: {
2804
+ content: {
2805
+ "application/json": components["schemas"]["ComputerStartRequest"];
2806
+ };
2807
+ };
2808
+ responses: {
2809
+ /** @description Desktop state. */
2810
+ 200: {
2811
+ headers: {
2812
+ [name: string]: unknown;
2813
+ };
2814
+ content: {
2815
+ "application/json": components["schemas"]["ComputerStatus"];
2816
+ };
2817
+ };
2818
+ default: components["responses"]["Error"];
2819
+ };
2820
+ };
2821
+ computerStop: {
2822
+ parameters: {
2823
+ query?: never;
2824
+ header?: never;
2825
+ path: {
2826
+ workspace_id: components["parameters"]["WorkspaceId"];
2827
+ };
2828
+ cookie?: never;
2829
+ };
2830
+ requestBody?: never;
2831
+ responses: {
2832
+ /** @description Stopped */
2833
+ 204: {
2834
+ headers: {
2835
+ [name: string]: unknown;
2836
+ };
2837
+ content?: never;
2838
+ };
2839
+ default: components["responses"]["Error"];
2840
+ };
2841
+ };
2842
+ computerActions: {
2843
+ parameters: {
2844
+ query?: never;
2845
+ header?: never;
2846
+ path: {
2847
+ workspace_id: components["parameters"]["WorkspaceId"];
2848
+ };
2849
+ cookie?: never;
2850
+ };
2851
+ requestBody: {
2852
+ content: {
2853
+ "application/json": components["schemas"]["ComputerActionsRequest"];
2854
+ };
2855
+ };
2856
+ responses: {
2857
+ /** @description Per-action results. */
2858
+ 200: {
2859
+ headers: {
2860
+ [name: string]: unknown;
2861
+ };
2862
+ content: {
2863
+ "application/json": components["schemas"]["ComputerActionsResult"];
2864
+ };
2865
+ };
2866
+ default: components["responses"]["Error"];
2867
+ };
2868
+ };
2869
+ computerStreamStart: {
2870
+ parameters: {
2871
+ query?: never;
2872
+ header?: never;
2873
+ path: {
2874
+ workspace_id: components["parameters"]["WorkspaceId"];
2875
+ };
2876
+ cookie?: never;
2877
+ };
2878
+ requestBody?: {
2879
+ content: {
2880
+ "application/json": components["schemas"]["ComputerStreamRequest"];
2881
+ };
2882
+ };
2883
+ responses: {
2884
+ /** @description Viewer started. */
2885
+ 200: {
2886
+ headers: {
2887
+ [name: string]: unknown;
2888
+ };
2889
+ content: {
2890
+ "application/json": components["schemas"]["ComputerStream"];
2891
+ };
2892
+ };
2893
+ default: components["responses"]["Error"];
2894
+ };
2895
+ };
2896
+ computerStreamStop: {
2897
+ parameters: {
2898
+ query?: never;
2899
+ header?: never;
2900
+ path: {
2901
+ workspace_id: components["parameters"]["WorkspaceId"];
2902
+ };
2903
+ cookie?: never;
2904
+ };
2905
+ requestBody?: never;
2906
+ responses: {
2907
+ /** @description Viewers stopped. */
2908
+ 204: {
2909
+ headers: {
2910
+ [name: string]: unknown;
2911
+ };
2912
+ content?: never;
2913
+ };
2914
+ default: components["responses"]["Error"];
2915
+ };
2916
+ };
2579
2917
  workspaceWakeHint: {
2580
2918
  parameters: {
2581
2919
  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.13.1";
2
+ export declare const SDK_VERSION = "0.15.0";
3
3
  export interface RequestOptions {
4
4
  query?: Record<string, string | number | boolean | undefined | null>;
5
5
  json?: unknown;
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.13.1';
14
+ export const SDK_VERSION = '0.15.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
package/dist/index.d.ts CHANGED
@@ -14,10 +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, ResumeAnswer, ResumeRequestOptions, ResumeResponse, ShardfluxOptions, SuspendRequest, SuspendWhenIdleOptions, SuspendWhenIdleResponse, SuspendWhenIdleResult, WaitOptions, WorkspaceInputs, WorkspaceLifetime, WorkspaceMemory, WorkspaceOrigin, WorkspacePurpose, WorkspaceView, } from './client.js';
17
+ export { BillingApi, Shardflux, WorkspacesApi, fetchBillingCatalog, pickByKey, workspace } from './client.js';
18
+ export { WorkspaceRef } from './workspace-ref.js';
19
+ export type { WorkspaceRefFiles, WorkspaceRefParams } from './workspace-ref.js';
20
+ export type { AgentSession, AllocationMode, ComputerUse, 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';
19
21
  export type { FinishedOperation, ForkOptions, LifecycleOptions, ResumeOptions, SuspendOptions, WaitedForkOptions, WaitedLifecycleOptions, WaitedResumeOptions, WaitedSuspendOptions } from './lifecycle.js';
20
- export { durabilityOf, formatTiming, hostLostOf, isDurable, lostSuspendOf } from './progress.js';
22
+ export { COLD_BOOT_REASONS, durabilityOf, formatTiming, hostLostOf, isDurable, lostSuspendOf } from './progress.js';
21
23
  export type { ColdBootReason, Durability, HostLost, LostSuspend, LifecycleAction, LifecyclePhase, LifecycleTiming, ProgressEvent, ProgressListener, RetryRecord, ServerTiming, TimingOutcome, TimingPhase, } from './progress.js';
22
24
  export { FEEDBACK_CATEGORIES, FEEDBACK_MESSAGE_MAX_LENGTH } from './feedback.js';
23
25
  export type { AccountFeedbackParams, FeedbackCategory, FeedbackContext, FeedbackReceipt, SendFeedbackParams } from './feedback.js';
@@ -29,6 +31,10 @@ export type { PackedFile, YamlParser } from './template-file.js';
29
31
  export { tarEnd, tarHeader, tarPadding } from './tar.js';
30
32
  export type { TarEntry, TarEntryType } from './tar.js';
31
33
  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';
34
+ export { WorkspacePorts } from './ports.js';
35
+ export { COMPUTER_TOOLSET, WorkspaceComputer, computerToolset, decodeComputerImage } from './computer.js';
36
+ export type { ComputerActOptions, ComputerScreenshot, ComputerStream, ComputerStreamOptions, ComputerToolResult, ComputerToolsetOptions, ToolUseBlockLike } from './computer.js';
37
+ export type { ExposePortResult, ExposedPort, PortCallbackResponse, PortCallbackUrl, PortLink, PortLinkOptions, PortLinkResponse, PortToken, PortTokenOptions, PortTokenResponse, PortView } from './ports.js';
32
38
  export { SecretsApi, WorkspaceSecrets } from './secrets.js';
33
39
  export type { BoundSecretStatus, CreateOrganizationSecretParams, CreateSecretParams, Secret, SecretAccessEvent, SecretPermissions, SecretScope, SecretVersion, UpdateSecretParams, WorkspaceSecretBindings, } from './secrets.js';
34
40
  export { EgressPolicyApi } from './egress.js';
@@ -42,11 +48,11 @@ export type { HintOptions, HintResult, WakeOptions } from './workspace.js';
42
48
  export { CellClient, DEFAULT_TRANSITION_TIMEOUT_MS, cellPath, ndjson } from './cell.js';
43
49
  export { EXECUTION_ID, ExecutionResult, newExecutionId } from './executions.js';
44
50
  export type { ExecutionChange, ExecutionError, ExecutionGetOptions, ExecutionResultBody, ExecutionRunOptions, ExecutionState } from './executions.js';
45
- 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, RunOptions, RunResult, ServedFrom, Signal, WakeHintResult, WorkspaceChange, WorkspaceChangeKind, WorkspaceChangesPage, WorkspaceChangesParams, WorkspaceChangesSummary, } from './cell.js';
51
+ 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';
46
52
  export { ToolTokenManager } from './tokens.js';
47
53
  export type { ToolName, ToolToken, ToolTokenOptions } from './tokens.js';
48
54
  export { ToolArgumentError, executeToolCall, toAnthropicTools, toOpenAITools, validateArgs, workspaceTools } from './tools.js';
49
- export type { AnthropicToolDefinition, JsonSchema, OpenAIChatToolDefinition, OpenAIResponsesToolDefinition, WorkspaceTool, WorkspaceToolsOptions } from './tools.js';
55
+ export type { AnthropicToolDefinition, JsonSchema, OpenAIChatToolDefinition, OpenAIResponsesToolDefinition, ToolTarget, WorkspaceTool, WorkspaceToolsOptions } from './tools.js';
50
56
  export { CaptureError, ToolCallCapture, captureTool } from './capture.js';
51
57
  export type { CallLike, CallRef, CaptureCall, CaptureErrorKind, CaptureEvent, CaptureFlushResult, CapturePart, CaptureSelector, CaptureSource, CaptureStats, CaptureStatus, DropReason, ToolCallCaptureOptions, WrapOptions, } from './capture.js';
52
58
  export type { AiSdkAdapter, AiSdkToolEndEvent, AnthropicAdapter, ClaudeAdapter, ClaudeCaptureHooks, ClaudeHookCallback, ClaudeHookMatcher, LangChainAdapter, LangChainToolHandler, MastraAdapter, MastraAfterToolCallContext, McpAdapter, OpenAIAgentsAdapter, } from './capture-adapters.js';
@@ -54,7 +60,9 @@ export { DurabilityLostError, ExecStartError, NotSupportedForModeError, Operatio
54
60
  export type { AppErrorCode, CellErrorCode, ErrorCode, ErrorReason, KnownErrorReason, WorkspaceMode } from './errors.js';
55
61
  export { SDK_VERSION } from './http.js';
56
62
  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';
57
- export type { AccountClientOptions, AccountDeletion, AccountDeletionCanceled, AccountDeletionScheduled, ApiKey, ApiKeyPage, ApiKeyToolPermission, AuditExportParams, AuthSessionInfo, AuthSessionPage, AuthSessionState, AuthUser, BillingInvoicePage, BillingPortalSession, CheckoutStatus, CreateApiKeyParams, CreatedApiKey, DataExport, EmailChangeConfirmResult, EmailChangeResult, Invitation, InvitationPage, LoginResult, Member, MemberPage, MemberRole, MfaChallengeResult, Organization, OrganizationDeletion, OrganizationDeletionResult, OrganizationPage, OrganizationRole, OrganizationWorkspacePage, OrganizationWorkspacesParams, PageParams, PasswordChangeResult, PasswordResetConfirmResult, PasswordResetRequestResult, Project, ProjectPage, RecoveryCodes, RegisterResult, ResendVerificationResult, SessionTokenUpdate, ShardfluxAccountOptions, SpendPolicyUpdate, StepUpResult, TotpConfirmResult, TotpDisableResult, TotpEnrollment, VerifyEmailResult, WaitForCheckoutOptions, } from './account.js';
63
+ export { codexIdentityProof } from './codex-proof.js';
64
+ export type { CodexIdentityProof, CodexProofOptions, CodexProofUnavailable } from './codex-proof.js';
65
+ export type { AccountClientOptions, AccountDeletion, AccountDeletionCanceled, AccountDeletionScheduled, ApiKey, ApiKeyPage, ApiKeyToolPermission, AuditExportParams, AuthSessionInfo, AuthSessionPage, AuthSessionState, AuthUser, BillingInvoicePage, BillingPortalSession, CheckoutStatus, CreateApiKeyParams, CreatedApiKey, DataExport, EmailChangeConfirmResult, EmailChangeResult, Invitation, InvitationPage, LoginResult, Member, MemberPage, MemberRole, MfaChallengeResult, Organization, OrganizationDeletion, OrganizationDeletionResult, OrganizationPage, OrganizationRole, OrganizationWorkspacePage, OrganizationWorkspacesParams, PageParams, PasswordChangeResult, PasswordResetConfirmResult, PasswordResetRequestResult, Project, ProjectPage, RecoveryCodes, RegisterResult, SignupResult, SignupAccess, EmailCodeResult, ResendVerificationResult, SessionTokenUpdate, ShardfluxAccountOptions, SpendPolicyUpdate, StepUpResult, TotpConfirmResult, TotpDisableResult, TotpEnrollment, VerifyEmailResult, WaitForCheckoutOptions, } from './account.js';
58
66
  export { checkClientVersion, clientVersionStatus, compareVersions, versionCheckDisabledByEnv } from './version-check.js';
59
67
  export type { CheckClientVersionOptions, ClientEcosystem, ClientVersionEntry, ClientVersionStatus, ClientVersionStatusKind, ClientVersions, VersionCheckIdentity, VersionCheckOption, } from './version-check.js';
60
68
  export { isWorkspaceGone } from './errors.js';
package/dist/index.js CHANGED
@@ -1,10 +1,14 @@
1
- export { BillingApi, Shardflux, WorkspacesApi, fetchBillingCatalog, pickByKey } from "./client.js";
2
- export { durabilityOf, formatTiming, hostLostOf, isDurable, lostSuspendOf } from "./progress.js";
1
+ export { BillingApi, Shardflux, WorkspacesApi, fetchBillingCatalog, pickByKey, workspace } from "./client.js";
2
+ export { WorkspaceRef } from "./workspace-ref.js";
3
+ export { COLD_BOOT_REASONS, durabilityOf, formatTiming, hostLostOf, isDurable, lostSuspendOf } from "./progress.js";
3
4
  export { FEEDBACK_CATEGORIES, FEEDBACK_MESSAGE_MAX_LENGTH } from "./feedback.js";
4
5
  export { UsageApi } from "./usage.js";
5
6
  export { TemplateBuildTimeoutError, TemplateBuildsApi, TemplateDraftApi, TemplatePackagesApi, TemplateUploadError, TemplateUploadsApi, TemplateVersionTestInstancesApi, TemplateVersionsApi, TemplatesApi, buildSettled, saveAsTemplateBody, } from "./templates.js";
6
7
  export { TemplateFileError, packDirectory, parseTemplateText, readTemplateFile } from "./template-file.js";
7
8
  export { tarEnd, tarHeader, tarPadding } from "./tar.js";
9
+ export { WorkspacePorts } from "./ports.js";
10
+ // Computer use (0.15.0+, contracts §45).
11
+ export { COMPUTER_TOOLSET, WorkspaceComputer, computerToolset, decodeComputerImage } from "./computer.js";
8
12
  export { SecretsApi, WorkspaceSecrets } from "./secrets.js";
9
13
  export { EgressPolicyApi } from "./egress.js";
10
14
  export { VolumesApi } from "./volumes.js";
@@ -18,6 +22,7 @@ export { CaptureError, ToolCallCapture, captureTool } from "./capture.js";
18
22
  export { DurabilityLostError, ExecStartError, NotSupportedForModeError, OperationFailedError, OperationTimeoutError, ShardfluxApiError, ShardfluxProtocolError, TreeRevisionMismatchError } from "./errors.js";
19
23
  export { SDK_VERSION } from "./http.js";
20
24
  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";
25
+ export { codexIdentityProof } from "./codex-proof.js";
21
26
  export { checkClientVersion, clientVersionStatus, compareVersions, versionCheckDisabledByEnv } from "./version-check.js";
22
27
  export { isWorkspaceGone } from "./errors.js";
23
28
  export { defaultFetch } from "./http.js";
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Inbound ports (0.14.0; contracts §39.3): serve a TCP port of a processful workspace at its own HTTPS URL,
3
+ * `https://<port>-<handle>.<ingress domain>`. Every port is private: a request carries a port token
4
+ * (`Authorization: Bearer sfp_…`), a signed link's browser session, or arrives on the port's callback URL. A request
5
+ * to a suspended or parked workspace wakes it and is served once it runs.
6
+ *
7
+ * const { url } = await workspace.ports.expose(3000);
8
+ * const { token } = await workspace.ports.token(3000);
9
+ * await fetch(url, { headers: { authorization: `Bearer ${token}` } });
10
+ *
11
+ * Types are written by hand (checked against the generated contract in type-checks.ts).
12
+ */
13
+ import type { components, operations } from './generated/app-api.js';
14
+ import type { ClientContext } from './client.js';
15
+ type Created<Op> = Op extends {
16
+ responses: {
17
+ 201: {
18
+ content: {
19
+ 'application/json': infer T;
20
+ };
21
+ };
22
+ };
23
+ } ? T : never;
24
+ /** An exposed port as the API sends it (`Port`). */
25
+ export type PortView = components['schemas']['Port'];
26
+ /** POST …/ports/{port}/tokens (201). */
27
+ export type PortTokenResponse = Created<operations['postV1WorkspacesWorkspaceIdPortsPortTokens']>;
28
+ /** POST …/ports/{port}/links (201). */
29
+ export type PortLinkResponse = Created<operations['postV1WorkspacesWorkspaceIdPortsPortLinks']>;
30
+ /** POST …/ports/{port}/callback (201). */
31
+ export type PortCallbackResponse = Created<operations['postV1WorkspacesWorkspaceIdPortsPortCallback']>;
32
+ /** An exposed port of a workspace. */
33
+ export interface ExposedPort {
34
+ /** TCP port inside the workspace (1-65535). */
35
+ port: number;
36
+ /** `https://<port>-<handle>.<ingress domain>`: requests need a port token, a link's browser session or the callback URL. */
37
+ url: string;
38
+ /** When the port was exposed (RFC 3339). Exposing it again after a close starts a new exposure. */
39
+ createdAt: string;
40
+ /** Set when the port has a callback URL (its secret is shown only by `createCallbackUrl()`). */
41
+ callback: {
42
+ createdAt: string;
43
+ } | null;
44
+ }
45
+ /** `expose()`: the port, and whether this call exposed it (201) or it already was (200, unchanged). */
46
+ export interface ExposePortResult extends ExposedPort {
47
+ created: boolean;
48
+ }
49
+ /** A port token: send it as `Authorization: Bearer <token>` (or `X-Shardflux-Token`) to `url`. */
50
+ export interface PortToken {
51
+ /** `sfp_…`. Revoked when the port is closed, the workspace is deleted or the API key that minted it is revoked. */
52
+ token: string;
53
+ /** RFC 3339. */
54
+ expiresAt: string;
55
+ /** The port's URL. */
56
+ url: string;
57
+ }
58
+ /** A signed link: opening it in a browser starts a session for the port (a cookie until `expiresAt`) and lands on its path. */
59
+ export interface PortLink {
60
+ url: string;
61
+ /** RFC 3339: the link and the browser session it starts end then. */
62
+ expiresAt: string;
63
+ }
64
+ /**
65
+ * The port's callback URL: register `url` plus your own path with GitHub, Slack, Stripe or an OAuth provider. A request
66
+ * to `<url><rest>` reaches `/<rest>` (query kept) without a token header and wakes the workspace like any request.
67
+ */
68
+ export interface PortCallbackUrl {
69
+ /** `https://<port>-<handle>.<domain>/__shardflux/callback/sfcb_…/`. Shown once: the API keeps only its hash. */
70
+ url: string;
71
+ /** RFC 3339. */
72
+ createdAt: string;
73
+ }
74
+ export interface PortTokenOptions {
75
+ /** Lifetime in seconds: 60-86400 (default 3600). */
76
+ ttlSeconds?: number;
77
+ }
78
+ export interface PortLinkOptions {
79
+ /** Lifetime of the link and of the browser session it starts, in seconds: 60-604800 (default 86400). */
80
+ ttlSeconds?: number;
81
+ /** Where the link lands: a path starting with one `/`, printable ASCII, query allowed (default `/`). */
82
+ path?: string;
83
+ }
84
+ export declare function exposedPortOf(view: PortView): ExposedPort;
85
+ /**
86
+ * The exposed ports of one workspace (`workspace.ports`, `cloud.workspaces.ports(id)`). Errors are ShardfluxApiError:
87
+ * 403 `forbidden` reason `inbound_ports_not_available` (inbound ports are not enabled for the organization), 404
88
+ * `not_found` reason `port_not_exposed` (tokens, links and callback URLs of a port that is not exposed), 409 `conflict`
89
+ * reason `port_limit` (at most 10 exposed ports, `details.limit`) or `workspace_deleted`, NotSupportedForModeError for a
90
+ * file-first workspace, 422 `validation_failed` for a port outside 1-65535 or an option out of range.
91
+ */
92
+ export declare class WorkspacePorts {
93
+ #private;
94
+ constructor(ctx: ClientContext, workspaceId: string);
95
+ /**
96
+ * Exposes TCP `port` at its own HTTPS URL (idempotent: a port already exposed is returned unchanged, `created`
97
+ * false, and its tokens, links and callback URL stay valid). The server inside the workspace must listen on
98
+ * 0.0.0.0 (all interfaces), not only on 127.0.0.1.
99
+ */
100
+ expose(port: number): Promise<ExposePortResult>;
101
+ /** The exposed ports, ordered by port. */
102
+ list(): Promise<ExposedPort[]>;
103
+ /**
104
+ * Closes the port (idempotent: also when it is not exposed). Its tokens, links and callback URL stop working at once,
105
+ * and stay revoked if the port is exposed again.
106
+ */
107
+ close(port: number): Promise<void>;
108
+ /** Mints a port token for an exposed port (`use` bearer): `Authorization: Bearer <token>` on requests to `url`. */
109
+ token(port: number, opts?: PortTokenOptions): Promise<PortToken>;
110
+ /** 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. */
111
+ link(port: number, opts?: PortLinkOptions): Promise<PortLink>;
112
+ /** Creates the port's callback URL, or replaces it (the previous one stops working). Its secret is shown only here. */
113
+ createCallbackUrl(port: number): Promise<PortCallbackUrl>;
114
+ /** Revokes the port's callback URL (idempotent while the port is exposed). */
115
+ revokeCallbackUrl(port: number): Promise<void>;
116
+ }
117
+ export {};
package/dist/ports.js ADDED
@@ -0,0 +1,62 @@
1
+ export function exposedPortOf(view) {
2
+ return { port: view.port, url: view.url, createdAt: view.created_at, callback: view.callback ? { createdAt: view.callback.created_at } : null };
3
+ }
4
+ /**
5
+ * The exposed ports of one workspace (`workspace.ports`, `cloud.workspaces.ports(id)`). Errors are ShardfluxApiError:
6
+ * 403 `forbidden` reason `inbound_ports_not_available` (inbound ports are not enabled for the organization), 404
7
+ * `not_found` reason `port_not_exposed` (tokens, links and callback URLs of a port that is not exposed), 409 `conflict`
8
+ * reason `port_limit` (at most 10 exposed ports, `details.limit`) or `workspace_deleted`, NotSupportedForModeError for a
9
+ * file-first workspace, 422 `validation_failed` for a port outside 1-65535 or an option out of range.
10
+ */
11
+ export class WorkspacePorts {
12
+ #ctx;
13
+ #workspaceId;
14
+ constructor(ctx, workspaceId) {
15
+ this.#ctx = ctx;
16
+ this.#workspaceId = workspaceId;
17
+ }
18
+ #path(port, rest = '') {
19
+ const base = `/v1/workspaces/${encodeURIComponent(this.#workspaceId)}/ports`;
20
+ return port === undefined ? base : `${base}/${encodeURIComponent(String(port))}${rest}`;
21
+ }
22
+ /**
23
+ * Exposes TCP `port` at its own HTTPS URL (idempotent: a port already exposed is returned unchanged, `created`
24
+ * false, and its tokens, links and callback URL stay valid). The server inside the workspace must listen on
25
+ * 0.0.0.0 (all interfaces), not only on 127.0.0.1.
26
+ */
27
+ async expose(port) {
28
+ const r = await this.#ctx.http.jsonWithStatus('PUT', this.#path(port), { idempotent: true }, this.#ctx.authorization);
29
+ return { ...exposedPortOf(r.body), created: r.status === 201 };
30
+ }
31
+ /** The exposed ports, ordered by port. */
32
+ async list() {
33
+ const body = await this.#ctx.http.json('GET', this.#path(), {}, this.#ctx.authorization);
34
+ return body.ports.map(exposedPortOf);
35
+ }
36
+ /**
37
+ * Closes the port (idempotent: also when it is not exposed). Its tokens, links and callback URL stop working at once,
38
+ * and stay revoked if the port is exposed again.
39
+ */
40
+ async close(port) {
41
+ await this.#ctx.http.json('DELETE', this.#path(port), { idempotent: true }, this.#ctx.authorization);
42
+ }
43
+ /** Mints a port token for an exposed port (`use` bearer): `Authorization: Bearer <token>` on requests to `url`. */
44
+ async token(port, opts = {}) {
45
+ const body = await this.#ctx.http.json('POST', this.#path(port, '/tokens'), { json: opts.ttlSeconds !== undefined ? { ttl_seconds: opts.ttlSeconds } : {} }, this.#ctx.authorization);
46
+ return { token: body.token, expiresAt: body.expires_at, url: body.url };
47
+ }
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
+ 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);
51
+ return { url: body.url, expiresAt: body.expires_at };
52
+ }
53
+ /** Creates the port's callback URL, or replaces it (the previous one stops working). Its secret is shown only here. */
54
+ async createCallbackUrl(port) {
55
+ const body = await this.#ctx.http.json('POST', this.#path(port, '/callback'), {}, this.#ctx.authorization);
56
+ return { url: body.url, createdAt: body.created_at };
57
+ }
58
+ /** Revokes the port's callback URL (idempotent while the port is exposed). */
59
+ async revokeCallbackUrl(port) {
60
+ await this.#ctx.http.json('DELETE', this.#path(port, '/callback'), { idempotent: true }, this.#ctx.authorization);
61
+ }
62
+ }