@cuongtran001/kanna 1.97.0 → 1.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/client/assets/{BoardsPage-D3TlgAZ_.js → BoardsPage-CPdXl_9L.js} +1 -1
  2. package/dist/client/assets/{BoardsRoutePage-VkxV-IFk.js → BoardsRoutePage-DrTFjpAZ.js} +1 -1
  3. package/dist/client/assets/{ChatPage-Dscf_7rF.js → ChatPage-CGQoeYXf.js} +7 -7
  4. package/dist/client/assets/{CronJobsPage-CRkUkXat.js → CronJobsPage-B7o8EhRk.js} +1 -1
  5. package/dist/client/assets/{FilePreviewSheet-DeowWf5y.js → FilePreviewSheet-CfXThsQp.js} +1 -1
  6. package/dist/client/assets/{FlowSurface-CWsaGLfa.js → FlowSurface-CdVOTRYI.js} +1 -1
  7. package/dist/client/assets/{GenUIBlock-Bv-OFgT5.js → GenUIBlock-B3QE4V69.js} +2 -2
  8. package/dist/client/assets/{InboundHandlerFields-Bz-crPWC.js → InboundHandlerFields-CDVZGRJq.js} +1 -1
  9. package/dist/client/assets/InboxPage-C29v9zbq.js +1 -0
  10. package/dist/client/assets/{LocalProjectsPage-Lx4uBsJV.js → LocalProjectsPage-BYEjT-DZ.js} +1 -1
  11. package/dist/client/assets/SettingsPage-Bl7lDxe0.js +17 -0
  12. package/dist/client/assets/{StackBoardsRoutePage-Uy6E-3Gl.js → StackBoardsRoutePage-D8OwGaO7.js} +1 -1
  13. package/dist/client/assets/{ToolCallMessage-DEfxdq5H.js → ToolCallMessage-BFqfgkCH.js} +1 -1
  14. package/dist/client/assets/{VChartSurface-UFK0UlX-.js → VChartSurface-CMQoKhau.js} +1 -1
  15. package/dist/client/assets/{WebhooksPage-6ALLVh_l.js → WebhooksPage-DMmDX-ms.js} +2 -2
  16. package/dist/client/assets/{WorkflowsPage-1i5hmCxm.js → WorkflowsPage-DvfGbRlt.js} +1 -1
  17. package/dist/client/assets/{appSettingsStore-DhpIEBz2.js → appSettingsStore-BkV1YU8S.js} +1 -1
  18. package/dist/client/assets/{arrow-left-Bto85Swe.js → arrow-left-CjtboDsu.js} +1 -1
  19. package/dist/client/assets/{beacon-alias-HmDCskK6.js → beacon-alias-rXxwPHhZ.js} +3 -3
  20. package/dist/client/assets/{code-xml-DVVP_fVN.js → code-xml-C3fKotSy.js} +1 -1
  21. package/dist/client/assets/{commandFeedback-2cA8d_WY.js → commandFeedback-C8JG7P5C.js} +1 -1
  22. package/dist/client/assets/{contextWindow-B9Tu0rKj.js → contextWindow-h4X5oJjz.js} +1 -1
  23. package/dist/client/assets/{copyFeedbackStore-CNP3tyq0.js → copyFeedbackStore-DAsM7m9s.js} +1 -1
  24. package/dist/client/assets/{createScopedStore-jAn6kJBy.js → createScopedStore-VWkEjqnA.js} +1 -1
  25. package/dist/client/assets/{cronJobsStore-OUyVs58Z.js → cronJobsStore-DBkn33E8.js} +1 -1
  26. package/dist/client/assets/{file-plus-corner-DY_1K1Ne.js → file-plus-corner-TXCx13rk.js} +1 -1
  27. package/dist/client/assets/inboxStore-CC3pAzZZ.js +1 -0
  28. package/dist/client/assets/index-QA9eWHUp.css +1 -0
  29. package/dist/client/assets/{index-DUJdXxNz.js → index-R-jfstMQ.js} +14 -14
  30. package/dist/client/assets/{info-BcA9_4Qg.js → info-Dc1D2lOq.js} +1 -1
  31. package/dist/client/assets/{input-DbE6EzUB.js → input-B23WM9u5.js} +1 -1
  32. package/dist/client/assets/{log-CFGrfkV1.js → log-DL1J6840.js} +1 -1
  33. package/dist/client/assets/minus-DpXqEYpv.js +1 -0
  34. package/dist/client/assets/{monitor-Bd61vIbY.js → monitor-CnCS7O8D.js} +1 -1
  35. package/dist/client/assets/{pencil-Kx3rEkBI.js → pencil-DbIlj5g0.js} +1 -1
  36. package/dist/client/assets/{pendingActionsStore-C6o78Bki.js → pendingActionsStore-Bks-EsV3.js} +1 -1
  37. package/dist/client/assets/{plus-D5yDJAY3.js → plus-BmhG7IUi.js} +1 -1
  38. package/dist/client/assets/{refresh-cw-CxKjA56k.js → refresh-cw-BxmkSO32.js} +1 -1
  39. package/dist/client/assets/runDetached-BTPJqi-A.js +1 -0
  40. package/dist/client/assets/{search-mHZVZKtE.js → search-BUOQUhrF.js} +1 -1
  41. package/dist/client/assets/{searchable-select-B47fAmOU.js → searchable-select-ByMK5CZ8.js} +1 -1
  42. package/dist/client/assets/{segmented-control--alEtfTe.js → segmented-control-BXlWFDM8.js} +1 -1
  43. package/dist/client/assets/{select-BO0FDRBe.js → select-B-SEd4I2.js} +1 -1
  44. package/dist/client/assets/{settings-header-button-j3Rd0uOx.js → settings-header-button-DQUmCPE_.js} +1 -1
  45. package/dist/client/assets/{state-mark-Wim8WKu4.js → state-mark-Hjx5ToFs.js} +1 -1
  46. package/dist/client/assets/{terminal-BLkQOd9o.js → terminal-gOELI9ta.js} +1 -1
  47. package/dist/client/assets/{timer.adapter-DTTP0Zuq.js → timer.adapter-DgrMEqxC.js} +1 -1
  48. package/dist/client/assets/{tools-BxqpIPAt.js → tools-MfK2-0IV.js} +1 -1
  49. package/dist/client/assets/{triangle-alert-B3zlPujO.js → triangle-alert-DnqNE8_X.js} +1 -1
  50. package/dist/client/assets/{useAppGlobalState-BkMT4XZb.js → useAppGlobalState-BTVDcR0Z.js} +1 -1
  51. package/dist/client/assets/{useProviderCatalog-BlO4bNcc.js → useProviderCatalog-CxmLsNAf.js} +1 -1
  52. package/dist/client/assets/{useTheme-DqpsYqBt.js → useTheme-BWGWet54.js} +1 -1
  53. package/dist/client/index.html +32 -32
  54. package/package.json +1 -1
  55. package/src/server/inbound/inbox-reply.test.ts +24 -4
  56. package/src/server/inbound/inbox-reply.ts +6 -4
  57. package/src/server/inbound/referenced-chat-ids.test.ts +55 -0
  58. package/src/server/inbound/referenced-chat-ids.ts +22 -0
  59. package/src/server/inbox/inbox-boot.test.ts +65 -1
  60. package/src/server/inbox/inbox-boot.ts +24 -4
  61. package/src/server/inbox/inbox-outbox.test.ts +229 -0
  62. package/src/server/inbox/inbox-outbox.ts +107 -0
  63. package/src/server/inbox/inbox-projection.ts +50 -1
  64. package/src/server/inbox/inbox-registry.test.ts +56 -0
  65. package/src/server/inbox/inbox-registry.ts +87 -4
  66. package/src/server/mcp-sources/mcp-source-client.adapter.test.ts +38 -1
  67. package/src/server/mcp-sources/mcp-source-client.adapter.ts +13 -7
  68. package/src/server/mcp-sources/mcp-source-runner.test.ts +69 -0
  69. package/src/server/mcp-sources/mcp-source-runner.ts +67 -12
  70. package/src/server/mcp-sources/mcp-sources-boot.test.ts +11 -0
  71. package/src/server/mcp-sources/mcp-sources-boot.ts +6 -1
  72. package/src/server/mcp-sources-settings.test.ts +42 -1
  73. package/src/server/mcp-sources-settings.ts +25 -10
  74. package/src/server/push/push-manager.test.ts +2 -0
  75. package/src/server/server.ts +11 -2
  76. package/src/server/ws-router-abandoned-chat.test.ts +17 -1
  77. package/src/server/ws-router-broadcast.ts +3 -1
  78. package/src/server/ws-router-command-results.test.ts +6 -2
  79. package/src/server/ws-router-inbox.ts +45 -13
  80. package/src/server/ws-router.ts +7 -6
  81. package/src/shared/commands/inbox.ts +12 -4
  82. package/src/shared/commands/results/inbox.ts +8 -0
  83. package/src/shared/inbound/reply-args.test.ts +45 -0
  84. package/src/shared/inbound/reply-args.ts +48 -0
  85. package/src/shared/inbound/reply-prompt.test.ts +20 -6
  86. package/src/shared/inbound/reply-prompt.ts +22 -6
  87. package/src/shared/inbound/template.test.ts +6 -0
  88. package/src/shared/inbound/template.ts +11 -2
  89. package/src/shared/inbox/events.ts +50 -3
  90. package/src/shared/inbox/policy.test.ts +2 -0
  91. package/src/shared/inbox/policy.ts +23 -1
  92. package/src/shared/inbox/quick-prompts.ts +24 -0
  93. package/src/shared/inbox/types.schema.ts +25 -0
  94. package/src/shared/inbox/types.ts +48 -0
  95. package/src/shared/mcp-sources/presets.ts +10 -2
  96. package/src/shared/mcp-sources/types.schema.ts +15 -1
  97. package/src/shared/mcp-sources/types.ts +17 -0
  98. package/src/shared/mcp-sources/validate.test.ts +9 -0
  99. package/src/shared/mcp-sources/validate.ts +39 -2
  100. package/dist/client/assets/InboxPage-Cx2I-D9G.js +0 -1
  101. package/dist/client/assets/SettingsPage-QUQTA-qY.js +0 -17
  102. package/dist/client/assets/inboxStore-q-JHTh--.js +0 -1
  103. package/dist/client/assets/index-D_XO3fZ-.css +0 -1
  104. package/dist/client/assets/minus-jIhdwm1f.js +0 -1
  105. package/dist/client/assets/runDetached-138oevj9.js +0 -1
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/VChartSurface-UFK0UlX-.js","assets/rolldown-runtime-BCiCTKAo.js","assets/react-BWPDF9mI.js","assets/jsx-runtime-BB9-612F.js","assets/useTheme-DqpsYqBt.js","assets/core-types-Ds7PFmZN.js","assets/appSettingsStore-DhpIEBz2.js","assets/log-CFGrfkV1.js","assets/dom.adapter-C26vNdMA.js","assets/runDetached-138oevj9.js","assets/index-DUJdXxNz.js","assets/react-dom-2r3XOwTS.js","assets/chunk-6KYCQHYJ-C0N1h4Su.js","assets/useAppGlobalState-BkMT4XZb.js","assets/pendingActionsStore-C6o78Bki.js","assets/beacon-alias-HmDCskK6.js","assets/copyFeedbackStore-CNP3tyq0.js","assets/timer.adapter-DTTP0Zuq.js","assets/focusOverlay-BNpERJzs.js","assets/createScopedStore-jAn6kJBy.js","assets/preload-helper-BLdHbfdN.js","assets/contextWindow-B9Tu0rKj.js","assets/useProviderCatalog-BlO4bNcc.js","assets/input-DbE6EzUB.js","assets/tool-call-types-CtytAxam.js","assets/pathUtils-DTWwEzHK.js","assets/commandFeedback-2cA8d_WY.js","assets/segmented-control--alEtfTe.js","assets/dist-DQaZwNEz.js","assets/storage.adapter-DafyA8In.js","assets/inboxStore-q-JHTh--.js","assets/state-mark-Wim8WKu4.js","assets/cronJobsStore-OUyVs58Z.js","assets/ToolCallMessage-DEfxdq5H.js","assets/code-xml-DVVP_fVN.js","assets/FilePreviewSheet-DeowWf5y.js","assets/minus-jIhdwm1f.js","assets/plus-D5yDJAY3.js","assets/refresh-cw-CxKjA56k.js","assets/triangle-alert-B3zlPujO.js","assets/file-plus-corner-DY_1K1Ne.js","assets/pencil-Kx3rEkBI.js","assets/search-mHZVZKtE.js","assets/terminal-BLkQOd9o.js","assets/formatDuration-BbWTR_M_.js","assets/tools-BxqpIPAt.js","assets/index-D_XO3fZ-.css","assets/elk.bundled-ChRT-c4f.js","assets/FlowSurface-CWsaGLfa.js","assets/src-C_gRsKqw.js","assets/value-CHmTzbgv.js","assets/shim-IYZxwmPZ.js","assets/FlowSurface-ChafqZqb.css"])))=>i.map(i=>d[i]);
2
- import{o as e,r as t}from"./rolldown-runtime-BCiCTKAo.js";import{t as n}from"./react-BWPDF9mI.js";import{t as r}from"./jsx-runtime-BB9-612F.js";import{d as i,f as a,h as o,l as s,n as c,r as l,t as u}from"./pendingActionsStore-C6o78Bki.js";import{n as d}from"./code-xml-DVVP_fVN.js";import{a as f,c as p,i as m,n as h,o as g,s as _,t as v}from"./select-BO0FDRBe.js";import{H as y,L as b,R as ee,h as x,t as te}from"./FilePreviewSheet-DeowWf5y.js";import{n as S,t as ne}from"./file-plus-corner-DY_1K1Ne.js";import{t as re}from"./info-BcA9_4Qg.js";import{t as C}from"./minus-jIhdwm1f.js";import{t as w}from"./triangle-alert-B3zlPujO.js";import{g as ie}from"./timer.adapter-DTTP0Zuq.js";import{t as T}from"./segmented-control--alEtfTe.js";import{t as E}from"./log-CFGrfkV1.js";import{t as ae}from"./createScopedStore-jAn6kJBy.js";import{t as D}from"./preload-helper-BLdHbfdN.js";import{D as O,E as oe,Mr as se,T as k,_ as ce,a as le,b as ue,c as de,d as A,f as j,g as fe,i as pe,k as me,l as M,m as he,nu as ge,ru as _e,s as ve,u as N,v as ye,x as be,y as xe,yr as Se}from"./useTheme-DqpsYqBt.js";import{c as Ce,n as we}from"./pathUtils-DTWwEzHK.js";import{t as Te}from"./runDetached-138oevj9.js";import{t as Ee}from"./dom.adapter-C26vNdMA.js";import{t as De}from"./formatDuration-BbWTR_M_.js";import{C as Oe,D as ke,E as Ae,O as je,S as Me,T as Ne,_ as Pe,_n as Fe,b as Ie,c as Le,d as Re,dn as ze,f as Be,fn as Ve,g as He,gn as Ue,h as We,k as Ge,l as Ke,m as qe,p as Je,pn as Ye,rt as P,u as Xe,v as Ze,vn as Qe,w as $e,x as et,y as tt}from"./index-DUJdXxNz.js";var nt={name:`arrow-down-right`,size:24,node:[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]};nt.node;var rt=o(nt),it={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};it.node;var at=o(it),ot={name:`circle-x`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]],aliases:[`x-circle`]};ot.node;var st=o(ot),ct={name:`database`,size:24,node:[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]};ct.node;var lt=o(ct),ut={name:`diamond`,size:24,node:[[`path`,{d:`M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41l-7.59-7.59a2.41 2.41 0 0 0-3.41 0Z`,key:`1f1r0c`}]]};ut.node;var dt=o(ut),ft={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`]};ft.node;var pt=o(ft),mt={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`}]]};mt.node;var ht=o(mt),gt={name:`rectangle-horizontal`,size:24,node:[[`rect`,{width:`20`,height:`12`,x:`2`,y:`6`,rx:`2`,key:`9lu3g6`}]]};gt.node;var _t=o(gt),vt={name:`shield-question-mark`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`shield-question`]};vt.node;var yt=o(vt),bt={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};bt.node;var xt=o(bt);function St(e){return e.type??`static`}function Ct(e){let t=new Map(e.nodes.map(e=>[e.id,0]));for(let n of e.edges)n.from!==n.to&&t.set(n.to,(t.get(n.to)??0)+1);let n=new Set,r=[];for(;r.length<e.nodes.length;){let i=e.nodes.find(e=>!n.has(e.id)&&t.get(e.id)===0)??e.nodes.find(e=>!n.has(e.id));if(!i)break;n.add(i.id),r.push(i);for(let n of e.edges)n.from===i.id&&n.to!==i.id&&t.set(n.to,(t.get(n.to)??0)-1)}return r}function wt(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Map((e.groups??[]).map(e=>[e.id,e.label])),r=(e,n)=>{let r=t.get(e);return r?[{node:r,edge:n}]:[]};return Ct(e).map(t=>({node:t,groupLabel:t.group?n.get(t.group)??null:null,incoming:e.edges.filter(e=>e.to===t.id).flatMap(e=>r(e.from,e)),outgoing:e.edges.filter(e=>e.from===t.id).flatMap(e=>r(e.to,e))}))}function Tt(e){return{step:e.node.label,edge:St(e.edge),...e.edge.label?{label:e.edge.label}:{}}}function Et(e,t){let n=wt(e).find(e=>e.node.id===t);if(!n)return null;let{node:r}=n;return{...e.title?{diagram:e.title}:{},step:r.label,...r.description?{description:r.description}:{},...r.kind?{kind:r.kind}:{},...r.status?{status:r.status}:{},...n.groupLabel?{group:n.groupLabel}:{},...r.path?{path:r.path}:{},...r.line?{line:r.line}:{},upstream:n.incoming.map(Tt),downstream:n.outgoing.map(Tt)}}function Dt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return`h${(t>>>0).toString(16)}:${e.length}`}var F=e(n(),1);Xe(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 I=e(r(),1),Ot=(0,F.createContext)(null);function kt(e,t){return e?null:Object.keys(t).length===0?{}:Ne(t)}function At({store:e,initialState:t={},onStateChange:n,children:r}){let i=(0,F.useRef)(void 0);!e&&!i.current&&(i.current=$e(t));let a=e??i.current,o=(0,F.useRef)(a);o.current=a;let s=(0,F.useRef)(!!e);s.current=!!e,(0,F.useRef)(e?`controlled`:`uncontrolled`),(0,F.useRef)(!1);let c=(0,F.useRef)(t),l=(0,F.useRef)(kt(!!e,t));(0,F.useEffect)(()=>{if(e||t===c.current)return;c.current=t;let n=t&&Object.keys(t).length>0?Ne(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,F.useSyncExternalStore)(a.subscribe,a.getSnapshot,a.getServerSnapshot??a.getSnapshot),d=(0,F.useRef)(n);d.current=n;let f=(0,F.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,F.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))Ae(n,r)!==i&&t.push({path:r,value:i});t.length>0&&d.current?.(t)}},[]),m=(0,F.useCallback)(e=>o.current.get(e),[]),h=(0,F.useCallback)(()=>o.current.getSnapshot(),[]),g=(0,F.useMemo)(()=>({state:u,get:m,set:f,update:p,getSnapshot:h}),[u,m,f,p,h]);return(0,I.jsx)(Ot.Provider,{value:g,children:r})}function L(){let e=(0,F.useContext)(Ot);if(!e)throw Error(`useStateStore must be used within a StateProvider`);return e}function jt(e){let{state:t}=L();return Ae(t,e)}var Mt=(0,F.createContext)(null);function Nt({children:e}){let{state:t}=L(),n=(0,F.useMemo)(()=>({stateModel:t}),[t]),r=(0,F.useMemo)(()=>e=>Re(e,n),[n]),i=(0,F.useMemo)(()=>({isVisible:r,ctx:n}),[r,n]);return(0,I.jsx)(Mt.Provider,{value:i,children:e})}function Pt(){let e=(0,F.useContext)(Mt);if(!e)throw Error(`useVisibility must be used within a VisibilityProvider`);return e}var Ft=(0,F.createContext)(null),It={};function Lt(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 Rt(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||!Lt(t.args,i.args))return!1}return!0}function zt({customFunctions:e=It,children:t}){let{state:n,getSnapshot:r}=L(),[i,a]=(0,F.useState)({}),o=(0,F.useRef)({}),[s,c]=(0,F.useState)({}),l=(0,F.useCallback)((e,t)=>{c(n=>{let r=n[e];return r&&Rt(r,t)?n:{...n,[e]:t}})},[]),u=(0,F.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=et(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,F.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,F.useCallback)(e=>{let{[e]:t,...n}=o.current;o.current=n,a(n)},[]),p=(0,F.useCallback)(()=>{let e=!0;for(let[t,n]of Object.entries(s))u(t,n).valid||(e=!1);return e},[s,u]),m=(0,F.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,I.jsx)(Ft.Provider,{value:m,children:t})}function Bt(){return(0,F.useContext)(Ft)}var Vt=0;function Ht(){return Vt+=1,`${Date.now()}-${Vt}`}function Ut(e,t){if(e==null)return e;if(e===`$id`)return Ht();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 Ht()}if(Array.isArray(e))return e.map(e=>Ut(e,t));if(typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=Ut(i,t);return n}return e}var Wt=(0,F.createContext)(null);function Gt({handlers:e={},navigate:t,children:n}){let{get:r,set:i,getSnapshot:a}=L(),o=Bt(),[s,c]=(0,F.useState)(e),[l,u]=(0,F.useState)(new Set),[d,f]=(0,F.useState)(null),p=(0,F.useCallback)((e,t)=>{c(n=>({...n,[e]:t}))},[]),m=(0,F.useCallback)(async e=>{let n=Pe(e,a()),c=qe(),l=Date.now();We({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=Ut(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 Be({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 Be({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();He({id:c,name:n.action,ok:d,at:e,durationMs:e-l,error:p})}},[s,r,i,a,t,o]),h=(0,F.useCallback)(()=>{d?.resolve()},[d]),g=(0,F.useCallback)(()=>{d?.reject()},[d]),_=(0,F.useMemo)(()=>({handlers:s,loadingActions:l,pendingConfirmation:d,execute:m,confirm:h,cancel:g,registerHandler:p}),[s,l,d,m,h,g,p]);return(0,I.jsx)(Wt.Provider,{value:_,children:n})}function R(){let e=(0,F.useContext)(Wt);if(!e)throw Error(`useActions must be used within an ActionProvider`);return e}function Kt({confirm:e,onConfirm:t,onCancel:n}){let r=e.variant===`danger`;return(0,I.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,I.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,I.jsx)(`h3`,{style:{margin:`0 0 8px 0`,fontSize:`18px`,fontWeight:600},children:e.title}),(0,I.jsx)(`p`,{style:{margin:`0 0 24px 0`,color:`#6b7280`},children:e.message}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,justifyContent:`flex-end`},children:[(0,I.jsx)(`button`,{onClick:n,style:{padding:`8px 16px`,borderRadius:`6px`,border:`1px solid #d1d5db`,backgroundColor:`white`,cursor:`pointer`},children:e.cancelLabel??`Cancel`}),(0,I.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 qt=(0,F.createContext)(null);function Jt({item:e,index:t,basePath:n,children:r}){return(0,I.jsx)(qt.Provider,{value:{item:e,index:t,basePath:n},children:r})}function Yt(){return(0,F.useContext)(qt)}var Xt=new WeakMap,Zt={},Qt=class extends F.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}},$t={},en=F.createContext($t);function tn(){return F.useContext(en)}var nn=F.createContext(void 0);function rn(){return F.useContext(nn)}function an(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 on(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function sn(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)&&sn(r[e],i[e]))}function cn(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]=cn(e[n]);return t}function ln(e,t){if(Object.is(e,t))return e;let n=Array.isArray(e);if(n!==Array.isArray(t)||!n&&(!on(e)||!on(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=ln(r[e],t),Object.is(r[e],t)||(s=!1)):s=!1,o[e]=t}return s?e:o}function un(e){let t=(0,F.useRef)({}),n=(0,F.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&&sn(l.own,t.element)&&sn(l.children,t.childVersions)?l.version:++n.current;o.delete(t.key),i[t.key]={own:cn(t.element),children:t.childVersions,version:u},a[t.key]=u,c.pop()}}return t.current=i,a}var dn=F.memo(function({Component:e,element:t,slots:n,emit:r,on:i,bindings:a,loading:o,children:s}){return(0,I.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 fn(){return F.useSyncExternalStore(Oe,Je,()=>!1)}function pn({element:e,elementKey:t,spec:n,registry:r,loading:i,fallback:a,signatures:o}){let s=fn(),c=Yt(),{ctx:l}=Pt(),{execute:u}=R(),{getSnapshot:d,state:f}=L(),p=tn(),m=rn(),h=(0,F.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?Me(e.visible):{container:e.visible,itemFilter:void 0},_=g.itemFilter,v=g.container===void 0||Re(g.container,h),y=e.on,b=(0,F.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]=Ze(i,t);await u({...e,params:n})}},[y,u,h,d]),ee=(0,F.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]),x=e.watch,te=(0,F.useRef)(null),S=(0,F.useRef)(void 0),ne=(0,F.useRef)(void 0),re=(0,F.useRef)({}),C=(0,F.useMemo)(()=>{if(!x)return;let e={};for(let t of Object.keys(x))e[t]=Ae(f,t);let t=S.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 S.current=e,e},[x,f]);if((0,F.useEffect)(()=>{if(!x||!C)return;let e=Object.keys(x);if(e.length===0)return;let t=te.current;if(te.current=C,t===null)return;let n=!1;return(async()=>{for(let r of e){if(n)break;if(C[r]!==t[r]){let e=x[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]=Ze(i,t);if(await u({...e,params:r}),n)break}}}})().catch(console.error),()=>{n=!0}},[x,C,u,h,d]),!v)return null;let w=e.props??Zt,ie=an(tt(w,h),ne),T=ln(re.current,Ie(w,h));re.current=T;let E=T===e.props?e:{...e,props:T},ae=r[E.type]??a;if(!ae)return console.warn(`No renderer for component type: ${E.type}`),null;let D=Xt.get(r)?.[E.type];if(E.slots&&D?.slots){let e=new Set(D.slots);for(let t of Object.keys(E.slots))t==="default"?console.warn(`[json-render] Component "${E.type}" uses slots.default. Use "children" for default slot content.`):e.has(t)||console.warn(`[json-render] Unknown slot "${t}" on component "${E.type}". Available slots: ${D.slots.join(`, `)}`)}let O=(e,t)=>e.map(e=>{let s=n.elements[e];if(!s){if(!i){let n=t?`in slot "${t}" of "${E.type}"`:`as child of "${E.type}"`;console.warn(`[json-render] Missing element "${e}" referenced ${n}. This element will not render.`)}return null}return(0,I.jsx)(mn,{element:s,elementKey:e,spec:n,registry:r,loading:i,fallback:a,signatures:o},e)}),oe=E.repeat?(0,I.jsx)(hn,{element:E,spec:n,registry:r,loading:i,fallback:a,itemFilter:_,signatures:o}):E.children?O(E.children):void 0,se=E.slots?Object.fromEntries(Object.entries(E.slots).map(([e,t])=>[e,O(t,e)])):void 0,k=(0,I.jsx)(dn,{Component:ae,signature:o[t??``],execute:u,actionContext:c,functions:p,directives:m,element:E,slots:se,emit:b,on:ee,bindings:ie,loading:i,children:oe}),ce=s&&t?(0,I.jsx)(`span`,{"data-jr-key":t,style:{display:`contents`},children:k}):k;return(0,I.jsx)(Qt,{elementType:E.type,resetKey:o[t??``],children:ce})}var mn=F.memo(function(e){return(0,I.jsx)(pn,{...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 hn({element:e,spec:t,registry:n,loading:r,fallback:i,signatures:a,itemFilter:o}){let{state:s}=L(),{ctx:c}=Pt(),l=Yt(),u=e.repeat,d=je(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=(Ae(s,d)??[]).map((e,t)=>({itemValue:e,index:t})).filter(({itemValue:e,index:t})=>o===void 0||Re(o,{...c,repeatItem:e,repeatIndex:t}));return(0,I.jsx)(I.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,I.jsx)(Jt,{item:o,index:s,basePath:ke(d,s),children:e.children?.map(o=>{let s=t.elements[o];return s?(0,I.jsx)(mn,{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 gn({spec:e,registry:t,loading:n,fallback:r}){let i=un(e);if(!e||!e.root)return null;let a=e.elements[e.root];return a?(0,I.jsx)(mn,{element:a,elementKey:e.root,spec:e,registry:t,loading:n,fallback:r,signatures:i}):null}function _n({registry:e,store:t,initialState:n,handlers:r,navigate:i,validationFunctions:a,functions:o,directives:s,onStateChange:c,children:l}){let u=(0,F.useMemo)(()=>s?Ke(s):void 0,[s]);return(0,I.jsx)(At,{store:t,initialState:n,onStateChange:c,children:(0,I.jsx)(Nt,{children:(0,I.jsx)(zt,{customFunctions:a,children:(0,I.jsx)(Gt,{handlers:r,navigate:i,children:(0,I.jsx)(en.Provider,{value:o??$t,children:(0,I.jsxs)(nn.Provider,{value:u,children:[l,(0,I.jsx)(vn,{})]})})})})})})}function vn(){let{pendingConfirmation:e,confirm:t,cancel:n}=R();return e?.action.confirm?(0,I.jsx)(Kt,{confirm:e.action.confirm,onConfirm:t,onCancel:n}):null}function yn(e,t){let{set:n}=L();return[e,(0,F.useCallback)(e=>{t&&n(t,e)},[t,n])]}var bn=`/_drill`;function xn(e){return`${bn}/${e}`}var Sn=Se({dimension:se(),value:se(),into:se(),metric:se(),period:fe.optional()});function Cn(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 z(e,t){e.view.getState().showNotice(t)}function wn(e,t){e.host().sendToAgent?e.view.getState().proposeAgentMessage({headline:t.headline,message:ve(t)}):z(e,`Asking the agent is not available in this view`)}async function Tn(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 En(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=A[`file.open`].params.safeParse(n);if(!t.success)return z(e,`That file link is malformed`);let i=Cn(r.workspaceRoot,t.data.path);if(!i)return z(e,`"${t.data.path}" is outside this chat's workspace`);e.view.getState().openPreview(i);return}case`link.open`:{let t=A[`link.open`].params.safeParse(n);if(!t.success)return z(e,`Only https links can be opened`);r.openLink(t.data.url);return}case`dataset.refresh`:{let t=A[`dataset.refresh`].params.safeParse(n);t.success&&e.view.getState().refreshDataset(t.data.dataset);return}case`financial.drilldown`:{let t=A[`financial.drilldown`].params.safeParse(n);if(!t.success)return z(e,`That drilldown is malformed`);let{dataset:r,...i}=t.data;e.state.set(xn(r),i);return}case`agent.ask`:{let t=A[`agent.ask`].params.safeParse(n);return t.success?wn(e,le(`agent.ask`,t.data.prompt,t.data.context,i)):z(e,`That question is malformed`)}case`agent.investigate`:case`agent.fix`:{let r=A[t].params.safeParse(n);return r.success?wn(e,le(t,r.data.subject,r.data.context,i)):z(e,`That request is malformed`)}case`financial.explainVariance`:{let t=A[`financial.explainVariance`].params.safeParse(n);if(!t.success)return z(e,`That explanation request is malformed`);let a=e.spec.datasets?.[t.data.dataset];if(!a)return z(e,`Unknown dataset "${t.data.dataset}"`);let o=t.data.compareWith??`previous-period`,s=await Tn(r,a,{metrics:[t.data.metric],...t.data.period?{period:t.data.period}:{},...t.data.filters?{filters:t.data.filters}:{},compare:o});return wn(e,pe({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 Dn(e){let t={};for(let n of Object.keys(A))he(n)&&A[n].class!==`local`&&(t[n]=async t=>{if(e.host().readonly)return;let r=me.safeParse(t);if(!r.success)return z(e,`That action's parameters are not plain data`);await En(e,n,r.data)});return t}var B=`Other`;function On(e,t){let n=t.map(t=>N(e.metrics[t])),[r]=n;return n.every(e=>e.format===r?.format&&e.currency===r?.currency)}function kn(e,t,n,r){let i=e.dimensions?.[t];return i?.kind===`time`?xe(r,n.grain??i.grain??`month`):r}function An(e,t){let n=[];for(let r of e){let e=r.dimensions[t];e!==void 0&&!n.includes(e)&&n.push(e)}return n}function jn(e,t,n){let r=e.dimensions?.[t]?.order;return[...n].sort((e,t)=>{let n=r?r.indexOf(e):-1,i=r?r.indexOf(t):-1;return n===i?e.localeCompare(t,`en`,{numeric:!0}):n===-1?1:i===-1?-1:n-i})}function Mn(e,t,n,r){let i=new Map;for(let r of e){let e=r.dimensions[t]??``;i.set(e,(i.get(e)??0)+Math.abs(r.values[n]??0))}let a=[...i.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e);return new Set(a.length>r+1?a.slice(0,r):a)}function V(e,t,n,r,i){return{x:t,xLabel:e.xLabels[t]??t,series:n,value:r,...i}}function Nn(e,t,n,r){let i=An(n.rows,e.dimension);return{kind:e.chart,xOrder:i,xLabels:Object.fromEntries(i.map(r=>[r,kn(t,e.dimension,n,r)])),format:N(t.metrics[r]),valueLabel:O(r,t.metrics[r]),dimensionLabel:k(e.dimension,t.dimensions?.[e.dimension])}}function Pn(e,t,n){let[r]=e.metrics;if(!r)return{ok:!1,message:`A chart needs a metric`};if(!On(t,[...e.metrics,...e.secondaryMetric?[e.secondaryMetric]:[]]))return{ok:!1,message:`These metrics use different units, and a chart has one axis. Show them in two charts.`};switch(e.chart){case`waterfall`:return Ln(e,t,n,r);case`composition`:return Rn(e,t,n,r);case`combo`:return In(e,t,n,r);default:return Fn(e,t,n)}}function Fn(e,t,n){let[r=``]=e.metrics;if(e.chart===`stacked-bar`&&!e.series&&e.metrics.length<2)return{ok:!1,message:`A stacked bar needs a series dimension or at least two metrics to stack`};if(e.series&&e.metrics.length>1)return{ok:!1,message:`Split by a series dimension with one metric, or list several metrics without a series`};let i=Nn(e,t,n,r),a=[],o=[];if(e.series){let s=e.series,c=Mn(n.rows,s,r,7),l=jn(t,s,[...c]),u=An(n.rows,s).some(e=>!c.has(e));l.forEach((e,t)=>o.push({id:e,label:e,role:`series`,slot:t})),u&&o.push({id:B,label:B,role:`series`,slot:l.length});let d=new Map;for(let t of n.rows){let n=t.dimensions[e.dimension],i=t.dimensions[s]??``,a=t.values[r];if(n===void 0||a==null)continue;let o=`${n}\u0001${c.has(i)?i:B}`;d.set(o,(d.get(o)??0)+a)}for(let[e,t]of d){let[n=``,r=``]=e.split(``);a.push(V(i,n,r,t))}return{ok:!0,model:{...i,points:a,series:o}}}e.metrics.forEach((e,n)=>{o.push({id:e,label:O(e,t.metrics[e]),role:`series`,slot:n})}),n.comparison&&e.metrics.forEach(e=>{o.push({id:`${e}::compare`,label:`${O(e,t.metrics[e])} (${n.comparison?.label})`,role:`compare`,slot:null})});for(let t of n.rows){let n=t.dimensions[e.dimension];if(n!==void 0)for(let r of e.metrics){let e=t.values[r];e!=null&&a.push(V(i,n,r,e));let o=t.compare?.[r];o!=null&&a.push(V(i,n,`${r}::compare`,o))}}return{ok:!0,model:{...i,points:a,series:o}}}function In(e,t,n,r){if(!e.secondaryMetric)return{ok:!1,message:`A combo chart needs a secondaryMetric drawn as a line over the bars`};let i=e.secondaryMetric,a=Nn(e,t,n,r),o=[];for(let t of n.rows){let n=t.dimensions[e.dimension];if(n===void 0)continue;let s=t.values[r],c=t.values[i];s!=null&&o.push(V(a,n,r,s)),c!=null&&o.push(V(a,n,i,c))}return{ok:!0,model:{...a,points:o,series:[{id:r,label:O(r,t.metrics[r]),role:`series`,slot:0},{id:i,label:O(i,t.metrics[i]),role:`secondary`,slot:1}]}}}function Ln(e,t,n,r){if(e.series)return{ok:!1,message:`A waterfall shows one metric; drop the series dimension`};let i=Nn(e,t,n,r),a=[],o=0;for(let t of n.rows){let n=t.dimensions[e.dimension],s=t.values[r];if(n===void 0||s==null)continue;let c=o;o+=s,a.push(V(i,n,s>=0?`increase`:`decrease`,s,{start:c,end:o}))}let s=e.totalLabel??`Total`;return a.push(V(i,s,`total`,o,{start:0,end:o})),{ok:!0,model:{...i,points:a,xOrder:[...a.map(e=>e.x)],xLabels:{...i.xLabels,[s]:s},series:[{id:`increase`,label:`Increase`,role:`increase`,slot:null},{id:`decrease`,label:`Decrease`,role:`decrease`,slot:null},{id:`total`,label:s,role:`total`,slot:null}]}}}function Rn(e,t,n,r){let i=Nn(e,t,n,r),a=n.rows.map(t=>({key:t.dimensions[e.dimension]??``,value:t.values[r]??0})).filter(e=>e.value!==0);if(a.some(e=>e.value<0))return{ok:!1,message:`A part-to-whole chart cannot show negative values; use a bar chart`};let o=[...a].sort((e,t)=>t.value-e.value),s=o.length>6?o.slice(0,5):o,c=o.slice(s.length).reduce((e,t)=>e+t.value,0),l=jn(t,e.dimension,s.map(e=>e.key)),u=new Map(s.map(e=>[e.key,e.value])),d=l.map((e,t)=>({id:e,label:i.xLabels[e]??e,role:`series`,slot:t})),f=l.map(e=>V(i,e,e,u.get(e)??0));return c>0&&(d.push({id:B,label:B,role:`series`,slot:l.length}),f.push(V(i,B,B,c))),{ok:!0,model:{...i,points:f,series:d,xOrder:f.map(e=>e.x)}}}function zn(e,t){if(!t||t.x===void 0)return null;let n=String(t.x);return!e.xOrder.includes(n)||e.kind===`waterfall`&&n===e.xOrder[e.xOrder.length-1]?null:{x:n,series:t.series===void 0?``:String(t.series)}}var Bn=(0,F.createContext)(null);function Vn({value:e,children:t}){return(0,I.jsx)(Bn.Provider,{value:e,children:t})}function H(){let e=(0,F.useContext)(Bn);if(!e)throw Error(`GenUI components render only inside a GenUI view`);return e}var U=ae(`GenUIView`,()=>e=>({pendingAgentMessage:null,previewPath:null,previewProbe:null,refreshNonce:{},notice:null,proposeAgentMessage:t=>e({pendingAgentMessage:t,notice:null}),cancelAgentMessage:()=>e({pendingAgentMessage:null}),openPreview:t=>e({previewPath:t,previewProbe:null}),closePreview:()=>e({previewPath:null,previewProbe:null}),setPreviewProbe:t=>e({previewProbe:t}),refreshDataset:t=>e(e=>({refreshNonce:{...e.refreshNonce,[t]:(e.refreshNonce[t]??0)+1}})),showNotice:t=>e({notice:t})})),Hn=10,Un=`genui-dataset`;function Wn(e){return e.source===`file`?(e.refreshSeconds??Hn)*1e3:e.source===`mcp`&&e.refreshSeconds?e.refreshSeconds*1e3:!1}function W(e){let{spec:t}=H();return e?t.datasets?.[e]??null:null}function Gn(e,t){let n=P(),r=W(e),i=U.useScopedStore(t=>e?t.refreshNonce[e]??0:0),a=r!==null&&r.source!==`inline`&&n.queryDataset!==null&&t!==null,o=(0,F.useMemo)(()=>!r||r.source!==`inline`||!t?null:ce(r,r.rows,t),[r,t]),s=n.queryDataset,c=Ue({queryKey:[Un,n.chatId,e,r?Dt(JSON.stringify(r)):null,t?JSON.stringify(t):null,i],queryFn:async()=>{if(!r||!t||!s)throw Error(`dataset is not queryable`);return await s(r,t,i>0)},enabled:a,placeholderData:Fe,refetchInterval:r&&a&&!n.readonly?Wn(r):!1,retry:!1});if(!r)return{status:`error`,message:`This view refers to a dataset "${e??``}" it does not declare`};if(!t)return{status:`loading`};if(o)return o.ok?{status:`ok`,result:o.result,refreshing:!1}:{status:`error`,message:o.message};if(!n.queryDataset)return{status:`unavailable`,message:`Live data is not included in a shared view`};if(c.error)return{status:`error`,message:Ge.source_unavailable};let l=c.data;if(!l)return{status:`loading`};switch(l.status){case`ok`:return{status:`ok`,result:l.result,refreshing:c.isPlaceholderData};case`needs_approval`:return l;case`error`:return{status:`error`,message:`${Ge[l.code]}: ${l.message}`}}}var Kn=`_kannaKey`,qn=`/_ui`;function Jn(e){let t=e.props[Kn];return typeof t==`string`?t:e.type}function G(e,t,n,r){let i=`${qn}/${Jn(e)}/${t}`,a=jt(i),{set:o}=L(),s=(0,F.useCallback)(e=>o(i,e),[i,o]);return[r(a)?a:n,s]}function Yn(e){return typeof e==`string`}function Xn(e){return typeof e==`boolean`}function Zn(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}var Qn={neutral:`text-muted-foreground`,positive:`text-success-text`,negative:`text-destructive-text`,attention:`text-warning-text`,info:`text-info-text`};function K(e){return Qn[e]}function $n({tone:e,className:t}){let n=a(`h-3.5 w-3.5 shrink-0`,t);switch(e){case`positive`:return(0,I.jsx)(ze,{className:n,"aria-hidden":`true`});case`negative`:return(0,I.jsx)(st,{className:n,"aria-hidden":`true`});case`attention`:return(0,I.jsx)(w,{className:n,"aria-hidden":`true`});case`info`:return(0,I.jsx)(re,{className:n,"aria-hidden":`true`});case`neutral`:return(0,I.jsx)(C,{className:n,"aria-hidden":`true`})}}function er(e){return e===`positive`?`positive`:e===`negative`?`negative`:`neutral`}function tr({trend:e,className:t}){let n=a(`h-3.5 w-3.5 shrink-0`,t);return e===`up`?(0,I.jsx)(at,{className:n,"aria-hidden":`true`}):e===`down`?(0,I.jsx)(rt,{className:n,"aria-hidden":`true`}):(0,I.jsx)(C,{className:n,"aria-hidden":`true`})}function nr({component:e}){return(0,I.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,I.jsx)(w,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e,` could not be shown: its settings changed to an unsupported value`]})}function rr({server:e,tool:t}){let n=P(),r=Qe(),i=u(`genui.dataset.approve`,n.chatId??``,e,t),a=l(i),o=n.approveTool;return o?(0,I.jsx)(s,{size:`sm`,variant:`outline`,pending:a,onClick:()=>{c(i,async()=>{await o(e,t),await r.invalidateQueries({queryKey:[Un,n.chatId]})})},children:`Allow for this chat`}):null}function q({state:e,minHeight:t,emptyLabel:n}){return(0,I.jsx)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed border-border px-3 py-4 text-sm`,style:t?{minHeight:t}:void 0,children:(0,I.jsx)(ir,{state:e,emptyLabel:n})})}function ir({state:e,emptyLabel:t}){switch(e.status){case`loading`:return(0,I.jsxs)(`span`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,I.jsx)(i,{}),` Loading data…`]});case`needs_approval`:return(0,I.jsxs)(`span`,{className:`flex flex-col items-center gap-2 text-center text-muted-foreground`,children:[(0,I.jsxs)(`span`,{className:`flex items-center gap-1.5 text-foreground`,children:[(0,I.jsx)(yt,{className:`h-4 w-4`,"aria-hidden":`true`}),`Action requires approval`]}),(0,I.jsx)(`span`,{className:`max-w-prose text-xs`,children:e.message}),(0,I.jsx)(rr,{server:e.server,tool:e.tool})]});case`unavailable`:return(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:t??e.message});case`error`:return(0,I.jsxs)(`span`,{className:`flex items-center gap-1.5 text-destructive-text`,role:`alert`,children:[(0,I.jsx)(w,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),e.message]})}}function ar({label:e,minHeight:t}){return(0,I.jsx)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed border-border px-3 py-4 text-sm text-muted-foreground`,style:t?{minHeight:t}:void 0,children:e})}var or=50,J=`px-3 py-2 text-xs font-medium text-muted-foreground`;function sr({total:e,onShow:t}){return(0,I.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,I.jsxs)(s,{size:`sm`,variant:`ghost`,onClick:t,children:[`Show all `,e,` rows`]})})}function cr(e,t){let[n,r]=G(e,`expanded`,!1,Xn),i=!n&&t.length>or?(0,I.jsx)(sr,{total:t.length,onShow:()=>r(!0)}):null;return{visibleRows:n?t:t.slice(0,or),showAll:i}}function lr(e){if(!_e(e))return!1;let t=e.value;return t===`all`||t===``||t==null?!1:ge(t)?t.length>0:typeof t==`string`||typeof t==`number`}function ur(e){let t=me.safeParse(dr(e));if(!t.success)return null;let n=t.data.filters;return ge(n)?{...t.data,filters:n.filter(lr)}:t.data}function dr(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`_kannaKey`&&t!=null))}function Y(e){return e===`none`?void 0:e}function fr(e,t){let n=t?[...e??[],{dimension:t.dimension,value:t.value}]:e;return n&&n.length>0?[...n]:void 0}function pr(e){return e.metrics?[...e.metrics]:e.metric===void 0?[]:typeof e.metric==`string`?[e.metric]:[...e.metric]}function mr(e){return pr(e)[0]??``}function X({metrics:e,groupBy:t,period:n,compare:r,scenario:i,filters:a,sort:o,limit:s}){return{metrics:e,...t?{groupBy:t}:{},...n?{period:n}:{},...r?{compare:r}:{},...i?{scenario:i}:{},...a&&a.length>0?{filters:a}:{},...o?{sort:o}:{},...s===void 0?{}:{limit:s}}}function hr(e,t){let n=e.safeParse(t);return n.success?n.data:null}function Z(e,t){function n(n){let r=(0,F.useMemo)(()=>hr(e,ur(n.element.props)),[n.element.props]);return r?(0,I.jsx)(t,{...n,props:r}):(0,I.jsx)(nr,{component:n.element.type})}return n}var gr=(0,F.lazy)(()=>D(()=>import(`./VChartSurface-UFK0UlX-.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46]))),_r={sm:200,md:260,lg:340};function vr(e){return e===`chart`||e===`table`}var yr=60;function br(e){let t=jt(xn(e??``));return(0,F.useMemo)(()=>{if(!e||!t)return null;let n=Sn.safeParse(t);return n.success?n.data:null},[e,t])}function xr(e,t){let n=pr(e),r=t?t.into:e.dimension;return X({metrics:e.secondaryMetric?[...n,e.secondaryMetric]:n,groupBy:e.series&&!t?[r,e.series]:[r],period:t?.period??e.period,compare:e.chart===`waterfall`||e.chart===`composition`||t?void 0:Y(e.compareWith),filters:fr(e.filters,t),sort:e.chart===`waterfall`?{by:r,direction:`asc`}:void 0,limit:e.limit??yr})}function Sr(e,t){return t?e.chart===`composition`?`composition`:`bar`:e.chart}function Cr({x:e,label:t,drill:n}){return n?(0,I.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,I.jsx)(I.Fragment,{children:t})}function wr({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,I.jsx)(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:e.dimensionLabel}),n.map(e=>(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:e.label},e.id))]})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:e.xOrder.map(i=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-normal text-foreground`,children:(0,I.jsx)(Cr,{x:i,label:e.xLabels[i]??i,drill:Tr(e,i)?t:null})}),n.map(t=>(0,I.jsx)(`td`,{className:`px-3 py-1.5 text-right tabular-nums text-foreground`,children:M(r(i,t.id),e.format)},t.id))]},i))})]})})}function Tr(e,t){return zn(e,{x:t})!==null}function Er({model:e,height:t,onPointClick:n}){let r=P().ChartRenderer??gr,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,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(`div`,{className:`w-full`,style:{height:t},"aria-hidden":`true`}),children:(0,I.jsx)(r,{model:e,height:t,label:i,onPointClick:n})})}function Dr({props:e,drill:t}){let{execute:n}=R(),{viewKey:r}=H(),i=P(),a=u(`genui.financial.explainVariance`,r,e.dataset),o=l(a),d=mr(e),f=(0,F.useCallback)(()=>{let r=fr(e.filters,t),i=t?.period??e.period;c(a,()=>n({action:`financial.explainVariance`,params:{dataset:e.dataset,metric:d,compareWith:Y(e.compareWith)??`previous-period`,...i?{period:i}:{},...r?{filters:r.map(e=>({...e}))}:{}}}))},[t,n,a,d,e]);return i.readonly||!i.sendToAgent?null:(0,I.jsxs)(s,{size:`sm`,variant:`ghost`,className:`gap-1.5`,pending:o,onClick:f,children:[o?null:(0,I.jsx)(ht,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Explain variance`]})}function Or(e,t,n,r){return e===`back`&&t?n:e===`figure`&&!t?r:null}function kr({datasetId:e,drill:t,decl:n,backRef:r,focusAfterRef:i}){let{execute:a}=R(),{viewKey:o}=H(),d=u(`genui.drill.back`,o,e),f=l(d),p=(0,F.useCallback)(()=>{i.current=`figure`,c(d,()=>a({action:`setState`,params:{statePath:xn(e),value:null}}))},[e,a,i,d]);return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,I.jsxs)(s,{ref:r,size:`sm`,variant:`ghost`,className:`gap-1`,onClick:p,pending:f,children:[f?null:(0,I.jsx)(Ve,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Back`]}),(0,I.jsxs)(`span`,{children:[k(t.dimension,n.dimensions?.[t.dimension]),`: `,(0,I.jsx)(`span`,{className:`text-foreground`,children:Ar(t,n)}),` `,`by `,k(t.into,n.dimensions?.[t.into]).toLowerCase()]})]})}function Ar(e,t){let n=t.dimensions?.[e.dimension];return n?.kind===`time`?xe(e.value,n.grain??`month`):e.value}function jr(e,t,n,r){let i=t?t.period.label:be(e.period);if(n)return r?.dimensions?.[n.dimension]?.kind===`time`?Ar(n,r):i;let a=Y(e.compareWith),o=t?.comparison?.label??(a?ue(a):null);return o?`${i} · vs ${o.charAt(0).toLowerCase()}${o.slice(1)}`:i}var Mr=Z(j.FinancialChart.props,({element:e,props:t})=>{let n=W(t.dataset),r=br(t.drilldown?t.dataset:void 0),i=(0,F.useMemo)(()=>xr(t,r),[t,r]),o=Gn(t.dataset,i),[s,d]=G(e,`view`,`chart`,vr),{execute:f}=R(),{viewKey:p}=H(),m=u(`genui.financial.drilldown`,p,t.dataset),h=(0,F.useId)(),g=(0,F.useRef)(null),_=(0,F.useRef)(null),v=(0,F.useRef)(null),y=l(m),b=(0,F.useMemo)(()=>!n||o.status!==`ok`?null:Pn({chart:Sr(t,r),metrics:pr(t),...t.secondaryMetric?{secondaryMetric:t.secondaryMetric}:{},dimension:r?r.into:t.dimension,...t.series&&!r?{series:t.series}:{},...t.totalLabel?{totalLabel:t.totalLabel}:{}},n,o.result),[n,r,t,o]),ee=t?.drilldown,x=(0,F.useCallback)(e=>{ee&&!r&&c(m,()=>f({action:`financial.drilldown`,params:{dataset:t.dataset,metric:mr(t),dimension:t.dimension,value:e.x,into:ee.dimension,...t.period?{period:t.period}:{}}}))},[r,m,ee,f,t]);(0,F.useEffect)(()=>{let e=Or(v.current,r!==null,_.current,g.current);e&&(v.current=null,e.focus())},[r]);let te=(0,F.useCallback)(e=>{v.current=`back`,x(e)},[x]),S=_r[t.height??`md`],ne=mr(t),re=t.title??O(ne,n?.metrics[ne]),C=jr(t,o.status===`ok`?o.result:null,r,n),w=t.drilldown&&!r&&n?{intoLabel:k(t.drilldown.dimension,n.dimensions?.[t.drilldown.dimension]).toLowerCase(),pending:y,onDrill:te}:null;return(0,I.jsxs)(`figure`,{ref:g,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":h,children:[(0,I.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{id:h,className:`text-sm font-medium text-foreground`,children:re}),(0,I.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:C})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t.explain?(0,I.jsx)(Dr,{props:t,drill:r}):null,(0,I.jsx)(T,{size:`sm`,value:s,onValueChange:d,options:[{value:`chart`,label:`Chart`},{value:`table`,label:`Table`}]})]})]}),r&&n?(0,I.jsx)(kr,{datasetId:t.dataset,drill:r,decl:n,backRef:_,focusAfterRef:v}):null,o.status===`ok`?null:(0,I.jsx)(q,{state:o,minHeight:S}),o.status===`ok`&&b&&!b.ok?(0,I.jsx)(ar,{label:b.message,minHeight:S}):null,o.status===`ok`&&b?.ok&&b.model.points.length===0?(0,I.jsx)(ar,{label:`No data for the selected period`,minHeight:S}):null,o.status===`ok`&&b?.ok&&b.model.points.length>0?(0,I.jsxs)(`div`,{className:a(`transition-opacity duration-[var(--motion-quick)]`,(o.refreshing||y)&&`opacity-60`),"aria-busy":y||void 0,children:[s===`chart`?(0,I.jsx)(Er,{model:b.model,height:S,onPointClick:t.drilldown&&!r?x:null}):(0,I.jsx)(wr,{model:b.model,drill:w}),o.result.truncated?(0,I.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Showing the first `,o.result.rows.length,` groups.`]}):null]}):null]})}),Q=`px-3 py-1.5 tabular-nums`;function Nr(e,t){return t?e.dimensions[t]??``:`Total`}function Pr({element:e,config:t,result:n,decl:r}){let{metrics:i}=t,{visibleRows:o,showAll:s}=cr(e,n.rows);return(0,I.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:t.rows?k(t.rows,r.dimensions?.[t.rows]):``}),i.map(e=>(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:O(e,r.metrics[e])},e))]})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:o.map(e=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Nr(e,t.rows)}),i.map(t=>(0,I.jsx)(`td`,{className:a(Q,`text-right text-foreground`),children:M(e.values[t]??null,N(r.metrics[t]))},t))]},e.key))})]}),s]})}function Fr({value:e,compare:t,format:n,direction:r,accounting:i}){let o=de(e,t,n,r),s=K(er(o.sentiment));return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`td`,{className:a(Q,`text-right text-muted-foreground`),children:M(t,n,{accounting:i})}),(0,I.jsx)(`td`,{className:a(Q,`text-right`,s),children:o.amountText}),(0,I.jsx)(`td`,{className:a(Q,`text-right`,s),children:o.ratioText})]})}function Ir(e){return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:e}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:`Change`}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:`Change %`})]})}function Lr({element:e,config:t,result:n,decl:r}){let i=t.metrics[0]??``,o=r.metrics[i],s=N(o),{visibleRows:c,showAll:l}=cr(e,n.rows),u=n.comparison?.label;return(0,I.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:t.rows?k(t.rows,r.dimensions?.[t.rows]):``}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:O(i,o)}),u?Ir(u):null]})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:c.map(e=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Nr(e,t.rows)}),(0,I.jsx)(`td`,{className:a(Q,`text-right text-foreground`),children:M(e.values[i]??null,s)}),u?(0,I.jsx)(Fr,{value:e.values[i]??null,compare:e.compare?.[i]??null,format:s,direction:o?.direction,accounting:!1}):null]},e.key))})]}),l]})}function Rr(e){let t=e.filter(e=>typeof e==`number`);return t.length===0?null:t.reduce((e,t)=>e+t,0)}function zr(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:Rr(n.map(e=>e.values[t])),compare:Rr(n.map(e=>e.compare?.[t]))}))}function Br({element:e,config:t,result:n,decl:r}){let[i,o]=G(e,`collapsed`,[],Zn),s=new Set(i),c=t.metrics[0]??``,l=r.metrics[c],u=N(l),f=n.comparison?.label,p=zr(n,c,t.groupRows,t.groupRows?r.dimensions?.[t.groupRows]?.order:void 0),m=e=>{o(s.has(e)?i.filter(t=>t!==e):[...i,e])},h=e=>M(e,u,{accounting:!0}),g=(t.totals??[]).map(e=>{let t=p.filter(t=>e.groups.includes(t.name));return{label:e.label,value:Rr(t.map(e=>e.value)),compare:Rr(t.map(e=>e.compare))}});return(0,I.jsx)(`div`,{className:`max-h-[32rem] overflow-auto rounded-md border border-border`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:t.rows?k(t.rows,r.dimensions?.[t.rows]):``}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:n.period.label}),f?Ir(f):null]})}),(0,I.jsxs)(`tbody`,{children:[p.map(e=>{let n=s.has(e.name),r=!!t.groupRows;return(0,I.jsxs)(F.Fragment,{children:[r?(0,I.jsxs)(`tr`,{className:`border-t border-border`,children:[(0,I.jsx)(`th`,{scope:`rowgroup`,className:`sticky left-0 bg-card px-2 py-1.5 text-left font-medium text-foreground`,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>m(e.name),"aria-expanded":!n,className:`flex items-center gap-1 rounded px-1 hover:bg-muted`,children:[n?(0,I.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,I.jsx)(Ye,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e.name]})}),(0,I.jsx)(`td`,{className:a(Q,`text-right font-medium text-foreground`),children:h(e.value)}),f?(0,I.jsx)(Fr,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]}):null,n?null:e.rows.map(e=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:a(`sticky left-0 bg-card py-1 text-left font-normal text-foreground`,r?`pl-9 pr-3`:`px-3`),children:Nr(e,t.rows)}),(0,I.jsx)(`td`,{className:a(Q,`text-right text-foreground`),children:h(e.values[c]??null)}),f?(0,I.jsx)(Fr,{value:e.values[c]??null,compare:e.compare?.[c]??null,format:u,direction:l?.direction,accounting:!0}):null]},e.key))]},e.name||`_`)}),g.map(e=>(0,I.jsxs)(`tr`,{className:`border-t-2 border-border`,children:[(0,I.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-2 text-left font-semibold text-foreground`,children:e.label}),(0,I.jsx)(`td`,{className:a(Q,`text-right font-semibold text-foreground`),children:h(e.value)}),f?(0,I.jsx)(Fr,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]},e.label))]})]})})}function Vr({element:e,config:t,result:n,decl:r}){if(n.rows.length===0)return(0,I.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,I.jsx)(Br,{element:e,config:t,result:n,decl:r});case`comparison`:return(0,I.jsx)(Lr,{element:e,config:t,result:n,decl:r});case`detail`:return(0,I.jsx)(Pr,{element:e,config:t,result:n,decl:r})}}function Hr(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Ur=Z(j.FinancialMetric.props,({props:e})=>{let t=W(e.dataset),n=br(e.dataset),r=(0,F.useMemo)(()=>X({metrics:[e.metric],period:e.period,compare:Y(e.compareWith),scenario:e.scenario,filters:fr(e.filters,n)}),[n,e]),i=Gn(e.dataset,r),o=t?.metrics[e.metric],s=e.label??O(e.metric,o);if(i.status!==`ok`)return(0,I.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md border border-border p-3`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,I.jsx)(q,{state:i})]});let c=N(o),l=i.result.totals.values[e.metric]??null,u=i.result.totals.compare?.[e.metric]??null,d=de(l,u,c,o?.direction),f=er(d.sentiment);return(0,I.jsxs)(`div`,{className:a(`flex flex-col gap-1 rounded-md border border-border p-3`,i.refreshing&&`opacity-60`),children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,I.jsx)(`span`,{className:`text-2xl font-semibold leading-tight text-foreground`,children:M(l,c,{compact:!0})}),i.result.comparison&&d.amount!==null?(0,I.jsxs)(`span`,{className:a(`flex flex-wrap items-center gap-1 text-xs`,K(f)),children:[(0,I.jsx)(tr,{trend:d.trend}),(0,I.jsx)(`span`,{className:`font-medium tabular-nums`,children:d.ratioText}),(0,I.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,d.amountText,`)`]}),(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`vs `,Hr(i.result.comparison.label)]})]}):null,i.result.comparison&&d.amount===null?(0,I.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`No `,Hr(i.result.comparison.label),` data to compare`]}):null,(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i.result.period.label})]})});function Wr(e,t){return e.metrics.length===0?null:X({metrics:e.metrics,groupBy:[e.groupRows,e.rows].filter(e=>!!e),period:e.period,compare:e.variant===`detail`?void 0:Y(e.compareWith),filters:fr(e.filters,t),sort:e.rows?{by:e.rows,direction:`asc`}:void 0,limit:e.limit??500})}function Gr({element:e,config:t,defaultTitle:n}){let r=W(t.dataset),i=br(t.dataset),o=(0,F.useMemo)(()=>Wr(t,i),[t,i]),s=Gn(t.dataset,o);if(!o)return(0,I.jsx)(nr,{component:e.type});let c=t.title??n;return(0,I.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[c?(0,I.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:c}):null,i&&r?(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Filtered to `,k(i.dimension,r.dimensions?.[i.dimension]).toLowerCase(),` `,i.value]}):null,s.status===`ok`?null:(0,I.jsx)(q,{state:s}),s.status===`ok`&&r?(0,I.jsx)(`div`,{className:a(s.refreshing&&`opacity-60`),children:(0,I.jsx)(Vr,{element:e,config:t,result:s.result,decl:r})}):null]})}var Kr=Z(j.FinancialTable.props,({element:e,props:t})=>{let n=(0,F.useMemo)(()=>({...t,metrics:pr(t),variant:t.variant??(t.metrics?`detail`:`comparison`)}),[t]);return(0,I.jsx)(Gr,{element:e,config:n})});function qr(e,t){return Z(e,({element:e,props:n})=>{let r=(0,F.useMemo)(()=>({...n,metrics:[n.metric],variant:`statement`}),[n]);return(0,I.jsx)(Gr,{element:e,config:r,defaultTitle:t})})}function Jr(e,t,n){let[r,i]=yn(e,t);return[r??n,i]}function Yr({label:e,children:t}){return(0,I.jsxs)(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]})}var Xr=[`last-12-months`,`ytd`,`last-4-quarters`,`last-3-months`,`all`],Zr=Z(j.PeriodSelector.props,({props:e,bindings:t})=>{let n=e.options??[...Xr],[r,i]=Jr(e.value,t?.value,n[0]??`all`),a=n.includes(r)?n:[r,...n];return(0,I.jsx)(Yr,{label:e.label??`Period`,children:(0,I.jsxs)(v,{value:r,onValueChange:i,children:[(0,I.jsx)(f,{className:`h-9`,children:(0,I.jsx)(g,{})}),(0,I.jsx)(h,{children:a.map(e=>(0,I.jsx)(m,{value:e,children:be(e)},e))})]})})}),Qr=Z(j.CompareSelector.props,({props:e,bindings:t})=>{let{spec:n}=H(),r=(0,F.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]),i=[...ye.filter(e=>e.startsWith(`previous`)||r.has(e)),`none`],a=e.options??i,[o,s]=Jr(e.value,t?.value,a[0]??`none`);return(0,I.jsx)(Yr,{label:e.label??`Compare with`,children:(0,I.jsxs)(v,{value:o,onValueChange:s,children:[(0,I.jsx)(f,{className:`h-9`,children:(0,I.jsx)(g,{})}),(0,I.jsx)(h,{children:a.map(e=>(0,I.jsx)(m,{value:e,children:ue(e)},e))})]})})});function $r({props:e,bindings:t,defaultLabel:n}){let r=W(e.dataset),i=r?Object.keys(r.metrics)[0]:void 0,{dimension:a}=e,o=(0,F.useMemo)(()=>i?X({metrics:[i],groupBy:[a],sort:{by:a,direction:`asc`},limit:200}):null,[a,i]),s=Gn(e.dataset,o),c=s.status===`ok`?s.result.rows.map(e=>e.dimensions[a]??``):[],l=e.includeAll!==!1,u=l?`all`:c[0]??``,[d,p]=Jr(e.value,t?.value,u),_=e.label??n??k(a,r?.dimensions?.[a]);if(s.status!==`ok`)return(0,I.jsx)(Yr,{label:_,children:(0,I.jsx)(q,{state:s})});let y=[...l?[`all`]:[],...c];return(0,I.jsx)(Yr,{label:_,children:(0,I.jsxs)(v,{value:d||u,onValueChange:p,children:[(0,I.jsx)(f,{className:`h-9`,children:(0,I.jsx)(g,{})}),(0,I.jsx)(h,{children:y.map(e=>(0,I.jsx)(m,{value:e,children:e===`all`?`All`:e},e))})]})})}var ei=Z(j.CurrencySelector.props,({props:e,bindings:t})=>{let n=(0,F.useMemo)(()=>({...e,includeAll:!1}),[e]);return(0,I.jsx)($r,{props:n,bindings:t,defaultLabel:`Currency`})}),ti=Z(j.EntitySelector.props,({props:e,bindings:t})=>(0,I.jsx)($r,{props:e,bindings:t})),ni={sm:`gap-2`,md:`gap-3`,lg:`gap-5`},ri={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`},ii=Z(j.Stack.props,({props:e,children:t})=>{let n=e.direction===`horizontal`;return(0,I.jsx)(`div`,{className:a(`flex min-w-0`,n?`flex-row flex-wrap items-start`:`flex-col`,ni[e.gap??`md`]),children:t})}),ai=Z(j.Grid.props,({props:e,children:t})=>(0,I.jsx)(`div`,{className:a(`grid min-w-0`,ri[e.columns??2],ni[e.gap??`md`]),children:t})),oi=Z(j.Card.props,({props:e,children:t})=>(0,I.jsxs)(`section`,{className:`min-w-0 rounded-md border border-border p-3`,"aria-label":e.title,children:[e.title?(0,I.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:e.title}):null,e.description?(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e.description}):null,(0,I.jsx)(`div`,{className:a(`flex flex-col gap-3`,(e.title||e.description)&&`mt-3`),children:t})]})),si=Z(j.Section.props,({props:e,children:t})=>(0,I.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":e.title,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:e.title}),e.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}):null]}),t]})),ci=Z(j.Tabs.props,({element:e,props:t,children:n,bindings:r})=>{let{items:i}=t,[a,o]=yn(t.value,r?.value),[s,c]=G(e,`tab`,i[0]?.value??``,Yn),l=r?.value?a??i[0]?.value??``:s,u=e=>{r?.value?o(e):c(e)},d=F.Children.toArray(n),f=Math.max(0,i.findIndex(e=>e.value===l));return(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,I.jsx)(T,{size:`sm`,value:i[f]?.value??``,onValueChange:u,options:i.map(e=>({value:e.value,label:e.label}))}),(0,I.jsx)(`div`,{role:`tabpanel`,children:d[f]??null})]})}),li={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`},ui=Z(j.Text.props,({props:e})=>(0,I.jsx)(`p`,{className:a(`whitespace-pre-wrap break-words`,li[e.variant??`body`]),children:e.text})),di=Z(j.Badge.props,({props:e})=>{let t=e.tone??`neutral`;return(0,I.jsxs)(`span`,{className:a(`inline-flex w-fit items-center gap-1 rounded-md border border-border px-1.5 py-0.5 text-xs font-medium`,K(t)),children:[(0,I.jsx)($n,{tone:t}),e.label]})}),fi={primary:`default`,secondary:`outline`,ghost:`ghost`};function pi(e){return e?(Array.isArray(e)?e:[e]).map(e=>e.action):[]}var mi=Z(j.Button.props,({element:e,props:t,emit:n})=>{let{loadingActions:r}=R(),i=pi(e.on?.press).some(e=>r.has(e));return(0,I.jsx)(s,{size:`sm`,variant:fi[t.variant??`secondary`],className:`w-fit`,pending:i,onClick:()=>n(`press`),children:t.label})});function hi(){return(0,I.jsx)(`hr`,{className:`border-border`})}function gi(e,t,n){let{execute:r}=R(),{viewKey:i}=H(),a=u(`genui.${e}`,i,n),o=l(a);return{run:(0,F.useCallback)(()=>{c(a,()=>r({action:e,params:t}))},[e,r,a,t]),pending:o}}function _i({path:e,line:t,label:n}){let{run:r,pending:i}=gi(`file.open`,t?{path:e,line:t}:{path:e},`${e}:${t??``}`);return(0,I.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})}var vi=Z(j.KeyValue.props,({props:e})=>(0,I.jsx)(`dl`,{className:a(`grid gap-x-6 gap-y-1.5`,e.columns===2?`grid-cols-1 @md:grid-cols-2`:`grid-cols-1`),children:e.items.map(e=>(0,I.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,2fr)] gap-3 text-sm`,children:[(0,I.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,I.jsx)(`dd`,{className:`break-words text-foreground tabular-nums`,children:e.value===null?`—`:String(e.value)})]},e.label))})),yi={added:{icon:ne,label:`Added`},modified:{icon:S,label:`Modified`},deleted:{icon:pt,label:`Deleted`},renamed:{icon:y,label:`Renamed`}},bi=Z(j.FileList.props,({props:e})=>(0,I.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.files.map(e=>{let t=e.status?yi[e.status]:null,n=t?.icon??y;return(0,I.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2`,children:[(0,I.jsx)(n,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(_i,{path:e.path,label:e.path}),e.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}):null]}),t?(0,I.jsx)(`span`,{className:`mt-0.5 shrink-0 pl-2 text-xs text-muted-foreground`,children:t.label}):null]},e.path)})}));function xi(e,t,n){return t?n?`${e}:${t}:${n}`:`${e}:${t}`:e}var Si={error:`negative`,warning:`attention`,info:`info`},Ci={error:`Error`,warning:`Warning`,info:`Info`},wi=Z(j.DiagnosticList.props,({props:e})=>(0,I.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.items.map((e,t)=>{let n=Si[e.severity],r=e.path?xi(e.path,e.line,e.column):null;return(0,I.jsxs)(`li`,{className:`flex gap-2 px-3 py-2 text-sm`,children:[(0,I.jsxs)(`span`,{className:a(`mt-0.5 flex shrink-0 items-center gap-1 text-xs font-medium`,K(n)),children:[(0,I.jsx)($n,{tone:n}),Ci[e.severity]]}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`p`,{className:`break-words text-foreground`,children:e.message}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[e.path&&r?(0,I.jsx)(_i,{path:e.path,line:e.line,label:r}):null,e.source?(0,I.jsx)(`span`,{children:e.source}):null]})]})]},`${t}-${e.message}`)})}));function Ti({name:e,context:t}){let{run:n,pending:r}=gi(`agent.fix`,{subject:e,context:t},e);return(0,I.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,I.jsx)(ee,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Fix`]})}var Ei=Z(j.TestResult.props,({props:e})=>{let{passed:t,failed:n,skipped:r,durationMs:i,command:o,failures:s}=e,c=n>0?`negative`:`positive`;return(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-sm`,children:[(0,I.jsxs)(`span`,{className:a(`flex items-center gap-1 font-medium`,K(c)),children:[(0,I.jsx)($n,{tone:c}),n>0?`Failing`:`Passing`]}),(0,I.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[t,` passed`]}),(0,I.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[n,` failed`]}),r===void 0?null:(0,I.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[r,` skipped`]}),i===void 0?null:(0,I.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:De(i)})]}),o?(0,I.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,I.jsx)(`ul`,{className:`divide-y divide-border border-t border-border`,children:s.map(e=>(0,I.jsxs)(`li`,{className:`flex items-start gap-2 py-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`p`,{className:`break-words text-sm text-foreground`,children:e.name}),e.message?(0,I.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,I.jsx)(_i,{path:e.path,line:e.line,label:xi(e.path,e.line,void 0)}):null]}),(0,I.jsx)(Ti,{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]})}),Di=Z(j.Timeline.props,({props:e})=>(0,I.jsx)(`ol`,{className:`flex flex-col gap-3 border-l border-border pl-4`,children:e.items.map((e,t)=>(0,I.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.tone?(0,I.jsx)($n,{tone:e.tone,className:K(e.tone)}):null,(0,I.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e.title}),e.time?(0,I.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:e.time}):null]}),e.detail?(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.detail}):null]},`${t}-${e.title}`))}));function Oi(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 ki(e,t){let n=e??Object.keys(t[0]??{}).map(e=>({key:e,label:oe(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,Oi(e[t.key])]))}))}}function Ai(e,t,n,r){let i=r.comparison?.label;return{columns:[...t.map(t=>({key:`d:${t}`,label:k(t,e.dimensions?.[t]),numeric:!1})),...n.flatMap(t=>[{key:`m:${t}`,label:O(t,e.metrics[t]),numeric:!0},...i?[{key:`c:${t}`,label:`${O(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}`,M(r.values[t]??null,N(e.metrics[t]))],...i?[[`c:${t}`,M(r.compare?.[t]??null,N(e.metrics[t]))]]:[]])])}))}}function ji({element:e,columns:t,rows:n,title:r}){let{visibleRows:i,showAll:o}=cr(e,n);return(0,I.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[r?(0,I.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:r}):null,(0,I.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsx)(`tr`,{className:`border-b border-border`,children:t.map(e=>(0,I.jsx)(`th`,{scope:`col`,className:a(J,e.numeric?`text-right`:`text-left`),children:e.label},e.key))})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:i.map(e=>(0,I.jsx)(`tr`,{children:t.map(t=>(0,I.jsx)(`td`,{className:a(`px-3 py-1.5 text-foreground`,t.numeric?`text-right tabular-nums`:`text-left`),children:e.cells[t.key]},t.key))},e.key))})]}),o]})]})}var Mi=Z(j.DataTable.props,({element:e,props:t})=>{let n=W(t.dataset),r=br(t.dataset),i=(0,F.useMemo)(()=>!t.dataset||!t.metrics?null:X({metrics:t.metrics,groupBy:t.dimensions??[],period:t.period,compare:Y(t.compareWith),filters:fr(t.filters,r),limit:t.limit??200}),[r,t]),a=Gn(t.dataset,i);if(!t.dataset){let n=(t.rows??[]).filter(_e);return(0,I.jsx)(ji,{element:e,...ki(t.columns,n),title:t.title})}return t.metrics?a.status===`ok`?n?(0,I.jsx)(ji,{element:e,...Ai(n,t.dimensions??[],t.metrics,a.result),title:t.title}):(0,I.jsx)(nr,{component:`DataTable`}):(0,I.jsx)(q,{state:a}):(0,I.jsx)(nr,{component:`DataTable`})}),Ni={start:{icon:_,label:`Start`},end:{icon:xt,label:`End`},process:{icon:_t,label:`Step`},decision:{icon:dt,label:`Decision`},store:{icon:lt,label:`Store`},external:{icon:p,label:`External`}},Pi={neutral:`bg-muted-foreground`,positive:`bg-success`,negative:`bg-destructive`,attention:`bg-warning`,info:`bg-info`};function Fi({node:e,className:t}){let n=Ni[e.kind??`process`],r=n.icon;return(0,I.jsx)(r,{className:a(`h-3.5 w-3.5 shrink-0 text-muted-foreground`,t),"aria-label":n.label})}function Ii({node:e}){if(!e.status)return null;let t=e.tone??`neutral`;return(0,I.jsxs)(`span`,{className:a(`flex shrink-0 items-center gap-1 text-xs font-medium whitespace-nowrap tabular-nums`,K(t)),children:[(0,I.jsx)(`span`,{className:a(`h-1.5 w-1.5 rounded-full`,Pi[t]),"aria-hidden":`true`}),e.status]})}var Li={labelFont:`500 14px`,statusFont:`500 12px`,textFont:`12px`,paddingX:12,terminalPaddingX:16,contentChrome:26,statusChrome:24,rowHeight:16,baseHeight:38};function Ri(e){return e.kind===`start`||e.kind===`end`?Li.terminalPaddingX:Li.paddingX}function zi(e){return 2*Ri(e)+Li.contentChrome}function Bi(e){if(!e.path)return null;let t=we(e.path);return e.line?`${t}:${e.line}`:t}var Vi={sm:280,md:420,lg:600},Hi=720,Ui=14,Wi=132,Gi=300;function Ki(){return Ee.getCssVar(`--kanna-font-body`,`system-ui, sans-serif`)}function qi(){return Ee.getCssVar(`--kanna-font-mono`,`ui-monospace, monospace`)}function Ji(e,t,n){return Ee.measureTextWidth(e,t)??e.length*n}function Yi(e){let t=Li,n=Ki(),r=Ji(e.label,`${t.labelFont} ${n}`,7.6),i=e.status?Ji(e.status,`${t.statusFont} ${n}`,6.4)+t.statusChrome:0,a=e.description?Ji(e.description,`${t.textFont} ${n}`,6.2):0,o=Bi(e),s=o?Ji(o,`${t.textFont} ${qi()}`,7.2):0,c=Math.max(r+i,a,s);return{width:Math.round(Math.min(Gi,Math.max(Wi,c+zi(e)))),height:t.baseHeight+(e.description?t.rowHeight:0)+(e.path?t.rowHeight:0)}}function Xi(e){return`e${e}`}function Zi(e,t){let n=e=>({id:e.id,...Yi(e)}),r=new Set((e.groups??[]).map(e=>e.id)),i=e.edges.map((e,t)=>({id:Xi(t),sources:[e.from],targets:[e.to],...e.label?{labels:[{text:e.label,width:Ji(e.label,`${Li.textFont} ${Ki()}`,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=${Ui},bottom=${Ui},right=${Ui}]`},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 Qi(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});else{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(Xi(t))?.sections?.[0],r=c.get(Xi(t))?.labels?.[0];return{key:Xi(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 $i(t,n){let{default:r}=await D(async()=>{let{default:t}=await import(`./elk.bundled-ChRT-c4f.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([47,1]));return Qi(t,n,await new r().layout(Zi(t,n)))}function ea(e,t){return e.width===0||e.height===0?1:Math.min(Hi/e.width,t/e.height)}async function ta(e){await Ee.whenFontsReady();let t=e.direction??`auto`;if(t!==`auto`)return await $i(e,t);let n=Vi[e.height??`md`],[r,i]=await Promise.all([$i(e,`LR`),$i(e,`TB`)]);return ea(r,n)>=ea(i,n)?r:i}var na=(0,F.lazy)(()=>D(()=>import(`./FlowSurface-CWsaGLfa.js`),__vite__mapDeps([48,1,2,11,3,14,7,4,5,6,8,10,12,13,15,16,17,18,19,20,9,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,49,50,51,52]))),ra=`genui-flow-layout`;function ia(e){return e===`diagram`||e===`outline`}function aa(e){return Ue({queryKey:[ra,Dt(JSON.stringify(e))],queryFn:async()=>await ta(e),staleTime:1/0,retry:!1})}function oa(e){let t=e.edges.filter(e=>St(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 sa({heading:e,links:t,direction:n}){return t.length===0?null:(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(0,I.jsxs)(`span`,{children:[e,` `]}),t.map((e,t)=>(0,I.jsxs)(`span`,{children:[t>0?`, `:null,(0,I.jsx)(`span`,{className:`text-foreground`,children:e.node.label}),e.edge.label?(0,I.jsxs)(`span`,{children:[` (`,e.edge.label,`)`]}):null,St(e.edge)===`flow`?(0,I.jsx)(`span`,{className:`text-info-text`,children:` · live`}):null]},`${n}-${e.node.id}-${t}`))]})}function ca({entries:e,selectedId:t,onSelect:n}){return(0,I.jsx)(`ol`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map((e,r)=>(0,I.jsxs)(`li`,{className:a(`flex gap-3 px-3 py-2`,e.node.id===t&&`bg-muted`),children:[(0,I.jsx)(`span`,{className:`w-5 shrink-0 pt-0.5 text-right text-xs text-muted-foreground tabular-nums`,children:r+1}),(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,I.jsx)(Fi,{node:e.node}),(0,I.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,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Ni[e.node.kind??`process`].label}),e.groupLabel?(0,I.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`in `,e.groupLabel]}):null,(0,I.jsx)(Ii,{node:e.node})]}),e.node.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.node.description}):null,(0,I.jsx)(sa,{heading:`From`,links:e.incoming,direction:`in`}),(0,I.jsx)(sa,{heading:`To`,links:e.outgoing,direction:`out`})]})]},e.node.id))})}function la({node:e}){let{run:t,pending:n}=gi(`file.open`,(0,F.useMemo)(()=>e.line?{path:e.path,line:e.line}:{path:e.path},[e.line,e.path]),`${e.id}:${e.path}`);return(0,I.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:n,onClick:t,children:[n?null:(0,I.jsx)(y,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open file`]})}function ua({diagram:e,node:t}){let n=(0,F.useMemo)(()=>Et(e,t.id)??{},[e,t.id]),{run:r,pending:i}=gi(`agent.investigate`,(0,F.useMemo)(()=>({subject:t.label,context:n}),[n,t.label]),t.id);return(0,I.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:i,onClick:r,children:[i?null:(0,I.jsx)(ht,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Ask agent`]})}function da(e){return e.path?e.line?`${e.path}:${e.line}`:e.path:null}function fa(e){return e.path!==void 0}function pa({diagram:e,entry:t,onClose:n}){let r=P(),{node:i}=t,a=da(i);return(0,I.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,"aria-label":`Step ${i.label}`,children:[(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(Fi,{node:i,className:`mt-1`}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,I.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:i.label}),(0,I.jsx)(Ii,{node:i})]}),i.description?(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i.description}):null,a?(0,I.jsx)(`p`,{className:`font-mono text-xs break-all text-muted-foreground`,children:a}):null]}),(0,I.jsx)(s,{size:`icon-sm`,variant:`ghost`,onClick:n,"aria-label":`Close step details`,children:(0,I.jsx)(ie,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}),(0,I.jsx)(sa,{heading:`From`,links:t.incoming,direction:`in`}),(0,I.jsx)(sa,{heading:`To`,links:t.outgoing,direction:`out`}),r.readonly?null:(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[fa(i)?(0,I.jsx)(la,{node:i}):null,r.sendToAgent?(0,I.jsx)(ua,{diagram:e,node:i}):null]})]})}function ma({diagram:e,height:t,label:n,selectedId:r,onSelect:a}){let o=P(),s=aa(e),c=o.FlowRenderer??na;return s.error?(0,I.jsx)(ar,{label:`This diagram could not be laid out. The Outline view still lists every step.`,minHeight:t}):s.data?(0,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(`div`,{className:`w-full rounded-md border border-border`,style:{height:t},"aria-hidden":`true`}),children:(0,I.jsx)(c,{layout:s.data,height:t,label:n,selectedId:r,onSelect:a})}):(0,I.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,I.jsx)(i,{}),` Laying out diagram…`]})}var ha={Stack:ii,Grid:ai,Card:oi,Section:si,Tabs:ci,Text:ui,Badge:di,Button:mi,Divider:hi,KeyValue:vi,DataTable:Mi,FileList:bi,DiagnosticList:wi,TestResult:Ei,Timeline:Di,FlowDiagram:Z(j.FlowDiagram.props,({element:e,props:t})=>{let n=(0,F.useMemo)(()=>wt(t),[t]),[r,i]=G(e,`view`,`diagram`,ia),[a,o]=G(e,`selected`,``,Yn),s=(0,F.useId)(),c=(0,F.useCallback)(e=>o(e??``),[o]),l=(0,F.useCallback)(e=>o(e===a?``:e),[a,o]),u=(0,F.useCallback)(()=>o(``),[o]),d=Vi[t.height??`md`],f=n.find(e=>e.node.id===a)??null,p=`Diagram${t.title?` of ${t.title}`:``}: ${oa(t)}. Switch to Outline to read it as a list.`;return(0,I.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,"aria-labelledby":s,children:[(0,I.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{id:s,className:`text-sm font-medium text-foreground`,children:t.title??`Diagram`}),(0,I.jsx)(`div`,{className:`text-xs text-muted-foreground tabular-nums`,children:oa(t)})]}),(0,I.jsx)(T,{size:`sm`,value:r,onValueChange:i,options:[{value:`diagram`,label:`Diagram`},{value:`outline`,label:`Outline`}]})]}),r===`diagram`?(0,I.jsx)(ma,{diagram:t,height:d,label:p,selectedId:f?.node.id??null,onSelect:c}):(0,I.jsx)(ca,{entries:n,selectedId:f?.node.id??null,onSelect:l}),f?(0,I.jsx)(pa,{diagram:t,entry:f,onClose:u}):null]})}),FinancialMetric:Ur,FinancialChart:Mr,FinancialTable:Kr,IncomeStatement:qr(j.IncomeStatement.props,`Income statement`),BalanceSheet:qr(j.BalanceSheet.props,`Balance sheet`),CashFlowStatement:qr(j.CashFlowStatement.props,`Cash flow statement`),PeriodSelector:Zr,CompareSelector:Qr,CurrencySelector:ei,EntitySelector:ti};function ga({element:e}){return(0,I.jsx)(nr,{component:e.type})}var _a=64,$=new Map;function va(e,t){let n=$.get(e);if(n)return $.delete(e),$.set(e,n),n;let r=$e({...t});for($.set(e,r);$.size>_a;){let e=$.keys().next().value;if(e===void 0)break;$.delete(e)}return r}function ya(e){return{root:e.root,elements:Object.fromEntries(Object.entries(e.elements).map(([e,t])=>[e,{type:t.type,props:{...t.props,[Kn]: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 ba({viewKey:e}){let t=P(),n=U.useScopedStore(e=>e.pendingAgentMessage),r=U.useScopedStore(e=>e.cancelAgentMessage),i=U.useScopedStore(e=>e.showNotice),a=u(`genui.agent.send`,e),o=l(a),d=t.sendToAgent,f=(0,F.useCallback)(()=>{n&&d&&c(a,async()=>{try{await d(n.message),r()}catch(e){throw i(e instanceof Error?e.message:`The message could not be sent`),e}})},[r,a,n,d,i]);return n?(0,I.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,I.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,I.jsx)(ht,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Send to the agent`}),(0,I.jsx)(`p`,{className:`break-words text-foreground`,children:n.headline}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The view's current numbers and data source go with it.`})]})]}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(s,{size:`sm`,pending:o,onClick:f,children:`Send`}),(0,I.jsx)(s,{size:`sm`,variant:`ghost`,onClick:r,disabled:o,children:`Cancel`})]})]}):null}function xa(){let e=U.useScopedStore(e=>e.notice),t=U.useScopedStore(e=>e.showNotice);return e?(0,I.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-destructive-text`,role:`alert`,children:[(0,I.jsx)(w,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,I.jsx)(`button`,{type:`button`,className:`rounded p-0.5 text-muted-foreground hover:text-foreground`,"aria-label":`Dismiss`,onClick:()=>t(null),children:(0,I.jsx)(ie,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}):null}function Sa(){let e=U.useScopedStore(e=>e.previewPath),t=U.useScopedStore(e=>e.previewProbe),n=U.useScopedStore(e=>e.setPreviewProbe),r=U.useScopedStore(e=>e.closePreview),i=U.useScopedStore(e=>e.showNotice);(0,F.useEffect)(()=>{if(!e)return;let t=new AbortController;return Te(`probe generated file link`,b(Ce(e),{signal:t.signal}).then(a=>{t.signal.aborted||(a.kind===`ready`?n(a):(r(),i(`"${we(e)}" could not be opened`)))})),()=>t.abort()},[r,e,n,i]);let a=(0,F.useMemo)(()=>{if(!e||t?.kind!==`ready`)return null;let n=Ce(e);return x({id:`genui-file-${n}`,kind:`file`,displayName:we(e),absolutePath:e,relativePath:e,contentUrl:n,mimeType:t.mimeType,size:t.size},`local_file_link`)},[e,t]),o=(0,F.useCallback)(e=>{e||r()},[r]);return(0,I.jsx)(te,{source:a,open:a!==null,onOpenChange:o})}function Ca({handlers:e}){let{registerHandler:t}=R();return(0,F.useEffect)(()=>{for(let[n,r]of Object.entries(e))t(n,r)},[e,t]),null}function wa({spec:e,viewKey:t}){let n=P(),r=U.useScopedStoreApi(),i=(0,F.useMemo)(()=>va(t,e.state??{}),[t,e.state]),a=(0,F.useMemo)(()=>Dn({host:()=>n,view:r,spec:e,state:i}),[n,r,e,i]),o=(0,F.useMemo)(()=>ya(e),[e]),s=(0,F.useMemo)(()=>({spec:e,viewKey:t}),[e,t]);return(0,I.jsx)(Vn,{value:s,children:(0,I.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,I.jsx)(`h3`,{className:`text-base font-medium text-foreground`,children:e.title}):null,(0,I.jsxs)(_n,{registry:ha,store:i,handlers:a,children:[(0,I.jsx)(Ca,{handlers:a}),(0,I.jsx)(gn,{spec:o,registry:ha,fallback:ga})]}),(0,I.jsx)(xa,{}),(0,I.jsx)(ba,{viewKey:t}),(0,I.jsx)(Sa,{})]})})}function Ta({spec:e,viewKey:t}){return(0,I.jsx)(U.Provider,{init:void 0,children:(0,I.jsx)(wa,{spec:e,viewKey:t})})}var Ea=t({GenUIFallback:()=>Oa,default:()=>Aa}),Da=8;function Oa({issues:e}){return(0,I.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,I.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-foreground`,children:[(0,I.jsx)(w,{className:`h-4 w-4 text-warning-text`,"aria-hidden":`true`}),`Unable to show this view`]}),(0,I.jsx)(`p`,{className:`text-muted-foreground`,children:`The agent described a view Kanna could not validate, so nothing from it was run.`}),(0,I.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer select-none`,children:`Details`}),(0,I.jsxs)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4 font-mono`,children:[e.slice(0,Da).map(e=>(0,I.jsxs)(`li`,{children:[e.path?`${e.path}: `:``,e.message]},`${e.path}:${e.message}`)),e.length>Da?(0,I.jsxs)(`li`,{children:[`…and `,e.length-Da,` more`]}):null]})]})]})}var ka=class extends F.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){E.warn(`[kanna/genui] view failed to render`,{message:e.message})}render(){return this.state.failed?(0,I.jsx)(Oa,{issues:[{path:``,message:`The view stopped rendering unexpectedly`}]}):this.props.children}};function Aa({source:e}){let t=P(),n=(0,F.useMemo)(()=>Le(e),[e]),r=(0,F.useMemo)(()=>`${t.chatId??`shared`}:${Dt(e)}`,[t.chatId,e]);return n.ok?(0,I.jsx)(ka,{children:(0,I.jsx)(Ta,{spec:n.spec,viewKey:r})}):(0,I.jsx)(Oa,{issues:n.issues})}export{Oa as GenUIFallback,Ri as a,Aa as default,Bi as i,Fi as n,zn as o,Ii as r,St as s,Ea as t};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/VChartSurface-CMQoKhau.js","assets/rolldown-runtime-BCiCTKAo.js","assets/react-BWPDF9mI.js","assets/jsx-runtime-BB9-612F.js","assets/useTheme-BWGWet54.js","assets/core-types-Ds7PFmZN.js","assets/appSettingsStore-BkV1YU8S.js","assets/log-DL1J6840.js","assets/dom.adapter-C26vNdMA.js","assets/runDetached-BTPJqi-A.js","assets/index-R-jfstMQ.js","assets/react-dom-2r3XOwTS.js","assets/chunk-6KYCQHYJ-C0N1h4Su.js","assets/useAppGlobalState-BTVDcR0Z.js","assets/pendingActionsStore-Bks-EsV3.js","assets/beacon-alias-rXxwPHhZ.js","assets/copyFeedbackStore-DAsM7m9s.js","assets/timer.adapter-DgrMEqxC.js","assets/focusOverlay-BNpERJzs.js","assets/createScopedStore-VWkEjqnA.js","assets/preload-helper-BLdHbfdN.js","assets/contextWindow-h4X5oJjz.js","assets/useProviderCatalog-CxmLsNAf.js","assets/input-B23WM9u5.js","assets/tool-call-types-CtytAxam.js","assets/pathUtils-DTWwEzHK.js","assets/commandFeedback-C8JG7P5C.js","assets/segmented-control-BXlWFDM8.js","assets/dist-DQaZwNEz.js","assets/storage.adapter-DafyA8In.js","assets/inboxStore-CC3pAzZZ.js","assets/state-mark-Hjx5ToFs.js","assets/cronJobsStore-DBkn33E8.js","assets/ToolCallMessage-BFqfgkCH.js","assets/code-xml-C3fKotSy.js","assets/FilePreviewSheet-CfXThsQp.js","assets/minus-DpXqEYpv.js","assets/plus-BmhG7IUi.js","assets/refresh-cw-BxmkSO32.js","assets/triangle-alert-DnqNE8_X.js","assets/file-plus-corner-TXCx13rk.js","assets/pencil-DbIlj5g0.js","assets/search-BUOQUhrF.js","assets/terminal-gOELI9ta.js","assets/formatDuration-BbWTR_M_.js","assets/tools-MfK2-0IV.js","assets/index-QA9eWHUp.css","assets/elk.bundled-ChRT-c4f.js","assets/FlowSurface-CdVOTRYI.js","assets/src-C_gRsKqw.js","assets/value-CHmTzbgv.js","assets/shim-IYZxwmPZ.js","assets/FlowSurface-ChafqZqb.css"])))=>i.map(i=>d[i]);
2
+ import{o as e,r as t}from"./rolldown-runtime-BCiCTKAo.js";import{t as n}from"./react-BWPDF9mI.js";import{t as r}from"./jsx-runtime-BB9-612F.js";import{d as i,f as a,h as o,l as s,n as c,r as l,t as u}from"./pendingActionsStore-Bks-EsV3.js";import{n as d}from"./code-xml-C3fKotSy.js";import{a as f,c as p,i as m,n as h,o as g,s as _,t as v}from"./select-B-SEd4I2.js";import{H as y,L as b,R as ee,h as x,t as te}from"./FilePreviewSheet-CfXThsQp.js";import{n as S,t as ne}from"./file-plus-corner-TXCx13rk.js";import{t as re}from"./info-Dc1D2lOq.js";import{t as C}from"./minus-DpXqEYpv.js";import{t as w}from"./triangle-alert-DnqNE8_X.js";import{g as ie}from"./timer.adapter-DgrMEqxC.js";import{t as T}from"./segmented-control-BXlWFDM8.js";import{t as E}from"./log-DL1J6840.js";import{t as ae}from"./createScopedStore-VWkEjqnA.js";import{t as D}from"./preload-helper-BLdHbfdN.js";import{D as O,E as oe,Mr as se,T as k,_ as ce,a as le,b as ue,c as de,d as A,f as j,g as fe,i as pe,k as me,l as M,m as he,nu as ge,ru as _e,s as ve,u as N,v as ye,x as be,y as xe,yr as Se}from"./useTheme-BWGWet54.js";import{c as Ce,n as we}from"./pathUtils-DTWwEzHK.js";import{t as Te}from"./runDetached-BTPJqi-A.js";import{t as Ee}from"./dom.adapter-C26vNdMA.js";import{t as De}from"./formatDuration-BbWTR_M_.js";import{C as Oe,Cn as ke,D as Ae,E as je,O as Me,S as Ne,Sn as Pe,T as Fe,_ as Ie,_n as Le,b as Re,c as ze,d as Be,f as Ve,g as He,h as Ue,k as We,l as Ge,m as Ke,p as qe,rt as P,u as Je,v as Ye,vn as Xe,w as Ze,wn as Qe,x as $e,y as et,yn as tt}from"./index-R-jfstMQ.js";var nt={name:`arrow-down-right`,size:24,node:[[`path`,{d:`m7 7 10 10`,key:`1fmybs`}],[`path`,{d:`M17 7v10H7`,key:`6fjiku`}]]};nt.node;var rt=o(nt),it={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};it.node;var at=o(it),ot={name:`circle-x`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]],aliases:[`x-circle`]};ot.node;var st=o(ot),ct={name:`database`,size:24,node:[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]};ct.node;var lt=o(ct),ut={name:`diamond`,size:24,node:[[`path`,{d:`M2.7 10.3a2.41 2.41 0 0 0 0 3.41l7.59 7.59a2.41 2.41 0 0 0 3.41 0l7.59-7.59a2.41 2.41 0 0 0 0-3.41l-7.59-7.59a2.41 2.41 0 0 0-3.41 0Z`,key:`1f1r0c`}]]};ut.node;var dt=o(ut),ft={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`]};ft.node;var pt=o(ft),mt={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`}]]};mt.node;var ht=o(mt),gt={name:`rectangle-horizontal`,size:24,node:[[`rect`,{width:`20`,height:`12`,x:`2`,y:`6`,rx:`2`,key:`9lu3g6`}]]};gt.node;var _t=o(gt),vt={name:`shield-question-mark`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3`,key:`mhlwft`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]],aliases:[`shield-question`]};vt.node;var yt=o(vt),bt={name:`square`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]};bt.node;var xt=o(bt);function St(e){return e.type??`static`}function Ct(e){let t=new Map(e.nodes.map(e=>[e.id,0]));for(let n of e.edges)n.from!==n.to&&t.set(n.to,(t.get(n.to)??0)+1);let n=new Set,r=[];for(;r.length<e.nodes.length;){let i=e.nodes.find(e=>!n.has(e.id)&&t.get(e.id)===0)??e.nodes.find(e=>!n.has(e.id));if(!i)break;n.add(i.id),r.push(i);for(let n of e.edges)n.from===i.id&&n.to!==i.id&&t.set(n.to,(t.get(n.to)??0)-1)}return r}function wt(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Map((e.groups??[]).map(e=>[e.id,e.label])),r=(e,n)=>{let r=t.get(e);return r?[{node:r,edge:n}]:[]};return Ct(e).map(t=>({node:t,groupLabel:t.group?n.get(t.group)??null:null,incoming:e.edges.filter(e=>e.to===t.id).flatMap(e=>r(e.from,e)),outgoing:e.edges.filter(e=>e.from===t.id).flatMap(e=>r(e.to,e))}))}function Tt(e){return{step:e.node.label,edge:St(e.edge),...e.edge.label?{label:e.edge.label}:{}}}function Et(e,t){let n=wt(e).find(e=>e.node.id===t);if(!n)return null;let{node:r}=n;return{...e.title?{diagram:e.title}:{},step:r.label,...r.description?{description:r.description}:{},...r.kind?{kind:r.kind}:{},...r.status?{status:r.status}:{},...n.groupLabel?{group:n.groupLabel}:{},...r.path?{path:r.path}:{},...r.line?{line:r.line}:{},upstream:n.incoming.map(Tt),downstream:n.outgoing.map(Tt)}}function Dt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return`h${(t>>>0).toString(16)}:${e.length}`}var F=e(n(),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 I=e(r(),1),Ot=(0,F.createContext)(null);function kt(e,t){return e?null:Object.keys(t).length===0?{}:Fe(t)}function At({store:e,initialState:t={},onStateChange:n,children:r}){let i=(0,F.useRef)(void 0);!e&&!i.current&&(i.current=Ze(t));let a=e??i.current,o=(0,F.useRef)(a);o.current=a;let s=(0,F.useRef)(!!e);s.current=!!e,(0,F.useRef)(e?`controlled`:`uncontrolled`),(0,F.useRef)(!1);let c=(0,F.useRef)(t),l=(0,F.useRef)(kt(!!e,t));(0,F.useEffect)(()=>{if(e||t===c.current)return;c.current=t;let n=t&&Object.keys(t).length>0?Fe(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,F.useSyncExternalStore)(a.subscribe,a.getSnapshot,a.getServerSnapshot??a.getSnapshot),d=(0,F.useRef)(n);d.current=n;let f=(0,F.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,F.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))je(n,r)!==i&&t.push({path:r,value:i});t.length>0&&d.current?.(t)}},[]),m=(0,F.useCallback)(e=>o.current.get(e),[]),h=(0,F.useCallback)(()=>o.current.getSnapshot(),[]),g=(0,F.useMemo)(()=>({state:u,get:m,set:f,update:p,getSnapshot:h}),[u,m,f,p,h]);return(0,I.jsx)(Ot.Provider,{value:g,children:r})}function L(){let e=(0,F.useContext)(Ot);if(!e)throw Error(`useStateStore must be used within a StateProvider`);return e}function jt(e){let{state:t}=L();return je(t,e)}var Mt=(0,F.createContext)(null);function Nt({children:e}){let{state:t}=L(),n=(0,F.useMemo)(()=>({stateModel:t}),[t]),r=(0,F.useMemo)(()=>e=>Be(e,n),[n]),i=(0,F.useMemo)(()=>({isVisible:r,ctx:n}),[r,n]);return(0,I.jsx)(Mt.Provider,{value:i,children:e})}function Pt(){let e=(0,F.useContext)(Mt);if(!e)throw Error(`useVisibility must be used within a VisibilityProvider`);return e}var Ft=(0,F.createContext)(null),It={};function Lt(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 Rt(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||!Lt(t.args,i.args))return!1}return!0}function zt({customFunctions:e=It,children:t}){let{state:n,getSnapshot:r}=L(),[i,a]=(0,F.useState)({}),o=(0,F.useRef)({}),[s,c]=(0,F.useState)({}),l=(0,F.useCallback)((e,t)=>{c(n=>{let r=n[e];return r&&Rt(r,t)?n:{...n,[e]:t}})},[]),u=(0,F.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=$e(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,F.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,F.useCallback)(e=>{let{[e]:t,...n}=o.current;o.current=n,a(n)},[]),p=(0,F.useCallback)(()=>{let e=!0;for(let[t,n]of Object.entries(s))u(t,n).valid||(e=!1);return e},[s,u]),m=(0,F.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,I.jsx)(Ft.Provider,{value:m,children:t})}function Bt(){return(0,F.useContext)(Ft)}var Vt=0;function Ht(){return Vt+=1,`${Date.now()}-${Vt}`}function Ut(e,t){if(e==null)return e;if(e===`$id`)return Ht();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 Ht()}if(Array.isArray(e))return e.map(e=>Ut(e,t));if(typeof e==`object`){let n={};for(let[r,i]of Object.entries(e))n[r]=Ut(i,t);return n}return e}var Wt=(0,F.createContext)(null);function Gt({handlers:e={},navigate:t,children:n}){let{get:r,set:i,getSnapshot:a}=L(),o=Bt(),[s,c]=(0,F.useState)(e),[l,u]=(0,F.useState)(new Set),[d,f]=(0,F.useState)(null),p=(0,F.useCallback)((e,t)=>{c(n=>({...n,[e]:t}))},[]),m=(0,F.useCallback)(async e=>{let n=Ie(e,a()),c=Ke(),l=Date.now();Ue({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=Ut(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 Ve({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 Ve({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();He({id:c,name:n.action,ok:d,at:e,durationMs:e-l,error:p})}},[s,r,i,a,t,o]),h=(0,F.useCallback)(()=>{d?.resolve()},[d]),g=(0,F.useCallback)(()=>{d?.reject()},[d]),_=(0,F.useMemo)(()=>({handlers:s,loadingActions:l,pendingConfirmation:d,execute:m,confirm:h,cancel:g,registerHandler:p}),[s,l,d,m,h,g,p]);return(0,I.jsx)(Wt.Provider,{value:_,children:n})}function R(){let e=(0,F.useContext)(Wt);if(!e)throw Error(`useActions must be used within an ActionProvider`);return e}function Kt({confirm:e,onConfirm:t,onCancel:n}){let r=e.variant===`danger`;return(0,I.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,I.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,I.jsx)(`h3`,{style:{margin:`0 0 8px 0`,fontSize:`18px`,fontWeight:600},children:e.title}),(0,I.jsx)(`p`,{style:{margin:`0 0 24px 0`,color:`#6b7280`},children:e.message}),(0,I.jsxs)(`div`,{style:{display:`flex`,gap:`12px`,justifyContent:`flex-end`},children:[(0,I.jsx)(`button`,{onClick:n,style:{padding:`8px 16px`,borderRadius:`6px`,border:`1px solid #d1d5db`,backgroundColor:`white`,cursor:`pointer`},children:e.cancelLabel??`Cancel`}),(0,I.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 qt=(0,F.createContext)(null);function Jt({item:e,index:t,basePath:n,children:r}){return(0,I.jsx)(qt.Provider,{value:{item:e,index:t,basePath:n},children:r})}function Yt(){return(0,F.useContext)(qt)}var Xt=new WeakMap,Zt={},Qt=class extends F.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}},$t={},en=F.createContext($t);function tn(){return F.useContext(en)}var nn=F.createContext(void 0);function rn(){return F.useContext(nn)}function an(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 on(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function sn(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)&&sn(r[e],i[e]))}function cn(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]=cn(e[n]);return t}function ln(e,t){if(Object.is(e,t))return e;let n=Array.isArray(e);if(n!==Array.isArray(t)||!n&&(!on(e)||!on(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=ln(r[e],t),Object.is(r[e],t)||(s=!1)):s=!1,o[e]=t}return s?e:o}function un(e){let t=(0,F.useRef)({}),n=(0,F.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&&sn(l.own,t.element)&&sn(l.children,t.childVersions)?l.version:++n.current;o.delete(t.key),i[t.key]={own:cn(t.element),children:t.childVersions,version:u},a[t.key]=u,c.pop()}}return t.current=i,a}var dn=F.memo(function({Component:e,element:t,slots:n,emit:r,on:i,bindings:a,loading:o,children:s}){return(0,I.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 fn(){return F.useSyncExternalStore(Oe,qe,()=>!1)}function pn({element:e,elementKey:t,spec:n,registry:r,loading:i,fallback:a,signatures:o}){let s=fn(),c=Yt(),{ctx:l}=Pt(),{execute:u}=R(),{getSnapshot:d,state:f}=L(),p=tn(),m=rn(),h=(0,F.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?Ne(e.visible):{container:e.visible,itemFilter:void 0},_=g.itemFilter,v=g.container===void 0||Be(g.container,h),y=e.on,b=(0,F.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]=Ye(i,t);await u({...e,params:n})}},[y,u,h,d]),ee=(0,F.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]),x=e.watch,te=(0,F.useRef)(null),S=(0,F.useRef)(void 0),ne=(0,F.useRef)(void 0),re=(0,F.useRef)({}),C=(0,F.useMemo)(()=>{if(!x)return;let e={};for(let t of Object.keys(x))e[t]=je(f,t);let t=S.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 S.current=e,e},[x,f]);if((0,F.useEffect)(()=>{if(!x||!C)return;let e=Object.keys(x);if(e.length===0)return;let t=te.current;if(te.current=C,t===null)return;let n=!1;return(async()=>{for(let r of e){if(n)break;if(C[r]!==t[r]){let e=x[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]=Ye(i,t);if(await u({...e,params:r}),n)break}}}})().catch(console.error),()=>{n=!0}},[x,C,u,h,d]),!v)return null;let w=e.props??Zt,ie=an(et(w,h),ne),T=ln(re.current,Re(w,h));re.current=T;let E=T===e.props?e:{...e,props:T},ae=r[E.type]??a;if(!ae)return console.warn(`No renderer for component type: ${E.type}`),null;let D=Xt.get(r)?.[E.type];if(E.slots&&D?.slots){let e=new Set(D.slots);for(let t of Object.keys(E.slots))t==="default"?console.warn(`[json-render] Component "${E.type}" uses slots.default. Use "children" for default slot content.`):e.has(t)||console.warn(`[json-render] Unknown slot "${t}" on component "${E.type}". Available slots: ${D.slots.join(`, `)}`)}let O=(e,t)=>e.map(e=>{let s=n.elements[e];if(!s){if(!i){let n=t?`in slot "${t}" of "${E.type}"`:`as child of "${E.type}"`;console.warn(`[json-render] Missing element "${e}" referenced ${n}. This element will not render.`)}return null}return(0,I.jsx)(mn,{element:s,elementKey:e,spec:n,registry:r,loading:i,fallback:a,signatures:o},e)}),oe=E.repeat?(0,I.jsx)(hn,{element:E,spec:n,registry:r,loading:i,fallback:a,itemFilter:_,signatures:o}):E.children?O(E.children):void 0,se=E.slots?Object.fromEntries(Object.entries(E.slots).map(([e,t])=>[e,O(t,e)])):void 0,k=(0,I.jsx)(dn,{Component:ae,signature:o[t??``],execute:u,actionContext:c,functions:p,directives:m,element:E,slots:se,emit:b,on:ee,bindings:ie,loading:i,children:oe}),ce=s&&t?(0,I.jsx)(`span`,{"data-jr-key":t,style:{display:`contents`},children:k}):k;return(0,I.jsx)(Qt,{elementType:E.type,resetKey:o[t??``],children:ce})}var mn=F.memo(function(e){return(0,I.jsx)(pn,{...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 hn({element:e,spec:t,registry:n,loading:r,fallback:i,signatures:a,itemFilter:o}){let{state:s}=L(),{ctx:c}=Pt(),l=Yt(),u=e.repeat,d=Me(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=(je(s,d)??[]).map((e,t)=>({itemValue:e,index:t})).filter(({itemValue:e,index:t})=>o===void 0||Be(o,{...c,repeatItem:e,repeatIndex:t}));return(0,I.jsx)(I.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,I.jsx)(Jt,{item:o,index:s,basePath:Ae(d,s),children:e.children?.map(o=>{let s=t.elements[o];return s?(0,I.jsx)(mn,{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 gn({spec:e,registry:t,loading:n,fallback:r}){let i=un(e);if(!e||!e.root)return null;let a=e.elements[e.root];return a?(0,I.jsx)(mn,{element:a,elementKey:e.root,spec:e,registry:t,loading:n,fallback:r,signatures:i}):null}function _n({registry:e,store:t,initialState:n,handlers:r,navigate:i,validationFunctions:a,functions:o,directives:s,onStateChange:c,children:l}){let u=(0,F.useMemo)(()=>s?Ge(s):void 0,[s]);return(0,I.jsx)(At,{store:t,initialState:n,onStateChange:c,children:(0,I.jsx)(Nt,{children:(0,I.jsx)(zt,{customFunctions:a,children:(0,I.jsx)(Gt,{handlers:r,navigate:i,children:(0,I.jsx)(en.Provider,{value:o??$t,children:(0,I.jsxs)(nn.Provider,{value:u,children:[l,(0,I.jsx)(vn,{})]})})})})})})}function vn(){let{pendingConfirmation:e,confirm:t,cancel:n}=R();return e?.action.confirm?(0,I.jsx)(Kt,{confirm:e.action.confirm,onConfirm:t,onCancel:n}):null}function yn(e,t){let{set:n}=L();return[e,(0,F.useCallback)(e=>{t&&n(t,e)},[t,n])]}var bn=`/_drill`;function xn(e){return`${bn}/${e}`}var Sn=Se({dimension:se(),value:se(),into:se(),metric:se(),period:fe.optional()});function Cn(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 z(e,t){e.view.getState().showNotice(t)}function wn(e,t){e.host().sendToAgent?e.view.getState().proposeAgentMessage({headline:t.headline,message:ve(t)}):z(e,`Asking the agent is not available in this view`)}async function Tn(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 En(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=A[`file.open`].params.safeParse(n);if(!t.success)return z(e,`That file link is malformed`);let i=Cn(r.workspaceRoot,t.data.path);if(!i)return z(e,`"${t.data.path}" is outside this chat's workspace`);e.view.getState().openPreview(i);return}case`link.open`:{let t=A[`link.open`].params.safeParse(n);if(!t.success)return z(e,`Only https links can be opened`);r.openLink(t.data.url);return}case`dataset.refresh`:{let t=A[`dataset.refresh`].params.safeParse(n);t.success&&e.view.getState().refreshDataset(t.data.dataset);return}case`financial.drilldown`:{let t=A[`financial.drilldown`].params.safeParse(n);if(!t.success)return z(e,`That drilldown is malformed`);let{dataset:r,...i}=t.data;e.state.set(xn(r),i);return}case`agent.ask`:{let t=A[`agent.ask`].params.safeParse(n);return t.success?wn(e,le(`agent.ask`,t.data.prompt,t.data.context,i)):z(e,`That question is malformed`)}case`agent.investigate`:case`agent.fix`:{let r=A[t].params.safeParse(n);return r.success?wn(e,le(t,r.data.subject,r.data.context,i)):z(e,`That request is malformed`)}case`financial.explainVariance`:{let t=A[`financial.explainVariance`].params.safeParse(n);if(!t.success)return z(e,`That explanation request is malformed`);let a=e.spec.datasets?.[t.data.dataset];if(!a)return z(e,`Unknown dataset "${t.data.dataset}"`);let o=t.data.compareWith??`previous-period`,s=await Tn(r,a,{metrics:[t.data.metric],...t.data.period?{period:t.data.period}:{},...t.data.filters?{filters:t.data.filters}:{},compare:o});return wn(e,pe({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 Dn(e){let t={};for(let n of Object.keys(A))he(n)&&A[n].class!==`local`&&(t[n]=async t=>{if(e.host().readonly)return;let r=me.safeParse(t);if(!r.success)return z(e,`That action's parameters are not plain data`);await En(e,n,r.data)});return t}var B=`Other`;function On(e,t){let n=t.map(t=>N(e.metrics[t])),[r]=n;return n.every(e=>e.format===r?.format&&e.currency===r?.currency)}function kn(e,t,n,r){let i=e.dimensions?.[t];return i?.kind===`time`?xe(r,n.grain??i.grain??`month`):r}function An(e,t){let n=[];for(let r of e){let e=r.dimensions[t];e!==void 0&&!n.includes(e)&&n.push(e)}return n}function jn(e,t,n){let r=e.dimensions?.[t]?.order;return[...n].sort((e,t)=>{let n=r?r.indexOf(e):-1,i=r?r.indexOf(t):-1;return n===i?e.localeCompare(t,`en`,{numeric:!0}):n===-1?1:i===-1?-1:n-i})}function Mn(e,t,n,r){let i=new Map;for(let r of e){let e=r.dimensions[t]??``;i.set(e,(i.get(e)??0)+Math.abs(r.values[n]??0))}let a=[...i.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e);return new Set(a.length>r+1?a.slice(0,r):a)}function V(e,t,n,r,i){return{x:t,xLabel:e.xLabels[t]??t,series:n,value:r,...i}}function Nn(e,t,n,r){let i=An(n.rows,e.dimension);return{kind:e.chart,xOrder:i,xLabels:Object.fromEntries(i.map(r=>[r,kn(t,e.dimension,n,r)])),format:N(t.metrics[r]),valueLabel:O(r,t.metrics[r]),dimensionLabel:k(e.dimension,t.dimensions?.[e.dimension])}}function Pn(e,t,n){let[r]=e.metrics;if(!r)return{ok:!1,message:`A chart needs a metric`};if(!On(t,[...e.metrics,...e.secondaryMetric?[e.secondaryMetric]:[]]))return{ok:!1,message:`These metrics use different units, and a chart has one axis. Show them in two charts.`};switch(e.chart){case`waterfall`:return Ln(e,t,n,r);case`composition`:return Rn(e,t,n,r);case`combo`:return In(e,t,n,r);default:return Fn(e,t,n)}}function Fn(e,t,n){let[r=``]=e.metrics;if(e.chart===`stacked-bar`&&!e.series&&e.metrics.length<2)return{ok:!1,message:`A stacked bar needs a series dimension or at least two metrics to stack`};if(e.series&&e.metrics.length>1)return{ok:!1,message:`Split by a series dimension with one metric, or list several metrics without a series`};let i=Nn(e,t,n,r),a=[],o=[];if(e.series){let s=e.series,c=Mn(n.rows,s,r,7),l=jn(t,s,[...c]),u=An(n.rows,s).some(e=>!c.has(e));l.forEach((e,t)=>o.push({id:e,label:e,role:`series`,slot:t})),u&&o.push({id:B,label:B,role:`series`,slot:l.length});let d=new Map;for(let t of n.rows){let n=t.dimensions[e.dimension],i=t.dimensions[s]??``,a=t.values[r];if(n===void 0||a==null)continue;let o=`${n}\u0001${c.has(i)?i:B}`;d.set(o,(d.get(o)??0)+a)}for(let[e,t]of d){let[n=``,r=``]=e.split(``);a.push(V(i,n,r,t))}return{ok:!0,model:{...i,points:a,series:o}}}e.metrics.forEach((e,n)=>{o.push({id:e,label:O(e,t.metrics[e]),role:`series`,slot:n})}),n.comparison&&e.metrics.forEach(e=>{o.push({id:`${e}::compare`,label:`${O(e,t.metrics[e])} (${n.comparison?.label})`,role:`compare`,slot:null})});for(let t of n.rows){let n=t.dimensions[e.dimension];if(n!==void 0)for(let r of e.metrics){let e=t.values[r];e!=null&&a.push(V(i,n,r,e));let o=t.compare?.[r];o!=null&&a.push(V(i,n,`${r}::compare`,o))}}return{ok:!0,model:{...i,points:a,series:o}}}function In(e,t,n,r){if(!e.secondaryMetric)return{ok:!1,message:`A combo chart needs a secondaryMetric drawn as a line over the bars`};let i=e.secondaryMetric,a=Nn(e,t,n,r),o=[];for(let t of n.rows){let n=t.dimensions[e.dimension];if(n===void 0)continue;let s=t.values[r],c=t.values[i];s!=null&&o.push(V(a,n,r,s)),c!=null&&o.push(V(a,n,i,c))}return{ok:!0,model:{...a,points:o,series:[{id:r,label:O(r,t.metrics[r]),role:`series`,slot:0},{id:i,label:O(i,t.metrics[i]),role:`secondary`,slot:1}]}}}function Ln(e,t,n,r){if(e.series)return{ok:!1,message:`A waterfall shows one metric; drop the series dimension`};let i=Nn(e,t,n,r),a=[],o=0;for(let t of n.rows){let n=t.dimensions[e.dimension],s=t.values[r];if(n===void 0||s==null)continue;let c=o;o+=s,a.push(V(i,n,s>=0?`increase`:`decrease`,s,{start:c,end:o}))}let s=e.totalLabel??`Total`;return a.push(V(i,s,`total`,o,{start:0,end:o})),{ok:!0,model:{...i,points:a,xOrder:[...a.map(e=>e.x)],xLabels:{...i.xLabels,[s]:s},series:[{id:`increase`,label:`Increase`,role:`increase`,slot:null},{id:`decrease`,label:`Decrease`,role:`decrease`,slot:null},{id:`total`,label:s,role:`total`,slot:null}]}}}function Rn(e,t,n,r){let i=Nn(e,t,n,r),a=n.rows.map(t=>({key:t.dimensions[e.dimension]??``,value:t.values[r]??0})).filter(e=>e.value!==0);if(a.some(e=>e.value<0))return{ok:!1,message:`A part-to-whole chart cannot show negative values; use a bar chart`};let o=[...a].sort((e,t)=>t.value-e.value),s=o.length>6?o.slice(0,5):o,c=o.slice(s.length).reduce((e,t)=>e+t.value,0),l=jn(t,e.dimension,s.map(e=>e.key)),u=new Map(s.map(e=>[e.key,e.value])),d=l.map((e,t)=>({id:e,label:i.xLabels[e]??e,role:`series`,slot:t})),f=l.map(e=>V(i,e,e,u.get(e)??0));return c>0&&(d.push({id:B,label:B,role:`series`,slot:l.length}),f.push(V(i,B,B,c))),{ok:!0,model:{...i,points:f,series:d,xOrder:f.map(e=>e.x)}}}function zn(e,t){if(!t||t.x===void 0)return null;let n=String(t.x);return!e.xOrder.includes(n)||e.kind===`waterfall`&&n===e.xOrder[e.xOrder.length-1]?null:{x:n,series:t.series===void 0?``:String(t.series)}}var Bn=(0,F.createContext)(null);function Vn({value:e,children:t}){return(0,I.jsx)(Bn.Provider,{value:e,children:t})}function H(){let e=(0,F.useContext)(Bn);if(!e)throw Error(`GenUI components render only inside a GenUI view`);return e}var U=ae(`GenUIView`,()=>e=>({pendingAgentMessage:null,previewPath:null,previewProbe:null,refreshNonce:{},notice:null,proposeAgentMessage:t=>e({pendingAgentMessage:t,notice:null}),cancelAgentMessage:()=>e({pendingAgentMessage:null}),openPreview:t=>e({previewPath:t,previewProbe:null}),closePreview:()=>e({previewPath:null,previewProbe:null}),setPreviewProbe:t=>e({previewProbe:t}),refreshDataset:t=>e(e=>({refreshNonce:{...e.refreshNonce,[t]:(e.refreshNonce[t]??0)+1}})),showNotice:t=>e({notice:t})})),Hn=10,Un=`genui-dataset`;function Wn(e){return e.source===`file`?(e.refreshSeconds??Hn)*1e3:e.source===`mcp`&&e.refreshSeconds?e.refreshSeconds*1e3:!1}function W(e){let{spec:t}=H();return e?t.datasets?.[e]??null:null}function Gn(e,t){let n=P(),r=W(e),i=U.useScopedStore(t=>e?t.refreshNonce[e]??0:0),a=r!==null&&r.source!==`inline`&&n.queryDataset!==null&&t!==null,o=(0,F.useMemo)(()=>!r||r.source!==`inline`||!t?null:ce(r,r.rows,t),[r,t]),s=n.queryDataset,c=Pe({queryKey:[Un,n.chatId,e,r?Dt(JSON.stringify(r)):null,t?JSON.stringify(t):null,i],queryFn:async()=>{if(!r||!t||!s)throw Error(`dataset is not queryable`);return await s(r,t,i>0)},enabled:a,placeholderData:ke,refetchInterval:r&&a&&!n.readonly?Wn(r):!1,retry:!1});if(!r)return{status:`error`,message:`This view refers to a dataset "${e??``}" it does not declare`};if(!t)return{status:`loading`};if(o)return o.ok?{status:`ok`,result:o.result,refreshing:!1}:{status:`error`,message:o.message};if(!n.queryDataset)return{status:`unavailable`,message:`Live data is not included in a shared view`};if(c.error)return{status:`error`,message:We.source_unavailable};let l=c.data;if(!l)return{status:`loading`};switch(l.status){case`ok`:return{status:`ok`,result:l.result,refreshing:c.isPlaceholderData};case`needs_approval`:return l;case`error`:return{status:`error`,message:`${We[l.code]}: ${l.message}`}}}var Kn=`_kannaKey`,qn=`/_ui`;function Jn(e){let t=e.props[Kn];return typeof t==`string`?t:e.type}function G(e,t,n,r){let i=`${qn}/${Jn(e)}/${t}`,a=jt(i),{set:o}=L(),s=(0,F.useCallback)(e=>o(i,e),[i,o]);return[r(a)?a:n,s]}function Yn(e){return typeof e==`string`}function Xn(e){return typeof e==`boolean`}function Zn(e){return Array.isArray(e)&&e.every(e=>typeof e==`string`)}var Qn={neutral:`text-muted-foreground`,positive:`text-success-text`,negative:`text-destructive-text`,attention:`text-warning-text`,info:`text-info-text`};function K(e){return Qn[e]}function $n({tone:e,className:t}){let n=a(`h-3.5 w-3.5 shrink-0`,t);switch(e){case`positive`:return(0,I.jsx)(Le,{className:n,"aria-hidden":`true`});case`negative`:return(0,I.jsx)(st,{className:n,"aria-hidden":`true`});case`attention`:return(0,I.jsx)(w,{className:n,"aria-hidden":`true`});case`info`:return(0,I.jsx)(re,{className:n,"aria-hidden":`true`});case`neutral`:return(0,I.jsx)(C,{className:n,"aria-hidden":`true`})}}function er(e){return e===`positive`?`positive`:e===`negative`?`negative`:`neutral`}function tr({trend:e,className:t}){let n=a(`h-3.5 w-3.5 shrink-0`,t);return e===`up`?(0,I.jsx)(at,{className:n,"aria-hidden":`true`}):e===`down`?(0,I.jsx)(rt,{className:n,"aria-hidden":`true`}):(0,I.jsx)(C,{className:n,"aria-hidden":`true`})}function nr({component:e}){return(0,I.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,I.jsx)(w,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e,` could not be shown: its settings changed to an unsupported value`]})}function rr({server:e,tool:t}){let n=P(),r=Qe(),i=u(`genui.dataset.approve`,n.chatId??``,e,t),a=l(i),o=n.approveTool;return o?(0,I.jsx)(s,{size:`sm`,variant:`outline`,pending:a,onClick:()=>{c(i,async()=>{await o(e,t),await r.invalidateQueries({queryKey:[Un,n.chatId]})})},children:`Allow for this chat`}):null}function q({state:e,minHeight:t,emptyLabel:n}){return(0,I.jsx)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed border-border px-3 py-4 text-sm`,style:t?{minHeight:t}:void 0,children:(0,I.jsx)(ir,{state:e,emptyLabel:n})})}function ir({state:e,emptyLabel:t}){switch(e.status){case`loading`:return(0,I.jsxs)(`span`,{className:`flex items-center gap-2 text-muted-foreground`,role:`status`,children:[(0,I.jsx)(i,{}),` Loading data…`]});case`needs_approval`:return(0,I.jsxs)(`span`,{className:`flex flex-col items-center gap-2 text-center text-muted-foreground`,children:[(0,I.jsxs)(`span`,{className:`flex items-center gap-1.5 text-foreground`,children:[(0,I.jsx)(yt,{className:`h-4 w-4`,"aria-hidden":`true`}),`Action requires approval`]}),(0,I.jsx)(`span`,{className:`max-w-prose text-xs`,children:e.message}),(0,I.jsx)(rr,{server:e.server,tool:e.tool})]});case`unavailable`:return(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:t??e.message});case`error`:return(0,I.jsxs)(`span`,{className:`flex items-center gap-1.5 text-destructive-text`,role:`alert`,children:[(0,I.jsx)(w,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),e.message]})}}function ar({label:e,minHeight:t}){return(0,I.jsx)(`div`,{className:`flex items-center justify-center rounded-md border border-dashed border-border px-3 py-4 text-sm text-muted-foreground`,style:t?{minHeight:t}:void 0,children:e})}var or=50,J=`px-3 py-2 text-xs font-medium text-muted-foreground`;function sr({total:e,onShow:t}){return(0,I.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,I.jsxs)(s,{size:`sm`,variant:`ghost`,onClick:t,children:[`Show all `,e,` rows`]})})}function cr(e,t){let[n,r]=G(e,`expanded`,!1,Xn),i=!n&&t.length>or?(0,I.jsx)(sr,{total:t.length,onShow:()=>r(!0)}):null;return{visibleRows:n?t:t.slice(0,or),showAll:i}}function lr(e){if(!_e(e))return!1;let t=e.value;return t===`all`||t===``||t==null?!1:ge(t)?t.length>0:typeof t==`string`||typeof t==`number`}function ur(e){let t=me.safeParse(dr(e));if(!t.success)return null;let n=t.data.filters;return ge(n)?{...t.data,filters:n.filter(lr)}:t.data}function dr(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`_kannaKey`&&t!=null))}function Y(e){return e===`none`?void 0:e}function fr(e,t){let n=t?[...e??[],{dimension:t.dimension,value:t.value}]:e;return n&&n.length>0?[...n]:void 0}function pr(e){return e.metrics?[...e.metrics]:e.metric===void 0?[]:typeof e.metric==`string`?[e.metric]:[...e.metric]}function mr(e){return pr(e)[0]??``}function X({metrics:e,groupBy:t,period:n,compare:r,scenario:i,filters:a,sort:o,limit:s}){return{metrics:e,...t?{groupBy:t}:{},...n?{period:n}:{},...r?{compare:r}:{},...i?{scenario:i}:{},...a&&a.length>0?{filters:a}:{},...o?{sort:o}:{},...s===void 0?{}:{limit:s}}}function hr(e,t){let n=e.safeParse(t);return n.success?n.data:null}function Z(e,t){function n(n){let r=(0,F.useMemo)(()=>hr(e,ur(n.element.props)),[n.element.props]);return r?(0,I.jsx)(t,{...n,props:r}):(0,I.jsx)(nr,{component:n.element.type})}return n}var gr=(0,F.lazy)(()=>D(()=>import(`./VChartSurface-CMQoKhau.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46]))),_r={sm:200,md:260,lg:340};function vr(e){return e===`chart`||e===`table`}var yr=60;function br(e){let t=jt(xn(e??``));return(0,F.useMemo)(()=>{if(!e||!t)return null;let n=Sn.safeParse(t);return n.success?n.data:null},[e,t])}function xr(e,t){let n=pr(e),r=t?t.into:e.dimension;return X({metrics:e.secondaryMetric?[...n,e.secondaryMetric]:n,groupBy:e.series&&!t?[r,e.series]:[r],period:t?.period??e.period,compare:e.chart===`waterfall`||e.chart===`composition`||t?void 0:Y(e.compareWith),filters:fr(e.filters,t),sort:e.chart===`waterfall`?{by:r,direction:`asc`}:void 0,limit:e.limit??yr})}function Sr(e,t){return t?e.chart===`composition`?`composition`:`bar`:e.chart}function Cr({x:e,label:t,drill:n}){return n?(0,I.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,I.jsx)(I.Fragment,{children:t})}function wr({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,I.jsx)(`div`,{className:`max-h-80 overflow-auto rounded-md border border-border`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:e.dimensionLabel}),n.map(e=>(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:e.label},e.id))]})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:e.xOrder.map(i=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:`px-3 py-1.5 text-left font-normal text-foreground`,children:(0,I.jsx)(Cr,{x:i,label:e.xLabels[i]??i,drill:Tr(e,i)?t:null})}),n.map(t=>(0,I.jsx)(`td`,{className:`px-3 py-1.5 text-right tabular-nums text-foreground`,children:M(r(i,t.id),e.format)},t.id))]},i))})]})})}function Tr(e,t){return zn(e,{x:t})!==null}function Er({model:e,height:t,onPointClick:n}){let r=P().ChartRenderer??gr,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,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(`div`,{className:`w-full`,style:{height:t},"aria-hidden":`true`}),children:(0,I.jsx)(r,{model:e,height:t,label:i,onPointClick:n})})}function Dr({props:e,drill:t}){let{execute:n}=R(),{viewKey:r}=H(),i=P(),a=u(`genui.financial.explainVariance`,r,e.dataset),o=l(a),d=mr(e),f=(0,F.useCallback)(()=>{let r=fr(e.filters,t),i=t?.period??e.period;c(a,()=>n({action:`financial.explainVariance`,params:{dataset:e.dataset,metric:d,compareWith:Y(e.compareWith)??`previous-period`,...i?{period:i}:{},...r?{filters:r.map(e=>({...e}))}:{}}}))},[t,n,a,d,e]);return i.readonly||!i.sendToAgent?null:(0,I.jsxs)(s,{size:`sm`,variant:`ghost`,className:`gap-1.5`,pending:o,onClick:f,children:[o?null:(0,I.jsx)(ht,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Explain variance`]})}function Or(e,t,n,r){return e===`back`&&t?n:e===`figure`&&!t?r:null}function kr({datasetId:e,drill:t,decl:n,backRef:r,focusAfterRef:i}){let{execute:a}=R(),{viewKey:o}=H(),d=u(`genui.drill.back`,o,e),f=l(d),p=(0,F.useCallback)(()=>{i.current=`figure`,c(d,()=>a({action:`setState`,params:{statePath:xn(e),value:null}}))},[e,a,i,d]);return(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,I.jsxs)(s,{ref:r,size:`sm`,variant:`ghost`,className:`gap-1`,onClick:p,pending:f,children:[f?null:(0,I.jsx)(Xe,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Back`]}),(0,I.jsxs)(`span`,{children:[k(t.dimension,n.dimensions?.[t.dimension]),`: `,(0,I.jsx)(`span`,{className:`text-foreground`,children:Ar(t,n)}),` `,`by `,k(t.into,n.dimensions?.[t.into]).toLowerCase()]})]})}function Ar(e,t){let n=t.dimensions?.[e.dimension];return n?.kind===`time`?xe(e.value,n.grain??`month`):e.value}function jr(e,t,n,r){let i=t?t.period.label:be(e.period);if(n)return r?.dimensions?.[n.dimension]?.kind===`time`?Ar(n,r):i;let a=Y(e.compareWith),o=t?.comparison?.label??(a?ue(a):null);return o?`${i} · vs ${o.charAt(0).toLowerCase()}${o.slice(1)}`:i}var Mr=Z(j.FinancialChart.props,({element:e,props:t})=>{let n=W(t.dataset),r=br(t.drilldown?t.dataset:void 0),i=(0,F.useMemo)(()=>xr(t,r),[t,r]),o=Gn(t.dataset,i),[s,d]=G(e,`view`,`chart`,vr),{execute:f}=R(),{viewKey:p}=H(),m=u(`genui.financial.drilldown`,p,t.dataset),h=(0,F.useId)(),g=(0,F.useRef)(null),_=(0,F.useRef)(null),v=(0,F.useRef)(null),y=l(m),b=(0,F.useMemo)(()=>!n||o.status!==`ok`?null:Pn({chart:Sr(t,r),metrics:pr(t),...t.secondaryMetric?{secondaryMetric:t.secondaryMetric}:{},dimension:r?r.into:t.dimension,...t.series&&!r?{series:t.series}:{},...t.totalLabel?{totalLabel:t.totalLabel}:{}},n,o.result),[n,r,t,o]),ee=t?.drilldown,x=(0,F.useCallback)(e=>{ee&&!r&&c(m,()=>f({action:`financial.drilldown`,params:{dataset:t.dataset,metric:mr(t),dimension:t.dimension,value:e.x,into:ee.dimension,...t.period?{period:t.period}:{}}}))},[r,m,ee,f,t]);(0,F.useEffect)(()=>{let e=Or(v.current,r!==null,_.current,g.current);e&&(v.current=null,e.focus())},[r]);let te=(0,F.useCallback)(e=>{v.current=`back`,x(e)},[x]),S=_r[t.height??`md`],ne=mr(t),re=t.title??O(ne,n?.metrics[ne]),C=jr(t,o.status===`ok`?o.result:null,r,n),w=t.drilldown&&!r&&n?{intoLabel:k(t.drilldown.dimension,n.dimensions?.[t.drilldown.dimension]).toLowerCase(),pending:y,onDrill:te}:null;return(0,I.jsxs)(`figure`,{ref:g,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":h,children:[(0,I.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{id:h,className:`text-sm font-medium text-foreground`,children:re}),(0,I.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:C})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[t.explain?(0,I.jsx)(Dr,{props:t,drill:r}):null,(0,I.jsx)(T,{size:`sm`,value:s,onValueChange:d,options:[{value:`chart`,label:`Chart`},{value:`table`,label:`Table`}]})]})]}),r&&n?(0,I.jsx)(kr,{datasetId:t.dataset,drill:r,decl:n,backRef:_,focusAfterRef:v}):null,o.status===`ok`?null:(0,I.jsx)(q,{state:o,minHeight:S}),o.status===`ok`&&b&&!b.ok?(0,I.jsx)(ar,{label:b.message,minHeight:S}):null,o.status===`ok`&&b?.ok&&b.model.points.length===0?(0,I.jsx)(ar,{label:`No data for the selected period`,minHeight:S}):null,o.status===`ok`&&b?.ok&&b.model.points.length>0?(0,I.jsxs)(`div`,{className:a(`transition-opacity duration-[var(--motion-quick)]`,(o.refreshing||y)&&`opacity-60`),"aria-busy":y||void 0,children:[s===`chart`?(0,I.jsx)(Er,{model:b.model,height:S,onPointClick:t.drilldown&&!r?x:null}):(0,I.jsx)(wr,{model:b.model,drill:w}),o.result.truncated?(0,I.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[`Showing the first `,o.result.rows.length,` groups.`]}):null]}):null]})}),Q=`px-3 py-1.5 tabular-nums`;function Nr(e,t){return t?e.dimensions[t]??``:`Total`}function Pr({element:e,config:t,result:n,decl:r}){let{metrics:i}=t,{visibleRows:o,showAll:s}=cr(e,n.rows);return(0,I.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:t.rows?k(t.rows,r.dimensions?.[t.rows]):``}),i.map(e=>(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:O(e,r.metrics[e])},e))]})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:o.map(e=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Nr(e,t.rows)}),i.map(t=>(0,I.jsx)(`td`,{className:a(Q,`text-right text-foreground`),children:M(e.values[t]??null,N(r.metrics[t]))},t))]},e.key))})]}),s]})}function Fr({value:e,compare:t,format:n,direction:r,accounting:i}){let o=de(e,t,n,r),s=K(er(o.sentiment));return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`td`,{className:a(Q,`text-right text-muted-foreground`),children:M(t,n,{accounting:i})}),(0,I.jsx)(`td`,{className:a(Q,`text-right`,s),children:o.amountText}),(0,I.jsx)(`td`,{className:a(Q,`text-right`,s),children:o.ratioText})]})}function Ir(e){return(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:e}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:`Change`}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:`Change %`})]})}function Lr({element:e,config:t,result:n,decl:r}){let i=t.metrics[0]??``,o=r.metrics[i],s=N(o),{visibleRows:c,showAll:l}=cr(e,n.rows),u=n.comparison?.label;return(0,I.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:t.rows?k(t.rows,r.dimensions?.[t.rows]):``}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:O(i,o)}),u?Ir(u):null]})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:c.map(e=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-1.5 text-left font-normal text-foreground`,children:Nr(e,t.rows)}),(0,I.jsx)(`td`,{className:a(Q,`text-right text-foreground`),children:M(e.values[i]??null,s)}),u?(0,I.jsx)(Fr,{value:e.values[i]??null,compare:e.compare?.[i]??null,format:s,direction:o?.direction,accounting:!1}):null]},e.key))})]}),l]})}function Rr(e){let t=e.filter(e=>typeof e==`number`);return t.length===0?null:t.reduce((e,t)=>e+t,0)}function zr(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:Rr(n.map(e=>e.values[t])),compare:Rr(n.map(e=>e.compare?.[t]))}))}function Br({element:e,config:t,result:n,decl:r}){let[i,o]=G(e,`collapsed`,[],Zn),s=new Set(i),c=t.metrics[0]??``,l=r.metrics[c],u=N(l),f=n.comparison?.label,p=zr(n,c,t.groupRows,t.groupRows?r.dimensions?.[t.groupRows]?.order:void 0),m=e=>{o(s.has(e)?i.filter(t=>t!==e):[...i,e])},h=e=>M(e,u,{accounting:!0}),g=(t.totals??[]).map(e=>{let t=p.filter(t=>e.groups.includes(t.name));return{label:e.label,value:Rr(t.map(e=>e.value)),compare:Rr(t.map(e=>e.compare))}});return(0,I.jsx)(`div`,{className:`max-h-[32rem] overflow-auto rounded-md border border-border`,children:(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsxs)(`tr`,{className:`border-b border-border`,children:[(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-left`),children:t.rows?k(t.rows,r.dimensions?.[t.rows]):``}),(0,I.jsx)(`th`,{scope:`col`,className:a(J,`text-right`),children:n.period.label}),f?Ir(f):null]})}),(0,I.jsxs)(`tbody`,{children:[p.map(e=>{let n=s.has(e.name),r=!!t.groupRows;return(0,I.jsxs)(F.Fragment,{children:[r?(0,I.jsxs)(`tr`,{className:`border-t border-border`,children:[(0,I.jsx)(`th`,{scope:`rowgroup`,className:`sticky left-0 bg-card px-2 py-1.5 text-left font-medium text-foreground`,children:(0,I.jsxs)(`button`,{type:`button`,onClick:()=>m(e.name),"aria-expanded":!n,className:`flex items-center gap-1 rounded px-1 hover:bg-muted`,children:[n?(0,I.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,I.jsx)(tt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e.name]})}),(0,I.jsx)(`td`,{className:a(Q,`text-right font-medium text-foreground`),children:h(e.value)}),f?(0,I.jsx)(Fr,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]}):null,n?null:e.rows.map(e=>(0,I.jsxs)(`tr`,{children:[(0,I.jsx)(`th`,{scope:`row`,className:a(`sticky left-0 bg-card py-1 text-left font-normal text-foreground`,r?`pl-9 pr-3`:`px-3`),children:Nr(e,t.rows)}),(0,I.jsx)(`td`,{className:a(Q,`text-right text-foreground`),children:h(e.values[c]??null)}),f?(0,I.jsx)(Fr,{value:e.values[c]??null,compare:e.compare?.[c]??null,format:u,direction:l?.direction,accounting:!0}):null]},e.key))]},e.name||`_`)}),g.map(e=>(0,I.jsxs)(`tr`,{className:`border-t-2 border-border`,children:[(0,I.jsx)(`th`,{scope:`row`,className:`sticky left-0 bg-card px-3 py-2 text-left font-semibold text-foreground`,children:e.label}),(0,I.jsx)(`td`,{className:a(Q,`text-right font-semibold text-foreground`),children:h(e.value)}),f?(0,I.jsx)(Fr,{value:e.value,compare:e.compare,format:u,direction:l?.direction,accounting:!0}):null]},e.label))]})]})})}function Vr({element:e,config:t,result:n,decl:r}){if(n.rows.length===0)return(0,I.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,I.jsx)(Br,{element:e,config:t,result:n,decl:r});case`comparison`:return(0,I.jsx)(Lr,{element:e,config:t,result:n,decl:r});case`detail`:return(0,I.jsx)(Pr,{element:e,config:t,result:n,decl:r})}}function Hr(e){return e.charAt(0).toLowerCase()+e.slice(1)}var Ur=Z(j.FinancialMetric.props,({props:e})=>{let t=W(e.dataset),n=br(e.dataset),r=(0,F.useMemo)(()=>X({metrics:[e.metric],period:e.period,compare:Y(e.compareWith),scenario:e.scenario,filters:fr(e.filters,n)}),[n,e]),i=Gn(e.dataset,r),o=t?.metrics[e.metric],s=e.label??O(e.metric,o);if(i.status!==`ok`)return(0,I.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-md border border-border p-3`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,I.jsx)(q,{state:i})]});let c=N(o),l=i.result.totals.values[e.metric]??null,u=i.result.totals.compare?.[e.metric]??null,d=de(l,u,c,o?.direction),f=er(d.sentiment);return(0,I.jsxs)(`div`,{className:a(`flex flex-col gap-1 rounded-md border border-border p-3`,i.refreshing&&`opacity-60`),children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:s}),(0,I.jsx)(`span`,{className:`text-2xl font-semibold leading-tight text-foreground`,children:M(l,c,{compact:!0})}),i.result.comparison&&d.amount!==null?(0,I.jsxs)(`span`,{className:a(`flex flex-wrap items-center gap-1 text-xs`,K(f)),children:[(0,I.jsx)(tr,{trend:d.trend}),(0,I.jsx)(`span`,{className:`font-medium tabular-nums`,children:d.ratioText}),(0,I.jsxs)(`span`,{className:`tabular-nums`,children:[`(`,d.amountText,`)`]}),(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`vs `,Hr(i.result.comparison.label)]})]}):null,i.result.comparison&&d.amount===null?(0,I.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`No `,Hr(i.result.comparison.label),` data to compare`]}):null,(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i.result.period.label})]})});function Wr(e,t){return e.metrics.length===0?null:X({metrics:e.metrics,groupBy:[e.groupRows,e.rows].filter(e=>!!e),period:e.period,compare:e.variant===`detail`?void 0:Y(e.compareWith),filters:fr(e.filters,t),sort:e.rows?{by:e.rows,direction:`asc`}:void 0,limit:e.limit??500})}function Gr({element:e,config:t,defaultTitle:n}){let r=W(t.dataset),i=br(t.dataset),o=(0,F.useMemo)(()=>Wr(t,i),[t,i]),s=Gn(t.dataset,o);if(!o)return(0,I.jsx)(nr,{component:e.type});let c=t.title??n;return(0,I.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[c?(0,I.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:c}):null,i&&r?(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Filtered to `,k(i.dimension,r.dimensions?.[i.dimension]).toLowerCase(),` `,i.value]}):null,s.status===`ok`?null:(0,I.jsx)(q,{state:s}),s.status===`ok`&&r?(0,I.jsx)(`div`,{className:a(s.refreshing&&`opacity-60`),children:(0,I.jsx)(Vr,{element:e,config:t,result:s.result,decl:r})}):null]})}var Kr=Z(j.FinancialTable.props,({element:e,props:t})=>{let n=(0,F.useMemo)(()=>({...t,metrics:pr(t),variant:t.variant??(t.metrics?`detail`:`comparison`)}),[t]);return(0,I.jsx)(Gr,{element:e,config:n})});function qr(e,t){return Z(e,({element:e,props:n})=>{let r=(0,F.useMemo)(()=>({...n,metrics:[n.metric],variant:`statement`}),[n]);return(0,I.jsx)(Gr,{element:e,config:r,defaultTitle:t})})}function Jr(e,t,n){let[r,i]=yn(e,t);return[r??n,i]}function Yr({label:e,children:t}){return(0,I.jsxs)(`label`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]})}var Xr=[`last-12-months`,`ytd`,`last-4-quarters`,`last-3-months`,`all`],Zr=Z(j.PeriodSelector.props,({props:e,bindings:t})=>{let n=e.options??[...Xr],[r,i]=Jr(e.value,t?.value,n[0]??`all`),a=n.includes(r)?n:[r,...n];return(0,I.jsx)(Yr,{label:e.label??`Period`,children:(0,I.jsxs)(v,{value:r,onValueChange:i,children:[(0,I.jsx)(f,{className:`h-9`,children:(0,I.jsx)(g,{})}),(0,I.jsx)(h,{children:a.map(e=>(0,I.jsx)(m,{value:e,children:be(e)},e))})]})})}),Qr=Z(j.CompareSelector.props,({props:e,bindings:t})=>{let{spec:n}=H(),r=(0,F.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]),i=[...ye.filter(e=>e.startsWith(`previous`)||r.has(e)),`none`],a=e.options??i,[o,s]=Jr(e.value,t?.value,a[0]??`none`);return(0,I.jsx)(Yr,{label:e.label??`Compare with`,children:(0,I.jsxs)(v,{value:o,onValueChange:s,children:[(0,I.jsx)(f,{className:`h-9`,children:(0,I.jsx)(g,{})}),(0,I.jsx)(h,{children:a.map(e=>(0,I.jsx)(m,{value:e,children:ue(e)},e))})]})})});function $r({props:e,bindings:t,defaultLabel:n}){let r=W(e.dataset),i=r?Object.keys(r.metrics)[0]:void 0,{dimension:a}=e,o=(0,F.useMemo)(()=>i?X({metrics:[i],groupBy:[a],sort:{by:a,direction:`asc`},limit:200}):null,[a,i]),s=Gn(e.dataset,o),c=s.status===`ok`?s.result.rows.map(e=>e.dimensions[a]??``):[],l=e.includeAll!==!1,u=l?`all`:c[0]??``,[d,p]=Jr(e.value,t?.value,u),_=e.label??n??k(a,r?.dimensions?.[a]);if(s.status!==`ok`)return(0,I.jsx)(Yr,{label:_,children:(0,I.jsx)(q,{state:s})});let y=[...l?[`all`]:[],...c];return(0,I.jsx)(Yr,{label:_,children:(0,I.jsxs)(v,{value:d||u,onValueChange:p,children:[(0,I.jsx)(f,{className:`h-9`,children:(0,I.jsx)(g,{})}),(0,I.jsx)(h,{children:y.map(e=>(0,I.jsx)(m,{value:e,children:e===`all`?`All`:e},e))})]})})}var ei=Z(j.CurrencySelector.props,({props:e,bindings:t})=>{let n=(0,F.useMemo)(()=>({...e,includeAll:!1}),[e]);return(0,I.jsx)($r,{props:n,bindings:t,defaultLabel:`Currency`})}),ti=Z(j.EntitySelector.props,({props:e,bindings:t})=>(0,I.jsx)($r,{props:e,bindings:t})),ni={sm:`gap-2`,md:`gap-3`,lg:`gap-5`},ri={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`},ii=Z(j.Stack.props,({props:e,children:t})=>{let n=e.direction===`horizontal`;return(0,I.jsx)(`div`,{className:a(`flex min-w-0`,n?`flex-row flex-wrap items-start`:`flex-col`,ni[e.gap??`md`]),children:t})}),ai=Z(j.Grid.props,({props:e,children:t})=>(0,I.jsx)(`div`,{className:a(`grid min-w-0`,ri[e.columns??2],ni[e.gap??`md`]),children:t})),oi=Z(j.Card.props,({props:e,children:t})=>(0,I.jsxs)(`section`,{className:`min-w-0 rounded-md border border-border p-3`,"aria-label":e.title,children:[e.title?(0,I.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:e.title}):null,e.description?(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e.description}):null,(0,I.jsx)(`div`,{className:a(`flex flex-col gap-3`,(e.title||e.description)&&`mt-3`),children:t})]})),si=Z(j.Section.props,({props:e,children:t})=>(0,I.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-3`,"aria-label":e.title,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h4`,{className:`text-sm font-medium text-foreground`,children:e.title}),e.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}):null]}),t]})),ci=Z(j.Tabs.props,({element:e,props:t,children:n,bindings:r})=>{let{items:i}=t,[a,o]=yn(t.value,r?.value),[s,c]=G(e,`tab`,i[0]?.value??``,Yn),l=r?.value?a??i[0]?.value??``:s,u=e=>{r?.value?o(e):c(e)},d=F.Children.toArray(n),f=Math.max(0,i.findIndex(e=>e.value===l));return(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,I.jsx)(T,{size:`sm`,value:i[f]?.value??``,onValueChange:u,options:i.map(e=>({value:e.value,label:e.label}))}),(0,I.jsx)(`div`,{role:`tabpanel`,children:d[f]??null})]})}),li={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`},ui=Z(j.Text.props,({props:e})=>(0,I.jsx)(`p`,{className:a(`whitespace-pre-wrap break-words`,li[e.variant??`body`]),children:e.text})),di=Z(j.Badge.props,({props:e})=>{let t=e.tone??`neutral`;return(0,I.jsxs)(`span`,{className:a(`inline-flex w-fit items-center gap-1 rounded-md border border-border px-1.5 py-0.5 text-xs font-medium`,K(t)),children:[(0,I.jsx)($n,{tone:t}),e.label]})}),fi={primary:`default`,secondary:`outline`,ghost:`ghost`};function pi(e){return e?(Array.isArray(e)?e:[e]).map(e=>e.action):[]}var mi=Z(j.Button.props,({element:e,props:t,emit:n})=>{let{loadingActions:r}=R(),i=pi(e.on?.press).some(e=>r.has(e));return(0,I.jsx)(s,{size:`sm`,variant:fi[t.variant??`secondary`],className:`w-fit`,pending:i,onClick:()=>n(`press`),children:t.label})});function hi(){return(0,I.jsx)(`hr`,{className:`border-border`})}function gi(e,t,n){let{execute:r}=R(),{viewKey:i}=H(),a=u(`genui.${e}`,i,n),o=l(a);return{run:(0,F.useCallback)(()=>{c(a,()=>r({action:e,params:t}))},[e,r,a,t]),pending:o}}function _i({path:e,line:t,label:n}){let{run:r,pending:i}=gi(`file.open`,t?{path:e,line:t}:{path:e},`${e}:${t??``}`);return(0,I.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})}var vi=Z(j.KeyValue.props,({props:e})=>(0,I.jsx)(`dl`,{className:a(`grid gap-x-6 gap-y-1.5`,e.columns===2?`grid-cols-1 @md:grid-cols-2`:`grid-cols-1`),children:e.items.map(e=>(0,I.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,2fr)] gap-3 text-sm`,children:[(0,I.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,I.jsx)(`dd`,{className:`break-words text-foreground tabular-nums`,children:e.value===null?`—`:String(e.value)})]},e.label))})),yi={added:{icon:ne,label:`Added`},modified:{icon:S,label:`Modified`},deleted:{icon:pt,label:`Deleted`},renamed:{icon:y,label:`Renamed`}},bi=Z(j.FileList.props,({props:e})=>(0,I.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.files.map(e=>{let t=e.status?yi[e.status]:null,n=t?.icon??y;return(0,I.jsxs)(`li`,{className:`flex items-start gap-2 px-3 py-2`,children:[(0,I.jsx)(n,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(_i,{path:e.path,label:e.path}),e.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.description}):null]}),t?(0,I.jsx)(`span`,{className:`mt-0.5 shrink-0 pl-2 text-xs text-muted-foreground`,children:t.label}):null]},e.path)})}));function xi(e,t,n){return t?n?`${e}:${t}:${n}`:`${e}:${t}`:e}var Si={error:`negative`,warning:`attention`,info:`info`},Ci={error:`Error`,warning:`Warning`,info:`Info`},wi=Z(j.DiagnosticList.props,({props:e})=>(0,I.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.items.map((e,t)=>{let n=Si[e.severity],r=e.path?xi(e.path,e.line,e.column):null;return(0,I.jsxs)(`li`,{className:`flex gap-2 px-3 py-2 text-sm`,children:[(0,I.jsxs)(`span`,{className:a(`mt-0.5 flex shrink-0 items-center gap-1 text-xs font-medium`,K(n)),children:[(0,I.jsx)($n,{tone:n}),Ci[e.severity]]}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`p`,{className:`break-words text-foreground`,children:e.message}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[e.path&&r?(0,I.jsx)(_i,{path:e.path,line:e.line,label:r}):null,e.source?(0,I.jsx)(`span`,{children:e.source}):null]})]})]},`${t}-${e.message}`)})}));function Ti({name:e,context:t}){let{run:n,pending:r}=gi(`agent.fix`,{subject:e,context:t},e);return(0,I.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,I.jsx)(ee,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Fix`]})}var Ei=Z(j.TestResult.props,({props:e})=>{let{passed:t,failed:n,skipped:r,durationMs:i,command:o,failures:s}=e,c=n>0?`negative`:`positive`;return(0,I.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-sm`,children:[(0,I.jsxs)(`span`,{className:a(`flex items-center gap-1 font-medium`,K(c)),children:[(0,I.jsx)($n,{tone:c}),n>0?`Failing`:`Passing`]}),(0,I.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[t,` passed`]}),(0,I.jsxs)(`span`,{className:`tabular-nums text-foreground`,children:[n,` failed`]}),r===void 0?null:(0,I.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[r,` skipped`]}),i===void 0?null:(0,I.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:De(i)})]}),o?(0,I.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,I.jsx)(`ul`,{className:`divide-y divide-border border-t border-border`,children:s.map(e=>(0,I.jsxs)(`li`,{className:`flex items-start gap-2 py-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`p`,{className:`break-words text-sm text-foreground`,children:e.name}),e.message?(0,I.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,I.jsx)(_i,{path:e.path,line:e.line,label:xi(e.path,e.line,void 0)}):null]}),(0,I.jsx)(Ti,{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]})}),Di=Z(j.Timeline.props,({props:e})=>(0,I.jsx)(`ol`,{className:`flex flex-col gap-3 border-l border-border pl-4`,children:e.items.map((e,t)=>(0,I.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.tone?(0,I.jsx)($n,{tone:e.tone,className:K(e.tone)}):null,(0,I.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e.title}),e.time?(0,I.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:e.time}):null]}),e.detail?(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.detail}):null]},`${t}-${e.title}`))}));function Oi(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 ki(e,t){let n=e??Object.keys(t[0]??{}).map(e=>({key:e,label:oe(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,Oi(e[t.key])]))}))}}function Ai(e,t,n,r){let i=r.comparison?.label;return{columns:[...t.map(t=>({key:`d:${t}`,label:k(t,e.dimensions?.[t]),numeric:!1})),...n.flatMap(t=>[{key:`m:${t}`,label:O(t,e.metrics[t]),numeric:!0},...i?[{key:`c:${t}`,label:`${O(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}`,M(r.values[t]??null,N(e.metrics[t]))],...i?[[`c:${t}`,M(r.compare?.[t]??null,N(e.metrics[t]))]]:[]])])}))}}function ji({element:e,columns:t,rows:n,title:r}){let{visibleRows:i,showAll:o}=cr(e,n);return(0,I.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,children:[r?(0,I.jsx)(`figcaption`,{className:`text-sm font-medium text-foreground`,children:r}):null,(0,I.jsxs)(`div`,{className:`max-h-[28rem] overflow-auto rounded-md border border-border`,children:[(0,I.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,I.jsx)(`thead`,{className:`sticky top-0 bg-card`,children:(0,I.jsx)(`tr`,{className:`border-b border-border`,children:t.map(e=>(0,I.jsx)(`th`,{scope:`col`,className:a(J,e.numeric?`text-right`:`text-left`),children:e.label},e.key))})}),(0,I.jsx)(`tbody`,{className:`divide-y divide-border`,children:i.map(e=>(0,I.jsx)(`tr`,{children:t.map(t=>(0,I.jsx)(`td`,{className:a(`px-3 py-1.5 text-foreground`,t.numeric?`text-right tabular-nums`:`text-left`),children:e.cells[t.key]},t.key))},e.key))})]}),o]})]})}var Mi=Z(j.DataTable.props,({element:e,props:t})=>{let n=W(t.dataset),r=br(t.dataset),i=(0,F.useMemo)(()=>!t.dataset||!t.metrics?null:X({metrics:t.metrics,groupBy:t.dimensions??[],period:t.period,compare:Y(t.compareWith),filters:fr(t.filters,r),limit:t.limit??200}),[r,t]),a=Gn(t.dataset,i);if(!t.dataset){let n=(t.rows??[]).filter(_e);return(0,I.jsx)(ji,{element:e,...ki(t.columns,n),title:t.title})}return t.metrics?a.status===`ok`?n?(0,I.jsx)(ji,{element:e,...Ai(n,t.dimensions??[],t.metrics,a.result),title:t.title}):(0,I.jsx)(nr,{component:`DataTable`}):(0,I.jsx)(q,{state:a}):(0,I.jsx)(nr,{component:`DataTable`})}),Ni={start:{icon:_,label:`Start`},end:{icon:xt,label:`End`},process:{icon:_t,label:`Step`},decision:{icon:dt,label:`Decision`},store:{icon:lt,label:`Store`},external:{icon:p,label:`External`}},Pi={neutral:`bg-muted-foreground`,positive:`bg-success`,negative:`bg-destructive`,attention:`bg-warning`,info:`bg-info`};function Fi({node:e,className:t}){let n=Ni[e.kind??`process`],r=n.icon;return(0,I.jsx)(r,{className:a(`h-3.5 w-3.5 shrink-0 text-muted-foreground`,t),"aria-label":n.label})}function Ii({node:e}){if(!e.status)return null;let t=e.tone??`neutral`;return(0,I.jsxs)(`span`,{className:a(`flex shrink-0 items-center gap-1 text-xs font-medium whitespace-nowrap tabular-nums`,K(t)),children:[(0,I.jsx)(`span`,{className:a(`h-1.5 w-1.5 rounded-full`,Pi[t]),"aria-hidden":`true`}),e.status]})}var Li={labelFont:`500 14px`,statusFont:`500 12px`,textFont:`12px`,paddingX:12,terminalPaddingX:16,contentChrome:26,statusChrome:24,rowHeight:16,baseHeight:38};function Ri(e){return e.kind===`start`||e.kind===`end`?Li.terminalPaddingX:Li.paddingX}function zi(e){return 2*Ri(e)+Li.contentChrome}function Bi(e){if(!e.path)return null;let t=we(e.path);return e.line?`${t}:${e.line}`:t}var Vi={sm:280,md:420,lg:600},Hi=720,Ui=14,Wi=132,Gi=300;function Ki(){return Ee.getCssVar(`--kanna-font-body`,`system-ui, sans-serif`)}function qi(){return Ee.getCssVar(`--kanna-font-mono`,`ui-monospace, monospace`)}function Ji(e,t,n){return Ee.measureTextWidth(e,t)??e.length*n}function Yi(e){let t=Li,n=Ki(),r=Ji(e.label,`${t.labelFont} ${n}`,7.6),i=e.status?Ji(e.status,`${t.statusFont} ${n}`,6.4)+t.statusChrome:0,a=e.description?Ji(e.description,`${t.textFont} ${n}`,6.2):0,o=Bi(e),s=o?Ji(o,`${t.textFont} ${qi()}`,7.2):0,c=Math.max(r+i,a,s);return{width:Math.round(Math.min(Gi,Math.max(Wi,c+zi(e)))),height:t.baseHeight+(e.description?t.rowHeight:0)+(e.path?t.rowHeight:0)}}function Xi(e){return`e${e}`}function Zi(e,t){let n=e=>({id:e.id,...Yi(e)}),r=new Set((e.groups??[]).map(e=>e.id)),i=e.edges.map((e,t)=>({id:Xi(t),sources:[e.from],targets:[e.to],...e.label?{labels:[{text:e.label,width:Ji(e.label,`${Li.textFont} ${Ki()}`,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=${Ui},bottom=${Ui},right=${Ui}]`},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 Qi(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});else{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(Xi(t))?.sections?.[0],r=c.get(Xi(t))?.labels?.[0];return{key:Xi(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 $i(t,n){let{default:r}=await D(async()=>{let{default:t}=await import(`./elk.bundled-ChRT-c4f.js`).then(t=>e(t.default,1));return{default:t}},__vite__mapDeps([47,1]));return Qi(t,n,await new r().layout(Zi(t,n)))}function ea(e,t){return e.width===0||e.height===0?1:Math.min(Hi/e.width,t/e.height)}async function ta(e){await Ee.whenFontsReady();let t=e.direction??`auto`;if(t!==`auto`)return await $i(e,t);let n=Vi[e.height??`md`],[r,i]=await Promise.all([$i(e,`LR`),$i(e,`TB`)]);return ea(r,n)>=ea(i,n)?r:i}var na=(0,F.lazy)(()=>D(()=>import(`./FlowSurface-CdVOTRYI.js`),__vite__mapDeps([48,1,2,11,3,14,7,4,5,6,8,10,12,13,15,16,17,18,19,20,9,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,49,50,51,52]))),ra=`genui-flow-layout`;function ia(e){return e===`diagram`||e===`outline`}function aa(e){return Pe({queryKey:[ra,Dt(JSON.stringify(e))],queryFn:async()=>await ta(e),staleTime:1/0,retry:!1})}function oa(e){let t=e.edges.filter(e=>St(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 sa({heading:e,links:t,direction:n}){return t.length===0?null:(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[(0,I.jsxs)(`span`,{children:[e,` `]}),t.map((e,t)=>(0,I.jsxs)(`span`,{children:[t>0?`, `:null,(0,I.jsx)(`span`,{className:`text-foreground`,children:e.node.label}),e.edge.label?(0,I.jsxs)(`span`,{children:[` (`,e.edge.label,`)`]}):null,St(e.edge)===`flow`?(0,I.jsx)(`span`,{className:`text-info-text`,children:` · live`}):null]},`${n}-${e.node.id}-${t}`))]})}function ca({entries:e,selectedId:t,onSelect:n}){return(0,I.jsx)(`ol`,{className:`divide-y divide-border rounded-md border border-border`,children:e.map((e,r)=>(0,I.jsxs)(`li`,{className:a(`flex gap-3 px-3 py-2`,e.node.id===t&&`bg-muted`),children:[(0,I.jsx)(`span`,{className:`w-5 shrink-0 pt-0.5 text-right text-xs text-muted-foreground tabular-nums`,children:r+1}),(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,I.jsx)(Fi,{node:e.node}),(0,I.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,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Ni[e.node.kind??`process`].label}),e.groupLabel?(0,I.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`in `,e.groupLabel]}):null,(0,I.jsx)(Ii,{node:e.node})]}),e.node.description?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.node.description}):null,(0,I.jsx)(sa,{heading:`From`,links:e.incoming,direction:`in`}),(0,I.jsx)(sa,{heading:`To`,links:e.outgoing,direction:`out`})]})]},e.node.id))})}function la({node:e}){let{run:t,pending:n}=gi(`file.open`,(0,F.useMemo)(()=>e.line?{path:e.path,line:e.line}:{path:e.path},[e.line,e.path]),`${e.id}:${e.path}`);return(0,I.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:n,onClick:t,children:[n?null:(0,I.jsx)(y,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Open file`]})}function ua({diagram:e,node:t}){let n=(0,F.useMemo)(()=>Et(e,t.id)??{},[e,t.id]),{run:r,pending:i}=gi(`agent.investigate`,(0,F.useMemo)(()=>({subject:t.label,context:n}),[n,t.label]),t.id);return(0,I.jsxs)(s,{size:`sm`,variant:`secondary`,className:`gap-1.5`,pending:i,onClick:r,children:[i?null:(0,I.jsx)(ht,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Ask agent`]})}function da(e){return e.path?e.line?`${e.path}:${e.line}`:e.path:null}function fa(e){return e.path!==void 0}function pa({diagram:e,entry:t,onClose:n}){let r=P(),{node:i}=t,a=da(i);return(0,I.jsxs)(`section`,{className:`flex flex-col gap-2 rounded-md border border-border p-3`,"aria-label":`Step ${i.label}`,children:[(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(Fi,{node:i,className:`mt-1`}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2`,children:[(0,I.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:i.label}),(0,I.jsx)(Ii,{node:i})]}),i.description?(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i.description}):null,a?(0,I.jsx)(`p`,{className:`font-mono text-xs break-all text-muted-foreground`,children:a}):null]}),(0,I.jsx)(s,{size:`icon-sm`,variant:`ghost`,onClick:n,"aria-label":`Close step details`,children:(0,I.jsx)(ie,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}),(0,I.jsx)(sa,{heading:`From`,links:t.incoming,direction:`in`}),(0,I.jsx)(sa,{heading:`To`,links:t.outgoing,direction:`out`}),r.readonly?null:(0,I.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[fa(i)?(0,I.jsx)(la,{node:i}):null,r.sendToAgent?(0,I.jsx)(ua,{diagram:e,node:i}):null]})]})}function ma({diagram:e,height:t,label:n,selectedId:r,onSelect:a}){let o=P(),s=aa(e),c=o.FlowRenderer??na;return s.error?(0,I.jsx)(ar,{label:`This diagram could not be laid out. The Outline view still lists every step.`,minHeight:t}):s.data?(0,I.jsx)(F.Suspense,{fallback:(0,I.jsx)(`div`,{className:`w-full rounded-md border border-border`,style:{height:t},"aria-hidden":`true`}),children:(0,I.jsx)(c,{layout:s.data,height:t,label:n,selectedId:r,onSelect:a})}):(0,I.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,I.jsx)(i,{}),` Laying out diagram…`]})}var ha={Stack:ii,Grid:ai,Card:oi,Section:si,Tabs:ci,Text:ui,Badge:di,Button:mi,Divider:hi,KeyValue:vi,DataTable:Mi,FileList:bi,DiagnosticList:wi,TestResult:Ei,Timeline:Di,FlowDiagram:Z(j.FlowDiagram.props,({element:e,props:t})=>{let n=(0,F.useMemo)(()=>wt(t),[t]),[r,i]=G(e,`view`,`diagram`,ia),[a,o]=G(e,`selected`,``,Yn),s=(0,F.useId)(),c=(0,F.useCallback)(e=>o(e??``),[o]),l=(0,F.useCallback)(e=>o(e===a?``:e),[a,o]),u=(0,F.useCallback)(()=>o(``),[o]),d=Vi[t.height??`md`],f=n.find(e=>e.node.id===a)??null,p=`Diagram${t.title?` of ${t.title}`:``}: ${oa(t)}. Switch to Outline to read it as a list.`;return(0,I.jsxs)(`figure`,{className:`flex min-w-0 flex-col gap-2`,"aria-labelledby":s,children:[(0,I.jsxs)(`figcaption`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{id:s,className:`text-sm font-medium text-foreground`,children:t.title??`Diagram`}),(0,I.jsx)(`div`,{className:`text-xs text-muted-foreground tabular-nums`,children:oa(t)})]}),(0,I.jsx)(T,{size:`sm`,value:r,onValueChange:i,options:[{value:`diagram`,label:`Diagram`},{value:`outline`,label:`Outline`}]})]}),r===`diagram`?(0,I.jsx)(ma,{diagram:t,height:d,label:p,selectedId:f?.node.id??null,onSelect:c}):(0,I.jsx)(ca,{entries:n,selectedId:f?.node.id??null,onSelect:l}),f?(0,I.jsx)(pa,{diagram:t,entry:f,onClose:u}):null]})}),FinancialMetric:Ur,FinancialChart:Mr,FinancialTable:Kr,IncomeStatement:qr(j.IncomeStatement.props,`Income statement`),BalanceSheet:qr(j.BalanceSheet.props,`Balance sheet`),CashFlowStatement:qr(j.CashFlowStatement.props,`Cash flow statement`),PeriodSelector:Zr,CompareSelector:Qr,CurrencySelector:ei,EntitySelector:ti};function ga({element:e}){return(0,I.jsx)(nr,{component:e.type})}var _a=64,$=new Map;function va(e,t){let n=$.get(e);if(n)return $.delete(e),$.set(e,n),n;let r=Ze({...t});for($.set(e,r);$.size>_a;){let e=$.keys().next().value;if(e===void 0)break;$.delete(e)}return r}function ya(e){return{root:e.root,elements:Object.fromEntries(Object.entries(e.elements).map(([e,t])=>[e,{type:t.type,props:{...t.props,[Kn]: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 ba({viewKey:e}){let t=P(),n=U.useScopedStore(e=>e.pendingAgentMessage),r=U.useScopedStore(e=>e.cancelAgentMessage),i=U.useScopedStore(e=>e.showNotice),a=u(`genui.agent.send`,e),o=l(a),d=t.sendToAgent,f=(0,F.useCallback)(()=>{n&&d&&c(a,async()=>{try{await d(n.message),r()}catch(e){throw i(e instanceof Error?e.message:`The message could not be sent`),e}})},[r,a,n,d,i]);return n?(0,I.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,I.jsxs)(`div`,{className:`flex items-start gap-2 text-sm`,children:[(0,I.jsx)(ht,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:`Send to the agent`}),(0,I.jsx)(`p`,{className:`break-words text-foreground`,children:n.headline}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The view's current numbers and data source go with it.`})]})]}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(s,{size:`sm`,pending:o,onClick:f,children:`Send`}),(0,I.jsx)(s,{size:`sm`,variant:`ghost`,onClick:r,disabled:o,children:`Cancel`})]})]}):null}function xa(){let e=U.useScopedStore(e=>e.notice),t=U.useScopedStore(e=>e.showNotice);return e?(0,I.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-destructive-text`,role:`alert`,children:[(0,I.jsx)(w,{className:`h-3.5 w-3.5 shrink-0`,"aria-hidden":`true`}),(0,I.jsx)(`span`,{className:`min-w-0 flex-1`,children:e}),(0,I.jsx)(`button`,{type:`button`,className:`rounded p-0.5 text-muted-foreground hover:text-foreground`,"aria-label":`Dismiss`,onClick:()=>t(null),children:(0,I.jsx)(ie,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})]}):null}function Sa(){let e=U.useScopedStore(e=>e.previewPath),t=U.useScopedStore(e=>e.previewProbe),n=U.useScopedStore(e=>e.setPreviewProbe),r=U.useScopedStore(e=>e.closePreview),i=U.useScopedStore(e=>e.showNotice);(0,F.useEffect)(()=>{if(!e)return;let t=new AbortController;return Te(`probe generated file link`,b(Ce(e),{signal:t.signal}).then(a=>{t.signal.aborted||(a.kind===`ready`?n(a):(r(),i(`"${we(e)}" could not be opened`)))})),()=>t.abort()},[r,e,n,i]);let a=(0,F.useMemo)(()=>{if(!e||t?.kind!==`ready`)return null;let n=Ce(e);return x({id:`genui-file-${n}`,kind:`file`,displayName:we(e),absolutePath:e,relativePath:e,contentUrl:n,mimeType:t.mimeType,size:t.size},`local_file_link`)},[e,t]),o=(0,F.useCallback)(e=>{e||r()},[r]);return(0,I.jsx)(te,{source:a,open:a!==null,onOpenChange:o})}function Ca({handlers:e}){let{registerHandler:t}=R();return(0,F.useEffect)(()=>{for(let[n,r]of Object.entries(e))t(n,r)},[e,t]),null}function wa({spec:e,viewKey:t}){let n=P(),r=U.useScopedStoreApi(),i=(0,F.useMemo)(()=>va(t,e.state??{}),[t,e.state]),a=(0,F.useMemo)(()=>Dn({host:()=>n,view:r,spec:e,state:i}),[n,r,e,i]),o=(0,F.useMemo)(()=>ya(e),[e]),s=(0,F.useMemo)(()=>({spec:e,viewKey:t}),[e,t]);return(0,I.jsx)(Vn,{value:s,children:(0,I.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,I.jsx)(`h3`,{className:`text-base font-medium text-foreground`,children:e.title}):null,(0,I.jsxs)(_n,{registry:ha,store:i,handlers:a,children:[(0,I.jsx)(Ca,{handlers:a}),(0,I.jsx)(gn,{spec:o,registry:ha,fallback:ga})]}),(0,I.jsx)(xa,{}),(0,I.jsx)(ba,{viewKey:t}),(0,I.jsx)(Sa,{})]})})}function Ta({spec:e,viewKey:t}){return(0,I.jsx)(U.Provider,{init:void 0,children:(0,I.jsx)(wa,{spec:e,viewKey:t})})}var Ea=t({GenUIFallback:()=>Oa,default:()=>Aa}),Da=8;function Oa({issues:e}){return(0,I.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,I.jsxs)(`p`,{className:`flex items-center gap-1.5 font-medium text-foreground`,children:[(0,I.jsx)(w,{className:`h-4 w-4 text-warning-text`,"aria-hidden":`true`}),`Unable to show this view`]}),(0,I.jsx)(`p`,{className:`text-muted-foreground`,children:`The agent described a view Kanna could not validate, so nothing from it was run.`}),(0,I.jsxs)(`details`,{className:`text-xs text-muted-foreground`,children:[(0,I.jsx)(`summary`,{className:`cursor-pointer select-none`,children:`Details`}),(0,I.jsxs)(`ul`,{className:`mt-1 list-disc space-y-0.5 pl-4 font-mono`,children:[e.slice(0,Da).map(e=>(0,I.jsxs)(`li`,{children:[e.path?`${e.path}: `:``,e.message]},`${e.path}:${e.message}`)),e.length>Da?(0,I.jsxs)(`li`,{children:[`…and `,e.length-Da,` more`]}):null]})]})]})}var ka=class extends F.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(e){E.warn(`[kanna/genui] view failed to render`,{message:e.message})}render(){return this.state.failed?(0,I.jsx)(Oa,{issues:[{path:``,message:`The view stopped rendering unexpectedly`}]}):this.props.children}};function Aa({source:e}){let t=P(),n=(0,F.useMemo)(()=>ze(e),[e]),r=(0,F.useMemo)(()=>`${t.chatId??`shared`}:${Dt(e)}`,[t.chatId,e]);return n.ok?(0,I.jsx)(ka,{children:(0,I.jsx)(Ta,{spec:n.spec,viewKey:r})}):(0,I.jsx)(Oa,{issues:n.issues})}export{Oa as GenUIFallback,Ri as a,Aa as default,Bi as i,Fi as n,zn as o,Ii as r,St as s,Ea as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{t}from"./jsx-runtime-BB9-612F.js";import{g as n,h as r}from"./useProviderCatalog-BlO4bNcc.js";import{t as i}from"./segmented-control--alEtfTe.js";import{t as a}from"./searchable-select-B47fAmOU.js";var o=e(t(),1),s=[`notify`,`inline`,`spawn`].map(e=>({value:e,label:n(e)}));function c(e){let t=`${e.idPrefix}-target`,n=`${e.idPrefix}-model`;return(0,o.jsxs)(o.Fragment,{children:[e.showModeControl?(0,o.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,o.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:`Action`}),(0,o.jsx)(i,{value:e.mode,onValueChange:e.onModeChange,options:s,size:`sm`}),(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(e.mode)})]}):null,(0,o.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,o.jsx)(`label`,{htmlFor:t,className:`block text-sm font-medium text-foreground`,children:e.mode===`spawn`?`Project`:`Chat`}),e.mode===`spawn`?(0,o.jsx)(a,{id:t,value:e.projectId,options:e.targets.projects,placeholder:`Choose a project`,searchPlaceholder:`Search projects...`,emptyMessage:`Nothing to choose from yet`,onValueChange:e.onProjectChange}):(0,o.jsx)(a,{id:t,value:e.chatId,options:e.targets.chats,placeholder:`Choose a chat`,searchPlaceholder:`Search chats...`,emptyMessage:`Nothing to choose from yet`,onValueChange:e.onChatChange}),e.targetNote]}),e.beforeModel,e.startsTurn?(0,o.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,o.jsx)(`label`,{htmlFor:n,className:`block text-sm font-medium text-foreground`,children:`Model`}),(0,o.jsx)(a,{id:n,value:e.modelValue,options:e.modelOptions,placeholder:`Choose a model`,searchPlaceholder:`Search models...`,onValueChange:e.onModelChange}),(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.modelHint})]}):null]})}export{c as t};
1
+ import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{t}from"./jsx-runtime-BB9-612F.js";import{g as n,h as r}from"./useProviderCatalog-CxmLsNAf.js";import{t as i}from"./segmented-control-BXlWFDM8.js";import{t as a}from"./searchable-select-ByMK5CZ8.js";var o=e(t(),1),s=[`notify`,`inline`,`spawn`].map(e=>({value:e,label:n(e)}));function c(e){let t=`${e.idPrefix}-target`,n=`${e.idPrefix}-model`;return(0,o.jsxs)(o.Fragment,{children:[e.showModeControl?(0,o.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,o.jsx)(`span`,{className:`block text-sm font-medium text-foreground`,children:`Action`}),(0,o.jsx)(i,{value:e.mode,onValueChange:e.onModeChange,options:s,size:`sm`}),(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(e.mode)})]}):null,(0,o.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,o.jsx)(`label`,{htmlFor:t,className:`block text-sm font-medium text-foreground`,children:e.mode===`spawn`?`Project`:`Chat`}),e.mode===`spawn`?(0,o.jsx)(a,{id:t,value:e.projectId,options:e.targets.projects,placeholder:`Choose a project`,searchPlaceholder:`Search projects...`,emptyMessage:`Nothing to choose from yet`,onValueChange:e.onProjectChange}):(0,o.jsx)(a,{id:t,value:e.chatId,options:e.targets.chats,placeholder:`Choose a chat`,searchPlaceholder:`Search chats...`,emptyMessage:`Nothing to choose from yet`,onValueChange:e.onChatChange}),e.targetNote]}),e.beforeModel,e.startsTurn?(0,o.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,o.jsx)(`label`,{htmlFor:n,className:`block text-sm font-medium text-foreground`,children:`Model`}),(0,o.jsx)(a,{id:n,value:e.modelValue,options:e.modelOptions,placeholder:`Choose a model`,searchPlaceholder:`Search models...`,onValueChange:e.onModelChange}),(0,o.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.modelHint})]}):null]})}export{c as t};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{t}from"./react-BWPDF9mI.js";import{l as n,n as r}from"./chunk-6KYCQHYJ-C0N1h4Su.js";import{t as i}from"./jsx-runtime-BB9-612F.js";import{f as a,l as o,n as s,r as c,t as l}from"./pendingActionsStore-Bks-EsV3.js";import{t as u}from"./arrow-left-CjtboDsu.js";import{n as d}from"./FilePreviewSheet-CfXThsQp.js";import{t as f}from"./segmented-control-BXlWFDM8.js";import{_ as p,u as m}from"./appSettingsStore-BkV1YU8S.js";import{c as h,g,h as _,r as v,y}from"./commandFeedback-C8JG7P5C.js";import{_ as b,a as x,c as S,d as C,f as w,g as T,h as E,i as D,l as O,m as k,n as A,o as j,p as M,r as N,s as P,t as ee,u as te}from"./inboxStore-CC3pAzZZ.js";import{_ as F,n as I,o as L}from"./state-mark-Hjx5ToFs.js";import{Bt as R,Ft as z,Gt as ne,Ht as B,It as V,Jt as H,Kt as U,Lt as W,Rt as G,Ut as K,Vt as q,Wt as J,Xt as re,Yt as Y,Zt as ie,hn as ae,pn as oe,qt as se,zt as ce}from"./index-R-jfstMQ.js";import{a as le,t as X}from"./searchable-select-ByMK5CZ8.js";var Z=e(t(),1),Q=e(i(),1);function ue({item:e,onOpen:t}){let n=(0,Z.useCallback)(()=>t(e),[t,e]),r=K(e);return(0,Q.jsxs)(`button`,{type:`button`,onClick:n,className:`grid w-full grid-cols-[minmax(0,1fr)_auto] gap-x-3 gap-y-0.5 px-4 py-2.5 text-left transition-colors duration-[var(--motion-quick)] hover:bg-muted/50 motion-reduce:transition-none`,children:[(0,Q.jsxs)(`span`,{className:a(`truncate text-sm text-foreground`,e.unread?`font-semibold`:`font-medium`),children:[e.unread?(0,Q.jsx)(`span`,{className:`sr-only`,children:`Unread. `}):null,e.title,(0,Q.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[` · `,B(e.source),` · `,U(e.subject)]})]}),(0,Q.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:L(e.ts)}),(0,Q.jsxs)(`span`,{className:`col-span-2 flex min-w-0 items-center gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(I,{tone:r.tone,label:r.label,className:`shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.preview})]})]})}var de=(0,Z.memo)(ue),$=`all`;function fe({label:e,active:t,onToggle:n}){return(0,Q.jsx)(`button`,{type:`button`,"aria-pressed":t,onClick:n,className:a(`rounded-md border px-2.5 py-1 text-xs transition-colors duration-[var(--motion-quick)] motion-reduce:transition-none`,t?`border-border bg-muted font-medium text-foreground`:`border-border/0 text-muted-foreground hover:text-foreground`),children:e})}function pe({filter:e,targets:t}){let n=C(e=>e.toggleAttentionOnly),r=C(e=>e.toggleSourceKind),i=C(e=>e.setProjectFilter),a=C(e=>e.setChatFilter),o=(0,Z.useCallback)(e=>i(e===$?null:e),[i]),s=(0,Z.useCallback)(e=>a(e===$?null:e),[a]),c=(0,Z.useMemo)(()=>[{value:$,label:`All projects`},...t.projects],[t.projects]),l=(0,Z.useMemo)(()=>[{value:$,label:`All chats`},...t.chats],[t.chats]);return(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,role:`group`,"aria-label":`Filter activity`,children:[(0,Q.jsx)(fe,{label:`Needs attention`,active:e.attentionOnly===!0,onToggle:n}),z.map(t=>(0,Q.jsx)(fe,{label:t.label,active:e.sourceKind===t.kind,onToggle:()=>r(t.kind)},t.kind)),(0,Q.jsx)(`div`,{className:`w-44`,children:(0,Q.jsx)(X,{value:e.projectId??$,options:c,placeholder:`All projects`,searchPlaceholder:`Search projects`,onValueChange:o})}),(0,Q.jsx)(`div`,{className:`w-52`,children:(0,Q.jsx)(X,{value:e.chatId??$,options:l,placeholder:`All chats`,searchPlaceholder:`Search chats`,onValueChange:s})})]})}function me({thread:e,outbound:t}){let n=y(),r=C(e=>e.retryConfirming[t.id]===!0),i=l(`inbox.retrySend`,t.id),a=c(i),u=J(t),d=T(e,t.id),f=d.kind===`needs_confirm`,p=e.id,m=(0,Z.useCallback)(e=>{s(i,async()=>{await v(n,{type:`inbox.retrySend`,threadId:p,outboundId:t.id,...e?{confirmDuplicate:!0}:{}}),C.getState().dismissRetryConfirm(t.id)})},[t.id,i,n,p]),h=(0,Z.useCallback)(()=>{f?C.getState().askRetryConfirm(t.id):m(!1)},[f,t.id,m]),g=(0,Z.useCallback)(()=>m(!0),[m]),_=(0,Z.useCallback)(()=>C.getState().dismissRetryConfirm(t.id),[t.id]);return(0,Q.jsxs)(`li`,{className:`py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,Q.jsxs)(`p`,{className:`min-w-0 whitespace-pre-wrap break-words text-sm text-foreground`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:`You`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:` · `}),t.text]}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-xs tabular-nums text-muted-foreground`,children:L(t.ts)})]}),(0,Q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Q.jsx)(I,{tone:u.tone,label:u.label,className:`min-w-0 break-words`}),d.kind!==`refused`&&!r?(0,Q.jsx)(o,{variant:`link`,size:`none`,className:`h-auto text-xs`,pending:a,onClick:h,children:`Retry`}):null]}),r?(0,Q.jsxs)(`div`,{role:`alert`,className:`mt-2 space-y-2 rounded-lg border border-border bg-muted px-3 py-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-foreground`,children:`The first attempt may already have been delivered. Sending again may deliver this message twice.`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(o,{size:`sm`,pending:a,onClick:g,children:`Send again`}),(0,Q.jsx)(o,{variant:`ghost`,size:`sm`,disabled:a,onClick:_,children:`Cancel`})]})]}):null]})}function he({threadId:e,draft:t,version:n,active:r}){let i=(0,Z.useCallback)(()=>{C.getState().loadDraftVersion(e,t)},[t,e]);return(0,Q.jsx)(o,{variant:r?`secondary`:`ghost`,size:`sm`,"aria-pressed":r,onClick:i,children:W(t,n)})}function ge({threadId:e,drafts:t,currentText:n}){return t.length===0?null:(0,Q.jsx)(`div`,{role:`group`,"aria-label":`Draft versions`,className:`flex flex-wrap gap-1.5`,children:t.map((e,t)=>({draft:e,version:t+1})).reverse().map(({draft:t,version:r})=>(0,Q.jsx)(he,{threadId:e,draft:t,version:r,active:t.text===n},t.id))})}function _e({prompt:e,disabled:t,onAsk:n}){let r=(0,Z.useCallback)(()=>n(e),[n,e]);return(0,Q.jsx)(o,{variant:`ghost`,size:`sm`,disabled:t,onClick:r,children:e.label})}function ve({disabled:e,onAsk:t}){return(0,Q.jsx)(`div`,{role:`group`,"aria-label":`Quick prompts`,className:`flex flex-wrap items-center gap-1.5`,children:ie.map(n=>(0,Q.jsx)(_e,{prompt:n,disabled:e,onAsk:t},n.id))})}var ye={direct:`Send`,agent:`Agent will send`,none:`Send`},be={direct:`Send this text to the sender through the source's reply tool`,agent:`Hand this text to the handler chat, which sends it to the sender`,none:V},xe=`Ask the agent to write a draft from this text; nothing is sent to the sender`,Se=`/`;function Ce(e){return(e.startsWith(Se)?e.slice(1):e).trim()}var we=229;function Te(e){return e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&e.nativeEvent.keyCode!==we}function Ee(e){return Te(e)&&(e.metaKey||e.ctrlKey)}function De(e){return Te(e)&&!e.metaKey&&!e.ctrlKey}function Oe({thread:e,onArchived:t}){let n=y(),r=C(t=>t.replyDrafts[e.id]),i=ee(r,e.drafts),a=e.drafts.at(-1)?.id,u=p(m),d=R(e,u),f=ce(e),h=f===null,x=e.chatId!==void 0,S=i.trim().length>0,w=d!==`none`&&S,T=l(`inbox.reply`,e.id),E=l(`inbox.instruct`,e.id),D=l(`inbox.archive`,e.id),O=c(T),k=c(E),A=c(D),j=(0,Z.useCallback)(t=>{C.getState().setReplyDraft(e.id,t.target.value)},[e.id]),M=(0,Z.useCallback)(()=>{s(T,async()=>{await v(n,{type:`inbox.reply`,threadId:e.id,text:i}),C.getState().settleReplyDraft(e.id,a)})},[i,a,T,n,e.id]),N=(0,Z.useCallback)((t,r)=>{s(E,async()=>{await v(n,{type:`inbox.instruct`,threadId:e.id,text:t,...r===void 0?{}:{draft:r}}),C.getState().settleReplyDraft(e.id,a)})},[E,a,n,e.id]),P=(0,Z.useCallback)(()=>{let e=Ce(i);h&&e.length>0&&N(e,void 0)},[N,h,i]),te=(0,Z.useCallback)(e=>{let t=i.trim();N(e.instruction,t.length>0?t:void 0)},[N,i]),F=(0,Z.useCallback)(e=>{Ee(e)?(e.preventDefault(),P()):De(e)&&(e.preventDefault(),h&&i.startsWith(Se)?P():w&&M())},[h,w,i,P,M]),I=(0,Z.useCallback)(()=>{C.getState().settleReplyDraft(e.id,a)},[a,e.id]),L=(0,Z.useCallback)(()=>{s(D,async()=>{await v(n,{type:`inbox.archive`,threadId:e.id}),t()})},[D,t,n,e.id]);return(0,Q.jsxs)(`section`,{"aria-label":`Reply`,className:`space-y-2`,children:[(0,Q.jsx)(ge,{threadId:e.id,drafts:e.drafts,currentText:i}),(0,Q.jsx)(_,{"aria-label":`Reply to the sender`,rows:5,maxLength:b,value:i,onChange:j,onKeyDown:F,placeholder:x?`Write a reply, or ask the agent (⌘↵, or start with /)`:`Write a reply`,disabled:d===`none`}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(g,{label:be[d],side:`top`,children:(0,Q.jsx)(`span`,{className:`inline-flex`,children:(0,Q.jsx)(o,{size:`sm`,disabled:!w,pending:O,onClick:M,children:ye[d]})})}),(0,Q.jsx)(g,{label:f??xe,side:`top`,children:(0,Q.jsx)(`span`,{className:`inline-flex`,children:(0,Q.jsx)(o,{variant:`secondary`,size:`sm`,disabled:!h||!S,pending:k,onClick:P,children:`Ask agent`})})}),(0,Q.jsx)(o,{variant:`ghost`,size:`sm`,disabled:i.length===0,onClick:I,children:`Discard draft`}),(0,Q.jsx)(o,{variant:`ghost`,size:`sm`,className:`ml-auto`,disabled:e.state===`archived`,pending:A,onClick:L,children:`Archive`})]}),(0,Q.jsx)(ve,{disabled:!h||k,onAsk:te}),d===`none`?(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:V}):null]})}function ke({thread:e}){if(q(e))return(0,Q.jsx)(I,{tone:`active`,label:`Agent is reading…`});if(e.report===void 0)return(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The agent has not read this yet.`});let t=re(e.report.verdict);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(I,{tone:t.tone,label:t.label}),(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap text-sm text-foreground`,children:ne(e.report.summary)})]})}function Ae({message:e}){let t=C(t=>t.rawOpen[e.id]===!0),n=(0,Z.useCallback)(()=>C.getState().toggleRaw(e.id),[e.id]);return(0,Q.jsxs)(`li`,{className:`py-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,Q.jsx)(`p`,{className:`min-w-0 whitespace-pre-wrap break-words text-sm text-foreground`,children:e.preview}),(0,Q.jsx)(`span`,{className:`shrink-0 font-mono text-xs tabular-nums text-muted-foreground`,children:L(e.ts)})]}),(0,Q.jsx)(o,{variant:`link`,size:`none`,className:`mt-1 h-auto text-xs`,"aria-expanded":t,onClick:n,children:t?`Hide raw`:`Show raw`}),t?(0,Q.jsx)(`div`,{className:`mt-2 min-w-0`,children:d(G(e.payload))}):null]})}function je({thread:e,onBack:t,onArchived:n}){let i=Y(e),a=se(e);return(0,Q.jsx)(`article`,{"aria-label":`Thread from ${e.sender}`,className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-[720px] space-y-6 px-4 py-6`,children:[(0,Q.jsxs)(`header`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(o,{variant:`ghost`,size:`sm`,className:`-ml-2 md:hidden`,onClick:t,children:[(0,Q.jsx)(u,{className:`mr-1 h-4 w-4`,"aria-hidden":`true`}),`Inbox`]}),(0,Q.jsx)(`h2`,{className:`truncate text-lg font-medium text-foreground`,children:e.sender}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{children:e.sourceName}),(0,Q.jsx)(`span`,{className:`font-mono tabular-nums`,children:new Date(e.lastMessageAt).toLocaleString()}),(0,Q.jsx)(I,{tone:i.tone,label:i.label}),e.chatId===void 0?null:(0,Q.jsxs)(r,{to:F(e.chatId),className:`inline-flex items-center gap-1 text-foreground underline-offset-4 hover:underline`,children:[`Open chat`,(0,Q.jsx)(ae,{className:`h-3 w-3`,"aria-hidden":`true`})]})]})]}),(0,Q.jsxs)(`section`,{"aria-label":`Agent's read`,className:`space-y-2`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Agent's read`}),(0,Q.jsx)(ke,{thread:e})]}),(0,Q.jsxs)(`section`,{"aria-label":`Messages`,className:`space-y-1`,children:[(0,Q.jsxs)(`h3`,{className:`text-sm font-semibold text-foreground`,children:[`Messages `,(0,Q.jsx)(`span`,{className:`font-normal tabular-nums text-muted-foreground`,children:e.messages.length})]}),(0,Q.jsx)(`ul`,{className:`divide-y divide-border`,children:a.map(t=>t.kind===`inbound`?(0,Q.jsx)(Ae,{message:t.message},t.message.id):(0,Q.jsx)(me,{thread:e,outbound:t.outbound},t.outbound.id))})]}),(0,Q.jsx)(Oe,{thread:e,onArchived:n})]})})}function Me({thread:e,selected:t,onOpen:n}){let r=(0,Z.useCallback)(()=>n(e.id),[n,e.id]),i=Y(e);return(0,Q.jsxs)(`button`,{type:`button`,onClick:r,"aria-current":t?`true`:void 0,className:a(`grid w-full grid-cols-[minmax(0,1fr)_auto] gap-x-3 gap-y-0.5 px-4 py-2.5 text-left transition-colors duration-[var(--motion-quick)] motion-reduce:transition-none`,t?`bg-muted`:`hover:bg-muted/50`),children:[(0,Q.jsxs)(`span`,{className:a(`truncate text-sm text-foreground`,e.unread?`font-semibold`:`font-medium`),children:[e.unread?(0,Q.jsx)(`span`,{className:`sr-only`,children:`Unread. `}):null,e.sender,(0,Q.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[` · `,e.sourceName]})]}),(0,Q.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:L(e.lastMessageAt)}),(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-xs text-muted-foreground`,children:[(0,Q.jsx)(I,{tone:i.tone,label:i.label,className:`shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:H(e)})]}),(0,Q.jsx)(`span`,{className:`font-mono text-xs tabular-nums text-muted-foreground`,children:e.messages.length>1?`${String(e.messages.length)} messages`:``})]})}var Ne=(0,Z.memo)(Me),Pe=[{value:`inbox`,label:`Inbox`},{value:`activity`,label:`Activity`}],Fe=l(`inbox.markAllRead`),Ie=l(`inbox.page`);function Le(){return(0,Q.jsxs)(`div`,{className:`px-4 py-10 text-sm text-muted-foreground`,children:[(0,Q.jsx)(`p`,{children:`Nothing needs you. Webhooks and MCP sources land here.`}),(0,Q.jsxs)(`p`,{className:`mt-3 flex flex-wrap gap-x-4 gap-y-1`,children:[(0,Q.jsx)(r,{to:`/webhooks`,className:`text-foreground underline-offset-4 hover:underline`,children:`Set up a webhook`}),(0,Q.jsx)(r,{to:`/settings/mcp-servers`,className:`text-foreground underline-offset-4 hover:underline`,children:`Connect an MCP source`})]})]})}function Re({tab:e}){return e===`inbox`?(0,Q.jsx)(Le,{}):(0,Q.jsx)(`p`,{className:`px-4 py-10 text-sm text-muted-foreground`,children:`No activity matches this view yet.`})}function ze({threadId:e}){let t=y(),r=n(),i=C(D),a=C(A),u=C(x),d=C(N),p=C(j),m=C(P),g=C(S),_=C(te),b=C(O),T=h(e=>e.sidebarData),ee=(0,Z.useMemo)(()=>le(T),[T]),I=c(Fe),L=c(Ie),R=i===`activity`?a:w,z=(0,Z.useMemo)(()=>E(i,u,d,R),[i,u,d,R]),ne=(0,Z.useMemo)(()=>M(z,_),[z,_]);(0,Z.useEffect)(()=>{C.getState().select(e)},[e]);let B=b?.id??null,V=b?.unread===!0;(0,Z.useEffect)(()=>{B!==null&&V&&s(l(`inbox.markRead`,B),async()=>{await v(t,{type:`inbox.markRead`,ids:[B]})})},[B,V,t]);let H=(0,Z.useCallback)(e=>C.getState().setTab(e),[]),U=(0,Z.useCallback)(e=>{r(`/inbox/${e}`)},[r]),W=(0,Z.useCallback)(()=>{r(`/inbox`)},[r]),G=(0,Z.useCallback)(e=>{e.unread&&s(l(`inbox.markRead`,e.id),async()=>{await v(t,{type:`inbox.markRead`,ids:[e.id]})}),e.chatId!==void 0&&r(F(e.chatId))},[r,t]),K=(0,Z.useCallback)(()=>{s(Fe,async()=>{await v(t,{type:`inbox.markAllRead`})})},[t]),q=(0,Z.useCallback)(()=>{s(Ie,async()=>{let e=C.getState(),n=k(e.threads,e.items,e.filter),[r,i]=await Promise.all([v(t,{type:`inbox.page`,beforeTs:n.threadBefore,limit:50,filter:e.filter}),v(t,{type:`inbox.page`,beforeTs:n.itemBefore,limit:50,filter:e.filter})]);C.getState().appendPage({threads:r.threads,items:i.items})})},[t]),J=i===`activity`&&!g&&u.length+d.length<p;return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,Q.jsxs)(`div`,{className:`space-y-3 border-b border-border px-4 pb-3 pt-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Q.jsxs)(`h1`,{className:`flex items-center gap-2.5 text-lg font-semibold text-foreground`,children:[(0,Q.jsx)(oe,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),`Inbox`,(0,Q.jsxs)(`span`,{className:`text-sm font-normal tabular-nums text-muted-foreground`,children:[m,` unread`]})]}),(0,Q.jsx)(o,{size:`sm`,variant:`secondary`,disabled:m===0,pending:I,onClick:K,children:`Mark all read`})]}),(0,Q.jsx)(f,{value:i,onValueChange:H,options:Pe,size:`sm`}),i===`activity`?(0,Q.jsx)(pe,{filter:a,targets:ee}):null]}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto md:max-w-[440px] md:flex-none md:basis-[420px] md:border-r md:border-border`,children:[z.length===0?(0,Q.jsx)(Re,{tab:i}):ne.map(e=>(0,Q.jsxs)(`section`,{"aria-label":e.label,children:[(0,Q.jsx)(`h2`,{className:`px-4 pb-1 pt-4 text-xs font-medium text-muted-foreground`,children:e.label}),e.records.map(e=>(0,Q.jsx)(Be,{record:e,selectedId:B,onOpenThread:U,onOpenItem:G},e.id))]},e.key)),J?(0,Q.jsx)(`div`,{className:`px-4 py-4`,children:(0,Q.jsx)(o,{variant:`secondary`,size:`sm`,pending:L,onClick:q,children:`Load older`})}):null]}),b===null?(0,Q.jsx)(`div`,{className:`hidden min-w-0 flex-1 items-center justify-center px-6 text-sm text-muted-foreground md:flex`,children:`Select a thread to read it.`}):(0,Q.jsx)(`div`,{className:`absolute inset-0 z-20 flex min-w-0 bg-background md:static md:z-auto md:flex-1`,children:(0,Q.jsx)(je,{thread:b,onBack:W,onArchived:W})})]})]})}function Be({record:e,selectedId:t,onOpenThread:n,onOpenItem:r}){return e.kind===`thread`?(0,Q.jsx)(Ne,{thread:e.thread,selected:e.id===t,onOpen:n}):(0,Q.jsx)(de,{item:e.item,onOpen:r})}export{ze as InboxPage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{t}from"./react-BWPDF9mI.js";import{u as n}from"./chunk-6KYCQHYJ-C0N1h4Su.js";import{t as r}from"./jsx-runtime-BB9-612F.js";import{f as i,l as a,m as o,n as s,r as c}from"./pendingActionsStore-C6o78Bki.js";import{a as l,o as u,r as d}from"./copyFeedbackStore-CNP3tyq0.js";import{n as f,t as p}from"./code-xml-DVVP_fVN.js";import{t as m}from"./monitor-Bd61vIbY.js";import{t as h}from"./plus-D5yDJAY3.js";import{t as g}from"./terminal-BLkQOd9o.js";import{i as _,n as v,o as y,r as b,t as x,u as S}from"./timer.adapter-DTTP0Zuq.js";import{a as C,c as w,o as T,t as E}from"./segmented-control--alEtfTe.js";import{c as D,f as O,o as k,s as ee,u as A}from"./log-CFGrfkV1.js";import{t as j}from"./input-DbE6EzUB.js";import{n as M}from"./pathUtils-DTWwEzHK.js";import{t as N}from"./runDetached-138oevj9.js";import{Nt as P,Pt as F,nn as I}from"./index-DUJdXxNz.js";import{b as L}from"./ChatPage-Dscf_7rF.js";var R=e(t(),1),te=3210,z=e(r(),1);function B({narrow:e=!1,title:t,subtitle:n,icon:r=m}){return(0,z.jsxs)(`div`,{className:i(`w-full`,e?`max-w-2xl px-6 pt-16 mx-auto`:`px-6 pt-16 mb-10`),children:[(0,z.jsxs)(`div`,{className:i(`flex items-center gap-1 mb-2`,e&&`justify-center`),children:[(0,z.jsx)(`div`,{className:`p-2 pl-0 rounded-lg`,children:(0,z.jsx)(r,{className:`h-6 w-6 text-muted-foreground`})}),(0,z.jsx)(`h1`,{className:`text-2xl font-semibold text-foreground`,children:t})]}),n&&(0,z.jsx)(`p`,{className:i(`text-muted-foreground`,e&&`mb-10 text-center`),children:n})]})}var V=O()(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:``})})),H=()=>V(e=>e.tab),U=()=>V(e=>e.name),W=()=>V(e=>e.existingPath);function G(e){return e.toLowerCase().replace(/[\s_]+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``)}function K({open:e,onOpenChange:t,onConfirm:n,ports:r={}}){let i=r.timer??x,o=H(),s=U(),c=W(),l=V(e=>e.setTab),u=V(e=>e.setName),d=V(e=>e.setExistingPath),f=V(e=>e.resetForOpen),p=(0,R.useRef)(null),m=(0,R.useRef)(null);(0,R.useEffect)(()=>{e&&(f(),i.setTimeout(()=>p.current?.focus(),0))},[e,f,i]),(0,R.useEffect)(()=>{e&&i.setTimeout(()=>{o===`new`?p.current?.focus():m.current?.focus()},0)},[o,e,i]);let h=G(s),g=h?`${D}/${h}`:``,C=c.trim(),w=o===`new`?!!h:!!C,T=()=>{if(w){if(o===`new`)n({mode:`new`,localPath:g,title:s.trim()});else{let e=M(C);n({mode:`existing`,localPath:C,title:e})}t(!1)}};return(0,z.jsx)(v,{open:e,onOpenChange:t,children:(0,z.jsxs)(_,{size:`sm`,children:[(0,z.jsxs)(b,{className:`space-y-4`,children:[(0,z.jsx)(S,{children:`Add Project`}),(0,z.jsx)(E,{value:o,onValueChange:l,options:[{value:`new`,label:`New Folder`},{value:`existing`,label:`Existing Path`}],className:`w-full mb-2`,optionClassName:`flex-1 justify-center`}),o===`new`?(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsx)(j,{ref:p,type:`text`,value:s,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&t(!1)},placeholder:`Project name`}),g&&(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground font-mono`,children:g})]}):(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsx)(j,{ref:m,type:`text`,value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&t(!1)},placeholder:`~/Projects/my-app`}),(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The folder will be created if it doesn't exist.`})]})]}),(0,z.jsxs)(y,{children:[(0,z.jsx)(a,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,z.jsx)(a,{variant:`secondary`,size:`sm`,onClick:T,disabled:!w,children:`Create`})]})]})})}function q({text:e}){let{copied:t,copy:n}=d();return(0,z.jsx)(a,{variant:`ghost`,size:`icon-mobile`,"aria-label":t?`Copied`:`Copy to clipboard`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>N(`copy command`,n(e)),children:t?(0,z.jsx)(u,{className:`h-4 w-4 text-success-text`}):(0,z.jsx)(l,{className:`h-4 w-4`})})}function J({children:e}){return(0,z.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,z.jsxs)(`pre`,{className:`inline-flex items-center gap-2 overflow-x-auto`,children:[(0,z.jsx)(f,{className:`inline h-4 w-4 opacity-40`}),(0,z.jsx)(`code`,{children:e})]}),(0,z.jsx)(q,{text:e})]})}function Y({children:e}){return(0,z.jsx)(`div`,{className:`bg-card border border-border rounded-2xl p-4`,children:e})}function X({children:e}){return(0,z.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,z.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5 min-w-0`,children:[(0,z.jsx)(e,{className:r||`h-5 w-5 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:t}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground leading-tight`,children:n})]})}function Q(){return(0,z.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,z.jsx)(`div`,{className:`flex gap-4`,children:(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr] items-baseline gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-center font-medium text-logo`,children:[e,`.`]}),(0,z.jsx)(`h3`,{className:`font-medium text-foreground mb-2`,children:t})]}),(0,z.jsx)(`div`,{className:`text-muted-foreground text-sm space-y-3`,children:n})]})})}function ne({localPath:e,starting:t,onOpenProject:n}){let r=c(F(e))||t;return(0,z.jsxs)(C,{children:[(0,z.jsx)(w,{asChild:!0,children:(0,z.jsxs)(`button`,{className:i(`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:()=>s(F(e),()=>n(e)),children:[(0,z.jsx)(L,{className:`h-4 w-4 text-muted-foreground flex-shrink-0`}),(0,z.jsx)(`span`,{className:`font-medium text-foreground truncate flex-1`,children:M(e)}),r?(0,z.jsx)(o,{className:`h-4 w-4 text-muted-foreground group-hover:text-primary animate-spin flex-shrink-0`}):(0,z.jsx)(I,{className:`h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`})]})}),(0,z.jsx)(T,{children:(0,z.jsx)(`p`,{children:e})})]})}function re({connectionStatus:e,ready:t,snapshot:n,startingLocalPath:r,commandError:i,newProjectOpen:l,onNewProjectOpenChange:u,onOpenProject:d,onCreateProject:f}){let _=(0,R.useMemo)(()=>n?.projects??[],[n?.projects]),v=e===`connecting`||!t,y=e===`connected`&&t,b=c(P);return(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 bg-background overflow-y-auto`,children:[y?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(B,{title:n?.machine.displayName??`Local Projects`,subtitle:`${k} is connected, choose a project below to get started.`}),(0,z.jsxs)(`div`,{className:`w-full px-6 mb-10`,children:[(0,z.jsxs)(`div`,{className:`flex items-baseline justify-between mb-3`,children:[(0,z.jsx)(`h2`,{className:`text-13 font-medium text-muted-foreground tracking-wider`,children:`Projects`}),(0,z.jsxs)(a,{variant:`default`,size:`sm`,pending:b,onClick:()=>u(!0),children:[b?null:(0,z.jsx)(h,{className:`h-4 w-4 mr-1.5`}),`Add Project`]})]}),_.length>0?(0,z.jsx)(`div`,{className:`grid gap-2 [grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr))]`,children:_.map(e=>(0,z.jsx)(ne,{localPath:e.localPath,starting:r===e.localPath,onOpenProject:d},e.localPath))}):(0,z.jsx)(Y,{children:(0,z.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.`})}),i?(0,z.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/20 bg-destructive/5 rounded-xl px-4 py-3 mt-4`,children:i}):null]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(B,{narrow:!0,icon:p,title:v?`Connecting ${k}`:`Connect ${k}`,subtitle:v?`${k} is starting up and loading your local projects.`:`Run ${k} directly on your machine with full access to your local files and agent project history.`}),(0,z.jsxs)(`div`,{className:`max-w-2xl w-full mx-auto pb-12 px-6`,children:[(0,z.jsx)(X,{children:`Status`}),(0,z.jsx)(`div`,{className:`mb-8`,children:(0,z.jsx)(Y,{children:(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(o,{className:`h-4 w-4 text-muted-foreground animate-spin`}),(0,z.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:v?`Connecting to your local ${k} server...`:(0,z.jsxs)(z.Fragment,{children:[`Not connected. Run `,(0,z.jsx)(`code`,{className:`bg-background border border-border rounded-md mx-0.5 p-1 font-mono text-xs text-foreground`,children:A()}),` from any terminal on this machine.`]})})]})})}),v?null:(0,z.jsxs)(`div`,{className:`mb-10`,children:[(0,z.jsx)(X,{children:`How it works`}),(0,z.jsx)(Y,{children:(0,z.jsxs)(`div`,{className:`flex items-start gap-4 py-2 px-2`,children:[(0,z.jsx)(Z,{icon:g,title:`${k} CLI`,subtitle:`On Your Machine`}),(0,z.jsx)(Q,{}),(0,z.jsx)(Z,{icon:m,title:`${k} Server`,subtitle:`Local WebSocket`}),(0,z.jsx)(Q,{}),(0,z.jsx)(Z,{icon:p,title:`${k} UI`,subtitle:`Project Chat`})]})})]}),v?null:(0,z.jsxs)(`div`,{className:`mb-10`,children:[(0,z.jsx)(X,{children:`Setup`}),(0,z.jsx)(Y,{children:(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)($,{number:1,title:`Start ${k}`,children:[(0,z.jsx)(`p`,{children:`Run this command in your terminal:`}),(0,z.jsx)(J,{children:A()})]}),(0,z.jsxs)($,{number:2,title:`Open the local UI`,children:[(0,z.jsxs)(`p`,{children:[k,` serves the app locally and opens the Local Projects page in an app-style browser window.`]}),(0,z.jsx)(J,{children:`http://localhost:${te}/local`})]}),(0,z.jsxs)(`div`,{className:`mt-8`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground tracking-wider mb-4`,children:`Notes`}),(0,z.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,z.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:A(``).trim()}),(0,z.jsx)(`span`,{className:`text-muted-foreground`,children:`Start in the current directory`})]}),(0,z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,z.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:A(`--no-open`)}),(0,z.jsx)(`span`,{className:`text-muted-foreground`,children:`Start the server without opening the browser`})]})]})]})]})})]})]})]}),(0,z.jsx)(K,{open:l,onOpenChange:u,onConfirm:e=>{s(P,()=>f(e))}}),(0,z.jsx)(`div`,{className:`py-4 text-center`,children:(0,z.jsxs)(`span`,{className:`text-xs text-muted-foreground/50`,children:[`v`,ee]})})]})}function ie(){let e=n();return(0,z.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0 relative`,children:(0,z.jsx)(re,{connectionStatus:e.connectionStatus,ready:e.localProjectsReady,snapshot:e.localProjects,startingLocalPath:e.startingLocalPath,commandError:e.commandError,newProjectOpen:e.addProjectModalOpen,onNewProjectOpenChange:t=>{t?e.openAddProjectModal():e.closeAddProjectModal()},onOpenProject:e.handleOpenLocalProject,onCreateProject:e.handleCreateProject})})}export{ie as LocalProjectsPage};
1
+ import{o as e}from"./rolldown-runtime-BCiCTKAo.js";import{t}from"./react-BWPDF9mI.js";import{u as n}from"./chunk-6KYCQHYJ-C0N1h4Su.js";import{t as r}from"./jsx-runtime-BB9-612F.js";import{f as i,l as a,m as o,n as s,r as c}from"./pendingActionsStore-Bks-EsV3.js";import{a as l,o as u,r as d}from"./copyFeedbackStore-DAsM7m9s.js";import{n as f,t as p}from"./code-xml-C3fKotSy.js";import{t as m}from"./monitor-CnCS7O8D.js";import{t as h}from"./plus-BmhG7IUi.js";import{t as g}from"./terminal-gOELI9ta.js";import{i as _,n as v,o as y,r as b,t as x,u as S}from"./timer.adapter-DgrMEqxC.js";import{a as C,c as w,o as T,t as E}from"./segmented-control-BXlWFDM8.js";import{c as D,f as O,o as k,s as ee,u as A}from"./log-DL1J6840.js";import{t as j}from"./input-B23WM9u5.js";import{n as M}from"./pathUtils-DTWwEzHK.js";import{t as N}from"./runDetached-BTPJqi-A.js";import{Nt as P,Pt as F,cn as I}from"./index-R-jfstMQ.js";import{b as L}from"./ChatPage-CGQoeYXf.js";var R=e(t(),1),te=3210,z=e(r(),1);function B({narrow:e=!1,title:t,subtitle:n,icon:r=m}){return(0,z.jsxs)(`div`,{className:i(`w-full`,e?`max-w-2xl px-6 pt-16 mx-auto`:`px-6 pt-16 mb-10`),children:[(0,z.jsxs)(`div`,{className:i(`flex items-center gap-1 mb-2`,e&&`justify-center`),children:[(0,z.jsx)(`div`,{className:`p-2 pl-0 rounded-lg`,children:(0,z.jsx)(r,{className:`h-6 w-6 text-muted-foreground`})}),(0,z.jsx)(`h1`,{className:`text-2xl font-semibold text-foreground`,children:t})]}),n&&(0,z.jsx)(`p`,{className:i(`text-muted-foreground`,e&&`mb-10 text-center`),children:n})]})}var V=O()(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:``})})),H=()=>V(e=>e.tab),U=()=>V(e=>e.name),W=()=>V(e=>e.existingPath);function G(e){return e.toLowerCase().replace(/[\s_]+/g,`-`).replace(/[^a-z0-9-]/g,``).replace(/-+/g,`-`).replace(/^-|-$/g,``)}function K({open:e,onOpenChange:t,onConfirm:n,ports:r={}}){let i=r.timer??x,o=H(),s=U(),c=W(),l=V(e=>e.setTab),u=V(e=>e.setName),d=V(e=>e.setExistingPath),f=V(e=>e.resetForOpen),p=(0,R.useRef)(null),m=(0,R.useRef)(null);(0,R.useEffect)(()=>{e&&(f(),i.setTimeout(()=>p.current?.focus(),0))},[e,f,i]),(0,R.useEffect)(()=>{e&&i.setTimeout(()=>{o===`new`?p.current?.focus():m.current?.focus()},0)},[o,e,i]);let h=G(s),g=h?`${D}/${h}`:``,C=c.trim(),w=o===`new`?!!h:!!C,T=()=>{if(w){if(o===`new`)n({mode:`new`,localPath:g,title:s.trim()});else{let e=M(C);n({mode:`existing`,localPath:C,title:e})}t(!1)}};return(0,z.jsx)(v,{open:e,onOpenChange:t,children:(0,z.jsxs)(_,{size:`sm`,children:[(0,z.jsxs)(b,{className:`space-y-4`,children:[(0,z.jsx)(S,{children:`Add Project`}),(0,z.jsx)(E,{value:o,onValueChange:l,options:[{value:`new`,label:`New Folder`},{value:`existing`,label:`Existing Path`}],className:`w-full mb-2`,optionClassName:`flex-1 justify-center`}),o===`new`?(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsx)(j,{ref:p,type:`text`,value:s,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&t(!1)},placeholder:`Project name`}),g&&(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground font-mono`,children:g})]}):(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsx)(j,{ref:m,type:`text`,value:c,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T(),e.key===`Escape`&&t(!1)},placeholder:`~/Projects/my-app`}),(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The folder will be created if it doesn't exist.`})]})]}),(0,z.jsxs)(y,{children:[(0,z.jsx)(a,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,z.jsx)(a,{variant:`secondary`,size:`sm`,onClick:T,disabled:!w,children:`Create`})]})]})})}function q({text:e}){let{copied:t,copy:n}=d();return(0,z.jsx)(a,{variant:`ghost`,size:`icon-mobile`,"aria-label":t?`Copied`:`Copy to clipboard`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>N(`copy command`,n(e)),children:t?(0,z.jsx)(u,{className:`h-4 w-4 text-success-text`}):(0,z.jsx)(l,{className:`h-4 w-4`})})}function J({children:e}){return(0,z.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,z.jsxs)(`pre`,{className:`inline-flex items-center gap-2 overflow-x-auto`,children:[(0,z.jsx)(f,{className:`inline h-4 w-4 opacity-40`}),(0,z.jsx)(`code`,{children:e})]}),(0,z.jsx)(q,{text:e})]})}function Y({children:e}){return(0,z.jsx)(`div`,{className:`bg-card border border-border rounded-2xl p-4`,children:e})}function X({children:e}){return(0,z.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,z.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5 min-w-0`,children:[(0,z.jsx)(e,{className:r||`h-5 w-5 text-muted-foreground`}),(0,z.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:t}),(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground leading-tight`,children:n})]})}function Q(){return(0,z.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,z.jsx)(`div`,{className:`flex gap-4`,children:(0,z.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-[auto_1fr] items-baseline gap-3`,children:[(0,z.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-center font-medium text-logo`,children:[e,`.`]}),(0,z.jsx)(`h3`,{className:`font-medium text-foreground mb-2`,children:t})]}),(0,z.jsx)(`div`,{className:`text-muted-foreground text-sm space-y-3`,children:n})]})})}function ne({localPath:e,starting:t,onOpenProject:n}){let r=c(F(e))||t;return(0,z.jsxs)(C,{children:[(0,z.jsx)(w,{asChild:!0,children:(0,z.jsxs)(`button`,{className:i(`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:()=>s(F(e),()=>n(e)),children:[(0,z.jsx)(L,{className:`h-4 w-4 text-muted-foreground flex-shrink-0`}),(0,z.jsx)(`span`,{className:`font-medium text-foreground truncate flex-1`,children:M(e)}),r?(0,z.jsx)(o,{className:`h-4 w-4 text-muted-foreground group-hover:text-primary animate-spin flex-shrink-0`}):(0,z.jsx)(I,{className:`h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`})]})}),(0,z.jsx)(T,{children:(0,z.jsx)(`p`,{children:e})})]})}function re({connectionStatus:e,ready:t,snapshot:n,startingLocalPath:r,commandError:i,newProjectOpen:l,onNewProjectOpenChange:u,onOpenProject:d,onCreateProject:f}){let _=(0,R.useMemo)(()=>n?.projects??[],[n?.projects]),v=e===`connecting`||!t,y=e===`connected`&&t,b=c(P);return(0,z.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 bg-background overflow-y-auto`,children:[y?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(B,{title:n?.machine.displayName??`Local Projects`,subtitle:`${k} is connected, choose a project below to get started.`}),(0,z.jsxs)(`div`,{className:`w-full px-6 mb-10`,children:[(0,z.jsxs)(`div`,{className:`flex items-baseline justify-between mb-3`,children:[(0,z.jsx)(`h2`,{className:`text-13 font-medium text-muted-foreground tracking-wider`,children:`Projects`}),(0,z.jsxs)(a,{variant:`default`,size:`sm`,pending:b,onClick:()=>u(!0),children:[b?null:(0,z.jsx)(h,{className:`h-4 w-4 mr-1.5`}),`Add Project`]})]}),_.length>0?(0,z.jsx)(`div`,{className:`grid gap-2 [grid-template-columns:repeat(auto-fill,minmax(min(260px,100%),1fr))]`,children:_.map(e=>(0,z.jsx)(ne,{localPath:e.localPath,starting:r===e.localPath,onOpenProject:d},e.localPath))}):(0,z.jsx)(Y,{children:(0,z.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.`})}),i?(0,z.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/20 bg-destructive/5 rounded-xl px-4 py-3 mt-4`,children:i}):null]})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(B,{narrow:!0,icon:p,title:v?`Connecting ${k}`:`Connect ${k}`,subtitle:v?`${k} is starting up and loading your local projects.`:`Run ${k} directly on your machine with full access to your local files and agent project history.`}),(0,z.jsxs)(`div`,{className:`max-w-2xl w-full mx-auto pb-12 px-6`,children:[(0,z.jsx)(X,{children:`Status`}),(0,z.jsx)(`div`,{className:`mb-8`,children:(0,z.jsx)(Y,{children:(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(o,{className:`h-4 w-4 text-muted-foreground animate-spin`}),(0,z.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:v?`Connecting to your local ${k} server...`:(0,z.jsxs)(z.Fragment,{children:[`Not connected. Run `,(0,z.jsx)(`code`,{className:`bg-background border border-border rounded-md mx-0.5 p-1 font-mono text-xs text-foreground`,children:A()}),` from any terminal on this machine.`]})})]})})}),v?null:(0,z.jsxs)(`div`,{className:`mb-10`,children:[(0,z.jsx)(X,{children:`How it works`}),(0,z.jsx)(Y,{children:(0,z.jsxs)(`div`,{className:`flex items-start gap-4 py-2 px-2`,children:[(0,z.jsx)(Z,{icon:g,title:`${k} CLI`,subtitle:`On Your Machine`}),(0,z.jsx)(Q,{}),(0,z.jsx)(Z,{icon:m,title:`${k} Server`,subtitle:`Local WebSocket`}),(0,z.jsx)(Q,{}),(0,z.jsx)(Z,{icon:p,title:`${k} UI`,subtitle:`Project Chat`})]})})]}),v?null:(0,z.jsxs)(`div`,{className:`mb-10`,children:[(0,z.jsx)(X,{children:`Setup`}),(0,z.jsx)(Y,{children:(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)($,{number:1,title:`Start ${k}`,children:[(0,z.jsx)(`p`,{children:`Run this command in your terminal:`}),(0,z.jsx)(J,{children:A()})]}),(0,z.jsxs)($,{number:2,title:`Open the local UI`,children:[(0,z.jsxs)(`p`,{children:[k,` serves the app locally and opens the Local Projects page in an app-style browser window.`]}),(0,z.jsx)(J,{children:`http://localhost:${te}/local`})]}),(0,z.jsxs)(`div`,{className:`mt-8`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground tracking-wider mb-4`,children:`Notes`}),(0,z.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,z.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:A(``).trim()}),(0,z.jsx)(`span`,{className:`text-muted-foreground`,children:`Start in the current directory`})]}),(0,z.jsxs)(`div`,{className:`flex gap-4`,children:[(0,z.jsx)(`code`,{className:`font-mono text-foreground whitespace-nowrap`,children:A(`--no-open`)}),(0,z.jsx)(`span`,{className:`text-muted-foreground`,children:`Start the server without opening the browser`})]})]})]})]})})]})]})]}),(0,z.jsx)(K,{open:l,onOpenChange:u,onConfirm:e=>{s(P,()=>f(e))}}),(0,z.jsx)(`div`,{className:`py-4 text-center`,children:(0,z.jsxs)(`span`,{className:`text-xs text-muted-foreground/50`,children:[`v`,ee]})})]})}function ie(){let e=n();return(0,z.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0 relative`,children:(0,z.jsx)(re,{connectionStatus:e.connectionStatus,ready:e.localProjectsReady,snapshot:e.localProjects,startingLocalPath:e.startingLocalPath,commandError:e.commandError,newProjectOpen:e.addProjectModalOpen,onNewProjectOpenChange:t=>{t?e.openAddProjectModal():e.closeAddProjectModal()},onOpenProject:e.handleOpenLocalProject,onCreateProject:e.handleCreateProject})})}export{ie as LocalProjectsPage};