@byteplus-iga-pages/agent 0.0.0-stage → 1.0.4

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 (105) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +84 -2
  3. package/dist/cjs/261.js +77 -0
  4. package/dist/cjs/341.js +43 -0
  5. package/dist/cjs/401.js +3632 -0
  6. package/dist/cjs/419.js +854 -0
  7. package/dist/cjs/504.js +760 -0
  8. package/dist/cjs/521.js +242 -0
  9. package/dist/cjs/594.js +79 -0
  10. package/dist/cjs/647.js +1367 -0
  11. package/dist/cjs/808.js +322 -0
  12. package/dist/cjs/82.js +10089 -0
  13. package/dist/cjs/893.js +17720 -0
  14. package/dist/cjs/893.js.LICENSE.txt +13 -0
  15. package/dist/cjs/951.js +59 -0
  16. package/dist/cjs/package.json +3 -0
  17. package/dist/cjs/runtime.js +79 -0
  18. package/dist/cjs/sandbox/host.js +125 -0
  19. package/dist/cjs/sandbox/index.js +286 -0
  20. package/dist/cjs/store/claude.js +209 -0
  21. package/dist/cjs/store/host.js +92 -0
  22. package/dist/cjs/store/index.js +43 -0
  23. package/dist/cjs/store/langgraph.js +581 -0
  24. package/dist/cjs/store/openai.js +118 -0
  25. package/dist/cjs/tools/claude.js +59 -0
  26. package/dist/cjs/tools/index.js +37 -0
  27. package/dist/cjs/tools/langchain.js +52 -0
  28. package/dist/cjs/tools/openai-agents.js +43 -0
  29. package/dist/cjs/tools/openai.js +43 -0
  30. package/dist/esm/128.js +10381 -0
  31. package/dist/esm/261.js +67 -0
  32. package/dist/esm/341.js +30 -0
  33. package/dist/esm/392.js +4453 -0
  34. package/dist/esm/417.js +704 -0
  35. package/dist/esm/521.js +230 -0
  36. package/dist/esm/594.js +67 -0
  37. package/dist/esm/613.js +19042 -0
  38. package/dist/esm/613.js.LICENSE.txt +13 -0
  39. package/dist/esm/951.js +44 -0
  40. package/dist/esm/package.json +3 -0
  41. package/dist/esm/runtime.js +39 -0
  42. package/dist/esm/sandbox/host.js +1 -0
  43. package/dist/esm/sandbox/index.js +183 -0
  44. package/dist/esm/store/claude.js +172 -0
  45. package/dist/esm/store/host.js +46 -0
  46. package/dist/esm/store/index.js +2 -0
  47. package/dist/esm/store/langgraph.js +542 -0
  48. package/dist/esm/store/openai.js +81 -0
  49. package/dist/esm/tools/claude.js +22 -0
  50. package/dist/esm/tools/index.js +1 -0
  51. package/dist/esm/tools/langchain.js +16 -0
  52. package/dist/esm/tools/openai-agents.js +6 -0
  53. package/dist/esm/tools/openai.js +6 -0
  54. package/dist/types/_internal/data-plane/control-plane-request.d.ts +12 -0
  55. package/dist/types/_internal/data-plane/control-plane.d.ts +3 -0
  56. package/dist/types/_internal/data-plane/credential-provider.d.ts +25 -0
  57. package/dist/types/_internal/data-plane/errors.d.ts +19 -0
  58. package/dist/types/_internal/data-plane/index.d.ts +11 -0
  59. package/dist/types/_internal/data-plane/supabase-client.d.ts +12 -0
  60. package/dist/types/_internal/data-plane/token-client.d.ts +23 -0
  61. package/dist/types/sandbox/api-client.d.ts +37 -0
  62. package/dist/types/sandbox/api-types.d.ts +81 -0
  63. package/dist/types/sandbox/binding-repository.d.ts +62 -0
  64. package/dist/types/sandbox/error.d.ts +22 -0
  65. package/dist/types/sandbox/expiry.d.ts +11 -0
  66. package/dist/types/sandbox/host.d.ts +6 -0
  67. package/dist/types/sandbox/iga-sandbox.d.ts +208 -0
  68. package/dist/types/sandbox/index.d.ts +8 -0
  69. package/dist/types/sandbox/public-surface.d.ts +19 -0
  70. package/dist/types/sandbox/runtime-sandbox.d.ts +32 -0
  71. package/dist/types/sandbox/types.d.ts +238 -0
  72. package/dist/types/store/append.d.ts +41 -0
  73. package/dist/types/store/claude-repository.d.ts +36 -0
  74. package/dist/types/store/claude.d.ts +3 -0
  75. package/dist/types/store/control-plane-request.d.ts +2 -0
  76. package/dist/types/store/credential-error.d.ts +2 -0
  77. package/dist/types/store/credential-provider.d.ts +29 -0
  78. package/dist/types/store/errors.d.ts +29 -0
  79. package/dist/types/store/factory.d.ts +31 -0
  80. package/dist/types/store/host.d.ts +5 -0
  81. package/dist/types/store/index.d.ts +6 -0
  82. package/dist/types/store/json.d.ts +7 -0
  83. package/dist/types/store/langgraph-repository.d.ts +98 -0
  84. package/dist/types/store/langgraph.d.ts +43 -0
  85. package/dist/types/store/openai.d.ts +12 -0
  86. package/dist/types/store/pagination.d.ts +27 -0
  87. package/dist/types/store/runtime-data-plane.d.ts +8 -0
  88. package/dist/types/store/runtime-provider.d.ts +1 -0
  89. package/dist/types/store/runtime-store.d.ts +20 -0
  90. package/dist/types/store/store.d.ts +240 -0
  91. package/dist/types/store/supabase-transport.d.ts +43 -0
  92. package/dist/types/store/token-client.d.ts +7 -0
  93. package/dist/types/tools/adapters.d.ts +5 -0
  94. package/dist/types/tools/claude.d.ts +4 -0
  95. package/dist/types/tools/index.d.ts +2 -0
  96. package/dist/types/tools/langchain.d.ts +16 -0
  97. package/dist/types/tools/model-output.d.ts +8 -0
  98. package/dist/types/tools/openai-agents.d.ts +4 -0
  99. package/dist/types/tools/openai.d.ts +5 -0
  100. package/dist/types/tools/registry.d.ts +16 -0
  101. package/dist/types/tools/result.d.ts +17 -0
  102. package/dist/types/tools/sandbox-result-mappers.d.ts +10 -0
  103. package/dist/types/tools/sandbox-tools.d.ts +17 -0
  104. package/dist/types/tools/types.d.ts +307 -0
  105. package/package.json +136 -4
@@ -0,0 +1,12 @@
1
+ export declare function getControlPlaneHeaders(): Readonly<Record<string, string>>;
2
+ export interface ControlPlaneResponse {
3
+ readonly ok: boolean;
4
+ readonly status: number;
5
+ json(): Promise<unknown>;
6
+ }
7
+ export interface PostStoreTokenOptions {
8
+ endpoint: URL;
9
+ body: string;
10
+ fetch?: typeof globalThis.fetch;
11
+ }
12
+ export declare function postStoreToken(options: PostStoreTokenOptions): Promise<ControlPlaneResponse>;
@@ -0,0 +1,3 @@
1
+ export declare const CONTROL_PLANE_BASE_URL: string;
2
+ export declare const ALLOWED_STORE_HOST_SUFFIX: string;
3
+ export declare const CONTROL_PLANE_HEADERS: Readonly<Record<string, string>>;
@@ -0,0 +1,25 @@
1
+ import type { DataPlaneCredentials } from "./token-client.js";
2
+ export interface JwtTiming {
3
+ issuedAtMs: number;
4
+ expiresAtMs: number;
5
+ }
6
+ export interface DataPlaneCredentialProviderOptions {
7
+ fetchCredentials(): Promise<DataPlaneCredentials>;
8
+ now?: () => number;
9
+ }
10
+ /** Reads the project identity; authorization is still enforced by the data plane. */
11
+ export declare function readJwtProjectId(jwt: string): string;
12
+ export declare function readJwtTiming(jwt: string): JwtTiming;
13
+ export declare class DataPlaneCredentialProvider {
14
+ private readonly fetchCredentials;
15
+ private readonly now;
16
+ private current;
17
+ private refreshPromise;
18
+ private projectId;
19
+ constructor(options: DataPlaneCredentialProviderOptions);
20
+ getValidCredentials(signal?: AbortSignal): Promise<DataPlaneCredentials>;
21
+ getProjectId(signal?: AbortSignal): Promise<string>;
22
+ invalidate(jwt?: string): void;
23
+ private refresh;
24
+ private toPublic;
25
+ }
@@ -0,0 +1,19 @@
1
+ export declare const DATA_PLANE_ERROR_CODES: readonly ["invalid_argument", "not_found", "conflict", "unauthenticated", "permission_denied", "too_large", "rate_limited", "aborted", "unavailable", "unsupported", "execution_failed", "internal"];
2
+ export type DataPlaneErrorCode = (typeof DATA_PLANE_ERROR_CODES)[number];
3
+ export interface DataPlaneErrorOptions {
4
+ operation: string;
5
+ retryable?: boolean;
6
+ requestId?: string;
7
+ status?: number;
8
+ failureKind?: "authentication_failed" | "timeout";
9
+ }
10
+ /** Internal-only error. Domain packages must translate it before exporting. */
11
+ export declare class DataPlaneError extends Error {
12
+ readonly code: DataPlaneErrorCode;
13
+ readonly operation: string;
14
+ readonly retryable: boolean;
15
+ readonly requestId?: string;
16
+ readonly status?: number;
17
+ readonly failureKind?: "authentication_failed" | "timeout";
18
+ constructor(code: DataPlaneErrorCode, message: string, options: DataPlaneErrorOptions);
19
+ }
@@ -0,0 +1,11 @@
1
+ export { CONTROL_PLANE_BASE_URL } from "./control-plane.js";
2
+ export { ALLOWED_STORE_HOST_SUFFIX, STORE_TOKEN_ENDPOINT, fetchDataPlaneCredentials, fetchRuntimeDataPlaneCredentials, validateDataPlaneRootUrl, } from "./token-client.js";
3
+ export type { DataPlaneCredentials, FetchDataPlaneCredentialsOptions, } from "./token-client.js";
4
+ export { DataPlaneCredentialProvider, readJwtTiming, readJwtProjectId, } from "./credential-provider.js";
5
+ export type { DataPlaneCredentialProviderOptions, JwtTiming, } from "./credential-provider.js";
6
+ export { createAuthenticatedSupabaseClient } from "./supabase-client.js";
7
+ export type { CreateAuthenticatedSupabaseClientOptions } from "./supabase-client.js";
8
+ export { DataPlaneError } from "./errors.js";
9
+ export type { DataPlaneErrorCode, DataPlaneErrorOptions } from "./errors.js";
10
+ export { postStoreToken, getControlPlaneHeaders } from "./control-plane-request.js";
11
+ export type { ControlPlaneResponse, PostStoreTokenOptions, } from "./control-plane-request.js";
@@ -0,0 +1,12 @@
1
+ import { createClient, type SupabaseClient } from "@supabase/supabase-js";
2
+ import type { DataPlaneCredentials } from "./token-client.js";
3
+ export interface CreateAuthenticatedSupabaseClientOptions {
4
+ credentials: DataPlaneCredentials;
5
+ requestId?: string;
6
+ fetch?: typeof globalThis.fetch;
7
+ createClient?: typeof createClient;
8
+ signal?: AbortSignal;
9
+ realtimeError(): Error;
10
+ }
11
+ /** Creates a request-scoped client bound to one already validated JWT version. */
12
+ export declare function createAuthenticatedSupabaseClient(options: CreateAuthenticatedSupabaseClientOptions): SupabaseClient;
@@ -0,0 +1,23 @@
1
+ import { ALLOWED_STORE_HOST_SUFFIX } from "./control-plane.js";
2
+ export declare const STORE_TOKEN_ENDPOINT: string;
3
+ export { ALLOWED_STORE_HOST_SUFFIX };
4
+ export interface DataPlaneCredentials {
5
+ url: string;
6
+ anonKey: string;
7
+ jwt: string;
8
+ }
9
+ export interface FetchDataPlaneCredentialsOptions {
10
+ endpoint: string;
11
+ token: string;
12
+ fetch?: typeof globalThis.fetch;
13
+ now?: () => number;
14
+ isAllowedTokenEndpoint(url: URL): boolean;
15
+ isAllowedHostname(hostname: string): boolean;
16
+ }
17
+ export declare function validateDataPlaneRootUrl(value: string, isAllowedHostname: (hostname: string) => boolean): string;
18
+ export declare function fetchDataPlaneCredentials(options: FetchDataPlaneCredentialsOptions): Promise<DataPlaneCredentials>;
19
+ export declare function fetchRuntimeDataPlaneCredentials(options: {
20
+ token: string;
21
+ fetch?: typeof globalThis.fetch;
22
+ now?: () => number;
23
+ }): Promise<DataPlaneCredentials>;
@@ -0,0 +1,37 @@
1
+ import type { SandboxApiCallOptions, SandboxApiClient, SandboxCreateResult, SandboxDestroyResult, SandboxInstanceInfo, SandboxTokenResult } from "./types.js";
2
+ export interface CreateSandboxApiClientOptions {
3
+ /** 后端 base URL(不含路径,如 https://api.iga.example.com)。 */
4
+ apiBaseUrl?: string;
5
+ /** 控制面下发的项目 Token;只允许内部 SDK 代码传入。 */
6
+ apiToken?: string;
7
+ }
8
+ export declare function createSandboxApi(opts: CreateSandboxApiClientOptions): SandboxApiClient;
9
+ export declare class SandboxApi implements SandboxApiClient {
10
+ private readonly baseUrl?;
11
+ private readonly token?;
12
+ private readonly now;
13
+ private readonly http;
14
+ constructor(baseUrl?: string | undefined, token?: string | undefined, now?: () => number);
15
+ private resolveBaseUrl;
16
+ getToken(opts?: {
17
+ signal?: AbortSignal;
18
+ }): Promise<SandboxTokenResult>;
19
+ create(opts: SandboxApiCallOptions): Promise<SandboxCreateResult>;
20
+ destroy(opts: SandboxApiCallOptions & {
21
+ sandboxId: string;
22
+ }): Promise<SandboxDestroyResult>;
23
+ getInstance(opts: SandboxApiCallOptions & {
24
+ sandboxId: string;
25
+ }): Promise<SandboxInstanceInfo>;
26
+ confirmInstanceExists(opts: SandboxApiCallOptions & {
27
+ sandboxId: string;
28
+ }): Promise<void>;
29
+ private confirmMissingViaDataPlane;
30
+ updateInstanceTimeout(opts: SandboxApiCallOptions & {
31
+ sandboxId: string;
32
+ timeoutInMinutes: number;
33
+ }): Promise<SandboxInstanceInfo>;
34
+ private postJson;
35
+ }
36
+ /** Exact routing failure observed from veFaaS; a generic HTTP 404 is insufficient. */
37
+ export declare function isConfirmedMissingInstanceResponse(value: unknown): boolean;
@@ -0,0 +1,81 @@
1
+ import type { SandboxApi as UpstreamSandboxApi } from "@agent-infra/sandbox";
2
+ /**
3
+ * Named API types for the allowed code, shell, file and browserPage methods.
4
+ * Keep this positive export list explicit: upstream additions are reviewed before
5
+ * becoming public. Aliases preserve upstream field definitions without copying them.
6
+ * Includes the nested data types referenced by these methods' requests/responses.
7
+ */
8
+ export type BashCommandStatus = UpstreamSandboxApi.BashCommandStatus;
9
+ export type BrowserPageGetHtmlRequest = UpstreamSandboxApi.BrowserPageGetHtmlRequest;
10
+ export type BrowserPageScreenshotRequest = UpstreamSandboxApi.BrowserPageScreenshotRequest;
11
+ export type CheckRequest = UpstreamSandboxApi.CheckRequest;
12
+ export type ClickRequest = UpstreamSandboxApi.ClickRequest;
13
+ export type CodeExecuteRequest = UpstreamSandboxApi.CodeExecuteRequest;
14
+ export type CodeExecuteResponse = UpstreamSandboxApi.CodeExecuteResponse;
15
+ export type ConsoleRecord = UpstreamSandboxApi.ConsoleRecord;
16
+ export type FileContentEncoding = UpstreamSandboxApi.FileContentEncoding;
17
+ export type FileFindRequest = UpstreamSandboxApi.FileFindRequest;
18
+ export type FileFindResult = UpstreamSandboxApi.FileFindResult;
19
+ export type FileGrepRequest = UpstreamSandboxApi.FileGrepRequest;
20
+ export type FileGrepResult = UpstreamSandboxApi.FileGrepResult;
21
+ export type FileInfo = UpstreamSandboxApi.FileInfo;
22
+ export type FileListRequest = UpstreamSandboxApi.FileListRequest;
23
+ export type FileListResult = UpstreamSandboxApi.FileListResult;
24
+ export type FileOperationError = UpstreamSandboxApi.FileOperationError;
25
+ export type FileReadRequest = UpstreamSandboxApi.FileReadRequest;
26
+ export type FileReadResult = UpstreamSandboxApi.FileReadResult;
27
+ export type FileReplaceRequest = UpstreamSandboxApi.FileReplaceRequest;
28
+ export type FileReplaceResult = UpstreamSandboxApi.FileReplaceResult;
29
+ export type FileSearchRequest = UpstreamSandboxApi.FileSearchRequest;
30
+ export type FileSearchResult = UpstreamSandboxApi.FileSearchResult;
31
+ export type FileWriteRequest = UpstreamSandboxApi.FileWriteRequest;
32
+ export type FileWriteResult = UpstreamSandboxApi.FileWriteResult;
33
+ export type FillRequest = UpstreamSandboxApi.FillRequest;
34
+ export type GrepMatch = UpstreamSandboxApi.GrepMatch;
35
+ export type HotKeyRequest = UpstreamSandboxApi.HotKeyRequest;
36
+ export type HoverRequest = UpstreamSandboxApi.HoverRequest;
37
+ export type HttpValidationError = UpstreamSandboxApi.HttpValidationError;
38
+ export type KeyRequest = UpstreamSandboxApi.KeyRequest;
39
+ export type Language = UpstreamSandboxApi.Language;
40
+ export type NavigateRequest = UpstreamSandboxApi.NavigateRequest;
41
+ export type NavigateRequestWaitUntil = UpstreamSandboxApi.NavigateRequestWaitUntil;
42
+ export type Response = UpstreamSandboxApi.Response;
43
+ export type ResponseCodeExecuteResponse = UpstreamSandboxApi.ResponseCodeExecuteResponse;
44
+ export type ResponseDict = UpstreamSandboxApi.ResponseDict;
45
+ export type ResponseShellCommandResult = UpstreamSandboxApi.ResponseShellCommandResult;
46
+ export type ResponseShellKillResult = UpstreamSandboxApi.ResponseShellKillResult;
47
+ export type ResponseShellViewResult = UpstreamSandboxApi.ResponseShellViewResult;
48
+ export type ResponseShellWaitResult = UpstreamSandboxApi.ResponseShellWaitResult;
49
+ export type ResponseStr = UpstreamSandboxApi.ResponseStr;
50
+ export type ResponseUnionFileFindResultFileOperationError = UpstreamSandboxApi.ResponseUnionFileFindResultFileOperationError;
51
+ export type ResponseUnionFileFindResultFileOperationErrorData = UpstreamSandboxApi.ResponseUnionFileFindResultFileOperationErrorData;
52
+ export type ResponseUnionFileGrepResultFileOperationError = UpstreamSandboxApi.ResponseUnionFileGrepResultFileOperationError;
53
+ export type ResponseUnionFileGrepResultFileOperationErrorData = UpstreamSandboxApi.ResponseUnionFileGrepResultFileOperationErrorData;
54
+ export type ResponseUnionFileListResultFileOperationError = UpstreamSandboxApi.ResponseUnionFileListResultFileOperationError;
55
+ export type ResponseUnionFileListResultFileOperationErrorData = UpstreamSandboxApi.ResponseUnionFileListResultFileOperationErrorData;
56
+ export type ResponseUnionFileReadResultFileOperationError = UpstreamSandboxApi.ResponseUnionFileReadResultFileOperationError;
57
+ export type ResponseUnionFileReadResultFileOperationErrorData = UpstreamSandboxApi.ResponseUnionFileReadResultFileOperationErrorData;
58
+ export type ResponseUnionFileReplaceResultFileOperationError = UpstreamSandboxApi.ResponseUnionFileReplaceResultFileOperationError;
59
+ export type ResponseUnionFileReplaceResultFileOperationErrorData = UpstreamSandboxApi.ResponseUnionFileReplaceResultFileOperationErrorData;
60
+ export type ResponseUnionFileSearchResultFileOperationError = UpstreamSandboxApi.ResponseUnionFileSearchResultFileOperationError;
61
+ export type ResponseUnionFileSearchResultFileOperationErrorData = UpstreamSandboxApi.ResponseUnionFileSearchResultFileOperationErrorData;
62
+ export type ResponseUnionFileWriteResultFileOperationError = UpstreamSandboxApi.ResponseUnionFileWriteResultFileOperationError;
63
+ export type ResponseUnionFileWriteResultFileOperationErrorData = UpstreamSandboxApi.ResponseUnionFileWriteResultFileOperationErrorData;
64
+ export type ScrollRequest = UpstreamSandboxApi.ScrollRequest;
65
+ export type ScrollToElementRequest = UpstreamSandboxApi.ScrollToElementRequest;
66
+ export type ScrollToRequest = UpstreamSandboxApi.ScrollToRequest;
67
+ export type SelectOptionRequest = UpstreamSandboxApi.SelectOptionRequest;
68
+ export type ShellCommandResult = UpstreamSandboxApi.ShellCommandResult;
69
+ export type ShellExecRequest = UpstreamSandboxApi.ShellExecRequest;
70
+ export type ShellKillProcessRequest = UpstreamSandboxApi.ShellKillProcessRequest;
71
+ export type ShellKillResult = UpstreamSandboxApi.ShellKillResult;
72
+ export type ShellViewRequest = UpstreamSandboxApi.ShellViewRequest;
73
+ export type ShellViewResult = UpstreamSandboxApi.ShellViewResult;
74
+ export type ShellWaitRequest = UpstreamSandboxApi.ShellWaitRequest;
75
+ export type ShellWaitResult = UpstreamSandboxApi.ShellWaitResult;
76
+ export type Type = UpstreamSandboxApi.Type;
77
+ export type TypeTextRequest = UpstreamSandboxApi.TypeTextRequest;
78
+ export type UploadFileRequest = UpstreamSandboxApi.UploadFileRequest;
79
+ export type ValidationError = UpstreamSandboxApi.ValidationError;
80
+ export type ValidationErrorLocItem = UpstreamSandboxApi.ValidationErrorLocItem;
81
+ export type WaitRequest = UpstreamSandboxApi.WaitRequest;
@@ -0,0 +1,62 @@
1
+ import { DataPlaneCredentialProvider, type CreateAuthenticatedSupabaseClientOptions } from "../_internal/data-plane/index.js";
2
+ export type SandboxBindingAcquireResult = {
3
+ action: "attach";
4
+ generation: number;
5
+ sandboxId: string;
6
+ } | {
7
+ action: "create";
8
+ generation: number;
9
+ leaseExpiresAt: string;
10
+ } | {
11
+ action: "wait";
12
+ generation: number;
13
+ leaseExpiresAt: string;
14
+ };
15
+ export type SandboxBindingDestroyResult = {
16
+ action: "none";
17
+ } | {
18
+ action: "wait";
19
+ leaseExpiresAt: string;
20
+ } | {
21
+ action: "destroy";
22
+ generation: number;
23
+ sandboxId: string;
24
+ };
25
+ export interface SandboxBindingRepository {
26
+ acquire(conversationId: string, leaseToken: string, signal?: AbortSignal): Promise<SandboxBindingAcquireResult>;
27
+ publish(conversationId: string, generation: number, leaseToken: string, sandboxId: string, signal?: AbortSignal): Promise<boolean>;
28
+ release(conversationId: string, generation: number, leaseToken: string, signal?: AbortSignal): Promise<void>;
29
+ invalidate(conversationId: string, generation: number, sandboxId: string, signal?: AbortSignal): Promise<boolean>;
30
+ beginDestroy(conversationId: string, leaseToken: string, signal?: AbortSignal): Promise<SandboxBindingDestroyResult>;
31
+ finishDestroy(conversationId: string, generation: number, leaseToken: string, signal?: AbortSignal): Promise<void>;
32
+ restore(conversationId: string, generation: number, leaseToken: string, signal?: AbortSignal): Promise<void>;
33
+ }
34
+ export interface SupabaseSandboxBindingRepositoryOptions {
35
+ credentialProvider: DataPlaneCredentialProvider;
36
+ fetch?: typeof globalThis.fetch;
37
+ createClient?: CreateAuthenticatedSupabaseClientOptions["createClient"];
38
+ generateUuid?: () => string;
39
+ leaseSeconds?: number;
40
+ }
41
+ export declare class SupabaseSandboxBindingRepository implements SandboxBindingRepository {
42
+ private readonly credentialProvider;
43
+ private readonly fetch?;
44
+ private readonly createClient?;
45
+ private readonly generateUuid;
46
+ private readonly leaseSeconds;
47
+ constructor(options: SupabaseSandboxBindingRepositoryOptions);
48
+ acquire(conversationId: string, leaseToken: string, signal?: AbortSignal): Promise<SandboxBindingAcquireResult>;
49
+ publish(conversationId: string, generation: number, leaseToken: string, sandboxId: string, signal?: AbortSignal): Promise<boolean>;
50
+ release(conversationId: string, generation: number, leaseToken: string, signal?: AbortSignal): Promise<void>;
51
+ invalidate(conversationId: string, generation: number, sandboxId: string, signal?: AbortSignal): Promise<boolean>;
52
+ beginDestroy(conversationId: string, leaseToken: string, signal?: AbortSignal): Promise<SandboxBindingDestroyResult>;
53
+ finishDestroy(conversationId: string, generation: number, leaseToken: string, signal?: AbortSignal): Promise<void>;
54
+ restore(conversationId: string, generation: number, leaseToken: string, signal?: AbortSignal): Promise<void>;
55
+ private booleanRpc;
56
+ private rpc;
57
+ }
58
+ export declare function createRuntimeSandboxBindingRepository(options: {
59
+ token: string;
60
+ fetch?: typeof globalThis.fetch;
61
+ createClient?: CreateAuthenticatedSupabaseClientOptions["createClient"];
62
+ }): SandboxBindingRepository;
@@ -0,0 +1,22 @@
1
+ export interface IgaErrorInfo {
2
+ readonly code: string;
3
+ readonly status?: number;
4
+ readonly message: string;
5
+ }
6
+ export interface IgaErrorOptions {
7
+ status?: number;
8
+ }
9
+ /** A safe error for Sandbox lifecycle and control-plane failures. */
10
+ export declare class SandboxError extends Error implements IgaErrorInfo {
11
+ readonly code: string;
12
+ readonly status?: number;
13
+ constructor(message: string, options?: IgaErrorOptions);
14
+ toJSON(): IgaErrorInfo;
15
+ }
16
+ /** Internal lifecycle signals; neither class is exported by the public entry. */
17
+ export declare class SandboxAbortError extends SandboxError {
18
+ }
19
+ export declare class SandboxInstanceGoneError extends SandboxError {
20
+ }
21
+ /** Recognize cancellation from both the IGA wrapper and the official SDK. */
22
+ export declare function isAbortError(error: unknown): boolean;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 把后端返回的 expireAt 解析成 ms epoch,解析不了就返回 undefined。
3
+ *
4
+ * 后端是 Go 服务,时间格式是 `2026-08-26 17:52:15 +0800 CST`。这种带
5
+ * 时区缩写的形式 V8 解析不了:`CST` 在 JS 里按美国中部时区(UTC-6)算,
6
+ * 实际会差出 14 个小时。这里先把显式数字偏移(+0800)换成 `+08:00` 再把
7
+ * 时区缩写丢掉,让 Date.parse 只认数字偏移。
8
+ *
9
+ * 兼容 RFC3339(`2026-08-26T17:52:15+08:00` / `Z` 结尾)——老格式直接过。
10
+ */
11
+ export declare function parseExpireAtMs(value: string | undefined): number | undefined;
@@ -0,0 +1,6 @@
1
+ export { createSandbox, createDetachedSandbox, attachSandbox, IgaSandbox, isInstanceGoneResponse, __clearSandboxCacheForTests, __getEntryForTests, } from "./iga-sandbox.js";
2
+ export type { IgaSandboxConstructorOptions, IgaDetachedSandboxOptions, IgaAttachSandboxOptions, } from "./iga-sandbox.js";
3
+ export { createSandboxApi, SandboxApi, type CreateSandboxApiClientOptions, } from "./api-client.js";
4
+ export { SupabaseSandboxBindingRepository, createRuntimeSandboxBindingRepository, } from "./binding-repository.js";
5
+ export type { SandboxBindingAcquireResult, SandboxBindingDestroyResult, SandboxBindingRepository, SupabaseSandboxBindingRepositoryOptions, } from "./binding-repository.js";
6
+ export type { CreateSandboxOptions, CreateDetachedSandboxOptions, AttachSandboxOptions, SandboxControlPlaneEnvelope, SandboxControlPlaneResponse, SandboxCreateResponsePayload, SandboxDestroyResponsePayload, SandboxOperationOptions, SandboxInstance, SandboxApiClient, SandboxApiCallOptions, SandboxTokenResult, SandboxCreateResult, SandboxDestroyResult, SandboxInstanceInfo, SandboxInstanceResponsePayload, SandboxTokenResponsePayload, } from "./types.js";
@@ -0,0 +1,208 @@
1
+ import { SandboxClient } from "@agent-infra/sandbox";
2
+ import type { SandboxApiClient, CreateSandboxOptions, CreateDetachedSandboxOptions, AttachSandboxOptions, SandboxInstance, SandboxInstanceInfo, SandboxOperationOptions } from "./types.js";
3
+ /**
4
+ * 清空整个缓存。主要给测试用——避免跨用例污染。
5
+ * 调用方一般不需要调。
6
+ */
7
+ export declare function __clearSandboxCacheForTests(): void;
8
+ /**
9
+ * 读缓存 entry 的内部状态(测试用)。公开 Proxy 白名单不暴露 entry,
10
+ * 单测要用它改暂存的过期时间、模拟"实例快过期"。
11
+ */
12
+ export declare function __getEntryForTests(projectId: string, conversationId: string): {
13
+ generation: number;
14
+ instanceExpireAt?: number;
15
+ sandboxId?: string;
16
+ } | undefined;
17
+ /**
18
+ * 数据面初筛:官方业务调用的返回是否"疑似"实例已销毁。
19
+ * 官方 SDK 失败不抛异常,返回 { ok:false, error: { content: Fetcher.Error } }(探针实测)。
20
+ *
21
+ * 只看状态码 404/410,不匹配文案——上游错误响应 body 无稳定契约,文案变了只是
22
+ * 举报灵敏度下降(少触发初筛),不影响正确性。真正的定罪在控制面
23
+ * (confirmInstanceExists),这里宁可漏报不可误报。
24
+ */
25
+ export declare function isInstanceGoneResponse(result: unknown): boolean;
26
+ export interface IgaSandboxOptions extends CreateSandboxOptions {
27
+ }
28
+ /**
29
+ * 独立实例模式的构造参数(内部用)。公共 `createSandbox()` 从运行时 env 固定
30
+ * 项目作用域后转成这份配置。
31
+ */
32
+ export interface IgaDetachedSandboxOptions extends CreateDetachedSandboxOptions {
33
+ projectId: string;
34
+ apiBaseUrl?: string;
35
+ apiToken?: string;
36
+ api?: SandboxApiClient;
37
+ }
38
+ /**
39
+ * 接回已有实例模式的构造参数(内部用)。公共 `connectSandbox(sandboxId)` 用。
40
+ */
41
+ export interface IgaAttachSandboxOptions extends AttachSandboxOptions {
42
+ projectId: string;
43
+ sandboxId: string;
44
+ apiBaseUrl?: string;
45
+ apiToken?: string;
46
+ api?: SandboxApiClient;
47
+ }
48
+ /** IgaSandbox 构造参数:判别字段 mode 区分三种实例来源。 */
49
+ export type IgaSandboxConstructorOptions = IgaSandboxOptions | (IgaDetachedSandboxOptions & {
50
+ mode: "detached";
51
+ }) | (IgaAttachSandboxOptions & {
52
+ mode: "attach";
53
+ });
54
+ export declare class IgaSandbox {
55
+ readonly projectId: string;
56
+ /** 绑定会话的实例才有;detached / attach 模式下是 undefined。 */
57
+ readonly conversationId?: string;
58
+ /**
59
+ * 实例 ID。attach 模式同步可读(调用方传进来的);
60
+ * detached 模式懒加载建好后可读;conversation 模式是 undefined(要等 getInfo)。
61
+ */
62
+ readonly sandboxId?: string;
63
+ /** 后端 API。 */
64
+ private readonly api;
65
+ /** 实例状态——绑定会话的实例共享 conversation 键下的同一份;其余模式独占。 */
66
+ private readonly entry;
67
+ /** 实例来源模式。 */
68
+ private readonly mode;
69
+ /** 默认单请求超时(秒)。 */
70
+ private readonly timeoutInSeconds?;
71
+ /** 当前 Sandbox 对象的 client;request signal 只通过单次 RequestOptions 传入。 */
72
+ private raw?;
73
+ private rawGeneration;
74
+ /** 懒加载的子模块代理缓存(抄官方 SandboxClient 的 ??= 模式)。
75
+ * key 是子模块名("code"/"shell"/...),value 是 Proxy 子对象。 */
76
+ private readonly submoduleCache;
77
+ constructor(options: IgaSandboxConstructorOptions);
78
+ /**
79
+ * 给实例挂上所有官方子模块的 getter——访问时返回懒代理。
80
+ * 用 Object.defineProperty 反射挂载,不硬编码 key 名单。
81
+ * SDK 升级加新 getter(比如未来 sandbox.ai)自动跟进。
82
+ */
83
+ private installLazyGetters;
84
+ /**
85
+ * 拿到一个子模块的懒代理——抄官方 SandboxClient 的 ??= 缓存模式。
86
+ * 第一次访问构造,后续直接返回缓存(保证 sandbox.code === sandbox.code)。
87
+ *
88
+ * 代理行为:
89
+ * - 访问 sandbox.code 时同步返回代理(不发请求)
90
+ * - 调 sandbox.code.executeCode(...) 时 await ensureInstance(),然后转发到 raw.code.executeCode(...)
91
+ * - 调用方完全不感知 ensureInstance 的存在
92
+ */
93
+ private getLazySubmodule;
94
+ /**
95
+ * 实例预期外销毁的自动恢复入口。两段式,防止误重建:
96
+ *
97
+ * 1. 初筛:业务调用返回疑似销毁响应(数据面 404/410)
98
+ * 2. 定罪:问一次控制面 confirmInstanceExists——只有它明确说"没了"
99
+ * (not_found)才重建;控制面自己失败(网络抖动/500)一律不重建
100
+ *
101
+ * 定罪后:清缓存 + best-effort destroy + 重建 + 原调用重试一次。
102
+ * 重试结果直接返回,不递归。generation 变了(别的 Sandbox 对象已处理)就不再动。
103
+ *
104
+ * 只对绑定会话的实例生效。detached / attach 模式不自动重建:
105
+ * - detached:静默换新实例后,调用方保存的 sandboxId 就指向死实例了,
106
+ * 后续 connectSandbox(sandboxId) 接不回来,状态对不上
107
+ * - attach:调用方点名要这个实例,换一个等于偷换对象
108
+ */
109
+ private callWithRecreate;
110
+ /**
111
+ * 控制面定罪:实例确认已销毁返回 true;无法确认(含控制面自身故障)返回 false。
112
+ * singleflight:并发初筛命中只验证一次。
113
+ */
114
+ private confirmDestroyed;
115
+ /**
116
+ * 定罪后的恢复:清 entry 状态 + best-effort 清理旧实例(可能已不存在,失败静默),
117
+ * 下次 ensureInstance 懒加载重建。不做后台重建——恢复链里 invoke() 会触发。
118
+ */
119
+ private recreateInstance;
120
+ private performRecreation;
121
+ /**
122
+ * 拿到底层官方 SandboxClient(原装)。
123
+ * 首次调用会触发懒加载(getToken + create + new SandboxClient),后续命中缓存。
124
+ *
125
+ * 调用方一般不需要显式调——业务方法(sandbox.code.executeCode 等)会自动触发。
126
+ * 这个方法给"我要把 client 传给外部库"的场景用:
127
+ *
128
+ * const client = await sandbox.getClient();
129
+ * externalLibrary.doSomething(client);
130
+ */
131
+ getClient(options?: SandboxOperationOptions): Promise<SandboxClient>;
132
+ /**
133
+ * 内部初始化方法,等待实例身份、凭证和客户端准备完成,不轮询远端 Ready 状态。
134
+ * 供公共 createSandbox 在返回前调用,不对 SDK 用户暴露。
135
+ */
136
+ ensureReady(options?: SandboxOperationOptions): Promise<void>;
137
+ private ensureInstance;
138
+ /**
139
+ * 真正干活的初始化方法:getToken → create → 顺路查一次实例过期时间 → 构造官方 SandboxClient。
140
+ * 成功后写入共享的实例身份、凭证元数据;request-scoped client 由 createClient 构造。
141
+ */
142
+ private startInitialization;
143
+ private waitForInitialization;
144
+ private initializeEntry;
145
+ private queryUsableInstance;
146
+ private initializePersistentConversation;
147
+ private commitInitializedEntry;
148
+ /**
149
+ * attach 模式的初始化:getToken 换凭证 → 前置检查实例状态 → header 指向目标 sandboxId。
150
+ * 不调 create——实例已经存在,我们只是接上它。
151
+ *
152
+ * 前置检查(attach 特有,conversation 模式没有——它自己 create 的实例一定存在):
153
+ * 1. 查一次 sandbox/instance。空 SandboxID / Failed / Terminating → 直接抛
154
+ * not_found,调用方在接回时就能知道实例没了,不用等第一次业务调用撞 404
155
+ * 2. 已过期(ExpireAt 已过)→ 自动调 updateInstanceTimeout 续 30 分钟,
156
+ * 调用方无感继续用;续期失败按"实例状态未知"抛 not_found,宁可失败也不
157
+ * 让调用方拿一个马上要死的实例去跑业务
158
+ */
159
+ private initializeAttach;
160
+ /** 管理 API(instance / instance/update / destroy)共用的调用参数。 */
161
+ private managementCallOpts;
162
+ private createClient;
163
+ getInfo(options?: SandboxOperationOptions): Promise<SandboxInstanceInfo>;
164
+ extendTimeout(timeoutInMinutes: number, options?: SandboxOperationOptions): Promise<SandboxInstanceInfo>;
165
+ /**
166
+ * 管理方法的销毁恢复:控制面抛 not_found(后端 404)本身就是定罪——
167
+ * 管理接口就在控制面上,不需要二次验证。其它错误原样抛。
168
+ *
169
+ * detached / attach 模式不重建(理由同 callWithRecreate)——not_found
170
+ * 原样抛给调用方,由调用方决定下一步。
171
+ */
172
+ private managementCallWithRecreate;
173
+ destroy(options?: SandboxOperationOptions): Promise<void>;
174
+ private performDestroy;
175
+ private destroyStandalone;
176
+ private destroyPersistentBinding;
177
+ }
178
+ /**
179
+ * 创建一个 IgaSandbox 实例——既是官方 SandboxClient(业务能力自动懒加载),
180
+ * 又叠加管理能力(getInfo / extendTimeout / destroy)。
181
+ *
182
+ * 工厂本身不发任何网络请求。业务方法直接调用即可,第一次访问触发懒加载:
183
+ *
184
+ * const sandbox = createSandbox({...});
185
+ * await sandbox.code.executeCode({...}); // ← 第一次调用自动触发懒加载
186
+ * await sandbox.destroy();
187
+ *
188
+ * 同一 projectId:conversationId 多次调用会共享实例身份和凭证缓存;请求取消只通过
189
+ * 单次 operation 的 abortSignal 传入,不会固化进 Sandbox 对象或共享 client。
190
+ */
191
+ export declare function createSandbox(options: CreateSandboxOptions): SandboxInstance;
192
+ /**
193
+ * 独立实例:不绑定 conversation,不进缓存。首次懒加载时建全新实例,
194
+ * sandboxId 挂到 Sandbox 对象上(`sandbox.sandboxId`),调用方自己保存。
195
+ * 之后再操作它用 `connectSandbox(sandboxId)`(公共入口)接回来。
196
+ *
197
+ * 工厂本身不发网络请求。
198
+ */
199
+ export declare function createDetachedSandbox(options: IgaDetachedSandboxOptions): SandboxInstance;
200
+ /**
201
+ * 接回已有实例:不建新实例。首次懒加载时 getToken 换凭证 + 前置检查,数据面路由
202
+ * 指向传入的 sandboxId。sandboxId 在 Sandbox 对象上同步可读。
203
+ *
204
+ * 前置检查(fail-fast):查一次 sandbox/instance——实例不存在 / Failed /
205
+ * Terminating 直接抛 `内部实例丢失信号`;已过期自动续期 30 分钟,
206
+ * 续不上也抛错。控制面查询自身失败原样抛,不误判 not_found。
207
+ */
208
+ export declare function attachSandbox(options: IgaAttachSandboxOptions): SandboxInstance;
@@ -0,0 +1,8 @@
1
+ /** Server-only Sandbox SDK for BytePlus IGA Pages Functions and full-stack handlers. */
2
+ export { connectSandbox, createSandbox, getConversationSandbox, } from "./runtime-sandbox.js";
3
+ export { SandboxError, isAbortError } from "./error.js";
4
+ export type { IgaErrorInfo } from "./error.js";
5
+ export type { Sandbox, SandboxOperationOptions, SandboxInstanceInfo, } from "./types.js";
6
+ export type { BaseRequestOptions } from "@agent-infra/sandbox";
7
+ /** Named request, response-body and data types for the public business modules. */
8
+ export type * as SandboxApi from "./api-types.js";
@@ -0,0 +1,19 @@
1
+ import type { SandboxClient } from "@agent-infra/sandbox";
2
+ /** Explicit business-method allowlist. Upstream additions stay internal. */
3
+ export declare const PUBLIC_SANDBOX_METHODS: {
4
+ readonly code: readonly ["executeCode"];
5
+ readonly shell: readonly ["execCommand", "view", "waitForProcess", "killProcess"];
6
+ readonly file: readonly ["readFile", "writeFile", "replaceInFile", "searchInFile", "findFiles", "grepFiles", "listPath"];
7
+ readonly browserPage: readonly ["navigate", "back", "forward", "reload", "click", "fill", "typeText", "pressKey", "hotKey", "hover", "selectOption", "check", "uncheck", "uploadFile", "scroll", "scrollTo", "scrollToElement", "screenshot", "getHtml", "getText", "wait"];
8
+ };
9
+ export type PublicSandboxModule = keyof typeof PUBLIC_SANDBOX_METHODS;
10
+ export declare const PUBLIC_SANDBOX_MODULES: PublicSandboxModule[];
11
+ type PublicSandboxMethod<T> = T extends (...args: infer Args) => infer Result ? (...args: Args) => Promise<Awaited<Result>> : never;
12
+ export type PublicSandboxBusiness = {
13
+ [M in PublicSandboxModule]: {
14
+ [K in Extract<(typeof PUBLIC_SANDBOX_METHODS)[M][number], keyof SandboxClient[M]>]: PublicSandboxMethod<SandboxClient[M][K]>;
15
+ };
16
+ };
17
+ /** Plain frozen facades prevent access through descriptors or prototypes too. */
18
+ export declare function createPublicModules(invoke: (module: PublicSandboxModule, method: string, args: unknown[]) => unknown): PublicSandboxBusiness;
19
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { Sandbox } from "./types.js";
2
+ /**
3
+ * 返回某个会话对应的逻辑沙箱;conversationId 为非空字符串,UTF-8 最多 256 字节。
4
+ *
5
+ * 同一 projectId:conversationId 始终定位同一逻辑沙箱,实例身份与首次初始化
6
+ * 跨请求复用;返回轻量的 Sandbox 对象,不发网络请求,首次访问官方能力才触发懒加载。
7
+ */
8
+ export declare function getConversationSandbox(conversationId: string): Sandbox;
9
+ /**
10
+ * 创建一个独立沙箱实例,不绑定任何会话。
11
+ *
12
+ * SDK 不在 sandboxId 与实例之间维护映射——调用方 await 返回后直接读取
13
+ * `sandbox.sandboxId` 并自己保存;之后再操作
14
+ * 这个实例用 `connectSandbox(sandboxId)` 接回来。
15
+ *
16
+ * 等待凭证获取、远端实例创建和客户端初始化完成后返回;初始化失败时 reject。
17
+ */
18
+ export declare function createSandbox(): Promise<Sandbox & {
19
+ readonly sandboxId: string;
20
+ }>;
21
+ /**
22
+ * 通过 sandboxId 接回一个已存在的沙箱实例。
23
+ *
24
+ * 不建新实例:懒加载时只换凭证,数据面路由直接指向传入的 sandboxId。
25
+ * SDK 不维护 sandboxId 映射。
26
+ *
27
+ * 懒加载时做前置检查(fail-fast):
28
+ * - 实例不存在(或状态为 Failed / Terminating)→ 抛 `内部实例丢失信号`,
29
+ * 不用等第一次业务调用撞 404 才发现
30
+ * - 实例已过期 → 自动续期 30 分钟后接回;续不上就抛错
31
+ */
32
+ export declare function connectSandbox(sandboxId: string): Sandbox;