@wrongstack/webui 0.318.0 → 0.319.1

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.
Files changed (99) hide show
  1. package/dist/assets/{AgentRosterView-C46rL23K.js → AgentRosterView-VIctzKMy.js} +1 -1
  2. package/dist/assets/{AnalyticsDashboard-B8r_8kNv.js → AnalyticsDashboard-Dr67MeEY.js} +1 -1
  3. package/dist/assets/{AudienceMemoryPanel-Ciybycpn.js → AudienceMemoryPanel-DoaZfrjf.js} +1 -1
  4. package/dist/assets/{ChangesView-BREfCsEq.js → ChangesView-s7Mn7iE2.js} +1 -1
  5. package/dist/assets/ChimeraReviewsView-Cverzv0b.js +1 -0
  6. package/dist/assets/{ChronicleDashboard-bo2jv52s.js → ChronicleDashboard-CzqPfaPc.js} +1 -1
  7. package/dist/assets/{CodeEditor-C_KzNkIb.js → CodeEditor-DXQoTSH5.js} +1 -1
  8. package/dist/assets/{CodeMap-DA_k3u5g.js → CodeMap-D34FOPgR.js} +1 -1
  9. package/dist/assets/{ConfirmModal-gukSikBD.js → ConfirmModal-B6BGiiN8.js} +1 -1
  10. package/dist/assets/{CronJobsPanel-D-43oYQ-.js → CronJobsPanel-CenxuaN9.js} +1 -1
  11. package/dist/assets/{DeadCodeScanPanel-VnMQatbH.js → DeadCodeScanPanel-DooqnEMF.js} +1 -1
  12. package/dist/assets/{DebugDashboard-DNDadwro.js → DebugDashboard-DWaUg6e1.js} +1 -1
  13. package/dist/assets/{DesignGalleryView-B9ZMJPOQ.js → DesignGalleryView-BKtjn4px.js} +1 -1
  14. package/dist/assets/{GoalView-BkoCNN8l.js → GoalView-BZ62_vF-.js} +1 -1
  15. package/dist/assets/{KanbanView-nql6LkaS.js → KanbanView-DsWnTpxr.js} +1 -1
  16. package/dist/assets/{MailboxDetailView-CdHRfnNq.js → MailboxDetailView-DS1P9DRT.js} +1 -1
  17. package/dist/assets/{MemoryDrawer-CfukdhlF.js → MemoryDrawer-BJEY1v4P.js} +1 -1
  18. package/dist/assets/{MemoryManager-BD_VnFAu.js → MemoryManager-D-kuyTQe.js} +1 -1
  19. package/dist/assets/{ModelPicker-C3r7IFfh.js → ModelPicker-CLs0qQgg.js} +1 -1
  20. package/dist/assets/{OfficeMapPanel-B47jfEHf.js → OfficeMapPanel-BqoCcniD.js} +1 -1
  21. package/dist/assets/{ProcessMonitor-CvHdN8Bn.js → ProcessMonitor-CHNNqCk9.js} +1 -1
  22. package/dist/assets/{PromptJournalView-CXZ9notj.js → PromptJournalView-Biu4DknM.js} +1 -1
  23. package/dist/assets/{QueuePanel-DOcgHRH3.js → QueuePanel-CzTXq6j4.js} +1 -1
  24. package/dist/assets/{RefreshDebugView-BYmeORMQ.js → RefreshDebugView-d9iU3sFX.js} +1 -1
  25. package/dist/assets/{RequirementIntakeView-CFgVx_0T.js → RequirementIntakeView-BVyF2zXR.js} +1 -1
  26. package/dist/assets/{SageTabs-BRJG0fhZ.js → SageTabs-YASyEFo6.js} +2 -2
  27. package/dist/assets/{SddFlowGraph-BsfhxlDK.js → SddFlowGraph-Bj_Aqq5B.js} +1 -1
  28. package/dist/assets/{SddHub-Br1vyCgq.js → SddHub-rmGGEYZe.js} +1 -1
  29. package/dist/assets/{SessionInspectView-BSRjWErA.js → SessionInspectView-iaKkGAAM.js} +1 -1
  30. package/dist/assets/{SessionList-BkaI91oW.js → SessionList-vmAS2Fg5.js} +1 -1
  31. package/dist/assets/{SessionsDashboard-BEQs4Div.js → SessionsDashboard-x3iyhrGl.js} +1 -1
  32. package/dist/assets/SetupScreen-huPJT0Bv.js +1 -0
  33. package/dist/assets/{SkillDetailView-DqxkOnb8.js → SkillDetailView-BcD9z7zG.js} +1 -1
  34. package/dist/assets/{SpecsView-COS0-sxq.js → SpecsView-ok8HZ8ws.js} +1 -1
  35. package/dist/assets/{TechStackView-Dr8vI0hK.js → TechStackView-DmMtwb4l.js} +1 -1
  36. package/dist/assets/{TerminalPanel-DlIyvxm6.js → TerminalPanel-cbM6oQWQ.js} +1 -1
  37. package/dist/assets/{activity-q85HXQNv.js → activity-BU6MNvBJ.js} +1 -1
  38. package/dist/assets/{activity-B2_Vr2oD.js → activity-C7dkJqBU.js} +1 -1
  39. package/dist/assets/{activity-DYMBKGt0.js → activity-C_18AaRY.js} +1 -1
  40. package/dist/assets/{activity-IxgYWPDt.js → activity-CpnSsE22.js} +1 -1
  41. package/dist/assets/{activity-BF1idM4Y.js → activity-CtTKsSX6.js} +1 -1
  42. package/dist/assets/{activity-C-kOJZXC.js → activity-D1rp3dH9.js} +1 -1
  43. package/dist/assets/{activity-DPpMW8BU.js → activity-hTPcI4q1.js} +1 -1
  44. package/dist/assets/{chat-DTI7lNDx.js → chat-6dE2AJNN.js} +1 -1
  45. package/dist/assets/{chat-BvKkSd09.js → chat-B3AJmhGD.js} +1 -1
  46. package/dist/assets/{chat-BNWqeV-N.js → chat-BHsbpaVt.js} +1 -1
  47. package/dist/assets/{chat-BlllxfpP.js → chat-BITJe8-v.js} +1 -1
  48. package/dist/assets/{chat-DlhXGxxi.js → chat-U-Jjb8_k.js} +1 -1
  49. package/dist/assets/{chat-B60h8Cji.js → chat-_Xp5fDnj.js} +1 -1
  50. package/dist/assets/{chat-B5a3cvps.js → chat-mSbSzPl5.js} +1 -1
  51. package/dist/assets/{chat-store-DIcs826A.js → chat-store-oW_-zcJP.js} +1 -1
  52. package/dist/assets/{i18n-Cv65b1SP.js → i18n-D06uU1PM.js} +2 -2
  53. package/dist/assets/index-BQ7PJ-sA.js +144 -0
  54. package/dist/assets/index-CWYymMpa.css +1 -0
  55. package/dist/assets/{roster-ws-D5JW3IPJ.js → roster-ws-BQUI8QuW.js} +1 -1
  56. package/dist/assets/setup-B0D9CK3-.js +1 -0
  57. package/dist/assets/setup-B58YVaGU.js +1 -0
  58. package/dist/assets/setup-C2H9Uv0Q.js +1 -0
  59. package/dist/assets/setup-CzM4dkkU.js +1 -0
  60. package/dist/assets/setup-Di56FlHP.js +1 -0
  61. package/dist/assets/setup-Dwt58Mpz.js +1 -0
  62. package/dist/assets/setup-DznVdlJy.js +1 -0
  63. package/dist/assets/{stores-CNuMLG8X.js → stores-C7Vvce-6.js} +1 -1
  64. package/dist/assets/ui-store-Dm7ujR9u.js +1 -0
  65. package/dist/assets/useWebSocket-9lfOsI_r.js +27 -0
  66. package/dist/assets/{view-navigation-DPOY0lyt.js → view-navigation-wOKaM_Rf.js} +1 -1
  67. package/dist/assets/{ws-client-D-d32pHb.js → ws-client-DtTZLD8e.js} +2 -2
  68. package/dist/components/ChatInput/use-speech-recognition.d.ts +1 -1
  69. package/dist/components/DependencyGraph.d.ts +1 -1
  70. package/dist/components/DiffView.d.ts +1 -1
  71. package/dist/components/MessageBubble/ToolLedgerCard.d.ts +1 -1
  72. package/dist/components/SetupScreen/CustomProviderSection.d.ts +1 -1
  73. package/dist/components/agents/AgentRosterCard.d.ts +1 -1
  74. package/dist/components/context-editor/ContextWindowEditor.d.ts +1 -1
  75. package/dist/components/ui/dropdown-menu.d.ts +1 -1
  76. package/dist/components/vector-memory-panel/index.d.ts +1 -1
  77. package/dist/index.html +14 -14
  78. package/dist/index.js +5788 -3483
  79. package/dist/lib/launch-builtin-round.d.ts +43 -0
  80. package/dist/lib/perf-run-message.d.ts +51 -0
  81. package/dist/manifest.json +1 -1
  82. package/dist/stores/fleet-store.d.ts +4 -0
  83. package/dist/stores/index.d.ts +2 -2
  84. package/dist/stores/types.d.ts +9 -0
  85. package/dist/stores/ui-store.d.ts +0 -2
  86. package/package.json +10 -10
  87. package/dist/assets/ChimeraReviewsView-aSYmQ8tC.js +0 -1
  88. package/dist/assets/SetupScreen-zY4541lT.js +0 -1
  89. package/dist/assets/index-DSyVpLgL.css +0 -1
  90. package/dist/assets/index-DbprKWmG.js +0 -137
  91. package/dist/assets/setup-BQLPzL3N.js +0 -1
  92. package/dist/assets/setup-C9lrNwQF.js +0 -1
  93. package/dist/assets/setup-CcxP7cUl.js +0 -1
  94. package/dist/assets/setup-CtKKNpH9.js +0 -1
  95. package/dist/assets/setup-D4rp2jda.js +0 -1
  96. package/dist/assets/setup-MvmOtwNp.js +0 -1
  97. package/dist/assets/setup-blxUcxNU.js +0 -1
  98. package/dist/assets/ui-store-DpKUBLWd.js +0 -1
  99. package/dist/assets/useWebSocket-VIItbvVK.js +0 -27
@@ -0,0 +1,43 @@
1
+ import type { WrongStackWebSocketClient } from '@/lib/ws-client';
2
+ /**
3
+ * Shared launcher for the one-click built-in rounds (Bug Hunter, Performance
4
+ * Ratchet).
5
+ *
6
+ * Both cards do the same four-step dance: optionally flip the session to solo,
7
+ * ask the server for a builtin prompt body, compose the message, and send it —
8
+ * with a single timeout and a single settle path so a half-finished launch can
9
+ * never leave the button spinning forever. Extracting it means a fix to the
10
+ * settle logic lands for both cards instead of one.
11
+ */
12
+ /**
13
+ * The slice of the WS client these launchers use.
14
+ *
15
+ * Derived from the real client rather than restated structurally: `send` takes
16
+ * a discriminated union of message shapes, and a hand-written `{type: string}`
17
+ * signature would silently accept a message type the server does not handle.
18
+ */
19
+ export type RoundLauncherClient = Pick<WrongStackWebSocketClient, 'isConnected' | 'on' | 'send' | 'sendMessage'>;
20
+ export interface LaunchBuiltinRoundOptions {
21
+ client: RoundLauncherClient;
22
+ /** Builtin prompt slug to fetch. */
23
+ slug: string;
24
+ /**
25
+ * Force the session solo before starting. A round that attributes one
26
+ * outcome to one change cannot be fanned out across subagents.
27
+ */
28
+ requireSoloSession: boolean;
29
+ subagentsAllowed: boolean;
30
+ sessionId?: string | undefined;
31
+ setPrefs(patch: {
32
+ subagentsAllowed: boolean;
33
+ }): void;
34
+ /** Wrap the fetched prompt body into the message that gets sent. */
35
+ compose(content: string): string;
36
+ /** Called with the sent message id and text, to mirror it into the transcript. */
37
+ onSent(id: string, text: string): void;
38
+ onSettle(state: 'idle' | 'error'): void;
39
+ /** Defaults to 8s — long enough for a cold prompt store, short enough to notice. */
40
+ timeoutMs?: number;
41
+ }
42
+ export declare function launchBuiltinRound(options: LaunchBuiltinRoundOptions): void;
43
+ //# sourceMappingURL=launch-builtin-round.d.ts.map
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Durable display metadata for a one-click performance round.
3
+ *
4
+ * The agent receives the full prompt; the transcript shows a two-line card. The
5
+ * marker is an HTML comment so it survives a session reload without a parallel
6
+ * sidecar store, and so a replayed round still renders as a round rather than
7
+ * as a wall of pasted instructions.
8
+ *
9
+ * Mirrors `bug-hunt-message.ts` — same shape, same guarantees.
10
+ */
11
+ /** Keep in sync with `PERF_MODE_IDS` in `@wrongstack/core/performance`. */
12
+ export declare const PERF_RUN_MODES: readonly ['ratchet', 'audit', 'triage', 'memory', 'io', 'cpu', 'guard', 'contract'];
13
+ export type PerfRunMode = (typeof PERF_RUN_MODES)[number];
14
+ /** Keep in sync with `PERF_METRIC_IDS` in `@wrongstack/core/performance`. */
15
+ export declare const PERF_RUN_METRICS: readonly ['wall-ms', 'p99-latency-ms', 'peak-rss-bytes', 'throughput-ops', 'allocs-per-op', 'cold-start-ms', 'bundle-bytes'];
16
+ export type PerfRunMetric = (typeof PERF_RUN_METRICS)[number];
17
+ export interface PerfRunSummary {
18
+ scope: string;
19
+ mode: PerfRunMode;
20
+ /** Empty string means "whichever metric the workload actually feels". */
21
+ metric: PerfRunMetric | '';
22
+ }
23
+ /**
24
+ * Card labels for the transcript chip.
25
+ *
26
+ * Kept next to the mode list rather than in the i18n catalog, matching the
27
+ * sibling Bug Hunter card: these are the names of built-in modes, and a
28
+ * translated mode name would not match the `/perf <mode>` the user types.
29
+ */
30
+ export declare const PERF_RUN_MODE_LABELS: Record<PerfRunMode, string>;
31
+ export declare const PERF_RUN_METRIC_LABELS: Record<PerfRunMetric, string>;
32
+ /**
33
+ * Mode → builtin prompt slug.
34
+ *
35
+ * Mirrors `PERF_MODES` in `@wrongstack/core/performance`. `perf-run-message.test.ts`
36
+ * pins the two together, so a mode added on one side cannot silently 404 here.
37
+ */
38
+ export declare const PERF_MODE_SLUGS: Record<PerfRunMode, string>;
39
+ /**
40
+ * Modes that may change production code, and therefore run solo.
41
+ *
42
+ * A read-only mode must NOT flip the user's subagent policy: silently
43
+ * disabling their fleet to produce a report is a side effect they did not ask
44
+ * for, and the policy locks after the first message.
45
+ */
46
+ export declare const PERF_MUTATING_MODES: ReadonlySet<PerfRunMode>;
47
+ /** Adds durable display metadata without changing the instruction sent to the agent. */
48
+ export declare function buildPerfRunMessage(instruction: string, summary: PerfRunSummary): string;
49
+ /** Recognizes a persisted performance round and recovers its compact display data. */
50
+ export declare function parsePerfRunMessage(content: string): PerfRunSummary | undefined;
51
+ //# sourceMappingURL=perf-run-message.d.ts.map
@@ -14,4 +14,4 @@
14
14
  "theme_color": "#090a0f",
15
15
  "display": "standalone",
16
16
  "orientation": "any"
17
- }
17
+ }
@@ -46,6 +46,10 @@ export interface FleetState {
46
46
  * roster. Scoped: only agents belonging to `sessionId` are removed, so a
47
47
  * panel in one tab never drops another tab's finished agents. */
48
48
  clearFinishedAgents: (sessionId: string | null) => void;
49
+ /** Remove ONE agent from the roster (AgentTabs close affordance). Same
50
+ * cleanup path as clearFinishedAgents — transcripts, timelines, token
51
+ * totals and the leader pointer all follow the agent out. */
52
+ removeAgent: (subagentId: string) => void;
49
53
  }
50
54
  export declare const useFleetStore: import("zustand").UseBoundStore<import("zustand").StoreApi<FleetState>>;
51
55
  /** Pre-computed fleet-wide summary statistics. */
@@ -42,12 +42,12 @@ export { type SddWizardPhase, type SddWizardSnapshot, useSddWizardStore, } from
42
42
  /** The lane pointer — the single answer to "which tab is in front". */
43
43
  export { activeSessionLaneId, useActiveSessionId } from './session-lanes.js';
44
44
  export { memorySessionSnapshots, useSessionStore } from './session-store.js';
45
- export { isTabBusy, MAX_OPEN_TABS, slotOf, summarizeTab, type TabSummary, useSessionTabStore } from './session-tab-store.js';
45
+ export { isTabBusy, MAX_OPEN_TABS, slotOf, summarizeTab, type TabSummary, useSessionTabStore, } from './session-tab-store.js';
46
46
  export { type SideEffectEntry, useSideEffectStore } from './side-effect-store.js';
47
47
  export { type BoardTaskItem, type BoardTaskStatus, type SpecColumn, type SpecDetail, type SpecListItem, useSpecsStore, } from './specs-store.js';
48
48
  export { type TechStackCoverage, type TechStackDependency, type TechStackEvidence, type TechStackFinding, type TechStackFindingAction, type TechStackFindingSeverity, type TechStackFindingType, type TechStackJobKind, type TechStackJobStatus, type TechStackJobView, type TechStackProgress, type TechStackSnapshot, type TechStackWorkspace, useTechStackStore, } from './techstack-store.js';
49
49
  export { bucketSuccessRatio, LEADER_AGENT_KEY, sessionInFlight, type ToolStatsBucket, type ToolStatsDelegation, type ToolStatsSession, useToolStatsStore, } from './tool-stats-store.js';
50
- export type { AgentTranscriptEntry, AgentTranscriptKind, BrainDecisionData, ChatMessage, ChatMessageAttachment, CouncilDecisionData, CouncilSeatVote, FleetTimelineEvent, SessionHistoryEntry, SessionInfo, SubagentEvent, SubagentView, ToolExecution } from './types.js';
50
+ export type { AgentTranscriptEntry, AgentTranscriptKind, BrainDecisionData, ChatMessage, ChatMessageAttachment, CouncilDecisionData, CouncilSeatVote, FleetTimelineEvent, SessionHistoryEntry, SessionInfo, SubagentEvent, SubagentView, ToolExecution, } from './types.js';
51
51
  export type { Activity, DockSection, InspectorTab, WorkDashboardTab } from './ui-store.js';
52
52
  export { coerceActivity, resetUiNavigationToHome, SIDEBAR_DEFAULT_WIDTH, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH, useUIStore, } from './ui-store.js';
53
53
  export type { VizEdge, VizEvent, VizNode } from './viz-store.js';
@@ -1,4 +1,5 @@
1
1
  import type { Usage } from '@wrongstack/core/types';
2
+ import type { PerfRunMetric, PerfRunMode } from '@/lib/perf-run-message';
2
3
  export type CouncilVoteStatus = 'valid' | 'invalid' | 'failed' | 'cancelled';
3
4
  /** One council seat's observable vote. No hidden chain-of-thought is retained. */
4
5
  export interface CouncilSeatVote {
@@ -52,6 +53,14 @@ export interface ChatMessage {
52
53
  scope: string;
53
54
  maxBugs: 1 | 2 | 3;
54
55
  } | undefined;
56
+ /** The same treatment for a built-in performance ratchet round: the full
57
+ * prompt goes to the agent, the transcript shows the mode, scope, and the
58
+ * metric the round is optimising. */
59
+ perfRun?: {
60
+ scope: string;
61
+ mode: PerfRunMode;
62
+ metric: PerfRunMetric | '';
63
+ } | undefined;
55
64
  role: 'user' | 'assistant' | 'system' | 'tool';
56
65
  toolName?: string | undefined;
57
66
  toolInput?: unknown | undefined;
@@ -154,8 +154,6 @@ interface UIState {
154
154
  subagentChatFocusId: string | null;
155
155
  /** Which session the flat `subagentChatFocusId` describes. */
156
156
  subagentChatFocusSessionId: string | null;
157
- /** Per-tab subagent focus, so switching tabs restores what each was showing. */
158
- subagentChatFocusBySession: Record<string, string | null>;
159
157
  /** Process Monitor overlay — triggered by /kill slash command. */
160
158
  processMonitorOpen: boolean;
161
159
  /** Queue Panel overlay — triggered by /queue slash command. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrongstack/webui",
3
- "version": "0.318.0",
3
+ "version": "0.319.1",
4
4
  "license": "MIT",
5
5
  "description": "Browser-based WebUI for WrongStack — React + Vite frontend. The WebSocket backend lives in the separate @wrongstack/webui-server package (extracted in PR #018b to remove the CLI -> @wrongstack/webui/server cross-package edge).",
6
6
  "keywords": [
@@ -57,13 +57,13 @@
57
57
  "@radix-ui/react-tabs": "^1.1.21",
58
58
  "@tanstack/react-virtual": "^3.14.10",
59
59
  "@uiw/react-textarea-code-editor": "^3.1.1",
60
- "@wrongstack/core": "0.318.0",
61
- "@wrongstack/kanban": "0.318.0",
62
- "@wrongstack/plugins": "0.318.0",
63
- "@wrongstack/providers": "0.318.0",
64
- "@wrongstack/tools": "0.318.0",
65
- "@wrongstack/webui-protocol": "0.318.0",
66
- "@wrongstack/webui-server": "0.318.0",
60
+ "@wrongstack/core": "0.319.1",
61
+ "@wrongstack/kanban": "0.319.1",
62
+ "@wrongstack/plugins": "0.319.1",
63
+ "@wrongstack/providers": "0.319.1",
64
+ "@wrongstack/tools": "0.319.1",
65
+ "@wrongstack/webui-protocol": "0.319.1",
66
+ "@wrongstack/webui-server": "0.319.1",
67
67
  "@xterm/addon-fit": "^0.11.0",
68
68
  "@xterm/xterm": "^6.0.0",
69
69
  "@xyflow/react": "^12.11.3",
@@ -85,7 +85,7 @@
85
85
  "zustand": "^5.0.15"
86
86
  },
87
87
  "optionalDependencies": {
88
- "node-pty": "1.2.0-beta.14"
88
+ "node-pty": "1.1.0"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@playwright/test": "^1.62.1",
@@ -99,7 +99,7 @@
99
99
  "@types/ws": "^8.18.1",
100
100
  "@vitejs/plugin-react": "^6.1.0",
101
101
  "@vitest/coverage-v8": "^4.1.11",
102
- "@wrongstack/sdd": "0.318.0",
102
+ "@wrongstack/sdd": "0.319.1",
103
103
  "jsdom": "^30.0.1",
104
104
  "tailwindcss": "^4.3.3",
105
105
  "typescript": "^7.0.2",
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{t,wt as n}from"./ws-client-D-d32pHb.js";import{Dn as r,Yi as i,_n as a,da as o,en as s,fa as c,fr as l,hn as u,ia as d,mi as f,oa as p,on as m,oo as h,pa as g,sn as _,to as v,ut as y,xn as b}from"./vendor-enc0q-Va.js";import"./i18n-Cv65b1SP.js";import{t as x}from"./utils-DQ9Exx8j.js";import{f as S}from"./index-DbprKWmG.js";import{t as C}from"./empty-state-DBQN80mK.js";var w=e(h(),1),T=y();function E(e){try{return new Date(e).toLocaleString()}catch{return e}}function D(e){try{let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?`Just now`:n<36e5?`${Math.round(n/6e4)}m ago`:n<864e5?`${Math.round(n/36e5)}h ago`:n<6048e5?`${Math.round(n/864e5)}d ago`:t.toLocaleDateString()}catch{return e}}var O={open:{label:`Open`,cls:`border-primary/30 bg-primary/10 text-primary`,icon:p},actioned:{label:`Actioned`,cls:`border-warning/30 bg-warning/10 text-warning`,icon:u},completed:{label:`Completed`,cls:`border-success/30 bg-success/10 text-success`,icon:d},skipped:{label:`Skipped`,cls:`border-border bg-muted text-muted-foreground`,icon:i}},k={critical:{bg:`bg-destructive/10 border-destructive/30`,text:`text-destructive`,dot:`bg-destructive`},high:{bg:`bg-warning/15 border-warning/40`,text:`text-warning`,dot:`bg-warning`},medium:{bg:`bg-warning/10 border-warning/30`,text:`text-warning`,dot:`bg-warning`},low:{bg:`bg-muted border-border`,text:`text-muted-foreground`,dot:`bg-muted-foreground`}};function A(){let{t:e}=v(),{reports:p,selectedReportId:h,detail:y,loading:A,detailLoading:j,error:M,filterSessionId:N,filterLifecycle:P,searchQuery:F,fetchReports:I,selectReport:L,setFilterSessionId:R,setFilterLifecycle:z,setSearchQuery:B,transitionReport:V,addReportNote:H,transitionFinding:U}=S(),[W,G]=(0,w.useState)(``),[K,q]=(0,w.useState)(!1);(0,w.useEffect)(()=>{I()},[I]);let J=(0,w.useMemo)(()=>{let e=new Set;for(let t of p)t.sessionId&&e.add(t.sessionId);return Array.from(e)},[p]),Y=(0,w.useMemo)(()=>{let e=F.trim().toLowerCase();return p.filter(t=>{if(N&&t.sessionId!==N||P&&t.lifecycleStatus!==P)return!1;if(e){let n=t.reportId.toLowerCase().includes(e),r=t.sessionId.toLowerCase().includes(e),i=(t.reviewerModel??``).toLowerCase().includes(e);if(!n&&!r&&!i)return!1}return!0})},[p,N,P,F]);return(0,T.jsxs)(`div`,{className:`flex h-full w-full flex-col overflow-hidden bg-background text-foreground`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-border bg-card/40 px-4 py-3 sm:px-6`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`span`,{className:`text-xl`,"aria-hidden":!0,children:`🦂`}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h1`,{className:`text-base font-semibold leading-none`,children:`Chimera Review Hub & Journal`}),(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:`Track agent code reviews, findings, session lineage, and audit event timeline`})]})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,T.jsxs)(`select`,{value:N,onChange:e=>R(e.target.value),className:`rounded-lg border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Filter by session`,children:[(0,T.jsxs)(`option`,{value:``,children:[`All Sessions (`,J.length,`)`]}),J.map(e=>(0,T.jsxs)(`option`,{value:e,children:[`Session: `,e.length>16?`${e.slice(0,16)}…`:e]},e))]}),(0,T.jsxs)(`select`,{value:P,onChange:e=>z(e.target.value),className:`rounded-lg border border-border bg-background px-2.5 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary`,"aria-label":`Filter by status`,children:[(0,T.jsx)(`option`,{value:``,children:`All Statuses`}),(0,T.jsx)(`option`,{value:`open`,children:`Open`}),(0,T.jsx)(`option`,{value:`actioned`,children:`Actioned`}),(0,T.jsx)(`option`,{value:`completed`,children:`Completed`}),(0,T.jsx)(`option`,{value:`skipped`,children:`Skipped`})]}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(_,{className:`absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,T.jsx)(`input`,{type:`text`,placeholder:`Search reports...`,value:F,onChange:e=>B(e.target.value),className:`rounded-lg border border-border bg-background pl-8 pr-3 py-1.5 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary w-40 sm:w-52`})]}),(0,T.jsxs)(`button`,{type:`button`,onClick:()=>I(),disabled:A,className:`inline-flex items-center gap-1 rounded-lg border border-border bg-background px-2.5 py-1.5 text-xs font-medium hover:bg-muted transition-colors disabled:opacity-50`,title:`Refresh reports`,children:[(0,T.jsx)(b,{className:x(`h-3.5 w-3.5`,A&&`animate-spin`)}),(0,T.jsx)(`span`,{className:`hidden sm:inline`,children:`Refresh`})]})]})]}),(0,T.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0`,children:[(0,T.jsxs)(`div`,{className:`flex w-72 sm:w-80 flex-col border-r border-border bg-card/20 shrink-0 overflow-y-auto`,children:[(0,T.jsxs)(`div`,{className:`border-b border-border px-3 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider flex items-center justify-between`,children:[(0,T.jsxs)(`span`,{children:[`Reports (`,Y.length,`)`]}),A&&(0,T.jsx)(l,{className:`h-3 w-3 animate-spin`})]}),Y.length===0?(0,T.jsx)(`div`,{className:`p-6 text-center text-xs text-muted-foreground`,children:A?`Loading review reports…`:`No review reports match your filter.`}):(0,T.jsx)(`div`,{className:`divide-y divide-border/60`,children:Y.map(e=>{let t=e.reportId===h,n=O[e.lifecycleStatus]??O.open,r=n.icon,i=e.totalFindings;return(0,T.jsxs)(`button`,{type:`button`,onClick:()=>L(e.reportId),className:x(`flex w-full flex-col gap-1.5 px-3.5 py-3 text-left transition-colors hover:bg-muted/60`,t&&`bg-primary/10 border-l-2 border-primary`),children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,T.jsxs)(`span`,{className:`text-xs font-semibold truncate font-mono text-foreground`,children:[e.reportId.slice(0,12),`…`]}),(0,T.jsxs)(`span`,{className:x(`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium leading-none`,n.cls),children:[(0,T.jsx)(r,{className:`h-2.5 w-2.5`}),n.label]})]}),(0,T.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] text-muted-foreground`,children:[(0,T.jsxs)(`span`,{className:`truncate`,children:[`Sess: `,e.sessionId.slice(0,10),`…`]}),(0,T.jsx)(`span`,{children:D(e.reviewedAt)})]}),(0,T.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,T.jsx)(`span`,{className:`text-muted-foreground`,children:i===0?(0,T.jsx)(`span`,{className:`text-success font-medium`,children:`All clear ✓`}):`${i} finding(s)`}),e.counts&&i>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-1 font-mono text-[10px]`,children:[e.counts.critical>0&&(0,T.jsxs)(`span`,{className:`text-destructive font-semibold`,children:[e.counts.critical,` critical`]}),e.counts.high>0&&(0,T.jsxs)(`span`,{className:`text-warning`,children:[e.counts.high,` high`]}),e.counts.medium>0&&(0,T.jsxs)(`span`,{className:`text-warning`,children:[e.counts.medium,` med`]}),e.counts.low>0&&(0,T.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.counts.low,` low`]})]})]})]},e.reportId)})})]}),h&&y?.report?(0,T.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 flex-col lg:flex-row overflow-hidden`,children:[(0,T.jsxs)(`div`,{className:`flex flex-1 min-h-0 min-w-0 flex-col overflow-y-auto p-4 sm:p-6 space-y-6`,children:[(0,T.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-5 space-y-4 shadow-sm`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,T.jsxs)(`h2`,{className:`text-lg font-bold`,children:[`Review Report `,(0,T.jsxs)(`span`,{className:`font-mono text-sm text-muted-foreground`,children:[`(`,y.report.id,`)`]})]})}),(0,T.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:[`Session `,(0,T.jsx)(`span`,{className:`font-mono font-medium text-foreground`,children:y.report.sessionId}),` • Reviewed at `,E(y.report.reviewedAt)]})]}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,T.jsxs)(`button`,{type:`button`,onClick:()=>V(y.report.id,`actioned`,`Manual action status`),disabled:y.report.lifecycle===`actioned`,className:`inline-flex items-center gap-1 rounded-lg border border-warning/30 bg-warning/10 px-2.5 py-1 text-xs font-medium text-warning hover:bg-warning/20 disabled:opacity-40 transition-colors`,children:[(0,T.jsx)(u,{className:`h-3.5 w-3.5`}),`Mark Actioned`]}),(0,T.jsxs)(`button`,{type:`button`,onClick:()=>V(y.report.id,`completed`,`Manual completion`),disabled:y.report.lifecycle===`completed`,className:`inline-flex items-center gap-1 rounded-lg border border-success/30 bg-success/10 px-2.5 py-1 text-xs font-medium text-success hover:bg-success/20 disabled:opacity-40 transition-colors`,children:[(0,T.jsx)(g,{className:`h-3.5 w-3.5`}),`Mark Completed`]}),(0,T.jsxs)(`button`,{type:`button`,onClick:()=>V(y.report.id,`skipped`,`Manual skip`),disabled:y.report.lifecycle===`skipped`,className:`inline-flex items-center gap-1 rounded-lg border border-border bg-muted px-2.5 py-1 text-xs font-medium text-muted-foreground hover:bg-muted/80 disabled:opacity-40 transition-colors`,children:[(0,T.jsx)(i,{className:`h-3.5 w-3.5`}),`Skip`]})]})]}),(0,T.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-3 pt-2 border-t border-border/60 text-xs`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{className:`text-muted-foreground block text-[11px]`,children:`Reviewer Model`}),(0,T.jsx)(`span`,{className:`font-mono font-medium text-foreground`,children:y.report.reviewerModel||`default`})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{className:`text-muted-foreground block text-[11px]`,children:`Reviewed Files`}),(0,T.jsxs)(`span`,{className:`font-medium text-foreground`,children:[y.report.files.length,` file(s)`]})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{className:`text-muted-foreground block text-[11px]`,children:`Total Findings`}),(0,T.jsx)(`span`,{className:`font-semibold text-foreground`,children:y.report.totalFindings})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`span`,{className:`text-muted-foreground block text-[11px]`,children:`Cascade Depth`}),(0,T.jsx)(`span`,{className:`font-medium text-foreground`,children:y.report.cascadeDepth??0})]})]}),y.report.evidenceStatus&&(0,T.jsxs)(`div`,{className:`rounded-lg bg-muted/40 p-3 border border-border/80 text-xs space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,T.jsx)(`span`,{children:`Machine Evidence Verification:`}),(0,T.jsx)(`span`,{className:x(`px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase border`,y.report.evidenceStatus===`verified`?`bg-success/10 text-success border-success/30`:y.report.evidenceStatus===`failed`?`bg-destructive/10 text-destructive border-destructive/30`:`bg-warning/10 text-warning border-warning/30`),children:y.report.evidenceStatus})]}),y.report.evidenceChecks&&y.report.evidenceChecks.length>0&&(0,T.jsx)(`div`,{className:`space-y-1 font-mono text-[11px] text-muted-foreground`,children:y.report.evidenceChecks.map((e,t)=>(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`span`,{children:e.ok?`✓`:`✗`}),(0,T.jsxs)(`span`,{className:`font-semibold text-foreground`,children:[e.name,`:`]}),(0,T.jsx)(`span`,{className:`truncate`,children:e.command})]},t))})]}),(0,T.jsx)(`div`,{className:`pt-2`,children:(0,T.jsxs)(`button`,{type:`button`,onClick:()=>{if(!y?.report)return;let e=y.report,r=`Take a look at the tasks mentioned in Chimera report (${e.id}) for session ${e.sessionId} — review the ${e.totalFindings} finding(s) it flagged and address them.`,i=n(e.sessionId);i.addMessage({role:`user`,content:r}),i.patch({isLoading:!0}),t().sendMessage(r,void 0,!1,e.sessionId===`__unbound__`?void 0:e.sessionId),V(e.id,`actioned`,`Prompt dispatched to leader`)},className:`inline-flex items-center gap-2 rounded-lg bg-primary px-4 py-2 text-xs font-semibold text-primary-foreground hover:bg-primary/90 transition-colors shadow-sm`,children:[(0,T.jsx)(m,{className:`h-3.5 w-3.5`}),`Dispatch Follow-up Task to Session Leader`]})})]}),(0,T.jsxs)(`div`,{className:`space-y-4`,children:[(0,T.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,T.jsxs)(`h3`,{className:`text-sm font-bold uppercase tracking-wider text-muted-foreground`,children:[`Findings (`,y.findings.length,`)`]})}),y.findings.length===0?(0,T.jsxs)(`div`,{className:`rounded-xl border border-border/80 bg-card/40 p-8 text-center text-xs text-muted-foreground`,children:[(0,T.jsx)(d,{className:`mx-auto h-8 w-8 text-success/60 mb-2`}),`No actionable findings were discovered in this review run.`]}):(0,T.jsx)(`div`,{className:`space-y-3`,children:y.findings.map(({finding:e})=>{let t=k[e.severity]??k.low;return(0,T.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3 shadow-sm transition-all hover:border-border/80`,children:[(0,T.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(`span`,{className:x(`inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-semibold uppercase border`,t.bg,t.text),children:[(0,T.jsx)(`span`,{className:x(`h-1.5 w-1.5 rounded-full`,t.dot)}),e.severity]}),e.category&&(0,T.jsx)(`span`,{className:`rounded-md bg-muted px-2 py-0.5 text-[11px] font-medium text-muted-foreground`,children:e.category}),e.location?.file&&(0,T.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono text-xs text-foreground bg-muted/60 px-2 py-0.5 rounded`,children:[(0,T.jsx)(f,{className:`h-3 w-3 text-muted-foreground`}),e.location.file,e.location.line?`:${e.location.line}`:``]})]}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,T.jsx)(`span`,{className:`font-semibold text-muted-foreground mr-1`,children:`Status:`}),(0,T.jsx)(`span`,{className:x(`px-2 py-0.5 rounded-full text-[11px] font-medium capitalize border`,e.status===`resolved`?`bg-success/10 text-success border-success/30`:e.status===`ignored`?`bg-muted text-muted-foreground border-border`:`bg-primary/10 text-primary border-primary/30`),children:e.status}),e.status!==`resolved`&&(0,T.jsx)(`button`,{type:`button`,onClick:()=>U(e.id,`resolved`,`fixed`,`Resolved by operator in WebUI`),className:`ml-2 rounded px-2 py-0.5 text-[11px] font-medium bg-success/10 text-success hover:bg-success/20 border border-success/30`,children:`Resolve (Fixed)`}),e.status!==`ignored`&&e.status!==`resolved`&&(0,T.jsx)(`button`,{type:`button`,onClick:()=>U(e.id,`ignored`,void 0,`Ignored by operator`),className:`rounded px-2 py-0.5 text-[11px] font-medium bg-muted text-muted-foreground hover:bg-muted/80 border border-border`,children:`Ignore`}),(e.status===`resolved`||e.status===`ignored`)&&(0,T.jsx)(`button`,{type:`button`,onClick:()=>U(e.id,`active`,void 0,`Reopened in WebUI`),className:`rounded px-2 py-0.5 text-[11px] font-medium bg-primary/10 text-primary hover:bg-primary/20 border border-primary/30`,children:`Reopen`})]})]}),(0,T.jsx)(`h4`,{className:`text-sm font-semibold text-foreground`,children:e.title}),(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground whitespace-pre-wrap`,children:e.description}),e.suggestedFix&&(0,T.jsxs)(`div`,{className:`rounded-lg bg-muted/40 border border-border/80 p-3 space-y-1 text-xs`,children:[(0,T.jsx)(`span`,{className:`font-semibold text-primary block`,children:`Suggested Fix:`}),(0,T.jsx)(`pre`,{className:`font-mono text-[11px] text-foreground overflow-x-auto whitespace-pre-wrap`,children:e.suggestedFix})]}),e.verification&&(0,T.jsxs)(`div`,{className:`text-[11px] text-muted-foreground flex items-center gap-2`,children:[(0,T.jsx)(`span`,{children:`Disk check:`}),(0,T.jsxs)(`span`,{className:x(`font-semibold`,e.verification.status===`verified`?`text-success`:e.verification.status===`failed`?`text-destructive`:`text-warning`),children:[e.verification.status,` (`,e.verification.reason,`)`]}),e.verification.evidence&&(0,T.jsxs)(`span`,{className:`font-mono text-muted-foreground truncate max-w-xs`,children:[`"`,e.verification.evidence,`"`]})]})]},e.id)})})]}),y.report.rawText&&(0,T.jsxs)(`div`,{className:`rounded-xl border border-border bg-card overflow-hidden`,children:[(0,T.jsxs)(`button`,{type:`button`,onClick:()=>q(e=>!e),className:`flex w-full items-center justify-between px-4 py-3 text-xs font-semibold text-muted-foreground hover:bg-muted/50 transition-colors`,children:[(0,T.jsx)(`span`,{children:`Raw Report Markdown`}),K?(0,T.jsx)(c,{className:`h-4 w-4`}):(0,T.jsx)(o,{className:`h-4 w-4`})]}),K&&(0,T.jsx)(`div`,{className:`border-t border-border p-4 bg-muted/20`,children:(0,T.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap break-words text-muted-foreground`,children:y.report.rawText})})]})]}),(0,T.jsxs)(`div`,{className:`w-full lg:w-80 border-t lg:border-t-0 lg:border-l border-border bg-card/30 flex flex-col shrink-0 overflow-y-auto p-4 space-y-4`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border pb-3`,children:[(0,T.jsx)(a,{className:`h-4 w-4 text-primary`}),(0,T.jsx)(`h3`,{className:`text-sm font-bold`,children:`Activity Journal`})]}),(0,T.jsx)(`div`,{className:`space-y-3 flex-1 overflow-y-auto`,children:y.events.length===0?(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`No journal events recorded yet.`}):(0,T.jsx)(`div`,{className:`relative pl-4 space-y-4 before:absolute before:left-1.5 before:top-2 before:bottom-2 before:w-0.5 before:bg-border`,children:y.events.map(e=>(0,T.jsxs)(`div`,{className:`relative space-y-1 text-xs`,children:[(0,T.jsx)(`div`,{className:`absolute -left-4 top-1 h-2 w-2 rounded-full bg-primary ring-4 ring-card`}),(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-1 text-[11px] text-muted-foreground`,children:[(0,T.jsx)(`span`,{className:`font-semibold text-foreground capitalize`,children:e.eventType.replace(`_`,` `)}),(0,T.jsx)(`span`,{children:D(e.timestamp)})]}),(0,T.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[`Actor: `,(0,T.jsx)(`span`,{className:`font-medium text-foreground`,children:e.actorId}),` (`,e.actorKind,`)`]}),e.fromLifecycle&&e.toLifecycle&&(0,T.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[`Status: `,(0,T.jsxs)(`span`,{className:`text-foreground`,children:[e.fromLifecycle,` ➔ `,e.toLifecycle]})]}),e.reason&&(0,T.jsxs)(`p`,{className:`rounded bg-muted/60 p-1.5 text-[11px] text-foreground/90 italic`,children:[`"`,e.reason,`"`]})]},e.id))})}),(0,T.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),!(!h||!W.trim())&&(H(h,W.trim()),G(``))},className:`pt-3 border-t border-border space-y-2`,children:[(0,T.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground block`,children:`Add Journal Note / Inote:`}),(0,T.jsx)(`textarea`,{rows:3,value:W,onChange:e=>G(e.target.value),placeholder:`Record an observation, fix PR link, or triage note...`,className:`w-full rounded-lg border border-border bg-background p-2 text-xs placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary`}),(0,T.jsxs)(`button`,{type:`submit`,disabled:!W.trim(),className:`inline-flex w-full items-center justify-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,children:[(0,T.jsx)(r,{className:`h-3.5 w-3.5`}),`Append to Journal`]})]})]})]}):(0,T.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-8`,children:(0,T.jsx)(C,{icon:(0,T.jsx)(s,{className:`h-12 w-12 text-muted-foreground/40`}),title:`Select a Chimera Review Report`,description:`Choose a review report from the left pane to view structured findings, disk verification proofs, and the activity journal.`})})]})]})}export{A as ChimeraReviewsView};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{$ as t,K as n,t as r,x as i}from"./ws-client-D-d32pHb.js";import{Dn as a,Dr as o,Hr as s,Kt as c,La as l,Lr as u,Ni as d,Xa as f,Yt as p,bi as m,da as h,fa as g,fr as _,io as v,nn as y,oo as b,pa as x,t as S,to as C,ut as w,wa as T,xn as ee}from"./vendor-enc0q-Va.js";import"./i18n-Cv65b1SP.js";import{t as te}from"./useWebSocket-VIItbvVK.js";import{t as E}from"./utils-DQ9Exx8j.js";import"./stores-CNuMLG8X.js";import{o as D}from"./view-navigation-DPOY0lyt.js";import{a as O,n as ne,o as re,r as k,t as A}from"./dialog-BTHxOi5z.js";import{t as j}from"./button-DNyYztcH.js";import{t as M}from"./input-CTGeYzNe.js";import{D as ie,a as N,b as P,c as F,o as I,s as L,x as R}from"./index-DbprKWmG.js";var z=e(b(),1);function B(e,t=8e3){return new Promise((n,r)=>{let i=setTimeout(()=>{a(),r(Error(`timeout`))},t),a=e.on(`key.operation_result`,e=>{clearTimeout(i),a(),n(e.payload)})})}var V=w();function ae({onKeySaved:e}){let{t:i}=C(),[o,s]=(0,z.useState)(!1),[c,l]=(0,z.useState)(``),[u,d]=(0,z.useState)(`openai-compatible`),[f,p]=(0,z.useState)(``),[m,g]=(0,z.useState)(``),[v,y]=(0,z.useState)(!1),[b,x]=(0,z.useState)([]),{setFieldRef:S,handleKeyDown:w}=F(),T=async()=>{if(c.trim()){y(!0);try{let a=r(t.getState().wsUrl),o=B(a);a.send({type:`provider.add`,payload:{id:c.trim(),family:u,baseUrl:f.trim()||void 0,apiKey:m.trim()||void 0,models:b.length>0?b.map(e=>e.id):void 0,customModels:b.length>0?Object.fromEntries(b.filter(e=>e.name||e.maxOutput||e.capabilities).map(e=>[e.id,{...e.name&&e.name!==e.id?{name:e.name}:{},...e.maxOutput?{maxOutput:e.maxOutput}:{},...e.capabilities&&Object.values(e.capabilities).some(Boolean)?{capabilities:e.capabilities}:{}}])):void 0}});let d=await o;if(!d.success)throw Error(d.message);n.success(i(`setup:screen.toasts.providerAdded`,{id:c.trim()})),e(c.trim()),a.listSavedProviders(),a.probeProvider(c.trim()),l(``),p(``),g(``),x([]),s(!1)}catch(e){let t=e instanceof Error&&e.message&&e.message!==`timeout`?e.message:null;n.error(t??i(`setup:screen.toasts.providerAddFailed`))}finally{y(!1)}}};return(0,V.jsxs)(`div`,{className:`rounded-xl border border-dashed border-border/60 overflow-hidden`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>s(!o),className:`w-full flex items-center gap-3 p-4 text-left hover:bg-muted/30 transition-colors`,children:[(0,V.jsx)(`div`,{className:`w-10 h-10 rounded-lg bg-muted/50 flex items-center justify-center`,children:(0,V.jsx)(a,{className:`h-5 w-5 text-muted-foreground`})}),(0,V.jsxs)(`div`,{className:`flex-1`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-medium`,children:i(`setup:screen.custom.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`setup:screen.custom.description`)})]}),(0,V.jsx)(h,{className:E(`h-4 w-4 text-muted-foreground transition-transform`,o&&`rotate-90`)})]}),o&&(0,V.jsxs)(`div`,{className:`px-4 pb-4 space-y-3 border-t border-border/40`,children:[(0,V.jsxs)(`div`,{className:`space-y-1.5 pt-3`,children:[(0,V.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground block`,children:i(`setup:screen.custom.localServers`)}),(0,V.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:N.map(e=>(0,V.jsx)(j,{type:`button`,size:`sm`,variant:c===e.id?`default`:`outline`,onClick:()=>{l(e.id),d(`openai-compatible`),p(e.defaultBaseUrl),e.noAuth&&g(``),x([])},title:e.hint,children:e.label},e.id))})]}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:i(`setup:screen.custom.providerId`)}),(0,V.jsx)(M,{placeholder:i(`activity:customProviderSection.eGMyLlm`),value:c,onChange:e=>l(e.target.value),className:`text-sm`,ref:S(0),onKeyDown:e=>w(e,0)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:i(`setup:screen.custom.family`)}),(0,V.jsxs)(`select`,{value:u,onChange:e=>d(e.target.value),className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 text-sm`,ref:S(1),onKeyDown:e=>w(e,1),children:[(0,V.jsx)(`option`,{value:`openai-compatible`,children:i(`setup:screen.custom.familyOpenAiCompatible`)}),(0,V.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,V.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,V.jsx)(`option`,{value:`google`,children:`Google`})]})]})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:i(`setup:screen.custom.baseUrl`)}),(0,V.jsx)(M,{placeholder:i(`activity:customProviderSection.eGHttpLocalhost11434V1`),value:f,onChange:e=>p(e.target.value),className:`text-sm font-mono`,ref:S(2),onKeyDown:e=>w(e,2)})]}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`span`,{className:`text-[11px] font-medium text-muted-foreground mb-1 block`,children:i(`setup:screen.custom.apiKey`)}),(0,V.jsx)(M,{type:`password`,placeholder:i(`setup:screen.custom.apiKeyPlaceholder`),value:m,onChange:e=>g(e.target.value),className:`text-sm font-mono`,ref:S(3),onKeyDown:e=>w(e,3)})]}),(0,V.jsx)(L,{models:b,onChange:x}),(0,V.jsxs)(j,{onClick:T,disabled:!c.trim()||v,size:`sm`,ref:S(4),onKeyDown:e=>w(e,4,T),children:[v?(0,V.jsx)(_,{className:`h-4 w-4 animate-spin mr-2`}):null,i(`setup:screen.custom.add`)]})]})]})}var H=I();async function oe(e,t){try{let n=await fetch(e,{signal:t});if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.json();if(!Array.isArray(r))throw Error(`Expected JSON array`);let i=r.filter(e=>typeof e.id==`string`&&typeof e.name==`string`&&typeof e.family==`string`);return i.length>0?i:H}catch{return H}}function se(e,t){let n=new Date().getTime()-e.getTime(),r=Math.floor(n/1e3);if(r<10)return t(`setup:screen.time.justNow`);if(r<60)return t(`setup:screen.time.secondsAgo`,{count:r});let i=Math.floor(r/60);if(i<60)return t(`setup:screen.time.minutesAgo`,{count:i});let a=Math.floor(i/60);return a<24?t(`setup:screen.time.hoursAgo`,{count:a}):t(`setup:screen.time.daysAgo`,{count:Math.floor(a/24)})}var ce=e(S(),1);function le({popular:e,catalogProvider:i,savedProvider:a,onKeySaved:o,probeResult:c}){let{t:l}=C(),[u,f]=(0,z.useState)(``),[p,v]=(0,z.useState)(!1),[b,S]=(0,z.useState)(!!a?.apiKeys.some(e=>e.isActive)),[w,T]=(0,z.useState)(!1),[ee,te]=(0,z.useState)(!1),[D,ie]=(0,z.useState)(!1),[N,P]=(0,z.useState)(null);(0,z.useEffect)(()=>{D&&e.referral&&ce.toDataURL(e.referral.url,{width:200,margin:2,color:{dark:`#000000`,light:`#ffffff`}}).then(e=>P(e)).catch(()=>P(null))},[D,e.referral]);let F=async()=>{if(u.trim()){v(!0);try{let a=r(t.getState().wsUrl),s=B(a);i?a.addKey(e.id,`default`,u.trim()):a.send({type:`provider.add`,payload:{id:e.id,family:e.family,apiKey:u.trim()}});let c=await s;if(!c.success)throw Error(c.message);S(!0),f(``),n.success(l(`setup:screen.toasts.keySaved`,{name:e.name})),o(e.id),a.listSavedProviders(),a.probeProvider(e.id)}catch(t){let r=t instanceof Error&&t.message&&t.message!==`timeout`?t.message:null;n.error(r??l(`setup:screen.toasts.keySaveFailed`,{name:e.name}))}finally{v(!1)}}},I=e=>{e.key===`Enter`&&u.trim()&&F()},L=async()=>{if(e.referral)try{await navigator.clipboard.writeText(e.referral.url),te(!0),n.success(l(`setup:screen.toasts.referralCopied`)),setTimeout(()=>te(!1),2e3)}catch{n.error(l(`setup:screen.toasts.referralCopyFailed`))}},R=i&&i.modelCount>0;return(0,V.jsxs)(`div`,{className:E(`rounded-xl border p-4 transition-all`,b?`border-success/30 bg-success/5`:`bg-gradient-to-br ${e.color}`),children:[(0,V.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,V.jsx)(`span`,{className:`text-2xl shrink-0 mt-0.5`,children:e.icon}),(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),b&&(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-success/10 text-success border border-success/20`,children:[(0,V.jsx)(x,{className:`h-2.5 w-2.5`}),l(`setup:screen.card.keySaved`)]}),e.referral&&!b&&(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-warning/10 text-warning border border-warning/20`,children:[(0,V.jsx)(s,{className:`h-2.5 w-2.5`}),l(`setup:screen.card.referral`)]})]}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e.description}),e.referral&&!b&&(0,V.jsxs)(`p`,{className:`text-[11px] text-warning/80 mt-1`,children:[`🎁 `,e.referral.reward]}),b?b?(0,V.jsxs)(`div`,{className:`mt-3 space-y-1`,children:[a?.baseUrl&&(0,V.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70 font-mono truncate`,title:a.baseUrl,children:[(0,V.jsxs)(`span`,{className:`text-muted-foreground/50`,children:[l(`activity:providerKey.url`),` `]}),a.baseUrl]}),a?.models&&a.models.length>0&&(0,V.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:[(0,V.jsxs)(`span`,{className:`text-muted-foreground/50`,children:[l(`activity:providerKey.models`),` `]}),a.pickedModelId??a.models[0],(0,V.jsxs)(`span`,{className:`text-muted-foreground/50`,children:[` (+`,a.models.length-1,` more)`]})]}),c===`probing`?(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground mt-1`,children:[(0,V.jsx)(_,{className:`h-3 w-3 animate-spin`}),l(`setup:screen.probe.checking`,`Checking connection…`)]}):c?.ok?(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-success mt-1`,children:[(0,V.jsx)(x,{className:`h-3 w-3`}),(0,V.jsxs)(`span`,{children:[l(`setup:screen.probe.connected`,`Connected`),c.modelCount!=null&&` · ${c.modelCount} ${l(`setup:screen.probe.models`,`models`)}`,c.elapsedMs!=null&&` · ${c.elapsedMs}ms`]})]}):c&&!c.ok?(0,V.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[11px] text-destructive mt-1`,children:[(0,V.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:`✕`}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`font-medium`,children:l(`setup:screen.probe.failed`,`Probe failed`)}),c.status===`no_base_url`&&(0,V.jsx)(`span`,{className:`block text-destructive/70`,children:l(`setup:screen.probe.noBaseUrl`,`No base URL configured`)}),c.status===`unreachable`&&(0,V.jsxs)(`span`,{className:`block text-destructive/70`,children:[l(`setup:screen.probe.unreachable`,`Could not connect`),c.detail?`: ${c.detail}`:``]}),c.status!==`no_base_url`&&c.status!==`unreachable`&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`span`,{className:`block text-destructive/70`,children:c.httpStatus==null?c.status:`${l(`setup:screen.probe.httpStatus`,`Status`)} ${c.httpStatus}`}),c.detail&&(0,V.jsx)(`span`,{className:`block text-destructive/70 truncate max-w-[250px]`,title:c.detail,children:c.detail})]})]})]}):null,R&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>T(!w),className:`text-[11px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:[l(`setup:screen.providers.modelsAvailable`,{count:i?.modelCount??0}),w?(0,V.jsx)(g,{className:`h-3 w-3`}):(0,V.jsx)(h,{className:`h-3 w-3`})]})]}):null:(0,V.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsx)(M,{type:`password`,placeholder:e.keyPlaceholder,value:u,onChange:e=>f(e.target.value),onKeyDown:I,className:`font-mono text-sm`}),(0,V.jsx)(j,{onClick:F,disabled:!u.trim()||p,size:`sm`,className:`shrink-0`,children:p?(0,V.jsx)(_,{className:`h-4 w-4 animate-spin`}):l(`setup:screen.card.save`)})]}),e.docsUrl&&(0,V.jsxs)(`a`,{href:e.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground transition-colors`,children:[l(`setup:screen.card.getKey`),` `,(0,V.jsx)(m,{className:`h-3 w-3`})]}),e.referral&&(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:L,className:`inline-flex items-center gap-1 text-[11px] text-warning/80 hover:text-warning transition-colors`,children:ee?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(x,{className:`h-3 w-3`}),` `,l(`setup:screen.card.copied`)]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(d,{className:`h-3 w-3`}),` `,l(`setup:screen.card.copyReferral`)]})}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>ie(!0),className:`inline-flex items-center gap-1 text-[11px] text-warning/80 hover:text-warning transition-colors`,children:[(0,V.jsx)(y,{className:`h-3 w-3`}),` `,l(`setup:screen.card.share`)]})]})]})]})]}),(0,V.jsx)(A,{open:D,onOpenChange:ie,children:(0,V.jsxs)(ne,{className:`sm:max-w-md`,children:[(0,V.jsxs)(O,{children:[(0,V.jsxs)(re,{className:`flex items-center gap-2`,children:[(0,V.jsx)(s,{className:`h-4 w-4 text-warning`}),l(`setup:screen.share.title`,{name:e.name})]}),(0,V.jsx)(k,{children:l(`setup:screen.share.description`)})]}),(0,V.jsx)(`div`,{className:`flex flex-col items-center gap-4 py-4`,children:e.referral&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`div`,{className:`text-sm text-center`,children:(0,V.jsxs)(`p`,{className:`font-medium text-warning`,children:[`🎁 `,e.referral.reward]})}),N?(0,V.jsx)(`div`,{className:`rounded-lg border border-border p-2 bg-white`,children:(0,V.jsx)(`img`,{src:N,alt:l(`setup:screen.card.qrAlt`,{name:e.name}),className:`w-[200px] h-[200px]`})}):(0,V.jsx)(`div`,{className:`w-[200px] h-[200px] rounded-lg border border-border flex items-center justify-center bg-muted`,children:(0,V.jsx)(_,{className:`h-6 w-6 animate-spin text-muted-foreground`})}),(0,V.jsxs)(`div`,{className:`w-full space-y-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`https://twitter.com/intent/tweet?text=${t}&url=${n}`,`_blank`,`noopener,noreferrer`)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-xs text-foreground hover:bg-muted transition-colors`,title:l(`setup:screen.share.twitter`),children:[(0,V.jsx)(`svg`,{role:`img`,"aria-hidden":`true`,className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{d:`M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z`})}),`X`]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(e.referral.url),n=encodeURIComponent(`Check out ${e.name}! ${e.referral.reward}`);window.open(`https://www.linkedin.com/sharing/share-offsite/?url=${t}&summary=${n}`,`_blank`,`noopener,noreferrer`)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-xs text-foreground hover:bg-muted transition-colors`,title:l(`setup:screen.share.linkedin`),children:[(0,V.jsx)(`svg`,{role:`img`,"aria-hidden":`true`,className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{d:`M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z`})}),l(`activity:providerKey.linkedin`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward} ${e.referral.url}`);window.open(`https://t.me/share/url?url=${t}`,`_blank`,`noopener,noreferrer`)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-xs text-foreground hover:bg-muted transition-colors`,title:l(`setup:screen.share.telegram`),children:[(0,V.jsx)(`svg`,{role:`img`,"aria-hidden":`true`,className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{d:`M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z`})}),l(`activity:providerKey.telegram`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`https://wa.me/?text=${t}%20${n}`,`_blank`,`noopener,noreferrer`)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-xs text-foreground hover:bg-muted transition-colors`,title:l(`setup:screen.share.whatsapp`),children:[(0,V.jsx)(`svg`,{role:`img`,"aria-hidden":`true`,className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{d:`M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.134 1.585 5.934L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z`})}),l(`activity:providerKey.whatsapp`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(e.referral.url),n=encodeURIComponent(`${e.name} - ${e.referral.reward}`);window.open(`https://www.reddit.com/submit?url=${t}&title=${n}`,`_blank`,`noopener,noreferrer`)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-xs text-foreground hover:bg-muted transition-colors`,title:l(`setup:screen.share.reddit`),children:[(0,V.jsx)(`svg`,{role:`img`,"aria-hidden":`true`,className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{d:`M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.25 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 0 1.108-.701 1.25 1.25 0 0 1 2.144.33zm-8.811 8.748c-.968 0-1.754.786-1.754 1.754 0 .968.786 1.754 1.754 1.754.968 0 1.754-.786 1.754-1.754 0-.968-.786-1.754-1.754-1.754zm7.944 0c-.968 0-1.754.786-1.754 1.754 0 .968.786 1.754 1.754 1.754.968 0 1.754-.786 1.754-1.754 0-.968-.786-1.754-1.754-1.754z`})}),l(`activity:providerKey.reddit`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`https://www.facebook.com/sharer/sharer.php?u=${n}&quote=${t}`,`_blank`,`noopener,noreferrer`)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-border bg-card text-xs text-foreground hover:bg-muted transition-colors`,title:l(`setup:screen.share.facebook`),children:[(0,V.jsx)(`svg`,{role:`img`,"aria-hidden":`true`,className:`h-3.5 w-3.5`,fill:`currentColor`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{d:`M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z`})}),l(`activity:providerKey.facebook`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>{let t=encodeURIComponent(`Check out ${e.name}! 🎁 ${e.referral.reward}`),n=encodeURIComponent(e.referral.url);window.open(`mailto:?subject=${t}&body=${n}`,`_blank`,`noopener,noreferrer`)},className:`inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-muted text-muted-foreground text-xs hover:bg-muted/80 transition-colors`,title:l(`setup:screen.share.email`),children:[(0,V.jsx)(`svg`,{role:`img`,"aria-hidden":`true`,className:`h-3.5 w-3.5`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,viewBox:`0 0 24 24`,children:(0,V.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,d:`M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25H4.5a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75`})}),l(`activity:providerKey.email`)]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(M,{value:e.referral.url,readOnly:!0,className:`font-mono text-xs flex-1`}),(0,V.jsx)(j,{size:`sm`,variant:`outline`,onClick:L,className:`shrink-0`,children:ee?(0,V.jsx)(x,{className:`h-4 w-4`}):(0,V.jsx)(d,{className:`h-4 w-4`})})]}),(0,V.jsx)(`p`,{className:`text-[11px] text-muted-foreground text-center`,children:l(`setup:screen.share.hint`)})]})]})})]})})]})}function U(){let{t:e}=C(),{model:a,setProvider:s,setModel:d,wsConnected:m,wsUrl:g}=t(f(e=>({model:e.model,setProvider:e.setProvider,setModel:e.setModel,wsConnected:e.wsConnected,wsUrl:e.wsUrl})));te();let[y,b]=(0,z.useState)([]),[S,w]=(0,z.useState)({}),[O,ne]=(0,z.useState)([]),[re,k]=(0,z.useState)(!1),[A,M]=(0,z.useState)(null),[N,F]=(0,z.useState)(0),[I,L]=(0,z.useState)(new Set),[B,ce]=(0,z.useState)({}),[U,ue]=(0,z.useState)(H),[W,G]=(0,z.useState)(!1),[de,fe]=(0,z.useState)(0),[pe,me]=(0,z.useState)(0),[K,he]=(0,z.useState)(null),q=(0,z.useRef)(!0);(0,z.useEffect)(()=>{let e=new AbortController,t=`${window.location.origin}/providers.json`;return G(!0),oe(t,e.signal).then(t=>{if(t!==H){if(ue(t),G(!1),!q.current){let e=t.length-pe;e>0?n.success(v.t(`setup:screen.toasts.providersLoadedNew`,{count:t.length,diff:e})):e<0?n.success(v.t(`setup:screen.toasts.providersLoadedRemoved`,{count:t.length,diff:Math.abs(e)})):n.success(v.t(`setup:screen.toasts.providersLoadedNoChanges`,{count:t.length})),me(t.length)}he(new Date);return}return oe(`https://raw.githubusercontent.com/WrongStack/WrongStack/main/packages/webui/public/providers.json`,e.signal)}).then(e=>{if(e){if(ue(e),!q.current){let t=e.length-pe;t>0?n.success(v.t(`setup:screen.toasts.providersLoadedNew`,{count:e.length,diff:t})):t<0?n.success(v.t(`setup:screen.toasts.providersLoadedRemoved`,{count:e.length,diff:Math.abs(t)})):n.success(v.t(`setup:screen.toasts.providersLoadedNoChanges`,{count:e.length})),me(e.length)}he(new Date)}}).catch(()=>{q.current||n.error(v.t(`setup:screen.toasts.providersRefreshFailed`))}).finally(()=>{G(!1),q.current=!1}),()=>e.abort()},[de]);let[J,ge]=(0,z.useState)(null),[Y,X]=(0,z.useState)(null),[_e,ve]=(0,z.useState)(!1);(0,z.useEffect)(()=>{if(!m)return;let e=r(g),t=setTimeout(()=>{t=null,k(!1),M(v.t(`setup:screen.errors.backendNotResponding`))},8e3),n=()=>{t&&=(clearTimeout(t),null)},i=e.on(`provider.catalog`,e=>{if(e.type===`provider.catalog`){n(),M(null);let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));b(t),k(!1)}}),o=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let t=e.payload;if(t.provider!==J)return;w(e=>({...e,[t.provider]:t.models})),ve(!1),t.models.length===1?X(t.models[0].id):a&&t.models.some(e=>e.id===a)&&X(a)}}),s=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));ne(t);let n=new Set(t.filter(e=>e.apiKeys.some(e=>e.isActive)).map(e=>e.id));L(n)}}),c=e.on(`provider.probe`,e=>{if(e.type!==`provider.probe`)return;let t=e.payload;ce(e=>({...e,[t.providerId]:t}))});return M(null),k(!0),e.listProviders(),()=>{n(),i?.(),o?.(),s?.(),c?.()}},[m,g,a,N,J]);let ye=(0,z.useCallback)(()=>{M(null),F(e=>e+1)},[]),be=(0,z.useCallback)(()=>{fe(e=>e+1)},[]),xe=(0,z.useCallback)(t=>se(t,e),[e]),Z=(0,z.useCallback)(e=>{L(t=>new Set([...t,e])),ge(e),X(null)},[]),Se=I.size>0;(0,z.useEffect)(()=>{if(!J||!m)return;let e=r(g);S[J]||(ve(!0),e.listProviderModels(J))},[J,m,g,S]);let Ce=J?S[J]??[]:[],we=(0,z.useCallback)(async()=>{if(!J||!Y)return;if(!I.has(J)){n.error(`Please save the provider configuration before starting a session.`);return}s(J),d(Y);let e=await r(g).switchModel(J,Y,5e3);e.success?(i.getState().openPicker({startsSession:!0}),D(`chat`)):n.error(e.message||v.t(`setup:screen.errors.modelSwitchTimeout`))},[J,Y,s,d,g]),Te=(0,z.useCallback)(async()=>{if(!J||!Y)return;s(J),d(Y);let e=await r(g).switchModel(J,Y,5e3);e.success?D(`chat`):n.error(e.message||v.t(`setup:screen.errors.modelSwitchTimeout`))},[J,Y,s,d,g]),Ee=new Set(U.map(e=>e.id)),De=y.filter(e=>!Ee.has(e.id)).sort((e,t)=>e.id.localeCompare(t.id)),Q=R(De,10);R(O,9);let $=R(Ce,12,J);return(0,V.jsxs)(`div`,{className:`flex h-full min-h-0 min-w-0 flex-col`,children:[(0,V.jsxs)(`header`,{className:`flex shrink-0 flex-col gap-3 border-b bg-card px-4 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-6`,children:[(0,V.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,V.jsx)(`img`,{src:`/wrongstack.svg`,alt:`WrongStack`,draggable:!1,className:`ws-brand-logo h-10 w-10 shrink-0 border border-border/70 shadow-sm`}),(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`h1`,{className:`truncate text-lg font-semibold`,children:e(`setup:screen.header.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground sm:truncate`,children:e(`setup:screen.header.subtitle`)})]})]}),Se&&J?(0,V.jsxs)(`span`,{className:`text-xs text-success/80`,children:[(0,V.jsx)(x,{className:`h-3 w-3 inline-block mr-1`}),e(`setup:screen.header.continue`)]}):null]}),(0,V.jsx)(ie,{className:`min-h-0 flex-1`,children:(0,V.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-8 p-4 pb-4 sm:p-6`,children:[(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-sm`,children:[(0,V.jsxs)(`div`,{className:E(`flex min-w-0 items-center gap-1.5`,Se?`text-success`:`text-primary font-medium`),children:[(0,V.jsx)(o,{className:`h-4 w-4`}),(0,V.jsx)(`span`,{children:e(`setup:screen.steps.addKeys`)})]}),(0,V.jsx)(h,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,V.jsxs)(`div`,{className:E(`flex min-w-0 items-center gap-1.5`,J?`text-primary font-medium`:`text-muted-foreground`),children:[(0,V.jsx)(T,{className:`h-4 w-4`}),(0,V.jsx)(`span`,{children:e(`setup:screen.steps.pickModel`)})]}),(0,V.jsx)(h,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,V.jsxs)(`div`,{className:E(`flex min-w-0 items-center gap-1.5`,J&&Y?`text-primary font-medium`:`text-muted-foreground`),children:[(0,V.jsx)(c,{className:`h-4 w-4`}),(0,V.jsx)(`span`,{children:e(`setup:screen.steps.start`)})]})]}),(0,V.jsxs)(`div`,{className:`flex items-start gap-3 rounded-xl border border-primary/20 bg-primary/5 p-4`,children:[(0,V.jsx)(p,{className:`h-5 w-5 text-primary shrink-0 mt-0.5`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-sm font-medium`,children:e(`setup:screen.security.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`setup:screen.security.body`)})]})]}),A?(0,V.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-4 py-12 rounded-xl border border-destructive/30 bg-destructive/5 px-6`,children:[(0,V.jsx)(`div`,{className:`w-12 h-12 rounded-xl bg-destructive/10 border border-destructive/30 flex items-center justify-center`,children:(0,V.jsx)(u,{className:`h-6 w-6 text-destructive`})}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-destructive`,children:e(`setup:screen.errors.backendUnreachable`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 max-w-sm`,children:A})]}),(0,V.jsxs)(j,{onClick:ye,size:`sm`,variant:`outline`,children:[(0,V.jsx)(_,{className:`h-4 w-4 mr-2`}),e(`setup:screen.errors.retry`)]})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,V.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:e(`setup:screen.providers.popular`)}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[W&&(0,V.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,V.jsx)(_,{className:`h-3 w-3 animate-spin`}),e(`setup:screen.providers.updating`)]}),K&&!W&&(0,V.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,title:K.toLocaleString(),children:xe(K)}),(0,V.jsxs)(`button`,{type:`button`,onClick:be,disabled:W,className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed`,title:e(`setup:screen.providers.refreshTitle`),children:[(0,V.jsx)(ee,{className:E(`h-3 w-3`,W&&`animate-spin`)}),e(`setup:screen.providers.refresh`)]})]})]}),(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:U.map(e=>(0,V.jsx)(le,{popular:e,catalogProvider:y.find(t=>t.id===e.id),savedProvider:O.find(t=>t.id===e.id),onKeySaved:Z,probeResult:B[e.id]},e.id))})]}),De.length>0&&(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:e(`setup:screen.providers.more`)}),(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:Q.pageItems.map(t=>(0,V.jsx)(le,{popular:{id:t.id,name:t.name,description:e(`setup:screen.providers.catalogDescription`,{family:t.family,count:t.modelCount}),icon:`🔗`,color:`from-muted/60 to-muted/20 border-border hover:border-primary/40`,keyPlaceholder:`API key`,family:t.family},catalogProvider:t,savedProvider:O.find(e=>e.id===t.id),onKeySaved:Z,probeResult:B[t.id]},t.id))}),(0,V.jsx)(P,{page:Q.page,pageSize:Q.pageSize,totalItems:Q.totalItems,onPageChange:Q.setPage,itemLabel:`providers`})]}),(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground uppercase tracking-wider`,children:e(`setup:screen.providers.selfHosted`)}),(0,V.jsx)(ae,{onKeySaved:Z})]})]}),re&&(0,V.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,V.jsx)(_,{className:`h-6 w-6 animate-spin text-muted-foreground`})}),J&&(0,V.jsxs)(`div`,{className:`space-y-3`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,V.jsx)(c,{className:`h-4 w-4 text-primary`}),e(`setup:screen.start.chooseModel`)]}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>{ge(null),X(null)},className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:e(`setup:screen.start.addMoreKeys`)})]}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`setup:screen.start.modelsFor`,{provider:J})}),_e?(0,V.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,V.jsx)(_,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):Ce.length>0?(0,V.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:$.pageItems.map(e=>{let t=e.contextWindow?`${(e.contextWindow/1e6).toFixed(0)}M ctx`:null;return(0,V.jsx)(`button`,{type:`button`,onClick:()=>X(e.id),className:E(`w-full text-left rounded-xl border p-3 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,Y===e.id?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,V.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,V.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,V.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[t&&(0,V.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:t}),e.capabilities.slice(0,3).map(e=>(0,V.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20`,children:e},e))]})]}),Y===e.id&&(0,V.jsx)(`div`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-primary`,children:(0,V.jsx)(x,{className:`h-3 w-3 text-primary-foreground`})})]})},e.id)})}):(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:e(`setup:screen.errors.noModels`)}),(0,V.jsx)(P,{page:$.page,pageSize:$.pageSize,totalItems:$.totalItems,onPageChange:$.setPage,itemLabel:`models`})]}),J&&Y&&(0,V.jsxs)(`div`,{className:`sticky bottom-0 -mx-4 border-t bg-background/80 px-4 py-4 backdrop-blur-sm sm:-mx-6 sm:px-6`,children:[(0,V.jsx)(`div`,{className:`mb-3 flex min-w-0 items-center justify-between gap-2 text-sm text-muted-foreground`,children:(0,V.jsxs)(`span`,{className:`min-w-0 truncate`,children:[J,` / `,Y]})}),(0,V.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-2`,children:[(0,V.jsxs)(j,{onClick:we,className:`flex-1`,size:`lg`,children:[(0,V.jsx)(T,{className:`h-4 w-4 mr-2`}),e(`setup:screen.start.startSession`),(0,V.jsx)(l,{className:`h-4 w-4 ml-2`})]}),(0,V.jsxs)(j,{onClick:Te,variant:`outline`,className:`flex-1`,size:`lg`,children:[(0,V.jsx)(x,{className:`h-4 w-4 mr-2`}),e(`setup:screen.start.saveConfig`)]})]}),(0,V.jsx)(`p`,{className:`text-[11px] text-muted-foreground/60 text-center mt-2`,children:e(`setup:screen.start.saveConfigHint`)})]})]})})]})}export{U as SetupScreen};