@openchambery/web 2.0.0-beta.18 → 2.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AgentAvatar-Cxm7uMtK.js → AgentAvatar-DaUKQboA.js} +1 -1
- package/dist/assets/AssistantView-D6DUDRiE.js +3 -0
- package/dist/assets/{DiagramView-CDfSTjyI.js → DiagramView-Dw-czaLC.js} +1 -1
- package/dist/assets/{FadeInOnReveal-FAZTMV12.js → FadeInOnReveal-DHDffzHs.js} +1 -1
- package/dist/assets/{Icon-DKd015RD.js → Icon-D7NdMmbi.js} +1 -1
- package/dist/assets/{MarkdownRenderer-TW-h0HHu.js → MarkdownRenderer-CN--2AqC.js} +2 -2
- package/dist/assets/{MarkdownRendererImpl-BDhsNSZZ.js → MarkdownRendererImpl-B1WPWspj.js} +1 -1
- package/dist/assets/{MarkstreamRendererImpl-CTRQuEcK.js → MarkstreamRendererImpl-Ckt_qgRR.js} +1 -1
- package/dist/assets/{MobileDetailNavigation-Ba4FGle-.js → MobileDetailNavigation-D4vnftwk.js} +1 -1
- package/dist/assets/{MobileShareBridge-CbLWGJA7.js → MobileShareBridge-DYq2g-oS.js} +1 -1
- package/dist/assets/{MobileSurface-C62mL-z4.js → MobileSurface-C4TnOgAf.js} +1 -1
- package/dist/assets/{MultiRunWindow--Kog5jbS.js → MultiRunWindow-Ymr_-Qmo.js} +1 -1
- package/dist/assets/{OnboardingScreen-BGHwdpXe.js → OnboardingScreen-DMbPMwlp.js} +1 -1
- package/dist/assets/{OverlayScrollbar-SUdC3Pqe.js → OverlayScrollbar-mI9WVa7E.js} +1 -1
- package/dist/assets/{SettingsView-DrHDWxUP.js → SettingsView-BKFevwWh.js} +6 -6
- package/dist/assets/{SettingsWindow-Dj3oYcuF.js → SettingsWindow-BrdQkPx7.js} +1 -1
- package/dist/assets/{TerminalView-BrQT3zTi.js → TerminalView-DZv3cE3S.js} +1 -1
- package/dist/assets/{ToolOutputDialog-zTkbimFp.js → ToolOutputDialog-CD8vpktO.js} +1 -1
- package/dist/assets/{appThemeRegistry-Dd-Mc_ae.js → appThemeRegistry-BF1KyXSQ.js} +1 -1
- package/dist/assets/{button-EzCcYrQl.js → button-e8fYWIMM.js} +1 -1
- package/dist/assets/{collapsible-BwvSZkMC.js → collapsible-B6wLXHi3.js} +1 -1
- package/dist/assets/{context-menu-DSrUbCPh.js → context-menu-DtRlVINv.js} +1 -1
- package/dist/assets/{diagram-Brtt6ms7.js → diagram-BBL-LfsC.js} +1 -1
- package/dist/assets/{dialog-Cpu-rKij.js → dialog-GxY2maVf.js} +1 -1
- package/dist/assets/{es-Dsmc0A_3.js → es-DvPwAj0y.js} +2 -2
- package/dist/assets/{fileMentionTouchSelection-CZkJTpTW.js → fileMentionTouchSelection-CgY2F6Gp.js} +1 -1
- package/dist/assets/{fr-C_ZlZDI2.js → fr-XQsoaNKY.js} +2 -2
- package/dist/assets/{gitApi-DDZeOQ0N.js → gitApi-BcT8qbg1.js} +3 -3
- package/dist/assets/{input-DksVnckl.js → input-DbOe1mdT.js} +1 -1
- package/dist/assets/insertionBoundaries-Bud1OmK9.js +1 -0
- package/dist/assets/{ja-BqqTaWTi.js → ja-DslzO96s.js} +2 -2
- package/dist/assets/{ko-DP2XPM37.js → ko-C_9XOAL0.js} +2 -2
- package/dist/assets/{main-B839_vtF.js → main-CHciEnyA.js} +2 -2
- package/dist/assets/main-DqTPajNV.js +169 -0
- package/dist/assets/{markdownHeightCache-emzgqB2K.js → markdownHeightCache-B5VSLl79.js} +1 -1
- package/dist/assets/{mcpQueries-Cirhjpkq.js → mcpQueries-CmFNaqFN.js} +1 -1
- package/dist/assets/{miniChat-B0lH1mgT.js → miniChat-C1m5g6hf.js} +2 -2
- package/dist/assets/{mobile-DCMqyVbF.js → mobile-GLUq93M6.js} +2 -2
- package/dist/assets/multirun-C1nkMAhg.js +4 -0
- package/dist/assets/{pl-BCf5uLlK.js → pl-Dst9Wk53.js} +2 -2
- package/dist/assets/platform-B0p43squ.js +6 -0
- package/dist/assets/{projectMeta-BZj0Lqsc.js → projectMeta-PbrngEg0.js} +2 -2
- package/dist/assets/{pt-BR-W09Q2pvn.js → pt-BR-Dq394BPb.js} +2 -2
- package/dist/assets/renderElectronMiniChatApp-CN87PiN2.js +2 -0
- package/dist/assets/renderMobileApp-CJezPez9.js +28 -0
- package/dist/assets/{runtimeConfig-Dfmu3VWa.js → runtimeConfig-Bv2cTpw0.js} +1 -1
- package/dist/assets/runtimeEndpointReset-CUovP8BH.js +149 -0
- package/dist/assets/{sessionChangeSummary-BUya3rIx.js → sessionChangeSummary-BA50j2H3.js} +1 -1
- package/dist/assets/{sessionLookup-Ba9vzhFN.js → sessionLookup-Du_vHwQj.js} +1 -1
- package/dist/assets/{sortable-tabs-strip-Bc0lATi8.js → sortable-tabs-strip-B0sZ7mm6.js} +1 -1
- package/dist/assets/src-IEGDFexV.css +2 -0
- package/dist/assets/{store-jaP79mqI.js → store-D8fmTWK3.js} +3 -3
- package/dist/assets/{terminalApi-C6zlKnK1.js → terminalApi-CJyWCuc8.js} +1 -1
- package/dist/assets/{textarea-B9pCxe-7.js → textarea-B5GMntHk.js} +1 -1
- package/dist/assets/{tooltip-DwUy2erJ.js → tooltip-C64SdRvR.js} +1 -1
- package/dist/assets/{uk-BgFzz8m2.js → uk-8XAR75Qh.js} +2 -2
- package/dist/assets/{useAppFontEffects-C4YijXq2.js → useAppFontEffects-BulJwD-g.js} +53 -53
- package/dist/assets/useDesktopWindowControlsLayout-Bs17CRxC.js +1 -0
- package/dist/assets/{useEffectiveDirectory-DB10GDme.js → useEffectiveDirectory-BlF5TyvY.js} +1 -1
- package/dist/assets/{useFontPreferences-DFsjAsxC.js → useFontPreferences-CrteQiAp.js} +1 -1
- package/dist/assets/{useMobileNavigationStore-DXxkpRmA.js → useMobileNavigationStore-kKBevqMP.js} +20 -20
- package/dist/assets/{useSessionAutoCleanup-C7ONq7C-.js → useSessionAutoCleanup-BnBioNN4.js} +1 -1
- package/dist/assets/{useWorkerHighlightedLines-DWR_fwgu.js → useWorkerHighlightedLines-BI79F_7z.js} +1 -1
- package/dist/assets/{zh-CN-BhqSLgUY.js → zh-CN-B-ILfrqC.js} +2 -2
- package/dist/assets/{zh-TW-BsaBgY-p.js → zh-TW-5HeTVP4z.js} +2 -2
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +1 -1
- package/server/lib/opencode/DOCUMENTATION.md +3 -2
- package/server/lib/opencode/remote-upgrade.integration.test.js +66 -0
- package/server/lib/opencode/routes.js +5 -3
- package/server/lib/opencode/routes.test.js +41 -0
- package/server/lib/opencode/update-discovery.js +39 -0
- package/server/lib/opencode/update-discovery.test.js +39 -0
- package/dist/assets/AssistantView-CV7caMrh.js +0 -3
- package/dist/assets/insertionBoundaries-6cEF7UND.js +0 -1
- package/dist/assets/main-CboaV0z3.js +0 -169
- package/dist/assets/multirun-D45JAYPn.js +0 -4
- package/dist/assets/platform-BxU3ZvQ0.js +0 -6
- package/dist/assets/renderElectronMiniChatApp-KxK13wGq.js +0 -2
- package/dist/assets/renderMobileApp-DLwJp7Ef.js +0 -28
- package/dist/assets/runtimeEndpointReset-D4tNIDTD.js +0 -149
- package/dist/assets/src-iyTfdRD7.css +0 -2
- package/dist/assets/useDesktopWindowControlsLayout-hhGCbHKE.js +0 -1
package/dist/index.html
CHANGED
|
@@ -552,7 +552,7 @@
|
|
|
552
552
|
opacity: 0.72;
|
|
553
553
|
}
|
|
554
554
|
</style>
|
|
555
|
-
<script type="module" crossorigin src="/assets/main-
|
|
555
|
+
<script type="module" crossorigin src="/assets/main-CHciEnyA.js"></script>
|
|
556
556
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
557
557
|
<link rel="modulepreload" crossorigin href="/assets/runtime-auth-D66yq6ie.js">
|
|
558
558
|
<link rel="modulepreload" crossorigin href="/assets/runtime-switch-BJM2k_uH.js">
|
|
@@ -568,12 +568,12 @@
|
|
|
568
568
|
<link rel="modulepreload" crossorigin href="/assets/desktopRelayRestore-DDJtljeu.js">
|
|
569
569
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-client-C12gfjag.js">
|
|
570
570
|
<link rel="modulepreload" crossorigin href="/assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js">
|
|
571
|
-
<link rel="modulepreload" crossorigin href="/assets/platform-
|
|
572
|
-
<link rel="modulepreload" crossorigin href="/assets/terminalApi-
|
|
571
|
+
<link rel="modulepreload" crossorigin href="/assets/platform-B0p43squ.js">
|
|
572
|
+
<link rel="modulepreload" crossorigin href="/assets/terminalApi-CJyWCuc8.js">
|
|
573
573
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
574
574
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
575
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
576
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
575
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-Bv2cTpw0.js">
|
|
576
|
+
<link rel="stylesheet" crossorigin href="/assets/src-IEGDFexV.css">
|
|
577
577
|
</head>
|
|
578
578
|
<body class="h-full bg-background text-foreground">
|
|
579
579
|
<!-- Keep the startup layer outside #root. React replaces every child of
|
package/dist/mini-chat.html
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
}
|
|
75
75
|
</style>
|
|
76
76
|
|
|
77
|
-
<script type="module" crossorigin src="/assets/miniChat-
|
|
77
|
+
<script type="module" crossorigin src="/assets/miniChat-C1m5g6hf.js"></script>
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/assets/runtime-auth-D66yq6ie.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/runtime-switch-BJM2k_uH.js">
|
|
@@ -90,12 +90,12 @@
|
|
|
90
90
|
<link rel="modulepreload" crossorigin href="/assets/desktopRelayRestore-DDJtljeu.js">
|
|
91
91
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-client-C12gfjag.js">
|
|
92
92
|
<link rel="modulepreload" crossorigin href="/assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js">
|
|
93
|
-
<link rel="modulepreload" crossorigin href="/assets/platform-
|
|
94
|
-
<link rel="modulepreload" crossorigin href="/assets/terminalApi-
|
|
93
|
+
<link rel="modulepreload" crossorigin href="/assets/platform-B0p43squ.js">
|
|
94
|
+
<link rel="modulepreload" crossorigin href="/assets/terminalApi-CJyWCuc8.js">
|
|
95
95
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
96
96
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
97
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
98
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
97
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-Bv2cTpw0.js">
|
|
98
|
+
<link rel="stylesheet" crossorigin href="/assets/src-IEGDFexV.css">
|
|
99
99
|
</head>
|
|
100
100
|
<body class="h-full bg-background text-foreground">
|
|
101
101
|
<div id="root" class="h-full">
|
package/dist/mobile.html
CHANGED
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
})();
|
|
64
64
|
</script>
|
|
65
65
|
|
|
66
|
-
<script type="module" crossorigin src="/assets/mobile-
|
|
66
|
+
<script type="module" crossorigin src="/assets/mobile-GLUq93M6.js"></script>
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-C0FnF6B9.js">
|
|
68
68
|
<link rel="modulepreload" crossorigin href="/assets/runtime-auth-D66yq6ie.js">
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/assets/runtime-switch-BJM2k_uH.js">
|
|
@@ -79,12 +79,12 @@
|
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/assets/desktopRelayRestore-DDJtljeu.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/assets/vendor-opencode-client-C12gfjag.js">
|
|
81
81
|
<link rel="modulepreload" crossorigin href="/assets/vendor-aparajita-capacitor-secure-storage-CjQdwfjS.js">
|
|
82
|
-
<link rel="modulepreload" crossorigin href="/assets/platform-
|
|
83
|
-
<link rel="modulepreload" crossorigin href="/assets/terminalApi-
|
|
82
|
+
<link rel="modulepreload" crossorigin href="/assets/platform-B0p43squ.js">
|
|
83
|
+
<link rel="modulepreload" crossorigin href="/assets/terminalApi-CJyWCuc8.js">
|
|
84
84
|
<link rel="modulepreload" crossorigin href="/assets/types-BuiqMmh_.js">
|
|
85
85
|
<link rel="modulepreload" crossorigin href="/assets/capgoAdapter-DCowZ2ab.js">
|
|
86
|
-
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-
|
|
87
|
-
<link rel="stylesheet" crossorigin href="/assets/src-
|
|
86
|
+
<link rel="modulepreload" crossorigin href="/assets/runtimeConfig-Bv2cTpw0.js">
|
|
87
|
+
<link rel="stylesheet" crossorigin href="/assets/src-IEGDFexV.css">
|
|
88
88
|
</head>
|
|
89
89
|
<body class="h-full bg-background text-foreground">
|
|
90
90
|
<div id="root" class="h-full"></div>
|
package/package.json
CHANGED
|
@@ -87,8 +87,8 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
87
87
|
- `GET /api/config/opencode-resolution`
|
|
88
88
|
- `GET /api/behavior/agents-md`: returns an authoritative empty document only when the file is absent (`ENOENT`); permission and I/O failures return HTTP 500.
|
|
89
89
|
- `PUT /api/behavior/agents-md`
|
|
90
|
-
- `POST /api/opencode/upgrade` (ticket 12): installs the
|
|
91
|
-
|
|
90
|
+
- `POST /api/opencode/upgrade` (ticket 12): installs the remote latest or explicitly targeted `@opencode/cli` into the **owned cache** at `~/.config/openchamber/opencode-cli/<version>/`. Managed owned-cache processes restart on that binary; official shared services use that exact binary's `service restart`, then adopt its registration again. Success requires a fresh running-serve version probe and runtime contract verification. Arbitrary external servers, private processes using global CLI, and private bundled binaries return HTTP 409; user installs are never overwritten. Concurrent upgrades are single-flight (`operation` state). Active sessions require `confirmActiveTasks`/`force`. Failure preserves cached binaries, restores the previous binary selection, and reports the failed phase; it does not claim the old process was restored. Shared-service recovery can subsequently re-ensure the registered service.
|
|
91
|
+
- `GET /api/opencode/upgrade-status`: returns `currentVersion`/`serveVersion`/`cliVersion`, `targetVersion`/`latestVersion` (official npm `@opencode/cli` latest stable 2.x release), `supplySource`, `ownership`, `canManage`, `management`, `guidance`, `contract`, and `operation`. Official shared services report `ownership: 'shared-service'`, `processOwnership: 'shared'`, and `canManage: true`. `available` is true only when `canManage` and target > current; unmanaged global/external runtimes report `available: null` plus manual guidance. `update-discovery.js` shares one in-flight registry request per host, caches successful checks for five minutes and failed checks for thirty seconds, with a five-second request deadline. Failed registry checks return HTTP 500 with `available: null`, never a false up-to-date result. An upgrade without an explicit target resolves this same remote release. Shared Web/Electron/hosted-mobile/Capacitor clients check after startup, every five minutes while visible, on focus/reconnect, and on runtime changes; query results and dismissed notifications are scoped to the host. Successful upgrade already includes process restart and live version verification, so no second reload is needed.
|
|
92
92
|
- `GET /api/opencode/compatibility`: startup upgrade-screen status. `state` is `compatible` at OpenCode `2.0.15` or newer, `incompatible` when a detected version is older or not 2.x, and `unavailable` when no version could be read. `canInstall` is true only for a local (managed or bundled) runtime this platform can install into the owned cache. External serves are reported and not replaced.
|
|
93
93
|
- `POST /api/opencode/install-required`: installs the upgrade-screen target (`2.0.15`, or the pin when the pin is newer) into the owned cache and restarts through the existing lifecycle. `upgraded: true` only after the running serve verifies at or above that target. Failure is `upgraded: false` plus `error`. Concurrent installs are single-flight.
|
|
94
94
|
- `GET /api/opencode/contract` (ticket 11): runtime contract admission for the **running serve** (not health alone). Dimensions: reachable / authenticated / protocolCompatible / executionAllowed / capabilities / migration / CLI↔serve mismatch. Floor `2.0.12` (acceptable OpenCode 2.x at or above); below-min 2.x and 1.x block execution with upgrade guidance; no upper version cap.
|
|
@@ -180,6 +180,7 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
180
180
|
- `startSharedOpenCodeService({ binary, args, env, spawnImpl, timeoutMs, replace })`: runs `<binary> [...args] service start`, or `service restart` for explicit `replace: true`; rejects with the stderr tail on non-zero exit or timeout. The launcher has hidden Windows console and does not own the detached service lifetime.
|
|
181
181
|
- `isProcessAlive(pid)`, `createSharedOpenCodeService({ envLike, fsLike, spawnImpl })`: the lifecycle dependency (`start`, `readRegistration`, `buildStartEnv`).
|
|
182
182
|
- `shared-service.integration.test.js` is opt-in via `OPENCHAMBER_TEST_OPENCODE_BINARY`; it isolates HOME/XDG/config/database and verifies launcher exit survival, PID reuse, explicit replacement and authenticated health, then stops only its isolated service.
|
|
183
|
+
- `remote-upgrade.integration.test.js` is opt-in via `OPENCHAMBER_TEST_REMOTE_UPGRADE=1`; it downloads official binaries, starts an isolated 2.0.16 shared service, discovers the remote latest release through the status route, upgrades through the HTTP route, and verifies the running version and cleared update availability. It never restarts the user's shared service.
|
|
183
184
|
|
|
184
185
|
## Public exports (env-runtime.js)
|
|
185
186
|
- `createOpenCodeEnvRuntime(dependencies)`: creates runtime that owns OpenCode CLI environment and binary discovery state. Discovery order: settings/env, then PATH `opencode`, then known install locations, then a previously installed pin under the OpenChamber data dir. Automatic discovery and bundled resources use only `opencode` (`opencode.exe` on Windows); 1.x binaries are skipped by `--version`, not by basename. `resolveOpencodeCliPath()` never prefers a packaged/bundled Electron extraResource. Managed startup calls `ensurePinnedOpenCode2CliEnv()` and installs the pin only when no usable 2.x CLI exists; if pin install fails (or auto-install is disabled), it may last-resort to a 2.x binary under `OPENCHAMBER_BUNDLED_OPENCODE_CLI_DIR` or `process.resourcesPath/opencode-cli` (source `bundled`). Explicit `OPENCODE_BINARY` that reports 1.x fails closed with `OPENCODE_BINARY_INVALID`. Bootstrap reuses a healthy v2 `opencode serve` on port 4096 when present; otherwise it starts generic `opencode serve`.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { expect, test } from 'vitest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import request from 'supertest';
|
|
4
|
+
import { execFile, spawn } from 'node:child_process';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import fs from 'node:fs/promises';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import net from 'node:net';
|
|
10
|
+
import { createOpenCodeUpdateDiscovery } from './update-discovery.js';
|
|
11
|
+
import { installPinnedOpenCode2Cli } from './ensure-cli.js';
|
|
12
|
+
import { createSharedOpenCodeService } from './shared-service.js';
|
|
13
|
+
import { registerOpenCodeRoutes } from './routes.js';
|
|
14
|
+
|
|
15
|
+
// Downloads real official binaries; never touches the user's shared service.
|
|
16
|
+
test.skipIf(process.env.OPENCHAMBER_TEST_REMOTE_UPGRADE !== '1')('remote discovery upgrades an isolated shared service and verifies its running version', async () => {
|
|
17
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'opencode-upgrade-'));
|
|
18
|
+
const env = {
|
|
19
|
+
PATH: process.env.PATH, HOME: root, TMPDIR: os.tmpdir(),
|
|
20
|
+
XDG_CONFIG_HOME: path.join(root, 'config'), XDG_DATA_HOME: path.join(root, 'data'),
|
|
21
|
+
XDG_STATE_HOME: path.join(root, 'state'), XDG_CACHE_HOME: path.join(root, 'cache'),
|
|
22
|
+
OPENCODE_CONFIG_DIR: path.join(root, 'config', 'opencode'), OPENCODE_DISABLE_MODELS_FETCH: '1',
|
|
23
|
+
};
|
|
24
|
+
await fs.mkdir(env.OPENCODE_CONFIG_DIR, { recursive: true });
|
|
25
|
+
const listener = net.createServer();
|
|
26
|
+
await new Promise((resolve) => listener.listen(0, '127.0.0.1', resolve));
|
|
27
|
+
const port = listener.address().port;
|
|
28
|
+
await new Promise((resolve) => listener.close(resolve));
|
|
29
|
+
await fs.writeFile(path.join(env.OPENCODE_CONFIG_DIR, 'service.json'), JSON.stringify({ hostname: '127.0.0.1', port }));
|
|
30
|
+
const service = createSharedOpenCodeService({ envLike: env, spawnImpl: (command, args, options) => spawn(command, args, { ...options, cwd: root }) });
|
|
31
|
+
let binary;
|
|
32
|
+
let registration;
|
|
33
|
+
try {
|
|
34
|
+
const target = await createOpenCodeUpdateDiscovery()();
|
|
35
|
+
expect(target).not.toBe('2.0.16');
|
|
36
|
+
binary = await installPinnedOpenCode2Cli({ version: '2.0.16', dataDir: root });
|
|
37
|
+
await service.start({ binary, env });
|
|
38
|
+
registration = await service.readRegistration();
|
|
39
|
+
expect(registration.version).toBe('2.0.16');
|
|
40
|
+
const app = express();
|
|
41
|
+
app.use(express.json());
|
|
42
|
+
registerOpenCodeRoutes(app, {
|
|
43
|
+
getIsExternalOpenCode: () => true, getIsSharedOpenCodeService: () => true,
|
|
44
|
+
getResolvedOpenCodeBinary: () => binary, getResolvedOpenCodeBinarySource: () => 'installed',
|
|
45
|
+
readSettingsFromDiskMigrated: async () => ({}),
|
|
46
|
+
getOpenCodeResolutionSnapshot: async () => ({ source: 'installed', resolved: binary }),
|
|
47
|
+
buildOpenCodeUrl: (pathname) => `${registration.origin}${pathname}`,
|
|
48
|
+
getOpenCodeAuthHeaders: () => ({ Authorization: `Basic ${Buffer.from(`opencode:${registration.password}`).toString('base64')}` }),
|
|
49
|
+
forceResolvedOpenCodeBinary: (value) => { binary = value; },
|
|
50
|
+
restartOpenCode: async ({ binaryPath }) => {
|
|
51
|
+
await service.start({ binary: binaryPath, env, replace: true });
|
|
52
|
+
registration = await service.readRegistration();
|
|
53
|
+
},
|
|
54
|
+
openchamberDataDir: root,
|
|
55
|
+
});
|
|
56
|
+
const before = await request(app).get('/api/opencode/upgrade-status').expect(200);
|
|
57
|
+
expect(before.body).toMatchObject({ available: true, targetVersion: target });
|
|
58
|
+
const upgrade = await request(app).post('/api/opencode/upgrade').send({ target }).expect(200);
|
|
59
|
+
expect(upgrade.body).toMatchObject({ success: true, restarted: true, version: target });
|
|
60
|
+
const after = await request(app).get('/api/opencode/upgrade-status').expect(200);
|
|
61
|
+
expect(after.body).toMatchObject({ available: false, serveVersion: target });
|
|
62
|
+
} finally {
|
|
63
|
+
if (binary) await promisify(execFile)(binary, ['service', 'stop'], { env, cwd: root, timeout: 20_000, windowsHide: true });
|
|
64
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
65
|
+
}
|
|
66
|
+
}, 180_000);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createProjectIdFromPath } from '../projects/project-id.js';
|
|
2
2
|
import { projectBootstrapSettingsResponse } from './settings-helpers.js';
|
|
3
3
|
import {
|
|
4
|
-
PINNED_OPENCODE2_VERSION,
|
|
5
4
|
evaluateOpenCodeHealthBody,
|
|
6
5
|
isOpenCode1xVersion,
|
|
7
6
|
resolveOpenCode2UpgradeTarget,
|
|
@@ -13,6 +12,7 @@ import {
|
|
|
13
12
|
} from './ensure-cli.js';
|
|
14
13
|
import { registerUpgradeScreenRoutes } from './upgrade-screen.js';
|
|
15
14
|
import { evaluateRuntimeContract } from './runtime-contract.js';
|
|
15
|
+
import { createOpenCodeUpdateDiscovery } from './update-discovery.js';
|
|
16
16
|
import {
|
|
17
17
|
buildUpgradeStatusSnapshot,
|
|
18
18
|
classifyRuntimeOwnership,
|
|
@@ -54,6 +54,7 @@ export const registerOpenCodeRoutes = (app, dependencies) => {
|
|
|
54
54
|
getResolvedOpenCodeBinarySource = () => null,
|
|
55
55
|
getActiveSessionCount = () => 0,
|
|
56
56
|
openchamberDataDir = null,
|
|
57
|
+
discoverOpenCodeUpdate = createOpenCodeUpdateDiscovery(),
|
|
57
58
|
} = dependencies;
|
|
58
59
|
|
|
59
60
|
const upgradeOperation = createUpgradeOperationState();
|
|
@@ -156,12 +157,13 @@ export const registerOpenCodeRoutes = (app, dependencies) => {
|
|
|
156
157
|
const buildUpgradeStatus = async () => {
|
|
157
158
|
const ownership = await resolveOwnershipContext();
|
|
158
159
|
const contract = await buildLiveContract();
|
|
160
|
+
const targetVersion = await discoverOpenCodeUpdate();
|
|
159
161
|
const activeCount = typeof getActiveSessionCount === 'function' ? Number(getActiveSessionCount()) || 0 : 0;
|
|
160
162
|
return buildUpgradeStatusSnapshot({
|
|
161
163
|
ownership,
|
|
162
164
|
serveVersion: contract.serveVersion,
|
|
163
165
|
cliVersion: contract.cliVersion,
|
|
164
|
-
targetVersion
|
|
166
|
+
targetVersion,
|
|
165
167
|
contract,
|
|
166
168
|
operation: upgradeOperation.getState(),
|
|
167
169
|
hasActiveTasks: activeCount > 0,
|
|
@@ -342,7 +344,7 @@ export const registerOpenCodeRoutes = (app, dependencies) => {
|
|
|
342
344
|
errorCode: 'OPENCODE_UPGRADE_1X_REFUSED',
|
|
343
345
|
});
|
|
344
346
|
}
|
|
345
|
-
const target = resolveOpenCode2UpgradeTarget(rawTarget);
|
|
347
|
+
const target = resolveOpenCode2UpgradeTarget(rawTarget ?? (await buildUpgradeStatus()).targetVersion);
|
|
346
348
|
const confirmActive = req.body?.confirmActiveTasks === true || req.body?.force === true;
|
|
347
349
|
const activeCount = typeof getActiveSessionCount === 'function' ? Number(getActiveSessionCount()) || 0 : 0;
|
|
348
350
|
if (activeCount > 0 && !confirmActive) {
|
|
@@ -15,8 +15,10 @@ vi.mock('./ensure-cli.js', async (importOriginal) => {
|
|
|
15
15
|
|
|
16
16
|
import { registerOpenCodeRoutes } from './routes.js';
|
|
17
17
|
import { isOpenCode1xVersion } from './opencode2-pin.js';
|
|
18
|
+
import { createOpenCodeUpdateDiscovery } from './update-discovery.js';
|
|
18
19
|
|
|
19
20
|
const createDependencies = ({ formatSettingsResponse }) => ({
|
|
21
|
+
discoverOpenCodeUpdate: async () => '2.0.12',
|
|
20
22
|
crypto: {},
|
|
21
23
|
clientReloadDelayMs: 0,
|
|
22
24
|
getOpenCodeResolutionSnapshot: vi.fn(),
|
|
@@ -253,6 +255,45 @@ describe('opencode2 upgrade pin (ticket 12)', () => {
|
|
|
253
255
|
expect(response.body).toMatchObject({ success: true, version: '2.0.14', ownership: 'shared-service' });
|
|
254
256
|
});
|
|
255
257
|
|
|
258
|
+
it('discovers the remote release and updates a shared 2.0.16 service to 2.0.18', async () => {
|
|
259
|
+
let serveVersion = '2.0.16';
|
|
260
|
+
let binary = '/usr/local/bin/opencode';
|
|
261
|
+
const installed = '/cache/opencode-cli/2.0.18/opencode';
|
|
262
|
+
const fetchMock = vi.fn(async (url) => new Response(JSON.stringify({
|
|
263
|
+
version: String(url).includes('registry.npmjs.org') ? '2.0.18' : serveVersion,
|
|
264
|
+
})));
|
|
265
|
+
vi.stubGlobal('fetch', fetchMock);
|
|
266
|
+
vi.mocked(readOpenCode2BinaryVersion).mockReturnValue('2.0.18');
|
|
267
|
+
vi.mocked(installPinnedOpenCode2Cli).mockResolvedValueOnce(installed);
|
|
268
|
+
const restartOpenCode = vi.fn(async () => { serveVersion = '2.0.18'; });
|
|
269
|
+
const { app } = createUpgradeApp({
|
|
270
|
+
discoverOpenCodeUpdate: createOpenCodeUpdateDiscovery(),
|
|
271
|
+
getIsExternalOpenCode: () => true,
|
|
272
|
+
getIsSharedOpenCodeService: () => true,
|
|
273
|
+
getResolvedOpenCodeBinary: () => binary,
|
|
274
|
+
forceResolvedOpenCodeBinary: (value) => { binary = value; },
|
|
275
|
+
restartOpenCode,
|
|
276
|
+
waitForOpenCodeReady: vi.fn(),
|
|
277
|
+
openchamberDataDir: '/cache',
|
|
278
|
+
});
|
|
279
|
+
const before = await request(app).get('/api/opencode/upgrade-status').expect(200);
|
|
280
|
+
expect(before.body).toMatchObject({ available: true, serveVersion: '2.0.16', targetVersion: '2.0.18', canManage: true });
|
|
281
|
+
const result = await request(app).post('/api/opencode/upgrade').send({}).expect(200);
|
|
282
|
+
expect(result.body).toMatchObject({ success: true, restarted: true, version: '2.0.18' });
|
|
283
|
+
expect(restartOpenCode).toHaveBeenCalledWith({ binaryPath: installed });
|
|
284
|
+
const after = await request(app).get('/api/opencode/upgrade-status').expect(200);
|
|
285
|
+
expect(after.body).toMatchObject({ available: false, serveVersion: '2.0.18' });
|
|
286
|
+
expect(fetchMock.mock.calls.filter(([url]) => String(url).includes('registry.npmjs.org'))).toHaveLength(1);
|
|
287
|
+
vi.mocked(readOpenCode2BinaryVersion).mockReset();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('reports registry failure as unknown rather than up-to-date', async () => {
|
|
291
|
+
vi.stubGlobal('fetch', vi.fn(async () => new Response(JSON.stringify({ version: '2.0.16' }))));
|
|
292
|
+
const { app } = createUpgradeApp({ discoverOpenCodeUpdate: async () => { throw new Error('registry unavailable'); } });
|
|
293
|
+
const result = await request(app).get('/api/opencode/upgrade-status').expect(500);
|
|
294
|
+
expect(result.body).toMatchObject({ available: null, error: 'registry unavailable' });
|
|
295
|
+
});
|
|
296
|
+
|
|
256
297
|
it('does not report a failed shared replacement as success and restores binary selection', async () => {
|
|
257
298
|
vi.mocked(installPinnedOpenCode2Cli).mockResolvedValueOnce('/cache/opencode-cli/2.0.14/opencode');
|
|
258
299
|
vi.mocked(readOpenCode2BinaryVersion).mockReturnValueOnce('2.0.14');
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { OPENCODE2_NPM_PACKAGE } from './opencode2-pin.js';
|
|
2
|
+
|
|
3
|
+
const stableVersion = (value) => typeof value === 'string' && /^2\.\d+\.\d+$/.test(value) ? value : null;
|
|
4
|
+
|
|
5
|
+
// One bounded registry snapshot per host, shared by all connected clients.
|
|
6
|
+
export function createOpenCodeUpdateDiscovery({ fetchImpl = (...args) => fetch(...args), now = Date.now } = {}) {
|
|
7
|
+
let snapshot = null;
|
|
8
|
+
let expiresAt = 0;
|
|
9
|
+
let pending = null;
|
|
10
|
+
|
|
11
|
+
const registry = () => {
|
|
12
|
+
if (snapshot && now() < expiresAt) return Promise.resolve(snapshot);
|
|
13
|
+
if (pending) return pending;
|
|
14
|
+
pending = (async () => {
|
|
15
|
+
try {
|
|
16
|
+
const response = await fetchImpl(`https://registry.npmjs.org/${encodeURIComponent(OPENCODE2_NPM_PACKAGE)}/latest`, {
|
|
17
|
+
headers: { Accept: 'application/json' },
|
|
18
|
+
signal: AbortSignal.timeout(5000),
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) throw new Error(`OpenCode registry returned HTTP ${response.status}`);
|
|
21
|
+
const version = stableVersion((await response.json()).version);
|
|
22
|
+
if (!version) throw new Error('OpenCode registry did not return a stable 2.x version');
|
|
23
|
+
snapshot = { version, error: null };
|
|
24
|
+
expiresAt = now() + 5 * 60_000;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
snapshot = { version: snapshot?.version ?? null, error: error instanceof Error ? error.message : 'OpenCode registry check failed' };
|
|
27
|
+
expiresAt = now() + 30_000;
|
|
28
|
+
}
|
|
29
|
+
return snapshot;
|
|
30
|
+
})().finally(() => { pending = null; });
|
|
31
|
+
return pending;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return async () => {
|
|
35
|
+
const remote = await registry();
|
|
36
|
+
if (remote.error) throw new Error(remote.error);
|
|
37
|
+
return remote.version;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createOpenCodeUpdateDiscovery } from './update-discovery.js';
|
|
3
|
+
|
|
4
|
+
describe('OpenCode remote update discovery', () => {
|
|
5
|
+
it('shares concurrent requests, caches for five minutes and refreshes after expiry', async () => {
|
|
6
|
+
let time = 0;
|
|
7
|
+
const fetchImpl = vi.fn(async () => Response.json({ version: '2.0.18' }));
|
|
8
|
+
const discover = createOpenCodeUpdateDiscovery({ fetchImpl, now: () => time });
|
|
9
|
+
expect(await Promise.all([discover(), discover(), discover()])).toEqual(['2.0.18', '2.0.18', '2.0.18']);
|
|
10
|
+
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
|
11
|
+
time = 299_999;
|
|
12
|
+
await discover();
|
|
13
|
+
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
|
14
|
+
time = 300_000;
|
|
15
|
+
fetchImpl.mockResolvedValueOnce(Response.json({ version: '2.0.19' }));
|
|
16
|
+
expect(await discover()).toBe('2.0.19');
|
|
17
|
+
expect(fetchImpl).toHaveBeenCalledTimes(2);
|
|
18
|
+
expect(fetchImpl.mock.calls[0][1].signal).toBeInstanceOf(AbortSignal);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it.each(['1.18.4', '3.0.0', '2.0.19-beta.1', 'latest', undefined])('rejects an invalid stable release %s', async (version) => {
|
|
22
|
+
const discover = createOpenCodeUpdateDiscovery({ fetchImpl: async () => Response.json({ version }) });
|
|
23
|
+
await expect(discover()).rejects.toThrow('stable 2.x');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('backs off errors without reporting stale success, then recovers', async () => {
|
|
27
|
+
let time = 0;
|
|
28
|
+
const fetchImpl = vi.fn().mockResolvedValueOnce(Response.json({ version: '2.0.18' }))
|
|
29
|
+
.mockRejectedValueOnce(new Error('offline')).mockResolvedValueOnce(Response.json({ version: '2.0.19' }));
|
|
30
|
+
const discover = createOpenCodeUpdateDiscovery({ fetchImpl, now: () => time });
|
|
31
|
+
await discover();
|
|
32
|
+
time = 300_000;
|
|
33
|
+
await expect(discover()).rejects.toThrow('offline');
|
|
34
|
+
await expect(discover()).rejects.toThrow('offline');
|
|
35
|
+
expect(fetchImpl).toHaveBeenCalledTimes(2);
|
|
36
|
+
time += 30_000;
|
|
37
|
+
expect(await discover()).toBe('2.0.19');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolOutputDialog-zTkbimFp.js","assets/rolldown-runtime-C0FnF6B9.js","assets/runtime-fetch-CiqQd__Y.js","assets/runtime-auth-D66yq6ie.js","assets/runtime-switch-BJM2k_uH.js","assets/vendor-base-ui-CnHfUmDN.js","assets/useUIStore-Brsa2mKs.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-EzCcYrQl.js","assets/persistence-CMWO3jFo.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-Cpu-rKij.js","assets/Icon-DKd015RD.js","assets/useThemeSystem-DMzWVJaW.js","assets/markdownTheme-DM5h1i18.js","assets/appThemeRegistry-Dd-Mc_ae.js","assets/platform-BxU3ZvQ0.js","assets/vendor-opencode-client-C12gfjag.js","assets/useMobileNavigationStore-DXxkpRmA.js","assets/vendor-tanstack-react-query-D7pys_c9.js","assets/vendor-sonner-DVzioF3d.js","assets/useAssistantUIStore-B75cQm_z.js","assets/vendor-zod-Dzk5kdUU.js","assets/vendor-fuse.js-DB5wDJbI.js","assets/MarkdownRenderer-TW-h0HHu.js","assets/markdownHeightCache-emzgqB2K.js","assets/dualLimitLru-D8Sphgua.js","assets/markdown-worker-bS5OgGO3.js","assets/useEffectiveDirectory-DB10GDme.js","assets/imageSource-BpUsiwFd.js","assets/relay-image-stream-D2XooXKZ.js","assets/useWorkerHighlightedLines-DWR_fwgu.js","assets/tooltip-DwUy2erJ.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-BJM2k_uH.js";import{G as a,H as o,J as s,Q as c,V as l,X as u,Y as d,dt as f,rt as p}from"./persistence-CMWO3jFo.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-BxU3ZvQ0.js";import{n as y}from"./useUIStore-Brsa2mKs.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-EzCcYrQl.js";import{a as N,n as P}from"./MobileShareBridge-CbLWGJA7.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-Ba4FGle-.js";import{Jt as ie,bn as ae,br as oe,dt as G,o as se,so as ce,xr as K}from"./useMobileNavigationStore-DXxkpRmA.js";import{i as le,n as q,r as ue}from"./useAssistantUIStore-B75cQm_z.js";import{a as de,i as J,n as Y,o as X,r as fe,t as pe}from"./dialog-Cpu-rKij.js";import{t as me}from"./AgentAvatar-Cxm7uMtK.js";import{n as Z}from"./Icon-DKd015RD.js";import{i as he}from"./OverlayScrollbar-SUdC3Pqe.js";import{n as ge}from"./textarea-B9pCxe-7.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-BUya3rIx.js";import{a as Ne,n as Pe,r as Fe,t as Ie}from"./fileMentionTouchSelection-CZkJTpTW.js";import{o as Le,t as Re}from"./MarkdownRenderer-TW-h0HHu.js";import{c as ze,s as Be}from"./imageSource-BpUsiwFd.js";import{a as Ve,t as He}from"./sessionLookup-Ba9vzhFN.js";import{a as Ue,i as We,n as Ge,r as Ke,t as qe}from"./context-menu-DSrUbCPh.js";import{i as Je,n as Ye,r as Xe}from"./assistant-attachment-cache-sG8YQsVs.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({...K(c),select:dt}),u=Q.useMemo(()=>G({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,c;t[0]===e?(n=t[1],r=t[2],i=t[3],c=t[4]):({active:n,working:c,onChange:r,...i}=e,t[0]=e,t[1]=n,t[2]=r,t[3]=i,t[4]=c);let p=c!==void 0&&c,{t:m}=A(),h;t[5]===i.value?h=t[6]:(h=()=>({canonical:i.value,document:a(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:a(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=u(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=o(y,B.tokenStart,B.tokenEnd,{id:`session:${e.id}:${crypto.randomUUID()}`,kind:`session`,sessionId:e.id,display:f({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=l(n.selectionStart,n.selectionEnd,y.references)??{start:n.selectionStart,end:n.selectionEnd},i=u({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=s(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 G=oe,se=y.text,ce=i.pending||p,K=i.pending===!0,le=i.layout===`inline`?`py-3 leading-6`:`pt-4 pb-2`,q;t[40]!==i.textLayoutClassName||t[41]!==le?(q=j(`whitespace-pre-wrap break-words overflow-hidden px-3 typography-markdown md:typography-ui-label`,le,i.textLayoutClassName),t[40]=i.textLayoutClassName,t[41]=le,t[42]=q):q=t[42];let ue;t[43]!==W||t[44]!==y?(ue=(e,t)=>{let n=s(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=d(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]!==G||t[79]!==i||t[80]!==ce||t[81]!==K||t[82]!==q||t[83]!==ue||t[84]!==ge||t[85]!==_e?(be=(0,$.jsx)(ve,{...i,value:se,pending:ce,disableInputWhilePending:K,inputRef:k,highlightedContent:G,highlightRef:M,textLayoutClassName:q,onChange:ue,textareaProps:ge,children:_e}),t[77]=y.text,t[78]=G,t[79]=i,t[80]=ce,t[81]=K,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,...c(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){se.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=oe(s),l=ie(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;ae(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=p)=>{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-zTkbimFp.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),d=n&&!u&&!l.hasMessageGap?F(e,l.data):null,f=N(e.name),m=f.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 oe=Q.useMemo(()=>Rt(),[]),G=Q.useRef(new Set),se=Q.useRef(new Map),K=tt(e=>e.setWorking),le=l.data?.messages??bt,q=Ct(T,e.id),ue=wt(D,e.id),de=Dt(le,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),G.current.clear(),se.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,le))},[le]),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:se.current,pendingSendTurnIDs:t,messages:le,settledTurnIDs:G.current}))},[e.activeContactTurn,e.id,le,q,X,fe]),Q.useEffect(()=>{K(e.id,J||Y||X)},[e.id,Y,J,X,K]),Q.useEffect(()=>{let t=e.id;return()=>{K(t,!1)}},[e.id,K]);let be=O(t=>{if(!(!(`assistantID`in t)||t.assistantID!==e.id)){if(t.type===`contact-turn-start`){G.current.delete(t.turnID),k(e=>At(e,t.assistantID,t.turnID,t.occurredAt));return}if(t.type===`contact-bubble-delta`){if(G.current.has(t.turnID))return;k(e=>Nt(e,t));return}t.type===`contact-turn-end`&&(G.current.add(t.turnID),k(e=>Ft(Pt(e,t,{requireExisting:!0}),le)))}});Q.useEffect(()=>{if(n)return ce(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:oe,sending:Bt(q),text:n,attachments:r,assistantID:a,createMessageID:()=>c||`oc_contact_${p()}`});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`&&se.current.set(l.messageID,i.revision),E(e=>kt(e,l.messageID)),G.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,...f.avatarEmoji?{avatarEmoji:f.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`&&se.current.set(l.messageID,e.revision),E(e=>kt(e,l.messageID)),G.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{oe.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:f.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:f.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,f=!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`)}),d?.messageID===t.messageID?(0,$.jsx)(it,{assistantID:e.id,position:d},`${a}:${e.id}:${d.generation}:${d.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:f?(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,d?.messageID===t.messageID?(0,$.jsx)(it,{assistantID:e.id,position:d},`${a}:${e.id}:${d.generation}:${d.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=le.getState().defaultShareAssistant;if(t?.assistantID!==e.id)return;let n=await te();n.serverInstanceID&&t.serverInstanceID===n.serverInstanceID&&le.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=le(S),w=le(An),T=le(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 G=O(oe),se=O(Mn),ce;t[39]!==a||t[40]!==se?(ce=()=>{if(a){a();return}se()},t[39]=a,t[40]=se,t[41]=ce):ce=t[41];let K=O(ce),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]!==K||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:K,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]=K,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]!==K||t[49]!==m||t[50]!==o?(e=m?(0,$.jsx)(Tn,{assistant:D,onBack:K,onOpenSettings:o}):null,t[47]=D,t[48]=K,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]!==G||t[93]!==ge?(ve=(0,$.jsx)(yn,{assistant:W,open:ge,onOpenChange:G}),t[91]=W,t[92]=G,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]!==K||t[99]!==m||t[100]!==o||t[101]!==te||t[102]!==X||t[103]!==s?(xe=m?(0,$.jsx)(Tn,{assistant:D,onBack:K,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]=K,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};
|