agent-tower 0.7.2-beta.8 → 0.7.2
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/utils/database-runtime.test.js +82 -5
- package/dist/utils/database-runtime.test.js.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +29 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/web/assets/{AgentDemoPage-CtCYXopw.js → AgentDemoPage-BfXkNCdN.js} +1 -1
- package/dist/web/assets/{AgentEnvironmentSettingsPage-DSWN546Y.js → AgentEnvironmentSettingsPage-GHjKIWpb.js} +1 -1
- package/dist/web/assets/AttachmentPreview-CLN1lnLe.js +2 -0
- package/dist/web/assets/{BranchSelect-Dxs7HnMM.js → BranchSelect-Cofp8vYf.js} +1 -1
- package/dist/web/assets/{BrandLogo-Ilm880Xs.js → BrandLogo-BUimEX-9.js} +1 -1
- package/dist/web/assets/{ConversationPage-B55Bj_ft.js → ConversationPage-R7vNaOQv.js} +1 -1
- package/dist/web/assets/{CreateTaskInput-CxWPeToI.js → CreateTaskInput-CasITF8y.js} +1 -1
- package/dist/web/assets/{DemoPage-Dyn-U9JO.js → DemoPage-DK-ikg1_.js} +1 -1
- package/dist/web/assets/{DesignSystemPage-BxypsRUZ.js → DesignSystemPage-BhjNs2vP.js} +1 -1
- package/dist/web/assets/EditableTaskTitle-BJ9Rxggf.js +70 -0
- package/dist/web/assets/{ExecutionPermissionSelector-CQ_GNxR0.js → ExecutionPermissionSelector-B8befbxJ.js} +1 -1
- package/dist/web/assets/{GeneralSettingsPage-CzoejPZP.js → GeneralSettingsPage-RMN2al8I.js} +1 -1
- package/dist/web/assets/{LoadingPreviewPage-BlW2PJhI.js → LoadingPreviewPage-BDlf89rJ.js} +1 -1
- package/dist/web/assets/{McpSettingsPage-DD7EqD4L.js → McpSettingsPage-CPNxFF67.js} +1 -1
- package/dist/web/assets/{MemberAvatar-B2pAdWUi.js → MemberAvatar-YVr_erAr.js} +1 -1
- package/dist/web/assets/{MobileTaskDetail-CvmNW0BQ.js → MobileTaskDetail-QNUHMq7u.js} +1 -1
- package/dist/web/assets/{NotificationSettingsPage-BIqldIRf.js → NotificationSettingsPage-BEyuyu3Z.js} +1 -1
- package/dist/web/assets/{ProfileSettingsPage-DMxpHmF1.js → ProfileSettingsPage-CHe4LlRp.js} +1 -1
- package/dist/web/assets/{ProjectKanbanPage-CHW79td4.js → ProjectKanbanPage-Bt_01giW.js} +7 -7
- package/dist/web/assets/{ProjectSettingsPage-DKiEUkoa.js → ProjectSettingsPage-cus6Ns97.js} +1 -1
- package/dist/web/assets/{ProviderSettingsPage-DZT7wyE2.js → ProviderSettingsPage-DqA_B1Ey.js} +1 -1
- package/dist/web/assets/{SettingsMasterDetail-DnF0lsV1.js → SettingsMasterDetail-DjWR9Sqk.js} +1 -1
- package/dist/web/assets/{TaskDetail-D_970BDY.js → TaskDetail-rEXNe2h3.js} +1 -1
- package/dist/web/assets/{TeamSettingsPage-BJIEZ7xL.js → TeamSettingsPage-DwWROtW6.js} +1 -1
- package/dist/web/assets/{TranslationSettingsPage-D3mazqEW.js → TranslationSettingsPage-Cod9c4Ug.js} +1 -1
- package/dist/web/assets/{arc-hUh7ykl8.js → arc-DEy33vTc.js} +1 -1
- package/dist/web/assets/{architectureDiagram-3BPJPVTR-CcV9CLkm.js → architectureDiagram-3BPJPVTR-Ky1D1LBk.js} +1 -1
- package/dist/web/assets/{at-sign-B-nhoGyH.js → at-sign-C48_y345.js} +1 -1
- package/dist/web/assets/{blockDiagram-GPEHLZMM-5q3Y9y0e.js → blockDiagram-GPEHLZMM-BNgB7kNT.js} +1 -1
- package/dist/web/assets/{c4Diagram-AAUBKEIU-CorBXi06.js → c4Diagram-AAUBKEIU-4GMrPMgQ.js} +1 -1
- package/dist/web/assets/channel-DTP-syjA.js +1 -0
- package/dist/web/assets/check-BmiJ7qMY.js +1 -0
- package/dist/web/assets/{chevron-down-CPnvItQw.js → chevron-down-3y5Aiolp.js} +1 -1
- package/dist/web/assets/{chevron-up-B8PE5N0G.js → chevron-up-DqaYcjpq.js} +1 -1
- package/dist/web/assets/{chunk-2J33WTMH-BUf5B4z4.js → chunk-2J33WTMH-C439hRe_.js} +1 -1
- package/dist/web/assets/{chunk-4BX2VUAB-CdnOHkro.js → chunk-4BX2VUAB-D8GK3M3t.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-U7edZDpP.js → chunk-55IACEB6-Dl4UhJ8X.js} +1 -1
- package/dist/web/assets/{chunk-727SXJPM-B64Tuhla.js → chunk-727SXJPM-BSEeayBq.js} +1 -1
- package/dist/web/assets/{chunk-AQP2D5EJ-dXfe56jB.js → chunk-AQP2D5EJ-B6chbZfT.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-DDYbxc1Q.js → chunk-FMBD7UC4-DaLkiLdQ.js} +1 -1
- package/dist/web/assets/{chunk-ND2GUHAM-BQDGMv0R.js → chunk-ND2GUHAM-DeQwZAAT.js} +1 -1
- package/dist/web/assets/{chunk-QZHKN3VN-DB8q4xAj.js → chunk-QZHKN3VN-CLRr4YRM.js} +1 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-CUKgurLa.js +1 -0
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-CUKgurLa.js +1 -0
- package/dist/web/assets/{code-block-OCS4YCEC-BSdICyOa.js → code-block-OCS4YCEC-CnoxUpOx.js} +1 -1
- package/dist/web/assets/{confirm-dialog-DxEBZEbV.js → confirm-dialog-ltNBFYCs.js} +1 -1
- package/dist/web/assets/{content-CMUL3HGx.js → content-DPQMfMae.js} +1 -1
- package/dist/web/assets/{copy-DyxlXxiU.js → copy-HRMhTkIG.js} +1 -1
- package/dist/web/assets/{cose-bilkent-S5V4N54A-Dx6eMnll.js → cose-bilkent-S5V4N54A-C1UiYzfk.js} +1 -1
- package/dist/web/assets/{cssMode-ZnNWfjZ6.js → cssMode-DkuSsGeg.js} +1 -1
- package/dist/web/assets/{dagre-BM42HDAG-Cxe8pLgD.js → dagre-BM42HDAG-CTJpBgye.js} +1 -1
- package/dist/web/assets/{diagram-2AECGRRQ-RMsswEBe.js → diagram-2AECGRRQ-Dj1_TEYp.js} +1 -1
- package/dist/web/assets/{diagram-5GNKFQAL-Bi4E0hzx.js → diagram-5GNKFQAL-V-KUpwqh.js} +1 -1
- package/dist/web/assets/{diagram-KO2AKTUF-Mv6CDCyn.js → diagram-KO2AKTUF-CXG1ZIeX.js} +1 -1
- package/dist/web/assets/{diagram-LMA3HP47-CJ3qKNzK.js → diagram-LMA3HP47-BZSJUwk9.js} +1 -1
- package/dist/web/assets/{diagram-OG6HWLK6-D8SBY4ft.js → diagram-OG6HWLK6-CCr4gq4u.js} +1 -1
- package/dist/web/assets/{dialog-BYdeYC2Y.js → dialog-CuFEdqLg.js} +1 -1
- package/dist/web/assets/{erDiagram-TEJ5UH35-DwVSCU6X.js → erDiagram-TEJ5UH35-Djtyzh6z.js} +1 -1
- package/dist/web/assets/{flowDiagram-I6XJVG4X-CyipYAWd.js → flowDiagram-I6XJVG4X-BmSVSiXJ.js} +1 -1
- package/dist/web/assets/{freemarker2-DbH_yMCO.js → freemarker2-DdptX5f1.js} +1 -1
- package/dist/web/assets/{ganttDiagram-6RSMTGT7-CsC6Wjt4.js → ganttDiagram-6RSMTGT7-r5vQX-b5.js} +1 -1
- package/dist/web/assets/{gitGraphDiagram-PVQCEYII-E5jNbqlq.js → gitGraphDiagram-PVQCEYII-Zj9aloh9.js} +1 -1
- package/dist/web/assets/{globe-B2rgTPH3.js → globe-B9I-jHBB.js} +1 -1
- package/dist/web/assets/{handlebars-C5VY_S-z.js → handlebars-B34f-LAf.js} +1 -1
- package/dist/web/assets/{hooks-Ct0srfV-.js → hooks-BLxb16IA.js} +1 -1
- package/dist/web/assets/{html-e5uLnAgN.js → html-CnvOQ63o.js} +1 -1
- package/dist/web/assets/{htmlMode-BeNiGozX.js → htmlMode-RdxZ8Svp.js} +1 -1
- package/dist/web/assets/{icon-button-BEMJj_6T.js → icon-button-CYiKa-7C.js} +1 -1
- package/dist/web/assets/{index-DNdMmXBr.js → index-B1oVmCie.js} +1 -1
- package/dist/web/assets/index-BJObbxud.js +122 -0
- package/dist/web/assets/{index-CAjqC8pT.js → index-Bhvt-E6d.js} +1 -1
- package/dist/web/assets/{index-CPGzLjEC.js → index-BtUQYU5l.js} +1 -1
- package/dist/web/assets/{index-IMdA08Ok.js → index-CThFsQNP.js} +1 -1
- package/dist/web/assets/{index-BYPOXP6w.js → index-DZLnTISJ.js} +1 -1
- package/dist/web/assets/{index-kr6U6_pi.js → index-DcOU2m2F.js} +1 -1
- package/dist/web/assets/{index-DppwrK2G.js → index-Dk3bRQAK.js} +1 -1
- package/dist/web/assets/{index-C-M0QDqc.js → index-DkRy6eNX.js} +4 -4
- package/dist/web/assets/{infoDiagram-5YYISTIA-5_0wrRXl.js → infoDiagram-5YYISTIA-BHtVaxZx.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-YF4QCWOH-aQujIFZw.js → ishikawaDiagram-YF4QCWOH-BYmwjkbC.js} +1 -1
- package/dist/web/assets/javascript-BhombDEO.js +1 -0
- package/dist/web/assets/{journeyDiagram-JHISSGLW-ClMzHdqI.js → journeyDiagram-JHISSGLW-c8BBqqRS.js} +1 -1
- package/dist/web/assets/{jsonMode-nHmLVf-n.js → jsonMode-BJGOUeaV.js} +1 -1
- package/dist/web/assets/{kanban-definition-UN3LZRKU-BFVlt0tz.js → kanban-definition-UN3LZRKU-D4Vr-oFT.js} +1 -1
- package/dist/web/assets/{kbd-Bfq5K6Ux.js → kbd-C88ut3t9.js} +1 -1
- package/dist/web/assets/{key-round-BqsaQdce.js → key-round-Cjbj2qNa.js} +1 -1
- package/dist/web/assets/{layers-DI4vFJ4F.js → layers-eaHAVcc3.js} +1 -1
- package/dist/web/assets/{linear-DZ-6PAPS.js → linear-opi90s0L.js} +1 -1
- package/dist/web/assets/{link-BU4PN723.js → link-BSGb85gq.js} +1 -1
- package/dist/web/assets/{liquid-BPIyogoj.js → liquid-Czy1WpPz.js} +1 -1
- package/dist/web/assets/{lspLanguageFeatures-DH4Z8jiM.js → lspLanguageFeatures-DWu2Ubf0.js} +1 -1
- package/dist/web/assets/{mdx-CI8yO2pV.js → mdx-DhXfoSnM.js} +1 -1
- package/dist/web/assets/{menu-C3uB3M7p.js → menu--sjyisSg.js} +1 -1
- package/dist/web/assets/{mermaid-NOHMQCX5-BqeX1osS.js → mermaid-NOHMQCX5-BSNbBj78.js} +35 -35
- package/dist/web/assets/{message-square-E5K8E3A-.js → message-square-BLEJN6p7.js} +1 -1
- package/dist/web/assets/{mindmap-definition-RKZ34NQL-C7dea0db.js → mindmap-definition-RKZ34NQL-BN3ZjBh-.js} +1 -1
- package/dist/web/assets/{modal-Cz1iIVeD.js → modal-CSGOqphK.js} +1 -1
- package/dist/web/assets/{monaco-DM3DuGN5.js → monaco-BkuNyOkP.js} +3 -3
- package/dist/web/assets/{paperclip-COXNce_v.js → paperclip-CTNoXpUW.js} +1 -1
- package/dist/web/assets/{pencil-BFc4n44f.js → pencil-Cp70ZwtG.js} +1 -1
- package/dist/web/assets/{people-BaCetIqh.js → people-DT78SebR.js} +1 -1
- package/dist/web/assets/{pieDiagram-4H26LBE5-2q5medug.js → pieDiagram-4H26LBE5-CfmFHpPI.js} +1 -1
- package/dist/web/assets/{popover-CJCQLoGu.js → popover-BiVxGGgp.js} +1 -1
- package/dist/web/assets/{python-CSxVPG9p.js → python-DIcQDjcf.js} +1 -1
- package/dist/web/assets/{quadrantDiagram-W4KKPZXB-DHPEM56s.js → quadrantDiagram-W4KKPZXB-CeaumJAa.js} +1 -1
- package/dist/web/assets/{razor-CVoIieeS.js → razor-DYK6Rxer.js} +1 -1
- package/dist/web/assets/{requirementDiagram-4Y6WPE33-B_KyH7PP.js → requirementDiagram-4Y6WPE33-BWWCDXCE.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-5OEKKPKP-CrqkZAYW.js → sankeyDiagram-5OEKKPKP-DAJut743.js} +1 -1
- package/dist/web/assets/{search-CkiBPir_.js → search-DniD_AGC.js} +1 -1
- package/dist/web/assets/{search-field-CbM2P2KE.js → search-field-CQLDXLeA.js} +1 -1
- package/dist/web/assets/{select-DJsEG0jq.js → select-B5RYunTs.js} +1 -1
- package/dist/web/assets/{select-Br0TAs7A.js → select-BPdJrr5M.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-3UESZ5HK-BRTm1WQA.js → sequenceDiagram-3UESZ5HK-CynjRGW4.js} +1 -1
- package/dist/web/assets/{server-DYeSE1wn.js → server-xswxWpKD.js} +1 -1
- package/dist/web/assets/{stateDiagram-AJRCARHV-qN49iyR2.js → stateDiagram-AJRCARHV-amAtpx9w.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-V-lSceg1.js +1 -0
- package/dist/web/assets/{textarea-B7vtoRE3.js → textarea-BVyPl9rM.js} +1 -1
- package/dist/web/assets/{timeline-definition-PNZ67QCA-BzarcDi3.js → timeline-definition-PNZ67QCA-DZ9W7WlP.js} +1 -1
- package/dist/web/assets/{toggles-jo27o0AH.js → toggles-QcIz43DP.js} +1 -1
- package/dist/web/assets/{tooltip-DbVtCXcO.js → tooltip-CPqGK_WZ.js} +1 -1
- package/dist/web/assets/{track-C0vxnITw.js → track-Ckye0-tt.js} +1 -1
- package/dist/web/assets/{trash-2-CUM-XX8B.js → trash-2-CvUJsbtT.js} +1 -1
- package/dist/web/assets/{tsMode-7D3gqep6.js → tsMode-c5x0d47n.js} +1 -1
- package/dist/web/assets/{typescript-CbOVEQNg.js → typescript-i7eYblLt.js} +1 -1
- package/dist/web/assets/{upload-CJ6jVmte.js → upload-CsXAmAun.js} +1 -1
- package/dist/web/assets/{use-profiles-B0xXAf7Z.js → use-profiles-DuXaBRju.js} +1 -1
- package/dist/web/assets/{use-projects-BlTwWxkY.js → use-projects-Ddz0knyr.js} +1 -1
- package/dist/web/assets/{use-providers-FMSfyTD1.js → use-providers-Td1-gyrN.js} +1 -1
- package/dist/web/assets/use-translation-settings-NYM0lmBx.js +1 -0
- package/dist/web/assets/{use-workspaces-DYrEp0Lw.js → use-workspaces-CdJZLmGh.js} +1 -1
- package/dist/web/assets/{useNormalizedLogs-D0N8MJdH.js → useNormalizedLogs--RbVywYa.js} +1 -1
- package/dist/web/assets/{useTokenUsage-WB3ZQ25v.js → useTokenUsage-DDXf7E4p.js} +1 -1
- package/dist/web/assets/{vennDiagram-CIIHVFJN-B6oZetvf.js → vennDiagram-CIIHVFJN-CB2Ubvy9.js} +1 -1
- package/dist/web/assets/{wardley-L42UT6IY-Bzuhm76f.js → wardley-L42UT6IY-BXOkk77I.js} +1 -1
- package/dist/web/assets/{wardleyDiagram-YWT4CUSO-DaC-FUf5.js → wardleyDiagram-YWT4CUSO-VA6ywdQQ.js} +1 -1
- package/dist/web/assets/{xml-Cfa9tkdT.js → xml-D2EGActB.js} +1 -1
- package/dist/web/assets/{xychartDiagram-2RQKCTM6-CCvRIJRL.js → xychartDiagram-2RQKCTM6-FNcvDj5G.js} +1 -1
- package/dist/web/assets/{yaml-C86f7VLL.js → yaml-jeiIZSL4.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/AttachmentPreview-DRG5_cfN.js +0 -2
- package/dist/web/assets/EditableTaskTitle-Dh-SmvFW.js +0 -70
- package/dist/web/assets/channel-By24WpLg.js +0 -1
- package/dist/web/assets/check-DqPSoX0r.js +0 -1
- package/dist/web/assets/classDiagram-4FO5ZUOK-DxHoimtR.js +0 -1
- package/dist/web/assets/classDiagram-v2-Q7XG4LA2-DxHoimtR.js +0 -1
- package/dist/web/assets/index-Cm6snkmR.js +0 -122
- package/dist/web/assets/javascript-D7QVj9jR.js +0 -1
- package/dist/web/assets/stateDiagram-v2-BHNVJYJU-B1clBPkJ.js +0 -1
- package/dist/web/assets/use-translation-settings-BOlszecX.js +0 -1
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import pkg from '@prisma/client';
|
|
5
7
|
const testDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-tower-database-runtime-'));
|
|
6
|
-
const
|
|
7
|
-
process.env.AGENT_TOWER_DATABASE_URL = `file:${dbPath}`;
|
|
8
|
+
const originalDatabaseUrl = process.env.AGENT_TOWER_DATABASE_URL;
|
|
8
9
|
let prisma;
|
|
9
10
|
let initializeDatabaseRuntime;
|
|
10
11
|
let busyTimeoutMs;
|
|
12
|
+
let dbPath;
|
|
13
|
+
let databaseNumber = 0;
|
|
11
14
|
describe('initializeDatabaseRuntime', () => {
|
|
12
|
-
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
vi.resetModules();
|
|
17
|
+
dbPath = path.join(testDir, `test-${++databaseNumber}.db`);
|
|
18
|
+
process.env.AGENT_TOWER_DATABASE_URL = `file:${dbPath}`;
|
|
13
19
|
const utils = await import('./index.js');
|
|
14
20
|
prisma = utils.prisma;
|
|
15
21
|
initializeDatabaseRuntime = utils.initializeDatabaseRuntime;
|
|
16
22
|
busyTimeoutMs = utils.SQLITE_BUSY_TIMEOUT_MS;
|
|
17
23
|
});
|
|
18
|
-
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
vi.restoreAllMocks();
|
|
19
26
|
await prisma.$disconnect();
|
|
27
|
+
});
|
|
28
|
+
afterAll(() => {
|
|
29
|
+
if (originalDatabaseUrl === undefined)
|
|
30
|
+
delete process.env.AGENT_TOWER_DATABASE_URL;
|
|
31
|
+
else
|
|
32
|
+
process.env.AGENT_TOWER_DATABASE_URL = originalDatabaseUrl;
|
|
20
33
|
fs.rmSync(testDir, { recursive: true, force: true });
|
|
21
34
|
});
|
|
22
35
|
it('enables WAL and configures the SQLite busy timeout', async () => {
|
|
@@ -26,5 +39,69 @@ describe('initializeDatabaseRuntime', () => {
|
|
|
26
39
|
expect(journalMode[0]?.journal_mode.toLowerCase()).toBe('wal');
|
|
27
40
|
expect(Number(busyTimeout[0]?.timeout)).toBe(busyTimeoutMs);
|
|
28
41
|
});
|
|
42
|
+
it('waits for an existing SQLite writer before enabling WAL', async () => {
|
|
43
|
+
const writer = new pkg.PrismaClient({ datasources: { db: { url: `file:${dbPath}` } } });
|
|
44
|
+
let locked = false;
|
|
45
|
+
let initialization;
|
|
46
|
+
try {
|
|
47
|
+
await writer.$executeRawUnsafe('CREATE TABLE StartupEvidence (value TEXT)');
|
|
48
|
+
await writer.$executeRawUnsafe('BEGIN EXCLUSIVE');
|
|
49
|
+
locked = true;
|
|
50
|
+
await writer.$executeRawUnsafe("INSERT INTO StartupEvidence VALUES ('preserved')");
|
|
51
|
+
let initialized = false;
|
|
52
|
+
initialization = initializeDatabaseRuntime().then(() => { initialized = true; });
|
|
53
|
+
// Attach a handler immediately so the pre-fix rejection is reported by
|
|
54
|
+
// this assertion, rather than as an unhandled promise rejection.
|
|
55
|
+
void initialization.catch(() => { });
|
|
56
|
+
await delay(100);
|
|
57
|
+
expect(initialized).toBe(false);
|
|
58
|
+
await writer.$executeRawUnsafe('COMMIT');
|
|
59
|
+
locked = false;
|
|
60
|
+
await initialization;
|
|
61
|
+
expect(await prisma.$queryRawUnsafe('SELECT value FROM StartupEvidence'))
|
|
62
|
+
.toEqual([{ value: 'preserved' }]);
|
|
63
|
+
expect(await prisma.$queryRawUnsafe('PRAGMA journal_mode')).toEqual([{ journal_mode: 'wal' }]);
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
if (locked)
|
|
67
|
+
await writer.$executeRawUnsafe('ROLLBACK');
|
|
68
|
+
await initialization?.catch(() => { });
|
|
69
|
+
await writer.$disconnect();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
it('shares initialization and retries a transient WAL lock after configuring busy_timeout', async () => {
|
|
73
|
+
const lock = { code: 'P2010', meta: { code: '5' }, message: 'database is locked' };
|
|
74
|
+
const query = vi.spyOn(prisma, '$queryRawUnsafe')
|
|
75
|
+
.mockResolvedValueOnce([])
|
|
76
|
+
.mockRejectedValueOnce(lock)
|
|
77
|
+
.mockResolvedValueOnce([{ journal_mode: 'wal' }]);
|
|
78
|
+
const initialization = initializeDatabaseRuntime();
|
|
79
|
+
expect(initializeDatabaseRuntime()).toBe(initialization);
|
|
80
|
+
await initialization;
|
|
81
|
+
expect(query.mock.calls.map(([sql]) => sql)).toEqual([
|
|
82
|
+
`PRAGMA busy_timeout = ${busyTimeoutMs}`, 'PRAGMA journal_mode = WAL', 'PRAGMA journal_mode = WAL',
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
it('stops retrying locks after the startup window and preserves the original failure', async () => {
|
|
86
|
+
const lock = { code: 'P2010', meta: { code: '5' }, message: 'database is locked' };
|
|
87
|
+
vi.spyOn(performance, 'now').mockReturnValueOnce(0).mockReturnValueOnce(0).mockReturnValueOnce(50)
|
|
88
|
+
.mockReturnValue(busyTimeoutMs + 1);
|
|
89
|
+
const query = vi.spyOn(prisma, '$queryRawUnsafe')
|
|
90
|
+
.mockResolvedValueOnce([])
|
|
91
|
+
.mockRejectedValue(lock);
|
|
92
|
+
await expect(initializeDatabaseRuntime()).rejects.toBe(lock);
|
|
93
|
+
expect(query).toHaveBeenCalledTimes(3);
|
|
94
|
+
});
|
|
95
|
+
it('does not retry permanent query errors and allows initialization after a failure', async () => {
|
|
96
|
+
const failure = { code: 'P2010', meta: { code: '11' }, message: 'database disk image is malformed' };
|
|
97
|
+
const query = vi.spyOn(prisma, '$queryRawUnsafe')
|
|
98
|
+
.mockResolvedValueOnce([])
|
|
99
|
+
.mockRejectedValueOnce(failure);
|
|
100
|
+
await expect(initializeDatabaseRuntime()).rejects.toBe(failure);
|
|
101
|
+
expect(query).toHaveBeenCalledTimes(2);
|
|
102
|
+
query.mockResolvedValue([]);
|
|
103
|
+
await initializeDatabaseRuntime();
|
|
104
|
+
expect(query).toHaveBeenCalledTimes(4);
|
|
105
|
+
});
|
|
29
106
|
});
|
|
30
107
|
//# sourceMappingURL=database-runtime.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database-runtime.test.js","sourceRoot":"","sources":["../../src/utils/database-runtime.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"database-runtime.test.js","sourceRoot":"","sources":["../../src/utils/database-runtime.test.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,gBAAgB,CAAC;AACjC,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,gBAAgB,CAAC;AACjC,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAW3D,eAAO,MAAM,MAAM,+GAAqB,CAAC;AAEzC,eAAO,MAAM,sBAAsB,OAAQ,CAAC;AAc5C;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BzD;AAED,wBAAsB,SAAS,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAM7C;AAED;;;GAGG;AACH,wBAAsB,KAAK,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;CACd,GACL,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxB"}
|
package/dist/utils/index.js
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import pkg from '@prisma/client';
|
|
2
2
|
import { execFile } from 'child_process';
|
|
3
3
|
import { promisify } from 'util';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
4
5
|
import { normalizeCommandLookupOutput, withUnixUserPathFallbacks, withWindowsUserPathFallbacks, } from './process-launch.js';
|
|
5
6
|
const { PrismaClient } = pkg;
|
|
6
7
|
const execFileAsync = promisify(execFile);
|
|
7
8
|
export const prisma = new PrismaClient();
|
|
8
9
|
export const SQLITE_BUSY_TIMEOUT_MS = 5_000;
|
|
9
10
|
let databaseRuntimeInitialization = null;
|
|
11
|
+
function isSqliteLockError(error) {
|
|
12
|
+
if (!error || typeof error !== 'object')
|
|
13
|
+
return false;
|
|
14
|
+
const failure = error;
|
|
15
|
+
// Prisma wraps SQLite errors in P2010; preserve all other initialization
|
|
16
|
+
// failures instead of treating arbitrary query errors as startup contention.
|
|
17
|
+
return ['5', '6'].includes(String(failure.meta?.code))
|
|
18
|
+
|| /SQLITE_BUSY|SQLITE_LOCKED|database (?:is |table is )?locked/i.test(String(failure.message))
|
|
19
|
+
|| ['SQLITE_BUSY', 'SQLITE_LOCKED'].includes(String(failure.code));
|
|
20
|
+
}
|
|
10
21
|
/**
|
|
11
22
|
* Configure SQLite before HTTP traffic starts. WAL is persisted in the database file;
|
|
12
23
|
* busy_timeout protects the active Prisma connection from failing immediately on a writer lock.
|
|
@@ -16,8 +27,25 @@ export function initializeDatabaseRuntime() {
|
|
|
16
27
|
return databaseRuntimeInitialization;
|
|
17
28
|
}
|
|
18
29
|
databaseRuntimeInitialization = (async () => {
|
|
19
|
-
await prisma.$queryRawUnsafe(`PRAGMA journal_mode = WAL`);
|
|
20
30
|
await prisma.$queryRawUnsafe(`PRAGMA busy_timeout = ${SQLITE_BUSY_TIMEOUT_MS}`);
|
|
31
|
+
// Another CLI can still be synchronizing the same database. Changing its
|
|
32
|
+
// journal mode can return SQLITE_BUSY without invoking SQLite's busy
|
|
33
|
+
// handler, so retry this idempotent pragma within a bounded startup window.
|
|
34
|
+
const retryDeadline = performance.now() + SQLITE_BUSY_TIMEOUT_MS;
|
|
35
|
+
for (let attempt = 1;; attempt++) {
|
|
36
|
+
try {
|
|
37
|
+
await prisma.$queryRawUnsafe(`PRAGMA journal_mode = WAL`);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
const remainingMs = retryDeadline - performance.now();
|
|
42
|
+
if (!isSqliteLockError(error) || remainingMs <= 0)
|
|
43
|
+
throw error;
|
|
44
|
+
await delay(Math.min(attempt * 50, 250, remainingMs));
|
|
45
|
+
if (performance.now() >= retryDeadline)
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
21
49
|
})().catch((error) => {
|
|
22
50
|
databaseRuntimeInitialization = null;
|
|
23
51
|
throw error;
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,gBAAgB,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,qBAAqB,CAAC;AAC7B,MAAM,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC;AAC7B,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;AAEzC,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAE5C,IAAI,6BAA6B,GAAyB,IAAI,CAAC;AAE/D;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,6BAA6B,EAAE,CAAC;QAClC,OAAO,6BAA6B,CAAC;IACvC,CAAC;IAED,6BAA6B,GAAG,CAAC,KAAK,IAAI,EAAE;QAC1C,MAAM,MAAM,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as H,j as e,u as te,aK as se,r,v as b,B as N,aO as re,aM as ne,au as ae}from"./index-Cm6snkmR.js";import{u as le,a as oe,L as ie,T as ce}from"./useNormalizedLogs-D0N8MJdH.js";import{a as de}from"./mermaid-NOHMQCX5-BqeX1osS.js";import"./AttachmentPreview-DRG5_cfN.js";import{d as xe}from"./use-profiles-B0xXAf7Z.js";import{C as me}from"./chevron-up-B8PE5N0G.js";import{C as ue}from"./chevron-down-CPnvItQw.js";import{P as pe}from"./paperclip-COXNce_v.js";import{A as he}from"./at-sign-B-nhoGyH.js";import{G as ge}from"./globe-B2rgTPH3.js";import"./track-C0vxnITw.js";import"./use-translation-settings-BOlszecX.js";import"./copy-DyxlXxiU.js";import"./index-kr6U6_pi.js";import"./index-CAjqC8pT.js";import"./index-DNdMmXBr.js";import"./tooltip-DbVtCXcO.js";import"./kbd-Bfq5K6Ux.js";import"./index-DppwrK2G.js";const fe=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],be=H("hash",fe);const je=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],ve=H("send",je),B=({className:s})=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:s,xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.4"}),e.jsx("circle",{cx:"8",cy:"8",r:"3",fill:"currentColor"})]}),ye=({className:s})=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:s,xmlns:"http://www.w3.org/2000/svg",children:e.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5"})}),Ne=({className:s})=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:s,xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M13.5 4.5L6.5 11.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),we=!0;function Oe(){const{t:s}=te(),{preserveDesktopSearch:M}=se(),[w,U]=r.useState([]),[o,S]=r.useState(""),[x,k]=r.useState("DEFAULT"),[i,A]=r.useState(""),[a,C]=r.useState(null),[V,D]=r.useState(null),[l,c]=r.useState("idle"),[g,E]=r.useState(!1),[m,j]=r.useState(""),$=r.useRef(null),I=r.useRef(null),u=r.useRef(null),{data:p}=xe(o),F=p?Object.keys(p):["DEFAULT"],O=t=>{S(t),k("DEFAULT")},_=r.useCallback(t=>{c(t===0?"stopped":"error")},[]),G=r.useCallback(t=>{console.error("Agent error:",t),c("error")},[]),{isConnected:h,isAttached:f,isOutputActive:W,lastExitAt:K,logs:v,entries:q,agentSessionId:L,attach:z,clearLogs:P}=le({sessionId:a||"",sessionStartedAt:V,onExit:_,onError:G}),{todos:R}=oe(q);r.useEffect(()=>{b.get("/demo/agents").then(t=>{U(t.agents);const n=t.agents.find(y=>y.available);n&&S(n.type)})},[]),r.useEffect(()=>{$.current?.scrollToBottom("smooth")},[v]),r.useEffect(()=>{console.log(`[AgentDemoPage:useEffect] t=${Date.now()} sessionId=${a} isConnected=${h} isAttached=${f}`),a&&h&&!f&&(console.log(`[AgentDemoPage:useEffect] t=${Date.now()} calling attach()`),z())},[a,h,f,z]);const J=t=>{if(j(t.target.value),u.current){u.current.style.height="auto";const y=Math.min(u.current.scrollHeight,210);u.current.style.height=`${y}px`}},Q=async()=>{if(!o||!i.trim())return;const t=Date.now();console.log(`[AgentDemoPage:handleStart] t=${t} starting...`),c("starting"),P();try{const n=await b.post("/demo/start",{agentType:o,prompt:i.trim(),variant:x});we&&console.log(`[AgentDemoPage:handleStart] t=${Date.now()} apiTime=${Date.now()-t}ms sessionId=${n.sessionId}`),C(n.sessionId),D(t),c("running")}catch(n){console.error("Start failed:",n),c("error")}},T=async()=>{if(!a||!m.trim())return;const t=m.trim();j("");try{await b.post(`/demo/${a}/message`,{message:t})}catch(n){console.error("Send failed:",n)}},X=async()=>{if(a)try{await b.post(`/demo/${a}/stop`),c("stopped")}catch(t){console.error("Stop failed:",t)}},Y=()=>{C(null),D(null),c("idle"),A(""),j(""),P()},Z=l==="running",d=a!==null,ee=w.find(t=>t.type===o);return e.jsxs("div",{className:"flex flex-col h-full bg-white",children:[e.jsxs("div",{className:"px-8 py-5 border-b border-neutral-100 bg-white transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-base font-medium text-blue-600",children:"Agent Demo"}),e.jsx("span",{className:"text-neutral-300 text-sm",children:"/"}),e.jsx("span",{className:"text-xl font-bold text-neutral-900 tracking-tight",children:d?i.slice(0,50)+(i.length>50?"...":""):s("新会话")})]}),e.jsxs("div",{className:"flex items-center",children:[l==="running"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-blue-50 text-blue-700 rounded-full text-xs font-medium border border-blue-100",children:[e.jsx(B,{className:"w-3.5 h-3.5 animate-pulse"}),e.jsx("span",{children:"Running"})]}),l==="stopped"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-emerald-50 text-emerald-700 rounded-full text-xs font-medium border border-emerald-100",children:[e.jsx(Ne,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Done"})]}),l==="idle"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-neutral-100 text-neutral-600 rounded-full text-xs font-medium border border-neutral-200",children:[e.jsx(ye,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Idle"})]}),l==="starting"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-amber-50 text-amber-700 rounded-full text-xs font-medium border border-amber-100",children:[e.jsx(B,{className:"w-3.5 h-3.5 animate-spin"}),e.jsx("span",{children:"Starting..."})]}),l==="error"&&e.jsx("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-red-50 text-red-700 rounded-full text-xs font-medium border border-red-100",children:e.jsx("span",{children:"Error"})})]})]}),d&&e.jsxs("div",{className:"mt-1.5 flex items-start gap-2 group max-w-4xl",children:[e.jsx("div",{className:`text-sm text-neutral-600 leading-relaxed cursor-pointer transition-all ${g?"":"truncate"}`,onClick:()=>E(!g),children:i}),e.jsx("button",{onClick:()=>E(!g),className:"mt-0.5 text-neutral-400 opacity-0 group-hover:opacity-100 hover:text-neutral-600 transition-opacity",children:g?e.jsx(me,{size:14}):e.jsx(ue,{size:14})})]}),e.jsxs("div",{className:"flex items-center gap-6 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:"Agent"}),e.jsx("div",{className:"flex items-center gap-1.5 text-neutral-900 font-medium bg-neutral-50 px-2 py-1 rounded border border-neutral-100",children:ee?.name||o||s("未选择")})]}),x!=="DEFAULT"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:"Variant"}),e.jsx("div",{className:"flex items-center gap-1.5 text-neutral-700 font-medium bg-blue-50 px-2 py-1 rounded border border-blue-100",children:x})]}),L&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:"Session"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-neutral-700 font-mono bg-neutral-50 px-2 py-1 rounded border border-neutral-100",children:[L.slice(0,8),"..."]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:s("连接")}),e.jsx("div",{className:`flex items-center gap-1.5 font-medium px-2 py-1 rounded border ${h?"text-emerald-700 bg-emerald-50 border-emerald-100":"text-neutral-500 bg-neutral-50 border-neutral-100"}`,children:s(h?f?"已连接":"连接中...":"未连接")})]}),d&&e.jsx(N,{variant:"outline",size:"sm",onClick:Y,className:"ml-auto",children:s("新会话")}),e.jsxs(re,{to:M("/settings/profiles"),className:`flex items-center gap-1.5 text-xs text-neutral-500 hover:text-neutral-900 transition-colors ${d?"":"ml-auto"}`,children:[e.jsx(ne,{size:14}),e.jsx("span",{children:s("Profiles 设置")})]})]})]}),e.jsx("div",{ref:I,className:"flex-1 overflow-y-auto px-8 py-6",children:d?e.jsx("div",{className:"min-h-[200px]",children:v.length===0?e.jsx("div",{className:"text-neutral-400 text-center py-8",children:s("等待 Agent 响应...")}):e.jsx(ie,{children:e.jsx(de,{ref:$,logs:v,isOutputActive:W,lastExitAt:K,scrollElementRef:I})})}):e.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-neutral-900",children:s("选择 Agent")}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:w.map(t=>e.jsxs(N,{variant:o===t.type?"default":"outline",disabled:!t.available,onClick:()=>O(t.type),children:[t.name,t.available&&t.version&&` (${t.version})`,!t.available&&s(" (不可用)")]},t.type))})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-neutral-900",children:s("配置变体 (Profile Variant)")}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:F.map(t=>e.jsx("button",{onClick:()=>k(t),className:`px-3 py-1.5 rounded-full text-sm font-medium border transition-colors ${x===t?"bg-neutral-900 text-white border-neutral-900":"bg-white text-neutral-600 border-neutral-200 hover:border-neutral-400"}`,children:t},t))}),p&&p[x]&&e.jsx("p",{className:"mt-2 text-xs text-neutral-500 font-mono",children:Object.entries(p[x]).map(([t,n])=>`${t}: ${JSON.stringify(n)}`).join(", ")})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-neutral-900",children:s("输入任务")}),e.jsxs("div",{className:"relative border border-neutral-200 rounded-xl shadow-sm bg-white focus-within:ring-1 focus-within:ring-neutral-300 focus-within:border-neutral-300 transition-all duration-200",children:[e.jsx("textarea",{value:i,onChange:t=>A(t.target.value),rows:4,placeholder:s("描述你想让 Agent 完成的任务..."),className:"w-full px-4 py-3 bg-transparent border-none focus:outline-none focus:ring-0 resize-none text-neutral-900 placeholder-neutral-400 leading-relaxed text-sm"}),e.jsx("div",{className:"flex items-center justify-end px-3 pb-3 pt-1",children:e.jsx(N,{onClick:Q,disabled:l==="starting"||!o||!i.trim(),children:s(l==="starting"?"启动中...":"开始")})})]})]})]})}),d&&R.length>0&&e.jsx("div",{className:"px-8 py-2 bg-white border-t border-neutral-100",children:e.jsx(ce,{todos:R})}),d&&e.jsx("div",{className:"px-8 py-6 border-t border-neutral-100 bg-white",children:e.jsxs("div",{className:"relative border border-neutral-200 rounded-xl shadow-sm bg-white focus-within:ring-1 focus-within:ring-neutral-300 focus-within:border-neutral-300 transition-all duration-200",children:[e.jsx("textarea",{ref:u,value:m,onChange:J,rows:3,placeholder:s("发送消息给 Agent..."),className:"w-full px-4 py-3 bg-transparent border-none focus:outline-none focus:ring-0 resize-none text-neutral-900 placeholder-neutral-400 leading-relaxed text-sm scrollbar-thin scrollbar-thumb-neutral-200 scrollbar-track-transparent",style:{minHeight:"80px",maxHeight:"210px"},onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&!t.repeat&&!t.nativeEvent.isComposing&&t.nativeEvent.keyCode!==229&&(t.preventDefault(),T())}}),e.jsxs("div",{className:"flex items-center justify-between px-3 pb-3 pt-1 border-t border-transparent",children:[e.jsxs("div",{className:"flex items-center gap-1 text-neutral-400",children:[e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Attach File",children:e.jsx(pe,{size:18})}),e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Mention",children:e.jsx(he,{size:18})}),e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Reference Issue",children:e.jsx(be,{size:18})}),e.jsx("div",{className:"w-px h-4 bg-neutral-200 mx-1"}),e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Search Web",children:e.jsx(ge,{size:18})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[Z&&e.jsxs("button",{onClick:X,className:"flex items-center gap-2 px-3 py-2 text-xs font-semibold text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",children:[e.jsx(ae,{size:12,fill:"currentColor"}),e.jsx("span",{children:s("停止")})]}),e.jsxs("button",{onClick:T,disabled:!m.trim(),className:`flex items-center gap-2 px-3 py-2 text-xs font-semibold rounded-lg transition-all ${m.trim()?"bg-neutral-900 text-white hover:bg-black shadow-sm":"bg-neutral-100 text-neutral-400 cursor-not-allowed"}`,children:[e.jsx("span",{children:s("发送")}),e.jsx(ve,{size:14})]})]})]})]})})]})}export{Oe as AgentDemoPage};
|
|
1
|
+
import{c as H,j as e,u as te,aK as se,r,v as b,B as N,aO as re,aM as ne,au as ae}from"./index-BJObbxud.js";import{u as le,a as oe,L as ie,T as ce}from"./useNormalizedLogs--RbVywYa.js";import{a as de}from"./mermaid-NOHMQCX5-BSNbBj78.js";import"./AttachmentPreview-CLN1lnLe.js";import{d as xe}from"./use-profiles-DuXaBRju.js";import{C as me}from"./chevron-up-DqaYcjpq.js";import{C as ue}from"./chevron-down-3y5Aiolp.js";import{P as pe}from"./paperclip-CTNoXpUW.js";import{A as he}from"./at-sign-C48_y345.js";import{G as ge}from"./globe-B9I-jHBB.js";import"./track-Ckye0-tt.js";import"./use-translation-settings-NYM0lmBx.js";import"./copy-HRMhTkIG.js";import"./index-DcOU2m2F.js";import"./index-Bhvt-E6d.js";import"./index-B1oVmCie.js";import"./tooltip-CPqGK_WZ.js";import"./kbd-C88ut3t9.js";import"./index-Dk3bRQAK.js";const fe=[["line",{x1:"4",x2:"20",y1:"9",y2:"9",key:"4lhtct"}],["line",{x1:"4",x2:"20",y1:"15",y2:"15",key:"vyu0kd"}],["line",{x1:"10",x2:"8",y1:"3",y2:"21",key:"1ggp8o"}],["line",{x1:"16",x2:"14",y1:"3",y2:"21",key:"weycgp"}]],be=H("hash",fe);const je=[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]],ve=H("send",je),B=({className:s})=>e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:s,xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5",opacity:"0.4"}),e.jsx("circle",{cx:"8",cy:"8",r:"3",fill:"currentColor"})]}),ye=({className:s})=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:s,xmlns:"http://www.w3.org/2000/svg",children:e.jsx("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"1.5"})}),Ne=({className:s})=>e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:s,xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M13.5 4.5L6.5 11.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),we=!0;function Oe(){const{t:s}=te(),{preserveDesktopSearch:M}=se(),[w,U]=r.useState([]),[o,S]=r.useState(""),[x,k]=r.useState("DEFAULT"),[i,A]=r.useState(""),[a,C]=r.useState(null),[V,D]=r.useState(null),[l,c]=r.useState("idle"),[g,E]=r.useState(!1),[m,j]=r.useState(""),$=r.useRef(null),I=r.useRef(null),u=r.useRef(null),{data:p}=xe(o),F=p?Object.keys(p):["DEFAULT"],O=t=>{S(t),k("DEFAULT")},_=r.useCallback(t=>{c(t===0?"stopped":"error")},[]),G=r.useCallback(t=>{console.error("Agent error:",t),c("error")},[]),{isConnected:h,isAttached:f,isOutputActive:W,lastExitAt:K,logs:v,entries:q,agentSessionId:L,attach:z,clearLogs:P}=le({sessionId:a||"",sessionStartedAt:V,onExit:_,onError:G}),{todos:R}=oe(q);r.useEffect(()=>{b.get("/demo/agents").then(t=>{U(t.agents);const n=t.agents.find(y=>y.available);n&&S(n.type)})},[]),r.useEffect(()=>{$.current?.scrollToBottom("smooth")},[v]),r.useEffect(()=>{console.log(`[AgentDemoPage:useEffect] t=${Date.now()} sessionId=${a} isConnected=${h} isAttached=${f}`),a&&h&&!f&&(console.log(`[AgentDemoPage:useEffect] t=${Date.now()} calling attach()`),z())},[a,h,f,z]);const J=t=>{if(j(t.target.value),u.current){u.current.style.height="auto";const y=Math.min(u.current.scrollHeight,210);u.current.style.height=`${y}px`}},Q=async()=>{if(!o||!i.trim())return;const t=Date.now();console.log(`[AgentDemoPage:handleStart] t=${t} starting...`),c("starting"),P();try{const n=await b.post("/demo/start",{agentType:o,prompt:i.trim(),variant:x});we&&console.log(`[AgentDemoPage:handleStart] t=${Date.now()} apiTime=${Date.now()-t}ms sessionId=${n.sessionId}`),C(n.sessionId),D(t),c("running")}catch(n){console.error("Start failed:",n),c("error")}},T=async()=>{if(!a||!m.trim())return;const t=m.trim();j("");try{await b.post(`/demo/${a}/message`,{message:t})}catch(n){console.error("Send failed:",n)}},X=async()=>{if(a)try{await b.post(`/demo/${a}/stop`),c("stopped")}catch(t){console.error("Stop failed:",t)}},Y=()=>{C(null),D(null),c("idle"),A(""),j(""),P()},Z=l==="running",d=a!==null,ee=w.find(t=>t.type===o);return e.jsxs("div",{className:"flex flex-col h-full bg-white",children:[e.jsxs("div",{className:"px-8 py-5 border-b border-neutral-100 bg-white transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsx("span",{className:"text-base font-medium text-blue-600",children:"Agent Demo"}),e.jsx("span",{className:"text-neutral-300 text-sm",children:"/"}),e.jsx("span",{className:"text-xl font-bold text-neutral-900 tracking-tight",children:d?i.slice(0,50)+(i.length>50?"...":""):s("新会话")})]}),e.jsxs("div",{className:"flex items-center",children:[l==="running"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-blue-50 text-blue-700 rounded-full text-xs font-medium border border-blue-100",children:[e.jsx(B,{className:"w-3.5 h-3.5 animate-pulse"}),e.jsx("span",{children:"Running"})]}),l==="stopped"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-emerald-50 text-emerald-700 rounded-full text-xs font-medium border border-emerald-100",children:[e.jsx(Ne,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Done"})]}),l==="idle"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-neutral-100 text-neutral-600 rounded-full text-xs font-medium border border-neutral-200",children:[e.jsx(ye,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Idle"})]}),l==="starting"&&e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-amber-50 text-amber-700 rounded-full text-xs font-medium border border-amber-100",children:[e.jsx(B,{className:"w-3.5 h-3.5 animate-spin"}),e.jsx("span",{children:"Starting..."})]}),l==="error"&&e.jsx("div",{className:"flex items-center gap-1.5 px-2.5 py-0.5 bg-red-50 text-red-700 rounded-full text-xs font-medium border border-red-100",children:e.jsx("span",{children:"Error"})})]})]}),d&&e.jsxs("div",{className:"mt-1.5 flex items-start gap-2 group max-w-4xl",children:[e.jsx("div",{className:`text-sm text-neutral-600 leading-relaxed cursor-pointer transition-all ${g?"":"truncate"}`,onClick:()=>E(!g),children:i}),e.jsx("button",{onClick:()=>E(!g),className:"mt-0.5 text-neutral-400 opacity-0 group-hover:opacity-100 hover:text-neutral-600 transition-opacity",children:g?e.jsx(me,{size:14}):e.jsx(ue,{size:14})})]}),e.jsxs("div",{className:"flex items-center gap-6 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:"Agent"}),e.jsx("div",{className:"flex items-center gap-1.5 text-neutral-900 font-medium bg-neutral-50 px-2 py-1 rounded border border-neutral-100",children:ee?.name||o||s("未选择")})]}),x!=="DEFAULT"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:"Variant"}),e.jsx("div",{className:"flex items-center gap-1.5 text-neutral-700 font-medium bg-blue-50 px-2 py-1 rounded border border-blue-100",children:x})]}),L&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:"Session"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-neutral-700 font-mono bg-neutral-50 px-2 py-1 rounded border border-neutral-100",children:[L.slice(0,8),"..."]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-neutral-400 font-medium",children:s("连接")}),e.jsx("div",{className:`flex items-center gap-1.5 font-medium px-2 py-1 rounded border ${h?"text-emerald-700 bg-emerald-50 border-emerald-100":"text-neutral-500 bg-neutral-50 border-neutral-100"}`,children:s(h?f?"已连接":"连接中...":"未连接")})]}),d&&e.jsx(N,{variant:"outline",size:"sm",onClick:Y,className:"ml-auto",children:s("新会话")}),e.jsxs(re,{to:M("/settings/profiles"),className:`flex items-center gap-1.5 text-xs text-neutral-500 hover:text-neutral-900 transition-colors ${d?"":"ml-auto"}`,children:[e.jsx(ne,{size:14}),e.jsx("span",{children:s("Profiles 设置")})]})]})]}),e.jsx("div",{ref:I,className:"flex-1 overflow-y-auto px-8 py-6",children:d?e.jsx("div",{className:"min-h-[200px]",children:v.length===0?e.jsx("div",{className:"text-neutral-400 text-center py-8",children:s("等待 Agent 响应...")}):e.jsx(ie,{children:e.jsx(de,{ref:$,logs:v,isOutputActive:W,lastExitAt:K,scrollElementRef:I})})}):e.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-neutral-900",children:s("选择 Agent")}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:w.map(t=>e.jsxs(N,{variant:o===t.type?"default":"outline",disabled:!t.available,onClick:()=>O(t.type),children:[t.name,t.available&&t.version&&` (${t.version})`,!t.available&&s(" (不可用)")]},t.type))})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-neutral-900",children:s("配置变体 (Profile Variant)")}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:F.map(t=>e.jsx("button",{onClick:()=>k(t),className:`px-3 py-1.5 rounded-full text-sm font-medium border transition-colors ${x===t?"bg-neutral-900 text-white border-neutral-900":"bg-white text-neutral-600 border-neutral-200 hover:border-neutral-400"}`,children:t},t))}),p&&p[x]&&e.jsx("p",{className:"mt-2 text-xs text-neutral-500 font-mono",children:Object.entries(p[x]).map(([t,n])=>`${t}: ${JSON.stringify(n)}`).join(", ")})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold mb-3 text-neutral-900",children:s("输入任务")}),e.jsxs("div",{className:"relative border border-neutral-200 rounded-xl shadow-sm bg-white focus-within:ring-1 focus-within:ring-neutral-300 focus-within:border-neutral-300 transition-all duration-200",children:[e.jsx("textarea",{value:i,onChange:t=>A(t.target.value),rows:4,placeholder:s("描述你想让 Agent 完成的任务..."),className:"w-full px-4 py-3 bg-transparent border-none focus:outline-none focus:ring-0 resize-none text-neutral-900 placeholder-neutral-400 leading-relaxed text-sm"}),e.jsx("div",{className:"flex items-center justify-end px-3 pb-3 pt-1",children:e.jsx(N,{onClick:Q,disabled:l==="starting"||!o||!i.trim(),children:s(l==="starting"?"启动中...":"开始")})})]})]})]})}),d&&R.length>0&&e.jsx("div",{className:"px-8 py-2 bg-white border-t border-neutral-100",children:e.jsx(ce,{todos:R})}),d&&e.jsx("div",{className:"px-8 py-6 border-t border-neutral-100 bg-white",children:e.jsxs("div",{className:"relative border border-neutral-200 rounded-xl shadow-sm bg-white focus-within:ring-1 focus-within:ring-neutral-300 focus-within:border-neutral-300 transition-all duration-200",children:[e.jsx("textarea",{ref:u,value:m,onChange:J,rows:3,placeholder:s("发送消息给 Agent..."),className:"w-full px-4 py-3 bg-transparent border-none focus:outline-none focus:ring-0 resize-none text-neutral-900 placeholder-neutral-400 leading-relaxed text-sm scrollbar-thin scrollbar-thumb-neutral-200 scrollbar-track-transparent",style:{minHeight:"80px",maxHeight:"210px"},onKeyDown:t=>{t.key==="Enter"&&!t.shiftKey&&!t.repeat&&!t.nativeEvent.isComposing&&t.nativeEvent.keyCode!==229&&(t.preventDefault(),T())}}),e.jsxs("div",{className:"flex items-center justify-between px-3 pb-3 pt-1 border-t border-transparent",children:[e.jsxs("div",{className:"flex items-center gap-1 text-neutral-400",children:[e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Attach File",children:e.jsx(pe,{size:18})}),e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Mention",children:e.jsx(he,{size:18})}),e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Reference Issue",children:e.jsx(be,{size:18})}),e.jsx("div",{className:"w-px h-4 bg-neutral-200 mx-1"}),e.jsx("button",{className:"p-2 hover:bg-neutral-100 hover:text-neutral-600 rounded-lg transition-colors",title:"Search Web",children:e.jsx(ge,{size:18})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[Z&&e.jsxs("button",{onClick:X,className:"flex items-center gap-2 px-3 py-2 text-xs font-semibold text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",children:[e.jsx(ae,{size:12,fill:"currentColor"}),e.jsx("span",{children:s("停止")})]}),e.jsxs("button",{onClick:T,disabled:!m.trim(),className:`flex items-center gap-2 px-3 py-2 text-xs font-semibold rounded-lg transition-all ${m.trim()?"bg-neutral-900 text-white hover:bg-black shadow-sm":"bg-neutral-100 text-neutral-400 cursor-not-allowed"}`,children:[e.jsx("span",{children:s("发送")}),e.jsx(ve,{size:14})]})]})]})]})})]})}export{Oe as AgentDemoPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as e,j as n,i as s,k as i,A as r}from"./index-
|
|
1
|
+
import{u as e,j as n,i as s,k as i,A as r}from"./index-BJObbxud.js";function g(){const{t}=e();return n.jsxs(s,{children:[n.jsx(i,{title:t("Agent 环境"),description:t("检测并安装本机 Agent CLI。安装前会展示官方来源、风险和校验摘要。")}),n.jsx(r,{})]})}export{g as AgentEnvironmentSettingsPage};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{c as M,b6 as N,b7 as H,b8 as T,q as U,o as P,r as p,p as X,s as G,v as k,aI as D,a2 as W,j as f,n as q,u as V,Q as Y,X as Z}from"./index-BJObbxud.js";import{T as ee,F as te}from"./tooltip-CPqGK_WZ.js";const se=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],ne=M("image",se),S=new Map,B="tower:system-submission:",I=e=>Object.fromEntries(Object.entries(e).filter(([t])=>t!=="resolutionContextToken")),v=e=>"resolutionContextToken"in e?String(e.resolutionContextToken):void 0,E=e=>T(v(e))??I(e);let b=!1;const he=()=>b;function K(e){if(!e||typeof e!="object")return;const t=e;if(!(typeof t.id!="string"||!/^[0-9a-f-]{36}$/i.test(t.id)||typeof t.key!="string"||!t.identity||typeof t.identity!="object"||t.body!==void 0&&(!t.body||typeof t.body!="object"||Array.isArray(t.body))))return t}function pe(e){const t=T(e);if(t)return z(),[...S.values()].find(s=>JSON.stringify(s.identity)===JSON.stringify(t)&&s.key.startsWith("message:"))?.key.slice(8)}function z(){try{for(let e=0;e<sessionStorage.length;e++){const t=sessionStorage.key(e);if(t?.startsWith(B)){const s=K(JSON.parse(sessionStorage.getItem(t)));s?S.set(t,s):b=!0}}}catch{b=!0}}function ie(e,t){z();for(const s of S.values()){if(!s.body||!s.key.startsWith("message:"))continue;const n=v(s.body),i=N(n);if(i?.actor===e&&i.context.sourceWorkspaceId===t)return{token:n,receiverSessionId:s.key.slice(8),identity:s.identity}}}async function be(e,t,s){const n="systemAction"in t&&t.systemAction==="resolve_conflicts",i=n?E(t):t,c=n?N(v(t)):void 0,m=c?.context?.sourceWorkspaceId,d=c&&m?ie(c.actor,m):void 0;if(d&&(JSON.stringify(d.identity)!==JSON.stringify(i)||e!==`message:${d.receiverSessionId}`))throw new Error("Check the original conflict submission with its original Session, UUID and body before starting another request.");const g=n?`${B}${e}:${JSON.stringify(i)}`:`tower:user-submission:${e}:${JSON.stringify(t)}`;let l=S.get(g);const w=[];try{const r=sessionStorage.getItem(g);if(r){const o=n?K(JSON.parse(r)):{id:r,key:e,identity:i};if(!o||o.key!==e||JSON.stringify(o.identity)!==JSON.stringify(i))throw new Error("Invalid pending submission");l=o}if(n&&!l){const o=`tower:user-submission:${e}:`;for(let y=0;y<sessionStorage.length;y++){const u=sessionStorage.key(y);if(!u?.startsWith(o)||u.endsWith(":body"))continue;const h=JSON.parse(u.slice(o.length)),J=sessionStorage.getItem(`${u}:body`),x=J?JSON.parse(J):h,A=N(v(x)),C=N(v(t));if(!A&&C&&JSON.stringify(I(x))===JSON.stringify(I(t)))throw new Error("Incomplete legacy submission");if(A||C){if(JSON.stringify(E(x))!==JSON.stringify(i))continue}else if(JSON.stringify(I(x))!==JSON.stringify(I(t)))continue;const F=sessionStorage.getItem(u);if(F){l={id:F,key:e,identity:i,body:x},w.push(u,`${u}:body`);break}}}}catch{if(b=!0,n)throw new Error("Pending submission storage is unavailable or damaged. Preserve the operation details and check the original submission before sending again.")}l??={id:H(),key:e,identity:i},n&&(l.body??=t),S.set(g,l);try{sessionStorage.setItem(g,n?JSON.stringify(l):l.id);for(const r of w)sessionStorage.removeItem(r)}catch{b=!0}let a;try{a=await s({...l.body??t,clientSubmissionId:l.id})}catch(r){if(n&&r.details?.accepted===!1){l.body=void 0;try{sessionStorage.setItem(g,JSON.stringify(l))}catch{b=!0}}throw r}S.delete(g);try{sessionStorage.removeItem(g)}catch{b=!0}return a}function Q(e,t,s){const n=`tower:user-submission:${e}:${JSON.stringify(t)}`;S.get(n)?.id===s&&S.delete(n);try{sessionStorage.getItem(n)===s&&sessionStorage.removeItem(n)}catch{b=!0}}const R="tower:outgoing:",j=e=>["outgoing-submissions",e];function $(e){try{const t=JSON.parse(sessionStorage.getItem(R+e)??"[]");return Array.isArray(t)?t.filter(s=>s&&s.scope===e&&typeof s.id=="string"&&typeof s.path=="string"&&typeof s.text=="string"&&s.body?.clientSubmissionId===s.id).map(s=>({...s,failed:!0})):[]}catch{return[]}}function O(e,t,s){const n=s(e.getQueryData(j(t))??$(t));e.setQueryData(j(t),n);try{sessionStorage.setItem(R+t,JSON.stringify(n))}catch{}}function Se(e,t=[]){const s=U(),n=P({queryKey:j(e),queryFn:()=>$(e),initialData:()=>$(e),staleTime:1/0});return p.useEffect(()=>{const i=n.data.filter(c=>t.includes(c.id));if(i.length){for(const c of i)Q(L(c),_(c.body),c.id);O(s,e,c=>c.filter(m=>!t.includes(m.id)))}},[s,e,n.data,t]),n.data}async function re(e,t,s,n,i){const c="message"in n?String(n.message):"prompt"in n?String(n.prompt):"";if("systemAction"in n)return k.post(s,n);O(e,t,m=>[...m.filter(d=>d.id!==n.clientSubmissionId),{id:n.clientSubmissionId,scope:t,path:s,body:n,text:c,createdAt:m.find(d=>d.id===n.clientSubmissionId)?.createdAt??new Date().toISOString(),failed:!1}]);try{const m=await k.post(s,n),d=i?await i(m):m;return d&&typeof d=="object"&&"operationId"in d&&D(e,d.delivery),O(e,t,g=>g.filter(l=>l.id!==n.clientSubmissionId)),d}catch(m){throw O(e,t,d=>d.map(g=>g.id===n.clientSubmissionId?{...g,failed:!0}:g)),m}}function _(e){return Object.fromEntries(Object.entries(e).filter(([t])=>t!=="clientSubmissionId"))}function L(e){return e.path==="/conversations"?"conversation:create":e.path.startsWith("/sessions/")?`message:${e.scope}`:`conversation:message:${e.path.split("/")[2]}`}async function oe(e,t){return"operationId"in t&&"sessionId"in t?(D(e,t.delivery),k.get(`/conversations/${t.destinationId}`)):t}function xe(e){const t=U();return X({mutationFn:()=>ae(t,e),onSuccess:s=>(e.path==="/conversations"&&"id"in s&&t.setQueryData(G.conversations.detail(s.id),s),t.invalidateQueries())})}async function ae(e,t){const s=await re(e,t.scope,t.path,t.body,t.path==="/conversations"?n=>oe(e,n):void 0);return Q(L(t),_(t.body),t.id),s}const ce=W();async function de(e){const t=new FormData;t.append("file",e);const s=await fetch(`${ce}/attachments/upload`,{method:"POST",body:t});if(!s.ok){const n=await s.json().catch(()=>({}));throw new Error(n.error||`Upload failed (${s.status})`)}return s.json()}let ue=0;function Ie(){const[e,t]=p.useState([]),s=p.useRef(e);s.current=e;const n=p.useCallback(async a=>{const r=a.map(o=>({tempId:`tmp-${++ue}`,file:o,progress:0,status:"uploading"}));t(o=>[...o,...r]),await Promise.allSettled(r.map(async o=>{try{const y=await de(o.file);t(u=>u.map(h=>h.tempId===o.tempId?{...h,status:"done",progress:100,attachment:y}:h))}catch(y){t(u=>u.map(h=>h.tempId===o.tempId?{...h,status:"error",error:y instanceof Error?y.message:"Upload failed"}:h))}}))},[]),i=p.useCallback(()=>s.current.filter(a=>a.status==="done"&&a.attachment).map(a=>a.attachment),[]),c=p.useCallback(a=>{t(r=>r.filter(o=>o.tempId!==a))},[]),m=p.useCallback(()=>{t([])},[]),d=p.useCallback(a=>{a.length!==0&&t(r=>{const o=new Set(r.map(u=>u.attachment?.id??u.tempId)),y=a.filter(u=>{const h=u.attachment?.id??u.tempId;return o.has(h)?!1:(o.add(h),!0)});return y.length>0?[...r,...y]:r})},[]),g=p.useCallback(()=>{const a=i();return a.length===0?"":a.map(r=>`${r.mimeType.startsWith("image/")?"!":""}[${r.originalName}](${r.storagePath})`).join(`
|
|
2
|
+
`)},[i]),l=e.length>0,w=e.some(a=>a.status==="uploading");return{files:e,addFiles:n,removeFile:c,clear:m,restoreFiles:d,buildMarkdownLinks:g,getDoneAttachments:i,hasFiles:l,isUploading:w}}function ve(e){const t=p.useMemo(()=>Array.from(new Set(e.filter(Boolean))),[e]);return P({queryKey:["attachments","metadata",t],queryFn:()=>k.get("/attachments/metadata",{params:{ids:t.join(",")}}),enabled:t.length>0,staleTime:300*1e3})}function we({content:e,children:t,className:s,side:n="top",align:i="center"}){return f.jsx(ee,{content:e,side:n,align:i,children:f.jsx("div",{className:q("relative inline-block [&>:disabled]:pointer-events-none",s),children:t})})}const le=W();function fe(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}function Ne({files:e,onRemove:t}){return e.length===0?null:f.jsx("div",{"aria-label":"Attachments",className:"flex flex-wrap gap-2 px-4 pt-3 pb-1",children:e.map(s=>f.jsx(ge,{item:s,onRemove:t},s.tempId))})}function ge({item:e,onRemove:t}){const{t:s}=V(),n=e.file.type.startsWith("image/"),i=e.status==="error",c=e.status==="uploading";return f.jsxs("div",{className:q("relative group flex items-center gap-2 px-3 py-2 rounded-lg border text-xs max-w-[200px]",i?"border-destructive/25 bg-destructive/[0.06] text-destructive-ink":"border-border bg-muted/50 text-foreground/80"),children:[n&&e.status==="done"&&e.attachment?f.jsx("img",{src:`${le}${e.attachment.url}`,alt:e.file.name,className:"w-8 h-8 rounded object-cover flex-shrink-0"}):f.jsx("span",{className:"flex-shrink-0",children:c?f.jsx(Y,{size:16,className:"animate-spin motion-reduce:[animation-duration:2.4s] text-muted-foreground"}):n?f.jsx(ne,{size:16,className:"text-muted-foreground"}):f.jsx(te,{size:16,className:"text-muted-foreground"})}),f.jsxs("div",{className:"min-w-0 flex-1",children:[f.jsx("div",{className:"truncate font-medium",children:e.file.name}),i?f.jsx("div",{className:"truncate",children:e.error}):f.jsx("div",{className:"text-muted-foreground",children:fe(e.file.size)})]}),f.jsx("button",{type:"button",onClick:()=>t(e.tempId),"aria-label":`${s("Remove")} ${e.file.name}`,className:"absolute -top-1.5 -right-1.5 flex size-5 items-center justify-center rounded-full bg-inverse text-inverse-foreground opacity-0 shadow-raised transition-opacity hover:bg-inverse/90 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 group-hover:opacity-100 pointer-coarse:opacity-100",children:f.jsx(Z,{size:10})})]})}export{Ne as A,we as T,be as a,Se as b,ve as c,he as d,ie as e,xe as f,pe as p,oe as r,re as s,Ie as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as I,r as i,j as a,N as M,O as S,n as j,Q as A}from"./index-
|
|
1
|
+
import{u as I,r as i,j as a,N as M,O as S,n as j,Q as A}from"./index-BJObbxud.js";import{S as B}from"./search-field-CQLDXLeA.js";import{M as P,a as z,b as K}from"./menu-styles-DWynpVVz.js";import{P as U,a as O,b as R}from"./popover-BiVxGGgp.js";import{C as $}from"./chevron-down-3y5Aiolp.js";import{C as L}from"./check-BmiJ7qMY.js";function G({id:y,label:p,value:o,branches:l,disabled:N,isRefreshing:k,onChange:v,onOpen:C}){const{t}=I(),m=i.useId(),x=i.useRef(null),[c,g]=i.useState(!1),[r,f]=i.useState(""),[h,s]=i.useState(0),n=l.filter(e=>e.toLowerCase().includes(r.trim().toLowerCase())),u=n[h],D=l.includes(o),w=e=>{g(e),e&&(f(""),s(Math.max(0,l.indexOf(o))),C())},b=e=>{v(e),g(!1)};i.useEffect(()=>{c&&x.current?.querySelector("[data-highlighted]")?.scrollIntoView?.({block:"nearest"})},[c,h,r]);const E=e=>{e.nativeEvent.isComposing||(e.key==="ArrowDown"||e.key==="ArrowUp"?(e.preventDefault(),s(d=>Math.max(0,Math.min(n.length-1,d+(e.key==="ArrowDown"?1:-1))))):!r&&(e.key==="Home"||e.key==="End")?(e.preventDefault(),s(e.key==="Home"?0:Math.max(0,n.length-1))):e.key==="Enter"&&u&&(e.preventDefault(),b(u)))};return a.jsxs(U,{open:c,onOpenChange:w,children:[a.jsx(O,{asChild:!0,children:a.jsxs(M,{id:y,"aria-label":p,"aria-haspopup":"listbox",disabled:N,size:"lg",title:o,className:"w-full min-w-0 justify-between border border-input px-3 font-normal shadow-none ring-0 hover:border-ring/50 hover:bg-background focus-visible:border-ring focus-visible:ring-0 data-[state=open]:border-ring",onKeyDown:e=>{!c&&(e.key==="ArrowDown"||e.key==="ArrowUp")&&(e.preventDefault(),w(!0))},children:[a.jsx(S,{className:"size-3.5 text-muted-foreground"}),a.jsxs("span",{className:"min-w-0 flex-1 truncate text-left",children:[o,!D&&` (${t("Unavailable")})`]}),a.jsx($,{className:j("size-3.5 text-muted-foreground transition-transform",c&&"rotate-180")})]})}),a.jsxs(R,{"aria-label":p,className:"z-[70] flex max-h-[min(24rem,var(--radix-popover-content-available-height))] w-(--radix-popover-trigger-width) max-w-[calc(100vw-1rem)] flex-col overflow-hidden p-1",onKeyDown:e=>{e.key==="Escape"&&e.stopPropagation()},onEscapeKeyDown:e=>{e.stopPropagation(),r&&(e.preventDefault(),f(""),s(0))},children:[a.jsx("div",{className:"shrink-0 p-1",children:a.jsx(B,{"aria-label":t("Search branches"),placeholder:t("Search branches"),role:"combobox","aria-expanded":!0,"aria-autocomplete":"list","aria-controls":m,"aria-activedescendant":u?`${m}-${h}`:void 0,value:r,onValueChange:e=>{f(e),s(0)},onKeyDown:E})}),a.jsxs("div",{ref:x,id:m,role:"listbox","aria-label":p,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[n.map((e,d)=>a.jsxs("button",{id:`${m}-${d}`,type:"button",role:"option","aria-selected":e===o,"data-highlighted":d===h?"":void 0,tabIndex:-1,title:e,onPointerMove:()=>s(d),onClick:()=>b(e),className:j(K,z,e===o&&"font-medium text-foreground"),children:[a.jsx("span",{className:"min-w-0 flex-1 truncate",children:e}),e===o&&a.jsx("span",{className:P,children:a.jsx(L,{className:"size-3.5"})})]},e)),n.length===0&&a.jsx("p",{className:"px-2 py-3 text-xs text-muted-foreground",children:t("No matching branches")})]}),a.jsxs("div",{role:"status",className:"flex shrink-0 items-center gap-1.5 border-t border-border/60 px-2 pt-2 pb-1 text-xs tabular-nums text-muted-foreground",children:[k&&a.jsx(A,{className:"size-3 animate-spin motion-reduce:[animation-duration:2.4s]","aria-label":t("Refreshing branches")}),r.trim()?t("{shown} of {total} local branches",{shown:n.length,total:l.length}):t("{count} local branches",{count:l.length})]})]})]})}export{G as B};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as N,r as S,x,j as a,P as m,C as E,a8 as i,E as M,n as b}from"./index-
|
|
1
|
+
import{c as N,r as S,x,j as a,P as m,C as E,a8 as i,E as M,n as b}from"./index-BJObbxud.js";import{u as V}from"./hooks-BLxb16IA.js";import{I as A,c as C,R as D}from"./index-BtUQYU5l.js";import{u as F}from"./index-DZLnTISJ.js";const B=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],X=N("square-pen",B);var P="Toggle",T=S.forwardRef((e,t)=>{const{pressed:l,defaultPressed:r,onPressedChange:s,...u}=e,[n,o]=x({prop:l,onChange:s,defaultProp:r??!1,caller:P});return a.jsx(m.button,{type:"button","aria-pressed":n,"data-state":n?"on":"off","data-disabled":e.disabled?"":void 0,...u,ref:t,onClick:E(e.onClick,()=>{e.disabled||o(!n)})})});T.displayName=P;var g="ToggleGroup",[j]=M(g,[C]),_=C(),h=i.forwardRef((e,t)=>{const{type:l,...r}=e;if(l==="single"){const s=r;return a.jsx(z,{...s,ref:t})}if(l==="multiple"){const s=r;return a.jsx(L,{...s,ref:t})}throw new Error(`Missing prop \`type\` expected on \`${g}\``)});h.displayName=g;var[I,y]=j(g),z=i.forwardRef((e,t)=>{const{value:l,defaultValue:r,onValueChange:s=()=>{},...u}=e,[n,o]=x({prop:l,defaultProp:r??"",onChange:s,caller:g});return a.jsx(I,{scope:e.__scopeToggleGroup,type:"single",value:i.useMemo(()=>n?[n]:[],[n]),onItemActivate:o,onItemDeactivate:i.useCallback(()=>o(""),[o]),children:a.jsx(w,{...u,ref:t})})}),L=i.forwardRef((e,t)=>{const{value:l,defaultValue:r,onValueChange:s=()=>{},...u}=e,[n,o]=x({prop:l,defaultProp:r??[],onChange:s,caller:g}),d=i.useCallback(c=>o((p=[])=>[...p,c]),[o]),v=i.useCallback(c=>o((p=[])=>p.filter(R=>R!==c)),[o]);return a.jsx(I,{scope:e.__scopeToggleGroup,type:"multiple",value:n,onItemActivate:d,onItemDeactivate:v,children:a.jsx(w,{...u,ref:t})})});h.displayName=g;var[$,q]=j(g),w=i.forwardRef((e,t)=>{const{__scopeToggleGroup:l,disabled:r=!1,rovingFocus:s=!0,orientation:u,dir:n,loop:o=!0,...d}=e,v=_(l),c=F(n),p={role:"group",dir:c,...d};return a.jsx($,{scope:l,rovingFocus:s,disabled:r,children:s?a.jsx(D,{asChild:!0,...v,orientation:u,dir:c,loop:o,children:a.jsx(m.div,{...p,ref:t})}):a.jsx(m.div,{...p,ref:t})})}),f="ToggleGroupItem",k=i.forwardRef((e,t)=>{const l=y(f,e.__scopeToggleGroup),r=q(f,e.__scopeToggleGroup),s=_(e.__scopeToggleGroup),u=l.value.includes(e.value),n=r.disabled||e.disabled,o={...e,pressed:u,disabled:n},d=i.useRef(null);return r.rovingFocus?a.jsx(A,{asChild:!0,...s,focusable:!n,active:u,ref:d,children:a.jsx(G,{...o,ref:t})}):a.jsx(G,{...o,ref:t})});k.displayName=f;var G=i.forwardRef((e,t)=>{const{__scopeToggleGroup:l,value:r,...s}=e,u=y(f,l),n={role:"radio","aria-checked":e.pressed,"aria-pressed":void 0},o=u.type==="single"?n:void 0;return a.jsx(T,{...o,...s,ref:t,onPressedChange:d=>{d?u.onItemActivate(r):u.onItemDeactivate(r)}})}),H=h,O=k;function Y({options:e,value:t,defaultValue:l,onValueChange:r,size:s="md",block:u=!1,className:n,...o}){const[d,v]=V({value:t,defaultValue:l??e[0]?.value??"",onChange:r});return a.jsx(H,{type:"single",value:d,onValueChange:c=>{c&&v(c)},"aria-label":o["aria-label"],className:b("items-center gap-0.5 rounded-lg bg-foreground/[0.05] p-0.5",u?"flex w-full":"inline-flex w-fit",n),children:e.map(c=>a.jsxs(O,{value:c.value,disabled:c.disabled,className:b("inline-flex items-center justify-center gap-1.5 whitespace-nowrap rounded-md font-medium text-foreground/70 transition-[color,background-color,box-shadow] duration-150","hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 disabled:pointer-events-none disabled:opacity-40","data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:shadow-raised data-[state=on]:ring-1 data-[state=on]:ring-border/80",s==="md"?"h-7 px-3 text-xs [&_svg]:size-3.5":"h-6 px-2.5 text-xs [&_svg]:size-3",u&&"flex-1"),children:[c.icon,c.label,c.count!==void 0&&a.jsx("span",{className:"tabular-nums text-foreground/65",children:c.count})]},c.value))})}const U="/assets/agent-tower-lockup-DPAcheCt.png";function Z({className:e="h-6 w-auto max-[359px]:h-[22px]"}){return a.jsx("img",{src:U,alt:"Agent Tower",className:`block shrink-0 select-none object-contain ${e}`})}export{Z as B,X as S,Y as a};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as ze,u as ce,r,j as e,at as Ke,au as Qe,Q as Fe,av as Ue,n as C,o as Ce,q as ne,p as de,s as x,v as V,aI as ke,aJ as Be,aK as $e,aL as _e,an as T,ac as Ve,ad as ye,aM as Ge,aN as He,w as We,az as le}from"./index-Cm6snkmR.js";import{u as Je,A as Ye,a as Se,s as Ie,r as Xe,b as Ze}from"./AttachmentPreview-DRG5_cfN.js";import{a as et,d as De,O as tt}from"./mermaid-NOHMQCX5-BqeX1osS.js";import{g as st,a as nt}from"./ExecutionPermissionSelector-CQ_GNxR0.js";import{u as rt,a as at,L as ot,T as it}from"./useNormalizedLogs-D0N8MJdH.js";import{u as lt,a as ct,R as dt,P as ut,T as mt}from"./useTokenUsage-WB3ZQ25v.js";import{u as ft,C as xt}from"./CreateTaskInput-CxWPeToI.js";import{P as pt}from"./paperclip-COXNce_v.js";import{B as ht,S as gt}from"./BrandLogo-Ilm880Xs.js";import{u as vt}from"./use-providers-FMSfyTD1.js";import{S as Ae}from"./search-CkiBPir_.js";import{M as he}from"./message-square-E5K8E3A-.js";import{T as bt}from"./trash-2-CUM-XX8B.js";import"./tooltip-DbVtCXcO.js";import"./kbd-Bfq5K6Ux.js";import"./index-CAjqC8pT.js";import"./index-DNdMmXBr.js";import"./index-DppwrK2G.js";import"./use-translation-settings-BOlszecX.js";import"./copy-DyxlXxiU.js";import"./index-kr6U6_pi.js";import"./chevron-down-CPnvItQw.js";import"./check-DqPSoX0r.js";import"./track-C0vxnITw.js";import"./menu-C3uB3M7p.js";import"./menu-styles-DWynpVVz.js";import"./index-BYPOXP6w.js";import"./index-CPGzLjEC.js";import"./use-projects-BlTwWxkY.js";import"./MemberAvatar-B2pAdWUi.js";import"./people-BaCetIqh.js";import"./hooks-Ct0srfV-.js";const yt=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]],jt=ze("layout-list",yt);function Nt({sessionId:t,sessionStatus:n,sessionStartedAt:a,sessionEndedAt:u,agentType:h,runtimeType:f,providerId:m,providers:j,initialTokenUsage:g,onProviderChange:k,onSend:I,onStop:D,onExit:A,isSending:p=!1,isStopping:o=!1,canStop:v,className:N}){const{t:b}=ce(),[L,G]=r.useState(""),[q,H]=r.useState(m??""),O=st(j,q||m),[F,S]=r.useState(!1),W=r.useRef(null),re=r.useRef(null),ue=r.useRef(null),z=r.useRef(!1),{scrollRef:ae,contentRef:me,isAtBottom:fe,scrollToBottom:K,stopScroll:J}=lt({initial:"instant",resize:"smooth"}),{isConnected:Y,isLoadingSnapshot:i,isOutputActive:X,lastExitAt:Z,logs:U,entries:B,attach:$}=rt({sessionId:t,sessionStatus:n,sessionStartedAt:a,sessionEndedAt:u,onExit:A}),{todos:E}=at(B),oe=ct(U,g),{files:xe,addFiles:P,removeFile:pe,clear:ee,getDoneAttachments:ie,hasFiles:R,isUploading:Q}=Je(),{isActive:_,isCancelling:M}=ft(t,n),te=v??_;r.useEffect(()=>{H(m??"")},[m]),r.useEffect(()=>{t&&Y&&$()},[t,Y,$]);const s=r.useCallback(c=>{H(c),k?.(c)},[k]),l=r.useCallback(()=>{W.current&&(W.current.style.height="60px")},[]),d=r.useCallback(c=>{G(c.target.value);const w=c.target;w.style.height="auto",w.style.height=`${Math.max(60,Math.min(w.scrollHeight,300))}px`},[]),y=r.useCallback(async()=>{if(!L.trim()&&!R||z.current||p||o||M||Q||O)return;z.current=!0;const c=ie().map(se=>se.id),w=L.trim()||(c.length?" ":"");G(""),ee(),l();try{await I({message:w,providerId:q||void 0,attachmentIds:c}),await $(),requestAnimationFrame(()=>K("smooth"))}catch{}finally{z.current=!1}},[L,R,p,o,M,Q,ie,ee,l,I,q,O,$,K]),Le=r.useCallback(async()=>{!te||o||M||await D()},[te,o,M,D]),Pe=r.useCallback(c=>{const w=c.target.files;w&&w.length>0&&P(Array.from(w)),c.target.value=""},[P]),Me=r.useCallback(c=>{const w=c.clipboardData.items,se=[];for(const ve of w)if(ve.kind==="file"){const be=ve.getAsFile();be&&se.push(be)}se.length>0&&(c.preventDefault(),P(se))},[P]),Re=r.useCallback(c=>{c.preventDefault(),S(!0)},[]),qe=r.useCallback(c=>{c.preventDefault(),S(!1)},[]),Oe=r.useCallback(c=>{c.preventDefault(),S(!1);const w=c.dataTransfer.files;w.length>0&&P(Array.from(w))},[P]);return e.jsxs("div",{className:C("relative flex min-h-0 flex-1 flex-col bg-background",N),children:[e.jsxs("div",{className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:ae,className:"h-full overflow-y-auto scrollbar-app-thin px-6 pb-4 pt-6",children:e.jsx("div",{ref:me,className:"mx-auto w-full min-w-0 max-w-4xl",children:i?e.jsxs("div",{className:"flex items-center justify-center gap-3 py-12 text-muted-foreground",children:[e.jsxs("svg",{className:"h-5 w-5 animate-spin motion-reduce:[animation-duration:2.4s]",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),e.jsx("span",{className:"text-sm",children:b("Loading logs...")})]}):U.length===0&&!t?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:b(_?"Waiting for agent output...":"No logs recorded for this session.")}):e.jsx(ot,{children:e.jsx(et,{logs:U,sessionId:t,downloadSessionId:t,isOutputActive:X,lastExitAt:Z,onUserToggleDetails:J,scrollElementRef:ae})})})}),!fe&&e.jsxs("button",{type:"button",onClick:()=>K(),className:"absolute bottom-3 left-1/2 z-10 flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-raised backdrop-blur-sm transition-all hover:bg-background hover:text-foreground","aria-label":b("Scroll to bottom"),children:[e.jsx(Ke,{size:14}),e.jsx("span",{children:b("Back to bottom")})]})]}),E.length>0&&e.jsx("div",{className:"shrink-0 border-t border-border/60 bg-background px-6 pb-1 pt-2",children:e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsx(it,{todos:E})})}),e.jsx("div",{className:"z-10 w-full shrink-0 border-t border-transparent bg-background p-6 pb-6 pt-2",onDragOver:Re,onDragLeave:qe,onDrop:Oe,children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsx(dt,{sessionId:t}),e.jsxs("div",{ref:ue,className:C("relative rounded-xl border bg-background transition-colors duration-200 hover:border-ring/40 focus-within:border-ring/60",F?"border-foreground/40 bg-foreground/[0.02]":"border-border"),children:[e.jsx(Ye,{files:xe,onRemove:pe}),e.jsx("textarea",{ref:W,value:L,onChange:d,onPaste:Me,onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!c.repeat&&!c.nativeEvent.isComposing&&c.nativeEvent.keyCode!==229&&(c.preventDefault(),y())},rows:1,placeholder:b(F?"Drop files here...":t&&!_?"Continue conversation...":"Message Agent..."),className:"w-full resize-none border-none bg-transparent px-4 pb-2 pt-4 text-sm leading-relaxed text-foreground placeholder-muted-foreground/70 focus:outline-none",style:{minHeight:"60px",maxHeight:"300px"}}),e.jsx("input",{ref:re,type:"file",multiple:!0,className:"hidden",onChange:Pe}),e.jsxs("div",{className:"flex items-center justify-between px-2 pb-2 pt-1",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("button",{type:"button",onClick:()=>re.current?.click(),disabled:Q,className:"rounded-lg p-2 text-muted-foreground transition-colors hover:bg-muted hover:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",title:b("Upload file"),children:e.jsx(pt,{size:18})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{providers:j,currentProviderId:q,agentType:h,runtimeType:f,onSelect:s}),e.jsx(mt,{usage:oe}),te&&_&&!p&&!L.trim()&&!R?e.jsx("button",{type:"button",onClick:Le,disabled:o||M,className:"rounded-lg bg-destructive-ink p-2 text-white transition-all duration-200 hover:bg-destructive-ink/90 disabled:opacity-50",title:b("Stop"),"aria-label":b("Stop"),children:e.jsx(Qe,{size:14})}):e.jsx("button",{type:"button",onClick:y,disabled:!L.trim()&&!R||Q||p||o||M||!!O,className:C("rounded-lg p-2 transition-all duration-200",(L.trim()||R)&&!Q&&!p&&!o&&!M&&!O?"bg-primary text-primary-foreground hover:bg-primary/90":"cursor-not-allowed bg-transparent text-muted-foreground"),title:b(p?"发送中...":"Send"),"aria-label":b(p?"发送中...":"Send"),"aria-busy":p,children:p?e.jsx(Fe,{size:18,className:"animate-spin"}):e.jsx(Ue,{size:18})})]})]})]})]})})]})}function wt(t=50){return Ce({queryKey:x.conversations.list({limit:t}),queryFn:()=>V.get("/conversations",{params:{limit:String(t)}})})}function Ct(t){return Ce({queryKey:x.conversations.detail(t??""),queryFn:()=>V.get(`/conversations/${t}`),enabled:!!t})}function kt(){const t=ne();return de({mutationFn:n=>Se("conversation:create",n,async a=>{const u=await Ie(t,"new-conversation","/conversations",a,h=>Xe(t,h));return"operationId"in u?(ke(t,u.delivery),t.invalidateQueries({queryKey:De(u.sessionId)}),V.get(`/conversations/${u.destinationId}`)):u}),onSuccess:n=>{t.setQueryData(x.conversations.detail(n.id),n),t.invalidateQueries({queryKey:x.conversations.all}),t.invalidateQueries({queryKey:x.sessions.detail(n.sessionId)})}})}function St(){const t=ne();return de({mutationFn:({id:n,sessionId:a,...u})=>Se(`conversation:message:${n}`,u,async h=>{const f=await Ie(t,a??t.getQueryData(x.conversations.detail(n))?.sessionId??`conversation:${n}`,`/conversations/${n}/message`,h);return"operationId"in f?(ke(t,f.delivery),t.invalidateQueries({queryKey:De(f.sessionId)}),V.get(`/conversations/${f.destinationId}`)):f}),onSuccess:n=>{t.setQueryData(x.conversations.detail(n.id),n),t.invalidateQueries({queryKey:x.conversations.all}),t.invalidateQueries({queryKey:x.sessions.detail(n.sessionId)})}})}function It(){const t=ne();return de({mutationFn:n=>V.post(`/conversations/${n}/stop`),onSuccess:n=>{t.setQueryData(x.conversations.detail(n.id),n),t.invalidateQueries({queryKey:x.conversations.all}),t.invalidateQueries({queryKey:x.sessions.detail(n.sessionId)})},onSettled:(n,a,u)=>{const h=t.getQueryData(x.conversations.detail(u)),f=n?.sessionId??h?.sessionId;t.invalidateQueries({queryKey:x.conversations.detail(u)}),f&&(t.invalidateQueries({queryKey:x.sessions.detail(f)}),t.invalidateQueries({queryKey:x.sessions.runtime(f)}))}})}function Dt(){const t=ne();return de({mutationFn:n=>V.delete(`/conversations/${n}`),onSuccess:(n,a)=>{t.removeQueries({queryKey:x.conversations.detail(a)}),t.invalidateQueries({queryKey:x.conversations.all})}})}const At=3e4,Ee="agent-tower:conversation-read-times";function Et(){try{const t=window.localStorage.getItem(Ee);if(!t)return{};const n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:Object.fromEntries(Object.entries(n).map(([a,u])=>[a,typeof u=="number"?u:Number(u)]).filter(a=>Number.isFinite(a[1])))}catch{return{}}}function je(t){try{window.localStorage.setItem(Ee,JSON.stringify(t))}catch{}}function Ne(t){const n=t.lastActiveAt??t.updatedAt??t.createdAt;if(!n)return 0;const a=new Date(n).getTime();return Number.isFinite(a)?a:0}function Tt(t=At){const[,n]=r.useState(0);r.useEffect(()=>{const a=setInterval(()=>n(u=>u+1),t);return()=>clearInterval(a)},[t])}function ge(t){return t===T.RUNNING||t===T.PENDING}function Te(t){if(!t)return"";const n=new Date(t);if(Number.isNaN(n.getTime()))return"";const a=Math.max(0,Math.floor((Date.now()-n.getTime())/1e3));return a<60?le("{count}s ago",{count:a}):a<3600?le("{count}m ago",{count:Math.floor(a/60)}):a<86400?le("{count}h ago",{count:Math.floor(a/3600)}):le("{count}d ago",{count:Math.floor(a/86400)})}function Lt(t,n){switch(t){case T.RUNNING:return n("Running");case T.PENDING:return n("Starting");case T.COMPLETED:return n("Completed");case T.FAILED:return n("Failed");case T.CANCELLED:return n("Stopped");default:return t}}function we({className:t,pulseClassName:n}){return e.jsxs("span",{className:"relative inline-flex h-2 w-2",children:[e.jsx("span",{className:C("absolute inline-flex h-full w-full animate-ping motion-reduce:animate-none rounded-full",n)}),e.jsx("span",{className:C("relative inline-flex h-2 w-2 rounded-full",t)})]})}function Pt({status:t,unread:n}){return ge(t)?e.jsx(we,{className:"bg-success",pulseClassName:"bg-success/70"}):n?e.jsx(we,{className:"bg-warning",pulseClassName:"bg-warning/70"}):null}function Mt({conversation:t,selected:n,onSelect:a,onDelete:u,disabled:h,unread:f}){const{t:m}=ce(),j=Te(t.lastActiveAt??t.createdAt),g=ge(t.status)||f;return e.jsxs("div",{className:C("group ml-4 mr-2 flex items-center rounded-md transition-colors",n?"bg-accent":"hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:a,title:t.title,className:"flex min-w-0 flex-1 animate-task-enter items-center gap-2.5 rounded-md px-2 py-2 text-left text-sm",children:[e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(he,{size:14,className:"text-muted-foreground"})}),e.jsx("span",{className:C("min-w-0 flex-1 truncate",n?"font-medium text-foreground":"text-foreground/90"),children:t.title}),g?e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(Pt,{status:t.status,unread:f})}):e.jsx("span",{className:"flex w-14 shrink-0 items-center justify-end text-[11px] tabular-nums text-muted-foreground",children:e.jsx("span",{className:"truncate group-hover:hidden",children:j})})]}),e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),u()},disabled:h,className:"mr-1 hidden shrink-0 rounded-md p-1.5 text-muted-foreground hover:bg-background hover:text-destructive disabled:opacity-50 group-hover:flex",title:m("Delete"),children:e.jsx(bt,{size:14})})]})}function Rt({isOpen:t,conversations:n,onClose:a,onSelectConversation:u}){const{t:h}=ce(),[f,m]=r.useState(""),[j,g]=r.useState(0),k=r.useRef(null);r.useEffect(()=>{t&&(m(""),g(0))},[t]);const I=r.useMemo(()=>{const o=f.trim().toLowerCase();return o?n.filter(v=>v.title.toLowerCase().includes(o)).slice(0,50):n.slice(0,12)},[n,f]);r.useEffect(()=>{g(0)},[f]),r.useEffect(()=>{k.current?.children[j]?.scrollIntoView({block:"nearest"})},[j]);const D=r.useCallback(o=>{u(o),a()},[a,u]),A=r.useCallback(o=>{if(o.key==="Escape"){o.preventDefault(),a();return}if(o.key==="ArrowDown"){o.preventDefault(),g(v=>Math.min(v+1,I.length-1));return}if(o.key==="ArrowUp"){o.preventDefault(),g(v=>Math.max(v-1,0));return}if(o.key==="Enter"&&!o.nativeEvent.isComposing){o.preventDefault();const v=I[j];v&&D(v)}},[j,D,a,I]);if(!t)return null;const p=f.trim().length>0;return e.jsxs("div",{className:"fixed inset-0 z-90",role:"dialog","aria-modal":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:a}),e.jsxs("div",{className:"absolute left-1/2 top-[18vh] w-[min(560px,calc(100vw-2rem))] -translate-x-1/2 overflow-hidden rounded-xl border border-border bg-popover shadow-popover animate-in fade-in zoom-in-95 duration-100",children:[e.jsxs("div",{className:"flex items-center gap-2.5 border-b border-border/60 px-4",children:[e.jsx(Ae,{size:15,className:"shrink-0 text-muted-foreground/70"}),e.jsx("input",{value:f,onChange:o=>m(o.target.value),onKeyDown:A,placeholder:h("Search conversations..."),"aria-label":h("Search conversations..."),autoFocus:!0,className:"flex-1 border-none bg-transparent py-3 text-sm text-foreground placeholder-muted-foreground/60 focus:outline-none"})]}),I.length>0?e.jsxs(e.Fragment,{children:[p?null:e.jsx("div",{className:"px-4 pb-1 pt-2.5 text-xs font-medium text-muted-foreground",children:h("Recent conversations")}),e.jsx("div",{ref:k,className:"max-h-[46vh] overflow-y-auto pb-1.5 pt-0.5 scrollbar-app-thin",children:I.map((o,v)=>e.jsxs("button",{type:"button",onClick:()=>D(o),onMouseEnter:()=>g(v),className:C("flex w-full items-center gap-2.5 px-4 py-2 text-left transition-colors",v===j&&"bg-accent"),children:[e.jsx(he,{size:14,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-foreground/90",title:o.title,children:o.title}),e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:Te(o.lastActiveAt??o.createdAt)})]},o.id))})]}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:h("No matching conversations")})]})]})}function xs(){const{t}=ce();Tt();const n=Be(),{usesIntegratedTitlebar:a,desktopPlatform:u,hasMacTrafficLights:h}=$e(),f=a&&u==="win32",{conversationId:m}=_e(),j=ne(),[g,k]=r.useState(""),[I,D]=r.useState("idle"),[A,p]=r.useState(!1),[o,v]=r.useState(0),N=r.useRef({conversationId:m,isCreatingNew:A,epoch:o});(N.current.conversationId!==m||N.current.isCreatingNew!==A||N.current.epoch!==o)&&(N.current={conversationId:m,isCreatingNew:A,epoch:o});const b=N.current,[L,G]=r.useState(!1),[q,H]=r.useState(Et),[O,F]=r.useState(()=>new Set),{data:S=[],isLoading:W}=wt(),{data:re,isLoading:ue}=Ct(m),{data:z=[],isLoading:ae}=vt(),me=Ze("new-conversation"),fe=kt(),K=St(),J=It(),Y=Dt(),i=re??S.find(s=>s.id===m)??null,X=r.useMemo(()=>z.map(s=>{const l=nt(s);return{id:s.provider.id,name:s.provider.name,agentType:s.provider.agentType,available:!l,permissionMode:s.provider.executionPermission,reason:l}}),[z]),Z=!!m,U=Z||A,B=r.useCallback(s=>{j.invalidateQueries({queryKey:x.conversations.all}),s&&j.invalidateQueries({queryKey:x.conversations.detail(s)})},[j]),$=r.useCallback(()=>{B(m)},[m,B]),E=r.useCallback(s=>{if(F(d=>{if(!d.has(s.id))return d;const y=new Set(d);return y.delete(s.id),y}),s.status!==T.COMPLETED)return;const l=Math.max(Date.now(),Ne(s));H(d=>{if(d[s.id]&&d[s.id]>=l)return d;const y={...d,[s.id]:l};return je(y),y})},[]),oe=r.useCallback(s=>{F(l=>{if(l.has(s))return l;const d=new Set(l);return d.add(s),d})},[]),xe=r.useCallback(s=>{F(l=>{if(!l.has(s))return l;const d=new Set(l);return d.delete(s),d}),H(l=>{if(!(s in l))return l;const d={...l};return delete d[s],je(d),d})},[]),P=r.useMemo(()=>{const s=new Map;for(const l of S)s.set(l.sessionId,l);return i&&s.set(i.sessionId,i),s},[i,S]),pe=r.useCallback(s=>s.status!==T.COMPLETED?!1:O.has(s.id)?!0:Ne(s)>(q[s.id]??0),[q,O]);r.useEffect(()=>{i||g||k(X.find(s=>s.available)?.id??"")},[i,g,X]),r.useEffect(()=>{i?.providerId&&k(i.providerId)},[i?.providerId]),r.useEffect(()=>{m&&p(!1)},[m]),r.useEffect(()=>{i&&E(i)},[i,E]),r.useEffect(()=>{const s=Ve.connect(),l=d=>{const y=P.get(d.sessionId);if(y){if(B(y.id),d.status!==T.COMPLETED){E(y);return}if(y.id===m){E(y);return}oe(y.id)}};return s.on(ye.SESSION_COMPLETED,l),()=>{s.off(ye.SESSION_COMPLETED,l)}},[m,P,B,E,oe]);const ee=()=>{N.current={conversationId:void 0,isCreatingNew:!0,epoch:N.current.epoch+1},v(N.current.epoch),D("idle"),p(!0),n("/conversations")},ie=()=>{p(!1),n("/conversations")},R=r.useCallback(s=>{E(s),p(!1),n(`/conversations/${s.id}`)},[E,n]),Q=async s=>{if(!s.providerId||!s.title.trim()||I!=="idle")return;D("starting-session");const l=N.current;try{const d=await fe.mutateAsync({prompt:s.title.trim(),providerId:s.providerId,attachmentIds:s.attachmentIds});N.current===l&&(k(s.providerId),p(!1),n(`/conversations/${d.id}`))}finally{N.current===l&&D("idle")}},_=async s=>{!i||!s.message.trim()&&!s.attachmentIds?.length||K.isPending||await K.mutateAsync({id:i.id,sessionId:i.sessionId,message:s.message,providerId:s.providerId||g||void 0,attachmentIds:s.attachmentIds})},M=async()=>{!i||J.isPending||await J.mutateAsync(i.id)},te=async s=>{window.confirm(t("Delete this conversation?"))&&(await Y.mutateAsync(s),xe(s),m===s&&(p(!1),n("/conversations")))};return e.jsxs("div",{className:"flex h-dvh flex-col overflow-hidden bg-sidebar text-sm text-foreground",children:[e.jsxs("header",{className:C("flex h-12 shrink-0 items-center justify-between bg-sidebar px-4",a&&"app-region-drag",f&&"pr-[150px]"),children:[e.jsxs("div",{className:C("flex min-w-0 items-center gap-2",h&&"pl-[72px]"),children:[e.jsx(ht,{}),e.jsx("span",{className:"mx-1.5 select-none text-muted-foreground",children:"/"}),e.jsx("span",{className:"truncate text-sm font-medium text-foreground/90",children:t("Conversation")})]}),e.jsx("button",{type:"button",onClick:()=>He.getState().openSettings(),className:C("rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",a&&"app-region-no-drag"),title:t("Settings"),children:e.jsx(Ge,{size:16})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsxs("aside",{className:C("h-full w-full shrink-0 flex-col bg-sidebar md:flex md:w-[320px]",U?"hidden md:flex":"flex"),children:[e.jsxs("div",{className:"shrink-0 px-2 pb-1 pt-2",children:[e.jsxs("button",{type:"button",onClick:ee,className:C("flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm transition-colors",A?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50"),title:t("New Conversation"),children:[e.jsx(gt,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("New Conversation")})]}),e.jsxs("button",{type:"button",onClick:()=>n("/"),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Tasks"),children:[e.jsx(jt,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Tasks")})]}),e.jsxs("button",{type:"button",onClick:()=>G(!0),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Search"),children:[e.jsx(Ae,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Search")})]})]}),e.jsx("div",{className:"relative min-h-0 flex-1 overflow-y-auto scrollbar-app-thin pb-4 pt-3",children:W?e.jsx("div",{className:"px-4 py-4 text-sm text-muted-foreground",children:t("Loading...")}):S.length===0?e.jsxs("div",{className:"flex h-full select-none flex-col items-center justify-center px-6 text-center",children:[e.jsx(he,{size:36,"aria-hidden":"true",className:"mb-3 text-muted-foreground/50",strokeWidth:1.5}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:t("No conversations")}),e.jsx("button",{type:"button",onClick:ee,className:"rounded-md bg-brand px-3.5 py-1.5 text-xs font-medium text-brand-foreground transition-colors hover:bg-brand/90",children:t("New Conversation")})]}):e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex w-full items-center gap-1.5 px-4 py-1.5 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"flex-1 text-left",children:t("History")}),e.jsx("span",{className:"text-[11px] font-normal tabular-nums text-muted-foreground",children:S.length})]}),e.jsx("div",{className:"mt-0.5 flex min-h-[40px] flex-col rounded-md",children:S.map(s=>e.jsx(Mt,{conversation:s,selected:s.id===m,disabled:Y.isPending,unread:s.id!==m&&pe(s),onSelect:()=>R(s),onDelete:()=>te(s.id)},s.id))})]})}),e.jsx("div",{className:"flex items-center justify-between border-t border-border/60 px-4 py-3 text-xs text-muted-foreground",children:e.jsxs("span",{children:[t("Conversations")," · ",S.length]})})]}),e.jsxs("main",{className:C("min-w-0 flex-1 flex-col bg-background md:mb-2 md:mr-2 md:overflow-hidden md:rounded-xl md:border md:border-border/50",U?"flex":"hidden md:flex"),children:[e.jsx("header",{className:"flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-4 md:px-5",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[Z||A?e.jsx("button",{type:"button",className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground md:hidden",onClick:ie,title:t("Back"),children:e.jsx(We,{size:17})}):null,e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-semibold",children:i?.title??t("New Conversation")}),i?e.jsxs("div",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[Lt(i.status,t),i.directoryName?` · ${i.directoryName}`:""]}):null]})]})}),!i&&Z?e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center px-4 text-sm text-muted-foreground",children:t(ue?"Loading...":"Conversation not found")}):i?e.jsx(Nt,{sessionId:i.sessionId,sessionStatus:i.status,sessionStartedAt:i.createdAt,sessionEndedAt:ge(i.status)?null:i.lastActiveAt??i.updatedAt,agentType:i.agentType,runtimeType:i.runtimeType,providerId:g||i.providerId,providers:z,initialTokenUsage:i.tokenUsage,onProviderChange:k,onSend:_,onStop:M,onExit:$,isSending:K.isPending,isStopping:J.isPending}):e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 pb-[10vh] md:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl animate-[fadeInUp_0.5s_cubic-bezier(0.16,1,0.3,1)]",children:[me.map(s=>e.jsx(tt,{item:s,onConversationCreated:l=>{N.current===b&&n(`/conversations/${l}`)}},s.id)),e.jsx("h1",{className:"mb-8 max-w-full break-words text-center text-[26px] leading-tight tracking-tight text-foreground",children:t("需要我帮你做点什么?")}),e.jsx(xt,{variant:"conversation",projects:[],providers:X,isProvidersLoading:ae,defaultProviderId:g,createStep:I,placeholder:"Ask a question...",submitLabel:"Start",pendingLabel:"Starting...",submitTitle:"Start",onSubmit:async({title:s,providerId:l,attachmentIds:d})=>{await Q({title:s,providerId:l,attachmentIds:d})}},o)]})})]})]}),e.jsx(Rt,{isOpen:L,conversations:S,onClose:()=>G(!1),onSelectConversation:R})]})}export{xs as ConversationPage};
|
|
1
|
+
import{c as ze,u as ce,r,j as e,at as Ke,au as Qe,Q as Fe,av as Ue,n as C,o as Ce,q as ne,p as de,s as x,v as V,aI as ke,aJ as Be,aK as $e,aL as _e,an as T,ac as Ve,ad as ye,aM as Ge,aN as He,w as We,az as le}from"./index-BJObbxud.js";import{u as Je,A as Ye,a as Se,s as Ie,r as Xe,b as Ze}from"./AttachmentPreview-CLN1lnLe.js";import{a as et,d as De,O as tt}from"./mermaid-NOHMQCX5-BSNbBj78.js";import{g as st,a as nt}from"./ExecutionPermissionSelector-B8befbxJ.js";import{u as rt,a as at,L as ot,T as it}from"./useNormalizedLogs--RbVywYa.js";import{u as lt,a as ct,R as dt,P as ut,T as mt}from"./useTokenUsage-DDXf7E4p.js";import{u as ft,C as xt}from"./CreateTaskInput-CasITF8y.js";import{P as pt}from"./paperclip-CTNoXpUW.js";import{B as ht,S as gt}from"./BrandLogo-BUimEX-9.js";import{u as vt}from"./use-providers-Td1-gyrN.js";import{S as Ae}from"./search-DniD_AGC.js";import{M as he}from"./message-square-BLEJN6p7.js";import{T as bt}from"./trash-2-CvUJsbtT.js";import"./tooltip-CPqGK_WZ.js";import"./kbd-C88ut3t9.js";import"./index-Bhvt-E6d.js";import"./index-B1oVmCie.js";import"./index-Dk3bRQAK.js";import"./use-translation-settings-NYM0lmBx.js";import"./copy-HRMhTkIG.js";import"./index-DcOU2m2F.js";import"./chevron-down-3y5Aiolp.js";import"./check-BmiJ7qMY.js";import"./track-Ckye0-tt.js";import"./menu--sjyisSg.js";import"./menu-styles-DWynpVVz.js";import"./index-DZLnTISJ.js";import"./index-BtUQYU5l.js";import"./use-projects-Ddz0knyr.js";import"./MemberAvatar-YVr_erAr.js";import"./people-DT78SebR.js";import"./hooks-BLxb16IA.js";const yt=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}],["path",{d:"M14 4h7",key:"3xa0d5"}],["path",{d:"M14 9h7",key:"1icrd9"}],["path",{d:"M14 15h7",key:"1mj8o2"}],["path",{d:"M14 20h7",key:"11slyb"}]],jt=ze("layout-list",yt);function Nt({sessionId:t,sessionStatus:n,sessionStartedAt:a,sessionEndedAt:u,agentType:h,runtimeType:f,providerId:m,providers:j,initialTokenUsage:g,onProviderChange:k,onSend:I,onStop:D,onExit:A,isSending:p=!1,isStopping:o=!1,canStop:v,className:N}){const{t:b}=ce(),[L,G]=r.useState(""),[q,H]=r.useState(m??""),O=st(j,q||m),[F,S]=r.useState(!1),W=r.useRef(null),re=r.useRef(null),ue=r.useRef(null),z=r.useRef(!1),{scrollRef:ae,contentRef:me,isAtBottom:fe,scrollToBottom:K,stopScroll:J}=lt({initial:"instant",resize:"smooth"}),{isConnected:Y,isLoadingSnapshot:i,isOutputActive:X,lastExitAt:Z,logs:U,entries:B,attach:$}=rt({sessionId:t,sessionStatus:n,sessionStartedAt:a,sessionEndedAt:u,onExit:A}),{todos:E}=at(B),oe=ct(U,g),{files:xe,addFiles:P,removeFile:pe,clear:ee,getDoneAttachments:ie,hasFiles:R,isUploading:Q}=Je(),{isActive:_,isCancelling:M}=ft(t,n),te=v??_;r.useEffect(()=>{H(m??"")},[m]),r.useEffect(()=>{t&&Y&&$()},[t,Y,$]);const s=r.useCallback(c=>{H(c),k?.(c)},[k]),l=r.useCallback(()=>{W.current&&(W.current.style.height="60px")},[]),d=r.useCallback(c=>{G(c.target.value);const w=c.target;w.style.height="auto",w.style.height=`${Math.max(60,Math.min(w.scrollHeight,300))}px`},[]),y=r.useCallback(async()=>{if(!L.trim()&&!R||z.current||p||o||M||Q||O)return;z.current=!0;const c=ie().map(se=>se.id),w=L.trim()||(c.length?" ":"");G(""),ee(),l();try{await I({message:w,providerId:q||void 0,attachmentIds:c}),await $(),requestAnimationFrame(()=>K("smooth"))}catch{}finally{z.current=!1}},[L,R,p,o,M,Q,ie,ee,l,I,q,O,$,K]),Le=r.useCallback(async()=>{!te||o||M||await D()},[te,o,M,D]),Pe=r.useCallback(c=>{const w=c.target.files;w&&w.length>0&&P(Array.from(w)),c.target.value=""},[P]),Me=r.useCallback(c=>{const w=c.clipboardData.items,se=[];for(const ve of w)if(ve.kind==="file"){const be=ve.getAsFile();be&&se.push(be)}se.length>0&&(c.preventDefault(),P(se))},[P]),Re=r.useCallback(c=>{c.preventDefault(),S(!0)},[]),qe=r.useCallback(c=>{c.preventDefault(),S(!1)},[]),Oe=r.useCallback(c=>{c.preventDefault(),S(!1);const w=c.dataTransfer.files;w.length>0&&P(Array.from(w))},[P]);return e.jsxs("div",{className:C("relative flex min-h-0 flex-1 flex-col bg-background",N),children:[e.jsxs("div",{className:"relative min-h-0 flex-1",children:[e.jsx("div",{ref:ae,className:"h-full overflow-y-auto scrollbar-app-thin px-6 pb-4 pt-6",children:e.jsx("div",{ref:me,className:"mx-auto w-full min-w-0 max-w-4xl",children:i?e.jsxs("div",{className:"flex items-center justify-center gap-3 py-12 text-muted-foreground",children:[e.jsxs("svg",{className:"h-5 w-5 animate-spin motion-reduce:[animation-duration:2.4s]",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),e.jsx("span",{className:"text-sm",children:b("Loading logs...")})]}):U.length===0&&!t?e.jsx("div",{className:"py-8 text-center text-muted-foreground",children:b(_?"Waiting for agent output...":"No logs recorded for this session.")}):e.jsx(ot,{children:e.jsx(et,{logs:U,sessionId:t,downloadSessionId:t,isOutputActive:X,lastExitAt:Z,onUserToggleDetails:J,scrollElementRef:ae})})})}),!fe&&e.jsxs("button",{type:"button",onClick:()=>K(),className:"absolute bottom-3 left-1/2 z-10 flex -translate-x-1/2 items-center gap-1.5 rounded-full border border-border bg-background/90 px-3 py-1.5 text-xs text-muted-foreground shadow-raised backdrop-blur-sm transition-all hover:bg-background hover:text-foreground","aria-label":b("Scroll to bottom"),children:[e.jsx(Ke,{size:14}),e.jsx("span",{children:b("Back to bottom")})]})]}),E.length>0&&e.jsx("div",{className:"shrink-0 border-t border-border/60 bg-background px-6 pb-1 pt-2",children:e.jsx("div",{className:"mx-auto max-w-4xl",children:e.jsx(it,{todos:E})})}),e.jsx("div",{className:"z-10 w-full shrink-0 border-t border-transparent bg-background p-6 pb-6 pt-2",onDragOver:Re,onDragLeave:qe,onDrop:Oe,children:e.jsxs("div",{className:"mx-auto max-w-4xl",children:[e.jsx(dt,{sessionId:t}),e.jsxs("div",{ref:ue,className:C("relative rounded-xl border bg-background transition-colors duration-200 hover:border-ring/40 focus-within:border-ring/60",F?"border-foreground/40 bg-foreground/[0.02]":"border-border"),children:[e.jsx(Ye,{files:xe,onRemove:pe}),e.jsx("textarea",{ref:W,value:L,onChange:d,onPaste:Me,onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!c.repeat&&!c.nativeEvent.isComposing&&c.nativeEvent.keyCode!==229&&(c.preventDefault(),y())},rows:1,placeholder:b(F?"Drop files here...":t&&!_?"Continue conversation...":"Message Agent..."),className:"w-full resize-none border-none bg-transparent px-4 pb-2 pt-4 text-sm leading-relaxed text-foreground placeholder-muted-foreground/70 focus:outline-none",style:{minHeight:"60px",maxHeight:"300px"}}),e.jsx("input",{ref:re,type:"file",multiple:!0,className:"hidden",onChange:Pe}),e.jsxs("div",{className:"flex items-center justify-between px-2 pb-2 pt-1",children:[e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("button",{type:"button",onClick:()=>re.current?.click(),disabled:Q,className:"rounded-lg p-2 text-muted-foreground transition-colors hover:bg-muted hover:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",title:b("Upload file"),children:e.jsx(pt,{size:18})})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ut,{providers:j,currentProviderId:q,agentType:h,runtimeType:f,onSelect:s}),e.jsx(mt,{usage:oe}),te&&_&&!p&&!L.trim()&&!R?e.jsx("button",{type:"button",onClick:Le,disabled:o||M,className:"rounded-lg bg-destructive-ink p-2 text-white transition-all duration-200 hover:bg-destructive-ink/90 disabled:opacity-50",title:b("Stop"),"aria-label":b("Stop"),children:e.jsx(Qe,{size:14})}):e.jsx("button",{type:"button",onClick:y,disabled:!L.trim()&&!R||Q||p||o||M||!!O,className:C("rounded-lg p-2 transition-all duration-200",(L.trim()||R)&&!Q&&!p&&!o&&!M&&!O?"bg-primary text-primary-foreground hover:bg-primary/90":"cursor-not-allowed bg-transparent text-muted-foreground"),title:b(p?"发送中...":"Send"),"aria-label":b(p?"发送中...":"Send"),"aria-busy":p,children:p?e.jsx(Fe,{size:18,className:"animate-spin"}):e.jsx(Ue,{size:18})})]})]})]})]})})]})}function wt(t=50){return Ce({queryKey:x.conversations.list({limit:t}),queryFn:()=>V.get("/conversations",{params:{limit:String(t)}})})}function Ct(t){return Ce({queryKey:x.conversations.detail(t??""),queryFn:()=>V.get(`/conversations/${t}`),enabled:!!t})}function kt(){const t=ne();return de({mutationFn:n=>Se("conversation:create",n,async a=>{const u=await Ie(t,"new-conversation","/conversations",a,h=>Xe(t,h));return"operationId"in u?(ke(t,u.delivery),t.invalidateQueries({queryKey:De(u.sessionId)}),V.get(`/conversations/${u.destinationId}`)):u}),onSuccess:n=>{t.setQueryData(x.conversations.detail(n.id),n),t.invalidateQueries({queryKey:x.conversations.all}),t.invalidateQueries({queryKey:x.sessions.detail(n.sessionId)})}})}function St(){const t=ne();return de({mutationFn:({id:n,sessionId:a,...u})=>Se(`conversation:message:${n}`,u,async h=>{const f=await Ie(t,a??t.getQueryData(x.conversations.detail(n))?.sessionId??`conversation:${n}`,`/conversations/${n}/message`,h);return"operationId"in f?(ke(t,f.delivery),t.invalidateQueries({queryKey:De(f.sessionId)}),V.get(`/conversations/${f.destinationId}`)):f}),onSuccess:n=>{t.setQueryData(x.conversations.detail(n.id),n),t.invalidateQueries({queryKey:x.conversations.all}),t.invalidateQueries({queryKey:x.sessions.detail(n.sessionId)})}})}function It(){const t=ne();return de({mutationFn:n=>V.post(`/conversations/${n}/stop`),onSuccess:n=>{t.setQueryData(x.conversations.detail(n.id),n),t.invalidateQueries({queryKey:x.conversations.all}),t.invalidateQueries({queryKey:x.sessions.detail(n.sessionId)})},onSettled:(n,a,u)=>{const h=t.getQueryData(x.conversations.detail(u)),f=n?.sessionId??h?.sessionId;t.invalidateQueries({queryKey:x.conversations.detail(u)}),f&&(t.invalidateQueries({queryKey:x.sessions.detail(f)}),t.invalidateQueries({queryKey:x.sessions.runtime(f)}))}})}function Dt(){const t=ne();return de({mutationFn:n=>V.delete(`/conversations/${n}`),onSuccess:(n,a)=>{t.removeQueries({queryKey:x.conversations.detail(a)}),t.invalidateQueries({queryKey:x.conversations.all})}})}const At=3e4,Ee="agent-tower:conversation-read-times";function Et(){try{const t=window.localStorage.getItem(Ee);if(!t)return{};const n=JSON.parse(t);return!n||typeof n!="object"||Array.isArray(n)?{}:Object.fromEntries(Object.entries(n).map(([a,u])=>[a,typeof u=="number"?u:Number(u)]).filter(a=>Number.isFinite(a[1])))}catch{return{}}}function je(t){try{window.localStorage.setItem(Ee,JSON.stringify(t))}catch{}}function Ne(t){const n=t.lastActiveAt??t.updatedAt??t.createdAt;if(!n)return 0;const a=new Date(n).getTime();return Number.isFinite(a)?a:0}function Tt(t=At){const[,n]=r.useState(0);r.useEffect(()=>{const a=setInterval(()=>n(u=>u+1),t);return()=>clearInterval(a)},[t])}function ge(t){return t===T.RUNNING||t===T.PENDING}function Te(t){if(!t)return"";const n=new Date(t);if(Number.isNaN(n.getTime()))return"";const a=Math.max(0,Math.floor((Date.now()-n.getTime())/1e3));return a<60?le("{count}s ago",{count:a}):a<3600?le("{count}m ago",{count:Math.floor(a/60)}):a<86400?le("{count}h ago",{count:Math.floor(a/3600)}):le("{count}d ago",{count:Math.floor(a/86400)})}function Lt(t,n){switch(t){case T.RUNNING:return n("Running");case T.PENDING:return n("Starting");case T.COMPLETED:return n("Completed");case T.FAILED:return n("Failed");case T.CANCELLED:return n("Stopped");default:return t}}function we({className:t,pulseClassName:n}){return e.jsxs("span",{className:"relative inline-flex h-2 w-2",children:[e.jsx("span",{className:C("absolute inline-flex h-full w-full animate-ping motion-reduce:animate-none rounded-full",n)}),e.jsx("span",{className:C("relative inline-flex h-2 w-2 rounded-full",t)})]})}function Pt({status:t,unread:n}){return ge(t)?e.jsx(we,{className:"bg-success",pulseClassName:"bg-success/70"}):n?e.jsx(we,{className:"bg-warning",pulseClassName:"bg-warning/70"}):null}function Mt({conversation:t,selected:n,onSelect:a,onDelete:u,disabled:h,unread:f}){const{t:m}=ce(),j=Te(t.lastActiveAt??t.createdAt),g=ge(t.status)||f;return e.jsxs("div",{className:C("group ml-4 mr-2 flex items-center rounded-md transition-colors",n?"bg-accent":"hover:bg-accent/50"),children:[e.jsxs("button",{type:"button",onClick:a,title:t.title,className:"flex min-w-0 flex-1 animate-task-enter items-center gap-2.5 rounded-md px-2 py-2 text-left text-sm",children:[e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(he,{size:14,className:"text-muted-foreground"})}),e.jsx("span",{className:C("min-w-0 flex-1 truncate",n?"font-medium text-foreground":"text-foreground/90"),children:t.title}),g?e.jsx("span",{className:"flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:e.jsx(Pt,{status:t.status,unread:f})}):e.jsx("span",{className:"flex w-14 shrink-0 items-center justify-end text-[11px] tabular-nums text-muted-foreground",children:e.jsx("span",{className:"truncate group-hover:hidden",children:j})})]}),e.jsx("button",{type:"button",onClick:k=>{k.stopPropagation(),u()},disabled:h,className:"mr-1 hidden shrink-0 rounded-md p-1.5 text-muted-foreground hover:bg-background hover:text-destructive disabled:opacity-50 group-hover:flex",title:m("Delete"),children:e.jsx(bt,{size:14})})]})}function Rt({isOpen:t,conversations:n,onClose:a,onSelectConversation:u}){const{t:h}=ce(),[f,m]=r.useState(""),[j,g]=r.useState(0),k=r.useRef(null);r.useEffect(()=>{t&&(m(""),g(0))},[t]);const I=r.useMemo(()=>{const o=f.trim().toLowerCase();return o?n.filter(v=>v.title.toLowerCase().includes(o)).slice(0,50):n.slice(0,12)},[n,f]);r.useEffect(()=>{g(0)},[f]),r.useEffect(()=>{k.current?.children[j]?.scrollIntoView({block:"nearest"})},[j]);const D=r.useCallback(o=>{u(o),a()},[a,u]),A=r.useCallback(o=>{if(o.key==="Escape"){o.preventDefault(),a();return}if(o.key==="ArrowDown"){o.preventDefault(),g(v=>Math.min(v+1,I.length-1));return}if(o.key==="ArrowUp"){o.preventDefault(),g(v=>Math.max(v-1,0));return}if(o.key==="Enter"&&!o.nativeEvent.isComposing){o.preventDefault();const v=I[j];v&&D(v)}},[j,D,a,I]);if(!t)return null;const p=f.trim().length>0;return e.jsxs("div",{className:"fixed inset-0 z-90",role:"dialog","aria-modal":"true",children:[e.jsx("div",{className:"absolute inset-0 bg-black/20",onClick:a}),e.jsxs("div",{className:"absolute left-1/2 top-[18vh] w-[min(560px,calc(100vw-2rem))] -translate-x-1/2 overflow-hidden rounded-xl border border-border bg-popover shadow-popover animate-in fade-in zoom-in-95 duration-100",children:[e.jsxs("div",{className:"flex items-center gap-2.5 border-b border-border/60 px-4",children:[e.jsx(Ae,{size:15,className:"shrink-0 text-muted-foreground/70"}),e.jsx("input",{value:f,onChange:o=>m(o.target.value),onKeyDown:A,placeholder:h("Search conversations..."),"aria-label":h("Search conversations..."),autoFocus:!0,className:"flex-1 border-none bg-transparent py-3 text-sm text-foreground placeholder-muted-foreground/60 focus:outline-none"})]}),I.length>0?e.jsxs(e.Fragment,{children:[p?null:e.jsx("div",{className:"px-4 pb-1 pt-2.5 text-xs font-medium text-muted-foreground",children:h("Recent conversations")}),e.jsx("div",{ref:k,className:"max-h-[46vh] overflow-y-auto pb-1.5 pt-0.5 scrollbar-app-thin",children:I.map((o,v)=>e.jsxs("button",{type:"button",onClick:()=>D(o),onMouseEnter:()=>g(v),className:C("flex w-full items-center gap-2.5 px-4 py-2 text-left transition-colors",v===j&&"bg-accent"),children:[e.jsx(he,{size:14,className:"shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-foreground/90",title:o.title,children:o.title}),e.jsx("span",{className:"shrink-0 text-xs tabular-nums text-muted-foreground",children:Te(o.lastActiveAt??o.createdAt)})]},o.id))})]}):e.jsx("div",{className:"px-4 py-8 text-center text-sm text-muted-foreground",children:h("No matching conversations")})]})]})}function xs(){const{t}=ce();Tt();const n=Be(),{usesIntegratedTitlebar:a,desktopPlatform:u,hasMacTrafficLights:h}=$e(),f=a&&u==="win32",{conversationId:m}=_e(),j=ne(),[g,k]=r.useState(""),[I,D]=r.useState("idle"),[A,p]=r.useState(!1),[o,v]=r.useState(0),N=r.useRef({conversationId:m,isCreatingNew:A,epoch:o});(N.current.conversationId!==m||N.current.isCreatingNew!==A||N.current.epoch!==o)&&(N.current={conversationId:m,isCreatingNew:A,epoch:o});const b=N.current,[L,G]=r.useState(!1),[q,H]=r.useState(Et),[O,F]=r.useState(()=>new Set),{data:S=[],isLoading:W}=wt(),{data:re,isLoading:ue}=Ct(m),{data:z=[],isLoading:ae}=vt(),me=Ze("new-conversation"),fe=kt(),K=St(),J=It(),Y=Dt(),i=re??S.find(s=>s.id===m)??null,X=r.useMemo(()=>z.map(s=>{const l=nt(s);return{id:s.provider.id,name:s.provider.name,agentType:s.provider.agentType,available:!l,permissionMode:s.provider.executionPermission,reason:l}}),[z]),Z=!!m,U=Z||A,B=r.useCallback(s=>{j.invalidateQueries({queryKey:x.conversations.all}),s&&j.invalidateQueries({queryKey:x.conversations.detail(s)})},[j]),$=r.useCallback(()=>{B(m)},[m,B]),E=r.useCallback(s=>{if(F(d=>{if(!d.has(s.id))return d;const y=new Set(d);return y.delete(s.id),y}),s.status!==T.COMPLETED)return;const l=Math.max(Date.now(),Ne(s));H(d=>{if(d[s.id]&&d[s.id]>=l)return d;const y={...d,[s.id]:l};return je(y),y})},[]),oe=r.useCallback(s=>{F(l=>{if(l.has(s))return l;const d=new Set(l);return d.add(s),d})},[]),xe=r.useCallback(s=>{F(l=>{if(!l.has(s))return l;const d=new Set(l);return d.delete(s),d}),H(l=>{if(!(s in l))return l;const d={...l};return delete d[s],je(d),d})},[]),P=r.useMemo(()=>{const s=new Map;for(const l of S)s.set(l.sessionId,l);return i&&s.set(i.sessionId,i),s},[i,S]),pe=r.useCallback(s=>s.status!==T.COMPLETED?!1:O.has(s.id)?!0:Ne(s)>(q[s.id]??0),[q,O]);r.useEffect(()=>{i||g||k(X.find(s=>s.available)?.id??"")},[i,g,X]),r.useEffect(()=>{i?.providerId&&k(i.providerId)},[i?.providerId]),r.useEffect(()=>{m&&p(!1)},[m]),r.useEffect(()=>{i&&E(i)},[i,E]),r.useEffect(()=>{const s=Ve.connect(),l=d=>{const y=P.get(d.sessionId);if(y){if(B(y.id),d.status!==T.COMPLETED){E(y);return}if(y.id===m){E(y);return}oe(y.id)}};return s.on(ye.SESSION_COMPLETED,l),()=>{s.off(ye.SESSION_COMPLETED,l)}},[m,P,B,E,oe]);const ee=()=>{N.current={conversationId:void 0,isCreatingNew:!0,epoch:N.current.epoch+1},v(N.current.epoch),D("idle"),p(!0),n("/conversations")},ie=()=>{p(!1),n("/conversations")},R=r.useCallback(s=>{E(s),p(!1),n(`/conversations/${s.id}`)},[E,n]),Q=async s=>{if(!s.providerId||!s.title.trim()||I!=="idle")return;D("starting-session");const l=N.current;try{const d=await fe.mutateAsync({prompt:s.title.trim(),providerId:s.providerId,attachmentIds:s.attachmentIds});N.current===l&&(k(s.providerId),p(!1),n(`/conversations/${d.id}`))}finally{N.current===l&&D("idle")}},_=async s=>{!i||!s.message.trim()&&!s.attachmentIds?.length||K.isPending||await K.mutateAsync({id:i.id,sessionId:i.sessionId,message:s.message,providerId:s.providerId||g||void 0,attachmentIds:s.attachmentIds})},M=async()=>{!i||J.isPending||await J.mutateAsync(i.id)},te=async s=>{window.confirm(t("Delete this conversation?"))&&(await Y.mutateAsync(s),xe(s),m===s&&(p(!1),n("/conversations")))};return e.jsxs("div",{className:"flex h-dvh flex-col overflow-hidden bg-sidebar text-sm text-foreground",children:[e.jsxs("header",{className:C("flex h-12 shrink-0 items-center justify-between bg-sidebar px-4",a&&"app-region-drag",f&&"pr-[150px]"),children:[e.jsxs("div",{className:C("flex min-w-0 items-center gap-2",h&&"pl-[72px]"),children:[e.jsx(ht,{}),e.jsx("span",{className:"mx-1.5 select-none text-muted-foreground",children:"/"}),e.jsx("span",{className:"truncate text-sm font-medium text-foreground/90",children:t("Conversation")})]}),e.jsx("button",{type:"button",onClick:()=>He.getState().openSettings(),className:C("rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground",a&&"app-region-no-drag"),title:t("Settings"),children:e.jsx(Ge,{size:16})})]}),e.jsxs("div",{className:"flex min-h-0 flex-1 overflow-hidden",children:[e.jsxs("aside",{className:C("h-full w-full shrink-0 flex-col bg-sidebar md:flex md:w-[320px]",U?"hidden md:flex":"flex"),children:[e.jsxs("div",{className:"shrink-0 px-2 pb-1 pt-2",children:[e.jsxs("button",{type:"button",onClick:ee,className:C("flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm transition-colors",A?"bg-accent text-foreground":"text-foreground/80 hover:bg-accent/50"),title:t("New Conversation"),children:[e.jsx(gt,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("New Conversation")})]}),e.jsxs("button",{type:"button",onClick:()=>n("/"),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Tasks"),children:[e.jsx(jt,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Tasks")})]}),e.jsxs("button",{type:"button",onClick:()=>G(!0),className:"flex w-full items-center gap-2.5 rounded-md px-2 py-2 text-sm text-foreground/80 transition-colors hover:bg-accent/50",title:t("Search"),children:[e.jsx(Ae,{size:16,className:"text-muted-foreground"}),e.jsx("span",{children:t("Search")})]})]}),e.jsx("div",{className:"relative min-h-0 flex-1 overflow-y-auto scrollbar-app-thin pb-4 pt-3",children:W?e.jsx("div",{className:"px-4 py-4 text-sm text-muted-foreground",children:t("Loading...")}):S.length===0?e.jsxs("div",{className:"flex h-full select-none flex-col items-center justify-center px-6 text-center",children:[e.jsx(he,{size:36,"aria-hidden":"true",className:"mb-3 text-muted-foreground/50",strokeWidth:1.5}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:t("No conversations")}),e.jsx("button",{type:"button",onClick:ee,className:"rounded-md bg-brand px-3.5 py-1.5 text-xs font-medium text-brand-foreground transition-colors hover:bg-brand/90",children:t("New Conversation")})]}):e.jsxs("div",{className:"mb-2",children:[e.jsxs("div",{className:"flex w-full items-center gap-1.5 px-4 py-1.5 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{className:"flex-1 text-left",children:t("History")}),e.jsx("span",{className:"text-[11px] font-normal tabular-nums text-muted-foreground",children:S.length})]}),e.jsx("div",{className:"mt-0.5 flex min-h-[40px] flex-col rounded-md",children:S.map(s=>e.jsx(Mt,{conversation:s,selected:s.id===m,disabled:Y.isPending,unread:s.id!==m&&pe(s),onSelect:()=>R(s),onDelete:()=>te(s.id)},s.id))})]})}),e.jsx("div",{className:"flex items-center justify-between border-t border-border/60 px-4 py-3 text-xs text-muted-foreground",children:e.jsxs("span",{children:[t("Conversations")," · ",S.length]})})]}),e.jsxs("main",{className:C("min-w-0 flex-1 flex-col bg-background md:mb-2 md:mr-2 md:overflow-hidden md:rounded-xl md:border md:border-border/50",U?"flex":"hidden md:flex"),children:[e.jsx("header",{className:"flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-4 md:px-5",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[Z||A?e.jsx("button",{type:"button",className:"rounded-md p-1.5 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground md:hidden",onClick:ie,title:t("Back"),children:e.jsx(We,{size:17})}):null,e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-semibold",children:i?.title??t("New Conversation")}),i?e.jsxs("div",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[Lt(i.status,t),i.directoryName?` · ${i.directoryName}`:""]}):null]})]})}),!i&&Z?e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center px-4 text-sm text-muted-foreground",children:t(ue?"Loading...":"Conversation not found")}):i?e.jsx(Nt,{sessionId:i.sessionId,sessionStatus:i.status,sessionStartedAt:i.createdAt,sessionEndedAt:ge(i.status)?null:i.lastActiveAt??i.updatedAt,agentType:i.agentType,runtimeType:i.runtimeType,providerId:g||i.providerId,providers:z,initialTokenUsage:i.tokenUsage,onProviderChange:k,onSend:_,onStop:M,onExit:$,isSending:K.isPending,isStopping:J.isPending}):e.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center overflow-y-auto px-4 pb-[10vh] md:px-8",children:e.jsxs("div",{className:"w-full max-w-2xl animate-[fadeInUp_0.5s_cubic-bezier(0.16,1,0.3,1)]",children:[me.map(s=>e.jsx(tt,{item:s,onConversationCreated:l=>{N.current===b&&n(`/conversations/${l}`)}},s.id)),e.jsx("h1",{className:"mb-8 max-w-full break-words text-center text-[26px] leading-tight tracking-tight text-foreground",children:t("需要我帮你做点什么?")}),e.jsx(xt,{variant:"conversation",projects:[],providers:X,isProvidersLoading:ae,defaultProviderId:g,createStep:I,placeholder:"Ask a question...",submitLabel:"Start",pendingLabel:"Starting...",submitTitle:"Start",onSubmit:async({title:s,providerId:l,attachmentIds:d})=>{await Q({title:s,providerId:l,attachmentIds:d})}},o)]})})]})]}),e.jsx(Rt,{isOpen:L,conversations:S,onClose:()=>G(!1),onSelectConversation:R})]})}export{xs as ConversationPage};
|