@openchambery/web 1.19.13 → 1.19.15-beta.1
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/assets/{AgentAvatar-mbvX7YlW.js → AgentAvatar-m1jNq4bX.js} +1 -1
- package/dist/assets/AssistantView-D5rEZ-Ss.js +2 -0
- package/dist/assets/{DiagramView-BdI4PT2H.js → DiagramView-DaB9Sb7S.js} +1 -1
- package/dist/assets/{FadeInOnReveal-moBbL8Ll.js → FadeInOnReveal-UGwClbL_.js} +1 -1
- package/dist/assets/Icon-D1BcR8Tz.js +1 -0
- package/dist/assets/MarkdownRenderer-emLeoNjI.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-2ewbRZE2.js → MarkdownRendererImpl-BWCAPlqn.js} +3 -3
- package/dist/assets/{MarkstreamRendererImpl-DXewO7S_.js → MarkstreamRendererImpl-BD_NFKUv.js} +2 -2
- package/dist/assets/MobileDetailNavigation-DqXVAIap.js +1 -0
- package/dist/assets/MobileShareBridge-Bk2fdkJk.js +4 -0
- package/dist/assets/MobileSurface-C4mpcOCh.js +2 -0
- package/dist/assets/{MultiRunWindow-C8ukIdLA.js → MultiRunWindow-rs49_K1E.js} +1 -1
- package/dist/assets/{OnboardingScreen-j0iCyH7f.js → OnboardingScreen-bIWeMLVx.js} +1 -1
- package/dist/assets/{OverlayScrollbar-CDC5B3RH.js → OverlayScrollbar-Bahg_P3r.js} +1 -1
- package/dist/assets/SettingsView-b8LUjoad.js +25 -0
- package/dist/assets/{SettingsWindow-CSePZ_V8.js → SettingsWindow-D8JFlPdA.js} +1 -1
- package/dist/assets/{TerminalView-BmSIrZ81.js → TerminalView-DCd-Godi.js} +1 -1
- package/dist/assets/{ToolOutputDialog-2BYaWLo1.js → ToolOutputDialog-B50L_nUP.js} +1 -1
- package/dist/assets/{appThemeRegistry-Dk4gBaOu.js → appThemeRegistry-BWtCaTMe.js} +1 -1
- package/dist/assets/{button-xx1UOBA5.js → button-9R-WgVMl.js} +1 -1
- package/dist/assets/{clipboard-CUasgPiF.js → clipboard-GUUNlWIv.js} +1 -1
- package/dist/assets/{collapsible-CACHBRYZ.js → collapsible-Bbz9KiJf.js} +1 -1
- package/dist/assets/{context-menu-CYbm4wBZ.js → context-menu-CSyOhRz8.js} +1 -1
- package/dist/assets/{desktopHosts-DILvrAok.js → desktopHosts-B052a4UK.js} +1 -1
- package/dist/assets/{desktopRelayRestore-t8asCr3m.js → desktopRelayRestore-OjKNXr10.js} +1 -1
- package/dist/assets/{diagram-u0BC9uuY.js → diagram-NdsZih8P.js} +1 -1
- package/dist/assets/{dialog-BwQ3rY_x.js → dialog-DhMGbF_B.js} +1 -1
- package/dist/assets/{es-CRjOwvYM.js → es-BQb6I8gl.js} +2 -2
- package/dist/assets/fileMentionTouchSelection-DKYkoypI.js +4 -0
- package/dist/assets/{fileQueries-Bgly-E8f.js → fileQueries-B_s_B-fH.js} +1 -1
- package/dist/assets/{fr-D9taEN9L.js → fr-BjGouC_l.js} +2 -2
- package/dist/assets/{gitApi-DtPf-h-O.js → gitApi-D4PyYgLZ.js} +3 -3
- package/dist/assets/{input-CI730njs.js → input-Cd_1HyQv.js} +1 -1
- package/dist/assets/insertionBoundaries-Bnnx03Wj.js +1 -0
- package/dist/assets/{ja-CYQ5aoWp.js → ja-Cw9zliYY.js} +2 -2
- package/dist/assets/{ko-BwASV0Q0.js → ko-Dyz0Dk9b.js} +2 -2
- package/dist/assets/main-BRiQTNFX.js +169 -0
- package/dist/assets/{main-Ci3JmtpW.js → main-CnY0LWNc.js} +2 -2
- package/dist/assets/{markdownHeightCache-DEjGKLv8.js → markdownHeightCache-BL8CUQ0M.js} +1 -1
- package/dist/assets/miniChat-B0pw_mUs.js +2 -0
- package/dist/assets/mobile-BKHmxwXz.js +2 -0
- package/dist/assets/{multirun-CmaTeZON.js → multirun-BQKqVfFT.js} +1 -1
- package/dist/assets/{persistence-YbQKzHUQ.js → persistence-DwRBC4zl.js} +2 -2
- package/dist/assets/{pl-DUI1vPil.js → pl-C7EY-dTH.js} +1 -1
- package/dist/assets/platform-DQ5_LNKO.js +2 -0
- package/dist/assets/{projectMeta-cw9nrwpr.js → projectMeta-BvG8sdtC.js} +2 -2
- package/dist/assets/{pt-BR-CZQFJllP.js → pt-BR-B1uHpjFW.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-E5a0yy7E.js +2 -0
- package/dist/assets/renderMobileApp-DT0L4Ah6.js +28 -0
- package/dist/assets/{runtimeConfig-DI8l0VyZ.js → runtimeConfig-utWzrDwa.js} +1 -1
- package/dist/assets/runtimeEndpointReset-DE6lwHyg.js +147 -0
- package/dist/assets/sessionChangeSummary-BG7l2heP.js +2 -0
- package/dist/assets/sessionLookup-12zVOR0J.js +1 -0
- package/dist/assets/{sortable-tabs-strip-Dom6Sthu.js → sortable-tabs-strip-dYW6SH62.js} +1 -1
- package/dist/assets/src-CFUi4riW.css +2 -0
- package/dist/assets/{store-CSnH_QXM.js → store-ClnJdJSj.js} +3 -3
- package/dist/assets/{terminalApi-noa4Cdbh.js → terminalApi-CfgOfnZk.js} +1 -1
- package/dist/assets/{textarea-BfNtUdJE.js → textarea-B9CmN13Z.js} +1 -1
- package/dist/assets/{tooltip-DPxumadF.js → tooltip-DSjr26A_.js} +1 -1
- package/dist/assets/{uk-C1FYZlmA.js → uk-DgG8v2md.js} +2 -2
- package/dist/assets/{url-CVhsI9kR.js → url-CMQwHq4k.js} +1 -1
- package/dist/assets/{useAppFontEffects-BDFUND4v.js → useAppFontEffects-BhYuP4L2.js} +43 -44
- package/dist/assets/useDesktopWindowControlsLayout-DPNMRkrI.js +1 -0
- package/dist/assets/{useEffectiveDirectory-e9HjIqGz.js → useEffectiveDirectory-Ji8AKgzY.js} +1 -1
- package/dist/assets/{useFontPreferences-CB-cGo3I.js → useFontPreferences-DCaY8NbU.js} +1 -1
- package/dist/assets/useMobileNavigationStore-BYdpuwL7.js +413 -0
- package/dist/assets/useSessionAutoCleanup-CADZCvZL.js +2 -0
- package/dist/assets/{useWorkerHighlightedLines-DTGE0CDs.js → useWorkerHighlightedLines-CuG88Lsj.js} +1 -1
- package/dist/assets/{utils-BHTVlVov.js → utils-2ZK8yboQ.js} +1 -1
- package/dist/assets/{vendor-reactuses-core-DDoDDyM9.js → vendor-reactuses-core-BnW6GxJt.js} +1 -1
- package/dist/assets/{zh-CN-C96qP1ip.js → zh-CN-C6OFKjeT.js} +2 -2
- package/dist/assets/{zh-TW-BsRk1Rbb.js → zh-TW-BVP99aMr.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/mini-chat.html +8 -8
- package/dist/mobile.html +8 -8
- package/package.json +1 -1
- package/server/index.js +1 -0
- package/server/lib/assistants/DOCUMENTATION.md +120 -22
- package/server/lib/assistants/assign.js +117 -12
- package/server/lib/assistants/assign.test.js +79 -0
- package/server/lib/assistants/bubbles.js +1 -1
- package/server/lib/assistants/contact-store.js +520 -11
- package/server/lib/assistants/contact-store.test.js +362 -12
- package/server/lib/assistants/contact-tools.js +305 -54
- package/server/lib/assistants/contact-tools.test.js +239 -7
- package/server/lib/assistants/contracts.js +31 -0
- package/server/lib/assistants/harness.js +295 -132
- package/server/lib/assistants/harness.test.js +662 -10
- package/server/lib/assistants/pi-tools.js +2 -0
- package/server/lib/assistants/pi-tools.test.js +8 -0
- package/server/lib/assistants/routes.js +3 -0
- package/server/lib/assistants/service.js +861 -79
- package/server/lib/assistants/service.test.js +1234 -8
- package/server/lib/llm/DOCUMENTATION.md +10 -3
- package/server/lib/llm/completions.js +4 -0
- package/server/lib/llm/completions.test.js +3 -0
- package/server/lib/llm/generate.js +57 -11
- package/server/lib/llm/generate.test.js +92 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/dist/assets/AssistantView-CKmIS1cS.js +0 -2
- package/dist/assets/Icon-CkzzhaLr.js +0 -1
- package/dist/assets/MarkdownRenderer-CLQ4Z8Z0.js +0 -2
- package/dist/assets/MobileDetailNavigation-BGaAyuBH.js +0 -1
- package/dist/assets/MobileShareBridge-BAZoyeIP.js +0 -4
- package/dist/assets/MobileSurface-BVb3xNWt.js +0 -2
- package/dist/assets/SettingsView-CkQ61pbr.js +0 -25
- package/dist/assets/insertionBoundaries-BMhzPFft.js +0 -4
- package/dist/assets/main-BjeOhdcG.js +0 -169
- package/dist/assets/miniChat-BYrjYEXJ.js +0 -2
- package/dist/assets/mobile-BVMNnPK2.js +0 -2
- package/dist/assets/platform-DzsGqlGW.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-COwia8Cs.js +0 -2
- package/dist/assets/renderMobileApp-CXwwpY1t.js +0 -28
- package/dist/assets/runtimeEndpointReset-BkAQXmXJ.js +0 -147
- package/dist/assets/sessionChangeSummary-DQDZ5HW-.js +0 -1
- package/dist/assets/sessionLookup-Imc995rW.js +0 -1
- package/dist/assets/src-AA-5nXsF.css +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-C5hZD1co.js +0 -1
- package/dist/assets/useMobileNavigationStore-CYbDxRTM.js +0 -413
- package/dist/assets/useSessionAutoCleanup-BGy9_AhN.js +0 -2
|
@@ -47,9 +47,14 @@ The 1.18.4 client exposes `GET /provider`, `GET /config/providers`, and
|
|
|
47
47
|
`attachment`). Non-vision models (for example deepseek-v4-flash) keep the
|
|
48
48
|
`[image: …]` description and any text-file bytes, and skip image data URLs so
|
|
49
49
|
generate cannot stall on unsupported vision parts. Non-image text files are
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
also inlined into the flattened prompt. Wait for idle via `session.status` +
|
|
51
|
+
`session.messages`; a deterministic `session.messages` SDK error (for example
|
|
52
|
+
HTTP 400) fails generate immediately. The generator deadline is a **stall**
|
|
53
|
+
timer (`GENERATE_TIMEOUT_MS` = 90s), not a wall-clock cap. Busy / retry
|
|
54
|
+
session status, an incomplete assistant message, and throwaway
|
|
55
|
+
`message.part.delta` tokens reset the stall timer — a live model must not
|
|
56
|
+
look like "no response".
|
|
57
|
+
Then delete the session and surface
|
|
53
58
|
delete SDK errors in diagnostics without erasing a successful text result.
|
|
54
59
|
Throwaway sessions use `metadata.openchamber.llm.purpose = 'chat-completions'`
|
|
55
60
|
(and archived immediately) so sidebar visibility, session-index, session-title,
|
|
@@ -106,3 +111,5 @@ The Assistant contact harness owns system prompt, OpenChamber transcript,
|
|
|
106
111
|
bubble splitting, and OpenChamber API tools (`assign_session`). Those tools
|
|
107
112
|
deliver through contact **cards**, not this completions payload. The gateway
|
|
108
113
|
stays a text generator: OpenCode coding tools stay denied.
|
|
114
|
+
|
|
115
|
+
Internal completion/generate calls accept an optional AbortSignal from the contact continuation. It is combined with the stall generator deadline and passed to upstream requests and settle polling. Cancellation still runs throwaway-session cleanup; it must not turn a late model response into a new tool operation.
|
|
@@ -78,7 +78,9 @@ export async function createChatCompletion({
|
|
|
78
78
|
fetchImpl,
|
|
79
79
|
onTextDelta = null,
|
|
80
80
|
globalEventHub = null,
|
|
81
|
+
signal = null,
|
|
81
82
|
}) {
|
|
83
|
+
signal?.throwIfAborted();
|
|
82
84
|
if (!isRecord(body)) throw new LlmError('validation_error', 400, 'JSON body is required');
|
|
83
85
|
// Bundled OpenCode 1.18.4 generate is a full-turn JSON reply (sessionless
|
|
84
86
|
// generate or throwaway session.promptAsync). This HTTP gateway does not
|
|
@@ -100,6 +102,7 @@ export async function createChatCompletion({
|
|
|
100
102
|
provider: { list: async () => ({ error: { status: 500 } }) },
|
|
101
103
|
config: { providers: async () => ({ error: { status: 500 } }) },
|
|
102
104
|
});
|
|
105
|
+
signal?.throwIfAborted();
|
|
103
106
|
if (!isConnectedModel(catalog, resolved.providerID, resolved.modelID)) {
|
|
104
107
|
throw new LlmError(
|
|
105
108
|
'no_provider',
|
|
@@ -124,6 +127,7 @@ export async function createChatCompletion({
|
|
|
124
127
|
))?.acceptsImages),
|
|
125
128
|
onTextDelta,
|
|
126
129
|
globalEventHub,
|
|
130
|
+
signal,
|
|
127
131
|
});
|
|
128
132
|
} catch (error) {
|
|
129
133
|
if (error instanceof LlmError) throw error;
|
|
@@ -50,6 +50,7 @@ describe('createChatCompletion', () => {
|
|
|
50
50
|
it('forwards in-process onTextDelta and globalEventHub to generateText', async () => {
|
|
51
51
|
const generateText = vi.fn(async () => ({ text: 'streamed', source: 'throwaway-session' }))
|
|
52
52
|
const onTextDelta = vi.fn()
|
|
53
|
+
const signal = new AbortController().signal
|
|
53
54
|
const globalEventHub = { subscribeEvent: vi.fn() }
|
|
54
55
|
await createChatCompletion({
|
|
55
56
|
generateText,
|
|
@@ -60,9 +61,11 @@ describe('createChatCompletion', () => {
|
|
|
60
61
|
body: { model: 'openai/gpt-5.2', messages: [{ role: 'user', content: 'hi' }] },
|
|
61
62
|
onTextDelta,
|
|
62
63
|
globalEventHub,
|
|
64
|
+
signal,
|
|
63
65
|
})
|
|
64
66
|
expect(generateText.mock.calls[0][0].onTextDelta).toBe(onTextDelta)
|
|
65
67
|
expect(generateText.mock.calls[0][0].globalEventHub).toBe(globalEventHub)
|
|
68
|
+
expect(generateText.mock.calls[0][0].signal).toBe(signal)
|
|
66
69
|
})
|
|
67
70
|
|
|
68
71
|
it('forwards optional file parts on user messages', async () => {
|
|
@@ -6,6 +6,10 @@ const SETTLE_POLL_MS = 250;
|
|
|
6
6
|
const INCOMPLETE_ASSISTANT_SETTLE_PROBES = 2;
|
|
7
7
|
const EMPTY_IDLE_PROBES = 5;
|
|
8
8
|
|
|
9
|
+
const positiveMs = (value, fallback) => (
|
|
10
|
+
Number.isFinite(value) && value > 0 ? Math.trunc(value) : fallback
|
|
11
|
+
);
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* Session-level deny-all. OpenCode 1.18 session.create serializes this
|
|
11
15
|
* PermissionRuleset shape (permission/pattern/action). Confirmed on local
|
|
@@ -66,7 +70,10 @@ const sleep = (ms, signal) => new Promise((resolve, reject) => {
|
|
|
66
70
|
reject(signal.reason instanceof Error ? signal.reason : new Error('aborted'));
|
|
67
71
|
return;
|
|
68
72
|
}
|
|
69
|
-
const timer = setTimeout(
|
|
73
|
+
const timer = setTimeout(() => {
|
|
74
|
+
signal?.removeEventListener?.('abort', onAbort);
|
|
75
|
+
resolve();
|
|
76
|
+
}, ms);
|
|
70
77
|
const onAbort = () => {
|
|
71
78
|
clearTimeout(timer);
|
|
72
79
|
reject(signal.reason instanceof Error ? signal.reason : new Error('aborted'));
|
|
@@ -135,9 +142,17 @@ const deniedTools = (ids) => {
|
|
|
135
142
|
return tools;
|
|
136
143
|
};
|
|
137
144
|
|
|
138
|
-
const waitForIdleAssistant = async ({
|
|
145
|
+
const waitForIdleAssistant = async ({
|
|
146
|
+
client,
|
|
147
|
+
sessionID,
|
|
148
|
+
directory,
|
|
149
|
+
signal,
|
|
150
|
+
onProgress = null,
|
|
151
|
+
settlePollMs = SETTLE_POLL_MS,
|
|
152
|
+
}) => {
|
|
139
153
|
let incompleteAssistantProbes = 0;
|
|
140
154
|
let emptyIdleProbes = 0;
|
|
155
|
+
const pollMs = positiveMs(settlePollMs, SETTLE_POLL_MS);
|
|
141
156
|
|
|
142
157
|
for (;;) {
|
|
143
158
|
signal?.throwIfAborted?.();
|
|
@@ -157,7 +172,8 @@ const waitForIdleAssistant = async ({ client, sessionID, directory, signal }) =>
|
|
|
157
172
|
if (sessionBusy) {
|
|
158
173
|
incompleteAssistantProbes = 0;
|
|
159
174
|
emptyIdleProbes = 0;
|
|
160
|
-
|
|
175
|
+
onProgress?.();
|
|
176
|
+
await sleep(pollMs, signal);
|
|
161
177
|
continue;
|
|
162
178
|
}
|
|
163
179
|
|
|
@@ -183,6 +199,7 @@ const waitForIdleAssistant = async ({ client, sessionID, directory, signal }) =>
|
|
|
183
199
|
return messagesResult.data;
|
|
184
200
|
}
|
|
185
201
|
incompleteAssistantProbes += 1;
|
|
202
|
+
onProgress?.();
|
|
186
203
|
if (incompleteAssistantProbes >= INCOMPLETE_ASSISTANT_SETTLE_PROBES) {
|
|
187
204
|
return messagesResult.data;
|
|
188
205
|
}
|
|
@@ -199,7 +216,7 @@ const waitForIdleAssistant = async ({ client, sessionID, directory, signal }) =>
|
|
|
199
216
|
if (error?.code === 'upstream_error') throw error;
|
|
200
217
|
}
|
|
201
218
|
|
|
202
|
-
await sleep(
|
|
219
|
+
await sleep(pollMs, signal);
|
|
203
220
|
}
|
|
204
221
|
};
|
|
205
222
|
|
|
@@ -441,7 +458,11 @@ export async function generateOpenCodeText({
|
|
|
441
458
|
forwardImageParts = false,
|
|
442
459
|
onTextDelta = null,
|
|
443
460
|
globalEventHub = null,
|
|
461
|
+
signal: parentSignal = null,
|
|
462
|
+
timeoutMs = GENERATE_TIMEOUT_MS,
|
|
463
|
+
settlePollMs = SETTLE_POLL_MS,
|
|
444
464
|
}) {
|
|
465
|
+
parentSignal?.throwIfAborted();
|
|
445
466
|
if (!providerID || !modelID) {
|
|
446
467
|
const error = new Error('providerID and modelID are required');
|
|
447
468
|
error.code = 'validation_error';
|
|
@@ -458,8 +479,26 @@ export async function generateOpenCodeText({
|
|
|
458
479
|
const baseUrl = buildOpenCodeUrl('/', '').replace(/\/$/, '');
|
|
459
480
|
const headers = getOpenCodeAuthHeaders() || {};
|
|
460
481
|
const probe = await detect({ fetchImpl, baseUrl, headers, client: clientFactory?.() });
|
|
482
|
+
parentSignal?.throwIfAborted();
|
|
461
483
|
const controller = new AbortController();
|
|
462
|
-
const
|
|
484
|
+
const requestSignal = parentSignal ? AbortSignal.any([parentSignal, controller.signal]) : controller.signal;
|
|
485
|
+
const stallMs = positiveMs(timeoutMs, GENERATE_TIMEOUT_MS);
|
|
486
|
+
const abortGenerate = (message) => {
|
|
487
|
+
if (controller.signal.aborted) return;
|
|
488
|
+
controller.abort(new Error(message));
|
|
489
|
+
};
|
|
490
|
+
// Idle deadline only: live busy/delta/incomplete assistant progress
|
|
491
|
+
// must not look like "the model hung". There is no wall-clock cap.
|
|
492
|
+
let stallTimer = setTimeout(() => {
|
|
493
|
+
abortGenerate(`OpenCode LLM generate timed out after ${stallMs}ms without progress`);
|
|
494
|
+
}, stallMs);
|
|
495
|
+
const bumpTimeout = () => {
|
|
496
|
+
if (controller.signal.aborted) return;
|
|
497
|
+
clearTimeout(stallTimer);
|
|
498
|
+
stallTimer = setTimeout(() => {
|
|
499
|
+
abortGenerate(`OpenCode LLM generate timed out after ${stallMs}ms without progress`);
|
|
500
|
+
}, stallMs);
|
|
501
|
+
};
|
|
463
502
|
|
|
464
503
|
try {
|
|
465
504
|
if (probe.available && probe.mode === 'http' && probe.url) {
|
|
@@ -476,7 +515,7 @@ export async function generateOpenCodeText({
|
|
|
476
515
|
const parts = message.parts.filter((part) => part?.type !== 'file' || !String(part.mime || '').startsWith('image/'));
|
|
477
516
|
return parts.length === message.parts.length ? message : { ...message, parts };
|
|
478
517
|
}),
|
|
479
|
-
signal:
|
|
518
|
+
signal: requestSignal,
|
|
480
519
|
});
|
|
481
520
|
}
|
|
482
521
|
|
|
@@ -506,7 +545,7 @@ export async function generateOpenCodeText({
|
|
|
506
545
|
// Session fence: deny every native OpenCode/MCP/skill tool for this throwaway.
|
|
507
546
|
permission: LLM_SESSION_DENY_PERMISSION,
|
|
508
547
|
metadata: { openchamber: { llm: { purpose: 'chat-completions' } } },
|
|
509
|
-
}, { signal:
|
|
548
|
+
}, { signal: requestSignal });
|
|
510
549
|
const sessionID = created?.data?.id;
|
|
511
550
|
if (created?.error || !sessionID) {
|
|
512
551
|
failGenerate(`OpenCode LLM session create failed: ${sdkErrorMessage(created, 'create failed')}`);
|
|
@@ -535,7 +574,10 @@ export async function generateOpenCodeText({
|
|
|
535
574
|
unsubscribeDeltas = subscribeThrowawayTextDeltas({
|
|
536
575
|
globalEventHub,
|
|
537
576
|
sessionID,
|
|
538
|
-
onTextDelta
|
|
577
|
+
onTextDelta: (text) => {
|
|
578
|
+
bumpTimeout();
|
|
579
|
+
if (typeof onTextDelta === 'function') onTextDelta(text);
|
|
580
|
+
},
|
|
539
581
|
});
|
|
540
582
|
|
|
541
583
|
// promptAsync still forwards model/parts/tools. v2 session.prompt does not.
|
|
@@ -550,10 +592,11 @@ export async function generateOpenCodeText({
|
|
|
550
592
|
{ type: 'text', text: flattened.prompt, synthetic: false },
|
|
551
593
|
...promptFiles,
|
|
552
594
|
],
|
|
553
|
-
}, { signal:
|
|
595
|
+
}, { signal: requestSignal });
|
|
554
596
|
if (!promptAdmitted(prompted)) {
|
|
555
597
|
failGenerate(`OpenCode LLM promptAsync failed: ${sdkErrorMessage(prompted, 'promptAsync failed')}`);
|
|
556
598
|
}
|
|
599
|
+
bumpTimeout();
|
|
557
600
|
|
|
558
601
|
let text = assistantTextFromPrompt(prompted?.data ?? prompted);
|
|
559
602
|
if (!text.trim()) {
|
|
@@ -561,7 +604,9 @@ export async function generateOpenCodeText({
|
|
|
561
604
|
client,
|
|
562
605
|
sessionID,
|
|
563
606
|
directory: workingDirectory,
|
|
564
|
-
signal:
|
|
607
|
+
signal: requestSignal,
|
|
608
|
+
onProgress: bumpTimeout,
|
|
609
|
+
settlePollMs,
|
|
565
610
|
});
|
|
566
611
|
text = assistantTextFromMessages(settled);
|
|
567
612
|
}
|
|
@@ -589,7 +634,7 @@ export async function generateOpenCodeText({
|
|
|
589
634
|
}
|
|
590
635
|
}
|
|
591
636
|
} finally {
|
|
592
|
-
clearTimeout(
|
|
637
|
+
clearTimeout(stallTimer);
|
|
593
638
|
}
|
|
594
639
|
}
|
|
595
640
|
|
|
@@ -606,4 +651,5 @@ export const _test = {
|
|
|
606
651
|
LLM_AGENT_NAME,
|
|
607
652
|
AGENT_MARKDOWN,
|
|
608
653
|
LLM_SESSION_DENY_PERMISSION,
|
|
654
|
+
GENERATE_TIMEOUT_MS,
|
|
609
655
|
};
|
|
@@ -9,6 +9,70 @@ const completedAssistant = (text) => ({
|
|
|
9
9
|
parts: [{ type: 'text', text }],
|
|
10
10
|
})
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
const throwawayGenerate = (client, extra = {}) => generateOpenCodeText({
|
|
14
|
+
providerID: 'p',
|
|
15
|
+
modelID: 'm',
|
|
16
|
+
messages: [{ role: 'user', content: 'work' }],
|
|
17
|
+
buildOpenCodeUrl: () => 'http://localhost:1',
|
|
18
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
19
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
20
|
+
clientFactory: () => client,
|
|
21
|
+
ensureTempDirectory: async () => '/tmp/timeout-fixture',
|
|
22
|
+
...extra,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const throwawayClient = ({ status, messages, id = 'ses_tmp', remove = vi.fn(async () => ({ data: true })) }) => ({
|
|
26
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
27
|
+
session: {
|
|
28
|
+
create: async () => ({ data: { id } }),
|
|
29
|
+
update: async () => ({ data: { id } }),
|
|
30
|
+
promptAsync: async () => ({ response: { status: 204 } }),
|
|
31
|
+
status,
|
|
32
|
+
messages,
|
|
33
|
+
delete: remove,
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe('generate cancellation', () => {
|
|
38
|
+
it('cancels throwaway polling and still deletes only its temporary session', async () => {
|
|
39
|
+
const controller = new AbortController()
|
|
40
|
+
const remove = vi.fn(async () => ({ data: true }))
|
|
41
|
+
const client = {
|
|
42
|
+
tool: { ids: async () => ({ data: [] }) },
|
|
43
|
+
session: {
|
|
44
|
+
create: async () => ({ data: { id: 'ses_abort_fixture' } }),
|
|
45
|
+
update: async () => ({ data: { id: 'ses_abort_fixture' } }),
|
|
46
|
+
promptAsync: async () => ({ response: { status: 204 } }),
|
|
47
|
+
status: async (_args, { signal }) => { controller.abort(); signal.throwIfAborted() },
|
|
48
|
+
delete: remove,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
await expect(generateOpenCodeText({
|
|
52
|
+
providerID: 'p', modelID: 'm', messages: [{ role: 'user', content: 'work' }],
|
|
53
|
+
buildOpenCodeUrl: () => 'http://localhost:1', getOpenCodeAuthHeaders: () => ({}),
|
|
54
|
+
detect: async () => ({ available: false, mode: 'throwaway-session' }),
|
|
55
|
+
clientFactory: () => client, ensureTempDirectory: async () => '/tmp/abort-fixture',
|
|
56
|
+
signal: controller.signal,
|
|
57
|
+
})).rejects.toMatchObject({ name: 'AbortError' })
|
|
58
|
+
expect(remove).toHaveBeenCalledExactlyOnceWith({ sessionID: 'ses_abort_fixture', directory: '/tmp/abort-fixture' })
|
|
59
|
+
})
|
|
60
|
+
it('aborts an in-flight model request when the contact continuation is cancelled', async () => {
|
|
61
|
+
const controller = new AbortController()
|
|
62
|
+
const fetchImpl = vi.fn(async (_url, { signal }) => {
|
|
63
|
+
controller.abort()
|
|
64
|
+
signal.throwIfAborted()
|
|
65
|
+
})
|
|
66
|
+
await expect(generateOpenCodeText({
|
|
67
|
+
providerID: 'p', modelID: 'm', messages: [{ role: 'user', content: 'work' }],
|
|
68
|
+
buildOpenCodeUrl: () => 'http://localhost:1', getOpenCodeAuthHeaders: () => ({}),
|
|
69
|
+
detect: async () => ({ available: true, mode: 'http', url: 'http://localhost:1/generate' }),
|
|
70
|
+
fetchImpl, signal: controller.signal,
|
|
71
|
+
})).rejects.toMatchObject({ name: 'AbortError' })
|
|
72
|
+
expect(fetchImpl).toHaveBeenCalledTimes(1)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
12
76
|
describe('detectSessionlessGenerate', () => {
|
|
13
77
|
it('returns unavailable when the probe 404s', async () => {
|
|
14
78
|
const fetchImpl = vi.fn(async () => new Response('missing', { status: 404 }))
|
|
@@ -546,6 +610,34 @@ describe('generateOpenCodeText', () => {
|
|
|
546
610
|
})
|
|
547
611
|
})
|
|
548
612
|
|
|
613
|
+
describe('generate stall timeout', () => {
|
|
614
|
+
it('keeps waiting while the throwaway session stays busy past the stall deadline', async () => {
|
|
615
|
+
let polls = 0
|
|
616
|
+
const result = await throwawayGenerate(throwawayClient({
|
|
617
|
+
status: async () => {
|
|
618
|
+
polls += 1
|
|
619
|
+
return { data: { ses_tmp: { type: polls < 12 ? 'busy' : 'idle' } } }
|
|
620
|
+
},
|
|
621
|
+
messages: async () => ({ data: [completedAssistant('late reply')] }),
|
|
622
|
+
}), {
|
|
623
|
+
timeoutMs: 50,
|
|
624
|
+
settlePollMs: 10,
|
|
625
|
+
})
|
|
626
|
+
expect(polls).toBeGreaterThan(5)
|
|
627
|
+
expect(result).toEqual({ text: 'late reply', source: 'throwaway-session' })
|
|
628
|
+
})
|
|
629
|
+
|
|
630
|
+
it('times out when throwaway settle makes no progress', async () => {
|
|
631
|
+
await expect(throwawayGenerate(throwawayClient({
|
|
632
|
+
status: async () => ({ data: {} }),
|
|
633
|
+
messages: async () => ({ data: [] }),
|
|
634
|
+
}), {
|
|
635
|
+
timeoutMs: 40,
|
|
636
|
+
settlePollMs: 10,
|
|
637
|
+
})).rejects.toThrow(/timed out after 40ms without progress/)
|
|
638
|
+
})
|
|
639
|
+
})
|
|
640
|
+
|
|
549
641
|
describe('subscribeThrowawayTextDeltas', () => {
|
|
550
642
|
it('returns null without a callback or hub', () => {
|
|
551
643
|
expect(_test.subscribeThrowawayTextDeltas({
|
|
@@ -105,6 +105,7 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
105
105
|
formatSettingsResponse,
|
|
106
106
|
readSettingsFromDisk,
|
|
107
107
|
readSettingsFromDiskMigrated,
|
|
108
|
+
readSettingsFromDiskStrict,
|
|
108
109
|
persistSettings,
|
|
109
110
|
sanitizeProjects,
|
|
110
111
|
sanitizeSkillCatalogs,
|
|
@@ -246,6 +247,10 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
246
247
|
: {}),
|
|
247
248
|
}));
|
|
248
249
|
},
|
|
250
|
+
readModelPreferences: async () => {
|
|
251
|
+
const settings = await readSettingsFromDiskStrict();
|
|
252
|
+
return { favoriteModels: settings.favoriteModels, recentModels: settings.recentModels };
|
|
253
|
+
},
|
|
249
254
|
listScheduledTasks: (projectID) => projectConfigRuntime.listScheduledTasks(projectID),
|
|
250
255
|
sessionIndexService,
|
|
251
256
|
upsertScheduledTask: (projectID, task) => projectConfigRuntime.upsertScheduledTask(projectID, task),
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t}from"./rolldown-runtime-C0FnF6B9.js";import{c as n,i as r}from"./runtime-switch-LvWDU-SL.js";import{et as i}from"./persistence-YbQKzHUQ.js";import{a}from"./vendor-zustand-B4dlGEM2.js";import{nt as o,rt as s}from"./vendor-base-ui-CnHfUmDN.js";import{r as c}from"./platform-DzsGqlGW.js";import{t as l}from"./useUIStore-CxOoCv7B.js";import{n as u}from"./vendor-react-DLPElpoQ.js";import{r as d}from"./vendor-sonner-DVzioF3d.js";import{n as f,r as p,u as m}from"./vendor-reactuses-core-DDoDDyM9.js";import{n as h}from"./clipboard-CUasgPiF.js";import{a as g,n as _}from"./MobileShareBridge-BAZoyeIP.js";import{Oo as v,dr as y,qt as b,r as x,vn as S}from"./useMobileNavigationStore-CYbDxRTM.js";import{g as C,i as w,l as ee,m as T,n as E,o as D,p as O,t as k,x as A,y as j}from"./MobileDetailNavigation-BGaAyuBH.js";import{i as M,n as N,r as P}from"./useAssistantUIStore-CLPCNoj_.js";import{a as F,i as I,n as L,o as R,r as z,t as B}from"./dialog-BwQ3rY_x.js";import{t as V}from"./utils-BHTVlVov.js";import{t as H}from"./AgentAvatar-mbvX7YlW.js";import{n as U}from"./Icon-CkzzhaLr.js";import{t as W}from"./button-xx1UOBA5.js";import{i as te}from"./OverlayScrollbar-CDC5B3RH.js";import{t as ne}from"./MarkdownRenderer-CLQ4Z8Z0.js";import{c as re,s as G}from"./imageSource-BlAJJUEI.js";import{a as ie,c as ae,i as oe,n as K,o as q,p as se,r as J,t as ce}from"./sessionChangeSummary-DQDZ5HW-.js";import{a as le,i as Y,n as ue,r as de,t as fe}from"./context-menu-CYbm4wBZ.js";import{i as pe,n as X,r as me}from"./assistant-attachment-cache-C0aRnFkj.js";import{t as he}from"./sessionLookup-Imc995rW.js";var Z=u(),Q=e(s(),1),$=o(),ge=e=>{let t=(0,Z.c)(17),{name:n,emoji:r,size:i,label:a,working:o,className:s}=e,c=i===void 0?24:i,l=o!==void 0&&o,{t:u}=h(),d=`calc(${c}px * var(--dpt-n, 1))`,f;t[0]===s?f=t[1]:(f=V(`relative inline-block shrink-0 align-middle leading-none`,s),t[0]=s,t[1]=f);let p;t[2]===d?p=t[3]:(p={width:d,height:d},t[2]=d,t[3]=p);let m;t[4]!==r||t[5]!==a||t[6]!==n||t[7]!==c?(m=(0,$.jsx)(H,{name:n,emoji:r,size:c,label:a,shape:`circle`}),t[4]=r,t[5]=a,t[6]=n,t[7]=c,t[8]=m):m=t[8];let g;t[9]!==u||t[10]!==l?(g=l?(0,$.jsx)(`span`,{className:`pointer-events-none absolute right-0 bottom-0 size-2 translate-x-1/4 translate-y-1/4 rounded-full bg-[var(--status-success)] ring-2 ring-background`,"data-assistant-working-dot":``,"aria-label":u(`assistants.contact.working`)}):null,t[9]=u,t[10]=l,t[11]=g):g=t[11];let _;return t[12]!==f||t[13]!==p||t[14]!==m||t[15]!==g?(_=(0,$.jsxs)(`span`,{className:f,style:p,"data-assistant-working-avatar":``,children:[m,g]}),t[12]=f,t[13]=p,t[14]=m,t[15]=g,t[16]=_):_=t[16],_},_e=a(e=>({workingByID:{},setWorking:(t,n)=>e(e=>({workingByID:{...e.workingByID,[t]:n}}))})),ve=({sending:e=!1,processing:t=!1,serverWorking:n=!1})=>e||t||n,ye=(e,t)=>{let n=(0,Z.c)(5),r=t!==void 0&&t,i;n[0]===e?i=n[1]:(i=t=>!!t.workingByID[e],n[0]=e,n[1]=i);let a=_e(i),o;return n[2]!==a||n[3]!==r?(o=ve({processing:a,serverWorking:r}),n[2]=a,n[3]=r,n[4]=o):o=n[4],o},be=`max-h-72 max-w-full rounded-[1.35rem] border border-border/40 object-contain`;function xe({assistantID:e,descriptor:t}){let{t:n}=h(),r=re(),{attachmentID:i,sha256:a,size:o,mime:s,filename:c}=t,l=Q.useMemo(()=>({type:`file`,attachmentID:i,sha256:a,size:o,mime:s,filename:c}),[i,a,o,s,c]),u=s.startsWith(`image/`),[d,p]=Q.useState(0),[m,g]=Q.useState(``),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1),x=Q.useRef(null),S=Q.useRef([]);Q.useEffect(()=>{g(``),v(!1);let t=new AbortController,n;return u&&me(e,l,{signal:t.signal}).then(e=>{if(t.signal.aborted){e.release();return}n=e.release,g(e.url)}).catch(()=>{t.signal.aborted||v(!0)}),()=>{t.abort(),n?.()}},[e,l,r,u,d]),Q.useEffect(()=>()=>{x.current?.abort(),S.current.forEach(e=>URL.revokeObjectURL(e)),S.current=[]},[e,l,r]);let C=f(async()=>{if(x.current)return;let t=new AbortController;x.current=t,b(!0),v(!1);try{let r=await X(e,l,{signal:t.signal});if(t.signal.aborted)return;S.current.forEach(e=>URL.revokeObjectURL(e));let i=URL.createObjectURL(r);S.current=[i];let a=document.createElement(`a`);a.href=i,a.download=c||n(`assistants.contact.attachment.file`),document.body.appendChild(a),a.click(),a.remove()}catch{t.signal.aborted||v(!0)}finally{x.current===t&&(x.current=null),t.signal.aborted||b(!1)}}),w=c||n(u?`assistants.contact.attachment.image`:`assistants.contact.attachment.file`);return u&&m&&!_?(0,$.jsx)(`img`,{src:m,alt:w,className:be,onError:()=>v(!0),"data-assistant-contact-image":``}):(0,$.jsxs)(`div`,{className:`flex max-w-full flex-col gap-1 rounded-[1.25rem] bg-[var(--surface-muted)] px-3.5 py-2.5 ring-1 ring-inset ring-[var(--surface-subtle)]`,"data-assistant-contact-file":``,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,$.jsx)(U,{name:`file-text`,className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate typography-ui`,children:w})]}),_?(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:n(`assistants.contact.attachment.loadFailed`)}):null,u&&!_||y?(0,$.jsx)(`span`,{role:`status`,className:`typography-micro text-muted-foreground`,children:n(`common.loading`)}):(0,$.jsx)(W,{type:`button`,size:`sm`,variant:`ghost`,onClick:u?()=>p(e=>e+1):()=>void C(),children:n(_?`chat.history.retry`:`assistants.contact.attachment.download`)})]})}function Se(e){let t=(0,Z.c)(19),{part:n}=e,{t:r}=h(),i=/^(?:https?:|data:|blob:)/i.test(n.url)?n.url:``,a=G(i,``),[o,s]=Q.useState(!1);if(n.mime.startsWith(`image/`)&&a&&!o){let e;t[0]!==n.filename||t[1]!==r?(e=n.filename||r(`assistants.contact.attachment.image`),t[0]=n.filename,t[1]=r,t[2]=e):e=t[2];let i;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=()=>s(!0),t[3]=i):i=t[3];let o;return t[4]!==a||t[5]!==e?(o=(0,$.jsx)(`img`,{src:a,alt:e,className:be,onError:i,"data-assistant-contact-image":``}),t[4]=a,t[5]=e,t[6]=o):o=t[6],o}let c;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,$.jsx)(U,{name:`file-text`,className:`size-4 shrink-0 text-muted-foreground`}),t[7]=c):c=t[7];let l;t[8]!==n.filename||t[9]!==r?(l=n.filename||r(`assistants.contact.attachment.file`),t[8]=n.filename,t[9]=r,t[10]=l):l=t[10];let u;t[11]===l?u=t[12]:(u=(0,$.jsx)(`span`,{className:`truncate typography-ui`,children:l}),t[11]=l,t[12]=u);let d;t[13]!==o||t[14]!==r?(d=o?(0,$.jsx)(W,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>s(!1),children:r(`chat.history.retry`)}):null,t[13]=o,t[14]=r,t[15]=d):d=t[15];let f;return t[16]!==u||t[17]!==d?(f=(0,$.jsxs)(`div`,{className:`flex max-w-full items-center gap-2.5 rounded-[1.25rem] bg-[var(--surface-muted)] px-3.5 py-2.5`,"data-assistant-contact-file":``,children:[c,u,d]}),t[16]=u,t[17]=d,t[18]=f):f=t[18],f}function Ce(e){let t=(0,Z.c)(4),{assistantID:n,part:r}=e,i=re(),a;return t[0]!==n||t[1]!==r||t[2]!==i?(a=`attachmentID`in r?(0,$.jsx)(xe,{assistantID:n,descriptor:r},`${i}:${n}:${r.attachmentID}:${r.sha256}`):(0,$.jsx)(Se,{part:r},`${i}:${r.url}`),t[0]=n,t[1]=r,t[2]=i,t[3]=a):a=t[3],a}var we=[],Te=e=>e.flatMap(e=>e.type===`text`&&e.text.trim()?[e.text]:[]).join(`
|
|
2
|
-
`),Ee=(e,t,n,r=Date.now())=>({assistantID:e,messageID:t,parts:n,status:`sending`,createdAt:r}),De=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},Oe=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},ke=(e,t,n,r)=>({messageID:t?`${e.turnID}:preview:${t.bubbleIndex}`:`${e.turnID}:preview:${r}`,assistantID:e.assistantID,role:`assistant`,turnID:e.turnID,bubbleIndex:t?.bubbleIndex??0,createdAt:t?.occurredAt??e.occurredAt,ordinal:n,status:r,fromAssistantID:null,fromAssistantName:null,parts:t?[{type:`text`,text:t.text}]:[],text:t?.text??``,cards:[]}),Ae=(e,t,n)=>{let r=e.bubbles.filter(e=>!t.has(e.bubbleIndex)).map((t,r)=>ke(e,t,n+r,t.done?`complete`:`streaming`));return e.status===`failed`?[...r,ke(e,null,n+r.length,`failed`)]:e.status===`admitted`||e.status===`streaming`?[...r,ke(e,null,n+r.length,`admitted`)]:r},je=(e,t,n,r=[])=>{let i=new Set(e.map(e=>e.messageID)),a=t.flatMap((t,r)=>t.assistantID!==n||i.has(t.messageID)?[]:[{messageID:t.messageID,assistantID:n,role:`user`,turnID:t.messageID,bubbleIndex:0,createdAt:t.createdAt,ordinal:e.length+r,status:t.status,fromAssistantID:null,fromAssistantName:null,parts:[...t.parts],text:Te(t.parts),cards:[]}]),o=a.length===0?e:[...e,...a],s=r.filter(e=>e.assistantID===n);if(s.length===0)return o;let c=new Map,l=new Map;o.forEach((e,t)=>{if(c.set(e.turnID,t),e.role!==`assistant`||e.messageID.includes(`:preview:`))return;let n=l.get(e.turnID)??new Set;n.add(e.bubbleIndex),l.set(e.turnID,n)});let u=new Map,d=[];for(let e of s){let t=Ae(e,l.get(e.turnID)??new Set,o.length+d.length);if(t.length===0)continue;let n=c.get(e.turnID);if(n===void 0){d.push(...t);continue}let r=u.get(n)??[];r.push(...t),u.set(n,r)}return u.size===0&&d.length===0?o:o.flatMap((e,t)=>[e,...u.get(t)??[]]).concat(d)},Me=(e,t)=>{let n=new Set(t.map(e=>e.messageID)),r=e.filter(e=>!n.has(e.messageID));return r.length===e.length?e:r},Ne=(e,t)=>e.map(e=>e.messageID===t?{...e,status:`admitted`}:e),Pe=(e,t,n,r=Date.now())=>e.some(e=>e.assistantID===t&&e.turnID===n)?e:[...e,{assistantID:t,turnID:n,status:`admitted`,bubbles:[],occurredAt:r}],Fe=(e,t,n)=>!t?.turnID||!t.assistantID||n?.has(t.turnID)?e:Pe(e,t.assistantID,t.turnID,t.admittedAt),Ie=(e,t)=>{let n=t.assistantID,r=t.pendingSendTurnIDs??new Set,i=t.settledTurnIDs??new Set,a=typeof t.snapshotRevision==`number`&&Number.isFinite(t.snapshotRevision)?t.snapshotRevision:null,o=t.admissionRevisionByTurnID instanceof Map?t.admissionRevisionByTurnID:new Map(Object.entries(t.admissionRevisionByTurnID??{}).map(([e,t])=>[e,Number(t)])),s=t.occurredAt??Date.now(),c=t.activeContactTurn&&t.activeContactTurn.turnID?t.activeContactTurn:null,l=!!(t.serverWorking||c),u=Fe(e,c?{assistantID:n,turnID:c.turnID,admittedAt:c.admittedAt}:null,i),d=Array.isArray(t.messages)?t.messages:[];for(let e of d)e.role===`assistant`&&e.status===`error`&&(r.has(e.turnID)||i.has(e.turnID)||(u=Re(u,{assistantID:n,turnID:e.turnID,status:`error`,error:e.text||`upstream_error`,occurredAt:s})));if(u=ze(u,d),l){let t=u.filter(e=>{if(e.assistantID!==n||e.status!==`admitted`&&e.status!==`streaming`||r.has(e.turnID)||c&&e.turnID===c.turnID)return!0;let t=o.get(e.turnID);return typeof t==`number`&&a!=null&&a<t?!0:typeof t==`number`&&a!=null&&a>=t&&e.turnID!==c?.turnID?!1:!c||e.turnID===c.turnID});return t.length===e.length&&t.every((t,n)=>t===e[n])?e:t}if(a==null)return u.length===e.length&&u.every((t,n)=>t===e[n])?e:u;let f=u.filter(e=>{if(e.assistantID!==n||e.status!==`admitted`&&e.status!==`streaming`||r.has(e.turnID))return!0;if(i.has(e.turnID))return!1;let t=o.get(e.turnID);return typeof t==`number`&&a<t});return f.length===e.length&&f.every((t,n)=>t===e[n])?e:f.length===u.length?u:f},Le=(e,t)=>Pe(e,t.assistantID,t.turnID,t.occurredAt).map(e=>{if(e.assistantID!==t.assistantID||e.turnID!==t.turnID||e.status===`failed`||e.status===`complete`)return e;let n=e.bubbles.find(e=>e.bubbleIndex===t.bubbleIndex);if(n?.done)return e;let r=n?{...n,text:`${n.text}${t.delta}`,done:t.done,occurredAt:t.occurredAt}:{bubbleIndex:t.bubbleIndex,text:t.delta,done:t.done,occurredAt:t.occurredAt},i=n?e.bubbles.map(e=>e.bubbleIndex===t.bubbleIndex?r:e):[...e.bubbles,r].sort((e,t)=>e.bubbleIndex-t.bubbleIndex);return{...e,status:`streaming`,bubbles:i}}),Re=(e,t,n={})=>n.requireExisting&&!e.some(e=>e.assistantID===t.assistantID&&e.turnID===t.turnID)?e:Pe(e,t.assistantID,t.turnID,t.occurredAt).map(e=>e.assistantID!==t.assistantID||e.turnID!==t.turnID||e.status===`complete`||e.status===`failed`?e:{...e,status:t.status===`error`?`failed`:`complete`,...t.error?{error:t.error}:{}}),ze=(e,t)=>{let n=new Set(t.flatMap(e=>e.role===`assistant`?[e.turnID]:[])),r=e.filter(e=>e.status!==`complete`||!n.has(e.turnID));return r.length===e.length?e:r},Be=(e,t,n)=>e.map(e=>e.messageID===t?{...e,status:`failed`,error:n}:e),Ve=(e,t)=>{if(e instanceof j){if(e.code===`no_provider`)return t.noProvider;if(e.code===`admission_timeout`||e.code===`generate_timeout`)return t.timedOut;if(e.message&&e.message!==e.code)return e.message}return A(e)?t.timedOut:t.sendFailed},He=()=>{let e=!1;return{tryAcquire:()=>!e&&(e=!0,!0),release:()=>{e=!1}}},Ue=e=>{let t=e.text.trim();if(e.sending||!t&&e.attachments.length===0||!e.gate.tryAcquire())return{ok:!1};let n=[...t?[{type:`text`,text:t}]:[],...e.attachments.map(e=>({type:`file`,mime:e.mime,url:e.url,filename:e.name}))],r=e.createMessageID();return{ok:!0,messageID:r,parts:n,turn:Ee(e.assistantID,r,n,e.createdAt)}},We=e=>e.some(e=>e.status===`sending`),Ge=e=>e.some(e=>e.status===`admitted`||e.status===`streaming`),Ke=[`cursor-pointer rounded-[1.35rem] bg-[var(--surface-elevated)] ring-1 ring-inset ring-[var(--surface-subtle)]`,`px-3.5 py-3 text-left transition-[background-color,box-shadow,transform] duration-200 ease-out motion-reduce:transition-none`,`hover:-translate-y-px hover:bg-interactive-hover/45 hover:shadow-sm active:translate-y-0 motion-reduce:hover:translate-y-0`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]`].join(` `),qe=`${Ke} w-fit min-w-0 max-w-[min(100%,15rem)]`,Je=`${Ke} w-fit min-w-0 max-w-[min(100%,20rem)]`;function Ye(e,t){(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())}var Xe=e=>{let t=(0,Z.c)(26),{card:n}=e,{t:r}=h(),i=se(),a;t[0]===i?a=t[1]:(a=i&&!c(),t[0]=i,t[1]=a);let o=!!a,s=n.name,l=`${n.providerID}/${n.modelID}`,u;t[2]!==n.mode||t[3]!==l?(u=[l,n.mode].filter(Boolean),t[2]=n.mode,t[3]=l,t[4]=u):u=t[4];let d=u,p;t[5]!==n.assistantID||t[6]!==o?(p=()=>{if(o){x.getState().openAssistant(n.assistantID);return}N(n.assistantID)},t[5]=n.assistantID,t[6]=o,t[7]=p):p=t[7];let m=f(p),g;t[8]===m?g=t[9]:(g=e=>{Ye(e,m)},t[8]=m,t[9]=g);let _=f(g),v;t[10]!==r||t[11]!==s?(v=r(`assistants.contact.card.assistant.aria`,{name:s}),t[10]=r,t[11]=s,t[12]=v):v=t[12];let y;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(U,{name:`robot-2`,className:`size-3`})})}),t[13]=y):y=t[13];let b;t[14]===s?b=t[15]:(b=(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-medium text-foreground`,children:s}),t[14]=s,t[15]=b);let S;t[16]===d?S=t[17]:(S=d.length>0?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:d.join(` · `)}):null,t[16]=d,t[17]=S);let C;t[18]!==b||t[19]!==S?(C=(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[y,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[b,S]})]}),t[18]=b,t[19]=S,t[20]=C):C=t[20];let w;return t[21]!==_||t[22]!==m||t[23]!==C||t[24]!==v?(w=(0,$.jsx)(`article`,{className:qe,role:`button`,tabIndex:0,"aria-label":v,"data-assistant-contact-card":`assistant`,onClick:m,onKeyDown:_,children:C}),t[21]=_,t[22]=m,t[23]=C,t[24]=v,t[25]=w):w=t[25],w},Ze=e=>{let t=(0,Z.c)(25),{card:n}=e,{t:r}=h(),i=n.name,a;t[0]!==n.kind||t[1]!==n.time||t[2]!==n.timezone?(a=[n.kind,n.time,n.timezone].filter(Boolean),t[0]=n.kind,t[1]=n.time,t[2]=n.timezone,t[3]=a):a=t[3];let o=a.join(` `),s;t[4]!==n.prompt||t[5]!==o?(s=o.trim()||(typeof n.prompt==`string`?n.prompt.trim():``),t[4]=n.prompt,t[5]=o,t[6]=s):s=t[6];let c=s,l=f(Qe),u;t[7]===l?u=t[8]:(u=e=>{Ye(e,l)},t[7]=l,t[8]=u);let d=f(u),p;t[9]!==r||t[10]!==i?(p=r(`assistants.contact.card.schedule.aria`,{name:i}),t[9]=r,t[10]=i,t[11]=p):p=t[11];let m;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(U,{name:`calendar`,className:`size-3`})})}),t[12]=m):m=t[12];let g;t[13]===i?g=t[14]:(g=(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-medium text-foreground`,children:i}),t[13]=i,t[14]=g);let _;t[15]===c?_=t[16]:(_=c?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:c}):null,t[15]=c,t[16]=_);let v;t[17]!==g||t[18]!==_?(v=(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[m,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[g,_]})]}),t[17]=g,t[18]=_,t[19]=v):v=t[19];let y;return t[20]!==d||t[21]!==l||t[22]!==p||t[23]!==v?(y=(0,$.jsx)(`article`,{className:qe,role:`button`,tabIndex:0,"aria-label":p,"data-assistant-contact-card":`schedule`,onClick:l,onKeyDown:d,children:v}),t[20]=d,t[21]=l,t[22]=p,t[23]=v,t[24]=y):y=t[24],y};function Qe(){l.getState().setActiveMainTab(`schedule`),l.getState().setScheduledTasksDialogOpen(!0)}var $e=(e,t)=>e===`busy`||e===`retry`?e:t===`error`||t===`question`||t===`complete`?t:e===`idle`?`complete`:t===`busy`||t===`retry`||t===`idle`?t:t||`busy`,et=e=>e===`busy`?`assistants.contact.card.session.status.busy`:e===`retry`?`assistants.contact.card.session.status.retry`:e===`idle`?`assistants.contact.card.session.status.idle`:e===`complete`?`assistants.contact.card.session.status.complete`:e===`error`?`assistants.contact.card.session.status.error`:e===`question`?`assistants.contact.card.session.status.question`:null,tt=e=>e===`busy`?`bg-[var(--status-info)]/10 text-[var(--status-info)]`:e===`retry`||e===`question`?`bg-[var(--status-warning)]/10 text-[var(--status-warning)]`:e===`error`?`bg-[var(--status-error)]/10 text-[var(--status-error)]`:e===`idle`||e===`complete`?`bg-[var(--status-success)]/10 text-[var(--status-success)]`:`bg-[var(--surface-muted)] text-muted-foreground`,nt=e=>e.split(/[/\\]/u).filter(Boolean).at(-1)||e,rt=e=>{let t=(0,Z.c)(35),{card:n}=e,{t:r}=h(),i=se(),a;t[0]===i?a=t[1]:(a=i&&!c(),t[0]=i,t[1]=a);let o=!!a,s;t[2]===n.sessionID?s=t[3]:(s=e=>e.activeSessions.find(e=>e.id===n.sessionID)??e.archivedSessions.find(e=>e.id===n.sessionID)??null,t[2]=n.sessionID,t[3]=s);let u=y(s),d=b(n.sessionID),p=(typeof u?.title==`string`&&u.title.trim()?u.title.trim():null)||n.title||r(`assistants.contact.card.session.untitled`),m=$e(d?.type,n.status),g=et(m),_=m===`busy`||m===`retry`,v=nt(typeof u?.directory==`string`&&u.directory.trim()?u.directory.trim():n.directory),x=K(u)||n.branch,C=oe(u),w=J(u),ee=ce(w),T=[v,C,x].filter(it),E;t[4]!==n.directory||t[5]!==n.sessionID||t[6]!==o?(E=()=>{let e=he(n.sessionID)?.directory||n.directory;S(n.sessionID,e,{phoneShell:o,switchToChat:!0}),o||l.getState().setActiveMainTab(`chat`)},t[4]=n.directory,t[5]=n.sessionID,t[6]=o,t[7]=E):E=t[7];let D=f(E),O;t[8]===D?O=t[9]:(O=e=>{Ye(e,D)},t[8]=D,t[9]=O);let k=f(O),A=Je,j=r(`assistants.contact.card.session.aria`,{title:p}),M;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(U,{name:`chat-3`,className:`size-3`})}),t[10]=M):M=t[10];let N;t[11]===_?N=t[12]:(N=_?(0,$.jsx)(`span`,{className:`pointer-events-none absolute right-0 bottom-0 size-2 translate-x-1/4 translate-y-1/4 rounded-full bg-[var(--status-success)] ring-2 ring-[var(--surface-elevated)]`,"data-assistant-working-dot":``,"aria-hidden":!0}):null,t[11]=_,t[12]=N);let P;t[13]===N?P=t[14]:(P=(0,$.jsxs)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:[M,N]}),t[13]=N,t[14]=P);let F;t[15]===p?F=t[16]:(F=(0,$.jsx)(`h3`,{className:`min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground`,children:p}),t[15]=p,t[16]=F);let I=g?(0,$.jsx)(`span`,{className:V(`shrink-0 rounded-full px-1.5 py-0.5 typography-micro leading-none`,tt(m)),children:r(g)}):null,L;t[17]!==F||t[18]!==I?(L=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[F,I]}),t[17]=F,t[18]=I,t[19]=L):L=t[19];let R;t[20]===T?R=t[21]:(R=T.length>0?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:T.join(` · `)}):null,t[20]=T,t[21]=R);let z=ee||w?.files!==void 0&&w.files>0?(0,$.jsxs)(`p`,{className:`flex flex-wrap items-baseline gap-x-1.5 typography-micro tabular-nums`,children:[w?.additions===void 0?null:(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,w.additions]}),w?.deletions===void 0?null:(0,$.jsxs)(`span`,{className:`text-[var(--status-error)]`,children:[`−`,w.deletions]}),w?.files===void 0?null:(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:w.files===1?r(`assistants.contact.card.session.changes.filesSingle`,{count:w.files}):r(`assistants.contact.card.session.changes.filesPlural`,{count:w.files})})]}):null,B;t[22]!==L||t[23]!==R||t[24]!==z?(B=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[L,R,z]}),t[22]=L,t[23]=R,t[24]=z,t[25]=B):B=t[25];let H;t[26]!==P||t[27]!==B?(H=(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[P,B]}),t[26]=P,t[27]=B,t[28]=H):H=t[28];let W;return t[29]!==k||t[30]!==D||t[31]!==H||t[32]!==A||t[33]!==j?(W=(0,$.jsx)(`article`,{className:A,role:`button`,tabIndex:0,"aria-label":j,"data-assistant-contact-card":`session`,onClick:D,onKeyDown:k,children:H}),t[29]=k,t[30]=D,t[31]=H,t[32]=A,t[33]=j,t[34]=W):W=t[34],W};function it(e){return!!(e&&e.trim())}var at=2,ot=1500,st=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),ct=e=>e.scrollHeight-e.scrollTop-e.clientHeight,lt=e=>ct(e)<=at,ut=(e,t)=>{let n=t instanceof Element?t:t instanceof Node?t.parentElement:null;for(;n&&n!==e;){if(n instanceof HTMLElement&&n.scrollHeight>n.clientHeight+1&&n.scrollTop+n.clientHeight<n.scrollHeight-1)return!0;n=n.parentElement}return!1},dt=e=>e.altKey||e.ctrlKey||e.metaKey?!1:e.key===`ArrowDown`||e.key===`PageDown`||e.key===`End`,ft=({active:e,assistantID:t,contentRevision:n,onLoadEarlier:r})=>{let i=Q.useRef(null),[a,o]=Q.useState(null),[s,c]=Q.useState(null),l=Q.useRef(!0),u=Q.useRef(null),d=Q.useRef(null),h=Q.useRef(null),g=Q.useRef(0),_=Q.useRef(null),v=Q.useRef(null),y=Q.useRef(e);y.current=e;let b=Q.useMemo(()=>e=>{i.current=e,o(t=>t===e?t:e)},[]),x=Q.useMemo(()=>e=>{c(t=>t===e?t:e)},[]),S=f(()=>{let e=i.current;if(!e||!y.current||l.current)return;let t=e.getBoundingClientRect().top,n=Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.getBoundingClientRect().bottom>t);u.current=n?{id:n.dataset.messageId,offset:n.getBoundingClientRect().top-t}:null}),C=f(()=>{let e=i.current,t=u.current;if(!e||!t||!y.current||l.current)return;if(Math.abs(e.scrollTop-g.current)>.5){g.current=e.scrollTop,S();return}let n=Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t.id);if(!n){S();return}let r=n.getBoundingClientRect().top-e.getBoundingClientRect().top-t.offset;Math.abs(r)>.5&&(e.scrollTop+=r),g.current=e.scrollTop}),w=f(()=>{l.current=!1,g.current=i.current?.scrollTop??0,S()}),ee=f(()=>{if(!y.current||!l.current)return!1;let e=i.current;if(!e)return!1;let t=st(e),n=Math.min(g.current,Math.max(0,t.scrollHeight-t.clientHeight));return t.scrollTop<n-.5?(l.current=!1,g.current=t.scrollTop,S(),!1):lt(t)?(g.current=t.scrollTop,!1):(e.scrollTop=e.scrollHeight,g.current=e.scrollTop,!0)}),T=f(e=>{v.current={direction:e,expiresAt:performance.now()+ot}}),E=f(()=>{let e=v.current;return e?performance.now()>e.expiresAt?(v.current=null,null):e.direction:null}),D=f(()=>{l.current=!1,S()}),O=f(()=>{if(!y.current)return;let e=i.current;if(!e)return;let t=st(e),n=t.scrollTop>g.current,a=Math.min(g.current,Math.max(0,t.scrollHeight-t.clientHeight));if(g.current=t.scrollTop,l.current){t.scrollTop<a-.5&&D();return}let o=E();S(),t.scrollTop<=80&&o===`up`&&r?.(),n&<(t)&&(o===`down`||o===`scrollbar`)&&(l.current=!0)}),k=f(e=>{let t=i.current;if(!(!t||e.deltaY===0)){if(e.deltaY<0){if(q(t,e.target))return;T(`up`),D(),t.scrollTop<=80&&r?.();return}ut(t,e.target)||T(`down`)}}),A=f(e=>{v.current=null;let t=e.touches.item(0);_.current=t?{x:t.clientX,y:t.clientY,deltaX:0,deltaY:0}:null}),j=f(e=>{let t=i.current,n=e.touches.item(0);if(!t||!n){_.current=null;return}let a=_.current;if(!a)return;let o=n.clientY-a.y,s=o*a.deltaY<0,c=(s?0:a.deltaX)+n.clientX-a.x,l=(s?0:a.deltaY)+o;if(_.current={x:n.clientX,y:n.clientY,deltaX:c,deltaY:l},!(Math.abs(c)>=Math.abs(l))){if(l>0&&q(t,e.target)||l<0&&ut(t,e.target)){_.current.deltaX=0,_.current.deltaY=0;return}T(l>0?`up`:`down`),l>2&&(D(),t.scrollTop<=80&&r?.())}}),M=f(()=>{_.current=null}),N=f(e=>{if(ie(e)){T(`up`),D(),(i.current?.scrollTop??1/0)<=80&&r?.();return}dt(e)&&T(`down`)}),P=f(e=>{let t=i.current;e.pointerType===`mouse`&&e.target===t&&T(`scrollbar`)});Q.useLayoutEffect(()=>{let n=e?t:null,r=i.current;(d.current!==n||h.current!==r)&&(d.current=n,h.current=r,l.current=!0,u.current=null,v.current=null,_.current=null,g.current=r?.scrollTop??0),e&&(ee(),C())},[e,t,n,a]);let F=Q.useMemo(()=>()=>void 0,[]),I=e&&a?a:F,L=Q.useMemo(()=>({passive:!0}),[]);p(`scroll`,O,I,L),p(`wheel`,k,I,L),p(`touchstart`,A,I,L),p(`touchmove`,j,I,L),p(`touchend`,M,I,L),p(`touchcancel`,M,I,L),p(`keydown`,N,I),p(`pointerdown`,P,I,L);let R=f(()=>{ee(),C()});return m(typeof ResizeObserver<`u`&&e?s:null,R),{scrollRef:b,contentRef:x,preparePrepend:w}},pt=64,mt=e=>{if(!e)return[];let t=Array.from(e.files||[]);return t.length>0?t:Array.from(e.items||[]).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e instanceof File)},ht=e=>Array.from(e?.files||[]),gt=async(e,t=i)=>{let n=[],r=0;for(let i of Array.from(e||[])){if(!i||i.size<=0)continue;if(i.size>26214400){r+=1;continue}let e=URL.createObjectURL(i);n.push({id:t(),url:e,name:i.name.trim()||`attachment`,mime:i.type.trim()||`application/octet-stream`,file:i})}return{attachments:n,skippedTooLarge:r}},_t=(e,t)=>{let n=[...e,...t];for(let e of n.slice(pt))e.url.startsWith(`blob:`)&&URL.revokeObjectURL(e.url);return n.slice(0,pt)},vt=e=>e.trim().startsWith(`oc.settle.`),yt=({assistant:e,warning:t,active:n,overlayHeader:r=!1})=>{let{t:a}=h(),o=re(),s=l(e=>e.isMobile),c=O(),u=C(),d=T(e.id,n),p=g(e.name),m=p.displayName||e.name,y=(e,t)=>{let n=e?u.data?.assistants.find(t=>t.id===e):void 0;return n?g(n.name).displayName||n.name:t||a(`assistants.contact.peer.unknown`)},[b,x]=Q.useState(``),[S,w]=Q.useState([]),D=Q.useRef(null),k=Q.useRef(new Map),A=Q.useRef(new AbortController);Q.useEffect(()=>{let e=new AbortController;return A.current=e,()=>e.abort()},[e.id,o]);let M=Q.useRef(new Set);Q.useEffect(()=>{let e=new Set(S.map(e=>e.url));for(let t of M.current)e.has(t)||URL.revokeObjectURL(t);M.current=e},[S]),Q.useEffect(()=>()=>{for(let e of M.current)URL.revokeObjectURL(e)},[]);let[N,P]=Q.useState([]),[F,I]=Q.useState([]),[L,R]=Q.useState(null);Q.useEffect(()=>{k.current.clear(),D.current=null,P([]),I([]),R(null)},[o]);let z=Q.useMemo(()=>He(),[]),B=Q.useRef(new Set),H=Q.useRef(new Map),te=_e(e=>e.setWorking),G=d.data?.messages??we,ie=De(N,e.id),oe=Oe(F,e.id),K=je(G,ie,e.id,oe).filter(e=>{let t=Array.isArray(e.parts)?e.parts:[];return t.length===0||t.some(e=>!(e.type===`text`&&vt(e.text)))}),q=We(ie),se=Ge(oe),J=!!(e.working||e.activeContactTurn),ce=u.data?.revision??null,le=oe.reduce((e,t)=>e+t.bubbles.reduce((e,t)=>e+t.text.length,0),0),Y=new Map(oe.map(e=>[e.turnID,e])),ue=Q.useRef(!1),de=f(async(e=!1)=>{if(!(!n||ue.current||d.isFetchingPreviousPage||d.isFillingMessageGap)&&!(e&&d.previousPageError)&&!(!d.hasPreviousPage&&!d.hasMessageGap)){ue.current=!0,me();try{d.hasMessageGap?await d.retryMessageGap():await d.fetchPreviousPage()}catch{}finally{ue.current=!1}}}),{scrollRef:fe,contentRef:X,preparePrepend:me}=ft({active:n,assistantID:e.id,contentRevision:`${K[0]?.messageID}:${K.length}:${le}:${d.isFetchingPreviousPage}:${d.hasPreviousPage}:${d.isFillingMessageGap}`,onLoadEarlier:()=>{de(!0)}});Q.useEffect(()=>{R(null),B.current.clear(),H.current=new Map,P(t=>De(t,e.id)),I(t=>Oe(t,e.id))},[e.id]),Q.useEffect(()=>{P(e=>Me(e,G))},[G]),Q.useEffect(()=>{let t=new Set(ie.filter(e=>e.status===`sending`).map(e=>e.messageID));I(n=>Ie(n,{assistantID:e.id,activeContactTurn:e.activeContactTurn?{turnID:e.activeContactTurn.turnID,admittedAt:e.activeContactTurn.admittedAt}:null,serverWorking:J,snapshotRevision:ce,admissionRevisionByTurnID:H.current,pendingSendTurnIDs:t,messages:G,settledTurnIDs:B.current}))},[e.activeContactTurn,e.id,G,ie,J,ce]),Q.useEffect(()=>{te(e.id,q||se||J)},[e.id,se,q,J,te]),Q.useEffect(()=>{let t=e.id;return()=>{te(t,!1)}},[e.id,te]);let he=f(t=>{if(!(!(`assistantID`in t)||t.assistantID!==e.id)){if(t.type===`contact-turn-start`){B.current.delete(t.turnID),I(e=>Pe(e,t.assistantID,t.turnID,t.occurredAt));return}if(t.type===`contact-bubble-delta`){if(B.current.has(t.turnID))return;I(e=>Le(e,t));return}t.type===`contact-turn-end`&&(B.current.add(t.turnID),I(e=>ze(Re(e,t,{requireExisting:!0}),G)))}});Q.useEffect(()=>{if(n)return v(he)},[n,e.id]);let Z=f(async e=>{if(q)return;let t=A.current,n=await gt(e);if(t.signal.aborted){n.attachments.forEach(e=>URL.revokeObjectURL(e.url));return}n.skippedTooLarge>0&&R(a(`assistants.contact.attachment.tooLarge`)),n.attachments.length!==0&&w(e=>_t(e,n.attachments))}),ve=f(e=>{let t=mt(e.clipboardData);t.length!==0&&(e.preventDefault(),Z(t))}),ye=f(e=>{Array.from(e.dataTransfer?.types??[]).includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}),be=f(e=>{let t=ht(e.dataTransfer);t.length!==0&&(e.preventDefault(),Z(t))}),xe=f(async()=>{let t=A.current,n=b,r=S,o=e.id,s=D.current,l=s?.assistantID===o&&s.text===n&&s.attachments===r?s.messageID:null,u=Ue({gate:z,sending:We(ie),text:n,attachments:r,assistantID:o,createMessageID:()=>l||`oc_contact_${i()}`});if(!u.ok)return;D.current={assistantID:o,text:n,attachments:r,messageID:u.messageID},P(e=>[...e.filter(e=>e.messageID!==u.messageID),u.turn]),R(null);let d=()=>{x(e=>e===n?``:e),w(e=>e.filter(e=>!r.includes(e))),r.forEach(e=>k.current.delete(`${o}:${e.id}`)),D.current=null};try{let e=[];for(let n of r){let r=`${o}:${n.id}`,i=k.current.get(r);if(!i){if(i=await pe(o,n.file,n.id,t.signal),t.signal.aborted)return;k.current.set(r,i)}e.push(i)}if(t.signal.aborted)return;let n=[...u.parts.filter(e=>e.type===`text`),...e];P(e=>e.map(e=>e.messageID===u.messageID?{...e,parts:n}:e));let i=await ee(o,u.messageID,{parts:n});if(t.signal.aborted)return;d(),typeof i.revision==`number`&&H.current.set(u.messageID,i.revision),P(e=>Ne(e,u.messageID)),B.current.has(u.messageID)||I(e=>Pe(e,o,u.messageID)),c.data?.serverInstanceID&&_({serverInstanceID:c.data.serverInstanceID,assistantID:o,name:m,avatarSeed:o,...p.avatarEmoji?{avatarEmoji:p.avatarEmoji}:{}}).catch(()=>void 0)}catch(e){if(t.signal.aborted)return;if(e instanceof j&&e.code===`admission_timeout`)try{let e=await E(o,u.messageID);if(t.signal.aborted)return;if(e){d(),typeof e.revision==`number`&&H.current.set(u.messageID,e.revision),P(e=>Ne(e,u.messageID)),B.current.has(u.messageID)||I(e=>Pe(e,o,u.messageID));return}}catch{}let n=Ve(e,{noProvider:a(`assistants.contact.noProvider`),sendFailed:a(`assistants.contact.sendFailed`),timedOut:a(`assistants.contact.timedOut`)});P(e=>Be(e,u.messageID,n)),R(n)}finally{z.release()}}),Se=d.isError&&K.length===0,Te=d.isSuccess&&K.length===0,Ee=new Map(ie.map(e=>[e.messageID,e]));return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col bg-background`,children:[(0,$.jsxs)(`div`,{ref:fe,className:V(`min-h-0 flex-1 overflow-x-hidden overflow-y-auto px-4 pb-9 sm:px-8 sm:pb-12`,r?`pt-[calc(max(0.625rem,var(--oc-safe-area-top,0px))+var(--oc-mobile-detail-navigation-height)+1.25rem)]`:`pt-5 sm:pt-7`),style:{overflowAnchor:`none`,overscrollBehavior:`contain`,overscrollBehaviorY:`contain`},"data-assistant-contact-transcript":``,children:[t?(0,$.jsx)(`p`,{className:`mb-3 typography-micro text-[var(--status-warning)]`,children:t}):null,Se?(0,$.jsxs)(`div`,{ref:X,className:`mx-auto flex h-full min-h-56 max-w-xs flex-col items-center justify-center pb-16 text-center`,"data-assistant-contact-error":``,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(ge,{name:e.id,emoji:p.avatarEmoji,size:44,label:m}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute -right-1 -bottom-1 flex size-5 items-center justify-center rounded-full bg-[var(--surface-elevated)] text-[var(--status-error)] ring-2 ring-background`,children:(0,$.jsx)(U,{name:`error-warning`,className:`size-3`})})]}),(0,$.jsx)(`p`,{className:`mt-4 typography-ui-label font-medium text-foreground`,children:m}),(0,$.jsx)(`p`,{className:`mt-1.5 typography-ui leading-6 text-muted-foreground`,children:a(`assistants.contact.loadFailed`)}),(0,$.jsx)(W,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void d.refetch(),children:a(`chat.history.retry`)})]}):Te?(0,$.jsxs)(`div`,{ref:X,className:`mx-auto flex h-full min-h-56 max-w-sm flex-col items-center justify-center pb-16 text-center`,"data-assistant-contact-empty":``,children:[(0,$.jsx)(ge,{name:e.id,emoji:p.avatarEmoji,size:48,label:m,className:`opacity-90`}),(0,$.jsx)(`p`,{className:`mt-5 typography-ui-header font-medium tracking-[-0.01em] text-foreground`,children:a(`assistants.conversation.emptyTitle`,{name:m})}),(0,$.jsx)(`p`,{className:`mt-2 max-w-xs typography-ui leading-6 text-muted-foreground/80`,children:a(`assistants.contact.empty`)})]}):(0,$.jsxs)(`div`,{ref:X,className:`mx-auto flex w-full max-w-[42rem] flex-col`,children:[d.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-3 text-center typography-micro text-muted-foreground`,children:a(`common.loading`)}):null,d.hasPreviousPage||d.hasMessageGap?(0,$.jsxs)(`div`,{className:`mb-3 flex flex-col items-center gap-1`,"data-assistant-contact-pagination":``,"aria-busy":d.isFetchingPreviousPage||d.isFillingMessageGap,children:[d.previousPageError?(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:a(`chat.history.loadOlderFailed`)}):null,d.hasMessageGap?(0,$.jsx)(`p`,{role:`status`,className:`typography-micro text-muted-foreground`,children:a(`assistants.contact.history.gap`)}):null,(0,$.jsx)(W,{type:`button`,size:`sm`,variant:`ghost`,disabled:d.isFetchingPreviousPage||d.isFillingMessageGap,onClick:()=>void de(),children:a(d.isFetchingPreviousPage||d.isFillingMessageGap?`chat.history.loadingMore`:d.previousPageError||d.hasMessageGap?`chat.history.retry`:`chat.history.loadOlder`)})]}):null,K.map((t,n)=>{let r=n>0?K[n-1]:null,i=t.role===`user`,o=t.role===`peer`,s=t.role===`assistant`&&r?.role===`assistant`&&r.turnID===t.turnID,c=r?.turnID!==t.turnID,l=!i&&(o||!s),d=o?y(t.fromAssistantID,t.fromAssistantName):m,f=o&&t.fromAssistantID?u.data?.assistants.find(e=>e.id===t.fromAssistantID):e,p=f?g(f.name):null,h=Ee.get(t.messageID),_=Y.get(t.turnID),v=t.status===`admitted`&&t.messageID.endsWith(`:preview:admitted`),b=t.status===`failed`&&t.messageID.endsWith(`:preview:failed`);return(0,$.jsxs)(`div`,{"data-message-id":t.messageID,className:V(`flex w-full`,i?`justify-end`:`justify-start`,c?`mt-6 first:mt-0`:s?`mt-1.5`:`mt-3`),"data-assistant-contact-role":t.role,"data-assistant-contact-turn-status":h?.status??t.status,"data-assistant-contact-run-start":t.role===`assistant`&&!s?``:void 0,children:[i?null:(0,$.jsx)(`div`,{className:`mr-2.5 flex w-8 shrink-0 justify-center pt-0.5`,children:l?(0,$.jsx)(ge,{name:f?.id||t.fromAssistantID||e.id,emoji:p?.avatarEmoji,size:28,label:d}):(0,$.jsx)(`span`,{className:`size-7`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:V(`flex min-w-0 flex-col gap-1.5`,i?`max-w-[min(82%,30rem)] items-end`:`max-w-[min(84%,34rem)] items-start`),children:[o?(0,$.jsx)(`span`,{className:`mb-0.5 px-1 typography-micro text-muted-foreground/75`,children:a(`assistants.contact.peer.from`,{name:d})}):null,v?(0,$.jsxs)(`div`,{role:`status`,"aria-label":a(`assistants.contact.processing`),className:`inline-flex w-fit items-center gap-1 rounded-full bg-[var(--surface-muted)] px-3.5 py-2.5 text-muted-foreground/70`,"data-assistant-contact-processing":``,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 animate-pulse rounded-full bg-current [animation-delay:-0.45s] [animation-duration:1.4s] motion-reduce:animate-none`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 animate-pulse rounded-full bg-current [animation-delay:-0.22s] [animation-duration:1.4s] motion-reduce:animate-none`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 animate-pulse rounded-full bg-current [animation-duration:1.4s] motion-reduce:animate-none`})]}):null,t.parts.map((n,r)=>{if(n.type===`card`&&n.cardType===`session`)return(0,$.jsx)(rt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`assistant`)return(0,$.jsx)(Xe,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`schedule`)return(0,$.jsx)(Ze,{card:n},`${t.messageID}:card:${r}`);if(n.type===`file`)return(0,$.jsx)(Ce,{assistantID:e.id,part:n},`${t.messageID}:file:${r}`);if(n.type===`text`&&vt(n.text))return null;if(n.type===`text`&&(n.text.trim()||t.status===`streaming`)){let e=!i;return(0,$.jsxs)(`div`,{"aria-label":o?a(`assistants.contact.peer.aria`,{name:d}):void 0,"data-assistant-contact-text":``,className:V(`min-w-0 max-w-full [overflow-wrap:anywhere] rounded-[1.35rem] px-4 py-2.5 typography-markdown leading-6`,e?null:`whitespace-pre-wrap`,i?`rounded-[1.15rem] rounded-br-lg bg-[var(--primary-base)]/90 text-[var(--primary-foreground)]`:o?`rounded-[1.25rem] border border-dashed border-border/50 bg-[var(--surface-muted)]/70 text-foreground`:V(`bg-[var(--surface-muted)] text-foreground`,s&&`rounded-tl-lg`)),children:[e?(0,$.jsx)(ne,{content:n.text,messageId:t.messageID,isAnimated:!1,isStreaming:t.status===`streaming`,variant:`assistant`,enableFileReferences:!1,className:`w-full min-w-0 [overflow-wrap:anywhere]`}):n.text,t.status===`streaming`&&r===t.parts.length-1?(0,$.jsx)(`span`,{"aria-hidden":!0,className:`ml-0.5 inline-block h-[1em] w-px translate-y-[0.12em] animate-pulse bg-current opacity-45 [animation-duration:1.1s] motion-reduce:animate-none`,"data-assistant-contact-streaming-caret":``}):null]},`${t.messageID}:text:${r}`)}return null}),h?.status===`sending`?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-muted-foreground/75`,children:a(`assistants.contact.sending`)}):null,h?.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-[var(--status-error)]`,children:h.error||a(`assistants.contact.sendFailed`)}):null,b?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-[var(--status-error)]`,children:_?.error||a(`assistants.contact.sendFailed`)}):null]})]},t.messageID)})]})]}),(0,$.jsxs)(`footer`,{className:`relative z-10 shrink-0 bg-background pt-1`,"data-assistant-contact-composer":``,children:[L?(0,$.jsxs)(`div`,{className:`chat-input-column mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:L}),D.current?(0,$.jsx)(W,{type:`button`,size:`sm`,variant:`ghost`,disabled:q,onClick:()=>void xe(),children:a(`chat.history.retry`)}):null]}):null,(0,$.jsx)(`form`,{className:V(`relative w-full pt-1.5 pb-4`,s&&`bottom-safe-area oc-mobile-composer`),onSubmit:e=>{e.preventDefault(),xe()},onDragOver:ye,onDrop:be,children:(0,$.jsx)(`div`,{className:`chat-input-column relative overflow-visible`,children:(0,$.jsx)(ae,{layout:`inline`,value:b,attachments:S,pending:q,isMobile:s,placeholder:a(`assistants.contact.placeholder`,{name:m}),sendLabel:a(`assistants.contact.send`),addFilesLabel:a(`assistants.contact.addFiles`),removeAttachmentLabel:a(`assistants.contact.removeAttachment`),fileAccept:`*/*`,onChange:e=>x(e),onSubmit:()=>{xe()},onAddFiles:e=>{Z(e)},onRemoveAttachment:t=>{q||(k.current.delete(`${e.id}:${t}`),D.current=null,w(e=>e.filter(e=>e.id!==t)))},onPaste:ve,onDragOver:ye,onDrop:be,className:V(`relative z-10`,s&&`oc-mobile-composer-surface`),style:{borderRadius:`1.5rem`},"data-assistant-contact-composer-surface":``,textareaProps:{"aria-label":a(`assistants.contact.placeholder`,{name:m})}})})})]})]})};async function bt(e){await w(e);let t=M.getState().defaultShareAssistant;if(t?.assistantID!==e.id)return;let n=await D();n.serverInstanceID&&t.serverInstanceID===n.serverInstanceID&&M.getState().setDefaultShareAssistant(null)}function xt({assistant:e,open:t,onOpenChange:n,onDeleted:r}){let{t:i}=h(),[a,o]=Q.useState(!1),s=e?g(e.name).displayName||e.name:``,c=f(e=>{a&&!e||n(e)}),l=f(()=>{a||n(!1)}),u=f(async()=>{if(!(!e||a)){o(!0);try{await bt(e),r?.(e.id),n(!1),d.success(i(`assistants.settings.toast.deleted`))}catch{d.error(i(`assistants.settings.toast.deleteFailed`))}finally{o(!1)}}});return(0,$.jsx)(B,{open:t&&e!==null,onOpenChange:c,children:(0,$.jsxs)(L,{className:`max-w-md`,children:[(0,$.jsxs)(F,{children:[(0,$.jsx)(R,{children:i(`assistants.settings.delete`)}),(0,$.jsx)(z,{children:i(`assistants.settings.deleteConfirm`,{name:s})})]}),(0,$.jsxs)(I,{children:[(0,$.jsx)(W,{size:`sm`,variant:`ghost`,onClick:l,disabled:a,children:i(`settings.common.actions.cancel`)}),(0,$.jsx)(W,{size:`sm`,variant:`destructive`,onClick:u,disabled:a,children:i(`settings.common.actions.delete`)})]})]})})}var St=`line-clamp-2 min-w-0 max-w-full overflow-clip whitespace-normal [overflow-wrap:anywhere] typography-micro text-muted-foreground`,Ct={image:`assistants.contact.attachment.image`,file:`assistants.contact.attachment.file`,session:`assistants.contact.card.session.untitled`,assistant:`assistants.title`,schedule:`assistants.settings.scheduledTasks.title`};function wt(e,t){return e?.text.replace(/\s+/gu,` `).trim()||t(e?.fallbackKind?Ct[e.fallbackKind]:`assistants.contact.empty`)}var Tt=e=>e.capabilityPending?`loading`:e.capabilityError||e.supported!==!0||e.capabilityEnabled!==!0?`unavailable`:e.snapshotPending?`loading`:e.snapshotEnabled===!0?e.assistantCount===0?`onboarding`:e.hasAssistant?`ready`:e.snapshotSettled?`unavailable`:`loading`:`unavailable`,Et=t({AssistantView:()=>kt}),Dt=e=>{let t=(0,Z.c)(21),{assistant:n,onBack:r}=e,{t:i}=h(),a=se(),o;t[0]===n?o=t[1]:(o=n?g(n.name):null,t[0]=n,t[1]=o);let s=o,c=n&&s?s.displayName||n.name:``,l;t[2]!==n||t[3]!==a?(l=()=>{n&&P(n.id,a?{openMobileSettings:a.openSettings}:void 0)},t[2]=n,t[3]=a,t[4]=l):l=t[4];let u=f(l),d;t[5]!==n||t[6]!==c||t[7]!==s?.avatarEmoji||t[8]!==i?(d=n?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2.5`,children:[(0,$.jsx)(ge,{name:n.id,emoji:s?.avatarEmoji,size:28,label:c}),(0,$.jsx)(`span`,{className:`truncate font-medium tracking-[-0.01em]`,children:c||i(`assistants.title`)})]}):c||i(`assistants.title`),t[5]=n,t[6]=c,t[7]=s?.avatarEmoji,t[8]=i,t[9]=d):d=t[9];let p;t[10]===i?p=t[11]:(p=i(`assistants.actions.backToChat`),t[10]=i,t[11]=p);let m;t[12]!==n||t[13]!==u||t[14]!==i?(m=n?[{icon:`settings-3`,ariaLabel:i(`assistants.conversation.openSettings`),onClick:u}]:[],t[12]=n,t[13]=u,t[14]=i,t[15]=m):m=t[15];let _;return t[16]!==r||t[17]!==d||t[18]!==p||t[19]!==m?(_=(0,$.jsx)(k,{title:d,backAriaLabel:p,onBack:r,actions:m,overlay:!0}),t[16]=r,t[17]=d,t[18]=p,t[19]=m,t[20]=_):_=t[20],_},Ot=e=>{let t=(0,Z.c)(47),{summary:n,assistantID:r,displayName:i,avatarEmoji:a,selected:o,enabled:s,editLabel:c,deleteLabel:l,onSelect:u,onEdit:d,onDelete:p,serverWorking:m}=e,h=ye(r,m!==void 0&&m),[g,_]=Q.useState(!1),v;t[0]===u?v=t[1]:(v=()=>u(),t[0]=u,t[1]=v);let y=f(v),b;t[2]===d?b=t[3]:(b=()=>{_(!1),d()},t[2]=d,t[3]=b);let x=f(b),S;t[4]===p?S=t[5]:(S=()=>{_(!1),p()},t[4]=p,t[5]=S);let C=f(S),w;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(w=e=>{e.preventDefault(),_(!0)},t[6]=w):w=t[6];let ee=o?`border-border/50 bg-[var(--surface-elevated)]`:`border-transparent hover:bg-interactive-hover`,T=!s&&`opacity-65`,E;t[7]!==ee||t[8]!==T?(E=V(`flex w-full min-h-11 items-center gap-3 rounded-xl border px-3 py-3 text-left outline-none transition-[background-color,border-color,opacity] duration-150 ease-out active:bg-interactive-active focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] motion-reduce:transition-none`,ee,T),t[7]=ee,t[8]=T,t[9]=E):E=t[9];let D;t[10]!==y||t[11]!==o||t[12]!==E?(D=(0,$.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":o,onClick:y,onContextMenu:w,className:E}),t[10]=y,t[11]=o,t[12]=E,t[13]=D):D=t[13];let O;t[14]!==r||t[15]!==a||t[16]!==i||t[17]!==h?(O=(0,$.jsx)(ge,{name:r,emoji:a,size:24,label:i,working:h}),t[14]=r,t[15]=a,t[16]=i,t[17]=h,t[18]=O):O=t[18];let k;t[19]===i?k=t[20]:(k=(0,$.jsx)(`span`,{className:`block truncate typography-ui-label font-medium`,children:i}),t[19]=i,t[20]=k);let A;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(A=V(St,`mt-1.5`),t[21]=A):A=t[21];let j;t[22]===n?j=t[23]:(j=(0,$.jsx)(`span`,{className:A,children:n}),t[22]=n,t[23]=j);let M;t[24]!==k||t[25]!==j?(M=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[k,j]}),t[24]=k,t[25]=j,t[26]=M):M=t[26];let N;t[27]!==O||t[28]!==M||t[29]!==D?(N=(0,$.jsxs)(le,{render:D,children:[O,M]}),t[27]=O,t[28]=M,t[29]=D,t[30]=N):N=t[30];let P;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(P=(0,$.jsx)(U,{name:`edit`,className:`size-4`}),t[31]=P):P=t[31];let F;t[32]!==c||t[33]!==x?(F=(0,$.jsxs)(de,{onClick:x,children:[P,c]}),t[32]=c,t[33]=x,t[34]=F):F=t[34];let I;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(Y,{}),t[35]=I):I=t[35];let L;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(U,{name:`delete-bin`,className:`size-4`}),t[36]=L):L=t[36];let R;t[37]!==l||t[38]!==C?(R=(0,$.jsxs)(de,{onClick:C,className:`text-[var(--status-error)] focus:text-[var(--status-error)] data-[highlighted]:text-[var(--status-error)] [&_svg]:text-[var(--status-error)]`,children:[L,l]}),t[37]=l,t[38]=C,t[39]=R):R=t[39];let z;t[40]!==F||t[41]!==R?(z=(0,$.jsxs)(ue,{className:`min-w-[10rem]`,children:[F,I,R]}),t[40]=F,t[41]=R,t[42]=z):z=t[42];let B;return t[43]!==g||t[44]!==N||t[45]!==z?(B=(0,$.jsxs)(fe,{open:g,onOpenChange:_,children:[N,z]}),t[43]=g,t[44]=N,t[45]=z,t[46]=B):B=t[46],B},kt=e=>{let t=(0,Z.c)(110),{activeOverride:i,onMobileBack:a}=e,{t:o}=h(),{isMobile:s}=te(),c=se(),u=Q.useSyncExternalStore(n,r,r),d=l(At),p=i??d,m=l(jt),_=s||m,v=O(),y=C(),b=y.data,x;t[0]===u?x=t[1]:(x=e=>e.assistantByTransport[u]??null,t[0]=u,t[1]=x);let S=M(x),w=M(Mt),ee=M(Nt),T;t[2]!==S||t[3]!==b?.assistants?(T=b?.assistants.find(e=>e.id===S)??null,t[2]=S,t[3]=b?.assistants,t[4]=T):T=t[4];let E=T,D;t[5]!==w||t[6]!==S||t[7]!==b?(D=()=>{!S&&b?.assistants[0]&&w(b.assistants[0].id)},t[5]=w,t[6]=S,t[7]=b,t[8]=D):D=t[8];let k=b?.assistants,A;t[9]!==w||t[10]!==S||t[11]!==k?(A=[w,S,k],t[9]=w,t[10]=S,t[11]=k,t[12]=A):A=t[12],Q.useEffect(D,A);let j;t[13]!==E||t[14]!==w||t[15]!==S||t[16]!==b?.assistants||t[17]!==y.isSuccess?(j=()=>{y.isSuccess&&S&&!E&&w(b?.assistants[0]?.id??null)},t[13]=E,t[14]=w,t[15]=S,t[16]=b?.assistants,t[17]=y.isSuccess,t[18]=j):j=t[18];let N=b?.assistants,F;t[19]!==E||t[20]!==w||t[21]!==S||t[22]!==y.isSuccess||t[23]!==N?(F=[E,w,S,N,y.isSuccess],t[19]=E,t[20]=w,t[21]=S,t[22]=y.isSuccess,t[23]=N,t[24]=F):F=t[24],Q.useEffect(j,F);let I;t[25]!==c||t[26]!==ee?(I=()=>{if(ee(),c){c.openSettings();return}let e=l.getState();e.setSettingsPage(`assistants`),e.setSettingsDialogOpen(!0)},t[25]=c,t[26]=ee,t[27]=I):I=t[27];let L=f(I),R;t[28]===c?R=t[29]:(R=e=>{P(e,c?{openMobileSettings:c.openSettings}:void 0)},t[28]=c,t[29]=R);let z=f(R),B;t[30]!==E||t[31]!==c?(B=()=>{E&&P(E.id,c?{openMobileSettings:c.openSettings}:void 0)},t[30]=E,t[31]=c,t[32]=B):B=t[32];let H=f(B),[ne,re]=Q.useState(null),G;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(G=e=>{re(e)},t[33]=G):G=t[33];let ie=f(G),ae;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(ae=e=>{e||re(null)},t[34]=ae):ae=t[34];let oe=f(ae),K=f(Pt),q;t[35]!==a||t[36]!==K?(q=()=>{if(a){a();return}K()},t[35]=a,t[36]=K,t[37]=q):q=t[37];let J=f(q),ce=Tt({capabilityPending:v.isPending,snapshotPending:y.isPending,capabilityError:v.isError,supported:v.data?.supported,capabilityEnabled:v.data?.enabled,snapshotEnabled:b?.enabled,snapshotSettled:y.isSuccess,assistantCount:b?.assistants.length??0,hasAssistant:!!E}),le;t[38]!==E||t[39]!==J||t[40]!==_?(le=(e,t,n,r)=>(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[_?(0,$.jsx)(Dt,{assistant:E,onBack:J}):null,(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center px-6 pt-[calc(max(0.25rem,var(--oc-safe-area-top,0px))+var(--oc-mobile-detail-navigation-height,3.5rem))] text-center`,children:[(0,$.jsx)(U,{name:e,className:`size-6 text-muted-foreground`}),(0,$.jsx)(`h1`,{className:`mt-4 typography-ui-header font-semibold`,children:t}),n?(0,$.jsx)(`p`,{className:`mt-2 max-w-md typography-ui text-muted-foreground`,children:n}):null,r?(0,$.jsx)(`div`,{className:`mt-5`,children:r}):null]})]}),t[38]=E,t[39]=J,t[40]=_,t[41]=le):le=t[41];let Y=le;if(ce===`loading`){let e;t[42]!==E||t[43]!==J||t[44]!==_?(e=_?(0,$.jsx)(Dt,{assistant:E,onBack:J}):null,t[42]=E,t[43]=J,t[44]=_,t[45]=e):e=t[45];let n;t[46]===o?n=t[47]:(n=o(`common.loading`),t[46]=o,t[47]=n);let r;t[48]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(U,{name:`loader-4`,className:`size-6 animate-spin text-muted-foreground`}),t[48]=r):r=t[48];let i;t[49]===n?i=t[50]:(i=(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center px-6 pt-[calc(max(0.25rem,var(--oc-safe-area-top,0px))+var(--oc-mobile-detail-navigation-height,3.5rem))] text-center`,"aria-busy":`true`,"aria-label":n,"data-assistant-workspace-loading":``,children:r}),t[49]=n,t[50]=i);let a;return t[51]!==e||t[52]!==i?(a=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[e,i]}),t[51]=e,t[52]=i,t[53]=a):a=t[53],a}if(ce===`unavailable`){let e;return t[54]!==Y||t[55]!==o?(e=Y(`cloud-off`,o(`assistants.state.unavailable`)),t[54]=Y,t[55]=o,t[56]=e):e=t[56],e}if(ce===`onboarding`){let e;if(t[57]!==L||t[58]!==Y||t[59]!==o){let n=o(`assistants.onboarding.title`),r=o(`assistants.onboarding.description`),i;t[61]===o?i=t[62]:(i=o(`assistants.onboarding.action`),t[61]=o,t[62]=i);let a;t[63]!==L||t[64]!==i?(a=(0,$.jsx)(W,{onClick:L,children:i}),t[63]=L,t[64]=i,t[65]=a):a=t[65],e=Y(`ai-agent`,n,r,a),t[57]=L,t[58]=Y,t[59]=o,t[60]=e}else e=t[60];return e}if(!b||!E){let e;return t[66]!==Y||t[67]!==o?(e=Y(`cloud-off`,o(`assistants.state.unavailable`)),t[66]=Y,t[67]=o,t[68]=e):e=t[68],e}let ue;t[69]===E.name?ue=t[70]:(ue=g(E.name),t[69]=E.name,t[70]=ue);let de=ue,fe;t[71]!==E.enabled||t[72]!==y.isError||t[73]!==o?(fe=E.enabled?y.isError?o(`assistants.state.staleSnapshot`):null:o(`assistants.state.assistantDisabled`),t[71]=E.enabled,t[72]=y.isError,t[73]=o,t[74]=fe):fe=t[74];let pe=fe,X;t[75]!==_||t[76]!==L||t[77]!==z||t[78]!==ie||t[79]!==w||t[80]!==S||t[81]!==b||t[82]!==o?(X=_?null:(0,$.jsxs)(`section`,{className:`flex h-full min-h-0 w-[clamp(16rem,22vw,20rem)] shrink-0 flex-col overflow-hidden`,children:[(0,$.jsxs)(`header`,{className:`flex shrink-0 items-center gap-3 px-4 pb-3 pt-4 sm:px-5`,children:[(0,$.jsx)(`h1`,{className:`min-w-0 flex-1 truncate typography-ui-label font-semibold text-foreground`,children:o(`assistants.title`)}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":o(`assistants.settings.create`),onClick:L,children:(0,$.jsx)(U,{name:`add`,className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-4 sm:px-4`,role:`listbox`,"aria-label":o(`assistants.listAria`),children:(0,$.jsx)(`div`,{className:`flex flex-col gap-1 border-t border-border/40 pt-3`,children:b.assistants.map(e=>{let t=e.id===S,n=g(e.name);return(0,$.jsx)(Ot,{assistantID:e.id,summary:wt(e.latestMessagePreview,o),displayName:n.displayName,avatarEmoji:n.avatarEmoji??void 0,selected:t,enabled:e.enabled,editLabel:o(`assistants.menu.edit`),deleteLabel:o(`assistants.settings.delete`),assignedSessionIDs:e.assignedSessionIDs,serverWorking:e.working,onSelect:()=>w(e.id),onEdit:()=>z(e.id),onDelete:()=>ie(e)},e.id)})})})]}),t[75]=_,t[76]=L,t[77]=z,t[78]=ie,t[79]=w,t[80]=S,t[81]=b,t[82]=o,t[83]=X):X=t[83];let me=ne!==null,he;t[84]!==ne||t[85]!==oe||t[86]!==me?(he=(0,$.jsx)(xt,{assistant:ne,open:me,onOpenChange:oe}),t[84]=ne,t[85]=oe,t[86]=me,t[87]=he):he=t[87];let _e=!_&&`border-l border-[var(--surface-subtle)]`,ve;t[88]===_e?ve=t[89]:(ve=V(`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-background`,_e),t[88]=_e,t[89]=ve);let ye;t[90]!==E||t[91]!==J||t[92]!==_||t[93]!==H||t[94]!==de||t[95]!==o?(ye=_?(0,$.jsx)(Dt,{assistant:E,onBack:J}):(0,$.jsxs)(`header`,{className:`flex h-16 shrink-0 items-center gap-3.5 border-b border-[var(--surface-subtle)]/70 px-5 sm:px-7`,children:[(0,$.jsx)(ge,{name:E.id,emoji:de.avatarEmoji,size:30,label:de.displayName||E.name}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate typography-ui-label font-semibold tracking-[-0.01em] text-foreground`,children:de.displayName}),(0,$.jsx)(`div`,{className:`mt-1 truncate typography-micro leading-none text-muted-foreground/55`,children:o(`assistants.conversation.contactHint`)})]}),(0,$.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 shrink-0 rounded-full text-muted-foreground/65 transition-colors hover:text-foreground`,onClick:H,"aria-label":o(`assistants.conversation.openSettings`),children:(0,$.jsx)(U,{name:`settings-3`,className:`size-4`})})]}),t[90]=E,t[91]=J,t[92]=_,t[93]=H,t[94]=de,t[95]=o,t[96]=ye):ye=t[96];let be;t[97]!==p||t[98]!==E||t[99]!==_||t[100]!==pe?(be=(0,$.jsx)(yt,{assistant:E,warning:pe,active:p,overlayHeader:_}),t[97]=p,t[98]=E,t[99]=_,t[100]=pe,t[101]=be):be=t[101];let xe;t[102]!==ve||t[103]!==ye||t[104]!==be?(xe=(0,$.jsxs)(`div`,{className:ve,children:[ye,be]}),t[102]=ve,t[103]=ye,t[104]=be,t[105]=xe):xe=t[105];let Se;return t[106]!==X||t[107]!==he||t[108]!==xe?(Se=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden bg-background`,"data-presentation":`workspace`,children:[X,he,xe]}),t[106]=X,t[107]=he,t[108]=xe,t[109]=Se):Se=t[109],Se};function At(e){return e.activeMainTab===`assistant`}function jt(e){return e.isMobile}function Mt(e){return e.selectAssistant}function Nt(e){return e.requestCreate}function Pt(){l.getState().setActiveMainTab(`chat`)}export{xt as a,wt as i,Et as n,ye as o,St as r,ge as s,kt as t};
|