@openchambery/web 2.0.0-beta.9 → 2.0.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/README.md +14 -0
- package/dist/assets/{AgentAvatar-CzTtVMnI.js → AgentAvatar-DGyF86jy.js} +1 -1
- package/dist/assets/AssistantView-ByGdaGiF.js +3 -0
- package/dist/assets/{DiagramView-oeXj4YHn.js → DiagramView-PB0pBILb.js} +1 -1
- package/dist/assets/{FadeInOnReveal-DCqrQkkz.js → FadeInOnReveal-B_a083XJ.js} +1 -1
- package/dist/assets/Icon-BE2hkaYc.js +1 -0
- package/dist/assets/MarkdownRenderer-H1MIHXzt.js +2 -0
- package/dist/assets/{MarkdownRendererImpl-CahUctxC.js → MarkdownRendererImpl-CZ8GeckU.js} +3 -3
- package/dist/assets/{MarkstreamRendererImpl-5JUaTSdl.js → MarkstreamRendererImpl-BKE6YZ2N.js} +1 -1
- package/dist/assets/MobileDetailNavigation-D9KkIrWy.js +1 -0
- package/dist/assets/{MobileShareBridge-yCN95dYg.js → MobileShareBridge-1yCjq-60.js} +3 -3
- package/dist/assets/MobileSurface-Dqn3OPVX.js +2 -0
- package/dist/assets/{MultiRunWindow-C0HqMFpp.js → MultiRunWindow-YCFM6or1.js} +1 -1
- package/dist/assets/{OnboardingScreen-O4cGdz5p.js → OnboardingScreen-CTmsNR65.js} +1 -1
- package/dist/assets/{OverlayScrollbar-CRfGtcmG.js → OverlayScrollbar-CVgW_Z9B.js} +1 -1
- package/dist/assets/SettingsView-CbiuXtYG.js +25 -0
- package/dist/assets/{SettingsWindow-B_d5Aqq3.js → SettingsWindow-jOZ7L6K8.js} +1 -1
- package/dist/assets/{TerminalView-DdNQQb8W.js → TerminalView-CI-KsDdH.js} +1 -1
- package/dist/assets/{ToolOutputDialog-4DC5OE1J.js → ToolOutputDialog-izZjgkkg.js} +1 -1
- package/dist/assets/appThemeRegistry-MiWlVk4e.js +1 -0
- package/dist/assets/{assistant-attachment-cache-DphJleHr.js → assistant-attachment-cache-sG8YQsVs.js} +1 -1
- package/dist/assets/{button-DIIrsMjW.js → button-CcOoDLE1.js} +1 -1
- package/dist/assets/{collapsible-CnvUeYst.js → collapsible-CSa0Ndgm.js} +1 -1
- package/dist/assets/{context-menu-BGBUpZEQ.js → context-menu-DoTwmMb5.js} +1 -1
- package/dist/assets/{desktopHosts-JGFqhlaM.js → desktopHosts-BsbquPqS.js} +1 -1
- package/dist/assets/desktopRelayRestore-yyvjztgj.js +1 -0
- package/dist/assets/{diagram-rvn7_qBM.js → diagram-CZKDkADZ.js} +1 -1
- package/dist/assets/dialog-Csvrld51.js +1 -0
- package/dist/assets/dropdown-menu.styles-ayLWk2gf.js +1 -0
- package/dist/assets/{es-Dsmc0A_3.js → es-BBbon7SL.js} +4 -4
- package/dist/assets/fileMentionTouchSelection-Bn0f83D3.js +2 -0
- package/dist/assets/{fileQueries-DN6gbLhM.js → fileQueries-B0hhXD86.js} +1 -1
- package/dist/assets/{fr-C_ZlZDI2.js → fr-BsKj2CTi.js} +4 -4
- package/dist/assets/{gitApi-da8etTTe.js → gitApi-DpwH7xTg.js} +4 -4
- package/dist/assets/{imageSource-BMztRu0c.js → imageSource-BpUsiwFd.js} +1 -1
- package/dist/assets/{input-BVu-iykl.js → input-C6Y7mytw.js} +1 -1
- package/dist/assets/insertionBoundaries-Cst5Z6Cd.js +1 -0
- package/dist/assets/{ja-BqqTaWTi.js → ja-1mgxunoM.js} +4 -4
- package/dist/assets/{ko-DP2XPM37.js → ko-Ra9znPcL.js} +4 -4
- package/dist/assets/{main-KwlAomA8.js → main-CEs8ipuu.js} +2 -2
- package/dist/assets/main-Dkzuy7EG.js +169 -0
- package/dist/assets/main-qSeeJRW1.css +1 -0
- package/dist/assets/{markdownHeightCache-D9-B1wdY.js → markdownHeightCache-DhLhFBWX.js} +1 -1
- package/dist/assets/{mcpQueries-3GTWeMU-.js → mcpQueries-BBpCJgvK.js} +1 -1
- package/dist/assets/miniChat-CR7k42bZ.js +2 -0
- package/dist/assets/mobile-rvypjUpd.js +2 -0
- package/dist/assets/multirun-DqmJk0mh.js +3 -0
- package/dist/assets/persistence-CwHY3fDg.js +3 -0
- package/dist/assets/pl-B714sdql.js +15 -0
- package/dist/assets/platform-Bxaalnc8.js +6 -0
- package/dist/assets/projectMeta-BhKfv5cj.js +1 -0
- package/dist/assets/{pt-BR-W09Q2pvn.js → pt-BR-DVoT_I7_.js} +4 -4
- package/dist/assets/{relay-image-stream-DrdVj99c.js → relay-image-stream-D2XooXKZ.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-BLay6f9j.js +2 -0
- package/dist/assets/renderMobileApp-BrikirqO.js +28 -0
- package/dist/assets/{runtime-fetch-Fs9ZV2V8.js → runtime-fetch-CiqQd__Y.js} +1 -1
- package/dist/assets/runtime-switch-BJM2k_uH.js +1 -0
- package/dist/assets/runtimeConfig-DjKsteH0.js +2 -0
- package/dist/assets/runtimeEndpointReset-D_vfNOQz.css +1 -0
- package/dist/assets/runtimeEndpointReset-DbfaE3dL.js +148 -0
- package/dist/assets/sessionChangeSummary-Cgq9RPUq.js +2 -0
- package/dist/assets/{sessionLookup-0Z4e-J1g.js → sessionLookup-BiE36BTy.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-CE7W7lJ9.js → sortable-tabs-strip-CKKp4p3Y.js} +1 -1
- package/dist/assets/src-BZ0tISrf.css +2 -0
- package/dist/assets/{store-jaP79mqI.js → store-l_X_jQNz.js} +4 -4
- package/dist/assets/{terminalApi-mDR2jXTo.js → terminalApi-DSJOXNRQ.js} +1 -1
- package/dist/assets/{textarea-XD2oX_Ee.js → textarea-DUjc3iDJ.js} +1 -1
- package/dist/assets/{tooltip-DYeQ_Hvy.js → tooltip-CBHR50fA.js} +1 -1
- package/dist/assets/{uk-BgFzz8m2.js → uk-ChNnTgKP.js} +4 -4
- package/dist/assets/{url-CGbJbiJq.js → url-CEnO45_n.js} +1 -1
- package/dist/assets/{useAppFontEffects-y_GTVXhJ.js → useAppFontEffects-CWzjhjXr.js} +55 -55
- package/dist/assets/{useAssistantUIStore-Bz4tRflF.js → useAssistantUIStore-CXj8c_tt.js} +1 -1
- package/dist/assets/useDesktopWindowControlsLayout-Dtqco-Um.js +1 -0
- package/dist/assets/{useEffectiveDirectory-BW9jNyuK.js → useEffectiveDirectory-DNbDaaNV.js} +1 -1
- package/dist/assets/{useFontPreferences-Bjx8zkGM.js → useFontPreferences-DGbTdGy3.js} +1 -1
- package/dist/assets/useMobileNavigationStore-DYKC2swj.js +415 -0
- package/dist/assets/useSessionAutoCleanup-BI0xQcio.js +2 -0
- package/dist/assets/{useUIStore-syVmbuDA.js → useUIStore-DNkuudYO.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-BUcSLKlL.js → useWorkerHighlightedLines-BoyYALWC.js} +1 -1
- package/dist/assets/vendor-opencode-client-MF2GBrFx.js +12 -0
- package/dist/assets/{vendor-zustand-B4dlGEM2.js → vendor-zustand-DzRqcymP.js} +1 -1
- package/dist/assets/{zh-CN-BhqSLgUY.js → zh-CN-DHEFf4u1.js} +4 -4
- package/dist/assets/{zh-TW-BsaBgY-p.js → zh-TW-rdSa8atW.js} +4 -4
- package/dist/index.html +13 -13
- package/dist/mini-chat.html +13 -13
- package/dist/mobile.html +13 -13
- package/package.json +3 -3
- package/server/index.js +8 -20
- package/server/lib/client-auth/remote-clients.js +15 -0
- package/server/lib/client-auth/remote-clients.test.js +42 -1
- package/server/lib/git/DOCUMENTATION.md +1 -0
- package/server/lib/git/routes.js +7 -4
- package/server/lib/git/routes.test.js +34 -0
- package/server/lib/git/service.js +3 -1
- package/server/lib/llm/DOCUMENTATION.md +6 -4
- package/server/lib/llm/generate.js +8 -9
- package/server/lib/llm/generate.test.js +33 -6
- package/server/lib/message-queue/service.js +1 -1
- package/server/lib/opencode/DOCUMENTATION.md +33 -22
- package/server/lib/opencode/agents.js +13 -22
- package/server/lib/opencode/auth-state-runtime.js +3 -3
- package/server/lib/opencode/auth-state-runtime.test.js +59 -0
- package/server/lib/opencode/auth.d.ts +13 -0
- package/server/lib/opencode/auth.js +74 -64
- package/server/lib/opencode/auth.test.js +57 -0
- package/server/lib/opencode/commands.js +1 -1
- package/server/lib/opencode/config-entities-layering.test.js +72 -0
- package/server/lib/opencode/config-entity-routes.js +10 -123
- package/server/lib/opencode/config-entity-routes.test.js +23 -11
- package/server/lib/opencode/config-files.d.ts +17 -0
- package/server/lib/opencode/config-files.js +187 -0
- package/server/lib/opencode/config-files.test.js +201 -0
- package/server/lib/opencode/core-routes.js +17 -1
- package/server/lib/opencode/core-routes.test.js +43 -15
- package/server/lib/opencode/credential-boundary.d.ts +1 -0
- package/server/lib/opencode/credential-boundary.js +11 -0
- package/server/lib/opencode/ensure-cli.js +4 -1
- package/server/lib/opencode/env-config.js +4 -1
- package/server/lib/opencode/env-config.test.js +28 -0
- package/server/lib/opencode/env-runtime.test.js +18 -1
- package/server/lib/opencode/feature-routes-runtime.js +9 -7
- package/server/lib/opencode/hmr-state-runtime.js +4 -4
- package/server/lib/opencode/lifecycle.js +1 -49
- package/server/lib/opencode/lifecycle.test.js +30 -4
- package/server/lib/opencode/location-release.d.ts +8 -0
- package/server/lib/opencode/location-release.js +32 -0
- package/server/lib/opencode/location-release.test.js +43 -0
- package/server/lib/opencode/mcp.js +1 -1
- package/server/lib/opencode/opencode2-pin.js +2 -1
- package/server/lib/opencode/owned-runtime-upgrade.test.js +5 -5
- package/server/lib/opencode/plugin-routes.test.js +4 -2
- package/server/lib/opencode/plugins.js +12 -60
- package/server/lib/opencode/plugins.test.js +5 -3
- package/server/lib/opencode/providers.js +6 -3
- package/server/lib/opencode/proxy.js +7 -0
- package/server/lib/opencode/proxy.test.js +13 -0
- package/server/lib/opencode/remote-upgrade.integration.test.js +66 -0
- package/server/lib/opencode/routes.js +10 -8
- package/server/lib/opencode/routes.test.js +51 -10
- package/server/lib/opencode/runtime-contract.js +3 -2
- package/server/lib/opencode/runtime-contract.test.js +12 -12
- package/server/lib/opencode/settings-normalization-runtime.js +3 -1
- package/server/lib/opencode/settings-normalization-runtime.test.js +36 -0
- package/server/lib/opencode/settings-runtime.test.js +58 -1
- package/server/lib/opencode/shared.js +6 -175
- package/server/lib/opencode/update-discovery.js +39 -0
- package/server/lib/opencode/update-discovery.test.js +39 -0
- package/server/lib/opencode/upgrade-screen.js +4 -11
- package/server/lib/opencode/upgrade-screen.test.js +25 -25
- package/server/lib/opencode/version-alignment.test.js +40 -0
- package/server/lib/question-auto-delegate/DOCUMENTATION.md +21 -6
- package/server/lib/question-auto-delegate/core.d.ts +5 -1
- package/server/lib/question-auto-delegate/core.js +21 -13
- package/server/lib/question-auto-delegate/form-io.d.ts +6 -0
- package/server/lib/question-auto-delegate/form-io.js +39 -0
- package/server/lib/question-auto-delegate/runtime.js +4 -24
- package/server/lib/question-auto-delegate/runtime.test.js +138 -0
- package/server/lib/quota/DOCUMENTATION.md +9 -0
- package/server/lib/quota/provider-credentials.test.js +29 -0
- package/server/lib/quota/providers/claude.js +4 -4
- package/server/lib/quota/providers/codex.js +4 -4
- package/server/lib/quota/providers/codex.test.js +1 -1
- package/server/lib/quota/providers/copilot.js +5 -5
- package/server/lib/quota/providers/google/auth.js +3 -3
- package/server/lib/quota/providers/google/index.js +2 -2
- package/server/lib/quota/providers/index.js +3 -7
- package/server/lib/quota/providers/index.test.js +2 -2
- package/server/lib/quota/providers/kimi.js +4 -4
- package/server/lib/quota/providers/minimax-shared.js +4 -4
- package/server/lib/quota/providers/nanogpt.js +4 -4
- package/server/lib/quota/providers/openai.js +4 -4
- package/server/lib/quota/providers/openrouter.js +4 -4
- package/server/lib/quota/providers/wafer.js +4 -4
- package/server/lib/quota/providers/zai.js +4 -4
- package/server/lib/quota/providers/zhipuai-coding-plan.js +6 -20
- package/server/lib/quota/routes.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +3 -1
- package/server/lib/relay/service.js +1 -0
- package/server/lib/relay/service.test.js +13 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +8 -1
- package/server/lib/scheduled-tasks/runtime.js +12 -4
- package/server/lib/scheduled-tasks/runtime.test.js +81 -6
- package/server/lib/session-goal/DOCUMENTATION.md +11 -0
- package/server/lib/session-goal/runtime.js +4 -4
- package/server/lib/session-goal/runtime.test.js +32 -3
- package/server/lib/session-index/DOCUMENTATION.md +7 -0
- package/server/lib/session-index/event-ingest.js +13 -0
- package/server/lib/session-index/event-ingest.test.js +7 -0
- package/server/lib/session-index/service.js +45 -0
- package/server/lib/session-index/service.test.js +47 -0
- package/server/lib/session-metadata/DOCUMENTATION.md +6 -0
- package/server/lib/session-metadata/session-metadata-store.test.js +23 -0
- package/server/lib/session-metadata/session-projection.d.ts +1 -0
- package/server/lib/session-metadata/session-projection.js +23 -0
- package/server/lib/session-metadata/session-projection.test.js +35 -0
- package/server/lib/session-title/DOCUMENTATION.md +52 -14
- package/server/lib/session-title/native-runtime.test.js +59 -5
- package/server/lib/session-title/runtime.js +63 -17
- package/server/lib/session-title/session-access.js +108 -3
- package/server/lib/session-title/session-access.test.js +125 -7
- package/server/lib/tts/DOCUMENTATION.md +7 -5
- package/server/lib/tts/credential-source.test.js +23 -0
- package/server/lib/tts/routes.js +2 -2
- package/server/lib/tts/service.js +16 -37
- package/dist/assets/AssistantView-CLFPj5Ki.js +0 -3
- package/dist/assets/Icon-B8fSTLdP.js +0 -1
- package/dist/assets/MarkdownRenderer-BK69MEHQ.js +0 -2
- package/dist/assets/MobileDetailNavigation-agQ-Yhpd.js +0 -1
- package/dist/assets/MobileSurface-D0HP_lTS.js +0 -2
- package/dist/assets/SettingsView-xLYb22wV.js +0 -25
- package/dist/assets/appThemeRegistry-LkVH62uF.js +0 -1
- package/dist/assets/desktopRelayRestore-CHEwrI93.js +0 -1
- package/dist/assets/dialog-CQ63sc9E.js +0 -1
- package/dist/assets/dropdown-menu.styles-Bzo6L3FH.js +0 -1
- package/dist/assets/fileMentionTouchSelection-CBzDuQxP.js +0 -3
- package/dist/assets/insertionBoundaries-DQrE5qG2.js +0 -1
- package/dist/assets/main-D2BzpnUt.css +0 -1
- package/dist/assets/main-DYISNvWY.js +0 -169
- package/dist/assets/miniChat-DYIqdWi7.js +0 -2
- package/dist/assets/mobile-CwiCcmWt.js +0 -2
- package/dist/assets/multirun-C3snjTFs.js +0 -4
- package/dist/assets/persistence-D0y7226-.js +0 -3
- package/dist/assets/pl-BCf5uLlK.js +0 -15
- package/dist/assets/platform-CurqO28D.js +0 -6
- package/dist/assets/projectMeta-BkhYFMaM.js +0 -3
- package/dist/assets/renderElectronMiniChatApp-7iyh_419.js +0 -2
- package/dist/assets/renderMobileApp-y0_NeckR.js +0 -28
- package/dist/assets/runtime-switch-LvWDU-SL.js +0 -1
- package/dist/assets/runtimeConfig-12C5j02f.js +0 -2
- package/dist/assets/runtimeEndpointReset-DTY2ZXXb.js +0 -149
- package/dist/assets/sessionChangeSummary-CwPBIb3Z.js +0 -2
- package/dist/assets/src-lS1keDVV.css +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-CR_DcY77.js +0 -1
- package/dist/assets/useMobileNavigationStore-DwupvLSA.js +0 -414
- package/dist/assets/useSessionAutoCleanup-DkGO_usj.js +0 -2
- package/dist/assets/vendor-opencode-client-C12gfjag.js +0 -12
- package/server/lib/opencode/snippets.js +0 -242
- package/server/lib/opencode/snippets.test.js +0 -97
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { beforeEach, expect, it, vi } from 'vitest';
|
|
1
|
+
import { afterEach, beforeEach, expect, it, vi } from 'vitest';
|
|
2
2
|
import { mergeMetadataPatch } from '../session-metadata/session-metadata-store.js';
|
|
3
3
|
|
|
4
4
|
const { api } = vi.hoisted(() => ({ api: {
|
|
@@ -8,17 +8,21 @@ const { api } = vi.hoisted(() => ({ api: {
|
|
|
8
8
|
vi.mock('../opencode/v2-client.js', () => ({ makeOpenCodeV2Client: () => api }));
|
|
9
9
|
import { createTitleSessionAccess } from './session-access.js';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const accesses = [];
|
|
12
|
+
beforeEach(() => { vi.resetAllMocks(); vi.useFakeTimers(); });
|
|
13
|
+
afterEach(() => { for (const access of accesses.splice(0)) access.stop(); vi.useRealTimers(); });
|
|
12
14
|
|
|
13
15
|
function fixture() {
|
|
14
16
|
let metadata = { openchamber: {
|
|
15
17
|
goal: { status: 'active' },
|
|
16
18
|
titleRefresh: { isGenerating: true, requestedAt: 1000, lastError: 'old failure', failedAt: 1 },
|
|
17
19
|
} };
|
|
18
|
-
|
|
20
|
+
const session = {
|
|
19
21
|
id: 'ses_title', title: 'Updated title', location: { directory: '/repo' },
|
|
20
22
|
time: { created: 10, updated: 20 },
|
|
21
|
-
}
|
|
23
|
+
};
|
|
24
|
+
api.session.get.mockImplementation(async () => structuredClone(session));
|
|
25
|
+
api.session.update.mockImplementation(async ({ title }) => { session.title = title; });
|
|
22
26
|
const persist = vi.fn(async (_id, patch) => { metadata = mergeMetadataPatch(metadata, patch); });
|
|
23
27
|
const publish = vi.fn();
|
|
24
28
|
const access = createTitleSessionAccess({
|
|
@@ -26,9 +30,17 @@ function fixture() {
|
|
|
26
30
|
getOpenCodeAuthHeaders: () => ({}),
|
|
27
31
|
readSessionMetadata: async () => metadata,
|
|
28
32
|
persistSessionMetadata: persist,
|
|
33
|
+
mutateSessionMetadata: async (id, decide) => {
|
|
34
|
+
const decision = decide(metadata);
|
|
35
|
+
if (!decision.ok) return { committed: false, metadata };
|
|
36
|
+
await persist(id, decision.patch);
|
|
37
|
+
return { committed: true, metadata };
|
|
38
|
+
},
|
|
39
|
+
listSessionMetadata: async () => ({ ses_title: metadata }),
|
|
29
40
|
publishSession: publish,
|
|
30
41
|
});
|
|
31
|
-
|
|
42
|
+
accesses.push(access);
|
|
43
|
+
return { access, persist, publish, session, metadata: () => metadata };
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
it('publishes the full authoritative title row and clears Host loading without overwriting unrelated state', async () => {
|
|
@@ -42,6 +54,7 @@ it('publishes the full authoritative title row and clears Host loading without o
|
|
|
42
54
|
expect(api.session.update.mock.calls[0][0]).toEqual({ sessionID: 'ses_title', title: 'Updated title' });
|
|
43
55
|
expect(f.metadata()).toEqual({ openchamber: {
|
|
44
56
|
goal: { status: 'active' }, titleRefresh: { lastAutoTitle: 'Updated title' },
|
|
57
|
+
titleAuthority: { sessionID: 'ses_title', title: 'Updated title', revision: expect.any(String), source: 'summary' },
|
|
45
58
|
} });
|
|
46
59
|
expect(f.publish).toHaveBeenCalledWith(expect.objectContaining({
|
|
47
60
|
id: 'ses_title', title: 'Updated title', directory: '/repo', metadata: f.metadata(),
|
|
@@ -72,14 +85,119 @@ it('publishes a full loading row before the new session exists in client catalog
|
|
|
72
85
|
expect(api.session.update).not.toHaveBeenCalled();
|
|
73
86
|
});
|
|
74
87
|
|
|
75
|
-
it('
|
|
88
|
+
it('retains durable intent and retries a failed upstream title write without publishing success', async () => {
|
|
76
89
|
const f = fixture();
|
|
77
90
|
api.session.update.mockRejectedValue(new Error('offline'));
|
|
78
91
|
await expect(f.access.update('ses_title', '/repo', {
|
|
79
92
|
title: 'Failed', metadata: { openchamber: { titleRefresh: { lastAutoTitle: 'Failed' } } },
|
|
80
93
|
})).rejects.toThrow('offline');
|
|
81
|
-
expect(f.
|
|
94
|
+
expect(f.metadata().openchamber.titleAuthority.title).toBe('Failed');
|
|
82
95
|
expect(f.publish).not.toHaveBeenCalled();
|
|
96
|
+
api.session.update.mockImplementation(async ({ title }) => { f.session.title = title; });
|
|
97
|
+
await vi.runAllTimersAsync();
|
|
98
|
+
expect(f.session.title).toBe('Failed');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it.each(['before', 'after', 'during'])('rectifies upstream title writes %s our write', async (timing) => {
|
|
102
|
+
const f = fixture();
|
|
103
|
+
if (timing === 'before') f.session.title = 'Native';
|
|
104
|
+
await f.access.update('ses_title', '/repo', { title: 'Ours' });
|
|
105
|
+
if (timing !== 'before') f.session.title = 'Native';
|
|
106
|
+
if (timing === 'during') {
|
|
107
|
+
api.session.update.mockImplementationOnce(async () => { f.session.title = 'Native again'; });
|
|
108
|
+
}
|
|
109
|
+
for (let i = 0; i < 100; i++) f.access.reconcile('ses_title');
|
|
110
|
+
await vi.runAllTimersAsync();
|
|
111
|
+
expect(f.session.title).toBe('Ours');
|
|
112
|
+
expect(api.session.update.mock.calls.length).toBeLessThanOrEqual(3);
|
|
113
|
+
const writes = api.session.update.mock.calls.length;
|
|
114
|
+
f.access.reconcile('ses_title');
|
|
115
|
+
await vi.runAllTimersAsync();
|
|
116
|
+
expect(api.session.update).toHaveBeenCalledTimes(writes);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('rejects stale generation after a manual rename and repairs from the newest authority', async () => {
|
|
120
|
+
const f = fixture();
|
|
121
|
+
await f.access.update('ses_title', '/repo', { title: 'Summary' });
|
|
122
|
+
const previous = f.metadata().openchamber.titleAuthority.revision;
|
|
123
|
+
await f.persist('ses_title', { openchamber: { titleAuthority: {
|
|
124
|
+
sessionID: 'ses_title', title: 'Manual', revision: 'manual-1', source: 'manual',
|
|
125
|
+
} } });
|
|
126
|
+
await f.access.update('ses_title', '/repo', { title: 'Late summary', expectedTitleRevision: previous });
|
|
127
|
+
await vi.runAllTimersAsync();
|
|
128
|
+
expect(f.session.title).toBe('Manual');
|
|
129
|
+
expect(f.metadata().openchamber.titleAuthority.source).toBe('manual');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('re-reads authority when manual rename lands during an upstream repair', async () => {
|
|
133
|
+
const f = fixture();
|
|
134
|
+
await f.access.update('ses_title', '/repo', { title: 'Summary' });
|
|
135
|
+
f.session.title = 'Native';
|
|
136
|
+
api.session.get.mockImplementationOnce(async () => {
|
|
137
|
+
await f.persist('ses_title', { openchamber: { titleAuthority: {
|
|
138
|
+
sessionID: 'ses_title', title: 'Manual', revision: 'manual-2', source: 'manual',
|
|
139
|
+
} } });
|
|
140
|
+
return structuredClone(f.session);
|
|
141
|
+
});
|
|
142
|
+
await vi.runAllTimersAsync();
|
|
143
|
+
expect(f.session.title).toBe('Manual');
|
|
144
|
+
expect(f.publish.mock.calls.at(-1)[0].title).toBe('Manual');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('recovers missed rename events after reconnect without regenerating a title', async () => {
|
|
148
|
+
const f = fixture();
|
|
149
|
+
await f.persist('ses_title', { openchamber: { titleAuthority: {
|
|
150
|
+
sessionID: 'ses_title', title: 'Durable', revision: 'saved', source: 'summary',
|
|
151
|
+
} } });
|
|
152
|
+
await f.access.reconcileAll();
|
|
153
|
+
await vi.runAllTimersAsync();
|
|
154
|
+
expect(f.session.title).toBe('Durable');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('does not adopt inherited fork authority or legacy lastAutoTitle as a lock', async () => {
|
|
158
|
+
const f = fixture();
|
|
159
|
+
await f.persist('ses_title', { openchamber: {
|
|
160
|
+
titleRefresh: { lastAutoTitle: 'Old summary' },
|
|
161
|
+
titleAuthority: { sessionID: 'ses_parent', title: 'Parent', revision: 'parent' },
|
|
162
|
+
} });
|
|
163
|
+
f.access.reconcile('ses_title');
|
|
164
|
+
await vi.runAllTimersAsync();
|
|
165
|
+
expect(api.session.update).not.toHaveBeenCalled();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('does not write a title if durable authority persistence fails', async () => {
|
|
169
|
+
const f = fixture();
|
|
170
|
+
f.persist.mockRejectedValue(new Error('disk unavailable'));
|
|
171
|
+
await expect(f.access.update('ses_title', '/repo', { title: 'Unsaved' })).rejects.toThrow('disk unavailable');
|
|
172
|
+
await vi.runAllTimersAsync();
|
|
173
|
+
expect(api.session.update).not.toHaveBeenCalled();
|
|
174
|
+
expect(f.publish).not.toHaveBeenCalled();
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('stops repair after authoritative deletion', async () => {
|
|
178
|
+
const f = fixture();
|
|
179
|
+
await f.persist('ses_title', { openchamber: { titleAuthority: {
|
|
180
|
+
sessionID: 'ses_title', title: 'Durable', revision: 'saved',
|
|
181
|
+
} } });
|
|
182
|
+
api.session.get.mockRejectedValue(Object.assign(new Error('deleted'), { status: 404 }));
|
|
183
|
+
f.access.reconcile('ses_title');
|
|
184
|
+
await vi.runAllTimersAsync();
|
|
185
|
+
expect(api.session.get).toHaveBeenCalledTimes(1);
|
|
186
|
+
expect(api.session.update).not.toHaveBeenCalled();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('backs off transient failures and cancels retry on stop', async () => {
|
|
190
|
+
const f = fixture();
|
|
191
|
+
await f.persist('ses_title', { openchamber: { titleAuthority: {
|
|
192
|
+
sessionID: 'ses_title', title: 'Durable', revision: 'saved',
|
|
193
|
+
} } });
|
|
194
|
+
api.session.get.mockRejectedValue(new Error('offline'));
|
|
195
|
+
f.access.reconcile('ses_title');
|
|
196
|
+
await vi.advanceTimersByTimeAsync(3000);
|
|
197
|
+
expect(api.session.get).toHaveBeenCalledTimes(3);
|
|
198
|
+
f.access.stop();
|
|
199
|
+
await vi.advanceTimersByTimeAsync(60_000);
|
|
200
|
+
expect(api.session.get).toHaveBeenCalledTimes(3);
|
|
83
201
|
});
|
|
84
202
|
|
|
85
203
|
it('does not turn a failed or malformed message read into empty success', async () => {
|
|
@@ -43,7 +43,8 @@ This module provides server-side Text-to-Speech services using OpenAI's TTS API.
|
|
|
43
43
|
## TTSService methods
|
|
44
44
|
|
|
45
45
|
### `isAvailable()`
|
|
46
|
-
Returns
|
|
46
|
+
Returns a Promise of boolean after reading the current OpenCode selected credential.
|
|
47
|
+
Credential-source failure rejects; logout clears the previously constructed client.
|
|
47
48
|
|
|
48
49
|
### `generateSpeechStream(options)`
|
|
49
50
|
Generates speech and returns as a web stream for direct streaming to clients.
|
|
@@ -81,10 +82,11 @@ Returns object with:
|
|
|
81
82
|
Returns Buffer containing MP3 audio data.
|
|
82
83
|
|
|
83
84
|
## API key resolution
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
Explicit request API key/custom base URL remains supported. Otherwise the host
|
|
86
|
+
reads the current OpenCode credential API (`openai`, `codex`, `chatgpt` aliases),
|
|
87
|
+
using API `key` or OAuth `access`. There is no host-local environment/file fallback
|
|
88
|
+
that could substitute another account for a remote service. A credential read
|
|
89
|
+
failure propagates; selected-account changes replace the client and logout clears it.
|
|
88
90
|
|
|
89
91
|
## Usage in web server
|
|
90
92
|
The TTS module is used by `packages/web/server/index.js` for:
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { afterEach, expect, it } from 'vitest';
|
|
2
|
+
import { configureOpenCodeCredentials } from '../opencode/auth.js';
|
|
3
|
+
import { TTSService } from './service.js';
|
|
4
|
+
|
|
5
|
+
afterEach(() => configureOpenCodeCredentials(null));
|
|
6
|
+
|
|
7
|
+
it('TTS clears its old client after logout and obtains a new client after account switching', async () => {
|
|
8
|
+
let token = 'first';
|
|
9
|
+
configureOpenCodeCredentials(() => ({ credential: { list: async () => token ? [{ id: 'selected', integrationID: 'openai', active: true, value: { type: 'key', key: token } }] : [] } }));
|
|
10
|
+
const service = new TTSService();
|
|
11
|
+
const first = await service._getClient();
|
|
12
|
+
expect(await service.isAvailable()).toBe(true);
|
|
13
|
+
token = 'second';
|
|
14
|
+
expect(await service._getClient()).not.toBe(first);
|
|
15
|
+
token = '';
|
|
16
|
+
expect(await service.isAvailable()).toBe(false);
|
|
17
|
+
expect(await service._getClient()).toBeNull();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('TTS does not present credential read failure as unavailable success', async () => {
|
|
21
|
+
configureOpenCodeCredentials(() => ({ credential: { list: async () => { throw new Error('private'); } } }));
|
|
22
|
+
await expect(new TTSService().isAvailable()).rejects.toThrow(/^Unable to read OpenCode credentials$/);
|
|
23
|
+
});
|
package/server/lib/tts/routes.js
CHANGED
|
@@ -62,7 +62,7 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
|
|
|
62
62
|
const { ttsService } = await getTtsModule();
|
|
63
63
|
|
|
64
64
|
// Check availability - server-configured key, client-provided key, or custom server URL
|
|
65
|
-
const hasServerKey = ttsService.isAvailable();
|
|
65
|
+
const hasServerKey = await ttsService.isAvailable();
|
|
66
66
|
const hasClientKey = apiKey && typeof apiKey === 'string' && apiKey.trim().length > 0;
|
|
67
67
|
const hasCustomBaseURL = typeof normalizedBaseURL === 'string' && normalizedBaseURL.length > 0;
|
|
68
68
|
|
|
@@ -134,7 +134,7 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
|
|
|
134
134
|
try {
|
|
135
135
|
const { ttsService } = await getTtsModule();
|
|
136
136
|
res.json({
|
|
137
|
-
available: ttsService.isAvailable(),
|
|
137
|
+
available: await ttsService.isAvailable(),
|
|
138
138
|
voices: [
|
|
139
139
|
'alloy', 'ash', 'ballad', 'coral', 'echo', 'fable',
|
|
140
140
|
'nova', 'onyx', 'sage', 'shimmer', 'verse', 'marin', 'cedar'
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import OpenAI from 'openai';
|
|
9
|
-
import {
|
|
9
|
+
import { readOpenCodeCredentials } from '../opencode/auth.js';
|
|
10
10
|
import { normalizeCustomOpenAIBaseURL } from './base-url.js';
|
|
11
11
|
|
|
12
12
|
// Voice options from OpenAI
|
|
@@ -15,36 +15,10 @@ export const TTS_VOICES = [
|
|
|
15
15
|
'nova', 'onyx', 'sage', 'shimmer', 'verse', 'marin', 'cedar'
|
|
16
16
|
];
|
|
17
17
|
|
|
18
|
-
function getOpenAIApiKey() {
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
return envKey;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Then check opencode auth file (same as usage tracker)
|
|
26
|
-
try {
|
|
27
|
-
const auth = readAuthFile();
|
|
28
|
-
// Check for openai, codex, or chatgpt aliases
|
|
29
|
-
const openaiAuth = auth.openai || auth.codex || auth.chatgpt;
|
|
30
|
-
if (openaiAuth) {
|
|
31
|
-
// Handle both string format (just the token) and object format
|
|
32
|
-
if (typeof openaiAuth === 'string') {
|
|
33
|
-
return openaiAuth;
|
|
34
|
-
}
|
|
35
|
-
// Try access token first (OAuth), then regular token
|
|
36
|
-
if (openaiAuth.access) {
|
|
37
|
-
return openaiAuth.access;
|
|
38
|
-
}
|
|
39
|
-
if (openaiAuth.token) {
|
|
40
|
-
return openaiAuth.token;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.warn('[TTSService] Failed to read auth file:', error.message);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return null;
|
|
18
|
+
async function getOpenAIApiKey() {
|
|
19
|
+
const auth = await readOpenCodeCredentials();
|
|
20
|
+
const entry = auth.openai || auth.codex || auth.chatgpt;
|
|
21
|
+
return entry?.type === 'api' ? entry.key : entry?.access || null;
|
|
48
22
|
}
|
|
49
23
|
|
|
50
24
|
class TTSService {
|
|
@@ -53,8 +27,13 @@ class TTSService {
|
|
|
53
27
|
this._lastApiKey = null;
|
|
54
28
|
}
|
|
55
29
|
|
|
56
|
-
_getClient() {
|
|
57
|
-
const apiKey = getOpenAIApiKey();
|
|
30
|
+
async _getClient() {
|
|
31
|
+
const apiKey = await getOpenAIApiKey();
|
|
32
|
+
if (!apiKey) {
|
|
33
|
+
this._client = null;
|
|
34
|
+
this._lastApiKey = null;
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
58
37
|
|
|
59
38
|
// If API key changed or client doesn't exist, create new client
|
|
60
39
|
if (apiKey && (!this._client || this._lastApiKey !== apiKey)) {
|
|
@@ -65,8 +44,8 @@ class TTSService {
|
|
|
65
44
|
return this._client;
|
|
66
45
|
}
|
|
67
46
|
|
|
68
|
-
isAvailable() {
|
|
69
|
-
return this._getClient() !== null;
|
|
47
|
+
async isAvailable() {
|
|
48
|
+
return (await this._getClient()) !== null;
|
|
70
49
|
}
|
|
71
50
|
|
|
72
51
|
/**
|
|
@@ -98,7 +77,7 @@ class TTSService {
|
|
|
98
77
|
if (normalizedBaseURL) clientOpts.baseURL = normalizedBaseURL;
|
|
99
78
|
client = new OpenAI(clientOpts);
|
|
100
79
|
} else {
|
|
101
|
-
client = this._getClient();
|
|
80
|
+
client = await this._getClient();
|
|
102
81
|
}
|
|
103
82
|
|
|
104
83
|
if (!client) {
|
|
@@ -141,7 +120,7 @@ class TTSService {
|
|
|
141
120
|
* Generate speech and return as a buffer (for caching)
|
|
142
121
|
*/
|
|
143
122
|
async generateSpeechBuffer(options) {
|
|
144
|
-
const client = this._getClient();
|
|
123
|
+
const client = await this._getClient();
|
|
145
124
|
if (!client) {
|
|
146
125
|
throw new Error('OpenAI API key not configured. Set OPENAI_API_KEY environment variable or configure OpenAI in OpenCode.');
|
|
147
126
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-4DC5OE1J.js","assets/rolldown-runtime-C0FnF6B9.js","assets/runtime-fetch-Fs9ZV2V8.js","assets/runtime-auth-D66yq6ie.js","assets/runtime-switch-LvWDU-SL.js","assets/vendor-base-ui-CnHfUmDN.js","assets/useUIStore-syVmbuDA.js","assets/vendor-zustand-B4dlGEM2.js","assets/vendor-react-DLPElpoQ.js","assets/vendor-pierre-diffs-DX7XTPG3.js","assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js","assets/vendor-hast-util-to-html-B0p1k5Xa.js","assets/vendor-character-entities-legacy-Wut6vMuj.js","assets/vendor-character-entities-html4-DlN_yAFd.js","assets/vendor-ccount-CyGsA0u7.js","assets/vendor-comma-separated-tokens-B9ouxNNS.js","assets/vendor-oniguruma-to-es-CrHzjjSU.js","assets/vendor-oniguruma-parser-D2DIvhSP.js","assets/vendor-diff-Dq7CZNim.js","assets/vendor-lru_map-DpDied8H.js","assets/vendor-reactuses-core-Dq5ocTF8.js","assets/vendor-lodash-es-DfLbG5Af.js","assets/vendor-js-cookie-hSOiFTtX.js","assets/button-DIIrsMjW.js","assets/persistence-D0y7226-.js","assets/vendor-pathe-vBmvQE8f.js","assets/vendor-tanstack-query-core-BWz0ose6.js","assets/store-jaP79mqI.js","assets/vendor-class-variance-authority-BLUaYARZ.js","assets/vendor-tailwind-merge-BicNWLTg.js","assets/dialog-CQ63sc9E.js","assets/Icon-B8fSTLdP.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-DM5h1i18.js","assets/appThemeRegistry-LkVH62uF.js","assets/platform-CurqO28D.js","assets/vendor-opencode-client-C12gfjag.js","assets/useMobileNavigationStore-DwupvLSA.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-Bz4tRflF.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/MarkdownRenderer-BK69MEHQ.js","assets/markdownHeightCache-D9-B1wdY.js","assets/dualLimitLru-D8Sphgua.js","assets/markdown-worker-bS5OgGO3.js","assets/useEffectiveDirectory-BW9jNyuK.js","assets/imageSource-BMztRu0c.js","assets/relay-image-stream-DrdVj99c.js","assets/useWorkerHighlightedLines-BUcSLKlL.js","assets/tooltip-DYeQ_Hvy.js","assets/vendor-tanstack-react-virtual-tlDgH6PG.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
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-D0y7226-.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-CurqO28D.js";import{n as y}from"./useUIStore-syVmbuDA.js";import{n as b}from"./vendor-react-DLPElpoQ.js";import{o as x}from"./vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js";import{s as S}from"./vendor-tanstack-react-query-D7pys_c9.js";import{r as C}from"./vendor-sonner-DVzioF3d.js";import{a as w,d as T,f as E,i as D,n as O,r as k}from"./vendor-reactuses-core-Dq5ocTF8.js";import{f as A,r as j,t as M}from"./button-DIIrsMjW.js";import{a as N,n as P}from"./MobileShareBridge-yCN95dYg.js";import{C as F,_ as I,a as L,f as R,g as z,j as B,k as V,l as H,n as U,r as ee,s as te,t as W,u as ne,y as re}from"./MobileDetailNavigation-agQ-Yhpd.js";import{Sr as ie,Yt as ae,ho as oe,lt as se,o as ce,xn as le,xr as G}from"./useMobileNavigationStore-DwupvLSA.js";import{i as K,n as q,r as ue}from"./useAssistantUIStore-Bz4tRflF.js";import{a as de,i as J,n as Y,o as X,r as fe,t as pe}from"./dialog-CQ63sc9E.js";import{t as me}from"./AgentAvatar-CzTtVMnI.js";import{n as Z}from"./Icon-B8fSTLdP.js";import{i as he}from"./OverlayScrollbar-CRfGtcmG.js";import{n as ge}from"./textarea-XD2oX_Ee.js";import{D as _e,S as ve,T as ye,a as be,c as xe,d as Se,f as Ce,i as we,l as Te,m as Ee,n as De,o as Oe,p as ke,r as Ae,t as je,u as Me}from"./sessionChangeSummary-CwPBIb3Z.js";import{a as Ne,n as Pe,r as Fe,t as Ie}from"./fileMentionTouchSelection-CBzDuQxP.js";import{o as Le,t as Re}from"./MarkdownRenderer-BK69MEHQ.js";import{c as ze,s as Be}from"./imageSource-BMztRu0c.js";import{a as Ve,t as He}from"./sessionLookup-0Z4e-J1g.js";import{a as Ue,i as We,n as Ge,r as Ke,t as qe}from"./context-menu-BGBUpZEQ.js";import{i as Je,n as Ye,r as Xe}from"./assistant-attachment-cache-DphJleHr.js";var Ze=b();function Qe(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 $e({snapshot:e,rowClassName:t}){let{t:n}=A(),[r,i]=Q.useState(!1),a=Q.useRef(!1),o=O(async()=>{if(!a.current){a.current=!0,i(!0);try{(await H(e)).failed&&C.error(n(`assistants.unread.markAllFailed`))}catch{C.error(n(`assistants.unread.markAllFailed`))}finally{a.current=!1,i(!1)}}});return e.assistants.some(e=>(e.unreadCount??0)>0)?(0,$.jsx)(`div`,{className:t,children:(0,$.jsx)(M,{type:`button`,variant:`ghost`,size:`xs`,onClick:o,className:`max-w-full whitespace-normal text-right`,disabled:r||!e.assistants.some(e=>(e.unreadCount??0)>0&&e.readTip),"aria-busy":r,children:n(`assistants.unread.markAll`)})}):null}var et=e=>{let t=(0,Ze.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}=A(),d=`calc(${c}px * var(--dpt-n, 1))`,f;t[0]===s?f=t[1]:(f=j(`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)(me,{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.5 translate-x-0.5 translate-y-0.5 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},tt=m(e=>({workingByID:{},setWorking:(t,n)=>e(e=>({workingByID:{...e.workingByID,[t]:n}}))})),nt=({sending:e=!1,processing:t=!1,serverWorking:n=!1})=>e||t||n,rt=(e,t)=>{let n=(0,Ze.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=tt(i),o;return n[2]!==a||n[3]!==r?(o=nt({processing:a,serverWorking:r}),n[2]=a,n[3]=r,n[4]=o):o=n[4],o};function it(e){let t=(0,Ze.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(ut),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,ne(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=O(d),p;t[5]===f?p=t[6]:(p=e=>{s.current=e.some(lt),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],D(o,O(p),m),k(`visibilitychange`,f,ct),k(`focus`,f,st),k(`resize`,f,ot);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]),k(`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],T(f,at,v),w(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 at(){return document.documentElement}function ot(){return window.visualViewport}function st(){return window}function ct(){return document}function lt(e){return e.isIntersecting&&e.intersectionRatio===1}function ut(){return{transport:r(),generation:i()}}var dt=e=>e?.directories.flatMap(({directory:e,sessions:t})=>e?t.filter(e=>!e.time.archived).map(t=>({...t,directory:e||t.location?.directory||t.directory||``})).filter(e=>e.directory.length>0):[])??null,ft=Q.forwardRef(({query:e,isMobile:t,listId:n,onHighlightChange:r,onSelect:i,onClose:a},o)=>{let{t:s}=A(),c=ze(),l=S({...ie(c),select:dt}),u=Q.useMemo(()=>se({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(Ie,[]);k(`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 _=O(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)(Pe,{ref:m,isMobile:t,className:`max-w-[640px] max-h-64`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 px-3 py-1`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 text-[length:calc(var(--text-meta)*0.875)] leading-4 text-muted-foreground`,children:s(`assistants.contact.sessionMention.scope`)}),(0,$.jsx)(M,{type:`button`,size:`xs`,variant:`ghost`,"aria-label":s(`dialog.common.actions.close`),onClick:a,children:(0,$.jsx)(Z,{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)(M,{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)(ge,{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:`p-1.5`,children:u.map((r,a)=>(0,$.jsxs)(`div`,{id:`${n}-${a}`,role:`option`,"aria-selected":a===p,ref:e=>{h.current[a]=e},className:j(`flex min-h-10 cursor-pointer items-center gap-2 rounded-md px-1.5 py-1 typography-ui-label`,Fe(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)(Z,{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 font-medium leading-5`,title:r.title,children:r.title||s(`chat.fileMentionAutocomplete.untitledSession`)}),(0,$.jsx)(`div`,{className:`truncate text-[length:calc(var(--text-meta)*0.875)] leading-4 text-muted-foreground`,title:r.directory,children:r.directory})]})]},`${r.directory}:${r.id}`))})}),t?null:(0,$.jsx)(`div`,{className:`mx-1.5 shrink-0 border-t px-1.5 py-1 text-[length:calc(var(--text-meta)*0.875)] leading-4 text-muted-foreground`,children:s(`chat.autocomplete.keyboardHint`)})]})}),pt=e=>{let t=(0,Ze.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}=A(),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),[E,D]=Q.useState(),k=Q.useRef(null),M=Q.useRef(null),N=Q.useRef(null),P=Q.useRef(null),F;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(F=Te(),t[11]=F):F=t[11];let I=Q.useRef(F),L=Q.useId(),R;t[12]!==n||t[13]!==w||t[14]!==b||t[15]!==S||t[16]!==y.text||t[17]!==i.disabled||t[18]!==i.pending?(R=n&&!i.pending&&!i.disabled&&!S&&!w?Ne({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]=R):R=t[19];let z=R,B=z?.kind===`mention`?z:null,V;t[20]===Symbol.for(`react.memo_cache_sentinel`)?(V=()=>{P.current!==null&&(k.current?.focus({preventScroll:!0}),k.current?.setSelectionRange(P.current,P.current),P.current=null)},t[20]=V):V=t[20];let H;t[21]===y?H=t[22]:(H=[y],t[21]=y,t[22]=H),Q.useLayoutEffect(V,H);let U;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(U=()=>C(!0),t[23]=U):U=t[23];let ee=O(U),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&&(I.current=Me(I.current,{before:xe(y,[],{start:k.current?.selectionStart??b,end:k.current?.selectionEnd??b}),after:xe(e,[],{start:t,end:t})})),w||(P.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 W=O(te),ne;t[29]!==W||t[30]!==y||t[31]!==B||t[32]!==m?(ne=e=>{if(!B)return;let t=e.title||m(`chat.fileMentionAutocomplete.untitledSession`),n=s(y,B.tokenStart,B.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),W(n.document,r)},t[29]=W,t[30]=y,t[31]=B,t[32]=m,t[33]=ne):ne=t[33];let re=O(ne),ie;t[34]!==W||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);W(e.document,e.caret)}},t[34]=W,t[35]=y,t[36]=ie):ie=t[36];let ae=O(ie),oe;t[37]!==y.references||t[38]!==y.text?(oe=Ee(y.text,y.references.map(mt))?.map(ht),t[37]=y.references,t[38]=y.text,t[39]=oe):oe=t[39];let se=oe,ce=y.text,le=i.pending||d,G=i.pending===!0,K=i.layout===`inline`?`py-3 leading-6`:`pt-4 pb-2`,q;t[40]!==i.textLayoutClassName||t[41]!==K?(q=j(`whitespace-pre-wrap break-words overflow-hidden px-3 typography-markdown md:typography-ui-label`,K,i.textLayoutClassName),t[40]=i.textLayoutClassName,t[41]=K,t[42]=q):q=t[42];let ue;t[43]!==W||t[44]!==y?(ue=(e,t)=>{let n=f(y,e,t?.target.selectionStart??e.length,t?.target.selectionEnd??e.length);W(n.document,n.caret),C(t?.nativeEvent?.inputType===`insertFromPaste`)},t[43]=W,t[44]=y,t[45]=ue):ue=t[45];let de=B?L:void 0,J=B?E:void 0,Y;t[46]===i.textareaProps?Y=t[47]:(Y=e=>{i.textareaProps?.onScroll?.(e),M.current&&(M.current.scrollTop=e.currentTarget.scrollTop,M.current.scrollLeft=e.currentTarget.scrollLeft)},t[46]=i.textareaProps,t[47]=Y);let X,fe;t[48]!==ae||t[49]!==i.textareaProps?(X=e=>{i.textareaProps?.onCopy?.(e),e.defaultPrevented||ae(e,!1)},fe=e=>{i.textareaProps?.onCut?.(e),e.defaultPrevented||ae(e,!0)},t[48]=ae,t[49]=i.textareaProps,t[50]=X,t[51]=fe):(X=t[50],fe=t[51]);let pe;t[52]===i.textareaProps?pe=t[53]:(pe=e=>{x(e.currentTarget.selectionStart),i.textareaProps?.onSelect?.(e)},t[52]=i.textareaProps,t[53]=pe);let me,Z;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(me=()=>{T(!0)},Z=e=>{T(!1),x(e.currentTarget.selectionStart)},t[54]=me,t[55]=Z):(me=t[54],Z=t[55]);let he;t[56]!==W||t[57]!==w||t[58]!==y||t[59]!==B||t[60]!==i.textareaProps?(he=e=>{if(i.textareaProps?.onKeyDown?.(e),!(e.defaultPrevented||ye(e))){if(w){e.key===`Enter`&&e.preventDefault();return}if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`z`){let t=e.shiftKey?Se(I.current,y):Ce(I.current,y);t&&(e.preventDefault(),I.current=t.history,W(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(),W(t.document,t.caret),C(!0);return}}B&&[`ArrowDown`,`ArrowUp`,`Enter`,`Tab`,`Escape`].includes(e.key)&&(e.preventDefault(),e.stopPropagation(),N.current?.keyDown(e.key))}},t[56]=W,t[57]=w,t[58]=y,t[59]=B,t[60]=i.textareaProps,t[61]=he):he=t[61];let ge;t[62]!==i.textareaProps||t[63]!==de||t[64]!==J||t[65]!==Y||t[66]!==X||t[67]!==fe||t[68]!==pe||t[69]!==he?(ge={...i.textareaProps,"aria-controls":de,"aria-activedescendant":J,"aria-autocomplete":`list`,onScroll:Y,onCopy:X,onCut:fe,onSelect:pe,onCompositionStart:me,onCompositionEnd:Z,onKeyDown:he},t[62]=i.textareaProps,t[63]=de,t[64]=J,t[65]=Y,t[66]=X,t[67]=fe,t[68]=pe,t[69]=he,t[70]=ge):ge=t[70];let _e;t[71]!==ee||t[72]!==L||t[73]!==B||t[74]!==i.isMobile||t[75]!==re?(_e=B?(0,$.jsx)(ft,{ref:N,query:B.query,isMobile:i.isMobile??!1,listId:L,onHighlightChange:D,onSelect:re,onClose:ee}):null,t[71]=ee,t[72]=L,t[73]=B,t[74]=i.isMobile,t[75]=re,t[76]=_e):_e=t[76];let be;return t[77]!==y.text||t[78]!==se||t[79]!==i||t[80]!==le||t[81]!==G||t[82]!==q||t[83]!==ue||t[84]!==ge||t[85]!==_e?(be=(0,$.jsx)(ve,{...i,value:ce,pending:le,disableInputWhilePending:G,inputRef:k,highlightedContent:se,highlightRef:M,textLayoutClassName:q,onChange:ue,textareaProps:ge,children:_e}),t[77]=y.text,t[78]=se,t[79]=i,t[80]=le,t[81]=G,t[82]=q,t[83]=ue,t[84]=ge,t[85]=_e,t[86]=be):be=t[86],be};function mt(e){return{start:e.start,end:e.end,priority:103,...u(e)}}function ht(e,t){return(0,$.jsx)(`span`,{className:e.className,children:e.visual?(0,$.jsx)(ke,{visual:e.visual,text:e.text}):e.text},`${t}-${e.text.length}`)}var gt=`max-h-72 max-w-full rounded-[1.35rem] border border-border/40 object-contain cursor-zoom-in`;function _t({assistantID:e,descriptor:t,onShowPopup:n}){let{t:r}=A(),i=ze(),{attachmentID:a,sha256:o,size:s,mime:c,filename:l}=t,u=Q.useMemo(()=>({type:`file`,attachmentID:a,sha256:o,size:s,mime:c,filename:l}),[a,o,s,c,l]),d=c.startsWith(`image/`),[f,p]=Q.useState(0),[m,h]=Q.useState(``),[g,_]=Q.useState(!1),[v,y]=Q.useState(!1),b=Q.useRef(null),x=Q.useRef([]);Q.useEffect(()=>{h(``),_(!1);let t=new AbortController,n;return d&&Xe(e,u,{signal:t.signal}).then(e=>{if(t.signal.aborted){e.release();return}n=e.release,h(e.url)}).catch(()=>{t.signal.aborted||_(!0)}),()=>{t.abort(),n?.()}},[e,u,i,d,f]),Q.useEffect(()=>()=>{b.current?.abort(),x.current.forEach(e=>URL.revokeObjectURL(e)),x.current=[]},[e,u,i]);let S=O(async()=>{if(b.current)return;let t=new AbortController;b.current=t,y(!0),_(!1);try{let n=await Ye(e,u,{signal:t.signal});if(t.signal.aborted)return;x.current.forEach(e=>URL.revokeObjectURL(e));let i=URL.createObjectURL(n);x.current=[i];let a=document.createElement(`a`);a.href=i,a.download=l||r(`assistants.contact.attachment.file`),document.body.appendChild(a),a.click(),a.remove()}catch{t.signal.aborted||_(!0)}finally{b.current===t&&(b.current=null),t.signal.aborted||y(!1)}}),C=l||r(d?`assistants.contact.attachment.image`:`assistants.contact.attachment.file`),w=O(()=>{!n||!m||n({open:!0,title:C,content:``,metadata:{tool:`image-preview`,filename:C,mime:c},image:{url:m,mimeType:c,filename:C,size:s,gallery:[{url:m,mimeType:c,filename:C,size:s}],index:0}})});return d&&m&&!g?(0,$.jsx)(`img`,{src:m,alt:C,className:gt,onError:()=>_(!0),onClick:w,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),w())},role:`button`,tabIndex: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)(Z,{name:`file-text`,className:`size-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate typography-ui`,children:C})]}),g?(0,$.jsx)(`p`,{role:`alert`,className:`typography-micro text-[var(--status-error)]`,children:r(`assistants.contact.attachment.loadFailed`)}):null,d&&!g||v?(0,$.jsx)(`span`,{role:`status`,className:`typography-micro text-muted-foreground`,children:r(`common.loading`)}):(0,$.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,onClick:d?()=>p(e=>e+1):()=>void S(),children:r(g?`chat.history.retry`:`assistants.contact.attachment.download`)})]})}function vt(e){let t=(0,Ze.c)(27),{part:n,onShowPopup:r}=e,{t:i}=A(),a=/^(?:https?:|data:|blob:)/i.test(n.url)?n.url:``,o=Be(a,``),[s,c]=Q.useState(!1),l;t[0]!==n.filename||t[1]!==i?(l=n.filename||i(`assistants.contact.attachment.image`),t[0]=n.filename,t[1]=i,t[2]=l):l=t[2];let u=l,d;t[3]!==u||t[4]!==r||t[5]!==o?(d=()=>{!r||!o||r({open:!0,title:u,content:``,metadata:{tool:`image-preview`,filename:u},image:{url:o,filename:u,gallery:[{url:o,filename:u}],index:0}})},t[3]=u,t[4]=r,t[5]=o,t[6]=d):d=t[6];let f=O(d);if(n.mime.startsWith(`image/`)&&o&&!s){let e;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(e=()=>c(!0),t[7]=e):e=t[7];let n;t[8]===f?n=t[9]:(n=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),f())},t[8]=f,t[9]=n);let r;return t[10]!==u||t[11]!==f||t[12]!==o||t[13]!==n?(r=(0,$.jsx)(`img`,{src:o,alt:u,className:gt,onError:e,onClick:f,onKeyDown:n,role:`button`,tabIndex:0,"data-assistant-contact-image":``}),t[10]=u,t[11]=f,t[12]=o,t[13]=n,t[14]=r):r=t[14],r}let p;t[15]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Z,{name:`file-text`,className:`size-4 shrink-0 text-muted-foreground`}),t[15]=p):p=t[15];let m;t[16]!==n.filename||t[17]!==i?(m=n.filename||i(`assistants.contact.attachment.file`),t[16]=n.filename,t[17]=i,t[18]=m):m=t[18];let h;t[19]===m?h=t[20]:(h=(0,$.jsx)(`span`,{className:`truncate typography-ui`,children:m}),t[19]=m,t[20]=h);let g;t[21]!==s||t[22]!==i?(g=s?(0,$.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>c(!1),children:i(`chat.history.retry`)}):null,t[21]=s,t[22]=i,t[23]=g):g=t[23];let _;return t[24]!==h||t[25]!==g?(_=(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:[p,h,g]}),t[24]=h,t[25]=g,t[26]=_):_=t[26],_}function yt(e){let t=(0,Ze.c)(5),{assistantID:n,part:r,onShowPopup:i}=e,a=ze(),o;return t[0]!==n||t[1]!==i||t[2]!==r||t[3]!==a?(o=`attachmentID`in r?(0,$.jsx)(_t,{assistantID:n,descriptor:r,onShowPopup:i},`${a}:${n}:${r.attachmentID}:${r.sha256}`):(0,$.jsx)(vt,{part:r,onShowPopup:i},`${a}:${r.url}`),t[0]=n,t[1]=i,t[2]=r,t[3]=a,t[4]=o):o=t[4],o}var bt=[],xt=e=>e.flatMap(e=>e.type===`text`&&e.text.trim()?[e.text]:[]).join(`
|
|
3
|
-
`),St=(e,t,n,r=Date.now())=>({assistantID:e,messageID:t,parts:n,status:`sending`,createdAt:r}),Ct=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},wt=(e,t)=>{let n=e.filter(e=>e.assistantID===t);return n.length===e.length?e:n},Tt=(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:[]}),Et=(e,t,n)=>{let r=e.bubbles.filter(e=>!t.has(e.bubbleIndex)).map((t,r)=>Tt(e,t,n+r,t.done?`complete`:`streaming`));return e.status===`failed`?[...r,Tt(e,null,n+r.length,`failed`)]:e.status===`admitted`||e.status===`streaming`?[...r,Tt(e,null,n+r.length,`admitted`)]:r},Dt=(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:xt(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=Et(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){if(e.status===`failed`&&o.some(t=>t.turnID!==e.turnID))continue;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)},Ot=(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},kt=(e,t)=>e.map(e=>e.messageID===t?{...e,status:`admitted`}:e),At=(e,t,n,r=Date.now())=>{let i=e.filter(e=>e.assistantID!==t||e.status!==`failed`||e.turnID===n);return i.some(e=>e.assistantID===t&&e.turnID===n)?i.length===e.length?e:i:[...i,{assistantID:t,turnID:n,status:`admitted`,bubbles:[],occurredAt:r}]},jt=(e,t,n)=>!t?.turnID||!t.assistantID||n?.has(t.turnID)?e:At(e,t.assistantID,t.turnID,t.admittedAt),Mt=(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=jt(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=Pt(u,{assistantID:n,turnID:e.turnID,status:`error`,error:e.text||`upstream_error`,occurredAt:s})));if(u=Ft(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},Nt=(e,t)=>At(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}}),Pt=(e,t,n={})=>n.requireExisting&&!e.some(e=>e.assistantID===t.assistantID&&e.turnID===t.turnID)?e:At(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}:{}}),Ft=(e,t)=>{let n=new Set(t.map(e=>e.turnID).filter(Boolean)),r=t.length>0?t[t.length-1]?.turnID??null:null,i=[...e].reverse().find(e=>e.status===`admitted`||e.status===`streaming`)?.turnID??r,a=new Set(t.flatMap(e=>e.role===`assistant`?[e.turnID]:[])),o=e.filter(e=>e.status===`admitted`||e.status===`streaming`||!(e.status===`complete`&&a.has(e.turnID)||!n.has(e.turnID)||e.status===`failed`&&(i&&i!==e.turnID||r&&r!==e.turnID)));return o.length===e.length?e:o},It=(e,t,n)=>e.map(e=>e.messageID===t?{...e,status:`failed`,error:n}:e),Lt=(e,t)=>{if(e instanceof V){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 B(e)?t.timedOut:t.sendFailed},Rt=()=>{let e=!1;return{tryAcquire:()=>!e&&(e=!0,!0),release:()=>{e=!1}}},zt=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:St(e.assistantID,r,n,e.createdAt)}},Bt=e=>e.some(e=>e.status===`sending`),Vt=e=>e.some(e=>e.status===`admitted`||e.status===`streaming`),Ht=[`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(` `),Ut=`${Ht} w-fit min-w-0 max-w-[min(100%,15rem)]`,Wt=`${Ht} w-fit min-w-0 max-w-[min(100%,20rem)]`;function Gt(e,t){(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),t())}var Kt=e=>{let t=(0,Ze.c)(26),{card:n}=e,{t:r}=A(),i=_e(),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){ce.getState().openAssistant(n.assistantID);return}q(n.assistantID)},t[5]=n.assistantID,t[6]=o,t[7]=d):d=t[7];let f=O(d),p;t[8]===f?p=t[9]:(p=e=>{Gt(e,f)},t[8]=f,t[9]=p);let m=O(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)(Z,{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:Ut,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},qt=e=>{let t=(0,Ze.c)(25),{card:n}=e,{t:r}=A(),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=O(Jt),u;t[7]===l?u=t[8]:(u=e=>{Gt(e,l)},t[7]=l,t[8]=u);let d=O(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)(Z,{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:Ut,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 Jt(){y.getState().setActiveMainTab(`schedule`),y.getState().setScheduledTasksDialogOpen(!0)}var Yt=(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`,Xt=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,Zt=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`,Qt=e=>e.split(/[/\\]/u).filter(Boolean).at(-1)||e,$t=e=>{let t=(0,Ze.c)(35),{card:n}=e,{t:r}=A(),i=_e(),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=G(s),l=ae(n.sessionID),u=(typeof c?.title==`string`&&c.title.trim()?c.title.trim():null)||n.title||r(`assistants.contact.card.session.untitled`),d=Yt(l?.type,n.status),f=Xt(d),p=d===`busy`||d===`retry`,m=Qt(typeof c?.directory==`string`&&c.directory.trim()?c.directory.trim():n.directory),h=De(c)||n.branch,g=we(c),_=Ae(c),b=je(_),x=[m,g,h].filter(en),S;t[4]!==n.directory||t[5]!==n.sessionID||t[6]!==o?(S=()=>{let e=He(n.sessionID)?.directory||n.directory;le(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=O(S),w;t[8]===C?w=t[9]:(w=e=>{Gt(e,C)},t[8]=C,t[9]=w);let T=O(w),E=Wt,D=r(`assistants.contact.card.session.aria`,{title:u}),k;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(`span`,{className:`flex size-6 items-center justify-center rounded-lg bg-[var(--surface-muted)] text-muted-foreground`,children:(0,$.jsx)(Z,{name:`chat-3`,className:`size-3`})}),t[10]=k):k=t[10];let M;t[11]===p?M=t[12]:(M=p?(0,$.jsx)(`span`,{className:`pointer-events-none absolute right-0 bottom-0 size-2.5 translate-x-0.5 translate-y-0.5 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]=M);let N;t[13]===M?N=t[14]:(N=(0,$.jsxs)(`span`,{className:`relative inline-block size-6 shrink-0 leading-none`,children:[k,M]}),t[13]=M,t[14]=N);let P;t[15]===u?P=t[16]:(P=(0,$.jsx)(`h3`,{className:`min-w-0 flex-1 truncate typography-ui-label font-medium text-foreground`,children:u}),t[15]=u,t[16]=P);let F=f?(0,$.jsx)(`span`,{className:j(`shrink-0 rounded-full px-1.5 py-0.5 typography-micro leading-none`,Zt(d)),children:r(f)}):null,I;t[17]!==P||t[18]!==F?(I=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[P,F]}),t[17]=P,t[18]=F,t[19]=I):I=t[19];let L;t[20]===x?L=t[21]:(L=x.length>0?(0,$.jsx)(`p`,{className:`truncate typography-micro text-muted-foreground`,children:x.join(` · `)}):null,t[20]=x,t[21]=L);let R=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,z;t[22]!==I||t[23]!==L||t[24]!==R?(z=(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[I,L,R]}),t[22]=I,t[23]=L,t[24]=R,t[25]=z):z=t[25];let B;t[26]!==N||t[27]!==z?(B=(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[N,z]}),t[26]=N,t[27]=z,t[28]=B):B=t[28];let V;return t[29]!==T||t[30]!==C||t[31]!==B||t[32]!==E||t[33]!==D?(V=(0,$.jsx)(`article`,{className:E,role:`button`,tabIndex:0,"aria-label":D,"data-assistant-contact-card":`session`,onClick:C,onKeyDown:T,children:B}),t[29]=T,t[30]=C,t[31]=B,t[32]=E,t[33]=D,t[34]=V):V=t[34],V};function en(e){return!!(e&&e.trim())}var tn=2,nn=1500,rn=e=>({scrollTop:e.scrollTop,scrollHeight:e.scrollHeight,clientHeight:e.clientHeight}),an=e=>e.scrollHeight-e.scrollTop-e.clientHeight,on=e=>an(e)<=tn,sn=(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},cn=e=>e.altKey||e.ctrlKey||e.metaKey?!1:e.key===`ArrowDown`||e.key===`PageDown`||e.key===`End`,ln=({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=O(()=>{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=O(()=>{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=O(()=>{l.current=!1,p.current=i.current?.scrollTop??0,y()}),S=O(()=>{if(!g.current||!l.current)return!1;let e=i.current;if(!e)return!1;let t=rn(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):on(t)?(p.current=t.scrollTop,!1):(e.scrollTop=e.scrollHeight,p.current=e.scrollTop,!0)}),C=O(e=>{h.current={direction:e,expiresAt:performance.now()+nn}}),w=O(()=>{let e=h.current;return e?performance.now()>e.expiresAt?(h.current=null,null):e.direction:null}),T=O(()=>{l.current=!1,y()}),D=O(()=>{if(!g.current)return;let e=i.current;if(!e)return;let t=rn(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&&T();return}let o=w();y(),t.scrollTop<=80&&o===`up`&&r?.(),n&&on(t)&&(o===`down`||o===`scrollbar`)&&(l.current=!0)}),A=O(e=>{let t=i.current;if(!(!t||e.deltaY===0)){if(e.deltaY<0){if(Oe(t,e.target))return;C(`up`),T(),t.scrollTop<=80&&r?.();return}sn(t,e.target)||C(`down`)}}),j=O(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=O(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&&Oe(t,e.target)||l<0&&sn(t,e.target)){m.current.deltaX=0,m.current.deltaY=0;return}C(l>0?`up`:`down`),l>2&&(T(),t.scrollTop<=80&&r?.())}}),N=O(()=>{m.current=null}),P=O(e=>{if(be(e)){C(`up`),T(),(i.current?.scrollTop??1/0)<=80&&r?.();return}cn(e)&&C(`down`)}),F=O(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}),[]);k(`scroll`,D,L,R),k(`wheel`,A,L,R),k(`touchstart`,j,L,R),k(`touchmove`,M,L,R),k(`touchend`,N,L,R),k(`touchcancel`,N,L,R),k(`keydown`,P,L),k(`pointerdown`,F,L,R);let z=O(()=>{S(),b()});return E(typeof ResizeObserver<`u`&&e?s:null,z),{scrollRef:_,contentRef:v,preparePrepend:x}},un=64,dn=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)},fn=e=>Array.from(e?.files||[]),pn=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}},mn=(e,t)=>{let n=[...e,...t];for(let e of n.slice(un))e.url.startsWith(`blob:`)&&URL.revokeObjectURL(e.url);return n.slice(0,un)},hn=Le(()=>x(()=>import(`./ToolOutputDialog-4DC5OE1J.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52]))),gn=e=>e.trim().startsWith(`oc.settle.`),_n=({assistant:e,warning:t,active:n,overlayHeader:r=!1})=>{let{t:i}=A(),a=ze(),o=y(e=>e.isMobile),s=z(),c=re(),l=I(e.id,n),u=y(e=>e.isSettingsDialogOpen),f=n&&!u&&!l.hasMessageGap?F(e,l.data):null,p=N(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?N(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,E]=Q.useState([]),[D,k]=Q.useState([]),[L,B]=Q.useState(null),[H,te]=Q.useState({open:!1,title:``,content:``}),W=y(e=>e.setImagePreviewOpen),ne=O(e=>{(e.image||e.mermaid)&&(te(e),W(!0))}),ie=O(e=>{te(t=>({...t,open:e})),W(e)});Q.useEffect(()=>()=>{W(!1)},[W]);let ae=Q.useRef(!1);Q.useEffect(()=>{S.current.clear(),x.current=null,E([]),k([]),B(null)},[a]);let se=Q.useMemo(()=>Rt(),[]),ce=Q.useRef(new Set),le=Q.useRef(new Map),G=tt(e=>e.setWorking),K=l.data?.messages??bt,q=Ct(T,e.id),ue=wt(D,e.id),de=Dt(K,q,e.id,ue).filter(e=>{let t=Array.isArray(e.parts)?e.parts:[];return t.length===0||t.some(e=>!(e.type===`text`&&gn(e.text)))}),J=Bt(q),Y=Vt(ue),X=!!(e.working||e.activeContactTurn),fe=c.data?.revision??null,pe=ue.reduce((e,t)=>e+t.bubbles.reduce((e,t)=>e+t.text.length,0),0),me=new Map(ue.map(e=>[e.turnID,e])),he=Q.useRef(!1),ge=O(async(e=!1)=>{if(!(!n||he.current||l.isFetchingPreviousPage||l.isFillingMessageGap)&&!(e&&l.previousPageError)&&!(!l.hasPreviousPage&&!l.hasMessageGap)){he.current=!0,ye();try{l.hasMessageGap?await l.retryMessageGap():await l.fetchPreviousPage()}catch{}finally{he.current=!1}}}),{scrollRef:_e,contentRef:ve,preparePrepend:ye}=ln({active:n,assistantID:e.id,contentRevision:`${de[0]?.messageID}:${de.length}:${pe}:${l.isFetchingPreviousPage}:${l.hasPreviousPage}:${l.isFillingMessageGap}`,onLoadEarlier:()=>{ge(!0)}});Q.useEffect(()=>{B(null),ce.current.clear(),le.current=new Map,E(t=>Ct(t,e.id)),k(t=>wt(t,e.id)),te({open:!1,title:``,content:``}),W(!1)},[e.id,W]),Q.useEffect(()=>{E(e=>Ot(e,K))},[K]),Q.useEffect(()=>{let t=new Set(q.filter(e=>e.status===`sending`).map(e=>e.messageID));k(n=>Mt(n,{assistantID:e.id,activeContactTurn:e.activeContactTurn?{turnID:e.activeContactTurn.turnID,admittedAt:e.activeContactTurn.admittedAt}:null,serverWorking:X,snapshotRevision:fe,admissionRevisionByTurnID:le.current,pendingSendTurnIDs:t,messages:K,settledTurnIDs:ce.current}))},[e.activeContactTurn,e.id,K,q,X,fe]),Q.useEffect(()=>{G(e.id,J||Y||X)},[e.id,Y,J,X,G]),Q.useEffect(()=>{let t=e.id;return()=>{G(t,!1)}},[e.id,G]);let be=O(t=>{if(!(!(`assistantID`in t)||t.assistantID!==e.id)){if(t.type===`contact-turn-start`){ce.current.delete(t.turnID),k(e=>At(e,t.assistantID,t.turnID,t.occurredAt));return}if(t.type===`contact-bubble-delta`){if(ce.current.has(t.turnID))return;k(e=>Nt(e,t));return}t.type===`contact-turn-end`&&(ce.current.add(t.turnID),k(e=>Ft(Pt(e,t,{requireExisting:!0}),K)))}});Q.useEffect(()=>{if(n)return oe(be)},[n,e.id]);let xe=O(async e=>{if(J)return;let t=C.current,n=await pn(e);if(t.signal.aborted){n.attachments.forEach(e=>URL.revokeObjectURL(e.url));return}n.skippedTooLarge>0&&B(i(`assistants.contact.attachment.tooLarge`)),n.attachments.length!==0&&b(e=>mn(e,n.attachments))}),Se=O(e=>{let t=dn(e.clipboardData);t.length!==0&&(e.preventDefault(),xe(t))}),Ce=O(e=>{Array.from(e.dataTransfer?.types??[]).includes(`Files`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)}),we=O(e=>{let t=fn(e.dataTransfer);t.length!==0&&(e.preventDefault(),xe(t))}),Te=O(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=zt({gate:se,sending:Bt(q),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},E(e=>[...e.filter(e=>e.messageID!==l.messageID),l.turn]),B(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 Je(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];E(e=>e.map(e=>e.messageID===l.messageID?{...e,parts:n}:e));let i=await R(a,l.messageID,{parts:n});if(t.signal.aborted)return;u(),typeof i.revision==`number`&&le.current.set(l.messageID,i.revision),E(e=>kt(e,l.messageID)),ce.current.has(l.messageID)||k(e=>At(e,a,l.messageID)),s.data?.serverInstanceID&&P({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 V&&e.code===`admission_timeout`)try{let e=await ee(a,l.messageID);if(t.signal.aborted)return;if(e){u(),typeof e.revision==`number`&&le.current.set(l.messageID,e.revision),E(e=>kt(e,l.messageID)),ce.current.has(l.messageID)||k(e=>At(e,a,l.messageID));return}}catch{}let n=Lt(e,{noProvider:i(`assistants.contact.noProvider`),sendFailed:i(`assistants.contact.sendFailed`),timedOut:i(`assistants.contact.timedOut`)});E(e=>It(e,l.messageID,n)),B(n)}finally{se.release()}}),Ee=O(async()=>{if(ae.current)return;ae.current=!0;let t=C.current;B(null);try{await U(e.id,e)}catch(e){t.signal.aborted||B(e instanceof Error?e.message:i(`settings.mcp.page.toast.unexpectedError`))}finally{ae.current=!1}}),De=l.isError&&de.length===0,Oe=l.isSuccess&&de.length===0,ke=new Map(q.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:_e,className:j(`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,De?(0,$.jsxs)(`div`,{ref:ve,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)(et,{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)(Z,{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)(M,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>void l.refetch(),children:i(`chat.history.retry`)})]}):Oe?(0,$.jsxs)(`div`,{ref:ve,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)(et,{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:ve,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)(M,{type:`button`,size:`sm`,variant:`ghost`,disabled:l.isFetchingPreviousPage||l.isFillingMessageGap,onClick:()=>void ge(),children:i(l.isFetchingPreviousPage||l.isFillingMessageGap?`chat.history.loadingMore`:l.previousPageError||l.hasMessageGap?`chat.history.retry`:`chat.history.loadOlder`)})]}):null,de.map((t,n)=>{let r=n>0?de[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?N(g.name):null,v=ke.get(t.messageID),y=me.get(t.turnID),b=t.status===`admitted`&&t.messageID.endsWith(`:preview:admitted`),x=t.status===`failed`&&t.messageID.endsWith(`:preview:failed`);return t.status===`error`||x?(0,$.jsxs)(`div`,{"data-message-id":t.messageID,"data-assistant-contact-error":``,className:`mt-3 px-1`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap typography-micro text-[var(--status-error)] [overflow-wrap:anywhere]`,children:t.text||y?.error||i(`assistants.contact.sendFailed`)}),f?.messageID===t.messageID?(0,$.jsx)(it,{assistantID:e.id,position:f},`${a}:${e.id}:${f.generation}:${f.ordinal}`):null]},t.messageID):(0,$.jsxs)(`div`,{"data-message-id":t.messageID,className:j(`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)(et,{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:j(`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)($t,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`assistant`)return(0,$.jsx)(Kt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`card`&&n.cardType===`schedule`)return(0,$.jsx)(qt,{card:n},`${t.messageID}:card:${r}`);if(n.type===`file`)return(0,$.jsx)(yt,{assistantID:e.id,part:n,onShowPopup:ne},`${t.messageID}:file:${r}`);if(n.type===`text`&&gn(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:j(`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`:j(`bg-[var(--surface-muted)] text-foreground`,l&&`rounded-tl-lg`)),children:[e?(0,$.jsx)(Re,{content:n.text,messageId:t.messageID,isAnimated:!1,isStreaming:t.status===`streaming`,variant:`assistant`,enableFileReferences:!1,onShowPopup:ne,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,f?.messageID===t.messageID?(0,$.jsx)(it,{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)(M,{type:`button`,size:`sm`,variant:`ghost`,disabled:J,onClick:()=>void Te(),children:i(`chat.history.retry`)}):null]}):null,(0,$.jsx)(`form`,{className:j(`relative w-full pt-1.5 pb-4`,o&&`bottom-safe-area oc-mobile-composer`),onSubmit:e=>{e.preventDefault(),Te()},onDragOver:Ce,onDrop:we,children:(0,$.jsx)(`div`,{className:`chat-input-column relative overflow-visible`,children:(0,$.jsx)(pt,{active:n,layout:`inline`,value:g,attachments:v,pending:J,working:Y||X,onStop:Y||X?()=>{Ee()}: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:()=>{Te()},onAddFiles:e=>{xe(e)},onRemoveAttachment:t=>{J||(S.current.delete(`${e.id}:${t}`),x.current=null,b(e=>e.filter(e=>e.id!==t)))},onPaste:Se,onDragOver:Ce,onDrop:we,className:j(`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}`)})})]}),H.open?(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(hn,{popup:H,onOpenChange:ie,isMobile:o})}):null]})};async function vn(e){await L(e);let t=K.getState().defaultShareAssistant;if(t?.assistantID!==e.id)return;let n=await te();n.serverInstanceID&&t.serverInstanceID===n.serverInstanceID&&K.getState().setDefaultShareAssistant(null)}function yn({assistant:e,open:t,onOpenChange:n,onDeleted:r}){let{t:i}=A(),[a,o]=Q.useState(!1),s=e?N(e.name).displayName||e.name:``,c=O(e=>{a&&!e||n(e)}),l=O(()=>{a||n(!1)}),u=O(async()=>{if(!(!e||a)){o(!0);try{await vn(e),r?.(e.id),n(!1),C.success(i(`assistants.settings.toast.deleted`))}catch{C.error(i(`assistants.settings.toast.deleteFailed`))}finally{o(!1)}}});return(0,$.jsx)(pe,{open:t&&e!==null,onOpenChange:c,children:(0,$.jsxs)(Y,{className:`max-w-md`,children:[(0,$.jsxs)(de,{children:[(0,$.jsx)(X,{children:i(`assistants.settings.delete`)}),(0,$.jsx)(fe,{children:i(`assistants.settings.deleteConfirm`,{name:s})})]}),(0,$.jsxs)(J,{children:[(0,$.jsx)(M,{size:`sm`,variant:`ghost`,onClick:l,disabled:a,children:i(`settings.common.actions.cancel`)}),(0,$.jsx)(M,{size:`sm`,variant:`destructive`,onClick:u,disabled:a,children:i(`settings.common.actions.delete`)})]})]})})}var bn=`line-clamp-2 min-w-0 max-w-full overflow-clip whitespace-normal [overflow-wrap:anywhere] typography-micro text-muted-foreground`,xn={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 Sn(e,t){return e?.text.replace(/\s+/gu,` `).trim()||t(e?.fallbackKind?xn[e.fallbackKind]:`assistants.contact.empty`)}var Cn=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`,wn=t({AssistantView:()=>Dn}),Tn=e=>{let t=(0,Ze.c)(22),{assistant:n,onBack:r,onOpenSettings:i}=e,{t:a}=A(),o=_e(),s;t[0]===n?s=t[1]:(s=n?N(n.name):null,t[0]=n,t[1]=s);let c=s,l=n&&c?c.displayName||n.name:``,u;t[2]!==n||t[3]!==o||t[4]!==i?(u=()=>{if(n){if(i){i(n.id);return}ue(n.id,o?{openMobileSettings:o.openSettings}:void 0)}},t[2]=n,t[3]=o,t[4]=i,t[5]=u):u=t[5];let d=O(u),f;t[6]!==n||t[7]!==l||t[8]!==c?.avatarEmoji||t[9]!==a?(f=n?(0,$.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-2.5`,children:[(0,$.jsx)(et,{name:n.id,emoji:c?.avatarEmoji,size:28,label:l}),(0,$.jsx)(`span`,{className:`truncate font-medium tracking-[-0.01em]`,children:l||a(`assistants.title`)})]}):l||a(`assistants.title`),t[6]=n,t[7]=l,t[8]=c?.avatarEmoji,t[9]=a,t[10]=f):f=t[10];let p;t[11]===a?p=t[12]:(p=a(`assistants.actions.backToChat`),t[11]=a,t[12]=p);let m;t[13]!==n||t[14]!==d||t[15]!==a?(m=n?[{icon:`settings-3`,ariaLabel:a(`assistants.conversation.openSettings`),onClick:d}]:[],t[13]=n,t[14]=d,t[15]=a,t[16]=m):m=t[16];let h;return t[17]!==r||t[18]!==f||t[19]!==p||t[20]!==m?(h=(0,$.jsx)(W,{title:f,backAriaLabel:p,onBack:r,actions:m,overlay:!0}),t[17]=r,t[18]=f,t[19]=p,t[20]=m,t[21]=h):h=t[21],h},En=e=>{let t=(0,Ze.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=rt(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=O(v),b;t[2]===f?b=t[3]:(b=()=>{_(!1),f()},t[2]=f,t[3]=b);let x=O(b),S;t[4]===p?S=t[5]:(S=()=>{_(!1),p()},t[4]=p,t[5]=S);let C=O(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`,E=!c&&`opacity-65`,D;t[7]!==T||t[8]!==E?(D=j(`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,E),t[7]=T,t[8]=E,t[9]=D):D=t[9];let k;t[10]!==y||t[11]!==s||t[12]!==D?(k=(0,$.jsx)(`button`,{type:`button`,role:`option`,"aria-selected":s,onClick:y,onContextMenu:w,className:D}),t[10]=y,t[11]=s,t[12]=D,t[13]=k):k=t[13];let A;t[14]!==i||t[15]!==o||t[16]!==a||t[17]!==h?(A=(0,$.jsx)(et,{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 M;t[19]===a?M=t[20]:(M=(0,$.jsx)(`span`,{className:`block truncate typography-ui-label font-medium`,children:a}),t[19]=a,t[20]=M);let N;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(N=j(bn,`mt-1.5`),t[21]=N):N=t[21];let P;t[22]===r?P=t[23]:(P=(0,$.jsx)(`span`,{className:N,children:r}),t[22]=r,t[23]=P);let F;t[24]!==M||t[25]!==P?(F=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[M,P]}),t[24]=M,t[25]=P,t[26]=F):F=t[26];let I;t[27]===n?I=t[28]:(I=(0,$.jsx)(Ve,{count:n}),t[27]=n,t[28]=I);let L;t[29]!==A||t[30]!==F||t[31]!==I||t[32]!==k?(L=(0,$.jsxs)(Ue,{render:k,children:[A,F,I]}),t[29]=A,t[30]=F,t[31]=I,t[32]=k,t[33]=L):L=t[33];let R;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(Z,{name:`edit`,className:`size-4`}),t[34]=R):R=t[34];let z;t[35]!==l||t[36]!==x?(z=(0,$.jsxs)(Ke,{onClick:x,children:[R,l]}),t[35]=l,t[36]=x,t[37]=z):z=t[37];let B;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(We,{}),t[38]=B):B=t[38];let V;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(Z,{name:`delete-bin`,className:`size-4`}),t[39]=V):V=t[39];let H;t[40]!==u||t[41]!==C?(H=(0,$.jsxs)(Ke,{onClick:C,className:`text-[var(--status-error)] focus:text-[var(--status-error)] data-[highlighted]:text-[var(--status-error)] [&_svg]:text-[var(--status-error)]`,children:[V,u]}),t[40]=u,t[41]=C,t[42]=H):H=t[42];let U;t[43]!==z||t[44]!==H?(U=(0,$.jsxs)(Ge,{className:`min-w-[10rem]`,children:[z,B,H]}),t[43]=z,t[44]=H,t[45]=U):U=t[45];let ee;return t[46]!==g||t[47]!==L||t[48]!==U?(ee=(0,$.jsxs)(qe,{open:g,onOpenChange:_,children:[L,U]}),t[46]=g,t[47]=L,t[48]=U,t[49]=ee):ee=t[49],ee},Dn=e=>{let t=(0,Ze.c)(118),{activeOverride:i,onMobileBack:a,onMobileOpenSettings:o}=e,{t:s}=A(),{isMobile:c}=he(),l=_e(),u=Q.useSyncExternalStore(n,r,r),d=y(On),f=i??d,p=y(kn),m=c||p,h=z(),g=re(),_=g.data;_?.assistants;let v;t[0]===_?.assistants?v=t[1]:(v=_?.assistants??[],t[0]=_?.assistants,t[1]=v);let b;t[2]===v?b=t[3]:(b=Qe(v),t[2]=v,t[3]=b);let x=b,S;t[4]===u?S=t[5]:(S=e=>e.assistantByTransport[u]??null,t[4]=u,t[5]=S);let C=K(S),w=K(An),T=K(jn),E;t[6]!==C||t[7]!==_?.assistants?(E=_?.assistants.find(e=>e.id===C)??null,t[6]=C,t[7]=_?.assistants,t[8]=E):E=t[8];let D=E,k;t[9]!==w||t[10]!==C||t[11]!==_?(k=()=>{!C&&_?.assistants[0]&&w(_.assistants[0].id)},t[9]=w,t[10]=C,t[11]=_,t[12]=k):k=t[12];let P=_?.assistants,F;t[13]!==w||t[14]!==C||t[15]!==P?(F=[w,C,P],t[13]=w,t[14]=C,t[15]=P,t[16]=F):F=t[16],Q.useEffect(k,F);let I;t[17]!==D||t[18]!==w||t[19]!==C||t[20]!==_?.assistants||t[21]!==g.isSuccess?(I=()=>{g.isSuccess&&C&&!D&&w(_?.assistants[0]?.id??null)},t[17]=D,t[18]=w,t[19]=C,t[20]=_?.assistants,t[21]=g.isSuccess,t[22]=I):I=t[22];let L=_?.assistants,R;t[23]!==D||t[24]!==w||t[25]!==C||t[26]!==g.isSuccess||t[27]!==L?(R=[D,w,C,L,g.isSuccess],t[23]=D,t[24]=w,t[25]=C,t[26]=g.isSuccess,t[27]=L,t[28]=R):R=t[28],Q.useEffect(I,R);let B;t[29]!==l||t[30]!==T?(B=()=>{if(T(),l){l.openSettings();return}let e=y.getState();e.setSettingsPage(`assistants`),e.setSettingsDialogOpen(!0)},t[29]=l,t[30]=T,t[31]=B):B=t[31];let V=O(B),H;t[32]===l?H=t[33]:(H=e=>{ue(e,l?{openMobileSettings:l.openSettings}:void 0)},t[32]=l,t[33]=H);let U=O(H),ee;t[34]!==D||t[35]!==l?(ee=()=>{D&&ue(D.id,l?{openMobileSettings:l.openSettings}:void 0)},t[34]=D,t[35]=l,t[36]=ee):ee=t[36];let te=O(ee),[W,ne]=Q.useState(null),ie;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>{ne(e)},t[37]=ie):ie=t[37];let ae=O(ie),oe;t[38]===Symbol.for(`react.memo_cache_sentinel`)?(oe=e=>{e||ne(null)},t[38]=oe):oe=t[38];let se=O(oe),ce=O(Mn),le;t[39]!==a||t[40]!==ce?(le=()=>{if(a){a();return}ce()},t[39]=a,t[40]=ce,t[41]=le):le=t[41];let G=O(le),q=Cn({capabilityPending:h.isPending,snapshotPending:g.isPending,capabilityError:h.isError,supported:h.data?.supported,capabilityEnabled:h.data?.enabled,snapshotEnabled:_?.enabled,snapshotSettled:g.isSuccess,assistantCount:_?.assistants.length??0,hasAssistant:!!D}),de;t[42]!==D||t[43]!==G||t[44]!==m||t[45]!==o?(de=(e,t,n,r)=>(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[m?(0,$.jsx)(Tn,{assistant:D,onBack:G,onOpenSettings:o}):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)(Z,{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]=G,t[44]=m,t[45]=o,t[46]=de):de=t[46];let J=de;if(q===`loading`){let e;t[47]!==D||t[48]!==G||t[49]!==m||t[50]!==o?(e=m?(0,$.jsx)(Tn,{assistant:D,onBack:G,onOpenSettings:o}):null,t[47]=D,t[48]=G,t[49]=m,t[50]=o,t[51]=e):e=t[51];let n;t[52]===s?n=t[53]:(n=s(`common.loading`),t[52]=s,t[53]=n);let r;t[54]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,$.jsx)(Z,{name:`loader-4`,className:`size-6 animate-spin text-muted-foreground`}),t[54]=r):r=t[54];let i;t[55]===n?i=t[56]:(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[55]=n,t[56]=i);let a;return t[57]!==e||t[58]!==i?(a=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 flex-col`,children:[e,i]}),t[57]=e,t[58]=i,t[59]=a):a=t[59],a}if(q===`unavailable`){let e;return t[60]!==J||t[61]!==s?(e=J(`cloud-off`,s(`assistants.state.unavailable`)),t[60]=J,t[61]=s,t[62]=e):e=t[62],e}if(q===`onboarding`){let e;if(t[63]!==V||t[64]!==J||t[65]!==s){let n=s(`assistants.onboarding.title`),r=s(`assistants.onboarding.description`),i;t[67]===s?i=t[68]:(i=s(`assistants.onboarding.action`),t[67]=s,t[68]=i);let a;t[69]!==V||t[70]!==i?(a=(0,$.jsx)(M,{onClick:V,children:i}),t[69]=V,t[70]=i,t[71]=a):a=t[71],e=J(`ai-agent`,n,r,a),t[63]=V,t[64]=J,t[65]=s,t[66]=e}else e=t[66];return e}if(!_||!D){let e;return t[72]!==J||t[73]!==s?(e=J(`cloud-off`,s(`assistants.state.unavailable`)),t[72]=J,t[73]=s,t[74]=e):e=t[74],e}let Y;t[75]===D.name?Y=t[76]:(Y=N(D.name),t[75]=D.name,t[76]=Y);let X=Y,fe;t[77]!==D.enabled||t[78]!==g.isError||t[79]!==s?(fe=D.enabled?g.isError?s(`assistants.state.staleSnapshot`):null:s(`assistants.state.assistantDisabled`),t[77]=D.enabled,t[78]=g.isError,t[79]=s,t[80]=fe):fe=t[80];let pe=fe,me;t[81]!==x||t[82]!==m||t[83]!==V||t[84]!==U||t[85]!==ae||t[86]!==w||t[87]!==C||t[88]!==_||t[89]!==s?(me=m?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:s(`assistants.title`)}),(0,$.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":s(`assistants.settings.create`),onClick:V,children:(0,$.jsx)(Z,{name:`add`,className:`size-4`})})]}),(0,$.jsx)($e,{snapshot:_,rowClassName:`flex justify-end px-4 pb-2 sm:px-5`}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-3 pb-4 sm:px-4`,role:`listbox`,"aria-label":s(`assistants.listAria`),children:(0,$.jsx)(`div`,{className:`flex flex-col gap-1 border-t border-border/40 pt-3`,children:x.map(e=>{let t=e.id===C,n=N(e.name);return(0,$.jsx)(En,{assistantID:e.id,unreadCount:e.unreadCount??0,summary:Sn(e.latestMessagePreview,s),displayName:n.displayName,avatarEmoji:n.avatarEmoji??void 0,selected:t,enabled:e.enabled,editLabel:s(`assistants.menu.edit`),deleteLabel:s(`assistants.settings.delete`),assignedSessionIDs:e.assignedSessionIDs,serverWorking:e.working,onSelect:()=>w(e.id),onEdit:()=>U(e.id),onDelete:()=>ae(e)},e.id)})})})]}),t[81]=x,t[82]=m,t[83]=V,t[84]=U,t[85]=ae,t[86]=w,t[87]=C,t[88]=_,t[89]=s,t[90]=me):me=t[90];let ge=W!==null,ve;t[91]!==W||t[92]!==se||t[93]!==ge?(ve=(0,$.jsx)(yn,{assistant:W,open:ge,onOpenChange:se}),t[91]=W,t[92]=se,t[93]=ge,t[94]=ve):ve=t[94];let ye=!m&&`border-l border-[var(--surface-subtle)]`,be;t[95]===ye?be=t[96]:(be=j(`relative flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-background`,ye),t[95]=ye,t[96]=be);let xe;t[97]!==D||t[98]!==G||t[99]!==m||t[100]!==o||t[101]!==te||t[102]!==X||t[103]!==s?(xe=m?(0,$.jsx)(Tn,{assistant:D,onBack:G,onOpenSettings:o}):(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)(et,{name:D.id,emoji:X.avatarEmoji,size:30,label:X.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:X.displayName}),(0,$.jsx)(`div`,{className:`mt-1 truncate typography-micro leading-none text-muted-foreground/55`,children:s(`assistants.conversation.contactHint`)})]}),(0,$.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 shrink-0 rounded-full text-muted-foreground/65 transition-colors hover:text-foreground`,onClick:te,"aria-label":s(`assistants.conversation.openSettings`),children:(0,$.jsx)(Z,{name:`settings-3`,className:`size-4`})})]}),t[97]=D,t[98]=G,t[99]=m,t[100]=o,t[101]=te,t[102]=X,t[103]=s,t[104]=xe):xe=t[104];let Se;t[105]!==f||t[106]!==D||t[107]!==m||t[108]!==pe?(Se=(0,$.jsx)(_n,{assistant:D,warning:pe,active:f,overlayHeader:m}),t[105]=f,t[106]=D,t[107]=m,t[108]=pe,t[109]=Se):Se=t[109];let Ce;t[110]!==be||t[111]!==xe||t[112]!==Se?(Ce=(0,$.jsxs)(`div`,{className:be,children:[xe,Se]}),t[110]=be,t[111]=xe,t[112]=Se,t[113]=Ce):Ce=t[113];let we;return t[114]!==me||t[115]!==ve||t[116]!==Ce?(we=(0,$.jsxs)(`div`,{className:`relative flex h-full min-h-0 overflow-hidden bg-background`,"data-presentation":`workspace`,children:[me,ve,Ce]}),t[114]=me,t[115]=ve,t[116]=Ce,t[117]=we):we=t[117],we};function On(e){return e.activeMainTab===`assistant`}function kn(e){return e.isMobile}function An(e){return e.selectAssistant}function jn(e){return e.requestCreate}function Mn(){y.getState().setActiveMainTab(`chat`)}export{yn as a,$e as c,Sn as i,Qe as l,wn as n,rt as o,bn as r,et as s,Dn as t};
|