@vertesia/ui 1.6.0-dev.20260918.090710Z → 1.6.0-dev.20260918.115658Z

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 (102) hide show
  1. package/lib/features/oauth/McpConnectionsButton.d.ts +2 -2
  2. package/lib/features/oauth/McpConnectionsButton.d.ts.map +1 -1
  3. package/lib/features/oauth/McpConnectionsButton.js +9 -7
  4. package/lib/features/oauth/McpConnectionsButton.js.map +1 -1
  5. package/lib/features/oauth/McpConnectionsDialog.d.ts.map +1 -1
  6. package/lib/features/oauth/McpConnectionsDialog.js +7 -3
  7. package/lib/features/oauth/McpConnectionsDialog.js.map +1 -1
  8. package/lib/features/oauth/useMcpConnections.d.ts +4 -2
  9. package/lib/features/oauth/useMcpConnections.d.ts.map +1 -1
  10. package/lib/features/oauth/useMcpConnections.js +15 -9
  11. package/lib/features/oauth/useMcpConnections.js.map +1 -1
  12. package/lib/i18n/locales/ar.json +1 -0
  13. package/lib/i18n/locales/de.json +1 -0
  14. package/lib/i18n/locales/en.json +1 -0
  15. package/lib/i18n/locales/es.json +1 -0
  16. package/lib/i18n/locales/fr.json +1 -0
  17. package/lib/i18n/locales/it.json +1 -0
  18. package/lib/i18n/locales/ja.json +1 -0
  19. package/lib/i18n/locales/ko.json +1 -0
  20. package/lib/i18n/locales/pt.json +1 -0
  21. package/lib/i18n/locales/ru.json +1 -0
  22. package/lib/i18n/locales/tr.json +1 -0
  23. package/lib/i18n/locales/zh-TW.json +1 -0
  24. package/lib/i18n/locales/zh.json +1 -0
  25. package/lib/session/auth/oauth.d.ts.map +1 -1
  26. package/lib/session/auth/oauth.js +3 -0
  27. package/lib/session/auth/oauth.js.map +1 -1
  28. package/lib/shell/apps/AppInstallationProvider.d.ts +4 -4
  29. package/lib/vertesia-ui-features.js +13 -13
  30. package/lib/vertesia-ui-features.js.map +1 -1
  31. package/lib/vertesia-ui-i18n.4e0lpFmb.chunk.js +5 -0
  32. package/lib/vertesia-ui-i18n.4e0lpFmb.chunk.js.map +1 -0
  33. package/lib/vertesia-ui-i18n.BWrAGXBo.chunk.js +5 -0
  34. package/lib/vertesia-ui-i18n.BWrAGXBo.chunk.js.map +1 -0
  35. package/lib/vertesia-ui-i18n.BWsksQSO.chunk.js +5 -0
  36. package/lib/vertesia-ui-i18n.BWsksQSO.chunk.js.map +1 -0
  37. package/lib/vertesia-ui-i18n.BtxcuCei.chunk.js +5 -0
  38. package/lib/vertesia-ui-i18n.BtxcuCei.chunk.js.map +1 -0
  39. package/lib/vertesia-ui-i18n.Bz8LMNmG.chunk.js +5 -0
  40. package/lib/vertesia-ui-i18n.Bz8LMNmG.chunk.js.map +1 -0
  41. package/lib/vertesia-ui-i18n.CSRfYYZ3.chunk.js +5 -0
  42. package/lib/vertesia-ui-i18n.CSRfYYZ3.chunk.js.map +1 -0
  43. package/lib/vertesia-ui-i18n.D0aB839H.chunk.js +5 -0
  44. package/lib/vertesia-ui-i18n.D0aB839H.chunk.js.map +1 -0
  45. package/lib/vertesia-ui-i18n.Dn3ZhpYw.chunk.js +5 -0
  46. package/lib/vertesia-ui-i18n.Dn3ZhpYw.chunk.js.map +1 -0
  47. package/lib/vertesia-ui-i18n._vo6dQOd.chunk.js +5 -0
  48. package/lib/vertesia-ui-i18n._vo6dQOd.chunk.js.map +1 -0
  49. package/lib/vertesia-ui-i18n.fNnmGqlI.chunk.js +5 -0
  50. package/lib/vertesia-ui-i18n.fNnmGqlI.chunk.js.map +1 -0
  51. package/lib/vertesia-ui-i18n.js +2 -2
  52. package/lib/vertesia-ui-i18n.lcqwXwSM.chunk.js +5 -0
  53. package/lib/vertesia-ui-i18n.lcqwXwSM.chunk.js.map +1 -0
  54. package/lib/vertesia-ui-i18n.snVd8TDP.chunk.js +5 -0
  55. package/lib/vertesia-ui-i18n.snVd8TDP.chunk.js.map +1 -0
  56. package/lib/vertesia-ui-session.js +1 -1
  57. package/lib/vertesia-ui-session.js.map +1 -1
  58. package/package.json +7 -7
  59. package/src/features/oauth/McpConnectionsButton.test.tsx +56 -0
  60. package/src/features/oauth/McpConnectionsButton.tsx +9 -6
  61. package/src/features/oauth/McpConnectionsDialog.tsx +14 -5
  62. package/src/features/oauth/useMcpConnections.test.ts +10 -0
  63. package/src/features/oauth/useMcpConnections.ts +18 -10
  64. package/src/i18n/locales/ar.json +1 -0
  65. package/src/i18n/locales/de.json +1 -0
  66. package/src/i18n/locales/en.json +1 -0
  67. package/src/i18n/locales/es.json +1 -0
  68. package/src/i18n/locales/fr.json +1 -0
  69. package/src/i18n/locales/it.json +1 -0
  70. package/src/i18n/locales/ja.json +1 -0
  71. package/src/i18n/locales/ko.json +1 -0
  72. package/src/i18n/locales/pt.json +1 -0
  73. package/src/i18n/locales/ru.json +1 -0
  74. package/src/i18n/locales/tr.json +1 -0
  75. package/src/i18n/locales/zh-TW.json +1 -0
  76. package/src/i18n/locales/zh.json +1 -0
  77. package/src/session/auth/oauth.test.ts +2 -0
  78. package/src/session/auth/oauth.ts +3 -0
  79. package/lib/vertesia-ui-i18n.B3NFclwl.chunk.js +0 -5
  80. package/lib/vertesia-ui-i18n.B3NFclwl.chunk.js.map +0 -1
  81. package/lib/vertesia-ui-i18n.BWSrNIxc.chunk.js +0 -5
  82. package/lib/vertesia-ui-i18n.BWSrNIxc.chunk.js.map +0 -1
  83. package/lib/vertesia-ui-i18n.BWvWeB1p.chunk.js +0 -5
  84. package/lib/vertesia-ui-i18n.BWvWeB1p.chunk.js.map +0 -1
  85. package/lib/vertesia-ui-i18n.BZCXvTC1.chunk.js +0 -5
  86. package/lib/vertesia-ui-i18n.BZCXvTC1.chunk.js.map +0 -1
  87. package/lib/vertesia-ui-i18n.BbJMvFZW.chunk.js +0 -5
  88. package/lib/vertesia-ui-i18n.BbJMvFZW.chunk.js.map +0 -1
  89. package/lib/vertesia-ui-i18n.CE5ldwpt.chunk.js +0 -5
  90. package/lib/vertesia-ui-i18n.CE5ldwpt.chunk.js.map +0 -1
  91. package/lib/vertesia-ui-i18n.CMC0IShY.chunk.js +0 -5
  92. package/lib/vertesia-ui-i18n.CMC0IShY.chunk.js.map +0 -1
  93. package/lib/vertesia-ui-i18n.CkcRqBKU.chunk.js +0 -5
  94. package/lib/vertesia-ui-i18n.CkcRqBKU.chunk.js.map +0 -1
  95. package/lib/vertesia-ui-i18n.D-Mq1sw_.chunk.js +0 -5
  96. package/lib/vertesia-ui-i18n.D-Mq1sw_.chunk.js.map +0 -1
  97. package/lib/vertesia-ui-i18n.DkK68-A-.chunk.js +0 -5
  98. package/lib/vertesia-ui-i18n.DkK68-A-.chunk.js.map +0 -1
  99. package/lib/vertesia-ui-i18n.XE_dcCg6.chunk.js +0 -5
  100. package/lib/vertesia-ui-i18n.XE_dcCg6.chunk.js.map +0 -1
  101. package/lib/vertesia-ui-i18n.qgNqMPvK.chunk.js +0 -5
  102. package/lib/vertesia-ui-i18n.qgNqMPvK.chunk.js.map +0 -1
@@ -1282,7 +1282,7 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
1282
1282
  .agent-markdown tbody tr:hover {
1283
1283
  background: transparent;
1284
1284
  }
1285
- `}),s===`stacked`&&t(`div`,{className:z(`sticky top-0 z-10`,b&&`hidden`),children:t(iq,{workstreams:pe,activeWorkstream:R,onSelectWorkstream:_e,count:ye,completionStatus:at})}),ce&&R!==`all`&&me&&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:I(`agent.backToMainAgent`),"aria-label":I(`agent.backToMainAgent`),onClick:ve,children:t(jm,{className:`size-4`,"aria-hidden":`true`})}),t(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:me})]})}),be.length===0&&He.length===0&&!Ae&&!(ce&&Qe)?R===`all`&&Xe?t(`div`,{className:`flex-1 px-2 py-6 sm:px-4`,children:t(Xq,{label:I(`agent.preparing`),timestamp:ke.current,className:x})}):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:I(R===`all`?`agent.waitingForAgentResponse`:`agent.noMessagesInWorkstream`)})}):n(`div`,{className:z(`flex-1 flex flex-col justify-start w-full max-w-full`,ce?`gap-6 px-2 py-6 sm:px-4`:`gap-3 pb-4`,S),children:[Me&&t(Yq,{data:E,schema:D,title:O,template:k,prependFriendlyMessage:T,timestamp:be[0]?.timestamp??Date.now(),isSummaryView:ce,messageItemClassNames:f,messageStyleOverrides:p,StoreLinkComponent:C,CollectionLinkComponent:w},`initial-request`),et&&t(Xq,{label:$e,timestamp:it,className:x}),s===`stacked`?n(e,{children:[Ye.map((e,n)=>{let r=n===Ye.length-1;if(e.type===`resource_summary`)return t(nK,{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&&!dU.includes(n.type)&&!i;return h?.includes(s)?null:t($J,{status:e.toolStatus,children:t(eY,{children:t(ZK,{...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)})})},CJ(e))}if(e.type===`streaming`)return t($J,{children:t(cK,{...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)})},CJ(e));{let i=e.message;if(Ee(i)||De(i))return null;if(mU(i))return t($J,{children:t(ZJ,{message:i,startTimestamp:wJ(Ye,n)??i.timestamp,endTimestamp:i.timestamp})},SJ(i,`stopped`));let a=!c&&r&&!dU.includes(i.type);return sq(i)?t(eY,{children:t(TG,{message:i,batchData:i.details,isRunning:!i.details.completed_at,..._})},`batch-${i.details.batch_id}-${i.timestamp}`):t($J,{status:`message`,children:t(eY,{children:t(YG,{...f,message:i,showPulsatingCircle:a,onSendMessage:u,onOpenArtifact:d,requestInputAnswered:gW(i,xe),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:C,CollectionLinkComponent:w,feedbackAgentRunId:y})})},SJ(i))}}),He.map(({id:e,data:n})=>t($J,{children:t(cK,{...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}`)),Xe&&He.length===0&&!et&&t($J,{children:n(`div`,{className:z(`flex items-center gap-2 py-2 text-sm text-muted`,x),children:[t(FW,{size:`sm`,color:`blue`}),t(`span`,{children:I(`agent.working`)})]})})]}):n(e,{children:[qe.map(e=>{if(e.type===`resource_summary`)return t(nK,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`work`){if(h?.includes(s))return null;let n=gq(e.messages);return t(QJ,{label:_q(e.isActive),status:e.status,timestamp:e.startTimestamp,durationSeconds:e.isActive?void 0:uq(e.startTimestamp,e.endTimestamp),showElapsed:!0,details:n?void 0:e.messages,defaultExpanded:e.isActive&&!n,disablePreambleCollapse:e.isActive,className:x,onSendMessage:u,answeredToolApprovalRequestInputKeys:Ce,resolvedToolApprovalKeys:Se},`work-${e.id}-${e.isActive?`active`:`done`}-${e.status}`)}if(e.type===`stopped`)return t(ZJ,{message:e.message,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp},SJ(e.message,`stopped-summary`));let n=e.message;return Ee(n)||De(n)?null:sq(n)?t(eY,{children:t(TG,{message:n,batchData:n.details,isRunning:!n.details.completed_at,..._})},SJ(n,`batch`)):t(eY,{children:t(Bq,{message:n,onSendMessage:u,onOpenArtifact:d,onSelectWorkstream:_e,requestInputAnswered:gW(n,xe),StoreLinkComponent:C,CollectionLinkComponent:w,feedbackAgentRunId:y})},SJ(n,`summary`))}),He.map(({id:e,data:n})=>t(XJ,{text:n.text,workstreamId:n.workstreamId,artifactRunId:v},`streaming-incomplete-${e}`)),Ze&&t(`div`,{className:z(`mx-auto w-full max-w-3xl px-1 text-sm text-muted`,x),"data-testid":`post-tool-thinking-indicator`,children:I(`agent.thinking`)}),Qe&&!et&&t(QJ,{label:$e,status:`running`,timestamp:it,showElapsed:!0,className:x})]}),t(`div`,{ref:a,className:`h-2`})]})]})}const rY=(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},iY=ot.memo(nY);Q();function aY(e){return e?new Map(e.streamingMessages.map((e,t)=>[e.id??e.activityId??`stream-${t}`,e])):new Map}function oY(e,t){return e?.find(e=>e.cursor===t)}function sY(e,t){if(t===0||e===`live`)return`live`;let n=TC(e,t);return n>=t-1?`live`:n+1}function cY(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 lY(e){return cY(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function uY(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 dY({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(()=>wC(h,m.length)),v=r??g,y=l??`sliding`,[b,x]=G(!!s),[S,C]=G(0),w=W(null),T=U(()=>OC(m,v,!0),[v,m]),E=T.displayedMessages,D=U(()=>aY(oY(e.streamingFrames,T.cursor)),[e.streamingFrames,T.cursor]),O=V(e=>{let t=wC(e,m.length);r===void 0&&_(t),a?.(t)},[r,m.length,a]);H(()=>{let e=wC(v,m.length);e!==v&&O(e)},[v,m.length,O]),H(()=>{if(!s||s<=0||!b)return;let e=window.setInterval(()=>{let e=sY(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&&!pU(E),A=U(()=>_W(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`;uY(`${lY(j)||`agent-chat`}-${lY(n)}.json`,t)},[e,m.length,j]),N=V(()=>{O(sY(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(pg,{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?Qv:uy,{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(PC,{cursor:T.cursor,messages:m,onChangeCursor:O})}),t(iY,{messages:E,isCompleted:k,streamingMessages:D,bottomRef:w,artifactRunId:e.metadata?.agent_run_id??`agent-chat-fixture`,viewMode:y,renderRequestInputControls:!A}),A&&t(yW,{message:A,onSendMessage:N,isLoading:!1})]})}function fY({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-primary rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-primary`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-primary rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-primary`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-primary rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-primary`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}})]})}function pY(){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 mY(e,t){return t?.length?e.memberIds.every(e=>t.includes(e)):!1}function hY(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 gY(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!mY(e,t)).length}function _Y(e,t){return e.filter(e=>e.authStatus?.authenticated===!0&&!mY(e,t)).map(e=>e.label)}Q();function vY({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(DT,{isOpen:e,onClose:r,size:`md`,className:`max-w-[92vw] sm:max-w-[620px] lg:max-w-[620px]`,children:[t(OT,{children:f(`mcpConnections.title`)}),n(kT,{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(wO,{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=!mY(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?Q_:Y_,{className:`size-4 shrink-0 ${i?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(mT,{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(yT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:f(`mcpConnections.checkingStatus`),children:t(wO,{className:`size-3`})}):a?t(DO,{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(CT,{variant:`outline`,className:`h-6 w-32 justify-center px-2 text-xs`,children:f(`mcpConnections.managedByApp`)}):null,l&&t(SO,{size:`sm`,value:r,onChange:t=>l(hY(e,c,t)),disabled:d,"aria-label":f(r?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:e.label})})]})]},e.key)})})]})]})}Q();function yY({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}=pY(),[m,h]=G(!1);if(!d&&u.length===0)return null;let g=gY(u,r),_=_Y(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(yT,{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(CT,{variant:`success`,children:g})]})]}),t(vY,{isOpen:m,onClose:()=>h(!1),groups:u,loading:d,reload:p,statusLoading:f,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}function bY({disabledCollections:e,onChange:r,onConnectionChange:i,readOnly:a=!1}){let{t:o}=K(),{groups:s,loading:c,statusLoading:l,reload:u}=pY();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(wO,{className:`size-4`}),t(`span`,{children:o(`mcpConnections.label`)})]}):t(`div`,{className:`space-y-1`,children:s.map(i=>{let s=!mY(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?Q_:Y_,{className:`size-4 shrink-0 ${c?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(mT,{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(yT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:o(`mcpConnections.checkingStatus`),children:t(wO,{className:`size-3`})}):u?t(DO,{appId:i.appId,collectionId:i.representativeId,collectionName:i.label,authenticated:i.authStatus?.authenticated,onAuthChange:d,variant:`compact`,showDisconnect:!0,readOnly:a}):t(CT,{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(SO,{size:`sm`,value:s,onChange:t=>r(hY(i,e,t)),disabled:a,"aria-label":o(s?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:i.label})})]})]},i.key)})})}function xY({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1}){let{t:s}=K(),{groups:c,loading:l,statusLoading:u,reload:d}=pY(),[f,p]=G(!1);if(!l&&c.length===0)return null;let m=gY(c,r);return n(e,{children:[t(tO,{align:`left`,trigger:t(yT,{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(nO,{onClick:()=>p(!0),isDisabled:l,children:[t(`span`,{children:s(`mcpConnections.title`)}),m>0&&t(CT,{variant:`success`,children:m})]})}),t(vY,{isOpen:f,onClose:()=>p(!1),groups:c,loading:l,reload:d,statusLoading:u,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}const SY=/(^|\/)(tool-inputs|tool-results|archive)(\/|$)/,CY=/(^|\/)process\/(history|state)(\/|$)/,wY=[/conversation\.json$/,/^conversation-checkpoint-\d+\.json$/,/^tools\.json$/,/^tool-input-refs\.json$/,/^toolu[_-]/i];function TY(e){if(SY.test(e)||CY.test(e))return!0;let t=e.split(`/`).pop()??e;return wY.some(e=>e.test(t))}function EY(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 DY(e,t){let n=`agents/${t}/`,r=e.indexOf(n);return r===-1?e.split(`/`).pop()??e:e.slice(r+n.length)}function OY(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=>DY(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=>!TY(e)),[i,r]),h=U(()=>EY(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 kY(){return AY||=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}),AY}var AY,jY,MY,NY=Y((()=>{jY=ht(()=>kY().then(({Document:e})=>({default:e}))),MY=ht(()=>kY().then(({Page:e})=>({default:e})))}));function PY({className:e,size:n=`md`}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(sv,{className:`${{sm:`w-4 h-4`,md:`w-6 h-6`,lg:`w-8 h-8`}[n]} animate-spin text-muted`})})}function FY({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(PY,{className:`py-4`,size:`md`}),t(ut,{fallback:null,children:t(jY,{file:e,onLoadSuccess:({numPages:e})=>{d(!1),c?.(e)},onLoadError:e=>{d(!1),p(e),l?.(e)},loading:null,children:t(MY,{pageNumber:r,width:i,renderTextLayer:o,renderAnnotationLayer:s,loading:t(PY,{className:`py-4`,size:`sm`})})})})]})}function IY({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(PY,{className:`py-4`,size:`md`}),children:t(jY,{file:e,onLoadSuccess:p,onLoadError:m,loading:t(PY,{className:`py-4`,size:`md`}),children:r((e,n)=>t(MY,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(PY,{className:`py-4`,size:`sm`})},e))})}):t(PY,{className:`py-4`,size:`md`})})}function LY(){return _t(UY)}function RY({pageNumber:e,width:n,className:r}){let i=LY(),a=i?.pageDimensions?.aspectRatio??WY,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(PY,{size:`md`})}):t(`div`,{className:r,children:t(MY,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(PY,{className:`py-4`,size:`sm`})})})}function zY({pageNumber:e,width:n,isSelected:r,onSelect:i,renderThumbnail:a,aspectRatio:o=WY,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(MY,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d},children:t(PY,{size:`sm`})})}):t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d,width:n||`100%`},children:t(`span`,{className:`text-muted text-xs`,children:e})});return t(`div`,{ref:c,children:a({pageNumber:e,isSelected:r,pageElement:f,onSelect:i})})}function BY(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 VY({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(WY),d?.(WY)}},[d,m]),w=y??WY,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||BY(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(PY,{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(PY,{className:`py-4`,size:`md`}),children:t(jY,{file:r,onLoadSuccess:C,onLoadError:S,loading:t(PY,{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(zY,{pageNumber:r,width:s,isSelected:r===o,onSelect:()=>c(r),renderThumbnail:l,aspectRatio:w})},r)}),O>0&&t(`div`,{style:{height:O}})]}):t(PY,{className:`py-4`,size:`md`})})})})}function HY({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(PY,{className:`py-8`,size:`lg`}),t(ut,{fallback:null,children:t(jY,{file:e,onLoadSuccess:({numPages:e})=>{d(e),p(!1)},onLoadError:e=>{p(!1),h(e)},loading:null,children:t(MY,{pageNumber:Math.min(r,u||1),width:i,height:a,renderTextLayer:s,renderAnnotationLayer:c,loading:t(PY,{className:`py-8`,size:`md`})})})})]})}var UY,WY,GY=Y((()=>{Q(),NY(),UY=dt(null),WY=210/297}));function KY({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(ZY),[x,S]=G(YY),[C,w]=G(null),T=W(null),E=_?Math.round(_*y/100):void 0,D=V(()=>{let e=XY.findIndex(e=>e>=y);e===-1&&(e=XY.length-1);let t=Math.min(e+1,XY.length-1);b(XY[t])},[y]),O=V(()=>{let e=XY.findIndex(e=>e>=y);e===-1&&(e=XY.length-1);let t=Math.max(e-1,0);b(XY[t])},[y]),k=V(()=>{b(ZY)},[]),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(Ph,{className:`size-4`})}),n(`div`,{className:`absolute start-2 flex items-center gap-x-1`,children:[t(JY,{zoom:y,onZoomIn:D,onZoomOut:O,onFitToView:k,canZoomIn:y<XY[XY.length-1],canZoomOut:y>XY[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(qY,{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(VY,{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 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(Sh,{className:`size-4`})})})]})}function qY({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`,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 JY({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(Lv,{})}),n(`span`,{className:`text-xs text-muted min-w-[32px] text-center`,children:[e,`%`]}),t(o,{variant:`ghost`,size:`xs`,onClick:r,isDisabled:!s,title:l(`pdf.zoomIn`),children:t(py,{})}),t(o,{variant:`ghost`,size:`xs`,onClick:a,title:l(`pdf.fitToWidth`),className:e===ZY?`text-muted/40`:void 0,children:t(yv,{})})]})}var YY,XY,ZY,QY=Y((()=>{Q(),GY(),YY=210/297,XY=[50,75,100,125,150,200,300],ZY=100}));function $Y({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(ix,{className:`size-4`})})}),t(KY,{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(KY,{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 hover:text-foreground hover:bg-muted`,onClick:()=>v(!0),children:t(gv,{className:`size-4`})})})}):t(`div`,{className:`flex items-center justify-center h-full text-muted`,children:s(`pdf.noPdfAvailable`)})}var eX=Y((()=>{Q(),QY()})),tX=hr({UniversalDocumentViewer:()=>EX});function nX(e){return e.fileName||e.title||e.artifact?.path.split(`/`).pop()||e.sourcePath?.split(`/`).pop()||`Document`}function rX(e){let t=e.split(`?`)[0]||e;return t.includes(`.`)&&t.split(`.`).pop()?.toLowerCase()||``}function iX(e){return e.contentType===`application/pdf`||e.extension===`pdf`}function aX(e){return[`md`,`markdown`].includes(e.extension)||[`text/markdown`,`text/x-markdown`].includes(e.contentType||``)}function oX(e){return e.contentType?.startsWith(`image/`)||[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`].includes(e.extension)}function sX(e){return e.contentType===`text/html`||[`html`,`htm`].includes(e.extension)}function cX(e){return[`application/xml`,`text/xml`].includes(e.contentType||``)||e.extension===`xml`}function lX(e){return e.contentType?.startsWith(`text/`)||[`css`,`csv`,`json`,`txt`,`tsx`,`ts`,`jsx`,`js`,`xml`,`yaml`,`yml`].includes(e.extension)}function uX(e){return[`tsx`,`jsx`].includes(e.extension)}function dX(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 fX({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 pX({message:e}){return n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-muted`,children:[t(i_,{className:`size-8`}),t(`span`,{className:`text-sm`,children:e})]})}function mX(e,n){if(e.Component){let r=e.Component;return t(r,{context:n})}return e.render?.(n)??null}function hX(e,t){return e.includes(`.`)?e.replace(/\.[^/.]+$/,t):`${e}${t}`}function gX(e){return e.split(`/`).pop()||e}function _X(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function vX(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function yX(e){if(e!==void 0)return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function bX(e){return Array.isArray(e)?e.length:0}function xX(e){try{let t=_X(JSON.parse(e));if(!t)return;let n=_X(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:vX(n.width),height:vX(n.height)}:void 0,dependencies_reused:typeof t.dependencies_reused==`boolean`?t.dependencies_reused:void 0,status:vX(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:_X(t.timings_ms),error:t.error}}catch{return}}async function SX(e,t){let n=await fetch(e);if(!n.ok)throw Error(`Failed to load ${t}: ${n.statusText}`);return n.text()}function CX({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}${gX(i)}`:n}function wX({metadata:e}){if(!e)return null;let r=vX(e.timings_ms?.total_before_cleanup),a=bX(e.console_errors)+bX(e.page_errors)+bX(e.failed_requests)+bX(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]}),yX(r)&&n(`div`,{children:[`Total `,yX(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 TX({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,gX(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=hX(e,`.png`),r=hX(e,`.render.json`);async function i(){u({isLoading:!0});let i,a,o=n;try{i=xX(await SX(await d(r,`inline`),gX(r))),o=CX({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(P_,{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(sv,{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(wX,{metadata:l.metadata}),t(`div`,{className:`p-3`,children:t(fX,{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(wX,{metadata:l.metadata}),t(fX,{content:c,extension:e.extension})]})]})]})}function EX({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(()=>nX(e),[e]),g=U(()=>rX(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 ${nX(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&&(aX(P)||sX(P)||cX(P)||lX(P)),L=!F&&(iX(P)||oX(P)),ee={source:e,fileName:h,extension:g,contentType:e.contentType,target:`pdf`},te=!F&&!P.url?s.find(e=>e.target===`pdf`&&e.canConvert(ee)):void 0,R=!F&&!P.url&&(dX(P)||!!te)&&(!!te||!!u);H(()=>{let t=!1,n=e;E(null),v(n.url),b(n.content),S(null);async function r(){if(I||L||R){w(!0);try{if(R){let e=te?await te.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,R,I,L,D,j,te,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(sv,{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(Lh,{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?mX(F,ne):(iX(ne)||x?.contentType===`application/pdf`)&&ne.url?t($Y,{url:ne.url,className:`h-full`}):oX(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`})}):aX(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||``})}):sX(ne)?t(`iframe`,{title:h,className:`h-full min-h-96 w-full bg-white`,sandbox:``,srcDoc:ne.content||``}):cX(ne)?t(`div`,{className:`px-4 py-2`,children:t(Rt,{xml:ne.content||``,collapsible:!0})}):uX(ne)?t(TX,{context:ne}):lX(ne)?t(fX,{content:ne.content,extension:g}):dX(ne)&&!te&&!u?t(pX,{message:`This file needs a PDF rendition before it can be previewed.`}):t(pX,{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 DX=Y((()=>{Q(),eX()}));Q();const OX=ot.lazy(async()=>({default:(await Promise.resolve().then(()=>(DX(),tX))).UniversalDocumentViewer})),kX=new Set([`md`,`markdown`,`mdx`,`txt`]);function AX(e){let t=e.split(`.`).pop()?.toLowerCase();return t!==void 0&&kX.has(t)}function jX(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function MX({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(uh,{className:`size-3.5 shrink-0 text-muted`}):t(gh,{className:`size-3.5 shrink-0 text-muted cn-rtl-flip`}),t(p?u_:p_,{className:`size-4 shrink-0 text-info`}),t(`span`,{className:`min-w-0 truncate font-medium`,title:e.path,children:jX(e.name)})]}),p&&e.children.map(e=>t(MX,{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(i_,{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(sv,{className:`size-3.5 animate-spin text-info`}):t(Og,{className:`size-3.5`})})]})}function NX(e){return e.reduce((e,t)=>t.isDirectory?e+NX(t.children):e+1,0)}function PX(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=PX(e.children,n);return t?[{...e}]:r.length>0?[{...e,children:r}]:[]}):e}function FX(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 IX(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 LX({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(jm,{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(sv,{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(sh,{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(Oy,{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(ty,{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(Og,{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 RX({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 zX({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}=OY(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(()=>PX(h,N),[h,N]),F=U(()=>NX(P),[P]),I=vt(),L=V(async e=>{if(r){C(e);try{let{url:t}=await d.files.getArtifactDownloadUrl(r,e,`attachment`);FX(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(AX(e)){j(e);return}T(e)},[j]),te=r&&w?{title:w.split(`/`).pop()||w,fileName:w.split(`/`).pop()||w,contentType:IX(w),artifact:{runId:r,path:w}}:null;return r?y&&_===0?t(RX,{icon:t(sv,{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(Sy,{className:`size-3.5 me-1.5`}),u(`agent.retry`)]}),children:[t(`span`,{className:`break-all text-muted`,children:b}),` `,t(`br`,{})]})}):_===0?t(RX,{icon:t(Uv,{className:`mb-2 size-8`}),action:n(o,{variant:`ghost`,size:`sm`,className:`mt-2`,onClick:x,children:[t(Sy,{className:`size-3.5 me-1.5`}),u(`agent.refresh`)]}),children:u(`agent.noArtifactsYet`)}):A?t(LX,{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(Sy,{className:`size-3.5 ${y?`animate-spin`:``}`})})]})]}),t(`label`,{htmlFor:I,className:`sr-only`,children:u(`form.filter`)}),t(R,{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(MX,{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`)})}),te&&n(se,{isOpen:!!w,onClose:()=>T(null),size:`xl`,className:`h-[90vh] p-0`,description:`Artifact preview`,children:[t(ue,{show:!1,children:te.fileName}),t(ce,{className:`h-full max-h-none p-0`,children:t(ot.Suspense,{fallback:t(p,{className:`h-full`,children:t(sv,{className:`size-6 animate-spin text-muted`})}),children:t(OX,{source:te,className:`h-full`,showHeader:!0,onDownload:()=>w&&void L(w)})})})]})]}):t(RX,{icon:t(Uv,{className:`mb-2 size-8`}),children:`No run selected`})}const BX=ot.memo(zX);Q();function VX(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function HX(e){if(!VX(e))return;let t=e.browseruse??e.browser_use;if(!VX(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=HX(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 WX(e){return e.replace(/^artifact:\/\//,``).replace(/^artifact:/,``).replace(/^\/+/,``)}function GX(e){return e?e.replace(/_/g,` `):`browser`}function KX({state:e,runId:r,className:a,compact:o}){let{t:s}=K(),{client:c}=q(),l=eC(),{openImage:u}=rG(),[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&&WX(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=WX(p);try{let n=nC(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(Bv,{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:[`· `,GX(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(Pg,{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(P_,{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(Bv,{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:GX(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(P_,{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(Pg,{className:`size-3`})})]})]})}Q();function qX({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(jm,{className:`size-4 cn-rtl-flip`})}),n(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[t(Qg,{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(Pg,{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(sv,{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(Qg,{className:`size-8 mb-2`}),t(`span`,{className:`text-sm`,children:u(`agent.noContentAvailable`)})]})})]})}const JX=ot.memo(qX);Q();function YX({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(JX,{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(R,{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(Qg,{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(Pg,{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 XX=ot.memo(YX);Q();function ZX({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(sg,{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(ph,{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(gh,{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=tg,f=`text-muted`;c===`in_progress`?(d=ug,f=`text-info`):c===`completed`&&(d=Uh,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=tg,a=`text-muted`,o=u(`agent.pending`);return r===`in_progress`?(i=ug,a=`text-info`,o=u(`agent.inProgress`)):r===`completed`&&(i=Uh,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 QX=ot.memo(ZX);Q();function $X({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 eZ({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(sv,{className:`size-4 animate-spin text-info`});case mn.READY:return t(Uh,{className:`size-4 text-success`});case mn.ERROR:return t(Qh,{className:`size-4 text-destructive`});default:return t(Qg,{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($X,{icon:t(Qg,{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 tZ=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 nZ({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 bU(c,e);t&&window.open(t,`_blank`)}catch{l({status:`error`,title:s(`agent.failedToDownload`)})}},[c,s,l]);return e.length===0?t($X,{icon:t(K_,{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?YH(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(tZ,{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`,rU(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:YH(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(tZ,{title:s(`agent.browserWidgetRenderError`),description:d,compact:!0,children:t(KX,{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(ig,{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(pg,{className:`size-3 me-1`}),s(`agent.download`)]})]})]})]})})},e.launch_id)})})]})}function rZ({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(tZ,{title:A(`agent.panelRenderError`,{name:e}),description:A(`agent.panelRenderErrorDescription`),children:n}),[A]),te={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},R=[...T?[te]:[],{name:`plan`,label:A(`agent.plan`),content:ee(A(`agent.plan`),e?t(QX,{plan:e,workstreamStatus:r||new Map,isOpen:!0,onClose:E,plans:i,activePlanIndex:a,onChangePlan:s}):t($X,{icon:t(K_,{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(nZ,{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(XX,{documents:d,activeDocumentId:f??null,onSelectDocument:p,onUpdateDocumentTitle:m,refreshKey:h,runId:g}):t($X,{icon:t(Qg,{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(eZ,{files:_})),is_allowed:!0},{name:`artifacts`,label:A(`agent.artifacts`),content:ee(A(`agent.artifacts`),t(BX,{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=R.filter(e=>e.is_allowed===void 0||e.is_allowed===!0);return n(ze,{tabs:R,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(ix,{className:`size-4`})})]}),t(Ve,{className:`flex-1 min-h-0 pt-0 pb-0`})]})}const iZ=ot.memo(rZ);function aZ(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 oZ(e,t){let[n,r]=G([]),[i,a]=G(0),[o,s]=G(new Map),[c,l]=G(t),[u,d]=G(!1),f=W(-1),p=W(new Set);H(()=>{e.length===0&&(r([]),a(0),s(new Map),d(!1),f.current=-1,p.current.clear())},[e.length]);let m=V(e=>{let n=e[e.length-1];n&&(n.type===J.TERMINATED?l(!1):l(t?!0:n.type===J.REQUEST_INPUT))},[t]);return H(()=>{if(e.length===0)return;let t=f.current+1;if(t>=e.length){m(e);return}let n=!1,i=[],o=[];for(let r=t;r<e.length;r++){let t=e[r];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 r=typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime();if(!p.current.has(r)){p.current.add(r),n=!0,i.push({plan:e,timestamp:r});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`)}}),o.push({timestamp:r,statusMap:t})}}}catch(e){console.error(`Failed to parse plan from message:`,e)}}f.current=e.length-1,n&&i.length>0&&(r(e=>[...[...i].reverse(),...e]),a(0),d(!0),o.length>0&&s(e=>{let t=new Map(e);for(let e of o)t.set(e.timestamp,e.statusMap);return t})),m(e)},[e,m]),H(()=>{if(n.length===1&&!u&&!sessionStorage.getItem(`plan-panel-shown`)){let e=setTimeout(()=>{d(!0),sessionStorage.setItem(`plan-panel-shown`,`true`)},500);return()=>clearTimeout(e)}},[n.length,u]),{plans:n,activePlanIndex:i,setActivePlanIndex:a,workstreamStatusMap:o,showInput:c,showSlidingPanel:u,setShowSlidingPanel:d}}function sZ(e,t){return{...e,details:{...e.details??{},_deliveryStatus:t}}}function cZ(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 lZ(e,t){let n=e?.[t];return typeof n==`string`&&n?n:void 0}function uZ(e){return e?.streaming_id_scope===`workflow_run`}function dZ(e){return[J.COMPLETE,J.IDLE,J.TERMINATED,J.REQUEST_INPUT].includes(e.type)}function fZ(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||dZ(e)||On(e).length>0}function pZ(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 mZ(e,t){if(e.find(e=>e.timestamp===t.timestamp))return e;if(!t.details?._optimistic&&(t.type===J.QUESTION||mU(t))){let n=typeof t.details?.ack==`string`?t.details.ack:void 0,r=n?sZ(t,`consumed`):t;if(n){let i=e.filter(e=>e.type!==t.type&&!mU(e)||!e.details?._optimistic||cZ(e)!==n);return uU(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 uU(r,t),r}}}let n=[...e];return uU(n,t),n}function hZ(e){let t=e.details,n=lZ(t,`streaming_id`),r=lZ(t,`activity_id`);return n&&uZ(t)?n:r??n}function gZ(e){let t=e.details,n=lZ(t,`streaming_id`),r=lZ(t,`activity_id`),i=[];return n&&uZ(t)&&i.push(n),r&&i.push(r),[...new Set(i)]}function _Z(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(!pU(r))},[r]),H(()=>{lU(`stream state`,{agentRunId:t,messageCount:r.length,streamingCount:x.size,initialHistoryStatus:s,isCompleted:a,lastDeliveredTs:b.current,first:pZ(r[0]),last:pZ(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 lU(`stream start`,{agentRunId:t,isNewConversation:n,since:a,streamNonce:g}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(lU(`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),lU(`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=hZ(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=gZ(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(),fZ(e)&&i(t=>mZ(t,e))},a,r.signal,{closeOnIdle:!1,onHistoryLoaded:e=>{if(r.signal.aborted)return;let n=e.filter(fZ),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]))),lU(`history loaded`,{agentRunId:t,count:e.length,timelineCount:n.length,since:a,first:pZ(e[0]),last:pZ(e[e.length-1])}),c(e.length>0?`has_messages`:`empty`),n.length>0&&i(e=>n.reduce((e,t)=>mZ(e,t),e))},onHistoryError:e=>{r.signal.aborted||(lU(`history error`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),c(`error`))}}).then(()=>{if(!r.signal.aborted)return lU(`stream resolved`,{agentRunId:t}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(lU(`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||(lU(`stream failed`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),console.error(`Failed to stream agent messages:`,e))}),()=>{lU(`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&&cZ(n)===e?sZ(n,t):n))},[]),removeOptimisticMessages:V(e=>{i(t=>t.filter(t=>!e(t)))},[]),reconnect:v,agentRunStatus:l,workflowRunId:d,serverFileUpdates:m}}function vZ(e){if(typeof e==`string`&&e.trim().length>0)return e}function yZ(e,t){let n=vZ(e.revision_root_id)||vZ(e.revision_root)||vZ(e.root_document_id)||vZ(e.root_id);if(n)return n;let r=e.revision_info;if(r&&typeof r==`object`){let e=vZ(r.root);if(e)return e}return t}function bZ(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 xZ(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=vZ(e.document_id),r=vZ(e.updated_document_id)||t,a=e.title;if(r){let s=yZ(e,t||r),l={id:r,title:a||`Document`,revisionRootId:s};n(e=>{let t=e.findIndex(e=>bZ(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 SZ(e){return e.type.startsWith(`image/`)}function CZ(e){if(!(!SZ(e)||typeof URL>`u`||!URL.createObjectURL))return URL.createObjectURL(e)}function wZ(e){typeof URL<`u`&&URL.revokeObjectURL&&URL.revokeObjectURL(e)}function TZ(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&&(wZ(t),d.current.delete(e))},[]);H(()=>{if(f.current!==t){f.current=t,d.current.forEach(wZ),d.current.clear(),s(new Map);let e=new Set;u.current=e,l(e)}},[t]),H(()=>()=>{d.current.forEach(wZ),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=CZ(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(wZ),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 EZ({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(Lm,{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?yh:uh,{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=ZH(r.workstream_id,r.interaction),s=n(e,{children:[t(`span`,{className:z(`size-1.5 shrink-0 rounded-full`,rU(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:YH(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(gh,{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(uh,{className:z(`size-3.5 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})]})]})})}const DZ=new tr({strict:!1,validateFormats:!1});function OZ(e){if(e!==Tn.virtual_lb&&e!==Tn.virtual_mediator&&e!==Tn.test)return e}var kZ=class{_listeners=new Set;snapshot;constructor(e){this.snapshot=new AZ(e,this)}subscribe=e=>(this._listeners.add(e),()=>{this._listeners.delete(e)});getSnapshot=()=>this.snapshot;notify(){this._listeners.forEach(e=>{e()})}},AZ=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).catch(()=>{this.environment=void 0})}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?OZ(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:DZ.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 jZ=dt(void 0);function MZ({children:e}){let{client:n}=q(),[r]=G(()=>new kZ(n)),i=xt(r.subscribe,r.getSnapshot);return t(jZ.Provider,{value:i,children:e})}function NZ(){let e=_t(jZ);if(!e)throw Error(`usePayloadBuilder must be used within a PayloadProvider`);return e}Q();function PZ(){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 FZ({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=PZ(),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(sg,{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`?Oy:Tv,{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(Oy,{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(Tv,{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(Qm,{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(Pg,{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(Sv,{className:z(`size-4`,r===`full`&&`me-1.5`)})}),t(IZ,{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(ix,{className:`size-4`})})]});return r===`compact`?t(MZ,{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(MZ,{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(Lm,{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-muted`)})]})]}),P]})})}function IZ({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=NZ();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(jg,{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(yg,{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(yg,{className:`size-3.5 text-muted`}),` `,g(`agent.copyWorkflowRunId`)]}),p&&n(ae,{onClick:p,children:[t(L_,{className:`size-3.5 text-muted`}),` `,g(`agent.details`)]}),n(ae,{onClick:()=>{l?l():bU(v,r).then(e=>window.open(e,`_blank`))},children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.downloadConversation`)]}),f&&n(ae,{onClick:f,children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.exportAsPdf`)]}),u&&n(ae,{onClick:u,children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.rewind.exportFixture`)]}),c&&a&&n(ae,{onClick:c,children:[t(ix,{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(T_,{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(ix,{className:`size-3.5`}),` `,g(`agent.cancelWorkflow`)]})]})})}function LZ(e){return typeof e==`object`&&!!e&&`value`in e}function RZ(e){return LZ(e)?e.value:e}function zZ(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 BZ(e,t,n){e.query[t]=n}function VZ(e){let t=new Set(e);return e=>t.has(e)}const HZ=[`sys`,`app`,`tmp`],UZ=/^[0-9a-fA-F]{24}$/;function WZ(e){let t=e.indexOf(`:`),n=t>0?e.slice(0,t):void 0;return n&&HZ.includes(n)?{type:n,label:e.slice(t+1)}:{label:e}}function GZ(e,...t){let n=[e?.name,...t].filter(e=>!!e),r=n.find(e=>!UZ.test(e));if(r)return r;let i=n[0];return i?`Deleted interaction (~${i.slice(-8)})`:void 0}function KZ(e){return!!e&&e.version===0&&e.status===gn.unknown}function qZ({interaction:e,className:n}){let r=`success`;switch(e.status){case gn.published:r=`success`;break;case gn.archived:r=`destructive`;break;case gn.code:r=`info`}let a=[e.version?`v${e.version}`:``,e.status&&e.status!==gn.unknown?e.status:``].filter(Boolean).join(` `);return a?t(i,{variant:r,className:n,children:a}):null}function JZ({interaction:r,fallbacks:a=[],fallbackNode:o=null}){let s=GZ(r,...a);if(!s)return t(e,{children:o});let{type:c,label:l}=WZ(s),u=!!r&&!KZ(r);return n(e,{children:[l,(c||u)&&n(`div`,{className:`flex items-center mt-1.5 shrink-0 gap-2`,children:[c&&t(i,{variant:`secondary`,children:c}),u&&r&&t(qZ,{interaction:r})]})]})}function YZ(e,t){return GZ(e,t)??t}function XZ({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),{type:o,label:s}=WZ(YZ(a,r));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:s}),o&&t(i,{variant:`secondary`,className:`text-xs w-fit`,children:o}),a&&t(qZ,{interaction:a,className:`text-xs w-fit`})]}),(a?.count??0)>0&&n(`span`,{className:`ms-2 text-xs shrink-0`,children:[`(`,a?.count,`)`]})]})},filterBy:(t,n)=>YZ(e.find(e=>e._id===t),t).toLowerCase().includes(n.toLowerCase())}}function ZZ(e){return`${e._id} (${e.count})`}function QZ(e){return`${e.name} (${e.count})`}function $Z({buckets:e,name:t,placeholder:n,type:r=`select`,multiple:i=!1}){return{name:t,options:e.map(e=>({label:ZZ(e),value:e._id})),type:r,multiple:i,placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`,allowCreate:!1}}function eQ({buckets:e,name:t,placeholder:n,type:r,multiple:i}){return $Z({buckets:e,name:t,placeholder:n,type:r,multiple:i})}Q();const tQ={},nQ={},rQ={};function iQ(e){return typeof e==`object`&&!!e&&`status`in e&&e.status===404}function aQ(e,t,n){let r=e[t];return r||(r=n().catch(n=>{throw iQ(n)||delete e[t],n}),e[t]=r),r}function oQ(e){let{client:t}=q();return Ye(()=>aQ(tQ,e,()=>t.users.retrieve(e)),{deps:[e],condition:()=>!!e})}function sQ(e){let{client:t}=q();return Ye(()=>aQ(nQ,e,()=>t.iam.groups.retrieve(e)),{deps:[e],condition:()=>!!e})}function cQ(e){let{client:t}=q();return Ye(()=>aQ(rQ,e,()=>t.apikeys.retrieve(e)),{deps:[e],condition:()=>!!e})}function lQ(){return t(`div`,{className:`size-8`})}function uQ({showTitle:e=!1,size:i=`md`}){let{t:a}=K();return t(SQ,{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 dQ({showTitle:e=!1,size:r=`md`}){let{t:i}=K();return t(SQ,{title:i(`user.allProjectMembers`),description:i(`user.allProjectMembersDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(Ub,{className:`size-4`,size:r}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:i(`user.allProjectMembers`)})]})})}function fQ({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(SQ,{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 pQ({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(SQ,{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-background`,size:o}),t(r,{name:i,size:o,className:`border-2 border-background`})]}),a&&n(`div`,{className:`text-sm font-semibold truncate`,children:[`Agent (`,i,`)`]})]})})}function mQ({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=oQ(o||``),m=cQ(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`,children:[`Key ID: `,g.id]})]}),!h&&!g&&n(e,{children:[t(`div`,{children:u(`user.serviceAccountDescription`)}),n(`div`,{className:`text-foreground dark:text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]})]});return t(SQ,{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-background`,size:c}),h&&t(r,{src:h.picture,name:h.name,size:c,className:`border-2 border-background`}),g&&t(r,{name:`API`,color:`bg-gray-400`,size:c,className:`border-2 border-background`})]}),s&&t(`div`,{className:`text-sm font-semibold truncate`,children:h?`Agent (${h.name||h.email})`:g?`Agent (${g.name})`:v})]})})}function hQ({title:e=`Error`,error:n,showTitle:r=!1,size:i=`md`}){return t(vQ,{title:e,message:Ge(n),color:`bg-red-500`,showTitle:r,size:i})}function gQ({showTitle:e=!1,size:n=`md`,color:r}){let{t:i}=K();return t(vQ,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),color:r,showTitle:e,size:n})}function _Q({userRef:e,showTitle:n=!1,size:r=`md`}){let{t:i}=K();if(!e)return t(vQ,{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(bQ,{userId:a[1],showTitle:n,size:r});case xn.Group:return t(yQ,{userId:a[1],showTitle:n,size:r});case`system`:return t(uQ,{showTitle:n,size:r});case xn.ServiceAccount:return t(fQ,{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(mQ,{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(mQ,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r,isScheduleAgent:!0})}case`email`:return t(pQ,{email:a[1],showTitle:n,size:r});case xn.ApiKey:return t(xQ,{keyId:a[1],size:r,showTitle:n});case`project`:if(a[1]===`*`)return t(dQ,{showTitle:n,size:r});break;default:return t(hQ,{title:i(`user.unknownUser`),error:`Invalid user ref type: ${o}`,showTitle:n,size:r})}}function vQ({title:e,message:i,color:a,size:o=`md`,showTitle:s=!1}){return t(SQ,{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 yQ({userId:e,showTitle:r=!1,size:i=`md`}){let{t:a}=K(),{data:o,error:s}=sQ(e);if(s)return iQ(s)?t(gQ,{showTitle:r,size:i,color:`bg-indigo-500`}):t(hQ,{title:a(`user.failedToFetchGroup`),error:s,showTitle:r,size:i});if(!o)return t(lQ,{});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`,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(SQ,{title:o.name||a(`user.unnamedGroup`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(Kb,{className:`size-6 text-info`,size:i}),r&&t(`div`,{className:`text-sm font-semibold ps-2`,children:o.name||a(`user.unnamedGroup`)})]})})}function bQ({userId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=oQ(e);if(c)return iQ(c)?t(gQ,{showTitle:i,size:a,color:`bg-indigo-500`}):t(hQ,{title:o(`user.failedToFetchUser`),error:c,showTitle:i,size:a});if(!s)return t(lQ,{});let l=t(`div`,{className:`truncate`,title:s.email,children:s.email});return t(SQ,{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 xQ({keyId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=cQ(e);if(c)return iQ(c)?t(gQ,{showTitle:i,size:a,color:`bg-pink-500`}):t(hQ,{title:o(`user.failedToFetchApiKey`),error:c,showTitle:i,size:a});if(!s)return t(lQ,{});let l=o(`user.privateKey`),u=t(r,{name:`PK`,color:`bg-pink-500`,size:a}),d=n(Le,{className:`dark:bg-muted dark:text-foreground 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(SQ,{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 SQ({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-base font-semibold`,children:e}),r]})})]})}function CQ({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(_Q,{userRef:r,showTitle:!0,size:`sm`})}),n(`span`,{className:`text-muted flex-shrink-0`,children:[`(`,i?.count||0,`)`]})]})}}}function wQ({buckets:e,name:t,placeholder:n}){return CQ({buckets:e,name:t,placeholder:n})}Q();const TQ=VZ([`id`,`run_kind`,`interaction`,`status`,`initiated_by`,`start`,`end`,`evaluation`,`feedback`]);function EQ(e){let t=[];return t.push({name:`id`,placeholder:`Agent Run ID`,type:`text`,multiple:!1}),t.push(eQ({buckets:e.kinds||[],name:`run_kind`,placeholder:`Kind`})),t.push(XZ({buckets:e.interactions||[],name:`interaction`,placeholder:`Interaction`})),t.push(eQ({buckets:e.statuses||[],name:`status`,placeholder:`Status`})),t.push(wQ({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`})),t.push(eQ({buckets:e.evaluation||[],name:`evaluation`,placeholder:`Evaluation`})),t.push(eQ({buckets:e.feedback||[],name:`feedback`,placeholder:`Feedback`})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function DQ(e){return t=>{e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!TQ(t.name))return;let n=t.name;BZ(e,n,zZ(t))}}),e.search()}}function OQ({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=EQ(e),_=l??g,v=U(()=>DQ(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`,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(Sy,{className:`size-5`})})]})]}),f.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}var kQ=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 AQ=dt({registry:void 0,isLoading:!1,load:()=>Promise.resolve(),reload:()=>Promise.resolve()});function jQ({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 kQ(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(AQ.Provider,{value:{registry:i,isLoading:o,load:u,reload:d},children:e})}function MQ(){let e=_t(AQ);return H(()=>{!e.registry&&!e.isLoading&&e.load()},[e.registry,e.isLoading,e.load]),e}const NQ=VZ([`name`,`types`]);function PQ(e){let{registry:t}=MQ(),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 FQ(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(!NQ(t.name))return;let n=t.name;BZ(e,n,zZ(t))}}),e.search()}}function IQ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=PQ(e),u=FQ(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({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 RQ=[`id`,`name`,`types`,`status`],zQ=[`tags`,`created_at`,`updated_at`],BQ=VZ(RQ),VQ=new Set(zQ);function HQ(e){return VQ.has(e)}function UQ(e){return Array.isArray(e)?e:[]}function WQ(e){let{registry:t}=MQ(),n=[];if(n.push({placeholder:`ID`,name:`id`,type:`text`,options:[]}),n.push({placeholder:`Name`,name:`name`,type:`text`,options:[]}),e.type){let r=LQ({buckets:UQ(e.type),typeRegistry:t,type:`select`,multiple:!0});n.push(r)}if(e.status){let t=eQ({buckets:UQ(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:UQ(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 GQ(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=zZ(t);BQ(n)?BZ(e,n,r):HQ(n)&&r!==void 0&&(e.query.match={...e.query.match,[n]:r})}}),e.search()}}function KQ({facets:e,search:r}){let[i,a]=G([]),o=WQ(e),s=GQ(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 qQ({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:QZ,options:o,value:u,onChange:l,by:`_id`,placeholder:r})}const JQ=VZ([`name`,`prompt`,`model`,`tags`]);function YQ(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 XQ(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(!JQ(t.name))return;let n=t.name;BZ(e,n,zZ(t))}}),e.search(!0)}}function ZQ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=YQ(e),u=XQ(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 QQ(e){let t=[];return t.push(eQ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!1})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function $Q({facets:e,filters:r,setFilters:i}){let a=QQ(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 e$(e){let t=[];return t.push(eQ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!0})),t.push(wQ({buckets:e.started_by||[],name:`started_by`,placeholder:`Started By`})),t.push(eQ({buckets:e.run_type||[],name:`run_type`,placeholder:`Mode`,multiple:!0})),t.push(eQ({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 t$({facets:e,filters:r,setFilters:i}){let a=e$(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 n$=VZ([`name`,`role`,`tags`]);function r$(e,t){let n=e[t];return Array.isArray(n)?n:[]}function i$(e){let t=r$(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:r$(e,`tags`).map(e=>({label:e._id,value:e._id}))};return n.push(r),n}function a$(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(!n$(t.name))return;let n=t.name;BZ(e,n,zZ(t))}}),e.search()}}function o$({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=i$(e),u=a$(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 s$({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 c$=VZ([`run_ids`,`interaction`,`environment`,`tags`,`model`,`status`,`finish_reason`,`start`,`end`,`workflow_run_ids`,`workflow_ids`]);function l$(e){return e.filter(e=>e._id!==null)}function u$(e){let t=[];if(t.push({name:`run_ids`,placeholder:`Run ID`,type:`text`,multiple:!1}),e.interactions){let n=XZ({buckets:l$(e.interactions),name:`interaction`,placeholder:`Interactions`});t.push(n)}if(e.environments){let n=s$({buckets:l$(e.environments),name:`environment`});t.push(n)}if(t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),e.models){let n=eQ({buckets:l$(e.models),name:`model`});t.push(n)}if(e.statuses){let n=eQ({buckets:l$(e.statuses),name:`status`});t.push(n)}if(e.finish_reason){let n=eQ({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 d$(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(!c$(t.name))return;let n=t.name,r=zZ(t);(n===`run_ids`||n===`workflow_run_ids`||n===`workflow_ids`)&&!Array.isArray(r)&&(r=[r]),BZ(e,n,r)}}),e.search()}}function f$({facets:e,search:r,actions:i,selectionCount:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=G([]),f=u$(e),p=d$(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(Sy,{className:`size-5`})})]})]}),h.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}function p$({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:ZZ,options:n,value:c,onChange:s,by:`_id`,placeholder:i})}function m$({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 h$(e){return`${e.name} (${e.count})`}function g$({search:e,buckets:n,placeholder:r=`Filter by Type`,className:i}){let[a,o]=G([]),{registry:s}=MQ(),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:h$,options:a,value:u,onChange:l,by:`_id`,placeholder:r})}function _$(e){let t=[];return t.push(eQ({buckets:e.tags||[],name:`tags`,placeholder:`Tags`,multiple:!0})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function v$({facets:e,filters:r,setFilters:i}){let a=_$(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 y$=VZ([`search_term`,`status`,`initiated_by`,`start`,`end`,`has_reported_errors`]);function b$(e){let t=[];if(t.push({placeholder:`Workflow Name or Workflow Run ID`,name:`search_term`,type:`text`,options:[]}),e.status){let n=eQ({buckets:e.status||[],name:`status`,placeholder:`Status`});t.push({...n,name:`status`})}if(e.initiated_by){let n=wQ({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 x$(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!y$(t.name))return;let n=t.name,r=zZ(t);if(n===`has_reported_errors`){let t=Array.isArray(r)?r[0]:r;(t===`true`||t===`false`)&&BZ(e,n,t===`true`)}else typeof r==`string`&&BZ(e,n,r)}}),e.search()}}function S$({facets:e,search:r}){let[i,a]=G([]),o=b$(e),s=x$(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 C$(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function w$({facets:e,filters:r,setFilters:i}){let a=C$(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 T$=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 E$=dt(void 0);function D$(){let e=_t(E$);if(!e)throw Error(`useObjectSelection must be used within a ObjectSelectionProvider`);return e}function O$(){return _t(E$)}function k$({value:e,collectionId:n,children:r}){let[i,a]=G();return H(()=>{let t=new T$(e,n,{},a);a(t)},[n,e]),i&&t(E$.Provider,{value:i,children:r})}Q();const A$=dt(void 0);function j$({onFilter:e,children:n}){return t(A$.Provider,{value:e,children:n})}function M$(){return _t(A$)}const N$=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function P$({field:r,value:i,label:a,copyContent:s}){let c=M$(),l=Array.isArray(i)?i.length>0:i!==void 0&&i!==``;return n(e,{children:[s!==void 0&&s!==``&&t(x,{content:s,className:N$}),l&&i!==void 0&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${a}`,className:N$,onClick:e=>{e.stopPropagation(),c?.(r,i)},children:t(g_,{className:`size-3`})})]})}const F$=`text/csv`,I$=`image/`,L$=`application/pdf`,R$=`video/`,z$=[`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/msword`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.ms-powerpoint`],B$=e=>e===F$||F$.includes(e),V$=e=>e.startsWith(I$)||I$.includes(e),H$=e=>e===L$||L$.includes(e),U$=e=>e.startsWith(R$)||R$.includes(e),W$=e=>z$.includes(e);function G$(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=`
1285
+ `}),s===`stacked`&&t(`div`,{className:z(`sticky top-0 z-10`,b&&`hidden`),children:t(iq,{workstreams:pe,activeWorkstream:R,onSelectWorkstream:_e,count:ye,completionStatus:at})}),ce&&R!==`all`&&me&&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:I(`agent.backToMainAgent`),"aria-label":I(`agent.backToMainAgent`),onClick:ve,children:t(jm,{className:`size-4`,"aria-hidden":`true`})}),t(`div`,{className:`min-w-0 flex-1 truncate text-sm font-medium text-foreground`,children:me})]})}),be.length===0&&He.length===0&&!Ae&&!(ce&&Qe)?R===`all`&&Xe?t(`div`,{className:`flex-1 px-2 py-6 sm:px-4`,children:t(Xq,{label:I(`agent.preparing`),timestamp:ke.current,className:x})}):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:I(R===`all`?`agent.waitingForAgentResponse`:`agent.noMessagesInWorkstream`)})}):n(`div`,{className:z(`flex-1 flex flex-col justify-start w-full max-w-full`,ce?`gap-6 px-2 py-6 sm:px-4`:`gap-3 pb-4`,S),children:[Me&&t(Yq,{data:E,schema:D,title:O,template:k,prependFriendlyMessage:T,timestamp:be[0]?.timestamp??Date.now(),isSummaryView:ce,messageItemClassNames:f,messageStyleOverrides:p,StoreLinkComponent:C,CollectionLinkComponent:w},`initial-request`),et&&t(Xq,{label:$e,timestamp:it,className:x}),s===`stacked`?n(e,{children:[Ye.map((e,n)=>{let r=n===Ye.length-1;if(e.type===`resource_summary`)return t(nK,{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&&!dU.includes(n.type)&&!i;return h?.includes(s)?null:t($J,{status:e.toolStatus,children:t(eY,{children:t(ZK,{...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)})})},CJ(e))}if(e.type===`streaming`)return t($J,{children:t(cK,{...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)})},CJ(e));{let i=e.message;if(Ee(i)||De(i))return null;if(mU(i))return t($J,{children:t(ZJ,{message:i,startTimestamp:wJ(Ye,n)??i.timestamp,endTimestamp:i.timestamp})},SJ(i,`stopped`));let a=!c&&r&&!dU.includes(i.type);return sq(i)?t(eY,{children:t(TG,{message:i,batchData:i.details,isRunning:!i.details.completed_at,..._})},`batch-${i.details.batch_id}-${i.timestamp}`):t($J,{status:`message`,children:t(eY,{children:t(YG,{...f,message:i,showPulsatingCircle:a,onSendMessage:u,onOpenArtifact:d,requestInputAnswered:gW(i,xe),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:C,CollectionLinkComponent:w,feedbackAgentRunId:y})})},SJ(i))}}),He.map(({id:e,data:n})=>t($J,{children:t(cK,{...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}`)),Xe&&He.length===0&&!et&&t($J,{children:n(`div`,{className:z(`flex items-center gap-2 py-2 text-sm text-muted`,x),children:[t(FW,{size:`sm`,color:`blue`}),t(`span`,{children:I(`agent.working`)})]})})]}):n(e,{children:[qe.map(e=>{if(e.type===`resource_summary`)return t(nK,{resources:e.resources,workflowRunId:v,className:`my-2`},e.key);if(e.type===`work`){if(h?.includes(s))return null;let n=gq(e.messages);return t(QJ,{label:_q(e.isActive),status:e.status,timestamp:e.startTimestamp,durationSeconds:e.isActive?void 0:uq(e.startTimestamp,e.endTimestamp),showElapsed:!0,details:n?void 0:e.messages,defaultExpanded:e.isActive&&!n,disablePreambleCollapse:e.isActive,className:x,onSendMessage:u,answeredToolApprovalRequestInputKeys:Ce,resolvedToolApprovalKeys:Se},`work-${e.id}-${e.isActive?`active`:`done`}-${e.status}`)}if(e.type===`stopped`)return t(ZJ,{message:e.message,startTimestamp:e.startTimestamp,endTimestamp:e.endTimestamp},SJ(e.message,`stopped-summary`));let n=e.message;return Ee(n)||De(n)?null:sq(n)?t(eY,{children:t(TG,{message:n,batchData:n.details,isRunning:!n.details.completed_at,..._})},SJ(n,`batch`)):t(eY,{children:t(Bq,{message:n,onSendMessage:u,onOpenArtifact:d,onSelectWorkstream:_e,requestInputAnswered:gW(n,xe),StoreLinkComponent:C,CollectionLinkComponent:w,feedbackAgentRunId:y})},SJ(n,`summary`))}),He.map(({id:e,data:n})=>t(XJ,{text:n.text,workstreamId:n.workstreamId,artifactRunId:v},`streaming-incomplete-${e}`)),Ze&&t(`div`,{className:z(`mx-auto w-full max-w-3xl px-1 text-sm text-muted`,x),"data-testid":`post-tool-thinking-indicator`,children:I(`agent.thinking`)}),Qe&&!et&&t(QJ,{label:$e,status:`running`,timestamp:it,showElapsed:!0,className:x})]}),t(`div`,{ref:a,className:`h-2`})]})]})}const rY=(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},iY=ot.memo(nY);Q();function aY(e){return e?new Map(e.streamingMessages.map((e,t)=>[e.id??e.activityId??`stream-${t}`,e])):new Map}function oY(e,t){return e?.find(e=>e.cursor===t)}function sY(e,t){if(t===0||e===`live`)return`live`;let n=TC(e,t);return n>=t-1?`live`:n+1}function cY(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 lY(e){return cY(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function uY(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 dY({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(()=>wC(h,m.length)),v=r??g,y=l??`sliding`,[b,x]=G(!!s),[S,C]=G(0),w=W(null),T=U(()=>OC(m,v,!0),[v,m]),E=T.displayedMessages,D=U(()=>aY(oY(e.streamingFrames,T.cursor)),[e.streamingFrames,T.cursor]),O=V(e=>{let t=wC(e,m.length);r===void 0&&_(t),a?.(t)},[r,m.length,a]);H(()=>{let e=wC(v,m.length);e!==v&&O(e)},[v,m.length,O]),H(()=>{if(!s||s<=0||!b)return;let e=window.setInterval(()=>{let e=sY(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&&!pU(E),A=U(()=>_W(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`;uY(`${lY(j)||`agent-chat`}-${lY(n)}.json`,t)},[e,m.length,j]),N=V(()=>{O(sY(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(pg,{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?Qv:uy,{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(PC,{cursor:T.cursor,messages:m,onChangeCursor:O})}),t(iY,{messages:E,isCompleted:k,streamingMessages:D,bottomRef:w,artifactRunId:e.metadata?.agent_run_id??`agent-chat-fixture`,viewMode:y,renderRequestInputControls:!A}),A&&t(yW,{message:A,onSendMessage:N,isLoading:!1})]})}function fY({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-primary rounded-full animate-[jumping_1s_infinite_ease-in-out] hover:bg-primary`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-primary rounded-full animate-[jumping_1s_0.3s_infinite_ease-in-out] hover:bg-primary`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}}),t(`div`,{className:`w-2 h-2 bg-primary rounded-full animate-[jumping_1s_0.6s_infinite_ease-in-out] hover:bg-primary`,style:{transform:`translateY(0)`,animationRange:`0px -8px`}})]})}function pY(){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!==`none`&&e.auth!==`api_key`&&n.includes(e.id)),s=i.filter(e=>e.auth===`none`||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}:${e.auth}:${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:e.auth===`none`?`none`:`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=>{if(t.authType===`none`)return 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 mY(e,t){return t?.length?e.memberIds.every(e=>t.includes(e)):!1}function hY(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 gY(e){return e.authType===`none`||e.authStatus?.authenticated===!0}function _Y(e,t){return e.filter(e=>gY(e)&&!mY(e,t)).length}function vY(e,t){return e.filter(e=>gY(e)&&!mY(e,t)).map(e=>e.label)}Q();function yY({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(DT,{isOpen:e,onClose:r,size:`md`,className:`max-w-[92vw] sm:max-w-[620px] lg:max-w-[620px]`,children:[t(OT,{children:f(`mcpConnections.title`)}),n(kT,{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(wO,{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=!mY(e,c),i=gY(e),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?Q_:Y_,{className:`size-4 shrink-0 ${i?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(mT,{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(yT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:f(`mcpConnections.checkingStatus`),children:t(wO,{className:`size-3`})}):a?t(DO,{appId:e.appId,collectionId:e.representativeId,collectionName:e.label,authenticated:e.authStatus?.authenticated,onAuthChange:p,variant:`compact`,showDisconnect:!0,readOnly:d}):t(CT,{variant:`outline`,className:`h-6 w-32 justify-center px-2 text-xs`,children:e.authType===`none`?f(`mcpConnections.noAuthentication`):e.authType===`api_key`?f(`mcpConnections.apiKey`):f(`mcpConnections.managedByApp`)}),l&&t(SO,{size:`sm`,value:r,onChange:t=>l(hY(e,c,t)),disabled:d,"aria-label":f(r?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:e.label})})]})]},e.key)})})]})]})}Q();function bY({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}=pY(),[m,h]=G(!1);if(!d&&u.length===0)return null;let g=_Y(u,r),_=vY(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(yT,{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(CT,{variant:`success`,children:g})]})]}),t(yY,{isOpen:m,onClose:()=>h(!1),groups:u,loading:d,reload:p,statusLoading:f,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}function xY({disabledCollections:e,onChange:r,onConnectionChange:i,readOnly:a=!1}){let{t:o}=K(),{groups:s,loading:c,statusLoading:l,reload:u}=pY();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(wO,{className:`size-4`}),t(`span`,{children:o(`mcpConnections.label`)})]}):t(`div`,{className:`space-y-1`,children:s.map(i=>{let s=!mY(i,e),c=gY(i),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?Q_:Y_,{className:`size-4 shrink-0 ${c?`text-success`:`text-muted`}`,"aria-hidden":`true`}),t(mT,{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(yT,{variant:`outline`,size:`sm`,disabled:!0,className:`h-6 w-32 justify-center px-2 text-xs`,title:o(`mcpConnections.checkingStatus`),children:t(wO,{className:`size-3`})}):u?t(DO,{appId:i.appId,collectionId:i.representativeId,collectionName:i.label,authenticated:i.authStatus?.authenticated,onAuthChange:d,variant:`compact`,showDisconnect:!0,readOnly:a}):t(CT,{variant:`outline`,className:`h-6 w-32 justify-center px-2 text-xs`,children:i.authType===`none`?o(`mcpConnections.noAuthentication`):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(SO,{size:`sm`,value:s,onChange:t=>r(hY(i,e,t)),disabled:a,"aria-label":o(s?`mcpConnections.deactivateAria`:`mcpConnections.activateAria`,{name:i.label})})]})]},i.key)})})}function SY({disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o=!1}){let{t:s}=K(),{groups:c,loading:l,statusLoading:u,reload:d}=pY(),[f,p]=G(!1);if(!l&&c.length===0)return null;let m=_Y(c,r);return n(e,{children:[t(tO,{align:`left`,trigger:t(yT,{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(nO,{onClick:()=>p(!0),isDisabled:l,children:[t(`span`,{children:s(`mcpConnections.title`)}),m>0&&t(CT,{variant:`success`,children:m})]})}),t(yY,{isOpen:f,onClose:()=>p(!1),groups:c,loading:l,reload:d,statusLoading:u,disabledCollections:r,onChange:i,onConnectionChange:a,readOnly:o})]})}const CY=/(^|\/)(tool-inputs|tool-results|archive)(\/|$)/,wY=/(^|\/)process\/(history|state)(\/|$)/,TY=[/conversation\.json$/,/^conversation-checkpoint-\d+\.json$/,/^tools\.json$/,/^tool-input-refs\.json$/,/^toolu[_-]/i];function EY(e){if(CY.test(e)||wY.test(e))return!0;let t=e.split(`/`).pop()??e;return TY.some(e=>e.test(t))}function DY(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 OY(e,t){let n=`agents/${t}/`,r=e.indexOf(n);return r===-1?e.split(`/`).pop()??e:e.slice(r+n.length)}function kY(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=>OY(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=>!EY(e)),[i,r]),h=U(()=>DY(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 AY(){return jY||=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}),jY}var jY,MY,NY,PY=Y((()=>{MY=ht(()=>AY().then(({Document:e})=>({default:e}))),NY=ht(()=>AY().then(({Page:e})=>({default:e})))}));function FY({className:e,size:n=`md`}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(sv,{className:`${{sm:`w-4 h-4`,md:`w-6 h-6`,lg:`w-8 h-8`}[n]} animate-spin text-muted`})})}function IY({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(FY,{className:`py-4`,size:`md`}),t(ut,{fallback:null,children:t(MY,{file:e,onLoadSuccess:({numPages:e})=>{d(!1),c?.(e)},onLoadError:e=>{d(!1),p(e),l?.(e)},loading:null,children:t(NY,{pageNumber:r,width:i,renderTextLayer:o,renderAnnotationLayer:s,loading:t(FY,{className:`py-4`,size:`sm`})})})})]})}function LY({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(WY.Provider,{value:h,children:e?t(ut,{fallback:t(FY,{className:`py-4`,size:`md`}),children:t(MY,{file:e,onLoadSuccess:p,onLoadError:m,loading:t(FY,{className:`py-4`,size:`md`}),children:r((e,n)=>t(NY,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(FY,{className:`py-4`,size:`sm`})},e))})}):t(FY,{className:`py-4`,size:`md`})})}function RY(){return _t(WY)}function zY({pageNumber:e,width:n,className:r}){let i=RY(),a=i?.pageDimensions?.aspectRatio??GY,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(FY,{size:`md`})}):t(`div`,{className:r,children:t(NY,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(FY,{className:`py-4`,size:`sm`})})})}function BY({pageNumber:e,width:n,isSelected:r,onSelect:i,renderThumbnail:a,aspectRatio:o=GY,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(NY,{pageNumber:e,width:n,renderTextLayer:!1,renderAnnotationLayer:!1,loading:t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d},children:t(FY,{size:`sm`})})}):t(`div`,{className:`flex items-center justify-center bg-muted`,style:{height:d,width:n||`100%`},children:t(`span`,{className:`text-muted text-xs`,children:e})});return t(`div`,{ref:c,children:a({pageNumber:e,isSelected:r,pageElement:f,onSelect:i})})}function VY(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 HY({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(GY),d?.(GY)}},[d,m]),w=y??GY,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||VY(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(FY,{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(FY,{className:`py-4`,size:`md`}),children:t(MY,{file:r,onLoadSuccess:C,onLoadError:S,loading:t(FY,{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(BY,{pageNumber:r,width:s,isSelected:r===o,onSelect:()=>c(r),renderThumbnail:l,aspectRatio:w})},r)}),O>0&&t(`div`,{style:{height:O}})]}):t(FY,{className:`py-4`,size:`md`})})})})}function UY({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(FY,{className:`py-8`,size:`lg`}),t(ut,{fallback:null,children:t(MY,{file:e,onLoadSuccess:({numPages:e})=>{d(e),p(!1)},onLoadError:e=>{p(!1),h(e)},loading:null,children:t(NY,{pageNumber:Math.min(r,u||1),width:i,height:a,renderTextLayer:s,renderAnnotationLayer:c,loading:t(FY,{className:`py-8`,size:`md`})})})})]})}var WY,GY,KY=Y((()=>{Q(),PY(),WY=dt(null),GY=210/297}));function qY({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(QY),[x,S]=G(XY),[C,w]=G(null),T=W(null),E=_?Math.round(_*y/100):void 0,D=V(()=>{let e=ZY.findIndex(e=>e>=y);e===-1&&(e=ZY.length-1);let t=Math.min(e+1,ZY.length-1);b(ZY[t])},[y]),O=V(()=>{let e=ZY.findIndex(e=>e>=y);e===-1&&(e=ZY.length-1);let t=Math.max(e-1,0);b(ZY[t])},[y]),k=V(()=>{b(QY)},[]),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(Ph,{className:`size-4`})}),n(`div`,{className:`absolute start-2 flex items-center gap-x-1`,children:[t(YY,{zoom:y,onZoomIn:D,onZoomOut:O,onFitToView:k,canZoomIn:y<ZY[ZY.length-1],canZoomOut:y>ZY[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(JY,{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(HY,{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 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(Sh,{className:`size-4`})})})]})}function JY({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`,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 YY({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(Lv,{})}),n(`span`,{className:`text-xs text-muted min-w-[32px] text-center`,children:[e,`%`]}),t(o,{variant:`ghost`,size:`xs`,onClick:r,isDisabled:!s,title:l(`pdf.zoomIn`),children:t(py,{})}),t(o,{variant:`ghost`,size:`xs`,onClick:a,title:l(`pdf.fitToWidth`),className:e===QY?`text-muted/40`:void 0,children:t(yv,{})})]})}var XY,ZY,QY,$Y=Y((()=>{Q(),KY(),XY=210/297,ZY=[50,75,100,125,150,200,300],QY=100}));function eX({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(ix,{className:`size-4`})})}),t(qY,{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(qY,{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 hover:text-foreground hover:bg-muted`,onClick:()=>v(!0),children:t(gv,{className:`size-4`})})})}):t(`div`,{className:`flex items-center justify-center h-full text-muted`,children:s(`pdf.noPdfAvailable`)})}var tX=Y((()=>{Q(),$Y()})),nX=hr({UniversalDocumentViewer:()=>DX});function rX(e){return e.fileName||e.title||e.artifact?.path.split(`/`).pop()||e.sourcePath?.split(`/`).pop()||`Document`}function iX(e){let t=e.split(`?`)[0]||e;return t.includes(`.`)&&t.split(`.`).pop()?.toLowerCase()||``}function aX(e){return e.contentType===`application/pdf`||e.extension===`pdf`}function oX(e){return[`md`,`markdown`].includes(e.extension)||[`text/markdown`,`text/x-markdown`].includes(e.contentType||``)}function sX(e){return e.contentType?.startsWith(`image/`)||[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`].includes(e.extension)}function cX(e){return e.contentType===`text/html`||[`html`,`htm`].includes(e.extension)}function lX(e){return[`application/xml`,`text/xml`].includes(e.contentType||``)||e.extension===`xml`}function uX(e){return e.contentType?.startsWith(`text/`)||[`css`,`csv`,`json`,`txt`,`tsx`,`ts`,`jsx`,`js`,`xml`,`yaml`,`yml`].includes(e.extension)}function dX(e){return[`tsx`,`jsx`].includes(e.extension)}function fX(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 pX({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 mX({message:e}){return n(`div`,{className:`flex h-full min-h-64 flex-col items-center justify-center gap-2 text-muted`,children:[t(i_,{className:`size-8`}),t(`span`,{className:`text-sm`,children:e})]})}function hX(e,n){if(e.Component){let r=e.Component;return t(r,{context:n})}return e.render?.(n)??null}function gX(e,t){return e.includes(`.`)?e.replace(/\.[^/.]+$/,t):`${e}${t}`}function _X(e){return e.split(`/`).pop()||e}function vX(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function yX(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function bX(e){if(e!==void 0)return e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`}function xX(e){return Array.isArray(e)?e.length:0}function SX(e){try{let t=vX(JSON.parse(e));if(!t)return;let n=vX(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:yX(n.width),height:yX(n.height)}:void 0,dependencies_reused:typeof t.dependencies_reused==`boolean`?t.dependencies_reused:void 0,status:yX(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:vX(t.timings_ms),error:t.error}}catch{return}}async function CX(e,t){let n=await fetch(e);if(!n.ok)throw Error(`Failed to load ${t}: ${n.statusText}`);return n.text()}function wX({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}${_X(i)}`:n}function TX({metadata:e}){if(!e)return null;let r=yX(e.timings_ms?.total_before_cleanup),a=xX(e.console_errors)+xX(e.page_errors)+xX(e.failed_requests)+xX(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]}),bX(r)&&n(`div`,{children:[`Total `,bX(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 EX({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,_X(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=gX(e,`.png`),r=gX(e,`.render.json`);async function i(){u({isLoading:!0});let i,a,o=n;try{i=SX(await CX(await d(r,`inline`),_X(r))),o=wX({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(P_,{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(sv,{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(TX,{metadata:l.metadata}),t(`div`,{className:`p-3`,children:t(pX,{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(TX,{metadata:l.metadata}),t(pX,{content:c,extension:e.extension})]})]})]})}function DX({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(()=>rX(e),[e]),g=U(()=>iX(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 ${rX(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&&(oX(P)||cX(P)||lX(P)||uX(P)),L=!F&&(aX(P)||sX(P)),ee={source:e,fileName:h,extension:g,contentType:e.contentType,target:`pdf`},te=!F&&!P.url?s.find(e=>e.target===`pdf`&&e.canConvert(ee)):void 0,R=!F&&!P.url&&(fX(P)||!!te)&&(!!te||!!u);H(()=>{let t=!1,n=e;E(null),v(n.url),b(n.content),S(null);async function r(){if(I||L||R){w(!0);try{if(R){let e=te?await te.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,R,I,L,D,j,te,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(sv,{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(Lh,{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?hX(F,ne):(aX(ne)||x?.contentType===`application/pdf`)&&ne.url?t(eX,{url:ne.url,className:`h-full`}):sX(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`})}):oX(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||``})}):cX(ne)?t(`iframe`,{title:h,className:`h-full min-h-96 w-full bg-white`,sandbox:``,srcDoc:ne.content||``}):lX(ne)?t(`div`,{className:`px-4 py-2`,children:t(Rt,{xml:ne.content||``,collapsible:!0})}):dX(ne)?t(EX,{context:ne}):uX(ne)?t(pX,{content:ne.content,extension:g}):fX(ne)&&!te&&!u?t(mX,{message:`This file needs a PDF rendition before it can be previewed.`}):t(mX,{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 OX=Y((()=>{Q(),tX()}));Q();const kX=ot.lazy(async()=>({default:(await Promise.resolve().then(()=>(OX(),nX))).UniversalDocumentViewer})),AX=new Set([`md`,`markdown`,`mdx`,`txt`]);function jX(e){let t=e.split(`.`).pop()?.toLowerCase();return t!==void 0&&AX.has(t)}function MX(e){return e.replace(/[_-]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function NX({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(uh,{className:`size-3.5 shrink-0 text-muted`}):t(gh,{className:`size-3.5 shrink-0 text-muted cn-rtl-flip`}),t(p?u_:p_,{className:`size-4 shrink-0 text-info`}),t(`span`,{className:`min-w-0 truncate font-medium`,title:e.path,children:MX(e.name)})]}),p&&e.children.map(e=>t(NX,{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(i_,{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(sv,{className:`size-3.5 animate-spin text-info`}):t(Og,{className:`size-3.5`})})]})}function PX(e){return e.reduce((e,t)=>t.isDirectory?e+PX(t.children):e+1,0)}function FX(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=FX(e.children,n);return t?[{...e}]:r.length>0?[{...e,children:r}]:[]}):e}function IX(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 LX(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 RX({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(jm,{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(sv,{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(sh,{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(Oy,{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(ty,{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(Og,{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 zX({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 BX({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}=kY(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(()=>FX(h,N),[h,N]),F=U(()=>PX(P),[P]),I=vt(),L=V(async e=>{if(r){C(e);try{let{url:t}=await d.files.getArtifactDownloadUrl(r,e,`attachment`);IX(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(jX(e)){j(e);return}T(e)},[j]),te=r&&w?{title:w.split(`/`).pop()||w,fileName:w.split(`/`).pop()||w,contentType:LX(w),artifact:{runId:r,path:w}}:null;return r?y&&_===0?t(zX,{icon:t(sv,{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(Sy,{className:`size-3.5 me-1.5`}),u(`agent.retry`)]}),children:[t(`span`,{className:`break-all text-muted`,children:b}),` `,t(`br`,{})]})}):_===0?t(zX,{icon:t(Uv,{className:`mb-2 size-8`}),action:n(o,{variant:`ghost`,size:`sm`,className:`mt-2`,onClick:x,children:[t(Sy,{className:`size-3.5 me-1.5`}),u(`agent.refresh`)]}),children:u(`agent.noArtifactsYet`)}):A?t(RX,{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(Sy,{className:`size-3.5 ${y?`animate-spin`:``}`})})]})]}),t(`label`,{htmlFor:I,className:`sr-only`,children:u(`form.filter`)}),t(R,{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(NX,{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`)})}),te&&n(se,{isOpen:!!w,onClose:()=>T(null),size:`xl`,className:`h-[90vh] p-0`,description:`Artifact preview`,children:[t(ue,{show:!1,children:te.fileName}),t(ce,{className:`h-full max-h-none p-0`,children:t(ot.Suspense,{fallback:t(p,{className:`h-full`,children:t(sv,{className:`size-6 animate-spin text-muted`})}),children:t(kX,{source:te,className:`h-full`,showHeader:!0,onDownload:()=>w&&void L(w)})})})]})]}):t(zX,{icon:t(Uv,{className:`mb-2 size-8`}),children:`No run selected`})}const VX=ot.memo(BX);Q();function HX(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function UX(e){if(!HX(e))return;let t=e.browseruse??e.browser_use;if(!HX(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 WX(e){let t=new Map;for(let n of e){let e=UX(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 GX(e){return e.replace(/^artifact:\/\//,``).replace(/^artifact:/,``).replace(/^\/+/,``)}function KX(e){return e?e.replace(/_/g,` `):`browser`}function qX({state:e,runId:r,className:a,compact:o}){let{t:s}=K(),{client:c}=q(),l=eC(),{openImage:u}=rG(),[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&&GX(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=GX(p);try{let n=nC(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(Bv,{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:[`· `,KX(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(Pg,{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(P_,{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(Bv,{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:KX(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(P_,{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(Pg,{className:`size-3`})})]})]})}Q();function JX({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(jm,{className:`size-4 cn-rtl-flip`})}),n(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[t(Qg,{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(Pg,{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(sv,{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(Qg,{className:`size-8 mb-2`}),t(`span`,{className:`text-sm`,children:u(`agent.noContentAvailable`)})]})})]})}const YX=ot.memo(JX);Q();function XX({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(YX,{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(R,{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(Qg,{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(Pg,{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 ZX=ot.memo(XX);Q();function QX({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(sg,{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(ph,{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(gh,{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=tg,f=`text-muted`;c===`in_progress`?(d=ug,f=`text-info`):c===`completed`&&(d=Uh,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=tg,a=`text-muted`,o=u(`agent.pending`);return r===`in_progress`?(i=ug,a=`text-info`,o=u(`agent.inProgress`)):r===`completed`&&(i=Uh,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 $X=ot.memo(QX);Q();function eZ({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 tZ({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(sv,{className:`size-4 animate-spin text-info`});case mn.READY:return t(Uh,{className:`size-4 text-success`});case mn.ERROR:return t(Qh,{className:`size-4 text-destructive`});default:return t(Qg,{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(eZ,{icon:t(Qg,{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 nZ=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 rZ({workstreams:e,messages:r,runId:a}){let{t:s}=K(),{client:c}=q(),l=nt(),u=U(()=>WX(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 bU(c,e);t&&window.open(t,`_blank`)}catch{l({status:`error`,title:s(`agent.failedToDownload`)})}},[c,s,l]);return e.length===0?t(eZ,{icon:t(K_,{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?YH(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(nZ,{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`,rU(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:YH(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(nZ,{title:s(`agent.browserWidgetRenderError`),description:d,compact:!0,children:t(qX,{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(ig,{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(pg,{className:`size-3 me-1`}),s(`agent.download`)]})]})]})]})})},e.launch_id)})})]})}function iZ({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(nZ,{title:A(`agent.panelRenderError`,{name:e}),description:A(`agent.panelRenderErrorDescription`),children:n}),[A]),te={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},R=[...T?[te]:[],{name:`plan`,label:A(`agent.plan`),content:ee(A(`agent.plan`),e?t($X,{plan:e,workstreamStatus:r||new Map,isOpen:!0,onClose:E,plans:i,activePlanIndex:a,onChangePlan:s}):t(eZ,{icon:t(K_,{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(rZ,{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(ZX,{documents:d,activeDocumentId:f??null,onSelectDocument:p,onUpdateDocumentTitle:m,refreshKey:h,runId:g}):t(eZ,{icon:t(Qg,{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(tZ,{files:_})),is_allowed:!0},{name:`artifacts`,label:A(`agent.artifacts`),content:ee(A(`agent.artifacts`),t(VX,{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=R.filter(e=>e.is_allowed===void 0||e.is_allowed===!0);return n(ze,{tabs:R,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(ix,{className:`size-4`})})]}),t(Ve,{className:`flex-1 min-h-0 pt-0 pb-0`})]})}const aZ=ot.memo(iZ);function oZ(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 sZ(e,t){let[n,r]=G([]),[i,a]=G(0),[o,s]=G(new Map),[c,l]=G(t),[u,d]=G(!1),f=W(-1),p=W(new Set);H(()=>{e.length===0&&(r([]),a(0),s(new Map),d(!1),f.current=-1,p.current.clear())},[e.length]);let m=V(e=>{let n=e[e.length-1];n&&(n.type===J.TERMINATED?l(!1):l(t?!0:n.type===J.REQUEST_INPUT))},[t]);return H(()=>{if(e.length===0)return;let t=f.current+1;if(t>=e.length){m(e);return}let n=!1,i=[],o=[];for(let r=t;r<e.length;r++){let t=e[r];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 r=typeof t.timestamp==`number`?t.timestamp:new Date(t.timestamp).getTime();if(!p.current.has(r)){p.current.add(r),n=!0,i.push({plan:e,timestamp:r});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`)}}),o.push({timestamp:r,statusMap:t})}}}catch(e){console.error(`Failed to parse plan from message:`,e)}}f.current=e.length-1,n&&i.length>0&&(r(e=>[...[...i].reverse(),...e]),a(0),d(!0),o.length>0&&s(e=>{let t=new Map(e);for(let e of o)t.set(e.timestamp,e.statusMap);return t})),m(e)},[e,m]),H(()=>{if(n.length===1&&!u&&!sessionStorage.getItem(`plan-panel-shown`)){let e=setTimeout(()=>{d(!0),sessionStorage.setItem(`plan-panel-shown`,`true`)},500);return()=>clearTimeout(e)}},[n.length,u]),{plans:n,activePlanIndex:i,setActivePlanIndex:a,workstreamStatusMap:o,showInput:c,showSlidingPanel:u,setShowSlidingPanel:d}}function cZ(e,t){return{...e,details:{...e.details??{},_deliveryStatus:t}}}function lZ(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 uZ(e,t){let n=e?.[t];return typeof n==`string`&&n?n:void 0}function dZ(e){return e?.streaming_id_scope===`workflow_run`}function fZ(e){return[J.COMPLETE,J.IDLE,J.TERMINATED,J.REQUEST_INPUT].includes(e.type)}function pZ(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||fZ(e)||On(e).length>0}function mZ(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 hZ(e,t){if(e.find(e=>e.timestamp===t.timestamp))return e;if(!t.details?._optimistic&&(t.type===J.QUESTION||mU(t))){let n=typeof t.details?.ack==`string`?t.details.ack:void 0,r=n?cZ(t,`consumed`):t;if(n){let i=e.filter(e=>e.type!==t.type&&!mU(e)||!e.details?._optimistic||lZ(e)!==n);return uU(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 uU(r,t),r}}}let n=[...e];return uU(n,t),n}function gZ(e){let t=e.details,n=uZ(t,`streaming_id`),r=uZ(t,`activity_id`);return n&&dZ(t)?n:r??n}function _Z(e){let t=e.details,n=uZ(t,`streaming_id`),r=uZ(t,`activity_id`),i=[];return n&&dZ(t)&&i.push(n),r&&i.push(r),[...new Set(i)]}function vZ(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(!pU(r))},[r]),H(()=>{lU(`stream state`,{agentRunId:t,messageCount:r.length,streamingCount:x.size,initialHistoryStatus:s,isCompleted:a,lastDeliveredTs:b.current,first:mZ(r[0]),last:mZ(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 lU(`stream start`,{agentRunId:t,isNewConversation:n,since:a,streamNonce:g}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(lU(`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),lU(`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=gZ(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=_Z(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(),pZ(e)&&i(t=>hZ(t,e))},a,r.signal,{closeOnIdle:!1,onHistoryLoaded:e=>{if(r.signal.aborted)return;let n=e.filter(pZ),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]))),lU(`history loaded`,{agentRunId:t,count:e.length,timelineCount:n.length,since:a,first:mZ(e[0]),last:mZ(e[e.length-1])}),c(e.length>0?`has_messages`:`empty`),n.length>0&&i(e=>n.reduce((e,t)=>hZ(e,t),e))},onHistoryError:e=>{r.signal.aborted||(lU(`history error`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),c(`error`))}}).then(()=>{if(!r.signal.aborted)return lU(`stream resolved`,{agentRunId:t}),e.agents.getInternals(t).then(e=>{r.signal.aborted||(lU(`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||(lU(`stream failed`,{agentRunId:t,error:e instanceof Error?e.message:String(e)}),console.error(`Failed to stream agent messages:`,e))}),()=>{lU(`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&&lZ(n)===e?cZ(n,t):n))},[]),removeOptimisticMessages:V(e=>{i(t=>t.filter(t=>!e(t)))},[]),reconnect:v,agentRunStatus:l,workflowRunId:d,serverFileUpdates:m}}function yZ(e){if(typeof e==`string`&&e.trim().length>0)return e}function bZ(e,t){let n=yZ(e.revision_root_id)||yZ(e.revision_root)||yZ(e.root_document_id)||yZ(e.root_id);if(n)return n;let r=e.revision_info;if(r&&typeof r==`object`){let e=yZ(r.root);if(e)return e}return t}function xZ(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 SZ(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=yZ(e.document_id),r=yZ(e.updated_document_id)||t,a=e.title;if(r){let s=bZ(e,t||r),l={id:r,title:a||`Document`,revisionRootId:s};n(e=>{let t=e.findIndex(e=>xZ(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 CZ(e){return e.type.startsWith(`image/`)}function wZ(e){if(!(!CZ(e)||typeof URL>`u`||!URL.createObjectURL))return URL.createObjectURL(e)}function TZ(e){typeof URL<`u`&&URL.revokeObjectURL&&URL.revokeObjectURL(e)}function EZ(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&&(TZ(t),d.current.delete(e))},[]);H(()=>{if(f.current!==t){f.current=t,d.current.forEach(TZ),d.current.clear(),s(new Map);let e=new Set;u.current=e,l(e)}},[t]),H(()=>()=>{d.current.forEach(TZ),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=wZ(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(TZ),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 DZ({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(Lm,{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?yh:uh,{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=ZH(r.workstream_id,r.interaction),s=n(e,{children:[t(`span`,{className:z(`size-1.5 shrink-0 rounded-full`,rU(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:YH(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(gh,{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(uh,{className:z(`size-3.5 transition-transform`,c&&`rotate-180`),"aria-hidden":`true`})]})]})]})})}const OZ=new tr({strict:!1,validateFormats:!1});function kZ(e){if(e!==Tn.virtual_lb&&e!==Tn.virtual_mediator&&e!==Tn.test)return e}var AZ=class{_listeners=new Set;snapshot;constructor(e){this.snapshot=new jZ(e,this)}subscribe=e=>(this._listeners.add(e),()=>{this._listeners.delete(e)});getSnapshot=()=>this.snapshot;notify(){this._listeners.forEach(e=>{e()})}},jZ=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).catch(()=>{this.environment=void 0})}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?kZ(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:OZ.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 MZ=dt(void 0);function NZ({children:e}){let{client:n}=q(),[r]=G(()=>new AZ(n)),i=xt(r.subscribe,r.getSnapshot);return t(MZ.Provider,{value:i,children:e})}function PZ(){let e=_t(MZ);if(!e)throw Error(`usePayloadBuilder must be used within a PayloadProvider`);return e}Q();function FZ(){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 IZ({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=FZ(),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(sg,{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`?Oy:Tv,{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(Oy,{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(Tv,{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(Qm,{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(Pg,{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(Sv,{className:z(`size-4`,r===`full`&&`me-1.5`)})}),t(LZ,{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(ix,{className:`size-4`})})]});return r===`compact`?t(NZ,{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(NZ,{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(Lm,{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-muted`)})]})]}),P]})})}function LZ({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=PZ();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(jg,{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(yg,{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(yg,{className:`size-3.5 text-muted`}),` `,g(`agent.copyWorkflowRunId`)]}),p&&n(ae,{onClick:p,children:[t(L_,{className:`size-3.5 text-muted`}),` `,g(`agent.details`)]}),n(ae,{onClick:()=>{l?l():bU(v,r).then(e=>window.open(e,`_blank`))},children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.downloadConversation`)]}),f&&n(ae,{onClick:f,children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.exportAsPdf`)]}),u&&n(ae,{onClick:u,children:[t(pg,{className:`size-3.5 text-muted`}),` `,g(`agent.rewind.exportFixture`)]}),c&&a&&n(ae,{onClick:c,children:[t(ix,{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(T_,{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(ix,{className:`size-3.5`}),` `,g(`agent.cancelWorkflow`)]})]})})}function RZ(e){return typeof e==`object`&&!!e&&`value`in e}function zZ(e){return RZ(e)?e.value:e}function BZ(e){if(e.type===`stringList`)return e.value.map(e=>typeof e==`string`?e:zZ(e));if(e.multiple)return e.value.map(zZ);let t=e.value[0];return t===void 0?void 0:zZ(t)}function VZ(e,t,n){e.query[t]=n}function HZ(e){let t=new Set(e);return e=>t.has(e)}const UZ=[`sys`,`app`,`tmp`],WZ=/^[0-9a-fA-F]{24}$/;function GZ(e){let t=e.indexOf(`:`),n=t>0?e.slice(0,t):void 0;return n&&UZ.includes(n)?{type:n,label:e.slice(t+1)}:{label:e}}function KZ(e,...t){let n=[e?.name,...t].filter(e=>!!e),r=n.find(e=>!WZ.test(e));if(r)return r;let i=n[0];return i?`Deleted interaction (~${i.slice(-8)})`:void 0}function qZ(e){return!!e&&e.version===0&&e.status===gn.unknown}function JZ({interaction:e,className:n}){let r=`success`;switch(e.status){case gn.published:r=`success`;break;case gn.archived:r=`destructive`;break;case gn.code:r=`info`}let a=[e.version?`v${e.version}`:``,e.status&&e.status!==gn.unknown?e.status:``].filter(Boolean).join(` `);return a?t(i,{variant:r,className:n,children:a}):null}function YZ({interaction:r,fallbacks:a=[],fallbackNode:o=null}){let s=KZ(r,...a);if(!s)return t(e,{children:o});let{type:c,label:l}=GZ(s),u=!!r&&!qZ(r);return n(e,{children:[l,(c||u)&&n(`div`,{className:`flex items-center mt-1.5 shrink-0 gap-2`,children:[c&&t(i,{variant:`secondary`,children:c}),u&&r&&t(JZ,{interaction:r})]})]})}function XZ(e,t){return KZ(e,t)??t}function ZZ({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),{type:o,label:s}=GZ(XZ(a,r));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:s}),o&&t(i,{variant:`secondary`,className:`text-xs w-fit`,children:o}),a&&t(JZ,{interaction:a,className:`text-xs w-fit`})]}),(a?.count??0)>0&&n(`span`,{className:`ms-2 text-xs shrink-0`,children:[`(`,a?.count,`)`]})]})},filterBy:(t,n)=>XZ(e.find(e=>e._id===t),t).toLowerCase().includes(n.toLowerCase())}}function QZ(e){return`${e._id} (${e.count})`}function $Z(e){return`${e.name} (${e.count})`}function eQ({buckets:e,name:t,placeholder:n,type:r=`select`,multiple:i=!1}){return{name:t,options:e.map(e=>({label:QZ(e),value:e._id})),type:r,multiple:i,placeholder:`${n??`${t.charAt(0).toUpperCase()+t.slice(1)}`}`,allowCreate:!1}}function tQ({buckets:e,name:t,placeholder:n,type:r,multiple:i}){return eQ({buckets:e,name:t,placeholder:n,type:r,multiple:i})}Q();const nQ={},rQ={},iQ={};function aQ(e){return typeof e==`object`&&!!e&&`status`in e&&e.status===404}function oQ(e,t,n){let r=e[t];return r||(r=n().catch(n=>{throw aQ(n)||delete e[t],n}),e[t]=r),r}function sQ(e){let{client:t}=q();return Ye(()=>oQ(nQ,e,()=>t.users.retrieve(e)),{deps:[e],condition:()=>!!e})}function cQ(e){let{client:t}=q();return Ye(()=>oQ(rQ,e,()=>t.iam.groups.retrieve(e)),{deps:[e],condition:()=>!!e})}function lQ(e){let{client:t}=q();return Ye(()=>oQ(iQ,e,()=>t.apikeys.retrieve(e)),{deps:[e],condition:()=>!!e})}function uQ(){return t(`div`,{className:`size-8`})}function dQ({showTitle:e=!1,size:i=`md`}){let{t:a}=K();return t(CQ,{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 fQ({showTitle:e=!1,size:r=`md`}){let{t:i}=K();return t(CQ,{title:i(`user.allProjectMembers`),description:i(`user.allProjectMembersDescription`),children:n(`div`,{className:`flex gap-2 items-center`,children:[t(Ub,{className:`size-4`,size:r}),e&&t(`div`,{className:`text-sm font-semibold ps-2`,children:i(`user.allProjectMembers`)})]})})}function pQ({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(CQ,{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 mQ({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(CQ,{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-background`,size:o}),t(r,{name:i,size:o,className:`border-2 border-background`})]}),a&&n(`div`,{className:`text-sm font-semibold truncate`,children:[`Agent (`,i,`)`]})]})})}function hQ({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=sQ(o||``),m=lQ(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`,children:[`Key ID: `,g.id]})]}),!h&&!g&&n(e,{children:[t(`div`,{children:u(`user.serviceAccountDescription`)}),n(`div`,{className:`text-foreground dark:text-muted text-sm`,children:[t(`span`,{className:`font-semibold`,children:`ID:`}),` `,i]})]})]});return t(CQ,{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-background`,size:c}),h&&t(r,{src:h.picture,name:h.name,size:c,className:`border-2 border-background`}),g&&t(r,{name:`API`,color:`bg-gray-400`,size:c,className:`border-2 border-background`})]}),s&&t(`div`,{className:`text-sm font-semibold truncate`,children:h?`Agent (${h.name||h.email})`:g?`Agent (${g.name})`:v})]})})}function gQ({title:e=`Error`,error:n,showTitle:r=!1,size:i=`md`}){return t(yQ,{title:e,message:Ge(n),color:`bg-red-500`,showTitle:r,size:i})}function _Q({showTitle:e=!1,size:n=`md`,color:r}){let{t:i}=K();return t(yQ,{title:i(`user.unknownUser`),message:i(`user.unknownUserDescription`),color:r,showTitle:e,size:n})}function vQ({userRef:e,showTitle:n=!1,size:r=`md`}){let{t:i}=K();if(!e)return t(yQ,{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(xQ,{userId:a[1],showTitle:n,size:r});case xn.Group:return t(bQ,{userId:a[1],showTitle:n,size:r});case`system`:return t(dQ,{showTitle:n,size:r});case xn.ServiceAccount:return t(pQ,{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(hQ,{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(hQ,{agentId:e,onBehalfOfType:i,onBehalfOfId:o,showTitle:n,size:r,isScheduleAgent:!0})}case`email`:return t(mQ,{email:a[1],showTitle:n,size:r});case xn.ApiKey:return t(SQ,{keyId:a[1],size:r,showTitle:n});case`project`:if(a[1]===`*`)return t(fQ,{showTitle:n,size:r});break;default:return t(gQ,{title:i(`user.unknownUser`),error:`Invalid user ref type: ${o}`,showTitle:n,size:r})}}function yQ({title:e,message:i,color:a,size:o=`md`,showTitle:s=!1}){return t(CQ,{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 bQ({userId:e,showTitle:r=!1,size:i=`md`}){let{t:a}=K(),{data:o,error:s}=cQ(e);if(s)return aQ(s)?t(_Q,{showTitle:r,size:i,color:`bg-indigo-500`}):t(gQ,{title:a(`user.failedToFetchGroup`),error:s,showTitle:r,size:i});if(!o)return t(uQ,{});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`,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(CQ,{title:o.name||a(`user.unnamedGroup`),description:c,children:n(`div`,{className:`flex flex-row items-center gap-2`,children:[t(Kb,{className:`size-6 text-info`,size:i}),r&&t(`div`,{className:`text-sm font-semibold ps-2`,children:o.name||a(`user.unnamedGroup`)})]})})}function xQ({userId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=sQ(e);if(c)return aQ(c)?t(_Q,{showTitle:i,size:a,color:`bg-indigo-500`}):t(gQ,{title:o(`user.failedToFetchUser`),error:c,showTitle:i,size:a});if(!s)return t(uQ,{});let l=t(`div`,{className:`truncate`,title:s.email,children:s.email});return t(CQ,{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 SQ({keyId:e,showTitle:i=!1,size:a=`md`}){let{t:o}=K(),{data:s,error:c}=lQ(e);if(c)return aQ(c)?t(_Q,{showTitle:i,size:a,color:`bg-pink-500`}):t(gQ,{title:o(`user.failedToFetchApiKey`),error:c,showTitle:i,size:a});if(!s)return t(uQ,{});let l=o(`user.privateKey`),u=t(r,{name:`PK`,color:`bg-pink-500`,size:a}),d=n(Le,{className:`dark:bg-muted dark:text-foreground 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(CQ,{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 CQ({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-base font-semibold`,children:e}),r]})})]})}function wQ({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(vQ,{userRef:r,showTitle:!0,size:`sm`})}),n(`span`,{className:`text-muted flex-shrink-0`,children:[`(`,i?.count||0,`)`]})]})}}}function TQ({buckets:e,name:t,placeholder:n}){return wQ({buckets:e,name:t,placeholder:n})}Q();const EQ=HZ([`id`,`run_kind`,`interaction`,`status`,`initiated_by`,`start`,`end`,`evaluation`,`feedback`]);function DQ(e){let t=[];return t.push({name:`id`,placeholder:`Agent Run ID`,type:`text`,multiple:!1}),t.push(tQ({buckets:e.kinds||[],name:`run_kind`,placeholder:`Kind`})),t.push(ZZ({buckets:e.interactions||[],name:`interaction`,placeholder:`Interaction`})),t.push(tQ({buckets:e.statuses||[],name:`status`,placeholder:`Status`})),t.push(TQ({buckets:e.initiated_by||[],name:`initiated_by`,placeholder:`Initiated By`})),t.push(tQ({buckets:e.evaluation||[],name:`evaluation`,placeholder:`Evaluation`})),t.push(tQ({buckets:e.feedback||[],name:`feedback`,placeholder:`Feedback`})),t.push({name:`start`,placeholder:`Started After`,type:`date`,multiple:!1}),t.push({name:`end`,placeholder:`Started Before`,type:`date`,multiple:!1}),t}function OQ(e){return t=>{e.clearFilters(!1,!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!EQ(t.name))return;let n=t.name;VZ(e,n,BZ(t))}}),e.search()}}function kQ({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=DQ(e),_=l??g,v=U(()=>OQ(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`,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(Sy,{className:`size-5`})})]})]}),f.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}var AQ=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 jQ=dt({registry:void 0,isLoading:!1,load:()=>Promise.resolve(),reload:()=>Promise.resolve()});function MQ({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 AQ(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(jQ.Provider,{value:{registry:i,isLoading:o,load:u,reload:d},children:e})}function NQ(){let e=_t(jQ);return H(()=>{!e.registry&&!e.isLoading&&e.load()},[e.registry,e.isLoading,e.load]),e}const PQ=HZ([`name`,`types`]);function FQ(e){let{registry:t}=NQ(),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 IQ(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(!PQ(t.name))return;let n=t.name;VZ(e,n,BZ(t))}}),e.search()}}function LQ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=FQ(e),u=IQ(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 RQ({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 zQ=[`id`,`name`,`types`,`status`],BQ=[`tags`,`created_at`,`updated_at`],VQ=HZ(zQ),HQ=new Set(BQ);function UQ(e){return HQ.has(e)}function WQ(e){return Array.isArray(e)?e:[]}function GQ(e){let{registry:t}=NQ(),n=[];if(n.push({placeholder:`ID`,name:`id`,type:`text`,options:[]}),n.push({placeholder:`Name`,name:`name`,type:`text`,options:[]}),e.type){let r=RQ({buckets:WQ(e.type),typeRegistry:t,type:`select`,multiple:!0});n.push(r)}if(e.status){let t=tQ({buckets:WQ(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:WQ(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 KQ(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=zZ(t.value[0]);r={gte:e,lte:e}}else t.value.length===2&&(r={gte:zZ(t.value[0]),lte:zZ(t.value[1])})}}else r=BZ(t);VQ(n)?VZ(e,n,r):UQ(n)&&r!==void 0&&(e.query.match={...e.query.match,[n]:r})}}),e.search()}}function qQ({facets:e,search:r}){let[i,a]=G([]),o=GQ(e),s=KQ(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 JQ({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:$Z,options:o,value:u,onChange:l,by:`_id`,placeholder:r})}const YQ=HZ([`name`,`prompt`,`model`,`tags`]);function XQ(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 ZQ(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(!YQ(t.name))return;let n=t.name;VZ(e,n,BZ(t))}}),e.search(!0)}}function QQ({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=XQ(e),u=ZQ(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 $Q(e){let t=[];return t.push(tQ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!1})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function e$({facets:e,filters:r,setFilters:i}){let a=$Q(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 t$(e){let t=[];return t.push(tQ({buckets:e.statuses||[],name:`status`,placeholder:`Status`,multiple:!0})),t.push(TQ({buckets:e.started_by||[],name:`started_by`,placeholder:`Started By`})),t.push(tQ({buckets:e.run_type||[],name:`run_type`,placeholder:`Mode`,multiple:!0})),t.push(tQ({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 n$({facets:e,filters:r,setFilters:i}){let a=t$(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 r$=HZ([`name`,`role`,`tags`]);function i$(e,t){let n=e[t];return Array.isArray(n)?n:[]}function a$(e){let t=i$(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:i$(e,`tags`).map(e=>({label:e._id,value:e._id}))};return n.push(r),n}function o$(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(!r$(t.name))return;let n=t.name;VZ(e,n,BZ(t))}}),e.search()}}function s$({facets:e,search:r,filters:i,setFilters:a,filterGroups:o}){let[s,c]=G([]),l=a$(e),u=o$(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 c$({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 l$=HZ([`run_ids`,`interaction`,`environment`,`tags`,`model`,`status`,`finish_reason`,`start`,`end`,`workflow_run_ids`,`workflow_ids`]);function u$(e){return e.filter(e=>e._id!==null)}function d$(e){let t=[];if(t.push({name:`run_ids`,placeholder:`Run ID`,type:`text`,multiple:!1}),e.interactions){let n=ZZ({buckets:u$(e.interactions),name:`interaction`,placeholder:`Interactions`});t.push(n)}if(e.environments){let n=c$({buckets:u$(e.environments),name:`environment`});t.push(n)}if(t.push({name:`tags`,placeholder:`Tags`,type:`stringList`,multiple:!0}),e.models){let n=tQ({buckets:u$(e.models),name:`model`});t.push(n)}if(e.statuses){let n=tQ({buckets:u$(e.statuses),name:`status`});t.push(n)}if(e.finish_reason){let n=tQ({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 f$(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(!l$(t.name))return;let n=t.name,r=BZ(t);(n===`run_ids`||n===`workflow_run_ids`||n===`workflow_ids`)&&!Array.isArray(r)&&(r=[r]),VZ(e,n,r)}}),e.search()}}function p$({facets:e,search:r,actions:i,selectionCount:a,filters:s,setFilters:c,filterGroups:l}){let[u,d]=G([]),f=d$(e),p=f$(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(Sy,{className:`size-5`})})]})]}),h.length>0&&n(`div`,{className:`flex items-center gap-2 mb-1`,children:[t(N,{}),t(F,{})]})]})})}function m$({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:QZ,options:n,value:c,onChange:s,by:`_id`,placeholder:i})}function h$({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 g$(e){return`${e.name} (${e.count})`}function _$({search:e,buckets:n,placeholder:r=`Filter by Type`,className:i}){let[a,o]=G([]),{registry:s}=NQ(),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:g$,options:a,value:u,onChange:l,by:`_id`,placeholder:r})}function v$(e){let t=[];return t.push(tQ({buckets:e.tags||[],name:`tags`,placeholder:`Tags`,multiple:!0})),t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function y$({facets:e,filters:r,setFilters:i}){let a=v$(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 b$=HZ([`search_term`,`status`,`initiated_by`,`start`,`end`,`has_reported_errors`]);function x$(e){let t=[];if(t.push({placeholder:`Workflow Name or Workflow Run ID`,name:`search_term`,type:`text`,options:[]}),e.status){let n=tQ({buckets:e.status||[],name:`status`,placeholder:`Status`});t.push({...n,name:`status`})}if(e.initiated_by){let n=TQ({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 S$(e){return t=>{if(t.length===0){e.clearFilters();return}e.clearFilters(!1),t.forEach(t=>{if(t.value&&t.value.length>0){if(!b$(t.name))return;let n=t.name,r=BZ(t);if(n===`has_reported_errors`){let t=Array.isArray(r)?r[0]:r;(t===`true`||t===`false`)&&VZ(e,n,t===`true`)}else typeof r==`string`&&VZ(e,n,r)}}),e.search()}}function C$({facets:e,search:r}){let[i,a]=G([]),o=x$(e),s=S$(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 w$(e){let t=[];return t.push({name:`name`,placeholder:`Name`,type:`text`,multiple:!1}),t}function T$({facets:e,filters:r,setFilters:i}){let a=w$(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 E$=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 D$=dt(void 0);function O$(){let e=_t(D$);if(!e)throw Error(`useObjectSelection must be used within a ObjectSelectionProvider`);return e}function k$(){return _t(D$)}function A$({value:e,collectionId:n,children:r}){let[i,a]=G();return H(()=>{let t=new E$(e,n,{},a);a(t)},[n,e]),i&&t(D$.Provider,{value:i,children:r})}Q();const j$=dt(void 0);function M$({onFilter:e,children:n}){return t(j$.Provider,{value:e,children:n})}function N$(){return _t(j$)}const P$=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function F$({field:r,value:i,label:a,copyContent:s}){let c=N$(),l=Array.isArray(i)?i.length>0:i!==void 0&&i!==``;return n(e,{children:[s!==void 0&&s!==``&&t(x,{content:s,className:P$}),l&&i!==void 0&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${a}`,className:P$,onClick:e=>{e.stopPropagation(),c?.(r,i)},children:t(g_,{className:`size-3`})})]})}const I$=`text/csv`,L$=`image/`,R$=`application/pdf`,z$=`video/`,B$=[`application/vnd.openxmlformats-officedocument.wordprocessingml.document`,`application/msword`,`application/vnd.openxmlformats-officedocument.presentationml.presentation`,`application/vnd.ms-powerpoint`],V$=e=>e===I$||I$.includes(e),H$=e=>e.startsWith(L$)||L$.includes(e),U$=e=>e===R$||R$.includes(e),W$=e=>e.startsWith(z$)||z$.includes(e),G$=e=>B$.includes(e);function K$(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=`
1286
1286
  @media print {
1287
1287
  body {
1288
1288
  margin: 24px;
@@ -1407,30 +1407,30 @@ $&`)),t.includes(` - `)&&(t=t.replace(/(^|\S)\s+-\s+/g,`$1
1407
1407
  page-break-inside: avoid;
1408
1408
  }
1409
1409
  }
1410
- `,i.head.appendChild(a),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}const K$={max_hw:import.meta.env?.VITE_RENDITION_HW||256,format:hn.jpeg,generate_if_missing:!0},q$=`vertesia.content_store.renditionId`;async function J$(e,t,n,r,i){if(!t?.content?.type||!(V$(t.content.type)||U$(t.content.type)||H$(t.content.type))){i(`No preview available`);return}i(`Preparing preview...`);let a=Date.now()/1e3,o=localStorage.getItem(`${q$}_${t.id}_${K$.max_hw}`),s=localStorage.getItem(`${q$}_${t.id}_${K$.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,K$).then(a=>{if(a.status===`generating`)i(`Preparing preview...`),n(``),r(``),setTimeout(()=>J$(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(`${q$}_${t.id}_${K$.max_hw}`,e),localStorage.setItem(`${q$}_${t.id}_${K$.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 Y$(e,t=7){return e?`~${e.slice(-t)}`:``}function X$(e,t){return e.length>t?`${e.substring(0,t)}...`:e}function Z$(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 Q$(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 $$(e){return typeof e==`object`&&!!e}function e1(e,t){if(!$$(e))return;let n=e[t];return typeof n==`string`?n:void 0}function t1(e){return typeof e==`string`?e:e1(e,`id`)||``}function n1(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e)}const r1={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=t1(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(Lg,{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=($$(e)&&$$(e.properties)?e.properties:void 0)?.[i],s=n1(o),c=e1(e,`name`),l=e1(e,`id`),u=s||c||(l?Y$(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=t1(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(Lg,{className:`size-4`})})]},a)}},typeLink(e,r){return(e,r,i)=>{let a=e1(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=$$(e)&&$$(e.revision)?e.revision:void 0;if(!i)return t(`td`,{},r);let a=e1(i,`root`),o=e1(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(Pg,{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=rO(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)}}},i1=r1.string();function a1(e){return typeof e==`object`&&!!e}function o1(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(!a1(n)||(n=n[t[e]],!n))return;if(a1(n))return n[t[r]]}function s1(e){return!e||e===`.`?[]:e.split(`.`)}var c1=class{layout;renderer=i1;path;fallbackPath;previewObject;constructor(e,t){if(this.layout=e,this.path=s1(e.field||``),this.fallbackPath=e.fallback?s1(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=r1[e](r)}else this.renderer=r1[t]()}}get name(){return this.layout.name}resolveValue(e){let t=o1(e,this.path);return t===void 0&&this.fallbackPath&&(t=o1(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 r1[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(P$,{field:`id`,value:e.id,label:e.id,copyContent:e.id});if(n===`objectName`||r===`name`)return t(P$,{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(P$,{field:`type`,value:n,label:e.type?.name??n??`type`})}if(r===`status`)return t(P$,{field:`status`,value:e.status,label:e.status})}};Q();function l1({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 u1({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&&J$(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-info bg-info/50 dark:bg-info/20`:``}`,onClick:()=>a?.(r),children:[x&&t(`div`,{className:`absolute top-2 end-8 z-10`,children:t(sh,{className:`size-4 text-info`})}),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(Lg,{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-muted rounded-t-xl flex items-center justify-center text-muted`,children:_}),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(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 d1({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-info`:``}`,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(sh,{className:`size-4 text-info inline-block`})})]},e.id)}),e.length===0&&t(`tr`,{children:t(`td`,{colSpan:a.length+ +!!r,className:`text-center`,children:d(`store.noObjectsDragAndDrop`)})})]})]})}function f1({objects:r,selection:i,isLoading:a,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u}){return n(e,{children:[t(l1,{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(u1,{document:e,selection:i,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u},e.id))})]})}var p1=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}).catch(e=>{let t=e instanceof Error?e:Error(String(e));this.result.value={...this.result.value,error:t}})}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 m1=dt(void 0);function h1(){return _t(m1)}function g1(){return rt(h1().facets)}function _1(){let e=h1();return{...rt(e.result),search:e}}function v1(){let e=h1();return rt(e.facets).total}const y1=Xt.getFixedT(null,Yt);var b1;(function(e){e.CREATE=`create`,e.SKIP=`skip`,e.UPDATE=`update`})(b1||={});async function x1(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 S1(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 x1(e),name:e.name,size:e.size,location:n}}));n.push(...a)}return n}function C1(){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 S1(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=b1.SKIP)}})(),await(async()=>{let n=t.filter(e=>e.action!==b1.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=b1.UPDATE)}console.log(`Reconciled ${t.filter(e=>e.action===b1.UPDATE).length}`)})(),t.forEach(e=>{e.action||=b1.CREATE}),console.log(`Document processing check results:`,{totalFiles:n.length,toCreate:t.filter(e=>e.action===b1.CREATE).length,toUpdate:t.filter(e=>e.action===b1.UPDATE).length,toSkip:t.filter(e=>e.action===b1.SKIP).length}),t}catch(e){throw t({title:y1(`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 w1({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}=MQ(),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,te]=G(Date.now()),[R,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=()=>!R&&!c?null:n(oe,{className:`mb-4`,status:`default`,icon:t(p_,{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:[R&&n(`div`,{className:`flex items-center`,children:[t(`span`,{className:`me-1`,children:b(`upload.collectionLabel`)}),t(`span`,{className:`font-medium`,children:R.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}=C1(),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===b1.CREATE).length,r=t.filter(e=>e.action===b1.UPDATE).length,i=t.filter(e=>e.action===b1.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([]),te(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(``),te(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===b1.CREATE?`create`:e.action===b1.UPDATE?`update`:`skip`}));j(t),N(!0),F(!1);let n=w.filter(e=>e.action===b1.SKIP),r=w.filter(e=>e.action===b1.UPDATE),i=w.filter(e=>e.action===b1.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(L_,{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(Uh,{className:`size-4 me-1`}),b(`store.automaticTypeDetection`),t(We,{description:b(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(L_,{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(Lb,{className:`size-5 text-info`}),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(Uh,{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(Lh,{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(i_,{className:`size-5 text-muted`}),e.status===`uploading`&&t(je,{size:`sm`}),e.status===`success`&&t(Uh,{className:`size-5 text-success`}),e.status===`error`&&t(Qh,{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:R?.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 T1(e){let t=typeof e==`function`?e:e.onUploadDone,{client:n,project:r,store:i}=q(),a=h1(),o=nt(),s=Xt.getFixedT(null,Yt),{checkDocumentProcessing:c}=C1();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===b1.CREATE).length,v=g.filter(e=>e.action===b1.UPDATE).length,y=g.filter(e=>e.action===b1.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===b1.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===b1.CREATE||e.action===b1.UPDATE)&&e.file);if(b.length>0){console.log(`Processing ${b.length} files (${b.filter(e=>e.action===b1.CREATE).length} create, ${b.filter(e=>e.action===b1.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===b1.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 E1=[{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 D1({isGridView:e=!1,onUpload:n,collectionId:r,...i}){return n?t(O1,{...i,onUpload:n,isGridView:e,collectionId:r}):t(k1,{...i,isGridView:e})}function O1({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),_=h1(),v=nt(),{t:y}=K(),{checkDocumentProcessing:b}=C1(),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-muted opacity-40 absolute inset-0 z-50 flex justify-center items-center`,s?`block`:`hidden`),children:t(je,{size:`xl`})}),t(k1,{...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-muted/90 pointer-events-auto`,d?`flex`:`hidden`),buttonLabel:`Select Files or Folders`,allowFolders:!0})})}),t(w1,{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 k1({objects:e,layout:n=E1,isLoading:r,onRowClick:i,onSelectionChange:a,highlightRow:o,previewObject:s,selectedObject:c,isGridView:l}){let u=O$(),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=A1(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=j1(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:E1;return console.log(`Using layout with columns:`,e.map(e=>e.name).join(`, `)),e.map(e=>new c1(e,s))},[n,s]);return t(l?f1:d1,{objects:e,isLoading:r,columns:p,onRowClick:i,highlightRow:o,previewObject:s,selectedObject:c,selection:u,toggleAll:f,onSelectionChange:d})}function A1(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}function j1(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 M1({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 p1(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(m1.Provider,{value:l,children:e})}Q();const N1=`vertesia.content_store.lastDisplayedView`;function P1({onUpdate:e}){let{t:n}=K(),[r,i]=G(localStorage.getItem(N1)===`grid`),a=()=>{r?c():s()},s=()=>{localStorage.setItem(N1,`grid`),i(!0),e(!0)},c=()=>{localStorage.setItem(N1,`table`),i(!1),e(!1)};return t(o,{variant:`outline`,onClick:a,title:n(r?`misc.tableView`:`misc.thumbnailView`),children:t(r?pb:U_,{})})}P1.LAST_DISPLAYED_VIEW=N1,Q();const F1=[{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 I1({onChange:e,selectedIds:n}){return t(M1,{children:t(L1,{onRowClick:t=>{e(t||void 0)},selectedIds:n})})}function L1({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}=_1(),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 _=g1(),v=h1();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(KQ,{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(Sy,{size:16})}),t(P1,{onUpdate:u})]})]}),n(`div`,{className:`@container relative flex-1 overflow-y-auto`,children:[t(D1,{objects:m||[],isLoading:!m.length&&f,layout:F1,onRowClick:e,highlightRow:r?.size?a:void 0,isGridView:l}),t(`div`,{ref:g,className:`h-4 w-full`})]})]})}Q();function R1(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 z1({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`),te=W(null),R=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:R1(f.usedTokens),limit:R1(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&&te.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=aZ(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(()=>{R.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=te.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-info/80 dark:bg-info/40 rounded-lg z-10 pointer-events-none`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2`,children:[t(Lb,{className:`size-5`}),L(`agent.dropFilesToUpload`)]})}),me&&t(`input`,{ref:R,type:`file`,multiple:!0,accept:C,onChange:ke,className:`hidden`}),t(EZ,{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(_G,{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:te,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(py,{className:`size-4`})}),children:[!M&&n(ae,{onClick:()=>oe(!0),isDisabled:!d,children:[t(Yv,{className:`size-4`}),L(`agent.linkObject`)]}),me&&n(ae,{onClick:Ae,isDisabled:_e,children:[t(Lb,{className:`size-4`}),L(`agent.upload`)]}),k&&n(ae,{onClick:()=>de(!0),children:[t(Qg,{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(Om,{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(ub,{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(Pm,{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(I1,{onChange:e=>{let t=`[${e.properties?.title||e.name||`Object`}](store:${e.id})`,n=ne||``,r=te.current?.selectionStart||n.length,i=n.substring(0,r)+t+n.substring(r);re(i),oe(!1),setTimeout(()=>{if(te.current){te.current.focus();let e=r+t.length;te.current.setSelectionRange(e,e)}},100)}})})]}),k?.({isOpen:le,onClose:Me,onSelect:Ne})]})}function B1({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(qH,{...a})}):t(Et,{type:`proposal`,error:`Invalid proposal specification`})}const V1=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(yC,{spec:n}):null}),H1=gt(function({code:e}){let n=U(()=>{try{return{library:`vega-lite`,spec:JSON.parse(e)}}catch{return null}},[e]);return n?t(yC,{spec:n}):null}),U1={chart:V1,"vega-lite":H1,vegalite:H1,"fusion-fragment":Yn,proposal:B1,askuser:B1};function W1({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 G1(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(W1,{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 K1({children:e}){let{client:n}=q(),[r,i]=G(U1);return H(()=>{G1(n).then(e=>{i({...U1,...e})})},[n]),t(Dt,{components:r,children:e})}Q();const q1=new Map,J1=[400,1200];async function Y1(e,t,n){for(let r=0;;r++)try{return await e.agents.sendSignal(t,`FileBatchClosed`,n),!0}catch(e){if(r>=J1.length)return console.error(`Failed to close staged file batch:`,e),!1;await new Promise(e=>setTimeout(e,J1[r]))}}function X1(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 Z1(e){return e===`running`||e===`canceling`}function Q1(e){return!Z1(e)}function $1(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function e0(e){for(let t=e.length-1;t>=0;t--){let n=e[t].details;if(!n)continue;let r=n.token_usage,i=$1(r?.prompt),a=i&&i>0?i:$1(r?.total),o=$1(n.checkpoint_threshold)??$1(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 t0(e,t){return!Q1(e.status)||!Z1(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 n0(e){let t=e.details,n=typeof t?.workstream_id==`string`&&t.workstream_id.trim()?t.workstream_id:gU(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 r0(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 i0(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 a0(e){let t=new Map,n=new Map;return e.forEach((e,r)=>{let i=X1(e.timestamp),a=n0(e),o=aU(e),s=o?.workstreamId??a?.workstreamId;if(!s)return;let c=o?.launchId??a?.launchId,l=nU(e);if(!o&&!c&&l&&!n.has(s))return;let u=i0(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=iU(e);d?u.status=d:l||(r0(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),Z1(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(!Z1(e.status))-Number(!Z1(t.status));return n===0?Z1(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 o0(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 s0(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 c0(e,t){let n=e.findIndex(e=>e.launch_id===t.launch_id);if(n>=0){e[n]=t0(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]=t0(e[r],t);return}e.push(t)}function l0(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 u0(e,t=!0){let[n,r]=G(()=>Math.max(0,Math.floor((Date.now()-X1(e))/1e3)));return H(()=>{if(!t)return;let n=()=>{r(Math.max(0,Math.floor((Date.now()-X1(e))/1e3)))};n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function d0(e=!0){let[t,n]=G(0);return H(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*$W.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function f0({message:e,startedAt:r}){let{t:i}=K(),a=u0(r),o=d0();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(FW,{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 `,l0(a)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:$W[o]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(PW,{color:`blue`})})]})]})}function p0(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 m0(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 h0(e){return m0(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function g0(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 _0(e){let{agentRunId:n,startWorkflow:r,resourceResolver:i}=e;if(n){let r=t(K1,{children:t(b0,{...e,agentRunId:n})});return i?t(Ct,{value:i,children:r}):r}return r?t(y0,{...e}):t(v0,{})}function v0(){let{t:e}=K();return n(oe,{status:`info`,icon:t(Lm,{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 y0({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),[te,R]=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=aZ(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(`
1410
+ `,i.head.appendChild(a),i.body.innerHTML=e.innerHTML,r.focus(),r.print(),setTimeout(()=>{n.parentNode?.removeChild(n)},1e3),!0}const q$={max_hw:import.meta.env?.VITE_RENDITION_HW||256,format:hn.jpeg,generate_if_missing:!0},J$=`vertesia.content_store.renditionId`;async function Y$(e,t,n,r,i){if(!t?.content?.type||!(H$(t.content.type)||W$(t.content.type)||U$(t.content.type))){i(`No preview available`);return}i(`Preparing preview...`);let a=Date.now()/1e3,o=localStorage.getItem(`${J$}_${t.id}_${q$.max_hw}`),s=localStorage.getItem(`${J$}_${t.id}_${q$.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,q$).then(a=>{if(a.status===`generating`)i(`Preparing preview...`),n(``),r(``),setTimeout(()=>Y$(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(`${J$}_${t.id}_${q$.max_hw}`,e),localStorage.setItem(`${J$}_${t.id}_${q$.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 X$(e,t=7){return e?`~${e.slice(-t)}`:``}function Z$(e,t){return e.length>t?`${e.substring(0,t)}...`:e}function Q$(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 $$(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 e1(e){return typeof e==`object`&&!!e}function t1(e,t){if(!e1(e))return;let n=e[t];return typeof n==`string`?n:void 0}function n1(e){return typeof e==`string`?e:t1(e,`id`)||``}function r1(e){return e==null||typeof e==`string`||typeof e==`number`||typeof e==`boolean`?e:String(e)}const i1={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=n1(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(Lg,{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=(e1(e)&&e1(e.properties)?e.properties:void 0)?.[i],s=r1(o),c=t1(e,`name`),l=t1(e,`id`),u=s||c||(l?X$(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=n1(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(Lg,{className:`size-4`})})]},a)}},typeLink(e,r){return(e,r,i)=>{let a=t1(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=e1(e)&&e1(e.revision)?e.revision:void 0;if(!i)return t(`td`,{},r);let a=t1(i,`root`),o=t1(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(Pg,{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=rO(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)}}},a1=i1.string();function o1(e){return typeof e==`object`&&!!e}function s1(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(!o1(n)||(n=n[t[e]],!n))return;if(o1(n))return n[t[r]]}function c1(e){return!e||e===`.`?[]:e.split(`.`)}var l1=class{layout;renderer=a1;path;fallbackPath;previewObject;constructor(e,t){if(this.layout=e,this.path=c1(e.field||``),this.fallbackPath=e.fallback?c1(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=i1[e](r)}else this.renderer=i1[t]()}}get name(){return this.layout.name}resolveValue(e){let t=s1(e,this.path);return t===void 0&&this.fallbackPath&&(t=s1(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 i1[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(F$,{field:`id`,value:e.id,label:e.id,copyContent:e.id});if(n===`objectName`||r===`name`)return t(F$,{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(F$,{field:`type`,value:n,label:e.type?.name??n??`type`})}if(r===`status`)return t(F$,{field:`status`,value:e.status,label:e.status})}};Q();function u1({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 d1({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&&Y$(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-info bg-info/50 dark:bg-info/20`:``}`,onClick:()=>a?.(r),children:[x&&t(`div`,{className:`absolute top-2 end-8 z-10`,children:t(sh,{className:`size-4 text-info`})}),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(Lg,{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-muted rounded-t-xl flex items-center justify-center text-muted`,children:_}),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(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 f1({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-info`:``}`,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(sh,{className:`size-4 text-info inline-block`})})]},e.id)}),e.length===0&&t(`tr`,{children:t(`td`,{colSpan:a.length+ +!!r,className:`text-center`,children:d(`store.noObjectsDragAndDrop`)})})]})]})}function p1({objects:r,selection:i,isLoading:a,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u}){return n(e,{children:[t(u1,{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(d1,{document:e,selection:i,onSelectionChange:o,onRowClick:s,highlightRow:c,previewObject:l,selectedObject:u},e.id))})]})}var m1=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}).catch(e=>{let t=e instanceof Error?e:Error(String(e));this.result.value={...this.result.value,error:t}})}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 h1=dt(void 0);function g1(){return _t(h1)}function _1(){return rt(g1().facets)}function v1(){let e=g1();return{...rt(e.result),search:e}}function y1(){let e=g1();return rt(e.facets).total}const b1=Xt.getFixedT(null,Yt);var x1;(function(e){e.CREATE=`create`,e.SKIP=`skip`,e.UPDATE=`update`})(x1||={});async function S1(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 C1(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 S1(e),name:e.name,size:e.size,location:n}}));n.push(...a)}return n}function w1(){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 C1(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=x1.SKIP)}})(),await(async()=>{let n=t.filter(e=>e.action!==x1.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=x1.UPDATE)}console.log(`Reconciled ${t.filter(e=>e.action===x1.UPDATE).length}`)})(),t.forEach(e=>{e.action||=x1.CREATE}),console.log(`Document processing check results:`,{totalFiles:n.length,toCreate:t.filter(e=>e.action===x1.CREATE).length,toUpdate:t.filter(e=>e.action===x1.UPDATE).length,toSkip:t.filter(e=>e.action===x1.SKIP).length}),t}catch(e){throw t({title:b1(`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 T1({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}=NQ(),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,te]=G(Date.now()),[R,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=()=>!R&&!c?null:n(oe,{className:`mb-4`,status:`default`,icon:t(p_,{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:[R&&n(`div`,{className:`flex items-center`,children:[t(`span`,{className:`me-1`,children:b(`upload.collectionLabel`)}),t(`span`,{className:`font-medium`,children:R.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}=w1(),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===x1.CREATE).length,r=t.filter(e=>e.action===x1.UPDATE).length,i=t.filter(e=>e.action===x1.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([]),te(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(``),te(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===x1.CREATE?`create`:e.action===x1.UPDATE?`update`:`skip`}));j(t),N(!0),F(!1);let n=w.filter(e=>e.action===x1.SKIP),r=w.filter(e=>e.action===x1.UPDATE),i=w.filter(e=>e.action===x1.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(L_,{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(Uh,{className:`size-4 me-1`}),b(`store.automaticTypeDetection`),t(We,{description:b(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(L_,{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(Lb,{className:`size-5 text-info`}),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(Uh,{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(Lh,{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(i_,{className:`size-5 text-muted`}),e.status===`uploading`&&t(je,{size:`sm`}),e.status===`success`&&t(Uh,{className:`size-5 text-success`}),e.status===`error`&&t(Qh,{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:R?.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 E1(e){let t=typeof e==`function`?e:e.onUploadDone,{client:n,project:r,store:i}=q(),a=g1(),o=nt(),s=Xt.getFixedT(null,Yt),{checkDocumentProcessing:c}=w1();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===x1.CREATE).length,v=g.filter(e=>e.action===x1.UPDATE).length,y=g.filter(e=>e.action===x1.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===x1.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===x1.CREATE||e.action===x1.UPDATE)&&e.file);if(b.length>0){console.log(`Processing ${b.length} files (${b.filter(e=>e.action===x1.CREATE).length} create, ${b.filter(e=>e.action===x1.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===x1.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 D1=[{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 O1({isGridView:e=!1,onUpload:n,collectionId:r,...i}){return n?t(k1,{...i,onUpload:n,isGridView:e,collectionId:r}):t(A1,{...i,isGridView:e})}function k1({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),_=g1(),v=nt(),{t:y}=K(),{checkDocumentProcessing:b}=w1(),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-muted opacity-40 absolute inset-0 z-50 flex justify-center items-center`,s?`block`:`hidden`),children:t(je,{size:`xl`})}),t(A1,{...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-muted/90 pointer-events-auto`,d?`flex`:`hidden`),buttonLabel:`Select Files or Folders`,allowFolders:!0})})}),t(T1,{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 A1({objects:e,layout:n=D1,isLoading:r,onRowClick:i,onSelectionChange:a,highlightRow:o,previewObject:s,selectedObject:c,isGridView:l}){let u=k$(),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=j1(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=M1(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:D1;return console.log(`Using layout with columns:`,e.map(e=>e.name).join(`, `)),e.map(e=>new l1(e,s))},[n,s]);return t(l?p1:f1,{objects:e,isLoading:r,columns:p,onRowClick:i,highlightRow:o,previewObject:s,selectedObject:c,selection:u,toggleAll:f,onSelectionChange:d})}function j1(e,t,n){for(let r=t-1;r>=0;r--)if(n.isSelected(e[r].id))return r;return-1}function M1(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 N1({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 m1(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(h1.Provider,{value:l,children:e})}Q();const P1=`vertesia.content_store.lastDisplayedView`;function F1({onUpdate:e}){let{t:n}=K(),[r,i]=G(localStorage.getItem(P1)===`grid`),a=()=>{r?c():s()},s=()=>{localStorage.setItem(P1,`grid`),i(!0),e(!0)},c=()=>{localStorage.setItem(P1,`table`),i(!1),e(!1)};return t(o,{variant:`outline`,onClick:a,title:n(r?`misc.tableView`:`misc.thumbnailView`),children:t(r?pb:U_,{})})}F1.LAST_DISPLAYED_VIEW=P1,Q();const I1=[{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 L1({onChange:e,selectedIds:n}){return t(N1,{children:t(R1,{onRowClick:t=>{e(t||void 0)},selectedIds:n})})}function R1({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}=v1(),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 _=_1(),v=g1();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(qQ,{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(Sy,{size:16})}),t(F1,{onUpdate:u})]})]}),n(`div`,{className:`@container relative flex-1 overflow-y-auto`,children:[t(O1,{objects:m||[],isLoading:!m.length&&f,layout:I1,onRowClick:e,highlightRow:r?.size?a:void 0,isGridView:l}),t(`div`,{ref:g,className:`h-4 w-full`})]})]})}Q();function z1(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 B1({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`),te=W(null),R=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:z1(f.usedTokens),limit:z1(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&&te.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=oZ(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(()=>{R.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=te.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-info/80 dark:bg-info/40 rounded-lg z-10 pointer-events-none`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2`,children:[t(Lb,{className:`size-5`}),L(`agent.dropFilesToUpload`)]})}),me&&t(`input`,{ref:R,type:`file`,multiple:!0,accept:C,onChange:ke,className:`hidden`}),t(DZ,{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(_G,{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:te,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(py,{className:`size-4`})}),children:[!M&&n(ae,{onClick:()=>oe(!0),isDisabled:!d,children:[t(Yv,{className:`size-4`}),L(`agent.linkObject`)]}),me&&n(ae,{onClick:Ae,isDisabled:_e,children:[t(Lb,{className:`size-4`}),L(`agent.upload`)]}),k&&n(ae,{onClick:()=>de(!0),children:[t(Qg,{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(Om,{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(ub,{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(Pm,{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(L1,{onChange:e=>{let t=`[${e.properties?.title||e.name||`Object`}](store:${e.id})`,n=ne||``,r=te.current?.selectionStart||n.length,i=n.substring(0,r)+t+n.substring(r);re(i),oe(!1),setTimeout(()=>{if(te.current){te.current.focus();let e=r+t.length;te.current.setSelectionRange(e,e)}},100)}})})]}),k?.({isOpen:le,onClose:Me,onSelect:Ne})]})}function V1({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(qH,{...a})}):t(Et,{type:`proposal`,error:`Invalid proposal specification`})}const H1=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(yC,{spec:n}):null}),U1=gt(function({code:e}){let n=U(()=>{try{return{library:`vega-lite`,spec:JSON.parse(e)}}catch{return null}},[e]);return n?t(yC,{spec:n}):null}),W1={chart:H1,"vega-lite":U1,vegalite:U1,"fusion-fragment":Yn,proposal:V1,askuser:V1};function G1({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 K1(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(G1,{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 q1({children:e}){let{client:n}=q(),[r,i]=G(W1);return H(()=>{K1(n).then(e=>{i({...W1,...e})})},[n]),t(Dt,{components:r,children:e})}Q();const J1=new Map,Y1=[400,1200];async function X1(e,t,n){for(let r=0;;r++)try{return await e.agents.sendSignal(t,`FileBatchClosed`,n),!0}catch(e){if(r>=Y1.length)return console.error(`Failed to close staged file batch:`,e),!1;await new Promise(e=>setTimeout(e,Y1[r]))}}function Z1(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 Q1(e){return e===`running`||e===`canceling`}function $1(e){return!Q1(e)}function e0(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}function t0(e){for(let t=e.length-1;t>=0;t--){let n=e[t].details;if(!n)continue;let r=n.token_usage,i=e0(r?.prompt),a=i&&i>0?i:e0(r?.total),o=e0(n.checkpoint_threshold)??e0(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 n0(e,t){return!$1(e.status)||!Q1(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 r0(e){let t=e.details,n=typeof t?.workstream_id==`string`&&t.workstream_id.trim()?t.workstream_id:gU(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 i0(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 a0(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 o0(e){let t=new Map,n=new Map;return e.forEach((e,r)=>{let i=Z1(e.timestamp),a=r0(e),o=aU(e),s=o?.workstreamId??a?.workstreamId;if(!s)return;let c=o?.launchId??a?.launchId,l=nU(e);if(!o&&!c&&l&&!n.has(s))return;let u=a0(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=iU(e);d?u.status=d:l||(i0(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),Q1(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(!Q1(e.status))-Number(!Q1(t.status));return n===0?Q1(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 s0(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 c0(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 l0(e,t){let n=e.findIndex(e=>e.launch_id===t.launch_id);if(n>=0){e[n]=n0(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]=n0(e[r],t);return}e.push(t)}function u0(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 d0(e,t=!0){let[n,r]=G(()=>Math.max(0,Math.floor((Date.now()-Z1(e))/1e3)));return H(()=>{if(!t)return;let n=()=>{r(Math.max(0,Math.floor((Date.now()-Z1(e))/1e3)))};n();let i=window.setInterval(n,1e3);return()=>window.clearInterval(i)},[t,e]),n}function f0(e=!0){let[t,n]=G(0);return H(()=>{if(!e)return;let t=window.setInterval(()=>{n(()=>Math.floor(Math.random()*$W.length))},4e3);return()=>window.clearInterval(t)},[e]),t}function p0({message:e,startedAt:r}){let{t:i}=K(),a=d0(r),o=f0();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(FW,{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 `,u0(a)]})]}),t(`div`,{className:`mt-1 truncate text-muted/80`,children:$W[o]})]})]}),t(`div`,{className:`mt-3 ps-6`,children:t(PW,{color:`blue`})})]})]})}function m0(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 h0(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 g0(e){return h0(e.trim().replace(/[^a-z0-9-_]+/gi,`-`)).slice(0,80)}function _0(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 v0(e){let{agentRunId:n,startWorkflow:r,resourceResolver:i}=e;if(n){let r=t(q1,{children:t(x0,{...e,agentRunId:n})});return i?t(Ct,{value:i,children:r}):r}return r?t(b0,{...e}):t(y0,{})}function y0(){let{t:e}=K();return n(oe,{status:`info`,icon:t(Lm,{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 b0({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),[te,R]=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=oZ(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(`
1411
1411
  `)),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(`
1412
- `)}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 Y1(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?.(),R(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]),te?t(b0,{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:te,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 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(Lb,{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(Sg,{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(ix,{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(f0,{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(Qg,{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(ix,{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(uh,{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(Lb,{className:`size-4`})}),r&&t(cx,{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(Pm,{className:`size-4`})})]})]})})]})})}function b0({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:te,inputContainerClassName:R,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}=_Z(Ye,r,fe),{plans:ct,activePlanIndex:lt,setActivePlanIndex:ut,workstreamStatusMap:dt,showInput:ft,showSlidingPanel:pt,setShowSlidingPanel:mt}=oZ(Ze,a),{openDocuments:ht,activeDocumentId:gt,isDocPanelOpen:_t,docRefreshKey:vt,closeDocPanel:yt,selectDocument:bt,openDocInPanel:xt,updateDocumentTitle:St}=xZ(Ze),{processingFiles:Ct,hasProcessingFiles:wt,handleFileUpload:Tt,removeProcessingFile:Et,clearProcessingFiles:Dt}=TZ(Ye,r,st,Xe,U(()=>CG(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||gU(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(()=>a0(Ze),[Ze]),Mn=U(()=>{let e=[...jn];for(let t of rn)c0(e,s0(t));for(let t of tn)c0(e,o0(t));return e.map((e,t)=>({workstream:e,index:t})).sort((e,t)=>Number(!Z1(e.workstream.status))-Number(!Z1(t.workstream.status))||e.index-t.index).map(({workstream:e})=>e)},[jn,tn,rn]),Nn=U(()=>Mn.filter(e=>Z1(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?ZH(e.workstream_id,e.interaction):ZH(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&&AC(),Rn=We??(jC()||Zt),zn=U(()=>Ze.filter(e=>!fU(e)&&!(P?.includes(e.type)??!1)),[P,Ze]),Bn=U(()=>yU(zn,Kt),[Kt,zn]),Vn=U(()=>OC(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:q1,Yn=U(()=>a0(Gn),[Gn]),Zn=U(()=>Yn.filter(e=>Z1(e.status)),[Yn]),Qn=U(()=>$e||!pU(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)YU(r,t)&&e.add(GU(t));return _W(Gn,`main`,e)},[r,Gn]),nr=!!tr&&!Tn&&(!Sn||Cn),rr=Rn&&!Un,ir=wn&&!rr,ar=U(()=>e0(Ze),[Ze]),or=h&&!Sn&&Un&&!!ar;H(()=>{lU(`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=TC(Hn,Bn.length),n=TC(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`:void 0),fr=ct.length>0||Mn.length===0?`plan`:`workstreams`,[pr,Y]=G(null),[mr,hr]=G(400),[gr,_r]=G(!1),[vr,yr]=G(!1),br=A&&!vr&&(pt||_t||!k&&Mn.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=Mt.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),dr(`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),dr(`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(),xt(n),dr(`documents`)},children:r}),[xt]),Dr=je??Er;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(()=>{Y(null),dn.current=!1,sn(!1),nn([]),an([])},[r]),H(()=>{let e=et!==`loading`&&!Qn&&!Sn&&!on;if(lU(`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){lU(`active workstreams fetch skipped while previous request is pending`,{agentRunId:r});return}n=!0;try{lU(`active workstreams fetch start`,{agentRunId:r});let e=await Ye.agents.getActiveWorkstreams(r);if(t)return;if(lU(`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),lU(`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 Or=V(async()=>{let e=gn.current;e&&await e},[]),kr=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=tW(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(`
1412
+ `)}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 X1(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?.(),R(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]),te?t(x0,{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:te,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 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(Lb,{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(Sg,{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(ix,{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(p0,{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(Qg,{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(ix,{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(uh,{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(Lb,{className:`size-4`})}),r&&t(cx,{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(Pm,{className:`size-4`})})]})]})})]})})}function x0({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:te,inputContainerClassName:R,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}=vZ(Ye,r,fe),{plans:ct,activePlanIndex:lt,setActivePlanIndex:ut,workstreamStatusMap:dt,showInput:ft,showSlidingPanel:pt,setShowSlidingPanel:mt}=sZ(Ze,a),{openDocuments:ht,activeDocumentId:gt,isDocPanelOpen:_t,docRefreshKey:vt,closeDocPanel:yt,selectDocument:bt,openDocInPanel:xt,updateDocumentTitle:St}=SZ(Ze),{processingFiles:Ct,hasProcessingFiles:wt,handleFileUpload:Tt,removeProcessingFile:Et,clearProcessingFiles:Dt}=EZ(Ye,r,st,Xe,U(()=>CG(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||gU(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(()=>o0(Ze),[Ze]),Mn=U(()=>{let e=[...jn];for(let t of rn)l0(e,c0(t));for(let t of tn)l0(e,s0(t));return e.map((e,t)=>({workstream:e,index:t})).sort((e,t)=>Number(!Q1(e.workstream.status))-Number(!Q1(t.workstream.status))||e.index-t.index).map(({workstream:e})=>e)},[jn,tn,rn]),Nn=U(()=>Mn.filter(e=>Q1(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?ZH(e.workstream_id,e.interaction):ZH(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&&AC(),Rn=We??(jC()||Zt),zn=U(()=>Ze.filter(e=>!fU(e)&&!(P?.includes(e.type)??!1)),[P,Ze]),Bn=U(()=>yU(zn,Kt),[Kt,zn]),Vn=U(()=>OC(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:J1,Yn=U(()=>o0(Gn),[Gn]),Zn=U(()=>Yn.filter(e=>Q1(e.status)),[Yn]),Qn=U(()=>$e||!pU(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)YU(r,t)&&e.add(GU(t));return _W(Gn,`main`,e)},[r,Gn]),nr=!!tr&&!Tn&&(!Sn||Cn),rr=Rn&&!Un,ir=wn&&!rr,ar=U(()=>t0(Ze),[Ze]),or=h&&!Sn&&Un&&!!ar;H(()=>{lU(`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=TC(Hn,Bn.length),n=TC(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`:void 0),fr=ct.length>0||Mn.length===0?`plan`:`workstreams`,[pr,Y]=G(null),[mr,hr]=G(400),[gr,_r]=G(!1),[vr,yr]=G(!1),br=A&&!vr&&(pt||_t||!k&&Mn.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=Mt.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),dr(`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),dr(`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(),xt(n),dr(`documents`)},children:r}),[xt]),Dr=je??Er;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(()=>{Y(null),dn.current=!1,sn(!1),nn([]),an([])},[r]),H(()=>{let e=et!==`loading`&&!Qn&&!Sn&&!on;if(lU(`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){lU(`active workstreams fetch skipped while previous request is pending`,{agentRunId:r});return}n=!0;try{lU(`active workstreams fetch start`,{agentRunId:r});let e=await Ye.agents.getActiveWorkstreams(r);if(t)return;if(lU(`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),lU(`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 Or=V(async()=>{let e=gn.current;e&&await e},[]),kr=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=tW(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(`
1413
1413
  `));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(`
1414
- `));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&&qU(r,i),(async()=>{await Or(),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,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=hn.current;return Ye.agents.retrieve(r).then(n=>{e||(Mr(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 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=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]),Ir=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation(),fn.current++,e.dataTransfer?.types?.includes(`Files`)&&Gt(!0))},[Ot]),Lr=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation())},[Ot]),Rr=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation(),fn.current--,fn.current===0&&Gt(!1))},[Ot]),zr=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]),Br=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]),Vr=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?Br:null),()=>{xe&&(xe.current=null)}),[xe,Qn,Br,h]),H(()=>{Se?.(Vt)},[Vt,Se]);let Hr=i||Je(`agent.agentConversation`),Ur=async()=>{try{let e=await bU(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}:{}};g0(`${h0(Hr)||`agent-chat`}-${h0(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(!jt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}Kr(!0)},Jr=()=>{if(!jt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}let e=`${Hr} - ${r}`;if(!p0(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}),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&&Un&&xn?.toUpperCase()===`RUNNING`,Qr=U(()=>kn.plan.plan?.reduce((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e),new Map),[kn.plan]),$r=e=>t(FZ,{title:Hr,variant:e,isCompleted:Qn,isTerminal:Sn,onClose:s,isModal:c,agentRunId:r,workflowRunId:ot||``,viewMode:zt,onViewModeChange:Bt,showPlanPanel:br,hasPlan:A&&ct.length>0,showPlanButton:A&&!Be,onTogglePlanPanel:Sr,showPlaybackButton:Ln,isPlaybackEnabled:Rn,onTogglePlayback:sr,onDownload:Ur,onExportFixture:Wr,resetWorkflow:d,onClone:p,onShowDetails:m,allowWorkflowControl:h,onExportPdf:qr,isReceivingChunks:tt}),ei=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`: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)}),Rn&&t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(PC,{cursor:Hn,messages:Bn,onChangeCursor:cr})}),Ze.length===0&&!Qn&&Ve&&He?t(f0,{message:Ve,startedAt:He}):t(MW,{agentRunId:r,children:t(iY,{messages:Kn,workstreamSourceMessages:qn,bottomRef:At,isCompleted:$n,plan:kn.plan,workstreamStatus:kn.workstreamStatus,showPlanPanel:A&&pt,onTogglePlanPanel:Sr,plans:ct,activePlanIndex:lt,onChangePlan:lr,taskLabels:Qr,streamingMessages:Jn,onSendMessage:Un?kr:void 0,onOpenArtifact:M?wr:void 0,messageItemClassNames:Ce,messageStyleOverrides:we,toolCallGroupClassNames:Te,hideToolCallsInViewMode:Ee,streamingMessageClassNames:De,batchProgressPanelClassNames:Oe,artifactRunId:r,agentRunId:r,viewMode:zt,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:!Un,renderRequestInputControls:!nr,activeWorkstream:Kt,onActiveWorkstreamChange:qt})}),nr?t(yW,{message:tr,onSendMessage:Un?kr:void 0,onMcpConnected:Un?Ar:void 0,disabled:L||!Un,isLoading:Nt||L}):rr&&Zn.length>0?t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:t(EZ,{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(Uh,{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(z1,{onSend:kr,onStop:h?Br:void 0,approvalModeSlot:a&&ln?t(cx,{mode:ln,onChange:Fr,disabled:!Un||Sn||!h}):void 0,mcpSlot:t(xY,{disabledCollections:jr,onChange:Nr,onConnectionChange:Pr}),disabled:L||!Un,isSending:Nt||L,isStopping:Vt,isStreaming:!Qn,isCompleted:Qn,contextWindowUsage:or?ar:void 0,onCompactContext:or?Vr: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:R,inputClassName:ne})]})})]}),ti=t($S,{children:t(iG,{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-info ring-inset`,te),onDragEnter:Ot?Ir:void 0,onDragOver:Ot?Lr:void 0,onDragLeave:Ot?Rr:void 0,onDrop:Ot?zr:void 0,children:[Ot&&Wt&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-info/80 dark:bg-info/40 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(Lb,{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=Mt.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(iZ,{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: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:ur??fr,activeTab:ur??fr,onTabChange:dr})})]}),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:yC,artifactRunId:r,children:ti}):ti}function x0({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(YG,{message:e,showPulsatingCircle:!1},`${e.workstream_id??`main`}-${e.timestamp}-${e.type}`))})}function S0({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-muted`,children:`Waiting for agent response...`})}):t(`div`,{className:`flex-1 flex flex-col justify-start h-full min-h-0 ${i||``}`,children:t(x0,{messages:s,isCompleted:!1})})})}function C0(e){return e.name}function w0({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:C0,options:u??[],value:c,onChange:e=>{l(e),n(e)},placeholder:o(`intakePolicy.placeholder.environment`),filterBy:`name`,disabled:a,isLoading:d})}function T0(e){return e.name}function E0(e){return e?.length?n=>{let r=e.some(e=>e.id===n.id);return t(`span`,{className:r?`opacity-50`:``,children:n.name})}:T0}function D0({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:E0(o),options:f??[],value:u,onChange:e=>{d(e),r(e)},placeholder:c(`intakePolicy.placeholder.model`),disabled:a,isLoading:p})}function O0({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:T0,options:c??[],value:o,onChange:e=>{s(e),r(e)},placeholder:i(`intakePolicy.placeholder.model`),disabled:!e,isLoading:l})}function k0({children:e,fallback:n}){return A0?t(A0,{fallback:n,children:e}):t(ir,{FallbackComponent:n,children:e})}let A0=null;function j0(e){A0=e}function M0({children:e}){return t(k0,{fallback:N0,children:e})}function N0({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 P0({children:e}){return t(k0,{fallback:F0,children:e})}function F0({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-muted`,children:r})]})})}function I0({children:e}){return t(k0,{fallback:L0,children:e})}function L0({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 R0=/^[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 z0(e){return R0.test(e)}function B0({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(z0(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 Array.isArray(c)&&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})(),g=!!i&&h.length===0;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(gh,{className:`size-3.5 cn-rtl-flip`}),maxItems:4}),o&&!g&&t(We,{description:o,children:t(L_,{className:`size-4 text-muted ms-4`})})]}),i&&n(`div`,{className:`flex gap-2 items-center`,children:[t(`h1`,{className:`text-xl font-semibold break-all`,children:i}),o&&g&&t(We,{description:o,children:t(L_,{className:`size-4 text-muted`})})]})]}),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 V0(){let{t:e}=K();return n(`div`,{className:`text-center pt-32`,children:[t(`h1`,{className:`text-3xl font-bold text-destructive`,children:`404`}),t(`p`,{className:`text-2xl`,children:e(`layout.pageNotFound`)})]})}Q();const H0=`magic-pdf`;function U0(e){return e.replace(/^\$\.?/,``).replace(/^data\./,``)}function W0(e){let{client:t}=q(),[n,r]=G(!1);return H(()=>{let n=!1;return r(!1),t.files.getDownloadUrl(`${H0}/${e}/grounded-extraction.json`).then(e=>fetch(e.url,{method:`HEAD`})).then(e=>{n||r(e.ok)}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function G0(e){let{client:t}=q(),[n,r]=G(null);return H(()=>{let n=!1;return r(null),t.files.getDownloadUrl(`${H0}/${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 K0({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(`${H0}/${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(J0,{extraction:s,objectId:e,onClose:r})})}function q0({objectId:e,onClose:n}){return t(`div`,{className:`fixed inset-0 bg-background z-50`,children:t(K0,{objectId:e,onClose:n})})}function J0({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(`${H0}/${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=U0(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(U0(e))?.[0];t&&p(t.page)},E=u.indexOf(f),D=m?x.get(U0(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(ph,{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(gh,{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(P_,{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(O_,{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(Y0,{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?Bh:Lg,{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(Og,{className:`size-4`})}),children:[n(ae,{className:`text-xs`,onClick:()=>d(`grounded-extraction.json`),children:[t(Bg,{className:`size-4`}),c(`grounded.downloadCitations`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`pages/page-${f}.json`),children:[t(Qg,{className:`size-4`}),c(`grounded.downloadBlocks`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`grounded-annotated.pdf`),children:[t(Ug,{className:`size-4`}),c(`grounded.downloadAnnotated`)]})]}),!!s&&t(o,{variant:`ghost`,size:`xs`,onClick:s,"aria-label":c(`pdf.close`),children:t(ix,{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(L_,{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(X0,{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 Y0({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(`${H0}/${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&&U0(o)===U0(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:$0(e.path).map((e,r)=>n(lt,{children:[r>0&&t(gh,{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(U0(e.path)),className:z(`absolute cursor-pointer border rounded-[1px] transition-colors`,e.misaligned&&`border-dashed`,c?`border-2 border-info bg-info 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 X0({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(Z0,{items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}):t(`div`,{className:`space-y-1`,children:e.map((e,n)=>t(X0,{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(Q0,{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:e2(e)}),t(X0,{value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o})]},c)})}):null}function Z0({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:[e2(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:e2(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-info ring-1 ring-primary`:d?`hover:bg-muted cursor-pointer`:`text-muted cursor-default`),children:[r2(e[c]),d&&typeof d.confidence==`number`&&t(`span`,{className:z(`ms-1 text-[10px]`,n2(d.confidence)),title:s(`grounded.scoreHint`),children:t2(d.confidence)})]})},c)})},`${r}[${l}]`))})]})})]})}function Q0({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-info ring-1 ring-primary`:l?`hover:bg-muted`:``,!l&&`cursor-default`),children:[n(`span`,{className:`min-w-28 shrink-0 font-semibold`,children:[e2(e),`:`]}),t(`span`,{className:`flex-1 wrap-break-word`,children:r2(r)}),l&&typeof l.confidence==`number`&&t(`span`,{className:z(`text-xs shrink-0`,n2(l.confidence)),title:c(`grounded.scoreHint`),children:t2(l.confidence)}),l&&(l.verified?t(Bh,{"aria-label":c(`grounded.verified`),className:`size-3.5 shrink-0 text-success`}):l.reviewed?t(tb,{"aria-label":c(`grounded.aiVerified`),className:`size-3.5 shrink-0 text-info`}):t(Lg,{"aria-label":c(`grounded.readFromImage`),className:`size-3.5 shrink-0 text-attention`}))]})}function $0(e){return U0(e).split(`.`).map(e=>e2(e.replace(/\[\d+\]/g,``))).filter(Boolean)}function e2(e){return e?zt(e):``}function t2(e){let t=e*100;return Number.isInteger(t)?`${t}%`:`${(Math.floor(t*100)/100).toFixed(2)}%`}function n2(e){return e>=.95?`text-success`:e>=.7?`text-attention`:`text-destructive`}function r2(e){return e==null||e===``?`—`:typeof e==`boolean`?e?`true`:`false`:typeof e==`object`?JSON.stringify(e):String(e)}const i2=`magic-pdf`;var a2;(function(e){e.original=`original`,e.instrumented=`instrumented`})(a2||={});var o2=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=`${i2}/${this.objectId}/pages`;switch(t){case a2.original:return`${n}/page-${e}.original.jpg`;case a2.instrumented:return`${n}/page-${e}.instrumented.jpg`}}},s2=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=`${i2}/${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()}},c2=class{totalPages;pages=[];constructor(e){this.totalPages=e}initFromContent(e){this.pages=l2(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 l2(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 u2=dt(void 0);function d2({children:e,object:n}){let{client:r}=q(),i=n.metadata.page_count||10,[a,o]=G(()=>{let e=new c2(i);return n.text&&e.initFromContent(n.text),{count:i,layoutProvider:new s2(r,n.id,i),markdownProvider:e,imageProvider:new o2(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(u2.Provider,{value:a,children:e})}function f2(e,t,n){return e.files.getDownloadUrl(`${i2}/${t}/${n}`).then(e=>e.url)}function p2(){let e=ot.useContext(u2);if(!e)throw Error(`useMagicPdfContext must be used within a MagicPdfProvider`);return e}Q();function m2({object:e}){let{t:n}=K(),{client:r}=q(),i=t=>{f2(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(Og,{className:`size-4`})})}Q();function h2({className:e}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(sv,{className:`w-6 h-6 animate-spin text-muted`})})}function g2({viewType:e,pageNumber:n}){switch(e){case`json`:return t(_2,{pageNumber:n});case`markdown`:return t(v2,{pageNumber:n});default:return t(v2,{pageNumber:n})}}function _2({pageNumber:e}){let[n,r]=G(null),[i,a]=G(!0),[o,s]=G(null),{layoutProvider:c}=p2();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(h2,{})}):o?t(`div`,{className:`px-4 py-2 text-destructive text-sm`,children:o}):n?t(At,{className:`w-full`,data:n}):null}function v2({pageNumber:e}){let[r,i]=G(null),[a,o]=G(!0),[s,c]=G(null),{markdownProvider:l}=p2();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(h2,{}),t(`span`,{className:`text-sm text-muted`,children:`Loading...`})]}):s?t(`div`,{className:`px-4 py-2 text-destructive 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(),QY();var y2=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 b2({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(y2,{onClose:r,children:t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:t(d2,{object:s,children:t(x2,{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(ix,{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 x2({object:e,onClose:r}){let{t:i}=K(),{count:a,pdfUrl:s,pdfUrlLoading:c}=p2(),[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(KY,{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(m2,{object:e})}),t(`span`,{className:`text-xs text-muted`,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(ix,{className:`size-4`})})})]}),t(`div`,{className:`flex-1 overflow-auto px-2`,children:t(g2,{pageNumber:l,viewType:`markdown`})})]})]})}const S2=[`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`],C2=[`video/mp4`,`video/webm`],w2=[`audio/mp4`,`audio/m4a`,`audio/x-m4a`,`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/webm`];function T2(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 E2({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&&w2.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: `,T2(f.duration)]})]}):t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:`Failed to load audio`})}function D2({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&&S2.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 O2({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&&C2.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 k2({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}=EO({onComplete:()=>{f(!1),h(),i?.()},onError:e=>{console.error(`OAuth provider auth failed:`,e),f(!1)}});return l?t(wO,{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(Bh,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.connected`)})]}),t(yT,{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(wO,{className:`size-3`}):o(`oauthProvider.disconnect`)})]}):t(yT,{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(wO,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.authenticating`)})]}):n(e,{children:[t(Pg,{className:`size-4 me-1`}),t(`span`,{children:o(`oauthProvider.authenticate`)})]})})}function A2(...e){let t=Array.from(e);return t.__AnyOf__=!0,t}function j2(...e){return Array.from(e)}function M2(e){return e.__AnyOf__===!0}function N2(e){if(e&&typeof e==`object`&&`status`in e&&typeof e.status==`number`)return e.status}function P2(e){let t=N2(e);return t===0||t===502||t===503||t===504||e instanceof Error&&e.name===`TimeoutError`}function F2(e,t){let n=U(()=>t?JSON.stringify(t):void 0,[t]),r=!(!t||t.permissions),[i,a]=G(0),[o,s]=G(),c=V(()=>a(e=>e+1),[]);return H(()=>{if(!r)return;let t=new AbortController,a=!1,o=0,c,l,u=t=>s({client:e,tokenKey:n,attempt:i,state:t}),d=()=>{a=!0,clearTimeout(f),clearTimeout(p),clearTimeout(l),t.abort()},f=setTimeout(()=>u({status:`retrying`}),5e3),p=setTimeout(()=>{d(),u({status:`error`,error:c})},6e4),m=async()=>{try{let n=await e.iam.roles.listSystem({signal:t.signal,timeoutMs:15e3,retryPolicy:!1});if(a)return;d(),u({status:`ready`,roles:n})}catch(e){if(a)return;if(c=e,!P2(e)){d(),u({status:`error`,error:e});return}u({status:`retrying`});let t=Math.min(1e3*2**o++,8e3)*(.5+Math.random()*.5);l=setTimeout(()=>{m()},t)}};return u({status:`loading`}),m(),d},[e,n,r,i]),{state:o?.client===e&&o.tokenKey===n&&o.attempt===i?o.state:{status:`loading`},retry:c}}var I2=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??L2(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(M2(e))return e.some(e=>this.permissions.has(e));for(let t of e)if(!this.permissions.has(t))return!1;return!0}};function L2(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 R2=dt(void 0);function z2(){let e=_t(R2);if(!e)throw Error(`UserPermissionContext cannot be used outside UserPermissionProvider`);return e}function B2({children:e,loadingIcon:n,LoadingScreen:r}){let{t:i}=K(),a=q(),o=a.authToken,{state:s,retry:c}=F2(a.client,o),l=U(()=>{if(o){if(o.permissions)return new I2(o);if(s.status===`ready`)return new I2(o,s.roles)}},[o,s]);if(o&&!l){let e=s.status===`error`,o=e?N2(s.error):void 0,l=o===401,u=o===403,d=i(l?`auth.recovery.credential.title`:u?`shell.accessDenied`:e?`permissions.connectionFailed`:`permissions.connecting`),f=l?i(`auth.recovery.credential.body`):u?i(`permissions.accessDenied`):e?i(`permissions.tryAgainLater`):s.status===`retrying`?i(`permissions.retrying`):i(`permissions.loadingPermissions`),p=i(l||u?`auth.recovery.useDifferentAccount`:`auth.recovery.tryAgain`),m=l||u?()=>a.signOut():c;return t(r??V2,{status:e?`error`:s.status===`retrying`?`retrying`:`loading`,error:e?s.error:void 0,title:d,description:f,loadingIcon:n,actionLabel:p,onAction:m})}return l&&t(R2.Provider,{value:l,children:e})}function V2({status:r,error:i,title:a,description:s,loadingIcon:c,actionLabel:l,onAction:u}){let{t:d}=K(),f=r===`error`;return t(`div`,{className:`flex min-h-dvh items-center justify-center bg-background px-6 text-foreground`,children:n(`div`,{className:`w-full max-w-md space-y-6 text-center`,children:[t(`div`,{"aria-hidden":`true`,className:`flex justify-center`,children:c||!f&&t(je,{size:`2xl`,className:`text-info`})}),n(`div`,{role:f?`alert`:`status`,"aria-live":f?`assertive`:`polite`,className:`space-y-2`,children:[t(`h1`,{className:`text-xl font-semibold`,children:a}),t(`p`,{className:`text-muted`,children:s})]}),f&&n(e,{children:[t(o,{variant:`outline`,onClick:u,children:l}),i!=null&&n(`details`,{className:`text-start text-sm text-muted`,children:[t(`summary`,{className:`cursor-pointer`,children:d(`auth.recovery.technicalDetails`)}),t(`pre`,{className:`mt-2 max-h-48 overflow-auto whitespace-pre-wrap wrap-break-word`,children:Ge(i)})]})]})]})})}function H2({permission:e,isDisabled:n,title:r,children:i,...a}){return z2().hasPermission(e)?t(o,{isDisabled:n,title:r,...a,children:i}):null}function U2({permission:e,...n}){return z2().hasPermission(e)?t(or,{...n}):null}const W2=new WeakMap;function G2(e,t){let n=W2.get(e);n||(n=new Map,W2.set(e,n));let r=n.get(t);return r||(r=e.types.catalog.resolve(t).then(e=>e??void 0,()=>{W2.get(e)?.delete(t)}),n.set(t,r)),r}function K2(e,t){let n=W2.get(e);n&&(t?n.delete(t):n.clear())}Q();function q2(e){let t=e.configuration?.defaults?.system?.agent??e.configuration?.defaults?.base;return{environment:t?.environment,model:t?.model}}function J2(e){return e.name}function Y2(e){return e.name}function X2(e){return e.split(`/`).filter(Boolean).pop()||e}function Z2({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:X2(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(Qy,{className:`size-3.5 shrink-0`}),t(`span`,{className:`min-w-0 truncate`,children:S}),t(uh,{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:J2,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:Y2,filterBy:`name`,placeholder:c(`agent.documentEditingSelectModel`),onChange:x,disabled:i||!e.environment,isLoading:h,warnOnMissingValue:!1})]})]})]})}Q();function Q2({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(uv,{className:`size-3.5 shrink-0 animate-pulse`}):t(pv,{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?pv:uv,{className:`size-3.5`})})})]})}const $2=/artifact:(?!agents\/)(?!documents\/)([^\s)\]"]+)/g;function e4(e){let t=new Set;for(let n of e.matchAll($2))t.add(n[1].replace(/^\/+/,``));return[...t]}async function t4(e,t,n,r){let i=e4(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($2,(e,t)=>{let n=a.get(t.replace(/^\/+/,``));return n?`artifact:${n}`:e}),persisted:o,failed:s}}const n4=[`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`],r4=[`artifact_operations`,`code_execution`],i4=[`update_document`,`update_document_properties`,`create_document`,`set_document_type`,`merge_documents`,`import_file`,`create_or_update_object_type`,`disable_type`,`batch_execute`];function a4(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(`
1415
- `)}const o4=`document-editing`,s4=`sys:GeneralAgent`,c4=new Set,l4=new Set([`text/markdown`,`text/x-markdown`]),u4=new Set([...l4,`text/plain`]);function d4(e,t){return`${e}:${t}`}function f4(e){return c4.has(e)}function p4(e,t){t?c4.add(e):c4.delete(e)}function m4(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function h4(e){return`document-root:${e}`}function g4(e){return`document:${e}`}function _4(e,t){return{tags:[o4,h4(t),g4(e)],properties:{resource_kind:`store_document`,document_id:e,document_root_id:t}}}function v4(e,t){return{canEdit:e,canCollaborate:t}}function y4(e){return e?.split(`;`,1)[0]?.trim().toLowerCase()||void 0}function b4(e){let t=y4(e);return t!==void 0&&l4.has(t)}function x4(e){let t=y4(e);return t!==void 0&&u4.has(t)}function S4(e,t,n,r,i=s4){if(e.interaction!==i||e.started_by!==r||e.status===`cancelled`)return!1;let a=e.tags??[];if(!a.includes(o4))return!1;let o=m4(e.properties);return a.includes(h4(n))?o?.resource_kind===`store_document`&&o.document_root_id===n:a.includes(g4(n))||a.includes(g4(t))}async function C4(e,t,n,r,i,a){for(let o of t)try{let t=await e.retrieve(o);if(S4(t,n,r,i,a))return t}catch{}}async function w4(e,t,n,r,i=s4){let a=[h4(n),g4(n),g4(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 C4(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`&&S4(e,t,n,r,i))}var T4=class extends Error{constructor(e,t){super(e,t===void 0?void 0:{cause:t}),this.name=`DocumentEditingTargetError`}};async function E4(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 T4(`Expected one head revision for document ${t}, found ${i.length}`);if(r=await e.retrieve(i[0].id),r.revision?.head!==!0)throw new T4(`Resolved document ${r.id} is no longer the current head`)}let i=r.content?.etag;if(!i)throw new T4(`Document ${r.id} has no content ETag`);let a=await e.getObjectText(r.id);if(typeof a.text!=`string`)throw new T4(`Document ${r.id} has no text content`);return{id:r.id,etag:i,content:a.text}}var D4=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 O4({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 D4;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-info rounded-md`,children:n(`p`,{className:`text-sm text-info 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(R,{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 k4(e){return e.length>12?`${e.slice(0,4)}…${e.slice(-4)}`:e}function A4(e){return`drafts/${e}.md`}function j4(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(`
1416
- `)}function M4(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(`
1417
- `)}function N4(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(`
1418
- `)}function P4(e){if(e&&typeof e==`object`&&`status`in e)return typeof e.status==`number`?e.status:void 0}function F4({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 I4({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,te=U(()=>JSON.parse(L),[L]),[R,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(te),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(()=>A4(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(te),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,te]),H(()=>{let e=!1,t=Ze,n=tt.current.id;return A(!0),M(!1),E4(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:s4});return}return G2(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(te),ne(!1)):Ve.current===`host`&&(Ve.current=`none`,Be({})))},[x,ee,te]),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(q2(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),w4(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||R)){w(!0);try{if(!ze.environment||!ze.model){_({status:`error`,title:g(`agent.documentEditingDefaultsRequired`),duration:5e3});return}let n=j4(r,Ne,Fe,Ye,e?.trim()||g(`agent.documentEditingInitialRequest`)),i=_4(Ne,Je),a={interaction:$e,interactive:!0,tool_approval_mode:t?.tool_approval_mode,tool_names:n4,excluded_tools:i4,initial_skills:r4,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,R,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||R||!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,R,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 t4(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=P4(e),n=t===412;if(t===412||t===400)try{let e=await E4(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(M4(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(N4(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(a4(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(sh,{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/`,k4(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(),` `,k4(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(Qg,{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(Kg,{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(S_,{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(iv,{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(Sy,{className:`size-4`})})}),t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),t(Z2,{value:ze,onChange:B,disabled:!!x||C||D,isLoading:R}),x?null:n(o,{variant:`primary`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>void ct(g(`agent.documentEditingStartRequest`)),disabled:C||D||k||R||j||!f||!$e||!ze.environment||!ze.model,children:[C?t(je,{size:`sm`}):t(tb,{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:k4(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(Ty,{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(jy,{className:`size-4`}),g(`agent.saveToDocument`)]}),s?t(o,{variant:`ghost`,size:`sm`,onClick:()=>void vt(),"aria-label":g(`agent.close`),children:t(ix,{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(ix,{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(F4,{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(Q2,{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(_0,{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(O4,{isOpen:ae,onClose:()=>oe(!1),onConfirm:pt,isLoading:re})]})}function L4({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(I4,{object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s})})}function R4({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-muted`,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-success`,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(O4,{isOpen:v,onClose:M,onConfirm:j,isLoading:m})]})}const z4=ht(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownDocumentEditor})));function B4(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 V4({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=B4(r.content?.type),C=b4(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(z4,{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(O4,{isOpen:b,onClose:()=>x(!1),onConfirm:D,isLoading:v})]})}const H4=131072;function U4(e,t,n=!1,r=e){let{store:i}=q(),[a,o]=G(t),[s,c]=G(()=>t&&t.length>H4?t.substring(0,H4):t),[l,u]=G(!1),[d,f]=G(()=>!!t&&t.length>H4),[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>H4?(c(e.substring(0,H4)),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 W4(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 G4(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(),DX();const K4=()=>({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 q4(e){return e===fn.created||e===fn.processing}function J4(e){return e.metadata?.content_processor?.type}function Y4(e){return e?e.includes(`
1414
+ `));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&&qU(r,i),(async()=>{await Or(),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,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=hn.current;return Ye.agents.retrieve(r).then(n=>{e||(Mr(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 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=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]),Ir=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation(),fn.current++,e.dataTransfer?.types?.includes(`Files`)&&Gt(!0))},[Ot]),Lr=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation())},[Ot]),Rr=V(e=>{Ot&&(e.preventDefault(),e.stopPropagation(),fn.current--,fn.current===0&&Gt(!1))},[Ot]),zr=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]),Br=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]),Vr=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?Br:null),()=>{xe&&(xe.current=null)}),[xe,Qn,Br,h]),H(()=>{Se?.(Vt)},[Vt,Se]);let Hr=i||Je(`agent.agentConversation`),Ur=async()=>{try{let e=await bU(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}:{}};_0(`${g0(Hr)||`agent-chat`}-${g0(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(!jt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}Kr(!0)},Jr=()=>{if(!jt.current){Xe({status:`error`,title:Je(`agent.pdfExportFailed`),description:Je(`agent.noConversationContent`),duration:3e3});return}let e=`${Hr} - ${r}`;if(!m0(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}),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&&Un&&xn?.toUpperCase()===`RUNNING`,Qr=U(()=>kn.plan.plan?.reduce((e,t)=>(t.id&&t.goal&&e.set(t.id.toString(),t.goal),e),new Map),[kn.plan]),$r=e=>t(IZ,{title:Hr,variant:e,isCompleted:Qn,isTerminal:Sn,onClose:s,isModal:c,agentRunId:r,workflowRunId:ot||``,viewMode:zt,onViewModeChange:Bt,showPlanPanel:br,hasPlan:A&&ct.length>0,showPlanButton:A&&!Be,onTogglePlanPanel:Sr,showPlaybackButton:Ln,isPlaybackEnabled:Rn,onTogglePlayback:sr,onDownload:Ur,onExportFixture:Wr,resetWorkflow:d,onClone:p,onShowDetails:m,allowWorkflowControl:h,onExportPdf:qr,isReceivingChunks:tt}),ei=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`: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)}),Rn&&t(`div`,{className:`flex flex-shrink-0 justify-end px-2 py-1.5`,children:t(PC,{cursor:Hn,messages:Bn,onChangeCursor:cr})}),Ze.length===0&&!Qn&&Ve&&He?t(p0,{message:Ve,startedAt:He}):t(MW,{agentRunId:r,children:t(iY,{messages:Kn,workstreamSourceMessages:qn,bottomRef:At,isCompleted:$n,plan:kn.plan,workstreamStatus:kn.workstreamStatus,showPlanPanel:A&&pt,onTogglePlanPanel:Sr,plans:ct,activePlanIndex:lt,onChangePlan:lr,taskLabels:Qr,streamingMessages:Jn,onSendMessage:Un?kr:void 0,onOpenArtifact:M?wr:void 0,messageItemClassNames:Ce,messageStyleOverrides:we,toolCallGroupClassNames:Te,hideToolCallsInViewMode:Ee,streamingMessageClassNames:De,batchProgressPanelClassNames:Oe,artifactRunId:r,agentRunId:r,viewMode:zt,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:!Un,renderRequestInputControls:!nr,activeWorkstream:Kt,onActiveWorkstreamChange:qt})}),nr?t(yW,{message:tr,onSendMessage:Un?kr:void 0,onMcpConnected:Un?Ar:void 0,disabled:L||!Un,isLoading:Nt||L}):rr&&Zn.length>0?t(`div`,{className:`flex-shrink-0 pb-safe-area`,children:t(DZ,{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(Uh,{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(B1,{onSend:kr,onStop:h?Br:void 0,approvalModeSlot:a&&ln?t(cx,{mode:ln,onChange:Fr,disabled:!Un||Sn||!h}):void 0,mcpSlot:t(SY,{disabledCollections:jr,onChange:Nr,onConnectionChange:Pr}),disabled:L||!Un,isSending:Nt||L,isStopping:Vt,isStreaming:!Qn,isCompleted:Qn,contextWindowUsage:or?ar:void 0,onCompactContext:or?Vr: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:R,inputClassName:ne})]})})]}),ti=t($S,{children:t(iG,{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-info ring-inset`,te),onDragEnter:Ot?Ir:void 0,onDragOver:Ot?Lr:void 0,onDragLeave:Ot?Rr:void 0,onDrop:Ot?zr:void 0,children:[Ot&&Wt&&t(`div`,{className:`absolute inset-0 flex items-center justify-center bg-info/80 dark:bg-info/40 z-50 pointer-events-none rounded-lg`,children:n(`div`,{className:`text-info font-medium flex items-center gap-2 text-lg`,children:[t(Lb,{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=Mt.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(aZ,{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: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:ur??fr,activeTab:ur??fr,onTabChange:dr})})]}),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:yC,artifactRunId:r,children:ti}):ti}function S0({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(YG,{message:e,showPulsatingCircle:!1},`${e.workstream_id??`main`}-${e.timestamp}-${e.type}`))})}function C0({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-muted`,children:`Waiting for agent response...`})}):t(`div`,{className:`flex-1 flex flex-col justify-start h-full min-h-0 ${i||``}`,children:t(S0,{messages:s,isCompleted:!1})})})}function w0(e){return e.name}function T0({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:w0,options:u??[],value:c,onChange:e=>{l(e),n(e)},placeholder:o(`intakePolicy.placeholder.environment`),filterBy:`name`,disabled:a,isLoading:d})}function E0(e){return e.name}function D0(e){return e?.length?n=>{let r=e.some(e=>e.id===n.id);return t(`span`,{className:r?`opacity-50`:``,children:n.name})}:E0}function O0({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:D0(o),options:f??[],value:u,onChange:e=>{d(e),r(e)},placeholder:c(`intakePolicy.placeholder.model`),disabled:a,isLoading:p})}function k0({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:E0,options:c??[],value:o,onChange:e=>{s(e),r(e)},placeholder:i(`intakePolicy.placeholder.model`),disabled:!e,isLoading:l})}function A0({children:e,fallback:n}){return j0?t(j0,{fallback:n,children:e}):t(ir,{FallbackComponent:n,children:e})}let j0=null;function M0(e){j0=e}function N0({children:e}){return t(A0,{fallback:P0,children:e})}function P0({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 F0({children:e}){return t(A0,{fallback:I0,children:e})}function I0({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-muted`,children:r})]})})}function L0({children:e}){return t(A0,{fallback:R0,children:e})}function R0({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 z0=/^[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 B0(e){return z0.test(e)}function V0({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(B0(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 Array.isArray(c)&&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})(),g=!!i&&h.length===0;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(gh,{className:`size-3.5 cn-rtl-flip`}),maxItems:4}),o&&!g&&t(We,{description:o,children:t(L_,{className:`size-4 text-muted ms-4`})})]}),i&&n(`div`,{className:`flex gap-2 items-center`,children:[t(`h1`,{className:`text-xl font-semibold break-all`,children:i}),o&&g&&t(We,{description:o,children:t(L_,{className:`size-4 text-muted`})})]})]}),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 H0(){let{t:e}=K();return n(`div`,{className:`text-center pt-32`,children:[t(`h1`,{className:`text-3xl font-bold text-destructive`,children:`404`}),t(`p`,{className:`text-2xl`,children:e(`layout.pageNotFound`)})]})}Q();const U0=`magic-pdf`;function W0(e){return e.replace(/^\$\.?/,``).replace(/^data\./,``)}function G0(e){let{client:t}=q(),[n,r]=G(!1);return H(()=>{let n=!1;return r(!1),t.files.getDownloadUrl(`${U0}/${e}/grounded-extraction.json`).then(e=>fetch(e.url,{method:`HEAD`})).then(e=>{n||r(e.ok)}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function K0(e){let{client:t}=q(),[n,r]=G(null);return H(()=>{let n=!1;return r(null),t.files.getDownloadUrl(`${U0}/${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 q0({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(`${U0}/${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(Y0,{extraction:s,objectId:e,onClose:r})})}function J0({objectId:e,onClose:n}){return t(`div`,{className:`fixed inset-0 bg-background z-50`,children:t(q0,{objectId:e,onClose:n})})}function Y0({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(`${U0}/${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=W0(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(W0(e))?.[0];t&&p(t.page)},E=u.indexOf(f),D=m?x.get(W0(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(ph,{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(gh,{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(P_,{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(O_,{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(X0,{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?Bh:Lg,{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(Og,{className:`size-4`})}),children:[n(ae,{className:`text-xs`,onClick:()=>d(`grounded-extraction.json`),children:[t(Bg,{className:`size-4`}),c(`grounded.downloadCitations`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`pages/page-${f}.json`),children:[t(Qg,{className:`size-4`}),c(`grounded.downloadBlocks`)]}),n(ae,{className:`text-xs`,onClick:()=>d(`grounded-annotated.pdf`),children:[t(Ug,{className:`size-4`}),c(`grounded.downloadAnnotated`)]})]}),!!s&&t(o,{variant:`ghost`,size:`xs`,onClick:s,"aria-label":c(`pdf.close`),children:t(ix,{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(L_,{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(Z0,{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 X0({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(`${U0}/${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&&W0(o)===W0(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:e2(e.path).map((e,r)=>n(lt,{children:[r>0&&t(gh,{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(W0(e.path)),className:z(`absolute cursor-pointer border rounded-[1px] transition-colors`,e.misaligned&&`border-dashed`,c?`border-2 border-info bg-info 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 Z0({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(Q0,{items:e,path:r,citationsByPath:i,selectedPath:a,onSelect:o}):t(`div`,{className:`space-y-1`,children:e.map((e,n)=>t(Z0,{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($0,{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:t2(e)}),t(Z0,{value:s,path:c,citationsByPath:i,selectedPath:a,onSelect:o})]},c)})}):null}function Q0({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:[t2(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:t2(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-info ring-1 ring-primary`:d?`hover:bg-muted cursor-pointer`:`text-muted cursor-default`),children:[i2(e[c]),d&&typeof d.confidence==`number`&&t(`span`,{className:z(`ms-1 text-[10px]`,r2(d.confidence)),title:s(`grounded.scoreHint`),children:n2(d.confidence)})]})},c)})},`${r}[${l}]`))})]})})]})}function $0({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-info ring-1 ring-primary`:l?`hover:bg-muted`:``,!l&&`cursor-default`),children:[n(`span`,{className:`min-w-28 shrink-0 font-semibold`,children:[t2(e),`:`]}),t(`span`,{className:`flex-1 wrap-break-word`,children:i2(r)}),l&&typeof l.confidence==`number`&&t(`span`,{className:z(`text-xs shrink-0`,r2(l.confidence)),title:c(`grounded.scoreHint`),children:n2(l.confidence)}),l&&(l.verified?t(Bh,{"aria-label":c(`grounded.verified`),className:`size-3.5 shrink-0 text-success`}):l.reviewed?t(tb,{"aria-label":c(`grounded.aiVerified`),className:`size-3.5 shrink-0 text-info`}):t(Lg,{"aria-label":c(`grounded.readFromImage`),className:`size-3.5 shrink-0 text-attention`}))]})}function e2(e){return W0(e).split(`.`).map(e=>t2(e.replace(/\[\d+\]/g,``))).filter(Boolean)}function t2(e){return e?zt(e):``}function n2(e){let t=e*100;return Number.isInteger(t)?`${t}%`:`${(Math.floor(t*100)/100).toFixed(2)}%`}function r2(e){return e>=.95?`text-success`:e>=.7?`text-attention`:`text-destructive`}function i2(e){return e==null||e===``?`—`:typeof e==`boolean`?e?`true`:`false`:typeof e==`object`?JSON.stringify(e):String(e)}const a2=`magic-pdf`;var o2;(function(e){e.original=`original`,e.instrumented=`instrumented`})(o2||={});var s2=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=`${a2}/${this.objectId}/pages`;switch(t){case o2.original:return`${n}/page-${e}.original.jpg`;case o2.instrumented:return`${n}/page-${e}.instrumented.jpg`}}},c2=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=`${a2}/${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()}},l2=class{totalPages;pages=[];constructor(e){this.totalPages=e}initFromContent(e){this.pages=u2(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 u2(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 d2=dt(void 0);function f2({children:e,object:n}){let{client:r}=q(),i=n.metadata.page_count||10,[a,o]=G(()=>{let e=new l2(i);return n.text&&e.initFromContent(n.text),{count:i,layoutProvider:new c2(r,n.id,i),markdownProvider:e,imageProvider:new s2(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(d2.Provider,{value:a,children:e})}function p2(e,t,n){return e.files.getDownloadUrl(`${a2}/${t}/${n}`).then(e=>e.url)}function m2(){let e=ot.useContext(d2);if(!e)throw Error(`useMagicPdfContext must be used within a MagicPdfProvider`);return e}Q();function h2({object:e}){let{t:n}=K(),{client:r}=q(),i=t=>{p2(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(Og,{className:`size-4`})})}Q();function g2({className:e}){return t(`div`,{className:`flex items-center justify-center ${e||``}`,children:t(sv,{className:`w-6 h-6 animate-spin text-muted`})})}function _2({viewType:e,pageNumber:n}){switch(e){case`json`:return t(v2,{pageNumber:n});case`markdown`:return t(y2,{pageNumber:n});default:return t(y2,{pageNumber:n})}}function v2({pageNumber:e}){let[n,r]=G(null),[i,a]=G(!0),[o,s]=G(null),{layoutProvider:c}=m2();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(g2,{})}):o?t(`div`,{className:`px-4 py-2 text-destructive text-sm`,children:o}):n?t(At,{className:`w-full`,data:n}):null}function y2({pageNumber:e}){let[r,i]=G(null),[a,o]=G(!0),[s,c]=G(null),{markdownProvider:l}=m2();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(g2,{}),t(`span`,{className:`text-sm text-muted`,children:`Loading...`})]}):s?t(`div`,{className:`px-4 py-2 text-destructive 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(),$Y();var b2=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 x2({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(b2,{onClose:r,children:t(`div`,{className:`fixed inset-0 bg-background z-50 flex items-center justify-center`,children:t(f2,{object:s,children:t(S2,{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(ix,{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 S2({object:e,onClose:r}){let{t:i}=K(),{count:a,pdfUrl:s,pdfUrlLoading:c}=m2(),[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(qY,{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(h2,{object:e})}),t(`span`,{className:`text-xs text-muted`,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(ix,{className:`size-4`})})})]}),t(`div`,{className:`flex-1 overflow-auto px-2`,children:t(_2,{pageNumber:l,viewType:`markdown`})})]})]})}const C2=[`image/jpeg`,`image/jpg`,`image/png`,`image/gif`,`image/webp`,`image/svg+xml`],w2=[`video/mp4`,`video/webm`],T2=[`audio/mp4`,`audio/m4a`,`audio/x-m4a`,`audio/mpeg`,`audio/ogg`,`audio/wav`,`audio/webm`];function E2(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 D2({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&&T2.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: `,E2(f.duration)]})]}):t(`div`,{className:`flex justify-center items-center h-[200px] text-muted ${a??``}`.trim(),children:`Failed to load audio`})}function O2({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&&C2.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 k2({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&&w2.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 A2({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}=EO({onComplete:()=>{f(!1),h(),i?.()},onError:e=>{console.error(`OAuth provider auth failed:`,e),f(!1)}});return l?t(wO,{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(Bh,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.connected`)})]}),t(yT,{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(wO,{className:`size-3`}):o(`oauthProvider.disconnect`)})]}):t(yT,{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(wO,{className:`size-4`}),t(`span`,{children:o(`oauthProvider.authenticating`)})]}):n(e,{children:[t(Pg,{className:`size-4 me-1`}),t(`span`,{children:o(`oauthProvider.authenticate`)})]})})}function j2(...e){let t=Array.from(e);return t.__AnyOf__=!0,t}function M2(...e){return Array.from(e)}function N2(e){return e.__AnyOf__===!0}function P2(e){if(e&&typeof e==`object`&&`status`in e&&typeof e.status==`number`)return e.status}function F2(e){let t=P2(e);return t===0||t===502||t===503||t===504||e instanceof Error&&e.name===`TimeoutError`}function I2(e,t){let n=U(()=>t?JSON.stringify(t):void 0,[t]),r=!(!t||t.permissions),[i,a]=G(0),[o,s]=G(),c=V(()=>a(e=>e+1),[]);return H(()=>{if(!r)return;let t=new AbortController,a=!1,o=0,c,l,u=t=>s({client:e,tokenKey:n,attempt:i,state:t}),d=()=>{a=!0,clearTimeout(f),clearTimeout(p),clearTimeout(l),t.abort()},f=setTimeout(()=>u({status:`retrying`}),5e3),p=setTimeout(()=>{d(),u({status:`error`,error:c})},6e4),m=async()=>{try{let n=await e.iam.roles.listSystem({signal:t.signal,timeoutMs:15e3,retryPolicy:!1});if(a)return;d(),u({status:`ready`,roles:n})}catch(e){if(a)return;if(c=e,!F2(e)){d(),u({status:`error`,error:e});return}u({status:`retrying`});let t=Math.min(1e3*2**o++,8e3)*(.5+Math.random()*.5);l=setTimeout(()=>{m()},t)}};return u({status:`loading`}),m(),d},[e,n,r,i]),{state:o?.client===e&&o.tokenKey===n&&o.attempt===i?o.state:{status:`loading`},retry:c}}var L2=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??R2(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(N2(e))return e.some(e=>this.permissions.has(e));for(let t of e)if(!this.permissions.has(t))return!1;return!0}};function R2(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 z2=dt(void 0);function B2(){let e=_t(z2);if(!e)throw Error(`UserPermissionContext cannot be used outside UserPermissionProvider`);return e}function V2({children:e,loadingIcon:n,LoadingScreen:r}){let{t:i}=K(),a=q(),o=a.authToken,{state:s,retry:c}=I2(a.client,o),l=U(()=>{if(o){if(o.permissions)return new L2(o);if(s.status===`ready`)return new L2(o,s.roles)}},[o,s]);if(o&&!l){let e=s.status===`error`,o=e?P2(s.error):void 0,l=o===401,u=o===403,d=i(l?`auth.recovery.credential.title`:u?`shell.accessDenied`:e?`permissions.connectionFailed`:`permissions.connecting`),f=l?i(`auth.recovery.credential.body`):u?i(`permissions.accessDenied`):e?i(`permissions.tryAgainLater`):s.status===`retrying`?i(`permissions.retrying`):i(`permissions.loadingPermissions`),p=i(l||u?`auth.recovery.useDifferentAccount`:`auth.recovery.tryAgain`),m=l||u?()=>a.signOut():c;return t(r??H2,{status:e?`error`:s.status===`retrying`?`retrying`:`loading`,error:e?s.error:void 0,title:d,description:f,loadingIcon:n,actionLabel:p,onAction:m})}return l&&t(z2.Provider,{value:l,children:e})}function H2({status:r,error:i,title:a,description:s,loadingIcon:c,actionLabel:l,onAction:u}){let{t:d}=K(),f=r===`error`;return t(`div`,{className:`flex min-h-dvh items-center justify-center bg-background px-6 text-foreground`,children:n(`div`,{className:`w-full max-w-md space-y-6 text-center`,children:[t(`div`,{"aria-hidden":`true`,className:`flex justify-center`,children:c||!f&&t(je,{size:`2xl`,className:`text-info`})}),n(`div`,{role:f?`alert`:`status`,"aria-live":f?`assertive`:`polite`,className:`space-y-2`,children:[t(`h1`,{className:`text-xl font-semibold`,children:a}),t(`p`,{className:`text-muted`,children:s})]}),f&&n(e,{children:[t(o,{variant:`outline`,onClick:u,children:l}),i!=null&&n(`details`,{className:`text-start text-sm text-muted`,children:[t(`summary`,{className:`cursor-pointer`,children:d(`auth.recovery.technicalDetails`)}),t(`pre`,{className:`mt-2 max-h-48 overflow-auto whitespace-pre-wrap wrap-break-word`,children:Ge(i)})]})]})]})})}function U2({permission:e,isDisabled:n,title:r,children:i,...a}){return B2().hasPermission(e)?t(o,{isDisabled:n,title:r,...a,children:i}):null}function W2({permission:e,...n}){return B2().hasPermission(e)?t(or,{...n}):null}const G2=new WeakMap;function K2(e,t){let n=G2.get(e);n||(n=new Map,G2.set(e,n));let r=n.get(t);return r||(r=e.types.catalog.resolve(t).then(e=>e??void 0,()=>{G2.get(e)?.delete(t)}),n.set(t,r)),r}function q2(e,t){let n=G2.get(e);n&&(t?n.delete(t):n.clear())}Q();function J2(e){let t=e.configuration?.defaults?.system?.agent??e.configuration?.defaults?.base;return{environment:t?.environment,model:t?.model}}function Y2(e){return e.name}function X2(e){return e.name}function Z2(e){return e.split(`/`).filter(Boolean).pop()||e}function Q2({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:Z2(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(Qy,{className:`size-3.5 shrink-0`}),t(`span`,{className:`min-w-0 truncate`,children:S}),t(uh,{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:Y2,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:X2,filterBy:`name`,placeholder:c(`agent.documentEditingSelectModel`),onChange:x,disabled:i||!e.environment,isLoading:h,warnOnMissingValue:!1})]})]})]})}Q();function $2({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(uv,{className:`size-3.5 shrink-0 animate-pulse`}):t(pv,{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?pv:uv,{className:`size-3.5`})})})]})}const e4=/artifact:(?!agents\/)(?!documents\/)([^\s)\]"]+)/g;function t4(e){let t=new Set;for(let n of e.matchAll(e4))t.add(n[1].replace(/^\/+/,``));return[...t]}async function n4(e,t,n,r){let i=t4(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(e4,(e,t)=>{let n=a.get(t.replace(/^\/+/,``));return n?`artifact:${n}`:e}),persisted:o,failed:s}}const r4=[`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`],i4=[`artifact_operations`,`code_execution`],a4=[`update_document`,`update_document_properties`,`create_document`,`set_document_type`,`merge_documents`,`import_file`,`create_or_update_object_type`,`disable_type`,`batch_execute`];function o4(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(`
1415
+ `)}const s4=`document-editing`,c4=`sys:GeneralAgent`,l4=new Set,u4=new Set([`text/markdown`,`text/x-markdown`]),d4=new Set([...u4,`text/plain`]);function f4(e,t){return`${e}:${t}`}function p4(e){return l4.has(e)}function m4(e,t){t?l4.add(e):l4.delete(e)}function h4(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:void 0}function g4(e){return`document-root:${e}`}function _4(e){return`document:${e}`}function v4(e,t){return{tags:[s4,g4(t),_4(e)],properties:{resource_kind:`store_document`,document_id:e,document_root_id:t}}}function y4(e,t){return{canEdit:e,canCollaborate:t}}function b4(e){return e?.split(`;`,1)[0]?.trim().toLowerCase()||void 0}function x4(e){let t=b4(e);return t!==void 0&&u4.has(t)}function S4(e){let t=b4(e);return t!==void 0&&d4.has(t)}function C4(e,t,n,r,i=c4){if(e.interaction!==i||e.started_by!==r||e.status===`cancelled`)return!1;let a=e.tags??[];if(!a.includes(s4))return!1;let o=h4(e.properties);return a.includes(g4(n))?o?.resource_kind===`store_document`&&o.document_root_id===n:a.includes(_4(n))||a.includes(_4(t))}async function w4(e,t,n,r,i,a){for(let o of t)try{let t=await e.retrieve(o);if(C4(t,n,r,i,a))return t}catch{}}async function T4(e,t,n,r,i=c4){let a=[g4(n),_4(n),_4(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 w4(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`&&C4(e,t,n,r,i))}var E4=class extends Error{constructor(e,t){super(e,t===void 0?void 0:{cause:t}),this.name=`DocumentEditingTargetError`}};async function D4(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 E4(`Expected one head revision for document ${t}, found ${i.length}`);if(r=await e.retrieve(i[0].id),r.revision?.head!==!0)throw new E4(`Resolved document ${r.id} is no longer the current head`)}let i=r.content?.etag;if(!i)throw new E4(`Document ${r.id} has no content ETag`);let a=await e.getObjectText(r.id);if(typeof a.text!=`string`)throw new E4(`Document ${r.id} has no text content`);return{id:r.id,etag:i,content:a.text}}var O4=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 k4({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 O4;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-info rounded-md`,children:n(`p`,{className:`text-sm text-info 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(R,{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 A4(e){return e.length>12?`${e.slice(0,4)}…${e.slice(-4)}`:e}function j4(e){return`drafts/${e}.md`}function M4(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(`
1416
+ `)}function N4(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(`
1417
+ `)}function P4(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(`
1418
+ `)}function F4(e){if(e&&typeof e==`object`&&`status`in e)return typeof e.status==`number`?e.status:void 0}function I4({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 L4({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,te=U(()=>JSON.parse(L),[L]),[R,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(te),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(()=>j4(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(te),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,te]),H(()=>{let e=!1,t=Ze,n=tt.current.id;return A(!0),M(!1),D4(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:c4});return}return K2(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(te),ne(!1)):Ve.current===`host`&&(Ve.current=`none`,Be({})))},[x,ee,te]),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(J2(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),T4(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||R)){w(!0);try{if(!ze.environment||!ze.model){_({status:`error`,title:g(`agent.documentEditingDefaultsRequired`),duration:5e3});return}let n=M4(r,Ne,Fe,Ye,e?.trim()||g(`agent.documentEditingInitialRequest`)),i=v4(Ne,Je),a={interaction:$e,interactive:!0,tool_approval_mode:t?.tool_approval_mode,tool_names:r4,excluded_tools:a4,initial_skills:i4,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,R,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||R||!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,R,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 n4(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=F4(e),n=t===412;if(t===412||t===400)try{let e=await D4(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(N4(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(P4(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(o4(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(sh,{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/`,A4(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(),` `,A4(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(Qg,{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(Kg,{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(S_,{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(iv,{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(Sy,{className:`size-4`})})}),t(`div`,{"aria-hidden":!0,className:`mx-1 h-6 w-px bg-mixer-muted/25`}),t(Q2,{value:ze,onChange:B,disabled:!!x||C||D,isLoading:R}),x?null:n(o,{variant:`primary`,size:`sm`,className:`h-8 gap-1.5`,onClick:()=>void ct(g(`agent.documentEditingStartRequest`)),disabled:C||D||k||R||j||!f||!$e||!ze.environment||!ze.model,children:[C?t(je,{size:`sm`}):t(tb,{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:A4(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(Ty,{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(jy,{className:`size-4`}),g(`agent.saveToDocument`)]}),s?t(o,{variant:`ghost`,size:`sm`,onClick:()=>void vt(),"aria-label":g(`agent.close`),children:t(ix,{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(ix,{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(I4,{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($2,{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(v0,{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(k4,{isOpen:ae,onClose:()=>oe(!1),onConfirm:pt,isLoading:re})]})}function R4({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(L4,{object:e,initialContent:n,onClose:r,onDocumentUpdated:i,sendMessageRef:a,model:o,startImmediately:s})})}function z4({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-muted`,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-success`,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(k4,{isOpen:v,onClose:M,onConfirm:j,isLoading:m})]})}const B4=ht(()=>import(`@vertesia/ui/rich-text`).then(e=>({default:e.VertesiaMarkdownDocumentEditor})));function V4(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 H4({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=V4(r.content?.type),C=x4(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(B4,{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(k4,{isOpen:b,onClose:()=>x(!1),onConfirm:D,isLoading:v})]})}const U4=131072;function W4(e,t,n=!1,r=e){let{store:i}=q(),[a,o]=G(t),[s,c]=G(()=>t&&t.length>U4?t.substring(0,U4):t),[l,u]=G(!1),[d,f]=G(()=>!!t&&t.length>U4),[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>U4?(c(e.substring(0,U4)),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 G4(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 K4(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(),OX();const q4=()=>({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 J4(e){return e===fn.created||e===fn.processing}function Y4(e){return e.metadata?.content_processor?.type}function X4(e){return e?e.includes(`
1419
1419
  # `)||e.includes(`
1420
1420
  ## `)||e.includes(`
1421
1421
  ### `)||e.includes(`
1422
1422
  * `)||e.includes(`
1423
1423
  - `)||e.includes(`
1424
- + `)||e.includes(`![`)||e.includes(`](`):!1}function X4(e){return e?`h-full overflow-auto`:`hidden`}var Z4;(function(e){e.Text=`text`,e.Image=`image`,e.Video=`video`,e.Audio=`audio`,e.Pdf=`pdf`,e.Transcript=`transcript`})(Z4||={});function Q4({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?d4(u.id,p):void 0,[h,g]=G(r),[_,v]=G(()=>m?f4(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?f4(m):!1))},[m]);let C=V(()=>{v(e=>{let t=!e;return m&&p4(m,t),t})},[m]),w=V(()=>{m&&p4(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(e3,{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($4,{object:h,refetch:a??(()=>Promise.resolve()),handleCopyContent:E,canEditProperties:o})})]}),_?t(L4,{object:h,initialContent:h.text??``,onClose:w,onDocumentUpdated:(e,t)=>void T(e,t),sendMessageRef:y}):null]})}function $4({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(yg,{className:`size-4`})}),s&&t(H2,{permission:bn.content_write,variant:`ghost`,size:`sm`,onClick:()=>{f(!0)},title:`Edit properties`,className:`flex items-center gap-2`,children:t(ib,{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(R4,{isOpen:d,onClose:()=>{f(!1)},object:r,refetch:i})]})}function e3(e){let{client:n}=q(),r=e.object.type,i=r?.id,a=r?.default_view,{data:o}=Ye(async()=>!i||a?null:(await G2(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(t3,{...e,defaultView:s??void 0})}function t3({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?W$(e.content.type):!1,v=q4(e?.status),y=!!(e.transcript&&(m||h)),b=e.metadata?.renditions?.find(e=>e.name===vn),x=()=>{switch(s){case`text`:return Z4.Text;case`pdf`:if(g||_||b)return Z4.Pdf;break;case`image`:if(p)return Z4.Image;break;case`properties`:return Z4.Text}return m?Z4.Video:h?Z4.Audio:p?Z4.Image:Z4.Text},S=W0(e.id),[C,w]=G(x()),[T,E]=G(C===Z4.Pdf);H(()=>{C===Z4.Pdf&&E(!0)},[C]);let[D,O]=G(!1),k=v4(!(!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}=U4(e.id,e.text,r,e.revision?.root||e.id),F=(g||_)&&v&&(C===Z4.Text||C===Z4.Pdf),{progress:I,status:L,isComplete:ee}=W4(e.id,F),{pdfUrl:te,isConverting:R,error:ne,triggerConversion:re}=G4(e.id,_),ie=U(()=>[{id:`office-pdf-rendition`,target:`pdf`,canConvert:({contentType:e,extension:t})=>_||(e?W$(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===Z4.Pdf&&!ae,se=ae&&(C===Z4.Text||C===Z4.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===Z4.Image?`primary`:`ghost`,size:`sm`,title:f(`store.viewImage`),onClick:()=>w(Z4.Image),children:`Image`}),m&&t(o,{variant:C===Z4.Video?`primary`:`ghost`,size:`sm`,title:f(`store.viewVideo`),onClick:()=>w(Z4.Video),children:`Video`}),h&&t(o,{variant:C===Z4.Audio?`primary`:`ghost`,size:`sm`,title:f(`store.viewAudio`),onClick:()=>w(Z4.Audio),children:`Audio`}),y&&t(o,{variant:C===Z4.Transcript?`primary`:`ghost`,size:`sm`,title:f(`store.viewTranscript`),onClick:()=>w(Z4.Transcript),children:`Transcript`}),t(o,{variant:C===Z4.Text?`primary`:`ghost`,size:`sm`,title:f(`store.viewText`),onClick:()=>w(Z4.Text),children:`Text`}),g&&t(o,{variant:C===Z4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewPdf`),onClick:()=>w(Z4.Pdf),children:`PDF`}),_&&t(o,{variant:C===Z4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewAsPdf`),onClick:()=>{w(Z4.Pdf),!b&&!te&&!R&&re()},disabled:R,children:R?t(je,{size:`sm`}):`PDF`})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(a3,{object:e}),t(o3,{objectId:e.id,available:S})]})]}),C===Z4.Text&&!ae&&!D&&t(n3,{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===Z4.Pdf&&_&&(b||te)&&t(s3,{object:e,pdfRendition:b,officePdfUrl:te})]}),C===Z4.Image&&t(`div`,{className:X4(!0),children:t(D2,{object:e})}),C===Z4.Video&&t(`div`,{className:X4(!0),children:t(O2,{object:e})}),C===Z4.Audio&&t(`div`,{className:X4(!0),children:t(E2,{object:e})}),y&&C===Z4.Transcript&&t(`div`,{className:X4(!0),children:t(i3,{object:e,handleCopyContent:i})}),g&&ce&&t(`div`,{className:X4(oe),children:t(c3,{object:e})}),_&&ce&&t(`div`,{className:X4(oe),children:t(l3,{object:e,pdfRendition:b,officePdfUrl:te,converters:ie,officePdfConverting:R,officePdfError:ne})}),se&&t(`div`,{className:X4(!0),children:t(u3,{progress:I,status:L})}),C===Z4.Text&&!ae&&!D&&M&&!j&&t(`div`,{className:X4(!0),children:t(`div`,{className:`flex justify-center items-center flex-1`,children:t(je,{size:`lg`})})}),C===Z4.Text&&!ae&&!D&&(!M||j)&&t(`div`,{className:X4(!0),children:t(r3,{object:e,text:j,isTextCropped:N,textContainerRef:le})}),D&&C===Z4.Text&&A!=null&&t(V4,{object:e,text:A,onClose:()=>O(!1),onSaved:()=>{O(!1),P(),a?.()}})]})}function n3({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}=MG({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=b4(_?.type),C=x4(_?.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(yg,{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(Og,{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(Og,{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(Og,{className:`size-4`}),`Export as DOCX`]})}),t(ae,{onClick:()=>T(_n.pdf,!1),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Og,{className:`size-4`}),`Export as PDF`]})}),t(ae,{onClick:()=>T(_n.pdf),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Og,{className:`size-4`}),`Export as Branded PDF`]})})]})]}),a&&n(e,{children:[l&&c&&t(H2,{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(ib,{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(tb,{className:`size-4`})})]})]})})}const r3=gt(({object:r,text:i,isTextCropped:a,textContainerRef:o})=>{let{t:s}=K(),c=q4(r?.status),l=r.content,u=J4(r)===`xml`||l?.type===`application/xml`||l?.type===`text/xml`,d=x4(l?.type),f=!u&&(d||Y4(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(jb,{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(EX,{source:p,className:`h-full`,bodyClassName:`overflow-auto`,markdownComponents:K4()})})]}):t(`div`,{className:`px-2`,children:t(`div`,{children:c?`Extracting content...`:`No content`})})});function i3({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(yg,{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 a3({object:r}){let[i,a]=G(!1);return J4(r)===`markdown`?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>a(!0),title:`Side by side view`,children:t(Yg,{className:`size-4`})}),i&&t(ve,{children:t(b2,{objectId:r.id,onClose:()=>a(!1)})})]}):null}function o3({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(Py,{className:`size-4`})}),s&&t(ve,{children:t(q0,{objectId:r,onClose:()=>c(!1)})})]}):null}function s3({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(Og,{className:`size-4`})})})}function c3({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(EX,{source:n,className:`h-full`,showHeader:!1})})}function l3({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(jb,{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(EX,{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(EX,{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(EX,{source:l,converters:a,className:`h-full`})})}function u3({progress:r,status:i}){let{t:a}=K(),o=Z$(i),s=Q$(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(d3,{name:c?`Prepare Evidence`:`Analyze Page`,progress:r.pages}),c&&n(e,{children:[t(d3,{name:`Run OCR`,progress:r.images}),t(d3,{name:`Extract Grounded Data`,progress:r.tables}),t(d3,{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 d3({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 f3=Object.values(Sn),p3=Object.values(wn);function m3({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||f3),[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,p3.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(R,{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(Uy,{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`)}),p3.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 h3=[{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 g3(e,t){return(t?e.getTypeLayout(t):h3)??h3}function _3({onUploadDone:e=async()=>{},layout:n,toolbarActions:r}){let i=h1(),a=nt(),{t:o}=K(),s=T1(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(v3,{layout:n,onUpload:c,toolbarActions:r})}function v3({layout:e,onUpload:r,allowFilter:i=!0,allowSearch:a=!0,toolbarActions:o}){let{t:s}=K(),c=h1(),[l,u]=G(!1),[d,f]=G(null),{registry:p}=MQ(),{search:m,isLoading:h,error:g,objects:_,hasMore:v}=_1(),[y,b]=G(p?e||g3(p,m.query.type):h3);H(()=>{e&&b(e)},[e]);let[x,S]=G(0),[C,w]=G(0),[T,E]=G(localStorage.getItem(P1.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=g1(),F=h1(),I=()=>{j(m.search(),`Search refresh failed:`)},L=WQ(P),ee=GQ(F),te=e=>{let t=typeof e==`function`?e(D):e;O(t),ee(t)},R=(e,t)=>{let n=L.find(t=>t.name===e),r={name:e,type:n?.type,placeholder:n?.placeholder,multiple:n?.multiple};te(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(b3,{object:d,onClose:()=>f(null)}),g&&t(M,{title:s(`store.error`),children:g.message}),t(y3,{isLoading:h,refreshTrigger:x,allowFilter:i,allowSearch:a,filterGroups:L,filters:D,handleFilterChange:te,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(j$,{onFilter:R,children:t(D1,{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 y3(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(m3,{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(m3,{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(Sy,{size:16})}),t(P1,{onUpdate:m})]})]})}function b3({object:e,onClose:r}){let{store:i}=q(),a=nt(),s=$n(),{downloadFromContentSource:c}=MG({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(Pg,{className:`size-4`})}),l&&t(o,{variant:`ghost`,size:`sm`,title:`Download`,onClick:()=>c(l,jG(e)),children:t(Og,{className:`size-4`})})]}),t(C,{className:`my-2`}),t(`div`,{className:`pt-2`,children:t(Q4,{object:e,loadText:!0},e.id)})]}):null}const x3=[{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 S3({collection:e}){let n=nt(),{client:r}=q(),{registry:i}=MQ(),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=C3(e,i);return t(`div`,{className:`flex flex-col h-full`,children:e.dynamic?t(v3,{layout:o}):t(_3,{onUploadDone:a,layout:o})})}function C3(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:x3}function w3({className:e,defaultValue:r,onChange:i,isClearable:a,multiple:o}){let{t:s}=K(),{registry:c}=MQ(),[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 T3({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(R,{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(w3,{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(w3,{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 E3({isOpen:e,onClose:r}){let{t:i}=K();return n(se,{onClose:r,isOpen:e,children:[t(ue,{children:i(`store.createACollection`)}),t(T3,{onClose:r})]})}Q();function D3(){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(O3,{isDynamic:e.dynamic}),t(Qn,{href:`/collections/${e.id}`,children:e.name})]})}),t(`td`,{children:e.type?.name||`-`}),t(`td`,{children:rO(e.created_at).fromNow()}),t(`td`,{className:`text-end`,children:t(o,{variant:`destructive`,size:`sm`,onClick:()=>c(e.id),children:t(Ob,{className:`size-4`})})})]},e.id))})]}):t(j,{title:a(`store.noCollections`),buttonLabel:a(`store.newCollections`),onClick:()=>f(!0),children:a(`store.getStartedCollections`)})),t(E3,{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 O3({isDynamic:e}){let{t:n}=K(),r=n(e?`store.dynamicCollection`:`store.staticCollection`),i=t(e?Ly:s_,{className:`size-5`});return t(We,{description:r,className:`me-2`,children:i})}Q();const k3=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function A3({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:k3}),i&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${e.name}`,className:k3,onClick:t=>{t.stopPropagation(),i(`name`,e.name)},children:t(g_,{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:rO(e.updated_at).format(`YYYY-MM-DD HH:mm:ss`),children:rO(e.updated_at).fromNow()})})]},e.id))})]})}function j3({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(R,{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 M3=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 N3=dt(void 0);function P3(){return _t(N3)}function F3(){let e=P3();return{...rt(e.result),search:e}}function I3(){return P3().objects.length}Q();var L3;(function(e){e.true=`Yes`,e.false=`No`})(L3||={});function R3({isDirty:r=!1}){let{store:i}=q(),{reload:a}=MQ(),{t:s}=K(),c=nt(),[l,u]=G(!1),{search:d,isLoading:f,error:p,objects:m}=F3(),[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(R,{placeholder:s(`store.filterByName`),value:O,onChange:k}),t(we,{className:`w-60`,isClearable:!0,options:Object.values(L3),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(ix,{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(A3,{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(j3,{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 z3(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=W3(t)?t:{};a[e]=n,a=n,i.push(a)}let o=t[t.length-1];return n===void 0||n===``?(delete a[o],U3(i,t)):a[o]=n,r}function B3(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 V3(e,t){let n={...e,environment:t};return delete n.model,delete n.model_options,G3(n)?n:void 0}function H3(e,t){let n={...e,model:t};return t!==e?.model&&delete n.model_options,G3(n)?n:void 0}function U3(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 W3(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function G3(e){return Object.values(e).some(e=>e!==void 0)}Q();function K3({policy:e,section:r,onChange:i,readonly:a=!1}){let{t:o}=K(),s=(t,n)=>i(z3(e,t,n));if(r===`classification`)return n(q3,{children:[n(J3,{title:o(`intakePolicy.section.classification`),description:o(`intakePolicy.help.section.classification`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Q3,{label:o(`intakePolicy.field.mode`),description:o(`intakePolicy.help.mode`),value:e.mode,options:r6(o,[`programmatic`,`agentic`]),onChange:e=>s([`mode`],e),readonly:a}),t(Q3,{label:o(`intakePolicy.field.defaultView`),value:e.default_view,options:r6(o,[`auto`,`text`,`pdf`,`image`,`properties`]),onChange:e=>s([`default_view`],e),readonly:a})]}),t(X3,{label:o(`intakePolicy.field.identificationGuidance`),description:o(`intakePolicy.help.identificationGuidance`),value:e.identification?.guidance,onChange:e=>s([`identification`,`guidance`],e),readonly:a}),t(X3,{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(J3,{title:o(`intakePolicy.section.locate`),description:o(`intakePolicy.help.section.locate`),last:!0,children:[t(X3,{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(Q3,{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(Z3,{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(q3,{children:[n(J3,{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($3,{label:o(`intakePolicy.field.enabled`),value:e.text_conversion?.enabled,onChange:e=>s([`text_conversion`,`enabled`],e),readonly:a}),t(Q3,{label:o(`intakePolicy.field.method`),description:o(`intakePolicy.help.method`),value:e.text_conversion?.method,options:r6(o,[`auto`,`basic`,`llm`,`custom`]),onChange:e=>s([`text_conversion`,`method`],e),readonly:a}),t(Q3,{label:o(`intakePolicy.field.outputFormat`),value:e.text_conversion?.output_format,options:r6(o,[`markdown`,`text`]),onChange:e=>s([`text_conversion`,`output_format`],e),readonly:a}),t(Q3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.text_conversion?.scope,options:r6(o,[`all`,`located`]),onChange:e=>s([`text_conversion`,`scope`],e),readonly:a}),t(Z3,{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(X3,{label:o(`intakePolicy.field.instructions`),value:e.text_conversion?.instructions,onChange:e=>s([`text_conversion`,`instructions`],e),readonly:a})]}),t(J3,{title:o(`intakePolicy.section.conversionModel`),description:o(`intakePolicy.help.section.conversionModel`),children:t(n6,{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(J3,{title:o(`intakePolicy.section.customConversion`),description:o(`intakePolicy.help.section.customConversion`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(Y3,{label:o(`intakePolicy.field.interaction`),value:e.text_conversion.custom?.interaction,onChange:e=>s([`text_conversion`,`custom`,`interaction`],e),readonly:a}),t(Y3,{label:o(`intakePolicy.field.agent`),value:e.text_conversion.custom?.agent,onChange:e=>s([`text_conversion`,`custom`,`agent`],e),readonly:a})]})}),t(J3,{title:o(`intakePolicy.section.pageRanges`),description:o(`intakePolicy.help.section.pageRanges`),last:!0,children:t(t6,{value:e.text_conversion?.page_ranges,onChange:e=>s([`text_conversion`,`page_ranges`],e),readonly:a})})]});if(r===`extraction`)return n(q3,{children:[n(J3,{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($3,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.enabled,onChange:e=>s([`extraction`,`enabled`],e),readonly:a}),t(Q3,{label:o(`intakePolicy.field.source`),description:o(`intakePolicy.help.extractionSource`),value:e.extraction?.source,options:r6(o,[`auto`,`text`,`vision`,`mixed`]),onChange:e=>s([`extraction`,`source`],e),readonly:a}),t(Q3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.extraction?.scope,options:r6(o,[`all`,`located`]),onChange:e=>s([`extraction`,`scope`],e),readonly:a}),t(Z3,{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(Y3,{label:o(`intakePolicy.field.interaction`),description:o(`intakePolicy.help.extractionInteraction`),value:e.extraction?.interaction,onChange:e=>s([`extraction`,`interaction`],e),readonly:a}),t(X3,{label:o(`intakePolicy.field.instructions`),value:e.extraction?.instructions,onChange:e=>s([`extraction`,`instructions`],e),readonly:a}),t(t6,{value:e.extraction?.page_ranges,onChange:e=>s([`extraction`,`page_ranges`],e),readonly:a})]}),t(J3,{title:o(`intakePolicy.section.extractionModel`),description:o(`intakePolicy.help.section.extractionModel`),children:t(n6,{title:o(`intakePolicy.field.model`),config:e.extraction?.config,onChange:e=>s([`extraction`,`config`],e),readonly:a})}),t(J3,{title:o(`intakePolicy.section.visionBudget`),description:o(`intakePolicy.help.section.visionBudget`),last:!0,children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t(Q3,{label:o(`intakePolicy.field.defaultDetail`),description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.default_detail,options:r6(o,[`low`,`standard`,`high`]),onChange:e=>s([`extraction`,`vision`,`default_detail`],e),readonly:a}),t(e6,{description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.allowed_details,onChange:e=>s([`extraction`,`vision`,`allowed_details`],e),readonly:a}),t(Z3,{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(Z3,{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(Z3,{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})]})})]});if(r===`grounding`){let r=e.extraction?.grounding,i=r?.review;return n(q3,{children:[n(J3,{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($3,{label:o(`intakePolicy.field.enabled`),value:r?.enabled,onChange:e=>s([`extraction`,`grounding`,`enabled`],e),readonly:a}),t(Z3,{label:o(`intakePolicy.field.maxPages`),value:r?.max_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`max_pages`],e),readonly:a}),t(Z3,{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(Y3,{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($3,{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($3,{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($3,{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($3,{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($3,{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(J3,{title:o(`intakePolicy.section.models`),description:o(`intakePolicy.help.section.models`),children:[t(n6,{title:o(`intakePolicy.field.primaryModel`),config:r?.config,onChange:e=>s([`extraction`,`grounding`,`config`],e),readonly:a}),t(n6,{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(Z3,{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(Z3,{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(J3,{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($3,{label:o(`intakePolicy.field.enabled`),value:i?.enabled,onChange:e=>s([`extraction`,`grounding`,`review`,`enabled`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.forceReview`),description:o(`intakePolicy.help.forceReview`),value:i?.force,onChange:e=>s([`extraction`,`grounding`,`review`,`force`],e),readonly:a}),t(Z3,{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(Z3,{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(n6,{title:o(`intakePolicy.field.reviewModel`),config:i?.config,onChange:e=>s([`extraction`,`grounding`,`review`,`config`],e),readonly:a})]})]})}return n(q3,{children:[t(J3,{title:o(`intakePolicy.section.rendering`),description:o(`intakePolicy.help.section.rendering`),children:t(X3,{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(J3,{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($3,{label:o(`intakePolicy.field.textEmbedding`),value:e.embeddings?.text,onChange:e=>s([`embeddings`,`text`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.imageEmbedding`),value:e.embeddings?.image,onChange:e=>s([`embeddings`,`image`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.propertiesEmbedding`),value:e.embeddings?.properties,onChange:e=>s([`embeddings`,`properties`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.generateToc`),value:e.generate_toc,onChange:e=>s([`generate_toc`],e),readonly:a})]})})]})}function q3({children:e}){return t(`div`,{className:`w-full px-1 py-4`,children:e})}function J3({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(te,{description:r})]}),t(`div`,{className:`space-y-4`,children:i})]})}function Y3({label:e,value:n,onChange:r,readonly:i,description:a}){return t(L,{label:e,description:a,children:t(R,{value:n??``,onChange:e=>r(e||void 0),disabled:i})})}function X3({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 Z3({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 Q3({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 $3({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 e6({description:e,value:n,onChange:r,readonly:i}){let{t:a}=K(),o=r6(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 t6({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(B3(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(B3(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(Ob,{className:`size-4`})})})]},`${l}`)),n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...e??[],[1,1]]),disabled:i,children:[t(py,{className:`size-4`}),a(`intakePolicy.action.addRange`)]})]})})}function n6({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(w0,{selectedEnvId:r?.environment,onChange:e=>i(V3(r,e?.id)),isClearable:!0,disabled:a})}),t(L,{label:o(`intakePolicy.field.model`),children:t(D0,{envId:r?.environment,selectedModelId:r?.model,onChange:e=>i(H3(r,e?.id)),isClearable:!0,disabled:a||!r?.environment})})]})]})}function r6(e,t){return t.map(t=>({value:t,label:e(`intakePolicy.option.${t}`)}))}Q();const i6=[{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}}
1424
+ + `)||e.includes(`![`)||e.includes(`](`):!1}function Z4(e){return e?`h-full overflow-auto`:`hidden`}var Q4;(function(e){e.Text=`text`,e.Image=`image`,e.Video=`video`,e.Audio=`audio`,e.Pdf=`pdf`,e.Transcript=`transcript`})(Q4||={});function $4({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?f4(u.id,p):void 0,[h,g]=G(r),[_,v]=G(()=>m?p4(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?p4(m):!1))},[m]);let C=V(()=>{v(e=>{let t=!e;return m&&m4(m,t),t})},[m]),w=V(()=>{m&&m4(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(t3,{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(e3,{object:h,refetch:a??(()=>Promise.resolve()),handleCopyContent:E,canEditProperties:o})})]}),_?t(R4,{object:h,initialContent:h.text??``,onClose:w,onDocumentUpdated:(e,t)=>void T(e,t),sendMessageRef:y}):null]})}function e3({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(yg,{className:`size-4`})}),s&&t(U2,{permission:bn.content_write,variant:`ghost`,size:`sm`,onClick:()=>{f(!0)},title:`Edit properties`,className:`flex items-center gap-2`,children:t(ib,{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(z4,{isOpen:d,onClose:()=>{f(!1)},object:r,refetch:i})]})}function t3(e){let{client:n}=q(),r=e.object.type,i=r?.id,a=r?.default_view,{data:o}=Ye(async()=>!i||a?null:(await K2(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(n3,{...e,defaultView:s??void 0})}function n3({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?G$(e.content.type):!1,v=J4(e?.status),y=!!(e.transcript&&(m||h)),b=e.metadata?.renditions?.find(e=>e.name===vn),x=()=>{switch(s){case`text`:return Q4.Text;case`pdf`:if(g||_||b)return Q4.Pdf;break;case`image`:if(p)return Q4.Image;break;case`properties`:return Q4.Text}return m?Q4.Video:h?Q4.Audio:p?Q4.Image:Q4.Text},S=G0(e.id),[C,w]=G(x()),[T,E]=G(C===Q4.Pdf);H(()=>{C===Q4.Pdf&&E(!0)},[C]);let[D,O]=G(!1),k=y4(!(!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}=W4(e.id,e.text,r,e.revision?.root||e.id),F=(g||_)&&v&&(C===Q4.Text||C===Q4.Pdf),{progress:I,status:L,isComplete:ee}=G4(e.id,F),{pdfUrl:te,isConverting:R,error:ne,triggerConversion:re}=K4(e.id,_),ie=U(()=>[{id:`office-pdf-rendition`,target:`pdf`,canConvert:({contentType:e,extension:t})=>_||(e?G$(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===Q4.Pdf&&!ae,se=ae&&(C===Q4.Text||C===Q4.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===Q4.Image?`primary`:`ghost`,size:`sm`,title:f(`store.viewImage`),onClick:()=>w(Q4.Image),children:`Image`}),m&&t(o,{variant:C===Q4.Video?`primary`:`ghost`,size:`sm`,title:f(`store.viewVideo`),onClick:()=>w(Q4.Video),children:`Video`}),h&&t(o,{variant:C===Q4.Audio?`primary`:`ghost`,size:`sm`,title:f(`store.viewAudio`),onClick:()=>w(Q4.Audio),children:`Audio`}),y&&t(o,{variant:C===Q4.Transcript?`primary`:`ghost`,size:`sm`,title:f(`store.viewTranscript`),onClick:()=>w(Q4.Transcript),children:`Transcript`}),t(o,{variant:C===Q4.Text?`primary`:`ghost`,size:`sm`,title:f(`store.viewText`),onClick:()=>w(Q4.Text),children:`Text`}),g&&t(o,{variant:C===Q4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewPdf`),onClick:()=>w(Q4.Pdf),children:`PDF`}),_&&t(o,{variant:C===Q4.Pdf?`primary`:`ghost`,size:`sm`,title:f(`store.viewAsPdf`),onClick:()=>{w(Q4.Pdf),!b&&!te&&!R&&re()},disabled:R,children:R?t(je,{size:`sm`}):`PDF`})]}),n(`div`,{className:`flex items-center gap-1`,children:[t(o3,{object:e}),t(s3,{objectId:e.id,available:S})]})]}),C===Q4.Text&&!ae&&!D&&t(r3,{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===Q4.Pdf&&_&&(b||te)&&t(c3,{object:e,pdfRendition:b,officePdfUrl:te})]}),C===Q4.Image&&t(`div`,{className:Z4(!0),children:t(O2,{object:e})}),C===Q4.Video&&t(`div`,{className:Z4(!0),children:t(k2,{object:e})}),C===Q4.Audio&&t(`div`,{className:Z4(!0),children:t(D2,{object:e})}),y&&C===Q4.Transcript&&t(`div`,{className:Z4(!0),children:t(a3,{object:e,handleCopyContent:i})}),g&&ce&&t(`div`,{className:Z4(oe),children:t(l3,{object:e})}),_&&ce&&t(`div`,{className:Z4(oe),children:t(u3,{object:e,pdfRendition:b,officePdfUrl:te,converters:ie,officePdfConverting:R,officePdfError:ne})}),se&&t(`div`,{className:Z4(!0),children:t(d3,{progress:I,status:L})}),C===Q4.Text&&!ae&&!D&&M&&!j&&t(`div`,{className:Z4(!0),children:t(`div`,{className:`flex justify-center items-center flex-1`,children:t(je,{size:`lg`})})}),C===Q4.Text&&!ae&&!D&&(!M||j)&&t(`div`,{className:Z4(!0),children:t(i3,{object:e,text:j,isTextCropped:N,textContainerRef:le})}),D&&C===Q4.Text&&A!=null&&t(H4,{object:e,text:A,onClose:()=>O(!1),onSaved:()=>{O(!1),P(),a?.()}})]})}function r3({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}=MG({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=x4(_?.type),C=S4(_?.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(yg,{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(Og,{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(Og,{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(Og,{className:`size-4`}),`Export as DOCX`]})}),t(ae,{onClick:()=>T(_n.pdf,!1),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Og,{className:`size-4`}),`Export as PDF`]})}),t(ae,{onClick:()=>T(_n.pdf),children:n(`div`,{className:`flex items-center gap-2`,children:[t(Og,{className:`size-4`}),`Export as Branded PDF`]})})]})]}),a&&n(e,{children:[l&&c&&t(U2,{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(ib,{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(tb,{className:`size-4`})})]})]})})}const i3=gt(({object:r,text:i,isTextCropped:a,textContainerRef:o})=>{let{t:s}=K(),c=J4(r?.status),l=r.content,u=Y4(r)===`xml`||l?.type===`application/xml`||l?.type===`text/xml`,d=S4(l?.type),f=!u&&(d||X4(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(jb,{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(DX,{source:p,className:`h-full`,bodyClassName:`overflow-auto`,markdownComponents:q4()})})]}):t(`div`,{className:`px-2`,children:t(`div`,{children:c?`Extracting content...`:`No content`})})});function a3({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(yg,{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 o3({object:r}){let[i,a]=G(!1);return Y4(r)===`markdown`?n(e,{children:[t(o,{variant:`ghost`,size:`sm`,onClick:()=>a(!0),title:`Side by side view`,children:t(Yg,{className:`size-4`})}),i&&t(ve,{children:t(x2,{objectId:r.id,onClose:()=>a(!1)})})]}):null}function s3({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(Py,{className:`size-4`})}),s&&t(ve,{children:t(J0,{objectId:r,onClose:()=>c(!1)})})]}):null}function c3({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(Og,{className:`size-4`})})})}function l3({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(DX,{source:n,className:`h-full`,showHeader:!1})})}function u3({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(jb,{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(DX,{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(DX,{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(DX,{source:l,converters:a,className:`h-full`})})}function d3({progress:r,status:i}){let{t:a}=K(),o=Q$(i),s=$$(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(f3,{name:c?`Prepare Evidence`:`Analyze Page`,progress:r.pages}),c&&n(e,{children:[t(f3,{name:`Run OCR`,progress:r.images}),t(f3,{name:`Extract Grounded Data`,progress:r.tables}),t(f3,{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 f3({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 p3=Object.values(Sn),m3=Object.values(wn);function h3({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||p3),[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,m3.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(R,{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(Uy,{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`)}),m3.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 g3=[{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 _3(e,t){return(t?e.getTypeLayout(t):g3)??g3}function v3({onUploadDone:e=async()=>{},layout:n,toolbarActions:r}){let i=g1(),a=nt(),{t:o}=K(),s=E1(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(y3,{layout:n,onUpload:c,toolbarActions:r})}function y3({layout:e,onUpload:r,allowFilter:i=!0,allowSearch:a=!0,toolbarActions:o}){let{t:s}=K(),c=g1(),[l,u]=G(!1),[d,f]=G(null),{registry:p}=NQ(),{search:m,isLoading:h,error:g,objects:_,hasMore:v}=v1(),[y,b]=G(p?e||_3(p,m.query.type):g3);H(()=>{e&&b(e)},[e]);let[x,S]=G(0),[C,w]=G(0),[T,E]=G(localStorage.getItem(F1.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=_1(),F=g1(),I=()=>{j(m.search(),`Search refresh failed:`)},L=GQ(P),ee=KQ(F),te=e=>{let t=typeof e==`function`?e(D):e;O(t),ee(t)},R=(e,t)=>{let n=L.find(t=>t.name===e),r={name:e,type:n?.type,placeholder:n?.placeholder,multiple:n?.multiple};te(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(x3,{object:d,onClose:()=>f(null)}),g&&t(M,{title:s(`store.error`),children:g.message}),t(b3,{isLoading:h,refreshTrigger:x,allowFilter:i,allowSearch:a,filterGroups:L,filters:D,handleFilterChange:te,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(M$,{onFilter:R,children:t(O1,{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 b3(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(h3,{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(h3,{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(Sy,{size:16})}),t(F1,{onUpdate:m})]})]})}function x3({object:e,onClose:r}){let{store:i}=q(),a=nt(),s=$n(),{downloadFromContentSource:c}=MG({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(Pg,{className:`size-4`})}),l&&t(o,{variant:`ghost`,size:`sm`,title:`Download`,onClick:()=>c(l,jG(e)),children:t(Og,{className:`size-4`})})]}),t(C,{className:`my-2`}),t(`div`,{className:`pt-2`,children:t($4,{object:e,loadText:!0},e.id)})]}):null}const S3=[{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 C3({collection:e}){let n=nt(),{client:r}=q(),{registry:i}=NQ(),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=w3(e,i);return t(`div`,{className:`flex flex-col h-full`,children:e.dynamic?t(y3,{layout:o}):t(v3,{onUploadDone:a,layout:o})})}function w3(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:S3}function T3({className:e,defaultValue:r,onChange:i,isClearable:a,multiple:o}){let{t:s}=K(),{registry:c}=NQ(),[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 E3({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(R,{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(T3,{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(T3,{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 D3({isOpen:e,onClose:r}){let{t:i}=K();return n(se,{onClose:r,isOpen:e,children:[t(ue,{children:i(`store.createACollection`)}),t(E3,{onClose:r})]})}Q();function O3(){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(k3,{isDynamic:e.dynamic}),t(Qn,{href:`/collections/${e.id}`,children:e.name})]})}),t(`td`,{children:e.type?.name||`-`}),t(`td`,{children:rO(e.created_at).fromNow()}),t(`td`,{className:`text-end`,children:t(o,{variant:`destructive`,size:`sm`,onClick:()=>c(e.id),children:t(Ob,{className:`size-4`})})})]},e.id))})]}):t(j,{title:a(`store.noCollections`),buttonLabel:a(`store.newCollections`),onClick:()=>f(!0),children:a(`store.getStartedCollections`)})),t(D3,{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 k3({isDynamic:e}){let{t:n}=K(),r=n(e?`store.dynamicCollection`:`store.staticCollection`),i=t(e?Ly:s_,{className:`size-5`});return t(We,{description:r,className:`me-2`,children:i})}Q();const A3=`h-6 w-6 p-0 opacity-0 group-hover/field:opacity-100 text-muted hover:text-foreground transition-opacity shrink-0`;function j3({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:A3}),i&&t(o,{variant:`ghost`,size:`sm`,title:`Filter by ${e.name}`,className:A3,onClick:t=>{t.stopPropagation(),i(`name`,e.name)},children:t(g_,{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:rO(e.updated_at).format(`YYYY-MM-DD HH:mm:ss`),children:rO(e.updated_at).fromNow()})})]},e.id))})]})}function M3({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(R,{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 N3=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 P3=dt(void 0);function F3(){return _t(P3)}function I3(){let e=F3();return{...rt(e.result),search:e}}function L3(){return F3().objects.length}Q();var R3;(function(e){e.true=`Yes`,e.false=`No`})(R3||={});function z3({isDirty:r=!1}){let{store:i}=q(),{reload:a}=NQ(),{t:s}=K(),c=nt(),[l,u]=G(!1),{search:d,isLoading:f,error:p,objects:m}=I3(),[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(R,{placeholder:s(`store.filterByName`),value:O,onChange:k}),t(we,{className:`w-60`,isClearable:!0,options:Object.values(R3),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(ix,{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(j3,{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(M3,{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 B3(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=G3(t)?t:{};a[e]=n,a=n,i.push(a)}let o=t[t.length-1];return n===void 0||n===``?(delete a[o],W3(i,t)):a[o]=n,r}function V3(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 H3(e,t){let n={...e,environment:t};return delete n.model,delete n.model_options,K3(n)?n:void 0}function U3(e,t){let n={...e,model:t};return t!==e?.model&&delete n.model_options,K3(n)?n:void 0}function W3(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 G3(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function K3(e){return Object.values(e).some(e=>e!==void 0)}Q();function q3({policy:e,section:r,onChange:i,readonly:a=!1}){let{t:o}=K(),s=(t,n)=>i(B3(e,t,n));if(r===`classification`)return n(J3,{children:[n(Y3,{title:o(`intakePolicy.section.classification`),description:o(`intakePolicy.help.section.classification`),children:[n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t($3,{label:o(`intakePolicy.field.mode`),description:o(`intakePolicy.help.mode`),value:e.mode,options:i6(o,[`programmatic`,`agentic`]),onChange:e=>s([`mode`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.defaultView`),value:e.default_view,options:i6(o,[`auto`,`text`,`pdf`,`image`,`properties`]),onChange:e=>s([`default_view`],e),readonly:a})]}),t(Z3,{label:o(`intakePolicy.field.identificationGuidance`),description:o(`intakePolicy.help.identificationGuidance`),value:e.identification?.guidance,onChange:e=>s([`identification`,`guidance`],e),readonly:a}),t(Z3,{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(Y3,{title:o(`intakePolicy.section.locate`),description:o(`intakePolicy.help.section.locate`),last:!0,children:[t(Z3,{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($3,{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(Q3,{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(J3,{children:[n(Y3,{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(e6,{label:o(`intakePolicy.field.enabled`),value:e.text_conversion?.enabled,onChange:e=>s([`text_conversion`,`enabled`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.method`),description:o(`intakePolicy.help.method`),value:e.text_conversion?.method,options:i6(o,[`auto`,`basic`,`llm`,`custom`]),onChange:e=>s([`text_conversion`,`method`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.outputFormat`),value:e.text_conversion?.output_format,options:i6(o,[`markdown`,`text`]),onChange:e=>s([`text_conversion`,`output_format`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.text_conversion?.scope,options:i6(o,[`all`,`located`]),onChange:e=>s([`text_conversion`,`scope`],e),readonly:a}),t(Q3,{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(Z3,{label:o(`intakePolicy.field.instructions`),value:e.text_conversion?.instructions,onChange:e=>s([`text_conversion`,`instructions`],e),readonly:a})]}),t(Y3,{title:o(`intakePolicy.section.conversionModel`),description:o(`intakePolicy.help.section.conversionModel`),children:t(r6,{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(Y3,{title:o(`intakePolicy.section.customConversion`),description:o(`intakePolicy.help.section.customConversion`),children:n(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[t(X3,{label:o(`intakePolicy.field.interaction`),value:e.text_conversion.custom?.interaction,onChange:e=>s([`text_conversion`,`custom`,`interaction`],e),readonly:a}),t(X3,{label:o(`intakePolicy.field.agent`),value:e.text_conversion.custom?.agent,onChange:e=>s([`text_conversion`,`custom`,`agent`],e),readonly:a})]})}),t(Y3,{title:o(`intakePolicy.section.pageRanges`),description:o(`intakePolicy.help.section.pageRanges`),last:!0,children:t(n6,{value:e.text_conversion?.page_ranges,onChange:e=>s([`text_conversion`,`page_ranges`],e),readonly:a})})]});if(r===`extraction`)return n(J3,{children:[n(Y3,{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(e6,{label:o(`intakePolicy.field.enabled`),value:e.extraction?.enabled,onChange:e=>s([`extraction`,`enabled`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.source`),description:o(`intakePolicy.help.extractionSource`),value:e.extraction?.source,options:i6(o,[`auto`,`text`,`vision`,`mixed`]),onChange:e=>s([`extraction`,`source`],e),readonly:a}),t($3,{label:o(`intakePolicy.field.pageScope`),description:o(`intakePolicy.help.pageScope`),value:e.extraction?.scope,options:i6(o,[`all`,`located`]),onChange:e=>s([`extraction`,`scope`],e),readonly:a}),t(Q3,{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(X3,{label:o(`intakePolicy.field.interaction`),description:o(`intakePolicy.help.extractionInteraction`),value:e.extraction?.interaction,onChange:e=>s([`extraction`,`interaction`],e),readonly:a}),t(Z3,{label:o(`intakePolicy.field.instructions`),value:e.extraction?.instructions,onChange:e=>s([`extraction`,`instructions`],e),readonly:a}),t(n6,{value:e.extraction?.page_ranges,onChange:e=>s([`extraction`,`page_ranges`],e),readonly:a})]}),t(Y3,{title:o(`intakePolicy.section.extractionModel`),description:o(`intakePolicy.help.section.extractionModel`),children:t(r6,{title:o(`intakePolicy.field.model`),config:e.extraction?.config,onChange:e=>s([`extraction`,`config`],e),readonly:a})}),t(Y3,{title:o(`intakePolicy.section.visionBudget`),description:o(`intakePolicy.help.section.visionBudget`),last:!0,children:n(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:[t($3,{label:o(`intakePolicy.field.defaultDetail`),description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.default_detail,options:i6(o,[`low`,`standard`,`high`]),onChange:e=>s([`extraction`,`vision`,`default_detail`],e),readonly:a}),t(t6,{description:o(`intakePolicy.help.visionDetail`),value:e.extraction?.vision?.allowed_details,onChange:e=>s([`extraction`,`vision`,`allowed_details`],e),readonly:a}),t(Q3,{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(Q3,{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(Q3,{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})]})})]});if(r===`grounding`){let r=e.extraction?.grounding,i=r?.review;return n(J3,{children:[n(Y3,{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(e6,{label:o(`intakePolicy.field.enabled`),value:r?.enabled,onChange:e=>s([`extraction`,`grounding`,`enabled`],e),readonly:a}),t(Q3,{label:o(`intakePolicy.field.maxPages`),value:r?.max_pages,min:1,onChange:e=>s([`extraction`,`grounding`,`max_pages`],e),readonly:a}),t(Q3,{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(X3,{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(e6,{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(e6,{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(e6,{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(e6,{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(e6,{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(Y3,{title:o(`intakePolicy.section.models`),description:o(`intakePolicy.help.section.models`),children:[t(r6,{title:o(`intakePolicy.field.primaryModel`),config:r?.config,onChange:e=>s([`extraction`,`grounding`,`config`],e),readonly:a}),t(r6,{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(Q3,{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(Q3,{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(Y3,{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(e6,{label:o(`intakePolicy.field.enabled`),value:i?.enabled,onChange:e=>s([`extraction`,`grounding`,`review`,`enabled`],e),readonly:a}),t(e6,{label:o(`intakePolicy.field.forceReview`),description:o(`intakePolicy.help.forceReview`),value:i?.force,onChange:e=>s([`extraction`,`grounding`,`review`,`force`],e),readonly:a}),t(Q3,{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(Q3,{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(r6,{title:o(`intakePolicy.field.reviewModel`),config:i?.config,onChange:e=>s([`extraction`,`grounding`,`review`,`config`],e),readonly:a})]})]})}return n(J3,{children:[t(Y3,{title:o(`intakePolicy.section.rendering`),description:o(`intakePolicy.help.section.rendering`),children:t(Z3,{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(Y3,{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(e6,{label:o(`intakePolicy.field.textEmbedding`),value:e.embeddings?.text,onChange:e=>s([`embeddings`,`text`],e),readonly:a}),t(e6,{label:o(`intakePolicy.field.imageEmbedding`),value:e.embeddings?.image,onChange:e=>s([`embeddings`,`image`],e),readonly:a}),t(e6,{label:o(`intakePolicy.field.propertiesEmbedding`),value:e.embeddings?.properties,onChange:e=>s([`embeddings`,`properties`],e),readonly:a}),t(e6,{label:o(`intakePolicy.field.generateToc`),value:e.generate_toc,onChange:e=>s([`generate_toc`],e),readonly:a})]})})]})}function J3({children:e}){return t(`div`,{className:`w-full px-1 py-4`,children:e})}function Y3({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(te,{description:r})]}),t(`div`,{className:`space-y-4`,children:i})]})}function X3({label:e,value:n,onChange:r,readonly:i,description:a}){return t(L,{label:e,description:a,children:t(R,{value:n??``,onChange:e=>r(e||void 0),disabled:i})})}function Z3({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 Q3({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 $3({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 e6({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 t6({description:e,value:n,onChange:r,readonly:i}){let{t:a}=K(),o=i6(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 n6({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(V3(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(V3(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(Ob,{className:`size-4`})})})]},`${l}`)),n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...e??[],[1,1]]),disabled:i,children:[t(py,{className:`size-4`}),a(`intakePolicy.action.addRange`)]})]})})}function r6({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(T0,{selectedEnvId:r?.environment,onChange:e=>i(H3(r,e?.id)),isClearable:!0,disabled:a})}),t(L,{label:o(`intakePolicy.field.model`),children:t(O0,{envId:r?.environment,selectedModelId:r?.model,onChange:e=>i(U3(r,e?.id)),isClearable:!0,disabled:a||!r?.environment})})]})]})}function i6(e,t){return t.map(t=>({value:t,label:e(`intakePolicy.option.${t}`)}))}Q();const a6=[{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}}
1425
1425
 
1426
1426
  {{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}}
1427
1427
 
1428
1428
  - Vendor: {{properties.vendor_name}}
1429
1429
  - Total: {{properties.currency}} {{properties.total_amount}}
1430
- - Due: {{properties.due_date}}`,embeddings:{text:!0,image:!1,properties:!0},generate_toc:!1,default_view:`auto`}}],a6={};function o6({objectType:r,value:a,onSave:s,onIntakeUpdate:c,leadingTabs:l,readonly:u=!1}){let{store:d}=q(),{t:f}=K(),p=nt(),{theme:m}=tt(),h=W(void 0),g=U(()=>m6(),[]),[_,v]=G(!1),y=r?.intake??a,[b,x]=G(()=>p6(y)),[S,C]=G(()=>p6(y)),[T,E]=G(void 0),[D,O]=G(l?.[0]?.name??`classification`),k=b!==S,A=U(()=>{let e=h6(b,g);return e.ok?e.policy:void 0},[b,g]),j=A??y??a6,M=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}]})},N=()=>{let e=h6(D===`json`?h.current?.getValue()??b:b,g);if(!e.ok){E(e.message);return}return E(void 0),e.policy},P=()=>{let e=N();if(!e)return;let t=s??(r?e=>d.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&&(v(!0),t(e).then(t=>{let n=p6(t??e);x(n),C(n),c?.(t??e),p({status:`success`,title:f(`intakePolicy.toast.updated`),description:f(`intakePolicy.toast.saved`),duration:2e3})}).catch(e=>{p({status:`error`,title:f(`intakePolicy.toast.updateFailed`),description:Ge(e),duration:5e3})}).finally(()=>{v(!1)}))},F=()=>{let e=h6(D===`json`?h.current?.getValue()??b:b,g);E(e.ok?void 0:e.message),p({status:e.ok?`success`:`error`,title:e.ok?f(`intakePolicy.toast.valid`):f(`intakePolicy.toast.invalid`),description:e.ok?f(`intakePolicy.toast.schemaValid`):e.message,duration:3e3})},I=()=>{x(S),h.current?.setValue(S),E(void 0)},L=()=>{let e=N();if(!e)return;let t=p6(e);x(t),h.current?.setValue(t)},ee=e=>{let t=p6(e.value);x(t),h.current?.setValue(t),E(void 0),O(`classification`)},te=e=>{x(p6(e)),E(void 0)},R=e=>{if(l?.some(t=>t.name===e)){O(e);return}let t=e;if(t!==`json`&&!A){E(f(`intakePolicy.error.fixJsonBeforeForm`)),O(`json`);return}O(t)},ne=n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{children:f(`intakePolicy.title`)}),k&&t(i,{variant:`attention`,children:f(`intakePolicy.status.unsaved`)})]}),re=u?void 0:n(e,{children:[t(w,{align:`right`,trigger:n(o,{variant:`outline`,size:`md`,children:[t(Yb,{className:`size-4`}),f(`intakePolicy.action.examples`)]}),children:t(ie,{label:f(`intakePolicy.action.insertExample`),children:i6.map(e=>n(ae,{onClick:()=>ee(e),children:[t(Qg,{className:`size-4`}),n(`div`,{className:`flex flex-col`,children:[t(`span`,{children:f(`intakePolicy.example.${e.key}.label`)}),t(`span`,{className:`text-xs text-muted`,children:f(`intakePolicy.example.${e.key}.description`)})]})]},e.key))})}),D===`json`&&n(e,{children:[n(o,{variant:`outline`,size:`md`,onClick:L,children:[t(Um,{className:`size-4`}),f(`intakePolicy.action.format`)]}),n(o,{variant:`outline`,size:`md`,onClick:F,children:[t(Bh,{className:`size-4`}),f(`intakePolicy.action.validate`)]})]}),n(o,{variant:`outline`,size:`md`,onClick:I,disabled:!k,children:[t(Ty,{className:`size-4`}),f(`intakePolicy.action.revert`)]}),t(o,{isLoading:_,size:`md`,onClick:P,disabled:!k,children:f(`intakePolicy.action.save`)})]}),oe=s6(f,A??a6,u,te,b,{editorRef:h,beforeMount:M,onChange:e=>{x(e),E(void 0)},theme:m},e=>t(me,{title:ne,className:`bg-background! h-full`,action:re,children:n(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[T&&t(`div`,{className:`rounded-sm border border-destructive bg-mixer-destructive/10 px-3 py-2 text-sm whitespace-pre-line text-destructive`,children:T}),e]})}));return n(`div`,{className:`flex h-full min-h-0 w-full flex-col gap-3`,children:[t(c6,{policy:j}),n(ze,{tabs:l?[...l,...oe]:oe,current:D,onTabChange:R,updateHash:!1,fullHeight:!0,className:`px-0 min-h-0 flex-1 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 ps-4`})]})]})}function s6(e,r,i,a,o,s,c){let l=(e,n)=>({name:e,label:n,content:c(t(K3,{policy:r,section:e,onChange:a,readonly:i}))});return[l(`classification`,e(`intakePolicy.tab.classification`)),l(`conversion`,e(`intakePolicy.tab.conversion`)),l(`extraction`,e(`intakePolicy.tab.extraction`)),l(`grounding`,e(`intakePolicy.tab.grounding`)),l(`output`,e(`intakePolicy.tab.output`)),{name:`json`,label:e(`intakePolicy.tab.json`),content:c(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(l6,{})]}))}]}function c6({policy:e}){let{t:r}=K(),a=e.extraction?.grounding,o=[[r(`intakePolicy.summary.mode`),f6(r,e.mode)],[r(`intakePolicy.summary.conversion`),d6(r,e.text_conversion?.enabled)],[r(`intakePolicy.summary.method`),f6(r,e.text_conversion?.method)],[r(`intakePolicy.summary.source`),f6(r,e.extraction?.source)],[r(`intakePolicy.summary.extraction`),d6(r,e.extraction?.enabled)],[r(`intakePolicy.summary.grounding`),d6(r,a?.enabled)],[r(`intakePolicy.summary.defaultView`),f6(r,e.default_view)],[r(`intakePolicy.summary.toc`),d6(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 l6(){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(u6,{label:`identification`,text:e(`intakePolicy.help.identification`)}),t(u6,{label:`text_conversion`,text:e(`intakePolicy.help.textConversion`)}),t(u6,{label:`extraction.source`,text:e(`intakePolicy.help.extractionSource`)}),t(u6,{label:`extraction.grounding`,text:e(`intakePolicy.help.grounding`)}),t(u6,{label:`extraction.grounding.review`,text:e(`intakePolicy.help.review`)}),t(u6,{label:`rendering_template`,text:e(`intakePolicy.help.renderingTemplate`)}),t(u6,{label:`embeddings`,text:e(`intakePolicy.help.embeddings`)}),t(u6,{label:`default_view`,text:e(`intakePolicy.help.defaultView`)})]})]})}function u6({label:e,text:r}){return n(`div`,{children:[t(`div`,{className:`font-medium text-foreground`,children:e}),t(`div`,{children:r})]})}function d6(e,t){return e(t===!0?`intakePolicy.option.enabled`:t===!1?`intakePolicy.option.disabled`:`intakePolicy.option.inherit`)}function f6(e,t){return e(t?`intakePolicy.option.${t}`:`intakePolicy.option.inherit`)}function p6(e){return JSON.stringify(e??a6,null,2)}function m6(){let e=new tr({strict:!1,allErrors:!0});return sr(e),e.compile(pn)}function h6(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:g6(t.errors)}}function g6(e){return e?.length?e.map(e=>`${e.instancePath||`/`} ${e.message??`is invalid`}`).join(`
1431
- `):`The intake policy does not match the schema.`}function _6({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(()=>v6(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=y6(e);b6(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 v6(e){return e?JSON.stringify(e,null,2):``}function y6(e){if(e?.trim())return JSON.parse(e.trim())}const b6=e=>{try{new nr({strict:!1}).compile(e)}catch(e){throw Error(`Invalid JSON Schema definition: ${Ge(e)}`,{cause:e})}};Q();function x6({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}=MQ(),[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-muted 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(Uh,{className:`size-4 me-1`}),l(`store.automaticTypeDetection`),t(We,{description:l(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(L_,{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 S6({children:e,limit:n,name:r,chunkable:i}){let{store:a}=q(),o=U(()=>{let e=new M3(a,n);return e.query.name=r,e.query.chunkable=i,e},[i,n,r,a]);return t(N3.Provider,{value:o,children:e})}function C6({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(()=>w6(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 w6(e){return e?JSON.stringify(e,null,2):`[
1430
+ - Due: {{properties.due_date}}`,embeddings:{text:!0,image:!1,properties:!0},generate_toc:!1,default_view:`auto`}}],o6={};function s6({objectType:r,value:a,onSave:s,onIntakeUpdate:c,leadingTabs:l,readonly:u=!1}){let{store:d}=q(),{t:f}=K(),p=nt(),{theme:m}=tt(),h=W(void 0),g=U(()=>h6(),[]),[_,v]=G(!1),y=r?.intake??a,[b,x]=G(()=>m6(y)),[S,C]=G(()=>m6(y)),[T,E]=G(void 0),[D,O]=G(l?.[0]?.name??`classification`),k=b!==S,A=U(()=>{let e=g6(b,g);return e.ok?e.policy:void 0},[b,g]),j=A??y??o6,M=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}]})},N=()=>{let e=g6(D===`json`?h.current?.getValue()??b:b,g);if(!e.ok){E(e.message);return}return E(void 0),e.policy},P=()=>{let e=N();if(!e)return;let t=s??(r?e=>d.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&&(v(!0),t(e).then(t=>{let n=m6(t??e);x(n),C(n),c?.(t??e),p({status:`success`,title:f(`intakePolicy.toast.updated`),description:f(`intakePolicy.toast.saved`),duration:2e3})}).catch(e=>{p({status:`error`,title:f(`intakePolicy.toast.updateFailed`),description:Ge(e),duration:5e3})}).finally(()=>{v(!1)}))},F=()=>{let e=g6(D===`json`?h.current?.getValue()??b:b,g);E(e.ok?void 0:e.message),p({status:e.ok?`success`:`error`,title:e.ok?f(`intakePolicy.toast.valid`):f(`intakePolicy.toast.invalid`),description:e.ok?f(`intakePolicy.toast.schemaValid`):e.message,duration:3e3})},I=()=>{x(S),h.current?.setValue(S),E(void 0)},L=()=>{let e=N();if(!e)return;let t=m6(e);x(t),h.current?.setValue(t)},ee=e=>{let t=m6(e.value);x(t),h.current?.setValue(t),E(void 0),O(`classification`)},te=e=>{x(m6(e)),E(void 0)},R=e=>{if(l?.some(t=>t.name===e)){O(e);return}let t=e;if(t!==`json`&&!A){E(f(`intakePolicy.error.fixJsonBeforeForm`)),O(`json`);return}O(t)},ne=n(`div`,{className:`flex items-center gap-2`,children:[t(`div`,{children:f(`intakePolicy.title`)}),k&&t(i,{variant:`attention`,children:f(`intakePolicy.status.unsaved`)})]}),re=u?void 0:n(e,{children:[t(w,{align:`right`,trigger:n(o,{variant:`outline`,size:`md`,children:[t(Yb,{className:`size-4`}),f(`intakePolicy.action.examples`)]}),children:t(ie,{label:f(`intakePolicy.action.insertExample`),children:a6.map(e=>n(ae,{onClick:()=>ee(e),children:[t(Qg,{className:`size-4`}),n(`div`,{className:`flex flex-col`,children:[t(`span`,{children:f(`intakePolicy.example.${e.key}.label`)}),t(`span`,{className:`text-xs text-muted`,children:f(`intakePolicy.example.${e.key}.description`)})]})]},e.key))})}),D===`json`&&n(e,{children:[n(o,{variant:`outline`,size:`md`,onClick:L,children:[t(Um,{className:`size-4`}),f(`intakePolicy.action.format`)]}),n(o,{variant:`outline`,size:`md`,onClick:F,children:[t(Bh,{className:`size-4`}),f(`intakePolicy.action.validate`)]})]}),n(o,{variant:`outline`,size:`md`,onClick:I,disabled:!k,children:[t(Ty,{className:`size-4`}),f(`intakePolicy.action.revert`)]}),t(o,{isLoading:_,size:`md`,onClick:P,disabled:!k,children:f(`intakePolicy.action.save`)})]}),oe=c6(f,A??o6,u,te,b,{editorRef:h,beforeMount:M,onChange:e=>{x(e),E(void 0)},theme:m},e=>t(me,{title:ne,className:`bg-background! h-full`,action:re,children:n(`div`,{className:`flex h-full min-h-0 flex-col gap-3`,children:[T&&t(`div`,{className:`rounded-sm border border-destructive bg-mixer-destructive/10 px-3 py-2 text-sm whitespace-pre-line text-destructive`,children:T}),e]})}));return n(`div`,{className:`flex h-full min-h-0 w-full flex-col gap-3`,children:[t(l6,{policy:j}),n(ze,{tabs:l?[...l,...oe]:oe,current:D,onTabChange:R,updateHash:!1,fullHeight:!0,className:`px-0 min-h-0 flex-1 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 ps-4`})]})]})}function c6(e,r,i,a,o,s,c){let l=(e,n)=>({name:e,label:n,content:c(t(q3,{policy:r,section:e,onChange:a,readonly:i}))});return[l(`classification`,e(`intakePolicy.tab.classification`)),l(`conversion`,e(`intakePolicy.tab.conversion`)),l(`extraction`,e(`intakePolicy.tab.extraction`)),l(`grounding`,e(`intakePolicy.tab.grounding`)),l(`output`,e(`intakePolicy.tab.output`)),{name:`json`,label:e(`intakePolicy.tab.json`),content:c(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(u6,{})]}))}]}function l6({policy:e}){let{t:r}=K(),a=e.extraction?.grounding,o=[[r(`intakePolicy.summary.mode`),p6(r,e.mode)],[r(`intakePolicy.summary.conversion`),f6(r,e.text_conversion?.enabled)],[r(`intakePolicy.summary.method`),p6(r,e.text_conversion?.method)],[r(`intakePolicy.summary.source`),p6(r,e.extraction?.source)],[r(`intakePolicy.summary.extraction`),f6(r,e.extraction?.enabled)],[r(`intakePolicy.summary.grounding`),f6(r,a?.enabled)],[r(`intakePolicy.summary.defaultView`),p6(r,e.default_view)],[r(`intakePolicy.summary.toc`),f6(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 u6(){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(d6,{label:`identification`,text:e(`intakePolicy.help.identification`)}),t(d6,{label:`text_conversion`,text:e(`intakePolicy.help.textConversion`)}),t(d6,{label:`extraction.source`,text:e(`intakePolicy.help.extractionSource`)}),t(d6,{label:`extraction.grounding`,text:e(`intakePolicy.help.grounding`)}),t(d6,{label:`extraction.grounding.review`,text:e(`intakePolicy.help.review`)}),t(d6,{label:`rendering_template`,text:e(`intakePolicy.help.renderingTemplate`)}),t(d6,{label:`embeddings`,text:e(`intakePolicy.help.embeddings`)}),t(d6,{label:`default_view`,text:e(`intakePolicy.help.defaultView`)})]})]})}function d6({label:e,text:r}){return n(`div`,{children:[t(`div`,{className:`font-medium text-foreground`,children:e}),t(`div`,{children:r})]})}function f6(e,t){return e(t===!0?`intakePolicy.option.enabled`:t===!1?`intakePolicy.option.disabled`:`intakePolicy.option.inherit`)}function p6(e,t){return e(t?`intakePolicy.option.${t}`:`intakePolicy.option.inherit`)}function m6(e){return JSON.stringify(e??o6,null,2)}function h6(){let e=new tr({strict:!1,allErrors:!0});return sr(e),e.compile(pn)}function g6(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:_6(t.errors)}}function _6(e){return e?.length?e.map(e=>`${e.instancePath||`/`} ${e.message??`is invalid`}`).join(`
1431
+ `):`The intake policy does not match the schema.`}function v6({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(()=>y6(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=b6(e);x6(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 y6(e){return e?JSON.stringify(e,null,2):``}function b6(e){if(e?.trim())return JSON.parse(e.trim())}const x6=e=>{try{new nr({strict:!1}).compile(e)}catch(e){throw Error(`Invalid JSON Schema definition: ${Ge(e)}`,{cause:e})}};Q();function S6({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}=NQ(),[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-muted 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(Uh,{className:`size-4 me-1`}),l(`store.automaticTypeDetection`),t(We,{description:l(`store.automaticTypeDetectionDescription`),placement:`top`,size:`xs`,children:t(L_,{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 C6({children:e,limit:n,name:r,chunkable:i}){let{store:a}=q(),o=U(()=>{let e=new N3(a,n);return e.query.name=r,e.query.chunkable=i,e},[i,n,r,a]);return t(P3.Provider,{value:o,children:e})}function w6({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(()=>T6(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 T6(e){return e?JSON.stringify(e,null,2):`[
1432
1432
 
1433
- ]`}function T6({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 E6({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 D6(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O6({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(m1),[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(()=>w6(a.table_layout),[a.table_layout]),x=()=>{let e;try{let t=g.query?JSON.parse(g.query):void 0;if(t!==void 0&&!D6(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(_Q,{userRef:a.created_by,showTitle:!0}),n(`span`,{children:[`at `,rO(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(_Q,{userRef:a.updated_by,showTitle:!0}),n(`span`,{children:[`at `,rO(a.updated_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]})]}),t(L,{label:s(`type.name`),required:!0,children:t(R,{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(w3,{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(w3,{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(R,{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(k6,{typeId:c,collection:a}),!a.dynamic&&n(e,{children:[t(E6,{collection:a}),t(T6,{collection:a})]})]})}function k6({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 A6({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(ix,{className:`h-4 w-4`})}):t(Oh,{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 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(sh,{className:`ms-2 h-4 w-4 shrink-0`})]},e.id)})]})]})})]})}function j6({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(I1,{onChange:r})})]})}Q();const M6=/store:([a-f0-9]+)/;function N6({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(M6);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-destructive hover:bg-muted`,children:t(ix,{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-muted`,children:t(Oh,{className:`size-5`})})}),t(j6,{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 font-semibold text-sm text-muted dark:text-foreground`,children:typeof u.properties?.title==`string`?u.properties.title:u.name})]})}Q();function P6({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(`
1433
+ ]`}function E6({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 D6({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 O6(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function k6({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(h1),[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(()=>T6(a.table_layout),[a.table_layout]),x=()=>{let e;try{let t=g.query?JSON.parse(g.query):void 0;if(t!==void 0&&!O6(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(vQ,{userRef:a.created_by,showTitle:!0}),n(`span`,{children:[`at `,rO(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(vQ,{userRef:a.updated_by,showTitle:!0}),n(`span`,{children:[`at `,rO(a.updated_at).format(`YYYY-MM-DD HH:mm:ss`)]})]})]})]}),t(L,{label:s(`type.name`),required:!0,children:t(R,{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(T3,{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(T3,{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(R,{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(A6,{typeId:c,collection:a}),!a.dynamic&&n(e,{children:[t(D6,{collection:a}),t(E6,{collection:a})]})]})}function A6({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 j6({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(ix,{className:`h-4 w-4`})}):t(Oh,{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 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(sh,{className:`ms-2 h-4 w-4 shrink-0`})]},e.id)})]})]})})]})}function M6({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(L1,{onChange:r})})]})}Q();const N6=/store:([a-f0-9]+)/;function P6({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(N6);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-destructive hover:bg-muted`,children:t(ix,{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-muted`,children:t(Oh,{className:`size-5`})})}),t(M6,{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 font-semibold text-sm text-muted dark:text-foreground`,children:typeof u.properties?.title==`string`?u.properties.title:u.name})]})}Q();function F6({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(`
1434
1434
  #`)||h.includes(`
1435
- *`)),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-muted 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-border 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(Qg,{className:`h-5 w-5 text-info me-2`}),t(`h2`,{className:`text-lg font-semibold text-foreground 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-info hover:text-info`,children:[t(gv,{className:`h-4 w-4`}),t(`span`,{children:x(`store.fullView`)})]}),t(o,{variant:`ghost`,size:`sm`,onClick:i,className:`flex items-center text-muted hover:text-foreground dark:text-foreground`,children:t(ix,{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-info mb-2`}),t(`p`,{className:`text-muted`,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-primary text-info`:`border-transparent text-muted hover:text-foreground`}`,onClick:()=>b(`preview`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(U_,{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-primary text-info`:`border-transparent text-muted hover:text-foreground`}`,onClick:()=>b(`properties`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(L_,{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-info`})}):h?t(`div`,{className:`shadow rounded-md p-4 border border-border bg-white dark:bg-muted`,children:E?t(`div`,{className:`prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-muted prose-pre:my-2 prose-headings:text-info dark:prose-invert`,children:t(Nt,{children:h})}):t(`pre`,{className:`text-wrap whitespace-pre-wrap dark:text-foreground`,children:h})}):null,D&&t(`div`,{className:`mt-4`,children:_?t(`div`,{className:`border border-border rounded-md p-2 bg-white dark:bg-muted`,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-info`})})}),O&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-border rounded-md p-4 bg-muted`,children:[t(Qg,{className:`h-16 w-16 text-info mb-4`}),t(`p`,{className:`text-muted text-center mb-4`,children:x(`store.pdfPreviewFullView`)}),t(o,{onClick:T,className:`bg-primary hover:bg-primary text-white`,children:x(`store.openFullDocumentView`)})]}),!D&&!h&&!O&&!p&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-border rounded-md p-4 bg-muted`,children:[t(Qg,{className:`h-16 w-16 text-foreground dark:text-muted mb-4`}),t(`p`,{className:`text-muted 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-border bg-white dark:bg-muted`,children:t(jt,{value:l.properties})}):n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-border rounded-md p-4 bg-muted`,children:[t(L_,{className:`h-16 w-16 text-foreground dark:text-muted mb-4`}),t(`p`,{className:`text-muted text-center`,children:x(`store.noPropertiesAvailable`)})]}),n(`div`,{className:`mt-4`,children:[t(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:x(`store.documentInformation`)}),t(`div`,{className:`shadow rounded-md p-4 border border-border bg-white dark:bg-muted`,children:n(`div`,{className:`grid grid-cols-2 gap-y-2 gap-x-4 text-sm`,children:[t(`div`,{className:`text-muted`,children:x(`store.id`)}),t(`div`,{className:`font-medium dark:text-foreground`,children:l.id}),t(`div`,{className:`text-muted`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-foreground`,children:l.type?.name||x(`store.unknown`)}),t(`div`,{className:`text-muted`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-foreground`,children:l.content?.type||x(`store.na`)}),t(`div`,{className:`text-muted`,children:x(`store.size`)}),t(`div`,{className:`font-medium`,children:l.content&&`size`in l.content?F6(l.content.size):x(`store.unknown`)}),t(`div`,{className:`text-muted`,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-muted`,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-muted dark:border-border`,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-info border-primary hover:bg-info`,children:[t(Og,{className:`h-4 w-4 me-2`}),x(`pdf.download`)]})}),n(o,{onClick:T,className:`bg-primary hover:bg-primary text-white`,children:[x(`store.openFullDocument`),t(gh,{className:`h-4 w-4 ms-2 cn-rtl-flip`})]})]})]}):null}function F6(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 I6;(function(e){e.CSV=`CSV`,e.JSON=`JSON`})(I6||={});function L6({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(R6,{onClose:i,allowExportAll:a}),e&&t(z6,{})]})]})}function R6({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(I6),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 z6(){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 B6=dt(void 0);function V6(){let e=_t(B6);if(!e)throw Error(`You cannot use useActionContext outside an ActionProvider`);return e}function H6(e,t){let n=V6();return H(()=>n.registerCallback(e,t),[n,e,t]),n}function U6({action:e,objectIds:n}){let[r,i]=G(!1),a=V(()=>(n.length>0&&i(!0),Promise.resolve(!0)),[n]);return H6(e.id,a),r&&t(ve,{children:t(K6,{objectIds:n,isOpen:r,onClose:()=>{i(!1)}})})}const W6=Xt.getFixedT(null,Yt),G6={id:`addToCollection`,name:W6(`store.actions.addToCollection`),description:W6(`store.actions.addToCollectionDesc`),confirm:!1,component:U6};function K6({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(q6,{onClose:r,objectIds:i})})]})}function q6({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(A6,{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(T3,{onClose:e,onAddToCollection:e=>u({collectionId:e}),redirect:!1})})}];return n(ze,{defaultValue:`select`,tabs:d,fullWidth:!0,children:[t(Be,{}),t(Ve,{})]})}function J6({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 H6(e.id,u),n(`div`,{children:[i,t(x6,{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 Y6=Xt.getFixedT(null,Yt),X6={id:`changeType`,name:Y6(`store.actions.changeContentType`),description:Y6(`store.actions.changeContentTypeDesc`),confirm:!1,component:J6};function Z6({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=H6(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 Q6({action:r,objectIds:i,children:a}){let{t:o}=K(),s=V6(),c=nt(),{client:l}=q(),u=h1(),d=$n(),[f,p]=G(!1),m=i?.length??0,h=s.params?.type?.name??`object`,g=V(()=>(p(!0),Promise.resolve(!0)),[]);H6(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 $6=Xt.getFixedT(null,Yt),e8={id:`delete`,name:$6(`store.actions.delete`),description:$6(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:$6(`store.actions.confirmDeleteAll`),component:Q6,destructive:!0},t8={id:`deleteFromCollections`,name:$6(`store.actions.deleteObjects`),description:$6(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:$6(`store.actions.confirmDeleteSelected`),component:Q6,destructive:!0};function n8({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=H6(e.id,u);return t(L6,{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 r8=Xt.getFixedT(null,Yt),i8={id:`exportProperties`,name:r8(`store.actions.exportProperties`),description:r8(`store.actions.exportAllObjectProperties`),confirm:!1,component:n8};function a8({action:e,objectIds:n,collectionId:r}){let{t:i}=K(),a=V6(),o=nt(),{client:s}=q(),c=h1(),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(Z6,{action:e,callback:l})}const o8=Xt.getFixedT(null,Yt),s8={id:`removeFromCollection`,name:o8(`store.actions.removeFromCollection`),description:o8(`store.actions.removeFromCollectionDesc`),confirm:!0,confirmationText:o8(`store.actions.confirmRemoveFromCollection`),component:a8,destructive:!0};var c8=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 l8=[i8,X6,G6,e8,s8,t8];function u8({children:e,type:r}){let i=D$(),a=nt(),{client:o}=q(),s=h1(),c=U(()=>{let e=new c8({selection:i,toast:a,client:o,search:s,type:r});return e.allActions=l8,e},[o,s,i,a,r]);return c&&n(B6.Provider,{value:c,children:[t(d8,{}),e]})}function d8(){let e=V6(),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 f8(){let{t:r}=K(),i=D$(),[a,s]=G(!1);return i?.hasSelection()?n(e,{children:[t(o,{onClick:()=>s(!0),children:r(`store.actions.startWorkflow`)}),a&&t(p8,{objectIds:i.getObjectIds(),onClose:()=>s(!1)})]}):null}function p8({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 m8({type:e,allowMutations:r=!0,allowDelete:i=!0,allowWorkflowRun:a=!1}){let s=D$(),c=s.size(),l=c>1?`s`:``,u=s?.hasSelection(),d=s?.isSingleSelection();return t(u8,{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(ix,{className:`size-4`})})]}),a&&t(f8,{}),t(_8,{selection:s,allowMutations:r,allowDelete:i,children:e=>e.length>0?t(o,{variant:`ghost`,title:`More action`,size:`sm`,children:t(jg,{size:16})}):null})]})})}function h8({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(w1,{collectionId:r??``,isOpen:l,onClose:()=>{u(!1),c([])},files:s,title:`Upload Files`,onUploadComplete:e=>{e?.success&&c([])},allowFolders:i})]})}function g8(e){return{label:e.name,className:it(`flex-1 px-2 py-2 hover:bg-muted whitespace-nowrap`,e.destructive?`text-destructive`:``)}}function _8({selection:e,children:r,allowMutations:i=!0,allowDelete:a=!0}){let o=V6(),s=e=>{o.run(e.id)},c=y8(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(v8,{executeAction:s,actions:c})})]}):null}function v8({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:g8,onChange:t=>{e(t)},noCheck:!0})})})}function y8(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):[i8]}function b8({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-primary`,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-foreground group-hover:text-foreground`,children:e.name??`Deleted User`}),t(`p`,{className:`text-xs font-medium text-muted dark:text-foreground group-hover:text-foreground`,children:e.email??`Deleted User`})]})]})}Q();const x8=dt(void 0);function S8(){return _t(x8)}function C8(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 w8(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 T8({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(C8(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=>{w8(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(x8.Provider,{value:k,children:[e,t(L6,{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 E8({selection:r,page:i,showSelectPage:a=!1}){let{t:s}=K(),c=S8(),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)&&C8(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(ix,{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(Og,{className:`size-4`}),e.handler===`delete`&&t(Ob,{className:`size-4`}),e.label]},e.id))]})}function D8({hit:e}){let{t:r}=K(),i=S8(),a=i?.actions.filter(t=>(t.placement??`selection`)===`row`&&C8(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(jg,{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 O8(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 k8({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(O8(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(w1,{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 A8(e,t,n,r){return n?r===!1?[t]:e.includes(t)?e:[...e,t]:e.filter(e=>e!==t)}function j8({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 M8({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(A8(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(ix,{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(R,{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(Ly,{"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(gh,{"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(ix,{"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(j8,{node:e}),e.expandable&&t(gh,{"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(j8,{node:e})})]},e.id)})}),r.nodes.length===0&&t(`p`,{className:`text-sm text-muted`,children:c(`filter.noAvailableFilters`)})]})}const N8=`display`,P8=`sort`,F8=`offset`;function I8(e){if(e===null||e.trim()===``)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0}function L8(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 R8(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 z8(e){let t=new URLSearchParams(e.startsWith(`?`)?e.slice(1):e),n=t.get(`q`)?.trim(),r=t.get(N8)?.trim(),i=t.get(P8)?.trim(),a=I8(t.get(F8)),o=L8(t,`t.`),s=L8(t,`n.`),c=R8(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 B8(e){for(let t of[...e.keys()])(t===`q`||t===N8||t===P8||t===F8||t.startsWith(`t.`)||t.startsWith(`nq.`)||t.startsWith(`n.`))&&e.delete(t)}function V8(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 H8(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 U8(e,t=``){let n=new URLSearchParams(t.startsWith(`?`)?t.slice(1):t);B8(n),e.query?.trim()&&n.set(`q`,e.query.trim()),e.display&&n.set(N8,e.display),e.sort&&n.set(P8,e.sort),e.offset&&e.offset>0&&n.set(F8,String(e.offset)),V8(n,`t.`,e.key_terms),V8(n,`n.`,e.navigation),H8(n,`nq.`,e.navigation_queries);let r=n.toString();return r?`?${r}`:``}function W8(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 G8(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 K8(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=W8(t),a=G8(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 q8(e,t,n){return t.sort??e.sort??(e.query?.trim()?void 0:n)}function J8(e){if(typeof window>`u`)return;let t=U8(e,window.location.search);window.history.replaceState(window.history.state||{},``,`${window.location.pathname}${t}`)}Q();function Y8(e,t){return!t||t===`.`?e:t.split(`.`).reduce((e,t)=>{if(e&&typeof e==`object`&&!Array.isArray(e))return e[t]},e)}function X8(e,t){return t===`score`?e.score:t.startsWith(`annotation.`)?Y8(e.annotation,t.slice(11)):t.startsWith(`document.`)?Y8(e.document,t.slice(9)):Y8(e.document,t)}const Z8=dt(void 0);function Q8(e){if(e!=null&&e!==``)return Array.isArray(e)?e.map(Q8).filter(Boolean).join(`, `):typeof e==`object`?JSON.stringify(e):String(e)}function $8(e,t,n){let r=X8(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 Q8(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):Q8(r)??i}return Q8(r)??i}function e5({hit:e,field:n,className:r}){let a=$8(e,n,_t(Z8));return a?n.format===`badge`||n.format===`content_type`?t(i,{className:r,children:a}):t(`span`,{className:r,children:a}):null}function t5({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(Pg,{className:`size-4`})})}):n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(e),children:[t(Pg,{className:`size-4`}),a(`agent.openDocument`)]}):null}function n5(e,t){if(t.source!==`property`||!t.field)return;let n=Q8(X8(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 r5=new WeakMap,i5=[2e3,4e3,8e3];function a5(e){let t=r5.get(e);if(t)return t;let n=new Map;return r5.set(e,n),n}function o5(e,t,n){let r=a5(e),i=r.get(t);if(i)return i;let a=n().finally(()=>{r.delete(t)});return r.set(t,a),a}function s5({hit:e,media:n,resolveMedia:r,className:i}){let a=n?n5(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=>{o5(r,u,async()=>r(d.current,f.current)).then(r=>{if(!e)return;if(r){s(r);return}let a=i5[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`?P_:Qg,{className:`size-10 text-muted`})})}function c5({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 l5({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 u5({hit:e,fields:n}){return n?.length?t(`div`,{className:`flex flex-wrap gap-1`,children:n.map(n=>t(e5,{hit:e,field:n},`${n.field}-${n.label??``}`))}):null}function d5({hit:e,fields:r}){let i=_t(Z8);return r?.length?t(`dl`,{className:`space-y-1 text-sm`,children:r.map(r=>{let a=$8(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 f5({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(l5,{hit:s,page:r,selection:o})}),e.media&&t(s5,{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(e5,{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(e5,{hit:s,field:e},e.field))})]}),e.description&&t(`p`,{className:`line-clamp-3 text-sm text-muted`,children:t(e5,{hit:s,field:e.description})}),t(u5,{hit:s,fields:e.badges}),t(c5,{hit:s})]}),n(`div`,{className:`shrink-0 self-center`,children:[t(t5,{hit:s,onOpenHit:i,compact:!0}),t(D8,{hit:s})]})]},s.id))})}function p5({display:e,hits:r,isLoading:i,onOpenHit:a,sortOptions:o,currentSort:s,onSortChange:c,selection:l}){let{t:u}=K(),d=S8()?.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(yh,{className:`size-3`,"aria-hidden":`true`}):e===`descending`?t(uh,{className:`size-3`,"aria-hidden":`true`}):t(Oh,{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(l5,{hit:i,page:r,selection:l})}),e.columns.map(e=>t(`td`,{style:e.width?{width:e.width}:void 0,children:t(e5,{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(t5,{hit:i,onOpenHit:a,compact:!0}),t(D8,{hit:i})]})})]},i.id))})]})})}const m5={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 h5({hit:e,configuration:r,onOpenHit:i,resolveMedia:a,selection:o,page:p}){let m=S8()?.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(l5,{hit:e,page:p,selection:o})}),r.media&&t(s5,{hit:e,media:r.media,resolveMedia:a,className:`h-40 w-full border-b`}),n(d,{className:`gap-2 p-4`,children:[t(u5,{hit:e,fields:r.badges}),t(f,{className:`truncate text-base`,children:t(e5,{hit:e,field:r.title})}),r.description&&t(l,{className:`line-clamp-3`,children:t(e5,{hit:e,field:r.description})})]}),n(c,{className:`flex-1 p-4 pt-0`,children:[t(d5,{hit:e,fields:r.fields}),t(c5,{hit:e})]}),(i||m)&&n(u,{className:`justify-end p-4 pt-0`,children:[t(t5,{hit:e,onOpenHit:i}),t(D8,{hit:e})]})]})}function g5({display:e,hits:n,onOpenHit:r,resolveMedia:i,selection:a}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${m5[e.columns??3]}`,children:n.map(o=>t(h5,{hit:o,configuration:e,onOpenHit:r,resolveMedia:i,selection:a,page:n},o.id))})}function _5({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${m5[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(l5,{hit:l,page:r,selection:o})}),t(s5,{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(e5,{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(e5,{hit:l,field:e})},e.field))}),n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(t5,{hit:l,onOpenHit:i}),t(D8,{hit:l})]})]})]},l.id))})}function v5({display:e,hits:r,onOpenHit:a,resolveMedia:o,selection:s}){let c=new Map;for(let t of r){let n=Q8(X8(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(h5,{hit:n,configuration:e.card,onOpenHit:a,resolveMedia:o,selection:s,page:r},n.id))})]},l.value)})})}function y5(e,n,r,i,a,o,s,c,l){return e.type===`table`?t(p5,{display:e,hits:n,isLoading:r,onOpenHit:i,sortOptions:o,currentSort:s,onSortChange:c,selection:l}):e.type===`cards`?t(g5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`gallery`?t(_5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`board`?t(v5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):t(f5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l})}function b5({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(Z8.Provider,{value:d,children:y5(e,i.hits,a,s,c,n.results?.sort_options,q8(r,i,n.results?.default_sort),o,l)})}Q();function x5(e,t){return t?`text`:e===`number`?`number`:e===`date`?`date`:`text`}function S5(e){let[t=``,n=``]=(e[0]??``).split(`..`,2);return[t,n]}function C5(e,t){return e||t?[`${e}..${t}`]:[]}function w5(e,t){return t?e.join(`, `):e[0]??``}function T5(e,t){return t?e.split(`,`).map(e=>e.trim()).filter(Boolean):e.trim()?[e.trim()]:[]}function E5({term:e,values:n,isLoading:r,onChange:i}){let a=W(!1),o=W(void 0),[s,c]=G(()=>w5(n,e.multiple)),l=w5(n,e.multiple);return H(()=>{a.current&&o.current===l||c(l),o.current=void 0},[l]),t(L,{label:e.label,children:t(R,{type:x5(e.type,e.multiple),name:`view-key-term-${e.id}`,autoComplete:`off`,value:s,onFocus:()=>{a.current=!0},onBlur:()=>{a.current=!1;let t=T5(s,e.multiple);c(w5(t,e.multiple))},onChange:t=>{c(t);let n=T5(t,e.multiple);o.current=w5(n,e.multiple),i(n)},placeholder:e.label,disabled:r})})}function D5({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(R,{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(Ly,{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(E5,{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]=S5(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(R,{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,C5(t.trim(),o)),placeholder:u(`view.from`),disabled:a}),t(R,{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,C5(r,t.trim())),placeholder:u(`view.to`),disabled:a})]})]},e.id)})})]})]})]})}Q();const O5={id:`default`,label:`Results`,type:`list`,title:{field:`name`},subtitle:[{field:`type.name`,format:`content_type`},{field:`location`,format:`location`}],description:{field:`description`}};function k5(e){return!e||typeof window>`u`?{}:z8(window.location.search)}function A5(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function j5(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 M5(e){let{client:n}=q(),r=_t(R2),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(P5,{...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 N5({execute:e,...n}){return e?t(P5,{...n,execute:e},n.viewId):t(M5,{...n},n.viewId)}function P5({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(()=>k5(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&&J8(e),E(!0),O(void 0),h.current(e).then(t=>{if(r===g.current){let n=K8(e,t);v(n),c&&J8(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=k5(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,te=ee?.selection,R=C?.display??_.display??ee?.default_display,ne=ee?.displays.find(e=>e.id===R)??O5,re=C?q8(_,C,ee?.default_sort):_.sort,ie=e=>{P(e,!0)},ae=(e,t)=>{let n=A5({..._.navigation??{},[e.id]:t});ie({..._,navigation:n,offset:void 0})},se=(e,t)=>{let n=j5({..._.navigation_queries??{},[e.id]:t});ie({..._,navigation_queries:n,offset:void 0})},ce=()=>{ie({..._,query:y.trim()||void 0,key_terms:A5(x),offset:void 0})},le=U(()=>{if(!te)return;let e=Object.keys(k);return{mode:te.mode,selectAll:te.mode===`multiple`&&te.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(te.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)=>{te.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,te]);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]??D5:D5,de=ne.renderer?r?.results?.[ne.renderer]??b5:b5,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]??M8:M8;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(B0,{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(E8,{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(k8,{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(ph,{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(gh,{className:`size-4 cn-rtl-flip`})]})]})]})]})})]});return t(T8,{definition:I,request:_,result:C,selection:le,contributions:i,client:d,canDelete:f,refresh:ye,children:be})}GY(),QY(),eX(),DX();export{Jp as ActivitiesDoc,Xp as ActivityDoc,G6 as AddToCollectionAction,U6 as AddToCollectionActionComponent,cx as AgentApprovalModeSelector,CC as AgentChart,dY as AgentChatFixtureReplay,PC as AgentChatPlaybackControls,St as AgentResourceResolverProvider,NW as AgentRunFeedback,MW as AgentRunFeedbackProvider,OQ as AgentRunnerFacetsNav,j2 as AllOf,PW as AnimatedThinkingDots,A2 as AnyOf,xQ as ApiKeyAvatar,qH as AskUserWidget,E2 as AudioPanel,S3 as BrowseCollectionView,X6 as ChangeTypeAction,J6 as ChangeTypeActionComponent,O3 as CollectionIcon,IQ as CollectionsFacetsNav,D3 as CollectionsTable,JH as ConfirmationWidget,P1 as ContentDispositionButton,R3 as ContentObjectTypesSearch,A3 as ContentObjectTypesTable,Q4 as ContentOverview,T3 as CreateCollectionForm,E3 as CreateCollectionModal,j3 as CreateOrUpdateTypeModal,V2 as DefaultPermissionLoadingScreen,M8 as DefaultViewNavigation,b5 as DefaultViewResults,D5 as DefaultViewSearch,e8 as DeleteObjectsAction,Q6 as DeleteObjectsActionComponent,t8 as DeleteObjectsFromCollectionsAction,L4 as DocumentEditingPanel,I4 as DocumentEditingWorkspace,f1 as DocumentGridView,u1 as DocumentIcon,l1 as DocumentIconSkeleton,N6 as DocumentInput,P6 as DocumentPreviewPanel,p1 as DocumentSearch,M1 as DocumentSearchProvider,v3 as DocumentSearchResults,_3 as DocumentSearchResultsWithDropZone,T$ as DocumentSelection,k$ as DocumentSelectionProvider,D1 as DocumentTable,c1 as DocumentTableColumn,d1 as DocumentTableView,w1 as DocumentUploadModal,KQ as DocumentsFacetsNav,O6 as EditCollectionView,qQ as EnvironmentFacet,i8 as ExportPropertiesAction,n8 as ExportPropertiesComponent,L6 as ExportPropertiesModal,I6 as ExportTypes,b1 as FileUploadAction,B0 as GenericPageNavHeader,K0 as GroundedExtractionPanel,q0 as GroundedExtractionView,FZ as Header,D2 as ImagePanel,o6 as IntakePolicyEditor,JZ as InteractionLabel,qZ as InteractionStatusBadge,ZQ as InteractionsFacetsNav,fY as JumpingDots,qG as MESSAGE_STYLES,b2 as MagicPdfView,xY as McpConnectionsActionMenu,yY as McpConnectionsButton,vY as McpConnectionsDialog,bY as McpConnectionsInlineList,YG as MessageItem,S0 as MessagesContainer,_0 as ModernAgentConversation,V0 as NotFoundView,k2 as OAuthProviderConnectButton,_6 as ObjectSchemaEditor,M3 as ObjectTypeSearch,N3 as ObjectTypeSearchContext,S6 as ObjectTypeSearchProvider,u8 as ObjectsActionContextProvider,M0 as PanelErrorBoundary,AZ as PayloadBuilder,MZ as PayloadBuilderProvider,kZ as PayloadBuilderStore,jZ as PayloadContext,HY as PdfDocumentRenderer,FY as PdfPageRenderer,KY as PdfPageSlider,VY as PdfThumbnailList,$Q as ProcessDefinitionsFacetsNav,t$ as ProcessRunsFacetsNav,o$ as PromptsFacetsNav,R4 as PropertiesEditorModal,FW as PulsatingCircle,LW as PulsingMessageLoader,DO as RemoteMcpConnectionButton,s8 as RemoveFromCollectionAction,a8 as RemoveFromCollectionActionComponent,P0 as RowErrorBoundary,f$ as RunsFacetsNav,O4 as SaveVersionConfirmModal,m1 as SearchContext,H2 as SecureButton,U2 as SecureSidebarItem,A6 as SelectCollection,w3 as SelectContentType,x6 as SelectContentTypeModal,I1 as SelectDocument,j6 as SelectDocumentModal,w0 as SelectEnvironment,D0 as SelectModel,O0 as SelectTrainingModel,m8 as SelectionActions,IY as SharedPdfProvider,T6 as SharedPropsEditor,RY as SimplePdfPage,$Y as SimplePdfViewer,K1 as SkillWidgetProvider,cK as StreamingMessage,p$ as StringFacet,m$ as StringListFacet,E6 as SyncMemberHeadsToggle,C6 as TableLayoutEditor,RW as ThinkingBar,$W as ThinkingMessages,g$ as TypeFacet,kQ as TypeRegistry,jQ as TypeRegistryProvider,IW as TypedDots,EX as UniversalDocumentViewer,h8 as UploadObjectsButton,b8 as UserAvatar,_Q as UserInfo,B2 as UserPermissionProvider,I2 as UserPermissions,R2 as UserPermissionsContext,XZ as VInteractionFacet,eQ as VStringFacet,LQ as VTypeFacet,wQ as VUserFacet,yC as VegaLiteChart,k0 as VertesiaErrorBoundary,O2 as VideoPanel,T8 as ViewActionsProvider,E8 as ViewActionsToolbar,N5 as ViewExperience,D8 as ViewRowActions,w2 as WEB_SUPPORTED_AUDIO_FORMATS,S2 as WEB_SUPPORTED_IMAGE_FORMATS,C2 as WEB_SUPPORTED_VIDEO_FORMATS,zW as WavyThinking,I0 as WidgetErrorBoundary,v$ as WorkflowDefinitionsFacetsNav,S$ as WorkflowExecutionsFacetsNav,w$ as WorkflowRulesFacetsNav,SW as agentRunFeedbackReasonCodes,K8 as canonicalizeViewState,wC as clampPlaybackCursor,gY as countConnectedActiveGroups,DQ as createAgentRunnerFilterHandler,N4 as createDocumentChangeSummaryPrompt,M4 as createDocumentReconcilePrompt,OC as createPlaybackState,VZ as createSearchQueryKeyGuard,zZ as filterValueToQueryValue,T2 as formatDuration,$8 as formatViewFieldValue,_Y as getConnectedActiveGroupLabels,jG as getContentObjectDownloadName,DC as getNextUserTurnIndex,TC as getPlaybackCursorIndex,EC as getPreviousUserTurnIndex,X8 as getViewFieldValue,Z$ as getWorkflowStatusColor,Q$ as getWorkflowStatusName,K2 as invalidateTypeCache,AC as isAgentChatPlaybackAvailable,jC as isAgentChatPlaybackEnabled,M2 as isAnyOf,B$ as isCsv,mY as isGroupDisabled,V$ as isImage,MC as isLocalhostAgentChatPlaybackAvailable,NC as isLocalhostAgentChatPlaybackEnabled,H$ as isPdf,W$ as isPreviewableAsPdf,xC as isRechartsSpec,KZ as isUnresolvedInteractionRef,bC as isVegaLiteSpec,U$ as isVideo,z8 as parseViewState,G$ as printElementToPdf,J8 as replaceViewStateInUrl,GZ as resolveInteractionName,G2 as resolveTypeCached,q8 as resolveViewSort,J$ as retrieveRendition,U8 as serializeViewState,j0 as setErrorBoundaryComponent,BZ as setSearchQueryValue,Y$ as shortId,X$ as shortenString,WZ as splitInteractionType,w6 as stringifyTableLayout,hY as toggleGroupDisabled,RZ as unwrapFilterOptionValue,Gt as useAgentResourceResolver,EQ as useAgentRunnerFilterGroups,PQ as useCollectionsFilterGroups,FQ as useCollectionsFilterHandler,WQ as useDocumentFilterGroups,GQ as useDocumentFilterHandler,h1 as useDocumentSearch,v1 as useDocumentSearchCount,D$ as useDocumentSelection,T1 as useDocumentUploadHandler,MG as useDownloadFile,cQ as useFetchApiKeyInfo,sQ as useFetchGroupInfo,oQ as useFetchUserInfo,W0 as useGroundedExtractionAvailable,G0 as useGroundedSummary,YQ as useInteractionsFilterGroups,XQ as useInteractionsFilterHandler,pY as useMcpConnections,EO as useOAuthPopup,O$ as useOptionalDocumentSelection,NZ as usePayloadBuilder,QQ as useProcessDefinitionsFilterGroups,e$ as useProcessRunsFilterGroups,i$ as usePromptsFilterGroups,a$ as usePromptsFilterHandler,u$ as useRunsFilterGroups,d$ as useRunsFilterHandler,P3 as useSearch,I3 as useSearchCount,LY as useSharedPdf,C1 as useSmartFileUploadProcessing,MQ as useTypeRegistry,z2 as useUserPermissions,S8 as useViewActions,g1 as useWatchDocumentSearchFacets,_1 as useWatchDocumentSearchResult,F3 as useWatchSearchResult,_$ as useWorkflowDefinitionsFilterGroups,b$ as useWorkflowExecutionsFilterGroups,x$ as useWorkflowExecutionsFilterHandler,C$ as useWorkflowRulesFilterGroups};
1435
+ *`)),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-muted 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-border 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(Qg,{className:`h-5 w-5 text-info me-2`}),t(`h2`,{className:`text-lg font-semibold text-foreground 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-info hover:text-info`,children:[t(gv,{className:`h-4 w-4`}),t(`span`,{children:x(`store.fullView`)})]}),t(o,{variant:`ghost`,size:`sm`,onClick:i,className:`flex items-center text-muted hover:text-foreground dark:text-foreground`,children:t(ix,{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-info mb-2`}),t(`p`,{className:`text-muted`,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-primary text-info`:`border-transparent text-muted hover:text-foreground`}`,onClick:()=>b(`preview`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(U_,{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-primary text-info`:`border-transparent text-muted hover:text-foreground`}`,onClick:()=>b(`properties`),children:n(`div`,{className:`flex items-center gap-1`,children:[t(L_,{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-info`})}):h?t(`div`,{className:`shadow rounded-md p-4 border border-border bg-white dark:bg-muted`,children:E?t(`div`,{className:`prose prose-sm max-w-none prose-p:my-2 prose-pre:bg-muted prose-pre:my-2 prose-headings:text-info dark:prose-invert`,children:t(Nt,{children:h})}):t(`pre`,{className:`text-wrap whitespace-pre-wrap dark:text-foreground`,children:h})}):null,D&&t(`div`,{className:`mt-4`,children:_?t(`div`,{className:`border border-border rounded-md p-2 bg-white dark:bg-muted`,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-info`})})}),O&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-border rounded-md p-4 bg-muted`,children:[t(Qg,{className:`h-16 w-16 text-info mb-4`}),t(`p`,{className:`text-muted text-center mb-4`,children:x(`store.pdfPreviewFullView`)}),t(o,{onClick:T,className:`bg-primary hover:bg-primary text-white`,children:x(`store.openFullDocumentView`)})]}),!D&&!h&&!O&&!p&&n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-border rounded-md p-4 bg-muted`,children:[t(Qg,{className:`h-16 w-16 text-foreground dark:text-muted mb-4`}),t(`p`,{className:`text-muted 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-border bg-white dark:bg-muted`,children:t(jt,{value:l.properties})}):n(`div`,{className:`flex flex-col items-center justify-center h-64 border border-border rounded-md p-4 bg-muted`,children:[t(L_,{className:`h-16 w-16 text-foreground dark:text-muted mb-4`}),t(`p`,{className:`text-muted text-center`,children:x(`store.noPropertiesAvailable`)})]}),n(`div`,{className:`mt-4`,children:[t(`h3`,{className:`text-sm font-semibold text-foreground mb-2`,children:x(`store.documentInformation`)}),t(`div`,{className:`shadow rounded-md p-4 border border-border bg-white dark:bg-muted`,children:n(`div`,{className:`grid grid-cols-2 gap-y-2 gap-x-4 text-sm`,children:[t(`div`,{className:`text-muted`,children:x(`store.id`)}),t(`div`,{className:`font-medium dark:text-foreground`,children:l.id}),t(`div`,{className:`text-muted`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-foreground`,children:l.type?.name||x(`store.unknown`)}),t(`div`,{className:`text-muted`,children:x(`store.contentType`)}),t(`div`,{className:`font-medium dark:text-foreground`,children:l.content?.type||x(`store.na`)}),t(`div`,{className:`text-muted`,children:x(`store.size`)}),t(`div`,{className:`font-medium`,children:l.content&&`size`in l.content?I6(l.content.size):x(`store.unknown`)}),t(`div`,{className:`text-muted`,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-muted`,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-muted dark:border-border`,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-info border-primary hover:bg-info`,children:[t(Og,{className:`h-4 w-4 me-2`}),x(`pdf.download`)]})}),n(o,{onClick:T,className:`bg-primary hover:bg-primary text-white`,children:[x(`store.openFullDocument`),t(gh,{className:`h-4 w-4 ms-2 cn-rtl-flip`})]})]})]}):null}function I6(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 L6;(function(e){e.CSV=`CSV`,e.JSON=`JSON`})(L6||={});function R6({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(z6,{onClose:i,allowExportAll:a}),e&&t(B6,{})]})]})}function z6({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(L6),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 B6(){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 V6=dt(void 0);function H6(){let e=_t(V6);if(!e)throw Error(`You cannot use useActionContext outside an ActionProvider`);return e}function U6(e,t){let n=H6();return H(()=>n.registerCallback(e,t),[n,e,t]),n}function W6({action:e,objectIds:n}){let[r,i]=G(!1),a=V(()=>(n.length>0&&i(!0),Promise.resolve(!0)),[n]);return U6(e.id,a),r&&t(ve,{children:t(q6,{objectIds:n,isOpen:r,onClose:()=>{i(!1)}})})}const G6=Xt.getFixedT(null,Yt),K6={id:`addToCollection`,name:G6(`store.actions.addToCollection`),description:G6(`store.actions.addToCollectionDesc`),confirm:!1,component:W6};function q6({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(J6,{onClose:r,objectIds:i})})]})}function J6({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(j6,{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(E3,{onClose:e,onAddToCollection:e=>u({collectionId:e}),redirect:!1})})}];return n(ze,{defaultValue:`select`,tabs:d,fullWidth:!0,children:[t(Be,{}),t(Ve,{})]})}function Y6({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 U6(e.id,u),n(`div`,{children:[i,t(S6,{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 X6=Xt.getFixedT(null,Yt),Z6={id:`changeType`,name:X6(`store.actions.changeContentType`),description:X6(`store.actions.changeContentTypeDesc`),confirm:!1,component:Y6};function Q6({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=U6(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 $6({action:r,objectIds:i,children:a}){let{t:o}=K(),s=H6(),c=nt(),{client:l}=q(),u=g1(),d=$n(),[f,p]=G(!1),m=i?.length??0,h=s.params?.type?.name??`object`,g=V(()=>(p(!0),Promise.resolve(!0)),[]);U6(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 e8=Xt.getFixedT(null,Yt),t8={id:`delete`,name:e8(`store.actions.delete`),description:e8(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:e8(`store.actions.confirmDeleteAll`),component:$6,destructive:!0},n8={id:`deleteFromCollections`,name:e8(`store.actions.deleteObjects`),description:e8(`store.actions.deleteTheSelectedObjects`),confirm:!0,confirmationText:e8(`store.actions.confirmDeleteSelected`),component:$6,destructive:!0};function r8({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=U6(e.id,u);return t(R6,{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 i8=Xt.getFixedT(null,Yt),a8={id:`exportProperties`,name:i8(`store.actions.exportProperties`),description:i8(`store.actions.exportAllObjectProperties`),confirm:!1,component:r8};function o8({action:e,objectIds:n,collectionId:r}){let{t:i}=K(),a=H6(),o=nt(),{client:s}=q(),c=g1(),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(Q6,{action:e,callback:l})}const s8=Xt.getFixedT(null,Yt),c8={id:`removeFromCollection`,name:s8(`store.actions.removeFromCollection`),description:s8(`store.actions.removeFromCollectionDesc`),confirm:!0,confirmationText:s8(`store.actions.confirmRemoveFromCollection`),component:o8,destructive:!0};var l8=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 u8=[a8,Z6,K6,t8,c8,n8];function d8({children:e,type:r}){let i=O$(),a=nt(),{client:o}=q(),s=g1(),c=U(()=>{let e=new l8({selection:i,toast:a,client:o,search:s,type:r});return e.allActions=u8,e},[o,s,i,a,r]);return c&&n(V6.Provider,{value:c,children:[t(f8,{}),e]})}function f8(){let e=H6(),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 p8(){let{t:r}=K(),i=O$(),[a,s]=G(!1);return i?.hasSelection()?n(e,{children:[t(o,{onClick:()=>s(!0),children:r(`store.actions.startWorkflow`)}),a&&t(m8,{objectIds:i.getObjectIds(),onClose:()=>s(!1)})]}):null}function m8({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 h8({type:e,allowMutations:r=!0,allowDelete:i=!0,allowWorkflowRun:a=!1}){let s=O$(),c=s.size(),l=c>1?`s`:``,u=s?.hasSelection(),d=s?.isSingleSelection();return t(d8,{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(ix,{className:`size-4`})})]}),a&&t(p8,{}),t(v8,{selection:s,allowMutations:r,allowDelete:i,children:e=>e.length>0?t(o,{variant:`ghost`,title:`More action`,size:`sm`,children:t(jg,{size:16})}):null})]})})}function g8({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(T1,{collectionId:r??``,isOpen:l,onClose:()=>{u(!1),c([])},files:s,title:`Upload Files`,onUploadComplete:e=>{e?.success&&c([])},allowFolders:i})]})}function _8(e){return{label:e.name,className:it(`flex-1 px-2 py-2 hover:bg-muted whitespace-nowrap`,e.destructive?`text-destructive`:``)}}function v8({selection:e,children:r,allowMutations:i=!0,allowDelete:a=!0}){let o=H6(),s=e=>{o.run(e.id)},c=b8(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(y8,{executeAction:s,actions:c})})]}):null}function y8({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:_8,onChange:t=>{e(t)},noCheck:!0})})})}function b8(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):[a8]}function x8({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-primary`,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-foreground group-hover:text-foreground`,children:e.name??`Deleted User`}),t(`p`,{className:`text-xs font-medium text-muted dark:text-foreground group-hover:text-foreground`,children:e.email??`Deleted User`})]})]})}Q();const S8=dt(void 0);function C8(){return _t(S8)}function w8(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 T8(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 E8({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(w8(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=>{T8(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(S8.Provider,{value:k,children:[e,t(R6,{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 D8({selection:r,page:i,showSelectPage:a=!1}){let{t:s}=K(),c=C8(),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)&&w8(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(ix,{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(Og,{className:`size-4`}),e.handler===`delete`&&t(Ob,{className:`size-4`}),e.label]},e.id))]})}function O8({hit:e}){let{t:r}=K(),i=C8(),a=i?.actions.filter(t=>(t.placement??`selection`)===`row`&&w8(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(jg,{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 k8(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 A8({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(k8(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(T1,{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 j8(e,t,n,r){return n?r===!1?[t]:e.includes(t)?e:[...e,t]:e.filter(e=>e!==t)}function M8({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 N8({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(j8(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(ix,{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(R,{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(Ly,{"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(gh,{"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(ix,{"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(M8,{node:e}),e.expandable&&t(gh,{"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(M8,{node:e})})]},e.id)})}),r.nodes.length===0&&t(`p`,{className:`text-sm text-muted`,children:c(`filter.noAvailableFilters`)})]})}const P8=`display`,F8=`sort`,I8=`offset`;function L8(e){if(e===null||e.trim()===``)return;let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:void 0}function R8(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 z8(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 B8(e){let t=new URLSearchParams(e.startsWith(`?`)?e.slice(1):e),n=t.get(`q`)?.trim(),r=t.get(P8)?.trim(),i=t.get(F8)?.trim(),a=L8(t.get(I8)),o=R8(t,`t.`),s=R8(t,`n.`),c=z8(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 V8(e){for(let t of[...e.keys()])(t===`q`||t===P8||t===F8||t===I8||t.startsWith(`t.`)||t.startsWith(`nq.`)||t.startsWith(`n.`))&&e.delete(t)}function H8(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 U8(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 W8(e,t=``){let n=new URLSearchParams(t.startsWith(`?`)?t.slice(1):t);V8(n),e.query?.trim()&&n.set(`q`,e.query.trim()),e.display&&n.set(P8,e.display),e.sort&&n.set(F8,e.sort),e.offset&&e.offset>0&&n.set(I8,String(e.offset)),H8(n,`t.`,e.key_terms),H8(n,`n.`,e.navigation),U8(n,`nq.`,e.navigation_queries);let r=n.toString();return r?`?${r}`:``}function G8(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 K8(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 q8(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=G8(t),a=K8(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 J8(e,t,n){return t.sort??e.sort??(e.query?.trim()?void 0:n)}function Y8(e){if(typeof window>`u`)return;let t=W8(e,window.location.search);window.history.replaceState(window.history.state||{},``,`${window.location.pathname}${t}`)}Q();function X8(e,t){return!t||t===`.`?e:t.split(`.`).reduce((e,t)=>{if(e&&typeof e==`object`&&!Array.isArray(e))return e[t]},e)}function Z8(e,t){return t===`score`?e.score:t.startsWith(`annotation.`)?X8(e.annotation,t.slice(11)):t.startsWith(`document.`)?X8(e.document,t.slice(9)):X8(e.document,t)}const Q8=dt(void 0);function $8(e){if(e!=null&&e!==``)return Array.isArray(e)?e.map($8).filter(Boolean).join(`, `):typeof e==`object`?JSON.stringify(e):String(e)}function e5(e,t,n){let r=Z8(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 $8(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):$8(r)??i}return $8(r)??i}function t5({hit:e,field:n,className:r}){let a=e5(e,n,_t(Q8));return a?n.format===`badge`||n.format===`content_type`?t(i,{className:r,children:a}):t(`span`,{className:r,children:a}):null}function n5({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(Pg,{className:`size-4`})})}):n(o,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r(e),children:[t(Pg,{className:`size-4`}),a(`agent.openDocument`)]}):null}function r5(e,t){if(t.source!==`property`||!t.field)return;let n=$8(Z8(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 i5=new WeakMap,a5=[2e3,4e3,8e3];function o5(e){let t=i5.get(e);if(t)return t;let n=new Map;return i5.set(e,n),n}function s5(e,t,n){let r=o5(e),i=r.get(t);if(i)return i;let a=n().finally(()=>{r.delete(t)});return r.set(t,a),a}function c5({hit:e,media:n,resolveMedia:r,className:i}){let a=n?r5(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=>{s5(r,u,async()=>r(d.current,f.current)).then(r=>{if(!e)return;if(r){s(r);return}let a=a5[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`?P_:Qg,{className:`size-10 text-muted`})})}function l5({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 u5({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 d5({hit:e,fields:n}){return n?.length?t(`div`,{className:`flex flex-wrap gap-1`,children:n.map(n=>t(t5,{hit:e,field:n},`${n.field}-${n.label??``}`))}):null}function f5({hit:e,fields:r}){let i=_t(Q8);return r?.length?t(`dl`,{className:`space-y-1 text-sm`,children:r.map(r=>{let a=e5(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 p5({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(u5,{hit:s,page:r,selection:o})}),e.media&&t(c5,{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(t5,{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(t5,{hit:s,field:e},e.field))})]}),e.description&&t(`p`,{className:`line-clamp-3 text-sm text-muted`,children:t(t5,{hit:s,field:e.description})}),t(d5,{hit:s,fields:e.badges}),t(l5,{hit:s})]}),n(`div`,{className:`shrink-0 self-center`,children:[t(n5,{hit:s,onOpenHit:i,compact:!0}),t(O8,{hit:s})]})]},s.id))})}function m5({display:e,hits:r,isLoading:i,onOpenHit:a,sortOptions:o,currentSort:s,onSortChange:c,selection:l}){let{t:u}=K(),d=C8()?.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(yh,{className:`size-3`,"aria-hidden":`true`}):e===`descending`?t(uh,{className:`size-3`,"aria-hidden":`true`}):t(Oh,{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(u5,{hit:i,page:r,selection:l})}),e.columns.map(e=>t(`td`,{style:e.width?{width:e.width}:void 0,children:t(t5,{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(n5,{hit:i,onOpenHit:a,compact:!0}),t(O8,{hit:i})]})})]},i.id))})]})})}const h5={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 g5({hit:e,configuration:r,onOpenHit:i,resolveMedia:a,selection:o,page:p}){let m=C8()?.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(u5,{hit:e,page:p,selection:o})}),r.media&&t(c5,{hit:e,media:r.media,resolveMedia:a,className:`h-40 w-full border-b`}),n(d,{className:`gap-2 p-4`,children:[t(d5,{hit:e,fields:r.badges}),t(f,{className:`truncate text-base`,children:t(t5,{hit:e,field:r.title})}),r.description&&t(l,{className:`line-clamp-3`,children:t(t5,{hit:e,field:r.description})})]}),n(c,{className:`flex-1 p-4 pt-0`,children:[t(f5,{hit:e,fields:r.fields}),t(l5,{hit:e})]}),(i||m)&&n(u,{className:`justify-end p-4 pt-0`,children:[t(n5,{hit:e,onOpenHit:i}),t(O8,{hit:e})]})]})}function _5({display:e,hits:n,onOpenHit:r,resolveMedia:i,selection:a}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${h5[e.columns??3]}`,children:n.map(o=>t(g5,{hit:o,configuration:e,onOpenHit:r,resolveMedia:i,selection:a,page:n},o.id))})}function v5({display:e,hits:r,onOpenHit:i,resolveMedia:a,selection:o}){return t(`div`,{className:`grid grid-cols-1 gap-4 ${h5[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(u5,{hit:l,page:r,selection:o})}),t(c5,{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(t5,{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(t5,{hit:l,field:e})},e.field))}),n(`div`,{className:`flex items-center justify-end gap-1`,children:[t(n5,{hit:l,onOpenHit:i}),t(O8,{hit:l})]})]})]},l.id))})}function y5({display:e,hits:r,onOpenHit:a,resolveMedia:o,selection:s}){let c=new Map;for(let t of r){let n=$8(Z8(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(g5,{hit:n,configuration:e.card,onOpenHit:a,resolveMedia:o,selection:s,page:r},n.id))})]},l.value)})})}function b5(e,n,r,i,a,o,s,c,l){return e.type===`table`?t(m5,{display:e,hits:n,isLoading:r,onOpenHit:i,sortOptions:o,currentSort:s,onSortChange:c,selection:l}):e.type===`cards`?t(_5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`gallery`?t(v5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):e.type===`board`?t(y5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l}):t(p5,{display:e,hits:n,onOpenHit:i,resolveMedia:a,selection:l})}function x5({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(Q8.Provider,{value:d,children:b5(e,i.hits,a,s,c,n.results?.sort_options,J8(r,i,n.results?.default_sort),o,l)})}Q();function S5(e,t){return t?`text`:e===`number`?`number`:e===`date`?`date`:`text`}function C5(e){let[t=``,n=``]=(e[0]??``).split(`..`,2);return[t,n]}function w5(e,t){return e||t?[`${e}..${t}`]:[]}function T5(e,t){return t?e.join(`, `):e[0]??``}function E5(e,t){return t?e.split(`,`).map(e=>e.trim()).filter(Boolean):e.trim()?[e.trim()]:[]}function D5({term:e,values:n,isLoading:r,onChange:i}){let a=W(!1),o=W(void 0),[s,c]=G(()=>T5(n,e.multiple)),l=T5(n,e.multiple);return H(()=>{a.current&&o.current===l||c(l),o.current=void 0},[l]),t(L,{label:e.label,children:t(R,{type:S5(e.type,e.multiple),name:`view-key-term-${e.id}`,autoComplete:`off`,value:s,onFocus:()=>{a.current=!0},onBlur:()=>{a.current=!1;let t=E5(s,e.multiple);c(T5(t,e.multiple))},onChange:t=>{c(t);let n=E5(t,e.multiple);o.current=T5(n,e.multiple),i(n)},placeholder:e.label,disabled:r})})}function O5({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(R,{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(Ly,{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(D5,{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]=C5(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(R,{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,w5(t.trim(),o)),placeholder:u(`view.from`),disabled:a}),t(R,{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,w5(r,t.trim())),placeholder:u(`view.to`),disabled:a})]})]},e.id)})})]})]})]})}Q();const k5={id:`default`,label:`Results`,type:`list`,title:{field:`name`},subtitle:[{field:`type.name`,format:`content_type`},{field:`location`,format:`location`}],description:{field:`description`}};function A5(e){return!e||typeof window>`u`?{}:B8(window.location.search)}function j5(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e.length>0));return Object.keys(t).length>0?t:void 0}function M5(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 N5(e){let{client:n}=q(),r=_t(z2),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(F5,{...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 P5({execute:e,...n}){return e?t(F5,{...n,execute:e},n.viewId):t(N5,{...n},n.viewId)}function F5({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(()=>A5(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&&Y8(e),E(!0),O(void 0),h.current(e).then(t=>{if(r===g.current){let n=q8(e,t);v(n),c&&Y8(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=A5(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,te=ee?.selection,R=C?.display??_.display??ee?.default_display,ne=ee?.displays.find(e=>e.id===R)??k5,re=C?J8(_,C,ee?.default_sort):_.sort,ie=e=>{P(e,!0)},ae=(e,t)=>{let n=j5({..._.navigation??{},[e.id]:t});ie({..._,navigation:n,offset:void 0})},se=(e,t)=>{let n=M5({..._.navigation_queries??{},[e.id]:t});ie({..._,navigation_queries:n,offset:void 0})},ce=()=>{ie({..._,query:y.trim()||void 0,key_terms:j5(x),offset:void 0})},le=U(()=>{if(!te)return;let e=Object.keys(k);return{mode:te.mode,selectAll:te.mode===`multiple`&&te.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(te.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)=>{te.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,te]);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]??O5:O5,de=ne.renderer?r?.results?.[ne.renderer]??x5:x5,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]??N8:N8;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(V0,{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(D8,{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(A8,{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(ph,{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(gh,{className:`size-4 cn-rtl-flip`})]})]})]})]})})]});return t(E8,{definition:I,request:_,result:C,selection:le,contributions:i,client:d,canDelete:f,refresh:ye,children:be})}KY(),$Y(),tX(),OX();export{Jp as ActivitiesDoc,Xp as ActivityDoc,K6 as AddToCollectionAction,W6 as AddToCollectionActionComponent,cx as AgentApprovalModeSelector,CC as AgentChart,dY as AgentChatFixtureReplay,PC as AgentChatPlaybackControls,St as AgentResourceResolverProvider,NW as AgentRunFeedback,MW as AgentRunFeedbackProvider,kQ as AgentRunnerFacetsNav,M2 as AllOf,PW as AnimatedThinkingDots,j2 as AnyOf,SQ as ApiKeyAvatar,qH as AskUserWidget,D2 as AudioPanel,C3 as BrowseCollectionView,Z6 as ChangeTypeAction,Y6 as ChangeTypeActionComponent,k3 as CollectionIcon,LQ as CollectionsFacetsNav,O3 as CollectionsTable,JH as ConfirmationWidget,F1 as ContentDispositionButton,z3 as ContentObjectTypesSearch,j3 as ContentObjectTypesTable,$4 as ContentOverview,E3 as CreateCollectionForm,D3 as CreateCollectionModal,M3 as CreateOrUpdateTypeModal,H2 as DefaultPermissionLoadingScreen,N8 as DefaultViewNavigation,x5 as DefaultViewResults,O5 as DefaultViewSearch,t8 as DeleteObjectsAction,$6 as DeleteObjectsActionComponent,n8 as DeleteObjectsFromCollectionsAction,R4 as DocumentEditingPanel,L4 as DocumentEditingWorkspace,p1 as DocumentGridView,d1 as DocumentIcon,u1 as DocumentIconSkeleton,P6 as DocumentInput,F6 as DocumentPreviewPanel,m1 as DocumentSearch,N1 as DocumentSearchProvider,y3 as DocumentSearchResults,v3 as DocumentSearchResultsWithDropZone,E$ as DocumentSelection,A$ as DocumentSelectionProvider,O1 as DocumentTable,l1 as DocumentTableColumn,f1 as DocumentTableView,T1 as DocumentUploadModal,qQ as DocumentsFacetsNav,k6 as EditCollectionView,JQ as EnvironmentFacet,a8 as ExportPropertiesAction,r8 as ExportPropertiesComponent,R6 as ExportPropertiesModal,L6 as ExportTypes,x1 as FileUploadAction,V0 as GenericPageNavHeader,q0 as GroundedExtractionPanel,J0 as GroundedExtractionView,IZ as Header,O2 as ImagePanel,s6 as IntakePolicyEditor,YZ as InteractionLabel,JZ as InteractionStatusBadge,QQ as InteractionsFacetsNav,fY as JumpingDots,qG as MESSAGE_STYLES,x2 as MagicPdfView,SY as McpConnectionsActionMenu,bY as McpConnectionsButton,yY as McpConnectionsDialog,xY as McpConnectionsInlineList,YG as MessageItem,C0 as MessagesContainer,v0 as ModernAgentConversation,H0 as NotFoundView,A2 as OAuthProviderConnectButton,v6 as ObjectSchemaEditor,N3 as ObjectTypeSearch,P3 as ObjectTypeSearchContext,C6 as ObjectTypeSearchProvider,d8 as ObjectsActionContextProvider,N0 as PanelErrorBoundary,jZ as PayloadBuilder,NZ as PayloadBuilderProvider,AZ as PayloadBuilderStore,MZ as PayloadContext,UY as PdfDocumentRenderer,IY as PdfPageRenderer,qY as PdfPageSlider,HY as PdfThumbnailList,e$ as ProcessDefinitionsFacetsNav,n$ as ProcessRunsFacetsNav,s$ as PromptsFacetsNav,z4 as PropertiesEditorModal,FW as PulsatingCircle,LW as PulsingMessageLoader,DO as RemoteMcpConnectionButton,c8 as RemoveFromCollectionAction,o8 as RemoveFromCollectionActionComponent,F0 as RowErrorBoundary,p$ as RunsFacetsNav,k4 as SaveVersionConfirmModal,h1 as SearchContext,U2 as SecureButton,W2 as SecureSidebarItem,j6 as SelectCollection,T3 as SelectContentType,S6 as SelectContentTypeModal,L1 as SelectDocument,M6 as SelectDocumentModal,T0 as SelectEnvironment,O0 as SelectModel,k0 as SelectTrainingModel,h8 as SelectionActions,LY as SharedPdfProvider,E6 as SharedPropsEditor,zY as SimplePdfPage,eX as SimplePdfViewer,q1 as SkillWidgetProvider,cK as StreamingMessage,m$ as StringFacet,h$ as StringListFacet,D6 as SyncMemberHeadsToggle,w6 as TableLayoutEditor,RW as ThinkingBar,$W as ThinkingMessages,_$ as TypeFacet,AQ as TypeRegistry,MQ as TypeRegistryProvider,IW as TypedDots,DX as UniversalDocumentViewer,g8 as UploadObjectsButton,x8 as UserAvatar,vQ as UserInfo,V2 as UserPermissionProvider,L2 as UserPermissions,z2 as UserPermissionsContext,ZZ as VInteractionFacet,tQ as VStringFacet,RQ as VTypeFacet,TQ as VUserFacet,yC as VegaLiteChart,A0 as VertesiaErrorBoundary,k2 as VideoPanel,E8 as ViewActionsProvider,D8 as ViewActionsToolbar,P5 as ViewExperience,O8 as ViewRowActions,T2 as WEB_SUPPORTED_AUDIO_FORMATS,C2 as WEB_SUPPORTED_IMAGE_FORMATS,w2 as WEB_SUPPORTED_VIDEO_FORMATS,zW as WavyThinking,L0 as WidgetErrorBoundary,y$ as WorkflowDefinitionsFacetsNav,C$ as WorkflowExecutionsFacetsNav,T$ as WorkflowRulesFacetsNav,SW as agentRunFeedbackReasonCodes,q8 as canonicalizeViewState,wC as clampPlaybackCursor,_Y as countConnectedActiveGroups,OQ as createAgentRunnerFilterHandler,P4 as createDocumentChangeSummaryPrompt,N4 as createDocumentReconcilePrompt,OC as createPlaybackState,HZ as createSearchQueryKeyGuard,BZ as filterValueToQueryValue,E2 as formatDuration,e5 as formatViewFieldValue,vY as getConnectedActiveGroupLabels,jG as getContentObjectDownloadName,DC as getNextUserTurnIndex,TC as getPlaybackCursorIndex,EC as getPreviousUserTurnIndex,Z8 as getViewFieldValue,Q$ as getWorkflowStatusColor,$$ as getWorkflowStatusName,q2 as invalidateTypeCache,AC as isAgentChatPlaybackAvailable,jC as isAgentChatPlaybackEnabled,N2 as isAnyOf,V$ as isCsv,gY as isGroupConnected,mY as isGroupDisabled,H$ as isImage,MC as isLocalhostAgentChatPlaybackAvailable,NC as isLocalhostAgentChatPlaybackEnabled,U$ as isPdf,G$ as isPreviewableAsPdf,xC as isRechartsSpec,qZ as isUnresolvedInteractionRef,bC as isVegaLiteSpec,W$ as isVideo,B8 as parseViewState,K$ as printElementToPdf,Y8 as replaceViewStateInUrl,KZ as resolveInteractionName,K2 as resolveTypeCached,J8 as resolveViewSort,Y$ as retrieveRendition,W8 as serializeViewState,M0 as setErrorBoundaryComponent,VZ as setSearchQueryValue,X$ as shortId,Z$ as shortenString,GZ as splitInteractionType,T6 as stringifyTableLayout,hY as toggleGroupDisabled,zZ as unwrapFilterOptionValue,Gt as useAgentResourceResolver,DQ as useAgentRunnerFilterGroups,FQ as useCollectionsFilterGroups,IQ as useCollectionsFilterHandler,GQ as useDocumentFilterGroups,KQ as useDocumentFilterHandler,g1 as useDocumentSearch,y1 as useDocumentSearchCount,O$ as useDocumentSelection,E1 as useDocumentUploadHandler,MG as useDownloadFile,lQ as useFetchApiKeyInfo,cQ as useFetchGroupInfo,sQ as useFetchUserInfo,G0 as useGroundedExtractionAvailable,K0 as useGroundedSummary,XQ as useInteractionsFilterGroups,ZQ as useInteractionsFilterHandler,pY as useMcpConnections,EO as useOAuthPopup,k$ as useOptionalDocumentSelection,PZ as usePayloadBuilder,$Q as useProcessDefinitionsFilterGroups,t$ as useProcessRunsFilterGroups,a$ as usePromptsFilterGroups,o$ as usePromptsFilterHandler,d$ as useRunsFilterGroups,f$ as useRunsFilterHandler,F3 as useSearch,L3 as useSearchCount,RY as useSharedPdf,w1 as useSmartFileUploadProcessing,NQ as useTypeRegistry,B2 as useUserPermissions,C8 as useViewActions,_1 as useWatchDocumentSearchFacets,v1 as useWatchDocumentSearchResult,I3 as useWatchSearchResult,v$ as useWorkflowDefinitionsFilterGroups,x$ as useWorkflowExecutionsFilterGroups,S$ as useWorkflowExecutionsFilterHandler,w$ as useWorkflowRulesFilterGroups};
1436
1436
  //# sourceMappingURL=vertesia-ui-features.js.map