Release of @iterate-com/ui from 2dad9d70df726cde287b3b2066cc14a672d236e8
ui release builder, 2026-11-26 23:04 UTC · 87fc8a87e7d39570888e70d813c90facd1ba872d · parent dad6fd3
82 files changed
- M dist/agent-kind-view-frame.js
- M dist/agent-kind-view/dash-agents.mjs
- M dist/chunks/agent-chat.mjs
- M dist/chunks/agent-events.mjs
- M dist/chunks/agent-facts.mjs
- M dist/chunks/agent-look.mjs
- M dist/chunks/agent-strip.mjs
- M dist/chunks/agent-summary.mjs
- M dist/chunks/app-shell.mjs
- M dist/chunks/code-block.client.mjs
- M dist/chunks/command.mjs
- M dist/chunks/composer.mjs
- M dist/chunks/context-about.mjs
- M dist/chunks/context-catalog-list.mjs
- A dist/chunks/context-catalog-live.mjs
- M dist/chunks/context-catalog-rows.mjs
- M dist/chunks/context-view-search.mjs
- M dist/chunks/context-view.mjs
- M dist/chunks/dash.mjs
- M dist/chunks/dist3.mjs
- M dist/chunks/docs-editor-icons.mjs
- M dist/chunks/highlighted-body-KPVGNVTW.mjs
- M dist/chunks/host.mjs
- M dist/chunks/mermaid-HWGCJPDP.mjs
- M dist/chunks/message.mjs
- M dist/chunks/presence-line.mjs
- M dist/chunks/principal-label.mjs
- M dist/chunks/react.mjs
- M dist/chunks/run.mjs
- M dist/chunks/sonner.mjs
- M dist/chunks/ui-shell.mjs
- A dist/chunks/vendor-db.mjs
- M dist/chunks/vendor-icons.mjs
- M dist/chunks/vendor-zod.mjs
- M dist/chunks/virtual-log.mjs
- M dist/chunks/waiting-approvals.mjs
- M dist/components/agent-chat/chat-parts.mjs
- M dist/components/agent-context.mjs
- M dist/components/agents-home.mjs
- M dist/components/agents-nav.mjs
- M dist/components/call/call-bar.mjs
- M dist/components/call/call-controls.mjs
- M dist/components/call/call-pip.mjs
- M dist/components/call/caption-strip.mjs
- M dist/components/call/face.mjs
- M dist/components/call/transcript-rollup.mjs
- M dist/components/change-my-mind-button.mjs
- M dist/components/checklist.mjs
- M dist/components/connect-mind.mjs
- M dist/components/context-catalog/context-catalog.mjs
- M dist/components/context-explorer/context-explorer.mjs
- A dist/components/context-stream/context-stream.mjs
- M dist/components/copy-text.mjs
- M dist/components/dash/dash-paths.mjs
- M dist/components/docs-editor/docs-editor.mjs
- M dist/components/identifier.mjs
- M dist/components/integrations-page.mjs
- M dist/components/last-mind-redirect.mjs
- M dist/components/mcp-connect.mjs
- M dist/components/page-tools.mjs
- M dist/components/repo-ide/repo-ide.mjs
- M dist/components/secrets-page.mjs
- M dist/components/setup-steps.mjs
- M dist/components/step-row.mjs
- M dist/components/ui/breadcrumb.mjs
- M dist/components/ui/checkbox.mjs
- M dist/components/ui/native-select.mjs
- M dist/components/ui/select.mjs
- M dist/components/ui/spinner.mjs
- A dist/db.mjs
- M dist/docs-editor.css
- M dist/icons.mjs
- M dist/iterate.css
- M dist/lib/agent-progress.mjs
- M dist/lib/call-rules.mjs
- M dist/lib/page-url.mjs
- M dist/lib/presence.mjs
- M dist/lib/saved-log-tail.mjs
- M dist/styles.css
- M files.json
- M package.json
- M release.json
M dist/agent-kind-view-frame.js
Not shown: the change is larger than this page shows. A clone has it.
M dist/agent-kind-view/dash-agents.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"../chunks/rolldown-runtime.mjs";import{a as t,n}from"../chunks/vendor-react";import{itxSessionOf as r,keptRead as i,versionOf as a}from"../lib/itx-session";import{_ as o,c as s,d as c,f as l,g as u,i as d,l as f,m as p,r as m,t as h,u as g}from"../chunks/vendor-zod";import{sameView as _,savedLogTails as v}from"../lib/saved-log-tail";import{t as y}from"../chunks/react.mjs";import{useHasSavedTail as b,useSavedContext as ee}from"../lib/saved-context";import{t as x}from"../chunks/use-itx-session.mjs";import{d as S,y as C}from"../chunks/vendor-icons";import{n as w,o as T,r as E,t as D}from"../chunks/host.mjs";import{WIDGET_FACT as O,asksToReadContext as k,widgetNamesContext as A}from"../components/widget/widget";import{r as j}from"../chunks/agent-facts.mjs";import{f as M,l as N,n as P,o as F,s as te}from"../chunks/agent-summary.mjs";import{t as ne}from"../chunks/context-view-search.mjs";import{t as re}from"../chunks/agent-reading.mjs";import{AgentPageHeader as ie,heldRowsOf as ae}from"../components/agent-chat/agent-page-header";import{go as I,hrefOf as oe,linkTo as se,pageHref as ce,usePageParam as L,useView as R}from"../lib/page-url";import{a as z,f as le,l as ue,p as B}from"../chunks/dash.mjs";var V=/* @__PURE__ */ e(t(),1);const de=e=>{let t=t=>e.some(e=>e.match===`itx.${t}`&&e.target===`itx.builtins.${t}`);return!(t(`run`)&&t(`cd`))},fe=f({name:p(),_meta:f({ui:f({visibility:m(p()).optional()}).optional()}).optional()}),pe=f({isError:d().optional()});function me({path:e,open:t,append:n,now:r=Date.now,rules:i,readEvents:a}){let o=/* @__PURE__ */ new Map,s=(e,n)=>{let r=JSON.stringify([e,n||{}]),i=o.get(r);return i||(i={connection:t(e,n)},o.set(r,i),i.connection.catch(()=>o.delete(r))),i},c=t=>{if(t!==e)throw Error(`A widget of ${e} cannot call as ${t}.`)};return{async callTool({path:e,key:t,server:i,headers:a,name:o,args:l}){c(e);let u=s(i,a),d=await u.connection,f=()=>{let e=d.listTools().then(e=>e.flatMap(e=>fe.safeParse(e).data??[])),t={listed:e,at:r()};return u.tools=t,e.catch(()=>{u.tools===t&&(u.tools=void 0)}),e},p=u.tools&&r()-u.tools.at<3e4,m=async e=>(await e).find(e=>e.name===o),h=await m(p&&u.tools?u.tools.listed:f())??(p?await m(f()):void 0);if(!h)throw Error(`${o} is not a tool of ${i}.`);let g=h._meta?.ui?.visibility;if(g&&!g.includes(`app`))throw Error(`${o} is not a tool for the app: its visibility is ${g.join(`, `)}.`);let _=performance.now(),v=(e,r)=>n([{type:O.toolCalled,payload:{key:t,server:i,tool:o,ok:e,ms:Math.round(performance.now()-_),error:r}}]).catch(()=>void 0);try{let e=await d.callToolResult(o,l);return v(pe.safeParse(e).data?.isError!==!0),e}catch(e){throw v(!1,(e instanceof Error?e.message:String(e)).slice(0,500)),e}},async readResource({path:e,server:t,headers:n,uri:r}){return c(e),await(await s(t,n).connection).readResource(r)},...i&&a&&{async readContext({path:t,context:n,after:r,limit:o}){if(c(t),de(await i()))throw Error(`The agent at ${e} is jailed: its widget reads no context of the mind.`);let s=(e,t,n)=>Number.isFinite(e)?Math.min(Math.max(Math.floor(e),t),n):t;return await a(n,s(r,0,2**53-1),s(o,1,500))}}}}const H=e=>e,he=m(f({type:p(),payload:l(p(),o()).optional()}));async function U(e,t){await e.append(...he.parse(t))}async function W(e,t,n){let r=await e.cd(t);try{await U(r,n)}finally{r[Symbol.dispose]()}}async function G(e,t,n,r){let i=H(e).agents.get(t);try{await(r?i.message(n,{key:r}):i.message(n))}finally{i[Symbol.dispose]()}}async function ge(e,t){let n=e.files.get(t);try{return(await n.url()).url}finally{n[Symbol.dispose]()}}async function _e(e,t,n,r){let i=[];for(let[a,o]of n.entries()){let n=o.filename.replace(/[^A-Za-z0-9._-]+/g,`-`),s=r?(await ve(`${r}\n${String(a)}\n${o.contentType}\n${await ve(o.data)}`)).slice(0,16):crypto.randomUUID().slice(0,8),c=e.files.get(`${t}/${s}-${n}`);try{let e=await c.put({contentType:o.contentType,data:o.data});i.push({contentType:e.contentType,filename:o.filename,path:e.path,size:e.size})}finally{c[Symbol.dispose]()}}return i}async function ve(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e));return Array.from(new Uint8Array(t),e=>e.toString(16).padStart(2,`0`)).join(``)}const ye=/* @__PURE__ */ new WeakMap;function K(e,t){let n=ye.get(e);n||ye.set(e,n=/* @__PURE__ */ new Map);let r=n.get(t);if(!r){let i,a=()=>(i||=Promise.resolve(e.cd(t)),i.catch(()=>i=void 0),i);r=me({path:t,open:async(e,t)=>await(await a()).connectToMcp(e,{headers:t}),append:async e=>await U(await a(),e),rules:async()=>(await(await a()).rewriteRules.list(0)).map(({match:e,target:t})=>({match:e,target:t})),readEvents:async(e,t,n)=>{let r=await(await a()).cd(e);try{return await r.readEvents(t,n)}finally{r[Symbol.dispose]()}}}),n.set(t,r)}return r}const be=/\bdefault\s*:\s*true\b/;function xe(e){return e.filter(e=>e.source&&be.test(e.source)).toSorted((e,t)=>e.kind.localeCompare(t.kind))}async function Se(e,t=15e3){for(let n of e){let e=await Ce(n,t),r=e&&`ephemeralEvents`in e?e.newAgent:void 0;if(r?.default&&r.choices.length>0)return{starter:n,newAgent:r}}return null}function Ce(e,t){let n=e.loaded();return n?Promise.resolve(n):new Promise(n=>{let r=setTimeout(()=>{i(),n(void 0)},t),i=e.subscribe(()=>{let t=e.loaded();t&&(clearTimeout(r),i(),n(t))})})}function we(e,t,n){let[r]=e.newAgent.choices,i=N(e.starter.file.kind,n,r.byPerson?t:void 0),a=Object.fromEntries((e.newAgent.fields||[]).filter(e=>!e.choices||e.choices.includes(r.id)).map(e=>[e.name,e.type===`select`&&e.options&&!e.options.includes(e.defaultValue)?e.options[0]??``:e.defaultValue]));return{choice:r.id,fields:a,path:i}}async function Te(e,t,n){let r=t.files.length>0?await n.storeFiles(e,t.files):[];await n.append(e,[j({message:t.message,files:r})])}const Ee=ne.extend({view:h([`chat`,`events`]).optional().catch(void 0),llmRequest:g().int().positive().optional().catch(void 0),scriptRun:g().int().positive().optional().catch(void 0)});var q=/* @__PURE__ */ e(n(),1);function J(e){let t;return()=>t||=e()}const Y=J(()=>import(`../components/agents-home`)),De=J(()=>import(`../components/agent-chat/agent-chat`)),Oe=J(()=>import(`../components/page-tools`)),ke=J(async()=>{let e=import(`../chunks/call-presence.mjs`),t=import(`../chunks/dash-share.mjs`),{AgentCall:n}=await import(`../chunks/dash-call.mjs`),{inCallOf:r}=await e,{AgentShare:i}=await t;return{AgentCall:n,AgentShare:i,inCallOf:r}}),Ae=l(p(),p()),X=/* @__PURE__ */ new WeakMap,je=/* @__PURE__ */ new WeakMap;function Me(e){let t=i(e,X.get(e),t=>(async()=>{let n=()=>(t(),null),r=await Promise.resolve(e.kv.get(`agent-kinds`)).catch(n),i={};try{i=Ae.safeParse(JSON.parse(r||`{}`)).data||{}}catch{}let a=e.repos.get(`/repos/config`);return await Promise.all(Object.entries(i).map(async([e,t])=>({kind:e,name:t,source:await Promise.resolve(a.readFile(t)).then(e=>e||null,n)})))})());return t!==X.get(e)&&t.answer.then(e=>void je.set(t.answer,e),()=>{}),X.set(e,t),t.answer}function Ne(e){let t=Me(e),n=(0,V.useCallback)(e=>{let n=!0;return t.then(()=>{n&&e()},()=>{}),()=>{n=!1}},[t]);return{files:t,kinds:(0,V.useSyncExternalStore)(n,()=>je.get(t))}}let Pe;function Fe(){return Pe||=`${Ie.safeParse(JSON.parse(document.querySelector(`script[type="importmap"]`)?.textContent||`{}`)).data?.imports[`@iterate-com/ui/`]||`/`}dist/agent-kind-view-frame.js?raw`,Pe}const Ie=c({imports:l(p(),p())});function Le({itx:e,mind:t,principal:n,pages:r,agents:i,waiting:a}){let{RecentAgents:o}=(0,V.use)(Y()),s=Be(r);return/* @__PURE__ */ (0,q.jsx)(ue,{children:/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-8 px-4 pt-8 pb-12 md:px-8 md:pt-16`,children:[/* @__PURE__ */ (0,q.jsx)(Ve,{itx:e,principal:n,links:s}),/* @__PURE__ */ (0,q.jsx)(We,{itx:e,mind:t,pages:r,waiting:a}),i?/* @__PURE__ */ (0,q.jsx)(o,{agents:i,...s}):/* @__PURE__ */ (0,q.jsx)(z,{waiting:!0,children:`Reading the agents…`})]})})}Le.staysOverReconnect=!0;function Re(e){let t=L(`agent`);return t?/* @__PURE__ */ (0,q.jsx)(Xe,{...e,path:t},t):/* @__PURE__ */ (0,q.jsx)(ze,{...e})}Re.staysOverReconnect=!0;function ze({itx:e,principal:t,pages:n,agents:r}){let{AllAgents:i}=(0,V.use)(Y()),a=Be(n),o=ct(5e3),s=(0,V.useMemo)(()=>r&&te(r,``).length,[r]),c=(0,V.useMemo)(()=>r&&P(r),[r]);return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-6 px-4 pt-8 md:px-8`,children:[/* @__PURE__ */ (0,q.jsxs)(`header`,{className:`flex items-baseline justify-between gap-3`,children:[/* @__PURE__ */ (0,q.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Agents`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`text-sm text-muted-foreground tabular-nums`,children:s===void 0?``:`${s.toLocaleString(`en`)} ${s===1?`agent`:`agents`}`})]}),/* @__PURE__ */ (0,q.jsx)(Ve,{itx:e,principal:t,links:a}),/* @__PURE__ */ (0,q.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground`,children:`Most recently active`})]}),!r||!c?/* @__PURE__ */ (0,q.jsx)(z,{waiting:!0,children:`Reading the agents…`}):c.length?/* @__PURE__ */ (0,q.jsx)(i,{agents:r,nowMs:o,className:`pb-8`,...a}):/* @__PURE__ */ (0,q.jsx)(`p`,{className:`mx-auto w-full max-w-3xl px-4 font-readme text-sm text-muted-foreground md:px-8`,children:`No agents yet. Say something above to start one.`})]})}function Be(e){let t=e.find(e=>e.id===`agents`)?.id;return(0,V.useMemo)(()=>{let e=e=>e?B(e):ce(t);return{agentHref:e,onOpen:t=>I(e(t))}},[t])}function Ve({itx:e,principal:t,links:n}){let{NewAgentComposer:r}=(0,V.use)(Y()),{frames:i,resolve:a,chosen:o}=He(e),[s]=(0,V.useState)(()=>F(globalThis.location?.hash));return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[i,/* @__PURE__ */ (0,q.jsx)(r,{initialDraft:s,person:t===void 0?async()=>M((await e.whoami()).principal?.email):M(t?.email),pathFor:async(e,t)=>{let n=await a();if(!n)return N(`web`,t,e);let r=we(n,e,t);return o.set(r.path,{found:n,start:r}),r.path},onCreate:async t=>{let n=o.get(t);if(!n)return await H(e).agents.create(t);await W(e,t,await n.found.starter.start(n.start))},onMessage:(t,{message:n,files:r})=>o.has(t)?Te(t,{message:n,files:r},{storeFiles:(t,n)=>_e(e,t,n),append:(t,n)=>W(e,t,n)}):G(e,t,{message:n,files:r}),...n})]})}function He(e){let{files:t,kinds:n}=Ne(e),[r]=(0,V.useState)(()=>/* @__PURE__ */ new Map),[i]=(0,V.useState)(()=>/* @__PURE__ */ new Map),a=(0,V.useCallback)(e=>{let t=`${e.name}\n${e.source||``}`,n=r.get(t);if(n)return n;let i=new E(e.name,e.source);return r.set(t,i),i},[r]);return{frames:(0,V.useMemo)(()=>xe(n||[]),[n]).map(e=>/* @__PURE__ */ (0,q.jsx)(D,{link:a(e),frameScript:Fe()},e.name)),resolve:(0,V.useCallback)(async()=>Se(xe(await t.catch(()=>[])).map(e=>Ue(e,a(e)))),[t,a]),chosen:i}}function Ue(e,t){return{file:e,loaded:t.loaded,subscribe:t.subscribe,start:e=>t.start(e)}}function We({itx:e,mind:t,pages:n,waiting:r}){let[i]=(0,V.useState)(()=>Ye(e)),a=n.find(e=>e.id===`integrations`);return/* @__PURE__ */ (0,q.jsxs)(`section`,{"aria-labelledby":`needs-you`,className:`flex min-h-22 flex-col gap-3`,children:[/* @__PURE__ */ (0,q.jsx)(`h2`,{id:`needs-you`,className:`text-sm font-medium text-muted-foreground`,children:`Waiting for you`}),/* @__PURE__ */ (0,q.jsx)(V.Suspense,{fallback:/* @__PURE__ */ (0,q.jsx)(Ge,{}),children:/* @__PURE__ */ (0,q.jsx)(Ke,{integrations:i,approvals:r,approvalsHref:`https://${t}/secrets/approvals`,integrationsHref:a&&ce(a.id)})})]})}function Ge(){return/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Looking…`})}function Ke({integrations:e,approvals:t,approvalsHref:n,integrationsHref:r}){let i=(0,V.use)(e);return t===void 0?/* @__PURE__ */ (0,q.jsx)(Ge,{}):!t&&!i.length?/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Nothing waits for you.`}):/* @__PURE__ */ (0,q.jsxs)(`ul`,{className:`flex flex-col gap-2`,children:[t?/* @__PURE__ */ (0,q.jsx)(Z,{href:n,icon:/* @__PURE__ */ (0,q.jsx)(C,{"aria-hidden":!0,className:`size-4 shrink-0 text-warning`}),title:t===1?`1 request waits for your yes`:`${String(t)} requests wait for your yes`,text:`Your agents wait until you answer.`}):null,i.map(e=>/* @__PURE__ */ (0,q.jsx)(Z,{href:r,inPage:!0,icon:/* @__PURE__ */ (0,q.jsx)(S,{"aria-hidden":!0,className:e.kind===`error`?`size-4 shrink-0 text-destructive`:`size-4 shrink-0 text-warning`}),title:e.title,text:e.text},e.key))]})}function Z({href:e,inPage:t,icon:n,title:r,text:i}){let a=/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[n,/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[/* @__PURE__ */ (0,q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:r}),i?/* @__PURE__ */ (0,q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:i}):null]})]}),o=`flex items-center gap-3 rounded-lg border px-3 py-2`;return/* @__PURE__ */ (0,q.jsx)(`li`,{children:e?/* @__PURE__ */ (0,q.jsx)(`a`,{...t?se(e):{href:e},className:`${o} text-inherit no-underline hover:bg-muted/60`,children:a}):/* @__PURE__ */ (0,q.jsx)(`div`,{className:o,children:a})})}const qe=c({kind:h([`ok`,`attention`,`error`]),text:p().optional()}),Je=c({integrations:l(p(),f({title:p(),status:qe.optional()})).catch({}).default({}),connections:l(p(),f({account:p(),status:qe.optional()})).catch({}).default({})});async function Ye(e){try{if(!await le(e,`integrations`))return[];let t=await e.cd(`/integrations`),n;try{n=(await y(t,`integration`)).state}finally{t[Symbol.dispose]()}let{integrations:r,connections:i}=Je.parse(n),a=Object.entries(r).flatMap(([e,t])=>t.status&&t.status.kind!==`ok`?[{key:e,title:t.title,text:t.status.text,kind:t.status.kind}]:[]),o=Object.entries(i).flatMap(([e,t])=>{let n=r[e.split(`/`)[0]];return t.status&&t.status.kind!==`ok`?[{key:e,title:`${n?.title||e.split(`/`)[0]}: ${t.account}`,text:t.status.text,kind:t.status.kind}]:[]});return[...a,...o]}catch{return[]}}function Xe({itx:e,mind:t,mindFace:n,principal:r,page:i,agents:a,path:o}){let s=(0,V.useMemo)(()=>n||{name:t},[n,t]),c=r===void 0?`pending`:r?.actor?v({mind:t,actor:r.actor}):void 0,l=b(c,o),u=l!==!1,d=l&&c&&c!==`pending`?c.peek(o)?.view:void 0;return/* @__PURE__ */ (0,q.jsxs)(Q,{value:s,children:[/* @__PURE__ */ (0,q.jsx)(V.Suspense,{fallback:/* @__PURE__ */ (0,q.jsx)(Qe,{path:o,agents:a,quiet:u,presence:!!i.presence,call:!!i.call,share:!!(i.call&&i.share)}),children:/* @__PURE__ */ (0,q.jsx)($e,{itx:e,path:o,agents:a,opener:i.openers?.[o],presence:!!i.presence,call:i.call,share:i.call?i.share:void 0,me:r?.actor,tails:c,quiet:u,remembered:d})}),i.pageTools&&r?/* @__PURE__ */ (0,q.jsx)(Ze,{itx:e,path:o,me:r,agent:a?.find(e=>e.path===o)?.title||o.split(`/`).findLast(Boolean)||o,tools:i.pageTools===!0?void 0:i.pageTools.tools}):null]})}function Ze(e){let[t,n]=(0,V.useState)();return(0,V.useEffect)(()=>{Oe().then(n,e=>console.error({event:`page-tools.load-failed`,message:e instanceof Error?e.message:String(e)}))},[]),t?/* @__PURE__ */ (0,q.jsx)(t.PageTools,{...e,onOpen:I}):null}const Q=(0,V.createContext)(void 0);function $(e){return/* @__PURE__ */ (0,q.jsx)(ie,{...e,mind:(0,V.use)(Q)})}function Qe({path:e,agents:t,quiet:n,presence:r,call:i,share:a}){return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)($,{path:e,agents:t,presence:r,call:i,share:a}),/* @__PURE__ */ (0,q.jsx)(re,{strip:!1,quiet:n})]})}function $e({itx:e,path:t,agents:n,opener:r,presence:i,call:a,share:o,me:s,tails:c,quiet:l,remembered:u}){let{files:d,kinds:f}=Ne(e),p=(0,V.useMemo)(()=>f&&n&&et(t,n,f),[t,n,f]),[m,h]=(0,V.useState)(),g=m||u&&{view:u,mount:0},v=p&&!(g&&_(g.view,p))?{view:p,mount:(g?.mount??0)+1}:g;if(v!==m&&h(v),(0,V.useEffect)(()=>{p&&c&&c!==`pending`&&c.saveView(t,p)},[p,c,t]),!v)return(0,V.use)(d),/* @__PURE__ */ (0,q.jsx)(Qe,{path:t,agents:n,quiet:l,presence:i,call:!!a,share:!!o});let{view:y,mount:b}=v;return y.file?/* @__PURE__ */ (0,q.jsx)(at,{itx:e,path:t,file:y.file,agents:n,presence:i,call:!!a,share:!!o,me:s,tails:c},b):/* @__PURE__ */ (0,q.jsx)(nt,{itx:e,path:t,kind:y.kind,agents:n,opener:r,presence:i,call:a,share:o,me:s,tails:c},b)}function et(e,t,n){let r=t.find(t=>t.path===e)?.kind||void 0,i=r&&r!==`iterate`?n.find(e=>e.kind===r):void 0;return{kind:r,file:i&&{name:i.name,source:i.source}}}const tt=u([c({type:s(`events.iterate.com/agent/message-received`)}),c({type:s(`events.iterate.com/agent/context-added`),payload:c({role:p().refine(e=>e!==`system`),llmRequestPolicy:c({behaviour:p().refine(e=>e!==`dont-trigger-request`)}).optional()})})]);function nt({itx:e,path:t,kind:n,agents:i,opener:a,presence:o,call:s,share:c,me:l,tails:u}){let d=s&&ke(),{AgentChat:f}=(0,V.use)(De()),p=d&&(0,V.use)(d),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(null),{view:v,patchView:y}=R(),b=L(`call`)===`join`,[S,C]=(0,V.useState)(null),w=r(e),T=x(w,()=>e.cd(t),[e,t]),E=ee({held:T,options:f.contextOptions,path:t,session:w,tails:u}),D=Ee.safeParse(v).data||{},O=D.view||!n||n===`iterate`?D:{...D,view:`events`},{stub:k}=T,A=(0,V.useCallback)(t=>ge(e,t),[e]),j=!E.savedCopy&&E.caughtUp&&E.older.exhausted&&!E.events.some(e=>tt.safeParse(e).success),M=E.liveState.call?.value,N=(0,V.useCallback)(()=>s.enable(e,t),[s,e,t]),P=(0,V.useMemo)(()=>K(e,t),[e,t]),F=(0,V.useMemo)(()=>p&&p.inCallOf(M),[p,M]);return(0,V.useEffect)(()=>{a&&k&&j&&k.append({type:`events.iterate.com/agent/context-added`,idempotencyKey:`opener:${t}`,payload:{role:`developer`,content:a}}).catch(()=>{})},[a,k,j,t]),/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)($,{path:t,agents:i,tabs:{view:O.view,hasChat:!0,held:E.caughtUp||E.events.length?ae(E.events):void 0,wholeLogHeld:E.older.exhausted,onStateChange:y},presence:o,aside:C,call:!!s,callIn:h,share:!!c,shareIn:_}),s&&c&&p?/* @__PURE__ */ (0,q.jsx)(p.AgentShare,{share:c,itx:e,path:t,title:i?.find(e=>e.path===t)?.title||t.split(`/`).at(-1)||t,pageUrl:new URL(B(t),location.href).href,context:E,enable:N,shareIn:g}):null,s&&p?/* @__PURE__ */ (0,q.jsx)(p.AgentCall,{stub:k,context:E,enable:()=>s.enable(e,t),barIn:m,joinOnArrival:b,arrived:rt}):null,/* @__PURE__ */ (0,q.jsx)(f,{path:t,context:E,error:T.error,state:O,onStateChange:y,tabsInHeader:!0,asideIn:S,onMessage:async({message:n,files:r,key:i})=>{await G(e,t,{message:n,files:r},i)},onAppend:k?e=>U(k,e):void 0,signedUrl:A,me:l,presence:o,inCall:F,mind:(0,V.use)(Q),widgetCalls:P})]})}function rt(){I(oe({call:void 0}),!0)}function it(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributeFilter:[`class`]}),()=>t.disconnect()}function at({itx:e,path:t,file:n,agents:i,presence:o,call:s,share:c,me:l,tails:u}){let{view:d,patchView:f}=R(),p=r(e),m=x(p,()=>e.cd(t),[e,t]),{link:h,loaded:g}=T(n.name,n.source),_=(0,V.useMemo)(()=>ot(g),[g]),v=(0,V.useMemo)(()=>({consumes:[`*`,..._.ephemeralEvents]}),[_.ephemeralEvents]),y=ee({held:{stub:g?m.stub:void 0,error:m.error},options:v,path:t,session:p,tails:u}),b=(0,V.useSyncExternalStore)(it,()=>document.documentElement.className,()=>``),{loading:S,exhausted:C}=y.older,E=(0,V.useMemo)(()=>C?null:{loading:S,exhausted:C},[S,C]),{stub:D}=m,O=m.error||_.error,k=(!g||!y.caughtUp&&y.events.length===0)&&!y.error&&!O,A={path:t,events:y.events,caughtUp:y.caughtUp,error:y.error,head:y.head,older:E,processors:y.processors,presence:y.presence,liveState:y.liveState,version:a(y),hostError:O,state:Ee.loose().safeParse(d).data||{},documentClass:b,tabsInHeader:!0,...l&&{me:l},presenceOn:o},j=A.state,M=st({itx:e,path:t,stub:D,setState:f,loadOlder:y.older.loadOlder,facts:y.events}),{hasChat:N}=_;return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)($,{path:t,agents:i,tabs:{view:N?j.view:`events`,hasChat:N,held:g&&!k?ae(y.events):void 0,wholeLogHeld:y.older.exhausted,onStateChange:f},presence:!1,call:s,share:c}),/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[/* @__PURE__ */ (0,q.jsx)(w,{link:h,frameScript:Fe(),inputs:A,verbs:M}),k?/* @__PURE__ */ (0,q.jsx)(`div`,{className:`absolute inset-0 bg-background`,children:/* @__PURE__ */ (0,q.jsx)(re,{strip:!1,quiet:y.events.length>0})}):null]})]})}function ot(e){return e?`ephemeralEvents`in e?{ephemeralEvents:e.ephemeralEvents,error:void 0,hasChat:!0}:{ephemeralEvents:[],error:`error`in e?e.error:void 0,hasChat:!1}:{ephemeralEvents:[],error:void 0,hasChat:!0}}function st({itx:e,path:t,stub:n,setState:r,loadOlder:i,facts:a}){return{message:({message:n,files:r,key:i})=>G(e,t,{message:n,files:r},i),append:async e=>{if(!n)throw Error(`not connected`);if(e.some(k))throw Error(`A view appends no widget that names contexts to read.`);await U(n,e)},fileUrl:async n=>{if(!n.startsWith(`${t}/`))throw Error(`${n} is not a file of ${t}`);return ge(e,n)},storeFiles:(n,r)=>_e(e,t,n,r),callTool:n=>K(e,t).callTool(n),readResource:n=>K(e,t).readResource(n),readContext:async n=>{let{readContext:r}=K(e,t);if(!r)throw Error(`This page reads no context for a widget.`);if(!A(a,t,n.key,n.context))throw Error(`No widget ${n.key} of ${t} names the context ${n.context}.`);return await r(n)},setState:r,loadOlder:i}}function ct(e){let[t,n]=(0,V.useState)(()=>Date.now());return(0,V.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}export{Re as DashAgents,Le as DashHome}; +import{r as e}from"../chunks/rolldown-runtime.mjs";import{a as t,n}from"../chunks/vendor-react";import{itxSessionOf as r,keptRead as i,versionOf as a}from"../lib/itx-session";import{_ as o,d as s,f as c,h as l,i as u,l as d,p as f,r as p,t as m,u as h,v as g}from"../chunks/vendor-zod";import{sameView as _,savedLogTails as v}from"../lib/saved-log-tail";import{t as y}from"../chunks/react.mjs";import{useHasSavedTail as b,useSavedContext as ee}from"../lib/saved-context";import{t as x}from"../chunks/use-itx-session.mjs";import{d as S,y as C}from"../chunks/vendor-icons";import{n as w,o as T,r as E,t as D}from"../chunks/host.mjs";import{WIDGET_FACT as O,asksToReadContext as k,widgetNamesContext as A}from"../components/widget/widget";import{r as j}from"../chunks/agent-facts.mjs";import{f as M,l as N,n as P,o as F,s as te}from"../chunks/agent-summary.mjs";import{t as ne}from"../chunks/context-view-search.mjs";import{t as re}from"../chunks/agent-reading.mjs";import{AgentPageHeader as ie,heldRowsOf as ae}from"../components/agent-chat/agent-page-header";import{go as I,hrefOf as oe,linkTo as se,pageHref as ce,usePageParam as L,useView as R}from"../lib/page-url";import{a as z,f as le,l as ue,p as B}from"../chunks/dash.mjs";var V=/* @__PURE__ */ e(t(),1);const de=e=>{let t=t=>e.some(e=>e.match===`itx.${t}`&&e.target===`itx.builtins.${t}`);return!(t(`run`)&&t(`cd`))},fe=h({name:l(),_meta:h({ui:h({visibility:p(l()).optional()}).optional()}).optional()}),pe=h({isError:u().optional()});function me({path:e,open:t,append:n,now:r=Date.now,rules:i,readEvents:a}){let o=/* @__PURE__ */ new Map,s=(e,n)=>{let r=JSON.stringify([e,n||{}]),i=o.get(r);return i||(i={connection:t(e,n)},o.set(r,i),i.connection.catch(()=>o.delete(r))),i},c=t=>{if(t!==e)throw Error(`A widget of ${e} cannot call as ${t}.`)};return{async callTool({path:e,key:t,server:i,headers:a,name:o,args:l}){c(e);let u=s(i,a),d=await u.connection,f=()=>{let e=d.listTools().then(e=>e.flatMap(e=>fe.safeParse(e).data??[])),t={listed:e,at:r()};return u.tools=t,e.catch(()=>{u.tools===t&&(u.tools=void 0)}),e},p=u.tools&&r()-u.tools.at<3e4,m=async e=>(await e).find(e=>e.name===o),h=await m(p&&u.tools?u.tools.listed:f())??(p?await m(f()):void 0);if(!h)throw Error(`${o} is not a tool of ${i}.`);let g=h._meta?.ui?.visibility;if(g&&!g.includes(`app`))throw Error(`${o} is not a tool for the app: its visibility is ${g.join(`, `)}.`);let _=performance.now(),v=(e,r)=>n([{type:O.toolCalled,payload:{key:t,server:i,tool:o,ok:e,ms:Math.round(performance.now()-_),error:r}}]).catch(()=>void 0);try{let e=await d.callToolResult(o,l);return v(pe.safeParse(e).data?.isError!==!0),e}catch(e){throw v(!1,(e instanceof Error?e.message:String(e)).slice(0,500)),e}},async readResource({path:e,server:t,headers:n,uri:r}){return c(e),await(await s(t,n).connection).readResource(r)},...i&&a&&{async readContext({path:t,context:n,after:r,limit:o}){if(c(t),de(await i()))throw Error(`The agent at ${e} is jailed: its widget reads no context of the mind.`);let s=(e,t,n)=>Number.isFinite(e)?Math.min(Math.max(Math.floor(e),t),n):t;return await a(n,s(r,0,2**53-1),s(o,1,500))}}}}const H=e=>e,he=p(h({type:l(),payload:f(l(),g()).optional()}));async function U(e,t){await e.append(...he.parse(t))}async function W(e,t,n){let r=await e.cd(t);try{await U(r,n)}finally{r[Symbol.dispose]()}}async function G(e,t,n,r){let i=H(e).agents.get(t);try{await(r?i.message(n,{key:r}):i.message(n))}finally{i[Symbol.dispose]()}}async function ge(e,t){let n=e.files.get(t);try{return(await n.url()).url}finally{n[Symbol.dispose]()}}async function _e(e,t,n,r){let i=[];for(let[a,o]of n.entries()){let n=o.filename.replace(/[^A-Za-z0-9._-]+/g,`-`),s=r?(await ve(`${r}\n${String(a)}\n${o.contentType}\n${await ve(o.data)}`)).slice(0,16):crypto.randomUUID().slice(0,8),c=e.files.get(`${t}/${s}-${n}`);try{let e=await c.put({contentType:o.contentType,data:o.data});i.push({contentType:e.contentType,filename:o.filename,path:e.path,size:e.size})}finally{c[Symbol.dispose]()}}return i}async function ve(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e));return Array.from(new Uint8Array(t),e=>e.toString(16).padStart(2,`0`)).join(``)}const ye=/* @__PURE__ */ new WeakMap;function K(e,t){let n=ye.get(e);n||ye.set(e,n=/* @__PURE__ */ new Map);let r=n.get(t);if(!r){let i,a=()=>(i||=Promise.resolve(e.cd(t)),i.catch(()=>i=void 0),i);r=me({path:t,open:async(e,t)=>await(await a()).connectToMcp(e,{headers:t}),append:async e=>await U(await a(),e),rules:async()=>(await(await a()).rewriteRules.list(0)).map(({match:e,target:t})=>({match:e,target:t})),readEvents:async(e,t,n)=>{let r=await(await a()).cd(e);try{return await r.readEvents(t,n)}finally{r[Symbol.dispose]()}}}),n.set(t,r)}return r}const be=/\bdefault\s*:\s*true\b/;function xe(e){return e.filter(e=>e.source&&be.test(e.source)).toSorted((e,t)=>e.kind.localeCompare(t.kind))}async function Se(e,t=15e3){for(let n of e){let e=await Ce(n,t),r=e&&`ephemeralEvents`in e?e.newAgent:void 0;if(r?.default&&r.choices.length>0)return{starter:n,newAgent:r}}return null}function Ce(e,t){let n=e.loaded();return n?Promise.resolve(n):new Promise(n=>{let r=setTimeout(()=>{i(),n(void 0)},t),i=e.subscribe(()=>{let t=e.loaded();t&&(clearTimeout(r),i(),n(t))})})}function we(e,t,n){let[r]=e.newAgent.choices,i=N(e.starter.file.kind,n,r.byPerson?t:void 0),a=Object.fromEntries((e.newAgent.fields||[]).filter(e=>!e.choices||e.choices.includes(r.id)).map(e=>[e.name,e.type===`select`&&e.options&&!e.options.includes(e.defaultValue)?e.options[0]??``:e.defaultValue]));return{choice:r.id,fields:a,path:i}}async function Te(e,t,n){let r=t.files.length>0?await n.storeFiles(e,t.files):[];await n.append(e,[j({message:t.message,files:r})])}const Ee=ne.extend({view:m([`chat`,`events`]).optional().catch(void 0),llmRequest:s().int().positive().optional().catch(void 0),scriptRun:s().int().positive().optional().catch(void 0)});var q=/* @__PURE__ */ e(n(),1);function J(e){let t;return()=>t||=e()}const Y=J(()=>import(`../components/agents-home`)),De=J(()=>import(`../components/agent-chat/agent-chat`)),Oe=J(()=>import(`../components/page-tools`)),ke=J(async()=>{let e=import(`../chunks/call-presence.mjs`),t=import(`../chunks/dash-share.mjs`),{AgentCall:n}=await import(`../chunks/dash-call.mjs`),{inCallOf:r}=await e,{AgentShare:i}=await t;return{AgentCall:n,AgentShare:i,inCallOf:r}}),Ae=f(l(),l()),X=/* @__PURE__ */ new WeakMap,je=/* @__PURE__ */ new WeakMap;function Me(e){let t=i(e,X.get(e),t=>(async()=>{let n=()=>(t(),null),r=await Promise.resolve(e.kv.get(`agent-kinds`)).catch(n),i={};try{i=Ae.safeParse(JSON.parse(r||`{}`)).data||{}}catch{}let a=e.repos.get(`/repos/config`);return await Promise.all(Object.entries(i).map(async([e,t])=>({kind:e,name:t,source:await Promise.resolve(a.readFile(t)).then(e=>e||null,n)})))})());return t!==X.get(e)&&t.answer.then(e=>void je.set(t.answer,e),()=>{}),X.set(e,t),t.answer}function Ne(e){let t=Me(e),n=(0,V.useCallback)(e=>{let n=!0;return t.then(()=>{n&&e()},()=>{}),()=>{n=!1}},[t]);return{files:t,kinds:(0,V.useSyncExternalStore)(n,()=>je.get(t))}}let Pe;function Fe(){return Pe||=`${Ie.safeParse(JSON.parse(document.querySelector(`script[type="importmap"]`)?.textContent||`{}`)).data?.imports[`@iterate-com/ui/`]||`/`}dist/agent-kind-view-frame.js?raw`,Pe}const Ie=c({imports:f(l(),l())});function Le({itx:e,mind:t,principal:n,pages:r,agents:i,waiting:a}){let{RecentAgents:o}=(0,V.use)(Y()),s=Be(r);return/* @__PURE__ */ (0,q.jsx)(ue,{children:/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-8 px-4 pt-8 pb-12 md:px-8 md:pt-16`,children:[/* @__PURE__ */ (0,q.jsx)(Ve,{itx:e,principal:n,links:s}),/* @__PURE__ */ (0,q.jsx)(We,{itx:e,mind:t,pages:r,waiting:a}),i?/* @__PURE__ */ (0,q.jsx)(o,{agents:i,...s}):/* @__PURE__ */ (0,q.jsx)(z,{waiting:!0,children:`Reading the agents…`})]})})}Le.staysOverReconnect=!0;function Re(e){let t=L(`agent`);return t?/* @__PURE__ */ (0,q.jsx)(Xe,{...e,path:t},t):/* @__PURE__ */ (0,q.jsx)(ze,{...e})}Re.staysOverReconnect=!0;function ze({itx:e,principal:t,pages:n,agents:r}){let{AllAgents:i}=(0,V.use)(Y()),a=Be(n),o=ct(5e3),s=(0,V.useMemo)(()=>r&&te(r,``).length,[r]),c=(0,V.useMemo)(()=>r&&P(r),[r]);return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-6 px-4 pt-8 md:px-8`,children:[/* @__PURE__ */ (0,q.jsxs)(`header`,{className:`flex items-baseline justify-between gap-3`,children:[/* @__PURE__ */ (0,q.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Agents`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`text-sm text-muted-foreground tabular-nums`,children:s===void 0?``:`${s.toLocaleString(`en`)} ${s===1?`agent`:`agents`}`})]}),/* @__PURE__ */ (0,q.jsx)(Ve,{itx:e,principal:t,links:a}),/* @__PURE__ */ (0,q.jsx)(`h2`,{className:`text-sm font-medium text-muted-foreground`,children:`Most recently active`})]}),!r||!c?/* @__PURE__ */ (0,q.jsx)(z,{waiting:!0,children:`Reading the agents…`}):c.length?/* @__PURE__ */ (0,q.jsx)(i,{agents:r,nowMs:o,className:`pb-8`,...a}):/* @__PURE__ */ (0,q.jsx)(`p`,{className:`mx-auto w-full max-w-3xl px-4 font-readme text-sm text-muted-foreground md:px-8`,children:`No agents yet. Say something above to start one.`})]})}function Be(e){let t=e.find(e=>e.id===`agents`)?.id;return(0,V.useMemo)(()=>{let e=e=>e?B(e):ce(t);return{agentHref:e,onOpen:t=>I(e(t))}},[t])}function Ve({itx:e,principal:t,links:n}){let{NewAgentComposer:r}=(0,V.use)(Y()),{frames:i,resolve:a,chosen:o}=He(e),[s]=(0,V.useState)(()=>F(globalThis.location?.hash));return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[i,/* @__PURE__ */ (0,q.jsx)(r,{initialDraft:s,person:t===void 0?async()=>M((await e.whoami()).principal?.email):M(t?.email),pathFor:async(e,t)=>{let n=await a();if(!n)return N(`web`,t,e);let r=we(n,e,t);return o.set(r.path,{found:n,start:r}),r.path},onCreate:async t=>{let n=o.get(t);if(!n)return await H(e).agents.create(t);await W(e,t,await n.found.starter.start(n.start))},onMessage:(t,{message:n,files:r})=>o.has(t)?Te(t,{message:n,files:r},{storeFiles:(t,n)=>_e(e,t,n),append:(t,n)=>W(e,t,n)}):G(e,t,{message:n,files:r}),...n})]})}function He(e){let{files:t,kinds:n}=Ne(e),[r]=(0,V.useState)(()=>/* @__PURE__ */ new Map),[i]=(0,V.useState)(()=>/* @__PURE__ */ new Map),a=(0,V.useCallback)(e=>{let t=`${e.name}\n${e.source||``}`,n=r.get(t);if(n)return n;let i=new E(e.name,e.source);return r.set(t,i),i},[r]);return{frames:(0,V.useMemo)(()=>xe(n||[]),[n]).map(e=>/* @__PURE__ */ (0,q.jsx)(D,{link:a(e),frameScript:Fe()},e.name)),resolve:(0,V.useCallback)(async()=>Se(xe(await t.catch(()=>[])).map(e=>Ue(e,a(e)))),[t,a]),chosen:i}}function Ue(e,t){return{file:e,loaded:t.loaded,subscribe:t.subscribe,start:e=>t.start(e)}}function We({itx:e,mind:t,pages:n,waiting:r}){let[i]=(0,V.useState)(()=>Ye(e)),a=n.find(e=>e.id===`integrations`);return/* @__PURE__ */ (0,q.jsxs)(`section`,{"aria-labelledby":`needs-you`,className:`flex min-h-22 flex-col gap-3`,children:[/* @__PURE__ */ (0,q.jsx)(`h2`,{id:`needs-you`,className:`text-sm font-medium text-muted-foreground`,children:`Waiting for you`}),/* @__PURE__ */ (0,q.jsx)(V.Suspense,{fallback:/* @__PURE__ */ (0,q.jsx)(Ge,{}),children:/* @__PURE__ */ (0,q.jsx)(Ke,{integrations:i,approvals:r,approvalsHref:`https://${t}/secrets/approvals`,integrationsHref:a&&ce(a.id)})})]})}function Ge(){return/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Looking…`})}function Ke({integrations:e,approvals:t,approvalsHref:n,integrationsHref:r}){let i=(0,V.use)(e);return t===void 0?/* @__PURE__ */ (0,q.jsx)(Ge,{}):!t&&!i.length?/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Nothing waits for you.`}):/* @__PURE__ */ (0,q.jsxs)(`ul`,{className:`flex flex-col gap-2`,children:[t?/* @__PURE__ */ (0,q.jsx)(Z,{href:n,icon:/* @__PURE__ */ (0,q.jsx)(C,{"aria-hidden":!0,className:`size-4 shrink-0 text-warning`}),title:t===1?`1 request waits for your yes`:`${String(t)} requests wait for your yes`,text:`Your agents wait until you answer.`}):null,i.map(e=>/* @__PURE__ */ (0,q.jsx)(Z,{href:r,inPage:!0,icon:/* @__PURE__ */ (0,q.jsx)(S,{"aria-hidden":!0,className:e.kind===`error`?`size-4 shrink-0 text-destructive`:`size-4 shrink-0 text-warning`}),title:e.title,text:e.text},e.key))]})}function Z({href:e,inPage:t,icon:n,title:r,text:i}){let a=/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[n,/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[/* @__PURE__ */ (0,q.jsx)(`span`,{className:`truncate text-sm font-medium`,children:r}),i?/* @__PURE__ */ (0,q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:i}):null]})]}),o=`flex items-center gap-3 rounded-lg border px-3 py-2`;return/* @__PURE__ */ (0,q.jsx)(`li`,{children:e?/* @__PURE__ */ (0,q.jsx)(`a`,{...t?se(e):{href:e},className:`${o} text-inherit no-underline hover:bg-muted/60`,children:a}):/* @__PURE__ */ (0,q.jsx)(`div`,{className:o,children:a})})}const qe=c({kind:m([`ok`,`attention`,`error`]),text:l().optional()}),Je=c({integrations:f(l(),h({title:l(),status:qe.optional()})).catch({}).default({}),connections:f(l(),h({account:l(),status:qe.optional()})).catch({}).default({})});async function Ye(e){try{if(!await le(e,`integrations`))return[];let t=await e.cd(`/integrations`),n;try{n=(await y(t,`integration`)).state}finally{t[Symbol.dispose]()}let{integrations:r,connections:i}=Je.parse(n),a=Object.entries(r).flatMap(([e,t])=>t.status&&t.status.kind!==`ok`?[{key:e,title:t.title,text:t.status.text,kind:t.status.kind}]:[]),o=Object.entries(i).flatMap(([e,t])=>{let n=r[e.split(`/`)[0]];return t.status&&t.status.kind!==`ok`?[{key:e,title:`${n?.title||e.split(`/`)[0]}: ${t.account}`,text:t.status.text,kind:t.status.kind}]:[]});return[...a,...o]}catch{return[]}}function Xe({itx:e,mind:t,mindFace:n,principal:r,page:i,agents:a,path:o}){let s=(0,V.useMemo)(()=>n||{name:t},[n,t]),c=r===void 0?`pending`:r?.actor?v({mind:t,actor:r.actor}):void 0,l=b(c,o),u=l!==!1,d=l&&c&&c!==`pending`?c.peek(o)?.view:void 0;return/* @__PURE__ */ (0,q.jsxs)(Q,{value:s,children:[/* @__PURE__ */ (0,q.jsx)(V.Suspense,{fallback:/* @__PURE__ */ (0,q.jsx)(Qe,{path:o,agents:a,quiet:u,presence:!!i.presence,call:!!i.call,share:!!(i.call&&i.share)}),children:/* @__PURE__ */ (0,q.jsx)($e,{itx:e,path:o,agents:a,opener:i.openers?.[o],presence:!!i.presence,call:i.call,share:i.call?i.share:void 0,me:r?.actor,tails:c,quiet:u,remembered:d})}),i.pageTools&&r?/* @__PURE__ */ (0,q.jsx)(Ze,{itx:e,path:o,me:r,agent:a?.find(e=>e.path===o)?.title||o.split(`/`).findLast(Boolean)||o,tools:i.pageTools===!0?void 0:i.pageTools.tools}):null]})}function Ze(e){let[t,n]=(0,V.useState)();return(0,V.useEffect)(()=>{Oe().then(n,e=>console.error({event:`page-tools.load-failed`,message:e instanceof Error?e.message:String(e)}))},[]),t?/* @__PURE__ */ (0,q.jsx)(t.PageTools,{...e,onOpen:I}):null}const Q=(0,V.createContext)(void 0);function $(e){return/* @__PURE__ */ (0,q.jsx)(ie,{...e,mind:(0,V.use)(Q)})}function Qe({path:e,agents:t,quiet:n,presence:r,call:i,share:a}){return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)($,{path:e,agents:t,presence:r,call:i,share:a}),/* @__PURE__ */ (0,q.jsx)(re,{strip:!1,quiet:n})]})}function $e({itx:e,path:t,agents:n,opener:r,presence:i,call:a,share:o,me:s,tails:c,quiet:l,remembered:u}){let{files:d,kinds:f}=Ne(e),p=(0,V.useMemo)(()=>f&&n&&et(t,n,f),[t,n,f]),[m,h]=(0,V.useState)(),g=m||u&&{view:u,mount:0},v=p&&!(g&&_(g.view,p))?{view:p,mount:(g?.mount??0)+1}:g;if(v!==m&&h(v),(0,V.useEffect)(()=>{p&&c&&c!==`pending`&&c.saveView(t,p)},[p,c,t]),!v)return(0,V.use)(d),/* @__PURE__ */ (0,q.jsx)(Qe,{path:t,agents:n,quiet:l,presence:i,call:!!a,share:!!o});let{view:y,mount:b}=v;return y.file?/* @__PURE__ */ (0,q.jsx)(at,{itx:e,path:t,file:y.file,agents:n,presence:i,call:!!a,share:!!o,me:s,tails:c},b):/* @__PURE__ */ (0,q.jsx)(nt,{itx:e,path:t,kind:y.kind,agents:n,opener:r,presence:i,call:a,share:o,me:s,tails:c},b)}function et(e,t,n){let r=t.find(t=>t.path===e)?.kind||void 0,i=r&&r!==`iterate`?n.find(e=>e.kind===r):void 0;return{kind:r,file:i&&{name:i.name,source:i.source}}}const tt=o([c({type:d(`events.iterate.com/agent/message-received`)}),c({type:d(`events.iterate.com/agent/context-added`),payload:c({role:l().refine(e=>e!==`system`),llmRequestPolicy:c({behaviour:l().refine(e=>e!==`dont-trigger-request`)}).optional()})})]);function nt({itx:e,path:t,kind:n,agents:i,opener:a,presence:o,call:s,share:c,me:l,tails:u}){let d=s&&ke(),{AgentChat:f}=(0,V.use)(De()),p=d&&(0,V.use)(d),[m,h]=(0,V.useState)(null),[g,_]=(0,V.useState)(null),{view:v,patchView:y}=R(),b=L(`call`)===`join`,[S,C]=(0,V.useState)(null),w=r(e),T=x(w,()=>e.cd(t),[e,t]),E=ee({held:T,options:f.contextOptions,path:t,session:w,tails:u}),D=Ee.safeParse(v).data||{},O=D.view||!n||n===`iterate`?D:{...D,view:`events`},{stub:k}=T,A=(0,V.useCallback)(t=>ge(e,t),[e]),j=!E.savedCopy&&E.caughtUp&&E.older.exhausted&&!E.events.some(e=>tt.safeParse(e).success),M=E.liveState.call?.value,N=(0,V.useCallback)(()=>s.enable(e,t),[s,e,t]),P=(0,V.useMemo)(()=>K(e,t),[e,t]),F=(0,V.useMemo)(()=>p&&p.inCallOf(M),[p,M]);return(0,V.useEffect)(()=>{a&&k&&j&&k.append({type:`events.iterate.com/agent/context-added`,idempotencyKey:`opener:${t}`,payload:{role:`developer`,content:a}}).catch(()=>{})},[a,k,j,t]),/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)($,{path:t,agents:i,tabs:{view:O.view,hasChat:!0,held:E.caughtUp||E.events.length?ae(E.events):void 0,wholeLogHeld:E.older.exhausted,onStateChange:y},presence:o,aside:C,call:!!s,callIn:h,share:!!c,shareIn:_}),s&&c&&p?/* @__PURE__ */ (0,q.jsx)(p.AgentShare,{share:c,itx:e,path:t,title:i?.find(e=>e.path===t)?.title||t.split(`/`).at(-1)||t,pageUrl:new URL(B(t),location.href).href,context:E,enable:N,shareIn:g}):null,s&&p?/* @__PURE__ */ (0,q.jsx)(p.AgentCall,{stub:k,context:E,enable:()=>s.enable(e,t),barIn:m,joinOnArrival:b,arrived:rt}):null,/* @__PURE__ */ (0,q.jsx)(f,{path:t,context:E,error:T.error,state:O,onStateChange:y,tabsInHeader:!0,asideIn:S,onMessage:async({message:n,files:r,key:i})=>{await G(e,t,{message:n,files:r},i)},onAppend:k?e=>U(k,e):void 0,signedUrl:A,me:l,presence:o,inCall:F,mind:(0,V.use)(Q),widgetCalls:P})]})}function rt(){I(oe({call:void 0}),!0)}function it(e){let t=new MutationObserver(e);return t.observe(document.documentElement,{attributeFilter:[`class`]}),()=>t.disconnect()}function at({itx:e,path:t,file:n,agents:i,presence:o,call:s,share:c,me:l,tails:u}){let{view:d,patchView:f}=R(),p=r(e),m=x(p,()=>e.cd(t),[e,t]),{link:h,loaded:g}=T(n.name,n.source),_=(0,V.useMemo)(()=>ot(g),[g]),v=(0,V.useMemo)(()=>({consumes:[`*`,..._.ephemeralEvents]}),[_.ephemeralEvents]),y=ee({held:{stub:g?m.stub:void 0,error:m.error},options:v,path:t,session:p,tails:u}),b=(0,V.useSyncExternalStore)(it,()=>document.documentElement.className,()=>``),{loading:S,exhausted:C}=y.older,E=(0,V.useMemo)(()=>C?null:{loading:S,exhausted:C},[S,C]),{stub:D}=m,O=m.error||_.error,k=(!g||!y.caughtUp&&y.events.length===0)&&!y.error&&!O,A={path:t,events:y.events,caughtUp:y.caughtUp,error:y.error,head:y.head,older:E,processors:y.processors,presence:y.presence,liveState:y.liveState,version:a(y),hostError:O,state:Ee.loose().safeParse(d).data||{},documentClass:b,tabsInHeader:!0,...l&&{me:l},presenceOn:o},j=A.state,M=st({itx:e,path:t,stub:D,setState:f,loadOlder:y.older.loadOlder,facts:y.events}),{hasChat:N}=_;return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)($,{path:t,agents:i,tabs:{view:N?j.view:`events`,hasChat:N,held:g&&!k?ae(y.events):void 0,wholeLogHeld:y.older.exhausted,onStateChange:f},presence:!1,call:s,share:c}),/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 flex-col`,children:[/* @__PURE__ */ (0,q.jsx)(w,{link:h,frameScript:Fe(),inputs:A,verbs:M}),k?/* @__PURE__ */ (0,q.jsx)(`div`,{className:`absolute inset-0 bg-background`,children:/* @__PURE__ */ (0,q.jsx)(re,{strip:!1,quiet:y.events.length>0})}):null]})]})}function ot(e){return e?`ephemeralEvents`in e?{ephemeralEvents:e.ephemeralEvents,error:void 0,hasChat:!0}:{ephemeralEvents:[],error:`error`in e?e.error:void 0,hasChat:!1}:{ephemeralEvents:[],error:void 0,hasChat:!0}}function st({itx:e,path:t,stub:n,setState:r,loadOlder:i,facts:a}){return{message:({message:n,files:r,key:i})=>G(e,t,{message:n,files:r},i),append:async e=>{if(!n)throw Error(`not connected`);if(e.some(k))throw Error(`A view appends no widget that names contexts to read.`);await U(n,e)},fileUrl:async n=>{if(!n.startsWith(`${t}/`))throw Error(`${n} is not a file of ${t}`);return ge(e,n)},storeFiles:(n,r)=>_e(e,t,n,r),callTool:n=>K(e,t).callTool(n),readResource:n=>K(e,t).readResource(n),readContext:async n=>{let{readContext:r}=K(e,t);if(!r)throw Error(`This page reads no context for a widget.`);if(!A(a,t,n.key,n.context))throw Error(`No widget ${n.key} of ${t} names the context ${n.context}.`);return await r(n)},setState:r,loadOlder:i}}function ct(e){let[t,n]=(0,V.useState)(()=>Date.now());return(0,V.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}export{Re as DashAgents,Le as DashHome};
M dist/chunks/agent-chat.mjs
@@ -1,4 +1,4 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{versionOf as r}from"../lib/itx-session";import{_ as i,c as a,d as o,f as s,i as c,m as l,r as u,u as d}from"./vendor-zod";import{D as f,Ft as p,N as m,Ot as h,P as g,gt as _,nt as v,r as y,t as b,tt as x,vt as S,wt as C,zt as w}from"./vendor-icons";import{WIDGET_FACT as T,widgetAnswer as ee,widgetDocument as E,widgetFold as D,widgetHtmlMax as te,widgetInput as ne,widgetPolicy as re,widgetResult as O,widgetServerHost as ie,widgetThemeAt as ae}from"../components/widget/widget";import{i as k,n as A,o as j,s as oe,t as M}from"./agent-facts.mjs";import{r as N}from"./context-view-search.mjs";import{c as P,i as F}from"./ui-base";import{t as se}from"./agent-strip.mjs";import{Tabs as I,TabsContent as L,TabsList as R,TabsTrigger as z}from"../components/ui/tabs";import{Spinner as B}from"../components/ui/spinner";import{r as ce}from"./read-progress.mjs";import{n as le}from"./agent-reading.mjs";import{C as V,S as H,_ as ue,b as U,w as de,y as fe}from"./ui-shell";import{Face as pe}from"../components/call/face";import{n as me,r as he,t as ge}from"./principal-label.mjs";import{r as _e,t as ve}from"./presence-line.mjs";import{PRESENCE_EVENT_TYPES as ye,isPresenceEvent as be,usePresence as xe}from"../lib/presence";import{n as Se}from"./dist2.mjs";import{a as Ce,i as we,n as Te,o as Ee,r as De,t as Oe}from"./message.mjs";import{_ as ke,a as W,b as Ae,c as je,f as Me,g as Ne,h as Pe,i as Fe,l as Ie,m as G,n as Le,o as Re,p as ze,r as Be,s as Ve,t as He,u as Ue,v as We,y as Ge}from"./agent-events.mjs";import{n as Ke,t as qe}from"./composer.mjs";import{n as Je,r as Ye,t as Xe}from"./virtual-log.mjs";import{n as Ze}from"./context-view.mjs";import{t as Qe}from"./agent-shell.mjs";import{CodeBlock as K,SerializedObjectCodeBlock as $e}from"../components/code-block";import{Empty as et,EmptyDescription as tt,EmptyHeader as nt,EmptyTitle as rt}from"../components/ui/empty";var q=/* @__PURE__ */ e(t(),1);function it(e){let t=Date.now(),n=/* @__PURE__ */ new Set,r;function i(){r||n.size===0||(r=setInterval(()=>{t=Date.now();for(let e of n)e()},e))}function a(){!r||n.size>0||(clearInterval(r),r=void 0)}return{subscribe(e){return n.add(e),t=Date.now(),i(),queueMicrotask(()=>{n.has(e)&&e()}),()=>{n.delete(e),a()}},getSnapshot(){return t}}}const at=/* @__PURE__ */ new Map;function ot(e){let t=at.get(e);return t||(t=it(e),at.set(e,t)),t}const st=e=>typeof e==`number`?e:1/0;function ct(e,t=null){let n=ot(e),r=(0,q.useCallback)(()=>Math.min(n.getSnapshot(),st(t)),[n,t]),[i]=(0,q.useState)(Date.now),a=(0,q.useCallback)(()=>Math.min(i,st(t)),[i,t]),o=(0,q.useCallback)(e=>{let r=()=>typeof t==`number`&&n.getSnapshot()>=t,i=n.subscribe(()=>{e(),r()&&i()});return r()&&i(),i},[n,t]);return(0,q.useSyncExternalStore)(o,r,a)}var J=/* @__PURE__ */ e(n(),1);const lt=`grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-2`;function ut({principal:e,words:t,className:n,...r}){let i=me(e);return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:P(lt,`items-center font-readme text-2xs text-muted-foreground`,n),children:[/* @__PURE__ */ (0,J.jsx)(`span`,{className:`flex`,children:/* @__PURE__ */ (0,J.jsx)(pe,{small:!0,...ge(e),label:i})}),/* @__PURE__ */ (0,J.jsx)(`span`,{...r,title:i,className:`min-w-0 truncate`,children:t})]})}function dt({principal:e,name:t,first:n,children:r,className:i,...a}){return/* @__PURE__ */ (0,J.jsxs)(`div`,{...a,className:P(lt,`gap-y-1 pb-2`,n&&`pt-3.5`,i),children:[n?/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsx)(`span`,{"data-said-by":!0,"aria-hidden":`true`,title:me(e),className:`col-start-2 row-start-1 truncate font-readme text-2xs text-muted-foreground`,children:t}),/* @__PURE__ */ (0,J.jsx)(`span`,{"aria-hidden":`true`,className:`col-start-1 row-start-2 flex pt-3.5`,children:/* @__PURE__ */ (0,J.jsx)(pe,{small:!0,...ge(e)})})]}):null,/* @__PURE__ */ (0,J.jsx)(Oe,{from:`user`,side:`start`,className:P(`col-start-2`,n&&`row-start-2`),children:/* @__PURE__ */ (0,J.jsxs)(Te,{className:`group-[.is-user]:rounded-2xl`,children:[/* @__PURE__ */ (0,J.jsx)(ft,{children:me(e)}),r]})})]})}function ft({children:e}){return/* @__PURE__ */ (0,J.jsx)(`span`,{className:`sr-only`,children:`${e}:`})}function pt({typing:e,runOf:t}){let n=e.toSorted((e,n)=>Number(n.actor===t)-Number(e.actor===t));return/* @__PURE__ */ (0,J.jsxs)(`div`,{"data-typing-in-stream":!0,"aria-hidden":`true`,children:[n.slice(0,3).map(e=>/* @__PURE__ */ (0,J.jsx)(dt,{principal:e,name:he(e),first:e.actor!==t,children:/* @__PURE__ */ (0,J.jsxs)(`span`,{className:`flex h-6 items-center gap-1`,children:[/* @__PURE__ */ (0,J.jsx)(mt,{}),/* @__PURE__ */ (0,J.jsx)(mt,{className:`[animation-delay:150ms]`}),/* @__PURE__ */ (0,J.jsx)(mt,{className:`[animation-delay:300ms]`})]})},e.actor)),e.length>3?/* @__PURE__ */ (0,J.jsx)(`div`,{className:P(lt,`pb-2`),children:/* @__PURE__ */ (0,J.jsxs)(`span`,{"data-typing-more":!0,className:`text-center text-2xs text-muted-foreground`,children:[`+`,String(e.length-3)]})}):null]})}function mt({className:e}){return/* @__PURE__ */ (0,J.jsx)(`span`,{className:P(`size-1.5 rounded-full bg-muted-foreground motion-safe:animate-pulse`,e)})}function ht({text:e}){let[t,n]=(0,q.useState)();return/* @__PURE__ */ (0,J.jsxs)(`span`,{className:`mb-2 flex flex-wrap items-center gap-2 whitespace-normal font-sans text-xs not-italic text-muted-foreground`,children:[`Latest ~32K characters`,/* @__PURE__ */ (0,J.jsxs)(ue,{open:!!t,onOpenChange:t=>n(t?Ae(e):void 0),children:[/* @__PURE__ */ (0,J.jsx)(de,{render:/* @__PURE__ */ (0,J.jsx)(F,{variant:`outline`,size:`xs`}),children:`View full text`}),/* @__PURE__ */ (0,J.jsxs)(fe,{className:`data-[side=right]:w-full sm:max-w-3xl`,children:[/* @__PURE__ */ (0,J.jsxs)(H,{children:[/* @__PURE__ */ (0,J.jsx)(V,{children:`Available response text`}),/* @__PURE__ */ (0,J.jsx)(U,{children:`Captured when opened. Reopen for newer text.`})]}),/* @__PURE__ */ (0,J.jsxs)(F,{className:`mx-4 self-start`,variant:`outline`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(t||``).then(()=>Se.success(`Copied`),()=>Se.error(`Failed to copy to clipboard`))},children:[/* @__PURE__ */ (0,J.jsx)(_,{"data-icon":`inline-start`}),`Copy text`]}),/* @__PURE__ */ (0,J.jsx)(gt,{text:t||``})]})]})]})}const gt=(0,q.memo)(function({text:e}){return/* @__PURE__ */ (0,J.jsx)(`pre`,{className:`min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-words px-4 pb-4 text-sm`,children:e})}),Y=(0,q.memo)(function({text:e,animate:t=!1,literal:n=!1}){if(typeof e==`string`)return n?e:X(_t,e).text;let r=e.blockCount-1,i=Math.floor(r/32),a=Math.max(0,e.blockCount-32),o=n?{}:vt(e,a);return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[a>0?/* @__PURE__ */ (0,J.jsx)(ht,{text:e}):null,Object.entries(e.groups).map(([s,c])=>{if(Number(s)<Math.floor(a/32))return null;let l=o[Number(s)]??_t;return/* @__PURE__ */ (0,J.jsx)(bt,{blocks:c,firstBlock:Number(s)===Math.floor(a/32)?a:0,tailBlock:t&&Number(s)===i?r:null,tailOffset:t&&Number(s)===i?e.tailOffset:0,carry:l.carry,fence:l.fence,tick:l.tick,lineStart:l.lineStart,literal:n},s)})]})}),_t={fence:``,tick:0,lineStart:!0,carry:``};function vt(e,t){let n={},r=_t;for(let i=Math.max(0,t-1);i<e.blockCount;i++)(i%32==0||i===t)&&(n[Math.floor(i/32)]=r),r=X(r,e.groups[Math.floor(i/32)][i]).next;return n}function X(e,t){let n=e.carry+t,r=/[`~]+$/.exec(n)?.[0]||``,{parts:i,end:a}=yt(e,n.slice(0,n.length-r.length)),o=r,s=i.at(-1);if(!r&&s&&!s.code){let e=Ee(s.text);e.endsWith(`[`)&&(e=e.slice(0,-1)),o=s.text.slice(e.length),s.text=e}return{text:i.map(e=>e.code?e.text:Ce(e.text)).join(``),next:{...a,carry:o}}}function yt(e,t){let{fence:n,tick:r,lineStart:i}=e,a=[],o=0,s=!!n||r>0,c=(e,n)=>{e>o&&a.push({code:s,text:t.slice(o,e)}),o=e,s=n},l=0;for(;l<t.length;){let e=t[l];if(e==="`"||e===`~`){let a=l;for(;t[a]===e;)a++;let o=a-l;n?i&&e===n[0]&&o>=n.length&&(n=``,c(a,!1)):r?e==="`"&&o===r&&(r=0,c(a,!1)):i&&o>=3?(c(l,!0),n=e.repeat(o)):e==="`"&&(c(l,!0),r=o),l=a,i=!1;continue}r&&e===` +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{versionOf as r}from"../lib/itx-session";import{d as i,f as a,h as o,i as s,l as c,p as l,r as u,v as d}from"./vendor-zod";import{Bt as f,D as p,It as m,N as h,P as g,Tt as _,_t as v,kt as y,nt as b,r as x,rt as S,t as ee,yt as C}from"./vendor-icons";import{WIDGET_FACT as w,widgetAnswer as te,widgetDocument as T,widgetFold as E,widgetHtmlMax as ne,widgetInput as re,widgetPolicy as ie,widgetResult as D,widgetServerHost as ae,widgetThemeAt as oe}from"../components/widget/widget";import{i as O,n as k,o as A,s as se,t as j}from"./agent-facts.mjs";import{r as M}from"./context-view-search.mjs";import{c as N,i as P}from"./ui-base";import{t as ce}from"./agent-strip.mjs";import{Tabs as F,TabsContent as I,TabsList as L,TabsTrigger as R}from"../components/ui/tabs";import{Spinner as z}from"../components/ui/spinner";import{r as le}from"./read-progress.mjs";import{n as ue}from"./agent-reading.mjs";import{C as B,S as V,_ as de,b as H,w as fe,y as pe}from"./ui-shell";import{Face as me}from"../components/call/face";import{n as he,r as ge,t as _e}from"./principal-label.mjs";import{r as ve,t as ye}from"./presence-line.mjs";import{PRESENCE_EVENT_TYPES as be,isPresenceEvent as xe,usePresence as Se}from"../lib/presence";import{n as Ce}from"./dist2.mjs";import{a as we,i as Te,n as Ee,o as De,r as Oe,t as ke}from"./message.mjs";import{_ as Ae,a as U,b as je,c as Me,f as Ne,g as Pe,h as Fe,i as Ie,l as Le,m as W,n as Re,o as ze,p as Be,r as Ve,s as He,t as Ue,u as We,v as Ge,y as Ke}from"./agent-events.mjs";import{n as qe,t as Je}from"./composer.mjs";import{i as Ye,r as Xe,t as Ze}from"./virtual-log.mjs";import{n as Qe}from"./context-view.mjs";import{t as $e}from"./agent-shell.mjs";import{CodeBlock as G,SerializedObjectCodeBlock as et}from"../components/code-block";import{Empty as tt,EmptyDescription as nt,EmptyHeader as rt,EmptyTitle as it}from"../components/ui/empty";var K=/* @__PURE__ */ e(t(),1);function at(e){let t=Date.now(),n=/* @__PURE__ */ new Set,r;function i(){r||n.size===0||(r=setInterval(()=>{t=Date.now();for(let e of n)e()},e))}function a(){!r||n.size>0||(clearInterval(r),r=void 0)}return{subscribe(e){return n.add(e),t=Date.now(),i(),queueMicrotask(()=>{n.has(e)&&e()}),()=>{n.delete(e),a()}},getSnapshot(){return t}}}const ot=/* @__PURE__ */ new Map;function st(e){let t=ot.get(e);return t||(t=at(e),ot.set(e,t)),t}const ct=e=>typeof e==`number`?e:1/0;function lt(e,t=null){let n=st(e),r=(0,K.useCallback)(()=>Math.min(n.getSnapshot(),ct(t)),[n,t]),[i]=(0,K.useState)(Date.now),a=(0,K.useCallback)(()=>Math.min(i,ct(t)),[i,t]),o=(0,K.useCallback)(e=>{let r=()=>typeof t==`number`&&n.getSnapshot()>=t,i=n.subscribe(()=>{e(),r()&&i()});return r()&&i(),i},[n,t]);return(0,K.useSyncExternalStore)(o,r,a)}var q=/* @__PURE__ */ e(n(),1);const ut=`grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-2`;function dt({principal:e,words:t,className:n,...r}){let i=he(e);return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:N(ut,`items-center font-readme text-2xs text-muted-foreground`,n),children:[/* @__PURE__ */ (0,q.jsx)(`span`,{className:`flex`,children:/* @__PURE__ */ (0,q.jsx)(me,{small:!0,..._e(e),label:i})}),/* @__PURE__ */ (0,q.jsx)(`span`,{...r,title:i,className:`min-w-0 truncate`,children:t})]})}function ft({principal:e,name:t,first:n,children:r,className:i,...a}){return/* @__PURE__ */ (0,q.jsxs)(`div`,{...a,className:N(ut,`gap-y-1 pb-2`,n&&`pt-3.5`,i),children:[n?/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)(`span`,{"data-said-by":!0,"aria-hidden":`true`,title:he(e),className:`col-start-2 row-start-1 truncate font-readme text-2xs text-muted-foreground`,children:t}),/* @__PURE__ */ (0,q.jsx)(`span`,{"aria-hidden":`true`,className:`col-start-1 row-start-2 flex pt-3.5`,children:/* @__PURE__ */ (0,q.jsx)(me,{small:!0,..._e(e)})})]}):null,/* @__PURE__ */ (0,q.jsx)(ke,{from:`user`,side:`start`,className:N(`col-start-2`,n&&`row-start-2`),children:/* @__PURE__ */ (0,q.jsxs)(Ee,{className:`group-[.is-user]:rounded-2xl`,children:[/* @__PURE__ */ (0,q.jsx)(pt,{children:he(e)}),r]})})]})}function pt({children:e}){return/* @__PURE__ */ (0,q.jsx)(`span`,{className:`sr-only`,children:`${e}:`})}function mt({typing:e,runOf:t}){let n=e.toSorted((e,n)=>Number(n.actor===t)-Number(e.actor===t));return/* @__PURE__ */ (0,q.jsxs)(`div`,{"data-typing-in-stream":!0,"aria-hidden":`true`,children:[n.slice(0,3).map(e=>/* @__PURE__ */ (0,q.jsx)(ft,{principal:e,name:ge(e),first:e.actor!==t,children:/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`flex h-6 items-center gap-1`,children:[/* @__PURE__ */ (0,q.jsx)(ht,{}),/* @__PURE__ */ (0,q.jsx)(ht,{className:`[animation-delay:150ms]`}),/* @__PURE__ */ (0,q.jsx)(ht,{className:`[animation-delay:300ms]`})]})},e.actor)),e.length>3?/* @__PURE__ */ (0,q.jsx)(`div`,{className:N(ut,`pb-2`),children:/* @__PURE__ */ (0,q.jsxs)(`span`,{"data-typing-more":!0,className:`text-center text-2xs text-muted-foreground`,children:[`+`,String(e.length-3)]})}):null]})}function ht({className:e}){return/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`size-1.5 rounded-full bg-muted-foreground motion-safe:animate-pulse`,e)})}function gt({text:e}){let[t,n]=(0,K.useState)();return/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`mb-2 flex flex-wrap items-center gap-2 whitespace-normal font-sans text-xs not-italic text-muted-foreground`,children:[`Latest ~32K characters`,/* @__PURE__ */ (0,q.jsxs)(de,{open:!!t,onOpenChange:t=>n(t?je(e):void 0),children:[/* @__PURE__ */ (0,q.jsx)(fe,{render:/* @__PURE__ */ (0,q.jsx)(P,{variant:`outline`,size:`xs`}),children:`View full text`}),/* @__PURE__ */ (0,q.jsxs)(pe,{className:`data-[side=right]:w-full sm:max-w-3xl`,children:[/* @__PURE__ */ (0,q.jsxs)(V,{children:[/* @__PURE__ */ (0,q.jsx)(B,{children:`Available response text`}),/* @__PURE__ */ (0,q.jsx)(H,{children:`Captured when opened. Reopen for newer text.`})]}),/* @__PURE__ */ (0,q.jsxs)(P,{className:`mx-4 self-start`,variant:`outline`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(t||``).then(()=>Ce.success(`Copied`),()=>Ce.error(`Failed to copy to clipboard`))},children:[/* @__PURE__ */ (0,q.jsx)(v,{"data-icon":`inline-start`}),`Copy text`]}),/* @__PURE__ */ (0,q.jsx)(_t,{text:t||``})]})]})]})}const _t=(0,K.memo)(function({text:e}){return/* @__PURE__ */ (0,q.jsx)(`pre`,{className:`min-h-0 flex-1 overflow-auto whitespace-pre-wrap break-words px-4 pb-4 text-sm`,children:e})}),J=(0,K.memo)(function({text:e,animate:t=!1,literal:n=!1}){if(typeof e==`string`)return n?e:Y(vt,e).text;let r=e.blockCount-1,i=Math.floor(r/32),a=Math.max(0,e.blockCount-32),o=n?{}:yt(e,a);return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[a>0?/* @__PURE__ */ (0,q.jsx)(gt,{text:e}):null,Object.entries(e.groups).map(([s,c])=>{if(Number(s)<Math.floor(a/32))return null;let l=o[Number(s)]??vt;return/* @__PURE__ */ (0,q.jsx)(xt,{blocks:c,firstBlock:Number(s)===Math.floor(a/32)?a:0,tailBlock:t&&Number(s)===i?r:null,tailOffset:t&&Number(s)===i?e.tailOffset:0,carry:l.carry,fence:l.fence,tick:l.tick,lineStart:l.lineStart,literal:n},s)})]})}),vt={fence:``,tick:0,lineStart:!0,carry:``};function yt(e,t){let n={},r=vt;for(let i=Math.max(0,t-1);i<e.blockCount;i++)(i%32==0||i===t)&&(n[Math.floor(i/32)]=r),r=Y(r,e.groups[Math.floor(i/32)][i]).next;return n}function Y(e,t){let n=e.carry+t,r=/[`~]+$/.exec(n)?.[0]||``,{parts:i,end:a}=bt(e,n.slice(0,n.length-r.length)),o=r,s=i.at(-1);if(!r&&s&&!s.code){let e=De(s.text);e.endsWith(`[`)&&(e=e.slice(0,-1)),o=s.text.slice(e.length),s.text=e}return{text:i.map(e=>e.code?e.text:we(e.text)).join(``),next:{...a,carry:o}}}function bt(e,t){let{fence:n,tick:r,lineStart:i}=e,a=[],o=0,s=!!n||r>0,c=(e,n)=>{e>o&&a.push({code:s,text:t.slice(o,e)}),o=e,s=n},l=0;for(;l<t.length;){let e=t[l];if(e==="`"||e===`~`){let a=l;for(;t[a]===e;)a++;let o=a-l;n?i&&e===n[0]&&o>=n.length&&(n=``,c(a,!1)):r?e==="`"&&o===r&&(r=0,c(a,!1)):i&&o>=3?(c(l,!0),n=e.repeat(o)):e==="`"&&(c(l,!0),r=o),l=a,i=!1;continue}r&&e===` `&&t[l+1]===` `&&(r=0,c(l,!1)),i=e===` -`||i&&(e===` `||e===` `),l++}return c(t.length,s),{parts:a,end:{fence:n,tick:r,lineStart:i}}}const bt=(0,q.memo)(function({blocks:e,firstBlock:t,tailBlock:n,tailOffset:r,literal:i,...a}){let o=a;return Object.entries(e).map(([e,a])=>{if(Number(e)<t)return null;let s=o;return i||(o=X(o,a).next),/* @__PURE__ */ (0,J.jsx)(xt,{text:a,...s,literal:i,revealFrom:Number(e)===n?r:null},e)})}),xt=(0,q.memo)(function({text:e,literal:t,revealFrom:n,...r}){let i=t?e:X(r,e).text;if(typeof n!=`number`)return/* @__PURE__ */ (0,J.jsx)(`span`,{children:i});let a=t?e.slice(0,n):X(r,e.slice(0,n)).text,o=0;for(;o<a.length&&a[o]===i[o];)o++;let s=i.slice(o),c=[...s.matchAll(/\S+\s*|\s+/g)],l=c.length<=64?c:[{0:s,index:0}];return/* @__PURE__ */ (0,J.jsxs)(`span`,{children:[i.slice(0,o),l.map(e=>/* @__PURE__ */ (0,J.jsx)(`span`,{className:`animate-token-in motion-reduce:animate-none`,style:{animationDelay:`${Math.round(e.index/s.length*140)}ms`},children:e[0]},o+e.index))]})});function St({code:e}){return/* @__PURE__ */ (0,J.jsxs)(`pre`,{className:`whitespace-pre-wrap rounded-xl bg-warning/10 px-4 py-3 font-mono text-xs leading-relaxed text-foreground wrap-break-word`,children:[/* @__PURE__ */ (0,J.jsx)(Y,{text:e,literal:!0}),/* @__PURE__ */ (0,J.jsx)(Ct,{className:`bg-warning`})]})}function Ct({className:e}){return/* @__PURE__ */ (0,J.jsx)(`span`,{className:P(`ml-px inline-block h-3.5 w-[7px] animate-caret-blink bg-muted-foreground/40 align-[-2px]`,e)})}function wt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)+e.length.toString(36)}const Tt=/* @__PURE__ */ new Map;function Et(e){for(let t=e.parentElement;t;t=t.parentElement)if(/(auto|scroll)/.test(getComputedStyle(t).overflowY))return t;return e.ownerDocument.scrollingElement}function Dt(e,t,n){let r=e.ownerDocument.defaultView;if(!r)return;let i=(t,n)=>e.dispatchEvent(Object.assign(new r.Event(t,{bubbles:!0}),{touches:n}));`wheel`in t?(e.dispatchEvent(new r.WheelEvent(`wheel`,{deltaY:t.wheel,bubbles:!0})),Et(e)?.scrollBy(0,t.wheel)):t.touch===`start`?(n.y=0,i(`touchstart`,[{clientY:0}])):t.touch===`move`?(n.y-=t.by,i(`touchmove`,[{clientY:n.y}])):i(`touchend`,[])}function Ot({widget:e,onSend:t,onLog:n,onCallTool:r,onReadResource:i,onReadContext:a,onModelContext:o,onDraft:s,className:c}){let l=(0,q.useRef)(null),u=(0,q.useRef)(null),[d,f]=(0,q.useState)(null),[p,m]=(0,q.useState)(()=>Tt.get(e.key)??e.height??120),[h,g]=(0,q.useState)(!1),_=(0,q.useRef)(0),v=(0,q.useRef)(!1),y=(0,q.useRef)(!1),b=(0,q.useRef)({y:0}),x=e.html.length>te(e),S=(0,q.useRef)(0);(0,q.useLayoutEffect)(()=>{f(ae(l.current))},[]);let C=re(e.csp),w=!!e.app,T=(0,q.useMemo)(()=>x||!d?``:E({html:e.html,data:e.data,csp:e.csp,app:e.app},d),[e.html,d,x,C,w]),D=e.app?JSON.stringify([e.app.server,e.app.headers||{}]):``,k=`${(0,q.useMemo)(()=>wt(T),[T])}:${D}`;(0,q.useLayoutEffect)(()=>{y.current=!1,_.current=0,v.current=!1},[k]);let A=(0,q.useCallback)(e=>{v.current||u.current?.contentWindow?.postMessage(e,`*`)},[]),j=(e,t)=>{if(S.current>=4){A({jsonrpc:`2.0`,id:e,error:{code:-32e3,message:`Too many calls are open; try again when one ends.`}});return}S.current+=1;let n=u.current?.contentWindow,r=t=>{n&&!v.current&&u.current?.contentWindow===n&&n.postMessage({jsonrpc:`2.0`,id:e,...t},`*`)};t().then(e=>r({result:e}),e=>{let t=e instanceof Error?e.message:String(e);r({error:{code:-32e3,message:t.slice(0,2e3)}})}).finally(()=>{--S.current})},oe=(0,q.useEffectEvent)(c=>{if(!u.current||v.current||c.source!==u.current.contentWindow||!d)return;let f=ee(c.data,{widget:e,theme:d,width:l.current?.clientWidth,pressed:(navigator.userActivation?.isActive??!1)&&document.activeElement===u.current,canSend:!!t,canDraft:!!s,canCallServer:!!(r&&i),canModelContext:!!o,canReadContext:!!a});f.reply&&A(f.reply);let{callTool:p,readResource:h,readContext:g}=f;g&&a&&j(g.id,()=>a({widget:e,context:g.context,after:g.after,limit:g.limit})),p&&r&&j(p.id,()=>r({widget:e,name:p.name,arguments:p.arguments})),h&&i&&j(h.id,()=>i({widget:e,uri:h.uri})),f.height!==void 0&&(Tt.set(e.key,f.height),m(f.height)),f.modelContext&&o?.({widget:e,...f.modelContext}),f.initialized&&(y.current=!0,A({jsonrpc:`2.0`,method:`ui/notifications/tool-input`,params:{arguments:ne(e)}}),A({jsonrpc:`2.0`,method:`ui/notifications/tool-result`,params:O(e)})),(f.send||f.draft||f.open)&&l.current?.focus({preventScroll:!0}),f.draft&&s?.(f.draft),f.send&&t?.(f.send,{key:e.key,offset:e.offset}),f.log&&n?.({...f.log,key:e.key}),f.scrolled&&u.current&&Dt(u.current,f.scrolled,b.current),f.open&&window.open(f.open,`_blank`,`noopener,noreferrer`)});(0,q.useEffect)(()=>{let e=e=>oe(e);return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[]);let M=(0,q.useEffectEvent)(()=>{y.current&&A({jsonrpc:`2.0`,method:`ui/notifications/tool-result`,params:O(e)})}),{data:N,text:F}=e;return(0,q.useEffect)(()=>M(),[N,F]),/* @__PURE__ */ (0,J.jsxs)(`figure`,{ref:l,className:P(`my-2 outline-none`,c),tabIndex:-1,"data-kind":`widget`,"data-widget":e.key,children:[e.app?/* @__PURE__ */ (0,J.jsxs)(`figcaption`,{className:`flex gap-1.5 pb-1 text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(`span`,{className:`font-medium text-foreground`,"data-widget-server":!0,children:ie(e.app)}),e.title?/* @__PURE__ */ (0,J.jsxs)(`span`,{className:`truncate`,children:[`· `,e.title]}):null]}):null,/* @__PURE__ */ (0,J.jsx)(`div`,{className:P(e.app?.prefersBorder&&`overflow-hidden rounded-xl border`),"data-widget-border":e.app?.prefersBorder?``:void 0,children:d?x||h?/* @__PURE__ */ (0,J.jsx)(`p`,{className:`whitespace-pre-wrap py-1 text-sm`,children:e.text}):/* @__PURE__ */ (0,J.jsx)(`iframe`,{ref:u,title:e.title||e.text,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,srcDoc:T,className:`block w-full border-0 bg-transparent`,style:{height:p},onLoad:()=>{_.current+=1,_.current>1&&(v.current=!0,g(!0))}},k):/* @__PURE__ */ (0,J.jsx)(`div`,{style:{height:p}})})]})}const kt=(0,q.createContext)({fold:/* @__PURE__ */ new Map});function At({events:e,onSend:t,onDraft:n,path:r,calls:i,onAppend:a,children:o}){let s=(0,q.useMemo)(()=>D(e,void 0,r),[e,r]),c=(0,q.useMemo)(()=>Mt(r,i,a),[r,i,a]),l=(0,q.useMemo)(()=>({fold:s,onSend:t,onDraft:n,...c}),[s,t,n,c]);return/* @__PURE__ */ (0,J.jsx)(kt.Provider,{value:l,children:o})}function jt({widgetKey:e,offset:t}){let{fold:n,onSend:r,onDraft:i,onCallTool:a,onReadResource:o,onReadContext:s,onModelContext:c}=(0,q.useContext)(kt),l=n.get(e);return!l||l.first!==t?null:/* @__PURE__ */ (0,J.jsx)(Ot,{widget:l.widget,onSend:r,onDraft:i,onCallTool:a,onReadResource:o,onReadContext:s,onModelContext:c})}function Mt(e,t,n){let r=e=>{if(!e.app)throw Error(`This widget has no server.`);return e.app};return{...e&&t&&{onCallTool:({widget:n,name:i,arguments:a})=>{let{server:o,headers:s}=r(n);return t.callTool({path:e,key:n.key,server:o,headers:s,name:i,args:a})},onReadResource:({widget:n,uri:i})=>{let{server:a,headers:o}=r(n);return t.readResource({path:e,server:a,headers:o,uri:i})}},...e&&t?.readContext&&{onReadContext:({widget:n,context:r,after:i,limit:a})=>t.readContext({path:e,key:n.key,context:r,after:i,limit:a})},...n&&{onModelContext:({widget:e,content:t})=>{n([{type:T.context,payload:{key:e.key,server:e.app?.server,content:t}}]).catch(()=>void 0)}}}}const Nt=(0,q.memo)(function({item:e,expanded:t,onToggle:n,inspect:r,signedUrl:i,me:a,agentPath:o,continuesRun:s=!1}){switch(e.kind){case`user`:return e.from?/* @__PURE__ */ (0,J.jsx)(Ft,{item:e,from:e.from,agentPath:o,expanded:t,onToggle:n,signedUrl:i}):e.sender&&e.saidBy&&!Ge(e.sender,a)?/* @__PURE__ */ (0,J.jsx)(dt,{"data-kind":`user`,"data-from":`other`,principal:e.sender,name:e.saidBy,first:!s,children:/* @__PURE__ */ (0,J.jsx)(dn,{item:e,signedUrl:i})}):/* @__PURE__ */ (0,J.jsx)(Oe,{from:`user`,className:`pb-2 pt-3.5`,"data-kind":`user`,children:/* @__PURE__ */ (0,J.jsxs)(Te,{className:`group-[.is-user]:rounded-2xl`,children:[/* @__PURE__ */ (0,J.jsx)(ft,{children:`You`}),/* @__PURE__ */ (0,J.jsx)(dn,{item:e,signedUrl:i})]})});case`assistant`:return/* @__PURE__ */ (0,J.jsx)(Oe,{from:`assistant`,className:`py-2`,"data-kind":`assistant`,children:/* @__PURE__ */ (0,J.jsxs)(Te,{children:[/* @__PURE__ */ (0,J.jsx)(De,{className:`min-w-0 max-w-full`,mode:`static`,parseIncompleteMarkdown:!1,children:e.text}),/* @__PURE__ */ (0,J.jsx)(fn,{files:e.files,hasText:e.text!==``,signedUrl:i})]})});case`activity`:return/* @__PURE__ */ (0,J.jsx)(Bt,{activity:e,expanded:t,onToggle:n,inspect:r,me:a});case`background`:return/* @__PURE__ */ (0,J.jsx)(Pt,{item:e,expanded:t,onToggle:n,signedUrl:i});case`note`:return/* @__PURE__ */ (0,J.jsx)(Lt,{item:e,expanded:t,onToggle:n});case`widget`:return/* @__PURE__ */ (0,J.jsx)(jt,{widgetKey:e.key,offset:e.offset});case`stream-paused`:case`stream-resumed`:{let t=e.kind===`stream-paused`?m:f;return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex items-center gap-3 py-3`,"data-kind":e.kind,children:[/* @__PURE__ */ (0,J.jsx)(`div`,{className:`h-px flex-1 bg-border`}),/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex min-w-0 shrink items-center gap-1.5 rounded-full bg-muted px-2.5 py-1 text-muted-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(t,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),/* @__PURE__ */ (0,J.jsx)(`time`,{className:`truncate text-xs font-medium`,title:W(e.timestampMs),children:e.reason?`${e.text}: ${e.reason}`:e.text})]}),/* @__PURE__ */ (0,J.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}}});function Pt({item:e,expanded:t,onToggle:n,signedUrl:r}){let i=e.messages.length;return/* @__PURE__ */ (0,J.jsxs)(Rt,{kind:`background`,icon:x,title:`Read by the agent, without starting a turn`,expanded:t,onToggle:()=>n(e.id),line:i===1?`1 message came in`:`${String(i)} messages came in`,children:[i>100?/* @__PURE__ */ (0,J.jsxs)(`p`,{children:[`The newest `,100,`. The Events tab has them all.`]}):null,e.messages.slice(-100).map(e=>/* @__PURE__ */ (0,J.jsx)(zt,{message:e,signedUrl:r},e.offset))]})}function Ft({item:e,from:t,agentPath:n,expanded:r,onToggle:i,signedUrl:a}){let o=t.split(`/`).findLast(Boolean)||t,s=!!n&&t.startsWith(`${n}/`);return/* @__PURE__ */ (0,J.jsx)(Rt,{kind:`report`,icon:p,title:t,expanded:r,onToggle:()=>i(e.id),line:/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[s?`${o} reported`:`${o} wrote`,/* @__PURE__ */ (0,J.jsx)(`time`,{dateTime:new Date(e.timestampMs).toISOString(),title:W(e.timestampMs),className:`ml-1.5 text-muted-foreground/60`,children:Fe(e.timestampMs)})]}),children:/* @__PURE__ */ (0,J.jsx)(zt,{message:e,signedUrl:a})})}const It={request:b,subagent:y,slack:v};function Lt({item:e,expanded:t,onToggle:n}){let r=e.failed?C:It[e.about],i=/* @__PURE__ */ (0,J.jsx)(`span`,{className:P(e.failed&&`text-destructive`),title:W(e.timestampMs),children:e.text});return e.detail?/* @__PURE__ */ (0,J.jsx)(Rt,{kind:`note`,icon:r,title:e.text,expanded:t,onToggle:()=>n(e.id),line:i,children:/* @__PURE__ */ (0,J.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.detail})}):/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex h-8 min-w-0 items-center gap-1.5 text-sm text-muted-foreground`,"data-kind":`note`,children:[/* @__PURE__ */ (0,J.jsx)(r,{className:`size-4 shrink-0 text-muted-foreground/60`,"aria-hidden":`true`}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`min-w-0 truncate`,children:i})]})}function Rt({kind:e,icon:t,title:n,line:r,expanded:i,onToggle:a,children:o}){return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col py-0.5`,"data-kind":e,children:[/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`sm`,"aria-expanded":i,title:n,onClick:a,className:`-ml-2.5 max-w-full self-start font-normal text-muted-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(t,{"data-icon":`inline-start`,className:`text-muted-foreground/60`}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`min-w-0 truncate`,children:r}),/* @__PURE__ */ (0,J.jsx)(h,{"data-icon":`inline-end`,className:P(`text-muted-foreground/50 transition-transform`,i&&`rotate-90`)})]}),i?/* @__PURE__ */ (0,J.jsx)(`div`,{className:`mb-1.5 ml-1 mt-0.5 flex min-w-0 flex-col gap-1.5 border-l-2 border-muted py-1 pl-4 text-xs leading-5 text-muted-foreground`,children:o}):null]})}function zt({message:e,signedUrl:t}){return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`min-w-0`,title:W(e.timestampMs),children:[e.text===``?null:/* @__PURE__ */ (0,J.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.text}),/* @__PURE__ */ (0,J.jsx)(fn,{files:e.files,hasText:e.text!==``,signedUrl:t})]})}function Bt({activity:e,expanded:t,onToggle:n,inspect:r,me:i}){let a=We(e),o=a.outcome===`failed`,s=[...e.steps].reverse().flatMap(e=>e.kind===`code`&&e.activitySummary?[e.activitySummary]:[]).at(0);return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col py-0.5`,"data-kind":`activity`,children:[/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`sm`,"aria-expanded":t,title:`Agent activity — click to see what it did`,onClick:()=>n(e.id),className:P(`-ml-2.5 max-w-full self-start font-medium text-muted-foreground`,o&&`text-destructive hover:text-destructive`),children:[o?/* @__PURE__ */ (0,J.jsx)(C,{"data-icon":`inline-start`,className:`text-destructive`}):a.outcome===`interrupted`?/* @__PURE__ */ (0,J.jsx)(w,{"data-icon":`inline-start`,className:`text-destructive`}):/* @__PURE__ */ (0,J.jsx)(S,{"data-icon":`inline-start`,className:`text-muted-foreground/60`}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`min-w-0 truncate`,children:!s||a.outcome!==`clean`?`${s?`${s} · `:``}${ze(e,{summary:a,interruptedPartialHint:`click to see partial response`,me:i})}`:[s,e.endedAtMs?G(Math.max(0,e.endedAtMs-e.startedAtMs)):``].filter(Boolean).join(` · `)}),/* @__PURE__ */ (0,J.jsx)(h,{"data-icon":`inline-end`,className:P(`text-muted-foreground/50 transition-transform`,t&&`rotate-90`)})]}),t?/* @__PURE__ */ (0,J.jsx)(`div`,{className:`mb-1.5 ml-1 mt-0.5 flex flex-col gap-1 border-l-2 border-muted py-1 pl-4`,children:/* @__PURE__ */ (0,J.jsx)(Vt,{rounds:Pe(e.steps),inspect:r})}):null]})}function Vt({rounds:e,inspect:t}){return e.length===1?/* @__PURE__ */ (0,J.jsx)(Wt,{round:e[0],inspect:t}):/* @__PURE__ */ (0,J.jsx)(J.Fragment,{children:e.map((e,n)=>/* @__PURE__ */ (0,J.jsx)(Ht,{round:e,index:n,inspect:t},e.code?.id||e.llm?.id))})}function Ht({round:e,index:t,inspect:n}){let[r,i]=(0,q.useState)(null),a=r??e.code?.status===`running`,o=e.code?.success===!1||e.llm?.outcome===`failed`;return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col items-start`,children:[/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`xs`,"aria-expanded":a,onClick:()=>i(!a),className:P(`-ml-2 max-w-full self-start font-normal`,o&&`text-destructive hover:text-destructive`),children:[/* @__PURE__ */ (0,J.jsxs)(`span`,{className:P(`shrink-0 font-mono text-xs text-foreground/70`,o&&`text-destructive`),children:[`Round `,t+1]}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-muted-foreground/70`,children:Ut(e)}),/* @__PURE__ */ (0,J.jsx)(h,{"data-icon":`inline-end`,className:P(`text-muted-foreground/50 transition-transform`,a&&`rotate-90`)})]}),a?/* @__PURE__ */ (0,J.jsx)(`div`,{className:`w-full py-1`,children:/* @__PURE__ */ (0,J.jsx)(Wt,{round:e,inspect:n})}):null]})}function Ut(e){let t=[];return e.code?.activitySummary?t.push(e.code.activitySummary):e.llm&&t.push(Fe(e.llm.startedAtMs)),e.llm?.durationMs!=null&&t.push(`model ${G(e.llm.durationMs)}`),e.code?.durationMs!=null&&t.push(`script ${G(e.code.durationMs)}`),t.join(` · `)}function Wt({round:e,inspect:t}){return e.code?/* @__PURE__ */ (0,J.jsx)(Xt,{llm:e.llm,code:e.code,inspect:t}):e.llm?/* @__PURE__ */ (0,J.jsx)(qt,{llm:e.llm,inspect:t}):null}function Gt(e){return e.status===`running`?e.responseText.length>0?`Writing code`:e.thinking||e.thinkingText.length>0?`Thinking`:`Waiting for a response`:e.outcome===`failed`?`Request failed`:e.outcome===`cancelled`?e.cancelReason===`expired`?`Request expired`:e.cancelReason===`superseded`?`Another response answered first`:`Request cancelled`:e.model||`Response`}function Kt(e){let t=[Fe(e.startedAtMs)];return e.durationMs!=null&&t.push(G(e.durationMs)),t.join(` · `)}function qt({llm:e,inspect:t}){return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-1.5`,children:[/* @__PURE__ */ (0,J.jsx)(`span`,{className:P(`font-mono text-xs text-foreground/70`,e.outcome!==`completed`&&`text-destructive`),children:Gt(e)}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground/70`,children:Kt(e)}),/* @__PURE__ */ (0,J.jsx)(Yt,{onClick:()=>t.llmRequest(e.llmRequestOffset)})]}),/* @__PURE__ */ (0,J.jsx)(Jt,{llm:e})]})}function Jt({llm:e}){let t=Ae(e.responseText);return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[t.length===0?null:Ie(t)?/* @__PURE__ */ (0,J.jsx)(`div`,{className:P(`w-full max-w-2xl`,e.interpreted&&`opacity-75`),children:/* @__PURE__ */ (0,J.jsx)(K,{code:t,language:`typescript`,showLineNumbers:!1})}):/* @__PURE__ */ (0,J.jsx)(`div`,{className:P(`max-w-2xl whitespace-pre-wrap px-1.5 text-sm leading-relaxed`,e.interpreted&&`text-muted-foreground`),children:t}),e.errorMessage?/* @__PURE__ */ (0,J.jsx)(`pre`,{"data-type":`error`,className:`max-w-2xl whitespace-pre-wrap px-1.5 font-mono text-xs text-destructive`,children:e.errorMessage}):null]})}function Yt({onClick:e}){return/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`xs`,title:`Open this LLM request trace`,onClick:e,className:`-ml-1 font-normal text-muted-foreground`,children:[`Full trace`,/* @__PURE__ */ (0,J.jsx)(h,{"data-icon":`inline-end`,className:`text-muted-foreground/50`})]})}function Xt({llm:e,code:t,inspect:n}){let[r,i]=(0,q.useState)(`script`),a=t.status===`done`,o=r===`result`&&!a?`script`:r,s=Le(t.code),c=!!s;return/* @__PURE__ */ (0,J.jsxs)(I,{value:o,onValueChange:e=>i(String(e)),className:`w-full gap-1.5`,children:[/* @__PURE__ */ (0,J.jsxs)(R,{variant:`line`,className:`h-7`,children:[/* @__PURE__ */ (0,J.jsx)(z,{value:`script`,className:`text-xs`,children:`Script`}),a?/* @__PURE__ */ (0,J.jsx)(z,{value:`result`,className:`text-xs`,children:`Result`}):null,c?/* @__PURE__ */ (0,J.jsx)(z,{value:`full`,className:`text-xs`,children:`Full script`}):null,/* @__PURE__ */ (0,J.jsx)(z,{value:`meta`,className:`text-xs`,children:`Meta`})]}),/* @__PURE__ */ (0,J.jsx)(L,{value:`script`,className:`flex flex-col gap-1.5`,children:/* @__PURE__ */ (0,J.jsx)(Zt,{source:s||t.code,error:a?void 0:t.errorMessage,onTrace:()=>n.scriptRun(t.requestOffset)})}),/* @__PURE__ */ (0,J.jsx)(L,{value:`result`,className:`flex flex-col gap-2`,children:/* @__PURE__ */ (0,J.jsx)(en,{code:t})}),c?/* @__PURE__ */ (0,J.jsx)(L,{value:`full`,className:`flex flex-col gap-1.5`,children:/* @__PURE__ */ (0,J.jsx)(K,{code:t.code,language:`typescript`,showLineNumbers:!1})}):null,/* @__PURE__ */ (0,J.jsx)(L,{value:`meta`,className:`flex flex-col gap-1.5`,children:/* @__PURE__ */ (0,J.jsx)(Qt,{llm:e,code:t,inspect:n})})]})}function Zt({source:e,error:t,onTrace:n}){return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsx)(K,{code:e,language:`typescript`,showLineNumbers:!1,prettify:!0}),t?/* @__PURE__ */ (0,J.jsx)(`pre`,{"data-type":`error`,className:`whitespace-pre-wrap px-1.5 font-mono text-xs text-destructive`,children:t}):null,/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`xs`,title:`Open this script's execution trace`,onClick:n,className:`-ml-2 self-start font-normal text-muted-foreground`,children:[`Execution trace`,/* @__PURE__ */ (0,J.jsx)(h,{"data-icon":`inline-end`,className:`text-muted-foreground/50`})]})]})}function Qt({llm:e,code:t,inspect:n}){return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 px-1.5 font-mono text-xs`,children:[e?/* @__PURE__ */ (0,J.jsx)($t,{llm:e}):null,/* @__PURE__ */ (0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:`script`}),/* @__PURE__ */ (0,J.jsxs)(`dd`,{children:[t.durationMs==null?`running`:G(t.durationMs),t.success===!1?` · failed`:``]}),/* @__PURE__ */ (0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:`run`}),/* @__PURE__ */ (0,J.jsxs)(`dd`,{className:`truncate`,children:[`#`,t.requestOffset]})]}),e?/* @__PURE__ */ (0,J.jsx)(Yt,{onClick:()=>n.llmRequest(e.llmRequestOffset)}):null]})}function $t({llm:e}){return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:`model`}),/* @__PURE__ */ (0,J.jsx)(`dd`,{children:e.model||`?`}),/* @__PURE__ */ (0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:`requested`}),/* @__PURE__ */ (0,J.jsx)(`dd`,{children:W(e.startedAtMs)}),/* @__PURE__ */ (0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:`response`}),/* @__PURE__ */ (0,J.jsxs)(`dd`,{children:[e.durationMs==null?`—`:G(e.durationMs),e.outcome&&e.outcome!==`completed`?` · ${e.outcome}`:``]})]})}function en({code:e}){return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[e.errorMessage?/* @__PURE__ */ (0,J.jsx)(`pre`,{"data-type":`error`,className:`whitespace-pre-wrap rounded-lg bg-destructive/5 px-3 py-2 font-mono text-xs leading-relaxed text-destructive`,children:e.errorMessage}):null,e.result===void 0?e.errorMessage?null:/* @__PURE__ */ (0,J.jsx)(`p`,{className:`font-readme px-1.5 text-xs text-muted-foreground`,children:`Returned nothing — the turn ended here.`}):typeof e.result==`string`?/* @__PURE__ */ (0,J.jsx)(`pre`,{className:`whitespace-pre-wrap rounded-lg wrap-break-word bg-muted/40 px-3 py-2 font-mono text-xs leading-relaxed`,children:e.result}):/* @__PURE__ */ (0,J.jsx)($e,{data:e.result})]})}function tn({state:e,toggledIds:t,onToggle:n,inspect:r,me:i}){let a=e.live,o=a?`live-activity:${a.id}`:``,s=(0,q.useCallback)(()=>n(o),[o,n]);if(!a)return null;let c=a.steps.filter(e=>e.status===`running`),l=c.at(-1),u=a.steps.filter(e=>e.status===`done`),d=Me(e),f=ke(e),p=t.has(o),m=p&&(u.length>0||c.some(e=>e.kind===`code`||cn(e)));return f?/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col py-0.5`,"data-kind":`live`,children:[u.length>0?/* @__PURE__ */ (0,J.jsx)(an,{live:a,doneSteps:u,expanded:p,onToggle:s,me:i}):null,m?/* @__PURE__ */ (0,J.jsx)(on,{live:a,liveStep:l,inspect:r}):null,!m&&l&&l.kind===`llm`&&l.thinkingText.length>0?/* @__PURE__ */ (0,J.jsx)(un,{step:l,showResponseText:!1}):null,/* @__PURE__ */ (0,J.jsx)(sn,{label:d?.statusText||je(c),startedAtMs:nn(a,l),deadlineMs:l?.kind===`code`?l.deadlineAtMs:null,onInspect:rn(l,r)})]}):/* @__PURE__ */ (0,J.jsx)(Bt,{activity:a,expanded:t.has(a.id),onToggle:n,inspect:r,me:i})}function Z({text:e,working:t}){return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex h-7 items-center gap-1.5 text-sm text-muted-foreground`,"data-testid":`agent-turn-status`,role:`status`,children:[t?/* @__PURE__ */ (0,J.jsx)(B,{className:`size-3 shrink-0`}):null,/* @__PURE__ */ (0,J.jsx)(`span`,{className:`truncate`,children:e})]})}function nn(e,t){if(t)return t.startedAtMs;let n=e.steps.at(-1);return n?n.startedAtMs+(n.durationMs??0):e.startedAtMs}function rn(e,t){if(e?.kind===`llm`)return()=>t.llmRequest(e.llmRequestOffset);if(e?.kind===`code`)return()=>t.scriptRun(e.requestOffset)}function an({live:e,doneSteps:t,expanded:n,onToggle:r,me:i}){let a=We(e,t);return/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`sm`,"aria-expanded":n,title:`Agent activity so far — click to see details`,onClick:r,className:`-ml-2.5 max-w-full self-start font-mono text-xs font-normal text-muted-foreground`,"data-testid":`agent-live-summary`,children:[a.codeCount>0?/* @__PURE__ */ (0,J.jsx)(S,{className:`size-3 shrink-0 text-muted-foreground/60`,"aria-hidden":`true`}):/* @__PURE__ */ (0,J.jsx)(`span`,{className:`shrink-0 text-2xs leading-none text-muted-foreground/60`,children:`✦`}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`min-w-0 truncate`,children:ze(e,{summary:a,interruptedPartialHint:`click to see partial response`,me:i})}),/* @__PURE__ */ (0,J.jsx)(h,{className:P(`size-2.5 text-muted-foreground/50 transition-transform`,n&&`rotate-90`),"aria-hidden":`true`})]})}function on({live:e,liveStep:t,inspect:n}){return/* @__PURE__ */ (0,J.jsx)(`div`,{className:`mb-1.5 ml-1 mt-0.5 flex flex-col gap-1 border-l-2 border-muted py-1 pl-4`,children:Pe(e.steps).map((e,r)=>!e.code&&e.llm&&e.llm.status===`running`?e.llm===t&&cn(e.llm)?/* @__PURE__ */ (0,J.jsx)(un,{step:e.llm},e.llm.id):null:/* @__PURE__ */ (0,J.jsx)(Ht,{round:e,index:r,inspect:n},e.code?.id||e.llm?.id))})}function sn({label:e,startedAtMs:t,deadlineMs:n,onInspect:r}){let i=ln(t,n),a=i.deadlineExceeded?`Code deadline exceeded`:e;return/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`sm`,disabled:!r,onClick:r,title:i.deadlineExceeded?`The script is past its deadline; the platform's settlement has not landed yet`:r?`Open the current operation's trace`:void 0,className:P(`-ml-2.5 h-7 self-start px-2.5 text-primary disabled:opacity-100`,i.deadlineExceeded&&`text-destructive`),"data-testid":`agent-live-status`,children:[i.deadlineExceeded?/* @__PURE__ */ (0,J.jsx)(C,{className:`size-3 shrink-0 text-destructive`}):/* @__PURE__ */ (0,J.jsx)(B,{className:`size-3 shrink-0 text-primary`}),/* @__PURE__ */ (0,J.jsxs)(`span`,{className:P(`text-sm font-medium tabular-nums text-primary`,i.deadlineExceeded&&`text-destructive`),children:[a,` `,i.elapsedLabel]}),r?/* @__PURE__ */ (0,J.jsx)(h,{className:P(`size-2.5 text-primary/60`,i.deadlineExceeded&&`text-destructive/60`),"aria-hidden":`true`}):null]})}function cn(e){return e.kind===`code`?e.code!==``:e.thinkingText.length>0||e.responseText.length>0}function ln(e,t){let n=ct(100,t),r=typeof t==`number`&&n>=t;return{deadlineExceeded:r,elapsedLabel:Re((r&&typeof t==`number`?t:n)-e)}}function un({step:e,showResponseText:t=!0}){return e.kind===`code`?/* @__PURE__ */ (0,J.jsx)(`div`,{className:`flex flex-col gap-1.5 py-1`,children:e.code===``?null:/* @__PURE__ */ (0,J.jsx)(St,{code:Le(e.code)||e.code})}):/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5 py-1`,children:[e.thinkingText.length===0?null:/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`max-w-2xl whitespace-pre-wrap px-1.5 text-sm italic leading-relaxed text-muted-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(Y,{text:e.thinkingText}),!t||e.responseText.length===0?/* @__PURE__ */ (0,J.jsx)(Ct,{}):null]}),!t||e.responseText.length===0?null:Ie(e.responseText)?/* @__PURE__ */ (0,J.jsx)(St,{code:e.responseText}):/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`max-w-2xl whitespace-pre-wrap px-1.5 text-sm leading-relaxed`,children:[/* @__PURE__ */ (0,J.jsx)(Y,{text:e.responseText,animate:!0}),/* @__PURE__ */ (0,J.jsx)(Ct,{})]})]})}function dn({item:e,signedUrl:t}){return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[e.text===``?null:/* @__PURE__ */ (0,J.jsx)(`div`,{className:`whitespace-pre-wrap leading-6 wrap-anywhere`,children:e.text}),/* @__PURE__ */ (0,J.jsx)(fn,{files:e.files,hasText:e.text!==``,signedUrl:t})]})}function fn({files:e,hasText:t,signedUrl:n}){return e?.length?/* @__PURE__ */ (0,J.jsx)(`div`,{className:P(`flex max-w-full flex-col gap-2`,t&&`mt-1`),children:e.map(e=>/* @__PURE__ */ (0,J.jsx)(pn,{file:e,signedUrl:n},e.path))}):null}function pn({file:e,signedUrl:t}){let[n,r]=(0,q.useState)();return(0,q.useEffect)(()=>{let n=!0;return t(e.path).then(e=>n&&r(e),()=>void 0),()=>void(n=!1)},[e.path,t]),e.contentType.startsWith(`image/`)&&n?/* @__PURE__ */ (0,J.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`block max-w-full`,children:/* @__PURE__ */ (0,J.jsx)(`img`,{src:n,alt:e.filename,className:`max-h-64 max-w-full rounded-lg border border-border/60 bg-background object-contain`})}):/* @__PURE__ */ (0,J.jsxs)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`inline-flex max-w-full items-center gap-1.5 self-start rounded-full border border-border/60 bg-background/70 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:text-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(g,{className:`size-3 shrink-0`}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`min-w-0 truncate text-foreground/80`,children:e.filename}),/* @__PURE__ */ (0,J.jsx)(`span`,{className:`shrink-0 font-mono`,children:Ve(e.size)})]})}const mn={user:96,assistant:72,activity:36,background:36,note:32,widget:140,"stream-paused":48,"stream-resumed":48},hn={key:e=>e.id,estimateSize:e=>e.kind===`user`&&e.from?mn.activity:mn[e.kind],offset:e=>e.kind===`user`||e.kind===`assistant`?e.offset:void 0};function gn({feed:e,older:t,logShare:n,followTail:r,empty:i,after:a,footer:o,toggledIds:s,onToggle:c,inspect:l,signedUrl:u,itemFooter:d,me:f,agentPath:p,typing:m}){let{items:h,state:g}=e,_=h.at(-1),v=m.length>0?/* @__PURE__ */ (0,J.jsx)(pt,{typing:m,runOf:g.live?void 0:vn(_)}):null,y=(0,q.useCallback)((e,t)=>/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsx)(Nt,{item:e,expanded:s.has(e.id),onToggle:c,inspect:l,signedUrl:u,me:f,agentPath:p,continuesRun:_n(h[t-1],e)}),d?.(e)]}),[s,c,l,u,d,f,p,h]);return/* @__PURE__ */ (0,J.jsx)(Xe,{rows:h,rowInfo:hn,renderRow:y,tail:g.live||v&&_||a?/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[g.live?/* @__PURE__ */ (0,J.jsx)(tn,{state:g,toggledIds:s,onToggle:c,inspect:l,me:f}):null,v,a]}):void 0,older:t,readingOlder:/* @__PURE__ */ (0,J.jsx)(ce,{label:`Loading older messages`,value:n}),empty:v?/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`relative h-full`,children:[i,/* @__PURE__ */ (0,J.jsx)(`div`,{className:`absolute inset-x-0 bottom-0`,children:v})]}):i,label:`Chat`,footer:o,followTail:r,paddingStart:8,paddingEnd:8,columnClassName:`mx-auto w-full max-w-3xl px-4 md:px-6`})}function _n(e,t){if(e?.kind!==`user`||t.kind!==`user`||e.from||t.from)return!1;let[n,r]=[e.sender,t.sender];return!!(n&&r&&n.actor===r.actor&&n.script===r.script)}function vn(e){if(!(e?.kind!==`user`||e.from||e.sender?.script!==!1))return e.sender.actor}const yn={llmRequest:void 0,scriptRun:void 0};function bn(e,t,n){return t.exhausted?!1:e?.kind===`scriptRun`?e.requestOffset<(n[0]?.offset??1/0):e?.kind===`llmRequest`}const Q=d().optional().catch(void 0),$=l().optional().catch(void 0),xn=s(l(),i()),Sn=o({contentType:l(),filename:l(),path:l(),size:d()}),Cn=u(Sn.nullable().catch(null)).catch([]).transform(e=>e.flatMap(e=>e?[e]:[])),wn=o({role:$,text:$,files:Cn.optional(),atOffset:Q,tag:$}).catch({}),Tn=o({model:$,purpose:$,instructions:$,extends:o({llmRequestOffset:d(),itemCount:d().nullable().optional().catch(void 0),response:c().optional().catch(void 0)}).nullable().catch(null),itemsAdded:u(wn).catch([])}),En=o({inputTokens:Q,outputTokens:Q,cachedInputTokens:Q,cacheWriteInputTokens:Q,reasoningOutputTokens:Q,costUsd:Q,estimated:a(!0).optional().catch(void 0)}),Dn=o({llmRequestOffset:d(),durationMs:Q,firstEventMs:Q,result:o({status:$,text:$,partialText:$,errorMessage:$,failureKind:$,reason:$,usage:En.optional().catch(void 0)}).catch({})}),On=o({llmRequestOffset:Q,attempt:d().catch(0),api:$,transport:$,model:$,inputChars:s(l(),d()).optional().catch(void 0),inputFileBytes:Q}),kn=o({llmRequestOffset:Q,attempt:Q,bodySha256:$,inputField:$,bodyWithoutInput:xn.optional().catch(void 0),inputItemsAdded:u(i()).optional().catch(void 0),extendsRequestStartedOffset:d().nullable().optional().catch(void 0),inputItemCountBefore:d().catch(0)});function An(e,t){let n=new Map(e.map(e=>[e.offset,e])),r=n.get(t);if(!r||r.type!==M.llmRequested)return null;let i=Tn.safeParse(r.payload).data,a=/* @__PURE__ */ new Map,o=[],s=[];for(let n of e){if(n.type===M.llmSettled){let e=Dn.safeParse(n.payload).data;e&&!a.has(e.llmRequestOffset)&&a.set(e.llmRequestOffset,e)}n.type===M.llmAttemptStarted&&On.safeParse(n.payload).data?.llmRequestOffset===t&&o.push(n),n.type===`events.iterate.com/itx/run-requested`&&j(n.idempotencyKey)===t&&s.push(n.offset)}let c=jn(n,a,t,0),l=a.get(t);return{llmRequestOffset:t,model:i?.model||`?`,purpose:i?.purpose||`?`,requestedAtMs:Date.parse(r.createdAt),instructions:c.instructions||null,conversation:c.items,conversationWhole:c.whole,attempts:o.map(t=>Nn(e,n,t)),outcome:Fn(l),usage:l?.result.usage,scriptRequestOffsets:s}}function jn(e,t,n,r){let i=e.get(n);if(!i||i.type!==M.llmRequested||r>64)return{items:[],whole:!1};let a=Tn.safeParse(i.payload).data,o=(a?.itemsAdded||[]).map(e=>({role:e.role||`?`,text:e.text||``,files:e.files||[],atOffset:e.atOffset??n,tag:e.tag||`words`})),s=a?.instructions,c=a?.extends;if(!c)return{instructions:s,items:o,whole:!0};let l=jn(e,t,c.llmRequestOffset,r+1),u=c.itemCount??l.items.length,d=c.response?Mn(t,c.llmRequestOffset):[];return{instructions:s||l.instructions,items:[...l.items.slice(0,u),...d,...o],whole:l.whole&&u<=l.items.length&&(!c.response||d.length>0)}}function Mn(e,t){let n=e.get(t)?.result;return n?.status!==`succeeded`||!n.text?[]:[{role:`assistant`,text:n.text,files:[],atOffset:t,tag:`llm-response`}]}function Nn(e,t,n){let r=On.parse(n.payload),i=r.api||null,a={attempt:r.attempt,api:i,transport:r.transport,model:r.model,startedAtMs:Date.parse(n.createdAt),inputChars:r.inputChars,inputFileBytes:r.inputFileBytes};if(!i)return{...a,body:null,bodyMissing:`The attempt names no API shape.`};let o=k(i,`request-started`),s=e.filter(e=>e.type===o).map(e=>kn.safeParse(e.payload).data).find(e=>e?.llmRequestOffset===r.llmRequestOffset&&e?.attempt===r.attempt);if(!s)return{...a,body:null,bodyMissing:`No ${i}/request-started for this attempt in the log held.`};let c={...a,bodySha256:s.bodySha256},l=Pn(t,o,s,0);return typeof l==`string`?{...c,body:null,bodyMissing:l}:!s.inputField||!s.bodyWithoutInput?{...c,body:null,bodyMissing:`The fact has no body.`}:{...c,body:{...s.bodyWithoutInput,[s.inputField]:l}}}function Pn(e,t,n,r){if(!n.inputItemsAdded)return`Its conversation was too large for one fact: the request facts before it give it.`;let i=n.extendsRequestStartedOffset;if(!i)return n.inputItemsAdded;let a=e.get(i),o=a?.type===t&&kn.safeParse(a.payload).data;if(!o||r>64)return`It extends the body at offset ${String(i)}, which is not in the log held.`;let s=Pn(e,t,o,r+1);return typeof s==`string`?s:[...s.slice(0,n.inputItemCountBefore),...n.inputItemsAdded]}function Fn(e){if(!e)return{status:`in flight`};let{result:t,durationMs:n}=e;return t.status===`succeeded`?{status:`succeeded`,text:t.text||``,durationMs:n,firstEventMs:e.firstEventMs}:t.status===`failed`?{status:`failed`,errorMessage:t.errorMessage||``,failureKind:t.failureKind,partialText:t.partialText,durationMs:n}:{status:`cancelled`,reason:t.reason,partialText:t.partialText,durationMs:n}}const In={key:e=>e.key,estimateSize:e=>56+Math.min(4e3,Math.ceil(e.text.length/100)*24),offset:e=>e.atOffset};function Ln({trace:e,step:t,onScript:n}){let[r,i]=(0,q.useState)(`markdown`),a=(0,q.useMemo)(()=>[...e.instructions?[{key:`instructions`,role:`instructions`,text:e.instructions,files:[]}]:[],...e.conversation.map((e,t)=>({...e,key:String(t)}))],[e.instructions,e.conversation]),o=[...new Set(e.attempts.flatMap(e=>e.api||[]))];return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsxs)(H,{className:`shrink-0 pr-12`,children:[/* @__PURE__ */ (0,J.jsxs)(V,{className:`truncate`,children:[`LLM trace #`,e.llmRequestOffset,` · `,e.model]}),/* @__PURE__ */ (0,J.jsxs)(U,{children:[W(e.requestedAtMs),o.length>0?` · ${o.join(`, `)}`:``,e.purpose===`answer`?``:` · ${e.purpose} request`,` · ${e.conversation.length.toLocaleString()} items`,/* @__PURE__ */ (0,J.jsx)(Wn,{outcome:e.outcome}),e.usage?` · ${Hn(e.usage)}`:``]})]}),/* @__PURE__ */ (0,J.jsxs)(I,{defaultValue:`conversation`,className:`min-h-0 flex-1 gap-0`,children:[/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 px-4`,children:[/* @__PURE__ */ (0,J.jsxs)(R,{variant:`line`,className:`h-8`,children:[/* @__PURE__ */ (0,J.jsx)(z,{value:`conversation`,children:`Conversation`}),/* @__PURE__ */ (0,J.jsx)(z,{value:`body`,children:`Request body`}),/* @__PURE__ */ (0,J.jsx)(z,{value:`response`,children:`Response`})]}),/* @__PURE__ */ (0,J.jsx)(F,{size:`xs`,variant:`ghost`,className:`ml-auto font-normal text-muted-foreground`,"aria-pressed":r===`plain`,title:`Toggle between rendered markdown and the verbatim text`,onClick:()=>i(r===`markdown`?`plain`:`markdown`),children:r===`markdown`?`Markdown`:`Plain text`})]}),/* @__PURE__ */ (0,J.jsxs)(L,{value:`conversation`,className:`flex min-h-0 flex-1 flex-col border-t`,children:[e.conversationWhole?null:/* @__PURE__ */ (0,J.jsx)(`p`,{className:`font-readme shrink-0 px-5 py-2 text-xs text-muted-foreground`,children:`A base of this request is not in the log held: its items are missing here. The request body has them as they were sent.`}),/* @__PURE__ */ (0,J.jsx)(Xe,{rows:a,rowInfo:In,renderRow:e=>/* @__PURE__ */ (0,J.jsx)(Rn,{item:e,renderMode:r}),className:`min-h-0 flex-1`})]}),/* @__PURE__ */ (0,J.jsx)(L,{value:`body`,className:`min-h-0 flex-1 overflow-y-auto border-t`,children:e.attempts.length===0?/* @__PURE__ */ (0,J.jsx)(`p`,{className:`font-readme px-5 py-3 text-sm text-muted-foreground`,children:`No attempt has started yet.`}):e.attempts.map(e=>/* @__PURE__ */ (0,J.jsx)(zn,{attempt:e},e.attempt))}),/* @__PURE__ */ (0,J.jsx)(L,{value:`response`,className:`min-h-0 flex-1 overflow-y-auto border-t`,children:/* @__PURE__ */ (0,J.jsx)(Bn,{trace:e,step:t,renderMode:r,onScript:n})})]})]})}const Rn=(0,q.memo)(function({item:e,renderMode:t}){return/* @__PURE__ */ (0,J.jsxs)(`section`,{className:`border-b border-border/60 px-5 py-3`,children:[/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`mb-2 flex items-baseline gap-2`,children:[/* @__PURE__ */ (0,J.jsx)(Kn,{name:e.role}),/* @__PURE__ */ (0,J.jsxs)(`span`,{className:`font-mono text-2xs text-muted-foreground/60`,children:[e.atOffset===void 0?``:`#${String(e.atOffset)} · `,e.tag?`${e.tag} · `:``,e.text.length.toLocaleString(),` chars`]})]}),e.files.length>0?/* @__PURE__ */ (0,J.jsx)(`ul`,{className:`mb-2 flex flex-col gap-0.5`,children:e.files.map(e=>/* @__PURE__ */ (0,J.jsxs)(`li`,{className:`flex items-center gap-1.5 font-mono text-2xs text-muted-foreground`,title:e.path,children:[/* @__PURE__ */ (0,J.jsx)(g,{className:`size-3 shrink-0`,"aria-hidden":`true`}),/* @__PURE__ */ (0,J.jsxs)(`span`,{className:`truncate`,children:[e.filename,` · `,e.contentType,` · `,Ve(e.size)]})]},e.path))}):null,/* @__PURE__ */ (0,J.jsx)(qn,{text:e.text,renderMode:t})]})});function zn({attempt:e}){let t=[e.api||`no API shape`,e.transport,e.model,e.inputFileBytes?`${Ve(e.inputFileBytes)} of files`:void 0].filter(Boolean);return/* @__PURE__ */ (0,J.jsxs)(`section`,{className:`flex flex-col gap-2 border-b border-border/60 px-5 py-3`,children:[/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[/* @__PURE__ */ (0,J.jsx)(Kn,{name:`attempt ${String(e.attempt+1)}`}),/* @__PURE__ */ (0,J.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-2xs text-muted-foreground/60`,children:[t.join(` · `),` · `,W(e.startedAtMs)]})]}),e.body?/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsx)(`div`,{className:`max-h-[70vh] overflow-y-auto rounded-lg`,children:/* @__PURE__ */ (0,J.jsx)($e,{data:e.body,initialFormat:`json`})}),/* @__PURE__ */ (0,J.jsxs)(`p`,{className:`font-readme text-2xs text-muted-foreground/70`,children:[`The body as it went to the provider. A file's bytes are a `,/* @__PURE__ */ (0,J.jsx)(`code`,{children:`$file`}),` reference here.`,e.bodySha256?` The real body's SHA-256: ${e.bodySha256}.`:``]})]}):/* @__PURE__ */ (0,J.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:e.bodyMissing})]})}function Bn({trace:e,step:t,renderMode:n,onScript:r}){let{outcome:i}=e,a=t?.status===`running`,o=t&&t.thinkingText.length>0?t.thinkingText:null,s=i.status===`succeeded`?i.text:a&&t?Ae(t.responseText):i.status===`in flight`?``:i.partialText||``;return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-3`,children:[o?/* @__PURE__ */ (0,J.jsxs)(`div`,{children:[/* @__PURE__ */ (0,J.jsx)(Gn,{children:`thinking`}),/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`whitespace-pre-wrap text-sm italic leading-relaxed text-muted-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(Y,{text:o}),a&&s===``?/* @__PURE__ */ (0,J.jsx)(Ct,{}):null]})]}):a&&t?.thinking?/* @__PURE__ */ (0,J.jsxs)(`p`,{className:`font-readme flex items-center gap-2 text-sm text-muted-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(B,{className:`size-3`}),` Thinking, with no words for it…`]}):null,s?/* @__PURE__ */ (0,J.jsxs)(`div`,{children:[/* @__PURE__ */ (0,J.jsx)(Gn,{children:i.status===`succeeded`?`response`:`what had streamed`}),/* @__PURE__ */ (0,J.jsx)(qn,{text:s,renderMode:n})]}):a&&!o&&!t?.thinking?/* @__PURE__ */ (0,J.jsxs)(`p`,{className:`font-readme flex items-center gap-2 text-sm text-muted-foreground`,children:[/* @__PURE__ */ (0,J.jsx)(B,{className:`size-3`}),` Waiting for the first tokens…`]}):null,i.status===`failed`?/* @__PURE__ */ (0,J.jsxs)(`pre`,{"data-type":`error`,className:`overflow-x-auto whitespace-pre-wrap rounded-xl bg-destructive/5 px-4 py-2.5 font-mono text-xs leading-relaxed text-destructive`,children:[i.failureKind?`${i.failureKind}: `:``,i.errorMessage]}):null,i.status===`cancelled`?/* @__PURE__ */ (0,J.jsxs)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:[`Cancelled`,i.reason?`: ${i.reason}`:``]}):null,e.usage?/* @__PURE__ */ (0,J.jsx)(Vn,{usage:e.usage}):null,e.scriptRequestOffsets.map(e=>/* @__PURE__ */ (0,J.jsxs)(F,{variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>r(e),children:[`Ran a script: open its execution trace`,/* @__PURE__ */ (0,J.jsx)(h,{"data-icon":`inline-end`})]},e))]})}function Vn({usage:e}){let t=[];return e.inputTokens!==void 0&&t.push([`input tokens`,e.inputTokens.toLocaleString()]),e.cachedInputTokens!==void 0&&t.push([`cached input`,e.cachedInputTokens.toLocaleString()]),e.cacheWriteInputTokens!==void 0&&t.push([`cache written`,e.cacheWriteInputTokens.toLocaleString()]),e.outputTokens!==void 0&&t.push([`output tokens`,e.outputTokens.toLocaleString()]),e.reasoningOutputTokens!==void 0&&t.push([`reasoning`,e.reasoningOutputTokens.toLocaleString()]),e.costUsd!==void 0&&t.push([`cost`,Un(e.costUsd)]),/* @__PURE__ */ (0,J.jsxs)(`div`,{children:[/* @__PURE__ */ (0,J.jsxs)(Gn,{children:[`usage`,e.estimated?` (estimated: the provider gave no count)`:``]}),/* @__PURE__ */ (0,J.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 font-mono text-xs`,children:t.map(([e,t])=>/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`contents`,children:[/* @__PURE__ */ (0,J.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,J.jsx)(`dd`,{children:t})]},e))})]})}function Hn(e){let t=[];return e.inputTokens!==void 0&&t.push(`${e.inputTokens.toLocaleString()} in${e.cachedInputTokens?` (${e.cachedInputTokens.toLocaleString()} cached)`:``}`),e.outputTokens!==void 0&&t.push(`${e.outputTokens.toLocaleString()} out`),e.costUsd!==void 0&&t.push(Un(e.costUsd)),t.join(` · `)}const Un=e=>`$${e<.01?e.toPrecision(3):e.toFixed(2)}`;function Wn({outcome:e}){if(e.status===`in flight`)return/* @__PURE__ */ (0,J.jsx)(J.Fragment,{children:` · in flight`});let t=e.durationMs===void 0?``:` in ${G(e.durationMs)}`;return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[` · `,/* @__PURE__ */ (0,J.jsxs)(`span`,{className:P(e.status===`succeeded`&&`text-success`,e.status===`failed`&&`text-destructive`,e.status===`cancelled`&&`text-warning`),children:[e.status,t]})]})}function Gn({children:e}){return/* @__PURE__ */ (0,J.jsx)(`p`,{className:`mb-1 font-mono text-2xs uppercase tracking-wider text-muted-foreground/60`,children:e})}function Kn({name:e}){return/* @__PURE__ */ (0,J.jsx)(`span`,{className:P(`font-mono text-2xs font-semibold uppercase tracking-wider text-muted-foreground`,e===`instructions`&&`text-foreground`,e===`user`&&`text-info`,e===`assistant`&&`text-success`),children:e})}function qn({text:e,renderMode:t}){return t===`markdown`?/* @__PURE__ */ (0,J.jsx)(De,{className:`min-w-0 max-w-full overflow-hidden text-sm`,mode:`static`,parseIncompleteMarkdown:!1,children:e}):/* @__PURE__ */ (0,J.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground`,children:e})}const Jn=`Reading the log…`;function Yn({events:e,live:t,items:n,inspected:r,readProgress:i,onInspect:a}){let o=i!==void 0,s=r?.kind===`llmRequest`?t?.steps.find(e=>e.kind===`llm`&&e.status===`running`&&e.llmRequestOffset===r.llmRequestOffset):void 0;return/* @__PURE__ */ (0,J.jsx)(ue,{open:!!r,onOpenChange:e=>!e&&a(null),children:/* @__PURE__ */ (0,J.jsxs)(fe,{side:`right`,className:`flex flex-col gap-0 p-0 data-[side=right]:w-full data-[side=right]:sm:w-[min(92vw,64rem)] data-[side=right]:sm:max-w-[92vw]`,children:[i===void 0?null:/* @__PURE__ */ (0,J.jsx)(`div`,{className:`shrink-0 px-4 pt-4 pr-12`,children:/* @__PURE__ */ (0,J.jsx)(ce,{label:`Reading the log`,value:i})}),r?.kind===`llmRequest`?/* @__PURE__ */ (0,J.jsx)(Xn,{events:e,llmRequestOffset:r.llmRequestOffset,liveStep:s,items:n,reading:o,onInspect:a}):r?.kind===`scriptRun`?/* @__PURE__ */ (0,J.jsx)(Qn,{events:e,requestOffset:r.requestOffset,reading:o}):null]})})}function Xn({events:e,llmRequestOffset:t,liveStep:n,items:r,reading:i,onInspect:a}){let o=(0,q.useMemo)(()=>An(e,t),[e,t]);return o?/* @__PURE__ */ (0,J.jsx)(Ln,{trace:o,step:n||Zn(r,t),onScript:e=>a({kind:`scriptRun`,requestOffset:e})}):/* @__PURE__ */ (0,J.jsxs)(H,{children:[/* @__PURE__ */ (0,J.jsxs)(V,{children:[`LLM trace #`,t]}),/* @__PURE__ */ (0,J.jsx)(U,{children:i?Jn:`No LLM request at offset #${String(t)} on this path.`})]})}function Zn(e,t){for(let n of e?.toReversed()??[]){if(n.kind!==`activity`)continue;let e=n.steps.find(e=>e.kind===`llm`&&e.llmRequestOffset===t);if(e)return e}}function Qn({events:e,requestOffset:t,reading:n}){let r=Ue(e,t);if(!r)return/* @__PURE__ */ (0,J.jsxs)(H,{children:[/* @__PURE__ */ (0,J.jsxs)(V,{children:[`Script run #`,t]}),/* @__PURE__ */ (0,J.jsx)(U,{children:n?Jn:`No script run requested at offset #${String(t)} on this path.`})]});let i=r.settlement?.value,a=i?.status===`failed`;return/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[/* @__PURE__ */ (0,J.jsxs)(H,{className:`shrink-0 pr-12`,children:[/* @__PURE__ */ (0,J.jsxs)(V,{className:`truncate`,children:[`Script run #`,t]}),/* @__PURE__ */ (0,J.jsxs)(U,{children:[W(r.requestedAtMs),r.settlement?/* @__PURE__ */ (0,J.jsxs)(J.Fragment,{children:[` · `,/* @__PURE__ */ (0,J.jsxs)(`span`,{className:a?`text-destructive`:`text-success`,children:[a?`failed`:`succeeded`,` in`,` `,G(r.settlement.atMs-r.requestedAtMs)]})]}):` · running`]})]}),/* @__PURE__ */ (0,J.jsxs)(I,{defaultValue:`code`,className:`min-h-0 flex-1 gap-0`,children:[/* @__PURE__ */ (0,J.jsxs)(R,{variant:`line`,className:`mx-4 h-8 shrink-0`,children:[/* @__PURE__ */ (0,J.jsx)(z,{value:`code`,children:`Code`}),/* @__PURE__ */ (0,J.jsx)(z,{value:`result`,children:`Result`}),/* @__PURE__ */ (0,J.jsx)(z,{value:`agent`,children:`What the agent saw`})]}),/* @__PURE__ */ (0,J.jsx)(L,{value:`code`,className:`min-h-0 flex-1 overflow-y-auto border-t p-4`,children:/* @__PURE__ */ (0,J.jsx)(K,{code:r.code,language:`typescript`})}),/* @__PURE__ */ (0,J.jsx)(L,{value:`result`,className:`min-h-0 flex-1 overflow-y-auto border-t p-4`,children:i?/* @__PURE__ */ (0,J.jsx)($e,{data:i}):/* @__PURE__ */ (0,J.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Not settled yet.`})}),/* @__PURE__ */ (0,J.jsx)(L,{value:`agent`,className:`min-h-0 flex-1 overflow-y-auto border-t p-4`,children:r.seen?/* @__PURE__ */ (0,J.jsx)(De,{className:`min-w-0 max-w-full overflow-hidden text-sm`,mode:`static`,parseIncompleteMarkdown:!1,children:r.seen}):/* @__PURE__ */ (0,J.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`No request of the agent has read this run's result yet. A script that returns nothing starts no request: the next request reads its result.`})})]})]})}function $n({messages:e,isInterrupting:t,onInterrupt:n,signedUrl:r,me:i}){let[a,o]=(0,q.useState)(!1),s=e.filter(e=>!e.from);if(s.length===0)return null;let c=s.length-1;return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`-mb-4 rounded-t-3xl border border-b-0 bg-muted/40 px-3 pb-6 pt-1.5`,"data-testid":`queued-messages-panel`,children:[/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex items-center gap-2 px-1.5 py-1`,children:[/* @__PURE__ */ (0,J.jsx)(`span`,{className:`min-w-0 truncate font-mono text-2xs text-muted-foreground`,children:`Queued for the next agent turn`}),c>0?/* @__PURE__ */ (0,J.jsx)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`shrink-0 font-mono text-2xs text-muted-foreground underline-offset-2 hover:underline sm:hidden`,children:a?`collapse`:`+${String(c)} more`}):null,n?/* @__PURE__ */ (0,J.jsxs)(F,{variant:`ghost`,size:`sm`,onClick:()=>void n(),disabled:t,className:`ml-auto h-6 shrink-0 gap-1 px-2 text-2xs text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[t?/* @__PURE__ */ (0,J.jsx)(B,{className:`size-3`}):/* @__PURE__ */ (0,J.jsx)(w,{className:`size-3 text-current`}),`Interrupt & send now`]}):null]}),/* @__PURE__ */ (0,J.jsx)(`div`,{className:`flex max-h-40 flex-col gap-1 overflow-y-auto`,children:s.map((e,t)=>/* @__PURE__ */ (0,J.jsxs)(`div`,{className:P(`rounded-xl border bg-background/80 px-3 py-1.5 text-sm`,!a&&t<s.length-1&&`hidden sm:block`),children:[e.sender&&e.saidBy?/* @__PURE__ */ (0,J.jsx)(ut,{principal:e.sender,words:Ge(e.sender,i)?`You`:e.saidBy,className:`mb-1`,"data-queued-by":!0}):null,/* @__PURE__ */ (0,J.jsx)(dn,{item:e,signedUrl:r})]},e.id))})]})}const er={state:Ne(),items:[]};function tr(e){if(`progress`in e){let{text:t,working:n,activity:r}=e.progress;return!n&&t===`Idle`?null:/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col`,"data-testid":`agent-progress`,children:[/* @__PURE__ */ (0,J.jsx)(Z,{text:t,working:n}),n&&r?/* @__PURE__ */ (0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r}):null]})}return/* @__PURE__ */ (0,J.jsx)(nr,{...e})}function nr({context:e,error:t}){let{turn:n,feed:r}=rr(e),i=lr(n,r.state),a=!e.liveState.agent&&e.processors.loaded&&!e.processors.error,o=t||e.error;if(a&&!o)return null;if(o||n.liveUnavailable)return/* @__PURE__ */ (0,J.jsx)(Z,{text:o||`Agent status unavailable`,working:!1});if(!e.caughtUp||i.tone===`muted`)return null;let s=Me(r.state)?.statusText;return/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`flex flex-col`,"data-testid":`agent-progress`,children:[/* @__PURE__ */ (0,J.jsx)(Z,{text:i.text,working:i.tone===`live`}),s&&i.tone===`live`&&!i.text.includes(s)?/* @__PURE__ */ (0,J.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s}):null]})}function rr(e){let[t]=(0,q.useState)(()=>Ze(Be)),n=(0,q.useMemo)(()=>t(e.events),[t,e.events]),r=cr(e),{idle:i,requestMayBeOpen:a}=r;return{fold:n,turn:r,feed:(0,q.useMemo)(()=>e.caughtUp?He(n,i,a):er,[e.caughtUp,n,i,a]),older:!e.error&&n.versionEndedAt===null&&e.older||Je}}function ir({path:e,context:t,error:n,state:r,onStateChange:i,onMessage:a,onAppend:o,storeFiles:s,signedUrl:c,itemFooter:l,strip:u=!0,aboveComposer:d,empty:f,placeholder:p=`Message this agent`,eventsTab:m=!0,tabsInHeader:h,asideIn:g,attach:_=!0,onChoice:v,choiceState:y,me:b,presence:x=!1,inCall:S,mind:C,widgetCalls:w}){let{fold:T,turn:ee,feed:E,older:D}=rr(t),te=pr(t),[ne,re]=gr(),O=Ke(),ie=or(),{inspected:ae,inspect:k,onInspect:A}=_r(r,i);hr(te,r,i);let j=bn(ae,D,T.events),M=t.caughtUp&&!D.exhausted&&E.items.length===0&&!E.state.live;vr(j,D,T.events);let N=Ye(T.events,t.head),P=(0,q.useMemo)(()=>o?e=>oe(e,{onAppend:o,onMessage:a,storeFiles:s}):a,[o,a,s]),F=(0,q.useCallback)((e,t)=>{P({message:e,files:[],key:`widget:${crypto.randomUUID()}`,widget:t})},[P]),{setMessage:se}=O,I=(0,q.useCallback)(e=>se(t=>t.trim()?`${t}\n\n${e}`:e),[se]),L=lr(ee,E.state,(S?.size??0)>0),R=xe({enabled:x,rows:t.processors.rows,rpcStubs:t.presence.rpcStubs,events:T.events,send:o,me:b,subscription:t.subscription}),z=(0,q.useMemo)(()=>ar(E.items,b),[E.items,b]),B=(0,q.useMemo)(()=>R.present.filter(e=>!e.me&&e.typing),[R.present]),ce=(0,q.useMemo)(()=>t.events.some(be)?{...t,events:t.events.filter(e=>!be(e))}:t,[t]);return/* @__PURE__ */ (0,J.jsx)(Qe,{path:e,context:ce,error:n,state:r,onStateChange:i,onAppend:o,status:L,strip:u,eventsTab:m,tabsInHeader:h,aside:x?/* @__PURE__ */ (0,J.jsx)(ve,{present:R.present,wrote:z,inCall:S,mind:C}):null,asideIn:g,closeSheet:yn,sheet:/* @__PURE__ */ (0,J.jsx)(Yn,{events:T.events,live:E.state.live,items:E.items,inspected:ae,readProgress:j?N:void 0,onInspect:A}),children:/* @__PURE__ */ (0,J.jsx)(we,{onChoice:v,choiceState:y,children:/* @__PURE__ */ (0,J.jsx)(At,{events:T.events,onSend:F,onDraft:I,path:e,calls:w,onAppend:o,children:/* @__PURE__ */ (0,J.jsx)(dr,{feed:E,conversation:te,older:D,logShare:N,caughtUp:t.caughtUp,failed:!!(n||t.error),readingForFirstRow:M,toggled:ne,onToggle:re,inspect:k,signedUrl:c,itemFooter:l,me:b,agentPath:e,statusRow:u?null:ur(L,E.state),aboveComposer:d,empty:f,placeholder:p,draft:O,keys:ie,onMessage:P,onAppend:o,attach:_,typingStatus:x?/* @__PURE__ */ (0,J.jsx)(_e,{typing:B}):null,onTyping:x?R.typing:void 0,typing:B})})})})}ir.contextOptions={consumes:[`*`,M.llmResponseFrame,...ye]};function ar(e,t){let n=/* @__PURE__ */ new Map;for(let r of e)r.kind===`user`&&r.sender&&!Ge(r.sender,t)&&n.set(r.sender.actor,n.get(r.sender.actor)||r.sender);return[...n.values()]}function or(){let[e]=(0,q.useState)(()=>crypto.randomUUID().slice(0,12)),t=(0,q.useRef)({count:0});return(0,q.useMemo)(()=>({keyFor(n){let r=JSON.stringify([n.message,n.files.map(e=>[e.filename,e.contentType,sr(e.data)])]);return t.current.message!==r&&(t.current.count+=1),t.current.message=r,`${e}:${String(t.current.count)}`},sent(){t.current.message=void 0}}),[e])}function sr(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return`${String(e.length)}:${(t>>>0).toString(16)}`}function cr({liveState:e,processors:t}){let n=e.agent,r=n?n.status===`error`:!!t.error||t.loaded&&!t.rows.some(e=>e.hostedFacet?.name===`agent`),i=A(n?.value),a=i&&i.llmRequests.length===0&&i.pendingTriggerOffsets.length===0&&i.scriptCalls.every(e=>e.answered);return{facet:i,liveUnavailable:r,detail:n?.error||t.error,idle:i?!!a:r,requestMayBeOpen:!a}}function lr({facet:e,liveUnavailable:t,detail:n},r,i=!1){if(!e)return{text:t?`Live state unavailable`:``,tone:`muted`,detail:n};if(e.paused)return{text:`Paused — ${e.paused.reason}`,tone:`amber`};let{live:a}=r,o=Me(r)?.statusText;if(a?.steps.some(e=>e.kind===`code`&&e.status===`running`))return{text:`Running a script${o?` · ${o}`:``}`,tone:`live`};let s=e.llmRequests.find(e=>e.purpose===`answer`)??e.llmRequests[0];return s?{text:`Thinking · ${s.model}`,tone:`live`}:e.pendingTriggerOffsets.length>0?{text:`About to think`,tone:`live`}:e.scriptCalls.some(e=>!e.answered)?{text:`About to run a script`,tone:`live`}:{text:i?``:`Idle`,tone:`muted`}}function ur({text:e,tone:t},n){return t===`amber`?/* @__PURE__ */ (0,J.jsx)(Z,{text:e,working:!1}):t===`live`&&!ke(n)?/* @__PURE__ */ (0,J.jsx)(Z,{text:`Working…`,working:!0}):null}function dr({feed:e,conversation:t,older:n,logShare:r,caughtUp:i,failed:a,readingForFirstRow:o,toggled:s,onToggle:c,inspect:l,signedUrl:u,itemFooter:d,me:f,agentPath:p,statusRow:m,aboveComposer:h,empty:g,placeholder:_,draft:v,keys:y,onMessage:b,onAppend:x,attach:S,typingStatus:C,onTyping:w,typing:T}){let[ee,E]=(0,q.useState)(0),D=yr({runningLlmRequestId:e.state.live?.steps.findLast(e=>e.kind===`llm`&&e.status===`running`)?.llmRequestOffset,onInterrupt:x?async()=>{await x([{type:`events.iterate.com/agent/context-added`,payload:{role:`developer`,content:`The user interrupted the in-progress response from the web chat.`,llmRequestPolicy:{behaviour:`interrupt-current-request`}}}])}:void 0});return/* @__PURE__ */ (0,J.jsx)(gn,{feed:e,older:n,logShare:r,followTail:ee+t,empty:/* @__PURE__ */ (0,J.jsx)(fr,{caughtUp:i,failed:a,readProgress:o?r:void 0,empty:g}),after:m,footer:/* @__PURE__ */ (0,J.jsx)(`div`,{className:`pointer-events-none bg-linear-to-t from-background from-80% to-transparent px-2 pt-2 pb-[max(0.5rem,env(safe-area-inset-bottom))] sm:px-4 sm:pt-4 sm:pb-[max(1rem,env(safe-area-inset-bottom))] md:px-6`,children:/* @__PURE__ */ (0,J.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl`,children:[/* @__PURE__ */ (0,J.jsx)(se,{}),C,h,/* @__PURE__ */ (0,J.jsx)($n,{messages:e.state.queuedUserMessages,isInterrupting:D?.isInterrupting||!1,onInterrupt:D?.run,signedUrl:u,me:f}),/* @__PURE__ */ (0,J.jsx)(qe,{draft:v,placeholder:_,autoFocusMessage:!0,attach:S,interrupt:D,onTyping:w,onSubmit:async e=>{E(e=>e+1),await b({...e,key:y.keyFor(e)}),y.sent()},onAppendRaw:async e=>{if(!x)throw Error(`not connected`);E(e=>e+1),await x(e)}})]})}),toggledIds:s,onToggle:c,inspect:l,signedUrl:u,itemFooter:d,me:f,agentPath:p,typing:T})}function fr({caughtUp:e,failed:t,readProgress:n,empty:r}){return t?null:!e||n!==void 0?/* @__PURE__ */ (0,J.jsx)(le,{progress:n}):r?/* @__PURE__ */ (0,J.jsx)(`div`,{"data-slot":`agent-chat-empty`,className:`flex h-full items-center justify-center py-6`,children:r}):/* @__PURE__ */ (0,J.jsx)(et,{className:`py-16`,children:/* @__PURE__ */ (0,J.jsxs)(nt,{children:[/* @__PURE__ */ (0,J.jsx)(rt,{children:`Nothing said yet`}),/* @__PURE__ */ (0,J.jsx)(tt,{children:`Say something below. The agent answers with prose, or with a script it runs against the mind.`})]})})}function pr(e){let t=r(e),[n,i]=(0,q.useState)({version:t,count:0});return t&&t!==n.version&&i({version:t,count:n.version?n.count+1:n.count}),n.count}const mr={...yn,event:void 0};function hr(e,t,n){let r=(0,q.useRef)(e),i=!!(t.llmRequest||t.scriptRun||t.event);(0,q.useEffect)(()=>{r.current!==e&&(r.current=e,i&&n(mr))},[e,i,n])}function gr(){let[e,t]=(0,q.useState)(()=>/* @__PURE__ */ new Set);return[e,(0,q.useCallback)(e=>t(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),[])]}function _r(e,t){let n=e.llmRequest?{kind:`llmRequest`,llmRequestOffset:e.llmRequest}:e.scriptRun?{kind:`scriptRun`,requestOffset:e.scriptRun}:null,r=(0,q.useCallback)(e=>t({...N,llmRequest:e?.kind===`llmRequest`?e.llmRequestOffset:void 0,scriptRun:e?.kind===`scriptRun`?e.requestOffset:void 0}),[t]);return{inspected:n,inspect:(0,q.useMemo)(()=>({llmRequest:e=>r({kind:`llmRequest`,llmRequestOffset:e}),scriptRun:e=>r({kind:`scriptRun`,requestOffset:e})}),[r]),onInspect:r}}function vr(e,t,n){let{loadOlder:r,loading:i}=t,a=n[0]?.offset;(0,q.useEffect)(()=>{e&&!i&&r()},[e,i,r,a])}function yr(e){let[t,n]=(0,q.useState)(!1),[r,i]=(0,q.useState)(),{onInterrupt:a,runningLlmRequestId:o}=e,[s,c]=(0,q.useState)(o);return s!==o&&(c(o),i(void 0)),!a||o===void 0?null:{isInterrupting:t,error:r,run:async()=>{if(!t){n(!0),i(void 0);try{await a()}catch(e){i(e instanceof Error?e.message:String(e))}finally{n(!1)}}}}}export{gr as a,yn as c,vr as i,bn as l,tr as n,_r as o,rr as r,Yn as s,ir as t,Nt as u}; +`||i&&(e===` `||e===` `),l++}return c(t.length,s),{parts:a,end:{fence:n,tick:r,lineStart:i}}}const xt=(0,K.memo)(function({blocks:e,firstBlock:t,tailBlock:n,tailOffset:r,literal:i,...a}){let o=a;return Object.entries(e).map(([e,a])=>{if(Number(e)<t)return null;let s=o;return i||(o=Y(o,a).next),/* @__PURE__ */ (0,q.jsx)(St,{text:a,...s,literal:i,revealFrom:Number(e)===n?r:null},e)})}),St=(0,K.memo)(function({text:e,literal:t,revealFrom:n,...r}){let i=t?e:Y(r,e).text;if(typeof n!=`number`)return/* @__PURE__ */ (0,q.jsx)(`span`,{children:i});let a=t?e.slice(0,n):Y(r,e.slice(0,n)).text,o=0;for(;o<a.length&&a[o]===i[o];)o++;let s=i.slice(o),c=[...s.matchAll(/\S+\s*|\s+/g)],l=c.length<=64?c:[{0:s,index:0}];return/* @__PURE__ */ (0,q.jsxs)(`span`,{children:[i.slice(0,o),l.map(e=>/* @__PURE__ */ (0,q.jsx)(`span`,{className:`animate-token-in motion-reduce:animate-none`,style:{animationDelay:`${Math.round(e.index/s.length*140)}ms`},children:e[0]},o+e.index))]})});function Ct({code:e}){return/* @__PURE__ */ (0,q.jsxs)(`pre`,{className:`whitespace-pre-wrap rounded-xl bg-warning/10 px-4 py-3 font-mono text-xs leading-relaxed text-foreground wrap-break-word`,children:[/* @__PURE__ */ (0,q.jsx)(J,{text:e,literal:!0}),/* @__PURE__ */ (0,q.jsx)(X,{className:`bg-warning`})]})}function X({className:e}){return/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`ml-px inline-block h-3.5 w-[7px] animate-caret-blink bg-muted-foreground/40 align-[-2px]`,e)})}function wt(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)+e.length.toString(36)}const Tt=/* @__PURE__ */ new Map;function Et(e){for(let t=e.parentElement;t;t=t.parentElement)if(/(auto|scroll)/.test(getComputedStyle(t).overflowY))return t;return e.ownerDocument.scrollingElement}function Dt(e,t,n){let r=e.ownerDocument.defaultView;if(!r)return;let i=(t,n)=>e.dispatchEvent(Object.assign(new r.Event(t,{bubbles:!0}),{touches:n}));`wheel`in t?(e.dispatchEvent(new r.WheelEvent(`wheel`,{deltaY:t.wheel,bubbles:!0})),Et(e)?.scrollBy(0,t.wheel)):t.touch===`start`?(n.y=0,i(`touchstart`,[{clientY:0}])):t.touch===`move`?(n.y-=t.by,i(`touchmove`,[{clientY:n.y}])):i(`touchend`,[])}function Ot({widget:e,onSend:t,onLog:n,onCallTool:r,onReadResource:i,onReadContext:a,onModelContext:o,onDraft:s,className:c}){let l=(0,K.useRef)(null),u=(0,K.useRef)(null),[d,f]=(0,K.useState)(null),[p,m]=(0,K.useState)(()=>Tt.get(e.key)??e.height??120),[h,g]=(0,K.useState)(!1),_=(0,K.useRef)(0),v=(0,K.useRef)(!1),y=(0,K.useRef)(!1),b=(0,K.useRef)({y:0}),x=e.html.length>ne(e),S=(0,K.useRef)(0);(0,K.useLayoutEffect)(()=>{f(oe(l.current))},[]);let ee=ie(e.csp),C=!!e.app,w=(0,K.useMemo)(()=>x||!d?``:T({html:e.html,data:e.data,csp:e.csp,app:e.app},d),[e.html,d,x,ee,C]),E=e.app?JSON.stringify([e.app.server,e.app.headers||{}]):``,O=`${(0,K.useMemo)(()=>wt(w),[w])}:${E}`;(0,K.useLayoutEffect)(()=>{y.current=!1,_.current=0,v.current=!1},[O]);let k=(0,K.useCallback)(e=>{v.current||u.current?.contentWindow?.postMessage(e,`*`)},[]),A=(e,t)=>{if(S.current>=4){k({jsonrpc:`2.0`,id:e,error:{code:-32e3,message:`Too many calls are open; try again when one ends.`}});return}S.current+=1;let n=u.current?.contentWindow,r=t=>{n&&!v.current&&u.current?.contentWindow===n&&n.postMessage({jsonrpc:`2.0`,id:e,...t},`*`)};t().then(e=>r({result:e}),e=>{let t=e instanceof Error?e.message:String(e);r({error:{code:-32e3,message:t.slice(0,2e3)}})}).finally(()=>{--S.current})},se=(0,K.useEffectEvent)(c=>{if(!u.current||v.current||c.source!==u.current.contentWindow||!d)return;let f=te(c.data,{widget:e,theme:d,width:l.current?.clientWidth,pressed:(navigator.userActivation?.isActive??!1)&&document.activeElement===u.current,canSend:!!t,canDraft:!!s,canCallServer:!!(r&&i),canModelContext:!!o,canReadContext:!!a});f.reply&&k(f.reply);let{callTool:p,readResource:h,readContext:g}=f;g&&a&&A(g.id,()=>a({widget:e,context:g.context,after:g.after,limit:g.limit})),p&&r&&A(p.id,()=>r({widget:e,name:p.name,arguments:p.arguments})),h&&i&&A(h.id,()=>i({widget:e,uri:h.uri})),f.height!==void 0&&(Tt.set(e.key,f.height),m(f.height)),f.modelContext&&o?.({widget:e,...f.modelContext}),f.initialized&&(y.current=!0,k({jsonrpc:`2.0`,method:`ui/notifications/tool-input`,params:{arguments:re(e)}}),k({jsonrpc:`2.0`,method:`ui/notifications/tool-result`,params:D(e)})),(f.send||f.draft||f.open)&&l.current?.focus({preventScroll:!0}),f.draft&&s?.(f.draft),f.send&&t?.(f.send,{key:e.key,offset:e.offset}),f.log&&n?.({...f.log,key:e.key}),f.scrolled&&u.current&&Dt(u.current,f.scrolled,b.current),f.open&&window.open(f.open,`_blank`,`noopener,noreferrer`)});(0,K.useEffect)(()=>{let e=e=>se(e);return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[]);let j=(0,K.useEffectEvent)(()=>{y.current&&k({jsonrpc:`2.0`,method:`ui/notifications/tool-result`,params:D(e)})}),{data:M,text:P}=e;return(0,K.useEffect)(()=>j(),[M,P]),/* @__PURE__ */ (0,q.jsxs)(`figure`,{ref:l,className:N(`my-2 outline-none`,c),tabIndex:-1,"data-kind":`widget`,"data-widget":e.key,children:[e.app?/* @__PURE__ */ (0,q.jsxs)(`figcaption`,{className:`flex gap-1.5 pb-1 text-xs text-muted-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(`span`,{className:`font-medium text-foreground`,"data-widget-server":!0,children:ae(e.app)}),e.title?/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`truncate`,children:[`· `,e.title]}):null]}):null,/* @__PURE__ */ (0,q.jsx)(`div`,{className:N(e.app?.prefersBorder&&`overflow-hidden rounded-xl border`),"data-widget-border":e.app?.prefersBorder?``:void 0,children:d?x||h?/* @__PURE__ */ (0,q.jsx)(`p`,{className:`whitespace-pre-wrap py-1 text-sm`,children:e.text}):/* @__PURE__ */ (0,q.jsx)(`iframe`,{ref:u,title:e.title||e.text,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,srcDoc:w,className:`block w-full border-0 bg-transparent`,style:{height:p},onLoad:()=>{_.current+=1,_.current>1&&(v.current=!0,g(!0))}},O):/* @__PURE__ */ (0,q.jsx)(`div`,{style:{height:p}})})]})}const kt=(0,K.createContext)({fold:/* @__PURE__ */ new Map});function At({events:e,onSend:t,onDraft:n,path:r,calls:i,onAppend:a,children:o}){let s=(0,K.useMemo)(()=>E(e,void 0,r),[e,r]),c=(0,K.useMemo)(()=>Mt(r,i,a),[r,i,a]),l=(0,K.useMemo)(()=>({fold:s,onSend:t,onDraft:n,...c}),[s,t,n,c]);return/* @__PURE__ */ (0,q.jsx)(kt.Provider,{value:l,children:o})}function jt({widgetKey:e,offset:t}){let{fold:n,onSend:r,onDraft:i,onCallTool:a,onReadResource:o,onReadContext:s,onModelContext:c}=(0,K.useContext)(kt),l=n.get(e);return!l||l.first!==t?null:/* @__PURE__ */ (0,q.jsx)(Ot,{widget:l.widget,onSend:r,onDraft:i,onCallTool:a,onReadResource:o,onReadContext:s,onModelContext:c})}function Mt(e,t,n){let r=e=>{if(!e.app)throw Error(`This widget has no server.`);return e.app};return{...e&&t&&{onCallTool:({widget:n,name:i,arguments:a})=>{let{server:o,headers:s}=r(n);return t.callTool({path:e,key:n.key,server:o,headers:s,name:i,args:a})},onReadResource:({widget:n,uri:i})=>{let{server:a,headers:o}=r(n);return t.readResource({path:e,server:a,headers:o,uri:i})}},...e&&t?.readContext&&{onReadContext:({widget:n,context:r,after:i,limit:a})=>t.readContext({path:e,key:n.key,context:r,after:i,limit:a})},...n&&{onModelContext:({widget:e,content:t})=>{n([{type:w.context,payload:{key:e.key,server:e.app?.server,content:t}}]).catch(()=>void 0)}}}}const Nt=(0,K.memo)(function({item:e,expanded:t,onToggle:n,inspect:r,signedUrl:i,me:a,agentPath:o,continuesRun:s=!1}){switch(e.kind){case`user`:return e.from?/* @__PURE__ */ (0,q.jsx)(Ft,{item:e,from:e.from,agentPath:o,expanded:t,onToggle:n,signedUrl:i}):e.sender&&e.saidBy&&!Ke(e.sender,a)?/* @__PURE__ */ (0,q.jsx)(ft,{"data-kind":`user`,"data-from":`other`,principal:e.sender,name:e.saidBy,first:!s,children:/* @__PURE__ */ (0,q.jsx)(dn,{item:e,signedUrl:i})}):/* @__PURE__ */ (0,q.jsx)(ke,{from:`user`,className:`pb-2 pt-3.5`,"data-kind":`user`,children:/* @__PURE__ */ (0,q.jsxs)(Ee,{className:`group-[.is-user]:rounded-2xl`,children:[/* @__PURE__ */ (0,q.jsx)(pt,{children:`You`}),/* @__PURE__ */ (0,q.jsx)(dn,{item:e,signedUrl:i})]})});case`assistant`:return/* @__PURE__ */ (0,q.jsx)(ke,{from:`assistant`,className:`py-2`,"data-kind":`assistant`,children:/* @__PURE__ */ (0,q.jsxs)(Ee,{children:[/* @__PURE__ */ (0,q.jsx)(Oe,{className:`min-w-0 max-w-full`,mode:`static`,parseIncompleteMarkdown:!1,children:e.text}),/* @__PURE__ */ (0,q.jsx)(fn,{files:e.files,hasText:e.text!==``,signedUrl:i})]})});case`activity`:return/* @__PURE__ */ (0,q.jsx)(Bt,{activity:e,expanded:t,onToggle:n,inspect:r,me:a});case`background`:return/* @__PURE__ */ (0,q.jsx)(Pt,{item:e,expanded:t,onToggle:n,signedUrl:i});case`note`:return/* @__PURE__ */ (0,q.jsx)(Lt,{item:e,expanded:t,onToggle:n});case`widget`:return/* @__PURE__ */ (0,q.jsx)(jt,{widgetKey:e.key,offset:e.offset});case`stream-paused`:case`stream-resumed`:{let t=e.kind===`stream-paused`?h:p;return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex items-center gap-3 py-3`,"data-kind":e.kind,children:[/* @__PURE__ */ (0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`}),/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex min-w-0 shrink items-center gap-1.5 rounded-full bg-muted px-2.5 py-1 text-muted-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(t,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),/* @__PURE__ */ (0,q.jsx)(`time`,{className:`truncate text-xs font-medium`,title:U(e.timestampMs),children:e.reason?`${e.text}: ${e.reason}`:e.text})]}),/* @__PURE__ */ (0,q.jsx)(`div`,{className:`h-px flex-1 bg-border`})]})}}});function Pt({item:e,expanded:t,onToggle:n,signedUrl:r}){let i=e.messages.length;return/* @__PURE__ */ (0,q.jsxs)(Rt,{kind:`background`,icon:b,title:`Read by the agent, without starting a turn`,expanded:t,onToggle:()=>n(e.id),line:i===1?`1 message came in`:`${String(i)} messages came in`,children:[i>100?/* @__PURE__ */ (0,q.jsxs)(`p`,{children:[`The newest `,100,`. The Events tab has them all.`]}):null,e.messages.slice(-100).map(e=>/* @__PURE__ */ (0,q.jsx)(zt,{message:e,signedUrl:r},e.offset))]})}function Ft({item:e,from:t,agentPath:n,expanded:r,onToggle:i,signedUrl:a}){let o=t.split(`/`).findLast(Boolean)||t,s=!!n&&t.startsWith(`${n}/`);return/* @__PURE__ */ (0,q.jsx)(Rt,{kind:`report`,icon:m,title:t,expanded:r,onToggle:()=>i(e.id),line:/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[s?`${o} reported`:`${o} wrote`,/* @__PURE__ */ (0,q.jsx)(`time`,{dateTime:new Date(e.timestampMs).toISOString(),title:U(e.timestampMs),className:`ml-1.5 text-muted-foreground/60`,children:Ie(e.timestampMs)})]}),children:/* @__PURE__ */ (0,q.jsx)(zt,{message:e,signedUrl:a})})}const It={request:ee,subagent:x,slack:S};function Lt({item:e,expanded:t,onToggle:n}){let r=e.failed?_:It[e.about],i=/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(e.failed&&`text-destructive`),title:U(e.timestampMs),children:e.text});return e.detail?/* @__PURE__ */ (0,q.jsx)(Rt,{kind:`note`,icon:r,title:e.text,expanded:t,onToggle:()=>n(e.id),line:i,children:/* @__PURE__ */ (0,q.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.detail})}):/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex h-8 min-w-0 items-center gap-1.5 text-sm text-muted-foreground`,"data-kind":`note`,children:[/* @__PURE__ */ (0,q.jsx)(r,{className:`size-4 shrink-0 text-muted-foreground/60`,"aria-hidden":`true`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`min-w-0 truncate`,children:i})]})}function Rt({kind:e,icon:t,title:n,line:r,expanded:i,onToggle:a,children:o}){return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col py-0.5`,"data-kind":e,children:[/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`sm`,"aria-expanded":i,title:n,onClick:a,className:`-ml-2.5 max-w-full self-start font-normal text-muted-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(t,{"data-icon":`inline-start`,className:`text-muted-foreground/60`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`min-w-0 truncate`,children:r}),/* @__PURE__ */ (0,q.jsx)(y,{"data-icon":`inline-end`,className:N(`text-muted-foreground/50 transition-transform`,i&&`rotate-90`)})]}),i?/* @__PURE__ */ (0,q.jsx)(`div`,{className:`mb-1.5 ml-1 mt-0.5 flex min-w-0 flex-col gap-1.5 border-l-2 border-muted py-1 pl-4 text-xs leading-5 text-muted-foreground`,children:o}):null]})}function zt({message:e,signedUrl:t}){return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`min-w-0`,title:U(e.timestampMs),children:[e.text===``?null:/* @__PURE__ */ (0,q.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word`,children:e.text}),/* @__PURE__ */ (0,q.jsx)(fn,{files:e.files,hasText:e.text!==``,signedUrl:t})]})}function Bt({activity:e,expanded:t,onToggle:n,inspect:r,me:i}){let a=Ge(e),o=a.outcome===`failed`,s=[...e.steps].reverse().flatMap(e=>e.kind===`code`&&e.activitySummary?[e.activitySummary]:[]).at(0);return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col py-0.5`,"data-kind":`activity`,children:[/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`sm`,"aria-expanded":t,title:`Agent activity — click to see what it did`,onClick:()=>n(e.id),className:N(`-ml-2.5 max-w-full self-start font-medium text-muted-foreground`,o&&`text-destructive hover:text-destructive`),children:[o?/* @__PURE__ */ (0,q.jsx)(_,{"data-icon":`inline-start`,className:`text-destructive`}):a.outcome===`interrupted`?/* @__PURE__ */ (0,q.jsx)(f,{"data-icon":`inline-start`,className:`text-destructive`}):/* @__PURE__ */ (0,q.jsx)(C,{"data-icon":`inline-start`,className:`text-muted-foreground/60`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`min-w-0 truncate`,children:!s||a.outcome!==`clean`?`${s?`${s} · `:``}${Be(e,{summary:a,interruptedPartialHint:`click to see partial response`,me:i})}`:[s,e.endedAtMs?W(Math.max(0,e.endedAtMs-e.startedAtMs)):``].filter(Boolean).join(` · `)}),/* @__PURE__ */ (0,q.jsx)(y,{"data-icon":`inline-end`,className:N(`text-muted-foreground/50 transition-transform`,t&&`rotate-90`)})]}),t?/* @__PURE__ */ (0,q.jsx)(`div`,{className:`mb-1.5 ml-1 mt-0.5 flex flex-col gap-1 border-l-2 border-muted py-1 pl-4`,children:/* @__PURE__ */ (0,q.jsx)(Vt,{rounds:Fe(e.steps),inspect:r})}):null]})}function Vt({rounds:e,inspect:t}){return e.length===1?/* @__PURE__ */ (0,q.jsx)(Wt,{round:e[0],inspect:t}):/* @__PURE__ */ (0,q.jsx)(q.Fragment,{children:e.map((e,n)=>/* @__PURE__ */ (0,q.jsx)(Ht,{round:e,index:n,inspect:t},e.code?.id||e.llm?.id))})}function Ht({round:e,index:t,inspect:n}){let[r,i]=(0,K.useState)(null),a=e.code?.status===`running`||e.llm?.status===`running`,o=r??e.code?.status===`running`,s=e.code?.success===!1||e.llm?.outcome===`failed`;return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col items-start`,children:[/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`xs`,"aria-expanded":o,onClick:()=>i(!o),className:N(`-ml-2 max-w-full self-start font-normal`,s&&`text-destructive hover:text-destructive`),children:[/* @__PURE__ */ (0,q.jsxs)(`span`,{className:N(`shrink-0 font-mono text-xs text-foreground/70`,s&&`text-destructive`),children:[`Round `,t+1]}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`min-w-0 truncate font-mono text-xs text-muted-foreground/70`,a&&!s&&`shimmer text-foreground/85`),children:Ut(e)}),/* @__PURE__ */ (0,q.jsx)(y,{"data-icon":`inline-end`,className:N(`text-muted-foreground/50 transition-transform`,o&&`rotate-90`)})]}),o?/* @__PURE__ */ (0,q.jsx)(`div`,{className:`w-full py-1`,children:/* @__PURE__ */ (0,q.jsx)(Wt,{round:e,inspect:n})}):null]})}function Ut(e){let t=[];return e.code?.activitySummary?t.push(e.code.activitySummary):e.llm&&t.push(Ie(e.llm.startedAtMs)),e.llm?.durationMs!=null&&t.push(`model ${W(e.llm.durationMs)}`),e.code?.durationMs!=null&&t.push(`script ${W(e.code.durationMs)}`),t.join(` · `)}function Wt({round:e,inspect:t}){return e.code?/* @__PURE__ */ (0,q.jsx)(Xt,{llm:e.llm,code:e.code,inspect:t}):e.llm?/* @__PURE__ */ (0,q.jsx)(qt,{llm:e.llm,inspect:t}):null}function Gt(e){return e.status===`running`?e.responseText.length>0?`Writing code`:e.thinking||e.thinkingText.length>0?`Thinking`:`Waiting for a response`:e.outcome===`failed`?`Request failed`:e.outcome===`cancelled`?e.cancelReason===`expired`?`Request expired`:e.cancelReason===`superseded`?`Another response answered first`:`Request cancelled`:e.model||`Response`}function Kt(e){let t=[Ie(e.startedAtMs)];return e.durationMs!=null&&t.push(W(e.durationMs)),t.join(` · `)}function qt({llm:e,inspect:t}){return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col items-start gap-1.5`,children:[/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-1.5`,children:[/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`font-mono text-xs text-foreground/70`,e.outcome!==`completed`&&`text-destructive`),children:Gt(e)}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground/70`,children:Kt(e)}),/* @__PURE__ */ (0,q.jsx)(Yt,{onClick:()=>t.llmRequest(e.llmRequestOffset)})]}),/* @__PURE__ */ (0,q.jsx)(Jt,{llm:e})]})}function Jt({llm:e}){let t=je(e.responseText);return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[t.length===0?null:Le(t)?/* @__PURE__ */ (0,q.jsx)(`div`,{className:N(`w-full max-w-2xl`,e.interpreted&&`opacity-75`),children:/* @__PURE__ */ (0,q.jsx)(G,{code:t,language:`typescript`,showLineNumbers:!1})}):/* @__PURE__ */ (0,q.jsx)(`div`,{className:N(`max-w-2xl whitespace-pre-wrap px-1.5 text-sm leading-relaxed`,e.interpreted&&`text-muted-foreground`),children:t}),e.errorMessage?/* @__PURE__ */ (0,q.jsx)(`pre`,{"data-type":`error`,className:`max-w-2xl whitespace-pre-wrap px-1.5 font-mono text-xs text-destructive`,children:e.errorMessage}):null]})}function Yt({onClick:e}){return/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`xs`,title:`Open this LLM request trace`,onClick:e,className:`-ml-1 font-normal text-muted-foreground`,children:[`Full trace`,/* @__PURE__ */ (0,q.jsx)(y,{"data-icon":`inline-end`,className:`text-muted-foreground/50`})]})}function Xt({llm:e,code:t,inspect:n}){let[r,i]=(0,K.useState)(`script`),a=t.status===`done`,o=r===`result`&&!a?`script`:r,s=Re(t.code),c=!!s;return/* @__PURE__ */ (0,q.jsxs)(F,{value:o,onValueChange:e=>i(String(e)),className:`w-full gap-1.5`,children:[/* @__PURE__ */ (0,q.jsxs)(L,{variant:`line`,className:`h-7`,children:[/* @__PURE__ */ (0,q.jsx)(R,{value:`script`,className:`text-xs`,children:`Script`}),a?/* @__PURE__ */ (0,q.jsx)(R,{value:`result`,className:`text-xs`,children:`Result`}):null,c?/* @__PURE__ */ (0,q.jsx)(R,{value:`full`,className:`text-xs`,children:`Full script`}):null,/* @__PURE__ */ (0,q.jsx)(R,{value:`meta`,className:`text-xs`,children:`Meta`})]}),/* @__PURE__ */ (0,q.jsx)(I,{value:`script`,className:`flex flex-col gap-1.5`,children:/* @__PURE__ */ (0,q.jsx)(Zt,{source:s||t.code,error:a?void 0:t.errorMessage,onTrace:()=>n.scriptRun(t.requestOffset)})}),/* @__PURE__ */ (0,q.jsx)(I,{value:`result`,className:`flex flex-col gap-2`,children:/* @__PURE__ */ (0,q.jsx)(en,{code:t})}),c?/* @__PURE__ */ (0,q.jsx)(I,{value:`full`,className:`flex flex-col gap-1.5`,children:/* @__PURE__ */ (0,q.jsx)(G,{code:t.code,language:`typescript`,showLineNumbers:!1})}):null,/* @__PURE__ */ (0,q.jsx)(I,{value:`meta`,className:`flex flex-col gap-1.5`,children:/* @__PURE__ */ (0,q.jsx)(Qt,{llm:e,code:t,inspect:n})})]})}function Zt({source:e,error:t,onTrace:n}){return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)(G,{code:e,language:`typescript`,showLineNumbers:!1,prettify:!0}),t?/* @__PURE__ */ (0,q.jsx)(`pre`,{"data-type":`error`,className:`whitespace-pre-wrap px-1.5 font-mono text-xs text-destructive`,children:t}):null,/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`xs`,title:`Open this script's execution trace`,onClick:n,className:`-ml-2 self-start font-normal text-muted-foreground`,children:[`Execution trace`,/* @__PURE__ */ (0,q.jsx)(y,{"data-icon":`inline-end`,className:`text-muted-foreground/50`})]})]})}function Qt({llm:e,code:t,inspect:n}){return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 px-1.5 font-mono text-xs`,children:[e?/* @__PURE__ */ (0,q.jsx)($t,{llm:e}):null,/* @__PURE__ */ (0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:`script`}),/* @__PURE__ */ (0,q.jsxs)(`dd`,{children:[t.durationMs==null?`running`:W(t.durationMs),t.success===!1?` · failed`:``]}),/* @__PURE__ */ (0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:`run`}),/* @__PURE__ */ (0,q.jsxs)(`dd`,{className:`truncate`,children:[`#`,t.requestOffset]})]}),e?/* @__PURE__ */ (0,q.jsx)(Yt,{onClick:()=>n.llmRequest(e.llmRequestOffset)}):null]})}function $t({llm:e}){return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:`model`}),/* @__PURE__ */ (0,q.jsx)(`dd`,{children:e.model||`?`}),/* @__PURE__ */ (0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:`requested`}),/* @__PURE__ */ (0,q.jsx)(`dd`,{children:U(e.startedAtMs)}),/* @__PURE__ */ (0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:`response`}),/* @__PURE__ */ (0,q.jsxs)(`dd`,{children:[e.durationMs==null?`—`:W(e.durationMs),e.outcome&&e.outcome!==`completed`?` · ${e.outcome}`:``]})]})}function en({code:e}){return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[e.errorMessage?/* @__PURE__ */ (0,q.jsx)(`pre`,{"data-type":`error`,className:`whitespace-pre-wrap rounded-lg bg-destructive/5 px-3 py-2 font-mono text-xs leading-relaxed text-destructive`,children:e.errorMessage}):null,e.result===void 0?e.errorMessage?null:/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme px-1.5 text-xs text-muted-foreground`,children:`Returned nothing — the turn ended here.`}):typeof e.result==`string`?/* @__PURE__ */ (0,q.jsx)(`pre`,{className:`whitespace-pre-wrap rounded-lg wrap-break-word bg-muted/40 px-3 py-2 font-mono text-xs leading-relaxed`,children:e.result}):/* @__PURE__ */ (0,q.jsx)(et,{data:e.result})]})}function tn({state:e,toggledIds:t,onToggle:n,inspect:r,me:i}){let a=e.live,o=a?`live-activity:${a.id}`:``,s=(0,K.useCallback)(()=>n(o),[o,n]);if(!a)return null;let c=a.steps.filter(e=>e.status===`running`),l=c.at(-1),u=a.steps.filter(e=>e.status===`done`),d=Ne(e),f=Ae(e),p=t.has(o),m=p&&(u.length>0||c.some(e=>e.kind===`code`||cn(e)));return f?/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col py-0.5`,"data-kind":`live`,children:[u.length>0?/* @__PURE__ */ (0,q.jsx)(an,{live:a,doneSteps:u,expanded:p,onToggle:s,me:i}):null,m?/* @__PURE__ */ (0,q.jsx)(on,{live:a,liveStep:l,inspect:r}):null,!m&&l&&l.kind===`llm`&&l.thinkingText.length>0?/* @__PURE__ */ (0,q.jsx)(un,{step:l,showResponseText:!1}):null,/* @__PURE__ */ (0,q.jsx)(sn,{label:d?.statusText||Me(c),startedAtMs:nn(a,l),deadlineMs:l?.kind===`code`?l.deadlineAtMs:null,onInspect:rn(l,r)})]}):/* @__PURE__ */ (0,q.jsx)(Bt,{activity:a,expanded:t.has(a.id),onToggle:n,inspect:r,me:i})}function Z({text:e,working:t}){return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex h-7 items-center gap-1.5 text-sm text-muted-foreground`,"data-testid":`agent-turn-status`,role:`status`,children:[t?/* @__PURE__ */ (0,q.jsx)(z,{className:`size-3 shrink-0`}):null,/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`truncate`,t&&`shimmer`),children:e})]})}function nn(e,t){if(t)return t.startedAtMs;let n=e.steps.at(-1);return n?n.startedAtMs+(n.durationMs??0):e.startedAtMs}function rn(e,t){if(e?.kind===`llm`)return()=>t.llmRequest(e.llmRequestOffset);if(e?.kind===`code`)return()=>t.scriptRun(e.requestOffset)}function an({live:e,doneSteps:t,expanded:n,onToggle:r,me:i}){let a=Ge(e,t);return/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`sm`,"aria-expanded":n,title:`Agent activity so far — click to see details`,onClick:r,className:`-ml-2.5 max-w-full self-start font-mono text-xs font-normal text-muted-foreground`,"data-testid":`agent-live-summary`,children:[a.codeCount>0?/* @__PURE__ */ (0,q.jsx)(C,{className:`size-3 shrink-0 text-muted-foreground/60`,"aria-hidden":`true`}):/* @__PURE__ */ (0,q.jsx)(`span`,{className:`shrink-0 text-2xs leading-none text-muted-foreground/60`,children:`✦`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`min-w-0 truncate`,children:Be(e,{summary:a,interruptedPartialHint:`click to see partial response`,me:i})}),/* @__PURE__ */ (0,q.jsx)(y,{className:N(`size-2.5 text-muted-foreground/50 transition-transform`,n&&`rotate-90`),"aria-hidden":`true`})]})}function on({live:e,liveStep:t,inspect:n}){return/* @__PURE__ */ (0,q.jsx)(`div`,{className:`mb-1.5 ml-1 mt-0.5 flex flex-col gap-1 border-l-2 border-muted py-1 pl-4`,children:Fe(e.steps).map((e,r)=>!e.code&&e.llm&&e.llm.status===`running`?e.llm===t&&cn(e.llm)?/* @__PURE__ */ (0,q.jsx)(un,{step:e.llm},e.llm.id):null:/* @__PURE__ */ (0,q.jsx)(Ht,{round:e,index:r,inspect:n},e.code?.id||e.llm?.id))})}function sn({label:e,startedAtMs:t,deadlineMs:n,onInspect:r}){let i=ln(t,n),a=i.deadlineExceeded?`Code deadline exceeded`:e;return/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`sm`,disabled:!r,onClick:r,title:i.deadlineExceeded?`The script is past its deadline; the platform's settlement has not landed yet`:r?`Open the current operation's trace`:void 0,className:N(`-ml-2.5 h-7 self-start px-2.5 text-primary disabled:opacity-100`,i.deadlineExceeded&&`text-destructive`),"data-testid":`agent-live-status`,children:[i.deadlineExceeded?/* @__PURE__ */ (0,q.jsx)(_,{className:`size-3 shrink-0 text-destructive`}):/* @__PURE__ */ (0,q.jsx)(z,{className:`size-3 shrink-0 text-primary`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`min-w-0 truncate text-sm font-medium text-primary`,!i.deadlineExceeded&&`shimmer`,i.deadlineExceeded&&`text-destructive`),children:a}),` `,/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`shrink-0 text-sm font-medium tabular-nums text-primary/80`,i.deadlineExceeded&&`text-destructive`),children:i.elapsedLabel}),r?/* @__PURE__ */ (0,q.jsx)(y,{className:N(`size-2.5 text-primary/60`,i.deadlineExceeded&&`text-destructive/60`),"aria-hidden":`true`}):null]})}function cn(e){return e.kind===`code`?e.code!==``:e.thinkingText.length>0||e.responseText.length>0}function ln(e,t){let n=lt(100,t),r=typeof t==`number`&&n>=t;return{deadlineExceeded:r,elapsedLabel:ze((r&&typeof t==`number`?t:n)-e)}}function un({step:e,showResponseText:t=!0}){return e.kind===`code`?/* @__PURE__ */ (0,q.jsx)(`div`,{className:`flex flex-col gap-1.5 py-1`,children:e.code===``?null:/* @__PURE__ */ (0,q.jsx)(Ct,{code:Re(e.code)||e.code})}):/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5 py-1`,children:[e.thinkingText.length===0?null:/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`max-w-2xl whitespace-pre-wrap px-1.5 text-sm italic leading-relaxed text-muted-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(J,{text:e.thinkingText}),!t||e.responseText.length===0?/* @__PURE__ */ (0,q.jsx)(X,{}):null]}),!t||e.responseText.length===0?null:Le(e.responseText)?/* @__PURE__ */ (0,q.jsx)(Ct,{code:e.responseText}):/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`max-w-2xl whitespace-pre-wrap px-1.5 text-sm leading-relaxed`,children:[/* @__PURE__ */ (0,q.jsx)(J,{text:e.responseText,animate:!0}),/* @__PURE__ */ (0,q.jsx)(X,{})]})]})}function dn({item:e,signedUrl:t}){return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[e.text===``?null:/* @__PURE__ */ (0,q.jsx)(`div`,{className:`whitespace-pre-wrap leading-6 wrap-anywhere`,children:e.text}),/* @__PURE__ */ (0,q.jsx)(fn,{files:e.files,hasText:e.text!==``,signedUrl:t})]})}function fn({files:e,hasText:t,signedUrl:n}){return e?.length?/* @__PURE__ */ (0,q.jsx)(`div`,{className:N(`flex max-w-full flex-col gap-2`,t&&`mt-1`),children:e.map(e=>/* @__PURE__ */ (0,q.jsx)(pn,{file:e,signedUrl:n},e.path))}):null}function pn({file:e,signedUrl:t}){let[n,r]=(0,K.useState)();return(0,K.useEffect)(()=>{let n=!0;return t(e.path).then(e=>n&&r(e),()=>void 0),()=>void(n=!1)},[e.path,t]),e.contentType.startsWith(`image/`)&&n?/* @__PURE__ */ (0,q.jsx)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`block max-w-full`,children:/* @__PURE__ */ (0,q.jsx)(`img`,{src:n,alt:e.filename,className:`max-h-64 max-w-full rounded-lg border border-border/60 bg-background object-contain`})}):/* @__PURE__ */ (0,q.jsxs)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`inline-flex max-w-full items-center gap-1.5 self-start rounded-full border border-border/60 bg-background/70 px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:text-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(g,{className:`size-3 shrink-0`}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`min-w-0 truncate text-foreground/80`,children:e.filename}),/* @__PURE__ */ (0,q.jsx)(`span`,{className:`shrink-0 font-mono`,children:He(e.size)})]})}const mn={user:96,assistant:72,activity:36,background:36,note:32,widget:140,"stream-paused":48,"stream-resumed":48},hn={key:e=>e.id,estimateSize:e=>e.kind===`user`&&e.from?mn.activity:mn[e.kind],offset:e=>e.kind===`user`||e.kind===`assistant`?e.offset:void 0};function gn({feed:e,older:t,logShare:n,followTail:r,empty:i,after:a,footer:o,toggledIds:s,onToggle:c,inspect:l,signedUrl:u,itemFooter:d,me:f,agentPath:p,typing:m}){let{items:h,state:g}=e,_=h.at(-1),v=m.length>0?/* @__PURE__ */ (0,q.jsx)(mt,{typing:m,runOf:g.live?void 0:vn(_)}):null,y=(0,K.useCallback)((e,t)=>/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)(Nt,{item:e,expanded:s.has(e.id),onToggle:c,inspect:l,signedUrl:u,me:f,agentPath:p,continuesRun:_n(h[t-1],e)}),d?.(e)]}),[s,c,l,u,d,f,p,h]);return/* @__PURE__ */ (0,q.jsx)(Ze,{rows:h,rowInfo:hn,renderRow:y,tail:g.live||v&&_||a?/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[g.live?/* @__PURE__ */ (0,q.jsx)(tn,{state:g,toggledIds:s,onToggle:c,inspect:l,me:f}):null,v,a]}):void 0,older:t,readingOlder:/* @__PURE__ */ (0,q.jsx)(le,{label:`Loading older messages`,value:n}),empty:v?/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`relative h-full`,children:[i,/* @__PURE__ */ (0,q.jsx)(`div`,{className:`absolute inset-x-0 bottom-0`,children:v})]}):i,label:`Chat`,footer:o,followTail:r,paddingStart:8,paddingEnd:8,columnClassName:`mx-auto w-full max-w-3xl px-4 md:px-6`})}function _n(e,t){if(e?.kind!==`user`||t.kind!==`user`||e.from||t.from)return!1;let[n,r]=[e.sender,t.sender];return!!(n&&r&&n.actor===r.actor&&n.script===r.script)}function vn(e){if(!(e?.kind!==`user`||e.from||e.sender?.script!==!1))return e.sender.actor}const yn={llmRequest:void 0,scriptRun:void 0};function bn(e,t,n){return t.exhausted?!1:e?.kind===`scriptRun`?e.requestOffset<(n[0]?.offset??1/0):e?.kind===`llmRequest`}const Q=i().optional().catch(void 0),$=o().optional().catch(void 0),xn=l(o(),d()),Sn=a({contentType:o(),filename:o(),path:o(),size:i()}),Cn=u(Sn.nullable().catch(null)).catch([]).transform(e=>e.flatMap(e=>e?[e]:[])),wn=a({role:$,text:$,files:Cn.optional(),atOffset:Q,tag:$}).catch({}),Tn=a({model:$,purpose:$,instructions:$,extends:a({llmRequestOffset:i(),itemCount:i().nullable().optional().catch(void 0),response:s().optional().catch(void 0)}).nullable().catch(null),itemsAdded:u(wn).catch([])}),En=a({inputTokens:Q,outputTokens:Q,cachedInputTokens:Q,cacheWriteInputTokens:Q,reasoningOutputTokens:Q,costUsd:Q,estimated:c(!0).optional().catch(void 0)}),Dn=a({llmRequestOffset:i(),durationMs:Q,firstEventMs:Q,result:a({status:$,text:$,partialText:$,errorMessage:$,failureKind:$,reason:$,usage:En.optional().catch(void 0)}).catch({})}),On=a({llmRequestOffset:Q,attempt:i().catch(0),api:$,transport:$,model:$,inputChars:l(o(),i()).optional().catch(void 0),inputFileBytes:Q}),kn=a({llmRequestOffset:Q,attempt:Q,bodySha256:$,inputField:$,bodyWithoutInput:xn.optional().catch(void 0),inputItemsAdded:u(d()).optional().catch(void 0),extendsRequestStartedOffset:i().nullable().optional().catch(void 0),inputItemCountBefore:i().catch(0)});function An(e,t){let n=new Map(e.map(e=>[e.offset,e])),r=n.get(t);if(!r||r.type!==j.llmRequested)return null;let i=Tn.safeParse(r.payload).data,a=/* @__PURE__ */ new Map,o=[],s=[];for(let n of e){if(n.type===j.llmSettled){let e=Dn.safeParse(n.payload).data;e&&!a.has(e.llmRequestOffset)&&a.set(e.llmRequestOffset,e)}n.type===j.llmAttemptStarted&&On.safeParse(n.payload).data?.llmRequestOffset===t&&o.push(n),n.type===`events.iterate.com/itx/run-requested`&&A(n.idempotencyKey)===t&&s.push(n.offset)}let c=jn(n,a,t,0),l=a.get(t);return{llmRequestOffset:t,model:i?.model||`?`,purpose:i?.purpose||`?`,requestedAtMs:Date.parse(r.createdAt),instructions:c.instructions||null,conversation:c.items,conversationWhole:c.whole,attempts:o.map(t=>Nn(e,n,t)),outcome:Fn(l),usage:l?.result.usage,scriptRequestOffsets:s}}function jn(e,t,n,r){let i=e.get(n);if(!i||i.type!==j.llmRequested||r>64)return{items:[],whole:!1};let a=Tn.safeParse(i.payload).data,o=(a?.itemsAdded||[]).map(e=>({role:e.role||`?`,text:e.text||``,files:e.files||[],atOffset:e.atOffset??n,tag:e.tag||`words`})),s=a?.instructions,c=a?.extends;if(!c)return{instructions:s,items:o,whole:!0};let l=jn(e,t,c.llmRequestOffset,r+1),u=c.itemCount??l.items.length,d=c.response?Mn(t,c.llmRequestOffset):[];return{instructions:s||l.instructions,items:[...l.items.slice(0,u),...d,...o],whole:l.whole&&u<=l.items.length&&(!c.response||d.length>0)}}function Mn(e,t){let n=e.get(t)?.result;return n?.status!==`succeeded`||!n.text?[]:[{role:`assistant`,text:n.text,files:[],atOffset:t,tag:`llm-response`}]}function Nn(e,t,n){let r=On.parse(n.payload),i=r.api||null,a={attempt:r.attempt,api:i,transport:r.transport,model:r.model,startedAtMs:Date.parse(n.createdAt),inputChars:r.inputChars,inputFileBytes:r.inputFileBytes};if(!i)return{...a,body:null,bodyMissing:`The attempt names no API shape.`};let o=O(i,`request-started`),s=e.filter(e=>e.type===o).map(e=>kn.safeParse(e.payload).data).find(e=>e?.llmRequestOffset===r.llmRequestOffset&&e?.attempt===r.attempt);if(!s)return{...a,body:null,bodyMissing:`No ${i}/request-started for this attempt in the log held.`};let c={...a,bodySha256:s.bodySha256},l=Pn(t,o,s,0);return typeof l==`string`?{...c,body:null,bodyMissing:l}:!s.inputField||!s.bodyWithoutInput?{...c,body:null,bodyMissing:`The fact has no body.`}:{...c,body:{...s.bodyWithoutInput,[s.inputField]:l}}}function Pn(e,t,n,r){if(!n.inputItemsAdded)return`Its conversation was too large for one fact: the request facts before it give it.`;let i=n.extendsRequestStartedOffset;if(!i)return n.inputItemsAdded;let a=e.get(i),o=a?.type===t&&kn.safeParse(a.payload).data;if(!o||r>64)return`It extends the body at offset ${String(i)}, which is not in the log held.`;let s=Pn(e,t,o,r+1);return typeof s==`string`?s:[...s.slice(0,n.inputItemCountBefore),...n.inputItemsAdded]}function Fn(e){if(!e)return{status:`in flight`};let{result:t,durationMs:n}=e;return t.status===`succeeded`?{status:`succeeded`,text:t.text||``,durationMs:n,firstEventMs:e.firstEventMs}:t.status===`failed`?{status:`failed`,errorMessage:t.errorMessage||``,failureKind:t.failureKind,partialText:t.partialText,durationMs:n}:{status:`cancelled`,reason:t.reason,partialText:t.partialText,durationMs:n}}const In={key:e=>e.key,estimateSize:e=>56+Math.min(4e3,Math.ceil(e.text.length/100)*24),offset:e=>e.atOffset};function Ln({trace:e,step:t,onScript:n}){let[r,i]=(0,K.useState)(`markdown`),a=(0,K.useMemo)(()=>[...e.instructions?[{key:`instructions`,role:`instructions`,text:e.instructions,files:[]}]:[],...e.conversation.map((e,t)=>({...e,key:String(t)}))],[e.instructions,e.conversation]),o=[...new Set(e.attempts.flatMap(e=>e.api||[]))];return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsxs)(V,{className:`shrink-0 pr-12`,children:[/* @__PURE__ */ (0,q.jsxs)(B,{className:`truncate`,children:[`LLM trace #`,e.llmRequestOffset,` · `,e.model]}),/* @__PURE__ */ (0,q.jsxs)(H,{children:[U(e.requestedAtMs),o.length>0?` · ${o.join(`, `)}`:``,e.purpose===`answer`?``:` · ${e.purpose} request`,` · ${e.conversation.length.toLocaleString()} items`,/* @__PURE__ */ (0,q.jsx)(Wn,{outcome:e.outcome}),e.usage?` · ${Hn(e.usage)}`:``]})]}),/* @__PURE__ */ (0,q.jsxs)(F,{defaultValue:`conversation`,className:`min-h-0 flex-1 gap-0`,children:[/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 px-4`,children:[/* @__PURE__ */ (0,q.jsxs)(L,{variant:`line`,className:`h-8`,children:[/* @__PURE__ */ (0,q.jsx)(R,{value:`conversation`,children:`Conversation`}),/* @__PURE__ */ (0,q.jsx)(R,{value:`body`,children:`Request body`}),/* @__PURE__ */ (0,q.jsx)(R,{value:`response`,children:`Response`})]}),/* @__PURE__ */ (0,q.jsx)(P,{size:`xs`,variant:`ghost`,className:`ml-auto font-normal text-muted-foreground`,"aria-pressed":r===`plain`,title:`Toggle between rendered markdown and the verbatim text`,onClick:()=>i(r===`markdown`?`plain`:`markdown`),children:r===`markdown`?`Markdown`:`Plain text`})]}),/* @__PURE__ */ (0,q.jsxs)(I,{value:`conversation`,className:`flex min-h-0 flex-1 flex-col border-t`,children:[e.conversationWhole?null:/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme shrink-0 px-5 py-2 text-xs text-muted-foreground`,children:`A base of this request is not in the log held: its items are missing here. The request body has them as they were sent.`}),/* @__PURE__ */ (0,q.jsx)(Ze,{rows:a,rowInfo:In,renderRow:e=>/* @__PURE__ */ (0,q.jsx)(Rn,{item:e,renderMode:r}),className:`min-h-0 flex-1`})]}),/* @__PURE__ */ (0,q.jsx)(I,{value:`body`,className:`min-h-0 flex-1 overflow-y-auto border-t`,children:e.attempts.length===0?/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme px-5 py-3 text-sm text-muted-foreground`,children:`No attempt has started yet.`}):e.attempts.map(e=>/* @__PURE__ */ (0,q.jsx)(zn,{attempt:e},e.attempt))}),/* @__PURE__ */ (0,q.jsx)(I,{value:`response`,className:`min-h-0 flex-1 overflow-y-auto border-t`,children:/* @__PURE__ */ (0,q.jsx)(Bn,{trace:e,step:t,renderMode:r,onScript:n})})]})]})}const Rn=(0,K.memo)(function({item:e,renderMode:t}){return/* @__PURE__ */ (0,q.jsxs)(`section`,{className:`border-b border-border/60 px-5 py-3`,children:[/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`mb-2 flex items-baseline gap-2`,children:[/* @__PURE__ */ (0,q.jsx)(Kn,{name:e.role}),/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`font-mono text-2xs text-muted-foreground/60`,children:[e.atOffset===void 0?``:`#${String(e.atOffset)} · `,e.tag?`${e.tag} · `:``,e.text.length.toLocaleString(),` chars`]})]}),e.files.length>0?/* @__PURE__ */ (0,q.jsx)(`ul`,{className:`mb-2 flex flex-col gap-0.5`,children:e.files.map(e=>/* @__PURE__ */ (0,q.jsxs)(`li`,{className:`flex items-center gap-1.5 font-mono text-2xs text-muted-foreground`,title:e.path,children:[/* @__PURE__ */ (0,q.jsx)(g,{className:`size-3 shrink-0`,"aria-hidden":`true`}),/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`truncate`,children:[e.filename,` · `,e.contentType,` · `,He(e.size)]})]},e.path))}):null,/* @__PURE__ */ (0,q.jsx)(qn,{text:e.text,renderMode:t})]})});function zn({attempt:e}){let t=[e.api||`no API shape`,e.transport,e.model,e.inputFileBytes?`${He(e.inputFileBytes)} of files`:void 0].filter(Boolean);return/* @__PURE__ */ (0,q.jsxs)(`section`,{className:`flex flex-col gap-2 border-b border-border/60 px-5 py-3`,children:[/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[/* @__PURE__ */ (0,q.jsx)(Kn,{name:`attempt ${String(e.attempt+1)}`}),/* @__PURE__ */ (0,q.jsxs)(`span`,{className:`min-w-0 truncate font-mono text-2xs text-muted-foreground/60`,children:[t.join(` · `),` · `,U(e.startedAtMs)]})]}),e.body?/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsx)(`div`,{className:`max-h-[70vh] overflow-y-auto rounded-lg`,children:/* @__PURE__ */ (0,q.jsx)(et,{data:e.body,initialFormat:`json`})}),/* @__PURE__ */ (0,q.jsxs)(`p`,{className:`font-readme text-2xs text-muted-foreground/70`,children:[`The body as it went to the provider. A file's bytes are a `,/* @__PURE__ */ (0,q.jsx)(`code`,{children:`$file`}),` reference here.`,e.bodySha256?` The real body's SHA-256: ${e.bodySha256}.`:``]})]}):/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:e.bodyMissing})]})}function Bn({trace:e,step:t,renderMode:n,onScript:r}){let{outcome:i}=e,a=t?.status===`running`,o=t&&t.thinkingText.length>0?t.thinkingText:null,s=i.status===`succeeded`?i.text:a&&t?je(t.responseText):i.status===`in flight`?``:i.partialText||``;return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col gap-3 px-5 py-3`,children:[o?/* @__PURE__ */ (0,q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,q.jsx)(Gn,{children:`thinking`}),/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`whitespace-pre-wrap text-sm italic leading-relaxed text-muted-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(J,{text:o}),a&&s===``?/* @__PURE__ */ (0,q.jsx)(X,{}):null]})]}):a&&t?.thinking?/* @__PURE__ */ (0,q.jsxs)(`p`,{className:`font-readme flex items-center gap-2 text-sm text-muted-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(z,{className:`size-3`}),` Thinking, with no words for it…`]}):null,s?/* @__PURE__ */ (0,q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,q.jsx)(Gn,{children:i.status===`succeeded`?`response`:`what had streamed`}),/* @__PURE__ */ (0,q.jsx)(qn,{text:s,renderMode:n})]}):a&&!o&&!t?.thinking?/* @__PURE__ */ (0,q.jsxs)(`p`,{className:`font-readme flex items-center gap-2 text-sm text-muted-foreground`,children:[/* @__PURE__ */ (0,q.jsx)(z,{className:`size-3`}),` Waiting for the first tokens…`]}):null,i.status===`failed`?/* @__PURE__ */ (0,q.jsxs)(`pre`,{"data-type":`error`,className:`overflow-x-auto whitespace-pre-wrap rounded-xl bg-destructive/5 px-4 py-2.5 font-mono text-xs leading-relaxed text-destructive`,children:[i.failureKind?`${i.failureKind}: `:``,i.errorMessage]}):null,i.status===`cancelled`?/* @__PURE__ */ (0,q.jsxs)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:[`Cancelled`,i.reason?`: ${i.reason}`:``]}):null,e.usage?/* @__PURE__ */ (0,q.jsx)(Vn,{usage:e.usage}):null,e.scriptRequestOffsets.map(e=>/* @__PURE__ */ (0,q.jsxs)(P,{variant:`outline`,size:`sm`,className:`self-start`,onClick:()=>r(e),children:[`Ran a script: open its execution trace`,/* @__PURE__ */ (0,q.jsx)(y,{"data-icon":`inline-end`})]},e))]})}function Vn({usage:e}){let t=[];return e.inputTokens!==void 0&&t.push([`input tokens`,e.inputTokens.toLocaleString()]),e.cachedInputTokens!==void 0&&t.push([`cached input`,e.cachedInputTokens.toLocaleString()]),e.cacheWriteInputTokens!==void 0&&t.push([`cache written`,e.cacheWriteInputTokens.toLocaleString()]),e.outputTokens!==void 0&&t.push([`output tokens`,e.outputTokens.toLocaleString()]),e.reasoningOutputTokens!==void 0&&t.push([`reasoning`,e.reasoningOutputTokens.toLocaleString()]),e.costUsd!==void 0&&t.push([`cost`,Un(e.costUsd)]),/* @__PURE__ */ (0,q.jsxs)(`div`,{children:[/* @__PURE__ */ (0,q.jsxs)(Gn,{children:[`usage`,e.estimated?` (estimated: the provider gave no count)`:``]}),/* @__PURE__ */ (0,q.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 font-mono text-xs`,children:t.map(([e,t])=>/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`contents`,children:[/* @__PURE__ */ (0,q.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,q.jsx)(`dd`,{children:t})]},e))})]})}function Hn(e){let t=[];return e.inputTokens!==void 0&&t.push(`${e.inputTokens.toLocaleString()} in${e.cachedInputTokens?` (${e.cachedInputTokens.toLocaleString()} cached)`:``}`),e.outputTokens!==void 0&&t.push(`${e.outputTokens.toLocaleString()} out`),e.costUsd!==void 0&&t.push(Un(e.costUsd)),t.join(` · `)}const Un=e=>`$${e<.01?e.toPrecision(3):e.toFixed(2)}`;function Wn({outcome:e}){if(e.status===`in flight`)return/* @__PURE__ */ (0,q.jsx)(q.Fragment,{children:` · in flight`});let t=e.durationMs===void 0?``:` in ${W(e.durationMs)}`;return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[` · `,/* @__PURE__ */ (0,q.jsxs)(`span`,{className:N(e.status===`succeeded`&&`text-success`,e.status===`failed`&&`text-destructive`,e.status===`cancelled`&&`text-warning`),children:[e.status,t]})]})}function Gn({children:e}){return/* @__PURE__ */ (0,q.jsx)(`p`,{className:`mb-1 font-mono text-2xs uppercase tracking-wider text-muted-foreground/60`,children:e})}function Kn({name:e}){return/* @__PURE__ */ (0,q.jsx)(`span`,{className:N(`font-mono text-2xs font-semibold uppercase tracking-wider text-muted-foreground`,e===`instructions`&&`text-foreground`,e===`user`&&`text-info`,e===`assistant`&&`text-success`),children:e})}function qn({text:e,renderMode:t}){return t===`markdown`?/* @__PURE__ */ (0,q.jsx)(Oe,{className:`min-w-0 max-w-full overflow-hidden text-sm`,mode:`static`,parseIncompleteMarkdown:!1,children:e}):/* @__PURE__ */ (0,q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground`,children:e})}const Jn=`Reading the log…`;function Yn({events:e,live:t,items:n,inspected:r,readProgress:i,onInspect:a}){let o=i!==void 0,s=r?.kind===`llmRequest`?t?.steps.find(e=>e.kind===`llm`&&e.status===`running`&&e.llmRequestOffset===r.llmRequestOffset):void 0;return/* @__PURE__ */ (0,q.jsx)(de,{open:!!r,onOpenChange:e=>!e&&a(null),children:/* @__PURE__ */ (0,q.jsxs)(pe,{side:`right`,className:`flex flex-col gap-0 p-0 data-[side=right]:w-full data-[side=right]:sm:w-[min(92vw,64rem)] data-[side=right]:sm:max-w-[92vw]`,children:[i===void 0?null:/* @__PURE__ */ (0,q.jsx)(`div`,{className:`shrink-0 px-4 pt-4 pr-12`,children:/* @__PURE__ */ (0,q.jsx)(le,{label:`Reading the log`,value:i})}),r?.kind===`llmRequest`?/* @__PURE__ */ (0,q.jsx)(Xn,{events:e,llmRequestOffset:r.llmRequestOffset,liveStep:s,items:n,reading:o,onInspect:a}):r?.kind===`scriptRun`?/* @__PURE__ */ (0,q.jsx)(Qn,{events:e,requestOffset:r.requestOffset,reading:o}):null]})})}function Xn({events:e,llmRequestOffset:t,liveStep:n,items:r,reading:i,onInspect:a}){let o=(0,K.useMemo)(()=>An(e,t),[e,t]);return o?/* @__PURE__ */ (0,q.jsx)(Ln,{trace:o,step:n||Zn(r,t),onScript:e=>a({kind:`scriptRun`,requestOffset:e})}):/* @__PURE__ */ (0,q.jsxs)(V,{children:[/* @__PURE__ */ (0,q.jsxs)(B,{children:[`LLM trace #`,t]}),/* @__PURE__ */ (0,q.jsx)(H,{children:i?Jn:`No LLM request at offset #${String(t)} on this path.`})]})}function Zn(e,t){for(let n of e?.toReversed()??[]){if(n.kind!==`activity`)continue;let e=n.steps.find(e=>e.kind===`llm`&&e.llmRequestOffset===t);if(e)return e}}function Qn({events:e,requestOffset:t,reading:n}){let r=We(e,t);if(!r)return/* @__PURE__ */ (0,q.jsxs)(V,{children:[/* @__PURE__ */ (0,q.jsxs)(B,{children:[`Script run #`,t]}),/* @__PURE__ */ (0,q.jsx)(H,{children:n?Jn:`No script run requested at offset #${String(t)} on this path.`})]});let i=r.settlement?.value,a=i?.status===`failed`;return/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[/* @__PURE__ */ (0,q.jsxs)(V,{className:`shrink-0 pr-12`,children:[/* @__PURE__ */ (0,q.jsxs)(B,{className:`truncate`,children:[`Script run #`,t]}),/* @__PURE__ */ (0,q.jsxs)(H,{children:[U(r.requestedAtMs),r.settlement?/* @__PURE__ */ (0,q.jsxs)(q.Fragment,{children:[` · `,/* @__PURE__ */ (0,q.jsxs)(`span`,{className:a?`text-destructive`:`text-success`,children:[a?`failed`:`succeeded`,` in`,` `,W(r.settlement.atMs-r.requestedAtMs)]})]}):` · running`]})]}),/* @__PURE__ */ (0,q.jsxs)(F,{defaultValue:`code`,className:`min-h-0 flex-1 gap-0`,children:[/* @__PURE__ */ (0,q.jsxs)(L,{variant:`line`,className:`mx-4 h-8 shrink-0`,children:[/* @__PURE__ */ (0,q.jsx)(R,{value:`code`,children:`Code`}),/* @__PURE__ */ (0,q.jsx)(R,{value:`result`,children:`Result`}),/* @__PURE__ */ (0,q.jsx)(R,{value:`agent`,children:`What the agent saw`})]}),/* @__PURE__ */ (0,q.jsx)(I,{value:`code`,className:`min-h-0 flex-1 overflow-y-auto border-t p-4`,children:/* @__PURE__ */ (0,q.jsx)(G,{code:r.code,language:`typescript`})}),/* @__PURE__ */ (0,q.jsx)(I,{value:`result`,className:`min-h-0 flex-1 overflow-y-auto border-t p-4`,children:i?/* @__PURE__ */ (0,q.jsx)(et,{data:i}):/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`Not settled yet.`})}),/* @__PURE__ */ (0,q.jsx)(I,{value:`agent`,className:`min-h-0 flex-1 overflow-y-auto border-t p-4`,children:r.seen?/* @__PURE__ */ (0,q.jsx)(Oe,{className:`min-w-0 max-w-full overflow-hidden text-sm`,mode:`static`,parseIncompleteMarkdown:!1,children:r.seen}):/* @__PURE__ */ (0,q.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:`No request of the agent has read this run's result yet. A script that returns nothing starts no request: the next request reads its result.`})})]})]})}function $n({messages:e,isInterrupting:t,onInterrupt:n,signedUrl:r,me:i}){let[a,o]=(0,K.useState)(!1),s=e.filter(e=>!e.from);if(s.length===0)return null;let c=s.length-1;return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`-mb-4 rounded-t-3xl border border-b-0 bg-muted/40 px-3 pb-6 pt-1.5`,"data-testid":`queued-messages-panel`,children:[/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-1.5 py-1`,children:[/* @__PURE__ */ (0,q.jsx)(`span`,{className:`min-w-0 truncate font-mono text-2xs text-muted-foreground`,children:`Queued for the next agent turn`}),c>0?/* @__PURE__ */ (0,q.jsx)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`shrink-0 font-mono text-2xs text-muted-foreground underline-offset-2 hover:underline sm:hidden`,children:a?`collapse`:`+${String(c)} more`}):null,n?/* @__PURE__ */ (0,q.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:()=>void n(),disabled:t,className:`ml-auto h-6 shrink-0 gap-1 px-2 text-2xs text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[t?/* @__PURE__ */ (0,q.jsx)(z,{className:`size-3`}):/* @__PURE__ */ (0,q.jsx)(f,{className:`size-3 text-current`}),`Interrupt & send now`]}):null]}),/* @__PURE__ */ (0,q.jsx)(`div`,{className:`flex max-h-40 flex-col gap-1 overflow-y-auto`,children:s.map((e,t)=>/* @__PURE__ */ (0,q.jsxs)(`div`,{className:N(`rounded-xl border bg-background/80 px-3 py-1.5 text-sm`,!a&&t<s.length-1&&`hidden sm:block`),children:[e.sender&&e.saidBy?/* @__PURE__ */ (0,q.jsx)(dt,{principal:e.sender,words:Ke(e.sender,i)?`You`:e.saidBy,className:`mb-1`,"data-queued-by":!0}):null,/* @__PURE__ */ (0,q.jsx)(dn,{item:e,signedUrl:r})]},e.id))})]})}const er={state:Pe(),items:[]};function tr(e){if(`progress`in e){let{text:t,working:n,activity:r}=e.progress;return!n&&t===`Idle`?null:/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col`,"data-testid":`agent-progress`,children:[/* @__PURE__ */ (0,q.jsx)(Z,{text:t,working:n}),n&&r?/* @__PURE__ */ (0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r}):null]})}return/* @__PURE__ */ (0,q.jsx)(nr,{...e})}function nr({context:e,error:t}){let{turn:n,feed:r}=rr(e),i=lr(n,r.state),a=!e.liveState.agent&&e.processors.loaded&&!e.processors.error,o=t||e.error;if(a&&!o)return null;if(o||n.liveUnavailable)return/* @__PURE__ */ (0,q.jsx)(Z,{text:o||`Agent status unavailable`,working:!1});if(!e.caughtUp||i.tone===`muted`)return null;let s=Ne(r.state)?.statusText;return/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`flex flex-col`,"data-testid":`agent-progress`,children:[/* @__PURE__ */ (0,q.jsx)(Z,{text:i.text,working:i.tone===`live`}),s&&i.tone===`live`&&!i.text.includes(s)?/* @__PURE__ */ (0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s}):null]})}function rr(e){let[t]=(0,K.useState)(()=>Qe(Ve)),n=(0,K.useMemo)(()=>t(e.events),[t,e.events]),r=cr(e),{idle:i,requestMayBeOpen:a}=r;return{fold:n,turn:r,feed:(0,K.useMemo)(()=>e.caughtUp?Ue(n,i,a):er,[e.caughtUp,n,i,a]),older:!e.error&&n.versionEndedAt===null&&e.older||Xe}}function ir({path:e,context:t,error:n,state:r,onStateChange:i,onMessage:a,onAppend:o,storeFiles:s,signedUrl:c,itemFooter:l,strip:u=!0,aboveComposer:d,empty:f,placeholder:p=`Message this agent`,eventsTab:m=!0,tabsInHeader:h,asideIn:g,attach:_=!0,onChoice:v,choiceState:y,me:b,presence:x=!1,inCall:S,mind:ee,widgetCalls:C}){let{fold:w,turn:te,feed:T,older:E}=rr(t),ne=pr(t),[re,ie]=gr(),D=qe(),ae=or(),{inspected:oe,inspect:O,onInspect:k}=_r(r,i);hr(ne,r,i);let A=bn(oe,E,w.events),j=t.caughtUp&&!E.exhausted&&T.items.length===0&&!T.state.live;vr(A,E,w.events);let M=Ye(w.events,t.head),N=(0,K.useMemo)(()=>o?e=>se(e,{onAppend:o,onMessage:a,storeFiles:s}):a,[o,a,s]),P=(0,K.useCallback)((e,t)=>{N({message:e,files:[],key:`widget:${crypto.randomUUID()}`,widget:t})},[N]),{setMessage:ce}=D,F=(0,K.useCallback)(e=>ce(t=>t.trim()?`${t}\n\n${e}`:e),[ce]),I=lr(te,T.state,(S?.size??0)>0),L=Se({enabled:x,rows:t.processors.rows,rpcStubs:t.presence.rpcStubs,events:w.events,send:o,me:b,subscription:t.subscription}),R=(0,K.useMemo)(()=>ar(T.items,b),[T.items,b]),z=(0,K.useMemo)(()=>L.present.filter(e=>!e.me&&e.typing),[L.present]),le=(0,K.useMemo)(()=>t.events.some(xe)?{...t,events:t.events.filter(e=>!xe(e))}:t,[t]);return/* @__PURE__ */ (0,q.jsx)($e,{path:e,context:le,error:n,state:r,onStateChange:i,onAppend:o,status:I,strip:u,eventsTab:m,tabsInHeader:h,aside:x?/* @__PURE__ */ (0,q.jsx)(ye,{present:L.present,wrote:R,inCall:S,mind:ee}):null,asideIn:g,closeSheet:yn,sheet:/* @__PURE__ */ (0,q.jsx)(Yn,{events:w.events,live:T.state.live,items:T.items,inspected:oe,readProgress:A?M:void 0,onInspect:k}),children:/* @__PURE__ */ (0,q.jsx)(Te,{onChoice:v,choiceState:y,children:/* @__PURE__ */ (0,q.jsx)(At,{events:w.events,onSend:P,onDraft:F,path:e,calls:C,onAppend:o,children:/* @__PURE__ */ (0,q.jsx)(dr,{feed:T,conversation:ne,older:E,logShare:M,caughtUp:t.caughtUp,failed:!!(n||t.error),readingForFirstRow:j,toggled:re,onToggle:ie,inspect:O,signedUrl:c,itemFooter:l,me:b,agentPath:e,statusRow:u?null:ur(I,T.state),aboveComposer:d,empty:f,placeholder:p,draft:D,keys:ae,onMessage:N,onAppend:o,attach:_,typingStatus:x?/* @__PURE__ */ (0,q.jsx)(ve,{typing:z}):null,onTyping:x?L.typing:void 0,typing:z})})})})}ir.contextOptions={consumes:[`*`,j.llmResponseFrame,...be]};function ar(e,t){let n=/* @__PURE__ */ new Map;for(let r of e)r.kind===`user`&&r.sender&&!Ke(r.sender,t)&&n.set(r.sender.actor,n.get(r.sender.actor)||r.sender);return[...n.values()]}function or(){let[e]=(0,K.useState)(()=>crypto.randomUUID().slice(0,12)),t=(0,K.useRef)({count:0});return(0,K.useMemo)(()=>({keyFor(n){let r=JSON.stringify([n.message,n.files.map(e=>[e.filename,e.contentType,sr(e.data)])]);return t.current.message!==r&&(t.current.count+=1),t.current.message=r,`${e}:${String(t.current.count)}`},sent(){t.current.message=void 0}}),[e])}function sr(e){let t=2166136261;for(let n=0;n<e.length;n++)t=Math.imul(t^e.charCodeAt(n),16777619);return`${String(e.length)}:${(t>>>0).toString(16)}`}function cr({liveState:e,processors:t}){let n=e.agent,r=n?n.status===`error`:!!t.error||t.loaded&&!t.rows.some(e=>e.hostedFacet?.name===`agent`),i=k(n?.value),a=i&&i.llmRequests.length===0&&i.pendingTriggerOffsets.length===0&&i.scriptCalls.every(e=>e.answered);return{facet:i,liveUnavailable:r,detail:n?.error||t.error,idle:i?!!a:r,requestMayBeOpen:!a}}function lr({facet:e,liveUnavailable:t,detail:n},r,i=!1){if(!e)return{text:t?`Live state unavailable`:``,tone:`muted`,detail:n};if(e.paused)return{text:`Paused — ${e.paused.reason}`,tone:`amber`};let{live:a}=r,o=Ne(r)?.statusText;if(a?.steps.some(e=>e.kind===`code`&&e.status===`running`))return{text:`Running a script${o?` · ${o}`:``}`,tone:`live`};let s=e.llmRequests.find(e=>e.purpose===`answer`)??e.llmRequests[0];return s?{text:`Thinking · ${s.model}`,tone:`live`}:e.pendingTriggerOffsets.length>0?{text:`About to think`,tone:`live`}:e.scriptCalls.some(e=>!e.answered)?{text:`About to run a script`,tone:`live`}:{text:i?``:`Idle`,tone:`muted`}}function ur({text:e,tone:t},n){return t===`amber`?/* @__PURE__ */ (0,q.jsx)(Z,{text:e,working:!1}):t===`live`&&!Ae(n)?/* @__PURE__ */ (0,q.jsx)(Z,{text:`Working…`,working:!0}):null}function dr({feed:e,conversation:t,older:n,logShare:r,caughtUp:i,failed:a,readingForFirstRow:o,toggled:s,onToggle:c,inspect:l,signedUrl:u,itemFooter:d,me:f,agentPath:p,statusRow:m,aboveComposer:h,empty:g,placeholder:_,draft:v,keys:y,onMessage:b,onAppend:x,attach:S,typingStatus:ee,onTyping:C,typing:w}){let[te,T]=(0,K.useState)(0),E=yr({runningLlmRequestId:e.state.live?.steps.findLast(e=>e.kind===`llm`&&e.status===`running`)?.llmRequestOffset,onInterrupt:x?async()=>{await x([{type:`events.iterate.com/agent/context-added`,payload:{role:`developer`,content:`The user interrupted the in-progress response from the web chat.`,llmRequestPolicy:{behaviour:`interrupt-current-request`}}}])}:void 0});return/* @__PURE__ */ (0,q.jsx)(gn,{feed:e,older:n,logShare:r,followTail:te+t,empty:/* @__PURE__ */ (0,q.jsx)(fr,{caughtUp:i,failed:a,readProgress:o?r:void 0,empty:g}),after:m,footer:/* @__PURE__ */ (0,q.jsx)(`div`,{className:`pointer-events-none bg-linear-to-t from-background from-80% to-transparent px-2 pt-2 pb-[max(0.5rem,env(safe-area-inset-bottom))] sm:px-4 sm:pt-4 sm:pb-[max(1rem,env(safe-area-inset-bottom))] md:px-6`,children:/* @__PURE__ */ (0,q.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl`,children:[/* @__PURE__ */ (0,q.jsx)(ce,{}),ee,h,/* @__PURE__ */ (0,q.jsx)($n,{messages:e.state.queuedUserMessages,isInterrupting:E?.isInterrupting||!1,onInterrupt:E?.run,signedUrl:u,me:f}),/* @__PURE__ */ (0,q.jsx)(Je,{draft:v,placeholder:_,autoFocusMessage:!0,attach:S,interrupt:E,onTyping:C,onSubmit:async e=>{T(e=>e+1),await b({...e,key:y.keyFor(e)}),y.sent()},onAppendRaw:async e=>{if(!x)throw Error(`not connected`);T(e=>e+1),await x(e)}})]})}),toggledIds:s,onToggle:c,inspect:l,signedUrl:u,itemFooter:d,me:f,agentPath:p,typing:w})}function fr({caughtUp:e,failed:t,readProgress:n,empty:r}){return t?null:!e||n!==void 0?/* @__PURE__ */ (0,q.jsx)(ue,{progress:n}):r?/* @__PURE__ */ (0,q.jsx)(`div`,{"data-slot":`agent-chat-empty`,className:`flex h-full items-center justify-center py-6`,children:r}):/* @__PURE__ */ (0,q.jsx)(tt,{className:`py-16`,children:/* @__PURE__ */ (0,q.jsxs)(rt,{children:[/* @__PURE__ */ (0,q.jsx)(it,{children:`Nothing said yet`}),/* @__PURE__ */ (0,q.jsx)(nt,{children:`Say something below. The agent answers with prose, or with a script it runs against the mind.`})]})})}function pr(e){let t=r(e),[n,i]=(0,K.useState)({version:t,count:0});return t&&t!==n.version&&i({version:t,count:n.version?n.count+1:n.count}),n.count}const mr={...yn,event:void 0};function hr(e,t,n){let r=(0,K.useRef)(e),i=!!(t.llmRequest||t.scriptRun||t.event);(0,K.useEffect)(()=>{r.current!==e&&(r.current=e,i&&n(mr))},[e,i,n])}function gr(){let[e,t]=(0,K.useState)(()=>/* @__PURE__ */ new Set);return[e,(0,K.useCallback)(e=>t(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),[])]}function _r(e,t){let n=e.llmRequest?{kind:`llmRequest`,llmRequestOffset:e.llmRequest}:e.scriptRun?{kind:`scriptRun`,requestOffset:e.scriptRun}:null,r=(0,K.useCallback)(e=>t({...M,llmRequest:e?.kind===`llmRequest`?e.llmRequestOffset:void 0,scriptRun:e?.kind===`scriptRun`?e.requestOffset:void 0}),[t]);return{inspected:n,inspect:(0,K.useMemo)(()=>({llmRequest:e=>r({kind:`llmRequest`,llmRequestOffset:e}),scriptRun:e=>r({kind:`scriptRun`,requestOffset:e})}),[r]),onInspect:r}}function vr(e,t,n){let{loadOlder:r,loading:i}=t,a=n[0]?.offset;(0,K.useEffect)(()=>{e&&!i&&r()},[e,i,r,a])}function yr(e){let[t,n]=(0,K.useState)(!1),[r,i]=(0,K.useState)(),{onInterrupt:a,runningLlmRequestId:o}=e,[s,c]=(0,K.useState)(o);return s!==o&&(c(o),i(void 0)),!a||o===void 0?null:{isInterrupting:t,error:r,run:async()=>{if(!t){n(!0),i(void 0);try{await a()}catch(e){i(e instanceof Error?e.message:String(e))}finally{n(!1)}}}}}export{gr as a,yn as c,vr as i,bn as l,tr as n,_r as o,rr as r,Yn as s,ir as t,Nt as u};
M dist/chunks/agent-events.mjs
@@ -1,1 +1,1 @@ -import{_ as e,d as t,f as n,g as r,l as i,m as a,p as o,r as s,t as c,u as l}from"./vendor-zod";import{a as u,o as d,t as f}from"./agent-facts.mjs";import{n as p,r as m,t as h}from"./run.mjs";import{r as g}from"./principal-label.mjs";const _=1024,v=a().regex(/^(0|[1-9]\d*)$/),ee=o({length:l().int().nonnegative(),blockCount:l().int().nonnegative(),tailOffset:l().int().nonnegative(),groups:n(v,n(v,a().max(1025)))}).superRefine((e,t)=>{let n=0,r=0;for(let t of Object.values(e.groups))r+=Object.keys(t).length;if(r!==e.blockCount){t.addIssue({code:`custom`,message:`Text block count does not match its content`});return}for(let r=0;r<e.blockCount;r++){let i=e.groups[Math.floor(r/32)]?.[r];if(!i||r<e.blockCount-1&&i.length<_){t.addIssue({code:`custom`,message:`Text blocks must be contiguous and full before the tail`});return}n+=i.length}let i=e.groups[Math.floor((e.blockCount-1)/32)]?.[e.blockCount-1];(n!==e.length||e.tailOffset>(i?.length??0))&&t.addIssue({code:`custom`,message:`Text block metadata does not match its content`})});r([a(),ee]);function y(e,t){let n=typeof e==`string`?{length:0,blockCount:0,tailOffset:0,groups:{}}:e,r=typeof e==`string`?e+t:t;if(r===``)return n;let i={...n.groups},{length:a,blockCount:o,tailOffset:s}=n,c=0;for(;c<r.length;){let e=Math.max(0,o-1),t=Math.floor(e/32),n=i[t]?.[e]??``,l=/[\uD800-\uDBFF]$/.test(n)&&/[\uDC00-\uDFFF]/.test(r[c]);n.length>=_&&!l&&(e=o,t=Math.floor(e/32),n=``);let u=Math.min(r.length,c+Math.max(1,_-n.length));/[\uD800-\uDBFF]/.test(r[u-1])&&/[\uDC00-\uDFFF]/.test(r[u]??``)&&(u+=1),s=n.length,i[t]={...i[t],[e]:n+r.slice(c,u)},a+=u-c,o=e+1,c=u}return{length:a,blockCount:o,tailOffset:s,groups:i}}function b(e,t=0,n=e.length){if(typeof e==`string`)return e.slice(t,n);let r=Math.trunc(t)||0,i=Math.trunc(n)||0,a=Math.max(0,r<0?e.length+r:r),o=Math.min(e.length,i<0?e.length+i:i),s=[],c=0;for(let t=0;t<e.blockCount&&c<o;t++){let n=e.groups[Math.floor(t/32)][t];c+n.length>a&&s.push(n.slice(Math.max(0,a-c),o-c)),c+=n.length}return s.join(``)}function x(e){if(e?.schedule||e?.copiedFrom||e?.platform)return;if(e?.signer){let{actor:t,kind:n}=e.signer.principal;return n===`mind`?{actor:t,script:!1}:void 0}let t=e?.principal||e?.onBehalfOf?.principal;if(!t)return;let{actor:n,email:r,name:i,kind:a}=t;return{actor:n,email:r,name:i,kind:a,script:!e?.principal&&!!e?.onBehalfOf?.run}}function S(e){return`${g(e)}${e.script?` (a script)`:``}`}function C(e,t){return t?e.actor===t||e.email?.toLowerCase()===t.toLowerCase():!1}const w=c([`interrupted-by-user-input`,`superseded`,`expired`]);function T(e,t=e.steps){let n=0,r=0,i=!1,a=!1,o=!1,s;for(let e of t){if(e.kind===`code`){n+=1,i||=e.success===!1;continue}r+=1;let t=e.outcome===`cancelled`;t&&e.cancelReason===`interrupted-by-user-input`?(a=!0,s=e.interruptedBy,o||=e.thinkingText.length>0||e.responseText.length>0):t&&e.cancelReason===`superseded`||(e.outcome===`failed`||t)&&(i=!0)}return{codeCount:n,requestCount:r,outcome:i?`failed`:a?`interrupted`:`clean`,interruptedWithPartialResponse:o,interruptedBy:s}}function te(e,t={}){let n=t.summary||T(e),r=[];if(n.codeCount>0&&r.push(`Ran code ${n.codeCount}×`),r.push(`${n.requestCount} request${n.requestCount===1?``:`s`}`),n.outcome===`interrupted`){let e=n.interruptedBy?`interrupted by ${C(n.interruptedBy,t.me)?`you`:S(n.interruptedBy)}`:`interrupted`;r.push(n.interruptedWithPartialResponse&&t.interruptedPartialHint?`${e} (${t.interruptedPartialHint})`:e)}n.outcome===`failed`&&r.push(`failed`);let i=e.endedAtMs==null?null:Math.max(0,e.endedAtMs-e.startedAtMs);return i!=null&&i>0&&r.push(E(i)),r.join(` · `)}function ne(e){let t=[];for(let n of e){let e=t.at(-1);n.kind===`llm`?t.push({llm:n,code:null}):e&&!e.code?e.code=n:t.push({llm:null,code:n})}return t}function E(e){if(e<1e3)return`${Math.round(e)} ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,``)} s`;let t=Math.round(e/1e3);return`${Math.floor(t/60)}m ${t%60}s`}function D(e){return!!e?.steps.some(e=>e.status===`running`)}function O(e){let t=e.live;if(!t)return null;let n=e.summaryActivity&&e.summaryActivityUpdatedAtMs!==null&&e.summaryActivityUpdatedAtMs>=t.startedAtMs?e.summaryActivity:null;return{phase:(()=>{let n=t.steps.findLast(e=>e.status===`running`);if(n?.kind===`code`)return`running`;if(n?.kind===`llm`&&n.responseText.length>0)return`writing`;if(n?.kind===`llm`&&(n.thinkingText.length>0||n.thinking))return`thinking`;if(n?.kind===`llm`)return`waiting`;let r=t.steps.at(-1);return!e.paused&&r?.kind===`code`&&r.status===`done`&&r.success&&r.result!==void 0||!e.paused&&r?.kind===`llm`&&r.status===`done`&&r.outcome===`completed`&&b(r.responseText).includes(`<codemode`)?`processing`:`working`})(),statusText:n}}function k(e){return e.live?D(e.live)||O(e)?.phase===`processing`:!1}function A(){return{live:null,deferredAssistantMessages:[],queuedUserMessages:[],heldBackground:[],summaryActivity:null,summaryActivityUpdatedAtMs:null,paused:!1,senderByMessage:{},drawnInputs:{},subagentPaths:{}}}function re(e,t){let n=[];return{endState:ae(e,t,n),items:n}}function ie(e){if(D(e.live))return{endState:e,items:[]};let t=[];return{endState:F(P(e,t),t),items:t}}function ae(e,t,n){let r=Date.parse(t.createdAt);if(!Number.isFinite(r))return e;switch(t.type){case`events.iterate.com/agent/message-received`:{let n=U(t,`message`);return n==null?e:{...e,senderByMessage:{...e.senderByMessage,[t.offset]:{sender:x(t.source),from:fe(t),words:n,files:H(t)}}}}case f.uiMessageReceived:{let i=U(t,`message`);if(i==null)return e;let a=H(t),o=x(t.source),s={path:t.path,sender:o};return L({...e,drawnInputs:{...e.drawnInputs,[t.offset]:s}},n,{kind:`user`,id:`user-${t.offset}`,offset:t.offset,text:i,...a.length===0?{}:{files:a},timestampMs:r,sender:o,saidBy:o&&S(o)})}case`events.iterate.com/agent/context-added`:{let i=U(t,`role`),a=U(t,`content`);if(a==null||i===`assistant`||i===`system`)return e;let o=i===`user`?M(t):void 0,s=o&&oe(e,t,o,n);if(s)return s;let c=H(t),l=x(t.source),u=K(t,`llmRequestPolicy`)?.behaviour,d=u===`interrupt-current-request`?{...e,interruptBy:l}:e;if(i===`user`){let e={offset:t.offset,text:a,...c.length===0?{}:{files:c},timestampMs:r,sender:l,saidBy:l&&S(l),from:se(t)};return u===`dont-trigger-request`?I(d,n,{kind:`background`,id:`background-${t.offset}`,offset:t.offset,messages:[e]}):L(d,n,{kind:`user`,id:`user-${t.offset}`,...e})}return K(t,`actor`)?.type===`agent`?L(d,n,{kind:`user`,id:`user-${t.offset}`,offset:t.offset,text:a,...c.length===0?{}:{files:c},timestampMs:r}):d}case f.uiMessageSent:{let i=U(t,`message`);if(i==null)return e;let a=H(t);return R(e,n,{kind:`assistant`,id:`assistant-${t.offset}`,offset:t.offset,text:i,...a.length===0?{}:{files:a},timestampMs:r})}case f.uiWidgetShown:{let i=q(t);if(!i||typeof i.html!=`string`)return e;let a=[i.key,i.id].find(e=>typeof e==`string`&&e.trim()!==``);return R(e,n,{kind:`widget`,id:`widget-${t.offset}`,offset:t.offset,key:a?.slice(0,200)??`widget-${String(t.offset)}`,timestampMs:r})}case f.llmRequested:return U(t,`purpose`)===`answer`?ce(e.queuedUserMessages.length===0&&e.live?e:F(P(e,n),n),t,r):e;case f.llmResponseFrame:{let n=q(t),r=n?.llmRequestOffset;if(!n||typeof r!=`number`)return e;let i=typeof n.textDelta==`string`?n.textDelta:``,a=typeof n.thinkingDelta==`string`?n.thinkingDelta:``,o=typeof n.attempt==`number`?n.attempt:0,s=n.thinking===!0;return z(e,r,e=>!i&&!a&&s===!!e.thinking?e:le(e,{attempt:o,responseDelta:i,thinkingDelta:a,thinking:s}))}case f.llmSettled:{let n=q(t),i=n?.llmRequestOffset;return!n||typeof i!=`number`?e:ue(e,i,n,r)}case`events.iterate.com/itx/run-requested`:{let n=p.safeParse(t.payload);if(!n.success)return e;let i=d(t.idempotencyKey),a=i===void 0?e:z(e,i,e=>({...e,interpreted:!0})),o=N(a,t.offset,r),s={kind:`code`,id:`code-${t.offset}`,requestOffset:t.offset,status:`running`,code:n.data.code,startedAtMs:r,deadlineAtMs:r+h,activitySummary:e.summaryActivity||void 0};return{...a,live:{...o,steps:[...o.steps,s]}}}case`events.iterate.com/itx/run-settled`:{let i=m.safeParse(t.payload);if(!i.success||!e.live)return e;let{requestOffset:a,settlement:o}=i.data,s=[...e.live.steps],c=s.findIndex(e=>e.kind===`code`&&e.requestOffset===a),l=s[c];if(!l||l.kind!==`code`||l.status!==`running`)return e;s[c]={...l,status:`done`,durationMs:Math.max(0,r-l.startedAtMs),endedAtMs:r,...o.status===`succeeded`?{success:!0,...Object.hasOwn(o,`result`)&&{result:o.result}}:{success:!1,errorMessage:o.error},activitySummary:e.summaryActivity||void 0};let u={...e,live:{...e.live,steps:s}},d=o.status===`succeeded`&&o.result===void 0,f=l.repliedAtOnce&&c===s.length-1&&(d||o.status!==`succeeded`);return(u.deferredAssistantMessages.length>0||u.queuedUserMessages.length>0||u.paused||f)&&!D(u.live)?F(P(u,n),n):u}case`events.iterate.com/agent/summary-updated`:{let n=U(t,`activity`);if(!n)return e;if(e.live){let t=e.live.steps.map(e=>e.kind===`code`&&e.status===`running`?{...e,activitySummary:n}:e);return{...e,summaryActivity:n,summaryActivityUpdatedAtMs:r,live:{...e.live,steps:t}}}return{...e,summaryActivity:n,summaryActivityUpdatedAtMs:r}}case`events.iterate.com/itx/paused`:case`events.iterate.com/agent/paused`:{let i=P({...e,paused:!0},n),a=i.live?i:F(i,n);return n.push({kind:`stream-paused`,id:`stream-paused-${t.offset}`,text:`Agent paused`,...W(t),timestampMs:r}),a}case`events.iterate.com/itx/resumed`:case`events.iterate.com/agent/resumed`:return n.push({kind:`stream-resumed`,id:`stream-resumed-${t.offset}`,text:`Agent resumed`,...W(t),timestampMs:r}),{...e,paused:!1};case f.llmRequestTriggered:{let i=U(t,`reason`);return j(e,n,t,r,{about:`request`,text:i?`Asked for an answer: ${i}`:`Asked for an answer`})}case f.subagentRequested:{let n=U(t,`path`);return n?{...e,subagentPaths:{...e.subagentPaths,[t.offset]:n}}:e}case f.subagentStarted:case f.subagentFailed:{let i=G(t,`requestOffset`),a=i===null?void 0:e.subagentPaths[i],o=i===null?e.subagentPaths:B(e.subagentPaths,i),s=U(t,`path`)??a,c=G(t,`copiedItems`)??0,l=U(t,`error`),u=t.type===f.subagentStarted;return j({...e,subagentPaths:o},n,t,r,{about:`subagent`,text:u?`Started a subagent${s?` at ${s}`:``}${c>0?`, with ${String(c)} items of this conversation`:``}`:`A subagent${s?` at ${s}`:``} did not start`,detail:l||void 0,...u?{}:{failed:!0}})}case f.slackMessageSent:case f.slackMessageFailed:{let i=t.type===f.slackMessageSent,a=U(t,`channel`),o=i?U(t,`text`):U(t,`error`);return j(e,n,t,r,{about:`slack`,text:i?`Sent a Slack message${a?` in ${a}`:``}`:`A Slack message was not sent`,detail:o||void 0,...i?{}:{failed:!0}})}default:return e}}function j(e,t,n,r,i){let a={kind:`note`,id:`note-${String(n.offset)}`,offset:n.offset,timestampMs:r,...i};return e.live?{...e,heldBackground:[...e.heldBackground,a]}:(t.push(a),e)}function M(e){let t=K(e,`source`);return typeof t?.path==`string`&&typeof t.offset==`number`?{path:t.path,offset:t.offset}:void 0}function oe(e,t,n,r){let i=K(t,`llmRequestPolicy`)?.behaviour,a=e.drawnInputs[n.offset];if(a&&(!a.path||a.path===n.path)){let t=B(e.drawnInputs,n.offset);return i===`interrupt-current-request`?{...e,drawnInputs:t,interruptBy:a.sender}:{...e,drawnInputs:t}}let o=e.senderByMessage[n.offset];if(!o||t.path&&t.path!==n.path)return;let s={...e,senderByMessage:B(e.senderByMessage,n.offset)},{files:c}=o,l={offset:t.offset,text:o.words,...c.length===0?{}:{files:c},timestampMs:Date.parse(t.createdAt),sender:o.sender,saidBy:o.sender&&S(o.sender),from:o.from};return i===`dont-trigger-request`?I(s,r,{kind:`background`,id:`background-${t.offset}`,offset:t.offset,messages:[l]}):L(i===`interrupt-current-request`?{...s,interruptBy:o.sender}:s,r,{kind:`user`,id:`user-${t.offset}`,...l})}function se(e){let t=e.source?.origin;if(e.path&&t?.startsWith(`/`)&&!(e.source?.schedule||e.source?.copiedFrom||e.source?.platform))return[e.path,`/`,`/agents`].includes(t)?void 0:t}function ce(e,t,n){let r=N(e,t.offset,n),i=U(t,`model`),a={kind:`llm`,id:`llm-${t.offset}`,llmRequestOffset:t.offset,status:`running`,model:i||void 0,thinkingText:``,responseText:``,startedAtMs:n};return{...e,live:{...r,steps:[...r.steps,a]}}}function le(e,t){let{attempt:n,responseDelta:r,thinkingDelta:i,thinking:a}=t,o=e.attempt??0;if(e.status!==`running`||n<o)return e;let s=n>o?{responseText:``,thinkingText:``}:e;return{...e,attempt:n,responseText:r===``?s.responseText:y(s.responseText,r),thinkingText:i===``?s.thinkingText:y(s.thinkingText,i),thinking:a??e.thinking}}function ue(e,t,n,r){let i=J(n.result)?n.result:void 0,a=typeof i?.status==`string`?i.status:`succeeded`,o=V(i?.usage),s=typeof i?.errorMessage==`string`?i.errorMessage:void 0,c=w.safeParse(i?.reason),l=c.success?c.data:null,u=typeof i?.partialText==`string`?i.partialText:null;return z(e,t,t=>t.outcome?t:{...t,status:`done`,endedAtMs:r,outcome:a===`succeeded`?`completed`:a===`failed`?`failed`:`cancelled`,...a===`succeeded`&&typeof i?.text==`string`&&{responseText:i.text,thinking:!1},...u&&u.length>t.responseText.length&&u.startsWith(b(t.responseText))&&{responseText:u},...typeof n.durationMs==`number`?{durationMs:n.durationMs}:a===`cancelled`?{durationMs:Math.max(0,r-t.startedAtMs)}:{},inputTokens:o.input,outputTokens:o.output,errorMessage:s,cancelReason:l||void 0,interruptedBy:l===`interrupted-by-user-input`?e.interruptBy:void 0})}function N(e,t,n){return e.live?{...e.live,status:`running`}:{kind:`activity`,id:`activity-${t}`,status:`running`,steps:[],startedAtMs:n}}function de(e){if(!e.live)return e;let t=e.live.steps.filter(e=>e.kind!==`llm`||e.status!==`running`);return t.length===e.live.steps.length?e:{...e,live:t.length>0?{...e.live,steps:t}:null}}function P(e,t){if(!e.live||D(e.live))return e;let{steps:n}=e.live;if(n.length>0){let r=Math.max(...n.map(e=>e.endedAtMs??e.startedAtMs));t.push({...e.live,status:`done`,endedAtMs:r})}return{...e,live:null}}function F(e,t){return t.push(...[...e.deferredAssistantMessages,...e.queuedUserMessages,...e.heldBackground].sort((e,t)=>e.offset-t.offset)),{...e,deferredAssistantMessages:[],queuedUserMessages:[],heldBackground:[]}}function I(e,t,n){return e.live?{...e,heldBackground:[...e.heldBackground,n]}:(t.push(n),e)}function L(e,t,n){let r=P(e,t);if(D(r.live))return{...r,queuedUserMessages:[...r.queuedUserMessages,n]};let i=r.live?r:F(r,t);return t.push(n),i}function R(e,t,n){let r=P(e,t);if(!r.live){let e=F(r,t);return t.push(n),e}if(r.live.steps.some(e=>e.kind===`code`&&e.status===`running`)){t.push(...r.deferredAssistantMessages,n);let e=r.live.steps.map(e=>e.kind===`code`&&e.status===`running`?{...e,repliedAtOnce:!0}:e);return{...r,live:{...r.live,steps:e},deferredAssistantMessages:[]}}return{...r,deferredAssistantMessages:[...r.deferredAssistantMessages,n]}}function z(e,t,n){if(!e.live)return e;let r=e.live.steps.findIndex(e=>e.kind===`llm`&&e.llmRequestOffset===t),i=e.live.steps[r];if(!i||i.kind!==`llm`)return e;let a=[...e.live.steps];return a[r]=n(i),{...e,live:{...e.live,steps:a}}}function B(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>Number(e)!==t))}function V(e){return J(e)?{...typeof e.inputTokens==`number`&&{input:e.inputTokens},...typeof e.outputTokens==`number`&&{output:e.outputTokens}}:{}}function H(e){let t=q(e)?.files;return Array.isArray(t)?t.flatMap(e=>{if(!J(e))return[];let t=typeof e.contentType==`string`?e.contentType:null,n=typeof e.filename==`string`?e.filename:null,r=typeof e.path==`string`?e.path:null,i=typeof e.size==`number`&&Number.isFinite(e.size)?e.size:null;return!t||!n||!r||i==null?[]:[{contentType:t,filename:n,path:r,size:i}]}):[]}function U(e,t){let n=q(e)?.[t];return typeof n==`string`?n:null}function W(e){let t=U(e,`reason`);return t?{reason:t}:{}}function G(e,t){let n=q(e)?.[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function fe(e){let t=U(e,`from`);return t?.startsWith(`/`)&&t!==`/`?t:void 0}function K(e,t){let n=q(e)?.[t];return J(n)?n:null}function q(e){return J(e.payload)?e.payload:null}function J(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const pe=i({offset:l().int().positive(),type:a(),createdAt:a(),payload:e().optional(),metadata:n(a(),e()).optional(),idempotencyKey:a().optional()});function Y(e){let t=pe.safeParse(e);return t.success?t.data:null}const me=/* @__PURE__ */ new Set([`events.iterate.com/itx/started-over`,`events.iterate.com/itx/version-ended`]),X={log:[],events:[],state:A(),items:[],versionEndedAt:null};function he(e,t){let n=e&&e.log.length>0&&t[0]===e.log[0]&&t[e.log.length-1]===e.log.at(-1),r=n?e:X,i=t.slice(r.log.length).flatMap(e=>Y(e)??[]),a=i.findLast(e=>me.has(e.type)),o=a?{...X,versionEndedAt:a.offset}:r,s=a?i.slice(i.indexOf(a)+1):i,{state:c}=o,l=[];for(let e of s){let t=re(c,e);c=t.endState,l.push(...t.items)}let u=Z(l);return{log:t,events:s.length>0?o.events.concat(s):o.events,state:c,items:u.length>0?n&&!a?Q(o.items,u):ge(u,e?.items):o.items,versionEndedAt:o.versionEndedAt}}function Z(e){let t=[];for(let n of e){let e=t.at(-1);n.kind===`background`&&e?.kind===`background`?e.messages.push(...n.messages):t.push(n.kind===`background`?{...n,messages:[...n.messages]}:n)}return t}function Q(e,t){let n=e.at(-1),[r,...i]=t;if(n?.kind!==`background`||r?.kind!==`background`)return e.concat(t);let a={...n,messages:[...n.messages,...r.messages]};return[...e.slice(0,-1),a,...i]}function ge(e,t=[]){let n=new Map(t.map(e=>[e.id,e]));return e.map(e=>{let t=n.get(e.id);return!t||e.kind===`activity`||e.kind===`background`&&t.kind===`background`&&e.messages.length!==t.messages.length?e:t})}function _e(e,t,n=!0){let r=n?e.state:de(e.state);if(!t)return{state:r,items:e.items};let i=ie(r),a=i.items.length>0?Q(e.items,Z(i.items)):e.items;return{state:i.endState,items:a}}function ve(e){let t=e.indexOf(`//#region your script`),n=e.lastIndexOf(`//#endregion your script`);return t===-1||n<t?null:e.slice(t+21,n).trim()}function $(e){return`${(Math.max(0,e)/1e3).toFixed(1)}s`}function ye(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function be(e){return new Date(e).toLocaleString([],{dateStyle:`medium`,timeStyle:`medium`})}function xe(e){if(e<1024)return`${String(e)} B`;let t=e/1024;return t<1024?`${t.toFixed(1).replace(/\.0$/,``)} KB`:`${(t/1024).toFixed(1).replace(/\.0$/,``)} MB`}const Se=/^\s*(async|await|function|const|let|import)\b/,Ce=/^[ \t]*<codemode(\s|>)/m;function we(e){let t=typeof e==`string`?e:b(e,0,4096);return t.includes("```")||Se.test(t)||Ce.test(t)}function Te(e){if(e.some(e=>e.kind===`code`))return`Running code`;let t=e.findLast(e=>e.kind===`llm`);return t?t.kind===`llm`&&t.responseText.length>0?`Writing code`:t.kind===`llm`&&(t.thinking||t.thinkingText.length>0)?`Thinking`:`Waiting for a response`:`Working…`}const Ee=t({itemsAdded:s(i({atOffset:l().optional(),rank:l().optional(),tag:a().optional(),text:a()}))});function De(e,t){let n=e.find(e=>e.offset===t&&e.type===`events.iterate.com/itx/run-requested`),r=p.safeParse(n?.payload);if(!n||!r.success)return null;let[i]=e.flatMap(e=>{if(e.type!==`events.iterate.com/itx/run-settled`)return[];let n=m.safeParse(e.payload);return n.success&&n.data.requestOffset===t?[{atMs:Date.parse(e.createdAt),value:n.data.settlement}]:[]}),a=u(n.idempotencyKey),[o]=a?e.flatMap(e=>{if(e.type!==f.llmRequested)return[];let t=Ee.safeParse(e.payload);if(!t.success)return[];let n=t.data.itemsAdded.find(e=>e.tag===`script-result`&&e.atOffset===a.requestOffset&&e.rank===1+a.index);return n?[n.text]:[]}):[];return{requestOffset:t,code:r.data.code,requestedAtMs:Date.parse(n.createdAt),settlement:i,seen:o}}export{k as _,be as a,b,Te as c,Y as d,O as f,A as g,ne as h,ye as i,we as l,E as m,ve as n,$ as o,te as p,he as r,xe as s,_e as t,De as u,T as v,C as y}; +import{_ as e,d as t,f as n,h as r,m as i,p as a,r as o,t as s,u as c,v as l}from"./vendor-zod";import{a as u,o as d,t as f}from"./agent-facts.mjs";import{n as p,r as m,t as h}from"./run.mjs";import{r as g}from"./principal-label.mjs";const _=1024,v=r().regex(/^(0|[1-9]\d*)$/),ee=i({length:t().int().nonnegative(),blockCount:t().int().nonnegative(),tailOffset:t().int().nonnegative(),groups:a(v,a(v,r().max(1025)))}).superRefine((e,t)=>{let n=0,r=0;for(let t of Object.values(e.groups))r+=Object.keys(t).length;if(r!==e.blockCount){t.addIssue({code:`custom`,message:`Text block count does not match its content`});return}for(let r=0;r<e.blockCount;r++){let i=e.groups[Math.floor(r/32)]?.[r];if(!i||r<e.blockCount-1&&i.length<_){t.addIssue({code:`custom`,message:`Text blocks must be contiguous and full before the tail`});return}n+=i.length}let i=e.groups[Math.floor((e.blockCount-1)/32)]?.[e.blockCount-1];(n!==e.length||e.tailOffset>(i?.length??0))&&t.addIssue({code:`custom`,message:`Text block metadata does not match its content`})});e([r(),ee]);function y(e,t){let n=typeof e==`string`?{length:0,blockCount:0,tailOffset:0,groups:{}}:e,r=typeof e==`string`?e+t:t;if(r===``)return n;let i={...n.groups},{length:a,blockCount:o,tailOffset:s}=n,c=0;for(;c<r.length;){let e=Math.max(0,o-1),t=Math.floor(e/32),n=i[t]?.[e]??``,l=/[\uD800-\uDBFF]$/.test(n)&&/[\uDC00-\uDFFF]/.test(r[c]);n.length>=_&&!l&&(e=o,t=Math.floor(e/32),n=``);let u=Math.min(r.length,c+Math.max(1,_-n.length));/[\uD800-\uDBFF]/.test(r[u-1])&&/[\uDC00-\uDFFF]/.test(r[u]??``)&&(u+=1),s=n.length,i[t]={...i[t],[e]:n+r.slice(c,u)},a+=u-c,o=e+1,c=u}return{length:a,blockCount:o,tailOffset:s,groups:i}}function b(e,t=0,n=e.length){if(typeof e==`string`)return e.slice(t,n);let r=Math.trunc(t)||0,i=Math.trunc(n)||0,a=Math.max(0,r<0?e.length+r:r),o=Math.min(e.length,i<0?e.length+i:i),s=[],c=0;for(let t=0;t<e.blockCount&&c<o;t++){let n=e.groups[Math.floor(t/32)][t];c+n.length>a&&s.push(n.slice(Math.max(0,a-c),o-c)),c+=n.length}return s.join(``)}function x(e){if(e?.schedule||e?.copiedFrom||e?.platform)return;if(e?.signer){let{actor:t,kind:n}=e.signer.principal;return n===`mind`?{actor:t,script:!1}:void 0}let t=e?.principal||e?.onBehalfOf?.principal;if(!t)return;let{actor:n,email:r,name:i,kind:a}=t;return{actor:n,email:r,name:i,kind:a,script:!e?.principal&&!!e?.onBehalfOf?.run}}function S(e){return`${g(e)}${e.script?` (a script)`:``}`}function C(e,t){return t?e.actor===t||e.email?.toLowerCase()===t.toLowerCase():!1}const w=s([`interrupted-by-user-input`,`superseded`,`expired`]);function T(e,t=e.steps){let n=0,r=0,i=!1,a=!1,o=!1,s;for(let e of t){if(e.kind===`code`){n+=1,i||=e.success===!1;continue}r+=1;let t=e.outcome===`cancelled`;t&&e.cancelReason===`interrupted-by-user-input`?(a=!0,s=e.interruptedBy,o||=e.thinkingText.length>0||e.responseText.length>0):t&&e.cancelReason===`superseded`||(e.outcome===`failed`||t)&&(i=!0)}return{codeCount:n,requestCount:r,outcome:i?`failed`:a?`interrupted`:`clean`,interruptedWithPartialResponse:o,interruptedBy:s}}function te(e,t={}){let n=t.summary||T(e),r=[];if(n.codeCount>0&&r.push(`Ran code ${n.codeCount}×`),r.push(`${n.requestCount} request${n.requestCount===1?``:`s`}`),n.outcome===`interrupted`){let e=n.interruptedBy?`interrupted by ${C(n.interruptedBy,t.me)?`you`:S(n.interruptedBy)}`:`interrupted`;r.push(n.interruptedWithPartialResponse&&t.interruptedPartialHint?`${e} (${t.interruptedPartialHint})`:e)}n.outcome===`failed`&&r.push(`failed`);let i=e.endedAtMs==null?null:Math.max(0,e.endedAtMs-e.startedAtMs);return i!=null&&i>0&&r.push(E(i)),r.join(` · `)}function ne(e){let t=[];for(let n of e){let e=t.at(-1);n.kind===`llm`?t.push({llm:n,code:null}):e&&!e.code?e.code=n:t.push({llm:null,code:n})}return t}function E(e){if(e<1e3)return`${Math.round(e)} ms`;if(e<6e4)return`${(e/1e3).toFixed(1).replace(/\.0$/,``)} s`;let t=Math.round(e/1e3);return`${Math.floor(t/60)}m ${t%60}s`}function D(e){return!!e?.steps.some(e=>e.status===`running`)}function O(e){let t=e.live;if(!t)return null;let n=e.summaryActivity&&e.summaryActivityUpdatedAtMs!==null&&e.summaryActivityUpdatedAtMs>=t.startedAtMs?e.summaryActivity:null;return{phase:(()=>{let n=t.steps.findLast(e=>e.status===`running`);if(n?.kind===`code`)return`running`;if(n?.kind===`llm`&&n.responseText.length>0)return`writing`;if(n?.kind===`llm`&&(n.thinkingText.length>0||n.thinking))return`thinking`;if(n?.kind===`llm`)return`waiting`;let r=t.steps.at(-1);return!e.paused&&r?.kind===`code`&&r.status===`done`&&r.success&&r.result!==void 0||!e.paused&&r?.kind===`llm`&&r.status===`done`&&r.outcome===`completed`&&b(r.responseText).includes(`<codemode`)?`processing`:`working`})(),statusText:n}}function k(e){return e.live?D(e.live)||O(e)?.phase===`processing`:!1}function A(){return{live:null,deferredAssistantMessages:[],queuedUserMessages:[],heldBackground:[],summaryActivity:null,summaryActivityUpdatedAtMs:null,paused:!1,senderByMessage:{},drawnInputs:{},subagentPaths:{}}}function re(e,t){let n=[];return{endState:ae(e,t,n),items:n}}function ie(e){if(D(e.live))return{endState:e,items:[]};let t=[];return{endState:F(P(e,t),t),items:t}}function ae(e,t,n){let r=Date.parse(t.createdAt);if(!Number.isFinite(r))return e;switch(t.type){case`events.iterate.com/agent/message-received`:{let n=U(t,`message`);return n==null?e:{...e,senderByMessage:{...e.senderByMessage,[t.offset]:{sender:x(t.source),from:fe(t),words:n,files:H(t)}}}}case f.uiMessageReceived:{let i=U(t,`message`);if(i==null)return e;let a=H(t),o=x(t.source),s={path:t.path,sender:o};return L({...e,drawnInputs:{...e.drawnInputs,[t.offset]:s}},n,{kind:`user`,id:`user-${t.offset}`,offset:t.offset,text:i,...a.length===0?{}:{files:a},timestampMs:r,sender:o,saidBy:o&&S(o)})}case`events.iterate.com/agent/context-added`:{let i=U(t,`role`),a=U(t,`content`);if(a==null||i===`assistant`||i===`system`)return e;let o=i===`user`?M(t):void 0,s=o&&oe(e,t,o,n);if(s)return s;let c=H(t),l=x(t.source),u=K(t,`llmRequestPolicy`)?.behaviour,d=u===`interrupt-current-request`?{...e,interruptBy:l}:e;if(i===`user`){let e={offset:t.offset,text:a,...c.length===0?{}:{files:c},timestampMs:r,sender:l,saidBy:l&&S(l),from:se(t)};return u===`dont-trigger-request`?I(d,n,{kind:`background`,id:`background-${t.offset}`,offset:t.offset,messages:[e]}):L(d,n,{kind:`user`,id:`user-${t.offset}`,...e})}return K(t,`actor`)?.type===`agent`?L(d,n,{kind:`user`,id:`user-${t.offset}`,offset:t.offset,text:a,...c.length===0?{}:{files:c},timestampMs:r}):d}case f.uiMessageSent:{let i=U(t,`message`);if(i==null)return e;let a=H(t);return R(e,n,{kind:`assistant`,id:`assistant-${t.offset}`,offset:t.offset,text:i,...a.length===0?{}:{files:a},timestampMs:r})}case f.uiWidgetShown:{let i=q(t);if(!i||typeof i.html!=`string`)return e;let a=[i.key,i.id].find(e=>typeof e==`string`&&e.trim()!==``);return R(e,n,{kind:`widget`,id:`widget-${t.offset}`,offset:t.offset,key:a?.slice(0,200)??`widget-${String(t.offset)}`,timestampMs:r})}case f.llmRequested:return U(t,`purpose`)===`answer`?ce(e.queuedUserMessages.length===0&&e.live?e:F(P(e,n),n),t,r):e;case f.llmResponseFrame:{let n=q(t),r=n?.llmRequestOffset;if(!n||typeof r!=`number`)return e;let i=typeof n.textDelta==`string`?n.textDelta:``,a=typeof n.thinkingDelta==`string`?n.thinkingDelta:``,o=typeof n.attempt==`number`?n.attempt:0,s=n.thinking===!0;return z(e,r,e=>!i&&!a&&s===!!e.thinking?e:le(e,{attempt:o,responseDelta:i,thinkingDelta:a,thinking:s}))}case f.llmSettled:{let n=q(t),i=n?.llmRequestOffset;return!n||typeof i!=`number`?e:ue(e,i,n,r)}case`events.iterate.com/itx/run-requested`:{let n=p.safeParse(t.payload);if(!n.success)return e;let i=d(t.idempotencyKey),a=i===void 0?e:z(e,i,e=>({...e,interpreted:!0})),o=N(a,t.offset,r),s={kind:`code`,id:`code-${t.offset}`,requestOffset:t.offset,status:`running`,code:n.data.code,startedAtMs:r,deadlineAtMs:r+h,activitySummary:e.summaryActivity||void 0};return{...a,live:{...o,steps:[...o.steps,s]}}}case`events.iterate.com/itx/run-settled`:{let i=m.safeParse(t.payload);if(!i.success||!e.live)return e;let{requestOffset:a,settlement:o}=i.data,s=[...e.live.steps],c=s.findIndex(e=>e.kind===`code`&&e.requestOffset===a),l=s[c];if(!l||l.kind!==`code`||l.status!==`running`)return e;s[c]={...l,status:`done`,durationMs:Math.max(0,r-l.startedAtMs),endedAtMs:r,...o.status===`succeeded`?{success:!0,...Object.hasOwn(o,`result`)&&{result:o.result}}:{success:!1,errorMessage:o.error},activitySummary:e.summaryActivity||void 0};let u={...e,live:{...e.live,steps:s}},d=o.status===`succeeded`&&o.result===void 0,f=l.repliedAtOnce&&c===s.length-1&&(d||o.status!==`succeeded`);return(u.deferredAssistantMessages.length>0||u.queuedUserMessages.length>0||u.paused||f)&&!D(u.live)?F(P(u,n),n):u}case`events.iterate.com/agent/summary-updated`:{let n=U(t,`activity`);if(!n)return e;if(e.live){let t=e.live.steps.map(e=>e.kind===`code`&&e.status===`running`?{...e,activitySummary:n}:e);return{...e,summaryActivity:n,summaryActivityUpdatedAtMs:r,live:{...e.live,steps:t}}}return{...e,summaryActivity:n,summaryActivityUpdatedAtMs:r}}case`events.iterate.com/itx/paused`:case`events.iterate.com/agent/paused`:{let i=P({...e,paused:!0},n),a=i.live?i:F(i,n);return n.push({kind:`stream-paused`,id:`stream-paused-${t.offset}`,text:`Agent paused`,...W(t),timestampMs:r}),a}case`events.iterate.com/itx/resumed`:case`events.iterate.com/agent/resumed`:return n.push({kind:`stream-resumed`,id:`stream-resumed-${t.offset}`,text:`Agent resumed`,...W(t),timestampMs:r}),{...e,paused:!1};case f.llmRequestTriggered:{let i=U(t,`reason`);return j(e,n,t,r,{about:`request`,text:i?`Asked for an answer: ${i}`:`Asked for an answer`})}case f.subagentRequested:{let n=U(t,`path`);return n?{...e,subagentPaths:{...e.subagentPaths,[t.offset]:n}}:e}case f.subagentStarted:case f.subagentFailed:{let i=G(t,`requestOffset`),a=i===null?void 0:e.subagentPaths[i],o=i===null?e.subagentPaths:B(e.subagentPaths,i),s=U(t,`path`)??a,c=G(t,`copiedItems`)??0,l=U(t,`error`),u=t.type===f.subagentStarted;return j({...e,subagentPaths:o},n,t,r,{about:`subagent`,text:u?`Started a subagent${s?` at ${s}`:``}${c>0?`, with ${String(c)} items of this conversation`:``}`:`A subagent${s?` at ${s}`:``} did not start`,detail:l||void 0,...u?{}:{failed:!0}})}case f.slackMessageSent:case f.slackMessageFailed:{let i=t.type===f.slackMessageSent,a=U(t,`channel`),o=i?U(t,`text`):U(t,`error`);return j(e,n,t,r,{about:`slack`,text:i?`Sent a Slack message${a?` in ${a}`:``}`:`A Slack message was not sent`,detail:o||void 0,...i?{}:{failed:!0}})}default:return e}}function j(e,t,n,r,i){let a={kind:`note`,id:`note-${String(n.offset)}`,offset:n.offset,timestampMs:r,...i};return e.live?{...e,heldBackground:[...e.heldBackground,a]}:(t.push(a),e)}function M(e){let t=K(e,`source`);return typeof t?.path==`string`&&typeof t.offset==`number`?{path:t.path,offset:t.offset}:void 0}function oe(e,t,n,r){let i=K(t,`llmRequestPolicy`)?.behaviour,a=e.drawnInputs[n.offset];if(a&&(!a.path||a.path===n.path)){let t=B(e.drawnInputs,n.offset);return i===`interrupt-current-request`?{...e,drawnInputs:t,interruptBy:a.sender}:{...e,drawnInputs:t}}let o=e.senderByMessage[n.offset];if(!o||t.path&&t.path!==n.path)return;let s={...e,senderByMessage:B(e.senderByMessage,n.offset)},{files:c}=o,l={offset:t.offset,text:o.words,...c.length===0?{}:{files:c},timestampMs:Date.parse(t.createdAt),sender:o.sender,saidBy:o.sender&&S(o.sender),from:o.from};return i===`dont-trigger-request`?I(s,r,{kind:`background`,id:`background-${t.offset}`,offset:t.offset,messages:[l]}):L(i===`interrupt-current-request`?{...s,interruptBy:o.sender}:s,r,{kind:`user`,id:`user-${t.offset}`,...l})}function se(e){let t=e.source?.origin;if(e.path&&t?.startsWith(`/`)&&!(e.source?.schedule||e.source?.copiedFrom||e.source?.platform))return[e.path,`/`,`/agents`].includes(t)?void 0:t}function ce(e,t,n){let r=N(e,t.offset,n),i=U(t,`model`),a={kind:`llm`,id:`llm-${t.offset}`,llmRequestOffset:t.offset,status:`running`,model:i||void 0,thinkingText:``,responseText:``,startedAtMs:n};return{...e,live:{...r,steps:[...r.steps,a]}}}function le(e,t){let{attempt:n,responseDelta:r,thinkingDelta:i,thinking:a}=t,o=e.attempt??0;if(e.status!==`running`||n<o)return e;let s=n>o?{responseText:``,thinkingText:``}:e;return{...e,attempt:n,responseText:r===``?s.responseText:y(s.responseText,r),thinkingText:i===``?s.thinkingText:y(s.thinkingText,i),thinking:a??e.thinking}}function ue(e,t,n,r){let i=J(n.result)?n.result:void 0,a=typeof i?.status==`string`?i.status:`succeeded`,o=V(i?.usage),s=typeof i?.errorMessage==`string`?i.errorMessage:void 0,c=w.safeParse(i?.reason),l=c.success?c.data:null,u=typeof i?.partialText==`string`?i.partialText:null;return z(e,t,t=>t.outcome?t:{...t,status:`done`,endedAtMs:r,outcome:a===`succeeded`?`completed`:a===`failed`?`failed`:`cancelled`,...a===`succeeded`&&typeof i?.text==`string`&&{responseText:i.text,thinking:!1},...u&&u.length>t.responseText.length&&u.startsWith(b(t.responseText))&&{responseText:u},...typeof n.durationMs==`number`?{durationMs:n.durationMs}:a===`cancelled`?{durationMs:Math.max(0,r-t.startedAtMs)}:{},inputTokens:o.input,outputTokens:o.output,errorMessage:s,cancelReason:l||void 0,interruptedBy:l===`interrupted-by-user-input`?e.interruptBy:void 0})}function N(e,t,n){return e.live?{...e.live,status:`running`}:{kind:`activity`,id:`activity-${t}`,status:`running`,steps:[],startedAtMs:n}}function de(e){if(!e.live)return e;let t=e.live.steps.filter(e=>e.kind!==`llm`||e.status!==`running`);return t.length===e.live.steps.length?e:{...e,live:t.length>0?{...e.live,steps:t}:null}}function P(e,t){if(!e.live||D(e.live))return e;let{steps:n}=e.live;if(n.length>0){let r=Math.max(...n.map(e=>e.endedAtMs??e.startedAtMs));t.push({...e.live,status:`done`,endedAtMs:r})}return{...e,live:null}}function F(e,t){return t.push(...[...e.deferredAssistantMessages,...e.queuedUserMessages,...e.heldBackground].sort((e,t)=>e.offset-t.offset)),{...e,deferredAssistantMessages:[],queuedUserMessages:[],heldBackground:[]}}function I(e,t,n){return e.live?{...e,heldBackground:[...e.heldBackground,n]}:(t.push(n),e)}function L(e,t,n){let r=P(e,t);if(D(r.live))return{...r,queuedUserMessages:[...r.queuedUserMessages,n]};let i=r.live?r:F(r,t);return t.push(n),i}function R(e,t,n){let r=P(e,t);if(!r.live){let e=F(r,t);return t.push(n),e}if(r.live.steps.some(e=>e.kind===`code`&&e.status===`running`)){t.push(...r.deferredAssistantMessages,n);let e=r.live.steps.map(e=>e.kind===`code`&&e.status===`running`?{...e,repliedAtOnce:!0}:e);return{...r,live:{...r.live,steps:e},deferredAssistantMessages:[]}}return{...r,deferredAssistantMessages:[...r.deferredAssistantMessages,n]}}function z(e,t,n){if(!e.live)return e;let r=e.live.steps.findIndex(e=>e.kind===`llm`&&e.llmRequestOffset===t),i=e.live.steps[r];if(!i||i.kind!==`llm`)return e;let a=[...e.live.steps];return a[r]=n(i),{...e,live:{...e.live,steps:a}}}function B(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>Number(e)!==t))}function V(e){return J(e)?{...typeof e.inputTokens==`number`&&{input:e.inputTokens},...typeof e.outputTokens==`number`&&{output:e.outputTokens}}:{}}function H(e){let t=q(e)?.files;return Array.isArray(t)?t.flatMap(e=>{if(!J(e))return[];let t=typeof e.contentType==`string`?e.contentType:null,n=typeof e.filename==`string`?e.filename:null,r=typeof e.path==`string`?e.path:null,i=typeof e.size==`number`&&Number.isFinite(e.size)?e.size:null;return!t||!n||!r||i==null?[]:[{contentType:t,filename:n,path:r,size:i}]}):[]}function U(e,t){let n=q(e)?.[t];return typeof n==`string`?n:null}function W(e){let t=U(e,`reason`);return t?{reason:t}:{}}function G(e,t){let n=q(e)?.[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function fe(e){let t=U(e,`from`);return t?.startsWith(`/`)&&t!==`/`?t:void 0}function K(e,t){let n=q(e)?.[t];return J(n)?n:null}function q(e){return J(e.payload)?e.payload:null}function J(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}const pe=c({offset:t().int().positive(),type:r(),createdAt:r(),payload:l().optional(),metadata:a(r(),l()).optional(),idempotencyKey:r().optional()});function Y(e){let t=pe.safeParse(e);return t.success?t.data:null}const me=/* @__PURE__ */ new Set([`events.iterate.com/itx/started-over`,`events.iterate.com/itx/version-ended`]),X={log:[],events:[],state:A(),items:[],versionEndedAt:null};function he(e,t){let n=e&&e.log.length>0&&t[0]===e.log[0]&&t[e.log.length-1]===e.log.at(-1),r=n?e:X,i=t.slice(r.log.length).flatMap(e=>Y(e)??[]),a=i.findLast(e=>me.has(e.type)),o=a?{...X,versionEndedAt:a.offset}:r,s=a?i.slice(i.indexOf(a)+1):i,{state:c}=o,l=[];for(let e of s){let t=re(c,e);c=t.endState,l.push(...t.items)}let u=Z(l);return{log:t,events:s.length>0?o.events.concat(s):o.events,state:c,items:u.length>0?n&&!a?Q(o.items,u):ge(u,e?.items):o.items,versionEndedAt:o.versionEndedAt}}function Z(e){let t=[];for(let n of e){let e=t.at(-1);n.kind===`background`&&e?.kind===`background`?e.messages.push(...n.messages):t.push(n.kind===`background`?{...n,messages:[...n.messages]}:n)}return t}function Q(e,t){let n=e.at(-1),[r,...i]=t;if(n?.kind!==`background`||r?.kind!==`background`)return e.concat(t);let a={...n,messages:[...n.messages,...r.messages]};return[...e.slice(0,-1),a,...i]}function ge(e,t=[]){let n=new Map(t.map(e=>[e.id,e]));return e.map(e=>{let t=n.get(e.id);return!t||e.kind===`activity`||e.kind===`background`&&t.kind===`background`&&e.messages.length!==t.messages.length?e:t})}function _e(e,t,n=!0){let r=n?e.state:de(e.state);if(!t)return{state:r,items:e.items};let i=ie(r),a=i.items.length>0?Q(e.items,Z(i.items)):e.items;return{state:i.endState,items:a}}function ve(e){let t=e.indexOf(`//#region your script`),n=e.lastIndexOf(`//#endregion your script`);return t===-1||n<t?null:e.slice(t+21,n).trim()}function $(e){return`${(Math.max(0,e)/1e3).toFixed(1)}s`}function ye(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function be(e){return new Date(e).toLocaleString([],{dateStyle:`medium`,timeStyle:`medium`})}function xe(e){if(e<1024)return`${String(e)} B`;let t=e/1024;return t<1024?`${t.toFixed(1).replace(/\.0$/,``)} KB`:`${(t/1024).toFixed(1).replace(/\.0$/,``)} MB`}const Se=/^\s*(async|await|function|const|let|import)\b/,Ce=/^[ \t]*<codemode(\s|>)/m;function we(e){let t=typeof e==`string`?e:b(e,0,4096);return t.includes("```")||Se.test(t)||Ce.test(t)}function Te(e){if(e.some(e=>e.kind===`code`))return`Running code`;let t=e.findLast(e=>e.kind===`llm`);return t?t.kind===`llm`&&t.responseText.length>0?`Writing code`:t.kind===`llm`&&(t.thinking||t.thinkingText.length>0)?`Thinking`:`Waiting for a response`:`Working…`}const Ee=n({itemsAdded:o(c({atOffset:t().optional(),rank:t().optional(),tag:r().optional(),text:r()}))});function De(e,t){let n=e.find(e=>e.offset===t&&e.type===`events.iterate.com/itx/run-requested`),r=p.safeParse(n?.payload);if(!n||!r.success)return null;let[i]=e.flatMap(e=>{if(e.type!==`events.iterate.com/itx/run-settled`)return[];let n=m.safeParse(e.payload);return n.success&&n.data.requestOffset===t?[{atMs:Date.parse(e.createdAt),value:n.data.settlement}]:[]}),a=u(n.idempotencyKey),[o]=a?e.flatMap(e=>{if(e.type!==f.llmRequested)return[];let t=Ee.safeParse(e.payload);if(!t.success)return[];let n=t.data.itemsAdded.find(e=>e.tag===`script-result`&&e.atOffset===a.requestOffset&&e.rank===1+a.index);return n?[n.text]:[]}):[];return{requestOffset:t,code:r.data.code,requestedAtMs:Date.parse(n.createdAt),settlement:i,seen:o}}export{k as _,be as a,b,Te as c,Y as d,O as f,A as g,ne as h,ye as i,we as l,E as m,ve as n,$ as o,te as p,he as r,xe as s,_e as t,De as u,T as v,C as y};
M dist/chunks/agent-facts.mjs
@@ -1,1 +1,1 @@ -import{d as e,i as t,m as n,r,u as i}from"./vendor-zod";const a=`events.iterate.com/`,o={uiMessageReceived:`${a}agent-ui/message-received`,uiAgentRequested:`${a}agent-ui/agent-requested`,uiMessageSent:`${a}agent-ui/message-sent`,uiWidgetShown:`${a}agent-ui/widget-shown`,llmRequested:`${a}llm-request/requested`,llmAttemptStarted:`${a}llm-request/attempt-started`,llmResponseFrame:`${a}llm-request/response-frame-received`,llmSettled:`${a}llm-request/settled`,llmRequestTriggered:`${a}agent/llm-request-triggered`,subagentRequested:`${a}agent/subagent-requested`,subagentStarted:`${a}agent/subagent-started`,subagentFailed:`${a}agent/subagent-failed`,slackMessageSent:`${a}slack/message-sent`,slackMessageFailed:`${a}slack/message-failed`},s=(e,t)=>`${a}${e}/${t}`;function c(e){let[,t,n]=/^agent\/script-run:(\d+)\/(\d+)$/.exec(e||``)??[];return t&&n?{requestOffset:Number(t),index:Number(n)}:void 0}function l(e){return c(e)?.requestOffset}const u=e({paused:e({reason:n()}).nullable(),llmRequests:r(e({requestOffset:i(),purpose:n(),model:n()})),pendingTriggerOffsets:r(i()),scriptCalls:r(e({answered:t()}))});function d(e){let t=u.safeParse(e);return t.success?t.data:void 0}function f(e){return{type:o.uiMessageReceived,...e.key&&{idempotencyKey:`agent-ui/message-received:${e.key}`},payload:{message:e.message,...e.files.length>0&&{files:[...e.files]},client:e.client||p(),widget:e.widget}}}function p(){return globalThis.navigator&&/Mobi|Android|iPhone|iPad/i.test(navigator.userAgent)?`mobile`:`web`}async function m(e,t){if(e.files.length>0&&!t.storeFiles)return await t.onMessage(e);let n=e.files.length>0&&t.storeFiles?await t.storeFiles(e.files,e.key):[];await t.onAppend([f({message:e.message,files:n,key:e.key,widget:e.widget})])}export{c as a,s as i,d as n,l as o,f as r,m as s,o as t}; +import{d as e,f as t,h as n,i as r,r as i}from"./vendor-zod";const a=`events.iterate.com/`,o={uiMessageReceived:`${a}agent-ui/message-received`,uiAgentRequested:`${a}agent-ui/agent-requested`,uiMessageSent:`${a}agent-ui/message-sent`,uiWidgetShown:`${a}agent-ui/widget-shown`,llmRequested:`${a}llm-request/requested`,llmAttemptStarted:`${a}llm-request/attempt-started`,llmResponseFrame:`${a}llm-request/response-frame-received`,llmSettled:`${a}llm-request/settled`,llmRequestTriggered:`${a}agent/llm-request-triggered`,subagentRequested:`${a}agent/subagent-requested`,subagentStarted:`${a}agent/subagent-started`,subagentFailed:`${a}agent/subagent-failed`,slackMessageSent:`${a}slack/message-sent`,slackMessageFailed:`${a}slack/message-failed`},s=(e,t)=>`${a}${e}/${t}`;function c(e){let[,t,n]=/^agent\/script-run:(\d+)\/(\d+)$/.exec(e||``)??[];return t&&n?{requestOffset:Number(t),index:Number(n)}:void 0}function l(e){return c(e)?.requestOffset}const u=t({paused:t({reason:n()}).nullable(),llmRequests:i(t({requestOffset:e(),purpose:n(),model:n()})),pendingTriggerOffsets:i(e()),scriptCalls:i(t({answered:r()}))});function d(e){let t=u.safeParse(e);return t.success?t.data:void 0}function f(e){return{type:o.uiMessageReceived,...e.key&&{idempotencyKey:`agent-ui/message-received:${e.key}`},payload:{message:e.message,...e.files.length>0&&{files:[...e.files]},client:e.client||p(),widget:e.widget}}}function p(){return globalThis.navigator&&/Mobi|Android|iPhone|iPad/i.test(navigator.userAgent)?`mobile`:`web`}async function m(e,t){if(e.files.length>0&&!t.storeFiles)return await t.onMessage(e);let n=e.files.length>0&&t.storeFiles?await t.storeFiles(e.files,e.key):[];await t.onAppend([f({message:e.message,files:n,key:e.key,widget:e.widget})])}export{c as a,s as i,d as n,l as o,f as r,m as s,o as t};
M dist/chunks/agent-look.mjs
@@ -1,1 +1,1 @@ -import{Ft as e,Pt as t,m as n}from"./vendor-icons";function r(r){return!r||r===`iterate`||r===`agent`?e:r===`claude`||r===`codex`||r===`opencode`?n:t}const i={working:`bg-success`,waiting:`bg-warning`,idle:`bg-muted-foreground/60`,ended:`border border-muted-foreground/60 bg-sidebar`};export{r as n,i as t}; +import{Ft as e,It as t,m as n}from"./vendor-icons";function r(r){return!r||r===`iterate`||r===`agent`?t:r===`claude`||r===`codex`||r===`opencode`?n:e}const i={working:`bg-success`,waiting:`bg-warning`,idle:`bg-muted-foreground/60`,ended:`border border-muted-foreground/60 bg-sidebar`};export{r as n,i as t};
M dist/chunks/agent-strip.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{bt as r}from"./vendor-icons";import{c as i}from"./ui-base";import{Tabs as a,TabsList as o,TabsTrigger as s}from"../components/ui/tabs";var c=/* @__PURE__ */ e(t(),1);const l=(0,c.createContext)(!1),u=(0,c.createContext)(null);var d=/* @__PURE__ */ e(n(),1);function f({status:e,view:t,hasChat:n,tabs:r,held:i,wholeLogHeld:a,onStateChange:o,aside:s}){return/* @__PURE__ */ (0,d.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 px-4 py-1`,children:[e?.text?/* @__PURE__ */ (0,d.jsx)(h,{status:e}):null,/* @__PURE__ */ (0,d.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[s,r?/* @__PURE__ */ (0,d.jsx)(p,{view:t,hasChat:n,held:i,wholeLogHeld:a,onStateChange:o}):null]})]})}function p({view:e,hasChat:t,held:n,wholeLogHeld:r,onStateChange:i,className:c}){return/* @__PURE__ */ (0,d.jsx)(a,{value:e||`chat`,onValueChange:e=>i({view:e===`chat`?void 0:`events`}),className:c,children:/* @__PURE__ */ (0,d.jsxs)(o,{className:`h-8 pointer-coarse:h-10`,children:[t?/* @__PURE__ */ (0,d.jsx)(s,{value:`chat`,className:`text-xs`,children:`Chat`}):null,/* @__PURE__ */ (0,d.jsx)(s,{value:`events`,className:`text-xs`,children:/* @__PURE__ */ (0,d.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5`,children:[`Events`,n===void 0?null:/* @__PURE__ */ (0,d.jsxs)(`span`,{className:`font-mono text-2xs text-muted-foreground/70`,children:[n,r?``:`+`]})]})})]})})}function m(){let e=(0,c.use)(u);return e?/* @__PURE__ */ (0,d.jsx)(`div`,{"data-slot":`agent-foot-status`,className:`flex h-5 min-w-0 items-center px-1 pb-1`,children:e.status?.text?/* @__PURE__ */ (0,d.jsx)(h,{status:e.status}):null}):null}function h({status:e}){return/* @__PURE__ */ (0,d.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 truncate text-xs text-muted-foreground`,title:e.detail,"data-status":e.tone,children:[/* @__PURE__ */ (0,d.jsx)(r,{className:i(`size-2 shrink-0`,e.tone===`live`&&`fill-success text-success`,e.tone===`amber`&&`fill-warning text-warning`,e.tone===`muted`&&`fill-muted-foreground/40 text-muted-foreground/40`)}),/* @__PURE__ */ (0,d.jsx)(`span`,{className:`truncate`,children:e.text})]})}export{l as a,u as i,f as n,p as r,m as t}; +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{xt as r}from"./vendor-icons";import{c as i}from"./ui-base";import{Tabs as a,TabsList as o,TabsTrigger as s}from"../components/ui/tabs";var c=/* @__PURE__ */ e(t(),1);const l=(0,c.createContext)(!1),u=(0,c.createContext)(null);var d=/* @__PURE__ */ e(n(),1);function f({status:e,view:t,hasChat:n,tabs:r,held:i,wholeLogHeld:a,onStateChange:o,aside:s}){return/* @__PURE__ */ (0,d.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 px-4 py-1`,children:[e?.text?/* @__PURE__ */ (0,d.jsx)(h,{status:e}):null,/* @__PURE__ */ (0,d.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[s,r?/* @__PURE__ */ (0,d.jsx)(p,{view:t,hasChat:n,held:i,wholeLogHeld:a,onStateChange:o}):null]})]})}function p({view:e,hasChat:t,held:n,wholeLogHeld:r,onStateChange:i,className:c}){return/* @__PURE__ */ (0,d.jsx)(a,{value:e||`chat`,onValueChange:e=>i({view:e===`chat`?void 0:`events`}),className:c,children:/* @__PURE__ */ (0,d.jsxs)(o,{className:`h-8 pointer-coarse:h-10`,children:[t?/* @__PURE__ */ (0,d.jsx)(s,{value:`chat`,className:`text-xs`,children:`Chat`}):null,/* @__PURE__ */ (0,d.jsx)(s,{value:`events`,className:`text-xs`,children:/* @__PURE__ */ (0,d.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5`,children:[`Events`,n===void 0?null:/* @__PURE__ */ (0,d.jsxs)(`span`,{className:`font-mono text-2xs text-muted-foreground/70`,children:[n,r?``:`+`]})]})})]})})}function m(){let e=(0,c.use)(u);return e?/* @__PURE__ */ (0,d.jsx)(`div`,{"data-slot":`agent-foot-status`,className:`flex h-5 min-w-0 items-center px-1 pb-1`,children:e.status?.text?/* @__PURE__ */ (0,d.jsx)(h,{status:e.status}):null}):null}function h({status:e}){return/* @__PURE__ */ (0,d.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 truncate text-xs text-muted-foreground`,title:e.detail,"data-status":e.tone,children:[/* @__PURE__ */ (0,d.jsx)(r,{className:i(`size-2 shrink-0`,e.tone===`live`&&`fill-success text-success`,e.tone===`amber`&&`fill-warning text-warning`,e.tone===`muted`&&`fill-muted-foreground/40 text-muted-foreground/40`)}),/* @__PURE__ */ (0,d.jsx)(`span`,{className:`truncate`,children:e.text})]})}export{l as a,u as i,f as n,p as r,m as t};
M dist/chunks/agent-summary.mjs
@@ -1,1 +1,1 @@ -import{d as e,f as t,i as n,m as r,t as i}from"./vendor-zod";import"./run.mjs";function a(e,t){let n=t-(e.lastActivityAt?Date.parse(e.lastActivityAt):0);return e.status===`working`||e.status===`waiting`?n<864e5:e.status===`idle`&&!!e.activity&&n<6e5}const o=i([`working`,`idle`,`waiting`,`ended`]),s=e({agents:t(r(),e({createdAt:r(),parent:r().nullish(),kind:r().nullish(),host:r().nullish(),status:o.nullish().catch(null),activity:r().nullish(),description:r().nullish(),title:r().nullish(),titleFromWords:n().nullish().catch(null),lastActivityAt:r().nullish()}))});function c(e){let t=s.safeParse(e);return t.success?Object.entries(t.data.agents).map(([e,t])=>({path:e,createdAt:t.createdAt,parent:t.parent||null,kind:t.kind||null,host:t.host||null,status:t.status||null,activity:t.activity||null,description:t.description||null,title:t.title||null,...!!t.title&&!!t.titleFromWords&&{titleFromWords:!0},lastActivityAt:t.lastActivityAt||null})):[]}function l(e){let t=new Map(e.map(e=>[e.path,e])),n=u(e);return e.filter(e=>{if(n(e))return!1;let r=e.parent&&t.get(e.parent);return!r||n(r)})}function u(e){let t=new Set(e.map(e=>e.parent));return e=>!e.kind&&!e.title&&(t.has(e.path)||S(e.path))}function d(e){return!e.kind&&!e.title&&!e.status&&!e.activity&&!e.description&&!e.lastActivityAt}function f(e){let t=u(e),n=l(e),r=new Set(n.map(e=>e.path)),i=/* @__PURE__ */ new Map;for(let e of n)p(e.path).some(e=>r.has(e))||i.set(e.path,{row:e,subagents:[]});for(let n of e)if(!(t(n)||d(n)))for(let e of p(n.path))i.get(e)?.subagents.push(n);let a=[...i.values()].map(e=>({row:e.row,subagents:y(e.subagents)})),o=new Map(a.map(e=>[e,[e.row,...e.subagents].map(v).reduce((e,t)=>e>t?e:t)]));return a.toSorted((e,t)=>o.get(t).localeCompare(o.get(e))||e.row.path.localeCompare(t.row.path))}function p(e){let t=[];for(let n=e.indexOf(`/`);n!==-1;n=e.indexOf(`/`,n+1))t.push(e.slice(0,n));return t}function m(e){return e===0?null:e===1?`and 1 subagent`:`and ${String(e)} subagents`}function h(e,t){let n=u(e),r=t.toLowerCase().split(/\s+/).filter(Boolean);return y(e.filter(e=>{if(n(e))return!1;let t=[e.title,e.path,e.activity,e.description].join(` `).toLowerCase();return r.every(e=>t.includes(e))}))}function g(e){return e.title||e.path.split(`/`).filter(Boolean).at(-1)||e.path}function _(e,t=Date.now()){return a(e,t)?e.activity:null}function v(e){return e.lastActivityAt||e.createdAt}function y(e){return e.toSorted((e,t)=>v(t).localeCompare(v(e))||e.path.localeCompare(t.path))}const b=`people`;function x(e){return(e||``).split(`@`)[0].toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40).replace(/-+$/,``)||void 0}function S(e){let[,t,n,...r]=e.split(`/`);return t===`agents`&&n===b&&r.length<=2}function C(e){let[,t,n,r,...i]=e.split(`/`);return t===`agents`&&n===b&&i.length>0?r:void 0}function w(e){return(new URLSearchParams((e||``).replace(/^#/,``)).get(`draft`)||``).slice(0,4e3)}function T(e,t,n){let r=t.toISOString().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return n?`/agents/${b}/${n}/${e}/${r}`:`/agents/${e}/${r}`}function E(e,t){return t?[...e.filter(e=>C(e.path)===t),...e.filter(e=>C(e.path)!==t)]:[...e]}function D(e,t,n){let r=E(y(e),n);return{pinned:r.filter(e=>t.has(e.path)),recent:r.filter(e=>!t.has(e.path))}}export{y as a,E as c,C as d,x as f,a as h,g as i,T as l,l as m,f as n,w as o,m as p,c as r,h as s,_ as t,D as u}; +import{f as e,h as t,i as n,p as r,t as i}from"./vendor-zod";import"./run.mjs";function a(e,t){let n=t-(e.lastActivityAt?Date.parse(e.lastActivityAt):0);return e.status===`working`||e.status===`waiting`?n<864e5:e.status===`idle`&&!!e.activity&&n<6e5}const o=i([`working`,`idle`,`waiting`,`ended`]),s=e({agents:r(t(),e({createdAt:t(),parent:t().nullish(),kind:t().nullish(),host:t().nullish(),status:o.nullish().catch(null),activity:t().nullish(),description:t().nullish(),title:t().nullish(),titleFromWords:n().nullish().catch(null),lastActivityAt:t().nullish()}))});function c(e){let t=s.safeParse(e);return t.success?Object.entries(t.data.agents).map(([e,t])=>({path:e,createdAt:t.createdAt,parent:t.parent||null,kind:t.kind||null,host:t.host||null,status:t.status||null,activity:t.activity||null,description:t.description||null,title:t.title||null,...!!t.title&&!!t.titleFromWords&&{titleFromWords:!0},lastActivityAt:t.lastActivityAt||null})):[]}function l(e){let t=new Map(e.map(e=>[e.path,e])),n=u(e);return e.filter(e=>{if(n(e))return!1;let r=e.parent&&t.get(e.parent);return!r||n(r)})}function u(e){let t=new Set(e.map(e=>e.parent));return e=>!e.kind&&!e.title&&(t.has(e.path)||S(e.path))}function d(e){return!e.kind&&!e.title&&!e.status&&!e.activity&&!e.description&&!e.lastActivityAt}function f(e){let t=u(e),n=l(e),r=new Set(n.map(e=>e.path)),i=/* @__PURE__ */ new Map;for(let e of n)p(e.path).some(e=>r.has(e))||i.set(e.path,{row:e,subagents:[]});for(let n of e)if(!(t(n)||d(n)))for(let e of p(n.path))i.get(e)?.subagents.push(n);let a=[...i.values()].map(e=>({row:e.row,subagents:y(e.subagents)})),o=new Map(a.map(e=>[e,[e.row,...e.subagents].map(v).reduce((e,t)=>e>t?e:t)]));return a.toSorted((e,t)=>o.get(t).localeCompare(o.get(e))||e.row.path.localeCompare(t.row.path))}function p(e){let t=[];for(let n=e.indexOf(`/`);n!==-1;n=e.indexOf(`/`,n+1))t.push(e.slice(0,n));return t}function m(e){return e===0?null:e===1?`and 1 subagent`:`and ${String(e)} subagents`}function h(e,t){let n=u(e),r=t.toLowerCase().split(/\s+/).filter(Boolean);return y(e.filter(e=>{if(n(e))return!1;let t=[e.title,e.path,e.activity,e.description].join(` `).toLowerCase();return r.every(e=>t.includes(e))}))}function g(e){return e.title||e.path.split(`/`).filter(Boolean).at(-1)||e.path}function _(e,t=Date.now()){return a(e,t)?e.activity:null}function v(e){return e.lastActivityAt||e.createdAt}function y(e){return e.toSorted((e,t)=>v(t).localeCompare(v(e))||e.path.localeCompare(t.path))}const b=`people`;function x(e){return(e||``).split(`@`)[0].toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,40).replace(/-+$/,``)||void 0}function S(e){let[,t,n,...r]=e.split(`/`);return t===`agents`&&n===b&&r.length<=2}function C(e){let[,t,n,r,...i]=e.split(`/`);return t===`agents`&&n===b&&i.length>0?r:void 0}function w(e){return(new URLSearchParams((e||``).replace(/^#/,``)).get(`draft`)||``).slice(0,4e3)}function T(e,t,n){let r=t.toISOString().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return n?`/agents/${b}/${n}/${e}/${r}`:`/agents/${e}/${r}`}function E(e,t){return t?[...e.filter(e=>C(e.path)===t),...e.filter(e=>C(e.path)!==t)]:[...e]}function D(e,t,n){let r=E(y(e),n);return{pinned:r.filter(e=>t.has(e.path)),recent:r.filter(e=>!t.has(e.path))}}export{y as a,E as c,C as d,x as f,a as h,g as i,T as l,l as m,f as n,w as o,m as p,c as r,h as s,_ as t,D as u};
M dist/chunks/app-shell.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,i as n,n as r}from"./vendor-react";import{wipeSavedLogTails as i}from"../lib/saved-log-tail";import{C as a,Et as o,K as s,Tt as c,jt as l,pt as u}from"./vendor-icons";import{c as d,i as f}from"./ui-base";import{I as p,J as m,K as h,N as g,P as _,a as v,g as y,h as b,i as x,j as S,o as C,r as w,t as T,u as E,z as D}from"./ui-shell";import{t as O}from"./iterate-logo.mjs";import{i as ee,l as te,o as ne,r as k,s as A,t as j,u as M}from"./command.mjs";import{C as N,b as P,c as re,d as F,h as I,m as L,n as ie,r as ae,t as R,u as z,w as B,x as V}from"./sidebar.mjs";import{plainLeftClick as H}from"../lib/plain-left-click";import{resetPosthog as U}from"../components/posthog";var W=/* @__PURE__ */ e(t(),1),G=/* @__PURE__ */ e(n(),1);function K(e,t){let n=t.trim().toLowerCase(),r=n.split(/\s+/).filter(Boolean),i=e.filter(e=>{let t=`${e.label} ${e.detail||``}`.toLowerCase();return r.every(e=>t.includes(e))}),a=/* @__PURE__ */ new Map;for(let e of i)a.set(e.group,[...a.get(e.group)||[],e]);return[...a].map(([e,t])=>({group:e,entries:n?[...t.filter(e=>e.label.toLowerCase().startsWith(n)),...t.filter(e=>!e.label.toLowerCase().startsWith(n))]:t}))}function q(e){return!e||e.closest(`[data-mobile]`)?[]:[...e.querySelectorAll(`[data-slot="sidebar-menu-button"], [data-slot="sidebar-menu-sub-button"]`)].flatMap(e=>{if(e.matches(`:disabled, [aria-disabled="true"]`))return[];let[t,...n]=J(e),r=t||e.getAttribute(`aria-label`)?.trim();if(!r)return[];let i=e.closest(`[data-slot="sidebar-group"]`),a=e.dataset.slot===`sidebar-menu-sub-button`?e.closest(`[data-slot="sidebar-menu-sub"]`)?.closest(`[data-slot="sidebar-menu-item"]`)?.querySelector(`[data-slot="sidebar-menu-button"]`):null;return[{element:e,label:r,group:J(i?.querySelector(`[data-slot="sidebar-group-label"]`))[0]||`Pages`,detail:J(a)[0]||n.join(` · `)||void 0,active:e.hasAttribute(`data-active`),href:e instanceof HTMLAnchorElement?e.href:void 0}]})}function J(e){if(!e)return[];let t=/* @__PURE__ */ new Map,n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let r=n.nextNode();r;r=n.nextNode()){let n=r.parentNode||e;t.set(n,`${t.get(n)||``}${r.nodeValue||``}`)}return[...t.values()].map(e=>e.replace(/\s+/g,` `).trim()).filter(Boolean)}var Y=/* @__PURE__ */ e(r(),1);const oe=()=>()=>{};function se(){return(0,W.useSyncExternalStore)(oe,()=>/Mac|iPhone|iPad/.test(navigator.platform)?`⌘K`:`Ctrl K`,()=>`⌘K`)}function ce(e){(0,W.useEffect)(()=>{if(!e)return;function t(t){t.defaultPrevented||t.altKey||t.shiftKey||(t.metaKey||t.ctrlKey)&&t.key.toLowerCase()===`k`&&(t.preventDefault(),e?.())}return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function le({onOpen:e}){let t=se();return/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(L,{type:`button`,tooltip:`Search (${t})`,onClick:e,children:[/* @__PURE__ */ (0,Y.jsx)(a,{}),/* @__PURE__ */ (0,Y.jsx)(`span`,{children:`Search`}),/* @__PURE__ */ (0,Y.jsx)(`kbd`,{className:`ml-auto font-sans text-xs text-muted-foreground`,children:t})]})})})}function ue({onOpen:e}){return/* @__PURE__ */ (0,Y.jsx)(f,{variant:`ghost`,size:`icon-sm`,className:`md:hidden`,"aria-label":`Search`,title:`Search`,onClick:e,children:/* @__PURE__ */ (0,Y.jsx)(a,{})})}function de({nav:e,entries:t,onClose:n}){return/* @__PURE__ */ (0,Y.jsx)(S,{open:!!e,onOpenChange:e=>{e||n()},children:/* @__PURE__ */ (0,Y.jsxs)(g,{showCloseButton:!1,className:`top-[12svh] translate-y-0 overflow-hidden p-0 sm:max-w-lg`,children:[/* @__PURE__ */ (0,Y.jsxs)(p,{className:`sr-only`,children:[/* @__PURE__ */ (0,Y.jsx)(D,{children:`Search`}),/* @__PURE__ */ (0,Y.jsx)(_,{children:`Go to a page`})]}),e?/* @__PURE__ */ (0,Y.jsx)(fe,{nav:e,entries:t,onClose:n}):null]})})}function fe({nav:e,entries:t,onClose:n}){let[r,i]=(0,W.useState)(``),o=e.map(({element:e,label:t,group:n,detail:r,active:i},a)=>({kind:`nav`,id:`nav:${a}`,label:t,group:n,detail:r,active:i,element:e})),s=t.map((e,t)=>({kind:`app`,id:`app:${t}`,...e})),c=K([...o,...s],r);return/* @__PURE__ */ (0,Y.jsxs)(j,{shouldFilter:!1,loop:!0,className:`p-0`,children:[/* @__PURE__ */ (0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[/* @__PURE__ */ (0,Y.jsx)(a,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":!0}),/* @__PURE__ */ (0,Y.jsx)(M.Input,{"data-slot":`command-input`,className:`flex h-8 w-full min-w-0 bg-transparent text-sm outline-hidden placeholder:text-muted-foreground`,placeholder:`Search…`,"aria-label":`Search`,value:r,onValueChange:i})]}),/* @__PURE__ */ (0,Y.jsxs)(A,{className:`max-h-[min(24rem,60svh)] border-t`,children:[/* @__PURE__ */ (0,Y.jsx)(k,{className:`text-muted-foreground`,children:`Nothing matches.`}),c.map(({group:e,entries:t})=>/* @__PURE__ */ (0,Y.jsx)(ee,{heading:e,className:`p-0 **:[[cmdk-group-heading]]:px-3 **:[[cmdk-group-heading]]:py-2`,children:t.map(e=>/* @__PURE__ */ (0,Y.jsx)(ne,{value:e.id,className:`rounded-none px-3 py-2 in-data-[slot=dialog-content]:rounded-none!`,onSelect:()=>{n(),e.kind===`app`?e.onSelect():e.element.click()},children:/* @__PURE__ */ (0,Y.jsx)(pe,{row:e})},e.id))},e))]})]})}function pe({row:e}){return/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate`,children:e.label}),e.detail?/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.detail}):null,e.active?/* @__PURE__ */ (0,Y.jsx)(te,{children:/* @__PURE__ */ (0,Y.jsx)(l,{"aria-label":`current`})}):null]})}const me=()=>()=>{};function he(){let e=document.cookie.split(`; `);if(e.includes(`sidebar_state=false`))return!1;if(e.includes(`sidebar_state=true`))return!0}function ge({app:e,mind:t,switcher:n,nav:r,paletteEntries:i,palette:a,commandPalette:o=!0,searchRow:s=!0,header:c,sidebarDefaultOpen:l=!0,phoneHeader:u=`row`,account:d,accountActions:f,sidebarAlert:p=!1,locationKey:m,children:h}){let g=(0,W.useSyncExternalStore)(me,()=>he()??l,()=>l),_=u===`floating`,v=(0,W.useRef)(null),[y,b]=(0,W.useState)(null),x=(0,W.useCallback)(()=>b(q(v.current)),[]),S=(0,W.useCallback)(()=>b(null),[]),[C,w]=(0,W.useState)(null),[T,E]=(0,W.useState)(null),D=(0,W.useCallback)(()=>b(e=>e?null:q(v.current)),[]);ce(o?D:null),Ee();let O=(0,W.useMemo)(()=>({header:C,menu:T,openPalette:o?x:void 0,appHeader:c}),[C,T,o,x,c]);return/* @__PURE__ */ (0,Y.jsxs)(P,{defaultOpen:g,className:`h-(--app-height,100svh) min-h-0`,children:[/* @__PURE__ */ (0,Y.jsx)(Ce,{locationKey:m}),/* @__PURE__ */ (0,Y.jsxs)(R,{collapsible:`icon`,children:[/* @__PURE__ */ (0,Y.jsxs)(re,{children:[n??/* @__PURE__ */ (0,Y.jsx)(Z,{app:e,line:t}),o&&s?/* @__PURE__ */ (0,Y.jsx)(le,{onOpen:x}):null]}),/* @__PURE__ */ (0,Y.jsx)(we,{navRef:v,children:r}),/* @__PURE__ */ (0,Y.jsxs)(ae,{children:[/* @__PURE__ */ (0,Y.jsx)(De,{}),d===!1?null:d===void 0?/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsx)($,{className:`h-12 group-data-[collapsible=icon]:h-8`})})}):/* @__PURE__ */ (0,Y.jsx)(Oe,{name:d?.email||d?.actor||t||e,mind:t,actions:f})]}),/* @__PURE__ */ (0,Y.jsx)(V,{})]}),/* @__PURE__ */ (0,Y.jsxs)(ve,{floatingHeader:_,locationKey:m,children:[/* @__PURE__ */ (0,Y.jsx)(_e,{header:c,floating:_,sidebarAlert:p,onOpenPalette:o?x:void 0,pageHeaderRef:w,pageMenuRef:E}),/* @__PURE__ */ (0,Y.jsx)(X,{value:O,children:/* @__PURE__ */ (0,Y.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-auto`,children:h})})]}),o?/* @__PURE__ */ (0,Y.jsx)(be,{appPalette:a,nav:y,entries:i||[],onClose:S}):null]})}function _e({header:e,floating:t,sidebarAlert:n,onOpenPalette:r,pageHeaderRef:i,pageMenuRef:a}){return/* @__PURE__ */ (0,Y.jsxs)(`header`,{className:d(`group/header flex shrink-0 items-center gap-3 px-4 pt-2.5 pb-1`,`has-[[data-page-header]]:border-b has-[[data-page-header]]:py-1.5`,!e&&`md:hidden md:has-[[data-page-header]]:flex`,t&&`max-md:pointer-events-none max-md:absolute max-md:inset-x-0 max-md:top-0 max-md:z-20 max-md:bg-linear-to-b max-md:from-background max-md:from-40% max-md:to-transparent max-md:*:pointer-events-auto max-md:motion-safe:transition-transform max-md:motion-safe:duration-200 max-md:group-data-[phone-header=hidden]/inset:not-focus-within:-translate-y-full`),children:[/* @__PURE__ */ (0,Y.jsxs)(`span`,{className:`relative -ml-1 inline-flex md:hidden`,children:[/* @__PURE__ */ (0,Y.jsx)(N,{title:n?`Toggle sidebar (requests wait for approval)`:`Toggle sidebar`,"aria-label":n?`Toggle sidebar (requests wait for approval)`:`Toggle sidebar`}),n?/* @__PURE__ */ (0,Y.jsx)(`span`,{"aria-hidden":`true`,"data-sidebar-alert":!0,className:`pointer-events-none absolute top-0.5 right-0.5 size-2 rounded-full bg-warning ring-2 ring-background`}):null]}),/* @__PURE__ */ (0,Y.jsxs)(`div`,{className:d(`flex min-w-0 items-center gap-3 max-md:group-has-[[data-page-menu]]/header:hidden`,!e&&`md:hidden`),children:[r?/* @__PURE__ */ (0,Y.jsx)(ue,{onOpen:r}):null,e]}),/* @__PURE__ */ (0,Y.jsx)(`div`,{ref:i,className:`flex min-w-0 flex-1 items-center empty:hidden`}),/* @__PURE__ */ (0,Y.jsx)(`div`,{ref:a,className:`ml-auto flex items-center empty:hidden md:hidden`})]})}function ve({floatingHeader:e,locationKey:t,children:n}){let[r,i]=(0,W.useState)(null),a=r!==t,o=(0,W.useRef)(null),s=(0,W.useRef)(0),c=(e,n,r)=>{e?ye(n,r)&&i(t):i(null)};return/* @__PURE__ */ (0,Y.jsx)(z,{className:`group/inset min-w-0 overflow-hidden`,"data-phone-header":e?a?`shown`:`hidden`:void 0,...e&&{onTouchStartCapture:e=>{let t=e.touches[0];o.current=t?{x:t.clientX,y:t.clientY}:null},onTouchMoveCapture:e=>{let t=e.touches[0],n=o.current;if(!t||!n)return;let r=t.clientY-n.y;Math.abs(r)<16||Math.abs(r)<Math.abs(t.clientX-n.x)||(o.current={x:t.clientX,y:t.clientY},c(r<0,e.target,e.currentTarget))},onWheelCapture:e=>{let t=Math.sign(e.deltaY)===Math.sign(s.current)?s.current+e.deltaY:e.deltaY;s.current=Math.abs(t)<16?t:0,Math.abs(t)>=16&&c(t>0,e.target,e.currentTarget)}},children:n})}function ye(e,t){for(let n=e instanceof Element?e:null;n&&n!==t;n=n.parentElement){let{overflowY:e}=getComputedStyle(n);if((e===`auto`||e===`scroll`)&&n.scrollHeight-n.clientHeight-n.scrollTop>1)return!0}return!1}function be({appPalette:e,...t}){return e?e({open:!!t.nav,onClose:t.onClose}):/* @__PURE__ */ (0,Y.jsx)(de,{...t})}const X=(0,W.createContext)(null);function xe(){return!!(0,W.useContext)(X)}function Z({app:e,line:t,logo:n,href:r,onClick:i}){let{isMobile:a,setOpenMobile:o}=B(),s=/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`flex aspect-square size-8 items-center justify-center rounded-md bg-black`,children:n??/* @__PURE__ */ (0,Y.jsx)(O,{alt:``,className:`size-6`})}),/* @__PURE__ */ (0,Y.jsxs)(`span`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e}),t?/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:t}):null]})]});return/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:r?/* @__PURE__ */ (0,Y.jsx)(L,{size:`lg`,tooltip:e,render:/* @__PURE__ */ (0,Y.jsx)(`a`,{href:r,onClick:e=>{let t=a&&H(e);i?.(e),t&&o(!1)}}),children:s}):/* @__PURE__ */ (0,Y.jsx)(L,{size:`lg`,className:`pointer-events-none`,children:s})})})}function Q({children:e}){let t=(0,W.useContext)(X);if(!t)throw Error(`AppShellPageHeader is drawn inside an AppShell`);return t.header?(0,G.createPortal)(/* @__PURE__ */ (0,Y.jsx)(`div`,{"data-page-header":!0,className:`flex min-w-0 flex-1 items-center gap-x-4 gap-y-1 md:flex-wrap`,children:e}),t.header):null}function Se({children:e}){let t=(0,W.useContext)(X);if(!t)throw Error(`AppShellPageMenu is drawn inside an AppShell`);return t.menu?(0,G.createPortal)(/* @__PURE__ */ (0,Y.jsxs)(T,{children:[/* @__PURE__ */ (0,Y.jsx)(b,{"data-page-menu":!0,render:/* @__PURE__ */ (0,Y.jsx)(f,{variant:`ghost`,size:`icon-sm`,className:`md:hidden`,"aria-label":`More`,title:`More`}),children:/* @__PURE__ */ (0,Y.jsx)(u,{})}),/* @__PURE__ */ (0,Y.jsxs)(w,{align:`end`,className:`min-w-56 rounded-lg`,children:[t.appHeader?/* @__PURE__ */ (0,Y.jsx)(`div`,{className:`px-1.5 py-1`,children:t.appHeader}):null,t.openPalette?/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[/* @__PURE__ */ (0,Y.jsx)(x,{children:/* @__PURE__ */ (0,Y.jsxs)(v,{onClick:t.openPalette,children:[/* @__PURE__ */ (0,Y.jsx)(a,{}),`Search`]})}),/* @__PURE__ */ (0,Y.jsx)(E,{})]}):null,e]})]}),t.menu):null}function $({className:e}){return/* @__PURE__ */ (0,Y.jsxs)(`div`,{className:d(`flex h-8 items-center gap-2 px-2`,e),children:[/* @__PURE__ */ (0,Y.jsx)(y,{className:`size-4 rounded-md`}),/* @__PURE__ */ (0,Y.jsx)(y,{className:`h-4 w-2/3`})]})}function Ce({locationKey:e}){let{setOpenMobile:t}=B(),n=(0,W.useRef)(e);return(0,W.useEffect)(()=>{n.current!==e&&(n.current=e,t(!1))},[e,t]),null}function we({navRef:e,children:t}){let{isMobile:n,setOpenMobile:r}=B();return/* @__PURE__ */ (0,Y.jsx)(ie,{ref:e,onClick:e=>{if(!n||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target instanceof Element?e.target.closest(`a[href]`):null;if(!t||!e.currentTarget.contains(t)||t.hasAttribute(`download`))return;let i=t.getAttribute(`target`);i&&i!==`_self`||r(!1)},children:t})}function Te({app:e,logo:t,value:n,items:r,label:i,href:a,mono:o=!1,onSelect:s}){let{isMobile:u,setOpenMobile:f}=B(),p=r.map(e=>typeof e==`string`?{value:e,label:e,href:void 0}:{value:e.value,label:e.label||e.value,href:e.href}),m=p.find(e=>e.value===n)?.label||n;return p.length<=1?/* @__PURE__ */ (0,Y.jsx)(Z,{app:e,line:o?/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`font-mono`,children:m}):m,logo:t,href:a}):/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(T,{children:[/* @__PURE__ */ (0,Y.jsx)(b,{render:/* @__PURE__ */ (0,Y.jsxs)(L,{size:`lg`,className:`data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground`,"aria-label":i?`${i}: ${m}`:`Switch ${e}`,children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`flex aspect-square size-8 items-center justify-center rounded-md bg-black`,children:t??/* @__PURE__ */ (0,Y.jsx)(O,{alt:``,className:`size-6`})}),/* @__PURE__ */ (0,Y.jsxs)(`span`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e}),/* @__PURE__ */ (0,Y.jsx)(`span`,{className:d(`truncate text-xs text-muted-foreground`,o&&`font-mono`),children:m})]}),/* @__PURE__ */ (0,Y.jsx)(c,{className:`ml-auto`})]})}),/* @__PURE__ */ (0,Y.jsx)(w,{align:`start`,side:u?`bottom`:`right`,sideOffset:4,className:`min-w-56 rounded-lg`,children:/* @__PURE__ */ (0,Y.jsxs)(x,{children:[i?/* @__PURE__ */ (0,Y.jsx)(C,{children:i}):null,p.map(e=>{let t=e.value===n;return e.href?/* @__PURE__ */ (0,Y.jsxs)(v,{className:`gap-2`,render:/* @__PURE__ */ (0,Y.jsx)(`a`,{href:e.href,"aria-current":t?`page`:void 0,onClick:t=>{H(t)&&(s?.(e.value,t),u&&f(!1))}}),children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:d(`truncate`,o&&`font-mono`),children:e.label}),t?/* @__PURE__ */ (0,Y.jsx)(l,{className:`ml-auto`}):null]},e.value):/* @__PURE__ */ (0,Y.jsxs)(v,{className:`gap-2`,onClick:t=>{s?.(e.value,t),u&&f(!1)},children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:d(`truncate`,o&&`font-mono`),children:e.label}),t?/* @__PURE__ */ (0,Y.jsx)(l,{className:`ml-auto`}):null]},e.value)})]})})]})})})}function Ee(){(0,W.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=()=>{let t=Math.round(e.height*e.scale*100)/100;document.documentElement.style.setProperty(`--app-height`,`${String(t)}px`),e.scale<=1&&window.scrollTo(0,0)};return e.addEventListener(`resize`,t),window.addEventListener(`pageshow`,t),document.addEventListener(`visibilitychange`,t),()=>{e.removeEventListener(`resize`,t),window.removeEventListener(`pageshow`,t),document.removeEventListener(`visibilitychange`,t)}},[])}function De(){let{state:e,toggleSidebar:t}=B(),n=e===`collapsed`;return/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(L,{type:`button`,size:`sm`,className:`text-sidebar-foreground/70`,tooltip:n?`Expand sidebar`:`Collapse sidebar`,onClick:t,children:[/* @__PURE__ */ (0,Y.jsx)(o,{className:n?`rotate-180`:void 0}),/* @__PURE__ */ (0,Y.jsx)(`span`,{children:`Collapse sidebar`})]})})})}function Oe({name:e,mind:t,actions:n}){let{isMobile:r,state:a}=B(),o=a===`collapsed`&&!r,l=(0,W.useRef)(null),u=e.slice(0,2).toUpperCase(),d=o||!!n;return/* @__PURE__ */ (0,Y.jsxs)(F,{children:[/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(T,{children:[/* @__PURE__ */ (0,Y.jsx)(b,{render:/* @__PURE__ */ (0,Y.jsxs)(L,{size:`lg`,className:`h-auto min-h-12 group-data-[collapsible=icon]:min-h-0 data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground`,"aria-label":`Account`,children:[/* @__PURE__ */ (0,Y.jsx)(h,{className:`size-8 rounded-lg`,children:/* @__PURE__ */ (0,Y.jsx)(m,{className:`rounded-lg`,children:u})}),/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left text-sm font-medium group-data-[collapsible=icon]:hidden`,children:e}),/* @__PURE__ */ (0,Y.jsx)(c,{className:`ml-auto`})]})}),/* @__PURE__ */ (0,Y.jsxs)(w,{className:`min-w-56 rounded-lg`,side:r?`bottom`:`right`,align:`end`,sideOffset:4,children:[d?/* @__PURE__ */ (0,Y.jsxs)(x,{children:[o?/* @__PURE__ */ (0,Y.jsx)(C,{className:`truncate font-normal`,children:e}):null,n]}):null,t?/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[d?/* @__PURE__ */ (0,Y.jsx)(E,{}):null,/* @__PURE__ */ (0,Y.jsx)(x,{children:/* @__PURE__ */ (0,Y.jsxs)(v,{onClick:()=>{U(),i().then(()=>l.current?.requestSubmit())},children:[/* @__PURE__ */ (0,Y.jsx)(s,{}),/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate`,children:`Sign out`})]})})]}):null]})]})}),t?/* @__PURE__ */ (0,Y.jsx)(`form`,{ref:l,method:`post`,action:`/.auth/logout?${new URLSearchParams({mind:t})}`,hidden:!0}):null]})}export{Te as a,Se as i,Z as n,$ as o,Q as r,xe as s,ge as t}; +import{r as e}from"./rolldown-runtime.mjs";import{a as t,i as n,n as r}from"./vendor-react";import{wipeSavedLogTails as i}from"../lib/saved-log-tail";import{C as a,Dt as o,Et as s,Mt as c,mt as l,q as u}from"./vendor-icons";import{c as d,i as f}from"./ui-base";import{I as p,J as m,K as h,N as g,P as _,a as v,g as y,h as b,i as x,j as S,o as C,r as w,t as T,u as E,z as D}from"./ui-shell";import{t as O}from"./iterate-logo.mjs";import{i as ee,l as te,o as ne,r as k,s as A,t as j,u as M}from"./command.mjs";import{C as N,b as P,c as re,d as F,h as I,m as L,n as ie,r as ae,t as R,u as z,w as B,x as V}from"./sidebar.mjs";import{plainLeftClick as H}from"../lib/plain-left-click";import{resetPosthog as U}from"../components/posthog";var W=/* @__PURE__ */ e(t(),1),G=/* @__PURE__ */ e(n(),1);function K(e,t){let n=t.trim().toLowerCase(),r=n.split(/\s+/).filter(Boolean),i=e.filter(e=>{let t=`${e.label} ${e.detail||``}`.toLowerCase();return r.every(e=>t.includes(e))}),a=/* @__PURE__ */ new Map;for(let e of i)a.set(e.group,[...a.get(e.group)||[],e]);return[...a].map(([e,t])=>({group:e,entries:n?[...t.filter(e=>e.label.toLowerCase().startsWith(n)),...t.filter(e=>!e.label.toLowerCase().startsWith(n))]:t}))}function q(e){return!e||e.closest(`[data-mobile]`)?[]:[...e.querySelectorAll(`[data-slot="sidebar-menu-button"], [data-slot="sidebar-menu-sub-button"]`)].flatMap(e=>{if(e.matches(`:disabled, [aria-disabled="true"]`))return[];let[t,...n]=J(e),r=t||e.getAttribute(`aria-label`)?.trim();if(!r)return[];let i=e.closest(`[data-slot="sidebar-group"]`),a=e.dataset.slot===`sidebar-menu-sub-button`?e.closest(`[data-slot="sidebar-menu-sub"]`)?.closest(`[data-slot="sidebar-menu-item"]`)?.querySelector(`[data-slot="sidebar-menu-button"]`):null;return[{element:e,label:r,group:J(i?.querySelector(`[data-slot="sidebar-group-label"]`))[0]||`Pages`,detail:J(a)[0]||n.join(` · `)||void 0,active:e.hasAttribute(`data-active`),href:e instanceof HTMLAnchorElement?e.href:void 0}]})}function J(e){if(!e)return[];let t=/* @__PURE__ */ new Map,n=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT);for(let r=n.nextNode();r;r=n.nextNode()){let n=r.parentNode||e;t.set(n,`${t.get(n)||``}${r.nodeValue||``}`)}return[...t.values()].map(e=>e.replace(/\s+/g,` `).trim()).filter(Boolean)}var Y=/* @__PURE__ */ e(r(),1);const oe=()=>()=>{};function se(){return(0,W.useSyncExternalStore)(oe,()=>/Mac|iPhone|iPad/.test(navigator.platform)?`⌘K`:`Ctrl K`,()=>`⌘K`)}function ce(e){(0,W.useEffect)(()=>{if(!e)return;function t(t){t.defaultPrevented||t.altKey||t.shiftKey||(t.metaKey||t.ctrlKey)&&t.key.toLowerCase()===`k`&&(t.preventDefault(),e?.())}return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e])}function le({onOpen:e}){let t=se();return/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(L,{type:`button`,tooltip:`Search (${t})`,onClick:e,children:[/* @__PURE__ */ (0,Y.jsx)(a,{}),/* @__PURE__ */ (0,Y.jsx)(`span`,{children:`Search`}),/* @__PURE__ */ (0,Y.jsx)(`kbd`,{className:`ml-auto font-sans text-xs text-muted-foreground`,children:t})]})})})}function ue({onOpen:e}){return/* @__PURE__ */ (0,Y.jsx)(f,{variant:`ghost`,size:`icon-sm`,className:`md:hidden`,"aria-label":`Search`,title:`Search`,onClick:e,children:/* @__PURE__ */ (0,Y.jsx)(a,{})})}function de({nav:e,entries:t,onClose:n}){return/* @__PURE__ */ (0,Y.jsx)(S,{open:!!e,onOpenChange:e=>{e||n()},children:/* @__PURE__ */ (0,Y.jsxs)(g,{showCloseButton:!1,className:`top-[12svh] translate-y-0 overflow-hidden p-0 sm:max-w-lg`,children:[/* @__PURE__ */ (0,Y.jsxs)(p,{className:`sr-only`,children:[/* @__PURE__ */ (0,Y.jsx)(D,{children:`Search`}),/* @__PURE__ */ (0,Y.jsx)(_,{children:`Go to a page`})]}),e?/* @__PURE__ */ (0,Y.jsx)(fe,{nav:e,entries:t,onClose:n}):null]})})}function fe({nav:e,entries:t,onClose:n}){let[r,i]=(0,W.useState)(``),o=e.map(({element:e,label:t,group:n,detail:r,active:i},a)=>({kind:`nav`,id:`nav:${a}`,label:t,group:n,detail:r,active:i,element:e})),s=t.map((e,t)=>({kind:`app`,id:`app:${t}`,...e})),c=K([...o,...s],r);return/* @__PURE__ */ (0,Y.jsxs)(j,{shouldFilter:!1,loop:!0,className:`p-0`,children:[/* @__PURE__ */ (0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[/* @__PURE__ */ (0,Y.jsx)(a,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":!0}),/* @__PURE__ */ (0,Y.jsx)(M.Input,{"data-slot":`command-input`,className:`flex h-8 w-full min-w-0 bg-transparent text-sm outline-hidden placeholder:text-muted-foreground`,placeholder:`Search…`,"aria-label":`Search`,value:r,onValueChange:i})]}),/* @__PURE__ */ (0,Y.jsxs)(A,{className:`max-h-[min(24rem,60svh)] border-t`,children:[/* @__PURE__ */ (0,Y.jsx)(k,{className:`text-muted-foreground`,children:`Nothing matches.`}),c.map(({group:e,entries:t})=>/* @__PURE__ */ (0,Y.jsx)(ee,{heading:e,className:`p-0 **:[[cmdk-group-heading]]:px-3 **:[[cmdk-group-heading]]:py-2`,children:t.map(e=>/* @__PURE__ */ (0,Y.jsx)(ne,{value:e.id,className:`rounded-none px-3 py-2 in-data-[slot=dialog-content]:rounded-none!`,onSelect:()=>{n(),e.kind===`app`?e.onSelect():e.element.click()},children:/* @__PURE__ */ (0,Y.jsx)(pe,{row:e})},e.id))},e))]})]})}function pe({row:e}){return/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate`,children:e.label}),e.detail?/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.detail}):null,e.active?/* @__PURE__ */ (0,Y.jsx)(te,{children:/* @__PURE__ */ (0,Y.jsx)(c,{"aria-label":`current`})}):null]})}const me=()=>()=>{};function he(){let e=document.cookie.split(`; `);if(e.includes(`sidebar_state=false`))return!1;if(e.includes(`sidebar_state=true`))return!0}function ge({app:e,mind:t,switcher:n,nav:r,paletteEntries:i,palette:a,commandPalette:o=!0,searchRow:s=!0,header:c,sidebarDefaultOpen:l=!0,phoneHeader:u=`row`,account:d,accountActions:f,sidebarAlert:p=!1,locationKey:m,children:h}){let g=(0,W.useSyncExternalStore)(me,()=>he()??l,()=>l),_=u===`floating`,v=(0,W.useRef)(null),[y,b]=(0,W.useState)(null),x=(0,W.useCallback)(()=>b(q(v.current)),[]),S=(0,W.useCallback)(()=>b(null),[]),[C,w]=(0,W.useState)(null),[T,E]=(0,W.useState)(null),D=(0,W.useCallback)(()=>b(e=>e?null:q(v.current)),[]);ce(o?D:null),Ee();let O=(0,W.useMemo)(()=>({header:C,menu:T,openPalette:o?x:void 0,appHeader:c}),[C,T,o,x,c]);return/* @__PURE__ */ (0,Y.jsxs)(P,{defaultOpen:g,className:`h-(--app-height,100svh) min-h-0`,children:[/* @__PURE__ */ (0,Y.jsx)(Ce,{locationKey:m}),/* @__PURE__ */ (0,Y.jsxs)(R,{collapsible:`icon`,children:[/* @__PURE__ */ (0,Y.jsxs)(re,{children:[n??/* @__PURE__ */ (0,Y.jsx)(Z,{app:e,line:t}),o&&s?/* @__PURE__ */ (0,Y.jsx)(le,{onOpen:x}):null]}),/* @__PURE__ */ (0,Y.jsx)(we,{navRef:v,children:r}),/* @__PURE__ */ (0,Y.jsxs)(ae,{children:[/* @__PURE__ */ (0,Y.jsx)(De,{}),d===!1?null:d===void 0?/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsx)($,{className:`h-12 group-data-[collapsible=icon]:h-8`})})}):/* @__PURE__ */ (0,Y.jsx)(Oe,{name:d?.email||d?.actor||t||e,mind:t,actions:f})]}),/* @__PURE__ */ (0,Y.jsx)(V,{})]}),/* @__PURE__ */ (0,Y.jsxs)(ve,{floatingHeader:_,locationKey:m,children:[/* @__PURE__ */ (0,Y.jsx)(_e,{header:c,floating:_,sidebarAlert:p,onOpenPalette:o?x:void 0,pageHeaderRef:w,pageMenuRef:E}),/* @__PURE__ */ (0,Y.jsx)(X,{value:O,children:/* @__PURE__ */ (0,Y.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-auto`,children:h})})]}),o?/* @__PURE__ */ (0,Y.jsx)(be,{appPalette:a,nav:y,entries:i||[],onClose:S}):null]})}function _e({header:e,floating:t,sidebarAlert:n,onOpenPalette:r,pageHeaderRef:i,pageMenuRef:a}){return/* @__PURE__ */ (0,Y.jsxs)(`header`,{className:d(`group/header flex shrink-0 items-center gap-3 px-4 pt-2.5 pb-1`,`has-[[data-page-header]]:border-b has-[[data-page-header]]:py-1.5`,!e&&`md:hidden md:has-[[data-page-header]]:flex`,t&&`max-md:pointer-events-none max-md:absolute max-md:inset-x-0 max-md:top-0 max-md:z-20 max-md:bg-linear-to-b max-md:from-background max-md:from-40% max-md:to-transparent max-md:*:pointer-events-auto max-md:motion-safe:transition-transform max-md:motion-safe:duration-200 max-md:group-data-[phone-header=hidden]/inset:not-focus-within:-translate-y-full`),children:[/* @__PURE__ */ (0,Y.jsxs)(`span`,{className:`relative -ml-1 inline-flex md:hidden`,children:[/* @__PURE__ */ (0,Y.jsx)(N,{title:n?`Toggle sidebar (requests wait for approval)`:`Toggle sidebar`,"aria-label":n?`Toggle sidebar (requests wait for approval)`:`Toggle sidebar`}),n?/* @__PURE__ */ (0,Y.jsx)(`span`,{"aria-hidden":`true`,"data-sidebar-alert":!0,className:`pointer-events-none absolute top-0.5 right-0.5 size-2 rounded-full bg-warning ring-2 ring-background`}):null]}),/* @__PURE__ */ (0,Y.jsxs)(`div`,{className:d(`flex min-w-0 items-center gap-3 max-md:group-has-[[data-page-menu]]/header:hidden`,!e&&`md:hidden`),children:[r?/* @__PURE__ */ (0,Y.jsx)(ue,{onOpen:r}):null,e]}),/* @__PURE__ */ (0,Y.jsx)(`div`,{ref:i,className:`flex min-w-0 flex-1 items-center empty:hidden`}),/* @__PURE__ */ (0,Y.jsx)(`div`,{ref:a,className:`ml-auto flex items-center empty:hidden md:hidden`})]})}function ve({floatingHeader:e,locationKey:t,children:n}){let[r,i]=(0,W.useState)(null),a=r!==t,o=(0,W.useRef)(null),s=(0,W.useRef)(0),c=(e,n,r)=>{e?ye(n,r)&&i(t):i(null)};return/* @__PURE__ */ (0,Y.jsx)(z,{className:`group/inset min-w-0 overflow-hidden`,"data-phone-header":e?a?`shown`:`hidden`:void 0,...e&&{onTouchStartCapture:e=>{let t=e.touches[0];o.current=t?{x:t.clientX,y:t.clientY}:null},onTouchMoveCapture:e=>{let t=e.touches[0],n=o.current;if(!t||!n)return;let r=t.clientY-n.y;Math.abs(r)<16||Math.abs(r)<Math.abs(t.clientX-n.x)||(o.current={x:t.clientX,y:t.clientY},c(r<0,e.target,e.currentTarget))},onWheelCapture:e=>{let t=Math.sign(e.deltaY)===Math.sign(s.current)?s.current+e.deltaY:e.deltaY;s.current=Math.abs(t)<16?t:0,Math.abs(t)>=16&&c(t>0,e.target,e.currentTarget)}},children:n})}function ye(e,t){for(let n=e instanceof Element?e:null;n&&n!==t;n=n.parentElement){let{overflowY:e}=getComputedStyle(n);if((e===`auto`||e===`scroll`)&&n.scrollHeight-n.clientHeight-n.scrollTop>1)return!0}return!1}function be({appPalette:e,...t}){return e?e({open:!!t.nav,onClose:t.onClose}):/* @__PURE__ */ (0,Y.jsx)(de,{...t})}const X=(0,W.createContext)(null);function xe(){return!!(0,W.useContext)(X)}function Z({app:e,line:t,logo:n,href:r,onClick:i}){let{isMobile:a,setOpenMobile:o}=B(),s=/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`flex aspect-square size-8 items-center justify-center rounded-md bg-black`,children:n??/* @__PURE__ */ (0,Y.jsx)(O,{alt:``,className:`size-6`})}),/* @__PURE__ */ (0,Y.jsxs)(`span`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e}),t?/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:t}):null]})]});return/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:r?/* @__PURE__ */ (0,Y.jsx)(L,{size:`lg`,tooltip:e,render:/* @__PURE__ */ (0,Y.jsx)(`a`,{href:r,onClick:e=>{let t=a&&H(e);i?.(e),t&&o(!1)}}),children:s}):/* @__PURE__ */ (0,Y.jsx)(L,{size:`lg`,className:`pointer-events-none`,children:s})})})}function Q({children:e}){let t=(0,W.useContext)(X);if(!t)throw Error(`AppShellPageHeader is drawn inside an AppShell`);return t.header?(0,G.createPortal)(/* @__PURE__ */ (0,Y.jsx)(`div`,{"data-page-header":!0,className:`flex min-w-0 flex-1 items-center gap-x-4 gap-y-1 md:flex-wrap`,children:e}),t.header):null}function Se({children:e}){let t=(0,W.useContext)(X);if(!t)throw Error(`AppShellPageMenu is drawn inside an AppShell`);return t.menu?(0,G.createPortal)(/* @__PURE__ */ (0,Y.jsxs)(T,{children:[/* @__PURE__ */ (0,Y.jsx)(b,{"data-page-menu":!0,render:/* @__PURE__ */ (0,Y.jsx)(f,{variant:`ghost`,size:`icon-sm`,className:`md:hidden`,"aria-label":`More`,title:`More`}),children:/* @__PURE__ */ (0,Y.jsx)(l,{})}),/* @__PURE__ */ (0,Y.jsxs)(w,{align:`end`,className:`min-w-56 rounded-lg`,children:[t.appHeader?/* @__PURE__ */ (0,Y.jsx)(`div`,{className:`px-1.5 py-1`,children:t.appHeader}):null,t.openPalette?/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[/* @__PURE__ */ (0,Y.jsx)(x,{children:/* @__PURE__ */ (0,Y.jsxs)(v,{onClick:t.openPalette,children:[/* @__PURE__ */ (0,Y.jsx)(a,{}),`Search`]})}),/* @__PURE__ */ (0,Y.jsx)(E,{})]}):null,e]})]}),t.menu):null}function $({className:e}){return/* @__PURE__ */ (0,Y.jsxs)(`div`,{className:d(`flex h-8 items-center gap-2 px-2`,e),children:[/* @__PURE__ */ (0,Y.jsx)(y,{className:`size-4 rounded-md`}),/* @__PURE__ */ (0,Y.jsx)(y,{className:`h-4 w-2/3`})]})}function Ce({locationKey:e}){let{setOpenMobile:t}=B(),n=(0,W.useRef)(e);return(0,W.useEffect)(()=>{n.current!==e&&(n.current=e,t(!1))},[e,t]),null}function we({navRef:e,children:t}){let{isMobile:n,setOpenMobile:r}=B();return/* @__PURE__ */ (0,Y.jsx)(ie,{ref:e,onClick:e=>{if(!n||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target instanceof Element?e.target.closest(`a[href]`):null;if(!t||!e.currentTarget.contains(t)||t.hasAttribute(`download`))return;let i=t.getAttribute(`target`);i&&i!==`_self`||r(!1)},children:t})}function Te({app:e,logo:t,value:n,items:r,label:i,href:a,mono:o=!1,onSelect:l}){let{isMobile:u,setOpenMobile:f}=B(),p=r.map(e=>typeof e==`string`?{value:e,label:e,href:void 0}:{value:e.value,label:e.label||e.value,href:e.href}),m=p.find(e=>e.value===n)?.label||n;return p.length<=1?/* @__PURE__ */ (0,Y.jsx)(Z,{app:e,line:o?/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`font-mono`,children:m}):m,logo:t,href:a}):/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(T,{children:[/* @__PURE__ */ (0,Y.jsx)(b,{render:/* @__PURE__ */ (0,Y.jsxs)(L,{size:`lg`,className:`data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground`,"aria-label":i?`${i}: ${m}`:`Switch ${e}`,children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`flex aspect-square size-8 items-center justify-center rounded-md bg-black`,children:t??/* @__PURE__ */ (0,Y.jsx)(O,{alt:``,className:`size-6`})}),/* @__PURE__ */ (0,Y.jsxs)(`span`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e}),/* @__PURE__ */ (0,Y.jsx)(`span`,{className:d(`truncate text-xs text-muted-foreground`,o&&`font-mono`),children:m})]}),/* @__PURE__ */ (0,Y.jsx)(s,{className:`ml-auto`})]})}),/* @__PURE__ */ (0,Y.jsx)(w,{align:`start`,side:u?`bottom`:`right`,sideOffset:4,className:`min-w-56 rounded-lg`,children:/* @__PURE__ */ (0,Y.jsxs)(x,{children:[i?/* @__PURE__ */ (0,Y.jsx)(C,{children:i}):null,p.map(e=>{let t=e.value===n;return e.href?/* @__PURE__ */ (0,Y.jsxs)(v,{className:`gap-2`,render:/* @__PURE__ */ (0,Y.jsx)(`a`,{href:e.href,"aria-current":t?`page`:void 0,onClick:t=>{H(t)&&(l?.(e.value,t),u&&f(!1))}}),children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:d(`truncate`,o&&`font-mono`),children:e.label}),t?/* @__PURE__ */ (0,Y.jsx)(c,{className:`ml-auto`}):null]},e.value):/* @__PURE__ */ (0,Y.jsxs)(v,{className:`gap-2`,onClick:t=>{l?.(e.value,t),u&&f(!1)},children:[/* @__PURE__ */ (0,Y.jsx)(`span`,{className:d(`truncate`,o&&`font-mono`),children:e.label}),t?/* @__PURE__ */ (0,Y.jsx)(c,{className:`ml-auto`}):null]},e.value)})]})})]})})})}function Ee(){(0,W.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=()=>{let t=Math.round(e.height*e.scale*100)/100;document.documentElement.style.setProperty(`--app-height`,`${String(t)}px`),e.scale<=1&&window.scrollTo(0,0)};return e.addEventListener(`resize`,t),window.addEventListener(`pageshow`,t),document.addEventListener(`visibilitychange`,t),()=>{e.removeEventListener(`resize`,t),window.removeEventListener(`pageshow`,t),document.removeEventListener(`visibilitychange`,t)}},[])}function De(){let{state:e,toggleSidebar:t}=B(),n=e===`collapsed`;return/* @__PURE__ */ (0,Y.jsx)(F,{children:/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(L,{type:`button`,size:`sm`,className:`text-sidebar-foreground/70`,tooltip:n?`Expand sidebar`:`Collapse sidebar`,onClick:t,children:[/* @__PURE__ */ (0,Y.jsx)(o,{className:n?`rotate-180`:void 0}),/* @__PURE__ */ (0,Y.jsx)(`span`,{children:`Collapse sidebar`})]})})})}function Oe({name:e,mind:t,actions:n}){let{isMobile:r,state:a}=B(),o=a===`collapsed`&&!r,c=(0,W.useRef)(null),l=e.slice(0,2).toUpperCase(),d=o||!!n;return/* @__PURE__ */ (0,Y.jsxs)(F,{children:[/* @__PURE__ */ (0,Y.jsx)(I,{children:/* @__PURE__ */ (0,Y.jsxs)(T,{children:[/* @__PURE__ */ (0,Y.jsx)(b,{render:/* @__PURE__ */ (0,Y.jsxs)(L,{size:`lg`,className:`h-auto min-h-12 group-data-[collapsible=icon]:min-h-0 data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground`,"aria-label":`Account`,children:[/* @__PURE__ */ (0,Y.jsx)(h,{className:`size-8 rounded-lg`,children:/* @__PURE__ */ (0,Y.jsx)(m,{className:`rounded-lg`,children:l})}),/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-left text-sm font-medium group-data-[collapsible=icon]:hidden`,children:e}),/* @__PURE__ */ (0,Y.jsx)(s,{className:`ml-auto`})]})}),/* @__PURE__ */ (0,Y.jsxs)(w,{className:`min-w-56 rounded-lg`,side:r?`bottom`:`right`,align:`end`,sideOffset:4,children:[d?/* @__PURE__ */ (0,Y.jsxs)(x,{children:[o?/* @__PURE__ */ (0,Y.jsx)(C,{className:`truncate font-normal`,children:e}):null,n]}):null,t?/* @__PURE__ */ (0,Y.jsxs)(Y.Fragment,{children:[d?/* @__PURE__ */ (0,Y.jsx)(E,{}):null,/* @__PURE__ */ (0,Y.jsx)(x,{children:/* @__PURE__ */ (0,Y.jsxs)(v,{onClick:()=>{U(),i().then(()=>c.current?.requestSubmit())},children:[/* @__PURE__ */ (0,Y.jsx)(u,{}),/* @__PURE__ */ (0,Y.jsx)(`span`,{className:`truncate`,children:`Sign out`})]})})]}):null]})]})}),t?/* @__PURE__ */ (0,Y.jsx)(`form`,{ref:c,method:`post`,action:`/.auth/logout?${new URLSearchParams({mind:t})}`,hidden:!0}):null]})}export{Te as a,Se as i,Z as n,$ as o,Q as r,xe as s,ge as t};
M dist/chunks/code-block.client.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{gt as r,jt as i}from"./vendor-icons";import{c as a}from"./ui-base";import{H as o,V as s,W as c}from"./ui-shell";import{n as l}from"./dist2.mjs";import{n as u}from"./vendor-yaml";import{Ot as d,St as f,X as p,ft as m,i as h,lt as g,pt as _,s as v,t as y,ut as b}from"./vendor-codemirror";import{n as x,t as S}from"./vendor-codemirror-themes";import{systemCodeMirrorTheme as C}from"../lib/codemirror-theme";var w=/* @__PURE__ */ e(t(),1),T=/* @__PURE__ */ e(n(),1);function E({code:e,language:t,className:n,showLineNumbers:r=!0,toolbar:i=/* @__PURE__ */ (0,T.jsx)(k,{label:`Copy code`,text:()=>e})}){let o=(0,w.useMemo)(()=>[y,C({Compartment:d,ViewPlugin:_,vsCodeLight:S,vsCodeDark:x}),g({top:!0}),M(),t,f.of(b),m.editable.of(!1),m.contentAttributes.of({tabindex:`0`}),m.lineWrapping,r?[]:m.theme({".cm-gutters":{display:`none`}})],[t,r]);return/* @__PURE__ */ (0,T.jsxs)(`div`,{className:a(`relative flex min-h-0 flex-col`,n),children:[/* @__PURE__ */ (0,T.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden overflow-y-auto rounded border`,children:/* @__PURE__ */ (0,T.jsx)(O,{value:e,extensions:o})}),/* @__PURE__ */ (0,T.jsx)(`div`,{className:`absolute top-1 right-1 flex items-center gap-0.5 rounded bg-background px-1 py-0.5 text-xs opacity-40 transition-opacity hover:opacity-90`,children:i})]})}function D({data:e,className:t,showToggle:n=!0,initialFormat:r=`yaml`}){let[i,a]=(0,w.useState)(r),o=(0,w.useMemo)(()=>j(e,i),[e,i]);return/* @__PURE__ */ (0,T.jsx)(E,{code:o,language:A[i],className:t,toolbar:/* @__PURE__ */ (0,T.jsxs)(T.Fragment,{children:[n?/* @__PURE__ */ (0,T.jsx)(`button`,{type:`button`,onClick:()=>a(e=>e===`yaml`?`json`:`yaml`),className:`rounded px-1.5 py-0.5 text-xs font-medium hover:bg-muted`,children:i===`yaml`?`YAML`:`JSON`}):null,/* @__PURE__ */ (0,T.jsx)(k,{label:`Copy YAML`,text:()=>j(e,`yaml`)}),/* @__PURE__ */ (0,T.jsx)(k,{label:`Copy JSON`,text:()=>j(e,`json`)})]})})}function O({value:e,extensions:t}){let n=(0,w.useRef)(null),r=(0,w.useRef)(null),i=(0,w.useRef)(e);return(0,w.useEffect)(()=>{i.current=e},[e]),(0,w.useEffect)(()=>{if(!n.current)return;let e=new m({doc:i.current,extensions:t,parent:n.current});return r.current=e,()=>{e.destroy(),r.current=null}},[t]),(0,w.useEffect)(()=>{let t=r.current;t&&t.state.doc.toString()!==e&&t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}})},[e]),/* @__PURE__ */ (0,T.jsx)(`div`,{ref:n})}function k({label:e,text:t}){let[n,a]=(0,w.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(t()),a(!0),window.setTimeout(()=>a(!1),2e3),l.success(`Copied to clipboard`)}catch{l.error(`Failed to copy`)}};return/* @__PURE__ */ (0,T.jsxs)(s,{children:[/* @__PURE__ */ (0,T.jsx)(c,{render:/* @__PURE__ */ (0,T.jsx)(`button`,{type:`button`,onClick:()=>void u(),className:`flex h-3 w-3 items-center justify-center rounded`}),children:n?/* @__PURE__ */ (0,T.jsx)(i,{className:`h-2 w-2 text-success`}):/* @__PURE__ */ (0,T.jsx)(r,{className:`h-2 w-2`})}),/* @__PURE__ */ (0,T.jsx)(o,{children:/* @__PURE__ */ (0,T.jsx)(`p`,{children:e})})]})}const A={yaml:[h(),N()],json:[v(),N()]};function j(e,t){try{return e===void 0?t===`yaml`?`undefined`:`"undefined"`:e===null?`null`:t===`yaml`?u(e):JSON.stringify(e,null,2)}catch(e){return t===`yaml`?`# Error serializing data\n# ${e instanceof Error?e.message:`Unknown error`}`:JSON.stringify({error:`Failed to serialize data`,message:e instanceof Error?e.message:`Unknown error`},null,2)}}function M(){return p.of((e,t,n)=>{let r=e.doc.lineAt(t);if(r.text.match(/^\s*<\S+>$/)){let t=r.text.replace(`<`,`</`);for(let i=r.number+1;i<=e.doc.lines;i++){let r=e.doc.line(i);if(r.text===t)return P(n,r)}}if(r.text.match(/^\s*```\w*\s*$/)){let t=r.text.slice(0,r.text.lastIndexOf("`")+1);for(let i=r.number+1;i<=e.doc.lines;i++){let r=e.doc.line(i);if(r.text===t)return P(n,r)}}let i=/^\s*#+ \w/;if(i.test(r.text)){let t=r.text.match(/^\s*/)?.[0]||``;for(let a=r.number+1;a<=e.doc.lines;a++){let{text:r}=e.doc.line(a),o=r.trim()&&!r.startsWith(t);if(i.test(r)||o||a===e.doc.lines)return{from:n,to:e.doc.line(a-1).from-1}}}return null})}function N(){return p.of((e,t,n)=>{let r=e.doc.lineAt(t);if(r.text.endsWith(`/**`))for(let t=r.number+1;t<=e.doc.lines;t++){let r=e.doc.line(t);if(r.text.includes(`*/`))return P(n,r)}for(let t of[`{}`,`[]`])if(r.text.trimEnd().endsWith(t[0])){let i=r.text.match(/^\s*/)?.[0]||``;for(let a=r.number+1;a<=e.doc.lines;a++){let r=e.doc.line(a);if(r.text===i+t[1])return P(n,r)}}return null})}function P(e,t){return{from:e,to:t.from+t.text.split(/\S/)[0].length}}export{E as CodeBlock,D as SerializedObjectCodeBlock}; +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{Mt as r,_t as i}from"./vendor-icons";import{c as a}from"./ui-base";import{H as o,V as s,W as c}from"./ui-shell";import{n as l}from"./dist2.mjs";import{n as u}from"./vendor-yaml";import{Ot as d,St as f,X as p,ft as m,i as h,lt as g,pt as _,s as v,t as y,ut as b}from"./vendor-codemirror";import{n as x,t as S}from"./vendor-codemirror-themes";import{systemCodeMirrorTheme as C}from"../lib/codemirror-theme";var w=/* @__PURE__ */ e(t(),1),T=/* @__PURE__ */ e(n(),1);function E({code:e,language:t,className:n,showLineNumbers:r=!0,toolbar:i=/* @__PURE__ */ (0,T.jsx)(k,{label:`Copy code`,text:()=>e})}){let o=(0,w.useMemo)(()=>[y,C({Compartment:d,ViewPlugin:_,vsCodeLight:S,vsCodeDark:x}),g({top:!0}),M(),t,f.of(b),m.editable.of(!1),m.contentAttributes.of({tabindex:`0`}),m.lineWrapping,r?[]:m.theme({".cm-gutters":{display:`none`}})],[t,r]);return/* @__PURE__ */ (0,T.jsxs)(`div`,{className:a(`relative flex min-h-0 flex-col`,n),children:[/* @__PURE__ */ (0,T.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden overflow-y-auto rounded border`,children:/* @__PURE__ */ (0,T.jsx)(O,{value:e,extensions:o})}),/* @__PURE__ */ (0,T.jsx)(`div`,{className:`absolute top-1 right-1 flex items-center gap-0.5 rounded bg-background px-1 py-0.5 text-xs opacity-40 transition-opacity hover:opacity-90`,children:i})]})}function D({data:e,className:t,showToggle:n=!0,initialFormat:r=`yaml`}){let[i,a]=(0,w.useState)(r),o=(0,w.useMemo)(()=>j(e,i),[e,i]);return/* @__PURE__ */ (0,T.jsx)(E,{code:o,language:A[i],className:t,toolbar:/* @__PURE__ */ (0,T.jsxs)(T.Fragment,{children:[n?/* @__PURE__ */ (0,T.jsx)(`button`,{type:`button`,onClick:()=>a(e=>e===`yaml`?`json`:`yaml`),className:`rounded px-1.5 py-0.5 text-xs font-medium hover:bg-muted`,children:i===`yaml`?`YAML`:`JSON`}):null,/* @__PURE__ */ (0,T.jsx)(k,{label:`Copy YAML`,text:()=>j(e,`yaml`)}),/* @__PURE__ */ (0,T.jsx)(k,{label:`Copy JSON`,text:()=>j(e,`json`)})]})})}function O({value:e,extensions:t}){let n=(0,w.useRef)(null),r=(0,w.useRef)(null),i=(0,w.useRef)(e);return(0,w.useEffect)(()=>{i.current=e},[e]),(0,w.useEffect)(()=>{if(!n.current)return;let e=new m({doc:i.current,extensions:t,parent:n.current});return r.current=e,()=>{e.destroy(),r.current=null}},[t]),(0,w.useEffect)(()=>{let t=r.current;t&&t.state.doc.toString()!==e&&t.dispatch({changes:{from:0,to:t.state.doc.length,insert:e}})},[e]),/* @__PURE__ */ (0,T.jsx)(`div`,{ref:n})}function k({label:e,text:t}){let[n,a]=(0,w.useState)(!1),u=async()=>{try{await navigator.clipboard.writeText(t()),a(!0),window.setTimeout(()=>a(!1),2e3),l.success(`Copied to clipboard`)}catch{l.error(`Failed to copy`)}};return/* @__PURE__ */ (0,T.jsxs)(s,{children:[/* @__PURE__ */ (0,T.jsx)(c,{render:/* @__PURE__ */ (0,T.jsx)(`button`,{type:`button`,onClick:()=>void u(),className:`flex h-3 w-3 items-center justify-center rounded`}),children:n?/* @__PURE__ */ (0,T.jsx)(r,{className:`h-2 w-2 text-success`}):/* @__PURE__ */ (0,T.jsx)(i,{className:`h-2 w-2`})}),/* @__PURE__ */ (0,T.jsx)(o,{children:/* @__PURE__ */ (0,T.jsx)(`p`,{children:e})})]})}const A={yaml:[h(),N()],json:[v(),N()]};function j(e,t){try{return e===void 0?t===`yaml`?`undefined`:`"undefined"`:e===null?`null`:t===`yaml`?u(e):JSON.stringify(e,null,2)}catch(e){return t===`yaml`?`# Error serializing data\n# ${e instanceof Error?e.message:`Unknown error`}`:JSON.stringify({error:`Failed to serialize data`,message:e instanceof Error?e.message:`Unknown error`},null,2)}}function M(){return p.of((e,t,n)=>{let r=e.doc.lineAt(t);if(r.text.match(/^\s*<\S+>$/)){let t=r.text.replace(`<`,`</`);for(let i=r.number+1;i<=e.doc.lines;i++){let r=e.doc.line(i);if(r.text===t)return P(n,r)}}if(r.text.match(/^\s*```\w*\s*$/)){let t=r.text.slice(0,r.text.lastIndexOf("`")+1);for(let i=r.number+1;i<=e.doc.lines;i++){let r=e.doc.line(i);if(r.text===t)return P(n,r)}}let i=/^\s*#+ \w/;if(i.test(r.text)){let t=r.text.match(/^\s*/)?.[0]||``;for(let a=r.number+1;a<=e.doc.lines;a++){let{text:r}=e.doc.line(a),o=r.trim()&&!r.startsWith(t);if(i.test(r)||o||a===e.doc.lines)return{from:n,to:e.doc.line(a-1).from-1}}}return null})}function N(){return p.of((e,t,n)=>{let r=e.doc.lineAt(t);if(r.text.endsWith(`/**`))for(let t=r.number+1;t<=e.doc.lines;t++){let r=e.doc.line(t);if(r.text.includes(`*/`))return P(n,r)}for(let t of[`{}`,`[]`])if(r.text.trimEnd().endsWith(t[0])){let i=r.text.match(/^\s*/)?.[0]||``;for(let a=r.number+1;a<=e.doc.lines;a++){let r=e.doc.line(a);if(r.text===i+t[1])return P(n,r)}}return null})}function P(e,t){return{from:e,to:t.from+t.text.split(/\S/)[0].length}}export{E as CodeBlock,D as SerializedObjectCodeBlock};
M dist/chunks/command.mjs
@@ -1,4 +1,4 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,i as n,n as r}from"./vendor-react";import{C as i,jt as a}from"./vendor-icons";import{c as o}from"./ui-base";import{E as s,I as c,N as l,P as u,T as d,j as f,z as p}from"./ui-shell";var m=/* @__PURE__ */ e(t(),1),h=1,g=.9,_=.8,v=.17,y=.1,b=.999,ee=.9999,x=.99,S=/[\\\/_+.#"@\[\(\{&]/,C=/[\\\/_+.#"@\[\(\{&]/g,w=/[\s-]/,T=/[\s-]/g;function E(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?h:x;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=E(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=h:S.test(e.charAt(l-1))?(d*=_,p=e.slice(i,l-1).match(C),p&&i>0&&(d*=b**+p.length)):w.test(e.charAt(l-1))?(d*=g,m=e.slice(i,l-1).match(T),m&&i>0&&(d*=b**+m.length)):(d*=v,i>0&&(d*=b**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=ee)),(d<y&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=E(e,t,n,r,l+1,a+2,o),f*y>d&&(d=f*y)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function te(e){return e.toLowerCase().replace(T,` `)}function ne(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,E(e,t,te(e),te(t),0,0,{})}var re=Object.defineProperty,D=(e,t)=>re(e,`name`,{value:t,configurable:!0}),O=!!(typeof window<`u`&&window.document&&window.document.createElement);function k(e,t,{checkForDefaultPrevented:n=!0}={}){return/* @__PURE__ */ D(function(r){if(e?.(r),n===!1||!r||!r.defaultPrevented)return t?.(r)},`handleEvent`)}D(k,`composeEventHandlers`);function ie(e){if(!O)throw Error(`Cannot access window outside of the DOM`);return e?.ownerDocument?.defaultView??window}D(ie,`getOwnerWindow`);function ae(e){if(!O)throw Error(`Cannot access document outside of the DOM`);return e?.ownerDocument??document}D(ae,`getOwnerDocument`);function oe(e,t=!1){let{activeElement:n}=ae(e);if(!n?.nodeName)return null;if(se(n)&&n.contentDocument)return oe(n.contentDocument.body,t);if(t){let e=n.getAttribute(`aria-activedescendant`);if(e){let t=ae(n).getElementById(e);if(t)return t}}return n}D(oe,`getActiveElement`);function se(e){return e.tagName===`IFRAME`}D(se,`isFrame`);var ce=Object.defineProperty,le=(e,t)=>ce(e,`name`,{value:t,configurable:!0});function ue(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}le(ue,`setRef`);function A(...e){return t=>{let n=!1,r=e.map(e=>{let r=ue(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():ue(e[t],null)}}}}le(A,`composeRefs`);function j(...e){return m.useCallback(A(...e),e)}le(j,`useComposedRefs`);var M=/* @__PURE__ */ e(r(),1),de=Object.defineProperty,N=(e,t)=>de(e,`name`,{value:t,configurable:!0});// @__NO_SIDE_EFFECTS__ +import{r as e}from"./rolldown-runtime.mjs";import{a as t,i as n,n as r}from"./vendor-react";import{C as i,Mt as a}from"./vendor-icons";import{c as o}from"./ui-base";import{E as s,I as c,N as l,P as u,T as d,j as f,z as p}from"./ui-shell";var m=/* @__PURE__ */ e(t(),1),h=1,g=.9,_=.8,v=.17,y=.1,b=.999,ee=.9999,x=.99,S=/[\\\/_+.#"@\[\(\{&]/,C=/[\\\/_+.#"@\[\(\{&]/g,w=/[\s-]/,T=/[\s-]/g;function E(e,t,n,r,i,a,o){if(a===t.length)return i===e.length?h:x;var s=`${i},${a}`;if(o[s]!==void 0)return o[s];for(var c=r.charAt(a),l=n.indexOf(c,i),u=0,d,f,p,m;l>=0;)d=E(e,t,n,r,l+1,a+1,o),d>u&&(l===i?d*=h:S.test(e.charAt(l-1))?(d*=_,p=e.slice(i,l-1).match(C),p&&i>0&&(d*=b**+p.length)):w.test(e.charAt(l-1))?(d*=g,m=e.slice(i,l-1).match(T),m&&i>0&&(d*=b**+m.length)):(d*=v,i>0&&(d*=b**+(l-i))),e.charAt(l)!==t.charAt(a)&&(d*=ee)),(d<y&&n.charAt(l-1)===r.charAt(a+1)||r.charAt(a+1)===r.charAt(a)&&n.charAt(l-1)!==r.charAt(a))&&(f=E(e,t,n,r,l+1,a+2,o),f*y>d&&(d=f*y)),d>u&&(u=d),l=n.indexOf(c,l+1);return o[s]=u,u}function te(e){return e.toLowerCase().replace(T,` `)}function ne(e,t,n){return e=n&&n.length>0?`${e+` `+n.join(` `)}`:e,E(e,t,te(e),te(t),0,0,{})}var re=Object.defineProperty,D=(e,t)=>re(e,`name`,{value:t,configurable:!0}),O=!!(typeof window<`u`&&window.document&&window.document.createElement);function k(e,t,{checkForDefaultPrevented:n=!0}={}){return/* @__PURE__ */ D(function(r){if(e?.(r),n===!1||!r||!r.defaultPrevented)return t?.(r)},`handleEvent`)}D(k,`composeEventHandlers`);function ie(e){if(!O)throw Error(`Cannot access window outside of the DOM`);return e?.ownerDocument?.defaultView??window}D(ie,`getOwnerWindow`);function ae(e){if(!O)throw Error(`Cannot access document outside of the DOM`);return e?.ownerDocument??document}D(ae,`getOwnerDocument`);function oe(e,t=!1){let{activeElement:n}=ae(e);if(!n?.nodeName)return null;if(se(n)&&n.contentDocument)return oe(n.contentDocument.body,t);if(t){let e=n.getAttribute(`aria-activedescendant`);if(e){let t=ae(n).getElementById(e);if(t)return t}}return n}D(oe,`getActiveElement`);function se(e){return e.tagName===`IFRAME`}D(se,`isFrame`);var ce=Object.defineProperty,le=(e,t)=>ce(e,`name`,{value:t,configurable:!0});function ue(e,t){if(typeof e==`function`)return e(t);e!=null&&(e.current=t)}le(ue,`setRef`);function A(...e){return t=>{let n=!1,r=e.map(e=>{let r=ue(e,t);return!n&&typeof r==`function`&&(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];typeof n==`function`?n():ue(e[t],null)}}}}le(A,`composeRefs`);function j(...e){return m.useCallback(A(...e),e)}le(j,`useComposedRefs`);var M=/* @__PURE__ */ e(r(),1),de=Object.defineProperty,N=(e,t)=>de(e,`name`,{value:t,configurable:!0});// @__NO_SIDE_EFFECTS__ function fe(e,t){let n=m.createContext(t);n.displayName=e+`Context`;let r=/* @__PURE__ */ N(e=>{let{children:t,...r}=e,i=m.useMemo(()=>r,Object.values(r));return/* @__PURE__ */ (0,M.jsx)(n.Provider,{value:i,children:t})},`Provider`);r.displayName=e+`Provider`;function i(r,i={}){let{optional:a=!1}=i,o=m.useContext(n);if(o)return o;if(t!==void 0)return t;if(!a)throw Error(`\`${r}\` must be used within \`${e}\``)}return N(i,`useContext`),[r,i]}N(fe,`createContext`);// @__NO_SIDE_EFFECTS__ function pe(e,t=[]){let n=[];function r(t,r){let i=m.createContext(r);i.displayName=t+`Context`;let a=n.length;n=[...n,r];let o=/* @__PURE__ */ N(t=>{let{scope:n,children:r,...o}=t,s=n?.[e]?.[a]||i,c=m.useMemo(()=>o,Object.values(o));return/* @__PURE__ */ (0,M.jsx)(s.Provider,{value:c,children:r})},`Provider`);o.displayName=t+`Provider`;function s(n,o,s={}){let{optional:c=!1}=s,l=o?.[e]?.[a]||i,u=m.useContext(l);if(u)return u;if(r!==void 0)return r;if(!c)throw Error(`\`${n}\` must be used within \`${t}\``)}return N(s,`useContext`),[o,s]}N(r,`createContext`);let i=/* @__PURE__ */ N(()=>{let t=n.map(e=>m.createContext(e));return/* @__PURE__ */ N(function(n){let r=n?.[e]||t;return m.useMemo(()=>({[`__scope${e}`]:{...n,[e]:r}}),[n,r])},`useScope`)},`createScope`);return i.scopeName=e,[r,me(i,...t)]}N(pe,`createContextScope`);function me(...e){let t=e[0];if(e.length===1)return t;let n=/* @__PURE__ */ N(()=>{let n=e.map(e=>({useScope:e(),scopeName:e.scopeName}));return/* @__PURE__ */ N(function(e){let r=n.reduce((t,{useScope:n,scopeName:r})=>{let i=n(e)[`__scope${r}`];return{...t,...i}},{});return m.useMemo(()=>({[`__scope${t.scopeName}`]:r}),[r])},`useComposedScopes`)},`createScope`);return n.scopeName=t.scopeName,n}N(me,`composeContextScopes`);var P=globalThis?.document?m.useLayoutEffect:()=>{},he=Object.defineProperty,ge=(e,t)=>he(e,`name`,{value:t,configurable:!0}),_e=m.useId||(()=>void 0),ve=0;function F(e){let[t,n]=m.useState(_e());return P(()=>{e||n(e=>e??String(ve++))},[e]),e||(t?`radix-${t}`:``)}ge(F,`useId`);var ye=Object.defineProperty,be=(e,t)=>ye(e,`name`,{value:t,configurable:!0}),xe=m.useEffectEvent,Se=m.useInsertionEffect;function Ce(e){if(typeof xe==`function`)return xe(e);let t=m.useRef(()=>{throw Error(`Cannot call an event handler while rendering.`)});return typeof Se==`function`?Se(()=>{t.current=e}):P(()=>{t.current=e}),m.useMemo(()=>((...e)=>t.current?.(...e)),[])}be(Ce,`useEffectEvent`);var we=Object.defineProperty,Te=(e,t)=>we(e,`name`,{value:t,configurable:!0}),Ee=m.useInsertionEffect||P;function De({prop:e,defaultProp:t,onChange:n=/* @__PURE__ */ Te(()=>{},`onChange`),caller:r}){let[i,a,o]=Oe({defaultProp:t,onChange:n}),s=e!==void 0;return[s?e:i,m.useCallback(t=>{if(s){let n=ke(t)?t(e):t;n!==e&&o.current?.(n)}else a(t)},[s,e,a,o])]}Te(De,`useControllableState`);function Oe({defaultProp:e,onChange:t}){let[n,r]=m.useState(e),i=m.useRef(n),a=m.useRef(t);return Ee(()=>{a.current=t},[t]),m.useEffect(()=>{i.current!==n&&(a.current?.(n),i.current=n)},[n,i]),[n,r,a]}Te(Oe,`useUncontrolledState`);function ke(e){return typeof e==`function`}Te(ke,`isFunction`);var Ae=Symbol(`RADIX:SYNC_STATE`);function je(e,t,n,r){let{prop:i,defaultProp:a,onChange:o,caller:s}=t,c=i!==void 0,l=Ce(o),u=[{...n,state:a}];r&&u.push(r);let[d,f]=m.useReducer((t,n)=>{if(n.type===Ae)return{...t,state:n.state};let r=e(t,n);return c&&!Object.is(r.state,t.state)&&l(r.state),r},...u),p=d.state,h=m.useRef(p);m.useEffect(()=>{h.current!==p&&(h.current=p,c||l(p))},[p,h,c]);let g=m.useMemo(()=>i===void 0?d:{...d,state:i},[d,i]);return m.useEffect(()=>{c&&!Object.is(i,d.state)&&f({type:Ae,state:i})},[i,d.state,c]),[g,f]}Te(je,`useControllableStateReducer`);var Me=/* @__PURE__ */ e(n(),1),Ne=Object.defineProperty,I=(e,t)=>Ne(e,`name`,{value:t,configurable:!0});// @__NO_SIDE_EFFECTS__ function Pe(e){let t=m.forwardRef((t,n)=>{let{children:r,...i}=t,a=null,o=!1,s=[];He(r)&&typeof Ke==`function`&&(r=Ke(r._payload)),m.Children.forEach(r,e=>{if(Be(e)){o=!0;let t=e,n=`child`in t.props?t.props.child:t.props.children;He(n)&&typeof Ke==`function`&&(n=Ke(n._payload)),a=Le(t,n),s.push(a?.props?.children)}else s.push(e)}),a?a=m.cloneElement(a,void 0,s):!o&&m.Children.count(r)===1&&m.isValidElement(r)&&(a=r);let c=a?ze(a):void 0,l=j(n,c);if(!a){if(r||r===0)throw Error(o?Ge(e):We(e));return r}let u=Re(i,a.props??{});return a.type!==m.Fragment&&(u.ref=n?l:c),m.cloneElement(a,u)});return t.displayName=`${e}.Slot`,t}I(Pe,`createSlot`);var Fe=Symbol.for(`radix.slottable`);// @__NO_SIDE_EFFECTS__
M dist/chunks/composer.mjs
@@ -1,6 +1,6 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{Bt as r,P as i,T as a,U as o,dt as s,n as c,p as l}from"./vendor-icons";import{c as u,i as d}from"./ui-base";import{Spinner as f}from"../components/ui/spinner";import{a as p,c as m,h,l as g,r as _,t as v,u as y}from"./ui-shell";import{t as b}from"./vendor-yaml";import{s as x}from"./agent-events.mjs";import{CodeEditor as S}from"../components/code-editor";var C=/* @__PURE__ */ e(t(),1),w=/* @__PURE__ */ e(n(),1);function T({attachments:e}){return/* @__PURE__ */ (0,w.jsx)(`input`,{ref:e.inputRef,type:`file`,multiple:!0,className:`hidden`,onChange:t=>{e.addFiles(t.currentTarget.files),t.currentTarget.value=``}})}function E({entries:e,onRemove:t}){return e.length===0?null:/* @__PURE__ */ (0,w.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:e.map(({id:e,file:n})=>/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`inline-flex max-w-52 items-center gap-1.5 rounded-full border bg-muted/50 py-1 pl-2 pr-1 text-xs`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`min-w-0 truncate`,children:n.name}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`shrink-0 font-mono text-muted-foreground`,children:x(n.size)}),/* @__PURE__ */ (0,w.jsx)(d,{variant:`ghost`,size:`icon-xs`,type:`button`,title:`Remove ${n.name}`,onClick:()=>t(e),className:`size-5 rounded-full text-muted-foreground`,children:/* @__PURE__ */ (0,w.jsx)(c,{className:`size-3`})})]},e))})}const D=(0,C.lazy)(async()=>({default:(await import(`./composer-textarea.client.mjs`)).ComposerTextareaClient}));function O(e){return/* @__PURE__ */ (0,w.jsx)(C.Suspense,{fallback:/* @__PURE__ */ (0,w.jsx)(`div`,{className:`min-h-10`,"aria-label":`Loading`,"aria-busy":`true`}),children:/* @__PURE__ */ (0,w.jsx)(D,{...e})})}const k=26214400;function A(e){let t=[],n=[];for(let r of e)r.size<=k?t.push(r):n.push(r);return{accepted:t,rejected:n}}function j(e){if(e.length!==0)return`${e.length===1?e[0].name:`${String(e.length)} files`} must be ${x(k)} or smaller.`}function M(){let e=(0,C.useRef)(null),[t,n]=(0,C.useState)([]),[r,i]=(0,C.useState)();function a(e){let t=Array.from(e||[]);if(t.length===0)return;let{accepted:r,rejected:a}=A(t);i(j(a)),r.length>0&&n(e=>[...e,...r.map(e=>({id:crypto.randomUUID(),file:e}))])}function o(e){n(t=>t.filter(t=>t.id!==e)),i(void 0)}function s(){n([]),i(void 0)}return{entries:t,files:t.map(e=>e.file),fileError:r,addFiles:a,removeFile:o,clearFiles:s,openFilePicker:()=>e.current?.click(),inputRef:e}}function N(e=``){let[t,n]=(0,C.useState)(e);return{message:t,setMessage:n,attachments:M()}}function P({mode:e,onModeChange:t,message:n,raw:r,isSubmitting:i=!1,error:a,autoFocusMessage:o=!1,isInterrupting:s=!1,onInterrupt:c,attach:l=!0}){let d=e===`raw`?r:void 0,f=!i&&(d?d.value.trim()!==``:n.canSubmit),p=e===`message`&&!!c&&!n.canSubmit&&!i,m=l&&!i,{isDragging:h,dropHandlers:g}=L({accepts:m,onFiles:r=>{e!==`message`&&t(`message`),n.onAddFiles(r)}});function _(){f&&(d||n).onSubmit()}function v(){i||s||!c||c()}return/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`w-full`,children:[/* @__PURE__ */ (0,w.jsx)(I,{error:a}),/* @__PURE__ */ (0,w.jsxs)(`div`,{...g,"data-drop-active":h?`true`:void 0,className:u(`flex items-end gap-1 rounded-3xl border bg-background p-1 shadow-sm transition-shadow sm:py-2 sm:pr-2 sm:pl-1.5`,h&&`ring-2 ring-primary/40 border-primary/40`),children:[l?/* @__PURE__ */ (0,w.jsx)(z,{mode:e,onModeChange:t,hasRaw:!!r,isSubmitting:i,onAttach:n.onAttach}):null,d?/* @__PURE__ */ (0,w.jsx)(S,{value:d.value,onValueChange:d.onValueChange,onSubmit:_,focusOnMount:!0,placeholder:`type: events.iterate.com/note/added +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{P as r,T as i,U as a,Vt as o,ft as s,n as c,p as l}from"./vendor-icons";import{c as u,i as d}from"./ui-base";import{Spinner as f}from"../components/ui/spinner";import{a as p,c as m,h,l as g,r as _,t as v,u as y}from"./ui-shell";import{t as b}from"./vendor-yaml";import{s as x}from"./agent-events.mjs";import{CodeEditor as S}from"../components/code-editor";var C=/* @__PURE__ */ e(t(),1),w=/* @__PURE__ */ e(n(),1);function T({attachments:e}){return/* @__PURE__ */ (0,w.jsx)(`input`,{ref:e.inputRef,type:`file`,multiple:!0,className:`hidden`,onChange:t=>{e.addFiles(t.currentTarget.files),t.currentTarget.value=``}})}function E({entries:e,onRemove:t}){return e.length===0?null:/* @__PURE__ */ (0,w.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:e.map(({id:e,file:n})=>/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`inline-flex max-w-52 items-center gap-1.5 rounded-full border bg-muted/50 py-1 pl-2 pr-1 text-xs`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`min-w-0 truncate`,children:n.name}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`shrink-0 font-mono text-muted-foreground`,children:x(n.size)}),/* @__PURE__ */ (0,w.jsx)(d,{variant:`ghost`,size:`icon-xs`,type:`button`,title:`Remove ${n.name}`,onClick:()=>t(e),className:`size-5 rounded-full text-muted-foreground`,children:/* @__PURE__ */ (0,w.jsx)(c,{className:`size-3`})})]},e))})}const D=(0,C.lazy)(async()=>({default:(await import(`./composer-textarea.client.mjs`)).ComposerTextareaClient}));function O(e){return/* @__PURE__ */ (0,w.jsx)(C.Suspense,{fallback:/* @__PURE__ */ (0,w.jsx)(`div`,{className:`min-h-10`,"aria-label":`Loading`,"aria-busy":`true`}),children:/* @__PURE__ */ (0,w.jsx)(D,{...e})})}const k=26214400;function A(e){let t=[],n=[];for(let r of e)r.size<=k?t.push(r):n.push(r);return{accepted:t,rejected:n}}function j(e){if(e.length!==0)return`${e.length===1?e[0].name:`${String(e.length)} files`} must be ${x(k)} or smaller.`}function M(){let e=(0,C.useRef)(null),[t,n]=(0,C.useState)([]),[r,i]=(0,C.useState)();function a(e){let t=Array.from(e||[]);if(t.length===0)return;let{accepted:r,rejected:a}=A(t);i(j(a)),r.length>0&&n(e=>[...e,...r.map(e=>({id:crypto.randomUUID(),file:e}))])}function o(e){n(t=>t.filter(t=>t.id!==e)),i(void 0)}function s(){n([]),i(void 0)}return{entries:t,files:t.map(e=>e.file),fileError:r,addFiles:a,removeFile:o,clearFiles:s,openFilePicker:()=>e.current?.click(),inputRef:e}}function N(e=``){let[t,n]=(0,C.useState)(e);return{message:t,setMessage:n,attachments:M()}}function P({mode:e,onModeChange:t,message:n,raw:r,isSubmitting:i=!1,error:a,autoFocusMessage:o=!1,isInterrupting:s=!1,onInterrupt:c,attach:l=!0,topLip:d,below:f}){let p=e===`raw`?r:void 0,m=!i&&(p?p.value.trim()!==``:n.canSubmit),h=e===`message`&&!!c&&!n.canSubmit&&!i,g=l&&!i,{isDragging:_,dropHandlers:v}=R({accepts:g,onFiles:r=>{e!==`message`&&t(`message`),n.onAddFiles(r)}});function y(){m&&(p||n).onSubmit()}function b(){i||s||!c||c()}return/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`w-full`,children:[/* @__PURE__ */ (0,w.jsx)(L,{error:a}),/* @__PURE__ */ (0,w.jsxs)(`div`,{className:u(`group/composer-card rounded-3xl transition-shadow has-[[data-composer-lip]]:border has-[[data-composer-lip]]:border-border has-[[data-composer-lip]]:bg-muted/45 has-[[data-composer-lip]]:shadow-sm`,_&&`has-[[data-composer-lip]]:border-primary/40 has-[[data-composer-lip]]:ring-2 has-[[data-composer-lip]]:ring-primary/40`),children:[/* @__PURE__ */ (0,w.jsx)(F,{className:`px-3.5 py-1`,children:d}),/* @__PURE__ */ (0,w.jsxs)(`div`,{...v,"data-drop-active":_?`true`:void 0,className:u(`flex items-end gap-1 rounded-3xl border bg-background p-1 shadow-sm transition-shadow sm:py-2 sm:pr-2 sm:pl-1.5 group-has-[[data-composer-lip]]/composer-card:border-x-0 group-has-[[data-composer-lip]]/composer-card:border-b-0 group-has-[[data-composer-lip]]/composer-card:shadow-none`,_&&`border-primary/40 ring-2 ring-primary/40 group-has-[[data-composer-lip]]/composer-card:ring-0`),children:[l?/* @__PURE__ */ (0,w.jsx)(B,{mode:e,onModeChange:t,hasRaw:!!r,isSubmitting:i,onAttach:n.onAttach}):null,p?/* @__PURE__ */ (0,w.jsx)(S,{value:p.value,onValueChange:p.onValueChange,onSubmit:y,focusOnMount:!0,placeholder:`type: events.iterate.com/note/added payload: - text: hello`,className:`min-w-0 flex-1 px-2 py-1.5`}):/* @__PURE__ */ (0,w.jsx)(F,{message:n,onSubmit:_,focusOnMount:o,takesFiles:m}),/* @__PURE__ */ (0,w.jsx)(B,{stops:p,sendTitle:e===`raw`?`Append events (⌘↵)`:`Send message`,canSubmit:f,isSubmitting:i,isInterrupting:s,onSubmit:_,onInterrupt:v})]})]})}function F({message:e,onSubmit:t,focusOnMount:n,takesFiles:r}){return/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,onPaste:t=>{let n=R(t.clipboardData);r&&n.length>0&&e.onAddFiles(n)},children:[e.attachments?/* @__PURE__ */ (0,w.jsx)(`div`,{className:`px-1 pb-1`,children:e.attachments}):null,/* @__PURE__ */ (0,w.jsx)(O,{value:e.value,onValueChange:e.onValueChange,onSubmit:t,focusOnMount:n,placeholder:e.placeholder})]})}function I({error:e}){return e?/* @__PURE__ */ (0,w.jsx)(`p`,{className:`mb-2 ml-4 truncate font-mono text-xs text-destructive`,role:`alert`,"data-type":`error`,children:e}):null}function L({accepts:e,onFiles:t}){let[n,r]=(0,C.useState)(!1);return{isDragging:n,dropHandlers:{onDragEnter(t){t.dataTransfer.types.includes(`Files`)&&(t.preventDefault(),e&&r(!0))},onDragOver(t){t.dataTransfer.types.includes(`Files`)&&(t.preventDefault(),t.dataTransfer.dropEffect=e?`copy`:`none`)},onDragLeave(e){e.currentTarget.contains(e.relatedTarget)||r(!1)},onDrop(n){n.dataTransfer.types.includes(`Files`)&&(n.preventDefault(),r(!1),e&&t(n.dataTransfer.files))}}}}function R(e){return e.files.length>0?Array.from(e.files):Array.from(e.items).flatMap(e=>{let t=e.kind===`file`?e.getAsFile():null;return t?[t]:[]})}function z({mode:e,onModeChange:t,hasRaw:n,isSubmitting:r,onAttach:c}){return/* @__PURE__ */ (0,w.jsxs)(v,{children:[/* @__PURE__ */ (0,w.jsx)(h,{render:/* @__PURE__ */ (0,w.jsx)(d,{variant:`ghost`,size:`icon-lg`,title:`Composer mode`,className:`rounded-full pointer-coarse:size-11`}),children:/* @__PURE__ */ (0,w.jsx)(a,{className:`size-4.5`})}),/* @__PURE__ */ (0,w.jsxs)(_,{align:`start`,side:`top`,className:`w-60`,children:[n?/* @__PURE__ */ (0,w.jsxs)(w.Fragment,{children:[/* @__PURE__ */ (0,w.jsxs)(m,{value:e,onValueChange:e=>t(e===`raw`?`raw`:`message`),children:[/* @__PURE__ */ (0,w.jsxs)(g,{value:`message`,closeOnClick:!0,children:[/* @__PURE__ */ (0,w.jsx)(o,{className:`text-muted-foreground`}),/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col py-0.5`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`font-medium`,children:`Message`}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Chat with this agent`})]})]}),/* @__PURE__ */ (0,w.jsxs)(g,{value:`raw`,closeOnClick:!0,children:[/* @__PURE__ */ (0,w.jsx)(s,{className:`text-muted-foreground`}),/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col py-0.5`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`font-medium`,children:`Raw event`}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Append YAML or JSON`})]})]})]}),/* @__PURE__ */ (0,w.jsx)(y,{})]}):null,/* @__PURE__ */ (0,w.jsxs)(p,{disabled:r,onClick:()=>{e!==`message`&&t(`message`),c()},children:[/* @__PURE__ */ (0,w.jsx)(i,{className:`text-muted-foreground`}),/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col py-0.5`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`font-medium`,children:`Attach files`}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Send along with a message`})]})]})]})]})}function B({stops:e,sendTitle:t,canSubmit:n,isSubmitting:i,isInterrupting:a,onSubmit:o,onInterrupt:s}){return/* @__PURE__ */ (0,w.jsxs)(d,{size:`icon-lg`,title:e?`Stop generation`:t,"data-spinner":e?`true`:void 0,onClick:e?s:o,disabled:e?a:!n,className:`relative overflow-hidden rounded-full pointer-coarse:size-11`,children:[e?/* @__PURE__ */ (0,w.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0 rounded-full border-2 border-transparent border-t-primary border-r-primary/40 animate-spin`}):null,(e?a:i)?/* @__PURE__ */ (0,w.jsx)(f,{className:`size-4`}):e?/* @__PURE__ */ (0,w.jsx)(l,{className:`size-3.5 fill-current`}):/* @__PURE__ */ (0,w.jsx)(r,{className:`size-4`})]})}function V(e){return Promise.all(e.map(e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t({contentType:e.type||`application/octet-stream`,filename:e.name,data:String(r.result)}),r.onerror=()=>n(r.error),r.readAsDataURL(e)})))}function H({draft:e,placeholder:t,onSubmit:n,onAppendRaw:r,interrupt:i,autoFocusMessage:a=!1,attach:o=!0,onTyping:s}){let{message:c,setMessage:l,attachments:u}=e,[d,f]=(0,C.useState)(`message`),[p,m]=(0,C.useState)(`type: events.iterate.com/note/added + text: hello`,className:`min-w-0 flex-1 px-2 py-1.5`}):/* @__PURE__ */ (0,w.jsx)(I,{message:n,onSubmit:y,focusOnMount:o,takesFiles:g}),/* @__PURE__ */ (0,w.jsx)(V,{stops:h,sendTitle:e===`raw`?`Append events (⌘↵)`:`Send message`,canSubmit:m,isSubmitting:i,isInterrupting:s,onSubmit:y,onInterrupt:b})]})]}),/* @__PURE__ */ (0,w.jsx)(F,{dataSlot:`composer-below`,className:`px-2 pt-1.5`,children:f})]})}function F({dataSlot:e,className:t,children:n}){return n?/* @__PURE__ */ (0,w.jsx)(`div`,{"data-slot":e,className:u(t,`empty:hidden`),children:n}):null}function I({message:e,onSubmit:t,focusOnMount:n,takesFiles:r}){return/* @__PURE__ */ (0,w.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,onPaste:t=>{let n=z(t.clipboardData);r&&n.length>0&&e.onAddFiles(n)},children:[e.attachments?/* @__PURE__ */ (0,w.jsx)(`div`,{className:`px-1 pb-1`,children:e.attachments}):null,/* @__PURE__ */ (0,w.jsx)(O,{value:e.value,onValueChange:e.onValueChange,onSubmit:t,focusOnMount:n,placeholder:e.placeholder})]})}function L({error:e}){return e?/* @__PURE__ */ (0,w.jsx)(`p`,{className:`mb-2 ml-4 truncate font-mono text-xs text-destructive`,role:`alert`,"data-type":`error`,children:e}):null}function R({accepts:e,onFiles:t}){let[n,r]=(0,C.useState)(!1);return{isDragging:n,dropHandlers:{onDragEnter(t){t.dataTransfer.types.includes(`Files`)&&(t.preventDefault(),e&&r(!0))},onDragOver(t){t.dataTransfer.types.includes(`Files`)&&(t.preventDefault(),t.dataTransfer.dropEffect=e?`copy`:`none`)},onDragLeave(e){e.currentTarget.contains(e.relatedTarget)||r(!1)},onDrop(n){n.dataTransfer.types.includes(`Files`)&&(n.preventDefault(),r(!1),e&&t(n.dataTransfer.files))}}}}function z(e){return e.files.length>0?Array.from(e.files):Array.from(e.items).flatMap(e=>{let t=e.kind===`file`?e.getAsFile():null;return t?[t]:[]})}function B({mode:e,onModeChange:t,hasRaw:n,isSubmitting:o,onAttach:c}){return/* @__PURE__ */ (0,w.jsxs)(v,{children:[/* @__PURE__ */ (0,w.jsx)(h,{render:/* @__PURE__ */ (0,w.jsx)(d,{variant:`ghost`,size:`icon-lg`,title:`Composer mode`,className:`rounded-full pointer-coarse:size-11`}),children:/* @__PURE__ */ (0,w.jsx)(i,{className:`size-4.5`})}),/* @__PURE__ */ (0,w.jsxs)(_,{align:`start`,side:`top`,className:`w-60`,children:[n?/* @__PURE__ */ (0,w.jsxs)(w.Fragment,{children:[/* @__PURE__ */ (0,w.jsxs)(m,{value:e,onValueChange:e=>t(e===`raw`?`raw`:`message`),children:[/* @__PURE__ */ (0,w.jsxs)(g,{value:`message`,closeOnClick:!0,children:[/* @__PURE__ */ (0,w.jsx)(a,{className:`text-muted-foreground`}),/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col py-0.5`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`font-medium`,children:`Message`}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Chat with this agent`})]})]}),/* @__PURE__ */ (0,w.jsxs)(g,{value:`raw`,closeOnClick:!0,children:[/* @__PURE__ */ (0,w.jsx)(s,{className:`text-muted-foreground`}),/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col py-0.5`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`font-medium`,children:`Raw event`}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Append YAML or JSON`})]})]})]}),/* @__PURE__ */ (0,w.jsx)(y,{})]}):null,/* @__PURE__ */ (0,w.jsxs)(p,{disabled:o,onClick:()=>{e!==`message`&&t(`message`),c()},children:[/* @__PURE__ */ (0,w.jsx)(r,{className:`text-muted-foreground`}),/* @__PURE__ */ (0,w.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col py-0.5`,children:[/* @__PURE__ */ (0,w.jsx)(`span`,{className:`font-medium`,children:`Attach files`}),/* @__PURE__ */ (0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Send along with a message`})]})]})]})]})}function V({stops:e,sendTitle:t,canSubmit:n,isSubmitting:r,isInterrupting:i,onSubmit:a,onInterrupt:s}){return/* @__PURE__ */ (0,w.jsxs)(d,{size:`icon-lg`,title:e?`Stop generation`:t,"data-spinner":e?`true`:void 0,onClick:e?s:a,disabled:e?i:!n,className:`relative overflow-hidden rounded-full pointer-coarse:size-11`,children:[e?/* @__PURE__ */ (0,w.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-0 rounded-full border-2 border-transparent border-t-primary border-r-primary/40 animate-spin`}):null,(e?i:r)?/* @__PURE__ */ (0,w.jsx)(f,{className:`size-4`}):e?/* @__PURE__ */ (0,w.jsx)(l,{className:`size-3.5 fill-current`}):/* @__PURE__ */ (0,w.jsx)(o,{className:`size-4`})]})}function H(e){return Promise.all(e.map(e=>new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t({contentType:e.type||`application/octet-stream`,filename:e.name,data:String(r.result)}),r.onerror=()=>n(r.error),r.readAsDataURL(e)})))}function U({draft:e,placeholder:t,onSubmit:n,onAppendRaw:r,interrupt:i,autoFocusMessage:a=!1,attach:o=!0,onTyping:s,topLip:c,below:l}){let{message:u,setMessage:d,attachments:f}=e,[p,m]=(0,C.useState)(`message`),[h,g]=(0,C.useState)(`type: events.iterate.com/note/added payload: text: Hello from the agents page -`),[h,g]=(0,C.useState)(!1),[_,v]=(0,C.useState)(),y=(0,C.useRef)(!1),x=(0,C.useRef)(0);async function S(e){if(y.current)return!1;y.current=!0,g(!0),v(void 0);try{return await e(),!0}catch(e){return v(e instanceof Error?e.message:String(e)),!1}finally{y.current=!1,g(!1)}}async function D(){if(y.current)return;let e=c,t=e.trim();if(t===``&&u.files.length===0)return;let r=x.current;if(e&&l(t=>t.startsWith(e)?t.slice(e.length):t),!await S(async()=>n({message:t||`(see attached)`,files:await V(u.files)}))){e&&x.current===r&&l(e);return}u.clearFiles(),x.current===r&&s?.(!1)}async function O(e){let t=p.trim();t&&await S(async()=>{let n=b(t);await e(Array.isArray(n)?n:[n])})}let k=[u.fileError,_,i?.error].filter(Boolean).join(` · `)||void 0;return/* @__PURE__ */ (0,w.jsxs)(w.Fragment,{children:[o?/* @__PURE__ */ (0,w.jsx)(T,{attachments:u}):null,/* @__PURE__ */ (0,w.jsx)(P,{mode:d,onModeChange:f,attach:o,autoFocusMessage:a,message:{value:c,onValueChange:e=>{x.current+=1,l(e),s?.(e.trim()!==``)},onSubmit:D,canSubmit:c.trim()!==``||u.files.length>0,attachments:u.entries.length===0?void 0:/* @__PURE__ */ (0,w.jsx)(E,{entries:u.entries,onRemove:u.removeFile}),onAttach:u.openFilePicker,onAddFiles:u.addFiles,placeholder:t},raw:o&&r?{value:p,onValueChange:m,onSubmit:()=>O(r)}:void 0,isSubmitting:h,error:k,isInterrupting:i?.isInterrupting,onInterrupt:i?.run})]})}export{N as n,H as t}; +`),[_,v]=(0,C.useState)(!1),[y,x]=(0,C.useState)(),S=(0,C.useRef)(!1),D=(0,C.useRef)(0);async function O(e){if(S.current)return!1;S.current=!0,v(!0),x(void 0);try{return await e(),!0}catch(e){return x(e instanceof Error?e.message:String(e)),!1}finally{S.current=!1,v(!1)}}async function k(){if(S.current)return;let e=u,t=e.trim();if(t===``&&f.files.length===0)return;let r=D.current;if(e&&d(t=>t.startsWith(e)?t.slice(e.length):t),!await O(async()=>n({message:t||`(see attached)`,files:await H(f.files)}))){e&&D.current===r&&d(e);return}f.clearFiles(),D.current===r&&s?.(!1)}async function A(e){let t=h.trim();t&&await O(async()=>{let n=b(t);await e(Array.isArray(n)?n:[n])})}let j=[f.fileError,y,i?.error].filter(Boolean).join(` · `)||void 0;return/* @__PURE__ */ (0,w.jsxs)(w.Fragment,{children:[o?/* @__PURE__ */ (0,w.jsx)(T,{attachments:f}):null,/* @__PURE__ */ (0,w.jsx)(P,{mode:p,onModeChange:m,attach:o,autoFocusMessage:a,message:{value:u,onValueChange:e=>{D.current+=1,d(e),s?.(e.trim()!==``)},onSubmit:k,canSubmit:u.trim()!==``||f.files.length>0,attachments:f.entries.length===0?void 0:/* @__PURE__ */ (0,w.jsx)(E,{entries:f.entries,onRemove:f.removeFile}),onAttach:f.openFilePicker,onAddFiles:f.addFiles,placeholder:t},raw:o&&r?{value:h,onValueChange:g,onSubmit:()=>A(r)}:void 0,isSubmitting:_,error:j,isInterrupting:i?.isInterrupting,onInterrupt:i?.run,topLip:c,below:l})]})}export{N as n,U as t};
M dist/chunks/context-about.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{et as r}from"./vendor-icons";import{c as i,i as a,r as o,t as s}from"./ui-base";import{Popover as c,PopoverContent as l,PopoverTrigger as u}from"../components/ui/popover";import{_ as d,h as f,i as p,p as m,u as h}from"./context-catalog-rows.mjs";import{Badge as g}from"../components/ui/badge";var _=/* @__PURE__ */ e(t(),1),v=/* @__PURE__ */ e(n(),1);function y({awake:e,className:t}){return/* @__PURE__ */ (0,v.jsx)(`span`,{role:e?`img`:void 0,"aria-label":e?`awake`:void 0,className:i(`size-1.5 shrink-0 rounded-full`,e&&`bg-success`,t)})}function b({row:e,onDescribe:t}){let n=e&&h(e)||``;return/* @__PURE__ */ (0,v.jsxs)(c,{children:[/* @__PURE__ */ (0,v.jsx)(u,{render:/* @__PURE__ */ (0,v.jsxs)(a,{variant:`ghost`,size:`sm`,className:`h-7 max-w-64 gap-1.5 px-2 text-xs`,children:[/* @__PURE__ */ (0,v.jsx)(y,{awake:!!e?.awake}),/* @__PURE__ */ (0,v.jsx)(`span`,{className:`truncate text-muted-foreground`,children:n||e?.description||`About this context`}),/* @__PURE__ */ (0,v.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`})]})}),/* @__PURE__ */ (0,v.jsxs)(l,{align:`start`,className:`max-h-[70svh] w-96 gap-3 overflow-y-auto text-xs`,children:[/* @__PURE__ */ (0,v.jsx)(x,{title:n,description:e?.description||``,listed:!!e,onDescribe:t},JSON.stringify([n,e?.description||``])),e?/* @__PURE__ */ (0,v.jsx)(S,{row:e}):/* @__PURE__ */ (0,v.jsx)(`p`,{className:`text-muted-foreground`,children:`Not listed yet.`})]})]})}function x({title:e,description:t,listed:n,onDescribe:r}){let[i,c]=(0,_.useState)(e),[l,u]=(0,_.useState)(t),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)();if(!r)return/* @__PURE__ */ (0,v.jsxs)(v.Fragment,{children:[e?/* @__PURE__ */ (0,v.jsx)(`p`,{className:`font-medium`,children:e}):null,/* @__PURE__ */ (0,v.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t||`No description.`})]});let h=async()=>{f(!0),m(void 0);try{i.trim()===e?await r(l.trim()):await r(l.trim(),i.trim())}catch(e){m(e instanceof Error?e.message:String(e))}f(!1)};return/* @__PURE__ */ (0,v.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[/* @__PURE__ */ (0,v.jsx)(o,{"aria-label":`Title`,placeholder:`A short title`,maxLength:80,disabled:!n,className:`h-7 text-xs md:text-xs`,value:i,onChange:e=>c(e.target.value)}),/* @__PURE__ */ (0,v.jsx)(s,{"aria-label":`Description`,placeholder:`What is this context for?`,className:`min-h-16 text-xs md:text-xs`,value:l,onChange:e=>u(e.target.value)}),/* @__PURE__ */ (0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[/* @__PURE__ */ (0,v.jsx)(a,{type:`button`,size:`sm`,disabled:d||l.trim()===t&&i.trim()===e,onClick:()=>void h(),children:d?`Saving…`:`Save`}),p?/* @__PURE__ */ (0,v.jsx)(`span`,{role:`alert`,className:`truncate text-destructive`,title:p,children:p}):null]})]})}function S({row:e,typeLimit:t}){let n=Object.entries(e.eventTypes).toSorted(([e,t],[n,r])=>r-t||e.localeCompare(n)),r=t===void 0?n:n.slice(0,t),i=m(e.recentTypes),a=p(e),o=[[`Working`,e.awake?`since ${new Date(e.awake.since).toLocaleTimeString()}`:`no`],[`Last active`,a&&new Date(a).toLocaleString()],[`Created`,e.createdAt&&new Date(e.createdAt).toLocaleString()],[`Events`,String(e.eventCount)],[`Storage`,e.storageBytes===void 0?void 0:f(e.storageBytes)]];return/* @__PURE__ */ (0,v.jsxs)(v.Fragment,{children:[/* @__PURE__ */ (0,v.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5`,children:o.map(([e,t])=>t?/* @__PURE__ */ (0,v.jsxs)(`div`,{className:`contents`,children:[/* @__PURE__ */ (0,v.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,v.jsx)(`dd`,{className:`truncate tabular-nums`,children:t})]},e):null)}),i.length?/* @__PURE__ */ (0,v.jsx)(C,{title:`Last events, newest first`,children:/* @__PURE__ */ (0,v.jsx)(`ul`,{className:`flex flex-col gap-0.5 font-mono text-2xs`,children:i.map(({type:e,count:t,at:n})=>/* @__PURE__ */ (0,v.jsxs)(`li`,{className:`flex min-w-0 gap-2`,children:[/* @__PURE__ */ (0,v.jsx)(`span`,{className:`min-w-0 truncate`,title:e,children:d(e)}),t>1?/* @__PURE__ */ (0,v.jsxs)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,children:[`×`,t]}):null]},n))})}):null,/* @__PURE__ */ (0,v.jsx)(C,{title:`Processors (${String(e.processors.length)})`,children:e.processors.length?/* @__PURE__ */ (0,v.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.processors.map(e=>/* @__PURE__ */ (0,v.jsx)(g,{variant:`secondary`,className:`text-2xs`,children:e},e))}):/* @__PURE__ */ (0,v.jsx)(`p`,{className:`text-muted-foreground`,children:`None.`})}),/* @__PURE__ */ (0,v.jsxs)(C,{title:`Event types (${String(n.length)})`,children:[/* @__PURE__ */ (0,v.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r.map(([e,t])=>/* @__PURE__ */ (0,v.jsxs)(`li`,{className:`flex min-w-0 gap-2`,children:[/* @__PURE__ */ (0,v.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e,children:d(e)}),/* @__PURE__ */ (0,v.jsx)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,children:t})]},e))}),r.length<n.length?/* @__PURE__ */ (0,v.jsxs)(`p`,{className:`text-muted-foreground`,children:[String(n.length-r.length),` more types.`]}):null]}),e.metadata?/* @__PURE__ */ (0,v.jsx)(C,{title:`Metadata`,children:/* @__PURE__ */ (0,v.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted p-2 text-2xs`,children:JSON.stringify(e.metadata,null,2)})}):null]})}function C({title:e,children:t}){return/* @__PURE__ */ (0,v.jsxs)(`section`,{className:`flex flex-col gap-1`,children:[/* @__PURE__ */ (0,v.jsx)(`h3`,{className:`text-2xs font-medium tracking-wide text-muted-foreground uppercase`,children:e}),t]})}export{S as n,y as r,b as t}; +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{tt as r}from"./vendor-icons";import{c as i,i as a,r as o,t as s}from"./ui-base";import{Popover as c,PopoverContent as l,PopoverTrigger as u}from"../components/ui/popover";import{_ as d,h as f,i as p,p as m,u as h}from"./context-catalog-rows.mjs";import{Badge as g}from"../components/ui/badge";var _=/* @__PURE__ */ e(t(),1),v=/* @__PURE__ */ e(n(),1);function y({awake:e,className:t}){return/* @__PURE__ */ (0,v.jsx)(`span`,{role:e?`img`:void 0,"aria-label":e?`awake`:void 0,className:i(`size-1.5 shrink-0 rounded-full`,e&&`bg-success`,t)})}function b({row:e,onDescribe:t}){let n=e&&h(e)||``;return/* @__PURE__ */ (0,v.jsxs)(c,{children:[/* @__PURE__ */ (0,v.jsx)(u,{render:/* @__PURE__ */ (0,v.jsxs)(a,{variant:`ghost`,size:`sm`,className:`h-7 max-w-64 gap-1.5 px-2 text-xs`,children:[/* @__PURE__ */ (0,v.jsx)(y,{awake:!!e?.awake}),/* @__PURE__ */ (0,v.jsx)(`span`,{className:`truncate text-muted-foreground`,children:n||e?.description||`About this context`}),/* @__PURE__ */ (0,v.jsx)(r,{className:`size-3.5 shrink-0 text-muted-foreground`})]})}),/* @__PURE__ */ (0,v.jsxs)(l,{align:`start`,className:`max-h-[70svh] w-96 gap-3 overflow-y-auto text-xs`,children:[/* @__PURE__ */ (0,v.jsx)(x,{title:n,description:e?.description||``,listed:!!e,onDescribe:t},JSON.stringify([n,e?.description||``])),e?/* @__PURE__ */ (0,v.jsx)(S,{row:e}):/* @__PURE__ */ (0,v.jsx)(`p`,{className:`text-muted-foreground`,children:`Not listed yet.`})]})]})}function x({title:e,description:t,listed:n,onDescribe:r}){let[i,c]=(0,_.useState)(e),[l,u]=(0,_.useState)(t),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)();if(!r)return/* @__PURE__ */ (0,v.jsxs)(v.Fragment,{children:[e?/* @__PURE__ */ (0,v.jsx)(`p`,{className:`font-medium`,children:e}):null,/* @__PURE__ */ (0,v.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t||`No description.`})]});let h=async()=>{f(!0),m(void 0);try{i.trim()===e?await r(l.trim()):await r(l.trim(),i.trim())}catch(e){m(e instanceof Error?e.message:String(e))}f(!1)};return/* @__PURE__ */ (0,v.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[/* @__PURE__ */ (0,v.jsx)(o,{"aria-label":`Title`,placeholder:`A short title`,maxLength:80,disabled:!n,className:`h-7 text-xs md:text-xs`,value:i,onChange:e=>c(e.target.value)}),/* @__PURE__ */ (0,v.jsx)(s,{"aria-label":`Description`,placeholder:`What is this context for?`,className:`min-h-16 text-xs md:text-xs`,value:l,onChange:e=>u(e.target.value)}),/* @__PURE__ */ (0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[/* @__PURE__ */ (0,v.jsx)(a,{type:`button`,size:`sm`,disabled:d||l.trim()===t&&i.trim()===e,onClick:()=>void h(),children:d?`Saving…`:`Save`}),p?/* @__PURE__ */ (0,v.jsx)(`span`,{role:`alert`,className:`truncate text-destructive`,title:p,children:p}):null]})]})}function S({row:e,typeLimit:t}){let n=Object.entries(e.eventTypes).toSorted(([e,t],[n,r])=>r-t||e.localeCompare(n)),r=t===void 0?n:n.slice(0,t),i=m(e.recentTypes),a=p(e),o=[[`Working`,e.awake?`since ${new Date(e.awake.since).toLocaleTimeString()}`:`no`],[`Last active`,a&&new Date(a).toLocaleString()],[`Created`,e.createdAt&&new Date(e.createdAt).toLocaleString()],[`Events`,String(e.eventCount)],[`Storage`,e.storageBytes===void 0?void 0:f(e.storageBytes)]];return/* @__PURE__ */ (0,v.jsxs)(v.Fragment,{children:[/* @__PURE__ */ (0,v.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-0.5`,children:o.map(([e,t])=>t?/* @__PURE__ */ (0,v.jsxs)(`div`,{className:`contents`,children:[/* @__PURE__ */ (0,v.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,v.jsx)(`dd`,{className:`truncate tabular-nums`,children:t})]},e):null)}),i.length?/* @__PURE__ */ (0,v.jsx)(C,{title:`Last events, newest first`,children:/* @__PURE__ */ (0,v.jsx)(`ul`,{className:`flex flex-col gap-0.5 font-mono text-2xs`,children:i.map(({type:e,count:t,at:n})=>/* @__PURE__ */ (0,v.jsxs)(`li`,{className:`flex min-w-0 gap-2`,children:[/* @__PURE__ */ (0,v.jsx)(`span`,{className:`min-w-0 truncate`,title:e,children:d(e)}),t>1?/* @__PURE__ */ (0,v.jsxs)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,children:[`×`,t]}):null]},n))})}):null,/* @__PURE__ */ (0,v.jsx)(C,{title:`Processors (${String(e.processors.length)})`,children:e.processors.length?/* @__PURE__ */ (0,v.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.processors.map(e=>/* @__PURE__ */ (0,v.jsx)(g,{variant:`secondary`,className:`text-2xs`,children:e},e))}):/* @__PURE__ */ (0,v.jsx)(`p`,{className:`text-muted-foreground`,children:`None.`})}),/* @__PURE__ */ (0,v.jsxs)(C,{title:`Event types (${String(n.length)})`,children:[/* @__PURE__ */ (0,v.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:r.map(([e,t])=>/* @__PURE__ */ (0,v.jsxs)(`li`,{className:`flex min-w-0 gap-2`,children:[/* @__PURE__ */ (0,v.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,title:e,children:d(e)}),/* @__PURE__ */ (0,v.jsx)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,children:t})]},e))}),r.length<n.length?/* @__PURE__ */ (0,v.jsxs)(`p`,{className:`text-muted-foreground`,children:[String(n.length-r.length),` more types.`]}):null]}),e.metadata?/* @__PURE__ */ (0,v.jsx)(C,{title:`Metadata`,children:/* @__PURE__ */ (0,v.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted p-2 text-2xs`,children:JSON.stringify(e.metadata,null,2)})}):null]})}function C({title:e,children:t}){return/* @__PURE__ */ (0,v.jsxs)(`section`,{className:`flex flex-col gap-1`,children:[/* @__PURE__ */ (0,v.jsx)(`h3`,{className:`text-2xs font-medium tracking-wide text-muted-foreground uppercase`,children:e}),t]})}export{S as n,y as r,b as t};
M dist/chunks/context-catalog-list.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{A as r,C as i,Dt as a,Ft as o,G as s,Nt as c,Q as l,Rt as u,Ut as d,_ as f,_t as p,at as m,bt as h,c as g,ft as _,g as v,lt as y,m as b,mt as x,rt as S,vt as C,x as w,yt as T}from"./vendor-icons";import{i as ee,p as te,t as ne}from"./agent-summary.mjs";import{c as E,r as re}from"./ui-base";import{H as ie,V as ae,W as oe}from"./ui-shell";import{Popover as se,PopoverContent as ce,PopoverTrigger as le}from"../components/ui/popover";import{plainLeftClick as ue}from"../lib/plain-left-click";import{ContextPathText as D}from"../components/context-path-text";import{n as O,t as de}from"./agent-look.mjs";import{t as k}from"./esm.mjs";import{D as A,E as j,O as M,a as N,c as fe,h as pe,i as P,m as me,o as he,s as ge,u as F,v as I}from"./context-catalog-rows.mjs";import{pxPerRem as L}from"../lib/px-per-rem";import{ListRowText as _e}from"../components/list-row-text";var R=/* @__PURE__ */ e(t(),1),z=/* @__PURE__ */ e(n(),1);function B(e,t){let[n,r]=(0,R.useState)(()=>Date.now()),i=t??n,a=(0,R.useMemo)(()=>j(e,i),[e,i]);return(0,R.useEffect)(()=>{if(t!==void 0||!e||e.length===0)return;let n=Date.now(),i=1/0,a=!1;for(let t of e){if(!t.expiresAt)continue;let e=Date.parse(t.expiresAt);Number.isFinite(e)&&(e<=n?a=!0:e<i&&(i=e))}if(a){r(n);return}if(!Number.isFinite(i))return;let o=Math.min(Math.max(1,i-n+5),2147483647),s=setTimeout(()=>r(Date.now()),o);return()=>clearTimeout(s)},[e,t,n]),a}const V=(0,R.memo)(function({activities:e,nowMs:t,mode:n=`pill`,compact:r=!1,status:i,faviconForHost:a,onOpenPath:o,className:s}){let c=B(e,t),l=t??Date.now(),u=i?.text&&i.text!==`Idle`?i:void 0;return c.length===0?n===`lip`&&u?/* @__PURE__ */ (0,z.jsx)(ve,{status:u,className:s}):null:n===`inline`?/* @__PURE__ */ (0,z.jsx)(ye,{active:c,faviconForHost:a,className:s}):/* @__PURE__ */ (0,z.jsx)(be,{active:c,givenNowMs:t,nowMs:l,mode:n,compact:r,visibleStatus:u,faviconForHost:a,onOpenPath:o,className:s})});function ve({status:e,className:t}){return/* @__PURE__ */ (0,z.jsxs)(`div`,{"data-slot":`agent-foot-status`,"data-composer-lip":`status`,"data-status":e.tone,title:e.detail,className:E(`flex h-5 min-w-0 items-center gap-1.5 text-2xs text-muted-foreground`,t),children:[/* @__PURE__ */ (0,z.jsx)(H,{tone:e.tone}),/* @__PURE__ */ (0,z.jsx)(`span`,{className:E(`truncate`,e.tone===`live`&&`shimmer`),children:e.text})]})}function H({tone:e}){return/* @__PURE__ */ (0,z.jsx)(h,{className:E(`size-1.5 shrink-0`,e===`live`&&`animate-pulse fill-success text-success`,e===`amber`&&`fill-warning text-warning`,e===`muted`&&`fill-muted-foreground/40 text-muted-foreground/40`)})}function ye({active:e,faviconForHost:t,className:n}){let r=e[0],i=G(e,t).slice(0,3);return/* @__PURE__ */ (0,z.jsxs)(`span`,{"data-slot":`context-activity-inline`,className:E(`inline-flex min-w-0 items-center gap-1.5 text-2xs text-foreground/90`,n),children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`inline-flex shrink-0 -space-x-1`,children:i.map(e=>/* @__PURE__ */ (0,z.jsx)(W,{item:e,faviconForHost:t,className:`size-3.5 ring-1 ring-background`},e.key))}),/* @__PURE__ */ (0,z.jsx)(`span`,{className:`shimmer min-w-0 truncate`,children:r.text}),e.length>1?/* @__PURE__ */ (0,z.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap rounded-full bg-muted px-1.5 text-2xs text-muted-foreground tabular-nums`,children:[`+`,e.length-1]}):null]})}function be({active:e,givenNowMs:t,nowMs:n,mode:r,compact:i,visibleStatus:a,faviconForHost:o,onOpenPath:s,className:c}){let[l,u]=(0,R.useState)(!1),[d,f]=(0,R.useState)(!1),p=Oe(e.length>1&&!d&&!l),m=e.length>1?p%e.length:0,h=e[m],g=(0,R.useMemo)(()=>G(e,o).slice(0,3),[e,o]),_=ke(t===void 0&&l&&e.some(e=>!!(e.pushedAt||e.expiresAt))),v=t??(l?_:n);return/* @__PURE__ */ (0,z.jsxs)(se,{open:l,onOpenChange:u,children:[/* @__PURE__ */ (0,z.jsx)(le,{render:/* @__PURE__ */ (0,z.jsx)(xe,{mode:r,compact:i,open:l,activeCount:e.length,currentIndex:m,current:h,stackPreview:g,visibleStatus:a,faviconForHost:o,onHoverChange:f,className:c})}),/* @__PURE__ */ (0,z.jsx)(ce,{align:`start`,className:`flex max-h-80 w-[min(24rem,calc(100vw-1.5rem))] flex-col gap-2 overflow-y-auto p-2.5 text-xs`,children:/* @__PURE__ */ (0,z.jsx)(Se,{active:e,visibleStatus:a,nowMs:v,faviconForHost:o,onNavigate:s?e=>{u(!1),s(e)}:void 0})})]})}function xe({mode:e,compact:t,open:n,activeCount:r,currentIndex:i,current:o,stackPreview:s,visibleStatus:c,faviconForHost:l,onHoverChange:u,className:d,...f}){let p=e===`lip`,m=c?.text.replace(/^Thinking\s*·\s*/i,``);return/* @__PURE__ */ (0,z.jsxs)(`button`,{...f,type:`button`,"data-slot":`context-activity-pill`,"data-composer-lip":p?`stack`:void 0,onMouseEnter:e=>{f.onMouseEnter?.(e),u(!0)},onMouseLeave:e=>{f.onMouseLeave?.(e),u(!1)},"aria-label":`Active stack: ${String(r)} ${r===1?`activity`:`activities`}`,className:E(p?`group flex h-5 w-full min-w-0 items-center gap-2 text-left text-2xs text-foreground/90 transition-colors hover:text-foreground`:`group inline-flex h-7 max-w-full min-w-0 items-center gap-1.5 rounded-full border border-border/80 bg-background/95 px-2.5 text-xs text-foreground shadow-2xs transition-colors hover:bg-muted/70`,t&&!p&&`h-6 px-2 text-2xs shadow-none`,d),children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`inline-flex shrink-0 items-center -space-x-1.5`,"data-slot":`activity-icon-stack`,children:s.map(e=>/* @__PURE__ */ (0,z.jsx)(W,{item:e,faviconForHost:l,className:p||t?`size-3.5 ring-1 ring-background`:`size-4 ring-2 ring-background`},e.key))}),/* @__PURE__ */ (0,z.jsx)(`span`,{"data-slot":`activity-ticker-item`,className:`shimmer min-w-0 flex-1 truncate font-medium`,children:o.text},o.key),p&&c?/* @__PURE__ */ (0,z.jsxs)(`span`,{"data-slot":`agent-foot-status`,"data-status":c.tone,title:c.text,className:`inline-flex shrink-0 items-center gap-1 whitespace-nowrap font-mono text-2xs text-muted-foreground`,children:[/* @__PURE__ */ (0,z.jsx)(H,{tone:c.tone}),/* @__PURE__ */ (0,z.jsx)(`span`,{className:`max-w-28 truncate`,children:m})]}):null,r>1?/* @__PURE__ */ (0,z.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap font-mono text-2xs text-muted-foreground tabular-nums`,children:[i+1,`/`,r]}):null,/* @__PURE__ */ (0,z.jsx)(a,{"aria-hidden":!0,className:E(`size-3 shrink-0 text-muted-foreground transition-transform`,n&&`rotate-180`)})]})}function Se({active:e,visibleStatus:t,nowMs:n,faviconForHost:r,onNavigate:i}){return/* @__PURE__ */ (0,z.jsxs)(z.Fragment,{children:[/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-1`,children:[/* @__PURE__ */ (0,z.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-medium text-foreground`,children:[/* @__PURE__ */ (0,z.jsx)(l,{className:`size-3.5 text-muted-foreground`,"aria-hidden":!0}),`Active work (`,e.length,`)`]}),t?/* @__PURE__ */ (0,z.jsx)(`span`,{className:`truncate text-2xs text-muted-foreground`,children:t.text}):null]}),/* @__PURE__ */ (0,z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,"data-slot":`activity-stack-list`,children:e.map(e=>/* @__PURE__ */ (0,z.jsx)(Ce,{item:e,nowMs:n,faviconForHost:r,onNavigate:i},e.key))})]})}function Ce({item:e,nowMs:t,faviconForHost:n,onNavigate:r}){let i=Ee(e.pushedAt,t),a=De(e.expiresAt,t),o=i||a,s=we(e);return/* @__PURE__ */ (0,z.jsxs)(`li`,{"data-activity-key":e.key,className:`flex min-w-0 items-center gap-2 rounded-md px-2 py-1.5 transition-colors hover:bg-muted/60`,children:[/* @__PURE__ */ (0,z.jsx)(W,{item:e,faviconForHost:n,className:`size-4 shrink-0`}),/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-baseline gap-2`,children:[/* @__PURE__ */ (0,z.jsx)(U,{item:e,onNavigate:r}),s?/* @__PURE__ */ (0,z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-2xs text-muted-foreground`,children:s}):null]}),o?/* @__PURE__ */ (0,z.jsx)(`span`,{title:e.expiresAt?`Expires at ${e.expiresAt}`:e.pushedAt?`Started at ${e.pushedAt}`:void 0,className:`shrink-0 font-mono text-2xs text-muted-foreground tabular-nums`,children:o}):null]})}function we(e){if(e.url){if(e.url.startsWith(`/`))return e.url;try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return}}}function U({item:e,onNavigate:t}){if(e.url?.startsWith(`/`)&&t){let n=e.url;return/* @__PURE__ */ (0,z.jsx)(`button`,{type:`button`,onClick:()=>t(n),className:`truncate text-left font-medium hover:underline`,children:e.text})}return e.url&&/^https?:\/\//i.test(e.url)?/* @__PURE__ */ (0,z.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex min-w-0 items-center gap-1 truncate font-medium hover:underline`,children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`truncate`,children:e.text}),/* @__PURE__ */ (0,z.jsx)(_,{className:`size-3 shrink-0 text-muted-foreground`,"aria-hidden":!0})]}):/* @__PURE__ */ (0,z.jsx)(`span`,{className:`truncate font-medium`,children:e.text})}function W({item:e,faviconForHost:t,className:n}){let r=A(e,t),[i,a]=(0,R.useState)();if(r&&i!==r)return/* @__PURE__ */ (0,z.jsx)(`span`,{className:E(`inline-flex items-center justify-center overflow-hidden rounded-full bg-background`,n),children:/* @__PURE__ */ (0,z.jsx)(`img`,{src:r,alt:``,className:`size-full object-contain`,onError:()=>a(r)})});let o=M(e);if(o.kind===`emoji`)return/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,className:E(`inline-flex items-center justify-center rounded-full bg-background text-2xs leading-none`,n),children:o.glyph});let s=Te[o.kind];return/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,className:E(`inline-flex items-center justify-center rounded-full bg-background text-muted-foreground`,n),children:/* @__PURE__ */ (0,z.jsx)(s,{className:`size-2.5`})})}const Te={agent:o,claude:b,mcp:u,code:C,search:i,web:S};function G(e,t){let n=/* @__PURE__ */ new Set,r=[];for(let i of e){let e=A(i,t)||JSON.stringify(M(i));n.has(e)||(n.add(e),r.push(i))}return r}function Ee(e,t){if(!e)return null;let n=Math.floor((t-Date.parse(e))/1e3);if(!Number.isFinite(n)||n<0)return null;if(n<60)return`${String(n)}s`;let r=Math.floor(n/60),i=n%60;return r<60?i===0?`${String(r)}m`:`${String(r)}m ${String(i).padStart(2,`0`)}s`:`${String(Math.floor(r/60))}h ${String(r%60).padStart(2,`0`)}m`}function De(e,t){if(!e)return null;let n=Math.ceil((Date.parse(e)-t)/1e3);return!Number.isFinite(n)||n<=0?null:n<60?`${String(n)}s`:`${String(Math.ceil(n/60))}m`}function Oe(e){let[t,n]=(0,R.useState)(0);return(0,R.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(e=>e+1),2200);return()=>clearInterval(t)},[e]),t}function ke(e){let[t,n]=(0,R.useState)(()=>Date.now());return(0,R.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),t}const K={bot:o,agent:o,bug:c,cloud:T,compass:p,terminal:b,cli:b,code:C,"git-branch":m,git:m,repo:m,globe:S,web:S,database:x,db:x,shield:f,security:f,audit:f,sparkles:v,mail:s,email:s,phone:r,call:r,"file-text":y,doc:y,docs:y,layers:l,activity:d,users:g,settings:w},Ae={xs:`size-4 rounded-[5px]`,sm:`size-5 rounded-md bg-muted/60 ring-1 ring-border/75`,md:`size-7 rounded-lg bg-muted/60 ring-1 ring-border/75`,lg:`size-9 rounded-xl bg-muted/60 ring-1 ring-border/75`,xl:`size-11 rounded-xl bg-muted/60 ring-1 ring-border/75`};function je(e,t){return t?t===`working`?e===`xs`?`bg-success/12 text-success ring-1 ring-success/75 shadow-xs shadow-success/35`:`bg-success/10 text-success ring-[1.5px] ring-success/75 shadow-sm shadow-success/35`:t===`waiting`?e===`xs`?`bg-warning/12 text-warning ring-1 ring-warning/80 shadow-xs shadow-warning/35`:`bg-warning/12 text-warning ring-[1.5px] ring-warning/80 shadow-sm shadow-warning/35`:t===`ended`?e===`xs`?`opacity-65`:`bg-muted/35 ring-border/50 opacity-75`:``:``}const Me={xs:`size-4`,sm:`size-3.5`,md:`size-4`,lg:`size-5`,xl:`size-6`},Ne={xs:`text-xs leading-none`,sm:`text-xs leading-none`,md:`text-sm leading-none`,lg:`text-lg leading-none`,xl:`text-xl leading-none`},Pe={xs:`size-2 -right-0.5 -bottom-0.5 ring-2 ring-sidebar`,sm:`size-2 -right-0.5 -bottom-0.5 ring-2 ring-background`,md:`size-2.5 -right-0.5 -bottom-0.5 ring-2 ring-background`,lg:`size-3 -right-0.5 -bottom-0.5 ring-2 ring-background`,xl:`size-3.5 -right-0.5 -bottom-0.5 ring-2 ring-background`},Fe={xs:`size-2.5 -right-1 -bottom-1`,sm:`size-3 -right-1 -bottom-1`,md:`size-3.5 -right-1 -bottom-1`,lg:`size-4 -right-1 -bottom-1`,xl:`size-5 -right-1 -bottom-1`};function Ie(e){return e.startsWith(`http://`)||e.startsWith(`https://`)||e.startsWith(`/`)||e.startsWith(`data:image/`)}function q(e,t,n){return e?.status?e.status:t?.awake||n?`working`:null}function Le(e){if(!e)return;let t=e.toLowerCase();if(t.includes(`engineering-manager`)||t.includes(`coordinator`))return p;if(t.includes(`sysadmin`)||t.includes(`deploy`)||t.includes(`ops`))return b;if(t.includes(`error`)||t.includes(`bug`)||t.includes(`crash`)||t.includes(`fix`))return c;if(t.includes(`audit`)||t.includes(`security`)||t.includes(`smoke`)||t.includes(`vault`)||t.includes(`passkey`)||t.includes(`verified`)||t.includes(`oauth`))return f;if(t.includes(`cloud`)||t.includes(`zone`)||t.includes(`rollout`)||t.includes(`gateway`))return T;if(t.includes(`standup`)||t.includes(`slack`)||t.includes(`member`))return g;if(t.includes(`r2`)||t.includes(`d1`)||t.includes(`sqlite`)||t.includes(`db`))return x;if(t.includes(`note`)||t.includes(`doc`)||t.includes(`task`))return y}function Re(e,t,n){if(e&&e.kind&&e.kind!==`agent`)return O(e.kind);let i=Le(n);if(i)return i;if(e)return O(e.kind);let a=t?.processors||[];return a.includes(`repo`)||n?.startsWith(`/repos/`)?m:a.includes(`call`)?r:a.includes(`email`)?s:a.includes(`agent`)||n?.startsWith(`/agents/`)?o:n?.startsWith(`/audit`)?f:l}function J({path:e,icon:t,row:n,agent:r,activities:i,subagentCount:a,size:o=`md`,showStatus:s=!0,showActivityBadge:c,showTooltip:l=!1,faviconForHost:u,nowMs:d=Date.now(),className:f}){let p=e||r?.path||n?.path,m=(t||he(n))?.trim()||void 0,h=X(i,n,d),g=q(r,n,h.length>0),_=h[0],v=c??(o!==`xs`&&o!==`sm`),y=/* @__PURE__ */ (0,z.jsxs)(`span`,{"data-slot":`context-icon`,"data-size":o,"data-context-status":g||void 0,className:E(`relative inline-flex shrink-0 items-center justify-center transition-shadow select-none`,Ae[o],s&&je(o,g),f),children:[/* @__PURE__ */ (0,z.jsx)(ze,{resolvedIcon:m,agent:r,row:n,path:p,size:o,tinted:s&&(g===`working`||g===`waiting`)}),/* @__PURE__ */ (0,z.jsx)(Be,{size:o,topActivity:v?_:void 0,status:s?g:null,faviconForHost:u})]});return l?/* @__PURE__ */ (0,z.jsxs)(ae,{children:[/* @__PURE__ */ (0,z.jsx)(oe,{render:/* @__PURE__ */ (0,z.jsx)(`span`,{className:`inline-flex shrink-0`}),children:y}),/* @__PURE__ */ (0,z.jsx)(ie,{side:`right`,align:`center`,className:`p-2.5`,children:/* @__PURE__ */ (0,z.jsx)(Y,{path:p,icon:t,row:n,agent:r,activities:h,subagentCount:a,faviconForHost:u,nowMs:d})})]}):y}function ze({resolvedIcon:e,agent:t,row:n,path:r,size:i,tinted:a=!1}){let[o,s]=(0,R.useState)(null),c=E(Me[i],!a&&i!==`xs`&&`text-foreground/85`);if(e&&Ie(e)&&o!==e)return/* @__PURE__ */ (0,z.jsx)(`img`,{src:e,alt:``,"aria-hidden":!0,onError:()=>s(e),className:E(`object-cover`,i===`xs`?`size-4 rounded-sm`:`size-full rounded-[inherit]`)});let l=e?.toLowerCase(),u=l&&Object.hasOwn(K,l)?K[l]:void 0;if(u)return/* @__PURE__ */ (0,z.jsx)(u,{className:c});if(e)return/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,className:Ne[i],children:e});let d=Re(t,n,r);return/* @__PURE__ */ (0,z.jsx)(d,{"data-agent-kind":t?.kind||void 0,className:c})}function Be({size:e,topActivity:t,status:n,faviconForHost:r}){return t?/* @__PURE__ */ (0,z.jsx)(`span`,{"data-slot":`context-icon-activity`,title:t.text,className:E(`pointer-events-none absolute inline-flex items-center justify-center rounded-full bg-background ring-1 ring-background`,Fe[e]),children:/* @__PURE__ */ (0,z.jsx)(W,{item:t,faviconForHost:r,className:`size-full`})}):n?/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,"data-agent-status":n,title:n,className:E(`pointer-events-none absolute rounded-full`,Pe[e],de[n])}):null}function Y({path:e,icon:t,row:n,agent:r,activities:i,subagentCount:a=0,line:o,faviconForHost:s,nowMs:c=Date.now()}){let l=X(i,n,c),{path:u,title:d,status:f}=Ve({givenPath:e,row:n,agent:r,hasActiveStack:l.length>0}),p=He(o,a,r,c),m=n?Ue(n,c):null;return/* @__PURE__ */ (0,z.jsxs)(`div`,{"data-agent-tooltip":!0,"data-slot":`context-icon-tooltip`,className:`flex max-w-72 min-w-48 flex-col gap-1.5 text-xs`,children:[/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[/* @__PURE__ */ (0,z.jsx)(J,{path:u,icon:t,row:n,agent:r,activities:l,size:`md`,faviconForHost:s,nowMs:c}),/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:d}),f?/* @__PURE__ */ (0,z.jsx)(`span`,{className:`shrink-0 rounded bg-background/20 px-1 py-0.5 font-mono text-2xs opacity-80`,children:f}):null]}),/* @__PURE__ */ (0,z.jsx)(D,{path:u,truncate:!0,className:`text-2xs opacity-70`})]})]}),p?/* @__PURE__ */ (0,z.jsx)(`div`,{className:`truncate text-2xs opacity-85`,children:p}):null,l.length>0?/* @__PURE__ */ (0,z.jsx)(`div`,{className:`rounded bg-background/15 px-1.5 py-1`,children:/* @__PURE__ */ (0,z.jsx)(V,{activities:l,nowMs:c,mode:`inline`,faviconForHost:s,className:`text-background`})}):null,n?.description?/* @__PURE__ */ (0,z.jsx)(`p`,{className:`m-0 line-clamp-2 text-2xs opacity-75`,children:n.description}):null,m?/* @__PURE__ */ (0,z.jsx)(`div`,{className:`font-mono text-2xs opacity-65`,children:m}):null]})}function X(e,t,n){return e?j(e,n):N(t,n)}function Ve({givenPath:e,row:t,agent:n,hasActiveStack:r}){let i=e||n?.path||t?.path||`/`;return{path:i,title:t&&F(t)||n&&ee(n)||i.split(`/`).filter(Boolean).at(-1)||i,status:q(n,t,r)}}function He(e,t,n,r){return e||[te(t),n?ne(n,r):null].filter(Boolean).join(` · `)||null}function Ue(e,t){let n=I(P(e),t);return[e.processors.length>0?e.processors.join(` · `):null,`${String(e.eventCount)} ${e.eventCount===1?`event`:`events`}`,e.storageBytes===void 0?null:pe(e.storageBytes),e.awake?`awake`:n?`${n} ago`:null].filter(Boolean).join(` · `)}function Z({path:e,links:t,className:n,children:r,...i}){let a=t.hrefOf(e);return/* @__PURE__ */ (0,z.jsx)(`a`,{href:a,className:n,onClick:e=>{e.stopPropagation(),t.onNavigate&&ue(e)&&t.onNavigate(a,e)},...i,children:r})}function We({path:e,links:t,className:n}){let r=e.split(`/`).filter(Boolean);return/* @__PURE__ */ (0,z.jsx)(`nav`,{"aria-label":`Context path`,className:E(`min-w-0 text-sm`,n),children:/* @__PURE__ */ (0,z.jsxs)(D,{path:e,children:[r.length===0?/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-current":`page`,children:`/`}):null,r.map((e,n)=>{let i=`/${r.slice(0,n+1).join(`/`)}`;return n===r.length-1?/* @__PURE__ */ (0,z.jsxs)(`span`,{"aria-current":`page`,children:[`/`,e]},i):/* @__PURE__ */ (0,z.jsxs)(Z,{path:i,links:t,className:`hover:underline`,children:[`/`,e]},i)})]})})}function Ge({rows:e,current:t,links:n,className:r}){let[i,a]=(0,R.useState)(``),o=qe(5e3),s=me(e||[],i);return/* @__PURE__ */ (0,z.jsxs)(`nav`,{"aria-label":`Recent contexts`,className:E(`flex min-h-0 flex-col gap-1.5`,r),children:[/* @__PURE__ */ (0,z.jsx)(re,{"aria-label":`Filter contexts`,placeholder:`Filter by path, description, event type…`,className:`h-8 text-xs md:text-xs`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(``)}}),/* @__PURE__ */ (0,z.jsx)(Q,{rows:s,current:t,links:n,nowMs:o}),/* @__PURE__ */ (0,z.jsx)(`p`,{className:`px-2 text-2xs text-muted-foreground`,children:e?i.trim()?`${String(s.length)} of ${String(e.length)} contexts`:`${String(e.length)} contexts, ${String(e.filter(e=>e.awake).length)} awake`:`Loading contexts…`})]})}function Q({rows:e,current:t,links:n,nowMs:r}){let i=(0,R.useRef)(null),[a]=(0,R.useState)(L),o=k({count:e.length,getScrollElement:()=>i.current,estimateSize:t=>$(e[t])*a,getItemKey:t=>e[t].path,overscan:12});return/* @__PURE__ */ (0,z.jsx)(`div`,{ref:i,className:`min-h-0 flex-1 overflow-y-auto text-xs`,children:/* @__PURE__ */ (0,z.jsx)(`ul`,{className:`relative w-full`,style:{height:o.getTotalSize()},children:o.getVirtualItems().map(i=>/* @__PURE__ */ (0,z.jsx)(`li`,{className:`absolute top-0 left-0 w-full`,style:{height:`${String($(e[i.index]))}rem`,transform:`translateY(${String(i.start)}px)`},children:/* @__PURE__ */ (0,z.jsx)(Ke,{row:e[i.index],current:t,links:n,nowMs:r})},i.key))})})}function Ke({row:e,current:t,links:n,nowMs:r}){let i=P(e),a=N(e,r);return/* @__PURE__ */ (0,z.jsx)(Z,{path:e.path,links:n,"aria-current":e.path===t?`page`:void 0,className:`flex h-full min-w-0 flex-col justify-center rounded-md px-2 hover:bg-muted/60 aria-[current=page]:bg-muted`,children:/* @__PURE__ */ (0,z.jsxs)(`span`,{className:`flex min-w-0 items-start gap-2`,children:[/* @__PURE__ */ (0,z.jsx)(J,{row:e,activities:a,size:`sm`,showTooltip:!0,nowMs:r,className:`mt-0.5`}),/* @__PURE__ */ (0,z.jsx)(_e,{title:F(e),path:e.path,line:a.length>0?/* @__PURE__ */ (0,z.jsx)(V,{activities:a,nowMs:r,mode:`inline`}):fe(e)||`${String(e.eventCount)} events`,className:`text-foreground/90`,time:/* @__PURE__ */ (0,z.jsx)(`time`,{dateTime:i,title:i,className:`shrink-0 text-2xs text-muted-foreground tabular-nums`,children:e.awake||a.length>0?`awake`:I(i,r)})})]})})}function $(e){return F(e)?3.75:2.75}function qe(e){let[t,n]=(0,R.useState)(()=>Date.now());return(0,R.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function Je(e,{of:t,pollMs:n=1e4}){let[r,i]=(0,R.useState)({}),a=(0,R.useEffectEvent)(async()=>{if(e&&document.visibilityState===`visible`)try{let n=ge(await e());i({of:t,rows:n})}catch(e){let n=e instanceof Error?e.message:String(e);i(e=>({of:t,rows:e.of===t?e.rows:void 0,error:n}))}}),o=!!e;return(0,R.useEffect)(()=>{if(!o)return;a();let e=setInterval(()=>void a(),n),t=()=>void a();return document.addEventListener(`visibilitychange`,t),()=>{clearInterval(e),document.removeEventListener(`visibilitychange`,t)}},[o,t,n]),r.of===t?{rows:r.rows,error:r.error}:{rows:void 0,error:void 0}}export{Z as a,W as c,We as i,V as l,Q as n,J as o,Je as r,Y as s,Ge as t,B as u}; +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{$ as r,A as i,C as a,It as o,K as s,Ot as c,Pt as l,Wt as u,_ as d,bt as f,c as p,g as m,ht as h,it as g,m as _,ot as v,pt as y,ut as b,vt as x,x as S,xt as ee,yt as C,zt as te}from"./vendor-icons";import{i as ne,p as re,t as ie}from"./agent-summary.mjs";import{c as w,r as ae}from"./ui-base";import{H as oe,V as se,W as T}from"./ui-shell";import{Popover as ce,PopoverContent as le,PopoverTrigger as ue}from"../components/ui/popover";import{plainLeftClick as de}from"../lib/plain-left-click";import{ContextPathText as E}from"../components/context-path-text";import{n as D,t as fe}from"./agent-look.mjs";import{D as O,E as k,O as A,a as j,c as pe,h as me,i as M,m as he,o as ge,s as N,u as P,v as F}from"./context-catalog-rows.mjs";import{t as I}from"./esm.mjs";import{pxPerRem as L}from"../lib/px-per-rem";import{ListRowText as _e}from"../components/list-row-text";var R=/* @__PURE__ */ e(t(),1),z=/* @__PURE__ */ e(n(),1);function B(e,t){let[n,r]=(0,R.useState)(()=>Date.now()),i=t??n,a=(0,R.useMemo)(()=>k(e,i),[e,i]);return(0,R.useEffect)(()=>{if(t!==void 0||!e||e.length===0)return;let n=Date.now(),i=1/0,a=!1;for(let t of e){if(!t.expiresAt)continue;let e=Date.parse(t.expiresAt);Number.isFinite(e)&&(e<=n?a=!0:e<i&&(i=e))}if(a){r(n);return}if(!Number.isFinite(i))return;let o=Math.min(Math.max(1,i-n+5),2147483647),s=setTimeout(()=>r(Date.now()),o);return()=>clearTimeout(s)},[e,t,n]),a}const V=(0,R.memo)(function({activities:e,nowMs:t,mode:n=`pill`,compact:r=!1,status:i,faviconForHost:a,onOpenPath:o,className:s}){let c=B(e,t),l=t??Date.now(),u=i?.text&&i.text!==`Idle`?i:void 0;return c.length===0?n===`lip`&&u?/* @__PURE__ */ (0,z.jsx)(ve,{status:u,className:s}):null:n===`inline`?/* @__PURE__ */ (0,z.jsx)(ye,{active:c,faviconForHost:a,className:s}):/* @__PURE__ */ (0,z.jsx)(be,{active:c,givenNowMs:t,nowMs:l,mode:n,compact:r,visibleStatus:u,faviconForHost:a,onOpenPath:o,className:s})});function ve({status:e,className:t}){return/* @__PURE__ */ (0,z.jsxs)(`div`,{"data-slot":`agent-foot-status`,"data-composer-lip":`status`,"data-status":e.tone,title:e.detail,className:w(`flex h-5 min-w-0 items-center gap-1.5 text-2xs text-muted-foreground`,t),children:[/* @__PURE__ */ (0,z.jsx)(H,{tone:e.tone}),/* @__PURE__ */ (0,z.jsx)(`span`,{className:w(`truncate`,e.tone===`live`&&`shimmer`),children:e.text})]})}function H({tone:e}){return/* @__PURE__ */ (0,z.jsx)(ee,{className:w(`size-1.5 shrink-0`,e===`live`&&`animate-pulse fill-success text-success`,e===`amber`&&`fill-warning text-warning`,e===`muted`&&`fill-muted-foreground/40 text-muted-foreground/40`)})}function ye({active:e,faviconForHost:t,className:n}){let r=e[0],i=G(e,t).slice(0,3);return/* @__PURE__ */ (0,z.jsxs)(`span`,{"data-slot":`context-activity-inline`,className:w(`inline-flex min-w-0 items-center gap-1.5 text-2xs text-foreground/90`,n),children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`inline-flex shrink-0 -space-x-1`,children:i.map(e=>/* @__PURE__ */ (0,z.jsx)(U,{item:e,faviconForHost:t,className:`size-3.5 ring-1 ring-background`},e.key))}),/* @__PURE__ */ (0,z.jsx)(`span`,{className:`shimmer min-w-0 truncate`,children:r.text}),e.length>1?/* @__PURE__ */ (0,z.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap rounded-full bg-muted px-1.5 text-2xs text-muted-foreground tabular-nums`,children:[`+`,e.length-1]}):null]})}function be({active:e,givenNowMs:t,nowMs:n,mode:r,compact:i,visibleStatus:a,faviconForHost:o,onOpenPath:s,className:c}){let[l,u]=(0,R.useState)(!1),[d,f]=(0,R.useState)(!1),p=Oe(e.length>1&&!d&&!l),m=e.length>1?p%e.length:0,h=e[m],g=(0,R.useMemo)(()=>G(e,o).slice(0,3),[e,o]),_=ke(t===void 0&&l&&e.some(e=>!!(e.pushedAt||e.expiresAt))),v=t??(l?_:n);return/* @__PURE__ */ (0,z.jsxs)(ce,{open:l,onOpenChange:u,children:[/* @__PURE__ */ (0,z.jsx)(ue,{render:/* @__PURE__ */ (0,z.jsx)(xe,{mode:r,compact:i,open:l,activeCount:e.length,currentIndex:m,current:h,stackPreview:g,visibleStatus:a,faviconForHost:o,onHoverChange:f,className:c})}),/* @__PURE__ */ (0,z.jsx)(le,{align:`start`,className:`flex max-h-80 w-[min(24rem,calc(100vw-1.5rem))] flex-col gap-2 overflow-y-auto p-2.5 text-xs`,children:/* @__PURE__ */ (0,z.jsx)(Se,{active:e,visibleStatus:a,nowMs:v,faviconForHost:o,onNavigate:s?e=>{u(!1),s(e)}:void 0})})]})}function xe({mode:e,compact:t,open:n,activeCount:r,currentIndex:i,current:a,stackPreview:o,visibleStatus:s,faviconForHost:l,onHoverChange:u,className:d,...f}){let p=e===`lip`,m=s?.text.replace(/^Thinking\s*·\s*/i,``);return/* @__PURE__ */ (0,z.jsxs)(`button`,{...f,type:`button`,"data-slot":`context-activity-pill`,"data-composer-lip":p?`stack`:void 0,onMouseEnter:e=>{f.onMouseEnter?.(e),u(!0)},onMouseLeave:e=>{f.onMouseLeave?.(e),u(!1)},"aria-label":`Active stack: ${String(r)} ${r===1?`activity`:`activities`}`,className:w(p?`group flex h-5 w-full min-w-0 items-center gap-2 text-left text-2xs text-foreground/90 transition-colors hover:text-foreground`:`group inline-flex h-7 max-w-full min-w-0 items-center gap-1.5 rounded-full border border-border/80 bg-background/95 px-2.5 text-xs text-foreground shadow-2xs transition-colors hover:bg-muted/70`,t&&!p&&`h-6 px-2 text-2xs shadow-none`,d),children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`inline-flex shrink-0 items-center -space-x-1.5`,"data-slot":`activity-icon-stack`,children:o.map(e=>/* @__PURE__ */ (0,z.jsx)(U,{item:e,faviconForHost:l,className:p||t?`size-3.5 ring-1 ring-background`:`size-4 ring-2 ring-background`},e.key))}),/* @__PURE__ */ (0,z.jsx)(`span`,{"data-slot":`activity-ticker-item`,className:`shimmer min-w-0 flex-1 truncate font-medium`,children:a.text},a.key),p&&s?/* @__PURE__ */ (0,z.jsxs)(`span`,{"data-slot":`agent-foot-status`,"data-status":s.tone,title:s.text,className:`inline-flex shrink-0 items-center gap-1 whitespace-nowrap font-mono text-2xs text-muted-foreground`,children:[/* @__PURE__ */ (0,z.jsx)(H,{tone:s.tone}),/* @__PURE__ */ (0,z.jsx)(`span`,{className:`max-w-28 truncate`,children:m})]}):null,r>1?/* @__PURE__ */ (0,z.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap font-mono text-2xs text-muted-foreground tabular-nums`,children:[i+1,`/`,r]}):null,/* @__PURE__ */ (0,z.jsx)(c,{"aria-hidden":!0,className:w(`size-3 shrink-0 text-muted-foreground transition-transform`,n&&`rotate-180`)})]})}function Se({active:e,visibleStatus:t,nowMs:n,faviconForHost:r,onNavigate:i}){return/* @__PURE__ */ (0,z.jsxs)(z.Fragment,{children:[t?/* @__PURE__ */ (0,z.jsx)(`div`,{className:`px-2 pt-0.5 text-2xs text-muted-foreground`,children:t.text}):null,/* @__PURE__ */ (0,z.jsx)(`ul`,{className:`flex flex-col gap-0.5`,"data-slot":`activity-stack-list`,children:e.map(e=>/* @__PURE__ */ (0,z.jsx)(Ce,{item:e,nowMs:n,faviconForHost:r,onNavigate:i},e.key))})]})}function Ce({item:e,nowMs:t,faviconForHost:n,onNavigate:r}){let i=Ee(e.pushedAt,t),a=De(e.expiresAt,t),o=i||a,s=we(e);return/* @__PURE__ */ (0,z.jsxs)(`li`,{"data-activity-key":e.key,className:`flex min-w-0 items-center gap-2 rounded-md px-2 py-1.5 transition-colors hover:bg-muted/60`,children:[/* @__PURE__ */ (0,z.jsx)(U,{item:e,faviconForHost:n,className:`size-4 shrink-0`}),/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-baseline gap-2`,children:[/* @__PURE__ */ (0,z.jsx)(Te,{item:e,onNavigate:r}),s?/* @__PURE__ */ (0,z.jsx)(`span`,{className:`min-w-0 truncate font-mono text-2xs text-muted-foreground`,children:s}):null]}),o?/* @__PURE__ */ (0,z.jsx)(`span`,{title:e.expiresAt?`Expires at ${e.expiresAt}`:e.pushedAt?`Started at ${e.pushedAt}`:void 0,className:`shrink-0 font-mono text-2xs text-muted-foreground tabular-nums`,children:o}):null]})}function we(e){if(e.url){if(e.url.startsWith(`/`))return e.url;try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return}}}function Te({item:e,onNavigate:t}){if(e.url?.startsWith(`/`)&&t){let n=e.url;return/* @__PURE__ */ (0,z.jsx)(`button`,{type:`button`,onClick:()=>t(n),className:`truncate text-left font-medium hover:underline`,children:e.text})}return e.url&&/^https?:\/\//i.test(e.url)?/* @__PURE__ */ (0,z.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex min-w-0 items-center gap-1 truncate font-medium hover:underline`,children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`truncate`,children:e.text}),/* @__PURE__ */ (0,z.jsx)(y,{className:`size-3 shrink-0 text-muted-foreground`,"aria-hidden":!0})]}):/* @__PURE__ */ (0,z.jsx)(`span`,{className:`truncate font-medium`,children:e.text})}function U({item:e,faviconForHost:t,className:n}){let r=O(e,t),[i,a]=(0,R.useState)();if(r&&i!==r)return/* @__PURE__ */ (0,z.jsx)(`span`,{className:w(`inline-flex items-center justify-center overflow-hidden rounded-full bg-background`,n),children:/* @__PURE__ */ (0,z.jsx)(`img`,{src:r,alt:``,className:`size-full object-contain`,onError:()=>a(r)})});let o=A(e);if(o.kind===`emoji`)return/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,className:w(`inline-flex items-center justify-center rounded-full bg-background text-2xs leading-none`,n),children:o.glyph});let s=W[o.kind];return/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,className:w(`inline-flex items-center justify-center rounded-full bg-background text-muted-foreground`,n),children:/* @__PURE__ */ (0,z.jsx)(s,{className:`size-2.5`})})}const W={agent:o,claude:_,mcp:te,code:C,search:a,web:g};function G(e,t){let n=/* @__PURE__ */ new Set,r=[];for(let i of e){let e=O(i,t)||JSON.stringify(A(i));n.has(e)||(n.add(e),r.push(i))}return r}function Ee(e,t){if(!e)return null;let n=Math.floor((t-Date.parse(e))/1e3);if(!Number.isFinite(n)||n<0)return null;if(n<60)return`${String(n)}s`;let r=Math.floor(n/60),i=n%60;return r<60?i===0?`${String(r)}m`:`${String(r)}m ${String(i).padStart(2,`0`)}s`:`${String(Math.floor(r/60))}h ${String(r%60).padStart(2,`0`)}m`}function De(e,t){if(!e)return null;let n=Math.ceil((Date.parse(e)-t)/1e3);return!Number.isFinite(n)||n<=0?null:n<60?`${String(n)}s`:`${String(Math.ceil(n/60))}m`}function Oe(e){let[t,n]=(0,R.useState)(0);return(0,R.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(e=>e+1),2200);return()=>clearInterval(t)},[e]),t}function ke(e){let[t,n]=(0,R.useState)(()=>Date.now());return(0,R.useEffect)(()=>{if(!e)return;let t=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(t)},[e]),t}const K={bot:o,agent:o,bug:l,cloud:f,compass:x,terminal:_,cli:_,code:C,"git-branch":v,git:v,repo:v,globe:g,web:g,database:h,db:h,shield:d,security:d,audit:d,sparkles:m,mail:s,email:s,phone:i,call:i,"file-text":b,doc:b,docs:b,layers:r,activity:u,users:p,settings:S},Ae={xs:`size-4 rounded-[5px]`,sm:`size-5 rounded-md bg-muted/60 ring-1 ring-border/75`,md:`size-7 rounded-lg bg-muted/60 ring-1 ring-border/75`,lg:`size-9 rounded-xl bg-muted/60 ring-1 ring-border/75`,xl:`size-11 rounded-xl bg-muted/60 ring-1 ring-border/75`};function je(e,t){return t?t===`working`?e===`xs`?`bg-success/12 text-success ring-1 ring-success/75 shadow-xs shadow-success/35`:`bg-success/10 text-success ring-[1.5px] ring-success/75 shadow-sm shadow-success/35`:t===`waiting`?e===`xs`?`bg-warning/12 text-warning ring-1 ring-warning/80 shadow-xs shadow-warning/35`:`bg-warning/12 text-warning ring-[1.5px] ring-warning/80 shadow-sm shadow-warning/35`:t===`ended`?e===`xs`?`opacity-65`:`bg-muted/35 ring-border/50 opacity-75`:``:``}const Me={xs:`size-4`,sm:`size-3.5`,md:`size-4`,lg:`size-5`,xl:`size-6`},Ne={xs:`text-xs leading-none`,sm:`text-xs leading-none`,md:`text-sm leading-none`,lg:`text-lg leading-none`,xl:`text-xl leading-none`},Pe={xs:`size-2 -right-0.5 -bottom-0.5 ring-2 ring-sidebar`,sm:`size-2 -right-0.5 -bottom-0.5 ring-2 ring-background`,md:`size-2.5 -right-0.5 -bottom-0.5 ring-2 ring-background`,lg:`size-3 -right-0.5 -bottom-0.5 ring-2 ring-background`,xl:`size-3.5 -right-0.5 -bottom-0.5 ring-2 ring-background`},Fe={xs:`size-2.5 -right-1 -bottom-1`,sm:`size-3 -right-1 -bottom-1`,md:`size-3.5 -right-1 -bottom-1`,lg:`size-4 -right-1 -bottom-1`,xl:`size-5 -right-1 -bottom-1`};function Ie(e){return e.startsWith(`http://`)||e.startsWith(`https://`)||e.startsWith(`/`)||e.startsWith(`data:image/`)}function q(e,t,n){return e?.status?e.status:t?.awake||n?`working`:null}function Le(e){if(!e)return;let t=e.toLowerCase();if(t.includes(`engineering-manager`)||t.includes(`coordinator`))return x;if(t.includes(`sysadmin`)||t.includes(`deploy`)||t.includes(`ops`))return _;if(t.includes(`error`)||t.includes(`bug`)||t.includes(`crash`)||t.includes(`fix`))return l;if(t.includes(`audit`)||t.includes(`security`)||t.includes(`smoke`)||t.includes(`vault`)||t.includes(`passkey`)||t.includes(`verified`)||t.includes(`oauth`))return d;if(t.includes(`cloud`)||t.includes(`zone`)||t.includes(`rollout`)||t.includes(`gateway`))return f;if(t.includes(`standup`)||t.includes(`slack`)||t.includes(`member`))return p;if(t.includes(`r2`)||t.includes(`d1`)||t.includes(`sqlite`)||t.includes(`db`))return h;if(t.includes(`note`)||t.includes(`doc`)||t.includes(`task`))return b}function Re(e,t,n){if(e&&e.kind&&e.kind!==`agent`)return D(e.kind);let a=Le(n);if(a)return a;if(e)return D(e.kind);let c=t?.processors||[];return c.includes(`repo`)||n?.startsWith(`/repos/`)?v:c.includes(`call`)?i:c.includes(`email`)?s:c.includes(`agent`)||n?.startsWith(`/agents/`)?o:n?.startsWith(`/audit`)?d:r}function J({path:e,icon:t,row:n,agent:r,activities:i,subagentCount:a,size:o=`md`,showStatus:s=!0,showActivityBadge:c,showTooltip:l=!1,faviconForHost:u,nowMs:d=Date.now(),className:f}){let p=e||r?.path||n?.path,m=(t||ge(n))?.trim()||void 0,h=X(i,n,d),g=q(r,n,h.length>0),_=h[0],v=c??(o!==`xs`&&o!==`sm`),y=/* @__PURE__ */ (0,z.jsxs)(`span`,{"data-slot":`context-icon`,"data-size":o,"data-context-status":g||void 0,className:w(`relative inline-flex shrink-0 items-center justify-center transition-shadow select-none`,Ae[o],s&&je(o,g),f),children:[/* @__PURE__ */ (0,z.jsx)(ze,{resolvedIcon:m,agent:r,row:n,path:p,size:o,tinted:s&&(g===`working`||g===`waiting`)}),/* @__PURE__ */ (0,z.jsx)(Be,{size:o,topActivity:v?_:void 0,status:s?g:null,faviconForHost:u})]});return l?/* @__PURE__ */ (0,z.jsxs)(se,{children:[/* @__PURE__ */ (0,z.jsx)(T,{render:/* @__PURE__ */ (0,z.jsx)(`span`,{className:`inline-flex shrink-0`}),children:y}),/* @__PURE__ */ (0,z.jsx)(oe,{side:`right`,align:`center`,className:`p-2.5`,children:/* @__PURE__ */ (0,z.jsx)(Y,{path:p,icon:t,row:n,agent:r,activities:h,subagentCount:a,faviconForHost:u,nowMs:d})})]}):y}function ze({resolvedIcon:e,agent:t,row:n,path:r,size:i,tinted:a=!1}){let[o,s]=(0,R.useState)(null),c=w(Me[i],!a&&i!==`xs`&&`text-foreground/85`);if(e&&Ie(e)&&o!==e)return/* @__PURE__ */ (0,z.jsx)(`img`,{src:e,alt:``,"aria-hidden":!0,onError:()=>s(e),className:w(`object-cover`,i===`xs`?`size-4 rounded-sm`:`size-full rounded-[inherit]`)});let l=e?.toLowerCase(),u=l&&Object.hasOwn(K,l)?K[l]:void 0;if(u)return/* @__PURE__ */ (0,z.jsx)(u,{className:c});if(e)return/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,className:Ne[i],children:e});let d=Re(t,n,r);return/* @__PURE__ */ (0,z.jsx)(d,{"data-agent-kind":t?.kind||void 0,className:c})}function Be({size:e,topActivity:t,status:n,faviconForHost:r}){return t?/* @__PURE__ */ (0,z.jsx)(`span`,{"data-slot":`context-icon-activity`,title:t.text,className:w(`pointer-events-none absolute inline-flex items-center justify-center rounded-full bg-background ring-1 ring-background`,Fe[e]),children:/* @__PURE__ */ (0,z.jsx)(U,{item:t,faviconForHost:r,className:`size-full`})}):n?/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-hidden":!0,"data-agent-status":n,title:n,className:w(`pointer-events-none absolute rounded-full`,Pe[e],fe[n])}):null}function Y({path:e,icon:t,row:n,agent:r,activities:i,subagentCount:a=0,line:o,faviconForHost:s,nowMs:c=Date.now()}){let l=X(i,n,c),{path:u,title:d,status:f}=Ve({givenPath:e,row:n,agent:r,hasActiveStack:l.length>0}),p=He(o,a,r,c),m=n?Ue(n,c):null;return/* @__PURE__ */ (0,z.jsxs)(`div`,{"data-agent-tooltip":!0,"data-slot":`context-icon-tooltip`,className:`flex max-w-72 min-w-48 flex-col gap-1.5 text-xs`,children:[/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[/* @__PURE__ */ (0,z.jsx)(J,{path:u,icon:t,row:n,agent:r,activities:l,size:`md`,faviconForHost:s,nowMs:c}),/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[/* @__PURE__ */ (0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[/* @__PURE__ */ (0,z.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:d}),f?/* @__PURE__ */ (0,z.jsx)(`span`,{className:`shrink-0 rounded bg-background/20 px-1 py-0.5 font-mono text-2xs opacity-80`,children:f}):null]}),/* @__PURE__ */ (0,z.jsx)(E,{path:u,truncate:!0,className:`text-2xs opacity-70`})]})]}),p?/* @__PURE__ */ (0,z.jsx)(`div`,{className:`truncate text-2xs opacity-85`,children:p}):null,l.length>0?/* @__PURE__ */ (0,z.jsx)(`div`,{className:`rounded bg-background/15 px-1.5 py-1`,children:/* @__PURE__ */ (0,z.jsx)(V,{activities:l,nowMs:c,mode:`inline`,faviconForHost:s,className:`text-background`})}):null,n?.description?/* @__PURE__ */ (0,z.jsx)(`p`,{className:`m-0 line-clamp-2 text-2xs opacity-75`,children:n.description}):null,m?/* @__PURE__ */ (0,z.jsx)(`div`,{className:`font-mono text-2xs opacity-65`,children:m}):null]})}function X(e,t,n){return e?k(e,n):j(t,n)}function Ve({givenPath:e,row:t,agent:n,hasActiveStack:r}){let i=e||n?.path||t?.path||`/`;return{path:i,title:t&&P(t)||n&&ne(n)||i.split(`/`).filter(Boolean).at(-1)||i,status:q(n,t,r)}}function He(e,t,n,r){return e||[re(t),n?ie(n,r):null].filter(Boolean).join(` · `)||null}function Ue(e,t){let n=F(M(e),t);return[e.processors.length>0?e.processors.join(` · `):null,`${String(e.eventCount)} ${e.eventCount===1?`event`:`events`}`,e.storageBytes===void 0?null:me(e.storageBytes),e.awake?`awake`:n?`${n} ago`:null].filter(Boolean).join(` · `)}function Z({path:e,links:t,className:n,children:r,...i}){let a=t.hrefOf(e);return/* @__PURE__ */ (0,z.jsx)(`a`,{href:a,className:n,onClick:e=>{e.stopPropagation(),t.onNavigate&&de(e)&&t.onNavigate(a,e)},...i,children:r})}function We({path:e,links:t,className:n}){let r=e.split(`/`).filter(Boolean);return/* @__PURE__ */ (0,z.jsx)(`nav`,{"aria-label":`Context path`,className:w(`min-w-0 text-sm`,n),children:/* @__PURE__ */ (0,z.jsxs)(E,{path:e,children:[r.length===0?/* @__PURE__ */ (0,z.jsx)(`span`,{"aria-current":`page`,children:`/`}):null,r.map((e,n)=>{let i=`/${r.slice(0,n+1).join(`/`)}`;return n===r.length-1?/* @__PURE__ */ (0,z.jsxs)(`span`,{"aria-current":`page`,children:[`/`,e]},i):/* @__PURE__ */ (0,z.jsxs)(Z,{path:i,links:t,className:`hover:underline`,children:[`/`,e]},i)})]})})}function Ge({rows:e,current:t,links:n,className:r}){let[i,a]=(0,R.useState)(``),o=qe(5e3),s=he(e||[],i);return/* @__PURE__ */ (0,z.jsxs)(`nav`,{"aria-label":`Recent contexts`,className:w(`flex min-h-0 flex-col gap-1.5`,r),children:[/* @__PURE__ */ (0,z.jsx)(ae,{"aria-label":`Filter contexts`,placeholder:`Filter by path, description, event type…`,className:`h-8 text-xs md:text-xs`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Escape`&&a(``)}}),/* @__PURE__ */ (0,z.jsx)(Q,{rows:s,current:t,links:n,nowMs:o}),/* @__PURE__ */ (0,z.jsx)(`p`,{className:`px-2 text-2xs text-muted-foreground`,children:e?i.trim()?`${String(s.length)} of ${String(e.length)} contexts`:`${String(e.length)} contexts, ${String(e.filter(e=>e.awake).length)} awake`:`Loading contexts…`})]})}function Q({rows:e,current:t,links:n,nowMs:r}){let i=(0,R.useRef)(null),[a]=(0,R.useState)(L),o=I({count:e.length,getScrollElement:()=>i.current,estimateSize:t=>$(e[t])*a,getItemKey:t=>e[t].path,overscan:12});return/* @__PURE__ */ (0,z.jsx)(`div`,{ref:i,className:`min-h-0 flex-1 overflow-y-auto text-xs`,children:/* @__PURE__ */ (0,z.jsx)(`ul`,{className:`relative w-full`,style:{height:o.getTotalSize()},children:o.getVirtualItems().map(i=>/* @__PURE__ */ (0,z.jsx)(`li`,{className:`absolute top-0 left-0 w-full`,style:{height:`${String($(e[i.index]))}rem`,transform:`translateY(${String(i.start)}px)`},children:/* @__PURE__ */ (0,z.jsx)(Ke,{row:e[i.index],current:t,links:n,nowMs:r})},i.key))})})}function Ke({row:e,current:t,links:n,nowMs:r}){let i=M(e),a=j(e,r);return/* @__PURE__ */ (0,z.jsx)(Z,{path:e.path,links:n,"aria-current":e.path===t?`page`:void 0,className:`flex h-full min-w-0 flex-col justify-center rounded-md px-2 hover:bg-muted/60 aria-[current=page]:bg-muted`,children:/* @__PURE__ */ (0,z.jsxs)(`span`,{className:`flex min-w-0 items-start gap-2`,children:[/* @__PURE__ */ (0,z.jsx)(J,{row:e,activities:a,size:`sm`,showTooltip:!0,nowMs:r,className:`mt-0.5`}),/* @__PURE__ */ (0,z.jsx)(_e,{title:P(e),path:e.path,line:a.length>0?/* @__PURE__ */ (0,z.jsx)(V,{activities:a,nowMs:r,mode:`inline`}):pe(e)||`${String(e.eventCount)} events`,className:`text-foreground/90`,time:/* @__PURE__ */ (0,z.jsx)(`time`,{dateTime:i,title:i,className:`shrink-0 text-2xs text-muted-foreground tabular-nums`,children:e.awake||a.length>0?`awake`:F(i,r)})})]})})}function $(e){return P(e)?3.75:2.75}function qe(e){let[t,n]=(0,R.useState)(()=>Date.now());return(0,R.useEffect)(()=>{let t=setInterval(()=>n(Date.now()),e);return()=>clearInterval(t)},[e]),t}function Je(e,{of:t,pollMs:n=1e4}){let[r,i]=(0,R.useState)({}),a=(0,R.useEffectEvent)(async()=>{if(e&&document.visibilityState===`visible`)try{let n=N(await e());i({of:t,rows:n})}catch(e){let n=e instanceof Error?e.message:String(e);i(e=>({of:t,rows:e.of===t?e.rows:void 0,error:n}))}}),o=!!e;return(0,R.useEffect)(()=>{if(!o)return;a();let e=setInterval(()=>void a(),n),t=()=>void a();return document.addEventListener(`visibilitychange`,t),()=>{clearInterval(e),document.removeEventListener(`visibilitychange`,t)}},[o,t,n]),r.of===t?{rows:r.rows,error:r.error}:{rows:void 0,error:void 0}}export{Z as a,U as c,We as i,V as l,Q as n,J as o,Je as r,Y as s,Ge as t,B as u};
A dist/chunks/context-catalog-live.mjs
@@ -0,0 +1,1 @@ +import{r as e}from"./rolldown-runtime.mjs";import{a as t}from"./vendor-react";import{itxSessionOf as n}from"../lib/itx-session";import{a as r,d as i,f as a,h as o,i as s,l as c,r as l,s as u,u as d,v as f}from"./vendor-zod";import{Pt as p,St as m,b as h,gn as g,s as _}from"./vendor-db";import{C as v,n as y}from"./context-catalog-rows.mjs";import{r as b}from"./context-catalog-list.mjs";var x=/* @__PURE__ */ e(t(),1);const S=y.omit({awake:!0,activities:!0}).extend({activeMs:i(),createdMs:i(),rev:i()}),C=d({path:o(),since:i(),activities:l(v).optional()}),w=u(a({gen:o(),rev:i(),more:c(!0).optional()}),r(`type`,[a({type:c(`reset`),q:o(),full:s(),rows:l(f())}),a({type:c(`resume`),q:o(),full:s(),ids:l(o()),rows:l(f())}),a({type:c(`change`),from:i(),del:l(o()),rows:l(f())})]));function T(e,t){if(e===t)return 0;let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e.charCodeAt(r),i=t.charCodeAt(r);if(n===i)continue;let a=n>=55296&&n<=57343;return a===(i>=55296&&i<=57343)?n<i?-1:1:a?1:-1}return e.length<t.length?-1:1}function E(e,t){return t===`path`?[0,e.path]:[(t===`created`?e.createdMs:e.activeMs)??0,e.path]}function D(e,t,n=`active`){if(n===`path`)return T(e.path,t.path);let[r]=E(e,n),[i]=E(t,n);return r===i?-T(e.path,t.path):i-r}const O=a({code:o()}),k=e=>e.keys?`keys`:e.awake?`awake`:`window`;function A(e){let t=n(e),r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set,o=`asking`,s=()=>Math.max(t.get().epoch,1),c=1,l=e=>{if(o!==e){o=e;for(let e of a)e()}};function u(e){if(!e.gen||!e.q)return;let t=k(e.query);if(t===`awake`)return;let n={gen:e.gen,rev:e.rev,q:e.q};if(t===`keys`)return{...n,have:[...e.rows.keys()]};let r=e.query.order||`active`,i=[...e.rows.values()].toSorted((e,t)=>D(e,t,r)).at(-1);return{...n,bound:i?E(i,r):null}}function d(e,t){e.error=t,f(e),e.rejectReady(Error(t)),e.onChange({del:[],put:[],error:t})}function f(e){let t=e.handle;e.start=void 0,e.handle=void 0,Promise.resolve(t).then(e=>e?.[Symbol.dispose](),()=>{})}function p(n){f(n);let r={};n.start=r;let i=s(),a=u(n),o;try{o=e.contexts.watch(n.query,e=>{h(n,r,e)},a?{cursor:a}:void 0)}catch(e){o=Promise.reject(e)}n.handle=o,Promise.resolve(o).then(void 0,e=>{n.start===r&&s()===i&&t.get().state===`open`&&(O.safeParse(e).data?.code!==`INVALID_INPUT`&&l(`none`),d(n,e instanceof Error?e.message:String(e)))}),Promise.resolve(o).then(e=>e.ended?e.ended():new Promise(()=>{})).then(()=>{n.start===r&&t.get().state===`open`&&m(n,`the catalog ended the watch three times in half a minute`)},()=>{})}function m(e,t){let n=Date.now();if(n-e.restartedAt>3e4&&(e.restarts=0,e.restartedAt=n),e.restarts>=2){l(`none`),d(e,t);return}e.restarts+=1,p(e)}function h(e,t,n){let r=w.safeParse(n);if(e.start===t&&(r.success?g(e,r.data):(l(`none`),d(e,`the catalog sent a frame that this page cannot read`))),!r.success||!r.data.more)for(let e of i)e()}function g(e,t){o===`asking`&&l(`live`);let n=t.rows.flatMap(t=>{let n=e.row.safeParse(t);return n.success?[n.data]:[]});if(t.type===`change`){if(e.gen!==t.gen||e.rev!==t.from){m(e,`the catalog's changes came with a gap three times in half a minute`);return}for(let n of t.del)e.rows.delete(n);for(let t of n)e.rows.set(t.path,t);e.rev=t.rev,e.frames+=1,e.onChange({del:t.del,put:n});return}let r=new Set(t.type===`reset`?n.map(e=>e.path):t.ids),i=[...e.rows.keys()].filter(e=>!r.has(e));for(let t of i)e.rows.delete(t);for(let t of n)e.rows.set(t.path,t);e.gen=t.gen,e.rev=t.rev,e.q=t.q,e.full=t.full,e.error=void 0,e.answers+=1,e.onChange({del:i,put:n,answer:!0}),e.resolveReady()}let _,v=()=>{c=s(),_||=t.subscribe(()=>{let e=s();if(e!==c){c=e;for(let e of r)e.error||p(e)}})},y=()=>{r.size>0||(_?.(),_=void 0)};return{watch(e,t,n,i){let a=Promise.withResolvers();a.promise.catch(()=>{});let o={query:e,row:t,onChange:n,rows:/* @__PURE__ */ new Map,gen:void 0,rev:-1,q:void 0,full:!1,answers:0,frames:0,restarts:0,restartedAt:0,error:void 0,start:void 0,handle:void 0,ready:a.promise,resolveReady:a.resolve,rejectReady:a.reject,stop(){r.delete(s)&&(f(s),y())}},s=o,c=i;return c?.gen&&k(c.query)===k(e)&&(o.rows=new Map(c.rows),o.gen=c.gen,o.rev=c.rev??-1,o.q=c.q),r.add(s),v(),p(s),o},onBatch(e){return i.add(e),()=>i.delete(e)},support:()=>o,subscribe(e){return a.add(e),()=>a.delete(e)},close(){for(let e of r)f(e);r.clear(),y()}}}function j(e){let t=[`/`],n=``;for(let r of e.path.split(`/`).filter(Boolean))t.push(n+=`/${r}`);let r=e.path.lastIndexOf(`/`),i=e.path===`/`?``:r<=0?`/`:e.path.slice(0,r);return{...e,parent:i,under:t}}const M=(e,...t)=>e?.type===`ref`&&e.path.length===t.length&&e.path.every((e,n)=>e===t[n]),N=e=>typeof e==`string`||typeof e==`number`||typeof e==`boolean`,P=e=>e.type===`ref`&&e.path.length===2&&e.path[0]===`metadata`?e.path[1]:void 0,F={activeMs:`active`,createdMs:`created`,path:`path`};function I(e){if(e.type!==`func`)return;let[t,n]=e.args;if(!t||!n)return;if(e.name===`eq`){let[e,r]=t.type===`ref`?[t,n]:[n,t];if(e.type!==`ref`||r.type!==`val`)return;let i=r.value;if(!N(i))return;if(M(e,`path`))return typeof i==`string`?{keys:[i]}:void 0;if(M(e,`activeMs`)||M(e,`createdMs`))return{tie:!0};if(M(e,`parent`))return typeof i==`string`?{childrenOf:i}:void 0;let a=P(e);return a?{fact:[a,i]}:void 0}if(e.name!==`in`)return;if(M(t,`path`)&&n.type===`val`){let e=l(o()).safeParse(n.value);return e.success?{keys:e.data}:void 0}if(t.type!==`val`||n.type!==`ref`)return;let r=t.value;if(!N(r))return;if(M(n,`under`))return typeof r==`string`?{under:r}:void 0;if(M(n,`processors`))return{fact:[`$processor`,r]};let i=P(n);return i?{fact:[i,r]}:void 0}const L=e=>e?e.type===`func`&&e.name===`and`?e.args.flatMap(L):[e]:[];function R(e){let[t,n,...r]=e||[];if(!t||r.length>0||t.expression.type!==`ref`)return;let[i,...a]=t.expression.path;if(a.length>0||!i||!Object.hasOwn(F,i))return;let o=F[i],s=o===`path`?`asc`:`desc`;if(t.compareOptions.direction===s&&(!n||o!==`path`&&M(n.expression,`path`))&&!(n&&n.compareOptions.direction!==s))return o}const z=500;function B(e){let t=[],n={},r,i=0;for(let a of L(e.where)){let e=I(a);if(!e)i+=1;else if(`tie`in e)return{nothing:!0};else if(`keys`in e){let t=new Set(e.keys);r=r?r.filter(e=>t.has(e)):e.keys}else`fact`in e?t.push(e.fact):`under`in e&&!n.under?n.under=e.under:`childrenOf`in e&&!n.childrenOf?n.childrenOf=e.childrenOf:i+=1}if(r)return r.length>0?{keys:[...new Set(r)]}:{nothing:!0};let a=t.toSorted(([e],[t])=>T(e,t)),o={...a.length>0&&{where:Object.fromEntries(a)},...n};if(e.limit===void 0)return{query:{...o,limit:500},unlimited:!0};if(i>0)throw Error(`the catalog has no index for a condition of this query, and a limit over a guessed set gives wrong rows: use facts (eq(c.metadata.x, value)), or drop the limit`);let s=R(e.orderBy);if(!s)throw Error(`the catalog keeps three orders: a query with a limit says orderBy(c.activeMs, "desc"), orderBy(c.createdMs, "desc") or orderBy(c.path, "asc")`);if(e.limit>500)throw Error(`the catalog's largest window is 500 rows`);let c={...o,order:s,limit:e.limit};return e.cursor||e.offset?{query:c,unlimited:!1,after:!0}:{query:c,unlimited:!1}}function V({watcher:e,id:t,index:n}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a={watch:void 0,settled:Promise.resolve(),scheduled:!1},o=/* @__PURE__ */ new Map,s=()=>[...[...r.values()].map(e=>e.watch),a.watch].flatMap(e=>e?[{query:e.query,rows:e.rows.size,full:e.full,frames:e.frames}]:[]);return{id:t,...n,getKey:e=>e.path,syncMode:`on-demand`,utils:{demands:s},sync:{rowUpdateMode:`full`,sync:({begin:t,write:n,commit:s,markReady:c,collection:l})=>{let u=!1,d=!0,f=/* @__PURE__ */ new Map,p=()=>{u||t(),u=!0},m=()=>{u&&(u=!1,f.clear(),d=s())},h=e.onBatch(m),g=e=>f.has(e)?f.get(e):l.get(e)?.rev??!1,_=(e,t)=>{let r=o.get(t.path)??/* @__PURE__ */ new Set;o.set(t.path,r),r.add(e);let i=g(t.path);if(i===t.rev)return;p();let a=j(t);n(i===!1?{type:`insert`,value:a}:{type:`update`,value:a}),f.set(t.path,t.rev)},v=(e,t)=>{let r=o.get(t);r?.delete(e),!r?.size&&(o.delete(t),g(t)!==!1&&(p(),n({type:`delete`,key:t}),f.set(t,!1)))},y=(e,t,n)=>{if(n.error)return;for(let t of n.del)v(e,t);let r=n.answer?t()?.rows.values()??n.put:n.put;for(let t of r)_(e,t)},b=(e,t)=>{t?.stop();for(let n of t?.rows.keys()??[])v(e,n)},x=async()=>{a.scheduled=!1;let t=[...i.keys()].toSorted(T),n=a.watch;if(t.length===0){a.watch=void 0,b(a,n),m();return}if(JSON.stringify(n?.query.keys)===JSON.stringify(t))return n?.ready;let r=e.watch({keys:t},S,e=>{y(a,()=>r,e)},n);a.watch=r,n?.stop(),await r.ready},C=(e,t)=>{for(let n of e){let e=(i.get(n)??0)+t;e>0?i.set(n,e):i.delete(n)}return a.scheduled?a.settled:(a.scheduled=!0,a.settled=Promise.resolve().then(x),a.settled.catch(()=>{}),a.settled)},w=async()=>{d!==!0&&await d};return c(),{loadSubset:t=>{let n=B(t);if(`nothing`in n)return!0;if(`keys`in n)return C(n.keys,1).then(w);let i=JSON.stringify(n.query),{limit:a,...o}=n.query,s=JSON.stringify(o),c=[...r.values()].find(({watch:e})=>{let{limit:t,...n}=e.query;return JSON.stringify(n)===s})?.watch;if(n.after){if(c&&c.answers>0)return!0;throw Error(`the catalog serves a window from its start: ask for a larger limit`)}let l=r.get(i);if(!l){let t={holds:0,unlimited:n.unlimited,watch:e.watch(n.query,S,e=>{y(t,()=>t.watch,e)},c)};l=t,r.set(i,l)}l.holds+=1;let{watch:u,unlimited:f}=l,p=()=>{if(f&&u.full)throw Error(`more than ${String(u.rows.size)} rows match and the query has no limit: say an order and a limit`)};return u.answers>0&&d===!0?(p(),!0):u.ready.then(p).then(w)},unloadSubset:e=>{let t;try{t=B(e)}catch{return}if(`nothing`in t)return;if(`keys`in t)return void C(t.keys,-1);if(t.after)return;let n=JSON.stringify(t.query),i=r.get(n);i&&(--i.holds,!(i.holds>0)&&(r.delete(n),b(i,i.watch),m()))},cleanup:()=>{h();for(let e of r.values())e.watch.stop();a.watch?.stop(),a.watch=void 0,r.clear(),i.clear(),o.clear()}}}}}}function H({watcher:e,id:t,query:n,row:r,index:i}){return{id:t,...i,getKey:e=>e.path,sync:{rowUpdateMode:`full`,sync:({begin:t,write:i,commit:a,markReady:o,fail:s,collection:c})=>{let l=!1,u=e.onBatch(()=>{l&&(l=!1,a(),o())}),d=e.watch(n,r,({del:e,put:n,error:r})=>{if(r){s(Error(r));return}l||t(),l=!0;for(let t of e)c.has(t)&&i({type:`delete`,key:t});for(let e of n)i({type:c.has(e.path)?`update`:`insert`,value:e})});return()=>{u(),d.stop()}}}}}const U={defaultIndexType:h,autoIndex:`eager`};function W(e){let t=A(e),n=p(V({watcher:t,index:U})),r=p(H({watcher:t,query:{awake:!0},row:C,index:U})),i=m(e=>e.from({context:n}).orderBy(({context:e})=>e.activeMs,`desc`).limit(500));return{watcher:t,contexts:n,awake:r,listings:m(e=>e.from({context:i}).join({awake:r},({context:e,awake:t})=>g(e.path,t.path),`left`))}}const G=/* @__PURE__ */ new WeakMap;function K(e){let t=G.get(e)??W(e);return G.set(e,t),t}function q(e,t,{of:n,pollMs:r}){let i=K(e),a=(0,x.useSyncExternalStore)(i.watcher.subscribe,i.watcher.support,i.watcher.support);(0,x.useEffect)(()=>{if(a!==`asking`)return;let e=i.watcher.watch({awake:!0},C,()=>{});return()=>{e.stop()}},[i,a]);let o=b(a===`none`?t:null,{of:n,pollMs:r}),s=_({query:e=>a===`live`?e.from({listing:i.listings}):void 0}),c=s.isReady?s.data:void 0,l=(0,x.useMemo)(()=>c?.map(({context:e,awake:t})=>({...e,...t&&{awake:{since:t.since}},...t?.activities&&{activities:t.activities}})).toSorted((e,t)=>D(e,t)),[c]);return a===`none`?o:{rows:l,error:s.isLoadingError?`The mind did not answer the catalog's query.`:void 0}}export{S as a,D as c,V as d,H as f,C as i,T as l,q as n,B as o,z as r,A as s,K as t,j as u};
M dist/chunks/context-catalog-rows.mjs
@@ -1,1 +1,1 @@ -import{_ as e,d as t,f as n,g as r,m as i,r as a,u as o}from"./vendor-zod";const s=`activities`,c=`events.iterate.com/itx/activity-pushed`,l=`events.iterate.com/itx/activity-popped`,u=32,d=i().trim().min(1).max(40),f=t({key:i().min(1).max(120),text:i().min(1).max(160),icon:i().min(1).max(500).optional(),url:i().min(1).max(500).optional(),tags:a(d).max(8).optional(),pushedAt:i().optional(),expiresAt:i().optional()}),p=f.omit({pushedAt:!0}).extend({ttlMs:o().int().positive().max(864e5).optional()}),m=r([p,t({items:a(p).min(1).max(32)})]),h=r([t({key:i().min(1).max(120)}),t({keys:a(i().min(1).max(120)).min(1).max(32)}),t({tag:d})]),g=t({type:i(),createdAt:i().optional(),payload:e().optional()});function _(e){if(!(e instanceof Object))return!1;let t=Reflect.get(e,`type`);return t===`events.iterate.com/itx/activity-pushed`||t===`events.iterate.com/itx/activity-popped`}const v=[];function y(e,t,n){let r=e&&e.initial===n&&e.log.length>0&&t[0]===e.log[0]&&t[e.log.length-1]===e.log.at(-1);if(r&&t.length===e.log.length)return e;let i=r?t.slice(e.log.length):t,a=r?e.stack:n||v;return i.some(_)?{log:t,initial:n,stack:w(i,{initial:a})}:{log:t,initial:n,stack:a}}function b(e,t){if(!e.expiresAt)return!0;let n=Date.parse(e.expiresAt);return!Number.isFinite(n)||n>t}const x=a(f);function S(e,t){if(e===void 0)return;let n=x.safeParse(e);return n.success?t===void 0?n.data:C(n.data,t):[]}function C(e,t=Date.now()){return!e||e.length===0?[]:e.filter(e=>b(e,t))}function w(e,t={}){let n=t.initial?[...t.initial]:[];for(let t of e){if(!_(t))continue;let e=g.safeParse(t);if(!e.success)continue;let{type:r,createdAt:i,payload:a}=e.data;if(r===`events.iterate.com/itx/activity-pushed`){let e=m.safeParse(a);if(!e.success)continue;let t=`items`in e.data?e.data.items:[e.data];for(let e of t){let t=j(e,i);n=[t,...n.filter(e=>e.key!==t.key)]}n.length>32&&(n=n.slice(0,32));continue}if(r===`events.iterate.com/itx/activity-popped`){let e=h.safeParse(a);if(!e.success)continue;if(`key`in e.data){let t=e.data.key;n=n.filter(e=>e.key!==t)}else if(`keys`in e.data){let t=new Set(e.data.keys);n=n.filter(e=>!t.has(e.key))}else{let t=e.data.tag;n=n.filter(e=>!e.tags?.includes(t))}}}return t.nowMs===void 0?n:C(n,t.nowMs)}function T(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=n.tags?.[0]||`activity`,r=t.get(e);r?r.push(n):t.set(e,[n])}return[...t.entries()].map(([e,t])=>({tag:e,items:t}))}const E=/* @__PURE__ */ new Set([`agent`,`claude`,`codex`,`opencode`,`mcp`,`code`,`search`,`web`]);function D(e,t=e=>`https://www.google.com/s2/favicons?domain=${encodeURIComponent(e)}&sz=32`){let n=e.icon?.trim();if(n){if(E.has(n.toLowerCase())||A(n))return;if(n.startsWith(`data:image/`)||n.startsWith(`/`)||/\.(svg|png|ico|webp|jpg|jpeg)(\?.*)?$/i.test(n))return n;let e=k(n);if(e)return t(e)}let r=e.url?k(e.url):void 0;return r?t(r):void 0}function O(e){let t=e.icon?.trim();if(t&&A(t))return{kind:`emoji`,glyph:t};let n=(t||e.tags?.[0]||``).toLowerCase();return n===`claude`||n===`codex`||n===`opencode`?{kind:`claude`}:n===`agent`||e.url?.startsWith(`/agents/`)?{kind:`agent`}:n===`mcp`?{kind:`mcp`}:n===`code`?{kind:`code`}:n===`search`?{kind:`search`}:{kind:`web`}}function k(e){if(!e.startsWith(`/`))try{let t=e.includes(`://`)?e:`https://${e}`,{hostname:n}=new URL(t);return n.includes(`.`)?n:void 0}catch{return}}function A(e){return e.length<=8&&/^\p{Extended_Pictographic}/u.test(e)}function j(e,t){let n=t?Date.parse(t):Date.now(),r=e.expiresAt||(e.ttlMs!==void 0&&Number.isFinite(n)?new Date(n+e.ttlMs).toISOString():void 0);return{key:e.key,text:e.text,icon:e.icon,url:e.url,tags:e.tags?.length?e.tags:void 0,pushedAt:t,expiresAt:r}}const M=t({path:i(),awake:t({since:o()}).optional(),createdAt:i().optional(),lastEventAt:i().optional(),lastActivityAt:i().optional(),eventCount:o(),eventTypes:n(i(),o()),recentTypes:a(i()),processors:a(i()),storageBytes:o().optional(),description:i().optional(),metadata:n(i(),e()).optional(),activities:a(f).optional()}),N=a(f);function P(e,t=Date.now()){return e?C(e.activities||N.safeParse(e.metadata?.activities).data,t):[]}function F(t){return(a(e()).safeParse(t).data||[]).flatMap(e=>{let t=M.safeParse(e);return t.success?[t.data]:[]})}function I(e){return e.lastActivityAt||e.lastEventAt}function L(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?[...e]:e.filter(e=>{let t=e.activities||[],r=[e.path,e.description||``,...Object.keys(e.eventTypes),...e.processors,...t.flatMap(e=>[e.text,e.key,...e.tags||[]]),e.metadata?JSON.stringify(e.metadata):``].join(` `).toLowerCase();return n.every(e=>r.includes(e))})}function R(e){return e.startsWith(`events.iterate.com/`)?e.slice(19):e}function z(e,t){if(e===void 0)return``;let n=Math.round((t-(typeof e==`number`?e:Date.parse(e)))/1e3);return Number.isFinite(n)?n<5?`now`:n<60?`${String(n)} s`:n<3600?`${String(Math.floor(n/60))} min`:n<86400?`${String(Math.floor(n/3600))} h`:`${String(Math.floor(n/86400))} d`:``}function B(e){return e<1e3?`${String(e)} B`:e<1e6?`${(e/1e3).toFixed(1)} kB`:e<1e9?`${(e/1e6).toFixed(1)} MB`:`${(e/1e9).toFixed(1)} GB`}function V(e){let t=e.metadata?.tags;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):[]}function H(e){let t=e.metadata?.title;if(typeof t==`string`)return t.trim().slice(0,80).trim()||void 0}function U(e){let t=e?.metadata?.icon;if(typeof t==`string`)return t.trim().slice(0,256).trim()||void 0}const W=[`🧭`,`🚀`,`🛡️`,`⚡`,`🔧`,`📡`,`📬`,`🎯`,`terminal`,`globe`,`git-branch`,`shield`,`database`,`sparkles`];function G(e,t,n,r){if(n===void 0&&r===void 0)return{description:t||null};if(!e)throw Error(`The catalog does not list this context yet, so its title cannot be set here.`);let i={...e.metadata||{}};if(n!==void 0&&(n.trim()?i.title=n.trim().slice(0,80):delete i.title),r!==void 0&&(r.trim()?i.icon=r.trim().slice(0,256):delete i.icon),JSON.stringify(i).length>4e3)throw Error(`This context's metadata is too long for the catalog to keep with a title.`);return{description:t||null,metadata:Object.keys(i).length?i:null}}const K=[`events.iterate.com/agent/`,`events.iterate.com/agent-ui/`,`events.iterate.com/llm-request/`,`events.iterate.com/claude-code/`,`events.iterate.com/acp/`,`herdr/`];function q(e){return e?.path.startsWith(`/agents/`)?Object.keys(e.eventTypes).some(e=>K.some(t=>e.startsWith(t))):!1}function J(e,t,n){let r=t.trim(),i=n?.trim();if((i||r!==(e.description||``))&&(i||r)&&!(r.length>500))return{...i&&{title:i.slice(0,200)},description:r||void 0}}async function Y(e,t,n,r,i){let a=[(async()=>e({type:`events.iterate.com/itx/described`,payload:G(t,n,r,i)}))()],o=q(t)?J(t,n,r):void 0;o&&a.push(e({type:`events.iterate.com/agent/summary-updated`,payload:o}));let s=(await Promise.allSettled(a)).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(s.length===1)throw s[0];if(s.length>1)throw AggregateError(s,s.map(e=>String(e)).join(` `))}function X(e){return e.description||e.recentTypes.map(R).toReversed().join(` · `)}function Z(e){let t=[];for(let n=e.length-1;n>=0;n--){let r=e[n],i=t.at(-1);i?.type===r?i.count+=1:t.push({type:r,count:1,at:n})}return t}export{w as A,f as C,D,C as E,T as M,b as N,O,u as S,m as T,R as _,P as a,l as b,X as c,Y as d,G as f,q as g,B as h,I as i,y as j,S as k,V as l,L as m,M as n,U as o,Z as p,J as r,F as s,W as t,H as u,z as v,h as w,c as x,s as y}; +import{_ as e,d as t,f as n,h as r,p as i,r as a,v as o}from"./vendor-zod";const s=`activities`,c=`events.iterate.com/itx/activity-pushed`,l=`events.iterate.com/itx/activity-popped`,u=32,d=r().trim().min(1).max(40),f=n({key:r().min(1).max(120),text:r().min(1).max(160),icon:r().min(1).max(500).optional(),url:r().min(1).max(500).optional(),tags:a(d).max(8).optional(),pushedAt:r().optional(),expiresAt:r().optional()}),p=f.omit({pushedAt:!0}).extend({ttlMs:t().int().positive().max(864e5).optional()}),m=e([p,n({items:a(p).min(1).max(32)})]),h=e([n({key:r().min(1).max(120)}),n({keys:a(r().min(1).max(120)).min(1).max(32)}),n({tag:d})]),g=n({type:r(),createdAt:r().optional(),payload:o().optional()});function _(e){if(!(e instanceof Object))return!1;let t=Reflect.get(e,`type`);return t===`events.iterate.com/itx/activity-pushed`||t===`events.iterate.com/itx/activity-popped`}const v=[];function y(e,t,n){let r=e&&e.initial===n&&e.log.length>0&&t[0]===e.log[0]&&t[e.log.length-1]===e.log.at(-1);if(r&&t.length===e.log.length)return e;let i=r?t.slice(e.log.length):t,a=r?e.stack:n||v;return i.some(_)?{log:t,initial:n,stack:w(i,{initial:a})}:{log:t,initial:n,stack:a}}function b(e,t){if(!e.expiresAt)return!0;let n=Date.parse(e.expiresAt);return!Number.isFinite(n)||n>t}const x=a(f);function S(e,t){if(e===void 0)return;let n=x.safeParse(e);return n.success?t===void 0?n.data:C(n.data,t):[]}function C(e,t=Date.now()){return!e||e.length===0?[]:e.filter(e=>b(e,t))}function w(e,t={}){let n=t.initial?[...t.initial]:[];for(let t of e){if(!_(t))continue;let e=g.safeParse(t);if(!e.success)continue;let{type:r,createdAt:i,payload:a}=e.data;if(r===`events.iterate.com/itx/activity-pushed`){let e=m.safeParse(a);if(!e.success)continue;let t=`items`in e.data?e.data.items:[e.data];for(let e of t){let t=j(e,i);n=[t,...n.filter(e=>e.key!==t.key)]}n.length>32&&(n=n.slice(0,32));continue}if(r===`events.iterate.com/itx/activity-popped`){let e=h.safeParse(a);if(!e.success)continue;if(`key`in e.data){let t=e.data.key;n=n.filter(e=>e.key!==t)}else if(`keys`in e.data){let t=new Set(e.data.keys);n=n.filter(e=>!t.has(e.key))}else{let t=e.data.tag;n=n.filter(e=>!e.tags?.includes(t))}}}return t.nowMs===void 0?n:C(n,t.nowMs)}function T(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=n.tags?.[0]||`activity`,r=t.get(e);r?r.push(n):t.set(e,[n])}return[...t.entries()].map(([e,t])=>({tag:e,items:t}))}const E=/* @__PURE__ */ new Set([`agent`,`claude`,`codex`,`opencode`,`mcp`,`code`,`search`,`web`]);function D(e,t=e=>`https://www.google.com/s2/favicons?domain=${encodeURIComponent(e)}&sz=32`){let n=e.icon?.trim();if(n){if(E.has(n.toLowerCase())||A(n))return;if(n.startsWith(`data:image/`)||n.startsWith(`/`)||/\.(svg|png|ico|webp|jpg|jpeg)(\?.*)?$/i.test(n))return n;let e=k(n);if(e)return t(e)}let r=e.url?k(e.url):void 0;return r?t(r):void 0}function O(e){let t=e.icon?.trim();if(t&&A(t))return{kind:`emoji`,glyph:t};let n=(t||e.tags?.[0]||``).toLowerCase();return n===`claude`||n===`codex`||n===`opencode`?{kind:`claude`}:n===`agent`||e.url?.startsWith(`/agents/`)?{kind:`agent`}:n===`mcp`?{kind:`mcp`}:n===`code`?{kind:`code`}:n===`search`?{kind:`search`}:{kind:`web`}}function k(e){if(!e.startsWith(`/`))try{let t=e.includes(`://`)?e:`https://${e}`,{hostname:n}=new URL(t);return n.includes(`.`)?n:void 0}catch{return}}function A(e){return e.length<=8&&/^\p{Extended_Pictographic}/u.test(e)}function j(e,t){let n=t?Date.parse(t):Date.now(),r=e.expiresAt||(e.ttlMs!==void 0&&Number.isFinite(n)?new Date(n+e.ttlMs).toISOString():void 0);return{key:e.key,text:e.text,icon:e.icon,url:e.url,tags:e.tags?.length?e.tags:void 0,pushedAt:t,expiresAt:r}}const M=n({path:r(),awake:n({since:t()}).optional(),createdAt:r().optional(),lastEventAt:r().optional(),lastActivityAt:r().optional(),eventCount:t(),eventTypes:i(r(),t()),recentTypes:a(r()),processors:a(r()),storageBytes:t().optional(),description:r().optional(),metadata:i(r(),o()).optional(),activities:a(f).optional()}),N=a(f);function P(e,t=Date.now()){return e?C(e.activities||N.safeParse(e.metadata?.activities).data,t):[]}function F(e){return(a(o()).safeParse(e).data||[]).flatMap(e=>{let t=M.safeParse(e);return t.success?[t.data]:[]})}function I(e){return e.lastActivityAt||e.lastEventAt}function L(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?[...e]:e.filter(e=>{let t=e.activities||[],r=[e.path,e.description||``,...Object.keys(e.eventTypes),...e.processors,...t.flatMap(e=>[e.text,e.key,...e.tags||[]]),e.metadata?JSON.stringify(e.metadata):``].join(` `).toLowerCase();return n.every(e=>r.includes(e))})}function R(e){return e.startsWith(`events.iterate.com/`)?e.slice(19):e}function z(e,t){if(e===void 0)return``;let n=Math.round((t-(typeof e==`number`?e:Date.parse(e)))/1e3);return Number.isFinite(n)?n<5?`now`:n<60?`${String(n)} s`:n<3600?`${String(Math.floor(n/60))} min`:n<86400?`${String(Math.floor(n/3600))} h`:`${String(Math.floor(n/86400))} d`:``}function B(e){return e<1e3?`${String(e)} B`:e<1e6?`${(e/1e3).toFixed(1)} kB`:e<1e9?`${(e/1e6).toFixed(1)} MB`:`${(e/1e9).toFixed(1)} GB`}function V(e){let t=e.metadata?.tags;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.length>0):[]}function H(e){let t=e.metadata?.title;if(typeof t==`string`)return t.trim().slice(0,80).trim()||void 0}function U(e){let t=e?.metadata?.icon;if(typeof t==`string`)return t.trim().slice(0,256).trim()||void 0}const W=[`🧭`,`🚀`,`🛡️`,`⚡`,`🔧`,`📡`,`📬`,`🎯`,`terminal`,`globe`,`git-branch`,`shield`,`database`,`sparkles`];function G(e,t,n,r){if(n===void 0&&r===void 0)return{description:t||null};if(!e)throw Error(`The catalog does not list this context yet, so its title cannot be set here.`);let i={...e.metadata||{}};if(n!==void 0&&(n.trim()?i.title=n.trim().slice(0,80):delete i.title),r!==void 0&&(r.trim()?i.icon=r.trim().slice(0,256):delete i.icon),JSON.stringify(i).length>4e3)throw Error(`This context's metadata is too long for the catalog to keep with a title.`);return{description:t||null,metadata:Object.keys(i).length?i:null}}const K=[`events.iterate.com/agent/`,`events.iterate.com/agent-ui/`,`events.iterate.com/llm-request/`,`events.iterate.com/claude-code/`,`events.iterate.com/acp/`,`herdr/`];function q(e){return e?.path.startsWith(`/agents/`)?Object.keys(e.eventTypes).some(e=>K.some(t=>e.startsWith(t))):!1}function J(e,t,n){let r=t.trim(),i=n?.trim();if((i||r!==(e.description||``))&&(i||r)&&!(r.length>500))return{...i&&{title:i.slice(0,200)},description:r||void 0}}async function Y(e,t,n,r,i){let a=[(async()=>e({type:`events.iterate.com/itx/described`,payload:G(t,n,r,i)}))()],o=q(t)?J(t,n,r):void 0;o&&a.push(e({type:`events.iterate.com/agent/summary-updated`,payload:o}));let s=(await Promise.allSettled(a)).flatMap(e=>e.status===`rejected`?[e.reason]:[]);if(s.length===1)throw s[0];if(s.length>1)throw AggregateError(s,s.map(e=>String(e)).join(` `))}function X(e){return e.description||e.recentTypes.map(R).toReversed().join(` · `)}function Z(e){let t=[];for(let n=e.length-1;n>=0;n--){let r=e[n],i=t.at(-1);i?.type===r?i.count+=1:t.push({type:r,count:1,at:n})}return t}export{w as A,f as C,D,C as E,T as M,b as N,O,u as S,m as T,R as _,P as a,l as b,X as c,Y as d,G as f,q as g,B as h,I as i,y as j,S as k,V as l,L as m,M as n,U as o,Z as p,J as r,F as s,W as t,H as u,z as v,h as w,c as x,s as y};
M dist/chunks/context-view-search.mjs
@@ -1,1 +1,1 @@ -import{c as e,d as t,m as n,r,u as i}from"./vendor-zod";const a=t({q:n().optional().catch(void 0),types:r(n()).optional().catch(void 0),actor:n().optional().catch(void 0),from:i().int().nonnegative().optional().catch(void 0),to:i().int().nonnegative().optional().catch(void 0),event:i().int().nonnegative().optional().catch(void 0),processors:e(!0).optional().catch(void 0),filter:e(!0).optional().catch(void 0)});function o(e){return{query:e.q||``,types:new Set(e.types||[]),actor:e.actor,from:e.from,to:e.to}}const s={q:void 0,types:void 0,actor:void 0,from:void 0,to:void 0},c={event:void 0,processors:void 0};export{o as i,s as n,c as r,a as t}; +import{d as e,f as t,h as n,l as r,r as i}from"./vendor-zod";const a=t({q:n().optional().catch(void 0),types:i(n()).optional().catch(void 0),actor:n().optional().catch(void 0),from:e().int().nonnegative().optional().catch(void 0),to:e().int().nonnegative().optional().catch(void 0),event:e().int().nonnegative().optional().catch(void 0),processors:r(!0).optional().catch(void 0),filter:r(!0).optional().catch(void 0)});function o(e){return{query:e.q||``,types:new Set(e.types||[]),actor:e.actor,from:e.from,to:e.to}}const s={q:void 0,types:void 0,actor:void 0,from:void 0,to:void 0},c={event:void 0,processors:void 0};export{o as i,s as n,c as r,a as t};
M dist/chunks/context-view.mjs
@@ -1,7 +1,7 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{At as r,C as i,Ot as a,T as o,g as s,kt as c}from"./vendor-icons";import{i as l,n as u,r as d}from"./context-view-search.mjs";import{c as f,i as p}from"./ui-base";import{Spinner as m}from"../components/ui/spinner";import{n as h,r as g}from"./read-progress.mjs";import{C as _,E as v,O as y,S as b,T as x,_ as S,a as C,b as ee,h as te,i as ne,o as re,r as ie,t as w,y as T}from"./ui-shell";import{lentStubKey as E}from"../lib/presence";import{n as ae,t as D}from"./vendor-yaml";import{CodeEditor as oe}from"../components/code-editor";import{n as se,r as ce,t as le}from"./virtual-log.mjs";import{SerializedObjectCodeBlock as O}from"../components/code-block";var k=/* @__PURE__ */ e(t(),1);const A=(e,t=``)=>typeof e==`string`?e:t,j=e=>Object.prototype.toString.call(e)===`[object Object]`,M=e=>j(e)?e:{};var N=/* @__PURE__ */ e(n(),1);function ue({type:e}){return e===`events.iterate.com/itx/woken`||e.startsWith(`events.iterate.com/itx/subscription-`)||e.startsWith(`events.iterate.com/itx/schedule-`)||e===`events.iterate.com/itx/live-state-changed`}const de={"events.iterate.com/itx/run-requested":e=>/* @__PURE__ */ (0,N.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted p-3 font-mono text-xs whitespace-pre-wrap break-words`,children:A(M(e.payload).code)}),"events.iterate.com/itx/run-settled":e=>{let t=M(M(e.payload).settlement);return t.status===`succeeded`?/* @__PURE__ */ (0,N.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted p-3 font-mono text-xs whitespace-pre-wrap break-words`,children:JSON.stringify(t.result??null,null,2)}):/* @__PURE__ */ (0,N.jsxs)(`p`,{"data-type":`error`,className:`text-sm text-destructive`,children:[A(t.failureKind),`: `,A(t.error)]})}};function P(e){return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`})}function fe(e){if(e<1e3)return`+${String(e)}ms`;if(e<6e4)return`+${(Math.floor(e/100)/10).toFixed(1).replace(/\.0$/,``)}s`;let t=Math.floor(e/1e3);if(t<3600)return`+${String(Math.floor(t/60))}m${String(t%60)}s`;let n=Math.floor(t/60);return`+${String(Math.floor(n/60))}h${String(n%60)}m`}const pe=e=>f(`flex w-full min-w-0 flex-wrap items-baseline gap-x-3.5 px-3 sm:px-4 py-[3px] text-left hover:bg-muted/60 max-sm:gap-x-2 max-sm:py-1.5 sm:flex-nowrap`,e&&`bg-muted shadow-[inset_2px_0_0_var(--color-foreground)] hover:bg-muted`);function me(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i].offset<t?n=i+1:r=i}let i=e[n]?.offset===t?e[n]:void 0,a=e[n-1],o=e[i?n+1:n];return i?{event:i,previous:a,next:o}:{previous:a,next:o,missing:o?a?`gap`:`below`:`above`}}function he(e,t){let n=Date.parse(t)-Date.parse(e);if(!Number.isNaN(n))return fe(Math.max(0,n))}const ge=[`type`,`payload`,`metadata`,`idempotencyKey`,`offset`,`createdAt`];function _e(e){let t=e,n={};for(let e of ge)e in t&&(n[e]=t[e]);for(let[e,r]of Object.entries(t))ge.includes(e)||(n[e]=r);return n}function ve(e){return e instanceof HTMLElement?e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e.isContentEditable:!1}function F(e){let t=ye.get(e);return t||(t=new Date(e.createdAt).toDateString(),ye.set(e,t)),t}const ye=/* @__PURE__ */ new WeakMap;function I(e,t=``){let n=[],r=t,i=0;for(;i<e.length;){let t=e[i],a=F(t);a!==r&&(n.push({kind:`day`,key:`day:${a}`,date:new Date(t.createdAt)}),r=a);let o=ue(t),s=i+1;for(;s<e.length&&F(e[s])===a&&(o?ue(e[s]):e[s].type===t.type);)s+=1;n.push(s-i===1?{kind:`event`,key:`event:${String(t.offset)}`,event:t}:{kind:`run`,key:`run:${String(t.offset)}`,events:e.slice(i,s)}),i=s}return n}function L(e,t,n=``){let r=n;return e.map(e=>{if(e.kind===`day`)return r=``,``;let n=r,i=R(e);return i&&t(i)&&(r=t(i)),n})}function R(e){if(e&&e.kind!==`day`)return e.kind===`event`?e.event:e.events.at(-1)}const be=e=>e.kind===`day`?0:e.kind===`event`?1:e.events.length;function z(e,t){if(t===e)return{end:[]};if(t.length<e.length)return null;if(e.length===0)return{end:t};let n=t.length-e.length;return t[0]===e[0]&&t[e.length-1]===e.at(-1)?{end:t.slice(e.length)}:t.at(-1)===e.at(-1)&&t[n]===e[0]?{start:t.slice(0,n)}:null}function xe(e,t,n){let r=e&&e.items.length>0?z(e.events,t):null;if(e&&r&&`end`in r){if(r.end.length===0)return{...e,events:t};let i=e.items.at(-1),a=e.events.length-be(i),o=I(t.slice(a),F(t[a]));return{events:t,items:e.items.slice(0,-1).concat(o),namedBefore:e.namedBefore.slice(0,-1).concat(L(o,n,e.namedBefore.at(-1)))}}if(e&&r&&`start`in r){let i=e.items[1],a=I(t.slice(0,r.start.length+be(i))).concat(e.items.slice(2));return{events:t,items:a,namedBefore:L(a,n)}}let i=I(t);return{events:t,items:i,namedBefore:L(i,n)}}function B(e,t){let n=t.query.trim().toLowerCase();return e.filter(e=>t.types.size>0&&!t.types.has(e.type)||t.actor&&e.source?.principal?.actor!==t.actor||t.from!==void 0&&e.offset<t.from||t.to!==void 0&&e.offset>t.to?!1:!n||e.type.toLowerCase().includes(n)||JSON.stringify(e.payload??null).toLowerCase().includes(n))}const V=e=>!!e.query.trim()||e.types.size>0||!!e.actor||e.from!==void 0||e.to!==void 0;function Se(e,t){return e.query.trim()===t.query.trim()&&e.actor===t.actor&&e.from===t.from&&e.to===t.to&&e.types.size===t.types.size&&[...e.types].every(e=>t.types.has(e))}function Ce(e,t,n){if(!V(n))return{events:t,filter:n,shown:t};let r=e&&V(e.filter)&&Se(e.filter,n)?z(e.events,t):null;return e&&r&&`end`in r?{events:t,filter:n,shown:r.end.length===0?e.shown:e.shown.concat(B(r.end,n))}:e&&r&&`start`in r?{events:t,filter:n,shown:B(r.start,n).concat(e.shown)}:{events:t,filter:n,shown:B(t,n)}}function we(e,t){let n=e?z(e.events,t):null;if(e&&n){let r=`end`in n?n.end:n.start;return r.length===0?{events:t,counts:e.counts}:{events:t,counts:Te(new Map(e.counts),r)}}return{events:t,counts:Te(/* @__PURE__ */ new Map,t)}}function Te(e,t){for(let n of t)e.set(n.type,(e.get(n.type)??0)+1);return e}function Ee(e){return[...e.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))}function De(e,t){let n=new Set(e.map(([e])=>e)),r=[...t].filter(e=>!n.has(e)).sort();return[...e,...r.map(e=>[e,0])]}function Oe(e){let t=e.trim();if(t===``)return;let n=Number(t.replace(/^#/,``));return Number.isFinite(n)?Math.max(0,Math.trunc(n)):null}const H=e=>e.replace(/^events\.iterate\.com\//,``);function ke(e,t=400){if(e===void 0)return``;if(Array.isArray(e))return`${String(e.length)} item${e.length===1?``:`s`}`;if(!j(e))return Ae(e);let n=[];for(let[t,r]of Object.entries(e)){if(n.length===8){n.push(`…`);break}n.push(`${t} ${Ae(r)}`)}let r=n.join(` · `);return r.length>t?`${r.slice(0,t-1)}…`:r}function Ae(e){if(typeof e==`string`){let t=e.split(` -`)[0]||``;return t.length>160?`${t.slice(0,159)}…`:t}if(Array.isArray(e))return`[${String(e.length)}]`;if(j(e)){let t=Object.keys(e);return`{${t.slice(0,3).join(`, `)}${t.length>3?`, …`:``}}`}return String(JSON.stringify(e))}const U=e=>e.source?.principal?.email||e.source?.principal?.actor||``;function je(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(n,(t.get(n)||0)+1);return[...t].map(([e,t])=>`${H(e)}${t>1?` ×${String(t)}`:``}`).join(`, `)}function Me(e,t){if(!e)return;if(e[t])return e[t];let n;for(let[r,i]of Object.entries(e)){if(!r.endsWith(`*`))continue;let e=r.slice(0,-1);t.startsWith(e)&&(!n||e.length>n.prefix.length)&&(n={prefix:e,entry:i})}return n?.entry}function Ne({events:e,offset:t,older:n,inspectors:r,onNavigate:i,onClose:a}){let o=t!==void 0,[s,c]=(0,k.useState)(t);t!==void 0&&t!==s&&c(t);let l=(0,k.useMemo)(()=>s===void 0?void 0:me(e,s),[e,s]),u=Pe({open:o,shown:s,place:l,older:n,onNavigate:i});return/* @__PURE__ */ (0,N.jsx)(S,{open:o,onOpenChange:e=>!e&&a(),children:/* @__PURE__ */ (0,N.jsx)(T,{side:`right`,className:`gap-0 p-0 data-[side=right]:w-full data-[side=right]:sm:max-w-3xl`,inert:!o,children:s===void 0?null:/* @__PURE__ */ (0,N.jsx)(Ie,{shown:s,open:o,loaded:e.length,place:l,paging:u,inspectors:r})})})}function Pe({open:e,shown:t,place:n,older:r,onNavigate:i}){let{previous:a,next:o,missing:s}=n||{},c=!r.exhausted,l=(0,k.useRef)(void 0),u=()=>{a?i(a.offset):c&&t!==void 0&&(l.current=t,r.loadOlder())},d=()=>o&&i(o.offset),f=(0,k.useEffectEvent)(()=>{let e=l.current;e!==void 0&&((e!==t||a||r.exhausted)&&(l.current=void 0),e===t&&a&&i(a.offset))});(0,k.useEffect)(()=>f(),[t,a,r.exhausted]);let p=e&&s===`below`&&c;(0,k.useEffect)(()=>{p&&!r.loading&&r.loadOlder()},[p,r]);let m=(0,k.useEffectEvent)(e=>{e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||ve(e.target)||(e.key===`ArrowLeft`&&(a||c)?(e.preventDefault(),u()):e.key===`ArrowRight`&&o&&(e.preventDefault(),d()))});return(0,k.useEffect)(()=>{if(!e)return;let t=e=>m(e);return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e]),{stepBack:u,stepForward:d,canStepBack:!!a||c,canStepForward:!!o,steppingBack:r.loading&&!a,readingDown:p}}function Fe(e){let{source:t}=e;return[[`Who`,U(e)],[`From`,t?.origin||``],[`Copy of`,t?.copiedFrom?`${H(t.copiedFrom.type)} #${t.copiedFrom.offset}${t.copiedFrom.subscription?` (row ${t.copiedFrom.subscription})`:``}`:``],[`Grant`,t?.grant||``],[`Processor`,t?.processor?`${t.processor.slug}@${t.processor.version}`:``]].filter(e=>!!e[1])}function Ie({shown:e,open:t,loaded:n,place:r,paging:i,inspectors:o}){let{event:s,previous:l,next:u,missing:d}=r||{};return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsxs)(b,{className:`shrink-0 pr-12`,children:[/* @__PURE__ */ (0,N.jsx)(_,{className:`line-clamp-2 text-sm break-all`,title:s?.type,children:s?H(s.type):`Event #${String(e)}`}),/* @__PURE__ */ (0,N.jsxs)(ee,{className:`text-xs tabular-nums`,children:[`#`,e,` · `,n.toLocaleString(),` loaded`,s?` · ${s.createdAt}`:``]})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 px-4 pb-3`,children:[/* @__PURE__ */ (0,N.jsxs)(p,{size:`sm`,variant:`outline`,disabled:!t||!i.canStepBack,onClick:i.stepBack,children:[i.steppingBack?/* @__PURE__ */ (0,N.jsx)(m,{}):/* @__PURE__ */ (0,N.jsx)(c,{}),`Prev`]}),/* @__PURE__ */ (0,N.jsxs)(p,{size:`sm`,variant:`outline`,disabled:!t||!i.canStepForward,onClick:i.stepForward,children:[`Next`,/* @__PURE__ */ (0,N.jsx)(a,{})]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden text-xs text-muted-foreground/70 sm:inline`,children:`← → page the log`}),/* @__PURE__ */ (0,N.jsx)(Le,{event:s,previous:l,next:u})]}),/* @__PURE__ */ (0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto border-t px-4 py-3`,children:s?/* @__PURE__ */ (0,N.jsx)(ze,{event:s,inspectors:o}):/* @__PURE__ */ (0,N.jsx)(Re,{shown:e,missing:d,readingDown:i.readingDown})})]})}function Le({event:e,previous:t,next:n}){let r=e&&t&&he(t.createdAt,e.createdAt),i=e&&n&&he(e.createdAt,n.createdAt);return/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 font-mono text-2xs text-muted-foreground`,children:[r?/* @__PURE__ */ (0,N.jsx)(`span`,{title:`Since the previous event`,children:r}):null,r&&i?/* @__PURE__ */ (0,N.jsx)(`span`,{children:`·`}):null,i?/* @__PURE__ */ (0,N.jsxs)(`span`,{title:`Until the next event`,children:[i,` to next`]}):null]})}function Re({shown:e,missing:t,readingDown:n}){return n?/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`flex items-center gap-2`,children:[/* @__PURE__ */ (0,N.jsx)(m,{}),` Reading older events to reach #`,e,`…`]})}):/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:t===`above`?`No event #${String(e)} yet.`:`No event has offset #${String(e)}. Prev and Next go to its neighbours.`})}function ze({event:e,inspectors:t}){let n=(0,k.useMemo)(()=>_e(e),[e]),r=Me(t,e.type)?.(e)??null,i=Fe(e);return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[r?/* @__PURE__ */ (0,N.jsx)(`div`,{className:`min-w-0`,children:r}):null,i.length>0?/* @__PURE__ */ (0,N.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs`,children:i.map(([e,t])=>/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`contents`,children:[/* @__PURE__ */ (0,N.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,N.jsx)(`dd`,{className:`min-w-0 truncate font-mono`,title:t,children:t})]},e))}):null,/* @__PURE__ */ (0,N.jsx)(`div`,{className:`min-w-0`,children:/* @__PURE__ */ (0,N.jsx)(O,{data:n})})]})}function Be(e){return e<1e4?`text-success`:e<6e4?`text-warning`:e<6e5?`text-destructive/70`:`text-destructive`}const Ve=`shrink-0 text-xs text-muted-foreground/60 tabular-nums sm:w-[var(--offset-width,6ch)] sm:text-right`,He=`shrink-0 text-xs text-muted-foreground tabular-nums sm:w-[8ch]`,Ue=`shrink-0 text-xs tabular-nums max-sm:empty:hidden sm:w-[7ch] sm:text-right`;function We({offset:e}){return/* @__PURE__ */ (0,N.jsxs)(`span`,{className:Ve,children:[`#`,e]})}function W({times:e}){return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`span`,{"aria-hidden":!0,className:f(Ve,`max-sm:hidden`)}),e?/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`span`,{"aria-hidden":!0,className:f(He,`max-sm:hidden`)}),/* @__PURE__ */ (0,N.jsx)(`span`,{"aria-hidden":!0,className:f(Ue,`max-sm:hidden`)})]}):null]})}function Ge({who:e}){return/* @__PURE__ */ (0,N.jsx)(`span`,{className:`max-w-48 min-w-0 truncate text-xs text-muted-foreground sm:ml-auto sm:shrink-0`,children:e})}function Ke({event:e,previous:t}){let n=Date.parse(e.createdAt),r=t?Math.max(0,n-Date.parse(t.createdAt)):void 0;return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`time`,{dateTime:e.createdAt,title:new Date(n).toISOString(),className:He,children:P(n)}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(Ue,r!==void 0&&Be(r)),title:`Since the row before`,children:r===void 0||r<1e3?``:fe(r)})]})}const qe=`min-w-0 flex-1 max-sm:order-first max-sm:basis-full`,Je=`flex min-w-0 items-baseline gap-x-3 text-sm leading-5 max-sm:flex-col`;function Ye({event:e}){let t=ke(e.payload);return/* @__PURE__ */ (0,N.jsxs)(`span`,{className:Je,children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 shrink-0 truncate max-sm:max-w-full sm:w-60`,title:e.type,"data-event-type":!0,children:H(e.type)}),t?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-muted-foreground max-sm:w-full`,children:t}):null]})}const Xe=(0,k.memo)(function({event:e,previous:t,showWho:n,selected:r,onOpen:i}){let a=U(e);return/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>i(e.offset),"data-offset":e.offset,className:pe(r),children:[/* @__PURE__ */ (0,N.jsx)(We,{offset:e.offset}),/* @__PURE__ */ (0,N.jsx)(Ke,{event:e,previous:t}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:qe,children:/* @__PURE__ */ (0,N.jsx)(Ye,{event:e})}),n&&a?/* @__PURE__ */ (0,N.jsx)(Ge,{who:a}):null]})}),Ze=(0,k.memo)(function({date:e}){let t=/* @__PURE__ */ new Date,n=/* @__PURE__ */ new Date(t.getTime()-864e5),r=e.toDateString()===t.toDateString()?`Today`:e.toDateString()===n.toDateString()?`Yesterday`:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`,month:`short`,year:e.getFullYear()===t.getFullYear()?void 0:`numeric`});return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex items-baseline gap-x-3.5 px-3 sm:px-4 pt-3 pb-1`,children:[/* @__PURE__ */ (0,N.jsx)(W,{}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs font-semibold text-foreground/75`,children:r})]})}),Qe=(0,k.memo)(function({itemKey:e,events:t,previous:n,showWho:i,open:o,onToggle:s}){let c=t[0],l=t.at(-1),u=U(c),d=o?r:a;return/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>s(e),"aria-expanded":o,"data-run":t.length,title:`${String(t.length)} events, ${P(Date.parse(c.createdAt))} to ${P(Date.parse(l.createdAt))}`,className:pe(),children:[/* @__PURE__ */ (0,N.jsx)(We,{offset:c.offset}),/* @__PURE__ */ (0,N.jsx)(Ke,{event:c,previous:n}),/* @__PURE__ */ (0,N.jsxs)(`span`,{className:f(qe,Je,`gap-x-1.5 max-sm:flex-row`),children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 truncate tabular-nums`,children:je(t.map(e=>e.type))}),/* @__PURE__ */ (0,N.jsx)(d,{className:`size-3 shrink-0 self-center text-muted-foreground`})]}),i&&u?/* @__PURE__ */ (0,N.jsx)(Ge,{who:u}):null]})});function $e({items:e,namedBefore:t,inspected:n,onInspect:r,opened:i,onToggle:a,older:o,logShare:s,followTail:c,arrivals:l,columnClassName:u,empty:d,footer:f}){let{rows:p,itemIndexOf:m}=(0,k.useMemo)(()=>{if(i.size===0)return{rows:e,itemIndexOf:null};let t=[],n=[];return e.forEach((r,a)=>{t.push(r),n.push(a),r.kind!==`day`&&r.kind!==`event`&&i.has(r.key)&&r.events.forEach((i,o)=>{t.push({kind:`member`,key:`${r.key}/${String(i.offset)}`,event:i,previous:o===0?R(e[a-1]):r.events[o-1]}),n.push(-1)})}),{rows:t,itemIndexOf:n}},[e,i]),h=(0,k.useMemo)(()=>({key:e=>e.key,estimateSize:e=>e.kind===`day`?36:26,offset:e=>e.kind===`member`?e.event.offset:R(e)?.offset}),[]);return/* @__PURE__ */ (0,N.jsx)(le,{rows:p,rowInfo:h,renderRow:_,older:o,readingOlder:/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-x-3.5 px-3 sm:px-4`,children:[/* @__PURE__ */ (0,N.jsx)(W,{times:!0}),/* @__PURE__ */ (0,N.jsx)(g,{label:`Loading older events`,value:s})]}),empty:d,label:`Events`,arrivals:l,footer:f,columnClassName:u,followTail:c,reveal:n,paddingStart:4,paddingEnd:8});function _(o,s){if(o.kind===`member`)return/* @__PURE__ */ (0,N.jsx)(Xe,{event:o.event,previous:o.previous,showWho:!1,selected:n===o.event.offset,onOpen:r});if(o.kind===`day`)return/* @__PURE__ */ (0,N.jsx)(Ze,{date:o.date});let c=m?m[s]:s,l=R(e[c-1]),u=o.kind===`event`?o.event:o.events[0],d=U(u)!==t[c];return o.kind===`run`?/* @__PURE__ */ (0,N.jsx)(Qe,{itemKey:o.key,events:o.events,previous:l,showWho:d,open:i.has(o.key),onToggle:a}):/* @__PURE__ */ (0,N.jsx)(Xe,{event:o.event,previous:l,showWho:d,selected:n===o.event.offset,onOpen:r})}}function et(e,t){let n=/* @__PURE__ */ new Map;for(let e of t)for(let t of e.consumes||[])t.includes(`*`)||n.set(t,[...n.get(t)||[],e.name]);let r=new Map(e),i=[...n.keys()].sort().map(e=>({type:e,section:`Consumed here`,detail:`${n.get(e).join(`, `)}${r.has(e)?` · ${tt(r.get(e))}`:``}`}));for(let[t,r]of e)n.has(t)||i.push({type:t,section:`In the log`,detail:tt(r)});return i}const tt=e=>`${e.toLocaleString()} in the log`,nt=[{key:`type`,detail:`the event type`},{key:`payload`,detail:`a mapping`},{key:`metadata`,detail:`a mapping`},{key:`idempotencyKey`,detail:`appends once per key`}];function rt(e,t,n,r){let i=e.lastIndexOf(` +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{At as r,C as i,T as a,g as o,jt as s,kt as c}from"./vendor-icons";import{i as l,n as u,r as d}from"./context-view-search.mjs";import{c as f,i as p}from"./ui-base";import{Spinner as m}from"../components/ui/spinner";import{n as h,r as g}from"./read-progress.mjs";import{C as _,E as v,O as y,S as b,T as x,_ as S,a as C,b as ee,h as te,i as ne,o as re,r as ie,t as w,y as T}from"./ui-shell";import{lentStubKey as E}from"../lib/presence";import{n as ae,t as D}from"./vendor-yaml";import{CodeEditor as oe}from"../components/code-editor";import{i as se,r as ce,t as le}from"./virtual-log.mjs";import{SerializedObjectCodeBlock as O}from"../components/code-block";var k=/* @__PURE__ */ e(t(),1);const A=(e,t=``)=>typeof e==`string`?e:t,j=e=>Object.prototype.toString.call(e)===`[object Object]`,M=e=>j(e)?e:{};var N=/* @__PURE__ */ e(n(),1);function ue({type:e}){return e===`events.iterate.com/itx/woken`||e.startsWith(`events.iterate.com/itx/subscription-`)||e.startsWith(`events.iterate.com/itx/schedule-`)||e===`events.iterate.com/itx/live-state-changed`}const de={"events.iterate.com/itx/run-requested":e=>/* @__PURE__ */ (0,N.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted p-3 font-mono text-xs whitespace-pre-wrap break-words`,children:A(M(e.payload).code)}),"events.iterate.com/itx/run-settled":e=>{let t=M(M(e.payload).settlement);return t.status===`succeeded`?/* @__PURE__ */ (0,N.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted p-3 font-mono text-xs whitespace-pre-wrap break-words`,children:JSON.stringify(t.result??null,null,2)}):/* @__PURE__ */ (0,N.jsxs)(`p`,{"data-type":`error`,className:`text-sm text-destructive`,children:[A(t.failureKind),`: `,A(t.error)]})}};function P(e){return new Date(e).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hourCycle:`h23`})}function fe(e){if(e<1e3)return`+${String(e)}ms`;if(e<6e4)return`+${(Math.floor(e/100)/10).toFixed(1).replace(/\.0$/,``)}s`;let t=Math.floor(e/1e3);if(t<3600)return`+${String(Math.floor(t/60))}m${String(t%60)}s`;let n=Math.floor(t/60);return`+${String(Math.floor(n/60))}h${String(n%60)}m`}const pe=e=>f(`flex w-full min-w-0 flex-wrap items-baseline gap-x-2 px-2.5 py-[3px] text-left hover:bg-muted/60 @max-md:py-1 @md:flex-nowrap @2xl:px-4 @3xl:gap-x-3.5`,e&&`bg-muted shadow-[inset_2px_0_0_var(--color-foreground)] hover:bg-muted`);function me(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i].offset<t?n=i+1:r=i}let i=e[n]?.offset===t?e[n]:void 0,a=e[n-1],o=e[i?n+1:n];return i?{event:i,previous:a,next:o}:{previous:a,next:o,missing:o?a?`gap`:`below`:`above`}}function he(e,t){let n=Date.parse(t)-Date.parse(e);if(!Number.isNaN(n))return fe(Math.max(0,n))}const ge=[`type`,`payload`,`metadata`,`idempotencyKey`,`offset`,`createdAt`];function _e(e){let t=e,n={};for(let e of ge)e in t&&(n[e]=t[e]);for(let[e,r]of Object.entries(t))ge.includes(e)||(n[e]=r);return n}function ve(e){return e instanceof HTMLElement?e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement||e.isContentEditable:!1}function F(e){let t=ye.get(e);return t||(t=new Date(e.createdAt).toDateString(),ye.set(e,t)),t}const ye=/* @__PURE__ */ new WeakMap;function I(e,t=``){let n=[],r=t,i=0;for(;i<e.length;){let t=e[i],a=F(t);a!==r&&(n.push({kind:`day`,key:`day:${a}`,date:new Date(t.createdAt)}),r=a);let o=ue(t),s=i+1;for(;s<e.length&&F(e[s])===a&&(o?ue(e[s]):e[s].type===t.type);)s+=1;n.push(s-i===1?{kind:`event`,key:`event:${String(t.offset)}`,event:t}:{kind:`run`,key:`run:${String(t.offset)}`,events:e.slice(i,s)}),i=s}return n}function L(e,t,n=``){let r=n;return e.map(e=>{if(e.kind===`day`)return r=``,``;let n=r,i=R(e);return i&&t(i)&&(r=t(i)),n})}function R(e){if(e&&e.kind!==`day`)return e.kind===`event`?e.event:e.events.at(-1)}const be=e=>e.kind===`day`?0:e.kind===`event`?1:e.events.length;function z(e,t){if(t===e)return{end:[]};if(t.length<e.length)return null;if(e.length===0)return{end:t};let n=t.length-e.length;return t[0]===e[0]&&t[e.length-1]===e.at(-1)?{end:t.slice(e.length)}:t.at(-1)===e.at(-1)&&t[n]===e[0]?{start:t.slice(0,n)}:null}function xe(e,t,n){let r=e&&e.items.length>0?z(e.events,t):null;if(e&&r&&`end`in r){if(r.end.length===0)return{...e,events:t};let i=e.items.at(-1),a=e.events.length-be(i),o=I(t.slice(a),F(t[a]));return{events:t,items:e.items.slice(0,-1).concat(o),namedBefore:e.namedBefore.slice(0,-1).concat(L(o,n,e.namedBefore.at(-1)))}}if(e&&r&&`start`in r){let i=e.items[1],a=I(t.slice(0,r.start.length+be(i))).concat(e.items.slice(2));return{events:t,items:a,namedBefore:L(a,n)}}let i=I(t);return{events:t,items:i,namedBefore:L(i,n)}}function B(e,t){let n=t.query.trim().toLowerCase();return e.filter(e=>t.types.size>0&&!t.types.has(e.type)||t.actor&&e.source?.principal?.actor!==t.actor||t.from!==void 0&&e.offset<t.from||t.to!==void 0&&e.offset>t.to?!1:!n||e.type.toLowerCase().includes(n)||JSON.stringify(e.payload??null).toLowerCase().includes(n))}const V=e=>!!e.query.trim()||e.types.size>0||!!e.actor||e.from!==void 0||e.to!==void 0;function Se(e,t){return e.query.trim()===t.query.trim()&&e.actor===t.actor&&e.from===t.from&&e.to===t.to&&e.types.size===t.types.size&&[...e.types].every(e=>t.types.has(e))}function Ce(e,t,n){if(!V(n))return{events:t,filter:n,shown:t};let r=e&&V(e.filter)&&Se(e.filter,n)?z(e.events,t):null;return e&&r&&`end`in r?{events:t,filter:n,shown:r.end.length===0?e.shown:e.shown.concat(B(r.end,n))}:e&&r&&`start`in r?{events:t,filter:n,shown:B(r.start,n).concat(e.shown)}:{events:t,filter:n,shown:B(t,n)}}function we(e,t){let n=e?z(e.events,t):null;if(e&&n){let r=`end`in n?n.end:n.start;return r.length===0?{events:t,counts:e.counts}:{events:t,counts:Te(new Map(e.counts),r)}}return{events:t,counts:Te(/* @__PURE__ */ new Map,t)}}function Te(e,t){for(let n of t)e.set(n.type,(e.get(n.type)??0)+1);return e}function Ee(e){return[...e.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0]))}function De(e,t){let n=new Set(e.map(([e])=>e)),r=[...t].filter(e=>!n.has(e)).sort();return[...e,...r.map(e=>[e,0])]}function Oe(e){let t=e.trim();if(t===``)return;let n=Number(t.replace(/^#/,``));return Number.isFinite(n)?Math.max(0,Math.trunc(n)):null}const H=e=>e.replace(/^events\.iterate\.com\//,``);function ke(e,t=400){if(e===void 0)return``;if(Array.isArray(e))return`${String(e.length)} item${e.length===1?``:`s`}`;if(!j(e))return Ae(e);let n=[];for(let[t,r]of Object.entries(e)){if(n.length===8){n.push(`…`);break}n.push(`${t} ${Ae(r)}`)}let r=n.join(` · `);return r.length>t?`${r.slice(0,t-1)}…`:r}function Ae(e){if(typeof e==`string`){let t=e.split(` +`)[0]||``;return t.length>160?`${t.slice(0,159)}…`:t}if(Array.isArray(e))return`[${String(e.length)}]`;if(j(e)){let t=Object.keys(e);return`{${t.slice(0,3).join(`, `)}${t.length>3?`, …`:``}}`}return String(JSON.stringify(e))}const U=e=>e.source?.principal?.email||e.source?.principal?.actor||``;function je(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(n,(t.get(n)||0)+1);return[...t].map(([e,t])=>`${H(e)}${t>1?` ×${String(t)}`:``}`).join(`, `)}function Me(e,t){if(!e)return;if(e[t])return e[t];let n;for(let[r,i]of Object.entries(e)){if(!r.endsWith(`*`))continue;let e=r.slice(0,-1);t.startsWith(e)&&(!n||e.length>n.prefix.length)&&(n={prefix:e,entry:i})}return n?.entry}function Ne({events:e,offset:t,older:n,inspectors:r,onNavigate:i,onClose:a}){let o=t!==void 0,[s,c]=(0,k.useState)(t);t!==void 0&&t!==s&&c(t);let l=(0,k.useMemo)(()=>s===void 0?void 0:me(e,s),[e,s]),u=Pe({open:o,shown:s,place:l,older:n,onNavigate:i});return/* @__PURE__ */ (0,N.jsx)(S,{open:o,onOpenChange:e=>!e&&a(),children:/* @__PURE__ */ (0,N.jsx)(T,{side:`right`,className:`gap-0 p-0 data-[side=right]:w-full data-[side=right]:sm:max-w-3xl`,inert:!o,children:s===void 0?null:/* @__PURE__ */ (0,N.jsx)(Ie,{shown:s,open:o,loaded:e.length,place:l,paging:u,inspectors:r})})})}function Pe({open:e,shown:t,place:n,older:r,onNavigate:i}){let{previous:a,next:o,missing:s}=n||{},c=!r.exhausted,l=(0,k.useRef)(void 0),u=()=>{a?i(a.offset):c&&t!==void 0&&(l.current=t,r.loadOlder())},d=()=>o&&i(o.offset),f=(0,k.useEffectEvent)(()=>{let e=l.current;e!==void 0&&((e!==t||a||r.exhausted)&&(l.current=void 0),e===t&&a&&i(a.offset))});(0,k.useEffect)(()=>f(),[t,a,r.exhausted]);let p=e&&s===`below`&&c;(0,k.useEffect)(()=>{p&&!r.loading&&r.loadOlder()},[p,r]);let m=(0,k.useEffectEvent)(e=>{e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||ve(e.target)||(e.key===`ArrowLeft`&&(a||c)?(e.preventDefault(),u()):e.key===`ArrowRight`&&o&&(e.preventDefault(),d()))});return(0,k.useEffect)(()=>{if(!e)return;let t=e=>m(e);return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[e]),{stepBack:u,stepForward:d,canStepBack:!!a||c,canStepForward:!!o,steppingBack:r.loading&&!a,readingDown:p}}function Fe(e){let{source:t}=e;return[[`Who`,U(e)],[`From`,t?.origin||``],[`Copy of`,t?.copiedFrom?`${H(t.copiedFrom.type)} #${t.copiedFrom.offset}${t.copiedFrom.subscription?` (row ${t.copiedFrom.subscription})`:``}`:``],[`Grant`,t?.grant||``],[`Processor`,t?.processor?`${t.processor.slug}@${t.processor.version}`:``]].filter(e=>!!e[1])}function Ie({shown:e,open:t,loaded:n,place:i,paging:a,inspectors:o}){let{event:s,previous:l,next:u,missing:d}=i||{};return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsxs)(b,{className:`shrink-0 pr-12`,children:[/* @__PURE__ */ (0,N.jsx)(_,{className:`line-clamp-2 text-sm break-all`,title:s?.type,children:s?H(s.type):`Event #${String(e)}`}),/* @__PURE__ */ (0,N.jsxs)(ee,{className:`text-xs tabular-nums`,children:[`#`,e,` · `,n.toLocaleString(),` loaded`,s?` · ${s.createdAt}`:``]})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2 px-4 pb-3`,children:[/* @__PURE__ */ (0,N.jsxs)(p,{size:`sm`,variant:`outline`,disabled:!t||!a.canStepBack,onClick:a.stepBack,children:[a.steppingBack?/* @__PURE__ */ (0,N.jsx)(m,{}):/* @__PURE__ */ (0,N.jsx)(r,{}),`Prev`]}),/* @__PURE__ */ (0,N.jsxs)(p,{size:`sm`,variant:`outline`,disabled:!t||!a.canStepForward,onClick:a.stepForward,children:[`Next`,/* @__PURE__ */ (0,N.jsx)(c,{})]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden text-xs text-muted-foreground/70 sm:inline`,children:`← → page the log`}),/* @__PURE__ */ (0,N.jsx)(Le,{event:s,previous:l,next:u})]}),/* @__PURE__ */ (0,N.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto border-t px-4 py-3`,children:s?/* @__PURE__ */ (0,N.jsx)(ze,{event:s,inspectors:o}):/* @__PURE__ */ (0,N.jsx)(Re,{shown:e,missing:d,readingDown:a.readingDown})})]})}function Le({event:e,previous:t,next:n}){let r=e&&t&&he(t.createdAt,e.createdAt),i=e&&n&&he(e.createdAt,n.createdAt);return/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 font-mono text-2xs text-muted-foreground`,children:[r?/* @__PURE__ */ (0,N.jsx)(`span`,{title:`Since the previous event`,children:r}):null,r&&i?/* @__PURE__ */ (0,N.jsx)(`span`,{children:`·`}):null,i?/* @__PURE__ */ (0,N.jsxs)(`span`,{title:`Until the next event`,children:[i,` to next`]}):null]})}function Re({shown:e,missing:t,readingDown:n}){return n?/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`flex items-center gap-2`,children:[/* @__PURE__ */ (0,N.jsx)(m,{}),` Reading older events to reach #`,e,`…`]})}):/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-sm text-muted-foreground`,children:t===`above`?`No event #${String(e)} yet.`:`No event has offset #${String(e)}. Prev and Next go to its neighbours.`})}function ze({event:e,inspectors:t}){let n=(0,k.useMemo)(()=>_e(e),[e]),r=Me(t,e.type)?.(e)??null,i=Fe(e);return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[r?/* @__PURE__ */ (0,N.jsx)(`div`,{className:`min-w-0`,children:r}):null,i.length>0?/* @__PURE__ */ (0,N.jsx)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-4 gap-y-1 text-xs`,children:i.map(([e,t])=>/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`contents`,children:[/* @__PURE__ */ (0,N.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,N.jsx)(`dd`,{className:`min-w-0 truncate font-mono`,title:t,children:t})]},e))}):null,/* @__PURE__ */ (0,N.jsx)(`div`,{className:`min-w-0`,children:/* @__PURE__ */ (0,N.jsx)(O,{data:n})})]})}function Be(e){return e<1e4?`text-success`:e<6e4?`text-warning`:e<6e5?`text-destructive/70`:`text-destructive`}const Ve=`shrink-0 text-xs text-muted-foreground/60 tabular-nums @md:w-[var(--offset-width,6ch)] @md:text-right`,He=`shrink-0 text-xs text-muted-foreground tabular-nums @3xl:w-[8ch]`,Ue=`shrink-0 text-xs tabular-nums empty:hidden @3xl:empty:inline @3xl:w-[7ch] @3xl:text-right`;function We({offset:e}){return/* @__PURE__ */ (0,N.jsxs)(`span`,{className:Ve,children:[`#`,e]})}function W({times:e}){return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`span`,{"aria-hidden":!0,className:f(Ve,`@max-md:hidden`)}),e?/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`span`,{"aria-hidden":!0,className:f(He,`@max-md:hidden`)}),/* @__PURE__ */ (0,N.jsx)(`span`,{"aria-hidden":!0,className:f(Ue,`@max-3xl:hidden`)})]}):null]})}function Ge({who:e}){return/* @__PURE__ */ (0,N.jsx)(`span`,{className:`max-w-36 min-w-0 truncate text-xs text-muted-foreground @md:ml-auto @md:shrink-0 @3xl:max-w-48`,children:e})}function Ke({event:e,previous:t}){let n=Date.parse(e.createdAt),r=t?Math.max(0,n-Date.parse(t.createdAt)):void 0;return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`time`,{dateTime:e.createdAt,title:new Date(n).toISOString(),className:He,children:P(n)}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(Ue,r!==void 0&&Be(r)),title:`Since the row before`,children:r===void 0||r<1e3?``:fe(r)})]})}const qe=`min-w-0 flex-1 @max-md:order-first @max-md:basis-full`,Je=`flex min-w-0 items-baseline gap-x-2 text-sm leading-5 @3xl:gap-x-3`;function Ye({event:e}){let t=ke(e.payload);return/* @__PURE__ */ (0,N.jsxs)(`span`,{className:Je,children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 shrink-0 truncate @max-md:max-w-[65%] @md:max-w-[13.5rem] @3xl:w-60 @3xl:max-w-none`,title:e.type,"data-event-type":!0,children:H(e.type)}),t?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-muted-foreground`,children:t}):null]})}const Xe=(0,k.memo)(function({event:e,previous:t,showWho:n,selected:r,onOpen:i}){let a=U(e);return/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>i(e.offset),"data-offset":e.offset,className:pe(r),children:[/* @__PURE__ */ (0,N.jsx)(We,{offset:e.offset}),/* @__PURE__ */ (0,N.jsx)(Ke,{event:e,previous:t}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:qe,children:/* @__PURE__ */ (0,N.jsx)(Ye,{event:e})}),n&&a?/* @__PURE__ */ (0,N.jsx)(Ge,{who:a}):null]})}),Ze=(0,k.memo)(function({date:e}){let t=/* @__PURE__ */ new Date,n=/* @__PURE__ */ new Date(t.getTime()-864e5),r=e.toDateString()===t.toDateString()?`Today`:e.toDateString()===n.toDateString()?`Yesterday`:e.toLocaleDateString(void 0,{weekday:`short`,day:`numeric`,month:`short`,year:e.getFullYear()===t.getFullYear()?void 0:`numeric`});return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex items-baseline gap-x-2 px-2.5 pt-3 pb-1 @2xl:px-4 @3xl:gap-x-3.5`,children:[/* @__PURE__ */ (0,N.jsx)(W,{}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs font-semibold text-foreground/75`,children:r})]})}),Qe=(0,k.memo)(function({itemKey:e,events:t,previous:n,showWho:r,open:i,onToggle:a}){let o=t[0],l=t.at(-1),u=U(o),d=i?s:c;return/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>a(e),"aria-expanded":i,"data-run":t.length,title:`${String(t.length)} events, ${P(Date.parse(o.createdAt))} to ${P(Date.parse(l.createdAt))}`,className:pe(),children:[/* @__PURE__ */ (0,N.jsx)(We,{offset:o.offset}),/* @__PURE__ */ (0,N.jsx)(Ke,{event:o,previous:n}),/* @__PURE__ */ (0,N.jsxs)(`span`,{className:f(qe,Je,`gap-x-1.5`),children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 truncate tabular-nums`,children:je(t.map(e=>e.type))}),/* @__PURE__ */ (0,N.jsx)(d,{className:`size-3 shrink-0 self-center text-muted-foreground`})]}),r&&u?/* @__PURE__ */ (0,N.jsx)(Ge,{who:u}):null]})});function $e({items:e,namedBefore:t,inspected:n,onInspect:r,opened:i,onToggle:a,older:o,logShare:s,followTail:c,arrivals:l,columnClassName:u,empty:d,footer:f}){let{rows:p,itemIndexOf:m}=(0,k.useMemo)(()=>{if(i.size===0)return{rows:e,itemIndexOf:null};let t=[],n=[];return e.forEach((r,a)=>{t.push(r),n.push(a),r.kind!==`day`&&r.kind!==`event`&&i.has(r.key)&&r.events.forEach((i,o)=>{t.push({kind:`member`,key:`${r.key}/${String(i.offset)}`,event:i,previous:o===0?R(e[a-1]):r.events[o-1]}),n.push(-1)})}),{rows:t,itemIndexOf:n}},[e,i]),h=(0,k.useMemo)(()=>({key:e=>e.key,estimateSize:e=>e.kind===`day`?36:26,offset:e=>e.kind===`member`?e.event.offset:R(e)?.offset}),[]);return/* @__PURE__ */ (0,N.jsx)(le,{rows:p,rowInfo:h,renderRow:_,older:o,readingOlder:/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-x-3.5 px-3 sm:px-4`,children:[/* @__PURE__ */ (0,N.jsx)(W,{times:!0}),/* @__PURE__ */ (0,N.jsx)(g,{label:`Loading older events`,value:s})]}),empty:d,label:`Events`,arrivals:l,footer:f,columnClassName:u,followTail:c,reveal:n,paddingStart:4,paddingEnd:8});function _(o,s){if(o.kind===`member`)return/* @__PURE__ */ (0,N.jsx)(Xe,{event:o.event,previous:o.previous,showWho:!1,selected:n===o.event.offset,onOpen:r});if(o.kind===`day`)return/* @__PURE__ */ (0,N.jsx)(Ze,{date:o.date});let c=m?m[s]:s,l=R(e[c-1]),u=o.kind===`event`?o.event:o.events[0],d=U(u)!==t[c];return o.kind===`run`?/* @__PURE__ */ (0,N.jsx)(Qe,{itemKey:o.key,events:o.events,previous:l,showWho:d,open:i.has(o.key),onToggle:a}):/* @__PURE__ */ (0,N.jsx)(Xe,{event:o.event,previous:l,showWho:d,selected:n===o.event.offset,onOpen:r})}}function et(e,t){let n=/* @__PURE__ */ new Map;for(let e of t)for(let t of e.consumes||[])t.includes(`*`)||n.set(t,[...n.get(t)||[],e.name]);let r=new Map(e),i=[...n.keys()].sort().map(e=>({type:e,section:`Consumed here`,detail:`${n.get(e).join(`, `)}${r.has(e)?` · ${tt(r.get(e))}`:``}`}));for(let[t,r]of e)n.has(t)||i.push({type:t,section:`In the log`,detail:tt(r)});return i}const tt=e=>`${e.toLocaleString()} in the log`,nt=[{key:`type`,detail:`the event type`},{key:`payload`,detail:`a mapping`},{key:`metadata`,detail:`a mapping`},{key:`idempotencyKey`,detail:`appends once per key`}];function rt(e,t,n,r){let i=e.lastIndexOf(` `,t-1)+1,a=e.slice(i,t),o=/^(?:\s*-\s+|\s*)type:\s*["']?([\w./@-]*)$/.exec(a);if(o)return{from:t-o[1].length,validFor:/^[\w./@-]*$/,options:r.map(({type:e,detail:t,section:n},r)=>({label:e,boost:Math.max(-99,99-r),displayLabel:H(e),detail:t,section:n}))};let s=/^\s*-/.test(e),c=(s?/^(?:- | {2})([A-Za-z]*)$/:/^([A-Za-z]*)$/).exec(a);if(!c||!c[1]&&!n)return null;let l=s?` `:``,u=s?/* @__PURE__ */ new Set:new Set(e.match(/^[A-Za-z]+(?=:)/gm));return{from:t-c[1].length,validFor:/^[A-Za-z]*$/,options:nt.filter(({key:e})=>!u.has(e)).map(({key:e,detail:t})=>({label:e,detail:t,apply:e===`payload`||e===`metadata`?`${e}:\n${l} `:`${e}: `}))}}const it=/* @__PURE__ */ new Set([`type`,`payload`,`metadata`,`idempotencyKey`]);function at(e){let t;try{t=D(e)}catch(e){return{error:`Not YAML: ${e instanceof Error?e.message:String(e)}`}}if(t==null)return{error:`Nothing to append.`};let n=Array.isArray(t)?t:[t];if(n.length===0)return{error:`Nothing to append.`};let r=[];for(let[e,i]of n.entries()){let n=Array.isArray(t)?`Event ${String(e+1)}: `:``;if(!G(i))return{error:`${n}an event is a mapping with a \`type\`.`};let a=Object.keys(i).find(e=>!it.has(e));if(a)return{error:`${n}unknown field \`${a}\`.`};let{type:o,payload:s,metadata:c,idempotencyKey:l}=i;if(typeof o!=`string`||o.trim()===``)return{error:`${n}\`type\` must be a non-empty string.`};if(s!==void 0&&!G(s))return{error:`${n}\`payload\` must be a mapping.`};if(c!==void 0&&!G(c))return{error:`${n}\`metadata\` must be a mapping.`};if(l!==void 0&&typeof l!=`string`)return{error:`${n}\`idempotencyKey\` must be a string.`};r.push({type:o,payload:s,metadata:c,idempotencyKey:l})}return{events:r}}function ot(e){return ae({type:e,payload:{}})}function st(e){let t=/* @__PURE__ */ new Map;for(let n of[...e].sort((e,t)=>e.name.localeCompare(t.name))){let e=[...new Set(n.consumes||[])].filter(e=>!e.includes(`*`)).sort(),r=e.join(` -`),i=t.get(r)||{names:[],types:e};i.names.push(n.name),t.set(r,i)}let n=/* @__PURE__ */ new Set,r=[];for(let{names:e,types:i}of t.values()){let t=i.filter(e=>!n.has(e));for(let e of t)n.add(e);if(t.length===0)continue;let a=e.length>1?`${e[0]} +${String(e.length-1)}`:e[0];r.push({label:a,types:t})}return r}function G(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function K(e){let t;return(...n)=>t=e(t,...n)}function ct({onAppend:e,onAppended:t,events:n,processors:r}){let[i,a]=(0,k.useState)(!1),[c,l]=(0,k.useState)(`type: manual/note-added +`),i=t.get(r)||{names:[],types:e};i.names.push(n.name),t.set(r,i)}let n=/* @__PURE__ */ new Set,r=[];for(let{names:e,types:i}of t.values()){let t=i.filter(e=>!n.has(e));for(let e of t)n.add(e);if(t.length===0)continue;let a=e.length>1?`${e[0]} +${String(e.length-1)}`:e[0];r.push({label:a,types:t})}return r}function G(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function K(e){let t;return(...n)=>t=e(t,...n)}function ct({onAppend:e,onAppended:t,events:n,processors:r}){let[i,s]=(0,k.useState)(!1),[c,l]=(0,k.useState)(`type: manual/note-added payload: text: Hello -`),[u,d]=(0,k.useState)(!1),[f,h]=(0,k.useState)(),g=(0,k.useMemo)(()=>st(r),[r]),[_]=(0,k.useState)(()=>K(we)),v=(0,k.useMemo)(()=>i?et(Ee(_(n).counts),r):[],[i,_,n,r]),y=e=>{l(e),h(void 0)},b=c.trim()===``,x=async()=>{if(u||b)return;let n=at(c);if(`error`in n)return h(n);d(!0);try{await e(n.events),h({appended:n.events.length}),t()}catch(e){h({error:e instanceof Error?e.message:String(e)})}finally{d(!1)}};return i?/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex gap-x-3.5 border-t px-3 sm:px-4 pt-2 pb-1`,"data-slot":`append-composer`,children:[/* @__PURE__ */ (0,N.jsx)(W,{times:!0}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[/* @__PURE__ */ (0,N.jsx)(oe,{value:c,onValueChange:y,onSubmit:()=>void x(),language:`yaml`,label:`Events to append`,placeholder:`type: manual/note-added (a YAML list appends several)`,focusOnMount:!0,complete:(e,t,n)=>rt(e,t,n,v)}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[g.length>0?/* @__PURE__ */ (0,N.jsxs)(w,{children:[/* @__PURE__ */ (0,N.jsxs)(te,{render:/* @__PURE__ */ (0,N.jsx)(p,{variant:`ghost`,size:`sm`}),children:[/* @__PURE__ */ (0,N.jsx)(s,{}),` Examples`]}),/* @__PURE__ */ (0,N.jsx)(ie,{align:`start`,side:`top`,className:`w-auto max-w-80`,children:g.map(e=>/* @__PURE__ */ (0,N.jsxs)(ne,{children:[/* @__PURE__ */ (0,N.jsx)(re,{className:`truncate`,children:e.label}),e.types.map(e=>/* @__PURE__ */ (0,N.jsx)(C,{title:e,onClick:()=>y(ot(e)),className:`font-mono text-xs`,children:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`truncate`,children:H(e)})},e))]},e.label))})]}):null,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs`,role:`status`,children:f&&`error`in f?/* @__PURE__ */ (0,N.jsx)(`span`,{"data-type":`error`,className:`text-destructive`,title:f.error,children:f.error}):f?/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Appended `,f.appended===1?`1 event`:`${String(f.appended)} events`]}):/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden text-muted-foreground sm:inline`,children:`YAML or JSON · Tab completes · ⌘↵ appends`})}),/* @__PURE__ */ (0,N.jsx)(p,{variant:`ghost`,size:`sm`,onClick:()=>a(!1),children:`Close`}),/* @__PURE__ */ (0,N.jsxs)(p,{size:`sm`,onClick:()=>void x(),disabled:u||b,title:`Append events (⌘↵)`,children:[u?/* @__PURE__ */ (0,N.jsx)(m,{}):null,` Append`]})]})]})]}):/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex items-center gap-x-3.5 px-3 sm:px-4 py-1`,children:[/* @__PURE__ */ (0,N.jsx)(W,{times:!0}),/* @__PURE__ */ (0,N.jsxs)(p,{variant:`ghost`,size:`sm`,className:`-ml-2`,onClick:()=>a(!0),children:[/* @__PURE__ */ (0,N.jsx)(o,{}),` Append event`]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:`YAML · ⌘↵`})]})}function lt({filter:e,counts:t,narrowed:n,partial:r,loaded:a,onStateChange:o}){let s=(0,k.useCallback)(e=>e?.focus(),[]),c=t=>{let n=e.types.has(t)?[...e.types].filter(e=>e!==t):[...e.types,t];o({types:n.length>0?n:void 0})};return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-slot":`filter-row`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[/* @__PURE__ */ (0,N.jsxs)(x,{className:`h-8 min-w-48 flex-1`,children:[/* @__PURE__ */ (0,N.jsx)(v,{children:/* @__PURE__ */ (0,N.jsx)(i,{})}),/* @__PURE__ */ (0,N.jsx)(y,{ref:s,value:e.query,onChange:e=>o({q:e.target.value||void 0}),onKeyDown:t=>{t.key===`Escape`&&e.query&&o({q:void 0})},placeholder:`Search type or payload`,"aria-label":`Search type or payload`,className:`text-base sm:text-sm`})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,title:`Only the events between these offsets, inclusive`,children:[/* @__PURE__ */ (0,N.jsx)(`span`,{children:`from`}),/* @__PURE__ */ (0,N.jsx)(ut,{label:`From offset`,value:e.from,onChange:e=>o({from:e})}),/* @__PURE__ */ (0,N.jsx)(`span`,{children:`to`}),/* @__PURE__ */ (0,N.jsx)(ut,{label:`To offset`,value:e.to,onChange:e=>o({to:e})})]})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex max-h-32 flex-wrap gap-1 overflow-y-auto`,children:[De(t,e.types).map(([t,n])=>/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>c(t),"aria-pressed":e.types.has(t),title:t,className:f(`rounded px-1.5 py-0.5 text-xs hover:bg-muted`,e.types.has(t)?`bg-muted text-foreground`:`text-muted-foreground`),children:[H(t),` `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`tabular-nums`,children:n.toLocaleString()})]},t)),n?/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,onClick:()=>o(u),className:`px-1.5 py-0.5 text-xs text-muted-foreground underline-offset-2 hover:underline`,children:`clear`}):null]}),r?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:[`The filter searches the `,a,` events loaded; scroll up to load older ones.`]}):null]})}function ut({label:e,value:t,onChange:n}){return/* @__PURE__ */ (0,N.jsx)(`input`,{inputMode:`numeric`,"aria-label":e,placeholder:`#`,value:t??``,onChange:e=>{let t=Oe(e.target.value);t!==null&&n(t)},className:`h-7 w-16 rounded-md border bg-background px-1.5 text-center text-base tabular-nums sm:text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`})}function dt({events:e}){let[t,n]=(0,k.useState)(()=>ft(e));return(0,k.useEffect)(()=>{let t=()=>n(ft(e));if(t(),ft(e)===0)return;let r=setInterval(t,5e3);return()=>clearInterval(r)},[e]),t===0?null:/* @__PURE__ */ (0,N.jsx)(`span`,{title:`Events in the last minute`,children:` · ${String(t)}/min`})}function ft(e){let t=Date.now(),n=0;for(let r=e.length-1;r>=0&&!(t-Date.parse(e[r].createdAt)>6e4);r--)n+=1;return n}function pt({actors:e,rpcStubs:t,className:n,onPick:r}){let i=e.slice(0,5);return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:f(`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,n),children:[i.map(e=>/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,className:`truncate hover:text-foreground`,title:`${e.actor}${e.grant?` via ${e.grant}`:``} · last ${new Date(e.lastSeenAt).toLocaleString()}`,onClick:()=>r?.(e.actor),children:e.email||e.actor},e.actor)),e.length>i.length?/* @__PURE__ */ (0,N.jsxs)(`span`,{children:[`+`,e.length-i.length]}):null,t.length>0?/* @__PURE__ */ (0,N.jsxs)(`span`,{title:t.join(`, `),children:[t.length,` live `,t.length===1?`stub`:`stubs`]}):null]})}function mt(e){if(typeof e==`string`)return e;if(!Array.isArray(e))return q(e,240);let t=[];for(let n of e)if(typeof n==`string`)t.push(n);else if(Array.isArray(n)&&typeof n[0]==`string`)t.push(`${n[0]}(${n.slice(1).map(e=>q(e,80)).join(`, `)})`);else return q(e,240);return t.join(`.`)}function q(e,t){let n;try{n=JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t)}catch{n=String(e)}return n||=String(e),n.length>t?`${n.slice(0,t-1)}…`:n}function ht({value:e,depth:t=0}){if(!j(e))return/* @__PURE__ */ (0,N.jsx)(bt,{value:e});let n=Object.entries(e);return n.length===0?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`empty`}):/* @__PURE__ */ (0,N.jsx)(`dl`,{className:`grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-3 gap-y-0.5 text-xs`,children:n.map(([e,n])=>/* @__PURE__ */ (0,N.jsx)(gt,{label:e,value:n,depth:t},e))})}function gt({label:e,value:t,depth:n}){return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`dt`,{className:`truncate font-mono text-muted-foreground`,title:e,children:e}),/* @__PURE__ */ (0,N.jsx)(`dd`,{className:`min-w-0`,children:/* @__PURE__ */ (0,N.jsx)(_t,{value:t,depth:n})})]})}function _t({value:e,depth:t}){return Array.isArray(e)?/* @__PURE__ */ (0,N.jsx)(vt,{value:e,depth:t}):j(e)?/* @__PURE__ */ (0,N.jsx)(yt,{value:e,depth:t}):/* @__PURE__ */ (0,N.jsx)(bt,{value:e})}function vt({value:e,depth:t}){return e.length===0?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:`none`}):e.length<=8&&e.every(e=>!j(e)&&!Array.isArray(e))?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:e.map(X).join(`, `)}):t>0&&q(e,200).length<=100?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:q(e,100)}):/* @__PURE__ */ (0,N.jsx)(xt,{summary:`${e.length.toLocaleString()} ${e.length===1?`item`:`items`}`,children:/* @__PURE__ */ (0,N.jsx)(J,{items:e.map((e,t)=>[`${t}`,e])})})}function yt({value:e,depth:t}){let n=Object.keys(e).length;return n===0?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:`{}`}):t===0?/* @__PURE__ */ (0,N.jsx)(ht,{value:e,depth:1}):q(e,200).length<=100?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:q(e,100)}):/* @__PURE__ */ (0,N.jsx)(xt,{summary:`${n.toLocaleString()} ${n===1?`field`:`fields`}`,children:/* @__PURE__ */ (0,N.jsx)(J,{items:Object.entries(e)})})}function bt({value:e}){if(e==null)return/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`—`});let t=X(e);return/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono text-xs break-all`,title:t.length>200?t:void 0,children:t.length>200?`${t.slice(0,199)}…`:t})}function xt({summary:e,children:t}){return/* @__PURE__ */ (0,N.jsxs)(`details`,{children:[/* @__PURE__ */ (0,N.jsx)(`summary`,{className:`cursor-pointer text-muted-foreground hover:text-foreground`,children:e}),t]})}function J({items:e}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col py-0.5`,children:[e.slice(0,50).map(([e,t])=>/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`truncate font-mono`,title:q(t,2e3),children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:e}),` `,q(t,240)]},e)),e.length>50?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-muted-foreground`,children:[`+`,(e.length-50).toLocaleString(),` more`]}):null]})}function St({state:e}){if(!j(e)||!(`subscriptions`in e))return/* @__PURE__ */ (0,N.jsx)(ht,{value:e});let t=Object.entries(M(e.itxExpressionRewriteRules)),n=Object.entries(M(e.schedules)),r=Object.entries(M(e.fetchRoutes)),i=Object.entries(M(e.scriptRuns)),a=[[`rewrite rules`,t],[`schedules`,n],[`fetch routes`,r],[`open script runs`,i]].filter(([,e])=>e.length===0).map(([e])=>e),o=j(e.paused)?{reason:X(e.paused.reason)}:void 0,s=[[`path`,e.path],[`mind`,e.mindId],[`created`,e.createdAt],[`incarnation`,e.incarnation],[`ingress`,e.ingressTarget?mt(e.ingressTarget):void 0]];return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-3 text-xs`,children:[o?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-warning`,children:[`Paused`,o.reason?`: ${o.reason}`:``]}):null,/* @__PURE__ */ (0,N.jsxs)(`dl`,{className:`grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-3 gap-y-0.5`,children:[s.filter(([,e])=>e!=null).map(([e,t])=>/* @__PURE__ */ (0,N.jsx)(gt,{label:e,value:t,depth:1},e)),/* @__PURE__ */ (0,N.jsx)(gt,{label:`subscriptions`,value:`${Object.keys(M(e.subscriptions)).length} (listed above)`,depth:1})]}),t.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Rewrite rules`,count:t.length,children:t.map(([e,t])=>{let n=M(t);return/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`font-mono break-all`,children:[e,` `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),` `,n.target===null?`denied`:mt(n.target),typeof n.description==`string`?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`ml-2 font-sans text-muted-foreground`,children:n.description}):null]},e)})}):null,n.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Schedules`,count:n.length,children:/* @__PURE__ */ (0,N.jsx)(J,{items:n})}):null,r.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Fetch routes`,count:r.length,children:/* @__PURE__ */ (0,N.jsx)(J,{items:r})}):null,i.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Open script runs`,count:i.length,children:i.map(([e,t])=>/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`font-mono`,children:[`#`,e,` `,/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`text-muted-foreground`,children:[`requested `,X(M(t).requestedAt)]})]},e))}):null,a.length>0?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-muted-foreground`,children:[`No `,a.join(`, `),`.`]}):null]})}function Y({title:e,count:t,children:n}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-muted-foreground`,children:[e,` `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`tabular-nums`,children:t})]}),n]})}function X(e){return typeof e==`string`?e:q(e,400)}function Ct({state:e,view:t,core:n}){return e.status===`error`?/* @__PURE__ */ (0,N.jsxs)(`p`,{"data-type":`error`,className:`text-xs text-destructive`,children:[`Live state unavailable: `,e.error]}):e.value===void 0?/* @__PURE__ */ (0,N.jsx)(h,{label:`Reading the live state`,className:`font-readme text-xs`}):t===`raw`?/* @__PURE__ */ (0,N.jsx)(O,{data:e.value,showToggle:!1,className:`max-h-[28rem]`}):n?/* @__PURE__ */ (0,N.jsx)(St,{state:e.value}):/* @__PURE__ */ (0,N.jsx)(ht,{value:e.value})}function wt({open:e,onClose:t,processors:n,presence:r,liveState:i,events:a,head:o,onPickActor:s}){let[c,l]=(0,k.useState)(`pretty`),u=Vt(e),d=(0,k.useMemo)(()=>new Set(r.rpcStubs),[r.rpcStubs]),p=(0,k.useMemo)(()=>[...n].sort((e,t)=>Ft($(e))-Ft($(t))||e.configuredAtOffset-t.configuredAtOffset),[n]),m=new Set(p.flatMap(e=>E(e)??[])),h=r.rpcStubs.filter(e=>!m.has(e)),g=i.core||Rt,v=p.filter(e=>$(e)!==`callback`),y=p.filter(e=>$(e)===`callback`&&d.has(E(e))),x=p.filter(e=>$(e)===`callback`&&!d.has(E(e)));return/* @__PURE__ */ (0,N.jsx)(S,{open:e,onOpenChange:e=>!e&&t(),children:/* @__PURE__ */ (0,N.jsxs)(T,{side:`right`,className:`overflow-y-auto data-[side=right]:w-full data-[side=right]:sm:max-w-2xl`,children:[/* @__PURE__ */ (0,N.jsxs)(b,{className:`flex-row items-start gap-3`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[/* @__PURE__ */ (0,N.jsx)(_,{children:`Processors`}),/* @__PURE__ */ (0,N.jsx)(ee,{children:`Who is here, what subscribes to this context, and what each has folded.`})]}),/* @__PURE__ */ (0,N.jsx)(`div`,{role:`tablist`,"aria-label":`How state reads`,className:`mr-8 flex shrink-0 rounded-md border p-0.5 text-xs`,children:[`pretty`,`raw`].map(e=>/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":c===e,onClick:()=>l(e),className:f(`rounded px-2 py-0.5 capitalize`,c===e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:e},e))})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6 px-4 pb-8`,children:[/* @__PURE__ */ (0,N.jsx)(At,{events:a,head:o,core:g.value,now:u}),/* @__PURE__ */ (0,N.jsxs)(Mt,{title:`Here`,count:r.actors.length,children:[r.actors.length===0?/* @__PURE__ */ (0,N.jsx)(Nt,{children:`Nobody has acted on this context in the loaded log.`}):/* @__PURE__ */ (0,N.jsx)(`ul`,{className:`flex flex-col`,children:r.actors.map(e=>/* @__PURE__ */ (0,N.jsx)(`li`,{children:/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>s(e.actor),title:`Show only what ${e.email||e.actor} did`,className:`flex w-full min-w-0 items-baseline gap-3 rounded px-1 py-0.5 text-left text-xs hover:bg-muted`,children:[/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[e.email||e.actor,e.email?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`ml-2 font-mono text-muted-foreground`,children:e.actor}):null]}),e.grant?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden truncate font-mono text-muted-foreground sm:inline`,children:e.grant}):null,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,title:e.lastSeenAt,children:Bt(e.lastSeenAt,u)})]})},e.actor))}),/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme px-1 text-xs text-muted-foreground`,children:r.rpcStubs.length===0?`No rpc stub is lent to this context right now.`:`${r.rpcStubs.length} rpc ${r.rpcStubs.length===1?`stub`:`stubs`} lent right now${h.length<r.rpcStubs.length?`, ${r.rpcStubs.length-h.length} of them for the live callbacks below`:``}.`}),h.length>0?/* @__PURE__ */ (0,N.jsx)(`ul`,{className:`flex flex-col px-1`,children:h.map(e=>/* @__PURE__ */ (0,N.jsx)(`li`,{className:`truncate font-mono text-xs`,title:e,children:e},e))}):null]}),/* @__PURE__ */ (0,N.jsxs)(Mt,{title:`Subscribers`,count:p.length,children:[p.length===0?/* @__PURE__ */ (0,N.jsx)(Nt,{children:`Nothing subscribes to this context.`}):/* @__PURE__ */ (0,N.jsx)(`div`,{className:`flex flex-col divide-y`,children:v.map(e=>/* @__PURE__ */ (0,N.jsx)(Tt,{row:e,head:o,state:e.hostedFacet?i[e.hostedFacet.name]:void 0,view:c},e.name))}),y.length>0?/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:`Live callbacks: a session's subscription, delivered to the stub it lent`}),y.map(e=>/* @__PURE__ */ (0,N.jsx)(kt,{row:e,connected:!0},e.name)),x.length>0?/* @__PURE__ */ (0,N.jsxs)(`details`,{className:`text-xs`,children:[/* @__PURE__ */ (0,N.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground hover:text-foreground`,children:[x.length,` not connected: their session ended and the row stayed`]}),x.map(e=>/* @__PURE__ */ (0,N.jsx)(kt,{row:e,connected:!1},e.name))]}):null]}):null]}),/* @__PURE__ */ (0,N.jsxs)(Mt,{title:`The context`,aside:typeof g.rev==`number`?/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`tabular-nums`,children:[`reduced through #`,g.rev.toLocaleString()]}):null,children:[/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:`The core reduce: rewrite rules, subscriptions, schedules, fetch routes, open runs, the pause.`}),/* @__PURE__ */ (0,N.jsx)(Ct,{state:g,view:c,core:!0})]})]})]})})}function Tt({row:e,head:t,state:n,view:r}){let i=$(e),a=It(e,i);return/* @__PURE__ */ (0,N.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-1.5 py-3 first:pt-1`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2`,children:[/* @__PURE__ */ (0,N.jsx)(`h4`,{className:`min-w-0 font-mono text-sm font-medium break-all`,children:e.name}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Pt[i]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(`ml-auto text-xs`,a.tone),children:a.label})]}),/* @__PURE__ */ (0,N.jsx)(Et,{row:e,head:t}),n?/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1 pt-1`,children:[/* @__PURE__ */ (0,N.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Live state`}),/* @__PURE__ */ (0,N.jsx)(Ct,{state:n,view:r,core:!1})]}):null]})}function Et({row:e,head:t}){return/* @__PURE__ */ (0,N.jsxs)(`dl`,{className:`grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-3 gap-y-0.5 text-xs`,children:[/* @__PURE__ */ (0,N.jsx)(Q,{label:`consumes`,children:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:Lt(e.consumes)})}),/* @__PURE__ */ (0,N.jsx)(Q,{label:`delivers to`,children:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:e.target})}),e.hostedFacet?/* @__PURE__ */ (0,N.jsx)(Dt,{facet:e.hostedFacet,name:e.name}):null,/* @__PURE__ */ (0,N.jsx)(Q,{label:`since`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`tabular-nums`,children:[`configured at #`,e.configuredAtOffset.toLocaleString(),e.afterOffset!==void 0&&e.afterOffset!==e.configuredAtOffset?`, delivering after #${e.afterOffset.toLocaleString()}`:``]})}),e.cursor?/* @__PURE__ */ (0,N.jsx)(Ot,{confirmed:e.cursor.confirmedOffset,head:t}):null,e.halted?/* @__PURE__ */ (0,N.jsx)(Q,{label:`halted`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`text-destructive`,children:[`after #`,e.halted.afterOffset.toLocaleString(),`, `,e.halted.attempts,` attempts`,e.halted.error?`: ${e.halted.error}`:``]})}):null]})}function Dt({facet:e,name:t}){return/* @__PURE__ */ (0,N.jsxs)(Q,{label:`hosts`,children:[/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`font-mono break-all`,children:[e.className,e.name===t?``:` as ${e.name}`]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(`ml-2`,e.restarts>0?`text-warning`:`text-muted-foreground`),title:`How often the platform failed the facet at its start and restarted it`,children:e.restarts>0?`restarted ${e.restarts}×`:`never restarted`})]})}function Ot({confirmed:e,head:t}){let n=t===void 0?void 0:Math.max(0,t-e);return/* @__PURE__ */ (0,N.jsx)(Q,{label:`confirmed`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`tabular-nums`,children:[`#`,e.toLocaleString(),n===void 0?null:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:f(`ml-2`,n>0?`text-warning`:`text-muted-foreground`),children:[`lag `,n.toLocaleString()]})]})})}function kt({row:e,connected:t}){return/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`flex min-w-0 items-baseline gap-3 text-xs`,title:e.target,children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`shrink-0 font-mono`,children:e.name}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-muted-foreground`,children:Lt(e.consumes)}),/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,children:[`#`,e.configuredAtOffset.toLocaleString()]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(`shrink-0`,t?`text-success`:`text-muted-foreground`),children:t?`connected`:`gone`})]})}function At({events:e,head:t,core:n,now:r}){let i=(0,k.useMemo)(()=>zt(e,r),[e,r]),a=i.slice(-5).reduce((e,t)=>e+t,0)/5,o=M(n),s=o.paused?M(o.paused):void 0,c=Math.max(...i);return/* @__PURE__ */ (0,N.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[/* @__PURE__ */ (0,N.jsx)(Z,{label:`head`,value:t===void 0?`—`:`#${t.toLocaleString()}`}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`appends / min`,value:a>=10?String(Math.round(a)):a.toFixed(1),title:`Mean over the last five minutes, from the loaded log`}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`age`,value:typeof o.createdAt==`string`?Bt(o.createdAt,r,``):`—`,title:typeof o.createdAt==`string`?`Created ${o.createdAt}`:void 0}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`incarnation`,value:typeof o.incarnation==`number`?String(o.incarnation):`—`,title:`The Durable Object's wake count: growth across idle is hibernation`}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`paused`,value:s?`yes`:`no`,title:typeof s?.reason==`string`?s.reason:void 0,tone:s?`text-warning`:void 0})]}),/* @__PURE__ */ (0,N.jsx)(jt,{counts:i}),/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-2xs text-muted-foreground`,children:[`Appends per minute over the last hour`,c>0?`, peak ${c}`:``,`, from the loaded log.`]})]})}function Z({label:e,value:t,title:n,tone:r}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{title:n,children:[/* @__PURE__ */ (0,N.jsx)(`div`,{className:`text-2xs tracking-wide text-muted-foreground uppercase`,children:e}),/* @__PURE__ */ (0,N.jsx)(`div`,{className:f(`font-mono text-sm tabular-nums`,r),children:t})]})}function jt({counts:e}){let t=Math.max(5,...e),n=360/Math.max(1,e.length-1),r=e.map((e,r)=>`${(r*n).toFixed(1)},${(35-e/t*32).toFixed(1)}`).join(` `);return/* @__PURE__ */ (0,N.jsxs)(`svg`,{viewBox:`0 0 360 36`,preserveAspectRatio:`none`,className:`h-9 w-full text-info`,"aria-hidden":!0,children:[/* @__PURE__ */ (0,N.jsx)(`polygon`,{points:`0,36 ${r} 360,36`,className:`fill-info/10`}),/* @__PURE__ */ (0,N.jsx)(`polyline`,{points:r,fill:`none`,stroke:`currentColor`,strokeWidth:`1.25`,strokeLinejoin:`round`,vectorEffect:`non-scaling-stroke`})]})}function Mt({title:e,count:t,aside:n,children:r}){return/* @__PURE__ */ (0,N.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-2`,children:[/* @__PURE__ */ (0,N.jsxs)(`h3`,{className:`flex items-baseline gap-2 text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:[e,t===void 0?null:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`tabular-nums`,children:t}),n?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`ml-auto text-xs font-normal tracking-normal normal-case`,children:n}):null]}),r]})}function Q({label:e,children:t}){return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,N.jsx)(`dd`,{className:`min-w-0`,children:t})]})}function Nt({children:e}){return/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:e})}const Pt={processor:`processor`,callback:`live callback`,call:`itx call`},Ft=e=>[`processor`,`call`,`callback`].indexOf(e);function $(e){return e.hostedFacet?`processor`:E(e)===void 0?`call`:`callback`}function It(e,t){return e.halted?{label:`halted`,tone:`text-destructive`}:e.cursor?.nextAttemptAtMs===void 0?t===`processor`?{label:`hosted`,tone:`text-success`}:{label:`delivering`,tone:`text-success`}:{label:`retrying, attempt ${e.cursor.attempt}`,tone:`text-warning`}}function Lt(e){return!e?.length||e.includes(`*`)?`every durable event`:e.map(H).join(`, `)}const Rt={status:`connecting`,value:void 0};function zt(e,t){let n=Array.from({length:60},()=>0),r=t-36e5;for(let t=e.length-1;t>=0;t--){let i=Date.parse(e[t].createdAt);if(!Number.isNaN(i)){if(i<r)break;n[Math.min(59,Math.floor((i-r)/6e4))]++}}return n}function Bt(e,t,n=` ago`){let r=Math.max(0,Math.round((t-Date.parse(e))/1e3));return Number.isNaN(r)?`—`:r<60?`${r}s${n}`:r<3600?`${Math.round(r/60)}m${n}`:r<86400?`${(r/3600).toFixed(1)}h${n}`:`${Math.round(r/86400)}d${n}`}function Vt(e){let[t,n]=(0,k.useState)(()=>Date.now());return(0,k.useEffect)(()=>{if(!e)return;n(Date.now());let t=setInterval(()=>n(Date.now()),15e3);return()=>clearInterval(t)},[e]),t}const Ht=e=>f(`rounded-md px-2 py-0.5 whitespace-nowrap`,e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`);function Ut({title:e,context:t,error:n,inspectors:r,state:i,onStateChange:a,onAppend:o,emptyText:s=`Nothing has happened on this context yet.`,className:c,columnClassName:u}){let{events:p,caughtUp:m,head:h,presence:g,liveState:_}=t,v=!t.error&&t.older||se,y=t.processors.rows,b=n||t.error||t.processors.error,x=(0,k.useMemo)(()=>l(i),[i]),S=!!i.filter,C=i.event,[ee,te]=(0,k.useState)(()=>/* @__PURE__ */ new Set),[ne,re]=(0,k.useState)(0),ie=(0,k.useMemo)(()=>({...de,...r}),[r]),{shown:w,items:T,namedBefore:E,types:ae}=Wt({events:p,filter:x,counting:S}),D=V(x),oe=(0,k.useCallback)(e=>te(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),[]),le=(0,k.useRef)(a);(0,k.useLayoutEffect)(()=>{le.current=a});let O=(0,k.useCallback)(e=>le.current({...d,event:e}),[]),A=p.length.toLocaleString(),j={"--offset-width":`${String(String(p.at(-1)?.offset??0).length+1)}ch`};return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:f(`flex min-h-0 min-w-0 flex-col`,c),style:j,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:u,children:[/* @__PURE__ */ (0,N.jsx)(Kt,{title:e,count:Gt({filtered:D,shown:w,loaded:A,older:v,head:h}),caughtUp:m,events:p,presence:g,pickedActor:x.actor,filtering:S,filtered:D,processorCount:y.length,onStateChange:a}),S?/* @__PURE__ */ (0,N.jsx)(`div`,{className:`px-3 sm:px-4 pb-2`,children:/* @__PURE__ */ (0,N.jsx)(lt,{filter:x,counts:ae,narrowed:D,partial:!v.exhausted,loaded:A,onStateChange:a})}):null,b?/* @__PURE__ */ (0,N.jsx)(`p`,{"data-type":`error`,className:`px-3 sm:px-4 text-sm text-destructive`,children:b}):null]}),/* @__PURE__ */ (0,N.jsx)($e,{items:T,namedBefore:E,inspected:C,onInspect:O,opened:ee,onToggle:oe,older:v,logShare:ce(p,h),followTail:ne,arrivals:w,columnClassName:u,empty:b?null:/* @__PURE__ */ (0,N.jsx)(qt,{caughtUp:m,readProgress:v.exhausted?void 0:ce(p,h),text:D?`No event matches the filter.`:s}),footer:o?/* @__PURE__ */ (0,N.jsx)(`div`,{className:`bg-background`,children:/* @__PURE__ */ (0,N.jsx)(`div`,{className:u,children:/* @__PURE__ */ (0,N.jsx)(ct,{onAppend:o,onAppended:()=>re(e=>e+1),events:p,processors:y})})}):null}),/* @__PURE__ */ (0,N.jsx)(Ne,{events:p,offset:C,older:v,inspectors:ie,onNavigate:O,onClose:()=>a({event:void 0})}),/* @__PURE__ */ (0,N.jsx)(wt,{open:!!i.processors,onClose:()=>a({processors:void 0}),processors:y,presence:g,liveState:_,events:p,head:h,onPickActor:e=>a({actor:e,processors:void 0})})]})}function Wt({events:e,filter:t,counting:n}){let[r]=(0,k.useState)(()=>K(Ce)),i=(0,k.useMemo)(()=>r(e,t).shown,[r,e,t]),[a]=(0,k.useState)(()=>K(xe)),{items:o,namedBefore:s}=(0,k.useMemo)(()=>a(i,U),[a,i]),[c]=(0,k.useState)(()=>K(we));return{shown:i,items:o,namedBefore:s,types:(0,k.useMemo)(()=>n?Ee(c(e).counts):[],[n,c,e])}}function Gt({filtered:e,shown:t,loaded:n,older:r,head:i}){return e?`${t.length.toLocaleString()} of ${n} loaded events`:r.exhausted?`${n} events`:`${n} loaded of ~${(i??0).toLocaleString()} events`}function Kt({title:e,count:t,caughtUp:n,events:r,presence:i,pickedActor:a,filtering:o,filtered:s,processorCount:c,onStateChange:l}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 px-3 sm:px-4 py-1.5`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-4`,children:[/* @__PURE__ */ (0,N.jsx)(`div`,{className:`min-w-0 truncate text-sm`,children:e}),/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground tabular-nums`,children:[t,n?``:` · loading`,/* @__PURE__ */ (0,N.jsx)(dt,{events:r})]})]}),/* @__PURE__ */ (0,N.jsx)(pt,{className:`hidden min-w-0 xl:flex`,actors:i.actors,rpcStubs:i.rpcStubs,onPick:e=>l({actor:a===e?void 0:e})}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`ml-auto flex items-center gap-3 text-xs`,children:[/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,onClick:()=>l({filter:!o||void 0}),"aria-expanded":o,className:Ht(o||s),children:`Filter`}),/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>l({...d,processors:!0}),className:Ht(!1),children:[`Processors `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-foreground tabular-nums`,children:c})]})]})]})}function qt({caughtUp:e,readProgress:t,text:n}){return!e||t!==void 0?/* @__PURE__ */ (0,N.jsx)(h,{label:e?`Reading the log`:`Loading the log`,progress:e?t:void 0,className:`px-3 sm:px-4 py-6`}):/* @__PURE__ */ (0,N.jsx)(`p`,{className:`px-3 sm:px-4 py-6 text-sm text-muted-foreground`,children:n})}export{A as i,K as n,M as r,Ut as t}; +`),[u,d]=(0,k.useState)(!1),[f,h]=(0,k.useState)(),g=(0,k.useMemo)(()=>st(r),[r]),[_]=(0,k.useState)(()=>K(we)),v=(0,k.useMemo)(()=>i?et(Ee(_(n).counts),r):[],[i,_,n,r]),y=e=>{l(e),h(void 0)},b=c.trim()===``,x=async()=>{if(u||b)return;let n=at(c);if(`error`in n)return h(n);d(!0);try{await e(n.events),h({appended:n.events.length}),t()}catch(e){h({error:e instanceof Error?e.message:String(e)})}finally{d(!1)}};return i?/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex gap-x-3.5 border-t px-3 sm:px-4 pt-2 pb-1`,"data-slot":`append-composer`,children:[/* @__PURE__ */ (0,N.jsx)(W,{times:!0}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[/* @__PURE__ */ (0,N.jsx)(oe,{value:c,onValueChange:y,onSubmit:()=>void x(),language:`yaml`,label:`Events to append`,placeholder:`type: manual/note-added (a YAML list appends several)`,focusOnMount:!0,complete:(e,t,n)=>rt(e,t,n,v)}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[g.length>0?/* @__PURE__ */ (0,N.jsxs)(w,{children:[/* @__PURE__ */ (0,N.jsxs)(te,{render:/* @__PURE__ */ (0,N.jsx)(p,{variant:`ghost`,size:`sm`}),children:[/* @__PURE__ */ (0,N.jsx)(o,{}),` Examples`]}),/* @__PURE__ */ (0,N.jsx)(ie,{align:`start`,side:`top`,className:`w-auto max-w-80`,children:g.map(e=>/* @__PURE__ */ (0,N.jsxs)(ne,{children:[/* @__PURE__ */ (0,N.jsx)(re,{className:`truncate`,children:e.label}),e.types.map(e=>/* @__PURE__ */ (0,N.jsx)(C,{title:e,onClick:()=>y(ot(e)),className:`font-mono text-xs`,children:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`truncate`,children:H(e)})},e))]},e.label))})]}):null,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs`,role:`status`,children:f&&`error`in f?/* @__PURE__ */ (0,N.jsx)(`span`,{"data-type":`error`,className:`text-destructive`,title:f.error,children:f.error}):f?/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Appended `,f.appended===1?`1 event`:`${String(f.appended)} events`]}):/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden text-muted-foreground sm:inline`,children:`YAML or JSON · Tab completes · ⌘↵ appends`})}),/* @__PURE__ */ (0,N.jsx)(p,{variant:`ghost`,size:`sm`,onClick:()=>s(!1),children:`Close`}),/* @__PURE__ */ (0,N.jsxs)(p,{size:`sm`,onClick:()=>void x(),disabled:u||b,title:`Append events (⌘↵)`,children:[u?/* @__PURE__ */ (0,N.jsx)(m,{}):null,` Append`]})]})]})]}):/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex items-center gap-x-3.5 px-3 sm:px-4 py-1`,children:[/* @__PURE__ */ (0,N.jsx)(W,{times:!0}),/* @__PURE__ */ (0,N.jsxs)(p,{variant:`ghost`,size:`sm`,className:`-ml-2`,onClick:()=>s(!0),children:[/* @__PURE__ */ (0,N.jsx)(a,{}),` Append event`]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden text-xs text-muted-foreground sm:inline`,children:`YAML · ⌘↵`})]})}function lt({filter:e,counts:t,narrowed:n,partial:r,loaded:a,onStateChange:o}){let s=(0,k.useCallback)(e=>e?.focus(),[]),c=t=>{let n=e.types.has(t)?[...e.types].filter(e=>e!==t):[...e.types,t];o({types:n.length>0?n:void 0})};return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-2`,"data-slot":`filter-row`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2`,children:[/* @__PURE__ */ (0,N.jsxs)(x,{className:`h-8 min-w-48 flex-1`,children:[/* @__PURE__ */ (0,N.jsx)(v,{children:/* @__PURE__ */ (0,N.jsx)(i,{})}),/* @__PURE__ */ (0,N.jsx)(y,{ref:s,value:e.query,onChange:e=>o({q:e.target.value||void 0}),onKeyDown:t=>{t.key===`Escape`&&e.query&&o({q:void 0})},placeholder:`Search type or payload`,"aria-label":`Search type or payload`,className:`text-base sm:text-sm`})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,title:`Only the events between these offsets, inclusive`,children:[/* @__PURE__ */ (0,N.jsx)(`span`,{children:`from`}),/* @__PURE__ */ (0,N.jsx)(ut,{label:`From offset`,value:e.from,onChange:e=>o({from:e})}),/* @__PURE__ */ (0,N.jsx)(`span`,{children:`to`}),/* @__PURE__ */ (0,N.jsx)(ut,{label:`To offset`,value:e.to,onChange:e=>o({to:e})})]})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex max-h-32 flex-wrap gap-1 overflow-y-auto`,children:[De(t,e.types).map(([t,n])=>/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>c(t),"aria-pressed":e.types.has(t),title:t,className:f(`rounded px-1.5 py-0.5 text-xs hover:bg-muted`,e.types.has(t)?`bg-muted text-foreground`:`text-muted-foreground`),children:[H(t),` `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`tabular-nums`,children:n.toLocaleString()})]},t)),n?/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,onClick:()=>o(u),className:`px-1.5 py-0.5 text-xs text-muted-foreground underline-offset-2 hover:underline`,children:`clear`}):null]}),r?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:[`The filter searches the `,a,` events loaded; scroll up to load older ones.`]}):null]})}function ut({label:e,value:t,onChange:n}){return/* @__PURE__ */ (0,N.jsx)(`input`,{inputMode:`numeric`,"aria-label":e,placeholder:`#`,value:t??``,onChange:e=>{let t=Oe(e.target.value);t!==null&&n(t)},className:`h-7 w-16 rounded-md border bg-background px-1.5 text-center text-base tabular-nums sm:text-xs outline-none focus-visible:ring-1 focus-visible:ring-ring`})}function dt({events:e}){let[t,n]=(0,k.useState)(()=>ft(e));return(0,k.useEffect)(()=>{let t=()=>n(ft(e));if(t(),ft(e)===0)return;let r=setInterval(t,5e3);return()=>clearInterval(r)},[e]),t===0?null:/* @__PURE__ */ (0,N.jsx)(`span`,{title:`Events in the last minute`,children:` · ${String(t)}/min`})}function ft(e){let t=Date.now(),n=0;for(let r=e.length-1;r>=0&&!(t-Date.parse(e[r].createdAt)>6e4);r--)n+=1;return n}function pt({actors:e,rpcStubs:t,className:n,onPick:r}){let i=e.slice(0,5);return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:f(`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,n),children:[i.map(e=>/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,className:`truncate hover:text-foreground`,title:`${e.actor}${e.grant?` via ${e.grant}`:``} · last ${new Date(e.lastSeenAt).toLocaleString()}`,onClick:()=>r?.(e.actor),children:e.email||e.actor},e.actor)),e.length>i.length?/* @__PURE__ */ (0,N.jsxs)(`span`,{children:[`+`,e.length-i.length]}):null,t.length>0?/* @__PURE__ */ (0,N.jsxs)(`span`,{title:t.join(`, `),children:[t.length,` live `,t.length===1?`stub`:`stubs`]}):null]})}function mt(e){if(typeof e==`string`)return e;if(!Array.isArray(e))return q(e,240);let t=[];for(let n of e)if(typeof n==`string`)t.push(n);else if(Array.isArray(n)&&typeof n[0]==`string`)t.push(`${n[0]}(${n.slice(1).map(e=>q(e,80)).join(`, `)})`);else return q(e,240);return t.join(`.`)}function q(e,t){let n;try{n=JSON.stringify(e,(e,t)=>typeof t==`bigint`?t.toString():t)}catch{n=String(e)}return n||=String(e),n.length>t?`${n.slice(0,t-1)}…`:n}function ht({value:e,depth:t=0}){if(!j(e))return/* @__PURE__ */ (0,N.jsx)(bt,{value:e});let n=Object.entries(e);return n.length===0?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`empty`}):/* @__PURE__ */ (0,N.jsx)(`dl`,{className:`grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-3 gap-y-0.5 text-xs`,children:n.map(([e,n])=>/* @__PURE__ */ (0,N.jsx)(gt,{label:e,value:n,depth:t},e))})}function gt({label:e,value:t,depth:n}){return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`dt`,{className:`truncate font-mono text-muted-foreground`,title:e,children:e}),/* @__PURE__ */ (0,N.jsx)(`dd`,{className:`min-w-0`,children:/* @__PURE__ */ (0,N.jsx)(_t,{value:t,depth:n})})]})}function _t({value:e,depth:t}){return Array.isArray(e)?/* @__PURE__ */ (0,N.jsx)(vt,{value:e,depth:t}):j(e)?/* @__PURE__ */ (0,N.jsx)(yt,{value:e,depth:t}):/* @__PURE__ */ (0,N.jsx)(bt,{value:e})}function vt({value:e,depth:t}){return e.length===0?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:`none`}):e.length<=8&&e.every(e=>!j(e)&&!Array.isArray(e))?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:e.map(X).join(`, `)}):t>0&&q(e,200).length<=100?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:q(e,100)}):/* @__PURE__ */ (0,N.jsx)(xt,{summary:`${e.length.toLocaleString()} ${e.length===1?`item`:`items`}`,children:/* @__PURE__ */ (0,N.jsx)(J,{items:e.map((e,t)=>[`${t}`,e])})})}function yt({value:e,depth:t}){let n=Object.keys(e).length;return n===0?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:`{}`}):t===0?/* @__PURE__ */ (0,N.jsx)(ht,{value:e,depth:1}):q(e,200).length<=100?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:q(e,100)}):/* @__PURE__ */ (0,N.jsx)(xt,{summary:`${n.toLocaleString()} ${n===1?`field`:`fields`}`,children:/* @__PURE__ */ (0,N.jsx)(J,{items:Object.entries(e)})})}function bt({value:e}){if(e==null)return/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`—`});let t=X(e);return/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono text-xs break-all`,title:t.length>200?t:void 0,children:t.length>200?`${t.slice(0,199)}…`:t})}function xt({summary:e,children:t}){return/* @__PURE__ */ (0,N.jsxs)(`details`,{children:[/* @__PURE__ */ (0,N.jsx)(`summary`,{className:`cursor-pointer text-muted-foreground hover:text-foreground`,children:e}),t]})}function J({items:e}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col py-0.5`,children:[e.slice(0,50).map(([e,t])=>/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`truncate font-mono`,title:q(t,2e3),children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:e}),` `,q(t,240)]},e)),e.length>50?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-muted-foreground`,children:[`+`,(e.length-50).toLocaleString(),` more`]}):null]})}function St({state:e}){if(!j(e)||!(`subscriptions`in e))return/* @__PURE__ */ (0,N.jsx)(ht,{value:e});let t=Object.entries(M(e.itxExpressionRewriteRules)),n=Object.entries(M(e.schedules)),r=Object.entries(M(e.fetchRoutes)),i=Object.entries(M(e.scriptRuns)),a=[[`rewrite rules`,t],[`schedules`,n],[`fetch routes`,r],[`open script runs`,i]].filter(([,e])=>e.length===0).map(([e])=>e),o=j(e.paused)?{reason:X(e.paused.reason)}:void 0,s=[[`path`,e.path],[`mind`,e.mindId],[`created`,e.createdAt],[`incarnation`,e.incarnation],[`ingress`,e.ingressTarget?mt(e.ingressTarget):void 0]];return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-3 text-xs`,children:[o?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-warning`,children:[`Paused`,o.reason?`: ${o.reason}`:``]}):null,/* @__PURE__ */ (0,N.jsxs)(`dl`,{className:`grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-3 gap-y-0.5`,children:[s.filter(([,e])=>e!=null).map(([e,t])=>/* @__PURE__ */ (0,N.jsx)(gt,{label:e,value:t,depth:1},e)),/* @__PURE__ */ (0,N.jsx)(gt,{label:`subscriptions`,value:`${Object.keys(M(e.subscriptions)).length} (listed above)`,depth:1})]}),t.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Rewrite rules`,count:t.length,children:t.map(([e,t])=>{let n=M(t);return/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`font-mono break-all`,children:[e,` `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),` `,n.target===null?`denied`:mt(n.target),typeof n.description==`string`?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`ml-2 font-sans text-muted-foreground`,children:n.description}):null]},e)})}):null,n.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Schedules`,count:n.length,children:/* @__PURE__ */ (0,N.jsx)(J,{items:n})}):null,r.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Fetch routes`,count:r.length,children:/* @__PURE__ */ (0,N.jsx)(J,{items:r})}):null,i.length>0?/* @__PURE__ */ (0,N.jsx)(Y,{title:`Open script runs`,count:i.length,children:i.map(([e,t])=>/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`font-mono`,children:[`#`,e,` `,/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`text-muted-foreground`,children:[`requested `,X(M(t).requestedAt)]})]},e))}):null,a.length>0?/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-muted-foreground`,children:[`No `,a.join(`, `),`.`]}):null]})}function Y({title:e,count:t,children:n}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-muted-foreground`,children:[e,` `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`tabular-nums`,children:t})]}),n]})}function X(e){return typeof e==`string`?e:q(e,400)}function Ct({state:e,view:t,core:n}){return e.status===`error`?/* @__PURE__ */ (0,N.jsxs)(`p`,{"data-type":`error`,className:`text-xs text-destructive`,children:[`Live state unavailable: `,e.error]}):e.value===void 0?/* @__PURE__ */ (0,N.jsx)(h,{label:`Reading the live state`,className:`font-readme text-xs`}):t===`raw`?/* @__PURE__ */ (0,N.jsx)(O,{data:e.value,showToggle:!1,className:`max-h-[28rem]`}):n?/* @__PURE__ */ (0,N.jsx)(St,{state:e.value}):/* @__PURE__ */ (0,N.jsx)(ht,{value:e.value})}function wt({open:e,onClose:t,processors:n,presence:r,liveState:i,events:a,head:o,onPickActor:s}){let[c,l]=(0,k.useState)(`pretty`),u=Vt(e),d=(0,k.useMemo)(()=>new Set(r.rpcStubs),[r.rpcStubs]),p=(0,k.useMemo)(()=>[...n].sort((e,t)=>Ft($(e))-Ft($(t))||e.configuredAtOffset-t.configuredAtOffset),[n]),m=new Set(p.flatMap(e=>E(e)??[])),h=r.rpcStubs.filter(e=>!m.has(e)),g=i.core||Rt,v=p.filter(e=>$(e)!==`callback`),y=p.filter(e=>$(e)===`callback`&&d.has(E(e))),x=p.filter(e=>$(e)===`callback`&&!d.has(E(e)));return/* @__PURE__ */ (0,N.jsx)(S,{open:e,onOpenChange:e=>!e&&t(),children:/* @__PURE__ */ (0,N.jsxs)(T,{side:`right`,className:`overflow-y-auto data-[side=right]:w-full data-[side=right]:sm:max-w-2xl`,children:[/* @__PURE__ */ (0,N.jsxs)(b,{className:`flex-row items-start gap-3`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[/* @__PURE__ */ (0,N.jsx)(_,{children:`Processors`}),/* @__PURE__ */ (0,N.jsx)(ee,{children:`Who is here, what subscribes to this context, and what each has folded.`})]}),/* @__PURE__ */ (0,N.jsx)(`div`,{role:`tablist`,"aria-label":`How state reads`,className:`mr-8 flex shrink-0 rounded-md border p-0.5 text-xs`,children:[`pretty`,`raw`].map(e=>/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":c===e,onClick:()=>l(e),className:f(`rounded px-2 py-0.5 capitalize`,c===e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:e},e))})]}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-6 px-4 pb-8`,children:[/* @__PURE__ */ (0,N.jsx)(At,{events:a,head:o,core:g.value,now:u}),/* @__PURE__ */ (0,N.jsxs)(Mt,{title:`Here`,count:r.actors.length,children:[r.actors.length===0?/* @__PURE__ */ (0,N.jsx)(Nt,{children:`Nobody has acted on this context in the loaded log.`}):/* @__PURE__ */ (0,N.jsx)(`ul`,{className:`flex flex-col`,children:r.actors.map(e=>/* @__PURE__ */ (0,N.jsx)(`li`,{children:/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>s(e.actor),title:`Show only what ${e.email||e.actor} did`,className:`flex w-full min-w-0 items-baseline gap-3 rounded px-1 py-0.5 text-left text-xs hover:bg-muted`,children:[/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[e.email||e.actor,e.email?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`ml-2 font-mono text-muted-foreground`,children:e.actor}):null]}),e.grant?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`hidden truncate font-mono text-muted-foreground sm:inline`,children:e.grant}):null,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,title:e.lastSeenAt,children:Bt(e.lastSeenAt,u)})]})},e.actor))}),/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme px-1 text-xs text-muted-foreground`,children:r.rpcStubs.length===0?`No rpc stub is lent to this context right now.`:`${r.rpcStubs.length} rpc ${r.rpcStubs.length===1?`stub`:`stubs`} lent right now${h.length<r.rpcStubs.length?`, ${r.rpcStubs.length-h.length} of them for the live callbacks below`:``}.`}),h.length>0?/* @__PURE__ */ (0,N.jsx)(`ul`,{className:`flex flex-col px-1`,children:h.map(e=>/* @__PURE__ */ (0,N.jsx)(`li`,{className:`truncate font-mono text-xs`,title:e,children:e},e))}):null]}),/* @__PURE__ */ (0,N.jsxs)(Mt,{title:`Subscribers`,count:p.length,children:[p.length===0?/* @__PURE__ */ (0,N.jsx)(Nt,{children:`Nothing subscribes to this context.`}):/* @__PURE__ */ (0,N.jsx)(`div`,{className:`flex flex-col divide-y`,children:v.map(e=>/* @__PURE__ */ (0,N.jsx)(Tt,{row:e,head:o,state:e.hostedFacet?i[e.hostedFacet.name]:void 0,view:c},e.name))}),y.length>0?/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:`Live callbacks: a session's subscription, delivered to the stub it lent`}),y.map(e=>/* @__PURE__ */ (0,N.jsx)(kt,{row:e,connected:!0},e.name)),x.length>0?/* @__PURE__ */ (0,N.jsxs)(`details`,{className:`text-xs`,children:[/* @__PURE__ */ (0,N.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground hover:text-foreground`,children:[x.length,` not connected: their session ended and the row stayed`]}),x.map(e=>/* @__PURE__ */ (0,N.jsx)(kt,{row:e,connected:!1},e.name))]}):null]}):null]}),/* @__PURE__ */ (0,N.jsxs)(Mt,{title:`The context`,aside:typeof g.rev==`number`?/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`tabular-nums`,children:[`reduced through #`,g.rev.toLocaleString()]}):null,children:[/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:`The core reduce: rewrite rules, subscriptions, schedules, fetch routes, open runs, the pause.`}),/* @__PURE__ */ (0,N.jsx)(Ct,{state:g,view:c,core:!0})]})]})]})})}function Tt({row:e,head:t,state:n,view:r}){let i=$(e),a=It(e,i);return/* @__PURE__ */ (0,N.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-1.5 py-3 first:pt-1`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2`,children:[/* @__PURE__ */ (0,N.jsx)(`h4`,{className:`min-w-0 font-mono text-sm font-medium break-all`,children:e.name}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:Pt[i]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(`ml-auto text-xs`,a.tone),children:a.label})]}),/* @__PURE__ */ (0,N.jsx)(Et,{row:e,head:t}),n?/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1 pt-1`,children:[/* @__PURE__ */ (0,N.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Live state`}),/* @__PURE__ */ (0,N.jsx)(Ct,{state:n,view:r,core:!1})]}):null]})}function Et({row:e,head:t}){return/* @__PURE__ */ (0,N.jsxs)(`dl`,{className:`grid grid-cols-[minmax(0,max-content)_minmax(0,1fr)] gap-x-3 gap-y-0.5 text-xs`,children:[/* @__PURE__ */ (0,N.jsx)(Q,{label:`consumes`,children:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:Lt(e.consumes)})}),/* @__PURE__ */ (0,N.jsx)(Q,{label:`delivers to`,children:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`font-mono break-all`,children:e.target})}),e.hostedFacet?/* @__PURE__ */ (0,N.jsx)(Dt,{facet:e.hostedFacet,name:e.name}):null,/* @__PURE__ */ (0,N.jsx)(Q,{label:`since`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`tabular-nums`,children:[`configured at #`,e.configuredAtOffset.toLocaleString(),e.afterOffset!==void 0&&e.afterOffset!==e.configuredAtOffset?`, delivering after #${e.afterOffset.toLocaleString()}`:``]})}),e.cursor?/* @__PURE__ */ (0,N.jsx)(Ot,{confirmed:e.cursor.confirmedOffset,head:t}):null,e.halted?/* @__PURE__ */ (0,N.jsx)(Q,{label:`halted`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`text-destructive`,children:[`after #`,e.halted.afterOffset.toLocaleString(),`, `,e.halted.attempts,` attempts`,e.halted.error?`: ${e.halted.error}`:``]})}):null]})}function Dt({facet:e,name:t}){return/* @__PURE__ */ (0,N.jsxs)(Q,{label:`hosts`,children:[/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`font-mono break-all`,children:[e.className,e.name===t?``:` as ${e.name}`]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(`ml-2`,e.restarts>0?`text-warning`:`text-muted-foreground`),title:`How often the platform failed the facet at its start and restarted it`,children:e.restarts>0?`restarted ${e.restarts}×`:`never restarted`})]})}function Ot({confirmed:e,head:t}){let n=t===void 0?void 0:Math.max(0,t-e);return/* @__PURE__ */ (0,N.jsx)(Q,{label:`confirmed`,children:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`tabular-nums`,children:[`#`,e.toLocaleString(),n===void 0?null:/* @__PURE__ */ (0,N.jsxs)(`span`,{className:f(`ml-2`,n>0?`text-warning`:`text-muted-foreground`),children:[`lag `,n.toLocaleString()]})]})})}function kt({row:e,connected:t}){return/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`flex min-w-0 items-baseline gap-3 text-xs`,title:e.target,children:[/* @__PURE__ */ (0,N.jsx)(`span`,{className:`shrink-0 font-mono`,children:e.name}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-muted-foreground`,children:Lt(e.consumes)}),/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`shrink-0 text-muted-foreground tabular-nums`,children:[`#`,e.configuredAtOffset.toLocaleString()]}),/* @__PURE__ */ (0,N.jsx)(`span`,{className:f(`shrink-0`,t?`text-success`:`text-muted-foreground`),children:t?`connected`:`gone`})]})}function At({events:e,head:t,core:n,now:r}){let i=(0,k.useMemo)(()=>zt(e,r),[e,r]),a=i.slice(-5).reduce((e,t)=>e+t,0)/5,o=M(n),s=o.paused?M(o.paused):void 0,c=Math.max(...i);return/* @__PURE__ */ (0,N.jsxs)(`section`,{className:`flex flex-col gap-2`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[/* @__PURE__ */ (0,N.jsx)(Z,{label:`head`,value:t===void 0?`—`:`#${t.toLocaleString()}`}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`appends / min`,value:a>=10?String(Math.round(a)):a.toFixed(1),title:`Mean over the last five minutes, from the loaded log`}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`age`,value:typeof o.createdAt==`string`?Bt(o.createdAt,r,``):`—`,title:typeof o.createdAt==`string`?`Created ${o.createdAt}`:void 0}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`incarnation`,value:typeof o.incarnation==`number`?String(o.incarnation):`—`,title:`The Durable Object's wake count: growth across idle is hibernation`}),/* @__PURE__ */ (0,N.jsx)(Z,{label:`paused`,value:s?`yes`:`no`,title:typeof s?.reason==`string`?s.reason:void 0,tone:s?`text-warning`:void 0})]}),/* @__PURE__ */ (0,N.jsx)(jt,{counts:i}),/* @__PURE__ */ (0,N.jsxs)(`p`,{className:`text-2xs text-muted-foreground`,children:[`Appends per minute over the last hour`,c>0?`, peak ${c}`:``,`, from the loaded log.`]})]})}function Z({label:e,value:t,title:n,tone:r}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{title:n,children:[/* @__PURE__ */ (0,N.jsx)(`div`,{className:`text-2xs tracking-wide text-muted-foreground uppercase`,children:e}),/* @__PURE__ */ (0,N.jsx)(`div`,{className:f(`font-mono text-sm tabular-nums`,r),children:t})]})}function jt({counts:e}){let t=Math.max(5,...e),n=360/Math.max(1,e.length-1),r=e.map((e,r)=>`${(r*n).toFixed(1)},${(35-e/t*32).toFixed(1)}`).join(` `);return/* @__PURE__ */ (0,N.jsxs)(`svg`,{viewBox:`0 0 360 36`,preserveAspectRatio:`none`,className:`h-9 w-full text-info`,"aria-hidden":!0,children:[/* @__PURE__ */ (0,N.jsx)(`polygon`,{points:`0,36 ${r} 360,36`,className:`fill-info/10`}),/* @__PURE__ */ (0,N.jsx)(`polyline`,{points:r,fill:`none`,stroke:`currentColor`,strokeWidth:`1.25`,strokeLinejoin:`round`,vectorEffect:`non-scaling-stroke`})]})}function Mt({title:e,count:t,aside:n,children:r}){return/* @__PURE__ */ (0,N.jsxs)(`section`,{className:`flex min-w-0 flex-col gap-2`,children:[/* @__PURE__ */ (0,N.jsxs)(`h3`,{className:`flex items-baseline gap-2 text-xs font-medium tracking-wide text-muted-foreground uppercase`,children:[e,t===void 0?null:/* @__PURE__ */ (0,N.jsx)(`span`,{className:`tabular-nums`,children:t}),n?/* @__PURE__ */ (0,N.jsx)(`span`,{className:`ml-auto text-xs font-normal tracking-normal normal-case`,children:n}):null]}),r]})}function Q({label:e,children:t}){return/* @__PURE__ */ (0,N.jsxs)(N.Fragment,{children:[/* @__PURE__ */ (0,N.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),/* @__PURE__ */ (0,N.jsx)(`dd`,{className:`min-w-0`,children:t})]})}function Nt({children:e}){return/* @__PURE__ */ (0,N.jsx)(`p`,{className:`font-readme text-xs text-muted-foreground`,children:e})}const Pt={processor:`processor`,callback:`live callback`,call:`itx call`},Ft=e=>[`processor`,`call`,`callback`].indexOf(e);function $(e){return e.hostedFacet?`processor`:E(e)===void 0?`call`:`callback`}function It(e,t){return e.halted?{label:`halted`,tone:`text-destructive`}:e.cursor?.nextAttemptAtMs===void 0?t===`processor`?{label:`hosted`,tone:`text-success`}:{label:`delivering`,tone:`text-success`}:{label:`retrying, attempt ${e.cursor.attempt}`,tone:`text-warning`}}function Lt(e){return!e?.length||e.includes(`*`)?`every durable event`:e.map(H).join(`, `)}const Rt={status:`connecting`,value:void 0};function zt(e,t){let n=Array.from({length:60},()=>0),r=t-36e5;for(let t=e.length-1;t>=0;t--){let i=Date.parse(e[t].createdAt);if(!Number.isNaN(i)){if(i<r)break;n[Math.min(59,Math.floor((i-r)/6e4))]++}}return n}function Bt(e,t,n=` ago`){let r=Math.max(0,Math.round((t-Date.parse(e))/1e3));return Number.isNaN(r)?`—`:r<60?`${r}s${n}`:r<3600?`${Math.round(r/60)}m${n}`:r<86400?`${(r/3600).toFixed(1)}h${n}`:`${Math.round(r/86400)}d${n}`}function Vt(e){let[t,n]=(0,k.useState)(()=>Date.now());return(0,k.useEffect)(()=>{if(!e)return;n(Date.now());let t=setInterval(()=>n(Date.now()),15e3);return()=>clearInterval(t)},[e]),t}const Ht=e=>f(`rounded-md px-2 py-0.5 whitespace-nowrap`,e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`);function Ut({title:e,context:t,error:n,inspectors:r,state:i,onStateChange:a,onAppend:o,emptyText:s=`Nothing has happened on this context yet.`,className:c,columnClassName:u}){let{events:p,caughtUp:m,head:h,presence:g,liveState:_}=t,v=!t.error&&t.older||ce,y=t.processors.rows,b=n||t.error||t.processors.error,x=(0,k.useMemo)(()=>l(i),[i]),S=!!i.filter,C=i.event,[ee,te]=(0,k.useState)(()=>/* @__PURE__ */ new Set),[ne,re]=(0,k.useState)(0),ie=(0,k.useMemo)(()=>({...de,...r}),[r]),{shown:w,items:T,namedBefore:E,types:ae}=Wt({events:p,filter:x,counting:S}),D=V(x),oe=(0,k.useCallback)(e=>te(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),[]),le=(0,k.useRef)(a);(0,k.useLayoutEffect)(()=>{le.current=a});let O=(0,k.useCallback)(e=>le.current({...d,event:e}),[]),A=p.length.toLocaleString(),j={"--offset-width":`${String(String(p.at(-1)?.offset??0).length+1)}ch`};return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:f(`@container flex min-h-0 min-w-0 flex-col`,c),style:j,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:u,children:[/* @__PURE__ */ (0,N.jsx)(Kt,{title:e,count:Gt({filtered:D,shown:w,loaded:A,older:v,head:h}),caughtUp:m,events:p,presence:g,pickedActor:x.actor,filtering:S,filtered:D,processorCount:y.length,onStateChange:a}),S?/* @__PURE__ */ (0,N.jsx)(`div`,{className:`px-3 sm:px-4 pb-2`,children:/* @__PURE__ */ (0,N.jsx)(lt,{filter:x,counts:ae,narrowed:D,partial:!v.exhausted,loaded:A,onStateChange:a})}):null,b?/* @__PURE__ */ (0,N.jsx)(`p`,{"data-type":`error`,className:`px-3 sm:px-4 text-sm text-destructive`,children:b}):null]}),/* @__PURE__ */ (0,N.jsx)($e,{items:T,namedBefore:E,inspected:C,onInspect:O,opened:ee,onToggle:oe,older:v,logShare:se(p,h),followTail:ne,arrivals:w,columnClassName:u,empty:b?null:/* @__PURE__ */ (0,N.jsx)(qt,{caughtUp:m,readProgress:v.exhausted?void 0:se(p,h),text:D?`No event matches the filter.`:s}),footer:o?/* @__PURE__ */ (0,N.jsx)(`div`,{className:`bg-background`,children:/* @__PURE__ */ (0,N.jsx)(`div`,{className:u,children:/* @__PURE__ */ (0,N.jsx)(ct,{onAppend:o,onAppended:()=>re(e=>e+1),events:p,processors:y})})}):null}),/* @__PURE__ */ (0,N.jsx)(Ne,{events:p,offset:C,older:v,inspectors:ie,onNavigate:O,onClose:()=>a({event:void 0})}),/* @__PURE__ */ (0,N.jsx)(wt,{open:!!i.processors,onClose:()=>a({processors:void 0}),processors:y,presence:g,liveState:_,events:p,head:h,onPickActor:e=>a({actor:e,processors:void 0})})]})}function Wt({events:e,filter:t,counting:n}){let[r]=(0,k.useState)(()=>K(Ce)),i=(0,k.useMemo)(()=>r(e,t).shown,[r,e,t]),[a]=(0,k.useState)(()=>K(xe)),{items:o,namedBefore:s}=(0,k.useMemo)(()=>a(i,U),[a,i]),[c]=(0,k.useState)(()=>K(we));return{shown:i,items:o,namedBefore:s,types:(0,k.useMemo)(()=>n?Ee(c(e).counts):[],[n,c,e])}}function Gt({filtered:e,shown:t,loaded:n,older:r,head:i}){return e?`${t.length.toLocaleString()} of ${n} loaded events`:r.exhausted?`${n} events`:`${n} loaded of ~${(i??0).toLocaleString()} events`}function Kt({title:e,count:t,caughtUp:n,events:r,presence:i,pickedActor:a,filtering:o,filtered:s,processorCount:c,onStateChange:l}){return/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-2.5 py-1.5 @2xl:px-4`,children:[/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-3`,children:[e?/* @__PURE__ */ (0,N.jsx)(`div`,{className:`min-w-0 truncate text-sm`,children:e}):null,/* @__PURE__ */ (0,N.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground tabular-nums`,children:[t,n?``:` · loading`,/* @__PURE__ */ (0,N.jsx)(dt,{events:r})]})]}),/* @__PURE__ */ (0,N.jsx)(pt,{className:`hidden min-w-0 @3xl:flex`,actors:i.actors,rpcStubs:i.rpcStubs,onPick:e=>l({actor:a===e?void 0:e})}),/* @__PURE__ */ (0,N.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 text-xs`,children:[/* @__PURE__ */ (0,N.jsx)(`button`,{type:`button`,onClick:()=>l({filter:!o||void 0}),"aria-expanded":o,className:Ht(o||s),children:`Filter`}),/* @__PURE__ */ (0,N.jsxs)(`button`,{type:`button`,onClick:()=>l({...d,processors:!0}),className:Ht(!1),children:[`Processors `,/* @__PURE__ */ (0,N.jsx)(`span`,{className:`text-foreground tabular-nums`,children:c})]})]})]})}function qt({caughtUp:e,readProgress:t,text:n}){return!e||t!==void 0?/* @__PURE__ */ (0,N.jsx)(h,{label:e?`Reading the log`:`Loading the log`,progress:e?t:void 0,className:`px-3 sm:px-4 py-6`}):/* @__PURE__ */ (0,N.jsx)(`p`,{className:`px-3 sm:px-4 py-6 text-sm text-muted-foreground`,children:n})}export{A as i,K as n,M as r,Ut as t};
M dist/chunks/dash.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/dist3.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/docs-editor-icons.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/highlighted-body-KPVGNVTW.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{i as r,n as i,t as a}from"./dist3.mjs";var o=/* @__PURE__ */ e(t(),1),s=/* @__PURE__ */ e(n(),1),c=({code:e,language:t,maxHeight:n,raw:c,className:l,startLine:u,lineNumbers:d,...f})=>{let{shikiTheme:p}=(0,o.useContext)(i),m=a(),[h,g]=(0,o.useState)(c);return(0,o.useEffect)(()=>{if(!m){g(c);return}let n=m.highlight({code:e,language:t,themes:p},e=>{g(e)});n&&g(n)},[e,t,p,m,c]),(0,s.jsx)(r,{className:l,language:t,lineNumbers:d,maxHeight:n,result:h,startLine:u,...f})};export{c as HighlightedCodeBlockBody}; +import{r as e}from"./rolldown-runtime.mjs";import{a as t,n}from"./vendor-react";import{n as r,o as i,r as a}from"./dist3.mjs";var o=/* @__PURE__ */ e(t(),1),s=/* @__PURE__ */ e(n(),1),c=({code:e,language:t,maxHeight:n,raw:c,className:l,startLine:u,lineNumbers:d,...f})=>{let{shikiTheme:p}=(0,o.useContext)(a),m=r(),[h,g]=(0,o.useState)(c);return(0,o.useEffect)(()=>{if(!m){g(c);return}let n=m.highlight({code:e,language:t,themes:p},e=>{g(e)});n&&g(n)},[e,t,p,m,c]),(0,s.jsx)(i,{className:l,language:t,lineNumbers:d,maxHeight:n,result:h,startLine:u,...f})};export{c as HighlightedCodeBlockBody};
M dist/chunks/host.mjs
@@ -1,4 +1,4 @@ -import{r as e}from"./rolldown-runtime.mjs";import{a as t}from"./vendor-react";import{n,t as r}from"./dist.mjs";import{_ as i,r as a}from"./vendor-zod";var o=/* @__PURE__ */ e(t(),1);function s(e,t){let n={},r=!1;for(let i of Object.keys(t))i===`events`||e&&e[i]===t[i]||(n[i]=t[i],r=!0);return(!e||e.events!==t.events)&&(n.events=c(e?.events||[],t.events),r=!0),r?n:null}function c(e,t){let n=e[0],r=e.at(-1);if(!n||!r)return{reset:[...t]};let i=t.findIndex(e=>e.offset===n.offset),a=i+e.length-1;return i<0||t[a]?.offset!==r.offset?{reset:[...t]}:{prepend:t.slice(0,i),append:t.slice(a+1)}}var l=class{name;source;verbs;#e;#t=/* @__PURE__ */ new Set;#n;#r;#i;constructor(e,t){this.name=e,this.source=t}loaded=()=>this.#e;subscribe=e=>(this.#t.add(e),()=>void this.#t.delete(e));push(e){if(this.#i=e,!this.#n)return;let t=s(this.#r,e);this.#r=e,t&&this.#n.update(t)}attach=e=>{if(!e)return;let t=t=>{if(t.source!==e.contentWindow||t.data?.type!==`iterate/agent-kind-view-ready`)return;this.#a();let r=new MessageChannel,i={type:`iterate/agent-kind-view`,name:this.name,source:this.source};e.contentWindow?.postMessage(i,`*`,[r.port2]),this.#n=n(r.port1,new u(this)),this.#i&&this.push(this.#i)};return window.addEventListener(`message`,t),()=>{window.removeEventListener(`message`,t),this.#a()}};async start(e){if(!this.#n)throw Error(`${this.name} has not loaded yet`);return a(i()).parse(await this.#n.start(e))}setLoaded(e){this.#e=e;for(let e of this.#t)e()}#a(){this.#n?.[Symbol.dispose](),this.#n=void 0,this.#r=void 0}},u=class extends r{#e;constructor(e){super(),this.#e=e}#t(){if(!this.#e.verbs)throw Error(`the page is not showing this agent`);return this.#e.verbs}loaded(e){this.#e.setLoaded(e)}message(e){return this.#t().message(e)}append(e){return this.#t().append(e)}fileUrl(e){return this.#t().fileUrl(e)}storeFiles(...[e,t]){let{storeFiles:n}=this.#t();if(!n)throw Error(`This page cannot store files for this agent.`);return n(e,t)}setState(e){this.#t().setState(e)}loadOlder(){this.#t().loadOlder()}callTool(e){let{callTool:t}=this.#t();if(!t)throw Error(`This page cannot call an MCP App's server for this agent.`);return t(e)}readResource(e){let{readResource:t}=this.#t();if(!t)throw Error(`This page cannot read an MCP App's server for this agent.`);return t(e)}readContext(e){let{readContext:t}=this.#t();if(!t)throw Error(`This page reads no context for a widget of this agent.`);return t(e)}};function d(e,t){let n=(0,o.useMemo)(()=>new l(e,t),[e,t]);return{link:n,loaded:(0,o.useSyncExternalStore)(n.subscribe,n.loaded,()=>void 0)}}function f({link:e,frameScript:t,inputs:n,verbs:r}){e.verbs=r,(0,o.useEffect)(()=>e.push(n),[e,n]);let i=(0,o.useMemo)(()=>v(t),[t]);return(0,o.createElement)(`iframe`,{ref:e.attach,title:e.name,sandbox:`allow-scripts allow-popups allow-popups-to-escape-sandbox allow-downloads`,srcDoc:i,className:`min-h-0 w-full flex-1 border-0`})}function p({link:e,frameScript:t}){e.verbs=void 0;let n=(0,o.useMemo)(()=>v(t),[t]);return(0,o.createElement)(`iframe`,{ref:e.attach,title:e.name,sandbox:`allow-scripts`,srcDoc:n,hidden:!0,"aria-hidden":!0,tabIndex:-1})}const m=e=>!e.includes(`ͼ`);function h(e,t){let n=e.media?` media="${y(e.media)}"`:``;return!e.rules||new URL(e.href).origin!==t?`<link rel="stylesheet" href="${y(e.href)}"${n}>`:`<style${n}>${g(e.rules.join(` +import{r as e}from"./rolldown-runtime.mjs";import{a as t}from"./vendor-react";import{n,t as r}from"./dist.mjs";import{r as i,v as a}from"./vendor-zod";var o=/* @__PURE__ */ e(t(),1);function s(e,t){let n={},r=!1;for(let i of Object.keys(t))i===`events`||e&&e[i]===t[i]||(n[i]=t[i],r=!0);return(!e||e.events!==t.events)&&(n.events=c(e?.events||[],t.events),r=!0),r?n:null}function c(e,t){let n=e[0],r=e.at(-1);if(!n||!r)return{reset:[...t]};let i=t.findIndex(e=>e.offset===n.offset),a=i+e.length-1;return i<0||t[a]?.offset!==r.offset?{reset:[...t]}:{prepend:t.slice(0,i),append:t.slice(a+1)}}var l=class{name;source;verbs;#e;#t=/* @__PURE__ */ new Set;#n;#r;#i;constructor(e,t){this.name=e,this.source=t}loaded=()=>this.#e;subscribe=e=>(this.#t.add(e),()=>void this.#t.delete(e));push(e){if(this.#i=e,!this.#n)return;let t=s(this.#r,e);this.#r=e,t&&this.#n.update(t)}attach=e=>{if(!e)return;let t=t=>{if(t.source!==e.contentWindow||t.data?.type!==`iterate/agent-kind-view-ready`)return;this.#a();let r=new MessageChannel,i={type:`iterate/agent-kind-view`,name:this.name,source:this.source};e.contentWindow?.postMessage(i,`*`,[r.port2]),this.#n=n(r.port1,new u(this)),this.#i&&this.push(this.#i)};return window.addEventListener(`message`,t),()=>{window.removeEventListener(`message`,t),this.#a()}};async start(e){if(!this.#n)throw Error(`${this.name} has not loaded yet`);return i(a()).parse(await this.#n.start(e))}setLoaded(e){this.#e=e;for(let e of this.#t)e()}#a(){this.#n?.[Symbol.dispose](),this.#n=void 0,this.#r=void 0}},u=class extends r{#e;constructor(e){super(),this.#e=e}#t(){if(!this.#e.verbs)throw Error(`the page is not showing this agent`);return this.#e.verbs}loaded(e){this.#e.setLoaded(e)}message(e){return this.#t().message(e)}append(e){return this.#t().append(e)}fileUrl(e){return this.#t().fileUrl(e)}storeFiles(...[e,t]){let{storeFiles:n}=this.#t();if(!n)throw Error(`This page cannot store files for this agent.`);return n(e,t)}setState(e){this.#t().setState(e)}loadOlder(){this.#t().loadOlder()}callTool(e){let{callTool:t}=this.#t();if(!t)throw Error(`This page cannot call an MCP App's server for this agent.`);return t(e)}readResource(e){let{readResource:t}=this.#t();if(!t)throw Error(`This page cannot read an MCP App's server for this agent.`);return t(e)}readContext(e){let{readContext:t}=this.#t();if(!t)throw Error(`This page reads no context for a widget of this agent.`);return t(e)}};function d(e,t){let n=(0,o.useMemo)(()=>new l(e,t),[e,t]);return{link:n,loaded:(0,o.useSyncExternalStore)(n.subscribe,n.loaded,()=>void 0)}}function f({link:e,frameScript:t,inputs:n,verbs:r}){e.verbs=r,(0,o.useEffect)(()=>e.push(n),[e,n]);let i=(0,o.useMemo)(()=>v(t),[t]);return(0,o.createElement)(`iframe`,{ref:e.attach,title:e.name,sandbox:`allow-scripts allow-popups allow-popups-to-escape-sandbox allow-downloads`,srcDoc:i,className:`min-h-0 w-full flex-1 border-0`})}function p({link:e,frameScript:t}){e.verbs=void 0;let n=(0,o.useMemo)(()=>v(t),[t]);return(0,o.createElement)(`iframe`,{ref:e.attach,title:e.name,sandbox:`allow-scripts`,srcDoc:n,hidden:!0,"aria-hidden":!0,tabIndex:-1})}const m=e=>!e.includes(`ͼ`);function h(e,t){let n=e.media?` media="${y(e.media)}"`:``;return!e.rules||new URL(e.href).origin!==t?`<link rel="stylesheet" href="${y(e.href)}"${n}>`:`<style${n}>${g(e.rules.join(` `))}</style>`}const g=e=>e.replaceAll(`</`,`<\\/`);function _(e){try{return e&&[...e.cssRules].map(e=>e.cssText)}catch{return null}}function v(e){if(!globalThis.document)return``;let t=[...document.querySelectorAll(`link[rel="stylesheet"], style`)].flatMap(e=>{if(e instanceof HTMLLinkElement)return[h({href:e.href,media:e.media,rules:_(e.sheet)},location.origin)];let t=e.textContent||``;return m(t)?[`<style>${g(t)}</style>`]:[]}).join(` `);return`<!doctype html> <html class="${y(document.documentElement.className)}">
M dist/chunks/mermaid-HWGCJPDP.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"./dist3.mjs";export{e as Mermaid}; +import{i as e}from"./dist3.mjs";export{e as Mermaid};
M dist/chunks/message.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/presence-line.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/principal-label.mjs
@@ -1,1 +1,1 @@ -const e=e=>r(e,e.email||e.name||e.actor),t=e=>r(e,e.email?.split(`@`,1)[0]||e.name||e.actor),n=e=>({who:e.email||e.actor,name:e.email?void 0:e.name}),r=(e,t)=>e.kind===`guest`?`${t} (guest)`:t;export{e as n,t as r,n as t}; +const e=e=>r(e,e.email||e.name||e.actor),t=e=>r(e,e.email?.split(`@`,1)[0]||e.name||e.actor),n=e=>({who:e.email||e.actor,name:e.email?void 0:e.name,...e.kind===`mind`&&{kind:`mind`}}),r=(e,t)=>e.kind===`guest`?`${t} (guest)`:t;export{e as n,t as r,n as t};
M dist/chunks/react.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/run.mjs
@@ -1,1 +1,1 @@ -import{_ as e,a as t,c as n,d as r,m as i,t as a,u as o}from"./vendor-zod";const s=r({code:i().min(1)}),c=a([`runtime`,`deadline`,`interrupted`]),l=r({requestOffset:o().int().positive(),settlement:t(`status`,[r({status:n(`succeeded`),result:e().optional()}),r({status:n(`failed`),error:i(),failureKind:c})])});r({failureKind:c});const u=6e5;export{s as n,l as r,u as t}; +import{a as e,d as t,f as n,h as r,l as i,t as a,v as o}from"./vendor-zod";const s=n({code:r().min(1)}),c=a([`runtime`,`deadline`,`interrupted`]),l=n({requestOffset:t().int().positive(),settlement:e(`status`,[n({status:i(`succeeded`),result:o().optional()}),n({status:i(`failed`),error:r(),failureKind:c})])});n({failureKind:c});const u=6e5;export{s as n,l as r,u as t};
M dist/chunks/sonner.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/ui-shell.mjs
Not shown: the change is larger than this page shows. A clone has it.
A dist/chunks/vendor-db.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/vendor-icons.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/vendor-zod.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/virtual-log.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/chunks/waiting-approvals.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/agent-chat/chat-parts.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/agent-context.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/agents-home.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/agents-nav.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/call/call-bar.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/call/call-controls.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/call/call-pip.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/call/caption-strip.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/call/face.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/call/transcript-rollup.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/change-my-mind-button.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/checklist.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/connect-mind.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/context-catalog/context-catalog.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/context-explorer/context-explorer.mjs
Not shown: the change is larger than this page shows. A clone has it.
A dist/components/context-stream/context-stream.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/copy-text.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/dash/dash-paths.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/docs-editor/docs-editor.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/identifier.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/integrations-page.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/last-mind-redirect.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/mcp-connect.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/page-tools.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/repo-ide/repo-ide.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/secrets-page.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/setup-steps.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/step-row.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/ui/breadcrumb.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/ui/checkbox.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/ui/native-select.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/ui/select.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/components/ui/spinner.mjs
@@ -1,1 +1,1 @@ -import{r as e}from"../../chunks/rolldown-runtime.mjs";import{n as t}from"../../chunks/vendor-react";import{Y as n}from"../../chunks/vendor-icons";import{c as r}from"../../chunks/ui-base";var i=/* @__PURE__ */ e(t(),1);function a({className:e,...t}){return/* @__PURE__ */ (0,i.jsx)(n,{"data-slot":`spinner`,role:`status`,"aria-label":`Loading`,className:r(`size-4 animate-spin`,e),...t})}export{a as Spinner}; +import{r as e}from"../../chunks/rolldown-runtime.mjs";import{n as t}from"../../chunks/vendor-react";import{X as n}from"../../chunks/vendor-icons";import{c as r}from"../../chunks/ui-base";var i=/* @__PURE__ */ e(t(),1);function a({className:e,...t}){return/* @__PURE__ */ (0,i.jsx)(n,{"data-slot":`spinner`,role:`status`,"aria-label":`Loading`,className:r(`size-4 animate-spin`,e),...t})}export{a as Spinner};
A dist/db.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/docs-editor.css
Not shown: the change is larger than this page shows. A clone has it.
M dist/icons.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/iterate.css
Not shown: the change is larger than this page shows. A clone has it.
M dist/lib/agent-progress.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/lib/call-rules.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/lib/page-url.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/lib/presence.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/lib/saved-log-tail.mjs
Not shown: the change is larger than this page shows. A clone has it.
M dist/styles.css
Not shown: the change is larger than this page shows. A clone has it.
M files.json
Not shown: the change is larger than this page shows. A clone has it.
M package.json
Not shown: the change is larger than this page shows. A clone has it.
M release.json
Not shown: the change is larger than this page shows. A clone has it.