@tangle-network/sandbox 0.60.78-develop.20261017090901.9326d18 → 0.60.78-develop.20261021201434.3bcd5ef

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 (66) hide show
  1. package/README.md +61 -0
  2. package/dist/agent/index.d.ts +4 -4
  3. package/dist/agent/index.js +5 -5
  4. package/dist/agent/preview.d.ts +1 -1
  5. package/dist/agent/preview.js +2 -2
  6. package/dist/{agent-run-outcome-CTEpjCEZ.d.ts → agent-run-outcome-brwJbH5S.d.ts} +1 -1
  7. package/dist/auth/index.d.ts +2 -2
  8. package/dist/auth/index.js +5 -5
  9. package/dist/{backend-types-D6bYbvMB.js → backend-types-CLvdSX8V.js} +41 -1
  10. package/dist/{browser-interactive-control-controller-rpTbyvAS.d.ts → browser-interactive-control-controller-CvObO_Kf.d.ts} +1 -1
  11. package/dist/{browser-interactive-control-controller-BJf0P_J4.js → browser-interactive-control-controller-DHx53yre.js} +16 -1
  12. package/dist/{chunked-upload-DtIvkKNo.js → chunked-upload-DN2twsUu.js} +2 -59
  13. package/dist/{chunked-upload-file-DnsHEjg0.js → chunked-upload-file-Dpv1YsoA.js} +2 -1
  14. package/dist/{cli-auth-bundle-cSJjPeFF.js → cli-auth-bundle-CFeHsq-5.js} +23 -11
  15. package/dist/{client-R1tw-4Px.js → client-CgtR203z.js} +3349 -3341
  16. package/dist/client-Dr8qasCR.d.ts +6076 -0
  17. package/dist/collaboration/index.d.ts +1 -1
  18. package/dist/collaboration/index.js +1 -1
  19. package/dist/{collaboration-DaJU5O0E.js → collaboration-g_HzXa6f.js} +5 -5
  20. package/dist/core.d.ts +7 -7
  21. package/dist/core.js +7 -6
  22. package/dist/direct-http2-Dar5erTH.js +99 -0
  23. package/dist/{errors-DSJBKmGZ.js → errors-BfbOP_rx.js} +171 -22
  24. package/dist/{index-DO7GVpk_.d.ts → index-C8VSFtWl.d.ts} +1 -1
  25. package/dist/{index-DZ27pdB8.d.ts → index-CVjTnRWP.d.ts} +1 -1
  26. package/dist/{sandbox-CoIGxzm_.d.ts → index-D5dVNm76.d.ts} +2117 -1519
  27. package/dist/index.d.ts +12 -4704
  28. package/dist/index.js +40 -15
  29. package/dist/intelligence/index.js +1 -1
  30. package/dist/interactive-control.d.ts +1 -1
  31. package/dist/interactive-control.js +1 -1
  32. package/dist/{interactive-controller-CJ24g8Va.js → interactive-controller-OAsASPd_.js} +662 -620
  33. package/dist/interactive-controller-nMhGqXxq.d.ts +41 -0
  34. package/dist/keep-alive-fetch-BBzJDWyt.js +247 -0
  35. package/dist/{lines-DodQslsf.d.ts → lines-C5CPSg8n.d.ts} +21 -17
  36. package/dist/lines-C5ER4aN_.js +298 -0
  37. package/dist/lines.d.ts +1 -1
  38. package/dist/lines.js +1 -295
  39. package/dist/{local-cli-auth-CBV7Vjk5.js → local-cli-auth-D-CQ0-ub.js} +1 -1
  40. package/dist/{mcp-local-DjryqUiY.js → mcp-local-BjLG7VHY.js} +1 -1
  41. package/dist/{preview-wpGGk0bu.d.ts → preview-COO7TSBk.d.ts} +3 -3
  42. package/dist/public-templates-BDrchm0J.d.ts +80 -0
  43. package/dist/public-templates.d.ts +2 -0
  44. package/dist/public-templates.js +173 -0
  45. package/dist/{raw-evidence-archive-Br5a3xZ_.js → raw-evidence-archive-CDYDqHNv.js} +161 -69
  46. package/dist/runtime.d.ts +49 -41
  47. package/dist/runtime.js +8 -8
  48. package/dist/{sandbox-C7Tk62qn.js → sandbox-BrZxAq11.js} +9048 -8939
  49. package/dist/{secp256k1-Dx2XABHz.js → secp256k1-CmLpsmWl.js} +1 -1
  50. package/dist/session-gateway/index.d.ts +23 -67
  51. package/dist/session-gateway/index.js +578 -451
  52. package/dist/tangle/index.d.ts +1 -1
  53. package/dist/tangle/index.js +1 -1
  54. package/dist/{tangle-Ba4Kz5zT.js → tangle-GiPBak5X.js} +176 -169
  55. package/dist/terminal-stream-types-ClZCArRg.d.ts +662 -0
  56. package/dist/{types-B_QF-iHm.d.ts → types-CtH0GRql.d.ts} +6161 -5812
  57. package/package.json +12 -7
  58. package/dist/client-Lhxo82x1.d.ts +0 -1261
  59. package/dist/errors-mPL-qvgF.d.ts +0 -347
  60. package/dist/index-DRto9Ijb.d.ts +0 -579
  61. package/dist/managed-process-B7WfqKmi.d.ts +0 -15
  62. package/dist/terminal-stream-jdYomM1m.d.ts +0 -389
  63. /package/dist/{cli-auth-bundle-ODe06Ts7.d.ts → cli-auth-bundle-Dyw3hCGx.d.ts} +0 -0
  64. /package/dist/{line-application-Cq6dJLBD.js → line-application-DY9ZTdgF.js} +0 -0
  65. /package/dist/{preview-operations-DqSo-IBm.js → preview-operations-Ca02vPDJ.js} +0 -0
  66. /package/dist/{utils-B7_9Hl_z.js → utils-BGvM02yJ.js} +0 -0
package/dist/lines.js CHANGED
@@ -1,296 +1,2 @@
1
- import { b as ValidationError, x as parseErrorResponse } from "./errors-DSJBKmGZ.js";
2
- //#region src/lines.ts
3
- /**
4
- * Lines: give a sandbox a phone number or messaging address.
5
- *
6
- * A line is an address that Tangle Hub receives on, such as an Inkbox
7
- * iMessage identity or Linq WhatsApp number. Attaching it to a sandbox makes
8
- * Hub route each inbound message to that sandbox. Each member gets a separate
9
- * thread in its own agent session. Hub sends the agent's answer on the same
10
- * line. Hub owns routing, consent (STOP/START), unknown senders and
11
- * metering, so an app only chooses who may text and in which mode.
12
- *
13
- * @example
14
- * ```ts
15
- * const line = await client.lines.fromConnection({ connectionId, transport: "imessage" });
16
- * await box.lines.attach({
17
- * number: line.id,
18
- * mode: "personal",
19
- * members: [{ address: "+15550100001", role: "owner" }],
20
- * });
21
- * // Text `line.connect` to `line.routerAddress`, then write to the agent.
22
- * ```
23
- *
24
- * A line can also give every member their own sandbox, so a public line
25
- * serves each person from an isolated box with its own files:
26
- *
27
- * ```ts
28
- * await client.lines.attach({
29
- * number: line.id,
30
- * mode: "shared",
31
- * members: [{ address: "+15550100001", role: "owner" }],
32
- * unknownSenders: "guest",
33
- * roles: { owner: { context: "own", tools: "act" }, guest: { context: "own", tools: "act" } },
34
- * instance: { keyPrefix: "person:", create: { idleTimeoutSeconds: 600 } },
35
- * });
36
- * ```
37
- */
38
- /**
39
- * The instance key that serves one member: `keyPrefix` plus the first 32 hex
40
- * characters of the SHA-256 of the member's address as Hub stores it (E.164,
41
- * or a lowercased email). It depends only on the prefix and the address, so a
42
- * person keeps their box across re-attaches, and your own code can reach it
43
- * with `client.instances.ensure({ key })`. This helper applies only to
44
- * address-bound members. Hub derives a different key for `subjectId` members.
45
- */
46
- async function lineInstanceKey(keyPrefix, address) {
47
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(address));
48
- return `${keyPrefix}${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 32)}`;
49
- }
50
- /** Stable setup retry identity. This label never grants profile or line access. */
51
- async function profileChannelReference(profileId, input) {
52
- if (!/^ap_[A-Za-z0-9_-]{1,61}$/.test(profileId)) throw new ValidationError("Use a stored Platform profile ID");
53
- const identity = JSON.stringify([
54
- input.connectionId,
55
- input.transport,
56
- input.phoneNumberId ?? null,
57
- input.address?.trim().toLowerCase() ?? null
58
- ]);
59
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(identity));
60
- return `profile:${profileId}:${Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join("").slice(0, 32)}`;
61
- }
62
- const LINE_ID = /^ln_[A-Za-z0-9_-]+$/;
63
- async function hubData(response) {
64
- const body = await response.text();
65
- if (!response.ok) throw parseErrorResponse(response.status, body, void 0, response.headers);
66
- const parsed = JSON.parse(body);
67
- if (parsed.success !== true || parsed.data === void 0) throw parseErrorResponse(502, body, void 0, response.headers);
68
- return parsed.data;
69
- }
70
- function json(method, body) {
71
- return {
72
- method,
73
- headers: { "Content-Type": "application/json" },
74
- body: JSON.stringify(body)
75
- };
76
- }
77
- /** `client.lines`: your lines, their members and their threads. */
78
- var LinesClient = class {
79
- constructor(http) {
80
- this.http = http;
81
- }
82
- /**
83
- * Create a line from an owned Inkbox or Linq connection, or return the line
84
- * already pinned to that provider identity. Hub owns inbound routing and
85
- * never re-keys the connection.
86
- */
87
- async fromConnection(input) {
88
- return (await hubData(await this.http.fetch("/v1/lines", json("POST", input)))).line;
89
- }
90
- /** Your lines. `sandboxId` narrows to lines attached to that sandbox. */
91
- async list(options = {}) {
92
- const params = new URLSearchParams();
93
- if (options.sandboxId) params.set("sandboxId", options.sandboxId);
94
- if (options.profileId) params.set("profileId", options.profileId);
95
- const query = params.size ? `?${params}` : "";
96
- return (await hubData(await this.http.fetch(`/v1/lines${query}`))).lines;
97
- }
98
- /** Supported combinations from the maintained host channel catalog. */
99
- async providers() {
100
- return (await hubData(await this.http.fetch("/v1/lines/providers"))).providers;
101
- }
102
- /** Metadata only; no reservation and no provider credentials are returned. */
103
- async numbers(connectionId, transport) {
104
- const params = new URLSearchParams({
105
- connectionId,
106
- transport
107
- });
108
- return hubData(await this.http.fetch(`/v1/lines/numbers?${params}`));
109
- }
110
- /** Choose the payer/execution authority for a cookie-authenticated attachment. */
111
- async executionKeys() {
112
- return (await hubData(await this.http.fetch("/v1/lines/execution-keys"))).keys;
113
- }
114
- async get(lineId) {
115
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`))).line;
116
- }
117
- /** A line id for a line id or one of your lines' addresses. */
118
- async resolve(number) {
119
- if (LINE_ID.test(number)) return number;
120
- const line = (await this.list()).find((l) => l.address === number);
121
- if (!line) throw new ValidationError(`No line with address ${number}`);
122
- return line.id;
123
- }
124
- /** Start a signed Inkbox iMessage owner-handset test for an unattached line. */
125
- async startSenderVerification(number) {
126
- const lineId = await this.resolve(number);
127
- return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/sender-verifications`, json("POST", {})));
128
- }
129
- /** Read proof state with the same owner API key that started the test. */
130
- async getSenderVerification(number, testId) {
131
- if (!/^lsv_[A-Za-z0-9_-]+$/.test(testId)) throw new ValidationError("A valid sender verification id is required");
132
- const lineId = await this.resolve(number);
133
- return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/sender-verifications/${encodeURIComponent(testId)}`));
134
- }
135
- /**
136
- * Attach a line to member sandboxes or one application callback. Hub checks
137
- * the owner key and keeps one active attachment. The callback must resolve
138
- * each declared customer's subject to its own authorized private target.
139
- */
140
- async attach(options) {
141
- const lineId = await this.resolve(options.number);
142
- const { number: _number, ...rest } = options;
143
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment`, json("PUT", rest)))).attachment;
144
- }
145
- /** Bind the current API key to this same attachment after app key rotation.
146
- * Hub checks the observed attachment and old key, app key lineage, owner,
147
- * workspace and sandbox. A race leaves the existing binding unchanged.
148
- */
149
- async reauthorizeAttachment(number, expected) {
150
- if (!/^lat_[A-Za-z0-9_-]+$/.test(expected.expectedAttachmentId)) throw new ValidationError("A valid expected attachment id is required");
151
- if (!/^key_[A-Za-z0-9_-]+$/.test(expected.expectedRunAsKeyId)) throw new ValidationError("A valid expected execution key id is required");
152
- const lineId = await this.resolve(number);
153
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment/reauthorize`, json("PUT", expected)))).attachment;
154
- }
155
- /**
156
- * Detach a line (by id or address), whatever it is attached to. This is
157
- * the way to detach a line attached with `instance`, which names no
158
- * sandbox. Each member's own sandbox stays under its instance key. Returns
159
- * false when the line was not attached.
160
- */
161
- async detach(number, options = {}) {
162
- if (options.expectedAttachmentId !== void 0 && !/^lat_[A-Za-z0-9_-]+$/.test(options.expectedAttachmentId)) throw new ValidationError("Invalid expected attachment identity");
163
- const lineId = await this.resolve(number);
164
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment`, {
165
- method: "DELETE",
166
- ...options.expectedAttachmentId ? { headers: { "if-match": `"${options.expectedAttachmentId}"` } } : {}
167
- }))).detached;
168
- }
169
- /** Detach only this observed attachment. A replacement is left untouched.
170
- * The distinct native route makes older hosts refuse rather than ignore
171
- * the condition. This never falls back to unconditional line detachment.
172
- */
173
- async detachAttachment(number, attachmentId) {
174
- if (!/^[A-Za-z0-9_-]{1,256}$/.test(attachmentId)) throw new ValidationError("A valid expected attachment id is required");
175
- const lineId = await this.resolve(number);
176
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachments/${encodeURIComponent(attachmentId)}`, { method: "DELETE" }))).detached;
177
- }
178
- /**
179
- * Retire a detached line's Hub routing and free its workspace transport slot.
180
- * Hub refuses an attached or voice-enabled line. A retry by line id returns
181
- * false; the provider connection and message history remain.
182
- */
183
- async release(number) {
184
- const lineId = await this.resolve(number);
185
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`, { method: "DELETE" }))).released;
186
- }
187
- /**
188
- * Take calls for an active Hub line. Without a phone number ID, the line
189
- * must be Inkbox iMessage; Hub changes its call action and adds
190
- * `ask_workspace` to the agent. With an owned ph0ny phone number ID, Hub
191
- * binds that Twilio number to the line's admission hook and leaves the
192
- * line's provider call settings unchanged.
193
- */
194
- async enableVoice(lineId, options) {
195
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`, json("PATCH", { voice: {
196
- enabled: true,
197
- ph0ny: {
198
- connectionId: options.ph0nyConnectionId,
199
- agentId: options.ph0nyAgentId,
200
- ...options.ph0nyPhoneNumberId ? { phoneNumberId: options.ph0nyPhoneNumberId } : {}
201
- }
202
- } })))).line;
203
- }
204
- /** Stop taking calls on a line: Hub refuses them and Inkbox rejects them. */
205
- async disableVoice(lineId) {
206
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}`, json("PATCH", { voice: { enabled: false } })))).line;
207
- }
208
- /**
209
- * Queue a proactive message to an active, consenting member. Hub reuses the
210
- * member's authenticated provider conversation, rechecks STOP immediately
211
- * before delivery, and defers delivery during the recipient's saved quiet hours.
212
- */
213
- async send(lineId, input) {
214
- return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/send`, json("POST", input)));
215
- }
216
- /** Read the native outbox receipt. Queued is not a delivery confirmation. */
217
- async sentMessage(lineId, messageId) {
218
- return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/outbox/${encodeURIComponent(messageId)}`));
219
- }
220
- /** Only the recipient's proven message can enable reminders or choose quiet hours. */
221
- async reminders(lineId, memberId) {
222
- return hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/members/${encodeURIComponent(memberId)}/reminders`));
223
- }
224
- /** Members of the line's active attachment. */
225
- members(lineId) {
226
- const base = `/v1/lines/${encodeURIComponent(lineId)}/members`;
227
- const http = this.http;
228
- return {
229
- async list() {
230
- return (await hubData(await http.fetch(base))).members;
231
- },
232
- async add(spec) {
233
- return (await hubData(await http.fetch(base, json("POST", spec)))).member;
234
- },
235
- async update(memberId, patch) {
236
- return (await hubData(await http.fetch(`${base}/${encodeURIComponent(memberId)}`, json("PATCH", patch)))).member;
237
- },
238
- async remove(memberId) {
239
- await hubData(await http.fetch(`${base}/${encodeURIComponent(memberId)}`, { method: "DELETE" }));
240
- }
241
- };
242
- }
243
- /** Read one retained message without depending on a recent-message page. */
244
- async message(lineId, messageId) {
245
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/messages/${encodeURIComponent(messageId)}`))).message;
246
- }
247
- /** Threads of a line (one per member) and their messages, newest first. */
248
- threads(lineId) {
249
- const base = `/v1/lines/${encodeURIComponent(lineId)}/threads`;
250
- const http = this.http;
251
- return {
252
- async list() {
253
- return (await hubData(await http.fetch(base))).threads;
254
- },
255
- async messages(threadId) {
256
- return (await hubData(await http.fetch(`${base}/${encodeURIComponent(threadId)}/messages`))).messages;
257
- }
258
- };
259
- }
260
- };
261
- /** `sandbox.lines`: attach lines to this sandbox. */
262
- var SandboxLines = class {
263
- lines;
264
- constructor(http, sandboxId) {
265
- this.http = http;
266
- this.sandboxId = sandboxId;
267
- this.lines = new LinesClient(http);
268
- }
269
- /**
270
- * Attach a line to this sandbox. Hub checks that your API key can run this
271
- * sandbox, and each turn runs as a short-lived child of that key. Attaching
272
- * again with the same options returns the same attachment.
273
- */
274
- async attach(options) {
275
- const lineId = await this.lines.resolve(options.number);
276
- const { number: _number, ...rest } = options;
277
- return (await hubData(await this.http.fetch(`/v1/lines/${encodeURIComponent(lineId)}/attachment`, json("PUT", {
278
- ...rest,
279
- sandboxId: this.sandboxId
280
- })))).attachment;
281
- }
282
- /** Lines attached to this sandbox. */
283
- async list() {
284
- return this.lines.list({ sandboxId: this.sandboxId });
285
- }
286
- /** Detach a line (by id or address) from this sandbox. */
287
- async detach(number) {
288
- const lineId = await this.lines.resolve(number);
289
- const line = await this.lines.get(lineId);
290
- if (!line.attachment) return;
291
- if (line.attachment.sandboxId !== this.sandboxId) throw new ValidationError(`Line ${lineId} is attached to another sandbox`);
292
- await this.lines.detachAttachment(lineId, line.attachment.id);
293
- }
294
- };
295
- //#endregion
1
+ import { i as profileChannelReference, n as SandboxLines, r as lineInstanceKey, t as LinesClient } from "./lines-C5ER4aN_.js";
296
2
  export { LinesClient, SandboxLines, lineInstanceKey, profileChannelReference };
@@ -1,4 +1,4 @@
1
- import { t as AUTH_BUNDLE_PATHS } from "./cli-auth-bundle-cSJjPeFF.js";
1
+ import { t as AUTH_BUNDLE_PATHS } from "./cli-auth-bundle-CFeHsq-5.js";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { homedir } from "node:os";
@@ -1,4 +1,4 @@
1
- import { a as listAgentPreviews, i as getAgentPreview, o as publishAgentPreview, r as ensureAgentPreview, s as removeAgentPreview, t as AgentPreviewError } from "./preview-operations-DqSo-IBm.js";
1
+ import { a as listAgentPreviews, i as getAgentPreview, o as publishAgentPreview, r as ensureAgentPreview, s as removeAgentPreview, t as AgentPreviewError } from "./preview-operations-Ca02vPDJ.js";
2
2
  import { createRequire } from "node:module";
3
3
  //#region \0rolldown/runtime.js
4
4
  var __defProp = Object.defineProperty;
@@ -1,6 +1,6 @@
1
- import { n as SandboxInstance } from "./sandbox-CoIGxzm_.js";
2
- import { Jn as PreviewLinkInfo, _t as EnsureDevServerOptions } from "./types-B_QF-iHm.js";
3
- import { i as Sandbox } from "./client-Lhxo82x1.js";
1
+ import { O as SandboxInstance } from "./index-D5dVNm76.js";
2
+ import { F as EnsureDevServerOptions, H as PreviewLinkInfo } from "./types-CtH0GRql.js";
3
+ import { t as Sandbox } from "./client-Dr8qasCR.js";
4
4
 
5
5
  //#region src/agent/preview-operations.d.ts
6
6
  type AgentPreviewOptions = Pick<EnsureDevServerOptions, "sessionId" | "cwd"> & {
@@ -0,0 +1,80 @@
1
+ import { F as SandboxError } from "./terminal-stream-types-ClZCArRg.js";
2
+ import { Pi as HttpClient, ai as PublishPublicTemplateVersionOptions, ii as PublishPublicTemplateOptions, ni as PublicTemplateInfo, ri as PublicTemplateVersionInfo } from "./types-CtH0GRql.js";
3
+ import { z } from "zod";
4
+
5
+ //#region src/public-templates.d.ts
6
+ declare const publishJobSchema: z.ZodObject<{
7
+ id: z.ZodString;
8
+ artifactId: z.ZodString;
9
+ templateId: z.ZodNullable<z.ZodString>;
10
+ versionId: z.ZodNullable<z.ZodString>;
11
+ status: z.ZodEnum<{
12
+ pending: "pending";
13
+ scanning: "scanning";
14
+ blocked: "blocked";
15
+ ready: "ready";
16
+ failed: "failed";
17
+ }>;
18
+ createdByCustomerId: z.ZodString;
19
+ completedAt: z.ZodNullable<z.ZodString>;
20
+ createdAt: z.ZodString;
21
+ updatedAt: z.ZodString;
22
+ }, z.core.$strip>;
23
+ declare const artifactSchema: z.ZodObject<{
24
+ id: z.ZodString;
25
+ status: z.ZodEnum<{
26
+ pending: "pending";
27
+ scanning: "scanning";
28
+ blocked: "blocked";
29
+ ready: "ready";
30
+ failed: "failed";
31
+ }>;
32
+ sourceSnapshotId: z.ZodString;
33
+ sourceSandboxId: z.ZodString;
34
+ derivedSnapshotId: z.ZodNullable<z.ZodString>;
35
+ errorMessage: z.ZodNullable<z.ZodString>;
36
+ }, z.core.$strip>;
37
+ type PublicTemplatePublishJob = z.infer<typeof publishJobSchema>;
38
+ type PublicTemplatePublishArtifact = z.infer<typeof artifactSchema>;
39
+ interface PublicTemplatePublishRequestOptions {
40
+ /** Total wait, including enqueue and final reads. Defaults to 30 minutes. */
41
+ timeoutMs?: number;
42
+ /** Stops waiting; an accepted publication continues on the server. */
43
+ signal?: AbortSignal;
44
+ /** Resume an accepted job for the same snapshot without publishing again. */
45
+ resumeJobId?: string;
46
+ /** Called when the observed job state changes, including its accepted identity. */
47
+ onProgress?: (job: PublicTemplatePublishJob) => void;
48
+ }
49
+ /** A failed or interrupted publication retains its accepted job for resumption. */
50
+ declare class PublicTemplatePublishError extends SandboxError {
51
+ readonly job: PublicTemplatePublishJob | undefined;
52
+ readonly artifact: PublicTemplatePublishArtifact | undefined;
53
+ constructor(message: string, code: string, job?: PublicTemplatePublishJob, artifact?: PublicTemplatePublishArtifact, cause?: unknown);
54
+ }
55
+ /** Public catalog and snapshot publication, shared by SDK, CLI and browser callers. */
56
+ declare class PublicTemplatesClient {
57
+ private readonly client;
58
+ constructor(client: Pick<HttpClient, "fetch">);
59
+ list(options?: {
60
+ query?: string;
61
+ tag?: string;
62
+ featuredOnly?: boolean;
63
+ limit?: number;
64
+ offset?: number;
65
+ }): Promise<PublicTemplateInfo[]>;
66
+ featured(): Promise<PublicTemplateInfo[]>;
67
+ get(idOrSlug: string): Promise<PublicTemplateInfo>;
68
+ versions(idOrSlug: string): Promise<PublicTemplateVersionInfo[]>;
69
+ publish(input: PublishPublicTemplateOptions, options?: PublicTemplatePublishRequestOptions): Promise<PublicTemplateInfo>;
70
+ publishVersion(idOrSlug: string, input: PublishPublicTemplateVersionOptions, options?: PublicTemplatePublishRequestOptions): Promise<PublicTemplateVersionInfo>;
71
+ /**
72
+ * `submit` is the POST that accepts the publication. Each caller spells its
73
+ * own route at the `client.fetch` call so scripts/check-sdk-route-contract.mjs
74
+ * can see the method and path; a path passed through a helper argument is
75
+ * invisible to it, and the API route then reads as having no SDK method.
76
+ */
77
+ private publishAndWait;
78
+ }
79
+ //#endregion
80
+ export { PublicTemplatesClient as a, PublicTemplatePublishRequestOptions as i, PublicTemplatePublishError as n, PublicTemplatePublishJob as r, PublicTemplatePublishArtifact as t };
@@ -0,0 +1,2 @@
1
+ import { a as PublicTemplatesClient, i as PublicTemplatePublishRequestOptions, n as PublicTemplatePublishError, r as PublicTemplatePublishJob, t as PublicTemplatePublishArtifact } from "./public-templates-BDrchm0J.js";
2
+ export { PublicTemplatePublishArtifact, PublicTemplatePublishError, PublicTemplatePublishJob, PublicTemplatePublishRequestOptions, PublicTemplatesClient };
@@ -0,0 +1,173 @@
1
+ import { b as SandboxError, i as readResponseJson } from "./errors-BfbOP_rx.js";
2
+ import { z } from "zod";
3
+ //#region src/public-templates.ts
4
+ const publicationStatus = z.enum([
5
+ "pending",
6
+ "scanning",
7
+ "blocked",
8
+ "ready",
9
+ "failed"
10
+ ]);
11
+ const publishJobSchema = z.object({
12
+ id: z.string().min(1),
13
+ artifactId: z.string().min(1),
14
+ templateId: z.string().nullable(),
15
+ versionId: z.string().nullable(),
16
+ status: publicationStatus,
17
+ createdByCustomerId: z.string(),
18
+ completedAt: z.string().nullable(),
19
+ createdAt: z.string(),
20
+ updatedAt: z.string()
21
+ });
22
+ const artifactSchema = z.object({
23
+ id: z.string().min(1),
24
+ status: publicationStatus,
25
+ sourceSnapshotId: z.string(),
26
+ sourceSandboxId: z.string(),
27
+ derivedSnapshotId: z.string().nullable(),
28
+ errorMessage: z.string().nullable()
29
+ });
30
+ const publishResponseSchema = z.object({
31
+ job: publishJobSchema,
32
+ artifact: artifactSchema
33
+ });
34
+ /** A failed or interrupted publication retains its accepted job for resumption. */
35
+ var PublicTemplatePublishError = class extends SandboxError {
36
+ job;
37
+ artifact;
38
+ constructor(message, code, job, artifact, cause) {
39
+ super(message, code, cause instanceof SandboxError ? cause.status : void 0, { origin: "sandbox-api" });
40
+ this.name = "PublicTemplatePublishError";
41
+ this.job = job;
42
+ this.artifact = artifact;
43
+ this.cause = cause;
44
+ }
45
+ };
46
+ function pause(ms, signal) {
47
+ return new Promise((resolve, reject) => {
48
+ signal.throwIfAborted();
49
+ const onAbort = () => {
50
+ clearTimeout(timer);
51
+ reject(signal.reason);
52
+ };
53
+ const timer = setTimeout(() => {
54
+ signal.removeEventListener("abort", onAbort);
55
+ resolve();
56
+ }, ms);
57
+ signal.addEventListener("abort", onAbort, { once: true });
58
+ });
59
+ }
60
+ /** Public catalog and snapshot publication, shared by SDK, CLI and browser callers. */
61
+ var PublicTemplatesClient = class {
62
+ client;
63
+ constructor(client) {
64
+ this.client = client;
65
+ }
66
+ async list(options) {
67
+ const params = new URLSearchParams();
68
+ if (options?.query) params.set("q", options.query);
69
+ if (options?.tag) params.set("tag", options.tag);
70
+ if (options?.featuredOnly) params.set("featured", "true");
71
+ if (options?.limit !== void 0) params.set("limit", String(options.limit));
72
+ if (options?.offset !== void 0) params.set("offset", String(options.offset));
73
+ const suffix = params.toString();
74
+ return (await readResponseJson(await this.client.fetch(`/v1/public-templates${suffix ? `?${suffix}` : ""}`))).templates ?? [];
75
+ }
76
+ async featured() {
77
+ return (await readResponseJson(await this.client.fetch("/v1/public-templates/featured"))).templates ?? [];
78
+ }
79
+ async get(idOrSlug) {
80
+ return (await readResponseJson(await this.client.fetch(`/v1/public-templates/${encodeURIComponent(idOrSlug)}`))).template;
81
+ }
82
+ async versions(idOrSlug) {
83
+ return (await readResponseJson(await this.client.fetch(`/v1/public-templates/${encodeURIComponent(idOrSlug)}/versions`))).versions ?? [];
84
+ }
85
+ async publish(input, options = {}) {
86
+ return (await this.publishAndWait((init) => this.client.fetch("/v1/public-templates", {
87
+ ...init,
88
+ method: "POST"
89
+ }), input, options)).template;
90
+ }
91
+ async publishVersion(idOrSlug, input, options = {}) {
92
+ return (await this.publishAndWait((init) => this.client.fetch(`/v1/public-templates/${encodeURIComponent(idOrSlug)}/versions`, {
93
+ ...init,
94
+ method: "POST"
95
+ }), input, options, idOrSlug)).version;
96
+ }
97
+ /**
98
+ * `submit` is the POST that accepts the publication. Each caller spells its
99
+ * own route at the `client.fetch` call so scripts/check-sdk-route-contract.mjs
100
+ * can see the method and path; a path passed through a helper argument is
101
+ * invisible to it, and the API route then reads as having no SDK method.
102
+ */
103
+ async publishAndWait(submit, input, options, idOrSlug) {
104
+ const timeoutMs = options.timeoutMs ?? 30 * 6e4;
105
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 2147483647) throw new TypeError("timeoutMs must be a positive safe timer interval");
106
+ if (options.resumeJobId !== void 0 && !options.resumeJobId.trim()) throw new TypeError("resumeJobId must not be empty");
107
+ options.signal?.throwIfAborted();
108
+ const timeout = AbortSignal.timeout(timeoutMs);
109
+ const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
110
+ let job;
111
+ let artifact;
112
+ const read = async (endpoint, init) => readResponseJson(await this.client.fetch(endpoint, {
113
+ ...init,
114
+ signal
115
+ }));
116
+ const readJob = async (id) => {
117
+ const body = await read(`/v1/public-templates/publish-jobs/${encodeURIComponent(id)}`);
118
+ const next = z.object({ job: publishJobSchema }).parse(body).job;
119
+ if (next.id !== id || job && (next.artifactId !== job.artifactId || next.templateId !== job.templateId || next.versionId !== job.versionId)) throw new Error("Publication job identity changed");
120
+ return next;
121
+ };
122
+ try {
123
+ if (options.resumeJobId) {
124
+ job = await readJob(options.resumeJobId);
125
+ artifact = z.object({ artifact: artifactSchema }).parse(await read(`/v1/public-templates/artifacts/${encodeURIComponent(job.artifactId)}`)).artifact;
126
+ } else {
127
+ const accepted = publishResponseSchema.parse(await readResponseJson(await submit({
128
+ body: JSON.stringify(input),
129
+ signal
130
+ })));
131
+ job = accepted.job;
132
+ artifact = accepted.artifact;
133
+ }
134
+ if (artifact.id !== job.artifactId || artifact.sourceSnapshotId !== input.snapshotId || artifact.sourceSandboxId !== input.sourceSandboxId) throw new Error("Publication receipt does not match the requested snapshot");
135
+ if (idOrSlug && options.resumeJobId) {
136
+ const { template } = await read(`/v1/public-templates/${encodeURIComponent(idOrSlug)}`);
137
+ if (template.id !== job.templateId) throw new Error("Publication job belongs to a different template");
138
+ }
139
+ let observed;
140
+ while (true) {
141
+ signal.throwIfAborted();
142
+ if (job.status !== observed) {
143
+ observed = job.status;
144
+ options.onProgress?.({ ...job });
145
+ }
146
+ if (job.status === "blocked" || job.status === "failed") {
147
+ artifact = z.object({ artifact: artifactSchema }).parse(await read(`/v1/public-templates/artifacts/${encodeURIComponent(job.artifactId)}`)).artifact;
148
+ throw new PublicTemplatePublishError(artifact.errorMessage ?? `Template publication ${job.id} ${job.status}`, job.status === "blocked" ? "TEMPLATE_PUBLICATION_BLOCKED" : "TEMPLATE_PUBLICATION_FAILED", job, artifact);
149
+ }
150
+ if (job.status === "ready") break;
151
+ await pause(1e3, signal);
152
+ job = await readJob(job.id);
153
+ }
154
+ if (!job.templateId || !job.versionId) throw new Error("Ready publication has no template or version");
155
+ const { template } = await read(`/v1/public-templates/${encodeURIComponent(job.templateId)}`);
156
+ if (!template || template.id !== job.templateId) throw new Error("Ready publication returned a different template");
157
+ let version = template.latestVersion;
158
+ if (version?.id !== job.versionId) version = (await read(`/v1/public-templates/${encodeURIComponent(job.templateId)}/versions`)).versions?.find((entry) => entry.id === job?.versionId) ?? null;
159
+ if (!version || version.templateId !== job.templateId || !version.publicArtifactId || version.publicArtifactId !== job.artifactId) throw new Error("Published version does not match the completed artifact");
160
+ return {
161
+ template,
162
+ version
163
+ };
164
+ } catch (cause) {
165
+ if (cause instanceof PublicTemplatePublishError) throw cause;
166
+ const interrupted = signal.aborted;
167
+ const message = timeout.aborted ? `Timed out waiting for template publication after ${timeoutMs} ms` : cause instanceof Error ? cause.message : "Template publication could not be confirmed";
168
+ throw new PublicTemplatePublishError(job ? `${message}. Publication ${job.id} is ${job.status}; resume it with resumeJobId instead of publishing again.` : message, interrupted ? "TEMPLATE_PUBLICATION_WAIT_INTERRUPTED" : "TEMPLATE_PUBLICATION_UNCONFIRMED", job, artifact, cause);
169
+ }
170
+ }
171
+ };
172
+ //#endregion
173
+ export { PublicTemplatePublishError, PublicTemplatesClient };