@burdenoff/fe-libs 2026.1023.1 → 2026.1023.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.
@@ -1,48 +1,49 @@
1
1
  import { sandboxProxyErrorFromBody as e, sandboxProxyErrorFromTurnTerminal as t } from "./sandboxProxyError.js";
2
2
  import { extensionObjectsIn as n } from "./quota.js";
3
- import { buildSandboxContextInput as r, executeAssistantGraphQLOnce as i, executeSandboxGraphQL as a } from "./gatewayClient.js";
4
- import { CHECK_AI_CREDITS as o, CREATE_SANDBOX as s, EXTEND_MY_ASSISTANT_SANDBOX_TTL as c, EXTEND_SANDBOX_TTL as l, GET_ACTIVE_SANDBOXES as u, GET_SANDBOX as d, PROVISION_ASSISTANT_SANDBOX as f, PROXY_SANDBOX_REQUEST as p, REPORT_AI_TOKEN_USAGE as ee, STOP_ASSISTANT_SANDBOX as te, STOP_MY_ASSISTANT_SANDBOX as ne, WAIT_FOR_SANDBOX_RUNNING as re } from "./operations.js";
5
- import { ASSISTANT_API_AUTH_STRATEGY as ie, getImageForMode as m, getImageTagForMode as ae, getResourcesForMode as oe, resolveSandboxAssistantMode as h } from "./images.js";
6
- import { STREAM_MINT_BACKOFF_ERROR_MS as g, STREAM_MINT_BACKOFF_UNAVAILABLE_MS as _, backOffStreamMint as v, clearStreamMintBackoff as se, getCapability as y, isMissingGatewayFieldError as b, isUnknownFieldError as ce, markSupported as x, markUnsupported as S, streamMintBackedOff as le } from "./capabilities.js";
7
- import { filterAssistantPageContext as ue } from "./pageContextKeys.js";
3
+ import { abandonAssistantSandboxTurns as r, withAssistantProxyResponse as i } from "./promptDelivery.js";
4
+ import { buildSandboxContextInput as a, executeAssistantGraphQLOnce as o, executeSandboxGraphQL as s } from "./gatewayClient.js";
5
+ import { CHECK_AI_CREDITS as c, CREATE_SANDBOX as l, EXTEND_MY_ASSISTANT_SANDBOX_TTL as u, EXTEND_SANDBOX_TTL as d, GET_ACTIVE_SANDBOXES as f, GET_SANDBOX as p, PROVISION_ASSISTANT_SANDBOX as ee, PROXY_SANDBOX_REQUEST as te, REPORT_AI_TOKEN_USAGE as ne, STOP_ASSISTANT_SANDBOX as re, STOP_MY_ASSISTANT_SANDBOX as ie, WAIT_FOR_SANDBOX_RUNNING as ae } from "./operations.js";
6
+ import { ASSISTANT_API_AUTH_STRATEGY as oe, getImageForMode as m, getImageTagForMode as se, getResourcesForMode as ce, resolveSandboxAssistantMode as h } from "./images.js";
7
+ import { STREAM_MINT_BACKOFF_ERROR_MS as g, STREAM_MINT_BACKOFF_UNAVAILABLE_MS as _, backOffStreamMint as v, clearStreamMintBackoff as le, getCapability as y, isMissingGatewayFieldError as b, isUnknownFieldError as ue, markSupported as x, markUnsupported as S, streamMintBackedOff as de } from "./capabilities.js";
8
+ import { filterAssistantPageContext as fe } from "./pageContextKeys.js";
8
9
  import { useAssistantStore as C } from "./store.js";
9
- import { REQUEST_TOO_LARGE_REFUSAL as de } from "./gatewayLimits.js";
10
+ import { REQUEST_TOO_LARGE_REFUSAL as pe } from "./gatewayLimits.js";
10
11
  //#region src/shared/assistant/api.ts
11
- function fe(e) {
12
+ function w(e) {
12
13
  return e === "assistant" || e === "api-calls";
13
14
  }
14
- function w(e, t, n, i, a, o, s) {
15
+ function T(e, t, n, r, i, o, s) {
15
16
  return {
16
- query: p,
17
+ query: te,
17
18
  operationName: "ProxySandboxRequest",
18
19
  variables: { input: {
19
20
  sandboxId: e,
20
21
  path: n,
21
- method: i,
22
- body: a,
23
- context: r(t, s),
24
- ...fe(o) ? {
22
+ method: r,
23
+ body: i,
24
+ context: a(t, s),
25
+ ...w(o) ? {
25
26
  forwardedAuthToken: s?.accessToken ?? void 0,
26
27
  forwardedWorkspaceToken: s?.workspaceToken ?? void 0
27
28
  } : {}
28
29
  } }
29
30
  };
30
31
  }
31
- async function T(t, n, r, i, o, s, c) {
32
- let l = (await a({
33
- ...w(t, n, r, i, o, s, c),
32
+ async function E(t, n, r, a, c, l, u, d) {
33
+ let f = (await (d === "transport" ? s : o)({
34
+ ...T(t, n, r, a, c, l, u),
34
35
  workspaceId: n,
35
- authContext: c
36
+ authContext: u
36
37
  })).proxySandboxRequest;
37
- if (!l || l.status >= 400) {
38
- let t = l?.body, n = t?.error ?? `Proxy error: ${l?.status ?? "unknown"}`;
39
- throw e(n, l?.status ?? null, t) ?? Error(n);
38
+ if (!f || f.status >= 400) {
39
+ let t = f?.body, n = t?.error ?? `Proxy error: ${f?.status ?? "unknown"}`;
40
+ throw i(e(n, f?.status ?? null, t) ?? Error(n), f?.status, t);
40
41
  }
41
- return l.body;
42
+ return f.body;
42
43
  }
43
- async function E(e, t, n, r, a, o, s) {
44
- let c = (await i({
45
- ...w(e, t, n, r, a, o, s),
44
+ async function D(e, t, n, r, i, a, s) {
45
+ let c = (await o({
46
+ ...T(e, t, n, r, i, a, s),
46
47
  workspaceId: t,
47
48
  authContext: s
48
49
  })).proxySandboxRequest;
@@ -52,44 +53,44 @@ async function E(e, t, n, r, a, o, s) {
52
53
  body: "body" in c ? c.body ?? null : null
53
54
  };
54
55
  }
55
- async function pe(e, t, n, r, i, a = /* @__PURE__ */ new Set(), o = "legacy") {
56
- return (await D(e, t, n, r, i, a, o))?.id ?? null;
56
+ async function me(e, t, n, r, i, a = /* @__PURE__ */ new Set(), o = "legacy") {
57
+ return (await O(e, t, n, r, i, a, o))?.id ?? null;
57
58
  }
58
- async function D(e, t, n, i, o, s = /* @__PURE__ */ new Set(), c = "legacy") {
59
- let l = (await a({
60
- query: u,
59
+ async function O(e, t, n, r, i, o = /* @__PURE__ */ new Set(), c = "legacy") {
60
+ let l = (await s({
61
+ query: f,
61
62
  operationName: "GetActiveSandboxes",
62
- variables: { context: r(e, o) },
63
+ variables: { context: a(e, i) },
63
64
  workspaceId: e,
64
- authContext: o
65
+ authContext: i
65
66
  })).getActiveSandboxes ?? [];
66
- L(l);
67
- let d = k(l, t, n, i, o, s, B(c));
68
- return d ? {
69
- id: d,
70
- status: O(l, d)
67
+ R(l);
68
+ let u = A(l, t, n, r, i, o, V(c));
69
+ return u ? {
70
+ id: u,
71
+ status: k(l, u)
71
72
  } : null;
72
73
  }
73
- function O(e, t) {
74
+ function k(e, t) {
74
75
  return e.find((e) => e.id === t)?.status ?? "UNKNOWN";
75
76
  }
76
- function k(e, t, n, r, i, a = /* @__PURE__ */ new Set(), o = "legacy") {
77
- return e.find((e) => !a.has(e.id) && (e.status === "RUNNING" || e.status === "PROVISIONING" || e.status === "PENDING") && e.template === "AI_BUILDER" && h(e, [n]) === n && (!i.userId || e.createdBy === i.userId) && e.metadata?.authStrategy === "sandbox-app-client-headers-v1" && e.metadata?.assistantProduct === t && (!N(n) || M(e.metadata, o)) && A(e, n, o))?.id ?? null;
77
+ function A(e, t, n, r, i, a = /* @__PURE__ */ new Set(), o = "legacy") {
78
+ return e.find((e) => !a.has(e.id) && (e.status === "RUNNING" || e.status === "PROVISIONING" || e.status === "PENDING") && e.template === "AI_BUILDER" && h(e, [n]) === n && (!i.userId || e.createdBy === i.userId) && e.metadata?.authStrategy === "sandbox-app-client-headers-v1" && e.metadata?.assistantProduct === t && (!P(n) || N(e.metadata, o)) && j(e, n, o))?.id ?? null;
78
79
  }
79
- function A(e, t, n) {
80
- return t !== "assistant" || n !== "proposal-v1" ? !0 : I(e);
80
+ function j(e, t, n) {
81
+ return t !== "assistant" || n !== "proposal-v1" ? !0 : L(e);
81
82
  }
82
- function j(e) {
83
+ function M(e) {
83
84
  return typeof e == "object" && !!e && !Array.isArray(e);
84
85
  }
85
- function M(e, t) {
86
+ function N(e, t) {
86
87
  let n = e?.assistantAuth;
87
- return j(n) && n.accessProfile === "member" ? !0 : (e?.writeApproval ?? "legacy") === t ? e?.confirmWrites === (t === "proposal-v1" ? "proposal-v1" : !0) : !1;
88
+ return M(n) && n.accessProfile === "member" ? !0 : (e?.writeApproval ?? "legacy") === t ? e?.confirmWrites === (t === "proposal-v1" ? "proposal-v1" : !0) : !1;
88
89
  }
89
- function N(e) {
90
+ function P(e) {
90
91
  return e === "api-calls";
91
92
  }
92
- function P(e, t, n, r) {
93
+ function F(e, t, n, r) {
93
94
  let i = [
94
95
  {
95
96
  name: "AI_ASSISTANT_MODE",
@@ -117,47 +118,47 @@ function P(e, t, n, r) {
117
118
  }), r.workspaceToken && i.push({
118
119
  name: "WORKSPACE_AUTH_TOKEN",
119
120
  value: r.workspaceToken
120
- })), N(t) && i.push({
121
+ })), P(t) && i.push({
121
122
  name: "AI_ASSISTANT_CONFIRM_WRITES",
122
123
  value: "1"
123
124
  }), i;
124
125
  }
125
- var me = "assistant.errors.assistantProvisioningUnavailable", he = "provisionAssistantSandbox", ge = [
126
+ var he = "assistant.errors.assistantProvisioningUnavailable", ge = "provisionAssistantSandbox", _e = [
126
127
  "ProvisionAssistantSandboxInput",
127
128
  "SandboxAssistantMode",
128
129
  "SandboxAssistantWriteApproval"
129
- ], F = /* @__PURE__ */ new Set();
130
- function I(e) {
131
- let t = e.metadata?.assistantAuth;
132
- return j(t) && t.provisionedVia === he;
133
- }
130
+ ], I = /* @__PURE__ */ new Set();
134
131
  function L(e) {
135
- for (let t of e) I(t) && F.add(t.id);
132
+ let t = e.metadata?.assistantAuth;
133
+ return M(t) && t.provisionedVia === ge;
136
134
  }
137
135
  function R(e) {
138
- return F.has(e);
136
+ for (let t of e) L(t) && I.add(t.id);
139
137
  }
140
- function z(e, t) {
141
- return q(t) === "proposal-v1" && (e === "assistant" || e === "api-calls") && y("provisionAssistantSandbox") !== "unsupported";
138
+ function z(e) {
139
+ return I.has(e);
142
140
  }
143
- function B(e) {
144
- return q(e) === "proposal-v1" && y("provisionAssistantSandbox") !== "unsupported" ? "proposal-v1" : "legacy";
141
+ function B(e, t) {
142
+ return J(t) === "proposal-v1" && (e === "assistant" || e === "api-calls") && y("provisionAssistantSandbox") !== "unsupported";
145
143
  }
146
144
  function V(e) {
147
- return n(e).some((e) => e.i18nKey === me || e.code === "SERVICE_UNAVAILABLE");
145
+ return J(e) === "proposal-v1" && y("provisionAssistantSandbox") !== "unsupported" ? "proposal-v1" : "legacy";
146
+ }
147
+ function H(e) {
148
+ return n(e).some((e) => e.i18nKey === he || e.code === "SERVICE_UNAVAILABLE");
148
149
  }
149
- function H(e, t) {
150
+ function U(e, t) {
150
151
  if (t <= 600) return !1;
151
152
  let n = e instanceof Error ? e.message.toLowerCase() : String(e);
152
153
  return n.includes("ttl") || n.includes("validation") || n.includes("maximum");
153
154
  }
154
- function U(e, t, n, i, a, o) {
155
+ function W(e, t, n, r, i, o) {
155
156
  if (t !== "assistant" && t !== "api-calls") throw Error(`Mode ${t} is not provisioned through the assistant path`);
156
157
  return {
157
158
  mode: t === "assistant" ? "ASSISTANT" : "API_CALLS",
158
159
  product: e,
159
- image: m(t, i),
160
- ttlSeconds: a,
160
+ image: m(t, r),
161
+ ttlSeconds: i,
161
162
  ...t === "api-calls" ? { writeApproval: "PROPOSAL_V1" } : {},
162
163
  env: [
163
164
  {
@@ -173,137 +174,137 @@ function U(e, t, n, i, a, o) {
173
174
  value: n
174
175
  }
175
176
  ],
176
- context: r(n, o)
177
+ context: a(n, o)
177
178
  };
178
179
  }
179
- async function W(e, t, n, r, i, o) {
180
- let s = (await a({
181
- query: f,
180
+ async function G(e, t, n, r, i, a) {
181
+ let o = (await s({
182
+ query: ee,
182
183
  operationName: "ProvisionAssistantSandbox",
183
- variables: { input: U(e, t, n, r, i, o) },
184
+ variables: { input: W(e, t, n, r, i, a) },
184
185
  workspaceId: n,
185
- authContext: o
186
+ authContext: a
186
187
  }))?.provisionAssistantSandbox?.id;
187
- if (!s) throw Error("provisionAssistantSandbox returned empty response");
188
- return s;
188
+ if (!o) throw Error("provisionAssistantSandbox returned empty response");
189
+ return o;
189
190
  }
190
- async function _e(e, t, n, r, i, a) {
191
+ async function ve(e, t, n, r, i, a) {
191
192
  try {
192
- return await W(e, t, n, r, i, a);
193
+ return await G(e, t, n, r, i, a);
193
194
  } catch (o) {
194
- if (V(o) || G(o) || !H(o, i)) throw o;
195
- return W(e, t, n, r, 600, a);
195
+ if (H(o) || K(o) || !U(o, i)) throw o;
196
+ return G(e, t, n, r, 600, a);
196
197
  }
197
198
  }
198
- function G(e) {
199
- return b(e, "provisionAssistantSandbox", ge);
199
+ function K(e) {
200
+ return b(e, "provisionAssistantSandbox", _e);
200
201
  }
201
- async function ve(e, t, n, r, i, a, o = {}) {
202
- if (z(t, o.writeApproval)) try {
203
- let o = await _e(e, t, n, r, i, a);
204
- return x("provisionAssistantSandbox"), F.add(o), o;
202
+ async function ye(e, t, n, r, i, a, o = {}) {
203
+ if (B(t, o.writeApproval)) try {
204
+ let o = await ve(e, t, n, r, i, a);
205
+ return x("provisionAssistantSandbox"), I.add(o), o;
205
206
  } catch (e) {
206
- if (!G(e)) throw e;
207
+ if (!K(e)) throw e;
207
208
  S("provisionAssistantSandbox");
208
209
  }
209
- return ye(e, t, n, r, i, a);
210
+ return be(e, t, n, r, i, a);
210
211
  }
211
- async function ye(e, t, n, i, o, c) {
212
- let l = oe(t), u = P(e, t, n, c), d = (a) => ({
212
+ async function be(e, t, n, r, i, o) {
213
+ let c = ce(t), u = F(e, t, n, o), d = (i) => ({
213
214
  name: `ai-assistant-${t}-${Date.now()}`,
214
215
  description: `AI Assistant sandbox (${t} mode)`,
215
216
  template: "AI_BUILDER",
216
217
  mode: "DEPLOYMENT",
217
218
  containers: [{
218
219
  name: "ai-assistant",
219
- image: m(t, i),
220
+ image: m(t, r),
220
221
  ports: [{
221
222
  containerPort: 8080,
222
223
  name: "http"
223
224
  }],
224
225
  env: u
225
226
  }],
226
- resources: l,
227
- ttlSeconds: a,
227
+ resources: c,
228
+ ttlSeconds: i,
228
229
  metadata: {
229
230
  assistantMode: t,
230
231
  assistantProduct: e,
231
- assistantOwnerUserId: c.userId ?? null,
232
- assistantOrganizationId: c.organizationId ?? null,
233
- authStrategy: ie,
234
- imageTag: ae(t, i),
235
- confirmWrites: N(t)
232
+ assistantOwnerUserId: o.userId ?? null,
233
+ assistantOrganizationId: o.organizationId ?? null,
234
+ authStrategy: oe,
235
+ imageTag: se(t, r),
236
+ confirmWrites: P(t)
236
237
  },
237
- context: r(n, c)
238
- }), f = (e) => a({
239
- query: s,
238
+ context: a(n, o)
239
+ }), f = (e) => s({
240
+ query: l,
240
241
  operationName: "CreateSandbox",
241
242
  variables: { input: d(e) },
242
243
  workspaceId: n,
243
- authContext: c
244
+ authContext: o
244
245
  }), p;
245
246
  try {
246
- p = await f(o);
247
+ p = await f(i);
247
248
  } catch (e) {
248
- if (H(e, o)) p = await f(600);
249
+ if (U(e, i)) p = await f(600);
249
250
  else throw e;
250
251
  }
251
252
  if (!p?.createSandbox?.id) throw Error("createSandbox returned empty response");
252
253
  return p.createSandbox.id;
253
254
  }
254
- async function be(e, t, n) {
255
- return (await a({
256
- query: d,
255
+ async function xe(e, t, n) {
256
+ return (await s({
257
+ query: p,
257
258
  operationName: "GetSandbox",
258
259
  variables: {
259
260
  id: e,
260
- context: r(t, n)
261
+ context: a(t, n)
261
262
  },
262
263
  workspaceId: t,
263
264
  authContext: n
264
265
  })).getSandbox;
265
266
  }
266
- function K(e, t) {
267
+ function q(e, t) {
267
268
  if (e === "FAILED" || e === "STOPPED" || e === "EXPIRED") throw Error(t ? `Sandbox ${e.toLowerCase()}: ${t}` : `Sandbox ${e.toLowerCase()}`);
268
269
  }
269
- async function xe(e, t, n, i = 3e5) {
270
- let o = Date.now();
271
- if (y("waitForSandboxRunning") !== "unsupported") for (; Date.now() - o < i;) try {
272
- let i = await a({
273
- query: re,
270
+ async function Se(e, t, n, r = 3e5) {
271
+ let i = Date.now();
272
+ if (y("waitForSandboxRunning") !== "unsupported") for (; Date.now() - i < r;) try {
273
+ let r = await s({
274
+ query: ae,
274
275
  operationName: "WaitForSandboxRunning",
275
276
  variables: {
276
277
  id: e,
277
278
  timeoutSeconds: 25,
278
- context: r(t, n)
279
+ context: a(t, n)
279
280
  },
280
281
  workspaceId: t,
281
282
  authContext: n
282
283
  });
283
284
  x("waitForSandboxRunning");
284
- let o = i.waitForSandboxRunning;
285
- if (o?.status === "RUNNING") return;
286
- K(o?.status, o?.errorMessage);
285
+ let i = r.waitForSandboxRunning;
286
+ if (i?.status === "RUNNING") return;
287
+ q(i?.status, i?.errorMessage);
287
288
  } catch (e) {
288
- if (ce(e)) {
289
+ if (ue(e)) {
289
290
  S("waitForSandboxRunning");
290
291
  break;
291
292
  }
292
293
  throw e;
293
294
  }
294
- for (; Date.now() - o < i;) {
295
- let r = await be(e, t, n);
295
+ for (; Date.now() - i < r;) {
296
+ let r = await xe(e, t, n);
296
297
  if (r?.status === "RUNNING") return;
297
- K(r?.status, r?.errorMessage), await new Promise((e) => setTimeout(e, 2e3));
298
+ q(r?.status, r?.errorMessage), await new Promise((e) => setTimeout(e, 2e3));
298
299
  }
299
300
  throw Error("Sandbox startup timed out");
300
301
  }
301
- async function Se(e, t, n, r, i = 9e4, a) {
302
+ async function Ce(e, t, n, r, i = 9e4, a) {
302
303
  let o = Date.now();
303
304
  for (; Date.now() - o < i;) {
304
305
  try {
305
- let i = await T(e, t, "/health", "GET", void 0, n, r);
306
- return C.getState().setSandboxWriteCapabilities(e, Y(i)), i;
306
+ let i = await E(e, t, "/health", "GET", void 0, n, r, "transport");
307
+ return C.getState().setSandboxWriteCapabilities(e, X(i)), i;
307
308
  } catch (e) {
308
309
  let t = e instanceof Error ? e.message : String(e);
309
310
  if (!/proxy error: 502|proxy error: 503|proxy error: 404|service not available|starting/i.test(t)) throw e;
@@ -313,69 +314,69 @@ async function Se(e, t, n, r, i = 9e4, a) {
313
314
  }
314
315
  throw Error("Assistant service did not become healthy before timeout");
315
316
  }
316
- function q(e) {
317
+ function J(e) {
317
318
  return e === "proposal-v1" ? "proposal-v1" : "legacy";
318
319
  }
319
- function J(e, t) {
320
+ function Y(e, t) {
320
321
  return e === "enabled" || e === void 0 && !t ? "enabled" : "fenced";
321
322
  }
322
- var Ce = new Set([
323
+ var we = new Set([
323
324
  "relay",
324
325
  "delegated",
325
326
  "direct",
326
327
  "unconfigured"
327
328
  ]);
328
- function Y(e) {
329
+ function X(e) {
329
330
  let t = typeof e == "object" && e && !Array.isArray(e) ? e.capabilities : void 0, n = typeof t == "object" && t && !Array.isArray(t) ? t : {}, r = n.writeProposals !== void 0 || n.writeApprovalMode !== void 0 || n.writeExecution !== void 0, i = n.writeRiskVersion, a = n.sessionCredentials;
330
331
  return {
331
332
  proposals: n.writeProposals === "v1",
332
- writeApprovalMode: q(n.writeApprovalMode),
333
- writeExecution: J(n.writeExecution, r),
333
+ writeApprovalMode: J(n.writeApprovalMode),
334
+ writeExecution: Y(n.writeExecution, r),
334
335
  replyApproval: "off",
335
336
  ...typeof i == "string" && i ? { writeRiskVersion: i } : {},
336
- ...typeof a == "string" && Ce.has(a) ? { sessionCredentials: a } : {},
337
+ ...typeof a == "string" && we.has(a) ? { sessionCredentials: a } : {},
337
338
  ...n.uiOffers === 1 ? { uiOffers: !0 } : {}
338
339
  };
339
340
  }
340
- async function we(e, t, n, r) {
341
+ async function Te(e, t, n, r) {
341
342
  let i;
342
343
  try {
343
- i = await E(e, t, "/health", "GET", void 0, n, r);
344
+ i = await D(e, t, "/health", "GET", void 0, n, r);
344
345
  } catch {
345
346
  return null;
346
347
  }
347
348
  let a = i.body;
348
349
  if (i.status < 200 || i.status >= 300 || typeof a != "object" || !a || Array.isArray(a)) return null;
349
- let o = Y(a);
350
+ let o = X(a);
350
351
  return C.getState().setSandboxWriteCapabilities(e, o), o;
351
352
  }
352
- async function Te(e, t, n, r) {
353
- return { sessionId: (await T(e, t, "/sessions", "POST", { mode: n }, n, r)).session.id };
353
+ async function Ee(e, t, n, r) {
354
+ return { sessionId: (await E(e, t, "/sessions", "POST", { mode: n }, n, r, "never")).session.id };
354
355
  }
355
- async function Ee(e, t, n, r, i) {
356
- let a = await T(e, t, `/write-confirmations/${encodeURIComponent(n)}/approve`, "POST", {}, r, i);
356
+ async function De(e, t, n, r, i) {
357
+ let a = await E(e, t, `/write-confirmations/${encodeURIComponent(n)}/approve`, "POST", {}, r, i, "never");
357
358
  if (a?.approved !== !0) throw Error(typeof a?.error == "string" ? a.error : "The change could not be approved. It may have expired — ask the assistant to try again.");
358
359
  }
359
- function X(e, t, n, r, i, a = /* @__PURE__ */ new Set(), o = "legacy") {
360
- return i.userId ? e.filter((e) => e.metadata?.authStrategy === "sandbox-app-client-headers-v1" && e.createdBy === i.userId && !(!a.has(e.id) && e.metadata?.assistantProduct === t && h(e, [n]) === n && (!N(n) || M(e.metadata, o)) && A(e, n, o))).map((e) => e.id) : [];
360
+ function Z(e, t, n, r, i, a = /* @__PURE__ */ new Set(), o = "legacy") {
361
+ return i.userId ? e.filter((e) => e.metadata?.authStrategy === "sandbox-app-client-headers-v1" && e.createdBy === i.userId && !(!a.has(e.id) && e.metadata?.assistantProduct === t && h(e, [n]) === n && (!P(n) || N(e.metadata, o)) && j(e, n, o))).map((e) => e.id) : [];
361
362
  }
362
- async function De(e, t, n, i, o, s = /* @__PURE__ */ new Set(), c = "legacy") {
363
- let l, d = /* @__PURE__ */ new Set();
363
+ async function Oe(e, t, n, r, i, o = /* @__PURE__ */ new Set(), c = "legacy") {
364
+ let l, u = /* @__PURE__ */ new Set();
364
365
  try {
365
- let f = (await a({
366
- query: u,
366
+ let d = (await s({
367
+ query: f,
367
368
  operationName: "GetActiveSandboxes",
368
- variables: { context: r(e, o) },
369
+ variables: { context: a(e, i) },
369
370
  workspaceId: e,
370
- authContext: o
371
+ authContext: i
371
372
  })).getActiveSandboxes ?? [];
372
- L(f);
373
- let p = B(c);
374
- if (l = X(f, t, n, i, o, s, p), p === "proposal-v1") {
373
+ R(d);
374
+ let p = V(c);
375
+ if (l = Z(d, t, n, r, i, o, p), p === "proposal-v1") {
375
376
  let e = new Set(l);
376
- for (let t of f) {
377
+ for (let t of d) {
377
378
  let n = h(t);
378
- e.has(t.id) && (n === "assistant" || n === "api-calls") && d.add(t.id);
379
+ e.has(t.id) && (n === "assistant" || n === "api-calls") && u.add(t.id);
379
380
  }
380
381
  }
381
382
  } catch {
@@ -383,20 +384,20 @@ async function De(e, t, n, i, o, s = /* @__PURE__ */ new Set(), c = "legacy") {
383
384
  }
384
385
  return (await Promise.all(l.map(async (t) => {
385
386
  try {
386
- return await Z(t, e, o, { ownerScoped: d.has(t) }), t;
387
+ return await ke(t, e, i, { ownerScoped: u.has(t) }), t;
387
388
  } catch {
388
389
  return null;
389
390
  }
390
391
  }))).filter((e) => e !== null);
391
392
  }
392
- async function Z(e, t, n, i = {}) {
393
- if ((i.ownerScoped === !0 || R(e)) && y("stopMyAssistantSandbox") !== "unsupported") try {
394
- await a({
395
- query: ne,
393
+ async function ke(e, t, n, i = {}) {
394
+ if (r(e), (i.ownerScoped === !0 || z(e)) && y("stopMyAssistantSandbox") !== "unsupported") try {
395
+ await s({
396
+ query: ie,
396
397
  operationName: "StopMyAssistantSandbox",
397
398
  variables: {
398
399
  id: e,
399
- context: r(t, n)
400
+ context: a(t, n)
400
401
  },
401
402
  workspaceId: t,
402
403
  authContext: n
@@ -406,57 +407,57 @@ async function Z(e, t, n, i = {}) {
406
407
  if (!b(e, "stopMyAssistantSandbox")) throw e;
407
408
  S("stopMyAssistantSandbox");
408
409
  }
409
- await a({
410
- query: te,
410
+ await s({
411
+ query: re,
411
412
  operationName: "StopAssistantSandbox",
412
413
  variables: {
413
414
  id: e,
414
- context: r(t, n)
415
+ context: a(t, n)
415
416
  },
416
417
  workspaceId: t,
417
418
  authContext: n
418
419
  });
419
420
  }
420
- var Q = /^[A-Za-z0-9_-]{1,128}$/, Oe = new Set([
421
+ var Ae = /^[A-Za-z0-9_-]{1,128}$/, je = new Set([
421
422
  "affirm",
422
423
  "decline",
423
424
  "other"
424
- ]), ke = new Set([
425
+ ]), Me = new Set([
425
426
  "typed",
426
427
  "spoken",
427
428
  "chip",
428
429
  "host_queued",
429
430
  "retry",
430
431
  "proposal_result"
431
- ]), Ae = /^wp_[0-9a-f]{32}$/;
432
- function je(e) {
433
- return !e || !Oe.has(e.kind) || !ke.has(e.origin) ? null : e.proposalId === void 0 ? {
432
+ ]), Ne = /^wp_[0-9a-f]{32}$/;
433
+ function Pe(e) {
434
+ return !e || !je.has(e.kind) || !Me.has(e.origin) ? null : e.proposalId === void 0 ? {
434
435
  kind: e.kind,
435
436
  origin: e.origin
436
- } : Ae.test(e.proposalId) ? {
437
+ } : Ne.test(e.proposalId) ? {
437
438
  kind: e.kind,
438
439
  origin: e.origin,
439
440
  proposalId: e.proposalId
440
441
  } : null;
441
442
  }
442
- function $(e) {
443
+ function Q(e) {
443
444
  let { mode: t, prompt: n, parts: r } = e, i = {
444
445
  mode: t,
445
446
  prompt: n,
446
- pageContext: ue(e.pageContext)
447
+ pageContext: fe(e.pageContext)
447
448
  };
448
- r && r.length > 0 && (i.parts = r), typeof e.conversationId == "string" && Q.test(e.conversationId) && (i.conversationId = e.conversationId);
449
- let a = je(e.writeReply);
449
+ r && r.length > 0 && (i.parts = r), typeof e.conversationId == "string" && Ae.test(e.conversationId) && (i.conversationId = e.conversationId);
450
+ let a = Pe(e.writeReply);
450
451
  return a && (i.writeReply = a), e.uiCatalogue && (i.uiCatalogue = e.uiCatalogue), i;
451
452
  }
452
- function Me(e) {
453
- return w(e.sandboxId, e.workspaceId, `/sessions/${e.sessionId}/prompt-async`, "POST", $(e), e.mode, e.authContext);
453
+ function Fe(e) {
454
+ return T(e.sandboxId, e.workspaceId, `/sessions/${e.sessionId}/prompt-async`, "POST", Q(e), e.mode, e.authContext);
454
455
  }
455
- function Ne(e) {
456
- return new TextEncoder().encode(JSON.stringify(Me(e))).byteLength;
456
+ function $(e) {
457
+ return new TextEncoder().encode(JSON.stringify(Fe(e))).byteLength;
457
458
  }
458
- async function Pe(e, t, n, r, i, a, o, s) {
459
- if (Ne({
459
+ async function Ie(e, t, n, r, i, a, o, s) {
460
+ if ($({
460
461
  sandboxId: e,
461
462
  workspaceId: t,
462
463
  sessionId: n,
@@ -468,8 +469,8 @@ async function Pe(e, t, n, r, i, a, o, s) {
468
469
  conversationId: s?.conversationId,
469
470
  writeReply: s?.writeReply,
470
471
  uiCatalogue: s?.uiCatalogue
471
- }) > 262144) throw Error(de);
472
- let c = await T(e, t, `/sessions/${n}/prompt-async`, "POST", $({
472
+ }) > 262144) throw Object.assign(Error(pe), { assistantPromptNotDispatched: !0 });
473
+ let c = await E(e, t, `/sessions/${n}/prompt-async`, "POST", Q({
473
474
  mode: i,
474
475
  prompt: r,
475
476
  pageContext: a,
@@ -477,13 +478,13 @@ async function Pe(e, t, n, r, i, a, o, s) {
477
478
  conversationId: s?.conversationId,
478
479
  writeReply: s?.writeReply,
479
480
  uiCatalogue: s?.uiCatalogue
480
- }), i, o);
481
+ }), i, o, "never");
481
482
  return { messageID: typeof c.messageID == "string" ? c.messageID : void 0 };
482
483
  }
483
- async function Fe(e, n, r, i, a, o) {
484
+ async function Le(e, n, r, i, a, o) {
484
485
  let s = `/sessions/${r}/messages?limit=${o?.limit ?? 50}`;
485
486
  o?.sinceMs && y("sinceParam") !== "unsupported" && (s += `&since=${o.sinceMs}`);
486
- let c = await T(e, n, s, "GET", void 0, i, a);
487
+ let c = await E(e, n, s, "GET", void 0, i, a, "transport");
487
488
  if (typeof c.now == "number" && x("sinceParam"), o?.surfaceUiOffers) try {
488
489
  o.surfaceUiOffers(c.uiOffers, typeof c.now == "number" ? c.now : NaN);
489
490
  } catch {}
@@ -493,10 +494,10 @@ async function Fe(e, n, r, i, a, o) {
493
494
  }
494
495
  return c.messages ?? [];
495
496
  }
496
- async function Ie(e, t, n, r, i) {
497
+ async function Re(e, t, n, r, i) {
497
498
  if (y("sse") === "unsupported") return null;
498
499
  try {
499
- let a = await T(e, t, `/sessions/${n}/stream-url`, "GET", void 0, r, i);
500
+ let a = await E(e, t, `/sessions/${n}/stream-url`, "GET", void 0, r, i, "transport");
500
501
  return typeof a.url == "string" && typeof a.expiresAt == "number" ? (x("sse"), {
501
502
  url: a.url,
502
503
  expiresAt: a.expiresAt
@@ -505,13 +506,13 @@ async function Ie(e, t, n, r, i) {
505
506
  return S("sse"), null;
506
507
  }
507
508
  }
508
- async function Le(e, t, n, r, i, a = Date.now) {
509
- if (le(a())) return null;
509
+ async function ze(e, t, n, r, i, a = Date.now) {
510
+ if (de(a())) return null;
510
511
  try {
511
- let { status: o, body: s } = await E(e, t, `/sessions/${n}/stream-url`, "GET", void 0, r, i);
512
+ let { status: o, body: s } = await D(e, t, `/sessions/${n}/stream-url`, "GET", void 0, r, i);
512
513
  if (o === 404) return v(_, a()), null;
513
514
  let c = o >= 200 && o < 300 && typeof s == "object" && s ? s : null;
514
- return c && c.transport === "relay" && typeof c.url == "string" && typeof c.expiresAt == "number" && Re(c.url) ? (se(), {
515
+ return c && c.transport === "relay" && typeof c.url == "string" && typeof c.expiresAt == "number" && Be(c.url) ? (le(), {
515
516
  url: c.url,
516
517
  expiresAt: c.expiresAt
517
518
  }) : (v(c ? _ : g, a()), null);
@@ -519,7 +520,7 @@ async function Le(e, t, n, r, i, a = Date.now) {
519
520
  return v(g, a()), null;
520
521
  }
521
522
  }
522
- function Re(e) {
523
+ function Be(e) {
523
524
  try {
524
525
  let { protocol: t } = new URL(e);
525
526
  return t === "https:" || t === "http:";
@@ -527,58 +528,58 @@ function Re(e) {
527
528
  return !1;
528
529
  }
529
530
  }
530
- async function ze(e, t, n, i) {
531
- if (R(e) && y("extendMyAssistantSandboxTTL") !== "unsupported") try {
532
- await a({
533
- query: c,
531
+ async function Ve(e, t, n, r) {
532
+ if (z(e) && y("extendMyAssistantSandboxTTL") !== "unsupported") try {
533
+ await s({
534
+ query: u,
534
535
  operationName: "ExtendMyAssistantSandboxTtl",
535
536
  variables: {
536
537
  id: e,
537
538
  additionalSeconds: n,
538
- context: r(t, i)
539
+ context: a(t, r)
539
540
  },
540
541
  workspaceId: t,
541
- authContext: i
542
+ authContext: r
542
543
  }), x("extendMyAssistantSandboxTTL");
543
544
  return;
544
545
  } catch (e) {
545
546
  if (!b(e, "extendMyAssistantSandboxTTL")) throw e;
546
547
  S("extendMyAssistantSandboxTTL");
547
548
  }
548
- await a({
549
- query: l,
549
+ await s({
550
+ query: d,
550
551
  operationName: "ExtendSandboxTtl",
551
552
  variables: {
552
553
  id: e,
553
554
  additionalSeconds: n,
554
- context: r(t, i)
555
+ context: a(t, r)
555
556
  },
556
557
  workspaceId: t,
557
- authContext: i
558
+ authContext: r
558
559
  });
559
560
  }
560
- async function Be(e, t, n, r, i) {
561
- await T(e, t, `/sessions/${n}/heartbeat`, "POST", void 0, r, i).catch(() => void 0);
561
+ async function He(e, t, n, r, i) {
562
+ await E(e, t, `/sessions/${n}/heartbeat`, "POST", void 0, r, i, "transport").catch(() => void 0);
562
563
  }
563
- async function Ve(e, t, n, r, i) {
564
+ async function Ue(e, t, n, r, i) {
564
565
  try {
565
- return (await T(e, t, `/sessions/${n}/abort`, "POST", void 0, r, i))?.aborted === !0;
566
+ return (await E(e, t, `/sessions/${n}/abort`, "POST", void 0, r, i, "never"))?.aborted === !0;
566
567
  } catch {
567
568
  return !1;
568
569
  }
569
570
  }
570
- async function He(e, t, n, r, i) {
571
- return ((await T(e, t, `/sessions/${n}/artifacts`, "GET", void 0, r, i)).artifacts ?? []).filter((e) => !e.name.startsWith("."));
571
+ async function We(e, t, n, r, i) {
572
+ return ((await E(e, t, `/sessions/${n}/artifacts`, "GET", void 0, r, i, "transport")).artifacts ?? []).filter((e) => !e.name.startsWith("."));
572
573
  }
573
- async function Ue(e, t, n, r, i) {
574
- let a = await T(e, t, `/sessions/${n}`, "GET", void 0, r, i);
574
+ async function Ge(e, t, n, r, i) {
575
+ let a = await E(e, t, `/sessions/${n}`, "GET", void 0, r, i, "transport");
575
576
  return {
576
577
  id: a.session?.id ?? n,
577
578
  mode: a.mode ?? "unknown"
578
579
  };
579
580
  }
580
- async function We(e, t, n, r, i, a) {
581
- let o = (await T(e, t, `/sessions/${n}/artifacts/download?path=${encodeURIComponent(r)}`, "GET", void 0, i, a)).artifact;
581
+ async function Ke(e, t, n, r, i, a) {
582
+ let o = (await E(e, t, `/sessions/${n}/artifacts/download?path=${encodeURIComponent(r)}`, "GET", void 0, i, a, "transport")).artifact;
582
583
  if (!o) throw Error("Artifact download returned an empty response");
583
584
  return {
584
585
  filename: o.filename,
@@ -586,30 +587,30 @@ async function We(e, t, n, r, i, a) {
586
587
  contentBase64: o.contentBase64
587
588
  };
588
589
  }
589
- async function Ge(e, t) {
590
- return (await a({
591
- query: o,
590
+ async function qe(e, t) {
591
+ return (await s({
592
+ query: c,
592
593
  operationName: "CheckAiCredits",
593
594
  variables: {},
594
595
  workspaceId: e,
595
596
  authContext: t
596
597
  })).checkAiCredits;
597
598
  }
598
- async function Ke(e, t, n, r, o, s) {
599
- let c = Math.max(0, Math.round(o.input ?? 0)), l = Math.max(0, Math.round(o.output ?? 0)), u = Math.max(0, Math.round(o.cache?.read ?? 0)), d = Math.max(0, Math.round(o.cache?.write ?? 0));
599
+ async function Je(e, t, n, r, i, a) {
600
+ let c = Math.max(0, Math.round(i.input ?? 0)), l = Math.max(0, Math.round(i.output ?? 0)), u = Math.max(0, Math.round(i.cache?.read ?? 0)), d = Math.max(0, Math.round(i.cache?.write ?? 0));
600
601
  if (c + l + u + d === 0 || !r) return;
601
602
  let f = !1;
602
- if (o.cache) try {
603
- f = (await i({
603
+ if (i.cache) try {
604
+ f = (await o({
604
605
  query: "query AiCacheTokensSupported { aiCacheTokensSupported }",
605
606
  operationName: "AiCacheTokensSupported",
606
607
  variables: {},
607
608
  workspaceId: e,
608
- authContext: s
609
+ authContext: a
609
610
  })).aiCacheTokensSupported === !0;
610
611
  } catch {}
611
- await a({
612
- query: ee,
612
+ await s({
613
+ query: ne,
613
614
  operationName: "ReportAiTokenUsage",
614
615
  variables: { input: {
615
616
  sessionId: t,
@@ -623,8 +624,8 @@ async function Ke(e, t, n, r, o, s) {
623
624
  } : {}
624
625
  } },
625
626
  workspaceId: e,
626
- authContext: s
627
+ authContext: a
627
628
  });
628
629
  }
629
630
  //#endregion
630
- export { Q as PROMPT_CONVERSATION_ID_PATTERN, Ve as abortAssistantTurn, Ee as approvePendingWrite, A as askReuseMatchesProvisioning, P as buildAssistantSandboxEnv, Me as buildPromptGatewayRequest, $ as buildPromptRequestBody, U as buildProvisionAssistantSandboxInput, Ge as checkAssistantAiCredits, ve as createAssistantSandbox, Te as createAssistantSession, We as downloadAssistantArtifact, ze as extendAssistantSandboxTTL, pe as findExistingSandbox, D as findExistingSandboxWithStatus, fe as forwardsUserTokensToSandbox, He as getAssistantArtifacts, Fe as getAssistantMessages, Ue as getAssistantSession, Ie as getAssistantStreamAccess, V as isAssistantProvisioningUnavailable, R as isDedicatedAssistantSandbox, I as isDedicatedAssistantSandboxRow, Le as mintAssistantTurnStream, N as modeRequiresConfirmWrites, Ne as promptGatewayRequestBytes, E as proxySandboxRaw, Y as readSandboxWriteCapabilities, we as readSandboxWriteCapabilitiesOnce, De as releaseSupersededAssistantSandboxes, Ke as reportAssistantAiTokenUsage, O as sandboxStatusOf, k as selectExistingAssistantSandbox, X as selectSupersededAssistantSandboxes, Pe as sendAssistantPromptAsync, Be as sendHeartbeat, Z as stopReapedAssistantSandbox, z as usesDedicatedAssistantProvisioning, Se as waitForAssistantServiceReady, xe as waitForSandboxRunning, q as writeApprovalModeOf, M as writeApprovalReuseMatches, J as writeExecutionOf };
631
+ export { Ae as PROMPT_CONVERSATION_ID_PATTERN, Ue as abortAssistantTurn, De as approvePendingWrite, j as askReuseMatchesProvisioning, F as buildAssistantSandboxEnv, Fe as buildPromptGatewayRequest, Q as buildPromptRequestBody, W as buildProvisionAssistantSandboxInput, qe as checkAssistantAiCredits, ye as createAssistantSandbox, Ee as createAssistantSession, Ke as downloadAssistantArtifact, Ve as extendAssistantSandboxTTL, me as findExistingSandbox, O as findExistingSandboxWithStatus, w as forwardsUserTokensToSandbox, We as getAssistantArtifacts, Le as getAssistantMessages, Ge as getAssistantSession, Re as getAssistantStreamAccess, H as isAssistantProvisioningUnavailable, z as isDedicatedAssistantSandbox, L as isDedicatedAssistantSandboxRow, ze as mintAssistantTurnStream, P as modeRequiresConfirmWrites, $ as promptGatewayRequestBytes, D as proxySandboxRaw, X as readSandboxWriteCapabilities, Te as readSandboxWriteCapabilitiesOnce, Oe as releaseSupersededAssistantSandboxes, Je as reportAssistantAiTokenUsage, k as sandboxStatusOf, A as selectExistingAssistantSandbox, Z as selectSupersededAssistantSandboxes, Ie as sendAssistantPromptAsync, He as sendHeartbeat, ke as stopReapedAssistantSandbox, B as usesDedicatedAssistantProvisioning, Ce as waitForAssistantServiceReady, Se as waitForSandboxRunning, J as writeApprovalModeOf, N as writeApprovalReuseMatches, Y as writeExecutionOf };