@rexvane/piweb 0.3.15 → 0.3.16
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/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +9 -6
- package/.next/build-manifest.json +3 -3
- package/.next/prerender-manifest.json +6 -6
- package/.next/react-loadable-manifest.json +16 -4
- package/.next/routes-manifest.json +20 -0
- package/.next/server/app/_global-error/page.js +2 -2
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page.js +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +7 -4
- package/.next/server/app/_not-found.segments/_full.segment.rsc +7 -4
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +5 -2
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +5 -2
- package/.next/server/app/api/agent/[id]/events/route.js +2 -2
- package/.next/server/app/api/agent/[id]/events/route.js.nft.json +1 -1
- package/.next/server/app/api/agent/[id]/route.js +1 -1
- package/.next/server/app/api/agent/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/agent/[id]/tree/route.js +1 -1
- package/.next/server/app/api/agent/[id]/tree/route.js.nft.json +1 -1
- package/.next/server/app/api/agent/new/route.js +1 -1
- package/.next/server/app/api/agent/new/route.js.nft.json +1 -1
- package/.next/server/app/api/config/route.js +1 -1
- package/.next/server/app/api/config/route.js.nft.json +1 -1
- package/.next/server/app/api/files/route.js +1 -1
- package/.next/server/app/api/files/route.js.nft.json +1 -1
- package/.next/server/app/api/git/route.js +2 -2
- package/.next/server/app/api/git/route.js.nft.json +1 -1
- package/.next/server/app/api/growth/route.js +1 -1
- package/.next/server/app/api/growth/route.js.nft.json +1 -1
- package/.next/server/app/api/health/route.js +1 -1
- package/.next/server/app/api/models/route.js +1 -1
- package/.next/server/app/api/models/route.js.nft.json +1 -1
- package/.next/server/app/api/pi-settings/route.js +1 -1
- package/.next/server/app/api/pi-settings/route.js.nft.json +1 -1
- package/.next/server/app/api/plugins/route.js +1 -1
- package/.next/server/app/api/plugins/route.js.nft.json +1 -1
- package/.next/server/app/api/prompts/route.js +1 -1
- package/.next/server/app/api/prompts/route.js.nft.json +1 -1
- package/.next/server/app/api/security/route.js +1 -1
- package/.next/server/app/api/security/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/export/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/export/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/[id]/route.js +1 -1
- package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/import/route.js +3 -3
- package/.next/server/app/api/sessions/import/route.js.nft.json +1 -1
- package/.next/server/app/api/sessions/route.js +1 -1
- package/.next/server/app/api/sessions/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/route.js +2 -2
- package/.next/server/app/api/skills/route.js.nft.json +1 -1
- package/.next/server/app/api/swarm/[id]/route.js +1 -0
- package/.next/server/app/api/swarm/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/swarm/[id]/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/swarm/route.js +1 -0
- package/.next/server/app/api/swarm/route.js.nft.json +1 -0
- package/.next/server/app/api/swarm/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/tests/route.js +2 -0
- package/.next/server/app/api/tests/route.js.nft.json +1 -0
- package/.next/server/app/api/tests/route_client-reference-manifest.js +1 -0
- package/.next/server/app/api/update/route.js +2 -2
- package/.next/server/app/api/update/route.js.nft.json +1 -1
- package/.next/server/app/api/version/route.js +1 -1
- package/.next/server/app/api/version/route.js.nft.json +1 -1
- package/.next/server/app/api/web-auth/route.js +1 -1
- package/.next/server/app/api/workspaces/route.js +1 -1
- package/.next/server/app/api/workspaces/route.js.nft.json +1 -1
- package/.next/server/app/icon.svg/route.js +1 -1
- package/.next/server/app/index.html +1 -1
- package/.next/server/app/index.rsc +9 -6
- package/.next/server/app/index.segments/__PAGE__.segment.rsc +7 -4
- package/.next/server/app/index.segments/_full.segment.rsc +9 -6
- package/.next/server/app/index.segments/_tree.segment.rsc +5 -2
- package/.next/server/app/login/page.js +1 -1
- package/.next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.next/server/app/login.html +1 -1
- package/.next/server/app/login.rsc +8 -5
- package/.next/server/app/login.segments/_full.segment.rsc +8 -5
- package/.next/server/app/login.segments/_tree.segment.rsc +5 -2
- package/.next/server/app/login.segments/login/__PAGE__.segment.rsc +6 -3
- package/.next/server/app/page.js +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +9 -6
- package/.next/server/chunks/496.js +1 -1
- package/.next/server/chunks/532.js +1 -1
- package/.next/server/chunks/686.js +6 -2
- package/.next/server/chunks/757.js +1 -0
- package/.next/server/chunks/775.js +3 -0
- package/.next/server/middleware-build-manifest.js +1 -1
- package/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.json +1 -1
- package/.next/static/0t1jBUAuVaTFTXxRyIo3q/_buildManifest.js +1 -0
- package/.next/static/chunks/2608.43c58236c9cce8e6.js +1 -0
- package/.next/static/chunks/{2716.a9e808190a4e2424.js → 2716.4ec42df1d51354c9.js} +1 -1
- package/.next/static/chunks/4632.62139b565b657aac.js +1 -0
- package/.next/static/chunks/{4673.d3d0a7f2599080fb.js → 4673.7796104395deb8d7.js} +1 -1
- package/.next/static/chunks/4686-17f21a006739a596.js +1 -0
- package/.next/static/chunks/7577.10af9bb661652da8.js +1 -0
- package/.next/static/chunks/8866.38ec4ac4ee5a1b74.js +1 -0
- package/.next/static/chunks/app/_global-error/page-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/events/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/agent/[id]/tree/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/agent/new/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/config/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/files/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/git/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/growth/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/health/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/models/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/pi-settings/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/plugins/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/prompts/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/security/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/export/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/sessions/[id]/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/sessions/import/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/sessions/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/skills/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/swarm/[id]/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/swarm/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/tests/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/update/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/version/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/web-auth/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/api/workspaces/route-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/app/page-14379b8060d5cf07.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-5148173b3f55e415.js +1 -0
- package/.next/static/chunks/webpack-d1a69ad9edb38b11.js +1 -0
- package/.next/static/css/d0a0162cb481abe8.css +1 -0
- package/.next/types/app/api/swarm/[id]/route.ts +353 -0
- package/.next/types/app/api/swarm/route.ts +353 -0
- package/.next/types/app/api/tests/route.ts +353 -0
- package/.next/types/routes.d.ts +4 -1
- package/.next/types/validator.ts +27 -0
- package/README.md +10 -0
- package/package.json +4 -3
- package/scripts/pick-folder.ps1 +11 -2
- package/scripts/release.mjs +11 -31
- package/scripts/run-test-file.mjs +34 -0
- package/scripts/verify-release-config.mjs +24 -0
- package/src/app/api/config/route.ts +4 -1
- package/src/app/api/security/route.ts +8 -3
- package/src/app/api/swarm/[id]/route.ts +28 -0
- package/src/app/api/swarm/route.ts +24 -0
- package/src/app/api/tests/route.ts +27 -0
- package/src/app/api/update/route.ts +8 -2
- package/src/app/globals.css +777 -0
- package/src/app/layout.tsx +13 -6
- package/src/components/AppShell.tsx +505 -199
- package/src/components/ChatInput.tsx +153 -26
- package/src/components/ChatWindow.tsx +46 -40
- package/src/components/ContextMeter.tsx +11 -17
- package/src/components/FileViewer.tsx +1 -1
- package/src/components/GitPanel.tsx +13 -11
- package/src/components/ModelSelector.tsx +19 -6
- package/src/components/PiMark.tsx +5 -38
- package/src/components/ProjectPanel.tsx +1 -0
- package/src/components/PromptPanel.tsx +132 -51
- package/src/components/SessionImportSection.tsx +17 -17
- package/src/components/SessionSidebar.tsx +159 -57
- package/src/components/SettingsPanel.tsx +330 -193
- package/src/components/SwarmCoordinatorPod.tsx +1021 -0
- package/src/components/TestInspectorPod.tsx +549 -0
- package/src/components/icons.tsx +23 -0
- package/src/hooks/usePiWeb.ts +112 -8
- package/src/i18n.tsx +59 -3
- package/src/lib/agent-manager.ts +180 -12
- package/src/lib/command-validation.ts +9 -1
- package/src/lib/delegation.ts +93 -0
- package/src/lib/managed-niubash.ts +8 -4
- package/src/lib/pi.ts +3 -2
- package/src/lib/runtime-activity.ts +27 -0
- package/src/lib/session-import/index.ts +5 -0
- package/src/lib/session-import/lock.ts +25 -0
- package/src/lib/session-import/writer.ts +8 -3
- package/src/lib/skills-service.ts +16 -9
- package/src/lib/swarm-service.ts +371 -0
- package/src/lib/test-run-service.ts +122 -0
- package/src/lib/theme.ts +68 -1
- package/src/lib/trajectory.ts +1 -0
- package/src/lib/types.ts +14 -0
- package/src/lib/workflow.ts +55 -0
- package/.next/static/DdBwPYoHBKtaJ97QIr6Co/_buildManifest.js +0 -1
- package/.next/static/chunks/2608.ec8ff1f5767c9056.js +0 -1
- package/.next/static/chunks/4632.0ed92ae42905ce40.js +0 -1
- package/.next/static/chunks/4686-7d694def920ff093.js +0 -1
- package/.next/static/chunks/app/_global-error/page-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/events/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/agent/[id]/tree/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/agent/new/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/config/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/files/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/git/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/growth/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/health/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/models/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/pi-settings/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/plugins/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/prompts/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/security/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/export/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/sessions/[id]/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/sessions/import/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/sessions/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/skills/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/update/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/version/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/web-auth/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/api/workspaces/route-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/app/page-9a5440047c5a415c.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/app-error-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/forbidden-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/not-found-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/next/dist/client/components/builtin/unauthorized-f77e9ede9808b18e.js +0 -1
- package/.next/static/chunks/webpack-42c5aae79b0e5d8c.js +0 -1
- package/.next/static/css/b2d35abc828d4713.css +0 -1
- /package/.next/static/{DdBwPYoHBKtaJ97QIr6Co → 0t1jBUAuVaTFTXxRyIo3q}/_ssgManifest.js +0 -0
package/src/lib/theme.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
export type PebrelTheme =
|
|
8
|
+
| 'piweb'
|
|
9
|
+
| 'ocean-ink'
|
|
8
10
|
| 'silver-steel'
|
|
9
11
|
| 'limestone-coal'
|
|
10
12
|
| 'linen-moss'
|
|
@@ -15,7 +17,61 @@ export type PebrelTheme =
|
|
|
15
17
|
/** dsh 的 THEME_PREFERENCES:浅色/深色/跟随系统 */
|
|
16
18
|
export type ThemeMode = 'light' | 'dark' | 'system';
|
|
17
19
|
|
|
20
|
+
export interface ThemeMeta {
|
|
21
|
+
id: PebrelTheme;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
colors: [string, string];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const THEME_CATALOG: ThemeMeta[] = [
|
|
28
|
+
{
|
|
29
|
+
id: 'piweb',
|
|
30
|
+
name: 'PiWeb · 工作台',
|
|
31
|
+
description: '粘土薄荷原装配方',
|
|
32
|
+
colors: ['#34D399', '#A7F3D0'],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'ocean-ink',
|
|
36
|
+
name: '海与墨',
|
|
37
|
+
description: '湛蓝深邃与清爽青靛',
|
|
38
|
+
colors: ['#38BDF8', '#0284C7'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'silver-steel',
|
|
42
|
+
name: '银钢',
|
|
43
|
+
description: '坚实质感与精密中性',
|
|
44
|
+
colors: ['#E2E8F0', '#475569'],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'limestone-coal',
|
|
48
|
+
name: '石灰与煤炭',
|
|
49
|
+
description: '暖橙炭黑微拟物风格',
|
|
50
|
+
colors: ['#FB923C', '#1E293B'],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'linen-moss',
|
|
54
|
+
name: '亚麻与苔绿',
|
|
55
|
+
description: '自然植物纤维温润感',
|
|
56
|
+
colors: ['#FFDCC5', '#006C4B'],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'nord-paper',
|
|
60
|
+
name: '北欧纸墨',
|
|
61
|
+
description: '哑光书纸触觉明度',
|
|
62
|
+
colors: ['#F6FAFE', '#00668A'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'pebrel',
|
|
66
|
+
name: 'Pebrel',
|
|
67
|
+
description: '柔和薰衣草紫与鹅卵石质感',
|
|
68
|
+
colors: ['#818CF8', '#EEF2FF'],
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
18
72
|
export const PEBREL_THEME_IDS: PebrelTheme[] = [
|
|
73
|
+
'piweb',
|
|
74
|
+
'ocean-ink',
|
|
19
75
|
'dsh',
|
|
20
76
|
'silver-steel',
|
|
21
77
|
'limestone-coal',
|
|
@@ -26,11 +82,12 @@ export const PEBREL_THEME_IDS: PebrelTheme[] = [
|
|
|
26
82
|
|
|
27
83
|
export const THEME_MODES: ThemeMode[] = ['light', 'dark', 'system'];
|
|
28
84
|
|
|
29
|
-
export const DEFAULT_PEBREL_THEME: PebrelTheme = '
|
|
85
|
+
export const DEFAULT_PEBREL_THEME: PebrelTheme = 'piweb';
|
|
30
86
|
export const DEFAULT_THEME_MODE: ThemeMode = 'system';
|
|
31
87
|
|
|
32
88
|
const THEME_KEY = 'piweb.pebrelTheme';
|
|
33
89
|
const MODE_KEY = 'piweb.theme';
|
|
90
|
+
const DESIGN_VERSION_KEY = 'piweb.designVersion';
|
|
34
91
|
|
|
35
92
|
export function isPebrelTheme(value: string | null): value is PebrelTheme {
|
|
36
93
|
return !!value && (PEBREL_THEME_IDS as string[]).includes(value);
|
|
@@ -44,6 +101,11 @@ export function loadPebrelTheme(): PebrelTheme {
|
|
|
44
101
|
if (typeof window === 'undefined') return DEFAULT_PEBREL_THEME;
|
|
45
102
|
try {
|
|
46
103
|
const saved = localStorage.getItem(THEME_KEY);
|
|
104
|
+
if (saved === 'dsh' && localStorage.getItem(DESIGN_VERSION_KEY) !== '1') {
|
|
105
|
+
localStorage.setItem(THEME_KEY, 'piweb');
|
|
106
|
+
localStorage.setItem(DESIGN_VERSION_KEY, '1');
|
|
107
|
+
return 'piweb';
|
|
108
|
+
}
|
|
47
109
|
if (isPebrelTheme(saved)) return saved;
|
|
48
110
|
} catch {
|
|
49
111
|
/* ignore */
|
|
@@ -79,13 +141,17 @@ function applyLightDark(mode: ThemeMode): void {
|
|
|
79
141
|
if (isDark) {
|
|
80
142
|
root.setAttribute('data-ds-dark-theme', '');
|
|
81
143
|
root.removeAttribute('data-ds-light-theme');
|
|
144
|
+
root.classList.add('dark');
|
|
82
145
|
body?.setAttribute('data-ds-dark-theme', '');
|
|
83
146
|
body?.removeAttribute('data-ds-light-theme');
|
|
147
|
+
body?.classList.add('dark');
|
|
84
148
|
} else {
|
|
85
149
|
root.removeAttribute('data-ds-dark-theme');
|
|
86
150
|
root.setAttribute('data-ds-light-theme', '');
|
|
151
|
+
root.classList.remove('dark');
|
|
87
152
|
body?.removeAttribute('data-ds-dark-theme');
|
|
88
153
|
body?.setAttribute('data-ds-light-theme', '');
|
|
154
|
+
body?.classList.remove('dark');
|
|
89
155
|
}
|
|
90
156
|
root.style.colorScheme = isDark ? 'dark' : 'light';
|
|
91
157
|
}
|
|
@@ -126,6 +192,7 @@ export function applyPebrelTheme(theme: PebrelTheme, mode?: ThemeMode): void {
|
|
|
126
192
|
try {
|
|
127
193
|
localStorage.setItem(THEME_KEY, theme);
|
|
128
194
|
localStorage.setItem(MODE_KEY, effectiveMode);
|
|
195
|
+
localStorage.setItem(DESIGN_VERSION_KEY, '1');
|
|
129
196
|
} catch {
|
|
130
197
|
/* ignore */
|
|
131
198
|
}
|
package/src/lib/trajectory.ts
CHANGED
|
@@ -14,6 +14,7 @@ export function toTrajTokens(u: any): TrajTokens | undefined {
|
|
|
14
14
|
if (typeof u.output === "number") t.output = u.output;
|
|
15
15
|
if (typeof u.cacheRead === "number") t.cacheRead = u.cacheRead;
|
|
16
16
|
if (typeof u.cacheWrite === "number") t.cacheWrite = u.cacheWrite;
|
|
17
|
+
if (typeof u.totalTokens === "number") t.totalTokens = u.totalTokens;
|
|
17
18
|
return Object.keys(t).length ? t : undefined;
|
|
18
19
|
}
|
|
19
20
|
|
package/src/lib/types.ts
CHANGED
|
@@ -25,6 +25,7 @@ export interface TrajTokens {
|
|
|
25
25
|
output?: number;
|
|
26
26
|
cacheRead?: number;
|
|
27
27
|
cacheWrite?: number;
|
|
28
|
+
totalTokens?: number;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export interface TrajEntry {
|
|
@@ -115,6 +116,7 @@ export type WebEvent =
|
|
|
115
116
|
| { type: "traj"; entry: TrajEntry; ts: number }
|
|
116
117
|
| { type: "name"; name: string; ts: number }
|
|
117
118
|
| { type: "tools"; active: string[]; all: string[]; toolPreset?: ToolPreset; customActiveTools?: string[] | null; ts: number }
|
|
119
|
+
| { type: "workflow"; workflow: WorkflowState; ts: number }
|
|
118
120
|
| {
|
|
119
121
|
/** 资源(扩展/技能/模板/命令)重载后的新清单;前端据此刷新 / 菜单与设置面板 */
|
|
120
122
|
type: "resources";
|
|
@@ -265,6 +267,7 @@ export interface WebSnapshot {
|
|
|
265
267
|
thinkingLevel?: string;
|
|
266
268
|
thinkingLevels: string[];
|
|
267
269
|
toolPreset: ToolPreset;
|
|
270
|
+
workflow: WorkflowState;
|
|
268
271
|
/** custom 白名单优先于 preset;null 表示使用 preset,省略兼容旧服务端。 */
|
|
269
272
|
customActiveTools?: string[] | null;
|
|
270
273
|
/** 当前待应答的扩展请求;快照是权威集合,不重放已答请求。 */
|
|
@@ -281,6 +284,14 @@ export interface WebSnapshot {
|
|
|
281
284
|
|
|
282
285
|
export type ToolPreset = "readonly" | "standard" | "full";
|
|
283
286
|
|
|
287
|
+
export type WorkflowMode = "agent" | "plan" | "goal";
|
|
288
|
+
export interface WorkflowState {
|
|
289
|
+
mode: WorkflowMode;
|
|
290
|
+
planStatus: "idle" | "planning" | "ready" | "executing";
|
|
291
|
+
planId?: string;
|
|
292
|
+
goal: string;
|
|
293
|
+
}
|
|
294
|
+
|
|
284
295
|
export interface ImageAttachment {
|
|
285
296
|
type: "image";
|
|
286
297
|
data: string;
|
|
@@ -298,6 +309,8 @@ export interface AgentCommand {
|
|
|
298
309
|
| "setModel"
|
|
299
310
|
| "setThinkingLevel"
|
|
300
311
|
| "setToolPreset"
|
|
312
|
+
| "setWorkflowMode"
|
|
313
|
+
| "approvePlan"
|
|
301
314
|
| "rename"
|
|
302
315
|
| "fork"
|
|
303
316
|
| "cycleModel"
|
|
@@ -314,6 +327,7 @@ export interface AgentCommand {
|
|
|
314
327
|
modelId?: string;
|
|
315
328
|
level?: string;
|
|
316
329
|
preset?: ToolPreset;
|
|
330
|
+
mode?: WorkflowMode;
|
|
317
331
|
entryId?: string;
|
|
318
332
|
behavior?: "steer" | "followUp";
|
|
319
333
|
direction?: "forward" | "backward";
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { WorkflowMode, WorkflowState } from "./types";
|
|
3
|
+
|
|
4
|
+
export type { WorkflowMode, WorkflowState } from "./types";
|
|
5
|
+
|
|
6
|
+
const ENTRY_TYPE = "piweb.workflow.v1";
|
|
7
|
+
const DEFAULT_STATE: WorkflowState = { mode: "agent", planStatus: "idle", goal: "" };
|
|
8
|
+
|
|
9
|
+
export function isWorkflowMode(value: unknown): value is WorkflowMode {
|
|
10
|
+
return value === "agent" || value === "plan" || value === "goal";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function readWorkflow(sm: SessionManager): WorkflowState {
|
|
14
|
+
for (const entry of sm.getBranch().slice().reverse()) {
|
|
15
|
+
if (entry.type !== "custom" || entry.customType !== ENTRY_TYPE) continue;
|
|
16
|
+
const data = entry.data as Partial<WorkflowState> | undefined;
|
|
17
|
+
if (!data || !isWorkflowMode(data.mode)) break;
|
|
18
|
+
return {
|
|
19
|
+
mode: data.mode,
|
|
20
|
+
planStatus: data.mode === "plan" && data.planStatus === "ready" ? "ready" : "idle",
|
|
21
|
+
planId: data.mode === "plan" && typeof data.planId === "string" ? data.planId : undefined,
|
|
22
|
+
goal: data.mode === "goal" && typeof data.goal === "string" ? data.goal.slice(0, 8_000) : "",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return { ...DEFAULT_STATE };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function saveWorkflow(sm: SessionManager, state: WorkflowState): void {
|
|
29
|
+
sm.appendCustomEntry(ENTRY_TYPE, state);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 最近一条工作流记录之后还没有用户消息:下一条(含编辑重发的)用户消息就是 Goal 的目标。 */
|
|
33
|
+
export function awaitingGoalMessage(sm: SessionManager): boolean {
|
|
34
|
+
for (const entry of sm.getBranch().slice().reverse()) {
|
|
35
|
+
if (entry.type === "custom" && entry.customType === ENTRY_TYPE) return true;
|
|
36
|
+
if (entry.type === "message" && entry.message.role === "user") return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function workflowInstruction(state: WorkflowState): string {
|
|
42
|
+
if (state.mode === "plan") {
|
|
43
|
+
return state.planStatus === "executing"
|
|
44
|
+
? "The user approved the plan in this conversation. Execute it now, verify the result, and report any unfinished work. Respect the active tool permissions."
|
|
45
|
+
: "Planning mode: investigate using read-only tools. Do not edit files, run commands, or cause side effects. Produce a concrete implementation plan with verification steps, then stop and wait for explicit approval in PiWeb.";
|
|
46
|
+
}
|
|
47
|
+
if (state.mode === "goal") {
|
|
48
|
+
return `Goal mode: work toward the user's objective, verify the result before claiming completion, and clearly report blockers or unverified assumptions. Do not silently change the objective. Objective: ${state.goal || "Use the next user message as the objective."}`;
|
|
49
|
+
}
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function planCanRun(state: WorkflowState): boolean {
|
|
54
|
+
return state.mode === "plan" && state.planStatus === "ready";
|
|
55
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
self.__BUILD_MANIFEST={__rewrites:{afterFiles:[],beforeFiles:[],fallback:[]},__routerFilterStatic:{numItems:23,errorRate:1e-4,numBits:441,numHashes:14,bitArray:[1,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,1,1,1,0,0,1,0,0,0,0,1,0,1,0,0,1,0,0,1,0,1,0,1,0,0,0,1,1,1,0,0,0,1,1,1,0,1,1,0,0,1,1,0,1,1,1,0,1,1,0,0,1,0,1,0,0,1,0,1,1,1,1,1,0,0,1,1,0,0,1,1,1,0,0,1,0,1,1,1,0,0,0,0,1,1,0,0,0,1,0,1,0,1,0,1,0,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0,1,1,1,0,1,0,0,0,1,0,0,1,0,0,0,0,0,1,0,1,1,0,1,0,1,0,1,1,1,1,0,0,1,0,1,1,0,1,1,1,1,1,0,1,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,1,0,1,1,0,0,0,1,1,0,1,0,0,1,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,0,1,0,1,0,1,0,0,0,0,1,0,1,1,0,0,1,0,1,0,0,1,0,1,1,1,0,1,0,1,1,0,1,1,1,1,1,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,0,1,1,1,1,0,1,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,1,1,0,1,0,1,0,0,1,1,0,1,1,0,0,0,1,1,0,1,0,0,1,0,0,1,1,1,1,1,0,1,0,0,0,0,0,1,1,0,0,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,1,0,0,1,0,1,1,0,1,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,0,1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,0]},__routerFilterDynamic:{numItems:2,errorRate:1e-4,numBits:39,numHashes:14,bitArray:[1,0,1,0,0,0,0,0,1,1,0,1,1,1,1,1,0,0,1,0,0,1,0,0,0,1,0,1,1,0,1,1,0,1,0,1,1,0,0]},sortedPages:["/_app"]},self.__BUILD_MANIFEST_CB&&self.__BUILD_MANIFEST_CB();
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2608],{2608:(e,t,l)=>{l.r(t),l.d(t,{GitPanel:()=>d});var n=l(5155),a=l(2115),s=l(8476),i=l(9665),r=l(9992),o=l(1859);let c={modified:"var(--dsw-warn)",added:"var(--dsw-success)",deleted:"var(--dsw-danger)",renamed:"var(--dsw-accent)",untracked:"var(--dsw-label-caption)",conflict:"var(--dsw-danger)"};function d({cwd:e,onClose:t,refreshKey:l=0,onAskCommit:f,onOpenFile:h}){let{t:p}=(0,o.s)(),[u,x]=(0,a.useState)(null),[g,m]=(0,a.useState)(!1),[v,b]=(0,a.useState)(""),[w,y]=(0,a.useState)(""),[j,k]=(0,a.useState)(null),[S,N]=(0,a.useState)(null),[z,C]=(0,a.useState)(!1),E=(0,a.useRef)({version:0}),R=(0,a.useRef)({version:0}),U=(0,a.useCallback)(async()=>{E.current.controller?.abort();let t=new AbortController,l=++E.current.version;E.current.controller=t;let n=()=>!t.signal.aborted&&E.current.version===l;if(e){m(!0),b("");try{let l=await fetch(`/api/git?cwd=${encodeURIComponent(e)}`,{signal:t.signal}),a=await l.json();if(!l.ok||!a.success)throw Error(a.error||"failed to load git status");n()&&x(a.data)}catch(e){n()&&b(e instanceof Error?e.message:"failed to load git status")}finally{n()&&m(!1)}}},[e]);(0,a.useEffect)(()=>(x(null),k(null),N(null),y(""),b(""),m(!1),()=>{E.current.controller?.abort(),E.current.version+=1,R.current.controller?.abort(),R.current.version+=1}),[e]),(0,a.useEffect)(()=>{U()},[U,l]);let $=(0,a.useCallback)(async t=>{R.current.controller?.abort();let l=new AbortController,n=++R.current.version;R.current.controller=l;let a=()=>!l.signal.aborted&&R.current.version===n;C(!0),N(null),y("");try{let n="file"===t.kind?`/api/git?cwd=${encodeURIComponent(e)}&diff=${encodeURIComponent(t.path)}&mode=${t.mode}`:`/api/git?cwd=${encodeURIComponent(e)}&show=${encodeURIComponent(t.hash)}`,s=await fetch(n,{signal:l.signal}),i=await s.json();if(!s.ok||!i.success)throw Error(i.error||"failed to load diff");a()&&N(i.data)}catch(e){a()&&y(e instanceof Error?e.message:"failed to load diff")}finally{a()&&C(!1)}},[e]);(0,a.useEffect)(()=>(N(null),y(""),C(!1),j&&$(j),()=>{R.current.controller?.abort(),R.current.version+=1}),[j,$,l]);let W=e=>{R.current.controller?.abort(),R.current.version+=1,N(null),y(""),k(e)},M=j?w:v||u?.statusError||"",A=(0,a.useMemo)(()=>S?.patch?(0,s.rj)(S.patch):null,[S]),D=A?(0,s.hM)(A):null,I=u?.files.filter(e=>"conflict"===e.kind)??[],L=u?.files.filter(e=>"conflict"!==e.kind&&"untracked"!==e.kind&&" "!==e.indexStatus)??[],T=u?.files.filter(e=>"conflict"!==e.kind&&"untracked"!==e.kind&&" "!==e.workStatus)??[],B=u?.files.filter(e=>"untracked"===e.kind)??[],F=j?"file"===j.kind?j.path.split("/").pop()??j.path:S?.title?.split("\n")[0]??j.hash:p.gitPanel;return(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col p-4",children:[(0,n.jsxs)("div",{className:"mb-3 flex items-center gap-2",children:[j?(0,n.jsx)("button",{className:"icon-btn",style:{width:22,height:22},title:p.gitBack,onClick:()=>W(null),children:(0,n.jsx)(r.bQ,{size:13})}):(0,n.jsx)(r.Je,{size:15,style:{flex:"none"}}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",style:{fontSize:13,fontWeight:600},title:j?.kind==="file"?j.path:void 0,children:F}),j?.kind==="file"&&h&&u?.root&&(0,n.jsx)("button",{className:"icon-btn",style:{width:22,height:22},title:p.fileOpenEditor,onClick:()=>h(`${u.root}/${j.path}`),children:(0,n.jsx)(r.lx,{size:13})}),(0,n.jsx)("button",{className:"icon-btn",style:{width:22,height:22},title:p.panelRefresh,onClick:()=>j?void $(j):void U(),children:(0,n.jsx)(r.Ct,{size:13})}),(0,n.jsx)("button",{className:"icon-btn",style:{width:22,height:22},title:p.close,onClick:t,children:(0,n.jsx)(r.Bh,{size:13})})]}),M&&(0,n.jsxs)("div",{className:"mb-2 rounded-xl px-3 py-2",style:{fontSize:12.5,background:"var(--dsw-danger)",color:"white"},role:"alert",children:[!j&&(0,n.jsx)("div",{children:p.gitStatusUnknown}),M]}),(0,n.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:[j&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"mb-2 flex flex-wrap items-center gap-2",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:["file"===j.kind?(0,n.jsx)("span",{children:j.label}):S?.title?.split("\n")[1]?(0,n.jsx)("span",{children:S.title.split("\n")[1]}):null,D&&(0,n.jsxs)("span",{style:{fontFamily:"var(--font-mono)"},children:[(0,n.jsxs)("span",{style:{color:"var(--dsw-success)"},children:["+",D.add]})," ",(0,n.jsxs)("span",{style:{color:"var(--dsw-danger)"},children:["−",D.del]})]}),S?.truncated&&(0,n.jsx)("span",{style:{color:"var(--dsw-warn)"},children:p.gitDiffTruncated})]}),z&&!S&&(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)",padding:"4px 2px"},children:p.panelLoading}),S?.binary&&(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)",padding:"4px 2px"},children:p.gitBinary}),S&&!S.binary&&!A&&(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)",padding:"4px 2px"},children:p.gitDiffEmpty}),A&&(0,n.jsx)("div",{className:"overflow-x-auto rounded-xl px-2 py-1.5",style:{background:"var(--dsw-hover)"},children:(0,n.jsx)(s.xZ,{lines:A,language:j?.kind==="file"?(0,i.f3)(j.path):void 0})})]}),!j&&g&&!u&&(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)",padding:"4px 2px"},children:p.panelLoading}),!j&&!g&&u&&!u.available&&(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-danger)",padding:"8px 2px",lineHeight:1.6},children:p.gitUnavailable}),!j&&!g&&u&&u.available&&!u.isRepo&&(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)",padding:"8px 2px",lineHeight:1.6},children:p.gitNotRepo}),!j&&u?.isRepo&&(0,n.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",style:{fontSize:12.5},children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 rounded-full px-2.5 py-1",style:{background:"var(--dsw-accent-soft)",color:"var(--dsw-accent)",fontWeight:500},children:[(0,n.jsx)(r.Je,{size:12}),u.detached?p.gitDetached:u.branch??"—"]}),u.ahead>0&&(0,n.jsxs)("span",{style:{color:"var(--dsw-label-secondary)"},children:["↑ ",p.gitAhead.replace("{n}",String(u.ahead))]}),u.behind>0&&(0,n.jsxs)("span",{style:{color:"var(--dsw-label-secondary)"},children:["↓ ",p.gitBehind.replace("{n}",String(u.behind))]}),(0,n.jsx)("span",{className:"min-w-0 truncate",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},title:u.upstream??void 0,children:u.upstream?p.gitUpstream.replace("{name}",u.upstream):u.detached?"":p.gitNoUpstream})]}),!M&&u.files.length>0&&f&&(0,n.jsx)("button",{type:"button",className:"btn-outline self-start",style:{height:28,padding:"0 12px",fontSize:12},onClick:f,title:p.gitAskCommitPrompt,children:p.gitAskCommit}),M?null:0===u.files.length?(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:p.gitNoChanges}):[{label:p.gitConflict,list:I,mode:"worktree"},{label:p.gitStaged,list:L,mode:"staged"},{label:p.gitUnstaged,list:T,mode:"worktree"},{label:p.gitUntracked,list:B,mode:"untracked"}].map(e=>e.list.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"mb-1 flex items-center gap-2",style:{fontSize:11.5,color:"worktree"===e.mode&&e.label===p.gitConflict?"var(--dsw-danger)":"var(--dsw-label-caption)"},children:[(0,n.jsx)("span",{style:{fontWeight:600},children:e.label}),(0,n.jsx)("span",{children:e.list.length})]}),(0,n.jsx)("div",{className:"flex flex-col",children:e.list.map(t=>(0,n.jsxs)("button",{type:"button",className:"flex w-full items-center gap-2 rounded-lg px-2 py-1 text-left transition-colors",title:t.path,onMouseEnter:e=>e.currentTarget.style.background="var(--dsw-hover)",onMouseLeave:e=>e.currentTarget.style.background="transparent",onClick:()=>{let l,n;return l=e.mode,n="staged"===e.mode?p.gitStagedDiff:"untracked"===e.mode?p.gitUntracked:p.gitWorktreeDiff,W({kind:"file",path:t.path,mode:l,label:n})},children:[(0,n.jsx)("span",{className:"flex-none rounded px-1 text-center",style:{minWidth:16,fontSize:10.5,fontFamily:"var(--font-mono)",fontWeight:600,color:c[t.kind],background:"var(--dsw-hover)"},children:"untracked"===t.kind?"?":"conflict"===t.kind?"!":"staged"===e.mode?t.indexStatus:" "!==t.workStatus?t.workStatus:t.indexStatus}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",style:{fontSize:12,fontFamily:"var(--font-mono)",color:"var(--dsw-label-secondary)"},children:t.path})]},`${e.label}:${t.path}`))})]},e.label)),(0,n.jsxs)("div",{className:"hairline-t pt-3",children:[(0,n.jsx)("div",{className:"mb-1",style:{fontSize:11.5,fontWeight:600,color:"var(--dsw-label-caption)"},children:p.gitRecentCommits}),0===u.commits.length?(0,n.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)",padding:"4px 2px"},children:p.gitNoCommits}):(0,n.jsx)("div",{className:"flex flex-col",children:u.commits.map(e=>(0,n.jsxs)("button",{type:"button",className:"flex w-full flex-col items-stretch rounded-lg px-2 py-1 text-left transition-colors",onMouseEnter:e=>e.currentTarget.style.background="var(--dsw-hover)",onMouseLeave:e=>e.currentTarget.style.background="transparent",onClick:()=>W({kind:"commit",hash:e.hash}),children:[(0,n.jsxs)("span",{className:"flex items-baseline gap-2",children:[(0,n.jsx)("span",{className:"flex-none",style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--dsw-accent)"},children:e.hash}),(0,n.jsx)("span",{className:"min-w-0 flex-1 truncate",style:{fontSize:12,color:"var(--dsw-label-secondary)"},title:e.subject,children:e.subject})]}),(0,n.jsxs)("span",{className:"truncate",style:{fontSize:11,color:"var(--dsw-label-caption)",paddingLeft:0},children:[e.author," \xb7 ",e.relative]})]},e.hash))})]})]})]})]})}}}]);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4632],{901:e=>{e.exports={mask:"ProviderSetupModal_mask__wwU3u",dialog:"ProviderSetupModal_dialog__BxSeI",builtinDialog:"ProviderSetupModal_builtinDialog__vA7_B",header:"ProviderSetupModal_header__Nvgmb",title:"ProviderSetupModal_title__ZIIXp",body:"ProviderSetupModal_body__QAlNu",builtinBody:"ProviderSetupModal_builtinBody___4EFo",field:"ProviderSetupModal_field__ZMO8M",label:"ProviderSetupModal_label__4_BYS",hint:"ProviderSetupModal_hint__yCwPV",input:"ProviderSetupModal_input__YZYV5",select:"ProviderSetupModal_select___PTpP",providerTrigger:"ProviderSetupModal_providerTrigger__TXtau",picker:"ProviderSetupModal_picker__VQdQc",providerText:"ProviderSetupModal_providerText__l9bwJ",providerName:"ProviderSetupModal_providerName__Hwwfg",providerMeta:"ProviderSetupModal_providerMeta____3za",menu:"ProviderSetupModal_menu__zO5CU",searchWrap:"ProviderSetupModal_searchWrap__5yw1r",searchIcon:"ProviderSetupModal_searchIcon__BZeD1",search:"ProviderSetupModal_search__j_n_8",providerList:"ProviderSetupModal_providerList__bMnFj",providerRow:"ProviderSetupModal_providerRow__Zf7fg",selectedMark:"ProviderSetupModal_selectedMark___8UDb",empty:"ProviderSetupModal_empty__4V1WK",advanced:"ProviderSetupModal_advanced__kWaTH",advancedButton:"ProviderSetupModal_advancedButton__efHwl",catalog:"ProviderSetupModal_catalog__mXakU",catalogHeader:"ProviderSetupModal_catalogHeader__0MDA4",catalogStatus:"ProviderSetupModal_catalogStatus__JRz0P",discoverButton:"ProviderSetupModal_discoverButton__GGuZX",discoverControls:"ProviderSetupModal_discoverControls___0_l8",allowPrivate:"ProviderSetupModal_allowPrivate__zZyZi",modelEmpty:"ProviderSetupModal_modelEmpty__h1N_8",modelList:"ProviderSetupModal_modelList__jkYVz",modelRow:"ProviderSetupModal_modelRow__mHfRv",removeModel:"ProviderSetupModal_removeModel___LjE1",addModel:"ProviderSetupModal_addModel__Q3KOU",error:"ProviderSetupModal_error__EAOK6",footer:"ProviderSetupModal_footer__zVp_c",footerButton:"ProviderSetupModal_footerButton__FL58k",primary:"ProviderSetupModal_primary__ArzeF",modelEntry:"ProviderSetupModal_modelEntry__G067u",rowToggle:"ProviderSetupModal_rowToggle__kc_Za",capacityRow:"ProviderSetupModal_capacityRow__0miDX",capacityField:"ProviderSetupModal_capacityField___TX70",capacityHint:"ProviderSetupModal_capacityHint__z_5re",rowError:"ProviderSetupModal_rowError__2vHrG",catalogError:"ProviderSetupModal_catalogError__ZL5D7",candidateMask:"ProviderSetupModal_candidateMask__YUZn7",candidateDialog:"ProviderSetupModal_candidateDialog__upECk",candidateHeader:"ProviderSetupModal_candidateHeader__bUvHV",candidateList:"ProviderSetupModal_candidateList__JRufC",candidateRow:"ProviderSetupModal_candidateRow__Omm_o",candidateId:"ProviderSetupModal_candidateId__7Hy7u",candidateName:"ProviderSetupModal_candidateName__D4rXE",candidateActions:"ProviderSetupModal_candidateActions__iptOe",candidateAll:"ProviderSetupModal_candidateAll__yhD_R",candidatePicked:"ProviderSetupModal_candidatePicked__cJ78H"}},4632:(e,a,t)=>{"use strict";t.r(a),t.d(a,{SettingsPanel:()=>z});var s=t(5155),r=t(2115),l=t(7650),i=t(560),n=t(9992);let o=[[/^amazon-bedrock$/,"bedrock-color"],[/^ant-ling$/,"antgroup-color"],[/^anthropic$/,"anthropic"],[/^azure-/,"azure-color"],[/^baseten$/,"baseten"],[/^cerebras$/,"cerebras-color"],[/^cloudflare-/,"cloudflare-color"],[/^deepseek$/,"deepseek-color"],[/^fireworks$/,"fireworks-color"],[/^github-copilot$/,"githubcopilot"],[/^google-vertex(?:-|$)/,"googlecloud-color"],[/^google$/,"google-color"],[/^groq$/,"groq"],[/^huggingface$/,"huggingface-color"],[/^kimi(?:-|$)/,"kimi-color"],[/^minimax/,"minimax-color"],[/^mistral$/,"mistral-color"],[/^moonshot(?:ai)?(?:-|$)/,"moonshot"],[/^nvidia$/,"nvidia-color"],[/^openai/,"openai"],[/^opencode(?:-|$)/,"opencode"],[/^openrouter$/,"openrouter-color"],[/^qwen(?:-|$)/,"qwen-color"],[/^together$/,"together-color"],[/^vercel(?:-|$)/,"vercel"],[/^xai$/,"xai"],[/^xiaomi(?:-|$)/,"xiaomimimo"],[/^zai(?:-|$)/,"zai"]];[...new Set(o.map(([,e])=>e))];let d=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,c=["openai-completions","openai-responses","anthropic-messages","google-generative-ai"];function u(e){let a=new Set(c);return[...c,...[...new Set(e.filter(e=>e&&!a.has(e)))].sort()]}function p({id:e,name:a,size:t=36}){let r,l=o.find(([a])=>a.test(e))?.[1]??null;return(0,s.jsx)("span",{"aria-hidden":"true",className:"inline-flex flex-none items-center justify-center overflow-hidden",style:{width:t,height:t,borderRadius:Math.max(10,Math.round(.3*t)),background:"#f7f7f5",border:"0.5px solid rgba(0,0,0,.09)",color:"#18191b",fontSize:Math.max(10,Math.round(.32*t)),fontWeight:750,letterSpacing:"-0.03em"},children:l?(0,s.jsx)("img",{src:`/provider-icons/${l}.svg`,alt:"",width:Math.round(.66*t),height:Math.round(.66*t)}):(r=a.trim().split(/[\s_-]+/).filter(Boolean)).length>=2?(r[0][0]+r[1][0]).toUpperCase():(r[0]??e).slice(0,2).toUpperCase()})}var m=t(1859);function h(e){let a=e&&"object"==typeof e&&!Array.isArray(e)?e:{id:"string"==typeof e?e:""};return{id:String(a.id??""),name:"string"==typeof a.name?a.name:"",contextWindow:"number"==typeof a.contextWindow?a.contextWindow:void 0,maxTokens:"number"==typeof a.maxTokens?a.maxTokens:void 0,source:a}}function x(e){let a=new Set;for(let t=0;t<e.length;t+=1){let s=e[t],r=s.id.trim();if(!r||a.has(r))return{index:t,reason:"id"};if(a.add(r),[s.contextWindow,s.maxTokens].some(e=>void 0!==e&&(!Number.isSafeInteger(e)||e<=0)))return{index:t,reason:"capacity"}}}function v(e){let a={...e.source},t=e.source?h(e.source):void 0;for(let s of["id","name","contextWindow","maxTokens"]){if(t&&Object.is(e[s],t[s]))continue;let r=e[s];if("id"===s||"name"===s){let e="string"==typeof r?r.trim():"";"id"===s||e?a[s]=e:delete a[s]}else"number"==typeof r&&Number.isSafeInteger(r)&&r>0?a[s]=r:delete a[s]}return a}function f(e,a,t){let s={...e};for(let t of["baseUrl","name","api"]){let r=a[t];void 0!==r&&r!==("string"==typeof e[t]?e[t]:"")&&(r.trim()?s[t]=r.trim():delete s[t])}return a.apiKey?.trim()&&(s.apiKey=a.apiKey.trim()),(a.models.length||Object.prototype.hasOwnProperty.call(e,"models"))&&(s.models=a.models.map(v)),a.models.length&&void 0===e.models&&void 0===s.api&&t&&(s.api=t),s}var g=t(901),b=t.n(g);function y({mode:e,providers:a,existingIds:t,onClose:l,onSaveBuiltin:i,onSaveCustom:o,onOAuthLogin:c}){let{t:h}=(0,m.s)(),[f,g]=(0,r.useState)(a[0]?.id??""),[j,S]=(0,r.useState)(!1),[N,k]=(0,r.useState)(""),[C,_]=(0,r.useState)("api_key"),[z,P]=(0,r.useState)(""),[M,E]=(0,r.useState)(!1),[T,$]=(0,r.useState)(""),[R,D]=(0,r.useState)(""),[L,F]=(0,r.useState)(""),A=u(a.flatMap(e=>e.apis)),[W,O]=(0,r.useState)(A.includes("openai-completions")?"openai-completions":A[0]??"openai-completions"),[I,U]=(0,r.useState)([]),[B,K]=(0,r.useState)(!1),[H,J]=(0,r.useState)(""),q=(0,r.useRef)(null),G=a.find(e=>e.id===f),Q=a.filter(e=>{let a=N.trim().toLocaleLowerCase();return!a||e.name.toLocaleLowerCase().includes(a)||e.id.toLocaleLowerCase().includes(a)});(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),j?S(!1):l())};return document.addEventListener("keydown",e,!0),()=>document.removeEventListener("keydown",e,!0)},[l,j]),(0,r.useEffect)(()=>{if(!j)return;let e=e=>{q.current?.contains(e.target)||S(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[j]);let V=(e,a)=>{U(t=>t.map((t,s)=>s===e?{...t,...a}:t))},X=x(I),Z=R.trim(),Y=d.test(Z),ee=Y&&!t.includes(Z)&&!!T.trim()&&I.length>0&&!X,ea=!!G&&("oauth"===C||!X),et=(0,r.useRef)(!1),es=async()=>{if(!et.current&&("builtin"===e?ea:ee)){et.current=!0,K(!0),J("");try{let a;if("builtin"===e&&G)if("oauth"===C&&c)a=await c(G.id);else{let e={};T.trim()&&(e.baseUrl=T.trim()),I.length&&(e.api=G.apis[0]??"openai-completions",e.models=I.map(v)),a=await i({providerId:G.id,apiKey:z.trim(),config:e})}else a=await o({providerId:Z,config:{name:L.trim()||Z,baseUrl:T.trim(),api:W,...z.trim()?{apiKey:z.trim()}:{},models:I.map(v)}});a.success?l():J(a.error||h.toastError)}catch(e){J(e instanceof Error?e.message:h.toastError)}finally{et.current=!1,K(!1)}}},er=async a=>{if(!T.trim())throw Error(h.apiAddress);let t=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"discoverModels",baseUrl:T.trim(),api:"builtin"===e?G?.apis[0]:W,apiKey:z.trim(),providerId:"builtin"===e?G?.id:void 0,allowPrivate:a})}),s=await t.json();if(!t.ok||!s.success)throw Error(s.error||h.toastError);return(s.data.models??[]).map(e=>({id:e.id,name:e.name??""}))};return(0,s.jsx)("div",{className:b().mask,"data-provider-modal":"true",onMouseDown:e=>{e.target===e.currentTarget&&l()},children:(0,s.jsxs)("section",{className:`${b().dialog} ${"builtin"===e?b().builtinDialog:""}`,role:"dialog","aria-modal":"true","aria-labelledby":"provider-setup-title",children:[(0,s.jsxs)("header",{className:b().header,children:[(0,s.jsx)("h2",{id:"provider-setup-title",className:b().title,children:"builtin"===e?h.addProvider:h.customProviderTitle}),(0,s.jsx)("button",{className:"icon-btn",title:h.close,"aria-label":h.close,onClick:l,children:(0,s.jsx)(n.Bh,{size:17})})]}),(0,s.jsxs)("div",{className:`${b().body} ${"builtin"===e?b().builtinBody:""}`,children:["builtin"===e?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.providerLabel}),(0,s.jsxs)("div",{className:b().picker,ref:q,children:[(0,s.jsxs)("button",{className:b().providerTrigger,"data-open":j,onClick:()=>S(e=>!e),children:[G?(0,s.jsx)(p,{id:G.id,name:G.name,size:34}):null,(0,s.jsxs)("span",{className:b().providerText,children:[(0,s.jsx)("span",{className:b().providerName,children:G?.name??h.selectProvider}),G?(0,s.jsx)("span",{className:b().providerMeta,children:G.id}):null]}),(0,s.jsx)(n.Cd,{size:15})]}),j?(0,s.jsxs)("div",{className:b().menu,children:[(0,s.jsxs)("div",{className:b().searchWrap,children:[(0,s.jsx)("span",{className:b().searchIcon,children:(0,s.jsx)(n.FG,{size:15})}),(0,s.jsx)("input",{autoFocus:!0,className:b().search,value:N,onChange:e=>k(e.target.value),placeholder:h.searchProviders})]}),(0,s.jsxs)("div",{className:b().providerList,children:[Q.map(e=>(0,s.jsxs)("button",{className:b().providerRow,"data-selected":e.id===f,onClick:()=>{g(e.id),_("api_key"),P(""),O(e.apis[0]??"openai-completions"),$(""),U([]),S(!1)},children:[(0,s.jsx)(p,{id:e.id,name:e.name,size:38}),(0,s.jsxs)("span",{className:b().providerText,children:[(0,s.jsx)("span",{className:b().providerName,children:e.name}),(0,s.jsxs)("span",{className:b().providerMeta,children:[e.id," \xb7 ",h.modelCount.replace("{count}",String(e.modelCount))]})]}),e.id===f?(0,s.jsx)("span",{className:b().selectedMark,children:(0,s.jsx)(n.df,{size:16})}):null]},e.id)),0===Q.length?(0,s.jsx)("div",{className:b().empty,children:h.noProviderMatches}):null]})]}):null]})]}),G?.authTypes.includes("oauth")&&c?(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.authMethod}),(0,s.jsxs)("select",{className:b().select,value:C,onChange:e=>_(e.target.value),children:[(0,s.jsx)("option",{value:"api_key",children:h.authMethodApiKey}),(0,s.jsx)("option",{value:"oauth",children:h.oauthLogin})]})]}):null,"api_key"===C?(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:G?.apiKeyLabel??h.apiKey}),(0,s.jsx)("input",{className:b().input,type:"password",value:z,onChange:e=>P(e.target.value),placeholder:h.apiKeyOptional})]}):null,(0,s.jsxs)("div",{className:b().advanced,children:[(0,s.jsxs)("button",{className:b().advancedButton,"data-open":M,onClick:()=>E(e=>!e),children:[(0,s.jsx)(n.Cd,{size:15}),h.customSettings]}),M?(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiAddress}),(0,s.jsx)("input",{className:b().input,value:T,onChange:e=>$(e.target.value),placeholder:G?.baseUrl||h.providerDefault})]}),(0,s.jsx)(w,{models:I,setModels:U,updateModel:V,inheritedCount:G?.modelCount??0,discover:er,discoverDisabled:!T.trim()})]}):null]})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.providerId}),(0,s.jsx)("input",{className:b().input,autoFocus:!0,value:R,onChange:e=>D(e.target.value.toLocaleLowerCase()),placeholder:"acme-gateway"}),(0,s.jsx)("div",{className:b().hint,children:h.providerIdHint}),Z&&!Y?(0,s.jsx)("div",{className:b().hint,style:{color:"var(--dsw-danger)"},children:h.providerIdInvalid}):null,Z&&t.includes(Z)?(0,s.jsx)("div",{className:b().hint,style:{color:"var(--dsw-danger)"},children:h.providerIdTaken}):null]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.displayName}),(0,s.jsx)("input",{className:b().input,value:L,onChange:e=>F(e.target.value),placeholder:h.displayName})]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiAddress}),(0,s.jsx)("input",{className:b().input,value:T,onChange:e=>$(e.target.value),placeholder:"https://gateway.example/v1"})]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiProtocol}),(0,s.jsx)("select",{className:b().select,value:W,onChange:e=>O(e.target.value),children:A.map(e=>(0,s.jsx)("option",{value:e,children:e},e))})]}),(0,s.jsxs)("div",{className:b().field,children:[(0,s.jsx)("label",{className:b().label,children:h.apiKey}),(0,s.jsx)("input",{className:b().input,type:"password",value:z,onChange:e=>P(e.target.value),placeholder:h.apiKeyOptional}),(0,s.jsx)("div",{className:b().hint,children:h.customApiKeyHint})]}),(0,s.jsx)(w,{models:I,setModels:U,updateModel:V,discover:er,discoverDisabled:!T.trim()})]}),H?(0,s.jsx)("div",{className:b().error,children:H}):null]}),(0,s.jsxs)("footer",{className:b().footer,children:[(0,s.jsx)("button",{className:b().footerButton,onClick:l,children:h.cancel}),(0,s.jsx)("button",{className:`${b().footerButton} ${b().primary}`,disabled:B||("builtin"===e?!ea:!ee),onClick:es,children:B?h.saving:"builtin"===e?h.save:h.createProvider})]})]})})}function w({models:e,setModels:a,updateModel:t,inheritedCount:l,discover:i,discoverDisabled:o}){let{t:d}=(0,m.s)(),[c,u]=(0,r.useState)(new Set),[p,h]=(0,r.useState)(!1),[v,f]=(0,r.useState)(""),[g,y]=(0,r.useState)(!1),[j,S]=(0,r.useState)(null),[N,k]=(0,r.useState)(new Set),[C,_]=(0,r.useState)({}),z=(e,a,t)=>{var s;return C[`${a}:${t}`]??(void 0===(s=e[t])||!Number.isFinite(s)||s<=0?"":s>=1e6&&s%1e6==0?`${s/1e6}M`:s>=1e3&&s%1e3==0?`${s/1e3}K`:String(s))},P=(e,a,s)=>{_(t=>({...t,[`${e}:${a}`]:s})),t(e,{[a]:function(e){let a=e.trim().toLowerCase();if(!a)return;let t=/^(\d+(?:\.\d+)?)\s*([km]?)$/.exec(a);if(!t)return NaN;let s=Math.round(Number(t[1])*("k"===t[2]?1e3:"m"===t[2]?1e6:1));return Number.isSafeInteger(s)&&s>0?s:NaN}(s)})},M=async()=>{if(i&&!p){h(!0),f("");try{let a=await i(g);if(!a.length)return void f(d.discoverEmpty);let t=new Set(e.map(e=>e.id.trim()).filter(Boolean));S(a),k(new Set(a.filter(e=>!t.has(e.id.trim())).map(e=>e.id)))}catch(e){f(e instanceof Error?e.message:d.toastError)}finally{h(!1)}}},E=()=>{S(null),k(new Set)},T=j??[],$=T.length>0&&T.every(e=>N.has(e.id)),R=x(e);return(0,s.jsxs)("div",{className:b().catalog,children:[(0,s.jsxs)("div",{className:b().catalogHeader,children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:b().label,children:d.modelCatalog}),(0,s.jsx)("div",{className:b().catalogStatus,children:l?d.usingDefaultModels.replace("{count}",String(l)):d.customModelsRequired})]}),i?(0,s.jsxs)("div",{className:b().discoverControls,children:[(0,s.jsxs)("label",{className:b().allowPrivate,title:d.allowPrivateHint,children:[(0,s.jsx)("input",{type:"checkbox",checked:g,onChange:e=>y(e.target.checked)}),d.allowPrivateDiscovery]}),(0,s.jsx)("button",{className:b().discoverButton,disabled:o||p,onClick:()=>void M(),children:p?d.discoveringModels:d.discoverModels})]}):null]}),v?(0,s.jsx)("div",{className:b().catalogError,children:v}):null,e.length?(0,s.jsx)("div",{className:b().modelList,children:e.map((e,r)=>{let l=c.has(r),i=Number.isNaN(e.contextWindow)||Number.isNaN(e.maxTokens);return(0,s.jsxs)("div",{className:b().modelEntry,children:[(0,s.jsxs)("div",{className:b().modelRow,children:[(0,s.jsx)("button",{type:"button",className:b().rowToggle,title:d.capacityFields,onClick:()=>u(e=>{let a=new Set(e);return a.delete(r)||a.add(r),a}),children:(0,s.jsx)(n.Cd,{size:13,style:{transform:l?"rotate(0deg)":"rotate(-90deg)",transition:"transform 120ms ease"}})}),(0,s.jsx)("input",{className:b().input,style:{borderColor:e.id.trim()||R?.index!==r?void 0:"var(--dsw-danger)"},value:e.id,onChange:e=>t(r,{id:e.target.value}),placeholder:d.modelId}),(0,s.jsx)("input",{className:b().input,value:e.name,onChange:e=>t(r,{name:e.target.value}),placeholder:d.displayNameOptional}),(0,s.jsx)("button",{className:b().removeModel,title:d.delete,onClick:()=>{a(e=>e.filter((e,a)=>a!==r)),u(e=>{let a=new Set;for(let t of e)t!==r&&a.add(t>r?t-1:t);return a}),_(e=>{let a={};for(let[t,s]of Object.entries(e)){let e=Number(t.slice(0,t.indexOf(":")));e!==r&&(a[e>r?`${e-1}${t.slice(t.indexOf(":"))}`:t]=s)}return a})},children:(0,s.jsx)(n.Vd,{size:15})})]}),l?(0,s.jsxs)("div",{className:b().capacityRow,children:[(0,s.jsxs)("label",{className:b().capacityField,children:[(0,s.jsx)("span",{children:d.contextWindowLabel}),(0,s.jsx)("input",{className:b().input,style:{borderColor:Number.isNaN(e.contextWindow)?"var(--dsw-danger)":void 0},value:z(e,r,"contextWindow"),onChange:e=>P(r,"contextWindow",e.target.value),placeholder:"128K"})]}),(0,s.jsxs)("label",{className:b().capacityField,children:[(0,s.jsx)("span",{children:d.maxTokensLabel}),(0,s.jsx)("input",{className:b().input,style:{borderColor:Number.isNaN(e.maxTokens)?"var(--dsw-danger)":void 0},value:z(e,r,"maxTokens"),onChange:e=>P(r,"maxTokens",e.target.value),placeholder:"16K"})]}),(0,s.jsx)("span",{className:b().capacityHint,children:d.capacityHint})]}):null,i?(0,s.jsx)("div",{className:b().rowError,children:d.capacityInvalid.replace("{n}",String(r+1))}):null]},r)})}):(0,s.jsx)("div",{className:b().modelEmpty,children:l?d.modelCatalogEmptyBuiltin:d.modelCatalogEmptyCustom}),(0,s.jsxs)("button",{className:b().addModel,onClick:()=>a(e=>[...e,{id:"",name:""}]),children:[(0,s.jsx)(n.Xh,{size:14}),d.addModel]}),j?(0,s.jsx)("div",{className:b().candidateMask,children:(0,s.jsxs)("div",{className:b().candidateDialog,role:"dialog","aria-modal":"true","aria-label":d.discoverModels,children:[(0,s.jsx)("div",{className:b().candidateHeader,children:(0,s.jsx)("span",{children:d.candidateTitle.replace("{count}",String(j.length))})}),(0,s.jsxs)("div",{className:b().candidateList,children:[T.map(e=>(0,s.jsxs)("label",{className:b().candidateRow,children:[(0,s.jsx)("input",{type:"checkbox",checked:N.has(e.id),onChange:()=>{let a;return a=e.id,k(e=>{let t=new Set(e);return t.delete(a)||t.add(a),t})}}),(0,s.jsx)("span",{className:b().candidateId,children:e.id}),e.name?(0,s.jsx)("span",{className:b().candidateName,children:e.name}):null]},e.id)),0===T.length?(0,s.jsx)("div",{className:b().modelEmpty,children:"—"}):null]}),(0,s.jsxs)("div",{className:b().candidateActions,children:[(0,s.jsxs)("label",{className:b().candidateAll,children:[(0,s.jsx)("input",{type:"checkbox",checked:$,onChange:()=>k(e=>{let a=new Set(e);return T.every(e=>a.has(e.id))?T.forEach(e=>a.delete(e.id)):T.forEach(e=>a.add(e.id)),a})}),d.candidateAll]}),(0,s.jsx)("span",{className:b().candidatePicked,children:d.candidatePicked.replace("{n}",String(N.size))}),(0,s.jsx)("button",{className:b().footerButton,onClick:E,children:d.cancel}),(0,s.jsx)("button",{className:`${b().footerButton} ${b().primary}`,disabled:0===N.size,onClick:()=>{j&&(a(e=>{let a=new Map(e.map(e=>[e.id.trim(),e]));for(let e of j){let t=e.id.trim();!t||!N.has(t)||a.has(t)||a.set(t,{id:t,name:e.name??""})}return[...a.values()]}),E())},children:d.candidateAdopt.replace("{n}",String(N.size))})]})]})}):null]})}let j=["claude","codex","grok","zcode","dsh","opencode"],S=e=>`${e.source}:${e.externalId}`;function N({cwd:e}){let{t:a}=(0,m.s)(),[t,l]=(0,r.useState)([]),[i,o]=(0,r.useState)([]),[d,c]=(0,r.useState)(new Set),[u,p]=(0,r.useState)(new Set),[h,x]=(0,r.useState)(!1),[v,f]=(0,r.useState)(!1),[g,b]=(0,r.useState)(null),[y,w]=(0,r.useState)(null),[k,C]=(0,r.useState)([]),[_,z]=(0,r.useState)(e),P=(0,r.useCallback)(async()=>{x(!0),w(null);try{let e=await fetch("/api/sessions/import"),t=await e.json();if(!t.success)return void w(t.error||a.toastError);let s=t.data.sessions??[],r=new Set(t.data.imported??[]),i=new Set(s.map(S));l(s),o(t.data.errors??[]),c(r),p(e=>new Set([...e].filter(e=>i.has(e)&&!r.has(e))))}catch(e){w(e instanceof Error?e.message:String(e))}finally{x(!1)}},[a]);(0,r.useEffect)(()=>{(async()=>{try{let e=await (await fetch("/api/workspaces")).json();e.success&&C(e.data.workspaces??[])}catch{}})()},[]),(0,r.useEffect)(()=>{P()},[P]);let M=(0,r.useMemo)(()=>{let e=new Map;for(let a of t){let t=e.get(a.source);t?t.push(a):e.set(a.source,[a])}return j.filter(a=>e.has(a)).map(a=>{let t=[...e.get(a)].sort((e,a)=>(a.updatedAt??a.createdAt??0)-(e.updatedAt??e.createdAt??0));return{source:a,rows:t,imported:t.filter(e=>d.has(S(e))).length}})},[t,d]),[E,T]=(0,r.useState)(""),$=M.reduce((e,a)=>{let t=a.rows[0],s=t?.updatedAt??t?.createdAt??0;return!e||s>e.at?{source:a.source,at:s}:e},null)?.source??"",R=E&&M.some(e=>e.source===E)?E:$,D=M.find(e=>e.source===R),L=(e,a)=>{p(t=>{let s=new Set(t);for(let t of e)d.has(S(t))||(a?s.add(S(t)):s.delete(S(t)));return s})},F=async()=>{if(!u.size)return;let e=t.filter(e=>u.has(S(e))).map(e=>({source:e.source,externalId:e.externalId}));f(!0),w(null),b(null);try{let t=await fetch("/api/sessions/import",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessions:e,fallbackCwd:_||void 0})}),s=await t.json();if(!s.success)return void w(s.error||a.toastError);b(s.data),p(new Set),await P()}catch(e){w(e instanceof Error?e.message:String(e))}finally{f(!1)}},A=e=>({claude:a.importSourceClaude,codex:a.importSourceCodex,grok:a.importSourceGrok,zcode:a.importSourceZcode,dsh:a.importSourceDsh,opencode:a.importSourceOpencode})[e]??e,W=g?.results.filter(e=>"failed"===e.status)??[],O=g?.results.filter(e=>"skipped"===e.status)??[],I=g?.results.filter(e=>"imported"===e.status&&e.skipped?.length)??[];return(0,s.jsxs)("div",{className:"flex flex-col gap-4","data-testid":"session-import",children:[(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:a.importDesc}),(0,s.jsx)("div",{style:{fontSize:11.5,color:"var(--dsw-label-caption)"},title:a.importLimitHintTooltip,"data-testid":"import-limit-hint",children:a.importLimitHint.replace("{n}",String(15))}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsxs)("button",{className:"flex items-center gap-1.5 rounded-lg px-2.5 py-1.5",style:{fontSize:12,border:"0.5px solid var(--dsw-border-l2)"},onClick:()=>void P(),disabled:h,"data-testid":"import-rescan",children:[(0,s.jsx)(n.Ct,{size:13})," ",h?a.importScanning:a.importRescan]}),(0,s.jsx)("span",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:a.importFallbackWorkspace}),(0,s.jsx)("select",{className:"rounded-lg px-2 py-1",style:{fontSize:12,border:"0.5px solid var(--dsw-border-l2)",background:"transparent",maxWidth:260},value:_,onChange:e=>z(e.target.value),"aria-label":a.importFallbackWorkspace,"data-testid":"import-fallback",children:(k.includes(_)||!_?k:[_,...k]).map(e=>(0,s.jsx)("option",{value:e,children:e},e))}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{className:"rounded-lg px-2.5 py-1.5",style:{fontSize:12,color:"var(--dsw-label-tertiary)"},onClick:()=>p(new Set),disabled:!u.size,children:a.importClearSelection}),(0,s.jsxs)("button",{className:"flex items-center gap-1.5 rounded-lg px-3 py-1.5",style:{fontSize:12,background:u.size&&!v?"var(--dsw-accent)":"var(--dsw-hover)",color:u.size&&!v?"#fff":"var(--dsw-label-caption)"},onClick:()=>void F(),disabled:!u.size||v,"data-testid":"import-run",children:[(0,s.jsx)(n.FQ,{size:13})," ",v?a.importRunning:a.importRun.replace("{n}",String(u.size))]})]}),y&&(0,s.jsx)("div",{role:"alert",className:"rounded-lg px-3 py-2",style:{fontSize:12.5,background:"var(--dsw-hover)",color:"var(--dsw-danger)"},children:y}),i.map(e=>(0,s.jsx)("div",{className:"rounded-lg px-3 py-2",style:{fontSize:12,background:"var(--dsw-hover)",color:"var(--dsw-label-tertiary)"},children:a.importSourceError.replace("{source}",A(e.source)).replace("{message}",e.message)},e.source)),g&&(0,s.jsxs)("div",{className:"rounded-2xl px-4 py-3",style:{border:"0.5px solid var(--dsw-border-l2)"},"data-testid":"import-report",children:[(0,s.jsx)("div",{style:{fontSize:13},children:a.importReportSummary.replace("{imported}",String(g.imported)).replace("{skipped}",String(g.skipped)).replace("{failed}",String(g.failed))}),O.map(e=>(0,s.jsxs)("div",{className:"mt-1",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:[A(e.source)," \xb7 ",e.title||e.externalId," — ",e.reason]},`skip-${e.source}-${e.externalId}`)),I.map(e=>(0,s.jsxs)("div",{className:"mt-1",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:[A(e.source)," \xb7 ",e.title||e.externalId," — ",e.skipped?.join(";")]},`note-${e.source}-${e.externalId}`)),W.map(e=>(0,s.jsxs)("div",{className:"mt-1",style:{fontSize:11.5,color:"var(--dsw-danger)"},children:[A(e.source)," \xb7 ",e.title||e.externalId," — ",e.reason]},`fail-${e.source}-${e.externalId}`))]}),!h&&!t.length&&!i.length&&(0,s.jsx)("div",{style:{fontSize:13,color:"var(--dsw-label-caption)"},children:a.importEmpty}),M.length>0&&(0,s.jsx)("div",{className:"flex flex-wrap items-center gap-1.5",role:"tablist","aria-label":a.importPickSource,"data-testid":"import-source-tabs",children:M.map(e=>{let a=e.source===R;return(0,s.jsxs)("button",{type:"button",role:"tab","aria-selected":a,className:"rounded-full px-3 py-1 transition-colors",style:{fontSize:12,border:`0.5px solid ${a?"var(--dsw-accent)":"var(--dsw-border-l2)"}`,background:a?"var(--dsw-accent)":"transparent",color:a?"#fff":"var(--dsw-label-tertiary)"},onClick:()=>T(e.source),"data-testid":`import-source-${e.source}`,children:[A(e.source),(0,s.jsx)("span",{style:{marginLeft:6,opacity:.75},children:e.rows.length})]},e.source)})}),D&&(0,s.jsxs)("div",{className:"flex flex-col gap-2","data-testid":`import-group-${D.source}`,children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:a.importGroupCount.replace("{n}",String(D.rows.length)).replace("{imported}",String(D.imported))}),(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsx)("button",{className:"rounded-lg px-2 py-0.5",style:{fontSize:11.5,color:"var(--dsw-label-tertiary)"},onClick:()=>L(D.rows,!0),children:a.importSelectAll}),(0,s.jsx)("button",{className:"rounded-lg px-2 py-0.5",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},onClick:()=>L(D.rows,!1),children:a.importSelectNone})]}),(0,s.jsx)("div",{className:"flex flex-col gap-1.5",children:D.rows.map(e=>{let t=S(e),r=d.has(t),l=u.has(t);return(0,s.jsxs)("label",{className:"flex cursor-pointer items-center gap-3 rounded-xl px-3 py-2",style:{border:`0.5px solid ${l?"var(--dsw-accent)":"var(--dsw-border-l2)"}`,opacity:r?.55:1},children:[(0,s.jsx)("input",{type:"checkbox",checked:l,disabled:r,onChange:()=>{!d.has(S(e))&&p(a=>{let t=new Set(a);return t.has(S(e))?t.delete(S(e)):t.add(S(e)),t})}}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{className:"truncate",style:{fontSize:12.5},title:e.title,children:e.title||a.importUntitled}),(0,s.jsx)("div",{className:"truncate",style:{fontSize:11,color:"var(--dsw-label-caption)"},title:e.projectPath,children:e.projectPath||a.importNoProject})]}),r&&(0,s.jsx)("span",{className:"rounded-full px-2 py-0.5",style:{fontSize:10,background:"var(--dsw-hover)",color:"var(--dsw-label-caption)"},children:a.importAlready}),(0,s.jsx)("span",{style:{fontSize:11,color:"var(--dsw-label-caption)",whiteSpace:"nowrap"},children:"number"==typeof e.messageCount?a.importMessages.replace("{n}",String(e.messageCount)):"—"}),(0,s.jsx)("span",{style:{fontSize:11,color:"var(--dsw-label-caption)",whiteSpace:"nowrap"},children:function(e){if(!e)return"";let a=new Date(e);if(Number.isNaN(a.getTime()))return"";let t=e=>String(e).padStart(2,"0");return`${a.getFullYear()}-${t(a.getMonth()+1)}-${t(a.getDate())}`}(e.updatedAt??e.createdAt)})]},t)})})]})]})}var k=t(6540);let C=["xai","openai-codex","anthropic","deepseek","openrouter","moonshotai","moonshotai-cn","kimi-coding","github-copilot","vercel-ai-gateway","opencode-go"];function _(e){return C.includes(e)}function z({open:e,onClose:a,cwd:t,toolPreset:l,onToolPresetChange:i,tools:o,onSetTools:d,onOpenFileContent:c}){let{t:u,lang:p,setLang:h}=(0,m.s)(),[x,v]=(0,r.useState)("general");if((0,r.useEffect)(()=>{if(!e)return;let t=e=>{"Escape"!==e.key||document.querySelector('[data-provider-modal="true"]')||a()};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,a]),!e)return null;let f=[{id:"general",label:u.setGeneral,icon:(0,s.jsx)(n.Ec,{size:15})},{id:"models",label:u.setModels,icon:(0,s.jsx)(n.se,{size:15})},{id:"tools",label:u.toolsSection,icon:(0,s.jsx)(n.DI,{size:15})},{id:"plugins",label:u.setPlugins,icon:(0,s.jsx)(n.q2,{size:15})},{id:"skills",label:u.setSkills,icon:(0,s.jsx)(n.i7,{size:15})},{id:"import",label:u.importSessions,icon:(0,s.jsx)(n.FQ,{size:15})}];return(0,s.jsx)("div",{className:"modal-mask fixed inset-0 z-[100] flex items-center justify-center",onMouseDown:e=>{e.target===e.currentTarget&&a()},children:(0,s.jsxs)("div",{className:"settings-dialog glass-modal flex overflow-hidden",style:{width:800,maxWidth:"calc(100vw - 48px)",height:"min(800px, calc(100vh - 48px))",borderRadius:32,boxShadow:"var(--dsw-elevation-prominent)"},children:[(0,s.jsxs)("div",{className:"settings-nav flex w-52 flex-none flex-col gap-0.5 py-4 pl-4 pr-3",children:[(0,s.jsx)("div",{className:"settings-title px-2 pb-3",style:{fontSize:16,fontWeight:500},children:u.settings}),f.map(e=>(0,s.jsxs)("button",{className:"flex h-[42px] items-center gap-2 rounded-xl px-3 text-left transition-colors",style:{paddingLeft:8,paddingRight:10,fontSize:14,background:x===e.id?"var(--dsw-active)":"transparent",color:x===e.id?"var(--dsw-label-primary)":"var(--dsw-label-secondary)"},onMouseEnter:a=>{x!==e.id&&(a.currentTarget.style.background="var(--dsw-hover)")},onMouseLeave:a=>{x!==e.id&&(a.currentTarget.style.background="transparent")},onClick:()=>v(e.id),children:[x===e.id?(0,s.jsx)("span",{style:{color:"var(--dsw-accent)"},children:e.icon}):e.icon,e.label]},e.id))]}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-1 flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 px-6 py-3.5",children:[(0,s.jsx)("div",{className:"flex-1"}),(0,s.jsxs)("button",{className:"btn-outline",style:{height:32,fontSize:13},onClick:()=>window.open("/api/config","_blank"),children:[(0,s.jsx)(n.FQ,{size:14})," ",u.openConfigFile]}),(0,s.jsx)("button",{className:"icon-btn",onClick:a,children:(0,s.jsx)(n.Bh,{size:15})})]}),(0,s.jsxs)("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-5",children:["general"===x&&(0,s.jsx)(P,{lang:p,setLang:h}),"models"===x&&(0,s.jsx)(L,{}),"skills"===x&&(0,s.jsx)(B,{cwd:t,onOpenFileContent:c}),"tools"===x&&(0,s.jsx)(U,{toolPreset:l,onToolPresetChange:i,tools:o,onSetTools:d}),"plugins"===x&&(0,s.jsx)(K,{cwd:t}),"import"===x&&(0,s.jsx)(N,{cwd:t})]})]})]})})}function P({lang:e,setLang:a}){let{t}=(0,m.s)(),[l,n]=(0,r.useState)("dsh"),[o,d]=(0,r.useState)("system"),[c,u]=(0,r.useState)(14),[p,h]=(0,r.useState)(14),[x,v]=(0,r.useState)("steer"),[f,g]=(0,r.useState)("ask"),[b,y]=(0,r.useState)(!1),[w,j]=(0,r.useState)(null),[S,N]=(0,r.useState)(null),[C,_]=(0,r.useState)(null),[z,L]=(0,r.useState)(!0),[F,A]=(0,r.useState)(!1),[W,O]=(0,r.useState)(null),[I,U]=(0,r.useState)({reserveTokens:"",keepRecentTokens:"",maxRetries:"",baseDelayMs:""}),B=async()=>{L(!0),O(null),y(!1);let e=async e=>{let a=await fetch(e),t=await a.json();if(!a.ok||!t.success)throw Error(t.error||`request failed (${a.status})`);return t.data},[a,t,s,r]=await Promise.allSettled([e("/api/security"),e("/api/pi-settings"),e("/api/version"),e("/api/web-auth")]);"fulfilled"===a.status&&(g(a.value.defaultProjectTrust),y(!0)),"fulfilled"===t.status?(j(t.value),U({reserveTokens:String(t.value.compaction.reserveTokens),keepRecentTokens:String(t.value.compaction.keepRecentTokens),maxRetries:String(t.value.retry.maxRetries),baseDelayMs:String(t.value.retry.baseDelayMs)})):j(null),"fulfilled"===s.status&&s.value?.piWeb?N({piWeb:s.value.piWeb,piEngine:s.value.piEngine}):N(null),"fulfilled"===r.status&&"boolean"==typeof r.value?.enabled?_({enabled:r.value.enabled,authenticated:!0===r.value.authenticated}):_(null),[a,t,s].some(e=>"rejected"===e.status)&&O("load"),L(!1)};(0,r.useEffect)(()=>{n((0,k.m6)()),d((0,k.Xf)());let e=parseInt(localStorage.getItem("piweb.fontSize")??"14",10);Number.isNaN(e)||u(e);let a=parseInt(localStorage.getItem("piweb.chatFontSize")??"14",10);Number.isNaN(a)||h(a),v((0,i.$h)()),B()},[]);let K=async e=>{if(!w||F)return!1;A(!0),O(null);try{let a=await fetch("/api/pi-settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),t=await a.json();if(!a.ok||!t.success)throw Error(t.error||"save failed");return j(t.data),!0}catch{return O("save"),!1}finally{A(!1)}},H=async(e,a)=>{if(!w)return;let t=I[a].trim(),s=Number(t);!t||!Number.isSafeInteger(s)||s<0||s>1e9?O("save"):s!==w[e][a]&&await K({[e]:{[a]:s}})},J=(e,a,t)=>(0,s.jsx)("input",{type:"number",min:0,value:I[a],disabled:!w||z||F,onChange:e=>U(t=>({...t,[a]:e.target.value})),onBlur:()=>void H(e,a),onKeyDown:e=>{"Enter"===e.key&&e.currentTarget.blur()},className:"rounded-lg px-2 py-1",title:t,style:{width:90,textAlign:"right",background:"var(--dsw-hover)"}}),q=async e=>{if(b&&!F){A(!0),O(null);try{let a=await fetch("/api/security",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultProjectTrust:e})}),t=await a.json();if(!a.ok||!t.success)throw Error(t.error||"save failed");g(e)}catch{O("save")}finally{A(!1)}}},G=[{id:"dsh",label:t.themeDsh,light:"#F9FAFB",dark:"#151517",accent:"#4176E6"},{id:"silver-steel",label:t.themeSilverSteel,light:"#F3F4F6",dark:"#1A1C24",accent:"#94A3B8"},{id:"limestone-coal",label:t.themeLimestoneCoal,light:"#F0EFEB",dark:"#171717",accent:"#CEB27E"},{id:"linen-moss",label:t.themeLinenMoss,light:"#F2F2EC",dark:"#1E211E",accent:"#A3B3A3"},{id:"nord-paper",label:t.themeNordPaper,light:"#FCFBF9",dark:"#2E3440",accent:"#88C0D0"},{id:"pebrel",label:t.themePebrel,light:"#F3F4F6",dark:"#0F111A",accent:"#52A8FF"}];return(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[(z||W)&&(0,s.jsxs)("div",{role:W?"alert":"status",className:"flex items-center gap-3 rounded-lg px-3 py-2",style:{background:"var(--dsw-hover)",color:W?"var(--dsw-danger)":"var(--dsw-label-secondary)"},children:[(0,s.jsx)("span",{className:"flex-1",children:"load"===W?t.settingsLoadFailed:"save"===W?t.settingsSaveFailed:t.settingsLoading}),"load"===W&&(0,s.jsx)("button",{type:"button",className:"pw-chip",onClick:()=>void B(),children:t.settingsRetry})]}),(0,s.jsx)($,{title:t.language,children:(0,s.jsx)(T,{value:e,options:[{value:"zh",label:"中文"},{value:"en",label:"English"}],onChange:e=>a(e)})}),(0,s.jsx)(R,{title:t.appearance,children:(0,s.jsx)("div",{className:"flex w-full flex-wrap gap-2",children:G.map(e=>(0,s.jsxs)("button",{className:"flex flex-col items-center justify-center gap-1 transition-colors",style:{flex:"1 1 150px",padding:"20px 32px",borderRadius:20,border:`0.5px solid ${l===e.id?"var(--dsw-border-strong)":"var(--dsw-border-l4)"}`,background:l===e.id?"var(--dsw-module-platform)":"transparent",color:"var(--dsw-label-primary)",fontSize:14,lineHeight:"22px"},"aria-pressed":l===e.id,onClick:()=>{var a;n(a=e.id),(0,k.kK)(a,o)},children:[(0,s.jsxs)("span",{className:"flex items-center overflow-hidden rounded-md",style:{border:"0.5px solid var(--dsw-border-l3)",width:42,height:20},children:[(0,s.jsx)("span",{style:{background:e.light,flex:1,height:"100%"}}),(0,s.jsx)("span",{style:{background:e.dark,flex:1,height:"100%"}})]}),(0,s.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("span",{className:"inline-block rounded-full",style:{width:8,height:8,background:e.accent}}),e.label]})]},e.id))})}),(0,s.jsx)(R,{title:t.appearanceMode,children:(0,s.jsx)("div",{className:"flex w-full flex-wrap gap-2",children:[{id:"light",label:t.themeLight},{id:"dark",label:t.themeDark},{id:"system",label:t.themeSystem}].map(e=>(0,s.jsx)("button",{className:"flex flex-col items-center justify-center gap-1 transition-colors",style:{flex:"1 1 120px",padding:"16px 24px",borderRadius:20,border:`0.5px solid ${o===e.id?"var(--dsw-border-strong)":"var(--dsw-border-l4)"}`,background:o===e.id?"var(--dsw-module-platform)":"transparent",color:"var(--dsw-label-primary)",fontSize:14,lineHeight:"22px"},"aria-pressed":o===e.id,onClick:()=>{var a;d(a=e.id),(0,k.kK)(l,a)},children:e.label},e.id))})}),(0,s.jsx)($,{title:t.fontUiSize,desc:t.fontUiSizeDesc,children:(0,s.jsx)(D,{value:c,onChange:e=>{let a=Math.max(12,Math.min(18,e));u(a),localStorage.setItem("piweb.fontSize",String(a)),document.documentElement.style.setProperty("--dsh-content-font-size",`${a}px`),document.documentElement.style.setProperty("--dsh-content-font-delta",`${a-14}px`)},max:18})}),(0,s.jsx)($,{title:t.fontChatSize,desc:t.fontChatSizeDesc,children:(0,s.jsx)(D,{value:p,onChange:e=>{let a=Math.max(12,Math.min(20,e));h(a),localStorage.setItem("piweb.chatFontSize",String(a)),document.documentElement.style.setProperty("--piweb-chat-font-size",`${a}px`)},max:20})}),(0,s.jsx)($,{title:t.enterBehavior,desc:t.enterBehaviorDesc,children:(0,s.jsx)(T,{value:x,options:[{value:"steer",label:t.enterSteer},{value:"queue",label:t.enterQueue}],onChange:e=>{v(e),(0,i.vf)(e)}})}),(0,s.jsx)($,{title:t.autoCompact,desc:t.autoCompactDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{disabled:!w||F,className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:w?.compaction.enabled?"var(--dsw-accent)":"var(--dsw-border-l3)"},role:"switch","aria-checked":w?.compaction.enabled??!1,onClick:()=>void K({compaction:{enabled:!w?.compaction.enabled}}),children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:w?.compaction.enabled?18:2}})}),J("compaction","reserveTokens",t.reserveTokens),J("compaction","keepRecentTokens",t.keepRecentTokens)]})}),(0,s.jsx)($,{title:t.autoRetry,desc:t.autoRetryDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{disabled:!w||F,className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:w?.retry.enabled?"var(--dsw-accent)":"var(--dsw-border-l3)"},role:"switch","aria-checked":w?.retry.enabled??!1,onClick:()=>void K({retry:{enabled:!w?.retry.enabled}}),children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:w?.retry.enabled?18:2}})}),J("retry","maxRetries",t.maxRetries),J("retry","baseDelayMs",t.baseDelayMs)]})}),(0,s.jsx)($,{title:t.securityTrust,desc:t.securityTrustDesc,children:(0,s.jsx)(T,{value:f,disabled:!b||z||F,options:[{value:"ask",label:t.trustAsk},{value:"always",label:t.trustAlways},{value:"never",label:t.trustNever}],onChange:e=>q(e)})}),(0,s.jsx)($,{title:t.versionPiweb,desc:t.versionPiwebDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)(M,{href:"https://github.com/RexVane/PiWeb",value:S?.piWeb}),(0,s.jsx)(E,{target:"piweb"})]})}),(0,s.jsx)($,{title:t.versionPi,desc:t.versionPiDesc,children:(0,s.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,s.jsx)(M,{href:"https://github.com/earendil-works/pi",value:S?.piEngine}),(0,s.jsx)(E,{target:"pi"})]})}),C?.enabled?(0,s.jsx)($,{title:t.webAuth,desc:t.webAuthOn,children:(0,s.jsx)("button",{className:"btn-outline",style:{height:30,padding:"0 14px",fontSize:12.5},onClick:async()=>{await fetch("/api/web-auth",{method:"DELETE"}).catch(()=>{}),window.location.href="/login"},children:t.logout})}):null]})}function M({href:e,value:a}){return(0,s.jsx)("a",{href:e,target:"_blank",rel:"noreferrer",style:{fontFamily:"var(--font-mono)",fontSize:13,color:"var(--dsw-label-secondary)",textDecoration:"none"},onMouseEnter:e=>e.currentTarget.style.color="var(--dsw-accent)",onMouseLeave:e=>e.currentTarget.style.color="var(--dsw-label-secondary)",children:a??"—"})}function E({target:e}){let{t:a}=(0,m.s)(),[t,l]=(0,r.useState)("idle"),[i,n]=(0,r.useState)(""),[o,d]=(0,r.useState)(""),[c,u]=(0,r.useState)(""),p=async a=>(await fetch("/api/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:e,action:a})})).json(),h=async()=>{l("checking"),u("");try{let e=await p("check");if(!e.success)throw Error(e.error);e.data.canUpdate?(n(e.data.latest),d(e.data.command??""),l("available")):l("latest")}catch(e){u(String(e?.message??e)),l("error")}},x=async()=>{l("updating");try{let e=await p("update");if(!e.success)throw Error(e.error);n(e.data.version??i),l("updated")}catch(e){u(String(e?.message??e)),l("error")}};if("idle"===t||"latest"===t||"error"===t){let e="latest"===t?a.upToDate:"error"===t?a.updateFailed:a.checkUpdate;return(0,s.jsx)("button",{type:"button",className:"btn-outline",style:{height:26,padding:"0 10px",fontSize:12,color:"latest"===t?"var(--dsw-label-tertiary)":"error"===t?"var(--dsw-danger)":"var(--dsw-label-primary)"},title:c||void 0,disabled:"checking"===t||"updating"===t,onClick:()=>void h(),children:e})}return"available"===t?o?(0,s.jsxs)("span",{className:"flex flex-col items-end gap-0.5",style:{maxWidth:300},children:[(0,s.jsx)("code",{style:{fontSize:11,color:"var(--dsw-label-primary)",whiteSpace:"nowrap",overflowX:"auto",maxWidth:"100%"},children:o}),(0,s.jsx)("span",{style:{fontSize:11,color:"var(--dsw-label-tertiary)",textAlign:"right"},children:a.updateManualHint})]}):(0,s.jsx)("button",{type:"button",className:"btn-primary-white",style:{height:26,padding:"0 12px",fontSize:12},onClick:()=>void x(),children:a.updateTo.replace("{v}",i)}):"updated"===t?(0,s.jsx)("span",{style:{fontSize:12,color:"var(--dsw-success)",maxWidth:260,textAlign:"right"},children:a.updatedTo.replace("{v}",i)}):(0,s.jsxs)("span",{className:"flex items-center gap-1.5",style:{fontSize:12,color:"var(--dsw-label-tertiary)"},children:[(0,s.jsx)("span",{className:"h-3 w-3 flex-none animate-spin rounded-full border-2 border-current border-t-transparent"}),"updating"===t?a.updatingNow:a.checkingUpdate]})}function T({value:e,options:a,onChange:t,width:i,disabled:o}){let[d,c]=(0,r.useState)(!1),[u,p]=(0,r.useState)(null),m=(0,r.useRef)(null),h=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!d)return;let e=m.current?.getBoundingClientRect();e&&p({left:e.left,top:e.bottom+6,bottom:e.top-6});let a=e=>{m.current?.contains(e.target)||h.current?.contains(e.target)||c(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[d]),(0,r.useEffect)(()=>{o&&c(!1)},[o]);let x=a.find(a=>a.value===e);return(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsxs)("button",{ref:m,className:"select-chip","data-open":d,disabled:o,onClick:()=>c(e=>!e),children:[x?.label??e,(0,s.jsx)("span",{className:"chevron",children:(0,s.jsx)(n.Cd,{size:14})})]}),d&&!o&&u&&(0,l.createPortal)((0,s.jsx)("div",{ref:h,className:"popover fixed z-[130] p-1.5 shadow-xl",style:{left:u.left,top:Math.min(u.top,window.innerHeight-40),minWidth:i??140,width:"max-content",maxHeight:280,overflowY:"auto"},children:a.map(a=>{let r=a.value===e;return(0,s.jsxs)("button",{className:"flex w-full items-center justify-between gap-3 rounded-xl px-3.5 py-2 text-left transition-colors",style:{background:r?"var(--dsw-accent-soft)":"transparent"},onMouseEnter:e=>{r||(e.currentTarget.style.background="var(--dsw-hover)")},onMouseLeave:e=>{r||(e.currentTarget.style.background="transparent")},onClick:()=>{t(a.value),c(!1)},children:[(0,s.jsx)("span",{style:{fontSize:13.5,color:r?"var(--dsw-accent)":"var(--dsw-label-primary)",whiteSpace:"nowrap"},children:a.label}),r&&(0,s.jsx)("span",{style:{display:"inline-flex",color:"var(--dsw-accent)",flex:"none"},children:(0,s.jsx)(n.df,{size:14})})]},a.value)})}),document.body)]})}function $({title:e,desc:a,children:t}){return(0,s.jsxs)("div",{className:"hairline-b flex items-center justify-between gap-6 pb-5",children:[(0,s.jsxs)("div",{className:"min-w-0",children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:e}),a&&(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:a})]}),(0,s.jsx)("div",{className:"flex-none",children:t})]})}function R({title:e,desc:a,children:t}){return(0,s.jsxs)("div",{className:"hairline-b flex flex-col gap-3 pb-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:e}),a&&(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:a})]}),t]})}function D({value:e,onChange:a,max:t}){return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("button",{className:"icon-btn",style:{width:26,height:26,border:"0.5px solid var(--dsw-border-l3)",borderRadius:8},disabled:e<=12,onClick:()=>a(e-1),"aria-label":"decrease font size",children:"−"}),(0,s.jsxs)("button",{style:{minWidth:48,textAlign:"center",fontSize:13,color:14===e?"var(--dsw-label-tertiary)":"var(--dsw-label-primary)"},title:"reset",onClick:()=>a(14),children:[e," px"]}),(0,s.jsx)("button",{className:"icon-btn",style:{width:26,height:26,border:"0.5px solid var(--dsw-border-l3)",borderRadius:8},disabled:e>=t,onClick:()=>a(e+1),"aria-label":"increase font size",children:"+"})]})}function L(){let{t:e}=(0,m.s)(),[a,t]=(0,r.useState)([]),[l,i]=(0,r.useState)({providers:{}}),[o,d]=(0,r.useState)(null),[c,v]=(0,r.useState)(new Set),[g,b]=(0,r.useState)(null),[j,S]=(0,r.useState)(""),[N,k]=(0,r.useState)(null),[C,z]=(0,r.useState)(""),[P,M]=(0,r.useState)(""),[E,$]=(0,r.useState)("openai-completions"),[R,D]=(0,r.useState)(""),[L,I]=(0,r.useState)([]),[U,B]=(0,r.useState)(""),[K,H]=(0,r.useState)(""),[J,q]=(0,r.useState)([]),[G,Q]=(0,r.useState)(!1),[V,X]=(0,r.useState)(!1),[Z,Y]=(0,r.useState)(null),[ee,ea]=(0,r.useState)(null),[et,es]=(0,r.useState)(null),[er,el]=(0,r.useState)([]),[ei,en]=(0,r.useState)(""),[eo,ed]=(0,r.useState)(null),[ec,eu]=(0,r.useState)(!1),ep=(0,r.useMemo)(()=>{for(let e=er.length-1;e>=0;e--){let a=er[e];if(a.startsWith("{"))try{let e=JSON.parse(a);if("device_code"===e.type&&"string"==typeof e.verificationUri)return{userCode:"string"==typeof e.userCode?e.userCode:"",verificationUri:e.verificationUri,instructions:""};if("auth_url"===e.type&&"string"==typeof e.url)return{userCode:"",verificationUri:e.url,instructions:"string"==typeof e.instructions?e.instructions:""}}catch{}}return null},[er]),em=(0,r.useRef)(null);(0,r.useEffect)(()=>{ep?.verificationUri&&em.current!==ep.verificationUri&&(em.current=ep.verificationUri,window.open(ep.verificationUri,"_blank","noopener"))},[ep]);let eh=(0,r.useCallback)(async()=>{try{let e=await fetch("/api/models?custom=1"),a=await e.json();if(!e.ok||!a.success)throw Error(a.error||"failed to load model configuration");let s=JSON.parse(a.data.customProviders?.content??"{}");if(!s||"object"!=typeof s||Array.isArray(s)||void 0!==s.providers&&(!s.providers||"object"!=typeof s.providers||Array.isArray(s.providers)))throw Error("invalid model configuration");t(a.data.providers),v(new Set(a.data.customProviders?.secretProviderIds??[])),i({...s,providers:s.providers??{}}),d("string"==typeof a.data.customProviders?.revision?a.data.customProviders.revision:null)}catch(e){d(null),Y({ok:!1,msg:e instanceof Error?e.message:"failed to load model configuration"})}},[]);(0,r.useEffect)(()=>{eh()},[eh]),(0,r.useEffect)(()=>{let e;if(!ee)return;let a=!0,t=!1,s=async()=>{try{let e=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"loginState",providerId:ee})}),s=await e.json();if(!a||!s.success)return;es(s.data.prompt),el(s.data.notifyLog??[]),s.data.done&&(t=!0,ed({ok:!s.data.error,msg:s.data.error??ee+" ✓"}),s.data.error||eh())}catch{}finally{a&&!t&&(e=setTimeout(s,1500))}};return s(),()=>{a=!1,e&&clearTimeout(e)}},[ee,eh]);let[ex,ev]=(0,r.useState)(null),[ef,eg]=(0,r.useState)(!1),[eb,ey]=(0,r.useState)(!1),ew=(0,r.useCallback)(async e=>{eg(!0),ey(!1);try{let a=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"providerUsage",providerId:"xai",force:e})}),t=await a.json();if(!a.ok||!t.success)throw Error(t.error||"usage probe failed");ev(t.data.usage??null)}catch{ey(!0)}finally{eg(!1)}},[]),[ej,eS]=(0,r.useState)({}),[eN,ek]=(0,r.useState)(null),[eC,e_]=(0,r.useState)({}),ez=(0,r.useCallback)(async(e,a)=>{ek(e),e_(a=>({...a,[e]:!1}));try{let t=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"providerUsage",providerId:e,force:a})}),s=await t.json();if(!t.ok||!s.success)throw Error(s.error||"usage probe failed");eS(a=>({...a,[e]:s.data.usage??null}))}catch{e_(a=>({...a,[e]:!0}))}finally{ek(a=>a===e?null:a)}},[]),eP=(0,r.useRef)(new Set);(0,r.useEffect)(()=>{for(let e of a)!e.authReady||!_(e.id)||"xai"===e.id||eP.current.has(e.id)||(eP.current.add(e.id),ez(e.id,!1))},[a,ez]);let eM=e=>`${"USD"===e.currency?"$":"CNY"===e.currency?"\xa5":""}${e.amount}${e.currency&&"USD"!==e.currency&&"CNY"!==e.currency?` ${e.currency}`:""}`,eE=(a,t)=>{Y({ok:a,msg:t??(a?e.toastSaved:e.toastError)}),setTimeout(()=>Y(null),2400)},eT=async a=>{try{let e=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),t=await e.json();return e.ok?t:{...t,success:!1,error:t.error||`request failed (${e.status})`}}catch(a){return{success:!1,error:a instanceof Error?a.message:e.toastError}}},e$=async a=>{let t=await eT(a);return eE(t.success,t.success&&t.data?.requiresSessionReopen?e.modelConfigReopen:t.error),t.success&&await eh(),t},eR=async a=>{if(ee)try{let t=await eT({action:"loginAnswer",providerId:ee,text:a});if(!t.success||t.data?.delivered!==!0)throw Error(t.error||e.toastError);en("")}catch(a){eE(!1,a instanceof Error?a.message:e.toastError)}},eD=async()=>{if(ee)try{let a=await eT({action:"loginCancel",providerId:ee});if(!a.success)throw Error(a.error||e.toastError);ea(null)}catch(a){eE(!1,a instanceof Error?a.message:e.toastError)}},eL=new Set(Object.keys(l.providers??{})),eF=a.filter(e=>e.authReady||e.authConfigured||e.keyManaged||eL.has(e.id)),eA=a.filter(e=>e.builtIn&&!eF.some(a=>a.id===e.id)),eW=async e=>{if(null===o){let e={success:!1,error:"Reload model configuration before saving."};return eE(!1,e.error),e}return e$({action:"saveCustomProviders",revision:o,content:JSON.stringify({...l,providers:e},null,2)})},eO=e=>a.find(a=>a.id===e)?.name??e,eI=async()=>{if(!G&&!x(L)&&P.trim()){Q(!0);try{let e={...l.providers},a=g??C.trim(),t=e[a]??{};a!==C.trim()&&delete e[a],e[C.trim()]=f(t,{name:U,baseUrl:P,api:E,apiKey:R,models:L}),(await eW(e)).success&&b(null)}finally{Q(!1)}}},eU=async e=>{if(!G&&!x(J)){Q(!0);try{let a={...l.providers};a[e.id]=f(a[e.id]??{},{baseUrl:K,models:J},e.apis[0]??"openai-completions");let t=await eW(a);t.success&&j.trim()&&(e$({action:"setKey",providerId:e.id,apiKey:j.trim()}),ed(null),ea(e.id)),t.success&&b(null)}finally{Q(!1)}}},eB=async t=>{if(!window.confirm(e.confirmRemoveProvider.replace("{name}",eO(t))))return;let s={...l.providers};delete s[t];let r=a.find(e=>e.id===t);if(r?.builtIn)try{await e$({action:"removeKey",providerId:t})}catch{}(await eW(s)).success&&b(null)},eK=async({providerId:e,apiKey:a,config:t})=>{let s={...l.providers,[e]:{...l.providers[e],...t}},r=await eW(s);return r.success&&a&&(eT({action:"setKey",providerId:e,apiKey:a}),ed(null),ea(e)),r},eH=async({providerId:e,config:a})=>eW({...l.providers,[e]:a}),eJ=async e=>{let a=await eT({action:"loginStart",providerId:e});return a.success?(ed(null),ea(e),{success:!0}):{success:!1,error:a.error}};return(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:e.modelsTitle}),(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:e.modelsDesc}),(0,s.jsx)("div",{className:"mt-1",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:e.customModelIdentityNotice})]}),Z&&(0,s.jsx)("div",{className:"rounded-xl px-3 py-2",style:{fontSize:12.5,background:Z.ok?"rgba(34,197,94,.1)":"rgba(236,19,19,.1)",color:Z.ok?"var(--dsw-success)":"var(--dsw-danger)"},children:Z.msg}),(0,s.jsx)("div",{className:"flex flex-col gap-2.5",children:eF.map(t=>{var r;let i,d,m,v,f=eL.has(t.id)&&!t.builtIn,y=g===t.id;return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex flex-col rounded-2xl px-4 py-3",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)(p,{id:t.id,name:eO(t.id),size:34}),(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{className:"truncate",style:{fontSize:14,fontWeight:500},children:eO(t.id)}),(0,s.jsxs)("div",{className:"truncate",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:[t.id,t.baseUrl?` \xb7 ${t.baseUrl}`:""]})]}),f&&(0,s.jsx)("span",{className:"rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:e.customBadge}),(0,s.jsx)("span",{className:"inline-block h-2 w-2 rounded-full",style:{background:t.authReady?"var(--dsw-success)":"var(--dsw-danger)"},title:t.authError||(t.authReady?e.providerReady:e.authUnavailable)}),(0,s.jsx)("span",{className:"rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:e.credentialSource.replace("{source}","stored"===(i=t.authSource)?"auth.json":"runtime"===i?e.authSourceRuntime:"environment"===i?e.authSourceEnvironment:"models_json_key"===i?"models.json":"models_json_command"===i?e.authSourceCommand:"fallback"===i?e.authSourceProvider:t.resolvedAuthSource||e.authUnavailable)}),(0,s.jsx)("button",{className:"btn-outline",style:{height:28,padding:"0 12px",fontSize:12},onClick:()=>{var e;let s;return b(g===(e=t.id)?null:e),S(""),Q(!1),X(!1),s=l.providers[e],void(eL.has(e)&&!a.find(a=>a.id===e)?.builtIn?(z(e),M(s?.baseUrl??""),$(s?.api??"openai-completions"),D(""),B("string"==typeof s?.name?s.name:""),I((s?.models??[]).map(h))):(H("string"==typeof s?.baseUrl?s.baseUrl:""),q((s?.models??[]).map(h))))},children:e.edit}),"oauth"===t.storedAuthType&&(0,s.jsx)("button",{style:{height:28,padding:"0 12px",fontSize:12,color:"var(--dsw-danger)"},onClick:async()=>{window.confirm(e.confirmRemoveOAuth.replace("{name}",eO(t.id)))&&await e$({action:"removeKey",providerId:t.id})},children:e.removeOAuth}),t.authTypes?.includes("oauth")&&(0,s.jsx)("button",{className:"btn-outline",style:{height:28,padding:"0 12px",fontSize:12},onClick:()=>{ed(null),e$({action:"loginStart",providerId:t.id}),ea(t.id)},children:e.oauthLogin}),eL.has(t.id)&&(0,s.jsx)("button",{style:{fontSize:12.5,color:"var(--dsw-danger)"},onClick:()=>eB(t.id),children:e.delete})]}),"xai"===t.id&&t.authReady&&(0,s.jsxs)("div",{className:"mt-3 flex items-center gap-2 pt-3",style:{borderTop:"0.5px solid var(--dsw-border-l2)",fontSize:11.5,color:"var(--dsw-label-tertiary)"},children:[ex?(0,s.jsxs)("span",{children:[e.usageQuotaLabel," \xb7 ",ex.model," \xb7 ",e.usageRequests," ",ex.requestRemaining.toLocaleString(),"/",ex.requestLimit.toLocaleString()," \xb7 Tokens ",A(ex.tokenRemaining),"/",A(ex.tokenLimit)]}):(0,s.jsx)("span",{children:eb?e.usageProbeFailed:e.usageProbeDisclosure}),(0,s.jsx)("button",{type:"button",className:"pw-chip",disabled:ef,title:e.usageProbeDisclosure,onClick:()=>void ew(!0),children:ef?e.usageProbing:ex?e.usageRefresh:e.usageProbe})]}),_(t.id)&&"xai"!==t.id&&t.authReady&&(0,s.jsx)("div",{className:"mt-3 flex flex-col gap-1.5 pt-3",style:{borderTop:"0.5px solid var(--dsw-border-l2)",fontSize:11.5,color:"var(--dsw-label-tertiary)"},children:(d=ej[r=t.id],m=eN===r,v=eC[r],(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[!d&&(0,s.jsx)("span",{children:v?e.usageProbeFailed:m?e.queryingQuota:e.usageReadOnlyDisclosure}),d?.kind==="quota"&&d.planType&&(0,s.jsxs)("span",{children:[e.usagePlan," ",W(d.planType)]}),d?.kind==="balance"&&d.primary&&(0,s.jsxs)("span",{children:["used"===d.primaryKey?e.usageBalanceUsed:e.usageQuotaRemaining," ",(0,s.jsx)("span",{style:{color:"var(--dsw-label-secondary)"},children:eM(d.primary)})]}),(0,s.jsx)("button",{type:"button",className:"pw-chip",disabled:m,title:e.usageReadOnlyDisclosure,onClick:()=>void ez(r,!0),children:m?e.usageProbing:d?e.usageRefresh:e.usageProbe})]}),d?.kind==="balance"&&d.details.length>0&&(0,s.jsx)("span",{children:d.details.map(a=>{var t;return`${"granted"===(t=a.key)?e.usageBalanceGranted:"toppedUp"===t?e.usageBalanceToppedUp:"voucher"===t?e.usageBalanceVoucher:"cash"===t?e.usageBalanceCash:"used"===t?e.usageBalanceUsed:e.usageBalanceLimit} ${eM(a)}`}).join(" \xb7 ")}),d?.kind==="quota"&&0===d.windows.length&&(0,s.jsxs)("span",{children:[e.usageQuotaRemaining," —"]}),d?.kind==="quota"&&d.windows.map((a,t)=>{var r;return(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{style:{width:84,flex:"none"},children:(a=>{var t,s,r,l;if(void 0!==a.limitWindowSeconds){let l;return`${"weekly"==(l=604800===(s=t=a.limitWindowSeconds)?"weekly":2592e3===s?"monthly":s<86400?"hours":"days")?e.usageWindowWeekly:"monthly"===l?e.usageWindowMonthly:("hours"===l?e.usageWindowHours:e.usageWindowDays).replace("{n}",String(Math.round(t/("hours"===l?3600:86400))))}${a.variant?` (${"opus"===(r=a.variant)?e.usageVariantOpus:"code"===r?e.usageVariantCode:W(r)})`:""}`}return a.name?"premium"===(l=a.name)?e.usageWindowPremium:"chat"===l?e.usageWindowChat:"completions"===l?e.usageWindowCompletions:"rolling"===l?e.usageWindowRolling:W(l):""})(a)}),(0,s.jsxs)("span",{style:{width:92,flex:"none"},children:[e.usageQuotaRemaining," ",a.remainingPercent,"%"]}),(0,s.jsxs)("span",{children:[e.usageReset," ",function(e){if(!e)return"—";let a=new Date(e);return Number.isNaN(a.getTime())?"—":a.toLocaleString()}(a.resetAt)]}),(0,s.jsx)("div",{className:"h-1 overflow-hidden rounded-full",style:{width:120,flex:"none",background:"var(--dsw-border-l2)"},children:(0,s.jsx)("div",{className:"h-full rounded-full",style:{width:`${a.remainingPercent}%`,background:(r=a.remainingPercent)<30?"var(--dsw-danger)":r<=60?"var(--dsw-warning)":"var(--dsw-success)"}})})]},`${a.limitWindowSeconds??a.name??"window"}-${a.variant??""}-${t}`)})]}))})]}),y&&(0,s.jsx)("div",{className:"mt-2 rounded-2xl p-4",style:{border:"0.5px solid var(--dsw-border-l2)"},children:f?(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)(O,{label:e.apiKey,children:(0,s.jsx)("input",{type:"password",value:R,onChange:e=>D(e.target.value),className:F,placeholder:c.has(t.id)?e.apiKeyStored:e.apiKeyOptional})}),(0,s.jsx)(O,{label:e.displayName,children:(0,s.jsx)("input",{value:U,onChange:e=>B(e.target.value),className:F,placeholder:t.id})}),(0,s.jsx)(O,{label:e.baseUrl,children:(0,s.jsx)("input",{value:P,onChange:e=>M(e.target.value),className:F,placeholder:"https://api.example.com/v1"})}),(0,s.jsx)(O,{label:e.apiType,children:(0,s.jsx)(T,{value:E,options:u([E,...t.apis]).map(e=>({value:e,label:e})),onChange:$})}),(0,s.jsx)(w,{models:L,setModels:I,updateModel:(e,a)=>I(t=>t.map((t,s)=>s===e?{...t,...a}:t)),discover:async a=>{let s=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"discoverModels",providerId:t.id,baseUrl:P.trim(),api:E,apiKey:R.trim(),allowPrivate:a})}),r=await s.json();if(!r.success)throw Error(r.error||e.toastError);return(r.data.models??[]).map(e=>({id:e.id,name:e.name??""}))},discoverDisabled:!P.trim()}),(0,s.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,s.jsx)("button",{className:"btn-outline",style:{height:32},disabled:G,onClick:()=>b(null),children:e.cancel}),(0,s.jsx)("button",{className:"btn-primary-white",disabled:G||!P.trim()||!!x(L)||!L.some(e=>e.id.trim()),onClick:()=>void eI(),children:G?e.saving:e.save})]})]}):(0,s.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,s.jsx)(O,{label:e.apiKey,children:(0,s.jsx)("input",{type:"password",value:j,onChange:e=>S(e.target.value),className:F,placeholder:t.keyManaged?e.apiKeyStored:t.apiKeyLabel??e.apiKey})}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{className:"flex w-full items-center gap-2 rounded-xl px-2 py-2 text-left transition-colors",style:{fontSize:13,color:"var(--dsw-label-secondary)",background:V?"var(--dsw-hover)":"transparent"},onClick:()=>X(e=>!e),children:[(0,s.jsx)("span",{style:{display:"inline-flex",transform:V?"none":"rotate(-90deg)",transition:"transform 120ms ease"},children:(0,s.jsx)(n.Cd,{size:13})}),e.customSettings]}),V?(0,s.jsxs)("div",{className:"flex flex-col gap-3 pl-1 pt-2",children:[(0,s.jsx)(O,{label:e.baseUrl,children:(0,s.jsx)("input",{value:K,onChange:e=>H(e.target.value),className:F,placeholder:t.baseUrl??e.providerDefault})}),(0,s.jsx)(w,{models:J,setModels:q,updateModel:(e,a)=>q(t=>t.map((t,s)=>s===e?{...t,...a}:t)),inheritedCount:t.modelCount,discover:async a=>{let s=await fetch("/api/models",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"discoverModels",providerId:t.id,baseUrl:K.trim()||t.baseUrl||"",api:t.apis[0],apiKey:j.trim(),allowPrivate:a})}),r=await s.json();if(!r.success)throw Error(r.error||e.toastError);return(r.data.models??[]).map(e=>({id:e.id,name:e.name??""}))},discoverDisabled:!(K.trim()||t.baseUrl)})]}):null]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[t.keyManaged&&(0,s.jsx)("button",{style:{fontSize:12.5,color:"var(--dsw-danger)"},disabled:G,onClick:async()=>{if("oauth"===t.storedAuthType){if(!window.confirm(e.confirmRemoveOAuth.replace("{name}",t.name)))return}else if(!window.confirm(e.confirmRemoveKey.replace("{name}",t.name)))return;(await e$({action:"removeKey",providerId:t.id})).success&&b(null)},children:"oauth"===t.storedAuthType?e.removeOAuth:e.removeKey}),(0,s.jsx)("button",{className:"btn-outline",style:{height:32},disabled:G,onClick:()=>b(null),children:e.cancel}),(0,s.jsx)("button",{className:"btn-primary-white",disabled:G||null===o||!!x(J),onClick:()=>void eU({id:t.id,apis:t.apis}),children:G?e.saving:e.save})]})]})})]},t.id)})}),(0,s.jsxs)("div",{className:"flex gap-3",children:[(0,s.jsxs)("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-2xl px-4 py-3.5 transition-colors",style:{border:"0.5px solid var(--dsw-border-l3)",fontSize:14},onMouseEnter:e=>e.currentTarget.style.background="var(--dsw-hover)",onMouseLeave:e=>e.currentTarget.style.background="transparent",onClick:()=>k("builtin"),children:[(0,s.jsx)(n.Xh,{size:15}),e.addProvider]}),(0,s.jsxs)("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-2xl px-4 py-3.5 transition-colors",style:{border:"0.5px solid var(--dsw-border-l3)",fontSize:14},onMouseEnter:e=>e.currentTarget.style.background="var(--dsw-hover)",onMouseLeave:e=>e.currentTarget.style.background="transparent",onClick:()=>k("custom"),children:[(0,s.jsx)(n.Xh,{size:15}),e.addCustomProvider]})]}),N?(0,s.jsx)(y,{mode:N,providers:eA,existingIds:a.map(e=>e.id),onClose:()=>k(null),onSaveBuiltin:eK,onSaveCustom:eH,onOAuthLogin:eJ}):null,ee&&(0,s.jsx)("div",{className:"modal-mask fixed inset-0 z-[120] flex items-center justify-center",onMouseDown:e=>{e.target===e.currentTarget&&eD()},children:(0,s.jsxs)("div",{className:"glass-modal flex flex-col gap-4 p-6",style:{width:460,maxWidth:"92vw",borderRadius:24,boxShadow:"var(--dsw-elevation-prominent)"},children:[(0,s.jsxs)("div",{style:{fontSize:15,fontWeight:600},children:[e.oauthLogin," \xb7 ",ee]}),ep&&!eo?(0,s.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,s.jsx)("div",{style:{fontSize:13,color:"var(--dsw-label-primary)"},children:e.oauthDevicePrompt}),ep.instructions?(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-label-tertiary)"},children:ep.instructions}):null,(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("a",{href:ep.verificationUri,target:"_blank",rel:"noreferrer",className:"btn-primary-white",style:{fontSize:12.5,textDecoration:"none"},children:e.oauthOpenAuth}),ep.userCode?(0,s.jsx)("button",{className:"btn-outline",style:{height:32},onClick:()=>{if(!ep?.userCode)return;let e=ep.userCode,a=()=>{eu(!0),setTimeout(()=>eu(!1),2e3)};navigator.clipboard.writeText(e).then(a).catch(()=>{let t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),t.remove(),a()})},children:ec?e.oauthCodeCopied:`${e.oauthDeviceCode}: ${ep.userCode}`}):null]})]}):er.length>0?(0,s.jsx)("div",{className:"flex flex-col gap-0.5",style:{fontSize:12,color:"var(--dsw-label-tertiary)"},children:er.slice(-3).map((e,a)=>(0,s.jsx)("div",{className:"truncate",children:e},a))}):null,eo?(0,s.jsx)("div",{style:{fontSize:13,color:eo.ok?"var(--dsw-success)":"var(--dsw-danger)"},children:eo.ok?ee+" ✓":eo.msg}):et?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{style:{fontSize:13.5,color:"var(--dsw-label-primary)"},children:et.message}),et.message.match(/https?:\/\/[^\s)]+/)&&(0,s.jsx)("a",{href:et.message.match(/https?:\/\/[^\s)]+/)[0],target:"_blank",rel:"noreferrer",className:"break-all",style:{fontSize:12.5,color:"var(--dsw-accent)"},children:et.message.match(/https?:\/\/[^\s)]+/)[0]}),et.options?.length?(0,s.jsx)("div",{className:"flex flex-col gap-1.5",children:et.options.map(e=>(0,s.jsx)("button",{className:"btn-outline",style:{height:34,justifyContent:"flex-start",textAlign:"left"},onClick:()=>{eR(e.value)},children:e.label},e.value))}):(0,s.jsx)("input",{autoFocus:!0,type:"secret"===et.type?"password":"text",value:ei,onChange:e=>en(e.target.value),placeholder:et.placeholder??"",className:"w-full rounded-xl px-3 py-2",style:{fontSize:13,background:"var(--dsw-hover)"},onKeyDown:e=>{"Enter"===e.key&&!e.nativeEvent.isComposing&&ei.trim()&&eR(ei.trim())}}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,s.jsx)("span",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:e.oauthWait}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)("button",{className:"btn-outline",style:{height:32},onClick:()=>{eD()},children:e.oauthCancel}),!et.options?.length&&(0,s.jsx)("button",{className:"btn-primary-white",disabled:!ei.trim(),style:{opacity:ei.trim()?1:.5},onClick:()=>{eR(ei.trim())},children:e.confirm})]})]})]}):(0,s.jsx)("div",{style:{fontSize:13,color:"var(--dsw-label-tertiary)"},children:e.oauthWait}),eo&&(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsx)("button",{className:"btn-primary-white",onClick:()=>ea(null),children:e.close})})]})})]})}let F="w-full rounded-xl px-3 py-2";function A(e){return e>=1e6?`${Math.round(e/1e5)/10}M`:e.toLocaleString()}function W(e){return 0===e.length?e:e[0].toUpperCase()+e.slice(1)}function O({label:e,children:a}){return(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"mb-1",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:e}),a]})}let I={read:{zh:"读取文件",en:"Read files"},bash:{zh:"执行 Shell 命令",en:"Run shell commands"},powershell:{zh:"执行 PowerShell",en:"Run PowerShell"},edit:{zh:"编辑文件",en:"Edit files"},write:{zh:"写入文件",en:"Write files"},grep:{zh:"搜索文件内容",en:"Search file contents"},find:{zh:"按名称查找文件",en:"Find files by name"},ls:{zh:"列出目录内容",en:"List directories"}};function U({toolPreset:e,onToolPresetChange:a,tools:t,onSetTools:r}){let{t:l,lang:i}=(0,m.s)(),n=new Set(t?.active??[]),o=t?.all??[];return(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:14,fontWeight:400},children:l.toolsSection}),(0,s.jsx)("div",{className:"mt-0.5",style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:l.toolsSectionDesc})]}),(0,s.jsx)($,{title:l.securityToolPreset,desc:l.securityToolPresetDesc,children:(0,s.jsx)(T,{value:e,options:[{value:"readonly",label:l.toolReadonly},{value:"standard",label:l.toolStandard},{value:"full",label:l.toolFull}],onChange:e=>a(e)})}),0===o.length?(0,s.jsx)("div",{className:"rounded-2xl p-4",style:{border:"0.5px dashed var(--dsw-border-l3)",fontSize:12.5,color:"var(--dsw-label-caption)"},children:l.toolsNoSession}):(0,s.jsxs)("div",{className:"flex flex-col gap-2.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",style:{fontSize:12,color:"var(--dsw-label-caption)"},children:[(0,s.jsx)("span",{style:{fontWeight:600},children:l.toolsCurrentSession}),(0,s.jsx)("span",{children:l.toolsActiveCount.replace("{n}",String(n.size)).replace("{total}",String(o.length))})]}),o.map(e=>{let a,t=n.has(e.name),l=e.description||((a=I[e.name])?"zh"===i?a.zh:a.en:"");return(0,s.jsxs)("div",{className:"flex items-center gap-3 rounded-2xl px-4 py-2.5",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsx)("div",{style:{fontSize:13.5,fontWeight:500,fontFamily:"var(--font-mono)"},children:e.name}),l&&(0,s.jsx)("div",{className:"truncate",style:{fontSize:11.5,color:"var(--dsw-label-caption)"},children:l})]}),(0,s.jsx)("button",{className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:t?"var(--dsw-accent)":"var(--dsw-border-l3)"},role:"switch","aria-checked":t,"aria-label":e.name,disabled:!r||t&&n.size<=1,onClick:()=>{var a;return a=e.name,void(!r||r(n.has(a)?[...n].filter(e=>e!==a):[...n,a]))},children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:t?18:2}})})]},e.name)})]})]})}function B({cwd:e,onOpenFileContent:a}){let{t}=(0,m.s)(),[l,i]=(0,r.useState)([]),n=(0,r.useCallback)(async()=>{let a=await fetch(`/api/skills${e?`?cwd=${encodeURIComponent(e)}`:""}`),t=await a.json();t.success&&i(t.data.skills)},[e]);(0,r.useEffect)(()=>{n()},[n]);let o=async a=>{let t=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"toggle",filePath:a.filePath,disabled:!a.disabled,cwd:e})});(await t.json()).success&&n()},d=async t=>{let s=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"read",filePath:t.filePath,cwd:e})}),r=await s.json();r.success&&a?.(t.filePath,r.data.content)},[c,u]=(0,r.useState)(null),p=async a=>{if(!window.confirm(t.confirmDeleteSkill.replace("{name}",a.name)))return;u(null);let s=await fetch("/api/skills",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"delete",filePath:a.filePath,cwd:e})}),r=await s.json();r.success?n():u(r.error||t.toastError)};return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("div",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:t.skillsDesc}),c&&(0,s.jsx)("div",{role:"alert",className:"rounded-lg px-3 py-2",style:{fontSize:12.5,background:"var(--dsw-hover)",color:"var(--dsw-danger)"},children:c}),0===l.length&&(0,s.jsx)("div",{style:{fontSize:13,color:"var(--dsw-label-caption)"},children:"—"}),(0,s.jsx)("div",{className:"flex flex-col gap-2",children:l.map(e=>{let a;return(0,s.jsx)("div",{className:"rounded-2xl px-4 py-3",style:{border:"0.5px solid var(--dsw-border-l2)"},children:(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{style:{fontSize:13.5,fontWeight:500},children:e.name}),(0,s.jsx)("span",{className:"rounded-full px-2 py-0.5",style:{fontSize:10,background:"var(--dsw-hover)",color:"var(--dsw-label-tertiary)"},children:"global"===(a=e.scope)?t.scopeGlobal:"project"===a?t.scopeProject:t.scopePackage})]}),(0,s.jsx)("div",{className:"mt-0.5 truncate",style:{fontSize:12,color:"var(--dsw-label-caption)"},title:e.description,children:e.description})]}),(0,s.jsx)("button",{className:"rounded-lg px-2.5 py-1",style:{fontSize:11.5,color:"var(--dsw-label-tertiary)"},onClick:()=>d(e),children:t.viewSkillFile}),"package"!==e.scope&&(0,s.jsx)("button",{className:"rounded-lg px-2.5 py-1",style:{fontSize:11.5,color:"var(--dsw-danger)"},title:t.deleteSkillHint,onClick:()=>void p(e),children:t.delete}),"package"===e.scope&&(0,s.jsx)("span",{style:{fontSize:10.5,color:"var(--dsw-label-caption)"},title:t.skillDeletePackageHint,children:t.skillDeletePackageHint}),(0,s.jsx)("button",{className:"relative h-5 w-9 flex-none rounded-full transition-colors",style:{background:e.disabled?"var(--dsw-border-l3)":"var(--dsw-accent)"},role:"switch","aria-checked":!e.disabled,onClick:()=>o(e),children:(0,s.jsx)("span",{className:"absolute top-0.5 h-4 w-4 rounded-full bg-white transition-all",style:{left:e.disabled?2:18}})})]})},e.filePath)})})]})}function K({cwd:e}){let{t:a,lang:t}=(0,m.s)(),l=e=>window.confirm(a.confirmUninstallPackage.replace("{source}",e)),[i,o]=(0,r.useState)("config"),[d,c]=(0,r.useState)([]),[u,p]=(0,r.useState)([]),[h,x]=(0,r.useState)(""),[v,f]=(0,r.useState)(new Set),[g,b]=(0,r.useState)(""),[y,w]=(0,r.useState)(!1),[j,S]=(0,r.useState)(!1),[N,k]=(0,r.useState)(null),[C,_]=(0,r.useState)(null),[z,P]=(0,r.useState)(null),M=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{e.target instanceof Node&&M.current?.contains(e.target)||P(null)};return window.addEventListener("pointerdown",e),()=>window.removeEventListener("pointerdown",e)},[]);let E=(0,r.useCallback)(async()=>{let a=await fetch(`/api/plugins${e?`?cwd=${encodeURIComponent(e)}`:""}`),t=await a.json();t.success&&(c(t.data.packages),p(t.data.extensions))},[e]);(0,r.useEffect)(()=>{E()},[E]);let T=(e,t)=>{_({ok:e,msg:t??(e?a.toastSaved:a.toastError),loading:!1}),setTimeout(()=>_(null),2600)},$=async(t,s={},r,l,i)=>{S(!0),r&&k(r),l&&_({ok:!0,msg:l,loading:!0});try{let r=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:t,cwd:e,...s})}),l=await r.json();if(l.success)return T(!0,i??("toggle"===t?s.disabled?a.disabled:a.enabled:a.toastSaved)),await E(),!0;return T(!1,l.error??a.toastError),!1}catch(e){return T(!1,e?.message??a.toastError),!1}finally{S(!1),k(null)}},R=e=>f(a=>{let t=new Set(a);return t.has(e)?t.delete(e):t.add(e),t}),D=e=>{let a=e.replace(/\\/g,"/");return a.includes("/.pi/agent/npm/")||a.includes("/.pi/agent/git/")?"package":a.includes("/.pi/agent/")?"global":(a.includes("/.pi/"),"project")},L=u.filter(e=>"package"!==D(e.path)),F=h.trim().toLowerCase(),A=[...d.map(e=>({key:`pkg:${e.scope}:${e.source}`,kind:"package",name:e.source.replace(/^npm:/,"").replace(/^git[^:]*:/,""),p:e})),...L.map(e=>({key:`ext:${e.path}`,kind:"extension",name:e.name,e}))].filter(e=>!F||e.name.toLowerCase().includes(F)),W=(0,s.jsxs)("span",{className:"flex flex-none items-center gap-1.5 rounded-md px-1.5 py-0.5",style:{fontSize:10.5,background:"rgba(34,197,94,.12)",color:"var(--dsw-success)"},children:[(0,s.jsx)("span",{className:"h-1.5 w-1.5 rounded-full",style:{background:"var(--dsw-success)"}}),a.enabled]});return(0,s.jsxs)("div",{className:"flex flex-col gap-5",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{style:{fontSize:20,fontWeight:600,color:"var(--dsw-label-primary)"},children:a.setPlugins}),(0,s.jsx)("div",{className:"mt-1",style:{fontSize:13,color:"var(--dsw-label-tertiary)"},children:a.pluginPageDesc})]}),C&&(0,s.jsxs)("div",{className:"fixed top-6 left-1/2 -translate-x-1/2 z-[9999] flex items-center gap-2.5 px-4 py-2 rounded-xl shadow-2xl transition-all pointer-events-none",style:{fontSize:13,fontWeight:500,background:"var(--dsw-surface-l1, #1e2025)",border:C.loading?"1px solid var(--dsw-border-l3)":C.ok?"1px solid rgba(34,197,94,.4)":"1px solid rgba(236,19,19,.4)",color:C.loading?"var(--dsw-label-primary)":C.ok?"var(--dsw-success)":"var(--dsw-danger)",backdropFilter:"blur(12px)",boxShadow:"0 10px 30px rgba(0,0,0,0.5)"},children:[C.loading&&(0,s.jsx)("span",{className:"h-3.5 w-3.5 flex-none animate-spin rounded-full border-2 border-current border-t-transparent"}),(0,s.jsx)("span",{children:C.msg})]}),(0,s.jsxs)("div",{className:"hairline-b flex items-center gap-6",children:[(0,s.jsx)("button",{className:"settings-tab-underline","data-active":"config"===i,onClick:()=>o("config"),children:a.pluginConfig}),(0,s.jsx)("button",{className:"settings-tab-underline","data-active":"list"===i,onClick:()=>o("list"),children:a.pluginList})]}),"config"===i&&(0,s.jsxs)("div",{className:"flex flex-col gap-2.5",children:[(0,s.jsxs)("div",{className:"flex flex-col gap-2 rounded-2xl px-4 py-3",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsx)("div",{style:{fontSize:13.5,fontWeight:500},children:a.addPackage}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,s.jsx)("input",{value:g,onChange:e=>b(e.target.value),placeholder:a.addPackagePlaceholder,className:"min-w-0 flex-1 rounded-xl px-3 py-2",style:{fontSize:13,background:"var(--dsw-hover)",border:"0.5px solid var(--dsw-border-l2)",fontFamily:"var(--font-mono)"},onKeyDown:e=>{"Enter"===e.key&&g.trim()&&!j&&$("install",{source:g.trim(),local:y},void 0,a.installing,a.installSuccess).then(e=>{e&&b("")})}}),(0,s.jsxs)("label",{className:"flex items-center gap-1.5",style:{fontSize:12.5,color:"var(--dsw-label-secondary)"},children:[(0,s.jsx)("input",{type:"checkbox",checked:y,onChange:e=>w(e.target.checked),disabled:!e}),a.installLocal]}),(0,s.jsx)("button",{className:"btn-primary-white",style:{height:32,padding:"0 14px"},disabled:!g.trim()||j,onClick:()=>void $("install",{source:g.trim(),local:y},void 0,a.installing,a.installSuccess).then(e=>{e&&b("")}),children:a.install})]})]}),(0,s.jsx)("div",{className:"flex justify-end",children:(0,s.jsxs)("button",{className:"btn-outline",style:{height:30,fontSize:12.5},disabled:j,onClick:async()=>{S(!0);try{let t=await fetch("/api/plugins",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"reload",cwd:e})}),s=await t.json();T(s.success,s.success?a.reloadedSessions.replace("{loaders}",String(s.data?.loaders??0)).replace("{sessions}",String(s.data?.sessions??0)):s.error),s.success&&await E()}finally{S(!1)}},children:[(0,s.jsx)(n.Ct,{size:13})," ",a.reloadExtensions]})}),0===L.length&&(0,s.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:a.extensionsEmpty}),L.map(e=>{let t=`ext:${e.path}`,r=v.has(t),l=D(e.path);return(0,s.jsxs)("div",{className:"rounded-2xl",style:{border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("button",{className:"flex w-full items-center gap-3 px-4 py-3.5 text-left",onClick:()=>R(t),children:[(0,s.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",style:{fontSize:14,fontWeight:500},children:[(0,s.jsx)("span",{children:e.name}),e.error&&(0,s.jsx)("span",{className:"rounded px-1.5 py-0.5",style:{fontSize:10.5,color:"var(--dsw-danger)",background:"var(--pw-danger-soft, rgba(236,19,19,.12))"},children:a.extensionLoadError}),e.disabled&&!e.error&&(0,s.jsx)("span",{className:"rounded px-1.5 py-0.5",style:{fontSize:10.5,color:"var(--dsw-label-tertiary)",background:"var(--dsw-selector)"},children:a.disabled})]}),(0,s.jsx)("div",{className:"truncate",style:{fontSize:12,color:e.error?"var(--dsw-danger)":"var(--dsw-label-caption)"},title:e.error??e.path,children:e.error??e.path})]}),(0,s.jsx)("span",{className:"chevron",style:{color:"var(--dsw-label-tertiary)",display:"inline-flex",transform:r?"rotate(180deg)":"none",transition:"transform 120ms var(--ds-ease-in-out)"},children:(0,s.jsx)(n.Cd,{size:14})})]}),r&&(0,s.jsxs)("div",{className:"hairline-t flex flex-col gap-1.5 px-4 py-3",style:{fontSize:12,color:"var(--dsw-label-secondary)"},children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:"global"===l?a.scopeGlobal:"project"===l?a.scopeProject:a.scopePackage}),W]}),(0,s.jsx)("div",{className:"break-all",style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--dsw-label-caption)"},children:e.path})]})]},t)})]}),"list"===i&&(0,s.jsxs)("div",{className:"flex flex-col gap-3.5",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2.5 rounded-xl px-3.5 py-2.5 transition-colors",style:{background:"var(--dsw-hover)",border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsx)(n.FG,{size:15,style:{color:"var(--dsw-label-caption)"}}),(0,s.jsx)("input",{value:h,onChange:e=>x(e.target.value),placeholder:a.searchPlugins,className:"w-full bg-transparent outline-none",style:{fontSize:13,color:"var(--dsw-label-primary)"}})]}),(0,s.jsxs)("div",{className:"flex items-baseline gap-2",children:[(0,s.jsx)("span",{style:{fontSize:13.5,fontWeight:600,color:"var(--dsw-label-primary)"},children:a.pluginList}),(0,s.jsx)("span",{style:{fontSize:12,color:"var(--dsw-label-caption)"},children:A.length})]}),0===A.length?(0,s.jsx)("div",{style:{fontSize:12.5,color:"var(--dsw-label-caption)"},children:a.packagesEmpty}):(0,s.jsx)("div",{className:"grid grid-cols-1 items-start sm:grid-cols-2 gap-2.5",children:A.map(e=>{let r=v.has(e.key),i="package"===e.kind?!0===e.p.disabled:!0===e.e.disabled,o=z===e.key,d=N===e.key;return(0,s.jsxs)("div",{className:"flex flex-col rounded-xl transition-colors",style:{background:"var(--dsw-hover)",border:"0.5px solid var(--dsw-border-l2)"},children:[(0,s.jsxs)("div",{className:"flex h-11 items-center justify-between px-3.5 gap-2",children:[(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate font-medium text-[var(--dsw-label-primary)] cursor-pointer select-none",style:{fontSize:13.5},onClick:()=>R(e.key),title:e.name,children:e.name}),(0,s.jsxs)("div",{ref:o?M:void 0,className:"relative flex-none",children:[(0,s.jsxs)("button",{type:"button",className:"flex min-w-[86px] items-center justify-center rounded-lg px-3 transition-colors cursor-pointer select-none disabled:cursor-wait",style:{gap:7,height:30,background:"rgba(255, 255, 255, 0.04)",border:"1px solid rgba(255, 255, 255, 0.08)"},"aria-haspopup":"menu","aria-expanded":o,disabled:d,onClick:a=>{a.stopPropagation(),P(a=>a===e.key?null:e.key)},children:[d?(0,s.jsx)("span",{className:"h-3 w-3 flex-none animate-spin rounded-full border border-[var(--dsw-label-tertiary)] border-t-transparent"}):i?null:(0,s.jsx)("span",{className:"h-2 w-2 flex-none rounded-full",style:{background:"#22c55e",boxShadow:"0 0 5px rgba(34, 197, 94, 0.4)"}}),(0,s.jsx)("span",{style:{fontSize:12,fontWeight:500,color:i?"var(--dsw-label-tertiary)":"var(--dsw-success)",lineHeight:1},children:i?a.disabled:a.enabled}),(0,s.jsx)(n.Cd,{size:13,style:{color:"var(--dsw-label-tertiary)",transform:o?"rotate(180deg)":"none",transition:"transform 140ms ease"}})]}),o&&(0,s.jsxs)("div",{className:"popover absolute right-0 top-full mt-1.5 z-50 w-36 py-1 rounded-xl shadow-xl",role:"menu",style:{background:"var(--dsw-surface-l1, #1e2025)",border:"0.5px solid var(--dsw-border-l3)",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5)"},children:[(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer",style:{color:i?"var(--dsw-success)":"var(--dsw-label-primary)"},disabled:j,onClick:()=>{P(null),$("toggle","package"===e.kind?{kind:"package",source:e.p.source,scope:e.p.scope,disabled:!i}:{kind:"extension",path:e.e.path,disabled:!i},e.key,i?"zh"===t?"正在启用...":"Enabling...":"zh"===t?"正在停用...":"Disabling...",i?a.enabled:a.disabled)},children:i?a.enablePlugin:a.disablePlugin}),"package"===e.kind&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer disabled:opacity-50",style:{color:"var(--dsw-label-secondary)"},disabled:j,onClick:()=>{P(null),$("update",{source:e.p.source},e.key,a.updating,a.updateSuccess)},children:a.update}),(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer disabled:opacity-50",style:{color:"var(--dsw-danger)"},disabled:j,onClick:()=>{P(null),l(e.p.source)&&$("remove",{source:e.p.source,local:"project"===e.p.scope},e.key,a.uninstalling,a.uninstallSuccess)},children:a.uninstall})]}),(0,s.jsx)("div",{className:"my-1 border-t border-[var(--dsw-border-l1)]"}),(0,s.jsx)("button",{type:"button",role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-[var(--dsw-hover)] cursor-pointer",style:{color:"var(--dsw-label-tertiary)"},onClick:()=>{R(e.key),P(null)},children:r?"zh"===t?"收起详情":"Hide details":"zh"===t?"查看详情":"View details"})]})]})]}),r&&(0,s.jsx)("div",{className:"hairline-t flex flex-col gap-2 px-3.5 py-3",style:{fontSize:12},children:"package"===e.kind?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"break-all",style:{color:"var(--dsw-label-tertiary)",fontSize:11.5},children:e.p.source}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("span",{className:"rounded-md px-1.5 py-0.5",style:{fontSize:10.5,border:"0.5px solid var(--dsw-border-l3)",color:"var(--dsw-label-tertiary)"},children:"user"===e.p.scope?a.scopeGlobal:a.scopeProject}),(0,s.jsxs)("span",{style:{color:"var(--dsw-label-caption)",fontSize:11.5},children:[a.resources,": ",e.p.resources.extensions," ext \xb7 ",e.p.resources.skills," skills \xb7 ",e.p.resources.prompts," prompts"]})]}),(0,s.jsxs)("div",{className:"flex items-center justify-end gap-3 pt-1",children:[(0,s.jsx)("button",{disabled:j,style:{fontSize:12,color:"var(--dsw-label-secondary)"},className:"hover:underline cursor-pointer disabled:opacity-50",onClick:()=>void $("update",{source:e.p.source},e.key,a.updating,a.updateSuccess),children:a.update}),(0,s.jsx)("button",{disabled:j,style:{fontSize:12,color:"var(--dsw-danger)"},className:"hover:underline cursor-pointer disabled:opacity-50",onClick:()=>{l(e.p.source)&&$("remove",{source:e.p.source,local:"project"===e.p.scope},e.key,a.uninstalling,a.uninstallSuccess)},children:a.uninstall})]})]}):(0,s.jsx)("div",{className:"break-all",style:{fontFamily:"var(--font-mono)",fontSize:11.5,color:"var(--dsw-label-caption)"},children:e.e.path})})]},e.key)})})]})]})}}}]);
|