@tangle-network/sandbox 0.0.0-develop.20260514223840.b2abd84

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.
@@ -0,0 +1,136 @@
1
+ //#region src/collaboration/types.d.ts
2
+ /**
3
+ * Collaboration Types
4
+ *
5
+ * Shared type contracts for collaborative document identity and bootstrap.
6
+ */
7
+ /**
8
+ * Headers shape accepted by `fetch` requests. Mirrors the standard
9
+ * `HeadersInit` (which is not consistently exported by `@types/node`).
10
+ */
11
+ type CollaborationRequestHeaders = Headers | Record<string, string> | Array<[string, string]>;
12
+ interface CollaborationDocumentRef {
13
+ workspaceId: string;
14
+ relativePath: string;
15
+ }
16
+ interface CollaborationTransportConfig {
17
+ websocketUrl: string;
18
+ token: string;
19
+ expiresAt: number;
20
+ }
21
+ interface CollaborationPermissions {
22
+ access: "read" | "write";
23
+ canSnapshot: boolean;
24
+ }
25
+ interface CollaborationBootstrapRequest {
26
+ workspaceId: string;
27
+ relativePath: string;
28
+ }
29
+ interface CollaborationBootstrapResponse {
30
+ documentId: string;
31
+ transport: CollaborationTransportConfig;
32
+ permissions: CollaborationPermissions;
33
+ source: "crdt" | "filesystem";
34
+ initialContent: string;
35
+ snapshotVersion?: string;
36
+ }
37
+ interface CollaborationTokenRefreshRequest {
38
+ workspaceId: string;
39
+ documentId: string;
40
+ }
41
+ interface CollaborationTokenRefreshResponse {
42
+ token: string;
43
+ expiresAt: number;
44
+ access: "read" | "write";
45
+ }
46
+ interface SaveCollaborationSnapshotRequest {
47
+ workspaceId: string;
48
+ relativePath: string;
49
+ documentId: string;
50
+ }
51
+ interface SaveCollaborationSnapshotResponse {
52
+ snapshotVersion: string;
53
+ savedAt: string;
54
+ }
55
+ interface CollaborationFileEvent {
56
+ path: string;
57
+ type: "updated" | "deleted" | "renamed";
58
+ content?: string;
59
+ nextPath?: string;
60
+ origin?: "agent" | "user" | "system" | "bridge";
61
+ version?: string;
62
+ }
63
+ interface CollaborationDocumentChange {
64
+ content: string;
65
+ origin?: string;
66
+ version?: string;
67
+ }
68
+ interface CollaborationDocumentAdapter {
69
+ getContent(): string;
70
+ replaceContent(content: string, meta?: {
71
+ origin?: string;
72
+ version?: string;
73
+ }): void;
74
+ subscribe(listener: (change: CollaborationDocumentChange) => void): () => void;
75
+ }
76
+ interface CollaborationFileBridgeOptions {
77
+ documentId: string;
78
+ relativePath: string;
79
+ writeFile: (path: string, content: string) => Promise<void>;
80
+ subscribeToFileEvents: (path: string, onChange: (event: CollaborationFileEvent) => void) => () => void;
81
+ debounceMs?: number;
82
+ onFileDeleted?: (event: CollaborationFileEvent) => void;
83
+ onFileRenamed?: (event: CollaborationFileEvent) => void;
84
+ }
85
+ interface CollaborationClientConfig {
86
+ baseUrl: string;
87
+ timeoutMs?: number;
88
+ headers?: CollaborationRequestHeaders | (() => CollaborationRequestHeaders | Promise<CollaborationRequestHeaders>);
89
+ fetch?: typeof globalThis.fetch;
90
+ }
91
+ //#endregion
92
+ //#region src/collaboration/client.d.ts
93
+ declare class CollaborationClient {
94
+ private readonly baseUrl;
95
+ private readonly timeoutMs;
96
+ private readonly fetchImpl;
97
+ private readonly headers?;
98
+ constructor(config: CollaborationClientConfig);
99
+ bootstrap(request: CollaborationBootstrapRequest): Promise<CollaborationBootstrapResponse>;
100
+ refreshToken(request: CollaborationTokenRefreshRequest): Promise<CollaborationTokenRefreshResponse>;
101
+ saveSnapshot(request: SaveCollaborationSnapshotRequest): Promise<SaveCollaborationSnapshotResponse>;
102
+ private requestJson;
103
+ private resolveHeaders;
104
+ }
105
+ //#endregion
106
+ //#region src/collaboration/document-id.d.ts
107
+ declare function normalizeCollaborationPath(path: string): string;
108
+ declare function buildCollaborationDocumentId(ref: CollaborationDocumentRef): string;
109
+ declare function parseCollaborationDocumentId(documentId: string): CollaborationDocumentRef | null;
110
+ //#endregion
111
+ //#region src/collaboration/file-bridge.d.ts
112
+ /**
113
+ * Headless bridge between a collaborative document adapter and the sandbox
114
+ * filesystem. Keeps this package free of direct Yjs assumptions.
115
+ */
116
+ declare class CollaborationFileBridge {
117
+ private readonly debounceMs;
118
+ private readonly options;
119
+ private adapter;
120
+ private unsubscribeDocument;
121
+ private unsubscribeFileEvents;
122
+ private pendingWriteTimer;
123
+ private destroyed;
124
+ private boundPath;
125
+ private lastWrittenContent;
126
+ constructor(options: CollaborationFileBridgeOptions);
127
+ bind(adapter: CollaborationDocumentAdapter): void;
128
+ flush(): Promise<void>;
129
+ getPath(): string;
130
+ destroy(): void;
131
+ private scheduleWrite;
132
+ private write;
133
+ private handleFileEvent;
134
+ }
135
+ //#endregion
136
+ export { CollaborationTransportConfig as _, CollaborationClient as a, CollaborationClientConfig as c, CollaborationDocumentRef as d, CollaborationFileBridgeOptions as f, CollaborationTokenRefreshResponse as g, CollaborationTokenRefreshRequest as h, parseCollaborationDocumentId as i, CollaborationDocumentAdapter as l, CollaborationPermissions as m, buildCollaborationDocumentId as n, CollaborationBootstrapRequest as o, CollaborationFileEvent as p, normalizeCollaborationPath as r, CollaborationBootstrapResponse as s, CollaborationFileBridge as t, CollaborationDocumentChange as u, SaveCollaborationSnapshotRequest as v, SaveCollaborationSnapshotResponse as y };
@@ -0,0 +1,371 @@
1
+ import { P as CreateSandboxOptions, n as SandboxInstance, t as HttpClient } from "./sandbox-CTe9fN5m.js";
2
+
3
+ //#region src/tangle/abi.d.ts
4
+ /**
5
+ * Tangle Contract ABI Definitions
6
+ *
7
+ * Viem-compatible ABI for the ITangleJobs precompile, the AgentSandbox
8
+ * blueprint contract views/events, and ABI parameter definitions for
9
+ * encoding/decoding blueprint job inputs and outputs.
10
+ */
11
+ declare const ITangleJobsAbi: readonly [{
12
+ readonly type: "function";
13
+ readonly name: "submitJob";
14
+ readonly inputs: readonly [{
15
+ readonly name: "serviceId";
16
+ readonly type: "uint64";
17
+ }, {
18
+ readonly name: "jobIndex";
19
+ readonly type: "uint8";
20
+ }, {
21
+ readonly name: "inputs";
22
+ readonly type: "bytes";
23
+ }];
24
+ readonly outputs: readonly [{
25
+ readonly name: "callId";
26
+ readonly type: "uint64";
27
+ }];
28
+ readonly stateMutability: "payable";
29
+ }, {
30
+ readonly type: "function";
31
+ readonly name: "getJobCall";
32
+ readonly inputs: readonly [{
33
+ readonly name: "serviceId";
34
+ readonly type: "uint64";
35
+ }, {
36
+ readonly name: "callId";
37
+ readonly type: "uint64";
38
+ }];
39
+ readonly outputs: readonly [{
40
+ readonly name: "";
41
+ readonly type: "tuple";
42
+ readonly components: readonly [{
43
+ readonly name: "jobIndex";
44
+ readonly type: "uint8";
45
+ }, {
46
+ readonly name: "caller";
47
+ readonly type: "address";
48
+ }, {
49
+ readonly name: "createdAt";
50
+ readonly type: "uint64";
51
+ }, {
52
+ readonly name: "resultCount";
53
+ readonly type: "uint32";
54
+ }, {
55
+ readonly name: "payment";
56
+ readonly type: "uint256";
57
+ }, {
58
+ readonly name: "completed";
59
+ readonly type: "bool";
60
+ }];
61
+ }];
62
+ readonly stateMutability: "view";
63
+ }, {
64
+ readonly type: "event";
65
+ readonly name: "JobSubmitted";
66
+ readonly inputs: readonly [{
67
+ readonly name: "serviceId";
68
+ readonly type: "uint64";
69
+ readonly indexed: true;
70
+ }, {
71
+ readonly name: "callId";
72
+ readonly type: "uint64";
73
+ readonly indexed: true;
74
+ }, {
75
+ readonly name: "jobIndex";
76
+ readonly type: "uint8";
77
+ readonly indexed: true;
78
+ }, {
79
+ readonly name: "caller";
80
+ readonly type: "address";
81
+ readonly indexed: false;
82
+ }, {
83
+ readonly name: "inputs";
84
+ readonly type: "bytes";
85
+ readonly indexed: false;
86
+ }];
87
+ }, {
88
+ readonly type: "event";
89
+ readonly name: "JobResultSubmitted";
90
+ readonly inputs: readonly [{
91
+ readonly name: "serviceId";
92
+ readonly type: "uint64";
93
+ readonly indexed: true;
94
+ }, {
95
+ readonly name: "callId";
96
+ readonly type: "uint64";
97
+ readonly indexed: true;
98
+ }, {
99
+ readonly name: "operator";
100
+ readonly type: "address";
101
+ readonly indexed: true;
102
+ }, {
103
+ readonly name: "result";
104
+ readonly type: "bytes";
105
+ readonly indexed: false;
106
+ }];
107
+ }];
108
+ declare const SandboxCreateParamTypes: readonly [{
109
+ readonly name: "name";
110
+ readonly type: "string";
111
+ }, {
112
+ readonly name: "image";
113
+ readonly type: "string";
114
+ }, {
115
+ readonly name: "stack";
116
+ readonly type: "string";
117
+ }, {
118
+ readonly name: "agent_identifier";
119
+ readonly type: "string";
120
+ }, {
121
+ readonly name: "env_json";
122
+ readonly type: "string";
123
+ }, {
124
+ readonly name: "metadata_json";
125
+ readonly type: "string";
126
+ }, {
127
+ readonly name: "ssh_enabled";
128
+ readonly type: "bool";
129
+ }, {
130
+ readonly name: "ssh_public_key";
131
+ readonly type: "string";
132
+ }, {
133
+ readonly name: "web_terminal_enabled";
134
+ readonly type: "bool";
135
+ }, {
136
+ readonly name: "max_lifetime_seconds";
137
+ readonly type: "uint64";
138
+ }, {
139
+ readonly name: "idle_timeout_seconds";
140
+ readonly type: "uint64";
141
+ }, {
142
+ readonly name: "cpu_cores";
143
+ readonly type: "uint64";
144
+ }, {
145
+ readonly name: "memory_mb";
146
+ readonly type: "uint64";
147
+ }, {
148
+ readonly name: "disk_gb";
149
+ readonly type: "uint64";
150
+ }, {
151
+ readonly name: "tee_required";
152
+ readonly type: "bool";
153
+ }, {
154
+ readonly name: "tee_type";
155
+ readonly type: "uint8";
156
+ }, {
157
+ readonly name: "attestation_nonce";
158
+ readonly type: "string";
159
+ }];
160
+ declare const SandboxIdParamTypes: readonly [{
161
+ readonly name: "sandbox_id";
162
+ readonly type: "string";
163
+ }];
164
+ declare const SandboxCreateResponseParamTypes: readonly [{
165
+ readonly name: "sandboxId";
166
+ readonly type: "string";
167
+ }, {
168
+ readonly name: "json";
169
+ readonly type: "string";
170
+ }];
171
+ declare const JsonResponseParamTypes: readonly [{
172
+ readonly name: "json";
173
+ readonly type: "string";
174
+ }];
175
+ declare const AgentSandboxBlueprintAbi: readonly [{
176
+ readonly type: "function";
177
+ readonly name: "getAvailableCapacity";
178
+ readonly inputs: readonly [];
179
+ readonly outputs: readonly [{
180
+ readonly name: "available";
181
+ readonly type: "uint32";
182
+ }];
183
+ readonly stateMutability: "view";
184
+ }, {
185
+ readonly type: "function";
186
+ readonly name: "getServiceStats";
187
+ readonly inputs: readonly [];
188
+ readonly outputs: readonly [{
189
+ readonly name: "totalSandboxes";
190
+ readonly type: "uint32";
191
+ }, {
192
+ readonly name: "totalCapacity";
193
+ readonly type: "uint32";
194
+ }];
195
+ readonly stateMutability: "view";
196
+ }, {
197
+ readonly type: "function";
198
+ readonly name: "getOperatorLoad";
199
+ readonly inputs: readonly [{
200
+ readonly name: "operator";
201
+ readonly type: "address";
202
+ }];
203
+ readonly outputs: readonly [{
204
+ readonly name: "active";
205
+ readonly type: "uint32";
206
+ }, {
207
+ readonly name: "max";
208
+ readonly type: "uint32";
209
+ }];
210
+ readonly stateMutability: "view";
211
+ }, {
212
+ readonly type: "function";
213
+ readonly name: "getSandboxOperator";
214
+ readonly inputs: readonly [{
215
+ readonly name: "sandboxId";
216
+ readonly type: "string";
217
+ }];
218
+ readonly outputs: readonly [{
219
+ readonly name: "";
220
+ readonly type: "address";
221
+ }];
222
+ readonly stateMutability: "view";
223
+ }, {
224
+ readonly type: "function";
225
+ readonly name: "isSandboxActive";
226
+ readonly inputs: readonly [{
227
+ readonly name: "sandboxId";
228
+ readonly type: "string";
229
+ }];
230
+ readonly outputs: readonly [{
231
+ readonly name: "";
232
+ readonly type: "bool";
233
+ }];
234
+ readonly stateMutability: "view";
235
+ }, {
236
+ readonly type: "event";
237
+ readonly name: "OperatorAssigned";
238
+ readonly inputs: readonly [{
239
+ readonly name: "serviceId";
240
+ readonly type: "uint64";
241
+ readonly indexed: true;
242
+ }, {
243
+ readonly name: "callId";
244
+ readonly type: "uint64";
245
+ readonly indexed: true;
246
+ }, {
247
+ readonly name: "operator";
248
+ readonly type: "address";
249
+ readonly indexed: true;
250
+ }];
251
+ }, {
252
+ readonly type: "event";
253
+ readonly name: "OperatorRouted";
254
+ readonly inputs: readonly [{
255
+ readonly name: "serviceId";
256
+ readonly type: "uint64";
257
+ readonly indexed: true;
258
+ }, {
259
+ readonly name: "callId";
260
+ readonly type: "uint64";
261
+ readonly indexed: true;
262
+ }, {
263
+ readonly name: "operator";
264
+ readonly type: "address";
265
+ readonly indexed: true;
266
+ }];
267
+ }, {
268
+ readonly type: "event";
269
+ readonly name: "SandboxCreated";
270
+ readonly inputs: readonly [{
271
+ readonly name: "sandboxHash";
272
+ readonly type: "bytes32";
273
+ readonly indexed: true;
274
+ }, {
275
+ readonly name: "operator";
276
+ readonly type: "address";
277
+ readonly indexed: true;
278
+ }];
279
+ }, {
280
+ readonly type: "event";
281
+ readonly name: "SandboxDeleted";
282
+ readonly inputs: readonly [{
283
+ readonly name: "sandboxHash";
284
+ readonly type: "bytes32";
285
+ readonly indexed: true;
286
+ }, {
287
+ readonly name: "operator";
288
+ readonly type: "address";
289
+ readonly indexed: true;
290
+ }];
291
+ }];
292
+ //#endregion
293
+ //#region src/tangle/types.d.ts
294
+ /**
295
+ * Tangle Sandbox Client types and constants.
296
+ */
297
+ /** Tangle mainnet chain ID. */
298
+ declare const TANGLE_CHAIN_ID = 5845;
299
+ /** Tangle mainnet RPC endpoint. */
300
+ declare const TANGLE_MAINNET_RPC = "https://rpc.tangle.tools";
301
+ /** ITangleJobs precompile contract address. */
302
+ declare const TANGLE_JOBS_CONTRACT: "0x0000000000000000000000000000000000000808";
303
+ /** Job indices matching the blueprint's job IDs. */
304
+ declare const JOB_SANDBOX_CREATE = 0;
305
+ declare const JOB_SANDBOX_DELETE = 1;
306
+ interface TangleSandboxClientConfig {
307
+ /** Tangle service instance ID for the sandbox blueprint. */
308
+ serviceId: bigint;
309
+ /** viem WalletClient for browser environments. Mutually exclusive with privateKey. */
310
+ wallet?: unknown;
311
+ /** Hex-encoded private key for Node.js environments. Mutually exclusive with wallet. */
312
+ privateKey?: `0x${string}`;
313
+ /** RPC URL. Required when using privateKey. Defaults to Tangle mainnet. */
314
+ rpcUrl?: string;
315
+ /** Blueprint contract address for view calls (getAvailableCapacity, etc). */
316
+ blueprintContractAddress?: `0x${string}`;
317
+ /** ITangleJobs precompile address. Defaults to 0x...0808. */
318
+ contractAddress?: `0x${string}`;
319
+ /** Max time to wait for a job to complete. No hard limit — agent jobs can run hours. Default: 14400000 (4h). */
320
+ jobTimeoutMs?: number;
321
+ /** Interval between job completion polls. Default: 5000 (5s). */
322
+ pollIntervalMs?: number;
323
+ /**
324
+ * Operator API base URL for routes that must be handled by the Blueprint
325
+ * operator rather than the sidecar directly, such as nonce-bound TEE
326
+ * attestation.
327
+ */
328
+ operatorApiUrl?: string;
329
+ /** Bearer token for the operator API session. */
330
+ operatorApiToken?: string;
331
+ }
332
+ //#endregion
333
+ //#region src/tangle/client.d.ts
334
+ declare class TangleSandboxClient implements HttpClient {
335
+ private readonly chain;
336
+ private readonly sandboxes;
337
+ private readonly operatorApiUrl?;
338
+ private readonly operatorApiToken?;
339
+ constructor(config: TangleSandboxClientConfig);
340
+ /**
341
+ * Create a sandbox via on-chain job submission.
342
+ */
343
+ create(options?: CreateSandboxOptions): Promise<SandboxInstance>;
344
+ /**
345
+ * Route interception for SandboxInstance lifecycle calls.
346
+ *
347
+ * SandboxInstance calls this.client.fetch() for:
348
+ * - GET /v1/sandboxes/:id → return from local tracking
349
+ * - POST /v1/sandboxes/:id/stop → unsupported until blueprint exposes stop
350
+ * - POST /v1/sandboxes/:id/resume → unsupported until blueprint exposes resume
351
+ * - DELETE /v1/sandboxes/:id → on-chain JOB_SANDBOX_DELETE
352
+ */
353
+ fetch(path: string, options?: RequestInit): Promise<Response>;
354
+ private fetchRuntime;
355
+ /**
356
+ * Get available capacity from the blueprint contract.
357
+ * Requires blueprintContractAddress in config.
358
+ */
359
+ getAvailableCapacity(): Promise<number>;
360
+ /**
361
+ * Get service stats from the blueprint contract.
362
+ * Requires blueprintContractAddress in config.
363
+ */
364
+ getServiceStats(): Promise<{
365
+ totalSandboxes: number;
366
+ totalCapacity: number;
367
+ }>;
368
+ private fetchOperatorApi;
369
+ }
370
+ //#endregion
371
+ export { TANGLE_JOBS_CONTRACT as a, AgentSandboxBlueprintAbi as c, SandboxCreateParamTypes as d, SandboxCreateResponseParamTypes as f, TANGLE_CHAIN_ID as i, ITangleJobsAbi as l, JOB_SANDBOX_CREATE as n, TANGLE_MAINNET_RPC as o, SandboxIdParamTypes as p, JOB_SANDBOX_DELETE as r, TangleSandboxClientConfig as s, TangleSandboxClient as t, JsonResponseParamTypes as u };