@hienlh/ppm 0.8.64 → 0.8.65
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/CHANGELOG.md +12 -0
- package/bun.lock +5 -0
- package/dist/web/assets/{_basePickBy-CZovQgWd.js → _basePickBy-CrBYAu1z.js} +1 -1
- package/dist/web/assets/{_baseUniq-ClnvscgW.js → _baseUniq-PMQMCyd4.js} +1 -1
- package/dist/web/assets/{api-settings--eVrUeZM.js → api-settings-Cj0OeEMH.js} +1 -1
- package/dist/web/assets/{arc-C2Qaz-ch.js → arc-Bx6TKJWg.js} +1 -1
- package/dist/web/assets/architecture-PBZL5I3N-DyGQgfy0.js +1 -0
- package/dist/web/assets/{architectureDiagram-2XIMDMQ5-Jq91S_rs.js → architectureDiagram-2XIMDMQ5-Dinq4Kbf.js} +1 -1
- package/dist/web/assets/arrow-up--LjUXLEt.js +1 -0
- package/dist/web/assets/{blockDiagram-WCTKOSBZ-CKGufRTy.js → blockDiagram-WCTKOSBZ-CXh2T4Mt.js} +1 -1
- package/dist/web/assets/{browser-tab-CjjWgPDL.js → browser-tab-BT8iJmIO.js} +1 -1
- package/dist/web/assets/{c4Diagram-IC4MRINW-BNP2L9r_.js → c4Diagram-IC4MRINW-BCqRHxU0.js} +1 -1
- package/dist/web/assets/channel-GxJZ6KAL.js +1 -0
- package/dist/web/assets/chat-tab-B5tNFtvt.js +7 -0
- package/dist/web/assets/chevron-right-DeV0ehiG.js +1 -0
- package/dist/web/assets/{chunk-4BX2VUAB-BptTlTyl.js → chunk-4BX2VUAB-BNc3BCto.js} +1 -1
- package/dist/web/assets/{chunk-55IACEB6-C4mUdyio.js → chunk-55IACEB6-NTU3iwXh.js} +1 -1
- package/dist/web/assets/{chunk-7E7YKBS2-6xAQfBwa.js → chunk-7E7YKBS2-B3LDS0kJ.js} +1 -1
- package/dist/web/assets/{chunk-7R4GIKGN-DXaGAn_K.js → chunk-7R4GIKGN-Y5Bg-bKJ.js} +2 -2
- package/dist/web/assets/{chunk-C72U2L5F-DOtEiN5f.js → chunk-C72U2L5F-0CMBXF9Y.js} +1 -1
- package/dist/web/assets/{chunk-EGIJ26TM-D0KJTa_T.js → chunk-EGIJ26TM-BATHdF9E.js} +1 -1
- package/dist/web/assets/{chunk-FMBD7UC4-C_1aG0eb.js → chunk-FMBD7UC4-BrH-Lnio.js} +1 -1
- package/dist/web/assets/{chunk-GEFDOKGD-DwVPiYfW.js → chunk-GEFDOKGD-_UEQ_Hqk.js} +1 -1
- package/dist/web/assets/chunk-GLR3WWYH-BWjkRp6S.js +2 -0
- package/dist/web/assets/chunk-HHEYEP7N-DhIRtWNx.js +1 -0
- package/dist/web/assets/{chunk-JSJVCQXG-BSrqCL_3.js → chunk-JSJVCQXG-LNOdgWAh.js} +1 -1
- package/dist/web/assets/{chunk-KX2RTZJC-BCxGmbzy.js → chunk-KX2RTZJC-AniEyPkm.js} +1 -1
- package/dist/web/assets/{chunk-KYZI473N-BKO5gMeU.js → chunk-KYZI473N-drU3HQZZ.js} +1 -1
- package/dist/web/assets/{chunk-L3YUKLVL-3wBgkSvL.js → chunk-L3YUKLVL-GJ3l4AXc.js} +1 -1
- package/dist/web/assets/{chunk-MX3YWQON-BgjSEzus.js → chunk-MX3YWQON-OOf6bZzK.js} +1 -1
- package/dist/web/assets/{chunk-NQ4KR5QH-DLrZwBEm.js → chunk-NQ4KR5QH-DoAhAAPR.js} +1 -1
- package/dist/web/assets/{chunk-O4XLMI2P-BurQy8tt.js → chunk-O4XLMI2P-BBFcNFB_.js} +1 -1
- package/dist/web/assets/{chunk-OZEHJAEY-YTn24bGg.js → chunk-OZEHJAEY-CxBlPGUC.js} +1 -1
- package/dist/web/assets/{chunk-PQ6SQG4A-BxtUGYhW.js → chunk-PQ6SQG4A-DZGwvbzy.js} +1 -1
- package/dist/web/assets/{chunk-PU5JKC2W-B66ELkQm.js → chunk-PU5JKC2W-CCXYoac7.js} +1 -1
- package/dist/web/assets/chunk-QZHKN3VN-CzG4AaJv.js +1 -0
- package/dist/web/assets/{chunk-R5LLSJPH-euR2RxLN.js → chunk-R5LLSJPH-BTcrDJ0u.js} +1 -1
- package/dist/web/assets/{chunk-WL4C6EOR-_2CBOJdI.js → chunk-WL4C6EOR-BkioZxSz.js} +1 -1
- package/dist/web/assets/{chunk-XIRO2GV7-kqQ0g6wW.js → chunk-XIRO2GV7-BojyzPX8.js} +1 -1
- package/dist/web/assets/{chunk-XPW4576I-CtcaMb09.js → chunk-XPW4576I-no3g3yPs.js} +1 -1
- package/dist/web/assets/{chunk-XZSTWKYB-BYxFzZwS.js → chunk-XZSTWKYB-DTNisBJo.js} +1 -1
- package/dist/web/assets/{chunk-YBOYWFTD-Dx_fX35n.js → chunk-YBOYWFTD-DGKGjR6H.js} +1 -1
- package/dist/web/assets/classDiagram-VBA2DB6C-D3WeZMpV.js +1 -0
- package/dist/web/assets/classDiagram-v2-RAHNMMFH-CuONv6uF.js +1 -0
- package/dist/web/assets/clone-BGvnD7V5.js +1 -0
- package/dist/web/assets/code-editor-4UczMI-T.js +2 -0
- package/dist/web/assets/{cose-bilkent-S5V4N54A-CHHjH2dV.js → cose-bilkent-S5V4N54A-zoeAORzo.js} +1 -1
- package/dist/web/assets/csv-preview-CgHOY6hR.js +9 -0
- package/dist/web/assets/{dagre-CNtSxiE_.js → dagre-Bh_0hC-U.js} +1 -1
- package/dist/web/assets/{dagre-KLK3FWXG-ChenfPp1.js → dagre-KLK3FWXG-C5SfvcWS.js} +1 -1
- package/dist/web/assets/database-viewer-CUjlWuu_.js +1 -0
- package/dist/web/assets/{diagram-E7M64L7V-CzKYZM0Y.js → diagram-E7M64L7V-CZUkePtj.js} +1 -1
- package/dist/web/assets/{diagram-IFDJBPK2-ChB_paPo.js → diagram-IFDJBPK2-C_f4KWUQ.js} +1 -1
- package/dist/web/assets/{diagram-P4PSJMXO-D1eW1dkL.js → diagram-P4PSJMXO-DCIgnRzg.js} +1 -1
- package/dist/web/assets/diff-viewer-B4lDAzWv.js +4 -0
- package/dist/web/assets/dist-B21lOVUR.js +1 -0
- package/dist/web/assets/dist-DylI9XxN.js +13 -0
- package/dist/web/assets/dist-lF8CoYII.js +41 -0
- package/dist/web/assets/{erDiagram-INFDFZHY-mCvUFSn6.js → erDiagram-INFDFZHY-BmVZ3V1Q.js} +1 -1
- package/dist/web/assets/{flowDiagram-PKNHOUZH-14ohZ1M1.js → flowDiagram-PKNHOUZH-DQVk-izW.js} +1 -1
- package/dist/web/assets/{ganttDiagram-A5KZAMGK-DIX0pLbk.js → ganttDiagram-A5KZAMGK-BesueWL2.js} +1 -1
- package/dist/web/assets/git-graph-BTZTGZdP.js +1 -0
- package/dist/web/assets/gitGraph-HDMCJU4V-sd3XYN52.js +1 -0
- package/dist/web/assets/{gitGraphDiagram-K3NZZRJ6-yEWZbdf_.js → gitGraphDiagram-K3NZZRJ6-BnKRAgIF.js} +1 -1
- package/dist/web/assets/{graphlib-DhOZxqsh.js → graphlib-BZkhmhks.js} +1 -1
- package/dist/web/assets/index-DPI-YVJI.css +2 -0
- package/dist/web/assets/index-hxAJJHpg.js +37 -0
- package/dist/web/assets/info-3K5VOQVL-DdzKhhLF.js +1 -0
- package/dist/web/assets/infoDiagram-LFFYTUFH-CnHorrOf.js +2 -0
- package/dist/web/assets/input-Bid961xi.js +1 -0
- package/dist/web/assets/{isEmpty-C0YYdhYj.js → isEmpty-CauZBoL-.js} +1 -1
- package/dist/web/assets/{ishikawaDiagram-PHBUUO56-olazD6dZ.js → ishikawaDiagram-PHBUUO56-Proo1Zyp.js} +1 -1
- package/dist/web/assets/{journeyDiagram-4ABVD52K-CttDH9bb.js → journeyDiagram-4ABVD52K-86MYRgHA.js} +1 -1
- package/dist/web/assets/{kanban-definition-K7BYSVSG-BBXbI37U.js → kanban-definition-K7BYSVSG-lsZmnsv1.js} +1 -1
- package/dist/web/assets/keybindings-store-BHUZp2i1.js +1 -0
- package/dist/web/assets/lib-Dmwceoh0.js +4 -0
- package/dist/web/assets/{line-DBLLF7lH.js → line-CNR7Z1Dm.js} +1 -1
- package/dist/web/assets/{linear-BLFWatDe.js → linear-CGDVbc3k.js} +1 -1
- package/dist/web/assets/markdown-renderer-ljVdhEEq.js +69 -0
- package/dist/web/assets/{mermaid-parser.core-BKiGOTjR.js → mermaid-parser.core-C3bmPvHW.js} +2 -2
- package/dist/web/assets/{mindmap-definition-YRQLILUH-DoT7m4Sz.js → mindmap-definition-YRQLILUH-BqZbwYh4.js} +1 -1
- package/dist/web/assets/{ordinal-CCj7PWgZ.js → ordinal-D8VwtNz9.js} +1 -1
- package/dist/web/assets/packet-RMMSAZCW-BJANCvjY.js +1 -0
- package/dist/web/assets/pie-UPGHQEXC-DM2KFfMP.js +1 -0
- package/dist/web/assets/{pieDiagram-SKSYHLDU-Bkh2E4zE.js → pieDiagram-SKSYHLDU-CysZmHF5.js} +1 -1
- package/dist/web/assets/postgres-viewer-Dlkyzslt.js +1 -0
- package/dist/web/assets/{quadrantDiagram-337W2JSQ-B7zgALOL.js → quadrantDiagram-337W2JSQ-B1KHH43M.js} +1 -1
- package/dist/web/assets/radar-KQ55EAFF-BB-ywBD0.js +1 -0
- package/dist/web/assets/react-dom-Bpkvzu3U.js +1 -0
- package/dist/web/assets/{requirementDiagram-Z7DCOOCP-D_5GXNRo.js → requirementDiagram-Z7DCOOCP-DpYZNbHV.js} +1 -1
- package/dist/web/assets/{sankeyDiagram-WA2Y5GQK-BA9EFAAe.js → sankeyDiagram-WA2Y5GQK-1QhDzoqT.js} +1 -1
- package/dist/web/assets/{sequenceDiagram-2WXFIKYE-fyWIrHiG.js → sequenceDiagram-2WXFIKYE-yoBahL9m.js} +1 -1
- package/dist/web/assets/settings-tab-BSfQh_HW.js +1 -0
- package/dist/web/assets/sqlite-viewer-DraX5cHB.js +1 -0
- package/dist/web/assets/{stateDiagram-RAJIS63D-DfRBcaBu.js → stateDiagram-RAJIS63D-c6UuHXom.js} +1 -1
- package/dist/web/assets/stateDiagram-v2-FVOUBMTO-0R9EtHx1.js +1 -0
- package/dist/web/assets/{tab-store-DcIBZTD4.js → tab-store-Ck-9RsH-.js} +1 -1
- package/dist/web/assets/{terminal-tab-B0TAHXjw.js → terminal-tab-C_jOKXBm.js} +2 -2
- package/dist/web/assets/{timeline-definition-YZTLITO2-DYfwJ1jM.js → timeline-definition-YZTLITO2-BayV-4fk.js} +1 -1
- package/dist/web/assets/treemap-KZPCXAKY-DGHYomZ7.js +1 -0
- package/dist/web/assets/use-monaco-theme-BHp8EuUZ.js +11 -0
- package/dist/web/assets/{vennDiagram-LZ73GAT5-DqbKNRD9.js → vennDiagram-LZ73GAT5-B_s6kymD.js} +1 -1
- package/dist/web/assets/{xychartDiagram-JWTSCODW-DhUL86qT.js → xychartDiagram-JWTSCODW-PwVoWxs2.js} +1 -1
- package/dist/web/index.html +13 -10
- package/dist/web/sw.js +1 -1
- package/docs/codebase-summary.md +9 -3
- package/docs/design-guidelines.md +21 -0
- package/package.json +2 -1
- package/src/providers/claude-agent-sdk.ts +14 -2
- package/src/server/index.ts +4 -0
- package/src/server/routes/chat.ts +4 -2
- package/src/server/ws/chat.ts +12 -6
- package/src/services/account-selector.service.ts +8 -2
- package/src/services/claude-usage.service.ts +24 -10
- package/src/services/db.service.ts +45 -6
- package/src/web/components/editor/code-editor.tsx +36 -26
- package/src/web/components/editor/csv-preview.tsx +207 -0
- package/src/web/components/editor/editor-breadcrumb.tsx +225 -0
- package/src/web/components/editor/editor-toolbar.tsx +74 -0
- package/src/web/lib/csv-parser.ts +134 -0
- package/dist/web/assets/architecture-PBZL5I3N-ChOahOB7.js +0 -1
- package/dist/web/assets/channel-w7yboq56.js +0 -1
- package/dist/web/assets/chat-tab--hD0r5RS.js +0 -7
- package/dist/web/assets/chunk-GLR3WWYH-D9pZakqr.js +0 -2
- package/dist/web/assets/chunk-HHEYEP7N-Dld5BpGB.js +0 -1
- package/dist/web/assets/chunk-QZHKN3VN-DwSXwtjH.js +0 -1
- package/dist/web/assets/classDiagram-VBA2DB6C-BpJ6Oog2.js +0 -1
- package/dist/web/assets/classDiagram-v2-RAHNMMFH-Bj8gIhkP.js +0 -1
- package/dist/web/assets/clone-BSi6cgDh.js +0 -1
- package/dist/web/assets/code-editor-EG9sb3gL.js +0 -1
- package/dist/web/assets/database-viewer-h1Zb9cFF.js +0 -1
- package/dist/web/assets/diff-viewer-DrTqG6RM.js +0 -4
- package/dist/web/assets/dist-T0Vhi0Mh.js +0 -16
- package/dist/web/assets/git-graph-Bx3h7BK1.js +0 -1
- package/dist/web/assets/gitGraph-HDMCJU4V-CEee2FCA.js +0 -1
- package/dist/web/assets/index-Beb248lR.css +0 -2
- package/dist/web/assets/index-DmfRyMpE.js +0 -37
- package/dist/web/assets/info-3K5VOQVL-ce_pi3En.js +0 -1
- package/dist/web/assets/infoDiagram-LFFYTUFH-BzqyoqXw.js +0 -2
- package/dist/web/assets/input-Brjz2Vv-.js +0 -41
- package/dist/web/assets/keybindings-store-BScuugqK.js +0 -1
- package/dist/web/assets/markdown-renderer-DwmzGpNI.js +0 -69
- package/dist/web/assets/packet-RMMSAZCW-CdYSLjRL.js +0 -1
- package/dist/web/assets/pie-UPGHQEXC-Bm5LiD-6.js +0 -1
- package/dist/web/assets/postgres-viewer-Bp6mOne8.js +0 -1
- package/dist/web/assets/radar-KQ55EAFF-C4PnyG7_.js +0 -1
- package/dist/web/assets/settings-store-Bbhg_ptG.js +0 -2
- package/dist/web/assets/settings-tab-8lfbaK4W.js +0 -1
- package/dist/web/assets/sqlite-viewer-Cenucoym.js +0 -1
- package/dist/web/assets/stateDiagram-v2-FVOUBMTO-CMN4M2Em.js +0 -1
- package/dist/web/assets/treemap-KZPCXAKY-2_y-mhkz.js +0 -1
- package/dist/web/assets/use-monaco-theme-vwto-Vlf.js +0 -11
- /package/dist/web/assets/{api-client-DpGMOZNf.js → api-client-DniUYaIY.js} +0 -0
- /package/dist/web/assets/{array-BGFCBI0e.js → array-Bxr4Uw0G.js} +0 -0
- /package/dist/web/assets/{columns-2-ChOTgl3e.js → columns-2-DpsNbZOc.js} +0 -0
- /package/dist/web/assets/{cytoscape.esm-Ccan6xou.js → cytoscape.esm-zgx_RusX.js} +0 -0
- /package/dist/web/assets/{defaultLocale-CRZydyG6.js → defaultLocale-BbBFINez.js} +0 -0
- /package/dist/web/assets/{dist-Cce3efmT.js → dist-CBQJF0q0.js} +0 -0
- /package/dist/web/assets/{init-B8gtcn7T.js → init-C9S7-8pU.js} +0 -0
- /package/dist/web/assets/{isArrayLikeObject-B4pdpV8V.js → isArrayLikeObject-sCNOrnc2.js} +0 -0
- /package/dist/web/assets/{katex-Bbu770d9.js → katex-C10ndCVt.js} +0 -0
- /package/dist/web/assets/{math-DwgHI-Cu.js → math-DO7stL4-.js} +0 -0
- /package/dist/web/assets/{path-DZF-JdEe.js → path-DPMyyJeP.js} +0 -0
- /package/dist/web/assets/{preload-helper-qlgyTAkD.js → preload-helper-uTix4PVD.js} +0 -0
- /package/dist/web/assets/{react-BGf7KNLk.js → react-ER-4DN55.js} +0 -0
- /package/dist/web/assets/{rough.esm-VLpapkIG.js → rough.esm-BWqoIFNR.js} +0 -0
- /package/dist/web/assets/{src-BoSBNdA_.js → src-BYKCXnff.js} +0 -0
- /package/dist/web/assets/{table-Yo02WRH-.js → table-C7X5UAEI.js} +0 -0
- /package/dist/web/assets/{tag-CaC1ng2E.js → tag-CCtdV063.js} +0 -0
- /package/dist/web/assets/{utils-btZ8C8-R.js → utils-BcFEFg4m.js} +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Code, Eye, WrapText, Table } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
interface EditorToolbarProps {
|
|
4
|
+
ext: string;
|
|
5
|
+
mdMode?: "edit" | "preview";
|
|
6
|
+
onMdModeChange?: (mode: "edit" | "preview") => void;
|
|
7
|
+
csvMode?: "table" | "raw";
|
|
8
|
+
onCsvModeChange?: (mode: "table" | "raw") => void;
|
|
9
|
+
wordWrap: boolean;
|
|
10
|
+
onToggleWordWrap: () => void;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function ToolbarButton({
|
|
15
|
+
active,
|
|
16
|
+
onClick,
|
|
17
|
+
icon: Icon,
|
|
18
|
+
label,
|
|
19
|
+
}: {
|
|
20
|
+
active: boolean;
|
|
21
|
+
onClick: () => void;
|
|
22
|
+
icon: React.ComponentType<{ className?: string }>;
|
|
23
|
+
label: string;
|
|
24
|
+
}) {
|
|
25
|
+
return (
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
onClick={onClick}
|
|
29
|
+
className={`flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors ${
|
|
30
|
+
active ? "bg-muted text-foreground" : "text-muted-foreground hover:text-foreground"
|
|
31
|
+
}`}
|
|
32
|
+
>
|
|
33
|
+
<Icon className="size-3" />
|
|
34
|
+
<span className="hidden sm:inline">{label}</span>
|
|
35
|
+
</button>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function EditorToolbar({
|
|
40
|
+
ext,
|
|
41
|
+
mdMode,
|
|
42
|
+
onMdModeChange,
|
|
43
|
+
csvMode,
|
|
44
|
+
onCsvModeChange,
|
|
45
|
+
wordWrap,
|
|
46
|
+
onToggleWordWrap,
|
|
47
|
+
className,
|
|
48
|
+
}: EditorToolbarProps) {
|
|
49
|
+
const isMarkdown = ext === "md" || ext === "mdx";
|
|
50
|
+
const isCsv = ext === "csv";
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div className={className}>
|
|
54
|
+
{isMarkdown && onMdModeChange && (
|
|
55
|
+
<>
|
|
56
|
+
<ToolbarButton active={mdMode === "edit"} onClick={() => onMdModeChange("edit")} icon={Code} label="Edit" />
|
|
57
|
+
<ToolbarButton active={mdMode === "preview"} onClick={() => onMdModeChange("preview")} icon={Eye} label="Preview" />
|
|
58
|
+
</>
|
|
59
|
+
)}
|
|
60
|
+
{isCsv && onCsvModeChange && (
|
|
61
|
+
<>
|
|
62
|
+
<ToolbarButton active={csvMode === "table"} onClick={() => onCsvModeChange("table")} icon={Table} label="Table" />
|
|
63
|
+
<ToolbarButton active={csvMode === "raw"} onClick={() => onCsvModeChange("raw")} icon={Code} label="Raw" />
|
|
64
|
+
</>
|
|
65
|
+
)}
|
|
66
|
+
<ToolbarButton
|
|
67
|
+
active={wordWrap}
|
|
68
|
+
onClick={onToggleWordWrap}
|
|
69
|
+
icon={WrapText}
|
|
70
|
+
label="Wrap"
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/** Simple state-machine CSV parser handling quoted fields, embedded commas, newlines */
|
|
2
|
+
|
|
3
|
+
const enum State {
|
|
4
|
+
FIELD_START,
|
|
5
|
+
UNQUOTED,
|
|
6
|
+
QUOTED,
|
|
7
|
+
QUOTE_IN_QUOTED,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface CsvData {
|
|
11
|
+
headers: string[];
|
|
12
|
+
rows: string[][];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function parseCsv(content: string): CsvData {
|
|
16
|
+
const rows: string[][] = [];
|
|
17
|
+
let row: string[] = [];
|
|
18
|
+
let field = "";
|
|
19
|
+
let state: State = State.FIELD_START;
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < content.length; i++) {
|
|
22
|
+
const ch = content[i]!;
|
|
23
|
+
|
|
24
|
+
switch (state) {
|
|
25
|
+
case State.FIELD_START:
|
|
26
|
+
if (ch === '"') {
|
|
27
|
+
state = State.QUOTED;
|
|
28
|
+
} else if (ch === ",") {
|
|
29
|
+
row.push(field);
|
|
30
|
+
field = "";
|
|
31
|
+
} else if (ch === "\r") {
|
|
32
|
+
// skip \r, handle \n next
|
|
33
|
+
} else if (ch === "\n") {
|
|
34
|
+
row.push(field);
|
|
35
|
+
field = "";
|
|
36
|
+
rows.push(row);
|
|
37
|
+
row = [];
|
|
38
|
+
} else {
|
|
39
|
+
field += ch;
|
|
40
|
+
state = State.UNQUOTED;
|
|
41
|
+
}
|
|
42
|
+
break;
|
|
43
|
+
|
|
44
|
+
case State.UNQUOTED:
|
|
45
|
+
if (ch === ",") {
|
|
46
|
+
row.push(field);
|
|
47
|
+
field = "";
|
|
48
|
+
state = State.FIELD_START;
|
|
49
|
+
} else if (ch === "\r") {
|
|
50
|
+
// skip
|
|
51
|
+
} else if (ch === "\n") {
|
|
52
|
+
row.push(field);
|
|
53
|
+
field = "";
|
|
54
|
+
rows.push(row);
|
|
55
|
+
row = [];
|
|
56
|
+
state = State.FIELD_START;
|
|
57
|
+
} else {
|
|
58
|
+
field += ch;
|
|
59
|
+
}
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case State.QUOTED:
|
|
63
|
+
if (ch === '"') {
|
|
64
|
+
state = State.QUOTE_IN_QUOTED;
|
|
65
|
+
} else {
|
|
66
|
+
field += ch;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case State.QUOTE_IN_QUOTED:
|
|
71
|
+
if (ch === '"') {
|
|
72
|
+
// Escaped quote ""
|
|
73
|
+
field += '"';
|
|
74
|
+
state = State.QUOTED;
|
|
75
|
+
} else if (ch === ",") {
|
|
76
|
+
row.push(field);
|
|
77
|
+
field = "";
|
|
78
|
+
state = State.FIELD_START;
|
|
79
|
+
} else if (ch === "\r") {
|
|
80
|
+
// skip
|
|
81
|
+
} else if (ch === "\n") {
|
|
82
|
+
row.push(field);
|
|
83
|
+
field = "";
|
|
84
|
+
rows.push(row);
|
|
85
|
+
row = [];
|
|
86
|
+
state = State.FIELD_START;
|
|
87
|
+
} else {
|
|
88
|
+
// Malformed — treat closing quote as literal
|
|
89
|
+
field += ch;
|
|
90
|
+
state = State.UNQUOTED;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Flush last field/row
|
|
97
|
+
if (field || row.length > 0) {
|
|
98
|
+
row.push(field);
|
|
99
|
+
rows.push(row);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (rows.length === 0) return { headers: [], rows: [] };
|
|
103
|
+
|
|
104
|
+
const headers = rows[0]!;
|
|
105
|
+
const dataRows = rows.slice(1);
|
|
106
|
+
|
|
107
|
+
// Normalize column count — pad short rows, truncate long ones
|
|
108
|
+
const colCount = headers.length;
|
|
109
|
+
for (let i = 0; i < dataRows.length; i++) {
|
|
110
|
+
const r = dataRows[i]!;
|
|
111
|
+
if (r.length < colCount) {
|
|
112
|
+
while (r.length < colCount) r.push("");
|
|
113
|
+
} else if (r.length > colCount) {
|
|
114
|
+
dataRows[i] = r.slice(0, colCount);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return { headers, rows: dataRows };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function serializeCsv(headers: string[], rows: string[][]): string {
|
|
122
|
+
const escape = (val: string): string => {
|
|
123
|
+
if (val.includes(",") || val.includes('"') || val.includes("\n")) {
|
|
124
|
+
return `"${val.replace(/"/g, '""')}"`;
|
|
125
|
+
}
|
|
126
|
+
return val;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const lines = [headers.map(escape).join(",")];
|
|
130
|
+
for (const row of rows) {
|
|
131
|
+
lines.push(row.map(escape).join(","));
|
|
132
|
+
}
|
|
133
|
+
return lines.join("\n");
|
|
134
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./chunk-XZSTWKYB-BYxFzZwS.js";import{n as e}from"./chunk-R5LLSJPH-euR2RxLN.js";export{e as createArchitectureServices};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{it as e,rt as t}from"./chunk-7R4GIKGN-DXaGAn_K.js";var n=(n,r)=>e.lang.round(t.parse(n)[r]);export{n as t};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-DpGMOZNf.js","assets/chunk-CFjPhJqf.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{M as n,N as r,j as i,n as a,t as o}from"./input-Brjz2Vv-.js";import{n as s,t as c}from"./jsx-runtime-BRW_vwa9.js";import{t as l}from"./columns-2-ChOTgl3e.js";import{n as u,o as d,t as f}from"./tab-store-DcIBZTD4.js";import{t as p}from"./tag-CaC1ng2E.js";import{t as m}from"./preload-helper-qlgyTAkD.js";import{n as h}from"./settings-store-Bbhg_ptG.js";import{n as g,r as _,t as v}from"./utils-btZ8C8-R.js";import{i as y,r as b,t as x}from"./api-client-DpGMOZNf.js";import{a as S,c as C,d as w,i as T,o as E,r as D,s as O,t as k,u as A}from"./api-settings--eVrUeZM.js";import{$ as j,A as M,B as N,D as P,E as F,F as I,G as L,J as R,L as z,M as B,N as ee,O as V,P as H,Q as U,R as te,U as ne,V as W,W as re,X as ie,a as ae,b as G,c as oe,d as K,et as se,f as q,it as ce,l as le,n as ue,o as de,p as J,q as fe,r as pe,rt as me,s as he,tt as ge,u as _e,z as ve}from"./index-DmfRyMpE.js";import"./chunk-GEFDOKGD-DwVPiYfW.js";import"./src-BoSBNdA_.js";import"./chunk-7R4GIKGN-DXaGAn_K.js";import"./chunk-HHEYEP7N-Dld5BpGB.js";import"./dist-Cce3efmT.js";import"./chunk-PU5JKC2W-B66ELkQm.js";import"./chunk-MX3YWQON-BgjSEzus.js";import"./chunk-YBOYWFTD-Dx_fX35n.js";import"./chunk-PQ6SQG4A-BxtUGYhW.js";import"./chunk-KYZI473N-BKO5gMeU.js";import"./chunk-O4XLMI2P-BurQy8tt.js";import"./chunk-GLR3WWYH-D9pZakqr.js";import"./chunk-XPW4576I-CtcaMb09.js";import{t as ye}from"./markdown-renderer-DwmzGpNI.js";var be=s(`activity`,[[`path`,{d:`M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2`,key:`169zse`}]]),xe=s(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),Se=s(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),Ce=s(`clipboard-list`,[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`,key:`116196`}],[`path`,{d:`M12 11h4`,key:`1jrz19`}],[`path`,{d:`M12 16h4`,key:`n85exb`}],[`path`,{d:`M8 11h.01`,key:`1dfujw`}],[`path`,{d:`M8 16h.01`,key:`18s6g9`}]]),we=s(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),Te=s(`hand`,[[`path`,{d:`M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2`,key:`1fvzgz`}],[`path`,{d:`M14 10V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2`,key:`1kc0my`}],[`path`,{d:`M10 10.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8`,key:`10h0bg`}],[`path`,{d:`M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15`,key:`1s1gnw`}]]),Ee=s(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),De=s(`image`,[[`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`}]]),Oe=s(`list-todo`,[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]),ke=s(`mic-off`,[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]),Ae=s(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),je=s(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),Me=s(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),Ne=s(`shield-off`,[[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M5 5a1 1 0 0 0-1 1v7c0 5 3.5 7.5 7.67 8.94a1 1 0 0 0 .67.01c2.35-.82 4.48-1.97 5.9-3.71`,key:`1jlk70`}],[`path`,{d:`M9.309 3.652A12.252 12.252 0 0 0 11.24 2.28a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1v7a9.784 9.784 0 0 1-.08 1.264`,key:`18rp1v`}]]),Pe=s(`sparkles`,[[`path`,{d:`M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z`,key:`1s2grr`}],[`path`,{d:`M20 2v4`,key:`1rf3ol`}],[`path`,{d:`M22 4h-4`,key:`gwowj6`}],[`circle`,{cx:`4`,cy:`20`,r:`2`,key:`6kqj1y`}]]),Fe=s(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),Y=e(t(),1),Ie=3e4,Le=1e3,Re=class{ws=null;url;handlers=[];reconnectAttempts=0;reconnectTimer=null;intentionalClose=!1;pendingMessages=[];constructor(e){this.url=e}connect(){this.intentionalClose=!1,this.cleanup();let e=window.location.protocol===`https:`?`wss:`:`ws:`,t=this.url.startsWith(`ws`)?this.url:`${e}//${window.location.host}${this.url}`;this.ws=new WebSocket(t),this.ws.onopen=()=>{this.reconnectAttempts=0;try{this.ws?.send(JSON.stringify({type:`ready`}))}catch{}if(this.pendingMessages.length>0){console.log(`[ws] flushing ${this.pendingMessages.length} queued message(s)`);for(let e of this.pendingMessages)try{this.ws?.send(e)}catch{}this.pendingMessages=[]}},this.ws.onmessage=e=>{for(let t of this.handlers)t(e)},this.ws.onclose=()=>{this.intentionalClose||this.scheduleReconnect()},this.ws.onerror=()=>{this.ws?.close()}}disconnect(){this.intentionalClose=!0,this.pendingMessages=[],this.cleanup(),this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null)}send(e){this.ws?.readyState===WebSocket.OPEN?this.ws.send(e):this.ws?.readyState===WebSocket.CONNECTING?(console.warn(`[ws] WS still CONNECTING — queuing message`),this.pendingMessages.push(e)):console.warn(`[ws] message dropped — readyState=${this.ws?.readyState??`no-ws`}`)}onMessage(e){return this.handlers.push(e),()=>{this.handlers=this.handlers.filter(t=>t!==e)}}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}cleanup(){this.ws&&=(this.ws.onopen=null,this.ws.onclose=null,this.ws.onmessage=null,this.ws.onerror=null,(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)&&this.ws.close(),null)}scheduleReconnect(){let e=Math.min(Le*2**this.reconnectAttempts,Ie);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ze({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{let i=new Re(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,Y.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,Y.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,Y.useCallback)(()=>{r.current?.disconnect()},[])}}var Be=null;function Ve(){return Be||=new AudioContext,Be}function X(e,t,n,r,i=`sine`){let a=Ve(),o=a.createOscillator(),s=a.createGain();o.type=i,o.frequency.value=e,s.gain.setValueAtTime(r,n),s.gain.exponentialRampToValueAtTime(.001,n+t),o.connect(s),s.connect(a.destination),o.start(n),o.stop(n+t)}function He(){let e=Ve().currentTime;X(523,.15,e,.15),X(659,.2,e+.12,.15)}function Ue(){let e=Ve().currentTime;X(880,.12,e,.18,`square`),X(698,.12,e+.15,.18,`square`),X(880,.15,e+.3,.15,`square`)}function We(){let e=Ve().currentTime;X(440,.12,e,.12),X(523,.12,e+.1,.12),X(659,.18,e+.2,.12)}var Ge={done:He,approval_request:Ue,question:We};function Ke(e){try{Ge[e]?.()}catch{}}function qe(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=u.getState(),r=t[n];if(!r)return!1;let i=r.tabs.find(e=>e.id===r.activeTabId);return i?.type===`chat`&&i.metadata?.sessionId===e}function Je(e,t=`claude`,n=``){let[r,i]=(0,Y.useState)([]),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(`idle`),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(0),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null),[x,S]=(0,Y.useState)(!1),C=(0,Y.useRef)(``),w=(0,Y.useRef)([]),T=(0,Y.useRef)(null),E=(0,Y.useRef)(`idle`),D=(0,Y.useRef)(null),O=(0,Y.useRef)(()=>{}),k=(0,Y.useRef)(null),A=(0,Y.useRef)(e);A.current=e;let j=(0,Y.useRef)(n);j.current=n;let M=s!==`idle`,N=(0,Y.useCallback)((e,t)=>{let n=w.current.findIndex(e=>e.type===`tool_use`&&(e.tool===`Agent`||e.tool===`Task`)&&e.toolUseId===t);if(n===-1)return!1;let r=w.current[n];if(r.type!==`tool_use`)return!1;let i=[...r.children??[],e];return w.current[n]={...r,children:i},!0},[]),P=(0,Y.useCallback)(()=>{let e=C.current,t=[...w.current],n=T.current;i(r=>{let i=r[r.length-1];return i?.role===`assistant`&&!i.id.startsWith(`final-`)?[...r.slice(0,-1),{...i,content:e,events:t,...n}]:[...r,{id:`streaming-${Date.now()}`,role:`assistant`,content:e,events:t,timestamp:new Date().toISOString(),...n}]})},[]),F=(0,Y.useCallback)(e=>{let t=e,n=t?.type;if(n)switch(n){case`account_info`:T.current={accountId:t.accountId,accountLabel:t.accountLabel};break;case`text`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}C.current+=t.content,w.current.push(t),P();break}case`thinking`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}w.current.push(t),P();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}w.current.push(t),P();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&N(t,e)){P();break}w.current.push(t),P();break}case`approval_request`:if(w.current.push(t),m({requestId:t.requestId,tool:t.tool,input:t.input}),A.current&&!qe(A.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;G.getState().addNotification(A.current,e,j.current),Ke(e)}break;case`error`:{w.current.push(t);let e=[...w.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,events:e}]:[...n,{id:`error-${Date.now()}`,role:`system`,content:t.message,events:[t],timestamp:new Date().toISOString()}]});break}case`done`:{if(E.current===`idle`)break;t.contextWindowPct!=null&&g(t.contextWindowPct),A.current&&!qe(A.current)&&(G.getState().addNotification(A.current,`done`,j.current),Ke(`done`));let e=C.current,n=[...w.current];i(t=>{let r=t[t.length-1];return r?.role===`assistant`?[...t.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:n.length>0?n:r.events}]:t}),C.current=``,w.current=[],T.current=null;break}}},[N,P]),I=(0,Y.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type!==`ping`){if(t.type===`title_updated`){v(t.title??null);return}if(t.type===`phase_changed`){let e=t.phase;c(e),E.current=e,f(e===`connecting`?t.elapsed??0:0);return}if(t.type===`session_state`){S(!0);let e=t,n=e.phase;c(n),E.current=n,e.sessionTitle&&v(e.sessionTitle),e.pendingApproval&&m({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),n===`idle`&&(k.current?.(),u(!1));return}if(t.type===`turn_events`){let e=t.events;if(!e?.length){u(!1);return}i(e=>{let t=e.findLastIndex(e=>e.role===`user`);return t>=0?e.slice(0,t+1):e}),C.current=``,w.current=[],T.current=null;let n=0,r=()=>{let t=Math.min(n+100,e.length);for(let r=n;r<t;r++)F(e[r]);n=t,n<e.length?requestAnimationFrame(r):u(!1)};requestAnimationFrame(r);return}F(t)}},[F]),{send:L,connect:R}=ze({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:I,autoConnect:!!e&&!!n});O.current=L,(0,Y.useEffect)(()=>{let r=!1;return c(`idle`),E.current=`idle`,m(null),C.current=``,w.current=[],S(!1),e&&n?(o(!0),fetch(`${y(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${b()}`}}).then(e=>e.json()).then(e=>{r||E.current!==`idle`||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&E.current===`idle`&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let z=(0,Y.useCallback)((e,t)=>{if(e.trim()){if(E.current!==`idle`){let e=C.current,t=[...w.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),L(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),C.current=``,w.current=[],D.current=null,c(`initializing`),E.current=`initializing`,m(null),L(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode}))}},[L]),B=(0,Y.useCallback)((e,t,n)=>{if(L(JSON.stringify({type:`approval_response`,requestId:e,approved:t,data:n})),t&&n){let t=w.current.find(t=>t.type===`approval_request`&&t.requestId===e&&t.tool===`AskUserQuestion`);if(t){let e=t.input;e&&typeof e==`object`&&(e.answers=n)}i(e=>[...e])}m(null)},[L]),ee=(0,Y.useCallback)(()=>{if(E.current===`idle`)return;L(JSON.stringify({type:`cancel`}));let e=C.current,t=[...w.current];i(n=>{let r=n[n.length-1];return r?.role===`assistant`?[...n.slice(0,-1),{...r,id:`final-${Date.now()}`,content:e||r.content,events:t.length>0?t:r.events}]:n}),C.current=``,w.current=[],D.current=null,c(`idle`),E.current=`idle`,m(null)},[L]),V=(0,Y.useCallback)(()=>{S(!1),u(!0),R()},[R]),H=(0,Y.useCallback)(()=>{!e||!n||(o(!0),fetch(`${y(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${b()}`}}).then(e=>e.json()).then(e=>{e.ok&&Array.isArray(e.data)&&e.data.length>0&&(i(e.data),C.current=``,w.current=[])}).catch(()=>{}).finally(()=>o(!1)))},[e,t,n]);return k.current=H,{messages:r,messagesLoading:a,isStreaming:M,phase:s,isReconnecting:l,connectingElapsed:d,pendingApproval:p,contextWindowPct:h,sessionTitle:_,sendMessage:z,respondToApproval:B,cancelStreaming:ee,reconnect:V,refetchMessages:H,isConnected:x}}var Ye=12e4;function Xe(e,t=`claude`){let[n,r]=(0,Y.useState)({}),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${y(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${b()}`}}).then(e=>e.json()).then(e=>{e.ok&&e.data&&(r(t=>({...t,...e.data})),e.data.lastFetchedAt&&s(e.data.lastFetchedAt))}).catch(()=>{}).finally(()=>a(!1))},[e,t]);return(0,Y.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Ye),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,Y.useCallback)(()=>l(!0),[l])}}var Ze={damping:.7,stiffness:.05,mass:1.25},Qe=70,$e=1e3/60,et=350,tt=!1;globalThis.document?.addEventListener(`mousedown`,()=>{tt=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{tt=!1}),globalThis.document?.addEventListener(`click`,()=>{tt=!1});var nt=(e={})=>{let[t,n]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(e.initial!==!1),[a,o]=(0,Y.useState)(!1),s=(0,Y.useRef)(null);s.current=e;let c=(0,Y.useCallback)(()=>{if(!tt)return!1;let e=window.getSelection();if(!e||!e.rangeCount)return!1;let t=e.getRangeAt(0);return t.commonAncestorContainer.contains(g.current)||g.current?.contains(t.commonAncestorContainer)},[]),l=(0,Y.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,Y.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,Y.useMemo)(()=>{let n;return{escapedFromLock:t,isAtBottom:r,resizeDifference:0,accumulated:0,velocity:0,listeners:new Set,get scrollTop(){return g.current?.scrollTop??0},set scrollTop(e){g.current&&(g.current.scrollTop=e,d.ignoreScrollToTop=g.current.scrollTop)},get targetScrollTop(){return!g.current||!_.current?0:g.current.scrollHeight-1-g.current.clientHeight},get calculatedTargetScrollTop(){if(!g.current||!_.current)return 0;let{targetScrollTop:t}=this;if(!e.targetScrollTop)return t;if(n?.targetScrollTop===t)return n.calculatedScrollTop;let r=Math.max(Math.min(e.targetScrollTop(t,{scrollElement:g.current,contentElement:_.current}),t),0);return n={targetScrollTop:t,calculatedScrollTop:r},requestAnimationFrame(()=>{n=void 0}),r},get scrollDifference(){return this.calculatedTargetScrollTop-this.scrollTop},get isNearBottom(){return this.scrollDifference<=Qe}}},[]),f=(0,Y.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=at(s.current,e.animation),{ignoreEscapes:r=!1}=e,i,a=d.calculatedTargetScrollTop;e.duration instanceof Promise?e.duration.finally(()=>{i=Date.now()}):i=t+(e.duration??0);let o=async()=>{let e=new Promise(requestAnimationFrame).then(()=>{if(!d.isAtBottom)return d.animation=void 0,!1;let{scrollTop:l}=d,u=performance.now(),p=(u-(d.lastTick??u))/$e;if(d.animation||={behavior:n,promise:e,ignoreEscapes:r},d.animation.behavior===n&&(d.lastTick=u),c()||t>Date.now())return o();if(l<Math.min(a,d.calculatedTargetScrollTop)){if(d.animation?.behavior===n){if(n===`instant`)return d.scrollTop=d.calculatedTargetScrollTop,o();d.velocity=(n.damping*d.velocity+n.stiffness*d.scrollDifference)/n.mass,d.accumulated+=d.velocity*p,d.scrollTop+=d.accumulated,d.scrollTop!==l&&(d.accumulated=0)}return o()}return i>Date.now()?(a=d.calculatedTargetScrollTop,o()):(d.animation=void 0,d.scrollTop<d.calculatedTargetScrollTop?f({animation:at(s.current,s.current.resize),ignoreEscapes:r,duration:Math.max(0,i-Date.now())||void 0}):d.isAtBottom)});return e.then(e=>(requestAnimationFrame(()=>{d.animation||(d.lastTick=void 0,d.velocity=0)}),e))};return e.wait!==!0&&(d.animation=void 0),d.animation?.behavior===n?d.animation.promise:o()},[l,c,d]),p=(0,Y.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,Y.useCallback)(({target:e})=>{if(e!==g.current)return;let{scrollTop:t,ignoreScrollToTop:n}=d,{lastScrollTop:r=t}=d;d.lastScrollTop=t,d.ignoreScrollToTop=void 0,n&&n>t&&(r=n),o(d.isNearBottom),setTimeout(()=>{if(d.resizeDifference||t===n)return;if(c()){u(!0),l(!1);return}let e=t>r,i=t<r;if(d.animation?.ignoreEscapes){d.scrollTop=r;return}i&&(u(!0),l(!1)),e&&u(!1),!d.escapedFromLock&&d.isNearBottom&&l(!0)},1)},[u,l,c,d]),h=(0,Y.useCallback)(({target:e,deltaY:t})=>{let n=e;for(;![`scroll`,`auto`].includes(getComputedStyle(n).overflow);){if(!n.parentElement)return;n=n.parentElement}n===g.current&&t<0&&g.current.scrollHeight>g.current.clientHeight&&!d.animation?.ignoreEscapes&&(u(!0),l(!1))},[u,l,d]),g=rt(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=rt(e=>{if(d.resizeObserver?.disconnect(),!e)return;let t;d.resizeObserver=new ResizeObserver(([e])=>{let{height:n}=e.contentRect,r=n-(t??n);if(d.resizeDifference=r,d.scrollTop>d.targetScrollTop&&(d.scrollTop=d.targetScrollTop),o(d.isNearBottom),r>=0){let e=at(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:et})}else d.isNearBottom&&(u(!1),l(!0));t=n,requestAnimationFrame(()=>{setTimeout(()=>{d.resizeDifference===r&&(d.resizeDifference=0)},1)})}),d.resizeObserver?.observe(e)},[]);return{contentRef:_,scrollRef:g,scrollToBottom:f,stopScroll:p,isAtBottom:r||a,isNearBottom:a,escapedFromLock:t,state:d}};function rt(e,t){let n=(0,Y.useCallback)(t=>(n.current=t,e(t)),t);return n}var it=new Map;function at(...e){let t={...Ze},n=!1;for(let r of e){if(r===`instant`){n=!0;continue}typeof r==`object`&&(n=!1,t.damping=r.damping??t.damping,t.stiffness=r.stiffness??t.stiffness,t.mass=r.mass??t.mass)}let r=JSON.stringify(t);return it.has(r)||it.set(r,Object.freeze(t)),n?`instant`:it.get(r)}var ot=(0,Y.createContext)(null),st=typeof window<`u`?Y.useLayoutEffect:Y.useEffect;function ct({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,Y.useRef)(null),d=nt({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:Y.useCallback((e,t)=>(y?.targetScrollTop??s)?.(e,t)??e,[s])}),{scrollRef:f,contentRef:p,scrollToBottom:m,stopScroll:h,isAtBottom:g,escapedFromLock:_,state:v}=e??d,y=(0,Y.useMemo)(()=>({scrollToBottom:m,stopScroll:h,scrollRef:f,isAtBottom:g,escapedFromLock:_,contentRef:p,state:v,get targetScrollTop(){return u.current},set targetScrollTop(e){u.current=e}}),[m,g,p,f,h,_,v]);return(0,Y.useImperativeHandle)(c,()=>y,[y]),st(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),Y.createElement(ot.Provider,{value:y},Y.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=lt();return Y.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},Y.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(ct||={});function lt(){let e=(0,Y.useContext)(ot);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var Z=c();function ut(e){let t=e.type===`approval_request`;return{toolName:e.type===`tool_use`?e.tool:t?e.tool??`Tool`:`Tool`,input:e.type===`tool_use`?e.input:t?e.input??{}:{}}}function dt({tool:e,result:t,completed:r,projectName:i}){let[a,o]=(0,Y.useState)(!1);if(e.type===`error`)return(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded bg-red-500/10 border border-red-500/20 px-2 py-1.5 text-xs text-red-400`,children:[(0,Z.jsx)(j,{className:`size-3`}),(0,Z.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=ut(e),l=t?.type===`tool_result`,u=l&&!!t.isError,d=s===`AskUserQuestion`&&!!c?.answers,f=(s===`Agent`||s===`Task`)&&e.type===`tool_use`,p=f?e.children:void 0,m=p&&p.length>0;return(0,Z.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,Z.jsxs)(`button`,{onClick:()=>o(!a),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors min-w-0`,children:[a?(0,Z.jsx)(n,{className:`size-3 shrink-0`}):(0,Z.jsx)(ge,{className:`size-3 shrink-0`}),u?(0,Z.jsx)(Se,{className:`size-3 text-red-400 shrink-0`}):l||d||r?(0,Z.jsx)(U,{className:`size-3 text-green-400 shrink-0`}):(0,Z.jsx)(N,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,Z.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,Z.jsx)(ft,{name:s,input:c})}),m&&(0,Z.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),a&&(0,Z.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,Z.jsx)(pt,{name:s,input:c,projectName:i}),m&&(0,Z.jsx)(_t,{events:p,projectName:i}),l&&(0,Z.jsx)(ht,{toolName:s,output:t.output})]})]})}function ft({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:v(n(t.file_path))})]});case`Bash`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Q(n(t.command),60)})]});case`Glob`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Q(n(t.pattern),40)})]});case`WebSearch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(B,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.query),50)})]});case`WebFetch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(W,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.url),50)})]});case`ToolSearch`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(B,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.query),50)})]});case`Agent`:case`Task`:return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(me,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:Q(n(t.description||t.prompt),60)})]});case`TodoWrite`:{let n=Array.isArray(t.todos)?t.todos:[],r=n.filter(e=>e.status===`completed`).length;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Oe,{className:`size-3 inline`}),` `,e,` `,(0,Z.jsxs)(`span`,{className:`text-text-subtle`,children:[r,`/`,n.length,` done`]})]})}case`AskUserQuestion`:{let n=Array.isArray(t.questions)?t.questions:[],r=!!t.answers;return(0,Z.jsxs)(Z.Fragment,{children:[e,` `,(0,Z.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,Z.jsx)(Z.Fragment,{children:e})}}function pt({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=f(),a=e=>{n&&i({type:`editor`,title:v(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${v(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Z.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,Z.jsx)(`pre`,{className:`font-mono text-text-secondary overflow-x-auto whitespace-pre-wrap break-all`,children:r(t.command)})]});case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:{let n=r(t.file_path);return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`font-mono text-text-secondary break-all hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>a(n),title:`Open file in editor`,children:[(0,Z.jsx)(d,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,Z.jsxs)(`button`,{type:`button`,className:`text-text-subtle hover:text-primary hover:underline text-left flex items-center gap-1`,onClick:()=>o(n,r(t.old_string),r(t.new_string)),title:`View diff in new tab`,children:[(0,Z.jsx)(l,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,Z.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Q(r(t.content),300)})]})}case`Glob`:return(0,Z.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,Z.jsx)(mt,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,Z.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,Z.jsx)(vt,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,Z.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`a`,{href:r(t.url),target:`_blank`,rel:`noopener noreferrer`,className:`font-mono text-primary hover:underline break-all flex items-center gap-1`,children:[(0,Z.jsx)(W,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,Z.jsx)(`p`,{className:`text-text-subtle`,children:Q(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,Z.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Z.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,Z.jsx)(`span`,{className:`inline-block rounded px-1.5 py-0.5 text-xs border ${(n[e.question]??``).split(`, `).includes(t.label)?`border-accent bg-accent/20 text-text-primary`:`border-border text-text-subtle`}`,children:t.label},r))}),n[e.question]&&(0,Z.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function mt({todos:e}){return(0,Z.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 mt-0.5 ${e.status===`completed`?`text-green-400`:e.status===`in_progress`?`text-yellow-400`:`text-text-subtle`}`,children:e.status===`completed`?`✓`:e.status===`in_progress`?`▶`:`○`}),(0,Z.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function ht({toolName:e,output:t}){let[n,r]=(0,Y.useState)(!1),i=(0,Y.useMemo)(()=>{if(e!==`Agent`&&e!==`Task`)return null;try{let e=JSON.parse(t);if(Array.isArray(e)){let t=e.filter(e=>e.type===`text`&&e.text).map(e=>e.text).join(`
|
|
3
|
-
|
|
4
|
-
`);if(t)return t}if(typeof e==`string`)return e}catch{if(t&&!t.startsWith(`[{`))return t}return null},[e,t]);return i?(0,Z.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,Z.jsx)(vt,{content:i,maxHeight:`max-h-60`}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>r(!n),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors`,children:[(0,Z.jsx)(we,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,Z.jsx)(gt,{output:t})}function gt({output:e}){let t=e.split(`
|
|
5
|
-
`).length,r=t>3||e.length>200,[i,a]=(0,Y.useState)(r);return(0,Z.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[r&&(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`flex items-center gap-1 text-[10px] text-text-subtle hover:text-text-secondary transition-colors mb-1`,children:[i?(0,Z.jsx)(ge,{className:`size-3`}):(0,Z.jsx)(n,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,Z.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono whitespace-pre-wrap break-all ${i?`max-h-16 overflow-hidden`:`max-h-60`}`,children:e})]})}function _t({events:e,projectName:t}){let n=[],r=``;for(let t of e)if(t.type===`text`)r+=t.content;else if(t.type===`tool_use`)r&&=(n.push({kind:`text`,content:r}),``),n.push({kind:`tool`,tool:t});else if(t.type===`tool_result`){let e=t.toolUseId,r=e?n.find(t=>t.kind===`tool`&&t.tool.type===`tool_use`&&t.tool.toolUseId===e&&!t.result):n.findLast(e=>e.kind===`tool`&&!e.result);r&&(r.result=t)}return r&&n.push({kind:`text`,content:r}),(0,Z.jsx)(`div`,{className:`border-l-2 border-accent/20 pl-2 space-y-1 mt-1`,children:n.map((e,n)=>e.kind===`text`?(0,Z.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,Z.jsx)(vt,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,Z.jsx)(dt,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function vt({content:e,maxHeight:t=`max-h-48`}){return(0,Z.jsx)(ye,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function Q(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function yt(e){let[t,n]=(0,Y.useState)({}),[r,i]=(0,Y.useState)({}),[a,o]=(0,Y.useState)(0),s=(0,Y.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,Y.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,Y.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,Y.useCallback)(e=>(t[e]?.length??0)>0||(r[e]?.trim().length??0)>0,[t,r]);return{answers:t,customInputs:r,activeTab:a,setActiveTab:o,handleSingleSelect:s,handleMultiSelect:c,handleCustomInput:l,hasAnswer:u,allAnswered:(0,Y.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,Y.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,Y.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,Y.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function bt(e){let[t,n]=(0,Y.useState)(0),r=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>n(0),[e.activeTab]),(0,Y.useEffect)(()=>{if(!e.enabled)return;let i=r=>{let i=document.activeElement===e.customInputRef.current;if(!i&&r.key>=`1`&&r.key<=`9`){r.preventDefault();let t=parseInt(r.key)-1;t<e.totalOptions-1&&(n(t),e.onSelectOption(t));return}if(!i&&(r.key===`o`||r.key===`O`||r.key===`0`)){r.preventDefault(),e.customInputRef.current?.focus(),n(e.totalOptions-1);return}if(r.key===`Tab`&&e.questions.length>1){r.preventDefault(),r.shiftKey?e.goToPrevTab():e.goToNextTab();return}if(!i){if(r.key===`ArrowLeft`){r.preventDefault(),e.goToPrevTab();return}if(r.key===`ArrowRight`){r.preventDefault(),e.goToNextTab();return}if(r.key===`ArrowUp`){r.preventDefault(),n(e=>Math.max(0,e-1));return}if(r.key===`ArrowDown`){r.preventDefault(),n(t=>Math.min(e.totalOptions-1,t+1));return}if(r.key===` `){r.preventDefault(),e.onSelectOption(t);return}}if(r.key===`Enter`){r.preventDefault(),e.allAnswered?e.onSubmit():e.hasAnswer(e.activeTab)&&e.goToNextTab();return}r.key===`Escape`&&i&&e.customInputRef.current?.blur()},a=r.current;return a&&(a.addEventListener(`keydown`,i),a.setAttribute(`tabindex`,`0`),a.contains(document.activeElement)||a.focus()),()=>{a?.removeEventListener(`keydown`,i)}},[e,t]),{focusedOption:t,setFocusedOption:n,containerRef:r}}function xt({questions:e,onSubmit:t,onSkip:n}){let r=(0,Y.useRef)(null),i=yt(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,Y.useCallback)(()=>{if(!i.allAnswered)return;let n={};e.forEach((e,t)=>{n[e.question]=i.getFinalAnswer(t)}),t(n)},[i.allAnswered,i.getFinalAnswer,e,t]),l=(0,Y.useCallback)(e=>{if(!(!a||e<0))if(e<a.options.length){let t=a.options[e]?.label;if(!t)return;a.multiSelect?i.handleMultiSelect(i.activeTab,t):i.handleSingleSelect(i.activeTab,t)}else e===a.options.length&&r.current?.focus()},[a,i]),u=bt({questions:e,activeTab:i.activeTab,totalOptions:o,allAnswered:i.allAnswered,hasAnswer:i.hasAnswer,onSelectOption:l,goToNextTab:i.goToNextTab,goToPrevTab:i.goToPrevTab,onSubmit:c,customInputRef:r,enabled:!0}),d=(0,Y.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,Z.jsxs)(`div`,{ref:u.containerRef,className:`rounded-lg border-2 border-primary/30 bg-primary/5 p-3 space-y-3 outline-none animate-in slide-in-from-bottom-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,Z.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,Z.jsxs)(`span`,{className:`text-[10px] text-text-secondary font-normal`,children:[s?`←→ tabs · `:``,`↑↓ options · 1-`,Math.min(o-1,9),` select · Enter submit`]})]}),s&&(0,Z.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,Z.jsxs)(`button`,{className:`flex items-center gap-1.5 px-3 py-1.5 rounded text-xs whitespace-nowrap transition-all ${i.activeTab===t?`bg-primary text-primary-foreground`:i.hasAnswer(t)?`text-primary bg-transparent`:`text-text-secondary hover:bg-surface-elevated`}`,onClick:()=>{i.setActiveTab(t),u.setFocusedOption(0)},tabIndex:-1,children:[(0,Z.jsx)(`span`,{className:`flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-semibold ${i.activeTab===t?`bg-white/20`:i.hasAnswer(t)?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:i.hasAnswer(t)?`✓`:t+1}),(0,Z.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,Z.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,Z.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a.options.map((e,t)=>{let n=(i.answers[i.activeTab]||[]).includes(e.label),r=u.focusedOption===t;return(0,Z.jsxs)(`button`,{onClick:()=>d(t),className:`text-left flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border transition-all ${n?`border-primary bg-primary/10 text-text-primary`:`border-border bg-background text-text-secondary hover:border-primary/40 hover:bg-primary/5`} ${r?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Z.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded text-[10px] font-semibold shrink-0 mt-px ${n?`bg-primary/20 text-primary`:`bg-surface-elevated text-text-secondary`}`,children:t+1}),(0,Z.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,Z.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,Z.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded px-2.5 py-2 text-xs border border-dashed transition-all border-border bg-transparent ${u.focusedOption===o-1?`ring-2 ring-primary/40 ring-offset-1 ring-offset-background`:``}`,children:[(0,Z.jsx)(`span`,{className:`flex items-center justify-center w-4.5 h-4.5 rounded bg-surface-elevated text-text-secondary text-[10px] font-semibold shrink-0 mt-px`,children:`O`}),(0,Z.jsx)(`input`,{ref:r,type:`text`,className:`flex-1 px-2 py-1 text-xs bg-surface border border-border rounded text-text-primary outline-none placeholder:text-text-subtle focus:border-primary`,placeholder:`Other (press O to type)...`,value:i.customInputs[i.activeTab]||``,onChange:e=>i.handleCustomInput(i.activeTab,e.target.value),onFocus:()=>u.setFocusedOption(o-1)})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToPrevTab,disabled:i.activeTab===0,tabIndex:-1,children:`← Prev`}),(0,Z.jsx)(`button`,{className:`px-3 py-1.5 text-xs rounded border border-border bg-background text-text-primary hover:bg-surface-elevated disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,onClick:i.goToNextTab,disabled:i.activeTab===e.length-1,tabIndex:-1,children:`Next →`})]}),(0,Z.jsx)(`button`,{onClick:n,className:`px-4 py-1.5 rounded border border-border bg-background text-text-secondary text-xs hover:bg-surface-elevated transition-colors`,tabIndex:-1,children:`Skip`}),(0,Z.jsxs)(`button`,{onClick:c,disabled:!i.allAnswered,className:`px-4 py-1.5 rounded bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/80 transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,tabIndex:-1,children:[`Submit `,i.allAnswered?`✓`:`(${e.filter((e,t)=>i.hasAnswer(t)).length}/${e.length})`]})]})]})}function St({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,phase:a,connectingElapsed:o,projectName:s,onFork:c}){if(t)return(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Z.jsx)(me,{className:`size-10 text-text-subtle animate-pulse`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]});if(e.length===0&&!i)return(0,Z.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,Z.jsx)(me,{className:`size-10 text-text-subtle`}),(0,Z.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]});let l=(0,Y.useMemo)(()=>e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return e.role===`user`?t:t||n}),[e]);return(0,Z.jsx)(`div`,{className:`relative flex-1 overflow-hidden flex flex-col min-h-0`,children:(0,Z.jsxs)(ct,{className:`flex-1 overflow-y-auto overflow-x-hidden`,resize:`smooth`,initial:`instant`,children:[(0,Z.jsxs)(ct.Content,{className:`p-4 space-y-4`,children:[l.map(e=>(0,Z.jsx)(wt,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:s,onFork:e.role===`user`&&c?()=>c(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,Z.jsx)(qt,{approval:n,onRespond:r}):(0,Z.jsx)(Kt,{approval:n,onRespond:r})),i&&(0,Z.jsx)(Wt,{lastMessage:e[e.length-1],phase:a,elapsed:o})]}),(0,Z.jsx)(Ct,{})]})})}function Ct(){let{isAtBottom:e,scrollToBottom:t}=lt();return e?null:(0,Z.jsxs)(`button`,{onClick:()=>t(),className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1 px-3 py-1 rounded-full bg-surface-elevated border border-border text-xs text-text-secondary hover:text-foreground shadow-lg transition-all`,children:[(0,Z.jsx)(n,{className:`size-3`}),`Scroll to bottom`]})}function wt({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,Z.jsx)(Mt,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-red-500/10 border border-red-500/20 px-3 py-2 text-sm text-red-400`,children:[(0,Z.jsx)(j,{className:`size-4 shrink-0`}),(0,Z.jsx)(`p`,{children:e.content})]}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,Z.jsx)(Vt,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Z.jsx)(Gt,{content:e.content,projectName:n})}),e.accountLabel&&(0,Z.jsxs)(`p`,{className:`text-[10px] select-none`,style:{color:`var(--color-text-subtle)`},children:[`via `,e.accountLabel]})]})}var Tt=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]),Et={"system-reminder":`Context`,claudeMd:`CLAUDE.md`,gitStatus:`Git Status`,currentDate:`Date`,fast_mode_info:`Fast Mode`,"available-deferred-tools":`Tools`,"task-notification":`Task Result`,environment_details:`Environment`};function Dt(e){let t=[],n=/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate|task-notification|environment_details)[^>]*>([\s\S]*?)<\/\1>/g,r;for(;(r=n.exec(e))!==null;){let e=r[1];t.push({name:e,label:Et[e]??e.replace(/^antml:/,``).replace(/-/g,` `),content:r[2].trim()})}return{cleanText:e.replace(n,``).trim(),tags:t}}function Ot(e){let t=e.match(/^\[Attached file: (.+?)\]\n\n?/);if(t)return{files:[t[1]],text:e.slice(t[0].length)};let n=e.match(/^\[Attached files:\n([\s\S]+?)\]\n\n?/);return n?{files:n[1].split(`
|
|
6
|
-
`).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function kt(e,t){let n=v(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function At(e){let t=e.lastIndexOf(`.`);return t===-1?!1:Tt.has(e.slice(t).toLowerCase())}var jt=new Set([`task-notification`,`environment_details`]);function Mt({content:e,projectName:t,onFork:r}){let{files:a,text:o,tags:s}=(0,Y.useMemo)(()=>{let t=Ot(e),{cleanText:n,tags:r}=Dt(t.text);return{files:t.files,text:n,tags:r}},[e]),c=s.some(e=>jt.has(e.name)),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),p=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{let e=p.current;if(!e)return;let t=()=>f(e.scrollHeight>e.clientHeight+2);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[o]),(0,Z.jsxs)(`div`,{className:g(`group/user relative rounded-lg px-3 py-2 text-sm border shadow-sm`,c?`bg-surface/40 border-border/40 text-text-secondary`:`bg-primary/10 border-primary/15 text-text-primary`),children:[s.length>0&&(0,Z.jsx)(Nt,{tags:s}),a.length>0&&(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:a.map((e,n)=>At(e)?(0,Z.jsx)(Bt,{filePath:e,projectName:t},n):(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary`,children:[(0,Z.jsx)(L,{className:`size-3 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate max-w-32`,children:v(e)})]},n))}),o&&(0,Z.jsx)(`div`,{ref:p,className:g(`whitespace-pre-wrap break-words transition-all duration-200`,!l&&`line-clamp-2`,l&&`max-h-[50vh] overflow-y-auto`),children:c?(0,Z.jsx)(Rt,{text:o,projectName:t}):o}),(d||l)&&(0,Z.jsx)(`button`,{onClick:()=>u(!l),className:g(`flex items-center gap-1 text-xs mt-1 transition-colors`,c?`text-text-subtle hover:text-text-secondary`:`text-primary/70 hover:text-primary`),children:l?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(se,{className:`size-3`}),`Show less`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(n,{className:`size-3`}),`Show more`]})}),!c&&r&&(0,Z.jsx)(`button`,{onClick:r,title:`Retry from this message (fork session)`,className:`absolute top-1.5 right-1.5 opacity-0 group-hover/user:opacity-100 transition-opacity size-5 flex items-center justify-center rounded text-text-subtle hover:text-text-primary`,children:(0,Z.jsx)(i,{className:`size-3`})})]})}function Nt({tags:e}){return(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,Z.jsx)(Pt,{tag:e},t))})}function Pt({tag:e}){let[t,n]=(0,Y.useState)(!1);return e.name===`task-notification`?(0,Z.jsx)(It,{content:e.content}):(0,Z.jsxs)(`div`,{className:`text-xs`,children:[(0,Z.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[(0,Z.jsx)(p,{className:`size-2.5`}),(0,Z.jsx)(`span`,{children:e.label}),(0,Z.jsx)(ge,{className:g(`size-2.5 transition-transform`,t&&`rotate-90`)})]}),t&&(0,Z.jsx)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 text-[11px] text-text-subtle/80 whitespace-pre-wrap max-h-40 overflow-y-auto leading-relaxed`,children:e.content})]})}function Ft(e,t){return e.match(RegExp(`<${t}>([\\s\\S]*?)</${t}>`))?.[1]?.trim()||void 0}function It({content:e}){let[t,n]=(0,Y.useState)(!1),r=Ft(e,`status`),i=Ft(e,`summary`),a=Ft(e,`output-file`),o=Ft(e,`result`);return(0,Z.jsxs)(`div`,{className:`text-xs`,children:[(0,Z.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1.5 rounded-full border border-border/60 bg-surface/50 px-2 py-0.5 text-text-subtle hover:text-text-secondary hover:bg-surface transition-colors`,children:[r===`completed`?(0,Z.jsx)(U,{className:`size-2.5 text-green-500`}):(0,Z.jsx)(Se,{className:`size-2.5 text-yellow-500`}),(0,Z.jsx)(`span`,{className:`truncate max-w-80`,children:i??`Task notification`}),(0,Z.jsx)(ge,{className:g(`size-2.5 transition-transform shrink-0`,t&&`rotate-90`)})]}),t&&(0,Z.jsxs)(`div`,{className:`mt-1 rounded border border-border/40 bg-surface/30 px-2 py-1.5 space-y-1.5`,children:[i&&(0,Z.jsx)(`p`,{className:`text-[11px] text-text-secondary`,children:i}),a&&(0,Z.jsx)(Lt,{path:a}),o&&(0,Z.jsx)(`div`,{className:`text-[11px] text-text-subtle/80 max-h-60 overflow-y-auto leading-relaxed`,children:(0,Z.jsx)(Gt,{content:o})})]})]})}function Lt({path:e,projectName:t}){return(0,Z.jsxs)(`button`,{type:`button`,onClick:(0,Y.useCallback)(()=>{let n=f.getState().openTab,r=t??F.getState().activeProject?.name,i=v(e),a={filePath:e};r&&(a.projectName=r),x.get(`/api/fs/read?path=${encodeURIComponent(e)}`).then(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})}).catch(()=>{n({type:`editor`,title:i,metadata:a,projectId:null,closable:!0})})},[e,t]),className:`inline-flex items-center gap-1 rounded border border-border/50 bg-surface/50 px-1.5 py-0.5 font-mono text-[10px] text-text-secondary hover:text-text-primary hover:bg-surface transition-colors cursor-pointer`,children:[(0,Z.jsx)(L,{className:`size-2.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate max-w-60`,children:v(e)}),(0,Z.jsx)(d,{className:`size-2 shrink-0 opacity-50`})]})}function Rt({text:e,projectName:t}){return(0,Z.jsx)(Z.Fragment,{children:(0,Y.useMemo)(()=>{let t=/(\/(?:[\w.\-]+\/)+[\w.\-]+)/g,n=[],r=0,i;for(;(i=t.exec(e))!==null;)i.index>r&&n.push({kind:`text`,value:e.slice(r,i.index)}),n.push({kind:`path`,value:i[1]}),r=i.index+i[0].length;return r<e.length&&n.push({kind:`text`,value:e.slice(r)}),n},[e]).map((e,n)=>e.kind===`path`?(0,Z.jsx)(Lt,{path:e.value,projectName:t},n):(0,Z.jsx)(`span`,{children:e.value},n))})}function zt(e){let[t,n]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{let t=!1,r,a=b();return fetch(e,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{t||(r=URL.createObjectURL(e),n(r))}).catch(()=>{t||i(!0)}),()=>{t=!0,r&&URL.revokeObjectURL(r)}},[e]),{blobUrl:t,error:r}}function Bt({filePath:e,projectName:t}){let{blobUrl:n,error:r}=zt(kt(e,t)),i=ue(e=>e.open),a=v(e);return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>n&&i(n,a),className:`flex items-center gap-1 rounded-md border border-border/60 bg-background/40 px-1.5 py-0.5 text-[11px] text-text-secondary hover:bg-surface transition-colors cursor-pointer`,children:[n?(0,Z.jsx)(`img`,{src:n,alt:a,className:`size-4 rounded-sm object-cover shrink-0`}):r?(0,Z.jsx)(De,{className:`size-3 shrink-0`}):(0,Z.jsx)(`div`,{className:`size-4 rounded-sm bg-surface animate-pulse shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate max-w-32`,children:a})]})}function Vt({events:e,isStreaming:t,projectName:n}){let r=[],i=``,a=``;for(let t=0;t<e.length;t++){let n=e[t];if(n.type===`thinking`){i&&=(r.push({kind:`text`,content:i}),``),a+=n.content;continue}a&&=(r.push({kind:`thinking`,content:a}),``),n.type===`text`?i+=n.content:n.type===`tool_use`?(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n})):n.type===`tool_result`||(i&&=(r.push({kind:`text`,content:i}),``),r.push({kind:`tool`,tool:n}))}a&&r.push({kind:`thinking`,content:a}),i&&r.push({kind:`text`,content:i});let o=e.filter(e=>e.type===`tool_result`);for(let e of o){let t=e.toolUseId;if(t){let n=r.find(e=>e.kind===`tool`&&e.tool.type===`tool_use`&&e.tool.toolUseId===t);if(n){n.result=e;continue}}let n=r.find(e=>e.kind===`tool`&&!e.result);n&&(n.result=e)}for(let e=0;e<r.length;e++){let n=r[e];if(n.kind===`tool`&&!n.result){let i=!1;if(n.tool.type===`tool_use`&&n.tool.tool===`Read`){let t=n.tool.input?.file_path;t&&(i=r.slice(e+1).some(e=>e.kind===`tool`&&e.result&&e.tool.type===`tool_use`&&e.tool.tool===`Edit`&&e.tool.input?.file_path===t))}n.completed=i||!t}}return(0,Z.jsx)(Z.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,Z.jsx)(Ht,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,Z.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,Z.jsx)(Ut,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,Z.jsx)(dt,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function Ht({content:e,isStreaming:t}){let[n,r]=(0,Y.useState)(t);return(0,Y.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,Z.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,Z.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-2 px-2 py-1.5 w-full text-left hover:bg-surface transition-colors text-text-subtle`,children:[t?(0,Z.jsx)(N,{className:`size-3 animate-spin`}):(0,Z.jsx)(ge,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,Z.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,Z.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,Z.jsx)(`div`,{className:`px-2 pb-2 text-text-subtle/80 whitespace-pre-wrap max-h-60 overflow-y-auto text-[11px] leading-relaxed`,children:e})]})}function Ut({content:e,animate:t,projectName:n}){return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Gt,{content:e,projectName:n}),t&&(0,Z.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function Wt({lastMessage:e,phase:t,elapsed:n}){let r=!e||e.role!==`assistant`,i=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!r&&!i?null:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,Z.jsx)(N,{className:`size-3 animate-spin`}),(0,Z.jsxs)(`span`,{children:[t===`initializing`?`Initializing`:t===`connecting`?`Connecting`:t===`thinking`?`Thinking`:`Processing`,r&&(n??0)>0&&(0,Z.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),t===`connecting`&&(n??0)>=30&&(0,Z.jsx)(`p`,{className:`text-xs text-yellow-500/80 ml-5`,children:`Taking longer than usual — may be rate-limited or API slow. Try sending a new message to retry.`})]})}function Gt({content:e,projectName:t}){return(0,Z.jsx)(ye,{content:e,projectName:t,codeActions:!0})}function Kt({approval:e,onRespond:t}){return(0,Z.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,Z.jsx)(Me,{className:`size-4`}),(0,Z.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,Z.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,Z.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,Z.jsx)(`pre`,{className:`text-xs font-mono text-text-secondary overflow-x-auto bg-background rounded p-2 border border-border`,children:JSON.stringify(e.input,null,2)}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!0),className:`px-4 py-1.5 rounded bg-green-600 text-white text-xs font-medium hover:bg-green-500 transition-colors`,children:`Allow`}),(0,Z.jsx)(`button`,{onClick:()=>t(e.requestId,!1),className:`px-4 py-1.5 rounded bg-red-600 text-white text-xs font-medium hover:bg-red-500 transition-colors`,children:`Deny`})]})]})}function qt({approval:e,onRespond:t}){return(0,Z.jsx)(xt,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}function Jt(){let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function Yt(e){let[t,n]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(``),a=(0,Y.useRef)(null),o=(0,Y.useRef)(``),s=typeof window<`u`&&Jt()!==null;return{isListening:t,interimText:r,start:(0,Y.useCallback)(t=>{let r=Jt();if(!r)return;a.current?.abort();let s=new r;s.lang=e?.lang??`vi-VN`,s.continuous=!0,s.interimResults=!0,o.current=``,s.onresult=e=>{let n=``,r=``;for(let t=0;t<e.results.length;t++){let i=e.results[t];i.isFinal?r+=i[0].transcript:n+=i[0].transcript}r&&(o.current=r);let a=(o.current+` `+n).trim();i(n),t(a,n.length===0&&o.current.length>0)},s.onend=()=>{n(!1),i(``),o.current&&t(o.current.trim(),!0)},s.onerror=e=>{e.error!==`no-speech`&&e.error!==`aborted`&&console.warn(`[voice-input] error:`,e.error),n(!1),i(``)},a.current=s,s.start(),n(!0)},[e?.lang]),stop:(0,Y.useCallback)(()=>{a.current?.stop(),a.current=null,n(!1),i(``)},[]),supported:s}}var Xt=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),Zt=new Set([`application/pdf`]),Qt=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],$t=new Set(`.ts,.tsx,.js,.jsx,.mjs,.cjs,.py,.rb,.go,.rs,.java,.kt,.swift,.c,.cpp,.h,.hpp,.cs,.json,.yaml,.yml,.toml,.xml,.md,.mdx,.txt,.csv,.tsv,.html,.css,.scss,.less,.sass,.sh,.bash,.zsh,.fish,.sql,.graphql,.gql,.env,.ini,.cfg,.conf,.dockerfile,.makefile,.vue,.svelte,.astro,.ipynb`.split(`,`));function en(e){return Xt.has(e.type)}function tn(e){if(Xt.has(e.type)||Zt.has(e.type)||Qt.some(t=>e.type.startsWith(t)))return!0;let t=nn(e.name);return!!(t&&$t.has(t))}function nn(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function rn({attachments:e,onRemove:t}){return e.length===0?null:(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-surface px-2 py-1 text-xs text-text-secondary max-w-48`,children:[e.previewUrl?(0,Z.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,Z.jsx)(De,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,Z.jsx)(L,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,Z.jsx)(N,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,Z.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,Z.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`shrink-0 rounded-sm p-0.5 hover:bg-border/50 transition-colors`,"aria-label":`Remove ${e.name}`,children:(0,Z.jsx)(P,{className:`size-3`})})]},e.id))})}var an=[{id:`default`,label:`Ask before edits`,icon:Te,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:we,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:Ce,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:Ne,description:`Claude will not ask before running commands`}];function on(e){return an.find(t=>t.id===e)?.label??`Unknown`}function sn(e){return an.find(t=>t.id===e)?.icon??Te}function cn({value:e,onChange:t,open:n,onOpenChange:i}){let a=(0,Y.useRef)(null),o=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{if(!n)return;let e=e=>{a.current&&!a.current.contains(e.target)&&i(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[n,i]),(0,Y.useEffect)(()=>{n&&(o.current=an.findIndex(t=>t.id===e),o.current<0&&(o.current=0))},[n,e]);let s=(0,Y.useCallback)(e=>{if(e.key===`Escape`){i(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;o.current=(o.current+t+an.length)%an.length,(a.current?.querySelector(`[data-idx="${o.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=an[o.current];n&&(t(n.id),i(!1))}},[t,i]);return n?(0,Z.jsxs)(`div`,{ref:a,role:`listbox`,"aria-label":`Permission modes`,onKeyDown:s,onMouseDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),className:`absolute bottom-full left-0 mb-1 z-50 w-72 md:w-80 rounded-lg border border-border bg-surface shadow-lg`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,Z.jsx)(`kbd`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-surface-elevated text-text-subtle border border-border`,children:`Shift + Tab`})]}),(0,Z.jsx)(`div`,{className:`py-1`,children:an.map((n,a)=>{let o=n.icon,s=n.id===e;return(0,Z.jsxs)(`button`,{"data-idx":a,role:`option`,"aria-selected":s,tabIndex:0,onClick:()=>{t(n.id),i(!1)},className:`w-full flex items-start gap-3 px-3 py-2.5 text-left transition-colors hover:bg-surface-elevated focus:bg-surface-elevated focus:outline-none ${s?`bg-surface-elevated`:``}`,children:[(0,Z.jsx)(o,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,Z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,Z.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),s&&(0,Z.jsx)(r,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}function ln(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function un({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,Y.useState)(0),s=(0,Y.useRef)(null),c=(()=>{if(!t)return e.slice(0,50);let n=t.toLowerCase();return e.filter(e=>e.path.toLowerCase().includes(n)||e.name.toLowerCase().includes(n)).slice(0,50)})();(0,Y.useEffect)(()=>{o(0)},[t]),(0,Y.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,Y.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,Y.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Z.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Z.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Z.jsxs)(`button`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Z.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,Z.jsx)(ne,{className:`size-4 text-amber-500`}):(0,Z.jsx)(re,{className:`size-4 text-blue-400`})}),(0,Z.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}var dn=(0,Y.memo)(function({onSend:e,isStreaming:t,onCancel:n,disabled:r,projectName:i,onSlashStateChange:a,onSlashItemsLoaded:o,slashSelected:s,onFileStateChange:c,onFileItemsLoaded:l,fileSelected:u,externalFiles:d,initialValue:f,autoFocus:p,permissionMode:m,onModeChange:h}){let[g,v]=(0,Y.useState)(f??``),[S,C]=(0,Y.useState)([]),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(!1),O=(0,Y.useRef)(null),k=(0,Y.useRef)(null),A=(0,Y.useRef)(null),j=(0,Y.useRef)([]),M=(0,Y.useRef)([]),P=Yt(),F=(0,Y.useRef)(``),I=(0,Y.useCallback)(e=>{let t=F.current;v(t?t+` `+e:e),requestAnimationFrame(()=>{let e=window.matchMedia(`(min-width: 768px)`).matches?O.current:k.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,160)+`px`)})},[]),L=(0,Y.useCallback)(()=>{P.isListening?P.stop():(F.current=g.trim(),P.start(I))},[P.isListening,P.start,P.stop,g,I]);(0,Y.useEffect)(()=>{let e=()=>{P.supported&&L()};return window.addEventListener(`toggle-voice-input`,e),()=>window.removeEventListener(`toggle-voice-input`,e)},[P.supported,L]),(0,Y.useEffect)(()=>{f&&(v(f),setTimeout(()=>{let e=O.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[f]),(0,Y.useEffect)(()=>{p&&setTimeout(()=>{(window.matchMedia(`(min-width: 768px)`).matches?O.current:k.current)?.focus()},100)},[]),(0,Y.useEffect)(()=>{if(!i){j.current=[],o?.([]);return}x.get(`${y(i)}/chat/slash-items`).then(e=>{j.current=e,o?.(e)}).catch(()=>{j.current=[],o?.([])})},[i]),(0,Y.useEffect)(()=>{if(!i){M.current=[],l?.([]);return}x.get(`${y(i)}/files/tree?depth=5`).then(e=>{let t=ln(e);M.current=t,l?.(t)}).catch(()=>{M.current=[],l?.([])})},[i]),(0,Y.useEffect)(()=>{if(!s)return;let e=O.current,t=e?.selectionStart??g.length,n=g.slice(0,t),r=g.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);v(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,Y.useEffect)(()=>{if(!u)return;let e=O.current;if(!e)return;let t=e.selectionStart,n=g.slice(0,t),r=g.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;v(n.slice(0,t)+`@${u.path} `+r);let a=t+u.path.length+2;setTimeout(()=>{e.selectionStart=e.selectionEnd=a,e.focus()},0)}else{let t=g+`@${u.path} `;v(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,Y.useEffect)(()=>{!d||d.length===0||B(d)},[d]);let R=(0,Y.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=b();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${y(i)}/chat/upload`,{method:`POST`,headers:n,body:t})).json();return a.ok&&Array.isArray(a.data)&&a.data.length>0?a.data[0].path:null}catch{return null}},[i]),B=(0,Y.useCallback)(e=>{for(let t of e){if(!tn(t)){v(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=_(),n=en(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};C(e=>[...e,i]),R(t).then(t=>{C(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(k.current??O.current)?.focus()},[R]),ee=(0,Y.useCallback)(e=>{C(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),V=(0,Y.useCallback)(()=>{let t=g.trim(),n=S.filter(e=>e.status===`ready`);if(!t&&n.length===0){D(!1);return}a?.(!1,``),c?.(!1,``),P.isListening&&P.stop(),e(t,n),v(``);for(let e of S)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);C([]),D(!1),O.current&&(O.current.style.height=`auto`),k.current&&(k.current.style.height=`auto`)},[g,S,e,a,c]),H=(0,Y.useCallback)(()=>{if(!r){if(S.some(e=>e.status===`uploading`)){(g.trim()||S.some(e=>e.status!==`error`))&&D(!0);return}V()}},[g,S,r,V]);(0,Y.useEffect)(()=>{E&&(S.some(e=>e.status===`uploading`)||V())},[E,S,V]);let U=(0,Y.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),H();return}if(e.shiftKey&&e.key===`Tab`){e.preventDefault();let t=[`default`,`acceptEdits`,`plan`,`bypassPermissions`],n=t[(t.indexOf(m??`bypassPermissions`)+1)%t.length];h?.(n)}},[H,m,h]),te=(0,Y.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&j.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&M.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),ne=(0,Y.useCallback)((e,t)=>{v(e),te(e,t)},[te]),W=(0,Y.useCallback)(e=>{let t=e?.target??O.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),re=(0,Y.useCallback)(e=>{let t=e.clipboardData?.items;if(!t)return;let n=[];for(let e of t)if(e.kind===`file`){let t=e.getAsFile();t&&n.push(t)}n.length>0&&(e.preventDefault(),B(n))},[B]),ie=(0,Y.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&B(t)},[B]),ae=(0,Y.useCallback)(e=>{e.preventDefault()},[]),G=(0,Y.useCallback)(()=>{A.current?.click()},[]),oe=(0,Y.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&B(t),e.target.value=``},[B]),K=g.trim().length>0||S.some(e=>e.status!==`error`),se=t&&!K;return(0,Z.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,Z.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:e=>{r||e.target instanceof HTMLTextAreaElement||(window.matchMedia(`(min-width: 768px)`).matches?O.current:k.current)?.focus()},children:[(0,Z.jsx)(rn,{attachments:S,onRemove:ee}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,Z.jsx)(fn,{mode:m??`bypassPermissions`,onClick:()=>T(e=>!e)}),(0,Z.jsx)(cn,{value:m??`bypassPermissions`,onChange:e=>h?.(e),open:w,onOpenChange:T})]}),(0,Z.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),G()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full text-text-subtle hover:text-text-primary transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Z.jsx)(Ae,{className:`size-4`})}),P.supported&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-7 shrink-0 rounded-full transition-colors disabled:opacity-50 ${P.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary`}`,"aria-label":P.isListening?`Stop voice input`:`Start voice input`,children:P.isListening?(0,Z.jsx)(ke,{className:`size-4`}):(0,Z.jsx)(z,{className:`size-4`})}),(0,Z.jsx)(`textarea`,{ref:k,value:g,onChange:e=>{ne(e.target.value,e.target.selectionStart),W(e)},onKeyDown:U,onPaste:re,onDrop:ie,onDragOver:ae,placeholder:t?`Follow-up...`:`Ask anything...`,disabled:r,rows:1,className:`flex-1 resize-none bg-transparent py-1.5 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-20`}),se?(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop`,children:(0,Z.jsx)(Fe,{className:`size-3`})}):(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),E?D(!1):H()},disabled:r||!K,className:`flex items-center justify-center size-7 shrink-0 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 transition-colors`,"aria-label":E?`Cancel queued send`:`Send`,children:E?(0,Z.jsx)(N,{className:`size-3.5 animate-spin`}):(0,Z.jsx)(xe,{className:`size-3.5`})})]}),(0,Z.jsxs)(`div`,{className:`hidden md:block`,children:[(0,Z.jsx)(`textarea`,{ref:O,value:g,onChange:e=>{ne(e.target.value,e.target.selectionStart),W(e)},onKeyDown:U,onPaste:re,onDrop:ie,onDragOver:ae,placeholder:t?`Follow-up or Stop...`:`Ask anything...`,disabled:r,rows:1,className:`w-full resize-none bg-transparent px-4 pt-3 pb-1 text-sm text-foreground placeholder:text-text-subtle focus:outline-none disabled:opacity-50 max-h-40`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),G()},disabled:r,className:`flex items-center justify-center size-8 rounded-full text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors disabled:opacity-50`,"aria-label":`Attach file`,children:(0,Z.jsx)(Ae,{className:`size-4`})}),P.supported&&(0,Z.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),L()},disabled:r,className:`flex items-center justify-center size-8 rounded-full transition-colors disabled:opacity-50 ${P.isListening?`bg-red-600 text-white animate-pulse`:`text-text-subtle hover:text-text-primary hover:bg-surface-elevated`}`,"aria-label":P.isListening?`Stop voice input`:`Start voice input`,children:P.isListening?(0,Z.jsx)(ke,{className:`size-4`}):(0,Z.jsx)(z,{className:`size-4`})}),(0,Z.jsxs)(`div`,{className:`relative`,children:[(0,Z.jsx)(fn,{mode:m??`bypassPermissions`,onClick:()=>T(e=>!e)}),(0,Z.jsx)(cn,{value:m??`bypassPermissions`,onChange:e=>h?.(e),open:w,onOpenChange:T})]})]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:se?(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),n?.()},className:`flex items-center justify-center size-8 rounded-full bg-red-600 text-white hover:bg-red-500 transition-colors`,"aria-label":`Stop response`,children:(0,Z.jsx)(Fe,{className:`size-3.5`})}):(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),E?D(!1):H()},disabled:r||!K,className:`flex items-center justify-center size-8 rounded-full bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-30 disabled:cursor-not-allowed transition-colors`,"aria-label":E?`Cancel queued send`:`Send message`,children:E?(0,Z.jsx)(N,{className:`size-4 animate-spin`}):(0,Z.jsx)(xe,{className:`size-4`})})})]})]})]}),(0,Z.jsx)(`input`,{ref:A,type:`file`,multiple:!0,className:`hidden`,onChange:oe})]})});function fn({mode:e,onClick:t}){let n=sn(e),r=on(e);return(0,Z.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t()},className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[11px] text-text-subtle hover:text-text-primary hover:bg-surface-elevated transition-colors border border-transparent hover:border-border`,"aria-label":`Permission mode: ${r}`,children:[(0,Z.jsx)(n,{className:`size-3`}),(0,Z.jsx)(`span`,{className:`max-w-[100px] truncate`,children:r})]})}function pn({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,Y.useState)(0),s=(0,Y.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,Y.useEffect)(()=>{o(0)},[t]),(0,Y.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,Y.useCallback)(e=>{if(!i||c.length===0)return!1;switch(e.key){case`ArrowUp`:return e.preventDefault(),o(e=>e>0?e-1:c.length-1),!0;case`ArrowDown`:return e.preventDefault(),o(e=>e<c.length-1?e+1:0),!0;case`Enter`:case`Tab`:return e.preventDefault(),c[a]&&n(c[a]),!0;case`Escape`:return e.preventDefault(),r(),!0}return!1},[i,c,a,n,r]);return(0,Y.useEffect)(()=>{if(!i)return;let e=e=>{l(e)&&e.stopPropagation()};return document.addEventListener(`keydown`,e,!0),()=>document.removeEventListener(`keydown`,e,!0)},[i,l]),!i||c.length===0?null:(0,Z.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,Z.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,Z.jsxs)(`button`,{className:`flex items-start gap-3 w-full px-3 py-2 text-left transition-colors ${t===a?`bg-primary/10 text-primary`:`hover:bg-surface-hover text-text-primary`}`,onMouseEnter:()=>o(t),onClick:()=>n(e),children:[(0,Z.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,Z.jsx)(Pe,{className:`size-4 text-amber-500`}):(0,Z.jsx)(M,{className:`size-4 text-blue-500`})}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Z.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,Z.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,Z.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}var mn=`ppm-hienlh`;function hn({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(``),[_,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(`idle`);function x(){m(null),g(``),b(`idle`),f(null)}function S(){t(!1),x(),i(``),c(``),f(null)}async function w(){v(!0),f(null);try{let{url:e,state:t}=await C();m(t),b(`waiting`),window.open(e,`_blank`)}catch(e){f(e.message)}v(!1)}async function T(){if(!(!h.trim()||!p)){v(!0),f(null);try{let e=h.trim();e.includes(`#`)&&(e=e.split(`#`)[0]??e),await D(e,p),S(),n(`Account connected via OAuth!`)}catch(e){f(e.message)}v(!1)}}async function E(){if(r.trim()){u(!0),f(null);try{await k({apiKey:r.trim(),label:s.trim()||void 0}),S(),n(`Account added!`)}catch(e){f(e.message)}u(!1)}}let O=r.trim()?r.trim().startsWith(`sk-ant-oat`)?`OAuth token (Claude Max/Pro)`:r.trim().startsWith(`sk-ant-api`)?`API key`:`Unknown format`:``;return(0,Z.jsx)(oe,{open:e,onOpenChange:e=>{e||S()},children:(0,Z.jsxs)(le,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(q,{children:[(0,Z.jsx)(J,{className:`text-sm`,children:`Add Claude Account`}),(0,Z.jsx)(_e,{className:`text-xs leading-relaxed`,children:`Connect via OAuth (recommended) or paste a token manually.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] font-medium`,children:`Recommended: Login with Claude`}),y===`idle`?(0,Z.jsx)(a,{size:`sm`,className:`w-full h-8 text-xs`,onClick:w,disabled:_,children:_?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(N,{className:`size-3 animate-spin mr-1`}),` Opening...`]}):`Login with Claude`}):(0,Z.jsxs)(`div`,{className:`space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Authorize in the opened tab, then paste the code:`}),(0,Z.jsx)(o,{placeholder:`Paste code here...`,value:h,onChange:e=>g(e.target.value),className:`text-xs h-8 font-mono`,autoFocus:!0}),(0,Z.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Z.jsx)(a,{size:`sm`,className:`flex-1 h-7 text-xs`,onClick:T,disabled:!h.trim()||_,children:_?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(N,{className:`size-3 animate-spin mr-1`}),` Connecting...`]}):`Connect`}),(0,Z.jsx)(a,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:x,children:`Cancel`})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 border-t`}),(0,Z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`or paste token`}),(0,Z.jsx)(`div`,{className:`flex-1 border-t`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(he,{htmlFor:`add-token`,className:`text-xs`,children:`Token`}),(0,Z.jsx)(o,{id:`add-token`,type:`password`,placeholder:`sk-ant-...`,value:r,onChange:e=>i(e.target.value),className:`text-xs h-8 font-mono`}),O&&(0,Z.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Detected: `,O]})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(he,{htmlFor:`add-label`,className:`text-xs`,children:`Label (optional)`}),(0,Z.jsx)(o,{id:`add-label`,placeholder:`e.g. Personal, Work`,value:s,onChange:e=>c(e.target.value),className:`text-xs h-8`})]})]}),d&&(0,Z.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:d}),(0,Z.jsxs)(K,{children:[(0,Z.jsx)(a,{size:`sm`,variant:`outline`,className:`text-xs h-7`,onClick:S,children:`Cancel`}),(0,Z.jsx)(a,{size:`sm`,className:`text-xs h-7`,onClick:E,disabled:!r.trim()||l,children:l?`Adding...`:`Add Token`})]})]})})}function gn({open:e,onOpenChange:t,accounts:n,preselectId:r,onMessage:i}){let s=n.filter(e=>e.hasRefreshToken),[c,l]=(0,Y.useState)(new Set),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(!1),[v,y]=(0,Y.useState)(!1);e&&!v&&(l(r?new Set([r]):new Set(s.map(e=>e.id))),y(!0)),!e&&v&&y(!1);function x(){t(!1),d(``),p(!1),h(!1)}async function S(e){if(c.size===0)return;_(!0);let t=u.trim()||mn;try{let n={"Content-Type":`application/json`},r=b();r&&(n.Authorization=`Bearer ${r}`);let a=await fetch(`/api/accounts/export`,{method:`POST`,headers:n,body:JSON.stringify({password:t,accountIds:[...c],includeRefreshToken:f,refreshBeforeExport:m})});if(!a.ok){let e=await a.json();throw Error(e.error??`Export failed: ${a.status}`)}let o=await a.text();if(e)try{await navigator.clipboard.writeText(o),i?.(`Backup copied to clipboard!`)}catch{vn(o),i?.(`Backup downloaded.`)}else vn(o),i?.(`Backup downloaded.`);x()}catch{}_(!1)}let C=c.size>0&&!g;return(0,Z.jsx)(oe,{open:e,onOpenChange:e=>{e||x()},children:(0,Z.jsxs)(le,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(J,{className:`text-sm flex items-center gap-1.5`,children:[(0,Z.jsx)(ve,{className:`size-3.5`}),` Export Accounts`]}),(0,Z.jsx)(_e,{className:`text-xs`,children:`Select accounts and set a password to protect the backup.`})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,Z.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:`Accounts to export`}),(0,Z.jsx)(`button`,{className:`text-[10px] text-primary hover:underline cursor-pointer`,onClick:()=>l(c.size===s.length?new Set:new Set(s.map(e=>e.id))),children:c.size===s.length?`Deselect all`:`Select all`})]}),s.length===0?(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground p-2 border rounded`,children:`No exportable accounts.`}):(0,Z.jsx)(`div`,{className:`max-h-36 overflow-y-auto space-y-1 border rounded p-2`,children:s.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`exp-${e.id}`,checked:c.has(e.id),onChange:t=>{let n=new Set(c);t.target.checked?n.add(e.id):n.delete(e.id),l(n)},className:`size-3.5 accent-primary cursor-pointer`}),(0,Z.jsx)(`label`,{htmlFor:`exp-${e.id}`,className:`text-xs cursor-pointer truncate`,children:e.label??e.email??e.id.slice(0,8)})]},e.id))})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(he,{className:`text-xs`,children:[`Password `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,Z.jsx)(o,{type:`password`,placeholder:`Leave empty for default`,value:u,onChange:e=>d(e.target.value),className:`text-xs h-8`,autoComplete:`new-password`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`exp-full`,checked:f,onChange:e=>p(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,Z.jsx)(`label`,{htmlFor:`exp-full`,className:`text-[11px] cursor-pointer`,children:`Include refresh tokens (full transfer)`})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,id:`exp-refresh`,checked:m,onChange:e=>h(e.target.checked),className:`size-3.5 accent-primary cursor-pointer`}),(0,Z.jsx)(`label`,{htmlFor:`exp-refresh`,className:`text-[11px] cursor-pointer`,children:`Refresh tokens before export`})]}),f?(0,Z.jsxs)(`div`,{className:`rounded-md border border-red-500/30 bg-red-500/5 p-2.5`,children:[(0,Z.jsx)(`p`,{className:`text-[10px] font-medium text-red-600`,children:`Full transfer — source accounts will expire`}),(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Refresh tokens included. Source machine expires in ~1h after target refreshes.`})]}):m?(0,Z.jsx)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-2.5`,children:(0,Z.jsx)(`p`,{className:`text-[10px] font-medium text-amber-600`,children:`Refresh before export — invalidates previous shares`})}):(0,Z.jsx)(`div`,{className:`rounded-md border border-green-500/30 bg-green-500/5 p-2.5`,children:(0,Z.jsx)(`p`,{className:`text-[10px] font-medium text-green-600`,children:`Share current token (safe)`})}),(0,Z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Encrypted with AES-256-GCM + scrypt.`})]}),(0,Z.jsxs)(K,{className:`gap-1.5 flex-col sm:flex-row`,children:[(0,Z.jsx)(a,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:x,children:`Cancel`}),(0,Z.jsxs)(a,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,disabled:!C,onClick:()=>S(!0),children:[(0,Z.jsx)(ie,{className:`size-3 mr-1`}),` Copy`]}),(0,Z.jsx)(a,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!C,onClick:()=>S(!1),children:g?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(N,{className:`size-3 animate-spin mr-1`}),` Exporting...`]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(R,{className:`size-3 mr-1`}),` Download`]})})]})]})})}function _n({open:e,onOpenChange:t,onSuccess:n}){let[r,i]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null);function p(){t(!1),i(``),c(``),f(null)}async function m(){if(r.trim()){u(!0),f(null);try{let e=await A({data:r.trim(),password:s.trim()||mn});p(),n(`Imported ${e.imported} account(s)`)}catch(e){f(e.message||`Import failed`)}u(!1)}}return(0,Z.jsx)(oe,{open:e,onOpenChange:e=>{e||p()},children:(0,Z.jsxs)(le,{className:`sm:max-w-md`,children:[(0,Z.jsxs)(q,{children:[(0,Z.jsxs)(J,{className:`text-sm flex items-center gap-1.5`,children:[(0,Z.jsx)(ve,{className:`size-3.5`}),` Import Accounts`]}),(0,Z.jsx)(_e,{className:`text-xs`,children:`Paste backup data and enter the export password. Imported accounts are temporary (~1h).`})]}),(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)(he,{className:`text-xs`,children:`Backup data`}),(0,Z.jsx)(`textarea`,{value:r,onChange:e=>i(e.target.value),placeholder:`Paste backup JSON here...`,rows:4,className:`w-full text-xs p-2 rounded border border-border bg-background font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary`})]}),(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsxs)(he,{className:`text-xs`,children:[`Password `,(0,Z.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(optional)`})]}),(0,Z.jsx)(o,{type:`password`,placeholder:`Leave empty for default`,value:s,onChange:e=>c(e.target.value),className:`text-xs h-8`,autoComplete:`current-password`})]})]}),d&&(0,Z.jsx)(`div`,{className:`text-[11px] p-2 rounded bg-red-500/10 text-red-600`,children:d}),(0,Z.jsxs)(K,{children:[(0,Z.jsx)(a,{size:`sm`,variant:`outline`,className:`text-xs h-7 cursor-pointer`,onClick:p,children:`Cancel`}),(0,Z.jsx)(a,{size:`sm`,className:`text-xs h-7 cursor-pointer`,disabled:!r.trim()||l,onClick:m,children:l?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(N,{className:`size-3 animate-spin mr-1`}),` Importing...`]}):`Import`})]})]})})}function vn(e){let t=new Blob([e],{type:`application/json`}),n=document.createElement(`a`);n.href=URL.createObjectURL(t),n.download=`ppm-accounts-backup.json`,n.click(),URL.revokeObjectURL(n.href)}function yn(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function bn(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function xn(e){if(!e)return null;let t=null;if(e.resetsInMinutes!=null)t=e.resetsInMinutes;else if(e.resetsInHours!=null)t=Math.round(e.resetsInHours*60);else if(e.resetsAt){let n=new Date(e.resetsAt).getTime()-Date.now();t=n>0?Math.ceil(n/6e4):0}if(t==null)return null;if(t<=0)return`now`;let n=Math.floor(t/1440),r=Math.floor(t%1440/60),i=t%60;return n>0?i>0?`${n}d ${r}h ${i}m`:r>0?`${n}d ${r}h`:`${n}d`:r>0?i>0?`${r}h ${i}m`:`${r}h`:`${i}m`}function $({label:e,bucket:t}){if(!t)return null;let n=Math.round(t.utilization*100),r=xn(t);return(0,Z.jsxs)(`div`,{className:`space-y-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,Z.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,title:`Resets in`,children:[`↻ `,r]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,Z.jsx)(`div`,{className:`h-full rounded-full transition-all ${bn(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,Z.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${yn(n)}`,children:[n,`%`]})]})]})}function Sn(e){let t=e-Date.now();if(t<=0)return`expired`;let n=Math.ceil(t/6e4),r=Math.floor(n/60),i=Math.floor(r/24);return i>0?`${i}d ${r%24}h`:r>0?`${r}h ${n%60}m`:`${n}m`}function Cn(e){if(!e)return{label:`unknown`,tip:`No account info available`,color:`text-text-subtle`};if(!e.expiresAt)return{label:`key`,tip:`API key (no expiry)`,color:`text-text-subtle`};let t=e.expiresAt*1e3<Date.now();return t&&e.hasRefreshToken?{label:`expired`,tip:`Token expired but has refresh token — will auto-renew`,color:`text-amber-500`}:t?{label:`expired`,tip:`Token expired, no refresh token`,color:`text-red-500`}:e.hasRefreshToken?{label:`long-lived`,tip:`OAuth token with refresh — long-lived`,color:`text-green-500`}:{label:`temp`,tip:`Temporary token without refresh — will expire`,color:`text-amber-500`}}function wn(e){if(!e)return null;let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60),i=n%60;return r<24?i>0?`${r}h ${i}m ago`:`${r}h ago`:`${Math.floor(r/24)}d ago`}function Tn({entry:e,isActive:t,accountInfo:n,onToggle:r,onExport:i,onViewProfile:a,flash:o}){let{usage:s}=e,c=s.session||s.weekly||s.weeklyOpus||s.weeklySonnet,l=n?.status??e.accountStatus;return(0,Z.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5 transition-colors duration-500 min-w-[200px] shrink-0 snap-start ${o?`bg-primary/10 border-primary/40`:``} ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),!e.isOAuth&&(0,Z.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[a&&n?.profileData&&(0,Z.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>a(n.profileData),title:`View profile`,children:(0,Z.jsx)(fe,{className:`size-3`})}),i&&e.isOAuth&&(0,Z.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-blue-500 hover:bg-surface-elevated transition-colors`,onClick:()=>i(e.accountId),title:`Export this account`,children:(0,Z.jsx)(R,{className:`size-3`})}),r&&(0,Z.jsx)(ae,{checked:l!==`disabled`,onCheckedChange:()=>r(e.accountId,l),disabled:l===`cooldown`,className:`scale-[0.6] cursor-pointer`})]})]}),c?(0,Z.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Z.jsx)($,{label:`5-Hour Session`,bucket:s.session}),(0,Z.jsx)($,{label:`Weekly`,bucket:s.weekly}),(0,Z.jsx)($,{label:`Weekly (Opus)`,bucket:s.weeklyOpus}),(0,Z.jsx)($,{label:`Weekly (Sonnet)`,bucket:s.weeklySonnet})]}):(0,Z.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),(()=>{let e=Cn(n);return(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[9px] text-text-subtle flex-wrap`,children:[s.lastFetchedAt&&(0,Z.jsxs)(`span`,{title:`Last usage data update`,children:[`↻ `,wn(new Date(s.lastFetchedAt).getTime())]}),n?.expiresAt&&n.expiresAt*1e3>Date.now()&&(0,Z.jsxs)(`span`,{title:`Token expires in`,children:[`⏱ `,Sn(n.expiresAt*1e3)]}),(0,Z.jsxs)(`span`,{className:e.color,title:e.tip,children:[`© `,e.label]})]})})()]})}function En({usage:e,visible:t,onClose:n,onReload:r,loading:i,lastFetchedAt:a}){let[o,s]=(0,Y.useState)([]),[c,l]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(!0),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(new Set),[v,y]=(0,Y.useState)(null),[b,x]=(0,Y.useState)(!1),[C,T]=(0,Y.useState)(!1),[D,k]=(0,Y.useState)(!1),[A,j]=(0,Y.useState)(null),[M,N]=(0,Y.useState)(null),F=(0,Y.useRef)(void 0),I=(0,Y.useRef)([]);function L(e){F.current&&clearTimeout(F.current),N(e),F.current=setTimeout(()=>N(null),4e3)}function z(e){B(),e&&L(e)}async function B(){let e=o.length>0;e?h(!0):p(!0);let[t,n,r]=await Promise.allSettled([O(),S(),E()]);if(t.status===`fulfilled`){let n=t.value;if(e&&I.current.length>0){let e=new Set,t=new Map(I.current.map(e=>[e.accountId,e]));for(let r of n){let n=t.get(r.accountId);if(!n){e.add(r.accountId);continue}let i=n.usage,a=r.usage;(i.session?.utilization!==a.session?.utilization||i.weekly?.utilization!==a.weekly?.utilization||i.weeklyOpus?.utilization!==a.weeklyOpus?.utilization||i.weeklySonnet?.utilization!==a.weeklySonnet?.utilization)&&e.add(r.accountId)}e.size>0&&(_(e),setTimeout(()=>_(new Set),1500))}I.current=n,s(n)}n.status===`fulfilled`&&l(n.value),r.status===`fulfilled`&&d(r.value?.id??null),p(!1),h(!1)}if((0,Y.useEffect)(()=>{t&&B()},[t]),(0,Y.useEffect)(()=>{!t||!a||B()},[a]),!t)return null;let U=new Map(c.map(e=>[e.id,e])),te=e.queryCostUsd!=null||e.totalCostUsd!=null,ne=o.length>0;async function W(e,t){await w(e,{status:t===`disabled`?`active`:`disabled`}),B(),r?.()}function re(){j(null),T(!0)}return(0,Z.jsxs)(`div`,{className:`border-b border-border bg-surface px-3 py-2.5 space-y-2.5 max-h-[350px] overflow-y-auto`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage & Accounts`}),a&&(0,Z.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:wn(new Date(a).getTime())})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Z.jsx)(`button`,{onClick:()=>{r(),B()},disabled:i||m,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,children:(0,Z.jsx)(ee,{className:`size-3 ${i||m?`animate-spin`:``}`})}),(0,Z.jsx)(`button`,{onClick:n,className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:(0,Z.jsx)(P,{className:`size-3`})})]})]}),M&&(0,Z.jsx)(`div`,{className:`text-[11px] p-1.5 rounded bg-green-500/10 text-green-600 text-center animate-in fade-in duration-200`,children:M}),ne||f?(0,Z.jsx)(`div`,{className:`flex gap-1.5 overflow-x-auto pb-1 -mx-3 px-3 snap-x snap-mandatory scrollbar-thin`,children:f?(0,Z.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):o.map(t=>(0,Z.jsx)(Tn,{entry:t,isActive:t.accountId===(u??e.activeAccountId),accountInfo:U.get(t.accountId),onToggle:W,onExport:e=>{j(e),T(!0)},onViewProfile:y,flash:g.has(t.accountId)},t.accountId))}):(0,Z.jsx)(Z.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,Z.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Z.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,Z.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,Z.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,Z.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,Z.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),te&&(0,Z.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,Z.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,Z.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]}),v&&(0,Z.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Profile`}),(0,Z.jsx)(`button`,{className:`text-text-subtle hover:text-foreground cursor-pointer`,onClick:()=>y(null),children:(0,Z.jsx)(P,{className:`size-3`})})]}),(0,Z.jsxs)(`div`,{className:`grid grid-cols-[70px_1fr] gap-x-2 gap-y-0.5 text-[10px]`,children:[v.account?.display_name&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Name`}),(0,Z.jsx)(`span`,{children:v.account.display_name})]}),v.account?.email&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Email`}),(0,Z.jsx)(`span`,{children:v.account.email})]}),v.organization?.name&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Org`}),(0,Z.jsx)(`span`,{children:v.organization.name})]}),v.organization?.organization_type&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Type`}),(0,Z.jsx)(`span`,{children:v.organization.organization_type})]}),v.organization?.rate_limit_tier&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Tier`}),(0,Z.jsx)(`span`,{children:v.organization.rate_limit_tier})]}),v.organization?.subscription_status&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`Status`}),(0,Z.jsx)(`span`,{children:v.organization.subscription_status})]})]})]}),(0,Z.jsxs)(`div`,{className:`border-t border-border pt-2 flex gap-1.5`,children:[(0,Z.jsxs)(`button`,{onClick:()=>x(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,Z.jsx)(H,{className:`size-3`}),` Add`]}),(0,Z.jsxs)(`button`,{onClick:re,className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,Z.jsx)(R,{className:`size-3`}),` Export`]}),(0,Z.jsxs)(`button`,{onClick:()=>k(!0),className:`flex-1 flex items-center justify-center gap-1 rounded-md border border-border px-2 py-1 text-[11px] text-text-secondary hover:bg-surface-hover transition-colors cursor-pointer`,children:[(0,Z.jsx)(V,{className:`size-3`}),` Import`]})]}),(0,Z.jsx)(hn,{open:b,onOpenChange:x,onSuccess:z}),(0,Z.jsx)(gn,{open:C,onOpenChange:e=>{T(e),e||j(null)},accounts:c,preselectId:A,onMessage:L}),(0,Z.jsx)(_n,{open:D,onOpenChange:k,onSuccess:z})]})}function Dn(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function On(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function kn({projectName:e,usageInfo:t,contextWindowPct:n,usageLoading:i,refreshUsage:a,lastFetchedAt:o,sessionId:s,onSelectSession:c,onBugReport:l,isConnected:u,onReconnect:d}){let[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)([]),[_,v]=(0,Y.useState)(!1),b=G(e=>s?e.notifications.has(s):!1),S=G(e=>e.clearForSession),[C,w]=(0,Y.useState)(``),[T,E]=(0,Y.useState)(null),[D,O]=(0,Y.useState)(``),k=(0,Y.useRef)(null),A=f(e=>e.openTab),j=e=>{m(t=>t===e?null:e)},M=(0,Y.useCallback)(async()=>{if(e){v(!0);try{g(await x.get(`${y(e)}/chat/sessions`))}catch{}finally{v(!1)}}},[e]);(0,Y.useEffect)(()=>{p===`history`&&h.length===0&&M()},[p]);function F(t){c?(c(t),m(null)):A({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let L=(0,Y.useCallback)((e,t)=>{t.stopPropagation(),E(e.id),O(e.title||``),setTimeout(()=>k.current?.select(),0)},[]),R=(0,Y.useCallback)(async()=>{if(!T||!D.trim()||!e){E(null);return}try{await x.patch(`${y(e)}/chat/sessions/${T}`,{title:D.trim()}),g(e=>e.map(e=>e.id===T?{...e,title:D.trim()}:e))}catch{}E(null)},[T,D,e]),z=(0,Y.useCallback)(()=>E(null),[]),V=C.trim()?h.filter(e=>(e.title||``).toLowerCase().includes(C.toLowerCase())):h,H=t.fiveHour==null?null:Math.round(t.fiveHour*100),U=t.sevenDay==null?null:Math.round(t.sevenDay*100),ne=H!=null||U!=null?On(Math.max(H??0,U??0)):`text-text-subtle`;return(0,Z.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,Z.jsxs)(`button`,{onClick:()=>j(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${p===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,Z.jsx)(Ee,{className:`size-3`}),(0,Z.jsx)(`span`,{children:`History`})]}),(0,Z.jsx)(`button`,{onClick:()=>j(`config`),className:`p-1 rounded transition-colors ${p===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,Z.jsx)(je,{className:`size-3`})}),(0,Z.jsxs)(`button`,{onClick:()=>j(`usage`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] font-medium tabular-nums transition-colors hover:bg-surface-elevated ${p===`usage`?`bg-primary/10`:``} ${ne}`,title:`Usage limits`,children:[(0,Z.jsx)(be,{className:`size-3`}),t.activeAccountLabel&&(0,Z.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[60px]`,children:[`[`,t.activeAccountLabel,`]`]}),(0,Z.jsxs)(`span`,{children:[`5h:`,H==null?`--%`:`${H}%`]}),(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Z.jsxs)(`span`,{children:[`Wk:`,U==null?`--%`:`${U}%`]}),n!=null&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,Z.jsxs)(`span`,{className:On(n),children:[`Ctx:`,n,`%`]})]})]}),(0,Z.jsx)(`div`,{className:`flex-1`}),b&&s&&(0,Z.jsx)(`button`,{onClick:()=>S(s),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,Z.jsx)(ce,{className:`size-3`})}),d&&(0,Z.jsx)(`button`,{onClick:d,className:`size-4 flex items-center justify-center`,title:u?`Connected`:`Disconnected — click to reconnect`,children:(0,Z.jsx)(`span`,{className:`size-2 rounded-full ${u?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),p===`history`&&(0,Z.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,Z.jsx)(B,{className:`size-3 text-text-subtle shrink-0`}),(0,Z.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,Z.jsx)(`button`,{onClick:M,disabled:_,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,Z.jsx)(ee,{className:`size-3 ${_?`animate-spin`:``}`})})]}),(0,Z.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:_&&h.length===0?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,Z.jsx)(N,{className:`size-3.5 animate-spin text-text-subtle`})}):V.length===0?(0,Z.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:C?`No matching sessions`:`No sessions yet`}):V.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 w-full px-3 py-1.5 text-left hover:bg-surface-elevated transition-colors group`,children:[(0,Z.jsx)(te,{className:`size-3 shrink-0 text-text-subtle`}),T===e.id?(0,Z.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),R()},children:[(0,Z.jsx)(`input`,{ref:k,value:D,onChange:e=>O(e.target.value),onBlur:R,onKeyDown:e=>{e.key===`Escape`&&z()},className:`flex-1 min-w-0 bg-surface-elevated text-[11px] text-text-primary px-1 py-0.5 rounded border border-border outline-none focus:border-primary`,autoFocus:!0}),(0,Z.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,Z.jsx)(r,{className:`size-3`})}),(0,Z.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),z()},children:(0,Z.jsx)(P,{className:`size-3`})})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{onClick:()=>F(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,Z.jsx)(`button`,{onClick:t=>L(e,t),className:`p-0.5 rounded text-text-subtle hover:text-text-secondary opacity-0 group-hover:opacity-100 transition-opacity`,title:`Rename session`,children:(0,Z.jsx)(I,{className:`size-3`})})]}),T!==e.id&&e.updatedAt&&(0,Z.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Dn(e.updatedAt)})]},e.id))})]}),p===`config`&&(0,Z.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,Z.jsx)(de,{compact:!0})}),p===`usage`&&(0,Z.jsx)(En,{usage:t,visible:!0,onClose:()=>m(null),onReload:a,loading:i,lastFetchedAt:o})]})}function An({metadata:e,tabId:t}){let[n,r]=(0,Y.useState)(e?.sessionId??null),[i,a]=(0,Y.useState)(e?.providerId??`claude`),[o,s]=(0,Y.useState)([]),[c,l]=(0,Y.useState)(!1),[d,p]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(null),[v,b]=(0,Y.useState)([]),[S,C]=(0,Y.useState)(!1),[w,E]=(0,Y.useState)(``),[D,O]=(0,Y.useState)(null),[k,A]=(0,Y.useState)(e?.permissionMode??void 0),[j,M]=(0,Y.useState)(!1),[P,F]=(0,Y.useState)(null),I=(0,Y.useRef)(0),L=e?.projectName??``,R=f(e=>e.updateTab),z=h(e=>e.version),{usageInfo:B,usageLoading:ee,lastFetchedAt:H,refreshUsage:U}=Xe(L,i);(0,Y.useEffect)(()=>{k||T().then(e=>{let t=e.providers[e.default_provider??`claude`];A(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,Y.useEffect)(()=>{!t||!n||R(t,{metadata:{...e,sessionId:n,providerId:i,permissionMode:k}})},[n,i,k]);let{messages:te,messagesLoading:ne,isStreaming:W,phase:re,isReconnecting:ie,connectingElapsed:ae,pendingApproval:oe,contextWindowPct:K,sessionTitle:se,sendMessage:q,respondToApproval:ce,cancelStreaming:le,reconnect:ue,refetchMessages:de,isConnected:J}=Je(n,i,L);(0,Y.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=u.getState();e[r]?.activeTabId===t&&G.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=u.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,Y.useEffect)(()=>{t&&se&&R(t,{title:se})},[se]);let fe=(0,Y.useRef)(e?.pendingMessage);(0,Y.useEffect)(()=>{if(fe.current&&J&&n){let n=fe.current;fe.current=void 0,t&&R(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>q(n,{permissionMode:k}),100)}},[J,n]),(0,Y.useCallback)(()=>{f.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:L},projectId:L||null,closable:!0})},[L]);let me=(0,Y.useCallback)(e=>{r(e.id),a(e.providerId),t&&R(t,{title:e.title||`Chat`})},[t,R]),he=(0,Y.useCallback)(async e=>{if(!(!n||!L))try{let{api:t,projectUrl:r}=await m(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-DpGMOZNf.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(L)}/chat/sessions/${n}/fork?providerId=${i}`);f.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:L,sessionId:a.id,providerId:i,pendingMessage:e},projectId:L||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,L,i]),ge=(0,Y.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
|
|
7
|
-
`);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),_e=(0,Y.useCallback)(async(e,t=[])=>{let o=ge(e,t);if(o.trim()){if(!n)try{let t=L,n=await x.post(`${y(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{q(o,{permissionMode:k})},500);return}catch(e){console.error(`Failed to create session:`,e);return}q(o,{permissionMode:k})}},[n,i,L,q,ge,k]),ve=(0,Y.useCallback)((e,t)=>{l(e),p(t)},[]),ye=(0,Y.useCallback)(e=>{_(e),l(!1),p(``),setTimeout(()=>_(null),50)},[]),be=(0,Y.useCallback)(()=>{l(!1),p(``)},[]),xe=(0,Y.useCallback)((e,t)=>{C(e),E(t)},[]),Se=(0,Y.useCallback)(e=>{O(e),C(!1),E(``),setTimeout(()=>O(null),50)},[]),Ce=(0,Y.useCallback)(()=>{C(!1),E(``)},[]);return(0,Z.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,Y.useCallback)(e=>{e.preventDefault(),I.current++,e.dataTransfer.types.includes(`Files`)&&M(!0)},[]),onDragLeave:(0,Y.useCallback)(e=>{e.preventDefault(),I.current--,I.current===0&&M(!1)},[]),onDragOver:(0,Y.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,Y.useCallback)(e=>{e.preventDefault(),I.current=0,M(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(F(t),setTimeout(()=>F(null),100))},[]),children:[j&&(0,Z.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm border-2 border-dashed border-primary rounded-lg pointer-events-none`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,Z.jsx)(V,{className:`size-8`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),ie&&(0,Z.jsx)(`div`,{className:`absolute inset-0 z-50 flex items-center justify-center bg-background/60 backdrop-blur-sm`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Z.jsx)(N,{className:`size-4 animate-spin`}),(0,Z.jsx)(`span`,{children:`Reconnecting...`})]})}),(0,Z.jsx)(St,{messages:te,messagesLoading:ne,pendingApproval:oe,onApprovalResponse:ce,isStreaming:W,phase:re,connectingElapsed:ae,projectName:L,onFork:W?void 0:he}),(0,Z.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,Z.jsx)(kn,{projectName:L,usageInfo:B,contextWindowPct:K,usageLoading:ee,refreshUsage:U,lastFetchedAt:H,sessionId:n,onSelectSession:me,onBugReport:n?()=>pe(z,{sessionId:n,projectName:L}):void 0,isConnected:J,onReconnect:()=>{J||ue(),de()}}),(0,Z.jsx)(pn,{items:o,filter:d,onSelect:ye,onClose:be,visible:c}),(0,Z.jsx)(un,{items:v,filter:w,onSelect:Se,onClose:Ce,visible:S}),(0,Z.jsx)(dn,{onSend:_e,isStreaming:W,onCancel:le,autoFocus:!e?.sessionId,projectName:L,onSlashStateChange:ve,onSlashItemsLoaded:s,slashSelected:g,onFileStateChange:xe,onFileItemsLoaded:b,fileSelected:D,externalFiles:P,permissionMode:k,onModeChange:A})]})]})}export{An as ChatTab};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dagre-KLK3FWXG-ChenfPp1.js","assets/dist-Cce3efmT.js","assets/chunk-CFjPhJqf.js","assets/chunk-PU5JKC2W-B66ELkQm.js","assets/src-BoSBNdA_.js","assets/chunk-GEFDOKGD-DwVPiYfW.js","assets/math-DwgHI-Cu.js","assets/chunk-7R4GIKGN-DXaGAn_K.js","assets/preload-helper-qlgyTAkD.js","assets/isArrayLikeObject-B4pdpV8V.js","assets/dagre-CNtSxiE_.js","assets/graphlib-DhOZxqsh.js","assets/isEmpty-C0YYdhYj.js","assets/_baseUniq-ClnvscgW.js","assets/_basePickBy-CZovQgWd.js","assets/clone-BSi6cgDh.js","assets/chunk-KYZI473N-BKO5gMeU.js","assets/chunk-PQ6SQG4A-BxtUGYhW.js","assets/chunk-YBOYWFTD-Dx_fX35n.js","assets/rough.esm-VLpapkIG.js","assets/chunk-MX3YWQON-BgjSEzus.js","assets/chunk-O4XLMI2P-BurQy8tt.js","assets/line-DBLLF7lH.js","assets/path-DZF-JdEe.js","assets/array-BGFCBI0e.js","assets/cose-bilkent-S5V4N54A-CHHjH2dV.js","assets/cytoscape.esm-Ccan6xou.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{t as e}from"./preload-helper-qlgyTAkD.js";import{u as t}from"./chunk-GEFDOKGD-DwVPiYfW.js";import{g as n,h as r}from"./src-BoSBNdA_.js";import{s as i,y as a}from"./chunk-7R4GIKGN-DXaGAn_K.js";import{a as o,i as s,s as c}from"./chunk-KYZI473N-BKO5gMeU.js";import{a as l,i as u,n as d,r as f}from"./chunk-O4XLMI2P-BurQy8tt.js";var p={common:i,getConfig:a,insertCluster:s,insertEdge:d,insertEdgeLabel:f,insertMarkers:u,insertNode:o,interpolateToCurve:t,labelHelper:c,log:n,positionEdgeLabel:l},m={},h=r(e=>{for(let t of e)m[t.name]=t},`registerLayoutLoaders`);r(()=>{h([{name:`dagre`,loader:r(async()=>await e(()=>import(`./dagre-KLK3FWXG-ChenfPp1.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24])),`loader`)},...[{name:`cose-bilkent`,loader:r(async()=>await e(()=>import(`./cose-bilkent-S5V4N54A-CHHjH2dV.js`),__vite__mapDeps([25,2,26,4])),`loader`)}]])},`registerDefaultLayoutLoaders`)();var g=r(async(e,t)=>{if(!(e.layoutAlgorithm in m))throw Error(`Unknown layout algorithm: ${e.layoutAlgorithm}`);let n=m[e.layoutAlgorithm];return(await n.loader()).render(e,t,p,{algorithm:n.algorithm})},`render`),_=r((e=``,{fallback:t=`dagre`}={})=>{if(e in m)return e;if(t in m)return n.warn(`Layout algorithm ${e} is not registered. Using ${t} as fallback.`),t;throw Error(`Both layout algorithms ${e} and ${t} are not registered.`)},`getRegisteredLayoutAlgorithm`);export{h as n,g as r,_ as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{h as e,p as t}from"./src-BoSBNdA_.js";import{b as n}from"./chunk-7R4GIKGN-DXaGAn_K.js";var r=e(e=>{let{securityLevel:r}=n(),i=t(`body`);return r===`sandbox`&&(i=t((t(`#i${e}`).node()?.contentDocument??document).body)),i.select(`#${e}`)},`selectSvgElement`);export{r as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{h as e}from"./src-BoSBNdA_.js";var t=class{constructor(e){this.init=e,this.records=this.init()}static{e(this,`ImperativeState`)}reset(){this.records=this.init()}};export{t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./chunk-GEFDOKGD-DwVPiYfW.js";import{h as e}from"./src-BoSBNdA_.js";import"./chunk-7R4GIKGN-DXaGAn_K.js";import"./dist-Cce3efmT.js";import"./chunk-PU5JKC2W-B66ELkQm.js";import"./chunk-FMBD7UC4-C_1aG0eb.js";import"./chunk-MX3YWQON-BgjSEzus.js";import"./chunk-YBOYWFTD-Dx_fX35n.js";import"./chunk-JSJVCQXG-BSrqCL_3.js";import"./chunk-55IACEB6-C4mUdyio.js";import"./chunk-KX2RTZJC-BCxGmbzy.js";import"./chunk-PQ6SQG4A-BxtUGYhW.js";import"./chunk-KYZI473N-BKO5gMeU.js";import"./chunk-O4XLMI2P-BurQy8tt.js";import"./chunk-GLR3WWYH-D9pZakqr.js";import{i as t,n,r,t as i}from"./chunk-WL4C6EOR-_2CBOJdI.js";var a={parser:n,get db(){return new i},renderer:r,styles:t,init:e(e=>{e.class||={},e.class.arrowMarkerAbsolute=e.arrowMarkerAbsolute},`init`)};export{a as diagram};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./chunk-GEFDOKGD-DwVPiYfW.js";import{h as e}from"./src-BoSBNdA_.js";import"./chunk-7R4GIKGN-DXaGAn_K.js";import"./dist-Cce3efmT.js";import"./chunk-PU5JKC2W-B66ELkQm.js";import"./chunk-FMBD7UC4-C_1aG0eb.js";import"./chunk-MX3YWQON-BgjSEzus.js";import"./chunk-YBOYWFTD-Dx_fX35n.js";import"./chunk-JSJVCQXG-BSrqCL_3.js";import"./chunk-55IACEB6-C4mUdyio.js";import"./chunk-KX2RTZJC-BCxGmbzy.js";import"./chunk-PQ6SQG4A-BxtUGYhW.js";import"./chunk-KYZI473N-BKO5gMeU.js";import"./chunk-O4XLMI2P-BurQy8tt.js";import"./chunk-GLR3WWYH-D9pZakqr.js";import{i as t,n,r,t as i}from"./chunk-WL4C6EOR-_2CBOJdI.js";var a={parser:n,get db(){return new i},renderer:r,styles:t,init:e(e=>{e.class||={},e.class.arrowMarkerAbsolute=e.arrowMarkerAbsolute},`init`)};export{a as diagram};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{y as e}from"./_baseUniq-ClnvscgW.js";var t=4;function n(n){return e(n,t)}export{n as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{o as i,t as a}from"./tab-store-DcIBZTD4.js";import{n as o}from"./settings-store-Bbhg_ptG.js";import{t as s}from"./utils-btZ8C8-R.js";import{i as c,r as l,t as u}from"./api-client-DpGMOZNf.js";import{B as d}from"./index-DmfRyMpE.js";import"./chunk-GEFDOKGD-DwVPiYfW.js";import"./src-BoSBNdA_.js";import"./chunk-7R4GIKGN-DXaGAn_K.js";import"./chunk-HHEYEP7N-Dld5BpGB.js";import"./dist-Cce3efmT.js";import"./chunk-PU5JKC2W-B66ELkQm.js";import"./chunk-MX3YWQON-BgjSEzus.js";import"./chunk-YBOYWFTD-Dx_fX35n.js";import"./chunk-PQ6SQG4A-BxtUGYhW.js";import"./chunk-KYZI473N-BKO5gMeU.js";import"./chunk-O4XLMI2P-BurQy8tt.js";import"./chunk-GLR3WWYH-D9pZakqr.js";import"./chunk-XPW4576I-CtcaMb09.js";import{t as f}from"./markdown-renderer-DwmzGpNI.js";import{n as p,t as m}from"./use-monaco-theme-vwto-Vlf.js";var h=n(`file-exclamation-point`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M12 9v4`,key:`juzpu7`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),g=e(t(),1),_=r(),v=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`]),y=new Set([`db`,`sqlite`,`sqlite3`]);function b(e){return e.split(`.`).pop()?.toLowerCase()??``}function x(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[b(e)]??`plaintext`}function S({metadata:e,tabId:t}){let n=e?.filePath,r=e?.projectName,[i,l]=(0,g.useState)(null),[f,S]=(0,g.useState)(`utf-8`),[E,D]=(0,g.useState)(!0),[O,k]=(0,g.useState)(null),[A,j]=(0,g.useState)(!1),M=(0,g.useRef)(null),N=(0,g.useRef)(``),P=(0,g.useRef)(null),{tabs:F,updateTab:I}=a(),{wordWrap:L,toggleWordWrap:R}=o(),z=m(),B=F.find(e=>e.id===t),V=n?b(n):``,H=v.has(V),U=V===`pdf`,W=y.has(V),G=V===`md`||V===`mdx`,[K,q]=(0,g.useState)(`preview`);(0,g.useEffect)(()=>{W&&t&&I(t,{type:`sqlite`})},[W,t,I]);let J=n?/^(\/|[A-Za-z]:[/\\])/.test(n):!1;(0,g.useEffect)(()=>{if(!n||!J&&!r)return;if(H||U){D(!1);return}D(!0),k(null);let e=J?`/api/fs/read?path=${encodeURIComponent(n)}`:`${c(r)}/files/read?path=${encodeURIComponent(n)}`;return u.get(e).then(e=>{l(e.content),e.encoding&&S(e.encoding),N.current=e.content,D(!1)}).catch(e=>{k(e instanceof Error?e.message:`Failed to load file`),D(!1)}),()=>{M.current&&clearTimeout(M.current)}},[n,r,H,U,J]),(0,g.useEffect)(()=>{if(!B)return;let e=n?s(n):`Untitled`,t=A?`${e} \u25CF`:e;B.title!==t&&I(B.id,{title:t})},[A]);let Y=(0,g.useCallback)(async e=>{if(n&&!(!J&&!r))try{J?await u.put(`/api/fs/write`,{path:n,content:e}):await u.put(`${c(r)}/files/write`,{path:n,content:e}),j(!1)}catch{}},[n,r,J]);function X(e){let t=e??``;l(t),N.current=t,j(!0),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>Y(N.current),1e3)}let Z=e?.lineNumber,Q=(0,g.useCallback)((e,t)=>{P.current=e,Z&&Z>0&&setTimeout(()=>{e.revealLineInCenter(Z),e.setPosition({lineNumber:Z,column:1}),e.focus()},100),e.addCommand(t.KeyMod.Alt|t.KeyCode.KeyZ,()=>o.getState().toggleWordWrap()),t.languages.typescript.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.languages.typescript.javascriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0})},[]);return!n||!J&&!r?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-text-secondary text-sm`,children:`No file selected.`}):E?(0,_.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-text-secondary`,children:[(0,_.jsx)(d,{className:`size-5 animate-spin`}),(0,_.jsx)(`span`,{className:`text-sm`,children:`Loading file...`})]}):O?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full text-error text-sm`,children:O}):H?(0,_.jsx)(w,{filePath:n,projectName:r}):U?(0,_.jsx)(T,{filePath:n,projectName:r}):f===`base64`?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`This file is a binary format and cannot be displayed.`}),(0,_.jsx)(`p`,{className:`text-xs text-text-subtle`,children:n})]}):(0,_.jsx)(`div`,{className:`flex flex-col h-full w-full overflow-hidden`,children:G&&K===`preview`?(0,_.jsx)(C,{content:i??``}):(0,_.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,_.jsx)(p,{height:`100%`,language:x(n),value:i??``,onChange:X,onMount:Q,theme:z,options:{fontSize:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:L?`on`:`off`,minimap:{enabled:!1},scrollBeyondLastLine:!1,automaticLayout:!0,lineNumbers:`on`,folding:!0,bracketPairColorization:{enabled:!0}},loading:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})})})}function C({content:e}){return(0,_.jsx)(f,{content:e,className:`flex-1 overflow-auto p-4`})}function w({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[i,a]=(0,g.useState)(!1);return(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,o=l();return fetch(i,{headers:o?{Authorization:`Bearer ${o}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(e);n=t,r(t)}).catch(()=>a(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]),i?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load image.`})]}):n?(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full p-4 bg-surface overflow-auto`,children:(0,_.jsx)(`img`,{src:n,alt:e,className:`max-w-full max-h-full object-contain`})}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}function T({filePath:e,projectName:t}){let[n,r]=(0,g.useState)(null),[a,o]=(0,g.useState)(!1);(0,g.useEffect)(()=>{let n,i=`${c(t)}/files/raw?path=${encodeURIComponent(e)}`,a=l();return fetch(i,{headers:a?{Authorization:`Bearer ${a}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed`);return e.blob()}).then(e=>{let t=URL.createObjectURL(new Blob([e],{type:`application/pdf`}));n=t,r(t)}).catch(()=>o(!0)),()=>{n&&URL.revokeObjectURL(n)}},[e,t]);let s=(0,g.useCallback)(()=>{n&&window.open(n,`_blank`)},[n]);return a?(0,_.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,_.jsx)(h,{className:`size-10 text-text-subtle`}),(0,_.jsx)(`p`,{className:`text-sm`,children:`Failed to load PDF.`})]}):n?(0,_.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,_.jsx)(`span`,{className:`text-xs text-text-secondary truncate`,children:e}),(0,_.jsxs)(`button`,{onClick:s,className:`flex items-center gap-1 text-xs text-text-secondary hover:text-text-primary transition-colors`,children:[(0,_.jsx)(i,{className:`size-3`}),` Open in new tab`]})]}),(0,_.jsx)(`iframe`,{src:n,title:e,className:`flex-1 w-full border-none`})]}):(0,_.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,_.jsx)(d,{className:`size-5 animate-spin text-text-subtle`})})}export{S as CodeEditor};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{t as n}from"./jsx-runtime-BRW_vwa9.js";import{a as r,c as i,i as a,n as o,o as s,r as c,s as l,t as u}from"./dist-T0Vhi0Mh.js";import{t as d}from"./api-client-DpGMOZNf.js";import{B as f,N as p,Y as m,nt as h,tt as g}from"./index-DmfRyMpE.js";var _=e(t(),1);function v(e,t,n,r){return`ppm-db-${e}-${n}.${t}-p${r}`}function y(e,t,n,r){try{let i=sessionStorage.getItem(v(e,t,n,r));return i?JSON.parse(i):null}catch{return null}}function b(e,t,n,r,i,a){try{sessionStorage.setItem(v(e,t,n,r),JSON.stringify({data:i,cols:a}))}catch{}}function x(e){let t=`/api/db/connections/${e}`,[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(`public`),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)([]),[u,f]=(0,_.useState)(!0),[p,m]=(0,_.useState)(null),[h,g]=(0,_.useState)(1),[v,x]=(0,_.useState)(null),[S,C]=(0,_.useState)(null),[w,T]=(0,_.useState)(!1),E=(0,_.useCallback)(async(r,a,o)=>{let c=r??n,u=a??i;if(c){f(!0);try{let[n,r]=await Promise.all([d.get(`${t}/data?table=${encodeURIComponent(c)}&schema=${u}&page=${o??h}&limit=100`),d.get(`${t}/schema?table=${encodeURIComponent(c)}&schema=${u}`)]);s(n),l(r),b(e,c,u,o??h,n,r)}catch(e){m(e.message)}finally{f(!1)}}},[t,e,n,i,h]);return{selectedTable:n,selectTable:(0,_.useCallback)((t,n=`public`)=>{r(t),a(n),g(1),x(null);let i=y(e,t,n,1);i?(s(i.data),l(i.cols),f(!1),E(t,n,1)):E(t,n,1)},[e,E]),tableData:o,schema:c,loading:u,error:p,page:h,setPage:(0,_.useCallback)(e=>{g(e),E(void 0,void 0,e)},[E]),queryResult:v,queryError:S,queryLoading:w,executeQuery:(0,_.useCallback)(async e=>{T(!0),C(null);try{let r=await d.post(`${t}/query`,{sql:e});x(r),r.changeType===`modify`&&E(n??void 0,i)}catch(e){C(e.message)}finally{T(!1)}},[t,n,i,E]),updateCell:(0,_.useCallback)(async(e,r,a,o)=>{if(!n)return;let s=n,c=i;try{await d.put(`${t}/cell`,{table:s,schema:c,pkColumn:e,pkValue:r,column:a,value:o}),E(s,c)}catch(e){m(e.message)}},[t,n,i,E]),refreshData:E}}var S=n(),C={postgres:u,sqlite:o};function w({metadata:e}){let t=e?.connectionId,n=e?.connectionName,r=e?.dbType??`postgres`,i=e?.tableName,a=e?.schemaName??`public`,o=x(t),[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{!i||l.current||(l.current=!0,o.selectTable(i,a))},[i,a]),(0,S.jsx)(`div`,{className:`flex h-full w-full overflow-hidden`,children:(0,S.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b border-border bg-background shrink-0`,children:[(0,S.jsx)(m,{className:`size-3.5 text-muted-foreground`}),(0,S.jsx)(`span`,{className:`text-xs text-muted-foreground truncate`,children:n??`Database`}),o.selectedTable&&(0,S.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`/ `,o.selectedTable]}),(0,S.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>o.refreshData(),title:`Reload data`,className:`p-1 rounded text-muted-foreground hover:text-foreground transition-colors`,children:(0,S.jsx)(p,{className:`size-3 ${o.loading?`animate-spin`:``}`})}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`px-2 py-1 rounded text-xs transition-colors ${s?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`}`,children:`SQL`})]})]}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden ${s?`max-h-[60%]`:``}`,children:(0,S.jsx)(T,{tableData:o.tableData,schema:o.schema,loading:o.loading,page:o.page,onPageChange:o.setPage,onCellUpdate:o.updateCell})}),s&&(0,S.jsx)(`div`,{className:`border-t border-border h-[40%] shrink-0`,children:(0,S.jsx)(E,{dialect:C[r]??u,onExecute:o.executeQuery,result:o.queryResult,error:o.queryError,loading:o.queryLoading})})]})})}function T({tableData:e,schema:t,loading:n,page:i,onPageChange:a,onCellUpdate:o}){let[c,u]=(0,_.useState)(null),[d,p]=(0,_.useState)(``),m=(0,_.useMemo)(()=>t.find(e=>e.pk)?.name??null,[t]),v=(0,_.useCallback)((e,t,n)=>{u({rowIdx:e,col:t}),p(n==null?``:String(n))},[]),y=(0,_.useCallback)(()=>{if(!c||!e||!m)return;let t=e.rows[c.rowIdx];if(!t)return;let n=t[c.col];String(n??``)!==d&&o(m,t[m],c.col,d===``?null:d),u(null)},[c,d,e,m,o]),b=(0,_.useCallback)(()=>u(null),[]),x=(0,_.useMemo)(()=>(e?.columns??[]).map(e=>({id:e,accessorFn:t=>t[e],header:()=>(0,S.jsx)(`span`,{className:t.find(t=>t.name===e)?.pk?`font-bold`:``,children:e}),cell:({row:t,getValue:n})=>{let r=c?.rowIdx===t.index&&c?.col===e,i=n();return r?(0,S.jsx)(`input`,{autoFocus:!0,className:`w-full bg-transparent border border-primary/50 rounded px-1 py-0 text-xs outline-none`,value:d,onChange:e=>p(e.target.value),onBlur:y,onKeyDown:e=>{e.key===`Enter`&&y(),e.key===`Escape`&&b()}}):(0,S.jsx)(`span`,{className:`cursor-pointer truncate block ${i==null?`text-muted-foreground/40 italic`:``}`,onDoubleClick:()=>m&&v(t.index,e,i),title:i==null?`NULL`:String(i),children:i==null?`NULL`:String(i)})}})),[e?.columns,t,c,d,y,b,v,m]),C=s({data:e?.rows??[],columns:x,getCoreRowModel:l()});if(!e)return(0,S.jsx)(`div`,{className:`flex items-center justify-center h-full text-xs text-muted-foreground`,children:n?(0,S.jsx)(f,{className:`size-4 animate-spin`}):`Select a table`});let w=Math.ceil(e.total/e.limit)||1;return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,S.jsxs)(`table`,{className:`w-full text-xs border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 z-10 bg-muted`,children:C.getHeaderGroups().map(e=>(0,S.jsx)(`tr`,{children:e.headers.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:r(e.column.columnDef.header,e.getContext())},e.id))},e.id))}),(0,S.jsxs)(`tbody`,{children:[C.getRowModel().rows.map(e=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:e.getVisibleCells().map(e=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px]`,children:r(e.column.columnDef.cell,e.getContext())},e.id))},e.id)),e.rows.length===0&&(0,S.jsx)(`tr`,{children:(0,S.jsx)(`td`,{colSpan:e.columns.length,className:`px-2 py-8 text-center text-muted-foreground`,children:`No data`})})]})]})}),(0,S.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-t border-border bg-background shrink-0 text-xs text-muted-foreground`,children:[(0,S.jsxs)(`span`,{children:[e.total.toLocaleString(),` rows`]}),(0,S.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,S.jsx)(`button`,{type:`button`,disabled:i<=1,onClick:()=>a(i-1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(h,{className:`size-3.5`})}),(0,S.jsxs)(`span`,{children:[i,` / `,w]}),(0,S.jsx)(`button`,{type:`button`,disabled:i>=w,onClick:()=>a(i+1),className:`p-0.5 rounded hover:bg-muted disabled:opacity-30`,children:(0,S.jsx)(g,{className:`size-3.5`})})]})]})]})}function E({dialect:e,onExecute:t,result:n,error:r,loading:o}){let[s,l]=(0,_.useState)(`SELECT * FROM `),u=(0,_.useCallback)(()=>{let e=s.trim();e&&t(e)},[s,t]);return(0,S.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-1 border-b border-border bg-background`,onKeyDown:(0,_.useCallback)(e=>{(e.metaKey||e.ctrlKey)&&e.key===`Enter`&&(e.preventDefault(),u())},[u]),children:[(0,S.jsx)(`div`,{className:`flex-1 max-h-[120px] overflow-auto`,children:(0,S.jsx)(a,{value:s,onChange:l,extensions:[c({dialect:e})],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1},className:`text-xs [&_.cm-editor]:!outline-none [&_.cm-scroller]:!overflow-auto`})}),(0,S.jsx)(`button`,{type:`button`,onClick:u,disabled:o,title:`Execute (Cmd+Enter)`,className:`shrink-0 m-1 p-1.5 rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:o?(0,S.jsx)(f,{className:`size-3.5 animate-spin`}):(0,S.jsx)(i,{className:`size-3.5`})})]}),(0,S.jsxs)(`div`,{className:`flex-1 overflow-auto text-xs`,children:[r&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-destructive bg-destructive/5`,children:r}),n?.changeType===`modify`&&(0,S.jsxs)(`div`,{className:`px-3 py-2 text-green-500`,children:[`Query executed. `,n.rowsAffected,` row(s) affected.`]}),n?.changeType===`select`&&n.rows.length>0&&(0,S.jsxs)(`table`,{className:`w-full border-collapse`,children:[(0,S.jsx)(`thead`,{className:`sticky top-0 bg-muted`,children:(0,S.jsx)(`tr`,{children:n.columns.map(e=>(0,S.jsx)(`th`,{className:`px-2 py-1 text-left font-medium text-muted-foreground border-b border-border whitespace-nowrap`,children:e},e))})}),(0,S.jsx)(`tbody`,{children:n.rows.map((e,t)=>(0,S.jsx)(`tr`,{className:`hover:bg-muted/30 border-b border-border/50`,children:n.columns.map(t=>(0,S.jsx)(`td`,{className:`px-2 py-1 max-w-[300px] truncate`,title:e[t]==null?`NULL`:String(e[t]),children:e[t]==null?(0,S.jsx)(`span`,{className:`text-muted-foreground/40 italic`,children:`NULL`}):String(e[t])},t))},t))})]}),n?.changeType===`select`&&n.rows.length===0&&(0,S.jsx)(`div`,{className:`px-3 py-2 text-muted-foreground`,children:`No results`})]})]})}export{w as DatabaseViewer};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./chunk-CFjPhJqf.js";import{t}from"./react-nm2Ru1Pt.js";import{n,t as r}from"./jsx-runtime-BRW_vwa9.js";import{t as i}from"./columns-2-ChOTgl3e.js";import{n as a}from"./settings-store-Bbhg_ptG.js";import{i as o,t as s}from"./api-client-DpGMOZNf.js";import{B as c,I as l,K as u}from"./index-DmfRyMpE.js";import{r as d,t as f}from"./use-monaco-theme-vwto-Vlf.js";var p=n(`panel-right-open`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]),m=n(`text-wrap`,[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]]),h=e(t(),1),g=r();function _(e){return{js:`javascript`,jsx:`javascript`,ts:`typescript`,tsx:`typescript`,py:`python`,html:`html`,css:`css`,scss:`scss`,json:`json`,md:`markdown`,mdx:`markdown`,yaml:`yaml`,yml:`yaml`,sh:`shell`,bash:`shell`}[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function v({metadata:e}){let t=e?.filePath,n=e?.projectName,r=e?.ref1,v=e?.ref2,b=e?.file1,x=e?.file2,S=e?.original,C=e?.modified,w=S!=null||C!=null,T=!!(b&&x),[E,D]=(0,h.useState)(null),[O,k]=(0,h.useState)(null),[A,j]=(0,h.useState)(!w),[M,N]=(0,h.useState)(null),[P,F]=(0,h.useState)(`both`),{wordWrap:I,toggleWordWrap:L}=a(),R=f(),z=(0,h.useRef)(null),[B,V]=(0,h.useState)();(0,h.useEffect)(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(([e])=>{e&&V(Math.floor(e.contentRect.height))});return t.observe(e),()=>t.disconnect()},[A,M]),(0,h.useEffect)(()=>{if(w||!n)return;if(j(!0),N(null),b&&x){let e=new URLSearchParams({file1:b,file2:x});s.get(`${o(n)}/files/compare?${e}`).then(e=>{k(e),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to compare files`),j(!1)});return}let e;if(t){let i=new URLSearchParams({file:t});r&&i.set(`ref`,r),e=`${o(n)}/git/file-diff?${i}`}else if(r||v){let t=new URLSearchParams;r&&t.set(`ref1`,r),v&&t.set(`ref2`,v),e=`${o(n)}/git/diff?${t}`}else e=`${o(n)}/git/diff`;s.get(e).then(e=>{D(e.diff),j(!1)}).catch(e=>{N(e instanceof Error?e.message:`Failed to load diff`),j(!1)})},[t,n,r,v,b,x,w]);let{original:H,modified:U}=(0,h.useMemo)(()=>w?{original:S??``,modified:C??``}:T&&O?O:E?y(E):{original:``,modified:``},[E,w,S,C,T,O]),W=(0,h.useMemo)(()=>{let e=t??x??b;return e?_(e):`plaintext`},[t,b,x]),G=typeof window<`u`&&window.innerWidth<768,K=!G&&P===`both`;return!n&&!w?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-muted-foreground text-sm`,children:`No project selected.`}):A?(0,g.jsxs)(`div`,{className:`flex items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(c,{className:`size-5 animate-spin`}),(0,g.jsx)(`span`,{className:`text-sm`,children:`Loading diff...`})]}):M?(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full text-destructive text-sm`,children:M}):!w&&!T&&!H&&!U?(0,g.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-2 text-muted-foreground`,children:[(0,g.jsx)(u,{className:`size-8`}),(0,g.jsx)(`p`,{className:`text-sm`,children:`No content changes`}),t&&(0,g.jsx)(`p`,{className:`text-xs font-mono`,children:t})]}):(0,g.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!G&&(0,g.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5 px-2 py-0.5 border-b border-border shrink-0`,children:[(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`left`?`both`:`left`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`left`?`bg-muted text-foreground`:``}`,title:`Expand original`,children:(0,g.jsx)(l,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(`both`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`both`?`bg-muted text-foreground`:``}`,title:`Side by side`,children:(0,g.jsx)(i,{className:`size-3.5`})}),(0,g.jsx)(`button`,{type:`button`,onClick:()=>F(P===`right`?`both`:`right`),className:`p-1 rounded hover:bg-muted transition-colors ${P===`right`?`bg-muted text-foreground`:``}`,title:`Expand modified`,children:(0,g.jsx)(p,{className:`size-3.5`})}),(0,g.jsx)(`div`,{className:`w-px h-3.5 bg-border mx-0.5 shrink-0`}),(0,g.jsx)(`button`,{type:`button`,onClick:L,title:`Toggle word wrap`,className:`p-1 rounded hover:bg-muted transition-colors ${I?`bg-muted text-foreground`:``}`,children:(0,g.jsx)(m,{className:`size-3.5`})})]}),(0,g.jsx)(`div`,{ref:z,className:`flex-1 overflow-hidden`,children:B&&B>0?(0,g.jsx)(d,{height:B,language:W,original:H,modified:U,theme:R,options:{fontSize:G?11:13,fontFamily:`Menlo, Monaco, Consolas, monospace`,wordWrap:G||I?`on`:`off`,renderSideBySide:K,readOnly:!0,automaticLayout:!0,scrollBeyondLastLine:!1},loading:(0,g.jsx)(c,{className:`size-5 animate-spin text-muted-foreground`})}):(0,g.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,g.jsx)(c,{className:`size-5 animate-spin text-muted-foreground`})})})]})}function y(e){let t=e.split(`
|
|
2
|
-
`),n=[],r=[],i=!1;for(let e of t)if(!(e.startsWith(`diff --git`)||e.startsWith(`diff --no-index`)||e.startsWith(`index `)||e.startsWith(`new file`)||e.startsWith(`deleted file`)||e.startsWith(`old mode`)||e.startsWith(`new mode`)||e.startsWith(`---`)||e.startsWith(`+++`)||e.startsWith(`Binary files`)||e.startsWith(`\\ No newline`))){if(e.startsWith(`@@`)){i=!0;continue}if(i)if(e.startsWith(`-`))n.push(e.slice(1));else if(e.startsWith(`+`))r.push(e.slice(1));else{let t=e.startsWith(` `)?e.slice(1):e;n.push(t),r.push(t)}}return{original:n.join(`
|
|
3
|
-
`),modified:r.join(`
|
|
4
|
-
`)}}export{v as DiffViewer};
|