@burdenoff/microfe-bigconsole 2026.713.5 → 2026.713.6
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.
|
@@ -185,11 +185,11 @@ function K(e) {
|
|
|
185
185
|
].some((e) => t.includes(e));
|
|
186
186
|
}
|
|
187
187
|
function q() {
|
|
188
|
-
let { getAccessToken: x, getWorkspaceToken: E, userId: j, workspaceId: M } = m(), [N, P] = f(() => [w(S), w(C)], []), F = p(N), I = p(P), R = d((e) => {
|
|
188
|
+
let { getAccessToken: x, getWorkspaceToken: E, userId: j, workspaceId: M } = m(), [N, P] = f(() => [w(S), w(C)], []), F = p(N), I = p(P), R = p(/* @__PURE__ */ new Map()), z = d((e) => {
|
|
189
189
|
F.current = e, T(S, e);
|
|
190
|
-
}, []),
|
|
190
|
+
}, []), B = d((e) => {
|
|
191
191
|
I.current = e, T(C, e);
|
|
192
|
-
}, []),
|
|
192
|
+
}, []), H = d(async (n, r) => {
|
|
193
193
|
let a = F.current;
|
|
194
194
|
if (console.log("[BigConsole-Assistant] ensureRuntime start", {
|
|
195
195
|
sandboxId: a,
|
|
@@ -204,7 +204,7 @@ function q() {
|
|
|
204
204
|
error: e instanceof Error ? e.message : String(e)
|
|
205
205
|
}), a = null;
|
|
206
206
|
}
|
|
207
|
-
a || (console.log("[BigConsole-Assistant] createAssistantSandbox called"), a = await e(h, n, r), console.log("[BigConsole-Assistant] createAssistantSandbox result", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForSandboxReady called (fresh)", { sandboxId: a }), await l(a, n, r), console.log("[BigConsole-Assistant] waitForSandboxReady done (fresh)", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForAssistantServiceReady called (fresh)", { sandboxId: a }), await c(a, n, h, r), console.log("[BigConsole-Assistant] waitForAssistantServiceReady done (fresh)", { sandboxId: a })),
|
|
207
|
+
a || (console.log("[BigConsole-Assistant] createAssistantSandbox called"), a = await e(h, n, r), console.log("[BigConsole-Assistant] createAssistantSandbox result", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForSandboxReady called (fresh)", { sandboxId: a }), await l(a, n, r), console.log("[BigConsole-Assistant] waitForSandboxReady done (fresh)", { sandboxId: a }), console.log("[BigConsole-Assistant] waitForAssistantServiceReady called (fresh)", { sandboxId: a }), await c(a, n, h, r), console.log("[BigConsole-Assistant] waitForAssistantServiceReady done (fresh)", { sandboxId: a })), z(a);
|
|
208
208
|
}
|
|
209
209
|
let o = I.current;
|
|
210
210
|
return console.log("[BigConsole-Assistant] session check", {
|
|
@@ -213,11 +213,11 @@ function q() {
|
|
|
213
213
|
}), o || (console.log("[BigConsole-Assistant] createAssistantSession called", {
|
|
214
214
|
sandboxId: a,
|
|
215
215
|
workspaceId: n
|
|
216
|
-
}), o = (await t(a, n, h, r)).sessionId,
|
|
216
|
+
}), o = (await t(a, n, h, r)).sessionId, B(o)), {
|
|
217
217
|
sandboxId: a,
|
|
218
218
|
sessionId: o
|
|
219
219
|
};
|
|
220
|
-
}, [x]),
|
|
220
|
+
}, [x]), U = d(async ({ prompt: e, onProgress: t, signal: n }) => {
|
|
221
221
|
let i = D(M);
|
|
222
222
|
if (console.log("[BigConsole-Assistant] sendPrompt called", {
|
|
223
223
|
promptLength: e.length,
|
|
@@ -245,7 +245,7 @@ function q() {
|
|
|
245
245
|
let c = async (l) => {
|
|
246
246
|
try {
|
|
247
247
|
console.log("[BigConsole-Assistant] run attempt", l);
|
|
248
|
-
let { sandboxId: c, sessionId: d } = await
|
|
248
|
+
let { sandboxId: c, sessionId: d } = await H(i, o);
|
|
249
249
|
console.log("[BigConsole-Assistant] ensureRuntime resolved", {
|
|
250
250
|
sandboxId: c,
|
|
251
251
|
sessionId: d
|
|
@@ -285,47 +285,63 @@ function q() {
|
|
|
285
285
|
stack: e instanceof Error ? e.stack : void 0,
|
|
286
286
|
sandboxId: F.current,
|
|
287
287
|
sessionId: I.current
|
|
288
|
-
}), l === 1 && K(e)) return
|
|
288
|
+
}), l === 1 && K(e)) return z(null), B(null), c(2);
|
|
289
289
|
throw e;
|
|
290
290
|
}
|
|
291
291
|
};
|
|
292
292
|
return c(1);
|
|
293
293
|
}, [
|
|
294
294
|
M,
|
|
295
|
-
|
|
295
|
+
H,
|
|
296
296
|
x,
|
|
297
297
|
E,
|
|
298
298
|
j,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
]),
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
299
|
+
z,
|
|
300
|
+
B
|
|
301
|
+
]), q = d(async (e, t) => {
|
|
302
|
+
if (F.current) return F.current;
|
|
303
|
+
try {
|
|
304
|
+
let n = await i(e, h, t);
|
|
305
|
+
return n && z(n), n;
|
|
306
|
+
} catch {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}, [z]), J = d(async () => {
|
|
310
|
+
let e = D(M);
|
|
311
|
+
if (!e || !x()) return [];
|
|
312
|
+
let t = {
|
|
307
313
|
accessToken: x(),
|
|
308
314
|
workspaceToken: E(),
|
|
309
315
|
userId: j,
|
|
310
316
|
organizationId: O()
|
|
311
|
-
};
|
|
317
|
+
}, n = await q(e, t);
|
|
318
|
+
if (!n) return [];
|
|
319
|
+
let r = I.current;
|
|
320
|
+
if (!r) try {
|
|
321
|
+
let i = [...await o(n, e, t)].sort((e, t) => (t.time?.updated ?? t.time?.created ?? 0) - (e.time?.updated ?? e.time?.created ?? 0))[0];
|
|
322
|
+
if (!i) return [];
|
|
323
|
+
r = i.id, B(r);
|
|
324
|
+
} catch {
|
|
325
|
+
return [];
|
|
326
|
+
}
|
|
312
327
|
try {
|
|
313
|
-
return V(await a(e,
|
|
314
|
-
} catch (
|
|
328
|
+
return V(await a(n, e, r, t, y));
|
|
329
|
+
} catch (e) {
|
|
315
330
|
return console.warn("[BigConsole-Assistant] could not restore history; starting fresh", {
|
|
316
|
-
sandboxId:
|
|
317
|
-
sessionId:
|
|
318
|
-
error:
|
|
319
|
-
}),
|
|
331
|
+
sandboxId: n,
|
|
332
|
+
sessionId: r,
|
|
333
|
+
error: e instanceof Error ? e.message : String(e)
|
|
334
|
+
}), z(null), B(null), [];
|
|
320
335
|
}
|
|
321
336
|
}, [
|
|
322
337
|
M,
|
|
323
338
|
x,
|
|
324
339
|
E,
|
|
325
340
|
j,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
341
|
+
z,
|
|
342
|
+
B,
|
|
343
|
+
q
|
|
344
|
+
]), Y = d(() => ({
|
|
329
345
|
accessToken: x(),
|
|
330
346
|
workspaceToken: E(),
|
|
331
347
|
userId: j,
|
|
@@ -334,67 +350,63 @@ function q() {
|
|
|
334
350
|
x,
|
|
335
351
|
E,
|
|
336
352
|
j
|
|
337
|
-
]),
|
|
338
|
-
let e =
|
|
339
|
-
if (!e
|
|
353
|
+
]), X = d(async () => {
|
|
354
|
+
let e = D(M);
|
|
355
|
+
if (!e) return [];
|
|
356
|
+
let t = Y(), n = await q(e, t);
|
|
357
|
+
if (!n) return [];
|
|
340
358
|
try {
|
|
341
|
-
let
|
|
359
|
+
let r = (await o(n, e, t)).map((e) => ({
|
|
342
360
|
session: e,
|
|
343
361
|
updatedAt: e.time?.updated ?? e.time?.created
|
|
344
362
|
})).sort((e, t) => (t.updatedAt ?? 0) - (e.updatedAt ?? 0)).slice(0, b);
|
|
345
|
-
return await Promise.all(
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
363
|
+
return await Promise.all(r.map(async ({ session: r, updatedAt: i }) => {
|
|
364
|
+
let a = R.current.get(r.id), o = a ?? await W(n, e, r, t);
|
|
365
|
+
return !a && o !== "New chat" && R.current.set(r.id, o), {
|
|
366
|
+
id: r.id,
|
|
367
|
+
title: o,
|
|
368
|
+
updatedAt: i,
|
|
369
|
+
active: r.id === I.current
|
|
370
|
+
};
|
|
371
|
+
}));
|
|
351
372
|
} catch {
|
|
352
373
|
return [];
|
|
353
374
|
}
|
|
354
|
-
}, [M, q]), Y = d(async () => {
|
|
355
|
-
let e = F.current, n = D(M);
|
|
356
|
-
if (!e || !n) {
|
|
357
|
-
z(null);
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
360
|
-
let { sessionId: r } = await t(e, n, h, q());
|
|
361
|
-
z(r);
|
|
362
375
|
}, [
|
|
363
376
|
M,
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
]),
|
|
367
|
-
let
|
|
368
|
-
|
|
377
|
+
Y,
|
|
378
|
+
q
|
|
379
|
+
]), Z = d(async () => (B(null), Promise.resolve()), [B]), Q = d(async (e) => {
|
|
380
|
+
let t = F.current, r = D(M);
|
|
381
|
+
!t || !r || (await n(t, r, e, Y()), R.current.delete(e), I.current === e && B(null));
|
|
369
382
|
}, [
|
|
370
383
|
M,
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
]), Z = d(async (e) => {
|
|
384
|
+
Y,
|
|
385
|
+
B
|
|
386
|
+
]), $ = d(async (e) => {
|
|
375
387
|
let t = F.current, n = D(M);
|
|
376
388
|
if (!t || !n) return [];
|
|
377
|
-
let r = await a(t, n, e,
|
|
378
|
-
return
|
|
389
|
+
let r = await a(t, n, e, Y(), y);
|
|
390
|
+
return B(e), V(r);
|
|
379
391
|
}, [
|
|
380
392
|
M,
|
|
381
|
-
|
|
382
|
-
|
|
393
|
+
Y,
|
|
394
|
+
B
|
|
383
395
|
]);
|
|
384
396
|
return f(() => ({
|
|
385
|
-
sendPrompt:
|
|
386
|
-
loadHistory:
|
|
387
|
-
listSessions:
|
|
388
|
-
newSession:
|
|
389
|
-
|
|
390
|
-
selectSession:
|
|
397
|
+
sendPrompt: U,
|
|
398
|
+
loadHistory: J,
|
|
399
|
+
listSessions: X,
|
|
400
|
+
newSession: Z,
|
|
401
|
+
deleteSession: Q,
|
|
402
|
+
selectSession: $
|
|
391
403
|
}), [
|
|
392
|
-
H,
|
|
393
404
|
U,
|
|
394
405
|
J,
|
|
395
|
-
Y,
|
|
396
406
|
X,
|
|
397
|
-
Z
|
|
407
|
+
Z,
|
|
408
|
+
Q,
|
|
409
|
+
$
|
|
398
410
|
]);
|
|
399
411
|
}
|
|
400
412
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSandboxAssistantTransport.js","names":[],"sources":["../../../src/bigconsole/assistant/createSandboxAssistantTransport.ts"],"sourcesContent":["/**\n * BigConsole adapter for the shared fe-libs AssistantWidget.\n *\n * The floating widget (fe-libs, Layer 1) is backend-agnostic — it calls an\n * injected `AssistantTransport`. This hook builds a transport that drives the\n * sandbox AI assistant (combined `assistant` mode = docs Q&A + api-calls): it\n * provisions/reuses a sandbox, opens a session, dispatches the prompt async,\n * then polls for the streamed answer. The agent introspects the GraphQL schema\n * and performs API calls on the user's behalf using their workspace token,\n * contextual to the current screen (via `gatherPageContext`).\n *\n * This is a faithful port of microfe-vibecontrols'\n * `services/createSandboxAssistantTransport.ts`; the only product-specific\n * difference lives in `assistantApi.createAssistantSandbox`\n * (`AI_ASSISTANT_PRODUCT=bigconsole`).\n */\n\nimport { useCallback, useMemo, useRef } from 'react';\nimport { useAuthToken } from '@burdenoff/fe-libs/shared/providers/shell';\nimport {\n createAssistantSandbox,\n createAssistantSession,\n deleteAssistantSession,\n extendAssistantSandboxTTL,\n findExistingSandbox,\n getAssistantMessages,\n listAssistantSessions,\n sendAssistantPromptAsync,\n waitForAssistantServiceReady,\n waitForSandboxReady,\n} from './assistantApi';\nimport { gatherPageContext } from './pageContext';\nimport type {\n AssistantMode,\n AssistantRawMessage,\n AssistantRawMessagePart,\n AssistantRawSession,\n AssistantSandboxAuthContext,\n} from './types';\n\n/**\n * Locally-defined mirror of the fe-libs `AssistantTransport` contract.\n *\n * Intentionally NOT imported from `@burdenoff/fe-libs`: microfe's tsconfig maps\n * `@burdenoff/fe-libs/*` to fe-libs *source*, so vite-plugin-dts would rewrite a\n * cross-package type used in this hook's public signature to a broken\n * source-relative path in the emitted `.d.ts`. Structural typing makes this\n * shape assignable to fe-libs' `AssistantTransport` at the call site\n * (bigconsole-app's AppShell), which is where compatibility is enforced.\n */\ninterface AssistantSendArgs {\n prompt: string;\n onProgress: (partialText: string) => void;\n signal: AbortSignal;\n}\n\n/** Mirror of fe-libs' `AssistantWidgetMessage` (see note above on why). */\ninterface AssistantHistoryMessage {\n id: string;\n role: 'user' | 'assistant';\n content: string;\n pending?: boolean;\n error?: boolean;\n}\n\n/** Mirror of fe-libs' `AssistantSessionSummary` (see note above on why). */\ninterface AssistantSessionSummaryLocal {\n id: string;\n title: string;\n updatedAt?: number;\n active?: boolean;\n}\n\nexport interface AssistantTransport {\n sendPrompt: (args: AssistantSendArgs) => Promise<{ text: string }>;\n loadHistory: () => Promise<AssistantHistoryMessage[]>;\n listSessions: () => Promise<AssistantSessionSummaryLocal[]>;\n newSession: () => Promise<void>;\n clearSession: () => Promise<void>;\n selectSession: (sessionId: string) => Promise<AssistantHistoryMessage[]>;\n}\n\n// BigConsole still boots the manually-tagged ACA image\n// `alpha-delegated-auth-v11` for the assistant sandbox. The historical\n// platform notes show that this image line reliably supports `api-calls`, while\n// the combined `assistant` mode depends on newer image contracts that are not\n// yet guaranteed on this tag. Use `api-calls` here so the assistant can execute\n// workspace GraphQL operations end-to-end right now. Once the underlying image\n// line is rebuilt and verified for combined mode, this can be switched back.\nconst MODE: AssistantMode = 'api-calls';\n// How long the UI will follow a single turn.\n//\n// This was 180s, which was SHORTER THAN THE WORK. A full \"create a school\n// attendance dashboard\" build — datasink → dashboard → parser → widget, each a\n// separate gateway call preceded by a model round-trip — measured 229s in prod.\n// So the agent finished, the dashboard genuinely existed, and the user was still\n// shown \"the assistant timed out\". That is worse than cosmetic: people retry and\n// end up with duplicate dashboards.\n//\n// 7 minutes covers the observed worst case with headroom. It costs nothing on\n// fast turns (we stop the moment the turn reports done), and the backend keeps\n// pace — the sandbox TTL is extended every TTL_EXTEND_INTERVAL_MS.\nconst STREAM_BUDGET_MS = 420_000;\nconst POLL_INTERVAL_MS = 1500;\nconst TTL_EXTEND_INTERVAL_MS = 30_000;\n// Raw agent messages per restore. The agent emits one message per internal\n// step, so a handful of turns is already dozens of messages — this is a cap on\n// the RAW fetch, not on the number of restored turns.\nconst HISTORY_MESSAGE_LIMIT = 200;\n// The History panel fetches one extra round-trip per chat to title it, so cap\n// how many chats we title at once. Older chats simply are not listed.\nconst SESSION_LIST_LIMIT = 15;\n// Only the first few messages are needed to find the first user prompt.\nconst SESSION_TITLE_PROBE_LIMIT = 8;\n\nconst SANDBOX_ID_KEY = 'bc-assistant-sandbox-id';\nconst SESSION_ID_KEY = 'bc-assistant-session-id';\n\nfunction readStoredId(key: string): string | null {\n try {\n return window.sessionStorage.getItem(key);\n } catch {\n // sessionStorage unavailable (private mode) — degrade to a fresh session.\n return null;\n }\n}\n\nfunction writeStoredId(key: string, id: string | null): void {\n try {\n if (id) window.sessionStorage.setItem(key, id);\n else window.sessionStorage.removeItem(key);\n } catch {\n // Non-fatal: we simply lose cross-reload continuity.\n }\n}\n\n// ── Context helpers (mirror vibecontrols' resolution) ────────────────\n\nfunction getProfileContextValue(key: 'workspaceId' | 'organizationId'): string {\n try {\n const activeContextKey =\n key === 'workspaceId' ? 'burdenoff-active-context-workspace' : 'burdenoff-active-context-organization';\n const activeContextValue = localStorage.getItem(activeContextKey);\n if (activeContextValue) return activeContextValue;\n\n const activeProfileId = sessionStorage.getItem('bf-active-profile');\n if (!activeProfileId) return '';\n const raw = localStorage.getItem(`bf-p-${activeProfileId}-context`);\n if (!raw) return '';\n const context = JSON.parse(raw) as { workspaceId?: string; organizationId?: string };\n return context[key] ?? '';\n } catch {\n return '';\n }\n}\n\nfunction getWorkspaceId(fallback: string | null): string {\n const params = new URLSearchParams(window.location.search);\n return params.get('workspace') ?? getProfileContextValue('workspaceId') ?? fallback ?? '';\n}\n\nfunction getOrganizationId(): string {\n const params = new URLSearchParams(window.location.search);\n return params.get('org') ?? getProfileContextValue('organizationId');\n}\n\n// ── Message-progress helpers (pure; mirror vibecontrols) ─────────────\n\nfunction getMessageRole(message: AssistantRawMessage): string | undefined {\n // Check nested format first, then flat format\n return message.info?.role ?? message.role;\n}\n\nfunction getRawMessageCreatedAt(message: AssistantRawMessage): number {\n // Check nested format first (epoch ms), then flat format (ISO string or epoch ms)\n const nested = message.info?.time?.created;\n if (nested !== undefined) return nested;\n const flat = message.createdAt;\n if (flat === undefined) return 0;\n // If it's a string (ISO), parse it; otherwise treat as epoch ms\n if (typeof flat === 'string') {\n const parsed = Date.parse(flat);\n return isNaN(parsed) ? 0 : parsed;\n }\n return flat;\n}\n\nfunction getMessageCompleted(message: AssistantRawMessage): number | undefined {\n // Check nested format first, then flat format\n const nested = message.info?.time?.completed;\n if (nested !== undefined) return nested;\n const flat = message.completedAt;\n if (flat === undefined) return undefined;\n if (typeof flat === 'string') {\n const parsed = Date.parse(flat);\n return isNaN(parsed) ? undefined : parsed;\n }\n return flat;\n}\n\nfunction getAssistantText(message: AssistantRawMessage): string {\n // Check parts format first (nested), then flat content\n const parts = message.parts ?? [];\n const textFromParts = (parts ?? [])\n .filter((part) => part.type === 'text' && typeof part.text === 'string')\n .map((part) => part.text?.trim() ?? '')\n .filter(Boolean)\n .join('\\n');\n if (textFromParts) return textFromParts;\n // Fallback to flat content field\n return typeof message.content === 'string' ? message.content.trim() : '';\n}\n\n// Friendly, human-readable labels for the agent's tools so the progress line\n// reads like \"Searching the schema…\" instead of \"Running: bash\". The agent sets\n// a `description` on every bash call (e.g. \"Search for sales-related types in\n// workspace schema\") and a todo list on todowrite — surface those directly.\nconst TOOL_LABELS: Record<string, string> = {\n bash: 'Running a command',\n webfetch: 'Fetching a page',\n 'file.read': 'Reading files',\n 'file.write': 'Writing files',\n 'file.edit': 'Editing files',\n 'file.find.text': 'Searching the code',\n 'file.find.file': 'Looking for files',\n todowrite: 'Planning the steps',\n todoread: 'Reviewing the plan',\n};\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : undefined;\n}\n\n/** Best-effort human summary of what a single tool part is doing right now. */\nfunction describeToolPart(part: AssistantRawMessagePart): string {\n const tool = part.tool ?? 'tool';\n const input = asRecord(part.state?.input);\n\n // bash carries a plain-English `description` of the step — the best signal.\n const description = input?.description;\n if (typeof description === 'string' && description.trim()) return description.trim();\n\n // todowrite carries the todo list — surface the item being worked on.\n const todos = input?.todos;\n if (Array.isArray(todos)) {\n const active = todos.find((todo) => asRecord(todo)?.status === 'in_progress') ?? todos[0];\n const content = asRecord(active)?.content;\n if (typeof content === 'string' && content.trim()) return content.trim();\n }\n\n return TOOL_LABELS[tool] ?? `Running ${tool}`;\n}\n\nfunction getToolProgress(message: AssistantRawMessage): string[] {\n const parts = message.parts ?? [];\n return parts\n .filter((part) => part.type === 'tool' && part.tool)\n .map((part) => {\n const status = part.state?.status ?? 'running';\n const label = describeToolPart(part);\n if (status === 'completed') return `✓ ${label}`;\n if (status === 'failed') return `⚠ ${label}`;\n return `⏳ ${label}…`;\n });\n}\n\nfunction buildProgress(\n messages: AssistantRawMessage[],\n sinceMs: number,\n previousContent?: string,\n previousContentAtMs?: number\n): { content: string; done: boolean } {\n const relevant = messages\n .filter((message) => getMessageRole(message) === 'assistant' && getRawMessageCreatedAt(message) >= sinceMs)\n .sort((left, right) => getRawMessageCreatedAt(left) - getRawMessageCreatedAt(right));\n\n // Debug: log message filtering when no relevant messages found\n if (relevant.length === 0 && messages.length > 0) {\n console.log('[BigConsole-Assistant] buildProgress: no relevant messages', {\n totalMessages: messages.length,\n sinceMs,\n messageRoles: messages.map((m) => getMessageRole(m)),\n messageTimestamps: messages.map((m) => getRawMessageCreatedAt(m)),\n });\n }\n\n let content: string;\n let done: boolean;\n\n if (relevant.length === 0) {\n content = '';\n // Staleness fallback: if no messages have appeared after 15+ seconds of polling,\n // treat the response as complete even when messages get filtered out\n // (e.g., due to timestamp skew or role mismatch).\n done =\n previousContent === content && previousContentAtMs !== undefined && Date.now() - previousContentAtMs >= 15_000;\n } else {\n const latest = relevant[relevant.length - 1]!;\n\n // ACCUMULATE the run, don't just show its last line.\n //\n // The agent emits a message per step, and it now narrates each one and prints\n // a link the moment a create lands (\"✅ Data sink created — [Open …](/…)\").\n // Showing only the newest message threw all of that away a second later: the\n // user saw a lone \"Thinking…\" and none of the links they were promised. Join\n // the whole run instead, so the panel reads as a live account of what is\n // happening and every link stays on screen.\n const narration = relevant.map(getAssistantText).filter(Boolean);\n const toolProgress = getToolProgress(latest);\n content = [...narration, ...toolProgress].join('\\n\\n');\n\n const officiallyDone = Boolean(getMessageCompleted(latest)) && content.length > 0;\n\n // A tool that is still running is proof the turn is alive, so never let the\n // staleness fallback fire underneath it. A single gateway call can sit on the\n // same \"⏳ Creating the data sink…\" line for far longer than the old 15s\n // window, which would have declared the turn finished mid-build.\n const hasRunningTool = (latest.parts ?? []).some(\n (part) => part.type === 'tool' && part.state?.status !== 'completed' && part.state?.status !== 'failed'\n );\n\n const staleDone =\n !officiallyDone &&\n !hasRunningTool &&\n previousContent === content &&\n previousContentAtMs !== undefined &&\n Date.now() - previousContentAtMs >= 45_000;\n\n done = officiallyDone || staleDone;\n }\n\n return { content, done };\n}\n\nfunction getRawMessageId(message: AssistantRawMessage): string | undefined {\n return message.info?.id ?? message.id;\n}\n\n/**\n * The host injects synthetic \"user\" messages into the session (the auth-context\n * file, and a `User's current context:` block describing the open screen). They\n * are plumbing, not something the human typed, so they must never be replayed\n * into the visible transcript.\n */\nconst INJECTED_USER_PREFIXES = ['[Context file:', \"User's current context:\"];\n\nfunction isInjectedContextMessage(text: string): boolean {\n const head = text.trimStart();\n return INJECTED_USER_PREFIXES.some((prefix) => head.startsWith(prefix));\n}\n\n/**\n * Collapse a raw agent session into the user-visible conversation.\n *\n * For each user turn we join every assistant message that carried text — the\n * same accumulation `buildProgress` renders live. That is deliberate: a restored\n * conversation must look like the one the user was actually looking at, and it\n * keeps the per-step \"✅ … [Open the data sink](/…)\" links, which are the whole\n * point of the run. Keeping only the final answer would silently drop them.\n *\n * Tool/step parts carry no text and so fall out on their own — the agent's\n * scratchpad never reaches the chat.\n *\n * Turn boundaries are derived from ordering rather than `parentID` so this also\n * works for backends that return the flat message shape.\n */\nfunction mapSessionToHistory(raw: AssistantRawMessage[]): AssistantHistoryMessage[] {\n const ordered = [...raw].sort((left, right) => getRawMessageCreatedAt(left) - getRawMessageCreatedAt(right));\n\n const history: AssistantHistoryMessage[] = [];\n let pendingUser: { id: string; content: string } | null = null;\n let reply: string[] = [];\n\n const flushTurn = (): void => {\n const turn = pendingUser;\n if (!turn) return;\n history.push({ id: turn.id, role: 'user', content: turn.content });\n if (reply.length > 0) {\n history.push({\n id: `${turn.id}:reply`,\n role: 'assistant',\n content: sanitize(reply.join('\\n\\n')),\n });\n }\n pendingUser = null;\n reply = [];\n };\n\n for (const message of ordered) {\n const role = getMessageRole(message);\n const text = getAssistantText(message);\n\n if (role === 'user') {\n if (!text || isInjectedContextMessage(text)) continue;\n flushTurn();\n pendingUser = {\n id: getRawMessageId(message) ?? `user-${String(history.length)}`,\n content: text,\n };\n } else if (role === 'assistant' && pendingUser && text) {\n // Accumulate every narrated step — mirrors what buildProgress showed live,\n // and preserves the per-step links.\n reply.push(text);\n }\n }\n flushTurn();\n\n return history;\n}\n\n/** The sandbox's placeholder title, which carries no information. */\nconst DEFAULT_SESSION_TITLE = /^AI Assistant\\s*[—-]/i;\nconst SESSION_TITLE_MAX = 60;\n\n/**\n * A human-meaningful label for a past chat: the first thing the user actually\n * typed in it.\n *\n * Falls back to the backend's own title when it has one worth showing (opencode\n * may auto-title a session later), and to \"New chat\" for a session with no\n * prompt in it yet.\n */\nasync function deriveSessionTitle(\n sandboxId: string,\n workspaceId: string,\n session: AssistantRawSession,\n authContext: AssistantSandboxAuthContext\n): Promise<string> {\n const backendTitle = session.title?.trim();\n if (backendTitle && !DEFAULT_SESSION_TITLE.test(backendTitle)) return backendTitle;\n\n try {\n const raw = await getAssistantMessages(sandboxId, workspaceId, session.id, authContext, SESSION_TITLE_PROBE_LIMIT);\n const firstPrompt = [...raw]\n .sort((left, right) => getRawMessageCreatedAt(left) - getRawMessageCreatedAt(right))\n .filter((message) => getMessageRole(message) === 'user')\n .map(getAssistantText)\n .find((text) => text && !isInjectedContextMessage(text));\n\n if (!firstPrompt) return 'New chat';\n const flat = firstPrompt.replace(/\\s+/g, ' ').trim();\n return flat.length > SESSION_TITLE_MAX ? `${flat.slice(0, SESSION_TITLE_MAX - 1)}…` : flat;\n } catch {\n return backendTitle || 'Untitled chat';\n }\n}\n\nfunction sanitize(response: string): string {\n return response\n .replace(/(Authorization\\s*:\\s*Bearer\\s+)[^\\s\\n]+/gi, '$1[REDACTED]')\n .replace(/(X-Workspace-Authorization\\s*:\\s*Bearer\\s+)[^\\s\\n]+/gi, '$1[REDACTED]')\n .replace(/\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9._-]+\\.[A-Za-z0-9._-]+\\b/g, '[REDACTED_JWT]')\n .replace(/\\bsk-ant-[A-Za-z0-9-]+\\b/g, '[REDACTED_API_KEY]');\n}\n\nfunction isRecoverable(error: unknown): boolean {\n const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();\n if (\n message.includes('rate limit exceeded') ||\n message.includes('unauthorized') ||\n message.includes('k8s api error 401')\n ) {\n return false;\n }\n return [\n 'sandbox not found',\n 'sandbox is not running',\n 'sandbox service not available yet',\n 'sandbox failed',\n 'sandbox startup timed out',\n 'assistant service did not become healthy',\n 'proxy error: 404',\n 'proxy error: 502',\n 'proxy error: 503',\n 'unable to connect',\n 'image pull',\n 'container failed',\n 'bootstrap failed',\n // Transient network errors from the browser fetch — gateway CORS preflight\n // failures, mid-stream resets, and Cloudflare 524s all surface as\n // \"Failed to fetch\" via TypeError. They're worth retrying on a clean\n // runtime since the underlying sandbox state is unaffected.\n 'failed to fetch',\n 'cf-proxy timeout',\n // Subgraph returned 500 with a generic message — gateway returns this as\n // a GraphQL error rather than an HTTP error. The actual underlying cause\n // (e.g., transient Prisma timeout) is recoverable, but a fresh sandbox\n // may be needed.\n 'unexpected error',\n ].some((fragment) => message.includes(fragment));\n}\n\n/**\n * Returns a memoized `AssistantTransport` wired to the BigConsole sandbox\n * assistant agent. The sandbox + session are cached in refs so follow-up turns\n * reuse the warm environment for the lifetime of the host shell.\n */\nexport function useSandboxAssistantTransport(): AssistantTransport {\n const { getAccessToken, getWorkspaceToken, userId, workspaceId: ctxWorkspaceId } = useAuthToken();\n\n // Rehydrate the sandbox + session ids persisted by the previous page\n // lifecycle. These were being WRITTEN to sessionStorage but never read back,\n // so every reload silently opened a brand-new agent session: the chat looked\n // empty AND the agent genuinely lost the conversation (it could no longer\n // resolve \"that datasink\" / \"the dashboard you just made\").\n //\n // Restoring both together is what makes history real rather than cosmetic —\n // the transcript we replay into the UI is the same session the agent will\n // keep reasoning over. A stale/expired sandbox is not a problem: `sendPrompt`\n // already treats that as recoverable, drops the refs, and retries clean.\n const [initialSandboxId, initialSessionId] = useMemo(\n () => [readStoredId(SANDBOX_ID_KEY), readStoredId(SESSION_ID_KEY)] as const,\n []\n );\n\n const sandboxIdRef = useRef<string | null>(initialSandboxId);\n const sessionIdRef = useRef<string | null>(initialSessionId);\n\n const persistSandboxId = useCallback((id: string | null) => {\n sandboxIdRef.current = id;\n writeStoredId(SANDBOX_ID_KEY, id);\n }, []);\n\n const persistSessionId = useCallback((id: string | null) => {\n sessionIdRef.current = id;\n writeStoredId(SESSION_ID_KEY, id);\n }, []);\n\n const ensureRuntime = useCallback(\n async (\n workspaceId: string,\n authContext: AssistantSandboxAuthContext\n ): Promise<{ sandboxId: string; sessionId: string }> => {\n let sandboxId = sandboxIdRef.current;\n console.log('[BigConsole-Assistant] ensureRuntime start', { sandboxId, workspaceId });\n if (!sandboxId) {\n if (!getAccessToken()) {\n throw new Error('The assistant requires an authenticated session. Please sign in again.');\n }\n console.log('[BigConsole-Assistant] findExistingSandbox called');\n sandboxId = await findExistingSandbox(workspaceId, MODE, authContext);\n console.log('[BigConsole-Assistant] findExistingSandbox result', { sandboxId });\n\n if (sandboxId) {\n try {\n console.log('[BigConsole-Assistant] waitForSandboxReady called (reused)', { sandboxId });\n await waitForSandboxReady(sandboxId, workspaceId, authContext);\n console.log('[BigConsole-Assistant] waitForSandboxReady done (reused)', { sandboxId });\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady called (reused)', { sandboxId });\n await waitForAssistantServiceReady(sandboxId, workspaceId, MODE, authContext);\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady done (reused)', { sandboxId });\n } catch (error) {\n console.warn('[BigConsole-Assistant] existing sandbox unusable, falling back to fresh sandbox', {\n sandboxId,\n error: error instanceof Error ? error.message : String(error),\n });\n sandboxId = null;\n }\n }\n\n if (!sandboxId) {\n console.log('[BigConsole-Assistant] createAssistantSandbox called');\n sandboxId = await createAssistantSandbox(MODE, workspaceId, authContext);\n console.log('[BigConsole-Assistant] createAssistantSandbox result', { sandboxId });\n console.log('[BigConsole-Assistant] waitForSandboxReady called (fresh)', { sandboxId });\n await waitForSandboxReady(sandboxId, workspaceId, authContext);\n console.log('[BigConsole-Assistant] waitForSandboxReady done (fresh)', { sandboxId });\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady called (fresh)', { sandboxId });\n await waitForAssistantServiceReady(sandboxId, workspaceId, MODE, authContext);\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady done (fresh)', { sandboxId });\n }\n\n persistSandboxId(sandboxId);\n }\n\n let sessionId = sessionIdRef.current;\n console.log('[BigConsole-Assistant] session check', { sessionId, sandboxId });\n if (!sessionId) {\n console.log('[BigConsole-Assistant] createAssistantSession called', { sandboxId, workspaceId });\n const result = await createAssistantSession(sandboxId, workspaceId, MODE, authContext);\n sessionId = result.sessionId;\n persistSessionId(sessionId);\n }\n\n return { sandboxId, sessionId };\n },\n [getAccessToken]\n );\n\n const sendPrompt = useCallback(\n async ({ prompt, onProgress, signal }: AssistantSendArgs): Promise<{ text: string }> => {\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n console.log('[BigConsole-Assistant] sendPrompt called', {\n promptLength: prompt.length,\n workspaceId,\n hasCtxWorkspaceId: !!ctxWorkspaceId,\n authContextKeys: {\n hasAccessToken: !!getAccessToken(),\n hasWorkspaceToken: !!getWorkspaceToken(),\n hasUserId: !!userId,\n },\n locationSearch: window.location.search,\n });\n if (!workspaceId) {\n throw new Error('The assistant needs an active workspace. Open a workspace and try again.');\n }\n const authContext: AssistantSandboxAuthContext = {\n accessToken: getAccessToken(),\n workspaceToken: getWorkspaceToken(),\n userId,\n organizationId: getOrganizationId(),\n };\n console.log('[BigConsole-Assistant] authContext prepared', {\n hasAccessToken: !!authContext.accessToken,\n hasWorkspaceToken: !!authContext.workspaceToken,\n hasUserId: !!authContext.userId,\n hasOrgId: !!authContext.organizationId,\n });\n\n const run = async (attempt: 1 | 2): Promise<{ text: string }> => {\n try {\n console.log('[BigConsole-Assistant] run attempt', attempt);\n const { sandboxId, sessionId } = await ensureRuntime(workspaceId, authContext);\n console.log('[BigConsole-Assistant] ensureRuntime resolved', { sandboxId, sessionId });\n\n const startedAt = Date.now();\n console.log('[BigConsole-Assistant] calling sendAssistantPromptAsync', {\n sandboxId,\n workspaceId,\n sessionId,\n promptLength: prompt.length,\n });\n await sendAssistantPromptAsync(\n sandboxId,\n workspaceId,\n sessionId,\n prompt,\n MODE,\n gatherPageContext(),\n authContext\n );\n\n const timeoutAt = Date.now() + STREAM_BUDGET_MS;\n let lastTtlExtensionAt = Date.now();\n let lastContent = '';\n let lastContentChangeAt = Date.now();\n let progress = buildProgress([], startedAt);\n\n while (Date.now() < timeoutAt) {\n if (signal.aborted) throw new Error('Cancelled');\n\n const messages = await getAssistantMessages(sandboxId, workspaceId, sessionId, authContext, 50);\n console.log('[BigConsole-Assistant] poll', {\n elapsedMs: Date.now() - startedAt,\n messageCount: messages.length,\n firstFewRoles: messages.slice(0, 3).map((m) => getMessageRole(m)),\n firstFewTimestamps: messages.slice(0, 3).map((m) => getRawMessageCreatedAt(m)),\n });\n progress = buildProgress(messages, startedAt, lastContent, lastContentChangeAt);\n console.log('[BigConsole-Assistant] progress', {\n contentPreview: progress.content.slice(0, 100),\n done: progress.done,\n lastContentChangeAt: Date.now() - lastContentChangeAt,\n });\n if (progress.content !== lastContent) {\n lastContent = progress.content;\n lastContentChangeAt = Date.now();\n }\n onProgress(sanitize(progress.content));\n if (progress.done) {\n console.log('[BigConsole-Assistant] progress.done=true, breaking poll loop');\n break;\n }\n\n if (Date.now() - lastTtlExtensionAt > TTL_EXTEND_INTERVAL_MS) {\n await extendAssistantSandboxTTL(sandboxId, workspaceId, 600, authContext).catch(() => undefined);\n lastTtlExtensionAt = Date.now();\n }\n\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n }\n\n if (!progress.done) {\n // Do NOT say \"please try again\". We stopped watching; the agent did\n // not stop working, and anything it already created is real. Telling\n // people to retry is how you get duplicate dashboards.\n throw new Error(\n 'I stopped waiting for a reply, but I may still be working — anything I already created will be there. Check your dashboards and data sinks before asking again, so you do not end up with duplicates.'\n );\n }\n\n return { text: sanitize(progress.content) };\n } catch (error) {\n console.error('[BigConsole-Assistant] run error', {\n attempt,\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n sandboxId: sandboxIdRef.current,\n sessionId: sessionIdRef.current,\n });\n // A stale/expired sandbox or session is recoverable — drop the warm\n // refs and retry once from a clean runtime.\n if (attempt === 1 && isRecoverable(error)) {\n persistSandboxId(null);\n persistSessionId(null);\n return run(2);\n }\n throw error;\n }\n };\n\n return run(1);\n },\n [ctxWorkspaceId, ensureRuntime, getAccessToken, getWorkspaceToken, userId, persistSandboxId, persistSessionId]\n );\n\n /**\n * Rebuild the visible conversation from the agent's own session.\n *\n * The sandbox is the source of truth for the transcript, so we replay from it\n * rather than mirroring messages into localStorage: the UI can then never\n * show a history the agent doesn't actually have. Called by the widget the\n * first time it opens; a no-op on a first-ever visit.\n */\n const loadHistory = useCallback(async (): Promise<AssistantHistoryMessage[]> => {\n const sandboxId = sandboxIdRef.current;\n const sessionId = sessionIdRef.current;\n if (!sandboxId || !sessionId) return [];\n\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n if (!workspaceId || !getAccessToken()) return [];\n\n const authContext: AssistantSandboxAuthContext = {\n accessToken: getAccessToken(),\n workspaceToken: getWorkspaceToken(),\n userId,\n organizationId: getOrganizationId(),\n };\n\n try {\n const raw = await getAssistantMessages(sandboxId, workspaceId, sessionId, authContext, HISTORY_MESSAGE_LIMIT);\n return mapSessionToHistory(raw);\n } catch (error) {\n // The session is gone — sandbox TTL expired, or the workspace was reset.\n // Drop the stale ids so the next prompt provisions a clean runtime instead\n // of repeatedly failing against a dead session.\n console.warn('[BigConsole-Assistant] could not restore history; starting fresh', {\n sandboxId,\n sessionId,\n error: error instanceof Error ? error.message : String(error),\n });\n persistSandboxId(null);\n persistSessionId(null);\n return [];\n }\n }, [ctxWorkspaceId, getAccessToken, getWorkspaceToken, userId, persistSandboxId, persistSessionId]);\n\n // ── Session management (powers the New chat / Clear chat / History rail) ──\n //\n // The sandbox owns the conversations, so every one of these is a thin call\n // onto it rather than client-side bookkeeping — the rail can never show a\n // chat the agent has actually forgotten.\n\n const authFor = useCallback(\n (): AssistantSandboxAuthContext => ({\n accessToken: getAccessToken(),\n workspaceToken: getWorkspaceToken(),\n userId,\n organizationId: getOrganizationId(),\n }),\n [getAccessToken, getWorkspaceToken, userId]\n );\n\n const listSessions = useCallback(async (): Promise<AssistantSessionSummaryLocal[]> => {\n const sandboxId = sandboxIdRef.current;\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n if (!sandboxId || !workspaceId) return [];\n\n try {\n const raw = await listAssistantSessions(sandboxId, workspaceId, authFor());\n const auth = authFor();\n\n const recent = raw\n .map((session) => ({\n session,\n updatedAt: session.time?.updated ?? session.time?.created,\n }))\n .sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))\n .slice(0, SESSION_LIST_LIMIT);\n\n // Title each chat from its own first prompt.\n //\n // The sandbox names every session `AI Assistant — <mode>`, so a History\n // list built from those titles is a column of identical rows — you cannot\n // tell which chat is which, which defeats the point of having it. The\n // first thing the user actually typed is the only title that means\n // anything, so fetch it. Bounded by SESSION_LIST_LIMIT and only ever run\n // when the panel is on screen; a failure degrades to the placeholder\n // rather than emptying the list.\n return await Promise.all(\n recent.map(async ({ session, updatedAt }) => ({\n id: session.id,\n title: await deriveSessionTitle(sandboxId, workspaceId, session, auth),\n updatedAt,\n active: session.id === sessionIdRef.current,\n }))\n );\n } catch {\n return [];\n }\n }, [ctxWorkspaceId, authFor]);\n\n const newSession = useCallback(async (): Promise<void> => {\n const sandboxId = sandboxIdRef.current;\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n\n // No sandbox yet → nothing to detach from; the next prompt provisions one.\n if (!sandboxId || !workspaceId) {\n persistSessionId(null);\n return;\n }\n\n const { sessionId } = await createAssistantSession(sandboxId, workspaceId, MODE, authFor());\n persistSessionId(sessionId);\n }, [ctxWorkspaceId, authFor, persistSessionId]);\n\n const clearSession = useCallback(async (): Promise<void> => {\n const sandboxId = sandboxIdRef.current;\n const sessionId = sessionIdRef.current;\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n\n if (sandboxId && sessionId && workspaceId) {\n // Best-effort: if the delete fails the session is still detached below, so\n // the user gets the empty chat they asked for either way.\n await deleteAssistantSession(sandboxId, workspaceId, sessionId, authFor()).catch(() => undefined);\n }\n persistSessionId(null);\n await newSession();\n }, [ctxWorkspaceId, authFor, persistSessionId, newSession]);\n\n const selectSession = useCallback(\n async (sessionId: string): Promise<AssistantHistoryMessage[]> => {\n const sandboxId = sandboxIdRef.current;\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n if (!sandboxId || !workspaceId) return [];\n\n const raw = await getAssistantMessages(sandboxId, workspaceId, sessionId, authFor(), HISTORY_MESSAGE_LIMIT);\n // Only adopt the session once we know we can actually read it.\n persistSessionId(sessionId);\n return mapSessionToHistory(raw);\n },\n [ctxWorkspaceId, authFor, persistSessionId]\n );\n\n return useMemo<AssistantTransport>(\n () => ({ sendPrompt, loadHistory, listSessions, newSession, clearSession, selectSession }),\n [sendPrompt, loadHistory, listSessions, newSession, clearSession, selectSession]\n );\n}\n"],"mappings":";;;;;AAyFA,IAAM,IAAsB,aAatB,IAAmB,MACnB,IAAmB,MACnB,IAAyB,KAIzB,IAAwB,KAGxB,IAAqB,IAErB,IAA4B,GAE5B,IAAiB,2BACjB,IAAiB;AAEvB,SAAS,EAAa,GAA4B;AAChD,KAAI;AACF,SAAO,OAAO,eAAe,QAAQ,EAAI;SACnC;AAEN,SAAO;;;AAIX,SAAS,EAAc,GAAa,GAAyB;AAC3D,KAAI;AACF,EAAI,IAAI,OAAO,eAAe,QAAQ,GAAK,EAAG,GACzC,OAAO,eAAe,WAAW,EAAI;SACpC;;AAOV,SAAS,EAAuB,GAA+C;AAC7E,KAAI;EACF,IAAM,IACJ,MAAQ,gBAAgB,uCAAuC,yCAC3D,IAAqB,aAAa,QAAQ,EAAiB;AACjE,MAAI,EAAoB,QAAO;EAE/B,IAAM,IAAkB,eAAe,QAAQ,oBAAoB;AACnE,MAAI,CAAC,EAAiB,QAAO;EAC7B,IAAM,IAAM,aAAa,QAAQ,QAAQ,EAAgB,UAAU;AAGnE,SAFK,IACW,KAAK,MAAM,EAAI,CAChB,MAAQ,KAFN;SAGX;AACN,SAAO;;;AAIX,SAAS,EAAe,GAAiC;AAEvD,QADe,IAAI,gBAAgB,OAAO,SAAS,OAAO,CAC5C,IAAI,YAAY,IAAI,EAAuB,cAAc,IAAI,KAAY;;AAGzF,SAAS,IAA4B;AAEnC,QADe,IAAI,gBAAgB,OAAO,SAAS,OAAO,CAC5C,IAAI,MAAM,IAAI,EAAuB,iBAAiB;;AAKtE,SAAS,EAAe,GAAkD;AAExE,QAAO,EAAQ,MAAM,QAAQ,EAAQ;;AAGvC,SAAS,EAAuB,GAAsC;CAEpE,IAAM,IAAS,EAAQ,MAAM,MAAM;AACnC,KAAI,MAAW,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C;EAAgB;EAAS;EAAkB;EAAW,CAAC,EAErD,IAAgB,EACpB,OAAO,MAA0D;EAC/D,IAAM,IAAY,EAAa,SACzB,IAAc,EAAe,EAAe;AAClD,MAAI,CAAC,KAAa,CAAC,EAAa,QAAO,EAAE;EAEzC,IAAM,IAAM,MAAM,EAAqB,GAAW,GAAa,GAAW,GAAS,EAAE,EAAsB;AAG3G,SADA,EAAiB,EAAU,EACpB,EAAoB,EAAI;IAEjC;EAAC;EAAgB;EAAS;EAAiB,CAC5C;AAED,QAAO,SACE;EAAE;EAAY;EAAa;EAAc;EAAY;EAAc;EAAe,GACzF;EAAC;EAAY;EAAa;EAAc;EAAY;EAAc;EAAc,CACjF"}
|
|
1
|
+
{"version":3,"file":"createSandboxAssistantTransport.js","names":[],"sources":["../../../src/bigconsole/assistant/createSandboxAssistantTransport.ts"],"sourcesContent":["/**\n * BigConsole adapter for the shared fe-libs AssistantWidget.\n *\n * The floating widget (fe-libs, Layer 1) is backend-agnostic — it calls an\n * injected `AssistantTransport`. This hook builds a transport that drives the\n * sandbox AI assistant (combined `assistant` mode = docs Q&A + api-calls): it\n * provisions/reuses a sandbox, opens a session, dispatches the prompt async,\n * then polls for the streamed answer. The agent introspects the GraphQL schema\n * and performs API calls on the user's behalf using their workspace token,\n * contextual to the current screen (via `gatherPageContext`).\n *\n * This is a faithful port of microfe-vibecontrols'\n * `services/createSandboxAssistantTransport.ts`; the only product-specific\n * difference lives in `assistantApi.createAssistantSandbox`\n * (`AI_ASSISTANT_PRODUCT=bigconsole`).\n */\n\nimport { useCallback, useMemo, useRef } from 'react';\nimport { useAuthToken } from '@burdenoff/fe-libs/shared/providers/shell';\nimport {\n createAssistantSandbox,\n createAssistantSession,\n deleteAssistantSession,\n extendAssistantSandboxTTL,\n findExistingSandbox,\n getAssistantMessages,\n listAssistantSessions,\n sendAssistantPromptAsync,\n waitForAssistantServiceReady,\n waitForSandboxReady,\n} from './assistantApi';\nimport { gatherPageContext } from './pageContext';\nimport type {\n AssistantMode,\n AssistantRawMessage,\n AssistantRawMessagePart,\n AssistantRawSession,\n AssistantSandboxAuthContext,\n} from './types';\n\n/**\n * Locally-defined mirror of the fe-libs `AssistantTransport` contract.\n *\n * Intentionally NOT imported from `@burdenoff/fe-libs`: microfe's tsconfig maps\n * `@burdenoff/fe-libs/*` to fe-libs *source*, so vite-plugin-dts would rewrite a\n * cross-package type used in this hook's public signature to a broken\n * source-relative path in the emitted `.d.ts`. Structural typing makes this\n * shape assignable to fe-libs' `AssistantTransport` at the call site\n * (bigconsole-app's AppShell), which is where compatibility is enforced.\n */\ninterface AssistantSendArgs {\n prompt: string;\n onProgress: (partialText: string) => void;\n signal: AbortSignal;\n}\n\n/** Mirror of fe-libs' `AssistantWidgetMessage` (see note above on why). */\ninterface AssistantHistoryMessage {\n id: string;\n role: 'user' | 'assistant';\n content: string;\n pending?: boolean;\n error?: boolean;\n}\n\n/** Mirror of fe-libs' `AssistantSessionSummary` (see note above on why). */\ninterface AssistantSessionSummaryLocal {\n id: string;\n title: string;\n updatedAt?: number;\n active?: boolean;\n}\n\nexport interface AssistantTransport {\n sendPrompt: (args: AssistantSendArgs) => Promise<{ text: string }>;\n loadHistory: () => Promise<AssistantHistoryMessage[]>;\n listSessions: () => Promise<AssistantSessionSummaryLocal[]>;\n newSession: () => Promise<void>;\n deleteSession: (sessionId: string) => Promise<void>;\n selectSession: (sessionId: string) => Promise<AssistantHistoryMessage[]>;\n}\n\n// BigConsole still boots the manually-tagged ACA image\n// `alpha-delegated-auth-v11` for the assistant sandbox. The historical\n// platform notes show that this image line reliably supports `api-calls`, while\n// the combined `assistant` mode depends on newer image contracts that are not\n// yet guaranteed on this tag. Use `api-calls` here so the assistant can execute\n// workspace GraphQL operations end-to-end right now. Once the underlying image\n// line is rebuilt and verified for combined mode, this can be switched back.\nconst MODE: AssistantMode = 'api-calls';\n// How long the UI will follow a single turn.\n//\n// This was 180s, which was SHORTER THAN THE WORK. A full \"create a school\n// attendance dashboard\" build — datasink → dashboard → parser → widget, each a\n// separate gateway call preceded by a model round-trip — measured 229s in prod.\n// So the agent finished, the dashboard genuinely existed, and the user was still\n// shown \"the assistant timed out\". That is worse than cosmetic: people retry and\n// end up with duplicate dashboards.\n//\n// 7 minutes covers the observed worst case with headroom. It costs nothing on\n// fast turns (we stop the moment the turn reports done), and the backend keeps\n// pace — the sandbox TTL is extended every TTL_EXTEND_INTERVAL_MS.\nconst STREAM_BUDGET_MS = 420_000;\nconst POLL_INTERVAL_MS = 1500;\nconst TTL_EXTEND_INTERVAL_MS = 30_000;\n// Raw agent messages per restore. The agent emits one message per internal\n// step, so a handful of turns is already dozens of messages — this is a cap on\n// the RAW fetch, not on the number of restored turns.\nconst HISTORY_MESSAGE_LIMIT = 200;\n// The History panel fetches one extra round-trip per chat to title it, so cap\n// how many chats we title at once. Older chats simply are not listed.\nconst SESSION_LIST_LIMIT = 15;\n// Only the first few messages are needed to find the first user prompt.\nconst SESSION_TITLE_PROBE_LIMIT = 8;\n\nconst SANDBOX_ID_KEY = 'bc-assistant-sandbox-id';\nconst SESSION_ID_KEY = 'bc-assistant-session-id';\n\nfunction readStoredId(key: string): string | null {\n try {\n return window.sessionStorage.getItem(key);\n } catch {\n // sessionStorage unavailable (private mode) — degrade to a fresh session.\n return null;\n }\n}\n\nfunction writeStoredId(key: string, id: string | null): void {\n try {\n if (id) window.sessionStorage.setItem(key, id);\n else window.sessionStorage.removeItem(key);\n } catch {\n // Non-fatal: we simply lose cross-reload continuity.\n }\n}\n\n// ── Context helpers (mirror vibecontrols' resolution) ────────────────\n\nfunction getProfileContextValue(key: 'workspaceId' | 'organizationId'): string {\n try {\n const activeContextKey =\n key === 'workspaceId' ? 'burdenoff-active-context-workspace' : 'burdenoff-active-context-organization';\n const activeContextValue = localStorage.getItem(activeContextKey);\n if (activeContextValue) return activeContextValue;\n\n const activeProfileId = sessionStorage.getItem('bf-active-profile');\n if (!activeProfileId) return '';\n const raw = localStorage.getItem(`bf-p-${activeProfileId}-context`);\n if (!raw) return '';\n const context = JSON.parse(raw) as { workspaceId?: string; organizationId?: string };\n return context[key] ?? '';\n } catch {\n return '';\n }\n}\n\nfunction getWorkspaceId(fallback: string | null): string {\n const params = new URLSearchParams(window.location.search);\n return params.get('workspace') ?? getProfileContextValue('workspaceId') ?? fallback ?? '';\n}\n\nfunction getOrganizationId(): string {\n const params = new URLSearchParams(window.location.search);\n return params.get('org') ?? getProfileContextValue('organizationId');\n}\n\n// ── Message-progress helpers (pure; mirror vibecontrols) ─────────────\n\nfunction getMessageRole(message: AssistantRawMessage): string | undefined {\n // Check nested format first, then flat format\n return message.info?.role ?? message.role;\n}\n\nfunction getRawMessageCreatedAt(message: AssistantRawMessage): number {\n // Check nested format first (epoch ms), then flat format (ISO string or epoch ms)\n const nested = message.info?.time?.created;\n if (nested !== undefined) return nested;\n const flat = message.createdAt;\n if (flat === undefined) return 0;\n // If it's a string (ISO), parse it; otherwise treat as epoch ms\n if (typeof flat === 'string') {\n const parsed = Date.parse(flat);\n return isNaN(parsed) ? 0 : parsed;\n }\n return flat;\n}\n\nfunction getMessageCompleted(message: AssistantRawMessage): number | undefined {\n // Check nested format first, then flat format\n const nested = message.info?.time?.completed;\n if (nested !== undefined) return nested;\n const flat = message.completedAt;\n if (flat === undefined) return undefined;\n if (typeof flat === 'string') {\n const parsed = Date.parse(flat);\n return isNaN(parsed) ? undefined : parsed;\n }\n return flat;\n}\n\nfunction getAssistantText(message: AssistantRawMessage): string {\n // Check parts format first (nested), then flat content\n const parts = message.parts ?? [];\n const textFromParts = (parts ?? [])\n .filter((part) => part.type === 'text' && typeof part.text === 'string')\n .map((part) => part.text?.trim() ?? '')\n .filter(Boolean)\n .join('\\n');\n if (textFromParts) return textFromParts;\n // Fallback to flat content field\n return typeof message.content === 'string' ? message.content.trim() : '';\n}\n\n// Friendly, human-readable labels for the agent's tools so the progress line\n// reads like \"Searching the schema…\" instead of \"Running: bash\". The agent sets\n// a `description` on every bash call (e.g. \"Search for sales-related types in\n// workspace schema\") and a todo list on todowrite — surface those directly.\nconst TOOL_LABELS: Record<string, string> = {\n bash: 'Running a command',\n webfetch: 'Fetching a page',\n 'file.read': 'Reading files',\n 'file.write': 'Writing files',\n 'file.edit': 'Editing files',\n 'file.find.text': 'Searching the code',\n 'file.find.file': 'Looking for files',\n todowrite: 'Planning the steps',\n todoread: 'Reviewing the plan',\n};\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : undefined;\n}\n\n/** Best-effort human summary of what a single tool part is doing right now. */\nfunction describeToolPart(part: AssistantRawMessagePart): string {\n const tool = part.tool ?? 'tool';\n const input = asRecord(part.state?.input);\n\n // bash carries a plain-English `description` of the step — the best signal.\n const description = input?.description;\n if (typeof description === 'string' && description.trim()) return description.trim();\n\n // todowrite carries the todo list — surface the item being worked on.\n const todos = input?.todos;\n if (Array.isArray(todos)) {\n const active = todos.find((todo) => asRecord(todo)?.status === 'in_progress') ?? todos[0];\n const content = asRecord(active)?.content;\n if (typeof content === 'string' && content.trim()) return content.trim();\n }\n\n return TOOL_LABELS[tool] ?? `Running ${tool}`;\n}\n\nfunction getToolProgress(message: AssistantRawMessage): string[] {\n const parts = message.parts ?? [];\n return parts\n .filter((part) => part.type === 'tool' && part.tool)\n .map((part) => {\n const status = part.state?.status ?? 'running';\n const label = describeToolPart(part);\n if (status === 'completed') return `✓ ${label}`;\n if (status === 'failed') return `⚠ ${label}`;\n return `⏳ ${label}…`;\n });\n}\n\nfunction buildProgress(\n messages: AssistantRawMessage[],\n sinceMs: number,\n previousContent?: string,\n previousContentAtMs?: number\n): { content: string; done: boolean } {\n const relevant = messages\n .filter((message) => getMessageRole(message) === 'assistant' && getRawMessageCreatedAt(message) >= sinceMs)\n .sort((left, right) => getRawMessageCreatedAt(left) - getRawMessageCreatedAt(right));\n\n // Debug: log message filtering when no relevant messages found\n if (relevant.length === 0 && messages.length > 0) {\n console.log('[BigConsole-Assistant] buildProgress: no relevant messages', {\n totalMessages: messages.length,\n sinceMs,\n messageRoles: messages.map((m) => getMessageRole(m)),\n messageTimestamps: messages.map((m) => getRawMessageCreatedAt(m)),\n });\n }\n\n let content: string;\n let done: boolean;\n\n if (relevant.length === 0) {\n content = '';\n // Staleness fallback: if no messages have appeared after 15+ seconds of polling,\n // treat the response as complete even when messages get filtered out\n // (e.g., due to timestamp skew or role mismatch).\n done =\n previousContent === content && previousContentAtMs !== undefined && Date.now() - previousContentAtMs >= 15_000;\n } else {\n const latest = relevant[relevant.length - 1]!;\n\n // ACCUMULATE the run, don't just show its last line.\n //\n // The agent emits a message per step, and it now narrates each one and prints\n // a link the moment a create lands (\"✅ Data sink created — [Open …](/…)\").\n // Showing only the newest message threw all of that away a second later: the\n // user saw a lone \"Thinking…\" and none of the links they were promised. Join\n // the whole run instead, so the panel reads as a live account of what is\n // happening and every link stays on screen.\n const narration = relevant.map(getAssistantText).filter(Boolean);\n const toolProgress = getToolProgress(latest);\n content = [...narration, ...toolProgress].join('\\n\\n');\n\n const officiallyDone = Boolean(getMessageCompleted(latest)) && content.length > 0;\n\n // A tool that is still running is proof the turn is alive, so never let the\n // staleness fallback fire underneath it. A single gateway call can sit on the\n // same \"⏳ Creating the data sink…\" line for far longer than the old 15s\n // window, which would have declared the turn finished mid-build.\n const hasRunningTool = (latest.parts ?? []).some(\n (part) => part.type === 'tool' && part.state?.status !== 'completed' && part.state?.status !== 'failed'\n );\n\n const staleDone =\n !officiallyDone &&\n !hasRunningTool &&\n previousContent === content &&\n previousContentAtMs !== undefined &&\n Date.now() - previousContentAtMs >= 45_000;\n\n done = officiallyDone || staleDone;\n }\n\n return { content, done };\n}\n\nfunction getRawMessageId(message: AssistantRawMessage): string | undefined {\n return message.info?.id ?? message.id;\n}\n\n/**\n * The host injects synthetic \"user\" messages into the session (the auth-context\n * file, and a `User's current context:` block describing the open screen). They\n * are plumbing, not something the human typed, so they must never be replayed\n * into the visible transcript.\n */\nconst INJECTED_USER_PREFIXES = ['[Context file:', \"User's current context:\"];\n\nfunction isInjectedContextMessage(text: string): boolean {\n const head = text.trimStart();\n return INJECTED_USER_PREFIXES.some((prefix) => head.startsWith(prefix));\n}\n\n/**\n * Collapse a raw agent session into the user-visible conversation.\n *\n * For each user turn we join every assistant message that carried text — the\n * same accumulation `buildProgress` renders live. That is deliberate: a restored\n * conversation must look like the one the user was actually looking at, and it\n * keeps the per-step \"✅ … [Open the data sink](/…)\" links, which are the whole\n * point of the run. Keeping only the final answer would silently drop them.\n *\n * Tool/step parts carry no text and so fall out on their own — the agent's\n * scratchpad never reaches the chat.\n *\n * Turn boundaries are derived from ordering rather than `parentID` so this also\n * works for backends that return the flat message shape.\n */\nfunction mapSessionToHistory(raw: AssistantRawMessage[]): AssistantHistoryMessage[] {\n const ordered = [...raw].sort((left, right) => getRawMessageCreatedAt(left) - getRawMessageCreatedAt(right));\n\n const history: AssistantHistoryMessage[] = [];\n let pendingUser: { id: string; content: string } | null = null;\n let reply: string[] = [];\n\n const flushTurn = (): void => {\n const turn = pendingUser;\n if (!turn) return;\n history.push({ id: turn.id, role: 'user', content: turn.content });\n if (reply.length > 0) {\n history.push({\n id: `${turn.id}:reply`,\n role: 'assistant',\n content: sanitize(reply.join('\\n\\n')),\n });\n }\n pendingUser = null;\n reply = [];\n };\n\n for (const message of ordered) {\n const role = getMessageRole(message);\n const text = getAssistantText(message);\n\n if (role === 'user') {\n if (!text || isInjectedContextMessage(text)) continue;\n flushTurn();\n pendingUser = {\n id: getRawMessageId(message) ?? `user-${String(history.length)}`,\n content: text,\n };\n } else if (role === 'assistant' && pendingUser && text) {\n // Accumulate every narrated step — mirrors what buildProgress showed live,\n // and preserves the per-step links.\n reply.push(text);\n }\n }\n flushTurn();\n\n return history;\n}\n\n/** The sandbox's placeholder title, which carries no information. */\nconst DEFAULT_SESSION_TITLE = /^AI Assistant\\s*[—-]/i;\nconst SESSION_TITLE_MAX = 60;\n\n/**\n * A human-meaningful label for a past chat: the first thing the user actually\n * typed in it.\n *\n * Falls back to the backend's own title when it has one worth showing (opencode\n * may auto-title a session later), and to \"New chat\" for a session with no\n * prompt in it yet.\n */\nasync function deriveSessionTitle(\n sandboxId: string,\n workspaceId: string,\n session: AssistantRawSession,\n authContext: AssistantSandboxAuthContext\n): Promise<string> {\n const backendTitle = session.title?.trim();\n if (backendTitle && !DEFAULT_SESSION_TITLE.test(backendTitle)) return backendTitle;\n\n try {\n const raw = await getAssistantMessages(sandboxId, workspaceId, session.id, authContext, SESSION_TITLE_PROBE_LIMIT);\n const firstPrompt = [...raw]\n .sort((left, right) => getRawMessageCreatedAt(left) - getRawMessageCreatedAt(right))\n .filter((message) => getMessageRole(message) === 'user')\n .map(getAssistantText)\n .find((text) => text && !isInjectedContextMessage(text));\n\n if (!firstPrompt) return 'New chat';\n const flat = firstPrompt.replace(/\\s+/g, ' ').trim();\n return flat.length > SESSION_TITLE_MAX ? `${flat.slice(0, SESSION_TITLE_MAX - 1)}…` : flat;\n } catch {\n return backendTitle || 'Untitled chat';\n }\n}\n\nfunction sanitize(response: string): string {\n return response\n .replace(/(Authorization\\s*:\\s*Bearer\\s+)[^\\s\\n]+/gi, '$1[REDACTED]')\n .replace(/(X-Workspace-Authorization\\s*:\\s*Bearer\\s+)[^\\s\\n]+/gi, '$1[REDACTED]')\n .replace(/\\beyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9._-]+\\.[A-Za-z0-9._-]+\\b/g, '[REDACTED_JWT]')\n .replace(/\\bsk-ant-[A-Za-z0-9-]+\\b/g, '[REDACTED_API_KEY]');\n}\n\nfunction isRecoverable(error: unknown): boolean {\n const message = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();\n if (\n message.includes('rate limit exceeded') ||\n message.includes('unauthorized') ||\n message.includes('k8s api error 401')\n ) {\n return false;\n }\n return [\n 'sandbox not found',\n 'sandbox is not running',\n 'sandbox service not available yet',\n 'sandbox failed',\n 'sandbox startup timed out',\n 'assistant service did not become healthy',\n 'proxy error: 404',\n 'proxy error: 502',\n 'proxy error: 503',\n 'unable to connect',\n 'image pull',\n 'container failed',\n 'bootstrap failed',\n // Transient network errors from the browser fetch — gateway CORS preflight\n // failures, mid-stream resets, and Cloudflare 524s all surface as\n // \"Failed to fetch\" via TypeError. They're worth retrying on a clean\n // runtime since the underlying sandbox state is unaffected.\n 'failed to fetch',\n 'cf-proxy timeout',\n // Subgraph returned 500 with a generic message — gateway returns this as\n // a GraphQL error rather than an HTTP error. The actual underlying cause\n // (e.g., transient Prisma timeout) is recoverable, but a fresh sandbox\n // may be needed.\n 'unexpected error',\n ].some((fragment) => message.includes(fragment));\n}\n\n/**\n * Returns a memoized `AssistantTransport` wired to the BigConsole sandbox\n * assistant agent. The sandbox + session are cached in refs so follow-up turns\n * reuse the warm environment for the lifetime of the host shell.\n */\nexport function useSandboxAssistantTransport(): AssistantTransport {\n const { getAccessToken, getWorkspaceToken, userId, workspaceId: ctxWorkspaceId } = useAuthToken();\n\n // Rehydrate the sandbox + session ids persisted by the previous page\n // lifecycle. These were being WRITTEN to sessionStorage but never read back,\n // so every reload silently opened a brand-new agent session: the chat looked\n // empty AND the agent genuinely lost the conversation (it could no longer\n // resolve \"that datasink\" / \"the dashboard you just made\").\n //\n // Restoring both together is what makes history real rather than cosmetic —\n // the transcript we replay into the UI is the same session the agent will\n // keep reasoning over. A stale/expired sandbox is not a problem: `sendPrompt`\n // already treats that as recoverable, drops the refs, and retries clean.\n const [initialSandboxId, initialSessionId] = useMemo(\n () => [readStoredId(SANDBOX_ID_KEY), readStoredId(SESSION_ID_KEY)] as const,\n []\n );\n\n const sandboxIdRef = useRef<string | null>(initialSandboxId);\n const sessionIdRef = useRef<string | null>(initialSessionId);\n // sessionId -> title. A chat's first prompt never changes, so this is safe to\n // memoise for the life of the page, and it keeps re-opening History free.\n const sessionTitlesRef = useRef<Map<string, string>>(new Map());\n\n const persistSandboxId = useCallback((id: string | null) => {\n sandboxIdRef.current = id;\n writeStoredId(SANDBOX_ID_KEY, id);\n }, []);\n\n const persistSessionId = useCallback((id: string | null) => {\n sessionIdRef.current = id;\n writeStoredId(SESSION_ID_KEY, id);\n }, []);\n\n const ensureRuntime = useCallback(\n async (\n workspaceId: string,\n authContext: AssistantSandboxAuthContext\n ): Promise<{ sandboxId: string; sessionId: string }> => {\n let sandboxId = sandboxIdRef.current;\n console.log('[BigConsole-Assistant] ensureRuntime start', { sandboxId, workspaceId });\n if (!sandboxId) {\n if (!getAccessToken()) {\n throw new Error('The assistant requires an authenticated session. Please sign in again.');\n }\n console.log('[BigConsole-Assistant] findExistingSandbox called');\n sandboxId = await findExistingSandbox(workspaceId, MODE, authContext);\n console.log('[BigConsole-Assistant] findExistingSandbox result', { sandboxId });\n\n if (sandboxId) {\n try {\n console.log('[BigConsole-Assistant] waitForSandboxReady called (reused)', { sandboxId });\n await waitForSandboxReady(sandboxId, workspaceId, authContext);\n console.log('[BigConsole-Assistant] waitForSandboxReady done (reused)', { sandboxId });\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady called (reused)', { sandboxId });\n await waitForAssistantServiceReady(sandboxId, workspaceId, MODE, authContext);\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady done (reused)', { sandboxId });\n } catch (error) {\n console.warn('[BigConsole-Assistant] existing sandbox unusable, falling back to fresh sandbox', {\n sandboxId,\n error: error instanceof Error ? error.message : String(error),\n });\n sandboxId = null;\n }\n }\n\n if (!sandboxId) {\n console.log('[BigConsole-Assistant] createAssistantSandbox called');\n sandboxId = await createAssistantSandbox(MODE, workspaceId, authContext);\n console.log('[BigConsole-Assistant] createAssistantSandbox result', { sandboxId });\n console.log('[BigConsole-Assistant] waitForSandboxReady called (fresh)', { sandboxId });\n await waitForSandboxReady(sandboxId, workspaceId, authContext);\n console.log('[BigConsole-Assistant] waitForSandboxReady done (fresh)', { sandboxId });\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady called (fresh)', { sandboxId });\n await waitForAssistantServiceReady(sandboxId, workspaceId, MODE, authContext);\n console.log('[BigConsole-Assistant] waitForAssistantServiceReady done (fresh)', { sandboxId });\n }\n\n persistSandboxId(sandboxId);\n }\n\n let sessionId = sessionIdRef.current;\n console.log('[BigConsole-Assistant] session check', { sessionId, sandboxId });\n if (!sessionId) {\n console.log('[BigConsole-Assistant] createAssistantSession called', { sandboxId, workspaceId });\n const result = await createAssistantSession(sandboxId, workspaceId, MODE, authContext);\n sessionId = result.sessionId;\n persistSessionId(sessionId);\n }\n\n return { sandboxId, sessionId };\n },\n [getAccessToken]\n );\n\n const sendPrompt = useCallback(\n async ({ prompt, onProgress, signal }: AssistantSendArgs): Promise<{ text: string }> => {\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n console.log('[BigConsole-Assistant] sendPrompt called', {\n promptLength: prompt.length,\n workspaceId,\n hasCtxWorkspaceId: !!ctxWorkspaceId,\n authContextKeys: {\n hasAccessToken: !!getAccessToken(),\n hasWorkspaceToken: !!getWorkspaceToken(),\n hasUserId: !!userId,\n },\n locationSearch: window.location.search,\n });\n if (!workspaceId) {\n throw new Error('The assistant needs an active workspace. Open a workspace and try again.');\n }\n const authContext: AssistantSandboxAuthContext = {\n accessToken: getAccessToken(),\n workspaceToken: getWorkspaceToken(),\n userId,\n organizationId: getOrganizationId(),\n };\n console.log('[BigConsole-Assistant] authContext prepared', {\n hasAccessToken: !!authContext.accessToken,\n hasWorkspaceToken: !!authContext.workspaceToken,\n hasUserId: !!authContext.userId,\n hasOrgId: !!authContext.organizationId,\n });\n\n const run = async (attempt: 1 | 2): Promise<{ text: string }> => {\n try {\n console.log('[BigConsole-Assistant] run attempt', attempt);\n const { sandboxId, sessionId } = await ensureRuntime(workspaceId, authContext);\n console.log('[BigConsole-Assistant] ensureRuntime resolved', { sandboxId, sessionId });\n\n const startedAt = Date.now();\n console.log('[BigConsole-Assistant] calling sendAssistantPromptAsync', {\n sandboxId,\n workspaceId,\n sessionId,\n promptLength: prompt.length,\n });\n await sendAssistantPromptAsync(\n sandboxId,\n workspaceId,\n sessionId,\n prompt,\n MODE,\n gatherPageContext(),\n authContext\n );\n\n const timeoutAt = Date.now() + STREAM_BUDGET_MS;\n let lastTtlExtensionAt = Date.now();\n let lastContent = '';\n let lastContentChangeAt = Date.now();\n let progress = buildProgress([], startedAt);\n\n while (Date.now() < timeoutAt) {\n if (signal.aborted) throw new Error('Cancelled');\n\n const messages = await getAssistantMessages(sandboxId, workspaceId, sessionId, authContext, 50);\n console.log('[BigConsole-Assistant] poll', {\n elapsedMs: Date.now() - startedAt,\n messageCount: messages.length,\n firstFewRoles: messages.slice(0, 3).map((m) => getMessageRole(m)),\n firstFewTimestamps: messages.slice(0, 3).map((m) => getRawMessageCreatedAt(m)),\n });\n progress = buildProgress(messages, startedAt, lastContent, lastContentChangeAt);\n console.log('[BigConsole-Assistant] progress', {\n contentPreview: progress.content.slice(0, 100),\n done: progress.done,\n lastContentChangeAt: Date.now() - lastContentChangeAt,\n });\n if (progress.content !== lastContent) {\n lastContent = progress.content;\n lastContentChangeAt = Date.now();\n }\n onProgress(sanitize(progress.content));\n if (progress.done) {\n console.log('[BigConsole-Assistant] progress.done=true, breaking poll loop');\n break;\n }\n\n if (Date.now() - lastTtlExtensionAt > TTL_EXTEND_INTERVAL_MS) {\n await extendAssistantSandboxTTL(sandboxId, workspaceId, 600, authContext).catch(() => undefined);\n lastTtlExtensionAt = Date.now();\n }\n\n await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));\n }\n\n if (!progress.done) {\n // Do NOT say \"please try again\". We stopped watching; the agent did\n // not stop working, and anything it already created is real. Telling\n // people to retry is how you get duplicate dashboards.\n throw new Error(\n 'I stopped waiting for a reply, but I may still be working — anything I already created will be there. Check your dashboards and data sinks before asking again, so you do not end up with duplicates.'\n );\n }\n\n return { text: sanitize(progress.content) };\n } catch (error) {\n console.error('[BigConsole-Assistant] run error', {\n attempt,\n error: error instanceof Error ? error.message : String(error),\n stack: error instanceof Error ? error.stack : undefined,\n sandboxId: sandboxIdRef.current,\n sessionId: sessionIdRef.current,\n });\n // A stale/expired sandbox or session is recoverable — drop the warm\n // refs and retry once from a clean runtime.\n if (attempt === 1 && isRecoverable(error)) {\n persistSandboxId(null);\n persistSessionId(null);\n return run(2);\n }\n throw error;\n }\n };\n\n return run(1);\n },\n [ctxWorkspaceId, ensureRuntime, getAccessToken, getWorkspaceToken, userId, persistSandboxId, persistSessionId]\n );\n\n /**\n * Rebuild the visible conversation from the agent's own session.\n *\n * The sandbox is the source of truth for the transcript, so we replay from it\n * rather than mirroring messages into localStorage: the UI can then never\n * show a history the agent doesn't actually have. Called by the widget the\n * first time it opens; a no-op on a first-ever visit.\n */\n /**\n * Resolve the sandbox for a READ (history / session list) without provisioning\n * one.\n *\n * Logging out clears sessionStorage, so the sandbox and session ids are gone —\n * but the sandbox itself is still alive on the backend, still holding every\n * conversation. Bailing out on a missing id is why History came back empty\n * after a re-login: we had simply forgotten where the chats were, not lost\n * them. Look the sandbox up instead (a cheap `getActiveSandboxes` query,\n * scoped to this user + workspace).\n *\n * Read-only on purpose: it will adopt a RUNNING sandbox, never create or wake\n * one. Opening the panel must not cost a provision.\n */\n const adoptExistingSandbox = useCallback(\n async (workspaceId: string, authContext: AssistantSandboxAuthContext): Promise<string | null> => {\n if (sandboxIdRef.current) return sandboxIdRef.current;\n try {\n const found = await findExistingSandbox(workspaceId, MODE, authContext);\n if (found) persistSandboxId(found);\n return found;\n } catch {\n return null;\n }\n },\n [persistSandboxId]\n );\n\n const loadHistory = useCallback(async (): Promise<AssistantHistoryMessage[]> => {\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n if (!workspaceId || !getAccessToken()) return [];\n\n const auth: AssistantSandboxAuthContext = {\n accessToken: getAccessToken(),\n workspaceToken: getWorkspaceToken(),\n userId,\n organizationId: getOrganizationId(),\n };\n\n const sandboxId = await adoptExistingSandbox(workspaceId, auth);\n if (!sandboxId) return [];\n\n // After a re-login we know the sandbox but not which conversation the user\n // was in. Reopen the most recent one so they land back where they left off\n // instead of in a blank chat with their history hidden behind a menu.\n let sessionId = sessionIdRef.current;\n if (!sessionId) {\n try {\n const sessions = await listAssistantSessions(sandboxId, workspaceId, auth);\n const newest = [...sessions].sort(\n (left, right) =>\n (right.time?.updated ?? right.time?.created ?? 0) - (left.time?.updated ?? left.time?.created ?? 0)\n )[0];\n if (!newest) return [];\n sessionId = newest.id;\n persistSessionId(sessionId);\n } catch {\n return [];\n }\n }\n\n try {\n const raw = await getAssistantMessages(sandboxId, workspaceId, sessionId, auth, HISTORY_MESSAGE_LIMIT);\n return mapSessionToHistory(raw);\n } catch (error) {\n // The session is gone — sandbox TTL expired, or the workspace was reset.\n // Drop the stale ids so the next prompt provisions a clean runtime instead\n // of repeatedly failing against a dead session.\n console.warn('[BigConsole-Assistant] could not restore history; starting fresh', {\n sandboxId,\n sessionId,\n error: error instanceof Error ? error.message : String(error),\n });\n persistSandboxId(null);\n persistSessionId(null);\n return [];\n }\n }, [\n ctxWorkspaceId,\n getAccessToken,\n getWorkspaceToken,\n userId,\n persistSandboxId,\n persistSessionId,\n adoptExistingSandbox,\n ]);\n\n // ── Session management (powers the New chat / Clear chat / History rail) ──\n //\n // The sandbox owns the conversations, so every one of these is a thin call\n // onto it rather than client-side bookkeeping — the rail can never show a\n // chat the agent has actually forgotten.\n\n const authFor = useCallback(\n (): AssistantSandboxAuthContext => ({\n accessToken: getAccessToken(),\n workspaceToken: getWorkspaceToken(),\n userId,\n organizationId: getOrganizationId(),\n }),\n [getAccessToken, getWorkspaceToken, userId]\n );\n\n const listSessions = useCallback(async (): Promise<AssistantSessionSummaryLocal[]> => {\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n if (!workspaceId) return [];\n const auth = authFor();\n\n // Same story as loadHistory: after a re-login we've forgotten where the\n // chats are, not lost them. Find the sandbox before giving up.\n const sandboxId = await adoptExistingSandbox(workspaceId, auth);\n if (!sandboxId) return [];\n\n try {\n const raw = await listAssistantSessions(sandboxId, workspaceId, auth);\n\n const recent = raw\n .map((session) => ({\n session,\n updatedAt: session.time?.updated ?? session.time?.created,\n }))\n .sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))\n .slice(0, SESSION_LIST_LIMIT);\n\n // Title each chat from its own first prompt.\n //\n // The sandbox names every session `AI Assistant — <mode>`, so a History\n // list built from those titles is a column of identical rows — you cannot\n // tell which chat is which, which defeats the point of having it. The\n // first thing the user actually typed is the only title that means\n // anything, so fetch it.\n //\n // Titles are memoised per session id: a chat's first prompt never changes,\n // so re-opening History (or refreshing it after a turn) costs nothing. That\n // matters — without the cache this was one extra round-trip per chat on\n // every single open, which is what made the panel feel slow.\n return await Promise.all(\n recent.map(async ({ session, updatedAt }) => {\n const cached = sessionTitlesRef.current.get(session.id);\n const title = cached ?? (await deriveSessionTitle(sandboxId, workspaceId, session, auth));\n if (!cached && title !== 'New chat') sessionTitlesRef.current.set(session.id, title);\n return {\n id: session.id,\n title,\n updatedAt,\n active: session.id === sessionIdRef.current,\n };\n })\n );\n } catch {\n return [];\n }\n }, [ctxWorkspaceId, authFor, adoptExistingSandbox]);\n\n /**\n * Start a new chat — instantly.\n *\n * This used to create the session on the sandbox and await the round-trip, and\n * the caller then refreshed the History list (one fetch per chat to title it).\n * Clicking \"New chat\" while History was open therefore paid for all of that\n * before the screen cleared, which is why it felt like it hung.\n *\n * None of that work is necessary. Detaching locally is enough: `ensureRuntime`\n * already creates a session on the next prompt if there isn't one. So this is\n * now pure local state — the chat clears immediately, and the session is\n * created lazily when the user actually says something.\n *\n * It also stops littering the History list with empty \"New chat\" rows for\n * sessions the user opened and never used.\n */\n const newSession = useCallback(async (): Promise<void> => {\n persistSessionId(null);\n return Promise.resolve();\n }, [persistSessionId]);\n\n /**\n * Delete one conversation.\n *\n * Replaces the old \"Clear chat\" button, which could only ever remove whichever\n * chat happened to be open — ambiguous, and useless for tidying up an old one.\n * A delete control on each History row says exactly what it will remove.\n */\n const deleteSession = useCallback(\n async (sessionId: string): Promise<void> => {\n const sandboxId = sandboxIdRef.current;\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n if (!sandboxId || !workspaceId) return;\n\n await deleteAssistantSession(sandboxId, workspaceId, sessionId, authFor());\n sessionTitlesRef.current.delete(sessionId);\n\n // Deleting the chat you're looking at leaves you in a fresh one.\n if (sessionIdRef.current === sessionId) persistSessionId(null);\n },\n [ctxWorkspaceId, authFor, persistSessionId]\n );\n\n const selectSession = useCallback(\n async (sessionId: string): Promise<AssistantHistoryMessage[]> => {\n const sandboxId = sandboxIdRef.current;\n const workspaceId = getWorkspaceId(ctxWorkspaceId);\n if (!sandboxId || !workspaceId) return [];\n\n const raw = await getAssistantMessages(sandboxId, workspaceId, sessionId, authFor(), HISTORY_MESSAGE_LIMIT);\n // Only adopt the session once we know we can actually read it.\n persistSessionId(sessionId);\n return mapSessionToHistory(raw);\n },\n [ctxWorkspaceId, authFor, persistSessionId]\n );\n\n return useMemo<AssistantTransport>(\n () => ({ sendPrompt, loadHistory, listSessions, newSession, deleteSession, selectSession }),\n [sendPrompt, loadHistory, listSessions, newSession, deleteSession, selectSession]\n );\n}\n"],"mappings":";;;;;AAyFA,IAAM,IAAsB,aAatB,IAAmB,MACnB,IAAmB,MACnB,IAAyB,KAIzB,IAAwB,KAGxB,IAAqB,IAErB,IAA4B,GAE5B,IAAiB,2BACjB,IAAiB;AAEvB,SAAS,EAAa,GAA4B;AAChD,KAAI;AACF,SAAO,OAAO,eAAe,QAAQ,EAAI;SACnC;AAEN,SAAO;;;AAIX,SAAS,EAAc,GAAa,GAAyB;AAC3D,KAAI;AACF,EAAI,IAAI,OAAO,eAAe,QAAQ,GAAK,EAAG,GACzC,OAAO,eAAe,WAAW,EAAI;SACpC;;AAOV,SAAS,EAAuB,GAA+C;AAC7E,KAAI;EACF,IAAM,IACJ,MAAQ,gBAAgB,uCAAuC,yCAC3D,IAAqB,aAAa,QAAQ,EAAiB;AACjE,MAAI,EAAoB,QAAO;EAE/B,IAAM,IAAkB,eAAe,QAAQ,oBAAoB;AACnE,MAAI,CAAC,EAAiB,QAAO;EAC7B,IAAM,IAAM,a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