@cuongtran001/kanna 1.63.2 → 1.63.3
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/README.md +5 -9
- package/dist/client/assets/{BoardsPage-BJalB-bc.js → BoardsPage-AckCuswi.js} +1 -1
- package/dist/client/assets/BoardsRoutePage-DzKwKy3f.js +1 -0
- package/dist/client/assets/ChatPage-DsaH8CTz.js +93 -0
- package/dist/client/assets/{CronJobRow-CPbO_jwU.js → CronJobRow-Bx9gRqKW.js} +1 -1
- package/dist/client/assets/{CronJobsPage-Ck3SNgGi.js → CronJobsPage-v0-2X1oX.js} +1 -1
- package/dist/client/assets/{FilePreviewSheet-XEuUtDPn.js → FilePreviewSheet-B6SDxSD0.js} +2 -2
- package/dist/client/assets/{FlowSurface-BCbeMTJe.js → FlowSurface-CLC-ZFar.js} +1 -1
- package/dist/client/assets/{GenUIBlock-BJy_dfs-.js → GenUIBlock-CC79Ujro.js} +2 -2
- package/dist/client/assets/{KannaSocketProvider-D7Lzlt35.js → KannaSocketProvider-B2sHsWP5.js} +1 -1
- package/dist/client/assets/{LocalProjectsPage-9LJkQjhT.js → LocalProjectsPage-DYBkcEAm.js} +1 -1
- package/dist/client/assets/SettingsPage-CZqMkMRW.js +9 -0
- package/dist/client/assets/{StackBoardsRoutePage-t_EaFNG4.js → StackBoardsRoutePage-Clviz0hX.js} +1 -1
- package/dist/client/assets/{ToolCallMessage-RbF9XT2B.js → ToolCallMessage-BfNbWGmc.js} +1 -1
- package/dist/client/assets/{VChartSurface-CKuPelsn.js → VChartSurface-CUbxyBo3.js} +1 -1
- package/dist/client/assets/{WorkflowsPage-B6qUmQA3.js → WorkflowsPage-rengzb97.js} +1 -1
- package/dist/client/assets/{WorkflowsSection-DxO0S4An.js → WorkflowsSection-DuXdLsMO.js} +1 -1
- package/dist/client/assets/{chart-renderer-DjYZvNxh.js → chart-renderer-D7ukB2wg.js} +1 -1
- package/dist/client/assets/{chatSounds-FD2DQzF6.js → chatSounds-BLg2xPDZ.js} +1 -1
- package/dist/client/assets/chevron-left-RbFvmeyK.js +1 -0
- package/dist/client/assets/{clipboard.adapter-GN9nnYak.js → clipboard.adapter-CgdNwn-1.js} +1 -1
- package/dist/client/assets/{columnStyle-DjA7hA9k.js → columnStyle-CMCF0ds6.js} +1 -1
- package/dist/client/assets/{createScopedStore-BoLB9Rhc.js → createScopedStore-BrD5NHWx.js} +1 -1
- package/dist/client/assets/{dist-CimtOoGK.js → dist-DNSTHlSo.js} +1 -1
- package/dist/client/assets/editor-icons-DY4uKeEY.js +1 -0
- package/dist/client/assets/{ellipsis-Cd7sO0LO.js → ellipsis-OHg0x_x1.js} +1 -1
- package/dist/client/assets/{flow-kinds-CW2TU_83.js → flow-kinds-Ki2DP9nP.js} +1 -1
- package/dist/client/assets/{folder-C7sXCaHj.js → folder-CnWzWIG5.js} +1 -1
- package/dist/client/assets/{formatters-wSVyvDFZ.js → formatters-BGORekd-.js} +1 -1
- package/dist/client/assets/{genui-EzBIAYFE.js → genui-C9i6j0XZ.js} +1 -1
- package/dist/client/assets/{globe-xmRpmpma.js → globe-BjR1tyE4.js} +1 -1
- package/dist/client/assets/{host-DCaA9W-Z.js → host-D9tJwZXl.js} +1 -1
- package/dist/client/assets/{index-CDqjh7nt.js → index-CesRxZ0X.js} +7 -7
- package/dist/client/assets/index-CxDE9VOy.css +1 -0
- package/dist/client/assets/{info-D4MMvZFe.js → info-DNYekoE-.js} +1 -1
- package/dist/client/assets/{input-C4fvDiQ4.js → input-DgW9uRZN.js} +1 -1
- package/dist/client/assets/{lexicalToReact-sPUyOWk6.js → lexicalToReact-CZvp9Pgz.js} +3 -3
- package/dist/client/assets/{log-aTaDVF_e.js → log-DnEvbp3E.js} +1 -1
- package/dist/client/assets/{monitor-_CRKcV1h.js → monitor-qbWfUdBG.js} +1 -1
- package/dist/client/assets/{pencil-fNBeUUCf.js → pencil-C965rrpd.js} +1 -1
- package/dist/client/assets/{pendingActionsStore-COTh4Ztq.js → pendingActionsStore-CxhI19V9.js} +1 -1
- package/dist/client/assets/{play-BAmkJfn6.js → play-uofLR7yT.js} +1 -1
- package/dist/client/assets/{plus-c75CkNEO.js → plus-D4CI6rj1.js} +1 -1
- package/dist/client/assets/{popover-CHM4skzh.js → popover-Bc646hKn.js} +1 -1
- package/dist/client/assets/{pushClient-BJH_ITRB.js → pushClient-CxnHu9h4.js} +1 -1
- package/dist/client/assets/runDetached-DfQXHAaY.js +1 -0
- package/dist/client/assets/{segmented-control-DNOwRupT.js → segmented-control-CKGX29Kl.js} +1 -1
- package/dist/client/assets/{select-dLHiAls6.js → select-BjeajpVt.js} +1 -1
- package/dist/client/assets/{settings-header-button-CGKCzFyk.js → settings-header-button-BYvHR6Xl.js} +1 -1
- package/dist/client/assets/{sidebarPendingActions-Dyp80Lv_.js → sidebarPendingActions-xgMTnfRY.js} +1 -1
- package/dist/client/assets/{square-pen-B1IxmScM.js → square-pen-DmppQdTd.js} +1 -1
- package/dist/client/assets/{state-mark-BhTZfcYe.js → state-mark-C3kEL1hX.js} +1 -1
- package/dist/client/assets/{status-pill-CwhJhaMy.js → status-pill-Bo1Nb6HX.js} +1 -1
- package/dist/client/assets/{terminal-Bnj7qFGw.js → terminal-DfCF-J4p.js} +1 -1
- package/dist/client/assets/{timer.adapter-DHt2zwsL.js → timer.adapter-C2RhP4d6.js} +1 -1
- package/dist/client/assets/{tools-3gJcj3hK.js → tools-t5T_3UBg.js} +1 -1
- package/dist/client/assets/{triangle-alert-CWrc0CIO.js → triangle-alert-CYQhobyY.js} +1 -1
- package/dist/client/assets/useAppGlobalState-DUa3pkCF.js +1 -0
- package/dist/client/assets/useKannaState-FcieR5qb.js +5 -0
- package/dist/client/assets/useTheme-D9sKDPEm.js +1 -0
- package/dist/client/index.html +35 -35
- package/package.json +2 -2
- package/src/server/agent-coordinator-types.ts +0 -6
- package/src/server/agent-coordinator.ts +6 -45
- package/src/server/agent.compaction.test.ts +1 -13
- package/src/server/agent.oauth-account-info.test.ts +0 -3
- package/src/server/agent.oauth-release.test.ts +0 -2
- package/src/server/agent.oauth-rotation.test.ts +0 -9
- package/src/server/agent.oauth-token-share-cap.test.ts +0 -1
- package/src/server/agent.openrouter-model.test.ts +0 -2
- package/src/server/agent.openrouter-watchdog.test.ts +0 -3
- package/src/server/agent.sdk-workflow-register.test.ts +2 -64
- package/src/server/agent.test.ts +1 -319
- package/src/server/app-settings.test.ts +14 -17
- package/src/server/app-settings.ts +22 -37
- package/src/server/auto-continue/e2e.test.ts +0 -1
- package/src/server/background-task-output-registry.test.ts +1 -1
- package/src/server/background-task-output-registry.ts +1 -1
- package/src/server/claude-cancel-handler.test.ts +0 -58
- package/src/server/claude-cancel-handler.ts +1 -17
- package/src/server/claude-harness-stream.test.ts +134 -0
- package/src/server/{claude-pty/jsonl-path.test.ts → claude-projects-path.adapter.test.ts} +1 -19
- package/src/server/{claude-pty/jsonl-path.adapter.ts → claude-projects-path.adapter.ts} +0 -11
- package/src/server/claude-send-command.test.ts +0 -1
- package/src/server/claude-session-config-helpers.test.ts +1 -90
- package/src/server/claude-session-config-helpers.ts +1 -38
- package/src/server/claude-session-error-handler.test.ts +0 -1
- package/src/server/claude-session-lifecycle.test.ts +2 -36
- package/src/server/claude-session-lifecycle.ts +2 -8
- package/src/server/claude-session-runner.test.ts +8 -36
- package/src/server/claude-session-runner.ts +1 -26
- package/src/server/claude-session-spawner.test.ts +5 -64
- package/src/server/claude-session-spawner.ts +49 -115
- package/src/server/claude-session-start.test.ts +1 -14
- package/src/server/claude-session-start.ts +0 -8
- package/src/server/claude-session-state-queries.test.ts +1 -2
- package/src/server/claude-session-state.test.ts +0 -1
- package/src/server/claude-session-state.ts +0 -4
- package/src/server/claude-subagent-wiring.test.ts +2 -68
- package/src/server/claude-subagent-wiring.ts +3 -50
- package/src/server/claude-turn-starter-types.ts +0 -3
- package/src/server/claude-turn-starter.test.ts +0 -28
- package/src/server/claude-turn-starter.ts +0 -5
- package/src/server/event-store.test.ts +0 -2
- package/src/server/events.ts +1 -2
- package/src/server/harness-types.ts +1 -2
- package/src/server/import-subagent-drill.e2e.test.ts +1 -1
- package/src/server/imported-subagents-dir.test.ts +1 -1
- package/src/server/imported-subagents-dir.ts +1 -1
- package/src/server/kanna-mcp.test.ts +0 -75
- package/src/server/kanna-mcp.ts +1 -47
- package/src/server/server.test.ts +5 -7
- package/src/server/server.ts +2 -18
- package/src/server/subagent-orchestrator.test.ts +0 -1
- package/src/server/subagent-provider-run.test.ts +48 -10
- package/src/server/subagent-provider-run.ts +12 -3
- package/src/server/tool-callback.test.ts +1 -1
- package/src/server/ws-router-agent-ctrl.test.ts +0 -45
- package/src/server/ws-router-agent-ctrl.ts +1 -31
- package/src/server/ws-router-broadcast.ts +0 -27
- package/src/server/ws-router-defaults.test.ts +2 -3
- package/src/server/ws-router-defaults.ts +2 -3
- package/src/server/ws-router-envelope.ts +0 -15
- package/src/server/ws-router-observability.test.ts +1 -1
- package/src/server/ws-router-settings.test.ts +2 -2
- package/src/server/ws-router.test.ts +2 -2
- package/src/server/ws-router.ts +0 -8
- package/src/shared/app-settings-types.ts +9 -20
- package/src/shared/claude-api-error-classification.ts +1 -1
- package/src/shared/protocol.ts +1 -11
- package/dist/client/assets/BoardsRoutePage-BTTjJX-Y.js +0 -1
- package/dist/client/assets/ChatPage-DH8wtQyD.js +0 -93
- package/dist/client/assets/SettingsPage-CKrZ6dGQ.js +0 -9
- package/dist/client/assets/chevron-left-CJ0qv9kF.js +0 -1
- package/dist/client/assets/editor-icons-CONDQZof.js +0 -1
- package/dist/client/assets/index-C-UYaDk6.css +0 -1
- package/dist/client/assets/runDetached-DqQ3k2ji.js +0 -1
- package/dist/client/assets/useAppGlobalState-DKOGrO5l.js +0 -1
- package/dist/client/assets/useKannaState-D7R_-dM6.js +0 -5
- package/dist/client/assets/useTheme-B57LIKyx.js +0 -1
- package/src/server/agent.pty-rotation.test.ts +0 -322
- package/src/server/claude-pty/auth.test.ts +0 -38
- package/src/server/claude-pty/auth.ts +0 -17
- package/src/server/claude-pty/claude-session-registry.adapter.ts +0 -68
- package/src/server/claude-pty/claude-session-registry.test.ts +0 -149
- package/src/server/claude-pty/driver.test.ts +0 -1153
- package/src/server/claude-pty/driver.ts +0 -829
- package/src/server/claude-pty/env.test.ts +0 -79
- package/src/server/claude-pty/env.ts +0 -20
- package/src/server/claude-pty/jsonl-to-event.test.ts +0 -882
- package/src/server/claude-pty/jsonl-to-event.ts +0 -357
- package/src/server/claude-pty/parity-matrix.test.ts +0 -437
- package/src/server/claude-pty/pid-registry.adapter.ts +0 -164
- package/src/server/claude-pty/pid-registry.test.ts +0 -178
- package/src/server/claude-pty/preflight/binary-fingerprint.adapter.ts +0 -20
- package/src/server/claude-pty/preflight/binary-fingerprint.test.ts +0 -32
- package/src/server/claude-pty/pty-instance-registry.test.ts +0 -208
- package/src/server/claude-pty/pty-instance-registry.ts +0 -172
- package/src/server/claude-pty/pty-memory-sampler.adapter.test.ts +0 -103
- package/src/server/claude-pty/pty-memory-sampler.adapter.ts +0 -86
- package/src/server/claude-pty/pty-process.adapter.ts +0 -60
- package/src/server/claude-pty/pty-process.test.ts +0 -49
- package/src/server/claude-pty/resolve-binary.adapter.ts +0 -106
- package/src/server/claude-pty/resolve-binary.test.ts +0 -118
- package/src/server/claude-pty/runtime-dir.adapter.ts +0 -19
- package/src/server/claude-pty/sandbox/detect.adapter.ts +0 -17
- package/src/server/claude-pty/sandbox/detect.test.ts +0 -17
- package/src/server/claude-pty/sandbox/platform.test.ts +0 -35
- package/src/server/claude-pty/sandbox/platform.ts +0 -27
- package/src/server/claude-pty/sandbox/preflight-io.adapter.ts +0 -14
- package/src/server/claude-pty/sandbox/preflight.test.ts +0 -69
- package/src/server/claude-pty/sandbox/preflight.ts +0 -44
- package/src/server/claude-pty/sandbox/profile-linux.adapter.ts +0 -63
- package/src/server/claude-pty/sandbox/profile-linux.test.ts +0 -90
- package/src/server/claude-pty/sandbox/profile-macos.adapter.ts +0 -72
- package/src/server/claude-pty/sandbox/profile-macos.test.ts +0 -68
- package/src/server/claude-pty/sandbox/wrap.adapter.ts +0 -58
- package/src/server/claude-pty/sandbox/wrap.test.ts +0 -82
- package/src/server/claude-pty/settings-writer.adapter.ts +0 -23
- package/src/server/claude-pty/settings-writer.test.ts +0 -22
- package/src/server/claude-pty/smoke-test-io.adapter.ts +0 -28
- package/src/server/claude-pty/smoke-test.test.ts +0 -199
- package/src/server/claude-pty/smoke-test.ts +0 -182
- package/src/server/claude-pty/tui-control.test.ts +0 -300
- package/src/server/claude-pty/tui-control.ts +0 -174
- package/src/server/claude-pty/tui-source.adapter.test.ts +0 -374
- package/src/server/claude-pty/tui-source.adapter.ts +0 -294
- package/src/server/http-server.adapter.test.ts +0 -18
- package/src/server/http-server.adapter.ts +0 -39
- package/src/server/kanna-mcp-http.test.ts +0 -274
- package/src/server/kanna-mcp-http.ts +0 -194
- package/src/server/kanna-mcp-tools/ask-user-question.test.ts +0 -108
- package/src/server/kanna-mcp-tools/ask-user-question.ts +0 -55
- package/src/server/kanna-mcp-tools/exit-plan-mode.test.ts +0 -61
- package/src/server/kanna-mcp-tools/exit-plan-mode.ts +0 -49
- package/src/server/mcp-zod-compat.adapter.ts +0 -20
- package/src/shared/pty-instance.ts +0 -43
- /package/src/server/{claude-pty/output-ring.test.ts → output-ring.test.ts} +0 -0
- /package/src/server/{claude-pty/output-ring.ts → output-ring.ts} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/VChartSurface-
|
|
2
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./react-DiVRNtpo.js";import{t as n}from"./preload-helper-DjzSQ1t3.js";import{t as r}from"./jsx-runtime-BdxMnOeJ.js";import{t as i}from"./useQuery-Cqr8_M0q.js";import{d as a,t as o}from"./log-aTaDVF_e.js";import{a as s,c,f as l,n as u,r as d,s as f,t as p}from"./pendingActionsStore-COTh4Ztq.js";import{_ as m,a as h,b as g,c as _,d as v,f as y,g as b,h as x,l as S,m as C,n as w,o as T,p as E,r as D,s as O,t as ee,u as k,v as A,y as j}from"./flow-kinds-CW2TU_83.js";import{G as M,R as te,U as ne,W as re,a as ie,l as ae,t as oe,z as se}from"./FilePreviewSheet-XEuUtDPn.js";import{r as ce}from"./dist-CimtOoGK.js";import{r as le}from"./terminal-Bnj7qFGw.js";import{t as ue}from"./chevron-left-CJ0qv9kF.js";import{a as de,i as fe,n as pe,o as me,t as he}from"./select-dLHiAls6.js";import{r as N}from"./host-DCaA9W-Z.js";import{t as ge}from"./triangle-alert-CWrc0CIO.js";import{g as _e}from"./timer.adapter-DHt2zwsL.js";import{t as ve}from"./segmented-control-DNOwRupT.js";import{c as ye,l as be}from"./useTheme-B57LIKyx.js";import{A as P,B as F,D as xe,E as Se,F as Ce,H as I,I as we,L as Te,Lr as Ee,M as De,N as Oe,O as L,P as ke,R as Ae,T as je,U as Me,V as Ne,_ as Pe,a as Fe,b as Ie,c as Le,d as Re,f as ze,g as Be,h as Ve,i as He,j as R,k as z,l as Ue,m as We,n as Ge,o as Ke,p as qe,r as Je,s as Ye,t as Xe,u as Ze,v as Qe,w as $e,wr as et,x as tt,y as B}from"./genui-EzBIAYFE.js";import{t as nt}from"./runDetached-DqQ3k2ji.js";import{t as rt}from"./formatDuration-BbWTR_M_.js";import{n as it,t as at}from"./chart-renderer-DjYZvNxh.js";var ot={name:`file-minus-corner`,size:24,node:[[`path`,{d:`M20 14V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12`,key:`l9p8hp`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M14 18h6`,key:`1m8k6r`}]],aliases:[`file-minus-2`]};ot.node;var st=l(ot),ct={name:`message-square-text`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]};ct.node;var lt=l(ct),V=e(t(),1);Je(e=>({spec:e.object({root:e.string(),elements:e.record(e.object({type:e.ref(`catalog.components`),props:e.propsOf(`catalog.components`),children:e.array(e.string()),slots:{...e.record(e.array(e.string())),...e.optional()},visible:{...e.any(),...e.optional()},repeat:{...e.any(),...e.optional()}}))}),catalog:e.object({components:e.map({props:e.zod(),slots:e.array(e.string()),description:e.string(),example:e.any()}),actions:e.map({params:e.zod(),description:e.string()})})}),{builtInActions:[{name:`setState`,description:`Update a value in the state model at the given statePath. Params: { statePath: string, value: any }`},{name:`pushState`,description:`Append an item to an array in state. Params: { statePath: string, value: any, clearStatePath?: string }. Value can contain {"$state":"/path"} refs and "$id" for auto IDs.`},{name:`removeState`,description:`Remove an item from an array in state by index. Params: { statePath: string, index: number }`},{name:`validateForm`,description:`Validate all registered form fields and write the result to state. Params: { statePath?: string }. Defaults to /formValidation. Result: { valid: boolean, errors: Record<string, string[]> }.`}],defaultRules:[`CRITICAL INTEGRITY CHECK: Before outputting ANY element that references children, you MUST have already output (or will output) each child as its own element. If an element has children: ['a', 'b'], then elements 'a' and 'b' MUST exist. A missing child element causes that entire branch of the UI to be invisible.`,`SELF-CHECK: After generating all elements, mentally walk the tree from root. Every key in every children array must resolve to a defined element. If you find a gap, output the missing element immediately.`,`REQUIRED FIELDS: Every element MUST include a "children" array. Leaf elements (text, badges, inputs, images) use an empty array: "children": []. Omitting "children" fails validation.`,`NAMED SLOTS: Use "children" for the default slot. For other slots declared by the component, use a top-level "slots" object that maps each slot name to child element keys, for example {"slots":{"header":["heading"],"footer":["actions"]}}. Never use "slots.default". Every referenced key must exist.`,`FILTERED LISTS: To render only the items matching a field value (kanban columns, tabbed lists, status sections), put "repeat" and a "visible" condition with $item on the same container element: {"repeat": {"statePath": "/tasks", "key": "id"}, "visible": {"$item": "status", "eq": "todo"}} renders one child per matching item. A visible condition object must use exactly one of $state, $item, or $index — never combine them in one object.`,`CRITICAL: The "visible" field goes on the ELEMENT object, NOT inside "props". Correct: {"type":"<ComponentName>","props":{},"visible":{"$state":"/tab","eq":"home"},"children":[...]}.`,`CRITICAL: The "on" field goes on the ELEMENT object, NOT inside "props". Use on.press, on.change, on.submit etc. NEVER put action/actionParams inside props.`,`When the user asks for a UI that displays data (e.g. blog posts, products, users), ALWAYS include a state field with realistic sample data. The state field is a top-level field on the spec (sibling of root/elements).`,`When building repeating content backed by a state array (e.g. posts, products, items), use the "repeat" field on a container element. Example: { "type": "<ContainerComponent>", "props": {}, "repeat": { "statePath": "/posts", "key": "id" }, "children": ["post-card"] }. For a nested list stored on the enclosing item, use "repeat": { "statePath": { "$item": "comments" }, "key": "id" }. The $item statePath form is valid only inside another repeat. Replace <ContainerComponent> with an appropriate component from the AVAILABLE COMPONENTS list. Inside repeated children, use { "$item": "field" } to read a field from the current item, and { "$index": true } for the current array index. For two-way binding to an item field use { "$bindItem": "completed" }. Do NOT hardcode individual elements for each array item.`,`Design with visual hierarchy: use container components to group content, heading components for section titles, proper spacing, and status indicators. ONLY use components from the AVAILABLE COMPONENTS list.`,`For data-rich UIs, use multi-column layout components if available. For forms and single-column content, use vertical layout components. ONLY use components from the AVAILABLE COMPONENTS list.`,`Always include realistic, professional-looking sample data. For blogs include 3-4 posts with varied titles, authors, dates, categories. For products include names, prices, images. Never leave data empty.`]});var H=e(r(),1),ut=(0,V.createContext)(null);function dt(e,t){return e?null:Object.keys(t).length===0?{}:Qe(t)}function ft({store:e,initialState:t={},onStateChange:n,children:r}){let i=(0,V.useRef)(void 0);!e&&!i.current&&(i.current=Pe(t));let a=e??i.current,o=(0,V.useRef)(a);o.current=a;let s=(0,V.useRef)(!!e);s.current=!!e,(0,V.useRef)(e?`controlled`:`uncontrolled`),(0,V.useRef)(!1);let c=(0,V.useRef)(t),l=(0,V.useRef)(dt(!!e,t));(0,V.useEffect)(()=>{if(e||t===c.current)return;c.current=t;let n=t&&Object.keys(t).length>0?Qe(t):{},r=l.current??{},i=new Set([...Object.keys(r),...Object.keys(n)]),o={};for(let e of i)r[e]!==n[e]&&(o[e]=e in n?n[e]:void 0);l.current=n,Object.keys(o).length>0&&a.update(o)},[e,t,a]);let u=(0,V.useSyncExternalStore)(a.subscribe,a.getSnapshot,a.getServerSnapshot??a.getSnapshot),d=(0,V.useRef)(n);d.current=n;let f=(0,V.useCallback)((e,t)=>{let n=o.current,r=n.getSnapshot();n.set(e,t),!s.current&&n.getSnapshot()!==r&&d.current?.([{path:e,value:t}])},[]),p=(0,V.useCallback)(e=>{let t=o.current,n=t.getSnapshot();if(t.update(e),!s.current&&t.getSnapshot()!==n){let t=[];for(let[r,i]of Object.entries(e))B(n,r)!==i&&t.push({path:r,value:i});t.length>0&&d.current?.(t)}},[]),m=(0,V.useCallback)(e=>o.current.get(e),[]),h=(0,V.useCallback)(()=>o.current.getSnapshot(),[]),g=(0,V.useMemo)(()=>({state:u,get:m,set:f,update:p,getSnapshot:h}),[u,m,f,p,h]);return(0,H.jsx)(ut.Provider,{value:g,children:r})}function U(){let e=(0,V.useContext)(ut);if(!e)throw Error(`useStateStore must be used within a StateProvider`);return e}function pt(e){let{state:t}=U();return B(t,e)}var mt=(0,V.createContext)(null);function ht({children:e}){let{state:t}=U(),n=(0,V.useMemo)(()=>({stateModel:t}),[t]),r=(0,V.useMemo)(()=>e=>He(e,n),[n]),i=(0,V.useMemo)(()=>({isVisible:r,ctx:n}),[r,n]);return(0,H.jsx)(mt.Provider,{value:i,children:e})}function gt(){let e=(0,V.useContext)(mt);if(!e)throw Error(`useVisibility must be used within a VisibilityProvider`);return e}var _t=(0,V.createContext)(null),vt={};function yt(e,t){if(e===t)return!0;if(!e||!t)return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(n!==i){if(typeof n==`object`&&n&&typeof i==`object`&&i){let e=n.$state,t=i.$state;if(typeof e==`string`&&e===t)continue}return!1}}return!0}function bt(e,t){if(e===t)return!0;if(e.validateOn!==t.validateOn)return!1;let n=e.checks??[],r=t.checks??[];if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++){let t=n[e],i=r[e];if(t.type!==i.type||t.message!==i.message||!yt(t.args,i.args))return!1}return!0}function xt({customFunctions:e=vt,children:t}){let{state:n,getSnapshot:r}=U(),[i,a]=(0,V.useState)({}),o=(0,V.useRef)({}),[s,c]=(0,V.useState)({}),l=(0,V.useCallback)((e,t)=>{c(n=>{let r=n[e];return r&&bt(r,t)?n:{...n,[e]:t}})},[]),u=(0,V.useCallback)((t,n)=>{let i=r(),s=t.split(`/`).filter(Boolean),c=i;for(let e of s)if(typeof c==`object`&&c)c=c[e];else{c=void 0;break}let l=We(n,{value:c,stateModel:i,customFunctions:e}),u={touched:o.current[t]?.touched??!0,validated:!0,result:l};return o.current={...o.current,[t]:u},a(o.current),l},[e,r]),d=(0,V.useCallback)(e=>{o.current={...o.current,[e]:{...o.current[e],touched:!0,validated:o.current[e]?.validated??!1,result:o.current[e]?.result??null}},a(o.current)},[]),f=(0,V.useCallback)(e=>{let{[e]:t,...n}=o.current;o.current=n,a(n)},[]),p=(0,V.useCallback)(()=>{let e=!0;for(let[t,n]of Object.entries(s))u(t,n).valid||(e=!1);return e},[s,u]),m=(0,V.useMemo)(()=>({customFunctions:e,get fieldStates(){return o.current},validate:u,touch:d,clear:f,validateAll:p,registerField:l}),[e,i,u,d,f,p,l]);return(0,H.jsx)(_t.Provider,{value:m,children:t})}function St(){return(0,V.useContext)(_t)}var Ct=0;function wt(){return Ct+=1,`${Date.now()}-${Ct}`}function Tt(e,t){if(e==null)return e;if(e===`$id`)return wt();if(typeof e==`object`&&!Array.isArray(e)){let n=e,r=Object.keys(n);if(r.length===1&&typeof n.$state==`string`)return t(n.$state);if(r.length===1&&`$id`in n)return wt()}if(Array.isArray(e))return e.map(e=>Tt(e,t));if(typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=Tt(i,t);return n}return e}var Et=(0,V.createContext)(null);function Dt({handlers:e={},navigate:t,children:n}){let{get:r,set:i,getSnapshot:a}=U(),o=St(),[s,c]=(0,V.useState)(e),[l,u]=(0,V.useState)(new Set),[d,f]=(0,V.useState)(null),p=(0,V.useCallback)((e,t)=>{c(n=>({...n,[e]:t}))},[]),m=(0,V.useCallback)(async e=>{let n=Ze(e,a()),c=Ye(),l=Date.now();Le({id:c,name:n.action,params:n.params,at:l});let d=!0,p;try{if(n.action===`setState`&&n.params){let e=n.params.statePath,t=n.params.value;e&&i(e,t);return}if(n.action===`pushState`&&n.params){let e=n.params.statePath,t=n.params.value;if(e){let a=Tt(t,r),o=r(e)??[];i(e,[...o,a]);let s=n.params.clearStatePath;s&&i(s,``)}return}if(n.action===`removeState`&&n.params){let e=n.params.statePath,t=n.params.index;if(e!==void 0&&t!==void 0){let n=r(e)??[];i(e,n.filter((e,n)=>n!==t))}return}if(n.action===`push`&&n.params){let e=n.params.screen;if(e){let t=r(`/currentScreen`),n=r(`/navStack`)??[];t?i(`/navStack`,[...n,t]):i(`/navStack`,[...n,``]),i(`/currentScreen`,e)}return}if(n.action===`pop`){let e=r(`/navStack`)??[];if(e.length>0){let t=e[e.length-1];i(`/navStack`,e.slice(0,-1)),t?i(`/currentScreen`,t):i(`/currentScreen`,void 0)}return}if(n.action===`validateForm`){let e=o?.validateAll;if(!e){console.warn(`validateForm action was dispatched but no ValidationProvider is connected. Ensure ValidationProvider is rendered inside the provider tree.`);return}let t=e(),r={};for(let[e,t]of Object.entries(o.fieldStates))t.result&&!t.result.valid&&(r[e]=t.result.errors);let a=n.params?.statePath||`/formValidation`;i(a,{valid:t,errors:r});return}let e=s[n.action];if(!e){console.warn(`No handler registered for action: ${n.action}`);return}if(n.confirm)return new Promise((t,r)=>{f({action:n,handler:e,resolve:()=>{f(null),t()},reject:()=>{f(null),r(Error(`Action cancelled`))}})}).then(async()=>{u(e=>new Set(e).add(n.action));try{await Fe({action:n,handler:e,setState:i,navigate:t,executeAction:async e=>{await m(e)}})}finally{u(e=>{let t=new Set(e);return t.delete(n.action),t})}});u(e=>new Set(e).add(n.action));try{await Fe({action:n,handler:e,setState:i,navigate:t,executeAction:async e=>{await m(e)}})}finally{u(e=>{let t=new Set(e);return t.delete(n.action),t})}}catch(e){throw d=!1,p=e,e}finally{let e=Date.now();Ue({id:c,name:n.action,ok:d,at:e,durationMs:e-l,error:p})}},[s,r,i,a,t,o]),h=(0,V.useCallback)(()=>{d?.resolve()},[d]),g=(0,V.useCallback)(()=>{d?.reject()},[d]),_=(0,V.useMemo)(()=>({handlers:s,loadingActions:l,pendingConfirmation:d,execute:m,confirm:h,cancel:g,registerHandler:p}),[s,l,d,m,h,g,p]);return(0,H.jsx)(Et.Provider,{value:_,children:n})}function W(){let e=(0,V.useContext)(Et);if(!e)throw Error(`useActions must be used within an ActionProvider`);return e}function Ot({confirm:e,onConfirm:t,onCancel:n}){let r=e.variant===`danger`;return(0,H.jsx)(`div`,{style:{position:`fixed`,inset:0,backgroundColor:`rgba(0, 0, 0, 0.5)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:50},onClick:n,children:(0,H.jsxs)(`div`,{style:{backgroundColor:`white`,borderRadius:`8px`,padding:`24px`,maxWidth:`400px`,width:`100%`,boxShadow:`0 20px 25px -5px rgba(0, 0, 0, 0.1)`},onClick:e=>e.stopPropagation(),children:[(0,H.jsx)(`h3`,{style:{margin:`0 0 8px 0`,fontSize:`18px`,fontWeight:600},children:e.title}),(0,H.jsx)(`p`,{style:{margin:`0 0 24px 0`,color:`#6b7280`},children:e.message}),(0,H.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,justifyContent:`flex-end`},children:[(0,H.jsx)(`button`,{onClick:n,style:{padding:`8px 16px`,borderRadius:`6px`,border:`1px solid #d1d5db`,backgroundColor:`white`,cursor:`pointer`},children:e.cancelLabel??`Cancel`}),(0,H.jsx)(`button`,{onClick:t,style:{padding:`8px 16px`,borderRadius:`6px`,border:`none`,backgroundColor:r?`#dc2626`:`#3b82f6`,color:`white`,cursor:`pointer`},children:e.confirmLabel??`Confirm`})]})]})})}var kt=(0,V.createContext)(null);function At({item:e,index:t,basePath:n,children:r}){return(0,H.jsx)(kt.Provider,{value:{item:e,index:t,basePath:n},children:r})}function jt(){return(0,V.useContext)(kt)}var Mt=new WeakMap,Nt={},Pt=class extends V.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){console.error(`[json-render] Rendering error in <${this.props.elementType}>:`,e,t.componentStack)}componentDidUpdate(e){this.state.hasError&&e.resetKey!==this.props.resetKey&&this.setState({hasError:!1})}render(){return this.state.hasError?null:this.props.children}},Ft={},It=V.createContext(Ft);function Lt(){return V.useContext(It)}var Rt=V.createContext(void 0);function zt(){return V.useContext(Rt)}function Bt(e,t){let n=t.current;if(n===e)return n;if(n&&e){let t=Object.keys(e);if(t.length===Object.keys(n).length&&t.every(t=>Object.prototype.hasOwnProperty.call(n,t)&&n[t]===e[t]))return n}return t.current=e,e}function Vt(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Ht(e,t){if(Object.is(e,t))return!0;let n=Array.isArray(e);if(n!==Array.isArray(t)||!n&&(e===null||t===null||typeof e!=`object`||typeof t!=`object`))return!1;let r=e,i=t,a=Object.keys(i);return n&&e.length!==t.length||a.length!==Object.keys(r).length?!1:a.every(e=>Object.prototype.hasOwnProperty.call(r,e)&&Ht(r[e],i[e]))}function Ut(e){if(typeof e!=`object`||!e)return e;let t=Array.isArray(e)?Array(e.length):{};for(let n of Object.keys(e))t[n]=Ut(e[n]);return t}function Wt(e,t){if(Object.is(e,t))return e;let n=Array.isArray(e);if(n!==Array.isArray(t)||!n&&(!Vt(e)||!Vt(t)))return t;let r=e,i=t,a=Object.keys(i),o=n?Array(t.length):{},s=(!n||e.length===t.length)&&a.length===Object.keys(r).length;for(let e of a){let t=i[e];Object.prototype.hasOwnProperty.call(r,e)?(t=Wt(r[e],t),Object.is(r[e],t)||(s=!1)):s=!1,o[e]=t}return s?e:o}function Gt(e){let t=(0,V.useRef)({}),n=(0,V.useRef)(0);if(!e)return{};let r=t.current,i={},a={},o=new Set;for(let t of Object.keys(e.elements)){if(a[t]!==void 0)continue;let s=e.elements[t];if(!s)continue;o.add(t);let c=[{key:t,element:s,children:[...s.children??[],...Object.values(s.slots??{}).flat()],childIndex:0,childVersions:[]}];for(;c.length>0;){let t=c[c.length-1],s=t.children[t.childIndex];if(s!==void 0){let n=a[s];if(n!==void 0){t.childVersions.push([s,n]),t.childIndex+=1;continue}let r=e.elements[s];if(!r||o.has(s)){t.childVersions.push([s,-1]),t.childIndex+=1;continue}o.add(s),c.push({key:s,element:r,children:[...r.children??[],...Object.values(r.slots??{}).flat()],childIndex:0,childVersions:[]});continue}let l=r[t.key],u=l&&Ht(l.own,t.element)&&Ht(l.children,t.childVersions)?l.version:++n.current;o.delete(t.key),i[t.key]={own:Ut(t.element),children:t.childVersions,version:u},a[t.key]=u,c.pop()}}return t.current=i,a}var Kt=V.memo(function({Component:e,element:t,slots:n,emit:r,on:i,bindings:a,loading:o,children:s}){return(0,H.jsx)(e,{element:t,slots:n,emit:r,on:i,bindings:a,loading:o,children:s})},(e,t)=>e.Component===t.Component&&e.signature===t.signature&&e.execute===t.execute&&e.actionContext?.item===t.actionContext?.item&&e.actionContext?.index===t.actionContext?.index&&e.actionContext?.basePath===t.actionContext?.basePath&&e.functions===t.functions&&e.directives===t.directives&&e.element.props===t.element.props&&e.bindings===t.bindings&&e.loading===t.loading);function qt(){return V.useSyncExternalStore(Be,Ke,()=>!1)}function Jt({element:e,elementKey:t,spec:n,registry:r,loading:i,fallback:a,signatures:o}){let s=qt(),c=jt(),{ctx:l}=gt(),{execute:u}=W(),{getSnapshot:d,state:f}=U(),p=Lt(),m=zt(),h=(0,V.useMemo)(()=>{let e=c?{...l,repeatItem:c.item,repeatIndex:c.index,repeatBasePath:c.basePath}:{...l};return e.functions=p,e.directives=m,e},[l,c,p,m]),g=e.repeat!==void 0&&c==null?Ve(e.visible):{container:e.visible,itemFilter:void 0},_=g.itemFilter,v=g.container===void 0||He(g.container,h),y=e.on,b=(0,V.useCallback)(async e=>{let t=y?.[e];if(!t)return;let n=Array.isArray(t)?t:[t];for(let e of n){if(!e.params){await u(e);continue}let t={...h,stateModel:d()},n={};for(let[r,i]of Object.entries(e.params))n[r]=Re(i,t);await u({...e,params:n})}},[y,u,h,d]),x=(0,V.useCallback)(e=>{let t=y?.[e];return t?{emit:()=>b(e),shouldPreventDefault:(Array.isArray(t)?t:[t]).some(e=>e.preventDefault),bound:!0}:{emit:()=>{},shouldPreventDefault:!1,bound:!1}},[y,b]),S=e.watch,C=(0,V.useRef)(null),w=(0,V.useRef)(void 0),T=(0,V.useRef)(void 0),E=(0,V.useRef)({}),D=(0,V.useMemo)(()=>{if(!S)return;let e={};for(let t of Object.keys(S))e[t]=B(f,t);let t=w.current;if(t){let n=Object.keys(e);if(n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n]))return t}return w.current=e,e},[S,f]);if((0,V.useEffect)(()=>{if(!S||!D)return;let e=Object.keys(S);if(e.length===0)return;let t=C.current;if(C.current=D,t===null)return;let n=!1;return(async()=>{for(let r of e){if(n)break;if(D[r]!==t[r]){let e=S[r];if(!e)continue;let t=Array.isArray(e)?e:[e];for(let e of t){if(n)break;if(!e.params){if(await u(e),n)break;continue}let t={...h,stateModel:d()},r={};for(let[n,i]of Object.entries(e.params))r[n]=Re(i,t);if(await u({...e,params:r}),n)break}}}})().catch(console.error),()=>{n=!0}},[S,D,u,h,d]),!v)return null;let O=e.props??Nt,ee=Bt(ze(O,h),T),k=Wt(E.current,qe(O,h));E.current=k;let A=k===e.props?e:{...e,props:k},j=r[A.type]??a;if(!j)return console.warn(`No renderer for component type: ${A.type}`),null;let M=Mt.get(r)?.[A.type];if(A.slots&&M?.slots){let e=new Set(M.slots);for(let t of Object.keys(A.slots))t==="default"?console.warn(`[json-render] Component "${A.type}" uses slots.default. Use "children" for default slot content.`):e.has(t)||console.warn(`[json-render] Unknown slot "${t}" on component "${A.type}". Available slots: ${M.slots.join(`, `)}`)}let te=(e,t)=>e.map(e=>{let s=n.elements[e];if(!s){if(!i){let n=t?`in slot "${t}" of "${A.type}"`:`as child of "${A.type}"`;console.warn(`[json-render] Missing element "${e}" referenced ${n}. This element will not render.`)}return null}return(0,H.jsx)(Yt,{element:s,elementKey:e,spec:n,registry:r,loading:i,fallback:a,signatures:o},e)}),ne=A.repeat?(0,H.jsx)(Xt,{element:A,spec:n,registry:r,loading:i,fallback:a,itemFilter:_,signatures:o}):A.children?te(A.children):void 0,re=A.slots?Object.fromEntries(Object.entries(A.slots).map(([e,t])=>[e,te(t,e)])):void 0,ie=(0,H.jsx)(Kt,{Component:j,signature:o[t??``],execute:u,actionContext:c,functions:p,directives:m,element:A,slots:re,emit:b,on:x,bindings:ee,loading:i,children:ne}),ae=s&&t?(0,H.jsx)(`span`,{"data-jr-key":t,style:{display:`contents`},children:ie}):ie;return(0,H.jsx)(Pt,{elementType:A.type,resetKey:o[t??``],children:ae})}var Yt=V.memo(function(e){return(0,H.jsx)(Jt,{...e})},(e,t)=>e.elementKey===t.elementKey&&e.signatures[e.elementKey??``]===t.signatures[t.elementKey??``]&&e.registry===t.registry&&e.loading===t.loading&&e.fallback===t.fallback);function Xt({element:e,spec:t,registry:n,loading:r,fallback:i,signatures:a,itemFilter:o}){let{state:s}=U(),{ctx:c}=gt(),l=jt(),u=e.repeat,d=tt(u.statePath,l?.basePath);if(d===void 0)return console.warn(`[json-render] $item in repeat.statePath used outside of a repeat scope`),null;let f=(B(s,d)??[]).map((e,t)=>({itemValue:e,index:t})).filter(({itemValue:e,index:t})=>o===void 0||He(o,{...c,repeatItem:e,repeatIndex:t}));return(0,H.jsx)(H.Fragment,{children:f.map(({itemValue:o,index:s})=>{let c=u.key&&typeof o==`object`&&o?String(o[u.key]??s):String(s);return(0,H.jsx)(At,{item:o,index:s,basePath:Ie(d,s),children:e.children?.map(o=>{let s=t.elements[o];return s?(0,H.jsx)(Yt,{element:s,elementKey:o,spec:t,registry:n,loading:r,fallback:i,signatures:a},o):(r||console.warn(`[json-render] Missing element "${o}" referenced as child of "${e.type}" (repeat). This element will not render.`),null)})},c)})})}function Zt({spec:e,registry:t,loading:n,fallback:r}){let i=Gt(e);if(!e||!e.root)return null;let a=e.elements[e.root];return a?(0,H.jsx)(Yt,{element:a,elementKey:e.root,spec:e,registry:t,loading:n,fallback:r,signatures:i}):null}function Qt({registry:e,store:t,initialState:n,handlers:r,navigate:i,validationFunctions:a,functions:o,directives:s,onStateChange:c,children:l}){let u=(0,V.useMemo)(()=>s?Ge(s):void 0,[s]);return(0,H.jsx)(ft,{store:t,initialState:n,onStateChange:c,children:(0,H.jsx)(ht,{children:(0,H.jsx)(xt,{customFunctions:a,children:(0,H.jsx)(Dt,{handlers:r,navigate:i,children:(0,H.jsx)(It.Provider,{value:o??Ft,children:(0,H.jsxs)(Rt.Provider,{value:u,children:[l,(0,H.jsx)($t,{})]})})})})})})}function $t(){let{pendingConfirmation:e,confirm:t,cancel:n}=W();return e?.action.confirm?(0,H.jsx)(Ot,{confirm:e.action.confirm,onConfirm:t,onCancel:n}):null}function en(e,t){let{set:n}=U();return[e,(0,V.useCallback)(e=>{t&&n(t,e)},[t,n])]}var tn=`/_drill`;function nn(e){return`${tn}/${e}`}var rn=et({dimension:Ee(),value:Ee(),into:Ee(),metric:Ee(),period:ke.optional()});function an(e,t){if(!e)return null;let n=e.endsWith(`/`)?e.slice(0,-1):e;if(t.startsWith(`/`))return t===n||t.startsWith(`${n}/`)?t:null;let r=t.replaceAll(`\\`,`/`).split(`/`).filter(e=>e!==``&&e!==`.`);return r.some(e=>e===`..`)?null:`${n}/${r.join(`/`)}`}function G(e,t){e.view.getState().showNotice(t)}function on(e,t){if(!e.host().sendToAgent){G(e,`Asking the agent is not available in this view`);return}e.view.getState().proposeAgentMessage({headline:t.headline,message:Se(t)})}async function sn(e,t,n){if(t.source===`inline`){let e=Ce(t,t.rows,n);return e.ok?e.result:null}if(!e.queryDataset)return null;let r=await e.queryDataset(t,n,!1);return r.status===`ok`?r.result:null}async function cn(e,t,n){let r=e.host(),i={title:e.spec.title};switch(t){case`setState`:case`pushState`:case`removeState`:return;case`file.open`:{let t=P[`file.open`].params.safeParse(n);if(!t.success)return G(e,`That file link is malformed`);let i=an(r.workspaceRoot,t.data.path);if(!i)return G(e,`"${t.data.path}" is outside this chat's workspace`);e.view.getState().openPreview(i);return}case`link.open`:{let t=P[`link.open`].params.safeParse(n);if(!t.success)return G(e,`Only https links can be opened`);r.openLink(t.data.url);return}case`dataset.refresh`:{let t=P[`dataset.refresh`].params.safeParse(n);t.success&&e.view.getState().refreshDataset(t.data.dataset);return}case`financial.drilldown`:{let t=P[`financial.drilldown`].params.safeParse(n);if(!t.success)return G(e,`That drilldown is malformed`);let{dataset:r,...i}=t.data;e.state.set(nn(r),i);return}case`agent.ask`:{let t=P[`agent.ask`].params.safeParse(n);return t.success?on(e,je(`agent.ask`,t.data.prompt,t.data.context,i)):G(e,`That question is malformed`)}case`agent.investigate`:case`agent.fix`:{let r=P[t].params.safeParse(n);return r.success?on(e,je(t,r.data.subject,r.data.context,i)):G(e,`That request is malformed`)}case`financial.explainVariance`:{let t=P[`financial.explainVariance`].params.safeParse(n);if(!t.success)return G(e,`That explanation request is malformed`);let a=e.spec.datasets?.[t.data.dataset];if(!a)return G(e,`Unknown dataset "${t.data.dataset}"`);let o=t.data.compareWith??`previous-period`,s=await sn(r,a,{metrics:[t.data.metric],...t.data.period?{period:t.data.period}:{},...t.data.filters?{filters:t.data.filters}:{},compare:o});return on(e,$e({datasetId:t.data.dataset,decl:a,metric:t.data.metric,...t.data.period?{period:t.data.period}:{},compareWith:o,...t.data.filters?{filters:t.data.filters}:{},...t.data.question?{question:t.data.question}:{},result:s},i))}}}function ln(e){let t={};for(let n of Object.keys(P))De(n)&&P[n].class!==`local`&&(t[n]=async t=>{if(e.host().readonly)return;let r=Me.safeParse(t);if(!r.success)return G(e,`That action's parameters are not plain data`);await cn(e,n,r.data)});return t}var un=`_kannaKey`,dn=`/_ui`;function fn(e){let t=e.props[un];return typeof t==`string`?t:e.type}function K(e,t,n,r){let i=`${dn}/${fn(e)}/${t}`,a=pt(i),{set:o}=U(),s=(0,V.useCallback)(e=>o(i,e),[i,o]);return[r(a)?a:n,s]}function pn(e){return typeof e==`string`}function mn(e){return typeof e==`boolean`}function hn(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function gn(e){if(!be(e))return!1;let t=e.value;return t===`all`||t===``||t==null?!1:ye(t)?t.length>0:typeof t==`string`||typeof t==`number`}function q(e){let t=Me.safeParse(_n(e));if(!t.success)return null;let n=t.data.filters;return ye(n)?{...t.data,filters:n.filter(gn)}:t.data}function _n(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`_kannaKey`&&t!=null))}function J(e){return e===`none`?void 0:e}function Y(e,t){return t?[...e??[],{dimension:t.dimension,value:t.value}]:e?[...e]:void 0}var vn=(0,V.lazy)(()=>n(()=>import(`./VChartSurface-CKuPelsn.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))),yn={sm:200,md:260,lg:340};function bn(e){return e===`chart`||e===`table`}var xn=60;function Sn(e){let t=q(e);if(!t)return null;let n=R.FinancialChart.props.safeParse(t);return n.success?n.data:null}function Cn(e){let t=pt(nn(e??``));return(0,V.useMemo)(()=>{if(!e||!t)return null;let n=rn.safeParse(t);return n.success?n.data:null},[e,t])}function wn(e,t){let n=Array.isArray(e.metric)?e.metric:[e.metric],r=t?t.into:e.dimension,i=t?.period??e.period,a=e.chart===`waterfall`||e.chart===`composition`||t?void 0:J(e.compareWith),o=Y(e.filters,t);return{metrics:e.secondaryMetric?[...n,e.secondaryMetric]:n,groupBy:e.series&&!t?[r,e.series]:[r],...i?{period:i}:{},...a?{compare:a}:{},...o&&o.length>0?{filters:o}:{},...e.chart===`waterfall`?{sort:{by:r,direction:`asc`}}:{},limit:e.limit??xn}}function Tn(e,t){return t?e.chart===`composition`?`composition`:`bar`:e.chart}function En({x:e,label:t,drill:n}){return n?(0,H.jsx)(`button`,{type:`button`,className:`rounded-sm text-left text-foreground underline decoration-border underline-offset-4 hover:decoration-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"aria-label":`Break down ${t} by ${n.intoLabel}`,disabled:n.pending,onClick:()=>n.onDrill({x:e,series:``}),children:t}):(0,H.jsx)(H.Fragment,{children:t})}function Dn({model:e,drill:t}){let n=e.series.filter(t=>e.points.some(e=>e.series===t.id)),r=(t,n)=>e.points.find(e=>e.x===t&&e.series===n)?.value??null;return(0,H.jsx)(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border`,children:(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-left text-xs font-medium text-muted-foreground`,children:e.dimensionLabel}),n.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-right text-xs font-medium text-muted-foreground`,children:e.label},e.id))]})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:e.xOrder.map(i=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-normal text-foreground`,children:(0,H.jsx)(En,{x:i,label:e.xLabels[i]??i,drill:On(e,i)?t:null})}),n.map(t=>(0,H.jsx)(`td`,{className:`px-3 py-1.5 text-right tabular-nums text-foreground`,children:L(r(i,t.id),e.format)},t.id))]},i))})]})})}function On(e,t){return at(e,{x:t})!==null}function kn({model:e,height:t,onPointClick:n}){let r=N().ChartRenderer??vn,i=`${e.valueLabel} by ${e.dimensionLabel.toLowerCase()}, ${e.points.length} values. Switch to Table to read them${n?` or break a value down`:``}.`;return(0,H.jsx)(V.Suspense,{fallback:(0,H.jsx)(`div`,{className:`w-full`,style:{height:t},"aria-hidden":`true`}),children:(0,H.jsx)(r,{model:e,height:t,label:i,onPointClick:n})})}function An({props:e,drill:t}){let{execute:n}=W(),{viewKey:r}=b(),i=N(),a=p(`genui.financial.explainVariance`,r,e.dataset),o=d(a),c=Array.isArray(e.metric)?e.metric[0]??``:e.metric,l=(0,V.useCallback)(()=>{let r=Y(e.filters,t),i=t?.period??e.period;u(a,()=>n({action:`financial.explainVariance`,params:{dataset:e.dataset,metric:c,compareWith:J(e.compareWith)??`previous-period`,...i?{period:i}:{},...r&&r.length>0?{filters:r.map(e=>({...e}))}:{}}}))},[t,n,a,c,e]);return i.readonly||!i.sendToAgent?null:(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,className:`gap-1.5`,pending:o,onClick:l,children:[o?null:(0,H.jsx)(lt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Explain variance`]})}function jn(e,t,n,r){return e===`back`&&t?n:e===`figure`&&!t?r:null}function Mn({datasetId:e,drill:t,decl:n,backRef:r,focusAfterRef:i}){let{execute:a}=W(),{viewKey:o}=b(),c=p(`genui.drill.back`,o,e),l=d(c),f=(0,V.useCallback)(()=>{i.current=`figure`,u(c,()=>a({action:`setState`,params:{statePath:nn(e),value:null}}))},[e,a,i,c]);return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,H.jsxs)(s,{ref:r,size:`sm`,variant:`ghost`,className:`gap-1`,onClick:f,pending:l,children:[l?null:(0,H.jsx)(ue,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Back`]}),(0,H.jsxs)(`span`,{children:[F(t.dimension,n.dimensions?.[t.dimension]),`: `,(0,H.jsx)(`span`,{className:`text-foreground`,children:Nn(t,n)}),` `,`by `,F(t.into,n.dimensions?.[t.into]).toLowerCase()]})]})}function Nn(e,t){let n=t.dimensions?.[e.dimension];return n?.kind===`time`?we(e.value,n.grain??`month`):e.value}function Pn(e,t,n,r){let i=t?t.period.label:Ae(e.period);if(n)return r?.dimensions?.[n.dimension]?.kind===`time`?Nn(n,r):i;let a=J(e.compareWith),o=t?.comparison?.label??(a?Te(a):null);return o?`${i} · vs ${o.charAt(0).toLowerCase()}${o.slice(1)}`:i}function Fn({element:e}){let t=(0,V.useMemo)(()=>Sn(e.props),[e.props]),n=y(t?.dataset),r=Cn(t?.drilldown?t.dataset:void 0),i=(0,V.useMemo)(()=>t?wn(t,r):null,[t,r]),a=E(t?.dataset,i),[o,s]=K(e,`view`,`chart`,bn),{execute:l}=W(),{viewKey:f}=b(),m=p(`genui.financial.drilldown`,f,t?.dataset??``),g=(0,V.useId)(),_=(0,V.useRef)(null),v=(0,V.useRef)(null),x=(0,V.useRef)(null),S=d(m),C=(0,V.useMemo)(()=>{if(!t||!n||a.status!==`ok`)return null;let e=Array.isArray(t.metric)?t.metric:[t.metric];return it({chart:Tn(t,r),metrics:e,...t.secondaryMetric?{secondaryMetric:t.secondaryMetric}:{},dimension:r?r.into:t.dimension,...t.series&&!r?{series:t.series}:{},...t.totalLabel?{totalLabel:t.totalLabel}:{}},n,a.result)},[n,r,t,a]),w=t?.drilldown,D=(0,V.useCallback)(e=>{if(!t||!w||r)return;let n=Array.isArray(t.metric)?t.metric[0]??``:t.metric;u(m,()=>l({action:`financial.drilldown`,params:{dataset:t.dataset,metric:n,dimension:t.dimension,value:e.x,into:w.dimension,...t.period?{period:t.period}:{}}}))},[r,m,w,l,t]);(0,V.useEffect)(()=>{let e=jn(x.current,r!==null,v.current,_.current);e&&(x.current=null,e.focus())},[r]);let ee=(0,V.useCallback)(e=>{x.current=`back`,D(e)},[D]);if(!t)return(0,H.jsx)(O,{component:`FinancialChart`});let k=yn[t.height??`md`],A=Array.isArray(t.metric)?t.metric[0]??``:t.metric,j=t.title??I(A,n?.metrics[A]),M=Pn(t,a.status===`ok`?a.result:null,r,n),te=t.drilldown&&!r&&n?{intoLabel:F(t.drilldown.dimension,n.dimensions?.[t.drilldown.dimension]).toLowerCase(),pending:S,onDrill:ee}:null;return(0,H.jsxs)(`figure`,{ref:_,tabIndex:-1,className:`flex min-w-0 flex-col gap-2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-labelledby":g,children:[(0,H.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{id:g,className:`text-sm font-medium text-foreground`,children:j}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:M})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t.explain?(0,H.jsx)(An,{props:t,drill:r}):null,(0,H.jsx)(ve,{size:`sm`,value:o,onValueChange:s,options:[{value:`chart`,label:`Chart`},{value:`table`,label:`Table`}]})]})]}),r&&n?(0,H.jsx)(Mn,{datasetId:t.dataset,drill:r,decl:n,backRef:v,focusAfterRef:x}):null,a.status===`ok`?null:(0,H.jsx)(h,{state:a,minHeight:k}),a.status===`ok`&&C&&!C.ok?(0,H.jsx)(T,{label:C.message,minHeight:k}):null,a.status===`ok`&&C?.ok&&C.model.points.length===0?(0,H.jsx)(T,{label:`No data for the selected period`,minHeight:k}):null,a.status===`ok`&&C?.ok&&C.model.points.length>0?(0,H.jsxs)(`div`,{className:c(`transition-opacity duration-[var(--motion-quick)]`,(a.refreshing||S)&&`opacity-60`),"aria-busy":S||void 0,children:[o===`chart`?(0,H.jsx)(kn,{model:C.model,height:k,onPointClick:t.drilldown&&!r?D:null}):(0,H.jsx)(Dn,{model:C.model,drill:te}),a.result.truncated?(0,H.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Showing the first `,a.result.rows.length,` groups.`]}):null]}):null]})}var In=50,X=`px-3 py-2 text-xs font-medium text-muted-foreground`,Z=`px-3 py-1.5 tabular-nums`;function Ln(e,t){return t?e.dimensions[t]??``:`Total`}function Rn({total:e,onShow:t}){return(0,H.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,onClick:t,children:[`Show all `,e,` rows`]})})}function zn({element:e,config:t,result:n,decl:r}){let[i,a]=K(e,`expanded`,!1,mn),o=t.metrics??(t.metric?[t.metric]:[]),s=i?n.rows:n.rows.slice(0,In);return(0,H.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-left`),children:t.rows?F(t.rows,r.dimensions?.[t.rows]):``}),o.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:I(e,r.metrics[e])},e))]})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:s.map(e=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Ln(e,t.rows)}),o.map(t=>(0,H.jsx)(`td`,{className:c(Z,`text-right text-foreground`),children:L(e.values[t]??null,z(r.metrics[t]))},t))]},e.key))})]}),!i&&n.rows.length>In?(0,H.jsx)(Rn,{total:n.rows.length,onShow:()=>a(!0)}):null]})}function Bn({value:e,compare:t,format:n,direction:r,accounting:i}){let a=xe(e,t,n,r),o=v(k(a.sentiment));return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`td`,{className:c(Z,`text-right text-muted-foreground`),children:L(t,n,{accounting:i})}),(0,H.jsx)(`td`,{className:c(Z,`text-right`,o),children:a.amountText}),(0,H.jsx)(`td`,{className:c(Z,`text-right`,o),children:a.ratioText})]})}function Vn(e){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:e}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:`Change`}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:`Change %`})]})}function Hn({element:e,config:t,result:n,decl:r}){let[i,a]=K(e,`expanded`,!1,mn),o=t.metric??t.metrics?.[0]??``,s=r.metrics[o],l=z(s),u=i?n.rows:n.rows.slice(0,In),d=n.comparison?.label;return(0,H.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-left`),children:t.rows?F(t.rows,r.dimensions?.[t.rows]):``}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:I(o,s)}),d?Vn(d):null]})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:u.map(e=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Ln(e,t.rows)}),(0,H.jsx)(`td`,{className:c(Z,`text-right text-foreground`),children:L(e.values[o]??null,l)}),d?(0,H.jsx)(Bn,{value:e.values[o]??null,compare:e.compare?.[o]??null,format:l,direction:s?.direction,accounting:!1}):null]},e.key))})]}),!i&&n.rows.length>In?(0,H.jsx)(Rn,{total:n.rows.length,onShow:()=>a(!0)}):null]})}function Un(e){let t=e.filter(e=>typeof e==`number`);return t.length===0?null:t.reduce((e,t)=>e+t,0)}function Wn(e,t,n,r=[]){let i=new Map;for(let t of e.rows){let e=n?t.dimensions[n]??``:``,r=i.get(e)??[];r.push(t),i.set(e,r)}let a=e=>r.includes(e)?r.indexOf(e):r.length;return[...i.entries()].sort(([e],[t])=>a(e)-a(t)).map(([e,n])=>({name:e,rows:n,value:Un(n.map(e=>e.values[t])),compare:Un(n.map(e=>e.compare?.[t]))}))}function Gn({element:e,config:t,result:n,decl:r}){let[i,a]=K(e,`collapsed`,[],hn),o=new Set(i),s=t.metric??t.metrics?.[0]??``,l=r.metrics[s],u=z(l),d=n.comparison?.label,f=Wn(n,s,t.groupRows,t.groupRows?r.dimensions?.[t.groupRows]?.order:void 0),p=e=>{a(o.has(e)?i.filter(t=>t!==e):[...i,e])},m=e=>L(e,u,{accounting:!0}),h=(t.totals??[]).map(e=>{let t=f.filter(t=>e.groups.includes(t.name));return{label:e.label,value:Un(t.map(e=>e.value)),compare:Un(t.map(e=>e.compare))}});return(0,H.jsx)(`div`,{className:`max-h-[32rem] overflow-auto rounded-md border border-border`,children:(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-left`),children:t.rows?F(t.rows,r.dimensions?.[t.rows]):``}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:n.period.label}),d?Vn(d):null]})}),(0,H.jsxs)(`tbody`,{children:[f.map(e=>{let n=o.has(e.name),r=!!t.groupRows;return(0,H.jsxs)(V.Fragment,{children:[r?(0,H.jsxs)(`tr`,{className:`border-t border-border`,children:[(0,H.jsx)(`th`,{scope:`rowgroup`,className:`sticky left-0 bg-card px-2 py-1.5 text-left font-medium text-foreground`,children:(0,H.jsxs)(`button`,{type:`button`,onClick:()=>p(e.name),"aria-expanded":!n,className:`flex items-center gap-1 rounded px-1 hover:bg-muted`,children:[n?(0,H.jsx)(le,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,H.jsx)(ce,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e.name]})}),(0,H.jsx)(`td`,{className:c(Z,`text-right font-medium text-foreground`),children:m(e.value)}),d?(0,H.jsx)(Bn,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]}):null,n?null:e.rows.map(e=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:c(`sticky left-0 bg-card py-1 text-left font-normal text-foreground`,r?`pl-9 pr-3`:`px-3`),children:Ln(e,t.rows)}),(0,H.jsx)(`td`,{className:c(Z,`text-right text-foreground`),children:m(e.values[s]??null)}),d?(0,H.jsx)(Bn,{value:e.values[s]??null,compare:e.compare?.[s]??null,format:u,direction:l?.direction,accounting:!0}):null]},e.key))]},e.name||`_`)}),h.map(e=>(0,H.jsxs)(`tr`,{className:`border-t-2 border-border`,children:[(0,H.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-2 text-left font-semibold text-foreground`,children:e.label}),(0,H.jsx)(`td`,{className:c(Z,`text-right font-semibold text-foreground`),children:m(e.value)}),d?(0,H.jsx)(Bn,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]},e.label))]})]})})}function Kn({element:e,config:t,result:n,decl:r}){if(n.rows.length===0)return(0,H.jsx)(`p`,{className:`rounded-md border border-dashed border-border px-3 py-4 text-center text-sm text-muted-foreground`,children:`No data for the selected period`});switch(t.variant){case`statement`:return(0,H.jsx)(Gn,{element:e,config:t,result:n,decl:r});case`comparison`:return(0,H.jsx)(Hn,{element:e,config:t,result:n,decl:r});case`detail`:return(0,H.jsx)(zn,{element:e,config:t,result:n,decl:r})}}function qn(e){return e.charAt(0).toLowerCase()+e.slice(1)}function Jn(e,t){return t(q(e))}function Yn({element:e}){let t=(0,V.useMemo)(()=>Jn(e.props,e=>{let t=R.FinancialMetric.props.safeParse(e);return t.success?t.data:null}),[e.props]),n=y(t?.dataset),r=Cn(t?.dataset),i=(0,V.useMemo)(()=>{if(!t)return null;let e=J(t.compareWith),n=Y(t.filters,r);return{metrics:[t.metric],...t.period?{period:t.period}:{},...e?{compare:e}:{},...t.scenario?{scenario:t.scenario}:{},...n&&n.length>0?{filters:n}:{}}},[r,t]),a=E(t?.dataset,i);if(!t)return(0,H.jsx)(O,{component:`FinancialMetric`});let o=n?.metrics[t.metric],s=t.label??I(t.metric,o);if(a.status!==`ok`)return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md border border-border p-3`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,H.jsx)(h,{state:a})]});let l=z(o),u=a.result.totals.values[t.metric]??null,d=a.result.totals.compare?.[t.metric]??null,f=xe(u,d,l,o?.direction),p=k(f.sentiment);return(0,H.jsxs)(`div`,{className:c(`flex flex-col gap-1 rounded-md border border-border p-3`,a.refreshing&&`opacity-60`),children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,H.jsx)(`span`,{className:`text-2xl font-semibold leading-tight text-foreground`,children:L(u,l,{compact:!0})}),a.result.comparison&&f.amount!==null?(0,H.jsxs)(`span`,{className:c(`flex flex-wrap items-center gap-1 text-xs`,v(p)),children:[(0,H.jsx)(S,{trend:f.trend}),(0,H.jsx)(`span`,{className:`font-medium tabular-nums`,children:f.ratioText}),(0,H.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,f.amountText,`)`]}),(0,H.jsxs)(`span`,{className:`text-muted-foreground`,children:[`vs `,qn(a.result.comparison.label)]})]}):null,a.result.comparison&&f.amount===null?(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`No `,qn(a.result.comparison.label),` data to compare`]}):null,(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a.result.period.label})]})}var Xn=new Set([`IncomeStatement`,`BalanceSheet`,`CashFlowStatement`]);function Zn(e,t){let n=q(t);if(Xn.has(e)){let e=R.IncomeStatement.props.safeParse(n);return e.success?{variant:`statement`,...e.data}:null}let r=R.FinancialTable.props.safeParse(n);return r.success?{...r.data,variant:r.data.variant??(r.data.metrics?`detail`:`comparison`)}:null}function Qn(e,t){let n=e.metrics??(e.metric?[e.metric]:[]);if(n.length===0)return null;let r=[e.groupRows,e.rows].filter(e=>!!e),i=e.variant===`detail`?void 0:J(e.compareWith),a=Y(e.filters,t);return{metrics:n,groupBy:r,...e.period?{period:e.period}:{},...i?{compare:i}:{},...a&&a.length>0?{filters:a}:{},...e.rows?{sort:{by:e.rows,direction:`asc`}}:{},limit:e.limit??500}}var $n={IncomeStatement:`Income statement`,BalanceSheet:`Balance sheet`,CashFlowStatement:`Cash flow statement`};function er({element:e}){let t=(0,V.useMemo)(()=>Zn(e.type,e.props),[e.type,e.props]),n=y(t?.dataset),r=Cn(t?.dataset),i=(0,V.useMemo)(()=>t?Qn(t,r):null,[t,r]),a=E(t?.dataset,i);if(!t||!i)return(0,H.jsx)(O,{component:e.type});let o=t.title??$n[e.type];return(0,H.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[o?(0,H.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:o}):null,r&&n?(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Filtered to `,F(r.dimension,n.dimensions?.[r.dimension]).toLowerCase(),` `,r.value]}):null,a.status===`ok`?null:(0,H.jsx)(h,{state:a}),a.status===`ok`&&n?(0,H.jsx)(`div`,{className:c(a.refreshing&&`opacity-60`),children:(0,H.jsx)(Kn,{element:e,config:t,query:i,result:a.result,decl:n})}):null]})}function tr(e,t,n){let[r,i]=en(e,t);return[r??n,i]}function nr({label:e,children:t}){return(0,H.jsxs)(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]})}var rr=[`last-12-months`,`ytd`,`last-4-quarters`,`last-3-months`,`all`];function ir({element:e,bindings:t}){let n=R.PeriodSelector.props.safeParse(q(e.props)),r=n.success?n.data.options??[...rr]:[],[i,a]=tr(n.success?n.data.value:void 0,t?.value,r[0]??`all`);if(!n.success)return(0,H.jsx)(O,{component:`PeriodSelector`});let o=r.includes(i)?r:[i,...r];return(0,H.jsx)(nr,{label:n.data.label??`Period`,children:(0,H.jsxs)(he,{value:i,onValueChange:a,children:[(0,H.jsx)(de,{className:`h-9`,children:(0,H.jsx)(me,{})}),(0,H.jsx)(pe,{children:o.map(e=>(0,H.jsx)(fe,{value:e,children:Ae(e)},e))})]})})}function ar({element:e,bindings:t}){let{spec:n}=b(),r=R.CompareSelector.props.safeParse(q(e.props)),i=(0,V.useMemo)(()=>{let e=Object.values(n.datasets??{}).flatMap(e=>[e.scenario?.budget?`budget`:null,e.scenario?.forecast?`forecast`:null]);return new Set(e)},[n.datasets]),a=[...Oe.filter(e=>e.startsWith(`previous`)||i.has(e)),`none`],o=r.success?r.data.options??a:[],[s,c]=tr(r.success?r.data.value:void 0,t?.value,o[0]??`none`);return r.success?(0,H.jsx)(nr,{label:r.data.label??`Compare with`,children:(0,H.jsxs)(he,{value:s,onValueChange:c,children:[(0,H.jsx)(de,{className:`h-9`,children:(0,H.jsx)(me,{})}),(0,H.jsx)(pe,{children:o.map(e=>(0,H.jsx)(fe,{value:e,children:Te(e)},e))})]})}):(0,H.jsx)(O,{component:`CompareSelector`})}function or({element:e,bindings:t}){let n=e.type===`CurrencySelector`,r=(0,V.useMemo)(()=>{let t=q(e.props);if(n){let e=R.CurrencySelector.props.safeParse(t);return e.success?{...e.data,includeAll:!1}:null}let r=R.EntitySelector.props.safeParse(t);return r.success?r.data:null},[e.props,n]),i=y(r?.dataset),a=i?Object.keys(i.metrics)[0]:void 0,o=(0,V.useMemo)(()=>r&&a?{metrics:[a],groupBy:[r.dimension],sort:{by:r.dimension,direction:`asc`},limit:200}:null,[a,r]),s=E(r?.dataset,o),c=s.status===`ok`?s.result.rows.map(e=>e.dimensions[r?.dimension??``]??``):[],l=r?.includeAll===!1||n?c[0]??``:`all`,[u,d]=tr(r?.value,t?.value,l);if(!r)return(0,H.jsx)(O,{component:e.type});let f=r.label??(n?`Currency`:F(r.dimension,i?.dimensions?.[r.dimension]));if(s.status!==`ok`)return(0,H.jsx)(nr,{label:f,children:(0,H.jsx)(h,{state:s})});let p=[...r.includeAll===!1||n?[]:[`all`],...c];return(0,H.jsx)(nr,{label:f,children:(0,H.jsxs)(he,{value:u||l,onValueChange:d,children:[(0,H.jsx)(de,{className:`h-9`,children:(0,H.jsx)(me,{})}),(0,H.jsx)(pe,{children:p.map(e=>(0,H.jsx)(fe,{value:e,children:e===`all`?`All`:e},e))})]})})}var sr={sm:`gap-2`,md:`gap-3`,lg:`gap-5`},cr={1:`grid-cols-1`,2:`grid-cols-1 @md:grid-cols-2`,3:`grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-4`};function lr({element:e,children:t}){let n=R.Stack.props.safeParse(q(e.props));if(!n.success)return(0,H.jsx)(O,{component:`Stack`});let r=n.data.direction===`horizontal`;return(0,H.jsx)(`div`,{className:c(`flex min-w-0`,r?`flex-row flex-wrap items-start`:`flex-col`,sr[n.data.gap??`md`]),children:t})}function ur({element:e,children:t}){let n=R.Grid.props.safeParse(q(e.props));return n.success?(0,H.jsx)(`div`,{className:c(`grid min-w-0`,cr[n.data.columns??2],sr[n.data.gap??`md`]),children:t}):(0,H.jsx)(O,{component:`Grid`})}function dr({element:e,children:t}){let n=R.Card.props.safeParse(q(e.props));return n.success?(0,H.jsxs)(`section`,{className:`min-w-0 rounded-md border border-border p-3`,"aria-label":n.data.title,children:[n.data.title?(0,H.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:n.data.title}):null,n.data.description?(0,H.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:n.data.description}):null,(0,H.jsx)(`div`,{className:c(`flex flex-col gap-3`,(n.data.title||n.data.description)&&`mt-3`),children:t})]}):(0,H.jsx)(O,{component:`Card`})}function fr({element:e,children:t}){let n=R.Section.props.safeParse(q(e.props));return n.success?(0,H.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":n.data.title,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:n.data.title}),n.data.description?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.data.description}):null]}),t]}):(0,H.jsx)(O,{component:`Section`})}function pr({element:e,children:t,bindings:n}){let r=R.Tabs.props.safeParse(q(e.props)),i=r.success?r.data.items:[],[a,o]=en(r.success?r.data.value:void 0,n?.value),[s,c]=K(e,`tab`,i[0]?.value??``,pn);if(!r.success)return(0,H.jsx)(O,{component:`Tabs`});let l=n?.value?a??i[0]?.value??``:s,u=e=>{n?.value?o(e):c(e)},d=V.Children.toArray(t),f=Math.max(0,i.findIndex(e=>e.value===l));return(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,H.jsx)(ve,{size:`sm`,value:i[f]?.value??``,onValueChange:u,options:i.map(e=>({value:e.value,label:e.label}))}),(0,H.jsx)(`div`,{role:`tabpanel`,children:d[f]??null})]})}var mr={body:`text-sm text-foreground`,muted:`text-sm text-muted-foreground`,heading:`text-base font-medium text-foreground`,label:`text-xs font-medium text-muted-foreground`};function hr({element:e}){let t=R.Text.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`p`,{className:c(`whitespace-pre-wrap break-words`,mr[t.data.variant??`body`]),children:t.data.text}):(0,H.jsx)(O,{component:`Text`})}function gr({element:e}){let t=R.Badge.props.safeParse(q(e.props));if(!t.success)return(0,H.jsx)(O,{component:`Badge`});let n=t.data.tone??`neutral`;return(0,H.jsxs)(`span`,{className:c(`inline-flex w-fit items-center gap-1 rounded-md border border-border px-1.5 py-0.5 text-xs font-medium`,v(n)),children:[(0,H.jsx)(_,{tone:n}),t.data.label]})}var _r={primary:`default`,secondary:`outline`,ghost:`ghost`};function vr(e){return e?(Array.isArray(e)?e:[e]).map(e=>e.action):[]}function yr({element:e,emit:t}){let{loadingActions:n}=W(),r=R.Button.props.safeParse(q(e.props));if(!r.success)return(0,H.jsx)(O,{component:`Button`});let i=vr(e.on?.press).some(e=>n.has(e));return(0,H.jsx)(s,{size:`sm`,variant:_r[r.data.variant??`secondary`],className:`w-fit`,pending:i,onClick:()=>t(`press`),children:r.data.label})}function br(){return(0,H.jsx)(`hr`,{className:`border-border`})}function xr(e,t,n){let{execute:r}=W(),{viewKey:i}=b(),a=p(`genui.${e}`,i,n),o=d(a);return{run:(0,V.useCallback)(()=>{u(a,()=>r({action:e,params:t}))},[e,r,a,t]),pending:o}}function Sr({path:e,line:t,label:n}){let{run:r,pending:i}=xr(`file.open`,t?{path:e,line:t}:{path:e},`${e}:${t??``}`);return(0,H.jsx)(`button`,{type:`button`,onClick:r,disabled:i,"aria-busy":i||void 0,className:`max-w-full rounded-sm text-left font-mono text-xs break-all text-foreground underline decoration-border underline-offset-2 hover:decoration-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:n})}function Cr({element:e}){let t=R.KeyValue.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`dl`,{className:c(`grid gap-x-6 gap-y-1.5`,t.data.columns===2?`grid-cols-1 @md:grid-cols-2`:`grid-cols-1`),children:t.data.items.map(e=>(0,H.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,2fr)] gap-3 text-sm`,children:[(0,H.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,H.jsx)(`dd`,{className:`break-words text-foreground tabular-nums`,children:e.value===null?`—`:String(e.value)})]},e.label))}):(0,H.jsx)(O,{component:`KeyValue`})}var wr={added:{icon:ne,label:`Added`},modified:{icon:re,label:`Modified`},deleted:{icon:st,label:`Deleted`},renamed:{icon:M,label:`Renamed`}};function Tr({element:e}){let t=R.FileList.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.data.files.map(e=>{let t=e.status?wr[e.status]:null,n=t?.icon??M;return(0,H.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2`,children:[(0,H.jsx)(n,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(Sr,{path:e.path,label:e.path}),e.description?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}):null]}),t?(0,H.jsx)(`span`,{className:`mt-0.5 shrink-0 pl-2 text-xs text-muted-foreground`,children:t.label}):null]},e.path)})}):(0,H.jsx)(O,{component:`FileList`})}function Er(e,t,n){return t?n?`${e}:${t}:${n}`:`${e}:${t}`:e}var Dr={error:`negative`,warning:`attention`,info:`info`},Or={error:`Error`,warning:`Warning`,info:`Info`};function kr({element:e}){let t=R.DiagnosticList.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.data.items.map((e,t)=>{let n=Dr[e.severity],r=e.path?Er(e.path,e.line,e.column):null;return(0,H.jsxs)(`li`,{className:`flex gap-2 px-3 py-2 text-sm`,children:[(0,H.jsxs)(`span`,{className:c(`mt-0.5 flex shrink-0 items-center gap-1 text-xs font-medium`,v(n)),children:[(0,H.jsx)(_,{tone:n}),Or[e.severity]]}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`break-words text-foreground`,children:e.message}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[e.path&&r?(0,H.jsx)(Sr,{path:e.path,line:e.line,label:r}):null,e.source?(0,H.jsx)(`span`,{children:e.source}):null]})]})]},`${t}-${e.message}`)})}):(0,H.jsx)(O,{component:`DiagnosticList`})}function Ar({name:e,context:t}){let{run:n,pending:r}=xr(`agent.fix`,{subject:e,context:t},e);return(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,className:`gap-1.5`,onClick:n,pending:r,"aria-label":`Ask the agent to fix ${e}`,children:[r?null:(0,H.jsx)(se,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Fix`]})}function jr({element:e}){let t=R.TestResult.props.safeParse(q(e.props));if(!t.success)return(0,H.jsx)(O,{component:`TestResult`});let{passed:n,failed:r,skipped:i,durationMs:a,command:o,failures:s}=t.data,l=r>0?`negative`:`positive`;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-sm`,children:[(0,H.jsxs)(`span`,{className:c(`flex items-center gap-1 font-medium`,v(l)),children:[(0,H.jsx)(_,{tone:l}),r>0?`Failing`:`Passing`]}),(0,H.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[n,` passed`]}),(0,H.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[r,` failed`]}),i===void 0?null:(0,H.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[i,` skipped`]}),a===void 0?null:(0,H.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:rt(a)})]}),o?(0,H.jsx)(`code`,{className:`w-fit rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-muted-foreground`,children:o}):null,s&&s.length>0?(0,H.jsx)(`ul`,{className:`divide-y divide-border border-t border-border`,children:s.map(e=>(0,H.jsxs)(`li`,{className:`flex items-start gap-2 py-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`break-words text-sm text-foreground`,children:e.name}),e.message?(0,H.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-auto whitespace-pre-wrap font-mono text-xs text-muted-foreground`,children:e.message}):null,e.path?(0,H.jsx)(Sr,{path:e.path,line:e.line,label:Er(e.path,e.line,void 0)}):null]}),(0,H.jsx)(Ar,{name:e.name,context:{...e.message?{message:e.message}:{},...e.path?{path:e.path}:{},...e.line?{line:e.line}:{},...o?{command:o}:{}}})]},e.name))}):null]})}function Mr({element:e}){let t=R.Timeline.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`ol`,{className:`flex flex-col gap-3 border-l border-border pl-4`,children:t.data.items.map((e,t)=>(0,H.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.tone?(0,H.jsx)(_,{tone:e.tone,className:v(e.tone)}):null,(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e.title}),e.time?(0,H.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:e.time}):null]}),e.detail?(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.detail}):null]},`${t}-${e.title}`))}):(0,H.jsx)(O,{component:`Timeline`})}var Nr=50,Pr=`px-3 py-2 text-xs font-medium text-muted-foreground`;function Fr(e){return e==null?`—`:typeof e==`string`?e:typeof e==`number`?new Intl.NumberFormat(`en-US`).format(e):typeof e==`boolean`?e?`Yes`:`No`:JSON.stringify(e)}function Ir(e,t){let n=e??Object.keys(t[0]??{}).map(e=>({key:e,label:Ne(e)}));return{columns:n.map(e=>({...e,numeric:t.every(t=>typeof t[e.key]==`number`||t[e.key]===void 0)})),rows:t.map((e,t)=>({key:String(t),cells:Object.fromEntries(n.map(t=>[t.key,Fr(e[t.key])]))}))}}function Lr(e,t,n,r){let i=r.comparison?.label;return{columns:[...t.map(t=>({key:`d:${t}`,label:F(t,e.dimensions?.[t]),numeric:!1})),...n.flatMap(t=>[{key:`m:${t}`,label:I(t,e.metrics[t]),numeric:!0},...i?[{key:`c:${t}`,label:`${I(t,e.metrics[t])} (${i})`,numeric:!0}]:[]])],rows:r.rows.map(r=>({key:r.key,cells:Object.fromEntries([...t.map(e=>[`d:${e}`,r.dimensions[e]??``]),...n.flatMap(t=>[[`m:${t}`,L(r.values[t]??null,z(e.metrics[t]))],...i?[[`c:${t}`,L(r.compare?.[t]??null,z(e.metrics[t]))]]:[]])])}))}}function Rr({element:e,columns:t,rows:n,title:r}){let[i,a]=K(e,`expanded`,!1,mn),o=i?n:n.slice(0,Nr);return(0,H.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[r?(0,H.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:r}):null,(0,H.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsx)(`tr`,{className:`border-b border-border`,children:t.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:c(Pr,e.numeric?`text-right`:`text-left`),children:e.label},e.key))})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:o.map(e=>(0,H.jsx)(`tr`,{children:t.map(t=>(0,H.jsx)(`td`,{className:c(`px-3 py-1.5 text-foreground`,t.numeric?`text-right tabular-nums`:`text-left`),children:e.cells[t.key]},t.key))},e.key))})]}),!i&&n.length>Nr?(0,H.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,onClick:()=>a(!0),children:[`Show all `,n.length,` rows`]})}):null]})]})}function zr({element:e}){let t=(0,V.useMemo)(()=>{let t=R.DataTable.props.safeParse(q(e.props));return t.success?t.data:null},[e.props]),n=y(t?.dataset),r=Cn(t?.dataset),i=(0,V.useMemo)(()=>{if(!t?.dataset||!t.metrics)return null;let e=J(t.compareWith),n=Y(t.filters,r);return{metrics:t.metrics,groupBy:t.dimensions??[],...t.period?{period:t.period}:{},...e?{compare:e}:{},...n&&n.length>0?{filters:n}:{},limit:t.limit??200}},[r,t]),a=E(t?.dataset,i);if(!t)return(0,H.jsx)(O,{component:`DataTable`});if(!t.dataset){let n=(t.rows??[]).filter(be);return(0,H.jsx)(Rr,{element:e,...Ir(t.columns,n),title:t.title})}return t.metrics?a.status===`ok`?n?(0,H.jsx)(Rr,{element:e,...Lr(n,t.dimensions??[],t.metrics,a.result),title:t.title}):(0,H.jsx)(O,{component:`DataTable`}):(0,H.jsx)(h,{state:a}):(0,H.jsx)(O,{component:`DataTable`})}var Br={sm:280,md:420,lg:600},Vr=720,Hr=14,Ur=132,Wr=300,Gr=50,Kr=8,qr=16,Jr=38,Yr=24;function Xr(){return a.getCssVar(`--kanna-font-body`,`system-ui, sans-serif`)}function Zr(){return a.getCssVar(`--kanna-font-mono`,`ui-monospace, monospace`)}function Q(e,t,n){return a.measureTextWidth(e,t)??e.length*n}function Qr(e,t){let n=e.split(`/`).pop()??e;return t?`${n}:${t}`:n}function $r(e){let t=Xr(),n=Q(e.label,`500 14px ${t}`,7.6),r=e.status?Q(e.status,`500 12px ${t}`,6.4)+Yr:0,i=e.description?Q(e.description,`12px ${t}`,6.2):0,a=e.path?Q(Qr(e.path,e.line),`12px ${Zr()}`,7.2):0,o=Math.max(n+r,i,a);return{width:Math.round(Math.min(Wr,Math.max(Ur,o+Gr+(e.kind===`start`||e.kind===`end`?Kr:0)))),height:Jr+(e.description?qr:0)+(e.path?qr:0)}}function ei(e){return`e${e}`}function ti(e,t){let n=e=>({id:e.id,...$r(e)}),r=new Set((e.groups??[]).map(e=>e.id)),i=e.edges.map((e,t)=>({id:ei(t),sources:[e.from],targets:[e.to],...e.label?{labels:[{text:e.label,width:Q(e.label,`12px ${Xr()}`,6.4)+10,height:18}]}:{}}));return{id:`root`,layoutOptions:{"elk.algorithm":`layered`,"elk.direction":t===`LR`?`RIGHT`:`DOWN`,"elk.hierarchyHandling":`INCLUDE_CHILDREN`,"elk.edgeRouting":`ORTHOGONAL`,"elk.json.edgeCoords":`ROOT`,"elk.edgeLabels.inline":`true`,"elk.spacing.nodeNode":`28`,"elk.layered.spacing.nodeNodeBetweenLayers":`52`,"elk.layered.nodePlacement.strategy":`NETWORK_SIMPLEX`},children:[...(e.groups??[]).map(t=>({id:t.id,layoutOptions:{"elk.padding":`[top=38,left=${Hr},bottom=${Hr},right=${Hr}]`},children:e.nodes.filter(e=>e.group===t.id).map(n)})).filter(e=>e.children.length>0),...e.nodes.filter(e=>e.group===void 0||!r.has(e.group)).map(n)],edges:i}}function ni(e,t,n){let r=new Map(e.nodes.map(e=>[e.id,e])),i=new Map((e.groups??[]).map(e=>[e.id,e.label])),a=[],o=[],s=(e,t)=>{let n={x:t.x+(e.x??0),y:t.y+(e.y??0),width:e.width??0,height:e.height??0},c=r.get(e.id);if(c){o.push({...n,node:c});return}a.push({...n,id:e.id,label:i.get(e.id)??e.id});for(let t of e.children??[])s(t,{x:n.x,y:n.y})};for(let e of n.children??[])s(e,{x:0,y:0});let c=new Map((n.edges??[]).map(e=>[e.id,e])),l=e.edges.map((e,t)=>{let n=c.get(ei(t))?.sections?.[0],r=c.get(ei(t))?.labels?.[0];return{key:ei(t),edge:e,points:n?[n.startPoint,...n.bendPoints??[],n.endPoint]:[],labelAt:r?.x!==void 0&&r.y!==void 0?{x:r.x+(r.width??0)/2,y:r.y+(r.height??0)/2}:null}});return{direction:t,width:n.width??0,height:n.height??0,groups:a,nodes:o,edges:l}}async function ri(t,r){let{default:i}=await n(async()=>{let{default:t}=await import(`./elk.bundled-BfUIUPT1.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([10,1]));return ni(t,r,await new i().layout(ti(t,r)))}function ii(e,t){return e.width===0||e.height===0?1:Math.min(Vr/e.width,t/e.height)}async function ai(e){await a.whenFontsReady();let t=e.direction??`auto`;if(t!==`auto`)return await ri(e,t);let n=Br[e.height??`md`],[r,i]=await Promise.all([ri(e,`LR`),ri(e,`TB`)]);return ii(r,n)>=ii(i,n)?r:i}var oi=(0,V.lazy)(()=>n(()=>import(`./FlowSurface-BCbeMTJe.js`),__vite__mapDeps([11,1,2,12,3,13,4,14,15,16,17,18,19,20,21,6,5,7,22,23,24,25]))),si=`genui-flow-layout`;function ci(e){return e===`diagram`||e===`outline`}function li(e){let t=q(e);if(!t)return null;let n=R.FlowDiagram.props.safeParse(t);return n.success?n.data:null}function ui(e){return i({queryKey:[si,m(JSON.stringify(e))],queryFn:async()=>await ai(e),staleTime:1/0,retry:!1})}function di(e){let t=e.edges.filter(e=>A(e)===`flow`).length,n=`${e.nodes.length} ${e.nodes.length===1?`step`:`steps`}`,r=`${e.edges.length} ${e.edges.length===1?`connection`:`connections`}`;return t>0?`${n} · ${r} · ${t} live`:`${n} · ${r}`}function fi({heading:e,links:t,direction:n}){return t.length===0?null:(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(0,H.jsxs)(`span`,{children:[e,` `]}),t.map((e,t)=>(0,H.jsxs)(`span`,{children:[t>0?`, `:null,(0,H.jsx)(`span`,{className:`text-foreground`,children:e.node.label}),e.edge.label?(0,H.jsxs)(`span`,{children:[` (`,e.edge.label,`)`]}):null,A(e.edge)===`flow`?(0,H.jsx)(`span`,{className:`text-info-text`,children:` · live`}):null]},`${n}-${e.node.id}-${t}`))]})}function pi({entries:e,selectedId:t,onSelect:n}){return(0,H.jsx)(`ol`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map((e,r)=>(0,H.jsxs)(`li`,{className:c(`flex gap-3 px-3 py-2`,e.node.id===t&&`bg-muted`),children:[(0,H.jsx)(`span`,{className:`w-5 shrink-0 pt-0.5 text-right text-xs text-muted-foreground tabular-nums`,children:r+1}),(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,H.jsx)(w,{node:e.node}),(0,H.jsx)(`button`,{type:`button`,className:`rounded-sm text-left text-sm font-medium text-foreground underline decoration-border underline-offset-4 hover:decoration-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-pressed":e.node.id===t,onClick:()=>n(e.node.id),children:e.node.label}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ee[e.node.kind??`process`].label}),e.groupLabel?(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`in `,e.groupLabel]}):null,(0,H.jsx)(D,{node:e.node})]}),e.node.description?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.node.description}):null,(0,H.jsx)(fi,{heading:`From`,links:e.incoming,direction:`in`}),(0,H.jsx)(fi,{heading:`To`,links:e.outgoing,direction:`out`})]})]},e.node.id))})}function mi({node:e}){let{run:t,pending:n}=xr(`file.open`,(0,V.useMemo)(()=>e.line?{path:e.path,line:e.line}:{path:e.path},[e.line,e.path]),`${e.id}:${e.path}`);return(0,H.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:n,onClick:t,children:[n?null:(0,H.jsx)(M,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open file`]})}function hi({diagram:e,node:t}){let n=(0,V.useMemo)(()=>j(e,t.id)??{},[e,t.id]),{run:r,pending:i}=xr(`agent.investigate`,(0,V.useMemo)(()=>({subject:t.label,context:n}),[n,t.label]),t.id);return(0,H.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:i,onClick:r,children:[i?null:(0,H.jsx)(lt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Ask agent`]})}function gi(e){return e.path?e.line?`${e.path}:${e.line}`:e.path:null}function _i(e){return e.path!==void 0}function vi({diagram:e,entry:t,onClose:n}){let r=N(),{node:i}=t,a=gi(i);return(0,H.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,"aria-label":`Step ${i.label}`,children:[(0,H.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,H.jsx)(w,{node:i,className:`mt-1`}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:i.label}),(0,H.jsx)(D,{node:i})]}),i.description?(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i.description}):null,a?(0,H.jsx)(`p`,{className:`font-mono text-xs break-all text-muted-foreground`,children:a}):null]}),(0,H.jsx)(s,{size:`icon-sm`,variant:`ghost`,onClick:n,"aria-label":`Close step details`,children:(0,H.jsx)(_e,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}),(0,H.jsx)(fi,{heading:`From`,links:t.incoming,direction:`in`}),(0,H.jsx)(fi,{heading:`To`,links:t.outgoing,direction:`out`}),r.readonly?null:(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[_i(i)?(0,H.jsx)(mi,{node:i}):null,r.sendToAgent?(0,H.jsx)(hi,{diagram:e,node:i}):null]})]})}function yi({diagram:e,height:t,label:n,selectedId:r,onSelect:i}){let a=N(),o=ui(e),s=a.FlowRenderer??oi;return o.error?(0,H.jsx)(T,{label:`This diagram could not be laid out. The Outline view still lists every step.`,minHeight:t}):o.data?(0,H.jsx)(V.Suspense,{fallback:(0,H.jsx)(`div`,{className:`w-full rounded-md border border-border`,style:{height:t},"aria-hidden":`true`}),children:(0,H.jsx)(s,{layout:o.data,height:t,label:n,selectedId:r,onSelect:i})}):(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 rounded-md border border-border text-sm text-muted-foreground`,style:{height:t},role:`status`,children:[(0,H.jsx)(f,{}),` Laying out diagram…`]})}function bi({element:e}){let t=(0,V.useMemo)(()=>li(e.props),[e.props]),n=(0,V.useMemo)(()=>t?g(t):[],[t]),[r,i]=K(e,`view`,`diagram`,ci),[a,o]=K(e,`selected`,``,pn),s=(0,V.useId)(),c=(0,V.useCallback)(e=>o(e??``),[o]),l=(0,V.useCallback)(e=>o(e===a?``:e),[a,o]),u=(0,V.useCallback)(()=>o(``),[o]);if(!t)return(0,H.jsx)(O,{component:`FlowDiagram`});let d=Br[t.height??`md`],f=n.find(e=>e.node.id===a)??null,p=`Diagram${t.title?` of ${t.title}`:``}: ${di(t)}. Switch to Outline to read it as a list.`;return(0,H.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,"aria-labelledby":s,children:[(0,H.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{id:s,className:`text-sm font-medium text-foreground`,children:t.title??`Diagram`}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground tabular-nums`,children:di(t)})]}),(0,H.jsx)(ve,{size:`sm`,value:r,onValueChange:i,options:[{value:`diagram`,label:`Diagram`},{value:`outline`,label:`Outline`}]})]}),r===`diagram`?(0,H.jsx)(yi,{diagram:t,height:d,label:p,selectedId:f?.node.id??null,onSelect:c}):(0,H.jsx)(pi,{entries:n,selectedId:f?.node.id??null,onSelect:l}),f?(0,H.jsx)(vi,{diagram:t,entry:f,onClose:u}):null]})}var xi={Stack:lr,Grid:ur,Card:dr,Section:fr,Tabs:pr,Text:hr,Badge:gr,Button:yr,Divider:br,KeyValue:Cr,DataTable:zr,FileList:Tr,DiagnosticList:kr,TestResult:jr,Timeline:Mr,FlowDiagram:bi,FinancialMetric:Yn,FinancialChart:Fn,FinancialTable:er,IncomeStatement:er,BalanceSheet:er,CashFlowStatement:er,PeriodSelector:ir,CompareSelector:ar,CurrencySelector:or,EntitySelector:or};function Si({element:e}){return(0,H.jsx)(O,{component:e.type})}var Ci=64,$=new Map;function wi(e,t){let n=$.get(e);if(n)return $.delete(e),$.set(e,n),n;let r=Pe({...t});for($.set(e,r);$.size>Ci;){let e=$.keys().next().value;if(e===void 0)break;$.delete(e)}return r}function Ti(e){return{root:e.root,elements:Object.fromEntries(Object.entries(e.elements).map(([e,t])=>[e,{type:t.type,props:{...t.props,[un]:e},children:t.children,...t.visible===void 0?{}:{visible:t.visible},...t.repeat?{repeat:t.repeat}:{},...t.on?{on:t.on}:{}}])),...e.state?{state:e.state}:{}}}function Ei({viewKey:e}){let t=N(),n=C.useScopedStore(e=>e.pendingAgentMessage),r=C.useScopedStore(e=>e.cancelAgentMessage),i=C.useScopedStore(e=>e.showNotice),a=p(`genui.agent.send`,e),o=d(a),c=t.sendToAgent,l=(0,V.useCallback)(()=>{n&&c&&u(a,async()=>{try{await c(n.message),r()}catch(e){throw i(e instanceof Error?e.message:`The message could not be sent`),e}})},[r,a,n,c,i]);return n?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-muted/40 p-3`,role:`group`,"aria-label":`Send to the agent`,children:[(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,H.jsx)(lt,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Send to the agent`}),(0,H.jsx)(`p`,{className:`break-words text-foreground`,children:n.headline}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The view's current numbers and data source go with it.`})]})]}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(s,{size:`sm`,pending:o,onClick:l,children:`Send`}),(0,H.jsx)(s,{size:`sm`,variant:`ghost`,onClick:r,disabled:o,children:`Cancel`})]})]}):null}function Di(){let e=C.useScopedStore(e=>e.notice),t=C.useScopedStore(e=>e.showNotice);return e?(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-destructive-text`,role:`alert`,children:[(0,H.jsx)(ge,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,H.jsx)(`button`,{type:`button`,className:`rounded p-0.5 text-muted-foreground hover:text-foreground`,"aria-label":`Dismiss`,onClick:()=>t(null),children:(0,H.jsx)(_e,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}):null}function Oi(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function ki(){let e=C.useScopedStore(e=>e.previewPath),t=C.useScopedStore(e=>e.previewProbe),n=C.useScopedStore(e=>e.setPreviewProbe),r=C.useScopedStore(e=>e.closePreview),i=C.useScopedStore(e=>e.showNotice);(0,V.useEffect)(()=>{if(!e)return;let t=new AbortController;return nt(`probe generated file link`,te(ae(e),{signal:t.signal}).then(a=>{t.signal.aborted||(a.kind===`ready`?n(a):(r(),i(`"${Oi(e)}" could not be opened`)))})),()=>t.abort()},[r,e,n,i]);let a=(0,V.useMemo)(()=>{if(!e||t?.kind!==`ready`)return null;let n=ae(e);return ie({id:`genui-file-${n}`,kind:`file`,displayName:Oi(e),absolutePath:e,relativePath:e,contentUrl:n,mimeType:t.mimeType,size:t.size},`local_file_link`)},[e,t]),o=(0,V.useCallback)(e=>{e||r()},[r]);return(0,H.jsx)(oe,{source:a,open:a!==null,onOpenChange:o})}function Ai({handlers:e}){let{registerHandler:t}=W();return(0,V.useEffect)(()=>{for(let[n,r]of Object.entries(e))t(n,r)},[e,t]),null}function ji({spec:e,viewKey:t}){let n=N(),r=C.useScopedStoreApi(),i=(0,V.useMemo)(()=>wi(t,e.state??{}),[t,e.state]),a=(0,V.useMemo)(()=>ln({host:()=>n,view:r,spec:e,state:i}),[n,r,e,i]),o=(0,V.useMemo)(()=>Ti(e),[e]),s=(0,V.useMemo)(()=>({spec:e,viewKey:t}),[e,t]);return(0,H.jsx)(x,{value:s,children:(0,H.jsxs)(`section`,{className:`@container not-prose my-3 flex w-full min-w-0 flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:p-4`,"aria-label":e.title??`Generated view`,children:[e.title?(0,H.jsx)(`h3`,{className:`text-base font-medium text-foreground`,children:e.title}):null,(0,H.jsxs)(Qt,{registry:xi,store:i,handlers:a,children:[(0,H.jsx)(Ai,{handlers:a}),(0,H.jsx)(Zt,{spec:o,registry:xi,fallback:Si})]}),(0,H.jsx)(Di,{}),(0,H.jsx)(Ei,{viewKey:t}),(0,H.jsx)(ki,{})]})})}function Mi({spec:e,viewKey:t}){return(0,H.jsx)(C.Provider,{init:void 0,children:(0,H.jsx)(ji,{spec:e,viewKey:t})})}var Ni=8;function Pi({issues:e}){return(0,H.jsxs)(`div`,{className:`not-prose my-3 flex flex-col gap-2 rounded-lg border border-border p-3 text-sm`,role:`alert`,children:[(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-foreground`,children:[(0,H.jsx)(ge,{className:`h-4 w-4 text-warning-text`,"aria-hidden":`true`}),`Unable to show this view`]}),(0,H.jsx)(`p`,{className:`text-muted-foreground`,children:`The agent described a view Kanna could not validate, so nothing from it was run.`}),(0,H.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer select-none`,children:`Details`}),(0,H.jsxs)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4 font-mono`,children:[e.slice(0,Ni).map(e=>(0,H.jsxs)(`li`,{children:[e.path?`${e.path}: `:``,e.message]},`${e.path}:${e.message}`)),e.length>Ni?(0,H.jsxs)(`li`,{children:[`…and `,e.length-Ni,` more`]}):null]})]})]})}var Fi=class extends V.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){o.warn(`[kanna/genui] view failed to render`,{message:e.message})}render(){return this.state.failed?(0,H.jsx)(Pi,{issues:[{path:``,message:`The view stopped rendering unexpectedly`}]}):this.props.children}};function Ii({source:e}){let t=N(),n=(0,V.useMemo)(()=>Xe(e),[e]),r=(0,V.useMemo)(()=>`${t.chatId??`shared`}:${m(e)}`,[t.chatId,e]);return n.ok?(0,H.jsx)(Fi,{children:(0,H.jsx)(Mi,{spec:n.spec,viewKey:r})}):(0,H.jsx)(Pi,{issues:n.issues})}export{Pi as GenUIFallback,Ii as default};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/VChartSurface-CUbxyBo3.js","assets/rolldown-runtime-C0FnF6B9.js","assets/react-DiVRNtpo.js","assets/jsx-runtime-BdxMnOeJ.js","assets/log-DnEvbp3E.js","assets/useTheme-D9sKDPEm.js","assets/genui-C9i6j0XZ.js","assets/tools-t5T_3UBg.js","assets/runDetached-DfQXHAaY.js","assets/chart-renderer-D7ukB2wg.js","assets/elk.bundled-BfUIUPT1.js","assets/FlowSurface-CLC-ZFar.js","assets/react-dom-CvX0TCLz.js","assets/pendingActionsStore-CxhI19V9.js","assets/flow-kinds-Ki2DP9nP.js","assets/useQuery-Cqr8_M0q.js","assets/host-D9tJwZXl.js","assets/globe-BjR1tyE4.js","assets/info-DNYekoE-.js","assets/triangle-alert-CYQhobyY.js","assets/play-uofLR7yT.js","assets/createScopedStore-BrD5NHWx.js","assets/src-B-DeWB10.js","assets/value-DcGlvoTp.js","assets/shim-DTZXyK8i.js","assets/FlowSurface-ChafqZqb.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./react-DiVRNtpo.js";import{t as n}from"./preload-helper-DjzSQ1t3.js";import{t as r}from"./jsx-runtime-BdxMnOeJ.js";import{t as i}from"./useQuery-Cqr8_M0q.js";import{d as a,t as o}from"./log-DnEvbp3E.js";import{a as s,c,f as l,n as u,r as d,s as f,t as p}from"./pendingActionsStore-CxhI19V9.js";import{_ as m,a as h,b as g,c as _,d as v,f as y,g as b,h as x,l as S,m as C,n as w,o as T,p as E,r as D,s as O,t as ee,u as k,v as A,y as j}from"./flow-kinds-Ki2DP9nP.js";import{G as M,R as te,U as ne,W as re,a as ie,l as ae,t as oe,z as se}from"./FilePreviewSheet-B6SDxSD0.js";import{r as ce}from"./dist-DNSTHlSo.js";import{t as le}from"./chevron-left-RbFvmeyK.js";import{r as ue}from"./terminal-DfCF-J4p.js";import{a as de,i as fe,n as pe,o as me,t as he}from"./select-BjeajpVt.js";import{r as N}from"./host-D9tJwZXl.js";import{t as ge}from"./triangle-alert-CYQhobyY.js";import{g as _e}from"./timer.adapter-C2RhP4d6.js";import{t as ve}from"./segmented-control-CKGX29Kl.js";import{c as ye,l as be}from"./useTheme-D9sKDPEm.js";import{A as P,B as F,D as xe,E as Se,F as Ce,H as I,I as we,L as Te,Lr as Ee,M as De,N as Oe,O as L,P as ke,R as Ae,T as je,U as Me,V as Ne,_ as Pe,a as Fe,b as Ie,c as Le,d as Re,f as ze,g as Be,h as Ve,i as He,j as R,k as z,l as Ue,m as We,n as Ge,o as Ke,p as qe,r as Je,s as Ye,t as Xe,u as Ze,v as Qe,w as $e,wr as et,x as tt,y as B}from"./genui-C9i6j0XZ.js";import{t as nt}from"./runDetached-DfQXHAaY.js";import{t as rt}from"./formatDuration-BbWTR_M_.js";import{n as it,t as at}from"./chart-renderer-D7ukB2wg.js";var ot={name:`file-minus-corner`,size:24,node:[[`path`,{d:`M20 14V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12`,key:`l9p8hp`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M14 18h6`,key:`1m8k6r`}]],aliases:[`file-minus-2`]};ot.node;var st=l(ot),ct={name:`message-square-text`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M7 11h10`,key:`1twpyw`}],[`path`,{d:`M7 15h6`,key:`d9of3u`}],[`path`,{d:`M7 7h8`,key:`af5zfr`}]]};ct.node;var lt=l(ct),V=e(t(),1);Je(e=>({spec:e.object({root:e.string(),elements:e.record(e.object({type:e.ref(`catalog.components`),props:e.propsOf(`catalog.components`),children:e.array(e.string()),slots:{...e.record(e.array(e.string())),...e.optional()},visible:{...e.any(),...e.optional()},repeat:{...e.any(),...e.optional()}}))}),catalog:e.object({components:e.map({props:e.zod(),slots:e.array(e.string()),description:e.string(),example:e.any()}),actions:e.map({params:e.zod(),description:e.string()})})}),{builtInActions:[{name:`setState`,description:`Update a value in the state model at the given statePath. Params: { statePath: string, value: any }`},{name:`pushState`,description:`Append an item to an array in state. Params: { statePath: string, value: any, clearStatePath?: string }. Value can contain {"$state":"/path"} refs and "$id" for auto IDs.`},{name:`removeState`,description:`Remove an item from an array in state by index. Params: { statePath: string, index: number }`},{name:`validateForm`,description:`Validate all registered form fields and write the result to state. Params: { statePath?: string }. Defaults to /formValidation. Result: { valid: boolean, errors: Record<string, string[]> }.`}],defaultRules:[`CRITICAL INTEGRITY CHECK: Before outputting ANY element that references children, you MUST have already output (or will output) each child as its own element. If an element has children: ['a', 'b'], then elements 'a' and 'b' MUST exist. A missing child element causes that entire branch of the UI to be invisible.`,`SELF-CHECK: After generating all elements, mentally walk the tree from root. Every key in every children array must resolve to a defined element. If you find a gap, output the missing element immediately.`,`REQUIRED FIELDS: Every element MUST include a "children" array. Leaf elements (text, badges, inputs, images) use an empty array: "children": []. Omitting "children" fails validation.`,`NAMED SLOTS: Use "children" for the default slot. For other slots declared by the component, use a top-level "slots" object that maps each slot name to child element keys, for example {"slots":{"header":["heading"],"footer":["actions"]}}. Never use "slots.default". Every referenced key must exist.`,`FILTERED LISTS: To render only the items matching a field value (kanban columns, tabbed lists, status sections), put "repeat" and a "visible" condition with $item on the same container element: {"repeat": {"statePath": "/tasks", "key": "id"}, "visible": {"$item": "status", "eq": "todo"}} renders one child per matching item. A visible condition object must use exactly one of $state, $item, or $index — never combine them in one object.`,`CRITICAL: The "visible" field goes on the ELEMENT object, NOT inside "props". Correct: {"type":"<ComponentName>","props":{},"visible":{"$state":"/tab","eq":"home"},"children":[...]}.`,`CRITICAL: The "on" field goes on the ELEMENT object, NOT inside "props". Use on.press, on.change, on.submit etc. NEVER put action/actionParams inside props.`,`When the user asks for a UI that displays data (e.g. blog posts, products, users), ALWAYS include a state field with realistic sample data. The state field is a top-level field on the spec (sibling of root/elements).`,`When building repeating content backed by a state array (e.g. posts, products, items), use the "repeat" field on a container element. Example: { "type": "<ContainerComponent>", "props": {}, "repeat": { "statePath": "/posts", "key": "id" }, "children": ["post-card"] }. For a nested list stored on the enclosing item, use "repeat": { "statePath": { "$item": "comments" }, "key": "id" }. The $item statePath form is valid only inside another repeat. Replace <ContainerComponent> with an appropriate component from the AVAILABLE COMPONENTS list. Inside repeated children, use { "$item": "field" } to read a field from the current item, and { "$index": true } for the current array index. For two-way binding to an item field use { "$bindItem": "completed" }. Do NOT hardcode individual elements for each array item.`,`Design with visual hierarchy: use container components to group content, heading components for section titles, proper spacing, and status indicators. ONLY use components from the AVAILABLE COMPONENTS list.`,`For data-rich UIs, use multi-column layout components if available. For forms and single-column content, use vertical layout components. ONLY use components from the AVAILABLE COMPONENTS list.`,`Always include realistic, professional-looking sample data. For blogs include 3-4 posts with varied titles, authors, dates, categories. For products include names, prices, images. Never leave data empty.`]});var H=e(r(),1),ut=(0,V.createContext)(null);function dt(e,t){return e?null:Object.keys(t).length===0?{}:Qe(t)}function ft({store:e,initialState:t={},onStateChange:n,children:r}){let i=(0,V.useRef)(void 0);!e&&!i.current&&(i.current=Pe(t));let a=e??i.current,o=(0,V.useRef)(a);o.current=a;let s=(0,V.useRef)(!!e);s.current=!!e,(0,V.useRef)(e?`controlled`:`uncontrolled`),(0,V.useRef)(!1);let c=(0,V.useRef)(t),l=(0,V.useRef)(dt(!!e,t));(0,V.useEffect)(()=>{if(e||t===c.current)return;c.current=t;let n=t&&Object.keys(t).length>0?Qe(t):{},r=l.current??{},i=new Set([...Object.keys(r),...Object.keys(n)]),o={};for(let e of i)r[e]!==n[e]&&(o[e]=e in n?n[e]:void 0);l.current=n,Object.keys(o).length>0&&a.update(o)},[e,t,a]);let u=(0,V.useSyncExternalStore)(a.subscribe,a.getSnapshot,a.getServerSnapshot??a.getSnapshot),d=(0,V.useRef)(n);d.current=n;let f=(0,V.useCallback)((e,t)=>{let n=o.current,r=n.getSnapshot();n.set(e,t),!s.current&&n.getSnapshot()!==r&&d.current?.([{path:e,value:t}])},[]),p=(0,V.useCallback)(e=>{let t=o.current,n=t.getSnapshot();if(t.update(e),!s.current&&t.getSnapshot()!==n){let t=[];for(let[r,i]of Object.entries(e))B(n,r)!==i&&t.push({path:r,value:i});t.length>0&&d.current?.(t)}},[]),m=(0,V.useCallback)(e=>o.current.get(e),[]),h=(0,V.useCallback)(()=>o.current.getSnapshot(),[]),g=(0,V.useMemo)(()=>({state:u,get:m,set:f,update:p,getSnapshot:h}),[u,m,f,p,h]);return(0,H.jsx)(ut.Provider,{value:g,children:r})}function U(){let e=(0,V.useContext)(ut);if(!e)throw Error(`useStateStore must be used within a StateProvider`);return e}function pt(e){let{state:t}=U();return B(t,e)}var mt=(0,V.createContext)(null);function ht({children:e}){let{state:t}=U(),n=(0,V.useMemo)(()=>({stateModel:t}),[t]),r=(0,V.useMemo)(()=>e=>He(e,n),[n]),i=(0,V.useMemo)(()=>({isVisible:r,ctx:n}),[r,n]);return(0,H.jsx)(mt.Provider,{value:i,children:e})}function gt(){let e=(0,V.useContext)(mt);if(!e)throw Error(`useVisibility must be used within a VisibilityProvider`);return e}var _t=(0,V.createContext)(null),vt={};function yt(e,t){if(e===t)return!0;if(!e||!t)return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n){let n=e[r],i=t[r];if(n!==i){if(typeof n==`object`&&n&&typeof i==`object`&&i){let e=n.$state,t=i.$state;if(typeof e==`string`&&e===t)continue}return!1}}return!0}function bt(e,t){if(e===t)return!0;if(e.validateOn!==t.validateOn)return!1;let n=e.checks??[],r=t.checks??[];if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++){let t=n[e],i=r[e];if(t.type!==i.type||t.message!==i.message||!yt(t.args,i.args))return!1}return!0}function xt({customFunctions:e=vt,children:t}){let{state:n,getSnapshot:r}=U(),[i,a]=(0,V.useState)({}),o=(0,V.useRef)({}),[s,c]=(0,V.useState)({}),l=(0,V.useCallback)((e,t)=>{c(n=>{let r=n[e];return r&&bt(r,t)?n:{...n,[e]:t}})},[]),u=(0,V.useCallback)((t,n)=>{let i=r(),s=t.split(`/`).filter(Boolean),c=i;for(let e of s)if(typeof c==`object`&&c)c=c[e];else{c=void 0;break}let l=We(n,{value:c,stateModel:i,customFunctions:e}),u={touched:o.current[t]?.touched??!0,validated:!0,result:l};return o.current={...o.current,[t]:u},a(o.current),l},[e,r]),d=(0,V.useCallback)(e=>{o.current={...o.current,[e]:{...o.current[e],touched:!0,validated:o.current[e]?.validated??!1,result:o.current[e]?.result??null}},a(o.current)},[]),f=(0,V.useCallback)(e=>{let{[e]:t,...n}=o.current;o.current=n,a(n)},[]),p=(0,V.useCallback)(()=>{let e=!0;for(let[t,n]of Object.entries(s))u(t,n).valid||(e=!1);return e},[s,u]),m=(0,V.useMemo)(()=>({customFunctions:e,get fieldStates(){return o.current},validate:u,touch:d,clear:f,validateAll:p,registerField:l}),[e,i,u,d,f,p,l]);return(0,H.jsx)(_t.Provider,{value:m,children:t})}function St(){return(0,V.useContext)(_t)}var Ct=0;function wt(){return Ct+=1,`${Date.now()}-${Ct}`}function Tt(e,t){if(e==null)return e;if(e===`$id`)return wt();if(typeof e==`object`&&!Array.isArray(e)){let n=e,r=Object.keys(n);if(r.length===1&&typeof n.$state==`string`)return t(n.$state);if(r.length===1&&`$id`in n)return wt()}if(Array.isArray(e))return e.map(e=>Tt(e,t));if(typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=Tt(i,t);return n}return e}var Et=(0,V.createContext)(null);function Dt({handlers:e={},navigate:t,children:n}){let{get:r,set:i,getSnapshot:a}=U(),o=St(),[s,c]=(0,V.useState)(e),[l,u]=(0,V.useState)(new Set),[d,f]=(0,V.useState)(null),p=(0,V.useCallback)((e,t)=>{c(n=>({...n,[e]:t}))},[]),m=(0,V.useCallback)(async e=>{let n=Ze(e,a()),c=Ye(),l=Date.now();Le({id:c,name:n.action,params:n.params,at:l});let d=!0,p;try{if(n.action===`setState`&&n.params){let e=n.params.statePath,t=n.params.value;e&&i(e,t);return}if(n.action===`pushState`&&n.params){let e=n.params.statePath,t=n.params.value;if(e){let a=Tt(t,r),o=r(e)??[];i(e,[...o,a]);let s=n.params.clearStatePath;s&&i(s,``)}return}if(n.action===`removeState`&&n.params){let e=n.params.statePath,t=n.params.index;if(e!==void 0&&t!==void 0){let n=r(e)??[];i(e,n.filter((e,n)=>n!==t))}return}if(n.action===`push`&&n.params){let e=n.params.screen;if(e){let t=r(`/currentScreen`),n=r(`/navStack`)??[];t?i(`/navStack`,[...n,t]):i(`/navStack`,[...n,``]),i(`/currentScreen`,e)}return}if(n.action===`pop`){let e=r(`/navStack`)??[];if(e.length>0){let t=e[e.length-1];i(`/navStack`,e.slice(0,-1)),t?i(`/currentScreen`,t):i(`/currentScreen`,void 0)}return}if(n.action===`validateForm`){let e=o?.validateAll;if(!e){console.warn(`validateForm action was dispatched but no ValidationProvider is connected. Ensure ValidationProvider is rendered inside the provider tree.`);return}let t=e(),r={};for(let[e,t]of Object.entries(o.fieldStates))t.result&&!t.result.valid&&(r[e]=t.result.errors);let a=n.params?.statePath||`/formValidation`;i(a,{valid:t,errors:r});return}let e=s[n.action];if(!e){console.warn(`No handler registered for action: ${n.action}`);return}if(n.confirm)return new Promise((t,r)=>{f({action:n,handler:e,resolve:()=>{f(null),t()},reject:()=>{f(null),r(Error(`Action cancelled`))}})}).then(async()=>{u(e=>new Set(e).add(n.action));try{await Fe({action:n,handler:e,setState:i,navigate:t,executeAction:async e=>{await m(e)}})}finally{u(e=>{let t=new Set(e);return t.delete(n.action),t})}});u(e=>new Set(e).add(n.action));try{await Fe({action:n,handler:e,setState:i,navigate:t,executeAction:async e=>{await m(e)}})}finally{u(e=>{let t=new Set(e);return t.delete(n.action),t})}}catch(e){throw d=!1,p=e,e}finally{let e=Date.now();Ue({id:c,name:n.action,ok:d,at:e,durationMs:e-l,error:p})}},[s,r,i,a,t,o]),h=(0,V.useCallback)(()=>{d?.resolve()},[d]),g=(0,V.useCallback)(()=>{d?.reject()},[d]),_=(0,V.useMemo)(()=>({handlers:s,loadingActions:l,pendingConfirmation:d,execute:m,confirm:h,cancel:g,registerHandler:p}),[s,l,d,m,h,g,p]);return(0,H.jsx)(Et.Provider,{value:_,children:n})}function W(){let e=(0,V.useContext)(Et);if(!e)throw Error(`useActions must be used within an ActionProvider`);return e}function Ot({confirm:e,onConfirm:t,onCancel:n}){let r=e.variant===`danger`;return(0,H.jsx)(`div`,{style:{position:`fixed`,inset:0,backgroundColor:`rgba(0, 0, 0, 0.5)`,display:`flex`,alignItems:`center`,justifyContent:`center`,zIndex:50},onClick:n,children:(0,H.jsxs)(`div`,{style:{backgroundColor:`white`,borderRadius:`8px`,padding:`24px`,maxWidth:`400px`,width:`100%`,boxShadow:`0 20px 25px -5px rgba(0, 0, 0, 0.1)`},onClick:e=>e.stopPropagation(),children:[(0,H.jsx)(`h3`,{style:{margin:`0 0 8px 0`,fontSize:`18px`,fontWeight:600},children:e.title}),(0,H.jsx)(`p`,{style:{margin:`0 0 24px 0`,color:`#6b7280`},children:e.message}),(0,H.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,justifyContent:`flex-end`},children:[(0,H.jsx)(`button`,{onClick:n,style:{padding:`8px 16px`,borderRadius:`6px`,border:`1px solid #d1d5db`,backgroundColor:`white`,cursor:`pointer`},children:e.cancelLabel??`Cancel`}),(0,H.jsx)(`button`,{onClick:t,style:{padding:`8px 16px`,borderRadius:`6px`,border:`none`,backgroundColor:r?`#dc2626`:`#3b82f6`,color:`white`,cursor:`pointer`},children:e.confirmLabel??`Confirm`})]})]})})}var kt=(0,V.createContext)(null);function At({item:e,index:t,basePath:n,children:r}){return(0,H.jsx)(kt.Provider,{value:{item:e,index:t,basePath:n},children:r})}function jt(){return(0,V.useContext)(kt)}var Mt=new WeakMap,Nt={},Pt=class extends V.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(e,t){console.error(`[json-render] Rendering error in <${this.props.elementType}>:`,e,t.componentStack)}componentDidUpdate(e){this.state.hasError&&e.resetKey!==this.props.resetKey&&this.setState({hasError:!1})}render(){return this.state.hasError?null:this.props.children}},Ft={},It=V.createContext(Ft);function Lt(){return V.useContext(It)}var Rt=V.createContext(void 0);function zt(){return V.useContext(Rt)}function Bt(e,t){let n=t.current;if(n===e)return n;if(n&&e){let t=Object.keys(e);if(t.length===Object.keys(n).length&&t.every(t=>Object.prototype.hasOwnProperty.call(n,t)&&n[t]===e[t]))return n}return t.current=e,e}function Vt(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Ht(e,t){if(Object.is(e,t))return!0;let n=Array.isArray(e);if(n!==Array.isArray(t)||!n&&(e===null||t===null||typeof e!=`object`||typeof t!=`object`))return!1;let r=e,i=t,a=Object.keys(i);return n&&e.length!==t.length||a.length!==Object.keys(r).length?!1:a.every(e=>Object.prototype.hasOwnProperty.call(r,e)&&Ht(r[e],i[e]))}function Ut(e){if(typeof e!=`object`||!e)return e;let t=Array.isArray(e)?Array(e.length):{};for(let n of Object.keys(e))t[n]=Ut(e[n]);return t}function Wt(e,t){if(Object.is(e,t))return e;let n=Array.isArray(e);if(n!==Array.isArray(t)||!n&&(!Vt(e)||!Vt(t)))return t;let r=e,i=t,a=Object.keys(i),o=n?Array(t.length):{},s=(!n||e.length===t.length)&&a.length===Object.keys(r).length;for(let e of a){let t=i[e];Object.prototype.hasOwnProperty.call(r,e)?(t=Wt(r[e],t),Object.is(r[e],t)||(s=!1)):s=!1,o[e]=t}return s?e:o}function Gt(e){let t=(0,V.useRef)({}),n=(0,V.useRef)(0);if(!e)return{};let r=t.current,i={},a={},o=new Set;for(let t of Object.keys(e.elements)){if(a[t]!==void 0)continue;let s=e.elements[t];if(!s)continue;o.add(t);let c=[{key:t,element:s,children:[...s.children??[],...Object.values(s.slots??{}).flat()],childIndex:0,childVersions:[]}];for(;c.length>0;){let t=c[c.length-1],s=t.children[t.childIndex];if(s!==void 0){let n=a[s];if(n!==void 0){t.childVersions.push([s,n]),t.childIndex+=1;continue}let r=e.elements[s];if(!r||o.has(s)){t.childVersions.push([s,-1]),t.childIndex+=1;continue}o.add(s),c.push({key:s,element:r,children:[...r.children??[],...Object.values(r.slots??{}).flat()],childIndex:0,childVersions:[]});continue}let l=r[t.key],u=l&&Ht(l.own,t.element)&&Ht(l.children,t.childVersions)?l.version:++n.current;o.delete(t.key),i[t.key]={own:Ut(t.element),children:t.childVersions,version:u},a[t.key]=u,c.pop()}}return t.current=i,a}var Kt=V.memo(function({Component:e,element:t,slots:n,emit:r,on:i,bindings:a,loading:o,children:s}){return(0,H.jsx)(e,{element:t,slots:n,emit:r,on:i,bindings:a,loading:o,children:s})},(e,t)=>e.Component===t.Component&&e.signature===t.signature&&e.execute===t.execute&&e.actionContext?.item===t.actionContext?.item&&e.actionContext?.index===t.actionContext?.index&&e.actionContext?.basePath===t.actionContext?.basePath&&e.functions===t.functions&&e.directives===t.directives&&e.element.props===t.element.props&&e.bindings===t.bindings&&e.loading===t.loading);function qt(){return V.useSyncExternalStore(Be,Ke,()=>!1)}function Jt({element:e,elementKey:t,spec:n,registry:r,loading:i,fallback:a,signatures:o}){let s=qt(),c=jt(),{ctx:l}=gt(),{execute:u}=W(),{getSnapshot:d,state:f}=U(),p=Lt(),m=zt(),h=(0,V.useMemo)(()=>{let e=c?{...l,repeatItem:c.item,repeatIndex:c.index,repeatBasePath:c.basePath}:{...l};return e.functions=p,e.directives=m,e},[l,c,p,m]),g=e.repeat!==void 0&&c==null?Ve(e.visible):{container:e.visible,itemFilter:void 0},_=g.itemFilter,v=g.container===void 0||He(g.container,h),y=e.on,b=(0,V.useCallback)(async e=>{let t=y?.[e];if(!t)return;let n=Array.isArray(t)?t:[t];for(let e of n){if(!e.params){await u(e);continue}let t={...h,stateModel:d()},n={};for(let[r,i]of Object.entries(e.params))n[r]=Re(i,t);await u({...e,params:n})}},[y,u,h,d]),x=(0,V.useCallback)(e=>{let t=y?.[e];return t?{emit:()=>b(e),shouldPreventDefault:(Array.isArray(t)?t:[t]).some(e=>e.preventDefault),bound:!0}:{emit:()=>{},shouldPreventDefault:!1,bound:!1}},[y,b]),S=e.watch,C=(0,V.useRef)(null),w=(0,V.useRef)(void 0),T=(0,V.useRef)(void 0),E=(0,V.useRef)({}),D=(0,V.useMemo)(()=>{if(!S)return;let e={};for(let t of Object.keys(S))e[t]=B(f,t);let t=w.current;if(t){let n=Object.keys(e);if(n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n]))return t}return w.current=e,e},[S,f]);if((0,V.useEffect)(()=>{if(!S||!D)return;let e=Object.keys(S);if(e.length===0)return;let t=C.current;if(C.current=D,t===null)return;let n=!1;return(async()=>{for(let r of e){if(n)break;if(D[r]!==t[r]){let e=S[r];if(!e)continue;let t=Array.isArray(e)?e:[e];for(let e of t){if(n)break;if(!e.params){if(await u(e),n)break;continue}let t={...h,stateModel:d()},r={};for(let[n,i]of Object.entries(e.params))r[n]=Re(i,t);if(await u({...e,params:r}),n)break}}}})().catch(console.error),()=>{n=!0}},[S,D,u,h,d]),!v)return null;let O=e.props??Nt,ee=Bt(ze(O,h),T),k=Wt(E.current,qe(O,h));E.current=k;let A=k===e.props?e:{...e,props:k},j=r[A.type]??a;if(!j)return console.warn(`No renderer for component type: ${A.type}`),null;let M=Mt.get(r)?.[A.type];if(A.slots&&M?.slots){let e=new Set(M.slots);for(let t of Object.keys(A.slots))t==="default"?console.warn(`[json-render] Component "${A.type}" uses slots.default. Use "children" for default slot content.`):e.has(t)||console.warn(`[json-render] Unknown slot "${t}" on component "${A.type}". Available slots: ${M.slots.join(`, `)}`)}let te=(e,t)=>e.map(e=>{let s=n.elements[e];if(!s){if(!i){let n=t?`in slot "${t}" of "${A.type}"`:`as child of "${A.type}"`;console.warn(`[json-render] Missing element "${e}" referenced ${n}. This element will not render.`)}return null}return(0,H.jsx)(Yt,{element:s,elementKey:e,spec:n,registry:r,loading:i,fallback:a,signatures:o},e)}),ne=A.repeat?(0,H.jsx)(Xt,{element:A,spec:n,registry:r,loading:i,fallback:a,itemFilter:_,signatures:o}):A.children?te(A.children):void 0,re=A.slots?Object.fromEntries(Object.entries(A.slots).map(([e,t])=>[e,te(t,e)])):void 0,ie=(0,H.jsx)(Kt,{Component:j,signature:o[t??``],execute:u,actionContext:c,functions:p,directives:m,element:A,slots:re,emit:b,on:x,bindings:ee,loading:i,children:ne}),ae=s&&t?(0,H.jsx)(`span`,{"data-jr-key":t,style:{display:`contents`},children:ie}):ie;return(0,H.jsx)(Pt,{elementType:A.type,resetKey:o[t??``],children:ae})}var Yt=V.memo(function(e){return(0,H.jsx)(Jt,{...e})},(e,t)=>e.elementKey===t.elementKey&&e.signatures[e.elementKey??``]===t.signatures[t.elementKey??``]&&e.registry===t.registry&&e.loading===t.loading&&e.fallback===t.fallback);function Xt({element:e,spec:t,registry:n,loading:r,fallback:i,signatures:a,itemFilter:o}){let{state:s}=U(),{ctx:c}=gt(),l=jt(),u=e.repeat,d=tt(u.statePath,l?.basePath);if(d===void 0)return console.warn(`[json-render] $item in repeat.statePath used outside of a repeat scope`),null;let f=(B(s,d)??[]).map((e,t)=>({itemValue:e,index:t})).filter(({itemValue:e,index:t})=>o===void 0||He(o,{...c,repeatItem:e,repeatIndex:t}));return(0,H.jsx)(H.Fragment,{children:f.map(({itemValue:o,index:s})=>{let c=u.key&&typeof o==`object`&&o?String(o[u.key]??s):String(s);return(0,H.jsx)(At,{item:o,index:s,basePath:Ie(d,s),children:e.children?.map(o=>{let s=t.elements[o];return s?(0,H.jsx)(Yt,{element:s,elementKey:o,spec:t,registry:n,loading:r,fallback:i,signatures:a},o):(r||console.warn(`[json-render] Missing element "${o}" referenced as child of "${e.type}" (repeat). This element will not render.`),null)})},c)})})}function Zt({spec:e,registry:t,loading:n,fallback:r}){let i=Gt(e);if(!e||!e.root)return null;let a=e.elements[e.root];return a?(0,H.jsx)(Yt,{element:a,elementKey:e.root,spec:e,registry:t,loading:n,fallback:r,signatures:i}):null}function Qt({registry:e,store:t,initialState:n,handlers:r,navigate:i,validationFunctions:a,functions:o,directives:s,onStateChange:c,children:l}){let u=(0,V.useMemo)(()=>s?Ge(s):void 0,[s]);return(0,H.jsx)(ft,{store:t,initialState:n,onStateChange:c,children:(0,H.jsx)(ht,{children:(0,H.jsx)(xt,{customFunctions:a,children:(0,H.jsx)(Dt,{handlers:r,navigate:i,children:(0,H.jsx)(It.Provider,{value:o??Ft,children:(0,H.jsxs)(Rt.Provider,{value:u,children:[l,(0,H.jsx)($t,{})]})})})})})})}function $t(){let{pendingConfirmation:e,confirm:t,cancel:n}=W();return e?.action.confirm?(0,H.jsx)(Ot,{confirm:e.action.confirm,onConfirm:t,onCancel:n}):null}function en(e,t){let{set:n}=U();return[e,(0,V.useCallback)(e=>{t&&n(t,e)},[t,n])]}var tn=`/_drill`;function nn(e){return`${tn}/${e}`}var rn=et({dimension:Ee(),value:Ee(),into:Ee(),metric:Ee(),period:ke.optional()});function an(e,t){if(!e)return null;let n=e.endsWith(`/`)?e.slice(0,-1):e;if(t.startsWith(`/`))return t===n||t.startsWith(`${n}/`)?t:null;let r=t.replaceAll(`\\`,`/`).split(`/`).filter(e=>e!==``&&e!==`.`);return r.some(e=>e===`..`)?null:`${n}/${r.join(`/`)}`}function G(e,t){e.view.getState().showNotice(t)}function on(e,t){if(!e.host().sendToAgent){G(e,`Asking the agent is not available in this view`);return}e.view.getState().proposeAgentMessage({headline:t.headline,message:Se(t)})}async function sn(e,t,n){if(t.source===`inline`){let e=Ce(t,t.rows,n);return e.ok?e.result:null}if(!e.queryDataset)return null;let r=await e.queryDataset(t,n,!1);return r.status===`ok`?r.result:null}async function cn(e,t,n){let r=e.host(),i={title:e.spec.title};switch(t){case`setState`:case`pushState`:case`removeState`:return;case`file.open`:{let t=P[`file.open`].params.safeParse(n);if(!t.success)return G(e,`That file link is malformed`);let i=an(r.workspaceRoot,t.data.path);if(!i)return G(e,`"${t.data.path}" is outside this chat's workspace`);e.view.getState().openPreview(i);return}case`link.open`:{let t=P[`link.open`].params.safeParse(n);if(!t.success)return G(e,`Only https links can be opened`);r.openLink(t.data.url);return}case`dataset.refresh`:{let t=P[`dataset.refresh`].params.safeParse(n);t.success&&e.view.getState().refreshDataset(t.data.dataset);return}case`financial.drilldown`:{let t=P[`financial.drilldown`].params.safeParse(n);if(!t.success)return G(e,`That drilldown is malformed`);let{dataset:r,...i}=t.data;e.state.set(nn(r),i);return}case`agent.ask`:{let t=P[`agent.ask`].params.safeParse(n);return t.success?on(e,je(`agent.ask`,t.data.prompt,t.data.context,i)):G(e,`That question is malformed`)}case`agent.investigate`:case`agent.fix`:{let r=P[t].params.safeParse(n);return r.success?on(e,je(t,r.data.subject,r.data.context,i)):G(e,`That request is malformed`)}case`financial.explainVariance`:{let t=P[`financial.explainVariance`].params.safeParse(n);if(!t.success)return G(e,`That explanation request is malformed`);let a=e.spec.datasets?.[t.data.dataset];if(!a)return G(e,`Unknown dataset "${t.data.dataset}"`);let o=t.data.compareWith??`previous-period`,s=await sn(r,a,{metrics:[t.data.metric],...t.data.period?{period:t.data.period}:{},...t.data.filters?{filters:t.data.filters}:{},compare:o});return on(e,$e({datasetId:t.data.dataset,decl:a,metric:t.data.metric,...t.data.period?{period:t.data.period}:{},compareWith:o,...t.data.filters?{filters:t.data.filters}:{},...t.data.question?{question:t.data.question}:{},result:s},i))}}}function ln(e){let t={};for(let n of Object.keys(P))De(n)&&P[n].class!==`local`&&(t[n]=async t=>{if(e.host().readonly)return;let r=Me.safeParse(t);if(!r.success)return G(e,`That action's parameters are not plain data`);await cn(e,n,r.data)});return t}var un=`_kannaKey`,dn=`/_ui`;function fn(e){let t=e.props[un];return typeof t==`string`?t:e.type}function K(e,t,n,r){let i=`${dn}/${fn(e)}/${t}`,a=pt(i),{set:o}=U(),s=(0,V.useCallback)(e=>o(i,e),[i,o]);return[r(a)?a:n,s]}function pn(e){return typeof e==`string`}function mn(e){return typeof e==`boolean`}function hn(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}function gn(e){if(!be(e))return!1;let t=e.value;return t===`all`||t===``||t==null?!1:ye(t)?t.length>0:typeof t==`string`||typeof t==`number`}function q(e){let t=Me.safeParse(_n(e));if(!t.success)return null;let n=t.data.filters;return ye(n)?{...t.data,filters:n.filter(gn)}:t.data}function _n(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`_kannaKey`&&t!=null))}function J(e){return e===`none`?void 0:e}function Y(e,t){return t?[...e??[],{dimension:t.dimension,value:t.value}]:e?[...e]:void 0}var vn=(0,V.lazy)(()=>n(()=>import(`./VChartSurface-CUbxyBo3.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]))),yn={sm:200,md:260,lg:340};function bn(e){return e===`chart`||e===`table`}var xn=60;function Sn(e){let t=q(e);if(!t)return null;let n=R.FinancialChart.props.safeParse(t);return n.success?n.data:null}function Cn(e){let t=pt(nn(e??``));return(0,V.useMemo)(()=>{if(!e||!t)return null;let n=rn.safeParse(t);return n.success?n.data:null},[e,t])}function wn(e,t){let n=Array.isArray(e.metric)?e.metric:[e.metric],r=t?t.into:e.dimension,i=t?.period??e.period,a=e.chart===`waterfall`||e.chart===`composition`||t?void 0:J(e.compareWith),o=Y(e.filters,t);return{metrics:e.secondaryMetric?[...n,e.secondaryMetric]:n,groupBy:e.series&&!t?[r,e.series]:[r],...i?{period:i}:{},...a?{compare:a}:{},...o&&o.length>0?{filters:o}:{},...e.chart===`waterfall`?{sort:{by:r,direction:`asc`}}:{},limit:e.limit??xn}}function Tn(e,t){return t?e.chart===`composition`?`composition`:`bar`:e.chart}function En({x:e,label:t,drill:n}){return n?(0,H.jsx)(`button`,{type:`button`,className:`rounded-sm text-left text-foreground underline decoration-border underline-offset-4 hover:decoration-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"aria-label":`Break down ${t} by ${n.intoLabel}`,disabled:n.pending,onClick:()=>n.onDrill({x:e,series:``}),children:t}):(0,H.jsx)(H.Fragment,{children:t})}function Dn({model:e,drill:t}){let n=e.series.filter(t=>e.points.some(e=>e.series===t.id)),r=(t,n)=>e.points.find(e=>e.x===t&&e.series===n)?.value??null;return(0,H.jsx)(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border`,children:(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-left text-xs font-medium text-muted-foreground`,children:e.dimensionLabel}),n.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:`px-3 py-2 text-right text-xs font-medium text-muted-foreground`,children:e.label},e.id))]})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:e.xOrder.map(i=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-normal text-foreground`,children:(0,H.jsx)(En,{x:i,label:e.xLabels[i]??i,drill:On(e,i)?t:null})}),n.map(t=>(0,H.jsx)(`td`,{className:`px-3 py-1.5 text-right tabular-nums text-foreground`,children:L(r(i,t.id),e.format)},t.id))]},i))})]})})}function On(e,t){return at(e,{x:t})!==null}function kn({model:e,height:t,onPointClick:n}){let r=N().ChartRenderer??vn,i=`${e.valueLabel} by ${e.dimensionLabel.toLowerCase()}, ${e.points.length} values. Switch to Table to read them${n?` or break a value down`:``}.`;return(0,H.jsx)(V.Suspense,{fallback:(0,H.jsx)(`div`,{className:`w-full`,style:{height:t},"aria-hidden":`true`}),children:(0,H.jsx)(r,{model:e,height:t,label:i,onPointClick:n})})}function An({props:e,drill:t}){let{execute:n}=W(),{viewKey:r}=b(),i=N(),a=p(`genui.financial.explainVariance`,r,e.dataset),o=d(a),c=Array.isArray(e.metric)?e.metric[0]??``:e.metric,l=(0,V.useCallback)(()=>{let r=Y(e.filters,t),i=t?.period??e.period;u(a,()=>n({action:`financial.explainVariance`,params:{dataset:e.dataset,metric:c,compareWith:J(e.compareWith)??`previous-period`,...i?{period:i}:{},...r&&r.length>0?{filters:r.map(e=>({...e}))}:{}}}))},[t,n,a,c,e]);return i.readonly||!i.sendToAgent?null:(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,className:`gap-1.5`,pending:o,onClick:l,children:[o?null:(0,H.jsx)(lt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Explain variance`]})}function jn(e,t,n,r){return e===`back`&&t?n:e===`figure`&&!t?r:null}function Mn({datasetId:e,drill:t,decl:n,backRef:r,focusAfterRef:i}){let{execute:a}=W(),{viewKey:o}=b(),c=p(`genui.drill.back`,o,e),l=d(c),f=(0,V.useCallback)(()=>{i.current=`figure`,u(c,()=>a({action:`setState`,params:{statePath:nn(e),value:null}}))},[e,a,i,c]);return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,H.jsxs)(s,{ref:r,size:`sm`,variant:`ghost`,className:`gap-1`,onClick:f,pending:l,children:[l?null:(0,H.jsx)(le,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Back`]}),(0,H.jsxs)(`span`,{children:[F(t.dimension,n.dimensions?.[t.dimension]),`: `,(0,H.jsx)(`span`,{className:`text-foreground`,children:Nn(t,n)}),` `,`by `,F(t.into,n.dimensions?.[t.into]).toLowerCase()]})]})}function Nn(e,t){let n=t.dimensions?.[e.dimension];return n?.kind===`time`?we(e.value,n.grain??`month`):e.value}function Pn(e,t,n,r){let i=t?t.period.label:Ae(e.period);if(n)return r?.dimensions?.[n.dimension]?.kind===`time`?Nn(n,r):i;let a=J(e.compareWith),o=t?.comparison?.label??(a?Te(a):null);return o?`${i} · vs ${o.charAt(0).toLowerCase()}${o.slice(1)}`:i}function Fn({element:e}){let t=(0,V.useMemo)(()=>Sn(e.props),[e.props]),n=y(t?.dataset),r=Cn(t?.drilldown?t.dataset:void 0),i=(0,V.useMemo)(()=>t?wn(t,r):null,[t,r]),a=E(t?.dataset,i),[o,s]=K(e,`view`,`chart`,bn),{execute:l}=W(),{viewKey:f}=b(),m=p(`genui.financial.drilldown`,f,t?.dataset??``),g=(0,V.useId)(),_=(0,V.useRef)(null),v=(0,V.useRef)(null),x=(0,V.useRef)(null),S=d(m),C=(0,V.useMemo)(()=>{if(!t||!n||a.status!==`ok`)return null;let e=Array.isArray(t.metric)?t.metric:[t.metric];return it({chart:Tn(t,r),metrics:e,...t.secondaryMetric?{secondaryMetric:t.secondaryMetric}:{},dimension:r?r.into:t.dimension,...t.series&&!r?{series:t.series}:{},...t.totalLabel?{totalLabel:t.totalLabel}:{}},n,a.result)},[n,r,t,a]),w=t?.drilldown,D=(0,V.useCallback)(e=>{if(!t||!w||r)return;let n=Array.isArray(t.metric)?t.metric[0]??``:t.metric;u(m,()=>l({action:`financial.drilldown`,params:{dataset:t.dataset,metric:n,dimension:t.dimension,value:e.x,into:w.dimension,...t.period?{period:t.period}:{}}}))},[r,m,w,l,t]);(0,V.useEffect)(()=>{let e=jn(x.current,r!==null,v.current,_.current);e&&(x.current=null,e.focus())},[r]);let ee=(0,V.useCallback)(e=>{x.current=`back`,D(e)},[D]);if(!t)return(0,H.jsx)(O,{component:`FinancialChart`});let k=yn[t.height??`md`],A=Array.isArray(t.metric)?t.metric[0]??``:t.metric,j=t.title??I(A,n?.metrics[A]),M=Pn(t,a.status===`ok`?a.result:null,r,n),te=t.drilldown&&!r&&n?{intoLabel:F(t.drilldown.dimension,n.dimensions?.[t.drilldown.dimension]).toLowerCase(),pending:S,onDrill:ee}:null;return(0,H.jsxs)(`figure`,{ref:_,tabIndex:-1,className:`flex min-w-0 flex-col gap-2 rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-labelledby":g,children:[(0,H.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{id:g,className:`text-sm font-medium text-foreground`,children:j}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:M})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t.explain?(0,H.jsx)(An,{props:t,drill:r}):null,(0,H.jsx)(ve,{size:`sm`,value:o,onValueChange:s,options:[{value:`chart`,label:`Chart`},{value:`table`,label:`Table`}]})]})]}),r&&n?(0,H.jsx)(Mn,{datasetId:t.dataset,drill:r,decl:n,backRef:v,focusAfterRef:x}):null,a.status===`ok`?null:(0,H.jsx)(h,{state:a,minHeight:k}),a.status===`ok`&&C&&!C.ok?(0,H.jsx)(T,{label:C.message,minHeight:k}):null,a.status===`ok`&&C?.ok&&C.model.points.length===0?(0,H.jsx)(T,{label:`No data for the selected period`,minHeight:k}):null,a.status===`ok`&&C?.ok&&C.model.points.length>0?(0,H.jsxs)(`div`,{className:c(`transition-opacity duration-[var(--motion-quick)]`,(a.refreshing||S)&&`opacity-60`),"aria-busy":S||void 0,children:[o===`chart`?(0,H.jsx)(kn,{model:C.model,height:k,onPointClick:t.drilldown&&!r?D:null}):(0,H.jsx)(Dn,{model:C.model,drill:te}),a.result.truncated?(0,H.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Showing the first `,a.result.rows.length,` groups.`]}):null]}):null]})}var In=50,X=`px-3 py-2 text-xs font-medium text-muted-foreground`,Z=`px-3 py-1.5 tabular-nums`;function Ln(e,t){return t?e.dimensions[t]??``:`Total`}function Rn({total:e,onShow:t}){return(0,H.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,onClick:t,children:[`Show all `,e,` rows`]})})}function zn({element:e,config:t,result:n,decl:r}){let[i,a]=K(e,`expanded`,!1,mn),o=t.metrics??(t.metric?[t.metric]:[]),s=i?n.rows:n.rows.slice(0,In);return(0,H.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-left`),children:t.rows?F(t.rows,r.dimensions?.[t.rows]):``}),o.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:I(e,r.metrics[e])},e))]})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:s.map(e=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Ln(e,t.rows)}),o.map(t=>(0,H.jsx)(`td`,{className:c(Z,`text-right text-foreground`),children:L(e.values[t]??null,z(r.metrics[t]))},t))]},e.key))})]}),!i&&n.rows.length>In?(0,H.jsx)(Rn,{total:n.rows.length,onShow:()=>a(!0)}):null]})}function Bn({value:e,compare:t,format:n,direction:r,accounting:i}){let a=xe(e,t,n,r),o=v(k(a.sentiment));return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`td`,{className:c(Z,`text-right text-muted-foreground`),children:L(t,n,{accounting:i})}),(0,H.jsx)(`td`,{className:c(Z,`text-right`,o),children:a.amountText}),(0,H.jsx)(`td`,{className:c(Z,`text-right`,o),children:a.ratioText})]})}function Vn(e){return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:e}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:`Change`}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:`Change %`})]})}function Hn({element:e,config:t,result:n,decl:r}){let[i,a]=K(e,`expanded`,!1,mn),o=t.metric??t.metrics?.[0]??``,s=r.metrics[o],l=z(s),u=i?n.rows:n.rows.slice(0,In),d=n.comparison?.label;return(0,H.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-left`),children:t.rows?F(t.rows,r.dimensions?.[t.rows]):``}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:I(o,s)}),d?Vn(d):null]})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:u.map(e=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Ln(e,t.rows)}),(0,H.jsx)(`td`,{className:c(Z,`text-right text-foreground`),children:L(e.values[o]??null,l)}),d?(0,H.jsx)(Bn,{value:e.values[o]??null,compare:e.compare?.[o]??null,format:l,direction:s?.direction,accounting:!1}):null]},e.key))})]}),!i&&n.rows.length>In?(0,H.jsx)(Rn,{total:n.rows.length,onShow:()=>a(!0)}):null]})}function Un(e){let t=e.filter(e=>typeof e==`number`);return t.length===0?null:t.reduce((e,t)=>e+t,0)}function Wn(e,t,n,r=[]){let i=new Map;for(let t of e.rows){let e=n?t.dimensions[n]??``:``,r=i.get(e)??[];r.push(t),i.set(e,r)}let a=e=>r.includes(e)?r.indexOf(e):r.length;return[...i.entries()].sort(([e],[t])=>a(e)-a(t)).map(([e,n])=>({name:e,rows:n,value:Un(n.map(e=>e.values[t])),compare:Un(n.map(e=>e.compare?.[t]))}))}function Gn({element:e,config:t,result:n,decl:r}){let[i,a]=K(e,`collapsed`,[],hn),o=new Set(i),s=t.metric??t.metrics?.[0]??``,l=r.metrics[s],u=z(l),d=n.comparison?.label,f=Wn(n,s,t.groupRows,t.groupRows?r.dimensions?.[t.groupRows]?.order:void 0),p=e=>{a(o.has(e)?i.filter(t=>t!==e):[...i,e])},m=e=>L(e,u,{accounting:!0}),h=(t.totals??[]).map(e=>{let t=f.filter(t=>e.groups.includes(t.name));return{label:e.label,value:Un(t.map(e=>e.value)),compare:Un(t.map(e=>e.compare))}});return(0,H.jsx)(`div`,{className:`max-h-[32rem] overflow-auto rounded-md border border-border`,children:(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-left`),children:t.rows?F(t.rows,r.dimensions?.[t.rows]):``}),(0,H.jsx)(`th`,{scope:`col`,className:c(X,`text-right`),children:n.period.label}),d?Vn(d):null]})}),(0,H.jsxs)(`tbody`,{children:[f.map(e=>{let n=o.has(e.name),r=!!t.groupRows;return(0,H.jsxs)(V.Fragment,{children:[r?(0,H.jsxs)(`tr`,{className:`border-t border-border`,children:[(0,H.jsx)(`th`,{scope:`rowgroup`,className:`sticky left-0 bg-card px-2 py-1.5 text-left font-medium text-foreground`,children:(0,H.jsxs)(`button`,{type:`button`,onClick:()=>p(e.name),"aria-expanded":!n,className:`flex items-center gap-1 rounded px-1 hover:bg-muted`,children:[n?(0,H.jsx)(ue,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,H.jsx)(ce,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e.name]})}),(0,H.jsx)(`td`,{className:c(Z,`text-right font-medium text-foreground`),children:m(e.value)}),d?(0,H.jsx)(Bn,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]}):null,n?null:e.rows.map(e=>(0,H.jsxs)(`tr`,{children:[(0,H.jsx)(`th`,{scope:`row`,className:c(`sticky left-0 bg-card py-1 text-left font-normal text-foreground`,r?`pl-9 pr-3`:`px-3`),children:Ln(e,t.rows)}),(0,H.jsx)(`td`,{className:c(Z,`text-right text-foreground`),children:m(e.values[s]??null)}),d?(0,H.jsx)(Bn,{value:e.values[s]??null,compare:e.compare?.[s]??null,format:u,direction:l?.direction,accounting:!0}):null]},e.key))]},e.name||`_`)}),h.map(e=>(0,H.jsxs)(`tr`,{className:`border-t-2 border-border`,children:[(0,H.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-2 text-left font-semibold text-foreground`,children:e.label}),(0,H.jsx)(`td`,{className:c(Z,`text-right font-semibold text-foreground`),children:m(e.value)}),d?(0,H.jsx)(Bn,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]},e.label))]})]})})}function Kn({element:e,config:t,result:n,decl:r}){if(n.rows.length===0)return(0,H.jsx)(`p`,{className:`rounded-md border border-dashed border-border px-3 py-4 text-center text-sm text-muted-foreground`,children:`No data for the selected period`});switch(t.variant){case`statement`:return(0,H.jsx)(Gn,{element:e,config:t,result:n,decl:r});case`comparison`:return(0,H.jsx)(Hn,{element:e,config:t,result:n,decl:r});case`detail`:return(0,H.jsx)(zn,{element:e,config:t,result:n,decl:r})}}function qn(e){return e.charAt(0).toLowerCase()+e.slice(1)}function Jn(e,t){return t(q(e))}function Yn({element:e}){let t=(0,V.useMemo)(()=>Jn(e.props,e=>{let t=R.FinancialMetric.props.safeParse(e);return t.success?t.data:null}),[e.props]),n=y(t?.dataset),r=Cn(t?.dataset),i=(0,V.useMemo)(()=>{if(!t)return null;let e=J(t.compareWith),n=Y(t.filters,r);return{metrics:[t.metric],...t.period?{period:t.period}:{},...e?{compare:e}:{},...t.scenario?{scenario:t.scenario}:{},...n&&n.length>0?{filters:n}:{}}},[r,t]),a=E(t?.dataset,i);if(!t)return(0,H.jsx)(O,{component:`FinancialMetric`});let o=n?.metrics[t.metric],s=t.label??I(t.metric,o);if(a.status!==`ok`)return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md border border-border p-3`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,H.jsx)(h,{state:a})]});let l=z(o),u=a.result.totals.values[t.metric]??null,d=a.result.totals.compare?.[t.metric]??null,f=xe(u,d,l,o?.direction),p=k(f.sentiment);return(0,H.jsxs)(`div`,{className:c(`flex flex-col gap-1 rounded-md border border-border p-3`,a.refreshing&&`opacity-60`),children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,H.jsx)(`span`,{className:`text-2xl font-semibold leading-tight text-foreground`,children:L(u,l,{compact:!0})}),a.result.comparison&&f.amount!==null?(0,H.jsxs)(`span`,{className:c(`flex flex-wrap items-center gap-1 text-xs`,v(p)),children:[(0,H.jsx)(S,{trend:f.trend}),(0,H.jsx)(`span`,{className:`font-medium tabular-nums`,children:f.ratioText}),(0,H.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,f.amountText,`)`]}),(0,H.jsxs)(`span`,{className:`text-muted-foreground`,children:[`vs `,qn(a.result.comparison.label)]})]}):null,a.result.comparison&&f.amount===null?(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`No `,qn(a.result.comparison.label),` data to compare`]}):null,(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a.result.period.label})]})}var Xn=new Set([`IncomeStatement`,`BalanceSheet`,`CashFlowStatement`]);function Zn(e,t){let n=q(t);if(Xn.has(e)){let e=R.IncomeStatement.props.safeParse(n);return e.success?{variant:`statement`,...e.data}:null}let r=R.FinancialTable.props.safeParse(n);return r.success?{...r.data,variant:r.data.variant??(r.data.metrics?`detail`:`comparison`)}:null}function Qn(e,t){let n=e.metrics??(e.metric?[e.metric]:[]);if(n.length===0)return null;let r=[e.groupRows,e.rows].filter(e=>!!e),i=e.variant===`detail`?void 0:J(e.compareWith),a=Y(e.filters,t);return{metrics:n,groupBy:r,...e.period?{period:e.period}:{},...i?{compare:i}:{},...a&&a.length>0?{filters:a}:{},...e.rows?{sort:{by:e.rows,direction:`asc`}}:{},limit:e.limit??500}}var $n={IncomeStatement:`Income statement`,BalanceSheet:`Balance sheet`,CashFlowStatement:`Cash flow statement`};function er({element:e}){let t=(0,V.useMemo)(()=>Zn(e.type,e.props),[e.type,e.props]),n=y(t?.dataset),r=Cn(t?.dataset),i=(0,V.useMemo)(()=>t?Qn(t,r):null,[t,r]),a=E(t?.dataset,i);if(!t||!i)return(0,H.jsx)(O,{component:e.type});let o=t.title??$n[e.type];return(0,H.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[o?(0,H.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:o}):null,r&&n?(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Filtered to `,F(r.dimension,n.dimensions?.[r.dimension]).toLowerCase(),` `,r.value]}):null,a.status===`ok`?null:(0,H.jsx)(h,{state:a}),a.status===`ok`&&n?(0,H.jsx)(`div`,{className:c(a.refreshing&&`opacity-60`),children:(0,H.jsx)(Kn,{element:e,config:t,query:i,result:a.result,decl:n})}):null]})}function tr(e,t,n){let[r,i]=en(e,t);return[r??n,i]}function nr({label:e,children:t}){return(0,H.jsxs)(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]})}var rr=[`last-12-months`,`ytd`,`last-4-quarters`,`last-3-months`,`all`];function ir({element:e,bindings:t}){let n=R.PeriodSelector.props.safeParse(q(e.props)),r=n.success?n.data.options??[...rr]:[],[i,a]=tr(n.success?n.data.value:void 0,t?.value,r[0]??`all`);if(!n.success)return(0,H.jsx)(O,{component:`PeriodSelector`});let o=r.includes(i)?r:[i,...r];return(0,H.jsx)(nr,{label:n.data.label??`Period`,children:(0,H.jsxs)(he,{value:i,onValueChange:a,children:[(0,H.jsx)(de,{className:`h-9`,children:(0,H.jsx)(me,{})}),(0,H.jsx)(pe,{children:o.map(e=>(0,H.jsx)(fe,{value:e,children:Ae(e)},e))})]})})}function ar({element:e,bindings:t}){let{spec:n}=b(),r=R.CompareSelector.props.safeParse(q(e.props)),i=(0,V.useMemo)(()=>{let e=Object.values(n.datasets??{}).flatMap(e=>[e.scenario?.budget?`budget`:null,e.scenario?.forecast?`forecast`:null]);return new Set(e)},[n.datasets]),a=[...Oe.filter(e=>e.startsWith(`previous`)||i.has(e)),`none`],o=r.success?r.data.options??a:[],[s,c]=tr(r.success?r.data.value:void 0,t?.value,o[0]??`none`);return r.success?(0,H.jsx)(nr,{label:r.data.label??`Compare with`,children:(0,H.jsxs)(he,{value:s,onValueChange:c,children:[(0,H.jsx)(de,{className:`h-9`,children:(0,H.jsx)(me,{})}),(0,H.jsx)(pe,{children:o.map(e=>(0,H.jsx)(fe,{value:e,children:Te(e)},e))})]})}):(0,H.jsx)(O,{component:`CompareSelector`})}function or({element:e,bindings:t}){let n=e.type===`CurrencySelector`,r=(0,V.useMemo)(()=>{let t=q(e.props);if(n){let e=R.CurrencySelector.props.safeParse(t);return e.success?{...e.data,includeAll:!1}:null}let r=R.EntitySelector.props.safeParse(t);return r.success?r.data:null},[e.props,n]),i=y(r?.dataset),a=i?Object.keys(i.metrics)[0]:void 0,o=(0,V.useMemo)(()=>r&&a?{metrics:[a],groupBy:[r.dimension],sort:{by:r.dimension,direction:`asc`},limit:200}:null,[a,r]),s=E(r?.dataset,o),c=s.status===`ok`?s.result.rows.map(e=>e.dimensions[r?.dimension??``]??``):[],l=r?.includeAll===!1||n?c[0]??``:`all`,[u,d]=tr(r?.value,t?.value,l);if(!r)return(0,H.jsx)(O,{component:e.type});let f=r.label??(n?`Currency`:F(r.dimension,i?.dimensions?.[r.dimension]));if(s.status!==`ok`)return(0,H.jsx)(nr,{label:f,children:(0,H.jsx)(h,{state:s})});let p=[...r.includeAll===!1||n?[]:[`all`],...c];return(0,H.jsx)(nr,{label:f,children:(0,H.jsxs)(he,{value:u||l,onValueChange:d,children:[(0,H.jsx)(de,{className:`h-9`,children:(0,H.jsx)(me,{})}),(0,H.jsx)(pe,{children:p.map(e=>(0,H.jsx)(fe,{value:e,children:e===`all`?`All`:e},e))})]})})}var sr={sm:`gap-2`,md:`gap-3`,lg:`gap-5`},cr={1:`grid-cols-1`,2:`grid-cols-1 @md:grid-cols-2`,3:`grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3`,4:`grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-4`};function lr({element:e,children:t}){let n=R.Stack.props.safeParse(q(e.props));if(!n.success)return(0,H.jsx)(O,{component:`Stack`});let r=n.data.direction===`horizontal`;return(0,H.jsx)(`div`,{className:c(`flex min-w-0`,r?`flex-row flex-wrap items-start`:`flex-col`,sr[n.data.gap??`md`]),children:t})}function ur({element:e,children:t}){let n=R.Grid.props.safeParse(q(e.props));return n.success?(0,H.jsx)(`div`,{className:c(`grid min-w-0`,cr[n.data.columns??2],sr[n.data.gap??`md`]),children:t}):(0,H.jsx)(O,{component:`Grid`})}function dr({element:e,children:t}){let n=R.Card.props.safeParse(q(e.props));return n.success?(0,H.jsxs)(`section`,{className:`min-w-0 rounded-md border border-border p-3`,"aria-label":n.data.title,children:[n.data.title?(0,H.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:n.data.title}):null,n.data.description?(0,H.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:n.data.description}):null,(0,H.jsx)(`div`,{className:c(`flex flex-col gap-3`,(n.data.title||n.data.description)&&`mt-3`),children:t})]}):(0,H.jsx)(O,{component:`Card`})}function fr({element:e,children:t}){let n=R.Section.props.safeParse(q(e.props));return n.success?(0,H.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":n.data.title,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:n.data.title}),n.data.description?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n.data.description}):null]}),t]}):(0,H.jsx)(O,{component:`Section`})}function pr({element:e,children:t,bindings:n}){let r=R.Tabs.props.safeParse(q(e.props)),i=r.success?r.data.items:[],[a,o]=en(r.success?r.data.value:void 0,n?.value),[s,c]=K(e,`tab`,i[0]?.value??``,pn);if(!r.success)return(0,H.jsx)(O,{component:`Tabs`});let l=n?.value?a??i[0]?.value??``:s,u=e=>{n?.value?o(e):c(e)},d=V.Children.toArray(t),f=Math.max(0,i.findIndex(e=>e.value===l));return(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,H.jsx)(ve,{size:`sm`,value:i[f]?.value??``,onValueChange:u,options:i.map(e=>({value:e.value,label:e.label}))}),(0,H.jsx)(`div`,{role:`tabpanel`,children:d[f]??null})]})}var mr={body:`text-sm text-foreground`,muted:`text-sm text-muted-foreground`,heading:`text-base font-medium text-foreground`,label:`text-xs font-medium text-muted-foreground`};function hr({element:e}){let t=R.Text.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`p`,{className:c(`whitespace-pre-wrap break-words`,mr[t.data.variant??`body`]),children:t.data.text}):(0,H.jsx)(O,{component:`Text`})}function gr({element:e}){let t=R.Badge.props.safeParse(q(e.props));if(!t.success)return(0,H.jsx)(O,{component:`Badge`});let n=t.data.tone??`neutral`;return(0,H.jsxs)(`span`,{className:c(`inline-flex w-fit items-center gap-1 rounded-md border border-border px-1.5 py-0.5 text-xs font-medium`,v(n)),children:[(0,H.jsx)(_,{tone:n}),t.data.label]})}var _r={primary:`default`,secondary:`outline`,ghost:`ghost`};function vr(e){return e?(Array.isArray(e)?e:[e]).map(e=>e.action):[]}function yr({element:e,emit:t}){let{loadingActions:n}=W(),r=R.Button.props.safeParse(q(e.props));if(!r.success)return(0,H.jsx)(O,{component:`Button`});let i=vr(e.on?.press).some(e=>n.has(e));return(0,H.jsx)(s,{size:`sm`,variant:_r[r.data.variant??`secondary`],className:`w-fit`,pending:i,onClick:()=>t(`press`),children:r.data.label})}function br(){return(0,H.jsx)(`hr`,{className:`border-border`})}function xr(e,t,n){let{execute:r}=W(),{viewKey:i}=b(),a=p(`genui.${e}`,i,n),o=d(a);return{run:(0,V.useCallback)(()=>{u(a,()=>r({action:e,params:t}))},[e,r,a,t]),pending:o}}function Sr({path:e,line:t,label:n}){let{run:r,pending:i}=xr(`file.open`,t?{path:e,line:t}:{path:e},`${e}:${t??``}`);return(0,H.jsx)(`button`,{type:`button`,onClick:r,disabled:i,"aria-busy":i||void 0,className:`max-w-full rounded-sm text-left font-mono text-xs break-all text-foreground underline decoration-border underline-offset-2 hover:decoration-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:n})}function Cr({element:e}){let t=R.KeyValue.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`dl`,{className:c(`grid gap-x-6 gap-y-1.5`,t.data.columns===2?`grid-cols-1 @md:grid-cols-2`:`grid-cols-1`),children:t.data.items.map(e=>(0,H.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,2fr)] gap-3 text-sm`,children:[(0,H.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,H.jsx)(`dd`,{className:`break-words text-foreground tabular-nums`,children:e.value===null?`—`:String(e.value)})]},e.label))}):(0,H.jsx)(O,{component:`KeyValue`})}var wr={added:{icon:re,label:`Added`},modified:{icon:ne,label:`Modified`},deleted:{icon:st,label:`Deleted`},renamed:{icon:M,label:`Renamed`}};function Tr({element:e}){let t=R.FileList.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.data.files.map(e=>{let t=e.status?wr[e.status]:null,n=t?.icon??M;return(0,H.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2`,children:[(0,H.jsx)(n,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(Sr,{path:e.path,label:e.path}),e.description?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}):null]}),t?(0,H.jsx)(`span`,{className:`mt-0.5 shrink-0 pl-2 text-xs text-muted-foreground`,children:t.label}):null]},e.path)})}):(0,H.jsx)(O,{component:`FileList`})}function Er(e,t,n){return t?n?`${e}:${t}:${n}`:`${e}:${t}`:e}var Dr={error:`negative`,warning:`attention`,info:`info`},Or={error:`Error`,warning:`Warning`,info:`Info`};function kr({element:e}){let t=R.DiagnosticList.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:t.data.items.map((e,t)=>{let n=Dr[e.severity],r=e.path?Er(e.path,e.line,e.column):null;return(0,H.jsxs)(`li`,{className:`flex gap-2 px-3 py-2 text-sm`,children:[(0,H.jsxs)(`span`,{className:c(`mt-0.5 flex shrink-0 items-center gap-1 text-xs font-medium`,v(n)),children:[(0,H.jsx)(_,{tone:n}),Or[e.severity]]}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`break-words text-foreground`,children:e.message}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[e.path&&r?(0,H.jsx)(Sr,{path:e.path,line:e.line,label:r}):null,e.source?(0,H.jsx)(`span`,{children:e.source}):null]})]})]},`${t}-${e.message}`)})}):(0,H.jsx)(O,{component:`DiagnosticList`})}function Ar({name:e,context:t}){let{run:n,pending:r}=xr(`agent.fix`,{subject:e,context:t},e);return(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,className:`gap-1.5`,onClick:n,pending:r,"aria-label":`Ask the agent to fix ${e}`,children:[r?null:(0,H.jsx)(se,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Fix`]})}function jr({element:e}){let t=R.TestResult.props.safeParse(q(e.props));if(!t.success)return(0,H.jsx)(O,{component:`TestResult`});let{passed:n,failed:r,skipped:i,durationMs:a,command:o,failures:s}=t.data,l=r>0?`negative`:`positive`;return(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-sm`,children:[(0,H.jsxs)(`span`,{className:c(`flex items-center gap-1 font-medium`,v(l)),children:[(0,H.jsx)(_,{tone:l}),r>0?`Failing`:`Passing`]}),(0,H.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[n,` passed`]}),(0,H.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[r,` failed`]}),i===void 0?null:(0,H.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[i,` skipped`]}),a===void 0?null:(0,H.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:rt(a)})]}),o?(0,H.jsx)(`code`,{className:`w-fit rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-muted-foreground`,children:o}):null,s&&s.length>0?(0,H.jsx)(`ul`,{className:`divide-y divide-border border-t border-border`,children:s.map(e=>(0,H.jsxs)(`li`,{className:`flex items-start gap-2 py-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`p`,{className:`break-words text-sm text-foreground`,children:e.name}),e.message?(0,H.jsx)(`pre`,{className:`mt-1 max-h-32 overflow-auto whitespace-pre-wrap font-mono text-xs text-muted-foreground`,children:e.message}):null,e.path?(0,H.jsx)(Sr,{path:e.path,line:e.line,label:Er(e.path,e.line,void 0)}):null]}),(0,H.jsx)(Ar,{name:e.name,context:{...e.message?{message:e.message}:{},...e.path?{path:e.path}:{},...e.line?{line:e.line}:{},...o?{command:o}:{}}})]},e.name))}):null]})}function Mr({element:e}){let t=R.Timeline.props.safeParse(q(e.props));return t.success?(0,H.jsx)(`ol`,{className:`flex flex-col gap-3 border-l border-border pl-4`,children:t.data.items.map((e,t)=>(0,H.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.tone?(0,H.jsx)(_,{tone:e.tone,className:v(e.tone)}):null,(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e.title}),e.time?(0,H.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:e.time}):null]}),e.detail?(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.detail}):null]},`${t}-${e.title}`))}):(0,H.jsx)(O,{component:`Timeline`})}var Nr=50,Pr=`px-3 py-2 text-xs font-medium text-muted-foreground`;function Fr(e){return e==null?`—`:typeof e==`string`?e:typeof e==`number`?new Intl.NumberFormat(`en-US`).format(e):typeof e==`boolean`?e?`Yes`:`No`:JSON.stringify(e)}function Ir(e,t){let n=e??Object.keys(t[0]??{}).map(e=>({key:e,label:Ne(e)}));return{columns:n.map(e=>({...e,numeric:t.every(t=>typeof t[e.key]==`number`||t[e.key]===void 0)})),rows:t.map((e,t)=>({key:String(t),cells:Object.fromEntries(n.map(t=>[t.key,Fr(e[t.key])]))}))}}function Lr(e,t,n,r){let i=r.comparison?.label;return{columns:[...t.map(t=>({key:`d:${t}`,label:F(t,e.dimensions?.[t]),numeric:!1})),...n.flatMap(t=>[{key:`m:${t}`,label:I(t,e.metrics[t]),numeric:!0},...i?[{key:`c:${t}`,label:`${I(t,e.metrics[t])} (${i})`,numeric:!0}]:[]])],rows:r.rows.map(r=>({key:r.key,cells:Object.fromEntries([...t.map(e=>[`d:${e}`,r.dimensions[e]??``]),...n.flatMap(t=>[[`m:${t}`,L(r.values[t]??null,z(e.metrics[t]))],...i?[[`c:${t}`,L(r.compare?.[t]??null,z(e.metrics[t]))]]:[]])])}))}}function Rr({element:e,columns:t,rows:n,title:r}){let[i,a]=K(e,`expanded`,!1,mn),o=i?n:n.slice(0,Nr);return(0,H.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[r?(0,H.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:r}):null,(0,H.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,H.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,H.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,H.jsx)(`tr`,{className:`border-b border-border`,children:t.map(e=>(0,H.jsx)(`th`,{scope:`col`,className:c(Pr,e.numeric?`text-right`:`text-left`),children:e.label},e.key))})}),(0,H.jsx)(`tbody`,{className:`divide-y divide-border`,children:o.map(e=>(0,H.jsx)(`tr`,{children:t.map(t=>(0,H.jsx)(`td`,{className:c(`px-3 py-1.5 text-foreground`,t.numeric?`text-right tabular-nums`:`text-left`),children:e.cells[t.key]},t.key))},e.key))})]}),!i&&n.length>Nr?(0,H.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,H.jsxs)(s,{size:`sm`,variant:`ghost`,onClick:()=>a(!0),children:[`Show all `,n.length,` rows`]})}):null]})]})}function zr({element:e}){let t=(0,V.useMemo)(()=>{let t=R.DataTable.props.safeParse(q(e.props));return t.success?t.data:null},[e.props]),n=y(t?.dataset),r=Cn(t?.dataset),i=(0,V.useMemo)(()=>{if(!t?.dataset||!t.metrics)return null;let e=J(t.compareWith),n=Y(t.filters,r);return{metrics:t.metrics,groupBy:t.dimensions??[],...t.period?{period:t.period}:{},...e?{compare:e}:{},...n&&n.length>0?{filters:n}:{},limit:t.limit??200}},[r,t]),a=E(t?.dataset,i);if(!t)return(0,H.jsx)(O,{component:`DataTable`});if(!t.dataset){let n=(t.rows??[]).filter(be);return(0,H.jsx)(Rr,{element:e,...Ir(t.columns,n),title:t.title})}return t.metrics?a.status===`ok`?n?(0,H.jsx)(Rr,{element:e,...Lr(n,t.dimensions??[],t.metrics,a.result),title:t.title}):(0,H.jsx)(O,{component:`DataTable`}):(0,H.jsx)(h,{state:a}):(0,H.jsx)(O,{component:`DataTable`})}var Br={sm:280,md:420,lg:600},Vr=720,Hr=14,Ur=132,Wr=300,Gr=50,Kr=8,qr=16,Jr=38,Yr=24;function Xr(){return a.getCssVar(`--kanna-font-body`,`system-ui, sans-serif`)}function Zr(){return a.getCssVar(`--kanna-font-mono`,`ui-monospace, monospace`)}function Q(e,t,n){return a.measureTextWidth(e,t)??e.length*n}function Qr(e,t){let n=e.split(`/`).pop()??e;return t?`${n}:${t}`:n}function $r(e){let t=Xr(),n=Q(e.label,`500 14px ${t}`,7.6),r=e.status?Q(e.status,`500 12px ${t}`,6.4)+Yr:0,i=e.description?Q(e.description,`12px ${t}`,6.2):0,a=e.path?Q(Qr(e.path,e.line),`12px ${Zr()}`,7.2):0,o=Math.max(n+r,i,a);return{width:Math.round(Math.min(Wr,Math.max(Ur,o+Gr+(e.kind===`start`||e.kind===`end`?Kr:0)))),height:Jr+(e.description?qr:0)+(e.path?qr:0)}}function ei(e){return`e${e}`}function ti(e,t){let n=e=>({id:e.id,...$r(e)}),r=new Set((e.groups??[]).map(e=>e.id)),i=e.edges.map((e,t)=>({id:ei(t),sources:[e.from],targets:[e.to],...e.label?{labels:[{text:e.label,width:Q(e.label,`12px ${Xr()}`,6.4)+10,height:18}]}:{}}));return{id:`root`,layoutOptions:{"elk.algorithm":`layered`,"elk.direction":t===`LR`?`RIGHT`:`DOWN`,"elk.hierarchyHandling":`INCLUDE_CHILDREN`,"elk.edgeRouting":`ORTHOGONAL`,"elk.json.edgeCoords":`ROOT`,"elk.edgeLabels.inline":`true`,"elk.spacing.nodeNode":`28`,"elk.layered.spacing.nodeNodeBetweenLayers":`52`,"elk.layered.nodePlacement.strategy":`NETWORK_SIMPLEX`},children:[...(e.groups??[]).map(t=>({id:t.id,layoutOptions:{"elk.padding":`[top=38,left=${Hr},bottom=${Hr},right=${Hr}]`},children:e.nodes.filter(e=>e.group===t.id).map(n)})).filter(e=>e.children.length>0),...e.nodes.filter(e=>e.group===void 0||!r.has(e.group)).map(n)],edges:i}}function ni(e,t,n){let r=new Map(e.nodes.map(e=>[e.id,e])),i=new Map((e.groups??[]).map(e=>[e.id,e.label])),a=[],o=[],s=(e,t)=>{let n={x:t.x+(e.x??0),y:t.y+(e.y??0),width:e.width??0,height:e.height??0},c=r.get(e.id);if(c){o.push({...n,node:c});return}a.push({...n,id:e.id,label:i.get(e.id)??e.id});for(let t of e.children??[])s(t,{x:n.x,y:n.y})};for(let e of n.children??[])s(e,{x:0,y:0});let c=new Map((n.edges??[]).map(e=>[e.id,e])),l=e.edges.map((e,t)=>{let n=c.get(ei(t))?.sections?.[0],r=c.get(ei(t))?.labels?.[0];return{key:ei(t),edge:e,points:n?[n.startPoint,...n.bendPoints??[],n.endPoint]:[],labelAt:r?.x!==void 0&&r.y!==void 0?{x:r.x+(r.width??0)/2,y:r.y+(r.height??0)/2}:null}});return{direction:t,width:n.width??0,height:n.height??0,groups:a,nodes:o,edges:l}}async function ri(t,r){let{default:i}=await n(async()=>{let{default:t}=await import(`./elk.bundled-BfUIUPT1.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([10,1]));return ni(t,r,await new i().layout(ti(t,r)))}function ii(e,t){return e.width===0||e.height===0?1:Math.min(Vr/e.width,t/e.height)}async function ai(e){await a.whenFontsReady();let t=e.direction??`auto`;if(t!==`auto`)return await ri(e,t);let n=Br[e.height??`md`],[r,i]=await Promise.all([ri(e,`LR`),ri(e,`TB`)]);return ii(r,n)>=ii(i,n)?r:i}var oi=(0,V.lazy)(()=>n(()=>import(`./FlowSurface-CLC-ZFar.js`),__vite__mapDeps([11,1,2,12,3,13,4,14,15,16,17,18,19,20,21,6,5,7,22,23,24,25]))),si=`genui-flow-layout`;function ci(e){return e===`diagram`||e===`outline`}function li(e){let t=q(e);if(!t)return null;let n=R.FlowDiagram.props.safeParse(t);return n.success?n.data:null}function ui(e){return i({queryKey:[si,m(JSON.stringify(e))],queryFn:async()=>await ai(e),staleTime:1/0,retry:!1})}function di(e){let t=e.edges.filter(e=>A(e)===`flow`).length,n=`${e.nodes.length} ${e.nodes.length===1?`step`:`steps`}`,r=`${e.edges.length} ${e.edges.length===1?`connection`:`connections`}`;return t>0?`${n} · ${r} · ${t} live`:`${n} · ${r}`}function fi({heading:e,links:t,direction:n}){return t.length===0?null:(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(0,H.jsxs)(`span`,{children:[e,` `]}),t.map((e,t)=>(0,H.jsxs)(`span`,{children:[t>0?`, `:null,(0,H.jsx)(`span`,{className:`text-foreground`,children:e.node.label}),e.edge.label?(0,H.jsxs)(`span`,{children:[` (`,e.edge.label,`)`]}):null,A(e.edge)===`flow`?(0,H.jsx)(`span`,{className:`text-info-text`,children:` · live`}):null]},`${n}-${e.node.id}-${t}`))]})}function pi({entries:e,selectedId:t,onSelect:n}){return(0,H.jsx)(`ol`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map((e,r)=>(0,H.jsxs)(`li`,{className:c(`flex gap-3 px-3 py-2`,e.node.id===t&&`bg-muted`),children:[(0,H.jsx)(`span`,{className:`w-5 shrink-0 pt-0.5 text-right text-xs text-muted-foreground tabular-nums`,children:r+1}),(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,H.jsx)(w,{node:e.node}),(0,H.jsx)(`button`,{type:`button`,className:`rounded-sm text-left text-sm font-medium text-foreground underline decoration-border underline-offset-4 hover:decoration-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-pressed":e.node.id===t,onClick:()=>n(e.node.id),children:e.node.label}),(0,H.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:ee[e.node.kind??`process`].label}),e.groupLabel?(0,H.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`in `,e.groupLabel]}):null,(0,H.jsx)(D,{node:e.node})]}),e.node.description?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.node.description}):null,(0,H.jsx)(fi,{heading:`From`,links:e.incoming,direction:`in`}),(0,H.jsx)(fi,{heading:`To`,links:e.outgoing,direction:`out`})]})]},e.node.id))})}function mi({node:e}){let{run:t,pending:n}=xr(`file.open`,(0,V.useMemo)(()=>e.line?{path:e.path,line:e.line}:{path:e.path},[e.line,e.path]),`${e.id}:${e.path}`);return(0,H.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:n,onClick:t,children:[n?null:(0,H.jsx)(M,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open file`]})}function hi({diagram:e,node:t}){let n=(0,V.useMemo)(()=>j(e,t.id)??{},[e,t.id]),{run:r,pending:i}=xr(`agent.investigate`,(0,V.useMemo)(()=>({subject:t.label,context:n}),[n,t.label]),t.id);return(0,H.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:i,onClick:r,children:[i?null:(0,H.jsx)(lt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Ask agent`]})}function gi(e){return e.path?e.line?`${e.path}:${e.line}`:e.path:null}function _i(e){return e.path!==void 0}function vi({diagram:e,entry:t,onClose:n}){let r=N(),{node:i}=t,a=gi(i);return(0,H.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,"aria-label":`Step ${i.label}`,children:[(0,H.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,H.jsx)(w,{node:i,className:`mt-1`}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:i.label}),(0,H.jsx)(D,{node:i})]}),i.description?(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i.description}):null,a?(0,H.jsx)(`p`,{className:`font-mono text-xs break-all text-muted-foreground`,children:a}):null]}),(0,H.jsx)(s,{size:`icon-sm`,variant:`ghost`,onClick:n,"aria-label":`Close step details`,children:(0,H.jsx)(_e,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}),(0,H.jsx)(fi,{heading:`From`,links:t.incoming,direction:`in`}),(0,H.jsx)(fi,{heading:`To`,links:t.outgoing,direction:`out`}),r.readonly?null:(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[_i(i)?(0,H.jsx)(mi,{node:i}):null,r.sendToAgent?(0,H.jsx)(hi,{diagram:e,node:i}):null]})]})}function yi({diagram:e,height:t,label:n,selectedId:r,onSelect:i}){let a=N(),o=ui(e),s=a.FlowRenderer??oi;return o.error?(0,H.jsx)(T,{label:`This diagram could not be laid out. The Outline view still lists every step.`,minHeight:t}):o.data?(0,H.jsx)(V.Suspense,{fallback:(0,H.jsx)(`div`,{className:`w-full rounded-md border border-border`,style:{height:t},"aria-hidden":`true`}),children:(0,H.jsx)(s,{layout:o.data,height:t,label:n,selectedId:r,onSelect:i})}):(0,H.jsxs)(`div`,{className:`flex items-center justify-center gap-2 rounded-md border border-border text-sm text-muted-foreground`,style:{height:t},role:`status`,children:[(0,H.jsx)(f,{}),` Laying out diagram…`]})}function bi({element:e}){let t=(0,V.useMemo)(()=>li(e.props),[e.props]),n=(0,V.useMemo)(()=>t?g(t):[],[t]),[r,i]=K(e,`view`,`diagram`,ci),[a,o]=K(e,`selected`,``,pn),s=(0,V.useId)(),c=(0,V.useCallback)(e=>o(e??``),[o]),l=(0,V.useCallback)(e=>o(e===a?``:e),[a,o]),u=(0,V.useCallback)(()=>o(``),[o]);if(!t)return(0,H.jsx)(O,{component:`FlowDiagram`});let d=Br[t.height??`md`],f=n.find(e=>e.node.id===a)??null,p=`Diagram${t.title?` of ${t.title}`:``}: ${di(t)}. Switch to Outline to read it as a list.`;return(0,H.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,"aria-labelledby":s,children:[(0,H.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{id:s,className:`text-sm font-medium text-foreground`,children:t.title??`Diagram`}),(0,H.jsx)(`div`,{className:`text-xs text-muted-foreground tabular-nums`,children:di(t)})]}),(0,H.jsx)(ve,{size:`sm`,value:r,onValueChange:i,options:[{value:`diagram`,label:`Diagram`},{value:`outline`,label:`Outline`}]})]}),r===`diagram`?(0,H.jsx)(yi,{diagram:t,height:d,label:p,selectedId:f?.node.id??null,onSelect:c}):(0,H.jsx)(pi,{entries:n,selectedId:f?.node.id??null,onSelect:l}),f?(0,H.jsx)(vi,{diagram:t,entry:f,onClose:u}):null]})}var xi={Stack:lr,Grid:ur,Card:dr,Section:fr,Tabs:pr,Text:hr,Badge:gr,Button:yr,Divider:br,KeyValue:Cr,DataTable:zr,FileList:Tr,DiagnosticList:kr,TestResult:jr,Timeline:Mr,FlowDiagram:bi,FinancialMetric:Yn,FinancialChart:Fn,FinancialTable:er,IncomeStatement:er,BalanceSheet:er,CashFlowStatement:er,PeriodSelector:ir,CompareSelector:ar,CurrencySelector:or,EntitySelector:or};function Si({element:e}){return(0,H.jsx)(O,{component:e.type})}var Ci=64,$=new Map;function wi(e,t){let n=$.get(e);if(n)return $.delete(e),$.set(e,n),n;let r=Pe({...t});for($.set(e,r);$.size>Ci;){let e=$.keys().next().value;if(e===void 0)break;$.delete(e)}return r}function Ti(e){return{root:e.root,elements:Object.fromEntries(Object.entries(e.elements).map(([e,t])=>[e,{type:t.type,props:{...t.props,[un]:e},children:t.children,...t.visible===void 0?{}:{visible:t.visible},...t.repeat?{repeat:t.repeat}:{},...t.on?{on:t.on}:{}}])),...e.state?{state:e.state}:{}}}function Ei({viewKey:e}){let t=N(),n=C.useScopedStore(e=>e.pendingAgentMessage),r=C.useScopedStore(e=>e.cancelAgentMessage),i=C.useScopedStore(e=>e.showNotice),a=p(`genui.agent.send`,e),o=d(a),c=t.sendToAgent,l=(0,V.useCallback)(()=>{n&&c&&u(a,async()=>{try{await c(n.message),r()}catch(e){throw i(e instanceof Error?e.message:`The message could not be sent`),e}})},[r,a,n,c,i]);return n?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border bg-muted/40 p-3`,role:`group`,"aria-label":`Send to the agent`,children:[(0,H.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,H.jsx)(lt,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Send to the agent`}),(0,H.jsx)(`p`,{className:`break-words text-foreground`,children:n.headline}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The view's current numbers and data source go with it.`})]})]}),(0,H.jsxs)(`div`,{className:`flex gap-2`,children:[(0,H.jsx)(s,{size:`sm`,pending:o,onClick:l,children:`Send`}),(0,H.jsx)(s,{size:`sm`,variant:`ghost`,onClick:r,disabled:o,children:`Cancel`})]})]}):null}function Di(){let e=C.useScopedStore(e=>e.notice),t=C.useScopedStore(e=>e.showNotice);return e?(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-destructive-text`,role:`alert`,children:[(0,H.jsx)(ge,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,H.jsx)(`button`,{type:`button`,className:`rounded p-0.5 text-muted-foreground hover:text-foreground`,"aria-label":`Dismiss`,onClick:()=>t(null),children:(0,H.jsx)(_e,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}):null}function Oi(e){let t=e.lastIndexOf(`/`);return t>=0?e.slice(t+1):e}function ki(){let e=C.useScopedStore(e=>e.previewPath),t=C.useScopedStore(e=>e.previewProbe),n=C.useScopedStore(e=>e.setPreviewProbe),r=C.useScopedStore(e=>e.closePreview),i=C.useScopedStore(e=>e.showNotice);(0,V.useEffect)(()=>{if(!e)return;let t=new AbortController;return nt(`probe generated file link`,te(ae(e),{signal:t.signal}).then(a=>{t.signal.aborted||(a.kind===`ready`?n(a):(r(),i(`"${Oi(e)}" could not be opened`)))})),()=>t.abort()},[r,e,n,i]);let a=(0,V.useMemo)(()=>{if(!e||t?.kind!==`ready`)return null;let n=ae(e);return ie({id:`genui-file-${n}`,kind:`file`,displayName:Oi(e),absolutePath:e,relativePath:e,contentUrl:n,mimeType:t.mimeType,size:t.size},`local_file_link`)},[e,t]),o=(0,V.useCallback)(e=>{e||r()},[r]);return(0,H.jsx)(oe,{source:a,open:a!==null,onOpenChange:o})}function Ai({handlers:e}){let{registerHandler:t}=W();return(0,V.useEffect)(()=>{for(let[n,r]of Object.entries(e))t(n,r)},[e,t]),null}function ji({spec:e,viewKey:t}){let n=N(),r=C.useScopedStoreApi(),i=(0,V.useMemo)(()=>wi(t,e.state??{}),[t,e.state]),a=(0,V.useMemo)(()=>ln({host:()=>n,view:r,spec:e,state:i}),[n,r,e,i]),o=(0,V.useMemo)(()=>Ti(e),[e]),s=(0,V.useMemo)(()=>({spec:e,viewKey:t}),[e,t]);return(0,H.jsx)(x,{value:s,children:(0,H.jsxs)(`section`,{className:`@container not-prose my-3 flex w-full min-w-0 flex-col gap-3 rounded-lg border border-border bg-card p-3 sm:p-4`,"aria-label":e.title??`Generated view`,children:[e.title?(0,H.jsx)(`h3`,{className:`text-base font-medium text-foreground`,children:e.title}):null,(0,H.jsxs)(Qt,{registry:xi,store:i,handlers:a,children:[(0,H.jsx)(Ai,{handlers:a}),(0,H.jsx)(Zt,{spec:o,registry:xi,fallback:Si})]}),(0,H.jsx)(Di,{}),(0,H.jsx)(Ei,{viewKey:t}),(0,H.jsx)(ki,{})]})})}function Mi({spec:e,viewKey:t}){return(0,H.jsx)(C.Provider,{init:void 0,children:(0,H.jsx)(ji,{spec:e,viewKey:t})})}var Ni=8;function Pi({issues:e}){return(0,H.jsxs)(`div`,{className:`not-prose my-3 flex flex-col gap-2 rounded-lg border border-border p-3 text-sm`,role:`alert`,children:[(0,H.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-foreground`,children:[(0,H.jsx)(ge,{className:`h-4 w-4 text-warning-text`,"aria-hidden":`true`}),`Unable to show this view`]}),(0,H.jsx)(`p`,{className:`text-muted-foreground`,children:`The agent described a view Kanna could not validate, so nothing from it was run.`}),(0,H.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,H.jsx)(`summary`,{className:`cursor-pointer select-none`,children:`Details`}),(0,H.jsxs)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4 font-mono`,children:[e.slice(0,Ni).map(e=>(0,H.jsxs)(`li`,{children:[e.path?`${e.path}: `:``,e.message]},`${e.path}:${e.message}`)),e.length>Ni?(0,H.jsxs)(`li`,{children:[`…and `,e.length-Ni,` more`]}):null]})]})]})}var Fi=class extends V.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){o.warn(`[kanna/genui] view failed to render`,{message:e.message})}render(){return this.state.failed?(0,H.jsx)(Pi,{issues:[{path:``,message:`The view stopped rendering unexpectedly`}]}):this.props.children}};function Ii({source:e}){let t=N(),n=(0,V.useMemo)(()=>Xe(e),[e]),r=(0,V.useMemo)(()=>`${t.chatId??`shared`}:${m(e)}`,[t.chatId,e]);return n.ok?(0,H.jsx)(Fi,{children:(0,H.jsx)(Mi,{spec:n.spec,viewKey:r})}):(0,H.jsx)(Pi,{issues:n.issues})}export{Pi as GenUIFallback,Ii as default};
|
package/dist/client/assets/{KannaSocketProvider-D7Lzlt35.js → KannaSocketProvider-B2sHsWP5.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./react-DiVRNtpo.js";import{n}from"./chunk-OB3PAWPO-mARpRU1A.js";import{t as r}from"./jsx-runtime-BdxMnOeJ.js";import{d as i,i as a,t as o}from"./log-aTaDVF_e.js";import{f as s,l as c}from"./pendingActionsStore-COTh4Ztq.js";import{d as l,h as u,r as d,u as f}from"./pushClient-BJH_ITRB.js";import{t as p}from"./timer.adapter-DHt2zwsL.js";import{t as m}from"./runDetached-DqQ3k2ji.js";import{a as h}from"./formatters-wSVyvDFZ.js";import{i as g,n as _,r as v}from"./state-mark-BhTZfcYe.js";var y={name:`calendar-clock`,size:24,node:[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`path`,{d:`M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338`,key:`7hb8p4`}],[`path`,{d:`M3 9h5.859`,key:`numkqi`}],[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]};y.node;var b=s(y),x=`h-[var(--shell-top-band)] max-h-[var(--shell-top-band)]`,S=`md:my-2 md:mr-2 md:rounded-2xl md:border md:border-border`,C=`flex min-h-0 flex-1 flex-col overflow-y-auto`,w=e(t(),1),T={timer:p};function E(e=1e3,t){let{timer:n}=t??T,[r,i]=(0,w.useState)(()=>Date.now()),a=(0,w.useRef)(e);return(0,w.useLayoutEffect)(()=>{a.current=e}),(0,w.useEffect)(()=>{let e=n.setInterval(()=>{i(Date.now())},a.current);return()=>n.clearInterval(e)},[n]),r}function D(e){return e===`inline`?`runs in this chat, context cleared each cycle`:`a new chat per run`}var O=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`];function k(e,t){if(e.type===`interval`)return A(e.ms);let{second:n,minute:r,hour:i,dom:a,month:o,dow:s}=e;if(o.kind!==`any`)return t;let c=a.kind===`any`&&s.kind===`any`;if(n!==void 0&&r.kind===`any`&&i.kind===`any`&&c){if(n.kind===`any`)return`every second`;let e=M(n.values);if(e!==null)return e===1?`every second`:`every ${e} seconds`;if(n.values.length>1)return t}let l=n===void 0?0:j(n);if(l===null)return t;let u=l===0?``:`:${N(l)}`,d=j(r),f=j(i);if(r.kind===`any`&&i.kind===`any`&&c)return l===0?`every minute`:`every minute at :${N(l)}`;if(d!==null&&i.kind===`any`&&c)return`hourly at :${N(d)}${u}`;if(d!==null&&f!==null){let e=`${N(f)}:${N(d)}${u}`;if(c)return`daily at ${e}`;if(a.kind===`any`&&s.kind===`values`)return`every ${s.values.map(e=>O[e]).join(`, `)} at ${e}`;if(s.kind===`any`&&a.kind===`values`&&a.values.length===1)return`on day ${a.values[0]} of each month at ${e}`}return t}function A(e){let t=Math.round(e/1e3);if(t%3600==0){let e=t/3600;return e===1?`every hour`:`every ${e} hours`}if(t%60==0){let e=t/60;return e===1?`every minute`:`every ${e} minutes`}return t===1?`every second`:`every ${t} seconds`}function j(e){return e.kind===`values`&&e.values.length===1?e.values[0]:null}function M(e){if(e.length<2||e[0]!==0)return null;let t=e[1];if(t<1||60%t!=0||e.length!==60/t)return null;for(let n=1;n<e.length;n++)if(e[n]!==n*t)return null;return t}function N(e){return String(e).padStart(2,`0`)}var P=e(r(),1);function F({message:e,cronJobs:t}){let r=(t?.find(t=>t.jobId===e.jobId))?.recentRuns.find(t=>t.runId===e.runId)?.status??`running`;return(0,P.jsxs)(`div`,{className:`px-0.5`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(b,{className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,P.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:`Cron run`}),(0,P.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.jobId}),(0,P.jsxs)(`span`,{className:`ml-auto flex items-center gap-3`,children:[(0,P.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:h(e.firedAt)}),(0,P.jsx)(I,{status:r})]})]}),(0,P.jsx)(`p`,{className:`mt-1.5 text-sm text-foreground/90`,children:e.instruction}),e.spawnedChatId?(0,P.jsxs)(n,{to:`/chat/${e.spawnedChatId}`,className:`mt-2 inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:underline`,children:[(0,P.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open run chat`]}):null]})}function I({status:e}){return(0,P.jsx)(_,{tone:g(e),label:v(e)})}function L(){return(0,P.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs font-medium text-muted-foreground`,children:[(0,P.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-muted-foreground`}),`Paused`]})}var R={CONNECTING:WebSocket.CONNECTING,OPEN:WebSocket.OPEN,CLOSING:WebSocket.CLOSING,CLOSED:WebSocket.CLOSED,create(e){return new WebSocket(e)}},z=25e3,B=15e3,V=4e3,H=`kanna:profile-send-to-starting`,U=class{url;ws=null;started=!1;reconnectTimer=null;reconnectDelayMs=750;subscriptions=new Map;pending=new Map;outboundQueue=[];statusListeners=new Set;heartbeatTimer=null;pingTimeoutTimer=null;pingPromise=null;lastOpenAt=0;lastMessageAt=0;reconnectImmediatelyOnClose=!1;serviceWorkerCleanup=null;dom;timer;localStore;sessStore;wsBridge;handleWindowFocus=()=>{m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection())};handleVisibilityChange=()=>{if(this.dom.getVisibilityState()===`visible`){this.startHeartbeat(),m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection());return}this.stopHeartbeat()};handleOnline=()=>{m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection())};constructor(e,t={}){this.url=e,this.dom=t.dom??i,this.timer=t.timer??p,this.localStore=t.localStorage??f,this.sessStore=t.sessionStorage??l,this.wsBridge=t.webSocket??R}start(){this.started||(this.started=!0,this.serviceWorkerCleanup=this.dom.addServiceWorkerMessageListener(e=>{let t=e.data;t?.type===`kanna.navigate`&&typeof t.url==`string`&&this.dom.setHref(t.url)}),this.dom.addWindowListener(`focus`,this.handleWindowFocus),this.dom.addWindowListener(`online`,this.handleOnline),this.dom.addDocumentListener(`visibilitychange`,this.handleVisibilityChange),this.connect())}dispose(){this.started=!1,this.reconnectTimer&&=(this.timer.clearTimeout(this.reconnectTimer),null),this.stopHeartbeat(),this.clearPingState(),this.serviceWorkerCleanup&&=(this.serviceWorkerCleanup(),null),this.ws?.close(),this.ws=null;for(let e of this.pending.values())e.reject(Error(`Socket disposed`));this.pending.clear()}onStatus(e){return this.statusListeners.add(e),e(this.getStatus()),()=>{this.statusListeners.delete(e)}}subscribe(e,t,n){let r=c(),i={topic:e,listener:t,eventListener:n};return this.subscriptions.set(r,i),this.enqueue({v:1,type:`subscribe`,id:r,topic:e}),()=>{this.subscriptions.delete(r),this.enqueue({v:1,type:`unsubscribe`,id:r})}}subscribeTerminal(e,t){let n=c(),r={type:`terminal`,terminalId:e},i={topic:r,listener:t.onSnapshot,eventListener:t.onEvent};return this.subscriptions.set(n,i),this.enqueue({v:1,type:`subscribe`,id:n,topic:r}),()=>{this.subscriptions.delete(n),this.enqueue({v:1,type:`unsubscribe`,id:n})}}command(e){let t=c(),n={v:1,type:`command`,id:t,command:e};return new Promise((e,r)=>{this.pending.set(t,{resolve:e,reject:r}),this.enqueue(n)})}setFocusedChat(e){let t=c();this.enqueue({v:1,type:`command`,id:t,command:{type:`push.setFocusedChat`,chatId:e}})}ensureHealthyConnection(){let e=this.wsBridge;return!this.ws||this.ws.readyState===e.CLOSED||this.ws.readyState===e.CLOSING?(this.reconnectNow(),Promise.resolve()):this.ws.readyState===e.CONNECTING||!this.isConnectionStale()?Promise.resolve():this.sendPing()}isSendToStartingProfilingEnabled(){try{return this.sessStore.getItem(H)===`1`||this.localStore.getItem(H)===`1`}catch{return!1}}connect(){this.started&&(this.emitStatus(`connecting`),this.ws=this.wsBridge.create(this.url),this.ws.addEventListener(`open`,()=>{this.reconnectDelayMs=750,this.reconnectImmediatelyOnClose=!1,this.lastOpenAt=Date.now(),this.lastMessageAt=this.lastOpenAt,this.emitStatus(`connected`),this.startHeartbeat();for(let[e,t]of this.subscriptions.entries())this.sendNow({v:1,type:`subscribe`,id:e,topic:t.topic});for(;this.outboundQueue.length>0;){let e=this.outboundQueue.shift();e&&this.sendNow(e)}let e=d();e&&this.sendNow({v:1,type:`command`,id:c(),command:{type:`push.identifyDevice`,pushDeviceId:e}})}),this.ws.addEventListener(`message`,e=>{this.lastMessageAt=Date.now();let t=performance.now(),n=e instanceof MessageEvent?e.data:void 0,r=String(n),i;try{i=JSON.parse(r)}catch{return}if(this.isSendToStartingProfilingEnabled()&&i.type===`snapshot`&&i.snapshot.type===`chat`&&i.snapshot.data?.runtime.status===`starting`&&o.debug(`[kanna/send->starting][client-ws]`,{stage:`socket_message_received`,receivedAt:t,payloadBytes:r.length,chatId:i.snapshot.data.runtime.chatId,status:i.snapshot.data.runtime.status,messageCount:i.snapshot.data.messages.length}),this.isSendToStartingProfilingEnabled()&&i.type===`ack`&&o.debug(`[kanna/send->starting][client-ws]`,{stage:`socket_ack_received`,receivedAt:t,payloadBytes:r.length,commandId:i.id}),i.type===`snapshot`){this.subscriptions.get(i.id)?.listener(i.snapshot.data);return}if(i.type===`event`){this.subscriptions.get(i.id)?.eventListener?.(i.event);return}if(i.type===`ack`){let e=this.pending.get(i.id);if(!e)return;this.pending.delete(i.id),e.resolve(i.result);return}if(i.type===`error`){if(!i.id){o.error(a,i.message);return}let e=this.pending.get(i.id);if(!e)return;this.pending.delete(i.id),e.reject(Error(i.message))}}),this.ws.addEventListener(`close`,()=>{if(!this.started)return;let e=this.reconnectImmediatelyOnClose;this.reconnectImmediatelyOnClose=!1,this.stopHeartbeat(),this.clearPingState(),this.emitStatus(`disconnected`);for(let e of this.pending.values())e.reject(Error(`Disconnected`));if(this.pending.clear(),e){this.connect();return}this.scheduleReconnect()}))}scheduleReconnect(){this.reconnectTimer===null&&(this.reconnectTimer=this.timer.setTimeout(()=>{this.reconnectTimer=null,this.connect(),this.reconnectDelayMs=Math.min(this.reconnectDelayMs*2,5e3)},this.reconnectDelayMs))}getStatus(){let e=this.wsBridge;return this.ws?.readyState===e.OPEN?`connected`:this.ws?.readyState===e.CONNECTING?`connecting`:`disconnected`}emitStatus(e){for(let t of this.statusListeners)t(e)}isConnectionStale(){let e=Math.max(this.lastMessageAt,this.lastOpenAt);return e>0&&Date.now()-e>=z}sendPing(){if(this.pingPromise)return this.pingPromise;let e=this.command({type:`system.ping`}).then(()=>{this.clearPingState()}).catch(e=>{throw this.clearPingState(),this.reconnectNow(),e});return this.pingTimeoutTimer=this.timer.setTimeout(()=>{this.clearPingState(),this.reconnectNow()},V),this.pingPromise=e,e}reconnectNow(){let e=this.wsBridge;if(this.reconnectTimer!==null&&(this.timer.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.ws||this.ws.readyState===e.CLOSED){this.connect();return}this.ws.readyState!==e.CONNECTING&&(this.reconnectImmediatelyOnClose=!0,this.ws.close())}startHeartbeat(){this.dom.getVisibilityState()===`visible`&&this.heartbeatTimer===null&&(this.heartbeatTimer=this.timer.setInterval(()=>{if(this.dom.getVisibilityState()!==`visible`){this.stopHeartbeat();return}let e=this.wsBridge;this.ws?.readyState===e.OPEN&&m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection())},B))}stopHeartbeat(){this.heartbeatTimer!==null&&(this.timer.clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}clearPingState(){this.pingTimeoutTimer!==null&&(this.timer.clearTimeout(this.pingTimeoutTimer),this.pingTimeoutTimer=null),this.pingPromise=null}enqueue(e){let t=this.wsBridge;if(this.ws?.readyState===t.OPEN){this.sendNow(e);return}this.outboundQueue.push(e)}sendNow(e){this.ws?.send(JSON.stringify(e))}},W=(0,w.createContext)(null);function G(e){let t=e.getHref();return`${t.startsWith(`https://`)?`wss:`:`ws:`}//${new URL(t).host}/ws`}function K({children:e,socket:t,ports:n}){let r=n?.dom??i,a=(0,w.useMemo)(()=>t?null:new U(G(r),n??{}),[]),o=t??a;return(0,w.useEffect)(()=>{if(a)return a.start(),()=>{a.dispose()}},[a]),(0,P.jsx)(W.Provider,{value:o,children:e})}function q(){return(0,w.useContext)(W)}export{I as a,E as c,x as d,b as f,F as i,S as l,q as n,k as o,L as r,D as s,K as t,C as u};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./react-DiVRNtpo.js";import{n}from"./chunk-OB3PAWPO-mARpRU1A.js";import{t as r}from"./jsx-runtime-BdxMnOeJ.js";import{d as i,i as a,t as o}from"./log-DnEvbp3E.js";import{f as s,l as c}from"./pendingActionsStore-CxhI19V9.js";import{d as l,h as u,r as d,u as f}from"./pushClient-CxnHu9h4.js";import{t as p}from"./timer.adapter-C2RhP4d6.js";import{t as m}from"./runDetached-DfQXHAaY.js";import{i as h}from"./formatters-BGORekd-.js";import{i as g,n as _,r as v}from"./state-mark-C3kEL1hX.js";var y={name:`calendar-clock`,size:24,node:[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`path`,{d:`M21 7.338V5a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h2.338`,key:`7hb8p4`}],[`path`,{d:`M3 9h5.859`,key:`numkqi`}],[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]};y.node;var b=s(y),x=`h-[var(--shell-top-band)] max-h-[var(--shell-top-band)]`,S=`md:my-2 md:mr-2 md:rounded-2xl md:border md:border-border`,C=`flex min-h-0 flex-1 flex-col overflow-y-auto`,w=e(t(),1),T={timer:p};function E(e=1e3,t){let{timer:n}=t??T,[r,i]=(0,w.useState)(()=>Date.now()),a=(0,w.useRef)(e);return(0,w.useLayoutEffect)(()=>{a.current=e}),(0,w.useEffect)(()=>{let e=n.setInterval(()=>{i(Date.now())},a.current);return()=>n.clearInterval(e)},[n]),r}function D(e){return e===`inline`?`runs in this chat, context cleared each cycle`:`a new chat per run`}var O=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`];function k(e,t){if(e.type===`interval`)return A(e.ms);let{second:n,minute:r,hour:i,dom:a,month:o,dow:s}=e;if(o.kind!==`any`)return t;let c=a.kind===`any`&&s.kind===`any`;if(n!==void 0&&r.kind===`any`&&i.kind===`any`&&c){if(n.kind===`any`)return`every second`;let e=M(n.values);if(e!==null)return e===1?`every second`:`every ${e} seconds`;if(n.values.length>1)return t}let l=n===void 0?0:j(n);if(l===null)return t;let u=l===0?``:`:${N(l)}`,d=j(r),f=j(i);if(r.kind===`any`&&i.kind===`any`&&c)return l===0?`every minute`:`every minute at :${N(l)}`;if(d!==null&&i.kind===`any`&&c)return`hourly at :${N(d)}${u}`;if(d!==null&&f!==null){let e=`${N(f)}:${N(d)}${u}`;if(c)return`daily at ${e}`;if(a.kind===`any`&&s.kind===`values`)return`every ${s.values.map(e=>O[e]).join(`, `)} at ${e}`;if(s.kind===`any`&&a.kind===`values`&&a.values.length===1)return`on day ${a.values[0]} of each month at ${e}`}return t}function A(e){let t=Math.round(e/1e3);if(t%3600==0){let e=t/3600;return e===1?`every hour`:`every ${e} hours`}if(t%60==0){let e=t/60;return e===1?`every minute`:`every ${e} minutes`}return t===1?`every second`:`every ${t} seconds`}function j(e){return e.kind===`values`&&e.values.length===1?e.values[0]:null}function M(e){if(e.length<2||e[0]!==0)return null;let t=e[1];if(t<1||60%t!=0||e.length!==60/t)return null;for(let n=1;n<e.length;n++)if(e[n]!==n*t)return null;return t}function N(e){return String(e).padStart(2,`0`)}var P=e(r(),1);function F({message:e,cronJobs:t}){let r=(t?.find(t=>t.jobId===e.jobId))?.recentRuns.find(t=>t.runId===e.runId)?.status??`running`;return(0,P.jsxs)(`div`,{className:`px-0.5`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(b,{className:`h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,P.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:`Cron run`}),(0,P.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:e.jobId}),(0,P.jsxs)(`span`,{className:`ml-auto flex items-center gap-3`,children:[(0,P.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:h(e.firedAt)}),(0,P.jsx)(I,{status:r})]})]}),(0,P.jsx)(`p`,{className:`mt-1.5 text-sm text-foreground/90`,children:e.instruction}),e.spawnedChatId?(0,P.jsxs)(n,{to:`/chat/${e.spawnedChatId}`,className:`mt-2 inline-flex items-center gap-1.5 text-xs font-medium text-primary hover:underline`,children:[(0,P.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open run chat`]}):null]})}function I({status:e}){return(0,P.jsx)(_,{tone:g(e),label:v(e)})}function L(){return(0,P.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs font-medium text-muted-foreground`,children:[(0,P.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-muted-foreground`}),`Paused`]})}var R={CONNECTING:WebSocket.CONNECTING,OPEN:WebSocket.OPEN,CLOSING:WebSocket.CLOSING,CLOSED:WebSocket.CLOSED,create(e){return new WebSocket(e)}},z=25e3,B=15e3,V=4e3,H=`kanna:profile-send-to-starting`,U=class{url;ws=null;started=!1;reconnectTimer=null;reconnectDelayMs=750;subscriptions=new Map;pending=new Map;outboundQueue=[];statusListeners=new Set;heartbeatTimer=null;pingTimeoutTimer=null;pingPromise=null;lastOpenAt=0;lastMessageAt=0;reconnectImmediatelyOnClose=!1;serviceWorkerCleanup=null;dom;timer;localStore;sessStore;wsBridge;handleWindowFocus=()=>{m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection())};handleVisibilityChange=()=>{if(this.dom.getVisibilityState()===`visible`){this.startHeartbeat(),m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection());return}this.stopHeartbeat()};handleOnline=()=>{m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection())};constructor(e,t={}){this.url=e,this.dom=t.dom??i,this.timer=t.timer??p,this.localStore=t.localStorage??f,this.sessStore=t.sessionStorage??l,this.wsBridge=t.webSocket??R}start(){this.started||(this.started=!0,this.serviceWorkerCleanup=this.dom.addServiceWorkerMessageListener(e=>{let t=e.data;t?.type===`kanna.navigate`&&typeof t.url==`string`&&this.dom.setHref(t.url)}),this.dom.addWindowListener(`focus`,this.handleWindowFocus),this.dom.addWindowListener(`online`,this.handleOnline),this.dom.addDocumentListener(`visibilitychange`,this.handleVisibilityChange),this.connect())}dispose(){this.started=!1,this.reconnectTimer&&=(this.timer.clearTimeout(this.reconnectTimer),null),this.stopHeartbeat(),this.clearPingState(),this.serviceWorkerCleanup&&=(this.serviceWorkerCleanup(),null),this.ws?.close(),this.ws=null;for(let e of this.pending.values())e.reject(Error(`Socket disposed`));this.pending.clear()}onStatus(e){return this.statusListeners.add(e),e(this.getStatus()),()=>{this.statusListeners.delete(e)}}subscribe(e,t,n){let r=c(),i={topic:e,listener:t,eventListener:n};return this.subscriptions.set(r,i),this.enqueue({v:1,type:`subscribe`,id:r,topic:e}),()=>{this.subscriptions.delete(r),this.enqueue({v:1,type:`unsubscribe`,id:r})}}subscribeTerminal(e,t){let n=c(),r={type:`terminal`,terminalId:e},i={topic:r,listener:t.onSnapshot,eventListener:t.onEvent};return this.subscriptions.set(n,i),this.enqueue({v:1,type:`subscribe`,id:n,topic:r}),()=>{this.subscriptions.delete(n),this.enqueue({v:1,type:`unsubscribe`,id:n})}}command(e){let t=c(),n={v:1,type:`command`,id:t,command:e};return new Promise((e,r)=>{this.pending.set(t,{resolve:e,reject:r}),this.enqueue(n)})}setFocusedChat(e){let t=c();this.enqueue({v:1,type:`command`,id:t,command:{type:`push.setFocusedChat`,chatId:e}})}ensureHealthyConnection(){let e=this.wsBridge;return!this.ws||this.ws.readyState===e.CLOSED||this.ws.readyState===e.CLOSING?(this.reconnectNow(),Promise.resolve()):this.ws.readyState===e.CONNECTING||!this.isConnectionStale()?Promise.resolve():this.sendPing()}isSendToStartingProfilingEnabled(){try{return this.sessStore.getItem(H)===`1`||this.localStore.getItem(H)===`1`}catch{return!1}}connect(){this.started&&(this.emitStatus(`connecting`),this.ws=this.wsBridge.create(this.url),this.ws.addEventListener(`open`,()=>{this.reconnectDelayMs=750,this.reconnectImmediatelyOnClose=!1,this.lastOpenAt=Date.now(),this.lastMessageAt=this.lastOpenAt,this.emitStatus(`connected`),this.startHeartbeat();for(let[e,t]of this.subscriptions.entries())this.sendNow({v:1,type:`subscribe`,id:e,topic:t.topic});for(;this.outboundQueue.length>0;){let e=this.outboundQueue.shift();e&&this.sendNow(e)}let e=d();e&&this.sendNow({v:1,type:`command`,id:c(),command:{type:`push.identifyDevice`,pushDeviceId:e}})}),this.ws.addEventListener(`message`,e=>{this.lastMessageAt=Date.now();let t=performance.now(),n=e instanceof MessageEvent?e.data:void 0,r=String(n),i;try{i=JSON.parse(r)}catch{return}if(this.isSendToStartingProfilingEnabled()&&i.type===`snapshot`&&i.snapshot.type===`chat`&&i.snapshot.data?.runtime.status===`starting`&&o.debug(`[kanna/send->starting][client-ws]`,{stage:`socket_message_received`,receivedAt:t,payloadBytes:r.length,chatId:i.snapshot.data.runtime.chatId,status:i.snapshot.data.runtime.status,messageCount:i.snapshot.data.messages.length}),this.isSendToStartingProfilingEnabled()&&i.type===`ack`&&o.debug(`[kanna/send->starting][client-ws]`,{stage:`socket_ack_received`,receivedAt:t,payloadBytes:r.length,commandId:i.id}),i.type===`snapshot`){this.subscriptions.get(i.id)?.listener(i.snapshot.data);return}if(i.type===`event`){this.subscriptions.get(i.id)?.eventListener?.(i.event);return}if(i.type===`ack`){let e=this.pending.get(i.id);if(!e)return;this.pending.delete(i.id),e.resolve(i.result);return}if(i.type===`error`){if(!i.id){o.error(a,i.message);return}let e=this.pending.get(i.id);if(!e)return;this.pending.delete(i.id),e.reject(Error(i.message))}}),this.ws.addEventListener(`close`,()=>{if(!this.started)return;let e=this.reconnectImmediatelyOnClose;this.reconnectImmediatelyOnClose=!1,this.stopHeartbeat(),this.clearPingState(),this.emitStatus(`disconnected`);for(let e of this.pending.values())e.reject(Error(`Disconnected`));if(this.pending.clear(),e){this.connect();return}this.scheduleReconnect()}))}scheduleReconnect(){this.reconnectTimer===null&&(this.reconnectTimer=this.timer.setTimeout(()=>{this.reconnectTimer=null,this.connect(),this.reconnectDelayMs=Math.min(this.reconnectDelayMs*2,5e3)},this.reconnectDelayMs))}getStatus(){let e=this.wsBridge;return this.ws?.readyState===e.OPEN?`connected`:this.ws?.readyState===e.CONNECTING?`connecting`:`disconnected`}emitStatus(e){for(let t of this.statusListeners)t(e)}isConnectionStale(){let e=Math.max(this.lastMessageAt,this.lastOpenAt);return e>0&&Date.now()-e>=z}sendPing(){if(this.pingPromise)return this.pingPromise;let e=this.command({type:`system.ping`}).then(()=>{this.clearPingState()}).catch(e=>{throw this.clearPingState(),this.reconnectNow(),e});return this.pingTimeoutTimer=this.timer.setTimeout(()=>{this.clearPingState(),this.reconnectNow()},V),this.pingPromise=e,e}reconnectNow(){let e=this.wsBridge;if(this.reconnectTimer!==null&&(this.timer.clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.ws||this.ws.readyState===e.CLOSED){this.connect();return}this.ws.readyState!==e.CONNECTING&&(this.reconnectImmediatelyOnClose=!0,this.ws.close())}startHeartbeat(){this.dom.getVisibilityState()===`visible`&&this.heartbeatTimer===null&&(this.heartbeatTimer=this.timer.setInterval(()=>{if(this.dom.getVisibilityState()!==`visible`){this.stopHeartbeat();return}let e=this.wsBridge;this.ws?.readyState===e.OPEN&&m(`socket.ensureHealthyConnection`,this.ensureHealthyConnection())},B))}stopHeartbeat(){this.heartbeatTimer!==null&&(this.timer.clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}clearPingState(){this.pingTimeoutTimer!==null&&(this.timer.clearTimeout(this.pingTimeoutTimer),this.pingTimeoutTimer=null),this.pingPromise=null}enqueue(e){let t=this.wsBridge;if(this.ws?.readyState===t.OPEN){this.sendNow(e);return}this.outboundQueue.push(e)}sendNow(e){this.ws?.send(JSON.stringify(e))}},W=(0,w.createContext)(null);function G(e){let t=e.getHref();return`${t.startsWith(`https://`)?`wss:`:`ws:`}//${new URL(t).host}/ws`}function K({children:e,socket:t,ports:n}){let r=n?.dom??i,a=(0,w.useMemo)(()=>t?null:new U(G(r),n??{}),[]),o=t??a;return(0,w.useEffect)(()=>{if(a)return a.start(),()=>{a.dispose()}},[a]),(0,P.jsx)(W.Provider,{value:o,children:e})}function q(){return(0,w.useContext)(W)}export{I as a,E as c,x as d,b as f,F as i,S as l,q as n,k as o,L as r,D as s,K as t,C as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./react-DiVRNtpo.js";import{l as n}from"./chunk-OB3PAWPO-mARpRU1A.js";import{t as r}from"./jsx-runtime-BdxMnOeJ.js";import{a as i,c as a,n as o,o as s,r as c}from"./log-aTaDVF_e.js";import{a as l,c as u,d,n as f,r as p}from"./pendingActionsStore-COTh4Ztq.js";import{n as m,r as h,t as g}from"./clipboard.adapter-GN9nnYak.js";import{n as _,r as v,t as y}from"./terminal-Bnj7qFGw.js";import{t as b}from"./folder-C7sXCaHj.js";import{t as x}from"./monitor-_CRKcV1h.js";import{t as S}from"./plus-c75CkNEO.js";import{t as C}from"./square-pen-B1IxmScM.js";import{i as w,n as T,o as ee,r as te,t as E,u as D}from"./timer.adapter-DHt2zwsL.js";import{a as O,c as k,o as A,t as j}from"./segmented-control-DNOwRupT.js";import{t as M}from"./createScopedStore-BoLB9Rhc.js";import{t as N}from"./input-C4fvDiQ4.js";import{t as P}from"./runDetached-DqQ3k2ji.js";import{n as F,u as I}from"./sidebarPendingActions-Dyp80Lv_.js";import{o as L}from"./formatters-wSVyvDFZ.js";var R=e(t(),1),z=M(`CopyButton`,()=>e=>({copied:!1,setCopied:t=>e({copied:t})})),B=e(r(),1);function V({narrow:e=!1,title:t,subtitle:n,icon:r=x}){return(0,B.jsxs)(`div`,{className:u(`w-full`,e?`max-w-2xl px-6 pt-16 mx-auto`:`px-6 pt-16 mb-10`),children:[(0,B.jsxs)(`div`,{className:u(`flex items-center gap-1 mb-2`,e&&`justify-center`),children:[(0,B.jsx)(`div`,{className:`p-2 pl-0 rounded-lg`,children:(0,B.jsx)(r,{className:`h-6 w-6 text-muted-foreground`})}),(0,B.jsx)(`h1`,{className:`text-2xl font-semibold text-foreground`,children:t})]}),n&&(0,B.jsx)(`p`,{className:u(`text-muted-foreground`,e&&`mb-10 text-center`),children:n})]})}var H=a()(e=>({tab:`new`,name:``,existingPath:``,setTab:t=>e({tab:t}),setName:t=>e({name:t}),setExistingPath:t=>e({existingPath:t}),resetForOpen:()=>e({tab:`new`,name:``,existingPath:``})})),U=()=>H(e=>e.tab),W=()=>H(e=>e.name),G=()=>H(e=>e.existingPath);function K(e){return e.toLowerCase().replace(/[\s_]+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``)}function q({open:e,onOpenChange:t,onConfirm:n,ports:r={}}){let i=r.timer??E,a=U(),o=W(),s=G(),u=H(e=>e.setTab),d=H(e=>e.setName),f=H(e=>e.setExistingPath),p=H(e=>e.resetForOpen),m=(0,R.useRef)(null),h=(0,R.useRef)(null);(0,R.useEffect)(()=>{e&&(p(),i.setTimeout(()=>m.current?.focus(),0))},[e,p,i]),(0,R.useEffect)(()=>{e&&i.setTimeout(()=>{a===`new`?m.current?.focus():h.current?.focus()},0)},[a,e,i]);let g=K(o),_=g?`${c}/${g}`:``,v=s.trim(),y=a===`new`?!!g:!!v,b=()=>{if(y){if(a===`new`)n({mode:`new`,localPath:_,title:o.trim()});else{let e=v.split(`/`).pop()||v;n({mode:`existing`,localPath:v,title:e})}t(!1)}};return(0,B.jsx)(T,{open:e,onOpenChange:t,children:(0,B.jsxs)(w,{size:`sm`,children:[(0,B.jsxs)(te,{className:`space-y-4`,children:[(0,B.jsx)(D,{children:`Add Project`}),(0,B.jsx)(j,{value:a,onValueChange:u,options:[{value:`new`,label:`New Folder`},{value:`existing`,label:`Existing Path`}],className:`w-full mb-2`,optionClassName:`flex-1 justify-center`}),a===`new`?(0,B.jsxs)(`div`,{className:`space-y-2`,children:[(0,B.jsx)(N,{ref:m,type:`text`,value:o,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&t(!1)},placeholder:`Project name`}),_&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground font-mono`,children:_})]}):(0,B.jsxs)(`div`,{className:`space-y-2`,children:[(0,B.jsx)(N,{ref:h,type:`text`,value:s,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&t(!1)},placeholder:`~/Projects/my-app`}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The folder will be created if it doesn't exist.`})]})]}),(0,B.jsxs)(ee,{children:[(0,B.jsx)(l,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,B.jsx)(l,{variant:`secondary`,size:`sm`,onClick:b,disabled:!y,children:`Create`})]})]})})}function ne({text:e,ports:t={}}){let n=z.useScopedStore(e=>e.copied),r=z.useScopedStore(e=>e.setCopied),i=t.clipboard??g,a=t.timer??E;async function o(){await i.writeText(e),r(!0),a.setTimeout(()=>r(!1),2e3)}return(0,B.jsx)(l,{variant:`ghost`,size:`icon-mobile`,"aria-label":n?`Copied`:`Copy to clipboard`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>P(`copy command`,o()),children:n?(0,B.jsx)(h,{className:`h-4 w-4 text-success-text`}):(0,B.jsx)(m,{className:`h-4 w-4`})})}function re({text:e}){return(0,B.jsx)(z.Provider,{init:{},children:(0,B.jsx)(ne,{text:e})})}function J({children:e}){return(0,B.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-center group bg-background border border-border text-foreground rounded-xl p-1.5 pl-3 font-mono text-sm`,children:[(0,B.jsxs)(`pre`,{className:`inline-flex items-center gap-2 overflow-x-auto`,children:[(0,B.jsx)(v,{className:`inline h-4 w-4 opacity-40`}),(0,B.jsx)(`code`,{children:e})]}),(0,B.jsx)(re,{text:e})]})}function Y({children:e}){return(0,B.jsx)(`div`,{className:`bg-card border border-border rounded-2xl p-4`,children:e})}function X({children:e}){return(0,B.jsx)(`h2`,{className:`text-13 font-medium text-muted-foreground tracking-wider mb-3`,children:e})}function Z({icon:e,title:t,subtitle:n,iconClassName:r}){return(0,B.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5 min-w-0`,children:[(0,B.jsx)(e,{className:r||`h-5 w-5 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:t}),(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground leading-tight`,children:n})]})}function Q(){return(0,B.jsx)(`div`,{"aria-hidden":!0,className:`mt-5 h-px w-6 shrink-0 bg-border`})}function $({number:e,title:t,children:n}){return(0,B.jsx)(`div`,{className:`flex gap-4`,children:(0,B.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,B.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr] items-baseline gap-3`,children:[(0,B.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-center font-medium text-logo`,children:[e,`.`]}),(0,B.jsx)(`h3`,{className:`font-medium text-foreground mb-2`,children:t})]}),(0,B.jsx)(`div`,{className:`text-muted-foreground text-sm space-y-3`,children:n})]})})}function ie({localPath:e,starting:t,onOpenProject:n}){let r=p(I(e))||t;return(0,B.jsxs)(O,{children:[(0,B.jsx)(k,{asChild:!0,children:(0,B.jsxs)(`button`,{className:u(`border border-border hover:border-primary/30 group rounded-lg bg-card px-4 py-3 flex items-center gap-3 w-full text-left hover:bg-muted/50 transition-colors`,r&&`opacity-50 cursor-not-allowed`),disabled:r,"aria-busy":r||void 0,onClick:()=>f(I(e),()=>n(e)),children:[(0,B.jsx)(b,{className:`h-4 w-4 text-muted-foreground flex-shrink-0`}),(0,B.jsx)(`span`,{className:`font-medium text-foreground truncate flex-1`,children:L(e)}),r?(0,B.jsx)(d,{className:`h-4 w-4 text-muted-foreground group-hover:text-primary animate-spin flex-shrink-0`}):(0,B.jsx)(C,{className:`h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`})]})}),(0,B.jsx)(A,{children:(0,B.jsx)(`p`,{children:e})})]})}function ae({connectionStatus:e,ready:t,snapshot:n,startingLocalPath:r,commandError:a,newProjectOpen:c,onNewProjectOpenChange:u,onOpenProject:m,onCreateProject:h}){let g=(0,R.useMemo)(()=>n?.projects??[],[n?.projects]),v=e===`connecting`||!t,b=e===`connected`&&t,C=p(F);return(0,B.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 bg-background overflow-y-auto`,children:[b?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(V,{title:n?.machine.displayName??`Local Projects`,subtitle:`${o} is connected, choose a project below to get started.`}),(0,B.jsxs)(`div`,{className:`w-full px-6 mb-10`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between mb-3`,children:[(0,B.jsx)(`h2`,{className:`text-13 font-medium text-muted-foreground tracking-wider`,children:`Projects`}),(0,B.jsxs)(l,{variant:`default`,size:`sm`,pending:C,onClick:()=>u(!0),children:[C?null:(0,B.jsx)(S,{className:`h-4 w-4 mr-1.5`}),`Add Project`]})]}),g.length>0?(0,B.jsx)(`div`,{className:`grid gap-2 [grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr))]`,children:g.map(e=>(0,B.jsx)(ie,{localPath:e.localPath,starting:r===e.localPath,onOpenProject:m},e.localPath))}):(0,B.jsx)(Y,{children:(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No local projects discovered yet. Open one with Claude or Codex, or create a new project here.`})}),a?(0,B.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/20 bg-destructive/5 rounded-xl px-4 py-3 mt-4`,children:a}):null]})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(V,{narrow:!0,icon:_,title:v?`Connecting ${o}`:`Connect ${o}`,subtitle:v?`${o} is starting up and loading your local projects.`:`Run ${o} directly on your machine with full access to your local files and agent project history.`}),(0,B.jsxs)(`div`,{className:`max-w-2xl w-full mx-auto pb-12 px-6`,children:[(0,B.jsx)(X,{children:`Status`}),(0,B.jsx)(`div`,{className:`mb-8`,children:(0,B.jsx)(Y,{children:(0,B.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,B.jsx)(d,{className:`h-4 w-4 text-muted-foreground animate-spin`}),(0,B.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:v?`Connecting to your local ${o} server...`:(0,B.jsxs)(B.Fragment,{children:[`Not connected. Run `,(0,B.jsx)(`code`,{className:`bg-background border border-border rounded-md mx-0.5 p-1 font-mono text-xs text-foreground`,children:s()}),` from any terminal on this machine.`]})})]})})}),v?null:(0,B.jsxs)(`div`,{className:`mb-10`,children:[(0,B.jsx)(X,{children:`How it works`}),(0,B.jsx)(Y,{children:(0,B.jsxs)(`div`,{className:`flex items-start gap-4 py-2 px-2`,children:[(0,B.jsx)(Z,{icon:y,title:`${o} CLI`,subtitle:`On Your Machine`}),(0,B.jsx)(Q,{}),(0,B.jsx)(Z,{icon:x,title:`${o} Server`,subtitle:`Local WebSocket`}),(0,B.jsx)(Q,{}),(0,B.jsx)(Z,{icon:_,title:`${o} UI`,subtitle:`Project Chat`})]})})]}),v?null:(0,B.jsxs)(`div`,{className:`mb-10`,children:[(0,B.jsx)(X,{children:`Setup`}),(0,B.jsx)(Y,{children:(0,B.jsxs)(`div`,{className:`space-y-4`,children:[(0,B.jsxs)($,{number:1,title:`Start ${o}`,children:[(0,B.jsx)(`p`,{children:`Run this command in your terminal:`}),(0,B.jsx)(J,{children:s()})]}),(0,B.jsxs)($,{number:2,title:`Open the local UI`,children:[(0,B.jsxs)(`p`,{children:[o,` serves the app locally and opens the Local Projects page in an app-style browser window.`]}),(0,B.jsx)(J,{children:`http://localhost:3210/local`})]}),(0,B.jsxs)(`div`,{className:`mt-8`,children:[(0,B.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground tracking-wider mb-4`,children:`Notes`}),(0,B.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:s(``).trim()}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Start in the current directory`})]}),(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:s(`--no-open`)}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Start the server without opening the browser`})]})]})]})]})})]})]})]}),(0,B.jsx)(q,{open:c,onOpenChange:u,onConfirm:e=>{f(F,()=>h(e))}}),(0,B.jsx)(`div`,{className:`py-4 text-center`,children:(0,B.jsxs)(`span`,{className:`text-xs text-muted-foreground/50`,children:[`v`,i.split(`/`)[1]]})})]})}function oe(){let e=n();return(0,B.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0 relative`,children:(0,B.jsx)(ae,{connectionStatus:e.connectionStatus,ready:e.localProjectsReady,snapshot:e.localProjects,startingLocalPath:e.startingLocalPath,commandError:e.commandError,newProjectOpen:e.addProjectModalOpen,onNewProjectOpenChange:t=>{if(t){e.openAddProjectModal();return}e.closeAddProjectModal()},onOpenProject:e.handleOpenLocalProject,onCreateProject:e.handleCreateProject})})}export{oe as LocalProjectsPage};
|
|
1
|
+
import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{t}from"./react-DiVRNtpo.js";import{l as n}from"./chunk-OB3PAWPO-mARpRU1A.js";import{t as r}from"./jsx-runtime-BdxMnOeJ.js";import{a as i,c as a,n as o,o as s,r as c}from"./log-DnEvbp3E.js";import{a as l,c as u,d,n as f,r as p}from"./pendingActionsStore-CxhI19V9.js";import{n as m,r as h,t as g}from"./clipboard.adapter-CgdNwn-1.js";import{n as _,r as v,t as y}from"./terminal-DfCF-J4p.js";import{t as b}from"./folder-CnWzWIG5.js";import{t as x}from"./monitor-qbWfUdBG.js";import{t as S}from"./plus-D4CI6rj1.js";import{t as C}from"./square-pen-DmppQdTd.js";import{i as w,n as T,o as ee,r as te,t as E,u as D}from"./timer.adapter-C2RhP4d6.js";import{a as O,c as k,o as A,t as j}from"./segmented-control-CKGX29Kl.js";import{t as M}from"./createScopedStore-BrD5NHWx.js";import{t as N}from"./input-DgW9uRZN.js";import{t as P}from"./runDetached-DfQXHAaY.js";import{n as F,u as I}from"./sidebarPendingActions-xgMTnfRY.js";import{a as L}from"./formatters-BGORekd-.js";var R=e(t(),1),z=M(`CopyButton`,()=>e=>({copied:!1,setCopied:t=>e({copied:t})})),B=e(r(),1);function V({narrow:e=!1,title:t,subtitle:n,icon:r=x}){return(0,B.jsxs)(`div`,{className:u(`w-full`,e?`max-w-2xl px-6 pt-16 mx-auto`:`px-6 pt-16 mb-10`),children:[(0,B.jsxs)(`div`,{className:u(`flex items-center gap-1 mb-2`,e&&`justify-center`),children:[(0,B.jsx)(`div`,{className:`p-2 pl-0 rounded-lg`,children:(0,B.jsx)(r,{className:`h-6 w-6 text-muted-foreground`})}),(0,B.jsx)(`h1`,{className:`text-2xl font-semibold text-foreground`,children:t})]}),n&&(0,B.jsx)(`p`,{className:u(`text-muted-foreground`,e&&`mb-10 text-center`),children:n})]})}var H=a()(e=>({tab:`new`,name:``,existingPath:``,setTab:t=>e({tab:t}),setName:t=>e({name:t}),setExistingPath:t=>e({existingPath:t}),resetForOpen:()=>e({tab:`new`,name:``,existingPath:``})})),U=()=>H(e=>e.tab),W=()=>H(e=>e.name),G=()=>H(e=>e.existingPath);function K(e){return e.toLowerCase().replace(/[\s_]+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``)}function q({open:e,onOpenChange:t,onConfirm:n,ports:r={}}){let i=r.timer??E,a=U(),o=W(),s=G(),u=H(e=>e.setTab),d=H(e=>e.setName),f=H(e=>e.setExistingPath),p=H(e=>e.resetForOpen),m=(0,R.useRef)(null),h=(0,R.useRef)(null);(0,R.useEffect)(()=>{e&&(p(),i.setTimeout(()=>m.current?.focus(),0))},[e,p,i]),(0,R.useEffect)(()=>{e&&i.setTimeout(()=>{a===`new`?m.current?.focus():h.current?.focus()},0)},[a,e,i]);let g=K(o),_=g?`${c}/${g}`:``,v=s.trim(),y=a===`new`?!!g:!!v,b=()=>{if(y){if(a===`new`)n({mode:`new`,localPath:_,title:o.trim()});else{let e=v.split(`/`).pop()||v;n({mode:`existing`,localPath:v,title:e})}t(!1)}};return(0,B.jsx)(T,{open:e,onOpenChange:t,children:(0,B.jsxs)(w,{size:`sm`,children:[(0,B.jsxs)(te,{className:`space-y-4`,children:[(0,B.jsx)(D,{children:`Add Project`}),(0,B.jsx)(j,{value:a,onValueChange:u,options:[{value:`new`,label:`New Folder`},{value:`existing`,label:`Existing Path`}],className:`w-full mb-2`,optionClassName:`flex-1 justify-center`}),a===`new`?(0,B.jsxs)(`div`,{className:`space-y-2`,children:[(0,B.jsx)(N,{ref:m,type:`text`,value:o,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&t(!1)},placeholder:`Project name`}),_&&(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground font-mono`,children:_})]}):(0,B.jsxs)(`div`,{className:`space-y-2`,children:[(0,B.jsx)(N,{ref:h,type:`text`,value:s,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b(),e.key===`Escape`&&t(!1)},placeholder:`~/Projects/my-app`}),(0,B.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The folder will be created if it doesn't exist.`})]})]}),(0,B.jsxs)(ee,{children:[(0,B.jsx)(l,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,B.jsx)(l,{variant:`secondary`,size:`sm`,onClick:b,disabled:!y,children:`Create`})]})]})})}function ne({text:e,ports:t={}}){let n=z.useScopedStore(e=>e.copied),r=z.useScopedStore(e=>e.setCopied),i=t.clipboard??g,a=t.timer??E;async function o(){await i.writeText(e),r(!0),a.setTimeout(()=>r(!1),2e3)}return(0,B.jsx)(l,{variant:`ghost`,size:`icon-mobile`,"aria-label":n?`Copied`:`Copy to clipboard`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>P(`copy command`,o()),children:n?(0,B.jsx)(h,{className:`h-4 w-4 text-success-text`}):(0,B.jsx)(m,{className:`h-4 w-4`})})}function re({text:e}){return(0,B.jsx)(z.Provider,{init:{},children:(0,B.jsx)(ne,{text:e})})}function J({children:e}){return(0,B.jsxs)(`div`,{className:`grid grid-cols-[1fr_auto] items-center group bg-background border border-border text-foreground rounded-xl p-1.5 pl-3 font-mono text-sm`,children:[(0,B.jsxs)(`pre`,{className:`inline-flex items-center gap-2 overflow-x-auto`,children:[(0,B.jsx)(v,{className:`inline h-4 w-4 opacity-40`}),(0,B.jsx)(`code`,{children:e})]}),(0,B.jsx)(re,{text:e})]})}function Y({children:e}){return(0,B.jsx)(`div`,{className:`bg-card border border-border rounded-2xl p-4`,children:e})}function X({children:e}){return(0,B.jsx)(`h2`,{className:`text-13 font-medium text-muted-foreground tracking-wider mb-3`,children:e})}function Z({icon:e,title:t,subtitle:n,iconClassName:r}){return(0,B.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5 min-w-0`,children:[(0,B.jsx)(e,{className:r||`h-5 w-5 text-muted-foreground`}),(0,B.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:t}),(0,B.jsx)(`span`,{className:`text-xs text-muted-foreground leading-tight`,children:n})]})}function Q(){return(0,B.jsx)(`div`,{"aria-hidden":!0,className:`mt-5 h-px w-6 shrink-0 bg-border`})}function $({number:e,title:t,children:n}){return(0,B.jsx)(`div`,{className:`flex gap-4`,children:(0,B.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,B.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr] items-baseline gap-3`,children:[(0,B.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-center font-medium text-logo`,children:[e,`.`]}),(0,B.jsx)(`h3`,{className:`font-medium text-foreground mb-2`,children:t})]}),(0,B.jsx)(`div`,{className:`text-muted-foreground text-sm space-y-3`,children:n})]})})}function ie({localPath:e,starting:t,onOpenProject:n}){let r=p(I(e))||t;return(0,B.jsxs)(O,{children:[(0,B.jsx)(k,{asChild:!0,children:(0,B.jsxs)(`button`,{className:u(`border border-border hover:border-primary/30 group rounded-lg bg-card px-4 py-3 flex items-center gap-3 w-full text-left hover:bg-muted/50 transition-colors`,r&&`opacity-50 cursor-not-allowed`),disabled:r,"aria-busy":r||void 0,onClick:()=>f(I(e),()=>n(e)),children:[(0,B.jsx)(b,{className:`h-4 w-4 text-muted-foreground flex-shrink-0`}),(0,B.jsx)(`span`,{className:`font-medium text-foreground truncate flex-1`,children:L(e)}),r?(0,B.jsx)(d,{className:`h-4 w-4 text-muted-foreground group-hover:text-primary animate-spin flex-shrink-0`}):(0,B.jsx)(C,{className:`h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`})]})}),(0,B.jsx)(A,{children:(0,B.jsx)(`p`,{children:e})})]})}function ae({connectionStatus:e,ready:t,snapshot:n,startingLocalPath:r,commandError:a,newProjectOpen:c,onNewProjectOpenChange:u,onOpenProject:m,onCreateProject:h}){let g=(0,R.useMemo)(()=>n?.projects??[],[n?.projects]),v=e===`connecting`||!t,b=e===`connected`&&t,C=p(F);return(0,B.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 bg-background overflow-y-auto`,children:[b?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(V,{title:n?.machine.displayName??`Local Projects`,subtitle:`${o} is connected, choose a project below to get started.`}),(0,B.jsxs)(`div`,{className:`w-full px-6 mb-10`,children:[(0,B.jsxs)(`div`,{className:`flex items-baseline justify-between mb-3`,children:[(0,B.jsx)(`h2`,{className:`text-13 font-medium text-muted-foreground tracking-wider`,children:`Projects`}),(0,B.jsxs)(l,{variant:`default`,size:`sm`,pending:C,onClick:()=>u(!0),children:[C?null:(0,B.jsx)(S,{className:`h-4 w-4 mr-1.5`}),`Add Project`]})]}),g.length>0?(0,B.jsx)(`div`,{className:`grid gap-2 [grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr))]`,children:g.map(e=>(0,B.jsx)(ie,{localPath:e.localPath,starting:r===e.localPath,onOpenProject:m},e.localPath))}):(0,B.jsx)(Y,{children:(0,B.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No local projects discovered yet. Open one with Claude or Codex, or create a new project here.`})}),a?(0,B.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/20 bg-destructive/5 rounded-xl px-4 py-3 mt-4`,children:a}):null]})]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(V,{narrow:!0,icon:_,title:v?`Connecting ${o}`:`Connect ${o}`,subtitle:v?`${o} is starting up and loading your local projects.`:`Run ${o} directly on your machine with full access to your local files and agent project history.`}),(0,B.jsxs)(`div`,{className:`max-w-2xl w-full mx-auto pb-12 px-6`,children:[(0,B.jsx)(X,{children:`Status`}),(0,B.jsx)(`div`,{className:`mb-8`,children:(0,B.jsx)(Y,{children:(0,B.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,B.jsx)(d,{className:`h-4 w-4 text-muted-foreground animate-spin`}),(0,B.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:v?`Connecting to your local ${o} server...`:(0,B.jsxs)(B.Fragment,{children:[`Not connected. Run `,(0,B.jsx)(`code`,{className:`bg-background border border-border rounded-md mx-0.5 p-1 font-mono text-xs text-foreground`,children:s()}),` from any terminal on this machine.`]})})]})})}),v?null:(0,B.jsxs)(`div`,{className:`mb-10`,children:[(0,B.jsx)(X,{children:`How it works`}),(0,B.jsx)(Y,{children:(0,B.jsxs)(`div`,{className:`flex items-start gap-4 py-2 px-2`,children:[(0,B.jsx)(Z,{icon:y,title:`${o} CLI`,subtitle:`On Your Machine`}),(0,B.jsx)(Q,{}),(0,B.jsx)(Z,{icon:x,title:`${o} Server`,subtitle:`Local WebSocket`}),(0,B.jsx)(Q,{}),(0,B.jsx)(Z,{icon:_,title:`${o} UI`,subtitle:`Project Chat`})]})})]}),v?null:(0,B.jsxs)(`div`,{className:`mb-10`,children:[(0,B.jsx)(X,{children:`Setup`}),(0,B.jsx)(Y,{children:(0,B.jsxs)(`div`,{className:`space-y-4`,children:[(0,B.jsxs)($,{number:1,title:`Start ${o}`,children:[(0,B.jsx)(`p`,{children:`Run this command in your terminal:`}),(0,B.jsx)(J,{children:s()})]}),(0,B.jsxs)($,{number:2,title:`Open the local UI`,children:[(0,B.jsxs)(`p`,{children:[o,` serves the app locally and opens the Local Projects page in an app-style browser window.`]}),(0,B.jsx)(J,{children:`http://localhost:3210/local`})]}),(0,B.jsxs)(`div`,{className:`mt-8`,children:[(0,B.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground tracking-wider mb-4`,children:`Notes`}),(0,B.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:s(``).trim()}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Start in the current directory`})]}),(0,B.jsxs)(`div`,{className:`flex gap-4`,children:[(0,B.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:s(`--no-open`)}),(0,B.jsx)(`span`,{className:`text-muted-foreground`,children:`Start the server without opening the browser`})]})]})]})]})})]})]})]}),(0,B.jsx)(q,{open:c,onOpenChange:u,onConfirm:e=>{f(F,()=>h(e))}}),(0,B.jsx)(`div`,{className:`py-4 text-center`,children:(0,B.jsxs)(`span`,{className:`text-xs text-muted-foreground/50`,children:[`v`,i.split(`/`)[1]]})})]})}function oe(){let e=n();return(0,B.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0 relative`,children:(0,B.jsx)(ae,{connectionStatus:e.connectionStatus,ready:e.localProjectsReady,snapshot:e.localProjects,startingLocalPath:e.startingLocalPath,commandError:e.commandError,newProjectOpen:e.addProjectModalOpen,onNewProjectOpenChange:t=>{if(t){e.openAddProjectModal();return}e.closeAddProjectModal()},onOpenProject:e.handleOpenLocalProject,onCreateProject:e.handleCreateProject})})}export{oe as LocalProjectsPage};
|