@vertesia/ui 1.5.0-dev.20260725.083715Z → 1.5.0-dev.20260804.124748Z

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 (176) hide show
  1. package/lib/core/hooks/useScrollableSearch.d.ts +1 -1
  2. package/lib/core/hooks/useScrollableSearch.d.ts.map +1 -1
  3. package/lib/core/hooks/useScrollableSearch.js +15 -2
  4. package/lib/core/hooks/useScrollableSearch.js.map +1 -1
  5. package/lib/env/index.d.ts +4 -0
  6. package/lib/env/index.d.ts.map +1 -1
  7. package/lib/env/index.js.map +1 -1
  8. package/lib/features/agent/chat/AgentRequestInputOverlay.d.ts +1 -1
  9. package/lib/features/agent/chat/AgentRequestInputOverlay.d.ts.map +1 -1
  10. package/lib/features/agent/chat/AgentRequestInputOverlay.js +3 -8
  11. package/lib/features/agent/chat/AgentRequestInputOverlay.js.map +1 -1
  12. package/lib/features/agent/chat/ModernAgentConversation.d.ts +8 -1
  13. package/lib/features/agent/chat/ModernAgentConversation.d.ts.map +1 -1
  14. package/lib/features/agent/chat/ModernAgentConversation.js +53 -17
  15. package/lib/features/agent/chat/ModernAgentConversation.js.map +1 -1
  16. package/lib/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.d.ts +2 -1
  17. package/lib/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.d.ts.map +1 -1
  18. package/lib/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.js +25 -10
  19. package/lib/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.js.map +1 -1
  20. package/lib/features/agent/chat/ModernAgentOutput/AllMessagesMixed.d.ts.map +1 -1
  21. package/lib/features/agent/chat/ModernAgentOutput/AllMessagesMixed.js +24 -9
  22. package/lib/features/agent/chat/ModernAgentOutput/AllMessagesMixed.js.map +1 -1
  23. package/lib/features/agent/chat/ModernAgentOutput/AttachmentPreview.d.ts.map +1 -1
  24. package/lib/features/agent/chat/ModernAgentOutput/AttachmentPreview.js +15 -3
  25. package/lib/features/agent/chat/ModernAgentOutput/AttachmentPreview.js.map +1 -1
  26. package/lib/features/agent/chat/ModernAgentOutput/Header.js +2 -2
  27. package/lib/features/agent/chat/ModernAgentOutput/Header.js.map +1 -1
  28. package/lib/features/agent/chat/ModernAgentOutput/MessageInput.d.ts +2 -1
  29. package/lib/features/agent/chat/ModernAgentOutput/MessageInput.d.ts.map +1 -1
  30. package/lib/features/agent/chat/ModernAgentOutput/MessageInput.js +2 -2
  31. package/lib/features/agent/chat/ModernAgentOutput/MessageInput.js.map +1 -1
  32. package/lib/features/agent/chat/ModernAgentOutput/MessageItem.d.ts.map +1 -1
  33. package/lib/features/agent/chat/ModernAgentOutput/MessageItem.js +2 -2
  34. package/lib/features/agent/chat/ModernAgentOutput/MessageItem.js.map +1 -1
  35. package/lib/features/agent/chat/ModernAgentOutput/requestInputMessages.d.ts +9 -1
  36. package/lib/features/agent/chat/ModernAgentOutput/requestInputMessages.d.ts.map +1 -1
  37. package/lib/features/agent/chat/ModernAgentOutput/requestInputMessages.js +97 -2
  38. package/lib/features/agent/chat/ModernAgentOutput/requestInputMessages.js.map +1 -1
  39. package/lib/features/agent/chat/hooks/useAgentStream.d.ts.map +1 -1
  40. package/lib/features/agent/chat/hooks/useAgentStream.js +12 -3
  41. package/lib/features/agent/chat/hooks/useAgentStream.js.map +1 -1
  42. package/lib/features/agent/chat/index.d.ts +1 -1
  43. package/lib/features/agent/chat/index.d.ts.map +1 -1
  44. package/lib/features/agent/chat/index.js.map +1 -1
  45. package/lib/features/facets/PromptsFacetsNav.d.ts +8 -6
  46. package/lib/features/facets/PromptsFacetsNav.d.ts.map +1 -1
  47. package/lib/features/facets/PromptsFacetsNav.js +8 -3
  48. package/lib/features/facets/PromptsFacetsNav.js.map +1 -1
  49. package/lib/features/store/objects/components/ContentOverview.js +4 -1
  50. package/lib/features/store/objects/components/ContentOverview.js.map +1 -1
  51. package/lib/features/store/objects/components/useContentPanelHooks.d.ts +31 -3
  52. package/lib/features/store/objects/components/useContentPanelHooks.d.ts.map +1 -1
  53. package/lib/features/store/objects/search/DocumentSearchContext.d.ts +128 -6
  54. package/lib/features/store/objects/search/DocumentSearchContext.d.ts.map +1 -1
  55. package/lib/features/store/objects/selection/ObjectsActionContext.d.ts +2 -2
  56. package/lib/features/store/objects/selection/ObjectsActionContext.d.ts.map +1 -1
  57. package/lib/features/store/objects/selection/ObjectsActionSpec.d.ts +2 -2
  58. package/lib/features/store/objects/selection/ObjectsActionSpec.d.ts.map +1 -1
  59. package/lib/features/store/objects/selection/SelectionActions.d.ts +2 -2
  60. package/lib/features/store/objects/selection/SelectionActions.d.ts.map +1 -1
  61. package/lib/features/store/objects/upload/DocumentUploadModal.js.map +1 -1
  62. package/lib/features/store/types/IntakePolicyEditor.d.ts +2 -2
  63. package/lib/features/store/types/IntakePolicyEditor.d.ts.map +1 -1
  64. package/lib/features/store/types/IntakePolicyEditor.js +5 -1
  65. package/lib/features/store/types/IntakePolicyEditor.js.map +1 -1
  66. package/lib/features/store/types/IntakePolicyForm.d.ts.map +1 -1
  67. package/lib/features/store/types/IntakePolicyForm.js +2 -2
  68. package/lib/features/store/types/IntakePolicyForm.js.map +1 -1
  69. package/lib/features/store/types/ObjectSchemaEditor.d.ts +2 -2
  70. package/lib/features/store/types/ObjectSchemaEditor.d.ts.map +1 -1
  71. package/lib/features/store/types/SelectContentType.d.ts +2 -2
  72. package/lib/features/store/types/SelectContentType.d.ts.map +1 -1
  73. package/lib/features/store/types/SelectContentType.js.map +1 -1
  74. package/lib/features/store/types/SelectContentTypeModal.d.ts +2 -2
  75. package/lib/features/store/types/SelectContentTypeModal.d.ts.map +1 -1
  76. package/lib/features/store/types/SelectContentTypeModal.js.map +1 -1
  77. package/lib/features/store/types/TableLayoutEditor.d.ts +2 -2
  78. package/lib/features/store/types/TableLayoutEditor.d.ts.map +1 -1
  79. package/lib/features/store/types/TypeRegistry.d.ts +1267 -6
  80. package/lib/features/store/types/TypeRegistry.d.ts.map +1 -1
  81. package/lib/features/store/types/TypeRegistry.js +5 -0
  82. package/lib/features/store/types/TypeRegistry.js.map +1 -1
  83. package/lib/features/store/types/intake-policy-editor.logic.d.ts +9 -1
  84. package/lib/features/store/types/intake-policy-editor.logic.d.ts.map +1 -1
  85. package/lib/features/store/types/intake-policy-editor.logic.js +9 -1
  86. package/lib/features/store/types/intake-policy-editor.logic.js.map +1 -1
  87. package/lib/features/store/types/search/ObjectTypeSearchContext.d.ts +1251 -1
  88. package/lib/features/store/types/search/ObjectTypeSearchContext.d.ts.map +1 -1
  89. package/lib/features/store/types/typeCatalogCache.d.ts +2 -2
  90. package/lib/features/store/types/typeCatalogCache.d.ts.map +1 -1
  91. package/lib/features/store/types/typeCatalogCache.js +4 -0
  92. package/lib/features/store/types/typeCatalogCache.js.map +1 -1
  93. package/lib/features/user/UserInfo.d.ts +118 -7
  94. package/lib/features/user/UserInfo.d.ts.map +1 -1
  95. package/lib/i18n/locales/ar.json +2 -1
  96. package/lib/i18n/locales/de.json +2 -1
  97. package/lib/i18n/locales/en.json +5 -1
  98. package/lib/i18n/locales/es.json +2 -1
  99. package/lib/i18n/locales/fr.json +2 -1
  100. package/lib/i18n/locales/it.json +2 -1
  101. package/lib/i18n/locales/ja.json +2 -1
  102. package/lib/i18n/locales/ko.json +2 -1
  103. package/lib/i18n/locales/pt.json +2 -1
  104. package/lib/i18n/locales/ru.json +2 -1
  105. package/lib/i18n/locales/tr.json +2 -1
  106. package/lib/i18n/locales/zh-TW.json +2 -1
  107. package/lib/i18n/locales/zh.json +2 -1
  108. package/lib/session/UserSession.d.ts +18 -4
  109. package/lib/session/UserSession.d.ts.map +1 -1
  110. package/lib/shell/apps/AppInstallationProvider.d.ts +222 -2
  111. package/lib/shell/apps/AppInstallationProvider.d.ts.map +1 -1
  112. package/lib/shell/login/InviteAcceptModal.js.map +1 -1
  113. package/lib/vertesia-ui-core.js +1 -1
  114. package/lib/vertesia-ui-core.js.map +1 -1
  115. package/lib/vertesia-ui-features.js +34 -34
  116. package/lib/vertesia-ui-features.js.map +1 -1
  117. package/lib/vertesia-ui-i18n.js +13 -13
  118. package/lib/vertesia-ui-widgets.js +18 -18
  119. package/lib/vertesia-ui-widgets.js.map +1 -1
  120. package/lib/widgets/monacoEditor/MonacoEditor.d.ts +7 -1
  121. package/lib/widgets/monacoEditor/MonacoEditor.d.ts.map +1 -1
  122. package/lib/widgets/monacoEditor/MonacoEditor.js +62 -6
  123. package/lib/widgets/monacoEditor/MonacoEditor.js.map +1 -1
  124. package/package.json +31 -31
  125. package/src/core/hooks/useScrollableSearch.test.tsx +139 -0
  126. package/src/core/hooks/useScrollableSearch.tsx +17 -3
  127. package/src/env/index.ts +2 -0
  128. package/src/features/agent/chat/AgentChatPlaybackControls.test.tsx +2 -0
  129. package/src/features/agent/chat/AgentRequestInputOverlay.test.tsx +51 -6
  130. package/src/features/agent/chat/AgentRequestInputOverlay.tsx +5 -7
  131. package/src/features/agent/chat/ModernAgentConversation.test.tsx +195 -3
  132. package/src/features/agent/chat/ModernAgentConversation.tsx +106 -22
  133. package/src/features/agent/chat/ModernAgentOutput/ActiveWorkstreamsSummary.tsx +75 -20
  134. package/src/features/agent/chat/ModernAgentOutput/AllMessagesMixed.test.tsx +112 -0
  135. package/src/features/agent/chat/ModernAgentOutput/AllMessagesMixed.tsx +62 -10
  136. package/src/features/agent/chat/ModernAgentOutput/AttachmentPreview.tsx +36 -4
  137. package/src/features/agent/chat/ModernAgentOutput/Header.tsx +2 -2
  138. package/src/features/agent/chat/ModernAgentOutput/MessageInput.test.tsx +71 -0
  139. package/src/features/agent/chat/ModernAgentOutput/MessageInput.tsx +3 -1
  140. package/src/features/agent/chat/ModernAgentOutput/MessageItem.tsx +18 -4
  141. package/src/features/agent/chat/ModernAgentOutput/requestInputMessages.test.ts +95 -0
  142. package/src/features/agent/chat/ModernAgentOutput/requestInputMessages.ts +111 -1
  143. package/src/features/agent/chat/hooks/useAgentStream.test.tsx +57 -0
  144. package/src/features/agent/chat/hooks/useAgentStream.ts +12 -3
  145. package/src/features/agent/chat/index.ts +1 -0
  146. package/src/features/facets/PromptsFacetsNav.tsx +17 -9
  147. package/src/features/store/objects/components/ContentOverview.tsx +4 -1
  148. package/src/features/store/objects/selection/ObjectsActionContext.tsx +2 -2
  149. package/src/features/store/objects/selection/ObjectsActionSpec.ts +2 -2
  150. package/src/features/store/objects/selection/SelectionActions.tsx +2 -2
  151. package/src/features/store/objects/upload/DocumentUploadModal.tsx +2 -2
  152. package/src/features/store/types/IntakePolicyEditor.tsx +12 -4
  153. package/src/features/store/types/IntakePolicyForm.tsx +25 -0
  154. package/src/features/store/types/ObjectSchemaEditor.tsx +2 -2
  155. package/src/features/store/types/SelectContentType.tsx +9 -9
  156. package/src/features/store/types/SelectContentTypeModal.tsx +5 -5
  157. package/src/features/store/types/TableLayoutEditor.tsx +2 -2
  158. package/src/features/store/types/TypeRegistry.ts +8 -3
  159. package/src/features/store/types/intake-policy-editor.logic.ts +10 -2
  160. package/src/features/store/types/typeCatalogCache.ts +10 -3
  161. package/src/i18n/locales/ar.json +2 -1
  162. package/src/i18n/locales/de.json +2 -1
  163. package/src/i18n/locales/en.json +5 -1
  164. package/src/i18n/locales/es.json +2 -1
  165. package/src/i18n/locales/fr.json +2 -1
  166. package/src/i18n/locales/it.json +2 -1
  167. package/src/i18n/locales/ja.json +2 -1
  168. package/src/i18n/locales/ko.json +2 -1
  169. package/src/i18n/locales/pt.json +2 -1
  170. package/src/i18n/locales/ru.json +2 -1
  171. package/src/i18n/locales/tr.json +2 -1
  172. package/src/i18n/locales/zh-TW.json +2 -1
  173. package/src/i18n/locales/zh.json +2 -1
  174. package/src/shell/login/InviteAcceptModal.tsx +4 -4
  175. package/src/widgets/markdown/ArtifactEditingSurface.test.tsx +13 -9
  176. package/src/widgets/monacoEditor/MonacoEditor.tsx +83 -7
@@ -1,27 +1,27 @@
1
- import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import{Button as r,Center as i,DotBadge as a,DropdownMenu as o,DropdownMenuContent as s,DropdownMenuItem as c,DropdownMenuTrigger as l,FormItem as u,MessageBox as d,Modal as f,ModalBody as p,ModalFooter as m,ModalTitle as h,SelectBox as g,Spinner as _,Styles as v,Switch as y,Table as b,Textarea as x,VTooltip as S,cn as C,errorMessage as ee,useClickOutside as w,useFlag as T,useTheme as E,useToast as te}from"@vertesia/ui/core";import D,{clsx as O}from"clsx";import{AlertCircleIcon as k,AlignLeft as A,BarChart3 as j,Check as ne,CheckCircleIcon as M,ChevronDown as N,ChevronRight as re,Code as ie,Code2 as ae,Copy as oe,Download as se,FileText as ce,GitBranch as le,GitCommitHorizontal as ue,Heading2 as de,Image as P,Info as fe,Link as pe,List as me,Loader2 as he,Maximize2 as ge,MessageSquare as _e,Minimize2 as ve,Pencil as ye,Pilcrow as be,Plus as xe,Quote as F,Send as I,SquarePen as L,Table as R,Table2 as z,Trash2 as Se,UploadIcon as Ce,X as we,XCircleIcon as Te}from"lucide-react";import B,{Suspense as Ee,createContext as V,lazy as De,memo as Oe,useCallback as H,useContext as U,useEffect as W,useId as ke,useMemo as G,useRef as K,useState as q}from"react";import Ae from"ajv";import je from"ajv-formats";import{useUITranslation as J}from"@vertesia/ui/i18n";import{Editor as Me}from"@monaco-editor/react";import Ne from"debounce";import{FusionFragmentHandler as Pe,FusionFragmentProvider as Fe}from"@vertesia/fusion-ux";import Ie from"dompurify";import*as Le from"@radix-ui/react-dialog";import{useUserSession as Re}from"@vertesia/ui/session";import ze from"papaparse";import{VegaEmbed as Be}from"react-vega";import{twMerge as Ve}from"tailwind-merge";import He,{defaultUrlTransform as Ue}from"react-markdown";import We from"rehype-katex";import{defListHastHandlers as Ge,remarkDefinitionList as Ke}from"remark-definition-list";import qe from"remark-directive";import Je from"remark-gfm";import Ye from"remark-github-blockquote-alert";import Xe from"remark-math";import Ze from"remark-supersub";import{SKIP as Qe,visit as $e}from"unist-util-visit";import et from"mermaid";import{XMLParser as tt}from"fast-xml-parser";import{isNil as nt,omit as rt}from"lodash-es";const it=V(void 0),at=it.Provider;function ot(){let e=U(it);if(!e)throw Error(`useFieldSet must be used within a Form or FieldSet element`);return e}var st=class{object;components;disabled;constructor(e,t={},n=!1){this.object=e,this.components=t,this.disabled=n}};const ct=V(void 0);function lt(){let e=U(ct);if(!e)throw Error(`useForm must be used within a Form element`);return e}const ut=ct.Provider,dt=B.forwardRef(({object:e,type:n=`text`,onChange:r,...i},a)=>{let[o,s]=q(e.value==null?``:String(e.value)),[c,l]=q(e.schema.isBoolean&&e.value===!0);i.className?i.className=D(v.INPUT,i.className):i.className=v.INPUT;let u=t=>{i.disabled||(s(t.target.value),e.schema.isBoolean?(e.value=t.target.checked,l(e.value)):e.value=t.target.value,r?.(t))};return n===`textarea`?t(`textarea`,{ref:a,...i,value:o,onChange:u}):n===`checkbox`?t(`input`,{ref:a,...i,type:`checkbox`,checked:c,onChange:u,className:`form-check-input`}):t(`input`,{ref:a,...i,type:n,value:o,onChange:u})});function ft({object:e,components:n,onSubmit:r,children:i,onChange:a,disabled:o}){return e.observer=a,t(ut,{value:new st(e,n||{},o??!1),children:t(`form`,{className:`w-full`,onSubmit:t=>{t.stopPropagation(),t.preventDefault(),r?.(e.value)},children:i})})}function pt(){return t(`div`,{className:`flex flex-col gap-4 w-full`,children:lt().object.properties.map(ht)})}function mt({children:e,...r}){return n(ft,{...r,children:[t(pt,{}),e]})}function ht(e){return e.isList?t(yt,{object:e},e.name):e.isObject?t(vt,{object:e},e.name):t(_t,{object:e},e.name)}function gt(e,n){return e.isList?t(yt,{object:e}):e.isObject?t(vt,{object:e}):t(_t,{object:e,editor:n})}function _t({object:e,editor:n,inline:r=!1}){n||=e.schema.editor;let{components:i,disabled:a}=lt(),o=n&&i[n]||dt,s=e.getInputType();s===`checkbox`&&(r=!0);let c=t=>{a||(e.schema.isBoolean?e.value=t.target instanceof HTMLInputElement&&t.target.checked:e.schema.isNumber?e.value=parseFloat(t.target.value):e.value=t.target.value)};return e.isListItem?t(o,{object:e,type:s,onChange:c,disabled:a}):t(u,{label:e.title,required:e.schema.isRequired,description:e.schema.description,className:D(`flex`,r?`flex-row items-center`:`flex-col`),children:t(o,{object:e,type:s,onChange:c,disabled:a})})}function vt({object:e}){return n(`div`,{className:`flex flex-col gap-4 my-4 py-2 ps-4 border-s-4 border-s-solid border-s-slate-100 dark:border-s-slate-600`,children:[!e.isListItem&&t(`div`,{className:`text-gray-900 dark:text-gray-200 font-semibold`,children:e.title}),e.properties.map(ht)]})}function yt({object:e}){let{disabled:i}=lt(),a=K((e.value??[]).length),[o,s]=q(()=>(e.value??[]).map((e,t)=>t)),c=()=>{i||(e.add(),s(e=>[...e,a.current++]))},l=t=>{i||(e.remove(t),s(e=>e.filter((e,n)=>n!==t)))};return n(`div`,{className:`flex flex-col gap-4 my-4 py-2 ps-4 border-s-4 border-s-solid border-s-slate-100 darK:border-s-slate-600`,children:[!e.isListItem&&t(`div`,{className:`text-gray-900 dark:text-gray-200 font-semibold`,children:e.title}),e.items.map((n,r)=>{let a=o[r];return t(bt,{object:n,list:e,onDelete:()=>l(r),disabled:i},a)}),t(`div`,{children:n(r,{variant:`outline`,onClick:c,disabled:i,children:[t(xe,{className:`size-6`}),` Add`]})})]})}function bt({list:e,object:i,onDelete:a,disabled:o}){return n(`div`,{className:`flex gap-2 w-full`,children:[t(`div`,{className:`flex-1`,children:gt(i,typeof e.schema.arraySchema.editor==`string`?e.schema.arraySchema.editor:void 0)}),t(r,{variant:`ghost`,onClick:a,disabled:o,title:`Delete`,children:t(Se,{className:`size-4 text-destructive`})})]})}function xt({label:e,required:n,children:r}){return t(u,{label:e,required:n,children:r})}function St({children:e}){return t(`p`,{className:`mt-2 text-sm text-gray-500`,children:e})}function Ct({children:e}){return t(`p`,{className:`mt-2 text-sm text-red-600`,children:e})}function wt(e){return e===`object`?{type:`object`,properties:{}}:e===`array`?{type:`array`,items:{}}:{type:e}}var Tt=class{schema;properties={};_validator;constructor(e){this.schema=e||{type:`object`,properties:{}},this.load()}get validator(){if(!this._validator){let e=new Ae({allErrors:!0,strict:!1});je(e),this._validator=e.compile(this.schema)}return this._validator}load(){if(this.schema.properties){let e=this.schema.properties;Object.keys(e).forEach(t=>{this.loadProperty(t,e[t])})}}hasProperties(){return Object.keys(this.properties).length>0}get title(){let e=this.schema.title;if(typeof e==`string`)return e;let t=this.schema.name;return typeof t==`string`?t:void 0}get description(){return this.schema.description}loadProperty(e,t){let n;return n=t.type===`array`?new Ot(this,e,t):new Et(this,e,t),this.properties[e]=n,n}get type(){return this.schema.type}validate(e){return this.validator(e)?null:this.validator.errors||[]}addProperty(e,t,n=!1){this.schema.type!==`object`&&(this.schema.type=`object`),this.schema.properties||(this.schema.properties={});let r=typeof t==`string`?wt(t):t,i=this.loadProperty(e,r);return this.schema.properties[i.name]=i.schema,n&&(i.isRequired=!0),i}removeProperty(e){this.schema.properties&&(delete this.schema.properties[e],Array.isArray(this.schema.required)&&(this.schema.required=this.schema.required.filter(t=>t!==e))),delete this.properties[e]}getProperty(e){return this.properties[e]}get editor(){return typeof this.schema.editor==`string`?this.schema.editor:void 0}},Et=class extends Tt{parent;name;constructor(e,t,n){if(super(n),this.parent=e,this.name=t,n.type===`array`)throw Error(`Array property must be instantiated using ArrayPropertySchema`);n.type===`object`&&!n.properties&&(n.properties={})}get isMulti(){return!1}get isReadOnly(){return!!this.schema.readOnly}set isReadOnly(e){this.schema.readOnly=e}get defaultValue(){return this.schema.default}set defaultValue(e){this.schema.default=e}get enum(){return this.schema.enum}set enum(e){this.schema.enum=e}get isRequired(){let e=this.parent.schema.required;return e?e.includes(this.name):!1}set isRequired(e){let t=Array.isArray(this.parent.schema.required)?this.parent.schema.required:[];t=e?t.concat(this.name):t.filter(e=>e!==this.name),this.parent.schema.required=t}get type(){return this.schema.type}set type(e){this.schema.type!==e&&(this.schema.type=e,e!==`object`&&(this.properties={},this.schema.properties=void 0))}remove(){this.parent.removeProperty(this.name)}get isBoolean(){return this.type===`boolean`}get isString(){return this.type===`string`}get isNumber(){return this.type===`number`||this.type===`integer`}get isObject(){return this.type===`object`}};function Dt(e){if(e.type!==`array`)throw Error(`Expecting an array schema`);if(!e.items)e.items={};else if(Array.isArray(e.items))throw Error(`Tuple arrays are not supported`);return e.items}var Ot=class extends Et{arraySchema;constructor(e,t,n){super(e,t,Dt(n)),this.arraySchema=n}get isMulti(){return!0}};function kt(e){return e=e.replace(/_/g,` `).replace(/([a-z0-9])&([A-Z])/g,`$1 $2`),e[0].toUpperCase()+e.slice(1)}function At(e,t){if(t.editor)return t.editor;if(t.schema.format)return t.schema.format;switch(t.type){case`number`:case`integer`:return`number`;case`boolean`:return`checkbox`;case`string`:return`text`;default:return`text`}}var jt=class{parent;schema;name;observer;constructor(e,t,n){this.parent=e,this.schema=t,this.name=n}get isRoot(){return!this.parent}get root(){return this.parent?this.parent.root:this}get path(){return this.parent?this.parent.path.concat(this.name):[]}get isScalar(){return!1}get isListItem(){return!1}get isObject(){return!1}get isList(){return!1}get title(){return this.schema.title||kt(this.name)}onChange(e){this.observer&&this.observer(this)===!1||this.parent?.onChange(e)}},Mt=class extends jt{get isObject(){return!0}getProperty(e){let t=this.schema.properties[e];return t.isMulti?new It(this,t,this.getOrInitArrayProperty(e)):t.isObject?new Pt(this,t,t.name,this.getOrInitObjectProperty(e)):new Ft(this,t)}getOrInitObjectProperty(e){let t=this.value[e];return t||(this.value[e]=t={}),t}getOrInitArrayProperty(e){let t=this.value[e];return t||(this.value[e]=t=[]),t}setPropertyValue(e,t){return this.value[e]===t?!1:(this.value[e]=t,!0)}getPropertyValue(e){return this.value[e]}get properties(){let e=[];for(let t of Object.values(this.schema.properties))t.isMulti?e.push(new It(this,t,this.getOrInitArrayProperty(t.name))):t.isObject?e.push(new Pt(this,t,t.name,this.getOrInitObjectProperty(t.name))):e.push(new Ft(this,t));return e}[Symbol.iterator](){return this.properties[Symbol.iterator]()}},Nt=class extends Mt{value;constructor(e,t={}){super(null,e instanceof Tt?e:new Tt(e),`#root`),this.value=t}},Pt=class extends Mt{value;constructor(e,t,n,r){super(e,t,n),this.value=r}},Ft=class extends jt{constructor(e,t){super(e,t,t.name),e.value[this.name]===void 0&&t.defaultValue!==void 0&&(e.value[this.name]=t.defaultValue)}get isScalar(){return!0}set value(e){this.parent.setPropertyValue(this.name,e)&&this.onChange(this)}get value(){return this.parent.getPropertyValue(this.name)}getInputType(){return At(this.name,this.schema)}},It=class extends jt{value;items=[];constructor(e,t,n){super(e,t,t.name),this.value=n;for(let e of this.value)this.add()}get isList(){return!0}newItem(e){return this.schema.isObject?new Lt(this,e):new Rt(this,e)}add(){let e=this.newItem(this.items.length);return this.items.push(e),e}remove(e){let t=this.value;if(e>=0&&e<this.items.length){this.items.splice(e,1);for(let e=0,t=this.items.length;e<t;e++){let t=this.items[e];t.index=e,t.name=String(e)}}Array.isArray(t)&&e>=0&&e<t.length&&(t.splice(e,1),this.onChange(this))}[Symbol.iterator](){return this.items[Symbol.iterator]()}item(e){if(e<0||e>=this.value.length)return;let t=this.value[e];return this.schema.isObject?new Pt(this,this.schema,String(e),t):new Rt(this,e)}trim(){for(;this.items[this.items.length-1]===void 0;)this.items.pop()}},Lt=class extends Mt{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,e.value[t]===void 0&&(e.value[t]={}),this.key=`${this.name}@${Date.now()}`}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}},Rt=class extends jt{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,e.value[t]===void 0&&e.schema.defaultValue!==void 0&&(e.value[t]=e.schema.defaultValue),this.key=`${this.name}@${Date.now()}`}get isScalar(){return!0}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}getInputType(){return At(this.name,this.schema)}};function zt({data:e,className:r}){let i=G(()=>{try{return JSON.stringify(e,null,2)}catch(e){return console.error(`Failed to stringify JSON:`,e),`{}`}},[e]),a=G(()=>i.split(`
1
+ import{Fragment as e,jsx as t,jsxs as n}from"react/jsx-runtime";import{Button as r,Center as i,DotBadge as a,DropdownMenu as o,DropdownMenuContent as s,DropdownMenuItem as c,DropdownMenuTrigger as l,FormItem as u,MessageBox as d,Modal as f,ModalBody as p,ModalFooter as m,ModalTitle as h,SelectBox as g,Spinner as _,Styles as v,Switch as y,Table as ee,Textarea as b,VTooltip as x,cn as S,errorMessage as te,useClickOutside as C,useFlag as w,useTheme as T,useToast as E}from"@vertesia/ui/core";import D,{clsx as O}from"clsx";import{AlertCircleIcon as k,AlignLeft as A,BarChart3 as j,Check as ne,CheckCircleIcon as M,ChevronDown as N,ChevronRight as re,Code as ie,Code2 as ae,Copy as oe,Download as se,FileText as ce,GitBranch as le,GitCommitHorizontal as ue,Heading2 as de,Image as P,Info as fe,Link as pe,List as me,Loader2 as he,Maximize2 as ge,MessageSquare as _e,Minimize2 as ve,Pencil as ye,Pilcrow as be,Plus as xe,Quote as F,Send as I,SquarePen as L,Table as R,Table2 as z,Trash2 as Se,UploadIcon as Ce,X as we,XCircleIcon as Te}from"lucide-react";import B,{Suspense as Ee,createContext as V,lazy as De,memo as Oe,useCallback as H,useContext as U,useEffect as W,useId as ke,useMemo as G,useRef as K,useState as q}from"react";import Ae from"ajv";import je from"ajv-formats";import{useUITranslation as J}from"@vertesia/ui/i18n";import{Editor as Me}from"@monaco-editor/react";import Ne from"debounce";import{FusionFragmentHandler as Pe,FusionFragmentProvider as Fe}from"@vertesia/fusion-ux";import Ie from"dompurify";import*as Le from"@radix-ui/react-dialog";import{useUserSession as Re}from"@vertesia/ui/session";import ze from"papaparse";import{VegaEmbed as Be}from"react-vega";import{twMerge as Ve}from"tailwind-merge";import He,{defaultUrlTransform as Ue}from"react-markdown";import We from"rehype-katex";import{defListHastHandlers as Ge,remarkDefinitionList as Ke}from"remark-definition-list";import qe from"remark-directive";import Je from"remark-gfm";import Ye from"remark-github-blockquote-alert";import Xe from"remark-math";import Ze from"remark-supersub";import{SKIP as Qe,visit as $e}from"unist-util-visit";import et from"mermaid";import{XMLParser as tt}from"fast-xml-parser";import{isNil as nt,omit as rt}from"lodash-es";const it=V(void 0),at=it.Provider;function ot(){let e=U(it);if(!e)throw Error(`useFieldSet must be used within a Form or FieldSet element`);return e}var st=class{object;components;disabled;constructor(e,t={},n=!1){this.object=e,this.components=t,this.disabled=n}};const ct=V(void 0);function lt(){let e=U(ct);if(!e)throw Error(`useForm must be used within a Form element`);return e}const ut=ct.Provider,dt=B.forwardRef(({object:e,type:n=`text`,onChange:r,...i},a)=>{let[o,s]=q(e.value==null?``:String(e.value)),[c,l]=q(e.schema.isBoolean&&e.value===!0);i.className?i.className=D(v.INPUT,i.className):i.className=v.INPUT;let u=t=>{i.disabled||(s(t.target.value),e.schema.isBoolean?(e.value=t.target.checked,l(e.value)):e.value=t.target.value,r?.(t))};return n===`textarea`?t(`textarea`,{ref:a,...i,value:o,onChange:u}):n===`checkbox`?t(`input`,{ref:a,...i,type:`checkbox`,checked:c,onChange:u,className:`form-check-input`}):t(`input`,{ref:a,...i,type:n,value:o,onChange:u})});function ft({object:e,components:n,onSubmit:r,children:i,onChange:a,disabled:o}){return e.observer=a,t(ut,{value:new st(e,n||{},o??!1),children:t(`form`,{className:`w-full`,onSubmit:t=>{t.stopPropagation(),t.preventDefault(),r?.(e.value)},children:i})})}function pt(){return t(`div`,{className:`flex flex-col gap-4 w-full`,children:lt().object.properties.map(ht)})}function mt({children:e,...r}){return n(ft,{...r,children:[t(pt,{}),e]})}function ht(e){return e.isList?t(yt,{object:e},e.name):e.isObject?t(vt,{object:e},e.name):t(_t,{object:e},e.name)}function gt(e,n){return e.isList?t(yt,{object:e}):e.isObject?t(vt,{object:e}):t(_t,{object:e,editor:n})}function _t({object:e,editor:n,inline:r=!1}){n||=e.schema.editor;let{components:i,disabled:a}=lt(),o=n&&i[n]||dt,s=e.getInputType();s===`checkbox`&&(r=!0);let c=t=>{a||(e.schema.isBoolean?e.value=t.target instanceof HTMLInputElement&&t.target.checked:e.schema.isNumber?e.value=parseFloat(t.target.value):e.value=t.target.value)};return e.isListItem?t(o,{object:e,type:s,onChange:c,disabled:a}):t(u,{label:e.title,required:e.schema.isRequired,description:e.schema.description,className:D(`flex`,r?`flex-row items-center`:`flex-col`),children:t(o,{object:e,type:s,onChange:c,disabled:a})})}function vt({object:e}){return n(`div`,{className:`flex flex-col gap-4 my-4 py-2 ps-4 border-s-4 border-s-solid border-s-slate-100 dark:border-s-slate-600`,children:[!e.isListItem&&t(`div`,{className:`text-gray-900 dark:text-gray-200 font-semibold`,children:e.title}),e.properties.map(ht)]})}function yt({object:e}){let{disabled:i}=lt(),a=K((e.value??[]).length),[o,s]=q(()=>(e.value??[]).map((e,t)=>t)),c=()=>{i||(e.add(),s(e=>[...e,a.current++]))},l=t=>{i||(e.remove(t),s(e=>e.filter((e,n)=>n!==t)))};return n(`div`,{className:`flex flex-col gap-4 my-4 py-2 ps-4 border-s-4 border-s-solid border-s-slate-100 darK:border-s-slate-600`,children:[!e.isListItem&&t(`div`,{className:`text-gray-900 dark:text-gray-200 font-semibold`,children:e.title}),e.items.map((n,r)=>{let a=o[r];return t(bt,{object:n,list:e,onDelete:()=>l(r),disabled:i},a)}),t(`div`,{children:n(r,{variant:`outline`,onClick:c,disabled:i,children:[t(xe,{className:`size-6`}),` Add`]})})]})}function bt({list:e,object:i,onDelete:a,disabled:o}){return n(`div`,{className:`flex gap-2 w-full`,children:[t(`div`,{className:`flex-1`,children:gt(i,typeof e.schema.arraySchema.editor==`string`?e.schema.arraySchema.editor:void 0)}),t(r,{variant:`ghost`,onClick:a,disabled:o,title:`Delete`,children:t(Se,{className:`size-4 text-destructive`})})]})}function xt({label:e,required:n,children:r}){return t(u,{label:e,required:n,children:r})}function St({children:e}){return t(`p`,{className:`mt-2 text-sm text-gray-500`,children:e})}function Ct({children:e}){return t(`p`,{className:`mt-2 text-sm text-red-600`,children:e})}function wt(e){return e===`object`?{type:`object`,properties:{}}:e===`array`?{type:`array`,items:{}}:{type:e}}var Tt=class{schema;properties={};_validator;constructor(e){this.schema=e||{type:`object`,properties:{}},this.load()}get validator(){if(!this._validator){let e=new Ae({allErrors:!0,strict:!1});je(e),this._validator=e.compile(this.schema)}return this._validator}load(){if(this.schema.properties){let e=this.schema.properties;Object.keys(e).forEach(t=>{this.loadProperty(t,e[t])})}}hasProperties(){return Object.keys(this.properties).length>0}get title(){let e=this.schema.title;if(typeof e==`string`)return e;let t=this.schema.name;return typeof t==`string`?t:void 0}get description(){return this.schema.description}loadProperty(e,t){let n;return n=t.type===`array`?new Ot(this,e,t):new Et(this,e,t),this.properties[e]=n,n}get type(){return this.schema.type}validate(e){return this.validator(e)?null:this.validator.errors||[]}addProperty(e,t,n=!1){this.schema.type!==`object`&&(this.schema.type=`object`),this.schema.properties||(this.schema.properties={});let r=typeof t==`string`?wt(t):t,i=this.loadProperty(e,r);return this.schema.properties[i.name]=i.schema,n&&(i.isRequired=!0),i}removeProperty(e){this.schema.properties&&(delete this.schema.properties[e],Array.isArray(this.schema.required)&&(this.schema.required=this.schema.required.filter(t=>t!==e))),delete this.properties[e]}getProperty(e){return this.properties[e]}get editor(){return typeof this.schema.editor==`string`?this.schema.editor:void 0}},Et=class extends Tt{parent;name;constructor(e,t,n){if(super(n),this.parent=e,this.name=t,n.type===`array`)throw Error(`Array property must be instantiated using ArrayPropertySchema`);n.type===`object`&&!n.properties&&(n.properties={})}get isMulti(){return!1}get isReadOnly(){return!!this.schema.readOnly}set isReadOnly(e){this.schema.readOnly=e}get defaultValue(){return this.schema.default}set defaultValue(e){this.schema.default=e}get enum(){return this.schema.enum}set enum(e){this.schema.enum=e}get isRequired(){let e=this.parent.schema.required;return e?e.includes(this.name):!1}set isRequired(e){let t=Array.isArray(this.parent.schema.required)?this.parent.schema.required:[];t=e?t.concat(this.name):t.filter(e=>e!==this.name),this.parent.schema.required=t}get type(){return this.schema.type}set type(e){this.schema.type!==e&&(this.schema.type=e,e!==`object`&&(this.properties={},this.schema.properties=void 0))}remove(){this.parent.removeProperty(this.name)}get isBoolean(){return this.type===`boolean`}get isString(){return this.type===`string`}get isNumber(){return this.type===`number`||this.type===`integer`}get isObject(){return this.type===`object`}};function Dt(e){if(e.type!==`array`)throw Error(`Expecting an array schema`);if(!e.items)e.items={};else if(Array.isArray(e.items))throw Error(`Tuple arrays are not supported`);return e.items}var Ot=class extends Et{arraySchema;constructor(e,t,n){super(e,t,Dt(n)),this.arraySchema=n}get isMulti(){return!0}};function kt(e){return e=e.replace(/_/g,` `).replace(/([a-z0-9])&([A-Z])/g,`$1 $2`),e[0].toUpperCase()+e.slice(1)}function At(e,t){if(t.editor)return t.editor;if(t.schema.format)return t.schema.format;switch(t.type){case`number`:case`integer`:return`number`;case`boolean`:return`checkbox`;case`string`:return`text`;default:return`text`}}var jt=class{parent;schema;name;observer;constructor(e,t,n){this.parent=e,this.schema=t,this.name=n}get isRoot(){return!this.parent}get root(){return this.parent?this.parent.root:this}get path(){return this.parent?this.parent.path.concat(this.name):[]}get isScalar(){return!1}get isListItem(){return!1}get isObject(){return!1}get isList(){return!1}get title(){return this.schema.title||kt(this.name)}onChange(e){this.observer&&this.observer(this)===!1||this.parent?.onChange(e)}},Mt=class extends jt{get isObject(){return!0}getProperty(e){let t=this.schema.properties[e];return t.isMulti?new It(this,t,this.getOrInitArrayProperty(e)):t.isObject?new Pt(this,t,t.name,this.getOrInitObjectProperty(e)):new Ft(this,t)}getOrInitObjectProperty(e){let t=this.value[e];return t||(this.value[e]=t={}),t}getOrInitArrayProperty(e){let t=this.value[e];return t||(this.value[e]=t=[]),t}setPropertyValue(e,t){return this.value[e]===t?!1:(this.value[e]=t,!0)}getPropertyValue(e){return this.value[e]}get properties(){let e=[];for(let t of Object.values(this.schema.properties))t.isMulti?e.push(new It(this,t,this.getOrInitArrayProperty(t.name))):t.isObject?e.push(new Pt(this,t,t.name,this.getOrInitObjectProperty(t.name))):e.push(new Ft(this,t));return e}[Symbol.iterator](){return this.properties[Symbol.iterator]()}},Nt=class extends Mt{value;constructor(e,t={}){super(null,e instanceof Tt?e:new Tt(e),`#root`),this.value=t}},Pt=class extends Mt{value;constructor(e,t,n,r){super(e,t,n),this.value=r}},Ft=class extends jt{constructor(e,t){super(e,t,t.name),e.value[this.name]===void 0&&t.defaultValue!==void 0&&(e.value[this.name]=t.defaultValue)}get isScalar(){return!0}set value(e){this.parent.setPropertyValue(this.name,e)&&this.onChange(this)}get value(){return this.parent.getPropertyValue(this.name)}getInputType(){return At(this.name,this.schema)}},It=class extends jt{value;items=[];constructor(e,t,n){super(e,t,t.name),this.value=n;for(let e of this.value)this.add()}get isList(){return!0}newItem(e){return this.schema.isObject?new Lt(this,e):new Rt(this,e)}add(){let e=this.newItem(this.items.length);return this.items.push(e),e}remove(e){let t=this.value;if(e>=0&&e<this.items.length){this.items.splice(e,1);for(let e=0,t=this.items.length;e<t;e++){let t=this.items[e];t.index=e,t.name=String(e)}}Array.isArray(t)&&e>=0&&e<t.length&&(t.splice(e,1),this.onChange(this))}[Symbol.iterator](){return this.items[Symbol.iterator]()}item(e){if(e<0||e>=this.value.length)return;let t=this.value[e];return this.schema.isObject?new Pt(this,this.schema,String(e),t):new Rt(this,e)}trim(){for(;this.items[this.items.length-1]===void 0;)this.items.pop()}},Lt=class extends Mt{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,e.value[t]===void 0&&(e.value[t]={}),this.key=`${this.name}@${Date.now()}`}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}},Rt=class extends jt{index;key;constructor(e,t){super(e,e.schema,String(t)),this.index=t,e.value[t]===void 0&&e.schema.defaultValue!==void 0&&(e.value[t]=e.schema.defaultValue),this.key=`${this.name}@${Date.now()}`}get isScalar(){return!0}get isListItem(){return!0}set value(e){this.parent.value[this.index]=e}get value(){return this.parent.value[this.index]}getInputType(){return At(this.name,this.schema)}};function zt({data:e,className:r}){let i=G(()=>{try{return JSON.stringify(e,null,2)}catch(e){return console.error(`Failed to stringify JSON:`,e),`{}`}},[e]),a=G(()=>i.split(`
2
2
  `),[i]);return t(`pre`,{className:`h-full overflow-auto rounded-md border bg-background p-3 font-mono text-xs leading-5 text-foreground ${r||``}`,children:t(`code`,{children:a.map((e,t)=>n(`span`,{children:[Ht(e),t<a.length-1?`
3
3
  `:null]},`line-${t}`))})})}const Bt=/("(?:\\.|[^"\\])*"?)|\b(true|false|null)\b|(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g,Vt=/^\s*:/;function Ht(e){Bt.lastIndex=0;let n=[],r=0,i=Bt.exec(e);for(;i!==null;){i.index>r&&n.push(e.slice(r,i.index));let[a,o,s,c]=i,l=o!==void 0&&Vt.test(e.slice(i.index+a.length))?`text-info`:o?`text-success`:s?`text-primary`:c?`text-attention`:void 0;n.push(t(`span`,{className:l,children:a},`${i.index}-${a}`)),r=i.index+a.length,i=Bt.exec(e)}return r<e.length&&n.push(e.slice(r)),n.length?n:e}function Ut({value:e}){return Array.isArray(e)?t(`div`,{className:`flex flex-col gap-4 px-2 h-full overflow-auto`,children:t(qt,{value:e})}):typeof e!=`object`||!e?t(`div`,{className:`flex flex-col gap-4 px-2 h-full overflow-auto`,children:t(Kt,{name:`value`,value:e})}):t(`div`,{className:`flex flex-col gap-4 px-2 h-full overflow-auto`,children:Object.entries(e).map(([e,n])=>t(Kt,{name:e,value:n},e))})}function Wt({name:e}){return t(`div`,{className:`text-sm font-semibold`,children:kt(e)})}function Gt({children:e,className:n}){return t(`div`,{className:D(`flex flex-col gap-4 py-2 ps-4 border-s-4 border-s-solid border-s-slate-100 dark:border-s-slate-600`,n),children:e})}function Kt({name:e,value:r}){let i=Yt(r);switch(i.type){case Y.Inline:return n(`div`,{className:`w-full flex gap-2 text-sm`,children:[t(Wt,{name:`${e}:`}),t(`p`,{children:i.value})]});case Y.Paragraph:return n(`div`,{className:`w-full flex flex-col gap-2 text-sm`,children:[t(Wt,{name:e}),t(`p`,{children:i.value})]});case Y.Prose:return n(`div`,{className:`prose dark:prose-invert`,children:[t(Wt,{name:e}),t(`div`,{className:`vprose prose-sm dark:prose-invert`,children:i.value})]});case Y.Array:return t(qt,{name:e,value:r});case Y.Object:return n(`div`,{className:`w-full flex flex-col gap-2 text-sm`,children:[t(Wt,{name:e}),t(Gt,{className:`mt-2`,children:Object.entries(r).map(([e,n])=>t(Kt,{name:e,value:n},e))})]})}}function qt({name:e,value:r}){let i=r.join(` `).length,o=i/r.length,s=typeof r[0]==`string`&&(i<80||i<400&&o<32),c=r.length>9,l=r.map((e,t)=>({item:e,index:t,key:`${t}-${JSON.stringify(e)}`}));return s?n(`div`,{className:`flex gap-2 flex-wrap`,children:[e&&t(Wt,{name:`${e}:`}),l.map(({item:e,key:n})=>t(a,{children:String(e)},n))]}):n(`div`,{children:[e&&t(Wt,{name:e}),t(`div`,{className:`flex flex-col gap-2`,children:l.map(({item:e,index:n,key:r})=>t(Jt,{index:n,value:e,useBullet:c},r))})]})}function Jt({index:e,value:r,useBullet:i}){let a=i?t(`span`,{className:`text-xl`,children:`•`}):n(`span`,{children:[e+1,`.`]}),o=Yt(r),s;switch(o.type){case Y.Object:s=t(Gt,{children:Object.entries(r).map(([e,n])=>t(Kt,{name:e,value:n},e))});break;case Y.Array:s=t(qt,{value:r});break;case Y.Prose:s=t(`div`,{className:`prose dark:prose-invert`,children:o.value});break;default:s=t(`div`,{children:o.value});break}return n(`div`,{className:`flex gap-4 hover:bg-muted py-2 pe-2 ps-4`,children:[t(`div`,{className:`font-semibold text-muted`,children:a}),t(`div`,{children:s})]})}var Y;(function(e){e[e.Inline=0]=`Inline`,e[e.Paragraph=1]=`Paragraph`,e[e.Prose=2]=`Prose`,e[e.Array=3]=`Array`,e[e.Object=4]=`Object`})(Y||={});function Yt(e){if(e==null)return{value:`-`,type:Y.Inline};if(Array.isArray(e))return{value:e,type:Y.Array};if(typeof e==`string`){let t=e.length,n,r=e;return t<80?n=Y.Inline:t>400?n=Y.Prose:(n=Y.Paragraph,r=e.replace(/(?:\n\n)+/g,`
4
4
 
5
- `)),{type:n,value:r}}else if(typeof e==`number`||typeof e==`boolean`)return{value:String(e),type:Y.Inline};else return{value:e,type:Y.Object}}function Xt({value:e,viewCode:n=!1}){let{t:r}=J();return e?t(`div`,{className:`relative w-full h-full flex flex-col`,children:n||!Zt(e)?t(zt,{data:e}):t(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:t(Ut,{value:e})})}):t(`pre`,{className:`whitespace-pre-wrap`,children:r(`misc.noData`)})}function Zt(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?!0:Array.isArray(e)?e.every(Zt):typeof e==`object`&&Object.values(e).every(Zt)}const Qt=new Set;function $t(e){Qt.has(`markdown`)||(Qt.add(`markdown`),e.languages.registerFoldingRangeProvider(`markdown`,{provideFoldingRanges(e){let t=[],n=e.getLinesContent(),r=/^(#{1,6})\s/,i=[];for(let e=0;e<n.length;e++){let a=e+1,o=r.exec(n[e]);if(o){let e=o[1].length;for(;i.length>0&&i[i.length-1].level>=e;){let e=i.pop();e&&a-1>e.line&&t.push({start:e.line,end:a-1})}i.push({level:e,line:a})}}let a=n.length;for(;i.length>0;){let e=i.pop();e&&a>e.line&&t.push({start:e.line,end:a})}return t}}));for(let t of[`javascript`,`typescript`])Qt.has(t)||(Qt.add(t),e.languages.registerFoldingRangeProvider(t,{provideFoldingRanges(e){let t=e.getLinesContent(),n=/^(#{1,6})\s/,r=[],i=[],a=[],o=[],s=!1,c=!1,l=``;for(let e=0;e<t.length;e++){let u=e+1,d=t[e],f=s;for(let e=0;e<d.length;e++){let t=d[e];if(t===`\\`){e++;continue}if(c){t===l&&(c=!1);continue}if(s){t==="`"&&(s=!1);continue}if(t==="`"){s=!0;continue}if(t===`"`||t===`'`){c=!0,l=t;continue}if(t===`{`&&a.push(u),t===`}`&&a.length>0){let t=a.pop(),n=d.slice(e+1).trimStart().length>0?u-1:u;t!==void 0&&n>t&&r.push({start:t,end:n})}}if(f){let e=n.exec(d);if(e){let t=e[1].length;for(;o.length>0&&o[o.length-1].level>=t;){let e=o.pop();e&&u-1>e.line&&i.push({start:e.line,end:u-1})}o.push({level:t,line:u})}if(!s)for(;o.length>0;){let e=o.pop();e&&u>e.line&&i.push({start:e.line,end:u})}}}return[...r,...i]}}))}let en;function tn(){if(!(typeof document>`u`)){if(!en){let e=document.createElement(`div`);e.className=`monaco-editor`,e.style.position=`absolute`,e.style.top=`0`,e.style.left=`0`,e.style.zIndex=`10000`,document.body.appendChild(e),en=e}return en}}var nn=class{VgetValue;VsetValue;constructor(e,t){this.VgetValue=e,this.VsetValue=t}getValue(){return this.VgetValue()}setValue(e){this.VsetValue(e||``)}};function rn({onChange:e,value:n,className:r,editorRef:i,language:a=`javascript`,path:o,debounceTimeout:s=0,options:c={},beforeMount:l,onMount:u,defaultValue:d,useCustomFolding:f=!1}){let[p,m]=q(n||d||``),h=K(null),g=K(null),{theme:_}=E(),v=_===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:_,y=n||d||``,b=K(()=>p),x=K(e=>{m(e),h.current&&h.current.setValue(e)});W(()=>{b.current=()=>p},[p]),W(()=>(i&&(i.current=new nn(()=>b.current(),e=>x.current(e))),()=>{i&&(i.current=void 0)}),[i]);let S=G(()=>{if(e)return s>0?Ne(t=>e(t),s):e},[e,s]),C=H(async(e,t)=>{let n=e.getModel();if(n)for(let r of n.getValue().matchAll(/```[\s\S]*?```/g)){let i=n.getPositionAt(r.index).lineNumber,a=n.getPositionAt(r.index+r[0].length).lineNumber;e.setSelection(new t.Selection(i,1,a,1)),await e.getAction(`editor.createFoldingRangeFromSelection`)?.run()}},[]),ee=H(e=>{let t=e||``;if(m(t),S){let e={docChanged:!0,state:{doc:{toString:()=>t,length:t.length}}};S(e)}},[S]),w=H((e,t)=>{h.current=e,g.current=t,f&&$t(t),x.current=t=>{m(t),e.setValue(t)},t.editor.defineTheme(`errorLineTheme`,{base:v===`dark`?`vs-dark`:`vs`,inherit:!0,rules:[],colors:{"editorError.background":`#ffebee`,"editorError.border":`#f44336`}}),t.editor.setTheme(`errorLineTheme`),f&&setTimeout(()=>C(e,t),300),u?.(e,t)},[u,v,f,C]);W(()=>{m(e=>y===e?e:(h.current&&h.current.setValue(y),y))},[y]),W(()=>{if(!y||!f||!h.current||!g.current)return;let e=h.current,t=g.current,n=setTimeout(()=>C(e,t),300);return()=>clearTimeout(n)},[y,f,C]);let T={fontSize:14,fontFamily:`monospace`,minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:`on`,lineNumbers:`on`,folding:!0,lineDecorationsWidth:10,lineNumbersMinChars:3,automaticLayout:!0,formatOnPaste:!0,formatOnType:!0,tabSize:2,insertSpaces:!0,fixedOverflowWidgets:!0,overflowWidgetsDomNode:tn(),glyphMargin:!0,renderValidationDecorations:`on`,renderLineHighlight:`line`,hover:{enabled:!0,delay:100},quickSuggestions:{other:!0,comments:!0,strings:!0},...c};return t(`div`,{className:D(r,`w-full h-full!`),children:t(Me,{className:`h-full w-full`,height:`100%`,theme:v===`dark`?`vs-dark`:`light`,language:a,path:o,value:p,onChange:ee,onMount:w,beforeMount:l,options:T,defaultValue:d||``})})}function an({value:e,onChange:r,onValidChange:i,readonly:a=!1,height:o=`200px`,placeholder:s,className:c}){let{theme:l}=E(),u=K(void 0),[d,f]=q(null),p=G(()=>{if(e==null)return s??`{}`;try{return JSON.stringify(e,null,2)}catch{return`{}`}},[e,s]),m=H(()=>{if(!u.current||a)return;let e=u.current.getValue();try{let t=JSON.parse(e);f(null),i?.(t)}catch{f(`Invalid JSON`)}},[a,i]);return n(`div`,{className:c,children:[t(`div`,{className:`border rounded overflow-hidden`,style:{height:o},children:t(rn,{defaultValue:p,editorRef:u,language:`json`,theme:l===`dark`?`vs-dark`:`vs`,onChange:m,options:a?{readOnly:!0,domReadOnly:!0}:void 0})}),d&&t(`p`,{className:`text-xs text-destructive mt-1`,children:d})]})}function on(e){if(!e.current)return null;try{return JSON.parse(e.current.getValue())}catch{return null}}function sn({title:e,viewCode:i,setViewCode:a}){return n(`div`,{className:`flex items-center gap-1 bg-muted mb-2 p-1 rounded`,children:[t(r,{variant:i?`ghost`:`primary`,size:`sm`,title:`Preview properties`,onClick:()=>a(!1),children:e}),t(r,{variant:i?`primary`:`ghost`,size:`sm`,title:`View in JSON format`,onClick:()=>a(!0),children:`JSON`})]})}function cn(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).replace(/\s+/g,` `).trim().replace(/^./,e=>e.toUpperCase())}function ln(r){return r==null?`Failed to query`:typeof r==`string`?r:Array.isArray(r)?r.length===0?`None`:r.some(e=>e&&typeof e==`object`)?t(e,{children:r.map((e,r)=>n(`div`,{className:`flex gap-1`,children:[n(`span`,{className:`text-xs align-top pe-2 font-medium`,children:[r+1,`:`]}),t(`span`,{className:`text-xs`,children:ln(e)})]},`item-${r}`))}):r.map(e=>String(e)).join(`, `):typeof r==`object`?t(e,{children:Object.entries(r).map(([e,r])=>n(`div`,{className:`flex gap-1`,children:[n(`span`,{className:`text-xs align-top pe-2 font-medium`,children:[cn(e),`:`]}),t(`span`,{className:`text-xs`,children:ln(r)})]},e))}):String(r)}function un({data:e,className:r}){let i=e?Object.entries(e):[];return t(`table`,{className:r||`mb-2 text-xs bg-muted rounded-sm w-full`,children:t(`tbody`,{children:i.map(([e,r])=>n(`tr`,{className:`align-top hover:bg-background border-y`,children:[t(`td`,{className:`align-top pe-4 p-2`,children:cn(e)}),t(`td`,{className:`p-2`,children:ln(r)})]},e))})})}const dn=V(()=>({kind:`none`})),fn=dn.Provider;function pn(){return U(dn)}const mn={store:`document`,document:`document`,collection:`collection`,interaction:`interaction`,prompt:`prompt`,agent:`agent`,workflow:`workflow`,process:`process`,run:`interaction_run`};function hn(e){let t=e.indexOf(`:`);if(t<=0)return;let n=e.slice(0,t);if(!Object.hasOwn(mn,n))return;let r=e.slice(t+1).trim().replace(/^\/+/,``);if(r)return{type:mn[n],id:r}}function gn(...e){return Ve(O(e))}const _n=V(null);function vn(){return U(_n)}function yn(e){return e.startsWith(`agents/`)||e.startsWith(`documents/`)}function bn(e,t,n=`inline`){return`artifact:${e}:${t}:${n}`}function xn(e){return`file:${e}`}function Sn({error:e,chartTitle:r}){return t(`div`,{className:`flex items-center justify-center h-full bg-red-50 dark:bg-red-950 rounded-md p-4`,children:n(`div`,{className:`text-center`,children:[n(`p`,{className:`text-sm font-medium text-red-600 dark:text-red-400`,children:[`Cannot render `,r||`Vega-Lite`,` chart`]}),t(`p`,{className:`text-xs text-red-500 dark:text-red-500 mt-1 max-w-xs truncate`,children:e})]})})}function Cn({isOpen:e,onClose:i,title:a,description:o,children:s}){let{t:c}=J();return t(Le.Root,{open:e,onOpenChange:e=>!e&&i(),children:n(Le.Portal,{children:[t(Le.Overlay,{className:`fixed inset-0 z-50 bg-black/80 backdrop-blur-sm transition-all duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),n(Le.Content,{className:`fixed inset-2 sm:inset-4 z-50 flex flex-col bg-white dark:bg-gray-900 rounded-xl shadow-2xl transition-all duration-300 ease-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-98 data-[state=open]:zoom-in-98 data-[state=closed]:slide-out-to-bottom-2 data-[state=open]:slide-in-from-bottom-2`,onEscapeKeyDown:i,children:[t(Le.Close,{asChild:!0,children:t(r,{variant:`unstyled`,onClick:i,className:`absolute top-3 end-3 z-10 p-2 rounded-lg bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-150 shadow-sm`,"aria-label":c(`agent.closeFullscreen`),children:t(we,{className:`w-5 h-5 text-gray-600 dark:text-gray-300`})})}),t(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6 animate-in fade-in-0 duration-500 delay-150`,children:s}),t(`div`,{className:`flex items-center justify-between px-4 sm:px-6 py-3 border-t border-gray-200 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-800/50 rounded-b-xl`,children:n(`div`,{className:`flex flex-col`,children:[t(Le.Title,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:a||c(`agent.dashboard`)}),o&&t(Le.Description,{className:`text-sm text-gray-500 dark:text-gray-400 mt-0.5`,children:o})]})})]})]})})}function wn(e,t){if(t===`chart`)return 280;let n=1;if(e.vconcat)n=Array.isArray(e.vconcat)?e.vconcat.length:1;else if(e.concat){let t=e.columns||2,r=Array.isArray(e.concat)?e.concat.length:1;n=Math.ceil(r/t)}else e.facet&&(n=2);return Math.max(500,n*280+40)}const Tn={categorical:[`#6366f1`,`#8b5cf6`,`#ec4899`,`#f43f5e`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#06b6d4`,`#3b82f6`],blues:[`#dbeafe`,`#93c5fd`,`#3b82f6`,`#1d4ed8`,`#1e3a8a`],purples:[`#f3e8ff`,`#c4b5fd`,`#8b5cf6`,`#6d28d9`,`#4c1d95`],greens:[`#dcfce7`,`#86efac`,`#22c55e`,`#15803d`,`#14532d`],diverging:[`#ef4444`,`#fca5a5`,`#fef3c7`,`#86efac`,`#22c55e`]};function En(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Dn(e){return En(e)}function On(e){let t=JSON.parse(JSON.stringify(e)),n=[`vconcat`,`hconcat`,`concat`];if(!n.some(e=>Array.isArray(t[e])))return t;let r=[];if(Array.isArray(t.params))for(let e of t.params)e&&typeof e==`object`&&e.name&&e.select&&r.push({name:e.name,param:e});if(r.length===0)return t;for(let{name:e,param:i}of r){let r=i.select?.fields||[],a=i.select?.bind===`legend`,o=null;for(let e of n)if(Array.isArray(t[e])){o=t[e];break}if(!o||o.length===0)continue;let s=0;for(let e=0;e<o.length;e++){let t=o[e];if(An(t,r)||a&&jn(t,r)){s=e;break}}let c=o[s];c.params||=[],c.params.push(i),t.params=(t.params??[]).filter(t=>t.name!==e)}return Array.isArray(t.params)&&t.params.length===0&&delete t.params,t}function kn(e,t){if(!t||Object.keys(t).length===0)return e;let n=JSON.parse(JSON.stringify(e)),r=e=>{for(let n of e)n.name&&n.name in t&&(n.value=t[n.name])};Array.isArray(n.params)&&r(n.params);let i=e=>{if(Array.isArray(e)){for(let t of e)if(Array.isArray(t.params)&&r(t.params),t.vconcat&&i(t.vconcat),t.hconcat&&i(t.hconcat),t.concat&&i(t.concat),Array.isArray(t.layer))for(let e of t.layer)Array.isArray(e.params)&&r(e.params)}};if(n.vconcat&&i(n.vconcat),n.hconcat&&i(n.hconcat),n.concat&&i(n.concat),Array.isArray(n.layer))for(let e of n.layer)e&&Array.isArray(e.params)&&r(e.params);return n}function An(e,t){if(!e?.encoding)return!1;for(let n of t)for(let t of Object.values(e.encoding))if(t.field===n)return!0;if(Array.isArray(e.layer)){for(let n of e.layer)if(An(n,t))return!0}return!1}function jn(e,t){if(!e)return!1;let n=e=>{if(!e)return!1;let n=e.color?.field;return!!n&&t.includes(n)};if(n(e.encoding))return!0;if(Array.isArray(e.layer)){for(let t of e.layer)if(n(t.encoding))return!0}return!1}function Mn(e,t=[]){let n=[];if(!e||typeof e!=`object`)return n;if(e.data&&typeof e.data==`object`){let r=e.data.url;typeof r==`string`&&r.startsWith(`artifact:`)&&n.push({path:[...t,`data`],artifactPath:r.replace(/^artifact:/,``).trim()})}for(let r of[`layer`,`vconcat`,`hconcat`,`concat`,`spec`,`repeat`,`facet`])if(r in e){let i=e[r];Array.isArray(i)?i.forEach((e,i)=>{Dn(e)&&n.push(...Mn(e,[...t,r,String(i)]))}):Dn(i)&&n.push(...Mn(i,[...t,r]))}return n}function Nn(e,t){let n=JSON.parse(JSON.stringify(e));for(let[e,r]of t){let t=e.split(`.`),i=n;for(let e=0;e<t.length-1;e++){let n=i[t[e]];if(!En(n))break;i=n}let a=t[t.length-1],o=i[a];En(o)&&(delete o.url,o.values=r)}return n}function Pn(e){let t={background:`transparent`,view:{stroke:`transparent`},range:{category:Tn.categorical,diverging:Tn.diverging,heatmap:Tn.purples,ramp:Tn.blues},mark:{tooltip:!0},bar:{tooltip:!0,cornerRadiusTopLeft:4,cornerRadiusTopRight:4},line:{tooltip:!0,strokeWidth:2.5,strokeCap:`round`},point:{tooltip:!0,size:60,filled:!0},area:{tooltip:!0,fillOpacity:.7,line:!0},rect:{tooltip:!0,cornerRadius:2},arc:{tooltip:!0,cornerRadius:4},circle:{tooltip:!0,size:80}};return e?{...t,axis:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,gridColor:`#3f3f46`,domainColor:`#52525b`,tickColor:`#52525b`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#fafafa`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}:{...t,axis:{labelColor:`#71717a`,titleColor:`#3f3f46`,gridColor:`#e4e4e7`,domainColor:`#d4d4d8`,tickColor:`#d4d4d8`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#71717a`,titleColor:`#3f3f46`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#18181b`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}}const Fn=Oe(function({spec:i,artifactRunId:a}){let{t:o}=J(),{title:s,description:c,options:l}=i,u=i.spec,[d,f]=q(!1),[p,m]=q(!1),[h,g]=q(null),[_,v]=q(!1),y=K(null),b=K(null),x=K(null),{client:S}=Re(),C=vn(),ee=K(S);ee.current=S;let w=K(C);w.current=C;let[T,E]=q(null),[te,D]=q(!1),[O,k]=q(null),A=l?.mode||`chart`,j=A===`dashboard`,M=l?.enableFullscreen??j,N=l?.height||wn(u,A);W(()=>{let e=Mn(u);if(e.length===0){E(u),D(!1),k(null);return}a?console.info(`[VegaLiteChart] resolving artifacts with runId:`,a,e.map(e=>e.artifactPath)):console.warn(`[VegaLiteChart] artifact references found but artifactRunId is missing!`,{references:e.map(e=>e.artifactPath),artifactRunId:a});let t=!1;return D(!0),k(null),(async()=>{let n=new Map,r=ee.current,i=w.current;for(let o of e)try{let e=o.path.join(`.`),t;if(a&&!yn(o.artifactPath)){let e=bn(a,o.artifactPath,`inline`);t=i?await i.getOrFetch(e,async()=>(await r.files.getArtifactDownloadUrl(a,o.artifactPath,`inline`)).url):(await r.files.getArtifactDownloadUrl(a,o.artifactPath,`inline`)).url}else{let e=xn(o.artifactPath);t=i?await i.getOrFetch(e,async()=>(await r.files.getDownloadUrl(o.artifactPath)).url):(await r.files.getDownloadUrl(o.artifactPath)).url}let s=await fetch(t);if(!s.ok)throw Error(`Failed to fetch artifact data: ${s.statusText}`);let c=o.artifactPath.toLowerCase().endsWith(`.csv`),l;if(c){let e=await s.text();l=ze.parse(e,{header:!0,skipEmptyLines:!0,dynamicTyping:!0}).data}else{let e=await s.json();l=Array.isArray(e)?e:[e]}n.set(e,l)}catch(e){console.error(`Failed to resolve artifact: ${o.artifactPath}`,e),t||k(`Failed to load data from artifact: ${o.artifactPath}`);return}if(!t){let e=Nn(u,n);E(e),D(!1)}})(),()=>{t=!0}},[u,a]);let[re,ie]=q(!1),ae=K(!1);W(()=>{let e=()=>{let e=document.documentElement.classList.contains(`dark`);e!==ae.current&&(ae.current=e,ie(e))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let[ce,le]=q(0),ue=K(0);W(()=>{if(!x.current)return;let e,t=new ResizeObserver(t=>{clearTimeout(e),e=setTimeout(()=>{let e=t[0]?.contentRect.width;e&&e!==ue.current&&(ue.current=e,le(e))},100)});t.observe(x.current);let n=x.current.clientWidth;return ue.current=n,le(n),()=>{clearTimeout(e),t.disconnect()}},[]);let de=G(()=>Mn(u).length>0,[u]),P=G(()=>{if(de&&!T)return null;let e=T||u;return e?(l?.parameterValues&&(e=kn(e,l.parameterValues)),On(e)):null},[T,u,de,l?.parameterValues]),fe=H((e,t)=>{if(!e||typeof e!=`object`)return e;if(e.hconcat&&Array.isArray(e.hconcat)){let n=e.hconcat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,hconcat:e.hconcat.map(e=>fe(e,i))}}if(e.vconcat&&Array.isArray(e.vconcat))return{...e,vconcat:e.vconcat.map(e=>fe(e,t))};if(e.concat&&Array.isArray(e.concat)){let n=e.columns??e.concat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,concat:e.concat.map(e=>fe(e,i))}}let n=e.width;return n===`container`||typeof n==`number`&&n>t?{...e,width:t}:e},[]),pe=H((e,t=!1)=>{if(!P)return null;let n=Pn(re),r=t?typeof window<`u`?Math.min(window.innerWidth-80,1400):1200:ce>0?ce-24:500,i=`vconcat`in P||`hconcat`in P||`concat`in P,a=i?{type:`pad`,contains:`padding`}:{type:`fit`,contains:`padding`},o=P;i&&r&&(o=fe(P,r));let c=o.width,l=i?void 0:c===`container`?r:c??r,{width:u,...d}=o;return{$schema:`https://vega.github.io/schema/vega-lite/v6.json`,...!i&&l?{width:l}:{},height:t?void 0:e,autosize:a,...i?o:d,...s&&!P.title?{title:s}:{},config:{...n,...P.config}}},[P,s,re,ce,fe]),me=H(async()=>{let e=_?b.current:y.current;if(!(!e||p))try{(await e.toCanvas(2)).toBlob(async e=>{e&&(await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),m(!0),setTimeout(()=>m(!1),2e3))},`image/png`)}catch(e){console.error(`Failed to copy chart:`,e)}},[p,_]),_e=H(async()=>{let e=_?b.current:y.current;if(!(!e||d)){f(!0);try{let t=await e.toImageURL(`png`,2),n=document.createElement(`a`);n.download=`${s||`chart`}.png`,n.href=t,n.click()}catch(e){console.error(`Failed to export chart:`,e)}finally{f(!1)}}},[s,d,_]),ye=H(e=>{y.current=e,g(null)},[]),be=H(e=>{b.current=e},[]),xe=H(e=>{console.error(`Vega-Lite rendering error:`,e),g(e instanceof Error?e.message:`Unknown error`)},[]),F=H(()=>{v(e=>!e)},[]);W(()=>{g(null)},[u]);let I=({className:e})=>n(`div`,{className:gn(`flex items-center gap-2`,e),children:[n(r,{variant:`unstyled`,onClick:me,disabled:p,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 flex items-center gap-1`,title:o(`agent.copyToClipboard`),children:[t(p?ne:oe,{className:`w-3 h-3`}),o(p?`agent.copied`:`agent.copy`)]}),n(r,{variant:`unstyled`,onClick:_e,disabled:d,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1`,title:o(`agent.exportAsPng`),children:[t(se,{className:`w-3 h-3`}),o(d?`agent.exporting`:`agent.export`)]}),M&&n(r,{variant:`unstyled`,onClick:F,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors flex items-center gap-1`,title:o(_?`agent.exitFullscreen`:`agent.fullscreen`),children:[t(_?ve:ge,{className:`w-3 h-3`}),o(_?`agent.exit`:`agent.fullscreen`)]})]});if(te||de&&!T)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{className:`flex items-center justify-center bg-gray-50 dark:bg-gray-800 rounded`,style:{width:`100%`,height:N},children:n(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[t(he,{className:`w-5 h-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading data from artifacts...`})]})})]})});if(O)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:N},children:t(Sn,{error:O,chartTitle:s})})]})});if(h)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:N},children:t(Sn,{error:h,chartTitle:s})})]})});let L=pe(N),R=pe(0,!0);return L?(typeof window<`u`&&localStorage.getItem(`DEBUG_VEGA_RENDERS`)&&console.log(`VegaLite rendering with spec:`,{title:s,hasData:!!L.data?.values,dataLength:L.data?.values?.length}),n(e,{children:[t(`div`,{className:gn(`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,j&&`border-2`),children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[n(`div`,{className:`flex items-center justify-between`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||(j?`Dashboard`:`Chart`)}),j&&t(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-indigo-100 dark:bg-indigo-900 text-indigo-700 dark:text-indigo-300`,children:`Interactive`})]}),t(I,{})]}),c&&t(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c}),t(`div`,{ref:x,className:`bg-white dark:bg-gray-900 rounded overflow-hidden`,style:{width:`100%`,height:N,minWidth:0},children:t(Be,{spec:L,onEmbed:e=>ye(e.view),onError:xe,options:{renderer:l?.renderer||`canvas`,actions:!1}})})]})}),n(Cn,{isOpen:_,onClose:()=>v(!1),title:s||(j?`Dashboard`:`Chart`),description:c,children:[t(`div`,{className:`w-full h-full min-h-[calc(100vh-200px)]`,children:R&&t(Be,{spec:R,onEmbed:e=>be(e.view),onError:xe,options:{renderer:l?.renderer||`canvas`,actions:!1}})}),t(`div`,{className:`absolute bottom-6 end-6`,children:t(I,{className:`bg-white dark:bg-gray-800 rounded-lg shadow-lg p-2 border border-gray-200 dark:border-gray-700`})})]})]})):null},(e,t)=>JSON.stringify(e.spec)===JSON.stringify(t.spec)&&e.artifactRunId===t.artifactRunId),In=B.createContext({});function Ln({children:e,artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}){let o=G(()=>({artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}),[n,r,i,a]);return t(In.Provider,{value:o,children:e})}function Rn(){return B.useContext(In)}const zn={chart:{icon:j,label:`chart`,defaultHeight:200},mermaid:{icon:le,label:`diagram`,defaultHeight:150},proposal:{icon:_e,label:`options`,defaultHeight:100},code:{icon:ie,label:`code`,defaultHeight:80},image:{icon:P,label:`image`,defaultHeight:150},link:{icon:pe,label:`link`,defaultHeight:24},expand:{icon:se,label:`content`,defaultHeight:100},table:{icon:R,label:`table`,defaultHeight:150},markdown:{icon:ce,label:`content`,defaultHeight:100},"fusion-fragment":{icon:ie,label:`fragment`,defaultHeight:150}};function X({type:e,error:i,onRetry:a,message:o,height:s}){let c=zn[e],l=s??c.defaultHeight,u=e===`link`;if(i)return n(`div`,{className:`flex items-center gap-2 rounded border border-destructive/30 bg-destructive/5 text-destructive ${u?`inline-flex px-2 py-1 text-sm`:`p-4`}`,style:u?void 0:{minHeight:l},children:[n(`span`,{className:`text-destructive`,children:[`Failed to load `,c.label]}),a&&t(r,{variant:`unstyled`,onClick:a,className:`ms-2 rounded bg-destructive/10 px-2 py-1 text-xs hover:bg-destructive/20 transition-colors text-destructive`,children:`Retry`})]});let d=c.icon;return u?n(`span`,{className:`inline-flex items-center gap-1 text-muted animate-pulse`,children:[t(d,{className:`h-3 w-3`}),t(`span`,{children:o||`Loading ${c.label}...`})]}):n(`div`,{className:`flex flex-col items-center justify-center gap-3 rounded border border-border bg-muted/30 animate-pulse`,style:{minHeight:l},children:[t(d,{className:`h-8 w-8 text-muted`}),t(`span`,{className:`text-sm text-muted`,children:o||`Loading ${c.label}...`}),t(`div`,{className:`flex gap-1`,children:[...[,,,]].map((e,n)=>t(`div`,{className:`h-2 w-2 rounded-full bg-muted animate-bounce`,style:{animationDelay:`${n*150}ms`}},`dot-${n}`))})]})}var Z=class extends B.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`CodeBlock rendering error (${this.props.type}):`,e,t),this.props.onError?.(e)}handleRetry=()=>{this.setState({hasError:!1,error:void 0})};render(){if(this.state.hasError){let{type:e,fallbackCode:r}=this.props;return n(`div`,{className:`space-y-2`,children:[t(X,{type:e,error:this.state.error?.message||`Rendering failed`,onRetry:this.handleRetry}),r&&n(`details`,{className:`text-sm`,children:[t(`summary`,{className:`cursor-pointer text-muted hover:text-foreground`,children:`Show raw content`}),t(`pre`,{className:`mt-2 overflow-x-auto rounded bg-muted/50 p-2 text-xs`,children:t(`code`,{children:r})})]})]})}return this.props.children}};function Bn(e,t,n){let r=t.split(`.`).pop()?.toLowerCase();if(r===`svg`)return`mockup`;if([`png`,`jpg`,`jpeg`,`gif`,`webp`].includes(r||``))return`image`;if(r===`md`)return`markdown`;if(r===`csv`)return`table`;if(n===`json`&&typeof e==`object`&&e){let t=e;if(typeof t.$schema==`string`&&t.$schema.includes(`vega`)||t.library===`vega-lite`&&`spec`in t)return`vega-lite`;if(`template`in t&&`data`in t)return`fusion-fragment`;if(Array.isArray(e)&&e.length>0&&typeof e[0]==`object`)return`table`}return`code`}function Vn(e){if(typeof e!=`object`||!e)return null;let t=e;return t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`&&t.spec!==null?t:typeof t.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}function Hn({content:e}){let{headers:r,rows:i}=G(()=>{if(!Array.isArray(e)||e.length===0)return{headers:[],rows:[]};let t=e[0];if(typeof t!=`object`||!t)return{headers:[],rows:[]};let n=Object.keys(t);return{headers:n,rows:e.map(e=>n.map(t=>{let n=e[t];return n==null?``:typeof n==`object`?JSON.stringify(n):String(n)}))}},[e]);return r.length===0?t(X,{type:`table`,error:`No table data found`}):n(`div`,{className:`overflow-x-auto`,children:[n(`table`,{className:`min-w-full text-sm border-collapse`,children:[t(`thead`,{children:t(`tr`,{className:`border-b`,children:r.map(e=>t(`th`,{className:`px-3 py-2 text-start font-medium text-muted`,children:e},e))})}),t(`tbody`,{children:i.slice(0,100).map((e,n)=>t(`tr`,{className:`border-b border-muted/20`,children:e.map((e,n)=>t(`td`,{className:`px-3 py-2`,children:e},`cell-${n}`))},`row-${n}`))})]}),i.length>100&&n(`div`,{className:`text-sm text-muted py-2`,children:[`Showing 100 of `,i.length,` rows`]})]})}function Un({content:e,path:n}){let r=n.split(`.`).pop()?.toLowerCase()||``,i=typeof e==`string`?e:JSON.stringify(e,null,2);return t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{className:`language-${r}`,children:i})})}function Wn(e){return Ie.sanitize(e,{USE_PROFILES:{svg:!0,svgFilters:!0},ADD_TAGS:[`use`],FORBID_TAGS:[`foreignObject`]})}function Gn(e){return e.replace(/<svg([^>]*)>/i,(e,t)=>{let n=t;if(!/viewBox/i.test(n)){let e=/\swidth\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n),t=/\sheight\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n);e&&t&&(n+=` viewBox="0 0 ${e[1]} ${t[1]}"`)}return n=n.replace(/\swidth\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``).replace(/\sheight\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``),/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}function Kn({content:e}){let n=G(()=>{let t=typeof e==`string`?e.trim():``;return t?Gn(Wn(t)):null},[e]);return n?t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}}):t(X,{type:`expand`,error:`Empty mockup`})}function qn({content:e,path:n}){return t(`img`,{src:typeof e==`string`?e:``,alt:n.split(`/`).pop()||`Artifact image`,className:`max-w-full h-auto rounded`,loading:`lazy`})}function Jn({content:e,renderType:n,path:r,runId:i,contentType:a}){let{MarkdownRenderer:o}=Rn();switch(G(()=>n===`auto`?Bn(e,r,a):n,[e,r,a,n])){case`chart`:{let n=Vn(e);return n?t(Z,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(Fn,{spec:n,artifactRunId:i})}):t(X,{type:`chart`,error:`Only Vega-Lite charts are supported. Recharts rendering has been retired.`})}case`vega-lite`:{let n=Vn(e);return n?t(Z,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(Fn,{spec:n,artifactRunId:i})}):t(X,{type:`chart`,error:`Invalid Vega-Lite specification`})}case`fusion-fragment`:{let n=e;return console.log(`[ArtifactContentRenderer] fusion-fragment:`,{hasTemplate:!!n.template,hasData:!!n.data,runId:i,hasVegaLiteChart:!!Fn}),n.template&&n.data?t(Z,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(Fe,{data:n.data,ChartComponent:Fn,artifactRunId:i,children:t(Pe,{code:JSON.stringify(n.template),data:n.data})})}):t(Z,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(Pe,{code:JSON.stringify(e)})})}case`table`:return t(Z,{type:`table`,fallbackCode:JSON.stringify(e,null,2),children:t(Hn,{content:e})});case`markdown`:{let n=typeof e==`string`?e:String(e);return t(Z,{type:`markdown`,fallbackCode:n,children:o?t(o,{artifactRunId:i,children:n}):t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{children:n})})})}case`mockup`:return t(Z,{type:`expand`,fallbackCode:typeof e==`string`?e:r,children:t(Kn,{content:e})});case`image`:return t(Z,{type:`image`,fallbackCode:r,children:t(qn,{content:e,path:r})});default:return t(Un,{content:e,path:r})}}var Yn=class{components={};registerComponent(e,t){this.components[e]=t}getComponent(e){return this.components[e]}};const Xn=V(null);function Zn({components:e,children:n}){let r=G(()=>{let t=new Yn;for(let[n,r]of Object.entries(e))t.registerComponent(n,r);return t},[e]);return t(Xn.Provider,{value:r,children:n})}function Qn(){return U(Xn)}function $n(e){let t=U(Xn);if(t)return t.getComponent(e)}const er=`Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`;function tr(e){let t=e.trim(),n=``,r=!1,i=!1;for(let e=0;e<t.length;e++){let a=t[e],o=e>0?t[e-1]:``;if(a===`"`&&!i&&o!==`\\`){r=!r,n+=a;continue}if(a===`'`&&!r&&o!==`\\`){i=!i,n+=a;continue}if((r||i)&&a===`\\`){let r=e;for(;t[r]===`\\`;)r++;if(t[r]===`n`){n+=`<br/>`,e=r;continue}}n+=a}return n}function nr(e){return e.replace(/<svg([^<>]*)>/i,(e,t)=>{let n=t.replace(/\swidth="[^"]*"/i,``).replace(/\sheight="[^"]*"/i,``);return/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}et.initialize({startOnLoad:!1,theme:`default`,securityLevel:`loose`,fontFamily:er,suppressErrorRendering:!0,flowchart:{htmlLabels:!0,useMaxWidth:!0,nodeSpacing:40,rankSpacing:50,padding:12},sequence:{useMaxWidth:!0},themeVariables:{fontFamily:er}});function rr({code:e,className:n}){let r=K(null),[i,a]=q(null),[o,s]=q(null),c=ke().replace(/:/g,`_`);return W(()=>{let t=!1;return(async()=>{if(!e.trim()){a(null),s(null);return}try{s(null);let n=`mermaid-${c}-${Date.now()}`,r=tr(e),{svg:i}=await et.render(n,r),o=nr(i);t||a(o)}catch(e){if(!t){let t=e instanceof Error?e.message:`Failed to render mermaid diagram`;s(t),a(null)}}})(),()=>{t=!0}},[e,c]),o?null:i?t(`div`,{ref:r,className:`my-4 w-full overflow-x-auto [&_svg]:mx-auto [&_svg]:w-full [&_svg]:h-auto [&_svg]:max-w-full ${n||``}`,dangerouslySetInnerHTML:{__html:i}}):t(`div`,{className:`my-4 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg animate-pulse ${n||``}`,children:t(`div`,{className:`h-32 bg-gray-200 dark:bg-gray-700 rounded`})})}function ir(e){switch(e.split(`.`).pop()?.toLowerCase()){case`json`:return`json`;case`md`:case`txt`:case`csv`:case`yaml`:case`yml`:return`text`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`webp`:case`pdf`:return`binary`;default:return`text`}}function ar({runId:e,path:t,parseJson:n=!0}){let{client:r}=Re(),i=vn(),a=K(r);a.current=r;let o=K(i);o.current=i;let[s,c]=q({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l=H(async()=>{if(!e){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No run ID provided`,contentType:void 0});return}if(!t){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No artifact path provided`,contentType:void 0});return}c(e=>({...e,isLoading:!0,error:void 0}));let r=a.current,i=o.current,s=ir(t);try{let a=bn(e,t,`inline`),o;o=i?await i.getOrFetch(a,async()=>(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url):(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url;let l=await fetch(o);if(!l.ok)throw Error(`Failed to fetch artifact: ${l.status} ${l.statusText}`);if(s===`binary`){c({data:o,rawContent:void 0,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)});return}let u=await l.text(),d;if(n&&s===`json`)try{d=JSON.parse(u)}catch{d=u}else d=u;c({data:d,rawContent:u,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)})}catch(e){let n=e instanceof Error?e.message:`Failed to fetch artifact`;console.error(`Failed to fetch artifact content:`,t,e),c({data:void 0,rawContent:void 0,isLoading:!1,error:n,contentType:s})}},[e,t,n]);W(()=>{l()},[l]);let u=H(()=>{c({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l()},[l]);return{data:s.data,rawContent:s.rawContent,isLoading:s.isLoading,error:s.error,contentType:s.contentType,etag:s.etag,retry:u}}function or(e){let t=e.trim();if(t.length<2)return!0;if(!t.startsWith(`{`))return!1;try{return JSON.parse(t),!1}catch(e){let n=e instanceof Error?e.message:``,r=[`unexpected end`,`unterminated string`,`expected`,`unexpected token`],i=n.toLowerCase();if(r.some(e=>i.includes(e))){let e=0,n=0,r=!1,i=!1;for(let a of t){if(i){i=!1;continue}if(a===`\\`){i=!0;continue}if(a===`"`){r=!r;continue}r||(a===`{`?e++:a===`}`?e--:a===`[`?n++:a===`]`&&n--)}return e>0||n>0||r}return!1}}function sr(e){try{let t=e.trim(),n=t.indexOf(`{`),r=t.lastIndexOf(`}`);return n!==-1&&r>n&&(t=t.slice(n,r+1)),JSON.parse(t)}catch{return null}}function cr(e){let t=typeof e.$schema==`string`&&e.$schema.includes(`vega`),n=e.library===`vega-lite`&&`spec`in e;return t||n?`vega-lite`:null}function lr({code:e}){let{artifactRunId:n}=Rn();n||console.warn(`[VegaLiteCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=G(()=>or(e),[e]),i=G(()=>{if(r)return null;let t=sr(e);return t?{library:`vega-lite`,spec:t}:null},[e,r]);return r?t(X,{type:`chart`,message:`Loading chart...`}):i?t(Z,{type:`chart`,fallbackCode:e,children:t(Fn,{spec:i,artifactRunId:n})}):t(X,{type:`chart`,error:`Invalid Vega-Lite specification`})}function ur({code:e}){let{artifactRunId:n}=Rn();n||console.warn(`[ChartCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=G(()=>or(e),[e]),i=G(()=>{if(r)return null;let t=sr(e);return!t||!cr(t)?null:t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`?t:{library:`vega-lite`,spec:t}},[e,r]);return r?t(X,{type:`chart`,message:`Loading chart...`}):i?t(Z,{type:`chart`,fallbackCode:e,children:t(Fn,{spec:i,artifactRunId:n})}):t(X,{type:`chart`,error:`Invalid Vega-Lite chart specification`})}function dr({code:e}){let n=e.trim();return n?t(Z,{type:`mermaid`,fallbackCode:e,children:t(rr,{code:n})}):t(X,{type:`mermaid`,error:`Empty diagram`})}function fr({code:e}){let n=G(()=>{let t=e.trim();return t?Gn(Wn(t)):null},[e]);return n?t(Z,{type:`code`,fallbackCode:e,children:t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}})}):t(X,{type:`code`,error:`Empty mockup`})}function pr({code:e,language:n}){let{artifactRunId:r}=Rn(),i=e.trim(),a=G(()=>{if(!n?.includes(`:`))return`auto`;let e=n.split(`:`)[1];return[`chart`,`vega-lite`,`table`,`markdown`,`fusion-fragment`,`mockup`,`code`,`image`,`auto`].includes(e)?e:`auto`},[n]),{data:o,isLoading:s,error:c,contentType:l}=ar({runId:r,path:i});return r?s?t(X,{type:`expand`,message:`Loading ${i}...`}):c?t(X,{type:`expand`,error:`Failed to load artifact: ${c}`}):o===void 0?t(X,{type:`expand`,error:`No content found in artifact`}):t(Jn,{content:o,renderType:a,path:i,runId:r,contentType:l}):t(X,{type:`expand`,error:`No artifact run ID available`})}function mr(e){return e?.startsWith(`expand`)??!1}function hr(){return{chart:ur,"vega-lite":lr,vegalite:lr,mermaid:dr,mockup:fr,svg:fr}}const gr=new Set([`store`,`document`,`collection`,`interaction`,`prompt`,`agent`,`workflow`,`process`,`run`]);function _r(e){return e.trim().replace(/^\/+/,``)}function vr(e){if(e.startsWith(`artifact:`))return{scheme:`artifact`,path:e.slice(9).trim()};if(e.startsWith(`image:`))return{scheme:`image`,path:e.slice(6).trim()};let t=e.indexOf(`:`);if(t>0){let n=e.slice(0,t);if(gr.has(n))return{scheme:n,path:_r(e.slice(t+1))}}return{scheme:`standard`,path:e}}function yr({rawUrl:e,artifactRunId:t,disposition:n=`inline`}){let{client:r}=Re(),i=vn(),a=K(r);a.current=r;let o=K(i);o.current=i;let{scheme:s,path:c}=vr(e),[l,u]=q(()=>{if(s===`standard`)return{url:e,isLoading:!1,error:void 0};if(i&&(s===`artifact`||s===`image`)){let e;e=s===`artifact`&&t&&!yn(c)?bn(t,c,n):xn(c);let r=i.getUrl(e);if(r)return{url:r,isLoading:!1,error:void 0}}return{url:void 0,isLoading:!0,error:void 0}}),d=H(async()=>{if(s===`standard`)return;if(s!==`artifact`&&s!==`image`){u({url:void 0,isLoading:!1,error:`Unknown scheme: ${s}`});return}u(e=>({...e,isLoading:!0,error:void 0}));let e=a.current,r=o.current;try{let i;if(s===`artifact`)if(t&&!yn(c)){let a=bn(t,c,n);i=r?await r.getOrFetch(a,async()=>(await e.files.getArtifactDownloadUrl(t,c,n)).url):(await e.files.getArtifactDownloadUrl(t,c,n)).url}else{let t=xn(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}else{let t=xn(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}u({url:i,isLoading:!1,error:void 0})}catch(e){let t=e instanceof Error?e.message:`Failed to resolve URL`;console.error(`Failed to resolve URL:`,c,e),u({url:void 0,isLoading:!1,error:t})}},[s,c,t,n]);W(()=>{if(l.url&&!l.error)return;let e=!1;return e||(async()=>{await d()})(),()=>{e=!0}},[d,l.url,l.error]);let f=H(()=>{u({url:void 0,isLoading:!0,error:void 0}),d()},[d]);return{url:l.url,isLoading:l.isLoading,error:l.error,scheme:s,retry:f}}function br({src:e,alt:r,caption:i,className:a,artifactRunId:o}){let s=e||``,{scheme:c}=vr(s);return c===`standard`?n(`figure`,{className:`my-4`,children:[t(`img`,{src:e,alt:r,className:a}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):t(xr,{rawSrc:s,alt:r,caption:i,artifactRunId:o,className:a})}function xr({rawSrc:e,alt:r,caption:i,artifactRunId:a,className:o}){let{url:s,isLoading:c,error:l,retry:u}=yr({rawUrl:e,artifactRunId:a,disposition:`inline`});return c?t(X,{type:`image`,message:r?`Loading ${r}...`:void 0}):l?t(X,{type:`image`,error:l,onRetry:u}):s?n(`figure`,{className:`my-4`,children:[t(`img`,{src:s,alt:r,className:o}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):null}function Sr({node:e,src:n,alt:r,className:i,artifactRunId:a,ExistingImg:o,...s}){let c=n||``,{scheme:l}=vr(c);return l===`standard`?typeof o==`function`?t(o,{node:e,src:n,alt:r,...s}):t(`img`,{src:n,alt:r,className:i,...s}):t(Cr,{rawSrc:c,alt:r,artifactRunId:a,className:i,rest:s})}function Cr({rawSrc:e,alt:n,artifactRunId:r,className:i,rest:a}){let{url:o,isLoading:s,error:c,retry:l}=yr({rawUrl:e,artifactRunId:r,disposition:`inline`});return s?t(X,{type:`image`,message:n?`Loading ${n}...`:void 0}):c?t(X,{type:`image`,error:c,onRetry:l}):o?t(`img`,{src:o,alt:n,className:i,...a}):null}function wr({node:e,href:n,children:r,className:i,artifactRunId:a,onArtifactOpen:o,ExistingLink:s,...c}){let l=n||``,u=hn(l);if(u)return t(Tr,{resource:u,rawHref:l,artifactRunId:a,className:i,ExistingLink:s,rest:c,children:r});let{scheme:d,path:f}=vr(l);return d===`standard`?typeof s==`function`?t(s,{node:e,href:n,className:i,...c,children:r}):t(`a`,{href:n,...c,className:i,target:`_blank`,rel:`noopener noreferrer`,children:r}):t(Er,{rawHref:l,artifactRunId:a,artifactPath:d===`artifact`?f:void 0,onArtifactOpen:o,className:i,rest:c,children:r})}function Tr({resource:e,rawHref:n,artifactRunId:i,className:a,children:o,ExistingLink:s,rest:c}){let l=pn()(e,{workflowRunId:i,source:`markdown`,rawHref:n});return l.kind===`navigate`?typeof s==`function`?t(s,{href:l.href,className:a,...c,children:o}):t(`a`,{href:l.href,...c,className:a,target:`_blank`,rel:`noopener noreferrer`,children:o}):l.kind===`activate`?t(r,{variant:`link`,size:`none`,className:a,onClick:l.onActivate,children:o}):t(`span`,{className:a,children:o})}function Er({rawHref:e,artifactRunId:n,artifactPath:r,onArtifactOpen:i,className:a,children:o,rest:s}){let{url:c,isLoading:l,error:u,retry:d}=yr({rawUrl:e,artifactRunId:n,disposition:`attachment`});return l?t(`span`,{className:`inline-flex items-center gap-1 text-muted`,children:t(X,{type:`link`})}):u?t(`span`,{className:`inline-flex items-center gap-1`,children:t(X,{type:`link`,error:u,onRetry:d})}):t(`a`,{href:c||`#`,...s,className:a,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>{r&&/\.md$/i.test(r)&&i&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&e.button===0&&(e.preventDefault(),i(r))},children:o})}const Dr=[`artifact:`,`image:`,`store:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`],Or=/(!?\[[^[\]\n]*\]\()((?:artifact:|image:|store:|document:\/\/|collection:|interaction:|prompt:|agent:|workflow:|process:|run:)[^)[\n]+)(\))/g,kr=/`[^`\n]*`/g,Ar=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,jr=/\s+("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\([^)]*\))\s*$/;function Mr(e){return Dr.some(t=>e.startsWith(t))}function Nr(e){let t=e.trim();if(t.startsWith(`<`)){let n=t.indexOf(`>`);if(n>0&&Mr(t.slice(1,n).trim()))return e}let n=t.match(jr)?.index??-1,r=(n>=0?t.slice(0,n):t).trim(),i=n>=0?t.slice(n):``;return Mr(r)?`<${r}>${i}`:e}function Pr(e){return e.replace(Or,(e,t,n,r)=>`${t}${Nr(n)}${r}`)}function Fr(e){let t=``,n=0;for(let r of e.matchAll(kr))t+=Pr(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=Pr(e.slice(n)),t}function Ir(e){if(!e||!Dr.some(t=>e.includes(t)))return e;let t=``,n=0;for(let r of e.matchAll(Ar))t+=Fr(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=Fr(e.slice(n)),t}const Lr=/^([ \t]*):::([^\n]*?):::[ \t]*$/gm,Rr=/^\w+/;function zr(e){return e?.includes(`:::`)?e.replace(Lr,(e,t,n)=>{let r=n.trim(),i=Rr.exec(r);if(!i)return e;let a=i[0],o=r.slice(a.length).trim();return o?`${t}:::${a}\n${t}${o}\n${t}:::`:`${t}::${a}`}):e}const Br=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,Vr=/`[^`\n]*`/g,Hr=/\\\$/g,Ur=/\\[^\s]/,Wr=/[{}]/,Gr=/[_^][\w{]/,Kr=/^[a-zA-Z]$/,qr=/^[a-zA-Z]\s*=/,Jr=/^\s/,Yr=/\s$/,Xr=/[+*/-]$/,Zr=/\^[+-]$/;function Qr(e){return Ur.test(e)||Wr.test(e)||Gr.test(e)||Kr.test(e)||qr.test(e)}function $r(e){return!!(Jr.test(e)||Yr.test(e)||Xr.test(e)&&!Zr.test(e))}function ei(e){let t=[];for(let n=0;n<e.length;n++)if(e[n]===`$`&&!(n>0&&e[n-1]===`\\`)){if(n+1<e.length&&e[n+1]===`$`){n++;continue}n>0&&e[n-1]===`$`&&(n<2||e[n-2]!==`\\`)||t.push(n)}return t}function ti(e,t,n){let r=e.slice(t+1,n);return r.length===0||r.includes(`
6
- `)?null:r}function ni(e){let t=ei(e);if(t.length<2)return e;let n=new Set,r=new Set,i=Array(t.length-1);for(let n=0;n<t.length-1;n++)i[n]=ti(e,t[n],t[n+1]);let a=[];for(let e=0;e<t.length-1;e++){if(n.has(e))continue;let r=i[e];r!==null&&Qr(r)&&(n.add(e),n.add(e+1),a.push([t[e],t[e+1]]))}let o=0;for(;o<t.length;){if(n.has(o)){o++;continue}let e=o+1;for(;e<t.length&&n.has(e);)e++;if(e>=t.length)break;if(e>o+1){r.add(t[o]),o++;continue}let a=i[o];if(a===null){o++;continue}$r(a)&&(r.add(t[o]),r.add(t[e])),n.add(o),n.add(e),o=e+1}for(let e=0;e<t.length;e++)n.has(e)||e+1<t.length&&n.has(e+1)&&r.add(t[e]);if(r.size===0&&a.length===0)return e;let s=[],c=0,l=Array.from(r).sort((e,t)=>e-t),u=0,d=0;for(;u<l.length||d<a.length;){let t=u<l.length?l[u]:1/0;if(t<(d<a.length?a[d][0]:1/0))t>c&&s.push(e.slice(c,t)),s.push(`\\$`),c=t+1,u++;else{let[t,n]=a[d];t>c&&s.push(e.slice(c,t));let r=e.slice(t,n+1);for(s.push(r.replace(Hr,`\\text{\\textdollar}`)),c=n+1;u<l.length&&l[u]<=n;)u++;d++}}return c<e.length&&s.push(e.slice(c)),s.join(``)}function ri(e){let t=[],n=0;for(let r of e.matchAll(Vr))t.push(ni(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(ni(e.slice(n))),t.join(``)}function ii(e){if(!e?.includes(`$`))return e;let t=[],n=0;for(let r of e.matchAll(Br))t.push(ri(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(ri(e.slice(n))),t.join(``)}const ai={note:`md-callout-info`,tip:`md-callout-info`,warning:`md-callout-attention`,important:`md-callout-attention`,caution:`md-callout-destructive`},oi={note:`Note`,tip:`Tip`,warning:`Warning`,important:`Important`,caution:`Caution`};function si(){return e=>{$e(e,e=>{if(e.type!==`containerDirective`&&e.type!==`leafDirective`&&e.type!==`textDirective`)return;let t=e;t.data||={};let n=t.data,r=t.attributes||{},i=t.name;if(i===`pagebreak`){n.hName=`hr`,n.hProperties={className:`md-pagebreak`};return}if(i===`columns`){n.hName=`div`,n.hProperties={className:`md-columns`};return}if(i===`column`){n.hName=`div`;let e={className:`md-column`};r.width&&(e.style=`flex-basis:${r.width};flex-grow:0;flex-shrink:0`),n.hProperties=e;return}if(i in ai){n.hName=`div`,n.hProperties={className:`md-callout ${ai[i]}`,"data-callout-type":i};let e=oi[i];if(e&&t.children){let n={type:`paragraph`,data:{hName:`p`,hProperties:{className:`md-callout-title`}},children:[{type:`text`,value:e}]};t.children.unshift(n)}return}n.hName=`div`,n.hProperties={className:`md-${i}`,...Object.fromEntries(Object.entries(r).filter(([e])=>e!==`class`))},r.class&&(n.hProperties.className+=` ${r.class}`)})}}const ci=[`artifact:`,`image:`,`store:`,`document:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`];function li(e){return ci.some(t=>e.startsWith(t))?e:Ue(e)}function ui(){return e=>{$e(e,`html`,(e,t,n)=>{let r=e,i=n;if(typeof r.value==`string`&&/<!--[\s\S]*?-->/.test(r.value)&&i?.children&&typeof t==`number`)return i.children.splice(t,1),[Qe,t]})}}const di=hr();function fi({children:e,components:n,remarkPlugins:r=[],removeComments:i=!0,artifactRunId:a,onArtifactOpen:o,className:s,codeClassName:c,inlineCodeClassName:l,linkClassName:u,imageClassName:d,onProposalSelect:f,onProposalSubmit:p,preserveSourcePositions:m=!1}){let h=Qn(),g=B.useMemo(()=>m?e:zr(Ir(ii(e))),[e,m]),_=t(Ln,{artifactRunId:a,onProposalSelect:f,onProposalSubmit:p,MarkdownRenderer:fi,children:t(He,{remarkPlugins:B.useMemo(()=>{let e=[Je,qe,si,Ye,Ke,Ze,Xe,...r];return i&&e.push(ui),e},[r,i]),rehypePlugins:B.useMemo(()=>[We],[]),remarkRehypeOptions:B.useMemo(()=>({handlers:{...Ge}}),[]),components:B.useMemo(()=>{let e=n||{},r=e.code,i=e.a,s=e.img,f=({node:e,className:n,children:i,...a})=>{let o=/language-([\w-]+)/.exec(n||``),s=!o,u=o?o[1]:``;if(!s&&u){if(h){let e=h.getComponent(u);if(e)return t(e,{code:String(i||``).trim(),language:u})}if(mr(u))return t(pr,{code:String(i||``).trim(),language:u});let e=di[u];if(e)return t(e,{code:String(i||``).trim(),language:u})}return typeof r==`function`?t(r,{node:e,className:n,...a,children:i}):t(`code`,{...a,className:s?`px-1.5 py-0.5 rounded ${l||``}`:` ${c||``}`,children:i})},p=e=>{let{node:n,href:r,children:s,...c}=e;return t(wr,{node:n,href:r,className:u,artifactRunId:a,onArtifactOpen:o,ExistingLink:typeof i==`function`?i:void 0,...c,children:s})},m=e=>{let{node:n,src:r,alt:i,title:o,...c}=e;return o?t(br,{src:r,alt:i,caption:o,className:d,artifactRunId:a}):t(Sr,{node:n,src:r,alt:i,className:d,artifactRunId:a,ExistingImg:typeof s==`function`?s:void 0,...c})};return{...e,code:f,a:p,img:m}},[n,a,o,h,c,l,u,d]),urlTransform:li,children:g})});return s?t(`div`,{className:`md-content ${s}`,children:_}):t(`div`,{className:`md-content`,children:_})}const pi=new Set([`list`,`blockquote`,`table`]),mi=V(null),hi=V(!1),gi=De(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownComponentEditor}))),_i=/^ {0,3}(#{1,6})[\t ]+(.+?)[\t ]*#*[\t ]*$/,vi=/^ {0,3}(`{3,}|~{3,})/;function yi(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`edit-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function bi(e,t,n){let r=t?.position?.start.offset,i=t?.position?.end.offset,a=typeof r==`number`&&typeof i==`number`&&r>=0&&i>=r,o=a?e.slice(r,i):``;return{block_id:a?`${n}:${r}:${i}`:`${n}:${yi()}`,block_type:n,...a?{source_range:{start:r,end:i}}:{},exact_text:o,...a&&r>0?{prefix:e.slice(Math.max(0,r-80),r)}:{},...a&&i<e.length?{suffix:e.slice(i,Math.min(e.length,i+80))}:{}}}function xi(e,t){let n=t.source_range?.start;if(typeof n!=`number`)return t;let r=Ci(e,n),i=wi(e,t.exact_text,n,r);return{...t,...r.length>0?{heading_path:r}:{},occurrence_index:i}}function Si(e,t,n){return xi(e,bi(e,t,n))}function Ci(e,t){let n=[],r=null,i=0;for(let a of e.slice(0,t).split(`
7
- `)){let e=vi.exec(a);if(e){let t=e[1]?.[0];r?t===r&&(r=null):r=t??null,i+=a.length+1;continue}if(!r){let e=_i.exec(a);if(e){let t=e[1]?.length??1,r=e[2]?.trim();r&&(n.length=t-1,n[t-1]=r)}}if(i+=a.length+1,i>t)break}return n.filter(e=>!!e)}function wi(e,t,n,r){if(!t)return 0;let i=0,a=e.indexOf(t);for(;a>=0&&a<n;){let n=Ci(e,a);n.length===r.length&&n.every((e,t)=>e===r[t])&&i++,a=e.indexOf(t,a+Math.max(1,t.length))}return i}function Ti(e){return e.kind===`store_document`?`store:${e.document_id}`:`artifact:${e.path} (run ${e.run_id})`}function Ei(...e){let t=0;for(let n of e)for(let e of n.matchAll(/`+/g))t=Math.max(t,e[0].length);return"`".repeat(Math.max(3,t+1))}function Di(e,t){let n=t.user_change;if(!n)return;let{before:r,after:i}=n,a=t.anchor.source_range;if(a&&e.slice(a.start,a.end)===r)return e.slice(0,a.start)+i+e.slice(a.end);let o=t.anchor.prefix;if(o){let t=e.indexOf(o+r);if(t>=0&&e.indexOf(o+r,t+1)<0){let n=t+o.length;return e.slice(0,n)+i+e.slice(n+r.length)}}let s=e.indexOf(r);if(!(s<0||e.indexOf(r,s+1)>=0))return e.slice(0,s)+i+e.slice(s+r.length)}function Oi(e){let t=Ti(e.resource),n=e.anchor.block_type.replace(`_`,` `);if(e.action===`edit`&&e.user_change&&e.applied){let r=Ei(e.user_change.before,e.user_change.after);return[`I already edited the ${n} in ${t} myself and the change is saved${e.updated_document_id?` as revision ${e.updated_document_id}`:``}.`,`Operation: ${e.operation_id}`,`This is a notification only. Do not apply this change again and do not modify the document in response; acknowledge briefly and use the latest content going forward.`,``,`Before:`,`${r}markdown`,e.user_change.before,r,``,`After:`,`${r}markdown`,e.user_change.after,r].join(`
8
- `)}if(e.action===`edit`&&e.user_change){let r=Ei(e.user_change.before,e.user_change.after);return[`Apply my edit to the ${n} in ${t}, then update the resource.`,`Operation: ${e.operation_id}`,`Preserve all content outside the selected block exactly; do not regenerate unrelated sections.`,``,`Before:`,`${r}markdown`,e.user_change.before,r,``,`After:`,`${r}markdown`,e.user_change.after,r].join(`
9
- `)}let r=Ei(e.anchor.exact_text);return[`Update the ${n} in ${t} based on this comment:`,`Operation: ${e.operation_id}`,`Preserve all content outside the selected block exactly; do not regenerate unrelated sections.`,``,e.comment??``,``,`Selected content:`,`${r}markdown`,e.anchor.exact_text,r].join(`
10
- `)}function ki(){let e=U(mi);if(!e)throw Error(`Collaborative Markdown blocks must be rendered inside CollaborativeMarkdownRenderer`);return e}function Ai({anchor:e,mode:i,initialDraft:a}){let{t:o}=J(),{artifactRunId:s,readOnly:c,allowComments:l,cancelEditing:u,submit:d,updateDraft:f}=ki(),[p,m]=q(i===`edit`?e.exact_text:i===`insert`?a??``:``),[h,g]=q(!1),_=i===`comment`?!l:c,v=e=>{m(e),f(e)},y=async()=>{if(!(!p.trim()||h)){g(!0);try{await d(e,i,i===`comment`?p.trim():p)}finally{g(!1)}}};return n(`div`,{className:`mb-2 space-y-2`,children:[i===`edit`||i===`insert`?t(Ee,{fallback:t(x,{value:p,onChange:e=>v(e.target.value),placeholder:o(`agent.editSelectionPlaceholder`),rows:6,autoFocus:!0}),children:t(gi,{value:p,onChange:v,artifactRunId:s,editable:!c,externalValueSync:`manual`,autoFocus:!0})}):t(x,{value:p,onChange:e=>v(e.target.value),placeholder:o(`agent.commentOnSelectionPlaceholder`),rows:3,autoFocus:!0,disabled:!l}),n(`div`,{className:`flex justify-end gap-2`,children:[n(r,{variant:`outline`,size:`sm`,onClick:u,disabled:h,children:[t(we,{className:`me-1 size-4`}),o(`store.cancelEdit`)]}),n(r,{size:`sm`,onClick:()=>void y(),disabled:_||!p.trim()||h,children:[t(I,{className:`me-1 size-4`}),o(`agent.send`)]})]})]})}function Q(i,a,u){return function({node:d,children:f,...p}){let{t:m}=J(),{markdown:h,readOnly:g,allowComments:_,activeEditing:v,highlightChangesFrom:y,flashChangedBlocks:b,beginEditing:x}=ki(),ee=U(hi),w=u?B.createElement(u,{node:d,...p},f):B.createElement(i,p,f);if(ee)return w;let T=bi(h,d,a),E=!!(T.source_range&&T.exact_text),te=!g&&E,D=_&&E,O=v?.anchor.block_id===T.block_id,k=O&&v?.mode===`edit`,A=b&&!!T.exact_text&&!!y&&!y?.includes(T.exact_text),ne=C(`group/collab relative rounded-md border transition-colors duration-700`,`-mx-2 -my-1 px-2 py-1`,k?`border-transparent`:O?`border-info bg-mixer-info/5`:te||D?`border-transparent hover:border-mixer-info/30 hover:bg-mixer-muted/10`:`border-transparent`,A&&`border-mixer-success/50 bg-mixer-success/15 ring-1 ring-mixer-success/20`),M=te||D||O?n(e,{children:[n(`div`,{className:C(`absolute end-1 top-1 z-10 flex items-center gap-0.5 rounded-md border bg-background p-0.5 shadow-sm`,(!te&&!D||k)&&`hidden`,O?`opacity-100`:`pointer-events-none opacity-0 group-hover/collab:pointer-events-auto group-hover/collab:opacity-100 group-focus-within/collab:pointer-events-auto group-focus-within/collab:opacity-100`),children:[D?t(S,{description:m(`agent.commentOnSelection`),asChild:!0,children:t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,"aria-label":m(`agent.commentOnSelection`),onClick:()=>x(T,`comment`),children:t(_e,{className:`size-4`})})}):null,te?t(S,{description:m(`agent.editSelection`),asChild:!0,children:t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,"aria-label":m(`agent.editSelection`),onClick:()=>x(T,`edit`),children:t(ye,{className:`size-4`})})}):null,te?n(o,{children:[t(S,{description:m(`agent.insertComponent`),asChild:!0,children:t(l,{asChild:!0,children:t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,"aria-label":m(`agent.insertComponent`),children:t(xe,{className:`size-4`})})})}),n(s,{align:`end`,className:`w-52`,children:[n(c,{onClick:()=>x(T,`insert`,m(`richText.paragraph`)),children:[t(be,{}),m(`richText.paragraph`)]}),n(c,{onClick:()=>x(T,`insert`,`## ${m(`richText.heading2`)}`),children:[t(de,{}),m(`richText.heading2`)]}),n(c,{onClick:()=>x(T,`insert`,`- ${m(`richText.bulletList`)}`),children:[t(me,{}),m(`richText.bulletList`)]}),n(c,{onClick:()=>x(T,`insert`,`> ${m(`richText.blockquote`)}`),children:[t(F,{}),m(`richText.blockquote`)]}),n(c,{onClick:()=>x(T,`insert`,"```\nCode\n```"),children:[t(ae,{}),m(`richText.codeBlock`)]}),n(c,{onClick:()=>x(T,`insert`,`| Column | Value |
5
+ `)),{type:n,value:r}}else if(typeof e==`number`||typeof e==`boolean`)return{value:String(e),type:Y.Inline};else return{value:e,type:Y.Object}}function Xt({value:e,viewCode:n=!1}){let{t:r}=J();return e?t(`div`,{className:`relative w-full h-full flex flex-col`,children:n||!Zt(e)?t(zt,{data:e}):t(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:t(Ut,{value:e})})}):t(`pre`,{className:`whitespace-pre-wrap`,children:r(`misc.noData`)})}function Zt(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?!0:Array.isArray(e)?e.every(Zt):typeof e==`object`&&Object.values(e).every(Zt)}const Qt=new Set;function $t(e){Qt.has(`markdown`)||(Qt.add(`markdown`),e.languages.registerFoldingRangeProvider(`markdown`,{provideFoldingRanges(e){let t=[],n=e.getLinesContent(),r=/^(#{1,6})\s/,i=[];for(let e=0;e<n.length;e++){let a=e+1,o=r.exec(n[e]);if(o){let e=o[1].length;for(;i.length>0&&i[i.length-1].level>=e;){let e=i.pop();e&&a-1>e.line&&t.push({start:e.line,end:a-1})}i.push({level:e,line:a})}}let a=n.length;for(;i.length>0;){let e=i.pop();e&&a>e.line&&t.push({start:e.line,end:a})}return t}}));for(let t of[`javascript`,`typescript`])Qt.has(t)||(Qt.add(t),e.languages.registerFoldingRangeProvider(t,{provideFoldingRanges(e){let t=e.getLinesContent(),n=/^(#{1,6})\s/,r=[],i=[],a=[],o=[],s=!1,c=!1,l=``;for(let e=0;e<t.length;e++){let u=e+1,d=t[e],f=s;for(let e=0;e<d.length;e++){let t=d[e];if(t===`\\`){e++;continue}if(c){t===l&&(c=!1);continue}if(s){t==="`"&&(s=!1);continue}if(t==="`"){s=!0;continue}if(t===`"`||t===`'`){c=!0,l=t;continue}if(t===`{`&&a.push(u),t===`}`&&a.length>0){let t=a.pop(),n=d.slice(e+1).trimStart().length>0?u-1:u;t!==void 0&&n>t&&r.push({start:t,end:n})}}if(f){let e=n.exec(d);if(e){let t=e[1].length;for(;o.length>0&&o[o.length-1].level>=t;){let e=o.pop();e&&u-1>e.line&&i.push({start:e.line,end:u-1})}o.push({level:t,line:u})}if(!s)for(;o.length>0;){let e=o.pop();e&&u>e.line&&i.push({start:e.line,end:u})}}}return[...r,...i]}}))}let en;function tn(){if(!(typeof document>`u`)){if(!en){let e=document.createElement(`div`);e.className=`monaco-editor`,e.style.position=`absolute`,e.style.top=`0`,e.style.left=`0`,e.style.zIndex=`10000`,document.body.appendChild(e),en=e}return en}}const nn=new Map;let rn=0;function an(e){(e.languages.json?.jsonDefaults)?.setDiagnosticsOptions({validate:!0,enableSchemaRequest:!1,schemas:Array.from(nn.entries()).map(([e,t])=>({uri:`vertesia://schemas/${encodeURIComponent(e)}`,fileMatch:[e],schema:t}))})}var on=class{VgetValue;VsetValue;constructor(e,t){this.VgetValue=e,this.VsetValue=t}getValue(){return this.VgetValue()}setValue(e){this.VsetValue(e||``)}};function sn({onChange:e,value:n,className:r,editorRef:i,language:a=`javascript`,path:o,debounceTimeout:s=0,options:c={},beforeMount:l,onMount:u,defaultValue:d,useCustomFolding:f=!1,jsonSchema:p}){let[m,h]=q(n||d||``),g=K(null),_=K(null),[v]=q(()=>p?`inmemory://vertesia/json/${++rn}.json`:void 0),y=o??v,{theme:ee}=T(),b=ee===`system`?window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`:ee,x=n||d||``,S=K(()=>m),te=K(e=>{h(e),g.current&&g.current.setValue(e)});W(()=>{S.current=()=>m},[m]),W(()=>(i&&(i.current=new on(()=>S.current(),e=>te.current(e))),()=>{i&&(i.current=void 0)}),[i]);let C=G(()=>{if(e)return s>0?Ne(t=>e(t),s):e},[e,s]),w=H(async(e,t)=>{let n=e.getModel();if(n)for(let r of n.getValue().matchAll(/```[\s\S]*?```/g)){let i=n.getPositionAt(r.index).lineNumber,a=n.getPositionAt(r.index+r[0].length).lineNumber;e.setSelection(new t.Selection(i,1,a,1)),await e.getAction(`editor.createFoldingRangeFromSelection`)?.run()}},[]),E=H(e=>{let t=e||``;if(h(t),C){let e={docChanged:!0,state:{doc:{toString:()=>t,length:t.length}}};C(e)}},[C]),O=H((e,t)=>{g.current=e,_.current=t,p&&y&&a===`json`&&(nn.set(y,p),an(t)),f&&$t(t),te.current=t=>{h(t),e.setValue(t)},t.editor.defineTheme(`errorLineTheme`,{base:b===`dark`?`vs-dark`:`vs`,inherit:!0,rules:[],colors:{"editorError.background":`#ffebee`,"editorError.border":`#f44336`}}),t.editor.setTheme(`errorLineTheme`),f&&setTimeout(()=>w(e,t),300),u?.(e,t)},[u,b,f,w,p,y,a]);W(()=>()=>{p&&y&&nn.delete(y)&&_.current&&an(_.current)},[p,y]),W(()=>{g.current?.hasTextFocus()||h(e=>x===e?e:(g.current&&g.current.setValue(x),x))},[x]),W(()=>{if(!x||!f||!g.current||!_.current||g.current.hasTextFocus())return;let e=g.current,t=_.current,n=setTimeout(()=>w(e,t),300);return()=>clearTimeout(n)},[x,f,w]);let k={fontSize:14,fontFamily:`monospace`,minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:`on`,lineNumbers:`on`,folding:!0,lineDecorationsWidth:10,lineNumbersMinChars:3,automaticLayout:!0,formatOnPaste:!0,formatOnType:!0,tabSize:2,insertSpaces:!0,fixedOverflowWidgets:!0,overflowWidgetsDomNode:tn(),glyphMargin:!0,renderValidationDecorations:`on`,renderLineHighlight:`line`,hover:{enabled:`on`,delay:100},quickSuggestions:{other:!0,comments:!0,strings:!0},...c};return t(`div`,{className:D(r,`w-full h-full!`),children:t(Me,{className:`h-full w-full`,height:`100%`,theme:b===`dark`?`vs-dark`:`light`,language:a,path:y,onChange:E,onMount:O,beforeMount:l,options:k,defaultValue:x})})}function cn({value:e,onChange:r,onValidChange:i,readonly:a=!1,height:o=`200px`,placeholder:s,className:c}){let{theme:l}=T(),u=K(void 0),[d,f]=q(null),p=G(()=>{if(e==null)return s??`{}`;try{return JSON.stringify(e,null,2)}catch{return`{}`}},[e,s]),m=H(()=>{if(!u.current||a)return;let e=u.current.getValue();try{let t=JSON.parse(e);f(null),i?.(t)}catch{f(`Invalid JSON`)}},[a,i]);return n(`div`,{className:c,children:[t(`div`,{className:`border rounded overflow-hidden`,style:{height:o},children:t(sn,{defaultValue:p,editorRef:u,language:`json`,theme:l===`dark`?`vs-dark`:`vs`,onChange:m,options:a?{readOnly:!0,domReadOnly:!0}:void 0})}),d&&t(`p`,{className:`text-xs text-destructive mt-1`,children:d})]})}function ln(e){if(!e.current)return null;try{return JSON.parse(e.current.getValue())}catch{return null}}function un({title:e,viewCode:i,setViewCode:a}){return n(`div`,{className:`flex items-center gap-1 bg-muted mb-2 p-1 rounded`,children:[t(r,{variant:i?`ghost`:`primary`,size:`sm`,title:`Preview properties`,onClick:()=>a(!1),children:e}),t(r,{variant:i?`primary`:`ghost`,size:`sm`,title:`View in JSON format`,onClick:()=>a(!0),children:`JSON`})]})}function dn(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).replace(/\s+/g,` `).trim().replace(/^./,e=>e.toUpperCase())}function fn(r){return r==null?`Failed to query`:typeof r==`string`?r:Array.isArray(r)?r.length===0?`None`:r.some(e=>e&&typeof e==`object`)?t(e,{children:r.map((e,r)=>n(`div`,{className:`flex gap-1`,children:[n(`span`,{className:`text-xs align-top pe-2 font-medium`,children:[r+1,`:`]}),t(`span`,{className:`text-xs`,children:fn(e)})]},`item-${r}`))}):r.map(e=>String(e)).join(`, `):typeof r==`object`?t(e,{children:Object.entries(r).map(([e,r])=>n(`div`,{className:`flex gap-1`,children:[n(`span`,{className:`text-xs align-top pe-2 font-medium`,children:[dn(e),`:`]}),t(`span`,{className:`text-xs`,children:fn(r)})]},e))}):String(r)}function pn({data:e,className:r}){let i=e?Object.entries(e):[];return t(`table`,{className:r||`mb-2 text-xs bg-muted rounded-sm w-full`,children:t(`tbody`,{children:i.map(([e,r])=>n(`tr`,{className:`align-top hover:bg-background border-y`,children:[t(`td`,{className:`align-top pe-4 p-2`,children:dn(e)}),t(`td`,{className:`p-2`,children:fn(r)})]},e))})})}const mn=V(()=>({kind:`none`})),hn=mn.Provider;function gn(){return U(mn)}const _n={store:`document`,document:`document`,collection:`collection`,interaction:`interaction`,prompt:`prompt`,agent:`agent`,workflow:`workflow`,process:`process`,run:`interaction_run`};function vn(e){let t=e.indexOf(`:`);if(t<=0)return;let n=e.slice(0,t);if(!Object.hasOwn(_n,n))return;let r=e.slice(t+1).trim().replace(/^\/+/,``);if(r)return{type:_n[n],id:r}}function yn(...e){return Ve(O(e))}const bn=V(null);function xn(){return U(bn)}function Sn(e){return e.startsWith(`agents/`)||e.startsWith(`documents/`)}function Cn(e,t,n=`inline`){return`artifact:${e}:${t}:${n}`}function wn(e){return`file:${e}`}function Tn({error:e,chartTitle:r}){return t(`div`,{className:`flex items-center justify-center h-full bg-red-50 dark:bg-red-950 rounded-md p-4`,children:n(`div`,{className:`text-center`,children:[n(`p`,{className:`text-sm font-medium text-red-600 dark:text-red-400`,children:[`Cannot render `,r||`Vega-Lite`,` chart`]}),t(`p`,{className:`text-xs text-red-500 dark:text-red-500 mt-1 max-w-xs truncate`,children:e})]})})}function En({isOpen:e,onClose:i,title:a,description:o,children:s}){let{t:c}=J();return t(Le.Root,{open:e,onOpenChange:e=>!e&&i(),children:n(Le.Portal,{children:[t(Le.Overlay,{className:`fixed inset-0 z-50 bg-black/80 backdrop-blur-sm transition-all duration-300 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`}),n(Le.Content,{className:`fixed inset-2 sm:inset-4 z-50 flex flex-col bg-white dark:bg-gray-900 rounded-xl shadow-2xl transition-all duration-300 ease-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-98 data-[state=open]:zoom-in-98 data-[state=closed]:slide-out-to-bottom-2 data-[state=open]:slide-in-from-bottom-2`,onEscapeKeyDown:i,children:[t(Le.Close,{asChild:!0,children:t(r,{variant:`unstyled`,onClick:i,className:`absolute top-3 end-3 z-10 p-2 rounded-lg bg-white/80 dark:bg-gray-800/80 backdrop-blur-sm hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors duration-150 shadow-sm`,"aria-label":c(`agent.closeFullscreen`),children:t(we,{className:`w-5 h-5 text-gray-600 dark:text-gray-300`})})}),t(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6 animate-in fade-in-0 duration-500 delay-150`,children:s}),t(`div`,{className:`flex items-center justify-between px-4 sm:px-6 py-3 border-t border-gray-200 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-800/50 rounded-b-xl`,children:n(`div`,{className:`flex flex-col`,children:[t(Le.Title,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:a||c(`agent.dashboard`)}),o&&t(Le.Description,{className:`text-sm text-gray-500 dark:text-gray-400 mt-0.5`,children:o})]})})]})]})})}function Dn(e,t){if(t===`chart`)return 280;let n=1;if(e.vconcat)n=Array.isArray(e.vconcat)?e.vconcat.length:1;else if(e.concat){let t=e.columns||2,r=Array.isArray(e.concat)?e.concat.length:1;n=Math.ceil(r/t)}else e.facet&&(n=2);return Math.max(500,n*280+40)}const On={categorical:[`#6366f1`,`#8b5cf6`,`#ec4899`,`#f43f5e`,`#f97316`,`#eab308`,`#22c55e`,`#14b8a6`,`#06b6d4`,`#3b82f6`],blues:[`#dbeafe`,`#93c5fd`,`#3b82f6`,`#1d4ed8`,`#1e3a8a`],purples:[`#f3e8ff`,`#c4b5fd`,`#8b5cf6`,`#6d28d9`,`#4c1d95`],greens:[`#dcfce7`,`#86efac`,`#22c55e`,`#15803d`,`#14532d`],diverging:[`#ef4444`,`#fca5a5`,`#fef3c7`,`#86efac`,`#22c55e`]};function kn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function An(e){return kn(e)}function jn(e){let t=JSON.parse(JSON.stringify(e)),n=[`vconcat`,`hconcat`,`concat`];if(!n.some(e=>Array.isArray(t[e])))return t;let r=[];if(Array.isArray(t.params))for(let e of t.params)e&&typeof e==`object`&&e.name&&e.select&&r.push({name:e.name,param:e});if(r.length===0)return t;for(let{name:e,param:i}of r){let r=i.select?.fields||[],a=i.select?.bind===`legend`,o=null;for(let e of n)if(Array.isArray(t[e])){o=t[e];break}if(!o||o.length===0)continue;let s=0;for(let e=0;e<o.length;e++){let t=o[e];if(Nn(t,r)||a&&Pn(t,r)){s=e;break}}let c=o[s];c.params||=[],c.params.push(i),t.params=(t.params??[]).filter(t=>t.name!==e)}return Array.isArray(t.params)&&t.params.length===0&&delete t.params,t}function Mn(e,t){if(!t||Object.keys(t).length===0)return e;let n=JSON.parse(JSON.stringify(e)),r=e=>{for(let n of e)n.name&&n.name in t&&(n.value=t[n.name])};Array.isArray(n.params)&&r(n.params);let i=e=>{if(Array.isArray(e)){for(let t of e)if(Array.isArray(t.params)&&r(t.params),t.vconcat&&i(t.vconcat),t.hconcat&&i(t.hconcat),t.concat&&i(t.concat),Array.isArray(t.layer))for(let e of t.layer)Array.isArray(e.params)&&r(e.params)}};if(n.vconcat&&i(n.vconcat),n.hconcat&&i(n.hconcat),n.concat&&i(n.concat),Array.isArray(n.layer))for(let e of n.layer)e&&Array.isArray(e.params)&&r(e.params);return n}function Nn(e,t){if(!e?.encoding)return!1;for(let n of t)for(let t of Object.values(e.encoding))if(t.field===n)return!0;if(Array.isArray(e.layer)){for(let n of e.layer)if(Nn(n,t))return!0}return!1}function Pn(e,t){if(!e)return!1;let n=e=>{if(!e)return!1;let n=e.color?.field;return!!n&&t.includes(n)};if(n(e.encoding))return!0;if(Array.isArray(e.layer)){for(let t of e.layer)if(n(t.encoding))return!0}return!1}function Fn(e,t=[]){let n=[];if(!e||typeof e!=`object`)return n;if(e.data&&typeof e.data==`object`){let r=e.data.url;typeof r==`string`&&r.startsWith(`artifact:`)&&n.push({path:[...t,`data`],artifactPath:r.replace(/^artifact:/,``).trim()})}for(let r of[`layer`,`vconcat`,`hconcat`,`concat`,`spec`,`repeat`,`facet`])if(r in e){let i=e[r];Array.isArray(i)?i.forEach((e,i)=>{An(e)&&n.push(...Fn(e,[...t,r,String(i)]))}):An(i)&&n.push(...Fn(i,[...t,r]))}return n}function In(e,t){let n=JSON.parse(JSON.stringify(e));for(let[e,r]of t){let t=e.split(`.`),i=n;for(let e=0;e<t.length-1;e++){let n=i[t[e]];if(!kn(n))break;i=n}let a=t[t.length-1],o=i[a];kn(o)&&(delete o.url,o.values=r)}return n}function Ln(e){let t={background:`transparent`,view:{stroke:`transparent`},range:{category:On.categorical,diverging:On.diverging,heatmap:On.purples,ramp:On.blues},mark:{tooltip:!0},bar:{tooltip:!0,cornerRadiusTopLeft:4,cornerRadiusTopRight:4},line:{tooltip:!0,strokeWidth:2.5,strokeCap:`round`},point:{tooltip:!0,size:60,filled:!0},area:{tooltip:!0,fillOpacity:.7,line:!0},rect:{tooltip:!0,cornerRadius:2},arc:{tooltip:!0,cornerRadius:4},circle:{tooltip:!0,size:80}};return e?{...t,axis:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,gridColor:`#3f3f46`,domainColor:`#52525b`,tickColor:`#52525b`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#a1a1aa`,titleColor:`#e4e4e7`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#fafafa`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}:{...t,axis:{labelColor:`#71717a`,titleColor:`#3f3f46`,gridColor:`#e4e4e7`,domainColor:`#d4d4d8`,tickColor:`#d4d4d8`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,titleFontWeight:500},legend:{labelColor:`#71717a`,titleColor:`#3f3f46`,labelFont:`Inter, system-ui, sans-serif`,titleFont:`Inter, system-ui, sans-serif`,labelFontSize:11,titleFontSize:12,symbolSize:100},title:{color:`#18181b`,font:`Inter, system-ui, sans-serif`,fontSize:14,fontWeight:600}}}const Rn=Oe(function({spec:i,artifactRunId:a}){let{t:o}=J(),{title:s,description:c,options:l}=i,u=i.spec,[d,f]=q(!1),[p,m]=q(!1),[h,g]=q(null),[_,v]=q(!1),y=K(null),ee=K(null),b=K(null),{client:x}=Re(),S=xn(),te=K(x);te.current=x;let C=K(S);C.current=S;let[w,T]=q(null),[E,D]=q(!1),[O,k]=q(null),A=l?.mode||`chart`,j=A===`dashboard`,M=l?.enableFullscreen??j,N=l?.height||Dn(u,A);W(()=>{let e=Fn(u);if(e.length===0){T(u),D(!1),k(null);return}a?console.info(`[VegaLiteChart] resolving artifacts with runId:`,a,e.map(e=>e.artifactPath)):console.warn(`[VegaLiteChart] artifact references found but artifactRunId is missing!`,{references:e.map(e=>e.artifactPath),artifactRunId:a});let t=!1;return D(!0),k(null),(async()=>{let n=new Map,r=te.current,i=C.current;for(let o of e)try{let e=o.path.join(`.`),t;if(a&&!Sn(o.artifactPath)){let e=Cn(a,o.artifactPath,`inline`);t=i?await i.getOrFetch(e,async()=>(await r.files.getArtifactDownloadUrl(a,o.artifactPath,`inline`)).url):(await r.files.getArtifactDownloadUrl(a,o.artifactPath,`inline`)).url}else{let e=wn(o.artifactPath);t=i?await i.getOrFetch(e,async()=>(await r.files.getDownloadUrl(o.artifactPath)).url):(await r.files.getDownloadUrl(o.artifactPath)).url}let s=await fetch(t);if(!s.ok)throw Error(`Failed to fetch artifact data: ${s.statusText}`);let c=o.artifactPath.toLowerCase().endsWith(`.csv`),l;if(c){let e=await s.text();l=ze.parse(e,{header:!0,skipEmptyLines:!0,dynamicTyping:!0}).data}else{let e=await s.json();l=Array.isArray(e)?e:[e]}n.set(e,l)}catch(e){console.error(`Failed to resolve artifact: ${o.artifactPath}`,e),t||k(`Failed to load data from artifact: ${o.artifactPath}`);return}if(!t){let e=In(u,n);T(e),D(!1)}})(),()=>{t=!0}},[u,a]);let[re,ie]=q(!1),ae=K(!1);W(()=>{let e=()=>{let e=document.documentElement.classList.contains(`dark`);e!==ae.current&&(ae.current=e,ie(e))};e();let t=new MutationObserver(e);return t.observe(document.documentElement,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let[ce,le]=q(0),ue=K(0);W(()=>{if(!b.current)return;let e,t=new ResizeObserver(t=>{clearTimeout(e),e=setTimeout(()=>{let e=t[0]?.contentRect.width;e&&e!==ue.current&&(ue.current=e,le(e))},100)});t.observe(b.current);let n=b.current.clientWidth;return ue.current=n,le(n),()=>{clearTimeout(e),t.disconnect()}},[]);let de=G(()=>Fn(u).length>0,[u]),P=G(()=>{if(de&&!w)return null;let e=w||u;return e?(l?.parameterValues&&(e=Mn(e,l.parameterValues)),jn(e)):null},[w,u,de,l?.parameterValues]),fe=H((e,t)=>{if(!e||typeof e!=`object`)return e;if(e.hconcat&&Array.isArray(e.hconcat)){let n=e.hconcat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,hconcat:e.hconcat.map(e=>fe(e,i))}}if(e.vconcat&&Array.isArray(e.vconcat))return{...e,vconcat:e.vconcat.map(e=>fe(e,t))};if(e.concat&&Array.isArray(e.concat)){let n=e.columns??e.concat.length,r=(e.spacing??10)*(n-1),i=Math.floor((t-r)/n);return{...e,concat:e.concat.map(e=>fe(e,i))}}let n=e.width;return n===`container`||typeof n==`number`&&n>t?{...e,width:t}:e},[]),pe=H((e,t=!1)=>{if(!P)return null;let n=Ln(re),r=t?typeof window<`u`?Math.min(window.innerWidth-80,1400):1200:ce>0?ce-24:500,i=`vconcat`in P||`hconcat`in P||`concat`in P,a=i?{type:`pad`,contains:`padding`}:{type:`fit`,contains:`padding`},o=P;i&&r&&(o=fe(P,r));let c=o.width,l=i?void 0:c===`container`?r:c??r,{width:u,...d}=o;return{$schema:`https://vega.github.io/schema/vega-lite/v6.json`,...!i&&l?{width:l}:{},height:t?void 0:e,autosize:a,...i?o:d,...s&&!P.title?{title:s}:{},config:{...n,...P.config}}},[P,s,re,ce,fe]),me=H(async()=>{let e=_?ee.current:y.current;if(!(!e||p))try{(await e.toCanvas(2)).toBlob(async e=>{e&&(await navigator.clipboard.write([new ClipboardItem({"image/png":e})]),m(!0),setTimeout(()=>m(!1),2e3))},`image/png`)}catch(e){console.error(`Failed to copy chart:`,e)}},[p,_]),_e=H(async()=>{let e=_?ee.current:y.current;if(!(!e||d)){f(!0);try{let t=await e.toImageURL(`png`,2),n=document.createElement(`a`);n.download=`${s||`chart`}.png`,n.href=t,n.click()}catch(e){console.error(`Failed to export chart:`,e)}finally{f(!1)}}},[s,d,_]),ye=H(e=>{y.current=e,g(null)},[]),be=H(e=>{ee.current=e},[]),xe=H(e=>{console.error(`Vega-Lite rendering error:`,e),g(e instanceof Error?e.message:`Unknown error`)},[]),F=H(()=>{v(e=>!e)},[]);W(()=>{g(null)},[u]);let I=({className:e})=>n(`div`,{className:yn(`flex items-center gap-2`,e),children:[n(r,{variant:`unstyled`,onClick:me,disabled:p,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 flex items-center gap-1`,title:o(`agent.copyToClipboard`),children:[t(p?ne:oe,{className:`w-3 h-3`}),o(p?`agent.copied`:`agent.copy`)]}),n(r,{variant:`unstyled`,onClick:_e,disabled:d,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-1`,title:o(`agent.exportAsPng`),children:[t(se,{className:`w-3 h-3`}),o(d?`agent.exporting`:`agent.export`)]}),M&&n(r,{variant:`unstyled`,onClick:F,className:`text-xs px-2 py-1 rounded border border-gray-300 dark:border-gray-700 bg-gray-100 dark:bg-gray-800 text-gray-700 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 cursor-pointer transition-colors flex items-center gap-1`,title:o(_?`agent.exitFullscreen`:`agent.fullscreen`),children:[t(_?ve:ge,{className:`w-3 h-3`}),o(_?`agent.exit`:`agent.fullscreen`)]})]});if(E||de&&!w)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{className:`flex items-center justify-center bg-gray-50 dark:bg-gray-800 rounded`,style:{width:`100%`,height:N},children:n(`div`,{className:`flex items-center gap-2 text-gray-500 dark:text-gray-400`,children:[t(he,{className:`w-5 h-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading data from artifacts...`})]})})]})});if(O)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:N},children:t(Tn,{error:O,chartTitle:s})})]})});if(h)return t(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[t(`div`,{className:`flex items-center justify-between`,children:t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||`Chart`})}),t(`div`,{style:{width:`100%`,height:N},children:t(Tn,{error:h,chartTitle:s})})]})});let L=pe(N),R=pe(0,!0);return L?(typeof window<`u`&&localStorage.getItem(`DEBUG_VEGA_RENDERS`)&&console.log(`VegaLite rendering with spec:`,{title:s,hasData:!!L.data?.values,dataLength:L.data?.values?.length}),n(e,{children:[t(`div`,{className:yn(`bg-white dark:bg-gray-900 rounded-lg border border-gray-200 dark:border-gray-800 shadow-sm`,j&&`border-2`),children:n(`div`,{className:`flex flex-col gap-2 p-3`,children:[n(`div`,{className:`flex items-center justify-between`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`font-medium text-sm text-gray-900 dark:text-gray-100`,children:s||(j?`Dashboard`:`Chart`)}),j&&t(`span`,{className:`text-xs px-2 py-0.5 rounded-full bg-indigo-100 dark:bg-indigo-900 text-indigo-700 dark:text-indigo-300`,children:`Interactive`})]}),t(I,{})]}),c&&t(`span`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c}),t(`div`,{ref:b,className:`bg-white dark:bg-gray-900 rounded overflow-hidden`,style:{width:`100%`,height:N,minWidth:0},children:t(Be,{spec:L,onEmbed:e=>ye(e.view),onError:xe,options:{renderer:l?.renderer||`canvas`,actions:!1}})})]})}),n(En,{isOpen:_,onClose:()=>v(!1),title:s||(j?`Dashboard`:`Chart`),description:c,children:[t(`div`,{className:`w-full h-full min-h-[calc(100vh-200px)]`,children:R&&t(Be,{spec:R,onEmbed:e=>be(e.view),onError:xe,options:{renderer:l?.renderer||`canvas`,actions:!1}})}),t(`div`,{className:`absolute bottom-6 end-6`,children:t(I,{className:`bg-white dark:bg-gray-800 rounded-lg shadow-lg p-2 border border-gray-200 dark:border-gray-700`})})]})]})):null},(e,t)=>JSON.stringify(e.spec)===JSON.stringify(t.spec)&&e.artifactRunId===t.artifactRunId),zn=B.createContext({});function Bn({children:e,artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}){let o=G(()=>({artifactRunId:n,onProposalSelect:r,onProposalSubmit:i,MarkdownRenderer:a}),[n,r,i,a]);return t(zn.Provider,{value:o,children:e})}function Vn(){return B.useContext(zn)}const Hn={chart:{icon:j,label:`chart`,defaultHeight:200},mermaid:{icon:le,label:`diagram`,defaultHeight:150},proposal:{icon:_e,label:`options`,defaultHeight:100},code:{icon:ie,label:`code`,defaultHeight:80},image:{icon:P,label:`image`,defaultHeight:150},link:{icon:pe,label:`link`,defaultHeight:24},expand:{icon:se,label:`content`,defaultHeight:100},table:{icon:R,label:`table`,defaultHeight:150},markdown:{icon:ce,label:`content`,defaultHeight:100},"fusion-fragment":{icon:ie,label:`fragment`,defaultHeight:150}};function X({type:e,error:i,onRetry:a,message:o,height:s}){let c=Hn[e],l=s??c.defaultHeight,u=e===`link`;if(i)return n(`div`,{className:`flex items-center gap-2 rounded border border-destructive/30 bg-destructive/5 text-destructive ${u?`inline-flex px-2 py-1 text-sm`:`p-4`}`,style:u?void 0:{minHeight:l},children:[n(`span`,{className:`text-destructive`,children:[`Failed to load `,c.label]}),a&&t(r,{variant:`unstyled`,onClick:a,className:`ms-2 rounded bg-destructive/10 px-2 py-1 text-xs hover:bg-destructive/20 transition-colors text-destructive`,children:`Retry`})]});let d=c.icon;return u?n(`span`,{className:`inline-flex items-center gap-1 text-muted animate-pulse`,children:[t(d,{className:`h-3 w-3`}),t(`span`,{children:o||`Loading ${c.label}...`})]}):n(`div`,{className:`flex flex-col items-center justify-center gap-3 rounded border border-border bg-muted/30 animate-pulse`,style:{minHeight:l},children:[t(d,{className:`h-8 w-8 text-muted`}),t(`span`,{className:`text-sm text-muted`,children:o||`Loading ${c.label}...`}),t(`div`,{className:`flex gap-1`,children:[...[,,,]].map((e,n)=>t(`div`,{className:`h-2 w-2 rounded-full bg-muted animate-bounce`,style:{animationDelay:`${n*150}ms`}},`dot-${n}`))})]})}var Z=class extends B.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`CodeBlock rendering error (${this.props.type}):`,e,t),this.props.onError?.(e)}handleRetry=()=>{this.setState({hasError:!1,error:void 0})};render(){if(this.state.hasError){let{type:e,fallbackCode:r}=this.props;return n(`div`,{className:`space-y-2`,children:[t(X,{type:e,error:this.state.error?.message||`Rendering failed`,onRetry:this.handleRetry}),r&&n(`details`,{className:`text-sm`,children:[t(`summary`,{className:`cursor-pointer text-muted hover:text-foreground`,children:`Show raw content`}),t(`pre`,{className:`mt-2 overflow-x-auto rounded bg-muted/50 p-2 text-xs`,children:t(`code`,{children:r})})]})]})}return this.props.children}};function Un(e,t,n){let r=t.split(`.`).pop()?.toLowerCase();if(r===`svg`)return`mockup`;if([`png`,`jpg`,`jpeg`,`gif`,`webp`].includes(r||``))return`image`;if(r===`md`)return`markdown`;if(r===`csv`)return`table`;if(n===`json`&&typeof e==`object`&&e){let t=e;if(typeof t.$schema==`string`&&t.$schema.includes(`vega`)||t.library===`vega-lite`&&`spec`in t)return`vega-lite`;if(`template`in t&&`data`in t)return`fusion-fragment`;if(Array.isArray(e)&&e.length>0&&typeof e[0]==`object`)return`table`}return`code`}function Wn(e){if(typeof e!=`object`||!e)return null;let t=e;return t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`&&t.spec!==null?t:typeof t.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}function Gn({content:e}){let{headers:r,rows:i}=G(()=>{if(!Array.isArray(e)||e.length===0)return{headers:[],rows:[]};let t=e[0];if(typeof t!=`object`||!t)return{headers:[],rows:[]};let n=Object.keys(t);return{headers:n,rows:e.map(e=>n.map(t=>{let n=e[t];return n==null?``:typeof n==`object`?JSON.stringify(n):String(n)}))}},[e]);return r.length===0?t(X,{type:`table`,error:`No table data found`}):n(`div`,{className:`overflow-x-auto`,children:[n(`table`,{className:`min-w-full text-sm border-collapse`,children:[t(`thead`,{children:t(`tr`,{className:`border-b`,children:r.map(e=>t(`th`,{className:`px-3 py-2 text-start font-medium text-muted`,children:e},e))})}),t(`tbody`,{children:i.slice(0,100).map((e,n)=>t(`tr`,{className:`border-b border-muted/20`,children:e.map((e,n)=>t(`td`,{className:`px-3 py-2`,children:e},`cell-${n}`))},`row-${n}`))})]}),i.length>100&&n(`div`,{className:`text-sm text-muted py-2`,children:[`Showing 100 of `,i.length,` rows`]})]})}function Kn({content:e,path:n}){let r=n.split(`.`).pop()?.toLowerCase()||``,i=typeof e==`string`?e:JSON.stringify(e,null,2);return t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{className:`language-${r}`,children:i})})}function qn(e){return Ie.sanitize(e,{USE_PROFILES:{svg:!0,svgFilters:!0},ADD_TAGS:[`use`],FORBID_TAGS:[`foreignObject`]})}function Jn(e){return e.replace(/<svg([^>]*)>/i,(e,t)=>{let n=t;if(!/viewBox/i.test(n)){let e=/\swidth\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n),t=/\sheight\s*=\s*["']?(\d+(?:\.\d+)?)/i.exec(n);e&&t&&(n+=` viewBox="0 0 ${e[1]} ${t[1]}"`)}return n=n.replace(/\swidth\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``).replace(/\sheight\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/i,``),/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}function Yn({content:e}){let n=G(()=>{let t=typeof e==`string`?e.trim():``;return t?Jn(qn(t)):null},[e]);return n?t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}}):t(X,{type:`expand`,error:`Empty mockup`})}function Xn({content:e,path:n}){return t(`img`,{src:typeof e==`string`?e:``,alt:n.split(`/`).pop()||`Artifact image`,className:`max-w-full h-auto rounded`,loading:`lazy`})}function Zn({content:e,renderType:n,path:r,runId:i,contentType:a}){let{MarkdownRenderer:o}=Vn();switch(G(()=>n===`auto`?Un(e,r,a):n,[e,r,a,n])){case`chart`:{let n=Wn(e);return n?t(Z,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(Rn,{spec:n,artifactRunId:i})}):t(X,{type:`chart`,error:`Only Vega-Lite charts are supported. Recharts rendering has been retired.`})}case`vega-lite`:{let n=Wn(e);return n?t(Z,{type:`chart`,fallbackCode:JSON.stringify(e,null,2),children:t(Rn,{spec:n,artifactRunId:i})}):t(X,{type:`chart`,error:`Invalid Vega-Lite specification`})}case`fusion-fragment`:{let n=e;return console.log(`[ArtifactContentRenderer] fusion-fragment:`,{hasTemplate:!!n.template,hasData:!!n.data,runId:i,hasVegaLiteChart:!!Rn}),n.template&&n.data?t(Z,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(Fe,{data:n.data,ChartComponent:Rn,artifactRunId:i,children:t(Pe,{code:JSON.stringify(n.template),data:n.data})})}):t(Z,{type:`fusion-fragment`,fallbackCode:JSON.stringify(e,null,2),children:t(Pe,{code:JSON.stringify(e)})})}case`table`:return t(Z,{type:`table`,fallbackCode:JSON.stringify(e,null,2),children:t(Gn,{content:e})});case`markdown`:{let n=typeof e==`string`?e:String(e);return t(Z,{type:`markdown`,fallbackCode:n,children:o?t(o,{artifactRunId:i,children:n}):t(`pre`,{className:`overflow-x-auto p-3 bg-muted/10 rounded text-sm`,children:t(`code`,{children:n})})})}case`mockup`:return t(Z,{type:`expand`,fallbackCode:typeof e==`string`?e:r,children:t(Yn,{content:e})});case`image`:return t(Z,{type:`image`,fallbackCode:r,children:t(Xn,{content:e,path:r})});default:return t(Kn,{content:e,path:r})}}var Qn=class{components={};registerComponent(e,t){this.components[e]=t}getComponent(e){return this.components[e]}};const $n=V(null);function er({components:e,children:n}){let r=G(()=>{let t=new Qn;for(let[n,r]of Object.entries(e))t.registerComponent(n,r);return t},[e]);return t($n.Provider,{value:r,children:n})}function tr(){return U($n)}function nr(e){let t=U($n);if(t)return t.getComponent(e)}const rr=`Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif`;function ir(e){let t=e.trim(),n=``,r=!1,i=!1;for(let e=0;e<t.length;e++){let a=t[e],o=e>0?t[e-1]:``;if(a===`"`&&!i&&o!==`\\`){r=!r,n+=a;continue}if(a===`'`&&!r&&o!==`\\`){i=!i,n+=a;continue}if((r||i)&&a===`\\`){let r=e;for(;t[r]===`\\`;)r++;if(t[r]===`n`){n+=`<br/>`,e=r;continue}}n+=a}return n}function ar(e){return e.replace(/<svg([^<>]*)>/i,(e,t)=>{let n=t.replace(/\swidth="[^"]*"/i,``).replace(/\sheight="[^"]*"/i,``);return/style="/i.test(n)?n=n.replace(/style="([^"]*)"/i,(e,t)=>`style="${t};width:100%;height:auto;display:block;max-width:100%;"`):n+=` style="width:100%;height:auto;display:block;max-width:100%;"`,/preserveAspectRatio=/i.test(n)||(n+=` preserveAspectRatio="xMidYMid meet"`),`<svg${n}>`})}et.initialize({startOnLoad:!1,theme:`default`,securityLevel:`loose`,fontFamily:rr,suppressErrorRendering:!0,flowchart:{htmlLabels:!0,useMaxWidth:!0,nodeSpacing:40,rankSpacing:50,padding:12},sequence:{useMaxWidth:!0},themeVariables:{fontFamily:rr}});function or({code:e,className:n}){let r=K(null),[i,a]=q(null),[o,s]=q(null),c=ke().replace(/:/g,`_`);return W(()=>{let t=!1;return(async()=>{if(!e.trim()){a(null),s(null);return}try{s(null);let n=`mermaid-${c}-${Date.now()}`,r=ir(e),{svg:i}=await et.render(n,r),o=ar(i);t||a(o)}catch(e){if(!t){let t=e instanceof Error?e.message:`Failed to render mermaid diagram`;s(t),a(null)}}})(),()=>{t=!0}},[e,c]),o?null:i?t(`div`,{ref:r,className:`my-4 w-full overflow-x-auto [&_svg]:mx-auto [&_svg]:w-full [&_svg]:h-auto [&_svg]:max-w-full ${n||``}`,dangerouslySetInnerHTML:{__html:i}}):t(`div`,{className:`my-4 p-4 bg-gray-50 dark:bg-gray-800 rounded-lg animate-pulse ${n||``}`,children:t(`div`,{className:`h-32 bg-gray-200 dark:bg-gray-700 rounded`})})}function sr(e){switch(e.split(`.`).pop()?.toLowerCase()){case`json`:return`json`;case`md`:case`txt`:case`csv`:case`yaml`:case`yml`:return`text`;case`png`:case`jpg`:case`jpeg`:case`gif`:case`webp`:case`pdf`:return`binary`;default:return`text`}}function cr({runId:e,path:t,parseJson:n=!0}){let{client:r}=Re(),i=xn(),a=K(r);a.current=r;let o=K(i);o.current=i;let[s,c]=q({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l=H(async()=>{if(!e){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No run ID provided`,contentType:void 0});return}if(!t){c({data:void 0,rawContent:void 0,isLoading:!1,error:`No artifact path provided`,contentType:void 0});return}c(e=>({...e,isLoading:!0,error:void 0}));let r=a.current,i=o.current,s=sr(t);try{let a=Cn(e,t,`inline`),o;o=i?await i.getOrFetch(a,async()=>(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url):(await r.files.getArtifactDownloadUrl(e,t,`inline`)).url;let l=await fetch(o);if(!l.ok)throw Error(`Failed to fetch artifact: ${l.status} ${l.statusText}`);if(s===`binary`){c({data:o,rawContent:void 0,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)});return}let u=await l.text(),d;if(n&&s===`json`)try{d=JSON.parse(u)}catch{d=u}else d=u;c({data:d,rawContent:u,isLoading:!1,error:void 0,contentType:s,etag:l.headers.get(`etag`)?.replace(/^"(.*)"$/,`$1`)})}catch(e){let n=e instanceof Error?e.message:`Failed to fetch artifact`;console.error(`Failed to fetch artifact content:`,t,e),c({data:void 0,rawContent:void 0,isLoading:!1,error:n,contentType:s})}},[e,t,n]);W(()=>{l()},[l]);let u=H(()=>{c({data:void 0,rawContent:void 0,isLoading:!0,error:void 0,contentType:void 0}),l()},[l]);return{data:s.data,rawContent:s.rawContent,isLoading:s.isLoading,error:s.error,contentType:s.contentType,etag:s.etag,retry:u}}function lr(e){let t=e.trim();if(t.length<2)return!0;if(!t.startsWith(`{`))return!1;try{return JSON.parse(t),!1}catch(e){let n=e instanceof Error?e.message:``,r=[`unexpected end`,`unterminated string`,`expected`,`unexpected token`],i=n.toLowerCase();if(r.some(e=>i.includes(e))){let e=0,n=0,r=!1,i=!1;for(let a of t){if(i){i=!1;continue}if(a===`\\`){i=!0;continue}if(a===`"`){r=!r;continue}r||(a===`{`?e++:a===`}`?e--:a===`[`?n++:a===`]`&&n--)}return e>0||n>0||r}return!1}}function ur(e){try{let t=e.trim(),n=t.indexOf(`{`),r=t.lastIndexOf(`}`);return n!==-1&&r>n&&(t=t.slice(n,r+1)),JSON.parse(t)}catch{return null}}function dr(e){let t=typeof e.$schema==`string`&&e.$schema.includes(`vega`),n=e.library===`vega-lite`&&`spec`in e;return t||n?`vega-lite`:null}function fr({code:e}){let{artifactRunId:n}=Vn();n||console.warn(`[VegaLiteCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=G(()=>lr(e),[e]),i=G(()=>{if(r)return null;let t=ur(e);return t?{library:`vega-lite`,spec:t}:null},[e,r]);return r?t(X,{type:`chart`,message:`Loading chart...`}):i?t(Z,{type:`chart`,fallbackCode:e,children:t(Rn,{spec:i,artifactRunId:n})}):t(X,{type:`chart`,error:`Invalid Vega-Lite specification`})}function pr({code:e}){let{artifactRunId:n}=Vn();n||console.warn(`[ChartCodeBlockHandler] artifactRunId is missing from CodeBlockContext`);let r=G(()=>lr(e),[e]),i=G(()=>{if(r)return null;let t=ur(e);return!t||!dr(t)?null:t.library===`vega-lite`&&`spec`in t&&typeof t.spec==`object`?t:{library:`vega-lite`,spec:t}},[e,r]);return r?t(X,{type:`chart`,message:`Loading chart...`}):i?t(Z,{type:`chart`,fallbackCode:e,children:t(Rn,{spec:i,artifactRunId:n})}):t(X,{type:`chart`,error:`Invalid Vega-Lite chart specification`})}function mr({code:e}){let n=e.trim();return n?t(Z,{type:`mermaid`,fallbackCode:e,children:t(or,{code:n})}):t(X,{type:`mermaid`,error:`Empty diagram`})}function hr({code:e}){let n=G(()=>{let t=e.trim();return t?Jn(qn(t)):null},[e]);return n?t(Z,{type:`code`,fallbackCode:e,children:t(`div`,{style:{margin:`16px 0`,width:`100%`,overflowX:`auto`},dangerouslySetInnerHTML:{__html:n}})}):t(X,{type:`code`,error:`Empty mockup`})}function gr({code:e,language:n}){let{artifactRunId:r}=Vn(),i=e.trim(),a=G(()=>{if(!n?.includes(`:`))return`auto`;let e=n.split(`:`)[1];return[`chart`,`vega-lite`,`table`,`markdown`,`fusion-fragment`,`mockup`,`code`,`image`,`auto`].includes(e)?e:`auto`},[n]),{data:o,isLoading:s,error:c,contentType:l}=cr({runId:r,path:i});return r?s?t(X,{type:`expand`,message:`Loading ${i}...`}):c?t(X,{type:`expand`,error:`Failed to load artifact: ${c}`}):o===void 0?t(X,{type:`expand`,error:`No content found in artifact`}):t(Zn,{content:o,renderType:a,path:i,runId:r,contentType:l}):t(X,{type:`expand`,error:`No artifact run ID available`})}function _r(e){return e?.startsWith(`expand`)??!1}function vr(){return{chart:pr,"vega-lite":fr,vegalite:fr,mermaid:mr,mockup:hr,svg:hr}}const yr=new Set([`store`,`document`,`collection`,`interaction`,`prompt`,`agent`,`workflow`,`process`,`run`]);function br(e){return e.trim().replace(/^\/+/,``)}function xr(e){if(e.startsWith(`artifact:`))return{scheme:`artifact`,path:e.slice(9).trim()};if(e.startsWith(`image:`))return{scheme:`image`,path:e.slice(6).trim()};let t=e.indexOf(`:`);if(t>0){let n=e.slice(0,t);if(yr.has(n))return{scheme:n,path:br(e.slice(t+1))}}return{scheme:`standard`,path:e}}function Sr({rawUrl:e,artifactRunId:t,disposition:n=`inline`}){let{client:r}=Re(),i=xn(),a=K(r);a.current=r;let o=K(i);o.current=i;let{scheme:s,path:c}=xr(e),[l,u]=q(()=>{if(s===`standard`)return{url:e,isLoading:!1,error:void 0};if(i&&(s===`artifact`||s===`image`)){let e;e=s===`artifact`&&t&&!Sn(c)?Cn(t,c,n):wn(c);let r=i.getUrl(e);if(r)return{url:r,isLoading:!1,error:void 0}}return{url:void 0,isLoading:!0,error:void 0}}),d=H(async()=>{if(s===`standard`)return;if(s!==`artifact`&&s!==`image`){u({url:void 0,isLoading:!1,error:`Unknown scheme: ${s}`});return}u(e=>({...e,isLoading:!0,error:void 0}));let e=a.current,r=o.current;try{let i;if(s===`artifact`)if(t&&!Sn(c)){let a=Cn(t,c,n);i=r?await r.getOrFetch(a,async()=>(await e.files.getArtifactDownloadUrl(t,c,n)).url):(await e.files.getArtifactDownloadUrl(t,c,n)).url}else{let t=wn(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}else{let t=wn(c);i=r?await r.getOrFetch(t,async()=>(await e.files.getDownloadUrl(c)).url):(await e.files.getDownloadUrl(c)).url}u({url:i,isLoading:!1,error:void 0})}catch(e){let t=e instanceof Error?e.message:`Failed to resolve URL`;console.error(`Failed to resolve URL:`,c,e),u({url:void 0,isLoading:!1,error:t})}},[s,c,t,n]);W(()=>{if(l.url&&!l.error)return;let e=!1;return e||(async()=>{await d()})(),()=>{e=!0}},[d,l.url,l.error]);let f=H(()=>{u({url:void 0,isLoading:!0,error:void 0}),d()},[d]);return{url:l.url,isLoading:l.isLoading,error:l.error,scheme:s,retry:f}}function Cr({src:e,alt:r,caption:i,className:a,artifactRunId:o}){let s=e||``,{scheme:c}=xr(s);return c===`standard`?n(`figure`,{className:`my-4`,children:[t(`img`,{src:e,alt:r,className:a}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):t(wr,{rawSrc:s,alt:r,caption:i,artifactRunId:o,className:a})}function wr({rawSrc:e,alt:r,caption:i,artifactRunId:a,className:o}){let{url:s,isLoading:c,error:l,retry:u}=Sr({rawUrl:e,artifactRunId:a,disposition:`inline`});return c?t(X,{type:`image`,message:r?`Loading ${r}...`:void 0}):l?t(X,{type:`image`,error:l,onRetry:u}):s?n(`figure`,{className:`my-4`,children:[t(`img`,{src:s,alt:r,className:o}),t(`figcaption`,{className:`mt-2 text-sm text-muted text-center italic`,children:i})]}):null}function Tr({node:e,src:n,alt:r,className:i,artifactRunId:a,ExistingImg:o,...s}){let c=n||``,{scheme:l}=xr(c);return l===`standard`?typeof o==`function`?t(o,{node:e,src:n,alt:r,...s}):t(`img`,{src:n,alt:r,className:i,...s}):t(Er,{rawSrc:c,alt:r,artifactRunId:a,className:i,rest:s})}function Er({rawSrc:e,alt:n,artifactRunId:r,className:i,rest:a}){let{url:o,isLoading:s,error:c,retry:l}=Sr({rawUrl:e,artifactRunId:r,disposition:`inline`});return s?t(X,{type:`image`,message:n?`Loading ${n}...`:void 0}):c?t(X,{type:`image`,error:c,onRetry:l}):o?t(`img`,{src:o,alt:n,className:i,...a}):null}function Dr({node:e,href:n,children:r,className:i,artifactRunId:a,onArtifactOpen:o,ExistingLink:s,...c}){let l=n||``,u=vn(l);if(u)return t(Or,{resource:u,rawHref:l,artifactRunId:a,className:i,ExistingLink:s,rest:c,children:r});let{scheme:d,path:f}=xr(l);return d===`standard`?typeof s==`function`?t(s,{node:e,href:n,className:i,...c,children:r}):t(`a`,{href:n,...c,className:i,target:`_blank`,rel:`noopener noreferrer`,children:r}):t(kr,{rawHref:l,artifactRunId:a,artifactPath:d===`artifact`?f:void 0,onArtifactOpen:o,className:i,rest:c,children:r})}function Or({resource:e,rawHref:n,artifactRunId:i,className:a,children:o,ExistingLink:s,rest:c}){let l=gn()(e,{workflowRunId:i,source:`markdown`,rawHref:n});return l.kind===`navigate`?typeof s==`function`?t(s,{href:l.href,className:a,...c,children:o}):t(`a`,{href:l.href,...c,className:a,target:`_blank`,rel:`noopener noreferrer`,children:o}):l.kind===`activate`?t(r,{variant:`link`,size:`none`,className:a,onClick:l.onActivate,children:o}):t(`span`,{className:a,children:o})}function kr({rawHref:e,artifactRunId:n,artifactPath:r,onArtifactOpen:i,className:a,children:o,rest:s}){let{url:c,isLoading:l,error:u,retry:d}=Sr({rawUrl:e,artifactRunId:n,disposition:`attachment`});return l?t(`span`,{className:`inline-flex items-center gap-1 text-muted`,children:t(X,{type:`link`})}):u?t(`span`,{className:`inline-flex items-center gap-1`,children:t(X,{type:`link`,error:u,onRetry:d})}):t(`a`,{href:c||`#`,...s,className:a,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>{r&&/\.md$/i.test(r)&&i&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&e.button===0&&(e.preventDefault(),i(r))},children:o})}const Ar=[`artifact:`,`image:`,`store:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`],jr=/(!?\[[^[\]\n]*\]\()((?:artifact:|image:|store:|document:\/\/|collection:|interaction:|prompt:|agent:|workflow:|process:|run:)[^)[\n]+)(\))/g,Mr=/`[^`\n]*`/g,Nr=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,Pr=/\s+("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\([^)]*\))\s*$/;function Fr(e){return Ar.some(t=>e.startsWith(t))}function Ir(e){let t=e.trim();if(t.startsWith(`<`)){let n=t.indexOf(`>`);if(n>0&&Fr(t.slice(1,n).trim()))return e}let n=t.match(Pr)?.index??-1,r=(n>=0?t.slice(0,n):t).trim(),i=n>=0?t.slice(n):``;return Fr(r)?`<${r}>${i}`:e}function Lr(e){return e.replace(jr,(e,t,n,r)=>`${t}${Ir(n)}${r}`)}function Rr(e){let t=``,n=0;for(let r of e.matchAll(Mr))t+=Lr(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=Lr(e.slice(n)),t}function zr(e){if(!e||!Ar.some(t=>e.includes(t)))return e;let t=``,n=0;for(let r of e.matchAll(Nr))t+=Rr(e.slice(n,r.index)),t+=r[0],n=r.index+r[0].length;return t+=Rr(e.slice(n)),t}const Br=/^([ \t]*):::([^\n]*?):::[ \t]*$/gm,Vr=/^\w+/;function Hr(e){return e?.includes(`:::`)?e.replace(Br,(e,t,n)=>{let r=n.trim(),i=Vr.exec(r);if(!i)return e;let a=i[0],o=r.slice(a.length).trim();return o?`${t}:::${a}\n${t}${o}\n${t}:::`:`${t}::${a}`}):e}const Ur=/(^|\n)(`{3,}|~{3,})[^\n]*\n[\s\S]*?\n\2(?=\n|$)/g,Wr=/`[^`\n]*`/g,Gr=/\\\$/g,Kr=/\\[^\s]/,qr=/[{}]/,Jr=/[_^][\w{]/,Yr=/^[a-zA-Z]$/,Xr=/^[a-zA-Z]\s*=/,Zr=/^\s/,Qr=/\s$/,$r=/[+*/-]$/,ei=/\^[+-]$/;function ti(e){return Kr.test(e)||qr.test(e)||Jr.test(e)||Yr.test(e)||Xr.test(e)}function ni(e){return!!(Zr.test(e)||Qr.test(e)||$r.test(e)&&!ei.test(e))}function ri(e){let t=[];for(let n=0;n<e.length;n++)if(e[n]===`$`&&!(n>0&&e[n-1]===`\\`)){if(n+1<e.length&&e[n+1]===`$`){n++;continue}n>0&&e[n-1]===`$`&&(n<2||e[n-2]!==`\\`)||t.push(n)}return t}function ii(e,t,n){let r=e.slice(t+1,n);return r.length===0||r.includes(`
6
+ `)?null:r}function ai(e){let t=ri(e);if(t.length<2)return e;let n=new Set,r=new Set,i=Array(t.length-1);for(let n=0;n<t.length-1;n++)i[n]=ii(e,t[n],t[n+1]);let a=[];for(let e=0;e<t.length-1;e++){if(n.has(e))continue;let r=i[e];r!==null&&ti(r)&&(n.add(e),n.add(e+1),a.push([t[e],t[e+1]]))}let o=0;for(;o<t.length;){if(n.has(o)){o++;continue}let e=o+1;for(;e<t.length&&n.has(e);)e++;if(e>=t.length)break;if(e>o+1){r.add(t[o]),o++;continue}let a=i[o];if(a===null){o++;continue}ni(a)&&(r.add(t[o]),r.add(t[e])),n.add(o),n.add(e),o=e+1}for(let e=0;e<t.length;e++)n.has(e)||e+1<t.length&&n.has(e+1)&&r.add(t[e]);if(r.size===0&&a.length===0)return e;let s=[],c=0,l=Array.from(r).sort((e,t)=>e-t),u=0,d=0;for(;u<l.length||d<a.length;){let t=u<l.length?l[u]:1/0;if(t<(d<a.length?a[d][0]:1/0))t>c&&s.push(e.slice(c,t)),s.push(`\\$`),c=t+1,u++;else{let[t,n]=a[d];t>c&&s.push(e.slice(c,t));let r=e.slice(t,n+1);for(s.push(r.replace(Gr,`\\text{\\textdollar}`)),c=n+1;u<l.length&&l[u]<=n;)u++;d++}}return c<e.length&&s.push(e.slice(c)),s.join(``)}function oi(e){let t=[],n=0;for(let r of e.matchAll(Wr))t.push(ai(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(ai(e.slice(n))),t.join(``)}function si(e){if(!e?.includes(`$`))return e;let t=[],n=0;for(let r of e.matchAll(Ur))t.push(oi(e.slice(n,r.index))),t.push(r[0]),n=r.index+r[0].length;return t.push(oi(e.slice(n))),t.join(``)}const ci={note:`md-callout-info`,tip:`md-callout-info`,warning:`md-callout-attention`,important:`md-callout-attention`,caution:`md-callout-destructive`},li={note:`Note`,tip:`Tip`,warning:`Warning`,important:`Important`,caution:`Caution`};function ui(){return e=>{$e(e,e=>{if(e.type!==`containerDirective`&&e.type!==`leafDirective`&&e.type!==`textDirective`)return;let t=e;t.data||={};let n=t.data,r=t.attributes||{},i=t.name;if(i===`pagebreak`){n.hName=`hr`,n.hProperties={className:`md-pagebreak`};return}if(i===`columns`){n.hName=`div`,n.hProperties={className:`md-columns`};return}if(i===`column`){n.hName=`div`;let e={className:`md-column`};r.width&&(e.style=`flex-basis:${r.width};flex-grow:0;flex-shrink:0`),n.hProperties=e;return}if(i in ci){n.hName=`div`,n.hProperties={className:`md-callout ${ci[i]}`,"data-callout-type":i};let e=li[i];if(e&&t.children){let n={type:`paragraph`,data:{hName:`p`,hProperties:{className:`md-callout-title`}},children:[{type:`text`,value:e}]};t.children.unshift(n)}return}n.hName=`div`,n.hProperties={className:`md-${i}`,...Object.fromEntries(Object.entries(r).filter(([e])=>e!==`class`))},r.class&&(n.hProperties.className+=` ${r.class}`)})}}const di=[`artifact:`,`image:`,`store:`,`document:`,`document://`,`collection:`,`interaction:`,`prompt:`,`agent:`,`workflow:`,`process:`,`run:`];function fi(e){return di.some(t=>e.startsWith(t))?e:Ue(e)}function pi(){return e=>{$e(e,`html`,(e,t,n)=>{let r=e,i=n;if(typeof r.value==`string`&&/<!--[\s\S]*?-->/.test(r.value)&&i?.children&&typeof t==`number`)return i.children.splice(t,1),[Qe,t]})}}const mi=vr();function hi({children:e,components:n,remarkPlugins:r=[],removeComments:i=!0,artifactRunId:a,onArtifactOpen:o,className:s,codeClassName:c,inlineCodeClassName:l,linkClassName:u,imageClassName:d,onProposalSelect:f,onProposalSubmit:p,preserveSourcePositions:m=!1}){let h=tr(),g=B.useMemo(()=>m?e:Hr(zr(si(e))),[e,m]),_=t(Bn,{artifactRunId:a,onProposalSelect:f,onProposalSubmit:p,MarkdownRenderer:hi,children:t(He,{remarkPlugins:B.useMemo(()=>{let e=[Je,qe,ui,Ye,Ke,Ze,Xe,...r];return i&&e.push(pi),e},[r,i]),rehypePlugins:B.useMemo(()=>[We],[]),remarkRehypeOptions:B.useMemo(()=>({handlers:{...Ge}}),[]),components:B.useMemo(()=>{let e=n||{},r=e.code,i=e.a,s=e.img,f=({node:e,className:n,children:i,...a})=>{let o=/language-([\w-]+)/.exec(n||``),s=!o,u=o?o[1]:``;if(!s&&u){if(h){let e=h.getComponent(u);if(e)return t(e,{code:String(i||``).trim(),language:u})}if(_r(u))return t(gr,{code:String(i||``).trim(),language:u});let e=mi[u];if(e)return t(e,{code:String(i||``).trim(),language:u})}return typeof r==`function`?t(r,{node:e,className:n,...a,children:i}):t(`code`,{...a,className:s?`px-1.5 py-0.5 rounded ${l||``}`:` ${c||``}`,children:i})},p=e=>{let{node:n,href:r,children:s,...c}=e;return t(Dr,{node:n,href:r,className:u,artifactRunId:a,onArtifactOpen:o,ExistingLink:typeof i==`function`?i:void 0,...c,children:s})},m=e=>{let{node:n,src:r,alt:i,title:o,...c}=e;return o?t(Cr,{src:r,alt:i,caption:o,className:d,artifactRunId:a}):t(Tr,{node:n,src:r,alt:i,className:d,artifactRunId:a,ExistingImg:typeof s==`function`?s:void 0,...c})};return{...e,code:f,a:p,img:m}},[n,a,o,h,c,l,u,d]),urlTransform:fi,children:g})});return s?t(`div`,{className:`md-content ${s}`,children:_}):t(`div`,{className:`md-content`,children:_})}const gi=new Set([`list`,`blockquote`,`table`]),_i=V(null),vi=V(!1),yi=De(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownComponentEditor}))),bi=/^ {0,3}(#{1,6})[\t ]+(.+?)[\t ]*#*[\t ]*$/,xi=/^ {0,3}(`{3,}|~{3,})/;function Si(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`edit-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function Ci(e,t,n){let r=t?.position?.start.offset,i=t?.position?.end.offset,a=typeof r==`number`&&typeof i==`number`&&r>=0&&i>=r,o=a?e.slice(r,i):``;return{block_id:a?`${n}:${r}:${i}`:`${n}:${Si()}`,block_type:n,...a?{source_range:{start:r,end:i}}:{},exact_text:o,...a&&r>0?{prefix:e.slice(Math.max(0,r-80),r)}:{},...a&&i<e.length?{suffix:e.slice(i,Math.min(e.length,i+80))}:{}}}function wi(e,t){let n=t.source_range?.start;if(typeof n!=`number`)return t;let r=Ei(e,n),i=Di(e,t.exact_text,n,r);return{...t,...r.length>0?{heading_path:r}:{},occurrence_index:i}}function Ti(e,t,n){return wi(e,Ci(e,t,n))}function Ei(e,t){let n=[],r=null,i=0;for(let a of e.slice(0,t).split(`
7
+ `)){let e=xi.exec(a);if(e){let t=e[1]?.[0];r?t===r&&(r=null):r=t??null,i+=a.length+1;continue}if(!r){let e=bi.exec(a);if(e){let t=e[1]?.length??1,r=e[2]?.trim();r&&(n.length=t-1,n[t-1]=r)}}if(i+=a.length+1,i>t)break}return n.filter(e=>!!e)}function Di(e,t,n,r){if(!t)return 0;let i=0,a=e.indexOf(t);for(;a>=0&&a<n;){let n=Ei(e,a);n.length===r.length&&n.every((e,t)=>e===r[t])&&i++,a=e.indexOf(t,a+Math.max(1,t.length))}return i}function Oi(e){return e.kind===`store_document`?`store:${e.document_id}`:`artifact:${e.path} (run ${e.run_id})`}function ki(...e){let t=0;for(let n of e)for(let e of n.matchAll(/`+/g))t=Math.max(t,e[0].length);return"`".repeat(Math.max(3,t+1))}function Ai(e,t){let n=t.user_change;if(!n)return;let{before:r,after:i}=n,a=t.anchor.source_range;if(a&&e.slice(a.start,a.end)===r)return e.slice(0,a.start)+i+e.slice(a.end);let o=t.anchor.prefix;if(o){let t=e.indexOf(o+r);if(t>=0&&e.indexOf(o+r,t+1)<0){let n=t+o.length;return e.slice(0,n)+i+e.slice(n+r.length)}}let s=e.indexOf(r);if(!(s<0||e.indexOf(r,s+1)>=0))return e.slice(0,s)+i+e.slice(s+r.length)}function ji(e){let t=Oi(e.resource),n=e.anchor.block_type.replace(`_`,` `);if(e.action===`edit`&&e.user_change&&e.applied){let r=ki(e.user_change.before,e.user_change.after);return[`I already edited the ${n} in ${t} myself and the change is saved${e.updated_document_id?` as revision ${e.updated_document_id}`:``}.`,`Operation: ${e.operation_id}`,`This is a notification only. Do not apply this change again and do not modify the document in response; acknowledge briefly and use the latest content going forward.`,``,`Before:`,`${r}markdown`,e.user_change.before,r,``,`After:`,`${r}markdown`,e.user_change.after,r].join(`
8
+ `)}if(e.action===`edit`&&e.user_change){let r=ki(e.user_change.before,e.user_change.after);return[`Apply my edit to the ${n} in ${t}, then update the resource.`,`Operation: ${e.operation_id}`,`Preserve all content outside the selected block exactly; do not regenerate unrelated sections.`,``,`Before:`,`${r}markdown`,e.user_change.before,r,``,`After:`,`${r}markdown`,e.user_change.after,r].join(`
9
+ `)}let r=ki(e.anchor.exact_text);return[`Update the ${n} in ${t} based on this comment:`,`Operation: ${e.operation_id}`,`Preserve all content outside the selected block exactly; do not regenerate unrelated sections.`,``,e.comment??``,``,`Selected content:`,`${r}markdown`,e.anchor.exact_text,r].join(`
10
+ `)}function Mi(){let e=U(_i);if(!e)throw Error(`Collaborative Markdown blocks must be rendered inside CollaborativeMarkdownRenderer`);return e}function Ni({anchor:e,mode:i,initialDraft:a}){let{t:o}=J(),{artifactRunId:s,readOnly:c,allowComments:l,cancelEditing:u,submit:d,updateDraft:f}=Mi(),[p,m]=q(i===`edit`?e.exact_text:i===`insert`?a??``:``),[h,g]=q(!1),_=i===`comment`?!l:c,v=e=>{m(e),f(e)},y=async()=>{if(!(!p.trim()||h)){g(!0);try{await d(e,i,i===`comment`?p.trim():p)}finally{g(!1)}}};return n(`div`,{className:`mb-2 space-y-2`,children:[i===`edit`||i===`insert`?t(Ee,{fallback:t(b,{value:p,onChange:e=>v(e.target.value),placeholder:o(`agent.editSelectionPlaceholder`),rows:6,autoFocus:!0}),children:t(yi,{value:p,onChange:v,artifactRunId:s,editable:!c,externalValueSync:`manual`,autoFocus:!0})}):t(b,{value:p,onChange:e=>v(e.target.value),placeholder:o(`agent.commentOnSelectionPlaceholder`),rows:3,autoFocus:!0,disabled:!l}),n(`div`,{className:`flex justify-end gap-2`,children:[n(r,{variant:`outline`,size:`sm`,onClick:u,disabled:h,children:[t(we,{className:`me-1 size-4`}),o(`store.cancelEdit`)]}),n(r,{size:`sm`,onClick:()=>void y(),disabled:_||!p.trim()||h,children:[t(I,{className:`me-1 size-4`}),o(`agent.send`)]})]})]})}function Q(i,a,u){return function({node:d,children:f,...p}){let{t:m}=J(),{markdown:h,readOnly:g,allowComments:_,activeEditing:v,highlightChangesFrom:y,flashChangedBlocks:ee,beginEditing:b}=Mi(),te=U(vi),C=u?B.createElement(u,{node:d,...p},f):B.createElement(i,p,f);if(te)return C;let w=Ci(h,d,a),T=!!(w.source_range&&w.exact_text),E=!g&&T,D=_&&T,O=v?.anchor.block_id===w.block_id,k=O&&v?.mode===`edit`,A=ee&&!!w.exact_text&&!!y&&!y?.includes(w.exact_text),ne=S(`group/collab relative rounded-md border transition-colors duration-700`,`-mx-2 -my-1 px-2 py-1`,k?`border-transparent`:O?`border-info bg-mixer-info/5`:E||D?`border-transparent hover:border-mixer-info/30 hover:bg-mixer-muted/10`:`border-transparent`,A&&`border-mixer-success/50 bg-mixer-success/15 ring-1 ring-mixer-success/20`),M=E||D||O?n(e,{children:[n(`div`,{className:S(`absolute end-1 top-1 z-10 flex items-center gap-0.5 rounded-md border bg-background p-0.5 shadow-sm`,(!E&&!D||k)&&`hidden`,O?`opacity-100`:`pointer-events-none opacity-0 group-hover/collab:pointer-events-auto group-hover/collab:opacity-100 group-focus-within/collab:pointer-events-auto group-focus-within/collab:opacity-100`),children:[D?t(x,{description:m(`agent.commentOnSelection`),asChild:!0,children:t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,"aria-label":m(`agent.commentOnSelection`),onClick:()=>b(w,`comment`),children:t(_e,{className:`size-4`})})}):null,E?t(x,{description:m(`agent.editSelection`),asChild:!0,children:t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,"aria-label":m(`agent.editSelection`),onClick:()=>b(w,`edit`),children:t(ye,{className:`size-4`})})}):null,E?n(o,{children:[t(x,{description:m(`agent.insertComponent`),asChild:!0,children:t(l,{asChild:!0,children:t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,"aria-label":m(`agent.insertComponent`),children:t(xe,{className:`size-4`})})})}),n(s,{align:`end`,className:`w-52`,children:[n(c,{onClick:()=>b(w,`insert`,m(`richText.paragraph`)),children:[t(be,{}),m(`richText.paragraph`)]}),n(c,{onClick:()=>b(w,`insert`,`## ${m(`richText.heading2`)}`),children:[t(de,{}),m(`richText.heading2`)]}),n(c,{onClick:()=>b(w,`insert`,`- ${m(`richText.bulletList`)}`),children:[t(me,{}),m(`richText.bulletList`)]}),n(c,{onClick:()=>b(w,`insert`,`> ${m(`richText.blockquote`)}`),children:[t(F,{}),m(`richText.blockquote`)]}),n(c,{onClick:()=>b(w,`insert`,"```\nCode\n```"),children:[t(ae,{}),m(`richText.codeBlock`)]}),n(c,{onClick:()=>b(w,`insert`,`| Column | Value |
11
11
  | --- | --- |
12
- | A | 1 |`),children:[t(z,{}),m(`richText.table`)]}),n(c,{onClick:()=>x(T,`insert`,`[${m(`agent.insertLink`)}](https://example.com)`),children:[t(pe,{}),m(`agent.insertLink`)]}),n(c,{onClick:()=>x(T,`insert`,'```chart\n{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"values":[{"category":"A","value":1}]},"mark":"bar","encoding":{"x":{"field":"category","type":"nominal"},"y":{"field":"value","type":"quantitative"}}}\n```'),children:[t(j,{}),m(`agent.insertChart`)]})]})]}):null]}),O&&v?t(Ai,{anchor:v.anchor,mode:v.mode,initialDraft:v.initialDraft},`${v.anchor.block_id}:${v.mode}:${v.initialDraft??``}`):null]}):null,N=pi.has(a)?t(hi.Provider,{value:!0,children:w}):w;return n(`div`,{className:ne,"data-collaborative-block":T.block_id,children:[k?null:N,M]})}}function ji({children:e,resource:i,baseVersion:a,artifactRunId:o,components:s,readOnly:c=!1,allowComments:l=!c,highlightChangesFrom:u,highlightVersion:d=0,onAction:f,className:p,...m}){let{t:h}=J(),[g,_]=q(),[v,y]=q(),[b,S]=q(!1),C=K(``);W(()=>{if(!u||d<=0)return;S(!0);let e=window.setTimeout(()=>S(!1),1800);return()=>window.clearTimeout(e)},[u,d]),W(()=>{let t=g?.anchor.source_range;if(!g||!t||e.slice(t.start,t.end)===g.anchor.exact_text)return;let n=C.current,r=g.mode===`edit`?g.anchor.exact_text:g.mode===`insert`?g.initialDraft??``:``;n.trim()&&n!==r&&y({...g,draft:n}),_(void 0)},[g,e]);let ee=G(()=>({...s,p:Q(`p`,`paragraph`,s?.p),h1:Q(`h1`,`heading`,s?.h1),h2:Q(`h2`,`heading`,s?.h2),h3:Q(`h3`,`heading`,s?.h3),h4:Q(`h4`,`heading`,s?.h4),h5:Q(`h5`,`heading`,s?.h5),h6:Q(`h6`,`heading`,s?.h6),ul:Q(`ul`,`list`,s?.ul),ol:Q(`ol`,`list`,s?.ol),blockquote:Q(`blockquote`,`blockquote`,s?.blockquote),pre:Q(`pre`,`code_block`,s?.pre),table:Q(`table`,`table`,s?.table),hr:Q(`hr`,`separator`,s?.hr)}),[s]),w=H((t,n,r)=>{if(n===`comment`&&!l||n!==`comment`&&c)return;let i=xi(e,t);C.current=n===`edit`?i.exact_text:r??``,_({anchor:i,mode:n,initialDraft:r})},[l,e,c]),T=H(()=>{C.current=``,_(void 0)},[]),E=H(e=>{C.current=e},[]),te=H(async(e,t,n)=>{if(t===`comment`&&!l||t!==`comment`&&c)return;let r=t===`insert`?`${e.exact_text.replace(/\s+$/,``)}\n\n${n.trim()}`:n;await f({operation_id:yi(),resource:i,base_version:a,action:t===`insert`?`edit`:t,anchor:e,...t===`comment`?{comment:n}:{user_change:{before:e.exact_text,after:r}}}),C.current=``,_(void 0)},[l,a,f,c,i]),D=G(()=>({markdown:e,artifactRunId:o,readOnly:c,allowComments:l,activeEditing:g,highlightChangesFrom:u,flashChangedBlocks:b,beginEditing:w,cancelEditing:T,updateDraft:E,submit:te}),[g,l,o,w,T,b,u,e,c,te,E]);return n(mi.Provider,{value:D,children:[v?n(`div`,{className:`not-prose mb-3 rounded-md border border-mixer-attention/35 bg-mixer-attention/10 p-3`,children:[n(`div`,{className:`flex items-start justify-between gap-3`,children:[n(`div`,{children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:h(`agent.documentEditingDraftPreserved`)}),t(`div`,{className:`mt-0.5 text-xs leading-4 text-muted`,children:h(`agent.documentEditingDraftPreservedDescription`)})]}),t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>y(void 0),"aria-label":h(`agent.close`),children:t(we,{className:`size-4`})})]}),t(x,{className:`mt-2`,value:v.draft,onChange:e=>y(t=>t&&{...t,draft:e.target.value}),rows:4})]}):null,t(fi,{...m,artifactRunId:o,className:p,components:ee,preserveSourcePositions:!0,children:e})]})}function Mi(e){return e.split(/(\s+)/).filter(e=>e.length>0)}function $(e,t,n){if(!n)return;let r=e[e.length-1];r&&r.type===t?r.text+=n:e.push({type:t,text:n})}function Ni(e,t,n){let r=e.length+1,i=t.length+1,a=new Uint32Array(r*i);for(let n=e.length-1;n>=0;n--)for(let r=t.length-1;r>=0;r--)a[n*i+r]=e[n]===t[r]?a[(n+1)*i+r+1]+1:Math.max(a[(n+1)*i+r],a[n*i+r+1]);let o=0,s=0;for(;o<e.length&&s<t.length;)e[o]===t[s]?($(n,`equal`,e[o]),o++,s++):a[(o+1)*i+s]>=a[o*i+s+1]?($(n,`removed`,e[o]),o++):($(n,`added`,t[s]),s++);$(n,`removed`,e.slice(o).join(``)),$(n,`added`,t.slice(s).join(``))}function Pi(e,t){if(e===t)return e?[{type:`equal`,text:e}]:[];let n=Mi(e),r=Mi(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;let a=n.length,o=r.length;for(;a>i&&o>i&&n[a-1]===r[o-1];)a--,o--;let s=[];$(s,`equal`,n.slice(0,i).join(``));let c=n.slice(i,a),l=r.slice(i,o);return c.length*l.length>600*600?($(s,`removed`,c.join(``)),$(s,`added`,l.join(``))):Ni(c,l,s),$(s,`equal`,n.slice(a).join(``)),s}function Fi(e,t){let n=[],r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)n.push({type:`equal`,line:e[r]}),r++;let i=e.length,a=t.length,o=[];for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--,o.unshift({type:`equal`,line:e[i]});let s=e.slice(r,i),c=t.slice(r,a);if(s.length*c.length>600*600){for(let e of s)n.push({type:`removed`,line:e});for(let e of c)n.push({type:`added`,line:e});return[...n,...o]}let l=s.length+1,u=c.length+1,d=new Uint32Array(l*u);for(let e=s.length-1;e>=0;e--)for(let t=c.length-1;t>=0;t--)d[e*u+t]=s[e]===c[t]?d[(e+1)*u+t+1]+1:Math.max(d[(e+1)*u+t],d[e*u+t+1]);let f=0,p=0;for(;f<s.length&&p<c.length;)s[f]===c[p]?(n.push({type:`equal`,line:s[f]}),f++,p++):d[(f+1)*u+p]>=d[f*u+p+1]?(n.push({type:`removed`,line:s[f]}),f++):(n.push({type:`added`,line:c[p]}),p++);for(;f<s.length;)n.push({type:`removed`,line:s[f++]});for(;p<c.length;)n.push({type:`added`,line:c[p++]});return[...n,...o]}function Ii(e){return e.match(/[^\n]*\n|[^\n]+$/g)??[]}function Li(e,t){if(!e.includes(`
12
+ | A | 1 |`),children:[t(z,{}),m(`richText.table`)]}),n(c,{onClick:()=>b(w,`insert`,`[${m(`agent.insertLink`)}](https://example.com)`),children:[t(pe,{}),m(`agent.insertLink`)]}),n(c,{onClick:()=>b(w,`insert`,'```chart\n{"$schema":"https://vega.github.io/schema/vega-lite/v5.json","data":{"values":[{"category":"A","value":1}]},"mark":"bar","encoding":{"x":{"field":"category","type":"nominal"},"y":{"field":"value","type":"quantitative"}}}\n```'),children:[t(j,{}),m(`agent.insertChart`)]})]})]}):null]}),O&&v?t(Ni,{anchor:v.anchor,mode:v.mode,initialDraft:v.initialDraft},`${v.anchor.block_id}:${v.mode}:${v.initialDraft??``}`):null]}):null,N=gi.has(a)?t(vi.Provider,{value:!0,children:C}):C;return n(`div`,{className:ne,"data-collaborative-block":w.block_id,children:[k?null:N,M]})}}function Pi({children:e,resource:i,baseVersion:a,artifactRunId:o,components:s,readOnly:c=!1,allowComments:l=!c,highlightChangesFrom:u,highlightVersion:d=0,onAction:f,className:p,...m}){let{t:h}=J(),[g,_]=q(),[v,y]=q(),[ee,x]=q(!1),S=K(``);W(()=>{if(!u||d<=0)return;x(!0);let e=window.setTimeout(()=>x(!1),1800);return()=>window.clearTimeout(e)},[u,d]),W(()=>{let t=g?.anchor.source_range;if(!g||!t||e.slice(t.start,t.end)===g.anchor.exact_text)return;let n=S.current,r=g.mode===`edit`?g.anchor.exact_text:g.mode===`insert`?g.initialDraft??``:``;n.trim()&&n!==r&&y({...g,draft:n}),_(void 0)},[g,e]);let te=G(()=>({...s,p:Q(`p`,`paragraph`,s?.p),h1:Q(`h1`,`heading`,s?.h1),h2:Q(`h2`,`heading`,s?.h2),h3:Q(`h3`,`heading`,s?.h3),h4:Q(`h4`,`heading`,s?.h4),h5:Q(`h5`,`heading`,s?.h5),h6:Q(`h6`,`heading`,s?.h6),ul:Q(`ul`,`list`,s?.ul),ol:Q(`ol`,`list`,s?.ol),blockquote:Q(`blockquote`,`blockquote`,s?.blockquote),pre:Q(`pre`,`code_block`,s?.pre),table:Q(`table`,`table`,s?.table),hr:Q(`hr`,`separator`,s?.hr)}),[s]),C=H((t,n,r)=>{if(n===`comment`&&!l||n!==`comment`&&c)return;let i=wi(e,t);S.current=n===`edit`?i.exact_text:r??``,_({anchor:i,mode:n,initialDraft:r})},[l,e,c]),w=H(()=>{S.current=``,_(void 0)},[]),T=H(e=>{S.current=e},[]),E=H(async(e,t,n)=>{if(t===`comment`&&!l||t!==`comment`&&c)return;let r=t===`insert`?`${e.exact_text.replace(/\s+$/,``)}\n\n${n.trim()}`:n;await f({operation_id:Si(),resource:i,base_version:a,action:t===`insert`?`edit`:t,anchor:e,...t===`comment`?{comment:n}:{user_change:{before:e.exact_text,after:r}}}),S.current=``,_(void 0)},[l,a,f,c,i]),D=G(()=>({markdown:e,artifactRunId:o,readOnly:c,allowComments:l,activeEditing:g,highlightChangesFrom:u,flashChangedBlocks:ee,beginEditing:C,cancelEditing:w,updateDraft:T,submit:E}),[g,l,o,C,w,ee,u,e,c,E,T]);return n(_i.Provider,{value:D,children:[v?n(`div`,{className:`not-prose mb-3 rounded-md border border-mixer-attention/35 bg-mixer-attention/10 p-3`,children:[n(`div`,{className:`flex items-start justify-between gap-3`,children:[n(`div`,{children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:h(`agent.documentEditingDraftPreserved`)}),t(`div`,{className:`mt-0.5 text-xs leading-4 text-muted`,children:h(`agent.documentEditingDraftPreservedDescription`)})]}),t(r,{variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>y(void 0),"aria-label":h(`agent.close`),children:t(we,{className:`size-4`})})]}),t(b,{className:`mt-2`,value:v.draft,onChange:e=>y(t=>t&&{...t,draft:e.target.value}),rows:4})]}):null,t(hi,{...m,artifactRunId:o,className:p,components:te,preserveSourcePositions:!0,children:e})]})}function Fi(e){return e.split(/(\s+)/).filter(e=>e.length>0)}function $(e,t,n){if(!n)return;let r=e[e.length-1];r&&r.type===t?r.text+=n:e.push({type:t,text:n})}function Ii(e,t,n){let r=e.length+1,i=t.length+1,a=new Uint32Array(r*i);for(let n=e.length-1;n>=0;n--)for(let r=t.length-1;r>=0;r--)a[n*i+r]=e[n]===t[r]?a[(n+1)*i+r+1]+1:Math.max(a[(n+1)*i+r],a[n*i+r+1]);let o=0,s=0;for(;o<e.length&&s<t.length;)e[o]===t[s]?($(n,`equal`,e[o]),o++,s++):a[(o+1)*i+s]>=a[o*i+s+1]?($(n,`removed`,e[o]),o++):($(n,`added`,t[s]),s++);$(n,`removed`,e.slice(o).join(``)),$(n,`added`,t.slice(s).join(``))}function Li(e,t){if(e===t)return e?[{type:`equal`,text:e}]:[];let n=Fi(e),r=Fi(t),i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;let a=n.length,o=r.length;for(;a>i&&o>i&&n[a-1]===r[o-1];)a--,o--;let s=[];$(s,`equal`,n.slice(0,i).join(``));let c=n.slice(i,a),l=r.slice(i,o);return c.length*l.length>600*600?($(s,`removed`,c.join(``)),$(s,`added`,l.join(``))):Ii(c,l,s),$(s,`equal`,n.slice(a).join(``)),s}function Ri(e,t){let n=[],r=0;for(;r<e.length&&r<t.length&&e[r]===t[r];)n.push({type:`equal`,line:e[r]}),r++;let i=e.length,a=t.length,o=[];for(;i>r&&a>r&&e[i-1]===t[a-1];)i--,a--,o.unshift({type:`equal`,line:e[i]});let s=e.slice(r,i),c=t.slice(r,a);if(s.length*c.length>600*600){for(let e of s)n.push({type:`removed`,line:e});for(let e of c)n.push({type:`added`,line:e});return[...n,...o]}let l=s.length+1,u=c.length+1,d=new Uint32Array(l*u);for(let e=s.length-1;e>=0;e--)for(let t=c.length-1;t>=0;t--)d[e*u+t]=s[e]===c[t]?d[(e+1)*u+t+1]+1:Math.max(d[(e+1)*u+t],d[e*u+t+1]);let f=0,p=0;for(;f<s.length&&p<c.length;)s[f]===c[p]?(n.push({type:`equal`,line:s[f]}),f++,p++):d[(f+1)*u+p]>=d[f*u+p+1]?(n.push({type:`removed`,line:s[f]}),f++):(n.push({type:`added`,line:c[p]}),p++);for(;f<s.length;)n.push({type:`removed`,line:s[f++]});for(;p<c.length;)n.push({type:`added`,line:c[p++]});return[...n,...o]}function zi(e){return e.match(/[^\n]*\n|[^\n]+$/g)??[]}function Bi(e,t){if(!e.includes(`
13
13
  `)&&!t.includes(`
14
- `))return Pi(e,t);if(e===t)return e?[{type:`equal`,text:e}]:[];let n=[],r=Fi(Ii(e),Ii(t)),i=0;for(;i<r.length;){let e=r[i];if(e.type===`equal`){$(n,`equal`,e.line),i++;continue}let t=``,a=``;for(;i<r.length&&r[i].type!==`equal`;){let e=r[i++];e.type===`removed`&&(t+=e.line),e.type===`added`&&(a+=e.line)}for(let e of Pi(t,a))$(n,e.type,e.text)}return n}function Ri(e,t){if(e===t)return[];let n=[],r=Fi(e.split(`
14
+ `))return Li(e,t);if(e===t)return e?[{type:`equal`,text:e}]:[];let n=[],r=Ri(zi(e),zi(t)),i=0;for(;i<r.length;){let e=r[i];if(e.type===`equal`){$(n,`equal`,e.line),i++;continue}let t=``,a=``;for(;i<r.length&&r[i].type!==`equal`;){let e=r[i++];e.type===`removed`&&(t+=e.line),e.type===`added`&&(a+=e.line)}for(let e of Li(t,a))$(n,e.type,e.text)}return n}function Vi(e,t){if(e===t)return[];let n=[],r=Ri(e.split(`
15
15
  `),t.split(`
16
- `)),i=0,a,o=()=>{a!==void 0&&(n.push({startLine:a,endLine:Math.max(a,i-1)}),a=void 0)};for(let e of r){if(e.type===`equal`){o(),i++;continue}a??=i,e.type===`added`&&i++}return o(),n}function zi(e,t){let n=[],r=Fi(e,t),i=0,a=0;for(;a<r.length;){if(r[a].type===`equal`){i++,a++;continue}let e=i,t=[];for(;a<r.length&&r[a].type!==`equal`;){let e=r[a++];e.type===`removed`&&i++,e.type===`added`&&t.push(e.line)}n.push({start:e,end:i,replacement:t})}return n}function Bi(e,t){return e.start===t.start&&e.end===t.end&&e.replacement.length===t.replacement.length&&e.replacement.every((e,n)=>e===t.replacement[n])}function Vi(e,t){let n=e.start===e.end,r=t.start===t.end;return n&&r?e.start===t.start:n?e.start>=t.start&&e.start<=t.end:r?t.start>=e.start&&t.start<=e.end:e.start<t.end&&t.start<e.end}function Hi(e,t,n){if(t===n)return{status:`rebased`,content:t};if(t===e)return{status:`rebased`,content:n};if(n===e)return{status:`rebased`,content:t};let r=e.split(`
17
- `),i=zi(r,t.split(`
18
- `)),a=zi(r,n.split(`
19
- `)),o=[];for(let e of i){let n=!1;for(let r of a){if(Bi(e,r)){n=!0;break}if(Vi(e,r))return{status:`conflict`,content:t}}n||o.push(e)}let s=[...a,...o].sort((e,t)=>e.start-t.start||e.end-t.end),c=[],l=0;for(let e of s)c.push(...r.slice(l,e.start),...e.replacement),l=e.end;return c.push(...r.slice(l)),{status:`rebased`,content:c.join(`
20
- `)}}function Ui(e,t,n={}){if(e===t)return;let r=n.context??2,i=Fi(e.split(`
16
+ `)),i=0,a,o=()=>{a!==void 0&&(n.push({startLine:a,endLine:Math.max(a,i-1)}),a=void 0)};for(let e of r){if(e.type===`equal`){o(),i++;continue}a??=i,e.type===`added`&&i++}return o(),n}function Hi(e,t){let n=[],r=Ri(e,t),i=0,a=0;for(;a<r.length;){if(r[a].type===`equal`){i++,a++;continue}let e=i,t=[];for(;a<r.length&&r[a].type!==`equal`;){let e=r[a++];e.type===`removed`&&i++,e.type===`added`&&t.push(e.line)}n.push({start:e,end:i,replacement:t})}return n}function Ui(e,t){return e.start===t.start&&e.end===t.end&&e.replacement.length===t.replacement.length&&e.replacement.every((e,n)=>e===t.replacement[n])}function Wi(e,t){let n=e.start===e.end,r=t.start===t.end;return n&&r?e.start===t.start:n?e.start>=t.start&&e.start<=t.end:r?t.start>=e.start&&t.start<=e.end:e.start<t.end&&t.start<e.end}function Gi(e,t,n){if(t===n)return{status:`rebased`,content:t};if(t===e)return{status:`rebased`,content:n};if(n===e)return{status:`rebased`,content:t};let r=e.split(`
17
+ `),i=Hi(r,t.split(`
18
+ `)),a=Hi(r,n.split(`
19
+ `)),o=[];for(let e of i){let n=!1;for(let r of a){if(Ui(e,r)){n=!0;break}if(Wi(e,r))return{status:`conflict`,content:t}}n||o.push(e)}let s=[...a,...o].sort((e,t)=>e.start-t.start||e.end-t.end),c=[],l=0;for(let e of s)c.push(...r.slice(l,e.start),...e.replacement),l=e.end;return c.push(...r.slice(l)),{status:`rebased`,content:c.join(`
20
+ `)}}function Ki(e,t,n={}){if(e===t)return;let r=n.context??2,i=Ri(e.split(`
21
21
  `),t.split(`
22
22
  `)),a=[];for(let e=0;e<i.length;e++){if(i[e].type===`equal`)continue;let t=a[a.length-1];t&&e-t.end<=r*2?t.end=e+1:a.push({start:e,end:e+1})}if(a.length===0)return;let o=[],s=1,c=1,l=0;for(let e of a){let t=Math.max(e.start-r,l===0?0:l);for(;l<t;l++)i[l].type!==`added`&&s++,i[l].type!==`removed`&&c++;let n=Math.min(e.end+r,i.length),a=0,u=0,d=[];for(let e=t;e<n;e++){let t=i[e];t.type===`equal`?(d.push(` ${t.line}`),a++,u++):t.type===`removed`?(d.push(`-${t.line}`),a++):(d.push(`+${t.line}`),u++)}for(o.push(`@@ -${s},${a} +${c},${u} @@`,...d);l<n;l++)i[l].type!==`added`&&s++,i[l].type!==`removed`&&c++}let u=o.join(`
23
- `);if(!(n.maxChars!==void 0&&u.length>n.maxChars))return u}const Wi=De(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownDocumentEditor})));function Gi(e,t){return e?.path===t?e.event_class===`artifact_updated`||e.event_class===`activity`&&e.tool_status===`completed`&&(e.tool===`edit_artifact`||e.tool===`write_artifact`):!1}function Ki(e,t){if(!Array.isArray(t?.changes)||t.changes.length===0)return;let n=e;for(let e of t.changes){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(t.operation!==`replace`||typeof t.before!=`string`||typeof t.after!=`string`||!n.includes(t.before))return;if(t.replace_all===!0)n=n.split(t.before).join(t.after);else{if(n.indexOf(t.before)!==n.lastIndexOf(t.before))return;n=n.replace(t.before,t.after)}}return n}function qi(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function Ji({regions:e,totalLines:n,onNavigate:r}){let{t:i}=J();return e.length===0?null:t(`nav`,{className:`absolute inset-y-12 end-1 z-10 w-3 rounded-full border border-mixer-muted/25 bg-muted/20`,"aria-label":i(`agent.changeRuler`),children:e.map(e=>{let a=e.startLine/Math.max(1,n)*100,o=Math.max(1.5,(e.endLine-e.startLine+1)/Math.max(1,n)*100);return t(S,{description:i(`agent.changedRegion`,{line:e.startLine+1}),asChild:!0,children:t(`button`,{type:`button`,className:`absolute inset-x-0 rounded-full bg-attention transition-colors hover:bg-info focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-info`,style:{top:`${Math.min(98.5,a)}%`,height:`${Math.min(100-a,o)}%`},onClick:()=>r(e.startLine),"aria-label":i(`agent.changedRegion`,{line:e.startLine+1})})},`${e.startLine}:${e.endLine}`)})})}function Yi(e,t){return Ri(e,t)}function Xi({runId:e,path:a,initialContent:o=``,refreshKey:s=0,refreshDetails:c,readOnly:l=!1,allowComments:u=!1,viewMode:f=`components`,baselineContent:p,className:m,onAction:h,onSendMessage:g,onSendChangesToAgent:v,hasUnsentChanges:y=!1,isSendingChanges:b=!1,sendChangesDisabled:x=!1,toolbarStatus:S,onContentChange:w,onDocumentEdit:T,onSaveStatusChange:E,flushChangesRef:D}){let{client:O}=Re(),{t:k}=J(),A=te(),[j,M]=q(o),[N,re]=q(),[ie,ae]=q(),[oe,se]=q(0),[ce,le]=q(!!e),[de,P]=q(!1),[fe,pe]=q(!1),[me,he]=q(),[ge,_e]=q(),[ve,ye]=q(!1),be=!l||u,xe=f!==`document`||ge?`idle`:de||fe?`saving`:N?`saved`:`idle`;W(()=>{E?.(xe)},[xe,E]);let F=K(j),I=K(N),L=K(0),R=K(void 0),z=K(void 0),Se=K(!1),Ce=K(void 0),we=K(()=>Promise.resolve(!1)),Te=K(!1),B=K(!1),V=K(null),De=K(N),Oe=K(o),U=K(void 0),ke=K(o),Ae=K(null),je=G(()=>Yi(p??j,j),[p,j]),Me=G(()=>j.split(`
24
- `).length,[j]),Ne=H(e=>{U.current=e,_e(e)},[]);W(()=>{F.current=j},[j]),W(()=>{I.current=N},[N]),W(()=>{f===`document`&&(B.current=!1,Te.current=!1)},[f]);let Pe=H(async t=>{if(!e)return;let n=++L.current;le(!0),he(void 0);for(let r=0;r<=60;r++)try{let t=await O.agents.getArtifactContent(e,a);if(L.current!==n)return;let r=F.current;r&&r!==t.content&&(ae(r),se(e=>e+1)),F.current=t.content,I.current=t.generation,ke.current=t.content,!Te.current&&z.current===void 0&&!Se.current&&(De.current=t.generation,Oe.current=t.content),M(t.content),re(t.generation),he(void 0),le(!1),w?.(t.content,t.generation);return}catch(e){if(L.current!==n||!t||qi(e)!==404||r===60){if(L.current!==n)return;he(ee(e,k(`agent.failedToLoadArtifact`))),le(!1);return}await new Promise(e=>setTimeout(e,500))}},[O,w,a,e,k]);W(()=>(L.current++,F.current=o,I.current=void 0,ke.current=o,De.current=void 0,Oe.current=o,U.current=void 0,Te.current=!1,B.current=!1,M(o),re(void 0),ae(void 0),he(void 0),_e(void 0),ye(!1),pe(!1),le(!!e),e&&Pe(!0),()=>{L.current++}),[o,Pe,e]),W(()=>{if(!e||s<=0||U.current)return;let t=F.current,n=Ki(t,c);n!==void 0&&n!==t&&(F.current=n,I.current=void 0,ae(t),se(e=>e+1),M(n),re(void 0),w?.(n)),Pe(!1)},[Pe,w,c,s,e]);let Fe=H((e,t)=>{let n=F.current;F.current=e,I.current=t,Oe.current=e,De.current=t,z.current=void 0,Ne(void 0),V.current?.getMarkdown()!==e&&V.current?.commands.setContent(e,{contentType:`markdown`,emitUpdate:!1}),n!==e&&(ae(n),se(e=>e+1)),M(e),re(t),pe(!1),w?.(e,t)},[w,Ne]),Ie=H(async(t,n,r)=>{if(!e)return!1;F.current=n,z.current=void 0,M(n),pe(!1),ye(!0);let i,o;try{let s=await O.agents.getArtifactContent(e,a);i=s.content,o=s.generation,ke.current=s.content;let c=Hi(t,n,s.content);if(c.status===`conflict`)return Ne({baseContent:t,localContent:n,remoteContent:s.content,remoteGeneration:s.generation,pendingAction:r}),!1;let l=s.generation;if(c.content!==s.content)try{l=(await O.agents.updateArtifactContent(e,a,{content:c.content,generation:s.generation})).generation}catch(e){if(qi(e)===412)return Ne({baseContent:s.content,localContent:c.content,remoteContent:s.content,remoteGeneration:s.generation,pendingAction:r}),!1;throw e}return Fe(c.content,l),A({status:`success`,title:k(`agent.artifactConflictRebased`),duration:3e3}),{content:c.content,generation:l}}catch(e){return Ne({baseContent:t,localContent:n,remoteContent:i,remoteGeneration:o,pendingAction:r}),A({status:`error`,title:k(`agent.artifactConflictTitle`),description:ee(e,k(`agent.failedToLoadArtifact`)),duration:5e3}),!1}finally{ye(!1)}},[Fe,O.agents,a,e,k,A,Ne]),Le=H(async t=>{if(t.action===`comment`){await h?.(t);return}if(U.current){A({status:`warning`,title:k(`agent.artifactConflictTitle`),duration:3e3});return}if(!e||!I.current){A({status:`warning`,title:k(`agent.artifactEditingUnavailable`),duration:3e3});return}let n=F.current,r=Di(n,t);if(r===void 0){A({status:`error`,title:k(`agent.documentEditApplyFailed`),description:k(`agent.documentEditApplyFailedDescription`),duration:5e3});return}try{let i=await O.agents.updateArtifactContent(e,a,{content:r,generation:I.current});F.current=r,I.current=i.generation,Oe.current=r,De.current=i.generation,ae(n),se(e=>e+1),M(r),re(i.generation),w?.(r,i.generation),await h?.({...t,applied:!0,base_version:i.generation}),ke.current=r}catch(e){if(qi(e)===412){let e=await Ie(n,r,t);e&&(await h?.({...t,applied:!0,base_version:e.generation}),ke.current=e.content);return}A({status:`error`,title:k(`agent.documentEditApplyFailed`),description:ee(e,k(`store.errorSavingTextDefault`)),duration:5e3})}},[O,h,w,a,Ie,e,k,A]),ze=H(()=>{if(!e)return Promise.resolve(!1);if(Ce.current)return Ce.current;let t=(async()=>{Se.current=!0,P(!0);try{for(;z.current!==void 0;){let t=z.current;z.current=void 0;let n=De.current;if(!n)throw Error(k(`agent.artifactEditingUnavailable`));let r=await O.agents.updateArtifactContent(e,a,{content:t,generation:n});I.current=r.generation,De.current=r.generation,Oe.current=t,re(r.generation),w?.(F.current,r.generation)}return pe(!1),!0}catch(e){return qi(e)===412?!!await Ie(Oe.current,F.current):(A({status:`error`,title:k(`agent.documentEditApplyFailed`),description:ee(e,k(`store.errorSavingTextDefault`)),duration:5e3}),!1)}finally{Se.current=!1,P(!1)}})();return Ce.current=t,t.finally(()=>{Ce.current===t&&(Ce.current=void 0)}),t},[O.agents,w,a,Ie,e,k,A]);we.current=ze;let Be=H(async()=>{R.current!==void 0&&(clearTimeout(R.current),R.current=void 0);let t=V.current?.getMarkdown();t!==void 0&&t!==F.current&&(F.current=t,M(t),w?.(t,I.current),z.current=t);let n=U.current;if(n&&!await Ie(n.baseContent,F.current))return!1;for(;z.current!==void 0||Ce.current;)if(!await ze())return!1;if(!e||!I.current)return!1;let r=ke.current;return ke.current=F.current,{previous:r,current:F.current}},[w,ze,Ie,e]);W(()=>{if(D)return D.current=Be,()=>{D.current===Be&&(D.current=null)}},[D,Be]);let Ve=H(e=>{if(e===F.current||Te.current&&z.current===void 0&&!Se.current&&e===Oe.current)return;if(!B.current){F.current=e,M(e);return}F.current=e,M(e),T?.(),w?.(e,I.current);let t=U.current;if(t){Ne({...t,localContent:e}),pe(!1);return}pe(!0),z.current=e,R.current!==void 0&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=void 0,ze()},400)},[w,T,ze,Ne]),He=H(e=>{Te.current=e,e&&(B.current=!0),(e||z.current===void 0&&!Se.current)&&(De.current=I.current,Oe.current=F.current)},[]),Ue=H(async()=>{let e=U.current;if(!e||ve)return;let t=await Ie(e.baseContent,F.current,e.pendingAction);t&&e.pendingAction&&(await h?.({...e.pendingAction,applied:!0,base_version:t.generation}),ke.current=t.content)},[ve,h,Ie]),We=H(e=>{let t=Ae.current?.querySelector(`.vertesia-markdown-document-editor-content`);if(!t)return;let n=Math.min(1,e/Math.max(1,Me-1));t.scrollTo({top:n*Math.max(0,t.scrollHeight-t.clientHeight),behavior:`smooth`})},[Me]);return W(()=>()=>{R.current!==void 0&&clearTimeout(R.current);let e=V.current?.getMarkdown();e!==void 0&&e!==F.current&&(F.current=e,z.current=e),z.current!==void 0&&we.current()},[]),n(`div`,{className:m??`relative h-full min-h-0 overflow-y-auto px-4 py-3`,children:[ge?t(`div`,{className:`absolute inset-x-4 top-3 z-30`,role:`alert`,children:t(d,{status:`warning`,title:k(`agent.artifactConflictTitle`),className:`shadow-lg`,children:n(`div`,{className:`space-y-3`,children:[t(`p`,{children:k(`agent.artifactConflictDescription`)}),t(`div`,{className:`flex justify-end`,children:n(r,{variant:`outline`,size:`sm`,disabled:ve,onClick:()=>void Ue(),children:[ve?t(_,{size:`sm`}):null,k(`agent.artifactConflictRetry`)]})})]})})}):null,ce&&!j?t(i,{className:`h-full min-h-[200px]`,children:t(_,{size:`lg`})}):me&&!j?n(i,{className:`h-full min-h-[200px] flex-col gap-3 text-center text-muted`,children:[t(`span`,{children:me}),t(r,{variant:`outline`,size:`sm`,onClick:()=>void Pe(!1),children:k(`agent.retry`)})]}):f===`document`?t(Ee,{fallback:t(i,{className:`h-full min-h-[200px]`,children:t(_,{size:`lg`})}),children:t(`div`,{className:`flex h-full min-h-0 flex-col`,children:n(`div`,{ref:Ae,className:`relative min-h-0 flex-1`,children:[t(Wi,{value:j,onChange:Ve,artifactRunId:e,editable:!l&&!!e,externalValueSync:`when-blurred`,onFocusChange:He,onEditor:e=>{V.current=e},onSendComment:g&&e&&!ge&&be?g:void 0,onSendChangesToAgent:v,hasUnsentChanges:y,isSendingChanges:b,sendChangesDisabled:x||!e||!!ge,toolbarStatus:S,contentClassName:`pe-5`}),t(Ji,{regions:je,totalLines:Me,onNavigate:We}),!E&&xe!==`idle`?n(`div`,{className:C(`pointer-events-none absolute bottom-3 end-6 flex items-center gap-1.5 rounded-full`,`border border-mixer-muted/25 bg-background/90 px-2.5 py-1 text-[11px] shadow-sm`,de||fe?`text-muted`:`text-success`),children:[de||fe?t(_,{size:`sm`}):t(ne,{className:`size-3`}),k(de||fe?`agent.savingWorkingCopy`:`agent.savedToWorkingCopy`)]}):null]})})}):t(`div`,{className:`vprose prose-sm mx-auto max-w-5xl`,children:t(ji,{artifactRunId:e,resource:{kind:`agent_artifact`,run_id:e??`pending`,path:a},baseVersion:N,readOnly:l||!e||!!ge,allowComments:be&&!!e&&!ge,highlightChangesFrom:ie,highlightVersion:oe,onAction:Le,children:j})}),ce&&j?t(`div`,{className:`absolute end-3 top-3 rounded-full bg-background/80 p-2 shadow-sm`,children:t(ue,{className:`size-4 animate-pulse text-muted`})}):null]})}function Zi({percent:e}){return t(`div`,{className:`w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700`,children:t(`div`,{className:`bg-blue-600 h-2.5 rounded-full`,style:{width:`${e}%`}})})}function Qi({className:e,properties:r}){return t(b,{className:e,children:t(`tbody`,{children:r.map(e=>n(`tr`,{children:[n(`td`,{className:`w-1/3 font-semibold gap-2`,children:[t(`span`,{children:e.name}),e.description&&t(S,{description:e.description,placement:`top`,children:t(fe,{className:`size-3 ms-2 text-muted-foreground`})})]}),t(`td`,{className:`w-2/3`,children:e.value??`undefined`})]},e.name))})})}function $i({content:e,...n}){let r=K(null);return W(()=>{if(!r.current)return;let t=new DOMParser().parseFromString(e,`image/svg+xml`).querySelector(`svg`);if(!t){console.warn(`SvgIcon: No <svg> element found in provided string`),r.current.innerHTML=``;return}Object.entries(n).forEach(([e,n])=>{if(n==null)return;let r=e===`className`?`class`:e;t.setAttribute(r,String(n))}),r.current.innerHTML=``,r.current.appendChild(t)}),t(`span`,{ref:r})}function ea(e){return n=>t($i,{content:e,...n})}function ta(e){return{name:e.getNameSignature(),type:e.getTypeSignature(),description:e.description,extractable:e.extractable}}var na;(function(e){e.string=`string`,e.number=`number`,e.integer=`integer`,e.boolean=`boolean`,e.object=`object`,e.any=`any`,e.text=`text`,e.media=`media`,e.document=`document`})(na||={});function ra(e){e=e.trim();let t=!1,n=!1;e.endsWith(`?`)&&(n=!0,e=e.substring(0,e.length-1).trim()),e.endsWith(`[]`)&&(t=!0,e=e.substring(0,e.length-2).trim());let r=na[e];if(!r)throw Error(`Unknown type "${e}"`);return{name:r,isArray:t,isNullable:n,isObject:r===na.object}}function ia(){let e=Object.values(na),t=[...e];for(let n of e)t.push(`${n}[]`);return e.sort(),t}const aa=ia();function oa({value:e,onChange:i,onCancel:a,onSave:o}){let{t:s}=J(),[c,l]=q(!1);return e?n(`div`,{className:`flex items-center`,children:[t(`div`,{className:`flex-1`,children:t(sa,{value:e.name,onChange:t=>{i({...e,name:t})},onCancel:a,onSave:o})}),t(`div`,{className:`px-1 font-semibold`,children:`:`}),t(`div`,{className:`flex-1`,children:t(ca,{value:e.type,onChange:t=>{i({...e,type:t})},onCancel:a,onSave:o})}),n(`div`,{children:[t(r,{variant:`ghost`,size:`xs`,onClick:()=>l(!0),title:s(`widgets.schema.editDescription`),children:t(A,{className:`size-4`})}),t(la,{value:e.description,isOpen:c,onClose:t=>{t!==void 0&&typeof t==`string`&&i({...e,description:t},!0),l(!1)}})]})]}):null}function sa({value:e,onChange:n,onCancel:r,onSave:i}){let a=K(null);return W(()=>{a.current?.focus()},[]),t(`input`,{onKeyUp:e=>{switch(e.key){case`Enter`:i?.();break;case`Escape`:r?.();break}},ref:a,value:e,onChange:e=>{n(e.target.value)},className:v.INPUT_UNSTYLED,style:{fontSize:`inherit`,width:``,display:`inline`}})}function ca({value:e,onChange:n,onCancel:r,onSave:i}){return t(g,{className:v.INPUT_UNSTYLED,options:aa,value:e||``,onBlur:()=>{i?.()},onChange:n,onKeyDown:(e,t)=>{t||(e.key===`Enter`?i?.():e.key===`Escape`&&r?.())},popupClass:`schema-type-suggest-popup z-90`})}function la({value:e,isOpen:r,onClose:i}){let{t:a}=J();return n(f,{isOpen:r,onClose:i,children:[t(h,{children:a(`widgets.schema.editDescription`)}),t(ua,{value:e,onSave:i})]})}function ua({value:i,onSave:a}){let{t:o}=J(),s=K(null),[c,l]=q(i||``);return W(()=>{s.current?.focus()},[]),n(e,{children:[t(p,{className:`h-max`,children:t(`textarea`,{ref:s,className:`dark:bg-gray-800 w-full h-full dark:text-white`,value:c,onChange:e=>l(e.target.value)})}),t(m,{children:t(r,{onClick:()=>a(c),children:o(`store.saveChanges`)})})]})}function da({value:e}){let{t:r}=J();if(!e)return null;let i=e.extractable===!1;return n(`div`,{className:`w-full flex items-baseline gap-2 min-w-0`,children:[t(`div`,{className:`truncate`,children:e.name||``}),t(`div`,{className:`text-sm text-muted shrink-0`,children:e.type||``}),i&&t(`span`,{className:`shrink-0 text-[10px] uppercase tracking-wide text-attention border border-attention/40 bg-attention/10 rounded px-1.5 py-0.5`,title:r(`widgets.schema.extractFromDocumentHint`),children:r(`widgets.schema.noExtract`)})]})}function fa(e,t,n){if(e.properties){let r=e.properties,i={};for(let e of Object.keys(r)){let a=r[e];e===t?i[n]=a:i[e]=a}e.properties=i}e.required&&=e.required.map(e=>e===t?n:e)}function pa(e,t,n){if(Array.isArray(e.required)){let r=e.required.indexOf(t);n?r<0&&e.required.push(t):r>-1&&e.required.splice(r,1)}else n&&(e.required=[t])}function ma(e,t){let n=t.name===`any`?void 0:t.isNullable?[t.name,`null`]:t.name;if(t.isArray)if(e.type=`array`,e.properties=void 0,!e.items||Array.isArray(e.items))e.items={type:n,properties:t.isObject?{}:void 0};else{let r=e.items;r.type=n,t.isObject&&!r.properties&&(r.properties={})}else e.type=n,e.items=void 0,t.isObject?e.properties||={}:e.properties=void 0}function ha(e,t){e.properties&&(delete e.properties[t],Array.isArray(e.required)&&(e.required=e.required.filter(e=>e!==t)))}function ga(e,t,n,r=!1){if(e.type!==`object`)throw Error(`Cannot add property to a non-object schema`);e.properties||={};let i={};return ma(i,n),e.properties[t]=i,r&&(Array.isArray(e.required)?ba(e.required,t):e.required=[t]),i}function _a(e){let t=!1,n=!1,r,i=e.type;if(Array.isArray(i))for(let e of i)e===`null`?t=!0:r||=e;else r=i;r||=`any`,r===`array`&&(n=!0,r=va(e.items));let a=r;switch(e.editor){case`textarea`:a=`text`;break;case`media`:a=`media`;break;case`document`:a=`document`;break}return{isNullable:t,isArray:n,isObject:r===`object`,name:a}}function va(e){if(!e)return`any`;let t;return t=ya(Array.isArray(e)?e[0].type:e.type),(t===`array`||t===`null`)&&(t=`any`),t}function ya(e){return e?Array.isArray(e)?e.find(e=>e!==`null`)||`any`:e:`any`}function ba(e,t){e.includes(t)||e.push(t)}let xa=0;var Sa=class e{source;onChange=()=>{};schema;root;constructor(e,t){e?typeof e==`string`?this.schema=JSON.parse(e):this.schema=e:this.schema={title:t,type:`object`,properties:{}},this.schema.properties||(this.schema.properties={}),this.root=new Ca(``,this.schema,this),this.root.loadChildren()}get isEmpty(){return!this.root.children||this.root.children.length===0}get children(){return this.root.children??[]}reload(){return this.root=new Ca(``,this.schema,this),this.root.loadChildren(),this.onChange?.(this),this}withSource(e,t){return this.source={uri:t,name:e},this}withChangeListener(e){return this.onChange=e,this}replaceSchema(e){e?this.schema=e:this.schema={title:this.schema.title,type:`object`,properties:{}},this.reload()}clone(){let t=new e(this.schema);return t.source=this.source,this.onChange&&t.withChangeListener(this.onChange),t}},Ca=class e{schema;loader;parent;name;isRequired=!1;type;children;constructor(e,t,n,r){if(this.schema=t,this.loader=n,this.parent=r,this.name=e,this.type=_a(t),this.parent){let t=this.parent._getPropertiesSchema().required;this.isRequired=t&&Array.isArray(t)?t.includes(e):!1}}get title(){return typeof this.schema.title==`string`?this.schema.title:void 0}set title(e){this.schema.title=e}get description(){return this.schema.description}set description(e){this.schema.description=e}get extractable(){return this.schema[`x-extract`]!==!1}set extractable(e){e?delete this.schema[`x-extract`]:this.schema[`x-extract`]=!1}get isParent(){return this.type.isObject}get isNew(){return!!this.schema.isNew}set isNew(e){e?this.schema.isNew=!0:delete this.schema.isNew}resetIsNew(){let e=this.isNew;return this.isNew=!1,e}getNameSignature(){return`${this.name}${this.isRequired?``:`?`}`}getTypeSignature(){return`${this.type.name}${this.type.isArray?`[]`:``}${this.type.isNullable?`?`:``}`}getSignature(){return`${this.getNameSignature()}: ${this.getTypeSignature()}`}reloadTree(){this.loader.reload()}loadChildren(){this.children=[];let e=this.schema.items?.properties;this.schema.items&&e?this._loadChildren(e,this.children):this.schema.properties&&this._loadChildren(this.schema.properties,this.children)}_loadChildren(t,n){for(let r of Object.keys(t)){let i=t[r],a=new e(r,i,this.loader,this);n.push(a),a.isParent&&a.loadChildren()}}_getPropertiesSchema(){return this.type.isArray&&this.type.isObject?this.schema.items:this.schema}findAvailableChildName(e){let t=this._getPropertiesSchema().properties||{},n;do n=e+ ++xa;while(t[n]);return n}addChild(t,n,r=!1){if(!this.type.isObject)throw Error(`Cannot add child to a non object node`);this.children||=[];let i=ga(this._getPropertiesSchema(),t,n,r),a=new e(t,i,this.loader,this);return this.children.push(a),a}remove(){return this.parent?.type.isObject?(ha(this.parent._getPropertiesSchema(),this.name),this.parent.children&&(this.parent.children=this.parent.children.filter(e=>e.name!==this.name)),!0):!1}update(e){let t=!1;e.name!=null&&this.name!==e.name&&(this.parent&&fa(this.parent._getPropertiesSchema(),this.name,e.name),this.name=e.name,t=!0),e.isRequired!=null&&this.isRequired!==e.isRequired&&(this.parent&&pa(this.parent._getPropertiesSchema(),this.name,e.isRequired),this.isRequired=e.isRequired,t=!0);let n=e.type?.name;n===`any`&&(n=void 0);let r=n!==this.schema.type;return e.type&&(ma(this.schema,e.type),this.type=e.type,this.type.isObject?this.children||=[]:this.children=void 0,t=!0),this.schema.editor&&e.editor===null?(this.schema.editor=void 0,t=!0):e.editor?(this.schema.editor=e.editor,t=!0):r&&(this.schema.editor=void 0,t=!0),e.description!==this.description&&(this.description=e.description,t=!0),e.extractable!=null&&this.extractable!==e.extractable&&(this.extractable=e.extractable,t=!0),t}getUpdateFromNameAndTypeSignature(e,t){let n=e.trim(),r=!0;n.endsWith(`?`)&&(n=n.substring(0,n.length-1).trim(),r=!1);let i=ra(t),a;return i.name===`text`?(i.name=na.string,a=`textarea`):i.name===`media`?(i.name=na.any,a=`media`):i.name===`document`?(i.name=na.any,a=`document`):a=null,{name:n,type:i,isRequired:r,editor:a}}updateFromNameAndTypeSignature(e,t){return this.update(this.getUpdateFromNameAndTypeSignature(e,t))}updateFromSignature(e){e=e.trim();let t=e.indexOf(`:`);if(t<0)throw Error(`Expecting a name and a type separated by a colon`);let n=e.substring(0,t),r=e.substring(t+1);return this.updateFromNameAndTypeSignature(n,r)}};function wa(e){let[t,n]=q(new Sa(e||{type:`object`,properties:{}}).withChangeListener(e=>{n(e.clone())}));return t}const Ta=`block text-sm sm:leading-6 rounded-md border-0 py-1.5 px-4`,Ea=`${Ta} hover:shadow-xs hover:ring-1 hover:ring-inset hover:ring-ring`,Da=`${Ta} shadow-xs ring-1 ring-inset ring-ring`;function Oa({value:e,onChange:r,onDelete:i,outlineOnHover:a=!1,editOnClick:o=!0,placeholder:s,viewer:c,editor:l,skipClickOutside:u,isEditing:d=!1,readonly:f=!1,onValidate:p}){let{on:m,off:h,isOn:g}=T(d),[_,v]=q();return n(`div`,{className:``,children:[g&&!f?t(Aa,{value:e,onSave:e=>{if(p){let t=p(e);if(t){v(t);return}else v(void 0)}r(e)&&h()},onCancel:h,editor:l,skipClickOutside:e=>u?u(e):!1}):t(ka,{value:e,onEdit:m,viewer:c,placeholder:s,outlineOnHover:a,editOnClick:o,onDelete:i,readonly:f}),_&&t(`div`,{className:`text-red-500 text-sm`,children:_})]})}function ka({viewer:e,value:i,onEdit:a,editOnClick:o,outlineOnHover:s,placeholder:c,onDelete:l,readonly:u}){let d=()=>{o&&a()},f=e=>{e.key===`Enter`&&a()},p=`invisible group-hover:visible`;return n(`div`,{role:o?`button`:void 0,tabIndex:0,onKeyUp:f,onClick:d,className:D(`flex justify-start items-center group`,s?Ea:Ta,{"cursor-pointer":o}),children:[t(e,{value:i,placeholder:c}),n(`div`,{className:`ms-auto flex gap-2`,children:[!u&&l&&t(r,{variant:`ghost`,size:`sm`,className:p,onClick:l,children:t(Se,{className:`size-4`})}),u?null:t(r,{variant:`ghost`,size:`sm`,className:p,onClick:a,children:t(L,{className:`size-4`})})]})]})}function Aa({editor:e,value:n,onSave:r,onCancel:i,skipClickOutside:a}){let[o,s]=q(n),c=K(n),[l,u]=q(null),d=()=>{r(c.current)};return t(`div`,{ref:w(d,a),children:t(`div`,{className:Da,children:t(`div`,{className:`w-full`,onClick:e=>e.stopPropagation(),children:t(e,{value:o,onChange:(e,t=!1)=>{s(e),c.current=e,t&&(l&&clearTimeout(l),u(setTimeout(()=>{r(e)},500)))},onSave:d,onCancel:i})})})})}function ja(e){return!!e.target.closest?.(`.schema-type-suggest-popup`)}function Ma({schema:e,readonly:r=!1}){let{t:i}=J();return n(`div`,{className:`space-y-1`,children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1 text-xs font-medium text-muted-foreground border-b border-border`,children:[t(`div`,{className:`flex-1 min-w-0`,children:i(`widgets.schema.propertyColumn`)}),!r&&t(`div`,{className:`shrink-0 w-28 text-end pe-1`,title:i(`widgets.schema.extractFromDocumentHint`),children:i(`widgets.schema.extractFromDocument`)}),t(`div`,{className:`w-8 shrink-0`})]}),n(`ul`,{className:``,children:[e.children.map(e=>Na(e,r)),r?null:t(Ra,{parent:e.root})]})]})}function Na(e,n){return e.isParent?t(Fa,{property:e,readonly:n},e.name):t(Pa,{node:e,readonly:n},e.name)}function Pa({node:e,readonly:n}){return t(`li`,{className:`border-b border-border/40 last:border-0`,children:t(La,{property:e,readonly:n})})}function Fa({property:e,readonly:i}){let[a,o]=q(!0),s=a?N:re;return n(`li`,{className:`border-b border-border/40 last:border-0`,children:[n(`div`,{className:`flex items-center w-full gap-1`,children:[t(`div`,{className:`flex-1 min-w-0`,children:t(La,{property:e,readonly:i})}),t(r,{variant:`ghost`,size:`icon`,onClick:()=>o(!a),"aria-label":a?`Collapse ${e.name}`:`Expand ${e.name}`,"aria-expanded":a,className:`shrink-0`,children:t(s,{className:`size-4 cn-rtl-flip`})})]}),a&&n(`ul`,{className:`ms-4 border-s border-gray-400 border-dashed`,children:[(e.children||[]).map(e=>Na(e,i)),i?null:t(Ra,{parent:e})]})]})}function Ia(e){if(!e)return`Name is required`;if(!/^[a-zA-Z0-9_]+[?]?$/.test(e))return`Only letters, numbers, underscores or question mark are allowed (a-zA-Z0-9_?)`}function La({property:e,readonly:r}){let{t:i}=J(),a=te(),o=t=>{try{t.description&&typeof t.description!=`string`&&(t.description=void 0);let n=e.getUpdateFromNameAndTypeSignature(t.name,t.type);e.update({...n,description:t.description,extractable:t.extractable})&&e.reloadTree()}catch(e){return a({status:`error`,title:i(`widgets.schema.invalidPropertyDeclaration`),description:ee(e),duration:9e3}),!1}return!0},s=t=>{e.update({extractable:t})&&e.reloadTree()},c=e.resetIsNew();return n(`div`,{className:`flex items-center gap-2 w-full min-w-0 py-0.5`,children:[t(`div`,{className:`flex-1 min-w-0`,children:t(Oa,{value:ta(e),onChange:o,onDelete:()=>{e.remove(),e.reloadTree()},editor:oa,viewer:da,outlineOnHover:!0,isEditing:c,skipClickOutside:ja,readonly:r,onValidate:e=>Ia(e.name)})}),r?e.extractable===!1?t(`div`,{className:`shrink-0 w-28 flex justify-end pe-1`,children:t(`span`,{className:`text-[10px] uppercase tracking-wide text-attention border border-attention/40 bg-attention/10 rounded px-1.5 py-0.5`,title:i(`widgets.schema.extractFromDocumentHint`),children:i(`widgets.schema.noExtract`)})}):null:t(`div`,{className:`shrink-0 w-28 flex items-center justify-end gap-1.5 pe-1`,children:t(y,{size:`sm`,value:e.extractable,onChange:s,"aria-label":`${i(`widgets.schema.extractFromDocument`)}: ${e.name}`})})]})}function Ra({parent:e}){return n(r,{variant:`ghost`,onClick:()=>{let t=e.findAvailableChildName(`new_property_`),n=e.addChild(t,{isObject:!1,isArray:!1,isNullable:!1,name:na.string},!0);n.isNew=!0,e.reloadTree()},children:[t(xe,{className:`size-4`}),`Add property`]})}function za(e){return e.isFile}function Ba(e){return e.isDirectory}function Va({onDrop:e,message:i,buttonLabel:a,allowFolders:o=!0,className:s=``}){let{t:c}=J(),l=a??c(`upload.uploadFiles`),[u,d]=q(!1),f=K(null),p=e=>{e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&d(!0)},m=e=>{e.preventDefault(),f.current&&!f.current.contains(e.relatedTarget)&&d(!1)},h=async t=>{if(t.preventDefault(),d(!1),t.dataTransfer.items&&t.dataTransfer.items.length>0){let n=Array.from(t.dataTransfer.items),r=[],i=new Set,a=async e=>{if(za(e)){let t=await new Promise(t=>{e.file(n=>{Object.defineProperty(n,"webkitRelativePath",{writable:!0,value:e.fullPath.substring(1)}),t(n)})});!t.name.startsWith(`.`)&&t.size>0&&r.push(t);let n=e.fullPath.substring(1).split(`/`).slice(0,-1).join(`/`);n&&i.add(n)}else if(Ba(e)){let t=e.createReader(),n=await new Promise(e=>{t.readEntries(t=>{e(t)})});await Promise.all(n.map(a));let r=e.fullPath.substring(1);r&&i.add(r)}};try{if(await Promise.all(n.map(e=>{let t=e.webkitGetAsEntry?e.webkitGetAsEntry():e;return t?a(t):Promise.resolve()})),r.length>0){let t=new Set(Array.from(i).map(e=>e.split(`/`)[0]).filter(Boolean)).size,n=r.length,a=``;a=t>0?c(`upload.preparingFolder`,{count:t,folderCount:t,fileCount:n}):c(`upload.preparingFiles`,{count:n}),e(r,{count:r.length,message:a})}}catch(n){console.error(`Error processing dropped files:`,n);let r=Array.from(t.dataTransfer.files);r.length>0&&e(r)}}else t.dataTransfer.files&&t.dataTransfer.files.length>0&&e(Array.from(t.dataTransfer.files))},g=t=>{if(t&&t.length>0){let n=Array.from(t);if(n.some(e=>e.webkitRelativePath?.includes(`/`))){let t=new Set(n.map(e=>e.webkitRelativePath.split(`/`)[0]).filter(Boolean)).size,r=n.length,i=c(`upload.preparingFolder`,{count:t,folderCount:t,fileCount:r});e(n,{count:n.length,message:i})}else e(n,{count:n.length,message:c(`upload.preparingFiles`,{count:n.length})})}};return n(`div`,{className:`flex flex-col items-center justify-center py-12 border-2 rounded-lg transition-colors ${u?`border-color-primary bg-color-primary/10`:`border-dashed border-color-border`} ${s}`,onDragOver:p,onDragLeave:m,onDrop:h,children:[t(Ce,{className:`h-12 w-12 mb-3 transition-colors ${u?`text-primary`:`text-muted/50`}`}),t(`p`,{className:`text-muted`,children:i}),n(`div`,{className:`flex gap-2 justify-center mt-2`,children:[t(r,{onClick:()=>{let e=document.createElement(`input`);e.type=`file`,e.multiple=!0,e.accept=`*`,e?.click(),e.onchange=()=>{g(e.files)}},children:l}),o&&t(r,{onClick:()=>{let e=document.createElement(`input`);e.type=`file`,e.multiple=!0,e.accept=`*`,e.webkitdirectory=!0,e?.click(),e.onchange=()=>{g(e.files)}},children:c(`upload.selectFolder`)})]})]})}function Ha({title:e,count:r,icon:i=t(M,{className:`h-4 w-4 text-green-500`}),items:a}){let{t:o}=J(),[s,c]=q(!1),l=ke();return n(`div`,{className:`border border-color-border rounded-md overflow-hidden`,children:[n(`button`,{type:`button`,"aria-expanded":s,"aria-controls":l,className:`w-full flex items-center justify-between p-3 bg-color-muted/10 cursor-pointer text-start bg-transparent border-0 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,onClick:()=>c(!s),children:[n(`span`,{className:`flex items-center`,children:[t(`span`,{className:`me-2`,children:i}),t(`span`,{className:`font-medium`,children:e}),t(`span`,{className:`ms-2 px-2 py-0.5 bg-color-muted/20 rounded-full text-xs`,children:r})]}),t(`span`,{className:`text-muted`,"aria-hidden":`true`,children:t(`svg`,{className:`h-5 w-5 transition-transform ${s?`transform rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,"aria-hidden":`true`,children:t(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})})]}),s&&t(`div`,{id:l,className:`p-3 border-t border-color-border max-h-48 overflow-y-auto`,children:a.length>0?t(`ul`,{className:`space-y-1`,children:a.map(e=>t(`li`,{className:`text-sm py-1 px-2 rounded hover:bg-color-muted/10`,children:e},e))}):t(`div`,{className:`text-sm text-muted py-2`,children:o(`upload.noItems`)})})]})}function Ua({files:e,className:r=``,location:i,collection:a}){let{t:o}=J(),s=e.filter(e=>e.status===`success`),c=e.filter(e=>e.status===`updated`),l=e.filter(e=>e.status===`skipped`),u=e.filter(e=>e.status===`failed`),d=s.length,f=c.length,p=l.length,m=u.length,h=e.length;return n(`div`,{className:`flex flex-col py-2 ${r}`,children:[n(`div`,{className:`flex items-center mb-4`,children:[t(`div`,{className:`size-8 me-4 rounded-full bg-success/10 flex items-center justify-center`,children:t(M,{className:`size-4 text-success`})}),t(`div`,{children:n(`p`,{className:`text-muted`,children:[o(`upload.filesProcessed`,{count:h}),a?o(`upload.inCollection`,{collection:a}):``,i?o(`upload.inFolder`,{location:i}):``]})})]}),n(`div`,{className:`space-y-3 mt-2`,children:[d>0&&t(Ha,{title:o(`upload.successfullyUploaded`),count:d,icon:t(M,{className:`h-4 w-4 text-green-500`}),items:s.map(e=>e.name)}),f>0&&t(Ha,{title:o(`upload.successfullyUpdated`),count:f,icon:t(M,{className:`h-4 w-4 text-blue-500`}),items:c.map(e=>e.name)}),p>0&&t(Ha,{title:o(`upload.skippedAlreadyExisted`),count:p,icon:t(k,{className:`h-4 w-4 text-amber-500`}),items:l.map(e=>e.name)}),m>0&&t(Ha,{title:o(`upload.failedToUpload`),count:m,icon:t(Te,{className:`h-4 w-4 text-red-500`}),items:u.map(e=>e.name)})]})]})}const Wa=`#text`,Ga=`#comment`,Ka=`#cdata`,qa=`DECLARATION_TAG`,Ja={tagColor:`#d43900`,textColor:`#333`,attributeKeyColor:`#2a7ab0`,attributeValueColor:`#008000`,separatorColor:`#333`,commentColor:`#aaa`,cdataColor:`#1d781d`,fontFamily:`monospace`},Ya={attributeKeyColor:`#FFD700`,attributeValueColor:`#FF4500`,tagColor:`#87CEFA`,textColor:`#00FF00`,separatorColor:`#FFD700`,commentColor:`#BEBEBE`,cdataColor:`#33CC66`,fontFamily:`monospace`},Xa=V({theme:Ja,collapsible:!1,indentSize:2}),Za=()=>U(Xa),Qa=new tt({preserveOrder:!0,ignoreAttributes:!1,attributeNamePrefix:``,allowBooleanAttributes:!0,commentPropName:Ga,cdataPropName:Ka,parseTagValue:!1});function $a(e){try{let t=new DOMParser().parseFromString(e,`application/xml`),n=t.documentElement.localName===`parsererror`?t.documentElement:void 0;if(n)throw Error(n.textContent?.trim()||`Invalid XML!`);let r=Qa.parse(e);if(e.trim().length>0&&r.length===0)throw Error(`Invalid XML!`);return{json:r,valid:!0}}catch(e){return{json:null,valid:!1,errorMessage:`Fail to parse: ${e instanceof Error?e.message:String(e)}`}}}function eo(e){return G(()=>$a(e),[e])}function to(e){let{indentation:r,children:i,isInline:a}=e,{theme:o}=Za();return n(`div`,{style:{color:o.cdataColor},children:[t(`span`,{children:`${r}<![CDATA[`}),i,t(`span`,{children:`${a?``:r}]]>`})]})}function no(e){let{collapsible:n,theme:r}=Za(),{collapsed:i}=e;return n?t(`span`,{style:{position:`relative`},children:t(`span`,{style:{position:`absolute`,right:`0`,border:0,padding:0,background:`none`},children:t(ro,{fill:r.separatorColor,style:{transform:`rotate(${i?0:90}deg)`,transition:`transform 0.2s`}})})}):null}function ro({...e}){return t(`svg`,{width:`16px`,height:`16px`,viewBox:`0 0 24 24`,"aria-hidden":`true`,...e,children:t(`path`,{d:`M9 17.898C9 18.972 10.2649 19.546 11.0731 18.8388L17.3838 13.3169C18.1806 12.6197 18.1806 11.3801 17.3838 10.6829L11.0731 5.16108C10.2649 4.45388 9 5.02785 9 6.1018V17.898Z`})})}function io(e){let{collapsible:t,initialCollapsedDepth:n}=Za(),[r,i]=q(()=>nt(n)||!t?!1:e>=n);return W(()=>{i(nt(n)||!t?!1:e>=n)},[n,e,t]),{collapsed:r,buttonProps:t?{onClick:()=>i(e=>!e),role:`button`,style:{cursor:`pointer`}}:{}}}function ao(e){let{indentation:r,children:i,isInline:a,level:o}=e,{theme:s}=Za(),{collapsed:c,buttonProps:l}=io(o);return n(`div`,{style:{color:s.commentColor},children:[n(`span`,{...l,children:[t(`span`,{children:r}),t(no,{collapsed:c}),t(`span`,{children:`<!-- `})]}),!c&&i,c&&`...`,t(`span`,{children:`${a||c?` `:r}-->`})]})}function oo(e){let{attributes:r}=e,{theme:i}=Za();return r?t(`span`,{children:Object.entries(r).map(([e,r])=>n(`span`,{children:[t(`span`,{style:{color:i.attributeKeyColor},children:` ${e}`}),t(`span`,{style:{color:i.separatorColor},children:`=`}),t(`span`,{style:{color:i.attributeValueColor},children:`"${r}"`})]},`attribute-${e}`))}):null}function so(e){let{indentation:r,tagKey:i,attributes:a}=e,{theme:o}=Za();return n(`div`,{children:[t(`span`,{style:{color:o.separatorColor},children:`${r}<?`}),t(`span`,{style:{color:o.tagColor},children:`${i.slice(1)}`}),t(oo,{attributes:a}),t(`span`,{style:{color:o.separatorColor},children:`?>`})]})}function co(e,t){return Array(t*e+1).join(` `)}function lo(e){return typeof e==`string`&&e.includes(`
25
- `)}function uo(e){return typeof e!=`string`&&e.length===1&&`#text`in e[0]&&!lo(e[0][`#text`])}function fo(e){switch(e){case Wa:case Ka:case Ga:return e;default:return e.startsWith(`?`)?qa:`TAG`}}function po(e){let t=e[`:@`],n=rt(e,`:@`),[[r,i]]=Object.entries(n);return{attributes:t,tagKey:r,subElements:i,type:fo(r)}}function mo(e){return e?Object.keys(e).length>0:!1}function ho(r){let{indentation:i,tagKey:a,attributes:o,children:s,isInline:c,hasChildren:l,level:u}=r,{collapsed:d,buttonProps:f}=io(u),{theme:p}=Za();return n(`div`,{children:[n(`span`,{...f,children:[t(`span`,{children:i}),t(no,{collapsed:d}),t(`span`,{style:{color:p.separatorColor},children:`<`}),t(`span`,{style:{color:p.tagColor},children:`${a}`}),!d&&t(oo,{attributes:o}),d&&mo(o)&&` ...`,t(`span`,{style:{color:p.separatorColor},children:l?`>`:` />`})]}),l&&n(e,{children:[!d&&s,d&&`...`,t(`span`,{style:{color:p.separatorColor},children:`${c||d?``:i}</`}),t(`span`,{style:{color:p.tagColor},children:`${a}`}),t(`span`,{style:{color:p.separatorColor},children:`>`})]})]})}function go(e){let{hasSiblings:n,text:r,indentation:i,isText:a}=e,{theme:o}=Za(),s=a?{color:o.textColor}:void 0;return lo(r)||n?t(`div`,{style:s,children:r.split(`
26
- `).filter(e=>!!e.trim()).map((e,n)=>t(`div`,{children:`${i}${e.trim()}`},`line-${n}`))}):t(`span`,{style:s,children:r})}function _o(n){let{elements:r,level:i=0,isText:a=!0}=n,{indentSize:o}=Za();return!Array.isArray(r)||r.length===0?null:t(e,{children:r.map((e,n)=>{let{tagKey:s,attributes:c,subElements:l,type:u}=po(e),d=r.length>1,f=co(o,i),p=`${i}-${n}`,m=uo(l);switch(u){case Wa:return t(go,{text:l,indentation:f,hasSiblings:d,isText:a},p);case Ga:return t(ao,{isInline:m,indentation:f,level:i,children:t(_o,{elements:l,level:i+1,isText:!1})},p);case Ka:return t(to,{indentation:f,isInline:m,children:t(_o,{elements:l,level:i+1,isText:!1})},p);case qa:return t(so,{indentation:f,tagKey:s,attributes:c},p);default:return t(ho,{indentation:f,tagKey:s,attributes:c,isInline:m,hasChildren:l.length>0,level:i,children:t(_o,{elements:l,level:i+1})},p)}})})}function vo(){return t(`div`,{children:`Invalid XML!`})}function yo(e){let{theme:n,xml:r,collapsible:i=!1,indentSize:a=2,invalidXml:o,initalCollapsedDepth:s,initialCollapsedDepth:c}=e,[l,u]=q(()=>document.documentElement.classList.contains(`dark`));W(()=>{let e=document.documentElement,t=new MutationObserver(()=>{u(e.classList.contains(`dark`))});return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let d=G(()=>({...l?Ya:Ja,...n}),[l,n]),{json:f,valid:p}=eo(r),m=G(()=>({theme:d,collapsible:i,indentSize:a,initialCollapsedDepth:c??s}),[d,i,a,s,c]);return p?t(Xa.Provider,{value:m,children:t(`div`,{className:`rxv-container`,style:{whiteSpace:`pre-wrap`,fontFamily:d.fontFamily,overflowWrap:`break-word`},children:t(_o,{elements:f})})}):o||t(vo,{})}export{fn as AgentResourceResolverProvider,Ot as ArrayPropertySchema,Jn as ArtifactContentRenderer,Xi as ArtifactEditingSurface,ur as ChartCodeBlockHandler,Z as CodeBlockErrorBoundary,Ln as CodeBlockHandlerProvider,X as CodeBlockPlaceholder,Zn as CodeBlockRendererProvider,ji as CollaborativeMarkdownRenderer,Va as DropZone,pr as ExpandCodeBlockHandler,at as FieldSetContextProvider,ft as Form,st as FormContext,ut as FormContextProvider,Ct as FormError,St as FormHelper,xt as FormLabel,mt as GeneratedForm,dt as Input,zt as JSONCode,Xt as JSONDisplay,an as JSONEditor,sn as JSONSwitcher,un as JSONTable,Ut as JSONView,Lt as ManageObjectEntry,It as ManagedListProperty,Nt as ManagedObject,Mt as ManagedObjectBase,Pt as ManagedObjectProperty,Ft as ManagedProperty,Rt as ManagedScalarEntry,Sa as ManagedSchema,br as MarkdownFigure,Sr as MarkdownImage,wr as MarkdownLink,fi as MarkdownRenderer,dr as MermaidCodeBlockHandler,rr as MermaidDiagram,rn as MonacoEditor,jt as Node,Zi as Progress,Qi as PropertiesView,oa as PropertyEditor,sa as PropertyNameEditor,Et as PropertySchema,da as PropertyViewer,_t as ScalarField,Tt as Schema,Ma as SchemaEditor,Ca as SchemaNode,$i as SvgIcon,Ha as UploadResultCategory,Ua as UploadSummary,nn as VEditorApi,yo as XMLViewer,Ki as applyArtifactRefreshChanges,Di as applyMarkdownEditingChange,kt as computeTitleFromName,hr as createDefaultCodeBlockHandlers,Si as createMarkdownBlockAnchor,ea as createSvgIcon,Ui as createUnifiedLineDiff,Li as diffTextSegments,Pi as diffWordSegments,Oi as formatMarkdownEditingAction,ta as getEditableSchemaProperty,on as getJSONEditorValue,Ri as getTextLineChangeRegions,Gi as isArtifactRefreshEvent,mr as isExpandLanguage,or as isIncompleteJson,hn as parseAgentResourceHref,vr as parseUrlScheme,Hi as rebaseTextChanges,Ht as renderJsonLine,pn as useAgentResourceResolver,ar as useArtifactContent,$n as useCodeBlockComponent,Rn as useCodeBlockContext,Qn as useCodeBlockRendererRegistry,ot as useFieldSet,lt as useForm,yr as useResolvedUrl,wa as useSchema,Ia as validatePropertyName};
23
+ `);if(!(n.maxChars!==void 0&&u.length>n.maxChars))return u}const qi=De(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownDocumentEditor})));function Ji(e,t){return e?.path===t?e.event_class===`artifact_updated`||e.event_class===`activity`&&e.tool_status===`completed`&&(e.tool===`edit_artifact`||e.tool===`write_artifact`):!1}function Yi(e,t){if(!Array.isArray(t?.changes)||t.changes.length===0)return;let n=e;for(let e of t.changes){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(t.operation!==`replace`||typeof t.before!=`string`||typeof t.after!=`string`||!n.includes(t.before))return;if(t.replace_all===!0)n=n.split(t.before).join(t.after);else{if(n.indexOf(t.before)!==n.lastIndexOf(t.before))return;n=n.replace(t.before,t.after)}}return n}function Xi(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function Zi({regions:e,totalLines:n,onNavigate:r}){let{t:i}=J();return e.length===0?null:t(`nav`,{className:`absolute inset-y-12 end-1 z-10 w-3 rounded-full border border-mixer-muted/25 bg-muted/20`,"aria-label":i(`agent.changeRuler`),children:e.map(e=>{let a=e.startLine/Math.max(1,n)*100,o=Math.max(1.5,(e.endLine-e.startLine+1)/Math.max(1,n)*100);return t(x,{description:i(`agent.changedRegion`,{line:e.startLine+1}),asChild:!0,children:t(`button`,{type:`button`,className:`absolute inset-x-0 rounded-full bg-attention transition-colors hover:bg-info focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-info`,style:{top:`${Math.min(98.5,a)}%`,height:`${Math.min(100-a,o)}%`},onClick:()=>r(e.startLine),"aria-label":i(`agent.changedRegion`,{line:e.startLine+1})})},`${e.startLine}:${e.endLine}`)})})}function Qi(e,t){return Vi(e,t)}function $i({runId:e,path:a,initialContent:o=``,refreshKey:s=0,refreshDetails:c,readOnly:l=!1,allowComments:u=!1,viewMode:f=`components`,baselineContent:p,className:m,onAction:h,onSendMessage:g,onSendChangesToAgent:v,hasUnsentChanges:y=!1,isSendingChanges:ee=!1,sendChangesDisabled:b=!1,toolbarStatus:x,onContentChange:C,onDocumentEdit:w,onSaveStatusChange:T,flushChangesRef:D}){let{client:O}=Re(),{t:k}=J(),A=E(),[j,M]=q(o),[N,re]=q(),[ie,ae]=q(),[oe,se]=q(0),[ce,le]=q(!!e),[de,P]=q(!1),[fe,pe]=q(!1),[me,he]=q(),[ge,_e]=q(),[ve,ye]=q(!1),be=!l||u,xe=f!==`document`||ge?`idle`:de||fe?`saving`:N?`saved`:`idle`;W(()=>{T?.(xe)},[xe,T]);let F=K(j),I=K(N),L=K(0),R=K(void 0),z=K(void 0),Se=K(!1),Ce=K(void 0),we=K(()=>Promise.resolve(!1)),Te=K(!1),B=K(!1),V=K(null),De=K(N),Oe=K(o),U=K(void 0),ke=K(o),Ae=K(null),je=G(()=>Qi(p??j,j),[p,j]),Me=G(()=>j.split(`
24
+ `).length,[j]),Ne=H(e=>{U.current=e,_e(e)},[]);W(()=>{F.current=j},[j]),W(()=>{I.current=N},[N]),W(()=>{f===`document`&&(B.current=!1,Te.current=!1)},[f]);let Pe=H(async t=>{if(!e)return;let n=++L.current;le(!0),he(void 0);for(let r=0;r<=60;r++)try{let t=await O.agents.getArtifactContent(e,a);if(L.current!==n)return;let r=F.current;r&&r!==t.content&&(ae(r),se(e=>e+1)),F.current=t.content,I.current=t.generation,ke.current=t.content,!Te.current&&z.current===void 0&&!Se.current&&(De.current=t.generation,Oe.current=t.content),M(t.content),re(t.generation),he(void 0),le(!1),C?.(t.content,t.generation);return}catch(e){if(L.current!==n||!t||Xi(e)!==404||r===60){if(L.current!==n)return;he(te(e,k(`agent.failedToLoadArtifact`))),le(!1);return}await new Promise(e=>setTimeout(e,500))}},[O,C,a,e,k]);W(()=>(L.current++,F.current=o,I.current=void 0,ke.current=o,De.current=void 0,Oe.current=o,U.current=void 0,Te.current=!1,B.current=!1,M(o),re(void 0),ae(void 0),he(void 0),_e(void 0),ye(!1),pe(!1),le(!!e),e&&Pe(!0),()=>{L.current++}),[o,Pe,e]),W(()=>{if(!e||s<=0||U.current)return;let t=F.current,n=Yi(t,c);n!==void 0&&n!==t&&(F.current=n,I.current=void 0,ae(t),se(e=>e+1),M(n),re(void 0),C?.(n)),Pe(!1)},[Pe,C,c,s,e]);let Fe=H((e,t)=>{let n=F.current;F.current=e,I.current=t,Oe.current=e,De.current=t,z.current=void 0,Ne(void 0),V.current?.getMarkdown()!==e&&V.current?.commands.setContent(e,{contentType:`markdown`,emitUpdate:!1}),n!==e&&(ae(n),se(e=>e+1)),M(e),re(t),pe(!1),C?.(e,t)},[C,Ne]),Ie=H(async(t,n,r)=>{if(!e)return!1;F.current=n,z.current=void 0,M(n),pe(!1),ye(!0);let i,o;try{let s=await O.agents.getArtifactContent(e,a);i=s.content,o=s.generation,ke.current=s.content;let c=Gi(t,n,s.content);if(c.status===`conflict`)return Ne({baseContent:t,localContent:n,remoteContent:s.content,remoteGeneration:s.generation,pendingAction:r}),!1;let l=s.generation;if(c.content!==s.content)try{l=(await O.agents.updateArtifactContent(e,a,{content:c.content,generation:s.generation})).generation}catch(e){if(Xi(e)===412)return Ne({baseContent:s.content,localContent:c.content,remoteContent:s.content,remoteGeneration:s.generation,pendingAction:r}),!1;throw e}return Fe(c.content,l),A({status:`success`,title:k(`agent.artifactConflictRebased`),duration:3e3}),{content:c.content,generation:l}}catch(e){return Ne({baseContent:t,localContent:n,remoteContent:i,remoteGeneration:o,pendingAction:r}),A({status:`error`,title:k(`agent.artifactConflictTitle`),description:te(e,k(`agent.failedToLoadArtifact`)),duration:5e3}),!1}finally{ye(!1)}},[Fe,O.agents,a,e,k,A,Ne]),Le=H(async t=>{if(t.action===`comment`){await h?.(t);return}if(U.current){A({status:`warning`,title:k(`agent.artifactConflictTitle`),duration:3e3});return}if(!e||!I.current){A({status:`warning`,title:k(`agent.artifactEditingUnavailable`),duration:3e3});return}let n=F.current,r=Ai(n,t);if(r===void 0){A({status:`error`,title:k(`agent.documentEditApplyFailed`),description:k(`agent.documentEditApplyFailedDescription`),duration:5e3});return}try{let i=await O.agents.updateArtifactContent(e,a,{content:r,generation:I.current});F.current=r,I.current=i.generation,Oe.current=r,De.current=i.generation,ae(n),se(e=>e+1),M(r),re(i.generation),C?.(r,i.generation),await h?.({...t,applied:!0,base_version:i.generation}),ke.current=r}catch(e){if(Xi(e)===412){let e=await Ie(n,r,t);e&&(await h?.({...t,applied:!0,base_version:e.generation}),ke.current=e.content);return}A({status:`error`,title:k(`agent.documentEditApplyFailed`),description:te(e,k(`store.errorSavingTextDefault`)),duration:5e3})}},[O,h,C,a,Ie,e,k,A]),ze=H(()=>{if(!e)return Promise.resolve(!1);if(Ce.current)return Ce.current;let t=(async()=>{Se.current=!0,P(!0);try{for(;z.current!==void 0;){let t=z.current;z.current=void 0;let n=De.current;if(!n)throw Error(k(`agent.artifactEditingUnavailable`));let r=await O.agents.updateArtifactContent(e,a,{content:t,generation:n});I.current=r.generation,De.current=r.generation,Oe.current=t,re(r.generation),C?.(F.current,r.generation)}return pe(!1),!0}catch(e){return Xi(e)===412?!!await Ie(Oe.current,F.current):(A({status:`error`,title:k(`agent.documentEditApplyFailed`),description:te(e,k(`store.errorSavingTextDefault`)),duration:5e3}),!1)}finally{Se.current=!1,P(!1)}})();return Ce.current=t,t.finally(()=>{Ce.current===t&&(Ce.current=void 0)}),t},[O.agents,C,a,Ie,e,k,A]);we.current=ze;let Be=H(async()=>{R.current!==void 0&&(clearTimeout(R.current),R.current=void 0);let t=V.current?.getMarkdown();t!==void 0&&t!==F.current&&(F.current=t,M(t),C?.(t,I.current),z.current=t);let n=U.current;if(n&&!await Ie(n.baseContent,F.current))return!1;for(;z.current!==void 0||Ce.current;)if(!await ze())return!1;if(!e||!I.current)return!1;let r=ke.current;return ke.current=F.current,{previous:r,current:F.current}},[C,ze,Ie,e]);W(()=>{if(D)return D.current=Be,()=>{D.current===Be&&(D.current=null)}},[D,Be]);let Ve=H(e=>{if(e===F.current||Te.current&&z.current===void 0&&!Se.current&&e===Oe.current)return;if(!B.current){F.current=e,M(e);return}F.current=e,M(e),w?.(),C?.(e,I.current);let t=U.current;if(t){Ne({...t,localContent:e}),pe(!1);return}pe(!0),z.current=e,R.current!==void 0&&clearTimeout(R.current),R.current=setTimeout(()=>{R.current=void 0,ze()},400)},[C,w,ze,Ne]),He=H(e=>{Te.current=e,e&&(B.current=!0),(e||z.current===void 0&&!Se.current)&&(De.current=I.current,Oe.current=F.current)},[]),Ue=H(async()=>{let e=U.current;if(!e||ve)return;let t=await Ie(e.baseContent,F.current,e.pendingAction);t&&e.pendingAction&&(await h?.({...e.pendingAction,applied:!0,base_version:t.generation}),ke.current=t.content)},[ve,h,Ie]),We=H(e=>{let t=Ae.current?.querySelector(`.vertesia-markdown-document-editor-content`);if(!t)return;let n=Math.min(1,e/Math.max(1,Me-1));t.scrollTo({top:n*Math.max(0,t.scrollHeight-t.clientHeight),behavior:`smooth`})},[Me]);return W(()=>()=>{R.current!==void 0&&clearTimeout(R.current);let e=V.current?.getMarkdown();e!==void 0&&e!==F.current&&(F.current=e,z.current=e),z.current!==void 0&&we.current()},[]),n(`div`,{className:m??`relative h-full min-h-0 overflow-y-auto px-4 py-3`,children:[ge?t(`div`,{className:`absolute inset-x-4 top-3 z-30`,role:`alert`,children:t(d,{status:`warning`,title:k(`agent.artifactConflictTitle`),className:`shadow-lg`,children:n(`div`,{className:`space-y-3`,children:[t(`p`,{children:k(`agent.artifactConflictDescription`)}),t(`div`,{className:`flex justify-end`,children:n(r,{variant:`outline`,size:`sm`,disabled:ve,onClick:()=>void Ue(),children:[ve?t(_,{size:`sm`}):null,k(`agent.artifactConflictRetry`)]})})]})})}):null,ce&&!j?t(i,{className:`h-full min-h-[200px]`,children:t(_,{size:`lg`})}):me&&!j?n(i,{className:`h-full min-h-[200px] flex-col gap-3 text-center text-muted`,children:[t(`span`,{children:me}),t(r,{variant:`outline`,size:`sm`,onClick:()=>void Pe(!1),children:k(`agent.retry`)})]}):f===`document`?t(Ee,{fallback:t(i,{className:`h-full min-h-[200px]`,children:t(_,{size:`lg`})}),children:t(`div`,{className:`flex h-full min-h-0 flex-col`,children:n(`div`,{ref:Ae,className:`relative min-h-0 flex-1`,children:[t(qi,{value:j,onChange:Ve,artifactRunId:e,editable:!l&&!!e,externalValueSync:`when-blurred`,onFocusChange:He,onEditor:e=>{V.current=e},onSendComment:g&&e&&!ge&&be?g:void 0,onSendChangesToAgent:v,hasUnsentChanges:y,isSendingChanges:ee,sendChangesDisabled:b||!e||!!ge,toolbarStatus:x,contentClassName:`pe-5`}),t(Zi,{regions:je,totalLines:Me,onNavigate:We}),!T&&xe!==`idle`?n(`div`,{className:S(`pointer-events-none absolute bottom-3 end-6 flex items-center gap-1.5 rounded-full`,`border border-mixer-muted/25 bg-background/90 px-2.5 py-1 text-[11px] shadow-sm`,de||fe?`text-muted`:`text-success`),children:[de||fe?t(_,{size:`sm`}):t(ne,{className:`size-3`}),k(de||fe?`agent.savingWorkingCopy`:`agent.savedToWorkingCopy`)]}):null]})})}):t(`div`,{className:`vprose prose-sm mx-auto max-w-5xl`,children:t(Pi,{artifactRunId:e,resource:{kind:`agent_artifact`,run_id:e??`pending`,path:a},baseVersion:N,readOnly:l||!e||!!ge,allowComments:be&&!!e&&!ge,highlightChangesFrom:ie,highlightVersion:oe,onAction:Le,children:j})}),ce&&j?t(`div`,{className:`absolute end-3 top-3 rounded-full bg-background/80 p-2 shadow-sm`,children:t(ue,{className:`size-4 animate-pulse text-muted`})}):null]})}function ea({percent:e}){return t(`div`,{className:`w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700`,children:t(`div`,{className:`bg-blue-600 h-2.5 rounded-full`,style:{width:`${e}%`}})})}function ta({className:e,properties:r}){return t(ee,{className:e,children:t(`tbody`,{children:r.map(e=>n(`tr`,{children:[n(`td`,{className:`w-1/3 font-semibold gap-2`,children:[t(`span`,{children:e.name}),e.description&&t(x,{description:e.description,placement:`top`,children:t(fe,{className:`size-3 ms-2 text-muted-foreground`})})]}),t(`td`,{className:`w-2/3`,children:e.value??`undefined`})]},e.name))})})}function na({content:e,...n}){let r=K(null);return W(()=>{if(!r.current)return;let t=new DOMParser().parseFromString(e,`image/svg+xml`).querySelector(`svg`);if(!t){console.warn(`SvgIcon: No <svg> element found in provided string`),r.current.innerHTML=``;return}Object.entries(n).forEach(([e,n])=>{if(n==null)return;let r=e===`className`?`class`:e;t.setAttribute(r,String(n))}),r.current.innerHTML=``,r.current.appendChild(t)}),t(`span`,{ref:r})}function ra(e){return n=>t(na,{content:e,...n})}function ia(e){return{name:e.getNameSignature(),type:e.getTypeSignature(),description:e.description,extractable:e.extractable}}var aa;(function(e){e.string=`string`,e.number=`number`,e.integer=`integer`,e.boolean=`boolean`,e.object=`object`,e.any=`any`,e.text=`text`,e.media=`media`,e.document=`document`})(aa||={});function oa(e){e=e.trim();let t=!1,n=!1;e.endsWith(`?`)&&(n=!0,e=e.substring(0,e.length-1).trim()),e.endsWith(`[]`)&&(t=!0,e=e.substring(0,e.length-2).trim());let r=aa[e];if(!r)throw Error(`Unknown type "${e}"`);return{name:r,isArray:t,isNullable:n,isObject:r===aa.object}}function sa(){let e=Object.values(aa),t=[...e];for(let n of e)t.push(`${n}[]`);return e.sort(),t}const ca=sa();function la({value:e,onChange:i,onCancel:a,onSave:o}){let{t:s}=J(),[c,l]=q(!1);return e?n(`div`,{className:`flex items-center`,children:[t(`div`,{className:`flex-1`,children:t(ua,{value:e.name,onChange:t=>{i({...e,name:t})},onCancel:a,onSave:o})}),t(`div`,{className:`px-1 font-semibold`,children:`:`}),t(`div`,{className:`flex-1`,children:t(da,{value:e.type,onChange:t=>{i({...e,type:t})},onCancel:a,onSave:o})}),n(`div`,{children:[t(r,{variant:`ghost`,size:`xs`,onClick:()=>l(!0),title:s(`widgets.schema.editDescription`),children:t(A,{className:`size-4`})}),t(fa,{value:e.description,isOpen:c,onClose:t=>{t!==void 0&&typeof t==`string`&&i({...e,description:t},!0),l(!1)}})]})]}):null}function ua({value:e,onChange:n,onCancel:r,onSave:i}){let a=K(null);return W(()=>{a.current?.focus()},[]),t(`input`,{onKeyUp:e=>{switch(e.key){case`Enter`:i?.();break;case`Escape`:r?.();break}},ref:a,value:e,onChange:e=>{n(e.target.value)},className:v.INPUT_UNSTYLED,style:{fontSize:`inherit`,width:``,display:`inline`}})}function da({value:e,onChange:n,onCancel:r,onSave:i}){return t(g,{className:v.INPUT_UNSTYLED,options:ca,value:e||``,onBlur:()=>{i?.()},onChange:n,onKeyDown:(e,t)=>{t||(e.key===`Enter`?i?.():e.key===`Escape`&&r?.())},popupClass:`schema-type-suggest-popup z-90`})}function fa({value:e,isOpen:r,onClose:i}){let{t:a}=J();return n(f,{isOpen:r,onClose:i,children:[t(h,{children:a(`widgets.schema.editDescription`)}),t(pa,{value:e,onSave:i})]})}function pa({value:i,onSave:a}){let{t:o}=J(),s=K(null),[c,l]=q(i||``);return W(()=>{s.current?.focus()},[]),n(e,{children:[t(p,{className:`h-max`,children:t(`textarea`,{ref:s,className:`dark:bg-gray-800 w-full h-full dark:text-white`,value:c,onChange:e=>l(e.target.value)})}),t(m,{children:t(r,{onClick:()=>a(c),children:o(`store.saveChanges`)})})]})}function ma({value:e}){let{t:r}=J();if(!e)return null;let i=e.extractable===!1;return n(`div`,{className:`w-full flex items-baseline gap-2 min-w-0`,children:[t(`div`,{className:`truncate`,children:e.name||``}),t(`div`,{className:`text-sm text-muted shrink-0`,children:e.type||``}),i&&t(`span`,{className:`shrink-0 text-[10px] uppercase tracking-wide text-attention border border-attention/40 bg-attention/10 rounded px-1.5 py-0.5`,title:r(`widgets.schema.extractFromDocumentHint`),children:r(`widgets.schema.noExtract`)})]})}function ha(e,t,n){if(e.properties){let r=e.properties,i={};for(let e of Object.keys(r)){let a=r[e];e===t?i[n]=a:i[e]=a}e.properties=i}e.required&&=e.required.map(e=>e===t?n:e)}function ga(e,t,n){if(Array.isArray(e.required)){let r=e.required.indexOf(t);n?r<0&&e.required.push(t):r>-1&&e.required.splice(r,1)}else n&&(e.required=[t])}function _a(e,t){let n=t.name===`any`?void 0:t.isNullable?[t.name,`null`]:t.name;if(t.isArray)if(e.type=`array`,e.properties=void 0,!e.items||Array.isArray(e.items))e.items={type:n,properties:t.isObject?{}:void 0};else{let r=e.items;r.type=n,t.isObject&&!r.properties&&(r.properties={})}else e.type=n,e.items=void 0,t.isObject?e.properties||={}:e.properties=void 0}function va(e,t){e.properties&&(delete e.properties[t],Array.isArray(e.required)&&(e.required=e.required.filter(e=>e!==t)))}function ya(e,t,n,r=!1){if(e.type!==`object`)throw Error(`Cannot add property to a non-object schema`);e.properties||={};let i={};return _a(i,n),e.properties[t]=i,r&&(Array.isArray(e.required)?Ca(e.required,t):e.required=[t]),i}function ba(e){let t=!1,n=!1,r,i=e.type;if(Array.isArray(i))for(let e of i)e===`null`?t=!0:r||=e;else r=i;r||=`any`,r===`array`&&(n=!0,r=xa(e.items));let a=r;switch(e.editor){case`textarea`:a=`text`;break;case`media`:a=`media`;break;case`document`:a=`document`;break}return{isNullable:t,isArray:n,isObject:r===`object`,name:a}}function xa(e){if(!e)return`any`;let t;return t=Sa(Array.isArray(e)?e[0].type:e.type),(t===`array`||t===`null`)&&(t=`any`),t}function Sa(e){return e?Array.isArray(e)?e.find(e=>e!==`null`)||`any`:e:`any`}function Ca(e,t){e.includes(t)||e.push(t)}let wa=0;var Ta=class e{source;onChange=()=>{};schema;root;constructor(e,t){e?typeof e==`string`?this.schema=JSON.parse(e):this.schema=e:this.schema={title:t,type:`object`,properties:{}},this.schema.properties||(this.schema.properties={}),this.root=new Ea(``,this.schema,this),this.root.loadChildren()}get isEmpty(){return!this.root.children||this.root.children.length===0}get children(){return this.root.children??[]}reload(){return this.root=new Ea(``,this.schema,this),this.root.loadChildren(),this.onChange?.(this),this}withSource(e,t){return this.source={uri:t,name:e},this}withChangeListener(e){return this.onChange=e,this}replaceSchema(e){e?this.schema=e:this.schema={title:this.schema.title,type:`object`,properties:{}},this.reload()}clone(){let t=new e(this.schema);return t.source=this.source,this.onChange&&t.withChangeListener(this.onChange),t}},Ea=class e{schema;loader;parent;name;isRequired=!1;type;children;constructor(e,t,n,r){if(this.schema=t,this.loader=n,this.parent=r,this.name=e,this.type=ba(t),this.parent){let t=this.parent._getPropertiesSchema().required;this.isRequired=t&&Array.isArray(t)?t.includes(e):!1}}get title(){return typeof this.schema.title==`string`?this.schema.title:void 0}set title(e){this.schema.title=e}get description(){return this.schema.description}set description(e){this.schema.description=e}get extractable(){return this.schema[`x-extract`]!==!1}set extractable(e){e?delete this.schema[`x-extract`]:this.schema[`x-extract`]=!1}get isParent(){return this.type.isObject}get isNew(){return!!this.schema.isNew}set isNew(e){e?this.schema.isNew=!0:delete this.schema.isNew}resetIsNew(){let e=this.isNew;return this.isNew=!1,e}getNameSignature(){return`${this.name}${this.isRequired?``:`?`}`}getTypeSignature(){return`${this.type.name}${this.type.isArray?`[]`:``}${this.type.isNullable?`?`:``}`}getSignature(){return`${this.getNameSignature()}: ${this.getTypeSignature()}`}reloadTree(){this.loader.reload()}loadChildren(){this.children=[];let e=this.schema.items?.properties;this.schema.items&&e?this._loadChildren(e,this.children):this.schema.properties&&this._loadChildren(this.schema.properties,this.children)}_loadChildren(t,n){for(let r of Object.keys(t)){let i=t[r],a=new e(r,i,this.loader,this);n.push(a),a.isParent&&a.loadChildren()}}_getPropertiesSchema(){return this.type.isArray&&this.type.isObject?this.schema.items:this.schema}findAvailableChildName(e){let t=this._getPropertiesSchema().properties||{},n;do n=e+ ++wa;while(t[n]);return n}addChild(t,n,r=!1){if(!this.type.isObject)throw Error(`Cannot add child to a non object node`);this.children||=[];let i=ya(this._getPropertiesSchema(),t,n,r),a=new e(t,i,this.loader,this);return this.children.push(a),a}remove(){return this.parent?.type.isObject?(va(this.parent._getPropertiesSchema(),this.name),this.parent.children&&(this.parent.children=this.parent.children.filter(e=>e.name!==this.name)),!0):!1}update(e){let t=!1;e.name!=null&&this.name!==e.name&&(this.parent&&ha(this.parent._getPropertiesSchema(),this.name,e.name),this.name=e.name,t=!0),e.isRequired!=null&&this.isRequired!==e.isRequired&&(this.parent&&ga(this.parent._getPropertiesSchema(),this.name,e.isRequired),this.isRequired=e.isRequired,t=!0);let n=e.type?.name;n===`any`&&(n=void 0);let r=n!==this.schema.type;return e.type&&(_a(this.schema,e.type),this.type=e.type,this.type.isObject?this.children||=[]:this.children=void 0,t=!0),this.schema.editor&&e.editor===null?(this.schema.editor=void 0,t=!0):e.editor?(this.schema.editor=e.editor,t=!0):r&&(this.schema.editor=void 0,t=!0),e.description!==this.description&&(this.description=e.description,t=!0),e.extractable!=null&&this.extractable!==e.extractable&&(this.extractable=e.extractable,t=!0),t}getUpdateFromNameAndTypeSignature(e,t){let n=e.trim(),r=!0;n.endsWith(`?`)&&(n=n.substring(0,n.length-1).trim(),r=!1);let i=oa(t),a;return i.name===`text`?(i.name=aa.string,a=`textarea`):i.name===`media`?(i.name=aa.any,a=`media`):i.name===`document`?(i.name=aa.any,a=`document`):a=null,{name:n,type:i,isRequired:r,editor:a}}updateFromNameAndTypeSignature(e,t){return this.update(this.getUpdateFromNameAndTypeSignature(e,t))}updateFromSignature(e){e=e.trim();let t=e.indexOf(`:`);if(t<0)throw Error(`Expecting a name and a type separated by a colon`);let n=e.substring(0,t),r=e.substring(t+1);return this.updateFromNameAndTypeSignature(n,r)}};function Da(e){let[t,n]=q(new Ta(e||{type:`object`,properties:{}}).withChangeListener(e=>{n(e.clone())}));return t}const Oa=`block text-sm sm:leading-6 rounded-md border-0 py-1.5 px-4`,ka=`${Oa} hover:shadow-xs hover:ring-1 hover:ring-inset hover:ring-ring`,Aa=`${Oa} shadow-xs ring-1 ring-inset ring-ring`;function ja({value:e,onChange:r,onDelete:i,outlineOnHover:a=!1,editOnClick:o=!0,placeholder:s,viewer:c,editor:l,skipClickOutside:u,isEditing:d=!1,readonly:f=!1,onValidate:p}){let{on:m,off:h,isOn:g}=w(d),[_,v]=q();return n(`div`,{className:``,children:[g&&!f?t(Na,{value:e,onSave:e=>{if(p){let t=p(e);if(t){v(t);return}else v(void 0)}r(e)&&h()},onCancel:h,editor:l,skipClickOutside:e=>u?u(e):!1}):t(Ma,{value:e,onEdit:m,viewer:c,placeholder:s,outlineOnHover:a,editOnClick:o,onDelete:i,readonly:f}),_&&t(`div`,{className:`text-red-500 text-sm`,children:_})]})}function Ma({viewer:e,value:i,onEdit:a,editOnClick:o,outlineOnHover:s,placeholder:c,onDelete:l,readonly:u}){let d=()=>{o&&a()},f=e=>{e.key===`Enter`&&a()},p=`invisible group-hover:visible`;return n(`div`,{role:o?`button`:void 0,tabIndex:0,onKeyUp:f,onClick:d,className:D(`flex justify-start items-center group`,s?ka:Oa,{"cursor-pointer":o}),children:[t(e,{value:i,placeholder:c}),n(`div`,{className:`ms-auto flex gap-2`,children:[!u&&l&&t(r,{variant:`ghost`,size:`sm`,className:p,onClick:l,children:t(Se,{className:`size-4`})}),u?null:t(r,{variant:`ghost`,size:`sm`,className:p,onClick:a,children:t(L,{className:`size-4`})})]})]})}function Na({editor:e,value:n,onSave:r,onCancel:i,skipClickOutside:a}){let[o,s]=q(n),c=K(n),[l,u]=q(null),d=()=>{r(c.current)};return t(`div`,{ref:C(d,a),children:t(`div`,{className:Aa,children:t(`div`,{className:`w-full`,onClick:e=>e.stopPropagation(),children:t(e,{value:o,onChange:(e,t=!1)=>{s(e),c.current=e,t&&(l&&clearTimeout(l),u(setTimeout(()=>{r(e)},500)))},onSave:d,onCancel:i})})})})}function Pa(e){return!!e.target.closest?.(`.schema-type-suggest-popup`)}function Fa({schema:e,readonly:r=!1}){let{t:i}=J();return n(`div`,{className:`space-y-1`,children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1 text-xs font-medium text-muted-foreground border-b border-border`,children:[t(`div`,{className:`flex-1 min-w-0`,children:i(`widgets.schema.propertyColumn`)}),!r&&t(`div`,{className:`shrink-0 w-28 text-end pe-1`,title:i(`widgets.schema.extractFromDocumentHint`),children:i(`widgets.schema.extractFromDocument`)}),t(`div`,{className:`w-8 shrink-0`})]}),n(`ul`,{className:``,children:[e.children.map(e=>Ia(e,r)),r?null:t(Va,{parent:e.root})]})]})}function Ia(e,n){return e.isParent?t(Ra,{property:e,readonly:n},e.name):t(La,{node:e,readonly:n},e.name)}function La({node:e,readonly:n}){return t(`li`,{className:`border-b border-border/40 last:border-0`,children:t(Ba,{property:e,readonly:n})})}function Ra({property:e,readonly:i}){let[a,o]=q(!0),s=a?N:re;return n(`li`,{className:`border-b border-border/40 last:border-0`,children:[n(`div`,{className:`flex items-center w-full gap-1`,children:[t(`div`,{className:`flex-1 min-w-0`,children:t(Ba,{property:e,readonly:i})}),t(r,{variant:`ghost`,size:`icon`,onClick:()=>o(!a),"aria-label":a?`Collapse ${e.name}`:`Expand ${e.name}`,"aria-expanded":a,className:`shrink-0`,children:t(s,{className:`size-4 cn-rtl-flip`})})]}),a&&n(`ul`,{className:`ms-4 border-s border-gray-400 border-dashed`,children:[(e.children||[]).map(e=>Ia(e,i)),i?null:t(Va,{parent:e})]})]})}function za(e){if(!e)return`Name is required`;if(!/^[a-zA-Z0-9_]+[?]?$/.test(e))return`Only letters, numbers, underscores or question mark are allowed (a-zA-Z0-9_?)`}function Ba({property:e,readonly:r}){let{t:i}=J(),a=E(),o=t=>{try{t.description&&typeof t.description!=`string`&&(t.description=void 0);let n=e.getUpdateFromNameAndTypeSignature(t.name,t.type);e.update({...n,description:t.description,extractable:t.extractable})&&e.reloadTree()}catch(e){return a({status:`error`,title:i(`widgets.schema.invalidPropertyDeclaration`),description:te(e),duration:9e3}),!1}return!0},s=t=>{e.update({extractable:t})&&e.reloadTree()},c=e.resetIsNew();return n(`div`,{className:`flex items-center gap-2 w-full min-w-0 py-0.5`,children:[t(`div`,{className:`flex-1 min-w-0`,children:t(ja,{value:ia(e),onChange:o,onDelete:()=>{e.remove(),e.reloadTree()},editor:la,viewer:ma,outlineOnHover:!0,isEditing:c,skipClickOutside:Pa,readonly:r,onValidate:e=>za(e.name)})}),r?e.extractable===!1?t(`div`,{className:`shrink-0 w-28 flex justify-end pe-1`,children:t(`span`,{className:`text-[10px] uppercase tracking-wide text-attention border border-attention/40 bg-attention/10 rounded px-1.5 py-0.5`,title:i(`widgets.schema.extractFromDocumentHint`),children:i(`widgets.schema.noExtract`)})}):null:t(`div`,{className:`shrink-0 w-28 flex items-center justify-end gap-1.5 pe-1`,children:t(y,{size:`sm`,value:e.extractable,onChange:s,"aria-label":`${i(`widgets.schema.extractFromDocument`)}: ${e.name}`})})]})}function Va({parent:e}){return n(r,{variant:`ghost`,onClick:()=>{let t=e.findAvailableChildName(`new_property_`),n=e.addChild(t,{isObject:!1,isArray:!1,isNullable:!1,name:aa.string},!0);n.isNew=!0,e.reloadTree()},children:[t(xe,{className:`size-4`}),`Add property`]})}function Ha(e){return e.isFile}function Ua(e){return e.isDirectory}function Wa({onDrop:e,message:i,buttonLabel:a,allowFolders:o=!0,className:s=``}){let{t:c}=J(),l=a??c(`upload.uploadFiles`),[u,d]=q(!1),f=K(null),p=e=>{e.preventDefault(),e.dataTransfer.types.includes(`Files`)&&d(!0)},m=e=>{e.preventDefault(),f.current&&!f.current.contains(e.relatedTarget)&&d(!1)},h=async t=>{if(t.preventDefault(),d(!1),t.dataTransfer.items&&t.dataTransfer.items.length>0){let n=Array.from(t.dataTransfer.items),r=[],i=new Set,a=async e=>{if(Ha(e)){let t=await new Promise(t=>{e.file(n=>{Object.defineProperty(n,"webkitRelativePath",{writable:!0,value:e.fullPath.substring(1)}),t(n)})});!t.name.startsWith(`.`)&&t.size>0&&r.push(t);let n=e.fullPath.substring(1).split(`/`).slice(0,-1).join(`/`);n&&i.add(n)}else if(Ua(e)){let t=e.createReader(),n=await new Promise(e=>{t.readEntries(t=>{e(t)})});await Promise.all(n.map(a));let r=e.fullPath.substring(1);r&&i.add(r)}};try{if(await Promise.all(n.map(e=>{let t=e.webkitGetAsEntry?e.webkitGetAsEntry():e;return t?a(t):Promise.resolve()})),r.length>0){let t=new Set(Array.from(i).map(e=>e.split(`/`)[0]).filter(Boolean)).size,n=r.length,a=``;a=t>0?c(`upload.preparingFolder`,{count:t,folderCount:t,fileCount:n}):c(`upload.preparingFiles`,{count:n}),e(r,{count:r.length,message:a})}}catch(n){console.error(`Error processing dropped files:`,n);let r=Array.from(t.dataTransfer.files);r.length>0&&e(r)}}else t.dataTransfer.files&&t.dataTransfer.files.length>0&&e(Array.from(t.dataTransfer.files))},g=t=>{if(t&&t.length>0){let n=Array.from(t);if(n.some(e=>e.webkitRelativePath?.includes(`/`))){let t=new Set(n.map(e=>e.webkitRelativePath.split(`/`)[0]).filter(Boolean)).size,r=n.length,i=c(`upload.preparingFolder`,{count:t,folderCount:t,fileCount:r});e(n,{count:n.length,message:i})}else e(n,{count:n.length,message:c(`upload.preparingFiles`,{count:n.length})})}};return n(`div`,{className:`flex flex-col items-center justify-center py-12 border-2 rounded-lg transition-colors ${u?`border-color-primary bg-color-primary/10`:`border-dashed border-color-border`} ${s}`,onDragOver:p,onDragLeave:m,onDrop:h,children:[t(Ce,{className:`h-12 w-12 mb-3 transition-colors ${u?`text-primary`:`text-muted/50`}`}),t(`p`,{className:`text-muted`,children:i}),n(`div`,{className:`flex gap-2 justify-center mt-2`,children:[t(r,{onClick:()=>{let e=document.createElement(`input`);e.type=`file`,e.multiple=!0,e.accept=`*`,e?.click(),e.onchange=()=>{g(e.files)}},children:l}),o&&t(r,{onClick:()=>{let e=document.createElement(`input`);e.type=`file`,e.multiple=!0,e.accept=`*`,e.webkitdirectory=!0,e?.click(),e.onchange=()=>{g(e.files)}},children:c(`upload.selectFolder`)})]})]})}function Ga({title:e,count:r,icon:i=t(M,{className:`h-4 w-4 text-green-500`}),items:a}){let{t:o}=J(),[s,c]=q(!1),l=ke();return n(`div`,{className:`border border-color-border rounded-md overflow-hidden`,children:[n(`button`,{type:`button`,"aria-expanded":s,"aria-controls":l,className:`w-full flex items-center justify-between p-3 bg-color-muted/10 cursor-pointer text-start bg-transparent border-0 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,onClick:()=>c(!s),children:[n(`span`,{className:`flex items-center`,children:[t(`span`,{className:`me-2`,children:i}),t(`span`,{className:`font-medium`,children:e}),t(`span`,{className:`ms-2 px-2 py-0.5 bg-color-muted/20 rounded-full text-xs`,children:r})]}),t(`span`,{className:`text-muted`,"aria-hidden":`true`,children:t(`svg`,{className:`h-5 w-5 transition-transform ${s?`transform rotate-180`:``}`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,"aria-hidden":`true`,children:t(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})})]}),s&&t(`div`,{id:l,className:`p-3 border-t border-color-border max-h-48 overflow-y-auto`,children:a.length>0?t(`ul`,{className:`space-y-1`,children:a.map(e=>t(`li`,{className:`text-sm py-1 px-2 rounded hover:bg-color-muted/10`,children:e},e))}):t(`div`,{className:`text-sm text-muted py-2`,children:o(`upload.noItems`)})})]})}function Ka({files:e,className:r=``,location:i,collection:a}){let{t:o}=J(),s=e.filter(e=>e.status===`success`),c=e.filter(e=>e.status===`updated`),l=e.filter(e=>e.status===`skipped`),u=e.filter(e=>e.status===`failed`),d=s.length,f=c.length,p=l.length,m=u.length,h=e.length;return n(`div`,{className:`flex flex-col py-2 ${r}`,children:[n(`div`,{className:`flex items-center mb-4`,children:[t(`div`,{className:`size-8 me-4 rounded-full bg-success/10 flex items-center justify-center`,children:t(M,{className:`size-4 text-success`})}),t(`div`,{children:n(`p`,{className:`text-muted`,children:[o(`upload.filesProcessed`,{count:h}),a?o(`upload.inCollection`,{collection:a}):``,i?o(`upload.inFolder`,{location:i}):``]})})]}),n(`div`,{className:`space-y-3 mt-2`,children:[d>0&&t(Ga,{title:o(`upload.successfullyUploaded`),count:d,icon:t(M,{className:`h-4 w-4 text-green-500`}),items:s.map(e=>e.name)}),f>0&&t(Ga,{title:o(`upload.successfullyUpdated`),count:f,icon:t(M,{className:`h-4 w-4 text-blue-500`}),items:c.map(e=>e.name)}),p>0&&t(Ga,{title:o(`upload.skippedAlreadyExisted`),count:p,icon:t(k,{className:`h-4 w-4 text-amber-500`}),items:l.map(e=>e.name)}),m>0&&t(Ga,{title:o(`upload.failedToUpload`),count:m,icon:t(Te,{className:`h-4 w-4 text-red-500`}),items:u.map(e=>e.name)})]})]})}const qa=`#text`,Ja=`#comment`,Ya=`#cdata`,Xa=`DECLARATION_TAG`,Za={tagColor:`#d43900`,textColor:`#333`,attributeKeyColor:`#2a7ab0`,attributeValueColor:`#008000`,separatorColor:`#333`,commentColor:`#aaa`,cdataColor:`#1d781d`,fontFamily:`monospace`},Qa={attributeKeyColor:`#FFD700`,attributeValueColor:`#FF4500`,tagColor:`#87CEFA`,textColor:`#00FF00`,separatorColor:`#FFD700`,commentColor:`#BEBEBE`,cdataColor:`#33CC66`,fontFamily:`monospace`},$a=V({theme:Za,collapsible:!1,indentSize:2}),eo=()=>U($a),to=new tt({preserveOrder:!0,ignoreAttributes:!1,attributeNamePrefix:``,allowBooleanAttributes:!0,commentPropName:Ja,cdataPropName:Ya,parseTagValue:!1});function no(e){try{let t=new DOMParser().parseFromString(e,`application/xml`),n=t.documentElement.localName===`parsererror`?t.documentElement:void 0;if(n)throw Error(n.textContent?.trim()||`Invalid XML!`);let r=to.parse(e);if(e.trim().length>0&&r.length===0)throw Error(`Invalid XML!`);return{json:r,valid:!0}}catch(e){return{json:null,valid:!1,errorMessage:`Fail to parse: ${e instanceof Error?e.message:String(e)}`}}}function ro(e){return G(()=>no(e),[e])}function io(e){let{indentation:r,children:i,isInline:a}=e,{theme:o}=eo();return n(`div`,{style:{color:o.cdataColor},children:[t(`span`,{children:`${r}<![CDATA[`}),i,t(`span`,{children:`${a?``:r}]]>`})]})}function ao(e){let{collapsible:n,theme:r}=eo(),{collapsed:i}=e;return n?t(`span`,{style:{position:`relative`},children:t(`span`,{style:{position:`absolute`,right:`0`,border:0,padding:0,background:`none`},children:t(oo,{fill:r.separatorColor,style:{transform:`rotate(${i?0:90}deg)`,transition:`transform 0.2s`}})})}):null}function oo({...e}){return t(`svg`,{width:`16px`,height:`16px`,viewBox:`0 0 24 24`,"aria-hidden":`true`,...e,children:t(`path`,{d:`M9 17.898C9 18.972 10.2649 19.546 11.0731 18.8388L17.3838 13.3169C18.1806 12.6197 18.1806 11.3801 17.3838 10.6829L11.0731 5.16108C10.2649 4.45388 9 5.02785 9 6.1018V17.898Z`})})}function so(e){let{collapsible:t,initialCollapsedDepth:n}=eo(),[r,i]=q(()=>nt(n)||!t?!1:e>=n);return W(()=>{i(nt(n)||!t?!1:e>=n)},[n,e,t]),{collapsed:r,buttonProps:t?{onClick:()=>i(e=>!e),role:`button`,style:{cursor:`pointer`}}:{}}}function co(e){let{indentation:r,children:i,isInline:a,level:o}=e,{theme:s}=eo(),{collapsed:c,buttonProps:l}=so(o);return n(`div`,{style:{color:s.commentColor},children:[n(`span`,{...l,children:[t(`span`,{children:r}),t(ao,{collapsed:c}),t(`span`,{children:`<!-- `})]}),!c&&i,c&&`...`,t(`span`,{children:`${a||c?` `:r}-->`})]})}function lo(e){let{attributes:r}=e,{theme:i}=eo();return r?t(`span`,{children:Object.entries(r).map(([e,r])=>n(`span`,{children:[t(`span`,{style:{color:i.attributeKeyColor},children:` ${e}`}),t(`span`,{style:{color:i.separatorColor},children:`=`}),t(`span`,{style:{color:i.attributeValueColor},children:`"${r}"`})]},`attribute-${e}`))}):null}function uo(e){let{indentation:r,tagKey:i,attributes:a}=e,{theme:o}=eo();return n(`div`,{children:[t(`span`,{style:{color:o.separatorColor},children:`${r}<?`}),t(`span`,{style:{color:o.tagColor},children:`${i.slice(1)}`}),t(lo,{attributes:a}),t(`span`,{style:{color:o.separatorColor},children:`?>`})]})}function fo(e,t){return Array(t*e+1).join(` `)}function po(e){return typeof e==`string`&&e.includes(`
25
+ `)}function mo(e){return typeof e!=`string`&&e.length===1&&`#text`in e[0]&&!po(e[0][`#text`])}function ho(e){switch(e){case qa:case Ya:case Ja:return e;default:return e.startsWith(`?`)?Xa:`TAG`}}function go(e){let t=e[`:@`],n=rt(e,`:@`),[[r,i]]=Object.entries(n);return{attributes:t,tagKey:r,subElements:i,type:ho(r)}}function _o(e){return e?Object.keys(e).length>0:!1}function vo(r){let{indentation:i,tagKey:a,attributes:o,children:s,isInline:c,hasChildren:l,level:u}=r,{collapsed:d,buttonProps:f}=so(u),{theme:p}=eo();return n(`div`,{children:[n(`span`,{...f,children:[t(`span`,{children:i}),t(ao,{collapsed:d}),t(`span`,{style:{color:p.separatorColor},children:`<`}),t(`span`,{style:{color:p.tagColor},children:`${a}`}),!d&&t(lo,{attributes:o}),d&&_o(o)&&` ...`,t(`span`,{style:{color:p.separatorColor},children:l?`>`:` />`})]}),l&&n(e,{children:[!d&&s,d&&`...`,t(`span`,{style:{color:p.separatorColor},children:`${c||d?``:i}</`}),t(`span`,{style:{color:p.tagColor},children:`${a}`}),t(`span`,{style:{color:p.separatorColor},children:`>`})]})]})}function yo(e){let{hasSiblings:n,text:r,indentation:i,isText:a}=e,{theme:o}=eo(),s=a?{color:o.textColor}:void 0;return po(r)||n?t(`div`,{style:s,children:r.split(`
26
+ `).filter(e=>!!e.trim()).map((e,n)=>t(`div`,{children:`${i}${e.trim()}`},`line-${n}`))}):t(`span`,{style:s,children:r})}function bo(n){let{elements:r,level:i=0,isText:a=!0}=n,{indentSize:o}=eo();return!Array.isArray(r)||r.length===0?null:t(e,{children:r.map((e,n)=>{let{tagKey:s,attributes:c,subElements:l,type:u}=go(e),d=r.length>1,f=fo(o,i),p=`${i}-${n}`,m=mo(l);switch(u){case qa:return t(yo,{text:l,indentation:f,hasSiblings:d,isText:a},p);case Ja:return t(co,{isInline:m,indentation:f,level:i,children:t(bo,{elements:l,level:i+1,isText:!1})},p);case Ya:return t(io,{indentation:f,isInline:m,children:t(bo,{elements:l,level:i+1,isText:!1})},p);case Xa:return t(uo,{indentation:f,tagKey:s,attributes:c},p);default:return t(vo,{indentation:f,tagKey:s,attributes:c,isInline:m,hasChildren:l.length>0,level:i,children:t(bo,{elements:l,level:i+1})},p)}})})}function xo(){return t(`div`,{children:`Invalid XML!`})}function So(e){let{theme:n,xml:r,collapsible:i=!1,indentSize:a=2,invalidXml:o,initalCollapsedDepth:s,initialCollapsedDepth:c}=e,[l,u]=q(()=>document.documentElement.classList.contains(`dark`));W(()=>{let e=document.documentElement,t=new MutationObserver(()=>{u(e.classList.contains(`dark`))});return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let d=G(()=>({...l?Qa:Za,...n}),[l,n]),{json:f,valid:p}=ro(r),m=G(()=>({theme:d,collapsible:i,indentSize:a,initialCollapsedDepth:c??s}),[d,i,a,s,c]);return p?t($a.Provider,{value:m,children:t(`div`,{className:`rxv-container`,style:{whiteSpace:`pre-wrap`,fontFamily:d.fontFamily,overflowWrap:`break-word`},children:t(bo,{elements:f})})}):o||t(xo,{})}export{hn as AgentResourceResolverProvider,Ot as ArrayPropertySchema,Zn as ArtifactContentRenderer,$i as ArtifactEditingSurface,pr as ChartCodeBlockHandler,Z as CodeBlockErrorBoundary,Bn as CodeBlockHandlerProvider,X as CodeBlockPlaceholder,er as CodeBlockRendererProvider,Pi as CollaborativeMarkdownRenderer,Wa as DropZone,gr as ExpandCodeBlockHandler,at as FieldSetContextProvider,ft as Form,st as FormContext,ut as FormContextProvider,Ct as FormError,St as FormHelper,xt as FormLabel,mt as GeneratedForm,dt as Input,zt as JSONCode,Xt as JSONDisplay,cn as JSONEditor,un as JSONSwitcher,pn as JSONTable,Ut as JSONView,Lt as ManageObjectEntry,It as ManagedListProperty,Nt as ManagedObject,Mt as ManagedObjectBase,Pt as ManagedObjectProperty,Ft as ManagedProperty,Rt as ManagedScalarEntry,Ta as ManagedSchema,Cr as MarkdownFigure,Tr as MarkdownImage,Dr as MarkdownLink,hi as MarkdownRenderer,mr as MermaidCodeBlockHandler,or as MermaidDiagram,sn as MonacoEditor,jt as Node,ea as Progress,ta as PropertiesView,la as PropertyEditor,ua as PropertyNameEditor,Et as PropertySchema,ma as PropertyViewer,_t as ScalarField,Tt as Schema,Fa as SchemaEditor,Ea as SchemaNode,na as SvgIcon,Ga as UploadResultCategory,Ka as UploadSummary,on as VEditorApi,So as XMLViewer,Yi as applyArtifactRefreshChanges,Ai as applyMarkdownEditingChange,kt as computeTitleFromName,vr as createDefaultCodeBlockHandlers,Ti as createMarkdownBlockAnchor,ra as createSvgIcon,Ki as createUnifiedLineDiff,Bi as diffTextSegments,Li as diffWordSegments,ji as formatMarkdownEditingAction,ia as getEditableSchemaProperty,ln as getJSONEditorValue,Vi as getTextLineChangeRegions,Ji as isArtifactRefreshEvent,_r as isExpandLanguage,lr as isIncompleteJson,vn as parseAgentResourceHref,xr as parseUrlScheme,Gi as rebaseTextChanges,Ht as renderJsonLine,gn as useAgentResourceResolver,cr as useArtifactContent,nr as useCodeBlockComponent,Vn as useCodeBlockContext,tr as useCodeBlockRendererRegistry,ot as useFieldSet,lt as useForm,Sr as useResolvedUrl,Da as useSchema,za as validatePropertyName};
27
27
  //# sourceMappingURL=vertesia-ui-widgets.js.map