@tangle-network/sandbox 0.0.3

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