@hienlh/ppm 0.8.9 → 0.8.11

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.11] - 2026-03-23
4
+
5
+ ### Fixed
6
+ - **Windows dev workflow**: Replace shell `&` with `concurrently` for cross-platform dev script, run dev:server in foreground, use `--profile dev` for SQLite-based config
7
+ - **PowerShell daemon**: Fix `ArgumentList` rejecting empty strings by stripping trailing empties and using `_` placeholder
8
+
9
+ ## [0.8.10] - 2026-03-23
10
+
11
+ ### Fixed
12
+ - **Block project .env poisoning**: All auth env vars (`ANTHROPIC_API_KEY`, `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, `CLAUDE_CODE_OAUTH_TOKEN`) are now explicitly set in SDK subprocess env — prevents Claude SDK from falling back to project `.env` which may contain unrelated/invalid keys (root cause of indefinite SDK hang)
13
+
3
14
  ## [0.8.9] - 2026-03-23
4
15
 
5
16
  ### Added
package/bun.lock CHANGED
@@ -49,6 +49,7 @@
49
49
  "@types/react-dom": "^19.2.3",
50
50
  "@types/web-push": "^3.6.4",
51
51
  "@vitejs/plugin-react": "^6.0.1",
52
+ "concurrently": "^9.2.1",
52
53
  "esbuild": "^0.27.4",
53
54
  "tailwindcss": "^4.2.1",
54
55
  "vite": "^8.0.0",
@@ -668,6 +669,10 @@
668
669
 
669
670
  "ajv": ["ajv@8.18.0", "", { "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2" } }, "sha512-PlXPeEWMXMZ7sPYOHqmDyCJzcfNrUr3fGNKtezX14ykXOEIvyK81d+qydx89KY5O71FKMPaQ2vBfBFI5NHR63A=="],
670
671
 
672
+ "ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="],
673
+
674
+ "ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
675
+
671
676
  "argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="],
672
677
 
673
678
  "aria-hidden": ["aria-hidden@1.2.6", "", { "dependencies": { "tslib": "^2.0.0" } }, "sha512-ik3ZgC9dY/lYVVM++OISsaYDeg1tb0VtP5uL3ouh1koGOaUMDPpbFIei4JkFimWUFPn90sbMNMXQAIVOlnYKJA=="],
@@ -716,20 +721,30 @@
716
721
 
717
722
  "caniuse-lite": ["caniuse-lite@1.0.30001778", "", {}, "sha512-PN7uxFL+ExFJO61aVmP1aIEG4i9whQd4eoSCebav62UwDyp5OHh06zN4jqKSMePVgxHifCw1QJxdRkA1Pisekg=="],
718
723
 
724
+ "chalk": ["chalk@4.1.2", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="],
725
+
719
726
  "chardet": ["chardet@2.1.1", "", {}, "sha512-PsezH1rqdV9VvyNhxxOW32/d75r01NY7TQCmOqomRo15ZSOKbpTFVsfjghxo6JloQUCGnH4k1LGu0R4yCLlWQQ=="],
720
727
 
721
728
  "class-variance-authority": ["class-variance-authority@0.7.1", "", { "dependencies": { "clsx": "^2.1.1" } }, "sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg=="],
722
729
 
723
730
  "cli-width": ["cli-width@4.1.0", "", {}, "sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ=="],
724
731
 
732
+ "cliui": ["cliui@8.0.1", "", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="],
733
+
725
734
  "clsx": ["clsx@2.1.1", "", {}, "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA=="],
726
735
 
727
736
  "codemirror": ["codemirror@6.0.2", "", { "dependencies": { "@codemirror/autocomplete": "^6.0.0", "@codemirror/commands": "^6.0.0", "@codemirror/language": "^6.0.0", "@codemirror/lint": "^6.0.0", "@codemirror/search": "^6.0.0", "@codemirror/state": "^6.0.0", "@codemirror/view": "^6.0.0" } }, "sha512-VhydHotNW5w1UGK0Qj96BwSk/Zqbp9WbnyK2W/eVMv4QyF41INRGpjUhFJY7/uDNuudSc33a/PKr4iDqRduvHw=="],
728
737
 
738
+ "color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="],
739
+
740
+ "color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="],
741
+
729
742
  "commander": ["commander@14.0.3", "", {}, "sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw=="],
730
743
 
731
744
  "common-tags": ["common-tags@1.8.2", "", {}, "sha512-gk/Z852D2Wtb//0I+kRFNKKE9dIIVirjoqPoA1wJU+XePVXZfGeBpk45+A1rKO4Q43prqWBNY/MiIeRLbPWUaA=="],
732
745
 
746
+ "concurrently": ["concurrently@9.2.1", "", { "dependencies": { "chalk": "4.1.2", "rxjs": "7.8.2", "shell-quote": "1.8.3", "supports-color": "8.1.1", "tree-kill": "1.2.2", "yargs": "17.7.2" }, "bin": { "conc": "dist/bin/concurrently.js", "concurrently": "dist/bin/concurrently.js" } }, "sha512-fsfrO0MxV64Znoy8/l1vVIjjHa29SZyyqPgQBwhiDcaW8wJc2W3XWVOGx4M3oJBnv/zdUZIIp1gDeS98GzP8Ng=="],
747
+
733
748
  "convert-source-map": ["convert-source-map@2.0.0", "", {}, "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg=="],
734
749
 
735
750
  "core-js-compat": ["core-js-compat@3.48.0", "", { "dependencies": { "browserslist": "^4.28.1" } }, "sha512-OM4cAF3D6VtH/WkLtWvyNC56EZVXsZdU3iqaMG2B4WvYrlqU831pc4UtG5yp0sE9z8Y02wVN7PjW5Zf9Gt0f1Q=="],
@@ -774,6 +789,8 @@
774
789
 
775
790
  "electron-to-chromium": ["electron-to-chromium@1.5.313", "", {}, "sha512-QBMrTWEf00GXZmJyx2lbYD45jpI3TUFnNIzJ5BBc8piGUDwMPa1GV6HJWTZVvY/eiN3fSopl7NRbgGp9sZ9LTA=="],
776
791
 
792
+ "emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
793
+
777
794
  "enhanced-resolve": ["enhanced-resolve@5.20.0", "", { "dependencies": { "graceful-fs": "^4.2.4", "tapable": "^2.3.0" } }, "sha512-/ce7+jQ1PQ6rVXwe+jKEg5hW5ciicHwIQUagZkp6IufBoY3YDgdTTY1azVs0qoRgVmvsNB+rbjLJxDAeHHtwsQ=="],
778
795
 
779
796
  "es-abstract": ["es-abstract@1.24.1", "", { "dependencies": { "array-buffer-byte-length": "^1.0.2", "arraybuffer.prototype.slice": "^1.0.4", "available-typed-arrays": "^1.0.7", "call-bind": "^1.0.8", "call-bound": "^1.0.4", "data-view-buffer": "^1.0.2", "data-view-byte-length": "^1.0.2", "data-view-byte-offset": "^1.0.1", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "es-set-tostringtag": "^2.1.0", "es-to-primitive": "^1.3.0", "function.prototype.name": "^1.1.8", "get-intrinsic": "^1.3.0", "get-proto": "^1.0.1", "get-symbol-description": "^1.1.0", "globalthis": "^1.0.4", "gopd": "^1.2.0", "has-property-descriptors": "^1.0.2", "has-proto": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "internal-slot": "^1.1.0", "is-array-buffer": "^3.0.5", "is-callable": "^1.2.7", "is-data-view": "^1.0.2", "is-negative-zero": "^2.0.3", "is-regex": "^1.2.1", "is-set": "^2.0.3", "is-shared-array-buffer": "^1.0.4", "is-string": "^1.1.1", "is-typed-array": "^1.1.15", "is-weakref": "^1.1.1", "math-intrinsics": "^1.1.0", "object-inspect": "^1.13.4", "object-keys": "^1.1.1", "object.assign": "^4.1.7", "own-keys": "^1.0.1", "regexp.prototype.flags": "^1.5.4", "safe-array-concat": "^1.1.3", "safe-push-apply": "^1.0.0", "safe-regex-test": "^1.1.0", "set-proto": "^1.0.0", "stop-iteration-iterator": "^1.1.0", "string.prototype.trim": "^1.2.10", "string.prototype.trimend": "^1.0.9", "string.prototype.trimstart": "^1.0.8", "typed-array-buffer": "^1.0.3", "typed-array-byte-length": "^1.0.3", "typed-array-byte-offset": "^1.0.4", "typed-array-length": "^1.0.7", "unbox-primitive": "^1.1.0", "which-typed-array": "^1.1.19" } }, "sha512-zHXBLhP+QehSSbsS9Pt23Gg964240DPd6QCf8WpkqEXxQ7fhdZzYsocOr5u7apWonsS5EjZDmTF+/slGMyasvw=="],
@@ -830,6 +847,8 @@
830
847
 
831
848
  "gensync": ["gensync@1.0.0-beta.2", "", {}, "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg=="],
832
849
 
850
+ "get-caller-file": ["get-caller-file@2.0.5", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="],
851
+
833
852
  "get-intrinsic": ["get-intrinsic@1.3.0", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "math-intrinsics": "^1.1.0" } }, "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ=="],
834
853
 
835
854
  "get-nonce": ["get-nonce@1.0.1", "", {}, "sha512-FJhYRoDaiatfEkUK8HKlicmu/3SGFD51q3itKDGoSTysQJBnfOcxU5GxnhE1E6soB76MbT0MBtnKJuXyAx+96Q=="],
@@ -850,6 +869,8 @@
850
869
 
851
870
  "has-bigints": ["has-bigints@1.1.0", "", {}, "sha512-R3pbpkcIqv2Pm3dUwgjclDRVmWpTJW2DcMzcIhEXEx1oh/CEMObMm3KLmRJOdvhM7o4uQBnwr8pzRK2sJWIqfg=="],
852
871
 
872
+ "has-flag": ["has-flag@4.0.0", "", {}, "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="],
873
+
853
874
  "has-property-descriptors": ["has-property-descriptors@1.0.2", "", { "dependencies": { "es-define-property": "^1.0.0" } }, "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg=="],
854
875
 
855
876
  "has-proto": ["has-proto@1.2.0", "", { "dependencies": { "dunder-proto": "^1.0.0" } }, "sha512-KIL7eQPfHQRC8+XluaIw7BHUwwqL19bQn4hzNgdr+1wXoU0KKj6rufu47lhY7KbJR2C6T6+PfyN0Ea7wkSS+qQ=="],
@@ -896,6 +917,8 @@
896
917
 
897
918
  "is-finalizationregistry": ["is-finalizationregistry@1.1.1", "", { "dependencies": { "call-bound": "^1.0.3" } }, "sha512-1pC6N8qWJbWoPtEjgcL2xyhQOP491EQjeUo3qTKcmV8YSDDJrOepfG8pcC7h/QgnQHYSv0mJ3Z/ZWxmatVrysg=="],
898
919
 
920
+ "is-fullwidth-code-point": ["is-fullwidth-code-point@3.0.0", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="],
921
+
899
922
  "is-generator-function": ["is-generator-function@1.1.2", "", { "dependencies": { "call-bound": "^1.0.4", "generator-function": "^2.0.0", "get-proto": "^1.0.1", "has-tostringtag": "^1.0.2", "safe-regex-test": "^1.1.0" } }, "sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA=="],
900
923
 
901
924
  "is-map": ["is-map@2.0.3", "", {}, "sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw=="],
@@ -1088,6 +1111,8 @@
1088
1111
 
1089
1112
  "regjsparser": ["regjsparser@0.13.0", "", { "dependencies": { "jsesc": "~3.1.0" }, "bin": { "regjsparser": "bin/parser" } }, "sha512-NZQZdC5wOE/H3UT28fVGL+ikOZcEzfMGk/c3iN9UGxzWHMa1op7274oyiUVrAG4B2EuFhus8SvkaYnhvW92p9Q=="],
1090
1113
 
1114
+ "require-directory": ["require-directory@2.1.1", "", {}, "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q=="],
1115
+
1091
1116
  "require-from-string": ["require-from-string@2.0.2", "", {}, "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw=="],
1092
1117
 
1093
1118
  "resolve": ["resolve@1.22.11", "", { "dependencies": { "is-core-module": "^2.16.1", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, "bin": { "resolve": "bin/resolve" } }, "sha512-RfqAvLnMl313r7c9oclB1HhUEAezcpLjz95wFH4LVuhk9JF/r22qmVP9AMmOU4vMX7Q8pN8jwNg/CSpdFnMjTQ=="],
@@ -1096,6 +1121,8 @@
1096
1121
 
1097
1122
  "rollup": ["rollup@2.80.0", "", { "optionalDependencies": { "fsevents": "~2.3.2" }, "bin": { "rollup": "dist/bin/rollup" } }, "sha512-cIFJOD1DESzpjOBl763Kp1AH7UE/0fcdHe6rZXUdQ9c50uvgigvW97u3IcSeBwOkgqL/PXPBktBCh0KEu5L8XQ=="],
1098
1123
 
1124
+ "rxjs": ["rxjs@7.8.2", "", { "dependencies": { "tslib": "^2.1.0" } }, "sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA=="],
1125
+
1099
1126
  "safe-array-concat": ["safe-array-concat@1.1.3", "", { "dependencies": { "call-bind": "^1.0.8", "call-bound": "^1.0.2", "get-intrinsic": "^1.2.6", "has-symbols": "^1.1.0", "isarray": "^2.0.5" } }, "sha512-AURm5f0jYEOydBj7VQlVvDrjeFgthDdEF5H1dP+6mNpoXOMo1quQqJ4wvJDyRZ9+pO3kGWoOdmV08cSv2aJV6Q=="],
1100
1127
 
1101
1128
  "safe-buffer": ["safe-buffer@5.2.1", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
@@ -1122,6 +1149,8 @@
1122
1149
 
1123
1150
  "shebang-regex": ["shebang-regex@3.0.0", "", {}, "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A=="],
1124
1151
 
1152
+ "shell-quote": ["shell-quote@1.8.3", "", {}, "sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw=="],
1153
+
1125
1154
  "side-channel": ["side-channel@1.1.0", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3", "side-channel-list": "^1.0.0", "side-channel-map": "^1.0.1", "side-channel-weakmap": "^1.0.2" } }, "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw=="],
1126
1155
 
1127
1156
  "side-channel-list": ["side-channel-list@1.0.0", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3" } }, "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA=="],
@@ -1150,6 +1179,8 @@
1150
1179
 
1151
1180
  "stop-iteration-iterator": ["stop-iteration-iterator@1.1.0", "", { "dependencies": { "es-errors": "^1.3.0", "internal-slot": "^1.1.0" } }, "sha512-eLoXW/DHyl62zxY4SCaIgnRhuMr6ri4juEYARS8E6sCEqzKpOiE521Ucofdx+KnDZl5xmvGYaaKCk5FEOxJCoQ=="],
1152
1181
 
1182
+ "string-width": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],
1183
+
1153
1184
  "string.prototype.matchall": ["string.prototype.matchall@4.0.12", "", { "dependencies": { "call-bind": "^1.0.8", "call-bound": "^1.0.3", "define-properties": "^1.2.1", "es-abstract": "^1.23.6", "es-errors": "^1.3.0", "es-object-atoms": "^1.0.0", "get-intrinsic": "^1.2.6", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "internal-slot": "^1.1.0", "regexp.prototype.flags": "^1.5.3", "set-function-name": "^2.0.2", "side-channel": "^1.1.0" } }, "sha512-6CC9uyBL+/48dYizRf7H7VAYCMCNTBeM78x/VTUe9bFEaxBepPJDa1Ow99LqI/1yF7kuy7Q3cQsYMrcjGUcskA=="],
1154
1185
 
1155
1186
  "string.prototype.trim": ["string.prototype.trim@1.2.10", "", { "dependencies": { "call-bind": "^1.0.8", "call-bound": "^1.0.2", "define-data-property": "^1.1.4", "define-properties": "^1.2.1", "es-abstract": "^1.23.5", "es-object-atoms": "^1.0.0", "has-property-descriptors": "^1.0.2" } }, "sha512-Rs66F0P/1kedk5lyYyH9uBzuiI/kNRmwJAR9quK6VOtIpZ2G+hMZd+HQbbv25MgCA6gEffoMZYxlTod4WcdrKA=="],
@@ -1160,10 +1191,14 @@
1160
1191
 
1161
1192
  "stringify-object": ["stringify-object@3.3.0", "", { "dependencies": { "get-own-enumerable-property-symbols": "^3.0.0", "is-obj": "^1.0.1", "is-regexp": "^1.0.0" } }, "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw=="],
1162
1193
 
1194
+ "strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="],
1195
+
1163
1196
  "strip-comments": ["strip-comments@2.0.1", "", {}, "sha512-ZprKx+bBLXv067WTCALv8SSz5l2+XhpYCsVtSqlMnkAXMWDq+/ekVbl1ghqP9rUHTzv6sm/DwCOiYutU/yp1fw=="],
1164
1197
 
1165
1198
  "style-mod": ["style-mod@4.1.3", "", {}, "sha512-i/n8VsZydrugj3Iuzll8+x/00GH2vnYsk1eomD8QiRrSAeW6ItbCQDtfXCeJHd0iwiNagqjQkvpvREEPtW3IoQ=="],
1166
1199
 
1200
+ "supports-color": ["supports-color@8.1.1", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q=="],
1201
+
1167
1202
  "supports-preserve-symlinks-flag": ["supports-preserve-symlinks-flag@1.0.0", "", {}, "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w=="],
1168
1203
 
1169
1204
  "tailwind-merge": ["tailwind-merge@3.5.0", "", {}, "sha512-I8K9wewnVDkL1NTGoqWmVEIlUcB9gFriAEkXkfCjX5ib8ezGxtR3xD7iZIxrfArjEsH7F1CHD4RFUtxefdqV/A=="],
@@ -1182,6 +1217,8 @@
1182
1217
 
1183
1218
  "tr46": ["tr46@1.0.1", "", { "dependencies": { "punycode": "^2.1.0" } }, "sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA=="],
1184
1219
 
1220
+ "tree-kill": ["tree-kill@1.2.2", "", { "bin": { "tree-kill": "cli.js" } }, "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A=="],
1221
+
1185
1222
  "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
1186
1223
 
1187
1224
  "type-fest": ["type-fest@0.16.0", "", {}, "sha512-eaBzG6MxNzEn9kiwvtre90cXaNLkmadMWa1zQMs3XORCXNbsH/OewwbxC5ia9dCxIxnTAsSxXJaa/p5y8DlvJg=="],
@@ -1280,8 +1317,16 @@
1280
1317
 
1281
1318
  "workbox-window": ["workbox-window@7.4.0", "", { "dependencies": { "@types/trusted-types": "^2.0.2", "workbox-core": "7.4.0" } }, "sha512-/bIYdBLAVsNR3v7gYGaV4pQW3M3kEPx5E8vDxGvxo6khTrGtSSCS7QiFKv9ogzBgZiy0OXLP9zO28U/1nF1mfw=="],
1282
1319
 
1320
+ "wrap-ansi": ["wrap-ansi@7.0.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="],
1321
+
1322
+ "y18n": ["y18n@5.0.8", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="],
1323
+
1283
1324
  "yallist": ["yallist@3.1.1", "", {}, "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g=="],
1284
1325
 
1326
+ "yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="],
1327
+
1328
+ "yargs-parser": ["yargs-parser@21.1.1", "", {}, "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw=="],
1329
+
1285
1330
  "zod": ["zod@4.3.6", "", {}, "sha512-rftlrkhHZOcjDwkGlnUtZZkvaPHCsDATp4pGpuOOMDaTdDDXF91wuVDJoWoPsKX/3YPQ5fHuF3STjcYyKr+Qhg=="],
1286
1331
 
1287
1332
  "zustand": ["zustand@5.0.11", "", { "peerDependencies": { "@types/react": ">=18.0.0", "immer": ">=9.0.6", "react": ">=18.0.0", "use-sync-external-store": ">=1.2.0" }, "optionalPeers": ["@types/react", "immer", "react", "use-sync-external-store"] }, "sha512-fdZY+dk7zn/vbWNCYmzZULHRrss0jx5pPFiOuMZ/5HJN6Yv3u+1Wswy/4MpZEkEGhtNH+pwxZB8OKgUBPzYAGg=="],
@@ -1308,6 +1353,8 @@
1308
1353
 
1309
1354
  "@tailwindcss/oxide-wasm32-wasi/tslib": ["tslib@2.8.1", "", { "bundled": true }, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
1310
1355
 
1356
+ "chalk/supports-color": ["supports-color@7.2.0", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw=="],
1357
+
1311
1358
  "filelist/minimatch": ["minimatch@5.1.9", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-7o1wEA2RyMP7Iu7GNba9vc0RWWGACJOCZBJX2GJWip0ikV+wcOsgVuY9uE8CPiyQhkGFSlhuSkZPavN7u1c2Fw=="],
1312
1359
 
1313
1360
  "monaco-editor/marked": ["marked@14.0.0", "", { "bin": { "marked": "bin/marked.js" } }, "sha512-uIj4+faQ+MgHgwUW1l2PsPglZLOLOT1uErt06dAPtx2kjteLAkbsd/0FiYg/MGS+i7ZKLb7w2WClxHkzOOuryQ=="],
@@ -1,7 +1,7 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/api-client-TUmacMRS.js","assets/react-CYzKIDNi.js"])))=>i.map(i=>d[i]);
2
- import{i as e,t}from"./react-CYzKIDNi.js";import{A as n,M as r,N as i,j as a}from"./input-CE3bFwLk.js";import{n as o,t as s}from"./jsx-runtime-wQxeESYQ.js";import{D as c,T as l,c as u,h as d,l as f,n as p,o as m,p as h,t as g,u as _,w as v}from"./switch-D0FJQVBN.js";import{t as y}from"./columns-2-fz8yNaAo.js";import{a as b,n as x,t as S}from"./tab-store-0CKk8cSr.js";import{n as C}from"./settings-store-2NQzaOVJ.js";import{r as w,t as T}from"./utils-DC-bdPS3.js";import{i as E,r as D,t as O}from"./api-client-TUmacMRS.js";import{A as k,B as A,C as j,D as M,E as N,H as P,M as F,N as I,P as L,T as R,V as z,g as B,h as ee,k as te,t as ne}from"./index-BjNob0pC.js";import{t as V}from"./markdown-renderer-GNvNI0W2.js";var re=o(`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`}]]),ie=o(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),H=o(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),U=o(`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`}]]),W=o(`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`}]]),ae=o(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),oe=o(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),se=o(`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`}]]),ce=o(`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`}]]),G=o(`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`}]]),K=o(`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`}]]),le=o(`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`}]]),ue=o(`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`}]]),de=o(`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`}]]),fe=o(`shield-check`,[[`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:`m9 12 2 2 4-4`,key:`dzmm74`}]]),q=o(`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=o(`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`}]]),me=o(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),J=e(t(),1),he=3e4,ge=1e3,_e=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(ge*2**this.reconnectAttempts,he);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ve({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let i=new _e(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,J.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,J.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,J.useCallback)(()=>{r.current?.disconnect()},[])}}var ye=null;function be(){return ye||=new AudioContext,ye}function Y(e,t,n,r,i=`sine`){let a=be(),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 xe(){let e=be().currentTime;Y(523,.15,e,.15),Y(659,.2,e+.12,.15)}function Se(){let e=be().currentTime;Y(880,.12,e,.18,`square`),Y(698,.12,e+.15,.18,`square`),Y(880,.15,e+.3,.15,`square`)}function Ce(){let e=be().currentTime;Y(440,.12,e,.12),Y(523,.12,e+.1,.12),Y(659,.18,e+.2,.12)}var we={done:xe,approval_request:Se,question:Ce};function Te(e){try{we[e]?.()}catch{}}function Ee(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=x.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 De(e,t=`claude`,n=``){let[r,i]=(0,J.useState)([]),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(!1),[l,u]=(0,J.useState)(`idle`),[d,f]=(0,J.useState)(0),[p,m]=(0,J.useState)(15),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(null),[x,S]=(0,J.useState)(!1),C=(0,J.useRef)(``),w=(0,J.useRef)([]),T=(0,J.useRef)(null),O=(0,J.useRef)(!1),k=(0,J.useRef)(null),A=(0,J.useRef)(()=>{}),j=(0,J.useRef)(null),M=(0,J.useRef)(e);M.current=e;let N=(0,J.useRef)(n);N.current=n;let P=(0,J.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`title_updated`){b(t.title??null);return}if(t.type===`streaming_status`){let e=t.status??`idle`;if(u(e),f(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),m(r)}return}if(t.type===`connected`){S(!0),t.sessionTitle&&b(t.sessionTitle);return}if(t.type===`status`){S(!0);let e=t;e.sessionTitle&&b(e.sessionTitle),e.isStreaming&&(O.current=!0,c(!0)),e.pendingApproval&&g({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),j.current?.();return}let n=(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},r=()=>{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}]})};switch(t.type){case`account_info`:T.current={accountId:t.accountId,accountLabel:t.accountLabel};break;case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}C.current+=t.content,w.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`approval_request`:if(w.current.push(t),g({requestId:t.requestId,tool:t.tool,input:t.input}),M.current&&!Ee(M.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;B.getState().addNotification(M.current,e,N.current),Te(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()}]}),O.current=!1,c(!1),u(`idle`);break}case`done`:{if(!O.current)break;t.contextWindowPct!=null&&v(t.contextWindowPct),M.current&&!Ee(M.current)&&(B.getState().addNotification(M.current,`done`,N.current),Te(`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,O.current=!1,c(!1),u(`idle`);break}}},[]),{send:F,connect:I}=ve({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:P,autoConnect:!!e&&!!n});A.current=F,(0,J.useEffect)(()=>{let r=!1;return c(!1),g(null),C.current=``,w.current=[],S(!1),e&&n?(o(!0),fetch(`${E(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${D()}`}}).then(e=>e.json()).then(e=>{r||O.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&!O.current&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let L=(0,J.useCallback)((e,t)=>{if(e.trim()){if(O.current){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}),F(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),C.current=``,w.current=[],k.current=null,O.current=!0,c(!0),u(`connecting`),g(null),F(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode}))}},[F]),R=(0,J.useCallback)((e,t,n)=>{if(F(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])}g(null)},[F]),z=(0,J.useCallback)(()=>{if(!O.current)return;F(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=[],k.current=null,O.current=!1,c(!1),g(null)},[F]),ee=(0,J.useCallback)(()=>{S(!1),I(),j.current?.()},[I]),te=(0,J.useCallback)(()=>{!e||!n||(o(!0),fetch(`${E(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${D()}`}}).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 j.current=te,{messages:r,messagesLoading:a,isStreaming:s,streamingStatus:l,connectingElapsed:d,thinkingWarningThreshold:p,pendingApproval:h,contextWindowPct:_,sessionTitle:y,sendMessage:L,respondToApproval:R,cancelStreaming:z,reconnect:ee,refetchMessages:te,isConnected:x}}var Oe=12e4;function ke(e,t=`claude`){let[n,r]=(0,J.useState)({}),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(null),c=(0,J.useRef)(null),l=(0,J.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${E(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${D()}`}}).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,J.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Oe),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,J.useCallback)(()=>l(!0),[l])}}var Ae={damping:.7,stiffness:.05,mass:1.25},je=70,Me=1e3/60,Ne=350,Pe=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Pe=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Pe=!1}),globalThis.document?.addEventListener(`click`,()=>{Pe=!1});var Fe=(e={})=>{let[t,n]=(0,J.useState)(!1),[r,i]=(0,J.useState)(e.initial!==!1),[a,o]=(0,J.useState)(!1),s=(0,J.useRef)(null);s.current=e;let c=(0,J.useCallback)(()=>{if(!Pe)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,J.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,J.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,J.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<=je}}},[]),f=(0,J.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Re(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))/Me;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:Re(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,J.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,J.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,J.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=Ie(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Ie(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=Re(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Ne})}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 Ie(e,t){let n=(0,J.useCallback)(t=>(n.current=t,e(t)),t);return n}var Le=new Map;function Re(...e){let t={...Ae},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 Le.has(r)||Le.set(r,Object.freeze(t)),n?`instant`:Le.get(r)}var ze=(0,J.createContext)(null),Be=typeof window<`u`?J.useLayoutEffect:J.useEffect;function Ve({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,J.useRef)(null),d=Fe({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:J.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,J.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,J.useImperativeHandle)(c,()=>y,[y]),Be(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),J.createElement(ze.Provider,{value:y},J.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=He();return J.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},J.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(Ve||={});function He(){let e=(0,J.useContext)(ze);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var X=s();function Ue(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 We({tool:e,result:t,completed:n,projectName:i}){let[a,o]=(0,J.useState)(!1);if(e.type===`error`)return(0,X.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,X.jsx)(z,{className:`size-3`}),(0,X.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=Ue(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,X.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,X.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,X.jsx)(r,{className:`size-3 shrink-0`}):(0,X.jsx)(P,{className:`size-3 shrink-0`}),u?(0,X.jsx)(U,{className:`size-3 text-red-400 shrink-0`}):l||d||n?(0,X.jsx)(A,{className:`size-3 text-green-400 shrink-0`}):(0,X.jsx)(k,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,X.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,X.jsx)(Ge,{name:s,input:c})}),m&&(0,X.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),a&&(0,X.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,X.jsx)(Ke,{name:s,input:c,projectName:i}),m&&(0,X.jsx)(Xe,{events:p,projectName:i}),l&&(0,X.jsx)(Je,{toolName:s,output:t.output})]})]})}function Ge({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:T(n(t.file_path))})]});case`Bash`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.command),60)})]});case`Glob`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.pattern),40)})]});case`WebSearch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`WebFetch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(oe,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.url),50)})]});case`ToolSearch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`Agent`:case`Task`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(H,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(K,{className:`size-3 inline`}),` `,e,` `,(0,X.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,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,X.jsx)(X.Fragment,{children:e})}}function Ke({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=S(),a=e=>{n&&i({type:`editor`,title:T(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${T(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,X.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.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,X.jsx)(b,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,X.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,X.jsx)(y,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,X.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Z(r(t.content),300)})]})}case`Glob`:return(0,X.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,X.jsx)(qe,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,X.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,X.jsx)(Ze,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.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,X.jsx)(oe,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,X.jsx)(`p`,{className:`text-text-subtle`,children:Z(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,X.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,X.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,X.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,X.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function qe({todos:e}){return(0,X.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.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,X.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Je({toolName:e,output:t}){let[n,r]=(0,J.useState)(!1),i=(0,J.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(`
2
+ import{i as e,t}from"./react-CYzKIDNi.js";import{A as n,M as r,N as i,j as a}from"./input-CE3bFwLk.js";import{n as o,t as s}from"./jsx-runtime-wQxeESYQ.js";import{D as c,T as l,c as u,h as d,l as f,n as p,o as m,p as h,t as g,u as _,w as v}from"./switch-D0FJQVBN.js";import{t as y}from"./columns-2-fz8yNaAo.js";import{a as b,n as x,t as S}from"./tab-store-0CKk8cSr.js";import{n as C}from"./settings-store-2NQzaOVJ.js";import{r as w,t as T}from"./utils-DC-bdPS3.js";import{i as E,r as D,t as O}from"./api-client-TUmacMRS.js";import{A as k,B as A,C as j,D as M,E as N,H as P,M as F,N as I,P as L,T as R,V as z,g as B,h as ee,k as te,t as ne}from"./index-ZE_hGmh8.js";import{t as V}from"./markdown-renderer-C1T1GaXJ.js";var re=o(`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`}]]),ie=o(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),H=o(`bot`,[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]),U=o(`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`}]]),W=o(`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`}]]),ae=o(`code`,[[`path`,{d:`m16 18 6-6-6-6`,key:`eg8j8`}],[`path`,{d:`m8 6-6 6 6 6`,key:`ppft3o`}]]),oe=o(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),se=o(`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`}]]),ce=o(`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`}]]),G=o(`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`}]]),K=o(`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`}]]),le=o(`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`}]]),ue=o(`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`}]]),de=o(`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`}]]),fe=o(`shield-check`,[[`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:`m9 12 2 2 4-4`,key:`dzmm74`}]]),q=o(`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=o(`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`}]]),me=o(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),J=e(t(),1),he=3e4,ge=1e3,_e=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(ge*2**this.reconnectAttempts,he);this.reconnectAttempts++,this.reconnectTimer=setTimeout(()=>this.connect(),e)}};function ve({url:e,onMessage:t,autoConnect:n=!0}){let r=(0,J.useRef)(null);return(0,J.useEffect)(()=>{let i=new _e(e);return r.current=i,t&&i.onMessage(t),n&&i.connect(),()=>{i.disconnect(),r.current=null}},[e,n]),{send:(0,J.useCallback)(e=>{r.current?.send(e)},[]),connect:(0,J.useCallback)(()=>{r.current?.connect()},[]),disconnect:(0,J.useCallback)(()=>{r.current?.disconnect()},[])}}var ye=null;function be(){return ye||=new AudioContext,ye}function Y(e,t,n,r,i=`sine`){let a=be(),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 xe(){let e=be().currentTime;Y(523,.15,e,.15),Y(659,.2,e+.12,.15)}function Se(){let e=be().currentTime;Y(880,.12,e,.18,`square`),Y(698,.12,e+.15,.18,`square`),Y(880,.15,e+.3,.15,`square`)}function Ce(){let e=be().currentTime;Y(440,.12,e,.12),Y(523,.12,e+.1,.12),Y(659,.18,e+.2,.12)}var we={done:xe,approval_request:Se,question:Ce};function Te(e){try{we[e]?.()}catch{}}function Ee(e){if(document.hidden)return!1;let{panels:t,focusedPanelId:n}=x.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 De(e,t=`claude`,n=``){let[r,i]=(0,J.useState)([]),[a,o]=(0,J.useState)(!1),[s,c]=(0,J.useState)(!1),[l,u]=(0,J.useState)(`idle`),[d,f]=(0,J.useState)(0),[p,m]=(0,J.useState)(15),[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)(null),[y,b]=(0,J.useState)(null),[x,S]=(0,J.useState)(!1),C=(0,J.useRef)(``),w=(0,J.useRef)([]),T=(0,J.useRef)(null),O=(0,J.useRef)(!1),k=(0,J.useRef)(null),A=(0,J.useRef)(()=>{}),j=(0,J.useRef)(null),M=(0,J.useRef)(e);M.current=e;let N=(0,J.useRef)(n);N.current=n;let P=(0,J.useCallback)(e=>{let t;try{t=JSON.parse(e.data)}catch{return}if(t.type===`ping`)return;if(t.type===`title_updated`){b(t.title??null);return}if(t.type===`streaming_status`){let e=t.status??`idle`;if(u(e),f(e===`connecting`?t.elapsed??0:0),e===`connecting`){let e=t.effort,n=t.thinkingBudget,r=15;n&&n>0?r=Math.max(15,Math.round(n/500)):e===`high`?r=30:e===`low`&&(r=10),m(r)}return}if(t.type===`connected`){S(!0),t.sessionTitle&&b(t.sessionTitle);return}if(t.type===`status`){S(!0);let e=t;e.sessionTitle&&b(e.sessionTitle),e.isStreaming&&(O.current=!0,c(!0)),e.pendingApproval&&g({requestId:e.pendingApproval.requestId,tool:e.pendingApproval.tool,input:e.pendingApproval.input}),j.current?.();return}let n=(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},r=()=>{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}]})};switch(t.type){case`account_info`:T.current={accountId:t.accountId,accountLabel:t.accountLabel};break;case`text`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}C.current+=t.content,w.current.push(t),r();break}case`thinking`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`tool_use`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`tool_result`:{let e=t.parentToolUseId;if(e&&n(t,e)){r();break}w.current.push(t),r();break}case`approval_request`:if(w.current.push(t),g({requestId:t.requestId,tool:t.tool,input:t.input}),M.current&&!Ee(M.current)){let e=t.tool===`AskUserQuestion`?`question`:`approval_request`;B.getState().addNotification(M.current,e,N.current),Te(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()}]}),O.current=!1,c(!1),u(`idle`);break}case`done`:{if(!O.current)break;t.contextWindowPct!=null&&v(t.contextWindowPct),M.current&&!Ee(M.current)&&(B.getState().addNotification(M.current,`done`,N.current),Te(`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,O.current=!1,c(!1),u(`idle`);break}}},[]),{send:F,connect:I}=ve({url:e&&n?`/ws/project/${encodeURIComponent(n)}/chat/${e}`:``,onMessage:P,autoConnect:!!e&&!!n});A.current=F,(0,J.useEffect)(()=>{let r=!1;return c(!1),g(null),C.current=``,w.current=[],S(!1),e&&n?(o(!0),fetch(`${E(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${D()}`}}).then(e=>e.json()).then(e=>{r||O.current||(e.ok&&Array.isArray(e.data)&&e.data.length>0?i(e.data):i([]))}).catch(()=>{!r&&!O.current&&i([])}).finally(()=>{r||o(!1)})):i([]),()=>{r=!0}},[e,t,n]);let L=(0,J.useCallback)((e,t)=>{if(e.trim()){if(O.current){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}),F(JSON.stringify({type:`cancel`}))}i(t=>[...t,{id:`user-${Date.now()}`,role:`user`,content:e,timestamp:new Date().toISOString()}]),C.current=``,w.current=[],k.current=null,O.current=!0,c(!0),u(`connecting`),g(null),F(JSON.stringify({type:`message`,content:e,permissionMode:t?.permissionMode}))}},[F]),R=(0,J.useCallback)((e,t,n)=>{if(F(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])}g(null)},[F]),z=(0,J.useCallback)(()=>{if(!O.current)return;F(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=[],k.current=null,O.current=!1,c(!1),g(null)},[F]),ee=(0,J.useCallback)(()=>{S(!1),I(),j.current?.()},[I]),te=(0,J.useCallback)(()=>{!e||!n||(o(!0),fetch(`${E(n)}/chat/sessions/${e}/messages?providerId=${t}`,{headers:{Authorization:`Bearer ${D()}`}}).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 j.current=te,{messages:r,messagesLoading:a,isStreaming:s,streamingStatus:l,connectingElapsed:d,thinkingWarningThreshold:p,pendingApproval:h,contextWindowPct:_,sessionTitle:y,sendMessage:L,respondToApproval:R,cancelStreaming:z,reconnect:ee,refetchMessages:te,isConnected:x}}var Oe=12e4;function ke(e,t=`claude`){let[n,r]=(0,J.useState)({}),[i,a]=(0,J.useState)(!1),[o,s]=(0,J.useState)(null),c=(0,J.useRef)(null),l=(0,J.useCallback)((n=!1)=>{if(!e)return;a(!0);let i=n?`&refresh=1`:``;fetch(`${E(e)}/chat/usage?providerId=${t}${i}`,{headers:{Authorization:`Bearer ${D()}`}}).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,J.useEffect)(()=>(l(),c.current=setInterval(()=>l(),Oe),()=>{c.current&&clearInterval(c.current)}),[l]),{usageInfo:n,usageLoading:i,lastFetchedAt:o,refreshUsage:(0,J.useCallback)(()=>l(!0),[l])}}var Ae={damping:.7,stiffness:.05,mass:1.25},je=70,Me=1e3/60,Ne=350,Pe=!1;globalThis.document?.addEventListener(`mousedown`,()=>{Pe=!0}),globalThis.document?.addEventListener(`mouseup`,()=>{Pe=!1}),globalThis.document?.addEventListener(`click`,()=>{Pe=!1});var Fe=(e={})=>{let[t,n]=(0,J.useState)(!1),[r,i]=(0,J.useState)(e.initial!==!1),[a,o]=(0,J.useState)(!1),s=(0,J.useRef)(null);s.current=e;let c=(0,J.useCallback)(()=>{if(!Pe)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,J.useCallback)(e=>{d.isAtBottom=e,i(e)},[]),u=(0,J.useCallback)(e=>{d.escapedFromLock=e,n(e)},[]),d=(0,J.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<=je}}},[]),f=(0,J.useCallback)((e={})=>{typeof e==`string`&&(e={animation:e}),e.preserveScrollPosition||l(!0);let t=Date.now()+(Number(e.wait)||0),n=Re(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))/Me;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:Re(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,J.useCallback)(()=>{u(!0),l(!1)},[u,l]),m=(0,J.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,J.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=Ie(e=>{g.current?.removeEventListener(`scroll`,m),g.current?.removeEventListener(`wheel`,h),e?.addEventListener(`scroll`,m,{passive:!0}),e?.addEventListener(`wheel`,h,{passive:!0})},[]),_=Ie(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=Re(s.current,t?s.current.resize:s.current.initial);f({animation:e,wait:!0,preserveScrollPosition:!0,duration:e===`instant`?void 0:Ne})}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 Ie(e,t){let n=(0,J.useCallback)(t=>(n.current=t,e(t)),t);return n}var Le=new Map;function Re(...e){let t={...Ae},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 Le.has(r)||Le.set(r,Object.freeze(t)),n?`instant`:Le.get(r)}var ze=(0,J.createContext)(null),Be=typeof window<`u`?J.useLayoutEffect:J.useEffect;function Ve({instance:e,children:t,resize:n,initial:r,mass:i,damping:a,stiffness:o,targetScrollTop:s,contextRef:c,...l}){let u=(0,J.useRef)(null),d=Fe({mass:i,damping:a,stiffness:o,resize:n,initial:r,targetScrollTop:J.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,J.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,J.useImperativeHandle)(c,()=>y,[y]),Be(()=>{f.current&&getComputedStyle(f.current).overflow===`visible`&&(f.current.style.overflow=`auto`)},[]),J.createElement(ze.Provider,{value:y},J.createElement(`div`,{...l},typeof t==`function`?t(y):t))}(function(e){function t({children:e,scrollClassName:t,...n}){let r=He();return J.createElement(`div`,{ref:r.scrollRef,style:{height:`100%`,width:`100%`,scrollbarGutter:`stable both-edges`},className:t},J.createElement(`div`,{...n,ref:r.contentRef},typeof e==`function`?e(r):e))}e.Content=t})(Ve||={});function He(){let e=(0,J.useContext)(ze);if(!e)throw Error(`use-stick-to-bottom component context must be used within a StickToBottom component`);return e}var X=s();function Ue(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 We({tool:e,result:t,completed:n,projectName:i}){let[a,o]=(0,J.useState)(!1);if(e.type===`error`)return(0,X.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,X.jsx)(z,{className:`size-3`}),(0,X.jsx)(`span`,{children:e.message})]});let{toolName:s,input:c}=Ue(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,X.jsxs)(`div`,{className:`rounded border text-xs ${f?`border-accent/30 bg-accent/5`:`border-border bg-background`}`,children:[(0,X.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,X.jsx)(r,{className:`size-3 shrink-0`}):(0,X.jsx)(P,{className:`size-3 shrink-0`}),u?(0,X.jsx)(U,{className:`size-3 text-red-400 shrink-0`}):l||d||n?(0,X.jsx)(A,{className:`size-3 text-green-400 shrink-0`}):(0,X.jsx)(k,{className:`size-3 text-yellow-400 shrink-0 animate-spin`}),(0,X.jsx)(`span`,{className:`truncate text-text-primary`,children:(0,X.jsx)(Ge,{name:s,input:c})}),m&&(0,X.jsxs)(`span`,{className:`ml-auto text-[10px] text-text-subtle shrink-0`,children:[p.length,` steps`]})]}),a&&(0,X.jsxs)(`div`,{className:`px-2 pb-2 space-y-1.5`,children:[(e.type===`tool_use`||e.type===`approval_request`)&&(0,X.jsx)(Ke,{name:s,input:c,projectName:i}),m&&(0,X.jsx)(Xe,{events:p,projectName:i}),l&&(0,X.jsx)(Je,{toolName:s,output:t.output})]})]})}function Ge({name:e,input:t}){let n=e=>String(e??``);switch(e){case`Read`:case`Write`:case`Edit`:case`MultiEdit`:case`NotebookEdit`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:T(n(t.file_path))})]});case`Bash`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.command),60)})]});case`Glob`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:n(t.pattern)})]});case`Grep`:return(0,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsx)(`span`,{className:`font-mono text-text-subtle`,children:Z(n(t.pattern),40)})]});case`WebSearch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`WebFetch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(oe,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.url),50)})]});case`ToolSearch`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(R,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(n(t.query),50)})]});case`Agent`:case`Task`:return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(H,{className:`size-3 inline`}),` `,e,` `,(0,X.jsx)(`span`,{className:`text-text-subtle`,children:Z(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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(K,{className:`size-3 inline`}),` `,e,` `,(0,X.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,X.jsxs)(X.Fragment,{children:[e,` `,(0,X.jsxs)(`span`,{className:`text-text-subtle`,children:[n.length,` question`,n.length===1?``:`s`,r?` ✓`:``]})]})}default:return(0,X.jsx)(X.Fragment,{children:e})}}function Ke({name:e,input:t,projectName:n}){let r=e=>String(e??``),{openTab:i}=S(),a=e=>{n&&i({type:`editor`,title:T(e),metadata:{filePath:e,projectName:n},projectId:n,closable:!0})},o=(e,t,r)=>{i({type:`git-diff`,title:`Diff ${T(e)}`,metadata:{filePath:e,projectName:n,original:t,modified:r},projectId:n??null,closable:!0})};switch(e){case`Bash`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,X.jsx)(`p`,{className:`text-text-subtle italic`,children:r(t.description)}),(0,X.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,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.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,X.jsx)(b,{className:`size-3 shrink-0`}),n]}),e===`Edit`&&(!!t.old_string||!!t.new_string)&&(0,X.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,X.jsx)(y,{className:`size-3 shrink-0`}),`View Diff`]}),e===`Write`&&!!t.content&&(0,X.jsx)(`pre`,{className:`font-mono text-text-subtle overflow-x-auto max-h-32 whitespace-pre-wrap`,children:Z(r(t.content),300)})]})}case`Glob`:return(0,X.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[r(t.pattern),t.path?` in ${r(t.path)}`:``]});case`Grep`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`p`,{className:`font-mono text-text-secondary`,children:[`/`,r(t.pattern),`/`]}),!!t.path&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`in `,r(t.path)]})]});case`TodoWrite`:return(0,X.jsx)(qe,{todos:t.todos??[]});case`Agent`:case`Task`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[!!t.description&&(0,X.jsx)(`p`,{className:`text-text-secondary font-medium`,children:r(t.description)}),!!t.subagent_type&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`Type: `,r(t.subagent_type)]}),!!t.prompt&&(0,X.jsx)(Ze,{content:r(t.prompt),maxHeight:`max-h-48`})]});case`ToolSearch`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsx)(`p`,{className:`font-mono text-text-secondary`,children:r(t.query)}),!!t.max_results&&(0,X.jsxs)(`p`,{className:`text-text-subtle`,children:[`Max results: `,r(t.max_results)]})]});case`WebFetch`:return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.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,X.jsx)(oe,{className:`size-3 shrink-0`}),r(t.url)]}),!!t.prompt&&(0,X.jsx)(`p`,{className:`text-text-subtle`,children:Z(r(t.prompt),100)})]});case`AskUserQuestion`:{let e=t.questions??[],n=t.answers??{};return(0,X.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`p`,{className:`text-text-primary font-medium`,children:[e.header?`${e.header}: `:``,e.question]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.options.map((t,r)=>(0,X.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,X.jsxs)(`p`,{className:`text-foreground text-xs`,children:[`Answer: `,n[e.question]]})]},t))})}default:return(0,X.jsx)(`pre`,{className:`overflow-x-auto text-text-secondary font-mono whitespace-pre-wrap break-all`,children:JSON.stringify(t,null,2)})}}function qe({todos:e}){return(0,X.jsx)(`div`,{className:`space-y-0.5`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.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,X.jsx)(`span`,{className:e.status===`completed`?`line-through text-text-subtle`:`text-text-secondary`,children:e.content})]},t))})}function Je({toolName:e,output:t}){let[n,r]=(0,J.useState)(!1),i=(0,J.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
3
 
4
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,X.jsxs)(`div`,{className:`border-t border-border pt-1.5 space-y-1`,children:[(0,X.jsx)(Ze,{content:i,maxHeight:`max-h-60`}),(0,X.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,X.jsx)(ae,{className:`size-3`}),n?`Hide`:`Show`,` raw`]}),n&&(0,X.jsx)(`pre`,{className:`overflow-x-auto text-text-subtle font-mono max-h-40 whitespace-pre-wrap break-all text-[10px]`,children:t})]}):(0,X.jsx)(Ye,{output:t})}function Ye({output:e}){let t=e.split(`
5
5
  `).length,n=t>3||e.length>200,[i,a]=(0,J.useState)(n);return(0,X.jsxs)(`div`,{className:`border-t border-border pt-1.5`,children:[n&&(0,X.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,X.jsx)(P,{className:`size-3`}):(0,X.jsx)(r,{className:`size-3`}),`Output (`,t,` lines)`]}),(0,X.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 Xe({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,X.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,X.jsx)(`div`,{className:`text-text-secondary text-[11px]`,children:(0,X.jsx)(Ze,{content:e.content,maxHeight:`max-h-24`})},`st-${n}`):(0,X.jsx)(We,{tool:e.tool,result:e.result,completed:!!e.result,projectName:t},`sc-${n}`))})}function Ze({content:e,maxHeight:t=`max-h-48`}){return(0,X.jsx)(V,{content:e,className:`text-text-secondary overflow-auto ${t}`})}function Z(e,t=50){return e?e.length>t?e.slice(0,t)+`…`:e:``}function Qe(e){let[t,n]=(0,J.useState)({}),[r,i]=(0,J.useState)({}),[a,o]=(0,J.useState)(0),s=(0,J.useCallback)((e,t)=>{n(n=>({...n,[e]:[t]})),i(t=>({...t,[e]:``}))},[]),c=(0,J.useCallback)((e,t)=>{n(n=>{let r=n[e]||[];return{...n,[e]:r.includes(t)?r.filter(e=>e!==t):[...r,t]}})},[]),l=(0,J.useCallback)((e,t)=>{i(n=>({...n,[e]:t})),t&&n(t=>({...t,[e]:[]}))},[]),u=(0,J.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,J.useMemo)(()=>e.every((e,t)=>u(t)),[e,u]),getFinalAnswer:(0,J.useCallback)(e=>r[e]?.trim()||(t[e]??[]).join(`, `),[t,r]),goToNextTab:(0,J.useCallback)(()=>o(t=>Math.min(t+1,e.length-1)),[e.length]),goToPrevTab:(0,J.useCallback)(()=>o(e=>Math.max(e-1,0)),[])}}function $e(e){let[t,n]=(0,J.useState)(0),r=(0,J.useRef)(null);return(0,J.useEffect)(()=>n(0),[e.activeTab]),(0,J.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 et({questions:e,onSubmit:t,onSkip:n}){let r=(0,J.useRef)(null),i=Qe(e),a=e[i.activeTab],o=a?a.options.length+1:0,s=e.length>1,c=(0,J.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,J.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=$e({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,J.useCallback)(e=>{l(e),u.setFocusedOption(e)},[l,u.setFocusedOption]);return(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between text-sm font-medium text-text-primary`,children:[(0,X.jsxs)(`span`,{children:[`AI has `,s?`${e.length} questions`:`a question`]}),(0,X.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,X.jsx)(`div`,{className:`flex gap-1 p-1 bg-background rounded-md overflow-x-auto border border-border`,children:e.map((e,t)=>(0,X.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,X.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,X.jsx)(`span`,{className:`max-w-[100px] overflow-hidden text-ellipsis`,children:e.header||`Q${t+1}`})]},t))}),a&&(0,X.jsxs)(`div`,{className:`space-y-2`,children:[!s&&a.header&&(0,X.jsx)(`div`,{className:`text-[11px] font-semibold uppercase tracking-wide text-text-secondary`,children:a.header}),(0,X.jsx)(`div`,{className:`text-sm text-text-primary`,children:a.question}),a.multiSelect&&(0,X.jsx)(`div`,{className:`text-[11px] text-text-secondary`,children:`Select multiple`}),(0,X.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,X.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,X.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,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 flex-1`,children:[(0,X.jsx)(`span`,{className:`font-medium text-text-primary`,children:e.label}),e.description&&(0,X.jsx)(`span`,{className:`text-[11px] text-text-secondary`,children:e.description})]})]},t)}),(0,X.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,X.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,X.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,X.jsxs)(`div`,{className:`flex gap-2 justify-end pt-1`,children:[s&&(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.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,X.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,X.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 tt({messages:e,messagesLoading:t,pendingApproval:n,onApprovalResponse:r,isStreaming:i,streamingStatus:a,connectingElapsed:o,thinkingWarningThreshold:s,projectName:c,onFork:l}){return t?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,X.jsx)(H,{className:`size-10 text-text-subtle animate-pulse`}),(0,X.jsx)(`p`,{className:`text-sm`,children:`Loading messages...`})]}):e.length===0&&!i?(0,X.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-text-secondary`,children:[(0,X.jsx)(H,{className:`size-10 text-text-subtle`}),(0,X.jsx)(`p`,{className:`text-sm`,children:`Send a message to start the conversation`})]}):(0,X.jsxs)(Ve,{className:`flex-1 overflow-y-auto`,resize:`smooth`,initial:`instant`,children:[(0,X.jsxs)(Ve.Content,{className:`p-4 space-y-4`,children:[e.filter(e=>{let t=e.content&&e.content.trim().length>0,n=e.events&&e.events.length>0;return t||n}).map(e=>(0,X.jsx)(rt,{message:e,isStreaming:i&&e.id.startsWith(`streaming-`),projectName:c,onFork:e.role===`user`&&l?()=>l(e.content):void 0},e.id)),n&&(n.tool===`AskUserQuestion`?(0,X.jsx)(yt,{approval:n,onRespond:r}):(0,X.jsx)(vt,{approval:n,onRespond:r})),i&&(0,X.jsx)(gt,{lastMessage:e[e.length-1],streamingStatus:a,elapsed:o,warningThreshold:s})]}),(0,X.jsx)(nt,{})]})}function nt(){let{isAtBottom:e,scrollToBottom:t}=He();return e?null:(0,X.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,X.jsx)(r,{className:`size-3`}),`Scroll to bottom`]})}function rt({message:e,isStreaming:t,projectName:n,onFork:r}){return e.role===`user`?(0,X.jsx)(ut,{content:e.content,projectName:n,onFork:r}):e.role===`system`?(0,X.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,X.jsx)(z,{className:`size-4 shrink-0`}),(0,X.jsx)(`p`,{children:e.content})]}):(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[e.events&&e.events.length>0?(0,X.jsx)(pt,{events:e.events,isStreaming:t,projectName:n}):e.content&&(0,X.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,X.jsx)(_t,{content:e.content,projectName:n})}),!t&&e.accountLabel&&(0,X.jsxs)(`p`,{className:`text-[10px] select-none`,style:{color:`var(--color-text-subtle)`},children:[`via `,e.accountLabel]})]})}var it=new Set([`.png`,`.jpg`,`.jpeg`,`.gif`,`.webp`]);function at(e){return e.replace(/<(system-reminder|available-deferred-tools|antml:[\w-]+|fast_mode_info|claudeMd|gitStatus|currentDate)[\s\S]*?<\/\1>/g,``).trim()}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 st(e,t){let n=T(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function ct(e){let t=e.lastIndexOf(`.`);return t===-1?!1:it.has(e.slice(t).toLowerCase())}function lt(e){return e.toLowerCase().endsWith(`.pdf`)}function ut({content:e,projectName:t,onFork:n}){let{files:r,text:i}=(0,J.useMemo)(()=>{let t=ot(e);return{files:t.files,text:at(t.text)}},[e]);return(0,X.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,X.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[r.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map((e,n)=>ct(e)?(0,X.jsx)(dt,{src:st(e,t),alt:T(e)||`image`},n):lt(e)?(0,X.jsx)(ft,{src:st(e,t),filename:T(e)||`document.pdf`,mimeType:`application/pdf`},n):(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,X.jsx)(L,{className:`size-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate max-w-40`,children:T(e)})]},n))}),i&&(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:i}),n&&(0,X.jsx)(`button`,{onClick:n,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,X.jsx)(a,{className:`size-3`})})]})})}function dt({src:e,alt:t}){let[n,r]=(0,J.useState)(null),[i,a]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{let t,n=D();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,X.jsx)(G,{className:`size-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,X.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,X.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,X.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function ft({src:e,filename:t,mimeType:n}){let[r,i]=(0,J.useState)(!1);return(0,X.jsxs)(`button`,{type:`button`,onClick:(0,J.useCallback)(async()=>{i(!0);try{let t=D(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,X.jsx)(L,{className:`size-3.5 shrink-0 text-red-400`}),(0,X.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,X.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function pt({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,X.jsx)(X.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,X.jsx)(mt,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,X.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,X.jsx)(ht,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,X.jsx)(We,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function mt({content:e,isStreaming:t}){let[n,r]=(0,J.useState)(t);return(0,J.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,X.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,X.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,X.jsx)(k,{className:`size-3 animate-spin`}):(0,X.jsx)(P,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,X.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,X.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,X.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 ht({content:e,animate:t,projectName:n}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_t,{content:e,projectName:n}),t&&(0,X.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function gt({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,X.jsx)(k,{className:`size-3 animate-spin`}),(0,X.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,X.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,X.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 _t({content:e,projectName:t}){return(0,X.jsx)(V,{content:e,projectName:t,codeActions:!0})}function vt({approval:e,onRespond:t}){return(0,X.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,X.jsx)(de,{className:`size-4`}),(0,X.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,X.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,X.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,X.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,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.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,X.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 yt({approval:e,onRespond:t}){return(0,X.jsx)(et,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}var bt=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),xt=new Set([`application/pdf`]),St=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Ct=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 wt(e){return bt.has(e.type)}function Tt(e){if(bt.has(e.type)||xt.has(e.type)||St.some(t=>e.type.startsWith(t)))return!0;let t=Et(e.name);return!!(t&&Ct.has(t))}function Et(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Dt({attachments:e,onRemove:t}){return e.length===0?null:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,X.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,X.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,X.jsx)(G,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,X.jsx)(L,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,X.jsx)(k,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,X.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,X.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,X.jsx)(n,{className:`size-3`})})]},e.id))})}var Q=[{id:`default`,label:`Ask before edits`,icon:se,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:ae,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:W,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:q,description:`Claude will not ask before running commands`}];function Ot(e){return Q.find(t=>t.id===e)?.label??`Unknown`}function kt(e){return Q.find(t=>t.id===e)?.icon??se}function At({value:e,onChange:t,open:n,onOpenChange:r}){let a=(0,J.useRef)(null),o=(0,J.useRef)(0);(0,J.useEffect)(()=>{if(!n)return;let e=e=>{a.current&&!a.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[n,r]),(0,J.useEffect)(()=>{n&&(o.current=Q.findIndex(t=>t.id===e),o.current<0&&(o.current=0))},[n,e]);let s=(0,J.useCallback)(e=>{if(e.key===`Escape`){r(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;o.current=(o.current+t+Q.length)%Q.length,(a.current?.querySelector(`[data-idx="${o.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=Q[o.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,X.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,X.jsx)(`div`,{className:`py-1`,children:Q.map((n,a)=>{let o=n.icon,s=n.id===e;return(0,X.jsxs)(`button`,{"data-idx":a,role:`option`,"aria-selected":s,tabIndex:0,onClick:()=>{t(n.id),r(!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,X.jsx)(o,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,X.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),s&&(0,X.jsx)(i,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}function jt(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Mt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,J.useState)(0),s=(0,J.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,J.useEffect)(()=>{o(0)},[t]),(0,J.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,J.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,J.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,X.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,X.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,X.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,X.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,X.jsx)(F,{className:`size-4 text-amber-500`}):(0,X.jsx)(I,{className:`size-4 text-blue-400`})}),(0,X.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}function Nt({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,permissionMode:p,onModeChange:m}){let[h,g]=(0,J.useState)(f??``),[_,v]=(0,J.useState)([]),[y,b]=(0,J.useState)(!1),x=(0,J.useRef)(null),S=(0,J.useRef)(null),C=(0,J.useRef)(null),T=(0,J.useRef)([]),k=(0,J.useRef)([]);(0,J.useEffect)(()=>{f&&(g(f),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[f]),(0,J.useEffect)(()=>{if(!i){T.current=[],o?.([]);return}O.get(`${E(i)}/chat/slash-items`).then(e=>{T.current=e,o?.(e)}).catch(()=>{T.current=[],o?.([])})},[i]),(0,J.useEffect)(()=>{if(!i){k.current=[],l?.([]);return}O.get(`${E(i)}/files/tree?depth=5`).then(e=>{let t=jt(e);k.current=t,l?.(t)}).catch(()=>{k.current=[],l?.([])})},[i]),(0,J.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??h.length,n=h.slice(0,t),r=h.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);g(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,J.useEffect)(()=>{if(!u)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=h.slice(0,t),r=h.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;g(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=h+`@${u.path} `;g(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,J.useEffect)(()=>{!d||d.length===0||j(d)},[d]);let A=(0,J.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=D();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${E(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]),j=(0,J.useCallback)(e=>{for(let t of e){if(!Tt(t)){g(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=w(),n=wt(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};v(e=>[...e,i]),A(t).then(t=>{v(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(S.current??x.current)?.focus()},[A]),M=(0,J.useCallback)(e=>{v(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),N=(0,J.useCallback)(()=>{let t=h.trim(),n=_.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),g(``);for(let e of _)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);v([]),x.current&&(x.current.style.height=`auto`),S.current&&(S.current.style.height=`auto`)}},[h,_,r,e,a,c]),P=(0,J.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),N();return}if(e.shiftKey&&e.key===`Tab`){e.preventDefault();let t=[`default`,`acceptEdits`,`plan`,`bypassPermissions`],n=t[(t.indexOf(p??`bypassPermissions`)+1)%t.length];m?.(n)}},[N,p,m]),F=(0,J.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&T.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&k.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),I=(0,J.useCallback)(e=>{g(e),setTimeout(()=>{F(e,x.current?.selectionStart??e.length)},0)},[F]),L=(0,J.useCallback)(e=>{let t=e?.target??x.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),R=(0,J.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(),j(n))},[j]),z=(0,J.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&j(t)},[j]),B=(0,J.useCallback)(e=>{e.preventDefault()},[]),ee=(0,J.useCallback)(()=>{C.current?.click()},[]),te=(0,J.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&j(t),e.target.value=``},[j]),ne=h.trim().length>0||_.some(e=>e.status===`ready`),V=t&&!ne;return(0,X.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,X.jsxs)(`div`,{className:`border border-border rounded-xl md:rounded-2xl bg-surface shadow-sm cursor-text`,onClick:()=>!r&&(S.current??x.current)?.focus(),children:[(0,X.jsx)(Dt,{attachments:_,onRemove:M}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,X.jsx)(Pt,{mode:p??`bypassPermissions`,onClick:()=>b(e=>!e)}),(0,X.jsx)(At,{value:p??`bypassPermissions`,onChange:e=>m?.(e),open:y,onOpenChange:b})]}),(0,X.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ee()},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,X.jsx)(le,{className:`size-4`})}),(0,X.jsx)(`textarea`,{ref:S,value:h,onChange:e=>{I(e.target.value),L(e)},onKeyDown:P,onPaste:R,onDrop:z,onDragOver:B,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`}),V?(0,X.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,X.jsx)(me,{className:`size-3`})}):(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),N()},disabled:r||!ne,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":`Send`,children:(0,X.jsx)(ie,{className:`size-3.5`})})]}),(0,X.jsxs)(`div`,{className:`hidden md:block`,children:[(0,X.jsx)(`textarea`,{ref:x,value:h,onChange:e=>{I(e.target.value),L(e)},onKeyDown:P,onPaste:R,onDrop:z,onDragOver:B,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,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ee()},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,X.jsx)(le,{className:`size-4`})}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Pt,{mode:p??`bypassPermissions`,onClick:()=>b(e=>!e)}),(0,X.jsx)(At,{value:p??`bypassPermissions`,onChange:e=>m?.(e),open:y,onOpenChange:b})]})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,X.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,X.jsx)(me,{className:`size-3.5`})}):(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),N()},disabled:r||!ne,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":`Send message`,children:(0,X.jsx)(ie,{className:`size-4`})})})]})]})]}),(0,X.jsx)(`input`,{ref:C,type:`file`,multiple:!0,className:`hidden`,onChange:te})]})}function Pt({mode:e,onClick:t}){let n=kt(e),r=Ot(e);return(0,X.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,X.jsx)(n,{className:`size-3`}),(0,X.jsx)(`span`,{className:`max-w-[100px] truncate`,children:r})]})}function Ft({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,J.useState)(0),s=(0,J.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,J.useEffect)(()=>{o(0)},[t]),(0,J.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,J.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,J.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,X.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,X.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,X.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,X.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,X.jsx)(pe,{className:`size-4 text-amber-500`}):(0,X.jsx)(j,{className:`size-4 text-blue-500`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,X.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,X.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function It(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Lt(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function Rt(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=Rt(t);return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,X.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full transition-all ${Lt(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,X.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${It(n)}`,children:[n,`%`]})]})]})}function zt(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 Bt({entry:e,isActive:t,accountInfo:n,onToggle:r,onVerify:i,verifyingId:a,onViewProfile:o,flash:s}){let{usage:c}=e,u=c.session||c.weekly||c.weeklyOpus||c.weeklySonnet,d=n?.status??e.accountStatus;return(0,X.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5 transition-colors duration-500 ${s?`bg-primary/10 border-primary/40`:``} ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),!e.isOAuth&&(0,X.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[o&&n?.profileData&&(0,X.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>o(n.profileData),title:`View profile`,children:(0,X.jsx)(l,{className:`size-3`})}),i&&(0,X.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-green-600 hover:bg-surface-elevated transition-colors`,onClick:()=>i(e.accountId),disabled:a===e.accountId,title:`Verify token`,children:a===e.accountId?(0,X.jsx)(k,{className:`size-3 animate-spin`}):(0,X.jsx)(fe,{className:`size-3`})}),r&&(0,X.jsx)(g,{checked:d!==`disabled`,onCheckedChange:()=>r(e.accountId,d),disabled:d===`cooldown`,className:`scale-[0.6] cursor-pointer`})]})]}),u?(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)($,{label:`5-Hour Session`,bucket:c.session}),(0,X.jsx)($,{label:`Weekly`,bucket:c.weekly}),(0,X.jsx)($,{label:`Weekly (Opus)`,bucket:c.weeklyOpus}),(0,X.jsx)($,{label:`Weekly (Sonnet)`,bucket:c.weeklySonnet})]}):(0,X.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),c.lastFetchedAt&&(0,X.jsxs)(`p`,{className:`text-[9px] text-text-subtle`,children:[`Updated: `,zt(new Date(c.lastFetchedAt).getTime())]})]})}function Vt({usage:e,visible:t,onClose:r,onReload:i,loading:a,lastFetchedAt:o}){let[s,c]=(0,J.useState)([]),[l,p]=(0,J.useState)([]),[m,g]=(0,J.useState)(null),[v,y]=(0,J.useState)(!0),[b,x]=(0,J.useState)(!1),[S,C]=(0,J.useState)(new Set),[w,T]=(0,J.useState)(null),[E,D]=(0,J.useState)(null),O=(0,J.useRef)([]);async function k(){let e=s.length>0;e?x(!0):y(!0);let[t,n,r]=await Promise.allSettled([_(),u(),f()]);if(t.status===`fulfilled`){let n=t.value;if(e&&O.current.length>0){let e=new Set,t=new Map(O.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&&(C(e),setTimeout(()=>C(new Set),1500))}O.current=n,c(n)}n.status===`fulfilled`&&p(n.value),r.status===`fulfilled`&&g(r.value?.id??null),y(!1),x(!1)}if((0,J.useEffect)(()=>{t&&k()},[t]),(0,J.useEffect)(()=>{!t||!o||k()},[o]),!t)return null;let A=new Map(l.map(e=>[e.id,e])),j=e.queryCostUsd!=null||e.totalCostUsd!=null,M=s.length>0;async function P(e,t){await h(e,{status:t===`disabled`?`active`:`disabled`}),k(),i?.()}async function F(e){T(e);try{await d(e),k()}catch{}T(null)}return(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage & Accounts`}),o&&(0,X.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:zt(new Date(o).getTime())})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,X.jsx)(`button`,{onClick:()=>{i(),k()},disabled:a||b,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,children:(0,X.jsx)(N,{className:`size-3 ${a||b?`animate-spin`:``}`})}),(0,X.jsx)(`button`,{onClick:r,className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:(0,X.jsx)(n,{className:`size-3`})})]})]}),M||v?(0,X.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-1.5`,children:v?(0,X.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):s.map(t=>(0,X.jsx)(Bt,{entry:t,isActive:t.accountId===(m??e.activeAccountId),accountInfo:A.get(t.accountId),onToggle:P,onVerify:F,verifyingId:w,onViewProfile:D,flash:S.has(t.accountId)},t.accountId))}):(0,X.jsx)(X.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,X.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,X.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,X.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,X.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,X.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,X.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),j&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,X.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,X.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]}),E&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Profile`}),(0,X.jsx)(`button`,{className:`text-text-subtle hover:text-foreground cursor-pointer`,onClick:()=>D(null),children:(0,X.jsx)(n,{className:`size-3`})})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-[70px_1fr] gap-x-2 gap-y-0.5 text-[10px]`,children:[E.account?.display_name&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Name`}),(0,X.jsx)(`span`,{children:E.account.display_name})]}),E.account?.email&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Email`}),(0,X.jsx)(`span`,{children:E.account.email})]}),E.organization?.name&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Org`}),(0,X.jsx)(`span`,{children:E.organization.name})]}),E.organization?.organization_type&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Type`}),(0,X.jsx)(`span`,{children:E.organization.organization_type})]}),E.organization?.rate_limit_tier&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Tier`}),(0,X.jsx)(`span`,{children:E.organization.rate_limit_tier})]}),E.organization?.subscription_status&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Status`}),(0,X.jsx)(`span`,{children:E.organization.subscription_status})]})]})]})]})}function Ht(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function Ut(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Wt({projectName:e,usageInfo:t,contextWindowPct:r,usageLoading:a,refreshUsage:o,lastFetchedAt:s,sessionId:l,onSelectSession:u,onBugReport:d,isConnected:f,onReconnect:m}){let[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)([]),[y,b]=(0,J.useState)(!1),x=B(e=>l?e.notifications.has(l):!1),C=B(e=>e.clearForSession),[w,T]=(0,J.useState)(``),[D,A]=(0,J.useState)(null),[j,P]=(0,J.useState)(``),F=(0,J.useRef)(null),I=S(e=>e.openTab),L=e=>{g(t=>t===e?null:e)},z=(0,J.useCallback)(async()=>{if(e){b(!0);try{v(await O.get(`${E(e)}/chat/sessions`))}catch{}finally{b(!1)}}},[e]);(0,J.useEffect)(()=>{h===`history`&&_.length===0&&z()},[h]);function ee(t){u?(u(t),g(null)):I({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let ne=(0,J.useCallback)((e,t)=>{t.stopPropagation(),A(e.id),P(e.title||``),setTimeout(()=>F.current?.select(),0)},[]),V=(0,J.useCallback)(async()=>{if(!D||!j.trim()||!e){A(null);return}try{await O.patch(`${E(e)}/chat/sessions/${D}`,{title:j.trim()}),v(e=>e.map(e=>e.id===D?{...e,title:j.trim()}:e))}catch{}A(null)},[D,j,e]),ie=(0,J.useCallback)(()=>A(null),[]),H=w.trim()?_.filter(e=>(e.title||``).toLowerCase().includes(w.toLowerCase())):_,U=t.fiveHour==null?null:Math.round(t.fiveHour*100),W=t.sevenDay==null?null:Math.round(t.sevenDay*100),ae=U!=null||W!=null?Ut(Math.max(U??0,W??0)):`text-text-subtle`;return(0,X.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,X.jsxs)(`button`,{onClick:()=>L(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${h===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,X.jsx)(ce,{className:`size-3`}),(0,X.jsx)(`span`,{children:`History`})]}),(0,X.jsx)(`button`,{onClick:()=>L(`config`),className:`p-1 rounded transition-colors ${h===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,X.jsx)(ue,{className:`size-3`})}),(0,X.jsxs)(`button`,{onClick:()=>L(`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 ${h===`usage`?`bg-primary/10`:``} ${ae}`,title:`Usage limits`,children:[(0,X.jsx)(re,{className:`size-3`}),t.activeAccountLabel&&(0,X.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[60px]`,children:[`[`,t.activeAccountLabel,`]`]}),(0,X.jsxs)(`span`,{children:[`5h:`,U==null?`--%`:`${U}%`]}),(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,X.jsxs)(`span`,{children:[`Wk:`,W==null?`--%`:`${W}%`]}),r!=null&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,X.jsxs)(`span`,{className:Ut(r),children:[`Ctx:`,r,`%`]})]})]}),(0,X.jsx)(`div`,{className:`flex-1`}),x&&l&&(0,X.jsx)(`button`,{onClick:()=>C(l),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,X.jsx)(c,{className:`size-3`})}),m&&(0,X.jsx)(`button`,{onClick:m,className:`size-4 flex items-center justify-center`,title:f?`Connected`:`Disconnected — click to reconnect`,children:(0,X.jsx)(`span`,{className:`size-2 rounded-full ${f?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),h===`history`&&(0,X.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,X.jsx)(R,{className:`size-3 text-text-subtle shrink-0`}),(0,X.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,X.jsx)(`button`,{onClick:z,disabled:y,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,X.jsx)(N,{className:`size-3 ${y?`animate-spin`:``}`})})]}),(0,X.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:y&&_.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,X.jsx)(k,{className:`size-3.5 animate-spin text-text-subtle`})}):H.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:w?`No matching sessions`:`No sessions yet`}):H.map(e=>(0,X.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,X.jsx)(te,{className:`size-3 shrink-0 text-text-subtle`}),D===e.id?(0,X.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),V()},children:[(0,X.jsx)(`input`,{ref:F,value:j,onChange:e=>P(e.target.value),onBlur:V,onKeyDown:e=>{e.key===`Escape`&&ie()},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,X.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,X.jsx)(i,{className:`size-3`})}),(0,X.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),ie()},children:(0,X.jsx)(n,{className:`size-3`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>ee(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,X.jsx)(`button`,{onClick:t=>ne(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,X.jsx)(M,{className:`size-3`})})]}),D!==e.id&&e.updatedAt&&(0,X.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Ht(e.updatedAt)})]},e.id))})]}),h===`config`&&(0,X.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,X.jsx)(p,{compact:!0})}),h===`usage`&&(0,X.jsx)(Vt,{usage:t,visible:!0,onClose:()=>g(null),onReload:o,loading:a,lastFetchedAt:s})]})}function Gt({metadata:e,tabId:t}){let[n,r]=(0,J.useState)(e?.sessionId??null),[i,a]=(0,J.useState)(e?.providerId??`claude`),[o,s]=(0,J.useState)([]),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(null),[h,g]=(0,J.useState)([]),[_,y]=(0,J.useState)(!1),[b,w]=(0,J.useState)(``),[T,D]=(0,J.useState)(null),[k,A]=(0,J.useState)(e?.permissionMode??void 0),[j,M]=(0,J.useState)(!1),[N,P]=(0,J.useState)(null),F=(0,J.useRef)(0),I=e?.projectName??``,L=S(e=>e.updateTab),R=C(e=>e.version),{usageInfo:z,usageLoading:te,lastFetchedAt:V,refreshUsage:re}=ke(I,i);(0,J.useEffect)(()=>{k||m().then(e=>{let t=e.providers[e.default_provider??`claude`];A(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,J.useEffect)(()=>{!t||!n||L(t,{metadata:{...e,sessionId:n,providerId:i,permissionMode:k}})},[n,i,k]);let{messages:ie,messagesLoading:H,isStreaming:U,streamingStatus:W,connectingElapsed:ae,thinkingWarningThreshold:oe,pendingApproval:se,contextWindowPct:ce,sessionTitle:G,sendMessage:K,respondToApproval:le,cancelStreaming:ue,reconnect:de,refetchMessages:fe,isConnected:q}=De(n,i,I);(0,J.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=x.getState();e[r]?.activeTabId===t&&B.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=x.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,J.useEffect)(()=>{t&&G&&L(t,{title:G})},[G]);let pe=(0,J.useRef)(e?.pendingMessage);(0,J.useEffect)(()=>{if(pe.current&&q&&n){let n=pe.current;pe.current=void 0,t&&L(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>K(n,{permissionMode:k}),100)}},[q,n]),(0,J.useCallback)(()=>{S.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:I},projectId:I||null,closable:!0})},[I]);let me=(0,J.useCallback)(e=>{r(e.id),a(e.providerId),t&&L(t,{title:e.title||`Chat`})},[t,L]),he=(0,J.useCallback)(async e=>{if(!(!n||!I))try{let{api:t,projectUrl:r}=await ee(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-TUmacMRS.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(I)}/chat/sessions/${n}/fork?providerId=${i}`);S.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:I,sessionId:a.id,providerId:i,pendingMessage:e},projectId:I||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,I,i]),ge=(0,J.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
6
+ `).map(e=>e.trim()).filter(Boolean),text:e.slice(n[0].length)}:{files:[],text:e}}function st(e,t){let n=T(e);return`/api/project/${encodeURIComponent(t??`_`)}/chat/uploads/${encodeURIComponent(n)}`}function ct(e){let t=e.lastIndexOf(`.`);return t===-1?!1:it.has(e.slice(t).toLowerCase())}function lt(e){return e.toLowerCase().endsWith(`.pdf`)}function ut({content:e,projectName:t,onFork:n}){let{files:r,text:i}=(0,J.useMemo)(()=>{let t=ot(e);return{files:t.files,text:at(t.text)}},[e]);return(0,X.jsx)(`div`,{className:`flex justify-end group/user`,children:(0,X.jsxs)(`div`,{className:`rounded-lg bg-primary/10 px-3 py-2 text-sm text-text-primary max-w-[85%] space-y-2 relative`,children:[r.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:r.map((e,n)=>ct(e)?(0,X.jsx)(dt,{src:st(e,t),alt:T(e)||`image`},n):lt(e)?(0,X.jsx)(ft,{src:st(e,t),filename:T(e)||`document.pdf`,mimeType:`application/pdf`},n):(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,X.jsx)(L,{className:`size-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate max-w-40`,children:T(e)})]},n))}),i&&(0,X.jsx)(`p`,{className:`whitespace-pre-wrap break-words`,children:i}),n&&(0,X.jsx)(`button`,{onClick:n,title:`Retry from this message (fork session)`,className:`absolute -left-8 top-1/2 -translate-y-1/2 opacity-0 group-hover/user:opacity-100 transition-opacity size-6 flex items-center justify-center rounded bg-surface border border-border text-text-subtle hover:text-text-primary hover:bg-surface-elevated`,children:(0,X.jsx)(a,{className:`size-3`})})]})})}function dt({src:e,alt:t}){let[n,r]=(0,J.useState)(null),[i,a]=(0,J.useState)(!1);return(0,J.useEffect)(()=>{let t,n=D();return fetch(e,{headers:n?{Authorization:`Bearer ${n}`}:{}}).then(e=>{if(!e.ok)throw Error(`Failed to load`);return e.blob()}).then(e=>{let n=URL.createObjectURL(e);t=n,r(n)}).catch(()=>a(!0)),()=>{t&&URL.revokeObjectURL(t)}},[e]),i?(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary`,children:[(0,X.jsx)(G,{className:`size-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate max-w-40`,children:t})]}):n?(0,X.jsx)(`a`,{href:n,target:`_blank`,rel:`noopener noreferrer`,className:`block`,children:(0,X.jsx)(`img`,{src:n,alt:t,className:`rounded-md max-h-48 max-w-full object-contain border border-border`})}):(0,X.jsx)(`div`,{className:`rounded-md bg-surface border border-border h-24 w-32 animate-pulse`})}function ft({src:e,filename:t,mimeType:n}){let[r,i]=(0,J.useState)(!1);return(0,X.jsxs)(`button`,{type:`button`,onClick:(0,J.useCallback)(async()=>{i(!0);try{let t=D(),r=await fetch(e,{headers:t?{Authorization:`Bearer ${t}`}:{}});if(!r.ok)throw Error(`Failed to load`);let i=await r.blob(),a=URL.createObjectURL(new Blob([i],{type:n}));window.open(a,`_blank`),setTimeout(()=>URL.revokeObjectURL(a),6e4)}catch{window.open(e,`_blank`)}finally{i(!1)}},[e,n]),disabled:r,className:`flex items-center gap-1.5 rounded-md border border-border bg-background/50 px-2 py-1 text-xs text-text-secondary hover:bg-surface hover:text-text-primary transition-colors cursor-pointer disabled:opacity-50`,children:[(0,X.jsx)(L,{className:`size-3.5 shrink-0 text-red-400`}),(0,X.jsx)(`span`,{className:`truncate max-w-40`,children:t}),r&&(0,X.jsx)(`span`,{className:`animate-spin text-[10px]`,children:`...`})]})}function pt({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,X.jsx)(X.Fragment,{children:r.map((e,i)=>{if(e.kind===`thinking`)return(0,X.jsx)(mt,{content:e.content,isStreaming:t&&i===r.length-1},`think-${i}`);if(e.kind===`text`){let a=t&&i===r.length-1;return(0,X.jsx)(`div`,{className:`text-sm text-text-primary`,children:(0,X.jsx)(ht,{content:e.content,animate:a,projectName:n})},`text-${i}`)}return(0,X.jsx)(We,{tool:e.tool,result:e.result,completed:e.completed,projectName:n},`tool-${i}`)})})}function mt({content:e,isStreaming:t}){let[n,r]=(0,J.useState)(t);return(0,J.useEffect)(()=>{!t&&e.length>0&&r(!1)},[t,e.length]),(0,X.jsxs)(`div`,{className:`rounded border border-border/50 bg-surface/30 text-xs`,children:[(0,X.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,X.jsx)(k,{className:`size-3 animate-spin`}):(0,X.jsx)(P,{className:`size-3 transition-transform ${n?`rotate-90`:``}`}),(0,X.jsxs)(`span`,{children:[`Thinking`,t?`...`:``]}),!t&&(0,X.jsx)(`span`,{className:`text-text-subtle/50 ml-auto`,children:e.length>100?`${Math.round(e.length/4)} tokens`:``})]}),n&&(0,X.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 ht({content:e,animate:t,projectName:n}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_t,{content:e,projectName:n}),t&&(0,X.jsx)(`span`,{className:`text-text-subtle text-sm animate-pulse`,children:`Thinking...`})]})}function gt({lastMessage:e,streamingStatus:t,elapsed:n,warningThreshold:r=15}){let i=!e||e.role!==`assistant`,a=e?.events?.length?e.events[e.events.length-1].type===`tool_result`:!1;return!i&&!a?null:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-text-subtle`,children:[(0,X.jsx)(k,{className:`size-3 animate-spin`}),(0,X.jsxs)(`span`,{children:[`Thinking`,i&&(n??0)>0&&(0,X.jsxs)(`span`,{className:`text-text-subtle/60`,children:[`... (`,n,`s)`]})]})]}),i&&(n??0)>=r&&(0,X.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 _t({content:e,projectName:t}){return(0,X.jsx)(V,{content:e,projectName:t,codeActions:!0})}function vt({approval:e,onRespond:t}){return(0,X.jsxs)(`div`,{className:`rounded-lg border-2 border-yellow-500/40 bg-yellow-500/10 p-3 space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-yellow-400 text-sm font-medium`,children:[(0,X.jsx)(de,{className:`size-4`}),(0,X.jsx)(`span`,{children:`Tool Approval Required`})]}),(0,X.jsx)(`div`,{className:`text-xs text-text-primary`,children:(0,X.jsx)(`span`,{className:`font-medium`,children:e.tool})}),(0,X.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,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.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,X.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 yt({approval:e,onRespond:t}){return(0,X.jsx)(et,{questions:e.input.questions??[],onSubmit:n=>t(e.requestId,!0,n),onSkip:()=>t(e.requestId,!1)})}var bt=new Set([`image/png`,`image/jpeg`,`image/gif`,`image/webp`]),xt=new Set([`application/pdf`]),St=[`text/`,`application/json`,`application/xml`,`application/javascript`,`application/typescript`,`application/x-yaml`,`application/toml`,`application/x-sh`],Ct=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 wt(e){return bt.has(e.type)}function Tt(e){if(bt.has(e.type)||xt.has(e.type)||St.some(t=>e.type.startsWith(t)))return!0;let t=Et(e.name);return!!(t&&Ct.has(t))}function Et(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t).toLowerCase()}function Dt({attachments:e,onRemove:t}){return e.length===0?null:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5 px-2 md:px-4 pt-2`,children:e.map(e=>(0,X.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,X.jsx)(`img`,{src:e.previewUrl,alt:e.name,className:`size-5 rounded object-cover shrink-0`}):e.isImage?(0,X.jsx)(G,{className:`size-3.5 shrink-0 text-text-subtle`}):(0,X.jsx)(L,{className:`size-3.5 shrink-0 text-text-subtle`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.name}),e.status===`uploading`?(0,X.jsx)(k,{className:`size-3 shrink-0 animate-spin text-text-subtle`}):e.status===`error`?(0,X.jsx)(`span`,{className:`text-red-500 shrink-0`,title:`Upload failed`,children:`!`}):null,(0,X.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,X.jsx)(n,{className:`size-3`})})]},e.id))})}var Q=[{id:`default`,label:`Ask before edits`,icon:se,description:`Claude will ask for approval before making each edit`},{id:`acceptEdits`,label:`Edit automatically`,icon:ae,description:`Claude will edit files without asking first`},{id:`plan`,label:`Plan mode`,icon:W,description:`Claude will present a plan before editing`},{id:`bypassPermissions`,label:`Bypass permissions`,icon:q,description:`Claude will not ask before running commands`}];function Ot(e){return Q.find(t=>t.id===e)?.label??`Unknown`}function kt(e){return Q.find(t=>t.id===e)?.icon??se}function At({value:e,onChange:t,open:n,onOpenChange:r}){let a=(0,J.useRef)(null),o=(0,J.useRef)(0);(0,J.useEffect)(()=>{if(!n)return;let e=e=>{a.current&&!a.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[n,r]),(0,J.useEffect)(()=>{n&&(o.current=Q.findIndex(t=>t.id===e),o.current<0&&(o.current=0))},[n,e]);let s=(0,J.useCallback)(e=>{if(e.key===`Escape`){r(!1);return}if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=e.key===`ArrowDown`?1:-1;o.current=(o.current+t+Q.length)%Q.length,(a.current?.querySelector(`[data-idx="${o.current}"]`))?.focus()}if(e.key===`Enter`){e.preventDefault();let n=Q[o.current];n&&(t(n.id),r(!1))}},[t,r]);return n?(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-border`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-text-secondary`,children:`Modes`}),(0,X.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,X.jsx)(`div`,{className:`py-1`,children:Q.map((n,a)=>{let o=n.icon,s=n.id===e;return(0,X.jsxs)(`button`,{"data-idx":a,role:`option`,"aria-selected":s,tabIndex:0,onClick:()=>{t(n.id),r(!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,X.jsx)(o,{className:`size-4 mt-0.5 shrink-0 text-text-secondary`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-text-primary`,children:n.label}),(0,X.jsx)(`div`,{className:`text-xs text-text-subtle leading-snug`,children:n.description})]}),s&&(0,X.jsx)(i,{className:`size-4 mt-0.5 shrink-0 text-primary`})]},n.id)})})]}):null}function jt(e){let t=[];function n(e){for(let r of e)t.push(r),r.children&&n(r.children)}return n(e),t}function Mt({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,J.useState)(0),s=(0,J.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,J.useEffect)(()=>{o(0)},[t]),(0,J.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,J.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,J.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,X.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,X.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,X.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,X.jsx)(`span`,{className:`shrink-0`,children:e.type===`directory`?(0,X.jsx)(F,{className:`size-4 text-amber-500`}):(0,X.jsx)(I,{className:`size-4 text-blue-400`})}),(0,X.jsx)(`span`,{className:`text-sm truncate`,children:e.path})]},e.path))})})}var Nt=(0,J.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,permissionMode:p,onModeChange:m}){let[h,g]=(0,J.useState)(f??``),[_,v]=(0,J.useState)([]),[y,b]=(0,J.useState)(!1),x=(0,J.useRef)(null),S=(0,J.useRef)(null),C=(0,J.useRef)(null),T=(0,J.useRef)([]),k=(0,J.useRef)([]);(0,J.useEffect)(()=>{f&&(g(f),setTimeout(()=>{let e=x.current;e&&(e.focus(),e.selectionStart=e.selectionEnd=e.value.length)},50))},[f]),(0,J.useEffect)(()=>{if(!i){T.current=[],o?.([]);return}O.get(`${E(i)}/chat/slash-items`).then(e=>{T.current=e,o?.(e)}).catch(()=>{T.current=[],o?.([])})},[i]),(0,J.useEffect)(()=>{if(!i){k.current=[],l?.([]);return}O.get(`${E(i)}/files/tree?depth=5`).then(e=>{let t=jt(e);k.current=t,l?.(t)}).catch(()=>{k.current=[],l?.([])})},[i]),(0,J.useEffect)(()=>{if(!s)return;let e=x.current,t=e?.selectionStart??h.length,n=h.slice(0,t),r=h.slice(t),i=n.replace(/(?:^|\s)\/\S*$/,e=>`${e.startsWith(`/`)?``:e[0]}/${s.name} `);g(i+r),a?.(!1,``),c?.(!1,``),e&&(e.focus(),setTimeout(()=>{e.selectionStart=e.selectionEnd=i.length},0))},[s]),(0,J.useEffect)(()=>{if(!u)return;let e=x.current;if(!e)return;let t=e.selectionStart,n=h.slice(0,t),r=h.slice(t),i=n.match(/@(\S*)$/);if(i){let t=n.length-i[0].length;g(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=h+`@${u.path} `;g(t),setTimeout(()=>{e.selectionStart=e.selectionEnd=t.length,e.focus()},0)}c?.(!1,``)},[u]),(0,J.useEffect)(()=>{!d||d.length===0||j(d)},[d]);let A=(0,J.useCallback)(async e=>{if(!i)return null;try{let t=new FormData;t.append(`files`,e);let n={},r=D();r&&(n.Authorization=`Bearer ${r}`);let a=await(await fetch(`${E(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]),j=(0,J.useCallback)(e=>{for(let t of e){if(!Tt(t)){g(e=>e+(e.length>0&&!e.endsWith(` `)?` `:``)+t.name);continue}let e=w(),n=wt(t),r=n?URL.createObjectURL(t):void 0,i={id:e,name:t.name,file:t,isImage:n,previewUrl:r,status:`uploading`};v(e=>[...e,i]),A(t).then(t=>{v(n=>n.map(n=>n.id===e?{...n,serverPath:t??void 0,status:t?`ready`:`error`}:n))})}(S.current??x.current)?.focus()},[A]),M=(0,J.useCallback)(e=>{v(t=>{let n=t.find(t=>t.id===e);return n?.previewUrl&&URL.revokeObjectURL(n.previewUrl),t.filter(t=>t.id!==e)})},[]),N=(0,J.useCallback)(()=>{let t=h.trim(),n=_.filter(e=>e.status===`ready`);if(!(!t&&n.length===0)&&!r){a?.(!1,``),c?.(!1,``),e(t,n),g(``);for(let e of _)e.previewUrl&&URL.revokeObjectURL(e.previewUrl);v([]),x.current&&(x.current.style.height=`auto`),S.current&&(S.current.style.height=`auto`)}},[h,_,r,e,a,c]),P=(0,J.useCallback)(e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),N();return}if(e.shiftKey&&e.key===`Tab`){e.preventDefault();let t=[`default`,`acceptEdits`,`plan`,`bypassPermissions`],n=t[(t.indexOf(p??`bypassPermissions`)+1)%t.length];m?.(n)}},[N,p,m]),F=(0,J.useCallback)((e,t)=>{let n=e.slice(0,t),r=n.match(/(?:^|\s)\/(\S*)$/);if(r&&T.current.length>0){a?.(!0,r[1]??``),c?.(!1,``);return}let i=n.match(/@(\S*)$/);if(i&&k.current.length>0){c?.(!0,i[1]??``),a?.(!1,``);return}a?.(!1,``),c?.(!1,``)},[a,c]),I=(0,J.useCallback)((e,t)=>{g(e),F(e,t)},[F]),L=(0,J.useCallback)(e=>{let t=e?.target??x.current;t&&(t.style.height=`auto`,t.style.height=Math.min(t.scrollHeight,160)+`px`)},[]),R=(0,J.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(),j(n))},[j]),z=(0,J.useCallback)(e=>{e.preventDefault();let t=Array.from(e.dataTransfer.files);t.length>0&&j(t)},[j]),B=(0,J.useCallback)(e=>{e.preventDefault()},[]),ee=(0,J.useCallback)(()=>{C.current?.click()},[]),te=(0,J.useCallback)(e=>{let t=Array.from(e.target.files??[]);t.length>0&&j(t),e.target.value=``},[j]),ne=h.trim().length>0||_.some(e=>e.status===`ready`),V=t&&!ne;return(0,X.jsxs)(`div`,{className:`p-2 md:p-3 bg-background`,children:[(0,X.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?x.current:S.current)?.focus()},children:[(0,X.jsx)(Dt,{attachments:_,onRemove:M}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pt-2 md:hidden relative`,children:[(0,X.jsx)(Pt,{mode:p??`bypassPermissions`,onClick:()=>b(e=>!e)}),(0,X.jsx)(At,{value:p??`bypassPermissions`,onChange:e=>m?.(e),open:y,onOpenChange:b})]}),(0,X.jsxs)(`div`,{className:`flex items-end gap-1 md:hidden px-2 py-2`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ee()},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,X.jsx)(le,{className:`size-4`})}),(0,X.jsx)(`textarea`,{ref:S,value:h,onChange:e=>{I(e.target.value,e.target.selectionStart),L(e)},onKeyDown:P,onPaste:R,onDrop:z,onDragOver:B,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`}),V?(0,X.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,X.jsx)(me,{className:`size-3`})}):(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),N()},disabled:r||!ne,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":`Send`,children:(0,X.jsx)(ie,{className:`size-3.5`})})]}),(0,X.jsxs)(`div`,{className:`hidden md:block`,children:[(0,X.jsx)(`textarea`,{ref:x,value:h,onChange:e=>{I(e.target.value,e.target.selectionStart),L(e)},onKeyDown:P,onPaste:R,onDrop:z,onDragOver:B,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,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 pb-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),ee()},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,X.jsx)(le,{className:`size-4`})}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Pt,{mode:p??`bypassPermissions`,onClick:()=>b(e=>!e)}),(0,X.jsx)(At,{value:p??`bypassPermissions`,onChange:e=>m?.(e),open:y,onOpenChange:b})]})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:V?(0,X.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,X.jsx)(me,{className:`size-3.5`})}):(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),N()},disabled:r||!ne,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":`Send message`,children:(0,X.jsx)(ie,{className:`size-4`})})})]})]})]}),(0,X.jsx)(`input`,{ref:C,type:`file`,multiple:!0,className:`hidden`,onChange:te})]})});function Pt({mode:e,onClick:t}){let n=kt(e),r=Ot(e);return(0,X.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,X.jsx)(n,{className:`size-3`}),(0,X.jsx)(`span`,{className:`max-w-[100px] truncate`,children:r})]})}function Ft({items:e,filter:t,onSelect:n,onClose:r,visible:i}){let[a,o]=(0,J.useState)(0),s=(0,J.useRef)(null),c=e.filter(e=>{let n=t.toLowerCase();return e.name.toLowerCase().includes(n)||e.description.toLowerCase().includes(n)});(0,J.useEffect)(()=>{o(0)},[t]),(0,J.useEffect)(()=>{let e=s.current;e&&e.children[a]?.scrollIntoView({block:`nearest`})},[a]);let l=(0,J.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,J.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,X.jsx)(`div`,{className:`max-h-52 overflow-y-auto border-b border-border bg-surface`,children:(0,X.jsx)(`div`,{ref:s,className:`py-1`,children:c.map((e,t)=>(0,X.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,X.jsx)(`span`,{className:`shrink-0 mt-0.5`,children:e.type===`skill`?(0,X.jsx)(pe,{className:`size-4 text-amber-500`}):(0,X.jsx)(j,{className:`size-4 text-blue-500`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-medium text-sm`,children:[`/`,e.name]}),e.argumentHint&&(0,X.jsx)(`span`,{className:`text-xs text-text-subtle`,children:e.argumentHint}),(0,X.jsx)(`span`,{className:`text-xs text-text-subtle capitalize ml-auto`,children:e.scope===`user`?`global`:e.type})]}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-text-subtle mt-0.5 line-clamp-2`,children:e.description})]})]},`${e.type}-${e.name}`))})})}function It(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Lt(e){return e>=90?`bg-red-500`:e>=70?`bg-amber-500`:`bg-green-500`}function Rt(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=Rt(t);return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-text-primary`,children:e}),r&&(0,X.jsxs)(`span`,{className:`text-[10px] text-text-subtle`,children:[`↻ `,r]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`flex-1 h-2 rounded-full bg-border overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full rounded-full transition-all ${Lt(n)}`,style:{width:`${Math.min(n,100)}%`}})}),(0,X.jsxs)(`span`,{className:`text-xs font-medium tabular-nums w-10 text-right ${It(n)}`,children:[n,`%`]})]})]})}function zt(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 Bt({entry:e,isActive:t,accountInfo:n,onToggle:r,onVerify:i,verifyingId:a,onViewProfile:o,flash:s}){let{usage:c}=e,u=c.session||c.weekly||c.weeklyOpus||c.weeklySonnet,d=n?.status??e.accountStatus;return(0,X.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5 transition-colors duration-500 ${s?`bg-primary/10 border-primary/40`:``} ${t?`border-primary/30 bg-primary/5`:`border-border/50`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium truncate flex-1 min-w-0`,children:e.accountLabel??e.accountId.slice(0,8)}),!e.isOAuth&&(0,X.jsx)(`span`,{className:`text-[9px] text-text-subtle shrink-0`,children:`API key`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[o&&n?.profileData&&(0,X.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-foreground hover:bg-surface-elevated transition-colors`,onClick:()=>o(n.profileData),title:`View profile`,children:(0,X.jsx)(l,{className:`size-3`})}),i&&(0,X.jsx)(`button`,{className:`p-1 rounded cursor-pointer text-text-subtle hover:text-green-600 hover:bg-surface-elevated transition-colors`,onClick:()=>i(e.accountId),disabled:a===e.accountId,title:`Verify token`,children:a===e.accountId?(0,X.jsx)(k,{className:`size-3 animate-spin`}):(0,X.jsx)(fe,{className:`size-3`})}),r&&(0,X.jsx)(g,{checked:d!==`disabled`,onCheckedChange:()=>r(e.accountId,d),disabled:d===`cooldown`,className:`scale-[0.6] cursor-pointer`})]})]}),u?(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)($,{label:`5-Hour Session`,bucket:c.session}),(0,X.jsx)($,{label:`Weekly`,bucket:c.weekly}),(0,X.jsx)($,{label:`Weekly (Opus)`,bucket:c.weeklyOpus}),(0,X.jsx)($,{label:`Weekly (Sonnet)`,bucket:c.weeklySonnet})]}):(0,X.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:e.isOAuth?`No usage data yet`:`Usage tracking not available for API keys`}),c.lastFetchedAt&&(0,X.jsxs)(`p`,{className:`text-[9px] text-text-subtle`,children:[`Updated: `,zt(new Date(c.lastFetchedAt).getTime())]})]})}function Vt({usage:e,visible:t,onClose:r,onReload:i,loading:a,lastFetchedAt:o}){let[s,c]=(0,J.useState)([]),[l,p]=(0,J.useState)([]),[m,g]=(0,J.useState)(null),[v,y]=(0,J.useState)(!0),[b,x]=(0,J.useState)(!1),[S,C]=(0,J.useState)(new Set),[w,T]=(0,J.useState)(null),[E,D]=(0,J.useState)(null),O=(0,J.useRef)([]);async function k(){let e=s.length>0;e?x(!0):y(!0);let[t,n,r]=await Promise.allSettled([_(),u(),f()]);if(t.status===`fulfilled`){let n=t.value;if(e&&O.current.length>0){let e=new Set,t=new Map(O.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&&(C(e),setTimeout(()=>C(new Set),1500))}O.current=n,c(n)}n.status===`fulfilled`&&p(n.value),r.status===`fulfilled`&&g(r.value?.id??null),y(!1),x(!1)}if((0,J.useEffect)(()=>{t&&k()},[t]),(0,J.useEffect)(()=>{!t||!o||k()},[o]),!t)return null;let A=new Map(l.map(e=>[e.id,e])),j=e.queryCostUsd!=null||e.totalCostUsd!=null,M=s.length>0;async function P(e,t){await h(e,{status:t===`disabled`?`active`:`disabled`}),k(),i?.()}async function F(e){T(e);try{await d(e),k()}catch{}T(null)}return(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-semibold text-text-primary`,children:`Usage & Accounts`}),o&&(0,X.jsx)(`span`,{className:`text-[10px] text-text-subtle`,children:zt(new Date(o).getTime())})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i&&(0,X.jsx)(`button`,{onClick:()=>{i(),k()},disabled:a||b,className:`text-xs text-text-subtle hover:text-text-primary px-1 disabled:opacity-50 cursor-pointer`,title:`Refresh`,children:(0,X.jsx)(N,{className:`size-3 ${a||b?`animate-spin`:``}`})}),(0,X.jsx)(`button`,{onClick:r,className:`text-xs text-text-subtle hover:text-text-primary px-1 cursor-pointer`,children:(0,X.jsx)(n,{className:`size-3`})})]})]}),M||v?(0,X.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-1.5`,children:v?(0,X.jsx)(`p`,{className:`text-[10px] text-text-subtle`,children:`Loading...`}):s.map(t=>(0,X.jsx)(Bt,{entry:t,isActive:t.accountId===(m??e.activeAccountId),accountInfo:A.get(t.accountId),onToggle:P,onVerify:F,verifyingId:w,onViewProfile:D,flash:S.has(t.accountId)},t.accountId))}):(0,X.jsx)(X.Fragment,{children:e.session||e.weekly||e.weeklyOpus||e.weeklySonnet?(0,X.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,X.jsx)($,{label:`5-Hour Session`,bucket:e.session}),(0,X.jsx)($,{label:`Weekly`,bucket:e.weekly}),(0,X.jsx)($,{label:`Weekly (Opus)`,bucket:e.weeklyOpus}),(0,X.jsx)($,{label:`Weekly (Sonnet)`,bucket:e.weeklySonnet})]}):(0,X.jsx)(`p`,{className:`text-xs text-text-subtle`,children:`No usage data available`})}),j&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[e.queryCostUsd!=null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Last query`}),(0,X.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.queryCostUsd.toFixed(4)]})]}),e.totalCostUsd!=null&&(0,X.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Session total`}),(0,X.jsxs)(`span`,{className:`text-text-primary font-medium tabular-nums`,children:[`$`,e.totalCostUsd.toFixed(4)]})]})]}),E&&(0,X.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-medium text-text-subtle`,children:`Profile`}),(0,X.jsx)(`button`,{className:`text-text-subtle hover:text-foreground cursor-pointer`,onClick:()=>D(null),children:(0,X.jsx)(n,{className:`size-3`})})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-[70px_1fr] gap-x-2 gap-y-0.5 text-[10px]`,children:[E.account?.display_name&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Name`}),(0,X.jsx)(`span`,{children:E.account.display_name})]}),E.account?.email&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Email`}),(0,X.jsx)(`span`,{children:E.account.email})]}),E.organization?.name&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Org`}),(0,X.jsx)(`span`,{children:E.organization.name})]}),E.organization?.organization_type&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Type`}),(0,X.jsx)(`span`,{children:E.organization.organization_type})]}),E.organization?.rate_limit_tier&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Tier`}),(0,X.jsx)(`span`,{children:E.organization.rate_limit_tier})]}),E.organization?.subscription_status&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`Status`}),(0,X.jsx)(`span`,{children:E.organization.subscription_status})]})]})]})]})}function Ht(e){try{return new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}catch{return``}}function Ut(e){return e>=90?`text-red-500`:e>=70?`text-amber-500`:`text-green-500`}function Wt({projectName:e,usageInfo:t,contextWindowPct:r,usageLoading:a,refreshUsage:o,lastFetchedAt:s,sessionId:l,onSelectSession:u,onBugReport:d,isConnected:f,onReconnect:m}){let[h,g]=(0,J.useState)(null),[_,v]=(0,J.useState)([]),[y,b]=(0,J.useState)(!1),x=B(e=>l?e.notifications.has(l):!1),C=B(e=>e.clearForSession),[w,T]=(0,J.useState)(``),[D,A]=(0,J.useState)(null),[j,P]=(0,J.useState)(``),F=(0,J.useRef)(null),I=S(e=>e.openTab),L=e=>{g(t=>t===e?null:e)},z=(0,J.useCallback)(async()=>{if(e){b(!0);try{v(await O.get(`${E(e)}/chat/sessions`))}catch{}finally{b(!1)}}},[e]);(0,J.useEffect)(()=>{h===`history`&&_.length===0&&z()},[h]);function ee(t){u?(u(t),g(null)):I({type:`chat`,title:t.title||`Chat`,projectId:e??null,metadata:{projectName:e,sessionId:t.id},closable:!0})}let ne=(0,J.useCallback)((e,t)=>{t.stopPropagation(),A(e.id),P(e.title||``),setTimeout(()=>F.current?.select(),0)},[]),V=(0,J.useCallback)(async()=>{if(!D||!j.trim()||!e){A(null);return}try{await O.patch(`${E(e)}/chat/sessions/${D}`,{title:j.trim()}),v(e=>e.map(e=>e.id===D?{...e,title:j.trim()}:e))}catch{}A(null)},[D,j,e]),ie=(0,J.useCallback)(()=>A(null),[]),H=w.trim()?_.filter(e=>(e.title||``).toLowerCase().includes(w.toLowerCase())):_,U=t.fiveHour==null?null:Math.round(t.fiveHour*100),W=t.sevenDay==null?null:Math.round(t.sevenDay*100),ae=U!=null||W!=null?Ut(Math.max(U??0,W??0)):`text-text-subtle`;return(0,X.jsxs)(`div`,{className:`border-b border-border/50`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1`,children:[(0,X.jsxs)(`button`,{onClick:()=>L(`history`),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[11px] transition-colors ${h===`history`?`text-primary bg-primary/10`:`text-text-secondary hover:text-foreground hover:bg-surface-elevated`}`,children:[(0,X.jsx)(ce,{className:`size-3`}),(0,X.jsx)(`span`,{children:`History`})]}),(0,X.jsx)(`button`,{onClick:()=>L(`config`),className:`p-1 rounded transition-colors ${h===`config`?`text-primary bg-primary/10`:`text-text-subtle hover:text-text-secondary hover:bg-surface-elevated`}`,title:`AI Settings`,children:(0,X.jsx)(ue,{className:`size-3`})}),(0,X.jsxs)(`button`,{onClick:()=>L(`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 ${h===`usage`?`bg-primary/10`:``} ${ae}`,title:`Usage limits`,children:[(0,X.jsx)(re,{className:`size-3`}),t.activeAccountLabel&&(0,X.jsxs)(`span`,{className:`text-text-secondary font-normal truncate max-w-[60px]`,children:[`[`,t.activeAccountLabel,`]`]}),(0,X.jsxs)(`span`,{children:[`5h:`,U==null?`--%`:`${U}%`]}),(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,X.jsxs)(`span`,{children:[`Wk:`,W==null?`--%`:`${W}%`]}),r!=null&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-text-subtle`,children:`·`}),(0,X.jsxs)(`span`,{className:Ut(r),children:[`Ctx:`,r,`%`]})]})]}),(0,X.jsx)(`div`,{className:`flex-1`}),x&&l&&(0,X.jsx)(`button`,{onClick:()=>C(l),className:`p-1 rounded text-amber-500 hover:text-amber-400 hover:bg-surface-elevated transition-colors`,title:`Mark as read`,children:(0,X.jsx)(c,{className:`size-3`})}),m&&(0,X.jsx)(`button`,{onClick:m,className:`size-4 flex items-center justify-center`,title:f?`Connected`:`Disconnected — click to reconnect`,children:(0,X.jsx)(`span`,{className:`size-2 rounded-full ${f?`bg-green-500`:`bg-red-500 animate-pulse`}`})})]}),h===`history`&&(0,X.jsxs)(`div`,{className:`border-t border-border/30 bg-surface`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 border-b border-border/30`,children:[(0,X.jsx)(R,{className:`size-3 text-text-subtle shrink-0`}),(0,X.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`Search sessions...`,className:`flex-1 bg-transparent text-[11px] text-text-primary outline-none placeholder:text-text-subtle`}),(0,X.jsx)(`button`,{onClick:z,disabled:y,className:`p-0.5 rounded text-text-subtle hover:text-text-secondary transition-colors disabled:opacity-50`,title:`Refresh`,children:(0,X.jsx)(N,{className:`size-3 ${y?`animate-spin`:``}`})})]}),(0,X.jsx)(`div`,{className:`max-h-[200px] overflow-y-auto`,children:y&&_.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3`,children:(0,X.jsx)(k,{className:`size-3.5 animate-spin text-text-subtle`})}):H.length===0?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-3 text-[11px] text-text-subtle`,children:w?`No matching sessions`:`No sessions yet`}):H.map(e=>(0,X.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,X.jsx)(te,{className:`size-3 shrink-0 text-text-subtle`}),D===e.id?(0,X.jsxs)(`form`,{className:`flex items-center gap-1 flex-1 min-w-0`,onSubmit:e=>{e.preventDefault(),V()},children:[(0,X.jsx)(`input`,{ref:F,value:j,onChange:e=>P(e.target.value),onBlur:V,onKeyDown:e=>{e.key===`Escape`&&ie()},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,X.jsx)(`button`,{type:`submit`,className:`p-0.5 text-green-500 hover:text-green-400`,onClick:e=>e.stopPropagation(),children:(0,X.jsx)(i,{className:`size-3`})}),(0,X.jsx)(`button`,{type:`button`,className:`p-0.5 text-text-subtle hover:text-text-secondary`,onClick:e=>{e.stopPropagation(),ie()},children:(0,X.jsx)(n,{className:`size-3`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:()=>ee(e),className:`text-[11px] truncate flex-1 text-left`,children:e.title||`Untitled`}),(0,X.jsx)(`button`,{onClick:t=>ne(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,X.jsx)(M,{className:`size-3`})})]}),D!==e.id&&e.updatedAt&&(0,X.jsx)(`span`,{className:`text-[10px] text-text-subtle shrink-0`,children:Ht(e.updatedAt)})]},e.id))})]}),h===`config`&&(0,X.jsx)(`div`,{className:`border-t border-border/30 bg-surface px-3 py-2 max-h-[280px] overflow-y-auto`,children:(0,X.jsx)(p,{compact:!0})}),h===`usage`&&(0,X.jsx)(Vt,{usage:t,visible:!0,onClose:()=>g(null),onReload:o,loading:a,lastFetchedAt:s})]})}function Gt({metadata:e,tabId:t}){let[n,r]=(0,J.useState)(e?.sessionId??null),[i,a]=(0,J.useState)(e?.providerId??`claude`),[o,s]=(0,J.useState)([]),[c,l]=(0,J.useState)(!1),[u,d]=(0,J.useState)(``),[f,p]=(0,J.useState)(null),[h,g]=(0,J.useState)([]),[_,y]=(0,J.useState)(!1),[b,w]=(0,J.useState)(``),[T,D]=(0,J.useState)(null),[k,A]=(0,J.useState)(e?.permissionMode??void 0),[j,M]=(0,J.useState)(!1),[N,P]=(0,J.useState)(null),F=(0,J.useRef)(0),I=e?.projectName??``,L=S(e=>e.updateTab),R=C(e=>e.version),{usageInfo:z,usageLoading:te,lastFetchedAt:V,refreshUsage:re}=ke(I,i);(0,J.useEffect)(()=>{k||m().then(e=>{let t=e.providers[e.default_provider??`claude`];A(t?.permission_mode??`bypassPermissions`)}).catch(()=>{})},[]),(0,J.useEffect)(()=>{!t||!n||L(t,{metadata:{...e,sessionId:n,providerId:i,permissionMode:k}})},[n,i,k]);let{messages:ie,messagesLoading:H,isStreaming:U,streamingStatus:W,connectingElapsed:ae,thinkingWarningThreshold:oe,pendingApproval:se,contextWindowPct:ce,sessionTitle:G,sendMessage:K,respondToApproval:le,cancelStreaming:ue,reconnect:de,refetchMessages:fe,isConnected:q}=De(n,i,I);(0,J.useEffect)(()=>{if(!n||!t)return;let e=()=>{if(document.hidden)return;let{panels:e,focusedPanelId:r}=x.getState();e[r]?.activeTabId===t&&B.getState().clearForSession(n)};e(),document.addEventListener(`visibilitychange`,e);let r=x.subscribe(e);return()=>{document.removeEventListener(`visibilitychange`,e),r()}},[n,t]),(0,J.useEffect)(()=>{t&&G&&L(t,{title:G})},[G]);let pe=(0,J.useRef)(e?.pendingMessage);(0,J.useEffect)(()=>{if(pe.current&&q&&n){let n=pe.current;pe.current=void 0,t&&L(t,{metadata:{...e,pendingMessage:void 0}}),setTimeout(()=>K(n,{permissionMode:k}),100)}},[q,n]),(0,J.useCallback)(()=>{S.getState().openTab({type:`chat`,title:`AI Chat`,metadata:{projectName:I},projectId:I||null,closable:!0})},[I]);let me=(0,J.useCallback)(e=>{r(e.id),a(e.providerId),t&&L(t,{title:e.title||`Chat`})},[t,L]),he=(0,J.useCallback)(async e=>{if(!(!n||!I))try{let{api:t,projectUrl:r}=await ee(async()=>{let{api:e,projectUrl:t}=await import(`./api-client-TUmacMRS.js`).then(e=>e.n);return{api:e,projectUrl:t}},__vite__mapDeps([0,1])),a=await t.post(`${r(I)}/chat/sessions/${n}/fork?providerId=${i}`);S.getState().openTab({type:`chat`,title:`Fork: ${e.slice(0,30)}`,metadata:{projectName:I,sessionId:a.id,providerId:i,pendingMessage:e},projectId:I||null,closable:!0})}catch(e){console.error(`Fork failed:`,e)}},[n,I,i]),ge=(0,J.useCallback)((e,t)=>{if(t.length===0)return e;let n=t.filter(e=>e.serverPath).map(e=>e.serverPath).join(`
7
7
  `);return n?(t.length===1?`[Attached file: ${n}]\n\n`:`[Attached files:\n${n}\n]\n\n`)+e:e},[]),_e=(0,J.useCallback)(async(e,t=[])=>{let o=ge(e,t);if(o.trim()){if(!n)try{let t=I,n=await O.post(`${E(t)}/chat/sessions`,{providerId:i,title:e.slice(0,50)});r(n.id),a(n.providerId),setTimeout(()=>{K(o,{permissionMode:k})},500);return}catch(e){console.error(`Failed to create session:`,e);return}K(o,{permissionMode:k})}},[n,i,I,K,ge,k]),ve=(0,J.useCallback)((e,t)=>{l(e),d(t)},[]),ye=(0,J.useCallback)(e=>{p(e),l(!1),d(``),setTimeout(()=>p(null),50)},[]),be=(0,J.useCallback)(()=>{l(!1),d(``)},[]),Y=(0,J.useCallback)((e,t)=>{y(e),w(t)},[]),xe=(0,J.useCallback)(e=>{D(e),y(!1),w(``),setTimeout(()=>D(null),50)},[]),Se=(0,J.useCallback)(()=>{y(!1),w(``)},[]);return(0,X.jsxs)(`div`,{className:`flex flex-col h-full relative`,onDragEnter:(0,J.useCallback)(e=>{e.preventDefault(),F.current++,e.dataTransfer.types.includes(`Files`)&&M(!0)},[]),onDragLeave:(0,J.useCallback)(e=>{e.preventDefault(),F.current--,F.current===0&&M(!1)},[]),onDragOver:(0,J.useCallback)(e=>{e.preventDefault()},[]),onDrop:(0,J.useCallback)(e=>{e.preventDefault(),F.current=0,M(!1);let t=Array.from(e.dataTransfer.files);t.length>0&&(P(t),setTimeout(()=>P(null),100))},[]),children:[j&&(0,X.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,X.jsxs)(`div`,{className:`flex flex-col items-center gap-2 text-primary`,children:[(0,X.jsx)(v,{className:`size-8`}),(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:`Drop files to attach`})]})}),(0,X.jsx)(tt,{messages:ie,messagesLoading:H,pendingApproval:se,onApprovalResponse:le,isStreaming:U,streamingStatus:W,connectingElapsed:ae,thinkingWarningThreshold:oe,projectName:I,onFork:U?void 0:he}),(0,X.jsxs)(`div`,{className:`border-t border-border bg-background shrink-0`,children:[(0,X.jsx)(Wt,{projectName:I,usageInfo:z,contextWindowPct:ce,usageLoading:te,refreshUsage:re,lastFetchedAt:V,sessionId:n,onSelectSession:me,onBugReport:n?()=>ne(R,{sessionId:n,projectName:I}):void 0,isConnected:q,onReconnect:()=>{q||de(),fe()}}),(0,X.jsx)(Ft,{items:o,filter:u,onSelect:ye,onClose:be,visible:c}),(0,X.jsx)(Mt,{items:h,filter:b,onSelect:xe,onClose:Se,visible:_}),(0,X.jsx)(Nt,{onSend:_e,isStreaming:U,onCancel:ue,projectName:I,onSlashStateChange:ve,onSlashItemsLoaded:s,slashSelected:f,onFileStateChange:Y,onFileItemsLoaded:g,fileSelected:T,externalFiles:N,permissionMode:k,onModeChange:A})]})]})}export{Gt as ChatTab};