@vertesia/ui 1.5.0-dev.20260901.045442Z → 1.5.0-dev.20260905.011013Z

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 (139) hide show
  1. package/lib/features/agent/chat/AgentRightPanel.d.ts +2 -3
  2. package/lib/features/agent/chat/AgentRightPanel.d.ts.map +1 -1
  3. package/lib/features/agent/chat/AgentRightPanel.js +3 -3
  4. package/lib/features/agent/chat/AgentRightPanel.js.map +1 -1
  5. package/lib/features/agent/chat/DocumentPanel.d.ts +7 -7
  6. package/lib/features/agent/chat/DocumentPanel.d.ts.map +1 -1
  7. package/lib/features/agent/chat/DocumentPanel.js +6 -12
  8. package/lib/features/agent/chat/DocumentPanel.js.map +1 -1
  9. package/lib/features/agent/chat/DocumentsTab.d.ts +15 -0
  10. package/lib/features/agent/chat/DocumentsTab.d.ts.map +1 -0
  11. package/lib/features/agent/chat/DocumentsTab.js +33 -0
  12. package/lib/features/agent/chat/DocumentsTab.js.map +1 -0
  13. package/lib/features/agent/chat/ModernAgentConversation.js +2 -2
  14. package/lib/features/agent/chat/ModernAgentConversation.js.map +1 -1
  15. package/lib/features/agent/chat/ModernAgentOutput/Header.d.ts.map +1 -1
  16. package/lib/features/agent/chat/ModernAgentOutput/Header.js +15 -10
  17. package/lib/features/agent/chat/ModernAgentOutput/Header.js.map +1 -1
  18. package/lib/features/agent/chat/hooks/useDocumentPanel.d.ts +2 -2
  19. package/lib/features/agent/chat/hooks/useDocumentPanel.d.ts.map +1 -1
  20. package/lib/features/agent/chat/hooks/useDocumentPanel.js +0 -18
  21. package/lib/features/agent/chat/hooks/useDocumentPanel.js.map +1 -1
  22. package/lib/features/oauth/McpConnectionsButton.d.ts.map +1 -1
  23. package/lib/features/oauth/McpConnectionsButton.js +4 -1
  24. package/lib/features/oauth/McpConnectionsButton.js.map +1 -1
  25. package/lib/features/oauth/McpConnectionsDialog.d.ts.map +1 -1
  26. package/lib/features/oauth/McpConnectionsDialog.js +3 -2
  27. package/lib/features/oauth/McpConnectionsDialog.js.map +1 -1
  28. package/lib/features/oauth/useMcpConnections.d.ts +6 -7
  29. package/lib/features/oauth/useMcpConnections.d.ts.map +1 -1
  30. package/lib/features/oauth/useMcpConnections.js +27 -20
  31. package/lib/features/oauth/useMcpConnections.js.map +1 -1
  32. package/lib/features/store/types/TypeRegistry.d.ts +10 -5
  33. package/lib/features/store/types/TypeRegistry.d.ts.map +1 -1
  34. package/lib/features/store/types/search/ObjectTypeSearchContext.d.ts +10 -5
  35. package/lib/features/store/types/search/ObjectTypeSearchContext.d.ts.map +1 -1
  36. package/lib/i18n/locales/ar.json +10 -0
  37. package/lib/i18n/locales/de.json +6 -0
  38. package/lib/i18n/locales/en.json +6 -0
  39. package/lib/i18n/locales/es.json +6 -0
  40. package/lib/i18n/locales/fr.json +6 -0
  41. package/lib/i18n/locales/it.json +6 -0
  42. package/lib/i18n/locales/ja.json +6 -0
  43. package/lib/i18n/locales/ko.json +6 -0
  44. package/lib/i18n/locales/pt.json +6 -0
  45. package/lib/i18n/locales/ru.json +8 -0
  46. package/lib/i18n/locales/tr.json +6 -0
  47. package/lib/i18n/locales/zh-TW.json +6 -0
  48. package/lib/i18n/locales/zh.json +6 -0
  49. package/lib/router/NestedNavigationContext.d.ts +3 -1
  50. package/lib/router/NestedNavigationContext.d.ts.map +1 -1
  51. package/lib/router/NestedNavigationContext.js +2 -2
  52. package/lib/router/NestedNavigationContext.js.map +1 -1
  53. package/lib/vertesia-ui-features.js +14 -14
  54. package/lib/vertesia-ui-features.js.map +1 -1
  55. package/lib/vertesia-ui-i18n.3yHWompP.chunk.js +5 -0
  56. package/lib/vertesia-ui-i18n.3yHWompP.chunk.js.map +1 -0
  57. package/lib/vertesia-ui-i18n.4XKCcnL0.chunk.js +5 -0
  58. package/lib/vertesia-ui-i18n.4XKCcnL0.chunk.js.map +1 -0
  59. package/lib/vertesia-ui-i18n.78KG4J25.chunk.js +5 -0
  60. package/lib/vertesia-ui-i18n.78KG4J25.chunk.js.map +1 -0
  61. package/lib/vertesia-ui-i18n.BN06mpp1.chunk.js +5 -0
  62. package/lib/vertesia-ui-i18n.BN06mpp1.chunk.js.map +1 -0
  63. package/lib/vertesia-ui-i18n.CSzKLlHJ.chunk.js +5 -0
  64. package/lib/vertesia-ui-i18n.CSzKLlHJ.chunk.js.map +1 -0
  65. package/lib/vertesia-ui-i18n.Ccus7aRh.chunk.js +5 -0
  66. package/lib/vertesia-ui-i18n.Ccus7aRh.chunk.js.map +1 -0
  67. package/lib/vertesia-ui-i18n.D9j3c6gI.chunk.js +5 -0
  68. package/lib/vertesia-ui-i18n.D9j3c6gI.chunk.js.map +1 -0
  69. package/lib/vertesia-ui-i18n.DAUg4rrI.chunk.js +5 -0
  70. package/lib/vertesia-ui-i18n.DAUg4rrI.chunk.js.map +1 -0
  71. package/lib/vertesia-ui-i18n.DSxVZKXy.chunk.js +5 -0
  72. package/lib/vertesia-ui-i18n.DSxVZKXy.chunk.js.map +1 -0
  73. package/lib/vertesia-ui-i18n.aahVhHvR.chunk.js +5 -0
  74. package/lib/vertesia-ui-i18n.aahVhHvR.chunk.js.map +1 -0
  75. package/lib/vertesia-ui-i18n.js +2 -2
  76. package/lib/vertesia-ui-i18n.nZ3xJ26v.chunk.js +5 -0
  77. package/lib/vertesia-ui-i18n.nZ3xJ26v.chunk.js.map +1 -0
  78. package/lib/vertesia-ui-i18n.xPYbuFzT.chunk.js +5 -0
  79. package/lib/vertesia-ui-i18n.xPYbuFzT.chunk.js.map +1 -0
  80. package/lib/vertesia-ui-router.js +1 -1
  81. package/lib/vertesia-ui-router.js.map +1 -1
  82. package/package.json +7 -7
  83. package/src/features/agent/chat/AgentRightPanel.tsx +4 -8
  84. package/src/features/agent/chat/DocumentPanel.tsx +39 -48
  85. package/src/features/agent/chat/DocumentsTab.test.tsx +87 -0
  86. package/src/features/agent/chat/DocumentsTab.tsx +124 -0
  87. package/src/features/agent/chat/ModernAgentConversation.test.tsx +0 -1
  88. package/src/features/agent/chat/ModernAgentConversation.tsx +0 -2
  89. package/src/features/agent/chat/ModernAgentOutput/Header.tsx +27 -14
  90. package/src/features/agent/chat/hooks/useDocumentPanel.test.tsx +33 -0
  91. package/src/features/agent/chat/hooks/useDocumentPanel.ts +3 -20
  92. package/src/features/oauth/McpConnectionsButton.test.tsx +79 -8
  93. package/src/features/oauth/McpConnectionsButton.tsx +6 -3
  94. package/src/features/oauth/McpConnectionsDialog.tsx +9 -3
  95. package/src/features/oauth/useMcpConnections.ts +33 -27
  96. package/src/i18n/locales/ar.json +10 -0
  97. package/src/i18n/locales/de.json +6 -0
  98. package/src/i18n/locales/en.json +6 -0
  99. package/src/i18n/locales/es.json +6 -0
  100. package/src/i18n/locales/fr.json +6 -0
  101. package/src/i18n/locales/it.json +6 -0
  102. package/src/i18n/locales/ja.json +6 -0
  103. package/src/i18n/locales/ko.json +6 -0
  104. package/src/i18n/locales/pt.json +6 -0
  105. package/src/i18n/locales/ru.json +8 -0
  106. package/src/i18n/locales/tr.json +6 -0
  107. package/src/i18n/locales/zh-TW.json +6 -0
  108. package/src/i18n/locales/zh.json +6 -0
  109. package/src/router/NestedNavigationContext.test.tsx +54 -0
  110. package/src/router/NestedNavigationContext.tsx +9 -2
  111. package/lib/features/agent/chat/DocumentTabBar.d.ts +0 -9
  112. package/lib/features/agent/chat/DocumentTabBar.d.ts.map +0 -1
  113. package/lib/features/agent/chat/DocumentTabBar.js +0 -9
  114. package/lib/features/agent/chat/DocumentTabBar.js.map +0 -1
  115. package/lib/vertesia-ui-i18n.BJBGsq-8.chunk.js +0 -5
  116. package/lib/vertesia-ui-i18n.BJBGsq-8.chunk.js.map +0 -1
  117. package/lib/vertesia-ui-i18n.BY5YG5cX.chunk.js +0 -5
  118. package/lib/vertesia-ui-i18n.BY5YG5cX.chunk.js.map +0 -1
  119. package/lib/vertesia-ui-i18n.Bd5_1BXO.chunk.js +0 -5
  120. package/lib/vertesia-ui-i18n.Bd5_1BXO.chunk.js.map +0 -1
  121. package/lib/vertesia-ui-i18n.Bvwej2HH.chunk.js +0 -5
  122. package/lib/vertesia-ui-i18n.Bvwej2HH.chunk.js.map +0 -1
  123. package/lib/vertesia-ui-i18n.CMT3f4gf.chunk.js +0 -5
  124. package/lib/vertesia-ui-i18n.CMT3f4gf.chunk.js.map +0 -1
  125. package/lib/vertesia-ui-i18n.D56DNPJW.chunk.js +0 -5
  126. package/lib/vertesia-ui-i18n.D56DNPJW.chunk.js.map +0 -1
  127. package/lib/vertesia-ui-i18n.DDzKLNx6.chunk.js +0 -5
  128. package/lib/vertesia-ui-i18n.DDzKLNx6.chunk.js.map +0 -1
  129. package/lib/vertesia-ui-i18n.D_Am1LpF.chunk.js +0 -5
  130. package/lib/vertesia-ui-i18n.D_Am1LpF.chunk.js.map +0 -1
  131. package/lib/vertesia-ui-i18n.DrZizgGV.chunk.js +0 -5
  132. package/lib/vertesia-ui-i18n.DrZizgGV.chunk.js.map +0 -1
  133. package/lib/vertesia-ui-i18n.DwHsq86z.chunk.js +0 -5
  134. package/lib/vertesia-ui-i18n.DwHsq86z.chunk.js.map +0 -1
  135. package/lib/vertesia-ui-i18n.PLpo0Bbz.chunk.js +0 -5
  136. package/lib/vertesia-ui-i18n.PLpo0Bbz.chunk.js.map +0 -1
  137. package/lib/vertesia-ui-i18n.xVbXALqz.chunk.js +0 -5
  138. package/lib/vertesia-ui-i18n.xVbXALqz.chunk.js.map +0 -1
  139. package/src/features/agent/chat/DocumentTabBar.tsx +0 -41
@@ -1252,7 +1252,7 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
1252
1252
  .agent-markdown tbody tr:hover {
1253
1253
  background: transparent;
1254
1254
  }
1255
- `}),s===`stacked`&&t(`div`,{className:z(`sticky top-0 z-10`,y&&`hidden`),children:t(EK,{workstreams:fe,activeWorkstream:R,onSelectWorkstream:ge,count:ve,completionStatus:it})}),ye.length===0&&Ve.length===0&&!ke&&!(se&&Ze)?R===`all`&&Ye?t(`div`,{className:`flex-1 px-2 py-6 sm:px-4`,children:t(vq,{label:F(`agent.preparing`),timestamp:Oe.current,className:b})}):t(`div`,{className:`flex items-center justify-center h-full text-center py-8`,children:t(`div`,{className:`flex items-center px-3 py-2 text-sm text-muted`,children:F(R===`all`?`agent.waitingForAgentResponse`:`agent.noMessagesInWorkstream`)})}):n(`div`,{className:z(`flex-1 flex flex-col justify-start w-full max-w-full`,se?`gap-6 px-2 py-6 sm:px-4`:`gap-3 pb-4`,x),children:[se&&R!==`all`&&pe&&t(`div`,{className:`sticky top-0 z-20 -mx-2 bg-background/95 px-2 pb-2 pt-1 backdrop-blur sm:-mx-4 sm:px-4`,children:n(`div`,{className:`mx-auto flex w-full max-w-3xl items-center gap-2 border-b border-border/70 pb-3`,children:[t(o,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 shrink-0 text-muted hover:text-foreground`,title:F(`agent.backToMainAgent`),onClick:_e,children:t(Tm,{className:`size-4`,"aria-hidden":`true`})}),t(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:pe})]})}),je&&t(_q,{data:T,schema:E,title:D,template:O,prependFriendlyMessage:w,timestamp:ye[0]?.timestamp??Date.now(),isSummaryView:se,messageItemClassNames:f,messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C},`initial-request`),$e&&t(vq,{label:Qe,timestamp:rt,className:b}),s===`stacked`?n(e,{children:[Je.map((e,n)=>{let r=n===Je.length-1;if(e.type===`resource_summary`)return t(wG,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`tool_group`){let n=e.messages[e.messages.length-1],i=e.toolStatus===`completed`||e.toolStatus===`error`||e.toolStatus===`warning`,a=!c&&r&&!JH.includes(n.type)&&!i;return h?.includes(s)?null:t(bJ,{status:e.toolStatus,children:t(xJ,{children:t(yK,{...m,messages:e.messages,showPulsatingCircle:a,toolRunId:e.toolRunId,toolStatus:e.toolStatus,preambleText:e.preambleText,preambleMessage:e.preambleMessage,rootClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,m?.rootClassName),headerClassName:z(`px-3 py-2`,m?.headerClassName),itemHeaderClassName:z(`hover:bg-mixer-muted/20`,m?.itemHeaderClassName)})})},Wq(e))}if(e.type===`streaming`)return t(bJ,{children:t(AG,{...g,text:e.text,workstreamId:e.workstreamId,isComplete:e.isComplete,timestamp:e.startTimestamp,artifactRunId:v,cardClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},Wq(e));{let i=e.message;if(Te(i)||Ee(i))return null;if(ZH(i))return t(bJ,{children:t(vJ,{message:i,startTimestamp:Gq(Je,n)??i.timestamp,endTimestamp:i.timestamp})},Uq(i,`stopped`));let a=!c&&r&&!JH.includes(i.type);return kK(i)?t(xJ,{children:t(qW,{message:i,batchData:i.details,isRunning:!i.details.completed_at,..._})},`batch-${i.details.batch_id}-${i.timestamp}`):t(bJ,{status:`message`,children:t(xJ,{children:t(_G,{...f,message:i,showPulsatingCircle:a,onSendMessage:u,onOpenArtifact:d,requestInputAnswered:QU(i,be),cardClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,f?.cardClassName),headerClassName:z(`px-3 py-2`,f?.headerClassName),contentClassName:z(`bg-transparent`,f?.contentClassName),messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C})})},Uq(i))}}),Ve.map(({id:e,data:n})=>t(bJ,{children:t(AG,{...g,text:n.text,workstreamId:n.workstreamId,isComplete:n.isComplete,timestamp:n.startTimestamp,artifactRunId:v,cardClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},`streaming-incomplete-${e}`)),Ye&&Ve.length===0&&!$e&&t(bJ,{children:n(`div`,{className:z(`flex items-center gap-2 py-2 text-sm text-muted`,b),children:[t(rW,{size:`sm`,color:`blue`}),t(`span`,{children:F(`agent.working`)})]})})]}):n(e,{children:[Ke.map(e=>{if(e.type===`resource_summary`)return t(wG,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`work`){if(h?.includes(s))return null;let n=RK(e.messages);return t(yJ,{label:zK(e.isActive),status:e.status,timestamp:e.startTimestamp,durationSeconds:e.isActive?void 0:MK(e.startTimestamp,e.endTimestamp),showElapsed:!0,details:n?void 0:e.messages,defaultExpanded:e.isActive&&!n,disablePreambleCollapse:e.isActive,className:b,onSendMessage:u,answeredToolApprovalRequestInputKeys:Se,resolvedToolApprovalKeys:xe},`work-${e.id}-${e.isActive?`active`:`done`}-${e.status}`)}if(e.type===`stopped`)return t(vJ,{message:e.message,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp},Uq(e.message,`stopped-summary`));let n=e.message;return Te(n)||Ee(n)?null:kK(n)?t(xJ,{children:t(qW,{message:n,batchData:n.details,isRunning:!n.details.completed_at,..._})},Uq(n,`batch`)):t(xJ,{children:t(cq,{message:n,onSendMessage:u,onOpenArtifact:d,onSelectWorkstream:ge,requestInputAnswered:QU(n,be),StoreLinkComponent:S,CollectionLinkComponent:C})},Uq(n,`summary`))}),Ve.map(({id:e,data:n})=>t(_J,{text:n.text,workstreamId:n.workstreamId,artifactRunId:v},`streaming-incomplete-${e}`)),Xe&&t(`div`,{className:z(`mx-auto w-full max-w-3xl px-1 text-sm text-muted`,b),"data-testid":`post-tool-thinking-indicator`,children:F(`agent.thinking`)}),Ze&&!$e&&t(yJ,{label:Qe,status:`running`,timestamp:rt,showElapsed:!0,className:b})]}),t(`div`,{ref:a,className:`h-2`})]})]})}const wJ=(e,t)=>{if(e.type!==t.type||e.message!==t.message)return!1;let n=e.details,r=t.details;if(n?.tool_status!==`completed`||r?.tool_status!==`completed`)return!1;let i=typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime();return(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())-i<2e3},TJ=ot.memo(CJ);Q();function EJ(e){return e?new Map(e.streamingMessages.map((e,t)=>[e.id??e.activityId??`stream-${t}`,e])):new Map}function DJ(e,t){return e?.find(e=>e.cursor===t)}function OJ(e,t){if(t===0||e===`live`)return`live`;let n=pC(e,t);return n>=t-1?`live`:n+1}function kJ(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function AJ(e){return kJ(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function jJ(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function MJ({fixture:e,cursor:r,initialCursor:i,onCursorChange:a,autoStepMs:s,repeat:c=1,viewMode:l,className:u,title:d,showHeader:f=!0}){let{t:p}=K(),m=e.messages,h=i??(m.length>0?0:`live`),[g,_]=G(()=>fC(h,m.length)),v=r??g,y=l??`sliding`,[b,x]=G(!!s),[S,C]=G(0),w=W(null),T=U(()=>gC(m,v,!0),[v,m]),E=T.displayedMessages,D=U(()=>EJ(DJ(e.streamingFrames,T.cursor)),[e.streamingFrames,T.cursor]),O=V(e=>{let t=fC(e,m.length);r===void 0&&_(t),a?.(t)},[r,m.length,a]);H(()=>{let e=fC(v,m.length);e!==v&&O(e)},[v,m.length,O]),H(()=>{if(!s||s<=0||!b)return;let e=window.setInterval(()=>{let e=OJ(v,m.length);if(e===`live`&&v===`live`){C(e=>{let t=e+1;return c>0&&t>=c?(x(!1),t):(O(m.length>0?0:`live`),t)});return}O(e)},s);return()=>window.clearInterval(e)},[s,v,b,m.length,c,O]);let k=E.length>0&&!XH(E),A=U(()=>$U(E),[E]),j=d??e.metadata?.title??p(`agent.rewind.fixtureTitle`),M=V(()=>{let t={...e,metadata:{...e.metadata,title:j,exported_at:e.metadata?.exported_at??new Date().toISOString(),message_count:m.length}},n=e.metadata?.agent_run_id??`fixture`;jJ(`${AJ(j)||`agent-chat`}-${AJ(n)}.json`,t)},[e,m.length,j]),N=V(()=>{O(OJ(T.cursor,m.length))},[m.length,T.cursor,O]);return n(`div`,{className:z(`flex h-full min-h-0 w-full flex-col bg-background text-foreground`,u),"data-agent-test-playback-enabled":!0,"data-agent-playback-cursor":T.cursor,"data-agent-live-message-count":m.length,"data-agent-rendered-message-count":T.renderedMessageCount,"data-agent-replay-playing":b||void 0,"data-agent-replay-loop":S,children:[f&&n(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 py-2`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,children:j}),t(`div`,{className:`text-xs text-muted`,children:p(`agent.rewind.fixtureMeta`,{messageCount:m.length,loops:S})})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:M,children:[t(sg,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(`agent.rewind.exportFixture`)})]}),s&&s>0&&n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>x(e=>!e),children:[t(b?Kv:iy,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(b?`agent.rewind.pause`:`agent.rewind.resume`)})]})]})]}),t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(SC,{cursor:T.cursor,messages:m,onChangeCursor:O})}),t(TJ,{messages:E,isCompleted:k,streamingMessages:D,bottomRef:w,artifactRunId:e.metadata?.agent_run_id??`agent-chat-fixture`,viewMode:y,renderRequestInputControls:!A}),A&&t(tW,{message:A,onSendMessage:N,isLoading:!1})]})}function NJ({className:e,inline:r=!1}){return n(`div`,{className:z(`flex items-center gap-1`,r?`inline-flex`:``,e),children:[t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}})]})}function PJ(){let{client:e}=q(),[t,n]=G([]),[r,i]=G(!0),[a,o]=G(!1),s=W(0),c=V(async()=>{let t=s.current+1;s.current=t,i(!0),o(!1);try{let r=await e.apps.getInstalledApps(`tools`),a=[];for(let e of r){let t=e,n=t.oauth_collection_ids??[],r=t.manifest.oauth_providers??{};if(!t.manifest.tool_collections)continue;let i=t.manifest.tool_collections.map(e=>jn(e)).filter(e=>e.type===`mcp`),o=i.filter(e=>e.auth!==`api_key`&&n.includes(e.id)),s=i.filter(e=>e.auth===`api_key`),c=new Map,l=new Map,u=[];for(let e of o)if(e.oauth_provider){let t=c.get(e.oauth_provider)??[];t.push(e),c.set(e.oauth_provider,t)}else if(e.oauth_app){let t=l.get(e.oauth_app)??[];t.push(e),l.set(e.oauth_app,t)}else u.push(e);for(let[e,n]of c)a.push({key:`${t.id}:provider:${e}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:r[e]?.display_name||e,representativeId:n[0].id,memberIds:n.map(e=>e.id),memberNames:n.map(e=>e.name),authType:`oauth`});for(let[e,n]of l)a.push({key:`${t.id}:oauthapp:${e}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e,representativeId:n[0].id,memberIds:n.map(e=>e.id),memberNames:n.map(e=>e.name),authType:`oauth`});for(let e of u)a.push({key:`${t.id}:individual:${e.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e.name,representativeId:e.id,memberIds:[e.id],memberNames:[e.name],authType:`oauth`});for(let e of s)a.push({key:`${t.id}:api-key:${e.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e.name,representativeId:e.id,memberIds:[e.id],memberNames:[e.name],authType:`api_key`})}if(s.current!==t||(n(a),i(!1),a.length===0))return;o(!0);let c=new Map,l=await Promise.all(a.map(async t=>{try{let n=c.get(t.appId);n||(n=e.remoteMcpConnections.getStatus(t.appId),c.set(t.appId,n));let r=(await n).find(e=>e.collection_id===t.representativeId);return{...t,authStatus:r}}catch{return t}}));if(s.current!==t)return;n(l)}catch(e){s.current===t&&(console.error(`Failed to load MCP tool collections:`,e),n([]))}finally{s.current===t&&(i(!1),o(!1))}},[e]);return H(()=>{c()},[c]),{groups:t,loading:r,statusLoading:a,reload:c}}function FJ(e,t){return t?.length?e.memberIds.every(e=>t.includes(e)):!1}function IJ(e,t,n){let r=new Set(t??[]);if(n)for(let t of e.memberIds)r.delete(t);else for(let t of e.memberIds)r.add(t);return Array.from(r)}function LJ(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!FJ(e,t)).length}function RJ(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!FJ(e,t)).map(e=>e.label)}Q();function zJ({isOpen:e,onClose:r,groups:i,loading:a,statusLoading:o=!1,reload:s,disabledCollections:c,onChange:l,onConnectionChange:u,readOnly:d=!1}){let{t:f}=K(),p=()=>{s(),u?.()};return n(hT,{isOpen:e,onClose:r,size:`md`,className:`max-w-[92vw] sm:max-w-[620px] lg:max-w-[620px]`,children:[t(gT,{children:f(`mcpConnections.title`)}),n(_T,{children:[t(`p`,{className:`mb-4 text-sm text-muted`,children:f(`mcpConnections.subtitle`)}),a?t(`div`,{className:`flex items-center justify-center py-8`,children:t(fO,{className:`size-5`})}):i.length===0?t(`div`,{className:`py-8 text-center text-sm text-muted`,children:f(`mcpConnections.empty`)}):t(`div`,{className:`space-y-1`,children:i.map(e=>{let r=!FJ(e,c),i=e.authStatus?.authenticated===!0;return n(`div`,{className:`flex items-center justify-between gap-3 py-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[t(i?K_:U_,{className:`size-4 shrink-0 ${i?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(nT,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:e.appName}),e.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:e.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`truncate ${r?`text-foreground`:`text-muted line-through`}`,children:e.label})})]}),n(`div`,{className:`flex shrink-0 items-center gap-3`,children:[o&&!e.authStatus?t(sT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:f(`mcpConnections.checkingStatus`),children:t(fO,{className:`size-3`})}):e.authType===`oauth`?t(hO,{appId:e.appId,collectionId:e.representativeId,collectionName:e.label,authenticated:e.authStatus?.authenticated,onAuthChange:p,variant:`compact`,showDisconnect:!0,readOnly:d}):null,l&&t(uO,{size:`sm`,value:r,onChange:t=>l(IJ(e,c,t)),disabled:d,"aria-label":f(r?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:e.label})})]})]},e.key)})})]})]})}Q();function BJ({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1,variant:s=`outline`,size:c=`sm`}){let{t:l}=K(),{groups:u,loading:d,statusLoading:f,reload:p}=PJ(),[m,h]=G(!1);if(!d&&u.length===0)return null;let g=LJ(u,r),_=RJ(u,r),v=_.slice(0,2),y=_.length-v.length,b=v.length>0?`${v.join(`, `)}${y>0?` +${y}`:``}`:void 0;return n(e,{children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[b&&t(`span`,{className:`max-w-48 truncate text-muted`,title:_.join(`, `),children:b}),n(sT,{variant:s,size:c,className:`shrink-0`,onClick:()=>h(!0),disabled:d,"aria-label":l(`mcpConnections.manage`),children:[t(`span`,{children:l(`mcpConnections.label`)}),g>0&&t(dT,{variant:`success`,children:g})]})]}),t(zJ,{isOpen:m,onClose:()=>h(!1),groups:u,loading:d,reload:p,statusLoading:f,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}function VJ({disabledCollections:e,onChange:r,onConnectionChange:i,readOnly:a=!1}){let{t:o}=K(),{groups:s,loading:c,statusLoading:l,reload:u}=PJ();if(!c&&s.length===0)return null;let d=()=>{u(),i?.()};return c&&s.length===0?n(`div`,{className:`flex items-center gap-2 border-y border-border/70 py-2 text-sm text-muted`,children:[t(fO,{className:`size-4`}),t(`span`,{children:o(`mcpConnections.label`)})]}):t(`div`,{className:`space-y-1`,children:s.map(i=>{let s=!FJ(i,e),c=i.authStatus?.authenticated===!0;return n(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 py-2 text-sm`,children:[n(`div`,{className:`flex min-w-36 flex-1 items-center gap-2`,children:[t(c?K_:U_,{className:`size-4 shrink-0 ${c?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(nT,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:i.appName}),i.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:i.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`block truncate ${s?`text-foreground`:`text-muted line-through`}`,children:i.label})})]}),l&&!i.authStatus?t(sT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:o(`mcpConnections.checkingStatus`),children:t(fO,{className:`size-3`})}):i.authType===`oauth`?t(hO,{appId:i.appId,collectionId:i.representativeId,collectionName:i.label,authenticated:i.authStatus?.authenticated,onAuthChange:d,variant:`compact`,showDisconnect:!0,readOnly:a}):t(dT,{variant:`outline`,className:`h-6 w-32 justify-center px-2 text-xs`,children:o(`mcpConnections.apiKey`)}),r&&n(`div`,{className:`flex min-w-24 items-center justify-end gap-2 text-xs`,children:[t(`span`,{className:s?`text-muted`:`text-attention`,children:o(s?`mcpConnections.enabled`:`mcpConnections.disabled`)}),t(uO,{size:`sm`,value:s,onChange:t=>r(IJ(i,e,t)),disabled:a,"aria-label":o(s?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:i.label})})]})]},i.key)})})}function HJ({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1}){let{t:s}=K(),{groups:c,loading:l,statusLoading:u,reload:d}=PJ(),[f,p]=G(!1);if(!l&&c.length===0)return null;let m=LJ(c,r);return n(e,{children:[t(UD,{align:`left`,trigger:t(sT,{variant:`ghost`,size:`icon`,className:`size-8 rounded-md text-muted hover:bg-muted`,title:s(`mcpConnections.settings`),disabled:l,children:t(`span`,{className:`flex size-5 items-center justify-center rounded-[3px] border border-muted text-sm font-semibold leading-none`,"aria-hidden":`true`,children:`/`})}),children:n(WD,{onClick:()=>p(!0),isDisabled:l,children:[t(`span`,{children:s(`mcpConnections.title`)}),m>0&&t(dT,{variant:`success`,children:m})]})}),t(zJ,{isOpen:f,onClose:()=>p(!1),groups:c,loading:l,reload:d,statusLoading:u,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}const UJ=/(^|\/)(tool-inputs|tool-results|archive)(\/|$)/,WJ=/(^|\/)process\/(history|state)(\/|$)/,GJ=[/conversation\.json$/,/^conversation-checkpoint-\d+\.json$/,/^tools\.json$/,/^tool-input-refs\.json$/,/^toolu[_-]/i];function KJ(e){if(UJ.test(e)||WJ.test(e))return!0;let t=e.split(`/`).pop()??e;return GJ.some(e=>e.test(t))}function qJ(e){let t={name:``,path:``,isDirectory:!0,children:[]};for(let n of e){let e=n.split(`/`),r=t,i=``;for(let t=0;t<e.length;t++){let n=e[t];i=i?`${i}/${n}`:n;let a=t===e.length-1,o=r.children.find(e=>e.name===n);o||(o={name:n,path:i,isDirectory:!a,children:[]},r.children.push(o)),r=o}}let n=e=>{e.children.sort((e,t)=>e.isDirectory===t.isDirectory?e.name.localeCompare(t.name):e.isDirectory?-1:1),e.children.forEach(n)};return n(t),t.children}function JJ(e,t){let n=`agents/${t}/`,r=e.indexOf(n);return r===-1?e.split(`/`).pop()??e:e.slice(r+n.length)}function YJ(e,t,n=0,r=!1){let[i,a]=G([]),[o,s]=G(!1),[c,l]=G(null),[u,d]=G(0),f=W(0),p=V(async()=>{if(!t)return;let n=++f.current;s(!0),l(null);try{let r=await e.files.listArtifacts(t);if(n!==f.current)return;let i=r.map(e=>JJ(e,t)).filter(e=>!!e);a(i)}catch(e){if(n!==f.current)return;l(e instanceof Error?e.message:`Failed to list artifacts`),a([])}finally{n===f.current&&s(!1)}},[e,t]);H(()=>{p()},[p,n,u]);let m=U(()=>r?i:i.filter(e=>!KJ(e)),[i,r]),h=U(()=>qJ(m),[m]),g=i.length-m.length,_=V(()=>{d(e=>e+1)},[]);return{tree:h,flatFiles:m,totalCount:i.length,systemHiddenCount:g,isLoading:o,error:c,refresh:_}}function XJ(){return ZJ||=import(`react-pdf`).then(e=>{let{pdfjs:t}=e;return t.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${t.version}/build/pdf.worker.min.mjs`,e}),ZJ}var ZJ,QJ,$J,eY=Y((()=>{QJ=ht(()=>XJ().then(({Document:e})=>({default:e}))),$J=ht(()=>XJ().then(({Page:e})=>({default:e})))}));function tY({className:e,size:n=`md`}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(tv,{className:`${{sm:`w-4 h-4`,md:`w-6 h-6`,lg:`w-8 h-8`}[n]} animate-spin text-muted-foreground`})})}function nY({pdfUrl:e,pageNumber:r,width:i,className:a,renderTextLayer:o=!1,renderAnnotationLayer:s=!1,onLoadSuccess:c,onError:l}){let[u,d]=G(!0),[f,p]=G(null);return f?t(`div`,{className:`flex items-center justify-center text-destructive text-sm ${a||``}`,children:`Failed to load PDF`}):n(`div`,{className:a,children:[u&&t(tY,{className:`py-4`,size:`md`}),t(ut,{fallback:null,children:t(QJ,{file:e,onLoadSuccess:({numPages:e})=>{d(!1),c?.(e)},onLoadError:e=>{d(!1),p(e),l?.(e)},loading:null,children:t($J,{pageNumber:r,width:i,renderTextLayer:o,renderAnnotationLayer:s,loading:t(tY,{className:`py-4`,size:`sm`})})})})]})}function rY({pdfUrl:e,urlLoading:n=!1,children:r,onLoadSuccess:i}){let[a,o]=G(0),[s,c]=G(!0),[l,u]=G(null),[d,f]=G(null),p=async e=>{o(e.numPages),i?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1});f({width:t.width,height:t.height,aspectRatio:t.width/t.height})}catch(e){console.error(`Failed to get page dimensions:`,e)}c(!1)},m=e=>{c(!1),u(e)},h={pdfUrl:e,numPages:a,loading:n||!e||s,error:l,pageDimensions:d};return l?t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`}):t(uY.Provider,{value:h,children:e?t(ut,{fallback:t(tY,{className:`py-4`,size:`md`}),children:t(QJ,{file:e,onLoadSuccess:p,onLoadError:m,loading:t(tY,{className:`py-4`,size:`md`}),children:r((e,n)=>t($J,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(tY,{className:`py-4`,size:`sm`})},e))})}):t(tY,{className:`py-4`,size:`md`})})}function iY(){return _t(uY)}function aY({pageNumber:e,width:n,className:r}){let i=iY(),a=i?.pageDimensions?.aspectRatio??dY,o=n?Math.round(n/a):200;return i?.loading?t(`div`,{className:`flex items-center justify-center bg-muted ${r||``}`,style:{height:o,width:n||`100%`},children:t(tY,{size:`md`})}):t(`div`,{className:r,children:t($J,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(tY,{className:`py-4`,size:`sm`})})})}function oY({pageNumber:e,width:n,isSelected:r,onSelect:i,renderThumbnail:a,aspectRatio:o=dY,rootMargin:s=`200px 0px`}){let c=W(null),[l,u]=G(!1);H(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0]?.isIntersecting&&u(!0)},{rootMargin:s,threshold:0});return t.observe(e),()=>t.disconnect()},[s]);let d=n?Math.round(n/o):200,f=l?t($J,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d},children:t(tY,{size:`sm`})})}):t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d,width:n||`100%`},children:t(`span`,{className:`text-muted-foreground text-xs`,children:e})});return t(`div`,{ref:c,children:a({pageNumber:e,isSelected:r,pageElement:f,onSelect:i})})}function sY(e){if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t).overflowY;if(e===`auto`||e===`scroll`)return t;t=t.parentElement}return null}function cY({pdfUrl:r,urlLoading:i=!1,pageCount:a,currentPage:o,thumbnailWidth:s,onPageSelect:c,renderThumbnail:l,scrollContainerRef:u,onAspectRatioChange:d,onItemHeightChange:f,calculateItemHeight:p,onPageCountChange:m}){let[h,g]=G(null),[_,v]=G({start:0,end:Math.min(15,a)}),[y,b]=G(null),x=W(null),S=V(e=>{g(e)},[]),C=V(async e=>{m?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1}),n=t.width/t.height;b(n),d?.(n)}catch(e){console.error(`Failed to get page dimensions:`,e),b(dY),d?.(dY)}},[d,m]),w=y??dY,T=s?Math.round(s/w):200,E=p?p(T):T+16+24+8;if(H(()=>{E>0&&y!==null&&f?.(E)},[E,y,f]),H(()=>{let e=u?.current||sY(x.current);if(!e)return;let t=()=>{let t=e.scrollTop,n=e.clientHeight,r=Math.floor(t/E),i=Math.ceil((t+n)/E),o=Math.max(0,r-5),s=Math.min(a,i+5);v(e=>e.start!==o||e.end!==s?{start:o,end:s}:e)};return t(),e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[E,a,u]),h)return t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`});if(i||!r)return t(tY,{className:`py-4`,size:`md`});let D=_.start*E,O=(a-_.end)*E,k=y!==null;return t(`div`,{ref:x,children:t(ut,{fallback:t(tY,{className:`py-4`,size:`md`}),children:t(QJ,{file:r,onLoadSuccess:C,onLoadError:S,loading:t(tY,{className:`py-4`,size:`md`}),children:k?n(e,{children:[D>0&&t(`div`,{style:{height:D}}),Array.from({length:_.end-_.start},(e,n)=>{let r=_.start+n+1;return t(`div`,{"data-page-index":r-1,style:{height:E,overflow:`hidden`},children:t(oY,{pageNumber:r,width:s,isSelected:r===o,onSelect:()=>c(r),renderThumbnail:l,aspectRatio:w})},r)}),O>0&&t(`div`,{style:{height:O}})]}):t(tY,{className:`py-4`,size:`md`})})})})}function lY({pdfUrl:e,pageNumber:r,width:i,height:a,className:o,renderTextLayer:s=!1,renderAnnotationLayer:c=!1,onPageChange:l}){let[u,d]=G(0),[f,p]=G(!0),[m,h]=G(null);return H(()=>{u>0&&l?.(r,u)},[r,u,l]),m?t(`div`,{className:`flex items-center justify-center text-destructive ${o||``}`,children:n(`span`,{children:[`Failed to load PDF: `,m.message]})}):n(`div`,{className:o,children:[f&&t(tY,{className:`py-8`,size:`lg`}),t(ut,{fallback:null,children:t(QJ,{file:e,onLoadSuccess:({numPages:e})=>{d(e),p(!1)},onLoadError:e=>{p(!1),h(e)},loading:null,children:t($J,{pageNumber:Math.min(r,u||1),width:i,height:a,renderTextLayer:s,renderAnnotationLayer:c,loading:t(tY,{className:`py-8`,size:`md`})})})})]})}var uY,dY,fY=Y((()=>{Q(),eY(),uY=dt(null),dY=210/297}));function pY({pdfUrl:r,pdfUrlLoading:i=!1,pageCount:a,currentPage:s,onChange:c,onPageCountChange:l,className:u,compact:d=!1,headerExtra:f}){let{t:m}=K(),h=W(null),g=W(null),[_,v]=G(void 0),[y,b]=G(vY),[x,S]=G(gY),[C,w]=G(null),T=W(null),E=_?Math.round(_*y/100):void 0,D=V(()=>{let e=_Y.findIndex(e=>e>=y);e===-1&&(e=_Y.length-1);let t=Math.min(e+1,_Y.length-1);b(_Y[t])},[y]),O=V(()=>{let e=_Y.findIndex(e=>e>=y);e===-1&&(e=_Y.length-1);let t=Math.max(e-1,0);b(_Y[t])},[y]),k=V(()=>{b(vY)},[]),A=V(e=>e+(d?28:48),[d]),j=V((e,t)=>{let n=e?Math.round(e/t):200;return A(n)},[A]);H(()=>{let e=g.current;if(!e)return;let t=null,n=()=>e.clientWidth-16-16-4,r=()=>{let t=n();if(t<=0)return;let r=T.current;if(r&&r>0){let n=e.scrollTop,i=Math.round(n/r),a=j(t,x),o=i*a;v(t),requestAnimationFrame(()=>{e.scrollTo({top:o,behavior:`instant`})}),T.current=a}else v(t),T.current=j(t,x)},i=n();i>0&&(v(i),T.current=j(i,x));let a=new ResizeObserver(()=>{t&&clearTimeout(t),t=setTimeout(r,150)});return a.observe(e),()=>{t&&clearTimeout(t),a.disconnect()}},[x,j]);let M=W(!1),N=W(null),P=W(y);H(()=>{P.current!==y&&(P.current=y,N.current={targetPage:s},M.current=!0)},[y,s]),H(()=>{let e=g.current,t=N.current;if(t&&e&&C){N.current=null;let n=(t.targetPage-1)*C;requestAnimationFrame(()=>{e.scrollTo({top:n,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})})}},[C]);let F=W(!1);H(()=>{let e=g.current;if(!(!e||!C||F.current)){if(s>1){F.current=!0,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}else F.current=!0}},[C,s]);let I=W(s);return H(()=>{let e=g.current;if(!(!e||!C)&&I.current!==s){I.current=s,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}},[s,C]),H(()=>{let e=g.current;if(!e||!C)return;let t=null,n=()=>{M.current||(t&&clearTimeout(t),t=setTimeout(()=>{let t=e.scrollTop,n=Math.round(t/C)+1,r=Math.max(1,Math.min(n,a));r!==s&&(I.current=r,c(r))},50))};return e.addEventListener(`scroll`,n,{passive:!0}),()=>{t&&clearTimeout(t),e.removeEventListener(`scroll`,n)}},[C,a,s,c]),n(`div`,{ref:h,className:it(`flex flex-col items-stretch`,d?`gap-y-1`:`gap-y-2`,u),children:[n(`div`,{className:it(`relative flex items-center justify-center px-2`,d?`h-6`:`h-9`),children:[t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s>1&&c(s-1)},title:m(`pdf.previousPage`),children:t(Oh,{className:`size-4`})}),n(`div`,{className:`absolute start-2 flex items-center gap-x-1`,children:[t(hY,{zoom:y,onZoomIn:D,onZoomOut:O,onFitToView:k,canZoomIn:y<_Y[_Y.length-1],canZoomOut:y>_Y[0]}),f&&n(e,{children:[t(`div`,{className:`w-px h-4 bg-border mx-1`}),f]})]}),t(`div`,{className:`absolute end-2`,children:t(mY,{currentPage:s,totalPages:a,onChange:c})})]}),t(`div`,{ref:g,className:it(`flex flex-col items-center flex-1 overflow-y-auto px-2`,d?`gap-1`:`gap-2`),children:t(cY,{pdfUrl:r,urlLoading:i,pageCount:a,currentPage:s,thumbnailWidth:E,onPageSelect:c,onPageCountChange:l,scrollContainerRef:g,onAspectRatioChange:S,onItemHeightChange:w,calculateItemHeight:A,renderThumbnail:({pageNumber:e,isSelected:r,pageElement:i,onSelect:a})=>n(`div`,{className:it(`hover:bg-muted rounded-md w-full`,d?`p-1`:`p-2`),children:[t(o,{variant:`unstyled`,size:`none`,"aria-pressed":r,"aria-label":`Page ${e}`,className:it(`relative border-[2px] cursor-pointer overflow-hidden`,r?`border-primary`:`border-border`),onClick:a,children:i}),t(p,{className:it(`text-muted-foreground font-semibold`,d?`text-xs pt-0.5`:`text-sm pt-1`),children:e})]},e)})}),t(`div`,{className:it(`flex items-center justify-center`,d?`h-6`:`h-9`),children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s<a&&c(s+1)},title:m(`pdf.nextPage`),children:t(gh,{className:`size-4`})})})]})}function mY({currentPage:e,totalPages:r,onChange:i}){let{t:a}=K(),o=W(null),[s,c]=G(String(e));H(()=>{c(String(e))},[e]);let l=()=>{let t=parseInt(s,10);!Number.isNaN(t)&&t>=1&&t<=r?i(t):c(String(e))};return n(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[t(`span`,{children:a(`pdf.page`)}),t(`input`,{ref:o,type:`text`,value:s,onChange:e=>c(e.target.value),onKeyDown:t=>{t.key===`Enter`?(l(),o.current?.blur()):t.key===`Escape`&&(c(String(e)),o.current?.blur())},onBlur:()=>{l()},className:`w-8 h-5 text-center text-xs px-1 py-0 bg-background border border-border rounded focus:outline-none focus:border-primary`}),n(`span`,{children:[`/ `,r]})]})}function hY({zoom:e,onZoomIn:r,onZoomOut:i,onFitToView:a,canZoomIn:s,canZoomOut:c}){let{t:l}=K();return n(`div`,{className:`flex items-center gap-x-0.5`,children:[t(o,{variant:`ghost`,size:`xs`,onClick:i,isDisabled:!c,title:l(`pdf.zoomOut`),children:t(jv,{})}),n(`span`,{className:`text-xs text-muted-foreground min-w-[32px] text-center`,children:[e,`%`]}),t(o,{variant:`ghost`,size:`xs`,onClick:r,isDisabled:!s,title:l(`pdf.zoomIn`),children:t(sy,{})}),t(o,{variant:`ghost`,size:`xs`,onClick:a,title:l(`pdf.fitToWidth`),className:e===vY?`text-muted-foreground/40`:void 0,children:t(pv,{})})]})}var gY,_Y,vY,yY=Y((()=>{Q(),fY(),gY=210/297,_Y=[50,75,100,125,150,200,300],vY=100}));function bY({object:e,url:r,source:i,className:a}){let{t:s}=K(),{client:c}=q(),[l,u]=G(1),[d,f]=G(r||``),[p,m]=G(!r),[h,g]=G(0),[_,v]=G(!1);H(()=>{if(r){f(r),m(!1);return}let t=i||e?.content?.source;if(!t){m(!1);return}m(!0),c.files.getDownloadUrl(t).then(e=>{f(e.url)}).catch(e=>{console.error(`Failed to get PDF URL:`,e)}).finally(()=>{m(!1)})},[r,i,e?.content?.source,c]),H(()=>{let t=e?.metadata,n=t?.pages||t?.page_count||0;n>0&&g(n)},[e?.metadata]);let y=e=>{g(e)};return p?t(`div`,{className:`flex items-center justify-center h-full`,children:t(je,{size:`lg`})}):d?_?n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col overflow-hidden`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>v(!1),title:s(`pdf.closeFullscreen`),children:t(Kb,{className:`size-4`})})}),t(pY,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:`flex-1 min-h-0`})]}):t(`div`,{className:`relative h-full flex flex-col`,children:t(pY,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:a,compact:!0,headerExtra:t(o,{title:s(`pdf.fullscreen`),tooltipPlacement:`bottom`,variant:`unstyled`,className:`p-1 rounded cursor-pointer transition-colors text-muted-foreground hover:text-foreground hover:bg-muted`,onClick:()=>v(!0),children:t(uv,{className:`size-4`})})})}):t(`div`,{className:`flex items-center justify-center h-full text-muted`,children:s(`pdf.noPdfAvailable`)})}var xY=Y((()=>{Q(),yY()})),SY=hr({UniversalDocumentViewer:()=>qY});function CY(e){return e.fileName||e.title||e.artifact?.path.split(`/`).pop()||e.sourcePath?.split(`/`).pop()||`Document`}function wY(e){let t=e.split(`?`)[0]||e;return t.includes(`.`)&&t.split(`.`).pop()?.toLowerCase()||``}function TY(e){return e.contentType===`application/pdf`||e.extension===`pdf`}function EY(e){return[`md`,`markdown`].includes(e.extension)||[`text/markdown`,`text/x-markdown`].includes(e.contentType||``)}function DY(e){return e.contentType?.startsWith(`image/`)||[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`].includes(e.extension)}function OY(e){return e.contentType===`text/html`||[`html`,`htm`].includes(e.extension)}function kY(e){return[`application/xml`,`text/xml`].includes(e.contentType||``)||e.extension===`xml`}function AY(e){return e.contentType?.startsWith(`text/`)||[`css`,`csv`,`json`,`txt`,`tsx`,`ts`,`jsx`,`js`,`xml`,`yaml`,`yml`].includes(e.extension)}function jY(e){return[`tsx`,`jsx`].includes(e.extension)}function MY(e){return[`doc`,`docx`,`ppt`,`pptx`].includes(e.extension)||[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`].includes(e.contentType||``)}function NY({content:e,extension:n}){return t(`pre`,{className:`h-full overflow-auto rounded-md bg-muted/10 p-3 text-xs leading-5`,children:t(`code`,{className:n?`language-${n}`:void 0,children:e||``})})}function PY({message:e}){return n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-muted`,children:[t(Qg,{className:`size-8`}),t(`span`,{className:`text-sm`,children:e})]})}function FY(e,n){if(e.Component){let r=e.Component;return t(r,{context:n})}return e.render?.(n)??null}function IY(e,t){return e.includes(`.`)?e.replace(/\.[^/.]+$/,t):`${e}${t}`}function LY(e){return e.split(`/`).pop()||e}function RY(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function zY(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function BY(e){if(e!==void 0)return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function VY(e){return Array.isArray(e)?e.length:0}function HY(e){try{let t=RY(JSON.parse(e));if(!t)return;let n=RY(t.viewport);return{ok:typeof t.ok==`boolean`?t.ok:void 0,source_artifact:typeof t.source_artifact==`string`?t.source_artifact:void 0,screenshot_artifact:typeof t.screenshot_artifact==`string`?t.screenshot_artifact:void 0,rendered_at:typeof t.rendered_at==`string`?t.rendered_at:void 0,viewport:n?{width:zY(n.width),height:zY(n.height)}:void 0,dependencies_reused:typeof t.dependencies_reused==`boolean`?t.dependencies_reused:void 0,status:zY(t.status),title:typeof t.title==`string`?t.title:void 0,console_errors:Array.isArray(t.console_errors)?t.console_errors:void 0,page_errors:Array.isArray(t.page_errors)?t.page_errors:void 0,failed_requests:Array.isArray(t.failed_requests)?t.failed_requests:void 0,bad_responses:Array.isArray(t.bad_responses)?t.bad_responses:void 0,timings_ms:RY(t.timings_ms),error:t.error}}catch{return}}async function UY(e,t){let n=await fetch(e);if(!n.ok)throw Error(`Failed to load ${t}: ${n.statusText}`);return n.text()}function WY({metadata:e,sourcePath:t,fallbackPath:n,artifactMode:r}){let i=e?.screenshot_artifact?.replace(/^\/+/,``);if(!i)return n;if(r)return i;let a=e?.source_artifact?.replace(/^\/+/,``),o=t.replace(/^\/+/,``);if(a&&o.endsWith(a)){let e=o.slice(0,-a.length).replace(/\/+$/,``);return e?`${e}/${i}`:i}let s=o.includes(`/`)?o.slice(0,o.lastIndexOf(`/`)+1):``;return s?`${s}${LY(i)}`:n}function GY({metadata:e}){if(!e)return null;let r=zY(e.timings_ms?.total_before_cleanup),a=VY(e.console_errors)+VY(e.page_errors)+VY(e.failed_requests)+VY(e.bad_responses);return n(`div`,{className:`grid gap-2 border-b p-3 text-xs`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.ok!==void 0&&t(i,{variant:e.ok?`success`:`destructive`,children:e.ok?`render ok`:`render failed`}),e.dependencies_reused!==void 0&&n(i,{variant:e.dependencies_reused?`info`:`secondary`,children:[`deps `,e.dependencies_reused?`reused`:`installed`]}),e.status&&n(i,{variant:`secondary`,children:[`HTTP `,e.status]}),a>0&&n(i,{variant:`attention`,children:[a,` browser issue(s)`]})]}),n(`div`,{className:`grid gap-1 text-muted sm:grid-cols-2`,children:[e.viewport?.width&&e.viewport.height&&n(`div`,{children:[`Viewport `,e.viewport.width,` x `,e.viewport.height]}),BY(r)&&n(`div`,{children:[`Total `,BY(r)]}),e.rendered_at&&n(`div`,{children:[`Rendered `,new Date(e.rendered_at).toLocaleString()]}),e.title&&n(`div`,{className:`truncate`,children:[`Title `,e.title]})]}),typeof e.error==`string`&&t(`div`,{className:`text-destructive`,children:e.error})]})}function KY({context:e}){let{client:r}=q(),a=e.source.artifact,o=a?.path||e.source.sourcePath,s=!!a,c=e.content||``,[l,u]=G({isLoading:!1}),d=V(async(e,t)=>a?(await r.files.getArtifactDownloadUrl(a.runId,e,t)).url:(await r.files.getDownloadUrl(e,LY(e),t)).url,[a,r]);return H(()=>{if(!o){u({isLoading:!1,previewError:`No source path is available for this TSX artifact.`});return}let e=o,t=!1,n=IY(e,`.png`),r=IY(e,`.render.json`);async function i(){u({isLoading:!0});let i,a,o=n;try{i=HY(await UY(await d(r,`inline`),LY(r))),o=WY({metadata:i,sourcePath:e,fallbackPath:n,artifactMode:s})}catch(e){a=e instanceof Error?e.message:`Render metadata is not available`}let c,l;try{c=await d(o,`inline`)}catch(e){l=e instanceof Error?e.message:`Sandbox render image is not available`}t||u({isLoading:!1,imageUrl:c,metadata:i,metadataError:a,previewError:l})}return i(),()=>{t=!0}},[s,d,o]),n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex min-h-10 flex-wrap items-center gap-2 border-b px-3 py-2 text-sm`,children:[t(O_,{className:`size-4 text-info`}),t(`span`,{className:`font-medium`,children:`Sandbox render`}),l.isLoading?t(i,{variant:`secondary`,children:`loading`}):l.imageUrl?t(i,{variant:`success`,children:`PNG preview`}):t(i,{variant:`attention`,children:`source only`}),l.metadata?.rendered_at&&t(`span`,{className:`text-xs text-muted`,children:new Date(l.metadata.rendered_at).toLocaleString()})]}),l.isLoading?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(tv,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading sandbox render...`})]}):l.imageUrl?n(`div`,{className:`grid min-h-0 flex-1 xl:grid-cols-[minmax(0,1fr)_minmax(24rem,0.7fr)]`,children:[t(`div`,{className:`flex min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:l.imageUrl,alt:`${e.fileName} sandbox render`,className:`max-h-full max-w-full rounded-md object-contain`})}),n(`div`,{className:`min-h-0 overflow-auto border-t xl:border-s xl:border-t-0`,children:[t(GY,{metadata:l.metadata}),t(`div`,{className:`p-3`,children:t(NY,{content:c,extension:e.extension})})]})]}):n(`div`,{className:`grid min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)]`,children:[n(`div`,{className:`border-b px-3 py-2 text-xs text-muted`,children:[`No sandbox-rendered PNG was found for this TSX artifact. Showing the source without executing it in Studio.`,l.previewError&&n(`span`,{className:`ms-1`,children:[`Preview lookup: `,l.previewError]}),!l.previewError&&l.metadataError&&n(`span`,{className:`ms-1`,children:[`Metadata lookup: `,l.metadataError]})]}),n(`div`,{className:`min-h-0 overflow-auto p-3`,children:[t(GY,{metadata:l.metadata}),t(NY,{content:c,extension:e.extension})]})]})]})}function qY({source:e,className:r,bodyClassName:i,renderers:a=[],converters:s=[],resolveUrl:c,loadText:l,createRendition:u,markdownComponents:d,showHeader:f=!1,onDownload:p}){let{client:m}=q(),h=U(()=>CY(e),[e]),g=U(()=>wY(h),[h]),[_,v]=G(e.url),[y,b]=G(e.content),[x,S]=G(null),[C,w]=G(!1),[T,E]=G(null),[D,O]=G(0),k=[e.id,e.title,e.fileName,e.contentType,e.url,e.sourcePath,e.content,e.artifact?.runId,e.artifact?.path].join(`\0`),A=V(async(e,t)=>e.url?e.url:e.artifact?(await m.files.getArtifactDownloadUrl(e.artifact.runId,e.artifact.path,t)).url:e.sourcePath?(await m.files.getDownloadUrl(e.sourcePath,e.fileName,t)).url:``,[m]),j=c||A,M=V(async e=>{if(e.content!==void 0)return e.content;let t=await j(e,`inline`);if(!t)return``;let n=await fetch(t);if(!n.ok)throw Error(`Failed to load ${CY(e)}: ${n.statusText}`);return n.text()},[j]),N=l||M,P={source:e,fileName:h,extension:g,contentType:e.contentType||x?.contentType,url:x?.url||_,content:x?.content||y,isLoading:C,error:T,reload:()=>O(e=>e+1)},F=a.find(e=>e.canRender(P)),I=!F&&(EY(P)||OY(P)||kY(P)||AY(P)),L=!F&&(TY(P)||DY(P)),ee={source:e,fileName:h,extension:g,contentType:e.contentType,target:`pdf`},R=!F&&!P.url?s.find(e=>e.target===`pdf`&&e.canConvert(ee)):void 0,te=!F&&!P.url&&(MY(P)||!!R)&&(!!R||!!u);H(()=>{let t=!1,n=e;E(null),v(n.url),b(n.content),S(null);async function r(){if(!(!I&&!L&&!te)){w(!0);try{if(te){let e=R?await R.convert({source:n,fileName:h,extension:g,contentType:n.contentType,target:`pdf`}):await u?.(n,`pdf`);t||S(e??null);return}if(I){let e=await N(n);t||b(e);return}if(L){let e=await j(n,`inline`);t||v(e)}}catch(e){t||E(e instanceof Error?e.message:`Failed to load document`)}finally{t||w(!1)}}}return r(),()=>{t=!0}},[u,g,h,N,te,I,L,D,j,R,e,k]);let ne={...P,url:x?.url||_,content:x?.content||y,contentType:x?.contentType||e.contentType,isLoading:C,error:T},re;return re=C?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(tv,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading preview...`})]}):T?n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-destructive`,children:[t(jh,{className:`size-7`}),t(`span`,{className:`max-w-xl text-center text-sm`,children:T}),t(o,{variant:`outline`,size:`sm`,onClick:ne.reload,children:`Retry`})]}):F?FY(F,ne):(TY(ne)||x?.contentType===`application/pdf`)&&ne.url?t(bY,{url:ne.url,className:`h-full`}):DY(ne)&&ne.url?t(`div`,{className:`flex h-full min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:ne.url,alt:h,className:`max-h-full max-w-full rounded-md object-contain`})}):EY(ne)?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none px-5 py-4`,children:t(Nt,{artifactRunId:e.artifact?.runId,components:d,children:ne.content||``})}):OY(ne)?t(`iframe`,{title:h,className:`h-full min-h-96 w-full bg-white`,sandbox:``,srcDoc:ne.content||``}):kY(ne)?t(`div`,{className:`px-4 py-2`,children:t(Rt,{xml:ne.content||``,collapsible:!0})}):jY(ne)?t(KY,{context:ne}):AY(ne)?t(NY,{content:ne.content,extension:g}):MY(ne)&&!R&&!u?t(PY,{message:`This file needs a PDF rendition before it can be previewed.`}):t(PY,{message:`Preview is not available for this file type.`}),n(`div`,{className:z(`flex h-full min-h-0 flex-col overflow-hidden`,r),children:[f&&n(`div`,{className:`flex min-h-10 items-center justify-between gap-3 border-b py-2 ps-3 pe-16`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,title:h,children:h}),ne.contentType&&t(`div`,{className:`truncate text-xs text-muted`,children:ne.contentType})]}),p&&t(o,{variant:`outline`,size:`sm`,onClick:()=>p(e),children:`Download`})]}),t(`div`,{className:z(`min-h-0 flex-1 overflow-auto`,i),children:re})]})}var JY=Y((()=>{Q(),xY()}));Q();const YY=ot.lazy(async()=>({default:(await Promise.resolve().then(()=>(JY(),SY))).UniversalDocumentViewer})),XY=new Set([`md`,`markdown`,`mdx`,`txt`]);function ZY(e){let t=e.split(`.`).pop()?.toLowerCase();return t!==void 0&&XY.has(t)}function QY(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function $Y({node:e,depth:r,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l=!1}){let{t:u}=K(),[d,f]=G(!1),p=l||d;if(e.isDirectory)return n(`div`,{className:`min-w-0`,children:[n(o,{variant:`unstyled`,className:`flex w-full max-w-full items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>f(e=>!e),"aria-expanded":p,children:[p?t(ih,{className:`size-3.5 shrink-0 text-muted`}):t(uh,{className:`size-3.5 shrink-0 text-muted cn-rtl-flip`}),t(p?i_:s_,{className:`size-4 shrink-0 text-info`}),t(`span`,{className:`min-w-0 truncate font-medium`,title:e.path,children:QY(e.name)})]}),p&&e.children.map(e=>t($Y,{node:e,depth:r+1,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l},`${i}:${e.path}`))]});let m=c===e.path;return n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[n(o,{variant:`unstyled`,className:`flex min-w-0 flex-1 items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>a(e.path),title:e.path,children:[t(`span`,{className:`size-3.5 shrink-0`}),t(Qg,{className:`size-4 shrink-0 text-muted`}),t(`span`,{className:`min-w-0 truncate`,children:e.name})]}),t(o,{variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>s(e.path),disabled:m,"aria-label":u(`agent.download`),title:u(`agent.download`),children:m?t(tv,{className:`size-3.5 animate-spin text-info`}):t(Sg,{className:`size-3.5`})})]})}function eX(e){return e.reduce((e,t)=>t.isDirectory?e+eX(t.children):e+1,0)}function tX(e,t){let n=t.trim().toLocaleLowerCase();return n?e.flatMap(e=>{let t=`${e.name} ${e.path}`.toLocaleLowerCase().includes(n);if(!e.isDirectory)return t?[e]:[];let r=tX(e.children,n);return t?[{...e}]:r.length>0?[{...e,children:r}]:[]}):e}function nX(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.rel=`noopener noreferrer`,n.style.display=`none`,document.body.appendChild(n),n.click(),n.remove()}function rX(e){switch(e.split(`.`).pop()?.toLowerCase()){case`css`:return`text/css`;case`gif`:return`image/gif`;case`htm`:case`html`:return`text/html`;case`jpeg`:case`jpg`:return`image/jpeg`;case`json`:return`application/json`;case`md`:case`markdown`:return`text/markdown`;case`pdf`:return`application/pdf`;case`png`:return`image/png`;case`svg`:return`image/svg+xml`;case`ts`:case`tsx`:return`text/typescript`;case`txt`:return`text/plain`;case`webp`:return`image/webp`;default:return}}function iX({runId:e,path:r,onBack:i,onDownload:a,refreshKey:s,refreshDetails:c,onSendMessage:l}){let{t:u}=K(),[d,f]=G(`components`),[p,m]=G(`idle`);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-2 py-1`,children:[t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:i,"aria-label":u(`agent.backToArtifacts`),title:u(`agent.backToArtifacts`),children:t(Tm,{className:`size-4 cn-rtl-flip`})}),n(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[t(`span`,{className:`truncate text-sm font-medium`,title:r,children:r.split(`/`).pop()}),p===`saving`?t(We,{description:u(`agent.savingWorkingCopy`),asChild:!0,children:t(tv,{className:`size-3.5 shrink-0 animate-spin text-muted`,"aria-label":u(`agent.savingWorkingCopy`)})}):p===`saved`?t(We,{description:u(`agent.savedToWorkingCopy`),asChild:!0,children:t(th,{className:`size-3.5 shrink-0 text-success`,"aria-label":u(`agent.savedToWorkingCopy`)})}):null]}),n(`div`,{className:`flex items-center gap-0.5`,children:[t(o,{variant:d===`components`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`components`),"aria-label":u(`agent.blockMode`),"aria-pressed":d===`components`,title:u(`agent.blockMode`),children:t(Sy,{className:`size-4`})}),t(o,{variant:d===`document`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`document`),"aria-label":u(`agent.editMode`),"aria-pressed":d===`document`,title:u(`agent.editMode`),children:t(Yv,{className:`size-4`})})]}),t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>a(r),"aria-label":u(`agent.download`),title:u(`agent.download`),children:t(Sg,{className:`size-4`})})]}),t(wt,{runId:e,path:r,viewMode:d,refreshKey:s,refreshDetails:c,readOnly:!l,onAction:e=>{if(!l)return;let t=e.anchor.block_type.replaceAll(`_`,` `);l(e.comment?.trim()||u(`agent.editedSelectionMessage`,{blockType:t}),{editing_action:e})},onSaveStatusChange:m,onSendMessage:l?e=>l(e):void 0,className:z(`relative min-h-0 flex-1`,d===`document`?`overflow-hidden`:`overflow-y-auto px-6 py-5`)})]})}function aX({icon:e,children:r,action:i}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r}),i]})}function oX({runId:r,refreshKey:i=0,refreshDetails:a,selectedPath:s,onSelectedPathChange:c,onSendMessage:l}){let{t:u}=K(),{client:d}=q(),[f,m]=G(!1),{tree:h,flatFiles:g,totalCount:_,systemHiddenCount:v,isLoading:y,error:b,refresh:x}=YJ(d,r,i,f),[S,C]=G(null),[w,T]=G(null),[E,D]=G(``),[O,k]=G(null),A=s===void 0?O:s,j=V(e=>{s===void 0&&k(e),c?.(e)},[c,s]),N=E.trim(),P=U(()=>tX(h,N),[h,N]),F=U(()=>eX(P),[P]),I=vt(),L=V(async e=>{if(r){C(e);try{let{url:t}=await d.files.getArtifactDownloadUrl(r,e,`attachment`);nX(t,e.split(`/`).pop()||`artifact`)}catch(e){console.error(`Failed to get artifact download URL:`,e)}finally{C(null)}}},[d,r]),ee=V(e=>{if(ZY(e)){j(e);return}T(e)},[j]),R=r&&w?{title:w.split(`/`).pop()||w,fileName:w.split(`/`).pop()||w,contentType:rX(w),artifact:{runId:r,path:w}}:null;return r?y&&_===0?t(aX,{icon:t(tv,{className:`mb-2 size-6 animate-spin`}),children:u(`agent.loadingArtifacts`)}):b?t(`div`,{className:`flex flex-col items-center justify-center p-4 text-muted w-full`,children:n(M,{title:`Fail to load Artifacts`,className:`w-full`,action:x,actionLabel:n(e,{children:[t(gy,{className:`size-3.5 me-1.5`}),u(`agent.retry`)]}),children:[t(`span`,{className:`break-all text-muted`,children:b}),` `,t(`br`,{})]})}):_===0?t(aX,{icon:t(Lv,{className:`mb-2 size-8`}),action:n(o,{variant:`ghost`,size:`sm`,className:`mt-2`,onClick:x,children:[t(gy,{className:`size-3.5 me-1.5`}),u(`agent.refresh`)]}),children:u(`agent.noArtifactsYet`)}):A?t(iX,{runId:r,path:A,refreshKey:i,refreshDetails:a,onBack:()=>j(null),onDownload:e=>void L(e),onSendMessage:l}):n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted`,children:[n(`span`,{children:[N?`${F} of ${g.length} file${g.length===1?``:`s`}`:`${g.length} file${g.length===1?``:`s`}`,!f&&v>0?` · ${v} hidden`:``]}),n(`div`,{className:`flex items-center gap-1`,children:[t(Ne,{size:`sm`,value:f,onChange:m,children:t(`span`,{className:`text-xs text-muted`,children:u(`agent.showSystemArtifacts`)})}),t(o,{variant:`ghost`,size:`sm`,onClick:x,disabled:y,className:`h-6 w-6 p-0`,children:t(gy,{className:`size-3.5 ${y?`animate-spin`:``}`})})]})]}),t(`label`,{htmlFor:I,className:`sr-only`,children:u(`form.filter`)}),t(te,{id:I,type:`text`,role:`searchbox`,autoComplete:`off`,placeholder:u(`store.searchPlaceholder`),value:E,onChange:D,clearable:!0})]}),t(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:P.length>0?t(`div`,{className:`min-w-0`,children:P.map(e=>t($Y,{node:e,depth:0,runId:r,onOpen:ee,onDownload:L,downloadingPath:S,forceExpanded:!!N},`${r}:${e.path}`))}):t(`div`,{className:`px-1 py-6 text-sm text-muted`,children:u(!f&&v>0?`agent.onlySystemArtifacts`:`agent.noContentAvailable`)})}),R&&n(se,{isOpen:!!w,onClose:()=>T(null),size:`xl`,className:`h-[90vh] p-0`,description:`Artifact preview`,children:[t(ue,{show:!1,children:R.fileName}),t(ce,{className:`h-full max-h-none p-0`,children:t(ot.Suspense,{fallback:t(p,{className:`h-full`,children:t(tv,{className:`size-6 animate-spin text-muted`})}),children:t(YY,{source:R,className:`h-full`,showHeader:!0,onDownload:()=>w&&void L(w)})})})]})]}):t(aX,{icon:t(Lv,{className:`mb-2 size-8`}),children:`No run selected`})}const sX=ot.memo(oX);Q();function cX(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function lX(e){if(!cX(e))return;let t=e.browseruse??e.browser_use;if(!cX(t))return;let n={widget:typeof t.widget==`string`?t.widget:void 0,browser_workflow_id:typeof t.browser_workflow_id==`string`?t.browser_workflow_id:void 0,workstream_id:typeof t.workstream_id==`string`?t.workstream_id:void 0,phase:typeof t.phase==`string`?t.phase:void 0,url:typeof t.url==`string`?t.url:void 0,title:typeof t.title==`string`?t.title:void 0,screenshot:typeof t.screenshot==`string`?t.screenshot:void 0,raw_screenshot:typeof t.raw_screenshot==`string`?t.raw_screenshot:void 0,prefer_raw_screenshot:typeof t.prefer_raw_screenshot==`boolean`?t.prefer_raw_screenshot:void 0,updated_at:typeof t.updated_at==`number`?t.updated_at:void 0};if(!(n.widget&&n.widget!==`browseruse`)&&!(!n.url&&!n.title&&!n.screenshot&&!n.raw_screenshot))return n}function uX(e){let t=new Map;for(let n of e){let e=lX(n.details);if(!e)continue;let r=e.workstream_id||n.workstream_id||`main`,i=e.updated_at??(typeof n.timestamp==`number`?n.timestamp:new Date(n.timestamp).getTime()),a=t.get(r);(!a||i>=a.timestamp)&&t.set(r,{state:{...e,workstream_id:r},timestamp:i})}return new Map(Array.from(t.entries()).map(([e,t])=>[e,t.state]))}function dX(e){return e.replace(/^artifact:\/\//,``).replace(/^artifact:/,``).replace(/^\/+/,``)}function fX(e){return e?e.replace(/_/g,` `):`browser`}function pX({state:e,runId:r,className:a,compact:o}){let{t:s}=K(),{client:c}=q(),l=HS(),{openImage:u}=TW(),[d,f]=G(),p=e.prefer_raw_screenshot===!1?e.screenshot||e.raw_screenshot:e.raw_screenshot||e.screenshot,m=e.title||e.url||s(`agent.browserUse`),h=U(()=>p&&dX(p).split(`/`).pop()||s(`agent.browserScreenshot`),[p,s]);return H(()=>{if(!p){f(void 0);return}if(p.startsWith(`http://`)||p.startsWith(`https://`)){f(p);return}if(!r){f(void 0);return}let e=!1;return(async()=>{let t=dX(p);try{let n=WS(r,t,`inline`),i=l?await l.getOrFetch(n,async()=>(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url):(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url;e||f(i)}catch(n){console.error(`Failed to resolve browser screenshot ${t}`,n),e||f(void 0)}})(),()=>{e=!0}},[c,r,p,l]),o?n(`div`,{className:z(`overflow-hidden rounded-md border border-border/70 bg-transparent`,a),children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[t(Pv,{className:`size-3.5 shrink-0 text-info`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[t(`span`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserPreview`)}),e.phase&&n(`span`,{className:`truncate text-[11px] capitalize text-muted`,children:[`· `,fX(e.phase)]})]}),t(`div`,{className:`truncate text-[11px] text-muted`,title:m,children:m})]}),e.url&&t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:z(`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md`,`text-muted hover:bg-muted hover:text-foreground`),children:t(Og,{className:`size-3`})})]}),p&&(d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-32 w-full object-contain`})}):n(`div`,{className:`flex min-h-16 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-4 text-xs text-muted`,children:[t(O_,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}))]}):n(`div`,{className:z(`overflow-hidden rounded-md border border-muted bg-mixer-muted/10`,a),children:[n(`div`,{className:`flex items-start justify-between gap-2 border-b border-muted px-2.5 py-2`,children:[n(`div`,{className:`flex min-w-0 items-start gap-2`,children:[t(Pv,{className:`mt-0.5 size-4 shrink-0 text-info`}),n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserUse`)}),t(`div`,{className:`truncate text-xs text-muted`,title:m,children:m})]})]}),t(i,{variant:`info`,className:`shrink-0 capitalize`,children:fX(e.phase)})]}),d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-56 w-full object-contain`})}):n(`div`,{className:`flex min-h-28 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-6 text-xs text-muted`,children:[t(O_,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}),e.url&&n(`div`,{className:`flex items-center gap-2 border-t border-muted px-2.5 py-1.5`,children:[t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`min-w-0 flex-1 truncate text-xs text-info hover:underline`,title:e.url,children:e.url}),t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:z(`inline-flex h-6 shrink-0 items-center justify-center rounded-md px-1.5`,`text-muted hover:bg-muted hover:text-foreground`),children:t(Og,{className:`size-3`})})]})]})}Q();function mX({documents:e,activeId:n,onSelect:r}){return e.length===0?null:t(`div`,{className:`flex items-center gap-1 px-2 py-1.5`,children:t(w,{align:`right`,trigger:t(o,{variant:`ghost`,size:`xs`,title:`All opened documents`,className:`flex items-center gap-1.5 max-w-[220px] text-xs h-7 px-2`,children:t(ih,{className:`size-3 shrink-0`})}),children:e.map(e=>t(ae,{onClick:()=>r(e.id),className:e.id===n?`font-medium`:``,children:t(`span`,{className:`truncate max-w-[200px]`,children:e.title})},e.id))})})}Q();function hX({isOpen:e,documents:r,activeDocumentId:i,onSelectDocument:a,onCloseDocument:s,onUpdateDocumentTitle:c,refreshKey:l,runId:u}){let{client:d}=q(),{t:f}=K(),[p,m]=G(null),[h,g]=G(!1),[_,v]=G(null),[y,b]=G(null),x=V(async e=>{g(!0),v(null);try{let[t,n]=await Promise.all([d.store.objects.getObjectText(e),d.store.objects.retrieve(e)]);m(t.text??null);let r=n.name;b(r),r&&c?.(e,r)}catch(e){let t=e instanceof Error?e.message:f(`agent.failedToLoadDocument`);v(t),m(null)}finally{g(!1)}},[d,c,f]);return H(()=>{i&&e&&x(i)},[i,l,e,x]),!e||r.length===0?null:n(`div`,{className:`h-full shadow-xl border border-muted/20 overflow-hidden flex flex-col`,children:[n(`div`,{className:`flex items-center justify-between px-3 py-2 border-b border-muted/20 shrink-0`,children:[n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(Kg,{className:`size-4 text-muted shrink-0`}),t(`h3`,{className:`font-bold text-sm truncate`,children:y||f(`agent.document`)})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(mX,{documents:r,activeId:i,onSelect:a}),i&&t(Qn,{href:`/store/objects/${i}#overview`,topLevelNav:!0,className:`inline-flex items-center justify-center rounded-md text-sm font-medium h-8 w-8 hover:bg-muted/20 text-muted hover:text-foreground`,children:t(We,{description:f(`agent.openDocument`),placement:`top`,size:`xs`,children:t(Og,{className:`size-4`})})}),t(o,{variant:`ghost`,size:`sm`,onClick:()=>i&&s(i),title:f(`agent.close`),children:t(Kb,{className:`size-4`})})]})]}),t(`div`,{className:`flex-1 overflow-y-auto px-4 py-4`,children:h?n(`div`,{className:`flex items-center justify-center py-12`,children:[t(tv,{className:`size-5 animate-spin text-muted`}),t(`span`,{className:`ms-2 text-sm text-muted`,children:f(`agent.loadingDocument`)})]}):_?t(`div`,{className:`p-4 rounded-md bg-destructive/10 text-destructive text-sm`,children:_}):p?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none`,children:t(Nt,{artifactRunId:u,children:p})}):n(`div`,{className:`flex flex-col items-center justify-center py-12 text-muted`,children:[t(Kg,{className:`size-8 mb-2`}),t(`span`,{className:`text-sm`,children:f(`agent.noContentAvailable`)})]})})]})}const gX=ot.memo(hX);Q();function _X({plan:e,workstreamStatus:r,isOpen:i,onClose:a,plans:s=[],activePlanIndex:c=0,onChangePlan:l=()=>{}}){let{t:u}=K();if(!i)return null;let d=e.plan||[],f=d.length,m=d.reduce((e,t)=>t?.id&&(r.get(t.id.toString())===`completed`||t.status===`completed`)?e+1:e,0),h=f>0?Math.round(m/f*100):0,g=s.length>0?s.length-c:1,_=s[c]?.timestamp;return d.length===0?t(`div`,{className:`h-full overflow-hidden`,children:n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[t(tg,{className:`mb-2 size-8`}),t(`span`,{className:`text-sm`,children:u(`agent.noPlanAvailable`)})]})}):t(`div`,{className:`h-full overflow-hidden`,children:n(`div`,{className:`flex h-full flex-col gap-4 overflow-y-auto px-2 py-3`,children:[n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex items-start justify-between gap-3`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-medium text-foreground`,children:u(`agent.taskProgress`)}),t(`div`,{className:`text-xs text-muted`,children:u(`agent.tasksCompleted`,{completed:m,total:f})})]}),s.length>1&&n(`div`,{className:`flex shrink-0 items-center gap-1 text-xs text-muted`,children:[t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.min(s.length-1,c+1)),disabled:c>=s.length-1,"aria-label":u(`agent.olderPlan`),title:u(`agent.olderPlan`),children:t(sh,{className:`size-4`,"aria-hidden":`true`})}),n(`div`,{className:`min-w-20 text-center`,children:[n(`div`,{className:`font-medium text-foreground`,children:[g,`/`,s.length]}),t(`div`,{className:`truncate`,children:_?new Date(_).toLocaleTimeString():u(`agent.unknownTime`)})]}),t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.max(0,c-1)),disabled:c<=0,"aria-label":u(`agent.newerPlan`),title:u(`agent.newerPlan`),children:t(uh,{className:`size-4`,"aria-hidden":`true`})})]})]}),t(`div`,{className:`h-2 overflow-hidden rounded-full bg-mixer-muted/20`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":f,"aria-valuenow":m,"aria-label":u(`agent.taskProgress`),children:t(`div`,{className:`h-full rounded-full bg-success transition-all duration-300`,style:{width:`${h}%`}})})]}),t(`ol`,{className:`divide-y divide-border/60`,children:d.map((e,i)=>{let a=e.id?e.id.toString():`task-${i}`,o=e.goal||`Task ${i+1}`,s=e.id?`task-${e.id.toString()}`:`task-${o}-${e.status||`pending`}`,c=e.status||`pending`,l=r.get(a);l!==void 0&&(c=l);let d=Yh,f=`text-muted`;c===`in_progress`?(d=ig,f=`text-info`):c===`completed`&&(d=Ph,f=`text-success`);let p=u(c===`completed`?`agent.completed`:c===`in_progress`?`agent.inProgress`:`agent.pending`);return n(`li`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 px-1 py-3`,children:[t(`span`,{className:`mt-0.5 min-w-5 text-center text-xs font-medium tabular-nums text-muted/80`,children:a}),t(`span`,{className:`min-w-0 text-sm leading-5 text-foreground/85`,children:o}),n(`span`,{className:z(`flex items-center gap-1.5 text-xs font-medium`,f),children:[t(d,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t(`span`,{children:p})]})]},s)})}),(()=>{let e=new Set(d.filter(e=>e?.id).map(e=>e.id.toString())),i=Array.from(r.entries()).filter(([t])=>t!==`main`&&!e.has(t));return i.length>0?n(`div`,{className:`mt-1 px-1 py-2`,children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:u(`agent.workstreams`)}),t(`div`,{className:`divide-y divide-border/60`,children:i.map(([e,r])=>{let i=Yh,a=`text-muted`,o=u(`agent.pending`);return r===`in_progress`?(i=ig,a=`text-info`,o=u(`agent.inProgress`)):r===`completed`&&(i=Ph,a=`text-success`,o=u(`agent.completed`)),n(`div`,{className:`flex items-center gap-2 py-2`,children:[t(i,{className:z(`size-3.5 shrink-0`,a)}),t(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-foreground/80`,children:e}),t(`span`,{className:`text-xs font-medium text-muted`,children:o})]},e)})})]}):null})()]})})}const vX=ot.memo(_X);Q();function yX({icon:e,children:r}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r})]})}function bX({files:e}){let{t:r}=K(),a=U(()=>e?Array.from(e.values()):[],[e]),o=e=>{switch(e){case mn.UPLOADING:case mn.PROCESSING:return t(tv,{className:`size-4 animate-spin text-info`});case mn.READY:return t(Ph,{className:`size-4 text-success`});case mn.ERROR:return t(Kh,{className:`size-4 text-destructive`});default:return t(Kg,{className:`size-4 text-muted`})}},s=e=>{switch(e){case mn.UPLOADING:return t(i,{variant:`info`,children:r(`agent.uploading`)});case mn.PROCESSING:return t(i,{variant:`info`,children:r(`agent.processing`)});case mn.READY:return t(i,{variant:`success`,children:r(`agent.ready`)});case mn.ERROR:return t(i,{variant:`destructive`,children:r(`agent.error`)});default:return null}};return t(`div`,{className:`h-full min-h-0`,children:a.length===0?t(yX,{icon:t(Kg,{className:`mb-2 size-8`}),children:r(`agent.noFilesUploadedYet`)}):t(`div`,{className:`space-y-2 p-2`,children:a.map(e=>n(`div`,{className:`flex items-start gap-2 p-2 border border-muted rounded-md`,children:[t(`div`,{className:`mt-0.5`,children:o(e.status)}),n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-sm font-medium truncate`,children:e.name}),s(e.status)]}),e.error&&t(`div`,{className:`text-xs text-destructive mt-1`,children:e.error})]})]},e.id))})})}var xX=class extends ot.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,message:e instanceof Error?e.message:String(e)}}componentDidCatch(e,t){console.error(`Agent right panel section failed to render`,{error:e,componentStack:t.componentStack})}render(){return this.state.hasError?n(`div`,{className:z(`rounded-md border border-destructive bg-mixer-destructive/10 text-destructive`,this.props.compact?`p-2 text-xs`:`m-3 p-3 text-sm`),children:[t(`div`,{className:`font-medium`,children:this.props.title}),t(`div`,{className:`mt-1 text-xs text-muted`,children:this.props.description}),this.state.message&&t(`div`,{className:`mt-1 break-all text-[11px] text-muted`,children:this.state.message})]}):this.props.children}};function SX({workstreams:e,messages:r,runId:a}){let{t:s}=K(),{client:c}=q(),l=nt(),u=U(()=>uX(r),[r]),d=s(`agent.panelRenderErrorDescription`),f=V(e=>{navigator.clipboard.writeText(e),l({status:`success`,title:s(`agent.runIdCopied`),duration:2e3})},[s,l]),p=V(async e=>{try{let t=await rU(c,e);t&&window.open(t,`_blank`)}catch{l({status:`error`,title:s(`agent.failedToDownload`)})}},[c,s,l]);return e.length===0?t(yX,{icon:t(B_,{className:`mb-2 size-8`}),children:s(`agent.noActiveParallelTasks`)}):n(`div`,{className:`h-full min-h-0 overflow-y-auto px-2 py-2`,children:[t(`div`,{className:`px-1 pb-2 text-xs text-muted`,children:s(`agent.parallelWorkDescription`)}),t(`div`,{className:`divide-y divide-border/60`,children:e.map(e=>{let r=e.status===`running`||e.status===`canceling`,c=Math.round(e.elapsed_ms/1e3),l=Math.max(0,Math.round(e.remaining_ms/1e3)),m=e.deadline_ms>0?Math.min(100,Math.round(e.elapsed_ms/e.deadline_ms*100)):0,h=u.get(e.workstream_id),g=e.deadline_ms>0,_=e.child_workflow_run_id,v=[e.phase?MH(e.phase):void 0,c>0?s(`agent.elapsed`,{seconds:c}):void 0,g&&l>0?s(`agent.remaining`,{seconds:l}):void 0].filter(Boolean),y=(()=>{switch(e.status){case`running`:return t(i,{variant:`info`,children:s(`agent.running`)});case`canceling`:return t(i,{variant:`attention`,children:s(`agent.canceling`)});case`completed`:return t(i,{variant:`done`,children:s(`agent.completed`)});case`failed`:return t(i,{variant:`destructive`,children:s(`agent.failed`)});case`timeout`:return t(i,{variant:`destructive`,children:s(`agent.timeout`)});case`canceled`:return t(i,{variant:`destructive`,children:s(`agent.canceled`)})}})();return t(xX,{title:s(`agent.workstreamRenderError`),description:d,compact:!0,children:t(`div`,{className:`py-3`,children:n(`div`,{className:`flex items-start gap-2`,children:[t(`span`,{className:z(`mt-2 size-2 shrink-0 rounded-full`,BH(e.status)),"aria-hidden":`true`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[t(`span`,{className:`min-w-0 truncate text-sm font-medium text-foreground`,title:e.workstream_id,children:MH(e.workstream_id)}),y]}),v.length>0&&t(`div`,{className:`mt-0.5 truncate text-xs text-muted`,children:v.join(` · `)}),r&&g&&t(`div`,{className:`mt-2 h-1 rounded-full bg-muted`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":m,"aria-valuetext":s(`agent.workstreamProgress`,{percent:m}),children:t(`div`,{className:`h-full rounded-full bg-info transition-all duration-500`,style:{width:`${m}%`}})}),h&&t(xX,{title:s(`agent.browserWidgetRenderError`),description:d,compact:!0,children:t(pX,{state:h,runId:a,compact:!0,className:`mt-2`})}),_&&n(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>f(_),children:[t(Qh,{className:`size-3 me-1`}),s(`agent.copyRunId`)]}),n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>p(_),children:[t(sg,{className:`size-3 me-1`}),s(`agent.download`)]})]})]})]})})},e.launch_id)})})]})}function CX({plan:e,workstreamStatus:r,plans:i=[],activePlanIndex:a=0,onChangePlan:s,activeWorkstreams:c=[],messages:l=[],hideWorkstreams:u=!1,openDocuments:d=[],activeDocumentId:f,onSelectDocument:p,onCloseDocument:m,onUpdateDocumentTitle:h,docRefreshKey:g=0,runId:_,processingFiles:v,showArtifacts:y=!1,artifactRefreshKey:b=0,artifactRefreshDetails:x,selectedArtifactPath:S,onSelectedArtifactPathChange:C,onSendMessage:w,payloadContent:T,conversationContent:E,onClose:D,defaultTab:O,activeTab:k,onTabChange:A}){let{t:j}=K(),[M,N]=G(O||`plan`),P=k??M,F=e=>{N(e),A?.(e)},I=!u&&c.length>0,L=d.length>0,ee=v?v.size>0:!1,R=V((e,n)=>t(xX,{title:j(`agent.panelRenderError`,{name:e}),description:j(`agent.panelRenderErrorDescription`),children:n}),[j]),te={name:`conversation`,label:`Conversation`,content:E?R(`Conversation`,t(`div`,{className:`flex flex-col h-full min-h-0`,children:E})):null,is_allowed:!!E},ne=[...E?[te]:[],{name:`plan`,label:j(`agent.plan`),content:R(j(`agent.plan`),e?t(vX,{plan:e,workstreamStatus:r||new Map,isOpen:!0,onClose:D,plans:i,activePlanIndex:a,onChangePlan:s}):t(yX,{icon:t(B_,{className:`mb-2 size-8`}),children:j(`agent.noPlanAvailable`)})),is_allowed:!0},{name:`workstreams`,label:I?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.workstreams`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:c.length})]}):j(`agent.workstreams`),content:R(j(`agent.workstreams`),t(SX,{workstreams:c,messages:l,runId:_})),is_allowed:!u},{name:`documents`,label:L?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.documents`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:d.length})]}):j(`agent.documents`),content:R(j(`agent.documents`),d.length>0&&p&&m?t(gX,{isOpen:!0,documents:d,activeDocumentId:f??null,onSelectDocument:p,onCloseDocument:m,onUpdateDocumentTitle:h,refreshKey:g,runId:_}):t(yX,{icon:t(Kg,{className:`mb-2 size-8`}),children:j(`agent.noDocumentsOpen`)})),is_allowed:!0},{name:`uploads`,label:ee?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[j(`agent.uploads`),` `,t(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-info`})]}):j(`agent.uploads`),content:R(j(`agent.uploads`),t(bX,{files:v})),is_allowed:!0},{name:`artifacts`,label:j(`agent.artifacts`),content:R(j(`agent.artifacts`),t(sX,{runId:_,refreshKey:b,refreshDetails:x,selectedPath:S,onSelectedPathChange:C,onSendMessage:w})),is_allowed:y},{name:`payload`,label:j(`agent.payload`),content:T?R(j(`agent.payload`),t(`div`,{className:`overflow-y-auto`,children:T})):null,is_allowed:!!T}],re=ne.filter(e=>e.is_allowed===void 0||e.is_allowed===!0);return n(ze,{tabs:ne,current:P,onTabChange:F,fullHeight:!0,className:`px-0`,children:[n(`div`,{className:`flex items-end justify-between shrink-0 px-1 py-1 gap-1`,children:[t(pe,{tabs:re,current:P,onTabChange:F,className:`min-w-0 flex-1`}),!E&&t(o,{variant:`ghost`,size:`sm`,className:`shrink-0 ms-1`,onClick:D,title:`Close Right Panel`,children:t(Kb,{className:`size-4`})})]}),t(Ve,{className:`flex-1 min-h-0 pt-0 pb-0`})]})}const wX=ot.memo(CX);function TX(e){if(!e)return[];let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.kind!==`file`)continue;let i=r.getAsFile();if(i){if(r.type.startsWith(`image/`)&&(!i.name||i.name===`image.png`)){let e=r.type.split(`/`)[1]||`png`;t.push(new File([i],`pasted-image-${Date.now()}.${e}`,{type:i.type}))}else t.push(i)}}return t}function EX(e,t,n=!1){let[r,i]=G([]),[a,o]=G(0),[s,c]=G(new Map),[l,u]=G(t),[d,f]=G(!n),p=W(-1),m=W(new Set);H(()=>{e.length===0&&(i([]),o(0),c(new Map),f(!n),p.current=-1,m.current.clear())},[e.length,n]);let h=V(e=>{let n=e[e.length-1];n&&(n.type===J.TERMINATED?u(!1):u(t?!0:n.type===J.REQUEST_INPUT))},[t]);return H(()=>{if(e.length===0)return;let t=p.current+1;if(t>=e.length){h(e);return}let n=!1,r=[],a=[];for(let i=t;i<e.length;i++){let t=e[i];if(t.type===J.PLAN)try{let e=null;if(t.details&&typeof t.details==`object`&&t.details.plan&&Array.isArray(t.details.plan)&&(e={plan:t.details.plan}),e){let i=typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime();if(!m.current.has(i)){m.current.add(i),n=!0,r.push({plan:e,timestamp:i});let t=new Map;t.set(`main`,`in_progress`),Array.isArray(e.plan)&&e.plan.forEach(e=>{if(e&&typeof e==`object`&&e.id){let n=e.id.toString();t.set(n,e.status||`pending`)}}),a.push({timestamp:i,statusMap:t})}}}catch(e){console.error(`Failed to parse plan from message:`,e)}}p.current=e.length-1,n&&r.length>0&&(i(e=>[...[...r].reverse(),...e]),o(0),f(!0),a.length>0&&c(e=>{let t=new Map(e);for(let e of a)t.set(e.timestamp,e.statusMap);return t})),h(e)},[e,h]),H(()=>{if(r.length===1&&!d&&!sessionStorage.getItem(`plan-panel-shown`)){let e=setTimeout(()=>{f(!0),sessionStorage.setItem(`plan-panel-shown`,`true`)},500);return()=>clearTimeout(e)}},[r.length,d]),{plans:r,activePlanIndex:a,setActivePlanIndex:o,workstreamStatusMap:s,showInput:l,showSlidingPanel:d,setShowSlidingPanel:f}}function DX(e,t){return{...e,details:{...e.details??{},_deliveryStatus:t}}}function OX(e){let t=e.details,n=t?._messageId;if(typeof n==`string`&&n)return n;let r=t?.ack;return typeof r==`string`&&r?r:void 0}function kX(e,t){let n=e?.[t];return typeof n==`string`&&n?n:void 0}function AX(e){return e?.streaming_id_scope===`workflow_run`}function jX(e){return[J.COMPLETE,J.IDLE,J.TERMINATED,J.REQUEST_INPUT].includes(e.type)}function MX(e){if(e.type===J.STREAMING_CHUNK)return!1;if(e.type===J.UPDATE&&typeof e.details?.event_class==`string`)return!0;if(e.type===J.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files)return!1}return!!e.message||jX(e)||On(e).length>0}function NX(e){if(e)return{type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,text:typeof e.message==`string`?e.message.slice(0,80):e.message?`[non-string]`:``,display_role:e.details?.display_role,source:e.details?.source}}function PX(e,t){if(e.find(e=>e.timestamp===t.timestamp))return e;if(!t.details?._optimistic&&(t.type===J.QUESTION||ZH(t))){let n=typeof t.details?.ack==`string`?t.details.ack:void 0,r=n?DX(t,`consumed`):t;if(n){let i=e.filter(e=>!((e.type===t.type||ZH(e))&&e.details?._optimistic&&OX(e)===n));return qH(i,r),i}if(t.type===J.QUESTION){let n=e.filter(e=>e.type===J.QUESTION&&e.details?._optimistic&&e.message===t.message&&(e.workstream_id??`main`)===(t.workstream_id??`main`));if(n.length===1){let r=e.filter(e=>e!==n[0]);return qH(r,t),r}}}let n=[...e];return qH(n,t),n}function FX(e){let t=e.details,n=kX(t,`streaming_id`),r=kX(t,`activity_id`);return n&&AX(t)?n:r??n}function IX(e){let t=e.details,n=kX(t,`streaming_id`),r=kX(t,`activity_id`),i=[];return n&&AX(t)&&i.push(n),r&&i.push(r),[...new Set(i)]}function LX(e,t,n){let[r,i]=G([]),[a,o]=G(!1),[s,c]=G(`loading`),[l,u]=G(null),[d,f]=G(null),p=W(n);p.current=n;let[m,h]=G(new Map),[g,_]=G(0),v=V(()=>_(e=>e+1),[]),y=W(null),b=W(0),[x,S]=G(new Map),C=W(new Map),w=W(null),[T,E]=G(!1),D=W(null),O=V(()=>{let e=w.current;e&&(e.mode===`raf`?cancelAnimationFrame(e.id):clearTimeout(e.id),w.current=null)},[]),k=V(()=>{C.current.size>0&&(S(new Map(C.current)),E(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>E(!1),50)),w.current=null},[]);return H(()=>{o(!XH(r))},[r]),H(()=>{KH(`stream state`,{agentRunId:t,messageCount:r.length,streamingCount:x.size,initialHistoryStatus:s,isCompleted:a,lastDeliveredTs:b.current,first:NX(r[0]),last:NX(r[r.length-1])})},[t,s,a,r,x.size]),H(()=>{let n=y.current!==t;y.current=t,n&&(i([]),c(`loading`),u(null),f(null),S(new Map),h(new Map),b.current=0);let r=new AbortController,a=n?void 0:b.current||void 0;return KH(`stream start`,{agentRunId:t,isNewConversation:n,since:a,streamNonce:g}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(KH(`internals loaded`,{agentRunId:t,status:e.status,first_workflow_run_id:e.first_workflow_run_id}),u(e.status?.toUpperCase()??null),f(e.first_workflow_run_id??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to check agent run status:`,e)}),e.agents.streamMessages(t,e=>{if(r.signal.aborted)return;let n=!!(e.timestamp&&e.timestamp<=b.current);if(n||p.current?.(e),KH(`stream message`,{agentRunId:t,type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,hasMessage:!!e.message,display_role:e.details?.display_role,source:e.details?.source}),e.timestamp&&e.timestamp>b.current&&(b.current=e.timestamp),e.type===J.STREAMING_CHUNK){let t=e.details,n=FX(e);if(!n)return;let r=C.current.get(n)||{text:``,workstreamId:e.workstream_id,startTimestamp:Date.now(),activityId:t?.activity_id,streamingId:t?.streaming_id},i=r.text+(e.message||``);C.current.set(n,{text:i,workstreamId:e.workstream_id,isComplete:t.is_final,startTimestamp:r.startTimestamp,activityId:t?.activity_id,streamingId:t?.streaming_id}),w.current===null&&(document.hidden?w.current={mode:`timeout`,id:window.setTimeout(k,16)}:w.current={mode:`raf`,id:requestAnimationFrame(k)});return}if(e.type===J.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files){n||h(new Map(t.files.map(e=>[e.id,e])));return}}if(e.type===J.THOUGHT||e.type===J.ANSWER){let t=IX(e);if(t.length>0){for(let e of t)C.current.delete(e);S(e=>{let n=new Map(e),r=!1;for(let e of t)r=n.delete(e)||r;return r?n:e})}}(e.type===J.COMPLETE||e.type===J.IDLE)&&C.current.size>0&&k(),MX(e)&&i(t=>PX(t,e))},a,r.signal,{closeOnIdle:!1,onHistoryLoaded:e=>{if(r.signal.aborted)return;let n=e.filter(MX),o,s=-1/0;for(let t of e)if(t.timestamp&&t.timestamp>b.current&&(b.current=t.timestamp),t.type===J.SYSTEM){let e=t.details;if(e?.system_type===`file_processing`&&e.files){let n=t.timestamp??-1/0;(!o||n>=s)&&(o=e,s=n)}}o&&h(new Map(o.files.map(e=>[e.id,e]))),KH(`history loaded`,{agentRunId:t,count:e.length,timelineCount:n.length,since:a,first:NX(e[0]),last:NX(e[e.length-1])}),c(e.length>0?`has_messages`:`empty`),n.length>0&&i(e=>n.reduce((e,t)=>PX(e,t),e))},onHistoryError:e=>{r.signal.aborted||(KH(`history error`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),c(`error`))}}).then(()=>{if(!r.signal.aborted)return KH(`stream resolved`,{agentRunId:t}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(KH(`internals refreshed after stream end`,{agentRunId:t,status:e.status}),u(e.status?.toUpperCase()??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to refresh agent run status on stream end:`,e)})}).catch(e=>{r.signal.aborted||(KH(`stream failed`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),console.error(`Failed to stream agent messages:`,e))}),()=>{KH(`stream cleanup`,{agentRunId:t,streamNonce:g}),r.abort(),O(),C.current.clear(),D.current&&=(clearTimeout(D.current),null)}},[t,g,e.agents,k,O]),H(()=>{let e=()=>{!document.hidden&&C.current.size>0&&(O(),k())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[k,O]),{messages:r,streamingMessages:x,isCompleted:a,initialHistoryStatus:s,debugChunkFlash:T,addOptimisticMessage:V(e=>{i(t=>{let n=[...t,e];return n.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),n})},[]),updateOptimisticMessageStatus:V((e,t)=>{i(n=>n.map(n=>n.details?._optimistic&&OX(n)===e?DX(n,t):n))},[]),removeOptimisticMessages:V(e=>{i(t=>t.filter(t=>!e(t)))},[]),reconnect:v,agentRunStatus:l,workflowRunId:d,serverFileUpdates:m}}function RX(e){if(typeof e==`string`&&e.trim().length>0)return e}function zX(e,t){let n=RX(e.revision_root_id)||RX(e.revision_root)||RX(e.root_document_id)||RX(e.root_id);if(n)return n;let r=e.revision_info;if(r&&typeof r==`object`){let e=RX(r.root);if(e)return e}return t}function BX(e,t){return e.revisionRootId&&t.revisionRootId?e.revisionRootId===t.revisionRootId:t.revisionRootId?e.id===t.revisionRootId:e.revisionRootId?e.revisionRootId===t.id:e.id===t.id}function VX(e){let[t,n]=G([]),[r,i]=G(null),[a,o]=G(!1),[s,c]=G(0),l=W(-1);return H(()=>{e.length===0&&(n([]),i(null),o(!1),c(0),l.current=-1)},[e.length]),H(()=>{let t=l.current+1;if(!(t>=e.length)){for(let r=t;r<e.length;r++){let t=e[r];if(t.type===J.UPDATE&&t.details){let e=t.details;if(e.event_class===`document_created`||e.event_class===`document_updated`){let t=RX(e.document_id),r=RX(e.updated_document_id)||t,a=e.title;if(r){let s=zX(e,t||r),l={id:r,title:a||`Document`,revisionRootId:s};n(e=>{let t=e.findIndex(e=>BX(e,l));if(t<0)return[...e,l];let n=e[t];if(n.id===l.id&&n.title===l.title&&n.revisionRootId===l.revisionRootId)return e;let r=[...e];return r[t]=l,r}),i(l.id),o(!0),e.event_class===`document_updated`&&c(e=>e+1)}}}}l.current=e.length-1}},[e]),{openDocuments:t,activeDocumentId:r,isDocPanelOpen:a,docRefreshKey:s,closeDocPanel:V(()=>{o(!1)},[]),closeDocument:V(e=>{n(t=>{let n=t.filter(t=>t.id!==e);return n.length===0?(o(!1),i(null)):i(t=>t===e?n[0].id:t),n})},[]),selectDocument:V(e=>{i(e)},[]),openDocInPanel:V(e=>{n(t=>t.some(t=>t.id===e)?t:[...t,{id:e,title:`Document`,revisionRootId:e}]),i(e),o(!0)},[]),updateDocumentTitle:V((e,t)=>{n(n=>n.map(n=>n.id===e?{...n,title:t}:n))},[])}}function HX(e){return e.type.startsWith(`image/`)}function UX(e){if(!(!HX(e)||typeof URL>`u`||!URL.createObjectURL))return URL.createObjectURL(e)}function WX(e){typeof URL<`u`&&URL.revokeObjectURL&&URL.revokeObjectURL(e)}function GX(e,t,n,r,i){let a=Xt.getFixedT(null,Yt),[o,s]=G(new Map),[c,l]=G(new Set),u=W(new Set),d=W(new Map),f=W(t),p=W(o);p.current=o;let m=W(n);m.current=n;let h=V(e=>{let t=d.current.get(e);t&&(WX(t),d.current.delete(e))},[]);H(()=>{if(f.current!==t){f.current=t,d.current.forEach(WX),d.current.clear(),s(new Map);let e=new Set;u.current=e,l(e)}},[t]),H(()=>()=>{d.current.forEach(WX),d.current.clear()},[]);let g=U(()=>{let e=new Map;if(o.forEach((t,n)=>{c.has(n)||e.set(n,t)}),n.forEach((t,n)=>{if(t.consumed_at){e.delete(n);return}if(!c.has(n)){let r=o.get(n);e.set(n,{...t,artifact_path:t.artifact_path??r?.artifact_path,reference:t.reference??r?.reference,...r?.preview_url?{preview_url:r.preview_url}:{}})}}),i&&i.size>0)for(let[t,n]of e)(n.reference&&i.has(n.reference)||n.artifact_path&&i.has(n.artifact_path))&&e.delete(t);return e},[o,c,n,i]);return{processingFiles:g,hasProcessingFiles:U(()=>Array.from(g.values()).some(e=>e.status===mn.UPLOADING||e.status===mn.PROCESSING),[g]),handleFileUpload:V(async n=>{for(let i of n){let n=`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,o=`files/${i.name}`,c=UX(i);c&&d.current.set(n,c);let l={id:n,name:i.name,content_type:i.type||`application/octet-stream`,size:i.size,status:mn.UPLOADING,started_at:Date.now(),preview_url:c};s(e=>new Map(e).set(n,l));try{if(await e.agents.uploadArtifact(t,o,i),s(e=>{let t=new Map(e),r=t.get(n);return r&&(r.status=mn.PROCESSING,r.artifact_path=o,r.reference=`artifact:${o}`),t}),u.current.has(n))continue;await e.agents.sendSignal(t,`FileUploaded`,{id:n,name:i.name,content_type:i.type||`application/octet-stream`,reference:`artifact:${o}`,artifact_path:o})}catch(e){if(u.current.has(n))continue;s(t=>{let r=new Map(t),i=r.get(n);return i&&(i.status=mn.ERROR,i.error=e instanceof Error?e.message:`Upload failed`,i.completed_at=Date.now()),r}),r({status:`error`,title:a(`agent.uploadFailed`),description:e instanceof Error?e.message:`Failed to upload file`,duration:3e3})}}},[e,t,r,a]),removeProcessingFile:V(async n=>{l(e=>{if(e.has(n))return e;let t=new Set(e);return t.add(n),u.current=t,t}),s(e=>{if(!e.has(n))return e;let t=new Map(e);return t.delete(n),t}),h(n);try{await e.agents.sendSignal(t,`FileRemoved`,{id:n})}catch(e){r({status:`error`,title:a(`agent.removeFileFailed`),description:e instanceof Error?e.message:`Failed to remove file`,duration:3e3})}},[t,e,h,a,r]),clearProcessingFiles:V(()=>{d.current.forEach(WX),d.current.clear(),l(e=>{let t=new Set(e);for(let e of m.current.keys())t.add(e);for(let e of p.current.keys())t.add(e);return u.current=t,t}),s(new Map)},[])}}Q();function KX({activeWorkstreams:r,onSelectWorkstream:i,className:a}){let{t:s}=K(),[c,l]=G(!1),[u,d]=G(!1),f=vt(),p=U(()=>r.filter(e=>e.status===`running`||e.status===`canceling`),[r]),m=c?p:p.slice(0,3),h=Math.max(0,p.length-m.length),g=p.length>3;return H(()=>{g||l(!1)},[g]),p.length===0?null:t(`div`,{className:z(`mx-auto mb-2 w-full max-w-3xl px-1`,a),"data-agent-active-workstreams":!0,children:n(`output`,{className:`flex flex-col gap-1.5 rounded-2xl border border-border/70 bg-background/95 p-2 text-xs text-muted shadow-lg shadow-black/5`,"aria-live":`polite`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2 px-1 font-medium`,children:[t(jm,{className:`size-3.5 shrink-0 text-muted`,"aria-hidden":`true`}),t(`span`,{className:`truncate`,children:s(`agent.activeWorkstreams`,{count:p.length})})]}),n(o,{variant:`ghost`,size:`icon`,onClick:()=>d(!u),title:s(u?`agent.showActiveWorkstreams`:`agent.hideActiveWorkstreams`),children:[t(u?ph:ih,{className:`size-4`}),s(u?`agent.showActiveWorkstreams`:`agent.hideActiveWorkstreams`)]})]}),u?null:n(e,{children:[t(`div`,{id:f,className:`flex flex-col gap-0.5`,children:m.map(r=>{let a=PH(r.workstream_id,r.interaction),s=n(e,{children:[t(`span`,{className:z(`size-1.5 shrink-0 rounded-full`,BH(r.status)),"aria-hidden":`true`}),t(`span`,{className:`truncate font-medium`,children:a}),r.phase&&t(`span`,{className:`truncate text-xs text-muted/75`,children:MH(r.phase)})]});return i?n(o,{type:`button`,variant:`ghost`,className:`h-auto min-w-0 justify-start gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,onClick:()=>{l(!1),i(r.workstream_id)},children:[s,t(uh,{className:`ms-auto size-3.5 shrink-0 rtl:rotate-180`,"aria-hidden":`true`})]},r.launch_id||r.workstream_id):t(`div`,{className:`flex min-w-0 items-center gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,children:s},r.launch_id||r.workstream_id)})}),g&&n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-fit shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,"aria-expanded":c,"aria-controls":f,onClick:()=>l(e=>!e),children:[!c&&n(`span`,{children:[`+`,h]}),s(c?`agent.showLess`:`agent.showMore`),t(ih,{className:z(`size-3.5 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})]})]})})}const qX=new tr({strict:!1,validateFormats:!1});function JX(e){if(e!==Tn.virtual_lb&&e!==Tn.virtual_mediator&&e!==Tn.test)return e}var YX=class{_listeners=new Set;snapshot;constructor(e){this.snapshot=new XX(e,this)}subscribe=e=>(this._listeners.add(e),()=>{this._listeners.delete(e)});getSnapshot=()=>this.snapshot;notify(){this._listeners.forEach(e=>{e()})}},XX=class e{vertesia;_interactive=!0;_debug_mode=!1;_non_blocking_subagents=!0;_checkpoint_tokens;_visibility;_user_channels;_collection;_disabled_mcp_collections;_start=!1;_preserveRunValues=!1;_interaction;_environment;_model=``;_model_options;_tool_names=[];_data;_mode=`start`;_scheduledWorkflowConfig;_interactionParamsSchema;_schemaVersion=0;_inputValidator;_store;constructor(e,t){this.vertesia=e,this._store=t}onStateChanged(){let e=this.clone();this._store.snapshot=e,this._store.notify()}clone(){let t=new e(this.vertesia,this._store);return t._interactionParamsSchema=this._interactionParamsSchema,t._schemaVersion=this._schemaVersion,t._interaction=this._interaction,t._data=this._data,t._environment=this._environment,t._model=this._model,t._model_options=this._model_options?{...this._model_options}:void 0,t._tool_names=[...this._tool_names],t._interactive=this._interactive,t._debug_mode=this._debug_mode,t._non_blocking_subagents=this._non_blocking_subagents,t._checkpoint_tokens=this._checkpoint_tokens,t._visibility=this._visibility,t._user_channels=this._user_channels?[...this._user_channels]:void 0,t._inputValidator=this._inputValidator,t._start=this._start,t._collection=this._collection,t._disabled_mcp_collections=this._disabled_mcp_collections?[...this._disabled_mcp_collections]:void 0,t._preserveRunValues=this._preserveRunValues,t._mode=this._mode,t._scheduledWorkflowConfig=this._scheduledWorkflowConfig,t}set mode(e){e!==this._mode&&(this._mode=e,e===`schedule`&&!this._scheduledWorkflowConfig&&(this._scheduledWorkflowConfig={name:``,description:``,cron_expression:`0 9 * * *`,timezone:`UTC`}),this.onStateChanged())}get mode(){return this._mode}set scheduledWorkflowConfig(e){this._scheduledWorkflowConfig=e,this.onStateChanged()}get scheduledWorkflowConfig(){return this._scheduledWorkflowConfig}updateScheduledWorkflowConfig(e){this._scheduledWorkflowConfig={...this._scheduledWorkflowConfig,...e},this.onStateChanged()}get interactive(){return this._interactive}set interactive(e){e!==this._interactive&&(this._interactive=e,this.onStateChanged())}get debug_mode(){return this._debug_mode}set debug_mode(e){e!==this._debug_mode&&(this._debug_mode=e,this.onStateChanged())}get non_blocking_subagents(){return this._non_blocking_subagents}set non_blocking_subagents(e){e!==this._non_blocking_subagents&&(this._non_blocking_subagents=e,this.onStateChanged())}get checkpoint_tokens(){return this._checkpoint_tokens}set checkpoint_tokens(e){e!==this._checkpoint_tokens&&(this._checkpoint_tokens=e,this.onStateChanged())}get visibility(){return this._visibility}set visibility(e){e!==this._visibility&&(this._visibility=e,this.onStateChanged())}get user_channels(){return this._user_channels}set user_channels(e){this._user_channels=e,this.onStateChanged()}get collection(){return this._collection}set collection(e){e!==this._collection&&(this._collection=e,this.onStateChanged())}get disabled_mcp_collections(){return this._disabled_mcp_collections}set disabled_mcp_collections(e){this._disabled_mcp_collections=e&&e.length>0?e:void 0,this.onStateChanged()}get search_scope(){return this._collection?un.Collection:void 0}async restoreConversation(e){let t=e.interaction;e.version&&(/^[a-fA-F0-9]{24}$/.test(t)||(t=`${t}@${e.version}`));let n=await this.vertesia.interactions.catalog.resolve(t),r=n.runtime?.environment||e.config?.environment,i=e.config?.model,a=await(r?this.vertesia.environments.retrieve(r).catch(()=>void 0):Promise.resolve(void 0));this._data=e.data,this.interaction=n,e.interactionParamsSchema!=null&&(this.interactionParamsSchema=e.interactionParamsSchema),this._tool_names=e.tool_names||[],this._interactive=e.interactive,this._debug_mode=e.debug_mode??!1,this._non_blocking_subagents=e.non_blocking_subagents??!0,this._checkpoint_tokens=e.checkpoint_tokens,this._user_channels=e.user_channels,this._disabled_mcp_collections=e.disabled_mcp_collections,this._model_options=e.config?.model_options,this.collection=e.collection_id??void 0,this._model_options=e.config?.model_options,this.environment=a,i&&(this._model=i),this.onStateChanged()}get interaction(){return this._interaction}set interaction(e){if(e?.id!==this._interaction?.id){if(this._interaction=e,this.interactionParamsSchema=e?kn(e.prompts):void 0,this._inputValidator=void 0,e&&!this._preserveRunValues&&(this._model_options=e.model_options,e.runtime?.environment)){let t=e.runtime.environment;this.vertesia.environments.retrieve(t).then(e=>this.environment=e)}this.onStateChanged()}}get environment(){return this._environment}set environment(e){if(e?.id!==this._environment?.id){if(this._environment=e,!this._preserveRunValues){let t=e?JX(e.provider):void 0,n=this.interaction?.runtime?.model;this._model=n&&t&&Mn(n,t)?n:e?.default_model&&t&&Mn(e.default_model,t)?e.default_model:``}this.onStateChanged()}}get model(){return this._model}set model(e){e!==this._model&&(this._model=e||``,this.onStateChanged())}get model_options(){return this._model_options}set model_options(e){JSON.stringify(e)!==JSON.stringify(this._model_options)&&(this._model_options=e,this.onStateChanged())}get tool_names(){return this._tool_names}set tool_names(e){this._tool_names=e,this.onStateChanged()}get data(){return this._data}set data(e){this._data=e,this.onStateChanged()}set run(e){console.log(`run`,e),this.onStateChanged()}set start(e){this._start!==e&&(this._start=e,this.onStateChanged())}markStarted(){this.start=!0}setMode(e){this.mode=e}setInteraction(e){this.interaction=e}setEnvironment(e){this.environment=e}setModel(e){this.model=e}setModelOptions(e){this.model_options=e}setToolNames(e){this.tool_names=e}setCollection(e){this.collection=e}setDisabledMcpCollections(e){this.disabled_mcp_collections=e}setInteractive(e){this.interactive=e}setDebugMode(e){this.debug_mode=e}setUserChannels(e){this.user_channels=e}setCheckpointTokens(e){this.checkpoint_tokens=e}setVisibility(e){this.visibility=e}setData(e){this.data=e}setDraftData(e){this._data=e}setPreserveRunValues(e){this.preserveRunValues=e}get start(){return this._start}get preserveRunValues(){return this._preserveRunValues}set preserveRunValues(e){this._preserveRunValues=e}get schemaVersion(){return this._schemaVersion}get interactionParamsSchema(){return this._interactionParamsSchema}set interactionParamsSchema(e){this._interactionParamsSchema!==e&&(this._interactionParamsSchema=e,this._schemaVersion+=1,e&&(this._data=this.initializeBooleanDefaults(this._data||{},e)),this.onStateChanged())}initializeBooleanDefaults(e,t){if(!t.properties)return e;let n={...e};for(let[e,r]of Object.entries(t.properties)){let t=r;t.type===`boolean`&&n[e]===void 0?n[e]=!1:t.type===`object`&&t.properties&&(n[e]=this.initializeBooleanDefaults(n[e]||{},t))}return n}reset(){if(this._start=!1,this._interactive=!0,this._debug_mode=!1,this._non_blocking_subagents=!0,this._checkpoint_tokens=void 0,this._visibility=void 0,this._user_channels=void 0,this._collection=void 0,this._disabled_mcp_collections=void 0,this._preserveRunValues=!1,this._model=``,this._model_options=void 0,this._environment=void 0,this._tool_names=[],this._interaction=void 0,this._data=void 0,this._interactionParamsSchema=null,this._inputValidator=void 0,this.model=void 0,this.environment=void 0,this.onStateChanged(),location.hash){let e=window.location.origin+window.location.pathname+window.location.search;history.replaceState(null,``,e),location.hash=``}}validateInput(){if(!this._interactionParamsSchema)return{isValid:!0};(!this._inputValidator||this._inputValidator.schema!==this._interactionParamsSchema)&&(this._inputValidator={validate:qX.compile(this._interactionParamsSchema),schema:this._interactionParamsSchema});let e=this._data||{};return this._inputValidator.validate(e)?{isValid:!0}:{isValid:!1,errorMessage:this._inputValidator.validate.errors?this._inputValidator.validate.errors.map(e=>`${e.instancePath}: ${e.message}`).join(`, `):`Invalid payload data`}}};const ZX=dt(void 0);function QX({children:e}){let{client:n}=q(),[r]=G(()=>new YX(n)),i=xt(r.subscribe,r.getSnapshot);return t(ZX.Provider,{value:i,children:e})}function $X(){let e=_t(ZX);if(!e)throw Error(`usePayloadBuilder must be used within a PayloadProvider`);return e}Q();function eZ({title:e,variant:r=`full`,isTerminal:i=!1,onClose:a,isModal:s,agentRunId:c,workflowRunId:l,viewMode:u,onViewModeChange:d,showPlanPanel:f,showPlanButton:p=!0,onTogglePlanPanel:m,showPlaybackButton:h=!1,isPlaybackEnabled:g=!1,onTogglePlayback:_,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C=!0,onClone:w,isReceivingChunks:T=!1,className:E}){let{t:D}=K(),O=r===`compact`,k=u===`sliding`?`stacked`:`sliding`,A=D(`agent.verbose`),j=D(`agent.summary`),M=k===`stacked`?A:j,N=n(`div`,{className:z(O?`flex flex-row items-center gap-1 lg:flex-col`:`flex justify-end items-center gap-2 ms-auto`),children:[p&&t(`div`,{className:`relative`,children:n(o,{size:r===`compact`?`icon`:`sm`,variant:f?`primary`:`ghost`,onClick:m,className:z(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),title:D(`agent.toggleRightSidebar`),children:[t(tg,{className:z(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)}):t(`span`,{className:`sr-only`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)})]})}),O?t(o,{variant:`ghost`,size:`icon`,onClick:()=>d(k),className:`size-8 rounded-lg`,title:M,"aria-label":M,children:t(k===`stacked`?Sy:yv,{className:`size-4`})}):n(`div`,{className:`flex items-center gap-1 bg-muted rounded p-0.5 mt-2 lg:mt-0`,children:[n(o,{variant:u===`stacked`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`stacked`),"aria-pressed":u===`stacked`,className:`gap-1.5`,children:[t(Sy,{className:`size-3.5`}),A]}),n(o,{variant:u===`sliding`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`sliding`),"aria-pressed":u===`sliding`,className:`gap-1.5`,children:[t(yv,{className:`size-3.5`}),j]})]}),h&&_&&n(o,{type:`button`,size:r===`compact`?`icon`:`sm`,variant:g?`primary`:`ghost`,onClick:_,"aria-pressed":g,title:D(`agent.rewind.label`),className:z(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),children:[t(Km,{className:z(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(`agent.rewind.label`)}):t(`span`,{className:`sr-only`,children:D(`agent.rewind.label`)})]}),b&&t(o,{type:`button`,size:r===`compact`?`icon`:`sm`,variant:`ghost`,onClick:b,title:D(`agent.startNewConversation`),className:z(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),children:t(gv,{className:z(`size-4`,r===`full`&&`me-1.5`)})}),t(tZ,{compact:O,agentRunId:c,workflowRunId:l,isModal:s,isTerminal:i,onClose:a,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C,onClone:w}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,"aria-label":D(`agent.close`),children:t(Kb,{className:`size-4`})})]});return r===`compact`?t(QX,{children:t(`div`,{className:z(`inline-flex items-center rounded-xl border border-border/70 bg-background/90 p-1 shadow-lg shadow-black/10 backdrop-blur`,E),children:N})}):t(QX,{children:n(`div`,{className:z(`flex flex-wrap items-center justify-between py-1.5 px-2 border-b shadow-sm flex-shrink-0`,E),children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1`,children:[t(jm,{className:`size-5 text-muted`}),t(`span`,{className:`font-medium`,children:e})]}),n(`span`,{className:`text-xs text-muted ms-1 flex items-center gap-1.5`,children:[`(Agent Run ID: `,c,`)`,t(`span`,{className:z(`w-2 h-2 rounded-full transition-colors duration-200`,T?`bg-purple-500 shadow-[0_0_6px_2px_rgba(168,85,247,0.6)]`:`bg-gray-400`)})]})]}),N]})})}function tZ({compact:e=!1,agentRunId:r,workflowRunId:i,isModal:a,isTerminal:s,onClose:c,onDownload:l,onExportFixture:u,resetWorkflow:d,onExportPdf:f,onShowDetails:p,allowWorkflowControl:m=!0,onClone:h}){let{t:g}=K(),_=nt(),{client:v}=q(),y=$X(),{router:b}=er(),x=async()=>{try{return await v.agents.terminate(r,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3}),y.reset(),d?.(),!0}catch{return _({status:`error`,title:g(`agent.failedToCancelWorkflow`),duration:2e3}),!1}},S=async()=>{try{let e=await v.agents.fork(r);_({status:`success`,title:g(`agent.conversationCloned`),duration:2e3}),h?.(e)}catch{_({status:`error`,title:g(`agent.failedToCloneConversation`),duration:2e3})}},C=e=>{let t=e.startsWith(`/`)?b.getTopRouter().navigator.addStickyParams(e):e;return window.open(t,`_blank`),t};return t(w,{align:`right`,trigger:t(o,{size:e?`icon`:`xs`,variant:`ghost`,title:g(`agent.moreActions`),className:e?`size-8 rounded-lg`:void 0,children:t(Tg,{className:`size-4`})}),children:n(ie,{label:`Actions`,children:[a&&n(ae,{onClick:()=>C(`/store/agent-runner/${r}`),children:[t(Og,{className:`size-3.5 text-muted`}),` `,g(`agent.openInNewTab`)]}),n(ae,{onClick:()=>{navigator.clipboard.writeText(r),_({status:`success`,title:g(`agent.agentRunIdCopied`),duration:2e3})},children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.copyAgentRunId`)]}),n(ae,{onClick:()=>{navigator.clipboard.writeText(i),_({status:`success`,title:g(`agent.workflowRunIdCopied`),duration:2e3})},children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.copyWorkflowRunId`)]}),p&&n(ae,{onClick:p,children:[t(j_,{className:`size-3.5 text-muted`}),` `,g(`agent.details`)]}),n(ae,{onClick:()=>{l?l():rU(v,r).then(e=>window.open(e,`_blank`))},children:[t(sg,{className:`size-3.5 text-muted`}),` `,g(`agent.downloadConversation`)]}),f&&n(ae,{onClick:f,children:[t(sg,{className:`size-3.5 text-muted`}),` `,g(`agent.exportAsPdf`)]}),u&&n(ae,{onClick:u,children:[t(sg,{className:`size-3.5 text-muted`}),` `,g(`agent.rewind.exportFixture`)]}),c&&a&&n(ae,{onClick:c,children:[t(Kb,{className:`size-3.5 text-muted`}),` `,g(`agent.close`)]}),h&&n(ae,{onClick:S,children:[t(y_,{className:`size-3.5 text-muted`}),` `,g(`agent.cloneConversation`)]}),m&&!s&&n(ae,{onClick:x,variant:`destructive`,children:[t(Kb,{className:`size-3.5`}),` `,g(`agent.cancelWorkflow`)]})]})})}function nZ(e){return typeof e==`object`&&!!e&&`value`in e}function rZ(e){return nZ(e)?e.value:e}function iZ(e){if(e.type===`stringList`)return e.value.map(e=>typeof e==`string`?e:rZ(e));if(e.multiple)return e.value.map(rZ);let t=e.value[0];return t===void 0?void 0:rZ(t)}function aZ(e,t,n){e.query[t]=n}function oZ(e){let t=new Set(e);return e=>t.has(e)}function sZ({buckets:e,name:r,placeholder:a}){let o=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:r,placeholder:a||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:o,type:`select`,labelRenderer:r=>{let a=e.find(e=>e._id===r),o=a?.name||r,s=`success`;if(a?.status)switch(a.status){case gn.published:s=`success`;break;case gn.archived:s=`destructive`;break;case gn.code:s=`info`}let c=a?.version&&a?.status?`v${a.version} ${a.status===gn.unknown?``:a.status}`:a?.status||(a?.version?`v${a.version}`:``);return n(`div`,{className:`w-full flex items-center justify-between`,children:[n(`div`,{className:`flex flex-row flex-wrap items-center gap-2 min-w-0 flex-1`,children:[t(`span`,{className:`text-sm truncate`,children:o}),c&&t(i,{variant:s,className:`text-xs w-fit`,children:c})]}),(a?.count??0)>0&&n(`span`,{className:`ms-2 text-xs shrink-0`,children:[`(`,a?.count,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}function cZ(e){return`${e._id} (${e.count})`}function lZ(e){return`${e.name} (${e.count})`}function uZ({buckets:e,name:t,placeholder:n,type:r=`select`,multiple:i=!1}){return{name:t,options:e.map(e=>({label:cZ(e),value:e._id})),type:r,multiple:i,placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`,allowCreate:!1}}function dZ({buckets:e,name:t,placeholder:n,type:r,multiple:i}){return uZ({buckets:e,name:t,placeholder:n,type:r,multiple:i})}Q();const fZ={},pZ={},mZ={};function hZ(e){return typeof e==`object`&&!!e&&`status`in e&&e.status===404}function gZ(e,t,n){let r=e[t];return r||(r=n().catch(n=>{throw hZ(n)||delete e[t],n}),e[t]=r),r}function _Z(e){let{client:t}=q();return Ye(()=>gZ(fZ,e,()=>t.users.retrieve(e)),{deps:[e],condition:()=>!!e})}function vZ(e){let{client:t}=q();return Ye(()=>gZ(pZ,e,()=>t.iam.groups.retrieve(e)),{deps:[e],condition:()=>!!e})}function yZ(e){let{client:t}=q();return Ye(()=>gZ(mZ,e,()=>t.apikeys.retrieve(e)),{deps:[e],condition:()=>!!e})}function bZ(){return t(`div`,{className:`size-8`})}function xZ({showTitle:e=!1,size:i=`md`}){let{t:a}=K();return t(NZ,{title:a(`user.systemUser`),description:a(`user.systemUserDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(r,{src:`/icon.svg`,size:i}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:a(`user.systemUser`)})]})})}function SZ({showTitle:e=!1,size:r=`md`}){let{t:i}=K();return t(NZ,{title:i(`user.allProjectMembers`),description:i(`user.allProjectMembersDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(jb,{className:`size-4`,size:r}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:i(`user.allProjectMembers`)})]})})}function CZ({accountId:i,showTitle:a=!1,size:o=`md`}){let{t:s}=K(),c=n(e,{children:[t(`div`,{children:s(`user.serviceAccountDescription`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]});return t(NZ,{title:s(`user.serviceAccount`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:`/cloud.svg`,name:`SA`,color:`bg-amber-500`,className:`px-[5px] text-white`,size:o}),a&&n(`div`,{className:`text-sm font-semibold ps-2 truncate`,children:[s(`user.serviceAccount`),` : ~`,i.slice(-6)]})]})})}function wZ({email:i,showTitle:a=!1,size:o=`md`}){let{t:s}=K(),c=n(e,{children:[t(`div`,{children:s(`user.agentOnBehalfOf`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`Email:`}),` `,i]})]});return t(NZ,{title:`Email Agent`,description:c,children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:o}),t(r,{name:i,size:o,className:`border-2 border-white dark:border-gray-800`})]}),a&&n(`div`,{className:`text-sm font-semibold truncate`,children:[`Agent (`,i,`)`]})]})})}function TZ({agentId:i,onBehalfOfType:a,onBehalfOfId:o,showTitle:s=!1,size:c=`md`,isScheduleAgent:l=!1}){let{t:u}=K(),d=a===`user`&&o,f=a===`apikey`&&o,p=_Z(o||``),m=yZ(o||``),h=d?p.data:void 0,g=f?m.data:void 0,_=i.slice(-6),v=h?u(`user.agentOnBehalfOf`):g?u(`user.agentOnBehalfOfApiKey`):`${u(`user.serviceAccount`)}~${_}`,y=l?u(`user.schedule`,{title:v}):v,b=n(`div`,{className:`space-y-2`,children:[h&&n(`div`,{className:`flex items-center gap-2`,children:[t(r,{src:h.picture,name:h.name,size:`sm`}),n(`div`,{children:[t(`div`,{className:`font-medium`,children:h.name||h.email}),h.email&&h.name&&t(`div`,{className:`text-xs text-muted`,children:h.email})]})]}),g&&n(`div`,{children:[t(`div`,{className:`font-medium`,children:g.name}),n(`div`,{className:`text-xs text-muted-foreground`,children:[`Key ID: `,g.id]})]}),!h&&!g&&n(e,{children:[t(`div`,{children:u(`user.serviceAccountDescription`)}),n(`div`,{className:`text-gray-800 dark:text-gray-500 text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]})]});return t(NZ,{title:y,description:b,children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:c}),h&&t(r,{src:h.picture,name:h.name,size:c,className:`border-2 border-white dark:border-gray-800`}),g&&t(r,{name:`API`,color:`bg-gray-400`,size:c,className:`border-2 border-white dark:border-gray-800`})]}),s&&t(`div`,{className:`text-sm font-semibold truncate`,children:h?`Agent (${h.name||h.email})`:g?`Agent (${g.name})`:v})]})})}function EZ({title:e=`Error`,error:n,showTitle:r=!1,size:i=`md`}){return t(kZ,{title:e,message:Ge(n),color:`bg-red-500`,showTitle:r,size:i})}function DZ({showTitle:e=!1,size:n=`md`,color:r}){let{t:i}=K();return t(kZ,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),color:r,showTitle:e,size:n})}function OZ({userRef:e,showTitle:n=!1,size:r=`md`}){let{t:i}=K();if(!e)return t(kZ,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),showTitle:n,size:r});let a=e.split(`:`),o=a[0];switch(o){case xn.User:return t(jZ,{userId:a[1],showTitle:n,size:r});case xn.Group:return t(AZ,{userId:a[1],showTitle:n,size:r});case`system`:return t(xZ,{showTitle:n,size:r});case xn.ServiceAccount:return t(CZ,{accountId:a.slice(1).join(`:`),showTitle:n,size:r});case xn.Agent:{let e,i,o;return a[1]===`agent`?(e=a.slice(2,5).join(`:`),i=a[5],o=a[6]):(e=a.slice(1,4).join(`:`),i=a[4],o=a[5]),t(TZ,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r})}case xn.Schedule:{let e=a[2]===`agent`?a.slice(3,6).join(`:`):`unknown-agent`,i=a[6],o=a[7];return t(TZ,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r,isScheduleAgent:!0})}case`email`:return t(wZ,{email:a[1],showTitle:n,size:r});case xn.ApiKey:return t(MZ,{keyId:a[1],size:r,showTitle:n});case`project`:if(a[1]===`*`)return t(SZ,{showTitle:n,size:r});break;default:return t(EZ,{title:i(`user.unknownUser`),error:`Invalid user ref type: ${o}`,showTitle:n,size:r})}}function kZ({title:e,message:i,color:a,size:o=`md`,showTitle:s=!1}){return t(NZ,{title:e,description:i,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{color:a,size:o}),s&&t(`div`,{className:`text-sm font-semibold ps-1`,children:e})]})})}function AZ({userId:e,showTitle:r=!1,size:i=`md`}){let{t:a}=K(),{data:o,error:s}=vZ(e);if(s)return hZ(s)?t(DZ,{showTitle:r,size:i,color:`bg-indigo-500`}):t(EZ,{title:a(`user.failedToFetchGroup`),error:s,showTitle:r,size:i});if(!o)return t(bZ,{});let c=n(`div`,{className:`space-y-1`,children:[o.description&&t(`div`,{className:`text-sm`,children:o.description}),t(`div`,{className:`text-xs text-muted-foreground`,children:a(`user.groupId`,{id:o.id})}),o.tags&&o.tags.length>0&&t(`div`,{className:`flex flex-wrap gap-1`,children:o.tags.map(e=>t(`span`,{className:`px-1.5 py-0.5 bg-muted rounded text-xs`,children:e},e))})]});return t(NZ,{title:o.name||a(`user.unnamedGroup`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(Pb,{className:`size-6 text-indigo-500`,size:i}),r&&t(`div`,{className:`text-sm font-semibold ps-2`,children:o.name||a(`user.unnamedGroup`)})]})})}function jZ({userId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=_Z(e);if(c)return hZ(c)?t(DZ,{showTitle:i,size:a,color:`bg-indigo-500`}):t(EZ,{title:o(`user.failedToFetchUser`),error:c,showTitle:i,size:a});if(!s)return t(bZ,{});let l=t(`div`,{className:`truncate`,title:s.email,children:s.email});return t(NZ,{title:s.name||s.email||s.username||o(`user.unknown`),description:l,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:s.picture,name:s.name,color:`bg-indigo-500`,size:a}),i&&t(`div`,{className:`text-sm font-semibold ps-2`,children:s.name||s.email||s.username||o(`user.unknown`)})]})})}function MZ({keyId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=yZ(e);if(c)return hZ(c)?t(DZ,{showTitle:i,size:a,color:`bg-pink-500`}):t(EZ,{title:o(`user.failedToFetchApiKey`),error:c,showTitle:i,size:a});if(!s)return t(bZ,{});let l=o(`user.privateKey`),u=t(r,{name:`PK`,color:`bg-pink-500`,size:a}),d=n(Le,{className:`dark:bg-gray-800 dark:text-gray-200 table-fixed w-full`,children:[n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.key`)}),t(`td`,{className:`truncate max-w-0`,children:s?.name})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.account`)}),t(`td`,{className:`truncate max-w-0`,children:s?.account})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.project`)}),t(`td`,{className:`truncate max-w-0`,children:s?.project.name})]})]});return t(NZ,{title:l,description:d,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[u,i&&t(`div`,{className:`text-sm font-semibold`,children:s?.name||s?.account||s?.project.name||o(`user.unknown`)})]})})}function NZ({title:e,description:r,children:i}){return n(he,{hover:!0,children:[t(_e,{className:`cursor-pointer flex items-center inline-block`,children:t(`div`,{children:i})}),t(ge,{align:`center`,sideOffset:8,side:`right`,children:n(`div`,{className:`flex flex-col gap-1 rounded-md shadow-md p-2`,children:[t(`div`,{className:`text-md font-semibold`,children:e}),r]})})]})}function PZ({buckets:e,name:r,placeholder:i}){let a=e.map(e=>({value:e._id,label:`(${e.count})`}));return{name:r,placeholder:i||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:a,labelRenderer:r=>{if(r===`Unknown User`||!r)return`Unknown User (${e.find(e=>e._id===r)?.count||0})`;let i=e.find(e=>e._id===r);return n(`div`,{className:`flex items-center w-full gap-2`,children:[t(`div`,{className:`flex-1 min-w-0 flex items-center truncate`,children:t(OZ,{userRef:r,showTitle:!0,size:`sm`})}),n(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`(`,i?.count||0,`)`]})]})}}}function FZ({buckets:e,name:t,placeholder:n}){return PZ({buckets:e,name:t,placeholder:n})}Q();const IZ=oZ([`id`,`run_kind`,`interaction`,`status`,`initiated_by`,`start`,`end`]);function LZ(e){let t=[];return t.push({name:`id`,placeholder:`Agent Run ID`,type:`text`,multiple:!1}),t.push(dZ({buckets:e.kinds||[],name:`run_kind`,placeholder:`Kind`})),t.push(sZ({buckets:e.interactions||[],name:`interaction`,placeholder:`Interaction`})),t.push(dZ({buckets:e.statuses||[],name:`status`,placeholder:`Status`})),t.push(FZ({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function RZ(e){return t=>{e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!IZ(t.name))return;let n=t.name;aZ(e,n,iZ(t))}}),e.search()}}function zZ({facets:e,search:r,selectionCount:i,actions:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=G([]),f=s??u,p=c??d,m=W(!1),h=W(typeof window<`u`&&!!new URLSearchParams(window.location.search).get(`filters`)),g=LZ(e),_=l??g,v=U(()=>RZ(r),[r]);return H(()=>{if(!m.current){m.current=!0;return}if(h.current){h.current=!1;return}v(f)},[f,v]),t(I,{filterGroups:_,filters:f,setFilters:p,children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!i&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted-foreground`,children:r.initialized?`${r.totalCount} runs`:`Loading runs...`})}),a&&a.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:a.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(gy,{className:`size-5`})})]})]}),f.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}var BZ=class{types;map={};constructor(e){this.types=e,e.sort((e,t)=>e.name.localeCompare(t.name));for(let t of e)this.map[t.id]=t}getType(e){return this.map[e]}getTypeLayout(e){let t=this.map[e];return t?t.table_layout:void 0}getTypeName(e){let t=this.map[e];return t?t.name:void 0}};const VZ=dt({registry:void 0,isLoading:!1,load:()=>Promise.resolve(),reload:()=>Promise.resolve()});function HZ({children:e}){let{store:n,project:r}=q(),[i,a]=G(),[o,s]=G(!1),c=W(!1),l=W(r?.id),u=V(async()=>{if(!(!r||c.current)){c.current=!0,s(!0);try{let e=await n.types.catalog.list({layout:!0});a(new BZ(e))}catch(e){console.error(`Failed to fetch types`,e)}finally{s(!1),c.current=!1}}},[n,r]),d=V(async()=>(c.current=!1,u()),[u]);return H(()=>{l.current!==r?.id&&(l.current=r?.id,a(void 0),c.current=!1)}),t(VZ.Provider,{value:{registry:i,isLoading:o,load:u,reload:d},children:e})}function UZ(){let e=_t(VZ);return H(()=>{!e.registry&&!e.isLoading&&e.load()},[e.registry,e.isLoading,e.load]),e}const WZ=oZ([`name`,`types`]);function GZ(e){let{registry:t}=UZ(),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t){let e=t.types.map(e=>({label:e.name,value:e.id})),r={name:`types`,placeholder:`Type`,type:`select`,multiple:!0,options:e,filterBy:(t,n)=>e.find(e=>e.value===t)?.label?.toLowerCase().includes(n.toLowerCase())??!1};n.push(r)}return n}function KZ(e){return t=>{if(t.length===0){e.clearFilters(!0);return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!WZ(t.name))return;let n=t.name;aZ(e,n,iZ(t))}}),e.search()}}function qZ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=GZ(e),u=KZ(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function JZ({buckets:e,typeRegistry:r,type:i=`select`,multiple:a=!1}){let o=new Map;return r||console.warn(`Type names cannot be resolved`),e.forEach(e=>{let t,n=e._id;e._id==null?(n=`Document`,t=`Document`):(t=r?.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),o.set(n,{name:t,count:e.count})}),{name:`types`,placeholder:`Types`,type:i,multiple:a,options:e.map(e=>{let t=e._id,n=t||`Document`,r=o.get(n);return{value:t,label:r?`${r.name} (${r.count})`:`Unknown (${e.count})`}}),labelRenderer:e=>{let r=o.get(e);return r?n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:r.name}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,r.count,`)`]})]}):(console.warn(`Type data not found for ${e}`),e)},filterBy:(e,t)=>{let n=o.get(e);return n?n.name.toLowerCase().includes(t.toLowerCase()):(console.warn(`Type name not found for ${e}`),!1)}}}const YZ=[`id`,`name`,`types`,`status`],XZ=[`tags`,`created_at`,`updated_at`],ZZ=oZ(YZ),QZ=new Set(XZ);function $Z(e){return QZ.has(e)}function eQ(e){return Array.isArray(e)?e:[]}function tQ(e){let{registry:t}=UZ(),n=[];if(n.push({placeholder:`ID`,name:`id`,type:`text`,options:[]}),n.push({placeholder:`Name`,name:`name`,type:`text`,options:[]}),e.type){let r=JZ({buckets:eQ(e.type),typeRegistry:t,type:`select`,multiple:!0});n.push(r)}if(e.status){let t=dZ({buckets:eQ(e.status),name:`status`,placeholder:`Status`,type:`select`,multiple:!0});n.push(t)}return e.tags&&n.push({name:`tags`,placeholder:`Tags`,type:`stringList`,options:eQ(e.tags).map(e=>({label:e._id,value:e._id}))}),n.push({name:`created_at`,placeholder:`Created Date`,type:`date`,multiple:!0,options:[]}),n.push({name:`updated_at`,placeholder:`Updated Date`,type:`date`,multiple:!0,options:[]}),n}function nQ(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name,r;if(t.type===`date`&&t.multiple){if(Array.isArray(t.value)&&t.value.length>0){if(t.value.length===1){let e=rZ(t.value[0]);r={gte:e,lte:e}}else t.value.length===2&&(r={gte:rZ(t.value[0]),lte:rZ(t.value[1])})}}else r=iZ(t);ZZ(n)?aZ(e,n,r):$Z(n)&&r!==void 0&&(e.query.match={...e.query.match,[n]:r})}}),e.search()}}function rQ({facets:e,search:r}){let[i,a]=G([]),o=tQ(e),s=nQ(r),c=$e();return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},inModal:c,children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function iQ({search:e,buckets:n,placeholder:r=`All Environments`,className:i}){let{client:a}=q(),[o,s]=G([]),c=e.getFilterValue(`environment`),l=t=>{e.setFilterValue(`environment`,t?._id)};H(()=>{if(a){let e=n.map(async e=>{let t;return await a.environments.retrieve(e._id).then(e=>{t=e.name}).catch(()=>{t=`${e._id} (deleted)`}),t||=e._id,{...e,name:t}});Promise.all(e).then(e=>{e.sort((e,t)=>e.name.localeCompare(t.name)),s(e)})}},[n,a]);let u=o?.find(e=>e._id===c);return t(we,{filterBy:`name`,className:i,isClearable:!0,optionLabel:lZ,options:o,value:u,onChange:l,by:`_id`,placeholder:r})}const aQ=oZ([`name`,`prompt`,`model`,`tags`]);function oQ(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.push({name:`prompt`,placeholder:`Prompt Name`,type:`text`,multiple:!1}),t.push({name:`model`,placeholder:`Model`,type:`text`,multiple:!1}),t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),t}function sQ(e){return t=>{if(t.length===0){e.clearFilters(!0,!0);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!aQ(t.name))return;let n=t.name;aZ(e,n,iZ(t))}}),e.search(!0)}}function cQ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=oQ(e),u=sQ(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function lQ(e){let t=[];return t.push(dZ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!1})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function uQ({facets:e,filters:r,setFilters:i}){let a=lQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function dQ(e){let t=[];return t.push(dZ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!0})),t.push(FZ({buckets:e.started_by||[],name:`started_by`,placeholder:`Started By`})),t.push(dZ({buckets:e.run_type||[],name:`run_type`,placeholder:`Mode`,multiple:!0})),t.push(dZ({buckets:e.processes||[],name:`process`,placeholder:`Process`,multiple:!0})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function fQ({facets:e,filters:r,setFilters:i}){let a=dQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}const pQ=oZ([`name`,`role`,`tags`]);function mQ(e,t){let n=e[t];return Array.isArray(n)?n:[]}function hQ(e){let t=mQ(e,`role`),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.length>0){let e={name:`role`,placeholder:`Role`,type:`select`,options:t.map(e=>({label:e._id,value:e._id,count:e.count}))};n.push(e)}let r={name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0,options:mQ(e,`tags`).map(e=>({label:e._id,value:e._id}))};return n.push(r),n}function gQ(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!pQ(t.name))return;let n=t.name;aZ(e,n,iZ(t))}}),e.search()}}function _Q({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=hQ(e),u=gQ(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function vQ({buckets:e,name:r}){let i=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:`environment`,placeholder:r.charAt(0).toUpperCase()+r.slice(1),options:i,type:`select`,labelRenderer:r=>{let i=e.find(e=>e._id===r),a=i?.name||r;return n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:a}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,i?.count||0,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}Q();const yQ=oZ([`run_ids`,`interaction`,`environment`,`tags`,`model`,`status`,`finish_reason`,`start`,`end`,`workflow_run_ids`,`workflow_ids`]);function bQ(e){return e.filter(e=>e._id!==null)}function xQ(e){let t=[];if(t.push({name:`run_ids`,placeholder:`Run ID`,type:`text`,multiple:!1}),e.interactions){let n=sZ({buckets:bQ(e.interactions),name:`interaction`,placeholder:`Interactions`});t.push(n)}if(e.environments){let n=vQ({buckets:bQ(e.environments),name:`environment`});t.push(n)}if(t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),e.models){let n=dZ({buckets:bQ(e.models),name:`model`});t.push(n)}if(e.statuses){let n=dZ({buckets:bQ(e.statuses),name:`status`});t.push(n)}if(e.finish_reason){let n=dZ({buckets:e.finish_reason.map(e=>({...e,_id:e._id===null?`none`:e._id})),name:`finish_reason`,placeholder:`Finish Reason`});t.push(n)}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`workflow_run_ids`,placeholder:`Workflow Run ID`,type:`text`,multiple:!1}),t.push({name:`workflow_ids`,placeholder:`Workflow ID`,type:`text`,multiple:!1}),t}function SQ(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!yQ(t.name))return;let n=t.name,r=iZ(t);(n===`run_ids`||n===`workflow_run_ids`||n===`workflow_ids`)&&!Array.isArray(r)&&(r=[r]),aZ(e,n,r)}}),e.search()}}function CQ({facets:e,search:r,actions:i,selectionCount:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=G([]),f=xQ(e),p=SQ(r),m=s!==void 0&&c!==void 0,h=m?s:u;return t(I,{filterGroups:l??f,filters:h,setFilters:e=>{if(m){c(e);return}let t=typeof e==`function`?e(u):e;d(t),p(t)},children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!a&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted`,children:r.initialized?`${r.totalCount} calls`:`Loading calls...`})}),i&&i.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:i.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(gy,{className:`size-5`})})]})]}),h.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}function wQ({search:e,buckets:n,name:r,placeholder:i,className:a}){let o=e.getFilterValue(r),s=t=>{e.setFilterValue(r,t?._id)},c=n?.find(e=>JSON.stringify(e._id)===JSON.stringify(o));return t(we,{filterBy:`_id`,className:a,isClearable:!0,optionLabel:cZ,options:n,value:c,onChange:s,by:`_id`,placeholder:i})}function TQ({search:e,name:n,placeholder:r,className:i}){let[a,o]=G([]);return H(()=>{e.setFilterValue(n,a)},[n,e,a]),t(ne,{className:i,value:a,onChange:o,placeholder:r})}function EQ(e){return`${e.name} (${e.count})`}function DQ({search:e,buckets:n,placeholder:r=`Filter by Type`,className:i}){let[a,o]=G([]),{registry:s}=UZ(),c=e.getFilterValue(`type`),l=t=>{e.setFilterValue(`type`,t?._id)};H(()=>{if(s){let e=n.map(e=>{let t;return e._id==null?(e._id=`Document`,t=`Document`):(t=s.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),{...e,name:t}});e.sort((e,t)=>e.name.localeCompare(t.name)),o(e)}},[n,s]);let u=a?.find(e=>e._id===c);return t(we,{filterBy:`name`,className:i,isClearable:!0,optionLabel:EQ,options:a,value:u,onChange:l,by:`_id`,placeholder:r})}function OQ(e){let t=[];return t.push(dZ({buckets:e.tags||[],name:`tags`,placeholder:`Tags`,multiple:!0})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function kQ({facets:e,filters:r,setFilters:i}){let a=OQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}const AQ=oZ([`search_term`,`status`,`initiated_by`,`start`,`end`,`has_reported_errors`]);function jQ(e){let t=[];if(t.push({placeholder:`Workflow Name or Workflow Run ID`,name:`search_term`,type:`text`,options:[]}),e.status){let n=dZ({buckets:e.status||[],name:`status`,placeholder:`Status`});t.push({...n,name:`status`})}if(e.initiated_by){let n=FZ({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`});t.push({...n,name:`initiated_by`})}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`has_reported_errors`,placeholder:`Has Reported Errors`,type:`select`,multiple:!1,options:[{label:`Yes`,value:`true`},{label:`No`,value:`false`}]}),t}function MQ(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!AQ(t.name))return;let n=t.name,r=iZ(t);if(n===`has_reported_errors`){let t=Array.isArray(r)?r[0]:r;(t===`true`||t===`false`)&&aZ(e,n,t===`true`)}else typeof r==`string`&&aZ(e,n,r)}}),e.search()}}function NQ({facets:e,search:r}){let[i,a]=G([]),o=jQ(e),s=MQ(r);return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function PQ(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function FQ({facets:e,filters:r,setFilters:i}){let a=PQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}var IQ=class e{object;objects;setState;collectionId;singleSelection=!1;constructor(e,t,n,r){this.object=e,this.objects=n,this.setState=r,this.singleSelection=Object.keys(this.objects).length===0,this.collectionId=t}isSingleSelection(){return this.singleSelection}hasSelection(){return this.object!==void 0||this.size()!==0}size(){return Object.keys(this.objects).length}getObjectIds(){return Object.keys(this.objects)}getObjectId(){return this.object?.id}clone(){return new e(this.object,this.collectionId,this.objects,this.setState)}add(e){this.objects[e.id]=e,this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}remove(e){delete this.objects[e],this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}addAll(e){for(let t of e)this.objects[t.id]=t;this.setState(this.clone())}isSelected(e){return this.objects[e]!==void 0}removeAll(){this.objects={},this.singleSelection=!0,this.setState(this.clone())}};const LQ=dt(void 0);function RQ(){let e=_t(LQ);if(!e)throw Error(`useObjectSelection must be used within a ObjectSelectionProvider`);return e}function zQ(){return _t(LQ)}function BQ({value:e,collectionId:n,children:r}){let[i,a]=G();return H(()=>{let t=new IQ(e,n,{},a);a(t)},[n,e]),i&&t(LQ.Provider,{value:i,children:r})}Q();const VQ=dt(void 0);function HQ({onFilter:e,children:n}){return t(VQ.Provider,{value:e,children:n})}function UQ(){return _t(VQ)}const WQ=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function GQ({field:r,value:i,label:a,copyContent:s}){let c=UQ(),l=Array.isArray(i)?i.length>0:i!==void 0&&i!==``;return n(e,{children:[s!==void 0&&s!==``&&t(x,{content:s,className:WQ}),l&&i!==void 0&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${a}`,className:WQ,onClick:e=>{e.stopPropagation(),c?.(r,i)},children:t(u_,{className:`size-3`})})]})}const KQ=`text/csv`,qQ=`image/`,JQ=`application/pdf`,YQ=`video/`,XQ=[`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/msword`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.ms-powerpoint`],ZQ=e=>e===KQ||KQ.includes(e),QQ=e=>e.startsWith(qQ)||qQ.includes(e),$Q=e=>e===JQ||JQ.includes(e),e$=e=>e.startsWith(YQ)||YQ.includes(e),t$=e=>XQ.includes(e);function n$(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))});let a=i.createElement(`style`);return a.textContent=`
1255
+ `}),s===`stacked`&&t(`div`,{className:z(`sticky top-0 z-10`,y&&`hidden`),children:t(EK,{workstreams:fe,activeWorkstream:R,onSelectWorkstream:ge,count:ve,completionStatus:it})}),ye.length===0&&Ve.length===0&&!ke&&!(se&&Ze)?R===`all`&&Ye?t(`div`,{className:`flex-1 px-2 py-6 sm:px-4`,children:t(vq,{label:F(`agent.preparing`),timestamp:Oe.current,className:b})}):t(`div`,{className:`flex items-center justify-center h-full text-center py-8`,children:t(`div`,{className:`flex items-center px-3 py-2 text-sm text-muted`,children:F(R===`all`?`agent.waitingForAgentResponse`:`agent.noMessagesInWorkstream`)})}):n(`div`,{className:z(`flex-1 flex flex-col justify-start w-full max-w-full`,se?`gap-6 px-2 py-6 sm:px-4`:`gap-3 pb-4`,x),children:[se&&R!==`all`&&pe&&t(`div`,{className:`sticky top-0 z-20 -mx-2 bg-background/95 px-2 pb-2 pt-1 backdrop-blur sm:-mx-4 sm:px-4`,children:n(`div`,{className:`mx-auto flex w-full max-w-3xl items-center gap-2 border-b border-border/70 pb-3`,children:[t(o,{type:`button`,variant:`ghost`,size:`icon`,className:`size-8 shrink-0 text-muted hover:text-foreground`,title:F(`agent.backToMainAgent`),onClick:_e,children:t(Tm,{className:`size-4`,"aria-hidden":`true`})}),t(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:pe})]})}),je&&t(_q,{data:T,schema:E,title:D,template:O,prependFriendlyMessage:w,timestamp:ye[0]?.timestamp??Date.now(),isSummaryView:se,messageItemClassNames:f,messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C},`initial-request`),$e&&t(vq,{label:Qe,timestamp:rt,className:b}),s===`stacked`?n(e,{children:[Je.map((e,n)=>{let r=n===Je.length-1;if(e.type===`resource_summary`)return t(wG,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`tool_group`){let n=e.messages[e.messages.length-1],i=e.toolStatus===`completed`||e.toolStatus===`error`||e.toolStatus===`warning`,a=!c&&r&&!JH.includes(n.type)&&!i;return h?.includes(s)?null:t(bJ,{status:e.toolStatus,children:t(xJ,{children:t(yK,{...m,messages:e.messages,showPulsatingCircle:a,toolRunId:e.toolRunId,toolStatus:e.toolStatus,preambleText:e.preambleText,preambleMessage:e.preambleMessage,rootClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,m?.rootClassName),headerClassName:z(`px-3 py-2`,m?.headerClassName),itemHeaderClassName:z(`hover:bg-mixer-muted/20`,m?.itemHeaderClassName)})})},Wq(e))}if(e.type===`streaming`)return t(bJ,{children:t(AG,{...g,text:e.text,workstreamId:e.workstreamId,isComplete:e.isComplete,timestamp:e.startTimestamp,artifactRunId:v,cardClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},Wq(e));{let i=e.message;if(Te(i)||Ee(i))return null;if(ZH(i))return t(bJ,{children:t(vJ,{message:i,startTimestamp:Gq(Je,n)??i.timestamp,endTimestamp:i.timestamp})},Uq(i,`stopped`));let a=!c&&r&&!JH.includes(i.type);return kK(i)?t(xJ,{children:t(qW,{message:i,batchData:i.details,isRunning:!i.details.completed_at,..._})},`batch-${i.details.batch_id}-${i.timestamp}`):t(bJ,{status:`message`,children:t(xJ,{children:t(_G,{...f,message:i,showPulsatingCircle:a,onSendMessage:u,onOpenArtifact:d,requestInputAnswered:QU(i,be),cardClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,f?.cardClassName),headerClassName:z(`px-3 py-2`,f?.headerClassName),contentClassName:z(`bg-transparent`,f?.contentClassName),messageStyleOverrides:p,StoreLinkComponent:S,CollectionLinkComponent:C})})},Uq(i))}}),Ve.map(({id:e,data:n})=>t(bJ,{children:t(AG,{...g,text:n.text,workstreamId:n.workstreamId,isComplete:n.isComplete,timestamp:n.startTimestamp,artifactRunId:v,cardClassName:z(`rounded-lg border border-border bg-background/60 shadow-none`,g?.cardClassName)})},`streaming-incomplete-${e}`)),Ye&&Ve.length===0&&!$e&&t(bJ,{children:n(`div`,{className:z(`flex items-center gap-2 py-2 text-sm text-muted`,b),children:[t(rW,{size:`sm`,color:`blue`}),t(`span`,{children:F(`agent.working`)})]})})]}):n(e,{children:[Ke.map(e=>{if(e.type===`resource_summary`)return t(wG,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`work`){if(h?.includes(s))return null;let n=RK(e.messages);return t(yJ,{label:zK(e.isActive),status:e.status,timestamp:e.startTimestamp,durationSeconds:e.isActive?void 0:MK(e.startTimestamp,e.endTimestamp),showElapsed:!0,details:n?void 0:e.messages,defaultExpanded:e.isActive&&!n,disablePreambleCollapse:e.isActive,className:b,onSendMessage:u,answeredToolApprovalRequestInputKeys:Se,resolvedToolApprovalKeys:xe},`work-${e.id}-${e.isActive?`active`:`done`}-${e.status}`)}if(e.type===`stopped`)return t(vJ,{message:e.message,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp},Uq(e.message,`stopped-summary`));let n=e.message;return Te(n)||Ee(n)?null:kK(n)?t(xJ,{children:t(qW,{message:n,batchData:n.details,isRunning:!n.details.completed_at,..._})},Uq(n,`batch`)):t(xJ,{children:t(cq,{message:n,onSendMessage:u,onOpenArtifact:d,onSelectWorkstream:ge,requestInputAnswered:QU(n,be),StoreLinkComponent:S,CollectionLinkComponent:C})},Uq(n,`summary`))}),Ve.map(({id:e,data:n})=>t(_J,{text:n.text,workstreamId:n.workstreamId,artifactRunId:v},`streaming-incomplete-${e}`)),Xe&&t(`div`,{className:z(`mx-auto w-full max-w-3xl px-1 text-sm text-muted`,b),"data-testid":`post-tool-thinking-indicator`,children:F(`agent.thinking`)}),Ze&&!$e&&t(yJ,{label:Qe,status:`running`,timestamp:rt,showElapsed:!0,className:b})]}),t(`div`,{ref:a,className:`h-2`})]})]})}const wJ=(e,t)=>{if(e.type!==t.type||e.message!==t.message)return!1;let n=e.details,r=t.details;if(n?.tool_status!==`completed`||r?.tool_status!==`completed`)return!1;let i=typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime();return(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())-i<2e3},TJ=ot.memo(CJ);Q();function EJ(e){return e?new Map(e.streamingMessages.map((e,t)=>[e.id??e.activityId??`stream-${t}`,e])):new Map}function DJ(e,t){return e?.find(e=>e.cursor===t)}function OJ(e,t){if(t===0||e===`live`)return`live`;let n=pC(e,t);return n>=t-1?`live`:n+1}function kJ(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function AJ(e){return kJ(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function jJ(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function MJ({fixture:e,cursor:r,initialCursor:i,onCursorChange:a,autoStepMs:s,repeat:c=1,viewMode:l,className:u,title:d,showHeader:f=!0}){let{t:p}=K(),m=e.messages,h=i??(m.length>0?0:`live`),[g,_]=G(()=>fC(h,m.length)),v=r??g,y=l??`sliding`,[b,x]=G(!!s),[S,C]=G(0),w=W(null),T=U(()=>gC(m,v,!0),[v,m]),E=T.displayedMessages,D=U(()=>EJ(DJ(e.streamingFrames,T.cursor)),[e.streamingFrames,T.cursor]),O=V(e=>{let t=fC(e,m.length);r===void 0&&_(t),a?.(t)},[r,m.length,a]);H(()=>{let e=fC(v,m.length);e!==v&&O(e)},[v,m.length,O]),H(()=>{if(!s||s<=0||!b)return;let e=window.setInterval(()=>{let e=OJ(v,m.length);if(e===`live`&&v===`live`){C(e=>{let t=e+1;return c>0&&t>=c?(x(!1),t):(O(m.length>0?0:`live`),t)});return}O(e)},s);return()=>window.clearInterval(e)},[s,v,b,m.length,c,O]);let k=E.length>0&&!XH(E),A=U(()=>$U(E),[E]),j=d??e.metadata?.title??p(`agent.rewind.fixtureTitle`),M=V(()=>{let t={...e,metadata:{...e.metadata,title:j,exported_at:e.metadata?.exported_at??new Date().toISOString(),message_count:m.length}},n=e.metadata?.agent_run_id??`fixture`;jJ(`${AJ(j)||`agent-chat`}-${AJ(n)}.json`,t)},[e,m.length,j]),N=V(()=>{O(OJ(T.cursor,m.length))},[m.length,T.cursor,O]);return n(`div`,{className:z(`flex h-full min-h-0 w-full flex-col bg-background text-foreground`,u),"data-agent-test-playback-enabled":!0,"data-agent-playback-cursor":T.cursor,"data-agent-live-message-count":m.length,"data-agent-rendered-message-count":T.renderedMessageCount,"data-agent-replay-playing":b||void 0,"data-agent-replay-loop":S,children:[f&&n(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border px-3 py-2`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,children:j}),t(`div`,{className:`text-xs text-muted`,children:p(`agent.rewind.fixtureMeta`,{messageCount:m.length,loops:S})})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:M,children:[t(sg,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(`agent.rewind.exportFixture`)})]}),s&&s>0&&n(o,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>x(e=>!e),children:[t(b?Kv:iy,{className:`size-4`}),t(`span`,{className:`ms-1.5`,children:p(b?`agent.rewind.pause`:`agent.rewind.resume`)})]})]})]}),t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(SC,{cursor:T.cursor,messages:m,onChangeCursor:O})}),t(TJ,{messages:E,isCompleted:k,streamingMessages:D,bottomRef:w,artifactRunId:e.metadata?.agent_run_id??`agent-chat-fixture`,viewMode:y,renderRequestInputControls:!A}),A&&t(tW,{message:A,onSendMessage:N,isLoading:!1})]})}function NJ({className:e,inline:r=!1}){return n(`div`,{className:z(`flex items-center gap-1`,r?`inline-flex`:``,e),children:[t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-blue-500 rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-blue-600`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}})]})}function PJ(){let{client:e}=q(),[t,n]=G([]),[r,i]=G(!0),[a,o]=G(!1),s=W(0),c=V(async()=>{let t=s.current+1;s.current=t,i(!0),o(!1);try{let r=await e.apps.getInstalledApps(`tools`),a=[];for(let e of r){let t=e,n=t.oauth_collection_ids??[],r=t.manifest.oauth_providers??{};if(!t.manifest.tool_collections)continue;let i=t.manifest.tool_collections.map(e=>jn(e)).filter(e=>e.type===`mcp`),o=i.filter(e=>e.auth!==`api_key`&&n.includes(e.id)),s=i.filter(e=>e.auth===`api_key`),c=new Map,l=new Map,u=[];for(let e of o)if(e.oauth_provider){let t=c.get(e.oauth_provider)??[];t.push(e),c.set(e.oauth_provider,t)}else if(e.oauth_app){let t=l.get(e.oauth_app)??[];t.push(e),l.set(e.oauth_app,t)}else u.push(e);for(let[e,n]of c){let i=n[0].id;for(let o of n)a.push({key:`${t.id}:provider:${e}:${o.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:o.name,representativeId:i,memberIds:[o.id],memberNames:[o.name],authType:`oauth`,oauthGrantType:r[e]?.grant_type})}for(let[e,n]of l){let r=n[0].id;for(let i of n)a.push({key:`${t.id}:oauthapp:${e}:${i.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:i.name,representativeId:r,memberIds:[i.id],memberNames:[i.name],authType:`oauth`})}for(let e of u)a.push({key:`${t.id}:individual:${e.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e.name,representativeId:e.id,memberIds:[e.id],memberNames:[e.name],authType:`oauth`});for(let e of s)a.push({key:`${t.id}:api-key:${e.id}`,appId:t.id,appName:t.manifest.title||t.manifest.name,label:e.name,representativeId:e.id,memberIds:[e.id],memberNames:[e.name],authType:`api_key`})}if(s.current!==t||(n(a),i(!1),a.length===0))return;o(!0);let c=new Map,l=await Promise.all(a.map(async t=>{try{let n=c.get(t.appId);n||(n=e.remoteMcpConnections.getStatus(t.appId),c.set(t.appId,n));let r=(await n).find(e=>e.collection_id===t.representativeId);return{...t,authStatus:r}}catch{return t}}));if(s.current!==t)return;n(l)}catch(e){s.current===t&&(console.error(`Failed to load MCP tool collections:`,e),n([]))}finally{s.current===t&&(i(!1),o(!1))}},[e]);return H(()=>{c()},[c]),{groups:t,loading:r,statusLoading:a,reload:c}}function FJ(e,t){return t?.length?e.memberIds.every(e=>t.includes(e)):!1}function IJ(e,t,n){let r=new Set(t??[]);if(n)for(let t of e.memberIds)r.delete(t);else for(let t of e.memberIds)r.add(t);return Array.from(r)}function LJ(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!FJ(e,t)).length}function RJ(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!FJ(e,t)).map(e=>e.label)}Q();function zJ({isOpen:e,onClose:r,groups:i,loading:a,statusLoading:o=!1,reload:s,disabledCollections:c,onChange:l,onConnectionChange:u,readOnly:d=!1}){let{t:f}=K(),p=()=>{s(),u?.()};return n(hT,{isOpen:e,onClose:r,size:`md`,className:`max-w-[92vw] sm:max-w-[620px] lg:max-w-[620px]`,children:[t(gT,{children:f(`mcpConnections.title`)}),n(_T,{children:[t(`p`,{className:`mb-4 text-sm text-muted`,children:f(`mcpConnections.subtitle`)}),a?t(`div`,{className:`flex items-center justify-center py-8`,children:t(fO,{className:`size-5`})}):i.length===0?t(`div`,{className:`py-8 text-center text-sm text-muted`,children:f(`mcpConnections.empty`)}):t(`div`,{className:`space-y-1`,children:i.map(e=>{let r=!FJ(e,c),i=e.authStatus?.authenticated===!0,a=e.authType===`oauth`&&e.oauthGrantType!==`client_credentials`;return n(`div`,{className:`flex items-center justify-between gap-3 py-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[t(i?K_:U_,{className:`size-4 shrink-0 ${i?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(nT,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:e.appName}),e.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:e.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`truncate ${r?`text-foreground`:`text-muted line-through`}`,children:e.label})})]}),n(`div`,{className:`flex shrink-0 items-center gap-3`,children:[a&&o&&!e.authStatus?t(sT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:f(`mcpConnections.checkingStatus`),children:t(fO,{className:`size-3`})}):a?t(hO,{appId:e.appId,collectionId:e.representativeId,collectionName:e.label,authenticated:e.authStatus?.authenticated,onAuthChange:p,variant:`compact`,showDisconnect:!0,readOnly:d}):e.authType===`oauth`?t(dT,{variant:`outline`,className:`h-6 w-32 justify-center px-2 text-xs`,children:f(`mcpConnections.managedByApp`)}):null,l&&t(uO,{size:`sm`,value:r,onChange:t=>l(IJ(e,c,t)),disabled:d,"aria-label":f(r?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:e.label})})]})]},e.key)})})]})]})}Q();function BJ({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1,variant:s=`outline`,size:c=`sm`}){let{t:l}=K(),{groups:u,loading:d,statusLoading:f,reload:p}=PJ(),[m,h]=G(!1);if(!d&&u.length===0)return null;let g=LJ(u,r),_=RJ(u,r),v=_.slice(0,2),y=_.length-v.length,b=v.length>0?`${v.join(`, `)}${y>0?` +${y}`:``}`:void 0;return n(e,{children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[b&&t(`span`,{className:`max-w-48 truncate text-muted`,title:_.join(`, `),children:b}),n(sT,{variant:s,size:c,className:`shrink-0`,onClick:()=>h(!0),disabled:d,"aria-label":l(`mcpConnections.manage`),children:[t(`span`,{children:l(`mcpConnections.label`)}),g>0&&t(dT,{variant:`success`,children:g})]})]}),t(zJ,{isOpen:m,onClose:()=>h(!1),groups:u,loading:d,reload:p,statusLoading:f,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}function VJ({disabledCollections:e,onChange:r,onConnectionChange:i,readOnly:a=!1}){let{t:o}=K(),{groups:s,loading:c,statusLoading:l,reload:u}=PJ();if(!c&&s.length===0)return null;let d=()=>{u(),i?.()};return c&&s.length===0?n(`div`,{className:`flex items-center gap-2 border-y border-border/70 py-2 text-sm text-muted`,children:[t(fO,{className:`size-4`}),t(`span`,{children:o(`mcpConnections.label`)})]}):t(`div`,{className:`space-y-1`,children:s.map(i=>{let s=!FJ(i,e),c=i.authStatus?.authenticated===!0,u=i.authType===`oauth`&&i.oauthGrantType!==`client_credentials`;return n(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 py-2 text-sm`,children:[n(`div`,{className:`flex min-w-36 flex-1 items-center gap-2`,children:[t(c?K_:U_,{className:`size-4 shrink-0 ${c?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(nT,{description:n(`div`,{className:`space-y-0.5`,children:[t(`div`,{className:`font-medium`,children:i.appName}),i.memberNames.length>1&&t(`div`,{className:`text-xs text-muted`,children:i.memberNames.join(` · `)})]}),placement:`top`,asChild:!0,children:t(`span`,{className:`block truncate ${s?`text-foreground`:`text-muted line-through`}`,children:i.label})})]}),u&&l&&!i.authStatus?t(sT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:o(`mcpConnections.checkingStatus`),children:t(fO,{className:`size-3`})}):u?t(hO,{appId:i.appId,collectionId:i.representativeId,collectionName:i.label,authenticated:i.authStatus?.authenticated,onAuthChange:d,variant:`compact`,showDisconnect:!0,readOnly:a}):t(dT,{variant:`outline`,className:`h-6 w-32 justify-center px-2 text-xs`,children:i.authType===`api_key`?o(`mcpConnections.apiKey`):o(`mcpConnections.managedByApp`)}),r&&n(`div`,{className:`flex min-w-24 items-center justify-end gap-2 text-xs`,children:[t(`span`,{className:s?`text-muted`:`text-attention`,children:o(s?`mcpConnections.enabled`:`mcpConnections.disabled`)}),t(uO,{size:`sm`,value:s,onChange:t=>r(IJ(i,e,t)),disabled:a,"aria-label":o(s?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:i.label})})]})]},i.key)})})}function HJ({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1}){let{t:s}=K(),{groups:c,loading:l,statusLoading:u,reload:d}=PJ(),[f,p]=G(!1);if(!l&&c.length===0)return null;let m=LJ(c,r);return n(e,{children:[t(UD,{align:`left`,trigger:t(sT,{variant:`ghost`,size:`icon`,className:`size-8 rounded-md text-muted hover:bg-muted`,title:s(`mcpConnections.settings`),disabled:l,children:t(`span`,{className:`flex size-5 items-center justify-center rounded-[3px] border border-muted text-sm font-semibold leading-none`,"aria-hidden":`true`,children:`/`})}),children:n(WD,{onClick:()=>p(!0),isDisabled:l,children:[t(`span`,{children:s(`mcpConnections.title`)}),m>0&&t(dT,{variant:`success`,children:m})]})}),t(zJ,{isOpen:f,onClose:()=>p(!1),groups:c,loading:l,reload:d,statusLoading:u,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}const UJ=/(^|\/)(tool-inputs|tool-results|archive)(\/|$)/,WJ=/(^|\/)process\/(history|state)(\/|$)/,GJ=[/conversation\.json$/,/^conversation-checkpoint-\d+\.json$/,/^tools\.json$/,/^tool-input-refs\.json$/,/^toolu[_-]/i];function KJ(e){if(UJ.test(e)||WJ.test(e))return!0;let t=e.split(`/`).pop()??e;return GJ.some(e=>e.test(t))}function qJ(e){let t={name:``,path:``,isDirectory:!0,children:[]};for(let n of e){let e=n.split(`/`),r=t,i=``;for(let t=0;t<e.length;t++){let n=e[t];i=i?`${i}/${n}`:n;let a=t===e.length-1,o=r.children.find(e=>e.name===n);o||(o={name:n,path:i,isDirectory:!a,children:[]},r.children.push(o)),r=o}}let n=e=>{e.children.sort((e,t)=>e.isDirectory===t.isDirectory?e.name.localeCompare(t.name):e.isDirectory?-1:1),e.children.forEach(n)};return n(t),t.children}function JJ(e,t){let n=`agents/${t}/`,r=e.indexOf(n);return r===-1?e.split(`/`).pop()??e:e.slice(r+n.length)}function YJ(e,t,n=0,r=!1){let[i,a]=G([]),[o,s]=G(!1),[c,l]=G(null),[u,d]=G(0),f=W(0),p=V(async()=>{if(!t)return;let n=++f.current;s(!0),l(null);try{let r=await e.files.listArtifacts(t);if(n!==f.current)return;let i=r.map(e=>JJ(e,t)).filter(e=>!!e);a(i)}catch(e){if(n!==f.current)return;l(e instanceof Error?e.message:`Failed to list artifacts`),a([])}finally{n===f.current&&s(!1)}},[e,t]);H(()=>{p()},[p,n,u]);let m=U(()=>r?i:i.filter(e=>!KJ(e)),[i,r]),h=U(()=>qJ(m),[m]),g=i.length-m.length,_=V(()=>{d(e=>e+1)},[]);return{tree:h,flatFiles:m,totalCount:i.length,systemHiddenCount:g,isLoading:o,error:c,refresh:_}}function XJ(){return ZJ||=import(`react-pdf`).then(e=>{let{pdfjs:t}=e;return t.GlobalWorkerOptions.workerSrc=`//unpkg.com/pdfjs-dist@${t.version}/build/pdf.worker.min.mjs`,e}),ZJ}var ZJ,QJ,$J,eY=Y((()=>{QJ=ht(()=>XJ().then(({Document:e})=>({default:e}))),$J=ht(()=>XJ().then(({Page:e})=>({default:e})))}));function tY({className:e,size:n=`md`}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(tv,{className:`${{sm:`w-4 h-4`,md:`w-6 h-6`,lg:`w-8 h-8`}[n]} animate-spin text-muted-foreground`})})}function nY({pdfUrl:e,pageNumber:r,width:i,className:a,renderTextLayer:o=!1,renderAnnotationLayer:s=!1,onLoadSuccess:c,onError:l}){let[u,d]=G(!0),[f,p]=G(null);return f?t(`div`,{className:`flex items-center justify-center text-destructive text-sm ${a||``}`,children:`Failed to load PDF`}):n(`div`,{className:a,children:[u&&t(tY,{className:`py-4`,size:`md`}),t(ut,{fallback:null,children:t(QJ,{file:e,onLoadSuccess:({numPages:e})=>{d(!1),c?.(e)},onLoadError:e=>{d(!1),p(e),l?.(e)},loading:null,children:t($J,{pageNumber:r,width:i,renderTextLayer:o,renderAnnotationLayer:s,loading:t(tY,{className:`py-4`,size:`sm`})})})})]})}function rY({pdfUrl:e,urlLoading:n=!1,children:r,onLoadSuccess:i}){let[a,o]=G(0),[s,c]=G(!0),[l,u]=G(null),[d,f]=G(null),p=async e=>{o(e.numPages),i?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1});f({width:t.width,height:t.height,aspectRatio:t.width/t.height})}catch(e){console.error(`Failed to get page dimensions:`,e)}c(!1)},m=e=>{c(!1),u(e)},h={pdfUrl:e,numPages:a,loading:n||!e||s,error:l,pageDimensions:d};return l?t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`}):t(uY.Provider,{value:h,children:e?t(ut,{fallback:t(tY,{className:`py-4`,size:`md`}),children:t(QJ,{file:e,onLoadSuccess:p,onLoadError:m,loading:t(tY,{className:`py-4`,size:`md`}),children:r((e,n)=>t($J,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(tY,{className:`py-4`,size:`sm`})},e))})}):t(tY,{className:`py-4`,size:`md`})})}function iY(){return _t(uY)}function aY({pageNumber:e,width:n,className:r}){let i=iY(),a=i?.pageDimensions?.aspectRatio??dY,o=n?Math.round(n/a):200;return i?.loading?t(`div`,{className:`flex items-center justify-center bg-muted ${r||``}`,style:{height:o,width:n||`100%`},children:t(tY,{size:`md`})}):t(`div`,{className:r,children:t($J,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(tY,{className:`py-4`,size:`sm`})})})}function oY({pageNumber:e,width:n,isSelected:r,onSelect:i,renderThumbnail:a,aspectRatio:o=dY,rootMargin:s=`200px 0px`}){let c=W(null),[l,u]=G(!1);H(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(e=>{e[0]?.isIntersecting&&u(!0)},{rootMargin:s,threshold:0});return t.observe(e),()=>t.disconnect()},[s]);let d=n?Math.round(n/o):200,f=l?t($J,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d},children:t(tY,{size:`sm`})})}):t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d,width:n||`100%`},children:t(`span`,{className:`text-muted-foreground text-xs`,children:e})});return t(`div`,{ref:c,children:a({pageNumber:e,isSelected:r,pageElement:f,onSelect:i})})}function sY(e){if(!e)return null;let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t).overflowY;if(e===`auto`||e===`scroll`)return t;t=t.parentElement}return null}function cY({pdfUrl:r,urlLoading:i=!1,pageCount:a,currentPage:o,thumbnailWidth:s,onPageSelect:c,renderThumbnail:l,scrollContainerRef:u,onAspectRatioChange:d,onItemHeightChange:f,calculateItemHeight:p,onPageCountChange:m}){let[h,g]=G(null),[_,v]=G({start:0,end:Math.min(15,a)}),[y,b]=G(null),x=W(null),S=V(e=>{g(e)},[]),C=V(async e=>{m?.(e.numPages);try{let t=(await e.getPage(1)).getViewport({scale:1}),n=t.width/t.height;b(n),d?.(n)}catch(e){console.error(`Failed to get page dimensions:`,e),b(dY),d?.(dY)}},[d,m]),w=y??dY,T=s?Math.round(s/w):200,E=p?p(T):T+16+24+8;if(H(()=>{E>0&&y!==null&&f?.(E)},[E,y,f]),H(()=>{let e=u?.current||sY(x.current);if(!e)return;let t=()=>{let t=e.scrollTop,n=e.clientHeight,r=Math.floor(t/E),i=Math.ceil((t+n)/E),o=Math.max(0,r-5),s=Math.min(a,i+5);v(e=>e.start!==o||e.end!==s?{start:o,end:s}:e)};return t(),e.addEventListener(`scroll`,t,{passive:!0}),()=>e.removeEventListener(`scroll`,t)},[E,a,u]),h)return t(`div`,{className:`flex items-center justify-center text-destructive text-sm py-4`,children:`Failed to load PDF`});if(i||!r)return t(tY,{className:`py-4`,size:`md`});let D=_.start*E,O=(a-_.end)*E,k=y!==null;return t(`div`,{ref:x,children:t(ut,{fallback:t(tY,{className:`py-4`,size:`md`}),children:t(QJ,{file:r,onLoadSuccess:C,onLoadError:S,loading:t(tY,{className:`py-4`,size:`md`}),children:k?n(e,{children:[D>0&&t(`div`,{style:{height:D}}),Array.from({length:_.end-_.start},(e,n)=>{let r=_.start+n+1;return t(`div`,{"data-page-index":r-1,style:{height:E,overflow:`hidden`},children:t(oY,{pageNumber:r,width:s,isSelected:r===o,onSelect:()=>c(r),renderThumbnail:l,aspectRatio:w})},r)}),O>0&&t(`div`,{style:{height:O}})]}):t(tY,{className:`py-4`,size:`md`})})})})}function lY({pdfUrl:e,pageNumber:r,width:i,height:a,className:o,renderTextLayer:s=!1,renderAnnotationLayer:c=!1,onPageChange:l}){let[u,d]=G(0),[f,p]=G(!0),[m,h]=G(null);return H(()=>{u>0&&l?.(r,u)},[r,u,l]),m?t(`div`,{className:`flex items-center justify-center text-destructive ${o||``}`,children:n(`span`,{children:[`Failed to load PDF: `,m.message]})}):n(`div`,{className:o,children:[f&&t(tY,{className:`py-8`,size:`lg`}),t(ut,{fallback:null,children:t(QJ,{file:e,onLoadSuccess:({numPages:e})=>{d(e),p(!1)},onLoadError:e=>{p(!1),h(e)},loading:null,children:t($J,{pageNumber:Math.min(r,u||1),width:i,height:a,renderTextLayer:s,renderAnnotationLayer:c,loading:t(tY,{className:`py-8`,size:`md`})})})})]})}var uY,dY,fY=Y((()=>{Q(),eY(),uY=dt(null),dY=210/297}));function pY({pdfUrl:r,pdfUrlLoading:i=!1,pageCount:a,currentPage:s,onChange:c,onPageCountChange:l,className:u,compact:d=!1,headerExtra:f}){let{t:m}=K(),h=W(null),g=W(null),[_,v]=G(void 0),[y,b]=G(vY),[x,S]=G(gY),[C,w]=G(null),T=W(null),E=_?Math.round(_*y/100):void 0,D=V(()=>{let e=_Y.findIndex(e=>e>=y);e===-1&&(e=_Y.length-1);let t=Math.min(e+1,_Y.length-1);b(_Y[t])},[y]),O=V(()=>{let e=_Y.findIndex(e=>e>=y);e===-1&&(e=_Y.length-1);let t=Math.max(e-1,0);b(_Y[t])},[y]),k=V(()=>{b(vY)},[]),A=V(e=>e+(d?28:48),[d]),j=V((e,t)=>{let n=e?Math.round(e/t):200;return A(n)},[A]);H(()=>{let e=g.current;if(!e)return;let t=null,n=()=>e.clientWidth-16-16-4,r=()=>{let t=n();if(t<=0)return;let r=T.current;if(r&&r>0){let n=e.scrollTop,i=Math.round(n/r),a=j(t,x),o=i*a;v(t),requestAnimationFrame(()=>{e.scrollTo({top:o,behavior:`instant`})}),T.current=a}else v(t),T.current=j(t,x)},i=n();i>0&&(v(i),T.current=j(i,x));let a=new ResizeObserver(()=>{t&&clearTimeout(t),t=setTimeout(r,150)});return a.observe(e),()=>{t&&clearTimeout(t),a.disconnect()}},[x,j]);let M=W(!1),N=W(null),P=W(y);H(()=>{P.current!==y&&(P.current=y,N.current={targetPage:s},M.current=!0)},[y,s]),H(()=>{let e=g.current,t=N.current;if(t&&e&&C){N.current=null;let n=(t.targetPage-1)*C;requestAnimationFrame(()=>{e.scrollTo({top:n,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})})}},[C]);let F=W(!1);H(()=>{let e=g.current;if(!(!e||!C||F.current)){if(s>1){F.current=!0,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}else F.current=!0}},[C,s]);let I=W(s);return H(()=>{let e=g.current;if(!(!e||!C)&&I.current!==s){I.current=s,M.current=!0;let t=(s-1)*C;e.scrollTo({top:t,behavior:`instant`}),requestAnimationFrame(()=>{M.current=!1})}},[s,C]),H(()=>{let e=g.current;if(!e||!C)return;let t=null,n=()=>{M.current||(t&&clearTimeout(t),t=setTimeout(()=>{let t=e.scrollTop,n=Math.round(t/C)+1,r=Math.max(1,Math.min(n,a));r!==s&&(I.current=r,c(r))},50))};return e.addEventListener(`scroll`,n,{passive:!0}),()=>{t&&clearTimeout(t),e.removeEventListener(`scroll`,n)}},[C,a,s,c]),n(`div`,{ref:h,className:it(`flex flex-col items-stretch`,d?`gap-y-1`:`gap-y-2`,u),children:[n(`div`,{className:it(`relative flex items-center justify-center px-2`,d?`h-6`:`h-9`),children:[t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s>1&&c(s-1)},title:m(`pdf.previousPage`),children:t(Oh,{className:`size-4`})}),n(`div`,{className:`absolute start-2 flex items-center gap-x-1`,children:[t(hY,{zoom:y,onZoomIn:D,onZoomOut:O,onFitToView:k,canZoomIn:y<_Y[_Y.length-1],canZoomOut:y>_Y[0]}),f&&n(e,{children:[t(`div`,{className:`w-px h-4 bg-border mx-1`}),f]})]}),t(`div`,{className:`absolute end-2`,children:t(mY,{currentPage:s,totalPages:a,onChange:c})})]}),t(`div`,{ref:g,className:it(`flex flex-col items-center flex-1 overflow-y-auto px-2`,d?`gap-1`:`gap-2`),children:t(cY,{pdfUrl:r,urlLoading:i,pageCount:a,currentPage:s,thumbnailWidth:E,onPageSelect:c,onPageCountChange:l,scrollContainerRef:g,onAspectRatioChange:S,onItemHeightChange:w,calculateItemHeight:A,renderThumbnail:({pageNumber:e,isSelected:r,pageElement:i,onSelect:a})=>n(`div`,{className:it(`hover:bg-muted rounded-md w-full`,d?`p-1`:`p-2`),children:[t(o,{variant:`unstyled`,size:`none`,"aria-pressed":r,"aria-label":`Page ${e}`,className:it(`relative border-[2px] cursor-pointer overflow-hidden`,r?`border-primary`:`border-border`),onClick:a,children:i}),t(p,{className:it(`text-muted-foreground font-semibold`,d?`text-xs pt-0.5`:`text-sm pt-1`),children:e})]},e)})}),t(`div`,{className:it(`flex items-center justify-center`,d?`h-6`:`h-9`),children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>{s<a&&c(s+1)},title:m(`pdf.nextPage`),children:t(gh,{className:`size-4`})})})]})}function mY({currentPage:e,totalPages:r,onChange:i}){let{t:a}=K(),o=W(null),[s,c]=G(String(e));H(()=>{c(String(e))},[e]);let l=()=>{let t=parseInt(s,10);!Number.isNaN(t)&&t>=1&&t<=r?i(t):c(String(e))};return n(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[t(`span`,{children:a(`pdf.page`)}),t(`input`,{ref:o,type:`text`,value:s,onChange:e=>c(e.target.value),onKeyDown:t=>{t.key===`Enter`?(l(),o.current?.blur()):t.key===`Escape`&&(c(String(e)),o.current?.blur())},onBlur:()=>{l()},className:`w-8 h-5 text-center text-xs px-1 py-0 bg-background border border-border rounded focus:outline-none focus:border-primary`}),n(`span`,{children:[`/ `,r]})]})}function hY({zoom:e,onZoomIn:r,onZoomOut:i,onFitToView:a,canZoomIn:s,canZoomOut:c}){let{t:l}=K();return n(`div`,{className:`flex items-center gap-x-0.5`,children:[t(o,{variant:`ghost`,size:`xs`,onClick:i,isDisabled:!c,title:l(`pdf.zoomOut`),children:t(jv,{})}),n(`span`,{className:`text-xs text-muted-foreground min-w-[32px] text-center`,children:[e,`%`]}),t(o,{variant:`ghost`,size:`xs`,onClick:r,isDisabled:!s,title:l(`pdf.zoomIn`),children:t(sy,{})}),t(o,{variant:`ghost`,size:`xs`,onClick:a,title:l(`pdf.fitToWidth`),className:e===vY?`text-muted-foreground/40`:void 0,children:t(pv,{})})]})}var gY,_Y,vY,yY=Y((()=>{Q(),fY(),gY=210/297,_Y=[50,75,100,125,150,200,300],vY=100}));function bY({object:e,url:r,source:i,className:a}){let{t:s}=K(),{client:c}=q(),[l,u]=G(1),[d,f]=G(r||``),[p,m]=G(!r),[h,g]=G(0),[_,v]=G(!1);H(()=>{if(r){f(r),m(!1);return}let t=i||e?.content?.source;if(!t){m(!1);return}m(!0),c.files.getDownloadUrl(t).then(e=>{f(e.url)}).catch(e=>{console.error(`Failed to get PDF URL:`,e)}).finally(()=>{m(!1)})},[r,i,e?.content?.source,c]),H(()=>{let t=e?.metadata,n=t?.pages||t?.page_count||0;n>0&&g(n)},[e?.metadata]);let y=e=>{g(e)};return p?t(`div`,{className:`flex items-center justify-center h-full`,children:t(je,{size:`lg`})}):d?_?n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col overflow-hidden`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:t(o,{variant:`ghost`,size:`xs`,onClick:()=>v(!1),title:s(`pdf.closeFullscreen`),children:t(Kb,{className:`size-4`})})}),t(pY,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:`flex-1 min-h-0`})]}):t(`div`,{className:`relative h-full flex flex-col`,children:t(pY,{pdfUrl:d,pdfUrlLoading:p,pageCount:h||100,currentPage:l,onChange:u,onPageCountChange:y,className:a,compact:!0,headerExtra:t(o,{title:s(`pdf.fullscreen`),tooltipPlacement:`bottom`,variant:`unstyled`,className:`p-1 rounded cursor-pointer transition-colors text-muted-foreground hover:text-foreground hover:bg-muted`,onClick:()=>v(!0),children:t(uv,{className:`size-4`})})})}):t(`div`,{className:`flex items-center justify-center h-full text-muted`,children:s(`pdf.noPdfAvailable`)})}var xY=Y((()=>{Q(),yY()})),SY=hr({UniversalDocumentViewer:()=>qY});function CY(e){return e.fileName||e.title||e.artifact?.path.split(`/`).pop()||e.sourcePath?.split(`/`).pop()||`Document`}function wY(e){let t=e.split(`?`)[0]||e;return t.includes(`.`)&&t.split(`.`).pop()?.toLowerCase()||``}function TY(e){return e.contentType===`application/pdf`||e.extension===`pdf`}function EY(e){return[`md`,`markdown`].includes(e.extension)||[`text/markdown`,`text/x-markdown`].includes(e.contentType||``)}function DY(e){return e.contentType?.startsWith(`image/`)||[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`].includes(e.extension)}function OY(e){return e.contentType===`text/html`||[`html`,`htm`].includes(e.extension)}function kY(e){return[`application/xml`,`text/xml`].includes(e.contentType||``)||e.extension===`xml`}function AY(e){return e.contentType?.startsWith(`text/`)||[`css`,`csv`,`json`,`txt`,`tsx`,`ts`,`jsx`,`js`,`xml`,`yaml`,`yml`].includes(e.extension)}function jY(e){return[`tsx`,`jsx`].includes(e.extension)}function MY(e){return[`doc`,`docx`,`ppt`,`pptx`].includes(e.extension)||[`application/msword`,`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/vnd.ms-powerpoint`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`].includes(e.contentType||``)}function NY({content:e,extension:n}){return t(`pre`,{className:`h-full overflow-auto rounded-md bg-muted/10 p-3 text-xs leading-5`,children:t(`code`,{className:n?`language-${n}`:void 0,children:e||``})})}function PY({message:e}){return n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-muted`,children:[t(Qg,{className:`size-8`}),t(`span`,{className:`text-sm`,children:e})]})}function FY(e,n){if(e.Component){let r=e.Component;return t(r,{context:n})}return e.render?.(n)??null}function IY(e,t){return e.includes(`.`)?e.replace(/\.[^/.]+$/,t):`${e}${t}`}function LY(e){return e.split(`/`).pop()||e}function RY(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function zY(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function BY(e){if(e!==void 0)return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function VY(e){return Array.isArray(e)?e.length:0}function HY(e){try{let t=RY(JSON.parse(e));if(!t)return;let n=RY(t.viewport);return{ok:typeof t.ok==`boolean`?t.ok:void 0,source_artifact:typeof t.source_artifact==`string`?t.source_artifact:void 0,screenshot_artifact:typeof t.screenshot_artifact==`string`?t.screenshot_artifact:void 0,rendered_at:typeof t.rendered_at==`string`?t.rendered_at:void 0,viewport:n?{width:zY(n.width),height:zY(n.height)}:void 0,dependencies_reused:typeof t.dependencies_reused==`boolean`?t.dependencies_reused:void 0,status:zY(t.status),title:typeof t.title==`string`?t.title:void 0,console_errors:Array.isArray(t.console_errors)?t.console_errors:void 0,page_errors:Array.isArray(t.page_errors)?t.page_errors:void 0,failed_requests:Array.isArray(t.failed_requests)?t.failed_requests:void 0,bad_responses:Array.isArray(t.bad_responses)?t.bad_responses:void 0,timings_ms:RY(t.timings_ms),error:t.error}}catch{return}}async function UY(e,t){let n=await fetch(e);if(!n.ok)throw Error(`Failed to load ${t}: ${n.statusText}`);return n.text()}function WY({metadata:e,sourcePath:t,fallbackPath:n,artifactMode:r}){let i=e?.screenshot_artifact?.replace(/^\/+/,``);if(!i)return n;if(r)return i;let a=e?.source_artifact?.replace(/^\/+/,``),o=t.replace(/^\/+/,``);if(a&&o.endsWith(a)){let e=o.slice(0,-a.length).replace(/\/+$/,``);return e?`${e}/${i}`:i}let s=o.includes(`/`)?o.slice(0,o.lastIndexOf(`/`)+1):``;return s?`${s}${LY(i)}`:n}function GY({metadata:e}){if(!e)return null;let r=zY(e.timings_ms?.total_before_cleanup),a=VY(e.console_errors)+VY(e.page_errors)+VY(e.failed_requests)+VY(e.bad_responses);return n(`div`,{className:`grid gap-2 border-b p-3 text-xs`,children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.ok!==void 0&&t(i,{variant:e.ok?`success`:`destructive`,children:e.ok?`render ok`:`render failed`}),e.dependencies_reused!==void 0&&n(i,{variant:e.dependencies_reused?`info`:`secondary`,children:[`deps `,e.dependencies_reused?`reused`:`installed`]}),e.status&&n(i,{variant:`secondary`,children:[`HTTP `,e.status]}),a>0&&n(i,{variant:`attention`,children:[a,` browser issue(s)`]})]}),n(`div`,{className:`grid gap-1 text-muted sm:grid-cols-2`,children:[e.viewport?.width&&e.viewport.height&&n(`div`,{children:[`Viewport `,e.viewport.width,` x `,e.viewport.height]}),BY(r)&&n(`div`,{children:[`Total `,BY(r)]}),e.rendered_at&&n(`div`,{children:[`Rendered `,new Date(e.rendered_at).toLocaleString()]}),e.title&&n(`div`,{className:`truncate`,children:[`Title `,e.title]})]}),typeof e.error==`string`&&t(`div`,{className:`text-destructive`,children:e.error})]})}function KY({context:e}){let{client:r}=q(),a=e.source.artifact,o=a?.path||e.source.sourcePath,s=!!a,c=e.content||``,[l,u]=G({isLoading:!1}),d=V(async(e,t)=>a?(await r.files.getArtifactDownloadUrl(a.runId,e,t)).url:(await r.files.getDownloadUrl(e,LY(e),t)).url,[a,r]);return H(()=>{if(!o){u({isLoading:!1,previewError:`No source path is available for this TSX artifact.`});return}let e=o,t=!1,n=IY(e,`.png`),r=IY(e,`.render.json`);async function i(){u({isLoading:!0});let i,a,o=n;try{i=HY(await UY(await d(r,`inline`),LY(r))),o=WY({metadata:i,sourcePath:e,fallbackPath:n,artifactMode:s})}catch(e){a=e instanceof Error?e.message:`Render metadata is not available`}let c,l;try{c=await d(o,`inline`)}catch(e){l=e instanceof Error?e.message:`Sandbox render image is not available`}t||u({isLoading:!1,imageUrl:c,metadata:i,metadataError:a,previewError:l})}return i(),()=>{t=!0}},[s,d,o]),n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex min-h-10 flex-wrap items-center gap-2 border-b px-3 py-2 text-sm`,children:[t(O_,{className:`size-4 text-info`}),t(`span`,{className:`font-medium`,children:`Sandbox render`}),l.isLoading?t(i,{variant:`secondary`,children:`loading`}):l.imageUrl?t(i,{variant:`success`,children:`PNG preview`}):t(i,{variant:`attention`,children:`source only`}),l.metadata?.rendered_at&&t(`span`,{className:`text-xs text-muted`,children:new Date(l.metadata.rendered_at).toLocaleString()})]}),l.isLoading?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(tv,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading sandbox render...`})]}):l.imageUrl?n(`div`,{className:`grid min-h-0 flex-1 xl:grid-cols-[minmax(0,1fr)_minmax(24rem,0.7fr)]`,children:[t(`div`,{className:`flex min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:l.imageUrl,alt:`${e.fileName} sandbox render`,className:`max-h-full max-w-full rounded-md object-contain`})}),n(`div`,{className:`min-h-0 overflow-auto border-t xl:border-s xl:border-t-0`,children:[t(GY,{metadata:l.metadata}),t(`div`,{className:`p-3`,children:t(NY,{content:c,extension:e.extension})})]})]}):n(`div`,{className:`grid min-h-0 flex-1 grid-rows-[auto_minmax(0,1fr)]`,children:[n(`div`,{className:`border-b px-3 py-2 text-xs text-muted`,children:[`No sandbox-rendered PNG was found for this TSX artifact. Showing the source without executing it in Studio.`,l.previewError&&n(`span`,{className:`ms-1`,children:[`Preview lookup: `,l.previewError]}),!l.previewError&&l.metadataError&&n(`span`,{className:`ms-1`,children:[`Metadata lookup: `,l.metadataError]})]}),n(`div`,{className:`min-h-0 overflow-auto p-3`,children:[t(GY,{metadata:l.metadata}),t(NY,{content:c,extension:e.extension})]})]})]})}function qY({source:e,className:r,bodyClassName:i,renderers:a=[],converters:s=[],resolveUrl:c,loadText:l,createRendition:u,markdownComponents:d,showHeader:f=!1,onDownload:p}){let{client:m}=q(),h=U(()=>CY(e),[e]),g=U(()=>wY(h),[h]),[_,v]=G(e.url),[y,b]=G(e.content),[x,S]=G(null),[C,w]=G(!1),[T,E]=G(null),[D,O]=G(0),k=[e.id,e.title,e.fileName,e.contentType,e.url,e.sourcePath,e.content,e.artifact?.runId,e.artifact?.path].join(`\0`),A=V(async(e,t)=>e.url?e.url:e.artifact?(await m.files.getArtifactDownloadUrl(e.artifact.runId,e.artifact.path,t)).url:e.sourcePath?(await m.files.getDownloadUrl(e.sourcePath,e.fileName,t)).url:``,[m]),j=c||A,M=V(async e=>{if(e.content!==void 0)return e.content;let t=await j(e,`inline`);if(!t)return``;let n=await fetch(t);if(!n.ok)throw Error(`Failed to load ${CY(e)}: ${n.statusText}`);return n.text()},[j]),N=l||M,P={source:e,fileName:h,extension:g,contentType:e.contentType||x?.contentType,url:x?.url||_,content:x?.content||y,isLoading:C,error:T,reload:()=>O(e=>e+1)},F=a.find(e=>e.canRender(P)),I=!F&&(EY(P)||OY(P)||kY(P)||AY(P)),L=!F&&(TY(P)||DY(P)),ee={source:e,fileName:h,extension:g,contentType:e.contentType,target:`pdf`},R=!F&&!P.url?s.find(e=>e.target===`pdf`&&e.canConvert(ee)):void 0,te=!F&&!P.url&&(MY(P)||!!R)&&(!!R||!!u);H(()=>{let t=!1,n=e;E(null),v(n.url),b(n.content),S(null);async function r(){if(!(!I&&!L&&!te)){w(!0);try{if(te){let e=R?await R.convert({source:n,fileName:h,extension:g,contentType:n.contentType,target:`pdf`}):await u?.(n,`pdf`);t||S(e??null);return}if(I){let e=await N(n);t||b(e);return}if(L){let e=await j(n,`inline`);t||v(e)}}catch(e){t||E(e instanceof Error?e.message:`Failed to load document`)}finally{t||w(!1)}}}return r(),()=>{t=!0}},[u,g,h,N,te,I,L,D,j,R,e,k]);let ne={...P,url:x?.url||_,content:x?.content||y,contentType:x?.contentType||e.contentType,isLoading:C,error:T},re;return re=C?n(`div`,{className:`flex h-full min-h-64 items-center justify-center gap-2 text-muted`,children:[t(tv,{className:`size-5 animate-spin`}),t(`span`,{className:`text-sm`,children:`Loading preview...`})]}):T?n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-destructive`,children:[t(jh,{className:`size-7`}),t(`span`,{className:`max-w-xl text-center text-sm`,children:T}),t(o,{variant:`outline`,size:`sm`,onClick:ne.reload,children:`Retry`})]}):F?FY(F,ne):(TY(ne)||x?.contentType===`application/pdf`)&&ne.url?t(bY,{url:ne.url,className:`h-full`}):DY(ne)&&ne.url?t(`div`,{className:`flex h-full min-h-0 items-center justify-center overflow-auto bg-muted/10 p-3`,children:t(`img`,{src:ne.url,alt:h,className:`max-h-full max-w-full rounded-md object-contain`})}):EY(ne)?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none px-5 py-4`,children:t(Nt,{artifactRunId:e.artifact?.runId,components:d,children:ne.content||``})}):OY(ne)?t(`iframe`,{title:h,className:`h-full min-h-96 w-full bg-white`,sandbox:``,srcDoc:ne.content||``}):kY(ne)?t(`div`,{className:`px-4 py-2`,children:t(Rt,{xml:ne.content||``,collapsible:!0})}):jY(ne)?t(KY,{context:ne}):AY(ne)?t(NY,{content:ne.content,extension:g}):MY(ne)&&!R&&!u?t(PY,{message:`This file needs a PDF rendition before it can be previewed.`}):t(PY,{message:`Preview is not available for this file type.`}),n(`div`,{className:z(`flex h-full min-h-0 flex-col overflow-hidden`,r),children:[f&&n(`div`,{className:`flex min-h-10 items-center justify-between gap-3 border-b py-2 ps-3 pe-16`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate text-sm font-medium`,title:h,children:h}),ne.contentType&&t(`div`,{className:`truncate text-xs text-muted`,children:ne.contentType})]}),p&&t(o,{variant:`outline`,size:`sm`,onClick:()=>p(e),children:`Download`})]}),t(`div`,{className:z(`min-h-0 flex-1 overflow-auto`,i),children:re})]})}var JY=Y((()=>{Q(),xY()}));Q();const YY=ot.lazy(async()=>({default:(await Promise.resolve().then(()=>(JY(),SY))).UniversalDocumentViewer})),XY=new Set([`md`,`markdown`,`mdx`,`txt`]);function ZY(e){let t=e.split(`.`).pop()?.toLowerCase();return t!==void 0&&XY.has(t)}function QY(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function $Y({node:e,depth:r,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l=!1}){let{t:u}=K(),[d,f]=G(!1),p=l||d;if(e.isDirectory)return n(`div`,{className:`min-w-0`,children:[n(o,{variant:`unstyled`,className:`flex w-full max-w-full items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>f(e=>!e),"aria-expanded":p,children:[p?t(ih,{className:`size-3.5 shrink-0 text-muted`}):t(uh,{className:`size-3.5 shrink-0 text-muted cn-rtl-flip`}),t(p?i_:s_,{className:`size-4 shrink-0 text-info`}),t(`span`,{className:`min-w-0 truncate font-medium`,title:e.path,children:QY(e.name)})]}),p&&e.children.map(e=>t($Y,{node:e,depth:r+1,runId:i,onOpen:a,onDownload:s,downloadingPath:c,forceExpanded:l},`${i}:${e.path}`))]});let m=c===e.path;return n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[n(o,{variant:`unstyled`,className:`flex min-w-0 flex-1 items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,style:{paddingInlineStart:`${r*14+4}px`},onClick:()=>a(e.path),title:e.path,children:[t(`span`,{className:`size-3.5 shrink-0`}),t(Qg,{className:`size-4 shrink-0 text-muted`}),t(`span`,{className:`min-w-0 truncate`,children:e.name})]}),t(o,{variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>s(e.path),disabled:m,"aria-label":u(`agent.download`),title:u(`agent.download`),children:m?t(tv,{className:`size-3.5 animate-spin text-info`}):t(Sg,{className:`size-3.5`})})]})}function eX(e){return e.reduce((e,t)=>t.isDirectory?e+eX(t.children):e+1,0)}function tX(e,t){let n=t.trim().toLocaleLowerCase();return n?e.flatMap(e=>{let t=`${e.name} ${e.path}`.toLocaleLowerCase().includes(n);if(!e.isDirectory)return t?[e]:[];let r=tX(e.children,n);return t?[{...e}]:r.length>0?[{...e,children:r}]:[]}):e}function nX(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.rel=`noopener noreferrer`,n.style.display=`none`,document.body.appendChild(n),n.click(),n.remove()}function rX(e){switch(e.split(`.`).pop()?.toLowerCase()){case`css`:return`text/css`;case`gif`:return`image/gif`;case`htm`:case`html`:return`text/html`;case`jpeg`:case`jpg`:return`image/jpeg`;case`json`:return`application/json`;case`md`:case`markdown`:return`text/markdown`;case`pdf`:return`application/pdf`;case`png`:return`image/png`;case`svg`:return`image/svg+xml`;case`ts`:case`tsx`:return`text/typescript`;case`txt`:return`text/plain`;case`webp`:return`image/webp`;default:return}}function iX({runId:e,path:r,onBack:i,onDownload:a,refreshKey:s,refreshDetails:c,onSendMessage:l}){let{t:u}=K(),[d,f]=G(`components`),[p,m]=G(`idle`);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-2 py-1`,children:[t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:i,"aria-label":u(`agent.backToArtifacts`),title:u(`agent.backToArtifacts`),children:t(Tm,{className:`size-4 cn-rtl-flip`})}),n(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[t(`span`,{className:`truncate text-sm font-medium`,title:r,children:r.split(`/`).pop()}),p===`saving`?t(We,{description:u(`agent.savingWorkingCopy`),asChild:!0,children:t(tv,{className:`size-3.5 shrink-0 animate-spin text-muted`,"aria-label":u(`agent.savingWorkingCopy`)})}):p===`saved`?t(We,{description:u(`agent.savedToWorkingCopy`),asChild:!0,children:t(th,{className:`size-3.5 shrink-0 text-success`,"aria-label":u(`agent.savedToWorkingCopy`)})}):null]}),n(`div`,{className:`flex items-center gap-0.5`,children:[t(o,{variant:d===`components`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`components`),"aria-label":u(`agent.blockMode`),"aria-pressed":d===`components`,title:u(`agent.blockMode`),children:t(Sy,{className:`size-4`})}),t(o,{variant:d===`document`?`primary`:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>f(`document`),"aria-label":u(`agent.editMode`),"aria-pressed":d===`document`,title:u(`agent.editMode`),children:t(Yv,{className:`size-4`})})]}),t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:()=>a(r),"aria-label":u(`agent.download`),title:u(`agent.download`),children:t(Sg,{className:`size-4`})})]}),t(wt,{runId:e,path:r,viewMode:d,refreshKey:s,refreshDetails:c,readOnly:!l,onAction:e=>{if(!l)return;let t=e.anchor.block_type.replaceAll(`_`,` `);l(e.comment?.trim()||u(`agent.editedSelectionMessage`,{blockType:t}),{editing_action:e})},onSaveStatusChange:m,onSendMessage:l?e=>l(e):void 0,className:z(`relative min-h-0 flex-1`,d===`document`?`overflow-hidden`:`overflow-y-auto px-6 py-5`)})]})}function aX({icon:e,children:r,action:i}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r}),i]})}function oX({runId:r,refreshKey:i=0,refreshDetails:a,selectedPath:s,onSelectedPathChange:c,onSendMessage:l}){let{t:u}=K(),{client:d}=q(),[f,m]=G(!1),{tree:h,flatFiles:g,totalCount:_,systemHiddenCount:v,isLoading:y,error:b,refresh:x}=YJ(d,r,i,f),[S,C]=G(null),[w,T]=G(null),[E,D]=G(``),[O,k]=G(null),A=s===void 0?O:s,j=V(e=>{s===void 0&&k(e),c?.(e)},[c,s]),N=E.trim(),P=U(()=>tX(h,N),[h,N]),F=U(()=>eX(P),[P]),I=vt(),L=V(async e=>{if(r){C(e);try{let{url:t}=await d.files.getArtifactDownloadUrl(r,e,`attachment`);nX(t,e.split(`/`).pop()||`artifact`)}catch(e){console.error(`Failed to get artifact download URL:`,e)}finally{C(null)}}},[d,r]),ee=V(e=>{if(ZY(e)){j(e);return}T(e)},[j]),R=r&&w?{title:w.split(`/`).pop()||w,fileName:w.split(`/`).pop()||w,contentType:rX(w),artifact:{runId:r,path:w}}:null;return r?y&&_===0?t(aX,{icon:t(tv,{className:`mb-2 size-6 animate-spin`}),children:u(`agent.loadingArtifacts`)}):b?t(`div`,{className:`flex flex-col items-center justify-center p-4 text-muted w-full`,children:n(M,{title:`Fail to load Artifacts`,className:`w-full`,action:x,actionLabel:n(e,{children:[t(gy,{className:`size-3.5 me-1.5`}),u(`agent.retry`)]}),children:[t(`span`,{className:`break-all text-muted`,children:b}),` `,t(`br`,{})]})}):_===0?t(aX,{icon:t(Lv,{className:`mb-2 size-8`}),action:n(o,{variant:`ghost`,size:`sm`,className:`mt-2`,onClick:x,children:[t(gy,{className:`size-3.5 me-1.5`}),u(`agent.refresh`)]}),children:u(`agent.noArtifactsYet`)}):A?t(iX,{runId:r,path:A,refreshKey:i,refreshDetails:a,onBack:()=>j(null),onDownload:e=>void L(e),onSendMessage:l}):n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[n(`div`,{className:`flex items-center justify-between gap-2 text-xs text-muted`,children:[n(`span`,{children:[N?`${F} of ${g.length} file${g.length===1?``:`s`}`:`${g.length} file${g.length===1?``:`s`}`,!f&&v>0?` · ${v} hidden`:``]}),n(`div`,{className:`flex items-center gap-1`,children:[t(Ne,{size:`sm`,value:f,onChange:m,children:t(`span`,{className:`text-xs text-muted`,children:u(`agent.showSystemArtifacts`)})}),t(o,{variant:`ghost`,size:`sm`,onClick:x,disabled:y,className:`h-6 w-6 p-0`,children:t(gy,{className:`size-3.5 ${y?`animate-spin`:``}`})})]})]}),t(`label`,{htmlFor:I,className:`sr-only`,children:u(`form.filter`)}),t(te,{id:I,type:`text`,role:`searchbox`,autoComplete:`off`,placeholder:u(`store.searchPlaceholder`),value:E,onChange:D,clearable:!0})]}),t(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:P.length>0?t(`div`,{className:`min-w-0`,children:P.map(e=>t($Y,{node:e,depth:0,runId:r,onOpen:ee,onDownload:L,downloadingPath:S,forceExpanded:!!N},`${r}:${e.path}`))}):t(`div`,{className:`px-1 py-6 text-sm text-muted`,children:u(!f&&v>0?`agent.onlySystemArtifacts`:`agent.noContentAvailable`)})}),R&&n(se,{isOpen:!!w,onClose:()=>T(null),size:`xl`,className:`h-[90vh] p-0`,description:`Artifact preview`,children:[t(ue,{show:!1,children:R.fileName}),t(ce,{className:`h-full max-h-none p-0`,children:t(ot.Suspense,{fallback:t(p,{className:`h-full`,children:t(tv,{className:`size-6 animate-spin text-muted`})}),children:t(YY,{source:R,className:`h-full`,showHeader:!0,onDownload:()=>w&&void L(w)})})})]})]}):t(aX,{icon:t(Lv,{className:`mb-2 size-8`}),children:`No run selected`})}const sX=ot.memo(oX);Q();function cX(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function lX(e){if(!cX(e))return;let t=e.browseruse??e.browser_use;if(!cX(t))return;let n={widget:typeof t.widget==`string`?t.widget:void 0,browser_workflow_id:typeof t.browser_workflow_id==`string`?t.browser_workflow_id:void 0,workstream_id:typeof t.workstream_id==`string`?t.workstream_id:void 0,phase:typeof t.phase==`string`?t.phase:void 0,url:typeof t.url==`string`?t.url:void 0,title:typeof t.title==`string`?t.title:void 0,screenshot:typeof t.screenshot==`string`?t.screenshot:void 0,raw_screenshot:typeof t.raw_screenshot==`string`?t.raw_screenshot:void 0,prefer_raw_screenshot:typeof t.prefer_raw_screenshot==`boolean`?t.prefer_raw_screenshot:void 0,updated_at:typeof t.updated_at==`number`?t.updated_at:void 0};if(!(n.widget&&n.widget!==`browseruse`)&&!(!n.url&&!n.title&&!n.screenshot&&!n.raw_screenshot))return n}function uX(e){let t=new Map;for(let n of e){let e=lX(n.details);if(!e)continue;let r=e.workstream_id||n.workstream_id||`main`,i=e.updated_at??(typeof n.timestamp==`number`?n.timestamp:new Date(n.timestamp).getTime()),a=t.get(r);(!a||i>=a.timestamp)&&t.set(r,{state:{...e,workstream_id:r},timestamp:i})}return new Map(Array.from(t.entries()).map(([e,t])=>[e,t.state]))}function dX(e){return e.replace(/^artifact:\/\//,``).replace(/^artifact:/,``).replace(/^\/+/,``)}function fX(e){return e?e.replace(/_/g,` `):`browser`}function pX({state:e,runId:r,className:a,compact:o}){let{t:s}=K(),{client:c}=q(),l=HS(),{openImage:u}=TW(),[d,f]=G(),p=e.prefer_raw_screenshot===!1?e.screenshot||e.raw_screenshot:e.raw_screenshot||e.screenshot,m=e.title||e.url||s(`agent.browserUse`),h=U(()=>p&&dX(p).split(`/`).pop()||s(`agent.browserScreenshot`),[p,s]);return H(()=>{if(!p){f(void 0);return}if(p.startsWith(`http://`)||p.startsWith(`https://`)){f(p);return}if(!r){f(void 0);return}let e=!1;return(async()=>{let t=dX(p);try{let n=WS(r,t,`inline`),i=l?await l.getOrFetch(n,async()=>(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url):(await c.files.getArtifactDownloadUrl(r,t,`inline`)).url;e||f(i)}catch(n){console.error(`Failed to resolve browser screenshot ${t}`,n),e||f(void 0)}})(),()=>{e=!0}},[c,r,p,l]),o?n(`div`,{className:z(`overflow-hidden rounded-md border border-border/70 bg-transparent`,a),children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1.5`,children:[t(Pv,{className:`size-3.5 shrink-0 text-info`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[t(`span`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserPreview`)}),e.phase&&n(`span`,{className:`truncate text-[11px] capitalize text-muted`,children:[`· `,fX(e.phase)]})]}),t(`div`,{className:`truncate text-[11px] text-muted`,title:m,children:m})]}),e.url&&t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:z(`inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md`,`text-muted hover:bg-muted hover:text-foreground`),children:t(Og,{className:`size-3`})})]}),p&&(d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-32 w-full object-contain`})}):n(`div`,{className:`flex min-h-16 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-4 text-xs text-muted`,children:[t(O_,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}))]}):n(`div`,{className:z(`overflow-hidden rounded-md border border-muted bg-mixer-muted/10`,a),children:[n(`div`,{className:`flex items-start justify-between gap-2 border-b border-muted px-2.5 py-2`,children:[n(`div`,{className:`flex min-w-0 items-start gap-2`,children:[t(Pv,{className:`mt-0.5 size-4 shrink-0 text-info`}),n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-xs font-medium text-foreground`,children:s(`agent.browserUse`)}),t(`div`,{className:`truncate text-xs text-muted`,title:m,children:m})]})]}),t(i,{variant:`info`,className:`shrink-0 capitalize`,children:fX(e.phase)})]}),d?t(`button`,{type:`button`,className:`block w-full bg-mixer-muted/20 text-start`,onClick:()=>u(d,h),title:s(`agent.clickToEnlarge`),children:t(`img`,{src:d,alt:h,className:`block max-h-56 w-full object-contain`})}):n(`div`,{className:`flex min-h-28 items-center justify-center gap-2 bg-mixer-muted/20 px-3 py-6 text-xs text-muted`,children:[t(O_,{className:`size-4`}),t(`span`,{children:s(`agent.browserScreenshotPending`)})]}),e.url&&n(`div`,{className:`flex items-center gap-2 border-t border-muted px-2.5 py-1.5`,children:[t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`min-w-0 flex-1 truncate text-xs text-info hover:underline`,title:e.url,children:e.url}),t(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,title:s(`agent.openInNewTab`),className:z(`inline-flex h-6 shrink-0 items-center justify-center rounded-md px-1.5`,`text-muted hover:bg-muted hover:text-foreground`),children:t(Og,{className:`size-3`})})]})]})}Q();function mX({documentId:e,title:r,onBack:i,onUpdateDocumentTitle:a,refreshKey:s,runId:c}){let{client:l}=q(),{t:u}=K(),[d,f]=G(null),[p,m]=G(!1),[h,g]=G(null),[_,v]=G(null),y=V(async e=>{m(!0),g(null);try{let[t,n]=await Promise.all([l.store.objects.getObjectText(e),l.store.objects.retrieve(e)]);f(t.text??null);let r=n.name;v(r),r&&a?.(e,r)}catch(e){let t=e instanceof Error?e.message:u(`agent.failedToLoadDocument`);g(t),f(null)}finally{m(!1)}},[l,a,u]);return H(()=>{y(e)},[e,s,y]),n(`div`,{className:`h-full overflow-hidden flex flex-col`,children:[n(`div`,{className:`flex items-center justify-between gap-1 px-2 py-1 border-b border-border/60 shrink-0`,children:[t(o,{variant:`ghost`,size:`sm`,className:`size-8 shrink-0 rounded-md p-0`,onClick:i,"aria-label":u(`agent.backToDocuments`),title:u(`agent.backToDocuments`),children:t(Tm,{className:`size-4 cn-rtl-flip`})}),n(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[t(Kg,{className:`size-4 text-muted shrink-0`}),t(`span`,{className:`truncate text-sm font-medium`,title:_||r,children:_||r||u(`agent.document`)})]}),n(Qn,{href:`/store/objects/${e}#overview`,topLevelNav:!0,className:`inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted hover:bg-muted/20 hover:text-foreground`,children:[t(We,{description:u(`agent.openDocument`),placement:`top`,size:`xs`,asChild:!0,children:t(Og,{className:`size-4`,"aria-hidden":`true`})}),t(`span`,{className:`sr-only`,children:u(`agent.openDocument`)})]})]}),t(`div`,{className:`flex-1 overflow-y-auto px-4 py-4`,children:p?n(`div`,{className:`flex items-center justify-center py-12`,children:[t(tv,{className:`size-5 animate-spin text-muted`}),t(`span`,{className:`ms-2 text-sm text-muted`,children:u(`agent.loadingDocument`)})]}):h?t(`div`,{className:`p-4 rounded-md bg-destructive/10 text-destructive text-sm`,children:h}):d?t(`div`,{className:`prose prose-sm dark:prose-invert max-w-none`,children:t(Nt,{artifactRunId:c,children:d})}):n(`div`,{className:`flex flex-col items-center justify-center py-12 text-muted`,children:[t(Kg,{className:`size-8 mb-2`}),t(`span`,{className:`text-sm`,children:u(`agent.noContentAvailable`)})]})})]})}const hX=ot.memo(mX);Q();function gX({documents:r,activeDocumentId:i,onSelectDocument:a,onUpdateDocumentTitle:s,refreshKey:c,runId:l}){let{t:u}=K(),[d,f]=G(``),p=vt(),m=d.trim().toLocaleLowerCase(),h=U(()=>m?r.filter(e=>e.title.toLocaleLowerCase().includes(m)):r,[r,m]),g=V(()=>a(null),[a]),_=i?r.find(e=>e.id===i):void 0;return i?t(hX,{documentId:i,title:_?.title,onBack:g,onUpdateDocumentTitle:s,refreshKey:c,runId:l}):n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[t(`span`,{className:`text-xs text-muted`,children:m?u(`agent.documentsFiltered`,{visible:h.length,total:r.length}):u(`agent.documentCount`,{count:r.length})}),r.length>5&&n(e,{children:[t(`label`,{htmlFor:p,className:`sr-only`,children:u(`form.filter`)}),t(te,{id:p,type:`text`,role:`searchbox`,autoComplete:`off`,placeholder:u(`store.searchPlaceholder`),value:d,onChange:f,clearable:!0})]})]}),t(`div`,{className:`flex-1 overflow-y-auto px-3 py-2`,children:h.length>0?t(`div`,{className:`min-w-0`,children:h.map(e=>n(`div`,{className:`flex min-w-0 items-center gap-1`,children:[n(o,{variant:`unstyled`,className:`flex min-w-0 flex-1 items-center justify-start gap-1.5 rounded px-1 py-1 text-start text-sm hover:bg-muted/30`,onClick:()=>a(e.id),title:e.title,children:[t(Kg,{className:`size-4 shrink-0 text-muted`}),t(`span`,{className:`min-w-0 truncate`,children:e.title})]}),n(Qn,{href:`/store/objects/${e.id}#overview`,topLevelNav:!0,className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-muted hover:bg-muted/20 hover:text-foreground`,children:[t(We,{description:u(`agent.openDocument`),placement:`top`,size:`xs`,asChild:!0,children:t(Og,{className:`size-3.5`,"aria-hidden":`true`})}),t(`span`,{className:`sr-only`,children:u(`agent.openDocument`)})]})]},e.id))}):t(`div`,{className:`px-1 py-6 text-sm text-muted`,children:u(`agent.noMatchingDocuments`)})})]})}const _X=ot.memo(gX);Q();function vX({plan:e,workstreamStatus:r,isOpen:i,onClose:a,plans:s=[],activePlanIndex:c=0,onChangePlan:l=()=>{}}){let{t:u}=K();if(!i)return null;let d=e.plan||[],f=d.length,m=d.reduce((e,t)=>t?.id&&(r.get(t.id.toString())===`completed`||t.status===`completed`)?e+1:e,0),h=f>0?Math.round(m/f*100):0,g=s.length>0?s.length-c:1,_=s[c]?.timestamp;return d.length===0?t(`div`,{className:`h-full overflow-hidden`,children:n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[t(tg,{className:`mb-2 size-8`}),t(`span`,{className:`text-sm`,children:u(`agent.noPlanAvailable`)})]})}):t(`div`,{className:`h-full overflow-hidden`,children:n(`div`,{className:`flex h-full flex-col gap-4 overflow-y-auto px-2 py-3`,children:[n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex items-start justify-between gap-3`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`text-sm font-medium text-foreground`,children:u(`agent.taskProgress`)}),t(`div`,{className:`text-xs text-muted`,children:u(`agent.tasksCompleted`,{completed:m,total:f})})]}),s.length>1&&n(`div`,{className:`flex shrink-0 items-center gap-1 text-xs text-muted`,children:[t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.min(s.length-1,c+1)),disabled:c>=s.length-1,"aria-label":u(`agent.olderPlan`),title:u(`agent.olderPlan`),children:t(sh,{className:`size-4`,"aria-hidden":`true`})}),n(`div`,{className:`min-w-20 text-center`,children:[n(`div`,{className:`font-medium text-foreground`,children:[g,`/`,s.length]}),t(`div`,{className:`truncate`,children:_?new Date(_).toLocaleTimeString():u(`agent.unknownTime`)})]}),t(o,{variant:`ghost`,size:`icon`,className:`size-7`,onClick:()=>l(Math.max(0,c-1)),disabled:c<=0,"aria-label":u(`agent.newerPlan`),title:u(`agent.newerPlan`),children:t(uh,{className:`size-4`,"aria-hidden":`true`})})]})]}),t(`div`,{className:`h-2 overflow-hidden rounded-full bg-mixer-muted/20`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":f,"aria-valuenow":m,"aria-label":u(`agent.taskProgress`),children:t(`div`,{className:`h-full rounded-full bg-success transition-all duration-300`,style:{width:`${h}%`}})})]}),t(`ol`,{className:`divide-y divide-border/60`,children:d.map((e,i)=>{let a=e.id?e.id.toString():`task-${i}`,o=e.goal||`Task ${i+1}`,s=e.id?`task-${e.id.toString()}`:`task-${o}-${e.status||`pending`}`,c=e.status||`pending`,l=r.get(a);l!==void 0&&(c=l);let d=Yh,f=`text-muted`;c===`in_progress`?(d=ig,f=`text-info`):c===`completed`&&(d=Ph,f=`text-success`);let p=u(c===`completed`?`agent.completed`:c===`in_progress`?`agent.inProgress`:`agent.pending`);return n(`li`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-start gap-3 px-1 py-3`,children:[t(`span`,{className:`mt-0.5 min-w-5 text-center text-xs font-medium tabular-nums text-muted/80`,children:a}),t(`span`,{className:`min-w-0 text-sm leading-5 text-foreground/85`,children:o}),n(`span`,{className:z(`flex items-center gap-1.5 text-xs font-medium`,f),children:[t(d,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),t(`span`,{children:p})]})]},s)})}),(()=>{let e=new Set(d.filter(e=>e?.id).map(e=>e.id.toString())),i=Array.from(r.entries()).filter(([t])=>t!==`main`&&!e.has(t));return i.length>0?n(`div`,{className:`mt-1 px-1 py-2`,children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:u(`agent.workstreams`)}),t(`div`,{className:`divide-y divide-border/60`,children:i.map(([e,r])=>{let i=Yh,a=`text-muted`,o=u(`agent.pending`);return r===`in_progress`?(i=ig,a=`text-info`,o=u(`agent.inProgress`)):r===`completed`&&(i=Ph,a=`text-success`,o=u(`agent.completed`)),n(`div`,{className:`flex items-center gap-2 py-2`,children:[t(i,{className:z(`size-3.5 shrink-0`,a)}),t(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium text-foreground/80`,children:e}),t(`span`,{className:`text-xs font-medium text-muted`,children:o})]},e)})})]}):null})()]})})}const yX=ot.memo(vX);Q();function bX({icon:e,children:r}){return n(p,{className:`h-full min-h-[240px] flex-col text-center text-muted`,children:[e,t(`span`,{className:`text-sm`,children:r})]})}function xX({files:e}){let{t:r}=K(),a=U(()=>e?Array.from(e.values()):[],[e]),o=e=>{switch(e){case mn.UPLOADING:case mn.PROCESSING:return t(tv,{className:`size-4 animate-spin text-info`});case mn.READY:return t(Ph,{className:`size-4 text-success`});case mn.ERROR:return t(Kh,{className:`size-4 text-destructive`});default:return t(Kg,{className:`size-4 text-muted`})}},s=e=>{switch(e){case mn.UPLOADING:return t(i,{variant:`info`,children:r(`agent.uploading`)});case mn.PROCESSING:return t(i,{variant:`info`,children:r(`agent.processing`)});case mn.READY:return t(i,{variant:`success`,children:r(`agent.ready`)});case mn.ERROR:return t(i,{variant:`destructive`,children:r(`agent.error`)});default:return null}};return t(`div`,{className:`h-full min-h-0`,children:a.length===0?t(bX,{icon:t(Kg,{className:`mb-2 size-8`}),children:r(`agent.noFilesUploadedYet`)}):t(`div`,{className:`space-y-2 p-2`,children:a.map(e=>n(`div`,{className:`flex items-start gap-2 p-2 border border-muted rounded-md`,children:[t(`div`,{className:`mt-0.5`,children:o(e.status)}),n(`div`,{className:`flex-1 min-w-0`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`span`,{className:`text-sm font-medium truncate`,children:e.name}),s(e.status)]}),e.error&&t(`div`,{className:`text-xs text-destructive mt-1`,children:e.error})]})]},e.id))})})}var SX=class extends ot.Component{state={hasError:!1};static getDerivedStateFromError(e){return{hasError:!0,message:e instanceof Error?e.message:String(e)}}componentDidCatch(e,t){console.error(`Agent right panel section failed to render`,{error:e,componentStack:t.componentStack})}render(){return this.state.hasError?n(`div`,{className:z(`rounded-md border border-destructive bg-mixer-destructive/10 text-destructive`,this.props.compact?`p-2 text-xs`:`m-3 p-3 text-sm`),children:[t(`div`,{className:`font-medium`,children:this.props.title}),t(`div`,{className:`mt-1 text-xs text-muted`,children:this.props.description}),this.state.message&&t(`div`,{className:`mt-1 break-all text-[11px] text-muted`,children:this.state.message})]}):this.props.children}};function CX({workstreams:e,messages:r,runId:a}){let{t:s}=K(),{client:c}=q(),l=nt(),u=U(()=>uX(r),[r]),d=s(`agent.panelRenderErrorDescription`),f=V(e=>{navigator.clipboard.writeText(e),l({status:`success`,title:s(`agent.runIdCopied`),duration:2e3})},[s,l]),p=V(async e=>{try{let t=await rU(c,e);t&&window.open(t,`_blank`)}catch{l({status:`error`,title:s(`agent.failedToDownload`)})}},[c,s,l]);return e.length===0?t(bX,{icon:t(B_,{className:`mb-2 size-8`}),children:s(`agent.noActiveParallelTasks`)}):n(`div`,{className:`h-full min-h-0 overflow-y-auto px-2 py-2`,children:[t(`div`,{className:`px-1 pb-2 text-xs text-muted`,children:s(`agent.parallelWorkDescription`)}),t(`div`,{className:`divide-y divide-border/60`,children:e.map(e=>{let r=e.status===`running`||e.status===`canceling`,c=Math.round(e.elapsed_ms/1e3),l=Math.max(0,Math.round(e.remaining_ms/1e3)),m=e.deadline_ms>0?Math.min(100,Math.round(e.elapsed_ms/e.deadline_ms*100)):0,h=u.get(e.workstream_id),g=e.deadline_ms>0,_=e.child_workflow_run_id,v=[e.phase?MH(e.phase):void 0,c>0?s(`agent.elapsed`,{seconds:c}):void 0,g&&l>0?s(`agent.remaining`,{seconds:l}):void 0].filter(Boolean),y=(()=>{switch(e.status){case`running`:return t(i,{variant:`info`,children:s(`agent.running`)});case`canceling`:return t(i,{variant:`attention`,children:s(`agent.canceling`)});case`completed`:return t(i,{variant:`done`,children:s(`agent.completed`)});case`failed`:return t(i,{variant:`destructive`,children:s(`agent.failed`)});case`timeout`:return t(i,{variant:`destructive`,children:s(`agent.timeout`)});case`canceled`:return t(i,{variant:`destructive`,children:s(`agent.canceled`)})}})();return t(SX,{title:s(`agent.workstreamRenderError`),description:d,compact:!0,children:t(`div`,{className:`py-3`,children:n(`div`,{className:`flex items-start gap-2`,children:[t(`span`,{className:z(`mt-2 size-2 shrink-0 rounded-full`,BH(e.status)),"aria-hidden":`true`}),n(`div`,{className:`min-w-0 flex-1`,children:[n(`div`,{className:`flex min-w-0 items-center justify-between gap-2`,children:[t(`span`,{className:`min-w-0 truncate text-sm font-medium text-foreground`,title:e.workstream_id,children:MH(e.workstream_id)}),y]}),v.length>0&&t(`div`,{className:`mt-0.5 truncate text-xs text-muted`,children:v.join(` · `)}),r&&g&&t(`div`,{className:`mt-2 h-1 rounded-full bg-muted`,role:`progressbar`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":m,"aria-valuetext":s(`agent.workstreamProgress`,{percent:m}),children:t(`div`,{className:`h-full rounded-full bg-info transition-all duration-500`,style:{width:`${m}%`}})}),h&&t(SX,{title:s(`agent.browserWidgetRenderError`),description:d,compact:!0,children:t(pX,{state:h,runId:a,compact:!0,className:`mt-2`})}),_&&n(`div`,{className:`mt-2 flex flex-wrap gap-1`,children:[n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>f(_),children:[t(Qh,{className:`size-3 me-1`}),s(`agent.copyRunId`)]}),n(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-xs text-muted hover:text-foreground`,onClick:()=>p(_),children:[t(sg,{className:`size-3 me-1`}),s(`agent.download`)]})]})]})]})})},e.launch_id)})})]})}function wX({plan:e,workstreamStatus:r,plans:i=[],activePlanIndex:a=0,onChangePlan:s,activeWorkstreams:c=[],messages:l=[],hideWorkstreams:u=!1,openDocuments:d=[],activeDocumentId:f,onSelectDocument:p,onUpdateDocumentTitle:m,docRefreshKey:h=0,runId:g,processingFiles:_,showArtifacts:v=!1,artifactRefreshKey:y=0,artifactRefreshDetails:b,selectedArtifactPath:x,onSelectedArtifactPathChange:S,onSendMessage:C,payloadContent:w,conversationContent:T,onClose:E,defaultTab:D,activeTab:O,onTabChange:k}){let{t:A}=K(),[j,M]=G(D||`plan`),N=O??j,P=e=>{M(e),k?.(e)},F=!u&&c.length>0,I=d.length>0,L=_?_.size>0:!1,ee=V((e,n)=>t(SX,{title:A(`agent.panelRenderError`,{name:e}),description:A(`agent.panelRenderErrorDescription`),children:n}),[A]),R={name:`conversation`,label:`Conversation`,content:T?ee(`Conversation`,t(`div`,{className:`flex flex-col h-full min-h-0`,children:T})):null,is_allowed:!!T},te=[...T?[R]:[],{name:`plan`,label:A(`agent.plan`),content:ee(A(`agent.plan`),e?t(yX,{plan:e,workstreamStatus:r||new Map,isOpen:!0,onClose:E,plans:i,activePlanIndex:a,onChangePlan:s}):t(bX,{icon:t(B_,{className:`mb-2 size-8`}),children:A(`agent.noPlanAvailable`)})),is_allowed:!0},{name:`workstreams`,label:F?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[A(`agent.workstreams`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:c.length})]}):A(`agent.workstreams`),content:ee(A(`agent.workstreams`),t(CX,{workstreams:c,messages:l,runId:g})),is_allowed:!u},{name:`documents`,label:I?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[A(`agent.documents`),` `,t(`span`,{className:`inline-flex shrink-0 items-center justify-center rounded-full bg-info px-1.5 py-0.5 text-[10px] text-info`,children:d.length})]}):A(`agent.documents`),content:ee(A(`agent.documents`),d.length>0&&p?t(_X,{documents:d,activeDocumentId:f??null,onSelectDocument:p,onUpdateDocumentTitle:m,refreshKey:h,runId:g}):t(bX,{icon:t(Kg,{className:`mb-2 size-8`}),children:A(`agent.noDocumentsOpen`)})),is_allowed:!0},{name:`uploads`,label:L?n(`span`,{className:`inline-flex min-w-0 items-center gap-1 whitespace-nowrap`,children:[A(`agent.uploads`),` `,t(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-info`})]}):A(`agent.uploads`),content:ee(A(`agent.uploads`),t(xX,{files:_})),is_allowed:!0},{name:`artifacts`,label:A(`agent.artifacts`),content:ee(A(`agent.artifacts`),t(sX,{runId:g,refreshKey:y,refreshDetails:b,selectedPath:x,onSelectedPathChange:S,onSendMessage:C})),is_allowed:v},{name:`payload`,label:A(`agent.payload`),content:w?ee(A(`agent.payload`),t(`div`,{className:`overflow-y-auto`,children:w})):null,is_allowed:!!w}],ne=te.filter(e=>e.is_allowed===void 0||e.is_allowed===!0);return n(ze,{tabs:te,current:N,onTabChange:P,fullHeight:!0,className:`px-0`,children:[n(`div`,{className:`flex items-end justify-between shrink-0 px-1 py-1 gap-1`,children:[t(pe,{tabs:ne,current:N,onTabChange:P,className:`min-w-0 flex-1`}),!T&&t(o,{variant:`ghost`,size:`sm`,className:`shrink-0 ms-1`,onClick:E,title:`Close Right Panel`,children:t(Kb,{className:`size-4`})})]}),t(Ve,{className:`flex-1 min-h-0 pt-0 pb-0`})]})}const TX=ot.memo(wX);function EX(e){if(!e)return[];let t=[];for(let n=0;n<e.length;n++){let r=e[n];if(r.kind!==`file`)continue;let i=r.getAsFile();if(i){if(r.type.startsWith(`image/`)&&(!i.name||i.name===`image.png`)){let e=r.type.split(`/`)[1]||`png`;t.push(new File([i],`pasted-image-${Date.now()}.${e}`,{type:i.type}))}else t.push(i)}}return t}function DX(e,t,n=!1){let[r,i]=G([]),[a,o]=G(0),[s,c]=G(new Map),[l,u]=G(t),[d,f]=G(!n),p=W(-1),m=W(new Set);H(()=>{e.length===0&&(i([]),o(0),c(new Map),f(!n),p.current=-1,m.current.clear())},[e.length,n]);let h=V(e=>{let n=e[e.length-1];n&&(n.type===J.TERMINATED?u(!1):u(t?!0:n.type===J.REQUEST_INPUT))},[t]);return H(()=>{if(e.length===0)return;let t=p.current+1;if(t>=e.length){h(e);return}let n=!1,r=[],a=[];for(let i=t;i<e.length;i++){let t=e[i];if(t.type===J.PLAN)try{let e=null;if(t.details&&typeof t.details==`object`&&t.details.plan&&Array.isArray(t.details.plan)&&(e={plan:t.details.plan}),e){let i=typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime();if(!m.current.has(i)){m.current.add(i),n=!0,r.push({plan:e,timestamp:i});let t=new Map;t.set(`main`,`in_progress`),Array.isArray(e.plan)&&e.plan.forEach(e=>{if(e&&typeof e==`object`&&e.id){let n=e.id.toString();t.set(n,e.status||`pending`)}}),a.push({timestamp:i,statusMap:t})}}}catch(e){console.error(`Failed to parse plan from message:`,e)}}p.current=e.length-1,n&&r.length>0&&(i(e=>[...[...r].reverse(),...e]),o(0),f(!0),a.length>0&&c(e=>{let t=new Map(e);for(let e of a)t.set(e.timestamp,e.statusMap);return t})),h(e)},[e,h]),H(()=>{if(r.length===1&&!d&&!sessionStorage.getItem(`plan-panel-shown`)){let e=setTimeout(()=>{f(!0),sessionStorage.setItem(`plan-panel-shown`,`true`)},500);return()=>clearTimeout(e)}},[r.length,d]),{plans:r,activePlanIndex:a,setActivePlanIndex:o,workstreamStatusMap:s,showInput:l,showSlidingPanel:d,setShowSlidingPanel:f}}function OX(e,t){return{...e,details:{...e.details??{},_deliveryStatus:t}}}function kX(e){let t=e.details,n=t?._messageId;if(typeof n==`string`&&n)return n;let r=t?.ack;return typeof r==`string`&&r?r:void 0}function AX(e,t){let n=e?.[t];return typeof n==`string`&&n?n:void 0}function jX(e){return e?.streaming_id_scope===`workflow_run`}function MX(e){return[J.COMPLETE,J.IDLE,J.TERMINATED,J.REQUEST_INPUT].includes(e.type)}function NX(e){if(e.type===J.STREAMING_CHUNK)return!1;if(e.type===J.UPDATE&&typeof e.details?.event_class==`string`)return!0;if(e.type===J.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files)return!1}return!!e.message||MX(e)||On(e).length>0}function PX(e){if(e)return{type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,text:typeof e.message==`string`?e.message.slice(0,80):e.message?`[non-string]`:``,display_role:e.details?.display_role,source:e.details?.source}}function FX(e,t){if(e.find(e=>e.timestamp===t.timestamp))return e;if(!t.details?._optimistic&&(t.type===J.QUESTION||ZH(t))){let n=typeof t.details?.ack==`string`?t.details.ack:void 0,r=n?OX(t,`consumed`):t;if(n){let i=e.filter(e=>!((e.type===t.type||ZH(e))&&e.details?._optimistic&&kX(e)===n));return qH(i,r),i}if(t.type===J.QUESTION){let n=e.filter(e=>e.type===J.QUESTION&&e.details?._optimistic&&e.message===t.message&&(e.workstream_id??`main`)===(t.workstream_id??`main`));if(n.length===1){let r=e.filter(e=>e!==n[0]);return qH(r,t),r}}}let n=[...e];return qH(n,t),n}function IX(e){let t=e.details,n=AX(t,`streaming_id`),r=AX(t,`activity_id`);return n&&jX(t)?n:r??n}function LX(e){let t=e.details,n=AX(t,`streaming_id`),r=AX(t,`activity_id`),i=[];return n&&jX(t)&&i.push(n),r&&i.push(r),[...new Set(i)]}function RX(e,t,n){let[r,i]=G([]),[a,o]=G(!1),[s,c]=G(`loading`),[l,u]=G(null),[d,f]=G(null),p=W(n);p.current=n;let[m,h]=G(new Map),[g,_]=G(0),v=V(()=>_(e=>e+1),[]),y=W(null),b=W(0),[x,S]=G(new Map),C=W(new Map),w=W(null),[T,E]=G(!1),D=W(null),O=V(()=>{let e=w.current;e&&(e.mode===`raf`?cancelAnimationFrame(e.id):clearTimeout(e.id),w.current=null)},[]),k=V(()=>{C.current.size>0&&(S(new Map(C.current)),E(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>E(!1),50)),w.current=null},[]);return H(()=>{o(!XH(r))},[r]),H(()=>{KH(`stream state`,{agentRunId:t,messageCount:r.length,streamingCount:x.size,initialHistoryStatus:s,isCompleted:a,lastDeliveredTs:b.current,first:PX(r[0]),last:PX(r[r.length-1])})},[t,s,a,r,x.size]),H(()=>{let n=y.current!==t;y.current=t,n&&(i([]),c(`loading`),u(null),f(null),S(new Map),h(new Map),b.current=0);let r=new AbortController,a=n?void 0:b.current||void 0;return KH(`stream start`,{agentRunId:t,isNewConversation:n,since:a,streamNonce:g}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(KH(`internals loaded`,{agentRunId:t,status:e.status,first_workflow_run_id:e.first_workflow_run_id}),u(e.status?.toUpperCase()??null),f(e.first_workflow_run_id??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to check agent run status:`,e)}),e.agents.streamMessages(t,e=>{if(r.signal.aborted)return;let n=!!(e.timestamp&&e.timestamp<=b.current);if(n||p.current?.(e),KH(`stream message`,{agentRunId:t,type:e.type,timestamp:e.timestamp,workstream_id:e.workstream_id,hasMessage:!!e.message,display_role:e.details?.display_role,source:e.details?.source}),e.timestamp&&e.timestamp>b.current&&(b.current=e.timestamp),e.type===J.STREAMING_CHUNK){let t=e.details,n=IX(e);if(!n)return;let r=C.current.get(n)||{text:``,workstreamId:e.workstream_id,startTimestamp:Date.now(),activityId:t?.activity_id,streamingId:t?.streaming_id},i=r.text+(e.message||``);C.current.set(n,{text:i,workstreamId:e.workstream_id,isComplete:t.is_final,startTimestamp:r.startTimestamp,activityId:t?.activity_id,streamingId:t?.streaming_id}),w.current===null&&(document.hidden?w.current={mode:`timeout`,id:window.setTimeout(k,16)}:w.current={mode:`raf`,id:requestAnimationFrame(k)});return}if(e.type===J.SYSTEM){let t=e.details;if(t?.system_type===`file_processing`&&t.files){n||h(new Map(t.files.map(e=>[e.id,e])));return}}if(e.type===J.THOUGHT||e.type===J.ANSWER){let t=LX(e);if(t.length>0){for(let e of t)C.current.delete(e);S(e=>{let n=new Map(e),r=!1;for(let e of t)r=n.delete(e)||r;return r?n:e})}}(e.type===J.COMPLETE||e.type===J.IDLE)&&C.current.size>0&&k(),NX(e)&&i(t=>FX(t,e))},a,r.signal,{closeOnIdle:!1,onHistoryLoaded:e=>{if(r.signal.aborted)return;let n=e.filter(NX),o,s=-1/0;for(let t of e)if(t.timestamp&&t.timestamp>b.current&&(b.current=t.timestamp),t.type===J.SYSTEM){let e=t.details;if(e?.system_type===`file_processing`&&e.files){let n=t.timestamp??-1/0;(!o||n>=s)&&(o=e,s=n)}}o&&h(new Map(o.files.map(e=>[e.id,e]))),KH(`history loaded`,{agentRunId:t,count:e.length,timelineCount:n.length,since:a,first:PX(e[0]),last:PX(e[e.length-1])}),c(e.length>0?`has_messages`:`empty`),n.length>0&&i(e=>n.reduce((e,t)=>FX(e,t),e))},onHistoryError:e=>{r.signal.aborted||(KH(`history error`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),c(`error`))}}).then(()=>{if(!r.signal.aborted)return KH(`stream resolved`,{agentRunId:t}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(KH(`internals refreshed after stream end`,{agentRunId:t,status:e.status}),u(e.status?.toUpperCase()??null))}).catch(e=>{r.signal.aborted||console.error(`Failed to refresh agent run status on stream end:`,e)})}).catch(e=>{r.signal.aborted||(KH(`stream failed`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),console.error(`Failed to stream agent messages:`,e))}),()=>{KH(`stream cleanup`,{agentRunId:t,streamNonce:g}),r.abort(),O(),C.current.clear(),D.current&&=(clearTimeout(D.current),null)}},[t,g,e.agents,k,O]),H(()=>{let e=()=>{!document.hidden&&C.current.size>0&&(O(),k())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[k,O]),{messages:r,streamingMessages:x,isCompleted:a,initialHistoryStatus:s,debugChunkFlash:T,addOptimisticMessage:V(e=>{i(t=>{let n=[...t,e];return n.sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),n})},[]),updateOptimisticMessageStatus:V((e,t)=>{i(n=>n.map(n=>n.details?._optimistic&&kX(n)===e?OX(n,t):n))},[]),removeOptimisticMessages:V(e=>{i(t=>t.filter(t=>!e(t)))},[]),reconnect:v,agentRunStatus:l,workflowRunId:d,serverFileUpdates:m}}function zX(e){if(typeof e==`string`&&e.trim().length>0)return e}function BX(e,t){let n=zX(e.revision_root_id)||zX(e.revision_root)||zX(e.root_document_id)||zX(e.root_id);if(n)return n;let r=e.revision_info;if(r&&typeof r==`object`){let e=zX(r.root);if(e)return e}return t}function VX(e,t){return e.revisionRootId&&t.revisionRootId?e.revisionRootId===t.revisionRootId:t.revisionRootId?e.id===t.revisionRootId:e.revisionRootId?e.revisionRootId===t.id:e.id===t.id}function HX(e){let[t,n]=G([]),[r,i]=G(null),[a,o]=G(!1),[s,c]=G(0),l=W(-1);return H(()=>{e.length===0&&(n([]),i(null),o(!1),c(0),l.current=-1)},[e.length]),H(()=>{let t=l.current+1;if(!(t>=e.length)){for(let r=t;r<e.length;r++){let t=e[r];if(t.type===J.UPDATE&&t.details){let e=t.details;if(e.event_class===`document_created`||e.event_class===`document_updated`){let t=zX(e.document_id),r=zX(e.updated_document_id)||t,a=e.title;if(r){let s=BX(e,t||r),l={id:r,title:a||`Document`,revisionRootId:s};n(e=>{let t=e.findIndex(e=>VX(e,l));if(t<0)return[...e,l];let n=e[t];if(n.id===l.id&&n.title===l.title&&n.revisionRootId===l.revisionRootId)return e;let r=[...e];return r[t]=l,r}),i(l.id),o(!0),e.event_class===`document_updated`&&c(e=>e+1)}}}}l.current=e.length-1}},[e]),{openDocuments:t,activeDocumentId:r,isDocPanelOpen:a,docRefreshKey:s,closeDocPanel:V(()=>{o(!1)},[]),selectDocument:V(e=>{i(e)},[]),openDocInPanel:V(e=>{n(t=>t.some(t=>t.id===e)?t:[...t,{id:e,title:`Document`,revisionRootId:e}]),i(e),o(!0)},[]),updateDocumentTitle:V((e,t)=>{n(n=>n.map(n=>n.id===e?{...n,title:t}:n))},[])}}function UX(e){return e.type.startsWith(`image/`)}function WX(e){if(!(!UX(e)||typeof URL>`u`||!URL.createObjectURL))return URL.createObjectURL(e)}function GX(e){typeof URL<`u`&&URL.revokeObjectURL&&URL.revokeObjectURL(e)}function KX(e,t,n,r,i){let a=Xt.getFixedT(null,Yt),[o,s]=G(new Map),[c,l]=G(new Set),u=W(new Set),d=W(new Map),f=W(t),p=W(o);p.current=o;let m=W(n);m.current=n;let h=V(e=>{let t=d.current.get(e);t&&(GX(t),d.current.delete(e))},[]);H(()=>{if(f.current!==t){f.current=t,d.current.forEach(GX),d.current.clear(),s(new Map);let e=new Set;u.current=e,l(e)}},[t]),H(()=>()=>{d.current.forEach(GX),d.current.clear()},[]);let g=U(()=>{let e=new Map;if(o.forEach((t,n)=>{c.has(n)||e.set(n,t)}),n.forEach((t,n)=>{if(t.consumed_at){e.delete(n);return}if(!c.has(n)){let r=o.get(n);e.set(n,{...t,artifact_path:t.artifact_path??r?.artifact_path,reference:t.reference??r?.reference,...r?.preview_url?{preview_url:r.preview_url}:{}})}}),i&&i.size>0)for(let[t,n]of e)(n.reference&&i.has(n.reference)||n.artifact_path&&i.has(n.artifact_path))&&e.delete(t);return e},[o,c,n,i]);return{processingFiles:g,hasProcessingFiles:U(()=>Array.from(g.values()).some(e=>e.status===mn.UPLOADING||e.status===mn.PROCESSING),[g]),handleFileUpload:V(async n=>{for(let i of n){let n=`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,o=`files/${i.name}`,c=WX(i);c&&d.current.set(n,c);let l={id:n,name:i.name,content_type:i.type||`application/octet-stream`,size:i.size,status:mn.UPLOADING,started_at:Date.now(),preview_url:c};s(e=>new Map(e).set(n,l));try{if(await e.agents.uploadArtifact(t,o,i),s(e=>{let t=new Map(e),r=t.get(n);return r&&(r.status=mn.PROCESSING,r.artifact_path=o,r.reference=`artifact:${o}`),t}),u.current.has(n))continue;await e.agents.sendSignal(t,`FileUploaded`,{id:n,name:i.name,content_type:i.type||`application/octet-stream`,reference:`artifact:${o}`,artifact_path:o})}catch(e){if(u.current.has(n))continue;s(t=>{let r=new Map(t),i=r.get(n);return i&&(i.status=mn.ERROR,i.error=e instanceof Error?e.message:`Upload failed`,i.completed_at=Date.now()),r}),r({status:`error`,title:a(`agent.uploadFailed`),description:e instanceof Error?e.message:`Failed to upload file`,duration:3e3})}}},[e,t,r,a]),removeProcessingFile:V(async n=>{l(e=>{if(e.has(n))return e;let t=new Set(e);return t.add(n),u.current=t,t}),s(e=>{if(!e.has(n))return e;let t=new Map(e);return t.delete(n),t}),h(n);try{await e.agents.sendSignal(t,`FileRemoved`,{id:n})}catch(e){r({status:`error`,title:a(`agent.removeFileFailed`),description:e instanceof Error?e.message:`Failed to remove file`,duration:3e3})}},[t,e,h,a,r]),clearProcessingFiles:V(()=>{d.current.forEach(GX),d.current.clear(),l(e=>{let t=new Set(e);for(let e of m.current.keys())t.add(e);for(let e of p.current.keys())t.add(e);return u.current=t,t}),s(new Map)},[])}}Q();function qX({activeWorkstreams:r,onSelectWorkstream:i,className:a}){let{t:s}=K(),[c,l]=G(!1),[u,d]=G(!1),f=vt(),p=U(()=>r.filter(e=>e.status===`running`||e.status===`canceling`),[r]),m=c?p:p.slice(0,3),h=Math.max(0,p.length-m.length),g=p.length>3;return H(()=>{g||l(!1)},[g]),p.length===0?null:t(`div`,{className:z(`mx-auto mb-2 w-full max-w-3xl px-1`,a),"data-agent-active-workstreams":!0,children:n(`output`,{className:`flex flex-col gap-1.5 rounded-2xl border border-border/70 bg-background/95 p-2 text-xs text-muted shadow-lg shadow-black/5`,"aria-live":`polite`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2 px-1 font-medium`,children:[t(jm,{className:`size-3.5 shrink-0 text-muted`,"aria-hidden":`true`}),t(`span`,{className:`truncate`,children:s(`agent.activeWorkstreams`,{count:p.length})})]}),n(o,{variant:`ghost`,size:`icon`,onClick:()=>d(!u),title:s(u?`agent.showActiveWorkstreams`:`agent.hideActiveWorkstreams`),children:[t(u?ph:ih,{className:`size-4`}),s(u?`agent.showActiveWorkstreams`:`agent.hideActiveWorkstreams`)]})]}),u?null:n(e,{children:[t(`div`,{id:f,className:`flex flex-col gap-0.5`,children:m.map(r=>{let a=PH(r.workstream_id,r.interaction),s=n(e,{children:[t(`span`,{className:z(`size-1.5 shrink-0 rounded-full`,BH(r.status)),"aria-hidden":`true`}),t(`span`,{className:`truncate font-medium`,children:a}),r.phase&&t(`span`,{className:`truncate text-xs text-muted/75`,children:MH(r.phase)})]});return i?n(o,{type:`button`,variant:`ghost`,className:`h-auto min-w-0 justify-start gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,onClick:()=>{l(!1),i(r.workstream_id)},children:[s,t(uh,{className:`ms-auto size-3.5 shrink-0 rtl:rotate-180`,"aria-hidden":`true`})]},r.launch_id||r.workstream_id):t(`div`,{className:`flex min-w-0 items-center gap-2 rounded-lg px-1 py-1 text-sm text-foreground/80`,title:a,children:s},r.launch_id||r.workstream_id)})}),g&&n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-fit shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,"aria-expanded":c,"aria-controls":f,onClick:()=>l(e=>!e),children:[!c&&n(`span`,{children:[`+`,h]}),s(c?`agent.showLess`:`agent.showMore`),t(ih,{className:z(`size-3.5 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})]})]})})}const JX=new tr({strict:!1,validateFormats:!1});function YX(e){if(e!==Tn.virtual_lb&&e!==Tn.virtual_mediator&&e!==Tn.test)return e}var XX=class{_listeners=new Set;snapshot;constructor(e){this.snapshot=new ZX(e,this)}subscribe=e=>(this._listeners.add(e),()=>{this._listeners.delete(e)});getSnapshot=()=>this.snapshot;notify(){this._listeners.forEach(e=>{e()})}},ZX=class e{vertesia;_interactive=!0;_debug_mode=!1;_non_blocking_subagents=!0;_checkpoint_tokens;_visibility;_user_channels;_collection;_disabled_mcp_collections;_start=!1;_preserveRunValues=!1;_interaction;_environment;_model=``;_model_options;_tool_names=[];_data;_mode=`start`;_scheduledWorkflowConfig;_interactionParamsSchema;_schemaVersion=0;_inputValidator;_store;constructor(e,t){this.vertesia=e,this._store=t}onStateChanged(){let e=this.clone();this._store.snapshot=e,this._store.notify()}clone(){let t=new e(this.vertesia,this._store);return t._interactionParamsSchema=this._interactionParamsSchema,t._schemaVersion=this._schemaVersion,t._interaction=this._interaction,t._data=this._data,t._environment=this._environment,t._model=this._model,t._model_options=this._model_options?{...this._model_options}:void 0,t._tool_names=[...this._tool_names],t._interactive=this._interactive,t._debug_mode=this._debug_mode,t._non_blocking_subagents=this._non_blocking_subagents,t._checkpoint_tokens=this._checkpoint_tokens,t._visibility=this._visibility,t._user_channels=this._user_channels?[...this._user_channels]:void 0,t._inputValidator=this._inputValidator,t._start=this._start,t._collection=this._collection,t._disabled_mcp_collections=this._disabled_mcp_collections?[...this._disabled_mcp_collections]:void 0,t._preserveRunValues=this._preserveRunValues,t._mode=this._mode,t._scheduledWorkflowConfig=this._scheduledWorkflowConfig,t}set mode(e){e!==this._mode&&(this._mode=e,e===`schedule`&&!this._scheduledWorkflowConfig&&(this._scheduledWorkflowConfig={name:``,description:``,cron_expression:`0 9 * * *`,timezone:`UTC`}),this.onStateChanged())}get mode(){return this._mode}set scheduledWorkflowConfig(e){this._scheduledWorkflowConfig=e,this.onStateChanged()}get scheduledWorkflowConfig(){return this._scheduledWorkflowConfig}updateScheduledWorkflowConfig(e){this._scheduledWorkflowConfig={...this._scheduledWorkflowConfig,...e},this.onStateChanged()}get interactive(){return this._interactive}set interactive(e){e!==this._interactive&&(this._interactive=e,this.onStateChanged())}get debug_mode(){return this._debug_mode}set debug_mode(e){e!==this._debug_mode&&(this._debug_mode=e,this.onStateChanged())}get non_blocking_subagents(){return this._non_blocking_subagents}set non_blocking_subagents(e){e!==this._non_blocking_subagents&&(this._non_blocking_subagents=e,this.onStateChanged())}get checkpoint_tokens(){return this._checkpoint_tokens}set checkpoint_tokens(e){e!==this._checkpoint_tokens&&(this._checkpoint_tokens=e,this.onStateChanged())}get visibility(){return this._visibility}set visibility(e){e!==this._visibility&&(this._visibility=e,this.onStateChanged())}get user_channels(){return this._user_channels}set user_channels(e){this._user_channels=e,this.onStateChanged()}get collection(){return this._collection}set collection(e){e!==this._collection&&(this._collection=e,this.onStateChanged())}get disabled_mcp_collections(){return this._disabled_mcp_collections}set disabled_mcp_collections(e){this._disabled_mcp_collections=e&&e.length>0?e:void 0,this.onStateChanged()}get search_scope(){return this._collection?un.Collection:void 0}async restoreConversation(e){let t=e.interaction;e.version&&(/^[a-fA-F0-9]{24}$/.test(t)||(t=`${t}@${e.version}`));let n=await this.vertesia.interactions.catalog.resolve(t),r=n.runtime?.environment||e.config?.environment,i=e.config?.model,a=await(r?this.vertesia.environments.retrieve(r).catch(()=>void 0):Promise.resolve(void 0));this._data=e.data,this.interaction=n,e.interactionParamsSchema!=null&&(this.interactionParamsSchema=e.interactionParamsSchema),this._tool_names=e.tool_names||[],this._interactive=e.interactive,this._debug_mode=e.debug_mode??!1,this._non_blocking_subagents=e.non_blocking_subagents??!0,this._checkpoint_tokens=e.checkpoint_tokens,this._user_channels=e.user_channels,this._disabled_mcp_collections=e.disabled_mcp_collections,this._model_options=e.config?.model_options,this.collection=e.collection_id??void 0,this._model_options=e.config?.model_options,this.environment=a,i&&(this._model=i),this.onStateChanged()}get interaction(){return this._interaction}set interaction(e){if(e?.id!==this._interaction?.id){if(this._interaction=e,this.interactionParamsSchema=e?kn(e.prompts):void 0,this._inputValidator=void 0,e&&!this._preserveRunValues&&(this._model_options=e.model_options,e.runtime?.environment)){let t=e.runtime.environment;this.vertesia.environments.retrieve(t).then(e=>this.environment=e)}this.onStateChanged()}}get environment(){return this._environment}set environment(e){if(e?.id!==this._environment?.id){if(this._environment=e,!this._preserveRunValues){let t=e?YX(e.provider):void 0,n=this.interaction?.runtime?.model;this._model=n&&t&&Mn(n,t)?n:e?.default_model&&t&&Mn(e.default_model,t)?e.default_model:``}this.onStateChanged()}}get model(){return this._model}set model(e){e!==this._model&&(this._model=e||``,this.onStateChanged())}get model_options(){return this._model_options}set model_options(e){JSON.stringify(e)!==JSON.stringify(this._model_options)&&(this._model_options=e,this.onStateChanged())}get tool_names(){return this._tool_names}set tool_names(e){this._tool_names=e,this.onStateChanged()}get data(){return this._data}set data(e){this._data=e,this.onStateChanged()}set run(e){console.log(`run`,e),this.onStateChanged()}set start(e){this._start!==e&&(this._start=e,this.onStateChanged())}markStarted(){this.start=!0}setMode(e){this.mode=e}setInteraction(e){this.interaction=e}setEnvironment(e){this.environment=e}setModel(e){this.model=e}setModelOptions(e){this.model_options=e}setToolNames(e){this.tool_names=e}setCollection(e){this.collection=e}setDisabledMcpCollections(e){this.disabled_mcp_collections=e}setInteractive(e){this.interactive=e}setDebugMode(e){this.debug_mode=e}setUserChannels(e){this.user_channels=e}setCheckpointTokens(e){this.checkpoint_tokens=e}setVisibility(e){this.visibility=e}setData(e){this.data=e}setDraftData(e){this._data=e}setPreserveRunValues(e){this.preserveRunValues=e}get start(){return this._start}get preserveRunValues(){return this._preserveRunValues}set preserveRunValues(e){this._preserveRunValues=e}get schemaVersion(){return this._schemaVersion}get interactionParamsSchema(){return this._interactionParamsSchema}set interactionParamsSchema(e){this._interactionParamsSchema!==e&&(this._interactionParamsSchema=e,this._schemaVersion+=1,e&&(this._data=this.initializeBooleanDefaults(this._data||{},e)),this.onStateChanged())}initializeBooleanDefaults(e,t){if(!t.properties)return e;let n={...e};for(let[e,r]of Object.entries(t.properties)){let t=r;t.type===`boolean`&&n[e]===void 0?n[e]=!1:t.type===`object`&&t.properties&&(n[e]=this.initializeBooleanDefaults(n[e]||{},t))}return n}reset(){if(this._start=!1,this._interactive=!0,this._debug_mode=!1,this._non_blocking_subagents=!0,this._checkpoint_tokens=void 0,this._visibility=void 0,this._user_channels=void 0,this._collection=void 0,this._disabled_mcp_collections=void 0,this._preserveRunValues=!1,this._model=``,this._model_options=void 0,this._environment=void 0,this._tool_names=[],this._interaction=void 0,this._data=void 0,this._interactionParamsSchema=null,this._inputValidator=void 0,this.model=void 0,this.environment=void 0,this.onStateChanged(),location.hash){let e=window.location.origin+window.location.pathname+window.location.search;history.replaceState(null,``,e),location.hash=``}}validateInput(){if(!this._interactionParamsSchema)return{isValid:!0};(!this._inputValidator||this._inputValidator.schema!==this._interactionParamsSchema)&&(this._inputValidator={validate:JX.compile(this._interactionParamsSchema),schema:this._interactionParamsSchema});let e=this._data||{};return this._inputValidator.validate(e)?{isValid:!0}:{isValid:!1,errorMessage:this._inputValidator.validate.errors?this._inputValidator.validate.errors.map(e=>`${e.instancePath}: ${e.message}`).join(`, `):`Invalid payload data`}}};const QX=dt(void 0);function $X({children:e}){let{client:n}=q(),[r]=G(()=>new XX(n)),i=xt(r.subscribe,r.getSnapshot);return t(QX.Provider,{value:i,children:e})}function eZ(){let e=_t(QX);if(!e)throw Error(`usePayloadBuilder must be used within a PayloadProvider`);return e}Q();function tZ(){let{router:e}=er();return t=>{let n=t.startsWith(`/`)?e.getTopRouter().navigator.addStickyParams(t):t;return window.open(n,`_blank`,`noopener,noreferrer`),n}}function nZ({title:e,variant:r=`full`,isTerminal:i=!1,onClose:a,isModal:s,agentRunId:c,workflowRunId:l,viewMode:u,onViewModeChange:d,showPlanPanel:f,showPlanButton:p=!0,onTogglePlanPanel:m,showPlaybackButton:h=!1,isPlaybackEnabled:g=!1,onTogglePlayback:_,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C=!0,onClone:w,isReceivingChunks:T=!1,className:E}){let{t:D}=K(),O=tZ(),k=r===`compact`,A=u===`sliding`?`stacked`:`sliding`,j=D(`agent.verbose`),M=D(`agent.summary`),N=A===`stacked`?j:M,P=n(`div`,{className:z(k?`flex flex-row items-center gap-1 lg:flex-col`:`flex justify-end items-center gap-2 ms-auto`),children:[p&&t(`div`,{className:`relative`,children:n(o,{size:r===`compact`?`icon`:`sm`,variant:f?`primary`:`ghost`,onClick:m,className:z(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),title:D(`agent.toggleRightSidebar`),children:[t(tg,{className:z(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)}):t(`span`,{className:`sr-only`,children:D(f?`agent.hideSidebar`:`agent.showSidebar`)})]})}),k?t(o,{variant:`ghost`,size:`icon`,onClick:()=>d(A),className:`size-8 rounded-lg`,title:N,"aria-label":N,children:t(A===`stacked`?Sy:yv,{className:`size-4`})}):n(`div`,{className:`flex items-center gap-1 bg-muted rounded p-0.5 mt-2 lg:mt-0`,children:[n(o,{variant:u===`stacked`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`stacked`),"aria-pressed":u===`stacked`,className:`gap-1.5`,children:[t(Sy,{className:`size-3.5`}),j]}),n(o,{variant:u===`sliding`?`outline`:`ghost`,size:`xs`,onClick:()=>d(`sliding`),"aria-pressed":u===`sliding`,className:`gap-1.5`,children:[t(yv,{className:`size-3.5`}),M]})]}),h&&_&&n(o,{type:`button`,size:r===`compact`?`icon`:`sm`,variant:g?`primary`:`ghost`,onClick:_,"aria-pressed":g,title:D(`agent.rewind.label`),className:z(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),children:[t(Km,{className:z(`size-4`,r===`full`&&`me-1.5`)}),r===`full`?t(`span`,{className:`font-medium text-xs`,children:D(`agent.rewind.label`)}):t(`span`,{className:`sr-only`,children:D(`agent.rewind.label`)})]}),c&&t(o,{type:`button`,size:k?`icon`:`xs`,variant:`ghost`,onClick:()=>O(`/store/agent-runner/${c}`),title:D(`agent.openInNewTab`),className:z(`transition-all duration-200 rounded-md`,k&&`size-8 rounded-lg`),children:t(Og,{className:`size-4`})}),b&&t(o,{type:`button`,size:r===`compact`?`icon`:`sm`,variant:`ghost`,onClick:b,title:D(`agent.startNewConversation`),className:z(`transition-all duration-200 rounded-md`,r===`compact`&&`size-8 rounded-lg`),children:t(gv,{className:z(`size-4`,r===`full`&&`me-1.5`)})}),t(rZ,{compact:k,agentRunId:c,workflowRunId:l,isModal:s,isTerminal:i,onClose:a,onDownload:v,onExportFixture:y,resetWorkflow:b,onExportPdf:x,onShowDetails:S,allowWorkflowControl:C,onClone:w}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,"aria-label":D(`agent.close`),children:t(Kb,{className:`size-4`})})]});return r===`compact`?t($X,{children:t(`div`,{className:z(`inline-flex items-center rounded-xl border border-border/70 bg-background/90 p-1 shadow-lg shadow-black/10 backdrop-blur`,E),children:P})}):t($X,{children:n(`div`,{className:z(`flex flex-wrap items-center justify-between py-1.5 px-2 border-b shadow-sm flex-shrink-0`,E),children:[n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1`,children:[t(jm,{className:`size-5 text-muted`}),t(`span`,{className:`font-medium`,children:e})]}),n(`span`,{className:`text-xs text-muted ms-1 flex items-center gap-1.5`,children:[`(Agent Run ID: `,c,`)`,t(`span`,{className:z(`w-2 h-2 rounded-full transition-colors duration-200`,T?`bg-purple-500 shadow-[0_0_6px_2px_rgba(168,85,247,0.6)]`:`bg-gray-400`)})]})]}),P]})})}function rZ({compact:e=!1,agentRunId:r,workflowRunId:i,isModal:a,isTerminal:s,onClose:c,onDownload:l,onExportFixture:u,resetWorkflow:d,onExportPdf:f,onShowDetails:p,allowWorkflowControl:m=!0,onClone:h}){let{t:g}=K(),_=nt(),{client:v}=q(),y=eZ();return t(w,{align:`right`,trigger:t(o,{size:e?`icon`:`xs`,variant:`ghost`,title:g(`agent.moreActions`),className:e?`size-8 rounded-lg`:void 0,children:t(Tg,{className:`size-4`})}),children:n(ie,{label:`Actions`,children:[n(ae,{onClick:()=>{navigator.clipboard.writeText(r),_({status:`success`,title:g(`agent.agentRunIdCopied`),duration:2e3})},children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.copyAgentRunId`)]}),n(ae,{onClick:()=>{navigator.clipboard.writeText(i),_({status:`success`,title:g(`agent.workflowRunIdCopied`),duration:2e3})},children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.copyWorkflowRunId`)]}),p&&n(ae,{onClick:p,children:[t(j_,{className:`size-3.5 text-muted`}),` `,g(`agent.details`)]}),n(ae,{onClick:()=>{l?l():rU(v,r).then(e=>window.open(e,`_blank`))},children:[t(sg,{className:`size-3.5 text-muted`}),` `,g(`agent.downloadConversation`)]}),f&&n(ae,{onClick:f,children:[t(sg,{className:`size-3.5 text-muted`}),` `,g(`agent.exportAsPdf`)]}),u&&n(ae,{onClick:u,children:[t(sg,{className:`size-3.5 text-muted`}),` `,g(`agent.rewind.exportFixture`)]}),c&&a&&n(ae,{onClick:c,children:[t(Kb,{className:`size-3.5 text-muted`}),` `,g(`agent.close`)]}),h&&n(ae,{onClick:async()=>{try{let e=await v.agents.fork(r);_({status:`success`,title:g(`agent.conversationCloned`),duration:2e3}),h?.(e)}catch{_({status:`error`,title:g(`agent.failedToCloneConversation`),duration:2e3})}},children:[t(y_,{className:`size-3.5 text-muted`}),` `,g(`agent.cloneConversation`)]}),m&&!s&&n(ae,{onClick:async()=>{try{return await v.agents.terminate(r,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3}),y.reset(),d?.(),!0}catch{return _({status:`error`,title:g(`agent.failedToCancelWorkflow`),duration:2e3}),!1}},variant:`destructive`,children:[t(Kb,{className:`size-3.5`}),` `,g(`agent.cancelWorkflow`)]})]})})}function iZ(e){return typeof e==`object`&&!!e&&`value`in e}function aZ(e){return iZ(e)?e.value:e}function oZ(e){if(e.type===`stringList`)return e.value.map(e=>typeof e==`string`?e:aZ(e));if(e.multiple)return e.value.map(aZ);let t=e.value[0];return t===void 0?void 0:aZ(t)}function sZ(e,t,n){e.query[t]=n}function cZ(e){let t=new Set(e);return e=>t.has(e)}function lZ({buckets:e,name:r,placeholder:a}){let o=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:r,placeholder:a||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:o,type:`select`,labelRenderer:r=>{let a=e.find(e=>e._id===r),o=a?.name||r,s=`success`;if(a?.status)switch(a.status){case gn.published:s=`success`;break;case gn.archived:s=`destructive`;break;case gn.code:s=`info`}let c=a?.version&&a?.status?`v${a.version} ${a.status===gn.unknown?``:a.status}`:a?.status||(a?.version?`v${a.version}`:``);return n(`div`,{className:`w-full flex items-center justify-between`,children:[n(`div`,{className:`flex flex-row flex-wrap items-center gap-2 min-w-0 flex-1`,children:[t(`span`,{className:`text-sm truncate`,children:o}),c&&t(i,{variant:s,className:`text-xs w-fit`,children:c})]}),(a?.count??0)>0&&n(`span`,{className:`ms-2 text-xs shrink-0`,children:[`(`,a?.count,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}function uZ(e){return`${e._id} (${e.count})`}function dZ(e){return`${e.name} (${e.count})`}function fZ({buckets:e,name:t,placeholder:n,type:r=`select`,multiple:i=!1}){return{name:t,options:e.map(e=>({label:uZ(e),value:e._id})),type:r,multiple:i,placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`,allowCreate:!1}}function pZ({buckets:e,name:t,placeholder:n,type:r,multiple:i}){return fZ({buckets:e,name:t,placeholder:n,type:r,multiple:i})}Q();const mZ={},hZ={},gZ={};function _Z(e){return typeof e==`object`&&!!e&&`status`in e&&e.status===404}function vZ(e,t,n){let r=e[t];return r||(r=n().catch(n=>{throw _Z(n)||delete e[t],n}),e[t]=r),r}function yZ(e){let{client:t}=q();return Ye(()=>vZ(mZ,e,()=>t.users.retrieve(e)),{deps:[e],condition:()=>!!e})}function bZ(e){let{client:t}=q();return Ye(()=>vZ(hZ,e,()=>t.iam.groups.retrieve(e)),{deps:[e],condition:()=>!!e})}function xZ(e){let{client:t}=q();return Ye(()=>vZ(gZ,e,()=>t.apikeys.retrieve(e)),{deps:[e],condition:()=>!!e})}function SZ(){return t(`div`,{className:`size-8`})}function CZ({showTitle:e=!1,size:i=`md`}){let{t:a}=K();return t(FZ,{title:a(`user.systemUser`),description:a(`user.systemUserDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(r,{src:`/icon.svg`,size:i}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:a(`user.systemUser`)})]})})}function wZ({showTitle:e=!1,size:r=`md`}){let{t:i}=K();return t(FZ,{title:i(`user.allProjectMembers`),description:i(`user.allProjectMembersDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(jb,{className:`size-4`,size:r}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:i(`user.allProjectMembers`)})]})})}function TZ({accountId:i,showTitle:a=!1,size:o=`md`}){let{t:s}=K(),c=n(e,{children:[t(`div`,{children:s(`user.serviceAccountDescription`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]});return t(FZ,{title:s(`user.serviceAccount`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:`/cloud.svg`,name:`SA`,color:`bg-amber-500`,className:`px-[5px] text-white`,size:o}),a&&n(`div`,{className:`text-sm font-semibold ps-2 truncate`,children:[s(`user.serviceAccount`),` : ~`,i.slice(-6)]})]})})}function EZ({email:i,showTitle:a=!1,size:o=`md`}){let{t:s}=K(),c=n(e,{children:[t(`div`,{children:s(`user.agentOnBehalfOf`)}),n(`div`,{className:`text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`Email:`}),` `,i]})]});return t(FZ,{title:`Email Agent`,description:c,children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:o}),t(r,{name:i,size:o,className:`border-2 border-white dark:border-gray-800`})]}),a&&n(`div`,{className:`text-sm font-semibold truncate`,children:[`Agent (`,i,`)`]})]})})}function DZ({agentId:i,onBehalfOfType:a,onBehalfOfId:o,showTitle:s=!1,size:c=`md`,isScheduleAgent:l=!1}){let{t:u}=K(),d=a===`user`&&o,f=a===`apikey`&&o,p=yZ(o||``),m=xZ(o||``),h=d?p.data:void 0,g=f?m.data:void 0,_=i.slice(-6),v=h?u(`user.agentOnBehalfOf`):g?u(`user.agentOnBehalfOfApiKey`):`${u(`user.serviceAccount`)}~${_}`,y=l?u(`user.schedule`,{title:v}):v,b=n(`div`,{className:`space-y-2`,children:[h&&n(`div`,{className:`flex items-center gap-2`,children:[t(r,{src:h.picture,name:h.name,size:`sm`}),n(`div`,{children:[t(`div`,{className:`font-medium`,children:h.name||h.email}),h.email&&h.name&&t(`div`,{className:`text-xs text-muted`,children:h.email})]})]}),g&&n(`div`,{children:[t(`div`,{className:`font-medium`,children:g.name}),n(`div`,{className:`text-xs text-muted-foreground`,children:[`Key ID: `,g.id]})]}),!h&&!g&&n(e,{children:[t(`div`,{children:u(`user.serviceAccountDescription`)}),n(`div`,{className:`text-gray-800 dark:text-gray-500 text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]})]});return t(FZ,{title:y,description:b,children:n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center -space-x-2`,children:[t(r,{src:`/cloud.svg`,color:`bg-amber-500`,className:`px-[5px] text-white border-2 border-white dark:border-gray-800`,size:c}),h&&t(r,{src:h.picture,name:h.name,size:c,className:`border-2 border-white dark:border-gray-800`}),g&&t(r,{name:`API`,color:`bg-gray-400`,size:c,className:`border-2 border-white dark:border-gray-800`})]}),s&&t(`div`,{className:`text-sm font-semibold truncate`,children:h?`Agent (${h.name||h.email})`:g?`Agent (${g.name})`:v})]})})}function OZ({title:e=`Error`,error:n,showTitle:r=!1,size:i=`md`}){return t(jZ,{title:e,message:Ge(n),color:`bg-red-500`,showTitle:r,size:i})}function kZ({showTitle:e=!1,size:n=`md`,color:r}){let{t:i}=K();return t(jZ,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),color:r,showTitle:e,size:n})}function AZ({userRef:e,showTitle:n=!1,size:r=`md`}){let{t:i}=K();if(!e)return t(jZ,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),showTitle:n,size:r});let a=e.split(`:`),o=a[0];switch(o){case xn.User:return t(NZ,{userId:a[1],showTitle:n,size:r});case xn.Group:return t(MZ,{userId:a[1],showTitle:n,size:r});case`system`:return t(CZ,{showTitle:n,size:r});case xn.ServiceAccount:return t(TZ,{accountId:a.slice(1).join(`:`),showTitle:n,size:r});case xn.Agent:{let e,i,o;return a[1]===`agent`?(e=a.slice(2,5).join(`:`),i=a[5],o=a[6]):(e=a.slice(1,4).join(`:`),i=a[4],o=a[5]),t(DZ,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r})}case xn.Schedule:{let e=a[2]===`agent`?a.slice(3,6).join(`:`):`unknown-agent`,i=a[6],o=a[7];return t(DZ,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r,isScheduleAgent:!0})}case`email`:return t(EZ,{email:a[1],showTitle:n,size:r});case xn.ApiKey:return t(PZ,{keyId:a[1],size:r,showTitle:n});case`project`:if(a[1]===`*`)return t(wZ,{showTitle:n,size:r});break;default:return t(OZ,{title:i(`user.unknownUser`),error:`Invalid user ref type: ${o}`,showTitle:n,size:r})}}function jZ({title:e,message:i,color:a,size:o=`md`,showTitle:s=!1}){return t(FZ,{title:e,description:i,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{color:a,size:o}),s&&t(`div`,{className:`text-sm font-semibold ps-1`,children:e})]})})}function MZ({userId:e,showTitle:r=!1,size:i=`md`}){let{t:a}=K(),{data:o,error:s}=bZ(e);if(s)return _Z(s)?t(kZ,{showTitle:r,size:i,color:`bg-indigo-500`}):t(OZ,{title:a(`user.failedToFetchGroup`),error:s,showTitle:r,size:i});if(!o)return t(SZ,{});let c=n(`div`,{className:`space-y-1`,children:[o.description&&t(`div`,{className:`text-sm`,children:o.description}),t(`div`,{className:`text-xs text-muted-foreground`,children:a(`user.groupId`,{id:o.id})}),o.tags&&o.tags.length>0&&t(`div`,{className:`flex flex-wrap gap-1`,children:o.tags.map(e=>t(`span`,{className:`px-1.5 py-0.5 bg-muted rounded text-xs`,children:e},e))})]});return t(FZ,{title:o.name||a(`user.unnamedGroup`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(Pb,{className:`size-6 text-indigo-500`,size:i}),r&&t(`div`,{className:`text-sm font-semibold ps-2`,children:o.name||a(`user.unnamedGroup`)})]})})}function NZ({userId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=yZ(e);if(c)return _Z(c)?t(kZ,{showTitle:i,size:a,color:`bg-indigo-500`}):t(OZ,{title:o(`user.failedToFetchUser`),error:c,showTitle:i,size:a});if(!s)return t(SZ,{});let l=t(`div`,{className:`truncate`,title:s.email,children:s.email});return t(FZ,{title:s.name||s.email||s.username||o(`user.unknown`),description:l,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(r,{src:s.picture,name:s.name,color:`bg-indigo-500`,size:a}),i&&t(`div`,{className:`text-sm font-semibold ps-2`,children:s.name||s.email||s.username||o(`user.unknown`)})]})})}function PZ({keyId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=xZ(e);if(c)return _Z(c)?t(kZ,{showTitle:i,size:a,color:`bg-pink-500`}):t(OZ,{title:o(`user.failedToFetchApiKey`),error:c,showTitle:i,size:a});if(!s)return t(SZ,{});let l=o(`user.privateKey`),u=t(r,{name:`PK`,color:`bg-pink-500`,size:a}),d=n(Le,{className:`dark:bg-gray-800 dark:text-gray-200 table-fixed w-full`,children:[n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.key`)}),t(`td`,{className:`truncate max-w-0`,children:s?.name})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.account`)}),t(`td`,{className:`truncate max-w-0`,children:s?.account})]}),n(`tr`,{children:[t(`td`,{className:`font-semibold w-20`,children:o(`user.project`)}),t(`td`,{className:`truncate max-w-0`,children:s?.project.name})]})]});return t(FZ,{title:l,description:d,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[u,i&&t(`div`,{className:`text-sm font-semibold`,children:s?.name||s?.account||s?.project.name||o(`user.unknown`)})]})})}function FZ({title:e,description:r,children:i}){return n(he,{hover:!0,children:[t(_e,{className:`cursor-pointer flex items-center inline-block`,children:t(`div`,{children:i})}),t(ge,{align:`center`,sideOffset:8,side:`right`,children:n(`div`,{className:`flex flex-col gap-1 rounded-md shadow-md p-2`,children:[t(`div`,{className:`text-md font-semibold`,children:e}),r]})})]})}function IZ({buckets:e,name:r,placeholder:i}){let a=e.map(e=>({value:e._id,label:`(${e.count})`}));return{name:r,placeholder:i||`${r.charAt(0).toUpperCase()+r.slice(1)}`,options:a,labelRenderer:r=>{if(r===`Unknown User`||!r)return`Unknown User (${e.find(e=>e._id===r)?.count||0})`;let i=e.find(e=>e._id===r);return n(`div`,{className:`flex items-center w-full gap-2`,children:[t(`div`,{className:`flex-1 min-w-0 flex items-center truncate`,children:t(AZ,{userRef:r,showTitle:!0,size:`sm`})}),n(`span`,{className:`text-muted-foreground flex-shrink-0`,children:[`(`,i?.count||0,`)`]})]})}}}function LZ({buckets:e,name:t,placeholder:n}){return IZ({buckets:e,name:t,placeholder:n})}Q();const RZ=cZ([`id`,`run_kind`,`interaction`,`status`,`initiated_by`,`start`,`end`]);function zZ(e){let t=[];return t.push({name:`id`,placeholder:`Agent Run ID`,type:`text`,multiple:!1}),t.push(pZ({buckets:e.kinds||[],name:`run_kind`,placeholder:`Kind`})),t.push(lZ({buckets:e.interactions||[],name:`interaction`,placeholder:`Interaction`})),t.push(pZ({buckets:e.statuses||[],name:`status`,placeholder:`Status`})),t.push(LZ({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function BZ(e){return t=>{e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!RZ(t.name))return;let n=t.name;sZ(e,n,oZ(t))}}),e.search()}}function VZ({facets:e,search:r,selectionCount:i,actions:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=G([]),f=s??u,p=c??d,m=W(!1),h=W(typeof window<`u`&&!!new URLSearchParams(window.location.search).get(`filters`)),g=zZ(e),_=l??g,v=U(()=>BZ(r),[r]);return H(()=>{if(!m.current){m.current=!0;return}if(h.current){h.current=!1;return}v(f)},[f,v]),t(I,{filterGroups:_,filters:f,setFilters:p,children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!i&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted-foreground`,children:r.initialized?`${r.totalCount} runs`:`Loading runs...`})}),a&&a.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:a.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(gy,{className:`size-5`})})]})]}),f.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}var HZ=class{types;map={};constructor(e){this.types=e,e.sort((e,t)=>e.name.localeCompare(t.name));for(let t of e)this.map[t.id]=t}getType(e){return this.map[e]}getTypeLayout(e){let t=this.map[e];return t?t.table_layout:void 0}getTypeName(e){let t=this.map[e];return t?t.name:void 0}};const UZ=dt({registry:void 0,isLoading:!1,load:()=>Promise.resolve(),reload:()=>Promise.resolve()});function WZ({children:e}){let{store:n,project:r}=q(),[i,a]=G(),[o,s]=G(!1),c=W(!1),l=W(r?.id),u=V(async()=>{if(!(!r||c.current)){c.current=!0,s(!0);try{let e=await n.types.catalog.list({layout:!0});a(new HZ(e))}catch(e){console.error(`Failed to fetch types`,e)}finally{s(!1),c.current=!1}}},[n,r]),d=V(async()=>(c.current=!1,u()),[u]);return H(()=>{l.current!==r?.id&&(l.current=r?.id,a(void 0),c.current=!1)}),t(UZ.Provider,{value:{registry:i,isLoading:o,load:u,reload:d},children:e})}function GZ(){let e=_t(UZ);return H(()=>{!e.registry&&!e.isLoading&&e.load()},[e.registry,e.isLoading,e.load]),e}const KZ=cZ([`name`,`types`]);function qZ(e){let{registry:t}=GZ(),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t){let e=t.types.map(e=>({label:e.name,value:e.id})),r={name:`types`,placeholder:`Type`,type:`select`,multiple:!0,options:e,filterBy:(t,n)=>e.find(e=>e.value===t)?.label?.toLowerCase().includes(n.toLowerCase())??!1};n.push(r)}return n}function JZ(e){return t=>{if(t.length===0){e.clearFilters(!0);return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!KZ(t.name))return;let n=t.name;sZ(e,n,oZ(t))}}),e.search()}}function YZ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=qZ(e),u=JZ(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function XZ({buckets:e,typeRegistry:r,type:i=`select`,multiple:a=!1}){let o=new Map;return r||console.warn(`Type names cannot be resolved`),e.forEach(e=>{let t,n=e._id;e._id==null?(n=`Document`,t=`Document`):(t=r?.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),o.set(n,{name:t,count:e.count})}),{name:`types`,placeholder:`Types`,type:i,multiple:a,options:e.map(e=>{let t=e._id,n=t||`Document`,r=o.get(n);return{value:t,label:r?`${r.name} (${r.count})`:`Unknown (${e.count})`}}),labelRenderer:e=>{let r=o.get(e);return r?n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:r.name}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,r.count,`)`]})]}):(console.warn(`Type data not found for ${e}`),e)},filterBy:(e,t)=>{let n=o.get(e);return n?n.name.toLowerCase().includes(t.toLowerCase()):(console.warn(`Type name not found for ${e}`),!1)}}}const ZZ=[`id`,`name`,`types`,`status`],QZ=[`tags`,`created_at`,`updated_at`],$Z=cZ(ZZ),eQ=new Set(QZ);function tQ(e){return eQ.has(e)}function nQ(e){return Array.isArray(e)?e:[]}function rQ(e){let{registry:t}=GZ(),n=[];if(n.push({placeholder:`ID`,name:`id`,type:`text`,options:[]}),n.push({placeholder:`Name`,name:`name`,type:`text`,options:[]}),e.type){let r=XZ({buckets:nQ(e.type),typeRegistry:t,type:`select`,multiple:!0});n.push(r)}if(e.status){let t=pZ({buckets:nQ(e.status),name:`status`,placeholder:`Status`,type:`select`,multiple:!0});n.push(t)}return e.tags&&n.push({name:`tags`,placeholder:`Tags`,type:`stringList`,options:nQ(e.tags).map(e=>({label:e._id,value:e._id}))}),n.push({name:`created_at`,placeholder:`Created Date`,type:`date`,multiple:!0,options:[]}),n.push({name:`updated_at`,placeholder:`Updated Date`,type:`date`,multiple:!0,options:[]}),n}function iQ(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){let n=t.name,r;if(t.type===`date`&&t.multiple){if(Array.isArray(t.value)&&t.value.length>0){if(t.value.length===1){let e=aZ(t.value[0]);r={gte:e,lte:e}}else t.value.length===2&&(r={gte:aZ(t.value[0]),lte:aZ(t.value[1])})}}else r=oZ(t);$Z(n)?sZ(e,n,r):tQ(n)&&r!==void 0&&(e.query.match={...e.query.match,[n]:r})}}),e.search()}}function aQ({facets:e,search:r}){let[i,a]=G([]),o=rQ(e),s=iQ(r),c=$e();return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},inModal:c,children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function oQ({search:e,buckets:n,placeholder:r=`All Environments`,className:i}){let{client:a}=q(),[o,s]=G([]),c=e.getFilterValue(`environment`),l=t=>{e.setFilterValue(`environment`,t?._id)};H(()=>{if(a){let e=n.map(async e=>{let t;return await a.environments.retrieve(e._id).then(e=>{t=e.name}).catch(()=>{t=`${e._id} (deleted)`}),t||=e._id,{...e,name:t}});Promise.all(e).then(e=>{e.sort((e,t)=>e.name.localeCompare(t.name)),s(e)})}},[n,a]);let u=o?.find(e=>e._id===c);return t(we,{filterBy:`name`,className:i,isClearable:!0,optionLabel:dZ,options:o,value:u,onChange:l,by:`_id`,placeholder:r})}const sQ=cZ([`name`,`prompt`,`model`,`tags`]);function cQ(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.push({name:`prompt`,placeholder:`Prompt Name`,type:`text`,multiple:!1}),t.push({name:`model`,placeholder:`Model`,type:`text`,multiple:!1}),t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),t}function lQ(e){return t=>{if(t.length===0){e.clearFilters(!0,!0);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!sQ(t.name))return;let n=t.name;sZ(e,n,oZ(t))}}),e.search(!0)}}function uQ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=cQ(e),u=lQ(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function dQ(e){let t=[];return t.push(pZ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!1})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function fQ({facets:e,filters:r,setFilters:i}){let a=dQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function pQ(e){let t=[];return t.push(pZ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!0})),t.push(LZ({buckets:e.started_by||[],name:`started_by`,placeholder:`Started By`})),t.push(pZ({buckets:e.run_type||[],name:`run_type`,placeholder:`Mode`,multiple:!0})),t.push(pZ({buckets:e.processes||[],name:`process`,placeholder:`Process`,multiple:!0})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function mQ({facets:e,filters:r,setFilters:i}){let a=pQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}const hQ=cZ([`name`,`role`,`tags`]);function gQ(e,t){let n=e[t];return Array.isArray(n)?n:[]}function _Q(e){let t=gQ(e,`role`),n=[];if(n.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t.length>0){let e={name:`role`,placeholder:`Role`,type:`select`,options:t.map(e=>({label:e._id,value:e._id,count:e.count}))};n.push(e)}let r={name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0,options:gQ(e,`tags`).map(e=>({label:e._id,value:e._id}))};return n.push(r),n}function vQ(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!hQ(t.name))return;let n=t.name;sZ(e,n,oZ(t))}}),e.search()}}function yQ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=_Q(e),u=vQ(r),d=i!==void 0&&a!==void 0;return t(I,{filterGroups:o??l,filters:d?i:s,setFilters:e=>{if(d){a(e);return}let t=typeof e==`function`?e(s):e;c(t),u(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function bQ({buckets:e,name:r}){let i=e.map(e=>({label:`(${e.count})`,value:e._id}));return{name:`environment`,placeholder:r.charAt(0).toUpperCase()+r.slice(1),options:i,type:`select`,labelRenderer:r=>{let i=e.find(e=>e._id===r),a=i?.name||r;return n(`div`,{className:`w-full flex items-center`,children:[t(`span`,{className:`text-sm truncate`,children:a}),n(`span`,{className:`ms-2 text-xs`,children:[`(`,i?.count||0,`)`]})]})},filterBy:(t,n)=>(e.find(e=>e._id===t)?.name||t).toLowerCase().includes(n.toLowerCase())}}Q();const xQ=cZ([`run_ids`,`interaction`,`environment`,`tags`,`model`,`status`,`finish_reason`,`start`,`end`,`workflow_run_ids`,`workflow_ids`]);function SQ(e){return e.filter(e=>e._id!==null)}function CQ(e){let t=[];if(t.push({name:`run_ids`,placeholder:`Run ID`,type:`text`,multiple:!1}),e.interactions){let n=lZ({buckets:SQ(e.interactions),name:`interaction`,placeholder:`Interactions`});t.push(n)}if(e.environments){let n=bQ({buckets:SQ(e.environments),name:`environment`});t.push(n)}if(t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),e.models){let n=pZ({buckets:SQ(e.models),name:`model`});t.push(n)}if(e.statuses){let n=pZ({buckets:SQ(e.statuses),name:`status`});t.push(n)}if(e.finish_reason){let n=pZ({buckets:e.finish_reason.map(e=>({...e,_id:e._id===null?`none`:e._id})),name:`finish_reason`,placeholder:`Finish Reason`});t.push(n)}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`workflow_run_ids`,placeholder:`Workflow Run ID`,type:`text`,multiple:!1}),t.push({name:`workflow_ids`,placeholder:`Workflow ID`,type:`text`,multiple:!1}),t}function wQ(e){return t=>{if(t.length===0){e.clearFilters(!0,!1);return}e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!xQ(t.name))return;let n=t.name,r=oZ(t);(n===`run_ids`||n===`workflow_run_ids`||n===`workflow_ids`)&&!Array.isArray(r)&&(r=[r]),sZ(e,n,r)}}),e.search()}}function TQ({facets:e,search:r,actions:i,selectionCount:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=G([]),f=CQ(e),p=wQ(r),m=s!==void 0&&c!==void 0,h=m?s:u;return t(I,{filterGroups:l??f,filters:h,setFilters:e=>{if(m){c(e);return}let t=typeof e==`function`?e(u):e;d(t),p(t)},children:n(`div`,{className:`gap-2 items-center w-full`,children:[n(`div`,{className:`flex justify-between mb-1`,children:[t(P,{}),n(`div`,{className:`flex justify-end`,children:[!a&&t(`div`,{className:`flex items-center justify-between px-2 py-1`,children:t(`div`,{className:`text-sm text-muted`,children:r.initialized?`${r.totalCount} calls`:`Loading calls...`})}),i&&i.length>0?t(`div`,{className:`flex items-center gap-2 mb-1 me-2`,children:i.map((e,n)=>t(`div`,{children:e},`action-${n}`))}):null,t(o,{onClick:()=>{r.search()},variant:`outline`,title:`Refresh`,children:t(gy,{className:`size-5`})})]})]}),h.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}function EQ({search:e,buckets:n,name:r,placeholder:i,className:a}){let o=e.getFilterValue(r),s=t=>{e.setFilterValue(r,t?._id)},c=n?.find(e=>JSON.stringify(e._id)===JSON.stringify(o));return t(we,{filterBy:`_id`,className:a,isClearable:!0,optionLabel:uZ,options:n,value:c,onChange:s,by:`_id`,placeholder:i})}function DQ({search:e,name:n,placeholder:r,className:i}){let[a,o]=G([]);return H(()=>{e.setFilterValue(n,a)},[n,e,a]),t(ne,{className:i,value:a,onChange:o,placeholder:r})}function OQ(e){return`${e.name} (${e.count})`}function kQ({search:e,buckets:n,placeholder:r=`Filter by Type`,className:i}){let[a,o]=G([]),{registry:s}=GZ(),c=e.getFilterValue(`type`),l=t=>{e.setFilterValue(`type`,t?._id)};H(()=>{if(s){let e=n.map(e=>{let t;return e._id==null?(e._id=`Document`,t=`Document`):(t=s.getTypeName(e._id),t||=(console.warn(`Content Object Type not found`,e._id),e._id)),{...e,name:t}});e.sort((e,t)=>e.name.localeCompare(t.name)),o(e)}},[n,s]);let u=a?.find(e=>e._id===c);return t(we,{filterBy:`name`,className:i,isClearable:!0,optionLabel:OQ,options:a,value:u,onChange:l,by:`_id`,placeholder:r})}function AQ(e){let t=[];return t.push(pZ({buckets:e.tags||[],name:`tags`,placeholder:`Tags`,multiple:!0})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function jQ({facets:e,filters:r,setFilters:i}){let a=AQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}const MQ=cZ([`search_term`,`status`,`initiated_by`,`start`,`end`,`has_reported_errors`]);function NQ(e){let t=[];if(t.push({placeholder:`Workflow Name or Workflow Run ID`,name:`search_term`,type:`text`,options:[]}),e.status){let n=pZ({buckets:e.status||[],name:`status`,placeholder:`Status`});t.push({...n,name:`status`})}if(e.initiated_by){let n=LZ({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`});t.push({...n,name:`initiated_by`})}return t.push({name:`start`,placeholder:`Date After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Date Before`,type:`date`,multiple:!1}),t.push({name:`has_reported_errors`,placeholder:`Has Reported Errors`,type:`select`,multiple:!1,options:[{label:`Yes`,value:`true`},{label:`No`,value:`false`}]}),t}function PQ(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!MQ(t.name))return;let n=t.name,r=oZ(t);if(n===`has_reported_errors`){let t=Array.isArray(r)?r[0]:r;(t===`true`||t===`false`)&&sZ(e,n,t===`true`)}else typeof r==`string`&&sZ(e,n,r)}}),e.search()}}function FQ({facets:e,search:r}){let[i,a]=G([]),o=NQ(e),s=PQ(r);return t(I,{filterGroups:o,filters:i,setFilters:e=>{let t=typeof e==`function`?e(i):e;a(t),s(t)},children:n(`div`,{className:`flex gap-2 items-center`,children:[t(P,{}),t(N,{}),t(F,{})]})})}function IQ(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function LQ({facets:e,filters:r,setFilters:i}){let a=IQ(e);return t(I,{filterGroups:a,filters:r,setFilters:i,children:n(`div`,{className:`flex items-center gap-2`,children:[t(P,{}),t(N,{}),t(F,{})]})})}var RQ=class e{object;objects;setState;collectionId;singleSelection=!1;constructor(e,t,n,r){this.object=e,this.objects=n,this.setState=r,this.singleSelection=Object.keys(this.objects).length===0,this.collectionId=t}isSingleSelection(){return this.singleSelection}hasSelection(){return this.object!==void 0||this.size()!==0}size(){return Object.keys(this.objects).length}getObjectIds(){return Object.keys(this.objects)}getObjectId(){return this.object?.id}clone(){return new e(this.object,this.collectionId,this.objects,this.setState)}add(e){this.objects[e.id]=e,this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}remove(e){delete this.objects[e],this.singleSelection=Object.keys(this.objects).length===0,this.setState(this.clone())}addAll(e){for(let t of e)this.objects[t.id]=t;this.setState(this.clone())}isSelected(e){return this.objects[e]!==void 0}removeAll(){this.objects={},this.singleSelection=!0,this.setState(this.clone())}};const zQ=dt(void 0);function BQ(){let e=_t(zQ);if(!e)throw Error(`useObjectSelection must be used within a ObjectSelectionProvider`);return e}function VQ(){return _t(zQ)}function HQ({value:e,collectionId:n,children:r}){let[i,a]=G();return H(()=>{let t=new RQ(e,n,{},a);a(t)},[n,e]),i&&t(zQ.Provider,{value:i,children:r})}Q();const UQ=dt(void 0);function WQ({onFilter:e,children:n}){return t(UQ.Provider,{value:e,children:n})}function GQ(){return _t(UQ)}const KQ=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function qQ({field:r,value:i,label:a,copyContent:s}){let c=GQ(),l=Array.isArray(i)?i.length>0:i!==void 0&&i!==``;return n(e,{children:[s!==void 0&&s!==``&&t(x,{content:s,className:KQ}),l&&i!==void 0&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${a}`,className:KQ,onClick:e=>{e.stopPropagation(),c?.(r,i)},children:t(u_,{className:`size-3`})})]})}const JQ=`text/csv`,YQ=`image/`,XQ=`application/pdf`,ZQ=`video/`,QQ=[`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/msword`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.ms-powerpoint`],$Q=e=>e===JQ||JQ.includes(e),e$=e=>e.startsWith(YQ)||YQ.includes(e),t$=e=>e===XQ||XQ.includes(e),n$=e=>e.startsWith(ZQ)||ZQ.includes(e),r$=e=>QQ.includes(e);function i$(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))});let a=i.createElement(`style`);return a.textContent=`
1256
1256
  @media print {
1257
1257
  body {
1258
1258
  margin: 24px;
@@ -1377,30 +1377,30 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
1377
1377
  page-break-inside: avoid;
1378
1378
  }
1379
1379
  }
1380
- `,i.head.appendChild(a),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}const r$={max_hw:import.meta.env?.VITE_RENDITION_HW||256,format:hn.jpeg,generate_if_missing:!0},i$=`vertesia.content_store.renditionId`;async function a$(e,t,n,r,i){if(!t?.content?.type||!(QQ(t.content.type)||e$(t.content.type)||$Q(t.content.type))){i(`No preview available`);return}i(`Preparing preview...`);let a=Date.now()/1e3,o=localStorage.getItem(`${i$}_${t.id}_${r$.max_hw}`),s=localStorage.getItem(`${i$}_${t.id}_${r$.max_hw}_time`);if(o?.length&&s&&Math.abs(a-parseInt(s,10))<=900)return n(o),r(`${t.name} Rendition`),i(`ready`),o;i(`Preparing preview...`),e.objects.getRendition(t.id,r$).then(a=>{if(a.status===`generating`)i(`Preparing preview...`),n(``),r(``),setTimeout(()=>a$(e,t,n,r,i),6e4);else if(a.status===`failed`){i(`No preview available`),n(``),r(``);return}else{if(!a?.renditions?.length){i(`No preview available`),n(``),r(``);return}let e=a.renditions[0];localStorage.setItem(`${i$}_${t.id}_${r$.max_hw}`,e),localStorage.setItem(`${i$}_${t.id}_${r$.max_hw}_time`,(Date.now()/1e3).toString()),n(e),r(`${t.name} Rendition`),i(`ready`),console.log(`Rendition for document ${t.id} retrieved successfully: ${e}`)}}).catch(e=>{i(`No preview available`),console.warn(`Failed to retrieve rendition:`,e),n(``),r(``)})}function o$(e,t=7){return e?`~${e.slice(-t)}`:``}function s$(e,t){return e.length>t?`${e.substring(0,t)}...`:e}function c$(e){switch(e){case En.RUNNING:return`text-info`;case En.COMPLETED:return`text-success`;case En.FAILED:return`text-destructive`;case En.TERMINATED:case En.CANCELED:return`text-attention`;default:return`text-muted`}}function l$(e){switch(e){case En.RUNNING:return`Running`;case En.COMPLETED:return`Completed`;case En.FAILED:return`Failed`;case En.CONTINUED_AS_NEW:return`Continued As New`;case En.TERMINATED:return`Terminated`;case En.TIMED_OUT:return`Timed Out`;case En.CANCELED:return`Canceled`;default:return`Unknown`}}Q();function u$(e){return typeof e==`object`&&!!e}function d$(e,t){if(!u$(e))return;let n=e[t];return typeof n==`string`?n:void 0}function f$(e){return typeof e==`string`?e:d$(e,`id`)||``}function p$(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e)}const m$={string(e,r){let i=[];if(e){let t=e.get(`slice`);t&&i.push(e=>e.slice(parseInt(t,10)));let n=e.get(`max_length`);n&&i.push(e=>e.slice(0,parseInt(n,10))),e.has(`upper`)&&i.push(e=>e.toUpperCase()),e.has(`lower`)&&i.push(e=>e.toLowerCase()),e.has(`capitalize`)&&i.push(e=>e[0].toUpperCase()+e.substring(1)),e.has(`ellipsis`)&&i.push(e=>`${e}...`)}return(e,r,a)=>{let o;if(e){if(o=String(e),i.length>0)for(let e of i)o=e(o)}else o=``;return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:o}),a]}):o},r)}},fileSize(e,n){return(e,n)=>{let r=``;if(e){let t=Number(e);if(Number.isNaN(t))r=String(e);else{let e=[`Bytes`,`KB`,`MB`,`GB`,`TB`];if(t===0)r=`0 Bytes`;else{let n=Math.floor(Math.log(t)/Math.log(1024));r=`${(t/1024**n).toFixed(2)} ${e[n]}`}}}return t(`td`,{className:`group/field`,children:r},n)}},number(e,n){let r,i;e&&(r=e.get(`currency`)||void 0,i=e.get(`decimals`)||void 0);let a=i?parseInt(i,10):2;return(e,n)=>{let i=Number(e),o=new Intl.NumberFormat(`en-US`,{style:r?`currency`:`decimal`,currency:r,maximumFractionDigits:a}).format(Number.isFinite(i)?i:0);return t(`td`,{className:`group/field`,children:o},n)}},objectId(e,r){let i=[],a=!1;if(e){let t=e.get(`slice`);t&&(a=!0,i.push(e=>e.slice(parseInt(t,10))))}return(e,s,c)=>{let l=f$(e),u=i.reduce((e,t)=>t(e),l);return n(`td`,{className:`flex justify-start items-center gap-2 group/field`,children:[t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(l)},children:t(jg,{className:`size-4`})}),a?`~`:``,u,c]},s)}},objectName(e,r){let i=`title`;return e&&(i=e.get(`title`)||`title`),(e,r,a)=>{let o=(u$(e)&&u$(e.properties)?e.properties:void 0)?.[i],s=p$(o),c=d$(e,`name`),l=d$(e,`id`),u=s||c||(l?o$(l):``);return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:u}),a]}):u},r)}},objectLink(e,r){let i=[];return i.push(e=>e.slice(-7)),(e,a)=>{let s=f$(e),c=i.reduce((e,t)=>t(e),s);return n(`td`,{className:`flex justify-between items-center gap-2 max-w-48 group/field`,children:[`~`,c,t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(s)},children:t(jg,{className:`size-4`})})]},a)}},typeLink(e,r){return(e,r,i)=>{let a=d$(e,`name`)||`n/a`;return t(`td`,{className:`group/field`,children:i?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:a}),i]}):a},r)}},revision(e,r){return(e,r)=>{let i=u$(e)&&u$(e.revision)?e.revision:void 0;if(!i)return t(`td`,{},r);let a=d$(i,`root`),o=d$(i,`label`);return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex flex-col gap-0.5`,children:[a&&n(`div`,{className:`flex items-center gap-1`,children:[n(`span`,{className:`text-xs text-muted font-mono`,children:[`root: ~`,a.slice(-7)]}),t(`a`,{href:`/store/objects/${a}`,onClick:e=>e.stopPropagation(),children:t(Og,{className:`size-3 text-muted`})})]}),o&&n(`span`,{className:`text-xs text-muted`,children:[`label: `,o]})]})},r)}},date(e,r){let i=`fromNow`,a;if(e){let t=e.get(`localized`);if(t)i=`format`,a=t;else{let t=e.get(`relative`);t&&(i=t)}}return(e,r,o)=>{let s=typeof e==`string`||typeof e==`number`||e instanceof Date?e:void 0;if(s===void 0)return t(`td`,{children:o},r);let c=GD(s),l=i===`format`?c.format(a):i===`toNow`?c.toNow():c.fromNow();return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2`,children:[t(We,{description:c.format(`LLL`),children:l}),o]})},r)}}},h$=m$.string();function g$(e){return typeof e==`object`&&!!e}function _$(e,t){let n=e;if(!n)return;if(!t.length)return n;let r=t.length-1;for(let e=0;e<r;e++)if(!g$(n)||(n=n[t[e]],!n))return;if(g$(n))return n[t[r]]}function v$(e){return!e||e===`.`?[]:e.split(`.`)}var y$=class{layout;renderer=h$;path;fallbackPath;previewObject;constructor(e,t){if(this.layout=e,this.path=v$(e.field||``),this.fallbackPath=e.fallback?v$(e.fallback):void 0,this.previewObject=t,e.render)this.renderer=(e,t)=>null;else{let t=e.type||`string`,n=t.indexOf(`?`);if(n>0){let e=t.substring(0,n),r=new URLSearchParams(t.substring(n+1));this.renderer=m$[e](r)}else this.renderer=m$[t]()}}get name(){return this.layout.name}resolveValue(e){let t=_$(e,this.path);return t===void 0&&this.fallbackPath&&(t=_$(e,this.fallbackPath)),t===void 0&&(t=this.layout.default),t}render(e,n){if(this.layout.render)return t(`td`,{className:`whitespace-nowrap px-3 py-4 text-sm group`,children:this.layout.render(e)},n);let r=this.layout.type||`string`,i=r.indexOf(`?`)>0?r.substring(0,r.indexOf(`?`)):r,a=this.buildActions(e,i);if((i===`objectId`||i===`objectLink`)&&this.previewObject){let t=r.indexOf(`?`),o=t>0?new URLSearchParams(r.substring(t+1)):void 0;return m$[i](o,t=>{this.previewObject?.(e.id)})(e,n,a)}return this.renderer(this.resolveValue(e),n,a)}buildActions(e,n){let r=this.layout.field;if(n===`objectId`||n===`objectLink`||r===`id`)return t(GQ,{field:`id`,value:e.id,label:e.id,copyContent:e.id});if(n===`objectName`||r===`name`)return t(GQ,{field:`name`,value:e.name,label:e.name??e.id});if(n===`typeLink`||r===`type.name`||r===`type`){let n=e.type?.id;return t(GQ,{field:`type`,value:n,label:e.type?.name??n??`type`})}if(r===`status`)return t(GQ,{field:`status`,value:e.status,label:e.status})}};Q();function b$({isLoading:e=!1,counts:r=6}){return e?t(`div`,{className:`flex flex-wrap gap-2 justify-between`,children:Array(r).fill(0).map((e,r)=>t(`div`,{className:`w-[15vw] animate-pulse`,children:n(s,{className:`relative flex flex-col border h-fit`,children:[t(`div`,{className:`h-48 bg-muted rounded-t-xl flex items-center justify-center text-muted`,children:`\xA0`}),t(Ee,{className:`bg-muted h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-2`}),t(`div`,{className:`h-4 bg-muted rounded w-1/2`})]}),t(`div`,{className:`text-xs text-muted w-full flex justify-end mt-2`,children:t(`div`,{className:`h-3 bg-muted rounded w-1/4`})})]})]})},`skeleton-${r}`))}):null}function x$({selection:e,document:r,onSelectionChange:i,onRowClick:a,highlightRow:l,previewObject:u,selectedObject:d}){let{client:f}=q(),[p,m]=G(void 0),[h,g]=G(void 0),[_,v]=G(void 0),y=typeof r.properties?.title==`string`?r.properties.title:r.name,b=e=>{e.stopPropagation(),i(r,e)};H(()=>{r?.content&&a$(f,r,m,g,v)},[f,r]);let x=l?.(r);return n(s,{className:`relative flex flex-col border h-fit w-full ${d?.id===r.id?`border-attention border-4`:``} ${x?`border-blue-400 dark:border-blue-500 bg-blue-50/50 dark:bg-blue-900/20`:``}`,onClick:()=>a?.(r),children:[x&&t(`div`,{className:`absolute top-2 end-8 z-10`,children:t(th,{className:`size-4 text-blue-600 dark:text-blue-400`})}),e&&t(`div`,{className:`absolute top-2 start-2 z-10 flex flex-col items-center gap-1`,children:t(`input`,{checked:e.isSelected(r.id),type:`checkbox`,onChange:b,onClick:e=>e.stopPropagation()})}),t(`div`,{className:`absolute top-1 end-1 z-10 flex flex-col items-center`,children:t(o,{variant:`ghost`,size:`sm`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),u?.(r.id)},children:t(jg,{className:`size-4 ${_===`ready`?`text-muted`:`text-white`}`})})}),p&&_===`ready`?t(`img`,{src:p,alt:h,className:`w-auto h-48 object-cover rounded-t-xl`}):t(`div`,{className:`h-48 bg-gray-700 rounded-t-xl flex items-center justify-center text-muted`,children:_}),t(Ee,{className:`bg-gray-200 h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(We,{placement:`top`,description:y,children:t(`h3`,{className:`text-start font-medium leading-none truncate`,children:y})}),r?.type?.name?t(We,{placement:`bottom`,size:`xs`,description:r?.type?.name,children:t(`p`,{className:`text-start text-xs text-muted truncate`,children:r?.type?.name})}):t(`p`,{className:`text-xs text-muted`,children:` `})]}),r.score&&n(`div`,{className:`text-xs text-muted w-full flex justify-end`,children:[`Score: `,r.score.toFixed(4)??`-`]})]})]})}Q();function S$({objects:e,selection:r,isLoading:i,columns:a,onRowClick:o,highlightRow:s,selectedObject:c,toggleAll:l,onSelectionChange:u}){let{t:d}=K();return n(Le,{className:`w-full`,children:[t(Fe,{children:n(`tr`,{children:[r&&t(`th`,{children:t(`input`,{type:`checkbox`,onChange:l})}),a.map(e=>t(`th`,{children:e.name},e.name))]})}),n(Pe,{isLoading:i,columns:a.length+1,children:[e?.map(e=>{let i=s?.(e);return n(`tr`,{className:`group cursor-pointer hover:bg-muted ${c?.id===e.id?`bg-muted`:``} ${i?`bg-blue-50 dark:bg-blue-900/20`:``}`,onClick:()=>{o?.(e)},children:[r&&t(`td`,{onClick:e=>e.stopPropagation(),children:t(`input`,{checked:r.isSelected(e.id),type:`checkbox`,className:`${r.isSelected(e.id)?``:`hidden group-hover:block`}`,onChange:t=>u(e,t)})}),a.map((t,n)=>t.render(e,n)),t(`td`,{className:`w-8 text-center`,children:i&&t(th,{className:`size-4 text-blue-600 dark:text-blue-400 inline-block`})})]},e.id)}),e.length===0&&t(`tr`,{children:t(`td`,{colSpan:a.length+ +!!r,className:`text-center`,children:d(`store.noObjectsDragAndDrop`)})})]})]})}function C$({objects:r,selection:i,isLoading:a,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u}){return n(e,{children:[t(b$,{isLoading:a}),t(`div`,{className:`w-full gap-2 grid xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-4 lg:grid-cols-6 @xs:grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3 @lg:grid-cols-4`,children:r.map(e=>t(x$,{document:e,selection:i,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u},e.id))})]})}var w$=class{client;limit;collectionId;facets=new De({});result=new De({objects:[],isLoading:!1});initialized=!1;facetSpecs=[];query={};deletedIds=new Set;loadedCount=0;constructor(e,t=100){this.client=e,this.limit=t}withFacets(e){return this.facetSpecs=e,this}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}get hasMore(){return this.result.value.hasMore||!1}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}setDefaultKeys(e){}clearFilters(e=!0){let{parent:t,full_text:n,vector:r,weights:i,score_aggregation:a,dynamic_scaling:o,limit:s,all_revisions:c}=this.query;this.query={parent:t,...n!==void 0&&{full_text:n},...r!==void 0&&{vector:r},...i!==void 0&&{weights:i},...a!==void 0&&{score_aggregation:a},...o!==void 0&&{dynamic_scaling:o},...s!==void 0&&{limit:s},...c!==void 0&&{all_revisions:c}},e&&this.search()}getFacetBuckets(e){let t=this.facets.value[e];return Array.isArray(t)?t:[]}resetFacets(){this.query={}}removeDeletedObjects(e){if(e.length===0)return;for(let t of e)this.deletedIds.add(t);let t=this.result.value,n=t.objects.filter(e=>!this.deletedIds.has(e.id)),r=t.objects.length-n.length;this.result.value={...t,objects:n};let i=this.facets.value;r>0&&typeof i.total==`number`&&(this.facets.value={...i,total:Math.max(0,i.total-r)})}reset(e=!1){this.initialized=!1,this.deletedIds.clear(),this.loadedCount=0,this.result.value={objects:[],isLoading:e,hasMore:!0}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error,hasMore:t.hasMore}}_searchRequest(e,t,n,r=!0){let i={limit:t,offset:n,query:e,facets:r?this.facetSpecs:void 0};return this.collectionId?this.client.collections.searchMembers(this.collectionId,i):this.client.objects.search(i)}_facetsRequest(){let e={facets:this.facetSpecs,query:this.query};return this.collectionId?this.client.collections.computeFacets(this.collectionId,e):this.client.objects.computeFacets(e)}computeFacets(e){this._facetsRequest().then(e=>{this.facets.value=e})}async _search(e=!1,t=!1){if(this.isRunning&&e)return!1;let n=this.result.value;e||(this.initialized=!0),this.result.value={isLoading:!0,objects:e?this.objects:[],hasMore:!e||this.result.value.hasMore};let r=this.limit,i=e?this.loadedCount:0;try{let n=await this._searchRequest(this.query,r,i,!t),a=n.results||[],o=n.facets||{};if(this.loadedCount=e?this.loadedCount+a.length:a.length,!e&&this.deletedIds.size>0)for(let e of[...this.deletedIds])a.some(t=>t.id===e)||this.deletedIds.delete(e);let s=this.deletedIds.size>0?a.filter(e=>!this.deletedIds.has(e.id)):a;return this.result.value={isLoading:!1,objects:e?this.objects.concat(s):s,hasMore:a.length===r},!t&&o&&Object.keys(o).length>0&&(this.facets.value=o),!0}catch(e){if(typeof e==`object`&&e&&`status`in e&&e.status===404)return this.result.value={isLoading:!1,objects:[],hasMore:!1},!1;let t=e instanceof Error?e:Error(String(e));return this.result.value={error:t,isLoading:!1,objects:n.objects,hasMore:!1},!1}}search(e=!1){return this.isRunning?Promise.resolve(!1):this._search(!1,e)}loadMore(e=!1){return this.isRunning||!this.hasMore||this.query.vector?Promise.resolve(!1):(this.objects.length>0&&(e=!0),this._search(!0,e))}};const T$=dt(void 0);function E$(){return _t(T$)}function D$(){return rt(E$().facets)}function O$(){let e=E$();return{...rt(e.result),search:e}}function k$(){let e=E$();return rt(e.facets).total}const A$=Xt.getFixedT(null,Yt);var j$;(function(e){e.CREATE=`create`,e.SKIP=`skip`,e.UPDATE=`update`})(j$||={});async function M$(e){try{let t=await e.arrayBuffer(),n=new rr;return n.appendByteArray(new Uint8Array(t)),n.end()?.toString()}catch(e){console.error(`Error calculating file hash:`,e);return}}async function N$(e,t){let n=[];for(let r=0;r<e.length;r+=5){let i=e.slice(r,r+5),a=await Promise.all(i.map(async e=>{let n=t||`/`;if(e.webkitRelativePath){let r=e.webkitRelativePath.split(`/`);if(r.length>1){let e=r.slice(0,-1).join(`/`);n=t?`${t}/${e}`:e}}return{file:e,hash:await M$(e),name:e.name,size:e.size,location:n}}));n.push(...a)}return n}function P$(){let{client:e}=q(),t=nt();return{checkDocumentProcessing:V(async(n,r,i)=>{try{console.log(`Preparing metadata for ${n.length} files...`);let t=await N$(n,r);return await(async()=>{let n=t.map(e=>e.hash).filter(Boolean);if(n.length===0)return;let r={"content.etag":{$in:n}},a;if(i){let t={query:{match:r},select:`id content.etag`};a=(await e.store.collections.searchMembers(i,t)).results.filter(e=>typeof e.id==`string`)}else{let t={query:r,select:`id content.etag`};a=(await e.store.objects.find(t)).flatMap(e=>typeof e.id==`string`?[{id:e.id,content:e.content}]:[])}for(let e of a){let n=t.find(t=>t.hash===e.content?.etag);n&&(n.existingId=e.id,n.action=j$.SKIP)}})(),await(async()=>{let n=t.filter(e=>e.action!==j$.SKIP),r=n.map(e=>e.location),a=Array.from(new Set(r)),o=[];for(let t of a){let r={"content.name":{$in:n.filter(e=>e.location===t).map(e=>e.name)},location:t||`/`};if(i){let t=e.store.collections.searchMembers(i,{query:{match:r},select:`id content.name location`}).then(e=>e.results);o.push(t)}else{let t=e.store.objects.find({query:r,select:`id content.name location`});o.push(t)}}let s=(await Promise.all(o)).flat();console.log(`Found ${s.length} document to update`,s);for(let e of s){let n=t.find(t=>t.name===e.content?.name&&(t.location?t.location===e.location:e.location===`/`));n&&(n.existingId=e.id,n.action=j$.UPDATE)}console.log(`Reconciled ${t.filter(e=>e.action===j$.UPDATE).length}`)})(),t.forEach(e=>{e.action||=j$.CREATE}),console.log(`Document processing check results:`,{totalFiles:n.length,toCreate:t.filter(e=>e.action===j$.CREATE).length,toUpdate:t.filter(e=>e.action===j$.UPDATE).length,toSkip:t.filter(e=>e.action===j$.SKIP).length}),t}catch(e){throw t({title:A$(`store.errorInUploadProcessingCheck`),status:`error`,description:Ge(e)}),console.log(`Error in file upload processing check`,e),Error(`Error in file upload processing check: ${Ge(e)}`,{cause:e})}},[e,t])}}Q();function F$({isOpen:r,onClose:i,files:a,collectionId:s,selectedFolder:c,title:l,children:u,onUploadComplete:d,hideFileSelection:f=!1,showTypeSelectionOnly:p=!1,allowFolders:m=!0,initialTypeId:h,defaultProperties:g}){let{client:_}=q(),{registry:v}=UZ(),y=nt(),{t:b}=K(),x=l??b(`upload.uploadFiles`),[S,C]=G([]),[w,T]=G([]),[E,D]=G(!1),[O,k]=G(null),[A,j]=G([]),[M,N]=G(!1),[P,F]=G(!1),[I,L]=G(0),[ee,R]=G(Date.now()),[te,ne]=G(void 0),[re,ie]=G(null),[ae,de]=G(x),[fe,pe]=G(``);H(()=>{s&&_.store.collections.retrieve(s).then(ne)},[_.store.collections.retrieve,s]),H(()=>{M?(de(b(`upload.uploadingFiles`)),pe(`${Math.round(I)}% complete`)):P?(de(b(`upload.uploadComplete`)),pe(``)):E?(de(b(`upload.fileAnalysisResults`)),pe(`${S.length} file${S.length===1?``:`s`}`)):S.length>0?(de(x),pe(b(`upload.checkingForDuplicates`))):(de(x),pe(``))},[M,P,E,x,I,S.length,b]);let me=()=>!te&&!c?null:n(oe,{className:`mb-4`,status:`default`,icon:t(s_,{className:`size-5`}),children:[t(`div`,{className:`flex items-center`,children:t(`span`,{className:`font-medium`,children:b(`upload.uploadLocation`)})}),n(`div`,{className:`text-sm mt-1`,children:[te&&n(`div`,{className:`flex items-center`,children:[t(`span`,{className:`me-1`,children:b(`upload.collectionLabel`)}),t(`span`,{className:`font-medium`,children:te.name})]}),c&&n(`div`,{className:`flex items-center mt-1`,children:[t(`span`,{className:`me-1`,children:b(`upload.folderLabel`)}),t(`span`,{className:`font-medium`,children:c})]})]})]}),[he,ge]=G({toCreate:0,toUpdate:0,toSkip:0}),{checkDocumentProcessing:_e}=P$(),ve=U(()=>v?.types||[],[v?.types]),ye=V(async e=>{if(e.length)try{console.log(`Processing ${e.length} files to determine required actions...`);let t=await _e(e,c,s);T(t);let n=t.filter(e=>e.action===j$.CREATE).length,r=t.filter(e=>e.action===j$.UPDATE).length,i=t.filter(e=>e.action===j$.SKIP).length;ge({toCreate:n,toUpdate:r,toSkip:i}),y({title:b(`upload.filesAnalyzed`),description:`${e.length} file(s): ${n} new, ${r} to update, ${i} to skip`,status:`info`,duration:4e3}),D(!0)}catch(e){console.error(`Error processing files:`,e),y({title:b(`agent.error`),description:b(`upload.errorAnalyzingFiles`),status:`error`,duration:5e3})}},[_e,s,c,b,y]);H(()=>{r&&(T([]),D(!1),k(h?v?.getType(h)??null:null),j([]),N(!1),F(!1),L(0),ge({toCreate:0,toUpdate:0,toSkip:0}),ie(null),de(x),pe(``),a&&a.length>0?(C(a),ye(a)):C([]),R(Date.now()))},[a,h,r,ye,x,v]);let be=()=>{C([]),T([]),D(!1),k(null),j([]),N(!1),F(!1),L(0),ge({toCreate:0,toUpdate:0,toSkip:0}),ie(null),de(x),pe(``),R(Date.now()),i()},xe=e=>{e&&e.length>0&&(C(e),ye(e))},Se=async()=>{if(!w.length)return;let e=O?.id||null,t=w.map(e=>({file:e.file,status:`pending`,progress:0,action:e.action===j$.CREATE?`create`:e.action===j$.UPDATE?`update`:`skip`}));j(t),N(!0),F(!1);let n=w.filter(e=>e.action===j$.SKIP),r=w.filter(e=>e.action===j$.UPDATE),i=w.filter(e=>e.action===j$.CREATE),a={success:!0,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};for(let t of n)t.existingId&&(a.objectIds.push(t.existingId),a.skippedFiles.push({id:t.existingId,name:t.name,type:e,status:`skipped`,location:t.location}),j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)));let o=async(t,n)=>{let r=[];for(let e=0;e<t.length;e+=50)r.push(t.slice(e,e+50));for(let i=0;i<r.length;i++){let o=r[i];if(console.log(`Processing ${n} batch ${i+1}/${r.length} (${o.length} files)`),t.length>50){let e=i*50;y({title:b(`upload.processingFilesAction`,{action:n}),description:b(`upload.processedCount`,{processed:e,total:t.length}),status:`info`,duration:2e3})}let c=0;await Promise.all(o.map(async t=>{try{if(j(e=>e.map(e=>e.file===t.file?{...e,status:`uploading`,progress:20}:e)),n===`update`&&t.existingId)await _.store.objects.update(t.existingId,{type:e||void 0,content:t.file,location:t.location,name:t.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`}),j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)),a.objectIds.push(t.existingId),a.uploadedFiles.push({id:t.existingId,name:t.name,type:e,status:`updated`,location:t.location});else{let n=await _.store.objects.create({type:e||void 0,content:t.file,location:t.location||t.file.webkitRelativePath||t.name,properties:g},{collection_id:s});j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:n.id}:e)),a.objectIds.push(n.id),a.uploadedFiles.push({id:n.id,name:t.name,type:e,status:`created`,location:t.location})}}catch(n){console.error(`Failed to process file ${t.name}:`,n),j(e=>e.map(e=>e.file===t.file?{...e,status:`error`,progress:100,message:Ge(n,`Unknown error`)}:e)),a.failedFiles.push({name:t.name,error:Ge(n,`Unknown error`),status:`failed`,location:t.location,type:e}),a.success=!1}c++,(c%5==0||c===o.length)&&j(e=>{let t=e.filter(e=>e.status===`success`||e.status===`error`).length,n=e.length,r=n>0?Math.round(t/n*100):0;return L(r),e})}))}};r.length>0&&await o(r,`update`),i.length>0&&await o(i,`create`),j(e=>{let t=e.filter(e=>e.status===`pending`).map(e=>({...e,status:`error`,progress:100,message:b(`upload.uploadProcessInterrupted`)}));return t.length>0?(t.forEach(e=>{a.failedFiles.push({name:e.file.name,error:b(`upload.uploadProcessInterrupted`),status:`failed`,type:O?.id||null})}),a.success=!1,e.map(e=>e.status===`pending`?{...e,status:`error`,progress:100,message:b(`upload.uploadProcessInterrupted`)}:e)):e}),N(!1),F(!0);let c=a.uploadedFiles.filter(e=>e.status===`created`).length,l=a.uploadedFiles.filter(e=>e.status===`updated`).length,u=a.skippedFiles.length,d=a.failedFiles.length,f=``;c>0&&(f+=`${c} file${c===1?``:`s`} uploaded`),l>0&&(f+=f?`, `:``,f+=`${l} file${l===1?``:`s`} updated`),u>0&&(f+=f?`, `:``,f+=`${u} file${u===1?``:`s`} skipped`),d>0&&(f+=f?`, `:``,f+=`${d} file${d===1?``:`s`} failed`),y({title:b(`upload.uploadComplete`),description:f,status:d>0?`warning`:`success`,duration:5e3}),ie(a)},Ce=()=>n(`div`,{className:`mb-4`,children:[n(`div`,{className:`block text-sm font-medium mb-2`,children:[b(`store.contentType`),` `,t(`span`,{className:`text-muted font-normal`,children:b(`store.optional`)}),t(We,{description:b(`upload.contentTypeTooltip`),placement:`top`,size:`xs`,children:t(j_,{className:`size-3 ms-2`})})]}),t(we,{options:ve,value:O,optionLabel:e=>e?e.name:b(`store.selectContentTypeLabel`),placeholder:b(`store.selectContentTypeAuto`),onChange:e=>k(e===void 0?null:e),filterBy:`name`,isClearable:!0}),!O&&t(`div`,{className:`p-2 rounded-md`,children:n(`div`,{className:`flex items-center text-attention`,children:[t(Ph,{className:`size-4 me-1`}),b(`store.automaticTypeDetection`),t(We,{description:b(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(j_,{className:`size-3 ms-2`})})]})})]});return n(se,{isOpen:r,onClose:be,className:`mx-auto`,disableCloseOnClickOutside:!0,children:[t(ue,{description:fe,children:ae}),p?n(ce,{children:[u,me(),Ce()]}):S.length===0&&!f?n(ce,{className:`flex flex-col items-center justify-center p-8`,children:[me(),t(Ot,{onDrop:xe,message:b(`upload.dragAndDrop`),buttonLabel:b(`upload.selectFiles`),className:`w-full h-64`,allowFolders:m}),u]}):!M&&!P?t(ce,{children:E?n(e,{children:[me(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`p-4 rounded-md mb-4`,children:n(`div`,{className:`grid grid-cols-3 gap-4`,children:[n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(Tb,{className:`size-5 text-primary`}),t(`span`,{className:`font-medium`,children:b(`upload.new`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:he.toCreate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(Ph,{className:`size-5 text-success`}),t(`span`,{className:`font-medium`,children:b(`upload.update`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:he.toUpdate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(jh,{className:`size-5 text-mixer-attention/40`}),t(`span`,{className:`font-medium`,children:b(`upload.skip`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:he.toSkip})]})]})})}),Ce(),t(oe,{className:`mb-4`,status:`info`,children:he.toCreate+he.toUpdate>0?n(`div`,{className:`space-y-1`,children:[t(`p`,{children:b(`upload.filesReadyToProcess`,{count:he.toCreate+he.toUpdate})}),t(`p`,{children:he.toSkip>0&&b(`upload.filesToSkip`,{count:he.toSkip})})]}):he.toSkip>0?t(`span`,{children:b(`upload.allFilesExist`,{count:he.toSkip})}):t(`span`,{children:b(`upload.noFilesToProcess`)})})]}):n(`div`,{className:`flex flex-col items-center justify-center py-4`,children:[t(je,{size:`lg`,className:`mb-4`}),t(`div`,{className:`text-lg font-medium`,children:b(`upload.analyzingFiles`)})]})}):M?n(ce,{children:[me(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`h-2 bg-muted/20 rounded-full overflow-hidden`,children:t(`div`,{className:`h-full bg-primary rounded-full`,style:{width:`${I}%`}})})}),t(`div`,{className:`max-h-96 overflow-y-auto`,children:A.map((e,r)=>n(`div`,{className:`flex items-center py-2 border-b border-border last:border-b-0`,children:[n(`div`,{className:`me-3`,children:[e.status===`pending`&&t(Qg,{className:`size-5 text-muted`}),e.status===`uploading`&&t(je,{size:`sm`}),e.status===`success`&&t(Ph,{className:`size-5 text-success`}),e.status===`error`&&t(Kh,{className:`size-5 text-destructive`})]}),n(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`truncate font-medium`,children:e.file.name}),n(`div`,{className:`text-xs text-muted`,children:[e.status===`pending`&&b(`agent.waiting`),e.status===`uploading`&&b(`agent.uploading`),e.status===`success`&&(e.action===`create`?b(`store.created`):e.action===`update`?b(`store.updated`):b(`upload.skip`)),e.status===`error`&&e.message]})]})]},`${e.file.name}-${e.file.size}-${e.file.lastModified}`))})]}):t(ce,{children:n(`div`,{className:`mb-4`,children:[me(),t(Lt,{files:A.map(e=>{let t;return t=e.status===`success`?e.action===`create`?`success`:e.action===`update`?`updated`:`skipped`:`failed`,{name:e.file.name,status:t,error:e.status===`error`?e.message:void 0}}),location:c||void 0,collection:te?.name})]})}),(()=>{if(p)return n(le,{children:[t(o,{variant:`ghost`,onClick:be,children:b(`modal.cancel`)}),t(o,{onClick:()=>{let e={success:!0,objectIds:[],uploadedFiles:[{name:`type-selection`,type:O?.id||null,status:`created`}],skippedFiles:[],failedFiles:[]};d&&d(e),be()},children:O?b(`upload.useTypeName`,{typeName:O.name}):b(`upload.useAutoDetection`)})]});if(S.length===0&&!f)return t(le,{children:t(o,{variant:`ghost`,onClick:be,children:b(`modal.cancel`)})});if(!M&&!P){let e=E;return n(le,{children:[t(o,{variant:`ghost`,onClick:be,children:b(`modal.cancel`)}),t(o,{disabled:!e,onClick:Se,children:he.toCreate+he.toUpdate>0?b(`agent.upload`):b(`upload.continue`)})]})}return M?t(le,{children:t(o,{variant:`ghost`,disabled:!0,children:b(`agent.uploading`)})}):n(le,{children:[t(o,{variant:`ghost`,onClick:()=>{C([]),T([]),D(!1),k(null),j([]),N(!1),F(!1),L(0),ge({toCreate:0,toUpdate:0,toSkip:0})},children:b(`upload.uploadMore`)}),t(o,{onClick:()=>{d&&re&&d(re),be()},children:b(`agent.close`)})]})})()]},ee)}function I$(e){let t=typeof e==`function`?e:e.onUploadDone,{client:n,project:r,store:i}=q(),a=E$(),o=nt(),s=Xt.getFixedT(null,Yt),{checkDocumentProcessing:c}=P$();return async(e,l,u)=>{let d={success:!1,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};if(!r)return o({status:`error`,title:s(`store.noProjectSelected`),duration:3e3}),d;if(!e||e.length===0)return o({status:`warning`,title:s(`store.noFilesSelected`),duration:3e3}),d;let f=Array.from(e).filter(e=>e.size>0);if(f.length===0)return o({status:`error`,title:s(`store.noValidFilesSelected`),description:s(`store.pleaseSelectValidFiles`),duration:5e3}),d;let p=[],m=[],h=[];console.log(`Processing ${f.length} files with smart file processing...`);let g=await c(f,null,u),_=g.filter(e=>e.action===j$.CREATE).length,v=g.filter(e=>e.action===j$.UPDATE).length,y=g.filter(e=>e.action===j$.SKIP).length;o({title:s(`store.filesAnalyzedTitle`),description:`${f.length} file(s): ${_} new, ${v} to update, ${y} to skip`,status:`info`,duration:4e3});for(let e of g.filter(e=>e.action===j$.SKIP&&e.existingId))p.push({id:e.existingId,name:e.name,type:l,status:`skipped`,location:e.location});let b=g.filter(e=>(e.action===j$.CREATE||e.action===j$.UPDATE)&&e.file);if(b.length>0){console.log(`Processing ${b.length} files (${b.filter(e=>e.action===j$.CREATE).length} create, ${b.filter(e=>e.action===j$.UPDATE).length} update)...`);let e=[];for(let t=0;t<b.length;t+=50)e.push(b.slice(t,t+50));for(let t=0;t<e.length;t++){let r=e[t],a=t*50;console.log(`Processing batch ${t+1}/${e.length} (${r.length} files)`),b.length>50&&o({title:s(`store.processingFiles`),description:`Processed ${a}/${b.length} files...`,status:`info`,duration:2e3});let c=await Promise.all(r.map(async e=>{try{if(e.action===j$.UPDATE&&e.existingId){let t=await n.store.objects.update(e.existingId,{type:l||void 0,content:e.file,location:e.location,name:e.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`});return m.push({id:e.existingId,name:e.name,type:l,status:`updated`,location:e.location}),d.objectIds.push(e.existingId),{success:!0,id:t.id,name:e.name,action:`update`}}{let t=u?{collection_id:u}:void 0,n=await i.objects.create({type:l||void 0,content:e.file,location:e.location||e.file.webkitRelativePath||e.name},t);m.push({id:n.id,name:e.name,type:l,status:`created`,location:e.location})}}catch(t){console.error(`Failed to process file ${e.name}:`,t),h.push({name:e.name,error:Ge(t,`Unknown error`),status:`failed`,location:e.location,type:l}),o({status:`error`,title:s(`store.processingFailedFor`,{name:e.name}),description:Ge(t),duration:4e3})}})),f=m.filter(e=>e.status===`created`),p=m.filter(e=>e.status===`updated`),g=m.filter(e=>e.status===`failed`);console.log(`Batch ${t+1} results:`,{creates:f,updates:p,failures:g,total:c.length})}}let x=m.filter(e=>e.status===`created`).length,S=m.filter(e=>e.status===`updated`).length,C=m.filter(e=>e.status===`failed`).length,w=m.filter(e=>e.status===`skipped`).length;t&&(console.log(`Upload complete:`,{totalObjectIds:d.objectIds.length,uploadedFiles:x,updatedFiles:S,skippedFiles:w,failedFiles:C}),await t(d.objectIds));let T=``;return x>0&&(T+=`${x} file${x===1?``:`s`} uploaded`),S>0&&(T+=T?`, `:``,T+=`${S} file${S===1?``:`s`} updated`),w>0&&(T+=T?`, `:``,T+=`${w} file${w===1?``:`s`} skipped (already existed)`),C>0&&(T+=T?`, `:``,T+=`${C} file${C===1?``:`s`} failed`),T&&o({status:C>0?`warning`:`success`,title:T,duration:4e3}),a.search(),d}}const L$=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function R$({isGridView:e=!1,onUpload:n,collectionId:r,...i}){return n?t(z$,{...i,onUpload:n,isGridView:e,collectionId:r}):t(B$,{...i,isGridView:e})}function z$({isGridView:e,onUpload:r,collectionId:i,skipTypeModal:a=!1,...o}){let[s,c]=G(!1),[l,u]=G([]),[d,f]=G(!1),[p,m]=G(null),[h,g]=G(!1),_=E$(),v=nt(),{t:y}=K(),{checkDocumentProcessing:b}=P$(),x=async(e,t)=>{console.log(`Files dropped on ObjectTable:`,e.length,t),c(!0);try{if(i){let t=await b(e,null,i);m(t);let n=t.filter(e=>e.action===`create`).length,r=t.filter(e=>e.action===`update`).length,a=t.filter(e=>e.action===`skip`).length;v({title:y(`store.filesReadyToProcess`),description:`${e.length} file(s): ${n} new, ${r} to update, ${a} to skip`,status:`info`,duration:4e3})}else m(null)}catch(e){console.error(`Error processing files:`,e),v({title:y(`store.errorProcessingFiles`),description:y(`store.errorCheckingDuplicates`),status:`error`,duration:4e3}),m(null)}finally{if(c(!1),u(e),f(!1),a){console.log(`Skipping type modal and calling onUpload directly`,{filesLength:e.length,processedFilesLength:p?.length});let t=r(e,null,i);t&&typeof t==`object`&&(t.processedFiles=p)}else console.log(`Setting typeSelectionOpen to true`,{filesLength:e.length}),g(!0)}},S=e=>{let t=[...l];u([]),m(null),g(!1),t.length>0&&e!==void 0&&(c(!0),console.log(`Starting upload with`,{typeId:e,filesCount:t.length,hasProcessingResults:!!p,collectionId:i}),r(t,e,i).finally(()=>{c(!1),_.search()}))},C=e=>{e.preventDefault(),e.stopPropagation(),f(!0)};return n(`div`,{className:`min-h-[400px] relative`,onDragOver:C,onDragEnter:C,onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),!e.currentTarget.contains(e.relatedTarget)&&f(!1)},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),f(!1),e.dataTransfer.items){let t=[];for(let n=0;n<e.dataTransfer.items.length;n++){let r=e.dataTransfer.items[n];if(r.kind===`file`){let e=r.getAsFile();e&&t.push(e)}}if(t.length>0){let e={count:t.length,message:`Preparing to upload ${t.length} file${t.length===1?``:`s`}...`};x(t,e)}}},children:[t(`div`,{className:it(`bg-white dark:bg-gray-800 opacity-40 absolute inset-0 z-50 flex justify-center items-center`,s?`block`:`hidden`),children:t(je,{size:`xl`})}),t(B$,{...o,isGridView:e}),t(`div`,{className:it(`absolute inset-0 pointer-events-none`,d?`z-40`:`-z-10`),children:t(`div`,{className:`w-full h-full relative`,children:t(Ot,{onDrop:x,message:`Drop files or folders here to upload`,className:it(`absolute inset-0 bg-white/90 dark:bg-gray-800/90 pointer-events-auto`,d?`flex`:`hidden`),buttonLabel:`Select Files or Folders`,allowFolders:!0})})}),t(F$,{isOpen:h&&l.length>0,onClose:()=>{u([]),m(null),g(!1),S(void 0)},files:l,collectionId:i,selectedFolder:null,title:`Upload Files`,onUploadComplete:e=>{if(e){if(e.failedFiles&&e.failedFiles.length>0&&v({title:y(`store.uploadIssues`),description:`${e.failedFiles.length} file(s) failed to upload`,status:`warning`,duration:5e3}),e.success){let t=e.uploadedFiles.filter(e=>e.status===`created`).length,n=e.uploadedFiles.filter(e=>e.status===`updated`).length,r=e.skippedFiles.length;(t>0||n>0)&&v({title:y(`store.uploadComplete`),description:`${t>0?`${t} created`:``}${t>0&&n>0?`, `:``}${n>0?`${n} updated`:``}${r>0?`, ${r} skipped`:``}`,status:`success`,duration:5e3})}_.search()}u([]),m(null),g(!1),e?.success&&e.objectIds.length>0?S(null):S(void 0)}})]})}function B$({objects:e,layout:n=L$,isLoading:r,onRowClick:i,onSelectionChange:a,highlightRow:o,previewObject:s,selectedObject:c,isGridView:l}){let u=zQ(),d=(t,n)=>{if(u){let r=n.nativeEvent instanceof MouseEvent&&n.nativeEvent.shiftKey;if(!n.target.checked)u.remove(t.id);else if(u.add(t),r){let n=e.findIndex(e=>e.id===t.id),r=V$(e,n,u);if(r>-1&&r<n-1){let t=[];for(let i=r+1;i<n;i++)t.push(e[i]);u.addAll(t)}else{let t=H$(e,n,u);if(t>-1&&t>n+1){let r=[];for(let i=n+1;i<t;i++)r.push(e[i]);u.addAll(r)}}}a?.(u)}},f=t=>{u&&(t.target.checked?u.addAll(e):u.removeAll())},p=U(()=>{let e=n.length>0?n:L$;return console.log(`Using layout with columns:`,e.map(e=>e.name).join(`, `)),e.map(e=>new y$(e,s))},[n,s]);return t(l?C$:S$,{objects:e,isLoading:r,columns:p,onRowClick:i,highlightRow:o,previewObject:s,selectedObject:c,selection:u,toggleAll:f,onSelectionChange:d})}function V$(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}function H$(e,t,n){let r=e.length;for(let i=t+1;i<r;i++)if(n.isSelected(e[i].id))return i;return-1}function U$({children:e,limit:n,parent:r,typeId:i,facets:a,name:o,collectionId:s}){let{store:c}=q(),l=U(()=>{let e;a?e=a:(e=[{name:`status`,field:`status`},{name:`location`,field:`location`}],i||e.unshift({name:`type`,field:`type`}));let t=new w$(c,n).withFacets(e);return t.collectionId=s,t.query.type=i,t.query.parent=r,t.query.name=o,s&&(t.query.all_revisions=!0),t},[s,a,n,o,r,c,i]);return t(T$.Provider,{value:l,children:e})}Q();const W$=`vertesia.content_store.lastDisplayedView`;function G$({onUpdate:e}){let{t:n}=K(),[r,i]=G(localStorage.getItem(W$)===`grid`),a=()=>{r?c():s()},s=()=>{localStorage.setItem(W$,`grid`),i(!0),e(!0)},c=()=>{localStorage.setItem(W$,`table`),i(!1),e(!1)};return t(o,{variant:`outline`,onClick:a,title:n(r?`misc.tableView`:`misc.thumbnailView`),children:t(r?sb:L_,{})})}G$.LAST_DISPLAYED_VIEW=W$,Q();const K$=[{name:`Name`,field:`properties.title`,type:`string`,fallback:`name`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Created At`,field:`created_at`,type:`date`}];function q$({onChange:e,selectedIds:n}){return t(U$,{children:t(J$,{onRowClick:t=>{e(t||void 0)},selectedIds:n})})}function J$({onRowClick:e,selectedIds:r}){let{t:i}=K(),a=V(e=>!!r?.has(e.id),[r]),[s,c]=G(!1),[l,u]=G(localStorage.getItem(`vertesia.content_store.lastDisplayedView`)===`grid`),{search:d,isLoading:f,error:p,objects:m,hasMore:h}=O$(),g=W(null);Qe(g,()=>{s&&h&&!f&&(c(!1),d.loadMore(!0).finally(()=>{c(!0)}))},{threshold:.1,deps:[s,h,f]}),H(()=>{d.search().finally(()=>{c(!0)})},[d]);let _=D$(),v=E$();return p?t(M,{title:i(`store.searchFailed`),children:p.message}):n(`div`,{className:`flex flex-col gap-2 h-full w-full`,children:[n(`div`,{className:`flex justify-between items-center flex-shrink-0`,children:[t(rQ,{facets:_,search:v}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`outline`,onClick:()=>{c(!1),d.search().then(()=>c(!0))},"aria-label":`Refresh`,children:t(gy,{size:16})}),t(G$,{onUpdate:u})]})]}),n(`div`,{className:`@container relative flex-1 overflow-y-auto`,children:[t(R$,{objects:m||[],isLoading:!m.length&&f,layout:K$,onRowClick:e,highlightRow:r?.size?a:void 0,isGridView:l}),t(`div`,{ref:g,className:`h-4 w-full`})]})]})}Q();function Y$(e){let t=Math.max(0,e)/1e3,n=+(t>0&&t<10&&!Number.isInteger(t));return`${new Intl.NumberFormat(void 0,{maximumFractionDigits:n}).format(t)}K`}function X$({onSend:e,onStop:r,approvalModeSlot:i,mcpSlot:a,disabled:s=!1,isSending:c=!1,isStopping:l=!1,isStreaming:u=!1,isCompleted:d=!1,contextWindowUsage:f,onCompactContext:p,isCompactingContext:m=!1,activeTaskCount:h=0,activeWorkstreams:g=[],onSelectWorkstream:_,placeholder:v,onFilesSelected:y,uploadedFiles:b=[],onRemoveFile:x,onRemoveProcessingFile:S,acceptedFileTypes:C,maxFiles:T=5,processingFiles:E,artifactRunId:D,hasProcessingFiles:O=!1,renderDocumentSearch:k,selectedDocuments:A=[],onRemoveDocument:j,hideObjectLinking:M=!1,hideFileUpload:N=!1,disableDropZone:P=!1,className:F,inputClassName:I}){let{t:L}=K(),ee=v??L(`agent.typeYourMessage`),R=W(null),te=W(null),[ne,re]=G(``),[ie,oe]=G(!1),[le,de]=G(!1),[fe,pe]=G(!1),me=!!(y&&!N),he=me&&!P,ge=!M||me||!!k,_e=b.length>=T,ve=S??x,ye=U(()=>g.filter(e=>e.status===`running`||e.status===`canceling`),[g]),be=ye.length||h,xe=f?L(`agent.contextUsageCompactLabel`,{percent:f.usedPercent}):void 0,Se=f?L(`agent.contextTokenUsage`,{used:Y$(f.usedTokens),limit:Y$(f.checkpointTokens)}):void 0,Ce=U(()=>{let e=[];if(!N&&E)for(let t of E.values()){let n=t.preview_url,r=t.status===mn.UPLOADING?L(`agent.uploading`):t.status===mn.PROCESSING?L(`agent.processing`):t.status===mn.ERROR?L(`agent.error`):t.status===mn.READY?L(`agent.ready`):t.status;e.push({id:t.id,name:t.name,contentType:t.content_type,artifactPath:t.artifact_path,previewUrl:n,removable:!!ve,statusLabel:r,statusTone:t.status===mn.ERROR?`destructive`:t.status===mn.READY?`success`:`attention`})}if(!N)for(let t of b)e.push({id:t.id,name:t.name,contentType:t.type,artifactPath:t.artifact_path,previewUrl:t.previewUrl,removable:!!x,statusLabel:L(`agent.ready`),statusTone:`success`});for(let t of A)e.push({id:t.id,name:t.name,href:`/store/objects/${t.id}`,removable:!!j,statusTone:`info`});return e},[ve,N,j,x,E,A,L,b]);H(()=>{!s&&d&&R.current?.focus()},[s,d]);let we=V(e=>{if(!me||!y)return;let t=Array.from(e),n=T-b.length,r=t.slice(0,n);r.length>0&&y(r)},[me,y,T,b.length]),Te=V(e=>{e.preventDefault(),e.stopPropagation(),he&&pe(!0)},[he]),Ee=V(e=>{e.preventDefault(),e.stopPropagation(),pe(!1)},[]),De=V(e=>{e.preventDefault(),e.stopPropagation(),pe(!1),he&&e.dataTransfer?.files&&e.dataTransfer.files.length>0&&we(e.dataTransfer.files)},[he,we]),Oe=V(e=>{if(!me)return;let t=TX(e.clipboardData?.items);t.length>0&&we(t)},[me,we]),ke=V(e=>{me&&e.target.files&&e.target.files.length>0&&(we(e.target.files),e.target.value=``)},[me,we]),Ae=V(()=>{te.current?.click()},[]),Me=V(()=>de(!1),[]),Ne=V(e=>de(!1),[]),Pe=()=>{let t=ne.trim();!t||s||c||O||(e(t),re(``))},Fe=()=>{r&&!l&&r()},Ie=W(0),Le=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),ne.trim().length>0&&Pe();return}e.shiftKey||(e.preventDefault(),Ke(e.currentTarget,re));return}if(e.key===`Escape`&&u&&r){let e=Date.now();e-Ie.current<500?(Fe(),Ie.current=0):Ie.current=e}},Re=V(()=>{let e=R.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]);return H(()=>{Re()},[ne,Re]),n(`div`,{className:z(`px-3 py-3 flex-shrink-0 transition-all fixed lg:sticky bottom-0 start-0 end-0 lg:start-auto lg:end-auto w-full bg-background/95 backdrop-blur z-10`,fe&&he&&`bg-info/10 border-info`,F),onDragOver:he?Te:void 0,onDragLeave:he?Ee:void 0,onDrop:he?De:void 0,children:[fe&&he&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 rounded-lg z-10 pointer-events-none`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2`,children:[t(Tb,{className:`size-5`}),L(`agent.dropFilesToUpload`)]})}),me&&t(`input`,{ref:te,type:`file`,multiple:!0,accept:C,onChange:ke,className:`hidden`}),t(KX,{activeWorkstreams:g,onSelectWorkstream:_}),n(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-2 rounded-2xl border border-border/70 bg-mixer-muted/15 p-2.5 shadow-lg shadow-black/5`,children:[Ce.length>0&&t(zW,{items:Ce,artifactRunId:D,variant:`composer`,onRemove:e=>{E?.has(e)?ve?.(e):b.some(t=>t.id===e)?x?.(e):j?.(e)},className:`gap-1.5`}),t(`div`,{className:`flex min-w-0 flex-1`,children:t(Ue,{ref:R,value:ne,onKeyDown:Le,onChange:e=>re(e.target.value),onPaste:Oe,disabled:s,"aria-label":ee,placeholder:ee,rows:1,style:{maxHeight:`160px`},className:z(`min-h-[44px] resize-none border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,I)})}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[ge&&n(w,{align:`left`,trigger:t(o,{variant:`ghost`,size:`icon`,className:`size-8 rounded-full text-muted hover:bg-muted`,title:L(`agent.addAttachment`),children:t(sy,{className:`size-4`})}),children:[!M&&n(ae,{onClick:()=>oe(!0),isDisabled:!d,children:[t(Uv,{className:`size-4`}),L(`agent.linkObject`)]}),me&&n(ae,{onClick:Ae,isDisabled:_e,children:[t(Tb,{className:`size-4`}),L(`agent.upload`)]}),k&&n(ae,{onClick:()=>de(!0),children:[t(Kg,{className:`size-4`}),t(`span`,{children:L(`agent.searchDocuments`)}),A.length>0&&t(`span`,{className:`ms-auto inline-flex items-center justify-center rounded-full bg-info/20 px-1.5 py-0.5 text-[10px] font-medium text-info`,children:A.length})]})]}),i,a,f&&t(We,{asChild:!0,placement:`top`,size:`md`,className:`text-foreground shadow-lg`,description:n(`span`,{className:`block max-w-56 text-start text-sm leading-6`,children:[t(`span`,{className:`block`,children:L(`agent.contextRemainingUntilCompact`,{percent:f.remainingPercent})}),Se&&t(`span`,{className:`mt-1 block text-foreground/80`,children:Se})]}),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,className:z(`size-8 rounded-lg text-info hover:bg-muted hover:text-info disabled:opacity-60`,`focus-visible:ring-2 focus-visible:ring-info/40`),"aria-label":xe,onClick:p,disabled:!p||m,children:m?t(je,{size:`sm`}):n(`svg`,{viewBox:`0 0 24 24`,className:z(`size-8 -rotate-90`,f.usedPercent>=90?`text-destructive`:f.usedPercent>=70?`text-attention`:`text-info`),"aria-hidden":`true`,children:[t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,strokeWidth:`4.5`,className:`stroke-current text-muted/50`}),t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,pathLength:100,strokeWidth:`4.5`,strokeLinecap:`round`,strokeDasharray:100,style:{strokeDashoffset:100-f.usedPercent},className:`stroke-current`})]})})}),ye.length===0&&be>0&&t(`output`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,"aria-live":`polite`,children:n(`span`,{className:`inline-flex h-8 items-center gap-1 rounded-full px-2 text-xs text-muted`,children:[t(Sm,{className:`size-3 text-attention`}),L(`agent.activeWorkstreams`,{count:be})]})})]}),u&&r&&!ne.trim()?t(o,{onClick:Fe,disabled:l,variant:`ghost`,size:`icon`,className:z(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`,`[&_svg]:text-destructive disabled:[&_svg]:text-muted`),title:L(`agent.stopTooltip`),children:l?t(je,{size:`sm`}):t(ib,{className:`size-3 fill-current stroke-current`})}):t(o,{onClick:Pe,disabled:s||c||!ne.trim()||O,variant:`ghost`,size:`icon`,className:z(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:L(O?`agent.waitForFiles`:`agent.sendTooltip`),"aria-label":L(O?`agent.waitForFiles`:`agent.send`),children:c?t(je,{size:`sm`}):t(Om,{className:`size-4`})})]})]}),n(se,{isOpen:ie,onClose:()=>oe(!1),className:`min-w-[60vw]`,children:[t(ue,{children:L(`agent.linkObject`)}),t(ce,{className:`pb-6`,children:t(q$,{onChange:e=>{let t=`[${e.properties?.title||e.name||`Object`}](store:${e.id})`,n=ne||``,r=R.current?.selectionStart||n.length,i=n.substring(0,r)+t+n.substring(r);re(i),oe(!1),setTimeout(()=>{if(R.current){R.current.focus();let e=r+t.length;R.current.setSelectionRange(e,e)}},100)}})})]}),k?.({isOpen:le,onClose:Me,onSelect:Ne})]})}function Z$({code:e}){let{onProposalSelect:n,onProposalSubmit:r}=qt(),i=U(()=>Wt(e),[e]),a=U(()=>{if(i)return null;try{let t=e.trim(),i=JSON.parse(t);if(!i.options||!i.question&&!i.title)return null;let a={question:i.question||i.title||``,description:i.description,options:Array.isArray(i.options)?i.options.map(e=>({id:e.id||e.value||``,label:e.label||``,description:e.description})):void 0,allowFreeResponse:i.allowFreeResponse??i.multiple,variant:i.variant,onSelect:n,onSubmit:r};return!a.question||!a.options?.length?null:a}catch{return null}},[e,n,r,i]);return i?t(Et,{type:`proposal`,message:`Loading options...`}):a?t(Tt,{type:`proposal`,fallbackCode:e,children:t(AH,{...a})}):t(Et,{type:`proposal`,error:`Invalid proposal specification`})}const Q$=gt(function({code:e}){let n=U(()=>{try{let t=JSON.parse(e);return t?.library===`vega-lite`&&t?.spec&&typeof t.spec==`object`?t:typeof t?.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}catch{return null}},[e]);return n?t(sC,{spec:n}):null}),$$=gt(function({code:e}){let n=U(()=>{try{return{library:`vega-lite`,spec:JSON.parse(e)}}catch{return null}},[e]);return n?t(sC,{spec:n}):null}),e1={chart:Q$,"vega-lite":$$,vegalite:$$,"fusion-fragment":Yn,proposal:Z$,askuser:Z$};function t1({url:e,code:n}){let[r,i]=G(null);return H(()=>{import(e).then(e=>{i(()=>e.default)}).catch(t=>{console.error(`Failed to load remote widget component from `,e,t)})},[e]),r?t(r,{code:n}):null}async function n1(e){let n=await e.apps.getInstalledApps(`tools`),r=new Set;for(let e of n){if(e.manifest.tool_collections&&e.manifest.tool_collections.length>0)for(let t of e.manifest.tool_collections||[]){let e=jn(t).url;if(e.startsWith(`http://`)||e.startsWith(`https://`)){let t=e.indexOf(`/api/`);if(t>0){let n=e.substring(0,t);r.add(`${n}/api/widgets`)}}}e.manifest.endpoint&&e.manifest.capabilities?.includes(`tools`)&&r.add(new URL(`/api/widgets`,e.manifest.endpoint).toString())}let i=await Promise.all(Array.from(r).map(e=>fetch(e).then(e=>{if(!e.ok)throw Error(`Failed to fetch widgets: ${e.status} ${e.statusText}`);return e.json()}).then(e=>{let n=[],r=e.widgets;for(let[e,i]of Object.entries(r))n.push({name:e,component:e=>t(t1,{url:i.url,code:e.code})});return n}).catch(()=>(console.error(`Failed to fetch skill widgets from `,e),null)))),a={};for(let e of i.flat())e&&(a[e.name]=e.component);return a}function r1({children:e}){let{client:n}=q(),[r,i]=G(e1);return H(()=>{n1(n).then(e=>{i({...e1,...e})})},[n]),t(Dt,{components:r,children:e})}Q();const i1=new Map,a1=[400,1200];async function o1(e,t,n){for(let r=0;;r++)try{return await e.agents.sendSignal(t,`FileBatchClosed`,n),!0}catch(e){if(r>=a1.length)return console.error(`Failed to close staged file batch:`,e),!1;await new Promise(e=>setTimeout(e,a1[r]))}}function s1(e){if(typeof e==`number`)return e;if(!e)return Date.now();let t=new Date(e).getTime();return Number.isFinite(t)?t:Date.now()}function c1(e){return e===`running`||e===`canceling`}function l1(e){return!c1(e)}function u1(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function d1(e){for(let t=e.length-1;t>=0;t--){let n=e[t].details;if(!n)continue;let r=n.token_usage,i=u1(r?.prompt),a=i&&i>0?i:u1(r?.total),o=u1(n.checkpoint_threshold)??u1(n.checkpoint_at);if(typeof a!=`number`||typeof o!=`number`||o<=0)continue;let s=Math.max(0,Math.min(100,Math.round(a/o*100)));return{usedTokens:a,checkpointTokens:o,usedPercent:s,remainingPercent:Math.max(0,100-s)}}}function f1(e,t){return!l1(e.status)||!c1(t.status)?{...e,...t}:{...e,interaction:e.interaction??t.interaction,elapsed_ms:Math.max(e.elapsed_ms,t.elapsed_ms),deadline_ms:Math.max(e.deadline_ms,t.deadline_ms),remaining_ms:0,phase:e.phase??t.phase,child_workflow_id:e.child_workflow_id??t.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id??t.child_workflow_run_id}}function p1(e){let t=e.details,n=typeof t?.workstream_id==`string`&&t.workstream_id.trim()?t.workstream_id:$H(e);return n===`main`||n===`all`?null:{workstreamId:n,launchId:typeof t?.launch_id==`string`?t.launch_id:void 0,interaction:typeof t?.interaction==`string`?t.interaction:void 0,childWorkflowId:typeof t?.child_workflow_id==`string`?t.child_workflow_id:void 0,childWorkflowRunId:typeof t?.child_workflow_run_id==`string`?t.child_workflow_run_id:void 0}}function m1(e){if(e.type!==J.ERROR)return!1;let t=e.details;if(t?.event_class!==`activity`||t.workstream_event)return!1;let n=typeof e.workstream_id==`string`&&e.workstream_id.trim()?e.workstream_id.trim():typeof t.workstream_id==`string`?t.workstream_id.trim():``,r=n.toLowerCase();return!n||r===`main`||r===`all`?!1:!(t.tool||t.tool_status||t.tool_run_id||t.activity_group_id||t.tool_event)}function h1(e,t,n,r,i,a){if(r){let a=t.get(n);if(a?.startsWith(`message-derived:`)){let t=e.get(a);t&&(e.delete(a),e.set(r,{...t,launch_id:r,updated_at:Math.max(t.updated_at,i)}))}t.set(n,r)}let o=r??t.get(n)??`message-derived:${n}`,s=e.get(o);if(s)return s;let c={workstream_id:n,launch_id:o,elapsed_ms:0,deadline_ms:0,remaining_ms:0,status:`running`,started_at:i,updated_at:i,order:a};return e.set(o,c),t.has(n)||t.set(n,o),c}function g1(e){let t=new Map,n=new Map;return e.forEach((e,r)=>{let i=s1(e.timestamp),a=p1(e),o=HH(e),s=o?.workstreamId??a?.workstreamId;if(!s)return;let c=o?.launchId??a?.launchId,l=zH(e);if(!o&&!c&&l&&!n.has(s))return;let u=h1(t,n,s,c,i,r);o?(u.interaction=o.interaction??u.interaction,u.child_workflow_id=o.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=o.childWorkflowRunId??u.child_workflow_run_id,u.status=`running`):(u.interaction=a?.interaction??u.interaction,u.child_workflow_id=a?.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=a?.childWorkflowRunId??u.child_workflow_run_id);let d=VH(e);d?u.status=d:l||(m1(e)?u.status=`failed`:(e.type===J.COMPLETE||e.type===J.IDLE)&&(u.status=`completed`)),!l&&(u.updated_at=Math.max(u.updated_at,i),c1(u.status)?u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at):(u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at),u.remaining_ms=0))}),Array.from(t.values()).sort((e,t)=>{let n=Number(!c1(e.status))-Number(!c1(t.status));return n===0?c1(e.status)?e.order-t.order:t.updated_at-e.updated_at||e.order-t.order:n}).map(({started_at:e,updated_at:t,order:n,...r})=>r)}function _1(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.elapsed_ms,deadline_ms:e.deadline_ms,remaining_ms:Math.max(0,e.deadline_ms-e.elapsed_ms),status:e.status,phase:e.latest_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function v1(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.duration_ms??0,deadline_ms:0,remaining_ms:0,status:e.status,phase:e.last_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function y1(e,t){let n=e.findIndex(e=>e.launch_id===t.launch_id);if(n>=0){e[n]=f1(e[n],t);return}let r=e.findIndex(e=>e.workstream_id===t.workstream_id&&e.launch_id.startsWith(`message-derived:`));if(r>=0&&!t.launch_id.startsWith(`message-derived:`)){e[r]=f1(e[r],t);return}e.push(t)}function b1(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function x1(e,t=!0){let[n,r]=G(()=>Math.max(0,Math.floor((Date.now()-s1(e))/1e3)));return H(()=>{if(!t)return;let n=()=>{r(Math.max(0,Math.floor((Date.now()-s1(e))/1e3)))};n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function S1(e=!0){let[t,n]=G(0);return H(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*xW.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function C1({message:e,startedAt:r}){let{t:i}=K(),a=x1(r),o=S1();return n(`div`,{className:`mx-auto flex min-h-full w-full max-w-3xl flex-col justify-end gap-6 px-1 py-8`,children:[t(`div`,{className:`flex w-full justify-end`,children:t(`div`,{className:z(`max-w-[min(44rem,82%)] rounded-[1.35rem] bg-mixer-muted/35 px-4 py-2.5`,`break-words text-sm font-normal leading-6 text-foreground/90 shadow-sm shadow-black/5`,`dark:bg-mixer-muted/15 dark:text-foreground/88 dark:shadow-none [overflow-wrap:anywhere]`),children:t(`div`,{className:`whitespace-pre-wrap`,children:e})})}),n(`div`,{className:`border-b border-border/70 pb-4 text-sm text-muted`,children:[n(`div`,{className:`flex items-center gap-3`,children:[t(rW,{size:`sm`,color:`blue`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{children:[t(`span`,{className:`font-medium`,children:i(`agent.preparing`)}),n(`span`,{className:`ms-2 text-muted/75`,children:[`for `,b1(a)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:xW[o]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(nW,{color:`blue`})})]})]})}function w1(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;return i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))}),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}function T1(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function E1(e){return T1(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function D1(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function O1(e){let{agentRunId:n,startWorkflow:r,resourceResolver:i}=e;if(n){let r=t(r1,{children:t(j1,{...e,agentRunId:n})});return i?t(Ct,{value:i,children:r}):r}return r?t(A1,{...e}):t(k1,{})}function k1(){let{t:e}=K();return n(oe,{status:`info`,icon:t(jm,{className:`size-16 text-muted mb-4`}),children:[t(`div`,{className:`text-base font-medium text-muted`,children:e(`agent.noAgentRunning`)}),t(`div`,{className:`mt-3 text-sm text-muted`,children:e(`agent.selectInteraction`)})]})}function A1({initialMessage:e,interactive:r=!0,startWorkflow:i,onClose:a,isModal:s=!1,fullWidth:c=!1,placeholder:l,startButtonText:u,title:d,getAttachedDocs:f,onAttachmentsSent:p,acceptedFileTypes:m,maxFiles:h=5,hideHeader:g=!1,hideFileUpload:_=!1,hideObjectLinking:v,headerVariant:y,startViewVariant:b=`default`,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,initialToolApprovalMode:T,onAgentWorkingChange:E}){let{t:D}=K(),O=b!=="default",k=b===`expanded-composer`,A=!_,j=l??D(`agent.typeYourMessage`),M=u??D(`agent.startAgent`),N=d??D(`agent.startNewConversation`),{client:P}=q(),[F,I]=G(``),[L,ee]=G(!1),[R,te]=G(null),[ne,re]=G(null),[ie,ae]=G(null),[oe,se]=G(()=>An(T,r)),ce=nt(),le=W(null),ue=W(null),[de,fe]=G([]),[pe,me]=G(!1),he=pe?de:de.slice(0,3),ge=de.length-3;H(()=>{E?.(L)},[L,E]);let[_e,ve]=G(!1),ye=W(0),be=V(e=>{A&&(e.preventDefault(),e.stopPropagation(),ye.current++,e.dataTransfer?.types?.includes(`Files`)&&ve(!0))},[A]),xe=V(e=>{A&&(e.preventDefault(),e.stopPropagation())},[A]),Se=V(e=>{A&&(e.preventDefault(),e.stopPropagation(),ye.current--,ye.current===0&&ve(!1))},[A]),Ce=V(e=>{if(A&&(e.preventDefault(),e.stopPropagation(),ye.current=0,ve(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);fe(e=>[...e,...t].slice(0,h))}},[h,A]),we=V(e=>{if(!A)return;let t=TX(e.clipboardData?.items);t.length>0&&fe(e=>[...e,...t].slice(0,h))},[A,h]),Te=V(e=>{if(e.target.files&&e.target.files.length>0){let t=Array.from(e.target.files);fe(e=>[...e,...t].slice(0,h))}e.target.value=``},[h]),Ee=V(e=>{fe(t=>t.filter((t,n)=>n!==e))},[]);H(()=>{de.length<=3&&me(!1)},[de.length]),H(()=>{le.current&&le.current.focus()},[]);let De=async()=>{if(!i)return;let e=F.trim();if(!(!e||L)){ee(!0);try{sessionStorage.removeItem(`plan-panel-shown`),ce({title:A&&de.length>0?D(`agent.startingAgentUploading`):D(`agent.startingAgent`),status:`info`,duration:3e3});let t=f?.()||[],n=e;if(t.length>0&&!/store:\S+/.test(e)&&(n=[e,``,`Attachments:`,...t.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
1380
+ `,i.head.appendChild(a),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}const a$={max_hw:import.meta.env?.VITE_RENDITION_HW||256,format:hn.jpeg,generate_if_missing:!0},o$=`vertesia.content_store.renditionId`;async function s$(e,t,n,r,i){if(!t?.content?.type||!(e$(t.content.type)||n$(t.content.type)||t$(t.content.type))){i(`No preview available`);return}i(`Preparing preview...`);let a=Date.now()/1e3,o=localStorage.getItem(`${o$}_${t.id}_${a$.max_hw}`),s=localStorage.getItem(`${o$}_${t.id}_${a$.max_hw}_time`);if(o?.length&&s&&Math.abs(a-parseInt(s,10))<=900)return n(o),r(`${t.name} Rendition`),i(`ready`),o;i(`Preparing preview...`),e.objects.getRendition(t.id,a$).then(a=>{if(a.status===`generating`)i(`Preparing preview...`),n(``),r(``),setTimeout(()=>s$(e,t,n,r,i),6e4);else if(a.status===`failed`){i(`No preview available`),n(``),r(``);return}else{if(!a?.renditions?.length){i(`No preview available`),n(``),r(``);return}let e=a.renditions[0];localStorage.setItem(`${o$}_${t.id}_${a$.max_hw}`,e),localStorage.setItem(`${o$}_${t.id}_${a$.max_hw}_time`,(Date.now()/1e3).toString()),n(e),r(`${t.name} Rendition`),i(`ready`),console.log(`Rendition for document ${t.id} retrieved successfully: ${e}`)}}).catch(e=>{i(`No preview available`),console.warn(`Failed to retrieve rendition:`,e),n(``),r(``)})}function c$(e,t=7){return e?`~${e.slice(-t)}`:``}function l$(e,t){return e.length>t?`${e.substring(0,t)}...`:e}function u$(e){switch(e){case En.RUNNING:return`text-info`;case En.COMPLETED:return`text-success`;case En.FAILED:return`text-destructive`;case En.TERMINATED:case En.CANCELED:return`text-attention`;default:return`text-muted`}}function d$(e){switch(e){case En.RUNNING:return`Running`;case En.COMPLETED:return`Completed`;case En.FAILED:return`Failed`;case En.CONTINUED_AS_NEW:return`Continued As New`;case En.TERMINATED:return`Terminated`;case En.TIMED_OUT:return`Timed Out`;case En.CANCELED:return`Canceled`;default:return`Unknown`}}Q();function f$(e){return typeof e==`object`&&!!e}function p$(e,t){if(!f$(e))return;let n=e[t];return typeof n==`string`?n:void 0}function m$(e){return typeof e==`string`?e:p$(e,`id`)||``}function h$(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e)}const g$={string(e,r){let i=[];if(e){let t=e.get(`slice`);t&&i.push(e=>e.slice(parseInt(t,10)));let n=e.get(`max_length`);n&&i.push(e=>e.slice(0,parseInt(n,10))),e.has(`upper`)&&i.push(e=>e.toUpperCase()),e.has(`lower`)&&i.push(e=>e.toLowerCase()),e.has(`capitalize`)&&i.push(e=>e[0].toUpperCase()+e.substring(1)),e.has(`ellipsis`)&&i.push(e=>`${e}...`)}return(e,r,a)=>{let o;if(e){if(o=String(e),i.length>0)for(let e of i)o=e(o)}else o=``;return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:o}),a]}):o},r)}},fileSize(e,n){return(e,n)=>{let r=``;if(e){let t=Number(e);if(Number.isNaN(t))r=String(e);else{let e=[`Bytes`,`KB`,`MB`,`GB`,`TB`];if(t===0)r=`0 Bytes`;else{let n=Math.floor(Math.log(t)/Math.log(1024));r=`${(t/1024**n).toFixed(2)} ${e[n]}`}}}return t(`td`,{className:`group/field`,children:r},n)}},number(e,n){let r,i;e&&(r=e.get(`currency`)||void 0,i=e.get(`decimals`)||void 0);let a=i?parseInt(i,10):2;return(e,n)=>{let i=Number(e),o=new Intl.NumberFormat(`en-US`,{style:r?`currency`:`decimal`,currency:r,maximumFractionDigits:a}).format(Number.isFinite(i)?i:0);return t(`td`,{className:`group/field`,children:o},n)}},objectId(e,r){let i=[],a=!1;if(e){let t=e.get(`slice`);t&&(a=!0,i.push(e=>e.slice(parseInt(t,10))))}return(e,s,c)=>{let l=m$(e),u=i.reduce((e,t)=>t(e),l);return n(`td`,{className:`flex justify-start items-center gap-2 group/field`,children:[t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(l)},children:t(jg,{className:`size-4`})}),a?`~`:``,u,c]},s)}},objectName(e,r){let i=`title`;return e&&(i=e.get(`title`)||`title`),(e,r,a)=>{let o=(f$(e)&&f$(e.properties)?e.properties:void 0)?.[i],s=h$(o),c=p$(e,`name`),l=p$(e,`id`),u=s||c||(l?c$(l):``);return t(`td`,{className:`group/field`,children:a?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:u}),a]}):u},r)}},objectLink(e,r){let i=[];return i.push(e=>e.slice(-7)),(e,a)=>{let s=m$(e),c=i.reduce((e,t)=>t(e),s);return n(`td`,{className:`flex justify-between items-center gap-2 max-w-48 group/field`,children:[`~`,c,t(o,{variant:`ghost`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),r?.(s)},children:t(jg,{className:`size-4`})})]},a)}},typeLink(e,r){return(e,r,i)=>{let a=p$(e,`name`)||`n/a`;return t(`td`,{className:`group/field`,children:i?n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:a}),i]}):a},r)}},revision(e,r){return(e,r)=>{let i=f$(e)&&f$(e.revision)?e.revision:void 0;if(!i)return t(`td`,{},r);let a=p$(i,`root`),o=p$(i,`label`);return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex flex-col gap-0.5`,children:[a&&n(`div`,{className:`flex items-center gap-1`,children:[n(`span`,{className:`text-xs text-muted font-mono`,children:[`root: ~`,a.slice(-7)]}),t(`a`,{href:`/store/objects/${a}`,onClick:e=>e.stopPropagation(),children:t(Og,{className:`size-3 text-muted`})})]}),o&&n(`span`,{className:`text-xs text-muted`,children:[`label: `,o]})]})},r)}},date(e,r){let i=`fromNow`,a;if(e){let t=e.get(`localized`);if(t)i=`format`,a=t;else{let t=e.get(`relative`);t&&(i=t)}}return(e,r,o)=>{let s=typeof e==`string`||typeof e==`number`||e instanceof Date?e:void 0;if(s===void 0)return t(`td`,{children:o},r);let c=GD(s),l=i===`format`?c.format(a):i===`toNow`?c.toNow():c.fromNow();return t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2`,children:[t(We,{description:c.format(`LLL`),children:l}),o]})},r)}}},_$=g$.string();function v$(e){return typeof e==`object`&&!!e}function y$(e,t){let n=e;if(!n)return;if(!t.length)return n;let r=t.length-1;for(let e=0;e<r;e++)if(!v$(n)||(n=n[t[e]],!n))return;if(v$(n))return n[t[r]]}function b$(e){return!e||e===`.`?[]:e.split(`.`)}var x$=class{layout;renderer=_$;path;fallbackPath;previewObject;constructor(e,t){if(this.layout=e,this.path=b$(e.field||``),this.fallbackPath=e.fallback?b$(e.fallback):void 0,this.previewObject=t,e.render)this.renderer=(e,t)=>null;else{let t=e.type||`string`,n=t.indexOf(`?`);if(n>0){let e=t.substring(0,n),r=new URLSearchParams(t.substring(n+1));this.renderer=g$[e](r)}else this.renderer=g$[t]()}}get name(){return this.layout.name}resolveValue(e){let t=y$(e,this.path);return t===void 0&&this.fallbackPath&&(t=y$(e,this.fallbackPath)),t===void 0&&(t=this.layout.default),t}render(e,n){if(this.layout.render)return t(`td`,{className:`whitespace-nowrap px-3 py-4 text-sm group`,children:this.layout.render(e)},n);let r=this.layout.type||`string`,i=r.indexOf(`?`)>0?r.substring(0,r.indexOf(`?`)):r,a=this.buildActions(e,i);if((i===`objectId`||i===`objectLink`)&&this.previewObject){let t=r.indexOf(`?`),o=t>0?new URLSearchParams(r.substring(t+1)):void 0;return g$[i](o,t=>{this.previewObject?.(e.id)})(e,n,a)}return this.renderer(this.resolveValue(e),n,a)}buildActions(e,n){let r=this.layout.field;if(n===`objectId`||n===`objectLink`||r===`id`)return t(qQ,{field:`id`,value:e.id,label:e.id,copyContent:e.id});if(n===`objectName`||r===`name`)return t(qQ,{field:`name`,value:e.name,label:e.name??e.id});if(n===`typeLink`||r===`type.name`||r===`type`){let n=e.type?.id;return t(qQ,{field:`type`,value:n,label:e.type?.name??n??`type`})}if(r===`status`)return t(qQ,{field:`status`,value:e.status,label:e.status})}};Q();function S$({isLoading:e=!1,counts:r=6}){return e?t(`div`,{className:`flex flex-wrap gap-2 justify-between`,children:Array(r).fill(0).map((e,r)=>t(`div`,{className:`w-[15vw] animate-pulse`,children:n(s,{className:`relative flex flex-col border h-fit`,children:[t(`div`,{className:`h-48 bg-muted rounded-t-xl flex items-center justify-center text-muted`,children:`\xA0`}),t(Ee,{className:`bg-muted h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(`div`,{className:`h-5 bg-muted rounded w-3/4 mb-2`}),t(`div`,{className:`h-4 bg-muted rounded w-1/2`})]}),t(`div`,{className:`text-xs text-muted w-full flex justify-end mt-2`,children:t(`div`,{className:`h-3 bg-muted rounded w-1/4`})})]})]})},`skeleton-${r}`))}):null}function C$({selection:e,document:r,onSelectionChange:i,onRowClick:a,highlightRow:l,previewObject:u,selectedObject:d}){let{client:f}=q(),[p,m]=G(void 0),[h,g]=G(void 0),[_,v]=G(void 0),y=typeof r.properties?.title==`string`?r.properties.title:r.name,b=e=>{e.stopPropagation(),i(r,e)};H(()=>{r?.content&&s$(f,r,m,g,v)},[f,r]);let x=l?.(r);return n(s,{className:`relative flex flex-col border h-fit w-full ${d?.id===r.id?`border-attention border-4`:``} ${x?`border-blue-400 dark:border-blue-500 bg-blue-50/50 dark:bg-blue-900/20`:``}`,onClick:()=>a?.(r),children:[x&&t(`div`,{className:`absolute top-2 end-8 z-10`,children:t(th,{className:`size-4 text-blue-600 dark:text-blue-400`})}),e&&t(`div`,{className:`absolute top-2 start-2 z-10 flex flex-col items-center gap-1`,children:t(`input`,{checked:e.isSelected(r.id),type:`checkbox`,onChange:b,onClick:e=>e.stopPropagation()})}),t(`div`,{className:`absolute top-1 end-1 z-10 flex flex-col items-center`,children:t(o,{variant:`ghost`,size:`sm`,title:`Preview Object`,onClick:e=>{e.stopPropagation(),u?.(r.id)},children:t(jg,{className:`size-4 ${_===`ready`?`text-muted`:`text-white`}`})})}),p&&_===`ready`?t(`img`,{src:p,alt:h,className:`w-auto h-48 object-cover rounded-t-xl`}):t(`div`,{className:`h-48 bg-gray-700 rounded-t-xl flex items-center justify-center text-muted`,children:_}),t(Ee,{className:`bg-gray-200 h-[2px]`}),n(c,{className:`p-2 flex flex-col`,children:[n(`div`,{className:`flex flex-col overflow-hidden`,children:[t(We,{placement:`top`,description:y,children:t(`h3`,{className:`text-start font-medium leading-none truncate`,children:y})}),r?.type?.name?t(We,{placement:`bottom`,size:`xs`,description:r?.type?.name,children:t(`p`,{className:`text-start text-xs text-muted truncate`,children:r?.type?.name})}):t(`p`,{className:`text-xs text-muted`,children:` `})]}),r.score&&n(`div`,{className:`text-xs text-muted w-full flex justify-end`,children:[`Score: `,r.score.toFixed(4)??`-`]})]})]})}Q();function w$({objects:e,selection:r,isLoading:i,columns:a,onRowClick:o,highlightRow:s,selectedObject:c,toggleAll:l,onSelectionChange:u}){let{t:d}=K();return n(Le,{className:`w-full`,children:[t(Fe,{children:n(`tr`,{children:[r&&t(`th`,{children:t(`input`,{type:`checkbox`,onChange:l})}),a.map(e=>t(`th`,{children:e.name},e.name))]})}),n(Pe,{isLoading:i,columns:a.length+1,children:[e?.map(e=>{let i=s?.(e);return n(`tr`,{className:`group cursor-pointer hover:bg-muted ${c?.id===e.id?`bg-muted`:``} ${i?`bg-blue-50 dark:bg-blue-900/20`:``}`,onClick:()=>{o?.(e)},children:[r&&t(`td`,{onClick:e=>e.stopPropagation(),children:t(`input`,{checked:r.isSelected(e.id),type:`checkbox`,className:`${r.isSelected(e.id)?``:`hidden group-hover:block`}`,onChange:t=>u(e,t)})}),a.map((t,n)=>t.render(e,n)),t(`td`,{className:`w-8 text-center`,children:i&&t(th,{className:`size-4 text-blue-600 dark:text-blue-400 inline-block`})})]},e.id)}),e.length===0&&t(`tr`,{children:t(`td`,{colSpan:a.length+ +!!r,className:`text-center`,children:d(`store.noObjectsDragAndDrop`)})})]})]})}function T$({objects:r,selection:i,isLoading:a,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u}){return n(e,{children:[t(S$,{isLoading:a}),t(`div`,{className:`w-full gap-2 grid xs:grid-cols-1 sm:grid-cols-2 md:grid-cols-4 lg:grid-cols-6 @xs:grid-cols-1 @sm:grid-cols-2 @md:grid-cols-3 @lg:grid-cols-4`,children:r.map(e=>t(C$,{document:e,selection:i,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u},e.id))})]})}var E$=class{client;limit;collectionId;facets=new De({});result=new De({objects:[],isLoading:!1});initialized=!1;facetSpecs=[];query={};deletedIds=new Set;loadedCount=0;constructor(e,t=100){this.client=e,this.limit=t}withFacets(e){return this.facetSpecs=e,this}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}get hasMore(){return this.result.value.hasMore||!1}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}setDefaultKeys(e){}clearFilters(e=!0){let{parent:t,full_text:n,vector:r,weights:i,score_aggregation:a,dynamic_scaling:o,limit:s,all_revisions:c}=this.query;this.query={parent:t,...n!==void 0&&{full_text:n},...r!==void 0&&{vector:r},...i!==void 0&&{weights:i},...a!==void 0&&{score_aggregation:a},...o!==void 0&&{dynamic_scaling:o},...s!==void 0&&{limit:s},...c!==void 0&&{all_revisions:c}},e&&this.search()}getFacetBuckets(e){let t=this.facets.value[e];return Array.isArray(t)?t:[]}resetFacets(){this.query={}}removeDeletedObjects(e){if(e.length===0)return;for(let t of e)this.deletedIds.add(t);let t=this.result.value,n=t.objects.filter(e=>!this.deletedIds.has(e.id)),r=t.objects.length-n.length;this.result.value={...t,objects:n};let i=this.facets.value;r>0&&typeof i.total==`number`&&(this.facets.value={...i,total:Math.max(0,i.total-r)})}reset(e=!1){this.initialized=!1,this.deletedIds.clear(),this.loadedCount=0,this.result.value={objects:[],isLoading:e,hasMore:!0}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error,hasMore:t.hasMore}}_searchRequest(e,t,n,r=!0){let i={limit:t,offset:n,query:e,facets:r?this.facetSpecs:void 0};return this.collectionId?this.client.collections.searchMembers(this.collectionId,i):this.client.objects.search(i)}_facetsRequest(){let e={facets:this.facetSpecs,query:this.query};return this.collectionId?this.client.collections.computeFacets(this.collectionId,e):this.client.objects.computeFacets(e)}computeFacets(e){this._facetsRequest().then(e=>{this.facets.value=e})}async _search(e=!1,t=!1){if(this.isRunning&&e)return!1;let n=this.result.value;e||(this.initialized=!0),this.result.value={isLoading:!0,objects:e?this.objects:[],hasMore:!e||this.result.value.hasMore};let r=this.limit,i=e?this.loadedCount:0;try{let n=await this._searchRequest(this.query,r,i,!t),a=n.results||[],o=n.facets||{};if(this.loadedCount=e?this.loadedCount+a.length:a.length,!e&&this.deletedIds.size>0)for(let e of[...this.deletedIds])a.some(t=>t.id===e)||this.deletedIds.delete(e);let s=this.deletedIds.size>0?a.filter(e=>!this.deletedIds.has(e.id)):a;return this.result.value={isLoading:!1,objects:e?this.objects.concat(s):s,hasMore:a.length===r},!t&&o&&Object.keys(o).length>0&&(this.facets.value=o),!0}catch(e){if(typeof e==`object`&&e&&`status`in e&&e.status===404)return this.result.value={isLoading:!1,objects:[],hasMore:!1},!1;let t=e instanceof Error?e:Error(String(e));return this.result.value={error:t,isLoading:!1,objects:n.objects,hasMore:!1},!1}}search(e=!1){return this.isRunning?Promise.resolve(!1):this._search(!1,e)}loadMore(e=!1){return this.isRunning||!this.hasMore||this.query.vector?Promise.resolve(!1):(this.objects.length>0&&(e=!0),this._search(!0,e))}};const D$=dt(void 0);function O$(){return _t(D$)}function k$(){return rt(O$().facets)}function A$(){let e=O$();return{...rt(e.result),search:e}}function j$(){let e=O$();return rt(e.facets).total}const M$=Xt.getFixedT(null,Yt);var N$;(function(e){e.CREATE=`create`,e.SKIP=`skip`,e.UPDATE=`update`})(N$||={});async function P$(e){try{let t=await e.arrayBuffer(),n=new rr;return n.appendByteArray(new Uint8Array(t)),n.end()?.toString()}catch(e){console.error(`Error calculating file hash:`,e);return}}async function F$(e,t){let n=[];for(let r=0;r<e.length;r+=5){let i=e.slice(r,r+5),a=await Promise.all(i.map(async e=>{let n=t||`/`;if(e.webkitRelativePath){let r=e.webkitRelativePath.split(`/`);if(r.length>1){let e=r.slice(0,-1).join(`/`);n=t?`${t}/${e}`:e}}return{file:e,hash:await P$(e),name:e.name,size:e.size,location:n}}));n.push(...a)}return n}function I$(){let{client:e}=q(),t=nt();return{checkDocumentProcessing:V(async(n,r,i)=>{try{console.log(`Preparing metadata for ${n.length} files...`);let t=await F$(n,r);return await(async()=>{let n=t.map(e=>e.hash).filter(Boolean);if(n.length===0)return;let r={"content.etag":{$in:n}},a;if(i){let t={query:{match:r},select:`id content.etag`};a=(await e.store.collections.searchMembers(i,t)).results.filter(e=>typeof e.id==`string`)}else{let t={query:r,select:`id content.etag`};a=(await e.store.objects.find(t)).flatMap(e=>typeof e.id==`string`?[{id:e.id,content:e.content}]:[])}for(let e of a){let n=t.find(t=>t.hash===e.content?.etag);n&&(n.existingId=e.id,n.action=N$.SKIP)}})(),await(async()=>{let n=t.filter(e=>e.action!==N$.SKIP),r=n.map(e=>e.location),a=Array.from(new Set(r)),o=[];for(let t of a){let r={"content.name":{$in:n.filter(e=>e.location===t).map(e=>e.name)},location:t||`/`};if(i){let t=e.store.collections.searchMembers(i,{query:{match:r},select:`id content.name location`}).then(e=>e.results);o.push(t)}else{let t=e.store.objects.find({query:r,select:`id content.name location`});o.push(t)}}let s=(await Promise.all(o)).flat();console.log(`Found ${s.length} document to update`,s);for(let e of s){let n=t.find(t=>t.name===e.content?.name&&(t.location?t.location===e.location:e.location===`/`));n&&(n.existingId=e.id,n.action=N$.UPDATE)}console.log(`Reconciled ${t.filter(e=>e.action===N$.UPDATE).length}`)})(),t.forEach(e=>{e.action||=N$.CREATE}),console.log(`Document processing check results:`,{totalFiles:n.length,toCreate:t.filter(e=>e.action===N$.CREATE).length,toUpdate:t.filter(e=>e.action===N$.UPDATE).length,toSkip:t.filter(e=>e.action===N$.SKIP).length}),t}catch(e){throw t({title:M$(`store.errorInUploadProcessingCheck`),status:`error`,description:Ge(e)}),console.log(`Error in file upload processing check`,e),Error(`Error in file upload processing check: ${Ge(e)}`,{cause:e})}},[e,t])}}Q();function L$({isOpen:r,onClose:i,files:a,collectionId:s,selectedFolder:c,title:l,children:u,onUploadComplete:d,hideFileSelection:f=!1,showTypeSelectionOnly:p=!1,allowFolders:m=!0,initialTypeId:h,defaultProperties:g}){let{client:_}=q(),{registry:v}=GZ(),y=nt(),{t:b}=K(),x=l??b(`upload.uploadFiles`),[S,C]=G([]),[w,T]=G([]),[E,D]=G(!1),[O,k]=G(null),[A,j]=G([]),[M,N]=G(!1),[P,F]=G(!1),[I,L]=G(0),[ee,R]=G(Date.now()),[te,ne]=G(void 0),[re,ie]=G(null),[ae,de]=G(x),[fe,pe]=G(``);H(()=>{s&&_.store.collections.retrieve(s).then(ne)},[_.store.collections.retrieve,s]),H(()=>{M?(de(b(`upload.uploadingFiles`)),pe(`${Math.round(I)}% complete`)):P?(de(b(`upload.uploadComplete`)),pe(``)):E?(de(b(`upload.fileAnalysisResults`)),pe(`${S.length} file${S.length===1?``:`s`}`)):S.length>0?(de(x),pe(b(`upload.checkingForDuplicates`))):(de(x),pe(``))},[M,P,E,x,I,S.length,b]);let me=()=>!te&&!c?null:n(oe,{className:`mb-4`,status:`default`,icon:t(s_,{className:`size-5`}),children:[t(`div`,{className:`flex items-center`,children:t(`span`,{className:`font-medium`,children:b(`upload.uploadLocation`)})}),n(`div`,{className:`text-sm mt-1`,children:[te&&n(`div`,{className:`flex items-center`,children:[t(`span`,{className:`me-1`,children:b(`upload.collectionLabel`)}),t(`span`,{className:`font-medium`,children:te.name})]}),c&&n(`div`,{className:`flex items-center mt-1`,children:[t(`span`,{className:`me-1`,children:b(`upload.folderLabel`)}),t(`span`,{className:`font-medium`,children:c})]})]})]}),[he,ge]=G({toCreate:0,toUpdate:0,toSkip:0}),{checkDocumentProcessing:_e}=I$(),ve=U(()=>v?.types||[],[v?.types]),ye=V(async e=>{if(e.length)try{console.log(`Processing ${e.length} files to determine required actions...`);let t=await _e(e,c,s);T(t);let n=t.filter(e=>e.action===N$.CREATE).length,r=t.filter(e=>e.action===N$.UPDATE).length,i=t.filter(e=>e.action===N$.SKIP).length;ge({toCreate:n,toUpdate:r,toSkip:i}),y({title:b(`upload.filesAnalyzed`),description:`${e.length} file(s): ${n} new, ${r} to update, ${i} to skip`,status:`info`,duration:4e3}),D(!0)}catch(e){console.error(`Error processing files:`,e),y({title:b(`agent.error`),description:b(`upload.errorAnalyzingFiles`),status:`error`,duration:5e3})}},[_e,s,c,b,y]);H(()=>{r&&(T([]),D(!1),k(h?v?.getType(h)??null:null),j([]),N(!1),F(!1),L(0),ge({toCreate:0,toUpdate:0,toSkip:0}),ie(null),de(x),pe(``),a&&a.length>0?(C(a),ye(a)):C([]),R(Date.now()))},[a,h,r,ye,x,v]);let be=()=>{C([]),T([]),D(!1),k(null),j([]),N(!1),F(!1),L(0),ge({toCreate:0,toUpdate:0,toSkip:0}),ie(null),de(x),pe(``),R(Date.now()),i()},xe=e=>{e&&e.length>0&&(C(e),ye(e))},Se=async()=>{if(!w.length)return;let e=O?.id||null,t=w.map(e=>({file:e.file,status:`pending`,progress:0,action:e.action===N$.CREATE?`create`:e.action===N$.UPDATE?`update`:`skip`}));j(t),N(!0),F(!1);let n=w.filter(e=>e.action===N$.SKIP),r=w.filter(e=>e.action===N$.UPDATE),i=w.filter(e=>e.action===N$.CREATE),a={success:!0,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};for(let t of n)t.existingId&&(a.objectIds.push(t.existingId),a.skippedFiles.push({id:t.existingId,name:t.name,type:e,status:`skipped`,location:t.location}),j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)));let o=async(t,n)=>{let r=[];for(let e=0;e<t.length;e+=50)r.push(t.slice(e,e+50));for(let i=0;i<r.length;i++){let o=r[i];if(console.log(`Processing ${n} batch ${i+1}/${r.length} (${o.length} files)`),t.length>50){let e=i*50;y({title:b(`upload.processingFilesAction`,{action:n}),description:b(`upload.processedCount`,{processed:e,total:t.length}),status:`info`,duration:2e3})}let c=0;await Promise.all(o.map(async t=>{try{if(j(e=>e.map(e=>e.file===t.file?{...e,status:`uploading`,progress:20}:e)),n===`update`&&t.existingId)await _.store.objects.update(t.existingId,{type:e||void 0,content:t.file,location:t.location,name:t.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`}),j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:t.existingId}:e)),a.objectIds.push(t.existingId),a.uploadedFiles.push({id:t.existingId,name:t.name,type:e,status:`updated`,location:t.location});else{let n=await _.store.objects.create({type:e||void 0,content:t.file,location:t.location||t.file.webkitRelativePath||t.name,properties:g},{collection_id:s});j(e=>e.map(e=>e.file===t.file?{...e,status:`success`,progress:100,id:n.id}:e)),a.objectIds.push(n.id),a.uploadedFiles.push({id:n.id,name:t.name,type:e,status:`created`,location:t.location})}}catch(n){console.error(`Failed to process file ${t.name}:`,n),j(e=>e.map(e=>e.file===t.file?{...e,status:`error`,progress:100,message:Ge(n,`Unknown error`)}:e)),a.failedFiles.push({name:t.name,error:Ge(n,`Unknown error`),status:`failed`,location:t.location,type:e}),a.success=!1}c++,(c%5==0||c===o.length)&&j(e=>{let t=e.filter(e=>e.status===`success`||e.status===`error`).length,n=e.length,r=n>0?Math.round(t/n*100):0;return L(r),e})}))}};r.length>0&&await o(r,`update`),i.length>0&&await o(i,`create`),j(e=>{let t=e.filter(e=>e.status===`pending`).map(e=>({...e,status:`error`,progress:100,message:b(`upload.uploadProcessInterrupted`)}));return t.length>0?(t.forEach(e=>{a.failedFiles.push({name:e.file.name,error:b(`upload.uploadProcessInterrupted`),status:`failed`,type:O?.id||null})}),a.success=!1,e.map(e=>e.status===`pending`?{...e,status:`error`,progress:100,message:b(`upload.uploadProcessInterrupted`)}:e)):e}),N(!1),F(!0);let c=a.uploadedFiles.filter(e=>e.status===`created`).length,l=a.uploadedFiles.filter(e=>e.status===`updated`).length,u=a.skippedFiles.length,d=a.failedFiles.length,f=``;c>0&&(f+=`${c} file${c===1?``:`s`} uploaded`),l>0&&(f+=f?`, `:``,f+=`${l} file${l===1?``:`s`} updated`),u>0&&(f+=f?`, `:``,f+=`${u} file${u===1?``:`s`} skipped`),d>0&&(f+=f?`, `:``,f+=`${d} file${d===1?``:`s`} failed`),y({title:b(`upload.uploadComplete`),description:f,status:d>0?`warning`:`success`,duration:5e3}),ie(a)},Ce=()=>n(`div`,{className:`mb-4`,children:[n(`div`,{className:`block text-sm font-medium mb-2`,children:[b(`store.contentType`),` `,t(`span`,{className:`text-muted font-normal`,children:b(`store.optional`)}),t(We,{description:b(`upload.contentTypeTooltip`),placement:`top`,size:`xs`,children:t(j_,{className:`size-3 ms-2`})})]}),t(we,{options:ve,value:O,optionLabel:e=>e?e.name:b(`store.selectContentTypeLabel`),placeholder:b(`store.selectContentTypeAuto`),onChange:e=>k(e===void 0?null:e),filterBy:`name`,isClearable:!0}),!O&&t(`div`,{className:`p-2 rounded-md`,children:n(`div`,{className:`flex items-center text-attention`,children:[t(Ph,{className:`size-4 me-1`}),b(`store.automaticTypeDetection`),t(We,{description:b(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(j_,{className:`size-3 ms-2`})})]})})]});return n(se,{isOpen:r,onClose:be,className:`mx-auto`,disableCloseOnClickOutside:!0,children:[t(ue,{description:fe,children:ae}),p?n(ce,{children:[u,me(),Ce()]}):S.length===0&&!f?n(ce,{className:`flex flex-col items-center justify-center p-8`,children:[me(),t(Ot,{onDrop:xe,message:b(`upload.dragAndDrop`),buttonLabel:b(`upload.selectFiles`),className:`w-full h-64`,allowFolders:m}),u]}):!M&&!P?t(ce,{children:E?n(e,{children:[me(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`p-4 rounded-md mb-4`,children:n(`div`,{className:`grid grid-cols-3 gap-4`,children:[n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(Tb,{className:`size-5 text-primary`}),t(`span`,{className:`font-medium`,children:b(`upload.new`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:he.toCreate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(Ph,{className:`size-5 text-success`}),t(`span`,{className:`font-medium`,children:b(`upload.update`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:he.toUpdate})]}),n(`div`,{className:`flex flex-col items-center`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(jh,{className:`size-5 text-mixer-attention/40`}),t(`span`,{className:`font-medium`,children:b(`upload.skip`)})]}),t(`div`,{className:`text-2xl font-semibold`,children:he.toSkip})]})]})})}),Ce(),t(oe,{className:`mb-4`,status:`info`,children:he.toCreate+he.toUpdate>0?n(`div`,{className:`space-y-1`,children:[t(`p`,{children:b(`upload.filesReadyToProcess`,{count:he.toCreate+he.toUpdate})}),t(`p`,{children:he.toSkip>0&&b(`upload.filesToSkip`,{count:he.toSkip})})]}):he.toSkip>0?t(`span`,{children:b(`upload.allFilesExist`,{count:he.toSkip})}):t(`span`,{children:b(`upload.noFilesToProcess`)})})]}):n(`div`,{className:`flex flex-col items-center justify-center py-4`,children:[t(je,{size:`lg`,className:`mb-4`}),t(`div`,{className:`text-lg font-medium`,children:b(`upload.analyzingFiles`)})]})}):M?n(ce,{children:[me(),t(`div`,{className:`mb-4`,children:t(`div`,{className:`h-2 bg-muted/20 rounded-full overflow-hidden`,children:t(`div`,{className:`h-full bg-primary rounded-full`,style:{width:`${I}%`}})})}),t(`div`,{className:`max-h-96 overflow-y-auto`,children:A.map((e,r)=>n(`div`,{className:`flex items-center py-2 border-b border-border last:border-b-0`,children:[n(`div`,{className:`me-3`,children:[e.status===`pending`&&t(Qg,{className:`size-5 text-muted`}),e.status===`uploading`&&t(je,{size:`sm`}),e.status===`success`&&t(Ph,{className:`size-5 text-success`}),e.status===`error`&&t(Kh,{className:`size-5 text-destructive`})]}),n(`div`,{className:`flex-1 min-w-0`,children:[t(`div`,{className:`truncate font-medium`,children:e.file.name}),n(`div`,{className:`text-xs text-muted`,children:[e.status===`pending`&&b(`agent.waiting`),e.status===`uploading`&&b(`agent.uploading`),e.status===`success`&&(e.action===`create`?b(`store.created`):e.action===`update`?b(`store.updated`):b(`upload.skip`)),e.status===`error`&&e.message]})]})]},`${e.file.name}-${e.file.size}-${e.file.lastModified}`))})]}):t(ce,{children:n(`div`,{className:`mb-4`,children:[me(),t(Lt,{files:A.map(e=>{let t;return t=e.status===`success`?e.action===`create`?`success`:e.action===`update`?`updated`:`skipped`:`failed`,{name:e.file.name,status:t,error:e.status===`error`?e.message:void 0}}),location:c||void 0,collection:te?.name})]})}),(()=>{if(p)return n(le,{children:[t(o,{variant:`ghost`,onClick:be,children:b(`modal.cancel`)}),t(o,{onClick:()=>{let e={success:!0,objectIds:[],uploadedFiles:[{name:`type-selection`,type:O?.id||null,status:`created`}],skippedFiles:[],failedFiles:[]};d&&d(e),be()},children:O?b(`upload.useTypeName`,{typeName:O.name}):b(`upload.useAutoDetection`)})]});if(S.length===0&&!f)return t(le,{children:t(o,{variant:`ghost`,onClick:be,children:b(`modal.cancel`)})});if(!M&&!P){let e=E;return n(le,{children:[t(o,{variant:`ghost`,onClick:be,children:b(`modal.cancel`)}),t(o,{disabled:!e,onClick:Se,children:he.toCreate+he.toUpdate>0?b(`agent.upload`):b(`upload.continue`)})]})}return M?t(le,{children:t(o,{variant:`ghost`,disabled:!0,children:b(`agent.uploading`)})}):n(le,{children:[t(o,{variant:`ghost`,onClick:()=>{C([]),T([]),D(!1),k(null),j([]),N(!1),F(!1),L(0),ge({toCreate:0,toUpdate:0,toSkip:0})},children:b(`upload.uploadMore`)}),t(o,{onClick:()=>{d&&re&&d(re),be()},children:b(`agent.close`)})]})})()]},ee)}function R$(e){let t=typeof e==`function`?e:e.onUploadDone,{client:n,project:r,store:i}=q(),a=O$(),o=nt(),s=Xt.getFixedT(null,Yt),{checkDocumentProcessing:c}=I$();return async(e,l,u)=>{let d={success:!1,objectIds:[],uploadedFiles:[],skippedFiles:[],failedFiles:[]};if(!r)return o({status:`error`,title:s(`store.noProjectSelected`),duration:3e3}),d;if(!e||e.length===0)return o({status:`warning`,title:s(`store.noFilesSelected`),duration:3e3}),d;let f=Array.from(e).filter(e=>e.size>0);if(f.length===0)return o({status:`error`,title:s(`store.noValidFilesSelected`),description:s(`store.pleaseSelectValidFiles`),duration:5e3}),d;let p=[],m=[],h=[];console.log(`Processing ${f.length} files with smart file processing...`);let g=await c(f,null,u),_=g.filter(e=>e.action===N$.CREATE).length,v=g.filter(e=>e.action===N$.UPDATE).length,y=g.filter(e=>e.action===N$.SKIP).length;o({title:s(`store.filesAnalyzedTitle`),description:`${f.length} file(s): ${_} new, ${v} to update, ${y} to skip`,status:`info`,duration:4e3});for(let e of g.filter(e=>e.action===N$.SKIP&&e.existingId))p.push({id:e.existingId,name:e.name,type:l,status:`skipped`,location:e.location});let b=g.filter(e=>(e.action===N$.CREATE||e.action===N$.UPDATE)&&e.file);if(b.length>0){console.log(`Processing ${b.length} files (${b.filter(e=>e.action===N$.CREATE).length} create, ${b.filter(e=>e.action===N$.UPDATE).length} update)...`);let e=[];for(let t=0;t<b.length;t+=50)e.push(b.slice(t,t+50));for(let t=0;t<e.length;t++){let r=e[t],a=t*50;console.log(`Processing batch ${t+1}/${e.length} (${r.length} files)`),b.length>50&&o({title:s(`store.processingFiles`),description:`Processed ${a}/${b.length} files...`,status:`info`,duration:2e3});let c=await Promise.all(r.map(async e=>{try{if(e.action===N$.UPDATE&&e.existingId){let t=await n.store.objects.update(e.existingId,{type:l||void 0,content:e.file,location:e.location,name:e.name},{createRevision:!0,revisionLabel:`upload on ${new Date().toISOString()}`});return m.push({id:e.existingId,name:e.name,type:l,status:`updated`,location:e.location}),d.objectIds.push(e.existingId),{success:!0,id:t.id,name:e.name,action:`update`}}{let t=u?{collection_id:u}:void 0,n=await i.objects.create({type:l||void 0,content:e.file,location:e.location||e.file.webkitRelativePath||e.name},t);m.push({id:n.id,name:e.name,type:l,status:`created`,location:e.location})}}catch(t){console.error(`Failed to process file ${e.name}:`,t),h.push({name:e.name,error:Ge(t,`Unknown error`),status:`failed`,location:e.location,type:l}),o({status:`error`,title:s(`store.processingFailedFor`,{name:e.name}),description:Ge(t),duration:4e3})}})),f=m.filter(e=>e.status===`created`),p=m.filter(e=>e.status===`updated`),g=m.filter(e=>e.status===`failed`);console.log(`Batch ${t+1} results:`,{creates:f,updates:p,failures:g,total:c.length})}}let x=m.filter(e=>e.status===`created`).length,S=m.filter(e=>e.status===`updated`).length,C=m.filter(e=>e.status===`failed`).length,w=m.filter(e=>e.status===`skipped`).length;t&&(console.log(`Upload complete:`,{totalObjectIds:d.objectIds.length,uploadedFiles:x,updatedFiles:S,skippedFiles:w,failedFiles:C}),await t(d.objectIds));let T=``;return x>0&&(T+=`${x} file${x===1?``:`s`} uploaded`),S>0&&(T+=T?`, `:``,T+=`${S} file${S===1?``:`s`} updated`),w>0&&(T+=T?`, `:``,T+=`${w} file${w===1?``:`s`} skipped (already existed)`),C>0&&(T+=T?`, `:``,T+=`${C} file${C===1?``:`s`} failed`),T&&o({status:C>0?`warning`:`success`,title:T,duration:4e3}),a.search(),d}}const z$=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function B$({isGridView:e=!1,onUpload:n,collectionId:r,...i}){return n?t(V$,{...i,onUpload:n,isGridView:e,collectionId:r}):t(H$,{...i,isGridView:e})}function V$({isGridView:e,onUpload:r,collectionId:i,skipTypeModal:a=!1,...o}){let[s,c]=G(!1),[l,u]=G([]),[d,f]=G(!1),[p,m]=G(null),[h,g]=G(!1),_=O$(),v=nt(),{t:y}=K(),{checkDocumentProcessing:b}=I$(),x=async(e,t)=>{console.log(`Files dropped on ObjectTable:`,e.length,t),c(!0);try{if(i){let t=await b(e,null,i);m(t);let n=t.filter(e=>e.action===`create`).length,r=t.filter(e=>e.action===`update`).length,a=t.filter(e=>e.action===`skip`).length;v({title:y(`store.filesReadyToProcess`),description:`${e.length} file(s): ${n} new, ${r} to update, ${a} to skip`,status:`info`,duration:4e3})}else m(null)}catch(e){console.error(`Error processing files:`,e),v({title:y(`store.errorProcessingFiles`),description:y(`store.errorCheckingDuplicates`),status:`error`,duration:4e3}),m(null)}finally{if(c(!1),u(e),f(!1),a){console.log(`Skipping type modal and calling onUpload directly`,{filesLength:e.length,processedFilesLength:p?.length});let t=r(e,null,i);t&&typeof t==`object`&&(t.processedFiles=p)}else console.log(`Setting typeSelectionOpen to true`,{filesLength:e.length}),g(!0)}},S=e=>{let t=[...l];u([]),m(null),g(!1),t.length>0&&e!==void 0&&(c(!0),console.log(`Starting upload with`,{typeId:e,filesCount:t.length,hasProcessingResults:!!p,collectionId:i}),r(t,e,i).finally(()=>{c(!1),_.search()}))},C=e=>{e.preventDefault(),e.stopPropagation(),f(!0)};return n(`div`,{className:`min-h-[400px] relative`,onDragOver:C,onDragEnter:C,onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),!e.currentTarget.contains(e.relatedTarget)&&f(!1)},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),f(!1),e.dataTransfer.items){let t=[];for(let n=0;n<e.dataTransfer.items.length;n++){let r=e.dataTransfer.items[n];if(r.kind===`file`){let e=r.getAsFile();e&&t.push(e)}}if(t.length>0){let e={count:t.length,message:`Preparing to upload ${t.length} file${t.length===1?``:`s`}...`};x(t,e)}}},children:[t(`div`,{className:it(`bg-white dark:bg-gray-800 opacity-40 absolute inset-0 z-50 flex justify-center items-center`,s?`block`:`hidden`),children:t(je,{size:`xl`})}),t(H$,{...o,isGridView:e}),t(`div`,{className:it(`absolute inset-0 pointer-events-none`,d?`z-40`:`-z-10`),children:t(`div`,{className:`w-full h-full relative`,children:t(Ot,{onDrop:x,message:`Drop files or folders here to upload`,className:it(`absolute inset-0 bg-white/90 dark:bg-gray-800/90 pointer-events-auto`,d?`flex`:`hidden`),buttonLabel:`Select Files or Folders`,allowFolders:!0})})}),t(L$,{isOpen:h&&l.length>0,onClose:()=>{u([]),m(null),g(!1),S(void 0)},files:l,collectionId:i,selectedFolder:null,title:`Upload Files`,onUploadComplete:e=>{if(e){if(e.failedFiles&&e.failedFiles.length>0&&v({title:y(`store.uploadIssues`),description:`${e.failedFiles.length} file(s) failed to upload`,status:`warning`,duration:5e3}),e.success){let t=e.uploadedFiles.filter(e=>e.status===`created`).length,n=e.uploadedFiles.filter(e=>e.status===`updated`).length,r=e.skippedFiles.length;(t>0||n>0)&&v({title:y(`store.uploadComplete`),description:`${t>0?`${t} created`:``}${t>0&&n>0?`, `:``}${n>0?`${n} updated`:``}${r>0?`, ${r} skipped`:``}`,status:`success`,duration:5e3})}_.search()}u([]),m(null),g(!1),e?.success&&e.objectIds.length>0?S(null):S(void 0)}})]})}function H$({objects:e,layout:n=z$,isLoading:r,onRowClick:i,onSelectionChange:a,highlightRow:o,previewObject:s,selectedObject:c,isGridView:l}){let u=VQ(),d=(t,n)=>{if(u){let r=n.nativeEvent instanceof MouseEvent&&n.nativeEvent.shiftKey;if(!n.target.checked)u.remove(t.id);else if(u.add(t),r){let n=e.findIndex(e=>e.id===t.id),r=U$(e,n,u);if(r>-1&&r<n-1){let t=[];for(let i=r+1;i<n;i++)t.push(e[i]);u.addAll(t)}else{let t=W$(e,n,u);if(t>-1&&t>n+1){let r=[];for(let i=n+1;i<t;i++)r.push(e[i]);u.addAll(r)}}}a?.(u)}},f=t=>{u&&(t.target.checked?u.addAll(e):u.removeAll())},p=U(()=>{let e=n.length>0?n:z$;return console.log(`Using layout with columns:`,e.map(e=>e.name).join(`, `)),e.map(e=>new x$(e,s))},[n,s]);return t(l?T$:w$,{objects:e,isLoading:r,columns:p,onRowClick:i,highlightRow:o,previewObject:s,selectedObject:c,selection:u,toggleAll:f,onSelectionChange:d})}function U$(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}function W$(e,t,n){let r=e.length;for(let i=t+1;i<r;i++)if(n.isSelected(e[i].id))return i;return-1}function G$({children:e,limit:n,parent:r,typeId:i,facets:a,name:o,collectionId:s}){let{store:c}=q(),l=U(()=>{let e;a?e=a:(e=[{name:`status`,field:`status`},{name:`location`,field:`location`}],i||e.unshift({name:`type`,field:`type`}));let t=new E$(c,n).withFacets(e);return t.collectionId=s,t.query.type=i,t.query.parent=r,t.query.name=o,s&&(t.query.all_revisions=!0),t},[s,a,n,o,r,c,i]);return t(D$.Provider,{value:l,children:e})}Q();const K$=`vertesia.content_store.lastDisplayedView`;function q$({onUpdate:e}){let{t:n}=K(),[r,i]=G(localStorage.getItem(K$)===`grid`),a=()=>{r?c():s()},s=()=>{localStorage.setItem(K$,`grid`),i(!0),e(!0)},c=()=>{localStorage.setItem(K$,`table`),i(!1),e(!1)};return t(o,{variant:`outline`,onClick:a,title:n(r?`misc.tableView`:`misc.thumbnailView`),children:t(r?sb:L_,{})})}q$.LAST_DISPLAYED_VIEW=K$,Q();const J$=[{name:`Name`,field:`properties.title`,type:`string`,fallback:`name`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Created At`,field:`created_at`,type:`date`}];function Y$({onChange:e,selectedIds:n}){return t(G$,{children:t(X$,{onRowClick:t=>{e(t||void 0)},selectedIds:n})})}function X$({onRowClick:e,selectedIds:r}){let{t:i}=K(),a=V(e=>!!r?.has(e.id),[r]),[s,c]=G(!1),[l,u]=G(localStorage.getItem(`vertesia.content_store.lastDisplayedView`)===`grid`),{search:d,isLoading:f,error:p,objects:m,hasMore:h}=A$(),g=W(null);Qe(g,()=>{s&&h&&!f&&(c(!1),d.loadMore(!0).finally(()=>{c(!0)}))},{threshold:.1,deps:[s,h,f]}),H(()=>{d.search().finally(()=>{c(!0)})},[d]);let _=k$(),v=O$();return p?t(M,{title:i(`store.searchFailed`),children:p.message}):n(`div`,{className:`flex flex-col gap-2 h-full w-full`,children:[n(`div`,{className:`flex justify-between items-center flex-shrink-0`,children:[t(aQ,{facets:_,search:v}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`outline`,onClick:()=>{c(!1),d.search().then(()=>c(!0))},"aria-label":`Refresh`,children:t(gy,{size:16})}),t(q$,{onUpdate:u})]})]}),n(`div`,{className:`@container relative flex-1 overflow-y-auto`,children:[t(B$,{objects:m||[],isLoading:!m.length&&f,layout:J$,onRowClick:e,highlightRow:r?.size?a:void 0,isGridView:l}),t(`div`,{ref:g,className:`h-4 w-full`})]})]})}Q();function Z$(e){let t=Math.max(0,e)/1e3,n=+(t>0&&t<10&&!Number.isInteger(t));return`${new Intl.NumberFormat(void 0,{maximumFractionDigits:n}).format(t)}K`}function Q$({onSend:e,onStop:r,approvalModeSlot:i,mcpSlot:a,disabled:s=!1,isSending:c=!1,isStopping:l=!1,isStreaming:u=!1,isCompleted:d=!1,contextWindowUsage:f,onCompactContext:p,isCompactingContext:m=!1,activeTaskCount:h=0,activeWorkstreams:g=[],onSelectWorkstream:_,placeholder:v,onFilesSelected:y,uploadedFiles:b=[],onRemoveFile:x,onRemoveProcessingFile:S,acceptedFileTypes:C,maxFiles:T=5,processingFiles:E,artifactRunId:D,hasProcessingFiles:O=!1,renderDocumentSearch:k,selectedDocuments:A=[],onRemoveDocument:j,hideObjectLinking:M=!1,hideFileUpload:N=!1,disableDropZone:P=!1,className:F,inputClassName:I}){let{t:L}=K(),ee=v??L(`agent.typeYourMessage`),R=W(null),te=W(null),[ne,re]=G(``),[ie,oe]=G(!1),[le,de]=G(!1),[fe,pe]=G(!1),me=!!(y&&!N),he=me&&!P,ge=!M||me||!!k,_e=b.length>=T,ve=S??x,ye=U(()=>g.filter(e=>e.status===`running`||e.status===`canceling`),[g]),be=ye.length||h,xe=f?L(`agent.contextUsageCompactLabel`,{percent:f.usedPercent}):void 0,Se=f?L(`agent.contextTokenUsage`,{used:Z$(f.usedTokens),limit:Z$(f.checkpointTokens)}):void 0,Ce=U(()=>{let e=[];if(!N&&E)for(let t of E.values()){let n=t.preview_url,r=t.status===mn.UPLOADING?L(`agent.uploading`):t.status===mn.PROCESSING?L(`agent.processing`):t.status===mn.ERROR?L(`agent.error`):t.status===mn.READY?L(`agent.ready`):t.status;e.push({id:t.id,name:t.name,contentType:t.content_type,artifactPath:t.artifact_path,previewUrl:n,removable:!!ve,statusLabel:r,statusTone:t.status===mn.ERROR?`destructive`:t.status===mn.READY?`success`:`attention`})}if(!N)for(let t of b)e.push({id:t.id,name:t.name,contentType:t.type,artifactPath:t.artifact_path,previewUrl:t.previewUrl,removable:!!x,statusLabel:L(`agent.ready`),statusTone:`success`});for(let t of A)e.push({id:t.id,name:t.name,href:`/store/objects/${t.id}`,removable:!!j,statusTone:`info`});return e},[ve,N,j,x,E,A,L,b]);H(()=>{!s&&d&&R.current?.focus()},[s,d]);let we=V(e=>{if(!me||!y)return;let t=Array.from(e),n=T-b.length,r=t.slice(0,n);r.length>0&&y(r)},[me,y,T,b.length]),Te=V(e=>{e.preventDefault(),e.stopPropagation(),he&&pe(!0)},[he]),Ee=V(e=>{e.preventDefault(),e.stopPropagation(),pe(!1)},[]),De=V(e=>{e.preventDefault(),e.stopPropagation(),pe(!1),he&&e.dataTransfer?.files&&e.dataTransfer.files.length>0&&we(e.dataTransfer.files)},[he,we]),Oe=V(e=>{if(!me)return;let t=EX(e.clipboardData?.items);t.length>0&&we(t)},[me,we]),ke=V(e=>{me&&e.target.files&&e.target.files.length>0&&(we(e.target.files),e.target.value=``)},[me,we]),Ae=V(()=>{te.current?.click()},[]),Me=V(()=>de(!1),[]),Ne=V(e=>de(!1),[]),Pe=()=>{let t=ne.trim();!t||s||c||O||(e(t),re(``))},Fe=()=>{r&&!l&&r()},Ie=W(0),Le=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),ne.trim().length>0&&Pe();return}e.shiftKey||(e.preventDefault(),Ke(e.currentTarget,re));return}if(e.key===`Escape`&&u&&r){let e=Date.now();e-Ie.current<500?(Fe(),Ie.current=0):Ie.current=e}},Re=V(()=>{let e=R.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[]);return H(()=>{Re()},[ne,Re]),n(`div`,{className:z(`px-3 py-3 flex-shrink-0 transition-all fixed lg:sticky bottom-0 start-0 end-0 lg:start-auto lg:end-auto w-full bg-background/95 backdrop-blur z-10`,fe&&he&&`bg-info/10 border-info`,F),onDragOver:he?Te:void 0,onDragLeave:he?Ee:void 0,onDrop:he?De:void 0,children:[fe&&he&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 rounded-lg z-10 pointer-events-none`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2`,children:[t(Tb,{className:`size-5`}),L(`agent.dropFilesToUpload`)]})}),me&&t(`input`,{ref:te,type:`file`,multiple:!0,accept:C,onChange:ke,className:`hidden`}),t(qX,{activeWorkstreams:g,onSelectWorkstream:_}),n(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-2 rounded-2xl border border-border/70 bg-mixer-muted/15 p-2.5 shadow-lg shadow-black/5`,children:[Ce.length>0&&t(zW,{items:Ce,artifactRunId:D,variant:`composer`,onRemove:e=>{E?.has(e)?ve?.(e):b.some(t=>t.id===e)?x?.(e):j?.(e)},className:`gap-1.5`}),t(`div`,{className:`flex min-w-0 flex-1`,children:t(Ue,{ref:R,value:ne,onKeyDown:Le,onChange:e=>re(e.target.value),onPaste:Oe,disabled:s,"aria-label":ee,placeholder:ee,rows:1,style:{maxHeight:`160px`},className:z(`min-h-[44px] resize-none border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,I)})}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[ge&&n(w,{align:`left`,trigger:t(o,{variant:`ghost`,size:`icon`,className:`size-8 rounded-full text-muted hover:bg-muted`,title:L(`agent.addAttachment`),children:t(sy,{className:`size-4`})}),children:[!M&&n(ae,{onClick:()=>oe(!0),isDisabled:!d,children:[t(Uv,{className:`size-4`}),L(`agent.linkObject`)]}),me&&n(ae,{onClick:Ae,isDisabled:_e,children:[t(Tb,{className:`size-4`}),L(`agent.upload`)]}),k&&n(ae,{onClick:()=>de(!0),children:[t(Kg,{className:`size-4`}),t(`span`,{children:L(`agent.searchDocuments`)}),A.length>0&&t(`span`,{className:`ms-auto inline-flex items-center justify-center rounded-full bg-info/20 px-1.5 py-0.5 text-[10px] font-medium text-info`,children:A.length})]})]}),i,a,f&&t(We,{asChild:!0,placement:`top`,size:`md`,className:`text-foreground shadow-lg`,description:n(`span`,{className:`block max-w-56 text-start text-sm leading-6`,children:[t(`span`,{className:`block`,children:L(`agent.contextRemainingUntilCompact`,{percent:f.remainingPercent})}),Se&&t(`span`,{className:`mt-1 block text-foreground/80`,children:Se})]}),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,className:z(`size-8 rounded-lg text-info hover:bg-muted hover:text-info disabled:opacity-60`,`focus-visible:ring-2 focus-visible:ring-info/40`),"aria-label":xe,onClick:p,disabled:!p||m,children:m?t(je,{size:`sm`}):n(`svg`,{viewBox:`0 0 24 24`,className:z(`size-8 -rotate-90`,f.usedPercent>=90?`text-destructive`:f.usedPercent>=70?`text-attention`:`text-info`),"aria-hidden":`true`,children:[t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,strokeWidth:`4.5`,className:`stroke-current text-muted/50`}),t(`circle`,{cx:`12`,cy:`12`,r:`9.75`,fill:`none`,pathLength:100,strokeWidth:`4.5`,strokeLinecap:`round`,strokeDasharray:100,style:{strokeDashoffset:100-f.usedPercent},className:`stroke-current`})]})})}),ye.length===0&&be>0&&t(`output`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,"aria-live":`polite`,children:n(`span`,{className:`inline-flex h-8 items-center gap-1 rounded-full px-2 text-xs text-muted`,children:[t(Sm,{className:`size-3 text-attention`}),L(`agent.activeWorkstreams`,{count:be})]})})]}),u&&r&&!ne.trim()?t(o,{onClick:Fe,disabled:l,variant:`ghost`,size:`icon`,className:z(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`,`[&_svg]:text-destructive disabled:[&_svg]:text-muted`),title:L(`agent.stopTooltip`),children:l?t(je,{size:`sm`}):t(ib,{className:`size-3 fill-current stroke-current`})}):t(o,{onClick:Pe,disabled:s||c||!ne.trim()||O,variant:`ghost`,size:`icon`,className:z(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:L(O?`agent.waitForFiles`:`agent.sendTooltip`),"aria-label":L(O?`agent.waitForFiles`:`agent.send`),children:c?t(je,{size:`sm`}):t(Om,{className:`size-4`})})]})]}),n(se,{isOpen:ie,onClose:()=>oe(!1),className:`min-w-[60vw]`,children:[t(ue,{children:L(`agent.linkObject`)}),t(ce,{className:`pb-6`,children:t(Y$,{onChange:e=>{let t=`[${e.properties?.title||e.name||`Object`}](store:${e.id})`,n=ne||``,r=R.current?.selectionStart||n.length,i=n.substring(0,r)+t+n.substring(r);re(i),oe(!1),setTimeout(()=>{if(R.current){R.current.focus();let e=r+t.length;R.current.setSelectionRange(e,e)}},100)}})})]}),k?.({isOpen:le,onClose:Me,onSelect:Ne})]})}function $$({code:e}){let{onProposalSelect:n,onProposalSubmit:r}=qt(),i=U(()=>Wt(e),[e]),a=U(()=>{if(i)return null;try{let t=e.trim(),i=JSON.parse(t);if(!i.options||!i.question&&!i.title)return null;let a={question:i.question||i.title||``,description:i.description,options:Array.isArray(i.options)?i.options.map(e=>({id:e.id||e.value||``,label:e.label||``,description:e.description})):void 0,allowFreeResponse:i.allowFreeResponse??i.multiple,variant:i.variant,onSelect:n,onSubmit:r};return!a.question||!a.options?.length?null:a}catch{return null}},[e,n,r,i]);return i?t(Et,{type:`proposal`,message:`Loading options...`}):a?t(Tt,{type:`proposal`,fallbackCode:e,children:t(AH,{...a})}):t(Et,{type:`proposal`,error:`Invalid proposal specification`})}const e1=gt(function({code:e}){let n=U(()=>{try{let t=JSON.parse(e);return t?.library===`vega-lite`&&t?.spec&&typeof t.spec==`object`?t:typeof t?.$schema==`string`&&t.$schema.includes(`vega`)?{library:`vega-lite`,spec:t}:null}catch{return null}},[e]);return n?t(sC,{spec:n}):null}),t1=gt(function({code:e}){let n=U(()=>{try{return{library:`vega-lite`,spec:JSON.parse(e)}}catch{return null}},[e]);return n?t(sC,{spec:n}):null}),n1={chart:e1,"vega-lite":t1,vegalite:t1,"fusion-fragment":Yn,proposal:$$,askuser:$$};function r1({url:e,code:n}){let[r,i]=G(null);return H(()=>{import(e).then(e=>{i(()=>e.default)}).catch(t=>{console.error(`Failed to load remote widget component from `,e,t)})},[e]),r?t(r,{code:n}):null}async function i1(e){let n=await e.apps.getInstalledApps(`tools`),r=new Set;for(let e of n){if(e.manifest.tool_collections&&e.manifest.tool_collections.length>0)for(let t of e.manifest.tool_collections||[]){let e=jn(t).url;if(e.startsWith(`http://`)||e.startsWith(`https://`)){let t=e.indexOf(`/api/`);if(t>0){let n=e.substring(0,t);r.add(`${n}/api/widgets`)}}}e.manifest.endpoint&&e.manifest.capabilities?.includes(`tools`)&&r.add(new URL(`/api/widgets`,e.manifest.endpoint).toString())}let i=await Promise.all(Array.from(r).map(e=>fetch(e).then(e=>{if(!e.ok)throw Error(`Failed to fetch widgets: ${e.status} ${e.statusText}`);return e.json()}).then(e=>{let n=[],r=e.widgets;for(let[e,i]of Object.entries(r))n.push({name:e,component:e=>t(r1,{url:i.url,code:e.code})});return n}).catch(()=>(console.error(`Failed to fetch skill widgets from `,e),null)))),a={};for(let e of i.flat())e&&(a[e.name]=e.component);return a}function a1({children:e}){let{client:n}=q(),[r,i]=G(n1);return H(()=>{i1(n).then(e=>{i({...n1,...e})})},[n]),t(Dt,{components:r,children:e})}Q();const o1=new Map,s1=[400,1200];async function c1(e,t,n){for(let r=0;;r++)try{return await e.agents.sendSignal(t,`FileBatchClosed`,n),!0}catch(e){if(r>=s1.length)return console.error(`Failed to close staged file batch:`,e),!1;await new Promise(e=>setTimeout(e,s1[r]))}}function l1(e){if(typeof e==`number`)return e;if(!e)return Date.now();let t=new Date(e).getTime();return Number.isFinite(t)?t:Date.now()}function u1(e){return e===`running`||e===`canceling`}function d1(e){return!u1(e)}function f1(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function p1(e){for(let t=e.length-1;t>=0;t--){let n=e[t].details;if(!n)continue;let r=n.token_usage,i=f1(r?.prompt),a=i&&i>0?i:f1(r?.total),o=f1(n.checkpoint_threshold)??f1(n.checkpoint_at);if(typeof a!=`number`||typeof o!=`number`||o<=0)continue;let s=Math.max(0,Math.min(100,Math.round(a/o*100)));return{usedTokens:a,checkpointTokens:o,usedPercent:s,remainingPercent:Math.max(0,100-s)}}}function m1(e,t){return!d1(e.status)||!u1(t.status)?{...e,...t}:{...e,interaction:e.interaction??t.interaction,elapsed_ms:Math.max(e.elapsed_ms,t.elapsed_ms),deadline_ms:Math.max(e.deadline_ms,t.deadline_ms),remaining_ms:0,phase:e.phase??t.phase,child_workflow_id:e.child_workflow_id??t.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id??t.child_workflow_run_id}}function h1(e){let t=e.details,n=typeof t?.workstream_id==`string`&&t.workstream_id.trim()?t.workstream_id:$H(e);return n===`main`||n===`all`?null:{workstreamId:n,launchId:typeof t?.launch_id==`string`?t.launch_id:void 0,interaction:typeof t?.interaction==`string`?t.interaction:void 0,childWorkflowId:typeof t?.child_workflow_id==`string`?t.child_workflow_id:void 0,childWorkflowRunId:typeof t?.child_workflow_run_id==`string`?t.child_workflow_run_id:void 0}}function g1(e){if(e.type!==J.ERROR)return!1;let t=e.details;if(t?.event_class!==`activity`||t.workstream_event)return!1;let n=typeof e.workstream_id==`string`&&e.workstream_id.trim()?e.workstream_id.trim():typeof t.workstream_id==`string`?t.workstream_id.trim():``,r=n.toLowerCase();return!n||r===`main`||r===`all`?!1:!(t.tool||t.tool_status||t.tool_run_id||t.activity_group_id||t.tool_event)}function _1(e,t,n,r,i,a){if(r){let a=t.get(n);if(a?.startsWith(`message-derived:`)){let t=e.get(a);t&&(e.delete(a),e.set(r,{...t,launch_id:r,updated_at:Math.max(t.updated_at,i)}))}t.set(n,r)}let o=r??t.get(n)??`message-derived:${n}`,s=e.get(o);if(s)return s;let c={workstream_id:n,launch_id:o,elapsed_ms:0,deadline_ms:0,remaining_ms:0,status:`running`,started_at:i,updated_at:i,order:a};return e.set(o,c),t.has(n)||t.set(n,o),c}function v1(e){let t=new Map,n=new Map;return e.forEach((e,r)=>{let i=l1(e.timestamp),a=h1(e),o=HH(e),s=o?.workstreamId??a?.workstreamId;if(!s)return;let c=o?.launchId??a?.launchId,l=zH(e);if(!o&&!c&&l&&!n.has(s))return;let u=_1(t,n,s,c,i,r);o?(u.interaction=o.interaction??u.interaction,u.child_workflow_id=o.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=o.childWorkflowRunId??u.child_workflow_run_id,u.status=`running`):(u.interaction=a?.interaction??u.interaction,u.child_workflow_id=a?.childWorkflowId??u.child_workflow_id,u.child_workflow_run_id=a?.childWorkflowRunId??u.child_workflow_run_id);let d=VH(e);d?u.status=d:l||(g1(e)?u.status=`failed`:(e.type===J.COMPLETE||e.type===J.IDLE)&&(u.status=`completed`)),!l&&(u.updated_at=Math.max(u.updated_at,i),u1(u.status)?u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at):(u.elapsed_ms=Math.max(u.elapsed_ms,i-u.started_at),u.remaining_ms=0))}),Array.from(t.values()).sort((e,t)=>{let n=Number(!u1(e.status))-Number(!u1(t.status));return n===0?u1(e.status)?e.order-t.order:t.updated_at-e.updated_at||e.order-t.order:n}).map(({started_at:e,updated_at:t,order:n,...r})=>r)}function y1(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.elapsed_ms,deadline_ms:e.deadline_ms,remaining_ms:Math.max(0,e.deadline_ms-e.elapsed_ms),status:e.status,phase:e.latest_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function b1(e){return{workstream_id:e.workstream_id,launch_id:e.launch_id,interaction:e.interaction,elapsed_ms:e.duration_ms??0,deadline_ms:0,remaining_ms:0,status:e.status,phase:e.last_progress?.phase,child_workflow_id:e.child_workflow_id,child_workflow_run_id:e.child_workflow_run_id}}function x1(e,t){let n=e.findIndex(e=>e.launch_id===t.launch_id);if(n>=0){e[n]=m1(e[n],t);return}let r=e.findIndex(e=>e.workstream_id===t.workstream_id&&e.launch_id.startsWith(`message-derived:`));if(r>=0&&!t.launch_id.startsWith(`message-derived:`)){e[r]=m1(e[r],t);return}e.push(t)}function S1(e){if(e<60)return`${e}s`;let t=Math.floor(e/60),n=e%60;return n>0?`${t}m ${n}s`:`${t}m`}function C1(e,t=!0){let[n,r]=G(()=>Math.max(0,Math.floor((Date.now()-l1(e))/1e3)));return H(()=>{if(!t)return;let n=()=>{r(Math.max(0,Math.floor((Date.now()-l1(e))/1e3)))};n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function w1(e=!0){let[t,n]=G(0);return H(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*xW.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function T1({message:e,startedAt:r}){let{t:i}=K(),a=C1(r),o=w1();return n(`div`,{className:`mx-auto flex min-h-full w-full max-w-3xl flex-col justify-end gap-6 px-1 py-8`,children:[t(`div`,{className:`flex w-full justify-end`,children:t(`div`,{className:z(`max-w-[min(44rem,82%)] rounded-[1.35rem] bg-mixer-muted/35 px-4 py-2.5`,`break-words text-sm font-normal leading-6 text-foreground/90 shadow-sm shadow-black/5`,`dark:bg-mixer-muted/15 dark:text-foreground/88 dark:shadow-none [overflow-wrap:anywhere]`),children:t(`div`,{className:`whitespace-pre-wrap`,children:e})})}),n(`div`,{className:`border-b border-border/70 pb-4 text-sm text-muted`,children:[n(`div`,{className:`flex items-center gap-3`,children:[t(rW,{size:`sm`,color:`blue`}),n(`div`,{className:`min-w-0`,children:[n(`div`,{children:[t(`span`,{className:`font-medium`,children:i(`agent.preparing`)}),n(`span`,{className:`ms-2 text-muted/75`,children:[`for `,S1(a)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:xW[o]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(nW,{color:`blue`})})]})]})}function E1(e,t){if(typeof window>`u`||typeof document>`u`)return!1;let n=document.createElement(`iframe`);n.style.position=`fixed`,n.style.right=`0`,n.style.bottom=`0`,n.style.width=`0`,n.style.height=`0`,n.style.border=`0`,n.style.visibility=`hidden`,document.body.appendChild(n);let r=n.contentWindow;if(!r)return n.parentNode?.removeChild(n),!1;let i=r.document;return i.open(),i.write(`<!doctype html><html><head><title></title></head><body></body></html>`),i.close(),i.title=t,document.querySelectorAll(`link[rel="stylesheet"], style`).forEach(e=>{i.head.appendChild(e.cloneNode(!0))}),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}function D1(e){let t=0,n=e.length;for(;t<n&&e[t]===`-`;)t++;for(;n>t&&e[n-1]===`-`;)n--;return e.slice(t,n)}function O1(e){return D1(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function k1(e,t){let n=new Blob([JSON.stringify(t,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function A1(e){let{agentRunId:n,startWorkflow:r,resourceResolver:i}=e;if(n){let r=t(a1,{children:t(N1,{...e,agentRunId:n})});return i?t(Ct,{value:i,children:r}):r}return r?t(M1,{...e}):t(j1,{})}function j1(){let{t:e}=K();return n(oe,{status:`info`,icon:t(jm,{className:`size-16 text-muted mb-4`}),children:[t(`div`,{className:`text-base font-medium text-muted`,children:e(`agent.noAgentRunning`)}),t(`div`,{className:`mt-3 text-sm text-muted`,children:e(`agent.selectInteraction`)})]})}function M1({initialMessage:e,interactive:r=!0,startWorkflow:i,onClose:a,isModal:s=!1,fullWidth:c=!1,placeholder:l,startButtonText:u,title:d,getAttachedDocs:f,onAttachmentsSent:p,acceptedFileTypes:m,maxFiles:h=5,hideHeader:g=!1,hideFileUpload:_=!1,hideObjectLinking:v,headerVariant:y,startViewVariant:b=`default`,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,initialToolApprovalMode:T,onAgentWorkingChange:E}){let{t:D}=K(),O=b!=="default",k=b===`expanded-composer`,A=!_,j=l??D(`agent.typeYourMessage`),M=u??D(`agent.startAgent`),N=d??D(`agent.startNewConversation`),{client:P}=q(),[F,I]=G(``),[L,ee]=G(!1),[R,te]=G(null),[ne,re]=G(null),[ie,ae]=G(null),[oe,se]=G(()=>An(T,r)),ce=nt(),le=W(null),ue=W(null),[de,fe]=G([]),[pe,me]=G(!1),he=pe?de:de.slice(0,3),ge=de.length-3;H(()=>{E?.(L)},[L,E]);let[_e,ve]=G(!1),ye=W(0),be=V(e=>{A&&(e.preventDefault(),e.stopPropagation(),ye.current++,e.dataTransfer?.types?.includes(`Files`)&&ve(!0))},[A]),xe=V(e=>{A&&(e.preventDefault(),e.stopPropagation())},[A]),Se=V(e=>{A&&(e.preventDefault(),e.stopPropagation(),ye.current--,ye.current===0&&ve(!1))},[A]),Ce=V(e=>{if(A&&(e.preventDefault(),e.stopPropagation(),ye.current=0,ve(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);fe(e=>[...e,...t].slice(0,h))}},[h,A]),we=V(e=>{if(!A)return;let t=EX(e.clipboardData?.items);t.length>0&&fe(e=>[...e,...t].slice(0,h))},[A,h]),Te=V(e=>{if(e.target.files&&e.target.files.length>0){let t=Array.from(e.target.files);fe(e=>[...e,...t].slice(0,h))}e.target.value=``},[h]),Ee=V(e=>{fe(t=>t.filter((t,n)=>n!==e))},[]);H(()=>{de.length<=3&&me(!1)},[de.length]),H(()=>{le.current&&le.current.focus()},[]);let De=async()=>{if(!i)return;let e=F.trim();if(!(!e||L)){ee(!0);try{sessionStorage.removeItem(`plan-panel-shown`),ce({title:A&&de.length>0?D(`agent.startingAgentUploading`):D(`agent.startingAgent`),status:`info`,duration:3e3});let t=f?.()||[],n=e;if(t.length>0&&!/store:\S+/.test(e)&&(n=[e,``,`Attachments:`,...t.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
1381
1381
  `)),A&&de.length>0){let e=de.map(e=>e.name).join(`, `);n=[n,``,`[System: ${de.length} file(s) are being uploaded: ${e}. Please wait for the "Files Ready" notification before processing them.]`].join(`
1382
- `)}let r=await i(n,{tool_approval_mode:oe});if(!r){re(null),ae(null);return}re(n),ae(Date.now());let a=r.agent_run_id,o=!0;if(A&&de.length>0){let e=`batch-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,t=[],n=[];for(let e of de)try{let n=`files/${e.name}`;await P.agents.uploadArtifact(a,n,e);let r=`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;await P.agents.sendSignal(a,`FileUploaded`,{id:r,name:e.name,content_type:e.type||`application/octet-stream`,reference:`artifact:${n}`,artifact_path:n}),t.push(r)}catch(t){console.error(`Failed to upload staged file ${e.name}:`,t),n.push({name:e.name,error:t instanceof Error?t.message:String(t)})}o=await o1(P,a,{batch_id:e,file_ids:t,failed_uploads:n.length>0?n:void 0}),o&&fe([]),n.length>0&&ce({title:D(`agent.stagedFilesUploadFailed`),status:`warning`,duration:6e3,description:n.map(e=>e.name).join(`, `)})}p?.(),te(a),I(``),ce(o?{title:D(`agent.agentStarted`),status:`success`,duration:3e3}:{title:D(`agent.stagedFilesNotDelivered`),status:`error`,duration:8e3,description:D(`agent.stagedFilesNotDeliveredDescription`)})}catch(e){re(null),ae(null),ce({title:D(`agent.errorStarting`),status:`error`,duration:3e3,description:e instanceof Error?e.message:D(`agent.unknownError`)})}finally{ee(!1)}}},Oe=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),De();return}e.shiftKey||(e.preventDefault(),Ke(e.currentTarget,I))}},ke=V(()=>{let e=le.current;if(e){if(k){e.style.height=`100%`;return}e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`}},[k]);return H(()=>{ke()},[F,ke]),R?t(j1,{onClose:a,isModal:s,initialMessage:e,placeholder:l,fullWidth:c,hideHeader:g,headerVariant:y,hideFileUpload:_,hideObjectLinking:v,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,onAgentWorkingChange:E,agentRunId:R,title:d,pendingStartMessage:ne??void 0,pendingStartTimestamp:ie??void 0,initialToolApprovalMode:oe}):t(`div`,{className:z(`flex flex-col items-center bg-background`,O&&!k?``:`h-full`,C),children:n(`div`,{className:z(`relative flex w-full flex-col overflow-hidden border-0`,O&&!k?``:`h-full`,c?``:`max-w-4xl`),onDragEnter:A?be:void 0,onDragOver:A?xe:void 0,onDragLeave:A?Se:void 0,onDrop:A?Ce:void 0,children:[A&&_e&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-info-background z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(Tb,{className:`size-6`}),`Drop files to stage for upload`]})}),A&&t(`input`,{ref:ue,type:`file`,multiple:!0,accept:m,onChange:Te,className:`hidden`}),!g&&n(`div`,{className:`flex items-center justify-between border-b border-border/60 bg-background px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{className:`p-1`,children:t(gg,{className:`size-3.5 text-muted`})}),t(`span`,{className:`text-sm font-medium text-foreground`,children:N})]}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,title:D(`agent.close`),className:`text-muted hover:text-foreground`,children:t(Kb,{className:`size-4`})})]}),t(`div`,{className:z(`flex flex-col items-center justify-end bg-background px-4`,O?`shrink-0 pt-3`:`flex-1 overflow-y-auto`),children:ne&&ie?t(C1,{message:ne,startedAt:ie}):t(`div`,{className:z(`mx-auto flex w-full max-w-3xl flex-col justify-end`,O?``:`min-h-full py-8`),children:e&&t(`div`,{className:`text-[15px] leading-relaxed text-foreground/80`,children:e})})}),t(`div`,{className:z(`bg-background px-4 pb-safe-area-4 pt-2`,k?`flex min-h-0 flex-1 flex-col`:`shrink-0`),children:n(`div`,{className:z(`mx-auto flex max-w-3xl flex-col gap-3 rounded-2xl border border-border/70 bg-mixer-muted/15 p-3 shadow-lg shadow-black/5`,k&&`min-h-0 w-full flex-1`,x),children:[A&&de.length>0&&n(`div`,{className:`flex flex-wrap gap-2`,children:[he.map((e,r)=>n(`div`,{className:`flex items-center gap-1.5 rounded-md bg-attention/10 px-2 py-1 text-sm text-attention`,title:D(`agent.fileStagedTooltip`),children:[t(Kg,{className:`size-3.5`}),t(`span`,{className:`max-w-[120px] truncate`,children:e.name}),t(`span`,{className:`text-xs opacity-70`,children:D(`agent.staged`)}),t(o,{variant:`unstyled`,"aria-label":`Remove staged file ${e.name}`,onClick:()=>Ee(r),className:`ms-1 rounded p-0.5 hover:bg-attention/20`,children:t(Kb,{className:`size-3`})})]},`${e.name}-${e.size}-${e.lastModified}`)),de.length>3&&n(o,{type:`button`,variant:`ghost`,size:`sm`,"aria-expanded":pe,onClick:()=>me(e=>!e),className:`h-8 shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,children:[!pe&&n(`span`,{children:[`+`,ge]}),D(pe?`agent.showLess`:`agent.showMore`),t(ih,{className:z(`size-3.5 transition-transform`,pe&&`rotate-180`),"aria-hidden":`true`})]})]}),t(Ue,{ref:le,value:F,onChange:e=>I(e.target.value),onKeyDown:Oe,onPaste:we,placeholder:j,disabled:L,rows:2,className:z(`min-h-[72px] resize-none border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,k?`min-h-0 flex-1 overflow-y-auto`:`overflow-hidden`,S),style:k?{minHeight:`72px`,maxHeight:`none`}:{minHeight:`72px`,maxHeight:`200px`}}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[A&&t(o,{variant:`ghost`,size:`icon`,onClick:()=>ue.current?.click(),disabled:L||de.length>=h,"aria-label":D(`agent.upload`),className:`rounded-full text-muted`,title:D(`agent.upload`),children:t(Tb,{className:`size-4`})}),r&&t(Xb,{mode:oe,onChange:se,disabled:L})]}),t(o,{onClick:De,disabled:!F.trim()||L,variant:`ghost`,size:`icon`,className:z(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:M,children:L?t(je,{size:`sm`}):t(Om,{className:`size-4`})})]})]})})]})})}function j1({agentRunId:r,title:i,interactive:a=!0,onClose:s,isModal:c=!1,fullWidth:l=!1,placeholder:u,resetWorkflow:d,onRestart:f,onClone:p,onShowDetails:m,allowWorkflowControl:h=!0,uploadedFiles:g,onRemoveFile:_,acceptedFileTypes:v,maxFiles:y,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideHeader:w,headerVariant:T=`full`,hideMessageInput:E,failedAction:D,hidePlanPanel:O,hideWorkstreamTabs:k,showRightPanel:A=!0,hideFileUpload:j,showArtifacts:M=!1,hideDocumentPanel:N,hiddenMessageTypes:P,getAttachedDocs:F,onAttachmentsSent:I,isUploading:L=!1,getMessageContext:ee,className:R,inputContainerClassName:te,inputClassName:ne,composerContext:re,fusionData:ie,fileUploadRef:ae,sendMessageRef:de,onMessage:fe,onAgentWorkingChange:pe,onProcessingFilesChange:me,processingFiles:he,onPlansChange:ge,onWorkstreamStatusChange:_e,viewMode:ve,onViewModeChange:ye,onShowInputChange:be,stopRef:xe,onStoppingChange:Se,messageItemClassNames:Ce,messageStyleOverrides:we,toolCallGroupClassNames:Te,hideToolCallsInViewMode:Ee,streamingMessageClassNames:De,batchProgressPanelClassNames:Oe,workingIndicatorClassName:ke,messageListClassName:Ae,StoreLinkComponent:je,CollectionLinkComponent:Me,prependFriendlyMessage:Ne,initialRequestData:Pe,initialRequestSchema:Fe,initialRequestTitle:Ie,initialRequestTemplate:Le,payloadContent:Re,conversationContent:ze,conversationTab:Be=!1,pendingStartMessage:Ve,pendingStartTimestamp:He,initialToolApprovalMode:Ue,enablePlayback:We,showPlaybackToggle:Ge=!0,messageFilter:Ke,initialWorkstream:qe}){let{t:Je}=K(),{client:Ye}=q(),Xe=nt(),{messages:Ze,streamingMessages:Qe,isCompleted:$e,initialHistoryStatus:et,debugChunkFlash:tt,addOptimisticMessage:rt,updateOptimisticMessageStatus:it,reconnect:at,agentRunStatus:B,workflowRunId:ot,serverFileUpdates:st}=LX(Ye,r,fe),{plans:ct,activePlanIndex:lt,setActivePlanIndex:ut,workstreamStatusMap:dt,showInput:ft,showSlidingPanel:pt,setShowSlidingPanel:mt}=EX(Ze,a,c),{openDocuments:ht,activeDocumentId:gt,isDocPanelOpen:_t,docRefreshKey:vt,closeDocPanel:yt,closeDocument:bt,selectDocument:xt,openDocInPanel:St,updateDocumentTitle:Ct}=VX(Ze),{processingFiles:wt,hasProcessingFiles:Tt,handleFileUpload:Et,removeProcessingFile:Dt,clearProcessingFiles:Ot}=GX(Ye,r,st,Xe,U(()=>GW(Ze),[Ze])),kt=a&&!j,At=V(e=>{Dt(e)},[Dt]),jt=W(null),Mt=W(null),Nt=W(null),[Pt,Ft]=G(!1),[It,Lt]=G(!1),[Rt,zt]=G(`sliding`),Bt=ve??Rt,Vt=V(e=>{ye?ye(e):zt(e)},[ye]),[Ht,Wt]=G(!1),[Gt,Kt]=G(!1),[qt,Jt]=G(qe||`all`),Yt=W(qe);H(()=>{qe&&qe!==Yt.current&&(Yt.current=qe,Jt(qe))},[qe]);let[Xt,Zt]=G(`live`),[Qt,$t]=G(!1),[en,tn]=G(0),[nn,rn]=G([]),[an,on]=G([]),[sn,cn]=G(!1),ln=U(()=>Ue===void 0&&a?void 0:An(Ue,a),[Ue,a]),[un,dn]=G(ln),fn=W(!1),pn=W(0),hn=W(!1),gn=W(0),_n=W(null);H(()=>{dn(ln)},[ln]);let vn=W(Pt);vn.current=Pt;let yn=W(Tt);yn.current=Tt;let bn=W(wt);bn.current=wt;let xn=U(()=>{let e=Ze.filter(e=>(e.workstream_id||`main`)===`main`);return e[e.length-1]},[Ze]),Sn=U(()=>xn?.type===J.TERMINATED?`TERMINATED`:xn?.type===J.COMPLETE&&(!B||B===`RUNNING`)?`COMPLETED`:B,[xn,B]),Cn=U(()=>{let e=Sn?.toUpperCase();return e===`COMPLETED`||e===`FAILED`||e===`CANCELED`||e===`CANCELLED`||e===`TERMINATED`||e===`TIMED_OUT`},[Sn]),wn=U(()=>Cn&&Sn?.toUpperCase()!==`FAILED`&&!!f,[Cn,Sn,f]),Tn=!E||wn,En=U(()=>Sn?.toUpperCase()===`FAILED`||B?.toUpperCase()===`FAILED`,[Sn,B]),Dn=U(()=>{for(let e=Ze.length-1;e>=0;e--){let t=Ze[e];if(t.type!==J.ERROR||$H(t)!==`main`)continue;let n=typeof t.message==`string`?t.message.trim():``;if(n)return n}},[Ze]),On=W(Cn);On.current=Cn;let kn=W(wn);kn.current=wn;let jn=U(()=>{let e=ct[lt]||{plan:{plan:[]},timestamp:0},t=dt.get(e.timestamp)||new Map;return{plan:e.plan,workstreamStatus:t}},[ct,lt,dt]),Mn=U(()=>g1(Ze),[Ze]),Nn=U(()=>{let e=[...Mn];for(let t of an)y1(e,v1(t));for(let t of nn)y1(e,_1(t));return e.map((e,t)=>({workstream:e,index:t})).sort((e,t)=>Number(!c1(e.workstream.status))-Number(!c1(t.workstream.status))||e.index-t.index).map(({workstream:e})=>e)},[Mn,nn,an]),Pn=U(()=>Nn.filter(e=>c1(e.status)),[Nn]),Fn=U(()=>Pn.filter(e=>e.status===`running`).length,[Pn]),In=U(()=>{if(qt===`all`)return;let e=Nn.find(e=>e.workstream_id===qt||e.launch_id===qt);return e?PH(e.workstream_id,e.interaction):PH(qt)},[qt,Nn]),Ln=U(()=>{if(u)return u;if(In)return Je(`agent.messageMainAgentWhileViewingWorkstream`,{workstream:In})},[In,u,Je]),Rn=Ge&&We===void 0&&vC(),zn=We??(yC()||Qt),Bn=U(()=>Ze.filter(e=>!YH(e)&&!(P?.includes(e.type)??!1)),[P,Ze]),Vn=U(()=>nU(Bn,qt),[qt,Bn]),Hn=U(()=>gC(Vn,Xt,zn),[zn,Xt,Vn]),Un=Hn.cursor,Wn=Hn.isLive,Gn=zn&&!Wn&&Hn.cursorIndex===Vn.length-1,Kn=Hn.displayedMessages,qn=U(()=>Ke?Kn.filter(e=>Ke(e)):Kn,[Kn,Ke]),Jn=U(()=>Ke?Bn.filter(e=>Ke(e)):Bn,[Ke,Bn]),Yn=Wn?Qe:i1,Zn=U(()=>g1(Kn),[Kn]),Qn=U(()=>Zn.filter(e=>c1(e.status)),[Zn]),$n=U(()=>$e||!XH(Ze),[$e,Ze]),er=Wn||Gn?$n:!1,tr=!$n&&!Cn;H(()=>{pe?.(tr)},[tr,pe]);let nr=U(()=>{let e=new Set;for(let t of Kn)MU(r,t)&&e.add(OU(t));return $U(Kn,`main`,e)},[r,Kn]),rr=!!nr&&!En&&(!Cn||wn),ir=zn&&!Wn,ar=Tn&&!ir,or=U(()=>d1(Ze),[Ze]),sr=h&&!Cn&&Wn&&!!or;H(()=>{KH(`conversation render state`,{agentRunId:r,messageCount:Ze.length,playbackMessageCount:Vn.length,displayedMessageCount:qn.length,streamingCount:Qe.size,displayedStreamingCount:Yn.size,initialHistoryStatus:et,isCompleted:$e,effectiveIsCompleted:$n,displayedIsCompleted:er,agentRunStatus:B,effectiveWorkflowStatus:Sn,isWorkflowTerminal:Cn,playbackCursor:Un,isPlaybackEnabled:zn,isPlaybackLive:Wn,isPlaybackAtLatest:Gn,activeWorkstream:qt,showInitialRequest:et===`empty`&&Ze.length===0,pendingStartVisible:Ze.length===0&&!$n&&!!Ve})},[qt,r,B,Un,er,qn.length,Yn.size,$n,Sn,et,$e,Gn,zn,Wn,Cn,Ze.length,Ve,Vn.length,Qe.size]);let cr=V(()=>{$t(e=>!e)},[]),lr=V(e=>{let t=pC(Un,Vn.length),n=pC(e,Vn.length);zn&&(n>t||e===`live`&&Un!==`live`)&&(hn.current=!0,tn(e=>e+1)),Zt(e)},[Un,zn,Vn.length]);H(()=>{if(!zn){Xt!==`live`&&Zt(`live`);return}Un!==Xt&&Zt(Un)},[Un,zn,Xt]),H(()=>{if(!zn||!hn.current)return;hn.current=!1;let e=window.requestAnimationFrame(()=>{jt.current?.scrollIntoView({behavior:`smooth`,block:`end`})});return()=>window.cancelAnimationFrame(e)},[zn,en]);let ur=V(e=>{ut(e)},[ut]),[dr,fr]=G(ze||Be?`conversation`:`plan`),[pr,Y]=G(null),[mr,hr]=G(400),[gr,_r]=G(!1),[vr,yr]=G(!1),br=A&&!vr&&(pt||_t||!k&&Nn.length>0||!!ze||Be),xr=W(_t);H(()=>{_t&&!xr.current&&yr(!1),xr.current=_t},[_t]);let Sr=V(()=>{br?(yr(!0),mt(!1)):(yr(!1),mt(!0),sessionStorage.setItem(`plan-panel-shown`,`true`))},[br,mt]);H(()=>{!br&&gr&&_r(!1)},[br,gr]),H(()=>{if(!gr)return;let e=e=>{let t=Nt.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(300,n.width-420),i=n.right-e.clientX;hr(Math.min(Math.max(i,300),r))},t=()=>{_r(!1)};return window.addEventListener(`mousemove`,e),window.addEventListener(`mouseup`,t),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,()=>{window.removeEventListener(`mousemove`,e),window.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[gr]);let Cr=V(()=>{yr(!0),mt(!1),yt()},[mt,yt]),wr=V(e=>{/\.md$/i.test(e)&&(yr(!1),Y(e),fr(`artifacts`),mt(!0))},[mt]),Tr=W(null);H(()=>{let e,t;for(let n of Ze){let r=n.details;r?.event_class===`display_artifact`&&typeof r.path==`string`&&(e=r.path,t=`${n.timestamp??``}:${r.path}`)}!e||!t||t===Tr.current||(Tr.current=t,yr(!1),Y(e),fr(`artifacts`),mt(!0))},[Ze,mt]);let Er=V(({href:e,documentId:n,children:r})=>t(`a`,{href:e,className:`text-info underline cursor-pointer hover:text-info/80`,onClick:e=>{e.preventDefault(),e.stopPropagation(),St(n),fr(`documents`)},children:r}),[St]),Dr=je??Er;H(()=>(ae&&(ae.current=kt?Et:null),()=>{ae&&(ae.current=null)}),[ae,Et,kt]),H(()=>{me?.(wt)},[wt,me]),H(()=>{ge?.(ct,lt)},[ct,lt,ge]),H(()=>{_e?.(dt)},[dt,_e]),H(()=>{Y(null),fn.current=!1,cn(!1),rn([]),on([])},[r]),H(()=>{let e=et!==`loading`&&!$n&&!Cn&&!sn;if(KH(`active workstreams poll state`,{agentRunId:r,shouldPoll:e,initialHistoryStatus:et,effectiveIsCompleted:$n,isWorkflowTerminal:Cn,isWorkstreamQueryUnavailable:sn}),!e){rn(e=>e.length===0?e:[]);return}let t=!1,n=!1,i=async()=>{if(n){KH(`active workstreams fetch skipped while previous request is pending`,{agentRunId:r});return}n=!0;try{KH(`active workstreams fetch start`,{agentRunId:r});let e=await Ye.agents.getActiveWorkstreams(r);if(t)return;if(KH(`active workstreams fetch success`,{agentRunId:r,runningCount:e.running?.length??0,completedCount:e.completed?.length??0,unavailable:e.unavailable===!0}),rn(e.running??[]),on(e.completed??[]),e.unavailable){cn(!0);return}fn.current=!1}catch(e){if(t)return;rn(e=>e.length===0?e:[]),cn(!0),KH(`active workstreams fetch failed`,{agentRunId:r,error:e instanceof Error?e.message:String(e)}),fn.current||=(console.warn(`Failed to fetch active workstreams:`,e),!0)}finally{n=!1}};i();let a=window.setInterval(i,1e4);return()=>{t=!0,window.clearInterval(a)}},[Ye.agents,r,$n,et,Cn,sn]),H(()=>{if(Ze.length!==0){if(wn){be?.(!0);return}if(!ft){be?.(!1);return}if(Sn&&Sn!==`RUNNING`){be?.(!1);return}Sn!==null&&be?.(!0)}},[ft,Sn,Ze.length,be,wn]);let Or=V(async()=>{let e=_n.current;e&&await e},[]),kr=V((e,t)=>{let n=e.trim();if(!n||vn.current||On.current&&!kn.current)return;if(yn.current){Xe({status:`warning`,title:Je(`agent.filesProcessing`),description:Je(`agent.waitForFilesProcessing`),duration:3e3});return}let i=RU(t);Ft(!0);let a=F?.()||[],o=ee?.()||{},s=n;a.length>0&&!/store:\S+/.test(n)&&(s=[n,``,`Attachments:`,...a.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
1383
- `));let c=Array.from(bn.current.values()).filter(e=>e.status===mn.READY).map(e=>{let t=e.reference?.startsWith(`artifact:`)?e.reference:e.artifact_path?`artifact:${e.artifact_path}`:void 0;return t?`[${e.name}](${t})`:void 0}).filter(e=>!!e);c.length>0&&(s=[s,``,`Uploaded artifacts:`,...c].join(`
1384
- `));let l=`msg-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,u={timestamp:Date.now(),workflow_run_id:r,type:J.QUESTION,message:s,workstream_id:`main`,details:{_optimistic:!0,_messageId:l,_deliveryStatus:`sending`,...t?.editing_action?{editing_action:t.editing_action}:{},...t?.request_input_response?{request_input_response:t.request_input_response}:{}}};rt(u);let d={...a.length>0?{attached_docs:a.map(e=>e.id)}:{},...o,...t,id:l,_messageId:l},f=()=>Ye.agents.sendSignal(r,`UserInput`,{message:s,client_message_id:l,metadata:d}),p=()=>{it(l,`received`),I?.(),Ot()};i&&AU(r,i),(async()=>{await Or(),On.current&&(await Ye.agents.restart(r),at()),await f(),p()})().catch(e=>{i&&jU(r,i),it(l,`failed`),Xe({status:`error`,title:Je(`agent.failedToSend`),description:e instanceof Error?e.message:Je(`agent.unknownError`),duration:3e3})}).finally(()=>{Ft(!1)})},[r,Ye,Xe,F,ee,I,Ot,at,rt,it,Je,Or]);H(()=>(de&&(de.current=kr),()=>{de?.current===kr&&(de.current=null)}),[kr,de]);let Ar=V(async(e,t)=>{try{await Ye.agents.sendSignal(r,`McpConfigChanged`,{})}catch(e){console.error(`Failed to signal MCP config change`,e)}kr(Je(`agent.mcpConnectedMessage`,{name:e.name}),t)},[Ye,r,kr,Je]),[jr,Mr]=G(void 0);H(()=>{let e=!1,t=gn.current;return Ye.agents.retrieve(r).then(n=>{e||(Mr(n.disabled_mcp_collections),gn.current===t&&(n.tool_approval_mode!==void 0||n.interactive!==void 0)&&dn(An(n.tool_approval_mode,n.interactive)))}).catch(()=>{}),()=>{e=!0}},[Ye,r]);let Nr=V(e=>{let t=e.length>0?e:void 0;Mr(t),Ye.agents.sendSignal(r,`McpConfigChanged`,{disabled_mcp_collections:e}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ye,r]),Pr=V(()=>{Ye.agents.sendSignal(r,`McpConfigChanged`,{}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ye,r]),Fr=V(e=>{let t=An(e,a),n=un;gn.current+=1,dn(t);let i=Ye.agents.sendSignal(r,`ToolApprovalModeChanged`,{mode:t}).then(()=>void 0).catch(e=>{dn(e=>e===t?n:e),Xe({status:`error`,title:Je(`agent.approvalMode.changeFailed`),description:e instanceof Error?e.message:Je(`agent.unknownError`),duration:3e3})});_n.current=i,i.finally(()=>{_n.current===i&&(_n.current=null)})},[r,Ye,a,Je,Xe,un]),Ir=V(e=>{kt&&(e.preventDefault(),e.stopPropagation(),pn.current++,e.dataTransfer?.types?.includes(`Files`)&&Kt(!0))},[kt]),Lr=V(e=>{kt&&(e.preventDefault(),e.stopPropagation())},[kt]),Rr=V(e=>{kt&&(e.preventDefault(),e.stopPropagation(),pn.current--,pn.current===0&&Kt(!1))},[kt]),zr=V(e=>{if(kt&&(e.preventDefault(),e.stopPropagation(),pn.current=0,Kt(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);Et(t)}},[Et,kt]),Br=V(async()=>{if(Ht)return;let e=`stop-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,t={timestamp:Date.now(),workflow_run_id:r,type:J.IDLE,message:`Stopped. Waiting for your command...`,workstream_id:`main`,details:{_optimistic:!0,_messageId:e,_deliveryStatus:`sending`,display_role:`user_stopped`,status_reason:`user_stopped`}};rt(t),Wt(!0);try{await Ye.agents.sendSignal(r,`Stop`,{message:`User requested stop`,client_message_id:e,metadata:{id:e,_messageId:e}}),it(e,`received`)}catch(t){Xe({status:`error`,title:Je(`agent.failedToInterrupt`),description:t instanceof Error?t.message:Je(`agent.unknownError`),duration:3e3}),it(e,`failed`)}finally{Wt(!1)}},[Ht,r,rt,Ye.agents,Xe,Je,it]),Vr=V(async()=>{if(!(It||$n||!Wn)){Lt(!0);try{await Ye.agents.sendSignal(r,`TriggerCheckpoint`,{reason:`manual user request`})}catch(e){Xe({status:`error`,title:Je(`agent.failedToCompactContext`),description:e instanceof Error?e.message:Je(`agent.unknownError`),duration:3e3})}finally{Lt(!1)}}},[r,Ye.agents,$n,It,Wn,Je,Xe]);H(()=>(xe&&(xe.current=h&&!$n?Br:null),()=>{xe&&(xe.current=null)}),[xe,$n,Br,h]),H(()=>{Se?.(Ht)},[Ht,Se]);let Hr=i||Je(`agent.agentConversation`),Ur=async()=>{try{let e=await rU(Ye,r);e&&window.open(e,`_blank`)}catch(e){console.error(`Failed to download conversation`,e),Xe({status:`error`,title:Je(`agent.failedToDownload`),duration:3e3})}},Wr=V(()=>{let e=new Date().toISOString(),t=Qe.size>0?[{cursor:`live`,streamingMessages:Array.from(Qe,([e,t])=>({id:e,...t}))}]:void 0,n={metadata:{title:Hr,agent_run_id:r,exported_at:e,message_count:Ze.length},messages:Ze,...t?{streamingFrames:t}:{}};D1(`${E1(Hr)||`agent-chat`}-${E1(r)}.json`,n),Xe({status:`success`,title:Je(`agent.rewind.fixtureExported`),duration:2e3})},[Hr,r,Ze,Qe,Je,Xe]),[Gr,Kr]=G(!1),qr=()=>{if(!Mt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}Kr(!0)},Jr=()=>{if(!Mt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}let e=`${Hr} - ${r}`;if(!w1(Mt.current,e)){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.unableToOpenPrint`),duration:4e3});return}Xe({status:`success`,title:Je(`agent.pdfExportReady`),description:Je(`agent.printDialogDescription`),duration:4e3}),Kr(!1)},Yr=U(()=>Ze.filter(e=>e.type===J.COMPLETE||e.type===J.THOUGHT&&e.details?.tool_status===`completed`).length,[Ze]),Xr=U(()=>{if(!pr)return{key:Yr,details:void 0};let e=0,t;for(let n of Ze){let r=n.details;Ut(r,pr)&&(e++,t=r)}return{key:e,details:t}},[Yr,Ze,pr]),Zr=a&&Wn&&Sn?.toUpperCase()===`RUNNING`,Qr=U(()=>jn.plan.plan?.reduce((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e),new Map),[jn.plan]),$r=e=>t(eZ,{title:Hr,variant:e,isCompleted:$n,isTerminal:Cn,onClose:s,isModal:c,agentRunId:r,workflowRunId:ot||``,viewMode:Bt,onViewModeChange:Vt,showPlanPanel:br,hasPlan:A&&ct.length>0,showPlanButton:A&&!Be,onTogglePlanPanel:Sr,showPlaybackButton:Rn,isPlaybackEnabled:zn,onTogglePlayback:cr,onDownload:Ur,onExportFixture:Wr,resetWorkflow:d,onClone:p,onShowDetails:m,allowWorkflowControl:h,onExportPdf:qr,isReceivingChunks:tt}),ei=n(`div`,{ref:Mt,"data-agent-playback-enabled":zn||void 0,"data-agent-playback-cursor":zn?Un:void 0,"data-agent-live-message-count":Ze.length,"data-agent-rendered-message-count":qn.length,className:z(`flex flex-col min-h-0 min-w-0 border-0`,Be?`flex-1 h-full`:br?`w-full flex-1 min-h-[50vh]`:l?`flex-1 w-full`:`flex-1 mx-auto ${c?``:`max-w-4xl`}`),children:[!w&&T===`compact`&&t(`div`,{className:`flex flex-shrink-0 justify-end border-b border-border/60 px-2 py-1 lg:hidden`,children:$r(`compact`)}),!w&&T!==`compact`&&t(`div`,{className:`flex-shrink-0`,children:$r(T)}),zn&&t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(SC,{cursor:Un,messages:Vn,onChangeCursor:lr})}),Ze.length===0&&!$n&&Ve&&He?t(C1,{message:Ve,startedAt:He}):t(TJ,{messages:qn,workstreamSourceMessages:Jn,bottomRef:jt,isCompleted:er,plan:jn.plan,workstreamStatus:jn.workstreamStatus,showPlanPanel:A&&pt,onTogglePlanPanel:Sr,plans:ct,activePlanIndex:lt,onChangePlan:ur,taskLabels:Qr,streamingMessages:Yn,onSendMessage:Wn?kr:void 0,onOpenArtifact:M?wr:void 0,messageItemClassNames:Ce,messageStyleOverrides:we,toolCallGroupClassNames:Te,hideToolCallsInViewMode:Ee,streamingMessageClassNames:De,batchProgressPanelClassNames:Oe,artifactRunId:r,viewMode:Bt,hideWorkstreamTabs:k,workingIndicatorClassName:ke,messageListClassName:Ae,StoreLinkComponent:Dr,CollectionLinkComponent:Me,prependFriendlyMessage:Ne,initialRequestData:Pe,initialRequestSchema:Fe,initialRequestTitle:Ie,initialRequestTemplate:Le,showInitialRequest:et===`empty`&&Ze.length===0,hiddenMessageTypes:P,disableAutoScroll:!Wn,renderRequestInputControls:!rr,activeWorkstream:qt,onActiveWorkstreamChange:Jt}),rr?t(tW,{message:nr,onSendMessage:Wn?kr:void 0,onMcpConnected:Wn?Ar:void 0,disabled:L||!Wn,isLoading:Pt||L}):ir&&Qn.length>0?t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:t(KX,{activeWorkstreams:Qn,onSelectWorkstream:Jt})}):ar&&t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:En?D??t(oe,{status:`error`,title:Je(`agent.failed`),className:`m-2`,children:Dn??Je(`agent.error`)}):Sn&&Sn!==`RUNNING`&&!wn?Bt===`sliding`&&Sn===`COMPLETED`?t(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-3 text-sm text-muted`,children:n(`div`,{className:`flex items-center gap-2 border-t border-success/25 pt-3 text-success`,children:[t(Ph,{className:`size-4`}),t(`span`,{className:`font-medium`,children:`Workflow completed`})]})}):n(oe,{status:Sn===`COMPLETED`?`success`:`done`,icon:null,className:`m-2`,children:[`This Workflow is `,Sn]}):(ft||wn)&&n(e,{children:[re,t(X$,{onSend:kr,onStop:h?Br:void 0,approvalModeSlot:a&&un?t(Xb,{mode:un,onChange:Fr,disabled:!Wn||Cn||!h}):void 0,mcpSlot:t(HJ,{disabledCollections:jr,onChange:Nr,onConnectionChange:Pr}),disabled:L||!Wn,isSending:Pt||L,isStopping:Ht,isStreaming:!$n,isCompleted:$n,contextWindowUsage:sr?or:void 0,onCompactContext:sr?Vr:void 0,isCompactingContext:It,activeTaskCount:Fn,activeWorkstreams:Pn,onSelectWorkstream:Jt,placeholder:Ln,onFilesSelected:kt?Et:void 0,uploadedFiles:g,onRemoveFile:_,onRemoveProcessingFile:At,acceptedFileTypes:v,maxFiles:y,processingFiles:wt,artifactRunId:r,hasProcessingFiles:Tt,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideFileUpload:!kt,disableDropZone:kt,className:te,inputClassName:ne})]})})]}),ti=t(VS,{children:t(EW,{children:n(`div`,{ref:Nt,className:z(`flex flex-col lg:flex-row gap-2 w-full h-full relative overflow-hidden`,kt&&Gt&&`ring-2 ring-blue-400 ring-inset`,R),onDragEnter:kt?Ir:void 0,onDragOver:kt?Lr:void 0,onDragLeave:kt?Rr:void 0,onDrop:kt?zr:void 0,children:[kt&&Gt&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2 text-lg`,children:[t(Tb,{className:`size-6`}),`Drop files to upload`]})}),!Be&&ei,!Be&&T===`compact`&&!w&&t(`div`,{className:`hidden h-full w-12 shrink-0 items-start justify-center px-1 pt-2 lg:flex`,children:$r(`compact`)}),br&&n(e,{children:[!Be&&t(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize right panel`,"aria-valuenow":Math.round(mr),"aria-valuemin":300,"aria-valuetext":`${Math.round(mr)} pixels`,tabIndex:0,className:`hidden lg:block lg:w-1 lg:shrink-0 cursor-col-resize bg-border/70 hover:bg-border transition-colors`,onMouseDown:()=>_r(!0),onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=e.shiftKey?32:16,n=e.key===`ArrowLeft`?t:-t,r=Nt.current,i=r?Math.max(300,r.getBoundingClientRect().width-420):900;hr(e=>Math.min(Math.max(e+n,300),i))}}),t(`div`,{className:Be?`w-full h-full overflow-auto`:`w-full lg:w-[var(--agent-right-panel-width)] lg:shrink-0 min-h-[50vh] lg:h-full border-t lg:border-t-0`,style:Be?void 0:{"--agent-right-panel-width":`${mr}px`},children:t(wX,{plan:jn.plan,workstreamStatus:jn.workstreamStatus,plans:ct,activePlanIndex:lt,onChangePlan:ur,showPlan:!O&&pt,activeWorkstreams:Nn,hideWorkstreams:k,openDocuments:ht,activeDocumentId:gt,onSelectDocument:xt,onCloseDocument:bt,onUpdateDocumentTitle:Ct,docRefreshKey:vt,runId:r,processingFiles:he??wt,showArtifacts:M,artifactRefreshKey:Xr.key,artifactRefreshDetails:Xr.details,selectedArtifactPath:pr,onSelectedArtifactPathChange:Y,onSendMessage:Zr?kr:void 0,messages:Ze,payloadContent:Re,conversationContent:Be?ei:ze,onClose:Cr,defaultTab:dr,activeTab:dr,onTabChange:fr})})]}),n(se,{isOpen:Gr,onClose:()=>Kr(!1),children:[t(ue,{children:`Export conversation as PDF`}),n(ce,{children:[t(`p`,{className:`mb-2`,children:`This will open your browser's print dialog with the current conversation.`}),t(`p`,{className:`text-sm text-muted`,children:`To save a PDF, choose "Save as PDF" or a similar option in the print dialog.`})]}),n(le,{align:`right`,children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>Kr(!1),children:`Cancel`}),t(o,{size:`sm`,onClick:Jr,children:`Open print dialog`})]})]})]})})});return ie?t(Xn,{data:ie,sendMessage:kr,ChartComponent:sC,artifactRunId:r,children:ti}):ti}function M1({messages:e}){let n=ot.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]);return t(`div`,{className:`flex flex-col overflow-y-auto space-y-6 py-4`,children:n.map(e=>t(_G,{message:e,showPulsatingCircle:!1},`${e.workstream_id??`main`}-${e.timestamp}-${e.type}`))})}function N1({messages:e,bottomRef:n,className:r,messagesClassName:i,emptyClassName:a}){let o=ot.useRef(null);H(()=>{n.current&&n.current.scrollIntoView({behavior:`smooth`})},[e,n]);let s=ot.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]);return t(`div`,{ref:o,className:`flex-1 min-h-0 h-full overflow-y-auto py-4 px-4 sm:px-6 lg:px-8 bg-white flex flex-col ${r||``}`,"data-testid":`messages-container`,children:s.length===0?t(`div`,{className:`flex items-center justify-center h-full text-center py-8 ${a||``}`,children:t(`div`,{className:`flex items-center px-4 py-3 text-gray-500`,children:`Waiting for agent response...`})}):t(`div`,{className:`flex-1 flex flex-col justify-start h-full min-h-0 ${i||``}`,children:t(M1,{messages:s,isCompleted:!1})})})}function P1(e){return e.name}function F1({isClearable:e=!1,onChange:n,ignoreVirtuals:r=!1,selectedEnvId:i,disabled:a=!1}){let{t:o}=K(),{client:s}=q(),[c,l]=G(),{data:u,isLoading:d}=Xe(()=>s.environments.list().then(e=>(r?e.filter(e=>!e.provider.startsWith(`virtual_`)):e).slice().sort((e,t)=>e.name.localeCompare(t.name))));return H(()=>{l(u?.find(e=>e.id===i))},[u,i]),t(we,{isClearable:e,optionLabel:P1,options:u??[],value:c,onChange:e=>{l(e),n(e)},placeholder:o(`intakePolicy.placeholder.environment`),filterBy:`name`,disabled:a,isLoading:d})}function I1(e){return e.name}function L1(e){return e?.length?n=>{let r=e.some(e=>e.id===n.id);return t(`span`,{className:r?`opacity-50`:``,children:n.name})}:I1}function R1({envId:e,isClearable:n,onChange:r,selectedModelId:i,disabled:a=!1,greyedModels:o,onModelsLoaded:s}){let{t:c}=K(),{client:l}=q(),[u,d]=G(),{data:f,isLoading:p}=Ye(async()=>{if(!e)return[];try{return[...(await l.environments.retrieve(e)).enabled_models??[]].sort((e,t)=>e.name.localeCompare(t.name))}catch{return[]}},[e]);return H(()=>{if(!i){d(void 0);return}let e=f?.find(e=>e.id===i);d(e??{id:i,name:i,provider:`unknown`})},[f,i]),H(()=>{f&&s?.(f)},[f,s]),t(we,{isClearable:n,by:`id`,optionLabel:L1(o),options:f??[],value:u,onChange:e=>{d(e),r(e)},placeholder:c(`intakePolicy.placeholder.model`),disabled:a,isLoading:p})}function z1({env:e,isClearable:n,onChange:r}){let{t:i}=K(),{client:a}=q(),[o,s]=G(),{data:c,isLoading:l}=Ye(async()=>{if(!e)return[];try{return a.environments.listTrainableModels(e.id)}catch{return[]}},[e?.id]);return t(we,{isClearable:n,by:`id`,optionLabel:I1,options:c??[],value:o,onChange:e=>{s(e),r(e)},placeholder:i(`intakePolicy.placeholder.model`),disabled:!e,isLoading:l})}function B1({children:e,fallback:n}){return V1?t(V1,{fallback:n,children:e}):t(ir,{FallbackComponent:n,children:e})}let V1=null;function H1(e){V1=e}function U1({children:e}){return t(B1,{fallback:W1,children:e})}function W1({error:e}){let{t:r}=K(),i=e instanceof Error?e.message:void 0;return n(oe,{status:`error`,title:r(`errors.somethingWentWrong`),children:[n(`div`,{className:`mb-4`,children:[r(`errors.teamNotifiedLine1`),` `,r(`errors.teamNotifiedLine2`),`\xA0`,t(`a`,{className:`text-info`,href:`mailto:support@vertesiahq.com`,children:`support@vertesiahq.com`}),`.`]}),i&&t(`code`,{className:`w-full mt-4 text-sm text-muted break-words`,children:i})]})}function G1({children:e}){return t(B1,{fallback:K1,children:e})}function K1({error:e}){let r=e instanceof Error?e.message:void 0;return t(`tr`,{children:n(`td`,{colSpan:100,children:[t(`span`,{className:`text-xs`,children:` Cannot display row`}),t(`br`,{}),t(`span`,{className:`bg-gray-400`,children:r})]})})}function q1({children:e}){return t(B1,{fallback:J1,children:e})}function J1({error:e}){let r=e instanceof Error?e.message:void 0;return console.log(`WidgetError`,e),n(`div`,{className:`text-sm`,children:[`Sorry, this area cannot be loaded or rendered.`,r&&t(`pre`,{children:r})]})}Q();const Y1=/^[a-f0-9]{24}$|^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9_-]{8,}$/i;function X1(e){return Y1.test(e)}function Z1({className:e,children:r,title:i,description:o,actions:s,breadcrumbs:c,useDynamicBreadcrumbs:l=!0,parentPath:u,parentLabel:d}){let f=$n();function p(e){return e.replace(/[-_]/g,` `).split(` `).map(e=>Jn(e)).join(` `)}let m=e=>{if(e?.title)return e.title;let t=e?.href||``;if(!t)return`Page`;let n=t.split(`#`)[0].split(`?`)[0].split(`/`).filter(e=>e.length>0);return n.length>=1?p(n[n.length-1]):`Page`},h=(()=>{let e=[];if(l&&typeof window<`u`){let t=window.history.state?.historyChain;if(Array.isArray(t))t.forEach((n,r)=>{let i=t.length-r;e.push({label:m(n),href:n.href,onClick:()=>f(n.href,{stepsBack:i})})});else if(u)e.push({label:d??m({href:u}),href:u,onClick:()=>f(u,{isBasePathNested:!1,replace:!0})});else{let t=window.location.pathname.split(`/`).filter(e=>e.length>0);for(let n=0;n<t.length;n++)if(X1(t[n])){let r=`/${t.slice(0,n).join(`/`)}`;e.push({label:p(t[n-1]||r),href:r,onClick:()=>f(r,{isBasePathNested:!1})})}}}return c&&c.length>0&&c.forEach(t=>{let n=t.props?.children||t,r=t.props?.href;e.push(r?{href:r,label:n,onClick:()=>f(r,{replace:t.props.clearBreadcrumbs})}:{label:n})}),e})();return n(`div`,{className:it(`pb-0 ps-4 pe-2 py-2 flex flex-col`,e),children:[n(`div`,{className:`flex items-start gap-4`,children:[n(`div`,{className:`w-full flex place-content-between h-auto min-h-8 flex-col items-start justify-center`,children:[n(`nav`,{className:`flex-1 flex justify-start text-sm`,children:[h.length>0&&t(a,{path:h,separator:t(uh,{className:`size-3.5 cn-rtl-flip`}),maxItems:4}),o&&t(We,{description:o,children:t(j_,{className:`size-4 text-muted ms-4`})})]}),i&&t(`div`,{className:`flex gap-2 items-center`,children:t(`h1`,{className:`text-xl font-semibold break-all`,children:i})})]}),t(`div`,{className:`flex gap-x-2 shrink-0 items-center`,children:s})]}),r&&t(`div`,{className:`w-full flex items-center`,children:r})]})}function Q1(){let{t:e}=K();return n(`div`,{className:`text-center pt-32`,children:[t(`h1`,{className:`text-3xl font-bold text-red-500`,children:`404`}),t(`p`,{className:`text-2xl`,children:e(`layout.pageNotFound`)})]})}Q();const $1=`magic-pdf`;function e0(e){return e.replace(/^\$\.?/,``).replace(/^data\./,``)}function t0(e){let{client:t}=q(),[n,r]=G(!1);return H(()=>{let n=!1;return r(!1),t.files.getDownloadUrl(`${$1}/${e}/grounded-extraction.json`).then(e=>fetch(e.url,{method:`HEAD`})).then(e=>{n||r(e.ok)}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function n0(e){let{client:t}=q(),[n,r]=G(null);return H(()=>{let n=!1;return r(null),t.files.getDownloadUrl(`${$1}/${e}/grounded-extraction.json`).then(e=>fetch(e.url)).then(e=>e.ok?e.json():null).then(e=>{n||!e?.citations||r({confidence:e.confidence,verified:e.citations.filter(e=>e.verified).length,total:e.citations.length,verdict:e.verdict,verdict_reason:e.verdict_reason})}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function r0({objectId:e,onClose:r}){let{t:i}=K(),{client:a}=q(),{data:s,error:c,isLoading:l}=Ye(async()=>{let t=await a.files.getDownloadUrl(`${$1}/${e}/grounded-extraction.json`),n=await fetch(t.url);if(!n.ok)throw Error(i(`grounded.notFound`));return n.json()},[e]);return c?t(`div`,{className:`flex h-full items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`grounded.failedToLoad`),children:Ge(c)}),r&&t(o,{variant:`outline`,onClick:r,children:i(`pdf.close`)})]})}):l||!s?t(`div`,{className:`flex h-full items-center justify-center`,children:t(je,{size:`lg`})}):t(`div`,{className:`relative h-full`,children:t(a0,{extraction:s,objectId:e,onClose:r})})}function i0({objectId:e,onClose:n}){return t(`div`,{className:`fixed inset-0 bg-background z-50`,children:t(r0,{objectId:e,onClose:n})})}function a0({extraction:r,objectId:a,onClose:s}){let{t:c}=K(),{client:l}=q(),u=U(()=>Object.keys(r.pages).map(e=>parseInt(e,10)).sort((e,t)=>e-t),[r.pages]),d=e=>{l.files.getDownloadUrl(`${$1}/${a}/${e}`).then(e=>window.open(e.url,`_blank`)).catch(()=>{})},[f,p]=G(u[0]??1),[m,h]=G(void 0),[g,_]=G(!1),[v,y]=G(`original`),b=U(()=>{let e={digital:0,ocr:0,reviewerConfirmed:0,snapped:0,imageRead:0},t=[];for(let n of r.citations)n.verified?n.snapped?e.snapped++:(n.confidence??0)>=1?e.digital++:e.ocr++:n.reviewed?e.reviewerConfirmed++:(e.imageRead++,t.push(n));let n=e.digital+e.ocr+e.snapped,i=e.reviewerConfirmed;return{groups:e,unverified:t,digitallyVerified:n,modelVerified:i,totalVerified:n+i}},[r.citations]),x=U(()=>{let e=new Map;for(let t of r.citations){let n=e0(t.path),r=e.get(n)??[];r.push(t),e.set(n,r)}return e},[r.citations]),S=r.citations.length,C=b.totalVerified===S,T=e=>{h(e);let t=x.get(e0(e))?.[0];t&&p(t.page)},E=u.indexOf(f),D=m?x.get(e0(m))?.find(e=>e.page===f):void 0,O=D?.cells?D.cells.start===D.cells.end?D.cells.start:`${D.cells.start}:${D.cells.end}`:void 0;return n(Ce,{direction:`horizontal`,className:`absolute inset-0`,children:[n(Se,{defaultSize:55,minSize:25,className:`flex flex-col bg-muted`,children:[n(`div`,{className:`relative flex h-9 shrink-0 items-center justify-center bg-sidebar px-2 border-b border-sidebar-border`,children:[O&&t(i,{variant:`secondary`,className:`absolute start-2 max-w-32 truncate font-mono text-[11px]`,title:O,children:O}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`grounded.previousPage`),disabled:E<=0,onClick:()=>p(u[E-1]),children:t(sh,{className:`size-4`})}),t(`span`,{className:`text-xs text-muted`,children:c(`pdf.pageOf`,{pageNumber:f,totalPages:u.length})}),t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`grounded.nextPage`),disabled:E>=u.length-1,onClick:()=>p(u[E+1]),children:t(uh,{className:`size-4`})})]}),n(`fieldset`,{className:`absolute end-2 flex items-center gap-0.5 rounded border-0 bg-muted p-0.5`,children:[t(`legend`,{className:`sr-only`,children:c(`grounded.checkerboard`)}),t(We,{description:c(`pdf.originalImages`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:v===`original`?`outline`:`ghost`,size:`xs`,"aria-label":c(`pdf.originalImages`),"aria-pressed":v===`original`,className:`h-6 gap-1 px-1.5`,onClick:()=>y(`original`),children:[t(O_,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:c(`pdf.page`)})]})}),t(We,{description:c(`grounded.checkerboard`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:v===`grid`?`outline`:`ghost`,size:`xs`,"aria-label":c(`grounded.checkerboard`),"aria-pressed":v===`grid`,className:`h-6 gap-1 px-1.5`,onClick:()=>y(`grid`),children:[t(S_,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:c(`grounded.checkerboard`)})]})})]})]}),t(`div`,{className:`flex-1 overflow-auto p-2`,children:t(o0,{objectId:a,page:f,dims:r.pages[String(f)],citations:r.citations.filter(e=>e.page===f),selectedPath:m,onSelectPath:h,imageMode:v})})]}),t(xe,{className:`w-[4px] bg-border cursor-ew-resize`}),n(Se,{defaultSize:45,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`span`,{className:`text-sm font-medium`,children:c(`grounded.title`)}),n(`div`,{className:`flex items-center gap-2`,children:[S>0&&t(We,{description:c(`grounded.confidenceHint`),placement:`bottom`,size:`xs`,asChild:!0,children:n(i,{variant:C?`success`:`attention`,className:`gap-1 text-nowrap cursor-pointer`,onClick:()=>_(e=>!e),"aria-expanded":g,children:[t(C?Lh:jg,{className:`size-3.5`}),c(`grounded.verifiedOf`,{verified:b.totalVerified,total:S})]})}),n(w,{align:`right`,trigger:t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`pdf.download`),title:c(`pdf.download`),children:t(Sg,{className:`size-4`})}),children:[n(ae,{className:`text-xs`,onClick:()=>d(`grounded-extraction.json`),children:[t(Pg,{className:`size-4`}),c(`grounded.downloadCitations`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`pages/page-${f}.json`),children:[t(Kg,{className:`size-4`}),c(`grounded.downloadBlocks`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`grounded-annotated.pdf`),children:[t(Lg,{className:`size-4`}),c(`grounded.downloadAnnotated`)]})]}),!!s&&t(o,{variant:`ghost`,size:`xs`,onClick:s,"aria-label":c(`pdf.close`),children:t(Kb,{className:`size-4`})})]})]}),g&&n(`div`,{className:`shrink-0 border-b border-border bg-background px-3 py-2 text-sm max-h-72 overflow-auto`,children:[n(`div`,{className:`mb-1 flex items-center gap-1`,children:[t(`span`,{className:`font-medium`,children:c(`grounded.breakdownTitle`)}),t(We,{description:c(`grounded.breakdownVerificationHelp`),size:`xs`,children:t(j_,{className:`size-3 text-muted`})})]}),n(`div`,{className:`grid grid-cols-2 gap-x-4 text-xs`,children:[t(`span`,{className:`col-span-2 mt-1 font-medium text-success`,children:c(`grounded.digitalVerifiedOf`,{count:b.digitallyVerified,total:S})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownDigital`)}),t(`span`,{className:`text-end text-success`,children:b.groups.digital}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownOcr`)}),t(`span`,{className:`text-end text-success`,children:b.groups.ocr}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownSnapped`)}),t(`span`,{className:`text-end text-success`,children:b.groups.snapped}),t(`span`,{className:`col-span-2 mt-2 font-medium text-success`,children:c(`grounded.modelVerifiedOf`,{count:b.modelVerified,total:S})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownReviewer`)}),t(`span`,{className:`text-end text-success`,children:b.groups.reviewerConfirmed}),b.groups.imageRead>0&&n(e,{children:[t(`span`,{className:`col-span-2 mt-2 font-medium text-attention`,children:c(`grounded.unverifiedCount`,{count:b.groups.imageRead})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownImageRead`)}),t(`span`,{className:`text-end text-attention`,children:b.groups.imageRead})]})]}),typeof r.hardness?.score==`number`&&n(`p`,{className:`mt-2 text-xs text-muted`,title:c(`grounded.hardnessHint`),children:[c(`grounded.hardness`,{percent:Math.round(r.hardness.score*100)}),r.hardness.escalated?` ↑`:``]}),(r.verdict_reason??r.review?.verdict_reason)&&t(`p`,{className:`mt-2 text-xs`,children:r.verdict_reason??r.review?.verdict_reason}),r.review?.summary&&n(`p`,{className:`mt-2 text-xs text-muted`,children:[n(`span`,{className:`font-medium text-foreground`,children:[c(`grounded.reviewSummary`),`: `]}),r.review.summary]}),typeof r.review?.corrections_applied==`number`&&r.review.corrections_applied>0&&t(`p`,{className:`mt-1 text-xs text-info`,children:c(`grounded.reviewCorrections`,{count:r.review.corrections_applied})}),b.unverified.length>0&&n(`div`,{className:`mt-2`,children:[t(`div`,{className:`text-xs font-medium text-muted mb-1`,children:c(`grounded.breakdownUnverifiedList`)}),t(`ul`,{className:`space-y-0.5`,children:b.unverified.map(e=>t(`li`,{children:n(`button`,{type:`button`,className:`w-full text-start text-xs rounded px-1 py-0.5 hover:bg-muted cursor-pointer`,onClick:()=>{T(e.path),_(!1)},children:[t(`span`,{className:`text-muted`,children:e.path}),` `,t(`span`,{children:String(e.value??``)})]})},e.path))})]})]}),n(`div`,{className:`flex-1 overflow-auto p-3`,children:[t(s0,{value:r.data,path:``,citationsByPath:x,selectedPath:m,onSelect:T}),r.conflicts&&r.conflicts.length>0&&t(`div`,{className:`mt-4 text-xs text-attention`,children:c(`grounded.conflicts`,{count:r.conflicts.length})})]})]})]})}function o0({objectId:e,page:r,dims:i,citations:a,selectedPath:o,onSelectPath:s,imageMode:c}){let{t:l}=K(),{client:u}=q(),[d,f]=G(void 0);if(H(()=>{let t=!1;return f(void 0),u.files.getDownloadUrl(`${$1}/${e}/pages/page-${r}.${c}.jpg`).then(e=>{t||f(e.url)}).catch(e=>console.warn(`Failed to load page image`,e)),()=>{t=!0}},[u,c,e,r]),!d||!i)return t(`div`,{className:`flex items-center justify-center h-64`,children:t(je,{})});let p=a.flatMap(e=>e.boxes.map((r,a)=>{let c=o!==void 0&&e0(o)===e0(e.path),l=e.cells?e.cells.start===e.cells.end?e.cells.start:`${e.cells.start}:${e.cells.end}`:void 0;return t(We,{description:n(`span`,{className:`flex flex-col gap-0.5`,children:[t(`span`,{className:`flex items-center gap-1 font-medium`,children:u0(e.path).map((e,r)=>n(lt,{children:[r>0&&t(uh,{className:`size-3 shrink-0 cn-rtl-flip`}),e]},`${r}:${e}`))}),l&&t(`span`,{className:`font-mono`,children:l}),e.source_text&&t(`span`,{children:e.source_text})]}),size:`xs`,asChild:!0,children:t(`button`,{type:`button`,"aria-label":e.path,onClick:()=>s(e0(e.path)),className:z(`absolute cursor-pointer border rounded-[1px] transition-colors`,e.misaligned&&`border-dashed`,c?`border-2 border-primary bg-primary/20 z-10`:e.verified?`border-success/70 hover:bg-success/20`:e.reviewed?`border-info/70 hover:bg-info/20`:`border-attention/80 hover:bg-attention/20`),style:{position:`absolute`,left:`${r.x/i.width*100}%`,top:`${r.y/i.height*100}%`,width:`${r.w/i.width*100}%`,height:`${r.h/i.height*100}%`}})},`${e.path}-${a}`)})),m=((i.rotation??0)%360+360)%360;if(m!==0){let e=m===90||m===270;return n(`div`,{className:`relative w-full`,style:{aspectRatio:`${i.width} / ${i.height}`},children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`absolute select-none`,style:{left:`50%`,top:`50%`,width:`${(e?i.height/i.width:1)*100}%`,height:`${(e?i.width/i.height:1)*100}%`,maxWidth:`none`,transform:`translate(-50%, -50%) rotate(${m}deg)`,transformOrigin:`center center`}}),p]})}return n(`div`,{className:`relative w-full`,children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`w-full select-none`}),p]})}function s0({value:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){return Array.isArray(e)?e.length>0&&e.every(e=>typeof e==`object`&&!!e)?t(c0,{items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}):t(`div`,{className:`space-y-1`,children:e.map((e,n)=>t(s0,{value:e,path:`${r}[${n}]`,citationsByPath:i,selectedPath:a,onSelect:o},`${r}[${n}]`))}):typeof e==`object`&&e?t(`div`,{className:r?`ps-3 border-s border-border space-y-0.5`:`space-y-0.5`,children:Object.entries(e).map(([e,s])=>{let c=r?`${r}.${e}`:e;if(typeof s!=`object`||!s)return t(l0,{label:e,value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o},c);let l=Array.isArray(s)&&s.length>0&&s.every(e=>typeof e==`object`&&!!e);return n(`div`,{className:`pt-1`,children:[!l&&t(`div`,{className:`text-sm font-semibold`,children:d0(e)}),t(s0,{value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o})]},c)})}):null}function c0({items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){let{t:s}=K(),c=U(()=>{let t=new Set;for(let n of e)for(let e of Object.keys(n))t.add(e);return Array.from(t)},[e]);return n(`div`,{className:`pt-1`,children:[n(`div`,{className:`text-sm font-semibold`,children:[d0(r.split(`.`).pop()),` (`,e.length,`)`]}),t(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs`,children:[t(`thead`,{children:t(`tr`,{className:`text-start text-muted`,children:c.map(e=>t(`th`,{scope:`col`,className:`py-1 pe-2 font-medium`,children:d0(e)},e))})}),t(`tbody`,{children:e.map((e,l)=>t(`tr`,{className:`border-t border-border/50`,children:c.map(c=>{let u=`${r}[${l}].${c}`,d=i.get(u)?.[0];return t(`td`,{className:`py-0.5 pe-2`,children:n(`button`,{type:`button`,onClick:()=>o(u),className:z(`text-start rounded px-1 w-full`,a===u?`bg-primary/15 ring-1 ring-primary`:d?`hover:bg-muted cursor-pointer`:`text-muted cursor-default`),children:[m0(e[c]),d&&typeof d.confidence==`number`&&t(`span`,{className:z(`ms-1 text-[10px]`,p0(d.confidence)),title:s(`grounded.scoreHint`),children:f0(d.confidence)})]})},c)})},`${r}[${l}]`))})]})})]})}function l0({label:e,value:r,path:i,citationsByPath:a,selectedPath:o,onSelect:s}){let{t:c}=K(),l=a.get(i)?.[0];return n(`button`,{type:`button`,onClick:()=>l&&s(i),className:z(`flex items-center gap-2 w-full text-start text-sm rounded px-1.5 py-0.5`,o===i?`bg-primary/15 ring-1 ring-primary`:l?`hover:bg-muted`:``,!l&&`cursor-default`),children:[n(`span`,{className:`min-w-28 shrink-0 font-semibold`,children:[d0(e),`:`]}),t(`span`,{className:`flex-1 wrap-break-word`,children:m0(r)}),l&&typeof l.confidence==`number`&&t(`span`,{className:z(`text-xs shrink-0`,p0(l.confidence)),title:c(`grounded.scoreHint`),children:f0(l.confidence)}),l&&(l.verified?t(Lh,{"aria-label":c(`grounded.verified`),className:`size-3.5 shrink-0 text-success`}):l.reviewed?t(Yy,{"aria-label":c(`grounded.aiVerified`),className:`size-3.5 shrink-0 text-info`}):t(jg,{"aria-label":c(`grounded.readFromImage`),className:`size-3.5 shrink-0 text-attention`}))]})}function u0(e){return e0(e).split(`.`).map(e=>d0(e.replace(/\[\d+\]/g,``))).filter(Boolean)}function d0(e){return e?zt(e):``}function f0(e){let t=e*100;return Number.isInteger(t)?`${t}%`:`${(Math.floor(t*100)/100).toFixed(2)}%`}function p0(e){return e>=.95?`text-success`:e>=.7?`text-attention`:`text-destructive`}function m0(e){return e==null||e===``?`—`:typeof e==`boolean`?e?`true`:`false`:typeof e==`object`?JSON.stringify(e):String(e)}const h0=`magic-pdf`;var g0;(function(e){e.original=`original`,e.instrumented=`instrumented`})(g0||={});var _0=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}getCacheKey(e,t){return`${t}-${e}`}async getPageImageUrl(e,t){let n=this.getCacheKey(e,t),r=this.cache.get(n);if(r)return r;let i=this.pending.get(n);if(i)return i;let a=this.fetchImageUrl(e,t);this.pending.set(n,a);try{let e=await a;return this.cache.set(n,e),e}finally{this.pending.delete(n)}}async fetchImageUrl(e,t){let n=this.getImagePath(e,t);return(await this.client.files.getDownloadUrl(n)).url}getImagePath(e,t){let n=`${h0}/${this.objectId}/pages`;switch(t){case g0.original:return`${n}/page-${e}.original.jpg`;case g0.instrumented:return`${n}/page-${e}.instrumented.jpg`}}},v0=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}async getPageLayout(e){let t=this.cache.get(e);if(t!==void 0)return t;let n=this.pending.get(e);if(n)return n;let r=this.fetchPageLayout(e);this.pending.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pending.delete(e)}}async fetchPageLayout(e){let t=`${h0}/${this.objectId}/pages/page-${e}.layout.json`,n=await this.client.files.getDownloadUrl(t),r=await fetch(n.url,{method:`GET`});if(!r.ok)throw Error(`Failed to fetch json layout: ${r.statusText}`);return r.text()}},y0=class{totalPages;pages=[];constructor(e){this.totalPages=e}initFromContent(e){this.pages=b0(e,this.totalPages)}async loadUrls(e,t){}async getPageMarkdown(e){let t=e-1;return t<0||t>=this.pages.length?``:this.pages[t]}};function b0(e,t){let n=Array(t).fill(``),r=/<!--\s*\{\s*"page"\s*:\s*(\d+)\s*\}\s*-->/g,i=[];for(let t of e.matchAll(r))i.push({page:parseInt(t[1],10),index:t.index+t[0].length});for(let r=0;r<i.length;r++){let a=i[r],o=a.page-1;if(o<0||o>=t)continue;let s=a.index,c=e.slice(s).match(/<!--\s*\{\s*"page"\s*:\s*\d+\s*\}\s*-->/),l=c&&c.index!==void 0?s+c.index:e.length,u=e.slice(s,l).trim();u=u.replace(/\n---\s*$/,``).trim(),n[o]=u}return n}const x0=dt(void 0);function S0({children:e,object:n}){let{client:r}=q(),i=n.metadata.page_count||10,[a,o]=G(()=>{let e=new y0(i);return n.text&&e.initFromContent(n.text),{count:i,layoutProvider:new v0(r,n.id,i),markdownProvider:e,imageProvider:new _0(r,n.id,i),pdfUrl:``,pdfUrlLoading:!0}});return H(()=>{let e=n.metadata?.renditions?.find(e=>e.name===vn),t=n.content?.type===`application/pdf`,i=e?.content?.source||(t?n.content?.source:void 0);i?r.store.objects.getDownloadUrl(i,void 0,`inline`).then(e=>{o(t=>({...t,pdfUrl:e.url,pdfUrlLoading:!1}))}).catch(e=>{console.warn(`Failed to get PDF URL:`,e),o(e=>({...e,pdfUrlLoading:!1}))}):o(e=>({...e,pdfUrlLoading:!1}))},[r,n.metadata,n.content?.type,n.content?.source]),t(x0.Provider,{value:a,children:e})}function C0(e,t,n){return e.files.getDownloadUrl(`${h0}/${t}/${n}`).then(e=>e.url)}function w0(){let e=ot.useContext(x0);if(!e)throw Error(`useMagicPdfContext must be used within a MagicPdfProvider`);return e}Q();function T0({object:e}){let{t:n}=K(),{client:r}=q(),i=t=>{C0(r,e.id,t).then(e=>window.open(e,`_blank`))};return t(o,{variant:`ghost`,size:`xs`,onClick:()=>i(`document.md`),title:n(`pdf.download`),children:t(Sg,{className:`size-4`})})}Q();function E0({className:e}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(tv,{className:`w-6 h-6 animate-spin text-gray-400`})})}function D0({viewType:e,pageNumber:n}){switch(e){case`json`:return t(O0,{pageNumber:n});case`markdown`:return t(k0,{pageNumber:n});default:return t(k0,{pageNumber:n})}}function O0({pageNumber:e}){let[n,r]=G(null),[i,a]=G(!0),[o,s]=G(null),{layoutProvider:c}=w0();return H(()=>{a(!0),s(null),c.getPageLayout(e).then(e=>{r(e?JSON.parse(e):null),a(!1)}).catch(e=>{console.error(e),s(e.message||`Failed to load layout`),a(!1)})},[e,c]),i?t(`div`,{className:`px-4 py-8`,children:t(E0,{})}):o?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:o}):n?t(At,{className:`w-full`,data:n}):null}function k0({pageNumber:e}){let[r,i]=G(null),[a,o]=G(!0),[s,c]=G(null),{markdownProvider:l}=w0();return H(()=>{o(!0),c(null),l.getPageMarkdown(e).then(e=>{i(e),o(!1)}).catch(e=>{console.error(e),c(e.message||`Failed to load markdown`),o(!1)})},[e,l]),a?n(`div`,{className:`h-full flex flex-col items-center justify-center gap-2`,children:[t(E0,{}),t(`span`,{className:`text-sm text-muted-foreground`,children:`Loading...`})]}):s?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:s}):t(`div`,{className:`px-4 py-2 prose prose-sm max-w-none dark:prose-invert`,children:r?t(Nt,{children:r}):t(`div`,{children:`No markdown content available`})})}Q(),yY();var A0=class extends ct{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`PDF View error:`,e,t)}render(){return this.state.hasError?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:Xt.t(`pdf.failedToLoadViewer`,{ns:Yt}),children:this.state.error?.message||`An unexpected error occurred`}),this.props.onClose&&t(o,{variant:`outline`,onClick:this.props.onClose,children:`Close`})]})}):this.props.children}};function j0({objectId:e,onClose:r}){let{t:i}=K(),{client:a}=q(),{data:s,error:c}=Ye(()=>a.store.objects.retrieve(e,`+text`),[e]);return c?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`pdf.fetchingDocumentFailed`),children:Ge(c)}),r&&t(o,{variant:`outline`,onClick:r,children:`Close`})]})}):s?t(A0,{onClose:r,children:t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:t(S0,{object:s,children:t(M0,{object:s,onClose:r})})})}):n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(Kb,{className:`size-4`})})}),t(`div`,{className:`flex-1 flex items-center justify-center`,children:t(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary`})})]})}function M0({object:e,onClose:r}){let{t:i}=K(),{count:a,pdfUrl:s,pdfUrlLoading:c}=w0(),[l,u]=G(1);return n(Ce,{direction:`horizontal`,className:`absolute inset-0`,children:[t(Se,{defaultSize:50,minSize:20,maxSize:80,className:`bg-muted`,children:t(pY,{pdfUrl:s,pdfUrlLoading:c,pageCount:a,className:`h-full`,currentPage:l,onChange:u})}),t(xe,{className:`w-[4px] bg-border cursor-ew-resize`}),n(Se,{defaultSize:50,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`div`,{className:`flex items-center gap-x-2`,children:t(T0,{object:e})}),t(`span`,{className:`text-xs text-muted-foreground`,children:i(`pdf.pageOf`,{pageNumber:l,totalPages:a})}),t(`div`,{className:`flex items-center gap-x-2`,children:!!r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(Kb,{className:`size-4`})})})]}),t(`div`,{className:`flex-1 overflow-auto px-2`,children:t(D0,{pageNumber:l,viewType:`markdown`})})]})]})}const N0=[`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`],P0=[`video/mp4`,`video/webm`],F0=[`audio/mp4`,`audio/m4a`,`audio/x-m4a`,`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/webm`];function I0(e){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`}function L0({url:e,source:r,object:i,className:a}){let{t:o}=K(),{client:s}=q(),[c,l]=G(e),[u,d]=G(!e&&(!!r||!!i)),f=i?.metadata,p=(f?.renditions||[]).find(e=>e.name===ln),m=i?.content?.type&&F0.includes(i.content.type),h=!!i&&i.metadata?.type===dn.Audio&&!p&&!m;return H(()=>{if(e){l(e),d(!1);return}l(void 0),r||i?(d(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==dn.Audio)return;let e;p?.content?.source?e=await s.files.getDownloadUrl(p.content.source):m&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get audio URL`,e)}finally{d(!1)}})()):d(!1)},[e,r,i,p,m,s]),h?t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noAudioRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.audioFormatRequired`)})]})}):u?t(`div`,{className:`flex justify-center items-center h-[200px] ${a??``}`.trim(),children:t(je,{size:`md`})}):c?n(`div`,{className:`flex flex-col items-center gap-4 ${a??``}`.trim(),children:[t(`audio`,{src:c,controls:!0,className:`w-full max-w-2xl`,children:`Your browser does not support the audio tag.`}),f?.duration&&n(`div`,{className:`text-sm text-muted`,children:[`Duration: `,I0(f.duration)]})]}):t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:`Failed to load audio`})}function R0({url:e,source:n,object:r,className:i}){let{client:a}=q(),[o,s]=G(e),[c,l]=G(!e&&(!!n||!!r));return H(()=>{if(e){s(e),l(!1);return}s(void 0),n||r?(l(!0),(async()=>{try{if(n){let e=await a.files.getDownloadUrl(n);s(e.url);return}if(!r||r.metadata?.type!==dn.Image)return;let e=r.content?.type&&N0.includes(r.content.type);try{let e=await a.objects.getRendition(r.id,{format:hn.jpeg,generate_if_missing:!1,sign_url:!0});if(e.status===`found`&&e.renditions?.length){s(e.renditions[0]);return}}catch{}if(e&&r.content?.source){let e=await a.files.getDownloadUrl(r.content.source);s(e.url)}}finally{l(!1)}})()):l(!1)},[e,n,r,a]),c?t(`div`,{className:i,children:t(je,{size:`md`})}):o?t(`img`,{src:o,alt:r?.name,className:`w-full object-contain ${i??``}`.trim()}):null}function z0({url:e,source:r,object:i,className:a}){let{t:o}=K(),{client:s}=q(),[c,l]=G(e),[u,d]=G(),[f,p]=G(!e&&(!!r||!!i)),m=i?.metadata?.renditions||[],h=m.find(e=>e.content.type===`video/mp4`)||m.find(e=>e.content.type===`video/webm`),g=i?.content?.type&&P0.includes(i.content.type),_=m.find(e=>e.name===yn),v=!!i&&i.metadata?.type===dn.Video&&!h&&!g;return H(()=>{if(e){l(e),p(!1);return}l(void 0),d(void 0),r||i?(p(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==dn.Video)return;let e;h?.content?.source?e=await s.files.getDownloadUrl(h.content.source):g&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get video URL`,e)}finally{p(!1)}})()):p(!1)},[e,r,i,h,g,s]),H(()=>{_?.content?.source&&s.files.getDownloadUrl(_.content.source).then(e=>d(e.url)).catch(e=>console.error(`Failed to load poster image`,e))},[_,s]),v?t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noVideoRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.videoFormatRequired`)})]})}):f?t(`div`,{className:`flex justify-center items-center h-[400px] ${a??``}`.trim(),children:t(je,{size:`md`})}):c?t(`video`,{src:c,poster:u,controls:!0,className:`w-full h-full object-contain ${a??``}`.trim(),children:`Your browser does not support the video tag.`}):t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:`Failed to load video`})}Q();function B0({oauthProviderId:r,onAuthChange:i}){let{client:a}=q(),{t:o}=K(),[s,c]=G(null),[l,u]=G(!0),[d,f]=G(!1),[p,m]=G(!1),h=V(async()=>{try{u(!0);let e=await a.oauthProviders.getStatus(r);c(e)}catch(e){console.error(`Failed to load OAuth provider status:`,e)}finally{u(!1)}},[a,r]);H(()=>{h()},[h]);let{openOAuthPopup:g}=mO({onComplete:()=>{f(!1),h(),i?.()},onError:e=>{console.error(`OAuth provider auth failed:`,e),f(!1)}});return l?t(fO,{className:`size-4`}):s?.authenticated?n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1 text-success text-sm`,children:[t(Lh,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.connected`)})]}),t(sT,{variant:`outline`,size:`sm`,onClick:async()=>{if(!p)try{m(!0),await a.oauthProviders.disconnect(r),await h(),i?.()}catch(e){console.error(`Failed to disconnect OAuth provider:`,e)}finally{m(!1)}},disabled:p,children:p?t(fO,{className:`size-3`}):o(`oauthProvider.disconnect`)})]}):t(sT,{variant:`outline`,size:`sm`,onClick:async()=>{if(!d)try{f(!0);let e=await a.oauthProviders.authorize(r);e.authorization_url&&g(e.authorization_url)}catch(e){console.error(`Failed to authorize OAuth provider:`,e),f(!1)}},disabled:d,children:d?n(e,{children:[t(fO,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.authenticating`)})]}):n(e,{children:[t(Og,{className:`size-4 me-1`}),t(`span`,{children:o(`oauthProvider.authenticate`)})]})})}function V0(...e){let t=Array.from(e);return t.__AnyOf__=!0,t}function H0(...e){return Array.from(e)}function U0(e){return e.__AnyOf__===!0}var W0=class{system_roles;roles;permissions;constructor(e,t=[]){this.system_roles=t;let n=[...e.account_roles||[],...e.project_roles||[]],r=new Set(n);this.roles=r;let i=e.permissions??G0(n,t),a=e.type===xn.OAuthAccess?new Set(e.permissions??[]):void 0;this.permissions=new Set(a?i.filter(e=>a.has(e)):i)}hasPermission(e){if(typeof e==`string`)return this.permissions.has(e);if(U0(e))return e.some(e=>this.permissions.has(e));for(let t of e)if(!this.permissions.has(t))return!1;return!0}};function G0(e,t){let n=new Map(t.map(e=>[e.name,e.permissions])),r=new Set;for(let t of e)for(let e of n.get(t)??[])r.add(e);return Array.from(r)}const K0=dt(void 0);function q0(){let e=_t(K0);if(!e)throw Error(`UserPermissionContext cannot be used outside UserPermissionProvider`);return e}function J0({children:e}){let{t:n}=K(),r=q(),i=r.authToken,a=!!(i&&!i.permissions),{data:o,error:s,isLoading:c}=Ye(()=>a?r.client.iam.roles.listSystem():Promise.resolve(void 0),[r.client,i,a]),l=U(()=>{if(i){if(i.permissions||!a)return new W0(i);if(o&&!c)return new W0(i,o)}else return},[i,o,c,a]);return s?t(M,{title:n(`store.failedToFetchRoleMappings`),children:Ge(s)}):l&&t(K0.Provider,{value:l,children:e})}function Y0({permission:e,isDisabled:n,title:r,children:i,...a}){return q0().hasPermission(e)?t(o,{isDisabled:n,title:r,...a,children:i}):null}function X0({permission:e,...n}){return q0().hasPermission(e)?t(or,{...n}):null}const Z0=new WeakMap;function Q0(e,t){let n=Z0.get(e);n||(n=new Map,Z0.set(e,n));let r=n.get(t);return r||(r=e.types.catalog.resolve(t).then(e=>e??void 0,()=>{Z0.get(e)?.delete(t)}),n.set(t,r)),r}function $0(e,t){let n=Z0.get(e);n&&(t?n.delete(t):n.clear())}Q();function e2(e){let t=e.configuration?.defaults?.system?.agent??e.configuration?.defaults?.base;return{environment:t?.environment,model:t?.model}}function t2(e){return e.name}function n2(e){return e.name}function r2(e){return e.split(`/`).filter(Boolean).pop()||e}function i2({value:e,onChange:r,disabled:i=!1,isLoading:a=!1}){let{client:s}=q(),{t:c}=K(),[l,u]=G([]),[d,f]=G([]),[p,m]=G(!0),[h,g]=G(!1),_=W(void 0);H(()=>{let e=!1;return m(!0),s.environments.list().then(t=>{e||u(t.slice().sort((e,t)=>e.name.localeCompare(t.name)))}).catch(t=>{console.warn(`Failed to list document editing environments`,t),e||u([])}).finally(()=>{e||m(!1)}),()=>{e=!0}},[s]),H(()=>{if(!e.environment){f([]),g(!1);return}let t=!1,n=e.environment;return g(!0),s.environments.retrieve(n).then(e=>{t||f((e.enabled_models??[]).map(e=>({id:e.id,name:e.name||e.id})).sort((e,t)=>e.name.localeCompare(t.name)))}).catch(e=>{console.warn(`Failed to load document editing models`,e),t||f([])}).finally(()=>{t||g(!1)}),()=>{t=!0}},[s,e.environment]);let v=l.find(t=>t.id===e.environment),y=U(()=>{if(e.model)return d.find(t=>t.id===e.model)??{id:e.model,name:r2(e.model)}},[d,e.model]),b=e=>{_.current=e.id,r({environment:e.id}),s.environments.retrieve(e.id).then(t=>{if(_.current!==e.id)return;let n=t.default_model??t.enabled_models?.[0]?.id;r({environment:e.id,model:n})}).catch(e=>{console.warn(`Failed to select a default document editing model`,e)})},x=t=>{_.current=void 0,r({environment:e.environment,model:t.id})},S=y?.name||c(`agent.documentEditingSelectModel`);return n(he,{children:[t(_e,{asChild:!0,children:n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 max-w-[15rem] gap-1.5 px-2 text-xs`,"aria-label":c(`agent.documentEditingConfiguration`),title:c(`agent.documentEditingConfiguration`),children:[a?t(je,{size:`sm`}):t(Ky,{className:`size-3.5 shrink-0`}),t(`span`,{className:`min-w-0 truncate`,children:S}),t(ih,{className:`size-3.5 shrink-0 opacity-70`})]})}),n(ge,{align:`end`,className:`z-[1000000] w-80 space-y-3 p-3`,children:[n(`div`,{children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:c(`agent.documentEditingConfiguration`)}),t(`div`,{className:`mt-0.5 text-xs leading-4 text-muted`,children:c(i?`agent.documentEditingConfigurationLocked`:`agent.documentEditingConfigurationDescription`)})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-environment`,children:c(`agent.environment`)}),t(we,{id:`document-editing-environment`,by:`id`,options:l,value:v,optionLabel:t2,filterBy:`name`,placeholder:c(`agent.documentEditingSelectEnvironment`),onChange:b,disabled:i,isLoading:p})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-model`,children:c(`agent.model`)}),t(we,{id:`document-editing-model`,by:`id`,options:d,value:y,optionLabel:n2,filterBy:`name`,placeholder:c(`agent.documentEditingSelectModel`),onChange:x,disabled:i||!e.environment,isLoading:h,warnOnMissingValue:!1})]})]})]})}Q();function a2({isLocked:e,onToggleLock:r}){let{t:i}=K(),a=i(e?`agent.editingLockedTitle`:`agent.editingManuallyUnlockedTitle`),s=i(e?`agent.editingLockedDescription`:`agent.editingManuallyUnlockedDescription`),c=i(e?`agent.unlockEditing`:`agent.lockEditing`);return n(`div`,{className:`flex h-8 max-w-64 shrink-0 items-center gap-1 rounded-md border border-mixer-attention/30 bg-mixer-attention/10 ps-2 pe-1 text-attention`,role:e?`status`:`alert`,"aria-live":`polite`,children:[e?t(iv,{className:`size-3.5 shrink-0 animate-pulse`}):t(sv,{className:`size-3.5 shrink-0`}),t(We,{description:s,asChild:!0,children:t(`span`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,children:a})}),t(`span`,{className:`sr-only`,children:s}),t(We,{description:c,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`size-6 shrink-0 rounded p-0 text-attention hover:bg-mixer-attention/15`,onClick:r,"aria-label":c,children:t(e?sv:iv,{className:`size-3.5`})})})]})}const o2=/artifact:(?!agents\/)(?!documents\/)([^\s)\]"]+)/g;function s2(e){let t=new Set;for(let n of e.matchAll(o2))t.add(n[1].replace(/^\/+/,``));return[...t]}async function c2(e,t,n,r){let i=s2(t);if(i.length===0)return{content:t,persisted:[],failed:[]};let a=new Map,o=[],s=[];for(let t of i){let i=`documents/${r}/${t}`;try{await e.copyFile(`agents/${n}/${t}`,i),a.set(t,i),o.push({from:t,to:i})}catch(e){console.warn(`Failed to persist a referenced artifact; keeping a run-scoped link`,{artifact_path:t,error:e instanceof Error?e.message:String(e)}),a.set(t,`agents/${n}/${t}`),s.push(t)}}return{content:t.replace(o2,(e,t)=>{let n=a.get(t.replace(/^\/+/,``));return n?`artifact:${n}`:e}),persisted:o,failed:s}}const l2=[`ask_user`,`think`,`plan`,`update_plan`,`end_conversation`,`learn_artifact_operations`,`learn_code_execution`,`learn_content_authoring`,`learn_document_management`,`learn_document_search`,`learn_image_analysis`,`execute_shell`,`fetch_document`],u2=[`artifact_operations`,`code_execution`],d2=[`update_document`,`update_document_properties`,`create_document`,`set_document_type`,`merge_documents`,`import_file`,`create_or_update_object_type`,`disable_type`,`batch_execute`];function f2(e,t){return[`Direct edits are already saved to '${e}'. Use this compact unified diff as context only;`,`do not re-apply it. The artifact remains the current source of truth.`,"```diff",`--- a/${e}`,`+++ b/${e}`,t,"```"].join(`
1385
- `)}const p2=`document-editing`,m2=`sys:GeneralAgent`,h2=new Set,g2=new Set([`text/markdown`,`text/x-markdown`]),_2=new Set([...g2,`text/plain`]);function v2(e,t){return`${e}:${t}`}function y2(e){return h2.has(e)}function b2(e,t){t?h2.add(e):h2.delete(e)}function x2(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function S2(e){return`document-root:${e}`}function C2(e){return`document:${e}`}function w2(e,t){return{tags:[p2,S2(t),C2(e)],properties:{resource_kind:`store_document`,document_id:e,document_root_id:t}}}function T2(e,t){return{canEdit:e,canCollaborate:t}}function E2(e){return e?.split(`;`,1)[0]?.trim().toLowerCase()||void 0}function D2(e){let t=E2(e);return t!==void 0&&g2.has(t)}function O2(e){let t=E2(e);return t!==void 0&&_2.has(t)}function k2(e,t,n,r,i=m2){if(e.interaction!==i||e.started_by!==r||e.status===`cancelled`)return!1;let a=e.tags??[];if(!a.includes(p2))return!1;let o=x2(e.properties);return a.includes(S2(n))?o?.resource_kind===`store_document`&&o.document_root_id===n:a.includes(C2(n))||a.includes(C2(t))}async function A2(e,t,n,r,i,a){for(let o of t)try{let t=await e.retrieve(o);if(k2(t,n,r,i,a))return t}catch{}}async function j2(e,t,n,r,i=m2){let a=[S2(n),C2(n),C2(t)],o=new Set;for(let s of new Set(a))try{let a=(await e.search({interaction:i,started_by:r,tags:[s],limit:20,sort:[`updated_at:desc`]})).hits.map(e=>e.id).filter(e=>!o.has(e));for(let e of a)o.add(e);let c=await A2(e,a,t,n,r,i);if(c)return c}catch{break}return(await e.list({interaction:i,started_by:r,limit:100,sort:`updated_at`,order:`desc`})).items.find(e=>e.run_kind===`agent`&&k2(e,t,n,r,i))}var M2=class extends Error{constructor(e,t){super(e,t===void 0?void 0:{cause:t}),this.name=`DocumentEditingTargetError`}};async function N2(e,t){let n=await e.retrieve(t),r=n;if(n.revision&&!n.revision.head){let i=(await e.getRevisions(n.id)).filter(e=>e.revision?.head===!0);if(i.length!==1)throw new M2(`Expected one head revision for document ${t}, found ${i.length}`);if(r=await e.retrieve(i[0].id),r.revision?.head!==!0)throw new M2(`Resolved document ${r.id} is no longer the current head`)}let i=r.content?.etag;if(!i)throw new M2(`Document ${r.id} has no content ETag`);let a=await e.getObjectText(r.id);if(typeof a.text!=`string`)throw new M2(`Document ${r.id} has no text content`);return{id:r.id,etag:i,content:a.text}}var P2=class extends be{idOf(e){return e.id}labelOf(e){return e.label}descriptionOf(e){return e.description}selectedClassName(e){return`border-3 border-primary`}};function F2({isOpen:e,onClose:r,onConfirm:i,isLoading:a,uploadedFileName:s}){let{t:c}=K(),l=U(()=>[{id:`update`,label:c(`modal.saveVersion.updateCurrent`),description:c(s?`modal.saveVersion.updateWithFileDescription`:`modal.saveVersion.updateDescription`)},{id:`new-version`,label:c(`modal.saveVersion.createNew`),description:c(s?`modal.saveVersion.createWithFileDescription`:`modal.saveVersion.createDescription`)}],[c,s]),u=s?l[1]:l[0],[d,f]=G(u),[p,m]=G(``),h=new P2;H(()=>{e&&(f(u),m(``))},[u,e]);let g=d?.id===`new-version`;return n(se,{isOpen:e,onClose:r,className:`sm:max-w-md`,children:[t(ue,{children:c(`modal.saveChanges`)}),t(ce,{children:n(`div`,{className:`space-y-4`,children:[s&&t(`div`,{className:`mb-4 p-3 bg-blue-50 dark:bg-blue-900/20 rounded-md`,children:n(`p`,{className:`text-sm text-blue-700 dark:text-blue-300 font-medium`,children:[c(`modal.saveVersion.replaceFile`),` `,t(`span`,{className:`font-bold`,children:s})]})}),t(`p`,{className:`text-sm text-mixer-muted/5`,children:c(`modal.saveVersion.howToSave`)}),t(ye,{adapter:h,options:l,selected:d,onSelect:e=>{f(e)}}),g&&t(L,{label:c(`modal.saveVersion.versionLabel`),description:c(`modal.saveVersion.versionLabelDescription`),className:`mt-3 ps-8`,children:t(te,{value:p,onChange:m,placeholder:c(`modal.saveVersion.versionLabelPlaceholder`),className:`w-full`})})]})}),n(le,{children:[t(o,{variant:`secondary`,onClick:r,disabled:a,children:c(`modal.cancel`)}),t(o,{variant:`primary`,onClick:async()=>{await i(g,g?p:void 0)},isLoading:a,children:c(`modal.save`)})]})]})}Q();function I2(e){return e.length>12?`${e.slice(0,4)}…${e.slice(-4)}`:e}function L2(e){return`drafts/${e}.md`}function R2(e,t,n,r,i){return[`You are collaborating with the user on one specific Markdown document in Vertesia.`,`Canonical document: [${e.name||e.content?.name||`Document`}](store:${t})`,`Canonical base revision ID: ${t}`,`Canonical base ETag: ${n??`unavailable`}`,`Working copy artifact: ${r}`,``,`The working copy was hydrated and read before your first turn. It is the source of truth for this editing`,`session. Apply requested changes only to that artifact using edit_artifact. Preserve all unrelated content`,`exactly. User block edits may already be applied to the artifact; acknowledge them and continue from the`,`current artifact generation. Attachments may contain review comments to apply in bulk.`,``,`Do not call update_document, create_document, or write_artifact for this working copy. The user publishes`,`the artifact back to the canonical document with the Save to document button, which enforces the base ETag.`,``,`You may use execute_shell to regenerate charts, diagrams, and other derived assets. Write generated files`,`under '/home/daytona/out/' so they sync back to the run, then reference them from Markdown with a run-local`,`link such as 'artifact:out/chart.png'. Saving the document persists and rewrites those links automatically.`,``,`Images: never inline image data as base64 data URIs — it bloats the document and cannot be reliably edited.`,`Keep existing image references (e.g. 'artifact:documents/…' URLs) exactly as they are: they point to durable`,`storage that outlives this session. Files already in this run's artifact space may be referenced with`,`run-local links like 'artifact:files/photo.png' — publishing copies them into durable storage and rewrites`,`the links automatically.`,``,`User request: ${i}`].join(`
1386
- `)}function z2(e,t,n){return[`The canonical document was updated outside this session, so publishing the working copy was rejected.`,`1) Fetch the latest canonical revision ${t} with fetch_document into 'drafts/${e}.theirs.md'.`,`2) Compare it with the working copy '${n}' and merge the external changes into the working copy with edit_artifact, preserving this session's edits.`,`3) Reply with a short list of what was merged, plus any conflicting passages and how you resolved them, so I can review before saving again.`].join(`
1387
- `)}function B2(e,t,n){return[`Summarize the changes in the working copy '${n}' relative to the original document revision ${t}.`,`If you no longer have the original content, fetch it with fetch_document into 'drafts/${e}.base.md'.`,`Do not modify the working copy.`,`Reply with a concise changelog: grouped bullets, most important first, suitable for a revision note.`].join(`
1388
- `)}function V2(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function H2({original:e,workingCopy:r}){let i=U(()=>Vt(e,r),[e,r]),a=U(()=>({added:i.reduce((e,t)=>e+(t.type===`added`?t.text.length:0),0),removed:i.reduce((e,t)=>e+(t.type===`removed`?t.text.length:0),0)}),[i]);return n(`div`,{className:`flex h-full min-h-0 flex-col bg-muted/10`,children:[n(`div`,{className:`flex shrink-0 items-center justify-end gap-3 border-b border-mixer-muted/20 px-5 py-2 text-xs`,children:[n(`span`,{className:`text-destructive`,children:[`−`,a.removed]}),n(`span`,{className:`text-success`,children:[`+`,a.added]})]}),t(`div`,{className:`min-h-0 flex-1 overflow-auto p-5`,children:t(`pre`,{className:`mx-auto max-w-5xl whitespace-pre-wrap break-words rounded-lg border border-mixer-muted/25 bg-background p-5 font-mono text-xs leading-6 shadow-sm`,children:i.map((e,n)=>e.type===`removed`?t(`del`,{className:`bg-mixer-destructive/15 text-destructive line-through decoration-destructive/50`,children:e.text},n):e.type===`added`?t(`ins`,{className:`bg-mixer-success/15 text-success no-underline`,children:e.text},n):t(`span`,{children:e.text},n))})})]})}function U2({object:r,initialContent:i=``,onDocumentUpdated:a,onClose:s,sendMessageRef:c,model:l,startImmediately:u=!1}){let{client:d,project:f,store:m,user:h}=q(),{t:g}=K(),_=nt(),v=W(null),y=c??v,[x,S]=G(),[C,w]=G(!1),[T,E]=G(!1),[D,O]=G(!0),[k,A]=G(!0),[j,M]=G(!1),[N,P]=G(0),[F,I]=G(!1),L=JSON.stringify(l?{environment:l.env,model:l.model,model_options:l.options}:{}),ee=l!==void 0,R=U(()=>JSON.parse(L),[L]),[te,ne]=G(!ee),[re,ie]=G(!1),[ae,oe]=G(!1),[se,ce]=G(!1),[le,ue]=G(!1),[de,fe]=G(!1),[pe,me]=G(!1),[he,ge]=G({key:0}),[_e,ve]=G(i),[ye,be]=G(!1),[we,Te]=G(i),[Ee,De]=G(i),[Oe,ke]=G(`document`),[Ae,Me]=G(),[Ne,Pe]=G(r.id),[Fe,Ie]=G(r.content?.etag),[Le,Re]=G(),[ze,Be]=G(R),Ve=W(ee?`host`:`none`),He=W(void 0),Ue=W(new Set),z=W(void 0),Ke=W(!1),qe=W(null),Je=r.revision?.root||r.id,Ye=U(()=>L2(Je),[Je]),Xe=h?.sub?`user:${h.sub}`:void 0,Ze=`${f?.id??`no-project`}:${Je}`,Qe=`${Ze}:${r.type?.id??`no-type`}`,$e=Le?.key===Qe?Le.interaction:void 0,et=W(Ze),tt=W({editingScopeKey:Ze,id:r.id}),rt=W({documentId:r.id,documentRootId:Je}),it=ye&&_e!==Ee,at=le&&!de;rt.current.documentRootId!==Je&&(rt.current={documentId:r.id,documentRootId:Je}),tt.current.editingScopeKey!==Ze&&(tt.current={editingScopeKey:Ze,id:r.id}),H(()=>{et.current!==Ze&&(et.current=Ze,Ve.current=ee?`host`:`none`,Be(R),ne(!ee),Ue.current.clear(),ve(i),Te(i),De(i),be(!1),me(!1),ue(!1),fe(!1),Ke.current=!1,ke(`document`),Pe(r.id),Ie(r.content?.etag))},[Ze,ee,i,r.content?.etag,r.id,R]),H(()=>{let e=!1,t=Ze,n=tt.current.id;return A(!0),M(!1),N2(m.objects,n).then(n=>{e||tt.current.editingScopeKey!==t||(tt.current={editingScopeKey:t,id:n.id},rt.current={documentId:n.id,documentRootId:Je},Pe(n.id),Ie(n.etag),Te(n.content),De(n.content))}).catch(n=>{console.warn(`Failed to resolve the document editing target`,{error:n,attempt:N}),!e&&tt.current.editingScopeKey===t&&M(!0)}).finally(()=>{!e&&tt.current.editingScopeKey===t&&A(!1)}),()=>{e=!0}},[Je,Ze,m.objects,N]),H(()=>{let e=!1,t=r.type?.id;if(!t){Re({key:Qe,interaction:m2});return}return Q0(d,t).then(t=>{e||Re({key:Qe,interaction:t?.editing?.interaction?.trim()||`sys:GeneralAgent`})}),()=>{e=!0}},[d,Qe,r.type?.id]),H(()=>{x||Ve.current===`run`||(ee?(Ve.current=`host`,Be(R),ne(!1)):Ve.current===`host`&&(Ve.current=`none`,Be({})))},[x,ee,R]),H(()=>{if(ee){ne(!1);return}if(!f){ne(!1);return}let e=!1,t=Ze;return ne(!0),d.projects.retrieve(f.id).then(n=>{e||et.current!==t||Ve.current!==`none`||(Ve.current=`project`,Be(e2(n)))}).catch(e=>{console.warn(`Failed to load the default document editing model`,e)}).finally(()=>{e||ne(!1)}),()=>{e=!0}},[d,Ze,ee,f]),H(()=>{if(S(void 0),!Xe||!$e){O(!1);return}let e=!1;return O(!0),j2(d.agents,rt.current.documentId,Je,Xe,$e).then(t=>{e||!t||(S(t.id),t.config?.environment&&t.config.model&&(Ve.current=`run`,Be({environment:t.config.environment,model:t.config.model,model_options:t.config.model_options})))}).catch(e=>{console.warn(`Failed to look up an existing document editing run`,e)}).finally(()=>{e||O(!1)}),()=>{e=!0}},[d,Je,$e,Xe]);let B=V(e=>{Ve.current=`user`,Be(e)},[]),ot=V(()=>{x&&navigator.clipboard.writeText(x).then(()=>_({status:`success`,title:g(`agent.runIdCopied`),duration:2e3})).catch(e=>console.warn(`Failed to copy the agent run id`,e))},[x,g,_]),st=V(async()=>{if(!(!x||T)){E(!0);try{await d.agents.terminate(x,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3})}catch(e){console.warn(`Failed to terminate the document editing run`,e)}finally{E(!1)}Ue.current.clear(),S(void 0),be(!1),ve(Ee),me(!1),Ke.current=!1,ue(!1),fe(!1)}},[x,d.agents,T,Ee,g,_]),ct=V(async(e,t)=>{if(!(!f||!$e||D||k||j||C||te)){w(!0);try{if(!ze.environment||!ze.model){_({status:`error`,title:g(`agent.documentEditingDefaultsRequired`),duration:5e3});return}let n=R2(r,Ne,Fe,Ye,e?.trim()||g(`agent.documentEditingInitialRequest`)),i=w2(Ne,Je),a={interaction:$e,interactive:!0,tool_approval_mode:t?.tool_approval_mode,tool_names:l2,excluded_tools:d2,initial_skills:u2,initial_tool_calls:[{id:`hydrate-working-copy`,tool:`fetch_document`,input:{id:Ne,mode:`content`,output_artifact:{path:Ye}}},{id:`read-working-copy`,tool:`read_artifact`,input:{path:Ye}}],data:{user_prompt:n},config:{environment:ze.environment,model:ze.model,model_options:ze.model_options},started_by:Xe,tags:i.tags,properties:i.properties},o=await d.agents.start(a);return S(o.id),{agent_run_id:o.id}}catch(e){console.error(`Failed to start document editing agent`,e),_({status:`error`,title:g(`agent.documentEditingStartFailed`),description:e instanceof Error?e.message:void 0,duration:5e3});return}finally{w(!1)}}},[d.agents,Je,Ye,ze,$e,te,D,k,C,r,f,Xe,g,Ne,Fe,j,_]),lt=V((e,t)=>{z.current=t,ve(e),be(!0)},[]);H(()=>{if(!u||x||!f||!$e||D||k||j||C||te||!ze.environment||!ze.model)return;let e=JSON.stringify({scope:Ze,interaction:$e,document:Ne,configuration:ze});He.current!==e&&(He.current=e,ct(g(`agent.documentEditingStartRequest`),{tool_approval_mode:`full_control`}))},[x,$e,Ze,ze,te,D,k,C,f,u,ct,g,Ne,j]);let ut=V(e=>{let t=Ke.current;Ke.current=e,ue(e),e||(fe(!1),t&&ge(e=>({key:e.key+1})))},[]),dt=V((e,t)=>{let n=y.current;if(!n){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}n(e,t)},[y,g,_]),ft=V(e=>{let t=e.anchor.block_type.replaceAll(`_`,` `),n=e.comment?.trim()||g(`agent.editedSelectionMessage`,{blockType:t});dt(n,{editing_action:e})},[dt,g]),pt=V(async(e,t)=>{if(!(!ye||!Fe||!it||at||re||k||j)){ie(!0);try{let n=_e;x&&(n=(await c2(d.files,n,x,crypto.randomUUID())).content);let i=r.content?.type||`text/markdown`,o=r.content?.name||`content.md`,s=new File([new Blob([n],{type:i})],o,{type:i}),c=await m.objects.update(Ne,{content:s},{createRevision:e,revisionLabel:t,ifMatch:Fe});if(Pe(c.id),Ie(c.content?.etag),De(n),Me(void 0),oe(!1),a?.(c.id,e),_({status:`success`,title:g(`store.textSaved`),duration:2500}),x&&n!==_e&&z.current)try{await d.agents.updateArtifactContent(x,Ye,{content:n,generation:z.current}),ge(e=>({key:e.key+1}))}catch(e){console.warn(`Failed to sync persisted artifact links into the working copy`,e)}}catch(e){let t=V2(e),n=t===412;if(t===412||t===400)try{let e=await N2(m.objects,Ne);(e.id!==Ne||t===412)&&(n=!0,Pe(e.id),Ie(e.etag),Me({headId:e.id}))}catch(e){console.warn(`Failed to resolve the new head after a save conflict`,e)}_({status:`error`,title:g(`store.errorSavingText`),description:n?g(`store.textConflict`):Ge(e,g(`store.errorSavingTextDefault`)),duration:5e3})}finally{ie(!1)}}},[x,_e,ye,d.agents,d.files,Ye,it,at,k,re,r.content?.name,r.content?.type,a,m.objects,g,Ne,Fe,j,_]),mt=V(()=>{let e=y.current;if(!e||!Ae){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(z2(Je,Ae.headId,Ye)),Me(void 0),ke(`document`)},[Je,Ye,y,Ae,g,_]),ht=V(()=>{let e=y.current;if(!e){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(B2(Je,tt.current.id,Ye))},[Je,Ye,y,g,_]),gt=V(async()=>Oe!==`editor`||!pe||!!await qe.current?.(),[pe,Oe]),_t=V(async e=>{e!==Oe&&await gt()&&ke(e)},[gt,Oe]),vt=V(async()=>{await gt()&&s?.()},[gt,s]),yt=V(async()=>{let e=y.current;if(!e||!x||at||se){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}ce(!0);try{let t=await qe.current?.();if(!t)return;let n=Bt(t.previous,t.current,{context:1});n&&e(f2(Ye,n)),me(!1),_({status:`success`,title:g(`agent.changesSentToAgent`),duration:2e3})}finally{ce(!1)}},[x,Ye,at,se,y,g,_]);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex h-14 shrink-0 items-center justify-between gap-3 border-b border-mixer-muted/20 px-4`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate font-semibold`,children:r.name||r.content?.name}),n(`div`,{className:`flex items-center gap-2 text-xs text-muted`,children:[n(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[it?t(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full bg-attention`}):ye?t(th,{className:`size-3 text-success`}):null,g(it?`store.unsavedChanges`:`store.textSaved`)]}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(We,{description:`${g(`agent.workingCopy`)}: ${Ye}`,asChild:!0,children:n(`span`,{className:`min-w-0 truncate font-mono`,children:[`drafts/`,I2(Je),`.md`]})}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(We,{description:`${g(`agent.originalDocument`)}: ${tt.current.id}`,asChild:!0,children:n(`span`,{className:`shrink-0 font-mono`,children:[g(`agent.originalDocument`).toLowerCase(),` `,I2(tt.current.id)]})})]})]}),n(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[n(`div`,{className:`flex items-center rounded-md border border-mixer-muted/25 bg-muted/10 p-0.5`,children:[n(o,{variant:Oe===`document`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void _t(`document`),children:[t(Kg,{className:`size-3.5`}),g(`agent.document`)]}),n(o,{variant:Oe===`editor`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void _t(`editor`),children:[t(Bg,{className:`size-3.5`}),g(`agent.fullEditor`)]}),n(o,{variant:Oe===`diff`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void _t(`diff`),disabled:!ye||_e===we,children:[t(g_,{className:`size-3.5`}),g(`agent.reviewChanges`)]})]}),Oe===`diff`?n(o,{variant:`ghost`,size:`sm`,className:`h-8 gap-1.5`,onClick:ht,disabled:!ye||_e===we,children:[t(Q_,{className:`size-3.5`}),g(`agent.summarizeChanges`)]}):null,t(We,{description:g(`agent.refresh`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>ge(e=>({key:e.key+1})),disabled:!x,"aria-label":g(`agent.refresh`),children:t(gy,{className:`size-4`})})}),t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),t(i2,{value:ze,onChange:B,disabled:!!x||C||D,isLoading:te}),x?null:n(o,{variant:`primary`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>void ct(g(`agent.documentEditingStartRequest`)),disabled:C||D||k||te||j||!f||!$e||!ze.environment||!ze.model,children:[C?t(je,{size:`sm`}):t(Yy,{className:`size-4`}),g(C?`agent.startingAgent`:`agent.documentEditingStart`)]}),x?n(e,{children:[t(We,{description:x,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`font-mono text-[11px] text-muted`,onClick:ot,"aria-label":g(`agent.copyRunId`),children:I2(x)})}),t(We,{description:g(`agent.startNewConversation`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>{it?I(!0):st()},disabled:T,"aria-label":g(`agent.startNewConversation`),children:t(yy,{className:`size-4`})})})]}):null,t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),n(o,{variant:`primary`,className:`min-w-36 gap-2`,onClick:()=>oe(!0),disabled:!it||!Fe||at||re||k||j,children:[re?t(je,{size:`sm`}):t(Ty,{className:`size-4`}),g(`agent.saveToDocument`)]}),s?t(o,{variant:`ghost`,size:`sm`,onClick:()=>void vt(),"aria-label":g(`agent.close`),children:t(Kb,{className:`size-4`})}):null]})]}),Ae?n(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-b border-mixer-attention/30 bg-mixer-attention/10 px-4 py-2 text-sm`,children:[t(`span`,{className:`min-w-0 truncate text-attention`,children:g(`agent.saveConflictNotice`)}),n(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t(o,{variant:`outline`,size:`sm`,onClick:mt,children:g(`agent.askAgentToReconcile`)}),t(o,{variant:`ghost`,size:`sm`,onClick:()=>Me(void 0),"aria-label":g(`agent.close`),children:t(Kb,{className:`size-4`})})]})]}):null,n(Ce,{direction:`horizontal`,className:`min-h-0 flex-1`,children:[t(Se,{defaultSize:65,minSize:35,className:`min-w-0 bg-background`,children:t(`div`,{className:`flex h-full min-h-0 flex-col`,children:t(`div`,{className:`min-h-0 flex-1`,children:Oe===`diff`?t(H2,{original:we,workingCopy:_e}):t(wt,{runId:x,path:Ye,viewMode:Oe===`editor`?`document`:`components`,baselineContent:we,initialContent:Ee,refreshKey:he.key,refreshDetails:he.details,readOnly:at,allowComments:!!x,onContentChange:lt,onAction:ft,onSendMessage:dt,onSendChangesToAgent:yt,hasUnsentChanges:it&&pe,isSendingChanges:se,sendChangesDisabled:!x||at,toolbarStatus:le?t(a2,{isLocked:at,onToggleLock:()=>fe(e=>!e)}):void 0,onDocumentEdit:()=>me(!0),flushChangesRef:qe})})})}),t(xe,{withHandle:!0}),t(Se,{defaultSize:35,minSize:25,className:`min-w-[320px]`,children:D||k?t(p,{className:`h-full`,children:t(je,{size:`lg`})}):j?n(p,{className:`h-full flex-col gap-3 px-6 text-center`,children:[t(`div`,{className:`text-sm text-muted`,children:g(`agent.failedToLoadDocument`)}),t(o,{variant:`outline`,size:`sm`,onClick:()=>P(e=>e+1),children:g(`agent.retry`)})]}):t(O1,{agentRunId:x,startWorkflow:ct,resetWorkflow:()=>S(void 0),onRestart:e=>S(e.id),sendMessageRef:y,onMessage:e=>{let t=e.details;if(!Ut(t,Ye))return;let n=`${e.timestamp}:${t?.path}:${t?.generation??``}`;Ue.current.has(n)||(Ue.current.add(n),ge(e=>({key:e.key+1,details:t})))},onAgentWorkingChange:ut,title:g(`agent.documentEditing`),initialMessage:g(`agent.documentEditingWelcome`),startButtonText:g(C?`agent.startingAgent`:`agent.startAgent`),placeholder:g(`agent.documentEditingPlaceholder`),initialToolApprovalMode:`full_control`,hideObjectLinking:!0,hideHeader:!0,showRightPanel:!1,fullWidth:!0,interactive:!0})})]}),t(b,{isOpen:F,title:g(`agent.newSessionDiscardTitle`),content:g(`agent.newSessionDiscardDescription`),onConfirm:()=>{I(!1),st()},onCancel:()=>I(!1)}),t(F2,{isOpen:ae,onClose:()=>oe(!1),onConfirm:pt,isLoading:re})]})}function W2({object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s}){let{t:c}=K();return t(se,{isOpen:!0,onClose:r,size:`full`,noCloseButton:!0,disableCloseOnClickOutside:!0,className:`gap-0 overflow-hidden p-0`,description:c(`agent.documentEditingWelcome`),children:t(U2,{object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s})})}function G2({isOpen:r,onClose:i,object:a,refetch:s}){let{client:c,store:l}=q(),u=nt(),{t:d}=K(),{theme:f}=tt(),p=$n(),[m,h]=G(!1),[g,_]=G(``),[v,y]=G(!1),[b,x]=G(null),S=W(void 0),[C,w]=G(null),[T,E]=G(null),D=V(async e=>{try{let t=await l.types.retrieve(e);t.object_schema&&w(t.object_schema)}catch(e){console.error(`Failed to fetch JSON schema:`,e)}},[l.types]);H(()=>{r&&(_(JSON.stringify(a.properties||{},null,2)),a.type?.id&&D(a.type.id))},[r,a,D]);let O=e=>{C&&e.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:`http://myserver/object-schema.json`,fileMatch:[`*`],schema:C}]})};function k(){if(!S.current)return;let e=S.current.getValue();try{let t=JSON.parse(e);x(t),y(!0)}catch{u({status:`error`,title:d(`store.invalidJson`),description:d(`store.pleaseFixJsonSyntax`),duration:5e3})}}let A=e=>{_(e)};async function j(e,t){try{h(!0);let n=b||JSON.parse(g);if(e){let e=await c.objects.update(a.id,{properties:n},{createRevision:!0,revisionLabel:t});e.id!==a.id&&E(e.id),u({status:`success`,title:d(`store.newVersionCreated`),description:d(`store.newVersionCreatedDesc`),duration:2e3}),y(!1),i(),e.id!==a.id&&setTimeout(()=>{p(`/objects/${e.id}`),u({status:`info`,title:d(`store.viewingNewVersion`),description:t?d(`store.viewingVersionLabel`,{label:t}):d(`store.viewingNewVersionDefault`),duration:3e3})},100)}else await l.objects.update(a.id,{properties:n}),u({status:`success`,title:d(`store.propertiesUpdated`),description:d(`store.propertiesUpdatedDesc`),duration:2e3}),s&&await s(),y(!1),i()}catch(e){u({status:`error`,title:d(`store.errorUpdatingProperties`),description:Ge(e,d(`store.errorUpdatingPropertiesDefault`)),duration:5e3}),h(!1)}}function M(){y(!1)}return n(e,{children:[n(se,{isOpen:r,onClose:i,className:`sm:max-w-[90%] md:max-w-[80%] lg:max-w-[75%] xl:max-w-[70%]`,children:[t(ue,{children:d(`store.editProperties`)}),n(ce,{children:[n(`div`,{className:`mb-2 text-sm text-gray-500`,children:[a.type?.name?n(`span`,{children:[`Editing properties for object type: `,t(`strong`,{children:a.type.name})]}):t(`span`,{children:d(`store.editingGenericDocument`)}),C!==null&&t(`span`,{className:`ms-2 text-green-600`,children:`(JSON schema validation enabled)`})]}),t(`div`,{className:`h-[75vh] border rounded-md overflow-hidden`,children:t(Pt,{value:g,language:`json`,editorRef:S,onChange:e=>A(e.state.doc.toString()),beforeMount:O,theme:f===`dark`?`vs-dark`:`vs`})})]}),n(le,{children:[t(o,{variant:`secondary`,onClick:i,children:`Cancel`}),t(o,{variant:`primary`,onClick:k,children:`Save Changes`})]})]}),t(F2,{isOpen:v,onClose:M,onConfirm:j,isLoading:m})]})}const K2=ht(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownDocumentEditor})));function q2(e){switch(e){case`text/markdown`:case`text/x-markdown`:return`markdown`;case`application/json`:return`json`;case`application/xml`:case`text/xml`:return`xml`;default:return`plaintext`}}function J2({object:r,text:i,onClose:a,onSaved:s}){let{store:c}=q(),l=nt(),{t:u}=K(),{theme:d}=tt(),f=$n(),p=W(void 0),[m,h]=G(i),[g,_]=G(!1),[v,y]=G(!1),[b,x]=G(!1),S=q2(r.content?.type),C=D2(r.content?.type);H(()=>{h(i),_(!1)},[i]);let w=V(()=>{g||_(!0)},[g]),T=V(e=>{h(e),_(e!==i)},[i]);function E(){!C&&!p.current||x(!0)}async function D(e,t){if(!C&&!p.current)return;let n=C?m:p.current?.getValue();if(n===void 0)return;let i=r.content?.type||`text/plain`,o=r.content?.name||`content.txt`;try{y(!0);let d=new Blob([n],{type:i}),p=new File([d],o,{type:i}),m=await c.objects.update(r.id,{content:p},{createRevision:e,revisionLabel:t,ifMatch:r.content?.etag});l({status:`success`,title:u(`store.textSaved`),duration:2e3}),x(!1),e&&m.id!==r.id?(a(),setTimeout(()=>{f(`/objects/${m.id}`)},100)):s()}catch(e){let t=Ge(e,u(`store.errorSavingTextDefault`)),n=(typeof e==`object`&&e&&`status`in e?e.status:void 0)===412||t.includes(`412`);l({status:`error`,title:u(`store.errorSavingText`),description:n?u(`store.textConflict`):t,duration:5e3})}finally{y(!1)}}return n(e,{children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1 shrink-0`,children:[g&&t(`span`,{className:`text-xs text-attention`,children:u(`store.unsavedChanges`)}),t(`div`,{className:`flex-1`}),t(o,{variant:`ghost`,size:`sm`,onClick:a,disabled:v,children:u(`store.cancelEdit`)}),t(o,{variant:`secondary`,size:`sm`,onClick:E,disabled:!g,isLoading:v,children:u(`store.saveText`)})]}),t(`div`,{className:`flex-1 min-h-0 border rounded-md overflow-hidden mx-2 mb-2`,children:C?t(ut,{fallback:t(`div`,{className:`h-full w-full`}),children:t(K2,{value:m,onChange:T})}):t(Pt,{value:i,language:S,editorRef:p,onChange:w,theme:d===`dark`?`vs-dark`:`vs`,options:{wordWrap:`on`,minimap:{enabled:!1},lineNumbers:`on`,scrollBeyondLastLine:!1}})}),t(F2,{isOpen:b,onClose:()=>x(!1),onConfirm:D,isLoading:v})]})}const Y2=131072;function X2(e,t,n=!1,r=e){let{store:i}=q(),[a,o]=G(t),[s,c]=G(()=>t&&t.length>Y2?t.substring(0,Y2):t),[l,u]=G(!1),[d,f]=G(()=>!!t&&t.length>Y2),[p,m]=G(),h=W(t),g=W(e),_=W(r),v=W(!1),y=V((e,t=!0)=>{let n=h.current;t&&n&&e&&n!==e?m(e=>({previousText:n,version:(e?.version??0)+1})):t||m(void 0),h.current=e,o(e),e&&e.length>Y2?(c(e.substring(0,Y2)),f(!0)):(c(e),f(!1))},[]),b=V(()=>{let t=e,n=r;u(!0),i.objects.getObjectText(e).then(e=>{if(g.current!==t)return;let r=_.current===n&&!v.current;y(e.text,r),v.current=!1}).catch(e=>{console.error(`Failed to load text`,e)}).finally(()=>{g.current===t&&u(!1)})},[y,r,e,i]);return bt(()=>{let i=g.current!==e,a=_.current!==r;g.current=e,_.current=r,a&&(v.current=!0),t!==void 0&&(y(t,!a),v.current=!1),n&&t===void 0&&(i||h.current===void 0)&&b()},[y,r,t,n,b,e]),{fullText:a,displayText:s,isLoading:l,isCropped:d,changeHighlight:p,loadText:b}}function Z2(e,t){let{client:n}=q(),[r,i]=G({isComplete:!1});return H(()=>{if(!t)return;let r=!1,a,o=(e,t,n)=>{i(r=>{let i=JSON.stringify(r.progress??null),a=JSON.stringify(e??null);return r.status===t&&r.isComplete===n&&i===a?r:{progress:e,status:t,isComplete:n}})};function s(){r||n.objects.analyze(e).getStatus().then(e=>{e.status===En.RUNNING?(o(e.progress,e.status,!1),r||(a=setTimeout(s,2e3))):o(e.progress,e.status,!0)}).catch(()=>{r||(a=setTimeout(s,1e4))})}return s(),()=>{r=!0,a&&clearTimeout(a)}},[t,e,n]),{progress:r.progress,status:r.status,isComplete:r.isComplete}}function Q2(e,t){let{client:n}=q(),r=Xt.getFixedT(null,Yt),[i,a]=G(),[o,s]=G(!1),[c,l]=G();return{pdfUrl:i,isConverting:o,error:c,triggerConversion:V(async()=>{if(!t||o)return;s(!0),l(void 0);let i=async t=>{try{let o=await n.objects.getRendition(e,{format:_n.pdf,generate_if_missing:t,sign_url:!0,block_on_generation:!1});o.status===`generating`?setTimeout(()=>i(!1),5e3):o.status===`found`&&o.renditions?.length?(a(o.renditions[0]),s(!1)):o.status===`failed`&&(l(r(`store.pdfConversionFailed`)),s(!1))}catch(e){console.error(`Failed to convert Office document to PDF:`,e),l(r(`store.failedToConvertToPdf`)),s(!1)}};await i(!0)},[e,t,o,n,r])}}Q(),JY();const $2=()=>({a:({node:e,...n})=>{let r=n.href||``;return r.includes(`/store/objects/`)?t(Qn,{topLevelNav:!0,href:r,className:`text-info`,children:n.children}):t(`a`,{...n,target:`_blank`,rel:`noopener noreferrer`})},p:({node:e,...n})=>t(`p`,{...n,className:`my-0`}),pre:({node:e,...n})=>t(`pre`,{...n,className:`my-2 p-2 rounded`}),code:({node:e,className:n,children:r,...i})=>{let a=!/language-(\w+)/.exec(n||``);return t(`code`,{...i,className:a?`px-1.5 py-0.5 rounded`:`text-muted`,children:r})},h1:({node:e,...n})=>t(`h1`,{...n,className:`font-bold text-2xl my-2`}),h2:({node:e,...n})=>t(`h2`,{...n,className:`font-bold text-xl my-2`}),h3:({node:e,...n})=>t(`h3`,{...n,className:`font-bold text-lg my-2`}),li:({node:e,...n})=>t(`li`,{...n})});function e4(e){return e===fn.created||e===fn.processing}function t4(e){return e.metadata?.content_processor?.type}function n4(e){return e?e.includes(`
1382
+ `)}let r=await i(n,{tool_approval_mode:oe});if(!r){re(null),ae(null);return}re(n),ae(Date.now());let a=r.agent_run_id,o=!0;if(A&&de.length>0){let e=`batch-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,t=[],n=[];for(let e of de)try{let n=`files/${e.name}`;await P.agents.uploadArtifact(a,n,e);let r=`file-${Date.now()}-${Math.random().toString(36).substr(2,9)}`;await P.agents.sendSignal(a,`FileUploaded`,{id:r,name:e.name,content_type:e.type||`application/octet-stream`,reference:`artifact:${n}`,artifact_path:n}),t.push(r)}catch(t){console.error(`Failed to upload staged file ${e.name}:`,t),n.push({name:e.name,error:t instanceof Error?t.message:String(t)})}o=await c1(P,a,{batch_id:e,file_ids:t,failed_uploads:n.length>0?n:void 0}),o&&fe([]),n.length>0&&ce({title:D(`agent.stagedFilesUploadFailed`),status:`warning`,duration:6e3,description:n.map(e=>e.name).join(`, `)})}p?.(),te(a),I(``),ce(o?{title:D(`agent.agentStarted`),status:`success`,duration:3e3}:{title:D(`agent.stagedFilesNotDelivered`),status:`error`,duration:8e3,description:D(`agent.stagedFilesNotDeliveredDescription`)})}catch(e){re(null),ae(null),ce({title:D(`agent.errorStarting`),status:`error`,duration:3e3,description:e instanceof Error?e.message:D(`agent.unknownError`)})}finally{ee(!1)}}},Oe=e=>{if(e.key===`Enter`){if(!(e.metaKey||e.ctrlKey||e.altKey||e.shiftKey)){e.preventDefault(),De();return}e.shiftKey||(e.preventDefault(),Ke(e.currentTarget,I))}},ke=V(()=>{let e=le.current;if(e){if(k){e.style.height=`100%`;return}e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`}},[k]);return H(()=>{ke()},[F,ke]),R?t(N1,{onClose:a,isModal:s,initialMessage:e,placeholder:l,fullWidth:c,hideHeader:g,headerVariant:y,hideFileUpload:_,hideObjectLinking:v,inputContainerClassName:x,inputClassName:S,className:C,allowWorkflowControl:w,onAgentWorkingChange:E,agentRunId:R,title:d,pendingStartMessage:ne??void 0,pendingStartTimestamp:ie??void 0,initialToolApprovalMode:oe}):t(`div`,{className:z(`flex flex-col items-center bg-background`,O&&!k?``:`h-full`,C),children:n(`div`,{className:z(`relative flex w-full flex-col overflow-hidden border-0`,O&&!k?``:`h-full`,c?``:`max-w-4xl`),onDragEnter:A?be:void 0,onDragOver:A?xe:void 0,onDragLeave:A?Se:void 0,onDrop:A?Ce:void 0,children:[A&&_e&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-info-background z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(Tb,{className:`size-6`}),`Drop files to stage for upload`]})}),A&&t(`input`,{ref:ue,type:`file`,multiple:!0,accept:m,onChange:Te,className:`hidden`}),!g&&n(`div`,{className:`flex items-center justify-between border-b border-border/60 bg-background px-3 py-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{className:`p-1`,children:t(gg,{className:`size-3.5 text-muted`})}),t(`span`,{className:`text-sm font-medium text-foreground`,children:N})]}),a&&!s&&t(o,{size:`xs`,variant:`ghost`,onClick:a,title:D(`agent.close`),className:`text-muted hover:text-foreground`,children:t(Kb,{className:`size-4`})})]}),t(`div`,{className:z(`flex flex-col items-center justify-end bg-background px-4`,O?`shrink-0 pt-3`:`flex-1 overflow-y-auto`),children:ne&&ie?t(T1,{message:ne,startedAt:ie}):t(`div`,{className:z(`mx-auto flex w-full max-w-3xl flex-col justify-end`,O?``:`min-h-full py-8`),children:e&&t(`div`,{className:`text-[15px] leading-relaxed text-foreground/80`,children:e})})}),t(`div`,{className:z(`bg-background px-4 pb-safe-area-4 pt-2`,k?`flex min-h-0 flex-1 flex-col`:`shrink-0`),children:n(`div`,{className:z(`mx-auto flex max-w-3xl flex-col gap-3 rounded-2xl border border-border/70 bg-mixer-muted/15 p-3 shadow-lg shadow-black/5`,k&&`min-h-0 w-full flex-1`,x),children:[A&&de.length>0&&n(`div`,{className:`flex flex-wrap gap-2`,children:[he.map((e,r)=>n(`div`,{className:`flex items-center gap-1.5 rounded-md bg-attention/10 px-2 py-1 text-sm text-attention`,title:D(`agent.fileStagedTooltip`),children:[t(Kg,{className:`size-3.5`}),t(`span`,{className:`max-w-[120px] truncate`,children:e.name}),t(`span`,{className:`text-xs opacity-70`,children:D(`agent.staged`)}),t(o,{variant:`unstyled`,"aria-label":`Remove staged file ${e.name}`,onClick:()=>Ee(r),className:`ms-1 rounded p-0.5 hover:bg-attention/20`,children:t(Kb,{className:`size-3`})})]},`${e.name}-${e.size}-${e.lastModified}`)),de.length>3&&n(o,{type:`button`,variant:`ghost`,size:`sm`,"aria-expanded":pe,onClick:()=>me(e=>!e),className:`h-8 shrink-0 gap-1 rounded-xl px-2.5 text-xs text-muted`,children:[!pe&&n(`span`,{children:[`+`,ge]}),D(pe?`agent.showLess`:`agent.showMore`),t(ih,{className:z(`size-3.5 transition-transform`,pe&&`rotate-180`),"aria-hidden":`true`})]})]}),t(Ue,{ref:le,value:F,onChange:e=>I(e.target.value),onKeyDown:Oe,onPaste:we,placeholder:j,disabled:L,rows:2,className:z(`min-h-[72px] resize-none border-0 bg-transparent px-0 py-0 text-sm leading-6 shadow-none focus-visible:ring-0`,k?`min-h-0 flex-1 overflow-y-auto`:`overflow-hidden`,S),style:k?{minHeight:`72px`,maxHeight:`none`}:{minHeight:`72px`,maxHeight:`200px`}}),n(`div`,{className:`flex items-center justify-between gap-3`,children:[n(`div`,{className:`flex min-w-0 items-center gap-2`,children:[A&&t(o,{variant:`ghost`,size:`icon`,onClick:()=>ue.current?.click(),disabled:L||de.length>=h,"aria-label":D(`agent.upload`),className:`rounded-full text-muted`,title:D(`agent.upload`),children:t(Tb,{className:`size-4`})}),r&&t(Xb,{mode:oe,onChange:se,disabled:L})]}),t(o,{onClick:De,disabled:!F.trim()||L,variant:`ghost`,size:`icon`,className:z(`size-9 rounded-full border border-border/60 bg-foreground text-background shadow-sm`,`hover:bg-foreground/90 hover:text-background`,`disabled:bg-mixer-muted/25 disabled:text-muted disabled:opacity-100`),title:M,children:L?t(je,{size:`sm`}):t(Om,{className:`size-4`})})]})]})})]})})}function N1({agentRunId:r,title:i,interactive:a=!0,onClose:s,isModal:c=!1,fullWidth:l=!1,placeholder:u,resetWorkflow:d,onRestart:f,onClone:p,onShowDetails:m,allowWorkflowControl:h=!0,uploadedFiles:g,onRemoveFile:_,acceptedFileTypes:v,maxFiles:y,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideHeader:w,headerVariant:T=`full`,hideMessageInput:E,failedAction:D,hidePlanPanel:O,hideWorkstreamTabs:k,showRightPanel:A=!0,hideFileUpload:j,showArtifacts:M=!1,hideDocumentPanel:N,hiddenMessageTypes:P,getAttachedDocs:F,onAttachmentsSent:I,isUploading:L=!1,getMessageContext:ee,className:R,inputContainerClassName:te,inputClassName:ne,composerContext:re,fusionData:ie,fileUploadRef:ae,sendMessageRef:de,onMessage:fe,onAgentWorkingChange:pe,onProcessingFilesChange:me,processingFiles:he,onPlansChange:ge,onWorkstreamStatusChange:_e,viewMode:ve,onViewModeChange:ye,onShowInputChange:be,stopRef:xe,onStoppingChange:Se,messageItemClassNames:Ce,messageStyleOverrides:we,toolCallGroupClassNames:Te,hideToolCallsInViewMode:Ee,streamingMessageClassNames:De,batchProgressPanelClassNames:Oe,workingIndicatorClassName:ke,messageListClassName:Ae,StoreLinkComponent:je,CollectionLinkComponent:Me,prependFriendlyMessage:Ne,initialRequestData:Pe,initialRequestSchema:Fe,initialRequestTitle:Ie,initialRequestTemplate:Le,payloadContent:Re,conversationContent:ze,conversationTab:Be=!1,pendingStartMessage:Ve,pendingStartTimestamp:He,initialToolApprovalMode:Ue,enablePlayback:We,showPlaybackToggle:Ge=!0,messageFilter:Ke,initialWorkstream:qe}){let{t:Je}=K(),{client:Ye}=q(),Xe=nt(),{messages:Ze,streamingMessages:Qe,isCompleted:$e,initialHistoryStatus:et,debugChunkFlash:tt,addOptimisticMessage:rt,updateOptimisticMessageStatus:it,reconnect:at,agentRunStatus:B,workflowRunId:ot,serverFileUpdates:st}=RX(Ye,r,fe),{plans:ct,activePlanIndex:lt,setActivePlanIndex:ut,workstreamStatusMap:dt,showInput:ft,showSlidingPanel:pt,setShowSlidingPanel:mt}=DX(Ze,a,c),{openDocuments:ht,activeDocumentId:gt,isDocPanelOpen:_t,docRefreshKey:vt,closeDocPanel:yt,selectDocument:bt,openDocInPanel:xt,updateDocumentTitle:St}=HX(Ze),{processingFiles:Ct,hasProcessingFiles:wt,handleFileUpload:Tt,removeProcessingFile:Et,clearProcessingFiles:Dt}=KX(Ye,r,st,Xe,U(()=>GW(Ze),[Ze])),Ot=a&&!j,kt=V(e=>{Et(e)},[Et]),At=W(null),jt=W(null),Mt=W(null),[Nt,Pt]=G(!1),[Ft,It]=G(!1),[Lt,Rt]=G(`sliding`),zt=ve??Lt,Bt=V(e=>{ye?ye(e):Rt(e)},[ye]),[Vt,Ht]=G(!1),[Wt,Gt]=G(!1),[Kt,qt]=G(qe||`all`),Jt=W(qe);H(()=>{qe&&qe!==Jt.current&&(Jt.current=qe,qt(qe))},[qe]);let[Yt,Xt]=G(`live`),[Zt,Qt]=G(!1),[$t,en]=G(0),[tn,nn]=G([]),[rn,an]=G([]),[on,sn]=G(!1),cn=U(()=>Ue===void 0&&a?void 0:An(Ue,a),[Ue,a]),[ln,un]=G(cn),dn=W(!1),fn=W(0),pn=W(!1),hn=W(0),gn=W(null);H(()=>{un(cn)},[cn]);let _n=W(Nt);_n.current=Nt;let vn=W(wt);vn.current=wt;let yn=W(Ct);yn.current=Ct;let bn=U(()=>{let e=Ze.filter(e=>(e.workstream_id||`main`)===`main`);return e[e.length-1]},[Ze]),xn=U(()=>bn?.type===J.TERMINATED?`TERMINATED`:bn?.type===J.COMPLETE&&(!B||B===`RUNNING`)?`COMPLETED`:B,[bn,B]),Sn=U(()=>{let e=xn?.toUpperCase();return e===`COMPLETED`||e===`FAILED`||e===`CANCELED`||e===`CANCELLED`||e===`TERMINATED`||e===`TIMED_OUT`},[xn]),Cn=U(()=>Sn&&xn?.toUpperCase()!==`FAILED`&&!!f,[Sn,xn,f]),wn=!E||Cn,Tn=U(()=>xn?.toUpperCase()===`FAILED`||B?.toUpperCase()===`FAILED`,[xn,B]),En=U(()=>{for(let e=Ze.length-1;e>=0;e--){let t=Ze[e];if(t.type!==J.ERROR||$H(t)!==`main`)continue;let n=typeof t.message==`string`?t.message.trim():``;if(n)return n}},[Ze]),Dn=W(Sn);Dn.current=Sn;let On=W(Cn);On.current=Cn;let kn=U(()=>{let e=ct[lt]||{plan:{plan:[]},timestamp:0},t=dt.get(e.timestamp)||new Map;return{plan:e.plan,workstreamStatus:t}},[ct,lt,dt]),jn=U(()=>v1(Ze),[Ze]),Mn=U(()=>{let e=[...jn];for(let t of rn)x1(e,b1(t));for(let t of tn)x1(e,y1(t));return e.map((e,t)=>({workstream:e,index:t})).sort((e,t)=>Number(!u1(e.workstream.status))-Number(!u1(t.workstream.status))||e.index-t.index).map(({workstream:e})=>e)},[jn,tn,rn]),Nn=U(()=>Mn.filter(e=>u1(e.status)),[Mn]),Pn=U(()=>Nn.filter(e=>e.status===`running`).length,[Nn]),Fn=U(()=>{if(Kt===`all`)return;let e=Mn.find(e=>e.workstream_id===Kt||e.launch_id===Kt);return e?PH(e.workstream_id,e.interaction):PH(Kt)},[Kt,Mn]),In=U(()=>{if(u)return u;if(Fn)return Je(`agent.messageMainAgentWhileViewingWorkstream`,{workstream:Fn})},[Fn,u,Je]),Ln=Ge&&We===void 0&&vC(),Rn=We??(yC()||Zt),zn=U(()=>Ze.filter(e=>!YH(e)&&!(P?.includes(e.type)??!1)),[P,Ze]),Bn=U(()=>nU(zn,Kt),[Kt,zn]),Vn=U(()=>gC(Bn,Yt,Rn),[Rn,Yt,Bn]),Hn=Vn.cursor,Un=Vn.isLive,Wn=Rn&&!Un&&Vn.cursorIndex===Bn.length-1,Gn=Vn.displayedMessages,Kn=U(()=>Ke?Gn.filter(e=>Ke(e)):Gn,[Gn,Ke]),qn=U(()=>Ke?zn.filter(e=>Ke(e)):zn,[Ke,zn]),Jn=Un?Qe:o1,Yn=U(()=>v1(Gn),[Gn]),Zn=U(()=>Yn.filter(e=>u1(e.status)),[Yn]),Qn=U(()=>$e||!XH(Ze),[$e,Ze]),$n=Un||Wn?Qn:!1,er=!Qn&&!Sn;H(()=>{pe?.(er)},[er,pe]);let tr=U(()=>{let e=new Set;for(let t of Gn)MU(r,t)&&e.add(OU(t));return $U(Gn,`main`,e)},[r,Gn]),nr=!!tr&&!Tn&&(!Sn||Cn),rr=Rn&&!Un,ir=wn&&!rr,ar=U(()=>p1(Ze),[Ze]),or=h&&!Sn&&Un&&!!ar;H(()=>{KH(`conversation render state`,{agentRunId:r,messageCount:Ze.length,playbackMessageCount:Bn.length,displayedMessageCount:Kn.length,streamingCount:Qe.size,displayedStreamingCount:Jn.size,initialHistoryStatus:et,isCompleted:$e,effectiveIsCompleted:Qn,displayedIsCompleted:$n,agentRunStatus:B,effectiveWorkflowStatus:xn,isWorkflowTerminal:Sn,playbackCursor:Hn,isPlaybackEnabled:Rn,isPlaybackLive:Un,isPlaybackAtLatest:Wn,activeWorkstream:Kt,showInitialRequest:et===`empty`&&Ze.length===0,pendingStartVisible:Ze.length===0&&!Qn&&!!Ve})},[Kt,r,B,Hn,$n,Kn.length,Jn.size,Qn,xn,et,$e,Wn,Rn,Un,Sn,Ze.length,Ve,Bn.length,Qe.size]);let sr=V(()=>{Qt(e=>!e)},[]),cr=V(e=>{let t=pC(Hn,Bn.length),n=pC(e,Bn.length);Rn&&(n>t||e===`live`&&Hn!==`live`)&&(pn.current=!0,en(e=>e+1)),Xt(e)},[Hn,Rn,Bn.length]);H(()=>{if(!Rn){Yt!==`live`&&Xt(`live`);return}Hn!==Yt&&Xt(Hn)},[Hn,Rn,Yt]),H(()=>{if(!Rn||!pn.current)return;pn.current=!1;let e=window.requestAnimationFrame(()=>{At.current?.scrollIntoView({behavior:`smooth`,block:`end`})});return()=>window.cancelAnimationFrame(e)},[Rn,$t]);let lr=V(e=>{ut(e)},[ut]),[ur,dr]=G(ze||Be?`conversation`:`plan`),[fr,pr]=G(null),[Y,mr]=G(400),[hr,gr]=G(!1),[_r,vr]=G(!1),yr=A&&!_r&&(pt||_t||!k&&Mn.length>0||!!ze||Be),br=W(_t);H(()=>{_t&&!br.current&&vr(!1),br.current=_t},[_t]);let xr=V(()=>{yr?(vr(!0),mt(!1)):(vr(!1),mt(!0),sessionStorage.setItem(`plan-panel-shown`,`true`))},[yr,mt]);H(()=>{!yr&&hr&&gr(!1)},[yr,hr]),H(()=>{if(!hr)return;let e=e=>{let t=Mt.current;if(!t)return;let n=t.getBoundingClientRect(),r=Math.max(300,n.width-420),i=n.right-e.clientX;mr(Math.min(Math.max(i,300),r))},t=()=>{gr(!1)};return window.addEventListener(`mousemove`,e),window.addEventListener(`mouseup`,t),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`,()=>{window.removeEventListener(`mousemove`,e),window.removeEventListener(`mouseup`,t),document.body.style.cursor=``,document.body.style.userSelect=``}},[hr]);let Sr=V(()=>{vr(!0),mt(!1),yt()},[mt,yt]),Cr=V(e=>{/\.md$/i.test(e)&&(vr(!1),pr(e),dr(`artifacts`),mt(!0))},[mt]),wr=W(null);H(()=>{let e,t;for(let n of Ze){let r=n.details;r?.event_class===`display_artifact`&&typeof r.path==`string`&&(e=r.path,t=`${n.timestamp??``}:${r.path}`)}!e||!t||t===wr.current||(wr.current=t,vr(!1),pr(e),dr(`artifacts`),mt(!0))},[Ze,mt]);let Tr=V(({href:e,documentId:n,children:r})=>t(`a`,{href:e,className:`text-info underline cursor-pointer hover:text-info/80`,onClick:e=>{e.preventDefault(),e.stopPropagation(),xt(n),dr(`documents`)},children:r}),[xt]),Er=je??Tr;H(()=>(ae&&(ae.current=Ot?Tt:null),()=>{ae&&(ae.current=null)}),[ae,Tt,Ot]),H(()=>{me?.(Ct)},[Ct,me]),H(()=>{ge?.(ct,lt)},[ct,lt,ge]),H(()=>{_e?.(dt)},[dt,_e]),H(()=>{pr(null),dn.current=!1,sn(!1),nn([]),an([])},[r]),H(()=>{let e=et!==`loading`&&!Qn&&!Sn&&!on;if(KH(`active workstreams poll state`,{agentRunId:r,shouldPoll:e,initialHistoryStatus:et,effectiveIsCompleted:Qn,isWorkflowTerminal:Sn,isWorkstreamQueryUnavailable:on}),!e){nn(e=>e.length===0?e:[]);return}let t=!1,n=!1,i=async()=>{if(n){KH(`active workstreams fetch skipped while previous request is pending`,{agentRunId:r});return}n=!0;try{KH(`active workstreams fetch start`,{agentRunId:r});let e=await Ye.agents.getActiveWorkstreams(r);if(t)return;if(KH(`active workstreams fetch success`,{agentRunId:r,runningCount:e.running?.length??0,completedCount:e.completed?.length??0,unavailable:e.unavailable===!0}),nn(e.running??[]),an(e.completed??[]),e.unavailable){sn(!0);return}dn.current=!1}catch(e){if(t)return;nn(e=>e.length===0?e:[]),sn(!0),KH(`active workstreams fetch failed`,{agentRunId:r,error:e instanceof Error?e.message:String(e)}),dn.current||=(console.warn(`Failed to fetch active workstreams:`,e),!0)}finally{n=!1}};i();let a=window.setInterval(i,1e4);return()=>{t=!0,window.clearInterval(a)}},[Ye.agents,r,Qn,et,Sn,on]),H(()=>{if(Ze.length!==0){if(Cn){be?.(!0);return}if(!ft){be?.(!1);return}if(xn&&xn!==`RUNNING`){be?.(!1);return}xn!==null&&be?.(!0)}},[ft,xn,Ze.length,be,Cn]);let Dr=V(async()=>{let e=gn.current;e&&await e},[]),Or=V((e,t)=>{let n=e.trim();if(!n||_n.current||Dn.current&&!On.current)return;if(vn.current){Xe({status:`warning`,title:Je(`agent.filesProcessing`),description:Je(`agent.waitForFilesProcessing`),duration:3e3});return}let i=RU(t);Pt(!0);let a=F?.()||[],o=ee?.()||{},s=n;a.length>0&&!/store:\S+/.test(n)&&(s=[n,``,`Attachments:`,...a.map(e=>`[${e.name}](/store/objects/${e.id})`)].join(`
1383
+ `));let c=Array.from(yn.current.values()).filter(e=>e.status===mn.READY).map(e=>{let t=e.reference?.startsWith(`artifact:`)?e.reference:e.artifact_path?`artifact:${e.artifact_path}`:void 0;return t?`[${e.name}](${t})`:void 0}).filter(e=>!!e);c.length>0&&(s=[s,``,`Uploaded artifacts:`,...c].join(`
1384
+ `));let l=`msg-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,u={timestamp:Date.now(),workflow_run_id:r,type:J.QUESTION,message:s,workstream_id:`main`,details:{_optimistic:!0,_messageId:l,_deliveryStatus:`sending`,...t?.editing_action?{editing_action:t.editing_action}:{},...t?.request_input_response?{request_input_response:t.request_input_response}:{}}};rt(u);let d={...a.length>0?{attached_docs:a.map(e=>e.id)}:{},...o,...t,id:l,_messageId:l},f=()=>Ye.agents.sendSignal(r,`UserInput`,{message:s,client_message_id:l,metadata:d}),p=()=>{it(l,`received`),I?.(),Dt()};i&&AU(r,i),(async()=>{await Dr(),Dn.current&&(await Ye.agents.restart(r),at()),await f(),p()})().catch(e=>{i&&jU(r,i),it(l,`failed`),Xe({status:`error`,title:Je(`agent.failedToSend`),description:e instanceof Error?e.message:Je(`agent.unknownError`),duration:3e3})}).finally(()=>{Pt(!1)})},[r,Ye,Xe,F,ee,I,Dt,at,rt,it,Je,Dr]);H(()=>(de&&(de.current=Or),()=>{de?.current===Or&&(de.current=null)}),[Or,de]);let kr=V(async(e,t)=>{try{await Ye.agents.sendSignal(r,`McpConfigChanged`,{})}catch(e){console.error(`Failed to signal MCP config change`,e)}Or(Je(`agent.mcpConnectedMessage`,{name:e.name}),t)},[Ye,r,Or,Je]),[Ar,jr]=G(void 0);H(()=>{let e=!1,t=hn.current;return Ye.agents.retrieve(r).then(n=>{e||(jr(n.disabled_mcp_collections),hn.current===t&&(n.tool_approval_mode!==void 0||n.interactive!==void 0)&&un(An(n.tool_approval_mode,n.interactive)))}).catch(()=>{}),()=>{e=!0}},[Ye,r]);let Mr=V(e=>{let t=e.length>0?e:void 0;jr(t),Ye.agents.sendSignal(r,`McpConfigChanged`,{disabled_mcp_collections:e}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ye,r]),Nr=V(()=>{Ye.agents.sendSignal(r,`McpConfigChanged`,{}).catch(e=>console.error(`Failed to signal MCP config change`,e))},[Ye,r]),Pr=V(e=>{let t=An(e,a),n=ln;hn.current+=1,un(t);let i=Ye.agents.sendSignal(r,`ToolApprovalModeChanged`,{mode:t}).then(()=>void 0).catch(e=>{un(e=>e===t?n:e),Xe({status:`error`,title:Je(`agent.approvalMode.changeFailed`),description:e instanceof Error?e.message:Je(`agent.unknownError`),duration:3e3})});gn.current=i,i.finally(()=>{gn.current===i&&(gn.current=null)})},[r,Ye,a,Je,Xe,ln]),Fr=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation(),fn.current++,e.dataTransfer?.types?.includes(`Files`)&&Gt(!0))},[Ot]),Ir=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation())},[Ot]),Lr=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation(),fn.current--,fn.current===0&&Gt(!1))},[Ot]),Rr=V(e=>{if(Ot&&(e.preventDefault(),e.stopPropagation(),fn.current=0,Gt(!1),e.dataTransfer?.files&&e.dataTransfer.files.length>0)){let t=Array.from(e.dataTransfer.files);Tt(t)}},[Tt,Ot]),zr=V(async()=>{if(Vt)return;let e=`stop-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,t={timestamp:Date.now(),workflow_run_id:r,type:J.IDLE,message:`Stopped. Waiting for your command...`,workstream_id:`main`,details:{_optimistic:!0,_messageId:e,_deliveryStatus:`sending`,display_role:`user_stopped`,status_reason:`user_stopped`}};rt(t),Ht(!0);try{await Ye.agents.sendSignal(r,`Stop`,{message:`User requested stop`,client_message_id:e,metadata:{id:e,_messageId:e}}),it(e,`received`)}catch(t){Xe({status:`error`,title:Je(`agent.failedToInterrupt`),description:t instanceof Error?t.message:Je(`agent.unknownError`),duration:3e3}),it(e,`failed`)}finally{Ht(!1)}},[Vt,r,rt,Ye.agents,Xe,Je,it]),Br=V(async()=>{if(!(Ft||Qn||!Un)){It(!0);try{await Ye.agents.sendSignal(r,`TriggerCheckpoint`,{reason:`manual user request`})}catch(e){Xe({status:`error`,title:Je(`agent.failedToCompactContext`),description:e instanceof Error?e.message:Je(`agent.unknownError`),duration:3e3})}finally{It(!1)}}},[r,Ye.agents,Qn,Ft,Un,Je,Xe]);H(()=>(xe&&(xe.current=h&&!Qn?zr:null),()=>{xe&&(xe.current=null)}),[xe,Qn,zr,h]),H(()=>{Se?.(Vt)},[Vt,Se]);let Vr=i||Je(`agent.agentConversation`),Hr=async()=>{try{let e=await rU(Ye,r);e&&window.open(e,`_blank`)}catch(e){console.error(`Failed to download conversation`,e),Xe({status:`error`,title:Je(`agent.failedToDownload`),duration:3e3})}},Ur=V(()=>{let e=new Date().toISOString(),t=Qe.size>0?[{cursor:`live`,streamingMessages:Array.from(Qe,([e,t])=>({id:e,...t}))}]:void 0,n={metadata:{title:Vr,agent_run_id:r,exported_at:e,message_count:Ze.length},messages:Ze,...t?{streamingFrames:t}:{}};k1(`${O1(Vr)||`agent-chat`}-${O1(r)}.json`,n),Xe({status:`success`,title:Je(`agent.rewind.fixtureExported`),duration:2e3})},[Vr,r,Ze,Qe,Je,Xe]),[Wr,Gr]=G(!1),Kr=()=>{if(!jt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}Gr(!0)},qr=()=>{if(!jt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}let e=`${Vr} - ${r}`;if(!E1(jt.current,e)){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.unableToOpenPrint`),duration:4e3});return}Xe({status:`success`,title:Je(`agent.pdfExportReady`),description:Je(`agent.printDialogDescription`),duration:4e3}),Gr(!1)},Jr=U(()=>Ze.filter(e=>e.type===J.COMPLETE||e.type===J.THOUGHT&&e.details?.tool_status===`completed`).length,[Ze]),Yr=U(()=>{if(!fr)return{key:Jr,details:void 0};let e=0,t;for(let n of Ze){let r=n.details;Ut(r,fr)&&(e++,t=r)}return{key:e,details:t}},[Jr,Ze,fr]),Xr=a&&Un&&xn?.toUpperCase()===`RUNNING`,Zr=U(()=>kn.plan.plan?.reduce((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e),new Map),[kn.plan]),Qr=e=>t(nZ,{title:Vr,variant:e,isCompleted:Qn,isTerminal:Sn,onClose:s,isModal:c,agentRunId:r,workflowRunId:ot||``,viewMode:zt,onViewModeChange:Bt,showPlanPanel:yr,hasPlan:A&&ct.length>0,showPlanButton:A&&!Be,onTogglePlanPanel:xr,showPlaybackButton:Ln,isPlaybackEnabled:Rn,onTogglePlayback:sr,onDownload:Hr,onExportFixture:Ur,resetWorkflow:d,onClone:p,onShowDetails:m,allowWorkflowControl:h,onExportPdf:Kr,isReceivingChunks:tt}),$r=n(`div`,{ref:jt,"data-agent-playback-enabled":Rn||void 0,"data-agent-playback-cursor":Rn?Hn:void 0,"data-agent-live-message-count":Ze.length,"data-agent-rendered-message-count":Kn.length,className:z(`flex flex-col min-h-0 min-w-0 border-0`,Be?`flex-1 h-full`:yr?`w-full flex-1 min-h-[50vh]`:l?`flex-1 w-full`:`flex-1 mx-auto ${c?``:`max-w-4xl`}`),children:[!w&&T===`compact`&&t(`div`,{className:`flex flex-shrink-0 justify-end border-b border-border/60 px-2 py-1 lg:hidden`,children:Qr(`compact`)}),!w&&T!==`compact`&&t(`div`,{className:`flex-shrink-0`,children:Qr(T)}),Rn&&t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(SC,{cursor:Hn,messages:Bn,onChangeCursor:cr})}),Ze.length===0&&!Qn&&Ve&&He?t(T1,{message:Ve,startedAt:He}):t(TJ,{messages:Kn,workstreamSourceMessages:qn,bottomRef:At,isCompleted:$n,plan:kn.plan,workstreamStatus:kn.workstreamStatus,showPlanPanel:A&&pt,onTogglePlanPanel:xr,plans:ct,activePlanIndex:lt,onChangePlan:lr,taskLabels:Zr,streamingMessages:Jn,onSendMessage:Un?Or:void 0,onOpenArtifact:M?Cr:void 0,messageItemClassNames:Ce,messageStyleOverrides:we,toolCallGroupClassNames:Te,hideToolCallsInViewMode:Ee,streamingMessageClassNames:De,batchProgressPanelClassNames:Oe,artifactRunId:r,viewMode:zt,hideWorkstreamTabs:k,workingIndicatorClassName:ke,messageListClassName:Ae,StoreLinkComponent:Er,CollectionLinkComponent:Me,prependFriendlyMessage:Ne,initialRequestData:Pe,initialRequestSchema:Fe,initialRequestTitle:Ie,initialRequestTemplate:Le,showInitialRequest:et===`empty`&&Ze.length===0,hiddenMessageTypes:P,disableAutoScroll:!Un,renderRequestInputControls:!nr,activeWorkstream:Kt,onActiveWorkstreamChange:qt}),nr?t(tW,{message:tr,onSendMessage:Un?Or:void 0,onMcpConnected:Un?kr:void 0,disabled:L||!Un,isLoading:Nt||L}):rr&&Zn.length>0?t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:t(qX,{activeWorkstreams:Zn,onSelectWorkstream:qt})}):ir&&t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:Tn?D??t(oe,{status:`error`,title:Je(`agent.failed`),className:`m-2`,children:En??Je(`agent.error`)}):xn&&xn!==`RUNNING`&&!Cn?zt===`sliding`&&xn===`COMPLETED`?t(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-3 text-sm text-muted`,children:n(`div`,{className:`flex items-center gap-2 border-t border-success/25 pt-3 text-success`,children:[t(Ph,{className:`size-4`}),t(`span`,{className:`font-medium`,children:`Workflow completed`})]})}):n(oe,{status:xn===`COMPLETED`?`success`:`done`,icon:null,className:`m-2`,children:[`This Workflow is `,xn]}):(ft||Cn)&&n(e,{children:[re,t(Q$,{onSend:Or,onStop:h?zr:void 0,approvalModeSlot:a&&ln?t(Xb,{mode:ln,onChange:Pr,disabled:!Un||Sn||!h}):void 0,mcpSlot:t(HJ,{disabledCollections:Ar,onChange:Mr,onConnectionChange:Nr}),disabled:L||!Un,isSending:Nt||L,isStopping:Vt,isStreaming:!Qn,isCompleted:Qn,contextWindowUsage:or?ar:void 0,onCompactContext:or?Br:void 0,isCompactingContext:Ft,activeTaskCount:Pn,activeWorkstreams:Nn,onSelectWorkstream:qt,placeholder:In,onFilesSelected:Ot?Tt:void 0,uploadedFiles:g,onRemoveFile:_,onRemoveProcessingFile:kt,acceptedFileTypes:v,maxFiles:y,processingFiles:Ct,artifactRunId:r,hasProcessingFiles:wt,renderDocumentSearch:b,selectedDocuments:x,onRemoveDocument:S,hideObjectLinking:C,hideFileUpload:!Ot,disableDropZone:Ot,className:te,inputClassName:ne})]})})]}),ei=t(VS,{children:t(EW,{children:n(`div`,{ref:Mt,className:z(`flex flex-col lg:flex-row gap-2 w-full h-full relative overflow-hidden`,Ot&&Wt&&`ring-2 ring-blue-400 ring-inset`,R),onDragEnter:Ot?Fr:void 0,onDragOver:Ot?Ir:void 0,onDragLeave:Ot?Lr:void 0,onDrop:Ot?Rr:void 0,children:[Ot&&Wt&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-blue-100/80 dark:bg-blue-900/40 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-blue-600 dark:text-blue-400 font-medium flex items-center gap-2 text-lg`,children:[t(Tb,{className:`size-6`}),`Drop files to upload`]})}),!Be&&$r,!Be&&T===`compact`&&!w&&t(`div`,{className:`hidden h-full w-12 shrink-0 items-start justify-center px-1 pt-2 lg:flex`,children:Qr(`compact`)}),yr&&n(e,{children:[!Be&&t(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize right panel`,"aria-valuenow":Math.round(Y),"aria-valuemin":300,"aria-valuetext":`${Math.round(Y)} pixels`,tabIndex:0,className:`hidden lg:block lg:w-1 lg:shrink-0 cursor-col-resize bg-border/70 hover:bg-border transition-colors`,onMouseDown:()=>gr(!0),onKeyDown:e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault();let t=e.shiftKey?32:16,n=e.key===`ArrowLeft`?t:-t,r=Mt.current,i=r?Math.max(300,r.getBoundingClientRect().width-420):900;mr(e=>Math.min(Math.max(e+n,300),i))}}),t(`div`,{className:Be?`w-full h-full overflow-auto`:`w-full lg:w-[var(--agent-right-panel-width)] lg:shrink-0 min-h-[50vh] lg:h-full border-t lg:border-t-0`,style:Be?void 0:{"--agent-right-panel-width":`${Y}px`},children:t(TX,{plan:kn.plan,workstreamStatus:kn.workstreamStatus,plans:ct,activePlanIndex:lt,onChangePlan:lr,showPlan:!O&&pt,activeWorkstreams:Mn,hideWorkstreams:k,openDocuments:ht,activeDocumentId:gt,onSelectDocument:bt,onUpdateDocumentTitle:St,docRefreshKey:vt,runId:r,processingFiles:he??Ct,showArtifacts:M,artifactRefreshKey:Yr.key,artifactRefreshDetails:Yr.details,selectedArtifactPath:fr,onSelectedArtifactPathChange:pr,onSendMessage:Xr?Or:void 0,messages:Ze,payloadContent:Re,conversationContent:Be?$r:ze,onClose:Sr,defaultTab:ur,activeTab:ur,onTabChange:dr})})]}),n(se,{isOpen:Wr,onClose:()=>Gr(!1),children:[t(ue,{children:`Export conversation as PDF`}),n(ce,{children:[t(`p`,{className:`mb-2`,children:`This will open your browser's print dialog with the current conversation.`}),t(`p`,{className:`text-sm text-muted`,children:`To save a PDF, choose "Save as PDF" or a similar option in the print dialog.`})]}),n(le,{align:`right`,children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>Gr(!1),children:`Cancel`}),t(o,{size:`sm`,onClick:qr,children:`Open print dialog`})]})]})]})})});return ie?t(Xn,{data:ie,sendMessage:Or,ChartComponent:sC,artifactRunId:r,children:ei}):ei}function P1({messages:e}){let n=ot.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]);return t(`div`,{className:`flex flex-col overflow-y-auto space-y-6 py-4`,children:n.map(e=>t(_G,{message:e,showPulsatingCircle:!1},`${e.workstream_id??`main`}-${e.timestamp}-${e.type}`))})}function F1({messages:e,bottomRef:n,className:r,messagesClassName:i,emptyClassName:a}){let o=ot.useRef(null);H(()=>{n.current&&n.current.scrollIntoView({behavior:`smooth`})},[e,n]);let s=ot.useMemo(()=>[...e].sort((e,t)=>(typeof e.timestamp==`number`?e.timestamp:new Date(e.timestamp).getTime())-(typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime())),[e]);return t(`div`,{ref:o,className:`flex-1 min-h-0 h-full overflow-y-auto py-4 px-4 sm:px-6 lg:px-8 bg-white flex flex-col ${r||``}`,"data-testid":`messages-container`,children:s.length===0?t(`div`,{className:`flex items-center justify-center h-full text-center py-8 ${a||``}`,children:t(`div`,{className:`flex items-center px-4 py-3 text-gray-500`,children:`Waiting for agent response...`})}):t(`div`,{className:`flex-1 flex flex-col justify-start h-full min-h-0 ${i||``}`,children:t(P1,{messages:s,isCompleted:!1})})})}function I1(e){return e.name}function L1({isClearable:e=!1,onChange:n,ignoreVirtuals:r=!1,selectedEnvId:i,disabled:a=!1}){let{t:o}=K(),{client:s}=q(),[c,l]=G(),{data:u,isLoading:d}=Xe(()=>s.environments.list().then(e=>(r?e.filter(e=>!e.provider.startsWith(`virtual_`)):e).slice().sort((e,t)=>e.name.localeCompare(t.name))));return H(()=>{l(u?.find(e=>e.id===i))},[u,i]),t(we,{isClearable:e,optionLabel:I1,options:u??[],value:c,onChange:e=>{l(e),n(e)},placeholder:o(`intakePolicy.placeholder.environment`),filterBy:`name`,disabled:a,isLoading:d})}function R1(e){return e.name}function z1(e){return e?.length?n=>{let r=e.some(e=>e.id===n.id);return t(`span`,{className:r?`opacity-50`:``,children:n.name})}:R1}function B1({envId:e,isClearable:n,onChange:r,selectedModelId:i,disabled:a=!1,greyedModels:o,onModelsLoaded:s}){let{t:c}=K(),{client:l}=q(),[u,d]=G(),{data:f,isLoading:p}=Ye(async()=>{if(!e)return[];try{return[...(await l.environments.retrieve(e)).enabled_models??[]].sort((e,t)=>e.name.localeCompare(t.name))}catch{return[]}},[e]);return H(()=>{if(!i){d(void 0);return}let e=f?.find(e=>e.id===i);d(e??{id:i,name:i,provider:`unknown`})},[f,i]),H(()=>{f&&s?.(f)},[f,s]),t(we,{isClearable:n,by:`id`,optionLabel:z1(o),options:f??[],value:u,onChange:e=>{d(e),r(e)},placeholder:c(`intakePolicy.placeholder.model`),disabled:a,isLoading:p})}function V1({env:e,isClearable:n,onChange:r}){let{t:i}=K(),{client:a}=q(),[o,s]=G(),{data:c,isLoading:l}=Ye(async()=>{if(!e)return[];try{return a.environments.listTrainableModels(e.id)}catch{return[]}},[e?.id]);return t(we,{isClearable:n,by:`id`,optionLabel:R1,options:c??[],value:o,onChange:e=>{s(e),r(e)},placeholder:i(`intakePolicy.placeholder.model`),disabled:!e,isLoading:l})}function H1({children:e,fallback:n}){return U1?t(U1,{fallback:n,children:e}):t(ir,{FallbackComponent:n,children:e})}let U1=null;function W1(e){U1=e}function G1({children:e}){return t(H1,{fallback:K1,children:e})}function K1({error:e}){let{t:r}=K(),i=e instanceof Error?e.message:void 0;return n(oe,{status:`error`,title:r(`errors.somethingWentWrong`),children:[n(`div`,{className:`mb-4`,children:[r(`errors.teamNotifiedLine1`),` `,r(`errors.teamNotifiedLine2`),`\xA0`,t(`a`,{className:`text-info`,href:`mailto:support@vertesiahq.com`,children:`support@vertesiahq.com`}),`.`]}),i&&t(`code`,{className:`w-full mt-4 text-sm text-muted break-words`,children:i})]})}function q1({children:e}){return t(H1,{fallback:J1,children:e})}function J1({error:e}){let r=e instanceof Error?e.message:void 0;return t(`tr`,{children:n(`td`,{colSpan:100,children:[t(`span`,{className:`text-xs`,children:` Cannot display row`}),t(`br`,{}),t(`span`,{className:`bg-gray-400`,children:r})]})})}function Y1({children:e}){return t(H1,{fallback:X1,children:e})}function X1({error:e}){let r=e instanceof Error?e.message:void 0;return console.log(`WidgetError`,e),n(`div`,{className:`text-sm`,children:[`Sorry, this area cannot be loaded or rendered.`,r&&t(`pre`,{children:r})]})}Q();const Z1=/^[a-f0-9]{24}$|^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$|^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9_-]{8,}$/i;function Q1(e){return Z1.test(e)}function $1({className:e,children:r,title:i,description:o,actions:s,breadcrumbs:c,useDynamicBreadcrumbs:l=!0,parentPath:u,parentLabel:d}){let f=$n();function p(e){return e.replace(/[-_]/g,` `).split(` `).map(e=>Jn(e)).join(` `)}let m=e=>{if(e?.title)return e.title;let t=e?.href||``;if(!t)return`Page`;let n=t.split(`#`)[0].split(`?`)[0].split(`/`).filter(e=>e.length>0);return n.length>=1?p(n[n.length-1]):`Page`},h=(()=>{let e=[];if(l&&typeof window<`u`){let t=window.history.state?.historyChain;if(Array.isArray(t))t.forEach((n,r)=>{let i=t.length-r;e.push({label:m(n),href:n.href,onClick:()=>f(n.href,{stepsBack:i})})});else if(u)e.push({label:d??m({href:u}),href:u,onClick:()=>f(u,{isBasePathNested:!1,replace:!0})});else{let t=window.location.pathname.split(`/`).filter(e=>e.length>0);for(let n=0;n<t.length;n++)if(Q1(t[n])){let r=`/${t.slice(0,n).join(`/`)}`;e.push({label:p(t[n-1]||r),href:r,onClick:()=>f(r,{isBasePathNested:!1})})}}}return c&&c.length>0&&c.forEach(t=>{let n=t.props?.children||t,r=t.props?.href;e.push(r?{href:r,label:n,onClick:()=>f(r,{replace:t.props.clearBreadcrumbs})}:{label:n})}),e})();return n(`div`,{className:it(`pb-0 ps-4 pe-2 py-2 flex flex-col`,e),children:[n(`div`,{className:`flex items-start gap-4`,children:[n(`div`,{className:`w-full flex place-content-between h-auto min-h-8 flex-col items-start justify-center`,children:[n(`nav`,{className:`flex-1 flex justify-start text-sm`,children:[h.length>0&&t(a,{path:h,separator:t(uh,{className:`size-3.5 cn-rtl-flip`}),maxItems:4}),o&&t(We,{description:o,children:t(j_,{className:`size-4 text-muted ms-4`})})]}),i&&t(`div`,{className:`flex gap-2 items-center`,children:t(`h1`,{className:`text-xl font-semibold break-all`,children:i})})]}),t(`div`,{className:`flex gap-x-2 shrink-0 items-center`,children:s})]}),r&&t(`div`,{className:`w-full flex items-center`,children:r})]})}function e0(){let{t:e}=K();return n(`div`,{className:`text-center pt-32`,children:[t(`h1`,{className:`text-3xl font-bold text-red-500`,children:`404`}),t(`p`,{className:`text-2xl`,children:e(`layout.pageNotFound`)})]})}Q();const t0=`magic-pdf`;function n0(e){return e.replace(/^\$\.?/,``).replace(/^data\./,``)}function r0(e){let{client:t}=q(),[n,r]=G(!1);return H(()=>{let n=!1;return r(!1),t.files.getDownloadUrl(`${t0}/${e}/grounded-extraction.json`).then(e=>fetch(e.url,{method:`HEAD`})).then(e=>{n||r(e.ok)}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function i0(e){let{client:t}=q(),[n,r]=G(null);return H(()=>{let n=!1;return r(null),t.files.getDownloadUrl(`${t0}/${e}/grounded-extraction.json`).then(e=>fetch(e.url)).then(e=>e.ok?e.json():null).then(e=>{n||!e?.citations||r({confidence:e.confidence,verified:e.citations.filter(e=>e.verified).length,total:e.citations.length,verdict:e.verdict,verdict_reason:e.verdict_reason})}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function a0({objectId:e,onClose:r}){let{t:i}=K(),{client:a}=q(),{data:s,error:c,isLoading:l}=Ye(async()=>{let t=await a.files.getDownloadUrl(`${t0}/${e}/grounded-extraction.json`),n=await fetch(t.url);if(!n.ok)throw Error(i(`grounded.notFound`));return n.json()},[e]);return c?t(`div`,{className:`flex h-full items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`grounded.failedToLoad`),children:Ge(c)}),r&&t(o,{variant:`outline`,onClick:r,children:i(`pdf.close`)})]})}):l||!s?t(`div`,{className:`flex h-full items-center justify-center`,children:t(je,{size:`lg`})}):t(`div`,{className:`relative h-full`,children:t(s0,{extraction:s,objectId:e,onClose:r})})}function o0({objectId:e,onClose:n}){return t(`div`,{className:`fixed inset-0 bg-background z-50`,children:t(a0,{objectId:e,onClose:n})})}function s0({extraction:r,objectId:a,onClose:s}){let{t:c}=K(),{client:l}=q(),u=U(()=>Object.keys(r.pages).map(e=>parseInt(e,10)).sort((e,t)=>e-t),[r.pages]),d=e=>{l.files.getDownloadUrl(`${t0}/${a}/${e}`).then(e=>window.open(e.url,`_blank`)).catch(()=>{})},[f,p]=G(u[0]??1),[m,h]=G(void 0),[g,_]=G(!1),[v,y]=G(`original`),b=U(()=>{let e={digital:0,ocr:0,reviewerConfirmed:0,snapped:0,imageRead:0},t=[];for(let n of r.citations)n.verified?n.snapped?e.snapped++:(n.confidence??0)>=1?e.digital++:e.ocr++:n.reviewed?e.reviewerConfirmed++:(e.imageRead++,t.push(n));let n=e.digital+e.ocr+e.snapped,i=e.reviewerConfirmed;return{groups:e,unverified:t,digitallyVerified:n,modelVerified:i,totalVerified:n+i}},[r.citations]),x=U(()=>{let e=new Map;for(let t of r.citations){let n=n0(t.path),r=e.get(n)??[];r.push(t),e.set(n,r)}return e},[r.citations]),S=r.citations.length,C=b.totalVerified===S,T=e=>{h(e);let t=x.get(n0(e))?.[0];t&&p(t.page)},E=u.indexOf(f),D=m?x.get(n0(m))?.find(e=>e.page===f):void 0,O=D?.cells?D.cells.start===D.cells.end?D.cells.start:`${D.cells.start}:${D.cells.end}`:void 0;return n(Ce,{direction:`horizontal`,className:`absolute inset-0`,children:[n(Se,{defaultSize:55,minSize:25,className:`flex flex-col bg-muted`,children:[n(`div`,{className:`relative flex h-9 shrink-0 items-center justify-center bg-sidebar px-2 border-b border-sidebar-border`,children:[O&&t(i,{variant:`secondary`,className:`absolute start-2 max-w-32 truncate font-mono text-[11px]`,title:O,children:O}),n(`div`,{className:`flex items-center gap-2`,children:[t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`grounded.previousPage`),disabled:E<=0,onClick:()=>p(u[E-1]),children:t(sh,{className:`size-4`})}),t(`span`,{className:`text-xs text-muted`,children:c(`pdf.pageOf`,{pageNumber:f,totalPages:u.length})}),t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`grounded.nextPage`),disabled:E>=u.length-1,onClick:()=>p(u[E+1]),children:t(uh,{className:`size-4`})})]}),n(`fieldset`,{className:`absolute end-2 flex items-center gap-0.5 rounded border-0 bg-muted p-0.5`,children:[t(`legend`,{className:`sr-only`,children:c(`grounded.checkerboard`)}),t(We,{description:c(`pdf.originalImages`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:v===`original`?`outline`:`ghost`,size:`xs`,"aria-label":c(`pdf.originalImages`),"aria-pressed":v===`original`,className:`h-6 gap-1 px-1.5`,onClick:()=>y(`original`),children:[t(O_,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:c(`pdf.page`)})]})}),t(We,{description:c(`grounded.checkerboard`),placement:`bottom`,size:`xs`,asChild:!0,children:n(o,{variant:v===`grid`?`outline`:`ghost`,size:`xs`,"aria-label":c(`grounded.checkerboard`),"aria-pressed":v===`grid`,className:`h-6 gap-1 px-1.5`,onClick:()=>y(`grid`),children:[t(S_,{className:`size-3.5`}),t(`span`,{className:`hidden sm:inline`,children:c(`grounded.checkerboard`)})]})})]})]}),t(`div`,{className:`flex-1 overflow-auto p-2`,children:t(c0,{objectId:a,page:f,dims:r.pages[String(f)],citations:r.citations.filter(e=>e.page===f),selectedPath:m,onSelectPath:h,imageMode:v})})]}),t(xe,{className:`w-[4px] bg-border cursor-ew-resize`}),n(Se,{defaultSize:45,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`span`,{className:`text-sm font-medium`,children:c(`grounded.title`)}),n(`div`,{className:`flex items-center gap-2`,children:[S>0&&t(We,{description:c(`grounded.confidenceHint`),placement:`bottom`,size:`xs`,asChild:!0,children:n(i,{variant:C?`success`:`attention`,className:`gap-1 text-nowrap cursor-pointer`,onClick:()=>_(e=>!e),"aria-expanded":g,children:[t(C?Lh:jg,{className:`size-3.5`}),c(`grounded.verifiedOf`,{verified:b.totalVerified,total:S})]})}),n(w,{align:`right`,trigger:t(o,{variant:`ghost`,size:`xs`,"aria-label":c(`pdf.download`),title:c(`pdf.download`),children:t(Sg,{className:`size-4`})}),children:[n(ae,{className:`text-xs`,onClick:()=>d(`grounded-extraction.json`),children:[t(Pg,{className:`size-4`}),c(`grounded.downloadCitations`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`pages/page-${f}.json`),children:[t(Kg,{className:`size-4`}),c(`grounded.downloadBlocks`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`grounded-annotated.pdf`),children:[t(Lg,{className:`size-4`}),c(`grounded.downloadAnnotated`)]})]}),!!s&&t(o,{variant:`ghost`,size:`xs`,onClick:s,"aria-label":c(`pdf.close`),children:t(Kb,{className:`size-4`})})]})]}),g&&n(`div`,{className:`shrink-0 border-b border-border bg-background px-3 py-2 text-sm max-h-72 overflow-auto`,children:[n(`div`,{className:`mb-1 flex items-center gap-1`,children:[t(`span`,{className:`font-medium`,children:c(`grounded.breakdownTitle`)}),t(We,{description:c(`grounded.breakdownVerificationHelp`),size:`xs`,children:t(j_,{className:`size-3 text-muted`})})]}),n(`div`,{className:`grid grid-cols-2 gap-x-4 text-xs`,children:[t(`span`,{className:`col-span-2 mt-1 font-medium text-success`,children:c(`grounded.digitalVerifiedOf`,{count:b.digitallyVerified,total:S})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownDigital`)}),t(`span`,{className:`text-end text-success`,children:b.groups.digital}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownOcr`)}),t(`span`,{className:`text-end text-success`,children:b.groups.ocr}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownSnapped`)}),t(`span`,{className:`text-end text-success`,children:b.groups.snapped}),t(`span`,{className:`col-span-2 mt-2 font-medium text-success`,children:c(`grounded.modelVerifiedOf`,{count:b.modelVerified,total:S})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownReviewer`)}),t(`span`,{className:`text-end text-success`,children:b.groups.reviewerConfirmed}),b.groups.imageRead>0&&n(e,{children:[t(`span`,{className:`col-span-2 mt-2 font-medium text-attention`,children:c(`grounded.unverifiedCount`,{count:b.groups.imageRead})}),t(`span`,{className:`ps-2 text-muted`,children:c(`grounded.breakdownImageRead`)}),t(`span`,{className:`text-end text-attention`,children:b.groups.imageRead})]})]}),typeof r.hardness?.score==`number`&&n(`p`,{className:`mt-2 text-xs text-muted`,title:c(`grounded.hardnessHint`),children:[c(`grounded.hardness`,{percent:Math.round(r.hardness.score*100)}),r.hardness.escalated?` ↑`:``]}),(r.verdict_reason??r.review?.verdict_reason)&&t(`p`,{className:`mt-2 text-xs`,children:r.verdict_reason??r.review?.verdict_reason}),r.review?.summary&&n(`p`,{className:`mt-2 text-xs text-muted`,children:[n(`span`,{className:`font-medium text-foreground`,children:[c(`grounded.reviewSummary`),`: `]}),r.review.summary]}),typeof r.review?.corrections_applied==`number`&&r.review.corrections_applied>0&&t(`p`,{className:`mt-1 text-xs text-info`,children:c(`grounded.reviewCorrections`,{count:r.review.corrections_applied})}),b.unverified.length>0&&n(`div`,{className:`mt-2`,children:[t(`div`,{className:`text-xs font-medium text-muted mb-1`,children:c(`grounded.breakdownUnverifiedList`)}),t(`ul`,{className:`space-y-0.5`,children:b.unverified.map(e=>t(`li`,{children:n(`button`,{type:`button`,className:`w-full text-start text-xs rounded px-1 py-0.5 hover:bg-muted cursor-pointer`,onClick:()=>{T(e.path),_(!1)},children:[t(`span`,{className:`text-muted`,children:e.path}),` `,t(`span`,{children:String(e.value??``)})]})},e.path))})]})]}),n(`div`,{className:`flex-1 overflow-auto p-3`,children:[t(l0,{value:r.data,path:``,citationsByPath:x,selectedPath:m,onSelect:T}),r.conflicts&&r.conflicts.length>0&&t(`div`,{className:`mt-4 text-xs text-attention`,children:c(`grounded.conflicts`,{count:r.conflicts.length})})]})]})]})}function c0({objectId:e,page:r,dims:i,citations:a,selectedPath:o,onSelectPath:s,imageMode:c}){let{t:l}=K(),{client:u}=q(),[d,f]=G(void 0);if(H(()=>{let t=!1;return f(void 0),u.files.getDownloadUrl(`${t0}/${e}/pages/page-${r}.${c}.jpg`).then(e=>{t||f(e.url)}).catch(e=>console.warn(`Failed to load page image`,e)),()=>{t=!0}},[u,c,e,r]),!d||!i)return t(`div`,{className:`flex items-center justify-center h-64`,children:t(je,{})});let p=a.flatMap(e=>e.boxes.map((r,a)=>{let c=o!==void 0&&n0(o)===n0(e.path),l=e.cells?e.cells.start===e.cells.end?e.cells.start:`${e.cells.start}:${e.cells.end}`:void 0;return t(We,{description:n(`span`,{className:`flex flex-col gap-0.5`,children:[t(`span`,{className:`flex items-center gap-1 font-medium`,children:f0(e.path).map((e,r)=>n(lt,{children:[r>0&&t(uh,{className:`size-3 shrink-0 cn-rtl-flip`}),e]},`${r}:${e}`))}),l&&t(`span`,{className:`font-mono`,children:l}),e.source_text&&t(`span`,{children:e.source_text})]}),size:`xs`,asChild:!0,children:t(`button`,{type:`button`,"aria-label":e.path,onClick:()=>s(n0(e.path)),className:z(`absolute cursor-pointer border rounded-[1px] transition-colors`,e.misaligned&&`border-dashed`,c?`border-2 border-primary bg-primary/20 z-10`:e.verified?`border-success/70 hover:bg-success/20`:e.reviewed?`border-info/70 hover:bg-info/20`:`border-attention/80 hover:bg-attention/20`),style:{position:`absolute`,left:`${r.x/i.width*100}%`,top:`${r.y/i.height*100}%`,width:`${r.w/i.width*100}%`,height:`${r.h/i.height*100}%`}})},`${e.path}-${a}`)})),m=((i.rotation??0)%360+360)%360;if(m!==0){let e=m===90||m===270;return n(`div`,{className:`relative w-full`,style:{aspectRatio:`${i.width} / ${i.height}`},children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`absolute select-none`,style:{left:`50%`,top:`50%`,width:`${(e?i.height/i.width:1)*100}%`,height:`${(e?i.width/i.height:1)*100}%`,maxWidth:`none`,transform:`translate(-50%, -50%) rotate(${m}deg)`,transformOrigin:`center center`}}),p]})}return n(`div`,{className:`relative w-full`,children:[t(`img`,{src:d,alt:l(`grounded.pageAlt`,{page:r}),className:`w-full select-none`}),p]})}function l0({value:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){return Array.isArray(e)?e.length>0&&e.every(e=>typeof e==`object`&&!!e)?t(u0,{items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}):t(`div`,{className:`space-y-1`,children:e.map((e,n)=>t(l0,{value:e,path:`${r}[${n}]`,citationsByPath:i,selectedPath:a,onSelect:o},`${r}[${n}]`))}):typeof e==`object`&&e?t(`div`,{className:r?`ps-3 border-s border-border space-y-0.5`:`space-y-0.5`,children:Object.entries(e).map(([e,s])=>{let c=r?`${r}.${e}`:e;if(typeof s!=`object`||!s)return t(d0,{label:e,value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o},c);let l=Array.isArray(s)&&s.length>0&&s.every(e=>typeof e==`object`&&!!e);return n(`div`,{className:`pt-1`,children:[!l&&t(`div`,{className:`text-sm font-semibold`,children:p0(e)}),t(l0,{value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o})]},c)})}):null}function u0({items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}){let{t:s}=K(),c=U(()=>{let t=new Set;for(let n of e)for(let e of Object.keys(n))t.add(e);return Array.from(t)},[e]);return n(`div`,{className:`pt-1`,children:[n(`div`,{className:`text-sm font-semibold`,children:[p0(r.split(`.`).pop()),` (`,e.length,`)`]}),t(`div`,{className:`overflow-x-auto`,children:n(`table`,{className:`w-full text-xs`,children:[t(`thead`,{children:t(`tr`,{className:`text-start text-muted`,children:c.map(e=>t(`th`,{scope:`col`,className:`py-1 pe-2 font-medium`,children:p0(e)},e))})}),t(`tbody`,{children:e.map((e,l)=>t(`tr`,{className:`border-t border-border/50`,children:c.map(c=>{let u=`${r}[${l}].${c}`,d=i.get(u)?.[0];return t(`td`,{className:`py-0.5 pe-2`,children:n(`button`,{type:`button`,onClick:()=>o(u),className:z(`text-start rounded px-1 w-full`,a===u?`bg-primary/15 ring-1 ring-primary`:d?`hover:bg-muted cursor-pointer`:`text-muted cursor-default`),children:[g0(e[c]),d&&typeof d.confidence==`number`&&t(`span`,{className:z(`ms-1 text-[10px]`,h0(d.confidence)),title:s(`grounded.scoreHint`),children:m0(d.confidence)})]})},c)})},`${r}[${l}]`))})]})})]})}function d0({label:e,value:r,path:i,citationsByPath:a,selectedPath:o,onSelect:s}){let{t:c}=K(),l=a.get(i)?.[0];return n(`button`,{type:`button`,onClick:()=>l&&s(i),className:z(`flex items-center gap-2 w-full text-start text-sm rounded px-1.5 py-0.5`,o===i?`bg-primary/15 ring-1 ring-primary`:l?`hover:bg-muted`:``,!l&&`cursor-default`),children:[n(`span`,{className:`min-w-28 shrink-0 font-semibold`,children:[p0(e),`:`]}),t(`span`,{className:`flex-1 wrap-break-word`,children:g0(r)}),l&&typeof l.confidence==`number`&&t(`span`,{className:z(`text-xs shrink-0`,h0(l.confidence)),title:c(`grounded.scoreHint`),children:m0(l.confidence)}),l&&(l.verified?t(Lh,{"aria-label":c(`grounded.verified`),className:`size-3.5 shrink-0 text-success`}):l.reviewed?t(Yy,{"aria-label":c(`grounded.aiVerified`),className:`size-3.5 shrink-0 text-info`}):t(jg,{"aria-label":c(`grounded.readFromImage`),className:`size-3.5 shrink-0 text-attention`}))]})}function f0(e){return n0(e).split(`.`).map(e=>p0(e.replace(/\[\d+\]/g,``))).filter(Boolean)}function p0(e){return e?zt(e):``}function m0(e){let t=e*100;return Number.isInteger(t)?`${t}%`:`${(Math.floor(t*100)/100).toFixed(2)}%`}function h0(e){return e>=.95?`text-success`:e>=.7?`text-attention`:`text-destructive`}function g0(e){return e==null||e===``?`—`:typeof e==`boolean`?e?`true`:`false`:typeof e==`object`?JSON.stringify(e):String(e)}const _0=`magic-pdf`;var v0;(function(e){e.original=`original`,e.instrumented=`instrumented`})(v0||={});var y0=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}getCacheKey(e,t){return`${t}-${e}`}async getPageImageUrl(e,t){let n=this.getCacheKey(e,t),r=this.cache.get(n);if(r)return r;let i=this.pending.get(n);if(i)return i;let a=this.fetchImageUrl(e,t);this.pending.set(n,a);try{let e=await a;return this.cache.set(n,e),e}finally{this.pending.delete(n)}}async fetchImageUrl(e,t){let n=this.getImagePath(e,t);return(await this.client.files.getDownloadUrl(n)).url}getImagePath(e,t){let n=`${_0}/${this.objectId}/pages`;switch(t){case v0.original:return`${n}/page-${e}.original.jpg`;case v0.instrumented:return`${n}/page-${e}.instrumented.jpg`}}},b0=class{client;objectId;totalPages;cache=new Map;pending=new Map;constructor(e,t,n){this.client=e,this.objectId=t,this.totalPages=n}async getPageLayout(e){let t=this.cache.get(e);if(t!==void 0)return t;let n=this.pending.get(e);if(n)return n;let r=this.fetchPageLayout(e);this.pending.set(e,r);try{let t=await r;return this.cache.set(e,t),t}finally{this.pending.delete(e)}}async fetchPageLayout(e){let t=`${_0}/${this.objectId}/pages/page-${e}.layout.json`,n=await this.client.files.getDownloadUrl(t),r=await fetch(n.url,{method:`GET`});if(!r.ok)throw Error(`Failed to fetch json layout: ${r.statusText}`);return r.text()}},x0=class{totalPages;pages=[];constructor(e){this.totalPages=e}initFromContent(e){this.pages=S0(e,this.totalPages)}async loadUrls(e,t){}async getPageMarkdown(e){let t=e-1;return t<0||t>=this.pages.length?``:this.pages[t]}};function S0(e,t){let n=Array(t).fill(``),r=/<!--\s*\{\s*"page"\s*:\s*(\d+)\s*\}\s*-->/g,i=[];for(let t of e.matchAll(r))i.push({page:parseInt(t[1],10),index:t.index+t[0].length});for(let r=0;r<i.length;r++){let a=i[r],o=a.page-1;if(o<0||o>=t)continue;let s=a.index,c=e.slice(s).match(/<!--\s*\{\s*"page"\s*:\s*\d+\s*\}\s*-->/),l=c&&c.index!==void 0?s+c.index:e.length,u=e.slice(s,l).trim();u=u.replace(/\n---\s*$/,``).trim(),n[o]=u}return n}const C0=dt(void 0);function w0({children:e,object:n}){let{client:r}=q(),i=n.metadata.page_count||10,[a,o]=G(()=>{let e=new x0(i);return n.text&&e.initFromContent(n.text),{count:i,layoutProvider:new b0(r,n.id,i),markdownProvider:e,imageProvider:new y0(r,n.id,i),pdfUrl:``,pdfUrlLoading:!0}});return H(()=>{let e=n.metadata?.renditions?.find(e=>e.name===vn),t=n.content?.type===`application/pdf`,i=e?.content?.source||(t?n.content?.source:void 0);i?r.store.objects.getDownloadUrl(i,void 0,`inline`).then(e=>{o(t=>({...t,pdfUrl:e.url,pdfUrlLoading:!1}))}).catch(e=>{console.warn(`Failed to get PDF URL:`,e),o(e=>({...e,pdfUrlLoading:!1}))}):o(e=>({...e,pdfUrlLoading:!1}))},[r,n.metadata,n.content?.type,n.content?.source]),t(C0.Provider,{value:a,children:e})}function T0(e,t,n){return e.files.getDownloadUrl(`${_0}/${t}/${n}`).then(e=>e.url)}function E0(){let e=ot.useContext(C0);if(!e)throw Error(`useMagicPdfContext must be used within a MagicPdfProvider`);return e}Q();function D0({object:e}){let{t:n}=K(),{client:r}=q(),i=t=>{T0(r,e.id,t).then(e=>window.open(e,`_blank`))};return t(o,{variant:`ghost`,size:`xs`,onClick:()=>i(`document.md`),title:n(`pdf.download`),children:t(Sg,{className:`size-4`})})}Q();function O0({className:e}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(tv,{className:`w-6 h-6 animate-spin text-gray-400`})})}function k0({viewType:e,pageNumber:n}){switch(e){case`json`:return t(A0,{pageNumber:n});case`markdown`:return t(j0,{pageNumber:n});default:return t(j0,{pageNumber:n})}}function A0({pageNumber:e}){let[n,r]=G(null),[i,a]=G(!0),[o,s]=G(null),{layoutProvider:c}=E0();return H(()=>{a(!0),s(null),c.getPageLayout(e).then(e=>{r(e?JSON.parse(e):null),a(!1)}).catch(e=>{console.error(e),s(e.message||`Failed to load layout`),a(!1)})},[e,c]),i?t(`div`,{className:`px-4 py-8`,children:t(O0,{})}):o?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:o}):n?t(At,{className:`w-full`,data:n}):null}function j0({pageNumber:e}){let[r,i]=G(null),[a,o]=G(!0),[s,c]=G(null),{markdownProvider:l}=E0();return H(()=>{o(!0),c(null),l.getPageMarkdown(e).then(e=>{i(e),o(!1)}).catch(e=>{console.error(e),c(e.message||`Failed to load markdown`),o(!1)})},[e,l]),a?n(`div`,{className:`h-full flex flex-col items-center justify-center gap-2`,children:[t(O0,{}),t(`span`,{className:`text-sm text-muted-foreground`,children:`Loading...`})]}):s?t(`div`,{className:`px-4 py-2 text-red-500 text-sm`,children:s}):t(`div`,{className:`px-4 py-2 prose prose-sm max-w-none dark:prose-invert`,children:r?t(Nt,{children:r}):t(`div`,{children:`No markdown content available`})})}Q(),yY();var M0=class extends ct{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`PDF View error:`,e,t)}render(){return this.state.hasError?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:Xt.t(`pdf.failedToLoadViewer`,{ns:Yt}),children:this.state.error?.message||`An unexpected error occurred`}),this.props.onClose&&t(o,{variant:`outline`,onClick:this.props.onClose,children:`Close`})]})}):this.props.children}};function N0({objectId:e,onClose:r}){let{t:i}=K(),{client:a}=q(),{data:s,error:c}=Ye(()=>a.store.objects.retrieve(e,`+text`),[e]);return c?t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:n(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md`,children:[t(M,{title:i(`pdf.fetchingDocumentFailed`),children:Ge(c)}),r&&t(o,{variant:`outline`,onClick:r,children:`Close`})]})}):s?t(M0,{onClose:r,children:t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:t(w0,{object:s,children:t(P0,{object:s,onClose:r})})})}):n(`div`,{className:`fixed inset-0 bg-background z-50 flex flex-col`,children:[t(`div`,{className:`flex h-9 items-center justify-end shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(Kb,{className:`size-4`})})}),t(`div`,{className:`flex-1 flex items-center justify-center`,children:t(`div`,{className:`animate-spin rounded-full h-8 w-8 border-b-2 border-primary`})})]})}function P0({object:e,onClose:r}){let{t:i}=K(),{count:a,pdfUrl:s,pdfUrlLoading:c}=E0(),[l,u]=G(1);return n(Ce,{direction:`horizontal`,className:`absolute inset-0`,children:[t(Se,{defaultSize:50,minSize:20,maxSize:80,className:`bg-muted`,children:t(pY,{pdfUrl:s,pdfUrlLoading:c,pageCount:a,className:`h-full`,currentPage:l,onChange:u})}),t(xe,{className:`w-[4px] bg-border cursor-ew-resize`}),n(Se,{defaultSize:50,minSize:20,className:`flex flex-col`,children:[n(`div`,{className:`flex h-9 items-center justify-between shrink-0 bg-sidebar px-2 border-b border-sidebar-border`,children:[t(`div`,{className:`flex items-center gap-x-2`,children:t(D0,{object:e})}),t(`span`,{className:`text-xs text-muted-foreground`,children:i(`pdf.pageOf`,{pageNumber:l,totalPages:a})}),t(`div`,{className:`flex items-center gap-x-2`,children:!!r&&t(o,{variant:`ghost`,size:`xs`,onClick:r,title:i(`pdf.close`),children:t(Kb,{className:`size-4`})})})]}),t(`div`,{className:`flex-1 overflow-auto px-2`,children:t(k0,{pageNumber:l,viewType:`markdown`})})]})]})}const F0=[`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`],I0=[`video/mp4`,`video/webm`],L0=[`audio/mp4`,`audio/m4a`,`audio/x-m4a`,`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/webm`];function R0(e){let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`}function z0({url:e,source:r,object:i,className:a}){let{t:o}=K(),{client:s}=q(),[c,l]=G(e),[u,d]=G(!e&&(!!r||!!i)),f=i?.metadata,p=(f?.renditions||[]).find(e=>e.name===ln),m=i?.content?.type&&L0.includes(i.content.type),h=!!i&&i.metadata?.type===dn.Audio&&!p&&!m;return H(()=>{if(e){l(e),d(!1);return}l(void 0),r||i?(d(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==dn.Audio)return;let e;p?.content?.source?e=await s.files.getDownloadUrl(p.content.source):m&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get audio URL`,e)}finally{d(!1)}})()):d(!1)},[e,r,i,p,m,s]),h?t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noAudioRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.audioFormatRequired`)})]})}):u?t(`div`,{className:`flex justify-center items-center h-[200px] ${a??``}`.trim(),children:t(je,{size:`md`})}):c?n(`div`,{className:`flex flex-col items-center gap-4 ${a??``}`.trim(),children:[t(`audio`,{src:c,controls:!0,className:`w-full max-w-2xl`,children:`Your browser does not support the audio tag.`}),f?.duration&&n(`div`,{className:`text-sm text-muted`,children:[`Duration: `,R0(f.duration)]})]}):t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:`Failed to load audio`})}function B0({url:e,source:n,object:r,className:i}){let{client:a}=q(),[o,s]=G(e),[c,l]=G(!e&&(!!n||!!r));return H(()=>{if(e){s(e),l(!1);return}s(void 0),n||r?(l(!0),(async()=>{try{if(n){let e=await a.files.getDownloadUrl(n);s(e.url);return}if(!r||r.metadata?.type!==dn.Image)return;let e=r.content?.type&&F0.includes(r.content.type);try{let e=await a.objects.getRendition(r.id,{format:hn.jpeg,generate_if_missing:!1,sign_url:!0});if(e.status===`found`&&e.renditions?.length){s(e.renditions[0]);return}}catch{}if(e&&r.content?.source){let e=await a.files.getDownloadUrl(r.content.source);s(e.url)}}finally{l(!1)}})()):l(!1)},[e,n,r,a]),c?t(`div`,{className:i,children:t(je,{size:`md`})}):o?t(`img`,{src:o,alt:r?.name,className:`w-full object-contain ${i??``}`.trim()}):null}function V0({url:e,source:r,object:i,className:a}){let{t:o}=K(),{client:s}=q(),[c,l]=G(e),[u,d]=G(),[f,p]=G(!e&&(!!r||!!i)),m=i?.metadata?.renditions||[],h=m.find(e=>e.content.type===`video/mp4`)||m.find(e=>e.content.type===`video/webm`),g=i?.content?.type&&I0.includes(i.content.type),_=m.find(e=>e.name===yn),v=!!i&&i.metadata?.type===dn.Video&&!h&&!g;return H(()=>{if(e){l(e),p(!1);return}l(void 0),d(void 0),r||i?(p(!0),(async()=>{try{if(r){let e=await s.files.getDownloadUrl(r);l(e.url);return}if(!i||i.metadata?.type!==dn.Video)return;let e;h?.content?.source?e=await s.files.getDownloadUrl(h.content.source):g&&i.content?.source&&(e=await s.files.getDownloadUrl(i.content.source)),e&&l(e.url)}catch(e){console.error(`Failed to get video URL`,e)}finally{p(!1)}})()):p(!1)},[e,r,i,h,g,s]),H(()=>{_?.content?.source&&s.files.getDownloadUrl(_.content.source).then(e=>d(e.url)).catch(e=>console.error(`Failed to load poster image`,e))},[_,s]),v?t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:n(`div`,{className:`text-center`,children:[t(`p`,{children:o(`store.noVideoRendition`)}),t(`p`,{className:`text-sm mt-2`,children:o(`store.videoFormatRequired`)})]})}):f?t(`div`,{className:`flex justify-center items-center h-[400px] ${a??``}`.trim(),children:t(je,{size:`md`})}):c?t(`video`,{src:c,poster:u,controls:!0,className:`w-full h-full object-contain ${a??``}`.trim(),children:`Your browser does not support the video tag.`}):t(`div`,{className:`flex justify-center items-center h-[400px] text-muted ${a??``}`.trim(),children:`Failed to load video`})}Q();function H0({oauthProviderId:r,onAuthChange:i}){let{client:a}=q(),{t:o}=K(),[s,c]=G(null),[l,u]=G(!0),[d,f]=G(!1),[p,m]=G(!1),h=V(async()=>{try{u(!0);let e=await a.oauthProviders.getStatus(r);c(e)}catch(e){console.error(`Failed to load OAuth provider status:`,e)}finally{u(!1)}},[a,r]);H(()=>{h()},[h]);let{openOAuthPopup:g}=mO({onComplete:()=>{f(!1),h(),i?.()},onError:e=>{console.error(`OAuth provider auth failed:`,e),f(!1)}});return l?t(fO,{className:`size-4`}):s?.authenticated?n(`div`,{className:`flex items-center gap-2`,children:[n(`div`,{className:`flex items-center gap-1 text-success text-sm`,children:[t(Lh,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.connected`)})]}),t(sT,{variant:`outline`,size:`sm`,onClick:async()=>{if(!p)try{m(!0),await a.oauthProviders.disconnect(r),await h(),i?.()}catch(e){console.error(`Failed to disconnect OAuth provider:`,e)}finally{m(!1)}},disabled:p,children:p?t(fO,{className:`size-3`}):o(`oauthProvider.disconnect`)})]}):t(sT,{variant:`outline`,size:`sm`,onClick:async()=>{if(!d)try{f(!0);let e=await a.oauthProviders.authorize(r);e.authorization_url&&g(e.authorization_url)}catch(e){console.error(`Failed to authorize OAuth provider:`,e),f(!1)}},disabled:d,children:d?n(e,{children:[t(fO,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.authenticating`)})]}):n(e,{children:[t(Og,{className:`size-4 me-1`}),t(`span`,{children:o(`oauthProvider.authenticate`)})]})})}function U0(...e){let t=Array.from(e);return t.__AnyOf__=!0,t}function W0(...e){return Array.from(e)}function G0(e){return e.__AnyOf__===!0}var K0=class{system_roles;roles;permissions;constructor(e,t=[]){this.system_roles=t;let n=[...e.account_roles||[],...e.project_roles||[]],r=new Set(n);this.roles=r;let i=e.permissions??q0(n,t),a=e.type===xn.OAuthAccess?new Set(e.permissions??[]):void 0;this.permissions=new Set(a?i.filter(e=>a.has(e)):i)}hasPermission(e){if(typeof e==`string`)return this.permissions.has(e);if(G0(e))return e.some(e=>this.permissions.has(e));for(let t of e)if(!this.permissions.has(t))return!1;return!0}};function q0(e,t){let n=new Map(t.map(e=>[e.name,e.permissions])),r=new Set;for(let t of e)for(let e of n.get(t)??[])r.add(e);return Array.from(r)}const J0=dt(void 0);function Y0(){let e=_t(J0);if(!e)throw Error(`UserPermissionContext cannot be used outside UserPermissionProvider`);return e}function X0({children:e}){let{t:n}=K(),r=q(),i=r.authToken,a=!!(i&&!i.permissions),{data:o,error:s,isLoading:c}=Ye(()=>a?r.client.iam.roles.listSystem():Promise.resolve(void 0),[r.client,i,a]),l=U(()=>{if(i){if(i.permissions||!a)return new K0(i);if(o&&!c)return new K0(i,o)}else return},[i,o,c,a]);return s?t(M,{title:n(`store.failedToFetchRoleMappings`),children:Ge(s)}):l&&t(J0.Provider,{value:l,children:e})}function Z0({permission:e,isDisabled:n,title:r,children:i,...a}){return Y0().hasPermission(e)?t(o,{isDisabled:n,title:r,...a,children:i}):null}function Q0({permission:e,...n}){return Y0().hasPermission(e)?t(or,{...n}):null}const $0=new WeakMap;function e2(e,t){let n=$0.get(e);n||(n=new Map,$0.set(e,n));let r=n.get(t);return r||(r=e.types.catalog.resolve(t).then(e=>e??void 0,()=>{$0.get(e)?.delete(t)}),n.set(t,r)),r}function t2(e,t){let n=$0.get(e);n&&(t?n.delete(t):n.clear())}Q();function n2(e){let t=e.configuration?.defaults?.system?.agent??e.configuration?.defaults?.base;return{environment:t?.environment,model:t?.model}}function r2(e){return e.name}function i2(e){return e.name}function a2(e){return e.split(`/`).filter(Boolean).pop()||e}function o2({value:e,onChange:r,disabled:i=!1,isLoading:a=!1}){let{client:s}=q(),{t:c}=K(),[l,u]=G([]),[d,f]=G([]),[p,m]=G(!0),[h,g]=G(!1),_=W(void 0);H(()=>{let e=!1;return m(!0),s.environments.list().then(t=>{e||u(t.slice().sort((e,t)=>e.name.localeCompare(t.name)))}).catch(t=>{console.warn(`Failed to list document editing environments`,t),e||u([])}).finally(()=>{e||m(!1)}),()=>{e=!0}},[s]),H(()=>{if(!e.environment){f([]),g(!1);return}let t=!1,n=e.environment;return g(!0),s.environments.retrieve(n).then(e=>{t||f((e.enabled_models??[]).map(e=>({id:e.id,name:e.name||e.id})).sort((e,t)=>e.name.localeCompare(t.name)))}).catch(e=>{console.warn(`Failed to load document editing models`,e),t||f([])}).finally(()=>{t||g(!1)}),()=>{t=!0}},[s,e.environment]);let v=l.find(t=>t.id===e.environment),y=U(()=>{if(e.model)return d.find(t=>t.id===e.model)??{id:e.model,name:a2(e.model)}},[d,e.model]),b=e=>{_.current=e.id,r({environment:e.id}),s.environments.retrieve(e.id).then(t=>{if(_.current!==e.id)return;let n=t.default_model??t.enabled_models?.[0]?.id;r({environment:e.id,model:n})}).catch(e=>{console.warn(`Failed to select a default document editing model`,e)})},x=t=>{_.current=void 0,r({environment:e.environment,model:t.id})},S=y?.name||c(`agent.documentEditingSelectModel`);return n(he,{children:[t(_e,{asChild:!0,children:n(o,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 max-w-[15rem] gap-1.5 px-2 text-xs`,"aria-label":c(`agent.documentEditingConfiguration`),title:c(`agent.documentEditingConfiguration`),children:[a?t(je,{size:`sm`}):t(Ky,{className:`size-3.5 shrink-0`}),t(`span`,{className:`min-w-0 truncate`,children:S}),t(ih,{className:`size-3.5 shrink-0 opacity-70`})]})}),n(ge,{align:`end`,className:`z-[1000000] w-80 space-y-3 p-3`,children:[n(`div`,{children:[t(`div`,{className:`text-sm font-semibold text-foreground`,children:c(`agent.documentEditingConfiguration`)}),t(`div`,{className:`mt-0.5 text-xs leading-4 text-muted`,children:c(i?`agent.documentEditingConfigurationLocked`:`agent.documentEditingConfigurationDescription`)})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-environment`,children:c(`agent.environment`)}),t(we,{id:`document-editing-environment`,by:`id`,options:l,value:v,optionLabel:r2,filterBy:`name`,placeholder:c(`agent.documentEditingSelectEnvironment`),onChange:b,disabled:i,isLoading:p})]}),n(`div`,{className:`space-y-1`,children:[t(`label`,{className:`text-xs font-medium text-foreground`,htmlFor:`document-editing-model`,children:c(`agent.model`)}),t(we,{id:`document-editing-model`,by:`id`,options:d,value:y,optionLabel:i2,filterBy:`name`,placeholder:c(`agent.documentEditingSelectModel`),onChange:x,disabled:i||!e.environment,isLoading:h,warnOnMissingValue:!1})]})]})]})}Q();function s2({isLocked:e,onToggleLock:r}){let{t:i}=K(),a=i(e?`agent.editingLockedTitle`:`agent.editingManuallyUnlockedTitle`),s=i(e?`agent.editingLockedDescription`:`agent.editingManuallyUnlockedDescription`),c=i(e?`agent.unlockEditing`:`agent.lockEditing`);return n(`div`,{className:`flex h-8 max-w-64 shrink-0 items-center gap-1 rounded-md border border-mixer-attention/30 bg-mixer-attention/10 ps-2 pe-1 text-attention`,role:e?`status`:`alert`,"aria-live":`polite`,children:[e?t(iv,{className:`size-3.5 shrink-0 animate-pulse`}):t(sv,{className:`size-3.5 shrink-0`}),t(We,{description:s,asChild:!0,children:t(`span`,{className:`min-w-0 truncate text-xs font-medium text-foreground`,children:a})}),t(`span`,{className:`sr-only`,children:s}),t(We,{description:c,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`size-6 shrink-0 rounded p-0 text-attention hover:bg-mixer-attention/15`,onClick:r,"aria-label":c,children:t(e?sv:iv,{className:`size-3.5`})})})]})}const c2=/artifact:(?!agents\/)(?!documents\/)([^\s)\]"]+)/g;function l2(e){let t=new Set;for(let n of e.matchAll(c2))t.add(n[1].replace(/^\/+/,``));return[...t]}async function u2(e,t,n,r){let i=l2(t);if(i.length===0)return{content:t,persisted:[],failed:[]};let a=new Map,o=[],s=[];for(let t of i){let i=`documents/${r}/${t}`;try{await e.copyFile(`agents/${n}/${t}`,i),a.set(t,i),o.push({from:t,to:i})}catch(e){console.warn(`Failed to persist a referenced artifact; keeping a run-scoped link`,{artifact_path:t,error:e instanceof Error?e.message:String(e)}),a.set(t,`agents/${n}/${t}`),s.push(t)}}return{content:t.replace(c2,(e,t)=>{let n=a.get(t.replace(/^\/+/,``));return n?`artifact:${n}`:e}),persisted:o,failed:s}}const d2=[`ask_user`,`think`,`plan`,`update_plan`,`end_conversation`,`learn_artifact_operations`,`learn_code_execution`,`learn_content_authoring`,`learn_document_management`,`learn_document_search`,`learn_image_analysis`,`execute_shell`,`fetch_document`],f2=[`artifact_operations`,`code_execution`],p2=[`update_document`,`update_document_properties`,`create_document`,`set_document_type`,`merge_documents`,`import_file`,`create_or_update_object_type`,`disable_type`,`batch_execute`];function m2(e,t){return[`Direct edits are already saved to '${e}'. Use this compact unified diff as context only;`,`do not re-apply it. The artifact remains the current source of truth.`,"```diff",`--- a/${e}`,`+++ b/${e}`,t,"```"].join(`
1385
+ `)}const h2=`document-editing`,g2=`sys:GeneralAgent`,_2=new Set,v2=new Set([`text/markdown`,`text/x-markdown`]),y2=new Set([...v2,`text/plain`]);function b2(e,t){return`${e}:${t}`}function x2(e){return _2.has(e)}function S2(e,t){t?_2.add(e):_2.delete(e)}function C2(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function w2(e){return`document-root:${e}`}function T2(e){return`document:${e}`}function E2(e,t){return{tags:[h2,w2(t),T2(e)],properties:{resource_kind:`store_document`,document_id:e,document_root_id:t}}}function D2(e,t){return{canEdit:e,canCollaborate:t}}function O2(e){return e?.split(`;`,1)[0]?.trim().toLowerCase()||void 0}function k2(e){let t=O2(e);return t!==void 0&&v2.has(t)}function A2(e){let t=O2(e);return t!==void 0&&y2.has(t)}function j2(e,t,n,r,i=g2){if(e.interaction!==i||e.started_by!==r||e.status===`cancelled`)return!1;let a=e.tags??[];if(!a.includes(h2))return!1;let o=C2(e.properties);return a.includes(w2(n))?o?.resource_kind===`store_document`&&o.document_root_id===n:a.includes(T2(n))||a.includes(T2(t))}async function M2(e,t,n,r,i,a){for(let o of t)try{let t=await e.retrieve(o);if(j2(t,n,r,i,a))return t}catch{}}async function N2(e,t,n,r,i=g2){let a=[w2(n),T2(n),T2(t)],o=new Set;for(let s of new Set(a))try{let a=(await e.search({interaction:i,started_by:r,tags:[s],limit:20,sort:[`updated_at:desc`]})).hits.map(e=>e.id).filter(e=>!o.has(e));for(let e of a)o.add(e);let c=await M2(e,a,t,n,r,i);if(c)return c}catch{break}return(await e.list({interaction:i,started_by:r,limit:100,sort:`updated_at`,order:`desc`})).items.find(e=>e.run_kind===`agent`&&j2(e,t,n,r,i))}var P2=class extends Error{constructor(e,t){super(e,t===void 0?void 0:{cause:t}),this.name=`DocumentEditingTargetError`}};async function F2(e,t){let n=await e.retrieve(t),r=n;if(n.revision&&!n.revision.head){let i=(await e.getRevisions(n.id)).filter(e=>e.revision?.head===!0);if(i.length!==1)throw new P2(`Expected one head revision for document ${t}, found ${i.length}`);if(r=await e.retrieve(i[0].id),r.revision?.head!==!0)throw new P2(`Resolved document ${r.id} is no longer the current head`)}let i=r.content?.etag;if(!i)throw new P2(`Document ${r.id} has no content ETag`);let a=await e.getObjectText(r.id);if(typeof a.text!=`string`)throw new P2(`Document ${r.id} has no text content`);return{id:r.id,etag:i,content:a.text}}var I2=class extends be{idOf(e){return e.id}labelOf(e){return e.label}descriptionOf(e){return e.description}selectedClassName(e){return`border-3 border-primary`}};function L2({isOpen:e,onClose:r,onConfirm:i,isLoading:a,uploadedFileName:s}){let{t:c}=K(),l=U(()=>[{id:`update`,label:c(`modal.saveVersion.updateCurrent`),description:c(s?`modal.saveVersion.updateWithFileDescription`:`modal.saveVersion.updateDescription`)},{id:`new-version`,label:c(`modal.saveVersion.createNew`),description:c(s?`modal.saveVersion.createWithFileDescription`:`modal.saveVersion.createDescription`)}],[c,s]),u=s?l[1]:l[0],[d,f]=G(u),[p,m]=G(``),h=new I2;H(()=>{e&&(f(u),m(``))},[u,e]);let g=d?.id===`new-version`;return n(se,{isOpen:e,onClose:r,className:`sm:max-w-md`,children:[t(ue,{children:c(`modal.saveChanges`)}),t(ce,{children:n(`div`,{className:`space-y-4`,children:[s&&t(`div`,{className:`mb-4 p-3 bg-blue-50 dark:bg-blue-900/20 rounded-md`,children:n(`p`,{className:`text-sm text-blue-700 dark:text-blue-300 font-medium`,children:[c(`modal.saveVersion.replaceFile`),` `,t(`span`,{className:`font-bold`,children:s})]})}),t(`p`,{className:`text-sm text-mixer-muted/5`,children:c(`modal.saveVersion.howToSave`)}),t(ye,{adapter:h,options:l,selected:d,onSelect:e=>{f(e)}}),g&&t(L,{label:c(`modal.saveVersion.versionLabel`),description:c(`modal.saveVersion.versionLabelDescription`),className:`mt-3 ps-8`,children:t(te,{value:p,onChange:m,placeholder:c(`modal.saveVersion.versionLabelPlaceholder`),className:`w-full`})})]})}),n(le,{children:[t(o,{variant:`secondary`,onClick:r,disabled:a,children:c(`modal.cancel`)}),t(o,{variant:`primary`,onClick:async()=>{await i(g,g?p:void 0)},isLoading:a,children:c(`modal.save`)})]})]})}Q();function R2(e){return e.length>12?`${e.slice(0,4)}…${e.slice(-4)}`:e}function z2(e){return`drafts/${e}.md`}function B2(e,t,n,r,i){return[`You are collaborating with the user on one specific Markdown document in Vertesia.`,`Canonical document: [${e.name||e.content?.name||`Document`}](store:${t})`,`Canonical base revision ID: ${t}`,`Canonical base ETag: ${n??`unavailable`}`,`Working copy artifact: ${r}`,``,`The working copy was hydrated and read before your first turn. It is the source of truth for this editing`,`session. Apply requested changes only to that artifact using edit_artifact. Preserve all unrelated content`,`exactly. User block edits may already be applied to the artifact; acknowledge them and continue from the`,`current artifact generation. Attachments may contain review comments to apply in bulk.`,``,`Do not call update_document, create_document, or write_artifact for this working copy. The user publishes`,`the artifact back to the canonical document with the Save to document button, which enforces the base ETag.`,``,`You may use execute_shell to regenerate charts, diagrams, and other derived assets. Write generated files`,`under '/home/daytona/out/' so they sync back to the run, then reference them from Markdown with a run-local`,`link such as 'artifact:out/chart.png'. Saving the document persists and rewrites those links automatically.`,``,`Images: never inline image data as base64 data URIs — it bloats the document and cannot be reliably edited.`,`Keep existing image references (e.g. 'artifact:documents/…' URLs) exactly as they are: they point to durable`,`storage that outlives this session. Files already in this run's artifact space may be referenced with`,`run-local links like 'artifact:files/photo.png' — publishing copies them into durable storage and rewrites`,`the links automatically.`,``,`User request: ${i}`].join(`
1386
+ `)}function V2(e,t,n){return[`The canonical document was updated outside this session, so publishing the working copy was rejected.`,`1) Fetch the latest canonical revision ${t} with fetch_document into 'drafts/${e}.theirs.md'.`,`2) Compare it with the working copy '${n}' and merge the external changes into the working copy with edit_artifact, preserving this session's edits.`,`3) Reply with a short list of what was merged, plus any conflicting passages and how you resolved them, so I can review before saving again.`].join(`
1387
+ `)}function H2(e,t,n){return[`Summarize the changes in the working copy '${n}' relative to the original document revision ${t}.`,`If you no longer have the original content, fetch it with fetch_document into 'drafts/${e}.base.md'.`,`Do not modify the working copy.`,`Reply with a concise changelog: grouped bullets, most important first, suitable for a revision note.`].join(`
1388
+ `)}function U2(e){if(!(!e||typeof e!=`object`||!(`status`in e)))return typeof e.status==`number`?e.status:void 0}function W2({original:e,workingCopy:r}){let i=U(()=>Vt(e,r),[e,r]),a=U(()=>({added:i.reduce((e,t)=>e+(t.type===`added`?t.text.length:0),0),removed:i.reduce((e,t)=>e+(t.type===`removed`?t.text.length:0),0)}),[i]);return n(`div`,{className:`flex h-full min-h-0 flex-col bg-muted/10`,children:[n(`div`,{className:`flex shrink-0 items-center justify-end gap-3 border-b border-mixer-muted/20 px-5 py-2 text-xs`,children:[n(`span`,{className:`text-destructive`,children:[`−`,a.removed]}),n(`span`,{className:`text-success`,children:[`+`,a.added]})]}),t(`div`,{className:`min-h-0 flex-1 overflow-auto p-5`,children:t(`pre`,{className:`mx-auto max-w-5xl whitespace-pre-wrap break-words rounded-lg border border-mixer-muted/25 bg-background p-5 font-mono text-xs leading-6 shadow-sm`,children:i.map((e,n)=>e.type===`removed`?t(`del`,{className:`bg-mixer-destructive/15 text-destructive line-through decoration-destructive/50`,children:e.text},n):e.type===`added`?t(`ins`,{className:`bg-mixer-success/15 text-success no-underline`,children:e.text},n):t(`span`,{children:e.text},n))})})]})}function G2({object:r,initialContent:i=``,onDocumentUpdated:a,onClose:s,sendMessageRef:c,model:l,startImmediately:u=!1}){let{client:d,project:f,store:m,user:h}=q(),{t:g}=K(),_=nt(),v=W(null),y=c??v,[x,S]=G(),[C,w]=G(!1),[T,E]=G(!1),[D,O]=G(!0),[k,A]=G(!0),[j,M]=G(!1),[N,P]=G(0),[F,I]=G(!1),L=JSON.stringify(l?{environment:l.env,model:l.model,model_options:l.options}:{}),ee=l!==void 0,R=U(()=>JSON.parse(L),[L]),[te,ne]=G(!ee),[re,ie]=G(!1),[ae,oe]=G(!1),[se,ce]=G(!1),[le,ue]=G(!1),[de,fe]=G(!1),[pe,me]=G(!1),[he,ge]=G({key:0}),[_e,ve]=G(i),[ye,be]=G(!1),[we,Te]=G(i),[Ee,De]=G(i),[Oe,ke]=G(`document`),[Ae,Me]=G(),[Ne,Pe]=G(r.id),[Fe,Ie]=G(r.content?.etag),[Le,Re]=G(),[ze,Be]=G(R),Ve=W(ee?`host`:`none`),He=W(void 0),Ue=W(new Set),z=W(void 0),Ke=W(!1),qe=W(null),Je=r.revision?.root||r.id,Ye=U(()=>z2(Je),[Je]),Xe=h?.sub?`user:${h.sub}`:void 0,Ze=`${f?.id??`no-project`}:${Je}`,Qe=`${Ze}:${r.type?.id??`no-type`}`,$e=Le?.key===Qe?Le.interaction:void 0,et=W(Ze),tt=W({editingScopeKey:Ze,id:r.id}),rt=W({documentId:r.id,documentRootId:Je}),it=ye&&_e!==Ee,at=le&&!de;rt.current.documentRootId!==Je&&(rt.current={documentId:r.id,documentRootId:Je}),tt.current.editingScopeKey!==Ze&&(tt.current={editingScopeKey:Ze,id:r.id}),H(()=>{et.current!==Ze&&(et.current=Ze,Ve.current=ee?`host`:`none`,Be(R),ne(!ee),Ue.current.clear(),ve(i),Te(i),De(i),be(!1),me(!1),ue(!1),fe(!1),Ke.current=!1,ke(`document`),Pe(r.id),Ie(r.content?.etag))},[Ze,ee,i,r.content?.etag,r.id,R]),H(()=>{let e=!1,t=Ze,n=tt.current.id;return A(!0),M(!1),F2(m.objects,n).then(n=>{e||tt.current.editingScopeKey!==t||(tt.current={editingScopeKey:t,id:n.id},rt.current={documentId:n.id,documentRootId:Je},Pe(n.id),Ie(n.etag),Te(n.content),De(n.content))}).catch(n=>{console.warn(`Failed to resolve the document editing target`,{error:n,attempt:N}),!e&&tt.current.editingScopeKey===t&&M(!0)}).finally(()=>{!e&&tt.current.editingScopeKey===t&&A(!1)}),()=>{e=!0}},[Je,Ze,m.objects,N]),H(()=>{let e=!1,t=r.type?.id;if(!t){Re({key:Qe,interaction:g2});return}return e2(d,t).then(t=>{e||Re({key:Qe,interaction:t?.editing?.interaction?.trim()||`sys:GeneralAgent`})}),()=>{e=!0}},[d,Qe,r.type?.id]),H(()=>{x||Ve.current===`run`||(ee?(Ve.current=`host`,Be(R),ne(!1)):Ve.current===`host`&&(Ve.current=`none`,Be({})))},[x,ee,R]),H(()=>{if(ee){ne(!1);return}if(!f){ne(!1);return}let e=!1,t=Ze;return ne(!0),d.projects.retrieve(f.id).then(n=>{e||et.current!==t||Ve.current!==`none`||(Ve.current=`project`,Be(n2(n)))}).catch(e=>{console.warn(`Failed to load the default document editing model`,e)}).finally(()=>{e||ne(!1)}),()=>{e=!0}},[d,Ze,ee,f]),H(()=>{if(S(void 0),!Xe||!$e){O(!1);return}let e=!1;return O(!0),N2(d.agents,rt.current.documentId,Je,Xe,$e).then(t=>{e||!t||(S(t.id),t.config?.environment&&t.config.model&&(Ve.current=`run`,Be({environment:t.config.environment,model:t.config.model,model_options:t.config.model_options})))}).catch(e=>{console.warn(`Failed to look up an existing document editing run`,e)}).finally(()=>{e||O(!1)}),()=>{e=!0}},[d,Je,$e,Xe]);let B=V(e=>{Ve.current=`user`,Be(e)},[]),ot=V(()=>{x&&navigator.clipboard.writeText(x).then(()=>_({status:`success`,title:g(`agent.runIdCopied`),duration:2e3})).catch(e=>console.warn(`Failed to copy the agent run id`,e))},[x,g,_]),st=V(async()=>{if(!(!x||T)){E(!0);try{await d.agents.terminate(x,`cancel`),_({status:`success`,title:g(`agent.workflowCancelled`),duration:2e3})}catch(e){console.warn(`Failed to terminate the document editing run`,e)}finally{E(!1)}Ue.current.clear(),S(void 0),be(!1),ve(Ee),me(!1),Ke.current=!1,ue(!1),fe(!1)}},[x,d.agents,T,Ee,g,_]),ct=V(async(e,t)=>{if(!(!f||!$e||D||k||j||C||te)){w(!0);try{if(!ze.environment||!ze.model){_({status:`error`,title:g(`agent.documentEditingDefaultsRequired`),duration:5e3});return}let n=B2(r,Ne,Fe,Ye,e?.trim()||g(`agent.documentEditingInitialRequest`)),i=E2(Ne,Je),a={interaction:$e,interactive:!0,tool_approval_mode:t?.tool_approval_mode,tool_names:d2,excluded_tools:p2,initial_skills:f2,initial_tool_calls:[{id:`hydrate-working-copy`,tool:`fetch_document`,input:{id:Ne,mode:`content`,output_artifact:{path:Ye}}},{id:`read-working-copy`,tool:`read_artifact`,input:{path:Ye}}],data:{user_prompt:n},config:{environment:ze.environment,model:ze.model,model_options:ze.model_options},started_by:Xe,tags:i.tags,properties:i.properties},o=await d.agents.start(a);return S(o.id),{agent_run_id:o.id}}catch(e){console.error(`Failed to start document editing agent`,e),_({status:`error`,title:g(`agent.documentEditingStartFailed`),description:e instanceof Error?e.message:void 0,duration:5e3});return}finally{w(!1)}}},[d.agents,Je,Ye,ze,$e,te,D,k,C,r,f,Xe,g,Ne,Fe,j,_]),lt=V((e,t)=>{z.current=t,ve(e),be(!0)},[]);H(()=>{if(!u||x||!f||!$e||D||k||j||C||te||!ze.environment||!ze.model)return;let e=JSON.stringify({scope:Ze,interaction:$e,document:Ne,configuration:ze});He.current!==e&&(He.current=e,ct(g(`agent.documentEditingStartRequest`),{tool_approval_mode:`full_control`}))},[x,$e,Ze,ze,te,D,k,C,f,u,ct,g,Ne,j]);let ut=V(e=>{let t=Ke.current;Ke.current=e,ue(e),e||(fe(!1),t&&ge(e=>({key:e.key+1})))},[]),dt=V((e,t)=>{let n=y.current;if(!n){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}n(e,t)},[y,g,_]),ft=V(e=>{let t=e.anchor.block_type.replaceAll(`_`,` `),n=e.comment?.trim()||g(`agent.editedSelectionMessage`,{blockType:t});dt(n,{editing_action:e})},[dt,g]),pt=V(async(e,t)=>{if(!(!ye||!Fe||!it||at||re||k||j)){ie(!0);try{let n=_e;x&&(n=(await u2(d.files,n,x,crypto.randomUUID())).content);let i=r.content?.type||`text/markdown`,o=r.content?.name||`content.md`,s=new File([new Blob([n],{type:i})],o,{type:i}),c=await m.objects.update(Ne,{content:s},{createRevision:e,revisionLabel:t,ifMatch:Fe});if(Pe(c.id),Ie(c.content?.etag),De(n),Me(void 0),oe(!1),a?.(c.id,e),_({status:`success`,title:g(`store.textSaved`),duration:2500}),x&&n!==_e&&z.current)try{await d.agents.updateArtifactContent(x,Ye,{content:n,generation:z.current}),ge(e=>({key:e.key+1}))}catch(e){console.warn(`Failed to sync persisted artifact links into the working copy`,e)}}catch(e){let t=U2(e),n=t===412;if(t===412||t===400)try{let e=await F2(m.objects,Ne);(e.id!==Ne||t===412)&&(n=!0,Pe(e.id),Ie(e.etag),Me({headId:e.id}))}catch(e){console.warn(`Failed to resolve the new head after a save conflict`,e)}_({status:`error`,title:g(`store.errorSavingText`),description:n?g(`store.textConflict`):Ge(e,g(`store.errorSavingTextDefault`)),duration:5e3})}finally{ie(!1)}}},[x,_e,ye,d.agents,d.files,Ye,it,at,k,re,r.content?.name,r.content?.type,a,m.objects,g,Ne,Fe,j,_]),mt=V(()=>{let e=y.current;if(!e||!Ae){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(V2(Je,Ae.headId,Ye)),Me(void 0),ke(`document`)},[Je,Ye,y,Ae,g,_]),ht=V(()=>{let e=y.current;if(!e){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}e(H2(Je,tt.current.id,Ye))},[Je,Ye,y,g,_]),gt=V(async()=>Oe!==`editor`||!pe||!!await qe.current?.(),[pe,Oe]),_t=V(async e=>{e!==Oe&&await gt()&&ke(e)},[gt,Oe]),vt=V(async()=>{await gt()&&s?.()},[gt,s]),yt=V(async()=>{let e=y.current;if(!e||!x||at||se){_({status:`warning`,title:g(`agent.artifactEditingUnavailable`),duration:3e3});return}ce(!0);try{let t=await qe.current?.();if(!t)return;let n=Bt(t.previous,t.current,{context:1});n&&e(m2(Ye,n)),me(!1),_({status:`success`,title:g(`agent.changesSentToAgent`),duration:2e3})}finally{ce(!1)}},[x,Ye,at,se,y,g,_]);return n(`div`,{className:`flex h-full min-h-0 flex-col`,children:[n(`div`,{className:`flex h-14 shrink-0 items-center justify-between gap-3 border-b border-mixer-muted/20 px-4`,children:[n(`div`,{className:`min-w-0`,children:[t(`div`,{className:`truncate font-semibold`,children:r.name||r.content?.name}),n(`div`,{className:`flex items-center gap-2 text-xs text-muted`,children:[n(`span`,{className:`flex shrink-0 items-center gap-1.5`,children:[it?t(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full bg-attention`}):ye?t(th,{className:`size-3 text-success`}):null,g(it?`store.unsavedChanges`:`store.textSaved`)]}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(We,{description:`${g(`agent.workingCopy`)}: ${Ye}`,asChild:!0,children:n(`span`,{className:`min-w-0 truncate font-mono`,children:[`drafts/`,R2(Je),`.md`]})}),t(`span`,{"aria-hidden":!0,className:`text-mixer-muted/60`,children:`·`}),t(We,{description:`${g(`agent.originalDocument`)}: ${tt.current.id}`,asChild:!0,children:n(`span`,{className:`shrink-0 font-mono`,children:[g(`agent.originalDocument`).toLowerCase(),` `,R2(tt.current.id)]})})]})]}),n(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[n(`div`,{className:`flex items-center rounded-md border border-mixer-muted/25 bg-muted/10 p-0.5`,children:[n(o,{variant:Oe===`document`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void _t(`document`),children:[t(Kg,{className:`size-3.5`}),g(`agent.document`)]}),n(o,{variant:Oe===`editor`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void _t(`editor`),children:[t(Bg,{className:`size-3.5`}),g(`agent.fullEditor`)]}),n(o,{variant:Oe===`diff`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:()=>void _t(`diff`),disabled:!ye||_e===we,children:[t(g_,{className:`size-3.5`}),g(`agent.reviewChanges`)]})]}),Oe===`diff`?n(o,{variant:`ghost`,size:`sm`,className:`h-8 gap-1.5`,onClick:ht,disabled:!ye||_e===we,children:[t(Q_,{className:`size-3.5`}),g(`agent.summarizeChanges`)]}):null,t(We,{description:g(`agent.refresh`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>ge(e=>({key:e.key+1})),disabled:!x,"aria-label":g(`agent.refresh`),children:t(gy,{className:`size-4`})})}),t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),t(o2,{value:ze,onChange:B,disabled:!!x||C||D,isLoading:te}),x?null:n(o,{variant:`primary`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>void ct(g(`agent.documentEditingStartRequest`)),disabled:C||D||k||te||j||!f||!$e||!ze.environment||!ze.model,children:[C?t(je,{size:`sm`}):t(Yy,{className:`size-4`}),g(C?`agent.startingAgent`:`agent.documentEditingStart`)]}),x?n(e,{children:[t(We,{description:x,asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,className:`font-mono text-[11px] text-muted`,onClick:ot,"aria-label":g(`agent.copyRunId`),children:R2(x)})}),t(We,{description:g(`agent.startNewConversation`),asChild:!0,children:t(o,{variant:`ghost`,size:`sm`,onClick:()=>{it?I(!0):st()},disabled:T,"aria-label":g(`agent.startNewConversation`),children:t(yy,{className:`size-4`})})})]}):null,t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),n(o,{variant:`primary`,className:`min-w-36 gap-2`,onClick:()=>oe(!0),disabled:!it||!Fe||at||re||k||j,children:[re?t(je,{size:`sm`}):t(Ty,{className:`size-4`}),g(`agent.saveToDocument`)]}),s?t(o,{variant:`ghost`,size:`sm`,onClick:()=>void vt(),"aria-label":g(`agent.close`),children:t(Kb,{className:`size-4`})}):null]})]}),Ae?n(`div`,{className:`flex shrink-0 items-center justify-between gap-3 border-b border-mixer-attention/30 bg-mixer-attention/10 px-4 py-2 text-sm`,children:[t(`span`,{className:`min-w-0 truncate text-attention`,children:g(`agent.saveConflictNotice`)}),n(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t(o,{variant:`outline`,size:`sm`,onClick:mt,children:g(`agent.askAgentToReconcile`)}),t(o,{variant:`ghost`,size:`sm`,onClick:()=>Me(void 0),"aria-label":g(`agent.close`),children:t(Kb,{className:`size-4`})})]})]}):null,n(Ce,{direction:`horizontal`,className:`min-h-0 flex-1`,children:[t(Se,{defaultSize:65,minSize:35,className:`min-w-0 bg-background`,children:t(`div`,{className:`flex h-full min-h-0 flex-col`,children:t(`div`,{className:`min-h-0 flex-1`,children:Oe===`diff`?t(W2,{original:we,workingCopy:_e}):t(wt,{runId:x,path:Ye,viewMode:Oe===`editor`?`document`:`components`,baselineContent:we,initialContent:Ee,refreshKey:he.key,refreshDetails:he.details,readOnly:at,allowComments:!!x,onContentChange:lt,onAction:ft,onSendMessage:dt,onSendChangesToAgent:yt,hasUnsentChanges:it&&pe,isSendingChanges:se,sendChangesDisabled:!x||at,toolbarStatus:le?t(s2,{isLocked:at,onToggleLock:()=>fe(e=>!e)}):void 0,onDocumentEdit:()=>me(!0),flushChangesRef:qe})})})}),t(xe,{withHandle:!0}),t(Se,{defaultSize:35,minSize:25,className:`min-w-[320px]`,children:D||k?t(p,{className:`h-full`,children:t(je,{size:`lg`})}):j?n(p,{className:`h-full flex-col gap-3 px-6 text-center`,children:[t(`div`,{className:`text-sm text-muted`,children:g(`agent.failedToLoadDocument`)}),t(o,{variant:`outline`,size:`sm`,onClick:()=>P(e=>e+1),children:g(`agent.retry`)})]}):t(A1,{agentRunId:x,startWorkflow:ct,resetWorkflow:()=>S(void 0),onRestart:e=>S(e.id),sendMessageRef:y,onMessage:e=>{let t=e.details;if(!Ut(t,Ye))return;let n=`${e.timestamp}:${t?.path}:${t?.generation??``}`;Ue.current.has(n)||(Ue.current.add(n),ge(e=>({key:e.key+1,details:t})))},onAgentWorkingChange:ut,title:g(`agent.documentEditing`),initialMessage:g(`agent.documentEditingWelcome`),startButtonText:g(C?`agent.startingAgent`:`agent.startAgent`),placeholder:g(`agent.documentEditingPlaceholder`),initialToolApprovalMode:`full_control`,hideObjectLinking:!0,hideHeader:!0,showRightPanel:!1,fullWidth:!0,interactive:!0})})]}),t(b,{isOpen:F,title:g(`agent.newSessionDiscardTitle`),content:g(`agent.newSessionDiscardDescription`),onConfirm:()=>{I(!1),st()},onCancel:()=>I(!1)}),t(L2,{isOpen:ae,onClose:()=>oe(!1),onConfirm:pt,isLoading:re})]})}function K2({object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s}){let{t:c}=K();return t(se,{isOpen:!0,onClose:r,size:`full`,noCloseButton:!0,disableCloseOnClickOutside:!0,className:`gap-0 overflow-hidden p-0`,description:c(`agent.documentEditingWelcome`),children:t(G2,{object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s})})}function q2({isOpen:r,onClose:i,object:a,refetch:s}){let{client:c,store:l}=q(),u=nt(),{t:d}=K(),{theme:f}=tt(),p=$n(),[m,h]=G(!1),[g,_]=G(``),[v,y]=G(!1),[b,x]=G(null),S=W(void 0),[C,w]=G(null),[T,E]=G(null),D=V(async e=>{try{let t=await l.types.retrieve(e);t.object_schema&&w(t.object_schema)}catch(e){console.error(`Failed to fetch JSON schema:`,e)}},[l.types]);H(()=>{r&&(_(JSON.stringify(a.properties||{},null,2)),a.type?.id&&D(a.type.id))},[r,a,D]);let O=e=>{C&&e.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:`http://myserver/object-schema.json`,fileMatch:[`*`],schema:C}]})};function k(){if(!S.current)return;let e=S.current.getValue();try{let t=JSON.parse(e);x(t),y(!0)}catch{u({status:`error`,title:d(`store.invalidJson`),description:d(`store.pleaseFixJsonSyntax`),duration:5e3})}}let A=e=>{_(e)};async function j(e,t){try{h(!0);let n=b||JSON.parse(g);if(e){let e=await c.objects.update(a.id,{properties:n},{createRevision:!0,revisionLabel:t});e.id!==a.id&&E(e.id),u({status:`success`,title:d(`store.newVersionCreated`),description:d(`store.newVersionCreatedDesc`),duration:2e3}),y(!1),i(),e.id!==a.id&&setTimeout(()=>{p(`/objects/${e.id}`),u({status:`info`,title:d(`store.viewingNewVersion`),description:t?d(`store.viewingVersionLabel`,{label:t}):d(`store.viewingNewVersionDefault`),duration:3e3})},100)}else await l.objects.update(a.id,{properties:n}),u({status:`success`,title:d(`store.propertiesUpdated`),description:d(`store.propertiesUpdatedDesc`),duration:2e3}),s&&await s(),y(!1),i()}catch(e){u({status:`error`,title:d(`store.errorUpdatingProperties`),description:Ge(e,d(`store.errorUpdatingPropertiesDefault`)),duration:5e3}),h(!1)}}function M(){y(!1)}return n(e,{children:[n(se,{isOpen:r,onClose:i,className:`sm:max-w-[90%] md:max-w-[80%] lg:max-w-[75%] xl:max-w-[70%]`,children:[t(ue,{children:d(`store.editProperties`)}),n(ce,{children:[n(`div`,{className:`mb-2 text-sm text-gray-500`,children:[a.type?.name?n(`span`,{children:[`Editing properties for object type: `,t(`strong`,{children:a.type.name})]}):t(`span`,{children:d(`store.editingGenericDocument`)}),C!==null&&t(`span`,{className:`ms-2 text-green-600`,children:`(JSON schema validation enabled)`})]}),t(`div`,{className:`h-[75vh] border rounded-md overflow-hidden`,children:t(Pt,{value:g,language:`json`,editorRef:S,onChange:e=>A(e.state.doc.toString()),beforeMount:O,theme:f===`dark`?`vs-dark`:`vs`})})]}),n(le,{children:[t(o,{variant:`secondary`,onClick:i,children:`Cancel`}),t(o,{variant:`primary`,onClick:k,children:`Save Changes`})]})]}),t(L2,{isOpen:v,onClose:M,onConfirm:j,isLoading:m})]})}const J2=ht(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownDocumentEditor})));function Y2(e){switch(e){case`text/markdown`:case`text/x-markdown`:return`markdown`;case`application/json`:return`json`;case`application/xml`:case`text/xml`:return`xml`;default:return`plaintext`}}function X2({object:r,text:i,onClose:a,onSaved:s}){let{store:c}=q(),l=nt(),{t:u}=K(),{theme:d}=tt(),f=$n(),p=W(void 0),[m,h]=G(i),[g,_]=G(!1),[v,y]=G(!1),[b,x]=G(!1),S=Y2(r.content?.type),C=k2(r.content?.type);H(()=>{h(i),_(!1)},[i]);let w=V(()=>{g||_(!0)},[g]),T=V(e=>{h(e),_(e!==i)},[i]);function E(){!C&&!p.current||x(!0)}async function D(e,t){if(!C&&!p.current)return;let n=C?m:p.current?.getValue();if(n===void 0)return;let i=r.content?.type||`text/plain`,o=r.content?.name||`content.txt`;try{y(!0);let d=new Blob([n],{type:i}),p=new File([d],o,{type:i}),m=await c.objects.update(r.id,{content:p},{createRevision:e,revisionLabel:t,ifMatch:r.content?.etag});l({status:`success`,title:u(`store.textSaved`),duration:2e3}),x(!1),e&&m.id!==r.id?(a(),setTimeout(()=>{f(`/objects/${m.id}`)},100)):s()}catch(e){let t=Ge(e,u(`store.errorSavingTextDefault`)),n=(typeof e==`object`&&e&&`status`in e?e.status:void 0)===412||t.includes(`412`);l({status:`error`,title:u(`store.errorSavingText`),description:n?u(`store.textConflict`):t,duration:5e3})}finally{y(!1)}}return n(e,{children:[n(`div`,{className:`flex items-center gap-2 px-2 py-1 shrink-0`,children:[g&&t(`span`,{className:`text-xs text-attention`,children:u(`store.unsavedChanges`)}),t(`div`,{className:`flex-1`}),t(o,{variant:`ghost`,size:`sm`,onClick:a,disabled:v,children:u(`store.cancelEdit`)}),t(o,{variant:`secondary`,size:`sm`,onClick:E,disabled:!g,isLoading:v,children:u(`store.saveText`)})]}),t(`div`,{className:`flex-1 min-h-0 border rounded-md overflow-hidden mx-2 mb-2`,children:C?t(ut,{fallback:t(`div`,{className:`h-full w-full`}),children:t(J2,{value:m,onChange:T})}):t(Pt,{value:i,language:S,editorRef:p,onChange:w,theme:d===`dark`?`vs-dark`:`vs`,options:{wordWrap:`on`,minimap:{enabled:!1},lineNumbers:`on`,scrollBeyondLastLine:!1}})}),t(L2,{isOpen:b,onClose:()=>x(!1),onConfirm:D,isLoading:v})]})}const Z2=131072;function Q2(e,t,n=!1,r=e){let{store:i}=q(),[a,o]=G(t),[s,c]=G(()=>t&&t.length>Z2?t.substring(0,Z2):t),[l,u]=G(!1),[d,f]=G(()=>!!t&&t.length>Z2),[p,m]=G(),h=W(t),g=W(e),_=W(r),v=W(!1),y=V((e,t=!0)=>{let n=h.current;t&&n&&e&&n!==e?m(e=>({previousText:n,version:(e?.version??0)+1})):t||m(void 0),h.current=e,o(e),e&&e.length>Z2?(c(e.substring(0,Z2)),f(!0)):(c(e),f(!1))},[]),b=V(()=>{let t=e,n=r;u(!0),i.objects.getObjectText(e).then(e=>{if(g.current!==t)return;let r=_.current===n&&!v.current;y(e.text,r),v.current=!1}).catch(e=>{console.error(`Failed to load text`,e)}).finally(()=>{g.current===t&&u(!1)})},[y,r,e,i]);return bt(()=>{let i=g.current!==e,a=_.current!==r;g.current=e,_.current=r,a&&(v.current=!0),t!==void 0&&(y(t,!a),v.current=!1),n&&t===void 0&&(i||h.current===void 0)&&b()},[y,r,t,n,b,e]),{fullText:a,displayText:s,isLoading:l,isCropped:d,changeHighlight:p,loadText:b}}function $2(e,t){let{client:n}=q(),[r,i]=G({isComplete:!1});return H(()=>{if(!t)return;let r=!1,a,o=(e,t,n)=>{i(r=>{let i=JSON.stringify(r.progress??null),a=JSON.stringify(e??null);return r.status===t&&r.isComplete===n&&i===a?r:{progress:e,status:t,isComplete:n}})};function s(){r||n.objects.analyze(e).getStatus().then(e=>{e.status===En.RUNNING?(o(e.progress,e.status,!1),r||(a=setTimeout(s,2e3))):o(e.progress,e.status,!0)}).catch(()=>{r||(a=setTimeout(s,1e4))})}return s(),()=>{r=!0,a&&clearTimeout(a)}},[t,e,n]),{progress:r.progress,status:r.status,isComplete:r.isComplete}}function e4(e,t){let{client:n}=q(),r=Xt.getFixedT(null,Yt),[i,a]=G(),[o,s]=G(!1),[c,l]=G();return{pdfUrl:i,isConverting:o,error:c,triggerConversion:V(async()=>{if(!t||o)return;s(!0),l(void 0);let i=async t=>{try{let o=await n.objects.getRendition(e,{format:_n.pdf,generate_if_missing:t,sign_url:!0,block_on_generation:!1});o.status===`generating`?setTimeout(()=>i(!1),5e3):o.status===`found`&&o.renditions?.length?(a(o.renditions[0]),s(!1)):o.status===`failed`&&(l(r(`store.pdfConversionFailed`)),s(!1))}catch(e){console.error(`Failed to convert Office document to PDF:`,e),l(r(`store.failedToConvertToPdf`)),s(!1)}};await i(!0)},[e,t,o,n,r])}}Q(),JY();const t4=()=>({a:({node:e,...n})=>{let r=n.href||``;return r.includes(`/store/objects/`)?t(Qn,{topLevelNav:!0,href:r,className:`text-info`,children:n.children}):t(`a`,{...n,target:`_blank`,rel:`noopener noreferrer`})},p:({node:e,...n})=>t(`p`,{...n,className:`my-0`}),pre:({node:e,...n})=>t(`pre`,{...n,className:`my-2 p-2 rounded`}),code:({node:e,className:n,children:r,...i})=>{let a=!/language-(\w+)/.exec(n||``);return t(`code`,{...i,className:a?`px-1.5 py-0.5 rounded`:`text-muted`,children:r})},h1:({node:e,...n})=>t(`h1`,{...n,className:`font-bold text-2xl my-2`}),h2:({node:e,...n})=>t(`h2`,{...n,className:`font-bold text-xl my-2`}),h3:({node:e,...n})=>t(`h3`,{...n,className:`font-bold text-lg my-2`}),li:({node:e,...n})=>t(`li`,{...n})});function n4(e){return e===fn.created||e===fn.processing}function r4(e){return e.metadata?.content_processor?.type}function i4(e){return e?e.includes(`
1389
1389
  # `)||e.includes(`
1390
1390
  ## `)||e.includes(`
1391
1391
  ### `)||e.includes(`
1392
1392
  * `)||e.includes(`
1393
1393
  - `)||e.includes(`
1394
- + `)||e.includes(`![`)||e.includes(`](`):!1}function r4(e){return e?`h-full overflow-auto`:`hidden`}var i4;(function(e){e.Text=`text`,e.Image=`image`,e.Video=`video`,e.Audio=`audio`,e.Pdf=`pdf`,e.Transcript=`transcript`})(i4||={});function a4({object:r,loadText:i,refetch:a,canEditProperties:o=!0,canCollaborate:s=!1}){let c=nt(),{t:l}=K(),{project:u,store:d}=q(),f=$n(),p=r.revision?.root||r.id,m=u?.id?v2(u.id,p):void 0,[h,g]=G(r),[_,v]=G(()=>m?y2(m):!1),y=W(null),b=W(r.id),x=W(r.id),S=W(m);H(()=>{S.current!==m&&(S.current=m,v(m?y2(m):!1))},[m]);let C=V(()=>{v(e=>{let t=!e;return m&&b2(m,t),t})},[m]),w=V(()=>{m&&b2(m,!1),v(!1)},[m]);H(()=>{let e=x.current!==r.id;x.current=r.id,g(t=>!e&&t.id!==r.id?t:(b.current=r.id,t.id===r.id&&t.text&&!r.text?{...r,text:t.text}:r))},[r]);let T=V(async(e,t)=>{b.current=e;try{let[t,n]=await Promise.all([d.objects.retrieve(e),d.objects.getObjectText(e)]);b.current===e&&g({...t,text:n.text})}catch(e){console.error(`Failed to load the updated document revision`,e),c({status:`error`,title:l(`agent.failedToLoadDocument`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{t&&f(`/objects/${e}`)}},[f,d.objects,l,c]),E=async(e,t)=>{try{await navigator.clipboard.writeText(e),c({status:`success`,title:l(`store.contentCopied`,{type:l(t===`text`?`store.contentType`:`store.properties`)}),description:l(`store.successfullyCopied`,{type:t}),duration:2e3})}catch(e){console.error(`Failed to copy ${t}:`,e),c({status:`error`,title:l(`store.copyFailed`),description:l(`store.failedToCopy`,{type:t}),duration:5e3})}};return n(e,{children:[n(Ce,{direction:`horizontal`,className:`h-full`,children:[t(Se,{defaultSize:67,className:`min-w-[100px]`,children:t(s4,{object:h,loadText:i??!1,handleCopyContent:E,refetch:a,canCollaborate:s,isCollaborating:_,onToggleCollaborate:C})}),t(xe,{withHandle:!0}),t(Se,{defaultSize:33,className:`min-w-[100px]`,children:t(o4,{object:h,refetch:a??(()=>Promise.resolve()),handleCopyContent:E,canEditProperties:o})})]}),_?t(W2,{object:h,initialContent:h.text??``,onClose:w,onDocumentUpdated:(e,t)=>void T(e,t),sendMessageRef:y}):null]})}function o4({object:r,refetch:i,handleCopyContent:a,canEditProperties:s}){let{t:c}=K(),[l,u]=G(!1),[d,f]=G(!1);return n(e,{children:[n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted mb-2 p-1 rounded`,children:[t(o,{variant:`${l?`ghost`:`primary`}`,size:`sm`,title:c(`store.previewProperties`),onClick:()=>u(!l),children:`Properties`}),t(o,{variant:`${l?`primary`:`ghost`}`,size:`sm`,title:c(`store.viewInJsonFormat`),onClick:()=>u(!l),children:`JSON`})]}),n(`div`,{className:`flex items-center gap-2`,children:[r.properties&&t(o,{variant:`ghost`,size:`sm`,title:`Copy properties`,onClick:()=>a(JSON.stringify(r.properties,null,2),`properties`),children:t(pg,{className:`size-4`})}),s&&t(Y0,{permission:bn.content_write,variant:`ghost`,size:`sm`,onClick:()=>{f(!0)},title:`Edit properties`,className:`flex items-center gap-2`,children:t(Qy,{className:`size-4`})})]})]}),r.properties?t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(jt,{value:r.properties,viewCode:l})}):t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(`div`,{children:c(`store.noPropertiesDefined`)})})]}),t(G2,{isOpen:d,onClose:()=>{f(!1)},object:r,refetch:i})]})}function s4(e){let{client:n}=q(),r=e.object.type,i=r?.id,a=r?.default_view,{data:o}=Ye(async()=>!i||a?null:(await Q0(n,i))?.intake?.default_view??null,[i,a]),s=a??o;return i&&!a&&o===void 0?t(`div`,{className:`flex h-full items-center justify-center`,children:t(je,{size:`lg`})}):t(c4,{...e,defaultView:s??void 0})}function c4({object:e,loadText:r,handleCopyContent:i,refetch:a,defaultView:s,canCollaborate:c,isCollaborating:l,onToggleCollaborate:u}){let{client:d}=q(),{t:f}=K(),p=e?.metadata?.type===dn.Image,m=e?.metadata?.type===dn.Video,h=e?.metadata?.type===dn.Audio,g=e?.content?.type===`application/pdf`,_=e?.content?.type?t$(e.content.type):!1,v=e4(e?.status),y=!!(e.transcript&&(m||h)),b=e.metadata?.renditions?.find(e=>e.name===vn),x=()=>{switch(s){case`text`:return i4.Text;case`pdf`:if(g||_||b)return i4.Pdf;break;case`image`:if(p)return i4.Image;break;case`properties`:return i4.Text}return m?i4.Video:h?i4.Audio:p?i4.Image:i4.Text},S=t0(e.id),[C,w]=G(x()),[T,E]=G(C===i4.Pdf);H(()=>{C===i4.Pdf&&E(!0)},[C]);let[D,O]=G(!1),k=T2(!!(e.content?.type&&!e.is_locked&&e.user_permissions?.can_write!==!1&&(e.content.type.startsWith(`text/`)||e.content.type===`application/json`||e.content.type===`application/xml`)),c),{fullText:A,displayText:j,isLoading:M,isCropped:N,loadText:P}=X2(e.id,e.text,r,e.revision?.root||e.id),F=(g||_)&&v&&(C===i4.Text||C===i4.Pdf),{progress:I,status:L,isComplete:ee}=Z2(e.id,F),{pdfUrl:R,isConverting:te,error:ne,triggerConversion:re}=Q2(e.id,_),ie=U(()=>[{id:`office-pdf-rendition`,target:`pdf`,canConvert:({contentType:e,extension:t})=>_||(e?t$(e):!1)||[`doc`,`docx`,`ppt`,`pptx`].includes(t),convert:async()=>{let t=await d.objects.getRendition(e.id,{format:_n.pdf,generate_if_missing:!0,sign_url:!0,block_on_generation:!0});return t.status===`found`&&t.renditions?.length?{url:t.renditions[0],contentType:`application/pdf`,fileName:`${e.name||`document`}.pdf`}:null}}],[d,_,e.id,e.name]);H(()=>{ee&&L===En.COMPLETED&&P()},[ee,L,P]);let ae=(g||_)&&v&&!ee&&L===En.RUNNING,oe=C===i4.Pdf&&!ae,se=ae&&(C===i4.Text||C===i4.Pdf),ce=T&&!ae,le=W(null);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2 shrink-0`,children:[n(`div`,{className:`flex items-center gap-2 mb-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted p-1 rounded`,children:[p&&t(o,{variant:C===i4.Image?`primary`:`ghost`,size:`sm`,title:f(`store.viewImage`),onClick:()=>w(i4.Image),children:`Image`}),m&&t(o,{variant:C===i4.Video?`primary`:`ghost`,size:`sm`,title:f(`store.viewVideo`),onClick:()=>w(i4.Video),children:`Video`}),h&&t(o,{variant:C===i4.Audio?`primary`:`ghost`,size:`sm`,title:f(`store.viewAudio`),onClick:()=>w(i4.Audio),children:`Audio`}),y&&t(o,{variant:C===i4.Transcript?`primary`:`ghost`,size:`sm`,title:f(`store.viewTranscript`),onClick:()=>w(i4.Transcript),children:`Transcript`}),t(o,{variant:C===i4.Text?`primary`:`ghost`,size:`sm`,title:f(`store.viewText`),onClick:()=>w(i4.Text),children:`Text`}),g&&t(o,{variant:C===i4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewPdf`),onClick:()=>w(i4.Pdf),children:`PDF`}),_&&t(o,{variant:C===i4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewAsPdf`),onClick:()=>{w(i4.Pdf),!b&&!R&&!te&&re()},disabled:te,children:te?t(je,{size:`sm`}):`PDF`})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(f4,{object:e}),t(p4,{objectId:e.id,available:S})]})]}),C===i4.Text&&!ae&&!D&&t(l4,{object:e,text:j,fullText:A,handleCopyContent:i,textContainerRef:le,isEditing:D,onToggleEdit:()=>O(!0),canEdit:k.canEdit,isCollaborating:l,onToggleCollaborate:u,canCollaborate:k.canCollaborate}),C===i4.Pdf&&_&&(b||R)&&t(m4,{object:e,pdfRendition:b,officePdfUrl:R})]}),C===i4.Image&&t(`div`,{className:r4(!0),children:t(R0,{object:e})}),C===i4.Video&&t(`div`,{className:r4(!0),children:t(z0,{object:e})}),C===i4.Audio&&t(`div`,{className:r4(!0),children:t(L0,{object:e})}),y&&C===i4.Transcript&&t(`div`,{className:r4(!0),children:t(d4,{object:e,handleCopyContent:i})}),g&&ce&&t(`div`,{className:r4(oe),children:t(h4,{object:e})}),_&&ce&&t(`div`,{className:r4(oe),children:t(g4,{object:e,pdfRendition:b,officePdfUrl:R,converters:ie,officePdfConverting:te,officePdfError:ne})}),se&&t(`div`,{className:r4(!0),children:t(_4,{progress:I,status:L})}),C===i4.Text&&!ae&&!D&&M&&!j&&t(`div`,{className:r4(!0),children:t(`div`,{className:`flex justify-center items-center flex-1`,children:t(je,{size:`lg`})})}),C===i4.Text&&!ae&&!D&&(!M||j)&&t(`div`,{className:r4(!0),children:t(u4,{object:e,text:j,isTextCropped:N,textContainerRef:le})}),D&&C===i4.Text&&A!=null&&t(J2,{object:e,text:A,onClose:()=>O(!1),onSaved:()=>{O(!1),P(),a?.()}})]})}function l4({object:r,text:i,fullText:a,handleCopyContent:s,onToggleEdit:c,canEdit:l,isCollaborating:u,onToggleCollaborate:d,canCollaborate:f}){let{client:p,project:m}=q(),h=nt(),{t:g}=K(),_=r.content,{renderDocument:v,isDownloading:y}=eG({client:p,toast:h}),{data:b}=Ye(()=>m?p.projects.retrieve(m.id):Promise.resolve(void 0),[m?.id]),x=b?.configuration?.pdf_template_object_id??void 0,S=D2(_?.type),C=O2(_?.type),T=async(e,t)=>{if(y)return;h({status:`info`,title:`Preparing ${e.toUpperCase()}`,description:g(`store.renderingDocument`),duration:2e3});let n=t===!1?void 0:x;await v(r.id,{format:e,title:r.name||`document`,useDefaultTemplate:t,templateObjectId:n})};return t(`div`,{className:`h-[41px] text-lg font-semibold flex justify-between items-center px-2`,children:n(`div`,{className:`flex items-center gap-2`,children:[a&&t(o,{variant:`ghost`,size:`sm`,title:`Copy text`,onClick:()=>s(a,`text`),children:t(pg,{className:`size-4`})}),y?t(o,{variant:`ghost`,size:`sm`,disabled:!0,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(je,{size:`sm`})}):n(w,{trigger:t(o,{variant:`ghost`,size:`sm`,disabled:!i,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(Sg,{className:`size-4`})}),children:[a&&t(ae,{onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!a)return;let t=`txt`,n=`text/plain`;_?.type===`application/xml`||_?.type===`text/xml`?(t=`xml`,n=`text/xml`):S&&(t=`md`,n=`text/markdown`);let i=new Blob([a],{type:n}),o=URL.createObjectURL(i),s=`${r.name||`document`}.${t}`,c=document.createElement(`a`);c.href=o,c.download=s,c.style.display=`none`,setTimeout(()=>{c.click(),URL.revokeObjectURL(o)},0)},children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Download Text`]})}),S&&i&&n(e,{children:[t(ae,{onClick:()=>T(_n.docx),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Export as DOCX`]})}),t(ae,{onClick:()=>T(_n.pdf,!1),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Export as PDF`]})}),t(ae,{onClick:()=>T(_n.pdf),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Export as Branded PDF`]})})]})]}),a&&n(e,{children:[l&&c&&t(Y0,{permission:bn.content_write,variant:`ghost`,size:`sm`,onClick:c,title:g(`store.editText`),"aria-label":g(`store.editText`),className:`h-8 w-8 p-0`,children:t(Qy,{className:`size-4`})}),f&&d&&C&&t(o,{variant:u?`primary`:`ghost`,size:`sm`,onClick:d,title:g(`agent.editWithAI`),"aria-label":g(`agent.editWithAI`),className:`h-8 w-8 p-0`,children:t(Yy,{className:`size-4`})})]})]})})}const u4=gt(({object:r,text:i,isTextCropped:a,textContainerRef:o})=>{let{t:s}=K(),c=e4(r?.status),l=r.content,u=t4(r)===`xml`||l?.type===`application/xml`||l?.type===`text/xml`,d=O2(l?.type),f=!u&&(d||n4(i)),p={id:r.id,title:r.name,fileName:r.content?.name||r.name,contentType:u?`text/xml`:f?`text/markdown`:r.content?.type,content:i,sourcePath:r.content?.source};return i?n(e,{children:[a&&t(`div`,{className:`px-2 py-2 bg-attention/10 border-s-4 border-attention mx-2 mb-2 rounded`,children:n(`div`,{className:`flex items-center gap-2 text-attention`,children:[t(yb,{className:`size-4`}),t(`span`,{className:`text-sm font-semibold`,children:s(`store.showingFirst128K`)})]})}),t(`div`,{className:`max-w-7xl px-2 h-full overflow-auto`,ref:o,children:t(qY,{source:p,className:`h-full`,bodyClassName:`overflow-auto`,markdownComponents:$2()})})]}):t(`div`,{className:`px-2`,children:t(`div`,{children:c?`Extracting content...`:`No content`})})});function d4({object:e,handleCopyContent:r}){let{t:i}=K(),a=e.transcript,s=a?.text,c=a?.segments,l=s||(c?c.map(e=>e.text).join(` `):``),u=e=>{let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`};return n(`div`,{className:`flex flex-col h-full`,children:[t(`div`,{className:`flex justify-end items-center px-2 mb-2`,children:l&&t(o,{variant:`ghost`,size:`sm`,title:`Copy transcript`,onClick:()=>r(l,`text`),children:t(pg,{className:`size-4`})})}),t(`div`,{className:`h-full} overflow-auto px-2`,children:c&&c.length>0?t(`div`,{className:`space-y-2`,children:c.map((e,r)=>n(`div`,{className:`flex gap-3 text-sm`,children:[n(`span`,{className:`text-muted font-mono text-xs shrink-0 pt-0.5`,children:[u(e.start),e.end&&` - ${u(e.end)}`]}),t(`span`,{className:`flex-1`,children:e.text})]},`segment-${r}`))}):s?t(`pre`,{className:`text-wrap bg-muted text-muted p-2 whitespace-pre-wrap`,children:s}):t(`div`,{className:`text-muted`,children:i(`store.noTranscriptAvailable`)})})]})}function f4({object:r}){let[i,a]=G(!1);return t4(r)===`markdown`?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>a(!0),title:`Side by side view`,children:t(Ug,{className:`size-4`})}),i&&t(ve,{children:t(j0,{objectId:r.id,onClose:()=>a(!1)})})]}):null}function p4({objectId:r,available:i}){let{t:a}=K(),[s,c]=G(!1);return i?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),title:a(`grounded.title`),"aria-label":a(`grounded.title`),children:t(Oy,{className:`size-4`})}),s&&t(ve,{children:t(i0,{objectId:r,onClose:()=>c(!1)})})]}):null}function m4({object:e,pdfRendition:n,officePdfUrl:r}){let{client:i}=q(),a=nt(),{t:s}=K(),[c,l]=G(!1);return t(`div`,{className:`flex items-center gap-2`,children:t(o,{variant:`ghost`,size:`sm`,onClick:async()=>{l(!0);try{let t=r;!t&&n?.content?.source&&(t=(await i.files.getDownloadUrl(n.content.source,`${e.name||`document`}.pdf`,`attachment`)).url),t&&window.open(t,`_blank`)}catch(e){console.error(`Failed to download PDF:`,e),a({status:`error`,title:s(`store.downloadFailed`),description:s(`store.failedToDownloadPdf`),duration:5e3})}finally{l(!1)}},disabled:c,title:`Download PDF`,children:c?t(je,{size:`sm`}):t(Sg,{className:`size-4`})})})}function h4({object:e}){let n={id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source};return t(`div`,{className:`h-full`,children:t(qY,{source:n,className:`h-full`,showHeader:!1})})}function g4({object:e,pdfRendition:r,officePdfUrl:i,converters:a,officePdfConverting:o,officePdfError:s}){let{t:c}=K();if(o)return n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2`,children:[t(je,{size:`lg`}),t(`span`,{className:`text-muted`,children:c(`store.convertingToPdf`)})]});if(s)return n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2 text-destructive`,children:[t(yb,{className:`size-8`}),t(`span`,{children:s})]});if(r?.content?.source){let n={id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,sourcePath:r.content.source};return t(`div`,{className:`h-full`,children:t(qY,{source:n,className:`h-full`})})}if(i){let n={id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,url:i};return t(`div`,{className:`h-full`,children:t(qY,{source:n,className:`h-full`})})}let l={id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source};return t(`div`,{className:`h-full`,children:t(qY,{source:l,converters:a,className:`h-full`})})}function _4({progress:r,status:i}){let{t:a}=K(),o=c$(i),s=l$(i),c=r?.phase===`grounded_extraction`,l=r?.percent!=null&&!Number.isNaN(r.percent)?r.percent:0;return n(`div`,{className:`px-4 py-4`,children:[r&&n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex flex-col gap-1`,children:[t(v4,{name:c?`Prepare Evidence`:`Analyze Page`,progress:r.pages}),c&&n(e,{children:[t(v4,{name:`Run OCR`,progress:r.images}),t(v4,{name:`Extract Grounded Data`,progress:r.tables}),t(v4,{name:`Review and Annotate`,progress:r.visuals})]})]}),n(`div`,{className:`pt-2 text-sm text-muted`,children:[`Progress: `,l,`%`,t(`span`,{className:`px-2`,children:`•`}),t(`span`,{className:o,children:s}),r.started_at&&n(e,{children:[t(`span`,{className:`px-2`,children:`•`}),n(`span`,{children:[((Date.now()-r.started_at)/1e3).toFixed(0),` sec. elapsed`]})]})]}),t(Ft,{percent:l})]}),!r&&n(`div`,{className:`flex items-center gap-2 text-muted`,children:[t(je,{size:`sm`}),t(`span`,{children:a(`store.loadingProcessingStatus`)})]})]})}function v4({name:e,progress:t}){return n(`div`,{className:`flex gap-2 text-sm`,children:[n(`span`,{className:`text-muted min-w-36`,children:[e,`:`]}),n(`span`,{children:[t.processed,` of `,t.total]})]})}Q();const y4=Object.values(Sn),b4=Object.values(wn);function x4({onChange:e,isLoading:r,refresh:i,searchTypes:a}){let{client:s,project:c}=q(),{t:l}=K(),u=nt(),[d,f]=G(void 0),[p,h]=G(void 0),g=!!c&&(!!p?.embeddings.text||!!p?.embeddings.image),[_,v]=G(void 0),y=W(i),b=W(void 0),[x,S]=G(!1),[C,w]=G(a||y4),[T,E]=G(100);H(()=>{a&&w(a)},[a]);let D={},O=!1,k=!1;C.forEach(e=>{e===Sn.full_text?O=!0:k=!0,b4.includes(e)&&(D[e]=!0)}),H(()=>{y.current!==i&&(y.current=i,f(void 0),v(void 0))}),H(()=>{c&&s.projects.retrieve(c.id).then(e=>{h(e.configuration)})},[s.projects.retrieve,c]),H(()=>{_&&u({title:_,status:`success`,duration:2e3})},[_,u]),H(()=>{let t=b.current;b.current=d,t&&(!d||d.length===0)&&e(void 0)},[e,d]);let A=()=>{!g||!d||(e({vector:k?{text:d,config:D}:void 0,full_text:O?d:void 0,limit:T}),v(`Searching...`))},j=e=>{e.key===`Enter`&&A()},M=e=>t=>{w(t?t=>Array.from(new Set([...t,e])):t=>t.filter(t=>t!==e))};return n(`div`,{className:`flex gap-1 items-center`,children:[t(te,{placeholder:l(`store.searchPlaceholder`),value:d,onChange:f,onKeyDown:j,className:`min-w-[200px]`}),t(o,{variant:`ghost`,onClick:()=>S(!0),title:l(`store.semanticSearchSettings`),className:`ms-1`,children:t(Ly,{size:18})}),n(se,{isOpen:x,onClose:()=>S(!1),children:[t(ue,{children:l(`store.searchTypes`)}),t(ce,{children:n(`div`,{className:`flex flex-col gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-full_text`,checked:C.includes(Sn.full_text),onCheckedChange:M(Sn.full_text)}),t(re,{htmlFor:`search-type-full_text`,children:l(`store.fullText`)})]}),t(`div`,{className:`font-semibold mt-2 mb-1`,children:l(`store.embeddings`)}),b4.map(e=>n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-${e}`,checked:C.includes(e),onCheckedChange:M(e)}),t(re,{htmlFor:`search-type-${e}`,children:e.charAt(0).toUpperCase()+e.slice(1)})]},e)),n(`div`,{className:`mt-3`,children:[t(`span`,{className:`me-2`,children:l(`store.limit`)}),t(de,{type:`number`,min:1,value:T,onChange:e=>E(Number(e??100)),style:{width:80}})]})]})}),t(le,{children:t(o,{variant:`outline`,onClick:()=>S(!1),children:l(`store.close`)})})]}),t(o,{variant:`secondary`,isLoading:r,onClick:A,isDisabled:!g,title:l(`store.semanticSearch`),children:l(`store.search`)})]})}Q();const S4=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function C4(e,t){return(t?e.getTypeLayout(t):S4)??S4}function w4({onUploadDone:e=async()=>{},layout:n,toolbarActions:r}){let i=E$(),a=nt(),{t:o}=K(),s=I$(V(async t=>{await e(t),setTimeout(()=>{console.log(`Delayed refresh after upload to ensure backend consistency`),i.search().then(e=>{e&&a({title:o(`store.documentListRefreshed`),description:o(`store.documentListRefreshedDesc`),status:`info`,duration:3e3})}).catch(e=>{console.error(`Failed to refresh search results:`,e)})},1e3)},[e,i,o,a])),c=V((e,t)=>{let n=i.collectionId;return s(e,t,n)},[i,s]);return t(T4,{layout:n,onUpload:c,toolbarActions:r})}function T4({layout:e,onUpload:r,allowFilter:i=!0,allowSearch:a=!0,toolbarActions:o}){let{t:s}=K(),c=E$(),[l,u]=G(!1),[d,f]=G(null),{registry:p}=UZ(),{search:m,isLoading:h,error:g,objects:_,hasMore:v}=O$(),[y,b]=G(p?e||C4(p,m.query.type):S4);H(()=>{e&&b(e)},[e]);let[x,S]=G(0),[C,w]=G(0),[T,E]=G(localStorage.getItem(G$.LAST_DISPLAYED_VIEW)===`grid`),[D,O]=G([]),k=W(null),A=W(null),j=V((e,t)=>{u(!1),e.catch(e=>{console.error(t,e)}).finally(()=>{u(!0)})},[]);H(()=>{let e=!1;return m.initialized?(u(!0),()=>{e=!0}):(u(!1),w(0),m.search().catch(t=>{e||console.error(`Initial search failed:`,t)}).finally(()=>{e||u(!0)}),()=>{e=!0})},[m]),H(()=>{_.length<C&&w(_.length)},[_.length,C]),Qe(k,()=>{l&&_.length>0&&_.length!==C&&(u(!1),m.loadMore().catch(e=>{console.error(`Failed to load more search results:`,e)}).finally(()=>{w(_.length),u(!0)}))},{deps:[l,_.length]});let N=e=>{if(e?.vector){if(m.query.vector=e.vector,m.query.full_text=e.full_text,m.query.weights=e.weights,m.query.score_aggregation=e.score_aggregation,m.query.dynamic_scaling=e.dynamic_scaling,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),!y.find(e=>e.name===`Search Score`)){let e=[...y,{name:`Search Score`,field:`score`,render:e=>typeof e.score==`number`?e.score.toFixed(4):`0.0000`}];b(e)}j(m.search(),`Vector search failed:`)}else e?.full_text?(m.query.full_text=e.full_text,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),j(m.search(),`Text search failed:`)):e===void 0&&l&&(delete m.query.vector,delete m.query.full_text,j(m.search(),`Search reset failed:`))},P=D$(),F=E$(),I=()=>{j(m.search(),`Search refresh failed:`)},L=tQ(P),ee=nQ(F),R=e=>{let t=typeof e==`function`?e(D):e;O(t),ee(t)},te=(e,t)=>{let n=L.find(t=>t.name===e),r={name:e,type:n?.type,placeholder:n?.placeholder,multiple:n?.multiple};R(i=>{let a=i.filter(t=>t.name!==e);if(n?.type===`stringList`||Array.isArray(t)){let n=Array.isArray(t)?t:[t],o=i.find(t=>t.name===e)?.value??[];return[...a,{...r,value:Array.from(new Set([...o,...n]))}]}return[...a,{...r,value:[{value:t,label:t}]}]})},ne=new URL(window.location.href),re=ne.searchParams.get(`filters`);if(re)try{let e=re.split(`;`),t=e.filter(e=>{let[t]=e.split(`:`),n=decodeURIComponent(t);return n!==`start`&&n!==`end`});if(t.length!==e.length){let e=t.length>0?t.join(`;`):``;e?ne.searchParams.set(`filters`,e):ne.searchParams.delete(`filters`),window.history.replaceState(window.history.state||{},``,ne.toString())}}catch(e){console.error(`Failed to clean start/end filters from URL:`,e)}let ie=$n();return n(`div`,{className:`flex flex-col gap-y-2 flex-1 min-h-0 `,children:[t(D4,{object:d,onClose:()=>f(null)}),g&&t(M,{title:s(`store.error`),children:g.message}),t(E4,{isLoading:h,refreshTrigger:x,allowFilter:i,allowSearch:a,filterGroups:L,filters:D,handleFilterChange:R,handleVectorSearch:N,handleRefetch:I,setIsGridView:E,toolbarActions:o}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md mb-2`,children:n(`div`,{ref:A,className:`flex-1 min-h-0 overflow-y-auto`,children:[t(HQ,{onFilter:te,children:t(R$,{objects:_,isLoading:!_.length&&h,layout:y,onRowClick:e=>{ie(`/objects/${e.id}`)},previewObject:e=>{let t=_.find(t=>t.id===e)||null;f(t)},selectedObject:d,onUpload:r,isGridView:T,collectionId:c.collectionId})}),v?t(`div`,{ref:k,className:`w-full flex justify-center`,children:t(je,{size:`xl`})}):t(`div`,{className:`text-muted text-center text-sm py-1`,children:`All ${_.length} objects loaded.`})]})})]})}function E4(e){let{t:r}=K(),{isLoading:i,refreshTrigger:a,allowFilter:s,allowSearch:c,filterGroups:l,filters:u,handleFilterChange:d,handleVectorSearch:f,handleRefetch:p,setIsGridView:m,toolbarActions:h}=e;return n(`div`,{className:`sticky top-0 z-10 bg-background py-2 flex justify-between items-center`,children:[s?t(I,{filterGroups:l,filters:u,setFilters:d,children:n(`div`,{children:[t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:n(`div`,{className:`flex gap-2 items-center w-2/3`,children:[c&&t(x4,{onChange:f,isLoading:i,refresh:a,className:`w-full`}),t(P,{})]})}),n(`div`,{className:`flex gap-2 items-center pt-2`,children:[t(N,{}),t(F,{})]})]})}):t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:t(`div`,{className:`flex gap-2 items-center w-2/3`,children:c&&t(x4,{onChange:f,isLoading:i,refresh:a})})}),n(`div`,{className:`flex gap-1 items-center`,children:[h,t(o,{variant:`outline`,onClick:p,title:r(`store.refresh`),children:t(gy,{size:16})}),t(G$,{onUpdate:m})]})]})}function D4({object:e,onClose:r}){let{store:i}=q(),a=nt(),s=$n(),{downloadFromContentSource:c}=eG({client:i,toast:a}),l=e?.content?.source,u=typeof e?.properties?.title==`string`?e.properties.title:e?.name;return e?n(Oe,{title:u,isOpen:!0,onClose:r,children:[n(`div`,{className:`flex items-center gap-x-2`,children:[t(o,{variant:`ghost`,size:`sm`,title:`Open Object`,onClick:()=>s(`/objects/${e.id}`),children:t(Og,{className:`size-4`})}),l&&t(o,{variant:`ghost`,size:`sm`,title:`Download`,onClick:()=>c(l,$W(e)),children:t(Sg,{className:`size-4`})})]}),t(C,{className:`my-2`}),t(`div`,{className:`pt-2`,children:t(a4,{object:e,loadText:!0},e.id)})]}):null}const O4=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Revision`,field:`.`,type:`revision`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function k4({collection:e}){let n=nt(),{client:r}=q(),{registry:i}=UZ(),a=async t=>{t.length>0&&await r.store.collections.addMembers(e.id,t).catch(e=>{n({title:`Failed to add objects to collection`,description:e.message,status:`error`})})},o=A4(e,i);return t(`div`,{className:`flex flex-col h-full`,children:e.dynamic?t(T4,{layout:o}):t(w4,{onUploadDone:a,layout:o})})}function A4(e,t){let n=e.table_layout;return n&&n.length>0||(e.type&&t&&(n=t?.getTypeLayout(Dn(e.type))),n&&n.length>0)?n:O4}function j4({className:e,defaultValue:r,onChange:i,isClearable:a,multiple:o}){let{t:s}=K(),{registry:c}=UZ(),[l,u]=G(!1),d=e=>e===null?s(`store.none`):n(`div`,{children:[t(`div`,{className:`text-sm`,children:e.name}),t(`div`,{className:`text-xs text-muted truncate`,children:e.description})]}),[f,p]=G(),[m,h]=G([]);return H(()=>{if(!l&&(u(!0),c&&r)){if(o&&Array.isArray(r)){let e=c.types.filter(e=>r.includes(e.id));h(e)}let e=c.types.find(e=>e.id===r);e&&p(e)}},[l,c,r,o]),o?t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(we,{options:c?.types||[],value:m,onChange:e=>{h(e),i(e)},placeholder:s(`store.chooseContentTypes`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1,multiple:!0})}):t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(we,{options:c?.types||[],value:f,onChange:e=>{p(e||void 0),i(e)},placeholder:s(`store.chooseContentType`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1})})}function M4({onClose:r,redirect:i=!0,onAddToCollection:a}){let s=$n(),c=nt(),{t:l}=K(),[u,d]=G(!1),{client:f}=q(),[p,m]=G({dynamic:!1,name:``,description:``});function h(e,t){m({...p,[e]:t})}return n(e,{children:[t(ce,{children:n(`form`,{onSubmit:e=>e.preventDefault(),children:[t(L,{label:l(`type.name`),required:!0,children:t(te,{type:`text`,value:p.name||``,onChange:e=>h(`name`,e)})}),t(L,{label:l(`type.description`),className:`mt-2`,children:t(Ue,{value:p.description||``,onChange:e=>h(`description`,e.target.value)})}),t(L,{label:l(`store.dynamicCollection`),className:`mt-2`,direction:`row`,description:l(`store.dynamicCollectionDescription`),children:t(Ne,{value:p.dynamic||!1,onChange:e=>h(`dynamic`,e)})}),!p.dynamic&&t(L,{label:l(`store.allowedContentTypes`),className:`mt-4`,description:l(`store.allowedContentTypesOptionalDescription`),children:t(j4,{defaultValue:p.allowed_types||null,onChange:e=>{Array.isArray(e)?h(`allowed_types`,e.map(e=>e.id)):h(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),t(L,{label:l(`store.contentType`),className:`mt-2`,description:l(`store.typeDescription`),children:t(j4,{defaultValue:p.type||null,onChange:e=>{Array.isArray(e)?h(`type`,e.length>0?e[0].id:null):h(`type`,e?.id||null)},isClearable:!0})})]})}),t(le,{children:t(o,{isDisabled:u,onClick:()=>{if(!p?.name?.trim()){c({title:l(`type.nameRequired`),description:l(`store.pleaseProvideName`),status:`error`,duration:5e3});return}p.name=p.name.trim(),p.description&&=p.description.trim(),p.dynamic??=!1,d(!0),f.store.collections.create(p).then(e=>{r(),c({title:l(`store.collectionCreated`),description:`Collection "${e.name}" created successfully`,status:`success`,duration:3e3}),i&&s(`/collections/${e.id}`),a&&a(e.id)}).catch(e=>{c({title:l(`store.failedToCreateCollection`),description:e.message,status:`error`,duration:5e3})}).finally(()=>d(!1))},children:l(`store.createCollection`)})})]})}function N4({isOpen:e,onClose:r}){let{t:i}=K();return n(se,{onClose:r,isOpen:e,children:[t(ue,{children:i(`store.createACollection`)}),t(M4,{onClose:r})]})}Q();function P4(){let{client:r}=q(),i=nt(),{t:a}=K(),[s,c]=G(),[l,u]=G(!0),[d,f]=G(!1),{data:p,error:m,refetch:h}=Ye(()=>r.store.collections.search({}),[]);return H(()=>{(p||m)&&u(!1)},[p,m]),m?t(M,{title:a(`store.collectionFetchFailed`),children:Ge(m)}):n(e,{children:[p&&(p.length>0?n(Le,{className:`w-full`,children:[t(`thead`,{children:n(`tr`,{children:[t(`th`,{children:a(`type.name`)}),t(`th`,{children:a(`type.type`)}),t(`th`,{children:a(`store.created`)}),t(`th`,{})]})}),t(Pe,{columns:4,isLoading:l,children:p.map(e=>n(Ie,{children:[t(`td`,{children:n(`div`,{className:`flex items-center gap-2`,children:[t(F4,{isDynamic:e.dynamic}),t(Qn,{href:`/collections/${e.id}`,children:e.name})]})}),t(`td`,{children:e.type?.name||`-`}),t(`td`,{children:GD(e.created_at).fromNow()}),t(`td`,{className:`text-end`,children:t(o,{variant:`destructive`,size:`sm`,onClick:()=>c(e.id),children:t(gb,{className:`size-4`})})})]},e.id))})]}):t(j,{title:a(`store.noCollections`),buttonLabel:a(`store.newCollections`),onClick:()=>f(!0),children:a(`store.getStartedCollections`)})),t(N4,{isOpen:d,onClose:()=>f(!1)}),t(b,{isOpen:!!s,title:a(`store.deleteCollection`),content:a(`store.areYouSureDeleteCollection`),onConfirm:async()=>{if(s)try{await r.store.collections.delete(s),i({title:a(`store.collectionDeleted`),status:`success`,duration:3e3}),h()}catch(e){console.error(`Failed to delete collection:`,e),i({title:a(`store.failedToDeleteCollection`),description:Ge(e),status:`error`,duration:5e3})}finally{c(void 0)}},onCancel:()=>c(void 0)})]})}function F4({isDynamic:e}){let{t:n}=K(),r=n(e?`store.dynamicCollection`:`store.staticCollection`),i=t(e?jy:t_,{className:`size-5`});return t(We,{description:r,className:`me-2`,children:i})}Q();const I4=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function L4({objects:e,isLoading:r,onFilter:i,selectedIds:a,onToggleOne:s,allSelected:c,onToggleAll:l}){let{t:u}=K(),d=$n(),f=!!s;return n(Le,{className:`w-full`,children:[t(Fe,{children:n(`tr`,{children:[f&&t(`th`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,checked:!!c,"aria-label":u(`store.actions.selectAllTypes`),onChange:e=>l?.(e.target.checked)})}),t(`th`,{children:u(`store.name`)}),t(`th`,{children:u(`store.strictMode`)}),t(`th`,{children:u(`store.semanticChunking`)}),t(`th`,{children:u(`store.updatedAt`)})]})}),t(Pe,{isLoading:r&&(!e||e.length===0),columns:f?5:4,children:e?.map(e=>n(`tr`,{onClick:()=>d(`/types/${e.id}`),className:`group cursor-pointer hover:bg-muted`,children:[f&&t(`td`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,className:it(`checkbox group-hover:inline-block`,a?.includes(e.id)?`inline-block`:`hidden`),checked:a?.includes(e.id)??!1,"aria-label":u(`store.actions.selectType`,{name:e.name}),onClick:e=>e.stopPropagation(),onChange:t=>s?.(e.id,t.target.checked)})}),t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:e.name}),t(x,{content:e.id,className:I4}),i&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${e.name}`,className:I4,onClick:t=>{t.stopPropagation(),i(`name`,e.name)},children:t(u_,{className:`size-3`})})]})}),t(`td`,{children:e.strict_mode?`Yes`:`No`}),t(`td`,{children:e.is_chunkable?`Yes`:`No`}),t(`td`,{children:t(We,{description:GD(e.updated_at).format(`YYYY-MM-DD HH:mm:ss`),children:GD(e.updated_at).fromNow()})})]},e.id))})]})}function R4({title:e,isOpen:r,onClose:i,okLabel:a,initialPayload:s,isLoading:c}){let{t:l}=K(),u=nt(),[d,f]=G(s?.name),[p,m]=G(s?.description),h=s?.strict_mode??!1,g=()=>{if(!d){u({status:`error`,title:l(`type.nameRequired`),duration:5e3});return}i({name:d,description:p,strict_mode:h}).then(()=>i())};return n(se,{isOpen:r,onClose:()=>i(),children:[t(ue,{children:e}),t(ce,{className:`pt-0`,children:n(`div`,{className:`h-full flex flex-col gap-4 content-between`,children:[n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.name`)}),t(te,{value:d,onChange:f})]}),n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.description`)}),t(Ue,{value:p,onChange:e=>m(e.target.value),minLines:5})]})]})}),t(le,{children:n(`div`,{className:`flex justify-end gap-4`,children:[t(o,{variant:`secondary`,onClick:()=>i(),children:l(`modal.cancel`)}),t(o,{variant:`primary`,onClick:()=>g(),isLoading:c,children:a})]})})]})}var z4=class{client;limit;result=new De({objects:[],isLoading:!1});query={};constructor(e,t=100){this.client=e,this.limit=t}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}async _search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};let t=this.limit,n=this.objects.length;return this.client.types.list({limit:t,offset:n,query:this.query}).then(async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0)).catch(e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e})}search(){return this.isRunning?Promise.resolve(!1):this._search(!1)}loadMore(){return this.isRunning?Promise.resolve(!1):this._search(!0)}};const B4=dt(void 0);function V4(){return _t(B4)}function H4(){let e=V4();return{...rt(e.result),search:e}}function U4(){return V4().objects.length}Q();var W4;(function(e){e.true=`Yes`,e.false=`No`})(W4||={});function G4({isDirty:r=!1}){let{store:i}=q(),{reload:a}=UZ(),{t:s}=K(),c=nt(),[l,u]=G(!1),{search:d,isLoading:f,error:p,objects:m}=H4(),[h,g]=G([]),[_,v]=G(!1),[y,x]=G(!1),S=h.length,C=!!m&&m.length>0&&m.every(e=>h.includes(e.id)),w=m?.filter(e=>h.includes(e.id))??[],T=(e,t)=>{g(n=>t?n.includes(e)?n:[...n,e]:n.filter(t=>t!==e))},E=e=>{g(e&&m?m.map(e=>e.id):[])},D=async()=>{if(!y){x(!0);try{let e=await Promise.allSettled(h.map(e=>i.types.delete(e))),t=e.filter(e=>e.status===`rejected`).length,n=e.length-t;v(!1),g([]),a(),await d.search(),c(t===0?{status:`success`,title:s(`store.actions.typeDeleted`,{count:n}),duration:3e3}:{status:`error`,title:s(`store.actions.typeDeletePartial`,{succeeded:n,failed:t}),duration:5e3})}catch(e){c({status:`error`,title:s(`store.actions.failedToDeleteTypes`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{x(!1)}}},[O,k]=G(``),A=Je(O,500),N=W(null);Qe(N,()=>{l&&d.loadMore()},{deps:[l,d]}),H(()=>{d.search().then(()=>u(!0))},[d]),H(()=>{d.query.name=A,d.search().then(()=>u(!0))},[A,d]);let[P,F]=G(void 0),I=e=>{F(e)};H(()=>{d.query.chunkable=P?P===`Yes`:void 0,d.search().then(()=>u(!0))},[P,d]),H(()=>{r&&l&&d.search().then(()=>u(!0))},[r,l,d]);let[L,ee]=G(!1);return p?t(M,{title:s(`store.failedToFetchTypes`),children:p.message}):n(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[n(`div`,{className:`flex flex-shrink-0 gap-4 items-center`,children:[t(te,{placeholder:s(`store.filterByName`),value:O,onChange:k}),t(we,{className:`w-60`,isClearable:!0,options:Object.values(W4),value:P,onChange:I,placeholder:s(`store.isChunkable`)}),S>0&&n(`div`,{className:`flex items-center gap-2 ms-auto`,children:[t(`span`,{className:`text-sm font-medium whitespace-nowrap`,children:s(`store.actions.selectedCount`,{n:S})}),t(We,{description:s(`store.actions.clearSelection`),asChild:!0,children:t(o,{variant:`ghost`,"aria-label":s(`store.actions.clearSelection`),onClick:()=>g([]),children:t(Kb,{className:`size-4`})})}),t(o,{variant:`destructive`,isDisabled:y,onClick:()=>v(!0),children:s(y?`store.actions.deleting`:`store.actions.deleteSelected`)})]})]}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md my-2`,children:n(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[!f&&m?.length===0?t(j,{title:s(`store.noType`),buttonLabel:s(`store.createType`),onClick:()=>{ee(!0)},children:s(`store.getStartedTypes`)}):n(e,{children:[t(L4,{objects:m,isLoading:f,onFilter:(e,t)=>{e===`name`&&k(t)},selectedIds:h,onToggleOne:T,allSelected:C,onToggleAll:E}),t(`div`,{ref:N,className:`h-4 w-full`})]}),t(R4,{okLabel:`Create`,title:s(`store.createType`),isOpen:L,onClose:async e=>e?i.types.create(e).then(async()=>{c({status:`success`,title:s(`store.typeCreated`),duration:2e3}),a(),d.search().then(()=>u(!0))}).catch(e=>{c({status:`error`,title:s(`store.errorCreatingType`),description:e.message,duration:5e3})}):(ee(!1),Promise.resolve())}),t(b,{isOpen:_,title:s(`store.actions.deleteType`,{count:S}),content:n(`div`,{children:[t(`p`,{children:s(`store.actions.deleteTypeConfirm`,{count:S})}),w.length>0&&n(e,{children:[t(`div`,{className:`mt-2`,children:s(`store.actions.affectedItems`)}),t(`ul`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border p-2 text-sm`,children:w.map(e=>t(`li`,{className:`truncate py-0.5`,children:e.name||e.id},e.id))})]})]}),onConfirm:D,onCancel:()=>v(!1),confirmationValue:`delete`,confirmationLabel:s(`store.actions.typeToConfirmDelete`),confirmationPlaceholder:`delete`})]})})]})}function K4(e,t,n){if(t.length===0)return e;let r=structuredClone(e),i=[r],a=r;for(let e of t.slice(0,-1)){let t=a[e],n=Z4(t)?t:{};a[e]=n,a=n,i.push(a)}let o=t[t.length-1];return n===void 0||n===``?(delete a[o],X4(i,t)):a[o]=n,r}function q4(e,t,n,r){let i=e?.map(e=>[e[0]??1,e[1]??1])??[],a=i[t]??[1,1];return a[n]=r,i[t]=a,i}function J4(e,t){let n={...e,environment:t};return delete n.model,delete n.model_options,Q4(n)?n:void 0}function Y4(e,t){let n={...e,model:t};return t!==e?.model&&delete n.model_options,Q4(n)?n:void 0}function X4(e,t){for(let n=e.length-1;n>0;--n){let r=e[n];if(Object.keys(r).length>0)break;delete e[n-1][t[n-1]]}}function Z4(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Q4(e){return Object.values(e).some(e=>e!==void 0)}Q();function $4({policy:e,section:r,onChange:i,readonly:a=!1}){let{t:o}=K(),s=(t,n)=>i(K4(e,t,n));if(r===`overview`)return n(e3,{children:[n(t3,{title:o(`intakePolicy.section.classification`),description:o(`intakePolicy.help.section.classification`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(a3,{label:o(`intakePolicy.field.mode`),description:o(`intakePolicy.help.mode`),value:e.mode,options:u3(o,[`programmatic`,`agentic`]),onChange:e=>s([`mode`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.defaultView`),value:e.default_view,options:u3(o,[`auto`,`text`,`pdf`,`image`,`properties`]),onChange:e=>s([`default_view`],e),readonly:a})]}),t(r3,{label:o(`intakePolicy.field.identificationGuidance`),description:o(`intakePolicy.help.identificationGuidance`),value:e.identification?.guidance,onChange:e=>s([`identification`,`guidance`],e),readonly:a}),t(r3,{label:o(`intakePolicy.field.distinguishFrom`),description:o(`intakePolicy.help.distinguishFrom`),value:e.identification?.distinguish_from,onChange:e=>s([`identification`,`distinguish_from`],e),readonly:a}),t(L,{label:o(`intakePolicy.field.examples`),description:o(`intakePolicy.help.examples`),children:t(He,{options:e.identification?.examples??[],value:e.identification?.examples??[],onChange:e=>s([`identification`,`examples`],e.length?e:void 0),onOptionsChange:e=>s([`identification`,`examples`],e.length?e:void 0),creatable:!0,disabled:a,placeholder:o(`intakePolicy.placeholder.objectId`)})})]}),n(t3,{title:o(`intakePolicy.section.locate`),description:o(`intakePolicy.help.section.locate`),last:!0,children:[t(r3,{label:o(`intakePolicy.field.locateInstructions`),description:o(`intakePolicy.help.locateInstructions`),value:e.locate?.instructions,onChange:t=>s([`locate`],t?{...e.locate,instructions:t}:void 0),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(a3,{label:o(`intakePolicy.field.contactSheetDetail`),description:o(`intakePolicy.help.contactSheetDetail`),value:e.locate?.detail,options:[{value:8,label:o(`intakePolicy.option.pagesPerSheet`,{count:8})},{value:16,label:o(`intakePolicy.option.pagesPerSheet`,{count:16})}],onChange:e=>s([`locate`,`detail`],e),readonly:a||!e.locate}),t(i3,{label:o(`intakePolicy.field.locateMinPages`),description:o(`intakePolicy.help.locateMinPages`),value:e.locate?.min_pages,min:0,onChange:e=>s([`locate`,`min_pages`],e),readonly:a||!e.locate})]})]})]});if(r===`conversion`)return n(e3,{children:[n(t3,{title:o(`intakePolicy.section.conversion`),description:o(`intakePolicy.help.section.conversion`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(o3,{label:o(`intakePolicy.field.enabled`),value:e.text_conversion?.enabled,onChange:e=>s([`text_conversion`,`enabled`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.method`),description:o(`intakePolicy.help.method`),value:e.text_conversion?.method,options:u3(o,[`auto`,`basic`,`llm`,`custom`]),onChange:e=>s([`text_conversion`,`method`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.outputFormat`),value:e.text_conversion?.output_format,options:u3(o,[`markdown`,`text`]),onChange:e=>s([`text_conversion`,`output_format`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.text_conversion?.scope,options:u3(o,[`all`,`located`]),onChange:e=>s([`text_conversion`,`scope`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.renderDpi`),description:o(`intakePolicy.help.renderDpi`),value:e.text_conversion?.render_dpi,min:72,onChange:e=>s([`text_conversion`,`render_dpi`],e),readonly:a})]}),t(r3,{label:o(`intakePolicy.field.instructions`),value:e.text_conversion?.instructions,onChange:e=>s([`text_conversion`,`instructions`],e),readonly:a})]}),t(t3,{title:o(`intakePolicy.section.conversionModel`),description:o(`intakePolicy.help.section.conversionModel`),children:t(l3,{title:o(`intakePolicy.field.model`),config:e.text_conversion?.config,onChange:e=>s([`text_conversion`,`config`],e),readonly:a})}),e.text_conversion?.method===`custom`&&t(t3,{title:o(`intakePolicy.section.customConversion`),description:o(`intakePolicy.help.section.customConversion`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(n3,{label:o(`intakePolicy.field.interaction`),value:e.text_conversion.custom?.interaction,onChange:e=>s([`text_conversion`,`custom`,`interaction`],e),readonly:a}),t(n3,{label:o(`intakePolicy.field.agent`),value:e.text_conversion.custom?.agent,onChange:e=>s([`text_conversion`,`custom`,`agent`],e),readonly:a})]})}),t(t3,{title:o(`intakePolicy.section.pageRanges`),description:o(`intakePolicy.help.section.pageRanges`),last:!0,children:t(c3,{value:e.text_conversion?.page_ranges,onChange:e=>s([`text_conversion`,`page_ranges`],e),readonly:a})})]});if(r===`extraction`)return n(e3,{children:[n(t3,{title:o(`intakePolicy.section.extraction`),description:o(`intakePolicy.help.section.extraction`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(o3,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.enabled,onChange:e=>s([`extraction`,`enabled`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.source`),description:o(`intakePolicy.help.extractionSource`),value:e.extraction?.source,options:u3(o,[`auto`,`text`,`vision`,`mixed`]),onChange:e=>s([`extraction`,`source`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.extraction?.scope,options:u3(o,[`all`,`located`]),onChange:e=>s([`extraction`,`scope`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.maxPages`),description:o(`intakePolicy.help.extractionMaxPages`),value:e.extraction?.max_pages,min:1,onChange:e=>s([`extraction`,`max_pages`],e),readonly:a})]}),t(n3,{label:o(`intakePolicy.field.interaction`),description:o(`intakePolicy.help.extractionInteraction`),value:e.extraction?.interaction,onChange:e=>s([`extraction`,`interaction`],e),readonly:a}),t(r3,{label:o(`intakePolicy.field.instructions`),value:e.extraction?.instructions,onChange:e=>s([`extraction`,`instructions`],e),readonly:a}),t(c3,{value:e.extraction?.page_ranges,onChange:e=>s([`extraction`,`page_ranges`],e),readonly:a})]}),t(t3,{title:o(`intakePolicy.section.extractionModel`),description:o(`intakePolicy.help.section.extractionModel`),children:t(l3,{title:o(`intakePolicy.field.model`),config:e.extraction?.config,onChange:e=>s([`extraction`,`config`],e),readonly:a})}),t(t3,{title:o(`intakePolicy.section.visionBudget`),description:o(`intakePolicy.help.section.visionBudget`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(a3,{label:o(`intakePolicy.field.defaultDetail`),description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.default_detail,options:u3(o,[`low`,`standard`,`high`]),onChange:e=>s([`extraction`,`vision`,`default_detail`],e),readonly:a}),t(s3,{description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.allowed_details,onChange:e=>s([`extraction`,`vision`,`allowed_details`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.maxImageTokens`),description:o(`intakePolicy.help.maxImageTokens`),value:e.extraction?.vision?.max_image_tokens,min:1,onChange:e=>s([`extraction`,`vision`,`max_image_tokens`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.maxPayloadMb`),description:o(`intakePolicy.help.maxPayloadMb`),value:e.extraction?.vision?.max_payload_mb,min:1,onChange:e=>s([`extraction`,`vision`,`max_payload_mb`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.maxPagesPerCall`),value:e.extraction?.vision?.max_pages_per_call,min:1,onChange:e=>s([`extraction`,`vision`,`max_pages_per_call`],e),readonly:a})]})}),n(t3,{title:o(`intakePolicy.section.verification`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(o3,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.verification?.enabled,onChange:e=>s([`extraction`,`verification`,`enabled`],e),readonly:a}),t(n3,{label:o(`intakePolicy.field.model`),value:e.extraction?.verification?.model,onChange:e=>s([`extraction`,`verification`,`model`],e),readonly:a}),t(n3,{label:o(`intakePolicy.field.environment`),value:e.extraction?.verification?.environment,onChange:e=>s([`extraction`,`verification`,`environment`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.threshold`),value:e.extraction?.verification?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`verification`,`threshold`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.maxRetries`),value:e.extraction?.verification?.max_retries,min:0,onChange:e=>s([`extraction`,`verification`,`max_retries`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.onFailure`),value:e.extraction?.verification?.on_fail,options:u3(o,[`flag`,`block`]),onChange:e=>s([`extraction`,`verification`,`on_fail`],e),readonly:a})]}),t(r3,{label:o(`intakePolicy.field.materiality`),value:e.extraction?.verification?.materiality,onChange:e=>s([`extraction`,`verification`,`materiality`],e),readonly:a})]})]});if(r===`grounding`){let r=e.extraction?.grounding,i=r?.review;return n(e3,{children:[n(t3,{title:o(`intakePolicy.section.grounding`),description:o(`intakePolicy.help.section.grounding`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(o3,{label:o(`intakePolicy.field.enabled`),value:r?.enabled,onChange:e=>s([`extraction`,`grounding`,`enabled`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.maxPages`),value:r?.max_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`max_pages`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.windowPages`),description:o(`intakePolicy.help.windowPages`),value:r?.window_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`window_pages`],e),readonly:a}),t(n3,{label:o(`intakePolicy.field.interaction`),value:r?.interaction,onChange:e=>s([`extraction`,`grounding`,`interaction`],e),readonly:a})]}),n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(o3,{label:o(`intakePolicy.field.useVision`),description:o(`intakePolicy.help.useVision`),value:r?.use_vision,onChange:e=>s([`extraction`,`grounding`,`use_vision`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.forceOcr`),description:o(`intakePolicy.help.forceOcr`),value:r?.force_ocr,onChange:e=>s([`extraction`,`grounding`,`force_ocr`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.refreshOcr`),description:o(`intakePolicy.help.refreshOcr`),value:r?.refresh_ocr,onChange:e=>s([`extraction`,`grounding`,`refresh_ocr`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.omitBlockBoxes`),description:o(`intakePolicy.help.omitBlockBoxes`),value:r?.omit_block_boxes,onChange:e=>s([`extraction`,`grounding`,`omit_block_boxes`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.updateProperties`),description:o(`intakePolicy.help.updateProperties`),value:r?.update_properties,onChange:e=>s([`extraction`,`grounding`,`update_properties`],e),readonly:a})]})]}),n(t3,{title:o(`intakePolicy.section.models`),description:o(`intakePolicy.help.section.models`),children:[t(l3,{title:o(`intakePolicy.field.primaryModel`),config:r?.config,onChange:e=>s([`extraction`,`grounding`,`config`],e),readonly:a}),t(l3,{title:o(`intakePolicy.field.hardModel`),config:r?.hard_config,onChange:e=>s([`extraction`,`grounding`,`hard_config`],e),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(i3,{label:o(`intakePolicy.field.hardnessThreshold`),description:o(`intakePolicy.help.hardnessThreshold`),value:r?.hardness_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`hardness_threshold`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.minCitationDensity`),description:o(`intakePolicy.help.minCitationDensity`),value:r?.min_citation_density,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`min_citation_density`],e),readonly:a})]})]}),n(t3,{title:o(`intakePolicy.section.review`),description:o(`intakePolicy.help.section.review`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(o3,{label:o(`intakePolicy.field.enabled`),value:i?.enabled,onChange:e=>s([`extraction`,`grounding`,`review`,`enabled`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.forceReview`),description:o(`intakePolicy.help.forceReview`),value:i?.force,onChange:e=>s([`extraction`,`grounding`,`review`,`force`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.reviewThreshold`),value:i?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`threshold`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.coverageThreshold`),description:o(`intakePolicy.help.coverageThreshold`),value:i?.coverage_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`coverage_threshold`],e),readonly:a})]}),t(l3,{title:o(`intakePolicy.field.reviewModel`),config:i?.config,onChange:e=>s([`extraction`,`grounding`,`review`,`config`],e),readonly:a})]})]})}return n(e3,{children:[t(t3,{title:o(`intakePolicy.section.rendering`),description:o(`intakePolicy.help.section.rendering`),children:t(r3,{label:o(`intakePolicy.field.renderingTemplate`),description:o(`intakePolicy.help.renderingTemplate`),value:e.rendering_template,onChange:e=>s([`rendering_template`],e),readonly:a,monospace:!0,minLines:8})}),t(t3,{title:o(`intakePolicy.section.embeddings`),description:o(`intakePolicy.help.section.embeddings`),last:!0,children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(o3,{label:o(`intakePolicy.field.textEmbedding`),value:e.embeddings?.text,onChange:e=>s([`embeddings`,`text`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.imageEmbedding`),value:e.embeddings?.image,onChange:e=>s([`embeddings`,`image`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.propertiesEmbedding`),value:e.embeddings?.properties,onChange:e=>s([`embeddings`,`properties`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.generateToc`),value:e.generate_toc,onChange:e=>s([`generate_toc`],e),readonly:a})]})})]})}function e3({children:e}){return t(`div`,{className:`mx-auto w-full max-w-6xl px-1 py-4`,children:e})}function t3({title:e,description:r,children:i,last:a=!1}){return n(`section`,{className:a?`pb-3`:`mb-6 border-b pb-6`,children:[n(`div`,{className:`mb-4 flex items-center gap-2`,children:[t(`h3`,{className:`text-sm font-semibold`,children:e}),t(R,{description:r})]}),t(`div`,{className:`space-y-4`,children:i})]})}function n3({label:e,value:n,onChange:r,readonly:i,description:a}){return t(L,{label:e,description:a,children:t(te,{value:n??``,onChange:e=>r(e||void 0),disabled:i})})}function r3({label:e,value:n,onChange:r,readonly:i,description:a,minLines:o=3,monospace:s=!1}){return t(L,{label:e,description:a,children:t(Ue,{value:n??``,onChange:e=>r(e.target.value||void 0),disabled:i,minLines:o,maxLines:14,className:s?`font-mono`:void 0})})}function i3({label:e,description:n,value:r,onChange:i,readonly:a,min:o,max:s,step:c}){return t(L,{label:e,description:n,children:t(de,{value:r,onChange:e=>i(e===void 0||Number.isFinite(e)?e:void 0),disabled:a,min:o,max:s,step:c??1,noScroll:!0})})}function a3({label:e,description:n,value:r,options:i,onChange:a,readonly:o}){let{t:s}=K(),c=[{value:`__inherit__`,label:s(`intakePolicy.option.inherit`)},...i],l=c.find(e=>e.value===r)??c[0];return t(L,{label:e,description:n,children:t(we,{options:c,value:l,by:`value`,optionLabel:e=>e.label,onChange:e=>a(e.value===`__inherit__`?void 0:e.value),disabled:o})})}function o3({label:e,description:n,value:r,onChange:i,readonly:a}){let{t:o}=K(),s=[{value:`inherit`,label:o(`intakePolicy.option.inherit`)},{value:`enabled`,label:o(`intakePolicy.option.enabled`)},{value:`disabled`,label:o(`intakePolicy.option.disabled`)}],c=r===void 0?`inherit`:r?`enabled`:`disabled`;return t(L,{label:e,description:n,children:t(we,{options:[...s],value:s.find(e=>e.value===c),by:`value`,optionLabel:e=>e.label,onChange:e=>i(e.value===`inherit`?void 0:e.value===`enabled`),disabled:a})})}function s3({description:e,value:n,onChange:r,readonly:i}){let{t:a}=K(),o=u3(a,[`low`,`standard`,`high`]);return t(L,{label:a(`intakePolicy.field.allowedDetails`),description:e,children:t(we,{multiple:!0,options:o,value:o.filter(e=>n?.includes(e.value)),by:`value`,optionLabel:e=>e.label,onChange:e=>r(e.length?e.map(e=>e.value):void 0),disabled:i})})}function c3({value:e,onChange:r,readonly:i}){let{t:a}=K(),s=t=>{let n=e?.filter((e,n)=>n!==t);r(n?.length?n:void 0)};return t(L,{label:a(`intakePolicy.field.pageRanges`),description:a(`intakePolicy.help.pageRanges`),children:n(`div`,{className:`space-y-2`,children:[e?.map((c,l)=>n(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] gap-2`,children:[t(de,{"aria-label":a(`intakePolicy.field.rangeStart`),value:c[0],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(q4(e,l,0,t))},disabled:i,step:1,noScroll:!0}),t(de,{"aria-label":a(`intakePolicy.field.rangeEnd`),value:c[1],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(q4(e,l,1,t))},disabled:i,step:1,noScroll:!0}),t(We,{description:a(`intakePolicy.action.removeRange`),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`intakePolicy.action.removeRange`),onClick:()=>s(l),disabled:i,children:t(gb,{className:`size-4`})})})]},`${l}`)),n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...e??[],[1,1]]),disabled:i,children:[t(sy,{className:`size-4`}),a(`intakePolicy.action.addRange`)]})]})})}function l3({title:e,config:r,onChange:i,readonly:a}){let{t:o}=K();return n(`div`,{children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:e}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(L,{label:o(`intakePolicy.field.environment`),children:t(F1,{selectedEnvId:r?.environment,onChange:e=>i(J4(r,e?.id)),isClearable:!0,disabled:a})}),t(L,{label:o(`intakePolicy.field.model`),children:t(R1,{envId:r?.environment,selectedModelId:r?.model,onChange:e=>i(Y4(r,e?.id)),isClearable:!0,disabled:a||!r?.environment})})]})]})}function u3(e,t){return t.map(t=>({value:t,label:e(`intakePolicy.option.${t}`)}))}Q();const d3=[{key:`minimal`,value:{identification:{guidance:`Documents that match this content type.`,distinguish_from:`Do not select this type for unrelated documents.`}}},{key:`extraction_only`,value:{text_conversion:{enabled:!1},extraction:{enabled:!0,source:`vision`,instructions:`Extract required fields only. Ignore cover pages, appendices, legal boilerplate, and marketing content.`},rendering_template:`# {{properties.title}}
1394
+ + `)||e.includes(`![`)||e.includes(`](`):!1}function a4(e){return e?`h-full overflow-auto`:`hidden`}var o4;(function(e){e.Text=`text`,e.Image=`image`,e.Video=`video`,e.Audio=`audio`,e.Pdf=`pdf`,e.Transcript=`transcript`})(o4||={});function s4({object:r,loadText:i,refetch:a,canEditProperties:o=!0,canCollaborate:s=!1}){let c=nt(),{t:l}=K(),{project:u,store:d}=q(),f=$n(),p=r.revision?.root||r.id,m=u?.id?b2(u.id,p):void 0,[h,g]=G(r),[_,v]=G(()=>m?x2(m):!1),y=W(null),b=W(r.id),x=W(r.id),S=W(m);H(()=>{S.current!==m&&(S.current=m,v(m?x2(m):!1))},[m]);let C=V(()=>{v(e=>{let t=!e;return m&&S2(m,t),t})},[m]),w=V(()=>{m&&S2(m,!1),v(!1)},[m]);H(()=>{let e=x.current!==r.id;x.current=r.id,g(t=>!e&&t.id!==r.id?t:(b.current=r.id,t.id===r.id&&t.text&&!r.text?{...r,text:t.text}:r))},[r]);let T=V(async(e,t)=>{b.current=e;try{let[t,n]=await Promise.all([d.objects.retrieve(e),d.objects.getObjectText(e)]);b.current===e&&g({...t,text:n.text})}catch(e){console.error(`Failed to load the updated document revision`,e),c({status:`error`,title:l(`agent.failedToLoadDocument`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{t&&f(`/objects/${e}`)}},[f,d.objects,l,c]),E=async(e,t)=>{try{await navigator.clipboard.writeText(e),c({status:`success`,title:l(`store.contentCopied`,{type:l(t===`text`?`store.contentType`:`store.properties`)}),description:l(`store.successfullyCopied`,{type:t}),duration:2e3})}catch(e){console.error(`Failed to copy ${t}:`,e),c({status:`error`,title:l(`store.copyFailed`),description:l(`store.failedToCopy`,{type:t}),duration:5e3})}};return n(e,{children:[n(Ce,{direction:`horizontal`,className:`h-full`,children:[t(Se,{defaultSize:67,className:`min-w-[100px]`,children:t(l4,{object:h,loadText:i??!1,handleCopyContent:E,refetch:a,canCollaborate:s,isCollaborating:_,onToggleCollaborate:C})}),t(xe,{withHandle:!0}),t(Se,{defaultSize:33,className:`min-w-[100px]`,children:t(c4,{object:h,refetch:a??(()=>Promise.resolve()),handleCopyContent:E,canEditProperties:o})})]}),_?t(K2,{object:h,initialContent:h.text??``,onClose:w,onDocumentUpdated:(e,t)=>void T(e,t),sendMessageRef:y}):null]})}function c4({object:r,refetch:i,handleCopyContent:a,canEditProperties:s}){let{t:c}=K(),[l,u]=G(!1),[d,f]=G(!1);return n(e,{children:[n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted mb-2 p-1 rounded`,children:[t(o,{variant:`${l?`ghost`:`primary`}`,size:`sm`,title:c(`store.previewProperties`),onClick:()=>u(!l),children:`Properties`}),t(o,{variant:`${l?`primary`:`ghost`}`,size:`sm`,title:c(`store.viewInJsonFormat`),onClick:()=>u(!l),children:`JSON`})]}),n(`div`,{className:`flex items-center gap-2`,children:[r.properties&&t(o,{variant:`ghost`,size:`sm`,title:`Copy properties`,onClick:()=>a(JSON.stringify(r.properties,null,2),`properties`),children:t(pg,{className:`size-4`})}),s&&t(Z0,{permission:bn.content_write,variant:`ghost`,size:`sm`,onClick:()=>{f(!0)},title:`Edit properties`,className:`flex items-center gap-2`,children:t(Qy,{className:`size-4`})})]})]}),r.properties?t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(jt,{value:r.properties,viewCode:l})}):t(`div`,{className:`flex-1 min-h-0 px-2`,children:t(`div`,{children:c(`store.noPropertiesDefined`)})})]}),t(q2,{isOpen:d,onClose:()=>{f(!1)},object:r,refetch:i})]})}function l4(e){let{client:n}=q(),r=e.object.type,i=r?.id,a=r?.default_view,{data:o}=Ye(async()=>!i||a?null:(await e2(n,i))?.intake?.default_view??null,[i,a]),s=a??o;return i&&!a&&o===void 0?t(`div`,{className:`flex h-full items-center justify-center`,children:t(je,{size:`lg`})}):t(u4,{...e,defaultView:s??void 0})}function u4({object:e,loadText:r,handleCopyContent:i,refetch:a,defaultView:s,canCollaborate:c,isCollaborating:l,onToggleCollaborate:u}){let{client:d}=q(),{t:f}=K(),p=e?.metadata?.type===dn.Image,m=e?.metadata?.type===dn.Video,h=e?.metadata?.type===dn.Audio,g=e?.content?.type===`application/pdf`,_=e?.content?.type?r$(e.content.type):!1,v=n4(e?.status),y=!!(e.transcript&&(m||h)),b=e.metadata?.renditions?.find(e=>e.name===vn),x=()=>{switch(s){case`text`:return o4.Text;case`pdf`:if(g||_||b)return o4.Pdf;break;case`image`:if(p)return o4.Image;break;case`properties`:return o4.Text}return m?o4.Video:h?o4.Audio:p?o4.Image:o4.Text},S=r0(e.id),[C,w]=G(x()),[T,E]=G(C===o4.Pdf);H(()=>{C===o4.Pdf&&E(!0)},[C]);let[D,O]=G(!1),k=D2(!!(e.content?.type&&!e.is_locked&&e.user_permissions?.can_write!==!1&&(e.content.type.startsWith(`text/`)||e.content.type===`application/json`||e.content.type===`application/xml`)),c),{fullText:A,displayText:j,isLoading:M,isCropped:N,loadText:P}=Q2(e.id,e.text,r,e.revision?.root||e.id),F=(g||_)&&v&&(C===o4.Text||C===o4.Pdf),{progress:I,status:L,isComplete:ee}=$2(e.id,F),{pdfUrl:R,isConverting:te,error:ne,triggerConversion:re}=e4(e.id,_),ie=U(()=>[{id:`office-pdf-rendition`,target:`pdf`,canConvert:({contentType:e,extension:t})=>_||(e?r$(e):!1)||[`doc`,`docx`,`ppt`,`pptx`].includes(t),convert:async()=>{let t=await d.objects.getRendition(e.id,{format:_n.pdf,generate_if_missing:!0,sign_url:!0,block_on_generation:!0});return t.status===`found`&&t.renditions?.length?{url:t.renditions[0],contentType:`application/pdf`,fileName:`${e.name||`document`}.pdf`}:null}}],[d,_,e.id,e.name]);H(()=>{ee&&L===En.COMPLETED&&P()},[ee,L,P]);let ae=(g||_)&&v&&!ee&&L===En.RUNNING,oe=C===o4.Pdf&&!ae,se=ae&&(C===o4.Text||C===o4.Pdf),ce=T&&!ae,le=W(null);return n(`div`,{className:`flex flex-col h-full`,children:[n(`div`,{className:`flex justify-between items-center px-2 shrink-0`,children:[n(`div`,{className:`flex items-center gap-2 mb-2`,children:[n(`div`,{className:`flex items-center gap-1 bg-muted p-1 rounded`,children:[p&&t(o,{variant:C===o4.Image?`primary`:`ghost`,size:`sm`,title:f(`store.viewImage`),onClick:()=>w(o4.Image),children:`Image`}),m&&t(o,{variant:C===o4.Video?`primary`:`ghost`,size:`sm`,title:f(`store.viewVideo`),onClick:()=>w(o4.Video),children:`Video`}),h&&t(o,{variant:C===o4.Audio?`primary`:`ghost`,size:`sm`,title:f(`store.viewAudio`),onClick:()=>w(o4.Audio),children:`Audio`}),y&&t(o,{variant:C===o4.Transcript?`primary`:`ghost`,size:`sm`,title:f(`store.viewTranscript`),onClick:()=>w(o4.Transcript),children:`Transcript`}),t(o,{variant:C===o4.Text?`primary`:`ghost`,size:`sm`,title:f(`store.viewText`),onClick:()=>w(o4.Text),children:`Text`}),g&&t(o,{variant:C===o4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewPdf`),onClick:()=>w(o4.Pdf),children:`PDF`}),_&&t(o,{variant:C===o4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewAsPdf`),onClick:()=>{w(o4.Pdf),!b&&!R&&!te&&re()},disabled:te,children:te?t(je,{size:`sm`}):`PDF`})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(m4,{object:e}),t(h4,{objectId:e.id,available:S})]})]}),C===o4.Text&&!ae&&!D&&t(d4,{object:e,text:j,fullText:A,handleCopyContent:i,textContainerRef:le,isEditing:D,onToggleEdit:()=>O(!0),canEdit:k.canEdit,isCollaborating:l,onToggleCollaborate:u,canCollaborate:k.canCollaborate}),C===o4.Pdf&&_&&(b||R)&&t(g4,{object:e,pdfRendition:b,officePdfUrl:R})]}),C===o4.Image&&t(`div`,{className:a4(!0),children:t(B0,{object:e})}),C===o4.Video&&t(`div`,{className:a4(!0),children:t(V0,{object:e})}),C===o4.Audio&&t(`div`,{className:a4(!0),children:t(z0,{object:e})}),y&&C===o4.Transcript&&t(`div`,{className:a4(!0),children:t(p4,{object:e,handleCopyContent:i})}),g&&ce&&t(`div`,{className:a4(oe),children:t(_4,{object:e})}),_&&ce&&t(`div`,{className:a4(oe),children:t(v4,{object:e,pdfRendition:b,officePdfUrl:R,converters:ie,officePdfConverting:te,officePdfError:ne})}),se&&t(`div`,{className:a4(!0),children:t(y4,{progress:I,status:L})}),C===o4.Text&&!ae&&!D&&M&&!j&&t(`div`,{className:a4(!0),children:t(`div`,{className:`flex justify-center items-center flex-1`,children:t(je,{size:`lg`})})}),C===o4.Text&&!ae&&!D&&(!M||j)&&t(`div`,{className:a4(!0),children:t(f4,{object:e,text:j,isTextCropped:N,textContainerRef:le})}),D&&C===o4.Text&&A!=null&&t(X2,{object:e,text:A,onClose:()=>O(!1),onSaved:()=>{O(!1),P(),a?.()}})]})}function d4({object:r,text:i,fullText:a,handleCopyContent:s,onToggleEdit:c,canEdit:l,isCollaborating:u,onToggleCollaborate:d,canCollaborate:f}){let{client:p,project:m}=q(),h=nt(),{t:g}=K(),_=r.content,{renderDocument:v,isDownloading:y}=eG({client:p,toast:h}),{data:b}=Ye(()=>m?p.projects.retrieve(m.id):Promise.resolve(void 0),[m?.id]),x=b?.configuration?.pdf_template_object_id??void 0,S=k2(_?.type),C=A2(_?.type),T=async(e,t)=>{if(y)return;h({status:`info`,title:`Preparing ${e.toUpperCase()}`,description:g(`store.renderingDocument`),duration:2e3});let n=t===!1?void 0:x;await v(r.id,{format:e,title:r.name||`document`,useDefaultTemplate:t,templateObjectId:n})};return t(`div`,{className:`h-[41px] text-lg font-semibold flex justify-between items-center px-2`,children:n(`div`,{className:`flex items-center gap-2`,children:[a&&t(o,{variant:`ghost`,size:`sm`,title:`Copy text`,onClick:()=>s(a,`text`),children:t(pg,{className:`size-4`})}),y?t(o,{variant:`ghost`,size:`sm`,disabled:!0,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(je,{size:`sm`})}):n(w,{trigger:t(o,{variant:`ghost`,size:`sm`,disabled:!i,className:`h-8 w-8 p-0`,title:g(`agent.download`),"aria-label":g(`agent.download`),children:t(Sg,{className:`size-4`})}),children:[a&&t(ae,{onClick:e=>{if(e.preventDefault(),e.stopPropagation(),!a)return;let t=`txt`,n=`text/plain`;_?.type===`application/xml`||_?.type===`text/xml`?(t=`xml`,n=`text/xml`):S&&(t=`md`,n=`text/markdown`);let i=new Blob([a],{type:n}),o=URL.createObjectURL(i),s=`${r.name||`document`}.${t}`,c=document.createElement(`a`);c.href=o,c.download=s,c.style.display=`none`,setTimeout(()=>{c.click(),URL.revokeObjectURL(o)},0)},children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Download Text`]})}),S&&i&&n(e,{children:[t(ae,{onClick:()=>T(_n.docx),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Export as DOCX`]})}),t(ae,{onClick:()=>T(_n.pdf,!1),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Export as PDF`]})}),t(ae,{onClick:()=>T(_n.pdf),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Sg,{className:`size-4`}),`Export as Branded PDF`]})})]})]}),a&&n(e,{children:[l&&c&&t(Z0,{permission:bn.content_write,variant:`ghost`,size:`sm`,onClick:c,title:g(`store.editText`),"aria-label":g(`store.editText`),className:`h-8 w-8 p-0`,children:t(Qy,{className:`size-4`})}),f&&d&&C&&t(o,{variant:u?`primary`:`ghost`,size:`sm`,onClick:d,title:g(`agent.editWithAI`),"aria-label":g(`agent.editWithAI`),className:`h-8 w-8 p-0`,children:t(Yy,{className:`size-4`})})]})]})})}const f4=gt(({object:r,text:i,isTextCropped:a,textContainerRef:o})=>{let{t:s}=K(),c=n4(r?.status),l=r.content,u=r4(r)===`xml`||l?.type===`application/xml`||l?.type===`text/xml`,d=A2(l?.type),f=!u&&(d||i4(i)),p={id:r.id,title:r.name,fileName:r.content?.name||r.name,contentType:u?`text/xml`:f?`text/markdown`:r.content?.type,content:i,sourcePath:r.content?.source};return i?n(e,{children:[a&&t(`div`,{className:`px-2 py-2 bg-attention/10 border-s-4 border-attention mx-2 mb-2 rounded`,children:n(`div`,{className:`flex items-center gap-2 text-attention`,children:[t(yb,{className:`size-4`}),t(`span`,{className:`text-sm font-semibold`,children:s(`store.showingFirst128K`)})]})}),t(`div`,{className:`max-w-7xl px-2 h-full overflow-auto`,ref:o,children:t(qY,{source:p,className:`h-full`,bodyClassName:`overflow-auto`,markdownComponents:t4()})})]}):t(`div`,{className:`px-2`,children:t(`div`,{children:c?`Extracting content...`:`No content`})})});function p4({object:e,handleCopyContent:r}){let{t:i}=K(),a=e.transcript,s=a?.text,c=a?.segments,l=s||(c?c.map(e=>e.text).join(` `):``),u=e=>{let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=Math.floor(e%60);return t>0?`${t}:${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`:`${n}:${r.toString().padStart(2,`0`)}`};return n(`div`,{className:`flex flex-col h-full`,children:[t(`div`,{className:`flex justify-end items-center px-2 mb-2`,children:l&&t(o,{variant:`ghost`,size:`sm`,title:`Copy transcript`,onClick:()=>r(l,`text`),children:t(pg,{className:`size-4`})})}),t(`div`,{className:`h-full} overflow-auto px-2`,children:c&&c.length>0?t(`div`,{className:`space-y-2`,children:c.map((e,r)=>n(`div`,{className:`flex gap-3 text-sm`,children:[n(`span`,{className:`text-muted font-mono text-xs shrink-0 pt-0.5`,children:[u(e.start),e.end&&` - ${u(e.end)}`]}),t(`span`,{className:`flex-1`,children:e.text})]},`segment-${r}`))}):s?t(`pre`,{className:`text-wrap bg-muted text-muted p-2 whitespace-pre-wrap`,children:s}):t(`div`,{className:`text-muted`,children:i(`store.noTranscriptAvailable`)})})]})}function m4({object:r}){let[i,a]=G(!1);return r4(r)===`markdown`?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>a(!0),title:`Side by side view`,children:t(Ug,{className:`size-4`})}),i&&t(ve,{children:t(N0,{objectId:r.id,onClose:()=>a(!1)})})]}):null}function h4({objectId:r,available:i}){let{t:a}=K(),[s,c]=G(!1);return i?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>c(!0),title:a(`grounded.title`),"aria-label":a(`grounded.title`),children:t(Oy,{className:`size-4`})}),s&&t(ve,{children:t(o0,{objectId:r,onClose:()=>c(!1)})})]}):null}function g4({object:e,pdfRendition:n,officePdfUrl:r}){let{client:i}=q(),a=nt(),{t:s}=K(),[c,l]=G(!1);return t(`div`,{className:`flex items-center gap-2`,children:t(o,{variant:`ghost`,size:`sm`,onClick:async()=>{l(!0);try{let t=r;!t&&n?.content?.source&&(t=(await i.files.getDownloadUrl(n.content.source,`${e.name||`document`}.pdf`,`attachment`)).url),t&&window.open(t,`_blank`)}catch(e){console.error(`Failed to download PDF:`,e),a({status:`error`,title:s(`store.downloadFailed`),description:s(`store.failedToDownloadPdf`),duration:5e3})}finally{l(!1)}},disabled:c,title:`Download PDF`,children:c?t(je,{size:`sm`}):t(Sg,{className:`size-4`})})})}function _4({object:e}){let n={id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source};return t(`div`,{className:`h-full`,children:t(qY,{source:n,className:`h-full`,showHeader:!1})})}function v4({object:e,pdfRendition:r,officePdfUrl:i,converters:a,officePdfConverting:o,officePdfError:s}){let{t:c}=K();if(o)return n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2`,children:[t(je,{size:`lg`}),t(`span`,{className:`text-muted`,children:c(`store.convertingToPdf`)})]});if(s)return n(`div`,{className:`flex flex-col justify-center items-center flex-1 gap-2 text-destructive`,children:[t(yb,{className:`size-8`}),t(`span`,{children:s})]});if(r?.content?.source){let n={id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,sourcePath:r.content.source};return t(`div`,{className:`h-full`,children:t(qY,{source:n,className:`h-full`})})}if(i){let n={id:e.id,title:e.name,fileName:`${e.name||`document`}.pdf`,contentType:`application/pdf`,url:i};return t(`div`,{className:`h-full`,children:t(qY,{source:n,className:`h-full`})})}let l={id:e.id,title:e.name,fileName:e.content?.name||e.name,contentType:e.content?.type,sourcePath:e.content?.source};return t(`div`,{className:`h-full`,children:t(qY,{source:l,converters:a,className:`h-full`})})}function y4({progress:r,status:i}){let{t:a}=K(),o=u$(i),s=d$(i),c=r?.phase===`grounded_extraction`,l=r?.percent!=null&&!Number.isNaN(r.percent)?r.percent:0;return n(`div`,{className:`px-4 py-4`,children:[r&&n(`div`,{className:`space-y-2`,children:[n(`div`,{className:`flex flex-col gap-1`,children:[t(b4,{name:c?`Prepare Evidence`:`Analyze Page`,progress:r.pages}),c&&n(e,{children:[t(b4,{name:`Run OCR`,progress:r.images}),t(b4,{name:`Extract Grounded Data`,progress:r.tables}),t(b4,{name:`Review and Annotate`,progress:r.visuals})]})]}),n(`div`,{className:`pt-2 text-sm text-muted`,children:[`Progress: `,l,`%`,t(`span`,{className:`px-2`,children:`•`}),t(`span`,{className:o,children:s}),r.started_at&&n(e,{children:[t(`span`,{className:`px-2`,children:`•`}),n(`span`,{children:[((Date.now()-r.started_at)/1e3).toFixed(0),` sec. elapsed`]})]})]}),t(Ft,{percent:l})]}),!r&&n(`div`,{className:`flex items-center gap-2 text-muted`,children:[t(je,{size:`sm`}),t(`span`,{children:a(`store.loadingProcessingStatus`)})]})]})}function b4({name:e,progress:t}){return n(`div`,{className:`flex gap-2 text-sm`,children:[n(`span`,{className:`text-muted min-w-36`,children:[e,`:`]}),n(`span`,{children:[t.processed,` of `,t.total]})]})}Q();const x4=Object.values(Sn),S4=Object.values(wn);function C4({onChange:e,isLoading:r,refresh:i,searchTypes:a}){let{client:s,project:c}=q(),{t:l}=K(),u=nt(),[d,f]=G(void 0),[p,h]=G(void 0),g=!!c&&(!!p?.embeddings.text||!!p?.embeddings.image),[_,v]=G(void 0),y=W(i),b=W(void 0),[x,S]=G(!1),[C,w]=G(a||x4),[T,E]=G(100);H(()=>{a&&w(a)},[a]);let D={},O=!1,k=!1;C.forEach(e=>{e===Sn.full_text?O=!0:k=!0,S4.includes(e)&&(D[e]=!0)}),H(()=>{y.current!==i&&(y.current=i,f(void 0),v(void 0))}),H(()=>{c&&s.projects.retrieve(c.id).then(e=>{h(e.configuration)})},[s.projects.retrieve,c]),H(()=>{_&&u({title:_,status:`success`,duration:2e3})},[_,u]),H(()=>{let t=b.current;b.current=d,t&&(!d||d.length===0)&&e(void 0)},[e,d]);let A=()=>{!g||!d||(e({vector:k?{text:d,config:D}:void 0,full_text:O?d:void 0,limit:T}),v(`Searching...`))},j=e=>{e.key===`Enter`&&A()},M=e=>t=>{w(t?t=>Array.from(new Set([...t,e])):t=>t.filter(t=>t!==e))};return n(`div`,{className:`flex gap-1 items-center`,children:[t(te,{placeholder:l(`store.searchPlaceholder`),value:d,onChange:f,onKeyDown:j,className:`min-w-[200px]`}),t(o,{variant:`ghost`,onClick:()=>S(!0),title:l(`store.semanticSearchSettings`),className:`ms-1`,children:t(Ly,{size:18})}),n(se,{isOpen:x,onClose:()=>S(!1),children:[t(ue,{children:l(`store.searchTypes`)}),t(ce,{children:n(`div`,{className:`flex flex-col gap-2`,children:[n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-full_text`,checked:C.includes(Sn.full_text),onCheckedChange:M(Sn.full_text)}),t(re,{htmlFor:`search-type-full_text`,children:l(`store.fullText`)})]}),t(`div`,{className:`font-semibold mt-2 mb-1`,children:l(`store.embeddings`)}),S4.map(e=>n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:`search-type-${e}`,checked:C.includes(e),onCheckedChange:M(e)}),t(re,{htmlFor:`search-type-${e}`,children:e.charAt(0).toUpperCase()+e.slice(1)})]},e)),n(`div`,{className:`mt-3`,children:[t(`span`,{className:`me-2`,children:l(`store.limit`)}),t(de,{type:`number`,min:1,value:T,onChange:e=>E(Number(e??100)),style:{width:80}})]})]})}),t(le,{children:t(o,{variant:`outline`,onClick:()=>S(!1),children:l(`store.close`)})})]}),t(o,{variant:`secondary`,isLoading:r,onClick:A,isDisabled:!g,title:l(`store.semanticSearch`),children:l(`store.search`)})]})}Q();const w4=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function T4(e,t){return(t?e.getTypeLayout(t):w4)??w4}function E4({onUploadDone:e=async()=>{},layout:n,toolbarActions:r}){let i=O$(),a=nt(),{t:o}=K(),s=R$(V(async t=>{await e(t),setTimeout(()=>{console.log(`Delayed refresh after upload to ensure backend consistency`),i.search().then(e=>{e&&a({title:o(`store.documentListRefreshed`),description:o(`store.documentListRefreshedDesc`),status:`info`,duration:3e3})}).catch(e=>{console.error(`Failed to refresh search results:`,e)})},1e3)},[e,i,o,a])),c=V((e,t)=>{let n=i.collectionId;return s(e,t,n)},[i,s]);return t(D4,{layout:n,onUpload:c,toolbarActions:r})}function D4({layout:e,onUpload:r,allowFilter:i=!0,allowSearch:a=!0,toolbarActions:o}){let{t:s}=K(),c=O$(),[l,u]=G(!1),[d,f]=G(null),{registry:p}=GZ(),{search:m,isLoading:h,error:g,objects:_,hasMore:v}=A$(),[y,b]=G(p?e||T4(p,m.query.type):w4);H(()=>{e&&b(e)},[e]);let[x,S]=G(0),[C,w]=G(0),[T,E]=G(localStorage.getItem(q$.LAST_DISPLAYED_VIEW)===`grid`),[D,O]=G([]),k=W(null),A=W(null),j=V((e,t)=>{u(!1),e.catch(e=>{console.error(t,e)}).finally(()=>{u(!0)})},[]);H(()=>{let e=!1;return m.initialized?(u(!0),()=>{e=!0}):(u(!1),w(0),m.search().catch(t=>{e||console.error(`Initial search failed:`,t)}).finally(()=>{e||u(!0)}),()=>{e=!0})},[m]),H(()=>{_.length<C&&w(_.length)},[_.length,C]),Qe(k,()=>{l&&_.length>0&&_.length!==C&&(u(!1),m.loadMore().catch(e=>{console.error(`Failed to load more search results:`,e)}).finally(()=>{w(_.length),u(!0)}))},{deps:[l,_.length]});let N=e=>{if(e?.vector){if(m.query.vector=e.vector,m.query.full_text=e.full_text,m.query.weights=e.weights,m.query.score_aggregation=e.score_aggregation,m.query.dynamic_scaling=e.dynamic_scaling,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),!y.find(e=>e.name===`Search Score`)){let e=[...y,{name:`Search Score`,field:`score`,render:e=>typeof e.score==`number`?e.score.toFixed(4):`0.0000`}];b(e)}j(m.search(),`Vector search failed:`)}else e?.full_text?(m.query.full_text=e.full_text,e.limit!==void 0&&(m.limit=e.limit,m.query.limit=e.limit),j(m.search(),`Text search failed:`)):e===void 0&&l&&(delete m.query.vector,delete m.query.full_text,j(m.search(),`Search reset failed:`))},P=k$(),F=O$(),I=()=>{j(m.search(),`Search refresh failed:`)},L=rQ(P),ee=iQ(F),R=e=>{let t=typeof e==`function`?e(D):e;O(t),ee(t)},te=(e,t)=>{let n=L.find(t=>t.name===e),r={name:e,type:n?.type,placeholder:n?.placeholder,multiple:n?.multiple};R(i=>{let a=i.filter(t=>t.name!==e);if(n?.type===`stringList`||Array.isArray(t)){let n=Array.isArray(t)?t:[t],o=i.find(t=>t.name===e)?.value??[];return[...a,{...r,value:Array.from(new Set([...o,...n]))}]}return[...a,{...r,value:[{value:t,label:t}]}]})},ne=new URL(window.location.href),re=ne.searchParams.get(`filters`);if(re)try{let e=re.split(`;`),t=e.filter(e=>{let[t]=e.split(`:`),n=decodeURIComponent(t);return n!==`start`&&n!==`end`});if(t.length!==e.length){let e=t.length>0?t.join(`;`):``;e?ne.searchParams.set(`filters`,e):ne.searchParams.delete(`filters`),window.history.replaceState(window.history.state||{},``,ne.toString())}}catch(e){console.error(`Failed to clean start/end filters from URL:`,e)}let ie=$n();return n(`div`,{className:`flex flex-col gap-y-2 flex-1 min-h-0 `,children:[t(k4,{object:d,onClose:()=>f(null)}),g&&t(M,{title:s(`store.error`),children:g.message}),t(O4,{isLoading:h,refreshTrigger:x,allowFilter:i,allowSearch:a,filterGroups:L,filters:D,handleFilterChange:R,handleVectorSearch:N,handleRefetch:I,setIsGridView:E,toolbarActions:o}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md mb-2`,children:n(`div`,{ref:A,className:`flex-1 min-h-0 overflow-y-auto`,children:[t(WQ,{onFilter:te,children:t(B$,{objects:_,isLoading:!_.length&&h,layout:y,onRowClick:e=>{ie(`/objects/${e.id}`)},previewObject:e=>{let t=_.find(t=>t.id===e)||null;f(t)},selectedObject:d,onUpload:r,isGridView:T,collectionId:c.collectionId})}),v?t(`div`,{ref:k,className:`w-full flex justify-center`,children:t(je,{size:`xl`})}):t(`div`,{className:`text-muted text-center text-sm py-1`,children:`All ${_.length} objects loaded.`})]})})]})}function O4(e){let{t:r}=K(),{isLoading:i,refreshTrigger:a,allowFilter:s,allowSearch:c,filterGroups:l,filters:u,handleFilterChange:d,handleVectorSearch:f,handleRefetch:p,setIsGridView:m,toolbarActions:h}=e;return n(`div`,{className:`sticky top-0 z-10 bg-background py-2 flex justify-between items-center`,children:[s?t(I,{filterGroups:l,filters:u,setFilters:d,children:n(`div`,{children:[t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:n(`div`,{className:`flex gap-2 items-center w-2/3`,children:[c&&t(C4,{onChange:f,isLoading:i,refresh:a,className:`w-full`}),t(P,{})]})}),n(`div`,{className:`flex gap-2 items-center pt-2`,children:[t(N,{}),t(F,{})]})]})}):t(`div`,{className:`flex flex-row gap-4 items-center justify-between w-full`,children:t(`div`,{className:`flex gap-2 items-center w-2/3`,children:c&&t(C4,{onChange:f,isLoading:i,refresh:a})})}),n(`div`,{className:`flex gap-1 items-center`,children:[h,t(o,{variant:`outline`,onClick:p,title:r(`store.refresh`),children:t(gy,{size:16})}),t(q$,{onUpdate:m})]})]})}function k4({object:e,onClose:r}){let{store:i}=q(),a=nt(),s=$n(),{downloadFromContentSource:c}=eG({client:i,toast:a}),l=e?.content?.source,u=typeof e?.properties?.title==`string`?e.properties.title:e?.name;return e?n(Oe,{title:u,isOpen:!0,onClose:r,children:[n(`div`,{className:`flex items-center gap-x-2`,children:[t(o,{variant:`ghost`,size:`sm`,title:`Open Object`,onClick:()=>s(`/objects/${e.id}`),children:t(Og,{className:`size-4`})}),l&&t(o,{variant:`ghost`,size:`sm`,title:`Download`,onClick:()=>c(l,$W(e)),children:t(Sg,{className:`size-4`})})]}),t(C,{className:`my-2`}),t(`div`,{className:`pt-2`,children:t(s4,{object:e,loadText:!0},e.id)})]}):null}const A4=[{name:`ID`,field:`id`,type:`objectId?slice=-7`},{name:`Name`,field:`.`,type:`objectName`},{name:`Revision`,field:`.`,type:`revision`},{name:`Type`,field:`type.name`,type:`string`},{name:`Status`,field:`status`,type:`string`},{name:`Updated At`,field:`updated_at`,type:`date`}];function j4({collection:e}){let n=nt(),{client:r}=q(),{registry:i}=GZ(),a=async t=>{t.length>0&&await r.store.collections.addMembers(e.id,t).catch(e=>{n({title:`Failed to add objects to collection`,description:e.message,status:`error`})})},o=M4(e,i);return t(`div`,{className:`flex flex-col h-full`,children:e.dynamic?t(D4,{layout:o}):t(E4,{onUploadDone:a,layout:o})})}function M4(e,t){let n=e.table_layout;return n&&n.length>0||(e.type&&t&&(n=t?.getTypeLayout(Dn(e.type))),n&&n.length>0)?n:A4}function N4({className:e,defaultValue:r,onChange:i,isClearable:a,multiple:o}){let{t:s}=K(),{registry:c}=GZ(),[l,u]=G(!1),d=e=>e===null?s(`store.none`):n(`div`,{children:[t(`div`,{className:`text-sm`,children:e.name}),t(`div`,{className:`text-xs text-muted truncate`,children:e.description})]}),[f,p]=G(),[m,h]=G([]);return H(()=>{if(!l&&(u(!0),c&&r)){if(o&&Array.isArray(r)){let e=c.types.filter(e=>r.includes(e.id));h(e)}let e=c.types.find(e=>e.id===r);e&&p(e)}},[l,c,r,o]),o?t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(we,{options:c?.types||[],value:m,onChange:e=>{h(e),i(e)},placeholder:s(`store.chooseContentTypes`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1,multiple:!0})}):t(`div`,{className:`flex flex-col gap-4 content-between`,children:t(we,{options:c?.types||[],value:f,onChange:e=>{p(e||void 0),i(e)},placeholder:s(`store.chooseContentType`),optionLabel:d,className:e||`text-sm bg-background`,filterBy:`name`,isClearable:a||!1})})}function P4({onClose:r,redirect:i=!0,onAddToCollection:a}){let s=$n(),c=nt(),{t:l}=K(),[u,d]=G(!1),{client:f}=q(),[p,m]=G({dynamic:!1,name:``,description:``});function h(e,t){m({...p,[e]:t})}return n(e,{children:[t(ce,{children:n(`form`,{onSubmit:e=>e.preventDefault(),children:[t(L,{label:l(`type.name`),required:!0,children:t(te,{type:`text`,value:p.name||``,onChange:e=>h(`name`,e)})}),t(L,{label:l(`type.description`),className:`mt-2`,children:t(Ue,{value:p.description||``,onChange:e=>h(`description`,e.target.value)})}),t(L,{label:l(`store.dynamicCollection`),className:`mt-2`,direction:`row`,description:l(`store.dynamicCollectionDescription`),children:t(Ne,{value:p.dynamic||!1,onChange:e=>h(`dynamic`,e)})}),!p.dynamic&&t(L,{label:l(`store.allowedContentTypes`),className:`mt-4`,description:l(`store.allowedContentTypesOptionalDescription`),children:t(N4,{defaultValue:p.allowed_types||null,onChange:e=>{Array.isArray(e)?h(`allowed_types`,e.map(e=>e.id)):h(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),t(L,{label:l(`store.contentType`),className:`mt-2`,description:l(`store.typeDescription`),children:t(N4,{defaultValue:p.type||null,onChange:e=>{Array.isArray(e)?h(`type`,e.length>0?e[0].id:null):h(`type`,e?.id||null)},isClearable:!0})})]})}),t(le,{children:t(o,{isDisabled:u,onClick:()=>{if(!p?.name?.trim()){c({title:l(`type.nameRequired`),description:l(`store.pleaseProvideName`),status:`error`,duration:5e3});return}p.name=p.name.trim(),p.description&&=p.description.trim(),p.dynamic??=!1,d(!0),f.store.collections.create(p).then(e=>{r(),c({title:l(`store.collectionCreated`),description:`Collection "${e.name}" created successfully`,status:`success`,duration:3e3}),i&&s(`/collections/${e.id}`),a&&a(e.id)}).catch(e=>{c({title:l(`store.failedToCreateCollection`),description:e.message,status:`error`,duration:5e3})}).finally(()=>d(!1))},children:l(`store.createCollection`)})})]})}function F4({isOpen:e,onClose:r}){let{t:i}=K();return n(se,{onClose:r,isOpen:e,children:[t(ue,{children:i(`store.createACollection`)}),t(P4,{onClose:r})]})}Q();function I4(){let{client:r}=q(),i=nt(),{t:a}=K(),[s,c]=G(),[l,u]=G(!0),[d,f]=G(!1),{data:p,error:m,refetch:h}=Ye(()=>r.store.collections.search({}),[]);return H(()=>{(p||m)&&u(!1)},[p,m]),m?t(M,{title:a(`store.collectionFetchFailed`),children:Ge(m)}):n(e,{children:[p&&(p.length>0?n(Le,{className:`w-full`,children:[t(`thead`,{children:n(`tr`,{children:[t(`th`,{children:a(`type.name`)}),t(`th`,{children:a(`type.type`)}),t(`th`,{children:a(`store.created`)}),t(`th`,{})]})}),t(Pe,{columns:4,isLoading:l,children:p.map(e=>n(Ie,{children:[t(`td`,{children:n(`div`,{className:`flex items-center gap-2`,children:[t(L4,{isDynamic:e.dynamic}),t(Qn,{href:`/collections/${e.id}`,children:e.name})]})}),t(`td`,{children:e.type?.name||`-`}),t(`td`,{children:GD(e.created_at).fromNow()}),t(`td`,{className:`text-end`,children:t(o,{variant:`destructive`,size:`sm`,onClick:()=>c(e.id),children:t(gb,{className:`size-4`})})})]},e.id))})]}):t(j,{title:a(`store.noCollections`),buttonLabel:a(`store.newCollections`),onClick:()=>f(!0),children:a(`store.getStartedCollections`)})),t(F4,{isOpen:d,onClose:()=>f(!1)}),t(b,{isOpen:!!s,title:a(`store.deleteCollection`),content:a(`store.areYouSureDeleteCollection`),onConfirm:async()=>{if(s)try{await r.store.collections.delete(s),i({title:a(`store.collectionDeleted`),status:`success`,duration:3e3}),h()}catch(e){console.error(`Failed to delete collection:`,e),i({title:a(`store.failedToDeleteCollection`),description:Ge(e),status:`error`,duration:5e3})}finally{c(void 0)}},onCancel:()=>c(void 0)})]})}function L4({isDynamic:e}){let{t:n}=K(),r=n(e?`store.dynamicCollection`:`store.staticCollection`),i=t(e?jy:t_,{className:`size-5`});return t(We,{description:r,className:`me-2`,children:i})}Q();const R4=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function z4({objects:e,isLoading:r,onFilter:i,selectedIds:a,onToggleOne:s,allSelected:c,onToggleAll:l}){let{t:u}=K(),d=$n(),f=!!s;return n(Le,{className:`w-full`,children:[t(Fe,{children:n(`tr`,{children:[f&&t(`th`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,checked:!!c,"aria-label":u(`store.actions.selectAllTypes`),onChange:e=>l?.(e.target.checked)})}),t(`th`,{children:u(`store.name`)}),t(`th`,{children:u(`store.strictMode`)}),t(`th`,{children:u(`store.semanticChunking`)}),t(`th`,{children:u(`store.updatedAt`)})]})}),t(Pe,{isLoading:r&&(!e||e.length===0),columns:f?5:4,children:e?.map(e=>n(`tr`,{onClick:()=>d(`/types/${e.id}`),className:`group cursor-pointer hover:bg-muted`,children:[f&&t(`td`,{className:`w-[5%]`,children:t(`input`,{type:`checkbox`,className:it(`checkbox group-hover:inline-block`,a?.includes(e.id)?`inline-block`:`hidden`),checked:a?.includes(e.id)??!1,"aria-label":u(`store.actions.selectType`,{name:e.name}),onClick:e=>e.stopPropagation(),onChange:t=>s?.(e.id,t.target.checked)})}),t(`td`,{className:`group/field`,children:n(`div`,{className:`flex items-center gap-2 min-w-0`,children:[t(`span`,{className:`truncate`,children:e.name}),t(x,{content:e.id,className:R4}),i&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${e.name}`,className:R4,onClick:t=>{t.stopPropagation(),i(`name`,e.name)},children:t(u_,{className:`size-3`})})]})}),t(`td`,{children:e.strict_mode?`Yes`:`No`}),t(`td`,{children:e.is_chunkable?`Yes`:`No`}),t(`td`,{children:t(We,{description:GD(e.updated_at).format(`YYYY-MM-DD HH:mm:ss`),children:GD(e.updated_at).fromNow()})})]},e.id))})]})}function B4({title:e,isOpen:r,onClose:i,okLabel:a,initialPayload:s,isLoading:c}){let{t:l}=K(),u=nt(),[d,f]=G(s?.name),[p,m]=G(s?.description),h=s?.strict_mode??!1,g=()=>{if(!d){u({status:`error`,title:l(`type.nameRequired`),duration:5e3});return}i({name:d,description:p,strict_mode:h}).then(()=>i())};return n(se,{isOpen:r,onClose:()=>i(),children:[t(ue,{children:e}),t(ce,{className:`pt-0`,children:n(`div`,{className:`h-full flex flex-col gap-4 content-between`,children:[n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.name`)}),t(te,{value:d,onChange:f})]}),n(`div`,{children:[t(`div`,{className:`block text-sm font-medium text-muted`,children:l(`type.description`)}),t(Ue,{value:p,onChange:e=>m(e.target.value),minLines:5})]})]})}),t(le,{children:n(`div`,{className:`flex justify-end gap-4`,children:[t(o,{variant:`secondary`,onClick:()=>i(),children:l(`modal.cancel`)}),t(o,{variant:`primary`,onClick:()=>g(),isLoading:c,children:a})]})})]})}var V4=class{client;limit;result=new De({objects:[],isLoading:!1});query={};constructor(e,t=100){this.client=e,this.limit=t}get objects(){return this.result.value.objects}get error(){return this.result.value.error}get isRunning(){return this.result.value.isLoading}getFilterValue(e){return this.query[e]}setFilterValue(e,t){this.query[e]=t,this.search()}reset(e=!1){this.result.value={objects:[],isLoading:e}}_updateRunningState(e){let t=this.result.value;this.result.value={objects:t.objects,isLoading:e,error:t.error}}async _search(e=!1){if(this.isRunning)return Promise.resolve(!1);this.result.value={isLoading:!0,objects:e?this.objects:[]};let t=this.limit,n=this.objects.length;return this.client.types.list({limit:t,offset:n,query:this.query}).then(async e=>(this.result.value={isLoading:!1,objects:this.objects.concat(e)},!0)).catch(e=>{throw this.result.value={error:e,isLoading:!1,objects:this.objects},e})}search(){return this.isRunning?Promise.resolve(!1):this._search(!1)}loadMore(){return this.isRunning?Promise.resolve(!1):this._search(!0)}};const H4=dt(void 0);function U4(){return _t(H4)}function W4(){let e=U4();return{...rt(e.result),search:e}}function G4(){return U4().objects.length}Q();var K4;(function(e){e.true=`Yes`,e.false=`No`})(K4||={});function q4({isDirty:r=!1}){let{store:i}=q(),{reload:a}=GZ(),{t:s}=K(),c=nt(),[l,u]=G(!1),{search:d,isLoading:f,error:p,objects:m}=W4(),[h,g]=G([]),[_,v]=G(!1),[y,x]=G(!1),S=h.length,C=!!m&&m.length>0&&m.every(e=>h.includes(e.id)),w=m?.filter(e=>h.includes(e.id))??[],T=(e,t)=>{g(n=>t?n.includes(e)?n:[...n,e]:n.filter(t=>t!==e))},E=e=>{g(e&&m?m.map(e=>e.id):[])},D=async()=>{if(!y){x(!0);try{let e=await Promise.allSettled(h.map(e=>i.types.delete(e))),t=e.filter(e=>e.status===`rejected`).length,n=e.length-t;v(!1),g([]),a(),await d.search(),c(t===0?{status:`success`,title:s(`store.actions.typeDeleted`,{count:n}),duration:3e3}:{status:`error`,title:s(`store.actions.typeDeletePartial`,{succeeded:n,failed:t}),duration:5e3})}catch(e){c({status:`error`,title:s(`store.actions.failedToDeleteTypes`),description:e instanceof Error?e.message:void 0,duration:5e3})}finally{x(!1)}}},[O,k]=G(``),A=Je(O,500),N=W(null);Qe(N,()=>{l&&d.loadMore()},{deps:[l,d]}),H(()=>{d.search().then(()=>u(!0))},[d]),H(()=>{d.query.name=A,d.search().then(()=>u(!0))},[A,d]);let[P,F]=G(void 0),I=e=>{F(e)};H(()=>{d.query.chunkable=P?P===`Yes`:void 0,d.search().then(()=>u(!0))},[P,d]),H(()=>{r&&l&&d.search().then(()=>u(!0))},[r,l,d]);let[L,ee]=G(!1);return p?t(M,{title:s(`store.failedToFetchTypes`),children:p.message}):n(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[n(`div`,{className:`flex flex-shrink-0 gap-4 items-center`,children:[t(te,{placeholder:s(`store.filterByName`),value:O,onChange:k}),t(we,{className:`w-60`,isClearable:!0,options:Object.values(K4),value:P,onChange:I,placeholder:s(`store.isChunkable`)}),S>0&&n(`div`,{className:`flex items-center gap-2 ms-auto`,children:[t(`span`,{className:`text-sm font-medium whitespace-nowrap`,children:s(`store.actions.selectedCount`,{n:S})}),t(We,{description:s(`store.actions.clearSelection`),asChild:!0,children:t(o,{variant:`ghost`,"aria-label":s(`store.actions.clearSelection`),onClick:()=>g([]),children:t(Kb,{className:`size-4`})})}),t(o,{variant:`destructive`,isDisabled:y,onClick:()=>v(!0),children:s(y?`store.actions.deleting`:`store.actions.deleteSelected`)})]})]}),t(`div`,{className:`flex flex-col w-full flex-1 min-h-0 border rounded-md my-2`,children:n(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:[!f&&m?.length===0?t(j,{title:s(`store.noType`),buttonLabel:s(`store.createType`),onClick:()=>{ee(!0)},children:s(`store.getStartedTypes`)}):n(e,{children:[t(z4,{objects:m,isLoading:f,onFilter:(e,t)=>{e===`name`&&k(t)},selectedIds:h,onToggleOne:T,allSelected:C,onToggleAll:E}),t(`div`,{ref:N,className:`h-4 w-full`})]}),t(B4,{okLabel:`Create`,title:s(`store.createType`),isOpen:L,onClose:async e=>e?i.types.create(e).then(async()=>{c({status:`success`,title:s(`store.typeCreated`),duration:2e3}),a(),d.search().then(()=>u(!0))}).catch(e=>{c({status:`error`,title:s(`store.errorCreatingType`),description:e.message,duration:5e3})}):(ee(!1),Promise.resolve())}),t(b,{isOpen:_,title:s(`store.actions.deleteType`,{count:S}),content:n(`div`,{children:[t(`p`,{children:s(`store.actions.deleteTypeConfirm`,{count:S})}),w.length>0&&n(e,{children:[t(`div`,{className:`mt-2`,children:s(`store.actions.affectedItems`)}),t(`ul`,{className:`mt-1 max-h-40 overflow-y-auto rounded-md border p-2 text-sm`,children:w.map(e=>t(`li`,{className:`truncate py-0.5`,children:e.name||e.id},e.id))})]})]}),onConfirm:D,onCancel:()=>v(!1),confirmationValue:`delete`,confirmationLabel:s(`store.actions.typeToConfirmDelete`),confirmationPlaceholder:`delete`})]})})]})}function J4(e,t,n){if(t.length===0)return e;let r=structuredClone(e),i=[r],a=r;for(let e of t.slice(0,-1)){let t=a[e],n=$4(t)?t:{};a[e]=n,a=n,i.push(a)}let o=t[t.length-1];return n===void 0||n===``?(delete a[o],Q4(i,t)):a[o]=n,r}function Y4(e,t,n,r){let i=e?.map(e=>[e[0]??1,e[1]??1])??[],a=i[t]??[1,1];return a[n]=r,i[t]=a,i}function X4(e,t){let n={...e,environment:t};return delete n.model,delete n.model_options,e3(n)?n:void 0}function Z4(e,t){let n={...e,model:t};return t!==e?.model&&delete n.model_options,e3(n)?n:void 0}function Q4(e,t){for(let n=e.length-1;n>0;--n){let r=e[n];if(Object.keys(r).length>0)break;delete e[n-1][t[n-1]]}}function $4(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function e3(e){return Object.values(e).some(e=>e!==void 0)}Q();function t3({policy:e,section:r,onChange:i,readonly:a=!1}){let{t:o}=K(),s=(t,n)=>i(J4(e,t,n));if(r===`overview`)return n(n3,{children:[n(r3,{title:o(`intakePolicy.section.classification`),description:o(`intakePolicy.help.section.classification`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(s3,{label:o(`intakePolicy.field.mode`),description:o(`intakePolicy.help.mode`),value:e.mode,options:f3(o,[`programmatic`,`agentic`]),onChange:e=>s([`mode`],e),readonly:a}),t(s3,{label:o(`intakePolicy.field.defaultView`),value:e.default_view,options:f3(o,[`auto`,`text`,`pdf`,`image`,`properties`]),onChange:e=>s([`default_view`],e),readonly:a})]}),t(a3,{label:o(`intakePolicy.field.identificationGuidance`),description:o(`intakePolicy.help.identificationGuidance`),value:e.identification?.guidance,onChange:e=>s([`identification`,`guidance`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.distinguishFrom`),description:o(`intakePolicy.help.distinguishFrom`),value:e.identification?.distinguish_from,onChange:e=>s([`identification`,`distinguish_from`],e),readonly:a}),t(L,{label:o(`intakePolicy.field.examples`),description:o(`intakePolicy.help.examples`),children:t(He,{options:e.identification?.examples??[],value:e.identification?.examples??[],onChange:e=>s([`identification`,`examples`],e.length?e:void 0),onOptionsChange:e=>s([`identification`,`examples`],e.length?e:void 0),creatable:!0,disabled:a,placeholder:o(`intakePolicy.placeholder.objectId`)})})]}),n(r3,{title:o(`intakePolicy.section.locate`),description:o(`intakePolicy.help.section.locate`),last:!0,children:[t(a3,{label:o(`intakePolicy.field.locateInstructions`),description:o(`intakePolicy.help.locateInstructions`),value:e.locate?.instructions,onChange:t=>s([`locate`],t?{...e.locate,instructions:t}:void 0),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(s3,{label:o(`intakePolicy.field.contactSheetDetail`),description:o(`intakePolicy.help.contactSheetDetail`),value:e.locate?.detail,options:[{value:8,label:o(`intakePolicy.option.pagesPerSheet`,{count:8})},{value:16,label:o(`intakePolicy.option.pagesPerSheet`,{count:16})}],onChange:e=>s([`locate`,`detail`],e),readonly:a||!e.locate}),t(o3,{label:o(`intakePolicy.field.locateMinPages`),description:o(`intakePolicy.help.locateMinPages`),value:e.locate?.min_pages,min:0,onChange:e=>s([`locate`,`min_pages`],e),readonly:a||!e.locate})]})]})]});if(r===`conversion`)return n(n3,{children:[n(r3,{title:o(`intakePolicy.section.conversion`),description:o(`intakePolicy.help.section.conversion`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(c3,{label:o(`intakePolicy.field.enabled`),value:e.text_conversion?.enabled,onChange:e=>s([`text_conversion`,`enabled`],e),readonly:a}),t(s3,{label:o(`intakePolicy.field.method`),description:o(`intakePolicy.help.method`),value:e.text_conversion?.method,options:f3(o,[`auto`,`basic`,`llm`,`custom`]),onChange:e=>s([`text_conversion`,`method`],e),readonly:a}),t(s3,{label:o(`intakePolicy.field.outputFormat`),value:e.text_conversion?.output_format,options:f3(o,[`markdown`,`text`]),onChange:e=>s([`text_conversion`,`output_format`],e),readonly:a}),t(s3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.text_conversion?.scope,options:f3(o,[`all`,`located`]),onChange:e=>s([`text_conversion`,`scope`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.renderDpi`),description:o(`intakePolicy.help.renderDpi`),value:e.text_conversion?.render_dpi,min:72,onChange:e=>s([`text_conversion`,`render_dpi`],e),readonly:a})]}),t(a3,{label:o(`intakePolicy.field.instructions`),value:e.text_conversion?.instructions,onChange:e=>s([`text_conversion`,`instructions`],e),readonly:a})]}),t(r3,{title:o(`intakePolicy.section.conversionModel`),description:o(`intakePolicy.help.section.conversionModel`),children:t(d3,{title:o(`intakePolicy.field.model`),config:e.text_conversion?.config,onChange:e=>s([`text_conversion`,`config`],e),readonly:a})}),e.text_conversion?.method===`custom`&&t(r3,{title:o(`intakePolicy.section.customConversion`),description:o(`intakePolicy.help.section.customConversion`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(i3,{label:o(`intakePolicy.field.interaction`),value:e.text_conversion.custom?.interaction,onChange:e=>s([`text_conversion`,`custom`,`interaction`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.agent`),value:e.text_conversion.custom?.agent,onChange:e=>s([`text_conversion`,`custom`,`agent`],e),readonly:a})]})}),t(r3,{title:o(`intakePolicy.section.pageRanges`),description:o(`intakePolicy.help.section.pageRanges`),last:!0,children:t(u3,{value:e.text_conversion?.page_ranges,onChange:e=>s([`text_conversion`,`page_ranges`],e),readonly:a})})]});if(r===`extraction`)return n(n3,{children:[n(r3,{title:o(`intakePolicy.section.extraction`),description:o(`intakePolicy.help.section.extraction`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(c3,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.enabled,onChange:e=>s([`extraction`,`enabled`],e),readonly:a}),t(s3,{label:o(`intakePolicy.field.source`),description:o(`intakePolicy.help.extractionSource`),value:e.extraction?.source,options:f3(o,[`auto`,`text`,`vision`,`mixed`]),onChange:e=>s([`extraction`,`source`],e),readonly:a}),t(s3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.extraction?.scope,options:f3(o,[`all`,`located`]),onChange:e=>s([`extraction`,`scope`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.maxPages`),description:o(`intakePolicy.help.extractionMaxPages`),value:e.extraction?.max_pages,min:1,onChange:e=>s([`extraction`,`max_pages`],e),readonly:a})]}),t(i3,{label:o(`intakePolicy.field.interaction`),description:o(`intakePolicy.help.extractionInteraction`),value:e.extraction?.interaction,onChange:e=>s([`extraction`,`interaction`],e),readonly:a}),t(a3,{label:o(`intakePolicy.field.instructions`),value:e.extraction?.instructions,onChange:e=>s([`extraction`,`instructions`],e),readonly:a}),t(u3,{value:e.extraction?.page_ranges,onChange:e=>s([`extraction`,`page_ranges`],e),readonly:a})]}),t(r3,{title:o(`intakePolicy.section.extractionModel`),description:o(`intakePolicy.help.section.extractionModel`),children:t(d3,{title:o(`intakePolicy.field.model`),config:e.extraction?.config,onChange:e=>s([`extraction`,`config`],e),readonly:a})}),t(r3,{title:o(`intakePolicy.section.visionBudget`),description:o(`intakePolicy.help.section.visionBudget`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(s3,{label:o(`intakePolicy.field.defaultDetail`),description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.default_detail,options:f3(o,[`low`,`standard`,`high`]),onChange:e=>s([`extraction`,`vision`,`default_detail`],e),readonly:a}),t(l3,{description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.allowed_details,onChange:e=>s([`extraction`,`vision`,`allowed_details`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.maxImageTokens`),description:o(`intakePolicy.help.maxImageTokens`),value:e.extraction?.vision?.max_image_tokens,min:1,onChange:e=>s([`extraction`,`vision`,`max_image_tokens`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.maxPayloadMb`),description:o(`intakePolicy.help.maxPayloadMb`),value:e.extraction?.vision?.max_payload_mb,min:1,onChange:e=>s([`extraction`,`vision`,`max_payload_mb`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.maxPagesPerCall`),value:e.extraction?.vision?.max_pages_per_call,min:1,onChange:e=>s([`extraction`,`vision`,`max_pages_per_call`],e),readonly:a})]})}),n(r3,{title:o(`intakePolicy.section.verification`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(c3,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.verification?.enabled,onChange:e=>s([`extraction`,`verification`,`enabled`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.model`),value:e.extraction?.verification?.model,onChange:e=>s([`extraction`,`verification`,`model`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.environment`),value:e.extraction?.verification?.environment,onChange:e=>s([`extraction`,`verification`,`environment`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.threshold`),value:e.extraction?.verification?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`verification`,`threshold`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.maxRetries`),value:e.extraction?.verification?.max_retries,min:0,onChange:e=>s([`extraction`,`verification`,`max_retries`],e),readonly:a}),t(s3,{label:o(`intakePolicy.field.onFailure`),value:e.extraction?.verification?.on_fail,options:f3(o,[`flag`,`block`]),onChange:e=>s([`extraction`,`verification`,`on_fail`],e),readonly:a})]}),t(a3,{label:o(`intakePolicy.field.materiality`),value:e.extraction?.verification?.materiality,onChange:e=>s([`extraction`,`verification`,`materiality`],e),readonly:a})]})]});if(r===`grounding`){let r=e.extraction?.grounding,i=r?.review;return n(n3,{children:[n(r3,{title:o(`intakePolicy.section.grounding`),description:o(`intakePolicy.help.section.grounding`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(c3,{label:o(`intakePolicy.field.enabled`),value:r?.enabled,onChange:e=>s([`extraction`,`grounding`,`enabled`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.maxPages`),value:r?.max_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`max_pages`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.windowPages`),description:o(`intakePolicy.help.windowPages`),value:r?.window_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`window_pages`],e),readonly:a}),t(i3,{label:o(`intakePolicy.field.interaction`),value:r?.interaction,onChange:e=>s([`extraction`,`grounding`,`interaction`],e),readonly:a})]}),n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(c3,{label:o(`intakePolicy.field.useVision`),description:o(`intakePolicy.help.useVision`),value:r?.use_vision,onChange:e=>s([`extraction`,`grounding`,`use_vision`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.forceOcr`),description:o(`intakePolicy.help.forceOcr`),value:r?.force_ocr,onChange:e=>s([`extraction`,`grounding`,`force_ocr`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.refreshOcr`),description:o(`intakePolicy.help.refreshOcr`),value:r?.refresh_ocr,onChange:e=>s([`extraction`,`grounding`,`refresh_ocr`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.omitBlockBoxes`),description:o(`intakePolicy.help.omitBlockBoxes`),value:r?.omit_block_boxes,onChange:e=>s([`extraction`,`grounding`,`omit_block_boxes`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.updateProperties`),description:o(`intakePolicy.help.updateProperties`),value:r?.update_properties,onChange:e=>s([`extraction`,`grounding`,`update_properties`],e),readonly:a})]})]}),n(r3,{title:o(`intakePolicy.section.models`),description:o(`intakePolicy.help.section.models`),children:[t(d3,{title:o(`intakePolicy.field.primaryModel`),config:r?.config,onChange:e=>s([`extraction`,`grounding`,`config`],e),readonly:a}),t(d3,{title:o(`intakePolicy.field.hardModel`),config:r?.hard_config,onChange:e=>s([`extraction`,`grounding`,`hard_config`],e),readonly:a}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(o3,{label:o(`intakePolicy.field.hardnessThreshold`),description:o(`intakePolicy.help.hardnessThreshold`),value:r?.hardness_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`hardness_threshold`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.minCitationDensity`),description:o(`intakePolicy.help.minCitationDensity`),value:r?.min_citation_density,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`min_citation_density`],e),readonly:a})]})]}),n(r3,{title:o(`intakePolicy.section.review`),description:o(`intakePolicy.help.section.review`),last:!0,children:[n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(c3,{label:o(`intakePolicy.field.enabled`),value:i?.enabled,onChange:e=>s([`extraction`,`grounding`,`review`,`enabled`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.forceReview`),description:o(`intakePolicy.help.forceReview`),value:i?.force,onChange:e=>s([`extraction`,`grounding`,`review`,`force`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.reviewThreshold`),value:i?.threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`threshold`],e),readonly:a}),t(o3,{label:o(`intakePolicy.field.coverageThreshold`),description:o(`intakePolicy.help.coverageThreshold`),value:i?.coverage_threshold,min:0,max:1,step:.05,onChange:e=>s([`extraction`,`grounding`,`review`,`coverage_threshold`],e),readonly:a})]}),t(d3,{title:o(`intakePolicy.field.reviewModel`),config:i?.config,onChange:e=>s([`extraction`,`grounding`,`review`,`config`],e),readonly:a})]})]})}return n(n3,{children:[t(r3,{title:o(`intakePolicy.section.rendering`),description:o(`intakePolicy.help.section.rendering`),children:t(a3,{label:o(`intakePolicy.field.renderingTemplate`),description:o(`intakePolicy.help.renderingTemplate`),value:e.rendering_template,onChange:e=>s([`rendering_template`],e),readonly:a,monospace:!0,minLines:8})}),t(r3,{title:o(`intakePolicy.section.embeddings`),description:o(`intakePolicy.help.section.embeddings`),last:!0,children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:[t(c3,{label:o(`intakePolicy.field.textEmbedding`),value:e.embeddings?.text,onChange:e=>s([`embeddings`,`text`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.imageEmbedding`),value:e.embeddings?.image,onChange:e=>s([`embeddings`,`image`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.propertiesEmbedding`),value:e.embeddings?.properties,onChange:e=>s([`embeddings`,`properties`],e),readonly:a}),t(c3,{label:o(`intakePolicy.field.generateToc`),value:e.generate_toc,onChange:e=>s([`generate_toc`],e),readonly:a})]})})]})}function n3({children:e}){return t(`div`,{className:`mx-auto w-full max-w-6xl px-1 py-4`,children:e})}function r3({title:e,description:r,children:i,last:a=!1}){return n(`section`,{className:a?`pb-3`:`mb-6 border-b pb-6`,children:[n(`div`,{className:`mb-4 flex items-center gap-2`,children:[t(`h3`,{className:`text-sm font-semibold`,children:e}),t(R,{description:r})]}),t(`div`,{className:`space-y-4`,children:i})]})}function i3({label:e,value:n,onChange:r,readonly:i,description:a}){return t(L,{label:e,description:a,children:t(te,{value:n??``,onChange:e=>r(e||void 0),disabled:i})})}function a3({label:e,value:n,onChange:r,readonly:i,description:a,minLines:o=3,monospace:s=!1}){return t(L,{label:e,description:a,children:t(Ue,{value:n??``,onChange:e=>r(e.target.value||void 0),disabled:i,minLines:o,maxLines:14,className:s?`font-mono`:void 0})})}function o3({label:e,description:n,value:r,onChange:i,readonly:a,min:o,max:s,step:c}){return t(L,{label:e,description:n,children:t(de,{value:r,onChange:e=>i(e===void 0||Number.isFinite(e)?e:void 0),disabled:a,min:o,max:s,step:c??1,noScroll:!0})})}function s3({label:e,description:n,value:r,options:i,onChange:a,readonly:o}){let{t:s}=K(),c=[{value:`__inherit__`,label:s(`intakePolicy.option.inherit`)},...i],l=c.find(e=>e.value===r)??c[0];return t(L,{label:e,description:n,children:t(we,{options:c,value:l,by:`value`,optionLabel:e=>e.label,onChange:e=>a(e.value===`__inherit__`?void 0:e.value),disabled:o})})}function c3({label:e,description:n,value:r,onChange:i,readonly:a}){let{t:o}=K(),s=[{value:`inherit`,label:o(`intakePolicy.option.inherit`)},{value:`enabled`,label:o(`intakePolicy.option.enabled`)},{value:`disabled`,label:o(`intakePolicy.option.disabled`)}],c=r===void 0?`inherit`:r?`enabled`:`disabled`;return t(L,{label:e,description:n,children:t(we,{options:[...s],value:s.find(e=>e.value===c),by:`value`,optionLabel:e=>e.label,onChange:e=>i(e.value===`inherit`?void 0:e.value===`enabled`),disabled:a})})}function l3({description:e,value:n,onChange:r,readonly:i}){let{t:a}=K(),o=f3(a,[`low`,`standard`,`high`]);return t(L,{label:a(`intakePolicy.field.allowedDetails`),description:e,children:t(we,{multiple:!0,options:o,value:o.filter(e=>n?.includes(e.value)),by:`value`,optionLabel:e=>e.label,onChange:e=>r(e.length?e.map(e=>e.value):void 0),disabled:i})})}function u3({value:e,onChange:r,readonly:i}){let{t:a}=K(),s=t=>{let n=e?.filter((e,n)=>n!==t);r(n?.length?n:void 0)};return t(L,{label:a(`intakePolicy.field.pageRanges`),description:a(`intakePolicy.help.pageRanges`),children:n(`div`,{className:`space-y-2`,children:[e?.map((c,l)=>n(`div`,{className:`grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.25rem] gap-2`,children:[t(de,{"aria-label":a(`intakePolicy.field.rangeStart`),value:c[0],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(Y4(e,l,0,t))},disabled:i,step:1,noScroll:!0}),t(de,{"aria-label":a(`intakePolicy.field.rangeEnd`),value:c[1],onChange:t=>{t!==void 0&&Number.isFinite(t)&&r(Y4(e,l,1,t))},disabled:i,step:1,noScroll:!0}),t(We,{description:a(`intakePolicy.action.removeRange`),children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`intakePolicy.action.removeRange`),onClick:()=>s(l),disabled:i,children:t(gb,{className:`size-4`})})})]},`${l}`)),n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...e??[],[1,1]]),disabled:i,children:[t(sy,{className:`size-4`}),a(`intakePolicy.action.addRange`)]})]})})}function d3({title:e,config:r,onChange:i,readonly:a}){let{t:o}=K();return n(`div`,{children:[t(`div`,{className:`mb-2 text-xs font-medium text-muted`,children:e}),n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(L,{label:o(`intakePolicy.field.environment`),children:t(L1,{selectedEnvId:r?.environment,onChange:e=>i(X4(r,e?.id)),isClearable:!0,disabled:a})}),t(L,{label:o(`intakePolicy.field.model`),children:t(B1,{envId:r?.environment,selectedModelId:r?.model,onChange:e=>i(Z4(r,e?.id)),isClearable:!0,disabled:a||!r?.environment})})]})]})}function f3(e,t){return t.map(t=>({value:t,label:e(`intakePolicy.option.${t}`)}))}Q();const p3=[{key:`minimal`,value:{identification:{guidance:`Documents that match this content type.`,distinguish_from:`Do not select this type for unrelated documents.`}}},{key:`extraction_only`,value:{text_conversion:{enabled:!1},extraction:{enabled:!0,source:`vision`,instructions:`Extract required fields only. Ignore cover pages, appendices, legal boilerplate, and marketing content.`},rendering_template:`# {{properties.title}}
1395
1395
 
1396
1396
  {{properties.summary}}`,embeddings:{text:!0,properties:!0},default_view:`pdf`}},{key:`grounded`,value:{extraction:{enabled:!0,grounding:{enabled:!0,use_vision:!0,config:{model:`publishers/google/models/gemini-3.5-flash`,model_options:{_option_id:`vertexai-gemini`,max_tokens:32e3,thinking_level:`LOW`,temperature:0}},hard_config:{model:`publishers/google/models/gemini-3.1-pro-preview`,model_options:{_option_id:`vertexai-gemini`,max_tokens:32e3,thinking_level:`LOW`,temperature:0}},hardness_threshold:.5,min_citation_density:.3,window_pages:3,review:{enabled:!0,config:{model:`publishers/google/models/gemini-3.5-flash`,model_options:{_option_id:`vertexai-gemini`,thinking_level:`MEDIUM`,max_tokens:32e3,temperature:0}},coverage_threshold:.2}}},default_view:`pdf`}},{key:`visual_first`,value:{identification:{guidance:`Presentation decks or visual reports with slides, charts, diagrams, tables, or callouts.`},text_conversion:{enabled:!0,method:`auto`},extraction:{enabled:!0,source:`auto`,instructions:`Use visual evidence when layout, charts, diagrams, or slide structure contain material information.`},default_view:`pdf`}},{key:`structured_spreadsheet`,value:{text_conversion:{enabled:!0,method:`auto`,instructions:`Preserve sheet names, headers, row labels, totals, and period columns.`},extraction:{enabled:!0,source:`text`,instructions:`Extract values from worksheet text. Do not infer values from charts.`},default_view:`properties`}},{key:`media_no_transcript`,value:{text_conversion:{enabled:!1},extraction:{enabled:!0,source:`auto`,instructions:`Analyze available metadata and source evidence without creating a transcript.`},default_view:`properties`}},{key:`full_reference`,value:{mode:`programmatic`,identification:{guidance:`Supplier invoices: billing documents with an invoice number, line items, amounts due, tax breakdown, and payment terms.`,distinguish_from:`Quotes and estimates are offers, not payment requests. Credit notes carry negative amounts. Receipts confirm a payment already made.`,examples:[]},text_conversion:{enabled:!0,method:`auto`,instructions:`Keep the commercial terms and totals. Drop boilerplate and legal footers.`,output_format:`markdown`,custom:{interaction:`my-project:ConvertSpecialDocument`,agent:`my-project:DocumentConversionAgent`}},extraction:{enabled:!0,source:`auto`,instructions:`Extract totals from the summary block, not from line items. Amounts include currency. Dates use ISO 8601.`,interaction:`sys:ExtractInformation`,verification:{enabled:!1,model:`publishers/anthropic/models/claude-sonnet`,environment:`default`,materiality:`Amounts, dates, identifiers, and party names are material. Typos in free text are not.`,threshold:.85,max_retries:1,on_fail:`flag`},grounding:{enabled:!0,interaction:`sys:ExtractInformationGrounded`,max_pages:20,force_ocr:!1,use_vision:!0,omit_block_boxes:!1,config:{model:`publishers/google/models/gemini-3.5-flash`},hard_config:{model:`publishers/google/models/gemini-3.1-pro-preview`},hardness_threshold:.5,window_pages:3,update_properties:!0,min_citation_density:.3,refresh_ocr:!1,review:{enabled:!0,config:{model:`publishers/google/models/gemini-3.5-flash`},coverage_threshold:.2}}},rendering_template:`# Invoice {{properties.invoice_number}}
1397
1397
 
1398
1398
  - Vendor: {{properties.vendor_name}}
1399
1399
  - Total: {{properties.currency}} {{properties.total_amount}}
1400
- - Due: {{properties.due_date}}`,embeddings:{text:!0,image:!1,properties:!0},generate_toc:!1,default_view:`auto`}}],f3={};function p3({objectType:r,value:a,onSave:s,onIntakeUpdate:c,readonly:l=!1}){let{store:u}=q(),{t:d}=K(),f=nt(),{theme:p}=tt(),m=W(void 0),h=U(()=>x3(),[]),[g,_]=G(!1),v=r?.intake??a,[y,b]=G(()=>b3(v)),[x,S]=G(()=>b3(v)),[C,T]=G(void 0),[E,D]=G(`overview`),O=y!==x,k=U(()=>{let e=S3(y,h);return e.ok?e.policy:void 0},[y,h]),A=k??v??f3,j=e=>{let t=e,n=t.languages?.json?.jsonDefaults??t.json?.jsonDefaults,r=structuredClone(pn);n?.setDiagnosticsOptions({validate:!0,allowComments:!1,schemas:[{uri:`vertesia://schemas/content-type-intake-policy.json`,fileMatch:[`*`],schema:r}]})},M=()=>{let e=S3(E===`json`?m.current?.getValue()??y:y,h);if(!e.ok){T(e.message);return}return T(void 0),e.policy},N=()=>{let e=M();if(!e)return;let t=s??(r?e=>u.types.update(r.id,{intake:e,...r.edit_revision===void 0?{}:{expected_edit_revision:r.edit_revision}}).then(e=>(r.edit_revision=e.edit_revision,e.intake)):void 0);t&&(_(!0),t(e).then(t=>{let n=b3(t??e);b(n),S(n),c?.(t??e),f({status:`success`,title:d(`intakePolicy.toast.updated`),description:d(`intakePolicy.toast.saved`),duration:2e3})}).catch(e=>{f({status:`error`,title:d(`intakePolicy.toast.updateFailed`),description:Ge(e),duration:5e3})}).finally(()=>{_(!1)}))},P=()=>{let e=S3(E===`json`?m.current?.getValue()??y:y,h);T(e.ok?void 0:e.message),f({status:e.ok?`success`:`error`,title:e.ok?d(`intakePolicy.toast.valid`):d(`intakePolicy.toast.invalid`),description:e.ok?d(`intakePolicy.toast.schemaValid`):e.message,duration:3e3})},F=()=>{b(x),m.current?.setValue(x),T(void 0)},I=()=>{let e=M();if(!e)return;let t=b3(e);b(t),m.current?.setValue(t)},L=e=>{let t=b3(e.value);b(t),m.current?.setValue(t),T(void 0),D(`overview`)},ee=e=>{b(b3(e)),T(void 0)},R=e=>{let t=e;if(t!==`json`&&!k){T(d(`intakePolicy.error.fixJsonBeforeForm`)),D(`json`);return}D(t)},te=n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{className:`text-base font-semibold`,children:d(`intakePolicy.title`)}),O&&t(i,{variant:`attention`,children:d(`intakePolicy.status.unsaved`)})]}),ne=l?void 0:n(e,{children:[t(w,{align:`right`,trigger:n(o,{variant:`outline`,size:`sm`,children:[t(Lb,{className:`size-4`}),d(`intakePolicy.action.examples`)]}),children:t(ie,{label:d(`intakePolicy.action.insertExample`),children:d3.map(e=>n(ae,{onClick:()=>L(e),children:[t(Kg,{className:`size-4`}),n(`div`,{className:`flex flex-col`,children:[t(`span`,{children:d(`intakePolicy.example.${e.key}.label`)}),t(`span`,{className:`text-xs text-muted`,children:d(`intakePolicy.example.${e.key}.description`)})]})]},e.key))})}),E===`json`&&n(e,{children:[n(o,{variant:`outline`,size:`sm`,onClick:I,children:[t(Lm,{className:`size-4`}),d(`intakePolicy.action.format`)]}),n(o,{variant:`outline`,size:`sm`,onClick:P,children:[t(Lh,{className:`size-4`}),d(`intakePolicy.action.validate`)]})]}),n(o,{variant:`outline`,size:`sm`,onClick:F,disabled:!O,children:[t(yy,{className:`size-4`}),d(`intakePolicy.action.revert`)]}),n(o,{isLoading:g,size:`sm`,onClick:N,disabled:!O,children:[t(Ty,{className:`size-4`}),d(`intakePolicy.action.save`)]})]});return t(me,{title:te,className:`bg-background! h-full`,action:ne,children:n(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[t(h3,{policy:A}),C&&t(`div`,{className:`rounded-sm border border-destructive bg-mixer-destructive/10 px-3 py-2 text-sm whitespace-pre-line text-destructive`,children:C}),n(ze,{tabs:m3(d,k??f3,l,ee,y,{editorRef:m,beforeMount:j,onChange:e=>{b(e),T(void 0)},theme:p}),current:E,onTabChange:R,updateHash:!1,fullHeight:!0,className:`px-0 flex-row!`,children:[t(Be,{className:`py-2 w-48 shrink-0`,direction:`vertical`}),t(Ve,{className:`min-h-0 min-w-0 flex-1 overflow-auto pt-1 ps-4`})]})]})})}function m3(e,r,i,a,o,s){let c=(e,n)=>({name:e,label:n,content:t($4,{policy:r,section:e,onChange:a,readonly:i})});return[c(`overview`,e(`intakePolicy.tab.overview`)),c(`conversion`,e(`intakePolicy.tab.conversion`)),c(`extraction`,e(`intakePolicy.tab.extraction`)),c(`grounding`,e(`intakePolicy.tab.grounding`)),c(`output`,e(`intakePolicy.tab.output`)),{name:`json`,label:e(`intakePolicy.tab.json`),content:n(`div`,{className:`flex h-full min-h-[36rem] gap-4 py-3`,children:[t(`div`,{className:`min-w-0 flex-1 overflow-hidden rounded-sm border`,children:t(Pt,{value:o,language:`json`,editorRef:s.editorRef,beforeMount:s.beforeMount,onChange:e=>s.onChange(e.state.doc.toString()),theme:s.theme===`dark`?`vs-dark`:`vs`,options:{readOnly:i,minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:`on`,lineNumbers:`on`,automaticLayout:!0,formatOnPaste:!0,formatOnType:!0,tabSize:2}})}),t(g3,{})]})}]}function h3({policy:e}){let{t:r}=K(),a=e.extraction?.grounding,o=[[r(`intakePolicy.summary.mode`),y3(r,e.mode)],[r(`intakePolicy.summary.conversion`),v3(r,e.text_conversion?.enabled)],[r(`intakePolicy.summary.method`),y3(r,e.text_conversion?.method)],[r(`intakePolicy.summary.source`),y3(r,e.extraction?.source)],[r(`intakePolicy.summary.extraction`),v3(r,e.extraction?.enabled)],[r(`intakePolicy.summary.grounding`),v3(r,a?.enabled)],[r(`intakePolicy.summary.defaultView`),y3(r,e.default_view)],[r(`intakePolicy.summary.toc`),v3(r,e.generate_toc)],[r(`intakePolicy.summary.template`),e.rendering_template?r(`intakePolicy.option.set`):r(`intakePolicy.option.inherit`)]];return t(`div`,{className:`flex flex-wrap gap-2`,children:o.map(([e,r])=>n(i,{variant:`outline`,className:`gap-1`,children:[n(`span`,{className:`text-muted`,children:[e,`:`]}),t(`span`,{children:r})]},e))})}function g3(){let{t:e}=K();return n(`aside`,{className:`hidden w-80 shrink-0 overflow-y-auto rounded-sm border bg-mixer-muted/20 p-3 text-sm lg:block`,children:[t(`div`,{className:`mb-3 font-semibold`,children:e(`intakePolicy.help.title`)}),n(`div`,{className:`space-y-3 text-muted`,children:[t(_3,{label:`identification`,text:e(`intakePolicy.help.identification`)}),t(_3,{label:`text_conversion`,text:e(`intakePolicy.help.textConversion`)}),t(_3,{label:`extraction.source`,text:e(`intakePolicy.help.extractionSource`)}),t(_3,{label:`extraction.grounding`,text:e(`intakePolicy.help.grounding`)}),t(_3,{label:`extraction.grounding.review`,text:e(`intakePolicy.help.review`)}),t(_3,{label:`rendering_template`,text:e(`intakePolicy.help.renderingTemplate`)}),t(_3,{label:`embeddings`,text:e(`intakePolicy.help.embeddings`)}),t(_3,{label:`default_view`,text:e(`intakePolicy.help.defaultView`)})]})]})}function _3({label:e,text:r}){return n(`div`,{children:[t(`div`,{className:`font-medium text-foreground`,children:e}),t(`div`,{children:r})]})}function v3(e,t){return e(t===!0?`intakePolicy.option.enabled`:t===!1?`intakePolicy.option.disabled`:`intakePolicy.option.inherit`)}function y3(e,t){return e(t?`intakePolicy.option.${t}`:`intakePolicy.option.inherit`)}function b3(e){return JSON.stringify(e??f3,null,2)}function x3(){let e=new tr({strict:!1,allErrors:!0});return sr(e),e.compile(pn)}function S3(e,t){let n;try{n=e.trim()?JSON.parse(e):{}}catch(e){return{ok:!1,message:`Invalid JSON: ${Ge(e)}`}}return t(n)?{ok:!0,policy:n}:{ok:!1,message:C3(t.errors)}}function C3(e){return e?.length?e.map(e=>`${e.instancePath||`/`} ${e.message??`is invalid`}`).join(`
1401
- `):`The intake policy does not match the schema.`}function w3({objectType:e,onSchemaUpdate:r,readonly:i=!1}){let{store:a}=q(),{t:s}=K(),c=nt(),{theme:l}=tt(),[u,d]=G(!1),f=Jt(e.object_schema),p=W(void 0),[m,h]=G(!1),g=U(()=>T3(f.schema),[f]),_=()=>{m&&!y()||(d(!0),a.types.update(e.id,{object_schema:f.schema,...e.edit_revision===void 0?{}:{expected_edit_revision:e.edit_revision}}).then(t=>{e.edit_revision=t.edit_revision,r(f),c({status:`success`,title:s(`store.schemaUpdated`),description:s(`store.schemaUpdatedSuccess`),duration:2e3})}).catch(e=>{c({status:`error`,title:s(`store.failedToUpdateSchema`),description:e.message,duration:5e3})}).finally(()=>{d(!1)}))},v=()=>{m&&!y()||h(e=>!e)},y=()=>{if(p.current){let e=p.current.getValue();try{let t=E3(e);D3(t),f.replaceSchema(t)}catch(e){return c({status:`error`,title:s(`store.invalidJsonSchema`),description:Ge(e),duration:5e3}),!1}}return!0},b=n(`div`,{className:`flex gap-2 items-center`,children:[t(`div`,{className:`text-base font-semibold`,children:s(`store.schemaEditor`)}),!i&&t(`div`,{children:t(o,{variant:`outline`,size:`sm`,onClick:v,children:s(m?`store.editSchema`:`store.editJson`)})})]});return t(me,{title:b,className:`bg-background! h-full`,action:i?void 0:t(o,{isLoading:u,variant:`outline`,size:`sm`,onClick:_,children:s(`modal.saveChanges`)}),children:m?t(Pt,{value:g,language:`json`,editorRef:p,theme:l===`dark`?`vs-dark`:`vs`,options:{readOnly:i}}):t(It,{schema:f,readonly:i})})}function T3(e){return e?JSON.stringify(e,null,2):``}function E3(e){if(e?.trim())return JSON.parse(e.trim())}const D3=e=>{try{new nr({strict:!1}).compile(e)}catch(e){throw Error(`Invalid JSON Schema definition: ${Ge(e)}`,{cause:e})}};Q();function O3({isOpen:e,onClose:r,title:i,children:a,initialSelectedType:s=null,allowNone:c=!0}){let{t:l}=K(),u=i??l(`store.selectContentType`),{registry:d}=UZ(),[f,p]=G(s),m=d?.types||[],h=()=>{r(void 0)};return n(se,{isOpen:e,onClose:h,className:`w-full max-w-xl mx-auto`,children:[t(ue,{children:u}),n(ce,{children:[a,n(`div`,{className:`mb-4 mt-4`,children:[n(`div`,{className:`block text-sm font-medium mb-2`,children:[l(`store.contentType`),` `,c&&t(`span`,{className:`text-gray-500 font-normal`,children:l(`store.optional`)})]}),c?t(we,{options:m,value:f,optionLabel:e=>e?e.name:l(`store.selectContentTypeLabel`),placeholder:l(`store.selectContentTypeAuto`),onChange:e=>p(e||null),filterBy:`name`,isClearable:!0}):t(we,{options:m,value:f,optionLabel:e=>e?e.name:l(`store.selectContentTypeLabel`),placeholder:l(`store.selectContentTypeLabel`),onChange:e=>p(e||null),filterBy:`name`})]}),!f&&n(`div`,{className:`flex items-center text-attention`,children:[t(Ph,{className:`size-4 me-1`}),l(`store.automaticTypeDetection`),t(We,{description:l(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(j_,{className:`size-3 ms-2`})})]})]}),n(le,{children:[t(o,{variant:`ghost`,onClick:h,title:l(`modal.cancel`),children:l(`modal.cancel`)}),t(o,{onClick:()=>{r(f?.id??null),p(null)},title:l(`store.confirmSelection`),children:l(`modal.confirm`)})]})]})}function k3({children:e,limit:n,name:r,chunkable:i}){let{store:a}=q(),o=U(()=>{let e=new z4(a,n);return e.query.name=r,e.query.chunkable=i,e},[i,n,r,a]);return t(B4.Provider,{value:o,children:e})}function A3({objectType:e,onLayoutUpdate:n,readonly:r=!1}){let i=nt(),{theme:a}=tt(),{t:s}=K(),[c,l]=G(!1),{store:u}=q(),d=W(void 0),f=U(()=>j3(e.table_layout),[e.table_layout]),p=(e,t)=>{i({status:`error`,title:e,description:t,duration:5e3})};return t(me,{title:`Table Layout Editor`,className:`bg-background! h-full`,action:r?void 0:t(o,{isLoading:c,variant:`outline`,size:`sm`,onClick:()=>{if(!d.current)return;let t=d.current.getValue(),r;if(!t)r=null;else try{r=JSON.parse(t)}catch(e){return p(`Invalid JSON`,Ge(e))}if(!Array.isArray(r))return p(`Invalid JSON`,`The table layout must be an array`);if(r.some(e=>!e?.name||!e.field))return p(`Invalid JSON`,`A table layout entry must contain the following properties:] {field, name, converter?}`);l(!0),u.types.update(e.id,{...e.edit_revision===void 0?{}:{expected_edit_revision:e.edit_revision},table_layout:r}).then(t=>{e.edit_revision=t.edit_revision,i({status:`success`,title:s(`store.tableLayoutUpdated`),description:s(`store.tableLayoutUpdatedDesc`),duration:2e3}),n(t.table_layout)}).catch(e=>{i({status:`error`,title:s(`store.failedToUpdateTableLayout`),description:e.message,duration:5e3})}).finally(()=>{l(!1)})},children:s(`store.saveChanges`)}),children:t(`div`,{className:`h-full`,children:t(Pt,{value:f,language:`json`,editorRef:d,theme:a===`dark`?`vs-dark`:`vs`,options:{readOnly:r}})})})}function j3(e){return e?JSON.stringify(e,null,2):`[
1400
+ - Due: {{properties.due_date}}`,embeddings:{text:!0,image:!1,properties:!0},generate_toc:!1,default_view:`auto`}}],m3={};function h3({objectType:r,value:a,onSave:s,onIntakeUpdate:c,readonly:l=!1}){let{store:u}=q(),{t:d}=K(),f=nt(),{theme:p}=tt(),m=W(void 0),h=U(()=>C3(),[]),[g,_]=G(!1),v=r?.intake??a,[y,b]=G(()=>S3(v)),[x,S]=G(()=>S3(v)),[C,T]=G(void 0),[E,D]=G(`overview`),O=y!==x,k=U(()=>{let e=w3(y,h);return e.ok?e.policy:void 0},[y,h]),A=k??v??m3,j=e=>{let t=e,n=t.languages?.json?.jsonDefaults??t.json?.jsonDefaults,r=structuredClone(pn);n?.setDiagnosticsOptions({validate:!0,allowComments:!1,schemas:[{uri:`vertesia://schemas/content-type-intake-policy.json`,fileMatch:[`*`],schema:r}]})},M=()=>{let e=w3(E===`json`?m.current?.getValue()??y:y,h);if(!e.ok){T(e.message);return}return T(void 0),e.policy},N=()=>{let e=M();if(!e)return;let t=s??(r?e=>u.types.update(r.id,{intake:e,...r.edit_revision===void 0?{}:{expected_edit_revision:r.edit_revision}}).then(e=>(r.edit_revision=e.edit_revision,e.intake)):void 0);t&&(_(!0),t(e).then(t=>{let n=S3(t??e);b(n),S(n),c?.(t??e),f({status:`success`,title:d(`intakePolicy.toast.updated`),description:d(`intakePolicy.toast.saved`),duration:2e3})}).catch(e=>{f({status:`error`,title:d(`intakePolicy.toast.updateFailed`),description:Ge(e),duration:5e3})}).finally(()=>{_(!1)}))},P=()=>{let e=w3(E===`json`?m.current?.getValue()??y:y,h);T(e.ok?void 0:e.message),f({status:e.ok?`success`:`error`,title:e.ok?d(`intakePolicy.toast.valid`):d(`intakePolicy.toast.invalid`),description:e.ok?d(`intakePolicy.toast.schemaValid`):e.message,duration:3e3})},F=()=>{b(x),m.current?.setValue(x),T(void 0)},I=()=>{let e=M();if(!e)return;let t=S3(e);b(t),m.current?.setValue(t)},L=e=>{let t=S3(e.value);b(t),m.current?.setValue(t),T(void 0),D(`overview`)},ee=e=>{b(S3(e)),T(void 0)},R=e=>{let t=e;if(t!==`json`&&!k){T(d(`intakePolicy.error.fixJsonBeforeForm`)),D(`json`);return}D(t)},te=n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{className:`text-base font-semibold`,children:d(`intakePolicy.title`)}),O&&t(i,{variant:`attention`,children:d(`intakePolicy.status.unsaved`)})]}),ne=l?void 0:n(e,{children:[t(w,{align:`right`,trigger:n(o,{variant:`outline`,size:`sm`,children:[t(Lb,{className:`size-4`}),d(`intakePolicy.action.examples`)]}),children:t(ie,{label:d(`intakePolicy.action.insertExample`),children:p3.map(e=>n(ae,{onClick:()=>L(e),children:[t(Kg,{className:`size-4`}),n(`div`,{className:`flex flex-col`,children:[t(`span`,{children:d(`intakePolicy.example.${e.key}.label`)}),t(`span`,{className:`text-xs text-muted`,children:d(`intakePolicy.example.${e.key}.description`)})]})]},e.key))})}),E===`json`&&n(e,{children:[n(o,{variant:`outline`,size:`sm`,onClick:I,children:[t(Lm,{className:`size-4`}),d(`intakePolicy.action.format`)]}),n(o,{variant:`outline`,size:`sm`,onClick:P,children:[t(Lh,{className:`size-4`}),d(`intakePolicy.action.validate`)]})]}),n(o,{variant:`outline`,size:`sm`,onClick:F,disabled:!O,children:[t(yy,{className:`size-4`}),d(`intakePolicy.action.revert`)]}),n(o,{isLoading:g,size:`sm`,onClick:N,disabled:!O,children:[t(Ty,{className:`size-4`}),d(`intakePolicy.action.save`)]})]});return t(me,{title:te,className:`bg-background! h-full`,action:ne,children:n(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[t(_3,{policy:A}),C&&t(`div`,{className:`rounded-sm border border-destructive bg-mixer-destructive/10 px-3 py-2 text-sm whitespace-pre-line text-destructive`,children:C}),n(ze,{tabs:g3(d,k??m3,l,ee,y,{editorRef:m,beforeMount:j,onChange:e=>{b(e),T(void 0)},theme:p}),current:E,onTabChange:R,updateHash:!1,fullHeight:!0,className:`px-0 flex-row!`,children:[t(Be,{className:`py-2 w-48 shrink-0`,direction:`vertical`}),t(Ve,{className:`min-h-0 min-w-0 flex-1 overflow-auto pt-1 ps-4`})]})]})})}function g3(e,r,i,a,o,s){let c=(e,n)=>({name:e,label:n,content:t(t3,{policy:r,section:e,onChange:a,readonly:i})});return[c(`overview`,e(`intakePolicy.tab.overview`)),c(`conversion`,e(`intakePolicy.tab.conversion`)),c(`extraction`,e(`intakePolicy.tab.extraction`)),c(`grounding`,e(`intakePolicy.tab.grounding`)),c(`output`,e(`intakePolicy.tab.output`)),{name:`json`,label:e(`intakePolicy.tab.json`),content:n(`div`,{className:`flex h-full min-h-[36rem] gap-4 py-3`,children:[t(`div`,{className:`min-w-0 flex-1 overflow-hidden rounded-sm border`,children:t(Pt,{value:o,language:`json`,editorRef:s.editorRef,beforeMount:s.beforeMount,onChange:e=>s.onChange(e.state.doc.toString()),theme:s.theme===`dark`?`vs-dark`:`vs`,options:{readOnly:i,minimap:{enabled:!1},scrollBeyondLastLine:!1,wordWrap:`on`,lineNumbers:`on`,automaticLayout:!0,formatOnPaste:!0,formatOnType:!0,tabSize:2}})}),t(v3,{})]})}]}function _3({policy:e}){let{t:r}=K(),a=e.extraction?.grounding,o=[[r(`intakePolicy.summary.mode`),x3(r,e.mode)],[r(`intakePolicy.summary.conversion`),b3(r,e.text_conversion?.enabled)],[r(`intakePolicy.summary.method`),x3(r,e.text_conversion?.method)],[r(`intakePolicy.summary.source`),x3(r,e.extraction?.source)],[r(`intakePolicy.summary.extraction`),b3(r,e.extraction?.enabled)],[r(`intakePolicy.summary.grounding`),b3(r,a?.enabled)],[r(`intakePolicy.summary.defaultView`),x3(r,e.default_view)],[r(`intakePolicy.summary.toc`),b3(r,e.generate_toc)],[r(`intakePolicy.summary.template`),e.rendering_template?r(`intakePolicy.option.set`):r(`intakePolicy.option.inherit`)]];return t(`div`,{className:`flex flex-wrap gap-2`,children:o.map(([e,r])=>n(i,{variant:`outline`,className:`gap-1`,children:[n(`span`,{className:`text-muted`,children:[e,`:`]}),t(`span`,{children:r})]},e))})}function v3(){let{t:e}=K();return n(`aside`,{className:`hidden w-80 shrink-0 overflow-y-auto rounded-sm border bg-mixer-muted/20 p-3 text-sm lg:block`,children:[t(`div`,{className:`mb-3 font-semibold`,children:e(`intakePolicy.help.title`)}),n(`div`,{className:`space-y-3 text-muted`,children:[t(y3,{label:`identification`,text:e(`intakePolicy.help.identification`)}),t(y3,{label:`text_conversion`,text:e(`intakePolicy.help.textConversion`)}),t(y3,{label:`extraction.source`,text:e(`intakePolicy.help.extractionSource`)}),t(y3,{label:`extraction.grounding`,text:e(`intakePolicy.help.grounding`)}),t(y3,{label:`extraction.grounding.review`,text:e(`intakePolicy.help.review`)}),t(y3,{label:`rendering_template`,text:e(`intakePolicy.help.renderingTemplate`)}),t(y3,{label:`embeddings`,text:e(`intakePolicy.help.embeddings`)}),t(y3,{label:`default_view`,text:e(`intakePolicy.help.defaultView`)})]})]})}function y3({label:e,text:r}){return n(`div`,{children:[t(`div`,{className:`font-medium text-foreground`,children:e}),t(`div`,{children:r})]})}function b3(e,t){return e(t===!0?`intakePolicy.option.enabled`:t===!1?`intakePolicy.option.disabled`:`intakePolicy.option.inherit`)}function x3(e,t){return e(t?`intakePolicy.option.${t}`:`intakePolicy.option.inherit`)}function S3(e){return JSON.stringify(e??m3,null,2)}function C3(){let e=new tr({strict:!1,allErrors:!0});return sr(e),e.compile(pn)}function w3(e,t){let n;try{n=e.trim()?JSON.parse(e):{}}catch(e){return{ok:!1,message:`Invalid JSON: ${Ge(e)}`}}return t(n)?{ok:!0,policy:n}:{ok:!1,message:T3(t.errors)}}function T3(e){return e?.length?e.map(e=>`${e.instancePath||`/`} ${e.message??`is invalid`}`).join(`
1401
+ `):`The intake policy does not match the schema.`}function E3({objectType:e,onSchemaUpdate:r,readonly:i=!1}){let{store:a}=q(),{t:s}=K(),c=nt(),{theme:l}=tt(),[u,d]=G(!1),f=Jt(e.object_schema),p=W(void 0),[m,h]=G(!1),g=U(()=>D3(f.schema),[f]),_=()=>{m&&!y()||(d(!0),a.types.update(e.id,{object_schema:f.schema,...e.edit_revision===void 0?{}:{expected_edit_revision:e.edit_revision}}).then(t=>{e.edit_revision=t.edit_revision,r(f),c({status:`success`,title:s(`store.schemaUpdated`),description:s(`store.schemaUpdatedSuccess`),duration:2e3})}).catch(e=>{c({status:`error`,title:s(`store.failedToUpdateSchema`),description:e.message,duration:5e3})}).finally(()=>{d(!1)}))},v=()=>{m&&!y()||h(e=>!e)},y=()=>{if(p.current){let e=p.current.getValue();try{let t=O3(e);k3(t),f.replaceSchema(t)}catch(e){return c({status:`error`,title:s(`store.invalidJsonSchema`),description:Ge(e),duration:5e3}),!1}}return!0},b=n(`div`,{className:`flex gap-2 items-center`,children:[t(`div`,{className:`text-base font-semibold`,children:s(`store.schemaEditor`)}),!i&&t(`div`,{children:t(o,{variant:`outline`,size:`sm`,onClick:v,children:s(m?`store.editSchema`:`store.editJson`)})})]});return t(me,{title:b,className:`bg-background! h-full`,action:i?void 0:t(o,{isLoading:u,variant:`outline`,size:`sm`,onClick:_,children:s(`modal.saveChanges`)}),children:m?t(Pt,{value:g,language:`json`,editorRef:p,theme:l===`dark`?`vs-dark`:`vs`,options:{readOnly:i}}):t(It,{schema:f,readonly:i})})}function D3(e){return e?JSON.stringify(e,null,2):``}function O3(e){if(e?.trim())return JSON.parse(e.trim())}const k3=e=>{try{new nr({strict:!1}).compile(e)}catch(e){throw Error(`Invalid JSON Schema definition: ${Ge(e)}`,{cause:e})}};Q();function A3({isOpen:e,onClose:r,title:i,children:a,initialSelectedType:s=null,allowNone:c=!0}){let{t:l}=K(),u=i??l(`store.selectContentType`),{registry:d}=GZ(),[f,p]=G(s),m=d?.types||[],h=()=>{r(void 0)};return n(se,{isOpen:e,onClose:h,className:`w-full max-w-xl mx-auto`,children:[t(ue,{children:u}),n(ce,{children:[a,n(`div`,{className:`mb-4 mt-4`,children:[n(`div`,{className:`block text-sm font-medium mb-2`,children:[l(`store.contentType`),` `,c&&t(`span`,{className:`text-gray-500 font-normal`,children:l(`store.optional`)})]}),c?t(we,{options:m,value:f,optionLabel:e=>e?e.name:l(`store.selectContentTypeLabel`),placeholder:l(`store.selectContentTypeAuto`),onChange:e=>p(e||null),filterBy:`name`,isClearable:!0}):t(we,{options:m,value:f,optionLabel:e=>e?e.name:l(`store.selectContentTypeLabel`),placeholder:l(`store.selectContentTypeLabel`),onChange:e=>p(e||null),filterBy:`name`})]}),!f&&n(`div`,{className:`flex items-center text-attention`,children:[t(Ph,{className:`size-4 me-1`}),l(`store.automaticTypeDetection`),t(We,{description:l(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(j_,{className:`size-3 ms-2`})})]})]}),n(le,{children:[t(o,{variant:`ghost`,onClick:h,title:l(`modal.cancel`),children:l(`modal.cancel`)}),t(o,{onClick:()=>{r(f?.id??null),p(null)},title:l(`store.confirmSelection`),children:l(`modal.confirm`)})]})]})}function j3({children:e,limit:n,name:r,chunkable:i}){let{store:a}=q(),o=U(()=>{let e=new V4(a,n);return e.query.name=r,e.query.chunkable=i,e},[i,n,r,a]);return t(H4.Provider,{value:o,children:e})}function M3({objectType:e,onLayoutUpdate:n,readonly:r=!1}){let i=nt(),{theme:a}=tt(),{t:s}=K(),[c,l]=G(!1),{store:u}=q(),d=W(void 0),f=U(()=>N3(e.table_layout),[e.table_layout]),p=(e,t)=>{i({status:`error`,title:e,description:t,duration:5e3})};return t(me,{title:`Table Layout Editor`,className:`bg-background! h-full`,action:r?void 0:t(o,{isLoading:c,variant:`outline`,size:`sm`,onClick:()=>{if(!d.current)return;let t=d.current.getValue(),r;if(!t)r=null;else try{r=JSON.parse(t)}catch(e){return p(`Invalid JSON`,Ge(e))}if(!Array.isArray(r))return p(`Invalid JSON`,`The table layout must be an array`);if(r.some(e=>!e?.name||!e.field))return p(`Invalid JSON`,`A table layout entry must contain the following properties:] {field, name, converter?}`);l(!0),u.types.update(e.id,{...e.edit_revision===void 0?{}:{expected_edit_revision:e.edit_revision},table_layout:r}).then(t=>{e.edit_revision=t.edit_revision,i({status:`success`,title:s(`store.tableLayoutUpdated`),description:s(`store.tableLayoutUpdatedDesc`),duration:2e3}),n(t.table_layout)}).catch(e=>{i({status:`error`,title:s(`store.failedToUpdateTableLayout`),description:e.message,duration:5e3})}).finally(()=>{l(!1)})},children:s(`store.saveChanges`)}),children:t(`div`,{className:`h-full`,children:t(Pt,{value:f,language:`json`,editorRef:d,theme:a===`dark`?`vs-dark`:`vs`,options:{readOnly:r}})})})}function N3(e){return e?JSON.stringify(e,null,2):`[
1402
1402
 
1403
- ]`}function M3({collection:e}){let{client:n}=q(),{t:r}=K(),[i,a]=G(void 0),[s,c]=G(e.shared_properties||[]),l=nt();H(()=>{e.type?.id&&n.store.types.retrieve(e.type.id).then(a)},[n.store.types.retrieve,e.type?.id]);let u=i?Object.keys(i.object_schema?.properties||{}):[];return t(me,{title:r(`store.sharedProperties`),description:r(`store.sharedPropertiesDescription`),action:t(o,{size:`lg`,isLoading:!1,onClick:()=>{n.store.collections.update(e.id,{shared_properties:s}).then(()=>{l({title:r(`store.updatedSharedProperties`),status:`success`})}).catch(e=>{l({title:r(`store.failedToUpdateSharedProperties`),description:e.message,status:`error`})})},children:r(`modal.save`)}),children:t(`div`,{className:``,children:t(He,{value:s,onChange:e=>{c(e)},options:u,placeholder:r(`store.selectPropertiesToShare`)})})})}function N3({collection:e}){let{client:n}=q(),{t:r}=K(),[i,a]=G(e.skip_head_sync??!1),[o,s]=G(!1),c=nt();return t(me,{title:r(`store.syncMemberHeads`),description:r(`store.syncMemberHeadsDescription`),children:t(Ne,{disabled:o,value:!i,onChange:t=>{let i=!t;s(!0),n.store.collections.update(e.id,{skip_head_sync:i}).then(()=>{c({title:r(`store.updatedSkipHeadSync`),status:`success`}),a(i)}).catch(e=>{c({title:r(`store.failedToUpdateSkipHeadSync`),description:e.message,status:`error`})}).finally(()=>{s(!1)})},children:r(`store.enableSyncMemberHeads`)})})}function P3(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function F3({refetch:r,collection:a}){let{t:s}=K(),c=a.type?Dn(a.type):void 0,l=W(void 0),u=nt(),{theme:d}=tt(),{client:f}=q(),p=_t(T$),[m,h]=G(!1),[g,_]=G({name:a.name,description:a.description||``,query:a.query?JSON.stringify(a.query,null,2):``,tags:a.tags||[],type:a.type?Dn(a.type):``,allowed_types:a.allowed_types||[],sensitivity:a.sensitivity,compartments:a.compartments||[]}),[v,y]=G(``),b=U(()=>j3(a.table_layout),[a.table_layout]),x=()=>{let e;try{let t=g.query?JSON.parse(g.query):void 0;if(t!==void 0&&!P3(t))throw Error(s(`store.invalidQueryJson`));e=t}catch(e){u({title:s(`store.invalidQueryJson`),description:Ge(e),status:`error`,duration:5e3});return}let t={name:g.name,description:g.description,query:e,tags:g.tags,type:g.type,allowed_types:g.allowed_types,sensitivity:g.sensitivity,compartments:g.compartments},n;if(t.name||(n=s(`type.nameRequired`)),t.type||=null,n){u({title:s(`store.validationFailed`),description:n,status:`error`,duration:5e3});return}if(l.current){let e=l.current.getValue();if(e)try{t.table_layout=JSON.parse(e)}catch(e){u({title:s(`store.invalidTableLayout`),description:Ge(e),status:`error`,duration:5e3});return}else t.table_layout=null}h(!0),f.store.collections.update(a.id,t).then(()=>{r(),a.dynamic&&p&&(p.reset(),p.search()),u({title:s(`store.collectionUpdated`),description:s(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{u({title:s(`store.failedToUpdateCollection`),description:Ge(e),status:`error`,duration:5e3})}).finally(()=>{h(!1)})},S=(e,t)=>{_({...g,[e]:t})};return n(`div`,{className:`flex flex-col gap-4 py-2`,children:[n(me,{title:s(`store.configuration`),action:t(o,{size:`lg`,isDisabled:m,onClick:x,children:s(`modal.save`)}),children:[n(`div`,{className:`flex justify-between mb-2`,children:[n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.createdBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(OZ,{userRef:a.created_by,showTitle:!0}),n(`span`,{children:[`at `,GD(a.created_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]}),n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.updatedBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(OZ,{userRef:a.updated_by,showTitle:!0}),n(`span`,{children:[`at `,GD(a.updated_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]})]}),t(L,{label:s(`type.name`),required:!0,children:t(te,{value:g.name,onChange:e=>S(`name`,e)})}),t(L,{label:s(`type.description`),children:t(Ue,{value:g.description,onChange:e=>S(`description`,e.target.value)})}),!a.dynamic&&t(L,{label:s(`store.allowedContentTypes`),description:s(`store.allowedContentTypesSelectDescription`),children:t(j4,{defaultValue:g.allowed_types||null,onChange:e=>{Array.isArray(e)?S(`allowed_types`,e.map(e=>e.id)):S(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),a.dynamic&&t(L,{label:s(`store.query`),description:s(`store.queryDescription`),children:t(Ue,{className:Me.INPUT,minLines:1,maxLines:12,value:g.query,onChange:e=>S(`query`,e.target.value)})}),t(L,{label:s(`store.tableLayout`),description:s(`store.tableLayoutDescription`),className:`h-[200px]`,children:t(Pt,{className:`border-1 rounded-md border-border`,value:b,language:`json`,editorRef:l,theme:d===`dark`?`vs-dark`:`vs`})}),t(L,{label:s(`store.contentType`),description:s(`store.typeSelectDescription`),children:t(j4,{defaultValue:g.type||null,onChange:e=>{Array.isArray(e)?S(`type`,e.length>0?e[0].id:null):S(`type`,e?.id||null)},isClearable:!0})}),t(L,{label:`Sensitivity`,description:`BLP sensitivity level — propagated to member documents (max across collections)`,children:t(we,{options:Cn.map((e,t)=>({label:`${t} — ${e}`,value:t})),value:g.sensitivity===void 0?void 0:{label:`${g.sensitivity} — ${Cn[g.sensitivity]??`Unknown`}`,value:g.sensitivity},onChange:e=>S(`sensitivity`,e.value),optionLabel:e=>e.label,by:`value`,placeholder:`Not set`})}),n(L,{label:`Compartments`,description:`Security compartments — propagated to member documents (union across collections)`,children:[n(`div`,{className:`flex gap-2`,children:[t(te,{value:v,onChange:y,placeholder:`Add a compartment`,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=v.trim();t&&!g.compartments.includes(t)&&(S(`compartments`,[...g.compartments,t]),y(``))}}}),t(o,{type:`button`,variant:`outline`,onClick:()=>{let e=v.trim();e&&!g.compartments.includes(e)&&(S(`compartments`,[...g.compartments,e]),y(``))},children:`Add`})]}),t(`div`,{className:`flex gap-1 flex-wrap mt-2`,children:g.compartments.map(e=>n(i,{variant:`secondary`,className:`cursor-pointer`,onClick:()=>S(`compartments`,g.compartments.filter(t=>t!==e)),children:[e,` ×`]},e))})]})]}),c&&t(I3,{typeId:c,collection:a}),!a.dynamic&&n(e,{children:[t(N3,{collection:a}),t(M3,{collection:a})]})]})}function I3({typeId:e,collection:n}){let{t:r}=K(),[i,a]=G({}),s=nt(),{client:c}=q(),[l,u]=G(!1),{data:d,error:f}=Ye(()=>c.store.types.catalog.resolve(e),[e]),p=d?.object_schema||{},m=U(()=>new Mt(p,n.properties||{}),[p,n.properties]);if(f)return t(M,{title:r(`store.failedToLoadType`),children:Ge(f)});if(!d)return null;let h=e=>{if(!e||!Object.keys(e).length)return;let t={properties:e||{}};u(!0),c.store.collections.update(n.id,t).then(()=>{s({title:r(`store.collectionPropertiesUpdated`),description:r(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{s({title:r(`store.failedToUpdateCollectionProperties`),description:Ge(e),status:`error`,duration:5e3})}).finally(()=>{u(!1)})};return t(me,{title:r(`store.properties`),action:t(o,{size:`lg`,isLoading:l,type:`submit`,onClick:()=>h(i),children:r(`modal.save`)}),children:t(kt,{object:m,onChange:e=>{e instanceof Mt&&a(e.value)}})})}Q();function L3({onChange:e,value:r,disabled:i=!1,placeholder:a,searchPlaceholder:s,filterOut:c,allowDynamic:l=!0,multiple:u=!1}){let{client:d}=q(),{t:f}=K(),p=a??f(`store.selectACollection`),m=s??f(`store.searchCollections`),[b,x]=G(``),[S,C]=G(!1),[w,T]=G(!1),E=Je(b,300),D=V(async e=>{C(!0);let t=e.trim(),n=await d.store.collections.search({dynamic:l?void 0:!1,name:w&&t||void 0});return C(!1),!w&&n.length>=1e3&&T(!0),c&&c.length>0?n.filter(e=>!c.includes(e.id)):n},[d,l,c,w]),{data:O,error:k}=Ye(()=>D(w?E:``),[w?E:``,D]),A=U(()=>O?u&&Array.isArray(r)?O.filter(e=>r.includes(e.id)):!u&&typeof r==`string`?O.find(e=>e.id===r):u?[]:void 0:u?[]:void 0,[O,r,u]),j=V(t=>{if(u){let n=Array.isArray(r)?r:[];if(n.includes(t.id)){let r=n.filter(e=>e!==t.id);e(r,O?.filter(e=>r.includes(e.id))||[])}else{let r=[...n,t.id];e(r,O?.filter(e=>r.includes(e.id))||[])}}else e(t.id,t)},[e,r,O,u]),N=V(()=>{e(void 0,void 0)},[e]),P=V(e=>{x(e)},[]),F=b.trim().length>0,I=U(()=>{if(!O)return[];if(w||!F)return O;let e=b.toLowerCase();return O.filter(t=>t.name.toLowerCase().includes(e))},[O,w,F,b]),L=u?Array.isArray(A)&&A.length>0:!!A;return k?t(M,{title:f(`store.collectionFetchFailed`),children:Ge(k)}):n(he,{children:[t(_e,{asChild:!0,children:n(o,{variant:`outline`,role:`combobox`,"aria-haspopup":`listbox`,className:z(`w-full justify-between min-w-0`),disabled:i,children:[t(`span`,{className:`truncate flex-1 text-start min-w-0`,children:u&&Array.isArray(A)&&A.length>0?A.length===1?A[0].name:f(`store.collectionsSelected`,{count:A.length}):!u&&A&&!Array.isArray(A)?A.name:p}),L&&!i?t(o,{variant:`unstyled`,"aria-label":`Clear selection`,className:`ms-2 shrink-0 opacity-50 hover:opacity-100 hover:text-destructive cursor-pointer`,onClick:e=>{e.stopPropagation(),N()},children:t(Kb,{className:`h-4 w-4`})}):t(Th,{className:`ms-2 h-4 w-4 shrink-0 opacity-50`})]})}),t(ge,{className:`mt-2 mb-2 w-[var(--radix-popover-trigger-width)] p-0`,align:`start`,children:n(h,{shouldFilter:!1,children:[n(`div`,{className:`flex justify-between items-center border-b px-3`,"cmdk-input-wrapper":``,children:[t(v,{placeholder:m,value:b,onValueChange:P,className:`flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`}),S&&t(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`})]}),t(g,{children:f(S?`store.searching`:F?`store.noCollectionsFound`:`store.noCollectionsAvailable`)}),n(_,{className:`max-h-[300px] overflow-auto`,children:[L&&!F&&t(y,{value:`__clear__`,onSelect:N,className:`text-destructive`,children:`Remove collection selection(s)`}),F&&t(y,{value:`__clear_search__`,onSelect:()=>x(``),className:`text-muted`,children:f(`store.clearSelection`)}),I.map(e=>{let i=u&&Array.isArray(r)?r.includes(e.id):r===e.id;return n(y,{value:e.id,onSelect:()=>j(e),className:`flex items-center justify-between`,children:[t(`span`,{className:`truncate`,children:e.name}),i&&t(th,{className:`ms-2 h-4 w-4 shrink-0`})]},e.id)})]})]})})]})}function R3({isOpen:e,onClose:r}){return n(se,{onClose:()=>r(),isOpen:!!e,className:`min-w-[60vw]`,children:[t(ue,{children:`Select Content`}),t(ce,{className:`pt-0 overflow-y-auto max-h-[80vh] min-h-[80vh]`,children:e&&t(q$,{onChange:r})})]})}Q();const z3=/store:([a-f0-9]+)/;function B3({object:e}){let{client:r}=q(),{off:i,on:a,isOn:s}=Ze(),[c,l]=G(e.value==null?``:String(e.value)),[u,d]=G(void 0),f=t=>{let n=t.target.value;l(n),e.value=n},p=V(()=>{l(``),e.value=``,d(void 0)},[e]);return H(()=>{if(!c||u)return;let e=c.match(z3);e&&r.objects.retrieve(e[1]).then(e=>{d(e)}).catch(()=>{p()})},[c,r.objects.retrieve,p,u]),n(`div`,{children:[n(`div`,{className:`relative`,children:[t(`input`,{value:c,onChange:f,className:it(Me.INPUT,`pe-10 w-full`)}),u&&t(`div`,{className:`absolute inset-y-0 end-10 flex items-center justify-center `,children:t(o,{onClick:p,variant:`unstyled`,className:`hover:text-red-500 hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(Kb,{className:`size-5`})})}),t(`div`,{className:`absolute inset-y-0 end-0 flex items-center justify-center`,children:t(o,{onClick:a,variant:`unstyled`,className:`hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(Th,{className:`size-5`})})}),t(R3,{value:c,isOpen:s,onClose:t=>{if(t){let n=`store:${t.id}`;l(n),d(t||void 0),e.value=n}i()}})]}),u&&t(`div`,{className:`p-1 semibold text-sm text-gray-600 dark:text-slate-300`,children:typeof u.properties?.title==`string`?u.properties.title:u.name})]})}Q();function V3({objectId:e,isOpen:r,onClose:i}){let a=$n(),{client:s,store:c}=q(),[l,u]=G(null),[d,f]=G(!1),[p,m]=G(!1),[h,g]=G(),[_,v]=G(),[y,b]=G(`preview`),{t:x}=K(),S=nt(),C=V(async e=>{m(!0);try{let t=await c.objects.getObjectText(e);g(t.text)}catch(e){console.error(`Error loading text:`,e)}finally{m(!1)}},[c.objects]),w=V(async e=>{if(e.content?.source)try{(await s.objects.getRendition(e.id,{format:hn.jpeg,generate_if_missing:!1})).status===`found`&&console.log(`Found rendition`);let t=await s.files.getDownloadUrl(e.content.source);v(t.url)}catch(e){console.error(`Error loading image:`,e)}},[s.files,s.objects]);H(()=>{e&&r?(f(!0),c.objects.retrieve(e,`+embeddings`).then(e=>{u(e),e.text?g(e.text):C(e.id);let t=e.content;t?.source&&t.type?.startsWith(`image/`)&&w(e)}).catch(e=>{console.error(`Error loading object:`,e),S({title:x(`agent.error`),description:x(`store.failedToLoadDocument`),status:`error`,duration:3e3})}).finally(()=>{f(!1)})):(u(null),g(void 0),v(void 0))},[e,r,c.objects,C,w,x,S]);let T=()=>{l&&(a(`/legal/objects/${l.id}`),i())},E=h&&(h.startsWith(`#`)||h.includes(`
1403
+ ]`}function P3({collection:e}){let{client:n}=q(),{t:r}=K(),[i,a]=G(void 0),[s,c]=G(e.shared_properties||[]),l=nt();H(()=>{e.type?.id&&n.store.types.retrieve(e.type.id).then(a)},[n.store.types.retrieve,e.type?.id]);let u=i?Object.keys(i.object_schema?.properties||{}):[];return t(me,{title:r(`store.sharedProperties`),description:r(`store.sharedPropertiesDescription`),action:t(o,{size:`lg`,isLoading:!1,onClick:()=>{n.store.collections.update(e.id,{shared_properties:s}).then(()=>{l({title:r(`store.updatedSharedProperties`),status:`success`})}).catch(e=>{l({title:r(`store.failedToUpdateSharedProperties`),description:e.message,status:`error`})})},children:r(`modal.save`)}),children:t(`div`,{className:``,children:t(He,{value:s,onChange:e=>{c(e)},options:u,placeholder:r(`store.selectPropertiesToShare`)})})})}function F3({collection:e}){let{client:n}=q(),{t:r}=K(),[i,a]=G(e.skip_head_sync??!1),[o,s]=G(!1),c=nt();return t(me,{title:r(`store.syncMemberHeads`),description:r(`store.syncMemberHeadsDescription`),children:t(Ne,{disabled:o,value:!i,onChange:t=>{let i=!t;s(!0),n.store.collections.update(e.id,{skip_head_sync:i}).then(()=>{c({title:r(`store.updatedSkipHeadSync`),status:`success`}),a(i)}).catch(e=>{c({title:r(`store.failedToUpdateSkipHeadSync`),description:e.message,status:`error`})}).finally(()=>{s(!1)})},children:r(`store.enableSyncMemberHeads`)})})}function I3(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function L3({refetch:r,collection:a}){let{t:s}=K(),c=a.type?Dn(a.type):void 0,l=W(void 0),u=nt(),{theme:d}=tt(),{client:f}=q(),p=_t(D$),[m,h]=G(!1),[g,_]=G({name:a.name,description:a.description||``,query:a.query?JSON.stringify(a.query,null,2):``,tags:a.tags||[],type:a.type?Dn(a.type):``,allowed_types:a.allowed_types||[],sensitivity:a.sensitivity,compartments:a.compartments||[]}),[v,y]=G(``),b=U(()=>N3(a.table_layout),[a.table_layout]),x=()=>{let e;try{let t=g.query?JSON.parse(g.query):void 0;if(t!==void 0&&!I3(t))throw Error(s(`store.invalidQueryJson`));e=t}catch(e){u({title:s(`store.invalidQueryJson`),description:Ge(e),status:`error`,duration:5e3});return}let t={name:g.name,description:g.description,query:e,tags:g.tags,type:g.type,allowed_types:g.allowed_types,sensitivity:g.sensitivity,compartments:g.compartments},n;if(t.name||(n=s(`type.nameRequired`)),t.type||=null,n){u({title:s(`store.validationFailed`),description:n,status:`error`,duration:5e3});return}if(l.current){let e=l.current.getValue();if(e)try{t.table_layout=JSON.parse(e)}catch(e){u({title:s(`store.invalidTableLayout`),description:Ge(e),status:`error`,duration:5e3});return}else t.table_layout=null}h(!0),f.store.collections.update(a.id,t).then(()=>{r(),a.dynamic&&p&&(p.reset(),p.search()),u({title:s(`store.collectionUpdated`),description:s(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{u({title:s(`store.failedToUpdateCollection`),description:Ge(e),status:`error`,duration:5e3})}).finally(()=>{h(!1)})},S=(e,t)=>{_({...g,[e]:t})};return n(`div`,{className:`flex flex-col gap-4 py-2`,children:[n(me,{title:s(`store.configuration`),action:t(o,{size:`lg`,isDisabled:m,onClick:x,children:s(`modal.save`)}),children:[n(`div`,{className:`flex justify-between mb-2`,children:[n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.createdBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(AZ,{userRef:a.created_by,showTitle:!0}),n(`span`,{children:[`at `,GD(a.created_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]}),n(`div`,{className:`w-1/2 gap-2 flex flex-col`,children:[t(`div`,{className:`text-sm font-medium mb-1`,children:s(`store.updatedBy`)}),n(`div`,{className:`gap-2 flex items-center`,children:[t(AZ,{userRef:a.updated_by,showTitle:!0}),n(`span`,{children:[`at `,GD(a.updated_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]})]}),t(L,{label:s(`type.name`),required:!0,children:t(te,{value:g.name,onChange:e=>S(`name`,e)})}),t(L,{label:s(`type.description`),children:t(Ue,{value:g.description,onChange:e=>S(`description`,e.target.value)})}),!a.dynamic&&t(L,{label:s(`store.allowedContentTypes`),description:s(`store.allowedContentTypesSelectDescription`),children:t(N4,{defaultValue:g.allowed_types||null,onChange:e=>{Array.isArray(e)?S(`allowed_types`,e.map(e=>e.id)):S(`allowed_types`,e?[e.id]:[])},isClearable:!0,multiple:!0})}),a.dynamic&&t(L,{label:s(`store.query`),description:s(`store.queryDescription`),children:t(Ue,{className:Me.INPUT,minLines:1,maxLines:12,value:g.query,onChange:e=>S(`query`,e.target.value)})}),t(L,{label:s(`store.tableLayout`),description:s(`store.tableLayoutDescription`),className:`h-[200px]`,children:t(Pt,{className:`border-1 rounded-md border-border`,value:b,language:`json`,editorRef:l,theme:d===`dark`?`vs-dark`:`vs`})}),t(L,{label:s(`store.contentType`),description:s(`store.typeSelectDescription`),children:t(N4,{defaultValue:g.type||null,onChange:e=>{Array.isArray(e)?S(`type`,e.length>0?e[0].id:null):S(`type`,e?.id||null)},isClearable:!0})}),t(L,{label:`Sensitivity`,description:`BLP sensitivity level — propagated to member documents (max across collections)`,children:t(we,{options:Cn.map((e,t)=>({label:`${t} — ${e}`,value:t})),value:g.sensitivity===void 0?void 0:{label:`${g.sensitivity} — ${Cn[g.sensitivity]??`Unknown`}`,value:g.sensitivity},onChange:e=>S(`sensitivity`,e.value),optionLabel:e=>e.label,by:`value`,placeholder:`Not set`})}),n(L,{label:`Compartments`,description:`Security compartments — propagated to member documents (union across collections)`,children:[n(`div`,{className:`flex gap-2`,children:[t(te,{value:v,onChange:y,placeholder:`Add a compartment`,onKeyDown:e=>{if(e.key===`Enter`){e.preventDefault();let t=v.trim();t&&!g.compartments.includes(t)&&(S(`compartments`,[...g.compartments,t]),y(``))}}}),t(o,{type:`button`,variant:`outline`,onClick:()=>{let e=v.trim();e&&!g.compartments.includes(e)&&(S(`compartments`,[...g.compartments,e]),y(``))},children:`Add`})]}),t(`div`,{className:`flex gap-1 flex-wrap mt-2`,children:g.compartments.map(e=>n(i,{variant:`secondary`,className:`cursor-pointer`,onClick:()=>S(`compartments`,g.compartments.filter(t=>t!==e)),children:[e,` ×`]},e))})]})]}),c&&t(R3,{typeId:c,collection:a}),!a.dynamic&&n(e,{children:[t(F3,{collection:a}),t(P3,{collection:a})]})]})}function R3({typeId:e,collection:n}){let{t:r}=K(),[i,a]=G({}),s=nt(),{client:c}=q(),[l,u]=G(!1),{data:d,error:f}=Ye(()=>c.store.types.catalog.resolve(e),[e]),p=d?.object_schema||{},m=U(()=>new Mt(p,n.properties||{}),[p,n.properties]);if(f)return t(M,{title:r(`store.failedToLoadType`),children:Ge(f)});if(!d)return null;let h=e=>{if(!e||!Object.keys(e).length)return;let t={properties:e||{}};u(!0),c.store.collections.update(n.id,t).then(()=>{s({title:r(`store.collectionPropertiesUpdated`),description:r(`store.collectionUpdatedSuccess`),status:`success`,duration:3e3})}).catch(e=>{s({title:r(`store.failedToUpdateCollectionProperties`),description:Ge(e),status:`error`,duration:5e3})}).finally(()=>{u(!1)})};return t(me,{title:r(`store.properties`),action:t(o,{size:`lg`,isLoading:l,type:`submit`,onClick:()=>h(i),children:r(`modal.save`)}),children:t(kt,{object:m,onChange:e=>{e instanceof Mt&&a(e.value)}})})}Q();function z3({onChange:e,value:r,disabled:i=!1,placeholder:a,searchPlaceholder:s,filterOut:c,allowDynamic:l=!0,multiple:u=!1}){let{client:d}=q(),{t:f}=K(),p=a??f(`store.selectACollection`),m=s??f(`store.searchCollections`),[b,x]=G(``),[S,C]=G(!1),[w,T]=G(!1),E=Je(b,300),D=V(async e=>{C(!0);let t=e.trim(),n=await d.store.collections.search({dynamic:l?void 0:!1,name:w&&t||void 0});return C(!1),!w&&n.length>=1e3&&T(!0),c&&c.length>0?n.filter(e=>!c.includes(e.id)):n},[d,l,c,w]),{data:O,error:k}=Ye(()=>D(w?E:``),[w?E:``,D]),A=U(()=>O?u&&Array.isArray(r)?O.filter(e=>r.includes(e.id)):!u&&typeof r==`string`?O.find(e=>e.id===r):u?[]:void 0:u?[]:void 0,[O,r,u]),j=V(t=>{if(u){let n=Array.isArray(r)?r:[];if(n.includes(t.id)){let r=n.filter(e=>e!==t.id);e(r,O?.filter(e=>r.includes(e.id))||[])}else{let r=[...n,t.id];e(r,O?.filter(e=>r.includes(e.id))||[])}}else e(t.id,t)},[e,r,O,u]),N=V(()=>{e(void 0,void 0)},[e]),P=V(e=>{x(e)},[]),F=b.trim().length>0,I=U(()=>{if(!O)return[];if(w||!F)return O;let e=b.toLowerCase();return O.filter(t=>t.name.toLowerCase().includes(e))},[O,w,F,b]),L=u?Array.isArray(A)&&A.length>0:!!A;return k?t(M,{title:f(`store.collectionFetchFailed`),children:Ge(k)}):n(he,{children:[t(_e,{asChild:!0,children:n(o,{variant:`outline`,role:`combobox`,"aria-haspopup":`listbox`,className:z(`w-full justify-between min-w-0`),disabled:i,children:[t(`span`,{className:`truncate flex-1 text-start min-w-0`,children:u&&Array.isArray(A)&&A.length>0?A.length===1?A[0].name:f(`store.collectionsSelected`,{count:A.length}):!u&&A&&!Array.isArray(A)?A.name:p}),L&&!i?t(o,{variant:`unstyled`,"aria-label":`Clear selection`,className:`ms-2 shrink-0 opacity-50 hover:opacity-100 hover:text-destructive cursor-pointer`,onClick:e=>{e.stopPropagation(),N()},children:t(Kb,{className:`h-4 w-4`})}):t(Th,{className:`ms-2 h-4 w-4 shrink-0 opacity-50`})]})}),t(ge,{className:`mt-2 mb-2 w-[var(--radix-popover-trigger-width)] p-0`,align:`start`,children:n(h,{shouldFilter:!1,children:[n(`div`,{className:`flex justify-between items-center border-b px-3`,"cmdk-input-wrapper":``,children:[t(v,{placeholder:m,value:b,onValueChange:P,className:`flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50`}),S&&t(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent`})]}),t(g,{children:f(S?`store.searching`:F?`store.noCollectionsFound`:`store.noCollectionsAvailable`)}),n(_,{className:`max-h-[300px] overflow-auto`,children:[L&&!F&&t(y,{value:`__clear__`,onSelect:N,className:`text-destructive`,children:`Remove collection selection(s)`}),F&&t(y,{value:`__clear_search__`,onSelect:()=>x(``),className:`text-muted`,children:f(`store.clearSelection`)}),I.map(e=>{let i=u&&Array.isArray(r)?r.includes(e.id):r===e.id;return n(y,{value:e.id,onSelect:()=>j(e),className:`flex items-center justify-between`,children:[t(`span`,{className:`truncate`,children:e.name}),i&&t(th,{className:`ms-2 h-4 w-4 shrink-0`})]},e.id)})]})]})})]})}function B3({isOpen:e,onClose:r}){return n(se,{onClose:()=>r(),isOpen:!!e,className:`min-w-[60vw]`,children:[t(ue,{children:`Select Content`}),t(ce,{className:`pt-0 overflow-y-auto max-h-[80vh] min-h-[80vh]`,children:e&&t(Y$,{onChange:r})})]})}Q();const V3=/store:([a-f0-9]+)/;function H3({object:e}){let{client:r}=q(),{off:i,on:a,isOn:s}=Ze(),[c,l]=G(e.value==null?``:String(e.value)),[u,d]=G(void 0),f=t=>{let n=t.target.value;l(n),e.value=n},p=V(()=>{l(``),e.value=``,d(void 0)},[e]);return H(()=>{if(!c||u)return;let e=c.match(V3);e&&r.objects.retrieve(e[1]).then(e=>{d(e)}).catch(()=>{p()})},[c,r.objects.retrieve,p,u]),n(`div`,{children:[n(`div`,{className:`relative`,children:[t(`input`,{value:c,onChange:f,className:it(Me.INPUT,`pe-10 w-full`)}),u&&t(`div`,{className:`absolute inset-y-0 end-10 flex items-center justify-center `,children:t(o,{onClick:p,variant:`unstyled`,className:`hover:text-red-500 hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(Kb,{className:`size-5`})})}),t(`div`,{className:`absolute inset-y-0 end-0 flex items-center justify-center`,children:t(o,{onClick:a,variant:`unstyled`,className:`hover:bg-gray-100 dark:hover:bg-gray-600`,children:t(Th,{className:`size-5`})})}),t(B3,{value:c,isOpen:s,onClose:t=>{if(t){let n=`store:${t.id}`;l(n),d(t||void 0),e.value=n}i()}})]}),u&&t(`div`,{className:`p-1 semibold text-sm text-gray-600 dark:text-slate-300`,children:typeof u.properties?.title==`string`?u.properties.title:u.name})]})}Q();function U3({objectId:e,isOpen:r,onClose:i}){let a=$n(),{client:s,store:c}=q(),[l,u]=G(null),[d,f]=G(!1),[p,m]=G(!1),[h,g]=G(),[_,v]=G(),[y,b]=G(`preview`),{t:x}=K(),S=nt(),C=V(async e=>{m(!0);try{let t=await c.objects.getObjectText(e);g(t.text)}catch(e){console.error(`Error loading text:`,e)}finally{m(!1)}},[c.objects]),w=V(async e=>{if(e.content?.source)try{(await s.objects.getRendition(e.id,{format:hn.jpeg,generate_if_missing:!1})).status===`found`&&console.log(`Found rendition`);let t=await s.files.getDownloadUrl(e.content.source);v(t.url)}catch(e){console.error(`Error loading image:`,e)}},[s.files,s.objects]);H(()=>{e&&r?(f(!0),c.objects.retrieve(e,`+embeddings`).then(e=>{u(e),e.text?g(e.text):C(e.id);let t=e.content;t?.source&&t.type?.startsWith(`image/`)&&w(e)}).catch(e=>{console.error(`Error loading object:`,e),S({title:x(`agent.error`),description:x(`store.failedToLoadDocument`),status:`error`,duration:3e3})}).finally(()=>{f(!1)})):(u(null),g(void 0),v(void 0))},[e,r,c.objects,C,w,x,S]);let T=()=>{l&&(a(`/legal/objects/${l.id}`),i())},E=h&&(h.startsWith(`#`)||h.includes(`
1404
1404
  #`)||h.includes(`
1405
- *`)),D=l?.content?.type?.startsWith(`image/`),O=l?.content?.type===`application/pdf`;return r?n(`div`,{className:`fixed inset-y-0 end-0 w-2/5 dark:bg-slate-900 shadow-xl z-50 flex flex-col transition-transform duration-300 transform ${r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`}`,children:[n(`div`,{className:`flex items-center justify-between px-4 py-3 border-b dark:border-gray-700 bg-gradient-to-r from-indigo-50 to-gray-50 dark:from-gray-800 dark:to-gray-900`,children:[n(`div`,{className:`flex items-center`,children:[t(Kg,{className:`h-5 w-5 text-indigo-600 me-2`}),t(`h2`,{className:`text-lg font-semibold text-gray-800 dark:text-gray-200 truncate`,children:d?x(`store.loadingDocument`):l?.name||x(`store.documentPreview`)})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{variant:`ghost`,size:`sm`,onClick:T,className:`flex items-center gap-1 text-indigo-600 hover:text-indigo-800`,children:[t(uv,{className:`h-4 w-4`}),t(`span`,{children:x(`store.fullView`)})]}),t(o,{variant:`ghost`,size:`sm`,onClick:i,className:`flex items-center text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100`,children:t(Kb,{className:`h-5 w-5`})})]})]}),d?t(`div`,{className:`flex-1 flex items-center justify-center`,children:n(`div`,{className:`text-center`,children:[t(je,{size:`lg`,className:`text-indigo-600 dark:text-indigo-400 mb-2`}),t(`p`,{className:`text-gray-600 dark:text-gray-400`,children:x(`store.loadingDocument`)})]})}):n(`div`,{className:`flex-1 flex flex-col h-full`,children:[t(`div`,{className:`border-b`,children:n(`div`,{className:`flex px-4`,children:[t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`preview`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`preview`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(L_,{className:`h-4 w-4`}),t(`span`,{children:x(`store.preview`)})]})}),t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`properties`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`properties`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(j_,{className:`h-4 w-4`}),t(`span`,{children:x(`store.properties`)})]})})]})}),n(`div`,{className:`flex-1 overflow-auto p-4`,children:[y===`preview`&&n(`div`,{className:`h-full`,children:[p?t(`div`,{className:`flex items-center justify-center h-40`,children:t(je,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})}):h?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:E?t(`div`,{className:`prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-gray-800 prose-pre:my-2 prose-headings:text-indigo-700 dark:prose-invert dark:prose-headings:text-indigo-300`,children:t(Nt,{children:h})}):t(`pre`,{className:`text-wrap whitespace-pre-wrap dark:text-gray-200`,children:h})}):null,D&&t(`div`,{className:`mt-4`,children:_?t(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-md p-2 bg-white dark:bg-gray-800`,children:t(`img`,{src:_,alt:l?.name,className:`mx-auto max-h-[70vh] object-contain`})}):t(`div`,{className:`flex items-center justify-center h-40`,children:t(je,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})})}),O&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Kg,{className:`h-16 w-16 text-indigo-300 dark:text-indigo-400 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center mb-4`,children:x(`store.pdfPreviewFullView`)}),t(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:x(`store.openFullDocumentView`)})]}),!D&&!h&&!O&&!p&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Kg,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPreviewAvailable`)})]})]}),y===`properties`&&l&&n(`div`,{className:`h-full`,children:[l.properties?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:t(jt,{value:l.properties})}):n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(j_,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPropertiesAvailable`)})]}),n(`div`,{className:`mt-4`,children:[t(`h3`,{className:`text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2`,children:x(`store.documentInformation`)}),t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:n(`div`,{className:`grid grid-cols-2 gap-y-2 gap-x-4 text-sm`,children:[t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.id`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.id}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.type?.name||x(`store.unknown`)}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.content?.type||x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.size`)}),t(`div`,{className:`font-medium`,children:l.content&&`size`in l.content?H3(l.content.size):x(`store.unknown`)}),t(`div`,{className:`text-gray-500`,children:x(`store.created`)}),t(`div`,{className:`font-medium`,children:l.created_at?new Date(l.created_at).toLocaleString():x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.updated`)}),t(`div`,{className:`font-medium`,children:l.updated_at?new Date(l.updated_at).toLocaleString():x(`store.na`)})]})})]})]})]})]}),n(`div`,{className:`flex items-center justify-between p-4 border-t bg-gray-50 dark:bg-gray-800 dark:border-gray-700`,children:[t(`div`,{children:l?.content?.source&&n(o,{onClick:()=>{l?.content?.source&&s.files.getDownloadUrl(l.content.source).then(e=>{window.open(e.url,`_blank`)}).catch(e=>{console.error(`Error getting download URL:`,e),S({title:x(`agent.error`),description:x(`store.failedToDownloadFile`),status:`error`,duration:3e3})})},variant:`outline`,className:`text-indigo-600 border-indigo-300 hover:bg-indigo-50`,children:[t(Sg,{className:`h-4 w-4 me-2`}),x(`pdf.download`)]})}),n(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:[x(`store.openFullDocument`),t(uh,{className:`h-4 w-4 ms-2 cn-rtl-flip`})]})]})]}):null}function H3(e){if(e===0)return`0 Bytes`;let t=1024,n=[`Bytes`,`KB`,`MB`,`GB`,`TB`],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`}var U3;(function(e){e.CSV=`CSV`,e.JSON=`JSON`})(U3||={});function W3({isExporting:e,isOpen:r,onClose:i,allowExportAll:a=!0}){return n(se,{onClose:()=>i(void 0),isOpen:r,children:[t(ue,{children:`Export Object Properties`}),n(ce,{children:[!e&&t(G3,{onClose:i,allowExportAll:a}),e&&t(K3,{})]})]})}function G3({onClose:e,allowExportAll:r}){let{t:i}=K(),[a,s]=G(void 0),c=[`Export selected objects`,`Export all objects`],[l,u]=G(r?void 0:c[0]),d=e=>e===c[1];return n(ce,{className:`min-h-[104px] pt-0 flex flex-col gap-y-4`,children:[r&&t(`div`,{className:`h-1/3`,children:t(we,{options:c,value:l,onChange:u,placeholder:i(`store.chooseWhatToExport`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0})}),n(`div`,{className:`h-1/2 flex flex-col gap-y-8 content-between`,children:[t(we,{options:Object.values(U3),value:a,onChange:s,placeholder:i(`store.chooseAFormat`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0}),t(o,{className:`w-full`,isDisabled:!a||!l,onClick:()=>{e(a,d(l))},children:i(`store.actions.exportProperties`)})]})]})}function K3(){let{t:e}=K();return t(ce,{className:`min-h-[84px] pt-0`,children:n(`div`,{className:`h-full grid flex-col gap-y-2 content-between justify-items-center`,children:[n(`div`,{className:`text-sm flex flex-col gap-x-2`,children:[t(`p`,{children:e(`store.exportInProgress`)}),t(`p`,{className:`pt-2 grid justify-items-center`,children:e(`store.pleaseWait`)})]}),t(je,{size:`lg`})]})})}const q3=dt(void 0);function J3(){let e=_t(q3);if(!e)throw Error(`You cannot use useActionContext outside an ActionProvider`);return e}function Y3(e,t){let n=J3();return H(()=>n.registerCallback(e,t),[n,e,t]),n}function X3({action:e,objectIds:n}){let[r,i]=G(!1),a=V(()=>(n.length>0&&i(!0),Promise.resolve(!0)),[n]);return Y3(e.id,a),r&&t(ve,{children:t($3,{objectIds:n,isOpen:r,onClose:()=>{i(!1)}})})}const Z3=Xt.getFixedT(null,Yt),Q3={id:`addToCollection`,name:Z3(`store.actions.addToCollection`),description:Z3(`store.actions.addToCollectionDesc`),confirm:!1,component:X3};function $3({isOpen:e,onClose:r,objectIds:i}){let{t:a}=K();return n(se,{isOpen:e,onClose:r,className:`max-w-lg w-full min-w-0 overflow-hidden`,children:[t(ue,{className:`flex flex-col min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionTitle`)}),t(S,{className:`min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionBody`)}),t(`div`,{className:`min-w-0 max-w-full overflow-hidden`,children:t(e6,{onClose:r,objectIds:i})})]})}function e6({onClose:e,objectIds:r}){let{t:i}=K(),a=nt(),{client:s}=q(),[c,l]=G(),u=({collectionId:t})=>{!t||!r?.length||s.store.collections.addMembers(t,r).then(()=>{a({title:i(`store.actions.addToCollectionSuccess`),status:`success`,description:i(`store.actions.addToCollectionSuccessDesc`,{count:r.length}),duration:3e3}),e()}).catch(()=>{a({title:i(`store.actions.addToCollectionFailure`),status:`error`,description:i(`store.actions.addToCollectionFailureDesc`),duration:5e3})})},d=[{name:`select`,label:i(`store.actions.selectCollection`),content:n(`div`,{className:`p-4 min-w-0 max-w-full overflow-hidden`,children:[t(ee,{level:5,children:i(`store.actions.chooseExistingCollections`)}),t(ce,{className:`min-w-0 max-w-full overflow-hidden`,children:t(`div`,{className:`mb-4 min-w-0 max-w-full overflow-hidden`,children:t(L3,{onChange:(e,t)=>{typeof e==`string`||e===void 0?l(e):Array.isArray(e)&&e.length>0?l(e[0]):l(void 0)},value:c})})}),t(le,{children:t(o,{isDisabled:!c,onClick:()=>c&&u({collectionId:c}),children:i(`store.actions.addToCollectionButton`)})})]})},{name:`create`,label:i(`store.actions.createNew`),content:t(`div`,{className:`p-4`,children:t(M4,{onClose:e,onAddToCollection:e=>u({collectionId:e}),redirect:!1})})}];return n(ze,{defaultValue:`select`,tabs:d,fullWidth:!0,children:[t(Be,{}),t(Ve,{})]})}function t6({action:e,objectIds:r,children:i}){let{t:a}=K(),{store:o}=q(),s=nt(),[c,l]=G(!1),u=V(()=>(l(!0),Promise.resolve(!0)),[]);return Y3(e.id,u),n(`div`,{children:[i,t(O3,{isOpen:c,onClose:e=>{l(!1),e!==void 0&&o.runOperation({name:`change_type`,ids:r,params:{typeId:e}}).then(e=>{s({status:`success`,title:a(`store.actions.changeType`),description:`Change the type of ${r.length} objects is ${e.status===`in_progress`?`in progress`:`completed`}`,duration:2e3})}).catch(e=>{s({status:`error`,title:a(`store.actions.errorChangingType`),description:e.message,duration:5e3})})},title:`Change Content Type`,confirmLabel:`Change Type`,children:n(`p`,{className:`pt-2 text-xs`,children:[`Note: This action will raise the `,t(`code`,{children:`change_type`}),` event and will trigger the standard intake workflows which may reset the object properties.`]})})]})}const n6=Xt.getFixedT(null,Yt),r6={id:`changeType`,name:n6(`store.actions.changeContentType`),description:n6(`store.actions.changeContentTypeDesc`),confirm:!1,component:t6};function i6({action:r,callback:i,children:a}){let{t:o}=K(),[s,c]=G(!1),l=r.confirmationText||`Are you sure you want to ${r.name}?`,u=V(e=>r.confirm?(c(!0),Promise.resolve(!0)):i(e),[r.confirm,i]),d=Y3(r.id,u);return n(e,{children:[a,t(b,{onConfirm:()=>{c(!1),i({...d.params,action:r})},onCancel:()=>c(!1),title:o(`store.actions.areYouSure`),content:l,isOpen:s})]})}function a6({action:r,objectIds:i,children:a}){let{t:o}=K(),s=J3(),c=nt(),{client:l}=q(),u=E$(),d=$n(),[f,p]=G(!1),m=i?.length??0,h=s.params?.type?.name??`object`,g=V(()=>(p(!0),Promise.resolve(!0)),[]);Y3(r.id,g);let _=V(()=>(p(!1),i?.length?l.store.objects.delete(i).then(e=>{let t=e.deleted>1?`s`:``;if(c({status:`success`,title:`${e.deleted} object${t} deleted`,duration:2e3}),e.failed.length>0&&c({status:`warning`,title:`${e.failed.length} object(s) could not be deleted`,duration:3e3}),u){s.params?.selection?.removeAll();let t=JSON.parse(JSON.stringify(u.facets));i.length===t._value.total&&u.resetFacets();let n=new Set(e.failed);u.removeDeletedObjects(i.filter(e=>!n.has(e))),u.search()}else d(`/objects`)}).catch(e=>{c({status:`error`,title:o(`store.actions.errorDeletingObjects`),description:e.message,duration:5e3})}):(c({status:`error`,title:o(`store.actions.noObjectsSelected`),description:o(`store.actions.pleaseSelectObjectsToDelete`),duration:3e3}),Promise.resolve(!1))),[l.store.objects.delete,s.params?.selection?.removeAll,d,i,u,u?.facets,u?.resetFacets,u?.search,o,c]);return n(e,{children:[a,t(b,{isOpen:f,title:m===1?`Delete ${h}`:`Delete ${h}s`,content:n(`div`,{children:[n(`p`,{children:[`Delete `,m,` selected `,h,m===1?``:`s`,`? `,m===1?`This ${h}`:`These ${h}s`,` will be permanently removed.`]}),t(`p`,{children:t(`span`,{className:`text-destructive`,children:`This action cannot be undone.`})})]}),onConfirm:_,onCancel:()=>p(!1),confirmationValue:`delete`,confirmationLabel:`Type "delete" to confirm`,confirmationPlaceholder:`delete`})]})}const o6=Xt.getFixedT(null,Yt),s6={id:`delete`,name:o6(`store.actions.delete`),description:o6(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:o6(`store.actions.confirmDeleteAll`),component:a6,destructive:!0},c6={id:`deleteFromCollections`,name:o6(`store.actions.deleteObjects`),description:o6(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:o6(`store.actions.confirmDeleteSelected`),component:a6,destructive:!0};function l6({action:e,objectIds:n}){let{t:r}=K(),{store:i}=q(),a=nt(),[o,s]=G(!1),[c,l]=G(!1),u=V(()=>(s(!0),Promise.resolve(!0)),[]),d=Y3(e.id,u);return t(W3,{isExporting:c,isOpen:o,onClose:(e,t)=>{if(e&&(t||n.length>0)){l(!0);let o=d.params?.search?.query||{},c=d.params?.search?.result?.value?.objects?.map(e=>e.id)||void 0,u=async e=>i.objects.list({query:{parent:e}}).then(e=>e.map(e=>e.id)),f=async()=>t?c?o.vector?c:[]:n.length===0?[]:(await u(n[0])).concat(n):n,p=d.params?.type?.id??o.type,m=d.params?.type?.table_layout??void 0;f().then(c=>{i.objects.exportProperties({objectIds:c,type:e,query:t&&!o.vector?{...o,type:p}:{type:p},table_layout:m}).then(e=>{let i=new Blob([e.data],{type:e.type}),o=window.URL.createObjectURL(i),s=document.createElement(`a`);s.download=e.name,s.href=o,s.click(),a({status:`success`,title:r(`store.actions.exportProperties`),description:t?`Export the properties of all objects completed`:`Export the properties of ${n.length} object${n.length>1?`s`:``} is completed`,duration:2e3})}).catch(e=>{a({status:`error`,title:r(`store.actions.errorExportProperties`),description:e.message,duration:5e3})}).finally(()=>{l(!1),s(!1)})})}else s(!1),a({status:`error`,title:r(`store.actions.errorExportProperties`),description:`No objects selected for export`,duration:5e3})}})}const u6=Xt.getFixedT(null,Yt),d6={id:`exportProperties`,name:u6(`store.actions.exportProperties`),description:u6(`store.actions.exportAllObjectProperties`),confirm:!1,component:l6};function f6({action:e,objectIds:n,collectionId:r}){let{t:i}=K(),a=J3(),o=nt(),{client:s}=q(),c=E$(),l=V(()=>n?.length?r?s.store.collections.deleteMembers(r,n).then(()=>{let e=n.length>1?`s`:``;o({status:`success`,title:`${n.length} object${e} removed from collection`,description:`Objects have been removed from the collection`,duration:2e3}),c&&(a.params?.selection?.removeAll(),c.search())}).catch(e=>{o({status:`error`,title:i(`store.actions.errorRemovingObjects`),description:Ge(e),duration:5e3})}):(o({status:`error`,title:i(`store.actions.noCollectionContext`),description:i(`store.actions.cannotRemoveNoCollection`),duration:3e3}),Promise.resolve(!1)):(o({status:`error`,title:i(`store.actions.noObjectsSelected`),description:i(`store.actions.pleaseSelectObjectsToRemove`),duration:3e3}),Promise.resolve(!1)),[s.store.collections.deleteMembers,r,a.params?.selection?.removeAll,n,c,c?.search,i,o]);return t(i6,{action:e,callback:l})}const p6=Xt.getFixedT(null,Yt),m6={id:`removeFromCollection`,name:p6(`store.actions.removeFromCollection`),description:p6(`store.actions.removeFromCollectionDesc`),confirm:!0,confirmationText:p6(`store.actions.confirmRemoveFromCollection`),component:f6,destructive:!0};var h6=class{params;allActions=[];callbacks={};constructor(e){this.params=e}get actions(){return this.params.selection?.collectionId?this.allActions.filter(e=>e.id!==`addToCollection`&&e.id!==`delete`):this.allActions.filter(e=>e.id!==`removeFromCollection`&&e.id!==`deleteFromCollections`)}registerCallback(e,t){return this.callbacks[e]=t,()=>{delete this.callbacks[e]}}unregisterCallback(e){delete this.callbacks[e]}findAction(e){return this.allActions.find(t=>t.id===e)}async run(e){let t=this.findAction(e);if(!t)throw Error(`Action ${e} not found`);let n={...this.params,action:t},r=this.callbacks[e];if(r)return r(n);throw Error(`No action callback set`)}};const g6=[d6,r6,Q3,s6,m6,c6];function _6({children:e,type:r}){let i=RQ(),a=nt(),{client:o}=q(),s=E$(),c=U(()=>{let e=new h6({selection:i,toast:a,client:o,search:s,type:r});return e.allActions=g6,e},[o,s,i,a,r]);return c&&n(q3.Provider,{value:c,children:[t(v6,{}),e]})}function v6(){let e=J3(),n=e.params.selection,r=n.getObjectId(),i=n.isSingleSelection()&&r?[r]:n.getObjectIds();return t(`div`,{style:{display:`none`},children:e.allActions.map(e=>t(e.component,{action:e,objectIds:i,collectionId:n.collectionId},e.id))})}function y6(){let{t:r}=K(),i=RQ(),[a,s]=G(!1);return i?.hasSelection()?n(e,{children:[t(o,{onClick:()=>s(!0),children:r(`store.actions.startWorkflow`)}),a&&t(b6,{objectIds:i.getObjectIds(),onClose:()=>s(!1)})]}):null}function b6({objectIds:e,onClose:r}){let{t:i}=K(),{client:a}=q(),s=nt(),[c,l]=G(void 0),[u,d]=G(!1),{data:f,isLoading:p}=Ye(()=>a.store.workflows.rules.list(),[]);return n(se,{isOpen:!0,onClose:r,size:`lg`,children:[t(ue,{children:i(`store.actions.startWorkflowByRule`)}),n(ce,{children:[t(`div`,{className:`pb-2`,children:i(`store.actions.chooseWorkflowRule`)}),p?t(`div`,{className:`flex justify-center py-4`,children:t(je,{})}):t(`div`,{className:`max-h-[420px] overflow-y-auto border-border border rounded-md`,children:t(Te,{className:`text-start w-full`,options:f??[],value:c,onChange:l,optionLayout:e=>({label:e.name})})})]}),n(le,{align:`right`,children:[t(o,{variant:`outline`,onClick:r,disabled:u,children:`Cancel`}),t(o,{onClick:async()=>{if(!(!c||u)){d(!0);try{await a.store.workflows.rules.execute(c.id,e),s({title:i(`store.actions.workflowStarted`),status:`success`,duration:3e3}),r()}catch(e){s({title:i(`store.actions.errorStartingWorkflow`),description:e instanceof Error?e.message:void 0,status:`error`,duration:9e3})}finally{d(!1)}}},isDisabled:!c||u,isLoading:u,children:`Start`})]})]})}Q();function x6({type:e,allowMutations:r=!0,allowDelete:i=!0,allowWorkflowRun:a=!1}){let s=RQ(),c=s.size(),l=c>1?`s`:``,u=s?.hasSelection(),d=s?.isSingleSelection();return t(_6,{type:e,children:n(`div`,{className:`flex items-center gap-x-2`,children:[u&&!d&&n(`div`,{className:`flex items-center gap-x-1 shrink-0`,children:[n(`div`,{className:`text-sm nowrap`,children:[c,` document`,l,` selected`]}),t(o,{title:`Clear selection`,variant:`ghost`,onClick:()=>{s?.removeAll()},children:t(Kb,{className:`size-4`})})]}),a&&t(y6,{}),t(w6,{selection:s,allowMutations:r,allowDelete:i,children:e=>e.length>0?t(o,{variant:`ghost`,title:`More action`,size:`sm`,children:t(Tg,{size:16})}):null})]})})}function S6({collectionId:r,allowFolders:i=!0}){let{t:a}=K(),[s,c]=G([]),[l,u]=G(!1);return n(e,{children:[t(o,{onClick:()=>u(!0),children:a(`store.upload`)}),t(F$,{collectionId:r??``,isOpen:l,onClose:()=>{u(!1),c([])},files:s,title:`Upload Files`,onUploadComplete:e=>{e?.success&&c([])},allowFolders:i})]})}function C6(e){return{label:e.name,className:it(`flex-1 px-2 py-2 hover:bg-accent nowrap`,e.destructive?`text-destructive`:``)}}function w6({selection:e,children:r,allowMutations:i=!0,allowDelete:a=!0}){let o=J3(),s=e=>{o.run(e.id)},c=E6(o.actions,e,{allowMutations:i,allowDelete:a}),l=r(c);return l?n(he,{hover:!0,children:[t(_e,{children:l}),t(ge,{className:`p-0 w-50`,align:`end`,sideOffset:6,children:t(T6,{executeAction:s,actions:c})})]}):null}function T6({executeAction:e,actions:n}){return t(`div`,{className:`rounded-md shadow-md py-2`,children:t(`div`,{className:`px-1 text-sm`,children:t(Te,{options:n,optionLayout:C6,onChange:t=>{e(t)},noCheck:!0})})})}function E6(e,t,n){return t?.hasSelection()?e.filter(e=>e.hideInList?!1:e.id===`delete`||e.id===`deleteFromCollections`?n.allowDelete:e.id===`changeType`||e.id===`addToCollection`||e.id===`removeFromCollection`?n.allowMutations:!0):[d6]}function D6({user:e}){return n(`div`,{className:`flex items-center`,children:[t(`div`,{className:`w-9 h-9`,children:(()=>{if(e.picture)return t(`img`,{className:`inline-block h-9 w-9 rounded-full`,src:e.picture,alt:e.name});{let n=e.name.split(` `).map(e=>e[0]).join(``);return t(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-full bg-indigo-600`,children:t(`span`,{className:`text-sm font-medium leading-none text-white`,children:n})})}})()}),n(`div`,{className:`ms-3`,children:[t(`p`,{className:`text-sm font-medium text-gray-700 dark:text-slate-50 group-hover:text-gray-900`,children:e.name??`Deleted User`}),t(`p`,{className:`text-xs font-medium text-gray-500 dark:text-slate-300 group-hover:text-gray-700`,children:e.email??`Deleted User`})]})]})}Q();const O6=dt(void 0);function k6(){return _t(O6)}function A6(e,t){let n=e.requires_selection??(e.placement===`toolbar`?`none`:`any`);return n===`none`?!0:n===`single`?t.length===1:n===`multiple`?t.length>1:t.length>0}function j6(e){let t=window.URL.createObjectURL(new Blob([e.data],{type:e.type})),n=document.createElement(`a`);n.download=e.name,n.href=t,n.click(),window.setTimeout(()=>window.URL.revokeObjectURL(t),0)}function M6({children:e,definition:r,request:i,result:a,selection:o,contributions:s,client:c,canDelete:l,refresh:u}){let{t:d}=K(),f=nt(),[p,m]=G(),[h,g]=G(),[_,v]=G(!1),[y,x]=G(),S=W(!1),C=r.results?.actions,w=U(()=>({definition:r,request:i,result:a,refresh:u,clearSelection:()=>o?.clear()}),[r,u,i,a,o]),T=U(()=>{let e=(C?.items??[]).filter(e=>{let t=s?.actions?.[e.handler];return t!==void 0&&(t.isAvailable?.(w)??!0)});if(!o||C?.include_defaults===!1||!c)return e;let t=new Set(C?.exclude_defaults??[]),n=[];return t.has(`export`)||n.push({id:`export`,label:d(`store.actions.exportProperties`),handler:`export`,placement:`selection`,requires_selection:`any`}),l&&!t.has(`delete`)&&n.push({id:`delete`,label:d(`store.actions.delete`),handler:`delete`,placement:`selection`,requires_selection:`any`,destructive:!0,confirm:!0}),[...n,...e]},[C,w,l,c,s?.actions,o,d]),E=V(async({action:e,hits:t})=>{if(!S.current){S.current=!0,x(e.id);try{if(e.handler===`delete`){if(!c)return;let e=await c.store.objects.delete(t.map(e=>e.id));f({status:e.failed.length>0?`warning`:`success`,title:d(`view.deletedObjects`,{count:e.deleted})}),o?.clear(),await u();return}let n=s?.actions?.[e.handler];if(!n)return;await n.run({...w,action:e,hits:t})}catch(e){console.error(`View action failed:`,e),f({status:`error`,title:d(`view.actionFailed`),description:d(`view.actionFailedDescription`)})}finally{S.current=!1,x(void 0),m(void 0)}}},[w,c,s?.actions,u,o,d,f]),D=V((e,t)=>{if(!(!A6(e,t)||S.current)){if(e.handler===`export`){g(t);return}if(e.confirm){m({action:e,hits:t});return}E({action:e,hits:t})}},[E]),O=V(e=>{if(!e||!h?.length||!c){g(void 0);return}v(!0),c.store.objects.exportProperties({objectIds:h.map(e=>e.id),type:e}).then(e=>{j6(e),f({status:`success`,title:d(`store.actions.exportProperties`)}),g(void 0)}).catch(e=>{console.error(`View export failed:`,e),f({status:`error`,title:d(`store.actions.errorExportProperties`),description:d(`view.actionFailedDescription`)})}).finally(()=>v(!1))},[c,h,d,f]),k=U(()=>({actions:T,runningActionId:y,run:D}),[T,D,y]);return n(O6.Provider,{value:k,children:[e,t(W3,{isOpen:h!==void 0,isExporting:_,onClose:O,allowExportAll:!1}),t(b,{isOpen:p!==void 0,title:p?.action.label??d(`modal.confirm`),content:d(`view.confirmAction`,{action:p?.action.label??``,count:p?.hits.length??0}),isLoading:y!==void 0,onConfirm:()=>{p&&E(p)},onCancel:()=>m(void 0),confirmationValue:p?.action.handler===`delete`?`delete`:void 0,confirmationLabel:p?.action.handler===`delete`?d(`view.typeDeleteToConfirm`):void 0,confirmationPlaceholder:p?.action.handler===`delete`?`delete`:void 0})]})}function N6({selection:r,page:i,showSelectPage:a=!1}){let{t:s}=K(),c=k6(),l=vt();if(!c)return null;let u=r?.selectedHits??[],d=r?i.filter(e=>r.isSelected(e.id)).length:0,f=i.length>0&&d===i.length,p=a&&r?.selectAll&&i.length>0,h=c.actions.filter(e=>((e.placement??`selection`)===`toolbar`||(e.placement??`selection`)===`selection`&&u.length>0)&&A6(e,u));return h.length===0&&u.length===0&&!p?null:n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[p&&r&&n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:l,checked:f?!0:d>0&&`indeterminate`,onCheckedChange:e=>r.togglePage(i,e===!0)}),t(`label`,{htmlFor:l,className:`text-sm text-muted`,children:s(`view.selectPage`)})]}),u.length>0&&n(e,{children:[t(`span`,{className:`text-sm text-muted`,children:s(`view.selectedCount`,{count:u.length})}),t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":s(`view.clearSelection`),onClick:r?.clear,children:t(Kb,{className:`size-4`})})]}),h.map(e=>n(o,{type:`button`,variant:e.destructive?`destructive`:`outline`,size:`sm`,disabled:c.runningActionId!==void 0,onClick:()=>c.run(e,u),children:[e.handler===`export`&&t(Sg,{className:`size-4`}),e.handler===`delete`&&t(gb,{className:`size-4`}),e.label]},e.id))]})}function P6({hit:e}){let{t:r}=K(),i=k6(),a=i?.actions.filter(t=>(t.placement??`selection`)===`row`&&A6(t,[e]));return!i||!a?.length?null:n(he,{children:[t(_e,{children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":r(`view.actions`),children:t(Tg,{className:`size-4`})})}),t(ge,{className:`w-52 p-1`,align:`end`,sideOffset:6,children:t(Te,{options:a,optionLayout:e=>({label:e.label,className:e.destructive?`text-destructive`:void 0}),onChange:t=>i.run(t,[e]),noCheck:!0})})]})}function F6(e){return e.dataTransfer.items?Array.from(e.dataTransfer.items).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e!==null):Array.from(e.dataTransfer.files)}function I6({children:r,definition:i,request:a,result:o,contribution:s,canWrite:c,refresh:l}){let{t:u}=K(),d=nt(),f=i.results?.drop,p=f?.handler===`upload`&&c,m=s!==void 0||p,[h,g]=G(!1),[_,v]=G(!1),[y,b]=G([]),x=W(!1),S=V(async e=>{if(e.length){if(s){if(x.current)return;x.current=!0,v(!0);try{await s.run({configuration:f,files:e,definition:i,request:a,result:o,refresh:l})}catch(e){console.error(`View drop action failed:`,e),d({status:`error`,title:u(`view.dropFailed`),description:u(`view.actionFailedDescription`)})}finally{x.current=!1,v(!1)}return}p&&b(e)}},[p,f,s,i,l,a,o,u,d]);if(!m)return r;let C=f?.params;return n(e,{children:[n(`div`,{className:`relative min-h-48`,onDragEnter:e=>{e.preventDefault(),g(!0)},onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:e=>{e.preventDefault(),e.currentTarget.contains(e.relatedTarget)||g(!1)},onDrop:e=>{e.preventDefault(),e.stopPropagation(),g(!1),!e.target.closest(`[data-view-drop-zone]`)&&S(F6(e))},children:[r,_&&t(`div`,{className:`absolute inset-0 z-40 flex items-center justify-center bg-background/80`,children:t(je,{size:`xl`})}),t(`div`,{"data-view-drop-zone":!0,className:`pointer-events-none absolute inset-0 ${h?`z-50`:`-z-10`}`,children:t(Ot,{onDrop:e=>void S(e),message:u(`view.dropFiles`),buttonLabel:u(`view.selectFiles`),allowFolders:C?.allow_folders??!0,className:`pointer-events-auto absolute inset-0 bg-background/90 ${h?`flex`:`hidden`}`})})]}),p&&t(F$,{isOpen:y.length>0,onClose:()=>b([]),files:y,collectionId:C?.collection_id,selectedFolder:C?.location,initialTypeId:C?.type_id,defaultProperties:C?.properties,allowFolders:C?.allow_folders??!0,title:u(`view.uploadToView`),onUploadComplete:e=>{e.success&&l()}})]})}Q();function L6(e,t,n,r){return n?r===!1?[t]:e.includes(t)?e:[...e,t]:e.filter(e=>e!==t)}function R6({node:e}){return n(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-2`,children:[t(`span`,{className:`truncate`,children:e.label}),t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]})}function z6({configuration:e,result:r,isLoading:i,onChange:a,onQueryChange:s}){let{t:c}=K(),l=vt(),u=e.presentation??(e.source===`location`||e.source===`hierarchy`?`tree`:`list`),d=e.source!==`hierarchy`&&e.multi_select,f=r.breadcrumbs??[],[p,h]=G(r.query??``);H(()=>{h(r.query??``)},[r.query]);let g=(e,t)=>{a(L6(r.selected,e,t,d))};return n(`section`,{className:`space-y-2`,"aria-labelledby":`${l}-label`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h2`,{id:`${l}-label`,className:`text-sm font-semibold`,children:e.label}),r.selected.length>0&&n(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([]),"aria-label":`${c(`filter.clearAll`)}: ${e.label}`,children:[t(Kb,{className:`size-3.5`}),c(`filter.clearAll`)]})]}),e.source===`collection`&&s&&n(`form`,{className:`flex items-center gap-1`,onSubmit:e=>{e.preventDefault(),s?.(p.trim())},children:[t(te,{value:p,onChange:h,disabled:i,placeholder:c(`view.filterNavigation`,{label:e.label}),"aria-label":c(`view.filterNavigation`,{label:e.label})}),t(o,{type:`submit`,variant:`outline`,size:`icon`,disabled:i,"aria-label":c(`view.searchNavigation`,{label:e.label}),children:t(jy,{"aria-hidden":`true`,className:`size-4`})})]}),f.length>0&&t(`nav`,{"aria-label":`${e.label} path`,children:t(`ol`,{className:`flex flex-wrap items-center gap-1 text-sm`,children:f.map((e,r)=>n(`li`,{className:`flex items-center gap-1`,children:[r>0&&t(uh,{"aria-hidden":`true`,className:`size-3.5 text-muted`}),t(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([e.id]),"aria-current":r===f.length-1?`page`:void 0,children:e.label})]},e.id))})}),r.selected.length>0&&f.length===0&&(e.source===`location`||e.source===`collection`)&&t(`div`,{className:`flex flex-wrap gap-1`,children:r.selected.map(e=>{let a=r.nodes.find(t=>t.id===e)?.label??e;return n(o,{type:`button`,variant:`secondary`,size:`sm`,disabled:i,onClick:()=>g(e,!1),"aria-label":c(`view.removeSelection`,{value:a}),children:[a,t(Kb,{"aria-hidden":`true`,className:`size-3.5`})]},e)})}),u===`select`&&d===!1?t(we,{options:r.nodes,value:r.nodes.find(e=>r.selected.includes(e.id)),onChange:e=>a([e.id]),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):u===`select`?t(we,{multiple:!0,options:r.nodes,value:r.nodes.filter(e=>r.selected.includes(e.id)),onChange:e=>a(e.map(e=>e.id)),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):u===`chips`?t(`div`,{className:`flex flex-wrap gap-2`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`outline`,size:`sm`,disabled:i,onClick:()=>g(e.id,!r.selected.includes(e.id)),children:[e.label,t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]},e.id))}):e.source===`hierarchy`?t(`div`,{className:`space-y-1`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`ghost`,className:`w-full justify-start`,disabled:i,onClick:()=>a([e.id]),children:[t(R6,{node:e}),e.expandable&&t(uh,{"aria-hidden":`true`,className:`size-4 shrink-0 text-muted`})]},e.id))}):t(`div`,{className:`space-y-1`,children:r.nodes.map((e,a)=>{let o=`${l}-${a}`;return n(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted`,children:[t(m,{id:o,checked:r.selected.includes(e.id),disabled:i,onCheckedChange:t=>g(e.id,t===!0)}),t(`label`,{htmlFor:o,className:`flex min-w-0 flex-1 cursor-pointer text-sm`,children:t(R6,{node:e})})]},e.id)})}),r.nodes.length===0&&t(`p`,{className:`text-sm text-muted`,children:c(`filter.noAvailableFilters`)})]})}const B6=`display`,V6=`sort`,H6=`offset`;function U6(e){if(e===null||e.trim()===``)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0}function W6(e,t){let n={};for(let r of new Set(e.keys())){if(!r.startsWith(t)||r.length===t.length)continue;let i=e.getAll(r).filter(e=>e!==``);i.length>0&&(n[r.slice(t.length)]=i)}return Object.keys(n).length>0?n:void 0}function G6(e,t){let n={};for(let r of new Set(e.keys())){if(!r.startsWith(t)||r.length===t.length)continue;let i=e.get(r)?.trim();i&&(n[r.slice(t.length)]=i)}return Object.keys(n).length>0?n:void 0}function K6(e){let t=new URLSearchParams(e.startsWith(`?`)?e.slice(1):e),n=t.get(`q`)?.trim(),r=t.get(B6)?.trim(),i=t.get(V6)?.trim(),a=U6(t.get(H6)),o=W6(t,`t.`),s=W6(t,`n.`),c=G6(t,`nq.`);return{...n?{query:n}:{},...o?{key_terms:o}:{},...s?{navigation:s}:{},...c?{navigation_queries:c}:{},...r?{display:r}:{},...i?{sort:i}:{},...a?{offset:a}:{}}}function q6(e){for(let t of[...e.keys()])(t===`q`||t===B6||t===V6||t===H6||t.startsWith(`t.`)||t.startsWith(`nq.`)||t.startsWith(`n.`))&&e.delete(t)}function J6(e,t,n){if(n)for(let[r,i]of Object.entries(n).sort(([e],[t])=>e.localeCompare(t)))for(let n of i)n!==``&&e.append(`${t}${r}`,n)}function Y6(e,t,n){if(n)for(let[r,i]of Object.entries(n).sort(([e],[t])=>e.localeCompare(t)))i.trim()&&e.set(`${t}${r}`,i.trim())}function X6(e,t=``){let n=new URLSearchParams(t.startsWith(`?`)?t.slice(1):t);q6(n),e.query?.trim()&&n.set(`q`,e.query.trim()),e.display&&n.set(B6,e.display),e.sort&&n.set(V6,e.sort),e.offset&&e.offset>0&&n.set(H6,String(e.offset)),J6(n,`t.`,e.key_terms),J6(n,`n.`,e.navigation),Y6(n,`nq.`,e.navigation_queries);let r=n.toString();return r?`?${r}`:``}function Z6(e){let t=Object.fromEntries(Object.entries(e.navigation).filter(([,e])=>e.selected.length>0).map(([e,t])=>[e,t.selected]));return Object.keys(t).length>0?t:void 0}function Q6(e){let t={};for(let[n,r]of Object.entries(e.navigation))r.query&&(t[n]=r.query);return Object.keys(t).length>0?t:void 0}function $6(e,t){let n=new Set(t.definition.search?.key_terms?.map(e=>e.id)??[]),r=e.key_terms?Object.fromEntries(Object.entries(e.key_terms).filter(([e,t])=>n.has(e)&&t.length)):void 0,i=Z6(t),a=Q6(t);return{...e.query?.trim()?{query:e.query.trim()}:{},...r&&Object.keys(r).length>0?{key_terms:r}:{},...i?{navigation:i}:{},...a?{navigation_queries:a}:{},...t.display?{display:t.display}:{},...t.sort?{sort:t.sort}:{},...e.offset&&e.offset>0?{offset:e.offset}:{},...e.limit?{limit:e.limit}:{}}}function e8(e,t,n){return t.sort??e.sort??(e.query?.trim()?void 0:n)}function t8(e){if(typeof window>`u`)return;let t=X6(e,window.location.search);window.history.replaceState(window.history.state||{},``,`${window.location.pathname}${t}`)}Q();function n8(e,t){return!t||t===`.`?e:t.split(`.`).reduce((e,t)=>{if(!(!e||typeof e!=`object`||Array.isArray(e)))return e[t]},e)}function r8(e,t){return t===`score`?e.score:t.startsWith(`annotation.`)?n8(e.annotation,t.slice(11)):t.startsWith(`document.`)?n8(e.document,t.slice(9)):n8(e.document,t)}const i8=dt(void 0);function a8(e){if(e!=null&&e!==``)return Array.isArray(e)?e.map(a8).filter(Boolean).join(`, `):typeof e==`object`?JSON.stringify(e):String(e)}function o8(e,t,n){let r=r8(e,t.field),i=t.fallback??``;if(r==null||r===``)return i;if(t.format===`date`){let e=String(r),t=/^\d{4}-\d{2}-\d{2}$/.test(e),a=new Date(e);if(Number.isNaN(a.getTime()))return a8(r)??i;let o={year:`numeric`,month:`numeric`,day:`numeric`,...t?{timeZone:`UTC`}:{}};return n?.formatDate(a,o)??new Intl.DateTimeFormat(void 0,o).format(a)}if(t.format===`number`){let e=typeof r==`number`?r:Number(r);return Number.isFinite(e)?n?.formatNumber(e)??new Intl.NumberFormat().format(e):a8(r)??i}return a8(r)??i}function s8({hit:e,field:n,className:r}){let a=o8(e,n,_t(i8));return a?n.format===`badge`||n.format===`content_type`?t(i,{className:r,children:a}):t(`span`,{className:r,children:a}):null}function c8({hit:e,onOpenHit:r,compact:i=!1}){let{t:a}=K();return r?i?t(We,{description:a(`agent.openDocument`),asChild:!0,children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`agent.openDocument`),onClick:()=>r(e),children:t(Og,{className:`size-4`})})}):n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(e),children:[t(Og,{className:`size-4`}),a(`agent.openDocument`)]}):null}function l8(e,t){if(t.source!==`property`||!t.field)return;let n=a8(r8(e,t.field));if(n)try{let e=new URL(n,typeof window>`u`?`https://localhost`:window.location.origin);return e.protocol===`http:`||e.protocol===`https:`?e.toString():void 0}catch{return}}const u8=new WeakMap,d8=[2e3,4e3,8e3];function f8(e){let t=u8.get(e);if(t)return t;let n=new Map;return u8.set(e,n),n}function p8(e,t,n){let r=f8(e),i=r.get(t);if(i)return i;let a=n().finally(()=>{r.delete(t)});return r.set(t,a),a}function m8({hit:e,media:n,resolveMedia:r,className:i}){let a=n?l8(e,n):void 0,[o,s]=G(),[c,l]=G(!1),u=!a&&n?`${e.id}|${JSON.stringify(n)}`:void 0,d=W(e),f=W(n);d.current=e,f.current=n,H(()=>{if(s(void 0),l(!1),!u||!r)return;let e=!0,t,n=i=>{p8(r,u,async()=>r(d.current,f.current)).then(r=>{if(!e)return;if(r){s(r);return}let a=d8[i];a!==void 0&&(t=setTimeout(()=>n(i+1),a))}).catch(()=>{e&&l(!0)})};return n(0),()=>{e=!1,t&&clearTimeout(t)}},[u,r,a]);let p=c?void 0:a??o,m=n?.fit===`contain`?`object-contain`:`object-cover`;if(p)return t(`img`,{src:p,alt:``,className:`${m} ${i??``}`,onError:()=>l(!0)});let h=n?.source===`type_icon`?`type_icon`:n?.fallback??`type_icon`;return h===`none`?null:t(`div`,{className:`flex items-center justify-center bg-muted ${i??``}`,"aria-hidden":`true`,children:t(h===`placeholder`?O_:Kg,{className:`size-10 text-muted-foreground`})})}function h8({hit:e}){let n=e.annotation?.why_match??e.annotation?.answer??e.annotation?.excerpt;return n?t(`p`,{className:`text-sm text-info`,children:n}):null}function g8({hit:e,page:n,selection:r}){let{t:i}=K(),a=W(!1);return r?t(m,{checked:r.isSelected(e.id),"aria-label":i(`view.selectResult`,{name:e.document.name}),onClick:e=>{a.current=e.shiftKey,e.stopPropagation()},onCheckedChange:t=>{r.toggle(e,t===!0,{page:n,range:r.mode===`multiple`&&a.current}),a.current=!1}}):null}function _8({hit:e,fields:n}){return n?.length?t(`div`,{className:`flex flex-wrap gap-1`,children:n.map(n=>t(s8,{hit:e,field:n},`${n.field}-${n.label??``}`))}):null}function v8({hit:e,fields:r}){let i=_t(i8);return r?.length?t(`dl`,{className:`space-y-1 text-sm`,children:r.map(r=>{let a=o8(e,r,i);return a?n(`div`,{className:`flex gap-2`,children:[r.label&&t(`dt`,{className:`shrink-0 text-muted`,children:r.label}),t(`dd`,{className:`min-w-0 truncate`,children:a})]},`${r.field}-${r.label??``}`):null})}):null}function y8({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`divide-y divide-border rounded-md border`,children:r.map(s=>n(`article`,{className:`flex gap-4 p-4 ${o?.isSelected(s.id)?`bg-muted/40`:``}`,children:[o&&t(`div`,{className:`pt-1`,children:t(g8,{hit:s,page:r,selection:o})}),e.media&&t(m8,{hit:s,media:e.media,resolveMedia:a,className:`size-20 shrink-0 rounded-md`}),n(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[n(`div`,{children:[t(`h3`,{className:`font-semibold`,children:t(s8,{hit:s,field:e.title})}),e.subtitle&&t(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm text-muted`,children:e.subtitle.map(e=>t(s8,{hit:s,field:e},e.field))})]}),e.description&&t(`p`,{className:`line-clamp-3 text-sm text-muted-foreground`,children:t(s8,{hit:s,field:e.description})}),t(_8,{hit:s,fields:e.badges}),t(h8,{hit:s})]}),n(`div`,{className:`shrink-0 self-center`,children:[t(c8,{hit:s,onOpenHit:i,compact:!0}),t(P6,{hit:s})]})]},s.id))})}function b8({display:e,hits:r,isLoading:i,onOpenHit:a,sortOptions:o,currentSort:s,onSortChange:c,selection:l}){let{t:u}=K(),d=k6()?.actions.some(e=>e.placement===`row`)??!1,f=l?r.filter(e=>l.isSelected(e.id)).length:0,p=r.length>0&&f===r.length;return t(`div`,{className:`overflow-x-auto rounded-md border`,children:n(Le,{className:`w-full`,children:[t(Fe,{children:n(`tr`,{children:[l&&t(Re,{className:`w-0`,children:l.selectAll&&t(m,{checked:p?!0:f>0&&`indeterminate`,"aria-label":u(`view.selectPage`),onCheckedChange:e=>l.togglePage(r,e===!0)})}),e.columns.map(e=>{let n=e.sort_option?o?.find(t=>t.id===e.sort_option):void 0;if(!e.sortable||!n)return t(Re,{children:e.label??e.field},`${e.field}-${e.label??``}`);let r=s===n.id?n.sort[0]?.order===`desc`?`descending`:`ascending`:`none`;return t(Ae,{sortDirection:r,onSort:()=>c?.(n.id),disabled:i||!c,sortIndicator:e=>e===`ascending`?t(ph,{className:`size-3`,"aria-hidden":`true`}):e===`descending`?t(ih,{className:`size-3`,"aria-hidden":`true`}):t(Th,{className:`size-3 text-muted`,"aria-hidden":`true`}),children:e.label??e.field},`${e.field}-${e.label??``}`)}),(a||d)&&t(Re,{className:`w-0`,children:t(`span`,{className:`sr-only`,children:u(d?`view.actions`:`agent.openDocument`)})})]})}),t(Pe,{isLoading:i&&r.length===0,columns:e.columns.length+ +!!l+(a||d?1:0),children:r.map(i=>n(`tr`,{className:l?.isSelected(i.id)?`bg-muted/40`:void 0,children:[l&&t(`td`,{className:`w-0`,children:t(g8,{hit:i,page:r,selection:l})}),e.columns.map(e=>t(`td`,{style:e.width?{width:e.width}:void 0,children:t(s8,{hit:i,field:e})},`${i.id}-${e.field}`)),(a||d)&&t(`td`,{className:`w-0 whitespace-nowrap text-end`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(c8,{hit:i,onOpenHit:a,compact:!0}),t(P6,{hit:i})]})})]},i.id))})]})})}const x8={2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`md:grid-cols-2 xl:grid-cols-4`,5:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-5`,6:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-6`};function S8({hit:e,configuration:r,onOpenHit:i,resolveMedia:a,selection:o,page:p}){let m=k6()?.actions.some(e=>e.placement===`row`)??!1;return n(s,{className:`relative flex h-full min-w-0 flex-col overflow-hidden ${o?.isSelected(e.id)?`ring-2 ring-primary`:``}`,children:[o&&t(`div`,{className:`absolute start-2 top-2 z-10 rounded bg-background/80 p-1`,children:t(g8,{hit:e,page:p,selection:o})}),r.media&&t(m8,{hit:e,media:r.media,resolveMedia:a,className:`h-40 w-full border-b`}),n(d,{className:`gap-2 p-4`,children:[t(_8,{hit:e,fields:r.badges}),t(f,{className:`truncate text-base`,children:t(s8,{hit:e,field:r.title})}),r.description&&t(l,{className:`line-clamp-3`,children:t(s8,{hit:e,field:r.description})})]}),n(c,{className:`flex-1 p-4 pt-0`,children:[t(v8,{hit:e,fields:r.fields}),t(h8,{hit:e})]}),(i||m)&&n(u,{className:`justify-end p-4 pt-0`,children:[t(c8,{hit:e,onOpenHit:i}),t(P6,{hit:e})]})]})}function C8({display:e,hits:n,onOpenHit:r,resolveMedia:i,selection:a}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${x8[e.columns??3]}`,children:n.map(o=>t(S8,{hit:o,configuration:e,onOpenHit:r,resolveMedia:i,selection:a,page:n},o.id))})}function w8({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${x8[e.columns??4]}`,children:r.map(l=>n(s,{className:`relative overflow-hidden ${o?.isSelected(l.id)?`ring-2 ring-primary`:``}`,children:[o&&t(`div`,{className:`absolute start-2 top-2 z-10 rounded bg-background/80 p-1`,children:t(g8,{hit:l,page:r,selection:o})}),t(m8,{hit:l,media:e.media,resolveMedia:a,className:`aspect-square w-full border-b`}),n(c,{className:`space-y-2 p-3`,children:[t(`h3`,{className:`truncate font-semibold`,children:t(s8,{hit:l,field:e.title})}),e.caption&&t(`div`,{className:`space-y-1 text-sm text-muted`,children:e.caption.map(e=>t(`div`,{className:`truncate`,children:t(s8,{hit:l,field:e})},e.field))}),n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(c8,{hit:l,onOpenHit:i}),t(P6,{hit:l})]})]})]},l.id))})}function T8({display:e,hits:r,onOpenHit:a,resolveMedia:o,selection:s}){let c=new Map;for(let t of r){let n=a8(r8(t,e.group_by))??``;c.set(n,[...c.get(n)??[],t])}let l=e.columns?.length?[...e.columns].sort((e,t)=>(e.order??0)-(t.order??0)):[...c.keys()].sort().map(e=>({value:e,label:e||`—`}));return t(`div`,{className:`flex min-w-max gap-4 overflow-x-auto pb-2`,children:l.map(l=>{let u=c.get(l.value)??[];return n(`section`,{className:`w-80 shrink-0 space-y-3 rounded-lg bg-muted/40 p-3`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h3`,{className:`font-semibold`,children:l.label}),t(i,{children:u.length})]}),t(`div`,{className:`space-y-3`,children:u.map(n=>t(S8,{hit:n,configuration:e.card,onOpenHit:a,resolveMedia:o,selection:s,page:r},n.id))})]},l.value)})})}function E8(e,n,r,i,a,o,s,c,l){return e.type===`table`?t(b8,{display:e,hits:n,isLoading:r,onOpenHit:i,sortOptions:o,currentSort:s,onSortChange:c,selection:l}):e.type===`cards`?t(C8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`gallery`?t(w8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`board`?t(T8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):t(y8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l})}function D8({configuration:e,definition:n,request:r,result:i,isLoading:a,onSortChange:o,onOpenHit:s,resolveMedia:c,selection:l}){let{t:u}=K(),d=Zt();return!a&&i.hits.length===0?t(`p`,{className:`py-12 text-center text-sm text-muted`,children:u(`filter.noResultsFound`)}):t(i8.Provider,{value:d,children:E8(e,i.hits,a,s,c,n.results?.sort_options,e8(r,i,n.results?.default_sort),o,l)})}Q();function O8(e,t){return t?`text`:e===`number`?`number`:e===`date`?`date`:`text`}function k8(e){let[t=``,n=``]=(e[0]??``).split(`..`,2);return[t,n]}function A8(e,t){return e||t?[`${e}..${t}`]:[]}function j8(e,t){return t?e.join(`, `):e[0]??``}function M8(e,t){return t?e.split(`,`).map(e=>e.trim()).filter(Boolean):e.trim()?[e.trim()]:[]}function N8({term:e,values:n,isLoading:r,onChange:i}){let a=W(!1),o=W(void 0),[s,c]=G(()=>j8(n,e.multiple)),l=j8(n,e.multiple);return H(()=>{a.current&&o.current===l||c(l),o.current=void 0},[l]),t(L,{label:e.label,children:t(te,{type:O8(e.type,e.multiple),name:`view-key-term-${e.id}`,autoComplete:`off`,value:s,onFocus:()=>{a.current=!0},onBlur:()=>{a.current=!1;let t=M8(s,e.multiple);c(j8(t,e.multiple))},onChange:t=>{c(t);let n=M8(t,e.multiple);o.current=j8(n,e.multiple),i(n)},placeholder:e.label,disabled:r})})}function P8({configuration:e,query:r,keyTerms:i,isLoading:a,onQueryChange:s,onKeyTermsChange:c,onSubmit:l}){let{t:u}=K(),d=vt(),f=e.key_terms?.filter(e=>e.operator!==`range`)??[],p=e.key_terms?.filter(e=>e.operator===`range`)??[];return n(`form`,{className:`flex flex-col gap-3`,"aria-label":u(`layout.search`),autoComplete:`off`,onSubmit:e=>{e.preventDefault(),l()},children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`label`,{htmlFor:d,className:`sr-only`,children:u(`layout.search`)}),t(te,{id:d,name:`view-query`,autoComplete:`off`,value:r,onChange:s,placeholder:e.placeholder??u(`store.searchPlaceholder`),disabled:a}),n(o,{type:`submit`,disabled:a,className:`shrink-0`,children:[t(jy,{className:`size-4`}),u(a?`store.searching`:`store.search`)]})]}),e.key_terms&&e.key_terms.length>0&&n(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[f.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${p.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.searchFields`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2 ${p.length===0?`lg:grid-cols-4`:``}`,children:f.map(e=>t(N8,{term:e,values:i[e.id]??[],isLoading:a,onChange:t=>c(e.id,t)},e.id))})]}),p.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${f.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.ranges`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:p.map(e=>{let[r,o]=k8(i[e.id]??[]),s=e.type===`number`?`number`:e.type===`date`?`date`:`text`;return n(`fieldset`,{className:`min-w-0`,children:[t(`legend`,{className:`mb-1 text-sm font-medium`,children:e.label}),n(`div`,{className:`grid grid-cols-2 gap-2`,children:[t(te,{type:s,name:`view-key-term-${e.id}-from`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.from`)}`,value:r,onChange:t=>c(e.id,A8(t.trim(),o)),placeholder:u(`view.from`),disabled:a}),t(te,{type:s,name:`view-key-term-${e.id}-to`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.to`)}`,value:o,onChange:t=>c(e.id,A8(r,t.trim())),placeholder:u(`view.to`),disabled:a})]})]},e.id)})})]})]})]})}Q();const F8={id:`default`,label:`Results`,type:`list`,title:{field:`name`},subtitle:[{field:`type.name`,format:`content_type`},{field:`location`,format:`location`}],description:{field:`description`}};function I8(e){return!e||typeof window>`u`?{}:K6(window.location.search)}function L8(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function R8(e){let t=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.trim()]).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function z8(e){let{client:n}=q(),r=_t(K0),i=V(t=>n.views.execute(e.viewId,t),[n,e.viewId]),a=V(async(e,t)=>{if(t.source!==`content_thumbnail`)return;let r=e.document.content;try{let t=await n.objects.getRenditionSafe(e.id,r?.type,{format:hn.jpeg,max_hw:512,generate_if_missing:!1,sign_url:!0});if(t?.status===`found`&&t.renditions?.length)return t.renditions[0]}catch{}if(r?.source&&r.type?.startsWith(`image/`))return(await n.files.getDownloadUrl(r.source)).url},[n]),o=e=>r!==void 0&&e.some(e=>r.hasPermission(e));return t(V8,{...e,execute:i,resolveMedia:e.resolveMedia??a,client:n,canDelete:o([bn.content_delete,bn.content_admin,bn.content_superadmin]),canWrite:o([bn.content_write,bn.content_admin,bn.content_superadmin])})}function B8({execute:e,...n}){return e?t(V8,{...n,execute:e},n.viewId):t(z8,{...n},n.viewId)}function V8({execute:e,renderers:r,contributions:i,onOpenHit:a,resolveMedia:s,syncUrl:c=!0,showHeader:l=!0,className:u,client:d,canDelete:f=!1,canWrite:p=!1}){let{t:m}=K(),h=W(e);h.current=e;let g=W(0),[_,v]=G(()=>I8(c)),[y,b]=G(_.query??``),[x,S]=G(_.key_terms??{}),[C,w]=G(),[T,E]=G(!0),[D,O]=G(),[k,A]=G({}),j=W(void 0),N=V(()=>{j.current=void 0,A({})},[]),P=V((e,t,n=!1)=>{let r=++g.current;return n||N(),v(e),t&&c&&t8(e),E(!0),O(void 0),h.current(e).then(t=>{if(r===g.current){let n=$6(e,t);v(n),c&&t8(n),w(t)}}).catch(e=>{r===g.current&&O(e instanceof Error?e:Error(String(e)))}).finally(()=>{r===g.current&&E(!1)})},[N,c]),F=V(()=>{let e=I8(c);return b(e.query??``),S(e.key_terms??{}),P(e,!1)},[P,c]);H(()=>(F(),()=>{g.current+=1}),[F]),H(()=>{if(!c||typeof window>`u`)return;let e=()=>void F();return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[F,c]);let I=C?.definition,L=U(()=>[...I?.navigation??[]].sort((e,t)=>(e.order??0)-(t.order??0)),[I?.navigation]),ee=I?.results,R=ee?.selection,te=C?.display??_.display??ee?.default_display,ne=ee?.displays.find(e=>e.id===te)??F8,re=C?e8(_,C,ee?.default_sort):_.sort,ie=e=>{P(e,!0)},ae=(e,t)=>{let n=L8({..._.navigation??{},[e.id]:t});ie({..._,navigation:n,offset:void 0})},se=(e,t)=>{let n=R8({..._.navigation_queries??{},[e.id]:t});ie({..._,navigation_queries:n,offset:void 0})},ce=()=>{ie({..._,query:y.trim()||void 0,key_terms:L8(x),offset:void 0})},le=U(()=>{if(!R)return;let e=Object.keys(k);return{mode:R.mode,selectAll:R.mode===`multiple`&&R.select_all===`page`,selectedIds:e,selectedHits:e.map(e=>k[e]).filter(e=>e!==void 0),isSelected:e=>k[e]!==void 0,toggle:(e,t,n)=>{A(r=>{if(!t){let t={...r};return delete t[e.id],t}if(R.mode===`single`)return j.current=e.id,{[e.id]:e};let i={...r,[e.id]:e};if(n?.range&&n.page&&j.current){let t=n.page.findIndex(e=>e.id===j.current),r=n.page.findIndex(t=>t.id===e.id);if(t>=0&&r>=0){let e=Math.min(t,r),a=Math.max(t,r);for(let t of n.page.slice(e,a+1))i[t.id]=t}}return j.current=e.id,i})},togglePage:(e,t)=>{R.mode===`multiple`&&A(n=>{let r={...n};for(let n of e)t?r[n.id]=n:delete r[n.id];return r})},clear:N}},[N,k,R]);if(!C&&T)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center`,children:t(je,{size:`xl`})});if(!C||!I)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center p-4`,children:t(M,{title:m(`store.searchFailed`),action:()=>void F(),actionLabel:m(`agent.retry`),children:m(`store.searchFailed`)})});let ue=I.search?.renderer?r?.search?.[I.search.renderer]??P8:P8,de=ne.renderer?r?.results?.[ne.renderer]??D8:D8,fe=L.length>0&&I.layout?.navigation_position!==`top`,pe=I.layout?.mode===`worklist`,me=_.offset??0,he=_.limit??ne.page_size??20,ge=me>0,_e=me+C.hits.length<C.total,ve=L.map(e=>{let n=C.navigation[e.id]??{id:e.id,selected:[],nodes:[]},i=e.renderer?r?.navigation?.[e.renderer]??z6:z6;return t(i,{configuration:e,result:n,isLoading:T,onChange:t=>ae(e,t),onQueryChange:e.source===`collection`?t=>se(e,t):void 0},e.id)}),ye=()=>P(_,!1,!0),be=n(ar,{className:u,children:[l&&t(Z1,{title:I.name,description:I.description}),n(ar.Fixed,{heightClass:`h-auto`,className:`space-y-3 border-b p-3`,children:[I.search&&t(ue,{configuration:I.search,query:y,keyTerms:x,isLoading:T,onQueryChange:b,onKeyTermsChange:(e,t)=>S(n=>({...n,[e]:t})),onSubmit:ce}),L.length>0&&I.layout?.navigation_position===`top`&&t(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:ve})]}),t(ar.Body,{className:`p-0`,children:n(`div`,{className:fe?pe?`grid min-h-full lg:grid-cols-[minmax(0,1fr)_18rem]`:`grid min-h-full lg:grid-cols-[18rem_minmax(0,1fr)]`:`min-h-full`,children:[fe&&t(`aside`,{className:pe?`space-y-5 border-b p-4 lg:order-2 lg:border-s lg:border-b-0`:`space-y-5 border-b p-4 lg:border-e lg:border-b-0`,children:ve}),n(`main`,{className:`min-w-0 space-y-4 p-4 ${pe?`lg:order-1`:``}`,children:[D&&t(M,{title:m(`store.searchFailed`),action:()=>void P(_,!1),actionLabel:m(`agent.retry`),children:m(`store.searchFailed`)}),C.search.warnings.length>0&&t(oe,{status:`warning`,title:m(`view.warning`),children:t(`ul`,{className:`list-disc space-y-1 ps-4`,children:C.search.warnings.map(e=>t(`li`,{children:e.message},`${e.code}-${e.path??``}`))})}),n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2 text-sm text-muted`,children:[t(`span`,{children:m(`view.resultsCount`,{count:C.total})}),T&&t(je,{size:`sm`})]}),n(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(N6,{selection:le,page:C.hits,showSelectPage:ne.type!==`table`}),ee?.allow_display_switch&&ee.displays.length>1&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:m(`view.display`)}),t(we,{options:ee.displays,value:ne,onChange:e=>void P({..._,display:e.id,offset:void 0},!0,!0),optionLabel:e=>e.label,by:`id`,disabled:T,"aria-label":m(`view.display`),className:`min-w-36`})]}),ee?.sort_options&&ee.sort_options.length>0&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:m(`view.sort`)}),t(we,{options:ee.sort_options,value:ee.sort_options.find(e=>e.id===re),onChange:e=>void P({..._,sort:e.id,offset:void 0},!0,!0),optionLabel:e=>e.label,by:`id`,disabled:T,"aria-label":m(`view.sort`),className:`min-w-44`})]})]})]}),t(I6,{definition:I,request:_,result:C,contribution:i?.drop,canWrite:p,refresh:ye,children:t(de,{configuration:ne,definition:I,request:_,result:C,isLoading:T,onSortChange:e=>void P({..._,sort:e,offset:void 0},!0,!0),onOpenHit:a,resolveMedia:s,selection:le})}),(ge||_e)&&n(`nav`,{className:`flex items-center justify-center gap-2`,"aria-label":m(`view.pagination`),children:[n(o,{type:`button`,variant:`outline`,disabled:!ge||T,onClick:()=>void P({..._,offset:Math.max(0,me-he)||void 0},!0,!0),children:[t(sh,{className:`size-4 cn-rtl-flip`}),m(`grounded.previousPage`)]}),n(o,{type:`button`,variant:`outline`,disabled:!_e||T,onClick:()=>void P({..._,offset:me+he},!0,!0),children:[m(`grounded.nextPage`),t(uh,{className:`size-4 cn-rtl-flip`})]})]})]})]})})]});return t(M6,{definition:I,request:_,result:C,selection:le,contributions:i,client:d,canDelete:f,refresh:ye,children:be})}fY(),yY(),xY(),JY();export{Yp as ActivitiesDoc,Zp as ActivityDoc,Q3 as AddToCollectionAction,X3 as AddToCollectionActionComponent,Xb as AgentApprovalModeSelector,dC as AgentChart,MJ as AgentChatFixtureReplay,SC as AgentChatPlaybackControls,St as AgentResourceResolverProvider,zZ as AgentRunnerFacetsNav,H0 as AllOf,nW as AnimatedThinkingDots,V0 as AnyOf,MZ as ApiKeyAvatar,AH as AskUserWidget,L0 as AudioPanel,k4 as BrowseCollectionView,r6 as ChangeTypeAction,t6 as ChangeTypeActionComponent,F4 as CollectionIcon,qZ as CollectionsFacetsNav,P4 as CollectionsTable,jH as ConfirmationWidget,G$ as ContentDispositionButton,G4 as ContentObjectTypesSearch,L4 as ContentObjectTypesTable,a4 as ContentOverview,M4 as CreateCollectionForm,N4 as CreateCollectionModal,R4 as CreateOrUpdateTypeModal,z6 as DefaultViewNavigation,D8 as DefaultViewResults,P8 as DefaultViewSearch,s6 as DeleteObjectsAction,a6 as DeleteObjectsActionComponent,c6 as DeleteObjectsFromCollectionsAction,W2 as DocumentEditingPanel,U2 as DocumentEditingWorkspace,C$ as DocumentGridView,x$ as DocumentIcon,b$ as DocumentIconSkeleton,B3 as DocumentInput,V3 as DocumentPreviewPanel,w$ as DocumentSearch,U$ as DocumentSearchProvider,T4 as DocumentSearchResults,w4 as DocumentSearchResultsWithDropZone,IQ as DocumentSelection,BQ as DocumentSelectionProvider,R$ as DocumentTable,y$ as DocumentTableColumn,S$ as DocumentTableView,F$ as DocumentUploadModal,rQ as DocumentsFacetsNav,F3 as EditCollectionView,iQ as EnvironmentFacet,d6 as ExportPropertiesAction,l6 as ExportPropertiesComponent,W3 as ExportPropertiesModal,U3 as ExportTypes,j$ as FileUploadAction,Z1 as GenericPageNavHeader,r0 as GroundedExtractionPanel,i0 as GroundedExtractionView,eZ as Header,R0 as ImagePanel,p3 as IntakePolicyEditor,cQ as InteractionsFacetsNav,NJ as JumpingDots,hG as MESSAGE_STYLES,j0 as MagicPdfView,HJ as McpConnectionsActionMenu,BJ as McpConnectionsButton,zJ as McpConnectionsDialog,VJ as McpConnectionsInlineList,_G as MessageItem,N1 as MessagesContainer,O1 as ModernAgentConversation,Q1 as NotFoundView,B0 as OAuthProviderConnectButton,w3 as ObjectSchemaEditor,z4 as ObjectTypeSearch,B4 as ObjectTypeSearchContext,k3 as ObjectTypeSearchProvider,_6 as ObjectsActionContextProvider,U1 as PanelErrorBoundary,XX as PayloadBuilder,QX as PayloadBuilderProvider,YX as PayloadBuilderStore,ZX as PayloadContext,lY as PdfDocumentRenderer,nY as PdfPageRenderer,pY as PdfPageSlider,cY as PdfThumbnailList,uQ as ProcessDefinitionsFacetsNav,fQ as ProcessRunsFacetsNav,_Q as PromptsFacetsNav,G2 as PropertiesEditorModal,rW as PulsatingCircle,aW as PulsingMessageLoader,hO as RemoteMcpConnectionButton,m6 as RemoveFromCollectionAction,f6 as RemoveFromCollectionActionComponent,G1 as RowErrorBoundary,CQ as RunsFacetsNav,F2 as SaveVersionConfirmModal,T$ as SearchContext,Y0 as SecureButton,X0 as SecureSidebarItem,L3 as SelectCollection,j4 as SelectContentType,O3 as SelectContentTypeModal,q$ as SelectDocument,R3 as SelectDocumentModal,F1 as SelectEnvironment,R1 as SelectModel,z1 as SelectTrainingModel,x6 as SelectionActions,rY as SharedPdfProvider,M3 as SharedPropsEditor,aY as SimplePdfPage,bY as SimplePdfViewer,r1 as SkillWidgetProvider,AG as StreamingMessage,wQ as StringFacet,TQ as StringListFacet,N3 as SyncMemberHeadsToggle,A3 as TableLayoutEditor,oW as ThinkingBar,xW as ThinkingMessages,DQ as TypeFacet,BZ as TypeRegistry,HZ as TypeRegistryProvider,iW as TypedDots,qY as UniversalDocumentViewer,S6 as UploadObjectsButton,D6 as UserAvatar,OZ as UserInfo,J0 as UserPermissionProvider,W0 as UserPermissions,K0 as UserPermissionsContext,sZ as VInteractionFacet,dZ as VStringFacet,JZ as VTypeFacet,FZ as VUserFacet,sC as VegaLiteChart,B1 as VertesiaErrorBoundary,z0 as VideoPanel,M6 as ViewActionsProvider,N6 as ViewActionsToolbar,B8 as ViewExperience,P6 as ViewRowActions,F0 as WEB_SUPPORTED_AUDIO_FORMATS,N0 as WEB_SUPPORTED_IMAGE_FORMATS,P0 as WEB_SUPPORTED_VIDEO_FORMATS,sW as WavyThinking,q1 as WidgetErrorBoundary,kQ as WorkflowDefinitionsFacetsNav,NQ as WorkflowExecutionsFacetsNav,FQ as WorkflowRulesFacetsNav,$6 as canonicalizeViewState,fC as clampPlaybackCursor,LJ as countConnectedActiveGroups,RZ as createAgentRunnerFilterHandler,B2 as createDocumentChangeSummaryPrompt,z2 as createDocumentReconcilePrompt,gC as createPlaybackState,oZ as createSearchQueryKeyGuard,iZ as filterValueToQueryValue,I0 as formatDuration,o8 as formatViewFieldValue,RJ as getConnectedActiveGroupLabels,$W as getContentObjectDownloadName,hC as getNextUserTurnIndex,pC as getPlaybackCursorIndex,mC as getPreviousUserTurnIndex,r8 as getViewFieldValue,c$ as getWorkflowStatusColor,l$ as getWorkflowStatusName,$0 as invalidateTypeCache,vC as isAgentChatPlaybackAvailable,yC as isAgentChatPlaybackEnabled,U0 as isAnyOf,ZQ as isCsv,FJ as isGroupDisabled,QQ as isImage,bC as isLocalhostAgentChatPlaybackAvailable,xC as isLocalhostAgentChatPlaybackEnabled,$Q as isPdf,t$ as isPreviewableAsPdf,lC as isRechartsSpec,cC as isVegaLiteSpec,e$ as isVideo,K6 as parseViewState,n$ as printElementToPdf,t8 as replaceViewStateInUrl,Q0 as resolveTypeCached,e8 as resolveViewSort,a$ as retrieveRendition,X6 as serializeViewState,H1 as setErrorBoundaryComponent,aZ as setSearchQueryValue,o$ as shortId,s$ as shortenString,j3 as stringifyTableLayout,IJ as toggleGroupDisabled,rZ as unwrapFilterOptionValue,Gt as useAgentResourceResolver,LZ as useAgentRunnerFilterGroups,GZ as useCollectionsFilterGroups,KZ as useCollectionsFilterHandler,tQ as useDocumentFilterGroups,nQ as useDocumentFilterHandler,E$ as useDocumentSearch,k$ as useDocumentSearchCount,RQ as useDocumentSelection,I$ as useDocumentUploadHandler,eG as useDownloadFile,yZ as useFetchApiKeyInfo,vZ as useFetchGroupInfo,_Z as useFetchUserInfo,t0 as useGroundedExtractionAvailable,n0 as useGroundedSummary,oQ as useInteractionsFilterGroups,sQ as useInteractionsFilterHandler,PJ as useMcpConnections,mO as useOAuthPopup,zQ as useOptionalDocumentSelection,$X as usePayloadBuilder,lQ as useProcessDefinitionsFilterGroups,dQ as useProcessRunsFilterGroups,hQ as usePromptsFilterGroups,gQ as usePromptsFilterHandler,xQ as useRunsFilterGroups,SQ as useRunsFilterHandler,V4 as useSearch,U4 as useSearchCount,iY as useSharedPdf,P$ as useSmartFileUploadProcessing,UZ as useTypeRegistry,q0 as useUserPermissions,k6 as useViewActions,D$ as useWatchDocumentSearchFacets,O$ as useWatchDocumentSearchResult,H4 as useWatchSearchResult,OQ as useWorkflowDefinitionsFilterGroups,jQ as useWorkflowExecutionsFilterGroups,MQ as useWorkflowExecutionsFilterHandler,PQ as useWorkflowRulesFilterGroups};
1405
+ *`)),D=l?.content?.type?.startsWith(`image/`),O=l?.content?.type===`application/pdf`;return r?n(`div`,{className:`fixed inset-y-0 end-0 w-2/5 dark:bg-slate-900 shadow-xl z-50 flex flex-col transition-transform duration-300 transform ${r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`}`,children:[n(`div`,{className:`flex items-center justify-between px-4 py-3 border-b dark:border-gray-700 bg-gradient-to-r from-indigo-50 to-gray-50 dark:from-gray-800 dark:to-gray-900`,children:[n(`div`,{className:`flex items-center`,children:[t(Kg,{className:`h-5 w-5 text-indigo-600 me-2`}),t(`h2`,{className:`text-lg font-semibold text-gray-800 dark:text-gray-200 truncate`,children:d?x(`store.loadingDocument`):l?.name||x(`store.documentPreview`)})]}),n(`div`,{className:`flex items-center gap-2`,children:[n(o,{variant:`ghost`,size:`sm`,onClick:T,className:`flex items-center gap-1 text-indigo-600 hover:text-indigo-800`,children:[t(uv,{className:`h-4 w-4`}),t(`span`,{children:x(`store.fullView`)})]}),t(o,{variant:`ghost`,size:`sm`,onClick:i,className:`flex items-center text-gray-600 hover:text-gray-800 dark:text-gray-300 dark:hover:text-gray-100`,children:t(Kb,{className:`h-5 w-5`})})]})]}),d?t(`div`,{className:`flex-1 flex items-center justify-center`,children:n(`div`,{className:`text-center`,children:[t(je,{size:`lg`,className:`text-indigo-600 dark:text-indigo-400 mb-2`}),t(`p`,{className:`text-gray-600 dark:text-gray-400`,children:x(`store.loadingDocument`)})]})}):n(`div`,{className:`flex-1 flex flex-col h-full`,children:[t(`div`,{className:`border-b`,children:n(`div`,{className:`flex px-4`,children:[t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`preview`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`preview`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(L_,{className:`h-4 w-4`}),t(`span`,{children:x(`store.preview`)})]})}),t(o,{variant:`unstyled`,className:`py-2 px-4 font-medium border-b-2 ${y===`properties`?`border-indigo-600 text-indigo-700 dark:text-indigo-300`:`border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200`}`,onClick:()=>b(`properties`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(j_,{className:`h-4 w-4`}),t(`span`,{children:x(`store.properties`)})]})})]})}),n(`div`,{className:`flex-1 overflow-auto p-4`,children:[y===`preview`&&n(`div`,{className:`h-full`,children:[p?t(`div`,{className:`flex items-center justify-center h-40`,children:t(je,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})}):h?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:E?t(`div`,{className:`prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-gray-800 prose-pre:my-2 prose-headings:text-indigo-700 dark:prose-invert dark:prose-headings:text-indigo-300`,children:t(Nt,{children:h})}):t(`pre`,{className:`text-wrap whitespace-pre-wrap dark:text-gray-200`,children:h})}):null,D&&t(`div`,{className:`mt-4`,children:_?t(`div`,{className:`border border-gray-200 dark:border-gray-700 rounded-md p-2 bg-white dark:bg-gray-800`,children:t(`img`,{src:_,alt:l?.name,className:`mx-auto max-h-[70vh] object-contain`})}):t(`div`,{className:`flex items-center justify-center h-40`,children:t(je,{size:`md`,className:`text-indigo-600 dark:text-indigo-400`})})}),O&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Kg,{className:`h-16 w-16 text-indigo-300 dark:text-indigo-400 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center mb-4`,children:x(`store.pdfPreviewFullView`)}),t(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:x(`store.openFullDocumentView`)})]}),!D&&!h&&!O&&!p&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(Kg,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPreviewAvailable`)})]})]}),y===`properties`&&l&&n(`div`,{className:`h-full`,children:[l.properties?t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:t(jt,{value:l.properties})}):n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-gray-200 dark:border-gray-700 rounded-md p-4 bg-gray-50 dark:bg-gray-800`,children:[t(j_,{className:`h-16 w-16 text-gray-300 dark:text-gray-600 mb-4`}),t(`p`,{className:`text-gray-600 dark:text-gray-400 text-center`,children:x(`store.noPropertiesAvailable`)})]}),n(`div`,{className:`mt-4`,children:[t(`h3`,{className:`text-sm font-semibold text-gray-700 dark:text-gray-300 mb-2`,children:x(`store.documentInformation`)}),t(`div`,{className:`shadow rounded-md p-4 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,children:n(`div`,{className:`grid grid-cols-2 gap-y-2 gap-x-4 text-sm`,children:[t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.id`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.id}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.type?.name||x(`store.unknown`)}),t(`div`,{className:`text-gray-500 dark:text-gray-400`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-gray-200`,children:l.content?.type||x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.size`)}),t(`div`,{className:`font-medium`,children:l.content&&`size`in l.content?W3(l.content.size):x(`store.unknown`)}),t(`div`,{className:`text-gray-500`,children:x(`store.created`)}),t(`div`,{className:`font-medium`,children:l.created_at?new Date(l.created_at).toLocaleString():x(`store.na`)}),t(`div`,{className:`text-gray-500`,children:x(`store.updated`)}),t(`div`,{className:`font-medium`,children:l.updated_at?new Date(l.updated_at).toLocaleString():x(`store.na`)})]})})]})]})]})]}),n(`div`,{className:`flex items-center justify-between p-4 border-t bg-gray-50 dark:bg-gray-800 dark:border-gray-700`,children:[t(`div`,{children:l?.content?.source&&n(o,{onClick:()=>{l?.content?.source&&s.files.getDownloadUrl(l.content.source).then(e=>{window.open(e.url,`_blank`)}).catch(e=>{console.error(`Error getting download URL:`,e),S({title:x(`agent.error`),description:x(`store.failedToDownloadFile`),status:`error`,duration:3e3})})},variant:`outline`,className:`text-indigo-600 border-indigo-300 hover:bg-indigo-50`,children:[t(Sg,{className:`h-4 w-4 me-2`}),x(`pdf.download`)]})}),n(o,{onClick:T,className:`bg-indigo-600 hover:bg-indigo-700 text-white`,children:[x(`store.openFullDocument`),t(uh,{className:`h-4 w-4 ms-2 cn-rtl-flip`})]})]})]}):null}function W3(e){if(e===0)return`0 Bytes`;let t=1024,n=[`Bytes`,`KB`,`MB`,`GB`,`TB`],r=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/t**r).toFixed(2))} ${n[r]}`}var G3;(function(e){e.CSV=`CSV`,e.JSON=`JSON`})(G3||={});function K3({isExporting:e,isOpen:r,onClose:i,allowExportAll:a=!0}){return n(se,{onClose:()=>i(void 0),isOpen:r,children:[t(ue,{children:`Export Object Properties`}),n(ce,{children:[!e&&t(q3,{onClose:i,allowExportAll:a}),e&&t(J3,{})]})]})}function q3({onClose:e,allowExportAll:r}){let{t:i}=K(),[a,s]=G(void 0),c=[`Export selected objects`,`Export all objects`],[l,u]=G(r?void 0:c[0]),d=e=>e===c[1];return n(ce,{className:`min-h-[104px] pt-0 flex flex-col gap-y-4`,children:[r&&t(`div`,{className:`h-1/3`,children:t(we,{options:c,value:l,onChange:u,placeholder:i(`store.chooseWhatToExport`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0})}),n(`div`,{className:`h-1/2 flex flex-col gap-y-8 content-between`,children:[t(we,{options:Object.values(G3),value:a,onChange:s,placeholder:i(`store.chooseAFormat`),className:`h-full w-full text-sm`,filterBy:`name`,isClearable:!0}),t(o,{className:`w-full`,isDisabled:!a||!l,onClick:()=>{e(a,d(l))},children:i(`store.actions.exportProperties`)})]})]})}function J3(){let{t:e}=K();return t(ce,{className:`min-h-[84px] pt-0`,children:n(`div`,{className:`h-full grid flex-col gap-y-2 content-between justify-items-center`,children:[n(`div`,{className:`text-sm flex flex-col gap-x-2`,children:[t(`p`,{children:e(`store.exportInProgress`)}),t(`p`,{className:`pt-2 grid justify-items-center`,children:e(`store.pleaseWait`)})]}),t(je,{size:`lg`})]})})}const Y3=dt(void 0);function X3(){let e=_t(Y3);if(!e)throw Error(`You cannot use useActionContext outside an ActionProvider`);return e}function Z3(e,t){let n=X3();return H(()=>n.registerCallback(e,t),[n,e,t]),n}function Q3({action:e,objectIds:n}){let[r,i]=G(!1),a=V(()=>(n.length>0&&i(!0),Promise.resolve(!0)),[n]);return Z3(e.id,a),r&&t(ve,{children:t(t6,{objectIds:n,isOpen:r,onClose:()=>{i(!1)}})})}const $3=Xt.getFixedT(null,Yt),e6={id:`addToCollection`,name:$3(`store.actions.addToCollection`),description:$3(`store.actions.addToCollectionDesc`),confirm:!1,component:Q3};function t6({isOpen:e,onClose:r,objectIds:i}){let{t:a}=K();return n(se,{isOpen:e,onClose:r,className:`max-w-lg w-full min-w-0 overflow-hidden`,children:[t(ue,{className:`flex flex-col min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionTitle`)}),t(S,{className:`min-w-0 overflow-hidden`,children:a(`store.actions.addToCollectionBody`)}),t(`div`,{className:`min-w-0 max-w-full overflow-hidden`,children:t(n6,{onClose:r,objectIds:i})})]})}function n6({onClose:e,objectIds:r}){let{t:i}=K(),a=nt(),{client:s}=q(),[c,l]=G(),u=({collectionId:t})=>{!t||!r?.length||s.store.collections.addMembers(t,r).then(()=>{a({title:i(`store.actions.addToCollectionSuccess`),status:`success`,description:i(`store.actions.addToCollectionSuccessDesc`,{count:r.length}),duration:3e3}),e()}).catch(()=>{a({title:i(`store.actions.addToCollectionFailure`),status:`error`,description:i(`store.actions.addToCollectionFailureDesc`),duration:5e3})})},d=[{name:`select`,label:i(`store.actions.selectCollection`),content:n(`div`,{className:`p-4 min-w-0 max-w-full overflow-hidden`,children:[t(ee,{level:5,children:i(`store.actions.chooseExistingCollections`)}),t(ce,{className:`min-w-0 max-w-full overflow-hidden`,children:t(`div`,{className:`mb-4 min-w-0 max-w-full overflow-hidden`,children:t(z3,{onChange:(e,t)=>{typeof e==`string`||e===void 0?l(e):Array.isArray(e)&&e.length>0?l(e[0]):l(void 0)},value:c})})}),t(le,{children:t(o,{isDisabled:!c,onClick:()=>c&&u({collectionId:c}),children:i(`store.actions.addToCollectionButton`)})})]})},{name:`create`,label:i(`store.actions.createNew`),content:t(`div`,{className:`p-4`,children:t(P4,{onClose:e,onAddToCollection:e=>u({collectionId:e}),redirect:!1})})}];return n(ze,{defaultValue:`select`,tabs:d,fullWidth:!0,children:[t(Be,{}),t(Ve,{})]})}function r6({action:e,objectIds:r,children:i}){let{t:a}=K(),{store:o}=q(),s=nt(),[c,l]=G(!1),u=V(()=>(l(!0),Promise.resolve(!0)),[]);return Z3(e.id,u),n(`div`,{children:[i,t(A3,{isOpen:c,onClose:e=>{l(!1),e!==void 0&&o.runOperation({name:`change_type`,ids:r,params:{typeId:e}}).then(e=>{s({status:`success`,title:a(`store.actions.changeType`),description:`Change the type of ${r.length} objects is ${e.status===`in_progress`?`in progress`:`completed`}`,duration:2e3})}).catch(e=>{s({status:`error`,title:a(`store.actions.errorChangingType`),description:e.message,duration:5e3})})},title:`Change Content Type`,confirmLabel:`Change Type`,children:n(`p`,{className:`pt-2 text-xs`,children:[`Note: This action will raise the `,t(`code`,{children:`change_type`}),` event and will trigger the standard intake workflows which may reset the object properties.`]})})]})}const i6=Xt.getFixedT(null,Yt),a6={id:`changeType`,name:i6(`store.actions.changeContentType`),description:i6(`store.actions.changeContentTypeDesc`),confirm:!1,component:r6};function o6({action:r,callback:i,children:a}){let{t:o}=K(),[s,c]=G(!1),l=r.confirmationText||`Are you sure you want to ${r.name}?`,u=V(e=>r.confirm?(c(!0),Promise.resolve(!0)):i(e),[r.confirm,i]),d=Z3(r.id,u);return n(e,{children:[a,t(b,{onConfirm:()=>{c(!1),i({...d.params,action:r})},onCancel:()=>c(!1),title:o(`store.actions.areYouSure`),content:l,isOpen:s})]})}function s6({action:r,objectIds:i,children:a}){let{t:o}=K(),s=X3(),c=nt(),{client:l}=q(),u=O$(),d=$n(),[f,p]=G(!1),m=i?.length??0,h=s.params?.type?.name??`object`,g=V(()=>(p(!0),Promise.resolve(!0)),[]);Z3(r.id,g);let _=V(()=>(p(!1),i?.length?l.store.objects.delete(i).then(e=>{let t=e.deleted>1?`s`:``;if(c({status:`success`,title:`${e.deleted} object${t} deleted`,duration:2e3}),e.failed.length>0&&c({status:`warning`,title:`${e.failed.length} object(s) could not be deleted`,duration:3e3}),u){s.params?.selection?.removeAll();let t=JSON.parse(JSON.stringify(u.facets));i.length===t._value.total&&u.resetFacets();let n=new Set(e.failed);u.removeDeletedObjects(i.filter(e=>!n.has(e))),u.search()}else d(`/objects`)}).catch(e=>{c({status:`error`,title:o(`store.actions.errorDeletingObjects`),description:e.message,duration:5e3})}):(c({status:`error`,title:o(`store.actions.noObjectsSelected`),description:o(`store.actions.pleaseSelectObjectsToDelete`),duration:3e3}),Promise.resolve(!1))),[l.store.objects.delete,s.params?.selection?.removeAll,d,i,u,u?.facets,u?.resetFacets,u?.search,o,c]);return n(e,{children:[a,t(b,{isOpen:f,title:m===1?`Delete ${h}`:`Delete ${h}s`,content:n(`div`,{children:[n(`p`,{children:[`Delete `,m,` selected `,h,m===1?``:`s`,`? `,m===1?`This ${h}`:`These ${h}s`,` will be permanently removed.`]}),t(`p`,{children:t(`span`,{className:`text-destructive`,children:`This action cannot be undone.`})})]}),onConfirm:_,onCancel:()=>p(!1),confirmationValue:`delete`,confirmationLabel:`Type "delete" to confirm`,confirmationPlaceholder:`delete`})]})}const c6=Xt.getFixedT(null,Yt),l6={id:`delete`,name:c6(`store.actions.delete`),description:c6(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:c6(`store.actions.confirmDeleteAll`),component:s6,destructive:!0},u6={id:`deleteFromCollections`,name:c6(`store.actions.deleteObjects`),description:c6(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:c6(`store.actions.confirmDeleteSelected`),component:s6,destructive:!0};function d6({action:e,objectIds:n}){let{t:r}=K(),{store:i}=q(),a=nt(),[o,s]=G(!1),[c,l]=G(!1),u=V(()=>(s(!0),Promise.resolve(!0)),[]),d=Z3(e.id,u);return t(K3,{isExporting:c,isOpen:o,onClose:(e,t)=>{if(e&&(t||n.length>0)){l(!0);let o=d.params?.search?.query||{},c=d.params?.search?.result?.value?.objects?.map(e=>e.id)||void 0,u=async e=>i.objects.list({query:{parent:e}}).then(e=>e.map(e=>e.id)),f=async()=>t?c?o.vector?c:[]:n.length===0?[]:(await u(n[0])).concat(n):n,p=d.params?.type?.id??o.type,m=d.params?.type?.table_layout??void 0;f().then(c=>{i.objects.exportProperties({objectIds:c,type:e,query:t&&!o.vector?{...o,type:p}:{type:p},table_layout:m}).then(e=>{let i=new Blob([e.data],{type:e.type}),o=window.URL.createObjectURL(i),s=document.createElement(`a`);s.download=e.name,s.href=o,s.click(),a({status:`success`,title:r(`store.actions.exportProperties`),description:t?`Export the properties of all objects completed`:`Export the properties of ${n.length} object${n.length>1?`s`:``} is completed`,duration:2e3})}).catch(e=>{a({status:`error`,title:r(`store.actions.errorExportProperties`),description:e.message,duration:5e3})}).finally(()=>{l(!1),s(!1)})})}else s(!1),a({status:`error`,title:r(`store.actions.errorExportProperties`),description:`No objects selected for export`,duration:5e3})}})}const f6=Xt.getFixedT(null,Yt),p6={id:`exportProperties`,name:f6(`store.actions.exportProperties`),description:f6(`store.actions.exportAllObjectProperties`),confirm:!1,component:d6};function m6({action:e,objectIds:n,collectionId:r}){let{t:i}=K(),a=X3(),o=nt(),{client:s}=q(),c=O$(),l=V(()=>n?.length?r?s.store.collections.deleteMembers(r,n).then(()=>{let e=n.length>1?`s`:``;o({status:`success`,title:`${n.length} object${e} removed from collection`,description:`Objects have been removed from the collection`,duration:2e3}),c&&(a.params?.selection?.removeAll(),c.search())}).catch(e=>{o({status:`error`,title:i(`store.actions.errorRemovingObjects`),description:Ge(e),duration:5e3})}):(o({status:`error`,title:i(`store.actions.noCollectionContext`),description:i(`store.actions.cannotRemoveNoCollection`),duration:3e3}),Promise.resolve(!1)):(o({status:`error`,title:i(`store.actions.noObjectsSelected`),description:i(`store.actions.pleaseSelectObjectsToRemove`),duration:3e3}),Promise.resolve(!1)),[s.store.collections.deleteMembers,r,a.params?.selection?.removeAll,n,c,c?.search,i,o]);return t(o6,{action:e,callback:l})}const h6=Xt.getFixedT(null,Yt),g6={id:`removeFromCollection`,name:h6(`store.actions.removeFromCollection`),description:h6(`store.actions.removeFromCollectionDesc`),confirm:!0,confirmationText:h6(`store.actions.confirmRemoveFromCollection`),component:m6,destructive:!0};var _6=class{params;allActions=[];callbacks={};constructor(e){this.params=e}get actions(){return this.params.selection?.collectionId?this.allActions.filter(e=>e.id!==`addToCollection`&&e.id!==`delete`):this.allActions.filter(e=>e.id!==`removeFromCollection`&&e.id!==`deleteFromCollections`)}registerCallback(e,t){return this.callbacks[e]=t,()=>{delete this.callbacks[e]}}unregisterCallback(e){delete this.callbacks[e]}findAction(e){return this.allActions.find(t=>t.id===e)}async run(e){let t=this.findAction(e);if(!t)throw Error(`Action ${e} not found`);let n={...this.params,action:t},r=this.callbacks[e];if(r)return r(n);throw Error(`No action callback set`)}};const v6=[p6,a6,e6,l6,g6,u6];function y6({children:e,type:r}){let i=BQ(),a=nt(),{client:o}=q(),s=O$(),c=U(()=>{let e=new _6({selection:i,toast:a,client:o,search:s,type:r});return e.allActions=v6,e},[o,s,i,a,r]);return c&&n(Y3.Provider,{value:c,children:[t(b6,{}),e]})}function b6(){let e=X3(),n=e.params.selection,r=n.getObjectId(),i=n.isSingleSelection()&&r?[r]:n.getObjectIds();return t(`div`,{style:{display:`none`},children:e.allActions.map(e=>t(e.component,{action:e,objectIds:i,collectionId:n.collectionId},e.id))})}function x6(){let{t:r}=K(),i=BQ(),[a,s]=G(!1);return i?.hasSelection()?n(e,{children:[t(o,{onClick:()=>s(!0),children:r(`store.actions.startWorkflow`)}),a&&t(S6,{objectIds:i.getObjectIds(),onClose:()=>s(!1)})]}):null}function S6({objectIds:e,onClose:r}){let{t:i}=K(),{client:a}=q(),s=nt(),[c,l]=G(void 0),[u,d]=G(!1),{data:f,isLoading:p}=Ye(()=>a.store.workflows.rules.list(),[]);return n(se,{isOpen:!0,onClose:r,size:`lg`,children:[t(ue,{children:i(`store.actions.startWorkflowByRule`)}),n(ce,{children:[t(`div`,{className:`pb-2`,children:i(`store.actions.chooseWorkflowRule`)}),p?t(`div`,{className:`flex justify-center py-4`,children:t(je,{})}):t(`div`,{className:`max-h-[420px] overflow-y-auto border-border border rounded-md`,children:t(Te,{className:`text-start w-full`,options:f??[],value:c,onChange:l,optionLayout:e=>({label:e.name})})})]}),n(le,{align:`right`,children:[t(o,{variant:`outline`,onClick:r,disabled:u,children:`Cancel`}),t(o,{onClick:async()=>{if(!(!c||u)){d(!0);try{await a.store.workflows.rules.execute(c.id,e),s({title:i(`store.actions.workflowStarted`),status:`success`,duration:3e3}),r()}catch(e){s({title:i(`store.actions.errorStartingWorkflow`),description:e instanceof Error?e.message:void 0,status:`error`,duration:9e3})}finally{d(!1)}}},isDisabled:!c||u,isLoading:u,children:`Start`})]})]})}Q();function C6({type:e,allowMutations:r=!0,allowDelete:i=!0,allowWorkflowRun:a=!1}){let s=BQ(),c=s.size(),l=c>1?`s`:``,u=s?.hasSelection(),d=s?.isSingleSelection();return t(y6,{type:e,children:n(`div`,{className:`flex items-center gap-x-2`,children:[u&&!d&&n(`div`,{className:`flex items-center gap-x-1 shrink-0`,children:[n(`div`,{className:`text-sm nowrap`,children:[c,` document`,l,` selected`]}),t(o,{title:`Clear selection`,variant:`ghost`,onClick:()=>{s?.removeAll()},children:t(Kb,{className:`size-4`})})]}),a&&t(x6,{}),t(E6,{selection:s,allowMutations:r,allowDelete:i,children:e=>e.length>0?t(o,{variant:`ghost`,title:`More action`,size:`sm`,children:t(Tg,{size:16})}):null})]})})}function w6({collectionId:r,allowFolders:i=!0}){let{t:a}=K(),[s,c]=G([]),[l,u]=G(!1);return n(e,{children:[t(o,{onClick:()=>u(!0),children:a(`store.upload`)}),t(L$,{collectionId:r??``,isOpen:l,onClose:()=>{u(!1),c([])},files:s,title:`Upload Files`,onUploadComplete:e=>{e?.success&&c([])},allowFolders:i})]})}function T6(e){return{label:e.name,className:it(`flex-1 px-2 py-2 hover:bg-accent nowrap`,e.destructive?`text-destructive`:``)}}function E6({selection:e,children:r,allowMutations:i=!0,allowDelete:a=!0}){let o=X3(),s=e=>{o.run(e.id)},c=O6(o.actions,e,{allowMutations:i,allowDelete:a}),l=r(c);return l?n(he,{hover:!0,children:[t(_e,{children:l}),t(ge,{className:`p-0 w-50`,align:`end`,sideOffset:6,children:t(D6,{executeAction:s,actions:c})})]}):null}function D6({executeAction:e,actions:n}){return t(`div`,{className:`rounded-md shadow-md py-2`,children:t(`div`,{className:`px-1 text-sm`,children:t(Te,{options:n,optionLayout:T6,onChange:t=>{e(t)},noCheck:!0})})})}function O6(e,t,n){return t?.hasSelection()?e.filter(e=>e.hideInList?!1:e.id===`delete`||e.id===`deleteFromCollections`?n.allowDelete:e.id===`changeType`||e.id===`addToCollection`||e.id===`removeFromCollection`?n.allowMutations:!0):[p6]}function k6({user:e}){return n(`div`,{className:`flex items-center`,children:[t(`div`,{className:`w-9 h-9`,children:(()=>{if(e.picture)return t(`img`,{className:`inline-block h-9 w-9 rounded-full`,src:e.picture,alt:e.name});{let n=e.name.split(` `).map(e=>e[0]).join(``);return t(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-full bg-indigo-600`,children:t(`span`,{className:`text-sm font-medium leading-none text-white`,children:n})})}})()}),n(`div`,{className:`ms-3`,children:[t(`p`,{className:`text-sm font-medium text-gray-700 dark:text-slate-50 group-hover:text-gray-900`,children:e.name??`Deleted User`}),t(`p`,{className:`text-xs font-medium text-gray-500 dark:text-slate-300 group-hover:text-gray-700`,children:e.email??`Deleted User`})]})]})}Q();const A6=dt(void 0);function j6(){return _t(A6)}function M6(e,t){let n=e.requires_selection??(e.placement===`toolbar`?`none`:`any`);return n===`none`?!0:n===`single`?t.length===1:n===`multiple`?t.length>1:t.length>0}function N6(e){let t=window.URL.createObjectURL(new Blob([e.data],{type:e.type})),n=document.createElement(`a`);n.download=e.name,n.href=t,n.click(),window.setTimeout(()=>window.URL.revokeObjectURL(t),0)}function P6({children:e,definition:r,request:i,result:a,selection:o,contributions:s,client:c,canDelete:l,refresh:u}){let{t:d}=K(),f=nt(),[p,m]=G(),[h,g]=G(),[_,v]=G(!1),[y,x]=G(),S=W(!1),C=r.results?.actions,w=U(()=>({definition:r,request:i,result:a,refresh:u,clearSelection:()=>o?.clear()}),[r,u,i,a,o]),T=U(()=>{let e=(C?.items??[]).filter(e=>{let t=s?.actions?.[e.handler];return t!==void 0&&(t.isAvailable?.(w)??!0)});if(!o||C?.include_defaults===!1||!c)return e;let t=new Set(C?.exclude_defaults??[]),n=[];return t.has(`export`)||n.push({id:`export`,label:d(`store.actions.exportProperties`),handler:`export`,placement:`selection`,requires_selection:`any`}),l&&!t.has(`delete`)&&n.push({id:`delete`,label:d(`store.actions.delete`),handler:`delete`,placement:`selection`,requires_selection:`any`,destructive:!0,confirm:!0}),[...n,...e]},[C,w,l,c,s?.actions,o,d]),E=V(async({action:e,hits:t})=>{if(!S.current){S.current=!0,x(e.id);try{if(e.handler===`delete`){if(!c)return;let e=await c.store.objects.delete(t.map(e=>e.id));f({status:e.failed.length>0?`warning`:`success`,title:d(`view.deletedObjects`,{count:e.deleted})}),o?.clear(),await u();return}let n=s?.actions?.[e.handler];if(!n)return;await n.run({...w,action:e,hits:t})}catch(e){console.error(`View action failed:`,e),f({status:`error`,title:d(`view.actionFailed`),description:d(`view.actionFailedDescription`)})}finally{S.current=!1,x(void 0),m(void 0)}}},[w,c,s?.actions,u,o,d,f]),D=V((e,t)=>{if(!(!M6(e,t)||S.current)){if(e.handler===`export`){g(t);return}if(e.confirm){m({action:e,hits:t});return}E({action:e,hits:t})}},[E]),O=V(e=>{if(!e||!h?.length||!c){g(void 0);return}v(!0),c.store.objects.exportProperties({objectIds:h.map(e=>e.id),type:e}).then(e=>{N6(e),f({status:`success`,title:d(`store.actions.exportProperties`)}),g(void 0)}).catch(e=>{console.error(`View export failed:`,e),f({status:`error`,title:d(`store.actions.errorExportProperties`),description:d(`view.actionFailedDescription`)})}).finally(()=>v(!1))},[c,h,d,f]),k=U(()=>({actions:T,runningActionId:y,run:D}),[T,D,y]);return n(A6.Provider,{value:k,children:[e,t(K3,{isOpen:h!==void 0,isExporting:_,onClose:O,allowExportAll:!1}),t(b,{isOpen:p!==void 0,title:p?.action.label??d(`modal.confirm`),content:d(`view.confirmAction`,{action:p?.action.label??``,count:p?.hits.length??0}),isLoading:y!==void 0,onConfirm:()=>{p&&E(p)},onCancel:()=>m(void 0),confirmationValue:p?.action.handler===`delete`?`delete`:void 0,confirmationLabel:p?.action.handler===`delete`?d(`view.typeDeleteToConfirm`):void 0,confirmationPlaceholder:p?.action.handler===`delete`?`delete`:void 0})]})}function F6({selection:r,page:i,showSelectPage:a=!1}){let{t:s}=K(),c=j6(),l=vt();if(!c)return null;let u=r?.selectedHits??[],d=r?i.filter(e=>r.isSelected(e.id)).length:0,f=i.length>0&&d===i.length,p=a&&r?.selectAll&&i.length>0,h=c.actions.filter(e=>((e.placement??`selection`)===`toolbar`||(e.placement??`selection`)===`selection`&&u.length>0)&&M6(e,u));return h.length===0&&u.length===0&&!p?null:n(`div`,{className:`flex flex-wrap items-center gap-2`,children:[p&&r&&n(`div`,{className:`flex items-center gap-2`,children:[t(m,{id:l,checked:f?!0:d>0&&`indeterminate`,onCheckedChange:e=>r.togglePage(i,e===!0)}),t(`label`,{htmlFor:l,className:`text-sm text-muted`,children:s(`view.selectPage`)})]}),u.length>0&&n(e,{children:[t(`span`,{className:`text-sm text-muted`,children:s(`view.selectedCount`,{count:u.length})}),t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":s(`view.clearSelection`),onClick:r?.clear,children:t(Kb,{className:`size-4`})})]}),h.map(e=>n(o,{type:`button`,variant:e.destructive?`destructive`:`outline`,size:`sm`,disabled:c.runningActionId!==void 0,onClick:()=>c.run(e,u),children:[e.handler===`export`&&t(Sg,{className:`size-4`}),e.handler===`delete`&&t(gb,{className:`size-4`}),e.label]},e.id))]})}function I6({hit:e}){let{t:r}=K(),i=j6(),a=i?.actions.filter(t=>(t.placement??`selection`)===`row`&&M6(t,[e]));return!i||!a?.length?null:n(he,{children:[t(_e,{children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":r(`view.actions`),children:t(Tg,{className:`size-4`})})}),t(ge,{className:`w-52 p-1`,align:`end`,sideOffset:6,children:t(Te,{options:a,optionLayout:e=>({label:e.label,className:e.destructive?`text-destructive`:void 0}),onChange:t=>i.run(t,[e]),noCheck:!0})})]})}function L6(e){return e.dataTransfer.items?Array.from(e.dataTransfer.items).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>e!==null):Array.from(e.dataTransfer.files)}function R6({children:r,definition:i,request:a,result:o,contribution:s,canWrite:c,refresh:l}){let{t:u}=K(),d=nt(),f=i.results?.drop,p=f?.handler===`upload`&&c,m=s!==void 0||p,[h,g]=G(!1),[_,v]=G(!1),[y,b]=G([]),x=W(!1),S=V(async e=>{if(e.length){if(s){if(x.current)return;x.current=!0,v(!0);try{await s.run({configuration:f,files:e,definition:i,request:a,result:o,refresh:l})}catch(e){console.error(`View drop action failed:`,e),d({status:`error`,title:u(`view.dropFailed`),description:u(`view.actionFailedDescription`)})}finally{x.current=!1,v(!1)}return}p&&b(e)}},[p,f,s,i,l,a,o,u,d]);if(!m)return r;let C=f?.params;return n(e,{children:[n(`div`,{className:`relative min-h-48`,onDragEnter:e=>{e.preventDefault(),g(!0)},onDragOver:e=>{e.preventDefault(),g(!0)},onDragLeave:e=>{e.preventDefault(),e.currentTarget.contains(e.relatedTarget)||g(!1)},onDrop:e=>{e.preventDefault(),e.stopPropagation(),g(!1),!e.target.closest(`[data-view-drop-zone]`)&&S(L6(e))},children:[r,_&&t(`div`,{className:`absolute inset-0 z-40 flex items-center justify-center bg-background/80`,children:t(je,{size:`xl`})}),t(`div`,{"data-view-drop-zone":!0,className:`pointer-events-none absolute inset-0 ${h?`z-50`:`-z-10`}`,children:t(Ot,{onDrop:e=>void S(e),message:u(`view.dropFiles`),buttonLabel:u(`view.selectFiles`),allowFolders:C?.allow_folders??!0,className:`pointer-events-auto absolute inset-0 bg-background/90 ${h?`flex`:`hidden`}`})})]}),p&&t(L$,{isOpen:y.length>0,onClose:()=>b([]),files:y,collectionId:C?.collection_id,selectedFolder:C?.location,initialTypeId:C?.type_id,defaultProperties:C?.properties,allowFolders:C?.allow_folders??!0,title:u(`view.uploadToView`),onUploadComplete:e=>{e.success&&l()}})]})}Q();function z6(e,t,n,r){return n?r===!1?[t]:e.includes(t)?e:[...e,t]:e.filter(e=>e!==t)}function B6({node:e}){return n(`span`,{className:`flex min-w-0 flex-1 items-center justify-between gap-2`,children:[t(`span`,{className:`truncate`,children:e.label}),t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]})}function V6({configuration:e,result:r,isLoading:i,onChange:a,onQueryChange:s}){let{t:c}=K(),l=vt(),u=e.presentation??(e.source===`location`||e.source===`hierarchy`?`tree`:`list`),d=e.source!==`hierarchy`&&e.multi_select,f=r.breadcrumbs??[],[p,h]=G(r.query??``);H(()=>{h(r.query??``)},[r.query]);let g=(e,t)=>{a(z6(r.selected,e,t,d))};return n(`section`,{className:`space-y-2`,"aria-labelledby":`${l}-label`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h2`,{id:`${l}-label`,className:`text-sm font-semibold`,children:e.label}),r.selected.length>0&&n(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([]),"aria-label":`${c(`filter.clearAll`)}: ${e.label}`,children:[t(Kb,{className:`size-3.5`}),c(`filter.clearAll`)]})]}),e.source===`collection`&&s&&n(`form`,{className:`flex items-center gap-1`,onSubmit:e=>{e.preventDefault(),s?.(p.trim())},children:[t(te,{value:p,onChange:h,disabled:i,placeholder:c(`view.filterNavigation`,{label:e.label}),"aria-label":c(`view.filterNavigation`,{label:e.label})}),t(o,{type:`submit`,variant:`outline`,size:`icon`,disabled:i,"aria-label":c(`view.searchNavigation`,{label:e.label}),children:t(jy,{"aria-hidden":`true`,className:`size-4`})})]}),f.length>0&&t(`nav`,{"aria-label":`${e.label} path`,children:t(`ol`,{className:`flex flex-wrap items-center gap-1 text-sm`,children:f.map((e,r)=>n(`li`,{className:`flex items-center gap-1`,children:[r>0&&t(uh,{"aria-hidden":`true`,className:`size-3.5 text-muted`}),t(o,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>a([e.id]),"aria-current":r===f.length-1?`page`:void 0,children:e.label})]},e.id))})}),r.selected.length>0&&f.length===0&&(e.source===`location`||e.source===`collection`)&&t(`div`,{className:`flex flex-wrap gap-1`,children:r.selected.map(e=>{let a=r.nodes.find(t=>t.id===e)?.label??e;return n(o,{type:`button`,variant:`secondary`,size:`sm`,disabled:i,onClick:()=>g(e,!1),"aria-label":c(`view.removeSelection`,{value:a}),children:[a,t(Kb,{"aria-hidden":`true`,className:`size-3.5`})]},e)})}),u===`select`&&d===!1?t(we,{options:r.nodes,value:r.nodes.find(e=>r.selected.includes(e.id)),onChange:e=>a([e.id]),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):u===`select`?t(we,{multiple:!0,options:r.nodes,value:r.nodes.filter(e=>r.selected.includes(e.id)),onChange:e=>a(e.map(e=>e.id)),optionLabel:e=>`${e.label} (${e.count})`,by:`id`,disabled:i,placeholder:e.label,"aria-label":e.label}):u===`chips`?t(`div`,{className:`flex flex-wrap gap-2`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`outline`,size:`sm`,disabled:i,onClick:()=>g(e.id,!r.selected.includes(e.id)),children:[e.label,t(`span`,{className:`text-xs tabular-nums text-muted`,children:e.count})]},e.id))}):e.source===`hierarchy`?t(`div`,{className:`space-y-1`,children:r.nodes.map(e=>n(o,{type:`button`,variant:r.selected.includes(e.id)?`secondary`:`ghost`,className:`w-full justify-start`,disabled:i,onClick:()=>a([e.id]),children:[t(B6,{node:e}),e.expandable&&t(uh,{"aria-hidden":`true`,className:`size-4 shrink-0 text-muted`})]},e.id))}):t(`div`,{className:`space-y-1`,children:r.nodes.map((e,a)=>{let o=`${l}-${a}`;return n(`div`,{className:`flex items-center gap-2 rounded-md px-2 py-1.5 hover:bg-muted`,children:[t(m,{id:o,checked:r.selected.includes(e.id),disabled:i,onCheckedChange:t=>g(e.id,t===!0)}),t(`label`,{htmlFor:o,className:`flex min-w-0 flex-1 cursor-pointer text-sm`,children:t(B6,{node:e})})]},e.id)})}),r.nodes.length===0&&t(`p`,{className:`text-sm text-muted`,children:c(`filter.noAvailableFilters`)})]})}const H6=`display`,U6=`sort`,W6=`offset`;function G6(e){if(e===null||e.trim()===``)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0}function K6(e,t){let n={};for(let r of new Set(e.keys())){if(!r.startsWith(t)||r.length===t.length)continue;let i=e.getAll(r).filter(e=>e!==``);i.length>0&&(n[r.slice(t.length)]=i)}return Object.keys(n).length>0?n:void 0}function q6(e,t){let n={};for(let r of new Set(e.keys())){if(!r.startsWith(t)||r.length===t.length)continue;let i=e.get(r)?.trim();i&&(n[r.slice(t.length)]=i)}return Object.keys(n).length>0?n:void 0}function J6(e){let t=new URLSearchParams(e.startsWith(`?`)?e.slice(1):e),n=t.get(`q`)?.trim(),r=t.get(H6)?.trim(),i=t.get(U6)?.trim(),a=G6(t.get(W6)),o=K6(t,`t.`),s=K6(t,`n.`),c=q6(t,`nq.`);return{...n?{query:n}:{},...o?{key_terms:o}:{},...s?{navigation:s}:{},...c?{navigation_queries:c}:{},...r?{display:r}:{},...i?{sort:i}:{},...a?{offset:a}:{}}}function Y6(e){for(let t of[...e.keys()])(t===`q`||t===H6||t===U6||t===W6||t.startsWith(`t.`)||t.startsWith(`nq.`)||t.startsWith(`n.`))&&e.delete(t)}function X6(e,t,n){if(n)for(let[r,i]of Object.entries(n).sort(([e],[t])=>e.localeCompare(t)))for(let n of i)n!==``&&e.append(`${t}${r}`,n)}function Z6(e,t,n){if(n)for(let[r,i]of Object.entries(n).sort(([e],[t])=>e.localeCompare(t)))i.trim()&&e.set(`${t}${r}`,i.trim())}function Q6(e,t=``){let n=new URLSearchParams(t.startsWith(`?`)?t.slice(1):t);Y6(n),e.query?.trim()&&n.set(`q`,e.query.trim()),e.display&&n.set(H6,e.display),e.sort&&n.set(U6,e.sort),e.offset&&e.offset>0&&n.set(W6,String(e.offset)),X6(n,`t.`,e.key_terms),X6(n,`n.`,e.navigation),Z6(n,`nq.`,e.navigation_queries);let r=n.toString();return r?`?${r}`:``}function $6(e){let t=Object.fromEntries(Object.entries(e.navigation).filter(([,e])=>e.selected.length>0).map(([e,t])=>[e,t.selected]));return Object.keys(t).length>0?t:void 0}function e8(e){let t={};for(let[n,r]of Object.entries(e.navigation))r.query&&(t[n]=r.query);return Object.keys(t).length>0?t:void 0}function t8(e,t){let n=new Set(t.definition.search?.key_terms?.map(e=>e.id)??[]),r=e.key_terms?Object.fromEntries(Object.entries(e.key_terms).filter(([e,t])=>n.has(e)&&t.length)):void 0,i=$6(t),a=e8(t);return{...e.query?.trim()?{query:e.query.trim()}:{},...r&&Object.keys(r).length>0?{key_terms:r}:{},...i?{navigation:i}:{},...a?{navigation_queries:a}:{},...t.display?{display:t.display}:{},...t.sort?{sort:t.sort}:{},...e.offset&&e.offset>0?{offset:e.offset}:{},...e.limit?{limit:e.limit}:{}}}function n8(e,t,n){return t.sort??e.sort??(e.query?.trim()?void 0:n)}function r8(e){if(typeof window>`u`)return;let t=Q6(e,window.location.search);window.history.replaceState(window.history.state||{},``,`${window.location.pathname}${t}`)}Q();function i8(e,t){return!t||t===`.`?e:t.split(`.`).reduce((e,t)=>{if(!(!e||typeof e!=`object`||Array.isArray(e)))return e[t]},e)}function a8(e,t){return t===`score`?e.score:t.startsWith(`annotation.`)?i8(e.annotation,t.slice(11)):t.startsWith(`document.`)?i8(e.document,t.slice(9)):i8(e.document,t)}const o8=dt(void 0);function s8(e){if(e!=null&&e!==``)return Array.isArray(e)?e.map(s8).filter(Boolean).join(`, `):typeof e==`object`?JSON.stringify(e):String(e)}function c8(e,t,n){let r=a8(e,t.field),i=t.fallback??``;if(r==null||r===``)return i;if(t.format===`date`){let e=String(r),t=/^\d{4}-\d{2}-\d{2}$/.test(e),a=new Date(e);if(Number.isNaN(a.getTime()))return s8(r)??i;let o={year:`numeric`,month:`numeric`,day:`numeric`,...t?{timeZone:`UTC`}:{}};return n?.formatDate(a,o)??new Intl.DateTimeFormat(void 0,o).format(a)}if(t.format===`number`){let e=typeof r==`number`?r:Number(r);return Number.isFinite(e)?n?.formatNumber(e)??new Intl.NumberFormat().format(e):s8(r)??i}return s8(r)??i}function l8({hit:e,field:n,className:r}){let a=c8(e,n,_t(o8));return a?n.format===`badge`||n.format===`content_type`?t(i,{className:r,children:a}):t(`span`,{className:r,children:a}):null}function u8({hit:e,onOpenHit:r,compact:i=!1}){let{t:a}=K();return r?i?t(We,{description:a(`agent.openDocument`),asChild:!0,children:t(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":a(`agent.openDocument`),onClick:()=>r(e),children:t(Og,{className:`size-4`})})}):n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(e),children:[t(Og,{className:`size-4`}),a(`agent.openDocument`)]}):null}function d8(e,t){if(t.source!==`property`||!t.field)return;let n=s8(a8(e,t.field));if(n)try{let e=new URL(n,typeof window>`u`?`https://localhost`:window.location.origin);return e.protocol===`http:`||e.protocol===`https:`?e.toString():void 0}catch{return}}const f8=new WeakMap,p8=[2e3,4e3,8e3];function m8(e){let t=f8.get(e);if(t)return t;let n=new Map;return f8.set(e,n),n}function h8(e,t,n){let r=m8(e),i=r.get(t);if(i)return i;let a=n().finally(()=>{r.delete(t)});return r.set(t,a),a}function g8({hit:e,media:n,resolveMedia:r,className:i}){let a=n?d8(e,n):void 0,[o,s]=G(),[c,l]=G(!1),u=!a&&n?`${e.id}|${JSON.stringify(n)}`:void 0,d=W(e),f=W(n);d.current=e,f.current=n,H(()=>{if(s(void 0),l(!1),!u||!r)return;let e=!0,t,n=i=>{h8(r,u,async()=>r(d.current,f.current)).then(r=>{if(!e)return;if(r){s(r);return}let a=p8[i];a!==void 0&&(t=setTimeout(()=>n(i+1),a))}).catch(()=>{e&&l(!0)})};return n(0),()=>{e=!1,t&&clearTimeout(t)}},[u,r,a]);let p=c?void 0:a??o,m=n?.fit===`contain`?`object-contain`:`object-cover`;if(p)return t(`img`,{src:p,alt:``,className:`${m} ${i??``}`,onError:()=>l(!0)});let h=n?.source===`type_icon`?`type_icon`:n?.fallback??`type_icon`;return h===`none`?null:t(`div`,{className:`flex items-center justify-center bg-muted ${i??``}`,"aria-hidden":`true`,children:t(h===`placeholder`?O_:Kg,{className:`size-10 text-muted-foreground`})})}function _8({hit:e}){let n=e.annotation?.why_match??e.annotation?.answer??e.annotation?.excerpt;return n?t(`p`,{className:`text-sm text-info`,children:n}):null}function v8({hit:e,page:n,selection:r}){let{t:i}=K(),a=W(!1);return r?t(m,{checked:r.isSelected(e.id),"aria-label":i(`view.selectResult`,{name:e.document.name}),onClick:e=>{a.current=e.shiftKey,e.stopPropagation()},onCheckedChange:t=>{r.toggle(e,t===!0,{page:n,range:r.mode===`multiple`&&a.current}),a.current=!1}}):null}function y8({hit:e,fields:n}){return n?.length?t(`div`,{className:`flex flex-wrap gap-1`,children:n.map(n=>t(l8,{hit:e,field:n},`${n.field}-${n.label??``}`))}):null}function b8({hit:e,fields:r}){let i=_t(o8);return r?.length?t(`dl`,{className:`space-y-1 text-sm`,children:r.map(r=>{let a=c8(e,r,i);return a?n(`div`,{className:`flex gap-2`,children:[r.label&&t(`dt`,{className:`shrink-0 text-muted`,children:r.label}),t(`dd`,{className:`min-w-0 truncate`,children:a})]},`${r.field}-${r.label??``}`):null})}):null}function x8({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`divide-y divide-border rounded-md border`,children:r.map(s=>n(`article`,{className:`flex gap-4 p-4 ${o?.isSelected(s.id)?`bg-muted/40`:``}`,children:[o&&t(`div`,{className:`pt-1`,children:t(v8,{hit:s,page:r,selection:o})}),e.media&&t(g8,{hit:s,media:e.media,resolveMedia:a,className:`size-20 shrink-0 rounded-md`}),n(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[n(`div`,{children:[t(`h3`,{className:`font-semibold`,children:t(l8,{hit:s,field:e.title})}),e.subtitle&&t(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-sm text-muted`,children:e.subtitle.map(e=>t(l8,{hit:s,field:e},e.field))})]}),e.description&&t(`p`,{className:`line-clamp-3 text-sm text-muted-foreground`,children:t(l8,{hit:s,field:e.description})}),t(y8,{hit:s,fields:e.badges}),t(_8,{hit:s})]}),n(`div`,{className:`shrink-0 self-center`,children:[t(u8,{hit:s,onOpenHit:i,compact:!0}),t(I6,{hit:s})]})]},s.id))})}function S8({display:e,hits:r,isLoading:i,onOpenHit:a,sortOptions:o,currentSort:s,onSortChange:c,selection:l}){let{t:u}=K(),d=j6()?.actions.some(e=>e.placement===`row`)??!1,f=l?r.filter(e=>l.isSelected(e.id)).length:0,p=r.length>0&&f===r.length;return t(`div`,{className:`overflow-x-auto rounded-md border`,children:n(Le,{className:`w-full`,children:[t(Fe,{children:n(`tr`,{children:[l&&t(Re,{className:`w-0`,children:l.selectAll&&t(m,{checked:p?!0:f>0&&`indeterminate`,"aria-label":u(`view.selectPage`),onCheckedChange:e=>l.togglePage(r,e===!0)})}),e.columns.map(e=>{let n=e.sort_option?o?.find(t=>t.id===e.sort_option):void 0;if(!e.sortable||!n)return t(Re,{children:e.label??e.field},`${e.field}-${e.label??``}`);let r=s===n.id?n.sort[0]?.order===`desc`?`descending`:`ascending`:`none`;return t(Ae,{sortDirection:r,onSort:()=>c?.(n.id),disabled:i||!c,sortIndicator:e=>e===`ascending`?t(ph,{className:`size-3`,"aria-hidden":`true`}):e===`descending`?t(ih,{className:`size-3`,"aria-hidden":`true`}):t(Th,{className:`size-3 text-muted`,"aria-hidden":`true`}),children:e.label??e.field},`${e.field}-${e.label??``}`)}),(a||d)&&t(Re,{className:`w-0`,children:t(`span`,{className:`sr-only`,children:u(d?`view.actions`:`agent.openDocument`)})})]})}),t(Pe,{isLoading:i&&r.length===0,columns:e.columns.length+ +!!l+(a||d?1:0),children:r.map(i=>n(`tr`,{className:l?.isSelected(i.id)?`bg-muted/40`:void 0,children:[l&&t(`td`,{className:`w-0`,children:t(v8,{hit:i,page:r,selection:l})}),e.columns.map(e=>t(`td`,{style:e.width?{width:e.width}:void 0,children:t(l8,{hit:i,field:e})},`${i.id}-${e.field}`)),(a||d)&&t(`td`,{className:`w-0 whitespace-nowrap text-end`,children:n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(u8,{hit:i,onOpenHit:a,compact:!0}),t(I6,{hit:i})]})})]},i.id))})]})})}const C8={2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`md:grid-cols-2 xl:grid-cols-4`,5:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-5`,6:`md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-6`};function w8({hit:e,configuration:r,onOpenHit:i,resolveMedia:a,selection:o,page:p}){let m=j6()?.actions.some(e=>e.placement===`row`)??!1;return n(s,{className:`relative flex h-full min-w-0 flex-col overflow-hidden ${o?.isSelected(e.id)?`ring-2 ring-primary`:``}`,children:[o&&t(`div`,{className:`absolute start-2 top-2 z-10 rounded bg-background/80 p-1`,children:t(v8,{hit:e,page:p,selection:o})}),r.media&&t(g8,{hit:e,media:r.media,resolveMedia:a,className:`h-40 w-full border-b`}),n(d,{className:`gap-2 p-4`,children:[t(y8,{hit:e,fields:r.badges}),t(f,{className:`truncate text-base`,children:t(l8,{hit:e,field:r.title})}),r.description&&t(l,{className:`line-clamp-3`,children:t(l8,{hit:e,field:r.description})})]}),n(c,{className:`flex-1 p-4 pt-0`,children:[t(b8,{hit:e,fields:r.fields}),t(_8,{hit:e})]}),(i||m)&&n(u,{className:`justify-end p-4 pt-0`,children:[t(u8,{hit:e,onOpenHit:i}),t(I6,{hit:e})]})]})}function T8({display:e,hits:n,onOpenHit:r,resolveMedia:i,selection:a}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${C8[e.columns??3]}`,children:n.map(o=>t(w8,{hit:o,configuration:e,onOpenHit:r,resolveMedia:i,selection:a,page:n},o.id))})}function E8({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${C8[e.columns??4]}`,children:r.map(l=>n(s,{className:`relative overflow-hidden ${o?.isSelected(l.id)?`ring-2 ring-primary`:``}`,children:[o&&t(`div`,{className:`absolute start-2 top-2 z-10 rounded bg-background/80 p-1`,children:t(v8,{hit:l,page:r,selection:o})}),t(g8,{hit:l,media:e.media,resolveMedia:a,className:`aspect-square w-full border-b`}),n(c,{className:`space-y-2 p-3`,children:[t(`h3`,{className:`truncate font-semibold`,children:t(l8,{hit:l,field:e.title})}),e.caption&&t(`div`,{className:`space-y-1 text-sm text-muted`,children:e.caption.map(e=>t(`div`,{className:`truncate`,children:t(l8,{hit:l,field:e})},e.field))}),n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(u8,{hit:l,onOpenHit:i}),t(I6,{hit:l})]})]})]},l.id))})}function D8({display:e,hits:r,onOpenHit:a,resolveMedia:o,selection:s}){let c=new Map;for(let t of r){let n=s8(a8(t,e.group_by))??``;c.set(n,[...c.get(n)??[],t])}let l=e.columns?.length?[...e.columns].sort((e,t)=>(e.order??0)-(t.order??0)):[...c.keys()].sort().map(e=>({value:e,label:e||`—`}));return t(`div`,{className:`flex min-w-max gap-4 overflow-x-auto pb-2`,children:l.map(l=>{let u=c.get(l.value)??[];return n(`section`,{className:`w-80 shrink-0 space-y-3 rounded-lg bg-muted/40 p-3`,children:[n(`div`,{className:`flex items-center justify-between gap-2`,children:[t(`h3`,{className:`font-semibold`,children:l.label}),t(i,{children:u.length})]}),t(`div`,{className:`space-y-3`,children:u.map(n=>t(w8,{hit:n,configuration:e.card,onOpenHit:a,resolveMedia:o,selection:s,page:r},n.id))})]},l.value)})})}function O8(e,n,r,i,a,o,s,c,l){return e.type===`table`?t(S8,{display:e,hits:n,isLoading:r,onOpenHit:i,sortOptions:o,currentSort:s,onSortChange:c,selection:l}):e.type===`cards`?t(T8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`gallery`?t(E8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`board`?t(D8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):t(x8,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l})}function k8({configuration:e,definition:n,request:r,result:i,isLoading:a,onSortChange:o,onOpenHit:s,resolveMedia:c,selection:l}){let{t:u}=K(),d=Zt();return!a&&i.hits.length===0?t(`p`,{className:`py-12 text-center text-sm text-muted`,children:u(`filter.noResultsFound`)}):t(o8.Provider,{value:d,children:O8(e,i.hits,a,s,c,n.results?.sort_options,n8(r,i,n.results?.default_sort),o,l)})}Q();function A8(e,t){return t?`text`:e===`number`?`number`:e===`date`?`date`:`text`}function j8(e){let[t=``,n=``]=(e[0]??``).split(`..`,2);return[t,n]}function M8(e,t){return e||t?[`${e}..${t}`]:[]}function N8(e,t){return t?e.join(`, `):e[0]??``}function P8(e,t){return t?e.split(`,`).map(e=>e.trim()).filter(Boolean):e.trim()?[e.trim()]:[]}function F8({term:e,values:n,isLoading:r,onChange:i}){let a=W(!1),o=W(void 0),[s,c]=G(()=>N8(n,e.multiple)),l=N8(n,e.multiple);return H(()=>{a.current&&o.current===l||c(l),o.current=void 0},[l]),t(L,{label:e.label,children:t(te,{type:A8(e.type,e.multiple),name:`view-key-term-${e.id}`,autoComplete:`off`,value:s,onFocus:()=>{a.current=!0},onBlur:()=>{a.current=!1;let t=P8(s,e.multiple);c(N8(t,e.multiple))},onChange:t=>{c(t);let n=P8(t,e.multiple);o.current=N8(n,e.multiple),i(n)},placeholder:e.label,disabled:r})})}function I8({configuration:e,query:r,keyTerms:i,isLoading:a,onQueryChange:s,onKeyTermsChange:c,onSubmit:l}){let{t:u}=K(),d=vt(),f=e.key_terms?.filter(e=>e.operator!==`range`)??[],p=e.key_terms?.filter(e=>e.operator===`range`)??[];return n(`form`,{className:`flex flex-col gap-3`,"aria-label":u(`layout.search`),autoComplete:`off`,onSubmit:e=>{e.preventDefault(),l()},children:[n(`div`,{className:`flex items-center gap-2`,children:[t(`label`,{htmlFor:d,className:`sr-only`,children:u(`layout.search`)}),t(te,{id:d,name:`view-query`,autoComplete:`off`,value:r,onChange:s,placeholder:e.placeholder??u(`store.searchPlaceholder`),disabled:a}),n(o,{type:`submit`,disabled:a,className:`shrink-0`,children:[t(jy,{className:`size-4`}),u(a?`store.searching`:`store.search`)]})]}),e.key_terms&&e.key_terms.length>0&&n(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[f.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${p.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.searchFields`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2 ${p.length===0?`lg:grid-cols-4`:``}`,children:f.map(e=>t(F8,{term:e,values:i[e.id]??[],isLoading:a,onChange:t=>c(e.id,t)},e.id))})]}),p.length>0&&n(`fieldset`,{className:`rounded-md border border-mixer-muted/30 bg-mixer-muted/5 p-3 ${f.length===0?`lg:col-span-2`:``}`,children:[t(`legend`,{className:`px-1 text-xs font-medium text-muted`,children:u(`view.ranges`)}),t(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:p.map(e=>{let[r,o]=j8(i[e.id]??[]),s=e.type===`number`?`number`:e.type===`date`?`date`:`text`;return n(`fieldset`,{className:`min-w-0`,children:[t(`legend`,{className:`mb-1 text-sm font-medium`,children:e.label}),n(`div`,{className:`grid grid-cols-2 gap-2`,children:[t(te,{type:s,name:`view-key-term-${e.id}-from`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.from`)}`,value:r,onChange:t=>c(e.id,M8(t.trim(),o)),placeholder:u(`view.from`),disabled:a}),t(te,{type:s,name:`view-key-term-${e.id}-to`,autoComplete:`off`,"aria-label":`${e.label}: ${u(`view.to`)}`,value:o,onChange:t=>c(e.id,M8(r,t.trim())),placeholder:u(`view.to`),disabled:a})]})]},e.id)})})]})]})]})}Q();const L8={id:`default`,label:`Results`,type:`list`,title:{field:`name`},subtitle:[{field:`type.name`,format:`content_type`},{field:`location`,format:`location`}],description:{field:`description`}};function R8(e){return!e||typeof window>`u`?{}:J6(window.location.search)}function z8(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function B8(e){let t=Object.fromEntries(Object.entries(e).map(([e,t])=>[e,t.trim()]).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function V8(e){let{client:n}=q(),r=_t(J0),i=V(t=>n.views.execute(e.viewId,t),[n,e.viewId]),a=V(async(e,t)=>{if(t.source!==`content_thumbnail`)return;let r=e.document.content;try{let t=await n.objects.getRenditionSafe(e.id,r?.type,{format:hn.jpeg,max_hw:512,generate_if_missing:!1,sign_url:!0});if(t?.status===`found`&&t.renditions?.length)return t.renditions[0]}catch{}if(r?.source&&r.type?.startsWith(`image/`))return(await n.files.getDownloadUrl(r.source)).url},[n]),o=e=>r!==void 0&&e.some(e=>r.hasPermission(e));return t(U8,{...e,execute:i,resolveMedia:e.resolveMedia??a,client:n,canDelete:o([bn.content_delete,bn.content_admin,bn.content_superadmin]),canWrite:o([bn.content_write,bn.content_admin,bn.content_superadmin])})}function H8({execute:e,...n}){return e?t(U8,{...n,execute:e},n.viewId):t(V8,{...n},n.viewId)}function U8({execute:e,renderers:r,contributions:i,onOpenHit:a,resolveMedia:s,syncUrl:c=!0,showHeader:l=!0,className:u,client:d,canDelete:f=!1,canWrite:p=!1}){let{t:m}=K(),h=W(e);h.current=e;let g=W(0),[_,v]=G(()=>R8(c)),[y,b]=G(_.query??``),[x,S]=G(_.key_terms??{}),[C,w]=G(),[T,E]=G(!0),[D,O]=G(),[k,A]=G({}),j=W(void 0),N=V(()=>{j.current=void 0,A({})},[]),P=V((e,t,n=!1)=>{let r=++g.current;return n||N(),v(e),t&&c&&r8(e),E(!0),O(void 0),h.current(e).then(t=>{if(r===g.current){let n=t8(e,t);v(n),c&&r8(n),w(t)}}).catch(e=>{r===g.current&&O(e instanceof Error?e:Error(String(e)))}).finally(()=>{r===g.current&&E(!1)})},[N,c]),F=V(()=>{let e=R8(c);return b(e.query??``),S(e.key_terms??{}),P(e,!1)},[P,c]);H(()=>(F(),()=>{g.current+=1}),[F]),H(()=>{if(!c||typeof window>`u`)return;let e=()=>void F();return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[F,c]);let I=C?.definition,L=U(()=>[...I?.navigation??[]].sort((e,t)=>(e.order??0)-(t.order??0)),[I?.navigation]),ee=I?.results,R=ee?.selection,te=C?.display??_.display??ee?.default_display,ne=ee?.displays.find(e=>e.id===te)??L8,re=C?n8(_,C,ee?.default_sort):_.sort,ie=e=>{P(e,!0)},ae=(e,t)=>{let n=z8({..._.navigation??{},[e.id]:t});ie({..._,navigation:n,offset:void 0})},se=(e,t)=>{let n=B8({..._.navigation_queries??{},[e.id]:t});ie({..._,navigation_queries:n,offset:void 0})},ce=()=>{ie({..._,query:y.trim()||void 0,key_terms:z8(x),offset:void 0})},le=U(()=>{if(!R)return;let e=Object.keys(k);return{mode:R.mode,selectAll:R.mode===`multiple`&&R.select_all===`page`,selectedIds:e,selectedHits:e.map(e=>k[e]).filter(e=>e!==void 0),isSelected:e=>k[e]!==void 0,toggle:(e,t,n)=>{A(r=>{if(!t){let t={...r};return delete t[e.id],t}if(R.mode===`single`)return j.current=e.id,{[e.id]:e};let i={...r,[e.id]:e};if(n?.range&&n.page&&j.current){let t=n.page.findIndex(e=>e.id===j.current),r=n.page.findIndex(t=>t.id===e.id);if(t>=0&&r>=0){let e=Math.min(t,r),a=Math.max(t,r);for(let t of n.page.slice(e,a+1))i[t.id]=t}}return j.current=e.id,i})},togglePage:(e,t)=>{R.mode===`multiple`&&A(n=>{let r={...n};for(let n of e)t?r[n.id]=n:delete r[n.id];return r})},clear:N}},[N,k,R]);if(!C&&T)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center`,children:t(je,{size:`xl`})});if(!C||!I)return t(`div`,{className:`flex h-full min-h-48 items-center justify-center p-4`,children:t(M,{title:m(`store.searchFailed`),action:()=>void F(),actionLabel:m(`agent.retry`),children:m(`store.searchFailed`)})});let ue=I.search?.renderer?r?.search?.[I.search.renderer]??I8:I8,de=ne.renderer?r?.results?.[ne.renderer]??k8:k8,fe=L.length>0&&I.layout?.navigation_position!==`top`,pe=I.layout?.mode===`worklist`,me=_.offset??0,he=_.limit??ne.page_size??20,ge=me>0,_e=me+C.hits.length<C.total,ve=L.map(e=>{let n=C.navigation[e.id]??{id:e.id,selected:[],nodes:[]},i=e.renderer?r?.navigation?.[e.renderer]??V6:V6;return t(i,{configuration:e,result:n,isLoading:T,onChange:t=>ae(e,t),onQueryChange:e.source===`collection`?t=>se(e,t):void 0},e.id)}),ye=()=>P(_,!1,!0),be=n(ar,{className:u,children:[l&&t($1,{title:I.name,description:I.description}),n(ar.Fixed,{heightClass:`h-auto`,className:`space-y-3 border-b p-3`,children:[I.search&&t(ue,{configuration:I.search,query:y,keyTerms:x,isLoading:T,onQueryChange:b,onKeyTermsChange:(e,t)=>S(n=>({...n,[e]:t})),onSubmit:ce}),L.length>0&&I.layout?.navigation_position===`top`&&t(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-4`,children:ve})]}),t(ar.Body,{className:`p-0`,children:n(`div`,{className:fe?pe?`grid min-h-full lg:grid-cols-[minmax(0,1fr)_18rem]`:`grid min-h-full lg:grid-cols-[18rem_minmax(0,1fr)]`:`min-h-full`,children:[fe&&t(`aside`,{className:pe?`space-y-5 border-b p-4 lg:order-2 lg:border-s lg:border-b-0`:`space-y-5 border-b p-4 lg:border-e lg:border-b-0`,children:ve}),n(`main`,{className:`min-w-0 space-y-4 p-4 ${pe?`lg:order-1`:``}`,children:[D&&t(M,{title:m(`store.searchFailed`),action:()=>void P(_,!1),actionLabel:m(`agent.retry`),children:m(`store.searchFailed`)}),C.search.warnings.length>0&&t(oe,{status:`warning`,title:m(`view.warning`),children:t(`ul`,{className:`list-disc space-y-1 ps-4`,children:C.search.warnings.map(e=>t(`li`,{children:e.message},`${e.code}-${e.path??``}`))})}),n(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[n(`div`,{className:`flex items-center gap-2 text-sm text-muted`,children:[t(`span`,{children:m(`view.resultsCount`,{count:C.total})}),T&&t(je,{size:`sm`})]}),n(`div`,{className:`flex flex-wrap items-center gap-3`,children:[t(F6,{selection:le,page:C.hits,showSelectPage:ne.type!==`table`}),ee?.allow_display_switch&&ee.displays.length>1&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:m(`view.display`)}),t(we,{options:ee.displays,value:ne,onChange:e=>void P({..._,display:e.id,offset:void 0},!0,!0),optionLabel:e=>e.label,by:`id`,disabled:T,"aria-label":m(`view.display`),className:`min-w-36`})]}),ee?.sort_options&&ee.sort_options.length>0&&n(`div`,{className:`flex items-center gap-2`,children:[t(`span`,{className:`text-sm text-muted`,children:m(`view.sort`)}),t(we,{options:ee.sort_options,value:ee.sort_options.find(e=>e.id===re),onChange:e=>void P({..._,sort:e.id,offset:void 0},!0,!0),optionLabel:e=>e.label,by:`id`,disabled:T,"aria-label":m(`view.sort`),className:`min-w-44`})]})]})]}),t(R6,{definition:I,request:_,result:C,contribution:i?.drop,canWrite:p,refresh:ye,children:t(de,{configuration:ne,definition:I,request:_,result:C,isLoading:T,onSortChange:e=>void P({..._,sort:e,offset:void 0},!0,!0),onOpenHit:a,resolveMedia:s,selection:le})}),(ge||_e)&&n(`nav`,{className:`flex items-center justify-center gap-2`,"aria-label":m(`view.pagination`),children:[n(o,{type:`button`,variant:`outline`,disabled:!ge||T,onClick:()=>void P({..._,offset:Math.max(0,me-he)||void 0},!0,!0),children:[t(sh,{className:`size-4 cn-rtl-flip`}),m(`grounded.previousPage`)]}),n(o,{type:`button`,variant:`outline`,disabled:!_e||T,onClick:()=>void P({..._,offset:me+he},!0,!0),children:[m(`grounded.nextPage`),t(uh,{className:`size-4 cn-rtl-flip`})]})]})]})]})})]});return t(P6,{definition:I,request:_,result:C,selection:le,contributions:i,client:d,canDelete:f,refresh:ye,children:be})}fY(),yY(),xY(),JY();export{Yp as ActivitiesDoc,Zp as ActivityDoc,e6 as AddToCollectionAction,Q3 as AddToCollectionActionComponent,Xb as AgentApprovalModeSelector,dC as AgentChart,MJ as AgentChatFixtureReplay,SC as AgentChatPlaybackControls,St as AgentResourceResolverProvider,VZ as AgentRunnerFacetsNav,W0 as AllOf,nW as AnimatedThinkingDots,U0 as AnyOf,PZ as ApiKeyAvatar,AH as AskUserWidget,z0 as AudioPanel,j4 as BrowseCollectionView,a6 as ChangeTypeAction,r6 as ChangeTypeActionComponent,L4 as CollectionIcon,YZ as CollectionsFacetsNav,I4 as CollectionsTable,jH as ConfirmationWidget,q$ as ContentDispositionButton,q4 as ContentObjectTypesSearch,z4 as ContentObjectTypesTable,s4 as ContentOverview,P4 as CreateCollectionForm,F4 as CreateCollectionModal,B4 as CreateOrUpdateTypeModal,V6 as DefaultViewNavigation,k8 as DefaultViewResults,I8 as DefaultViewSearch,l6 as DeleteObjectsAction,s6 as DeleteObjectsActionComponent,u6 as DeleteObjectsFromCollectionsAction,K2 as DocumentEditingPanel,G2 as DocumentEditingWorkspace,T$ as DocumentGridView,C$ as DocumentIcon,S$ as DocumentIconSkeleton,H3 as DocumentInput,U3 as DocumentPreviewPanel,E$ as DocumentSearch,G$ as DocumentSearchProvider,D4 as DocumentSearchResults,E4 as DocumentSearchResultsWithDropZone,RQ as DocumentSelection,HQ as DocumentSelectionProvider,B$ as DocumentTable,x$ as DocumentTableColumn,w$ as DocumentTableView,L$ as DocumentUploadModal,aQ as DocumentsFacetsNav,L3 as EditCollectionView,oQ as EnvironmentFacet,p6 as ExportPropertiesAction,d6 as ExportPropertiesComponent,K3 as ExportPropertiesModal,G3 as ExportTypes,N$ as FileUploadAction,$1 as GenericPageNavHeader,a0 as GroundedExtractionPanel,o0 as GroundedExtractionView,nZ as Header,B0 as ImagePanel,h3 as IntakePolicyEditor,uQ as InteractionsFacetsNav,NJ as JumpingDots,hG as MESSAGE_STYLES,N0 as MagicPdfView,HJ as McpConnectionsActionMenu,BJ as McpConnectionsButton,zJ as McpConnectionsDialog,VJ as McpConnectionsInlineList,_G as MessageItem,F1 as MessagesContainer,A1 as ModernAgentConversation,e0 as NotFoundView,H0 as OAuthProviderConnectButton,E3 as ObjectSchemaEditor,V4 as ObjectTypeSearch,H4 as ObjectTypeSearchContext,j3 as ObjectTypeSearchProvider,y6 as ObjectsActionContextProvider,G1 as PanelErrorBoundary,ZX as PayloadBuilder,$X as PayloadBuilderProvider,XX as PayloadBuilderStore,QX as PayloadContext,lY as PdfDocumentRenderer,nY as PdfPageRenderer,pY as PdfPageSlider,cY as PdfThumbnailList,fQ as ProcessDefinitionsFacetsNav,mQ as ProcessRunsFacetsNav,yQ as PromptsFacetsNav,q2 as PropertiesEditorModal,rW as PulsatingCircle,aW as PulsingMessageLoader,hO as RemoteMcpConnectionButton,g6 as RemoveFromCollectionAction,m6 as RemoveFromCollectionActionComponent,q1 as RowErrorBoundary,TQ as RunsFacetsNav,L2 as SaveVersionConfirmModal,D$ as SearchContext,Z0 as SecureButton,Q0 as SecureSidebarItem,z3 as SelectCollection,N4 as SelectContentType,A3 as SelectContentTypeModal,Y$ as SelectDocument,B3 as SelectDocumentModal,L1 as SelectEnvironment,B1 as SelectModel,V1 as SelectTrainingModel,C6 as SelectionActions,rY as SharedPdfProvider,P3 as SharedPropsEditor,aY as SimplePdfPage,bY as SimplePdfViewer,a1 as SkillWidgetProvider,AG as StreamingMessage,EQ as StringFacet,DQ as StringListFacet,F3 as SyncMemberHeadsToggle,M3 as TableLayoutEditor,oW as ThinkingBar,xW as ThinkingMessages,kQ as TypeFacet,HZ as TypeRegistry,WZ as TypeRegistryProvider,iW as TypedDots,qY as UniversalDocumentViewer,w6 as UploadObjectsButton,k6 as UserAvatar,AZ as UserInfo,X0 as UserPermissionProvider,K0 as UserPermissions,J0 as UserPermissionsContext,lZ as VInteractionFacet,pZ as VStringFacet,XZ as VTypeFacet,LZ as VUserFacet,sC as VegaLiteChart,H1 as VertesiaErrorBoundary,V0 as VideoPanel,P6 as ViewActionsProvider,F6 as ViewActionsToolbar,H8 as ViewExperience,I6 as ViewRowActions,L0 as WEB_SUPPORTED_AUDIO_FORMATS,F0 as WEB_SUPPORTED_IMAGE_FORMATS,I0 as WEB_SUPPORTED_VIDEO_FORMATS,sW as WavyThinking,Y1 as WidgetErrorBoundary,jQ as WorkflowDefinitionsFacetsNav,FQ as WorkflowExecutionsFacetsNav,LQ as WorkflowRulesFacetsNav,t8 as canonicalizeViewState,fC as clampPlaybackCursor,LJ as countConnectedActiveGroups,BZ as createAgentRunnerFilterHandler,H2 as createDocumentChangeSummaryPrompt,V2 as createDocumentReconcilePrompt,gC as createPlaybackState,cZ as createSearchQueryKeyGuard,oZ as filterValueToQueryValue,R0 as formatDuration,c8 as formatViewFieldValue,RJ as getConnectedActiveGroupLabels,$W as getContentObjectDownloadName,hC as getNextUserTurnIndex,pC as getPlaybackCursorIndex,mC as getPreviousUserTurnIndex,a8 as getViewFieldValue,u$ as getWorkflowStatusColor,d$ as getWorkflowStatusName,t2 as invalidateTypeCache,vC as isAgentChatPlaybackAvailable,yC as isAgentChatPlaybackEnabled,G0 as isAnyOf,$Q as isCsv,FJ as isGroupDisabled,e$ as isImage,bC as isLocalhostAgentChatPlaybackAvailable,xC as isLocalhostAgentChatPlaybackEnabled,t$ as isPdf,r$ as isPreviewableAsPdf,lC as isRechartsSpec,cC as isVegaLiteSpec,n$ as isVideo,J6 as parseViewState,i$ as printElementToPdf,r8 as replaceViewStateInUrl,e2 as resolveTypeCached,n8 as resolveViewSort,s$ as retrieveRendition,Q6 as serializeViewState,W1 as setErrorBoundaryComponent,sZ as setSearchQueryValue,c$ as shortId,l$ as shortenString,N3 as stringifyTableLayout,IJ as toggleGroupDisabled,aZ as unwrapFilterOptionValue,Gt as useAgentResourceResolver,zZ as useAgentRunnerFilterGroups,qZ as useCollectionsFilterGroups,JZ as useCollectionsFilterHandler,rQ as useDocumentFilterGroups,iQ as useDocumentFilterHandler,O$ as useDocumentSearch,j$ as useDocumentSearchCount,BQ as useDocumentSelection,R$ as useDocumentUploadHandler,eG as useDownloadFile,xZ as useFetchApiKeyInfo,bZ as useFetchGroupInfo,yZ as useFetchUserInfo,r0 as useGroundedExtractionAvailable,i0 as useGroundedSummary,cQ as useInteractionsFilterGroups,lQ as useInteractionsFilterHandler,PJ as useMcpConnections,mO as useOAuthPopup,VQ as useOptionalDocumentSelection,eZ as usePayloadBuilder,dQ as useProcessDefinitionsFilterGroups,pQ as useProcessRunsFilterGroups,_Q as usePromptsFilterGroups,vQ as usePromptsFilterHandler,CQ as useRunsFilterGroups,wQ as useRunsFilterHandler,U4 as useSearch,G4 as useSearchCount,iY as useSharedPdf,I$ as useSmartFileUploadProcessing,GZ as useTypeRegistry,Y0 as useUserPermissions,j6 as useViewActions,k$ as useWatchDocumentSearchFacets,A$ as useWatchDocumentSearchResult,W4 as useWatchSearchResult,AQ as useWorkflowDefinitionsFilterGroups,NQ as useWorkflowExecutionsFilterGroups,PQ as useWorkflowExecutionsFilterHandler,IQ as useWorkflowRulesFilterGroups};
1406
1406
  //# sourceMappingURL=vertesia-ui-features.js.map