@burdenoff/fe-libs 2026.924.1 → 2026.924.3

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