@burdenoff/fe-libs 2026.1027.14 → 2026.1028.2

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