@sigrun/sigrun 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,4 +52,4 @@ Error generating stack: `+e.message+`
52
52
 
53
53
  `)},`note:${e.entryId}`)}return null}),(0,R.jsx)(rd,{kind:`assistant`,text:n.text,onFork:d,meta:u?.text,metaTitle:u?.title})]})}function Ch(e,t){for(let n of e)if(n.kind===`pi.assistant`)for(let e of n.model??[]){let n=e.content;if(typeof n!=`string`)for(let e of n){if(e.type!==`toolCall`)continue;let n=e;if(n.id===t)return typeof n.arguments==`string`?n.arguments:n.arguments===void 0?void 0:JSON.stringify(n.arguments)}}}function wh(e){let{entry:t}=e,n=(t.data??{}).reason;return(0,R.jsx)(`div`,{className:`turn-compaction`,"data-reason":n,title:n===void 0?void 0:`context compacted (${n})`,children:(0,R.jsx)(`span`,{children:`Context compacted`})})}function Th(e){return(0,R.jsx)(`div`,{className:`entry entry-system`,children:(e.entry.model??[]).map(e=>Gm(e)).filter(e=>e!==``).join(` `)})}function Eh(e){if(e.kind!==`sigrun.blocks.answer`)return;let t=e.data;if(typeof t!=`object`||!t)return;let n=t.entryId,r=t.action;if(typeof n!=`string`||n===``||typeof r!=`string`||r===``)return;let i=t.payload,a=t.state;return{entryId:n,action:r,...i===void 0?{}:{payload:i},...a===void 0?{}:{state:a}}}function Dh(e){if(typeof e!=`object`||!e)return;let t=e.title;return typeof t==`string`&&t!==``?t:void 0}function Oh(e){return(e.model??[]).map(e=>Gm(e)).filter(e=>e!==``).join(`
54
54
 
55
- `)}function kh(e){return Ae(e)?.typed??Oh(e)}function Ah(e){let[t,n]=(0,v.useState)(!1),{expanded:r,fullText:i}=e;return(0,R.jsxs)(`div`,{className:`entry-expanded`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`entry-expanded-chip`,"aria-expanded":t,title:t?`Hide the expanded text`:`Show the expanded text`,onClick:()=>n(!t),children:[`expanded from /`,r.command??`…`]}),t&&(0,R.jsx)(`div`,{className:`entry-expanded-text`,children:(0,R.jsx)(md,{source:i,variant:`bubble`})})]})}function jh(e){let{entry:t}=e,n=Ae(t),r=Eh(t),i=r===void 0?void 0:(e.entries??[]).find(e=>e.kind===`sigrun.blocks`&&String(e.id)===r.entryId),a=i===void 0?void 0:Dh(i.data);return(0,R.jsxs)(`div`,{className:`turn turn-user`,"data-turn-kind":`user`,"data-entry-id":t.id,children:[(0,R.jsxs)(`div`,{className:`entry-user`,children:[n===void 0?(t.model??[]).map((e,t)=>(0,R.jsxs)(`div`,{className:`entry-user-message`,children:[(0,R.jsx)(md,{source:Gm(e),variant:`bubble`}),qm(e).map((e,t)=>(0,R.jsxs)(`span`,{className:`entry-attachment`,children:[`[`,e.type,`: `,e.path??`?`,`]`]},t))]},t)):(0,R.jsxs)(`div`,{className:`entry-user-message`,children:[(0,R.jsx)(md,{source:n.typed,variant:`bubble`}),(t.model??[]).flatMap(e=>qm(e).map((e,t)=>(0,R.jsxs)(`span`,{className:`entry-attachment`,children:[`[`,e.type,`: `,e.path??`?`,`]`]},t)))]}),n!==void 0&&(0,R.jsx)(Ah,{expanded:n,fullText:Oh(t)}),r!==void 0&&(0,R.jsxs)(`span`,{className:`entry-answer-chip`,"data-answer-entry":r.entryId,children:[`from `,a??`entry ${r.entryId}`]})]}),(0,R.jsx)(rd,{kind:`user`,text:kh(t),onFork:e.onFork,onEdit:e.onEdit})]})}function Mh(e){return e.docs[`pi.live`]}function Nh(e){return Mh(e)?.tools??[]}function Ph(e){let t=Mh(e)?.generation?.message;if(typeof t==`object`&&t)return t}function Fh(e){return Mh(e)?.compactions?.length??0}function Ih(e){let t=Mh(e)?.compactionFailure;if(typeof t!=`object`||!t)return;let n=t.error;return typeof n==`string`&&n!==``?n:void 0}function Lh(e){return e}function Rh(e){return Nh(Lh(e))}function zh(e){return Ph(Lh(e))}function Bh(e){return Fh(Lh(e))}function Vh(e){return Ih(Lh(e))}var Hh=-1;function Uh(e){let t=e.content;return typeof t==`string`?[]:t.filter(e=>e.type===`toolCall`).map(e=>{let t=e;return{callId:t.id??``,name:t.name??``,preview:Fe(t.name??``,t.arguments),isError:!1}})}function Wh(e,t){return{entries:[{id:Hh,conversationId:e,kind:`pi.assistant`,model:[t]}],thinking:Km(t),tools:Uh(t),text:Gm(t),lastEntryId:Hh,timeline:Gh(t)}}function Gh(e){let t=[];for(let n of Km(e))t.push({kind:`thinking`,text:n});for(let n of Uh(e))t.push({kind:`tool`,tool:n});let n=Gm(e);return n!==``&&t.push({kind:`text`,text:n}),t}function Kh(e){let{view:t,showThinking:n,timeline:r,parent:i,onNavigate:a,client:o}=e,s=t.conversation.id,c=Rh(t),l=zh(t),u=Me(t.entries),d=u[u.length-1],f=l!==void 0&&d!==void 0&&d.kind===`assistant`;if(f&&d!==void 0&&d.kind===`assistant`){let e=Gm(l),t=Uh(l).filter(e=>!d.tools.some(t=>t.callId===e.callId));u[u.length-1]={...d,text:d.text===``?e:`${d.text}\n\n${e}`,thinking:[...d.thinking,...Km(l)],tools:[...d.tools,...t],timeline:[...d.timeline,...Km(l).map(e=>({kind:`thinking`,text:e})),...t.map(e=>({kind:`tool`,tool:e})),...e===``?[]:[{kind:`text`,text:e}]]}}let p=e=>()=>{o.fork(s,e).then(e=>a(e.id)).catch(e=>console.error(`fork from conversation ${s} failed:`,e))};return(0,R.jsxs)(`div`,{className:`turn-list`,children:[i!==void 0&&(0,R.jsxs)(`button`,{type:`button`,className:`turn-lineage`,onClick:()=>a(i.id),children:[`Forked from `,i.name]}),u.map((e,i)=>e.kind===`user`?(0,R.jsx)(qh,{entry:e.entry,entries:t.entries,view:t,client:o,conversationId:s,onNavigate:a,forkFrom:p},e.entry.id):e.kind===`assistant`?(0,R.jsx)(Sh,{conversationId:s,turn:e,slots:c,showThinking:n,client:o,onNavigate:a,live:f&&i===u.length-1,timeline:r},e.lastEntryId):(0,R.jsx)(Jh,{entry:e.entry},e.entry.id)),l!==void 0&&!f&&(0,R.jsx)(Sh,{conversationId:s,turn:Wh(s,l),slots:c,showThinking:n,client:o,onNavigate:a,live:!0},Hh)]})}function qh(e){let{entry:t,entries:n,view:r,client:i,conversationId:a,onNavigate:o,forkFrom:s}=e;return(0,R.jsx)(jh,{entry:t,entries:n,onFork:s(t.id),onEdit:()=>{let e=r.entries[r.entries.findIndex(e=>e.id===t.id)-1];(e===void 0?i.createConversation():i.fork(a,e.id)).then(async e=>{await i.patchConversationMeta(e.id,{draft:{text:kh(t)}}),o(e.id)}).catch(e=>console.error(`edit-in-new-conversation failed:`,e))}})}function Jh(e){let{entry:t}=e,n=t.kind===`pi.compaction`?`compaction`:t.kind===`pi.system`?`system`:`other`;return(0,R.jsx)(`div`,{className:`turn turn-other`,"data-turn-kind":n,children:t.kind===`pi.compaction`?(0,R.jsx)(wh,{entry:t}):t.kind===`pi.system`?(0,R.jsx)(Th,{entry:t}):(0,R.jsxs)(`div`,{className:`entry entry-unknown`,children:[`unsupported entry kind: `,t.kind,` —`,` `,(t.model??[]).map(e=>Gm(e)).filter(e=>e!==``).join(` `)]})})}function Yh(e){let t=hh(e.transport,{onNavigate:e.onNavigate,refreshMs:e.refreshMs,visible:e.visible}),n=e.keepaliveMs,r=e.visible,i=(0,v.useRef)(t.refresh);i.current=t.refresh,(0,v.useEffect)(()=>{if(n===void 0)return;let e=setInterval(()=>{(r===void 0||r())&&i.current()},n),t=globalThis.document,a=()=>{(r===void 0||r())&&i.current()};return t?.addEventListener(`visibilitychange`,a),()=>{clearInterval(e),t?.removeEventListener(`visibilitychange`,a)}},[n,r]);let a=navigator.language,o=(0,v.useMemo)(()=>({dispatch:t.dispatch,access:t.access,rev:t.rev,viewState:typeof t.view.view==`object`&&t.view.view!==null&&!Array.isArray(t.view.view)?t.view.view:{},setView:t.setView,serverErrors:t.serverErrors}),[t.dispatch,t.access,t.rev,t.view,t.setView,t.serverErrors]);return t.status===`loading`?(0,R.jsx)(`div`,{className:`blk-surface`,"data-surface":`loading`,children:(0,R.jsx)(`p`,{children:`loading…`})}):t.status===`notFound`?(0,R.jsx)(`div`,{className:`blk-surface`,"data-surface":`not-found`,children:(0,R.jsx)(`p`,{children:`surface not found`})}):t.status===`error`?(0,R.jsxs)(`div`,{className:`blk-surface`,"data-surface":`error`,role:`alert`,children:[(0,R.jsx)(`p`,{children:`something went wrong`}),(0,R.jsx)(`button`,{type:`button`,"data-surface-retry":``,onClick:()=>t.retry(),children:`Retry`})]}):(0,R.jsx)(`div`,{className:`blk-surface`,"data-surface":`ready`,children:(0,R.jsx)(ze.Provider,{value:{data:t.view,locale:a},children:(0,R.jsxs)(Be.Provider,{value:o,children:[(0,R.jsx)(Xe,{children:t.tree!==void 0&&(0,R.jsx)(Kp,{block:t.tree.root})}),t.toasts.map((e,t)=>(0,R.jsx)(`p`,{className:`blk-surface-toast`,role:`status`,children:e},t))]})})})}var Xh=Object.assign({"../../../test/fixtures/blocks/ambient-footer.json":{v:1,root:{type:`columns`,id:`ambient-footer`,children:[{block:{type:`markdown`,text:`left`}},{block:{type:`stat`,label:`Queue`,value:3}},{block:{type:`markdown`,text:`right`}}]}},"../../../test/fixtures/blocks/ambient-panel.json":{v:1,root:{type:`stack`,id:`ambient-panel`,children:[{type:`collection`,id:`checks`,items:[{id:`c1`,name:`lint`,state:`passed`,busy:!1,tone:`good`},{id:`c2`,name:`tests`,state:`running`,busy:!0,tone:`neutral`}],display:`list`,item:{title:{$:`./name`},status:{label:{$:`./state`},spinner:{$:`./busy`}},tone:{$:`./tone`}}},{type:`log`,lines:[{at:1,level:`info`,text:`3 checks running`},{at:2,level:`error`,text:`rollback failed`}]},{type:`meter`,value:62,format:`percent`},{type:`details`,value:{ok:!0}}]}},"../../../test/fixtures/blocks/ambient-status.json":{v:1,root:{type:`markdown`,id:`ambient-status`,text:`glm-5.3-flash · main* · $0.0421`}},"../../../test/fixtures/blocks/callout.json":{v:1,root:{type:`callout`,id:`callout`,tone:`warn`,title:`Degraded`,body:`acme upstream is slow`,actions:[{id:`open`,label:`Open console`,icon:`external`,action:{type:`open`,url:`https://example.invalid/console`}},{id:`copy`,label:`Copy id`,action:{type:`copy`,text:`acme-42`}}]}},"../../../test/fixtures/blocks/chart.json":{v:1,root:{type:`chart`,id:`chart`,title:`Throughput`,x:{kind:`time`,format:`time`},y:{unit:`req/s`,min:0},series:[{name:`acme`,kind:`area`,data:{$:`/series/acme`}},{name:`Baseline`,kind:`line`,data:[[0,10],[60,12],[120,11]]}],stacked:!1,thresholds:[{at:20,tone:`warn`,label:`SLO`}]}},"../../../test/fixtures/blocks/chat-message.json":{v:1,root:{type:`stack`,id:`chat-message`,children:[{type:`markdown`,text:`acme ranking draft`},{type:`collection`,id:`rank`,items:{$:`/songs`},display:`list`,numbered:!0,reorder:{within:!0},onMove:`reorderSong`,item:{title:{$:`./title`},meta:[{person:{user:`user:example`,name:`Example`}}]}},{type:`form`,id:`use`,bind:`/reply`,mode:`submit`,onSubmit:`useOrder`,submitLabel:`Use this order`,turn:!0,children:[{type:`toggle`,name:`confirm`,label:`Confirm`}]}]}},"../../../test/fixtures/blocks/collection-calendar.json":{v:1,root:{type:`collection`,id:`collection-calendar`,items:{$:`/events`},display:`calendar`,time:{start:`startsAt`,end:`endsAt`,allDay:`allDay`,range:`month`,onResize:`resizeEvent`,onCreate:`createEvent`},item:{title:{$:`./title`}}}},"../../../test/fixtures/blocks/collection-grid.json":{v:1,root:{type:`collection`,id:`collection-grid`,items:{$:`/shots`},display:`grid`,overflow:`wrap`,item:{title:{$:`./title`},image:{$:`./image`}}}},"../../../test/fixtures/blocks/collection-lanes.json":{v:1,root:{type:`collection`,id:`collection-lanes`,items:{$:`/cards`},display:`lanes`,groupBy:`state`,groups:[{id:`todo`,title:`To do`,tone:`neutral`},{id:`doing`,title:`Doing`,tone:`info`,collapsed:!1}],reorder:{within:!0,across:!0},onMove:`moveCard`,onActivate:{type:`navigate`,params:{id:`acme`}},item:{title:{$:`./title`},tone:{$:`./tone`}}}},"../../../test/fixtures/blocks/collection-list.json":{v:1,root:{type:`collection`,id:`collection-list`,items:{$:`/cards`},display:`list`,numbered:!0,checkable:`done`,onCheck:`toggleDone`,children:`subtasks`,item:{eyebrow:{$:`./eyebrow`},title:{$:`./title`},subtitle:{$:`./subtitle`},body:{$:`./body`},icon:`file`,badges:[{text:{$:`./badge`},tone:`info`}],meta:[{icon:`clock`,text:{$:`./when`}},{person:{user:{$:`./user`},name:{$:`./userName`}}},{time:{$:`./at`},format:`datetime`}],metrics:[{label:`Score`,value:{$:`./score`},format:`number`}],tone:`accent`,status:{label:{$:`./state`},tone:`good`,spinner:{$:`./busy`}},quiet:{$:`./quiet`},deps:{$:`./deps`}}}},"../../../test/fixtures/blocks/collection-literal.json":{v:1,root:{type:`collection`,id:`collection-literal`,items:[{id:`row-1`,title:`acme provision`,state:`todo`,quiet:!1},{id:`row-2`,title:`acme build`,state:`doing`,quiet:!0}],display:`list`,item:{title:{$:`./title`},status:{label:{$:`./state`}},quiet:{$:`./quiet`}}}},"../../../test/fixtures/blocks/collection-table.json":{v:1,root:{type:`collection`,id:`collection-table`,items:{$:`/rows`},display:`table`,select:`multi`,sort:{field:`name`,dir:`asc`},bulkActions:[{id:`set-state`,label:`Set state`,icon:`edit`,onSubmit:`setState`,form:{v:1,root:{type:`form`,id:`set-state-form`,bind:`/bulk`,mode:`submit`,onSubmit:`setState`,children:[{type:`text`,name:`state`,label:`State`}]}}}],columns:[{field:`name`,label:`Name`,sortable:!0,priority:`high`},{field:`load`,label:`Load`,format:`percent`,cell:`meter`,priority:`low`},{field:`state`,label:`State`,cell:`badge`,width:`s`}],item:{title:{$:`./name`}}}},"../../../test/fixtures/blocks/columns.json":{v:1,root:{type:`columns`,id:`columns`,children:[{weight:2,minWidth:`m`,block:{type:`markdown`,text:`left`}},{weight:1,block:{type:`stat`,label:`Load`,value:.42,format:`percent`,size:`m`,icon:`clock`}}]}},"../../../test/fixtures/blocks/details.json":{v:1,root:{type:`details`,id:`details`,value:{host:`acme.example`,tags:[`a`,`b`],nested:{ok:!0}}}},"../../../test/fixtures/blocks/diff.json":{v:1,root:{type:`diff`,id:`diff`,before:`const a = 1;`,after:`const a = 2;`,path:`src/acme.ts`,lang:`ts`}},"../../../test/fixtures/blocks/field-choice.json":{v:1,root:{type:`form`,id:`form-choice`,bind:`/values`,mode:`submit`,children:[{type:`choice`,name:`pick`,label:`Pick`,multi:!0,options:[{id:`a`,label:`A`,description:`first`},{id:`b`,label:`B`,tone:`good`}]}]}},"../../../test/fixtures/blocks/field-date.json":{v:1,root:{type:`form`,id:`form-date`,bind:`/values`,mode:`submit`,children:[{type:`date`,name:`on`,label:`On`}]}},"../../../test/fixtures/blocks/field-daterange.json":{v:1,root:{type:`form`,id:`form-daterange`,bind:`/values`,mode:`submit`,children:[{type:`daterange`,name:`range`,label:`Range`,presets:[{id:`today`,label:`Today`,duration:`P1D`}]}]}},"../../../test/fixtures/blocks/field-datetime.json":{v:1,root:{type:`form`,id:`form-datetime`,bind:`/values`,mode:`submit`,children:[{type:`datetime`,name:`at`,label:`At`}]}},"../../../test/fixtures/blocks/field-file.json":{v:1,root:{type:`form`,id:`form-file`,bind:`/values`,mode:`submit`,children:[{type:`file`,name:`logo`,label:`Logo`,accept:`image/png`,multi:!0,onUpload:`uploadLogo`}]}},"../../../test/fixtures/blocks/field-list.json":{v:1,root:{type:`form`,id:`form-list`,bind:`/values`,mode:`submit`,children:[{type:`list`,name:`members`,label:`Members`,item:{type:`text`,name:`name`,label:`Name`},reorder:!0}]}},"../../../test/fixtures/blocks/field-longtext.json":{v:1,root:{type:`form`,id:`form-longtext`,bind:`/values`,mode:`submit`,children:[{type:`longtext`,name:`notes`,label:`Notes`,syntax:`markdown`,lang:`md`,rows:8,maxLength:4e3}]}},"../../../test/fixtures/blocks/field-number.json":{v:1,root:{type:`form`,id:`form-number`,bind:`/values`,mode:`submit`,children:[{type:`number`,name:`port`,label:`Port`,min:1,max:65535,step:1,format:`number`}]}},"../../../test/fixtures/blocks/field-secret.json":{v:1,root:{type:`form`,id:`form-secret`,bind:`/values`,mode:`submit`,children:[{type:`secret`,name:`apiKey`,label:`API key`}]}},"../../../test/fixtures/blocks/field-text.json":{v:1,root:{type:`form`,id:`form-text`,bind:`/values`,mode:`submit`,children:[{type:`text`,name:`name`,label:`Name`,kind:`email`,suggest:{$:`/suggestions`},required:!0,minLength:2,placeholder:`acme@example.invalid`}]}},"../../../test/fixtures/blocks/field-toggle.json":{v:1,root:{type:`form`,id:`form-toggle`,bind:`/values`,mode:`live`,children:[{type:`toggle`,name:`dark`,label:`Dark mode`,disabled:!1}]}},"../../../test/fixtures/blocks/fields.json":{v:1,root:{type:`fields`,id:`fields`,rows:[{label:`Host`,value:`acme.example`},{label:`Errors`,value:2,tone:`bad`,icon:`error`}]}},"../../../test/fixtures/blocks/form-chat.json":{v:1,root:{type:`form`,id:`form-chat`,bind:`/reply`,mode:`submit`,onSubmit:`sendReply`,submitLabel:`Send`,turn:!0,children:[{type:`choice`,name:`answer`,label:`Answer`,options:[{id:`yes`,label:`Yes`,preview:`proceed with the acme plan`},{id:`no`,label:`No`,tone:`bad`}]},{type:`longtext`,name:`reason`,label:`Reason`,syntax:`plain`}]}},"../../../test/fixtures/blocks/form-inline.json":{v:1,root:{type:`form`,id:`form-inline`,bind:`/view/quick`,mode:`inline`,onSubmit:`addQuick`,submitLabel:`Add`,children:[{type:`text`,name:`title`,label:`Title`,placeholder:`new item`,kind:`search`}]}},"../../../test/fixtures/blocks/form-interaction.json":{v:1,root:{type:`form`,id:`form-interaction`,bind:`/values`,mode:`submit`,onSubmit:`answer`,submitLabel:`Answer`,children:[{type:`section`,title:`Approve`,children:[{type:`choice`,name:`verdict`,label:`Verdict`,options:[{id:`allow`,label:`Allow`,tone:`good`,recommended:!0,preview:`run it`},{id:`deny`,label:`Deny`,tone:`bad`}]}]},{type:`longtext`,name:`reason`,label:`Reason`,required:!0},{type:`secret`,name:`token`,label:`Token`,help:`optional`}]}},"../../../test/fixtures/blocks/form-settings.json":{v:1,root:{type:`form`,id:`form-settings`,bind:`/settings`,mode:`submit`,onSubmit:`saveSettings`,children:[{type:`text`,name:`host`,label:`Host`,apply:`live`},{type:`choice`,name:`plan`,label:`Plan`,options:[{id:`basic`,label:`Basic`},{id:`pro`,label:`Pro`,recommended:!0}]},{type:`toggle`,name:`verbose`,label:`Verbose`,apply:`restart`},{type:`date`,name:`since`,label:`Since`},{type:`datetime`,name:`at`,label:`At`,min:0},{type:`daterange`,name:`window`,label:`Window`,presets:[{id:`7d`,label:`Last 7 days`,duration:`P7D`}]},{type:`list`,name:`hosts`,label:`Hosts`,reorder:!0,min:1,max:10,item:{type:`text`,name:`host`,label:`Host`,pattern:`^[a-z].*$`}}]}},"../../../test/fixtures/blocks/form-upload.json":{v:1,root:{type:`form`,id:`form-upload`,bind:`/upload`,mode:`submit`,onSubmit:`saveUpload`,children:[{type:`file`,name:`avatar`,label:`Avatar`,accept:`image/*`,maxBytes:1048576,onUpload:`uploadAvatar`}]}},"../../../test/fixtures/blocks/form-view.json":{v:1,root:{type:`form`,id:`form-view`,bind:`/view/filter`,mode:`live`,children:[{type:`choice`,name:`state`,label:`State`,multi:!1,allowOther:{label:`Other`},options:[{id:`all`,label:`All`,description:`every item`,recommended:!0},{id:`open`,label:`Open`,tone:`info`}]}]}},"../../../test/fixtures/blocks/form.json":{v:1,root:{type:`form`,id:`form`,bind:`/form`,mode:`submit`,onSubmit:`saveForm`,submitLabel:`Save`,children:[{type:`section`,title:`Basics`,children:[{type:`text`,name:`title`,label:`Title`,required:!0,maxLength:80}]},{type:`longtext`,name:`notes`,label:`Notes`,syntax:`markdown`,rows:4,help:`markdown ok`},{type:`number`,name:`retries`,label:`Retries`,min:0,max:5,step:1},{type:`toggle`,name:`enabled`,label:`Enabled`,help:`run the acme loop`}]}},"../../../test/fixtures/blocks/grid.json":{v:1,root:{type:`grid`,id:`grid`,minItemWidth:`m`,children:[{span:2,block:{type:`stat`,label:`Wide`,value:12,sparkline:[1,2,3]}},{block:{type:`stat`,label:`Narrow`,value:3}},{span:`full`,block:{type:`markdown`,text:`full row`}}]}},"../../../test/fixtures/blocks/image.json":{v:1,root:{type:`image`,id:`image`,src:`asset:acme/diagram.png`,alt:`acme cluster diagram`}},"../../../test/fixtures/blocks/interaction-form.json":{v:1,root:{type:`form`,id:`interaction-body`,bind:`/values`,mode:`submit`,onSubmit:`answer`,submitLabel:`Answer`,children:[{type:`section`,title:`Proceed?`,children:[{type:`choice`,name:`proceed`,label:`Proceed`,options:[{id:`yes`,label:`Yes`,tone:`good`,preview:`deploy to acme`},{id:`no`,label:`No`,tone:`bad`}]}]},{type:`text`,name:`note`,label:`Note`}]}},"../../../test/fixtures/blocks/log-literal.json":{v:1,root:{type:`log`,id:`log-literal`,lines:[{at:1,level:`info`,text:`deploy started`},{at:2,level:`warn`,text:`cache cold`},{at:3,level:`error`,text:`rollback failed`}],follow:!0,wrap:!1,tones:{error:`bad`,warn:`warn`,info:`neutral`}}},"../../../test/fixtures/blocks/log.json":{v:1,root:{type:`log`,id:`log`,lines:{$:`/lines`},follow:!0,wrap:!1,tones:{error:`bad`,warn:`warn`,info:`neutral`}}},"../../../test/fixtures/blocks/markdown.json":{v:1,root:{type:`markdown`,id:`markdown`,text:`acme **status** at [example.invalid](https://example.invalid/x)`}},"../../../test/fixtures/blocks/meter-literal.json":{v:1,root:{type:`meter`,id:`meter-literal`,value:.62,min:0,max:1,label:`Disk`,format:`percent`,thresholds:[{at:.8,tone:`warn`},{at:.95,tone:`bad`}]}},"../../../test/fixtures/blocks/meter.json":{v:1,root:{type:`meter`,id:`meter`,value:{$:`/disk`},min:0,max:1,label:`Disk`,format:`percent`,thresholds:[{at:.8,tone:`warn`},{at:.95,tone:`bad`}]}},"../../../test/fixtures/blocks/page-selection.json":{v:1,root:{type:`page`,id:`page`,title:`Jobs`,subtitle:`acme queue`,sidebar:[{type:`collection`,id:`jobs`,items:[{id:`job-1`,title:`acme provision`},{id:`job-2`,title:`acme build`},{id:`job-3`,title:`acme deploy`}],display:`list`,item:{title:{$:`./title`}}}],main:[{type:`markdown`,text:`acme build — the selected job's detail`}],selection:{selected:!0,back:{}}}},"../../../test/fixtures/blocks/page-sidebar.json":{v:1,root:{type:`page`,id:`page`,title:{$:`/title`},subtitle:`with a sidebar`,sidebar:[{type:`tree`,nodes:{$:`/nav`}}],main:[{type:`markdown`,text:`board body`}]}},"../../../test/fixtures/blocks/page.json":{v:1,root:{type:`page`,title:`Jobs`,subtitle:`acme queue`,actions:[{id:`refresh`,label:`Refresh`,icon:`refresh`,action:{type:`edit`,name:`refresh`}}],main:[{type:`section`,title:`Active`,children:[{type:`markdown`,text:`acme jobs run **here**`},{type:`fields`,rows:[{label:`Queue`,value:`acme`},{label:`State`,value:`running`,tone:`info`}]}]}],detail:[{type:`diff`,before:`a`,after:`b`,lang:`ts`},{type:`details`,value:{kind:`acme`,count:3}}],empty:{icon:`check`,title:`All done`,hint:`no pending jobs`},id:`page`}},"../../../test/fixtures/blocks/section.json":{v:1,root:{type:`section`,title:`Group`,subtitle:`subtitle`,tone:`info`,collapsible:!0,collapsed:!1,children:[{type:`markdown`,text:`in section`},{type:`callout`,id:`section-callout`,tone:`warn`,title:`Careful`,body:`acme maintenance at 02:00`,actions:[{id:`ack`,label:`Acknowledge`,action:{type:`edit`,name:`ack`}}]}]}},"../../../test/fixtures/blocks/stack.json":{v:1,root:{type:`stack`,id:`stack`,gap:`m`,visibleAt:`atLeast:regular`,children:[{type:`markdown`,text:`stacked`},{type:`fields`,rows:[{label:`L`,value:1}]}]}},"../../../test/fixtures/blocks/stat-literal.json":{v:1,root:{type:`stat`,id:`stat-literal`,label:`Latency`,value:42,unit:`ms`,format:`number`,tone:`good`,icon:`clock`,size:`l`,caption:`p95 over 5m`,sparkline:[30,42,38,51,44]}},"../../../test/fixtures/blocks/stat.json":{v:1,root:{type:`stat`,id:`stat`,label:`Latency`,value:{$:`/latency`},unit:`ms`,format:`number`,tone:`good`,icon:`clock`,size:`l`,caption:`p95 over 5m`,sparkline:[30,42,38,51,44]}},"../../../test/fixtures/blocks/tree.json":{v:1,root:{type:`tree`,id:`tree`,nodes:{$:`/nodes`},onExpand:`expandNode`,onActivate:{type:`navigate`,params:{node:`acme`}}}}}),Zh=[{id:`card-1`,title:`acme provision`,state:`todo`,done:!1,eyebrow:`acme/queue`,subtitle:`spin the example.invalid runner`,body:`clone the repo, mount the volume`,badge:`queue`,when:`today`,user:`u1`,userName:`acme ops`,at:`2026-10-19T09:00:00Z`,score:3,quiet:!1,busy:!1,deps:[],tone:`info`,subtasks:[]},{id:`card-2`,title:`acme build`,done:!0,eyebrow:`acme/ci`,subtitle:`build the release`,body:`vite build && vitest`,badge:`ci`,when:`yesterday`,user:`acme-ops`,userName:`acme ops`,at:`2026-10-18T17:00:00Z`,score:9,state:`doing`,quiet:!0,busy:!1,deps:[`card-1`],tone:`good`,subtasks:[]},{id:`card-3`,title:`acme deploy`,done:!1,eyebrow:`acme/cd`,subtitle:`ship to example.invalid`,body:`helm upgrade`,badge:`cd`,when:`tomorrow`,user:`acme-cd`,userName:`acme deploy`,at:`2026-10-20T12:00:00Z`,score:5,state:`doing`,quiet:!1,busy:!0,deps:[`card-2`],tone:`warn`,subtasks:[{id:`card-3a`,title:`acme smoke`,done:!1,state:`todo`,subtasks:[]}]}];function Qh(e){let t={cards:Zh,title:`acme board`,nav:[{id:`n1`,label:`Board`,icon:`folder`,children:[{id:`n1a`,label:`Active`}]},{id:`n2`,label:`Archive`,hasChildren:!1}],filter:{state:`open`}};return e===`collection-calendar`?{...t,cards:[{id:`ev-1`,title:`acme sync`,start:`2026-10-19T10:00:00Z`,end:`2026-10-19T11:00:00Z`},{id:`ev-2`,title:`acme review`,start:`2026-10-21T14:00:00Z`,end:`2026-10-21T15:30:00Z`}]}:t}var $h=Object.keys(Xh).filter(e=>e.endsWith(`.json`)).map(e=>{let t=e.slice(e.lastIndexOf(`/`)+1,e.length-5),n=Xh[e];return t===`form-view`?{name:t,tree:{v:1,root:{type:`stack`,children:[n.root,{type:`markdown`,text:"filter.state = `{$}` bound to `/view/filter/state`:"},{type:`markdown`,text:{$:`/view/filter/state`}}]}},data:Qh(t)}:{name:t,tree:n,data:Qh(t)}}).sort((e,t)=>e.name.localeCompare(t.name));function eg(e){let t=1,n=new Set;return{load:async()=>({tree:e.tree,data:e.data,rev:t,treeRev:1,access:`write`}),fetchData:async()=>({rev:t,treeRev:1}),act:async()=>(t+=1,{ok:!0,rev:t}),upload:async()=>(t+=1,{ok:!0,rev:t}),image:async()=>new Uint8Array,onChanged:()=>()=>{n.clear()}}}function tg(e){let t=(0,v.useMemo)(()=>eg(e.sample),[e.sample]);return(0,R.jsxs)(`div`,{className:`gallery-sample`,"data-gallery-sample":e.sample.name,children:[(0,R.jsx)(`h2`,{children:e.sample.name}),(0,R.jsx)(Yh,{transport:t})]})}function ng(){return ig(globalThis.location?.hash??``)}function rg(){let[e,t]=(0,v.useState)(()=>ng());(0,v.useEffect)(()=>{let e=globalThis,n=()=>t(ng());return e.addEventListener?.(`hashchange`,n),()=>e.removeEventListener?.(`hashchange`,n)},[]);let n=e=>{t(e),globalThis.history?.pushState(null,``,`#/blocks/${e}`)},r=$h.find(t=>t.name===e);return(0,R.jsxs)(`div`,{className:`gallery`,"data-gallery":``,children:[(0,R.jsxs)(`aside`,{className:`gallery-list`,children:[(0,R.jsx)(`h1`,{children:`Blocks`}),(0,R.jsx)(`ul`,{children:$h.map(e=>(0,R.jsx)(`li`,{children:(0,R.jsx)(`button`,{type:`button`,"data-gallery-entry":e.name,onClick:()=>n(e.name),children:e.name})},e.name))})]}),(0,R.jsx)(`main`,{className:`gallery-main`,children:r===void 0?(0,R.jsx)(`p`,{className:`gallery-hint`,children:`Pick a block sample — every entry renders through the real renderer over an in-memory surface.`}):(0,R.jsx)(tg,{sample:r})})]})}function ig(e){let t=/^#\/blocks\/(.+)$/.exec(e);return t===null?null:decodeURIComponent(t[1]??``)}var ag=3e5;function og(){return globalThis.document?.visibilityState!==`hidden`}function sg(e){return(0,R.jsx)(`section`,{className:`ext-surface`,"data-ext-surface":`${e.slug}/${e.id}`,children:(0,R.jsx)(Yh,{transport:e.transport,refreshMs:e.refreshMs,keepaliveMs:ag,visible:og,onNavigate:e.onNavigate})})}function cg(e){return(0,R.jsx)(`section`,{className:`ext-panel`,"data-ext-panel":`${e.slug}/${e.id}`,children:(0,R.jsx)(Yh,{transport:e.transport,refreshMs:e.refreshMs,onNavigate:e.onNavigate})})}function lg(e){let t=ug(e);return e.params===void 0||Object.keys(e.params).length===0?t:fg(t,`params`,dg(e))}function ug(e){return`/v1/ext/${encodeURIComponent(e.slug)}/surfaces/${encodeURIComponent(e.id)}`}function dg(e){return encodeURIComponent(JSON.stringify(e.params??{}))}function fg(e,t,n){return`${e}${e.includes(`?`)?`&`:`?`}${t}=${n}`}function pg(e){let t=e.fetch??((e,t)=>globalThis.fetch(e,t)),n=new Set,r=()=>({accept:`application/json`,...e.streamId===void 0?{}:{"x-sigrun-stream":e.streamId}}),i=async e=>{let n=await t(e,{method:`GET`,headers:r()});if(!n.ok)throw Error(`ext surface GET ${e} failed with status ${n.status}`);return await n.json()};return{load(){return i(lg(e))},fetchData(t){let n=fg(`${ug(e)}/data`,`params`,dg(e));return i(t===void 0?n:fg(n,`since`,String(t)))},async act(n){return await(await t(`${ug(e)}/actions`,{method:`POST`,headers:{...r(),"content-type":`application/json`},body:JSON.stringify({...n,params:e.params??{}})})).json()},async upload(n){let i=fg(`${ug(e)}/uploads/${encodeURIComponent(n.field)}/${encodeURIComponent(n.name)}`,`params`,dg(e));return await(await t(i,{method:`PUT`,headers:{...r(),"content-type":`application/octet-stream`},body:n.bytes})).json()},image(){return Promise.reject(Error(`ext surface image route ships with U7`))},onChanged(e){return n.add(e),()=>{n.delete(e)}}}}var mg=class{#e=new Set;attach(e,t){let n=pg(e),r=this;return{load:()=>n.load(),fetchData:e=>n.fetchData(e),act:e=>n.act(e),upload:e=>n.upload(e),image:(e,t)=>n.image(e,t),onChanged(n){let i={slug:e.slug,id:e.id,keyHash:t,listener:n};return r.#e.add(i),()=>{r.#e.delete(i)}}}}dispatch(e){for(let t of this.#e)t.slug===e.slug&&t.id===e.id&&t.keyHash===e.k&&t.listener({rev:e.rev,treeRev:e.treeRev})}};function hg(e){return`/v1/conversations/${e.conversationId}/blocks/${encodeURIComponent(e.entryId)}`}function gg(e){let t=e.fetch??((e,t)=>globalThis.fetch(e,t)),n=new Set,r=()=>({accept:`application/json`}),i=async e=>{let n=await t(e,{method:`GET`,headers:r()});if(!n.ok)throw Error(`chat block GET ${e} failed with status ${n.status}`);return await n.json()};return{load(){return i(hg(e))},fetchData(t){let n=`${hg(e)}/data`;return i(t===void 0?n:`${n}?since=${String(t)}`)},async act(n){return await(await t(`${hg(e)}/actions`,{method:`POST`,headers:{...r(),"content-type":`application/json`},body:JSON.stringify(n)})).json()},upload(){return Promise.reject(Error(`chat blocks carry no upload fields`))},image(){return Promise.reject(Error(`chat block image route ships with U7`))},onChanged(e){return n.add(e),()=>{n.delete(e)}}}}var _g=class{#e=new Set;attach(e){let t=gg(e),n=this;return{load:()=>t.load(),fetchData:e=>t.fetchData(e),act:e=>t.act(e),upload:e=>t.upload(e),image:(e,n)=>t.image(e,n),onChanged(t){let r={conversationId:e.conversationId,entryId:e.entryId,listener:t};return n.#e.add(r),()=>{n.#e.delete(r)}}}}dispatch(e){for(let t of this.#e)t.conversationId===e.conversationId&&t.entryId===e.entryId&&t.listener({rev:e.rev,treeRev:e.treeRev??0})}},vg=`sigrun.railOrder`;function yg(e){return(e.coreViews??[]).map(e=>({slug:`core`,id:e.id,title:e.title,icon:e.icon,...e.refreshMs===void 0?{}:{refreshMs:e.refreshMs}}))}function bg(e){return`${e.slug}/${e.id}`}function xg(e){let t=[];for(let n of e)if(n.status===`ok`)for(let e of n.surfaces??[])e.placement===`view`&&t.push({slug:n.name,id:e.id,title:e.title,icon:e.icon,...e.refreshMs===void 0?{}:{refreshMs:e.refreshMs}});return t}function Sg(e){let t=[];for(let n of e)if(n.status===`ok`)for(let e of n.surfaces??[])e.placement===`panel`&&t.push({slug:n.name,id:e.id,title:e.title,icon:e.icon,...e.perConversation===!0?{perConversation:!0}:{}});return t}function Cg(){return globalThis.localStorage}function wg(){try{let e=Cg()?.getItem(vg);if(e==null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Tg(e){try{Cg()?.setItem(vg,JSON.stringify(e))}catch{}}function Eg(e,t){let n=new Map(e.map(e=>[bg(e),e])),r=[],i=new Set;for(let e of t){let t=n.get(e);t!==void 0&&!i.has(e)&&(r.push(t),i.add(e))}for(let t of e)i.has(bg(t))||r.push(t);return r}function Dg(e,t,n){let r=e.map(e=>bg(e)),i=r.indexOf(t);if(i===-1)return r;let a=i+n;if(a<0||a>=r.length)return r;let o=[...r];return o[i]=r[a]??``,o[a]=t,Tg(o),o}function Og(e,t){return`ext:${e}/${t}`}var kg=`sigrun.panel`;function Ag(){return globalThis.localStorage}function jg(e){if(e===null)return null;if(e===`outline`||e===`workspace`)return e;if(e.startsWith(`ext:`)){let t=e.slice(4).split(`/`);return t.length===2&&t[0]!==``&&t[1]!==``?e:null}return null}function Mg(e,t){return e===t?null:t}function Ng(e,t){if(e===null||!e.startsWith(`ext:`))return e;let n=e.slice(4);return t.some(e=>bg(e)===n)?e:null}function Pg(){try{return jg(Ag()?.getItem(`sigrun.panel`)??null)}catch{return null}}function Fg(e){if(e!==`notices`)try{Ag()?.setItem(kg,e??`none`)}catch{}}function Ig(e){let{title:t,timeline:n,onTimeline:r,panel:i,onPanel:a,onRename:o,onExport:s,onCompact:c,onArchive:l,archived:u=!1,drawerOpen:d,onToggleDrawer:f}=e,[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(t),[_,y]=(0,v.useState)(!1),b=(0,v.useRef)(null);Em(_,()=>y(!1),b);let x=()=>{g(t),m(!0),y(!1)},S=()=>m(!1),C=()=>{let e=h.trim();if(e===``||e===t){m(!1);return}o(e).then(()=>m(!1),()=>m(!1))},w=e=>()=>{y(!1),e()};return(0,R.jsxs)(`header`,{className:`chat-header`,children:[(0,R.jsx)(`button`,{type:`button`,className:`icon-btn chat-menu-toggle`,title:`Conversations`,"aria-label":`open conversations`,"aria-expanded":d,onClick:f,children:(0,R.jsx)(_m,{})}),p?(0,R.jsx)(`input`,{className:`chat-title-input`,value:h,"aria-label":`conversation name`,autoFocus:!0,onChange:e=>g(e.target.value),onBlur:C,onKeyDown:e=>{e.key===`Enter`?C():e.key===`Escape`&&S()}}):(0,R.jsx)(`button`,{type:`button`,className:`chat-title`,title:t,onClick:x,children:t}),(0,R.jsx)(`span`,{className:`chat-header-spacer`}),(0,R.jsx)(`span`,{className:`chat-header-bell`,children:e.bell}),(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":`timeline`,title:`Chronological view — interleave thinking and tool calls in order instead of folding them under the response`,"aria-label":`chronological view`,"aria-pressed":n,onClick:r,children:`⇅`}),(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":`outline`,title:`Outline`,"aria-label":`outline`,"aria-pressed":i===`outline`,onClick:()=>a(`outline`),children:(0,R.jsx)(vm,{})}),(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":`workspace`,title:`Workspace files`,"aria-label":`workspace`,"aria-pressed":i===`workspace`,onClick:()=>a(`workspace`),children:(0,R.jsx)(ym,{})}),e.extPanels.map(e=>{let t=Og(e.slug,e.id);return(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":t,title:e.title,"aria-label":e.title,"aria-pressed":i===t,onClick:()=>a(t),children:(0,R.jsx)(gd,{name:e.icon,size:16})},t)}),(0,R.jsxs)(`span`,{className:`chat-menu-slot`,ref:b,children:[(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,title:`More (export, compact, rename, archive)`,"aria-label":`more actions`,"aria-haspopup":`menu`,"aria-expanded":_,onClick:()=>y(e=>!e),children:(0,R.jsx)(xm,{})}),_&&(0,R.jsxs)(`div`,{className:`chat-menu`,role:`menu`,children:[(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`export`,onClick:w(s),children:`Export`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`compact`,onClick:w(c),children:`Compact`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`rename`,onClick:w(x),children:`Rename`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`archive`,onClick:w(l),children:u?`Unarchive`:`Archive`})]})]})]})}function Lg(e){return e===`skills`||e===`jobs`?e:null}function Rg(e){return(0,R.jsxs)(`button`,{type:`button`,className:e.active?`bottom-bar-btn bottom-bar-btn-active`:`bottom-bar-btn`,"data-tab":e.tab,"aria-label":e.title.toLowerCase(),...e.active?{"aria-current":`page`}:{},onClick:t=>{t.preventDefault(),!(e.active&&e.tab!==`more`)&&e.onPress()},children:[e.children,(0,R.jsx)(`span`,{className:`bottom-bar-label`,children:e.title})]})}function zg(e){let[t,n]=(0,v.useState)(!1),r=new Map,i=[];for(let t of e.extViews)t.slug===`core`&&Lg(t.id)!==null?r.set(t.id,t):i.push(t);let a=e.active===`settings`||e.active.startsWith(`ext:`),o=t=>()=>{n(!1),e.onTab(t)};return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`nav`,{className:`bottom-bar`,"aria-label":`sections`,children:[(0,R.jsx)(Rg,{tab:`chats`,title:`Chats`,active:e.active===`chats`,onPress:()=>e.onTab(`chats`),children:(0,R.jsx)(mm,{})}),[`skills`,`jobs`].map(t=>{let n=r.get(t);return n===void 0?null:(0,R.jsx)(Rg,{tab:t,title:n.title,active:e.active===t,onPress:()=>e.onTab(t),children:(0,R.jsx)(gd,{name:n.icon,size:18})},t)}),(0,R.jsx)(Rg,{tab:`more`,title:`More`,active:a,onPress:()=>n(e=>!e),children:(0,R.jsx)(xm,{})})]}),t&&(0,R.jsx)(`div`,{className:`bottom-sheet-backdrop`,onClick:()=>n(!1),children:(0,R.jsxs)(`div`,{className:`bottom-sheet`,role:`dialog`,"aria-label":`More views`,onClick:e=>e.stopPropagation(),children:[i.map(e=>{let t=`ext:${e.slug}/${e.id}`;return(0,R.jsxs)(`button`,{type:`button`,className:`bottom-sheet-item`,"aria-label":e.title.toLowerCase(),onClick:o(t),children:[(0,R.jsx)(gd,{name:e.icon,size:18}),(0,R.jsx)(`span`,{children:e.title})]},`${e.slug}/${e.id}`)}),(0,R.jsxs)(`button`,{type:`button`,className:`bottom-sheet-item`,"aria-label":`settings`,onClick:o(`settings`),children:[(0,R.jsx)(gm,{}),(0,R.jsx)(`span`,{children:`Settings`})]}),e.onSignOut!==void 0&&(0,R.jsxs)(`button`,{type:`button`,className:`bottom-sheet-item`,"aria-label":`sign out`,onClick:()=>{n(!1),e.onSignOut?.()},children:[(0,R.jsx)(Cm,{}),(0,R.jsx)(`span`,{children:`Sign out`})]})]})})]})}function Bg(e){let t=e.extensions.every(e=>e.status===`ok`),n=e.health.memory===`ok`&&e.health.providers===`ok`&&e.health.backup!==`degraded`;return t&&n?`ok`:`degraded`}function Vg(e){return`${e.extensions.length===0?`extensions: none`:`extensions: ${e.extensions.map(e=>`${e.name}: ${e.status}`).join(`; `)}`} · backup: ${e.health.backup}`}function Hg(e){return(0,R.jsx)(`button`,{type:`button`,className:e.active?`rail-btn rail-btn-active`:`rail-btn`,"data-rail-section":e.tab,title:e.title,"aria-label":e.title.toLowerCase(),...e.active?{"aria-current":`page`}:{},onClick:()=>{e.active||e.onOpenTab?.(e.tab)},...e.onKeyDown===void 0?{}:{onKeyDown:e.onKeyDown},children:e.children})}function Ug(e){let{meta:t,identity:n,onLogout:r}=e,{onOpenGallery:i}=e,a=n?.method===`token`||n?.method===`session`,o=e.activeTab===void 0?`chats`:e.activeTab,s=new Set(e.hiddenExtSurfaces??[]),c=(e.extViewEntries??Eg(xg(t.extensions),wg())).filter(e=>!s.has(`${e.slug}/${e.id}`)),l=yg(t);return(0,R.jsxs)(`nav`,{className:`rail`,"aria-label":`sections`,children:[e.bell,(0,R.jsx)(`span`,{className:`rail-brand`,title:`sigrun`,children:(0,R.jsx)(pm,{})}),(0,R.jsx)(Hg,{tab:`chats`,title:`Chats`,active:o===`chats`,onOpenTab:e.onOpenTab,children:(0,R.jsx)(mm,{})}),t.dev&&i!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`rail-btn`,"data-rail-section":`blocks`,title:`Blocks`,"aria-label":`blocks gallery`,onClick:i,children:(0,R.jsx)(hm,{})}),l.map(t=>{let n=`ext:core/${t.id}`;return(0,R.jsx)(Hg,{tab:t.id===`skills`||t.id===`jobs`?t.id:n,title:t.title,active:o===(t.id===`skills`||t.id===`jobs`?t.id:n),onOpenTab:e.onOpenTab,children:(0,R.jsx)(gd,{name:t.icon,size:18})},`core/${t.id}`)}),c.map(t=>{let n=`ext:${t.slug}/${t.id}`,r=o===n;return(0,R.jsx)(Hg,{tab:n,title:t.title,active:r,onOpenTab:e.onOpenTab,onKeyDown:n=>{n.altKey&&(n.key===`ArrowUp`?(n.preventDefault(),e.onMoveExtView?.(`${t.slug}/${t.id}`,-1)):n.key===`ArrowDown`&&(n.preventDefault(),e.onMoveExtView?.(`${t.slug}/${t.id}`,1)))},children:(0,R.jsx)(gd,{name:t.icon,size:18})},`${t.slug}/${t.id}`)}),(0,R.jsx)(`span`,{className:`rail-spacer`}),(0,R.jsx)(`span`,{className:`rail-health`,"data-health":Bg(t),title:Vg(t)}),a&&(0,R.jsx)(`span`,{className:`rail-user`,"data-rail-user":n.user??``,title:n.user===void 0?`signed in`:`signed in as ${n.user}`,children:n.user??`—`}),a&&r!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`rail-btn`,"data-rail-section":`logout`,title:`Sign out`,"aria-label":`sign out`,onClick:r,children:(0,R.jsx)(Cm,{})}),(0,R.jsx)(Hg,{tab:`settings`,title:`Settings`,active:o===`settings`,onOpenTab:e.onOpenTab,children:(0,R.jsx)(gm,{})})]})}function Wg(e){let{selection:t,outline:n,workspace:r,notices:i,extContent:a}=e;if(t===null)return null;let o=t.startsWith(`ext:`);return(0,R.jsx)(`aside`,{className:`right-panel`,"data-panel":o?`ext`:t,"aria-label":`${o?`extension`:t} panel`,children:o?a??null:t===`outline`?n:t===`notices`?i:r})}var Gg=`sigrun.tabs`;function Kg(e){return e.kind===`chat`?`chats`:e.kind===`settings`?`settings`:e.slug===`core`&&e.id===`skills`?`skills`:e.slug===`core`&&e.id===`jobs`?`jobs`:`ext:${e.slug??``}/${e.id??``}`}function qg(e){if(e===`chats`)return`#/c`;if(e===`skills`)return`#/ext/core/skills`;if(e===`jobs`)return`#/ext/core/jobs`;if(e===`settings`)return`#/settings`;let t=/^ext:([^/]+)\/(.+)$/.exec(e);return t===null?`#/c`:`#/ext/${encodeURIComponent(t[1]??``)}/${encodeURIComponent(t[2]??``)}`}function Jg(){return globalThis.sessionStorage}var Yg=class{#e;constructor(){this.#e=new Map;try{let e=Jg()?.getItem(Gg);if(e==null)return;let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))return;for(let[e,n]of Object.entries(t))typeof n==`string`&&this.#e.set(e,n)}catch{}}remember(e,t){this.#e.set(e,t);try{Jg()?.setItem(Gg,JSON.stringify(Object.fromEntries(this.#e)))}catch{}}routeFor(e){return this.#e.get(e)??qg(e)}};function Xg(e){let t=null,n=1/0;for(let[r,i]of e)i.isIntersecting&&i.top<n&&(n=i.top,t=r);return t}function Zg(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Qg(e){let{scrollRoot:t,turns:n}=e,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(()=>new Set),s=(0,v.useRef)(null),c=n.map(e=>e.entryId).join(`,`);return(0,v.useEffect)(()=>{i(null)},[t,c]),(0,v.useEffect)(()=>{if(t===null)return;let e=globalThis.IntersectionObserver;if(e===void 0)return;let r=new Map,a=new e(e=>{for(let t of e){let e=t.target,n=Number(e.getAttribute(`data-entry-id`));Number.isFinite(n)&&r.set(n,{isIntersecting:t.isIntersecting,top:e.getBoundingClientRect().top})}i(Xg(r))});for(let e of n){let n=t.querySelector(`[data-entry-id="${e.entryId}"]`);n!==null&&a.observe(n)}return()=>{a.disconnect()}},[t,c]),(0,v.useLayoutEffect)(()=>{let e=s.current;if(e===null)return;let t=()=>{let t=new Set;for(let n of e.querySelectorAll(`.outline-text`)){if(n.scrollHeight<=n.clientHeight+1)continue;let e=n.closest(`.outline-item`),r=Number(e?.getAttribute(`data-entry-id`));Number.isFinite(r)&&t.add(r)}o(e=>Zg(e,t)?e:t)};t();let n=globalThis.ResizeObserver;if(n===void 0)return;let r=new n(t);return r.observe(e),()=>{r.disconnect()}},[t,c]),n.length===0?(0,R.jsxs)(`div`,{className:`right-panel-body outline-body`,children:[(0,R.jsx)(`h4`,{className:`right-panel-title`,children:`Outline`}),(0,R.jsx)(`p`,{className:`outline-empty`,children:`No prompts yet`})]}):(0,R.jsxs)(`div`,{className:`right-panel-body outline-body`,children:[(0,R.jsx)(`h4`,{className:`right-panel-title`,children:`Outline`}),(0,R.jsx)(`nav`,{className:`outline`,"aria-label":`conversation outline`,ref:s,children:n.map(e=>(0,R.jsx)(`button`,{type:`button`,className:`outline-item`,"data-entry-id":e.entryId,"data-clamped":a.has(e.entryId)?`true`:void 0,title:e.text,"aria-current":r===e.entryId?`true`:void 0,onClick:()=>{t?.querySelector(`[data-entry-id="${e.entryId}"]`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:(0,R.jsx)(`span`,{className:`outline-text`,children:e.text})},e.entryId))})]})}var $g=`79bdfd95541951f9db86236ee2a2f81cce481a5d8688090837a2bdde83d52c97`,e_=`sigrun-session-search`,t_=[`Pinned`,`Today`,`Yesterday`,`Earlier`];function n_(){(globalThis.document?.getElementById(e_))?.focus()}function r_(e,t){let n=new Set,r=new Map(e.map(e=>[e.id,e]));for(let i of e){if(!oe(i).toLowerCase().includes(t))continue;let e=i;for(;e!==void 0&&!n.has(e.id);)n.add(e.id),e=e.parent===void 0?void 0:r.get(e.parent.id)}return n}function i_(e,t){let n=[];for(let r of t_){let i=e.filter(e=>te(e,t)===r);if(i.length===0)continue;n.push({kind:`heading`,group:r});let a=(e,t)=>{n.push({kind:`row`,node:e,depth:t});for(let n of e.children)a(n,t+1)};for(let e of i)a(e,0)}return n}function a_(e){let{rows:t,activeId:n,onSelect:r,onNew:i,onRename:a,onArchive:o,onFork:s,currentUser:c,onShare:l}=e,[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(null),g=(0,v.useRef)(null);Em(m!==null,()=>h(null),g);let[_,y]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=globalThis.window;if(e===void 0)return;let t=e=>{(e.ctrlKey||e.metaKey)&&(e.key===`k`||e.key===`K`)&&(e.preventDefault(),n_())};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[]);let b=new Date,x=(0,v.useMemo)(()=>{let e=u.trim().toLowerCase(),n=r_(t,e);return i_(D(e===``?t:t.filter(e=>n.has(e.id)),{includeArchived:f}),b)},[t,u,f,b.getTime()]),S=e=>{if(_===null||_.id!==e)return;let n=t.find(t=>t.id===e),r=_.draft.trim();if(n===void 0||r===``||r===oe(n)){y(null);return}a(e,r).then(()=>y(null),()=>y(null))};return(0,R.jsxs)(`nav`,{className:`session-list`,"aria-label":`conversations`,children:[(0,R.jsxs)(`div`,{className:`session-search-row`,children:[(0,R.jsx)(`input`,{id:e_,className:`session-search`,type:`search`,placeholder:`Search`,"aria-label":`search conversations`,value:u,onChange:e=>d(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`session-new`,title:`New conversation`,"aria-label":`new conversation`,onClick:i,children:(0,R.jsx)(bm,{})})]}),(0,R.jsxs)(`ul`,{children:[x.map(e=>{if(e.kind===`heading`)return(0,R.jsx)(`li`,{className:`session-group`,"data-age-group":e.group,children:e.group},`group-${e.group}`);let{node:t,depth:i}=e,a=t.row,u=oe(a),d=_!==null&&_.id===a.id,f=l!==void 0&&c!==void 0&&a.owner===c,p=[`session-item`,a.id===n?`session-item-active`:``,a.archived?`session-item-archived`:``].filter(Boolean).join(` `);return(0,R.jsxs)(`li`,{className:p,"data-conversation-id":a.id,"data-depth":i,style:i===0?void 0:{paddingLeft:6+i*14},children:[i>0&&(0,R.jsx)(`span`,{className:`session-fork-mark`,"aria-hidden":`true`,children:`↳`}),d?(0,R.jsx)(`input`,{className:`session-rename-input`,"aria-label":`conversation name`,value:_.draft,onChange:e=>y({id:a.id,draft:e.target.value}),onKeyDown:e=>{e.key===`Enter`?S(a.id):e.key===`Escape`&&y(null)}}):(0,R.jsx)(`button`,{type:`button`,className:`session-select`,title:u,onClick:()=>r(a.id),children:(0,R.jsx)(`span`,{className:`session-name`,children:u})}),(0,R.jsx)(`span`,{className:`session-age`,children:ae(a.lastActivityAt,b)}),(0,R.jsxs)(`span`,{className:`session-row-actions`,ref:m===a.id?g:void 0,children:[(0,R.jsx)(`button`,{type:`button`,className:`session-menu-toggle`,"aria-label":`actions for ${u}`,"aria-haspopup":`menu`,"aria-expanded":m===a.id,onClick:()=>h(m===a.id?null:a.id),children:(0,R.jsx)(xm,{})}),m===a.id&&(0,R.jsxs)(`div`,{className:`session-menu`,role:`menu`,children:[f&&(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`share`,onClick:()=>{h(null),l?.(a.id)},children:`Share…`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`rename`,onClick:()=>{h(null),y({id:a.id,draft:u})},children:`Rename`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`fork`,onClick:()=>{h(null),s(a.id)},children:`Fork`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`archive`,onClick:()=>{h(null),o(a.id,!a.archived)},children:a.archived?`Unarchive`:`Archive`})]})]})]},a.id)}),x.length===0&&u.trim()!==``&&(0,R.jsx)(`li`,{className:`session-empty`,children:`No matching conversations`})]}),(0,R.jsx)(`button`,{type:`button`,className:`session-archived-toggle`,"aria-pressed":f,title:`Show archived conversations`,onClick:()=>p(e=>!e),children:`Archived`})]})}function o_(e){if(e instanceof x){let t={proxy_identity_required:`This sigrun signs people in through its sign-in proxy. Open it through the proxy.`,username_taken:`That username is taken. Choose another.`,invalid_username:`That name has no usable characters — use at least one letter or digit.`},n=e.error??``;if(Object.hasOwn(t,n))return t[n];if(e.error!==void 0)return e.error}return e instanceof Error?e.message:String(e)}function s_(e){return e.split(/[\s,]+/).map(e=>e.trim()).filter(e=>e!==``)}function c_(e){let{client:t,conversation:n,onClose:r,onSaved:i}=e,a=n.sharing,[o,s]=(0,v.useState)(a?.scope??`private`),[c,l]=(0,v.useState)(a?.scope===`household`||a?.scope===`people`?a.level:`read`),[u,d]=(0,v.useState)(a?.scope===`people`?a.users.join(`, `):``),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1);async function g(e){h(!0),p(null);try{await t.patchConversationMeta(n.id,{sharing:e}),await i()}catch(e){p(o_(e))}finally{h(!1)}}function _(e){m||(s(e),e===`private`?g({scope:`private`}):e===`household`&&g({scope:`household`,level:c}))}function y(e){m||(l(e),o===`household`&&g({scope:`household`,level:e}))}function b(){if(m)return;let e=s_(u);if(e.length===0){p(`enter at least one username to share with`);return}g({scope:`people`,users:e,...a?.scope===`people`&&a.groups!==void 0?{groups:[...a.groups]}:{},level:c})}return(0,R.jsxs)(`div`,{className:`share-menu`,role:`dialog`,"aria-label":`share conversation`,children:[(0,R.jsxs)(`div`,{className:`share-head`,children:[(0,R.jsx)(`h2`,{children:`Share`}),(0,R.jsx)(`button`,{type:`button`,className:`share-close`,"aria-label":`close share dialog`,onClick:r,children:`Close`})]}),(0,R.jsxs)(`div`,{className:`share-scopes`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`share-scope`,"data-share-scope":`private`,"data-selected":o===`private`||void 0,"aria-pressed":o===`private`,disabled:m,onClick:()=>_(`private`),children:[`Private`,(0,R.jsx)(`span`,{className:`share-scope-hint`,children:`only you`})]}),(0,R.jsxs)(`button`,{type:`button`,className:`share-scope`,"data-share-scope":`household`,"data-selected":o===`household`||void 0,"aria-pressed":o===`household`,disabled:m,onClick:()=>_(`household`),children:[`Household`,(0,R.jsx)(`span`,{className:`share-scope-hint`,children:`everyone signed in`})]}),(0,R.jsxs)(`button`,{type:`button`,className:`share-scope`,"data-share-scope":`people`,"data-selected":o===`people`||void 0,"aria-pressed":o===`people`,disabled:m,onClick:()=>_(`people`),children:[`People`,(0,R.jsx)(`span`,{className:`share-scope-hint`,children:`named users`})]})]}),o!==`private`&&(0,R.jsxs)(`div`,{className:`share-level`,role:`group`,"aria-label":`access level`,children:[(0,R.jsx)(`button`,{type:`button`,className:`share-level-btn`,"data-share-level":`read`,"data-selected":c===`read`||void 0,"aria-pressed":c===`read`,disabled:m,onClick:()=>y(`read`),children:`Can view`}),(0,R.jsx)(`button`,{type:`button`,className:`share-level-btn`,"data-share-level":`write`,"data-selected":c===`write`||void 0,"aria-pressed":c===`write`,disabled:m,onClick:()=>y(`write`),children:`Can edit`})]}),o===`people`&&(0,R.jsxs)(`label`,{className:`share-field`,children:[`Usernames`,(0,R.jsx)(`input`,{"data-share-field":`users`,placeholder:`carol, dave`,value:u,onChange:e=>d(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:m,onClick:b,children:`Share with people`})]}),o!==`private`&&c===`write`&&(0,R.jsx)(`p`,{className:`share-warning`,role:`alert`,children:`Others can ask the agent to act as you.`}),f!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:f})]})}var l_=5e3,u_=2,d_=5e3,f_=6e4;function p_(e,t,n,r,i,a){if(i===void 0&&globalThis.EventSource===void 0)return()=>{};let o=()=>i===void 0?new EventSource(`/v1/events`):i(`/v1/events`),s,c,l=d_,u=!1,d=()=>{let e=o();s=e,f(e),e.addEventListener(`hello`,()=>{l=d_}),e.addEventListener(`error`,()=>{u||e.readyState!==u_||c===void 0&&s===e&&(e.close(),c=setTimeout(()=>{c=void 0,u||d()},l),l=Math.min(l*2,f_))})};return d(),()=>{u=!0,c!==void 0&&clearTimeout(c),s?.close()};function f(i){let o=()=>e();i.addEventListener(`conversation.created`,o),i.addEventListener(`conversation.changed`,o),i.addEventListener(`surface.changed`,e=>{try{let t=JSON.parse(e.data);if(typeof t==`object`&&t&&typeof t.conversationId==`number`&&typeof t.entryId==`string`&&typeof t.rev==`number`){r?.(t);return}}catch{}if(n!==void 0)try{let t=JSON.parse(e.data);typeof t==`object`&&t&&typeof t.slug==`string`&&typeof t.id==`string`&&typeof t.k==`string`&&typeof t.rev==`number`&&typeof t.treeRev==`number`&&n(t)}catch{}}),a!==void 0&&i.addEventListener(`notice.changed`,()=>a()),i.addEventListener(`hello`,e=>{try{let n=JSON.parse(e.data);typeof n==`object`&&n&&typeof n.streamId==`string`&&t(n.streamId)}catch{}})}}function m_(e,t){let n=t.busy,[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(void 0),l=(0,v.useRef)(void 0),u=(0,v.useRef)(new Set),d=(0,v.useCallback)(async()=>{try{let t=await e.listConversations();i(t.conversations),o(null)}catch(e){o(e instanceof Error?e.message:String(e))}},[e]),f=(0,v.useCallback)(async(e,n,r)=>{let i=l.current;return(await(t.fetchImpl??fetch)(r===void 0||Object.keys(r).length===0?`/v1/ext/${e}/surfaces/${n}`:`/v1/ext/${e}/surfaces/${n}?params=${encodeURIComponent(JSON.stringify(r))}`,{headers:i===void 0?{accept:`application/json`}:{accept:`application/json`,"x-sigrun-stream":i}})).json()},[t.fetchImpl]),p=(0,v.useCallback)((e,t,n)=>{let r=n===void 0?`{}`:Ee(n);u.current.add(`${e}\u0001${t}\u0001${r}`)},[]),m=(0,v.useCallback)(e=>{let t=l.current;if(l.current=e,c(e),t!==void 0&&t!==e){d();for(let e of u.current){let[t,n,r]=e.split(``),i;if(r!==void 0&&r!==`{}`)try{let e=JSON.parse(r);typeof e==`object`&&e&&!Array.isArray(e)&&(i=e)}catch{}f(t??``,n??``,i)}}},[f,d]);(0,v.useEffect)(()=>{d()},[d]),(0,v.useEffect)(()=>{let e=globalThis.document;if(e?.addEventListener===void 0)return;let t=()=>{e.visibilityState===`visible`&&d()};return e.addEventListener(`visibilitychange`,t),()=>e.removeEventListener?.(`visibilitychange`,t)},[d]),(0,v.useEffect)(()=>p_(()=>{d()},m,t.onSurfaceChanged,t.onChatChanged,t.createEventSource,t.onNoticeChanged),[d,m,t.createEventSource,t.onSurfaceChanged,t.onChatChanged,t.onNoticeChanged]);let h=(0,v.useRef)(n);return(0,v.useEffect)(()=>{let e=h.current;if(h.current=n,!e||n)return;d();let t=setTimeout(()=>void d(),l_);return()=>clearTimeout(t)},[n,d]),{rows:r,reload:d,error:a,streamId:s,fetchSurface:f,noteSurfaceVisible:p}}var h_={fjord:{label:`Fjord`,defaultAccent:`baltic-amber`,dark:{bg:`#0b0f13`,surface:`#11171e`,surface2:`#18202a`,border:`#222d39`,text:`#dde6ee`,muted:`#8d9cab`,faint:`#5f6e7d`,ok:`#7fbf9a`,code:`rgba(255,255,255,.06)`},light:{bg:`#eef2f5`,surface:`#ffffff`,surface2:`#e3e9ef`,border:`#d3dbe3`,text:`#18212a`,muted:`#4d5b69`,faint:`#8593a1`,ok:`#2f8a5a`,code:`rgba(0,0,0,.05)`}},"iron-ember":{label:`Iron & Ember`,defaultAccent:`ember`,dark:{bg:`#0e0e0f`,surface:`#161618`,surface2:`#1e1e21`,border:`#2a2a2e`,text:`#e6e1da`,muted:`#9a958e`,faint:`#66625d`,ok:`#8fb58a`,code:`rgba(255,255,255,.06)`},light:{bg:`#f3f1ee`,surface:`#fbfaf8`,surface2:`#e9e6e1`,border:`#dbd7d1`,text:`#1c1b1a`,muted:`#55524d`,faint:`#8e8a84`,ok:`#3e7a3a`,code:`rgba(0,0,0,.05)`}},"polar-night":{label:`Polar Night`,defaultAccent:`aurora`,dark:{bg:`#090d16`,surface:`#0f1524`,surface2:`#161e31`,border:`#1f2942`,text:`#e2e8f3`,muted:`#8e9ab2`,faint:`#5d6984`,ok:`#5fd4a8`,code:`rgba(255,255,255,.06)`},light:{bg:`#f0f3f9`,surface:`#ffffff`,surface2:`#e4e9f3`,border:`#d2d9e6`,text:`#141b2b`,muted:`#4b5670`,faint:`#8691a8`,ok:`#13866a`,code:`rgba(0,0,0,.05)`}},"birch-moss":{label:`Birch & Moss`,defaultAccent:`lichen`,dark:{bg:`#0d100d`,surface:`#141a15`,surface2:`#1b221c`,border:`#263027`,text:`#e8e6dc`,muted:`#9ba091`,faint:`#666d60`,ok:`#9cc48a`,code:`rgba(255,255,255,.06)`},light:{bg:`#f3f2ea`,surface:`#fbfbf6`,surface2:`#e7e7dc`,border:`#d8d8ca`,text:`#1b1e18`,muted:`#525849`,faint:`#8b9080`,ok:`#4a7a35`,code:`rgba(0,0,0,.05)`}}},g_={"baltic-amber":{label:`Baltic Amber`,dark:`#d6a24a`,light:`#a8741f`},ember:{label:`Ember`,dark:`#d9773a`,light:`#b8571c`},lingonberry:{label:`Lingonberry`,dark:`#d0606a`,light:`#a83440`},glacier:{label:`Glacier`,dark:`#8fb8d0`,light:`#2f6f93`},aurora:{label:`Aurora`,dark:`#5fd4a8`,light:`#13866a`},lichen:{label:`Lichen`,dark:`#b9c46a`,light:`#6f7a1f`},heather:{label:`Heather`,dark:`#a993c9`,light:`#6c4f99`}},__=[`fjord`,`iron-ember`,`polar-night`,`birch-moss`],v_=[`baltic-amber`,`ember`,`lingonberry`,`glacier`,`aurora`,`lichen`,`heather`],y_=`polar-night`,b_=`baltic-amber`;function x_(e){return typeof e==`string`&&Object.prototype.hasOwnProperty.call(h_,e)}function S_(e){return typeof e==`string`&&Object.prototype.hasOwnProperty.call(g_,e)}function C_(e){let{client:t}=e,[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1;return Promise.all([t.accounts(),t.providers()]).then(([t,n])=>{e||(r(t.accounts),a(n.providers))}).catch(t=>{e||s(o_(t))}),()=>{e=!0}},[t]);async function u(e){l(`${e.provider}\u0000${e.subject}`),s(null);try{await t.removeAccount(e.provider,e.subject),r(t=>t?.filter(t=>t.provider!==e.provider||t.subject!==e.subject)??null)}catch(e){s(o_(e))}finally{l(null)}}return n===null?(0,R.jsx)(`p`,{className:`settings-note`,role:o===null?void 0:`alert`,children:o??`loading account links…`}):(0,R.jsxs)(`div`,{className:`settings-body`,"data-settings-section":`accounts`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`External identities linked to your sigrun account.`}),o!==null&&(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:o}),n.length===0&&(0,R.jsx)(`p`,{className:`settings-note`,children:`No account links.`}),n.map(e=>(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsxs)(`span`,{className:`settings-ext-key`,children:[i.find(t=>t.provider===e.provider)?.label??e.provider,` · `,e.subject]}),(0,R.jsx)(`button`,{type:`button`,className:`account-remove`,disabled:c!==null,onClick:()=>void u(e),children:`Remove`})]},`${e.provider}\u0000${e.subject}`)),i.length>0&&(0,R.jsxs)(`div`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Connect an account`}),i.map(e=>(0,R.jsx)(`a`,{className:`account-connect`,href:`/v1/auth/login/${encodeURIComponent(e.provider)}?link=1&return=%2Fsettings%3Fsection%3Daccounts`,children:`Connect`},e.provider))]})]})}function w_(e){let{client:t}=e,[n,r]=(0,v.useState)({status:`loading`}),[i,a]=(0,v.useState)({});(0,v.useEffect)(()=>{let e=!1;return t.listProviders().then(t=>{e||r({status:`ready`,providers:t.providers})}).catch(t=>{e||r({status:`error`,message:t instanceof Error?t.message:String(t)})}),()=>{e=!0}},[t]);let o=e=>{r(t=>t.status===`ready`?{status:`ready`,providers:t.providers.map(t=>t.provider===e.provider?e:t)}:t)},s=(e,t)=>{a(n=>({...n,[e]:{key:``,...n[e],...t}}))},c=async e=>{let n=i[e];if(n!==void 0&&n.key!==``)try{o(await t.putProviderCredential(e,n.key)),s(e,{key:``,note:{kind:`ok`,message:`saved`}})}catch(t){s(e,{note:{kind:`error`,message:t instanceof Error?t.message:String(t)}})}},l=async e=>{try{o(await t.deleteProviderCredential(e)),s(e,{note:{kind:`ok`,message:`cleared`}})}catch(t){s(e,{note:{kind:`error`,message:t instanceof Error?t.message:String(t)}})}},u=async e=>{try{o(await t.refreshProvider(e))}catch(t){s(e,{note:{kind:`error`,message:t instanceof Error?t.message:String(t)}})}};return n.status===`loading`?(0,R.jsx)(`p`,{className:`settings-note`,children:`loading providers…`}):n.status===`error`?(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:n.message}):n.providers.length===0?(0,R.jsx)(`div`,{className:`settings-body`,children:(0,R.jsx)(`p`,{className:`settings-note`,children:`no providers are loaded`})}):(0,R.jsxs)(`div`,{className:`settings-body settings-provider-list`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`readiness and credentials per provider — the key field is write-only (the server never returns it); saving applies immediately, no restart`}),n.providers.map(e=>{let t=i[e.provider]??{key:``};return(0,R.jsxs)(`fieldset`,{className:`settings-provider`,"data-provider":e.provider,children:[(0,R.jsxs)(`legend`,{className:`settings-provider-name`,children:[e.provider,(0,R.jsx)(`span`,{className:`settings-provider-status`,"data-status":e.status,children:e.status}),(0,R.jsxs)(`span`,{className:`settings-provider-meta`,children:[e.models,` model`,e.models===1?``:`s`]})]}),e.detail!==void 0&&(0,R.jsx)(`p`,{className:`settings-note`,children:e.detail}),(0,R.jsxs)(`div`,{className:`settings-provider-row`,children:[(0,R.jsx)(`input`,{type:`password`,className:`settings-provider-key`,placeholder:`api key`,value:t.key,autoComplete:`off`,onChange:t=>s(e.provider,{key:t.target.value})}),(0,R.jsx)(`button`,{type:`button`,className:`settings-provider-save`,disabled:t.key===``,onClick:()=>void c(e.provider),children:`Save`}),(0,R.jsx)(`button`,{type:`button`,className:`settings-provider-clear`,onClick:()=>void l(e.provider),children:`Clear`}),(0,R.jsx)(`button`,{type:`button`,className:`settings-provider-refresh`,onClick:()=>void u(e.provider),children:`Refresh`}),t.note!==void 0&&(0,R.jsx)(`span`,{className:`settings-note`,role:t.note.kind===`ok`?`status`:`alert`,children:t.note.message})]})]},e.provider)})]})}var T_=/\p{M}/gu,E_=/@/g,D_=/[^a-z0-9._-]/g,O_=/^[^a-z0-9]+/;function k_(e){let t=e.normalize(`NFKD`).replace(T_,``).toLowerCase().replace(E_,`_`).replace(D_,`-`).replace(O_,``).slice(0,128);return t===``?void 0:t}function A_(e){let{client:t,state:n,onClaimed:r}=e,[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1),g=n.proxyIdentity,_=o.trim(),y=_===``?void 0:k_(_),b=_!==``&&y===void 0;async function x(){h(!0),p(null);try{await t.claim({}),r()}catch(e){p(o_(e))}finally{h(!1)}}async function S(){let e=o.trim();if(n.codeRequired&&i.trim()===``){p(`enter the setup code (find it in the server log)`);return}if(e===``){p(`choose a username`);return}h(!0),p(null);try{await t.claim({...n.codeRequired?{code:i.trim()}:{},user:e,...c.trim()===``?{}:{name:c.trim()},...u.trim()===``?{}:{email:u.trim()},issueToken:!0,tokenName:`webui`}),r()}catch(e){p(o_(e))}finally{h(!1)}}return(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Set up sigrun`}),g===void 0?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`auth-message`,children:`Claim this server: the first user is its administrator.`}),n.codeRequired&&(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Setup code`,(0,R.jsx)(`input`,{"data-auth-field":`code`,autoComplete:`one-time-code`,value:i,onChange:e=>a(e.target.value)})]}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Username`,(0,R.jsx)(`input`,{"data-auth-field":`user`,autoComplete:`username`,value:o,onChange:e=>s(e.target.value)})]}),b?(0,R.jsx)(`p`,{className:`auth-message`,"data-auth-preview":`invalid`,children:`Your username needs at least one letter or digit.`}):y===void 0?null:(0,R.jsxs)(`p`,{className:`auth-message`,"data-auth-preview":`user`,children:[`Your username will be `,(0,R.jsx)(`strong`,{children:y})]}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Name `,(0,R.jsx)(`span`,{className:`auth-optional`,children:`(optional)`}),(0,R.jsx)(`input`,{"data-auth-field":`name`,autoComplete:`name`,value:c,onChange:e=>l(e.target.value)})]}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Email `,(0,R.jsx)(`span`,{className:`auth-optional`,children:`(optional)`}),(0,R.jsx)(`input`,{"data-auth-field":`email`,type:`email`,autoComplete:`email`,value:u,onChange:e=>d(e.target.value)})]}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:m||b,onClick:()=>void S(),children:m?`Claiming…`:`Set up sigrun`})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`auth-message`,children:`Your proxy vouches for your identity. Continuing claims this server as:`}),(0,R.jsxs)(`p`,{className:`auth-identity`,children:[(0,R.jsx)(`strong`,{children:g.user}),g.name===void 0?``:` — ${g.name}`,g.email===void 0?``:` · ${g.email}`]}),g.subject!==g.user&&(0,R.jsx)(`p`,{className:`auth-message`,"data-auth-proxy":`subject`,children:g.subject}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:m,onClick:()=>void x(),children:`Continue as ${g.user}`})]}),f!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:f})]})}function j_(e){let{client:t}=e,[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1),g=(0,v.useRef)(null);(0,v.useEffect)(()=>()=>{g.current!==null&&clearTimeout(g.current)},[]),(0,v.useEffect)(()=>{let e=!1;return t.listTokens().then(t=>{e||r(t)}).catch(t=>{e||a(o_(t))}),()=>{e=!0}},[t]);async function _(){if(!(o.trim()===``||c)){l(!0),a(null);try{let e=await t.createToken(o.trim());d({id:e.record.id,token:e.token,name:e.record.name}),r(t=>t===null?t:[...t,e.record]),s(``)}catch(e){a(o_(e))}finally{l(!1)}}}async function y(e){if(!(f===null||c)){l(!0),a(null);try{await t.revokeToken(e),r(t=>t===null?t:t.filter(t=>t.id!==e)),d(t=>t?.id===e?null:t),p(null)}catch(e){a(o_(e))}finally{l(!1)}}}function b(){u!==null&&(nd(u.token),h(!0),g.current!==null&&clearTimeout(g.current),g.current=setTimeout(()=>h(!1),1500))}if(n===null)return(0,R.jsx)(`p`,{className:`settings-note`,role:i===null?void 0:`alert`,children:i??`loading tokens…`});let x=n.filter(e=>e.kind!==`session`),S=globalThis.location?.origin??``,C=S===``?`<your sigrun URL>`:S;return(0,R.jsxs)(`div`,{className:`settings-body`,"data-settings-section":`tokens`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`Bearer tokens for the CLI, scripts, and sign-in. A token is shown once at creation — the server stores only its digest.`}),i!==null&&(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:i}),u!==null&&(0,R.jsxs)(`fieldset`,{className:`settings-field token-reveal`,children:[(0,R.jsxs)(`legend`,{className:`settings-label`,children:[`Token created: `,u.name]}),(0,R.jsx)(`p`,{className:`settings-note`,children:`Copy it now — it is never shown again.`}),(0,R.jsx)(`code`,{className:`token-secret`,children:u.token}),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`button`,{type:`button`,className:`token-copy`,onClick:b,children:m?`Copied`:`Copy`}),(0,R.jsx)(`button`,{type:`button`,className:`token-dismiss`,onClick:()=>d(null),children:`Done`})]}),(0,R.jsxs)(`label`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`CLI`}),(0,R.jsx)(`code`,{className:`token-snippet`,children:`SIGRUN_TOKEN=${u.token} sigrun attach --server ${C}`})]}),(0,R.jsxs)(`label`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`tui.json — $SIGRUN_CONFIG_DIR/tui.json (default ~/.config/sigrun/tui.json)`}),(0,R.jsx)(`code`,{className:`token-snippet`,children:`{"server": "${C}", "token": "${u.token}"}`})]})]}),x.length===0&&(0,R.jsx)(`p`,{className:`settings-note`,children:`No API tokens.`}),x.map(e=>(0,R.jsx)(`div`,{className:`settings-ext-row`,children:f?.id===e.id?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`settings-ext-key`,children:[`Revoke `,e.name,`?`]}),(0,R.jsx)(`button`,{type:`button`,className:`token-revoke-confirm`,disabled:c,onClick:()=>void y(e.id),children:`Confirm revoke`}),(0,R.jsx)(`button`,{type:`button`,className:`token-revoke-cancel`,disabled:c,onClick:()=>p(null),children:`Cancel`})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`settings-ext-key`,children:e.name}),(0,R.jsx)(`button`,{type:`button`,className:`token-revoke`,disabled:c,onClick:()=>p({id:e.id,name:e.name}),children:`Revoke`})]})},e.id)),(0,R.jsxs)(`div`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Create a token`}),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`input`,{type:`text`,className:`token-name-input`,"aria-label":`Token name`,placeholder:`name (e.g. laptop, ci)`,value:o,onChange:e=>s(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`token-create`,disabled:c||o.trim()===``,onClick:()=>void _(),children:`Create token`})]})]})]})}var M_=`sigrun.prefs`,N_={enterToSend:!1,showThinking:!0},P_=(()=>{let e=new Map;return{getItem:t=>e.get(t)??null,setItem:(t,n)=>{e.set(t,n)}}})();function F_(){return globalThis.localStorage??P_}function I_(e){if(e===null)return{};let t;try{t=JSON.parse(e)}catch{return{}}if(typeof t!=`object`||!t||Array.isArray(t))return{};let n=t,r={};for(let e of Object.keys(N_))typeof n[e]==`boolean`&&(r[e]=n[e]);return r}function L_(e){let t=e?.storage??F_(),[n,r]=(0,v.useState)(()=>I_(t.getItem(M_)));return{prefs:{...N_,...n},setPref(e,n){r(r=>{let i={...r,[e]:n};return t.setItem(M_,JSON.stringify(i)),i})}}}function R_(e,t){let n=t.trim().toLowerCase();return n===``?[]:e.filter(e=>e.label.toLowerCase().includes(n)||(e.help??``).toLowerCase().includes(n)||(e.key??``).toLowerCase().includes(n))}function z_(e,t){return R_(e,t)}function B_(e,t){return e.filter(e=>!(e.id===`providers`&&t===!1||e.scope===`user`&&e.admin===!0&&t===!1))}function V_(e){let{client:t,onSection:n,prefsState:r,theme:i,admin:a,onRestart:o,section:s}=e,[c,l]=(0,v.useState)({status:`loading`}),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),x=(0,v.useRef)({}),S=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=!1;return t.getMeta().then(t=>{e||d(t)}).catch(()=>{}),t.listSettingsSections().then(t=>{e||l({status:`ready`,sections:t.sections,index:t.index})}).catch(t=>{e||l({status:`error`,message:t instanceof Error?t.message:String(t)})}),t.listExtensions().then(t=>{e||h(t.extensions)}).catch(()=>{e||h([])}),()=>{e=!0}},[t]);let C=(0,v.useMemo)(()=>c.status===`ready`?new Set(c.sections.filter(e=>e.slug!==`core`).map(e=>e.slug)):new Set,[c]);(0,v.useEffect)(()=>{if(c.status!==`ready`)return;let e=B_(c.sections,a);if(s!==void 0){let t=e.find(e=>e.slug===`core`&&e.id===s);if(t!==void 0){p({kind:`section`,entry:t});return}let n=e.find(e=>e.id===s);if(n!==void 0){p({kind:`section`,entry:n});return}let r=m!==null&&!C.has(s)?m.find(e=>e.name===s):void 0;if(r!==void 0){p({kind:`extension`,slug:r.name});return}}let t=e.find(e=>e.slug===`core`&&e.id===`general`);t!==void 0&&p({kind:`section`,entry:t})},[c,s,a,m,C]);let w=(0,v.useMemo)(()=>c.status===`ready`?z_(c.index,g):[],[c,g]),T=(0,v.useCallback)(async e=>{let t=c.status===`ready`?c.sections.find(t=>t.slug===e.slug&&t.id===e.sectionId):void 0;if(t!==void 0&&(_(``),n(t.id),e.key!==void 0)){let t=e.key;for(let e=0;e<20;e++){await new Promise(e=>setTimeout(e,50));let e=S.current?.querySelector(`[data-name=${JSON.stringify(t)}]`),n=e?.querySelector(`input, textarea, select, button, [tabindex]`)??e;if(n!=null){n.focus();return}}}},[c,n]),E=y?.pendingRestart??[],D=y?.supervised===!0&&a!==!1&&o!==void 0,ee=(0,v.useMemo)(()=>c.status===`ready`?B_(c.sections,a):[],[c,a]);return(0,R.jsx)(`div`,{className:`settings-page`,children:(0,R.jsxs)(`div`,{className:`settings-panel`,children:[(0,R.jsxs)(`header`,{className:`settings-head`,children:[(0,R.jsx)(`span`,{className:`settings-title`,children:`Settings`}),(0,R.jsx)(`input`,{type:`search`,className:`settings-search`,placeholder:`Search settings`,"aria-label":`search settings`,value:g,onChange:e=>_(e.target.value)}),(0,R.jsx)(`span`,{className:`spacer`})]}),E.length>0&&(0,R.jsxs)(`div`,{className:`settings-restart-callout`,role:`status`,children:[(0,R.jsxs)(`p`,{className:`settings-restart-text`,children:[`Restart sigrun to apply: `,E.join(`, `)]}),D&&(0,R.jsx)(`button`,{type:`button`,className:`settings-restart`,onClick:()=>void o(),children:`Restart`})]}),c.status===`loading`&&(0,R.jsx)(`p`,{className:`settings-note`,children:`loading settings…`}),c.status===`error`&&(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:c.message}),c.status===`ready`&&(0,R.jsxs)(`div`,{className:`settings-layout`,children:[(0,R.jsxs)(`nav`,{className:`settings-nav`,"aria-label":`settings sections`,children:[ee.filter(e=>e.scope!==`user`).map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-nav-item`,"data-active":f?.kind===`section`&&f.entry.slug===e.slug&&f.entry.id===e.id?``:void 0,onClick:()=>n(e.id),children:e.title},`${e.slug}/${e.id}`)),ee.some(e=>e.scope===`user`)&&(0,R.jsxs)(`div`,{className:`settings-nav-group`,role:`group`,"aria-label":`My settings`,children:[(0,R.jsx)(`div`,{className:`settings-nav-heading`,children:`My settings`}),ee.filter(e=>e.scope===`user`).map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-nav-item`,"data-active":f?.kind===`section`&&f.entry.slug===e.slug&&f.entry.id===e.id?``:void 0,onClick:()=>n(e.id),children:e.title},`${e.slug}/${e.id}`))]}),(0,R.jsx)(X_,{extensions:m,open:f,coveredSlugs:C,onOpen:n})]}),(0,R.jsx)(`div`,{className:`settings-section`,ref:S,children:f===null?(0,R.jsx)(`p`,{className:`settings-note`,children:`select a section`}):f.kind===`extension`?(0,R.jsx)(Z_,{client:t,slug:f.slug}):(0,R.jsx)(H_,{client:t,entry:f.entry,prefsState:r,theme:i,meta:u,onCoreMeta:b,valuesRef:x},`${f.entry.slug}/${f.entry.id}`)})]}),g.trim()!==``&&w.length>0&&(0,R.jsx)(`div`,{className:`settings-search-results`,role:`listbox`,children:w.slice(0,20).map((e,t)=>(0,R.jsxs)(`button`,{type:`button`,className:`settings-search-hit`,role:`option`,"aria-selected":`false`,onClick:()=>void T(e),children:[(0,R.jsx)(`span`,{className:`settings-search-hit-label`,children:e.label}),(0,R.jsxs)(`span`,{className:`settings-search-hit-path`,children:[e.slug===`core`?``:`${e.slug} · `,e.sectionId]})]},`${e.slug}/${e.sectionId}/${e.key??e.label}/${t}`))})]})})}function H_(e){let{entry:t,client:n,prefsState:r,theme:i,meta:a,onCoreMeta:o}=e;return t.slug===`core`&&t.id===`interface`?(0,R.jsx)(q_,{prefsState:r,theme:i}):t.slug===`core`&&t.id===`providers`?(0,R.jsx)(w_,{client:n}):t.slug===`core`&&t.id===`extensions`?(0,R.jsx)(Q_,{client:n}):t.slug===`core`&&t.id===`accounts`?(0,R.jsx)(C_,{client:n}):t.slug===`core`&&t.id===`tokens`?(0,R.jsx)(j_,{client:n}):(0,R.jsx)(U_,{client:n,entry:t,meta:t.slug===`core`&&t.id===`general`?a:null,onCoreMeta:t.slug===`core`?o:void 0,valuesRef:e.valuesRef})}function U_(e){let{entry:t,meta:n,client:r}=e,i=(0,v.useMemo)(()=>pg({slug:t.slug,id:t.id,fetch:r.rawFetch}),[t.slug,t.id,r]),{onCoreMeta:a,valuesRef:o}=e,s=(0,v.useCallback)(e=>{if(o.current[`${t.slug}/${t.id}`]=typeof e.settings==`object`&&e.settings!==null&&!Array.isArray(e.settings)?e.settings:{},a!==void 0){let t=e.meta;if(typeof t==`object`&&t&&!Array.isArray(t)&&Array.isArray(t.pendingRestart)){let e=t;a({pendingRestart:e.pendingRestart.filter(e=>typeof e==`string`),supervised:e.supervised===!0})}}},[t.slug,t.id,a,o]);return(0,R.jsxs)(`div`,{className:`settings-body`,"data-settings-section":t.id,children:[t.slug===`core`&&t.id===`general`&&(0,R.jsxs)(`p`,{className:`settings-version`,children:[`sigrun `,n?.version===void 0?``:`v${n.version}`,n?.harnessVersion===void 0?``:` · pi-durable v${n.harnessVersion}`]}),(0,R.jsx)(W_,{transport:i,onData:s}),(0,R.jsx)(Yh,{transport:i})]})}function W_(e){let{transport:t,onData:n}=e;return(0,v.useEffect)(()=>{let e=!1,r=()=>{t.fetchData().then(t=>{!e&&t.data!==void 0&&n(t.data)}).catch(()=>{})};r();let i=setInterval(r,1500);return()=>{e=!0,clearInterval(i)}},[t,n]),null}var G_=[{key:`enterToSend`,label:`Enter sends the prompt`,note:`off: Ctrl+Enter submits (Enter inserts a newline); on: Enter submits and Shift+Enter inserts a newline. Ctrl+Enter submits either way.`},{key:`showThinking`,label:`Show thinking blocks`,note:`Show thinking text inside activity details`}],K_=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function q_(e){let{prefsState:t,theme:n}=e;return(0,R.jsxs)(`div`,{className:`settings-body`,children:[(0,R.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,R.jsx)(`legend`,{className:`settings-label`,children:`Mode`}),(0,R.jsx)(`div`,{className:`settings-mode-row`,role:`group`,"aria-label":`mode`,children:K_.map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-mode`,"data-mode-option":e.value,"aria-pressed":n.mode===e.value,onClick:()=>n.setMode(e.value),children:e.label},e.value))})]}),(0,R.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,R.jsx)(`legend`,{className:`settings-label`,children:`Palette`}),(0,R.jsx)(`div`,{className:`settings-palettes`,role:`group`,"aria-label":`palette`,children:__.map(e=>{let t=h_[e],r=t[n.resolved];return(0,R.jsxs)(`button`,{type:`button`,className:`settings-palette`,"data-palette-option":e,"aria-pressed":n.palette===e,title:t.label,onClick:()=>n.setPalette(e),style:{background:r.bg},children:[(0,R.jsx)(`span`,{className:`settings-swatch-dot`,"aria-hidden":`true`,style:{background:r.text}}),(0,R.jsx)(`span`,{className:`settings-swatch-dot`,"aria-hidden":`true`,style:{background:g_[t.defaultAccent][n.resolved]}})]},e)})})]}),(0,R.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,R.jsx)(`legend`,{className:`settings-label`,children:`Accent`}),(0,R.jsx)(`div`,{className:`settings-accents`,role:`group`,"aria-label":`accent`,children:v_.map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-accent`,"data-accent-option":e,"aria-pressed":n.accent===e,title:g_[e].label,onClick:()=>n.setAccent(e),style:{background:g_[e][n.resolved]}},e))})]}),G_.map(e=>(0,R.jsxs)(`label`,{className:`settings-field settings-checkbox`,children:[(0,R.jsx)(`input`,{type:`checkbox`,className:`settings-pref-${e.key}`,checked:t.prefs[e.key],onChange:n=>t.setPref(e.key,n.target.checked)}),(0,R.jsx)(`span`,{className:`settings-label`,children:e.label}),(0,R.jsx)(`p`,{className:`settings-note`,children:e.note})]},e.key)),(0,R.jsx)(`p`,{className:`settings-note`,children:`interface preferences are per-browser (stored locally — never sent to the server)`})]})}function J_(e){return Object.keys(e).length===0?``:JSON.stringify(e,null,2)}function Y_(e){let t=e.trim();if(t===``)return{ok:!0,value:{}};try{let e=JSON.parse(t);return typeof e!=`object`||!e||Array.isArray(e)?{ok:!1,message:`settings must be a JSON object`}:{ok:!0,value:e}}catch(e){return{ok:!1,message:`invalid JSON: ${e instanceof Error?e.message:String(e)}`}}}function X_(e){let{extensions:t,coveredSlugs:n,onOpen:r,open:i}=e;if(t===null)return null;let a=t.filter(e=>!n.has(e.name));return a.length===0?null:(0,R.jsx)(R.Fragment,{children:a.map(e=>(0,R.jsxs)(`button`,{type:`button`,className:`settings-nav-item settings-nav-extension`,"data-ext":e.name,"data-active":i?.kind===`extension`&&i.slug===e.name?``:void 0,onClick:()=>r(e.name),children:[e.name,` (advanced)`]},e.name))})}function Z_(e){let{client:t,slug:n,status:r,version:i}=e,[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1;return o(null),c(null),Promise.all([t.getExtensionSettings(n),t.listExtensionSecrets(n)]).then(([t,n])=>{e||o({settingsText:J_(t.settings),secrets:n.secrets,secretValues:{},newKey:``,newValue:``})}).catch(t=>{e||c(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[t,n]);let l=e=>{o(t=>t===null?t:{...t,...e})},u=async()=>{if(a===null)return;let e=Y_(a.settingsText);if(!e.ok){l({note:{kind:`error`,message:e.message}});return}try{await t.putExtensionSettings(n,e.value),l({note:{kind:`ok`,message:`saved`}})}catch(e){l({note:{kind:`error`,message:e instanceof Error?e.message:String(e)}})}},d=async(e,r)=>{if(e!==``&&r!==``&&a!==null)try{let{secrets:i}=await t.putExtensionSecret(n,e,r);o({...a,secrets:i,secretValues:{...a.secretValues,[e]:``},newKey:``,newValue:``,note:{kind:`ok`,message:`secret ${e} set`}})}catch(e){l({note:{kind:`error`,message:e instanceof Error?e.message:String(e)}})}},f=async e=>{try{let{secrets:r}=await t.deleteExtensionSecret(n,e);l({secrets:r,note:{kind:`ok`,message:`secret ${e} deleted`}})}catch(e){l({note:{kind:`error`,message:e instanceof Error?e.message:String(e)}})}};return s===null?a===null?(0,R.jsx)(`p`,{className:`settings-note`,children:`loading…`}):(0,R.jsxs)(`div`,{className:`settings-body settings-ext-list`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`settings are the extension's own JSON (read at factory time → applies at restart); secrets list keys only — values are write-only and never displayed`}),(0,R.jsxs)(`fieldset`,{className:`settings-ext`,"data-ext":n,children:[(0,R.jsxs)(`legend`,{className:`settings-ext-name`,children:[n,(0,R.jsxs)(`span`,{className:`settings-ext-meta`,children:[r??``,i===void 0?``:` · v${i}`]})]}),(0,R.jsxs)(`label`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Settings (raw JSON)`}),(0,R.jsx)(`textarea`,{className:`settings-ext-settings`,rows:4,spellCheck:!1,placeholder:`{}`,value:a.settingsText,onChange:e=>l({settingsText:e.target.value})}),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-save`,onClick:()=>void u(),children:`Save settings`}),a.note!==void 0&&(0,R.jsx)(`span`,{className:`settings-note`,role:a.note.kind===`ok`?`status`:`alert`,children:a.note.message})]})]}),(0,R.jsxs)(`div`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Secrets`}),a.secrets.length===0&&(0,R.jsx)(`p`,{className:`settings-note`,children:`no secrets set`}),a.secrets.map(e=>(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsxs)(`span`,{className:`settings-ext-key`,children:[e.key,` `,(0,R.jsxs)(`span`,{className:`settings-ext-source`,children:[`(`,e.source,`)`]})]}),(0,R.jsx)(`input`,{type:`password`,className:`settings-ext-secret-value`,"data-secret-key":e.key,placeholder:`new value`,value:a.secretValues[e.key]??``,onChange:t=>l({secretValues:{...a.secretValues,[e.key]:t.target.value}})}),(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-secret-set`,"data-secret-key":e.key,onClick:()=>void d(e.key,a.secretValues[e.key]??``),children:`Set`}),(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-secret-delete`,"data-secret-key":e.key,onClick:()=>void f(e.key),children:`Delete`})]},e.key)),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`input`,{type:`text`,className:`settings-ext-new-key`,placeholder:`new key`,value:a.newKey,onChange:e=>l({newKey:e.target.value})}),(0,R.jsx)(`input`,{type:`password`,className:`settings-ext-new-value`,placeholder:`value`,value:a.newValue,onChange:e=>l({newValue:e.target.value})}),(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-secret-add`,onClick:()=>void d(a.newKey,a.newValue),children:`Set`})]})]})]})]}):(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:s})}function Q_(e){let{client:t}=e,[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=!1;return t.listExtensions().then(t=>{e||r(t.extensions)}).catch(t=>{e||a(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[t]),i===null?n===null?(0,R.jsx)(`p`,{className:`settings-note`,children:`loading extensions…`}):n.length===0?(0,R.jsx)(`div`,{className:`settings-body`,children:(0,R.jsx)(`p`,{className:`settings-note`,children:`no extensions are configured`})}):(0,R.jsx)(`div`,{className:`settings-body`,children:n.map(e=>(0,R.jsx)(Z_,{client:t,slug:e.name,status:e.status,version:e.version},e.name))}):(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:i})}var $_=`sigrun.theme`,ev=`sigrun.palette`,tv=`sigrun.accent`,nv=(()=>{let e=new Map;return{getItem:t=>e.get(t)??null,setItem:(t,n)=>{e.set(t,n)}}})();function rv(){return globalThis.localStorage??nv}function iv(){let e=globalThis.document?.documentElement;return e===void 0?null:{dataset:e.dataset,setProperty:(t,n)=>{e.style.setProperty(t,n)}}}function av(){return globalThis.matchMedia??null}function ov(e){return e===`dark`||e===`light`?e:`system`}function sv(e){let t=e.getItem(tv);if(t===`amber`){let t=`baltic-amber`;return e.setItem(tv,t),t}return S_(t)?t:(e.setItem(tv,b_),b_)}function cv(e){let t=e.getItem(ev);return x_(t)?t:(e.setItem(ev,y_),y_)}var lv={bg:`--bg`,surface:`--surface`,surface2:`--surface-2`,border:`--border`,text:`--text`,muted:`--muted`,faint:`--faint`,ok:`--ok`,code:`--code`};function uv(e,t){let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(n===null)return`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`;let r=n[1].length===3?n[1].split(``).map(e=>e+e).join(``):n[1];return`rgba(${Number.parseInt(r.slice(0,2),16)}, ${Number.parseInt(r.slice(2,4),16)}, ${Number.parseInt(r.slice(4,6),16)}, ${t})`}function dv(e){let t=e?.storage??rv(),n=e?.root===void 0?iv():e.root,r=e?.matchMedia===void 0?av():e.matchMedia,[i,a]=(0,v.useState)(()=>ov(t.getItem($_))),[o,s]=(0,v.useState)(()=>cv(t)),[c,l]=(0,v.useState)(()=>sv(t)),[u,d]=(0,v.useState)(()=>r?.(`(prefers-color-scheme: dark)`)?.matches??!0);(0,v.useEffect)(()=>{let e=r?.(`(prefers-color-scheme: dark)`);if(e==null)return;let t=()=>d(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[r]);let f=i===`system`?u?`dark`:`light`:i;return(0,v.useEffect)(()=>{if(n===null)return;let e=h_[o][f];for(let[t,r]of Object.entries(lv))n.setProperty(r,e[t]);let t=g_[c][f];n.setProperty(`--accent`,t),n.setProperty(`--accent-bg`,uv(t,f===`dark`?.14:.16)),n.dataset.mode=f,n.dataset.palette=o,n.dataset.accent=c},[n,f,o,c]),{mode:i,resolved:f,palette:o,accent:c,setMode(e){t.setItem($_,e),a(e)},setPalette(e){t.setItem(ev,e),s(e)},setAccent(e){t.setItem(tv,e),l(e)}}}function fv(e,t){let n=e.entries;if(t.entries!==void 0){let r=new Set(t.entries.remove??[]);n=[...e.entries.filter(e=>!r.has(e.id)),...t.entries.append??[]]}let r=e.docs;if(t.docs!==void 0){let n=new Set(t.docs.unset??[]),i={};for(let[t,r]of Object.entries(e.docs))n.has(t)||(i[t]=r);for(let[e,n]of Object.entries(t.docs.set??{}))i[e]=n;r=i}return{...e,entries:n,docs:r,conversation:t.conversation??e.conversation,steer:t.steer??e.steer}}var pv=250,mv=4e3,hv=e=>new EventSource(e);function gv(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t==`object`&&t&&!Array.isArray(t))return t}function _v(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t==`object`&&t&&!Array.isArray(t))return t}function vv(e,t,n=``,r={}){let i=r.createEventSource??hv,a=`${n}/v1/conversations/${e}/stream`,o=!1,s=0,c,l,u;function d(){if(o)return;let e=i(a);l=e;let n=!1;e.addEventListener(`open`,()=>{o||(s=0,t.onOpen?.())}),e.addEventListener(`snapshot`,e=>{if(o)return;let n=gv(e.data);if(n===void 0){t.onError?.(`malformed snapshot frame (not a view object)`);return}u=n,t.onSnapshot?.(n)}),e.addEventListener(`delta`,e=>{if(o)return;if(u===void 0){t.onError?.(`malformed delta frame (arrived before any snapshot)`);return}let n=_v(e.data);if(n===void 0){t.onError?.(`malformed delta frame (not a delta object)`);return}u=fv(u,n),t.onView?.(u)}),e.addEventListener(`error`,()=>{if(o||n)return;n=!0,t.onError?.(`conversation stream connection error`),e.close(),l===e&&(l=void 0),s+=1;let r=Math.min(pv*2**(s-1),mv);c=setTimeout(()=>{c=void 0,d()},r)})}return d(),{close(){o||(o=!0,c!==void 0&&(clearTimeout(c),c=void 0),l?.close(),l=void 0)}}}var yv={view:null,status:`idle`,frames:0,error:null};function bv(e,t={}){let{baseUrl:n,createEventSource:r}=t,[i,a]=(0,v.useState)(yv);return(0,v.useEffect)(()=>{if(e===null){a(yv);return}a({view:null,status:`connecting`,frames:0,error:null});let t=vv(e,{onSnapshot:e=>a(t=>({view:e,status:`snapshot`,frames:t.frames+1,error:null})),onView:e=>a(t=>({view:e,status:`live`,frames:t.frames+1,error:null})),onError:e=>a(t=>({...t,status:`error`,error:e}))},n,{createEventSource:r});return()=>t.close()},[e,n,r]),i}var xv=4e3;function Sv(e,t){let[n,r]=(0,v.useState)([]),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)({}),c=(0,v.useRef)({}),l=(0,v.useCallback)(e=>{c.current=typeof e==`function`?e(c.current):e,s(c.current)},[]),u=(0,v.useRef)(null),d=(0,v.useRef)(0),f=(0,v.useRef)(new Set),p=(0,v.useCallback)(async(t=!1)=>{let n=(await e.listNotices()).notices,i=u.current;if(i!==null&&a(n.filter(e=>!i.has(e.id))),u.current=new Set(n.map(e=>e.id)),!t&&Date.now()<d.current){r(e=>{let t=new Set(n.map(e=>e.id));return[...n,...e.filter(e=>!t.has(e.id)&&(c.current[e.id]!==void 0||f.current.has(e.id)))]});return}r(n)},[e]),m=(0,v.useRef)(null),h=(0,v.useCallback)(()=>{d.current=Date.now()+xv,m.current!==null&&clearTimeout(m.current),m.current=setTimeout(()=>{m.current=null,l({}),p(!0).catch(()=>void 0)},xv);let e=m.current;typeof e==`object`&&e&&`unref`in e&&e.unref()},[p]);(0,v.useEffect)(()=>{p().catch(()=>void 0)},[p,t.refetchToken]);let g=(0,v.useCallback)(async t=>{await e.dismissNotice(t).catch(()=>void 0),await p().catch(()=>void 0)},[e,p]);return{notices:n,arrivals:i,results:o,refetch:p,dismiss:g,dismissAll:(0,v.useCallback)(async()=>{await e.dismissAllNotices().catch(()=>void 0),await p().catch(()=>void 0)},[e,p]),run:(0,v.useCallback)(async(t,r,i)=>{if(r.kind===`navigate`){i(r.target),await g(t.id);return}if(r.kind===`open`){globalThis.window?.open(r.url,`_blank`,`noopener,noreferrer`),await g(t.id);return}f.current=new Set([...f.current,t.id]);let a;try{a=await e.runNoticeAction(t.id,r.id)}catch(e){l(n=>({...n,[t.id]:e instanceof Error?e.message:String(e)})),await p(!0).catch(()=>void 0);return}finally{let e=new Set(f.current);e.delete(t.id),f.current=e}a.ok&&a.navigate!==void 0&&i(a.navigate);let o=a.ok?a.message:a.error.message;return o!==void 0&&l(e=>({...e,[t.id]:o})),a.ok&&n.some(e=>e.id===t.id)?(h(),a):(await p(!0).catch(()=>void 0),a)},[e,g,p,h,n])}}function Cv(){return globalThis.document}function wv(e){let t=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(e.variant!==`overlay`||e.onClose===void 0)return;let n=Cv();if(n===void 0)return;let r=e.onClose,i=e=>{e.key===`Escape`&&r()},a=e=>{let n=e.target;if(n==null)return;let i=t.current;if(i!==null&&!i.contains(n)){let e=n.closest;if(typeof e==`function`&&e.call(n,`[data-rail-section="notices"]`)!==null)return;r()}};return n.addEventListener(`keydown`,i),n.addEventListener(`mousedown`,a),()=>{n.removeEventListener(`keydown`,i),n.removeEventListener(`mousedown`,a)}},[e.variant,e.onClose]),(0,v.useEffect)(()=>{e.scrollTo!==null&&e.scrollTo!==void 0&&(t.current?.querySelector?.(`[data-notice-id="${e.scrollTo}"]`))?.scrollIntoView?.()},[e.scrollTo]),(0,R.jsxs)(`div`,{ref:t,className:e.variant===`overlay`?`notices-pane notices-pane-overlay`:`notices-pane`,role:`complementary`,"aria-label":`notices`,children:[(0,R.jsxs)(`h4`,{className:`notices-pane-head`,children:[(0,R.jsx)(`span`,{children:`Notices`}),e.notices.length>0&&(0,R.jsx)(`button`,{type:`button`,className:`notices-pane-clear`,onClick:()=>e.dismissAll(),children:`Clear all`})]}),e.notices.length===0?(0,R.jsx)(`p`,{className:`notices-pane-empty`,children:`No notices`}):e.notices.map(t=>(0,R.jsx)(im,{notice:t,result:e.results?.[t.id]??null,conversationName:t.conversationId===void 0?void 0:e.conversationName?.(t.conversationId),run:e.run,dismiss:e.dismiss,onNavigate:e.onNavigate},t.id))]})}var Tv=6e3,Ev={now:()=>Date.now(),sleep:(e,t)=>setTimeout(t,e),clear:e=>clearTimeout(e)};function Dv(){return globalThis.document?.visibilityState===`hidden`}function Ov(e){let{batch:t,clock:n}=e,r=t.length===1?t[0]:void 0,i=(0,v.useRef)(null),a=(0,v.useRef)(Tv),o=(0,v.useRef)(0),s=()=>{i.current!==null&&n.clear(i.current),o.current=n.now(),i.current=n.sleep(a.current,e.onFold)};(0,v.useEffect)(()=>(s(),()=>{i.current!==null&&n.clear(i.current)}),[]);let c=()=>{i.current!==null&&(n.clear(i.current),i.current=null,a.current=Math.max(0,a.current-(n.now()-o.current)))},l=()=>{i.current===null&&s()},u=r?.actions?.[0];return(0,R.jsxs)(`div`,{className:`notice-peek`,role:`status`,"aria-live":`polite`,onMouseEnter:c,onMouseLeave:l,onFocus:c,onBlur:l,children:[(0,R.jsx)(`button`,{type:`button`,className:`notice-peek-body`,onClick:()=>{e.onOpenPane(r?.id),e.onFold()},children:r===void 0?(0,R.jsxs)(`strong`,{children:[t.length,` new notices`]}):(0,R.jsx)(`strong`,{children:r.title})}),r!==void 0&&u!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`notice-peek-action`,onClick:()=>{e.run(r,u,e.onNavigate),e.onFold()},children:u.label}),r!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`notice-peek-close`,"aria-label":`dismiss notice`,onClick:()=>{e.dismiss(r.id),e.onFold()},children:`✕`})]})}function kv(e){let[t,n]=(0,v.useState)([]),r=(0,v.useRef)(new Set);return(0,v.useEffect)(()=>{let t=e.arrivals.filter(t=>!r.current.has(t.id)&&(e.visibleConversationId===null||e.visibleConversationId===void 0||t.conversationId!==e.visibleConversationId));for(let t of e.arrivals)r.current.add(t.id);t.length===0||Dv()||n(e=>[...e,...t])},[e.arrivals,e.visibleConversationId]),t.length===0?null:(0,R.jsx)(Ov,{batch:t,onFold:()=>n([]),run:e.run,dismiss:e.dismiss,onNavigate:e.onNavigate,onOpenPane:e.onOpenPane,clock:e.clock??Ev},`${t[0]?.id}:${t.length}`)}function Av(e){return(0,R.jsxs)(`button`,{type:`button`,className:`rail-btn rail-bell`,"data-rail-section":`notices`,title:`Notices`,"aria-label":`notices`,"aria-pressed":e.active===!0,"data-active":e.active===!0?``:void 0,onClick:()=>e.onToggle?.(),children:[`🔔`,e.count>0&&(0,R.jsx)(`span`,{className:`rail-bell-badge`,"data-bell-count":e.count,children:e.count})]})}var jv=24;function Mv(e,t){let[n,r]=(0,v.useState)(!0),i=(0,v.useRef)(!0);return(0,v.useEffect)(()=>{if(e===null)return;let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=jv;i.current=t,r(t)};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>e.removeEventListener(`scroll`,t)},[e]),(0,v.useEffect)(()=>{e!==null&&i.current&&(e.scrollTop=e.scrollHeight)},[e,t]),n}function Nv(e){let{client:t,conversationId:n,path:r}=e,[i,a]=(0,v.useState)({kind:`loading`});return(0,v.useEffect)(()=>{let e=!1;return a({kind:`loading`}),t.readFile(n,r).then(t=>{e||a(t.encoding===`text`?{kind:`text`,content:t.content,size:t.size}:{kind:`binary`,size:t.size})}).catch(t=>{e||a({kind:`error`,message:t instanceof Error?t.message:String(t)})}),()=>{e=!0}},[t,n,r]),(0,R.jsxs)(`div`,{className:`file-preview`,"data-path":r,children:[(0,R.jsx)(`div`,{className:`file-preview-path`,children:r}),i.kind===`loading`&&(0,R.jsx)(`p`,{className:`file-preview-loading`,children:`loading…`}),i.kind===`text`&&(0,R.jsx)(`pre`,{className:`file-preview-content`,children:i.content}),i.kind===`binary`&&(0,R.jsxs)(`p`,{className:`file-preview-binary`,children:[`binary file — `,i.size,` bytes (no preview)`]}),i.kind===`error`&&(0,R.jsx)(`p`,{role:`alert`,children:i.message})]})}function Pv(e){return[...e].sort((e,t)=>(e.kind===`directory`?0:1)-(t.kind===`directory`?0:1)||e.name.localeCompare(t.name))}function Fv(e){let{client:t,conversationId:n,onClose:r}=e,[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)({}),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(a(null),s({}),l({}),d(null),p(null),n===null)return;let e=!1;return t.listFiles(n).then(t=>{e||a(Pv(t.entries))}).catch(t=>{e||p(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[t,n]);async function m(e){if(n!==null){if(c[e.path]){l(t=>{let n={...t};return delete n[e.path],n});return}if(l(t=>({...t,[e.path]:!0})),o[e.path]===void 0)try{let r=await t.listFiles(n,e.path);s(t=>({...t,[e.path]:Pv(r.entries)}))}catch(e){p(e instanceof Error?e.message:String(e))}}}function h(e,t){return e.map(e=>{if(e.kind===`directory`){let n=c[e.path]===!0,r=o[e.path];return(0,R.jsxs)(`li`,{children:[(0,R.jsxs)(`button`,{type:`button`,className:`workspace-dir`,"data-tree-row":`true`,"data-path":e.path,"aria-expanded":n,style:{paddingLeft:`${t*.9}rem`},onClick:()=>void m(e),children:[n?`▾`:`▸`,` `,e.name,`/`]}),n&&r!==void 0&&(0,R.jsx)(`ul`,{className:`workspace-children`,children:h(r,t+1)})]},e.path)}return(0,R.jsx)(`li`,{children:(0,R.jsx)(`button`,{type:`button`,className:`workspace-file`,"data-tree-row":`true`,"data-path":e.path,"data-selected":u===e.path||void 0,style:{paddingLeft:`${t*.9}rem`},onClick:()=>d(e.path),children:e.name})},e.path)})}return(0,R.jsxs)(`section`,{className:`workspace-browser`,"aria-label":`workspace files`,children:[(0,R.jsxs)(`h2`,{className:`workspace-title`,children:[`Workspace`,r!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`workspace-close`,"aria-label":`close workspace panel`,title:`close`,onClick:r,children:`✕`})]}),n===null?(0,R.jsx)(`p`,{className:`workspace-empty`,children:`Select a conversation to browse its workspace`}):(0,R.jsxs)(R.Fragment,{children:[f!==null&&(0,R.jsx)(`p`,{role:`alert`,children:f}),i===null&&f===null?(0,R.jsx)(`p`,{className:`workspace-loading`,children:`loading…`}):i===null?null:(0,R.jsx)(`ul`,{className:`workspace-tree`,children:h(i,0)}),u!==null&&(0,R.jsx)(Nv,{client:t,conversationId:n,path:u})]})]})}var Iv=w(),Lv=6e4,Rv=`sigrun.timeline`;function zv(){try{return globalThis.localStorage?.getItem(Rv)!==`0`}catch{return!0}}function Bv(e){try{globalThis.localStorage?.setItem(Rv,e?`1`:`0`)}catch{}}function Vv(e,t){let n=globalThis.document;if(n===void 0)return;let r=URL.createObjectURL(new Blob([t],{type:`application/json`})),i=n.createElement(`a`);i.href=r,i.download=e,n.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function Hv(e,t){return t===null?`sigrun`:oe(e.find(e=>e.id===t)??{id:t,archived:!1,pinned:!1})}function Uv(e){let{activeId:t,view:n,status:r,error:i,showThinking:a,timeline:o}=e;if(t===null)return(0,R.jsx)(`section`,{className:`chat-center`,children:(0,R.jsx)(`p`,{className:`chat-empty`,children:`Start a conversation — type below.`})});let s=n?.steer.busy??!1,c=n!==null&&Bh(n)>0,l=n===null||c?void 0:Vh(n);return(0,R.jsxs)(`section`,{className:`chat-center`,"data-view-status":r,"aria-label":`chat transcript`,ref:e.onScrollRoot,style:e.dockPadding>0?{paddingBottom:`${e.dockPadding}px`}:void 0,children:[i!==null&&(0,R.jsx)(`p`,{role:`alert`,children:i}),n===null?(0,R.jsx)(`p`,{className:`chat-loading`,children:`loading…`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ah.Provider,{value:e.attachChatTransport,children:(0,R.jsx)(Kh,{view:n,showThinking:a,timeline:o,parent:e.parent,client:e.client,onNavigate:e.onNavigate})}),s&&(0,R.jsxs)(`div`,{className:`chat-working`,role:`status`,children:[(0,R.jsx)(`span`,{className:`chat-working-dot`}),(0,R.jsx)(`span`,{className:`chat-working-dot`}),(0,R.jsx)(`span`,{className:`chat-working-dot`}),(0,R.jsx)(`span`,{className:`chat-working-label`,children:c?`compacting…`:`working…`})]}),l!==void 0&&(0,R.jsxs)(`p`,{className:`chat-compaction-failure`,role:`alert`,children:[`compaction failed: `,l]})]})]})}function Wv(e){let t=e.startsWith(`#`)?e.slice(1):e,n=/^\/settings(?:\/([^/]+))?\/?$/.exec(t);if(n!==null){let e=n[1];if(e===void 0)return{kind:`settings`};try{return{kind:`settings`,section:decodeURIComponent(e)}}catch{return{kind:`chat`}}}let r=/^\/c(?:\/(\d+))?\/?$/.exec(t);if(r!==null){let e=r[1];return e===void 0?{kind:`chat`}:{kind:`chat`,conversationId:Number(e)}}let i=/^\/ext\/([^/]+)\/([^/?]+)(?:\?(.*))?$/.exec(t);if(i===null)return{kind:`chat`};try{return{kind:`ext`,slug:decodeURIComponent(i[1]??``),id:decodeURIComponent(i[2]??``),params:Gv(i[3])}}catch{return{kind:`chat`}}}function Gv(e){let t={};if(e!==void 0){let n=new URLSearchParams(e).get(`params`);if(n!==null)try{let e=JSON.parse(n);typeof e==`object`&&e&&!Array.isArray(e)&&(t=e)}catch{}}return t}function Kv(e){if(e.kind===`chat`)return e.conversationId===void 0?`#/c`:`#/c/${e.conversationId}`;if(e.kind===`settings`)return e.section===void 0?`#/settings`:`#/settings/${encodeURIComponent(e.section)}`;let t=`#/ext/${encodeURIComponent(e.slug)}/${encodeURIComponent(e.id)}`;return Object.keys(e.params).length===0?t:`${t}?params=${encodeURIComponent(JSON.stringify(e.params))}`}function qv(){let e=globalThis.location;if(e?.pathname!==`/settings`)return;let t=new URLSearchParams(e.search??``).get(`section`),n=t===null||t===``?`#/settings`:`#/settings/${encodeURIComponent(t)}`;Jv=n,globalThis.history?.replaceState(null,``,`/${n}`)}var Jv=``;function Yv(){let e=globalThis.location;return e!==void 0&&typeof e.hash==`string`?e.hash:Jv}function Xv(e,t=!1){let n=globalThis.history;Jv=e,n!==void 0&&(t?n.replaceState(null,``,e):n.pushState(null,``,e))}function Zv(e={}){let t=e.client??Iv,n=e.identity,r=e.onLogout,i=e.onRestarting,a=dv(),o=L_(),[s,c]=(0,v.useState)({status:`loading`}),l=(0,v.useCallback)(async()=>{try{await t.requestRestart()}catch(e){ue(`restart failed: ${e instanceof Error?e.message:String(e)}`);return}ue(null),c({status:`restarting`});let e=Date.now()+Lv;for(;;){await new Promise(e=>setTimeout(e,500));let n=!1;try{n=await t.checkReady()}catch{}if(n){i===void 0?c({status:`loading`}):i();return}if(Date.now()>e){c({status:`refused`,message:`restart did not come back: /readyz never answered within ${Lv/1e3}s — check the deployment's supervisor`});return}}},[t,i]);(0,v.useEffect)(()=>{e.onExposeActions?.({restart:l}),(e.onExposeActions!==void 0||globalThis.__sigrunE2E===!0)&&(globalThis.__sigrunAppActions={restart:l})},[l]);let[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(Pg),[m,h]=(0,v.useState)(zv),[g,_]=(0,v.useState)(!1),[,y]=(0,v.useState)(0),b=globalThis,x=s.status===`ready`&&b.location?.hash.startsWith(`#/blocks`)?`blocks`:`chats`;qv();let[S,C]=(0,v.useState)(()=>Wv(Yv())),[w]=(0,v.useState)(()=>new Yg),[T]=(0,v.useState)(()=>new mg),[E]=(0,v.useState)(()=>new _g),D=(0,v.useCallback)(e=>E.attach(e),[E]),[ee]=(0,v.useState)([]),[te,ne]=(0,v.useState)(null),[re,ie]=(0,v.useState)(0),[ae,O]=(0,v.useState)(!1),[se,ce]=(0,v.useState)(null),[le,ue]=(0,v.useState)(null),[de,fe]=(0,v.useState)(null),[pe,me]=(0,v.useState)(0),he=(0,v.useCallback)(e=>{if(e===null)return;let t=()=>me(e.offsetHeight);t();let n=globalThis.ResizeObserver;if(n===void 0)return;let r=new n(t);return r.observe(e),()=>r.disconnect()},[]),{view:ge,status:_e,error:ve,frames:ye}=bv(u,{createEventSource:e.createEventSource});Mv(de,ye);let k=m_(t,{busy:ge?.steer.busy??!1,createEventSource:e.createEventSource,onNoticeChanged:(0,v.useCallback)(()=>{ie(e=>e+1)},[]),onSurfaceChanged:(0,v.useCallback)(e=>{T.dispatch(e)},[T]),onChatChanged:(0,v.useCallback)(e=>{E.dispatch(e)},[E])}),A=S.kind===`ext`?S:null,j=A===null?``:Ee(A.params??{}),[M,be]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(A===null){be(null);return}let e=!0;return Oe(A.slug,A.id,j).then(t=>{e&&be({key:j,hash:t})}),()=>{e=!1}},[A,j]);let xe=(0,v.useMemo)(()=>{if(A!==null&&M!==null&&M.key===j)return T.attach({slug:A.slug,id:A.id,params:A.params,...k.streamId===void 0?{}:{streamId:k.streamId}},M.hash)},[A,j,M,T,k.streamId]),Se=(0,v.useMemo)(()=>s.status===`ready`?Ng(f,Sg(s.meta.extensions)):f,[f,s]),Ce=Se!==null&&Se.startsWith(`ext:`)?Se:null,N=(0,v.useMemo)(()=>{if(Ce===null)return null;let[e,t]=Ce.slice(4).split(`/`);return e===void 0||t===void 0||e===``||t===``?null:{slug:e,id:t}},[Ce]),P=(0,v.useMemo)(()=>Ce===null||s.status!==`ready`?{}:Sg(s.meta.extensions).find(e=>`ext:${e.slug}/${e.id}`===Ce)?.perConversation===!0&&u!==null?{conversationId:u}:{},[Ce,s,u]),we=(0,v.useMemo)(()=>Ee(P),[P]),[Te,De]=(0,v.useState)(null),ke=`${Ce??``}:${we}`;(0,v.useEffect)(()=>{if(N===null){De(null);return}let e=!0,t=ke;return Oe(N.slug,N.id,we).then(n=>{e&&De({forKey:t,hash:n})}),()=>{e=!1}},[N,ke,we]);let Ae=(0,v.useMemo)(()=>{if(N!==null&&Te!==null&&Te.forKey===ke)return T.attach({slug:N.slug,id:N.id,params:JSON.parse(we),...k.streamId===void 0?{}:{streamId:k.streamId}},Te.hash)},[N,ke,we,Te,T,k.streamId]);(0,v.useEffect)(()=>{A!==null&&k.noteSurfaceVisible(A.slug,A.id,A.params),N!==null&&k.noteSurfaceVisible(N.slug,N.id,JSON.parse(we))},[A,j,N,we,k.streamId,k.noteSurfaceVisible]);let je=(0,v.useMemo)(()=>{if(N!==null&&s.status===`ready`)return Sg(s.meta.extensions).find(e=>e.slug===N.slug&&e.id===N.id)?.refreshMs},[N,s]),Ne=(0,v.useMemo)(()=>{let e=k.rows.find(e=>e.id===u)?.parent;if(e===void 0)return;let t=k.rows.find(t=>t.id===e.id);return{id:e.id,name:oe(t===void 0?{id:e.id,archived:!1,pinned:!1}:t)}},[k.rows,u]),Pe=(0,v.useMemo)(()=>{let e=[];for(let t of Me(ge?.entries??[]))t.kind===`user`&&e.push({entryId:t.entry.id,text:kh(t.entry)});return e},[ge]),Fe=(0,v.useCallback)(e=>{d(e),_(!1)},[]),Ie=(0,v.useCallback)((e,t)=>{Xv(t),w.remember(Kg(e),t),C(e)},[w]),Le=(0,v.useCallback)(e=>{p(t=>{let n=Mg(t,e);return Fg(n),n})},[]),Re=(0,v.useCallback)(()=>{p(null),Fg(null)},[]),ze=(0,v.useRef)(k.rows);ze.current=k.rows;let Be=(0,v.useRef)(Fe);Be.current=Fe,(0,v.useEffect)(()=>{let e=()=>{let e=Wv(Yv());w.remember(Kg(e),Yv()),C(e),e.kind===`chat`&&e.conversationId!==void 0&&ze.current.some(t=>t.id===e.conversationId)&&Be.current(e.conversationId)};return globalThis.addEventListener?.(`popstate`,e),()=>{globalThis.removeEventListener?.(`popstate`,e)}},[w,k.rows,Fe]);let F=(0,v.useCallback)(e=>{let t=e===void 0?{kind:`settings`}:{kind:`settings`,section:e};Xv(Kv(t)),C(t)},[]),Ve=(0,v.useCallback)(e=>{F(e),_(!1)},[F]),He=(0,v.useCallback)(e=>Ve(e),[Ve]),I=(0,v.useCallback)(e=>{if(e===`settings`)F(void 0);else{let t=w.routeFor(e),n=Wv(t);Ie(n,t),n.kind===`chat`&&n.conversationId!==void 0&&Fe(n.conversationId)}y(e=>e+1),_(!1)},[w,Ie,F,Fe]),L=(0,v.useCallback)(()=>I(`settings`),[I]),[Ue,We]=(0,v.useState)(()=>wg()),Ge=(0,v.useCallback)((e,t)=>{We(n=>s.status===`ready`?Dg(Eg(xg(s.meta.extensions),n),e,t):n)},[s]),Ke=(0,v.useMemo)(()=>s.status===`ready`?Eg(xg(s.meta.extensions),Ue):[],[s,Ue]),qe=(0,v.useMemo)(()=>s.status===`ready`?[...yg(s.meta),...Ke]:[],[s,Ke]),Je=x===`blocks`?null:Kg(S),Ye=(0,v.useMemo)(()=>{if(A!==null)return Ke.find(e=>e.slug===A.slug&&e.id===A.id)?.refreshMs},[A,Ke]),Xe=(0,v.useCallback)(e=>{if(`conversation`in e&&typeof e.conversation==`number`){let t={kind:`chat`,conversationId:e.conversation};Ie(t,Kv(t)),Fe(e.conversation);return}if(`job`in e){let t={kind:`ext`,slug:`core`,id:`jobs`,params:{job:e.job}};Ie(t,Kv(t));return}if(`settings`in e){let t=e.settings;Ve(typeof t==`string`&&t!==``?t:void 0);return}if(`view`in e&&e.view!==null&&typeof e.view==`object`){let t=e.view,n={kind:`ext`,slug:t.extension,id:t.id,params:t.params??{}};Ie(n,Kv(n))}},[Ie,Fe,Ve]),Ze=(0,v.useCallback)(e=>{if(e.params!==void 0){if(A===null)return;let t={kind:`ext`,slug:A.slug,id:A.id,params:e.params};Ie(t,Kv(t));return}let t=e.target;typeof t==`object`&&t&&Xe(t)},[A,Ie,Xe]),z=Sv(t,{refetchToken:re}),Qe=(0,v.useRef)(void 0);(0,v.useEffect)(()=>{Qe.current!==void 0&&k.streamId!==void 0&&k.streamId!==Qe.current&&ie(e=>e+1),Qe.current=k.streamId},[k.streamId]),(0,v.useEffect)(()=>{let e=globalThis.document;if(e?.addEventListener===void 0)return;let t=()=>{e.visibilityState===`visible`&&ie(e=>e+1)};return e.addEventListener(`visibilitychange`,t),()=>e.removeEventListener?.(`visibilitychange`,t)},[]);let $e=(0,v.useCallback)(e=>{let t=k.rows.find(t=>t.id===e);return t===void 0?void 0:oe(t)},[k.rows]),et=(0,v.useCallback)(e=>{ce(e??null),S.kind===`chat`?p(`notices`):O(!0)},[S.kind]),tt=(0,v.useCallback)(()=>{S.kind===`chat`?Le(`notices`):O(e=>!e)},[S.kind,Le]),nt=S.kind===`chat`?f===`notices`:ae,rt=(0,v.useCallback)(e=>{let t={kind:`chat`,conversationId:e};Ie(t,Kv(t)),y(e=>e+1),Fe(e)},[Ie,Fe]);(0,v.useEffect)(()=>{if(s.status!==`ready`||u!==null||S.kind!==`chat`)return;if(S.conversationId!==void 0&&k.rows.some(e=>e.id===S.conversationId)){d(S.conversationId);return}if(k.rows.length===0)return;let e=k.rows.find(e=>e.root)??k.rows[0];d(t=>t??e?.id??null)},[s.status,k.rows,S.kind]),(0,v.useEffect)(()=>{let e=!1;return t.getMeta().then(t=>{e||(t.schemaVersion===`79bdfd95541951f9db86236ee2a2f81cce481a5d8688090837a2bdde83d52c97`?c({status:`ready`,meta:t}):c({status:`refused`,message:`schema mismatch: the server speaks schema ${t.schemaVersion} but this webui bundle is pinned to ${$g}. Rebuild and redeploy the bundle against this server (spec §5).`}))}).catch(t=>{if(e)return;let n=t instanceof Error?t.message:String(t);c({status:`refused`,message:`schema check failed: ${n}. The wire schema is unverifiable, so the webui refuses to render (spec §5).`})}),()=>{e=!0}},[t]),(0,v.useEffect)(()=>{let e=globalThis,t=()=>{y(e=>e+1)};return e.addEventListener?.(`hashchange`,t),()=>e.removeEventListener?.(`hashchange`,t)},[]);let it=(0,v.useCallback)(async(e,n)=>{try{await t.patchConversationMeta(e,{name:n}),await k.reload(),ue(null)}catch(e){ue(`rename failed: ${e instanceof Error?e.message:String(e)}`)}},[t,k.reload]),at=(0,v.useCallback)(async e=>{u!==null&&await it(u,e)},[u,it]),B=(0,v.useCallback)(async(e,n)=>{try{await t.patchConversationMeta(e,{archived:n}),await k.reload(),ue(null)}catch(e){ue(`archive failed: ${e instanceof Error?e.message:String(e)}`)}},[t,k.reload]),ot=(0,v.useCallback)(e=>{t.fork(e).then(async e=>{await k.reload(),Fe(e.id),ue(null)}).catch(e=>ue(`fork failed: ${e instanceof Error?e.message:String(e)}`))},[t,k.reload,Fe]),st=(0,v.useCallback)(()=>{t.createConversation().then(async e=>{await k.reload(),Fe(e.id),ue(null)}).catch(e=>ue(`new conversation failed: ${e instanceof Error?e.message:String(e)}`))},[t,k.reload,Fe]),ct=(0,v.useCallback)(()=>{u!==null&&t.exportConversation(u).then(e=>{Vv(`sigrun-conversation-${u}.jsonl`,e),ue(null)}).catch(e=>ue(`export failed: ${e instanceof Error?e.message:String(e)}`))},[u,t]),lt=(0,v.useCallback)(()=>{u!==null&&t.compact(u).then(()=>ue(null)).catch(e=>ue(`compact failed: ${e instanceof Error?e.message:String(e)}`))},[u,t]),ut=k.rows.find(e=>e.id===u)?.archived===!0,dt=(0,v.useCallback)(()=>{u!==null&&B(u,!ut)},[u,ut,B]),ft=r===void 0?void 0:()=>{t.logout().catch(()=>void 0).finally(()=>r())};return s.status===`loading`?(0,R.jsx)(`div`,{className:`app-boot`,children:(0,R.jsx)(`p`,{children:`sigrun — checking the wire schema…`})}):s.status===`restarting`?(0,R.jsx)(`div`,{className:`app-boot`,role:`status`,children:(0,R.jsx)(`p`,{children:`sigrun — Restarting…`})}):s.status===`refused`?(0,R.jsxs)(`div`,{className:`app-refused`,role:`alert`,children:[(0,R.jsx)(`h1`,{children:`sigrun — refusing to render`}),(0,R.jsx)(`p`,{children:s.message})]}):(0,R.jsxs)(`div`,{className:`app-root`,children:[(0,R.jsxs)(`div`,{className:`side-drawer`,"data-open":g?``:void 0,children:[(0,R.jsx)(Ug,{meta:s.meta,onOpenTab:I,activeTab:Je,onOpenGallery:s.meta.dev?()=>{globalThis.history?.pushState(null,``,`#/blocks`),y(e=>e+1)}:void 0,identity:n,hiddenExtSurfaces:ee,extViewEntries:Ke,onMoveExtView:Ge,onLogout:ft,bell:(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})}),k.error!==null&&(0,R.jsxs)(`p`,{className:`side-error`,role:`alert`,children:[`conversations unavailable: `,k.error]}),S.kind===`chat`&&(0,R.jsx)(a_,{rows:k.rows,activeId:u,onSelect:rt,onNew:st,onRename:it,onArchive:B,onFork:ot,currentUser:n?.user,onShare:ne})]}),x===`blocks`?(0,R.jsxs)(`main`,{className:`main-column`,children:[(0,R.jsxs)(`header`,{className:`phone-header`,children:[(0,R.jsx)(`span`,{className:`phone-header-spacer`}),(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})]}),(0,R.jsx)(rg,{})]}):S.kind===`settings`?(0,R.jsxs)(`main`,{className:`main-column`,"data-route":`settings`,children:[(0,R.jsxs)(`header`,{className:`phone-header`,children:[(0,R.jsx)(`span`,{className:`phone-header-spacer`}),(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})]}),(0,R.jsx)(kv,{arrivals:z.arrivals,visibleConversationId:null,run:z.run,dismiss:e=>void z.dismiss(e),onNavigate:Xe,onOpenPane:et}),(0,R.jsx)(V_,{client:t,prefsState:o,theme:a,admin:n?.admin,section:S.section,onSection:He,onRestart:l})]}):(0,R.jsxs)(`main`,{className:`main-column`,children:[(0,R.jsx)(kv,{arrivals:z.arrivals,visibleConversationId:S.kind===`chat`?u:null,run:z.run,dismiss:e=>void z.dismiss(e),onNavigate:Xe,onOpenPane:et}),S.kind===`chat`&&(0,R.jsx)(Ig,{title:Hv(k.rows,u),timeline:m,onTimeline:()=>h(e=>(Bv(!e),!e)),panel:f,extPanels:Sg(s.meta.extensions),onPanel:Le,onRename:at,onExport:ct,onCompact:lt,onArchive:dt,archived:ut,drawerOpen:g,onToggleDrawer:()=>_(e=>!e),bell:(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})}),S.kind!==`chat`&&(0,R.jsxs)(`header`,{className:`phone-header`,children:[(0,R.jsx)(`span`,{className:`phone-header-spacer`}),(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})]}),le!==null&&(0,R.jsx)(`p`,{className:`shell-error`,role:`alert`,children:le}),(0,R.jsxs)(`div`,{className:`main-body`,children:[A!==null&&xe!==void 0?(0,R.jsx)(sg,{slug:A.slug,id:A.id,hub:T,transport:xe,onNavigate:Ze,...Ye===void 0?{}:{refreshMs:Ye}},`${A.slug}/${A.id}/${k.streamId??`pre-hello`}`):S.kind===`chat`?(0,R.jsxs)(`div`,{className:`chat-column`,children:[(0,R.jsx)(Uv,{activeId:u,view:ge,status:_e,error:ve,showThinking:o.prefs.showThinking,timeline:m,client:t,onNavigate:Fe,parent:Ne,onScrollRoot:fe,dockPadding:pe,attachChatTransport:D}),(0,R.jsx)(`div`,{className:`chat-fade`,"aria-hidden":`true`}),(0,R.jsx)(`footer`,{className:`composer-slot`,ref:he,children:(0,R.jsx)(Vm,{client:t,conversationId:u,view:ge,onNavigate:Fe,onOpenSettings:L,enterToSend:o.prefs.enterToSend,readOnly:k.rows.find(e=>e.id===u)?.access===`read`,inlineNotices:u===null?[]:z.notices.filter(e=>e.conversationId===u),noticeResults:z.results,noticeRun:z.run,noticeDismiss:e=>void z.dismiss(e),onOpenNoticesPane:()=>et(),onAmbientNavigate:Xe})})]}):null,S.kind===`chat`&&(0,R.jsx)(Wg,{selection:Se,...N!==null&&Ae!==void 0?{extContent:(0,R.jsx)(cg,{slug:N.slug,id:N.id,transport:Ae,onNavigate:Ze,...je===void 0?{}:{refreshMs:je}},`${Ce}:${we}`)}:{},outline:(0,R.jsx)(Qg,{scrollRoot:de,turns:Pe}),workspace:(0,R.jsx)(Fv,{client:t,conversationId:u,onClose:Re}),notices:(0,R.jsx)(wv,{variant:`docked`,notices:z.notices,results:z.results,conversationName:$e,run:z.run,dismiss:e=>void z.dismiss(e),dismissAll:()=>void z.dismissAll(),onNavigate:e=>{Xe(e),`conversation`in e&&Re()},scrollTo:se})})]})]}),g&&(0,R.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>_(!1),"aria-hidden":`true`}),Se!==null&&Se!==`notices`&&(0,R.jsx)(`div`,{className:`panel-backdrop`,onClick:Re,"aria-hidden":`true`}),S.kind!==`chat`&&ae&&(0,R.jsx)(wv,{variant:`overlay`,notices:z.notices,results:z.results,conversationName:$e,run:z.run,dismiss:e=>void z.dismiss(e),dismissAll:()=>void z.dismissAll(),onClose:()=>O(!1),onNavigate:e=>{Xe(e),O(!1)},scrollTo:se}),(0,R.jsx)(zg,{active:Je??`chats`,extViews:qe,onTab:I,...ft===void 0?{}:{onSignOut:ft}}),te!==null&&(()=>{let e=k.rows.find(e=>e.id===te);return e===void 0?null:(0,R.jsx)(`div`,{className:`share-overlay`,onClick:e=>{e.target===e.currentTarget&&ne(null)},children:(0,R.jsx)(c_,{client:t,conversation:e,onClose:()=>ne(null),onSaved:()=>{k.reload()}})})})()]})}function Qv(e={}){let[t,n]=(0,v.useState)(0);return(0,R.jsx)(Zv,{...e,onRestarting:()=>n(e=>e+1)},t)}var $v={invalid_state:`That sign-in link was already used or came from another browser. Start again.`,login_expired:`This sign-in took too long or sigrun restarted. Start again.`,not_allowed:`Your account isn't allowed to use this sigrun.`,isolation_required:`This sigrun can't add another user yet. Ask the admin.`,auth_required:`This sigrun can't add another user yet. Ask the admin.`,account_link_conflict:`That account is already linked to another sigrun user.`,provider_error:`The sign-in provider returned an error. Try again.`,proxy_identity_required:`This sigrun signs people in through its sign-in proxy. Open it through the proxy.`};function ey(e){return $v[e]??`Sign-in failed. Try again.`}function ty(e){let{client:t,message:n,onSuccess:r}=e,[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(()=>{let e=globalThis.location?.search??``,t=new URLSearchParams(e).get(`error`);return t===null?null:ey(t)}),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)([]);(0,v.useEffect)(()=>{let e=!1;return t.providers().then(t=>{e||d(t.providers)}).catch(()=>{}),()=>{e=!0}},[t]),(0,v.useEffect)(()=>{let e=globalThis.location?.search??``;if(new URLSearchParams(e).get(`error`)===null)return;let t=globalThis.history,n=globalThis.location?.pathname??`/login`;t?.replaceState(null,``,n)},[]);async function f(){if(i.trim()===``){s(`paste your API token`);return}l(!0),s(null);try{await t.login(i.trim()),r()}catch(e){s(o_(e))}finally{l(!1)}}return(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Sign in to sigrun`}),n!==void 0&&(0,R.jsx)(`p`,{className:`auth-message`,children:n}),u.length>0&&(0,R.jsx)(`div`,{className:`auth-providers`,children:u.map(e=>(0,R.jsx)(`a`,{className:`auth-provider`,href:`/v1/auth/login/${encodeURIComponent(e.provider)}?return=%2F`,children:e.label},e.provider))}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`API token`,(0,R.jsx)(`input`,{"data-auth-field":`token`,type:`password`,autoComplete:`current-password`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())}})]}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:c,onClick:()=>void f(),children:c?`Signing in…`:`Sign in`}),o!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:o})]})}function ny(e){return!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`)||/^[A-Za-z][A-Za-z0-9+.-]*:/.test(e)?`/`:e}function ry(e){let{client:t,flowKey:n,reason:r,navigate:i}=e,[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(null);async function d(){if(a.trim()===``){u(`Enter your code.`);return}c(!0),u(null);try{let e=await t.submitLoginCode(n,a.trim());i(ny(e.returnTo))}catch(e){e instanceof x&&e.error===`invalid_code`?u(`That code didn't work. Check it and try again.`):e instanceof x&&e.error===`login_expired`?u(`This sign-in took too long or sigrun restarted. Start again.`):e instanceof x&&e.error===`not_allowed`?u(`Your account isn't allowed to use this sigrun.`):e instanceof x&&(e.error===`isolation_required`||e.error===`auth_required`)?u(`This sigrun can't add another user yet. Ask the admin.`):u(`Sign-in failed. Try again.`)}finally{c(!1)}}return(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Finish signing in`}),(0,R.jsx)(`p`,{className:`auth-message`,children:r===`setup`?`Enter the setup code to claim this sigrun.`:`Enter your invite code to finish signing in.`}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[r===`setup`?`Setup code`:`Invite code`,(0,R.jsx)(`input`,{"data-auth-field":`login-code`,type:`text`,autoComplete:`one-time-code`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),d())}})]}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:s,onClick:()=>void d(),children:s?`Signing in…`:`Continue`}),l!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:l})]})}function iy(e){let{cause:t,context:n}=e,r=e.reload??(()=>location.reload());return(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`proxy-unidentified`,children:(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Sign-in proxy required`}),n===`session_ended`&&(0,R.jsx)(`p`,{className:`auth-message`,children:`Your session ended.`}),t===`unidentified`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`auth-message`,children:`This sigrun runs behind a sign-in proxy, but the proxy's identity didn't reach sigrun.`}),(0,R.jsx)(`p`,{children:`The proxy's address may be missing from trustedProxies, or the proxy may not be forwarding the identity header. The operator can see the reason in the server log.`})]}):t===`invalid_username`?(0,R.jsx)(`p`,{className:`auth-message`,children:`The proxy supplied an invalid username: the proxy's username has no usable characters.`}):(0,R.jsx)(`p`,{className:`auth-message`,children:`Your account doesn't exist and auto-provisioning is off. Ask the admin to create your account.`}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,onClick:r,children:`Reload`})]})})}var ay=w();function oy(e,t){return new Proxy(e,{get(e,n){let r=e[n];return typeof r==`function`?(...n)=>Promise.resolve().then(()=>r.apply(e,n)).catch(e=>{throw e instanceof x&&e.status===401&&t(),e}):r}})}function sy(e={}){let[t,n]=(0,v.useState)({status:`probing`}),[r,i]=(0,v.useState)(0),a=(0,v.useCallback)(()=>{n(e=>e.status===`ready`?b(e.methods)?{status:`proxy-unidentified`,cause:`unidentified`,context:`session_ended`}:{status:`login`,methods:e.methods,message:`Your session ended. Sign in again.`}:e)},[]),o=(0,v.useMemo)(()=>oy(e.client??ay,a),[e.client,a]);if((0,v.useEffect)(()=>{let e=!1;return(async()=>{let t=await o.getOnboarding().catch(t=>{e||n({status:`failed`,message:t instanceof Error?t.message:String(t)})});if(!(t===void 0||e)){if(t.state===`unclaimed`){n({status:`onboarding`,state:t});return}try{let r=await o.whoami();if(e)return;n({status:`ready`,methods:t.methods,identity:r})}catch(r){if(e)return;if(b(t.methods)&&r instanceof x&&r.status===401){n({status:`proxy-unidentified`,cause:`unidentified`,context:`boot`});return}if(b(t.methods)&&r instanceof x&&r.status===403&&(r.error===`invalid_username`||r.error===`user_not_provisioned`)){n({status:`proxy-unidentified`,cause:r.error===`invalid_username`?`invalid_username`:`not_provisioned`,context:`boot`});return}if(r instanceof x&&r.status===401){n({status:`login`,methods:t.methods});return}n({status:`failed`,message:r instanceof Error?r.message:String(r)})}}})(),()=>{e=!0}},[o,r]),t.status===`probing`)return(0,R.jsx)(`div`,{className:`app-boot`,"data-auth-screen":`probing`,children:(0,R.jsx)(`p`,{children:`sigrun — signing in…`})});if(t.status===`failed`)return(0,R.jsxs)(`div`,{className:`app-refused`,role:`alert`,"data-auth-screen":`failed`,children:[(0,R.jsx)(`h1`,{children:`sigrun — auth check failed`}),(0,R.jsx)(`p`,{children:t.message}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e=>e+1),children:`Retry`})]});let s=globalThis.location;if(s?.pathname===`/login/code`){let e=new URLSearchParams(s.search??``),t=e.get(`key`);if(t!==null)return(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`login-code`,children:(0,R.jsx)(ry,{client:o,flowKey:t,reason:e.get(`reason`)??`invite`,navigate:e=>{s.href!==void 0&&(s.href=e)}})})}return t.status===`onboarding`?b(t.state.methods)&&t.state.codeRequired&&t.state.proxyIdentity===void 0?(0,R.jsx)(iy,{cause:`unidentified`,context:`onboarding`}):(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`onboarding`,children:(0,R.jsx)(A_,{client:o,state:t.state,onClaimed:()=>i(e=>e+1)})}):t.status===`proxy-unidentified`?(0,R.jsx)(iy,{cause:t.cause,context:t.context}):t.status===`login`?(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`login`,children:(0,R.jsx)(ty,{client:o,message:t.message,onSuccess:()=>i(e=>e+1)})}):(0,R.jsx)(Qv,{client:o,createEventSource:e.createEventSource,identity:t.identity,onLogout:()=>n({status:`login`,methods:t.methods,message:`Signed out.`})})}var cy=document.getElementById(`root`);if(cy===null)throw Error(`sigrun webui: #root mount point missing from index.html`);(0,y.createRoot)(cy).render((0,R.jsx)(v.StrictMode,{children:(0,R.jsx)(sy,{})}));
55
+ `)}function kh(e){return Ae(e)?.typed??Oh(e)}function Ah(e){let[t,n]=(0,v.useState)(!1),{expanded:r,fullText:i}=e;return(0,R.jsxs)(`div`,{className:`entry-expanded`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`entry-expanded-chip`,"aria-expanded":t,title:t?`Hide the expanded text`:`Show the expanded text`,onClick:()=>n(!t),children:[`expanded from /`,r.command??`…`]}),t&&(0,R.jsx)(`div`,{className:`entry-expanded-text`,children:(0,R.jsx)(md,{source:i,variant:`bubble`})})]})}function jh(e){let{entry:t}=e,n=Ae(t),r=Eh(t),i=r===void 0?void 0:(e.entries??[]).find(e=>e.kind===`sigrun.blocks`&&String(e.id)===r.entryId),a=i===void 0?void 0:Dh(i.data);return(0,R.jsxs)(`div`,{className:`turn turn-user`,"data-turn-kind":`user`,"data-entry-id":t.id,children:[(0,R.jsxs)(`div`,{className:`entry-user`,children:[n===void 0?(t.model??[]).map((e,t)=>(0,R.jsxs)(`div`,{className:`entry-user-message`,children:[(0,R.jsx)(md,{source:Gm(e),variant:`bubble`}),qm(e).map((e,t)=>(0,R.jsxs)(`span`,{className:`entry-attachment`,children:[`[`,e.type,`: `,e.path??`?`,`]`]},t))]},t)):(0,R.jsxs)(`div`,{className:`entry-user-message`,children:[(0,R.jsx)(md,{source:n.typed,variant:`bubble`}),(t.model??[]).flatMap(e=>qm(e).map((e,t)=>(0,R.jsxs)(`span`,{className:`entry-attachment`,children:[`[`,e.type,`: `,e.path??`?`,`]`]},t)))]}),n!==void 0&&(0,R.jsx)(Ah,{expanded:n,fullText:Oh(t)}),r!==void 0&&(0,R.jsxs)(`span`,{className:`entry-answer-chip`,"data-answer-entry":r.entryId,children:[`from `,a??`entry ${r.entryId}`]})]}),(0,R.jsx)(rd,{kind:`user`,text:kh(t),onFork:e.onFork,onEdit:e.onEdit})]})}function Mh(e){return e.docs[`pi.live`]}function Nh(e){return Mh(e)?.tools??[]}function Ph(e){let t=Mh(e)?.generation?.message;if(typeof t==`object`&&t)return t}function Fh(e){return Mh(e)?.compactions?.length??0}function Ih(e){let t=Mh(e)?.compactionFailure;if(typeof t!=`object`||!t)return;let n=t.error;return typeof n==`string`&&n!==``?n:void 0}function Lh(e){return e}function Rh(e){return Nh(Lh(e))}function zh(e){return Ph(Lh(e))}function Bh(e){return Fh(Lh(e))}function Vh(e){return Ih(Lh(e))}var Hh=-1;function Uh(e){let t=e.content;return typeof t==`string`?[]:t.filter(e=>e.type===`toolCall`).map(e=>{let t=e;return{callId:t.id??``,name:t.name??``,preview:Fe(t.name??``,t.arguments),isError:!1}})}function Wh(e,t){return{entries:[{id:Hh,conversationId:e,kind:`pi.assistant`,model:[t]}],thinking:Km(t),tools:Uh(t),text:Gm(t),lastEntryId:Hh,timeline:Gh(t)}}function Gh(e){let t=[];for(let n of Km(e))t.push({kind:`thinking`,text:n});for(let n of Uh(e))t.push({kind:`tool`,tool:n});let n=Gm(e);return n!==``&&t.push({kind:`text`,text:n}),t}function Kh(e){let{view:t,showThinking:n,timeline:r,parent:i,onNavigate:a,client:o}=e,s=t.conversation.id,c=Rh(t),l=zh(t),u=Me(t.entries),d=u[u.length-1],f=l!==void 0&&d!==void 0&&d.kind===`assistant`;if(f&&d!==void 0&&d.kind===`assistant`){let e=Gm(l),t=Uh(l).filter(e=>!d.tools.some(t=>t.callId===e.callId));u[u.length-1]={...d,text:d.text===``?e:`${d.text}\n\n${e}`,thinking:[...d.thinking,...Km(l)],tools:[...d.tools,...t],timeline:[...d.timeline,...Km(l).map(e=>({kind:`thinking`,text:e})),...t.map(e=>({kind:`tool`,tool:e})),...e===``?[]:[{kind:`text`,text:e}]]}}let p=e=>()=>{o.fork(s,e).then(e=>a(e.id)).catch(e=>console.error(`fork from conversation ${s} failed:`,e))};return(0,R.jsxs)(`div`,{className:`turn-list`,children:[i!==void 0&&(0,R.jsxs)(`button`,{type:`button`,className:`turn-lineage`,onClick:()=>a(i.id),children:[`Forked from `,i.name]}),u.map((e,i)=>e.kind===`user`?(0,R.jsx)(qh,{entry:e.entry,entries:t.entries,view:t,client:o,conversationId:s,onNavigate:a,forkFrom:p},e.entry.id):e.kind===`assistant`?(0,R.jsx)(Sh,{conversationId:s,turn:e,slots:c,showThinking:n,client:o,onNavigate:a,live:f&&i===u.length-1,timeline:r},e.lastEntryId):(0,R.jsx)(Jh,{entry:e.entry},e.entry.id)),l!==void 0&&!f&&(0,R.jsx)(Sh,{conversationId:s,turn:Wh(s,l),slots:c,showThinking:n,client:o,onNavigate:a,live:!0},Hh)]})}function qh(e){let{entry:t,entries:n,view:r,client:i,conversationId:a,onNavigate:o,forkFrom:s}=e;return(0,R.jsx)(jh,{entry:t,entries:n,onFork:s(t.id),onEdit:()=>{let e=r.entries[r.entries.findIndex(e=>e.id===t.id)-1];(e===void 0?i.createConversation():i.fork(a,e.id)).then(async e=>{await i.patchConversationMeta(e.id,{draft:{text:kh(t)}}),o(e.id)}).catch(e=>console.error(`edit-in-new-conversation failed:`,e))}})}function Jh(e){let{entry:t}=e,n=t.kind===`pi.compaction`?`compaction`:t.kind===`pi.system`?`system`:`other`;return(0,R.jsx)(`div`,{className:`turn turn-other`,"data-turn-kind":n,children:t.kind===`pi.compaction`?(0,R.jsx)(wh,{entry:t}):t.kind===`pi.system`?(0,R.jsx)(Th,{entry:t}):(0,R.jsxs)(`div`,{className:`entry entry-unknown`,children:[`unsupported entry kind: `,t.kind,` —`,` `,(t.model??[]).map(e=>Gm(e)).filter(e=>e!==``).join(` `)]})})}function Yh(e){let t=hh(e.transport,{onNavigate:e.onNavigate,refreshMs:e.refreshMs,visible:e.visible}),n=e.keepaliveMs,r=e.visible,i=(0,v.useRef)(t.refresh);i.current=t.refresh,(0,v.useEffect)(()=>{if(n===void 0)return;let e=setInterval(()=>{(r===void 0||r())&&i.current()},n),t=globalThis.document,a=()=>{(r===void 0||r())&&i.current()};return t?.addEventListener(`visibilitychange`,a),()=>{clearInterval(e),t?.removeEventListener(`visibilitychange`,a)}},[n,r]);let a=navigator.language,o=(0,v.useMemo)(()=>({dispatch:t.dispatch,access:t.access,rev:t.rev,viewState:typeof t.view.view==`object`&&t.view.view!==null&&!Array.isArray(t.view.view)?t.view.view:{},setView:t.setView,serverErrors:t.serverErrors}),[t.dispatch,t.access,t.rev,t.view,t.setView,t.serverErrors]);return t.status===`loading`?(0,R.jsx)(`div`,{className:`blk-surface`,"data-surface":`loading`,children:(0,R.jsx)(`p`,{children:`loading…`})}):t.status===`notFound`?(0,R.jsx)(`div`,{className:`blk-surface`,"data-surface":`not-found`,children:(0,R.jsx)(`p`,{children:`surface not found`})}):t.status===`error`?(0,R.jsxs)(`div`,{className:`blk-surface`,"data-surface":`error`,role:`alert`,children:[(0,R.jsx)(`p`,{children:`something went wrong`}),(0,R.jsx)(`button`,{type:`button`,"data-surface-retry":``,onClick:()=>t.retry(),children:`Retry`})]}):(0,R.jsx)(`div`,{className:`blk-surface`,"data-surface":`ready`,children:(0,R.jsx)(ze.Provider,{value:{data:t.view,locale:a},children:(0,R.jsxs)(Be.Provider,{value:o,children:[(0,R.jsx)(Xe,{children:t.tree!==void 0&&(0,R.jsx)(Kp,{block:t.tree.root})}),t.toasts.map((e,t)=>(0,R.jsx)(`p`,{className:`blk-surface-toast`,role:`status`,children:e},t))]})})})}var Xh=Object.assign({"../../../test/fixtures/blocks/ambient-footer.json":{v:1,root:{type:`columns`,id:`ambient-footer`,children:[{block:{type:`markdown`,text:`left`}},{block:{type:`stat`,label:`Queue`,value:3}},{block:{type:`markdown`,text:`right`}}]}},"../../../test/fixtures/blocks/ambient-panel.json":{v:1,root:{type:`stack`,id:`ambient-panel`,children:[{type:`collection`,id:`checks`,items:[{id:`c1`,name:`lint`,state:`passed`,busy:!1,tone:`good`},{id:`c2`,name:`tests`,state:`running`,busy:!0,tone:`neutral`}],display:`list`,item:{title:{$:`./name`},status:{label:{$:`./state`},spinner:{$:`./busy`}},tone:{$:`./tone`}}},{type:`log`,lines:[{at:1,level:`info`,text:`3 checks running`},{at:2,level:`error`,text:`rollback failed`}]},{type:`meter`,value:62,format:`percent`},{type:`details`,value:{ok:!0}}]}},"../../../test/fixtures/blocks/ambient-status.json":{v:1,root:{type:`markdown`,id:`ambient-status`,text:`glm-5.3-flash · main* · $0.0421`}},"../../../test/fixtures/blocks/callout.json":{v:1,root:{type:`callout`,id:`callout`,tone:`warn`,title:`Degraded`,body:`acme upstream is slow`,actions:[{id:`open`,label:`Open console`,icon:`external`,action:{type:`open`,url:`https://example.invalid/console`}},{id:`copy`,label:`Copy id`,action:{type:`copy`,text:`acme-42`}}]}},"../../../test/fixtures/blocks/chart.json":{v:1,root:{type:`chart`,id:`chart`,title:`Throughput`,x:{kind:`time`,format:`time`},y:{unit:`req/s`,min:0},series:[{name:`acme`,kind:`area`,data:{$:`/series/acme`}},{name:`Baseline`,kind:`line`,data:[[0,10],[60,12],[120,11]]}],stacked:!1,thresholds:[{at:20,tone:`warn`,label:`SLO`}]}},"../../../test/fixtures/blocks/chat-message.json":{v:1,root:{type:`stack`,id:`chat-message`,children:[{type:`markdown`,text:`acme ranking draft`},{type:`collection`,id:`rank`,items:{$:`/songs`},display:`list`,numbered:!0,reorder:{within:!0},onMove:`reorderSong`,item:{title:{$:`./title`},meta:[{person:{user:`user:example`,name:`Example`}}]}},{type:`form`,id:`use`,bind:`/reply`,mode:`submit`,onSubmit:`useOrder`,submitLabel:`Use this order`,turn:!0,children:[{type:`toggle`,name:`confirm`,label:`Confirm`}]}]}},"../../../test/fixtures/blocks/collection-calendar.json":{v:1,root:{type:`collection`,id:`collection-calendar`,items:{$:`/events`},display:`calendar`,time:{start:`startsAt`,end:`endsAt`,allDay:`allDay`,range:`month`,onResize:`resizeEvent`,onCreate:`createEvent`},item:{title:{$:`./title`}}}},"../../../test/fixtures/blocks/collection-grid.json":{v:1,root:{type:`collection`,id:`collection-grid`,items:{$:`/shots`},display:`grid`,overflow:`wrap`,item:{title:{$:`./title`},image:{$:`./image`}}}},"../../../test/fixtures/blocks/collection-lanes.json":{v:1,root:{type:`collection`,id:`collection-lanes`,items:{$:`/cards`},display:`lanes`,groupBy:`state`,groups:[{id:`todo`,title:`To do`,tone:`neutral`},{id:`doing`,title:`Doing`,tone:`info`,collapsed:!1}],reorder:{within:!0,across:!0},onMove:`moveCard`,onActivate:{type:`navigate`,params:{id:`acme`}},item:{title:{$:`./title`},tone:{$:`./tone`}}}},"../../../test/fixtures/blocks/collection-list.json":{v:1,root:{type:`collection`,id:`collection-list`,items:{$:`/cards`},display:`list`,numbered:!0,checkable:`done`,onCheck:`toggleDone`,children:`subtasks`,item:{eyebrow:{$:`./eyebrow`},title:{$:`./title`},subtitle:{$:`./subtitle`},body:{$:`./body`},icon:`file`,badges:[{text:{$:`./badge`},tone:`info`}],meta:[{icon:`clock`,text:{$:`./when`}},{person:{user:{$:`./user`},name:{$:`./userName`}}},{time:{$:`./at`},format:`datetime`}],metrics:[{label:`Score`,value:{$:`./score`},format:`number`}],tone:`accent`,status:{label:{$:`./state`},tone:`good`,spinner:{$:`./busy`}},quiet:{$:`./quiet`},deps:{$:`./deps`}}}},"../../../test/fixtures/blocks/collection-literal.json":{v:1,root:{type:`collection`,id:`collection-literal`,items:[{id:`row-1`,title:`acme provision`,state:`todo`,quiet:!1},{id:`row-2`,title:`acme build`,state:`doing`,quiet:!0}],display:`list`,item:{title:{$:`./title`},status:{label:{$:`./state`}},quiet:{$:`./quiet`}}}},"../../../test/fixtures/blocks/collection-table.json":{v:1,root:{type:`collection`,id:`collection-table`,items:{$:`/rows`},display:`table`,select:`multi`,sort:{field:`name`,dir:`asc`},bulkActions:[{id:`set-state`,label:`Set state`,icon:`edit`,onSubmit:`setState`,form:{v:1,root:{type:`form`,id:`set-state-form`,bind:`/bulk`,mode:`submit`,onSubmit:`setState`,children:[{type:`text`,name:`state`,label:`State`}]}}}],columns:[{field:`name`,label:`Name`,sortable:!0,priority:`high`},{field:`load`,label:`Load`,format:`percent`,cell:`meter`,priority:`low`},{field:`state`,label:`State`,cell:`badge`,width:`s`}],item:{title:{$:`./name`}}}},"../../../test/fixtures/blocks/columns.json":{v:1,root:{type:`columns`,id:`columns`,children:[{weight:2,minWidth:`m`,block:{type:`markdown`,text:`left`}},{weight:1,block:{type:`stat`,label:`Load`,value:.42,format:`percent`,size:`m`,icon:`clock`}}]}},"../../../test/fixtures/blocks/details.json":{v:1,root:{type:`details`,id:`details`,value:{host:`acme.example`,tags:[`a`,`b`],nested:{ok:!0}}}},"../../../test/fixtures/blocks/diff.json":{v:1,root:{type:`diff`,id:`diff`,before:`const a = 1;`,after:`const a = 2;`,path:`src/acme.ts`,lang:`ts`}},"../../../test/fixtures/blocks/field-choice.json":{v:1,root:{type:`form`,id:`form-choice`,bind:`/values`,mode:`submit`,children:[{type:`choice`,name:`pick`,label:`Pick`,multi:!0,options:[{id:`a`,label:`A`,description:`first`},{id:`b`,label:`B`,tone:`good`}]}]}},"../../../test/fixtures/blocks/field-date.json":{v:1,root:{type:`form`,id:`form-date`,bind:`/values`,mode:`submit`,children:[{type:`date`,name:`on`,label:`On`}]}},"../../../test/fixtures/blocks/field-daterange.json":{v:1,root:{type:`form`,id:`form-daterange`,bind:`/values`,mode:`submit`,children:[{type:`daterange`,name:`range`,label:`Range`,presets:[{id:`today`,label:`Today`,duration:`P1D`}]}]}},"../../../test/fixtures/blocks/field-datetime.json":{v:1,root:{type:`form`,id:`form-datetime`,bind:`/values`,mode:`submit`,children:[{type:`datetime`,name:`at`,label:`At`}]}},"../../../test/fixtures/blocks/field-file.json":{v:1,root:{type:`form`,id:`form-file`,bind:`/values`,mode:`submit`,children:[{type:`file`,name:`logo`,label:`Logo`,accept:`image/png`,multi:!0,onUpload:`uploadLogo`}]}},"../../../test/fixtures/blocks/field-list.json":{v:1,root:{type:`form`,id:`form-list`,bind:`/values`,mode:`submit`,children:[{type:`list`,name:`members`,label:`Members`,item:{type:`text`,name:`name`,label:`Name`},reorder:!0}]}},"../../../test/fixtures/blocks/field-longtext.json":{v:1,root:{type:`form`,id:`form-longtext`,bind:`/values`,mode:`submit`,children:[{type:`longtext`,name:`notes`,label:`Notes`,syntax:`markdown`,lang:`md`,rows:8,maxLength:4e3}]}},"../../../test/fixtures/blocks/field-number.json":{v:1,root:{type:`form`,id:`form-number`,bind:`/values`,mode:`submit`,children:[{type:`number`,name:`port`,label:`Port`,min:1,max:65535,step:1,format:`number`}]}},"../../../test/fixtures/blocks/field-secret.json":{v:1,root:{type:`form`,id:`form-secret`,bind:`/values`,mode:`submit`,children:[{type:`secret`,name:`apiKey`,label:`API key`}]}},"../../../test/fixtures/blocks/field-text.json":{v:1,root:{type:`form`,id:`form-text`,bind:`/values`,mode:`submit`,children:[{type:`text`,name:`name`,label:`Name`,kind:`email`,suggest:{$:`/suggestions`},required:!0,minLength:2,placeholder:`acme@example.invalid`}]}},"../../../test/fixtures/blocks/field-toggle.json":{v:1,root:{type:`form`,id:`form-toggle`,bind:`/values`,mode:`live`,children:[{type:`toggle`,name:`dark`,label:`Dark mode`,disabled:!1}]}},"../../../test/fixtures/blocks/fields.json":{v:1,root:{type:`fields`,id:`fields`,rows:[{label:`Host`,value:`acme.example`},{label:`Errors`,value:2,tone:`bad`,icon:`error`}]}},"../../../test/fixtures/blocks/form-chat.json":{v:1,root:{type:`form`,id:`form-chat`,bind:`/reply`,mode:`submit`,onSubmit:`sendReply`,submitLabel:`Send`,turn:!0,children:[{type:`choice`,name:`answer`,label:`Answer`,options:[{id:`yes`,label:`Yes`,preview:`proceed with the acme plan`},{id:`no`,label:`No`,tone:`bad`}]},{type:`longtext`,name:`reason`,label:`Reason`,syntax:`plain`}]}},"../../../test/fixtures/blocks/form-inline.json":{v:1,root:{type:`form`,id:`form-inline`,bind:`/view/quick`,mode:`inline`,onSubmit:`addQuick`,submitLabel:`Add`,children:[{type:`text`,name:`title`,label:`Title`,placeholder:`new item`,kind:`search`}]}},"../../../test/fixtures/blocks/form-interaction.json":{v:1,root:{type:`form`,id:`form-interaction`,bind:`/values`,mode:`submit`,onSubmit:`answer`,submitLabel:`Answer`,children:[{type:`section`,title:`Approve`,children:[{type:`choice`,name:`verdict`,label:`Verdict`,options:[{id:`allow`,label:`Allow`,tone:`good`,recommended:!0,preview:`run it`},{id:`deny`,label:`Deny`,tone:`bad`}]}]},{type:`longtext`,name:`reason`,label:`Reason`,required:!0},{type:`secret`,name:`token`,label:`Token`,help:`optional`}]}},"../../../test/fixtures/blocks/form-settings.json":{v:1,root:{type:`form`,id:`form-settings`,bind:`/settings`,mode:`submit`,onSubmit:`saveSettings`,children:[{type:`text`,name:`host`,label:`Host`,apply:`live`},{type:`choice`,name:`plan`,label:`Plan`,options:[{id:`basic`,label:`Basic`},{id:`pro`,label:`Pro`,recommended:!0}]},{type:`toggle`,name:`verbose`,label:`Verbose`,apply:`restart`},{type:`date`,name:`since`,label:`Since`},{type:`datetime`,name:`at`,label:`At`,min:0},{type:`daterange`,name:`window`,label:`Window`,presets:[{id:`7d`,label:`Last 7 days`,duration:`P7D`}]},{type:`list`,name:`hosts`,label:`Hosts`,reorder:!0,min:1,max:10,item:{type:`text`,name:`host`,label:`Host`,pattern:`^[a-z].*$`}}]}},"../../../test/fixtures/blocks/form-upload.json":{v:1,root:{type:`form`,id:`form-upload`,bind:`/upload`,mode:`submit`,onSubmit:`saveUpload`,children:[{type:`file`,name:`avatar`,label:`Avatar`,accept:`image/*`,maxBytes:1048576,onUpload:`uploadAvatar`}]}},"../../../test/fixtures/blocks/form-view.json":{v:1,root:{type:`form`,id:`form-view`,bind:`/view/filter`,mode:`live`,children:[{type:`choice`,name:`state`,label:`State`,multi:!1,allowOther:{label:`Other`},options:[{id:`all`,label:`All`,description:`every item`,recommended:!0},{id:`open`,label:`Open`,tone:`info`}]}]}},"../../../test/fixtures/blocks/form.json":{v:1,root:{type:`form`,id:`form`,bind:`/form`,mode:`submit`,onSubmit:`saveForm`,submitLabel:`Save`,children:[{type:`section`,title:`Basics`,children:[{type:`text`,name:`title`,label:`Title`,required:!0,maxLength:80}]},{type:`longtext`,name:`notes`,label:`Notes`,syntax:`markdown`,rows:4,help:`markdown ok`},{type:`number`,name:`retries`,label:`Retries`,min:0,max:5,step:1},{type:`toggle`,name:`enabled`,label:`Enabled`,help:`run the acme loop`}]}},"../../../test/fixtures/blocks/grid.json":{v:1,root:{type:`grid`,id:`grid`,minItemWidth:`m`,children:[{span:2,block:{type:`stat`,label:`Wide`,value:12,sparkline:[1,2,3]}},{block:{type:`stat`,label:`Narrow`,value:3}},{span:`full`,block:{type:`markdown`,text:`full row`}}]}},"../../../test/fixtures/blocks/image.json":{v:1,root:{type:`image`,id:`image`,src:`asset:acme/diagram.png`,alt:`acme cluster diagram`}},"../../../test/fixtures/blocks/interaction-form.json":{v:1,root:{type:`form`,id:`interaction-body`,bind:`/values`,mode:`submit`,onSubmit:`answer`,submitLabel:`Answer`,children:[{type:`section`,title:`Proceed?`,children:[{type:`choice`,name:`proceed`,label:`Proceed`,options:[{id:`yes`,label:`Yes`,tone:`good`,preview:`deploy to acme`},{id:`no`,label:`No`,tone:`bad`}]}]},{type:`text`,name:`note`,label:`Note`}]}},"../../../test/fixtures/blocks/log-literal.json":{v:1,root:{type:`log`,id:`log-literal`,lines:[{at:1,level:`info`,text:`deploy started`},{at:2,level:`warn`,text:`cache cold`},{at:3,level:`error`,text:`rollback failed`}],follow:!0,wrap:!1,tones:{error:`bad`,warn:`warn`,info:`neutral`}}},"../../../test/fixtures/blocks/log.json":{v:1,root:{type:`log`,id:`log`,lines:{$:`/lines`},follow:!0,wrap:!1,tones:{error:`bad`,warn:`warn`,info:`neutral`}}},"../../../test/fixtures/blocks/markdown.json":{v:1,root:{type:`markdown`,id:`markdown`,text:`acme **status** at [example.invalid](https://example.invalid/x)`}},"../../../test/fixtures/blocks/meter-literal.json":{v:1,root:{type:`meter`,id:`meter-literal`,value:.62,min:0,max:1,label:`Disk`,format:`percent`,thresholds:[{at:.8,tone:`warn`},{at:.95,tone:`bad`}]}},"../../../test/fixtures/blocks/meter.json":{v:1,root:{type:`meter`,id:`meter`,value:{$:`/disk`},min:0,max:1,label:`Disk`,format:`percent`,thresholds:[{at:.8,tone:`warn`},{at:.95,tone:`bad`}]}},"../../../test/fixtures/blocks/page-selection.json":{v:1,root:{type:`page`,id:`page`,title:`Jobs`,subtitle:`acme queue`,sidebar:[{type:`collection`,id:`jobs`,items:[{id:`job-1`,title:`acme provision`},{id:`job-2`,title:`acme build`},{id:`job-3`,title:`acme deploy`}],display:`list`,item:{title:{$:`./title`}}}],main:[{type:`markdown`,text:`acme build — the selected job's detail`}],selection:{selected:!0,back:{}}}},"../../../test/fixtures/blocks/page-sidebar.json":{v:1,root:{type:`page`,id:`page`,title:{$:`/title`},subtitle:`with a sidebar`,sidebar:[{type:`tree`,nodes:{$:`/nav`}}],main:[{type:`markdown`,text:`board body`}]}},"../../../test/fixtures/blocks/page.json":{v:1,root:{type:`page`,title:`Jobs`,subtitle:`acme queue`,actions:[{id:`refresh`,label:`Refresh`,icon:`refresh`,action:{type:`edit`,name:`refresh`}}],main:[{type:`section`,title:`Active`,children:[{type:`markdown`,text:`acme jobs run **here**`},{type:`fields`,rows:[{label:`Queue`,value:`acme`},{label:`State`,value:`running`,tone:`info`}]}]}],detail:[{type:`diff`,before:`a`,after:`b`,lang:`ts`},{type:`details`,value:{kind:`acme`,count:3}}],empty:{icon:`check`,title:`All done`,hint:`no pending jobs`},id:`page`}},"../../../test/fixtures/blocks/section.json":{v:1,root:{type:`section`,title:`Group`,subtitle:`subtitle`,tone:`info`,collapsible:!0,collapsed:!1,children:[{type:`markdown`,text:`in section`},{type:`callout`,id:`section-callout`,tone:`warn`,title:`Careful`,body:`acme maintenance at 02:00`,actions:[{id:`ack`,label:`Acknowledge`,action:{type:`edit`,name:`ack`}}]}]}},"../../../test/fixtures/blocks/stack.json":{v:1,root:{type:`stack`,id:`stack`,gap:`m`,visibleAt:`atLeast:regular`,children:[{type:`markdown`,text:`stacked`},{type:`fields`,rows:[{label:`L`,value:1}]}]}},"../../../test/fixtures/blocks/stat-literal.json":{v:1,root:{type:`stat`,id:`stat-literal`,label:`Latency`,value:42,unit:`ms`,format:`number`,tone:`good`,icon:`clock`,size:`l`,caption:`p95 over 5m`,sparkline:[30,42,38,51,44]}},"../../../test/fixtures/blocks/stat.json":{v:1,root:{type:`stat`,id:`stat`,label:`Latency`,value:{$:`/latency`},unit:`ms`,format:`number`,tone:`good`,icon:`clock`,size:`l`,caption:`p95 over 5m`,sparkline:[30,42,38,51,44]}},"../../../test/fixtures/blocks/tree.json":{v:1,root:{type:`tree`,id:`tree`,nodes:{$:`/nodes`},onExpand:`expandNode`,onActivate:{type:`navigate`,params:{node:`acme`}}}}}),Zh=[{id:`card-1`,title:`acme provision`,state:`todo`,done:!1,eyebrow:`acme/queue`,subtitle:`spin the example.invalid runner`,body:`clone the repo, mount the volume`,badge:`queue`,when:`today`,user:`u1`,userName:`acme ops`,at:`2026-10-19T09:00:00Z`,score:3,quiet:!1,busy:!1,deps:[],tone:`info`,subtasks:[]},{id:`card-2`,title:`acme build`,done:!0,eyebrow:`acme/ci`,subtitle:`build the release`,body:`vite build && vitest`,badge:`ci`,when:`yesterday`,user:`acme-ops`,userName:`acme ops`,at:`2026-10-18T17:00:00Z`,score:9,state:`doing`,quiet:!0,busy:!1,deps:[`card-1`],tone:`good`,subtasks:[]},{id:`card-3`,title:`acme deploy`,done:!1,eyebrow:`acme/cd`,subtitle:`ship to example.invalid`,body:`helm upgrade`,badge:`cd`,when:`tomorrow`,user:`acme-cd`,userName:`acme deploy`,at:`2026-10-20T12:00:00Z`,score:5,state:`doing`,quiet:!1,busy:!0,deps:[`card-2`],tone:`warn`,subtasks:[{id:`card-3a`,title:`acme smoke`,done:!1,state:`todo`,subtasks:[]}]}];function Qh(e){let t={cards:Zh,title:`acme board`,nav:[{id:`n1`,label:`Board`,icon:`folder`,children:[{id:`n1a`,label:`Active`}]},{id:`n2`,label:`Archive`,hasChildren:!1}],filter:{state:`open`}};return e===`collection-calendar`?{...t,cards:[{id:`ev-1`,title:`acme sync`,start:`2026-10-19T10:00:00Z`,end:`2026-10-19T11:00:00Z`},{id:`ev-2`,title:`acme review`,start:`2026-10-21T14:00:00Z`,end:`2026-10-21T15:30:00Z`}]}:t}var $h=Object.keys(Xh).filter(e=>e.endsWith(`.json`)).map(e=>{let t=e.slice(e.lastIndexOf(`/`)+1,e.length-5),n=Xh[e];return t===`form-view`?{name:t,tree:{v:1,root:{type:`stack`,children:[n.root,{type:`markdown`,text:"filter.state = `{$}` bound to `/view/filter/state`:"},{type:`markdown`,text:{$:`/view/filter/state`}}]}},data:Qh(t)}:{name:t,tree:n,data:Qh(t)}}).sort((e,t)=>e.name.localeCompare(t.name));function eg(e){let t=1,n=new Set;return{load:async()=>({tree:e.tree,data:e.data,rev:t,treeRev:1,access:`write`}),fetchData:async()=>({rev:t,treeRev:1}),act:async()=>(t+=1,{ok:!0,rev:t}),upload:async()=>(t+=1,{ok:!0,rev:t}),image:async()=>new Uint8Array,onChanged:()=>()=>{n.clear()}}}function tg(e){let t=(0,v.useMemo)(()=>eg(e.sample),[e.sample]);return(0,R.jsxs)(`div`,{className:`gallery-sample`,"data-gallery-sample":e.sample.name,children:[(0,R.jsx)(`h2`,{children:e.sample.name}),(0,R.jsx)(Yh,{transport:t})]})}function ng(){return ig(globalThis.location?.hash??``)}function rg(){let[e,t]=(0,v.useState)(()=>ng());(0,v.useEffect)(()=>{let e=globalThis,n=()=>t(ng());return e.addEventListener?.(`hashchange`,n),()=>e.removeEventListener?.(`hashchange`,n)},[]);let n=e=>{t(e),globalThis.history?.pushState(null,``,`#/blocks/${e}`)},r=$h.find(t=>t.name===e);return(0,R.jsxs)(`div`,{className:`gallery`,"data-gallery":``,children:[(0,R.jsxs)(`aside`,{className:`gallery-list`,children:[(0,R.jsx)(`h1`,{children:`Blocks`}),(0,R.jsx)(`ul`,{children:$h.map(e=>(0,R.jsx)(`li`,{children:(0,R.jsx)(`button`,{type:`button`,"data-gallery-entry":e.name,onClick:()=>n(e.name),children:e.name})},e.name))})]}),(0,R.jsx)(`main`,{className:`gallery-main`,children:r===void 0?(0,R.jsx)(`p`,{className:`gallery-hint`,children:`Pick a block sample — every entry renders through the real renderer over an in-memory surface.`}):(0,R.jsx)(tg,{sample:r})})]})}function ig(e){let t=/^#\/blocks\/(.+)$/.exec(e);return t===null?null:decodeURIComponent(t[1]??``)}var ag=3e5;function og(){return globalThis.document?.visibilityState!==`hidden`}function sg(e){return(0,R.jsx)(`section`,{className:`ext-surface`,"data-ext-surface":`${e.slug}/${e.id}`,children:(0,R.jsx)(Yh,{transport:e.transport,refreshMs:e.refreshMs,keepaliveMs:ag,visible:og,onNavigate:e.onNavigate})})}function cg(e){return(0,R.jsx)(`section`,{className:`ext-panel`,"data-ext-panel":`${e.slug}/${e.id}`,children:(0,R.jsx)(Yh,{transport:e.transport,refreshMs:e.refreshMs,onNavigate:e.onNavigate})})}function lg(e){let t=ug(e);return e.params===void 0||Object.keys(e.params).length===0?t:fg(t,`params`,dg(e))}function ug(e){return`/v1/ext/${encodeURIComponent(e.slug)}/surfaces/${encodeURIComponent(e.id)}`}function dg(e){return encodeURIComponent(JSON.stringify(e.params??{}))}function fg(e,t,n){return`${e}${e.includes(`?`)?`&`:`?`}${t}=${n}`}function pg(e){let t=e.fetch??((e,t)=>globalThis.fetch(e,t)),n=new Set,r=()=>({accept:`application/json`,...e.streamId===void 0?{}:{"x-sigrun-stream":e.streamId}}),i=async e=>{let n=await t(e,{method:`GET`,headers:r()});if(!n.ok)throw Error(`ext surface GET ${e} failed with status ${n.status}`);return await n.json()};return{load(){return i(lg(e))},fetchData(t){let n=fg(`${ug(e)}/data`,`params`,dg(e));return i(t===void 0?n:fg(n,`since`,String(t)))},async act(n){return await(await t(`${ug(e)}/actions`,{method:`POST`,headers:{...r(),"content-type":`application/json`},body:JSON.stringify({...n,params:e.params??{}})})).json()},async upload(n){let i=fg(`${ug(e)}/uploads/${encodeURIComponent(n.field)}/${encodeURIComponent(n.name)}`,`params`,dg(e));return await(await t(i,{method:`PUT`,headers:{...r(),"content-type":`application/octet-stream`},body:n.bytes})).json()},image(){return Promise.reject(Error(`ext surface image route ships with U7`))},onChanged(e){return n.add(e),()=>{n.delete(e)}}}}var mg=class{#e=new Set;attach(e,t){let n=pg(e),r=this;return{load:()=>n.load(),fetchData:e=>n.fetchData(e),act:e=>n.act(e),upload:e=>n.upload(e),image:(e,t)=>n.image(e,t),onChanged(t){let n={slug:e.slug,id:e.id,listener:t};return r.#e.add(n),()=>{r.#e.delete(n)}}}}dispatch(e){for(let t of this.#e)t.slug===e.slug&&t.id===e.id&&t.listener({rev:e.rev,treeRev:e.treeRev})}};function hg(e){return`/v1/conversations/${e.conversationId}/blocks/${encodeURIComponent(e.entryId)}`}function gg(e){let t=e.fetch??((e,t)=>globalThis.fetch(e,t)),n=new Set,r=()=>({accept:`application/json`}),i=async e=>{let n=await t(e,{method:`GET`,headers:r()});if(!n.ok)throw Error(`chat block GET ${e} failed with status ${n.status}`);return await n.json()};return{load(){return i(hg(e))},fetchData(t){let n=`${hg(e)}/data`;return i(t===void 0?n:`${n}?since=${String(t)}`)},async act(n){return await(await t(`${hg(e)}/actions`,{method:`POST`,headers:{...r(),"content-type":`application/json`},body:JSON.stringify(n)})).json()},upload(){return Promise.reject(Error(`chat blocks carry no upload fields`))},image(){return Promise.reject(Error(`chat block image route ships with U7`))},onChanged(e){return n.add(e),()=>{n.delete(e)}}}}var _g=class{#e=new Set;attach(e){let t=gg(e),n=this;return{load:()=>t.load(),fetchData:e=>t.fetchData(e),act:e=>t.act(e),upload:e=>t.upload(e),image:(e,n)=>t.image(e,n),onChanged(t){let r={conversationId:e.conversationId,entryId:e.entryId,listener:t};return n.#e.add(r),()=>{n.#e.delete(r)}}}}dispatch(e){for(let t of this.#e)t.conversationId===e.conversationId&&t.entryId===e.entryId&&t.listener({rev:e.rev,treeRev:e.treeRev??0})}},vg=`sigrun.railOrder`;function yg(e){return(e.coreViews??[]).map(e=>({slug:`core`,id:e.id,title:e.title,icon:e.icon,...e.refreshMs===void 0?{}:{refreshMs:e.refreshMs}}))}function bg(e){return`${e.slug}/${e.id}`}function xg(e){let t=[];for(let n of e)if(n.status===`ok`)for(let e of n.surfaces??[])e.placement===`view`&&t.push({slug:n.name,id:e.id,title:e.title,icon:e.icon,...e.refreshMs===void 0?{}:{refreshMs:e.refreshMs}});return t}function Sg(e){let t=[];for(let n of e)if(n.status===`ok`)for(let e of n.surfaces??[])e.placement===`panel`&&t.push({slug:n.name,id:e.id,title:e.title,icon:e.icon,...e.perConversation===!0?{perConversation:!0}:{}});return t}function Cg(){return globalThis.localStorage}function wg(){try{let e=Cg()?.getItem(vg);if(e==null)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}catch{return[]}}function Tg(e){try{Cg()?.setItem(vg,JSON.stringify(e))}catch{}}function Eg(e,t){let n=new Map(e.map(e=>[bg(e),e])),r=[],i=new Set;for(let e of t){let t=n.get(e);t!==void 0&&!i.has(e)&&(r.push(t),i.add(e))}for(let t of e)i.has(bg(t))||r.push(t);return r}function Dg(e,t,n){let r=e.map(e=>bg(e)),i=r.indexOf(t);if(i===-1)return r;let a=i+n;if(a<0||a>=r.length)return r;let o=[...r];return o[i]=r[a]??``,o[a]=t,Tg(o),o}function Og(e,t){return`ext:${e}/${t}`}var kg=`sigrun.panel`;function Ag(){return globalThis.localStorage}function jg(e){if(e===null)return null;if(e===`outline`||e===`workspace`)return e;if(e.startsWith(`ext:`)){let t=e.slice(4).split(`/`);return t.length===2&&t[0]!==``&&t[1]!==``?e:null}return null}function Mg(e,t){return e===t?null:t}function Ng(e,t){if(e===null||!e.startsWith(`ext:`))return e;let n=e.slice(4);return t.some(e=>bg(e)===n)?e:null}function Pg(){try{return jg(Ag()?.getItem(`sigrun.panel`)??null)}catch{return null}}function Fg(e){if(e!==`notices`)try{Ag()?.setItem(kg,e??`none`)}catch{}}function Ig(e){let{title:t,timeline:n,onTimeline:r,panel:i,onPanel:a,onRename:o,onExport:s,onCompact:c,onArchive:l,archived:u=!1,drawerOpen:d,onToggleDrawer:f}=e,[p,m]=(0,v.useState)(!1),[h,g]=(0,v.useState)(t),[_,y]=(0,v.useState)(!1),b=(0,v.useRef)(null);Em(_,()=>y(!1),b);let x=()=>{g(t),m(!0),y(!1)},S=()=>m(!1),C=()=>{let e=h.trim();if(e===``||e===t){m(!1);return}o(e).then(()=>m(!1),()=>m(!1))},w=e=>()=>{y(!1),e()};return(0,R.jsxs)(`header`,{className:`chat-header`,children:[(0,R.jsx)(`button`,{type:`button`,className:`icon-btn chat-menu-toggle`,title:`Conversations`,"aria-label":`open conversations`,"aria-expanded":d,onClick:f,children:(0,R.jsx)(_m,{})}),p?(0,R.jsx)(`input`,{className:`chat-title-input`,value:h,"aria-label":`conversation name`,autoFocus:!0,onChange:e=>g(e.target.value),onBlur:C,onKeyDown:e=>{e.key===`Enter`?C():e.key===`Escape`&&S()}}):(0,R.jsx)(`button`,{type:`button`,className:`chat-title`,title:t,onClick:x,children:t}),(0,R.jsx)(`span`,{className:`chat-header-spacer`}),(0,R.jsx)(`span`,{className:`chat-header-bell`,children:e.bell}),(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":`timeline`,title:`Chronological view — interleave thinking and tool calls in order instead of folding them under the response`,"aria-label":`chronological view`,"aria-pressed":n,onClick:r,children:`⇅`}),(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":`outline`,title:`Outline`,"aria-label":`outline`,"aria-pressed":i===`outline`,onClick:()=>a(`outline`),children:(0,R.jsx)(vm,{})}),(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":`workspace`,title:`Workspace files`,"aria-label":`workspace`,"aria-pressed":i===`workspace`,onClick:()=>a(`workspace`),children:(0,R.jsx)(ym,{})}),e.extPanels.map(e=>{let t=Og(e.slug,e.id);return(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,"data-panel":t,title:e.title,"aria-label":e.title,"aria-pressed":i===t,onClick:()=>a(t),children:(0,R.jsx)(gd,{name:e.icon,size:16})},t)}),(0,R.jsxs)(`span`,{className:`chat-menu-slot`,ref:b,children:[(0,R.jsx)(`button`,{type:`button`,className:`icon-btn`,title:`More (export, compact, rename, archive)`,"aria-label":`more actions`,"aria-haspopup":`menu`,"aria-expanded":_,onClick:()=>y(e=>!e),children:(0,R.jsx)(xm,{})}),_&&(0,R.jsxs)(`div`,{className:`chat-menu`,role:`menu`,children:[(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`export`,onClick:w(s),children:`Export`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`compact`,onClick:w(c),children:`Compact`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`rename`,onClick:w(x),children:`Rename`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`archive`,onClick:w(l),children:u?`Unarchive`:`Archive`})]})]})]})}function Lg(e){return e===`skills`||e===`jobs`?e:null}function Rg(e){return(0,R.jsxs)(`button`,{type:`button`,className:e.active?`bottom-bar-btn bottom-bar-btn-active`:`bottom-bar-btn`,"data-tab":e.tab,"aria-label":e.title.toLowerCase(),...e.active?{"aria-current":`page`}:{},onClick:t=>{t.preventDefault(),!(e.active&&e.tab!==`more`)&&e.onPress()},children:[e.children,(0,R.jsx)(`span`,{className:`bottom-bar-label`,children:e.title})]})}function zg(e){let[t,n]=(0,v.useState)(!1),r=new Map,i=[];for(let t of e.extViews)t.slug===`core`&&Lg(t.id)!==null?r.set(t.id,t):i.push(t);let a=e.active===`settings`||e.active.startsWith(`ext:`),o=t=>()=>{n(!1),e.onTab(t)};return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`nav`,{className:`bottom-bar`,"aria-label":`sections`,children:[(0,R.jsx)(Rg,{tab:`chats`,title:`Chats`,active:e.active===`chats`,onPress:()=>e.onTab(`chats`),children:(0,R.jsx)(mm,{})}),[`skills`,`jobs`].map(t=>{let n=r.get(t);return n===void 0?null:(0,R.jsx)(Rg,{tab:t,title:n.title,active:e.active===t,onPress:()=>e.onTab(t),children:(0,R.jsx)(gd,{name:n.icon,size:18})},t)}),(0,R.jsx)(Rg,{tab:`more`,title:`More`,active:a,onPress:()=>n(e=>!e),children:(0,R.jsx)(xm,{})})]}),t&&(0,R.jsx)(`div`,{className:`bottom-sheet-backdrop`,onClick:()=>n(!1),children:(0,R.jsxs)(`div`,{className:`bottom-sheet`,role:`dialog`,"aria-label":`More views`,onClick:e=>e.stopPropagation(),children:[i.map(e=>{let t=`ext:${e.slug}/${e.id}`;return(0,R.jsxs)(`button`,{type:`button`,className:`bottom-sheet-item`,"aria-label":e.title.toLowerCase(),onClick:o(t),children:[(0,R.jsx)(gd,{name:e.icon,size:18}),(0,R.jsx)(`span`,{children:e.title})]},`${e.slug}/${e.id}`)}),(0,R.jsxs)(`button`,{type:`button`,className:`bottom-sheet-item`,"aria-label":`settings`,onClick:o(`settings`),children:[(0,R.jsx)(gm,{}),(0,R.jsx)(`span`,{children:`Settings`})]}),e.onSignOut!==void 0&&(0,R.jsxs)(`button`,{type:`button`,className:`bottom-sheet-item`,"aria-label":`sign out`,onClick:()=>{n(!1),e.onSignOut?.()},children:[(0,R.jsx)(Cm,{}),(0,R.jsx)(`span`,{children:`Sign out`})]})]})})]})}function Bg(e){let t=e.extensions.every(e=>e.status===`ok`),n=e.health.memory===`ok`&&e.health.providers===`ok`&&e.health.backup!==`degraded`;return t&&n?`ok`:`degraded`}function Vg(e){return`${e.extensions.length===0?`extensions: none`:`extensions: ${e.extensions.map(e=>`${e.name}: ${e.status}`).join(`; `)}`} · backup: ${e.health.backup}`}function Hg(e){return(0,R.jsx)(`button`,{type:`button`,className:e.active?`rail-btn rail-btn-active`:`rail-btn`,"data-rail-section":e.tab,title:e.title,"aria-label":e.title.toLowerCase(),...e.active?{"aria-current":`page`}:{},onClick:()=>{e.active||e.onOpenTab?.(e.tab)},...e.onKeyDown===void 0?{}:{onKeyDown:e.onKeyDown},children:e.children})}function Ug(e){let{meta:t,identity:n,onLogout:r}=e,{onOpenGallery:i}=e,a=n?.method===`token`||n?.method===`session`,o=e.activeTab===void 0?`chats`:e.activeTab,s=new Set(e.hiddenExtSurfaces??[]),c=(e.extViewEntries??Eg(xg(t.extensions),wg())).filter(e=>!s.has(`${e.slug}/${e.id}`)),l=yg(t);return(0,R.jsxs)(`nav`,{className:`rail`,"aria-label":`sections`,children:[e.bell,(0,R.jsx)(`span`,{className:`rail-brand`,title:`sigrun`,children:(0,R.jsx)(pm,{})}),(0,R.jsx)(Hg,{tab:`chats`,title:`Chats`,active:o===`chats`,onOpenTab:e.onOpenTab,children:(0,R.jsx)(mm,{})}),t.dev&&i!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`rail-btn`,"data-rail-section":`blocks`,title:`Blocks`,"aria-label":`blocks gallery`,onClick:i,children:(0,R.jsx)(hm,{})}),l.map(t=>{let n=`ext:core/${t.id}`;return(0,R.jsx)(Hg,{tab:t.id===`skills`||t.id===`jobs`?t.id:n,title:t.title,active:o===(t.id===`skills`||t.id===`jobs`?t.id:n),onOpenTab:e.onOpenTab,children:(0,R.jsx)(gd,{name:t.icon,size:18})},`core/${t.id}`)}),c.map(t=>{let n=`ext:${t.slug}/${t.id}`,r=o===n;return(0,R.jsx)(Hg,{tab:n,title:t.title,active:r,onOpenTab:e.onOpenTab,onKeyDown:n=>{n.altKey&&(n.key===`ArrowUp`?(n.preventDefault(),e.onMoveExtView?.(`${t.slug}/${t.id}`,-1)):n.key===`ArrowDown`&&(n.preventDefault(),e.onMoveExtView?.(`${t.slug}/${t.id}`,1)))},children:(0,R.jsx)(gd,{name:t.icon,size:18})},`${t.slug}/${t.id}`)}),(0,R.jsx)(`span`,{className:`rail-spacer`}),(0,R.jsx)(`span`,{className:`rail-health`,"data-health":Bg(t),title:Vg(t)}),a&&(0,R.jsx)(`span`,{className:`rail-user`,"data-rail-user":n.user??``,title:n.user===void 0?`signed in`:`signed in as ${n.user}`,children:n.user??`—`}),a&&r!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`rail-btn`,"data-rail-section":`logout`,title:`Sign out`,"aria-label":`sign out`,onClick:r,children:(0,R.jsx)(Cm,{})}),(0,R.jsx)(Hg,{tab:`settings`,title:`Settings`,active:o===`settings`,onOpenTab:e.onOpenTab,children:(0,R.jsx)(gm,{})})]})}function Wg(e){let{selection:t,outline:n,workspace:r,notices:i,extContent:a}=e;if(t===null)return null;let o=t.startsWith(`ext:`);return(0,R.jsx)(`aside`,{className:`right-panel`,"data-panel":o?`ext`:t,"aria-label":`${o?`extension`:t} panel`,children:o?a??null:t===`outline`?n:t===`notices`?i:r})}var Gg=`sigrun.tabs`;function Kg(e){return e.kind===`chat`?`chats`:e.kind===`settings`?`settings`:e.slug===`core`&&e.id===`skills`?`skills`:e.slug===`core`&&e.id===`jobs`?`jobs`:`ext:${e.slug??``}/${e.id??``}`}function qg(e){if(e===`chats`)return`#/c`;if(e===`skills`)return`#/ext/core/skills`;if(e===`jobs`)return`#/ext/core/jobs`;if(e===`settings`)return`#/settings`;let t=/^ext:([^/]+)\/(.+)$/.exec(e);return t===null?`#/c`:`#/ext/${encodeURIComponent(t[1]??``)}/${encodeURIComponent(t[2]??``)}`}function Jg(){return globalThis.sessionStorage}var Yg=class{#e;constructor(){this.#e=new Map;try{let e=Jg()?.getItem(Gg);if(e==null)return;let t=JSON.parse(e);if(typeof t!=`object`||!t||Array.isArray(t))return;for(let[e,n]of Object.entries(t))typeof n==`string`&&this.#e.set(e,n)}catch{}}remember(e,t){this.#e.set(e,t);try{Jg()?.setItem(Gg,JSON.stringify(Object.fromEntries(this.#e)))}catch{}}routeFor(e){return this.#e.get(e)??qg(e)}};function Xg(e){let t=null,n=1/0;for(let[r,i]of e)i.isIntersecting&&i.top<n&&(n=i.top,t=r);return t}function Zg(e,t){if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Qg(e){let{scrollRoot:t,turns:n}=e,[r,i]=(0,v.useState)(null),[a,o]=(0,v.useState)(()=>new Set),s=(0,v.useRef)(null),c=n.map(e=>e.entryId).join(`,`);return(0,v.useEffect)(()=>{i(null)},[t,c]),(0,v.useEffect)(()=>{if(t===null)return;let e=globalThis.IntersectionObserver;if(e===void 0)return;let r=new Map,a=new e(e=>{for(let t of e){let e=t.target,n=Number(e.getAttribute(`data-entry-id`));Number.isFinite(n)&&r.set(n,{isIntersecting:t.isIntersecting,top:e.getBoundingClientRect().top})}i(Xg(r))});for(let e of n){let n=t.querySelector(`[data-entry-id="${e.entryId}"]`);n!==null&&a.observe(n)}return()=>{a.disconnect()}},[t,c]),(0,v.useLayoutEffect)(()=>{let e=s.current;if(e===null)return;let t=()=>{let t=new Set;for(let n of e.querySelectorAll(`.outline-text`)){if(n.scrollHeight<=n.clientHeight+1)continue;let e=n.closest(`.outline-item`),r=Number(e?.getAttribute(`data-entry-id`));Number.isFinite(r)&&t.add(r)}o(e=>Zg(e,t)?e:t)};t();let n=globalThis.ResizeObserver;if(n===void 0)return;let r=new n(t);return r.observe(e),()=>{r.disconnect()}},[t,c]),n.length===0?(0,R.jsxs)(`div`,{className:`right-panel-body outline-body`,children:[(0,R.jsx)(`h4`,{className:`right-panel-title`,children:`Outline`}),(0,R.jsx)(`p`,{className:`outline-empty`,children:`No prompts yet`})]}):(0,R.jsxs)(`div`,{className:`right-panel-body outline-body`,children:[(0,R.jsx)(`h4`,{className:`right-panel-title`,children:`Outline`}),(0,R.jsx)(`nav`,{className:`outline`,"aria-label":`conversation outline`,ref:s,children:n.map(e=>(0,R.jsx)(`button`,{type:`button`,className:`outline-item`,"data-entry-id":e.entryId,"data-clamped":a.has(e.entryId)?`true`:void 0,title:e.text,"aria-current":r===e.entryId?`true`:void 0,onClick:()=>{t?.querySelector(`[data-entry-id="${e.entryId}"]`)?.scrollIntoView({behavior:`smooth`,block:`start`})},children:(0,R.jsx)(`span`,{className:`outline-text`,children:e.text})},e.entryId))})]})}var $g=`79bdfd95541951f9db86236ee2a2f81cce481a5d8688090837a2bdde83d52c97`,e_=`sigrun-session-search`,t_=[`Pinned`,`Today`,`Yesterday`,`Earlier`];function n_(){(globalThis.document?.getElementById(e_))?.focus()}function r_(e,t){let n=new Set,r=new Map(e.map(e=>[e.id,e]));for(let i of e){if(!oe(i).toLowerCase().includes(t))continue;let e=i;for(;e!==void 0&&!n.has(e.id);)n.add(e.id),e=e.parent===void 0?void 0:r.get(e.parent.id)}return n}function i_(e,t){let n=[];for(let r of t_){let i=e.filter(e=>te(e,t)===r);if(i.length===0)continue;n.push({kind:`heading`,group:r});let a=(e,t)=>{n.push({kind:`row`,node:e,depth:t});for(let n of e.children)a(n,t+1)};for(let e of i)a(e,0)}return n}function a_(e){let{rows:t,activeId:n,onSelect:r,onNew:i,onRename:a,onArchive:o,onFork:s,currentUser:c,onShare:l}=e,[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),[m,h]=(0,v.useState)(null),g=(0,v.useRef)(null);Em(m!==null,()=>h(null),g);let[_,y]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=globalThis.window;if(e===void 0)return;let t=e=>{(e.ctrlKey||e.metaKey)&&(e.key===`k`||e.key===`K`)&&(e.preventDefault(),n_())};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[]);let b=new Date,x=(0,v.useMemo)(()=>{let e=u.trim().toLowerCase(),n=r_(t,e);return i_(D(e===``?t:t.filter(e=>n.has(e.id)),{includeArchived:f}),b)},[t,u,f,b.getTime()]),S=e=>{if(_===null||_.id!==e)return;let n=t.find(t=>t.id===e),r=_.draft.trim();if(n===void 0||r===``||r===oe(n)){y(null);return}a(e,r).then(()=>y(null),()=>y(null))};return(0,R.jsxs)(`nav`,{className:`session-list`,"aria-label":`conversations`,children:[(0,R.jsxs)(`div`,{className:`session-search-row`,children:[(0,R.jsx)(`input`,{id:e_,className:`session-search`,type:`search`,placeholder:`Search`,"aria-label":`search conversations`,value:u,onChange:e=>d(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`session-new`,title:`New conversation`,"aria-label":`new conversation`,onClick:i,children:(0,R.jsx)(bm,{})})]}),(0,R.jsxs)(`ul`,{children:[x.map(e=>{if(e.kind===`heading`)return(0,R.jsx)(`li`,{className:`session-group`,"data-age-group":e.group,children:e.group},`group-${e.group}`);let{node:t,depth:i}=e,a=t.row,u=oe(a),d=_!==null&&_.id===a.id,f=l!==void 0&&c!==void 0&&a.owner===c,p=[`session-item`,a.id===n?`session-item-active`:``,a.archived?`session-item-archived`:``].filter(Boolean).join(` `);return(0,R.jsxs)(`li`,{className:p,"data-conversation-id":a.id,"data-depth":i,style:i===0?void 0:{paddingLeft:6+i*14},children:[i>0&&(0,R.jsx)(`span`,{className:`session-fork-mark`,"aria-hidden":`true`,children:`↳`}),d?(0,R.jsx)(`input`,{className:`session-rename-input`,"aria-label":`conversation name`,value:_.draft,onChange:e=>y({id:a.id,draft:e.target.value}),onKeyDown:e=>{e.key===`Enter`?S(a.id):e.key===`Escape`&&y(null)}}):(0,R.jsx)(`button`,{type:`button`,className:`session-select`,title:u,onClick:()=>r(a.id),children:(0,R.jsx)(`span`,{className:`session-name`,children:u})}),(0,R.jsx)(`span`,{className:`session-age`,children:ae(a.lastActivityAt,b)}),(0,R.jsxs)(`span`,{className:`session-row-actions`,ref:m===a.id?g:void 0,children:[(0,R.jsx)(`button`,{type:`button`,className:`session-menu-toggle`,"aria-label":`actions for ${u}`,"aria-haspopup":`menu`,"aria-expanded":m===a.id,onClick:()=>h(m===a.id?null:a.id),children:(0,R.jsx)(xm,{})}),m===a.id&&(0,R.jsxs)(`div`,{className:`session-menu`,role:`menu`,children:[f&&(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`share`,onClick:()=>{h(null),l?.(a.id)},children:`Share…`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`rename`,onClick:()=>{h(null),y({id:a.id,draft:u})},children:`Rename`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`fork`,onClick:()=>{h(null),s(a.id)},children:`Fork`}),(0,R.jsx)(`button`,{type:`button`,role:`menuitem`,"data-menu-action":`archive`,onClick:()=>{h(null),o(a.id,!a.archived)},children:a.archived?`Unarchive`:`Archive`})]})]})]},a.id)}),x.length===0&&u.trim()!==``&&(0,R.jsx)(`li`,{className:`session-empty`,children:`No matching conversations`})]}),(0,R.jsx)(`button`,{type:`button`,className:`session-archived-toggle`,"aria-pressed":f,title:`Show archived conversations`,onClick:()=>p(e=>!e),children:`Archived`})]})}function o_(e){if(e instanceof x){let t={proxy_identity_required:`This sigrun signs people in through its sign-in proxy. Open it through the proxy.`,username_taken:`That username is taken. Choose another.`,invalid_username:`That name has no usable characters — use at least one letter or digit.`},n=e.error??``;if(Object.hasOwn(t,n))return t[n];if(e.error!==void 0)return e.error}return e instanceof Error?e.message:String(e)}function s_(e){return e.split(/[\s,]+/).map(e=>e.trim()).filter(e=>e!==``)}function c_(e){let{client:t,conversation:n,onClose:r,onSaved:i}=e,a=n.sharing,[o,s]=(0,v.useState)(a?.scope??`private`),[c,l]=(0,v.useState)(a?.scope===`household`||a?.scope===`people`?a.level:`read`),[u,d]=(0,v.useState)(a?.scope===`people`?a.users.join(`, `):``),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1);async function g(e){h(!0),p(null);try{await t.patchConversationMeta(n.id,{sharing:e}),await i()}catch(e){p(o_(e))}finally{h(!1)}}function _(e){m||(s(e),e===`private`?g({scope:`private`}):e===`household`&&g({scope:`household`,level:c}))}function y(e){m||(l(e),o===`household`&&g({scope:`household`,level:e}))}function b(){if(m)return;let e=s_(u);if(e.length===0){p(`enter at least one username to share with`);return}g({scope:`people`,users:e,...a?.scope===`people`&&a.groups!==void 0?{groups:[...a.groups]}:{},level:c})}return(0,R.jsxs)(`div`,{className:`share-menu`,role:`dialog`,"aria-label":`share conversation`,children:[(0,R.jsxs)(`div`,{className:`share-head`,children:[(0,R.jsx)(`h2`,{children:`Share`}),(0,R.jsx)(`button`,{type:`button`,className:`share-close`,"aria-label":`close share dialog`,onClick:r,children:`Close`})]}),(0,R.jsxs)(`div`,{className:`share-scopes`,children:[(0,R.jsxs)(`button`,{type:`button`,className:`share-scope`,"data-share-scope":`private`,"data-selected":o===`private`||void 0,"aria-pressed":o===`private`,disabled:m,onClick:()=>_(`private`),children:[`Private`,(0,R.jsx)(`span`,{className:`share-scope-hint`,children:`only you`})]}),(0,R.jsxs)(`button`,{type:`button`,className:`share-scope`,"data-share-scope":`household`,"data-selected":o===`household`||void 0,"aria-pressed":o===`household`,disabled:m,onClick:()=>_(`household`),children:[`Household`,(0,R.jsx)(`span`,{className:`share-scope-hint`,children:`everyone signed in`})]}),(0,R.jsxs)(`button`,{type:`button`,className:`share-scope`,"data-share-scope":`people`,"data-selected":o===`people`||void 0,"aria-pressed":o===`people`,disabled:m,onClick:()=>_(`people`),children:[`People`,(0,R.jsx)(`span`,{className:`share-scope-hint`,children:`named users`})]})]}),o!==`private`&&(0,R.jsxs)(`div`,{className:`share-level`,role:`group`,"aria-label":`access level`,children:[(0,R.jsx)(`button`,{type:`button`,className:`share-level-btn`,"data-share-level":`read`,"data-selected":c===`read`||void 0,"aria-pressed":c===`read`,disabled:m,onClick:()=>y(`read`),children:`Can view`}),(0,R.jsx)(`button`,{type:`button`,className:`share-level-btn`,"data-share-level":`write`,"data-selected":c===`write`||void 0,"aria-pressed":c===`write`,disabled:m,onClick:()=>y(`write`),children:`Can edit`})]}),o===`people`&&(0,R.jsxs)(`label`,{className:`share-field`,children:[`Usernames`,(0,R.jsx)(`input`,{"data-share-field":`users`,placeholder:`carol, dave`,value:u,onChange:e=>d(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:m,onClick:b,children:`Share with people`})]}),o!==`private`&&c===`write`&&(0,R.jsx)(`p`,{className:`share-warning`,role:`alert`,children:`Others can ask the agent to act as you.`}),f!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:f})]})}var l_=5e3,u_=2,d_=5e3,f_=6e4;function p_(e,t,n,r,i,a){if(i===void 0&&globalThis.EventSource===void 0)return()=>{};let o=()=>i===void 0?new EventSource(`/v1/events`):i(`/v1/events`),s,c,l=d_,u=!1,d=()=>{let e=o();s=e,f(e),e.addEventListener(`hello`,()=>{l=d_}),e.addEventListener(`error`,()=>{u||e.readyState!==u_||c===void 0&&s===e&&(e.close(),c=setTimeout(()=>{c=void 0,u||d()},l),l=Math.min(l*2,f_))})};return d(),()=>{u=!0,c!==void 0&&clearTimeout(c),s?.close()};function f(i){let o=()=>e();i.addEventListener(`conversation.created`,o),i.addEventListener(`conversation.changed`,o),i.addEventListener(`surface.changed`,e=>{try{let t=JSON.parse(e.data);if(typeof t==`object`&&t&&typeof t.conversationId==`number`&&typeof t.entryId==`string`&&typeof t.rev==`number`){r?.(t);return}}catch{}if(n!==void 0)try{let t=JSON.parse(e.data);typeof t==`object`&&t&&typeof t.slug==`string`&&typeof t.id==`string`&&typeof t.k==`string`&&typeof t.rev==`number`&&typeof t.treeRev==`number`&&n(t)}catch{}}),a!==void 0&&i.addEventListener(`notice.changed`,()=>a()),i.addEventListener(`hello`,e=>{try{let n=JSON.parse(e.data);typeof n==`object`&&n&&typeof n.streamId==`string`&&t(n.streamId)}catch{}})}}function m_(e,t){let n=t.busy,[r,i]=(0,v.useState)([]),[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(void 0),l=(0,v.useRef)(void 0),u=(0,v.useRef)(new Set),d=(0,v.useCallback)(async()=>{try{let t=await e.listConversations();i(t.conversations),o(null)}catch(e){o(e instanceof Error?e.message:String(e))}},[e]),f=(0,v.useCallback)(async(e,n,r)=>{let i=l.current;return(await(t.fetchImpl??fetch)(r===void 0||Object.keys(r).length===0?`/v1/ext/${e}/surfaces/${n}`:`/v1/ext/${e}/surfaces/${n}?params=${encodeURIComponent(JSON.stringify(r))}`,{headers:i===void 0?{accept:`application/json`}:{accept:`application/json`,"x-sigrun-stream":i}})).json()},[t.fetchImpl]),p=(0,v.useCallback)((e,t,n)=>{let r=n===void 0?`{}`:Ee(n);u.current.add(`${e}\u0001${t}\u0001${r}`)},[]),m=(0,v.useCallback)(e=>{let t=l.current;if(l.current=e,c(e),t!==void 0&&t!==e){d();for(let e of u.current){let[t,n,r]=e.split(``),i;if(r!==void 0&&r!==`{}`)try{let e=JSON.parse(r);typeof e==`object`&&e&&!Array.isArray(e)&&(i=e)}catch{}f(t??``,n??``,i)}}},[f,d]);(0,v.useEffect)(()=>{d()},[d]),(0,v.useEffect)(()=>{let e=globalThis.document;if(e?.addEventListener===void 0)return;let t=()=>{e.visibilityState===`visible`&&d()};return e.addEventListener(`visibilitychange`,t),()=>e.removeEventListener?.(`visibilitychange`,t)},[d]),(0,v.useEffect)(()=>p_(()=>{d()},m,t.onSurfaceChanged,t.onChatChanged,t.createEventSource,t.onNoticeChanged),[d,m,t.createEventSource,t.onSurfaceChanged,t.onChatChanged,t.onNoticeChanged]);let h=(0,v.useRef)(n);return(0,v.useEffect)(()=>{let e=h.current;if(h.current=n,!e||n)return;d();let t=setTimeout(()=>void d(),l_);return()=>clearTimeout(t)},[n,d]),{rows:r,reload:d,error:a,streamId:s,fetchSurface:f,noteSurfaceVisible:p}}var h_={fjord:{label:`Fjord`,defaultAccent:`baltic-amber`,dark:{bg:`#0b0f13`,surface:`#11171e`,surface2:`#18202a`,border:`#222d39`,text:`#dde6ee`,muted:`#8d9cab`,faint:`#5f6e7d`,ok:`#7fbf9a`,code:`rgba(255,255,255,.06)`},light:{bg:`#eef2f5`,surface:`#ffffff`,surface2:`#e3e9ef`,border:`#d3dbe3`,text:`#18212a`,muted:`#4d5b69`,faint:`#8593a1`,ok:`#2f8a5a`,code:`rgba(0,0,0,.05)`}},"iron-ember":{label:`Iron & Ember`,defaultAccent:`ember`,dark:{bg:`#0e0e0f`,surface:`#161618`,surface2:`#1e1e21`,border:`#2a2a2e`,text:`#e6e1da`,muted:`#9a958e`,faint:`#66625d`,ok:`#8fb58a`,code:`rgba(255,255,255,.06)`},light:{bg:`#f3f1ee`,surface:`#fbfaf8`,surface2:`#e9e6e1`,border:`#dbd7d1`,text:`#1c1b1a`,muted:`#55524d`,faint:`#8e8a84`,ok:`#3e7a3a`,code:`rgba(0,0,0,.05)`}},"polar-night":{label:`Polar Night`,defaultAccent:`aurora`,dark:{bg:`#090d16`,surface:`#0f1524`,surface2:`#161e31`,border:`#1f2942`,text:`#e2e8f3`,muted:`#8e9ab2`,faint:`#5d6984`,ok:`#5fd4a8`,code:`rgba(255,255,255,.06)`},light:{bg:`#f0f3f9`,surface:`#ffffff`,surface2:`#e4e9f3`,border:`#d2d9e6`,text:`#141b2b`,muted:`#4b5670`,faint:`#8691a8`,ok:`#13866a`,code:`rgba(0,0,0,.05)`}},"birch-moss":{label:`Birch & Moss`,defaultAccent:`lichen`,dark:{bg:`#0d100d`,surface:`#141a15`,surface2:`#1b221c`,border:`#263027`,text:`#e8e6dc`,muted:`#9ba091`,faint:`#666d60`,ok:`#9cc48a`,code:`rgba(255,255,255,.06)`},light:{bg:`#f3f2ea`,surface:`#fbfbf6`,surface2:`#e7e7dc`,border:`#d8d8ca`,text:`#1b1e18`,muted:`#525849`,faint:`#8b9080`,ok:`#4a7a35`,code:`rgba(0,0,0,.05)`}}},g_={"baltic-amber":{label:`Baltic Amber`,dark:`#d6a24a`,light:`#a8741f`},ember:{label:`Ember`,dark:`#d9773a`,light:`#b8571c`},lingonberry:{label:`Lingonberry`,dark:`#d0606a`,light:`#a83440`},glacier:{label:`Glacier`,dark:`#8fb8d0`,light:`#2f6f93`},aurora:{label:`Aurora`,dark:`#5fd4a8`,light:`#13866a`},lichen:{label:`Lichen`,dark:`#b9c46a`,light:`#6f7a1f`},heather:{label:`Heather`,dark:`#a993c9`,light:`#6c4f99`}},__=[`fjord`,`iron-ember`,`polar-night`,`birch-moss`],v_=[`baltic-amber`,`ember`,`lingonberry`,`glacier`,`aurora`,`lichen`,`heather`],y_=`polar-night`,b_=`baltic-amber`;function x_(e){return typeof e==`string`&&Object.prototype.hasOwnProperty.call(h_,e)}function S_(e){return typeof e==`string`&&Object.prototype.hasOwnProperty.call(g_,e)}function C_(e){let{client:t}=e,[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)(null),[c,l]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1;return Promise.all([t.accounts(),t.providers()]).then(([t,n])=>{e||(r(t.accounts),a(n.providers))}).catch(t=>{e||s(o_(t))}),()=>{e=!0}},[t]);async function u(e){l(`${e.provider}\u0000${e.subject}`),s(null);try{await t.removeAccount(e.provider,e.subject),r(t=>t?.filter(t=>t.provider!==e.provider||t.subject!==e.subject)??null)}catch(e){s(o_(e))}finally{l(null)}}return n===null?(0,R.jsx)(`p`,{className:`settings-note`,role:o===null?void 0:`alert`,children:o??`loading account links…`}):(0,R.jsxs)(`div`,{className:`settings-body`,"data-settings-section":`accounts`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`External identities linked to your sigrun account.`}),o!==null&&(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:o}),n.length===0&&(0,R.jsx)(`p`,{className:`settings-note`,children:`No account links.`}),n.map(e=>(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsxs)(`span`,{className:`settings-ext-key`,children:[i.find(t=>t.provider===e.provider)?.label??e.provider,` · `,e.subject]}),(0,R.jsx)(`button`,{type:`button`,className:`account-remove`,disabled:c!==null,onClick:()=>void u(e),children:`Remove`})]},`${e.provider}\u0000${e.subject}`)),i.length>0&&(0,R.jsxs)(`div`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Connect an account`}),i.map(e=>(0,R.jsx)(`a`,{className:`account-connect`,href:`/v1/auth/login/${encodeURIComponent(e.provider)}?link=1&return=%2Fsettings%3Fsection%3Daccounts`,children:`Connect`},e.provider))]})]})}function w_(e){let{client:t}=e,[n,r]=(0,v.useState)({status:`loading`}),[i,a]=(0,v.useState)({});(0,v.useEffect)(()=>{let e=!1;return t.listProviders().then(t=>{e||r({status:`ready`,providers:t.providers})}).catch(t=>{e||r({status:`error`,message:t instanceof Error?t.message:String(t)})}),()=>{e=!0}},[t]);let o=e=>{r(t=>t.status===`ready`?{status:`ready`,providers:t.providers.map(t=>t.provider===e.provider?e:t)}:t)},s=(e,t)=>{a(n=>({...n,[e]:{key:``,...n[e],...t}}))},c=async e=>{let n=i[e];if(n!==void 0&&n.key!==``)try{o(await t.putProviderCredential(e,n.key)),s(e,{key:``,note:{kind:`ok`,message:`saved`}})}catch(t){s(e,{note:{kind:`error`,message:t instanceof Error?t.message:String(t)}})}},l=async e=>{try{o(await t.deleteProviderCredential(e)),s(e,{note:{kind:`ok`,message:`cleared`}})}catch(t){s(e,{note:{kind:`error`,message:t instanceof Error?t.message:String(t)}})}},u=async e=>{try{o(await t.refreshProvider(e))}catch(t){s(e,{note:{kind:`error`,message:t instanceof Error?t.message:String(t)}})}};return n.status===`loading`?(0,R.jsx)(`p`,{className:`settings-note`,children:`loading providers…`}):n.status===`error`?(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:n.message}):n.providers.length===0?(0,R.jsx)(`div`,{className:`settings-body`,children:(0,R.jsx)(`p`,{className:`settings-note`,children:`no providers are loaded`})}):(0,R.jsxs)(`div`,{className:`settings-body settings-provider-list`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`readiness and credentials per provider — the key field is write-only (the server never returns it); saving applies immediately, no restart`}),n.providers.map(e=>{let t=i[e.provider]??{key:``};return(0,R.jsxs)(`fieldset`,{className:`settings-provider`,"data-provider":e.provider,children:[(0,R.jsxs)(`legend`,{className:`settings-provider-name`,children:[e.provider,(0,R.jsx)(`span`,{className:`settings-provider-status`,"data-status":e.status,children:e.status}),(0,R.jsxs)(`span`,{className:`settings-provider-meta`,children:[e.models,` model`,e.models===1?``:`s`]})]}),e.detail!==void 0&&(0,R.jsx)(`p`,{className:`settings-note`,children:e.detail}),(0,R.jsxs)(`div`,{className:`settings-provider-row`,children:[(0,R.jsx)(`input`,{type:`password`,className:`settings-provider-key`,placeholder:`api key`,value:t.key,autoComplete:`off`,onChange:t=>s(e.provider,{key:t.target.value})}),(0,R.jsx)(`button`,{type:`button`,className:`settings-provider-save`,disabled:t.key===``,onClick:()=>void c(e.provider),children:`Save`}),(0,R.jsx)(`button`,{type:`button`,className:`settings-provider-clear`,onClick:()=>void l(e.provider),children:`Clear`}),(0,R.jsx)(`button`,{type:`button`,className:`settings-provider-refresh`,onClick:()=>void u(e.provider),children:`Refresh`}),t.note!==void 0&&(0,R.jsx)(`span`,{className:`settings-note`,role:t.note.kind===`ok`?`status`:`alert`,children:t.note.message})]})]},e.provider)})]})}var T_=/\p{M}/gu,E_=/@/g,D_=/[^a-z0-9._-]/g,O_=/^[^a-z0-9]+/;function k_(e){let t=e.normalize(`NFKD`).replace(T_,``).toLowerCase().replace(E_,`_`).replace(D_,`-`).replace(O_,``).slice(0,128);return t===``?void 0:t}function A_(e){let{client:t,state:n,onClaimed:r}=e,[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(``),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1),g=n.proxyIdentity,_=o.trim(),y=_===``?void 0:k_(_),b=_!==``&&y===void 0;async function x(){h(!0),p(null);try{await t.claim({}),r()}catch(e){p(o_(e))}finally{h(!1)}}async function S(){let e=o.trim();if(n.codeRequired&&i.trim()===``){p(`enter the setup code (find it in the server log)`);return}if(e===``){p(`choose a username`);return}h(!0),p(null);try{await t.claim({...n.codeRequired?{code:i.trim()}:{},user:e,...c.trim()===``?{}:{name:c.trim()},...u.trim()===``?{}:{email:u.trim()},issueToken:!0,tokenName:`webui`}),r()}catch(e){p(o_(e))}finally{h(!1)}}return(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Set up sigrun`}),g===void 0?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`auth-message`,children:`Claim this server: the first user is its administrator.`}),n.codeRequired&&(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Setup code`,(0,R.jsx)(`input`,{"data-auth-field":`code`,autoComplete:`one-time-code`,value:i,onChange:e=>a(e.target.value)})]}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Username`,(0,R.jsx)(`input`,{"data-auth-field":`user`,autoComplete:`username`,value:o,onChange:e=>s(e.target.value)})]}),b?(0,R.jsx)(`p`,{className:`auth-message`,"data-auth-preview":`invalid`,children:`Your username needs at least one letter or digit.`}):y===void 0?null:(0,R.jsxs)(`p`,{className:`auth-message`,"data-auth-preview":`user`,children:[`Your username will be `,(0,R.jsx)(`strong`,{children:y})]}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Name `,(0,R.jsx)(`span`,{className:`auth-optional`,children:`(optional)`}),(0,R.jsx)(`input`,{"data-auth-field":`name`,autoComplete:`name`,value:c,onChange:e=>l(e.target.value)})]}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`Email `,(0,R.jsx)(`span`,{className:`auth-optional`,children:`(optional)`}),(0,R.jsx)(`input`,{"data-auth-field":`email`,type:`email`,autoComplete:`email`,value:u,onChange:e=>d(e.target.value)})]}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:m||b,onClick:()=>void S(),children:m?`Claiming…`:`Set up sigrun`})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`auth-message`,children:`Your proxy vouches for your identity. Continuing claims this server as:`}),(0,R.jsxs)(`p`,{className:`auth-identity`,children:[(0,R.jsx)(`strong`,{children:g.user}),g.name===void 0?``:` — ${g.name}`,g.email===void 0?``:` · ${g.email}`]}),g.subject!==g.user&&(0,R.jsx)(`p`,{className:`auth-message`,"data-auth-proxy":`subject`,children:g.subject}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:m,onClick:()=>void x(),children:`Continue as ${g.user}`})]}),f!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:f})]})}function j_(e){let{client:t}=e,[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(``),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1),g=(0,v.useRef)(null);(0,v.useEffect)(()=>()=>{g.current!==null&&clearTimeout(g.current)},[]),(0,v.useEffect)(()=>{let e=!1;return t.listTokens().then(t=>{e||r(t)}).catch(t=>{e||a(o_(t))}),()=>{e=!0}},[t]);async function _(){if(!(o.trim()===``||c)){l(!0),a(null);try{let e=await t.createToken(o.trim());d({id:e.record.id,token:e.token,name:e.record.name}),r(t=>t===null?t:[...t,e.record]),s(``)}catch(e){a(o_(e))}finally{l(!1)}}}async function y(e){if(!(f===null||c)){l(!0),a(null);try{await t.revokeToken(e),r(t=>t===null?t:t.filter(t=>t.id!==e)),d(t=>t?.id===e?null:t),p(null)}catch(e){a(o_(e))}finally{l(!1)}}}function b(){u!==null&&(nd(u.token),h(!0),g.current!==null&&clearTimeout(g.current),g.current=setTimeout(()=>h(!1),1500))}if(n===null)return(0,R.jsx)(`p`,{className:`settings-note`,role:i===null?void 0:`alert`,children:i??`loading tokens…`});let x=n.filter(e=>e.kind!==`session`),S=globalThis.location?.origin??``,C=S===``?`<your sigrun URL>`:S;return(0,R.jsxs)(`div`,{className:`settings-body`,"data-settings-section":`tokens`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`Bearer tokens for the CLI, scripts, and sign-in. A token is shown once at creation — the server stores only its digest.`}),i!==null&&(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:i}),u!==null&&(0,R.jsxs)(`fieldset`,{className:`settings-field token-reveal`,children:[(0,R.jsxs)(`legend`,{className:`settings-label`,children:[`Token created: `,u.name]}),(0,R.jsx)(`p`,{className:`settings-note`,children:`Copy it now — it is never shown again.`}),(0,R.jsx)(`code`,{className:`token-secret`,children:u.token}),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`button`,{type:`button`,className:`token-copy`,onClick:b,children:m?`Copied`:`Copy`}),(0,R.jsx)(`button`,{type:`button`,className:`token-dismiss`,onClick:()=>d(null),children:`Done`})]}),(0,R.jsxs)(`label`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`CLI`}),(0,R.jsx)(`code`,{className:`token-snippet`,children:`SIGRUN_TOKEN=${u.token} sigrun attach --server ${C}`})]}),(0,R.jsxs)(`label`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`tui.json — $SIGRUN_CONFIG_DIR/tui.json (default ~/.config/sigrun/tui.json)`}),(0,R.jsx)(`code`,{className:`token-snippet`,children:`{"server": "${C}", "token": "${u.token}"}`})]})]}),x.length===0&&(0,R.jsx)(`p`,{className:`settings-note`,children:`No API tokens.`}),x.map(e=>(0,R.jsx)(`div`,{className:`settings-ext-row`,children:f?.id===e.id?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`span`,{className:`settings-ext-key`,children:[`Revoke `,e.name,`?`]}),(0,R.jsx)(`button`,{type:`button`,className:`token-revoke-confirm`,disabled:c,onClick:()=>void y(e.id),children:`Confirm revoke`}),(0,R.jsx)(`button`,{type:`button`,className:`token-revoke-cancel`,disabled:c,onClick:()=>p(null),children:`Cancel`})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`settings-ext-key`,children:e.name}),(0,R.jsx)(`button`,{type:`button`,className:`token-revoke`,disabled:c,onClick:()=>p({id:e.id,name:e.name}),children:`Revoke`})]})},e.id)),(0,R.jsxs)(`div`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Create a token`}),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`input`,{type:`text`,className:`token-name-input`,"aria-label":`Token name`,placeholder:`name (e.g. laptop, ci)`,value:o,onChange:e=>s(e.target.value)}),(0,R.jsx)(`button`,{type:`button`,className:`token-create`,disabled:c||o.trim()===``,onClick:()=>void _(),children:`Create token`})]})]})]})}var M_=`sigrun.prefs`,N_={enterToSend:!1,showThinking:!0},P_=(()=>{let e=new Map;return{getItem:t=>e.get(t)??null,setItem:(t,n)=>{e.set(t,n)}}})();function F_(){return globalThis.localStorage??P_}function I_(e){if(e===null)return{};let t;try{t=JSON.parse(e)}catch{return{}}if(typeof t!=`object`||!t||Array.isArray(t))return{};let n=t,r={};for(let e of Object.keys(N_))typeof n[e]==`boolean`&&(r[e]=n[e]);return r}function L_(e){let t=e?.storage??F_(),[n,r]=(0,v.useState)(()=>I_(t.getItem(M_)));return{prefs:{...N_,...n},setPref(e,n){r(r=>{let i={...r,[e]:n};return t.setItem(M_,JSON.stringify(i)),i})}}}function R_(e,t){let n=t.trim().toLowerCase();return n===``?[]:e.filter(e=>e.label.toLowerCase().includes(n)||(e.help??``).toLowerCase().includes(n)||(e.key??``).toLowerCase().includes(n))}function z_(e,t){return R_(e,t)}function B_(e,t){return e.filter(e=>!(e.id===`providers`&&t===!1||e.scope===`user`&&e.admin===!0&&t===!1))}function V_(e){let{client:t,onSection:n,prefsState:r,theme:i,admin:a,onRestart:o,section:s}=e,[c,l]=(0,v.useState)({status:`loading`}),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(null),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),x=(0,v.useRef)({}),S=(0,v.useRef)(null);(0,v.useEffect)(()=>{let e=!1;return t.getMeta().then(t=>{e||d(t)}).catch(()=>{}),t.listSettingsSections().then(t=>{e||l({status:`ready`,sections:t.sections,index:t.index})}).catch(t=>{e||l({status:`error`,message:t instanceof Error?t.message:String(t)})}),t.listExtensions().then(t=>{e||h(t.extensions)}).catch(()=>{e||h([])}),()=>{e=!0}},[t]);let C=(0,v.useMemo)(()=>c.status===`ready`?new Set(c.sections.filter(e=>e.slug!==`core`).map(e=>e.slug)):new Set,[c]);(0,v.useEffect)(()=>{if(c.status!==`ready`)return;let e=B_(c.sections,a);if(s!==void 0){let t=e.find(e=>e.slug===`core`&&e.id===s);if(t!==void 0){p({kind:`section`,entry:t});return}let n=e.find(e=>e.id===s);if(n!==void 0){p({kind:`section`,entry:n});return}let r=m!==null&&!C.has(s)?m.find(e=>e.name===s):void 0;if(r!==void 0){p({kind:`extension`,slug:r.name});return}}let t=e.find(e=>e.slug===`core`&&e.id===`general`);t!==void 0&&p({kind:`section`,entry:t})},[c,s,a,m,C]);let w=(0,v.useMemo)(()=>c.status===`ready`?z_(c.index,g):[],[c,g]),T=(0,v.useCallback)(async e=>{let t=c.status===`ready`?c.sections.find(t=>t.slug===e.slug&&t.id===e.sectionId):void 0;if(t!==void 0&&(_(``),n(t.id),e.key!==void 0)){let t=e.key;for(let e=0;e<20;e++){await new Promise(e=>setTimeout(e,50));let e=S.current?.querySelector(`[data-name=${JSON.stringify(t)}]`),n=e?.querySelector(`input, textarea, select, button, [tabindex]`)??e;if(n!=null){n.focus();return}}}},[c,n]),E=y?.pendingRestart??[],D=y?.supervised===!0&&a!==!1&&o!==void 0,ee=(0,v.useMemo)(()=>c.status===`ready`?B_(c.sections,a):[],[c,a]);return(0,R.jsx)(`div`,{className:`settings-page`,children:(0,R.jsxs)(`div`,{className:`settings-panel`,children:[(0,R.jsxs)(`header`,{className:`settings-head`,children:[(0,R.jsx)(`span`,{className:`settings-title`,children:`Settings`}),(0,R.jsx)(`input`,{type:`search`,className:`settings-search`,placeholder:`Search settings`,"aria-label":`search settings`,value:g,onChange:e=>_(e.target.value)}),(0,R.jsx)(`span`,{className:`spacer`})]}),E.length>0&&(0,R.jsxs)(`div`,{className:`settings-restart-callout`,role:`status`,children:[(0,R.jsxs)(`p`,{className:`settings-restart-text`,children:[`Restart sigrun to apply: `,E.join(`, `)]}),D&&(0,R.jsx)(`button`,{type:`button`,className:`settings-restart`,onClick:()=>void o(),children:`Restart`})]}),c.status===`loading`&&(0,R.jsx)(`p`,{className:`settings-note`,children:`loading settings…`}),c.status===`error`&&(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:c.message}),c.status===`ready`&&(0,R.jsxs)(`div`,{className:`settings-layout`,children:[(0,R.jsxs)(`nav`,{className:`settings-nav`,"aria-label":`settings sections`,children:[ee.filter(e=>e.scope!==`user`).map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-nav-item`,"data-active":f?.kind===`section`&&f.entry.slug===e.slug&&f.entry.id===e.id?``:void 0,onClick:()=>n(e.id),children:e.title},`${e.slug}/${e.id}`)),ee.some(e=>e.scope===`user`)&&(0,R.jsxs)(`div`,{className:`settings-nav-group`,role:`group`,"aria-label":`My settings`,children:[(0,R.jsx)(`div`,{className:`settings-nav-heading`,children:`My settings`}),ee.filter(e=>e.scope===`user`).map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-nav-item`,"data-active":f?.kind===`section`&&f.entry.slug===e.slug&&f.entry.id===e.id?``:void 0,onClick:()=>n(e.id),children:e.title},`${e.slug}/${e.id}`))]}),(0,R.jsx)(X_,{extensions:m,open:f,coveredSlugs:C,onOpen:n})]}),(0,R.jsx)(`div`,{className:`settings-section`,ref:S,children:f===null?(0,R.jsx)(`p`,{className:`settings-note`,children:`select a section`}):f.kind===`extension`?(0,R.jsx)(Z_,{client:t,slug:f.slug}):(0,R.jsx)(H_,{client:t,entry:f.entry,prefsState:r,theme:i,meta:u,onCoreMeta:b,valuesRef:x},`${f.entry.slug}/${f.entry.id}`)})]}),g.trim()!==``&&w.length>0&&(0,R.jsx)(`div`,{className:`settings-search-results`,role:`listbox`,children:w.slice(0,20).map((e,t)=>(0,R.jsxs)(`button`,{type:`button`,className:`settings-search-hit`,role:`option`,"aria-selected":`false`,onClick:()=>void T(e),children:[(0,R.jsx)(`span`,{className:`settings-search-hit-label`,children:e.label}),(0,R.jsxs)(`span`,{className:`settings-search-hit-path`,children:[e.slug===`core`?``:`${e.slug} · `,e.sectionId]})]},`${e.slug}/${e.sectionId}/${e.key??e.label}/${t}`))})]})})}function H_(e){let{entry:t,client:n,prefsState:r,theme:i,meta:a,onCoreMeta:o}=e;return t.slug===`core`&&t.id===`interface`?(0,R.jsx)(q_,{prefsState:r,theme:i}):t.slug===`core`&&t.id===`providers`?(0,R.jsx)(w_,{client:n}):t.slug===`core`&&t.id===`extensions`?(0,R.jsx)(Q_,{client:n}):t.slug===`core`&&t.id===`accounts`?(0,R.jsx)(C_,{client:n}):t.slug===`core`&&t.id===`tokens`?(0,R.jsx)(j_,{client:n}):(0,R.jsx)(U_,{client:n,entry:t,meta:t.slug===`core`&&t.id===`general`?a:null,onCoreMeta:t.slug===`core`?o:void 0,valuesRef:e.valuesRef})}function U_(e){let{entry:t,meta:n,client:r}=e,i=(0,v.useMemo)(()=>pg({slug:t.slug,id:t.id,fetch:r.rawFetch}),[t.slug,t.id,r]),{onCoreMeta:a,valuesRef:o}=e,s=(0,v.useCallback)(e=>{if(o.current[`${t.slug}/${t.id}`]=typeof e.settings==`object`&&e.settings!==null&&!Array.isArray(e.settings)?e.settings:{},a!==void 0){let t=e.meta;if(typeof t==`object`&&t&&!Array.isArray(t)&&Array.isArray(t.pendingRestart)){let e=t;a({pendingRestart:e.pendingRestart.filter(e=>typeof e==`string`),supervised:e.supervised===!0})}}},[t.slug,t.id,a,o]);return(0,R.jsxs)(`div`,{className:`settings-body`,"data-settings-section":t.id,children:[t.slug===`core`&&t.id===`general`&&(0,R.jsxs)(`p`,{className:`settings-version`,children:[`sigrun `,n?.version===void 0?``:`v${n.version}`,n?.harnessVersion===void 0?``:` · pi-durable v${n.harnessVersion}`]}),(0,R.jsx)(W_,{transport:i,onData:s}),(0,R.jsx)(Yh,{transport:i})]})}function W_(e){let{transport:t,onData:n}=e;return(0,v.useEffect)(()=>{let e=!1,r=()=>{t.fetchData().then(t=>{!e&&t.data!==void 0&&n(t.data)}).catch(()=>{})};r();let i=setInterval(r,1500);return()=>{e=!0,clearInterval(i)}},[t,n]),null}var G_=[{key:`enterToSend`,label:`Enter sends the prompt`,note:`off: Ctrl+Enter submits (Enter inserts a newline); on: Enter submits and Shift+Enter inserts a newline. Ctrl+Enter submits either way.`},{key:`showThinking`,label:`Show thinking blocks`,note:`Show thinking text inside activity details`}],K_=[{value:`system`,label:`System`},{value:`dark`,label:`Dark`},{value:`light`,label:`Light`}];function q_(e){let{prefsState:t,theme:n}=e;return(0,R.jsxs)(`div`,{className:`settings-body`,children:[(0,R.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,R.jsx)(`legend`,{className:`settings-label`,children:`Mode`}),(0,R.jsx)(`div`,{className:`settings-mode-row`,role:`group`,"aria-label":`mode`,children:K_.map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-mode`,"data-mode-option":e.value,"aria-pressed":n.mode===e.value,onClick:()=>n.setMode(e.value),children:e.label},e.value))})]}),(0,R.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,R.jsx)(`legend`,{className:`settings-label`,children:`Palette`}),(0,R.jsx)(`div`,{className:`settings-palettes`,role:`group`,"aria-label":`palette`,children:__.map(e=>{let t=h_[e],r=t[n.resolved];return(0,R.jsxs)(`button`,{type:`button`,className:`settings-palette`,"data-palette-option":e,"aria-pressed":n.palette===e,title:t.label,onClick:()=>n.setPalette(e),style:{background:r.bg},children:[(0,R.jsx)(`span`,{className:`settings-swatch-dot`,"aria-hidden":`true`,style:{background:r.text}}),(0,R.jsx)(`span`,{className:`settings-swatch-dot`,"aria-hidden":`true`,style:{background:g_[t.defaultAccent][n.resolved]}})]},e)})})]}),(0,R.jsxs)(`fieldset`,{className:`settings-field`,children:[(0,R.jsx)(`legend`,{className:`settings-label`,children:`Accent`}),(0,R.jsx)(`div`,{className:`settings-accents`,role:`group`,"aria-label":`accent`,children:v_.map(e=>(0,R.jsx)(`button`,{type:`button`,className:`settings-accent`,"data-accent-option":e,"aria-pressed":n.accent===e,title:g_[e].label,onClick:()=>n.setAccent(e),style:{background:g_[e][n.resolved]}},e))})]}),G_.map(e=>(0,R.jsxs)(`label`,{className:`settings-field settings-checkbox`,children:[(0,R.jsx)(`input`,{type:`checkbox`,className:`settings-pref-${e.key}`,checked:t.prefs[e.key],onChange:n=>t.setPref(e.key,n.target.checked)}),(0,R.jsx)(`span`,{className:`settings-label`,children:e.label}),(0,R.jsx)(`p`,{className:`settings-note`,children:e.note})]},e.key)),(0,R.jsx)(`p`,{className:`settings-note`,children:`interface preferences are per-browser (stored locally — never sent to the server)`})]})}function J_(e){return Object.keys(e).length===0?``:JSON.stringify(e,null,2)}function Y_(e){let t=e.trim();if(t===``)return{ok:!0,value:{}};try{let e=JSON.parse(t);return typeof e!=`object`||!e||Array.isArray(e)?{ok:!1,message:`settings must be a JSON object`}:{ok:!0,value:e}}catch(e){return{ok:!1,message:`invalid JSON: ${e instanceof Error?e.message:String(e)}`}}}function X_(e){let{extensions:t,coveredSlugs:n,onOpen:r,open:i}=e;if(t===null)return null;let a=t.filter(e=>!n.has(e.name));return a.length===0?null:(0,R.jsx)(R.Fragment,{children:a.map(e=>(0,R.jsxs)(`button`,{type:`button`,className:`settings-nav-item settings-nav-extension`,"data-ext":e.name,"data-active":i?.kind===`extension`&&i.slug===e.name?``:void 0,onClick:()=>r(e.name),children:[e.name,` (advanced)`]},e.name))})}function Z_(e){let{client:t,slug:n,status:r,version:i}=e,[a,o]=(0,v.useState)(null),[s,c]=(0,v.useState)(null);(0,v.useEffect)(()=>{let e=!1;return o(null),c(null),Promise.all([t.getExtensionSettings(n),t.listExtensionSecrets(n)]).then(([t,n])=>{e||o({settingsText:J_(t.settings),secrets:n.secrets,secretValues:{},newKey:``,newValue:``})}).catch(t=>{e||c(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[t,n]);let l=e=>{o(t=>t===null?t:{...t,...e})},u=async()=>{if(a===null)return;let e=Y_(a.settingsText);if(!e.ok){l({note:{kind:`error`,message:e.message}});return}try{await t.putExtensionSettings(n,e.value),l({note:{kind:`ok`,message:`saved`}})}catch(e){l({note:{kind:`error`,message:e instanceof Error?e.message:String(e)}})}},d=async(e,r)=>{if(e!==``&&r!==``&&a!==null)try{let{secrets:i}=await t.putExtensionSecret(n,e,r);o({...a,secrets:i,secretValues:{...a.secretValues,[e]:``},newKey:``,newValue:``,note:{kind:`ok`,message:`secret ${e} set`}})}catch(e){l({note:{kind:`error`,message:e instanceof Error?e.message:String(e)}})}},f=async e=>{try{let{secrets:r}=await t.deleteExtensionSecret(n,e);l({secrets:r,note:{kind:`ok`,message:`secret ${e} deleted`}})}catch(e){l({note:{kind:`error`,message:e instanceof Error?e.message:String(e)}})}};return s===null?a===null?(0,R.jsx)(`p`,{className:`settings-note`,children:`loading…`}):(0,R.jsxs)(`div`,{className:`settings-body settings-ext-list`,children:[(0,R.jsx)(`p`,{className:`settings-note`,children:`settings are the extension's own JSON (read at factory time → applies at restart); secrets list keys only — values are write-only and never displayed`}),(0,R.jsxs)(`fieldset`,{className:`settings-ext`,"data-ext":n,children:[(0,R.jsxs)(`legend`,{className:`settings-ext-name`,children:[n,(0,R.jsxs)(`span`,{className:`settings-ext-meta`,children:[r??``,i===void 0?``:` · v${i}`]})]}),(0,R.jsxs)(`label`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Settings (raw JSON)`}),(0,R.jsx)(`textarea`,{className:`settings-ext-settings`,rows:4,spellCheck:!1,placeholder:`{}`,value:a.settingsText,onChange:e=>l({settingsText:e.target.value})}),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-save`,onClick:()=>void u(),children:`Save settings`}),a.note!==void 0&&(0,R.jsx)(`span`,{className:`settings-note`,role:a.note.kind===`ok`?`status`:`alert`,children:a.note.message})]})]}),(0,R.jsxs)(`div`,{className:`settings-field`,children:[(0,R.jsx)(`span`,{className:`settings-label`,children:`Secrets`}),a.secrets.length===0&&(0,R.jsx)(`p`,{className:`settings-note`,children:`no secrets set`}),a.secrets.map(e=>(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsxs)(`span`,{className:`settings-ext-key`,children:[e.key,` `,(0,R.jsxs)(`span`,{className:`settings-ext-source`,children:[`(`,e.source,`)`]})]}),(0,R.jsx)(`input`,{type:`password`,className:`settings-ext-secret-value`,"data-secret-key":e.key,placeholder:`new value`,value:a.secretValues[e.key]??``,onChange:t=>l({secretValues:{...a.secretValues,[e.key]:t.target.value}})}),(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-secret-set`,"data-secret-key":e.key,onClick:()=>void d(e.key,a.secretValues[e.key]??``),children:`Set`}),(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-secret-delete`,"data-secret-key":e.key,onClick:()=>void f(e.key),children:`Delete`})]},e.key)),(0,R.jsxs)(`div`,{className:`settings-ext-row`,children:[(0,R.jsx)(`input`,{type:`text`,className:`settings-ext-new-key`,placeholder:`new key`,value:a.newKey,onChange:e=>l({newKey:e.target.value})}),(0,R.jsx)(`input`,{type:`password`,className:`settings-ext-new-value`,placeholder:`value`,value:a.newValue,onChange:e=>l({newValue:e.target.value})}),(0,R.jsx)(`button`,{type:`button`,className:`settings-ext-secret-add`,onClick:()=>void d(a.newKey,a.newValue),children:`Set`})]})]})]})]}):(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:s})}function Q_(e){let{client:t}=e,[n,r]=(0,v.useState)(null),[i,a]=(0,v.useState)(null);return(0,v.useEffect)(()=>{let e=!1;return t.listExtensions().then(t=>{e||r(t.extensions)}).catch(t=>{e||a(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[t]),i===null?n===null?(0,R.jsx)(`p`,{className:`settings-note`,children:`loading extensions…`}):n.length===0?(0,R.jsx)(`div`,{className:`settings-body`,children:(0,R.jsx)(`p`,{className:`settings-note`,children:`no extensions are configured`})}):(0,R.jsx)(`div`,{className:`settings-body`,children:n.map(e=>(0,R.jsx)(Z_,{client:t,slug:e.name,status:e.status,version:e.version},e.name))}):(0,R.jsx)(`p`,{className:`settings-note`,role:`alert`,children:i})}var $_=`sigrun.theme`,ev=`sigrun.palette`,tv=`sigrun.accent`,nv=(()=>{let e=new Map;return{getItem:t=>e.get(t)??null,setItem:(t,n)=>{e.set(t,n)}}})();function rv(){return globalThis.localStorage??nv}function iv(){let e=globalThis.document?.documentElement;return e===void 0?null:{dataset:e.dataset,setProperty:(t,n)=>{e.style.setProperty(t,n)}}}function av(){return globalThis.matchMedia??null}function ov(e){return e===`dark`||e===`light`?e:`system`}function sv(e){let t=e.getItem(tv);if(t===`amber`){let t=`baltic-amber`;return e.setItem(tv,t),t}return S_(t)?t:(e.setItem(tv,b_),b_)}function cv(e){let t=e.getItem(ev);return x_(t)?t:(e.setItem(ev,y_),y_)}var lv={bg:`--bg`,surface:`--surface`,surface2:`--surface-2`,border:`--border`,text:`--text`,muted:`--muted`,faint:`--faint`,ok:`--ok`,code:`--code`};function uv(e,t){let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(n===null)return`color-mix(in srgb, ${e} ${Math.round(t*100)}%, transparent)`;let r=n[1].length===3?n[1].split(``).map(e=>e+e).join(``):n[1];return`rgba(${Number.parseInt(r.slice(0,2),16)}, ${Number.parseInt(r.slice(2,4),16)}, ${Number.parseInt(r.slice(4,6),16)}, ${t})`}function dv(e){let t=e?.storage??rv(),n=e?.root===void 0?iv():e.root,r=e?.matchMedia===void 0?av():e.matchMedia,[i,a]=(0,v.useState)(()=>ov(t.getItem($_))),[o,s]=(0,v.useState)(()=>cv(t)),[c,l]=(0,v.useState)(()=>sv(t)),[u,d]=(0,v.useState)(()=>r?.(`(prefers-color-scheme: dark)`)?.matches??!0);(0,v.useEffect)(()=>{let e=r?.(`(prefers-color-scheme: dark)`);if(e==null)return;let t=()=>d(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[r]);let f=i===`system`?u?`dark`:`light`:i;return(0,v.useEffect)(()=>{if(n===null)return;let e=h_[o][f];for(let[t,r]of Object.entries(lv))n.setProperty(r,e[t]);let t=g_[c][f];n.setProperty(`--accent`,t),n.setProperty(`--accent-bg`,uv(t,f===`dark`?.14:.16)),n.dataset.mode=f,n.dataset.palette=o,n.dataset.accent=c},[n,f,o,c]),{mode:i,resolved:f,palette:o,accent:c,setMode(e){t.setItem($_,e),a(e)},setPalette(e){t.setItem(ev,e),s(e)},setAccent(e){t.setItem(tv,e),l(e)}}}function fv(e,t){let n=e.entries;if(t.entries!==void 0){let r=new Set(t.entries.remove??[]);n=[...e.entries.filter(e=>!r.has(e.id)),...t.entries.append??[]]}let r=e.docs;if(t.docs!==void 0){let n=new Set(t.docs.unset??[]),i={};for(let[t,r]of Object.entries(e.docs))n.has(t)||(i[t]=r);for(let[e,n]of Object.entries(t.docs.set??{}))i[e]=n;r=i}return{...e,entries:n,docs:r,conversation:t.conversation??e.conversation,steer:t.steer??e.steer}}var pv=250,mv=4e3,hv=e=>new EventSource(e);function gv(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t==`object`&&t&&!Array.isArray(t))return t}function _v(e){let t;try{t=JSON.parse(e)}catch{return}if(typeof t==`object`&&t&&!Array.isArray(t))return t}function vv(e,t,n=``,r={}){let i=r.createEventSource??hv,a=`${n}/v1/conversations/${e}/stream`,o=!1,s=0,c,l,u;function d(){if(o)return;let e=i(a);l=e;let n=!1;e.addEventListener(`open`,()=>{o||(s=0,t.onOpen?.())}),e.addEventListener(`snapshot`,e=>{if(o)return;let n=gv(e.data);if(n===void 0){t.onError?.(`malformed snapshot frame (not a view object)`);return}u=n,t.onSnapshot?.(n)}),e.addEventListener(`delta`,e=>{if(o)return;if(u===void 0){t.onError?.(`malformed delta frame (arrived before any snapshot)`);return}let n=_v(e.data);if(n===void 0){t.onError?.(`malformed delta frame (not a delta object)`);return}u=fv(u,n),t.onView?.(u)}),e.addEventListener(`error`,()=>{if(o||n)return;n=!0,t.onError?.(`conversation stream connection error`),e.close(),l===e&&(l=void 0),s+=1;let r=Math.min(pv*2**(s-1),mv);c=setTimeout(()=>{c=void 0,d()},r)})}return d(),{close(){o||(o=!0,c!==void 0&&(clearTimeout(c),c=void 0),l?.close(),l=void 0)}}}var yv={view:null,status:`idle`,frames:0,error:null};function bv(e,t={}){let{baseUrl:n,createEventSource:r}=t,[i,a]=(0,v.useState)(yv);return(0,v.useEffect)(()=>{if(e===null){a(yv);return}a({view:null,status:`connecting`,frames:0,error:null});let t=vv(e,{onSnapshot:e=>a(t=>({view:e,status:`snapshot`,frames:t.frames+1,error:null})),onView:e=>a(t=>({view:e,status:`live`,frames:t.frames+1,error:null})),onError:e=>a(t=>({...t,status:`error`,error:e}))},n,{createEventSource:r});return()=>t.close()},[e,n,r]),i}var xv=4e3;function Sv(e,t){let[n,r]=(0,v.useState)([]),[i,a]=(0,v.useState)([]),[o,s]=(0,v.useState)({}),c=(0,v.useRef)({}),l=(0,v.useCallback)(e=>{c.current=typeof e==`function`?e(c.current):e,s(c.current)},[]),u=(0,v.useRef)(null),d=(0,v.useRef)(0),f=(0,v.useRef)(new Set),p=(0,v.useCallback)(async(t=!1)=>{let n=(await e.listNotices()).notices,i=u.current;if(i!==null&&a(n.filter(e=>!i.has(e.id))),u.current=new Set(n.map(e=>e.id)),!t&&Date.now()<d.current){r(e=>{let t=new Set(n.map(e=>e.id));return[...n,...e.filter(e=>!t.has(e.id)&&(c.current[e.id]!==void 0||f.current.has(e.id)))]});return}r(n)},[e]),m=(0,v.useRef)(null),h=(0,v.useCallback)(()=>{d.current=Date.now()+xv,m.current!==null&&clearTimeout(m.current),m.current=setTimeout(()=>{m.current=null,l({}),p(!0).catch(()=>void 0)},xv);let e=m.current;typeof e==`object`&&e&&`unref`in e&&e.unref()},[p]);(0,v.useEffect)(()=>{p().catch(()=>void 0)},[p,t.refetchToken]);let g=(0,v.useCallback)(async t=>{await e.dismissNotice(t).catch(()=>void 0),await p().catch(()=>void 0)},[e,p]);return{notices:n,arrivals:i,results:o,refetch:p,dismiss:g,dismissAll:(0,v.useCallback)(async()=>{await e.dismissAllNotices().catch(()=>void 0),await p().catch(()=>void 0)},[e,p]),run:(0,v.useCallback)(async(t,r,i)=>{if(r.kind===`navigate`){i(r.target),await g(t.id);return}if(r.kind===`open`){globalThis.window?.open(r.url,`_blank`,`noopener,noreferrer`),await g(t.id);return}f.current=new Set([...f.current,t.id]);let a;try{a=await e.runNoticeAction(t.id,r.id)}catch(e){l(n=>({...n,[t.id]:e instanceof Error?e.message:String(e)})),await p(!0).catch(()=>void 0);return}finally{let e=new Set(f.current);e.delete(t.id),f.current=e}a.ok&&a.navigate!==void 0&&i(a.navigate);let o=a.ok?a.message:a.error.message;return o!==void 0&&l(e=>({...e,[t.id]:o})),a.ok&&n.some(e=>e.id===t.id)?(h(),a):(await p(!0).catch(()=>void 0),a)},[e,g,p,h,n])}}function Cv(){return globalThis.document}function wv(e){let t=(0,v.useRef)(null);return(0,v.useEffect)(()=>{if(e.variant!==`overlay`||e.onClose===void 0)return;let n=Cv();if(n===void 0)return;let r=e.onClose,i=e=>{e.key===`Escape`&&r()},a=e=>{let n=e.target;if(n==null)return;let i=t.current;if(i!==null&&!i.contains(n)){let e=n.closest;if(typeof e==`function`&&e.call(n,`[data-rail-section="notices"]`)!==null)return;r()}};return n.addEventListener(`keydown`,i),n.addEventListener(`mousedown`,a),()=>{n.removeEventListener(`keydown`,i),n.removeEventListener(`mousedown`,a)}},[e.variant,e.onClose]),(0,v.useEffect)(()=>{e.scrollTo!==null&&e.scrollTo!==void 0&&(t.current?.querySelector?.(`[data-notice-id="${e.scrollTo}"]`))?.scrollIntoView?.()},[e.scrollTo]),(0,R.jsxs)(`div`,{ref:t,className:e.variant===`overlay`?`notices-pane notices-pane-overlay`:`notices-pane`,role:`complementary`,"aria-label":`notices`,children:[(0,R.jsxs)(`h4`,{className:`notices-pane-head`,children:[(0,R.jsx)(`span`,{children:`Notices`}),e.notices.length>0&&(0,R.jsx)(`button`,{type:`button`,className:`notices-pane-clear`,onClick:()=>e.dismissAll(),children:`Clear all`})]}),e.notices.length===0?(0,R.jsx)(`p`,{className:`notices-pane-empty`,children:`No notices`}):e.notices.map(t=>(0,R.jsx)(im,{notice:t,result:e.results?.[t.id]??null,conversationName:t.conversationId===void 0?void 0:e.conversationName?.(t.conversationId),run:e.run,dismiss:e.dismiss,onNavigate:e.onNavigate},t.id))]})}var Tv=6e3,Ev={now:()=>Date.now(),sleep:(e,t)=>setTimeout(t,e),clear:e=>clearTimeout(e)};function Dv(){return globalThis.document?.visibilityState===`hidden`}function Ov(e){let{batch:t,clock:n}=e,r=t.length===1?t[0]:void 0,i=(0,v.useRef)(null),a=(0,v.useRef)(Tv),o=(0,v.useRef)(0),s=()=>{i.current!==null&&n.clear(i.current),o.current=n.now(),i.current=n.sleep(a.current,e.onFold)};(0,v.useEffect)(()=>(s(),()=>{i.current!==null&&n.clear(i.current)}),[]);let c=()=>{i.current!==null&&(n.clear(i.current),i.current=null,a.current=Math.max(0,a.current-(n.now()-o.current)))},l=()=>{i.current===null&&s()},u=r?.actions?.[0];return(0,R.jsxs)(`div`,{className:`notice-peek`,role:`status`,"aria-live":`polite`,onMouseEnter:c,onMouseLeave:l,onFocus:c,onBlur:l,children:[(0,R.jsx)(`button`,{type:`button`,className:`notice-peek-body`,onClick:()=>{e.onOpenPane(r?.id),e.onFold()},children:r===void 0?(0,R.jsxs)(`strong`,{children:[t.length,` new notices`]}):(0,R.jsx)(`strong`,{children:r.title})}),r!==void 0&&u!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`notice-peek-action`,onClick:()=>{e.run(r,u,e.onNavigate),e.onFold()},children:u.label}),r!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`notice-peek-close`,"aria-label":`dismiss notice`,onClick:()=>{e.dismiss(r.id),e.onFold()},children:`✕`})]})}function kv(e){let[t,n]=(0,v.useState)([]),r=(0,v.useRef)(new Set);return(0,v.useEffect)(()=>{let t=e.arrivals.filter(t=>!r.current.has(t.id)&&(e.visibleConversationId===null||e.visibleConversationId===void 0||t.conversationId!==e.visibleConversationId));for(let t of e.arrivals)r.current.add(t.id);t.length===0||Dv()||n(e=>[...e,...t])},[e.arrivals,e.visibleConversationId]),t.length===0?null:(0,R.jsx)(Ov,{batch:t,onFold:()=>n([]),run:e.run,dismiss:e.dismiss,onNavigate:e.onNavigate,onOpenPane:e.onOpenPane,clock:e.clock??Ev},`${t[0]?.id}:${t.length}`)}function Av(e){return(0,R.jsxs)(`button`,{type:`button`,className:`rail-btn rail-bell`,"data-rail-section":`notices`,title:`Notices`,"aria-label":`notices`,"aria-pressed":e.active===!0,"data-active":e.active===!0?``:void 0,onClick:()=>e.onToggle?.(),children:[`🔔`,e.count>0&&(0,R.jsx)(`span`,{className:`rail-bell-badge`,"data-bell-count":e.count,children:e.count})]})}var jv=24;function Mv(e,t){let[n,r]=(0,v.useState)(!0),i=(0,v.useRef)(!0);return(0,v.useEffect)(()=>{if(e===null)return;let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<=jv;i.current=t,r(t)};return e.addEventListener(`scroll`,t,{passive:!0}),t(),()=>e.removeEventListener(`scroll`,t)},[e]),(0,v.useEffect)(()=>{e!==null&&i.current&&(e.scrollTop=e.scrollHeight)},[e,t]),n}function Nv(e){let{client:t,conversationId:n,path:r}=e,[i,a]=(0,v.useState)({kind:`loading`});return(0,v.useEffect)(()=>{let e=!1;return a({kind:`loading`}),t.readFile(n,r).then(t=>{e||a(t.encoding===`text`?{kind:`text`,content:t.content,size:t.size}:{kind:`binary`,size:t.size})}).catch(t=>{e||a({kind:`error`,message:t instanceof Error?t.message:String(t)})}),()=>{e=!0}},[t,n,r]),(0,R.jsxs)(`div`,{className:`file-preview`,"data-path":r,children:[(0,R.jsx)(`div`,{className:`file-preview-path`,children:r}),i.kind===`loading`&&(0,R.jsx)(`p`,{className:`file-preview-loading`,children:`loading…`}),i.kind===`text`&&(0,R.jsx)(`pre`,{className:`file-preview-content`,children:i.content}),i.kind===`binary`&&(0,R.jsxs)(`p`,{className:`file-preview-binary`,children:[`binary file — `,i.size,` bytes (no preview)`]}),i.kind===`error`&&(0,R.jsx)(`p`,{role:`alert`,children:i.message})]})}function Pv(e){return[...e].sort((e,t)=>(e.kind===`directory`?0:1)-(t.kind===`directory`?0:1)||e.name.localeCompare(t.name))}function Fv(e){let{client:t,conversationId:n,onClose:r}=e,[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)({}),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(a(null),s({}),l({}),d(null),p(null),n===null)return;let e=!1;return t.listFiles(n).then(t=>{e||a(Pv(t.entries))}).catch(t=>{e||p(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[t,n]);async function m(e){if(n!==null){if(c[e.path]){l(t=>{let n={...t};return delete n[e.path],n});return}if(l(t=>({...t,[e.path]:!0})),o[e.path]===void 0)try{let r=await t.listFiles(n,e.path);s(t=>({...t,[e.path]:Pv(r.entries)}))}catch(e){p(e instanceof Error?e.message:String(e))}}}function h(e,t){return e.map(e=>{if(e.kind===`directory`){let n=c[e.path]===!0,r=o[e.path];return(0,R.jsxs)(`li`,{children:[(0,R.jsxs)(`button`,{type:`button`,className:`workspace-dir`,"data-tree-row":`true`,"data-path":e.path,"aria-expanded":n,style:{paddingLeft:`${t*.9}rem`},onClick:()=>void m(e),children:[n?`▾`:`▸`,` `,e.name,`/`]}),n&&r!==void 0&&(0,R.jsx)(`ul`,{className:`workspace-children`,children:h(r,t+1)})]},e.path)}return(0,R.jsx)(`li`,{children:(0,R.jsx)(`button`,{type:`button`,className:`workspace-file`,"data-tree-row":`true`,"data-path":e.path,"data-selected":u===e.path||void 0,style:{paddingLeft:`${t*.9}rem`},onClick:()=>d(e.path),children:e.name})},e.path)})}return(0,R.jsxs)(`section`,{className:`workspace-browser`,"aria-label":`workspace files`,children:[(0,R.jsxs)(`h2`,{className:`workspace-title`,children:[`Workspace`,r!==void 0&&(0,R.jsx)(`button`,{type:`button`,className:`workspace-close`,"aria-label":`close workspace panel`,title:`close`,onClick:r,children:`✕`})]}),n===null?(0,R.jsx)(`p`,{className:`workspace-empty`,children:`Select a conversation to browse its workspace`}):(0,R.jsxs)(R.Fragment,{children:[f!==null&&(0,R.jsx)(`p`,{role:`alert`,children:f}),i===null&&f===null?(0,R.jsx)(`p`,{className:`workspace-loading`,children:`loading…`}):i===null?null:(0,R.jsx)(`ul`,{className:`workspace-tree`,children:h(i,0)}),u!==null&&(0,R.jsx)(Nv,{client:t,conversationId:n,path:u})]})]})}var Iv=w(),Lv=6e4,Rv=`sigrun.timeline`;function zv(){try{return globalThis.localStorage?.getItem(Rv)!==`0`}catch{return!0}}function Bv(e){try{globalThis.localStorage?.setItem(Rv,e?`1`:`0`)}catch{}}function Vv(e,t){let n=globalThis.document;if(n===void 0)return;let r=URL.createObjectURL(new Blob([t],{type:`application/json`})),i=n.createElement(`a`);i.href=r,i.download=e,n.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)}function Hv(e,t){return t===null?`sigrun`:oe(e.find(e=>e.id===t)??{id:t,archived:!1,pinned:!1})}function Uv(e){let{activeId:t,view:n,status:r,error:i,showThinking:a,timeline:o}=e;if(t===null)return(0,R.jsx)(`section`,{className:`chat-center`,children:(0,R.jsx)(`p`,{className:`chat-empty`,children:`Start a conversation — type below.`})});let s=n?.steer.busy??!1,c=n!==null&&Bh(n)>0,l=n===null||c?void 0:Vh(n);return(0,R.jsxs)(`section`,{className:`chat-center`,"data-view-status":r,"aria-label":`chat transcript`,ref:e.onScrollRoot,style:e.dockPadding>0?{paddingBottom:`${e.dockPadding}px`}:void 0,children:[i!==null&&(0,R.jsx)(`p`,{role:`alert`,children:i}),n===null?(0,R.jsx)(`p`,{className:`chat-loading`,children:`loading…`}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ah.Provider,{value:e.attachChatTransport,children:(0,R.jsx)(Kh,{view:n,showThinking:a,timeline:o,parent:e.parent,client:e.client,onNavigate:e.onNavigate})}),s&&(0,R.jsxs)(`div`,{className:`chat-working`,role:`status`,children:[(0,R.jsx)(`span`,{className:`chat-working-dot`}),(0,R.jsx)(`span`,{className:`chat-working-dot`}),(0,R.jsx)(`span`,{className:`chat-working-dot`}),(0,R.jsx)(`span`,{className:`chat-working-label`,children:c?`compacting…`:`working…`})]}),l!==void 0&&(0,R.jsxs)(`p`,{className:`chat-compaction-failure`,role:`alert`,children:[`compaction failed: `,l]})]})]})}function Wv(e){let t=e.startsWith(`#`)?e.slice(1):e,n=/^\/settings(?:\/([^/]+))?\/?$/.exec(t);if(n!==null){let e=n[1];if(e===void 0)return{kind:`settings`};try{return{kind:`settings`,section:decodeURIComponent(e)}}catch{return{kind:`chat`}}}let r=/^\/c(?:\/(\d+))?\/?$/.exec(t);if(r!==null){let e=r[1];return e===void 0?{kind:`chat`}:{kind:`chat`,conversationId:Number(e)}}let i=/^\/ext\/([^/]+)\/([^/?]+)(?:\?(.*))?$/.exec(t);if(i===null)return{kind:`chat`};try{return{kind:`ext`,slug:decodeURIComponent(i[1]??``),id:decodeURIComponent(i[2]??``),params:Gv(i[3])}}catch{return{kind:`chat`}}}function Gv(e){let t={};if(e!==void 0){let n=new URLSearchParams(e).get(`params`);if(n!==null)try{let e=JSON.parse(n);typeof e==`object`&&e&&!Array.isArray(e)&&(t=e)}catch{}}return t}function Kv(e){if(e.kind===`chat`)return e.conversationId===void 0?`#/c`:`#/c/${e.conversationId}`;if(e.kind===`settings`)return e.section===void 0?`#/settings`:`#/settings/${encodeURIComponent(e.section)}`;let t=`#/ext/${encodeURIComponent(e.slug)}/${encodeURIComponent(e.id)}`;return Object.keys(e.params).length===0?t:`${t}?params=${encodeURIComponent(JSON.stringify(e.params))}`}function qv(){let e=globalThis.location;if(e?.pathname!==`/settings`)return;let t=new URLSearchParams(e.search??``).get(`section`),n=t===null||t===``?`#/settings`:`#/settings/${encodeURIComponent(t)}`;Jv=n,globalThis.history?.replaceState(null,``,`/${n}`)}var Jv=``;function Yv(){let e=globalThis.location;return e!==void 0&&typeof e.hash==`string`?e.hash:Jv}function Xv(e,t=!1){let n=globalThis.history;Jv=e,n!==void 0&&(t?n.replaceState(null,``,e):n.pushState(null,``,e))}function Zv(e={}){let t=e.client??Iv,n=e.identity,r=e.onLogout,i=e.onRestarting,a=dv(),o=L_(),[s,c]=(0,v.useState)({status:`loading`}),l=(0,v.useCallback)(async()=>{try{await t.requestRestart()}catch(e){ue(`restart failed: ${e instanceof Error?e.message:String(e)}`);return}ue(null),c({status:`restarting`});let e=Date.now()+Lv;for(;;){await new Promise(e=>setTimeout(e,500));let n=!1;try{n=await t.checkReady()}catch{}if(n){i===void 0?c({status:`loading`}):i();return}if(Date.now()>e){c({status:`refused`,message:`restart did not come back: /readyz never answered within ${Lv/1e3}s — check the deployment's supervisor`});return}}},[t,i]);(0,v.useEffect)(()=>{e.onExposeActions?.({restart:l}),(e.onExposeActions!==void 0||globalThis.__sigrunE2E===!0)&&(globalThis.__sigrunAppActions={restart:l})},[l]);let[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(Pg),[m,h]=(0,v.useState)(zv),[g,_]=(0,v.useState)(!1),[,y]=(0,v.useState)(0),b=globalThis,x=s.status===`ready`&&b.location?.hash.startsWith(`#/blocks`)?`blocks`:`chats`;qv();let[S,C]=(0,v.useState)(()=>Wv(Yv())),[w]=(0,v.useState)(()=>new Yg),[T]=(0,v.useState)(()=>new mg),[E]=(0,v.useState)(()=>new _g),D=(0,v.useCallback)(e=>E.attach(e),[E]),[ee]=(0,v.useState)([]),[te,ne]=(0,v.useState)(null),[re,ie]=(0,v.useState)(0),[ae,O]=(0,v.useState)(!1),[se,ce]=(0,v.useState)(null),[le,ue]=(0,v.useState)(null),[de,fe]=(0,v.useState)(null),[pe,me]=(0,v.useState)(0),he=(0,v.useCallback)(e=>{if(e===null)return;let t=()=>me(e.offsetHeight);t();let n=globalThis.ResizeObserver;if(n===void 0)return;let r=new n(t);return r.observe(e),()=>r.disconnect()},[]),{view:ge,status:_e,error:ve,frames:ye}=bv(u,{createEventSource:e.createEventSource});Mv(de,ye);let k=m_(t,{busy:ge?.steer.busy??!1,createEventSource:e.createEventSource,onNoticeChanged:(0,v.useCallback)(()=>{ie(e=>e+1)},[]),onSurfaceChanged:(0,v.useCallback)(e=>{T.dispatch(e)},[T]),onChatChanged:(0,v.useCallback)(e=>{E.dispatch(e)},[E])}),A=S.kind===`ext`?S:null,j=A===null?``:Ee(A.params??{}),[M,be]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(A===null){be(null);return}let e=!0;return Oe(A.slug,A.id,j).then(t=>{e&&be({key:j,hash:t})}),()=>{e=!1}},[A,j]);let xe=(0,v.useMemo)(()=>{if(A!==null&&M!==null&&M.key===j)return T.attach({slug:A.slug,id:A.id,params:A.params,...k.streamId===void 0?{}:{streamId:k.streamId}},M.hash)},[A,j,M,T,k.streamId]),Se=(0,v.useMemo)(()=>s.status===`ready`?Ng(f,Sg(s.meta.extensions)):f,[f,s]),Ce=Se!==null&&Se.startsWith(`ext:`)?Se:null,N=(0,v.useMemo)(()=>{if(Ce===null)return null;let[e,t]=Ce.slice(4).split(`/`);return e===void 0||t===void 0||e===``||t===``?null:{slug:e,id:t}},[Ce]),P=(0,v.useMemo)(()=>Ce===null||s.status!==`ready`?{}:Sg(s.meta.extensions).find(e=>`ext:${e.slug}/${e.id}`===Ce)?.perConversation===!0&&u!==null?{conversationId:u}:{},[Ce,s,u]),we=(0,v.useMemo)(()=>Ee(P),[P]),[Te,De]=(0,v.useState)(null),ke=`${Ce??``}:${we}`;(0,v.useEffect)(()=>{if(N===null){De(null);return}let e=!0,t=ke;return Oe(N.slug,N.id,we).then(n=>{e&&De({forKey:t,hash:n})}),()=>{e=!1}},[N,ke,we]);let Ae=(0,v.useMemo)(()=>{if(N!==null&&Te!==null&&Te.forKey===ke)return T.attach({slug:N.slug,id:N.id,params:JSON.parse(we),...k.streamId===void 0?{}:{streamId:k.streamId}},Te.hash)},[N,ke,we,Te,T,k.streamId]);(0,v.useEffect)(()=>{A!==null&&k.noteSurfaceVisible(A.slug,A.id,A.params),N!==null&&k.noteSurfaceVisible(N.slug,N.id,JSON.parse(we))},[A,j,N,we,k.streamId,k.noteSurfaceVisible]);let je=(0,v.useMemo)(()=>{if(N!==null&&s.status===`ready`)return Sg(s.meta.extensions).find(e=>e.slug===N.slug&&e.id===N.id)?.refreshMs},[N,s]),Ne=(0,v.useMemo)(()=>{let e=k.rows.find(e=>e.id===u)?.parent;if(e===void 0)return;let t=k.rows.find(t=>t.id===e.id);return{id:e.id,name:oe(t===void 0?{id:e.id,archived:!1,pinned:!1}:t)}},[k.rows,u]),Pe=(0,v.useMemo)(()=>{let e=[];for(let t of Me(ge?.entries??[]))t.kind===`user`&&e.push({entryId:t.entry.id,text:kh(t.entry)});return e},[ge]),Fe=(0,v.useCallback)(e=>{d(e),_(!1)},[]),Ie=(0,v.useCallback)((e,t)=>{Xv(t),w.remember(Kg(e),t),C(e)},[w]),Le=(0,v.useCallback)(e=>{p(t=>{let n=Mg(t,e);return Fg(n),n})},[]),Re=(0,v.useCallback)(()=>{p(null),Fg(null)},[]),ze=(0,v.useRef)(k.rows);ze.current=k.rows;let Be=(0,v.useRef)(Fe);Be.current=Fe,(0,v.useEffect)(()=>{let e=()=>{let e=Wv(Yv());w.remember(Kg(e),Yv()),C(e),e.kind===`chat`&&e.conversationId!==void 0&&ze.current.some(t=>t.id===e.conversationId)&&Be.current(e.conversationId)};return globalThis.addEventListener?.(`popstate`,e),()=>{globalThis.removeEventListener?.(`popstate`,e)}},[w,k.rows,Fe]);let F=(0,v.useCallback)(e=>{let t=e===void 0?{kind:`settings`}:{kind:`settings`,section:e};Xv(Kv(t)),C(t)},[]),Ve=(0,v.useCallback)(e=>{F(e),_(!1)},[F]),He=(0,v.useCallback)(e=>Ve(e),[Ve]),I=(0,v.useCallback)(e=>{if(e===`settings`)F(void 0);else{let t=w.routeFor(e),n=Wv(t);Ie(n,t),n.kind===`chat`&&n.conversationId!==void 0&&Fe(n.conversationId)}y(e=>e+1),_(!1)},[w,Ie,F,Fe]),L=(0,v.useCallback)(()=>I(`settings`),[I]),[Ue,We]=(0,v.useState)(()=>wg()),Ge=(0,v.useCallback)((e,t)=>{We(n=>s.status===`ready`?Dg(Eg(xg(s.meta.extensions),n),e,t):n)},[s]),Ke=(0,v.useMemo)(()=>s.status===`ready`?Eg(xg(s.meta.extensions),Ue):[],[s,Ue]),qe=(0,v.useMemo)(()=>s.status===`ready`?[...yg(s.meta),...Ke]:[],[s,Ke]),Je=x===`blocks`?null:Kg(S),Ye=(0,v.useMemo)(()=>{if(A!==null)return Ke.find(e=>e.slug===A.slug&&e.id===A.id)?.refreshMs},[A,Ke]),Xe=(0,v.useCallback)(e=>{if(`conversation`in e&&typeof e.conversation==`number`){let t={kind:`chat`,conversationId:e.conversation};Ie(t,Kv(t)),Fe(e.conversation);return}if(`job`in e){let t={kind:`ext`,slug:`core`,id:`jobs`,params:{job:e.job}};Ie(t,Kv(t));return}if(`settings`in e){let t=e.settings;Ve(typeof t==`string`&&t!==``?t:void 0);return}if(`view`in e&&e.view!==null&&typeof e.view==`object`){let t=e.view,n={kind:`ext`,slug:t.extension,id:t.id,params:t.params??{}};Ie(n,Kv(n))}},[Ie,Fe,Ve]),Ze=(0,v.useCallback)(e=>{if(e.params!==void 0){if(A===null)return;let t={kind:`ext`,slug:A.slug,id:A.id,params:e.params};Ie(t,Kv(t));return}let t=e.target;typeof t==`object`&&t&&Xe(t)},[A,Ie,Xe]),z=Sv(t,{refetchToken:re}),Qe=(0,v.useRef)(void 0);(0,v.useEffect)(()=>{Qe.current!==void 0&&k.streamId!==void 0&&k.streamId!==Qe.current&&ie(e=>e+1),Qe.current=k.streamId},[k.streamId]),(0,v.useEffect)(()=>{let e=globalThis.document;if(e?.addEventListener===void 0)return;let t=()=>{e.visibilityState===`visible`&&ie(e=>e+1)};return e.addEventListener(`visibilitychange`,t),()=>e.removeEventListener?.(`visibilitychange`,t)},[]);let $e=(0,v.useCallback)(e=>{let t=k.rows.find(t=>t.id===e);return t===void 0?void 0:oe(t)},[k.rows]),et=(0,v.useCallback)(e=>{ce(e??null),S.kind===`chat`?p(`notices`):O(!0)},[S.kind]),tt=(0,v.useCallback)(()=>{S.kind===`chat`?Le(`notices`):O(e=>!e)},[S.kind,Le]),nt=S.kind===`chat`?f===`notices`:ae,rt=(0,v.useCallback)(e=>{let t={kind:`chat`,conversationId:e};Ie(t,Kv(t)),y(e=>e+1),Fe(e)},[Ie,Fe]);(0,v.useEffect)(()=>{if(s.status!==`ready`||u!==null||S.kind!==`chat`)return;if(S.conversationId!==void 0&&k.rows.some(e=>e.id===S.conversationId)){d(S.conversationId);return}if(k.rows.length===0)return;let e=k.rows.find(e=>e.root)??k.rows[0];d(t=>t??e?.id??null)},[s.status,k.rows,S.kind]),(0,v.useEffect)(()=>{let e=!1;return t.getMeta().then(t=>{e||(t.schemaVersion===`79bdfd95541951f9db86236ee2a2f81cce481a5d8688090837a2bdde83d52c97`?c({status:`ready`,meta:t}):c({status:`refused`,message:`schema mismatch: the server speaks schema ${t.schemaVersion} but this webui bundle is pinned to ${$g}. Rebuild and redeploy the bundle against this server (spec §5).`}))}).catch(t=>{if(e)return;let n=t instanceof Error?t.message:String(t);c({status:`refused`,message:`schema check failed: ${n}. The wire schema is unverifiable, so the webui refuses to render (spec §5).`})}),()=>{e=!0}},[t]),(0,v.useEffect)(()=>{let e=globalThis,t=()=>{y(e=>e+1)};return e.addEventListener?.(`hashchange`,t),()=>e.removeEventListener?.(`hashchange`,t)},[]);let it=(0,v.useCallback)(async(e,n)=>{try{await t.patchConversationMeta(e,{name:n}),await k.reload(),ue(null)}catch(e){ue(`rename failed: ${e instanceof Error?e.message:String(e)}`)}},[t,k.reload]),at=(0,v.useCallback)(async e=>{u!==null&&await it(u,e)},[u,it]),B=(0,v.useCallback)(async(e,n)=>{try{await t.patchConversationMeta(e,{archived:n}),await k.reload(),ue(null)}catch(e){ue(`archive failed: ${e instanceof Error?e.message:String(e)}`)}},[t,k.reload]),ot=(0,v.useCallback)(e=>{t.fork(e).then(async e=>{await k.reload(),Fe(e.id),ue(null)}).catch(e=>ue(`fork failed: ${e instanceof Error?e.message:String(e)}`))},[t,k.reload,Fe]),st=(0,v.useCallback)(()=>{t.createConversation().then(async e=>{await k.reload(),Fe(e.id),ue(null)}).catch(e=>ue(`new conversation failed: ${e instanceof Error?e.message:String(e)}`))},[t,k.reload,Fe]),ct=(0,v.useCallback)(()=>{u!==null&&t.exportConversation(u).then(e=>{Vv(`sigrun-conversation-${u}.jsonl`,e),ue(null)}).catch(e=>ue(`export failed: ${e instanceof Error?e.message:String(e)}`))},[u,t]),lt=(0,v.useCallback)(()=>{u!==null&&t.compact(u).then(()=>ue(null)).catch(e=>ue(`compact failed: ${e instanceof Error?e.message:String(e)}`))},[u,t]),ut=k.rows.find(e=>e.id===u)?.archived===!0,dt=(0,v.useCallback)(()=>{u!==null&&B(u,!ut)},[u,ut,B]),ft=r===void 0?void 0:()=>{t.logout().catch(()=>void 0).finally(()=>r())};return s.status===`loading`?(0,R.jsx)(`div`,{className:`app-boot`,children:(0,R.jsx)(`p`,{children:`sigrun — checking the wire schema…`})}):s.status===`restarting`?(0,R.jsx)(`div`,{className:`app-boot`,role:`status`,children:(0,R.jsx)(`p`,{children:`sigrun — Restarting…`})}):s.status===`refused`?(0,R.jsxs)(`div`,{className:`app-refused`,role:`alert`,children:[(0,R.jsx)(`h1`,{children:`sigrun — refusing to render`}),(0,R.jsx)(`p`,{children:s.message})]}):(0,R.jsxs)(`div`,{className:`app-root`,children:[(0,R.jsxs)(`div`,{className:`side-drawer`,"data-open":g?``:void 0,children:[(0,R.jsx)(Ug,{meta:s.meta,onOpenTab:I,activeTab:Je,onOpenGallery:s.meta.dev?()=>{globalThis.history?.pushState(null,``,`#/blocks`),y(e=>e+1)}:void 0,identity:n,hiddenExtSurfaces:ee,extViewEntries:Ke,onMoveExtView:Ge,onLogout:ft,bell:(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})}),k.error!==null&&(0,R.jsxs)(`p`,{className:`side-error`,role:`alert`,children:[`conversations unavailable: `,k.error]}),S.kind===`chat`&&(0,R.jsx)(a_,{rows:k.rows,activeId:u,onSelect:rt,onNew:st,onRename:it,onArchive:B,onFork:ot,currentUser:n?.user,onShare:ne})]}),x===`blocks`?(0,R.jsxs)(`main`,{className:`main-column`,children:[(0,R.jsxs)(`header`,{className:`phone-header`,children:[(0,R.jsx)(`span`,{className:`phone-header-spacer`}),(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})]}),(0,R.jsx)(rg,{})]}):S.kind===`settings`?(0,R.jsxs)(`main`,{className:`main-column`,"data-route":`settings`,children:[(0,R.jsxs)(`header`,{className:`phone-header`,children:[(0,R.jsx)(`span`,{className:`phone-header-spacer`}),(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})]}),(0,R.jsx)(kv,{arrivals:z.arrivals,visibleConversationId:null,run:z.run,dismiss:e=>void z.dismiss(e),onNavigate:Xe,onOpenPane:et}),(0,R.jsx)(V_,{client:t,prefsState:o,theme:a,admin:n?.admin,section:S.section,onSection:He,onRestart:l})]}):(0,R.jsxs)(`main`,{className:`main-column`,children:[(0,R.jsx)(kv,{arrivals:z.arrivals,visibleConversationId:S.kind===`chat`?u:null,run:z.run,dismiss:e=>void z.dismiss(e),onNavigate:Xe,onOpenPane:et}),S.kind===`chat`&&(0,R.jsx)(Ig,{title:Hv(k.rows,u),timeline:m,onTimeline:()=>h(e=>(Bv(!e),!e)),panel:f,extPanels:Sg(s.meta.extensions),onPanel:Le,onRename:at,onExport:ct,onCompact:lt,onArchive:dt,archived:ut,drawerOpen:g,onToggleDrawer:()=>_(e=>!e),bell:(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})}),S.kind!==`chat`&&(0,R.jsxs)(`header`,{className:`phone-header`,children:[(0,R.jsx)(`span`,{className:`phone-header-spacer`}),(0,R.jsx)(Av,{count:z.notices.length,active:nt,onToggle:tt})]}),le!==null&&(0,R.jsx)(`p`,{className:`shell-error`,role:`alert`,children:le}),(0,R.jsxs)(`div`,{className:`main-body`,children:[A!==null&&xe!==void 0?(0,R.jsx)(sg,{slug:A.slug,id:A.id,hub:T,transport:xe,onNavigate:Ze,...Ye===void 0?{}:{refreshMs:Ye}},`${A.slug}/${A.id}/${k.streamId??`pre-hello`}`):S.kind===`chat`?(0,R.jsxs)(`div`,{className:`chat-column`,children:[(0,R.jsx)(Uv,{activeId:u,view:ge,status:_e,error:ve,showThinking:o.prefs.showThinking,timeline:m,client:t,onNavigate:Fe,parent:Ne,onScrollRoot:fe,dockPadding:pe,attachChatTransport:D}),(0,R.jsx)(`div`,{className:`chat-fade`,"aria-hidden":`true`}),(0,R.jsx)(`footer`,{className:`composer-slot`,ref:he,children:(0,R.jsx)(Vm,{client:t,conversationId:u,view:ge,onNavigate:Fe,onOpenSettings:L,enterToSend:o.prefs.enterToSend,readOnly:k.rows.find(e=>e.id===u)?.access===`read`,inlineNotices:u===null?[]:z.notices.filter(e=>e.conversationId===u),noticeResults:z.results,noticeRun:z.run,noticeDismiss:e=>void z.dismiss(e),onOpenNoticesPane:()=>et(),onAmbientNavigate:Xe})})]}):null,S.kind===`chat`&&(0,R.jsx)(Wg,{selection:Se,...N!==null&&Ae!==void 0?{extContent:(0,R.jsx)(cg,{slug:N.slug,id:N.id,transport:Ae,onNavigate:Ze,...je===void 0?{}:{refreshMs:je}},`${Ce}:${we}`)}:{},outline:(0,R.jsx)(Qg,{scrollRoot:de,turns:Pe}),workspace:(0,R.jsx)(Fv,{client:t,conversationId:u,onClose:Re}),notices:(0,R.jsx)(wv,{variant:`docked`,notices:z.notices,results:z.results,conversationName:$e,run:z.run,dismiss:e=>void z.dismiss(e),dismissAll:()=>void z.dismissAll(),onNavigate:e=>{Xe(e),`conversation`in e&&Re()},scrollTo:se})})]})]}),g&&(0,R.jsx)(`div`,{className:`drawer-backdrop`,onClick:()=>_(!1),"aria-hidden":`true`}),Se!==null&&Se!==`notices`&&(0,R.jsx)(`div`,{className:`panel-backdrop`,onClick:Re,"aria-hidden":`true`}),S.kind!==`chat`&&ae&&(0,R.jsx)(wv,{variant:`overlay`,notices:z.notices,results:z.results,conversationName:$e,run:z.run,dismiss:e=>void z.dismiss(e),dismissAll:()=>void z.dismissAll(),onClose:()=>O(!1),onNavigate:e=>{Xe(e),O(!1)},scrollTo:se}),(0,R.jsx)(zg,{active:Je??`chats`,extViews:qe,onTab:I,...ft===void 0?{}:{onSignOut:ft}}),te!==null&&(()=>{let e=k.rows.find(e=>e.id===te);return e===void 0?null:(0,R.jsx)(`div`,{className:`share-overlay`,onClick:e=>{e.target===e.currentTarget&&ne(null)},children:(0,R.jsx)(c_,{client:t,conversation:e,onClose:()=>ne(null),onSaved:()=>{k.reload()}})})})()]})}function Qv(e={}){let[t,n]=(0,v.useState)(0);return(0,R.jsx)(Zv,{...e,onRestarting:()=>n(e=>e+1)},t)}var $v={invalid_state:`That sign-in link was already used or came from another browser. Start again.`,login_expired:`This sign-in took too long or sigrun restarted. Start again.`,not_allowed:`Your account isn't allowed to use this sigrun.`,isolation_required:`This sigrun can't add another user yet. Ask the admin.`,auth_required:`This sigrun can't add another user yet. Ask the admin.`,account_link_conflict:`That account is already linked to another sigrun user.`,provider_error:`The sign-in provider returned an error. Try again.`,proxy_identity_required:`This sigrun signs people in through its sign-in proxy. Open it through the proxy.`};function ey(e){return $v[e]??`Sign-in failed. Try again.`}function ty(e){let{client:t,message:n,onSuccess:r}=e,[i,a]=(0,v.useState)(``),[o,s]=(0,v.useState)(()=>{let e=globalThis.location?.search??``,t=new URLSearchParams(e).get(`error`);return t===null?null:ey(t)}),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)([]);(0,v.useEffect)(()=>{let e=!1;return t.providers().then(t=>{e||d(t.providers)}).catch(()=>{}),()=>{e=!0}},[t]),(0,v.useEffect)(()=>{let e=globalThis.location?.search??``;if(new URLSearchParams(e).get(`error`)===null)return;let t=globalThis.history,n=globalThis.location?.pathname??`/login`;t?.replaceState(null,``,n)},[]);async function f(){if(i.trim()===``){s(`paste your API token`);return}l(!0),s(null);try{await t.login(i.trim()),r()}catch(e){s(o_(e))}finally{l(!1)}}return(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Sign in to sigrun`}),n!==void 0&&(0,R.jsx)(`p`,{className:`auth-message`,children:n}),u.length>0&&(0,R.jsx)(`div`,{className:`auth-providers`,children:u.map(e=>(0,R.jsx)(`a`,{className:`auth-provider`,href:`/v1/auth/login/${encodeURIComponent(e.provider)}?return=%2F`,children:e.label},e.provider))}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[`API token`,(0,R.jsx)(`input`,{"data-auth-field":`token`,type:`password`,autoComplete:`current-password`,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),f())}})]}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:c,onClick:()=>void f(),children:c?`Signing in…`:`Sign in`}),o!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:o})]})}function ny(e){return!e.startsWith(`/`)||e.startsWith(`//`)||e.includes(`\\`)||/^[A-Za-z][A-Za-z0-9+.-]*:/.test(e)?`/`:e}function ry(e){let{client:t,flowKey:n,reason:r,navigate:i}=e,[a,o]=(0,v.useState)(``),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(null);async function d(){if(a.trim()===``){u(`Enter your code.`);return}c(!0),u(null);try{let e=await t.submitLoginCode(n,a.trim());i(ny(e.returnTo))}catch(e){e instanceof x&&e.error===`invalid_code`?u(`That code didn't work. Check it and try again.`):e instanceof x&&e.error===`login_expired`?u(`This sign-in took too long or sigrun restarted. Start again.`):e instanceof x&&e.error===`not_allowed`?u(`Your account isn't allowed to use this sigrun.`):e instanceof x&&(e.error===`isolation_required`||e.error===`auth_required`)?u(`This sigrun can't add another user yet. Ask the admin.`):u(`Sign-in failed. Try again.`)}finally{c(!1)}}return(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Finish signing in`}),(0,R.jsx)(`p`,{className:`auth-message`,children:r===`setup`?`Enter the setup code to claim this sigrun.`:`Enter your invite code to finish signing in.`}),(0,R.jsxs)(`label`,{className:`auth-field`,children:[r===`setup`?`Setup code`:`Invite code`,(0,R.jsx)(`input`,{"data-auth-field":`login-code`,type:`text`,autoComplete:`one-time-code`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),d())}})]}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,disabled:s,onClick:()=>void d(),children:s?`Signing in…`:`Continue`}),l!==null&&(0,R.jsx)(`p`,{className:`auth-error`,role:`alert`,children:l})]})}function iy(e){let{cause:t,context:n}=e,r=e.reload??(()=>location.reload());return(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`proxy-unidentified`,children:(0,R.jsxs)(`div`,{className:`auth-card`,children:[(0,R.jsx)(`h1`,{children:`Sign-in proxy required`}),n===`session_ended`&&(0,R.jsx)(`p`,{className:`auth-message`,children:`Your session ended.`}),t===`unidentified`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`auth-message`,children:`This sigrun runs behind a sign-in proxy, but the proxy's identity didn't reach sigrun.`}),(0,R.jsx)(`p`,{children:`The proxy's address may be missing from trustedProxies, or the proxy may not be forwarding the identity header. The operator can see the reason in the server log.`})]}):t===`invalid_username`?(0,R.jsx)(`p`,{className:`auth-message`,children:`The proxy supplied an invalid username: the proxy's username has no usable characters.`}):(0,R.jsx)(`p`,{className:`auth-message`,children:`Your account doesn't exist and auto-provisioning is off. Ask the admin to create your account.`}),(0,R.jsx)(`button`,{type:`button`,className:`auth-submit`,onClick:r,children:`Reload`})]})})}var ay=w();function oy(e,t){return new Proxy(e,{get(e,n){let r=e[n];return typeof r==`function`?(...n)=>Promise.resolve().then(()=>r.apply(e,n)).catch(e=>{throw e instanceof x&&e.status===401&&t(),e}):r}})}function sy(e={}){let[t,n]=(0,v.useState)({status:`probing`}),[r,i]=(0,v.useState)(0),a=(0,v.useCallback)(()=>{n(e=>e.status===`ready`?b(e.methods)?{status:`proxy-unidentified`,cause:`unidentified`,context:`session_ended`}:{status:`login`,methods:e.methods,message:`Your session ended. Sign in again.`}:e)},[]),o=(0,v.useMemo)(()=>oy(e.client??ay,a),[e.client,a]);if((0,v.useEffect)(()=>{let e=!1;return(async()=>{let t=await o.getOnboarding().catch(t=>{e||n({status:`failed`,message:t instanceof Error?t.message:String(t)})});if(!(t===void 0||e)){if(t.state===`unclaimed`){n({status:`onboarding`,state:t});return}try{let r=await o.whoami();if(e)return;n({status:`ready`,methods:t.methods,identity:r})}catch(r){if(e)return;if(b(t.methods)&&r instanceof x&&r.status===401){n({status:`proxy-unidentified`,cause:`unidentified`,context:`boot`});return}if(b(t.methods)&&r instanceof x&&r.status===403&&(r.error===`invalid_username`||r.error===`user_not_provisioned`)){n({status:`proxy-unidentified`,cause:r.error===`invalid_username`?`invalid_username`:`not_provisioned`,context:`boot`});return}if(r instanceof x&&r.status===401){n({status:`login`,methods:t.methods});return}n({status:`failed`,message:r instanceof Error?r.message:String(r)})}}})(),()=>{e=!0}},[o,r]),t.status===`probing`)return(0,R.jsx)(`div`,{className:`app-boot`,"data-auth-screen":`probing`,children:(0,R.jsx)(`p`,{children:`sigrun — signing in…`})});if(t.status===`failed`)return(0,R.jsxs)(`div`,{className:`app-refused`,role:`alert`,"data-auth-screen":`failed`,children:[(0,R.jsx)(`h1`,{children:`sigrun — auth check failed`}),(0,R.jsx)(`p`,{children:t.message}),(0,R.jsx)(`button`,{type:`button`,onClick:()=>i(e=>e+1),children:`Retry`})]});let s=globalThis.location;if(s?.pathname===`/login/code`){let e=new URLSearchParams(s.search??``),t=e.get(`key`);if(t!==null)return(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`login-code`,children:(0,R.jsx)(ry,{client:o,flowKey:t,reason:e.get(`reason`)??`invite`,navigate:e=>{s.href!==void 0&&(s.href=e)}})})}return t.status===`onboarding`?b(t.state.methods)&&t.state.codeRequired&&t.state.proxyIdentity===void 0?(0,R.jsx)(iy,{cause:`unidentified`,context:`onboarding`}):(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`onboarding`,children:(0,R.jsx)(A_,{client:o,state:t.state,onClaimed:()=>i(e=>e+1)})}):t.status===`proxy-unidentified`?(0,R.jsx)(iy,{cause:t.cause,context:t.context}):t.status===`login`?(0,R.jsx)(`div`,{className:`auth-screen`,"data-auth-screen":`login`,children:(0,R.jsx)(ty,{client:o,message:t.message,onSuccess:()=>i(e=>e+1)})}):(0,R.jsx)(Qv,{client:o,createEventSource:e.createEventSource,identity:t.identity,onLogout:()=>n({status:`login`,methods:t.methods,message:`Signed out.`})})}var cy=document.getElementById(`root`);if(cy===null)throw Error(`sigrun webui: #root mount point missing from index.html`);(0,y.createRoot)(cy).render((0,R.jsx)(v.StrictMode,{children:(0,R.jsx)(sy,{})}));