@openchambery/web 1.19.13-beta.6 → 1.19.13-beta.7
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/AssistantView-DhV6GhFz.js +2 -0
- package/dist/assets/{DiagramView-CAbNIt3t.js → DiagramView-DZc-OYOG.js} +1 -1
- package/dist/assets/{MarkdownRenderer-BPYs05iK.js → MarkdownRenderer-Ck0GdWsh.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-DMOxz3F2.js → MarkdownRendererImpl-DVQVI5vx.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-igQBbbc_.js → MarkstreamRendererImpl-BfNDXMOp.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-BqXkyZTu.js → MobileDetailNavigation-DsDo9Wi_.js} +1 -1
- package/dist/assets/{MobileShareBridge-XVaxj2S6.js → MobileShareBridge-71toeoY_.js} +1 -1
- package/dist/assets/{MobileSurface-6zONMJbZ.js → MobileSurface-DQ7ckeN6.js} +1 -1
- package/dist/assets/{MultiRunWindow-DK4IMgXD.js → MultiRunWindow-WmoZ6nx8.js} +1 -1
- package/dist/assets/{SettingsView-DyV0qt_2.js → SettingsView-B8DTddcL.js} +1 -1
- package/dist/assets/{SettingsWindow-D6BMtTR9.js → SettingsWindow-DC7meuIP.js} +1 -1
- package/dist/assets/{TerminalView-D24PhNyX.js → TerminalView-D75fVyUc.js} +1 -1
- package/dist/assets/{ToolOutputDialog-uKzrTqq_.js → ToolOutputDialog-BkUqgPvz.js} +1 -1
- package/dist/assets/{appThemeRegistry-CvGPIE7-.js → appThemeRegistry-BRuvElyv.js} +1 -1
- package/dist/assets/{fileMentionTouchSelection-DstJbYAw.js → fileMentionTouchSelection-BHGsKCxs.js} +1 -1
- package/dist/assets/{gitApi-ClM_B3fS.js → gitApi-CL2Myx_e.js} +1 -1
- package/dist/assets/{insertionBoundaries-RilpwKtQ.js → insertionBoundaries-D7rBkplR.js} +1 -1
- package/dist/assets/{main-uBrYU2q0.js → main-B4hVU-l2.js} +2 -2
- package/dist/assets/{main-C2wx8T4t.js → main-DguaBQR-.js} +4 -4
- package/dist/assets/{miniChat-Bt2HBpWq.js → miniChat-oSX3inOA.js} +2 -2
- package/dist/assets/{mobile-CpcbfIT1.js → mobile-D4M85fxw.js} +2 -2
- package/dist/assets/{multirun-FNfO4hCT.js → multirun-DZJk1_Zk.js} +1 -1
- package/dist/assets/{projectMeta-Cfq8wYwb.js → projectMeta-OucjgJJr.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-CA5VKfGo.js → renderElectronMiniChatApp-CCVDhPaw.js} +2 -2
- package/dist/assets/{renderMobileApp-De8AWiA6.js → renderMobileApp-BrtjHPwj.js} +5 -5
- package/dist/assets/{runtimeConfig-BpsTIe2G.js → runtimeConfig-CPYy2HWF.js} +1 -1
- package/dist/assets/{runtimeEndpointReset-CjT4jAvZ.js → runtimeEndpointReset-OyMKgGCH.js} +1 -1
- package/dist/assets/{sessionLookup-CBT9qysS.js → sessionLookup-Bzs-d6ek.js} +1 -1
- package/dist/assets/src-DYeppLfP.css +2 -0
- package/dist/assets/{useAppFontEffects-BD0BG-np.js → useAppFontEffects-PwYVhdyQ.js} +5 -5
- package/dist/assets/{useDesktopWindowControlsLayout-CF2GHw9J.js → useDesktopWindowControlsLayout-DbVLYP--.js} +1 -1
- package/dist/assets/{useEffectiveDirectory-Tz4YgZHt.js → useEffectiveDirectory-1LhqeRsH.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-BlYOTQfq.js → useMobileNavigationStore-CNpuVBEn.js} +1 -1
- package/dist/assets/{useSessionAutoCleanup-VgkhRtrf.js → useSessionAutoCleanup-hiDGV_VZ.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-DT0cJd4V.js → useWorkerHighlightedLines-z7yMKbSr.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/lib/assistants/DOCUMENTATION.md +2 -2
- package/server/lib/assistants/harness.js +9 -0
- package/server/lib/assistants/harness.test.js +74 -1
- package/dist/assets/AssistantView-7NzDL0Ft.js +0 -2
- package/dist/assets/src-BdO1hC7q.css +0 -2
package/dist/index.html
CHANGED
|
@@ -552,7 +552,7 @@
|
|
|
552
552
|
opacity: 0.72;
|
|
553
553
|
}
|
|
554
554
|
</style>
|
|
555
|
-
<script type="module" crossorigin src="/assets/main-
|
|
555
|
+
<script type="module" crossorigin src="/assets/main-B4hVU-l2.js"></script>
|
|
556
556
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
557
557
|
<link rel="modulepreload" crossorigin href="/assets/runtime-auth-D66yq6ie.js">
|
|
558
558
|
<link rel="modulepreload" crossorigin href="/assets/runtime-switch-LvWDU-SL.js">
|
|
@@ -572,8 +572,8 @@
|
|
|
572
572
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-CfgOfnZk.js">
|
|
573
573
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
574
574
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
575
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
576
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
575
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-CPYy2HWF.js">
|
|
576
|
+
<link rel="stylesheet" crossorigin href="/assets/src-DYeppLfP.css">
|
|
577
577
|
</head>
|
|
578
578
|
<body class="h-full bg-background text-foreground">
|
|
579
579
|
<!-- Keep the startup layer outside #root. React replaces every child of
|
package/dist/mini-chat.html
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
}
|
|
75
75
|
</style>
|
|
76
76
|
|
|
77
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
77
|
+
<script type="module" crossorigin src="/assets/miniChat-oSX3inOA.js"></script>
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/assets/runtime-auth-D66yq6ie.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/runtime-switch-LvWDU-SL.js">
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-CfgOfnZk.js">
|
|
95
95
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
96
96
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
97
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
98
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
97
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-CPYy2HWF.js">
|
|
98
|
+
<link rel="stylesheet" crossorigin href="/assets/src-DYeppLfP.css">
|
|
99
99
|
</head>
|
|
100
100
|
<body class="h-full bg-background text-foreground">
|
|
101
101
|
<div id="root" class="h-full">
|
package/dist/mobile.html
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-D4M85fxw.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/runtime-auth-D66yq6ie.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/runtime-switch-LvWDU-SL.js">
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
<link rel="modulepreload" crossorigin href="/assets/terminalApi-CfgOfnZk.js">
|
|
84
84
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
85
85
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
86
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
87
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
86
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-CPYy2HWF.js">
|
|
87
|
+
<link rel="stylesheet" crossorigin href="/assets/src-DYeppLfP.css">
|
|
88
88
|
</head>
|
|
89
89
|
<body class="h-full bg-background text-foreground">
|
|
90
90
|
<div id="root" class="h-full"></div>
|
package/package.json
CHANGED
|
@@ -201,7 +201,7 @@ Snapshots expose the latest 50 `historySessionIDs` in chronological order and `h
|
|
|
201
201
|
|
|
202
202
|
- `POST /api/openchamber/assistants/:id/messages` returns **202** `{ messageID, admitted: true, binding }` as soon as the **user row** is persisted (`status: complete`). It does **not** wait for the LLM turn. Validation errors still fail synchronously with 4xx before admit.
|
|
203
203
|
- After admit: bump revision + `openchamber:assistants-changed`, register active contact turn (`queued`), broadcast `openchamber:contact-turn-start` `{ assistantID, turnID, messageID, occurredAt }` (`turnID` = client `messageID`), then kick `runContactTurn` asynchronously (serialized per assistant). Lane start marks the turn `running`. Lane start marks the turn `running` and bumps revision. Same `messageID`+payload replays admission once (`replayed: true`) without a second lane run; payload mismatch → `idempotency_conflict`. Failures persist a durable assistant `status: error` bubble for query recovery. Catalog/project list loads use a bounded deadline so the lane cannot hang forever.
|
|
204
|
-
- Contact SSE reuses `/api/openchamber/events` (no new endpoint): `openchamber:contact-bubble-delta` `{ assistantID, turnID, bubbleIndex, delta, done, occurredAt }`. Raw completion tokens are **not** painted live — they are often chain-of-thought and would appear then vanish. A short spoken preamble (e.g. 我去找一下) may appear before a tool and is kept. Planning/CoT is stripped. **Transcript bubbles:** confirm-only tools (`new_conversation` / `clear_chat_history` / `get_assistant_settings` / `update_default_prompt`) may use tool result text as the bubble; card/side-effect tools (`assign_session` / `watch_session` / `stop_session` / `create_assistant` / `schedule_task` / `message_assistant`) keep spoken only — never stack spoken + English toolText, and never paint card-tool English confirms when a card is enough. Missed-tool turns keep any existing spoken/assistant text; the English `MISSED_TOOL_FAILURE_BUBBLE` is only when there is no text at all. No-tool replies emit each stripped bubble as `{ done:true }` after parse, with a short gap between bubbles so they arrive one beat at a time.
|
|
204
|
+
- Contact SSE reuses `/api/openchamber/events` (no new endpoint): `openchamber:contact-bubble-delta` `{ assistantID, turnID, bubbleIndex, delta, done, occurredAt }`. Raw completion tokens are **not** painted live — they are often chain-of-thought and would appear then vanish. A short spoken preamble (e.g. 我去找一下) may appear before a tool and is kept. Planning/CoT is stripped. **Transcript bubbles:** confirm-only tools (`new_conversation` / `clear_chat_history` / `get_assistant_settings` / `update_default_prompt`) may use tool result text as the bubble; card/side-effect tools (`assign_session` / `watch_session` / `stop_session` / `create_assistant` / `schedule_task` / `message_assistant`) keep spoken only — never stack spoken + English toolText, and never paint card-tool English confirms when a card is enough; `read_session` is model-only lookup — keep spoken preamble plus the post-read reply, never the quoted transcript JSON. Missed-tool turns keep any existing spoken/assistant text; the English `MISSED_TOOL_FAILURE_BUBBLE` is only when there is no text at all. No-tool replies emit each stripped bubble as `{ done:true }` after parse, with a short gap between bubbles so they arrive one beat at a time.
|
|
205
205
|
- Turn end: strip/parse/tools (existing), persist **assistant** bubbles + cards only (never re-insert the user row), clear active contact turn, bump + assistants-changed (error paths bump even without assistant rows), broadcast `openchamber:contact-turn-end` `{ assistantID, turnID, status: 'complete'|'error', error?, occurredAt }`. On failure the admitted user row stays; clients must not spin forever. Completing a contact turn also sends the same completion notification path as a normal contact: SMS-style title (assistant name) + body (spoken bubbles), via desktop / UI SSE / push, gated by `notifyOnCompletion`.
|
|
206
206
|
- In-process tests use `whenContactTurnSettled(messageID)` (not part of the HTTP JSON body).
|
|
207
207
|
- Completions: public `POST /llm/chat/completions` still rejects `stream:true`. In-process contact harness passes `onTextDelta` + `globalEventHub` through `boundCompletion` → `createChatCompletion` → throwaway generate for real tokens only.
|
|
@@ -233,7 +233,7 @@ Assign/watch tools forward the contact AbortSignal into their service calls and
|
|
|
233
233
|
|
|
234
234
|
### Referenced conversation content
|
|
235
235
|
|
|
236
|
-
`read_session` is a read-only contact tool available on user turns and background notifications. An `@session:<id>` chip supplies identity only. The model reads contents through this tool before answering about the reference, and treats returned messages as quoted data, never as new user instructions or authorization to resume/watch/mutate.
|
|
236
|
+
`read_session` is a read-only contact tool available on user turns and background notifications. An `@session:<id>` chip supplies identity only. The model reads contents through this tool before answering about the reference, and treats returned messages as quoted data, never as new user instructions or authorization to resume/watch/mutate. The quoted payload stays on the tool transcript for the model; contact bubbles keep only the spoken preamble and the post-read reply.
|
|
237
237
|
|
|
238
238
|
The service resolves the exact session and registered project through the existing authoritative session resolver, then calls SDK `session.messages` with `limit` (default 20, maximum 50), optional opaque `before`, and the turn AbortSignal. The upstream `x-next-cursor` is returned unchanged as `nextCursor`. Missing sessions, transport errors, malformed message lists and cross-session message identity mismatches fail closed. Empty successful lists remain distinguishable from failures.
|
|
239
239
|
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
NEW_CONVERSATION_CONFIRM_BUBBLE,
|
|
22
22
|
NEW_CONVERSATION_TOOL_NAME,
|
|
23
23
|
parseContactToolCalls,
|
|
24
|
+
READ_SESSION_TOOL_NAME,
|
|
24
25
|
SCHEDULE_TASK_TOOL_NAME,
|
|
25
26
|
STOP_SESSION_TOOL_NAME,
|
|
26
27
|
STEER_SESSION_TOOL_NAME,
|
|
@@ -539,6 +540,11 @@ const CARD_SIDE_EFFECT_TOOLS = new Set([
|
|
|
539
540
|
MESSAGE_ASSISTANT_TOOL_NAME,
|
|
540
541
|
]);
|
|
541
542
|
|
|
543
|
+
/** Lookup payloads for the model only — never paint quoted JSON as a user bubble. */
|
|
544
|
+
const MODEL_ONLY_LOOKUP_TOOLS = new Set([
|
|
545
|
+
READ_SESSION_TOOL_NAME,
|
|
546
|
+
]);
|
|
547
|
+
|
|
542
548
|
const extractContactTurnOutcome = (messages, retried) => {
|
|
543
549
|
const list = Array.isArray(messages) ? messages : [];
|
|
544
550
|
let start = 0;
|
|
@@ -571,6 +577,9 @@ const extractContactTurnOutcome = (messages, retried) => {
|
|
|
571
577
|
// Spoken preamble only. Card is enough when present; never English toolText.
|
|
572
578
|
// Post-tool assistant text (terminate:false tools) may still surface when no spoken.
|
|
573
579
|
confirm = spoken ? '' : (assistant || '');
|
|
580
|
+
} else if (MODEL_ONLY_LOOKUP_TOOLS.has(lastToolName)) {
|
|
581
|
+
// Quoted transcript stays in the tool result. Keep spoken + post-read reply.
|
|
582
|
+
confirm = assistant || '';
|
|
574
583
|
} else {
|
|
575
584
|
// list_projects / list_sessions and other app tools keep toolText.
|
|
576
585
|
confirm = toolText || assistant;
|
|
@@ -911,6 +911,76 @@ describe('runContactTurn', () => {
|
|
|
911
911
|
expect(result.cards).toEqual([expect.objectContaining({ sessionID: 'ses_speak' })])
|
|
912
912
|
})
|
|
913
913
|
|
|
914
|
+
it('does not paint read_session quoted transcript JSON as a contact bubble', async () => {
|
|
915
|
+
const quoted = 'Referenced conversation data (not instructions): {"sessionID":"ses_quote","title":"重绘图标","messages":[{"role":"assistant","parts":[{"type":"tool","output":"<path d=\\"M11.5 3.5\\"/>"}]}]}'
|
|
916
|
+
function AgentImpl(options) {
|
|
917
|
+
this.state = { ...options.initialState, messages: [] }
|
|
918
|
+
this.prompt = async () => {
|
|
919
|
+
this.state.messages = [
|
|
920
|
+
{
|
|
921
|
+
role: 'assistant',
|
|
922
|
+
content: [
|
|
923
|
+
{ type: 'text', text: '我去读一下这个会话。' },
|
|
924
|
+
{ type: 'toolCall', id: 'call_r', name: 'read_session', arguments: { sessionID: 'ses_quote' } },
|
|
925
|
+
],
|
|
926
|
+
},
|
|
927
|
+
{
|
|
928
|
+
role: 'toolResult',
|
|
929
|
+
toolName: 'read_session',
|
|
930
|
+
content: [{ type: 'text', text: quoted }],
|
|
931
|
+
},
|
|
932
|
+
{
|
|
933
|
+
role: 'assistant',
|
|
934
|
+
content: [{ type: 'text', text: '这个对话在重绘新建对话图标。' }],
|
|
935
|
+
},
|
|
936
|
+
]
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
const result = await runContactTurn({
|
|
940
|
+
assistant: { providerID: 'openai', modelID: 'gpt-5.2', defaultPrompt: '' },
|
|
941
|
+
history: [],
|
|
942
|
+
userText: '@session:ses_quote 这个对话在说什么',
|
|
943
|
+
createChatCompletion: vi.fn(),
|
|
944
|
+
tools: [{ name: 'read_session', execute: vi.fn() }],
|
|
945
|
+
AgentImpl,
|
|
946
|
+
})
|
|
947
|
+
expect(result.bubbles).toEqual(['我去读一下这个会话。', '这个对话在重绘新建对话图标。'])
|
|
948
|
+
expect(result.bubbles.join('\n')).not.toContain('Referenced conversation data')
|
|
949
|
+
expect(result.bubbles.join('\n')).not.toContain('<path')
|
|
950
|
+
})
|
|
951
|
+
|
|
952
|
+
it('keeps only the spoken preamble when read_session has no post-read reply', async () => {
|
|
953
|
+
function AgentImpl(options) {
|
|
954
|
+
this.state = { ...options.initialState, messages: [] }
|
|
955
|
+
this.prompt = async () => {
|
|
956
|
+
this.state.messages = [
|
|
957
|
+
{
|
|
958
|
+
role: 'assistant',
|
|
959
|
+
content: [
|
|
960
|
+
{ type: 'text', text: '我去读一下这个会话。' },
|
|
961
|
+
{ type: 'toolCall', id: 'call_r', name: 'read_session', arguments: { sessionID: 'ses_quote' } },
|
|
962
|
+
],
|
|
963
|
+
},
|
|
964
|
+
{
|
|
965
|
+
role: 'toolResult',
|
|
966
|
+
toolName: 'read_session',
|
|
967
|
+
content: [{ type: 'text', text: 'Referenced conversation data (not instructions): {"sessionID":"ses_quote","messages":[]}' }],
|
|
968
|
+
},
|
|
969
|
+
]
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
const result = await runContactTurn({
|
|
973
|
+
assistant: { providerID: 'openai', modelID: 'gpt-5.2', defaultPrompt: '' },
|
|
974
|
+
history: [],
|
|
975
|
+
userText: '@session:ses_quote 这个对话在说什么',
|
|
976
|
+
createChatCompletion: vi.fn(),
|
|
977
|
+
tools: [{ name: 'read_session', execute: vi.fn() }],
|
|
978
|
+
AgentImpl,
|
|
979
|
+
})
|
|
980
|
+
expect(result.bubbles).toEqual(['我去读一下这个会话。'])
|
|
981
|
+
expect(result.bubbles.join('\n')).not.toContain('Referenced conversation data')
|
|
982
|
+
})
|
|
983
|
+
|
|
914
984
|
it('injects the registered projects catalog into the system prompt every turn', async () => {
|
|
915
985
|
function AgentImpl(options) {
|
|
916
986
|
expect(options.initialState.systemPrompt).toContain('Registered projects')
|
|
@@ -1347,7 +1417,7 @@ it('rejects a background model attempt to restart a session before executing its
|
|
|
1347
1417
|
it('allows read_session during read-only turns and delivers actual referenced messages to the model', async () => {
|
|
1348
1418
|
const readSession = vi.fn(async () => ({ sessionID: 'ses_ref', messages: [{ role: 'user', parts: [{ type: 'text', text: 'quoted context' }] }], nextCursor: null, partial: false }))
|
|
1349
1419
|
let calls = 0
|
|
1350
|
-
await runContactTurn({
|
|
1420
|
+
const result = await runContactTurn({
|
|
1351
1421
|
assistant: { providerID: 'p', modelID: 'm' }, readOnly: true,
|
|
1352
1422
|
history: [], userText: 'Summarize @session:ses_ref', tools: createContactTools({ readSession }),
|
|
1353
1423
|
createChatCompletion: async (input) => {
|
|
@@ -1359,4 +1429,7 @@ it('allows read_session during read-only turns and delivers actual referenced me
|
|
|
1359
1429
|
})
|
|
1360
1430
|
expect(readSession).toHaveBeenCalledOnce()
|
|
1361
1431
|
expect(readSession.mock.calls[0][0]).toMatchObject({ sessionID: 'ses_ref', limit: 5 })
|
|
1432
|
+
expect(result.bubbles).toEqual(['已读取引用内容。'])
|
|
1433
|
+
expect(result.bubbles.join('\n')).not.toContain('Referenced conversation data')
|
|
1434
|
+
expect(result.bubbles.join('\n')).not.toContain('quoted context')
|
|
1362
1435
|
})
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{o as e,r as t}from"./rolldown-runtime-C0FnF6B9.js";import{c as n,i as r,n as i}from"./runtime-switch-LvWDU-SL.js";import{B as a,J as o,V as s,W as c,Y as l,Z as u,nt as d,q as f,ut as p}from"./persistence-DwRBC4zl.js";import{a as m}from"./vendor-zustand-B4dlGEM2.js";import{nt as h,rt as g}from"./vendor-base-ui-CnHfUmDN.js";import{n as _,r as v}from"./platform-DQ5_LNKO.js";import{t as y}from"./useUIStore-CxOoCv7B.js";import{n as b}from"./vendor-react-DLPElpoQ.js";import{s as x}from"./vendor-tanstack-react-query-D7pys_c9.js";import{r as S}from"./vendor-sonner-DVzioF3d.js";import{a as C,d as w,i as T,n as E,r as D,u as O}from"./vendor-reactuses-core-BnW6GxJt.js";import{n as k}from"./clipboard-CzXos-TI.js";import{a as A,n as j}from"./MobileShareBridge-XVaxj2S6.js";import{C as M,_ as N,a as P,f as F,g as I,j as L,k as R,l as z,n as B,r as V,s as H,t as ee,u as te,y as U}from"./MobileDetailNavigation-BqXkyZTu.js";import{dr as ne,fr as re,ko as ie,ot as ae,qt as oe,r as se,vn as W}from"./useMobileNavigationStore-BlYOTQfq.js";import{i as G,n as ce,r as le}from"./useAssistantUIStore-CLPCNoj_.js";import{a as ue,i as K,n as de,o as fe,r as pe,t as me}from"./dialog-gtFLyacK.js";import{t as he}from"./utils-2ZK8yboQ.js";import{t as q}from"./AgentAvatar-Bk-m9q6w.js";import{n as J}from"./Icon-D1BcR8Tz.js";import{t as Y}from"./button-9R-WgVMl.js";import{i as ge}from"./OverlayScrollbar-Bahg_P3r.js";import{a as _e,n as X,r as ve,t as Z}from"./fileMentionTouchSelection-DstJbYAw.js";import{t as ye}from"./MarkdownRenderer-BPYs05iK.js";import{n as be}from"./textarea-DE1UrdtK.js";import{c as xe,s as Se}from"./imageSource-BlAJJUEI.js";import{D as Ce,S as we,T as Te,a as Ee,c as De,d as Oe,f as ke,i as Ae,l as je,m as Me,n as Ne,o as Pe,p as Fe,r as Ie,t as Le,u as Re}from"./sessionChangeSummary-DKJxz5er.js";import{a as ze,t as Be}from"./sessionLookup-CBT9qysS.js";import{a as Ve,i as He,n as Ue,r as We,t as Ge}from"./context-menu-CSyOhRz8.js";import{i as Ke,n as qe,r as Je}from"./assistant-attachment-cache-C0aRnFkj.js";var Ye=b();function Xe(e){return[...e].sort((e,t)=>{let n=e.latestMessagePreview?.createdAt??-1/0,r=t.latestMessagePreview?.createdAt??-1/0;return n===r?0:r-n})}var Q=e(g(),1),$=h();function Ze({snapshot:e}){let{t}=k(),[n,r]=Q.useState(!1),i=Q.useRef(!1),a=E(async()=>{if(!i.current){i.current=!0,r(!0);try{(await z(e)).failed&&S.error(t(`assistants.unread.markAllFailed`))}catch{S.error(t(`assistants.unread.markAllFailed`))}finally{i.current=!1,r(!1)}}});return(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`xs`,onClick:a,className:`max-w-full whitespace-normal text-right`,disabled:n||!e.assistants.some(e=>(e.unreadCount??0)>0&&e.readTip),"aria-busy":n,children:t(`assistants.unread.markAll`)})}var Qe=e=>{let t=(0,Ye.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}=k(),d=`calc(${c}px * var(--dpt-n, 1))`,f;t[0]===s?f=t[1]:(f=he(`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)(q,{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 h;t[9]!==u||t[10]!==l?(h=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]=h):h=t[11];let g;return t[12]!==f||t[13]!==p||t[14]!==m||t[15]!==h?(g=(0,$.jsxs)(`span`,{className:f,style:p,"data-assistant-working-avatar":``,children:[m,h]}),t[12]=f,t[13]=p,t[14]=m,t[15]=h,t[16]=g):g=t[16],g},$e=m(e=>({workingByID:{},setWorking:(t,n)=>e(e=>({workingByID:{...e.workingByID,[t]:n}}))})),et=({sending:e=!1,processing:t=!1,serverWorking:n=!1})=>e||t||n,tt=(e,t)=>{let n=(0,Ye.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=et({processing:a,serverWorking:r}),n[2]=a,n[3]=r,n[4]=o):o=n[4],o};function nt(e){let t=(0,Ye.c)(12),{assistantID:n,position:a}=e,o=Q.useRef(null),s=Q.useRef(!1),c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c={busy:!1,done:!1,retryAt:0},t[0]=c):c=t[0];let l=Q.useRef(c),[u]=Q.useState(ct),d;t[1]!==n||t[2]!==a||t[3]!==u?(d=()=>{let e=o.current;if(!e||!s.current||l.current.busy||l.current.done||Date.now()<l.current.retryAt||u.transport!==r()||u.generation!==i()||document.visibilityState!==`visible`||(_()?!document.documentElement.classList.contains(`oc-native-app-active`):!document.hasFocus())||e.parentElement?.closest(`[inert], [aria-hidden="true"]`))return;let t=e.closest(`[data-assistant-contact-transcript]`);if(!t||t.scrollHeight-t.scrollTop-t.clientHeight>2)return;let c=e.getBoundingClientRect(),d=t.getBoundingClientRect(),f=window.visualViewport,p=f?.offsetTop??0,m=p+(f?.height??window.innerHeight);c.height<=0||c.width<=0||c.bottom>Math.min(d.bottom,m)||c.top<Math.max(d.top,p)||c.right<=Math.max(d.left,0)||c.left>=Math.min(d.right,window.innerWidth)||(l.current.busy=!0,te(n,a).then(()=>{l.current.done=!0}).catch(()=>{l.current.retryAt=Date.now()+15e3}).finally(()=>{l.current.busy=!1}))},t[1]=n,t[2]=a,t[3]=u,t[4]=d):d=t[4];let f=E(d),p;t[5]===f?p=t[6]:(p=e=>{s.current=e.some(st),f()},t[5]=f,t[6]=p);let m;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(m={threshold:1},t[7]=m):m=t[7],T(o,E(p),m),D(`visibilitychange`,f,ot),D(`focus`,f,at),D(`resize`,f,it);let h,g;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(h=()=>o.current?.closest(`[data-assistant-contact-transcript]`),g={passive:!0},t[8]=h,t[9]=g):(h=t[8],g=t[9]),D(`scroll`,f,h,g);let v;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(v={attributes:!0,attributeFilter:[`class`]},t[10]=v):v=t[10],O(f,rt,v),C(f,15e3);let y;return t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(`span`,{ref:o,"aria-hidden":`true`,className:`block h-px w-px shrink-0`,"data-assistant-read-marker":``}),t[11]=y):y=t[11],y}function rt(){return document.documentElement}function it(){return window.visualViewport}function at(){return window}function ot(){return document}function st(e){return e.isIntersecting&&e.intersectionRatio===1}function ct(){return{transport:r(),generation:i()}}var lt=e=>e?.directories.flatMap(({directory:e,sessions:t})=>e?t.filter(e=>!e.time.archived).map(t=>({...t,directory:e})):[])??null,ut=Q.forwardRef(({query:e,isMobile:t,listId:n,onHighlightChange:r,onSelect:i,onClose:a},o)=>{let{t:s}=k(),c=xe(),l=x({...re(c),select:lt}),u=Q.useMemo(()=>ae({sessions:l.data??[],currentSessionId:null,searchQuery:e}),[l.data,e]),[d,f]=Q.useState({query:e,index:0}),p=Math.min(d.query===e?d.index:0,Math.max(0,u.length-1)),m=Q.useRef(null),h=Q.useRef([]),g=Q.useMemo(Z,[]);D(`pointerdown`,e=>{e.target instanceof Node&&!m.current?.contains(e.target)&&a()},void 0,{capture:!0}),Q.useLayoutEffect(()=>{h.current[p]?.scrollIntoView?.({block:`nearest`})},[p]),Q.useLayoutEffect(()=>{r(u.length?`${n}-${p}`:void 0)},[p,n,u.length,r]);let _=E(t=>{if(t===`Escape`){a();return}u.length&&(t===`ArrowDown`&&f({query:e,index:(p+1)%u.length}),t===`ArrowUp`&&f({query:e,index:(p-1+u.length)%u.length}),(t===`Enter`||t===`Tab`)&&i(u[p]))});return Q.useImperativeHandle(o,()=>({keyDown:_}),[_]),(0,$.jsxs)(X,{ref:m,isMobile:t,className:`max-w-[640px] max-h-64`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,$.jsx)(`span`,{className:`flex-1 typography-meta text-muted-foreground`,children:s(`assistants.contact.sessionMention.scope`)}),(0,$.jsx)(Y,{type:`button`,size:`icon`,variant:`ghost`,"aria-label":s(`dialog.common.actions.close`),onClick:a,children:(0,$.jsx)(J,{name:`close`,className:`size-4`})})]}),l.isPending?(0,$.jsx)(`p`,{role:`status`,className:`px-3 py-2 typography-meta text-muted-foreground`,children:s(`common.loading`)}):null,l.isError?(0,$.jsxs)(`div`,{role:`alert`,className:`px-3 py-2 typography-meta text-[var(--status-error)]`,children:[s(`assistants.contact.sessionMention.loadFailed`),(0,$.jsx)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void l.refetch(),children:s(`chat.history.retry`)})]}):null,l.isSuccess&&!u.length?(0,$.jsx)(`p`,{role:`status`,className:`px-3 py-2 typography-meta text-muted-foreground`,children:s(l.data===null?`common.unavailable`:`sessions.sidebar.empty.noMatches.title`)}):null,(0,$.jsx)(be,{preventOverscroll:!0,outerClassName:`flex-1 min-h-0`,className:`px-0`,children:(0,$.jsx)(`div`,{id:n,role:`listbox`,"aria-label":s(`chat.fileMentionAutocomplete.groups.sessions`),className:`pb-2`,children:u.map((r,a)=>(0,$.jsxs)(`div`,{id:`${n}-${a}`,role:`option`,"aria-selected":a===p,ref:e=>{h.current[a]=e},className:he(`flex min-h-11 cursor-pointer items-center gap-2 rounded-lg px-3 py-1.5 typography-ui-label`,ve(t,a===p)),onMouseDown:e=>e.preventDefault(),onMouseMove:()=>f({query:e,index:a}),onPointerDown:e=>{e.pointerType===`touch`&&g.pointerDown(e.clientX,e.clientY)},onPointerMove:e=>{e.pointerType===`touch`&&g.pointerMove(e.clientX,e.clientY)},onPointerUp:e=>{e.pointerType===`touch`&&g.pointerUp(()=>i(r))&&(e.preventDefault(),e.stopPropagation())},onPointerCancel:()=>g.pointerCancel(),onClick:()=>g.click(()=>i(r)),children:[(0,$.jsx)(J,{name:`chat-thread`,className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate`,title:r.title,children:r.title||s(`chat.fileMentionAutocomplete.untitledSession`)}),(0,$.jsx)(`div`,{className:`truncate typography-meta text-muted-foreground`,title:r.directory,children:r.directory})]})]},`${r.directory}:${r.id}`))})}),t?null:(0,$.jsx)(`div`,{className:`border-t px-3 py-1.5 typography-meta text-muted-foreground`,children:s(`chat.autocomplete.keyboardHint`)})]})}),dt=e=>{let t=(0,Ye.c)(87),n,r,i,u;t[0]===e?(n=t[1],r=t[2],i=t[3],u=t[4]):({active:n,working:u,onChange:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=u);let d=u!==void 0&&u,{t:m}=k(),h;t[5]===i.value?h=t[6]:(h=()=>({canonical:i.value,document:c(i.value,new Map)}),t[5]=i.value,t[6]=h);let[g,_]=Q.useState(h),v;t[7]!==g.canonical||t[8]!==g.document||t[9]!==i.value?(v=g.canonical===i.value?g.document:c(i.value,new Map),t[7]=g.canonical,t[8]=g.document,t[9]=i.value,t[10]=v):v=t[10];let y=v,[b,x]=Q.useState(0),[S,C]=Q.useState(!0),[w,T]=Q.useState(!1),[D,O]=Q.useState(),A=Q.useRef(null),j=Q.useRef(null),M=Q.useRef(null),N=Q.useRef(null),P;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(P=je(),t[11]=P):P=t[11];let F=Q.useRef(P),I=Q.useId(),L;t[12]!==n||t[13]!==w||t[14]!==b||t[15]!==S||t[16]!==y.text||t[17]!==i.disabled||t[18]!==i.pending?(L=n&&!i.pending&&!i.disabled&&!S&&!w?_e({text:y.text,cursor:b}):null,t[12]=n,t[13]=w,t[14]=b,t[15]=S,t[16]=y.text,t[17]=i.disabled,t[18]=i.pending,t[19]=L):L=t[19];let R=L,z=R?.kind===`mention`?R:null,B;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(B=()=>{N.current!==null&&(A.current?.focus({preventScroll:!0}),A.current?.setSelectionRange(N.current,N.current),N.current=null)},t[20]=B):B=t[20];let V;t[21]===y?V=t[22]:(V=[y],t[21]=y,t[22]=V),Q.useLayoutEffect(B,V);let H;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(H=()=>C(!0),t[23]=H):H=t[23];let ee=E(H),te;t[24]!==w||t[25]!==b||t[26]!==y||t[27]!==r?(te=(e,t,n)=>{let i=n===void 0||n,a=l(e);a.ok&&(i&&(F.current=Re(F.current,{before:De(y,[],{start:A.current?.selectionStart??b,end:A.current?.selectionEnd??b}),after:De(e,[],{start:t,end:t})})),w||(N.current=t),x(t),_({canonical:a.text,document:e}),r(a.text))},t[24]=w,t[25]=b,t[26]=y,t[27]=r,t[28]=te):te=t[28];let U=E(te),ne;t[29]!==U||t[30]!==y||t[31]!==z||t[32]!==m?(ne=e=>{if(!z)return;let t=e.title||m(`chat.fileMentionAutocomplete.untitledSession`),n=s(y,z.tokenStart,z.tokenEnd,{id:`session:${e.id}:${crypto.randomUUID()}`,kind:`session`,sessionId:e.id,display:p({trigger:`@`,icon:`chat-thread`,label:t})},{inlineBoundaries:!0,padDocumentEdges:!0}),r=n.caret+ +(n.document.text[n.caret]===` `);C(!0),U(n.document,r)},t[29]=U,t[30]=y,t[31]=z,t[32]=m,t[33]=ne):ne=t[33];let re=E(ne),ie;t[34]!==U||t[35]!==y?(ie=(e,t)=>{let n=e.currentTarget;if(n.selectionStart===n.selectionEnd||!e.clipboardData||!y.references.some(e=>e.start<n.selectionEnd&&e.end>n.selectionStart))return;let r=a(n.selectionStart,n.selectionEnd,y.references)??{start:n.selectionStart,end:n.selectionEnd},i=l({text:y.text.slice(r.start,r.end),references:y.references.filter(e=>e.start>=r.start&&e.end<=r.end).map(e=>({...e,start:e.start-r.start,end:e.end-r.start}))});if(i.ok&&(e.preventDefault(),e.clipboardData.setData(`text/plain`,i.text),t)){let e=f(y,y.text.slice(0,r.start)+y.text.slice(r.end),r.start,r.start);U(e.document,e.caret)}},t[34]=U,t[35]=y,t[36]=ie):ie=t[36];let ae=E(ie),oe;t[37]!==y.references||t[38]!==y.text?(oe=Me(y.text,y.references.map(ft))?.map(pt),t[37]=y.references,t[38]=y.text,t[39]=oe):oe=t[39];let se=oe,W=y.text,G=i.pending||d,ce=i.pending===!0,le=i.layout===`inline`?`py-3 leading-6`:`pt-4 pb-2`,ue;t[40]!==i.textLayoutClassName||t[41]!==le?(ue=he(`whitespace-pre-wrap break-words overflow-hidden px-3 typography-markdown md:typography-ui-label`,le,i.textLayoutClassName),t[40]=i.textLayoutClassName,t[41]=le,t[42]=ue):ue=t[42];let K;t[43]!==U||t[44]!==y?(K=(e,t)=>{let n=f(y,e,t?.target.selectionStart??e.length,t?.target.selectionEnd??e.length);U(n.document,n.caret),C(t?.nativeEvent?.inputType===`insertFromPaste`)},t[43]=U,t[44]=y,t[45]=K):K=t[45];let de=z?I:void 0,fe=z?D:void 0,pe;t[46]===i.textareaProps?pe=t[47]:(pe=e=>{i.textareaProps?.onScroll?.(e),j.current&&(j.current.scrollTop=e.currentTarget.scrollTop,j.current.scrollLeft=e.currentTarget.scrollLeft)},t[46]=i.textareaProps,t[47]=pe);let me,q;t[48]!==ae||t[49]!==i.textareaProps?(me=e=>{i.textareaProps?.onCopy?.(e),e.defaultPrevented||ae(e,!1)},q=e=>{i.textareaProps?.onCut?.(e),e.defaultPrevented||ae(e,!0)},t[48]=ae,t[49]=i.textareaProps,t[50]=me,t[51]=q):(me=t[50],q=t[51]);let J;t[52]===i.textareaProps?J=t[53]:(J=e=>{x(e.currentTarget.selectionStart),i.textareaProps?.onSelect?.(e)},t[52]=i.textareaProps,t[53]=J);let Y,ge;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(Y=()=>{T(!0)},ge=e=>{T(!1),x(e.currentTarget.selectionStart)},t[54]=Y,t[55]=ge):(Y=t[54],ge=t[55]);let X;t[56]!==U||t[57]!==w||t[58]!==y||t[59]!==z||t[60]!==i.textareaProps?(X=e=>{if(i.textareaProps?.onKeyDown?.(e),!(e.defaultPrevented||Te(e))){if(w){e.key===`Enter`&&e.preventDefault();return}if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`z`){let t=e.shiftKey?Oe(F.current,y):ke(F.current,y);t&&(e.preventDefault(),F.current=t.history,U(t.snapshot.document,t.snapshot.selection.end,!1),C(!0));return}if(e.key===`Backspace`||e.key===`Delete`){let t=o(y,{key:e.key,selectionStart:e.currentTarget.selectionStart,selectionEnd:e.currentTarget.selectionEnd,altKey:e.altKey});if(t){e.preventDefault(),U(t.document,t.caret),C(!0);return}}z&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`,`Escape`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),M.current?.keyDown(e.key))}},t[56]=U,t[57]=w,t[58]=y,t[59]=z,t[60]=i.textareaProps,t[61]=X):X=t[61];let ve;t[62]!==i.textareaProps||t[63]!==de||t[64]!==fe||t[65]!==pe||t[66]!==me||t[67]!==q||t[68]!==J||t[69]!==X?(ve={...i.textareaProps,"aria-controls":de,"aria-activedescendant":fe,"aria-autocomplete":`list`,onScroll:pe,onCopy:me,onCut:q,onSelect:J,onCompositionStart:Y,onCompositionEnd:ge,onKeyDown:X},t[62]=i.textareaProps,t[63]=de,t[64]=fe,t[65]=pe,t[66]=me,t[67]=q,t[68]=J,t[69]=X,t[70]=ve):ve=t[70];let Z;t[71]!==ee||t[72]!==I||t[73]!==z||t[74]!==i.isMobile||t[75]!==re?(Z=z?(0,$.jsx)(ut,{ref:M,query:z.query,isMobile:i.isMobile??!1,listId:I,onHighlightChange:O,onSelect:re,onClose:ee}):null,t[71]=ee,t[72]=I,t[73]=z,t[74]=i.isMobile,t[75]=re,t[76]=Z):Z=t[76];let ye;return t[77]!==y.text||t[78]!==se||t[79]!==i||t[80]!==G||t[81]!==ce||t[82]!==ue||t[83]!==K||t[84]!==ve||t[85]!==Z?(ye=(0,$.jsx)(we,{...i,value:W,pending:G,disableInputWhilePending:ce,inputRef:A,highlightedContent:se,highlightRef:j,textLayoutClassName:ue,onChange:K,textareaProps:ve,children:Z}),t[77]=y.text,t[78]=se,t[79]=i,t[80]=G,t[81]=ce,t[82]=ue,t[83]=K,t[84]=ve,t[85]=Z,t[86]=ye):ye=t[86],ye};function ft(e){return{start:e.start,end:e.end,priority:103,...u(e)}}function pt(e,t){return(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(Fe,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)}var mt=`max-h-72 max-w-full rounded-[1.35rem] border border-border/40 object-contain`;function ht({assistantID:e,descriptor:t}){let{t:n}=k(),r=xe(),{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,f]=Q.useState(0),[p,m]=Q.useState(``),[h,g]=Q.useState(!1),[_,v]=Q.useState(!1),y=Q.useRef(null),b=Q.useRef([]);Q.useEffect(()=>{m(``),g(!1);let t=new AbortController,n;return u&&Je(e,l,{signal:t.signal}).then(e=>{if(t.signal.aborted){e.release();return}n=e.release,m(e.url)}).catch(()=>{t.signal.aborted||g(!0)}),()=>{t.abort(),n?.()}},[e,l,r,u,d]),Q.useEffect(()=>()=>{y.current?.abort(),b.current.forEach(e=>URL.revokeObjectURL(e)),b.current=[]},[e,l,r]);let x=E(async()=>{if(y.current)return;let t=new AbortController;y.current=t,v(!0),g(!1);try{let r=await qe(e,l,{signal:t.signal});if(t.signal.aborted)return;b.current.forEach(e=>URL.revokeObjectURL(e));let i=URL.createObjectURL(r);b.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||g(!0)}finally{y.current===t&&(y.current=null),t.signal.aborted||v(!1)}}),S=c||n(u?`assistants.contact.attachment.image`:`assistants.contact.attachment.file`);return u&&p&&!h?(0,$.jsx)(`img`,{src:p,alt:S,className:mt,onError:()=>g(!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)(J,{name:`file-text`,className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate typography-ui`,children:S})]}),h?(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:n(`assistants.contact.attachment.loadFailed`)}):null,u&&!h||_?(0,$.jsx)(`span`,{role:`status`,className:`typography-micro text-muted-foreground`,children:n(`common.loading`)}):(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,onClick:u?()=>f(e=>e+1):()=>void x(),children:n(h?`chat.history.retry`:`assistants.contact.attachment.download`)})]})}function gt(e){let t=(0,Ye.c)(19),{part:n}=e,{t:r}=k(),i=/^(?:https?:|data:|blob:)/i.test(n.url)?n.url:``,a=Se(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:mt,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)(J,{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)(Y,{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 _t(e){let t=(0,Ye.c)(4),{assistantID:n,part:r}=e,i=xe(),a;return t[0]!==n||t[1]!==r||t[2]!==i?(a=`attachmentID`in r?(0,$.jsx)(ht,{assistantID:n,descriptor:r},`${i}:${n}:${r.attachmentID}:${r.sha256}`):(0,$.jsx)(gt,{part:r},`${i}:${r.url}`),t[0]=n,t[1]=r,t[2]=i,t[3]=a):a=t[3],a}var vt=[],yt=e=>e.flatMap(e=>e.type===`text`&&e.text.trim()?[e.text]:[]).join(`
|
|
2
|
-
`),bt=(e,t,n,r=Date.now())=>({assistantID:e,messageID:t,parts:n,status:`sending`,createdAt:r}),xt=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},St=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},Ct=(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:[]}),wt=(e,t,n)=>{let r=e.bubbles.filter(e=>!t.has(e.bubbleIndex)).map((t,r)=>Ct(e,t,n+r,t.done?`complete`:`streaming`));return e.status===`failed`?[...r,Ct(e,null,n+r.length,`failed`)]:e.status===`admitted`||e.status===`streaming`?[...r,Ct(e,null,n+r.length,`admitted`)]:r},Tt=(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:yt(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=wt(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)},Et=(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},Dt=(e,t)=>e.map(e=>e.messageID===t?{...e,status:`admitted`}:e),Ot=(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}],kt=(e,t,n)=>!t?.turnID||!t.assistantID||n?.has(t.turnID)?e:Ot(e,t.assistantID,t.turnID,t.admittedAt),At=(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=kt(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=Mt(u,{assistantID:n,turnID:e.turnID,status:`error`,error:e.text||`upstream_error`,occurredAt:s})));if(u=Nt(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},jt=(e,t)=>Ot(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}}),Mt=(e,t,n={})=>n.requireExisting&&!e.some(e=>e.assistantID===t.assistantID&&e.turnID===t.turnID)?e:Ot(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}:{}}),Nt=(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},Pt=(e,t,n)=>e.map(e=>e.messageID===t?{...e,status:`failed`,error:n}:e),Ft=(e,t)=>{if(e instanceof R){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 L(e)?t.timedOut:t.sendFailed},It=()=>{let e=!1;return{tryAcquire:()=>!e&&(e=!0,!0),release:()=>{e=!1}}},Lt=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:bt(e.assistantID,r,n,e.createdAt)}},Rt=e=>e.some(e=>e.status===`sending`),zt=e=>e.some(e=>e.status===`admitted`||e.status===`streaming`),Bt=[`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(` `),Vt=`${Bt} w-fit min-w-0 max-w-[min(100%,15rem)]`,Ht=`${Bt} w-fit min-w-0 max-w-[min(100%,20rem)]`;function Ut(e,t){(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())}var Wt=e=>{let t=(0,Ye.c)(26),{card:n}=e,{t:r}=k(),i=Ce(),a;t[0]===i?a=t[1]:(a=i&&!v(),t[0]=i,t[1]=a);let o=!!a,s=n.name,c=`${n.providerID}/${n.modelID}`,l;t[2]!==n.mode||t[3]!==c?(l=[c,n.mode].filter(Boolean),t[2]=n.mode,t[3]=c,t[4]=l):l=t[4];let u=l,d;t[5]!==n.assistantID||t[6]!==o?(d=()=>{if(o){se.getState().openAssistant(n.assistantID);return}ce(n.assistantID)},t[5]=n.assistantID,t[6]=o,t[7]=d):d=t[7];let f=E(d),p;t[8]===f?p=t[9]:(p=e=>{Ut(e,f)},t[8]=f,t[9]=p);let m=E(p),h;t[10]!==r||t[11]!==s?(h=r(`assistants.contact.card.assistant.aria`,{name:s}),t[10]=r,t[11]=s,t[12]=h):h=t[12];let g;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(g=(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)(J,{name:`robot-2`,className:`size-3`})})}),t[13]=g):g=t[13];let _;t[14]===s?_=t[15]:(_=(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-medium text-foreground`,children:s}),t[14]=s,t[15]=_);let y;t[16]===u?y=t[17]:(y=u.length>0?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:u.join(` · `)}):null,t[16]=u,t[17]=y);let b;t[18]!==_||t[19]!==y?(b=(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[g,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[_,y]})]}),t[18]=_,t[19]=y,t[20]=b):b=t[20];let x;return t[21]!==m||t[22]!==f||t[23]!==b||t[24]!==h?(x=(0,$.jsx)(`article`,{className:Vt,role:`button`,tabIndex:0,"aria-label":h,"data-assistant-contact-card":`assistant`,onClick:f,onKeyDown:m,children:b}),t[21]=m,t[22]=f,t[23]=b,t[24]=h,t[25]=x):x=t[25],x},Gt=e=>{let t=(0,Ye.c)(25),{card:n}=e,{t:r}=k(),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=E(Kt),u;t[7]===l?u=t[8]:(u=e=>{Ut(e,l)},t[7]=l,t[8]=u);let d=E(u),f;t[9]!==r||t[10]!==i?(f=r(`assistants.contact.card.schedule.aria`,{name:i}),t[9]=r,t[10]=i,t[11]=f):f=t[11];let p;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(p=(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)(J,{name:`calendar`,className:`size-3`})})}),t[12]=p):p=t[12];let m;t[13]===i?m=t[14]:(m=(0,$.jsx)(`h3`,{className:`min-w-0 truncate typography-ui-label font-medium text-foreground`,children:i}),t[13]=i,t[14]=m);let h;t[15]===c?h=t[16]:(h=c?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:c}):null,t[15]=c,t[16]=h);let g;t[17]!==m||t[18]!==h?(g=(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[p,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[m,h]})]}),t[17]=m,t[18]=h,t[19]=g):g=t[19];let _;return t[20]!==d||t[21]!==l||t[22]!==f||t[23]!==g?(_=(0,$.jsx)(`article`,{className:Vt,role:`button`,tabIndex:0,"aria-label":f,"data-assistant-contact-card":`schedule`,onClick:l,onKeyDown:d,children:g}),t[20]=d,t[21]=l,t[22]=f,t[23]=g,t[24]=_):_=t[24],_};function Kt(){y.getState().setActiveMainTab(`schedule`),y.getState().setScheduledTasksDialogOpen(!0)}var qt=(e,t)=>t===`cancelled`?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`,Jt=e=>e===`cancelled`?`assistants.contact.card.session.status.cancelled`: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,Yt=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`,Xt=e=>e.split(/[/\\]/u).filter(Boolean).at(-1)||e,Zt=e=>{let t=(0,Ye.c)(35),{card:n}=e,{t:r}=k(),i=Ce(),a;t[0]===i?a=t[1]:(a=i&&!v(),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 c=ne(s),l=oe(n.sessionID),u=(typeof c?.title==`string`&&c.title.trim()?c.title.trim():null)||n.title||r(`assistants.contact.card.session.untitled`),d=qt(l?.type,n.status),f=Jt(d),p=d===`busy`||d===`retry`,m=Xt(typeof c?.directory==`string`&&c.directory.trim()?c.directory.trim():n.directory),h=Ne(c)||n.branch,g=Ae(c),_=Ie(c),b=Le(_),x=[m,g,h].filter(Qt),S;t[4]!==n.directory||t[5]!==n.sessionID||t[6]!==o?(S=()=>{let e=Be(n.sessionID)?.directory||n.directory;W(n.sessionID,e,{phoneShell:o,switchToChat:!0}),o||y.getState().setActiveMainTab(`chat`)},t[4]=n.directory,t[5]=n.sessionID,t[6]=o,t[7]=S):S=t[7];let C=E(S),w;t[8]===C?w=t[9]:(w=e=>{Ut(e,C)},t[8]=C,t[9]=w);let T=E(w),D=Ht,O=r(`assistants.contact.card.session.aria`,{title:u}),A;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(J,{name:`chat-3`,className:`size-3`})}),t[10]=A):A=t[10];let j;t[11]===p?j=t[12]:(j=p?(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]=p,t[12]=j);let M;t[13]===j?M=t[14]:(M=(0,$.jsxs)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:[A,j]}),t[13]=j,t[14]=M);let N;t[15]===u?N=t[16]:(N=(0,$.jsx)(`h3`,{className:`min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground`,children:u}),t[15]=u,t[16]=N);let P=f?(0,$.jsx)(`span`,{className:he(`shrink-0 rounded-full px-1.5 py-0.5 typography-micro leading-none`,Yt(d)),children:r(f)}):null,F;t[17]!==N||t[18]!==P?(F=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[N,P]}),t[17]=N,t[18]=P,t[19]=F):F=t[19];let I;t[20]===x?I=t[21]:(I=x.length>0?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:x.join(` · `)}):null,t[20]=x,t[21]=I);let L=b||_?.files!==void 0&&_.files>0?(0,$.jsxs)(`p`,{className:`flex flex-wrap items-baseline gap-x-1.5 typography-micro tabular-nums`,children:[_?.additions===void 0?null:(0,$.jsxs)(`span`,{className:`text-[var(--status-success)]`,children:[`+`,_.additions]}),_?.deletions===void 0?null:(0,$.jsxs)(`span`,{className:`text-[var(--status-error)]`,children:[`−`,_.deletions]}),_?.files===void 0?null:(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:_.files===1?r(`assistants.contact.card.session.changes.filesSingle`,{count:_.files}):r(`assistants.contact.card.session.changes.filesPlural`,{count:_.files})})]}):null,R;t[22]!==F||t[23]!==I||t[24]!==L?(R=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[F,I,L]}),t[22]=F,t[23]=I,t[24]=L,t[25]=R):R=t[25];let z;t[26]!==M||t[27]!==R?(z=(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[M,R]}),t[26]=M,t[27]=R,t[28]=z):z=t[28];let B;return t[29]!==T||t[30]!==C||t[31]!==z||t[32]!==D||t[33]!==O?(B=(0,$.jsx)(`article`,{className:D,role:`button`,tabIndex:0,"aria-label":O,"data-assistant-contact-card":`session`,onClick:C,onKeyDown:T,children:z}),t[29]=T,t[30]=C,t[31]=z,t[32]=D,t[33]=O,t[34]=B):B=t[34],B};function Qt(e){return!!(e&&e.trim())}var $t=2,en=1500,tn=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),nn=e=>e.scrollHeight-e.scrollTop-e.clientHeight,rn=e=>nn(e)<=$t,an=(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},on=e=>e.altKey||e.ctrlKey||e.metaKey?!1:e.key===`ArrowDown`||e.key===`PageDown`||e.key===`End`,sn=({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),f=Q.useRef(null),p=Q.useRef(0),m=Q.useRef(null),h=Q.useRef(null),g=Q.useRef(e);g.current=e;let _=Q.useMemo(()=>e=>{i.current=e,o(t=>t===e?t:e)},[]),v=Q.useMemo(()=>e=>{c(t=>t===e?t:e)},[]),y=E(()=>{let e=i.current;if(!e||!g.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}),b=E(()=>{let e=i.current,t=u.current;if(!e||!t||!g.current||l.current)return;if(Math.abs(e.scrollTop-p.current)>.5){p.current=e.scrollTop,y();return}let n=Array.from(e.querySelectorAll(`[data-message-id]`)).find(e=>e.dataset.messageId===t.id);if(!n){y();return}let r=n.getBoundingClientRect().top-e.getBoundingClientRect().top-t.offset;Math.abs(r)>.5&&(e.scrollTop+=r),p.current=e.scrollTop}),x=E(()=>{l.current=!1,p.current=i.current?.scrollTop??0,y()}),S=E(()=>{if(!g.current||!l.current)return!1;let e=i.current;if(!e)return!1;let t=tn(e),n=Math.min(p.current,Math.max(0,t.scrollHeight-t.clientHeight));return t.scrollTop<n-.5?(l.current=!1,p.current=t.scrollTop,y(),!1):rn(t)?(p.current=t.scrollTop,!1):(e.scrollTop=e.scrollHeight,p.current=e.scrollTop,!0)}),C=E(e=>{h.current={direction:e,expiresAt:performance.now()+en}}),T=E(()=>{let e=h.current;return e?performance.now()>e.expiresAt?(h.current=null,null):e.direction:null}),O=E(()=>{l.current=!1,y()}),k=E(()=>{if(!g.current)return;let e=i.current;if(!e)return;let t=tn(e),n=t.scrollTop>p.current,a=Math.min(p.current,Math.max(0,t.scrollHeight-t.clientHeight));if(p.current=t.scrollTop,l.current){t.scrollTop<a-.5&&O();return}let o=T();y(),t.scrollTop<=80&&o===`up`&&r?.(),n&&rn(t)&&(o===`down`||o===`scrollbar`)&&(l.current=!0)}),A=E(e=>{let t=i.current;if(!(!t||e.deltaY===0)){if(e.deltaY<0){if(Pe(t,e.target))return;C(`up`),O(),t.scrollTop<=80&&r?.();return}an(t,e.target)||C(`down`)}}),j=E(e=>{h.current=null;let t=e.touches.item(0);m.current=t?{x:t.clientX,y:t.clientY,deltaX:0,deltaY:0}:null}),M=E(e=>{let t=i.current,n=e.touches.item(0);if(!t||!n){m.current=null;return}let a=m.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(m.current={x:n.clientX,y:n.clientY,deltaX:c,deltaY:l},!(Math.abs(c)>=Math.abs(l))){if(l>0&&Pe(t,e.target)||l<0&&an(t,e.target)){m.current.deltaX=0,m.current.deltaY=0;return}C(l>0?`up`:`down`),l>2&&(O(),t.scrollTop<=80&&r?.())}}),N=E(()=>{m.current=null}),P=E(e=>{if(Ee(e)){C(`up`),O(),(i.current?.scrollTop??1/0)<=80&&r?.();return}on(e)&&C(`down`)}),F=E(e=>{let t=i.current;e.pointerType===`mouse`&&e.target===t&&C(`scrollbar`)});Q.useLayoutEffect(()=>{let n=e?t:null,r=i.current;(d.current!==n||f.current!==r)&&(d.current=n,f.current=r,l.current=!0,u.current=null,h.current=null,m.current=null,p.current=r?.scrollTop??0),e&&(S(),b())},[e,t,n,a]);let I=Q.useMemo(()=>()=>void 0,[]),L=e&&a?a:I,R=Q.useMemo(()=>({passive:!0}),[]);D(`scroll`,k,L,R),D(`wheel`,A,L,R),D(`touchstart`,j,L,R),D(`touchmove`,M,L,R),D(`touchend`,N,L,R),D(`touchcancel`,N,L,R),D(`keydown`,P,L),D(`pointerdown`,F,L,R);let z=E(()=>{S(),b()});return w(typeof ResizeObserver<`u`&&e?s:null,z),{scrollRef:_,contentRef:v,preparePrepend:x}},cn=64,ln=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)},un=e=>Array.from(e?.files||[]),dn=async(e,t=d)=>{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}},fn=(e,t)=>{let n=[...e,...t];for(let e of n.slice(cn))e.url.startsWith(`blob:`)&&URL.revokeObjectURL(e.url);return n.slice(0,cn)},pn=e=>e.trim().startsWith(`oc.settle.`),mn=({assistant:e,warning:t,active:n,overlayHeader:r=!1})=>{let{t:i}=k(),a=xe(),o=y(e=>e.isMobile),s=I(),c=U(),l=N(e.id,n),u=y(e=>e.isSettingsDialogOpen),f=n&&!u&&!l.hasMessageGap?M(e,l.data):null,p=A(e.name),m=p.displayName||e.name,h=(e,t)=>{let n=e?c.data?.assistants.find(t=>t.id===e):void 0;return n?A(n.name).displayName||n.name:t||i(`assistants.contact.peer.unknown`)},[g,_]=Q.useState(``),[v,b]=Q.useState([]),x=Q.useRef(null),S=Q.useRef(new Map),C=Q.useRef(new AbortController);Q.useEffect(()=>{let e=new AbortController;return C.current=e,()=>e.abort()},[e.id,a]);let w=Q.useRef(new Set);Q.useEffect(()=>{let e=new Set(v.map(e=>e.url));for(let t of w.current)e.has(t)||URL.revokeObjectURL(t);w.current=e},[v]),Q.useEffect(()=>()=>{for(let e of w.current)URL.revokeObjectURL(e)},[]);let[T,D]=Q.useState([]),[O,P]=Q.useState([]),[L,z]=Q.useState(null),H=Q.useRef(!1);Q.useEffect(()=>{S.current.clear(),x.current=null,D([]),P([]),z(null)},[a]);let ee=Q.useMemo(()=>It(),[]),te=Q.useRef(new Set),ne=Q.useRef(new Map),re=$e(e=>e.setWorking),ae=l.data?.messages??vt,oe=xt(T,e.id),se=St(O,e.id),W=Tt(ae,oe,e.id,se).filter(e=>{let t=Array.isArray(e.parts)?e.parts:[];return t.length===0||t.some(e=>!(e.type===`text`&&pn(e.text)))}),G=Rt(oe),ce=zt(se),le=!!(e.working||e.activeContactTurn),ue=c.data?.revision??null,K=se.reduce((e,t)=>e+t.bubbles.reduce((e,t)=>e+t.text.length,0),0),de=new Map(se.map(e=>[e.turnID,e])),fe=Q.useRef(!1),pe=E(async(e=!1)=>{if(!(!n||fe.current||l.isFetchingPreviousPage||l.isFillingMessageGap)&&!(e&&l.previousPageError)&&!(!l.hasPreviousPage&&!l.hasMessageGap)){fe.current=!0,ge();try{l.hasMessageGap?await l.retryMessageGap():await l.fetchPreviousPage()}catch{}finally{fe.current=!1}}}),{scrollRef:me,contentRef:q,preparePrepend:ge}=sn({active:n,assistantID:e.id,contentRevision:`${W[0]?.messageID}:${W.length}:${K}:${l.isFetchingPreviousPage}:${l.hasPreviousPage}:${l.isFillingMessageGap}`,onLoadEarlier:()=>{pe(!0)}});Q.useEffect(()=>{z(null),te.current.clear(),ne.current=new Map,D(t=>xt(t,e.id)),P(t=>St(t,e.id))},[e.id]),Q.useEffect(()=>{D(e=>Et(e,ae))},[ae]),Q.useEffect(()=>{let t=new Set(oe.filter(e=>e.status===`sending`).map(e=>e.messageID));P(n=>At(n,{assistantID:e.id,activeContactTurn:e.activeContactTurn?{turnID:e.activeContactTurn.turnID,admittedAt:e.activeContactTurn.admittedAt}:null,serverWorking:le,snapshotRevision:ue,admissionRevisionByTurnID:ne.current,pendingSendTurnIDs:t,messages:ae,settledTurnIDs:te.current}))},[e.activeContactTurn,e.id,ae,oe,le,ue]),Q.useEffect(()=>{re(e.id,G||ce||le)},[e.id,ce,G,le,re]),Q.useEffect(()=>{let t=e.id;return()=>{re(t,!1)}},[e.id,re]);let _e=E(t=>{if(!(!(`assistantID`in t)||t.assistantID!==e.id)){if(t.type===`contact-turn-start`){te.current.delete(t.turnID),P(e=>Ot(e,t.assistantID,t.turnID,t.occurredAt));return}if(t.type===`contact-bubble-delta`){if(te.current.has(t.turnID))return;P(e=>jt(e,t));return}t.type===`contact-turn-end`&&(te.current.add(t.turnID),P(e=>Nt(Mt(e,t,{requireExisting:!0}),ae)))}});Q.useEffect(()=>{if(n)return ie(_e)},[n,e.id]);let X=E(async e=>{if(G)return;let t=C.current,n=await dn(e);if(t.signal.aborted){n.attachments.forEach(e=>URL.revokeObjectURL(e.url));return}n.skippedTooLarge>0&&z(i(`assistants.contact.attachment.tooLarge`)),n.attachments.length!==0&&b(e=>fn(e,n.attachments))}),ve=E(e=>{let t=ln(e.clipboardData);t.length!==0&&(e.preventDefault(),X(t))}),Z=E(e=>{Array.from(e.dataTransfer?.types??[]).includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}),be=E(e=>{let t=un(e.dataTransfer);t.length!==0&&(e.preventDefault(),X(t))}),Se=E(async()=>{let t=C.current,n=g,r=v,a=e.id,o=x.current,c=o?.assistantID===a&&o.text===n&&o.attachments===r?o.messageID:null,l=Lt({gate:ee,sending:Rt(oe),text:n,attachments:r,assistantID:a,createMessageID:()=>c||`oc_contact_${d()}`});if(!l.ok)return;x.current={assistantID:a,text:n,attachments:r,messageID:l.messageID},D(e=>[...e.filter(e=>e.messageID!==l.messageID),l.turn]),z(null);let u=()=>{_(e=>e===n?``:e),b(e=>e.filter(e=>!r.includes(e))),r.forEach(e=>S.current.delete(`${a}:${e.id}`)),x.current=null};try{let e=[];for(let n of r){let r=`${a}:${n.id}`,i=S.current.get(r);if(!i){if(i=await Ke(a,n.file,n.id,t.signal),t.signal.aborted)return;S.current.set(r,i)}e.push(i)}if(t.signal.aborted)return;let n=[...l.parts.filter(e=>e.type===`text`),...e];D(e=>e.map(e=>e.messageID===l.messageID?{...e,parts:n}:e));let i=await F(a,l.messageID,{parts:n});if(t.signal.aborted)return;u(),typeof i.revision==`number`&&ne.current.set(l.messageID,i.revision),D(e=>Dt(e,l.messageID)),te.current.has(l.messageID)||P(e=>Ot(e,a,l.messageID)),s.data?.serverInstanceID&&j({serverInstanceID:s.data.serverInstanceID,assistantID:a,name:m,avatarSeed:a,...p.avatarEmoji?{avatarEmoji:p.avatarEmoji}:{}}).catch(()=>void 0)}catch(e){if(t.signal.aborted)return;if(e instanceof R&&e.code===`admission_timeout`)try{let e=await V(a,l.messageID);if(t.signal.aborted)return;if(e){u(),typeof e.revision==`number`&&ne.current.set(l.messageID,e.revision),D(e=>Dt(e,l.messageID)),te.current.has(l.messageID)||P(e=>Ot(e,a,l.messageID));return}}catch{}let n=Ft(e,{noProvider:i(`assistants.contact.noProvider`),sendFailed:i(`assistants.contact.sendFailed`),timedOut:i(`assistants.contact.timedOut`)});D(e=>Pt(e,l.messageID,n)),z(n)}finally{ee.release()}}),Ce=E(async()=>{if(H.current)return;H.current=!0;let t=C.current;z(null);try{await B(e.id,e)}catch(e){t.signal.aborted||z(e instanceof Error?e.message:i(`settings.mcp.page.toast.unexpectedError`))}finally{H.current=!1}}),we=l.isError&&W.length===0,Te=l.isSuccess&&W.length===0,Ee=new Map(oe.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:me,className:he(`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,we?(0,$.jsxs)(`div`,{ref:q,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)(Qe,{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)(J,{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:i(`assistants.contact.loadFailed`)}),(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void l.refetch(),children:i(`chat.history.retry`)})]}):Te?(0,$.jsxs)(`div`,{ref:q,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)(Qe,{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:i(`assistants.conversation.emptyTitle`,{name:m})}),(0,$.jsx)(`p`,{className:`mt-2 max-w-xs typography-ui leading-6 text-muted-foreground/80`,children:i(`assistants.contact.empty`)})]}):(0,$.jsxs)(`div`,{ref:q,className:`mx-auto flex w-full max-w-[42rem] flex-col`,children:[l.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-3 text-center typography-micro text-muted-foreground`,children:i(`common.loading`)}):null,l.hasPreviousPage||l.hasMessageGap?(0,$.jsxs)(`div`,{className:`mb-3 flex flex-col items-center gap-1`,"data-assistant-contact-pagination":``,"aria-busy":l.isFetchingPreviousPage||l.isFillingMessageGap,children:[l.previousPageError?(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:i(`chat.history.loadOlderFailed`)}):null,l.hasMessageGap?(0,$.jsx)(`p`,{role:`status`,className:`typography-micro text-muted-foreground`,children:i(`assistants.contact.history.gap`)}):null,(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,disabled:l.isFetchingPreviousPage||l.isFillingMessageGap,onClick:()=>void pe(),children:i(l.isFetchingPreviousPage||l.isFillingMessageGap?`chat.history.loadingMore`:l.previousPageError||l.hasMessageGap?`chat.history.retry`:`chat.history.loadOlder`)})]}):null,W.map((t,n)=>{let r=n>0?W[n-1]:null,o=t.role===`user`,s=t.role===`peer`,l=t.role===`assistant`&&r?.role===`assistant`&&r.turnID===t.turnID,u=r?.turnID!==t.turnID,d=!o&&(s||!l),p=s?h(t.fromAssistantID,t.fromAssistantName):m,g=s&&t.fromAssistantID?c.data?.assistants.find(e=>e.id===t.fromAssistantID):e,_=g?A(g.name):null,v=Ee.get(t.messageID),y=de.get(t.turnID),b=t.status===`admitted`&&t.messageID.endsWith(`:preview:admitted`),x=t.status===`failed`&&t.messageID.endsWith(`:preview:failed`);return(0,$.jsxs)(`div`,{"data-message-id":t.messageID,className:he(`flex w-full`,o?`justify-end`:`justify-start`,u?`mt-6 first:mt-0`:l?`mt-1.5`:`mt-3`),"data-assistant-contact-role":t.role,"data-assistant-contact-turn-status":v?.status??t.status,"data-assistant-contact-run-start":t.role===`assistant`&&!l?``:void 0,children:[o?null:(0,$.jsx)(`div`,{className:`mr-2.5 flex w-8 shrink-0 justify-center pt-0.5`,children:d?(0,$.jsx)(Qe,{name:g?.id||t.fromAssistantID||e.id,emoji:_?.avatarEmoji,size:28,label:p}):(0,$.jsx)(`span`,{className:`size-7`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:he(`flex min-w-0 flex-col gap-1.5`,o?`max-w-[min(82%,30rem)] items-end`:`max-w-[min(84%,34rem)] items-start`),children:[s?(0,$.jsx)(`span`,{className:`mb-0.5 px-1 typography-micro text-muted-foreground/75`,children:i(`assistants.contact.peer.from`,{name:p})}):null,b?(0,$.jsxs)(`div`,{role:`status`,"aria-label":i(`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)(Zt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`assistant`)return(0,$.jsx)(Wt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`schedule`)return(0,$.jsx)(Gt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`file`)return(0,$.jsx)(_t,{assistantID:e.id,part:n},`${t.messageID}:file:${r}`);if(n.type===`text`&&pn(n.text))return null;if(n.type===`text`&&(n.text.trim()||t.status===`streaming`)){let e=!o;return(0,$.jsxs)(`div`,{"aria-label":s?i(`assistants.contact.peer.aria`,{name:p}):void 0,"data-assistant-contact-text":``,className:he(`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`,o?`rounded-[1.15rem] rounded-br-lg bg-[var(--primary-base)]/90 text-[var(--primary-foreground)]`:s?`rounded-[1.25rem] border border-dashed border-border/50 bg-[var(--surface-muted)]/70 text-foreground`:he(`bg-[var(--surface-muted)] text-foreground`,l&&`rounded-tl-lg`)),children:[e?(0,$.jsx)(ye,{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}),v?.status===`sending`?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-muted-foreground/75`,children:i(`assistants.contact.sending`)}):null,v?.status===`failed`?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-[var(--status-error)]`,children:v.error||i(`assistants.contact.sendFailed`)}):null,x?(0,$.jsx)(`p`,{className:`px-1 typography-micro text-[var(--status-error)]`,children:y?.error||i(`assistants.contact.sendFailed`)}):null,f?.messageID===t.messageID?(0,$.jsx)(nt,{assistantID:e.id,position:f},`${a}:${e.id}:${f.generation}:${f.ordinal}`):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}),x.current?(0,$.jsx)(Y,{type:`button`,size:`sm`,variant:`ghost`,disabled:G,onClick:()=>void Se(),children:i(`chat.history.retry`)}):null]}):null,(0,$.jsx)(`form`,{className:he(`relative w-full pt-1.5 pb-4`,o&&`bottom-safe-area oc-mobile-composer`),onSubmit:e=>{e.preventDefault(),Se()},onDragOver:Z,onDrop:be,children:(0,$.jsx)(`div`,{className:`chat-input-column relative overflow-visible`,children:(0,$.jsx)(dt,{active:n,layout:`inline`,value:g,attachments:v,pending:G,working:ce||le,onStop:ce||le?()=>{Ce()}:void 0,stopLabel:i(`chat.chatInput.actions.stopGeneratingAria`),isMobile:o,placeholder:i(`assistants.contact.placeholder`,{name:m}),sendLabel:i(`assistants.contact.send`),addFilesLabel:i(`assistants.contact.addFiles`),removeAttachmentLabel:i(`assistants.contact.removeAttachment`),fileAccept:`*/*`,onChange:e=>_(e),onSubmit:()=>{Se()},onAddFiles:e=>{X(e)},onRemoveAttachment:t=>{G||(S.current.delete(`${e.id}:${t}`),x.current=null,b(e=>e.filter(e=>e.id!==t)))},onPaste:ve,onDragOver:Z,onDrop:be,className:he(`relative z-10`,o&&`oc-mobile-composer-surface`),style:{borderRadius:`1.5rem`},"data-assistant-contact-composer-surface":``,textareaProps:{"aria-label":i(`assistants.contact.placeholder`,{name:m})}},`${a}:${e.id}`)})})]})]})};async function hn(e){await P(e);let t=G.getState().defaultShareAssistant;if(t?.assistantID!==e.id)return;let n=await H();n.serverInstanceID&&t.serverInstanceID===n.serverInstanceID&&G.getState().setDefaultShareAssistant(null)}function gn({assistant:e,open:t,onOpenChange:n,onDeleted:r}){let{t:i}=k(),[a,o]=Q.useState(!1),s=e?A(e.name).displayName||e.name:``,c=E(e=>{a&&!e||n(e)}),l=E(()=>{a||n(!1)}),u=E(async()=>{if(!(!e||a)){o(!0);try{await hn(e),r?.(e.id),n(!1),S.success(i(`assistants.settings.toast.deleted`))}catch{S.error(i(`assistants.settings.toast.deleteFailed`))}finally{o(!1)}}});return(0,$.jsx)(me,{open:t&&e!==null,onOpenChange:c,children:(0,$.jsxs)(de,{className:`max-w-md`,children:[(0,$.jsxs)(ue,{children:[(0,$.jsx)(fe,{children:i(`assistants.settings.delete`)}),(0,$.jsx)(pe,{children:i(`assistants.settings.deleteConfirm`,{name:s})})]}),(0,$.jsxs)(K,{children:[(0,$.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:l,disabled:a,children:i(`settings.common.actions.cancel`)}),(0,$.jsx)(Y,{size:`sm`,variant:`destructive`,onClick:u,disabled:a,children:i(`settings.common.actions.delete`)})]})]})})}var _n=`line-clamp-2 min-w-0 max-w-full overflow-clip whitespace-normal [overflow-wrap:anywhere] typography-micro text-muted-foreground`,vn={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 yn(e,t){return e?.text.replace(/\s+/gu,` `).trim()||t(e?.fallbackKind?vn[e.fallbackKind]:`assistants.contact.empty`)}var bn=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`,xn=t({AssistantView:()=>wn}),Sn=e=>{let t=(0,Ye.c)(21),{assistant:n,onBack:r}=e,{t:i}=k(),a=Ce(),o;t[0]===n?o=t[1]:(o=n?A(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&&le(n.id,a?{openMobileSettings:a.openSettings}:void 0)},t[2]=n,t[3]=a,t[4]=l):l=t[4];let u=E(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)(Qe,{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 f;t[10]===i?f=t[11]:(f=i(`assistants.actions.backToChat`),t[10]=i,t[11]=f);let p;t[12]!==n||t[13]!==u||t[14]!==i?(p=n?[{icon:`settings-3`,ariaLabel:i(`assistants.conversation.openSettings`),onClick:u}]:[],t[12]=n,t[13]=u,t[14]=i,t[15]=p):p=t[15];let m;return t[16]!==r||t[17]!==d||t[18]!==f||t[19]!==p?(m=(0,$.jsx)(ee,{title:d,backAriaLabel:f,onBack:r,actions:p,overlay:!0}),t[16]=r,t[17]=d,t[18]=f,t[19]=p,t[20]=m):m=t[20],m},Cn=e=>{let t=(0,Ye.c)(50),{unreadCount:n,summary:r,assistantID:i,displayName:a,avatarEmoji:o,selected:s,enabled:c,editLabel:l,deleteLabel:u,onSelect:d,onEdit:f,onDelete:p,serverWorking:m}=e,h=tt(i,m!==void 0&&m),[g,_]=Q.useState(!1),v;t[0]===d?v=t[1]:(v=()=>d(),t[0]=d,t[1]=v);let y=E(v),b;t[2]===f?b=t[3]:(b=()=>{_(!1),f()},t[2]=f,t[3]=b);let x=E(b),S;t[4]===p?S=t[5]:(S=()=>{_(!1),p()},t[4]=p,t[5]=S);let C=E(S),w;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(w=e=>{e.preventDefault(),_(!0)},t[6]=w):w=t[6];let T=s?`border-border/50 bg-[var(--surface-elevated)]`:`border-transparent hover:bg-interactive-hover`,D=!c&&`opacity-65`,O;t[7]!==T||t[8]!==D?(O=he(`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`,T,D),t[7]=T,t[8]=D,t[9]=O):O=t[9];let k;t[10]!==y||t[11]!==s||t[12]!==O?(k=(0,$.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":s,onClick:y,onContextMenu:w,className:O}),t[10]=y,t[11]=s,t[12]=O,t[13]=k):k=t[13];let A;t[14]!==i||t[15]!==o||t[16]!==a||t[17]!==h?(A=(0,$.jsx)(Qe,{name:i,emoji:o,size:24,label:a,working:h}),t[14]=i,t[15]=o,t[16]=a,t[17]=h,t[18]=A):A=t[18];let j;t[19]===a?j=t[20]:(j=(0,$.jsx)(`span`,{className:`block truncate typography-ui-label font-medium`,children:a}),t[19]=a,t[20]=j);let M;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(M=he(_n,`mt-1.5`),t[21]=M):M=t[21];let N;t[22]===r?N=t[23]:(N=(0,$.jsx)(`span`,{className:M,children:r}),t[22]=r,t[23]=N);let P;t[24]!==j||t[25]!==N?(P=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[j,N]}),t[24]=j,t[25]=N,t[26]=P):P=t[26];let F;t[27]===n?F=t[28]:(F=(0,$.jsx)(ze,{count:n}),t[27]=n,t[28]=F);let I;t[29]!==A||t[30]!==P||t[31]!==F||t[32]!==k?(I=(0,$.jsxs)(Ve,{render:k,children:[A,P,F]}),t[29]=A,t[30]=P,t[31]=F,t[32]=k,t[33]=I):I=t[33];let L;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(J,{name:`edit`,className:`size-4`}),t[34]=L):L=t[34];let R;t[35]!==l||t[36]!==x?(R=(0,$.jsxs)(We,{onClick:x,children:[L,l]}),t[35]=l,t[36]=x,t[37]=R):R=t[37];let z;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(He,{}),t[38]=z):z=t[38];let B;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(J,{name:`delete-bin`,className:`size-4`}),t[39]=B):B=t[39];let V;t[40]!==u||t[41]!==C?(V=(0,$.jsxs)(We,{onClick:C,className:`text-[var(--status-error)] focus:text-[var(--status-error)] data-[highlighted]:text-[var(--status-error)] [&_svg]:text-[var(--status-error)]`,children:[B,u]}),t[40]=u,t[41]=C,t[42]=V):V=t[42];let H;t[43]!==R||t[44]!==V?(H=(0,$.jsxs)(Ue,{className:`min-w-[10rem]`,children:[R,z,V]}),t[43]=R,t[44]=V,t[45]=H):H=t[45];let ee;return t[46]!==g||t[47]!==I||t[48]!==H?(ee=(0,$.jsxs)(Ge,{open:g,onOpenChange:_,children:[I,H]}),t[46]=g,t[47]=I,t[48]=H,t[49]=ee):ee=t[49],ee},wn=e=>{let t=(0,Ye.c)(115),{activeOverride:i,onMobileBack:a}=e,{t:o}=k(),{isMobile:s}=ge(),c=Ce(),l=Q.useSyncExternalStore(n,r,r),u=y(Tn),d=i??u,f=y(En),p=s||f,m=I(),h=U(),g=h.data;g?.assistants;let _;t[0]===g?.assistants?_=t[1]:(_=g?.assistants??[],t[0]=g?.assistants,t[1]=_);let v;t[2]===_?v=t[3]:(v=Xe(_),t[2]=_,t[3]=v);let b=v,x;t[4]===l?x=t[5]:(x=e=>e.assistantByTransport[l]??null,t[4]=l,t[5]=x);let S=G(x),C=G(Dn),w=G(On),T;t[6]!==S||t[7]!==g?.assistants?(T=g?.assistants.find(e=>e.id===S)??null,t[6]=S,t[7]=g?.assistants,t[8]=T):T=t[8];let D=T,O;t[9]!==C||t[10]!==S||t[11]!==g?(O=()=>{!S&&g?.assistants[0]&&C(g.assistants[0].id)},t[9]=C,t[10]=S,t[11]=g,t[12]=O):O=t[12];let j=g?.assistants,M;t[13]!==C||t[14]!==S||t[15]!==j?(M=[C,S,j],t[13]=C,t[14]=S,t[15]=j,t[16]=M):M=t[16],Q.useEffect(O,M);let N;t[17]!==D||t[18]!==C||t[19]!==S||t[20]!==g?.assistants||t[21]!==h.isSuccess?(N=()=>{h.isSuccess&&S&&!D&&C(g?.assistants[0]?.id??null)},t[17]=D,t[18]=C,t[19]=S,t[20]=g?.assistants,t[21]=h.isSuccess,t[22]=N):N=t[22];let P=g?.assistants,F;t[23]!==D||t[24]!==C||t[25]!==S||t[26]!==h.isSuccess||t[27]!==P?(F=[D,C,S,P,h.isSuccess],t[23]=D,t[24]=C,t[25]=S,t[26]=h.isSuccess,t[27]=P,t[28]=F):F=t[28],Q.useEffect(N,F);let L;t[29]!==c||t[30]!==w?(L=()=>{if(w(),c){c.openSettings();return}let e=y.getState();e.setSettingsPage(`assistants`),e.setSettingsDialogOpen(!0)},t[29]=c,t[30]=w,t[31]=L):L=t[31];let R=E(L),z;t[32]===c?z=t[33]:(z=e=>{le(e,c?{openMobileSettings:c.openSettings}:void 0)},t[32]=c,t[33]=z);let B=E(z),V;t[34]!==D||t[35]!==c?(V=()=>{D&&le(D.id,c?{openMobileSettings:c.openSettings}:void 0)},t[34]=D,t[35]=c,t[36]=V):V=t[36];let H=E(V),[ee,te]=Q.useState(null),ne;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>{te(e)},t[37]=ne):ne=t[37];let re=E(ne),ie;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>{e||te(null)},t[38]=ie):ie=t[38];let ae=E(ie),oe=E(kn),se;t[39]!==a||t[40]!==oe?(se=()=>{if(a){a();return}oe()},t[39]=a,t[40]=oe,t[41]=se):se=t[41];let W=E(se),ce=bn({capabilityPending:m.isPending,snapshotPending:h.isPending,capabilityError:m.isError,supported:m.data?.supported,capabilityEnabled:m.data?.enabled,snapshotEnabled:g?.enabled,snapshotSettled:h.isSuccess,assistantCount:g?.assistants.length??0,hasAssistant:!!D}),ue;t[42]!==D||t[43]!==W||t[44]!==p?(ue=(e,t,n,r)=>(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[p?(0,$.jsx)(Sn,{assistant:D,onBack:W}):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)(J,{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[42]=D,t[43]=W,t[44]=p,t[45]=ue):ue=t[45];let K=ue;if(ce===`loading`){let e;t[46]!==D||t[47]!==W||t[48]!==p?(e=p?(0,$.jsx)(Sn,{assistant:D,onBack:W}):null,t[46]=D,t[47]=W,t[48]=p,t[49]=e):e=t[49];let n;t[50]===o?n=t[51]:(n=o(`common.loading`),t[50]=o,t[51]=n);let r;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(J,{name:`loader-4`,className:`size-6 animate-spin text-muted-foreground`}),t[52]=r):r=t[52];let i;t[53]===n?i=t[54]:(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[53]=n,t[54]=i);let a;return t[55]!==e||t[56]!==i?(a=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[e,i]}),t[55]=e,t[56]=i,t[57]=a):a=t[57],a}if(ce===`unavailable`){let e;return t[58]!==K||t[59]!==o?(e=K(`cloud-off`,o(`assistants.state.unavailable`)),t[58]=K,t[59]=o,t[60]=e):e=t[60],e}if(ce===`onboarding`){let e;if(t[61]!==R||t[62]!==K||t[63]!==o){let n=o(`assistants.onboarding.title`),r=o(`assistants.onboarding.description`),i;t[65]===o?i=t[66]:(i=o(`assistants.onboarding.action`),t[65]=o,t[66]=i);let a;t[67]!==R||t[68]!==i?(a=(0,$.jsx)(Y,{onClick:R,children:i}),t[67]=R,t[68]=i,t[69]=a):a=t[69],e=K(`ai-agent`,n,r,a),t[61]=R,t[62]=K,t[63]=o,t[64]=e}else e=t[64];return e}if(!g||!D){let e;return t[70]!==K||t[71]!==o?(e=K(`cloud-off`,o(`assistants.state.unavailable`)),t[70]=K,t[71]=o,t[72]=e):e=t[72],e}let de;t[73]===D.name?de=t[74]:(de=A(D.name),t[73]=D.name,t[74]=de);let fe=de,pe;t[75]!==D.enabled||t[76]!==h.isError||t[77]!==o?(pe=D.enabled?h.isError?o(`assistants.state.staleSnapshot`):null:o(`assistants.state.assistantDisabled`),t[75]=D.enabled,t[76]=h.isError,t[77]=o,t[78]=pe):pe=t[78];let me=pe,q;t[79]!==b||t[80]!==p||t[81]!==R||t[82]!==B||t[83]!==re||t[84]!==C||t[85]!==S||t[86]!==g||t[87]!==o?(q=p?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)(Y,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":o(`assistants.settings.create`),onClick:R,children:(0,$.jsx)(J,{name:`add`,className:`size-4`})})]}),(0,$.jsx)(`div`,{className:`flex justify-end px-4 pb-2 sm:px-5`,children:(0,$.jsx)(Ze,{snapshot:g})}),(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.map(e=>{let t=e.id===S,n=A(e.name);return(0,$.jsx)(Cn,{assistantID:e.id,unreadCount:e.unreadCount??0,summary:yn(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:()=>C(e.id),onEdit:()=>B(e.id),onDelete:()=>re(e)},e.id)})})})]}),t[79]=b,t[80]=p,t[81]=R,t[82]=B,t[83]=re,t[84]=C,t[85]=S,t[86]=g,t[87]=o,t[88]=q):q=t[88];let _e=ee!==null,X;t[89]!==ee||t[90]!==ae||t[91]!==_e?(X=(0,$.jsx)(gn,{assistant:ee,open:_e,onOpenChange:ae}),t[89]=ee,t[90]=ae,t[91]=_e,t[92]=X):X=t[92];let ve=!p&&`border-l border-[var(--surface-subtle)]`,Z;t[93]===ve?Z=t[94]:(Z=he(`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-background`,ve),t[93]=ve,t[94]=Z);let ye;t[95]!==D||t[96]!==W||t[97]!==p||t[98]!==H||t[99]!==fe||t[100]!==o?(ye=p?(0,$.jsx)(Sn,{assistant:D,onBack:W}):(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)(Qe,{name:D.id,emoji:fe.avatarEmoji,size:30,label:fe.displayName||D.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:fe.displayName}),(0,$.jsx)(`div`,{className:`mt-1 truncate typography-micro leading-none text-muted-foreground/55`,children:o(`assistants.conversation.contactHint`)})]}),(0,$.jsx)(Y,{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)(J,{name:`settings-3`,className:`size-4`})})]}),t[95]=D,t[96]=W,t[97]=p,t[98]=H,t[99]=fe,t[100]=o,t[101]=ye):ye=t[101];let be;t[102]!==d||t[103]!==D||t[104]!==p||t[105]!==me?(be=(0,$.jsx)(mn,{assistant:D,warning:me,active:d,overlayHeader:p}),t[102]=d,t[103]=D,t[104]=p,t[105]=me,t[106]=be):be=t[106];let xe;t[107]!==Z||t[108]!==ye||t[109]!==be?(xe=(0,$.jsxs)(`div`,{className:Z,children:[ye,be]}),t[107]=Z,t[108]=ye,t[109]=be,t[110]=xe):xe=t[110];let Se;return t[111]!==q||t[112]!==X||t[113]!==xe?(Se=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden bg-background`,"data-presentation":`workspace`,children:[q,X,xe]}),t[111]=q,t[112]=X,t[113]=xe,t[114]=Se):Se=t[114],Se};function Tn(e){return e.activeMainTab===`assistant`}function En(e){return e.isMobile}function Dn(e){return e.selectAssistant}function On(e){return e.requestCreate}function kn(){y.getState().setActiveMainTab(`chat`)}export{gn as a,Ze as c,yn as i,Xe as l,xn as n,tt as o,_n as r,Qe as s,wn as t};
|