@tangle-network/sandbox 0.57.0 → 0.58.1
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.
- package/README.md +3 -2
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.js +36 -74
- package/dist/agent/preview.d.ts +1 -1
- package/dist/agent/preview.js +2 -2
- package/dist/{agent-run-outcome-B8PjRMLE.d.ts → agent-run-outcome-CJP18Ip8.d.ts} +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/{browser-interactive-control-controller-knjCl8Zp.d.ts → browser-interactive-control-controller-1m7jgLeg.d.ts} +1 -1
- package/dist/{client-CdbHGWiu.js → client-BHItHEg0.js} +19 -5
- package/dist/{client-BHGieo06.d.ts → client-BI0_ZUUS.d.ts} +6 -4
- package/dist/collaboration/index.d.ts +1 -1
- package/dist/core.d.ts +6 -5
- package/dist/core.js +5 -3
- package/dist/{index-C1sVorE5.d.ts → index-BitiSmBp.d.ts} +2 -2
- package/dist/index.d.ts +12 -11
- package/dist/index.js +6 -4
- package/dist/interactive-control.d.ts +1 -1
- package/dist/line-application-DOg7jrnA.js +100 -0
- package/dist/lines-DLIo-NTB.d.ts +556 -0
- package/dist/lines.d.ts +2 -0
- package/dist/lines.js +273 -0
- package/dist/{local-cli-auth-DfuFJCcs.js → local-cli-auth-N1IYywxf.js} +1 -1
- package/dist/{mcp-local-DUT2U_y8.js → mcp-local-BWsftreI.js} +27 -16
- package/dist/{preview-wJJxG42-.d.ts → preview-CVrjEPgk.d.ts} +3 -3
- package/dist/runtime.d.ts +3 -3
- package/dist/{sandbox-C9VLoJAb.js → sandbox-B2kuUBn6.js} +84 -228
- package/dist/{sandbox-DWDqWnsJ.d.ts → sandbox-DyPRgt1M.d.ts} +10 -411
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +1 -1
- package/dist/{tangle-Bm6H-xIM.js → tangle-DCjIsZI0.js} +1 -1
- package/dist/{types-CFmeauzy.d.ts → types-_Gn4d93t.d.ts} +72 -2
- package/package.json +9 -4
- /package/dist/{cli-auth-bundle-bRJOyaJO.js → cli-auth-bundle-0VjPAtKt.js} +0 -0
- /package/dist/{errors-CNsmhCen.d.ts → errors-AVpynVrG.d.ts} +0 -0
- /package/dist/{index-BN7zNEUB.d.ts → index-C48z7K4r.d.ts} +0 -0
- /package/dist/{index-X4EEZlMi.d.ts → index-D4u-vv87.d.ts} +0 -0
- /package/dist/{preview-operations-Dgbi46FH.js → preview-operations-BhQ4_CF7.js} +0 -0
- /package/dist/{terminal-stream-BW4veIsI.d.ts → terminal-stream-Bf2stNDX.d.ts} +0 -0
|
@@ -2,6 +2,7 @@ import { C as normalizeRuntimeBackendConfig, S as mergeRuntimeBackendConfig, T a
|
|
|
2
2
|
import { _ as parseErrorResponse, c as NotFoundError, f as SandboxError, g as ValidationError, h as TimeoutError, m as StateError, n as CapabilityError, p as ServerError, r as EdgeNotReadyError, s as NetworkError, t as AuthError, u as QuotaError } from "./errors-BkhlSDW-.js";
|
|
3
3
|
import { c as createInteractiveControlHolderId, d as interactiveSessionControlReleaseResponseSchema, f as interactiveSessionControlValidationResponseSchema, i as createBrowserInteractiveSessionControlTransport, o as InteractiveSessionControlController, p as interactiveSessionStatusResponseSchema, r as browserInteractiveTerminalEndpoint, s as assertInteractiveSessionRef, u as interactiveSessionControlClaimResponseSchema } from "./browser-interactive-control-controller-CVGqjPgs.js";
|
|
4
4
|
import { n as combineAbortSignals, t as awaitWithAbort } from "./abort-signal-CgFhjY_v.js";
|
|
5
|
+
import { SandboxLines } from "./lines.js";
|
|
5
6
|
import { AgentExactRunControlRefSchema, AgentInteractiveSessionAttachSchema, AgentInteractiveSessionControlClaimAcknowledgementSchema, AgentInteractiveSessionControlClaimRequestSchema, AgentInteractiveSessionControlClaimSchema, AgentInteractiveSessionPromptAcknowledgementSchema, AgentInteractiveSessionPromptCommandSchema, AgentInteractiveSessionRefSchema, AgentInteractiveSessionStartSchema, AgentInteractiveSessionStopAcknowledgementSchema, AgentInteractiveSessionStopCommandSchema, AgentRunCancellationAcknowledgementSchema, AgentRunCancellationRequestSchema, InteractionAcknowledgementSchema, InteractionBindingSchema, InteractionRequestSchema, InteractionResponseCommandSchema, InteractionResponseSchema, TerminalInputSchema, TerminalOutputEventSchema, TerminalReplayWindowSchema, TerminalResizeSchema, TerminalSessionRefSchema, agentInteractiveSessionControlClaimAcknowledgementMatchesRequest, agentInteractiveSessionControlClaimIsNewer, agentInteractiveSessionControlClaimMatchesRef, agentInteractiveSessionPromptAcknowledgementMatchesCommand, agentInteractiveSessionPromptRequestDigest, agentInteractiveSessionRefMatchesStart, agentInteractiveSessionStatusMatchesRef, agentInteractiveSessionStopAcknowledgementMatchesCommand, agentRunCancellationAcknowledgementMatchesRequest, canonicalCandidateDigest, exactAgentInteractiveSessionStart, sha256DigestSchema, terminalSessionUsable } from "@tangle-network/agent-interface";
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
import { AgentInteractiveSessionControlClaimSchema as AgentInteractiveSessionControlClaimSchema$1, AgentInteractiveSessionPromptAcknowledgementSchema as AgentInteractiveSessionPromptAcknowledgementSchema$1, AgentInteractiveSessionRefSchema as AgentInteractiveSessionRefSchema$1, AgentInteractiveSessionStatusSchema, AgentInteractiveSessionStopAcknowledgementSchema as AgentInteractiveSessionStopAcknowledgementSchema$1 } from "@tangle-network/agent-interface/environment-interactive-control";
|
|
@@ -229,227 +230,6 @@ function rewrapResponse(original, headers) {
|
|
|
229
230
|
return wrapper;
|
|
230
231
|
}
|
|
231
232
|
//#endregion
|
|
232
|
-
//#region src/lines.ts
|
|
233
|
-
/**
|
|
234
|
-
* Lines: give a sandbox a phone number or messaging address.
|
|
235
|
-
*
|
|
236
|
-
* A line is an address that Tangle Hub receives on, such as an Inkbox
|
|
237
|
-
* iMessage identity or Linq WhatsApp number. Attaching it to a sandbox makes
|
|
238
|
-
* Hub route each inbound message to that sandbox. Each member gets a separate
|
|
239
|
-
* thread in its own agent session. Hub sends the agent's answer on the same
|
|
240
|
-
* line. Hub owns routing, consent (STOP/START), unknown senders and
|
|
241
|
-
* metering, so an app only chooses who may text and in which mode.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```ts
|
|
245
|
-
* const line = await client.lines.fromConnection({ connectionId, transport: "imessage" });
|
|
246
|
-
* await box.lines.attach({
|
|
247
|
-
* number: line.id,
|
|
248
|
-
* mode: "personal",
|
|
249
|
-
* members: [{ address: "+15550100001", role: "owner" }],
|
|
250
|
-
* });
|
|
251
|
-
* // Text `line.connect` to `line.routerAddress`, then write to the agent.
|
|
252
|
-
* ```
|
|
253
|
-
*
|
|
254
|
-
* A line can also give every member their own sandbox, so a public line
|
|
255
|
-
* serves each person from an isolated box with its own files:
|
|
256
|
-
*
|
|
257
|
-
* ```ts
|
|
258
|
-
* await client.lines.attach({
|
|
259
|
-
* number: line.id,
|
|
260
|
-
* mode: "shared",
|
|
261
|
-
* members: [{ address: "+15550100001", role: "owner" }],
|
|
262
|
-
* unknownSenders: "guest",
|
|
263
|
-
* roles: { owner: { context: "own", tools: "act" }, guest: { context: "own", tools: "act" } },
|
|
264
|
-
* instance: { keyPrefix: "person:", create: { idleTimeoutSeconds: 600 } },
|
|
265
|
-
* });
|
|
266
|
-
* ```
|
|
267
|
-
*/
|
|
268
|
-
/**
|
|
269
|
-
* The instance key that serves one member: `keyPrefix` plus the first 32 hex
|
|
270
|
-
* characters of the SHA-256 of the member's address as Hub stores it (E.164,
|
|
271
|
-
* or a lowercased email). It depends only on the prefix and the address, so a
|
|
272
|
-
* person keeps their box across re-attaches, and your own code can reach it
|
|
273
|
-
* with `client.instances.ensure({ key })`.
|
|
274
|
-
*/
|
|
275
|
-
async function lineInstanceKey(keyPrefix, address) {
|
|
276
|
-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(address));
|
|
277
|
-
return `${keyPrefix}${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 32)}`;
|
|
278
|
-
}
|
|
279
|
-
const LINE_ID = /^ln_[A-Za-z0-9_-]+$/;
|
|
280
|
-
async function hubData(response) {
|
|
281
|
-
const body = await response.text();
|
|
282
|
-
if (!response.ok) throw parseErrorResponse(response.status, body, void 0, response.headers);
|
|
283
|
-
const parsed = JSON.parse(body);
|
|
284
|
-
if (parsed.success !== true || parsed.data === void 0) throw parseErrorResponse(502, body, void 0, response.headers);
|
|
285
|
-
return parsed.data;
|
|
286
|
-
}
|
|
287
|
-
function json(method, body) {
|
|
288
|
-
return {
|
|
289
|
-
method,
|
|
290
|
-
headers: { "Content-Type": "application/json" },
|
|
291
|
-
body: JSON.stringify(body)
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
/** `client.lines`: your lines, their members and their threads. */
|
|
295
|
-
var LinesClient = class {
|
|
296
|
-
constructor(http) {
|
|
297
|
-
this.http = http;
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Create a line from an owned Inkbox or Linq connection, or return the line
|
|
301
|
-
* already pinned to that provider identity. Hub owns inbound routing and
|
|
302
|
-
* never re-keys the connection.
|
|
303
|
-
*/
|
|
304
|
-
async fromConnection(input) {
|
|
305
|
-
return (await hubData(await this.http.fetch("/v1/lines", json("POST", input)))).line;
|
|
306
|
-
}
|
|
307
|
-
/** Your lines. `sandboxId` narrows to lines attached to that sandbox. */
|
|
308
|
-
async list(options = {}) {
|
|
309
|
-
const query = options.sandboxId ? `?sandboxId=${encodeURIComponent(options.sandboxId)}` : "";
|
|
310
|
-
return (await hubData(await this.http.fetch(`/v1/lines${query}`))).lines;
|
|
311
|
-
}
|
|
312
|
-
async get(lineId) {
|
|
313
|
-
return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`))).line;
|
|
314
|
-
}
|
|
315
|
-
/** A line id for a line id or one of your lines' addresses. */
|
|
316
|
-
async resolve(number) {
|
|
317
|
-
if (LINE_ID.test(number)) return number;
|
|
318
|
-
const line = (await this.list()).find((l) => l.address === number);
|
|
319
|
-
if (!line) throw new ValidationError(`No line with address ${number}`);
|
|
320
|
-
return line.id;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Attach a line so each member runs in their own sandbox. Hub checks that
|
|
324
|
-
* your API key can run sandboxes, and each turn runs as a short-lived child
|
|
325
|
-
* of that key. Attaching again with the same options returns the same
|
|
326
|
-
* attachment. To attach a line to one sandbox, use `box.lines.attach()`.
|
|
327
|
-
*/
|
|
328
|
-
async attach(options) {
|
|
329
|
-
const lineId = await this.resolve(options.number);
|
|
330
|
-
const { number: _number, ...rest } = options;
|
|
331
|
-
return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment`, json("PUT", rest)))).attachment;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Detach a line (by id or address), whatever it is attached to. This is
|
|
335
|
-
* the way to detach a line attached with `instance`, which names no
|
|
336
|
-
* sandbox. Each member's own sandbox stays under its instance key. Returns
|
|
337
|
-
* false when the line was not attached.
|
|
338
|
-
*/
|
|
339
|
-
async detach(number) {
|
|
340
|
-
const lineId = await this.resolve(number);
|
|
341
|
-
return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment`, { method: "DELETE" }))).detached;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Retire a detached line's Hub routing and free its workspace transport slot.
|
|
345
|
-
* Hub refuses an attached or voice-enabled line. A retry by line id returns
|
|
346
|
-
* false; the provider connection and message history remain.
|
|
347
|
-
*/
|
|
348
|
-
async release(number) {
|
|
349
|
-
const lineId = await this.resolve(number);
|
|
350
|
-
return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`, { method: "DELETE" }))).released;
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Take calls on a line (Inkbox iMessage lines). Hub points the identity's
|
|
354
|
-
* incoming calls at itself, binds the ph0ny agent to the line and adds the
|
|
355
|
-
* agent's `ask_workspace` tool. Enabling again replaces every credential.
|
|
356
|
-
*/
|
|
357
|
-
async enableVoice(lineId, options) {
|
|
358
|
-
return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`, json("PATCH", { voice: {
|
|
359
|
-
enabled: true,
|
|
360
|
-
ph0ny: {
|
|
361
|
-
connectionId: options.ph0nyConnectionId,
|
|
362
|
-
agentId: options.ph0nyAgentId
|
|
363
|
-
}
|
|
364
|
-
} })))).line;
|
|
365
|
-
}
|
|
366
|
-
/** Stop taking calls on a line: Hub refuses them and Inkbox rejects them. */
|
|
367
|
-
async disableVoice(lineId) {
|
|
368
|
-
return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`, json("PATCH", { voice: { enabled: false } })))).line;
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Queue a proactive message to an active, consenting member. Hub reuses the
|
|
372
|
-
* member's authenticated provider conversation, rechecks STOP immediately
|
|
373
|
-
* before delivery, and defers delivery during the recipient's saved quiet hours.
|
|
374
|
-
*/
|
|
375
|
-
async send(lineId, input) {
|
|
376
|
-
return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/send`, json("POST", input)));
|
|
377
|
-
}
|
|
378
|
-
/** Read the native outbox receipt. Queued is not a delivery confirmation. */
|
|
379
|
-
async sentMessage(lineId, messageId) {
|
|
380
|
-
return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/outbox/${encodeURIComponent(messageId)}`));
|
|
381
|
-
}
|
|
382
|
-
/** Only the recipient's proven message can enable reminders or choose quiet hours. */
|
|
383
|
-
async reminders(lineId, memberId) {
|
|
384
|
-
return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/members/${encodeURIComponent(memberId)}/reminders`));
|
|
385
|
-
}
|
|
386
|
-
/** Members of the line's active attachment. */
|
|
387
|
-
members(lineId) {
|
|
388
|
-
const base = `/v1/lines/${encodeURIComponent(lineId)}/members`;
|
|
389
|
-
const http = this.http;
|
|
390
|
-
return {
|
|
391
|
-
async list() {
|
|
392
|
-
return (await hubData(await http.fetch(base))).members;
|
|
393
|
-
},
|
|
394
|
-
async add(spec) {
|
|
395
|
-
return (await hubData(await http.fetch(base, json("POST", spec)))).member;
|
|
396
|
-
},
|
|
397
|
-
async update(memberId, patch) {
|
|
398
|
-
return (await hubData(await http.fetch(`${base}/${encodeURIComponent(memberId)}`, json("PATCH", patch)))).member;
|
|
399
|
-
},
|
|
400
|
-
async remove(memberId) {
|
|
401
|
-
await hubData(await http.fetch(`${base}/${encodeURIComponent(memberId)}`, { method: "DELETE" }));
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
/** Threads of a line (one per member) and their messages, newest first. */
|
|
406
|
-
threads(lineId) {
|
|
407
|
-
const base = `/v1/lines/${encodeURIComponent(lineId)}/threads`;
|
|
408
|
-
const http = this.http;
|
|
409
|
-
return {
|
|
410
|
-
async list() {
|
|
411
|
-
return (await hubData(await http.fetch(base))).threads;
|
|
412
|
-
},
|
|
413
|
-
async messages(threadId) {
|
|
414
|
-
return (await hubData(await http.fetch(`${base}/${encodeURIComponent(threadId)}/messages`))).messages;
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
/** `sandbox.lines`: attach lines to this sandbox. */
|
|
420
|
-
var SandboxLines = class {
|
|
421
|
-
lines;
|
|
422
|
-
constructor(http, sandboxId) {
|
|
423
|
-
this.http = http;
|
|
424
|
-
this.sandboxId = sandboxId;
|
|
425
|
-
this.lines = new LinesClient(http);
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Attach a line to this sandbox. Hub checks that your API key can run this
|
|
429
|
-
* sandbox, and each turn runs as a short-lived child of that key. Attaching
|
|
430
|
-
* again with the same options returns the same attachment.
|
|
431
|
-
*/
|
|
432
|
-
async attach(options) {
|
|
433
|
-
const lineId = await this.lines.resolve(options.number);
|
|
434
|
-
const { number: _number, ...rest } = options;
|
|
435
|
-
return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment`, json("PUT", {
|
|
436
|
-
...rest,
|
|
437
|
-
sandboxId: this.sandboxId
|
|
438
|
-
})))).attachment;
|
|
439
|
-
}
|
|
440
|
-
/** Lines attached to this sandbox. */
|
|
441
|
-
async list() {
|
|
442
|
-
return this.lines.list({ sandboxId: this.sandboxId });
|
|
443
|
-
}
|
|
444
|
-
/** Detach a line (by id or address) from this sandbox. */
|
|
445
|
-
async detach(number) {
|
|
446
|
-
const lineId = await this.lines.resolve(number);
|
|
447
|
-
const line = await this.lines.get(lineId);
|
|
448
|
-
if (line.attachment && line.attachment.sandboxId !== this.sandboxId) throw new ValidationError(`Line ${lineId} is attached to another sandbox`);
|
|
449
|
-
await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment`, { method: "DELETE" }));
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
//#endregion
|
|
453
233
|
//#region src/normalize.ts
|
|
454
234
|
/**
|
|
455
235
|
* Normalize a raw `connection` payload from the Sandbox API into the SDK's
|
|
@@ -521,6 +301,58 @@ function normalizeSandboxShape(raw) {
|
|
|
521
301
|
};
|
|
522
302
|
}
|
|
523
303
|
//#endregion
|
|
304
|
+
//#region src/managed-process.ts
|
|
305
|
+
var ManagedProcessClient = class {
|
|
306
|
+
constructor(request, environmentId) {
|
|
307
|
+
this.request = request;
|
|
308
|
+
this.environmentId = environmentId;
|
|
309
|
+
}
|
|
310
|
+
async call(method, id, spec, options) {
|
|
311
|
+
if (typeof id !== "string" || !id.length || id.length > 256) throw new ValidationError("Invalid managed process id");
|
|
312
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
313
|
+
if (options?.sessionId) headers.set("X-Session-Id", options.sessionId);
|
|
314
|
+
const response = await this.request(method === "POST" ? "/process/jobs" : `/process/jobs/${encodeURIComponent(id)}`, {
|
|
315
|
+
method,
|
|
316
|
+
headers,
|
|
317
|
+
...spec ? { body: JSON.stringify(spec) } : {}
|
|
318
|
+
});
|
|
319
|
+
const text = await response.text();
|
|
320
|
+
let value;
|
|
321
|
+
try {
|
|
322
|
+
value = JSON.parse(text);
|
|
323
|
+
} catch {
|
|
324
|
+
if (!response.ok) throw parseErrorResponse(response.status, text, void 0, response.headers);
|
|
325
|
+
throw new ValidationError("Managed process response is not JSON");
|
|
326
|
+
}
|
|
327
|
+
const envelope = value;
|
|
328
|
+
if (method !== "POST" && response.status === 404 && envelope?.error?.code === "MANAGED_PROCESS_NOT_FOUND") return null;
|
|
329
|
+
if (!response.ok) throw parseErrorResponse(response.status, text, void 0, response.headers);
|
|
330
|
+
const record = envelope?.data;
|
|
331
|
+
if (envelope?.success !== true || record?.schema !== 1 || record.spec?.id !== id || record.environmentId !== this.environmentId || ![
|
|
332
|
+
"queued",
|
|
333
|
+
"running",
|
|
334
|
+
"retrying",
|
|
335
|
+
"stopping",
|
|
336
|
+
"succeeded",
|
|
337
|
+
"failed",
|
|
338
|
+
"cancelled",
|
|
339
|
+
"expired"
|
|
340
|
+
].includes(record.state) || !Number.isSafeInteger(record.attempt) || record.attempt < 0 || typeof record.digest !== "string" || !/^[a-f0-9]{64}$/.test(record.digest)) throw new ValidationError("Managed process response has invalid identity or state");
|
|
341
|
+
return record;
|
|
342
|
+
}
|
|
343
|
+
async submit(spec, options) {
|
|
344
|
+
const record = await this.call("POST", spec.id, spec, options);
|
|
345
|
+
if (!record) throw new ValidationError("Managed process admission returned no record");
|
|
346
|
+
return record;
|
|
347
|
+
}
|
|
348
|
+
get(id, options) {
|
|
349
|
+
return this.call("GET", id, void 0, options);
|
|
350
|
+
}
|
|
351
|
+
cancel(id, options) {
|
|
352
|
+
return this.call("DELETE", id, void 0, options);
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
//#endregion
|
|
524
356
|
//#region src/capabilities.ts
|
|
525
357
|
function invalidCapabilities(message) {
|
|
526
358
|
throw new ServerError(`Capability discovery returned ${message}`, 502, {
|
|
@@ -3745,6 +3577,18 @@ const SANDBOX_CREATE_OUTCOMES = [
|
|
|
3745
3577
|
* An outcome this SDK version does not know becomes `unknown`: only a known
|
|
3746
3578
|
* `created` proves that the call allocated the environment.
|
|
3747
3579
|
*/
|
|
3580
|
+
function normalizeCaptureProof(raw) {
|
|
3581
|
+
if (!raw || typeof raw !== "object") return null;
|
|
3582
|
+
const proof = raw;
|
|
3583
|
+
if (typeof proof.hostId !== "string" || proof.hostId.length === 0 || typeof proof.containerId !== "string" || !/^[a-f0-9]{64}$/.test(proof.containerId) || typeof proof.imageId !== "string" || !/^sha256:[a-f0-9]{64}$/.test(proof.imageId) || typeof proof.bundleRevision !== "string" || !/^[a-f0-9]{40}$/.test(proof.bundleRevision) || typeof proof.bundleChecksum !== "string" || !/^sha256:[a-f0-9]{64}$/.test(proof.bundleChecksum)) return null;
|
|
3584
|
+
return {
|
|
3585
|
+
hostId: proof.hostId,
|
|
3586
|
+
containerId: proof.containerId,
|
|
3587
|
+
imageId: proof.imageId,
|
|
3588
|
+
bundleRevision: proof.bundleRevision,
|
|
3589
|
+
bundleChecksum: proof.bundleChecksum
|
|
3590
|
+
};
|
|
3591
|
+
}
|
|
3748
3592
|
function normalizeSandboxCreateReceipt(raw) {
|
|
3749
3593
|
if (!raw || typeof raw !== "object") return null;
|
|
3750
3594
|
const record = raw;
|
|
@@ -3756,7 +3600,8 @@ function normalizeSandboxCreateReceipt(raw) {
|
|
|
3756
3600
|
outcome,
|
|
3757
3601
|
idempotencyKeyApplied,
|
|
3758
3602
|
...record.ownerContext === "inherit" || record.ownerContext === "isolated" ? { ownerContext: record.ownerContext } : {},
|
|
3759
|
-
...injectedSecrets ? { injectedSecrets } : {}
|
|
3603
|
+
...injectedSecrets ? { injectedSecrets } : {},
|
|
3604
|
+
...normalizeCaptureProof(record.captureProof) ? { captureProof: normalizeCaptureProof(record.captureProof) ?? void 0 } : {}
|
|
3760
3605
|
};
|
|
3761
3606
|
}
|
|
3762
3607
|
/**
|
|
@@ -4276,6 +4121,10 @@ var SandboxInstance = class SandboxInstance {
|
|
|
4276
4121
|
createReceipt() {
|
|
4277
4122
|
return this.info.createReceipt ?? null;
|
|
4278
4123
|
}
|
|
4124
|
+
/** Verified identity of the currently running container, if available. */
|
|
4125
|
+
captureProof() {
|
|
4126
|
+
return this.info.captureProof ?? null;
|
|
4127
|
+
}
|
|
4279
4128
|
/**
|
|
4280
4129
|
* Serialize to the public sandbox shape for logs and structured
|
|
4281
4130
|
* output. Secrets in `connection` (currently `authToken`) are
|
|
@@ -6370,6 +6219,10 @@ var SandboxInstance = class SandboxInstance {
|
|
|
6370
6219
|
*/
|
|
6371
6220
|
get process() {
|
|
6372
6221
|
return {
|
|
6222
|
+
jobs: new ManagedProcessClient(async (path, init) => {
|
|
6223
|
+
await this.ensureRunning();
|
|
6224
|
+
return this.runtimeFetch(path, init);
|
|
6225
|
+
}, this.id),
|
|
6373
6226
|
ensureDevServer: (options) => this.processEnsureDevServer(options),
|
|
6374
6227
|
spawn: (command, options) => this.processSpawn(command, options),
|
|
6375
6228
|
spawnExact: (executable, args, options) => this.processSpawnExact(executable, args, options),
|
|
@@ -8039,6 +7892,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
8039
7892
|
status: data.status ?? "pending",
|
|
8040
7893
|
connection,
|
|
8041
7894
|
metadata: data.metadata,
|
|
7895
|
+
captureProof: normalizeCaptureProof(data.captureProof) ?? void 0,
|
|
8042
7896
|
createdAt: data.createdAt ? new Date(data.createdAt) : this.info.createdAt,
|
|
8043
7897
|
startedAt: data.startedAt ? new Date(data.startedAt) : void 0,
|
|
8044
7898
|
lastActivityAt: data.lastActivityAt ? new Date(data.lastActivityAt) : void 0,
|
|
@@ -8577,9 +8431,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
8577
8431
|
for (let index = 0; index < binary.length; index += 1) content[index] = binary.charCodeAt(index);
|
|
8578
8432
|
if (content.length !== raw.sizeBytes) throw new ServerError("Native rollout byte count mismatch");
|
|
8579
8433
|
const subtle = globalThis.crypto?.subtle;
|
|
8580
|
-
if (
|
|
8581
|
-
const digest = await subtle.digest("SHA-256", content);
|
|
8582
|
-
if (`sha256:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("")}` !== raw.sha256) throw new ServerError("Native rollout SHA-256 mismatch");
|
|
8434
|
+
if ((subtle ? `sha256:${Array.from(new Uint8Array(await subtle.digest("SHA-256", content)), (byte) => byte.toString(16).padStart(2, "0")).join("")}` : `sha256:${(await import("node:crypto")).createHash("sha256").update(content).digest("hex")}`) !== raw.sha256) throw new ServerError("Native rollout SHA-256 mismatch");
|
|
8583
8435
|
let exported;
|
|
8584
8436
|
try {
|
|
8585
8437
|
exported = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(content));
|
|
@@ -8588,7 +8440,8 @@ var SandboxInstance = class SandboxInstance {
|
|
|
8588
8440
|
}
|
|
8589
8441
|
const native = typeof exported === "object" && exported !== null && !Array.isArray(exported) ? exported : void 0;
|
|
8590
8442
|
const info = native?.info;
|
|
8591
|
-
if (typeof info !== "object" || info === null || Array.isArray(info) || info.id !== raw.nativeSessionId
|
|
8443
|
+
if (typeof info !== "object" || info === null || Array.isArray(info) || info.id !== raw.nativeSessionId) throw new ServerError("Native rollout session ID mismatch");
|
|
8444
|
+
if (!Array.isArray(native?.messages)) throw new ServerError("Malformed native rollout content");
|
|
8592
8445
|
return {
|
|
8593
8446
|
...raw,
|
|
8594
8447
|
content
|
|
@@ -8597,6 +8450,7 @@ var SandboxInstance = class SandboxInstance {
|
|
|
8597
8450
|
/** @internal — invoked before the sandbox is deleted. */
|
|
8598
8451
|
async _sessionRawEvidence(id) {
|
|
8599
8452
|
await this.ensureRunning();
|
|
8453
|
+
await this.refresh();
|
|
8600
8454
|
const response = await this.runtimeFetch(`/agents/sessions/${encodeURIComponent(id)}/raw-evidence`);
|
|
8601
8455
|
if (!response.ok && response.status !== 404) throw parseErrorResponse(response.status, await response.text(), void 0, response.headers);
|
|
8602
8456
|
const raw = await response.json();
|
|
@@ -8607,7 +8461,9 @@ var SandboxInstance = class SandboxInstance {
|
|
|
8607
8461
|
return record;
|
|
8608
8462
|
}
|
|
8609
8463
|
const completeness = record.completeness;
|
|
8610
|
-
if (record.status !== "captured" || record.sessionId !== id || typeof record.backendType !== "string" || typeof record.nativeSessionId !== "string" || typeof record.sidecarImageDigest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(record.sidecarImageDigest) || typeof record.sidecarBundleRevision !== "string" || !/^[a-f0-9]{40}$/.test(record.sidecarBundleRevision) || !Array.isArray(record.nativeRoots) || !Array.isArray(record.files) || !Array.isArray(record.excluded) || !Array.isArray(record.processIo) || !Array.isArray(record.processTerminals) || !Array.isArray(record.events) || typeof record.inventory !== "object" || record.inventory === null || completeness?.nativeStore !== true || completeness.processIo !== true || completeness.events !== true || record.coverageComplete !== true) throw new ServerError("Malformed raw evidence response");
|
|
8464
|
+
if (record.status !== "captured" || record.sessionId !== id || typeof record.backendType !== "string" || typeof record.nativeSessionId !== "string" || record.proofStatus !== "verified" && record.proofStatus !== "unverified" || record.proofStatus === "verified" && (typeof record.containerId !== "string" || !/^[a-f0-9]{64}$/.test(record.containerId) || typeof record.sidecarBundleChecksum !== "string" || !/^sha256:[a-f0-9]{64}$/.test(record.sidecarBundleChecksum)) || typeof record.sidecarImageDigest !== "string" || !/^sha256:[a-f0-9]{64}$/.test(record.sidecarImageDigest) || typeof record.sidecarBundleRevision !== "string" || !/^[a-f0-9]{40}$/.test(record.sidecarBundleRevision) || !Array.isArray(record.nativeRoots) || !Array.isArray(record.files) || !Array.isArray(record.excluded) || !Array.isArray(record.processIo) || !Array.isArray(record.processTerminals) || !Array.isArray(record.events) || typeof record.inventory !== "object" || record.inventory === null || completeness?.nativeStore !== true || completeness.processIo !== true || completeness.events !== true || record.coverageComplete !== true) throw new ServerError("Malformed raw evidence response");
|
|
8465
|
+
const expected = this.info.captureProof;
|
|
8466
|
+
if (expected && (record.proofStatus !== "verified" || record.containerId !== expected.containerId || record.sidecarImageDigest !== expected.imageId || record.sidecarBundleRevision !== expected.bundleRevision || record.sidecarBundleChecksum !== expected.bundleChecksum)) throw new ServerError("Raw evidence does not match current container capture proof");
|
|
8611
8467
|
return record;
|
|
8612
8468
|
}
|
|
8613
8469
|
/** @internal — invoked by SandboxSession.runs(). */
|
|
@@ -9005,4 +8861,4 @@ function quoteForShell(value) {
|
|
|
9005
8861
|
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
9006
8862
|
}
|
|
9007
8863
|
//#endregion
|
|
9008
|
-
export {
|
|
8864
|
+
export { rewrapResponse as A, collectAgentFinalMessageText as C, ManagedProcessClient as D, isToolBearingEvent as E, exportTraceBundle as M, otelTraceIdForTangleTrace as N, normalizeConnection as O, toOtelJson as P, applySandboxEventText as S, getSandboxEventText as T, InteractiveSessionController as _, normalizeStartupDiagnostics as a, TERMINAL_WS_ECHO_SUBPROTOCOL as b, MAX_EGRESS_DENIALS_LIMIT as c, InteractiveSessionHandle as d, agentInteractiveSessionPromptRequestDigest as f, BrowserInteractiveSessionController as g, createInteractiveTerminalSession as h, normalizeSandboxCreateReceipt as i, buildTraceExportPayload as j, normalizeSandboxShape as k, SandboxTaskSession as l, createInteractiveTerminalCapture as m, createSandboxInstanceFromResponse as n, WorkspaceImages as o, InteractiveTerminalFrameLog as p, normalizeCaptureProof as r, GPU_LEASE_PROVIDER_NAMES as s, SandboxInstance as t, SandboxSession as u, TerminalStream as v, collectAgentResponseText as w, requestInteractiveSessionToken as x, TerminalStreamError as y };
|