@burdenoff/microfe-healthybowl 2026.904.20 → 2026.904.22

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.
@@ -17,19 +17,19 @@ import { parseToolActivity as le } from "./AssistantToolActivity.js";
17
17
  import { useVoiceSession as ue } from "../../hooks/useVoiceSession.js";
18
18
  import { useAssistantApiAccess as de } from "../../hooks/useAssistantApiAccess.js";
19
19
  import { useWorkspaceWriteAccess as fe } from "../../hooks/useWorkspaceWriteAccess.js";
20
- import { isVoiceTurn as pe, voiceMarker as me, voiceSessionIdOf as he } from "../../utils/voiceTurnVisibility.js";
21
- import { useConversationTurns as ge } from "../../hooks/useConversationTurns.js";
22
- import { isQuotaExhaustedError as _e } from "../../utils/quotaUtils.js";
23
- import { dispatchAssistantQuotaExhausted as ve, notifyAiCreditsUpdated as ye } from "../../utils/aiCredits.js";
24
- import { buildPromptForMode as be } from "../../utils/assistantPrompt.js";
25
- import { isMultimodalBodyRejection as xe, isRecoverableAssistantError as Se } from "../../utils/assistantTransportErrors.js";
26
- import { isTurnInFlight as Ce } from "../../utils/assistantTurnState.js";
27
- import { ASSISTANT_MODES as we } from "../../types/assistant.js";
28
- import { pollDelayMs as Te } from "../../utils/assistantPollSchedule.js";
29
- import { findPendingWrite as Ee } from "../../utils/pendingWrite.js";
30
- import { toCaptionText as De } from "../../utils/captionText.js";
31
- import { buildContinuedFromVoiceNote as Oe, buildVoiceTranscriptMarkdown as ke, voiceTranscriptFilename as Ae } from "../../utils/voiceTranscript.js";
32
- import { downloadFile as je } from "../../services/assistantExportService.js";
20
+ import { useConversationTurns as pe } from "../../hooks/useConversationTurns.js";
21
+ import { isQuotaExhaustedError as me } from "../../utils/quotaUtils.js";
22
+ import { dispatchAssistantQuotaExhausted as he, notifyAiCreditsUpdated as ge } from "../../utils/aiCredits.js";
23
+ import { buildPromptForMode as _e } from "../../utils/assistantPrompt.js";
24
+ import { isMultimodalBodyRejection as ve, isRecoverableAssistantError as ye } from "../../utils/assistantTransportErrors.js";
25
+ import { isTurnInFlight as be } from "../../utils/assistantTurnState.js";
26
+ import { ASSISTANT_MODES as xe } from "../../types/assistant.js";
27
+ import { pollDelayMs as Se } from "../../utils/assistantPollSchedule.js";
28
+ import { findPendingWrite as Ce } from "../../utils/pendingWrite.js";
29
+ import { toCaptionText as we } from "../../utils/captionText.js";
30
+ import { buildContinuedFromVoiceNote as Te, buildVoiceTranscriptMarkdown as Ee, voiceTranscriptFilename as De } from "../../utils/voiceTranscript.js";
31
+ import { downloadFile as Oe } from "../../services/assistantExportService.js";
32
+ import { isVoiceTurn as ke, voiceMarker as Ae, voiceSessionIdOf as je } from "../../utils/voiceTurnVisibility.js";
33
33
  import { createReadinessTracker as Me } from "../../utils/sandboxReadiness.js";
34
34
  import { useCallback as C, useEffect as w, useMemo as T, useRef as E, useState as Ne } from "react";
35
35
  import { useI18n as Pe } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
@@ -66,7 +66,7 @@ function We(e, t) {
66
66
  content: "Thinking...",
67
67
  done: !1
68
68
  };
69
- let r = n[n.length - 1], i = A(r.parts), a = O(r.parts), o = j(r.parts), ee = Ee(r.parts);
69
+ let r = n[n.length - 1], i = A(r.parts), a = O(r.parts), o = j(r.parts), ee = Ce(r.parts);
70
70
  return {
71
71
  content: [
72
72
  i,
@@ -86,12 +86,12 @@ function Ge(e) {
86
86
  default: return "";
87
87
  }
88
88
  }
89
- var Ke = ({ visible: Ee = !0 }) => {
89
+ var Ke = ({ visible: Ce = !0 }) => {
90
90
  let O = Re(), A = Ie("workspace"), { getAccessToken: j, getWorkspaceToken: Ke, userId: qe } = Le(), { locale: Je } = Pe(), Ye = e((e) => e.assistantLanguage), Xe = e((e) => e.replyLanguage), Ze = T(() => p(Ye, Xe, Je), [
91
91
  Ye,
92
92
  Xe,
93
93
  Je
94
- ]), Qe = Ze.reply.english, $e = Ze.replyIsExplicit, et = Ze.reply.code, { conversations: tt, activeConversationId: M, mode: N, processingByConversationId: nt, setMode: P, setConversationMode: F, setActiveConversation: rt, createConversation: I, addMessage: L, updateMessage: it, patchMessage: R, mergeMessageMetadata: at, setConversationProcessing: z, clearConversationProcessing: ot, setBackendSessionId: st, clearBackendSessionId: B, setSandbox: V, clearSandbox: ct, acknowledgeApiCalls: lt } = e(), H = ge(tt.find((e) => e.id === M)), U = H.all, W = M ? nt[M] : void 0, G = Ce(W?.status), ut = G ? W?.messageId ?? null : null, dt = W?.status === "error" ? W.messageId : null, { canUseApiCalls: K, loading: ft } = de(y()), pt = fe(te(), ne() || null), mt = T(() => we.filter((e) => !e.requiresAdmin || K), [K]), [ht, gt] = Ne(null), [_t, vt] = Ne(!1), yt = E({}), q = E(Me()), bt = E(/* @__PURE__ */ new Set()), xt = T(() => we.find((e) => e.id === N), [N]);
94
+ ]), Qe = Ze.reply.english, $e = Ze.replyIsExplicit, et = Ze.reply.code, { conversations: tt, activeConversationId: M, mode: N, processingByConversationId: nt, setMode: P, setConversationMode: F, setActiveConversation: rt, createConversation: I, addMessage: L, updateMessage: it, patchMessage: R, mergeMessageMetadata: at, setConversationProcessing: z, clearConversationProcessing: ot, setBackendSessionId: st, clearBackendSessionId: B, setSandbox: V, clearSandbox: ct, acknowledgeApiCalls: lt } = e(), H = pe(tt.find((e) => e.id === M)), U = H.all, W = M ? nt[M] : void 0, G = be(W?.status), ut = G ? W?.messageId ?? null : null, dt = W?.status === "error" ? W.messageId : null, { canUseApiCalls: K, loading: ft } = de(y()), pt = fe(te(), ne() || null), mt = T(() => xe.filter((e) => !e.requiresAdmin || K), [K]), [ht, gt] = Ne(null), [_t, vt] = Ne(!1), yt = E({}), q = E(Me()), bt = E(/* @__PURE__ */ new Set()), xt = T(() => xe.find((e) => e.id === N), [N]);
95
95
  w(() => {
96
96
  ft || (!xt || xt.requiresAdmin && !K) && N !== "assistant" && P("assistant");
97
97
  }, [
@@ -142,7 +142,7 @@ var Ke = ({ visible: Ee = !0 }) => {
142
142
  J
143
143
  ]), Y = C(async (t, n = [], i = {}) => {
144
144
  let ee = i.voiceSessionId !== void 0, l = e.getState(), u = l.activeConversationId ?? M;
145
- if (u && (Ce(l.processingByConversationId[u]?.status) || bt.current.has(u))) return;
145
+ if (u && (be(l.processingByConversationId[u]?.status) || bt.current.has(u))) return;
146
146
  let f = l.mode, p = M, m = p ? e.getState().conversations.find((e) => e.id === p) : void 0;
147
147
  if (p ? m && m.mode !== f && (m.messages.length > 0 || m.backendSessionId) ? p = I(void 0, f) : m && m.mode !== f && F(p, f) : p = I(void 0, f), !p) return;
148
148
  yt.current[p] = n;
@@ -158,7 +158,7 @@ var Ke = ({ visible: Ee = !0 }) => {
158
158
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
159
159
  metadata: {
160
160
  ...n.length ? { attachments: n.map(x) } : {},
161
- ...me(i.voiceSessionId)
161
+ ...Ae(i.voiceSessionId)
162
162
  }
163
163
  };
164
164
  L(p, _);
@@ -170,7 +170,7 @@ var Ke = ({ visible: Ee = !0 }) => {
170
170
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
171
171
  metadata: {
172
172
  lang: et,
173
- ...me(i.voiceSessionId)
173
+ ...Ae(i.voiceSessionId)
174
174
  }
175
175
  }), z(p, "provisioning", v, null);
176
176
  let te = (e, t, n, r, a = et) => {
@@ -180,23 +180,23 @@ var Ke = ({ visible: Ee = !0 }) => {
180
180
  ...t?.length || n || r ? { mode: f } : {},
181
181
  ...n ? { sessionId: n } : {},
182
182
  ...r ? { sandboxId: r } : {},
183
- ...me(i.voiceSessionId)
183
+ ...Ae(i.voiceSessionId)
184
184
  });
185
185
  }, b = async (e = 1) => {
186
186
  let i = !1;
187
187
  try {
188
188
  let { sandboxId: e, sessionId: l } = await St(p, v, f, h, g), u = (await o(A, e, h, l, g, 50).catch(() => [])).reduce((e, t) => Math.max(e, k(t)), 0);
189
189
  J(p, v, "streaming", "Thinking...");
190
- let m = be(f, ie(t, n), Qe, $e, ee), _ = re(m, n), y = oe(_), ne = y > 0, b = d();
190
+ let m = _e(f, ie(t, n), Qe, $e, ee), _ = re(m, n), y = oe(_), ne = y > 0, b = d();
191
191
  i = ae(n) > y;
192
192
  try {
193
193
  await c(A, e, h, l, m, f, b, g, _);
194
194
  } catch (t) {
195
- if (!_ || !xe(t)) throw t;
195
+ if (!_ || !ve(t)) throw t;
196
196
  await c(A, e, h, l, m, f, b, g, void 0), i ||= ne;
197
197
  }
198
198
  let x = We([], u), S = Date.now() + (Be[f] ?? Ve), se = Date.now(), ce = Date.now();
199
- for (; Date.now() < S && (x = We(await o(A, e, h, l, g, 50, u), u), R(p, v, { content: ze(x.content) }), x.pendingWrite && at(p, v, { pendingWrite: x.pendingWrite }), !x.done);) Date.now() - se > 3e4 && (await r(A, e, h, 600, g).catch(() => void 0), se = Date.now()), await new Promise((e) => setTimeout(e, Te(Date.now() - ce)));
199
+ for (; Date.now() < S && (x = We(await o(A, e, h, l, g, 50, u), u), R(p, v, { content: ze(x.content) }), x.pendingWrite && at(p, v, { pendingWrite: x.pendingWrite }), !x.done);) Date.now() - se > 3e4 && (await r(A, e, h, 600, g).catch(() => void 0), se = Date.now()), await new Promise((e) => setTimeout(e, Se(Date.now() - ce)));
200
200
  if (!x.done && f !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
201
201
  let le = f === "vibe-plugins" ? await a(A, e, h, l, g).catch(() => []) : void 0;
202
202
  if (x.done || (x = {
@@ -208,12 +208,12 @@ var Ke = ({ visible: Ee = !0 }) => {
208
208
  }), te(x.content, le, l, e), x.tokens) {
209
209
  R(p, v, { tokens: x.tokens });
210
210
  try {
211
- await s(A, h, l, x.tokens, g), ye();
211
+ await s(A, h, l, x.tokens, g), ge();
212
212
  } catch {}
213
213
  }
214
214
  z(p, "complete", v, null);
215
215
  } catch (t) {
216
- if (e === 1 && Se(t)) return B(p), ct(f), b(2);
216
+ if (e === 1 && ye(t)) return B(p), ct(f), b(2);
217
217
  throw t;
218
218
  }
219
219
  }, S = p;
@@ -222,14 +222,14 @@ var Ke = ({ visible: Ee = !0 }) => {
222
222
  if (!h) throw Error("Assistant backend is unavailable without an active workspace context.");
223
223
  await b();
224
224
  } catch (t) {
225
- if (q.current.invalidate(e.getState().sandboxesByMode[f]?.sandboxId ?? null), _e(t)) {
226
- ve("sandbox"), te("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant.", void 0, void 0, void 0, "en"), z(p, "error", v, null);
225
+ if (q.current.invalidate(e.getState().sandboxesByMode[f]?.sandboxId ?? null), me(t)) {
226
+ he("sandbox"), te("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant.", void 0, void 0, void 0, "en"), z(p, "error", v, null);
227
227
  return;
228
228
  }
229
229
  let n = t instanceof Error ? t.message : "Something went wrong";
230
230
  z(p, "error", v, n), R(p, v, { content: `Sorry, an error occurred: ${n}. Please try again.` }), at(p, v, {
231
231
  lang: "en",
232
- ...me(i.voiceSessionId)
232
+ ...Ae(i.voiceSessionId)
233
233
  });
234
234
  } finally {
235
235
  bt.current.delete(S);
@@ -272,7 +272,7 @@ var Ke = ({ visible: Ee = !0 }) => {
272
272
  if (G) return null;
273
273
  for (let e = U.length - 1; e >= 0; --e) {
274
274
  let t = U[e];
275
- if (t?.role !== "assistant" || !pe(t)) continue;
275
+ if (t?.role !== "assistant" || !ke(t)) continue;
276
276
  let n = le(t.content).text.trim();
277
277
  return n ? {
278
278
  id: t.id,
@@ -280,23 +280,23 @@ var Ke = ({ visible: Ee = !0 }) => {
280
280
  } : null;
281
281
  }
282
282
  return null;
283
- }, [U, G]), Dt = T(() => Et ? De(Et.text) : null, [Et]), Ot = H.chat, X = T(() => H.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
283
+ }, [U, G]), Dt = T(() => Et ? we(Et.text) : null, [Et]), Ot = H.chat, X = T(() => H.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
284
284
  id: e.id,
285
285
  role: e.role,
286
286
  text: le(e.content).text.trim(),
287
- sessionId: he(e),
287
+ sessionId: je(e),
288
288
  timestamp: e.timestamp
289
289
  })).filter((e) => e.text.length > 0), [H.voice]), kt = C(() => {
290
290
  if (X.length === 0) return;
291
291
  let e = /* @__PURE__ */ new Date();
292
- je(ke(X, {
292
+ Oe(Ee(X, {
293
293
  title: O("voiceSession.transcript", "Voice conversation"),
294
294
  savedAt: O("voiceSession.savedAt", "Saved"),
295
295
  session: O("voiceSession.sessionLabel", "Session"),
296
296
  earlier: O("voiceSession.earlierLabel", "Earlier"),
297
297
  you: O("voiceSession.speakerYou", "You"),
298
298
  assistant: O("voiceSession.speakerAssistant", "Assistant")
299
- }, e), Ae(e), "text/markdown");
299
+ }, e), De(e), "text/markdown");
300
300
  }, [X, O]), Z = S(), Q = E(Z);
301
301
  Q.current = Z;
302
302
  let $ = ue({
@@ -320,7 +320,7 @@ var Ke = ({ visible: Ee = !0 }) => {
320
320
  !t || X.length === 0 || (L(t, {
321
321
  id: Ue(),
322
322
  role: "system",
323
- content: Oe(X, {
323
+ content: Te(X, {
324
324
  intro: O("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
325
325
  nothing: O("voiceSession.continuedNothing", "Continued from a voice conversation."),
326
326
  more: (e) => O("voiceSession.continuedMore", "…and {{count}} more", { count: e })
@@ -333,8 +333,8 @@ var Ke = ({ visible: Ee = !0 }) => {
333
333
  O
334
334
  ]);
335
335
  w(() => {
336
- !Ee && $.active && $.end();
337
- }, [Ee, $]), w(() => {
336
+ !Ce && $.active && $.end();
337
+ }, [Ce, $]), w(() => {
338
338
  $.active || Q.current.clear();
339
339
  }, [$.active]), w(() => {
340
340
  let t = e.getState().consumePendingPrompt();
@@ -361,7 +361,7 @@ var Ke = ({ visible: Ee = !0 }) => {
361
361
  F,
362
362
  P
363
363
  ]), Mt = C((t) => {
364
- if (we.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
364
+ if (xe.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
365
365
  gt(t);
366
366
  return;
367
367
  }
@@ -23,6 +23,6 @@ var e = typeof window < "u", t = {
23
23
  writeCapable: !0
24
24
  }] : [t];
25
25
  //#endregion
26
- export { e as API_CALLS_MODE_ENABLED, n as ASSISTANT_USECASE_CONFIG };
26
+ export { n as ASSISTANT_USECASE_CONFIG };
27
27
 
28
28
  //# sourceMappingURL=assistantUsecases.js.map
@@ -1,38 +1,2 @@
1
- import { API_CALLS_MODE_ENABLED as e } from "../config/assistantUsecases.js";
2
- import { useEffect as t, useState as n } from "react";
3
- import { graphqlFetch as r } from "@burdenoff/fe-libs/shared/graphql";
4
- //#region src/hooks/useAssistantApiAccess.ts
5
- var i = "query AssistantMyRoles($scopeId: String!) {\n myRoles(scopeId: $scopeId) {\n isAdmin\n isOwner\n }\n}";
6
- function a(a) {
7
- let o = e && !!a, [s, c] = n(!1), [l, u] = n(o);
8
- return t(() => {
9
- if (!o) {
10
- c(!1), u(!1);
11
- return;
12
- }
13
- let e = !1;
14
- return u(!0), r({
15
- gateway: "global",
16
- query: i,
17
- variables: { scopeId: a },
18
- suppressGlobalErrorEvent: !0
19
- }).then((t) => {
20
- if (e) return;
21
- let n = t.data?.myRoles;
22
- c(!!(n?.isOwner || n?.isAdmin));
23
- }).catch(() => {
24
- e || c(!1);
25
- }).finally(() => {
26
- e || u(!1);
27
- }), () => {
28
- e = !0;
29
- };
30
- }, [o, a]), {
31
- canUseApiCalls: s,
32
- loading: l
33
- };
34
- }
35
- //#endregion
36
- export { a as useAssistantApiAccess };
37
-
38
- //# sourceMappingURL=useAssistantApiAccess.js.map
1
+ import { useAssistantApiAccess as e } from "@burdenoff/fe-libs/shared/assistant/useAssistantApiAccess";
2
+ export { e as useAssistantApiAccess };
@@ -1,19 +1,2 @@
1
- import { chatTurns as e, voiceTurnsOnly as t } from "../utils/voiceTurnVisibility.js";
2
- import { useMemo as n } from "react";
3
- //#region src/hooks/useConversationTurns.ts
4
- function r(r) {
5
- let i = n(() => r?.messages ?? [], [r?.messages]), a = n(() => e(i), [i]), o = n(() => t(i), [i]);
6
- return n(() => ({
7
- all: i,
8
- chat: a,
9
- voice: o
10
- }), [
11
- i,
12
- a,
13
- o
14
- ]);
15
- }
16
- //#endregion
17
- export { r as useConversationTurns };
18
-
19
- //# sourceMappingURL=useConversationTurns.js.map
1
+ import { useConversationTurns as e } from "@burdenoff/fe-libs/shared/assistant/useConversationTurns";
2
+ export { e as useConversationTurns };
@@ -1,54 +1,2 @@
1
- //#region src/utils/assistantTransportErrors.ts
2
- var e = [
3
- "failed to fetch",
4
- "networkerror",
5
- "network request failed",
6
- "load failed",
7
- "aborted",
8
- "took too long",
9
- "timed out",
10
- "timeout",
11
- "too many requests",
12
- "the server is having trouble",
13
- "unexpected error"
14
- ], t = [
15
- "the request could not be processed",
16
- "payload too large",
17
- "request body exceeds maximum size",
18
- "request entity too large",
19
- "content too large",
20
- "proxy error: 400",
21
- "proxy error: 413",
22
- "proxy error: 415",
23
- "proxy error: 422"
24
- ];
25
- function n(n) {
26
- let r = (n instanceof Error ? n.message : String(n)).toLowerCase();
27
- return e.some((e) => r.includes(e)) ? !1 : t.some((e) => r.includes(e));
28
- }
29
- var r = [
30
- "rate limit exceeded",
31
- "unauthorized",
32
- "k8s api error 401"
33
- ], i = [
34
- "sandbox not found",
35
- "sandbox is not running",
36
- "sandbox service not available yet",
37
- "sandbox failed",
38
- "sandbox startup timed out",
39
- "assistant service did not become healthy",
40
- "proxy error: 404",
41
- "proxy error: 502",
42
- "proxy error: 503",
43
- "session mode mismatch",
44
- "unable to connect",
45
- "able to access the url"
46
- ];
47
- function a(e) {
48
- let t = (e instanceof Error ? e.message : String(e)).toLowerCase();
49
- return r.some((e) => t.includes(e)) ? !1 : i.some((e) => t.includes(e));
50
- }
51
- //#endregion
52
- export { n as isMultimodalBodyRejection, a as isRecoverableAssistantError };
53
-
54
- //# sourceMappingURL=assistantTransportErrors.js.map
1
+ import { isMultimodalBodyRejection as e, isRecoverableAssistantError as t } from "@burdenoff/fe-libs/shared/assistant/transportErrors";
2
+ export { e as isMultimodalBodyRejection, t as isRecoverableAssistantError };
@@ -1,2 +1,2 @@
1
- import { chatTurns as e, isVoiceTurn as t, voiceMarker as n, voiceSessionIdOf as r, voiceTurnsOnly as i } from "@burdenoff/fe-libs/shared/assistant/voice/turnVisibility";
2
- export { e as chatTurns, t as isVoiceTurn, n as voiceMarker, r as voiceSessionIdOf, i as voiceTurnsOnly };
1
+ import { isVoiceTurn as e, voiceMarker as t, voiceSessionIdOf as n } from "@burdenoff/fe-libs/shared/assistant/voice/turnVisibility";
2
+ export { e as isVoiceTurn, t as voiceMarker, n as voiceSessionIdOf };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burdenoff/microfe-healthybowl",
3
- "version": "2026.904.20",
3
+ "version": "2026.904.22",
4
4
  "description": "Burdenoff HealthyBowl Microfrontend - Comprehensive organic farming and agro-foods management platform",
5
5
  "type": "module",
6
6
  "files": [
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@apollo/client": "^4.0.11",
51
- "@burdenoff/fe-libs": "2026.904.18",
51
+ "@burdenoff/fe-libs": "2026.904.20",
52
52
  "@burdenoff/planmagnet-fe-sdk": "2026.831.1",
53
53
  "@tanstack/react-query": "^5.90.16",
54
54
  "clsx": "^2.1.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAssistantApiAccess.js","names":[],"sources":["../../src/hooks/useAssistantApiAccess.ts"],"sourcesContent":["/**\n * Resolves whether the current user may use the write-capable `api-calls`\n * assistant mode.\n *\n * That mode mints a per-sandbox OAuth app under the caller's identity\n * (createApp/createApplication in wspace-sandbox-svc), which is RBAC-gated to a\n * global Owner/Admin — a non-admin would only discover this as a FORBIDDEN at\n * provision time. So we gate the UI on the same signal up front, via the global\n * gateway's `myRoles(scopeId)` query (`@rbac(public: true)`, auth-only, returns\n * `isAdmin`/`isOwner` directly — no extra provider wiring needed).\n *\n * Fails CLOSED: an error, an empty org scope, or the master flag being off all\n * resolve to `canUseApiCalls = false`, so the mode stays hidden unless the user\n * is provably an org admin.\n */\n\nimport { useEffect, useState } from 'react';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { API_CALLS_MODE_ENABLED } from '@/config/assistantUsecases';\n\nconst MY_ROLES_QUERY = `query AssistantMyRoles($scopeId: String!) {\n myRoles(scopeId: $scopeId) {\n isAdmin\n isOwner\n }\n}`;\n\ninterface MyRolesData {\n myRoles: { isAdmin: boolean; isOwner: boolean };\n}\n\nexport interface AssistantApiAccess {\n /** True only for a confirmed global Owner/Admin (and when the mode is enabled). */\n canUseApiCalls: boolean;\n /** True while the role check is in flight. */\n loading: boolean;\n}\n\nexport function useAssistantApiAccess(scopeId: string): AssistantApiAccess {\n const enabled = API_CALLS_MODE_ENABLED && Boolean(scopeId);\n const [canUseApiCalls, setCanUseApiCalls] = useState(false);\n const [loading, setLoading] = useState(enabled);\n\n useEffect(() => {\n if (!enabled) {\n setCanUseApiCalls(false);\n setLoading(false);\n return;\n }\n\n let cancelled = false;\n setLoading(true);\n\n graphqlFetch<MyRolesData>({\n gateway: 'global',\n query: MY_ROLES_QUERY,\n variables: { scopeId },\n // The gate fails closed on its own; don't surface a global error toast.\n suppressGlobalErrorEvent: true,\n })\n .then((result) => {\n if (cancelled) return;\n const roles = result.data?.myRoles;\n setCanUseApiCalls(Boolean(roles?.isOwner || roles?.isAdmin));\n })\n .catch(() => {\n if (!cancelled) setCanUseApiCalls(false);\n })\n .finally(() => {\n if (!cancelled) setLoading(false);\n });\n\n return () => {\n cancelled = true;\n };\n }, [enabled, scopeId]);\n\n return { canUseApiCalls, loading };\n}\n"],"mappings":";;;;AAoBA,IAAM,IAAiB;AAkBvB,SAAgB,EAAsB,GAAqC;CACzE,IAAM,IAAU,KAA0B,EAAQ,GAC5C,CAAC,GAAgB,KAAqB,EAAS,EAAK,GACpD,CAAC,GAAS,KAAc,EAAS,CAAO;CAoC9C,OAlCA,QAAgB;EACd,IAAI,CAAC,GAAS;GAEZ,AADA,EAAkB,EAAK,GACvB,EAAW,EAAK;GAChB;EACF;EAEA,IAAI,IAAY;EAsBhB,OArBA,EAAW,EAAI,GAEf,EAA0B;GACxB,SAAS;GACT,OAAO;GACP,WAAW,EAAE,WAAQ;GAErB,0BAA0B;EAC5B,CAAC,EACE,MAAM,MAAW;GAChB,IAAI,GAAW;GACf,IAAM,IAAQ,EAAO,MAAM;GAC3B,EAAkB,GAAQ,GAAO,WAAW,GAAO,QAAQ;EAC7D,CAAC,EACA,YAAY;GACX,AAAK,KAAW,EAAkB,EAAK;EACzC,CAAC,EACA,cAAc;GACb,AAAK,KAAW,EAAW,EAAK;EAClC,CAAC,SAEU;GACX,IAAY;EACd;CACF,GAAG,CAAC,GAAS,CAAO,CAAC,GAEd;EAAE;EAAgB;CAAQ;AACnC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useConversationTurns.js","names":[],"sources":["../../src/hooks/useConversationTurns.ts"],"sourcesContent":["import { useMemo } from 'react';\nimport type { Conversation, Message } from '@/types/assistant';\nimport { chatTurns, voiceTurnsOnly } from '@/utils/voiceTurnVisibility';\n\nexport interface ConversationTurns {\n /**\n * Every turn, both surfaces. Readonly, so it cannot be handed to a component\n * that renders a message list — that is the point of it being readonly.\n *\n * Use it for questions about the CONVERSATION (\"is it used at all?\"), never\n * for questions about a SURFACE (\"what should I draw?\").\n */\n all: readonly Message[];\n /** Typed turns — what the chat thread draws. */\n chat: Message[];\n /** Spoken turns — what the voice panel and the transcript draw. */\n voice: Message[];\n}\n\n/**\n * One place that decides which turns belong to which surface.\n *\n * Voice and chat share a single message array; separation is a per-message\n * marker plus a filter applied by every reader. That makes correctness scale\n * with the NUMBER OF READERS, which is how the last round of leaks happened —\n * the message list filtered correctly while four other readers did not, and\n * nothing failed.\n *\n * ★ Deliberately a hook returning memoised arrays rather than a zustand\n * selector. A selector like `useAssistantStore(s => chatTurns(...))` builds a\n * fresh array on every call, so `Object.is` never matches and the component\n * re-renders on every unrelated store change. Subscribing to the array and\n * filtering in `useMemo` is the version that does not.\n *\n * The two filters are separate memos on purpose: a typed turn arriving must not\n * hand the voice panel a new array identity, or the voice session re-renders\n * mid-utterance.\n */\nexport function useConversationTurns(conversation: Conversation | undefined): ConversationTurns {\n const all = useMemo(() => conversation?.messages ?? [], [conversation?.messages]);\n const chat = useMemo(() => chatTurns(all), [all]);\n const voice = useMemo(() => voiceTurnsOnly(all), [all]);\n return useMemo(() => ({ all, chat, voice }), [all, chat, voice]);\n}\n"],"mappings":";;;AAsCA,SAAgB,EAAqB,GAA2D;CAC9F,IAAM,IAAM,QAAc,GAAc,YAAY,CAAC,GAAG,CAAC,GAAc,QAAQ,CAAC,GAC1E,IAAO,QAAc,EAAU,CAAG,GAAG,CAAC,CAAG,CAAC,GAC1C,IAAQ,QAAc,EAAe,CAAG,GAAG,CAAC,CAAG,CAAC;CACtD,OAAO,SAAe;EAAE;EAAK;EAAM;CAAM,IAAI;EAAC;EAAK;EAAM;CAAK,CAAC;AACjE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"assistantTransportErrors.js","names":[],"sources":["../../src/utils/assistantTransportErrors.ts"],"sourcesContent":["/**\n * Deciding whether a failed turn is worth re-sending WITHOUT its images.\n *\n * The multimodal turn carries image bytes inside the `proxySandboxRequest` body.\n * Two things can refuse that body before the model ever sees it:\n *\n * 1. `wspace-public-gateway` enforces `MAX_REQUEST_BODY_SIZE` (256kb in alpha\n * and prod). It compares `Content-Length` and answers **413 before\n * authenticating and before forwarding anything**.\n * 2. The in-sandbox bridge can reject the body itself, which surfaces through\n * fe-libs as `Proxy error: <status>`.\n *\n * In both cases the prompt provably did not reach the agent, so re-sending it\n * text-only is safe and is strictly better than losing the turn.\n *\n * ## Why this is substring matching and not a status check\n *\n * fe-libs' `graphqlFetch` maps a non-2xx response to a human sentence and throws\n * that — `throw Error(friendlyMessage(response))` — keeping no status code, no\n * `extensions`, nothing structured. Every 4xx that is not 401/403/404/429\n * collapses to one sentence. So the sentence IS the signal; there is nothing\n * better to key on from here.\n *\n * ## Why the deny-list comes first\n *\n * Retrying something that may have LANDED would double-charge the user and give\n * the agent the same question twice — the session is stateful and the prompt\n * POST carries no idempotency key. Anything that could have failed on the\n * RESPONSE leg (network drops, timeouts, 5xx) is therefore excluded outright,\n * including the shapes fe-libs' own `executeSandboxGraphQL` has already retried\n * three times before we ever see them.\n */\n\n/** Failures that may have reached the agent. Never re-send these. */\nconst MAY_HAVE_LANDED = [\n 'failed to fetch',\n 'networkerror',\n 'network request failed',\n 'load failed',\n 'aborted',\n 'took too long',\n 'timed out',\n 'timeout',\n 'too many requests',\n 'the server is having trouble',\n 'unexpected error',\n];\n\n/** Failures that provably rejected the body before it was forwarded. */\nconst REJECTED_BEFORE_FORWARDING = [\n // The generic 4xx sentence from fe-libs `graphqlFetch`. For a POST whose\n // GraphQL document is known-good, the reachable cases are the gateway's 413\n // body cap and a 400-class rejection of the body — both pre-forward.\n 'the request could not be processed',\n // Direct 413 wording, in case a proxy answers with its own body.\n 'payload too large',\n 'request body exceeds maximum size',\n 'request entity too large',\n 'content too large',\n // The bridge rejected the body (fe-libs `Proxy error: <status>`).\n 'proxy error: 400',\n 'proxy error: 413',\n 'proxy error: 415',\n 'proxy error: 422',\n];\n\n/**\n * Is this error a rejection of the request BODY that we should retry without\n * the multimodal parts?\n */\nexport function isMultimodalBodyRejection(error: unknown): boolean {\n const message = (error instanceof Error ? error.message : String(error)).toLowerCase();\n if (MAY_HAVE_LANDED.some((fragment) => message.includes(fragment))) return false;\n return REJECTED_BEFORE_FORWARDING.some((fragment) => message.includes(fragment));\n}\n\n/**\n * Faults where the whole turn is worth replaying against a FRESH sandbox and\n * session (the caller drops the remembered sandbox + backend session, then\n * re-runs once).\n *\n * Lives next to `isMultimodalBodyRejection` on purpose: both decide whether to\n * re-send a prompt, and a change to one is nearly always a change to the other.\n */\nconst NEVER_RECOVERABLE = ['rate limit exceeded', 'unauthorized', 'k8s api error 401'];\n\nconst RECOVERABLE_WITH_FRESH_SANDBOX = [\n 'sandbox not found',\n 'sandbox is not running',\n 'sandbox service not available yet',\n 'sandbox failed',\n 'sandbox startup timed out',\n 'assistant service did not become healthy',\n 'proxy error: 404',\n 'proxy error: 502',\n 'proxy error: 503',\n 'session mode mismatch',\n // ── The reaped-sandbox signature ──────────────────────────────────────────\n // A sandbox is destroyed at create + ttlSeconds, and keep-alive extensions did\n // not reach the runtime that enforces it, so a panel left open outlives its\n // own sandbox. Requests afterwards report the in-container service as\n // unreachable (\"assistant service not available: Unable to connect. Is the\n // computer able to access the url?\"), and until now that matched nothing here\n // — so the turn died with a raw error instead of provisioning a new sandbox,\n // and stayed dead for every later turn in that conversation.\n //\n // Matching the CONNECTION-REFUSED wording specifically, not the generic\n // \"assistant service not available\" prefix, which is also used for a 9s fetch\n // timeout — a timeout may mean the prompt DID land, and replaying that would\n // ask the model the same question twice. Refused provably delivered nothing.\n // Same wording the sandbox proxy itself treats as \"container not reachable\".\n 'unable to connect',\n 'able to access the url',\n];\n\nexport function isRecoverableAssistantError(error: unknown): boolean {\n const message = (error instanceof Error ? error.message : String(error)).toLowerCase();\n if (NEVER_RECOVERABLE.some((fragment) => message.includes(fragment))) return false;\n return RECOVERABLE_WITH_FRESH_SANDBOX.some((fragment) => message.includes(fragment));\n}\n"],"mappings":";AAkCA,IAAM,IAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAGM,IAA6B;CAIjC;CAEA;CACA;CACA;CACA;CAEA;CACA;CACA;CACA;AACF;AAMA,SAAgB,EAA0B,GAAyB;CACjE,IAAM,KAAW,aAAiB,QAAQ,EAAM,UAAU,OAAO,CAAK,GAAG,YAAY;CAErF,OADI,EAAgB,MAAM,MAAa,EAAQ,SAAS,CAAQ,CAAC,IAAU,KACpE,EAA2B,MAAM,MAAa,EAAQ,SAAS,CAAQ,CAAC;AACjF;AAUA,IAAM,IAAoB;CAAC;CAAuB;CAAgB;AAAmB,GAE/E,IAAiC;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAeA;CACA;AACF;AAEA,SAAgB,EAA4B,GAAyB;CACnE,IAAM,KAAW,aAAiB,QAAQ,EAAM,UAAU,OAAO,CAAK,GAAG,YAAY;CAErF,OADI,EAAkB,MAAM,MAAa,EAAQ,SAAS,CAAQ,CAAC,IAAU,KACtE,EAA+B,MAAM,MAAa,EAAQ,SAAS,CAAQ,CAAC;AACrF"}