@burdenoff/fe-libs 2026.924.2 → 2026.924.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/shared/assistant/adminModeSendGate.d.ts.map +1 -1
  2. package/dist/shared/assistant/adminModeSendGate.js +23 -20
  3. package/dist/shared/assistant/autoRouting.d.ts +197 -0
  4. package/dist/shared/assistant/autoRouting.d.ts.map +1 -0
  5. package/dist/shared/assistant/autoRouting.js +854 -0
  6. package/dist/shared/assistant/conversation.d.ts +13 -0
  7. package/dist/shared/assistant/conversation.d.ts.map +1 -1
  8. package/dist/shared/assistant/i18nManifest.d.ts +2 -0
  9. package/dist/shared/assistant/i18nManifest.d.ts.map +1 -1
  10. package/dist/shared/assistant/i18nManifest.js +23 -19
  11. package/dist/shared/assistant/index.d.ts +3 -0
  12. package/dist/shared/assistant/index.d.ts.map +1 -1
  13. package/dist/shared/assistant/modeCapabilities.d.ts +1 -1
  14. package/dist/shared/assistant/modeCapabilities.d.ts.map +1 -1
  15. package/dist/shared/assistant/modeCapabilities.js +29 -28
  16. package/dist/shared/assistant/permissionError.d.ts.map +1 -1
  17. package/dist/shared/assistant/permissionError.js +11 -10
  18. package/dist/shared/assistant/store.d.ts +32 -2
  19. package/dist/shared/assistant/store.d.ts.map +1 -1
  20. package/dist/shared/assistant/store.js +69 -29
  21. package/dist/shared/assistant/turnOutcome.d.ts +58 -0
  22. package/dist/shared/assistant/turnOutcome.d.ts.map +1 -0
  23. package/dist/shared/assistant/turnOutcome.js +79 -0
  24. package/dist/shared/assistant/turnOutcomeCopy.d.ts +62 -0
  25. package/dist/shared/assistant/turnOutcomeCopy.d.ts.map +1 -0
  26. package/dist/shared/assistant/turnOutcomeCopy.js +49 -0
  27. package/dist/shared/assistant/ui/AssistantChatArea.d.ts.map +1 -1
  28. package/dist/shared/assistant/ui/AssistantChatArea.js +475 -399
  29. package/dist/shared/assistant/ui/AssistantEmptyState.d.ts +17 -1
  30. package/dist/shared/assistant/ui/AssistantEmptyState.d.ts.map +1 -1
  31. package/dist/shared/assistant/ui/AssistantEmptyState.js +14 -9
  32. package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts +3 -0
  33. package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts.map +1 -1
  34. package/dist/shared/assistant/ui/composer/AssistantComposer.js +110 -109
  35. package/dist/shared/assistant/ui/composer/AssistantModeSelector.d.ts +20 -0
  36. package/dist/shared/assistant/ui/composer/AssistantModeSelector.d.ts.map +1 -1
  37. package/dist/shared/assistant/ui/composer/AssistantModeSelector.js +89 -45
  38. package/dist/shared/assistant/writeModeConsent.d.ts +15 -2
  39. package/dist/shared/assistant/writeModeConsent.d.ts.map +1 -1
  40. package/dist/shared/assistant/writeModeConsent.js +24 -19
  41. package/dist/shared-assistant.js +116 -113
  42. package/package.json +1 -1
@@ -3,403 +3,437 @@ import { useAuthToken as t } from "../../providers/shell/AuthTokenProvider.js";
3
3
  import "../../../shared-providers-shell.js";
4
4
  import { useAssistantProduct as n } from "../product.js";
5
5
  import { useAssistantTr as r } from "../i18n.js";
6
- import { describeQuotaError as i } from "../quota.js";
7
- import { abortAssistantTurn as a, approvePendingWrite as o, createAssistantSandbox as s, createAssistantSession as c, extendAssistantSandboxTTL as l, findExistingSandbox as u, getAssistantArtifacts as ee, getAssistantMessages as te, getAssistantSession as d, modeRequiresConfirmWrites as f, promptGatewayRequestBytes as ne, releaseSupersededAssistantSandboxes as p, sendAssistantPromptAsync as re, waitForAssistantServiceReady as m, waitForSandboxRunning as h } from "../api.js";
8
- import { getRawMessageCreatedAt as ie, sanitize as ae } from "../progress.js";
9
- import { withIncompleteTurnNotice as oe } from "../streamBudget.js";
10
- import { isVoiceTurn as g, voiceMarker as _, voiceSessionIdOf as v } from "../voice/turnVisibility.js";
11
- import { buildContinuedFromVoiceNote as se, buildVoiceTranscriptMarkdown as ce, voiceTranscriptFilename as y } from "../voice/voiceTranscript.js";
12
- import { pollDelayMs as le } from "../voice/assistantPollSchedule.js";
13
- import { toCaptionText as ue } from "../voice/captionText.js";
14
- import { resolveAssistantLanguage as de } from "../voice/languages.js";
15
- import { resolveLanguagePair as fe } from "../voice/languagePair.js";
16
- import { countInlineImageCandidates as pe, countInlinedImageParts as me, getSendableAttachments as he, largestInlineCharsPerFile as ge, resolveAssistantInlineLimits as _e, toMessageAttachment as ve } from "../attachments.js";
17
- import { createAdminModeAccessGate as ye, resolveAssistantSendModeAfterAccess as be } from "../adminModeSendGate.js";
18
- import { buildBoundedAttachmentTurn as xe } from "../attachmentTurn.js";
19
- import { isWriteModeAcknowledged as Se, writeModeSendRefusal as Ce } from "../writeModeConsent.js";
20
- import { resolveActiveModeSandbox as we, useAssistantStore as b } from "../store.js";
21
- import { isTurnInFlight as Te, planAbandonedTurn as Ee, planTurnAbort as De } from "../turnState.js";
22
- import { getAssistantDisplayContent as Oe } from "../displayContent.js";
23
- import { buildAssistantProgress as ke } from "../turnProgress.js";
24
- import { parseToolActivity as Ae } from "./AssistantToolActivity.js";
25
- import { countSpokenTurns as je, spokenTurnText as Me } from "../spokenTurns.js";
26
- import { useVoiceSession as Ne } from "./useVoiceSession.js";
27
- import { getOrganizationId as Pe, getWorkspaceId as Fe } from "../context.js";
28
- import { createReadinessTracker as Ie } from "../sandboxReadiness.js";
29
- import { AssistantSpokenTurnsNotice as Le } from "./AssistantSpokenTurnsNotice.js";
30
- import { VoiceTranscriptDrawer as Re } from "./voice/VoiceTranscriptDrawer.js";
31
- import { downloadFile as ze } from "../exportConversation.js";
32
- import { AssistantEmptyState as Be } from "./AssistantEmptyState.js";
33
- import { AssistantMessageList as Ve } from "./AssistantMessageList.js";
34
- import { AssistantVoiceSession as He } from "./voice/AssistantVoiceSession.js";
35
- import { useAssistantApiAccess as Ue } from "../useAssistantApiAccess.js";
36
- import { useConversationTurns as We } from "../useConversationTurns.js";
37
- import { isMultimodalBodyRejection as Ge, isRecoverableAssistantError as Ke } from "../transportErrors.js";
38
- import { describePermissionError as qe, permissionRefusalMessage as Je } from "../permissionError.js";
39
- import { dispatchAssistantQuotaExhausted as Ye, notifyAiCreditsUpdated as Xe } from "../aiCredits.js";
40
- import { useAssistantAttachments as Ze } from "../useAssistantAttachments.js";
41
- import { AssistantComposer as Qe } from "./composer/AssistantComposer.js";
42
- import { isProdRuntime as $e } from "../env.js";
43
- import { AssistantApiCallsConsentDialog as et } from "./AssistantApiCallsConsentDialog.js";
44
- import { useCallback as x, useEffect as S, useMemo as C, useRef as w, useState as tt } from "react";
45
- import { jsx as T, jsxs as nt } from "react/jsx-runtime";
6
+ import { isAssistantModeId as i } from "../modeIds.js";
7
+ import { abortAssistantTurn as a, approvePendingWrite as o, createAssistantSandbox as s, createAssistantSession as c, extendAssistantSandboxTTL as ee, findExistingSandbox as te, getAssistantArtifacts as l, getAssistantMessages as ne, getAssistantSession as u, modeRequiresConfirmWrites as re, promptGatewayRequestBytes as ie, releaseSupersededAssistantSandboxes as d, sendAssistantPromptAsync as ae, waitForAssistantServiceReady as f, waitForSandboxRunning as oe } from "../api.js";
8
+ import { getRawMessageCreatedAt as se, sanitize as ce } from "../progress.js";
9
+ import { withIncompleteTurnNotice as le } from "../streamBudget.js";
10
+ import { isVoiceTurn as p, voiceMarker as m, voiceSessionIdOf as h } from "../voice/turnVisibility.js";
11
+ import { buildContinuedFromVoiceNote as ue, buildVoiceTranscriptMarkdown as g, voiceTranscriptFilename as de } from "../voice/voiceTranscript.js";
12
+ import { pollDelayMs as fe } from "../voice/assistantPollSchedule.js";
13
+ import { toCaptionText as pe } from "../voice/captionText.js";
14
+ import { resolveAssistantLanguage as _ } from "../voice/languages.js";
15
+ import { resolveLanguagePair as me } from "../voice/languagePair.js";
16
+ import { countInlineImageCandidates as he, countInlinedImageParts as ge, getSendableAttachments as _e, largestInlineCharsPerFile as ve, resolveAssistantInlineLimits as ye, toMessageAttachment as be } from "../attachments.js";
17
+ import { AssistantSendRefusal as xe, classifyTurnFailure as Se, turnOutcomeCopy as Ce } from "../turnOutcome.js";
18
+ import { createAdminModeAccessGate as we, resolveAssistantSendModeAfterAccess as Te } from "../adminModeSendGate.js";
19
+ import { buildBoundedAttachmentTurn as Ee } from "../attachmentTurn.js";
20
+ import { isWriteModeAcknowledged as De, writeModeSendRefusalReason as Oe } from "../writeModeConsent.js";
21
+ import { AUTO_READ_MODE as ke, autoCarryOverFor as Ae, autoSuggestions as je, classifyAssistantIntent as Me, escalationToUndo as Ne, isAutoRoutingOffered as Pe, resolveAutoRoute as Fe } from "../autoRouting.js";
22
+ import { resolveActiveModeSandbox as Ie, useAssistantStore as v } from "../store.js";
23
+ import { isTurnInFlight as Le, planAbandonedTurn as Re, planTurnAbort as ze } from "../turnState.js";
24
+ import { getAssistantDisplayContent as Be } from "../displayContent.js";
25
+ import { buildAssistantProgress as Ve } from "../turnProgress.js";
26
+ import { parseToolActivity as He } from "./AssistantToolActivity.js";
27
+ import { countSpokenTurns as Ue, spokenTurnText as We } from "../spokenTurns.js";
28
+ import { useVoiceSession as Ge } from "./useVoiceSession.js";
29
+ import { getOrganizationId as Ke, getWorkspaceId as qe } from "../context.js";
30
+ import { createReadinessTracker as Je } from "../sandboxReadiness.js";
31
+ import { AssistantSpokenTurnsNotice as Ye } from "./AssistantSpokenTurnsNotice.js";
32
+ import { VoiceTranscriptDrawer as Xe } from "./voice/VoiceTranscriptDrawer.js";
33
+ import { downloadFile as Ze } from "../exportConversation.js";
34
+ import { AssistantEmptyState as Qe } from "./AssistantEmptyState.js";
35
+ import { AssistantMessageList as $e } from "./AssistantMessageList.js";
36
+ import { AssistantVoiceSession as et } from "./voice/AssistantVoiceSession.js";
37
+ import { useAssistantApiAccess as tt } from "../useAssistantApiAccess.js";
38
+ import { useConversationTurns as nt } from "../useConversationTurns.js";
39
+ import { isMultimodalBodyRejection as rt, isRecoverableAssistantError as it } from "../transportErrors.js";
40
+ import { dispatchAssistantQuotaExhausted as at, notifyAiCreditsUpdated as ot } from "../aiCredits.js";
41
+ import { useAssistantAttachments as st } from "../useAssistantAttachments.js";
42
+ import { AssistantComposer as ct } from "./composer/AssistantComposer.js";
43
+ import { isProdRuntime as lt } from "../env.js";
44
+ import { AssistantApiCallsConsentDialog as ut } from "./AssistantApiCallsConsentDialog.js";
45
+ import { useCallback as y, useEffect as b, useMemo as x, useRef as S, useState as dt } from "react";
46
+ import { jsx as C, jsxs as ft } from "react/jsx-runtime";
46
47
  //#region src/shared/assistant/ui/AssistantChatArea.tsx
47
- var rt = 600, it = 2e4;
48
- function at() {
48
+ var pt = 600, mt = 2e4;
49
+ function ht() {
49
50
  return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
50
51
  }
51
- var ot = ({ visible: ot = !0, writeAccess: st = "unknown" }) => {
52
- let E = r(), { product: D, modes: O, gatherPageContext: ct, buildPrompt: lt, reportTokenUsage: ut } = n(), { getAccessToken: k, getWorkspaceToken: A, userId: j } = t(), { locale: dt } = e(), ft = b((e) => e.assistantLanguage), pt = b((e) => e.replyLanguage), mt = C(() => fe(ft, pt, dt), [
53
- ft,
54
- pt,
55
- dt
56
- ]), ht = mt.reply.english, gt = mt.replyIsExplicit, _t = mt.reply.code, { conversations: vt, activeConversationId: M, mode: N, processingByConversationId: yt, setMode: P, setConversationMode: bt, setActiveConversation: xt, createConversation: F, addMessage: I, updateMessage: St, patchMessage: L, mergeMessageMetadata: Ct, setConversationProcessing: R, clearConversationProcessing: wt, setBackendSessionId: Tt, clearBackendSessionId: Et, setSandbox: z, clearSandbox: Dt, acknowledgedWriteModes: Ot, acknowledgeWriteMode: kt } = b(), At = vt.find((e) => e.id === M), B = We(At), jt = B.all, V = M ? yt[M] : void 0, Mt = Te(V?.status), Nt = Mt ? V?.messageId ?? null : null, Pt = V?.status === "error" ? V.messageId : null, { canUseApiCalls: H, loading: Ft } = Ue(Pe()), U = w(ye({
57
- loading: Ft,
58
- canUseAdminModes: H
59
- })).current, It = w(O);
60
- S(() => {
61
- It.current = O;
62
- }, [O]), S(() => {
63
- U.update({
64
- loading: Ft,
65
- canUseAdminModes: H
52
+ var gt = ({ visible: gt = !0, writeAccess: _t = "unknown" }) => {
53
+ let w = r(), { product: T, modes: E, gatherPageContext: vt, buildPrompt: yt, reportTokenUsage: bt } = n(), { getAccessToken: D, getWorkspaceToken: O, userId: k } = t(), { locale: xt } = e(), St = v((e) => e.assistantLanguage), Ct = v((e) => e.replyLanguage), wt = x(() => me(St, Ct, xt), [
54
+ St,
55
+ Ct,
56
+ xt
57
+ ]), Tt = wt.reply.english, Et = wt.replyIsExplicit, Dt = wt.reply.code, { conversations: Ot, activeConversationId: A, mode: j, processingByConversationId: kt, setMode: M, setConversationMode: At, setActiveConversation: jt, createConversation: N, addMessage: P, updateMessage: Mt, patchMessage: Nt, mergeMessageMetadata: Pt, setConversationProcessing: F, clearConversationProcessing: Ft, setBackendSessionId: It, clearBackendSessionId: Lt, setSandbox: I, clearSandbox: Rt, acknowledgedWriteModes: zt, acknowledgeWriteMode: Bt, autoRouting: Vt, setAutoRouting: Ht, routeConversation: L } = v(), Ut = Ot.find((e) => e.id === A), R = nt(Ut), Wt = R.all, z = A ? kt[A] : void 0, Gt = Le(z?.status), Kt = Gt ? z?.messageId ?? null : null, qt = z?.status === "error" ? z.messageId : null, { canUseApiCalls: B, loading: Jt } = tt(Ke()), V = S(we({
58
+ loading: Jt,
59
+ canUseAdminModes: B
60
+ })).current, Yt = S(E);
61
+ b(() => {
62
+ Yt.current = E;
63
+ }, [E]), b(() => {
64
+ V.update({
65
+ loading: Jt,
66
+ canUseAdminModes: B
66
67
  });
67
68
  }, [
68
- U,
69
- Ft,
70
- H
71
- ]), S(() => () => {
72
- U.abandon();
73
- }, [U]);
74
- let Lt = C(() => O.filter((e) => !e.requiresAdmin || H), [O, H]), Rt = ge(O), [W, zt] = tt(null), [Bt, Vt] = tt(!1), Ht = w({}), Ut = w(Ie()), Wt = w(/* @__PURE__ */ new Set()), Gt = w(/* @__PURE__ */ new Set()), G = C(() => O.find((e) => e.id === N), [O, N]), Kt = N === "assistant" || G !== void 0 && !G.writeCapable && !f(N);
75
- S(() => {
76
- if (N !== "assistant" && G?.writeCapable && !Se(Ot, N)) {
77
- P("assistant");
69
+ V,
70
+ Jt,
71
+ B
72
+ ]), b(() => () => {
73
+ V.abandon();
74
+ }, [V]);
75
+ let Xt = x(() => E.filter((e) => !e.requiresAdmin || B), [E, B]), Zt = Pe(Xt), Qt = Vt && Zt, $t = S(Zt);
76
+ b(() => {
77
+ $t.current = Zt;
78
+ }, [Zt]);
79
+ let H = S(null), en = ve(E), [U, tn] = dt(null), [nn, rn] = dt(!1), an = S({}), W = S(Je()), on = S(/* @__PURE__ */ new Set()), sn = S(/* @__PURE__ */ new Set()), G = x(() => E.find((e) => e.id === j), [E, j]), cn = j === "assistant" || G !== void 0 && !G.writeCapable && !re(j);
80
+ b(() => {
81
+ if (j !== "assistant" && G?.writeCapable && !De(zt, j)) {
82
+ M("assistant");
78
83
  return;
79
84
  }
80
- Ft || (!G || G.requiresAdmin && !H) && N !== "assistant" && P("assistant");
85
+ Jt || (!G || G.requiresAdmin && !B) && j !== "assistant" && M("assistant");
81
86
  }, [
82
- N,
87
+ j,
83
88
  G,
84
- H,
85
- Ft,
86
- P,
87
- Ot
89
+ B,
90
+ Jt,
91
+ M,
92
+ zt
88
93
  ]);
89
- let K = x((e, t, n, r) => {
90
- R(e, n, t, null, r);
91
- }, [R]), qt = x(async (e, t, n, r, i) => {
92
- let a = b.getState().sandboxesByMode[n]?.sandboxId ?? null, o = async (e) => {
93
- if (Ut.current.isFresh(e)) return !0;
94
+ let K = y((e, t, n, r) => {
95
+ F(e, n, t, null, r);
96
+ }, [F]), ln = y(async (e, t, n, r, a) => {
97
+ let o = v.getState().sandboxesByMode[n]?.sandboxId ?? null, ee = async (e) => {
98
+ if (W.current.isFresh(e)) return !0;
94
99
  try {
95
- return await h(e, r, i, 3e5), await m(e, r, n, i, 9e4), Ut.current.markVerified(e), !0;
100
+ return await oe(e, r, a, 3e5), await f(e, r, n, a, 9e4), W.current.markVerified(e), !0;
96
101
  } catch {
97
- return Ut.current.invalidate(e), Wt.current.add(e), !1;
102
+ return W.current.invalidate(e), on.current.add(e), !1;
98
103
  }
99
104
  };
100
- if (a && (z(n, a, "provisioning"), K(e, t, "provisioning", "reusingEnvironment"), await o(a) || (z(n, null, "provisioning"), a = null)), !a) {
105
+ if (o && (I(n, o, "provisioning"), K(e, t, "provisioning", "reusingEnvironment"), await ee(o) || (I(n, null, "provisioning"), o = null)), !o) {
101
106
  K(e, t, "provisioning", "lookingForEnvironment");
102
- let s = await u(r, D, n, $e(), i, Wt.current);
103
- s && (z(n, s, "provisioning"), K(e, t, "provisioning", "reusingEnvironment"), await o(s) ? a = s : z(n, null, "provisioning"));
107
+ let i = await te(r, T, n, lt(), a, on.current);
108
+ i && (I(n, i, "provisioning"), K(e, t, "provisioning", "reusingEnvironment"), await ee(i) ? o = i : I(n, null, "provisioning"));
104
109
  }
105
- if (!a) {
106
- if (n === "api-calls" && !k()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
107
- K(e, t, "provisioning", "startingEnvironment"), z(n, null, "provisioning"), await p(r, D, n, $e(), i, Wt.current), a = await s(D, n, r, $e(), rt, i), z(n, a, "provisioning"), await h(a, r, i, 3e5), await m(a, r, n, i, 9e4);
110
+ if (!o) {
111
+ if (n === "api-calls" && !D()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
112
+ K(e, t, "provisioning", "startingEnvironment"), I(n, null, "provisioning");
113
+ let c = await d(r, T, n, lt(), a, on.current);
114
+ if (c.length > 0) {
115
+ let e = new Set(c);
116
+ for (let e of c) W.current.invalidate(e), on.current.add(e);
117
+ let t = v.getState().sandboxesByMode;
118
+ for (let [n, r] of Object.entries(t)) i(n) && r?.sandboxId && e.has(r.sandboxId) && Rt(n);
119
+ }
120
+ o = await s(T, n, r, lt(), pt, a), I(n, o, "provisioning"), await oe(o, r, a, 3e5), await f(o, r, n, a, 9e4);
108
121
  }
109
- z(n, a, "running");
110
- let l = b.getState().conversations.find((t) => t.id === e)?.backendSessionId ?? null;
122
+ I(n, o, "running");
123
+ let l = v.getState().conversations.find((t) => t.id === e)?.backendSessionId ?? null, ne = !1;
111
124
  if (l) try {
112
- let e = await d(a, r, l, n, i);
125
+ let e = await u(o, r, l, n, a);
113
126
  if (e.mode !== n) throw Error(`Session mode mismatch: expected ${n}, received ${e.mode}`);
114
127
  } catch {
115
- Et(e), l = null;
128
+ Lt(e), l = null;
116
129
  }
117
- return l || (K(e, t, "connecting", "preparingSession"), l = (await c(a, r, n, i)).sessionId, Tt(e, l)), {
118
- sandboxId: a,
119
- sessionId: l
130
+ return l || (K(e, t, "connecting", "preparingSession"), l = (await c(o, r, n, a)).sessionId, It(e, l), ne = !0), {
131
+ sandboxId: o,
132
+ sessionId: l,
133
+ sessionIsNew: ne
120
134
  };
121
135
  }, [
122
- Et,
123
- k,
136
+ Lt,
137
+ Rt,
124
138
  D,
125
- Tt,
126
- z,
139
+ T,
140
+ It,
141
+ I,
127
142
  K
128
- ]), [Jt, Yt] = tt(null), q = w(/* @__PURE__ */ new Set()), Xt = w(null), Zt = x(() => {
129
- let e = b.getState(), t = e.activeConversationId;
143
+ ]), [un, dn] = dt(null), q = S(/* @__PURE__ */ new Set()), fn = S(null), pn = y(() => {
144
+ let e = v.getState(), t = e.activeConversationId;
130
145
  if (!t) return;
131
- let n = e.processingByConversationId[t], r = Te(n?.status) ? n?.messageId ?? null : null;
132
- if (!De({
146
+ let n = e.processingByConversationId[t], r = Le(n?.status) ? n?.messageId ?? null : null;
147
+ if (!ze({
133
148
  interruptedTurnId: r,
134
149
  activeTurnId: r,
135
150
  alreadyRequested: r ? q.current.has(r) : !1
136
151
  }).send || !r) return;
137
152
  q.current.add(r);
138
- let i = we(e), o = Fe(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
153
+ let i = Ie(e), o = qe(), s = e.conversations.find((e) => e.id === t)?.backendSessionId;
139
154
  !i || !o || !s || a(i.sandboxId, o, s, i.mode, {
140
- accessToken: k(),
141
- workspaceToken: A(),
142
- userId: j,
143
- organizationId: Pe()
155
+ accessToken: D(),
156
+ workspaceToken: O(),
157
+ userId: k,
158
+ organizationId: Ke()
144
159
  });
145
160
  }, [
146
- j,
147
161
  k,
148
- A
149
- ]), Qt = x(async (e) => {
150
- let t = b.getState(), n = we(t), r = Fe(), i = t.activeConversationId;
162
+ D,
163
+ O
164
+ ]), mn = y(async (e) => {
165
+ let t = v.getState(), n = Ie(t), r = qe(), i = t.activeConversationId;
151
166
  if (!(!n || !r || !i)) {
152
- Yt(e);
167
+ dn(e);
153
168
  try {
154
169
  await o(n.sandboxId, r, e, n.mode, {
155
- accessToken: k(),
156
- workspaceToken: A(),
157
- userId: j,
158
- organizationId: Pe()
170
+ accessToken: D(),
171
+ workspaceToken: O(),
172
+ userId: k,
173
+ organizationId: Ke()
159
174
  });
160
175
  } catch (e) {
161
- Yt(null), I(i, {
162
- id: at(),
176
+ dn(null), P(i, {
177
+ id: ht(),
163
178
  role: "system",
164
179
  content: e instanceof Error ? e.message : "The change could not be approved.",
165
180
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
166
181
  });
167
182
  return;
168
183
  }
169
- Yt(null), Y.current(E("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
184
+ dn(null), Y.current(w("pendingWrite.approvedPrompt", "I approved that change — go ahead."));
170
185
  }
171
186
  }, [
172
- j,
173
- I,
174
- E
175
- ]), J = x(async (e, t = [], n = {}) => {
176
- let r = n.voiceSessionId !== void 0, a = b.getState(), o = a.activeConversationId ?? M;
177
- if (o) {
178
- if (Te(a.processingByConversationId[o]?.status)) {
179
- let r = a.processingByConversationId[o]?.messageId ?? null;
180
- r && q.current.has(r) && (Xt.current = {
181
- conversationId: o,
187
+ k,
188
+ P,
189
+ w
190
+ ]), J = y(async (e, t = [], n = {}) => {
191
+ let r = n.voiceSessionId !== void 0, i = v.getState(), a = i.activeConversationId ?? A;
192
+ if (a) {
193
+ if (Le(i.processingByConversationId[a]?.status)) {
194
+ let r = i.processingByConversationId[a]?.messageId ?? null;
195
+ r && q.current.has(r) && (fn.current = {
196
+ conversationId: a,
182
197
  content: e,
183
198
  attachments: t,
184
199
  options: n
185
200
  });
186
201
  return;
187
202
  }
188
- if (Gt.current.has(o)) return;
203
+ if (sn.current.has(a)) return;
204
+ }
205
+ if (H.current) return;
206
+ let o = i.activeConversationId ? i.conversations.find((e) => e.id === i.activeConversationId) : void 0, s = i.autoRouting && $t.current ? Fe({
207
+ intent: n.autoIntent ?? Me(e),
208
+ dictated: r,
209
+ conversation: o ? {
210
+ mode: o.mode,
211
+ routedBy: o.routedBy,
212
+ hasHistory: o.messages.length > 0 || !!o.backendSessionId
213
+ } : null
214
+ }) : null;
215
+ if (s && Yt.current.find((e) => e.id === s.mode)?.writeCapable && !De(i.acknowledgedWriteModes, s.mode)) {
216
+ H.current = {
217
+ content: e,
218
+ attachments: t,
219
+ options: n
220
+ }, tn(s.mode);
221
+ return;
189
222
  }
190
- let s = a.mode, c, u, d = M, p = d ? b.getState().conversations.find((e) => e.id === d) : void 0;
191
- if (d ? p && p.mode !== s && (p.messages.length > 0 || p.backendSessionId) ? d = F(void 0, s) : p && p.mode !== s && bt(d, s) : d = F(void 0, s), !d) return;
192
- Ht.current[d] = t;
193
- let m = Fe(), h = {
194
- accessToken: k(),
195
- workspaceToken: A(),
196
- userId: j,
197
- organizationId: Pe()
198
- }, g = {
199
- id: at(),
223
+ let c = s ? s.mode : i.mode, te, u, d = A, f = d ? v.getState().conversations.find((e) => e.id === d) : void 0, oe = s?.action === "escalate" && o ? {
224
+ mode: o.mode,
225
+ backendSessionId: o.backendSessionId ?? null
226
+ } : null;
227
+ if (s) s.action === "new" || !o ? d = N(void 0, c, { routedBy: "auto" }) : (d = o.id, L(d, c));
228
+ else {
229
+ let e = i.autoRouting ? { routedBy: "auto" } : void 0;
230
+ d ? f && f.mode !== c && (f.messages.length > 0 || f.backendSessionId) ? d = N(void 0, c, e) : f && f.mode !== c && (e ? L(d, c) : At(d, c)) : d = N(void 0, c, e);
231
+ }
232
+ if (!d) return;
233
+ an.current[d] = t;
234
+ let p = qe(), h = {
235
+ accessToken: D(),
236
+ workspaceToken: O(),
237
+ userId: k,
238
+ organizationId: Ke()
239
+ }, ue = {
240
+ id: ht(),
200
241
  role: "user",
201
242
  content: e,
202
243
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
203
244
  metadata: {
204
- ...t.length ? { attachments: t.map(ve) } : {},
205
- ..._(n.voiceSessionId)
245
+ ...t.length ? { attachments: t.map(be) } : {},
246
+ ...m(n.voiceSessionId)
206
247
  }
207
248
  };
208
- I(d, g);
209
- let v = at();
210
- I(d, {
211
- id: v,
249
+ P(d, ue);
250
+ let g = ht();
251
+ P(d, {
252
+ id: g,
212
253
  role: "assistant",
213
254
  content: "",
214
255
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
215
256
  metadata: {
216
- lang: _t,
217
- ..._(n.voiceSessionId)
257
+ lang: Dt,
258
+ ...m(n.voiceSessionId)
218
259
  }
219
- }), R(d, "provisioning", v, null);
220
- let se = (e, t, r, i, a = _t) => {
221
- L(d, v, { content: ae(e) }), Ct(d, v, {
260
+ }), F(d, "provisioning", g, null);
261
+ let de = (e, t, r, i, a = Dt) => {
262
+ Nt(d, g, { content: ce(e) }), Pt(d, g, {
222
263
  lang: a,
223
264
  ...t?.length ? { artifacts: t } : {},
224
- ...t?.length || r || i ? { mode: s } : {},
265
+ ...t?.length || r || i ? { mode: c } : {},
225
266
  ...r ? { sessionId: r } : {},
226
267
  ...i ? { sandboxId: i } : {},
227
- ..._(n.voiceSessionId)
268
+ ...m(n.voiceSessionId)
228
269
  });
229
- }, ce = async (n = 1) => {
270
+ }, pe = async (n = 1) => {
230
271
  let i = !1;
231
272
  try {
232
- let { sandboxId: n, sessionId: a } = await qt(d, v, s, m, h), o = (await te(n, m, a, s, h, { limit: 50 }).catch(() => [])).reduce((e, t) => Math.max(e, ie(t)), 0);
233
- K(d, v, "streaming", "thinking");
234
- let f = ct?.(), { prompt: p, parts: g } = xe({
235
- content: e,
273
+ let { sandboxId: n, sessionId: a, sessionIsNew: o } = await ln(d, g, c, p, h), s = Ae(v.getState().conversations.find((e) => e.id === d), e, o), re = (await ne(n, p, a, c, h, { limit: 50 }).catch(() => [])).reduce((e, t) => Math.max(e, se(t)), 0);
274
+ K(d, g, "streaming", "thinking");
275
+ let f = vt?.(), { prompt: oe, parts: m } = Ee({
276
+ content: s ? `${s}${e}` : e,
236
277
  attachments: t,
237
- limits: _e(c),
238
- wrapPrompt: (e) => lt?.(s, e, ht, gt, r) ?? e,
239
- requestBytes: (e, t) => ne({
278
+ limits: ye(te),
279
+ wrapPrompt: (e) => yt?.(c, e, Tt, Et, r) ?? e,
280
+ requestBytes: (e, t) => ie({
240
281
  sandboxId: n,
241
- workspaceId: m,
282
+ workspaceId: p,
242
283
  sessionId: a,
243
- mode: s,
284
+ mode: c,
244
285
  prompt: e,
245
286
  parts: t,
246
287
  pageContext: f,
247
288
  authContext: h
248
289
  })
249
- }), _ = me(g), ce = _ > 0;
250
- i = pe(t) > _;
290
+ }), ue = ge(m), pe = ue > 0;
291
+ i = he(t) > ue;
251
292
  try {
252
- await re(n, m, a, p, s, f, h, g?.length ? { parts: g } : void 0);
293
+ await ae(n, p, a, oe, c, f, h, m?.length ? { parts: m } : void 0);
253
294
  } catch (e) {
254
- if (!g || !Ge(e)) throw e;
255
- await re(n, m, a, p, s, f, h, void 0), i ||= ce;
295
+ if (!m || !rt(e)) throw e;
296
+ await ae(n, p, a, oe, c, f, h, void 0), i ||= pe;
256
297
  }
257
- let y = ke([], o), ue = Date.now() + u.streamBudgetMs, de = Date.now(), fe = Date.now(), he = () => Ee({
258
- turnId: v,
259
- abortRequested: q.current.has(v),
260
- activeTurnId: b.getState().processingByConversationId[d]?.messageId ?? null
298
+ let _ = Ve([], re), me = Date.now() + u.streamBudgetMs, _e = Date.now(), ve = Date.now(), be = () => Re({
299
+ turnId: g,
300
+ abortRequested: q.current.has(g),
301
+ activeTurnId: v.getState().processingByConversationId[d]?.messageId ?? null
261
302
  });
262
- for (; Date.now() < ue;) {
263
- let e = he();
303
+ for (; Date.now() < me;) {
304
+ let e = be();
264
305
  if (e.abandon) {
265
- e.clearProcessing && wt(d);
306
+ e.clearProcessing && Ft(d);
266
307
  return;
267
308
  }
268
- if (y = ke(await te(n, m, a, s, h, {
309
+ if (_ = Ve(await ne(n, p, a, c, h, {
269
310
  limit: 50,
270
- sinceMs: o
271
- }), o, { accumulateNarration: u.accumulatesNarration }), L(d, v, { content: ae(y.content) }), y.pendingWrite && Ct(d, v, { pendingWrite: y.pendingWrite }), y.done) break;
272
- Date.now() - de > 3e4 && (await l(n, m, 600, h).catch(() => void 0), de = Date.now()), await new Promise((e) => setTimeout(e, le(Date.now() - fe)));
311
+ sinceMs: re
312
+ }), re, { accumulateNarration: u.accumulatesNarration }), Nt(d, g, { content: ce(_.content) }), _.pendingWrite && Pt(d, g, { pendingWrite: _.pendingWrite }), _.done) break;
313
+ Date.now() - _e > 3e4 && (await ee(n, p, 600, h).catch(() => void 0), _e = Date.now()), await new Promise((e) => setTimeout(e, fe(Date.now() - ve)));
273
314
  }
274
- let ge = u.producesArtifacts ? await ee(n, m, a, s, h).then((e) => e).catch(() => []) : void 0;
275
- if (y.done || (y = {
276
- ...y,
277
- content: oe(y.content, s, E, c)
278
- }), i && (y = {
279
- ...y,
280
- content: `${y.content}\n\n${E("attachments.imagesNotSent", "_Your photo was too large to include with this message, so the answer above is from the text and the file link only. Try a smaller or more tightly cropped photo._")}`
281
- }), se(y.content, ge, a, n), y.tokens) {
282
- L(d, v, { tokens: y.tokens });
315
+ let xe = u.producesArtifacts ? await l(n, p, a, c, h).then((e) => e).catch(() => []) : void 0;
316
+ if (_.done || (_ = {
317
+ ..._,
318
+ content: le(_.content, c, w, te)
319
+ }), i && (_ = {
320
+ ..._,
321
+ content: `${_.content}\n\n${w("attachments.imagesNotSent", "_Your photo was too large to include with this message, so the answer above is from the text and the file link only. Try a smaller or more tightly cropped photo._")}`
322
+ }), de(_.content, xe, a, n), _.tokens) {
323
+ Nt(d, g, { tokens: _.tokens });
283
324
  try {
284
- await ut?.({
285
- workspaceId: m,
325
+ await bt?.({
326
+ workspaceId: p,
286
327
  sessionId: a,
287
- messageId: y.messageId,
288
- model: y.model,
289
- tokens: y.tokens
290
- }), Xe(D);
328
+ messageId: _.messageId,
329
+ model: _.model,
330
+ tokens: _.tokens
331
+ }), ot(T);
291
332
  } catch {}
292
333
  }
293
- let ve = he();
294
- if (ve.abandon) {
295
- ve.clearProcessing && wt(d);
334
+ let Se = be();
335
+ if (Se.abandon) {
336
+ Se.clearProcessing && Ft(d);
296
337
  return;
297
338
  }
298
- R(d, "complete", v, null);
339
+ F(d, "complete", g, null);
299
340
  } catch (e) {
300
- let t = Ee({
301
- turnId: v,
302
- abortRequested: q.current.has(v),
303
- activeTurnId: b.getState().processingByConversationId[d]?.messageId ?? null
341
+ let t = Re({
342
+ turnId: g,
343
+ abortRequested: q.current.has(g),
344
+ activeTurnId: v.getState().processingByConversationId[d]?.messageId ?? null
304
345
  });
305
346
  if (t.abandon) {
306
- t.clearProcessing && wt(d);
347
+ t.clearProcessing && Ft(d);
307
348
  return;
308
349
  }
309
- if (n === 1 && Ke(e)) {
310
- let e = b.getState().sandboxesByMode[s]?.sandboxId ?? null;
311
- return e && (Wt.current.add(e), Ut.current.invalidate(e)), Et(d), Dt(s), St(d, v, ""), Ct(d, v, { pendingWrite: void 0 }), ce(2);
350
+ if (n === 1 && it(e)) {
351
+ let e = v.getState().sandboxesByMode[c]?.sandboxId ?? null;
352
+ return e && (on.current.add(e), W.current.invalidate(e)), Lt(d), Rt(c), Mt(d, g, ""), Pt(d, g, { pendingWrite: void 0 }), pe(2);
312
353
  }
313
354
  throw e;
314
355
  }
315
- }, y = d;
316
- Gt.current.add(y);
356
+ }, _ = d;
357
+ sn.current.add(_);
317
358
  try {
318
- if (!m) throw Error("Assistant backend is unavailable without an active workspace context.");
319
- let e = await be(s, () => It.current.find((e) => e.id === s), U);
320
- c = e.config, u = e.capabilities;
321
- let t = Ce(s, c, b.getState().acknowledgedWriteModes, {
359
+ if (!p) throw Object.assign(/* @__PURE__ */ Error("Assistant backend is unavailable without an active workspace context."), { extensions: {
360
+ code: "UNAUTHENTICATED",
361
+ authFailure: "WORKSPACE_CONTEXT_MISSING"
362
+ } });
363
+ let e = await Te(c, () => Yt.current.find((e) => e.id === c), V);
364
+ te = e.config, u = e.capabilities;
365
+ let t = Oe(c, te, v.getState().acknowledgedWriteModes, {
322
366
  dictated: r,
323
- confirmsWrites: f(s)
367
+ confirmsWrites: re(c)
324
368
  });
325
- if (t) throw Error(t);
326
- await ce();
369
+ if (t) throw new xe(t, t === "confirm-write-mode" ? "Write mode not confirmed" : "Voice in a write mode");
370
+ await pe();
327
371
  } catch (e) {
328
- Ut.current.invalidate(b.getState().sandboxesByMode[s]?.sandboxId ?? null);
329
- let t = i(e);
330
- if (t) {
331
- t.refusal === "exhausted" && Ye(D, "sandbox");
332
- let e = [t.quotaName, t.traceId ? `reference ${t.traceId}` : null].filter(Boolean).join(" · "), n = t.refusal === "exhausted" ? "You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant." : "This workspace has no sandbox allowance provisioned, so the AI assistant cannot start. Upgrading will not help — ask an administrator to provision it.";
333
- se(e ? `${n}\n\n${e}` : n, void 0, void 0, void 0, "en"), R(d, "error", v, null);
334
- return;
335
- }
336
- let r = qe(e);
337
- if (r) {
338
- let e = Je(r);
339
- R(d, "error", v, e), L(d, v, { content: e }), Ct(d, v, {
340
- lang: "en",
341
- ..._(n.voiceSessionId)
342
- });
343
- return;
344
- }
345
- let a = e instanceof Error ? e.message : "Something went wrong";
346
- R(d, "error", v, a), L(d, v, { content: `Sorry, an error occurred: ${a}. Please try again.` }), Ct(d, v, {
347
- lang: "en",
348
- ..._(n.voiceSessionId)
372
+ W.current.invalidate(v.getState().sandboxesByMode[c]?.sandboxId ?? null);
373
+ let t = Se(e);
374
+ t.offersUpgrade && at(T, "sandbox");
375
+ let r = Ce(t, w);
376
+ F(d, "error", g, r.headline), Nt(d, g, { content: r.text }), Pt(d, g, {
377
+ lang: r.translated ? xt : "en",
378
+ ...m(n.voiceSessionId)
349
379
  });
350
380
  } finally {
351
- Gt.current.delete(y);
352
- let e = Xt.current;
353
- Xt.current = null, e && e.conversationId === y && Y.current(e.content, e.attachments, e.options);
381
+ sn.current.delete(_);
382
+ let e = v.getState(), t = Ne(oe, c, e.conversations.find((e) => e.id === _), (t) => !!e.sandboxesByMode[t]?.sandboxId);
383
+ t && (L(_, t.mode), t.backendSessionId && It(_, t.backendSessionId));
384
+ let n = fn.current;
385
+ fn.current = null, n && n.conversationId === _ && Y.current(n.content, n.attachments, n.options);
354
386
  }
355
387
  }, [
356
- M,
357
- I,
358
- lt,
359
- Et,
360
- Dt,
361
- vt,
362
- F,
363
- qt,
364
- ct,
365
- k,
366
388
  A,
367
- L,
389
+ P,
390
+ yt,
391
+ Lt,
392
+ Rt,
393
+ Ot,
394
+ N,
395
+ ln,
396
+ vt,
368
397
  D,
369
- U,
370
- ut,
371
- gt,
372
- _t,
373
- ht,
374
- Tt,
398
+ O,
399
+ Nt,
400
+ T,
401
+ V,
375
402
  bt,
376
- R,
377
- wt,
378
- E,
403
+ Et,
404
+ xt,
405
+ Dt,
406
+ Tt,
407
+ L,
408
+ It,
409
+ At,
410
+ F,
411
+ Ft,
412
+ w,
379
413
  K,
380
- St,
381
- j
382
- ]), $t = x((e) => {
383
- J(e);
384
- }, [J]), en = x(() => {
385
- let e = [...B.chat].reverse().find((e) => e.role === "user"), t = M ? Ht.current[M] ?? [] : [];
414
+ Mt,
415
+ k
416
+ ]), hn = y((e, t) => {
417
+ J(e, [], t ? { autoIntent: t } : {});
418
+ }, [J]), gn = y(() => {
419
+ let e = [...R.chat].reverse().find((e) => e.role === "user"), t = A ? an.current[A] ?? [] : [];
386
420
  e && J(e.content, t);
387
421
  }, [
388
- jt,
422
+ Wt,
389
423
  J,
390
- M
391
- ]), Y = w(J);
392
- S(() => {
424
+ A
425
+ ]), Y = S(J);
426
+ b(() => {
393
427
  Y.current = J;
394
428
  }, [J]);
395
- let tn = C(() => {
396
- if (Mt) return null;
397
- for (let e = jt.length - 1; e >= 0; --e) {
398
- let t = jt[e];
399
- if (t?.role !== "assistant" || !g(t) || q.current.has(t.id)) continue;
400
- let n = Oe(t, V, E);
429
+ let _n = x(() => {
430
+ if (Gt) return null;
431
+ for (let e = Wt.length - 1; e >= 0; --e) {
432
+ let t = Wt[e];
433
+ if (t?.role !== "assistant" || !p(t) || q.current.has(t.id)) continue;
434
+ let n = Be(t, z, w);
401
435
  if (n.kind !== "output") return null;
402
- let r = Ae(n.text).text.trim();
436
+ let r = He(n.text).text.trim();
403
437
  return r ? {
404
438
  id: t.id,
405
439
  text: r
@@ -407,176 +441,218 @@ var ot = ({ visible: ot = !0, writeAccess: st = "unknown" }) => {
407
441
  }
408
442
  return null;
409
443
  }, [
410
- jt,
411
- Mt,
412
- V,
413
- E
414
- ]), nn = C(() => tn ? ue(tn.text) : null, [tn]), rn = B.chat, X = C(() => B.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
444
+ Wt,
445
+ Gt,
446
+ z,
447
+ w
448
+ ]), vn = x(() => _n ? pe(_n.text) : null, [_n]), yn = R.chat, X = x(() => R.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
415
449
  id: e.id,
416
450
  role: e.role,
417
- text: Me(e, V, E),
418
- sessionId: v(e),
451
+ text: We(e, z, w),
452
+ sessionId: h(e),
419
453
  timestamp: e.timestamp
420
454
  })).filter((e) => e.text.length > 0), [
421
- B.voice,
422
- V,
423
- E
424
- ]), an = x(() => {
455
+ R.voice,
456
+ z,
457
+ w
458
+ ]), bn = y(() => {
425
459
  if (X.length === 0) return;
426
460
  let e = /* @__PURE__ */ new Date();
427
- ze(ce(X, {
428
- title: E("voiceSession.transcript", "Voice conversation"),
429
- savedAt: E("voiceSession.savedAt", "Saved"),
430
- session: E("voiceSession.sessionLabel", "Session"),
431
- earlier: E("voiceSession.earlierLabel", "Earlier"),
432
- you: E("voiceSession.speakerYou", "You"),
433
- assistant: E("voiceSession.speakerAssistant", "Assistant")
434
- }, e), y(D, e), "text/markdown");
461
+ Ze(g(X, {
462
+ title: w("voiceSession.transcript", "Voice conversation"),
463
+ savedAt: w("voiceSession.savedAt", "Saved"),
464
+ session: w("voiceSession.sessionLabel", "Session"),
465
+ earlier: w("voiceSession.earlierLabel", "Earlier"),
466
+ you: w("voiceSession.speakerYou", "You"),
467
+ assistant: w("voiceSession.speakerAssistant", "Assistant")
468
+ }, e), de(T, e), "text/markdown");
435
469
  }, [
436
- D,
470
+ T,
437
471
  X,
438
- E
439
- ]), Z = Ze({ perFileChars: Rt }), on = w(Z);
440
- on.current = Z;
441
- let Q = Ne({
442
- onSubmit: x((e, t) => {
472
+ w
473
+ ]), Z = st({ perFileChars: en }), xn = S(Z);
474
+ xn.current = Z;
475
+ let Q = Ge({
476
+ onSubmit: y((e, t) => {
443
477
  let n = () => {
444
- let n = on.current, r = he(n.attachments);
478
+ let n = xn.current, r = _e(n.attachments);
445
479
  Y.current(e, r, { voiceSessionId: t }), n.clear();
446
480
  };
447
- if (!on.current.isBusy) {
481
+ if (!xn.current.isBusy) {
448
482
  n();
449
483
  return;
450
484
  }
451
485
  let r = Date.now(), i = window.setInterval(() => {
452
- on.current.isBusy && Date.now() - r < it || (window.clearInterval(i), n());
486
+ xn.current.isBusy && Date.now() - r < mt || (window.clearInterval(i), n());
453
487
  }, 200);
454
488
  }, []),
455
- latestReply: tn,
456
- language: de(ft, dt).tag
457
- }), sn = C(() => (At?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [At?.messages]), $ = je(B.voice, V, E), cn = $ > sn, ln = x(() => {
458
- let e = b.getState().activeConversationId;
459
- !e || X.length === 0 || (I(e, {
460
- id: at(),
489
+ latestReply: _n,
490
+ language: _(St, xt).tag
491
+ }), Sn = x(() => (Ut?.messages ?? []).reduce((e, t) => Math.max(e, t.metadata?.continuedVoiceTurns ?? 0), 0), [Ut?.messages]), $ = Ue(R.voice, z, w), Cn = $ > Sn, wn = y(() => {
492
+ let e = v.getState().activeConversationId;
493
+ !e || X.length === 0 || (P(e, {
494
+ id: ht(),
461
495
  role: "system",
462
- content: se(X.slice(sn), {
463
- intro: E("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
464
- nothing: E("voiceSession.continuedNothing", "Continued from a voice conversation."),
465
- more: (e) => E("voiceSession.continuedMore", "…and {{count}} more", { count: e })
496
+ content: ue(X.slice(Sn), {
497
+ intro: w("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
498
+ nothing: w("voiceSession.continuedNothing", "Continued from a voice conversation."),
499
+ more: (e) => w("voiceSession.continuedMore", "…and {{count}} more", { count: e })
466
500
  }),
467
501
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
468
502
  metadata: { continuedVoiceTurns: $ }
469
- }), Vt(!1), Q.end());
503
+ }), rn(!1), Q.end());
470
504
  }, [
471
505
  X,
472
506
  $,
473
- sn,
474
- I,
475
- E,
507
+ Sn,
508
+ P,
509
+ w,
476
510
  Q
477
- ]), un = w(0);
478
- S(() => {
479
- Q.active && (un.current = $);
511
+ ]), Tn = S(0);
512
+ b(() => {
513
+ Q.active && (Tn.current = $);
480
514
  }, [Q.active]);
481
- let dn = x(() => {
482
- let e = $ > un.current;
483
- Q.end(), e && Vt(!0);
515
+ let En = y(() => {
516
+ let e = $ > Tn.current;
517
+ Q.end(), e && rn(!0);
484
518
  }, [$, Q]);
485
- S(() => {
486
- (!ot || !Kt) && Q.active && Q.end();
519
+ b(() => {
520
+ (!gt || !cn) && Q.active && Q.end();
487
521
  }, [
488
- ot,
489
- Kt,
522
+ gt,
523
+ cn,
490
524
  Q
491
- ]), S(() => {
492
- Q.active || (on.current.clear(), Xt.current = null);
493
- }, [Q.active]), S(() => {
494
- let e = b.getState().consumePendingPrompt();
495
- return e && Y.current(e), b.subscribe((e, t) => {
525
+ ]), b(() => {
526
+ Q.active || (xn.current.clear(), fn.current = null);
527
+ }, [Q.active]), b(() => {
528
+ let e = v.getState().consumePendingPrompt();
529
+ return e && Y.current(e), v.subscribe((e, t) => {
496
530
  if (e.pendingPrompt && e.pendingPrompt !== t.pendingPrompt) {
497
- let e = b.getState().consumePendingPrompt();
531
+ let e = v.getState().consumePendingPrompt();
498
532
  e && Y.current(e);
499
533
  }
500
534
  });
501
535
  }, []);
502
- let fn = x((e) => {
503
- let t = M ? b.getState().conversations.find((e) => e.id === M) : void 0;
536
+ let Dn = y((e) => {
537
+ let t = A ? v.getState().conversations.find((e) => e.id === A) : void 0;
504
538
  if (t && (t.messages.length > 0 || t.backendSessionId)) {
505
539
  if (t.mode !== e) {
506
- let t = b.getState().conversations.find((t) => t.mode === e && t.messages.length === 0 && !t.backendSessionId && !b.getState().processingByConversationId[t.id]);
507
- t ? xt(t.id) : F(void 0, e);
540
+ let t = v.getState().conversations.find((t) => t.mode === e && t.messages.length === 0 && !t.backendSessionId && !v.getState().processingByConversationId[t.id]);
541
+ t ? jt(t.id) : N(void 0, e);
508
542
  }
509
- } else M && bt(M, e);
510
- P(e);
543
+ } else A && At(A, e);
544
+ let n = v.getState().activeConversationId;
545
+ n ? At(n, e) : Ht(!1), M(e);
511
546
  }, [
512
- M,
513
- F,
514
- xt,
515
- bt,
516
- P
517
- ]), pn = x((e) => {
518
- if (O.find((t) => t.id === e)?.writeCapable && !Se(b.getState().acknowledgedWriteModes, e)) {
519
- zt(e);
547
+ A,
548
+ N,
549
+ jt,
550
+ Ht,
551
+ At,
552
+ M
553
+ ]), On = y(() => {
554
+ let e = v.getState(), t = e.activeConversationId ? e.conversations.find((t) => t.id === e.activeConversationId) : void 0;
555
+ if (!t) {
556
+ Ht(!0), M(ke);
520
557
  return;
521
558
  }
522
- fn(e);
523
- }, [fn, O]), mn = x(() => {
524
- let e = W;
525
- zt(null), e && (kt(e), fn(e));
559
+ if (t.routedBy === "auto") {
560
+ Ht(!0);
561
+ return;
562
+ }
563
+ if (t.messages.length === 0 && !t.backendSessionId) {
564
+ L(t.id, ke);
565
+ return;
566
+ }
567
+ let n = e.conversations.find((t) => t.routedBy === "auto" && t.messages.length === 0 && !t.backendSessionId && !e.processingByConversationId[t.id]);
568
+ n ? (jt(n.id), L(n.id, ke)) : N(void 0, ke, { routedBy: "auto" });
526
569
  }, [
527
- W,
528
- kt,
529
- fn
530
- ]), hn = W === null ? void 0 : O.find((e) => e.id === W) ?? { id: W }, gn = x(() => {
531
- zt(null);
532
- }, []);
533
- return /* @__PURE__ */ nt("div", {
570
+ N,
571
+ L,
572
+ jt,
573
+ Ht,
574
+ M
575
+ ]), kn = y((e) => {
576
+ if (E.find((t) => t.id === e)?.writeCapable && !De(v.getState().acknowledgedWriteModes, e)) {
577
+ tn(e);
578
+ return;
579
+ }
580
+ Dn(e);
581
+ }, [Dn, E]), An = y(() => {
582
+ let e = U;
583
+ if (tn(null), !e) return;
584
+ let t = H.current;
585
+ if (H.current = null, t) {
586
+ Bt(e), J(t.content, t.attachments, t.options);
587
+ return;
588
+ }
589
+ Bt(e), Dn(e);
590
+ }, [
591
+ U,
592
+ Bt,
593
+ Dn,
594
+ J
595
+ ]), jn = U === null ? void 0 : E.find((e) => e.id === U) ?? { id: U }, Mn = y(() => {
596
+ tn(null);
597
+ let e = H.current;
598
+ H.current = null, e && J(e.content, e.attachments, {
599
+ ...e.options,
600
+ autoIntent: "read"
601
+ });
602
+ }, [J]);
603
+ return /* @__PURE__ */ ft("div", {
534
604
  className: "relative flex flex-1 flex-col overflow-hidden",
535
605
  children: [
536
- /* @__PURE__ */ nt("div", {
606
+ /* @__PURE__ */ ft("div", {
537
607
  className: "contents",
538
608
  inert: Q.active || void 0,
539
609
  children: [
540
- X.length > 0 && !Q.active ? /* @__PURE__ */ T(Le, {
610
+ X.length > 0 && !Q.active ? /* @__PURE__ */ C(Ye, {
541
611
  count: X.length,
542
- onOpenTranscript: () => Vt(!0)
612
+ onOpenTranscript: () => rn(!0)
543
613
  }) : null,
544
- rn.length === 0 ? /* @__PURE__ */ T(Be, {
545
- mode: N,
546
- onSuggestionClick: $t
547
- }) : /* @__PURE__ */ T("div", {
614
+ yn.length === 0 ? /* @__PURE__ */ C(Qe, {
615
+ mode: j,
616
+ onSuggestionClick: hn,
617
+ explainsAuto: Qt,
618
+ suggestions: Qt && j === "assistant" ? je(E.find((e) => e.id === "assistant")?.suggestions ?? [], E.find((e) => e.id === "api-calls")?.suggestions ?? []) : void 0
619
+ }) : /* @__PURE__ */ C("div", {
548
620
  className: "flex min-h-0 flex-1 flex-col",
549
- children: /* @__PURE__ */ T(Ve, {
550
- onApprovePendingWrite: Qt,
551
- approvingWriteRef: Jt,
552
- messages: rn,
553
- processing: V ?? null,
554
- streamingMessageId: Nt,
555
- failedMessageId: Pt,
556
- onRetry: en
621
+ children: /* @__PURE__ */ C($e, {
622
+ onApprovePendingWrite: mn,
623
+ approvingWriteRef: un,
624
+ messages: yn,
625
+ processing: z ?? null,
626
+ streamingMessageId: Kt,
627
+ failedMessageId: qt,
628
+ onRetry: gn
557
629
  })
558
630
  }),
559
- /* @__PURE__ */ T(Qe, {
560
- onStartVoiceSession: Q.available && Kt ? Q.start : void 0,
631
+ /* @__PURE__ */ C(ct, {
632
+ onStartVoiceSession: Q.available && cn ? Q.start : void 0,
561
633
  onSend: (e, t) => void J(e, t),
562
- disabled: Mt,
563
- placeholder: N === "api-calls" ? E("chatArea.placeholderActions", "What would you like me to do?") : E("chatArea.placeholderGeneral", "Ask me anything…"),
564
- mode: N,
565
- writeAccessDenied: st === "denied" && !!G?.writeCapable,
566
- availableModes: Lt,
567
- attachmentCharsPerFile: Rt,
568
- onModeChange: pn
634
+ disabled: Gt,
635
+ placeholder: j === "api-calls" ? w("chatArea.placeholderActions", "What would you like me to do?") : w("chatArea.placeholderGeneral", "Ask me anything…"),
636
+ mode: j,
637
+ writeAccessDenied: _t === "denied" && !!G?.writeCapable,
638
+ availableModes: Xt,
639
+ attachmentCharsPerFile: en,
640
+ onModeChange: kn,
641
+ auto: Zt ? {
642
+ active: Qt,
643
+ onSelect: On
644
+ } : void 0
569
645
  })
570
646
  ]
571
647
  }),
572
- Bt && !Q.active ? /* @__PURE__ */ T(Re, {
648
+ nn && !Q.active ? /* @__PURE__ */ C(Xe, {
573
649
  turns: X,
574
- onClose: () => Vt(!1),
575
- onSave: an,
576
- onContinueInChat: cn ? ln : void 0,
650
+ onClose: () => rn(!1),
651
+ onSave: bn,
652
+ onContinueInChat: Cn ? wn : void 0,
577
653
  closeOnEscape: !0
578
654
  }) : null,
579
- Q.active && /* @__PURE__ */ T(He, {
655
+ Q.active && /* @__PURE__ */ C(et, {
580
656
  session: Q.session,
581
657
  notice: Q.notice,
582
658
  capturing: Q.capturing,
@@ -590,24 +666,24 @@ var ot = ({ visible: ot = !0, writeAccess: st = "unknown" }) => {
590
666
  onRetryAttachment: Z.retry,
591
667
  canAttachMore: Z.canAddMore,
592
668
  preparingAttachments: Z.preparingCount,
593
- onSaveTranscript: an,
594
- onContinueInChat: ln,
669
+ onSaveTranscript: bn,
670
+ onContinueInChat: wn,
595
671
  onInterrupt: () => {
596
- Q.interrupt(), Zt();
672
+ Q.interrupt(), pn();
597
673
  },
598
- spoken: nn,
674
+ spoken: vn,
599
675
  onToggleMute: Q.toggleMute,
600
- onEnd: dn
676
+ onEnd: En
601
677
  }),
602
- /* @__PURE__ */ T(et, {
603
- open: W !== null,
604
- mode: hn,
605
- currentMode: G ?? { id: N },
606
- onConfirm: mn,
607
- onCancel: gn
678
+ /* @__PURE__ */ C(ut, {
679
+ open: U !== null,
680
+ mode: jn,
681
+ currentMode: G ?? { id: j },
682
+ onConfirm: An,
683
+ onCancel: Mn
608
684
  })
609
685
  ]
610
686
  });
611
687
  };
612
688
  //#endregion
613
- export { ot as AssistantChatArea };
689
+ export { gt as AssistantChatArea };