@burdenoff/microfe-healthybowl 2026.904.16 → 2026.904.18
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.
- package/dist/components/assistant/AssistantChatArea.js +238 -247
- package/dist/components/assistant/AssistantChatArea.js.map +1 -1
- package/dist/services/assistantApi.js +5 -8
- package/dist/services/assistantApi.js.map +1 -1
- package/dist/utils/assistantContext.js +2 -38
- package/dist/utils/sandboxReadiness.js +2 -24
- package/package.json +1 -1
- package/dist/utils/assistantContext.js.map +0 -1
- package/dist/utils/sandboxReadiness.js.map +0 -1
|
@@ -1,53 +1,53 @@
|
|
|
1
1
|
import { useAssistantStore as e } from "../../store/assistantStore.js";
|
|
2
|
-
import {
|
|
3
|
-
import { gatherPageContext as
|
|
2
|
+
import { createAssistantSandbox as t, createAssistantSession as n, extendAssistantSandboxTTL as r, findExistingSandbox as i, getAssistantArtifacts as a, getAssistantMessages as o, getAssistantSession as ee, reportAssistantAiTokenUsage as s, sendAssistantPromptAsync as c, waitForAssistantServiceReady as l, waitForSandboxReady as u } from "../../services/assistantApi.js";
|
|
3
|
+
import { gatherPageContext as d } from "../../utils/pageContext.js";
|
|
4
4
|
import { resolveAssistantLanguage as f } from "../../config/assistantLanguages.js";
|
|
5
5
|
import { resolveLanguagePair as p } from "../../config/assistantLanguagePair.js";
|
|
6
6
|
import { AssistantMessageList as m } from "./AssistantMessageList.js";
|
|
7
7
|
import { AssistantApiCallsConsentDialog as h } from "./AssistantApiCallsConsentDialog.js";
|
|
8
8
|
import { AssistantEmptyState as g } from "./AssistantEmptyState.js";
|
|
9
|
-
import { AssistantSpokenTurnsNotice as
|
|
10
|
-
import { VoiceTranscriptDrawer as
|
|
11
|
-
import { getActorId as
|
|
12
|
-
import { buildPromptParts as
|
|
13
|
-
import { useAssistantAttachments as
|
|
14
|
-
import { AssistantComposer as
|
|
15
|
-
import { AssistantVoiceSession as
|
|
16
|
-
import { parseToolActivity as
|
|
17
|
-
import { useVoiceSession as
|
|
18
|
-
import { useAssistantApiAccess as
|
|
19
|
-
import { useWorkspaceWriteAccess as
|
|
20
|
-
import { isVoiceTurn as
|
|
21
|
-
import { useConversationTurns as
|
|
22
|
-
import { isQuotaExhaustedError as
|
|
23
|
-
import { dispatchAssistantQuotaExhausted as
|
|
24
|
-
import { buildPromptForMode as
|
|
25
|
-
import { isMultimodalBodyRejection as
|
|
26
|
-
import { isTurnInFlight as
|
|
27
|
-
import { ASSISTANT_MODES as
|
|
28
|
-
import { pollDelayMs as
|
|
29
|
-
import { findPendingWrite as
|
|
30
|
-
import { toCaptionText as
|
|
31
|
-
import { buildContinuedFromVoiceNote as
|
|
32
|
-
import { downloadFile as
|
|
33
|
-
import { createReadinessTracker as
|
|
34
|
-
import { useCallback as C, useEffect as w, useMemo as T, useRef as E, useState as
|
|
35
|
-
import { useI18n as
|
|
36
|
-
import { jsx as D, jsxs as
|
|
37
|
-
import { useGatewayClient as
|
|
38
|
-
import { useAuthToken as
|
|
39
|
-
import { getAssistantMedia as O, useAssistantTr as
|
|
9
|
+
import { AssistantSpokenTurnsNotice as _ } from "./AssistantSpokenTurnsNotice.js";
|
|
10
|
+
import { VoiceTranscriptDrawer as v } from "./voice/VoiceTranscriptDrawer.js";
|
|
11
|
+
import { getActorId as te, getOrganizationId as y, getWorkspaceId as ne } from "../../utils/assistantContext.js";
|
|
12
|
+
import { buildPromptParts as re, buildPromptWithAttachments as ie, countInlineImageCandidates as ae, countInlinedImageParts as oe, getSendableAttachments as b, toMessageAttachment as x } from "../../utils/assistantAttachments.js";
|
|
13
|
+
import { useAssistantAttachments as S } from "../../hooks/useAssistantAttachments.js";
|
|
14
|
+
import { AssistantComposer as se } from "./composer/AssistantComposer.js";
|
|
15
|
+
import { AssistantVoiceSession as ce } from "./voice/AssistantVoiceSession.js";
|
|
16
|
+
import { parseToolActivity as le } from "./AssistantToolActivity.js";
|
|
17
|
+
import { useVoiceSession as ue } from "../../hooks/useVoiceSession.js";
|
|
18
|
+
import { useAssistantApiAccess as de } from "../../hooks/useAssistantApiAccess.js";
|
|
19
|
+
import { useWorkspaceWriteAccess as fe } from "../../hooks/useWorkspaceWriteAccess.js";
|
|
20
|
+
import { isVoiceTurn as pe, voiceMarker as me, voiceSessionIdOf as he } from "../../utils/voiceTurnVisibility.js";
|
|
21
|
+
import { useConversationTurns as ge } from "../../hooks/useConversationTurns.js";
|
|
22
|
+
import { isQuotaExhaustedError as _e } from "../../utils/quotaUtils.js";
|
|
23
|
+
import { dispatchAssistantQuotaExhausted as ve, notifyAiCreditsUpdated as ye } from "../../utils/aiCredits.js";
|
|
24
|
+
import { buildPromptForMode as be } from "../../utils/assistantPrompt.js";
|
|
25
|
+
import { isMultimodalBodyRejection as xe, isRecoverableAssistantError as Se } from "../../utils/assistantTransportErrors.js";
|
|
26
|
+
import { isTurnInFlight as Ce } from "../../utils/assistantTurnState.js";
|
|
27
|
+
import { ASSISTANT_MODES as we } from "../../types/assistant.js";
|
|
28
|
+
import { pollDelayMs as Te } from "../../utils/assistantPollSchedule.js";
|
|
29
|
+
import { findPendingWrite as Ee } from "../../utils/pendingWrite.js";
|
|
30
|
+
import { toCaptionText as De } from "../../utils/captionText.js";
|
|
31
|
+
import { buildContinuedFromVoiceNote as Oe, buildVoiceTranscriptMarkdown as ke, voiceTranscriptFilename as Ae } from "../../utils/voiceTranscript.js";
|
|
32
|
+
import { downloadFile as je } from "../../services/assistantExportService.js";
|
|
33
|
+
import { createReadinessTracker as Me } from "../../utils/sandboxReadiness.js";
|
|
34
|
+
import { useCallback as C, useEffect as w, useMemo as T, useRef as E, useState as Ne } from "react";
|
|
35
|
+
import { useI18n as Pe } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
36
|
+
import { jsx as D, jsxs as Fe } from "react/jsx-runtime";
|
|
37
|
+
import { useGatewayClient as Ie } from "@burdenoff/fe-libs/shared/graphql";
|
|
38
|
+
import { useAuthToken as Le } from "@burdenoff/fe-libs/shared/providers/shell";
|
|
39
|
+
import { getAssistantMedia as O, useAssistantTr as Re } from "@burdenoff/fe-libs/shared/assistant";
|
|
40
40
|
//#region src/components/assistant/AssistantChatArea.tsx
|
|
41
|
-
var
|
|
41
|
+
var ze = {
|
|
42
42
|
general: 18e4,
|
|
43
43
|
assistant: 18e4,
|
|
44
44
|
"api-calls": 18e4,
|
|
45
45
|
"vibe-plugins": 6e5
|
|
46
|
-
},
|
|
47
|
-
function
|
|
46
|
+
}, Be = 18e4, Ve = 2e4;
|
|
47
|
+
function He() {
|
|
48
48
|
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
49
49
|
}
|
|
50
|
-
function
|
|
50
|
+
function Ue(e) {
|
|
51
51
|
return e.replace(/(Authorization\s*:\s*Bearer\s+)[^\s\n]+/gi, "$1[REDACTED]").replace(/(X-Workspace-Authorization\s*:\s*Bearer\s+)[^\s\n]+/gi, "$1[REDACTED]").replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9._-]+\.[A-Za-z0-9._-]+\b/g, "[REDACTED_JWT]").replace(/\bsk-ant-[A-Za-z0-9-]+\b/g, "[REDACTED_API_KEY]");
|
|
52
52
|
}
|
|
53
53
|
function k(e) {
|
|
@@ -62,13 +62,13 @@ function j(e) {
|
|
|
62
62
|
return t === "completed" ? `Completed: ${n}` : t === "failed" ? `Failed: ${n}` : `Running: ${n}`;
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function We(e, t) {
|
|
66
66
|
let n = e.filter((e) => e.info?.role === "assistant" && k(e) > t).sort((e, t) => k(e) - k(t));
|
|
67
67
|
if (n.length === 0) return {
|
|
68
68
|
content: "Thinking...",
|
|
69
69
|
done: !1
|
|
70
70
|
};
|
|
71
|
-
let r = n[n.length - 1], i = A(r.parts), a = O(r.parts), o = j(r.parts),
|
|
71
|
+
let r = n[n.length - 1], i = A(r.parts), a = O(r.parts), o = j(r.parts), ee = Ee(r.parts);
|
|
72
72
|
return {
|
|
73
73
|
content: [
|
|
74
74
|
i,
|
|
@@ -77,10 +77,10 @@ function Ge(e, t) {
|
|
|
77
77
|
].filter(Boolean).join("\n\n") || "Thinking...",
|
|
78
78
|
done: !!r.info?.time?.completed && (!!i || a.length > 0 || o.length > 0),
|
|
79
79
|
tokens: r.info?.tokens,
|
|
80
|
-
...
|
|
80
|
+
...ee ? { pendingWrite: ee } : {}
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
function
|
|
83
|
+
function Ge(e) {
|
|
84
84
|
switch (e) {
|
|
85
85
|
case "provisioning": return "Starting assistant environment...";
|
|
86
86
|
case "connecting": return "Connecting to assistant...";
|
|
@@ -88,375 +88,366 @@ function Ke(e) {
|
|
|
88
88
|
default: return "";
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
var
|
|
92
|
-
let O =
|
|
91
|
+
var Ke = ({ visible: Ee = !0 }) => {
|
|
92
|
+
let O = Re(), A = Ie("workspace"), { getAccessToken: j, getWorkspaceToken: Ke, userId: qe } = Le(), { locale: Je } = Pe(), Ye = e((e) => e.assistantLanguage), Xe = e((e) => e.replyLanguage), Ze = T(() => p(Ye, Xe, Je), [
|
|
93
|
+
Ye,
|
|
93
94
|
Xe,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
]), $e = Qe.reply.english, et = Qe.replyIsExplicit, tt = Qe.reply.code, { conversations: nt, activeConversationId: M, mode: N, processingByConversationId: rt, setMode: P, setConversationMode: F, setActiveConversation: it, createConversation: I, addMessage: L, updateMessage: at, patchMessage: R, mergeMessageMetadata: ot, setConversationProcessing: z, clearConversationProcessing: st, setBackendSessionId: ct, clearBackendSessionId: B, setSandbox: V, clearSandbox: lt, acknowledgeApiCalls: ut } = e(), H = _e(nt.find((e) => e.id === M)), U = H.all, W = M ? rt[M] : void 0, G = we(W?.status), dt = G ? W?.messageId ?? null : null, ft = W?.status === "error" ? W.messageId : null, { canUseApiCalls: pt, loading: mt } = pe(re()), ht = me(v(), y() || null), gt = T(() => Te.filter((e) => !e.requiresAdmin || pt), [pt]), [_t, vt] = Pe(null), [yt, bt] = Pe(!1), xt = E({}), St = E(Ne()), Ct = E(/* @__PURE__ */ new Set()), wt = T(() => Te.find((e) => e.id === N), [N]);
|
|
95
|
+
Je
|
|
96
|
+
]), Qe = Ze.reply.english, $e = Ze.replyIsExplicit, et = Ze.reply.code, { conversations: tt, activeConversationId: M, mode: N, processingByConversationId: nt, setMode: P, setConversationMode: F, setActiveConversation: rt, createConversation: I, addMessage: L, updateMessage: it, patchMessage: R, mergeMessageMetadata: at, setConversationProcessing: z, clearConversationProcessing: ot, setBackendSessionId: st, clearBackendSessionId: B, setSandbox: V, clearSandbox: ct, acknowledgeApiCalls: lt } = e(), H = ge(tt.find((e) => e.id === M)), U = H.all, W = M ? nt[M] : void 0, G = Ce(W?.status), ut = G ? W?.messageId ?? null : null, dt = W?.status === "error" ? W.messageId : null, { canUseApiCalls: K, loading: ft } = de(y()), pt = fe(te(), ne() || null), mt = T(() => we.filter((e) => !e.requiresAdmin || K), [K]), [ht, gt] = Ne(null), [_t, vt] = Ne(!1), yt = E({}), q = E(Me()), bt = E(/* @__PURE__ */ new Set()), xt = T(() => we.find((e) => e.id === N), [N]);
|
|
97
97
|
w(() => {
|
|
98
|
-
|
|
98
|
+
ft || (!xt || xt.requiresAdmin && !K) && N !== "assistant" && P("assistant");
|
|
99
99
|
}, [
|
|
100
100
|
N,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
xt,
|
|
102
|
+
K,
|
|
103
|
+
ft,
|
|
104
104
|
P
|
|
105
105
|
]);
|
|
106
|
-
let
|
|
107
|
-
z(e, n, t, null), r ?
|
|
108
|
-
}, [z,
|
|
109
|
-
let
|
|
110
|
-
if (
|
|
106
|
+
let J = C((e, t, n, r) => {
|
|
107
|
+
z(e, n, t, null), r ? it(e, t, r) : it(e, t, Ge(n));
|
|
108
|
+
}, [z, it]), St = C(async (r, a, o, s, c) => {
|
|
109
|
+
let d = e.getState().sandboxesByMode[o]?.sandboxId ?? null, f = async (e) => {
|
|
110
|
+
if (q.current.isFresh(e)) return !0;
|
|
111
111
|
try {
|
|
112
|
-
return await
|
|
112
|
+
return await u(A, e, s, c, 3e5, (e) => J(r, a, "provisioning", e)), await l(A, e, s, c, 9e4, (e) => J(r, a, "connecting", e)), q.current.markVerified(e), !0;
|
|
113
113
|
} catch {
|
|
114
|
-
return
|
|
114
|
+
return q.current.invalidate(e), !1;
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
let e = await
|
|
120
|
-
e && (V(o, e, "provisioning"),
|
|
117
|
+
if (d && (V(o, d, "provisioning"), J(r, a, "provisioning", "Reusing assistant environment..."), await f(d) || (V(o, null, "provisioning"), d = null)), !d) {
|
|
118
|
+
J(r, a, "provisioning", "Looking for existing environment...");
|
|
119
|
+
let e = await i(A, s, o, c);
|
|
120
|
+
e && (V(o, e, "provisioning"), J(r, a, "provisioning", "Reusing assistant environment..."), await f(e) ? d = e : V(o, null, "provisioning"));
|
|
121
121
|
}
|
|
122
|
-
if (!
|
|
122
|
+
if (!d) {
|
|
123
123
|
if (o === "api-calls" && !j()) throw Error("API Calls mode requires an authenticated session. Please sign in again.");
|
|
124
|
-
|
|
124
|
+
J(r, a, "provisioning", "Starting assistant environment..."), V(o, null, "provisioning"), d = await t(A, o, s, c), V(o, d, "provisioning"), await u(A, d, s, c, 3e5, (e) => J(r, a, "provisioning", e)), await l(A, d, s, c, 9e4, (e) => J(r, a, "connecting", e));
|
|
125
125
|
}
|
|
126
|
-
V(o,
|
|
127
|
-
let
|
|
128
|
-
if (
|
|
129
|
-
let e = await ee(A,
|
|
126
|
+
V(o, d, "running");
|
|
127
|
+
let p = e.getState().conversations.find((e) => e.id === r)?.backendSessionId ?? null;
|
|
128
|
+
if (p) try {
|
|
129
|
+
let e = await ee(A, d, s, p, c);
|
|
130
130
|
if (e.mode !== o) throw Error(`Session mode mismatch: expected ${o}, received ${e.mode}`);
|
|
131
131
|
} catch {
|
|
132
|
-
B(
|
|
132
|
+
B(r), p = null;
|
|
133
133
|
}
|
|
134
|
-
return
|
|
135
|
-
sandboxId:
|
|
136
|
-
sessionId:
|
|
134
|
+
return p || (J(r, a, "connecting", "Preparing session..."), p = (await n(A, d, s, o, c)).sessionId, st(r, p)), {
|
|
135
|
+
sandboxId: d,
|
|
136
|
+
sessionId: p
|
|
137
137
|
};
|
|
138
138
|
}, [
|
|
139
139
|
A,
|
|
140
140
|
B,
|
|
141
141
|
j,
|
|
142
|
-
|
|
142
|
+
st,
|
|
143
143
|
V,
|
|
144
|
-
|
|
145
|
-
]),
|
|
146
|
-
let ee =
|
|
147
|
-
if (
|
|
148
|
-
let f =
|
|
144
|
+
J
|
|
145
|
+
]), Y = C(async (t, n = [], i = {}) => {
|
|
146
|
+
let ee = i.voiceSessionId !== void 0, l = e.getState(), u = l.activeConversationId ?? M;
|
|
147
|
+
if (u && (Ce(l.processingByConversationId[u]?.status) || bt.current.has(u))) return;
|
|
148
|
+
let f = l.mode, p = M, m = p ? e.getState().conversations.find((e) => e.id === p) : void 0;
|
|
149
149
|
if (p ? m && m.mode !== f && (m.messages.length > 0 || m.backendSessionId) ? p = I(void 0, f) : m && m.mode !== f && F(p, f) : p = I(void 0, f), !p) return;
|
|
150
|
-
|
|
151
|
-
let h =
|
|
150
|
+
yt.current[p] = n;
|
|
151
|
+
let h = ne(), g = {
|
|
152
152
|
accessToken: j(),
|
|
153
|
-
workspaceToken:
|
|
154
|
-
userId:
|
|
155
|
-
organizationId:
|
|
156
|
-
},
|
|
157
|
-
id:
|
|
153
|
+
workspaceToken: Ke(),
|
|
154
|
+
userId: qe,
|
|
155
|
+
organizationId: y()
|
|
156
|
+
}, _ = {
|
|
157
|
+
id: He(),
|
|
158
158
|
role: "user",
|
|
159
|
-
content:
|
|
159
|
+
content: t,
|
|
160
160
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
161
161
|
metadata: {
|
|
162
|
-
...
|
|
163
|
-
...
|
|
162
|
+
...n.length ? { attachments: n.map(x) } : {},
|
|
163
|
+
...me(i.voiceSessionId)
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
|
-
L(p,
|
|
167
|
-
let
|
|
166
|
+
L(p, _);
|
|
167
|
+
let v = He();
|
|
168
168
|
L(p, {
|
|
169
|
-
id:
|
|
169
|
+
id: v,
|
|
170
170
|
role: "assistant",
|
|
171
171
|
content: "",
|
|
172
172
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
173
173
|
metadata: {
|
|
174
|
-
lang:
|
|
175
|
-
...
|
|
174
|
+
lang: et,
|
|
175
|
+
...me(i.voiceSessionId)
|
|
176
176
|
}
|
|
177
|
-
}), z(p, "provisioning",
|
|
178
|
-
let
|
|
179
|
-
R(p,
|
|
180
|
-
lang:
|
|
177
|
+
}), z(p, "provisioning", v, null);
|
|
178
|
+
let te = (e, t, n, r, a = et) => {
|
|
179
|
+
R(p, v, { content: Ue(e) }), at(p, v, {
|
|
180
|
+
lang: a,
|
|
181
181
|
...t?.length ? { artifacts: t } : {},
|
|
182
182
|
...t?.length || n || r ? { mode: f } : {},
|
|
183
183
|
...n ? { sessionId: n } : {},
|
|
184
184
|
...r ? { sandboxId: r } : {},
|
|
185
|
-
...
|
|
185
|
+
...me(i.voiceSessionId)
|
|
186
186
|
});
|
|
187
187
|
}, b = async (e = 1) => {
|
|
188
|
-
let
|
|
188
|
+
let i = !1;
|
|
189
189
|
try {
|
|
190
|
-
await
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
console.warn("[assistant] AI-credit pre-flight check failed with a non-quota error; proceeding — gateway @usage(checkQuota) still enforces the real budget downstream", e);
|
|
197
|
-
}
|
|
198
|
-
try {
|
|
199
|
-
let { sandboxId: e, sessionId: t } = await Tt(p, _, f, h, g), u = (await s(A, e, h, t, g, 50).catch(() => [])).reduce((e, t) => Math.max(e, k(t)), 0);
|
|
200
|
-
K(p, _, "streaming", "Thinking...");
|
|
201
|
-
let d = xe(f, ae(n, r), $e, et, ee), m = ie(d, r), ne = se(m), re = ne > 0, y = te();
|
|
202
|
-
a = oe(r) > ne;
|
|
190
|
+
let { sandboxId: e, sessionId: l } = await St(p, v, f, h, g), u = (await o(A, e, h, l, g, 50).catch(() => [])).reduce((e, t) => Math.max(e, k(t)), 0);
|
|
191
|
+
J(p, v, "streaming", "Thinking...");
|
|
192
|
+
let m = be(f, ie(t, n), Qe, $e, ee), _ = re(m, n), y = oe(_), ne = y > 0, b = d();
|
|
193
|
+
i = ae(n) > y;
|
|
203
194
|
try {
|
|
204
|
-
await
|
|
205
|
-
} catch (
|
|
206
|
-
if (!
|
|
207
|
-
await
|
|
195
|
+
await c(A, e, h, l, m, f, b, g, _);
|
|
196
|
+
} catch (t) {
|
|
197
|
+
if (!_ || !xe(t)) throw t;
|
|
198
|
+
await c(A, e, h, l, m, f, b, g, void 0), i ||= ne;
|
|
208
199
|
}
|
|
209
|
-
let
|
|
210
|
-
for (; Date.now() <
|
|
211
|
-
if (!
|
|
212
|
-
let
|
|
213
|
-
if (
|
|
214
|
-
...
|
|
215
|
-
content: `${
|
|
216
|
-
}),
|
|
217
|
-
...
|
|
218
|
-
content: `${
|
|
219
|
-
}),
|
|
220
|
-
R(p,
|
|
200
|
+
let x = We([], u), S = Date.now() + (ze[f] ?? Be), se = Date.now(), ce = Date.now();
|
|
201
|
+
for (; Date.now() < S && (x = We(await o(A, e, h, l, g, 50, u), u), R(p, v, { content: Ue(x.content) }), x.pendingWrite && at(p, v, { pendingWrite: x.pendingWrite }), !x.done);) Date.now() - se > 3e4 && (await r(A, e, h, 600, g).catch(() => void 0), se = Date.now()), await new Promise((e) => setTimeout(e, Te(Date.now() - ce)));
|
|
202
|
+
if (!x.done && f !== "vibe-plugins") throw Error("Assistant response timed out while streaming progress");
|
|
203
|
+
let le = f === "vibe-plugins" ? await a(A, e, h, l, g).catch(() => []) : void 0;
|
|
204
|
+
if (x.done || (x = {
|
|
205
|
+
...x,
|
|
206
|
+
content: `${x.content}\n\n_Still building in the background — any artifacts below will finish shortly. Re-open this conversation to pick up the completed plugin._`
|
|
207
|
+
}), i && (x = {
|
|
208
|
+
...x,
|
|
209
|
+
content: `${x.content}\n\n${O("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._")}`
|
|
210
|
+
}), te(x.content, le, l, e), x.tokens) {
|
|
211
|
+
R(p, v, { tokens: x.tokens });
|
|
221
212
|
try {
|
|
222
|
-
await
|
|
213
|
+
await s(A, h, l, x.tokens, g), ye();
|
|
223
214
|
} catch {}
|
|
224
215
|
}
|
|
225
|
-
z(p, "complete",
|
|
216
|
+
z(p, "complete", v, null);
|
|
226
217
|
} catch (t) {
|
|
227
|
-
if (e === 1 &&
|
|
218
|
+
if (e === 1 && Se(t)) return B(p), ct(f), b(2);
|
|
228
219
|
throw t;
|
|
229
220
|
}
|
|
230
|
-
},
|
|
231
|
-
|
|
221
|
+
}, S = p;
|
|
222
|
+
bt.current.add(S);
|
|
232
223
|
try {
|
|
233
224
|
if (!h) throw Error("Assistant backend is unavailable without an active workspace context.");
|
|
234
225
|
await b();
|
|
235
226
|
} catch (t) {
|
|
236
|
-
if (
|
|
237
|
-
|
|
227
|
+
if (q.current.invalidate(e.getState().sandboxesByMode[f]?.sandboxId ?? null), _e(t)) {
|
|
228
|
+
ve("sandbox"), te("You've reached your sandbox limit on the current plan. Upgrade to start the AI assistant.", void 0, void 0, void 0, "en"), z(p, "error", v, null);
|
|
238
229
|
return;
|
|
239
230
|
}
|
|
240
231
|
let n = t instanceof Error ? t.message : "Something went wrong";
|
|
241
|
-
z(p, "error",
|
|
232
|
+
z(p, "error", v, n), R(p, v, { content: `Sorry, an error occurred: ${n}. Please try again.` }), at(p, v, {
|
|
242
233
|
lang: "en",
|
|
243
|
-
...
|
|
234
|
+
...me(i.voiceSessionId)
|
|
244
235
|
});
|
|
245
236
|
} finally {
|
|
246
|
-
|
|
237
|
+
bt.current.delete(S);
|
|
247
238
|
}
|
|
248
239
|
}, [
|
|
249
240
|
M,
|
|
250
241
|
L,
|
|
251
242
|
A,
|
|
252
243
|
B,
|
|
253
|
-
|
|
254
|
-
|
|
244
|
+
ct,
|
|
245
|
+
tt,
|
|
255
246
|
I,
|
|
256
|
-
|
|
247
|
+
St,
|
|
257
248
|
j,
|
|
258
|
-
|
|
249
|
+
Ke,
|
|
259
250
|
R,
|
|
260
|
-
et,
|
|
261
|
-
tt,
|
|
262
251
|
$e,
|
|
263
|
-
|
|
252
|
+
et,
|
|
253
|
+
Qe,
|
|
254
|
+
st,
|
|
264
255
|
F,
|
|
265
256
|
z,
|
|
266
257
|
O,
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
]),
|
|
270
|
-
|
|
271
|
-
}, [
|
|
272
|
-
let e = [...H.chat].reverse().find((e) => e.role === "user"), t = M ?
|
|
273
|
-
e &&
|
|
258
|
+
J,
|
|
259
|
+
qe
|
|
260
|
+
]), Ct = C((e) => {
|
|
261
|
+
Y(e);
|
|
262
|
+
}, [Y]), wt = C(() => {
|
|
263
|
+
let e = [...H.chat].reverse().find((e) => e.role === "user"), t = M ? yt.current[M] ?? [] : [];
|
|
264
|
+
e && Y(e.content, t);
|
|
274
265
|
}, [
|
|
275
266
|
U,
|
|
276
|
-
|
|
267
|
+
Y,
|
|
277
268
|
M
|
|
278
|
-
]),
|
|
269
|
+
]), Tt = E(Y);
|
|
279
270
|
w(() => {
|
|
280
|
-
|
|
281
|
-
}, [
|
|
282
|
-
let
|
|
271
|
+
Tt.current = Y;
|
|
272
|
+
}, [Y]);
|
|
273
|
+
let Et = T(() => {
|
|
283
274
|
if (G) return null;
|
|
284
275
|
for (let e = U.length - 1; e >= 0; --e) {
|
|
285
276
|
let t = U[e];
|
|
286
|
-
if (t?.role !== "assistant" || !
|
|
287
|
-
let n =
|
|
277
|
+
if (t?.role !== "assistant" || !pe(t)) continue;
|
|
278
|
+
let n = le(t.content).text.trim();
|
|
288
279
|
return n ? {
|
|
289
280
|
id: t.id,
|
|
290
281
|
text: n
|
|
291
282
|
} : null;
|
|
292
283
|
}
|
|
293
284
|
return null;
|
|
294
|
-
}, [U, G]),
|
|
285
|
+
}, [U, G]), Dt = T(() => Et ? De(Et.text) : null, [Et]), Ot = H.chat, X = T(() => H.voice.filter((e) => e.role === "user" || e.role === "assistant").map((e) => ({
|
|
295
286
|
id: e.id,
|
|
296
287
|
role: e.role,
|
|
297
|
-
text:
|
|
298
|
-
sessionId:
|
|
288
|
+
text: le(e.content).text.trim(),
|
|
289
|
+
sessionId: he(e),
|
|
299
290
|
timestamp: e.timestamp
|
|
300
|
-
})).filter((e) => e.text.length > 0), [H.voice]),
|
|
301
|
-
if (
|
|
291
|
+
})).filter((e) => e.text.length > 0), [H.voice]), kt = C(() => {
|
|
292
|
+
if (X.length === 0) return;
|
|
302
293
|
let e = /* @__PURE__ */ new Date();
|
|
303
|
-
|
|
294
|
+
je(ke(X, {
|
|
304
295
|
title: O("voiceSession.transcript", "Voice conversation"),
|
|
305
296
|
savedAt: O("voiceSession.savedAt", "Saved"),
|
|
306
297
|
session: O("voiceSession.sessionLabel", "Session"),
|
|
307
298
|
earlier: O("voiceSession.earlierLabel", "Earlier"),
|
|
308
299
|
you: O("voiceSession.speakerYou", "You"),
|
|
309
300
|
assistant: O("voiceSession.speakerAssistant", "Assistant")
|
|
310
|
-
}, e),
|
|
311
|
-
}, [
|
|
312
|
-
|
|
313
|
-
let
|
|
301
|
+
}, e), Ae(e), "text/markdown");
|
|
302
|
+
}, [X, O]), Z = S(), Q = E(Z);
|
|
303
|
+
Q.current = Z;
|
|
304
|
+
let $ = ue({
|
|
314
305
|
onSubmit: C((e, t) => {
|
|
315
306
|
let n = () => {
|
|
316
|
-
let n =
|
|
317
|
-
|
|
307
|
+
let n = Q.current, r = b(n.attachments);
|
|
308
|
+
Tt.current(e, r, { voiceSessionId: t }), n.clear();
|
|
318
309
|
};
|
|
319
|
-
if (!
|
|
310
|
+
if (!Q.current.isBusy) {
|
|
320
311
|
n();
|
|
321
312
|
return;
|
|
322
313
|
}
|
|
323
314
|
let r = Date.now(), i = window.setInterval(() => {
|
|
324
|
-
|
|
315
|
+
Q.current.isBusy && Date.now() - r < Ve || (window.clearInterval(i), n());
|
|
325
316
|
}, 200);
|
|
326
317
|
}, []),
|
|
327
|
-
latestReply:
|
|
328
|
-
language: f(
|
|
329
|
-
}),
|
|
318
|
+
latestReply: Et,
|
|
319
|
+
language: f(Ye, Je).tag
|
|
320
|
+
}), At = C(() => {
|
|
330
321
|
let t = e.getState().activeConversationId;
|
|
331
|
-
!t ||
|
|
332
|
-
id:
|
|
322
|
+
!t || X.length === 0 || (L(t, {
|
|
323
|
+
id: He(),
|
|
333
324
|
role: "system",
|
|
334
|
-
content:
|
|
325
|
+
content: Oe(X, {
|
|
335
326
|
intro: O("voiceSession.continuedIntro", "Continued from a voice conversation. You asked about:"),
|
|
336
327
|
nothing: O("voiceSession.continuedNothing", "Continued from a voice conversation."),
|
|
337
328
|
more: (e) => O("voiceSession.continuedMore", "…and {{count}} more", { count: e })
|
|
338
329
|
}),
|
|
339
330
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
340
|
-
}),
|
|
331
|
+
}), vt(!1), $.end());
|
|
341
332
|
}, [
|
|
342
|
-
|
|
333
|
+
X,
|
|
343
334
|
L,
|
|
344
335
|
O
|
|
345
336
|
]);
|
|
346
337
|
w(() => {
|
|
347
|
-
!
|
|
348
|
-
}, [
|
|
349
|
-
|
|
350
|
-
}, [
|
|
338
|
+
!Ee && $.active && $.end();
|
|
339
|
+
}, [Ee, $]), w(() => {
|
|
340
|
+
$.active || Q.current.clear();
|
|
341
|
+
}, [$.active]), w(() => {
|
|
351
342
|
let t = e.getState().consumePendingPrompt();
|
|
352
|
-
return t &&
|
|
343
|
+
return t && Tt.current(t), e.subscribe((t, n) => {
|
|
353
344
|
if (t.pendingPrompt && t.pendingPrompt !== n.pendingPrompt) {
|
|
354
345
|
let t = e.getState().consumePendingPrompt();
|
|
355
|
-
t &&
|
|
346
|
+
t && Tt.current(t);
|
|
356
347
|
}
|
|
357
348
|
});
|
|
358
349
|
}, []);
|
|
359
|
-
let
|
|
350
|
+
let jt = C((t) => {
|
|
360
351
|
let n = M ? e.getState().conversations.find((e) => e.id === M) : void 0;
|
|
361
352
|
if (n && (n.messages.length > 0 || n.backendSessionId)) {
|
|
362
353
|
if (n.mode !== t) {
|
|
363
354
|
let n = e.getState().conversations.find((n) => n.mode === t && n.messages.length === 0 && !n.backendSessionId && !e.getState().processingByConversationId[n.id]);
|
|
364
|
-
n ?
|
|
355
|
+
n ? rt(n.id) : I(void 0, t);
|
|
365
356
|
}
|
|
366
357
|
} else M && F(M, t);
|
|
367
358
|
P(t);
|
|
368
359
|
}, [
|
|
369
360
|
M,
|
|
370
361
|
I,
|
|
371
|
-
|
|
362
|
+
rt,
|
|
372
363
|
F,
|
|
373
364
|
P
|
|
374
|
-
]),
|
|
375
|
-
if (
|
|
376
|
-
|
|
365
|
+
]), Mt = C((t) => {
|
|
366
|
+
if (we.find((e) => e.id === t)?.writeCapable && !e.getState().apiCallsAcknowledged) {
|
|
367
|
+
gt(t);
|
|
377
368
|
return;
|
|
378
369
|
}
|
|
379
|
-
|
|
380
|
-
}, [
|
|
381
|
-
let e =
|
|
382
|
-
|
|
370
|
+
jt(t);
|
|
371
|
+
}, [jt]), Nt = C(() => {
|
|
372
|
+
let e = ht;
|
|
373
|
+
gt(null), lt(), e && jt(e);
|
|
383
374
|
}, [
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
]),
|
|
388
|
-
|
|
375
|
+
ht,
|
|
376
|
+
lt,
|
|
377
|
+
jt
|
|
378
|
+
]), Pt = C(() => {
|
|
379
|
+
gt(null);
|
|
389
380
|
}, []);
|
|
390
|
-
return /* @__PURE__ */
|
|
381
|
+
return /* @__PURE__ */ Fe("div", {
|
|
391
382
|
className: "relative flex flex-1 flex-col overflow-hidden",
|
|
392
383
|
children: [
|
|
393
|
-
/* @__PURE__ */
|
|
384
|
+
/* @__PURE__ */ Fe("div", {
|
|
394
385
|
className: "contents",
|
|
395
|
-
inert:
|
|
386
|
+
inert: $.active || void 0,
|
|
396
387
|
children: [
|
|
397
|
-
|
|
398
|
-
count:
|
|
399
|
-
onOpenTranscript: () =>
|
|
388
|
+
X.length > 0 && !$.active ? /* @__PURE__ */ D(_, {
|
|
389
|
+
count: X.length,
|
|
390
|
+
onOpenTranscript: () => vt(!0)
|
|
400
391
|
}) : null,
|
|
401
|
-
|
|
392
|
+
Ot.length === 0 ? /* @__PURE__ */ D(g, {
|
|
402
393
|
mode: N,
|
|
403
|
-
onSuggestionClick:
|
|
394
|
+
onSuggestionClick: Ct
|
|
404
395
|
}) : /* @__PURE__ */ D("div", {
|
|
405
396
|
className: "flex min-h-0 flex-1 flex-col",
|
|
406
397
|
children: /* @__PURE__ */ D(m, {
|
|
407
|
-
messages:
|
|
408
|
-
streamingMessageId:
|
|
409
|
-
failedMessageId:
|
|
410
|
-
onRetry:
|
|
398
|
+
messages: Ot,
|
|
399
|
+
streamingMessageId: ut,
|
|
400
|
+
failedMessageId: dt,
|
|
401
|
+
onRetry: wt
|
|
411
402
|
})
|
|
412
403
|
}),
|
|
413
|
-
/* @__PURE__ */ D(
|
|
414
|
-
onStartVoiceSession:
|
|
415
|
-
onSend: (e, t) => void
|
|
404
|
+
/* @__PURE__ */ D(se, {
|
|
405
|
+
onStartVoiceSession: $.available && N !== "api-calls" ? $.start : void 0,
|
|
406
|
+
onSend: (e, t) => void Y(e, t),
|
|
416
407
|
disabled: G,
|
|
417
408
|
placeholder: N === "api-calls" ? O("chatArea.placeholderActions", "What would you like me to do?") : O("chatArea.placeholderGeneral", "Ask HealthyBowl anything…"),
|
|
418
409
|
mode: N,
|
|
419
|
-
writeAccessDenied:
|
|
420
|
-
availableModes:
|
|
421
|
-
onModeChange:
|
|
410
|
+
writeAccessDenied: pt === "denied" && !!xt?.writeCapable,
|
|
411
|
+
availableModes: mt,
|
|
412
|
+
onModeChange: Mt
|
|
422
413
|
})
|
|
423
414
|
]
|
|
424
415
|
}),
|
|
425
|
-
|
|
426
|
-
turns:
|
|
427
|
-
onClose: () =>
|
|
428
|
-
onSave:
|
|
416
|
+
_t && !$.active ? /* @__PURE__ */ D(v, {
|
|
417
|
+
turns: X,
|
|
418
|
+
onClose: () => vt(!1),
|
|
419
|
+
onSave: kt
|
|
429
420
|
}) : null,
|
|
430
|
-
|
|
431
|
-
session:
|
|
432
|
-
notice:
|
|
433
|
-
capturing:
|
|
434
|
-
interrupting:
|
|
435
|
-
awaitingEndpoint:
|
|
436
|
-
turns:
|
|
437
|
-
spokenChunks:
|
|
438
|
-
attachments:
|
|
439
|
-
onAttachFiles:
|
|
440
|
-
onRemoveAttachment:
|
|
441
|
-
onRetryAttachment:
|
|
442
|
-
canAttachMore:
|
|
443
|
-
preparingAttachments:
|
|
444
|
-
onSaveTranscript:
|
|
445
|
-
onContinueInChat:
|
|
446
|
-
onInterrupt:
|
|
447
|
-
spoken:
|
|
448
|
-
onToggleMute:
|
|
449
|
-
onEnd:
|
|
421
|
+
$.active && /* @__PURE__ */ D(ce, {
|
|
422
|
+
session: $.session,
|
|
423
|
+
notice: $.notice,
|
|
424
|
+
capturing: $.capturing,
|
|
425
|
+
interrupting: $.interrupting,
|
|
426
|
+
awaitingEndpoint: $.awaitingEndpoint,
|
|
427
|
+
turns: X,
|
|
428
|
+
spokenChunks: $.spokenChunks,
|
|
429
|
+
attachments: Z.attachments,
|
|
430
|
+
onAttachFiles: Z.addFiles,
|
|
431
|
+
onRemoveAttachment: Z.remove,
|
|
432
|
+
onRetryAttachment: Z.retry,
|
|
433
|
+
canAttachMore: Z.canAddMore,
|
|
434
|
+
preparingAttachments: Z.preparingCount,
|
|
435
|
+
onSaveTranscript: kt,
|
|
436
|
+
onContinueInChat: At,
|
|
437
|
+
onInterrupt: $.interrupt,
|
|
438
|
+
spoken: Dt,
|
|
439
|
+
onToggleMute: $.toggleMute,
|
|
440
|
+
onEnd: $.end
|
|
450
441
|
}),
|
|
451
442
|
/* @__PURE__ */ D(h, {
|
|
452
|
-
open:
|
|
453
|
-
onConfirm:
|
|
454
|
-
onCancel:
|
|
443
|
+
open: ht !== null,
|
|
444
|
+
onConfirm: Nt,
|
|
445
|
+
onCancel: Pt
|
|
455
446
|
})
|
|
456
447
|
]
|
|
457
448
|
});
|
|
458
449
|
};
|
|
459
450
|
//#endregion
|
|
460
|
-
export {
|
|
451
|
+
export { Ke as AssistantChatArea };
|
|
461
452
|
|
|
462
453
|
//# sourceMappingURL=AssistantChatArea.js.map
|