@abelxiaoxing/cadence 2.0.45 → 2.0.46

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.
@@ -11,7 +11,7 @@ import{r as e}from"./rolldown-runtime.js";import{n as t,r as n,t as r}from"./rea
11
11
  `)}function sr(e){let t=typeof e==`object`&&!!e&&Object.hasOwn(e,`notice`),n=z(e,[`id`,`revision`,`enabled`,`head`,`proposal`,`runs`,...t?[`notice`]:[]]);return{id:nn(n.id),revision:P(n.revision,0),enabled:F(n.enabled),head:R(n.head,V),proposal:R(n.proposal,Qn),runs:B(n.runs,200,V),...t?{notice:N(n.notice,1024,!0)}:{}}}function cr(e){let t=N(e,64,!0);if(!/^[A-Za-z0-9_-]+$/.test(t))throw new j(`invalid`);return t}var lr=16384,ur=1e3,dr=16384,fr=1024;function pr(e,t){let n=e=>new TextEncoder().encode(JSON.stringify(e)).length;if(n(e)<=t)return e;let r=0,i=Math.min(e.length,t);for(;r<i;){let a=Math.ceil((r+i)/2);n(e.slice(0,a))<=t?r=a:i=a-1}return/[\uD800-\uDBFF]/u.test(e.slice(r-1,r))?e.slice(0,r-1):e.slice(0,r)}function mr(e){let t;try{t=JSON.parse(e)}catch{return``}if(!t||typeof t!=`object`||Array.isArray(t))return``;let n=e=>{let n=Object.hasOwn(t,e)?t[e]:void 0;return typeof n==`string`?n.trim():``},r=n(`command`);return r?r.split(`
12
12
  `,1)[0]:[n(`pattern`),n(`path`)].filter(Boolean).join(` `)}function hr(e,t,n=!1){let r=e.role===`tool`,i=r?``:pr(e.text,dr);return{id:e.id,role:e.role,text:i,...e.images?.length?{images:e.images}:{},clipped:!r&&(n||i!==e.text),name:e.name,target:r?pr(mr(e.args),fr):``,error:e.error,parts:t}}function gr(e){let t=z(e,[`id`,`updatedAt`]);return{id:nn(t.id),updatedAt:P(t.updatedAt,0)}}var _r=[`queued`,`running`,`completed`,`failed`,`canceled`,`timeout`,`unknown`];function vr(e){let t=Object.getOwnPropertyDescriptor(e??{},`kind`)?.value;switch(t){case`conversation-context`:case`conversation-models`:return{kind:t,location:rn(z(e,[`kind`,`location`]).location)};case`conversation-turn`:{let n=z(e,[`kind`,`id`,`leaf`,`ordinal`,`before`]);return{kind:t,id:nn(n.id),leaf:R(n.leaf,cr),ordinal:P(n.ordinal,0),before:R(n.before,e=>P(e,0))}}case`conversation-image`:{let n=z(e,[`kind`,`id`,`leaf`,`entry`,`index`,`offset`,...Object.hasOwn(e??{},`live`)?[`live`]:[]]),r=P(n.offset,0);if(r%Mn.chunkChars||n.live!==void 0&&n.live!==!0)throw new j(`invalid`);return{kind:t,id:nn(n.id),leaf:R(n.leaf,cr),...n.live===void 0?{}:{live:!0},entry:cr(n.entry),index:P(n.index,0),offset:r}}case`conversation-step`:{let n=z(e,[`kind`,`id`,`leaf`,`turnId`,`step`,`part`]);return{kind:t,id:nn(n.id),leaf:R(n.leaf,cr),turnId:cr(n.turnId),step:P(n.step,0),part:P(n.part,0)}}case`cadence-conversation`:return{kind:t,id:nn(z(e,[`kind`,`id`]).id)};case`conversation-tree`:{let n=z(e,[`kind`,`id`,`leaf`]);return{kind:t,id:nn(n.id),leaf:R(n.leaf,cr)}}case`workflow-history`:{let n=Object.hasOwn(e,`scan`),r=z(e,[`kind`,`after`,...n?[`scan`]:[]]);return{kind:t,after:R(r.after,V),...n?{scan:V(r.scan)}:{}}}case`workflow-active`:return z(e,[`kind`]),{kind:t};case`workflow-transcript`:case`workflow-detail`:{let n=z(e,[`kind`,`id`,`stepId`]);return{kind:t,id:V(n.id),stepId:N(n.stepId,160,!0)}}case`workflow`:{let n=z(e,[`kind`,`id`,...Object.hasOwn(e??{},`before`)?[`before`]:[]]);return{kind:t,id:V(n.id),...n.before===void 0?{}:{before:P(n.before,1)}}}case`conversations`:{let n=Object.hasOwn(e,`after`),r=z(e,[`kind`,...n?[`after`]:[]]);return{kind:t,...n?{after:R(r.after,gr)}:{}}}case`conversation-active`:case`projects`:return z(e,[`kind`]),{kind:t};case`conversation`:{let n=z(e,[`kind`,`id`,`leaf`,`known`]);return{kind:t,id:nn(n.id),leaf:R(n.leaf,cr),known:R(n.known,cr)}}default:{let n=(t===`file`||t===`files`)&&Object.hasOwn(e??{},`location`),r=z(e,[`kind`,`path`,...n?[`location`]:[]]);return{kind:I(r.kind,[`files`,`file`,`directories`]),path:N(r.path,4096),...n?{location:rn(r.location)}:{}}}}}function yr(e){let t=Object.getOwnPropertyDescriptor(e??{},`kind`)?.value;if(t===`conversation-model`){let n=z(e,[`kind`,`commandId`,`location`,`expected`,`choice`]);return{kind:t,commandId:V(n.commandId),location:rn(n.location),expected:sn(n.expected),choice:ue(n.choice)}}if(t===`restore-model`||t===`workflow-cancel`){let n=z(e,t===`restore-model`?[`kind`,`commandId`,`epoch`,...Object.hasOwn(e??{},`location`)?[`location`]:[],...Object.hasOwn(e??{},`expected`)||Object.hasOwn(e??{},`choice`)?[`expected`,`choice`]:[]]:[`kind`,`commandId`,`epoch`,`runId`]);if((n.expected!==void 0||n.choice!==void 0)&&n.location===void 0)throw new j(`invalid`);let r=Object.hasOwn(e??{},`expected`)||Object.hasOwn(e??{},`choice`),i={commandId:V(n.commandId),epoch:V(n.epoch)};return t===`restore-model`?{kind:t,...i,...n.location===void 0?{}:{location:rn(n.location)},...r?{expected:sn(n.expected),choice:ue(n.choice)}:{}}:{kind:t,...i,runId:V(n.runId)}}if(t===`cadence-exit`){let n=z(e,[`kind`,`commandId`,`conversationId`,`head`,`revision`,...Object.hasOwn(e??{},`location`)?[`location`]:[]]);return{kind:t,...n.location===void 0?{}:{location:rn(n.location)},commandId:V(n.commandId),conversationId:nn(n.conversationId),head:R(n.head,cr),revision:P(n.revision,0)}}if(t===`image-upload`){let n=z(e,[`kind`,`commandId`,`imageId`,`send`,`mimeType`,`size`,`offset`,`data`]);if(![`send`,`cadence-send`].includes(Object.getOwnPropertyDescriptor(n.send??{},`kind`)?.value))throw new j(`invalid`);let r=yr(n.send);if(r.kind!==`send`&&r.kind!==`cadence-send`||r.images?.length||r.kind===`cadence-send`&&r.intent===`exit`)throw new j(`invalid`);return{kind:t,commandId:V(n.commandId),imageId:V(n.imageId),send:r,mimeType:I(n.mimeType,Nn),size:P(n.size,1),offset:P(n.offset,0),data:N(n.data,Mn.chunkChars,!0)}}if(t===`cadence-send`){let n=z(e,[`kind`,`commandId`,`conversationId`,`head`,`text`,...Object.hasOwn(e??{},`images`)?[`images`]:[],`model`,`revision`,`intent`]);return{kind:t,commandId:V(n.commandId),conversationId:nn(n.conversationId),head:R(n.head,cr),text:N(n.text,lr),...n.images===void 0?{}:{images:B(n.images,2**53-1,V)},model:sn(n.model),revision:P(n.revision,0),intent:I(n.intent,[`message`,`enter`,`exit`])}}if(t===`cadence-prepare`||t===`cadence-approve`){let n=[`kind`,`commandId`,`conversationId`,`revision`,`proposalId`,`digest`],r=z(e,t===`cadence-approve`?[...n,`grant`]:n),i={commandId:V(r.commandId),conversationId:nn(r.conversationId),revision:P(r.revision,0),proposalId:V(r.proposalId),digest:H(r.digest)};return t===`cadence-prepare`?{kind:t,...i}:{kind:t,...i,grant:V(r.grant)}}if(t===`workflow`){let n=z(e,[`kind`,`commandId`,`epoch`,`request`]);return{kind:t,commandId:V(n.commandId),epoch:V(n.epoch),request:$n(n.request)}}if(t===`send`){let n=z(e,[`kind`,`commandId`,`conversationId`,`head`,`text`,...Object.hasOwn(e??{},`images`)?[`images`]:[],`model`]);return{kind:t,commandId:V(n.commandId),conversationId:nn(n.conversationId),head:R(n.head,cr),text:N(n.text,lr),...n.images===void 0?{}:{images:B(n.images,2**53-1,V)},model:sn(n.model)}}if(t===`interrupt`){let n=z(e,[`kind`,`commandId`,`conversationId`,`turnId`,`epoch`]);return{kind:t,commandId:V(n.commandId),conversationId:nn(n.conversationId),turnId:V(n.turnId),epoch:V(n.epoch)}}let n=z(e,[`kind`,`commandId`,`path`,`epoch`]);return{kind:I(n.kind,[`open-project`]),commandId:V(n.commandId),path:N(n.path,4096,!0),epoch:V(n.epoch)}}function br(e){let t=[`id`,`epoch`,`status`,`items`,`notice`],n=typeof e==`object`&&!!e&&Object.hasOwn(e,`omitted`),r=typeof e==`object`&&!!e&&Object.hasOwn(e,`transcript`),i=z(e,[...t,...n?[`omitted`]:[],...r?[`transcript`]:[],...Object.hasOwn(e??{},`execution`)?[`execution`]:[]]),a=r?z(i.transcript,[`pages`]):null,o=n?z(i.omitted,[`thinking`,`media`,`other`]):null;return{...i.execution===void 0?{}:{execution:on(i.execution)},id:V(i.id),epoch:V(i.epoch),status:I(i.status,_r),notice:N(i.notice,1024),...a?{transcript:{pages:P(a.pages,0)}}:{},omitted:{thinking:o?F(o.thinking):!1,media:o?F(o.media):!1,other:o?F(o.other):!1},items:B(i.items,256,Sr)}}function xr(e){return B(e,2**53-1,e=>{let t=z(e,[`entry`,`index`,`mimeType`,...Object.hasOwn(e??{},`live`)?[`live`]:[]]);if(t.live!==void 0&&t.live!==!0)throw new j(`invalid`);return{...t.live===void 0?{}:{live:!0},entry:cr(t.entry),index:P(t.index,0),mimeType:I(t.mimeType,Nn)}})}function Sr(e){let t=z(e,[`id`,`role`,`text`,`name`,`args`,`error`,...Object.hasOwn(e??{},`images`)?[`images`]:[]]);return{...t.images===void 0?{}:{images:xr(t.images)},id:N(t.id,160,!0),role:I(t.role,[`user`,`assistant`,`tool`]),text:N(t.text,262144),name:N(t.name,128),args:N(t.args,65536),error:F(t.error)}}function Cr(e){let t=z(e,[`id`,`role`,`text`,`clipped`,...Object.hasOwn(e??{},`images`)?[`images`]:[],`name`,`target`,`error`,`parts`]),n={...t.images===void 0?{}:{images:xr(t.images)},id:N(t.id,160,!0),role:I(t.role,[`user`,`assistant`,`tool`]),text:N(t.text,dr),clipped:F(t.clipped),name:N(t.name,128),target:N(t.target,fr),error:F(t.error),parts:P(t.parts,0)};if(n.role===`tool`&&(n.text||n.clipped))throw new j(`invalid`);return n}function wr(e){let t=z(e,[`id`,`status`,`notice`,`omitted`,`steps`,`stable`,...Object.hasOwn(e??{},`execution`)?[`execution`]:[],`entry`,`at`]),n=z(t.omitted,[`thinking`,`media`,`other`]),r=P(t.steps,0);return{...t.execution===void 0?{}:{execution:on(t.execution)},id:cr(t.id),entry:R(t.entry,cr),at:P(t.at,0),status:I(t.status,_r),notice:N(t.notice,1024),omitted:{thinking:F(n.thinking),media:F(n.media),other:F(n.other)},steps:r,stable:P(t.stable,0,r)}}function Tr(e){let t=t=>typeof e==`object`&&!!e&&Object.hasOwn(e,t),n=z(e,[`id`,`title`,`leaf`,`status`,`updatedAt`,`origin`,...t(`cadence`)?[`cadence`]:[],...t(`live`)?[`live`]:[]]),r=t(`live`)?z(n.live,[`commandId`,`epoch`]):null;return{id:nn(n.id),title:N(n.title,512,!0),leaf:R(n.leaf,cr),status:I(n.status,_r),updatedAt:P(n.updatedAt,0),origin:I(n.origin,[`terminal`,`webui`]),...t(`cadence`)?{cadence:F(n.cadence)}:{},...r?{live:{commandId:V(r.commandId),epoch:V(r.epoch)}}:{}}}function Er(e){let t=z(e,[`commandId`,`text`,`status`,`notice`]);return{commandId:V(t.commandId),text:N(t.text,16384),status:I(t.status,_r),notice:N(t.notice,1024)}}function Dr(e){let t=z(e,[`id`,`parent`,`text`,`at`,`leaf`,`current`]);return{id:cr(t.id),parent:R(t.parent,cr),text:N(t.text,1024),at:P(t.at,0),leaf:cr(t.leaf),current:F(t.current)}}function Or(e){W(e,524288);let t=Object.getOwnPropertyDescriptor(e??{},`kind`)?.value;if(t===`image-upload`){let n=z(e,[`kind`,`commandId`,`imageId`,`offset`]);return{kind:t,commandId:V(n.commandId),imageId:V(n.imageId),offset:P(n.offset,0)}}if(t===`conversation-image`){let n=z(e,[`kind`,`mimeType`,`data`,`next`]);return{kind:t,mimeType:I(n.mimeType,Nn),data:N(n.data,Mn.chunkChars,!0),next:R(n.next,e=>P(e,0))}}if(t===`conversation-context`)return{kind:t,context:an(z(e,[`kind`,`context`]).context)};if(t===`conversation-models`)return{kind:t,catalog:pn(z(e,[`kind`,`catalog`]).catalog)};if(t===`conversation-model`){let n=z(e,[`kind`,`commandId`,`choice`]);return{kind:t,commandId:V(n.commandId),choice:cn(n.choice)}}if(t===`workflow-transcript`){let n=z(e,[`kind`,`runId`,`stepId`,`turn`]);return{kind:t,runId:V(n.runId),stepId:N(n.stepId,160,!0),turn:R(n.turn,br)}}if(t===`cadence-conversation`)return{kind:t,state:sr(z(e,[`kind`,`state`]).state)};if(t===`workflow-history-progress`){let n=z(e,[`kind`,`after`,`scan`]);return{kind:t,after:R(n.after,V),scan:V(n.scan)}}if(t===`workflow-history`){let n=z(e,[`kind`,`entries`,`next`]),r=B(n.entries,In.historyPage,e=>{let t=z(e,[`id`,`run`]),n=V(t.id),r=R(t.run,er);if(r&&r.id!==n)throw new j(`invalid`);return{id:n,run:r}}),i=R(n.next,V);if(new Set(r.map(e=>e.id)).size!==r.length||i!==null&&i!==r.at(-1)?.id)throw new j(`invalid`);return{kind:t,entries:r,next:i}}if(t===`workflow-active`){let n=typeof e==`object`&&!!e&&Object.hasOwn(e,`links`),r=z(e,[`kind`,`runs`,...n?[`links`]:[]]),i=B(r.runs,4,er),a=n?B(r.links,4,e=>{let t=z(e,[`runId`,`conversationId`]);return{runId:V(t.runId),conversationId:nn(t.conversationId)}}):[];if(new Set(a.map(e=>e.runId)).size!==a.length||a.some(e=>!i.some(t=>t.id===e.runId)))throw new j(`invalid`);return{kind:t,runs:i,links:a}}if(t===`cadence-grant`){let n=z(e,[`kind`,`commandId`,`grant`,`expiresAt`,`revision`,`proposal`]);return{kind:t,commandId:V(n.commandId),grant:V(n.grant),expiresAt:P(n.expiresAt,0),revision:P(n.revision,0),proposal:Qn(n.proposal)}}let n=Object.getOwnPropertyDescriptor(e??{},`kind`)?.value;if(n===`workflow`){let t=z(e,[`kind`,`commandId`,`response`]);return{kind:n,commandId:R(t.commandId,V),response:tr(t.response)}}if(n===`conversation-active`)return{kind:n,entries:B(z(e,[`kind`,`entries`]).entries,8,Tr)};if(n===`conversations`){let t=z(e,[`kind`,`entries`,`next`]);return{kind:n,entries:B(t.entries,200,Tr),next:R(t.next,gr)}}if(n===`conversation`){let t=z(e,[`kind`,`summary`,`leaf`,`continues`,`turns`,`branches`,`runs`,`attempt`,...Object.hasOwn(e??{},`commands`)?[`commands`]:[]]),r=R(t.summary,Tr),i=P(t.turns,0);if(!r&&i)throw new j(`invalid`);return{kind:n,...t.commands===void 0?{}:{commands:B(t.commands,64,V)},summary:r,leaf:R(t.leaf,cr),continues:F(t.continues),turns:i,branches:P(t.branches,0),runs:B(t.runs,200,V),attempt:R(t.attempt,Er)}}if(n===`conversation-tree`){let t=z(e,[`kind`,`conversationId`,`nodes`,`truncated`]);return{kind:n,conversationId:nn(t.conversationId),nodes:B(t.nodes,ur,Dr),truncated:F(t.truncated)}}if(n===`conversation-turn`){let t=z(e,[`kind`,`conversationId`,`leaf`,`ordinal`,`turn`,`start`,`steps`]),r=wr(t.turn),i=P(t.start,0),a=B(t.steps,24,Cr);if(i+a.length>r.steps)throw new j(`invalid`);return{kind:n,conversationId:nn(t.conversationId),leaf:R(t.leaf,cr),ordinal:P(t.ordinal,0),turn:r,start:i,steps:a}}if(n===`conversation-step`){let t=z(e,[`kind`,`conversationId`,`leaf`,`turnId`,`step`,`part`,`item`]);return{kind:n,conversationId:nn(t.conversationId),leaf:R(t.leaf,cr),turnId:cr(t.turnId),step:P(t.step,0),part:P(t.part,0),item:Sr(t.item)}}if(n===`files`||n===`directories`){let t=z(e,[`kind`,`path`,`parent`,`entries`,`limited`]);return{kind:n,path:N(t.path,4096),parent:R(t.parent,e=>N(e,4096)),limited:F(t.limited),entries:B(t.entries,200,e=>{let t=z(e,[`name`,`path`,`directory`]);return{name:N(t.name,1024,!0),path:N(t.path,4096,!0),directory:F(t.directory)}})}}if(n===`file`){let t=z(e,[`kind`,`path`,`text`,`limited`]);return{kind:n,path:N(t.path,4096),text:N(t.text,262144),limited:F(t.limited)}}if(n===`projects`)return{kind:n,entries:B(z(e,[`kind`,`entries`]).entries,128,e=>{let t=z(e,[`path`,`current`]);return{path:N(t.path,4096,!0),current:F(t.current)}})};if(n===`accepted`)return{kind:n,commandId:V(z(e,[`kind`,`commandId`]).commandId)};let r=z(e,[`kind`,`commandId`,`path`,`link`]);return{kind:I(r.kind,[`project`]),commandId:V(r.commandId),path:N(r.path,4096,!0),link:N(r.link,8192,!0)}}var kr={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ar=f.createContext&&f.createContext(kr),jr=[`attr`,`size`,`title`];function Mr(e,t){if(e==null)return{};var n,r,i=Nr(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function Nr(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}function Pr(){return Pr=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Pr.apply(null,arguments)}function Fr(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function Ir(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Fr(Object(n),!0).forEach(function(t){Lr(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Fr(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function Lr(e,t,n){return(t=Rr(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Rr(e){var t=zr(e,`string`);return typeof t==`symbol`?t:t+``}function zr(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Br(e){return e&&e.map((e,t)=>f.createElement(e.tag,Ir({key:t},e.attr),Br(e.child)))}function Q(e){return t=>f.createElement(Vr,Pr({attr:Ir({},e.attr)},t),Br(e.child))}function Vr(e){var t=t=>{var n=e.attr,r=e.size,i=e.title,a=Mr(e,jr),o=r||t.size||`1em`,s;return t.className&&(s=t.className),e.className&&(s=(s?s+` `:``)+e.className),f.createElement(`svg`,Pr({stroke:`currentColor`,fill:`currentColor`,strokeWidth:`0`},t.attr,n,a,{className:s,style:Ir(Ir({color:e.color||t.color},t.style),e.style),height:o,width:o,xmlns:`http://www.w3.org/2000/svg`}),i&&f.createElement(`title`,null,i),e.children)};return Ar===void 0?t(kr):f.createElement(Ar.Consumer,null,e=>t(e))}function Hr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`18`,y1:`6`,x2:`6`,y2:`18`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`6`,x2:`18`,y2:`18`},child:[]}]})(e)}function Ur(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z`},child:[]}]})(e)}function Wr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`},child:[]}]})(e)}function Gr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`3`,x2:`9`,y2:`21`},child:[]}]})(e)}function Kr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`2`,y:`2`,width:`20`,height:`8`,rx:`2`,ry:`2`},child:[]},{tag:`rect`,attr:{x:`2`,y:`14`,width:`20`,height:`8`,rx:`2`,ry:`2`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`6`,x2:`6.01`,y2:`6`},child:[]},{tag:`line`,attr:{x1:`6`,y1:`18`,x2:`6.01`,y2:`18`},child:[]}]})(e)}function qr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`11`,cy:`11`,r:`8`},child:[]},{tag:`line`,attr:{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`},child:[]}]})(e)}function Jr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`23 4 23 10 17 10`},child:[]},{tag:`polyline`,attr:{points:`1 20 1 14 7 14`},child:[]},{tag:`path`,attr:{d:`M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15`},child:[]}]})(e)}function Yr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`5`,x2:`12`,y2:`19`},child:[]},{tag:`line`,attr:{x1:`5`,y1:`12`,x2:`19`,y2:`12`},child:[]}]})(e)}function Xr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`1`},child:[]},{tag:`circle`,attr:{cx:`19`,cy:`12`,r:`1`},child:[]},{tag:`circle`,attr:{cx:`5`,cy:`12`,r:`1`},child:[]}]})(e)}function Zr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z`},child:[]}]})(e)}function Qr(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`3`,y1:`12`,x2:`21`,y2:`12`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`6`,x2:`21`,y2:`6`},child:[]},{tag:`line`,attr:{x1:`3`,y1:`18`,x2:`21`,y2:`18`},child:[]}]})(e)}function $r(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`},child:[]},{tag:`polyline`,attr:{points:`16 17 21 12 16 7`},child:[]},{tag:`line`,attr:{x1:`21`,y1:`12`,x2:`9`,y2:`12`},child:[]}]})(e)}function ei(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71`},child:[]},{tag:`path`,attr:{d:`M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71`},child:[]}]})(e)}function ti(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polygon`,attr:{points:`12 2 2 7 12 12 22 7 12 2`},child:[]},{tag:`polyline`,attr:{points:`2 17 12 22 22 17`},child:[]},{tag:`polyline`,attr:{points:`2 12 12 17 22 12`},child:[]}]})(e)}function ni(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,ry:`2`},child:[]},{tag:`circle`,attr:{cx:`8.5`,cy:`8.5`,r:`1.5`},child:[]},{tag:`polyline`,attr:{points:`21 15 16 10 5 21`},child:[]}]})(e)}function ri(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z`},child:[]},{tag:`polyline`,attr:{points:`9 22 9 12 15 12 15 22`},child:[]}]})(e)}function ii(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`line`,attr:{x1:`2`,y1:`12`,x2:`22`,y2:`12`},child:[]},{tag:`path`,attr:{d:`M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z`},child:[]}]})(e)}function ai(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`6`,y1:`3`,x2:`6`,y2:`15`},child:[]},{tag:`circle`,attr:{cx:`18`,cy:`6`,r:`3`},child:[]},{tag:`circle`,attr:{cx:`6`,cy:`18`,r:`3`},child:[]},{tag:`path`,attr:{d:`M18 9a9 9 0 0 1-9 9`},child:[]}]})(e)}function oi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z`},child:[]}]})(e)}function si(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z`},child:[]},{tag:`polyline`,attr:{points:`13 2 13 9 20 9`},child:[]}]})(e)}function ci(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z`},child:[]},{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`3`},child:[]}]})(e)}function li(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z`},child:[]}]})(e)}function ui(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`path`,attr:{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`},child:[]},{tag:`polyline`,attr:{points:`7 10 12 15 17 10`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`15`,x2:`12`,y2:`3`},child:[]}]})(e)}function di(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,ry:`2`},child:[]},{tag:`rect`,attr:{x:`9`,y:`9`,width:`6`,height:`6`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`1`,x2:`9`,y2:`4`},child:[]},{tag:`line`,attr:{x1:`15`,y1:`1`,x2:`15`,y2:`4`},child:[]},{tag:`line`,attr:{x1:`9`,y1:`20`,x2:`9`,y2:`23`},child:[]},{tag:`line`,attr:{x1:`15`,y1:`20`,x2:`15`,y2:`23`},child:[]},{tag:`line`,attr:{x1:`20`,y1:`9`,x2:`23`,y2:`9`},child:[]},{tag:`line`,attr:{x1:`20`,y1:`14`,x2:`23`,y2:`14`},child:[]},{tag:`line`,attr:{x1:`1`,y1:`9`,x2:`4`,y2:`9`},child:[]},{tag:`line`,attr:{x1:`1`,y1:`14`,x2:`4`,y2:`14`},child:[]}]})(e)}function fi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`15 10 20 15 15 20`},child:[]},{tag:`path`,attr:{d:`M4 4v7a4 4 0 0 0 4 4h12`},child:[]}]})(e)}function pi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`rect`,attr:{x:`9`,y:`9`,width:`13`,height:`13`,rx:`2`,ry:`2`},child:[]},{tag:`path`,attr:{d:`M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1`},child:[]}]})(e)}function mi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`polyline`,attr:{points:`12 6 12 12 16 14`},child:[]}]})(e)}function hi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`18 15 12 9 6 15`},child:[]}]})(e)}function gi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`9 18 15 12 9 6`},child:[]}]})(e)}function _i(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`6 9 12 15 18 9`},child:[]}]})(e)}function vi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`polyline`,attr:{points:`20 6 9 17 4 12`},child:[]}]})(e)}function yi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`19`,x2:`12`,y2:`5`},child:[]},{tag:`polyline`,attr:{points:`5 12 12 5 19 12`},child:[]}]})(e)}function bi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`circle`,attr:{cx:`12`,cy:`12`,r:`10`},child:[]},{tag:`polyline`,attr:{points:`16 12 12 8 8 12`},child:[]},{tag:`line`,attr:{x1:`12`,y1:`16`,x2:`12`,y2:`8`},child:[]}]})(e)}function xi(e){return Q({tag:`svg`,attr:{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`},child:[{tag:`line`,attr:{x1:`12`,y1:`5`,x2:`12`,y2:`19`},child:[]},{tag:`polyline`,attr:{points:`19 12 12 19 5 12`},child:[]}]})(e)}var $=e=>({kind:`error`,error:ee(`unavailable`,e?`uncertain`:`none`)}),Si=class{transport;constructor(e){this.transport=e}async workbenchRead(e,t){let n=vr(e);try{if(!this.transport.workbenchRead)return $(!1);let e=Z(await this.transport.workbenchRead(n,t),Or);return e.kind===`ok`&&n.kind===`conversation-context`&&(e.value.kind!==n.kind||e.value.context.id!==n.location.id)?$(!1):e}catch{return $(!1)}}async workbenchCommand(e){let t=yr(e);try{if(!this.transport.workbenchCommand)return $(!0);let e=Z(await this.transport.workbenchCommand(t),Or);return e.kind===`ok`&&(!(`commandId`in e.value)||e.value.commandId!==t.commandId)?$(!0):e}catch{return $(!0)}}async current(e,t){let n=Jt(e);try{if(!this.transport.current)return $(!1);let e=Z(await this.transport.current(n,t),en);return e.kind===`ok`&&W(e.value.request)!==W(n)?$(!1):e}catch{return $(!1)}}async currentChanges(e,t){let n=Yt(e);try{if(!this.transport.currentChanges)return $(!1);let e=Z(await this.transport.currentChanges(n,t),tn);return e.kind===`ok`&&W(e.value.request)!==W(n)?$(!1):e}catch{return $(!1)}}async activeRuns(e){try{return this.transport.activeRuns?Z(await this.transport.activeRuns(e),Je):$(!1)}catch{return $(!1)}}async models(e,t){try{if(t){let n=await this.workbenchRead({kind:`conversation-models`,location:t},e);return n.kind===`error`?n:n.value.kind===`conversation-models`&&n.value.catalog.version.conversation?.id===t.id?{kind:`ok`,value:n.value.catalog}:$(!1)}return this.transport.models?Z(await this.transport.models(e),pn):$(!1)}catch{return $(!1)}}async chooseModel(e,t){let n=ln(e);try{let e;if(t){let r=await this.workbenchCommand({kind:`conversation-model`,commandId:crypto.randomUUID(),location:t,...n});e=r.kind===`error`?r:r.value.kind===`conversation-model`?{kind:`ok`,value:r.value.choice}:$(!0)}else{if(!this.transport.chooseModel)return $(!1);e=Z(await this.transport.chooseModel(n),cn)}if(e.kind===`ok`){let{sourceSelectionId:r,...i}=e.value.selected??{};if(W(i)!==W(n.choice)||W(e.value.version.conversation??null)!==W(n.expected.conversation??null)||e.value.version.epoch!==n.expected.epoch||e.value.version.accessGeneration!==n.expected.accessGeneration||![n.expected.configRev,n.expected.configRev+1].includes(e.value.version.configRev)||!t&&e.value.version.configRev===n.expected.configRev!=(e.value.version.catalogId===n.expected.catalogId)||t&&e.value.version.configRev!==n.expected.configRev&&e.value.version.catalogId===n.expected.catalogId)return $(!0)}return e}catch{return $(!0)}}async checkObligations(e,t){V(e);try{let n=Z(await this.transport.checkObligations(e,t),Ut);return n.kind===`ok`&&n.value.taskId!==e?$(!1):n}catch{return $(!1)}}task(e,t){return this.entity(`task`,e,t)}message(e,t){return this.entity(`message`,e,t)}tool(e,t){return this.entity(`tool`,e,t)}async entity(e,t,n){let r=Wt({...t,kind:e});try{let e=Z(await this.transport.entity(r,n),Kt);return e.kind===`ok`&&W(e.value.request)!==W(r)?$(!1):e}catch{return $(!1)}}async session(e){try{return Z(await this.transport.session(e),vt)}catch{return $(!1)}}async workspace(e){try{return Z(await this.transport.workspace(e),yt)}catch{return $(!1)}}tasks(e,t){return this.page(`tasks`,e,t)}runs(e,t){return this.page(`runs`,e,t)}messages(e,t){return this.page(`messages`,e,t)}tools(e,t){return this.page(`tools`,e,t)}contents(e,t){return this.page(`contents`,e,t)}events(e,t){return this.page(`events`,e,t)}checks(e,t){return this.page(`checks`,e,t)}changes(e,t){return this.page(`changes`,e,t)}reviews(e,t){return this.page(`reviews`,e,t)}async page(e,t,n){let r=Dt({...t,reader:e});try{let t=Z(await this.transport[e](r,n),Nt);return t.kind===`ok`&&!Pt(r,t.value)?$(!1):t}catch{return $(!1)}}async graph(e,t){let n=Ft(e);try{let e=Z(await this.transport.graph(n,t),Lt);return e.kind===`ok`&&W(e.value.request)!==W(n)?$(!1):e}catch{return $(!1)}}async*export(e,t){let n=Rt(e),r=new Vt(n),i;try{if(t.aborted)throw new j(`unavailable`);for await(let e of this.transport.export(n,t)){if(t.aborted)throw new j(`unavailable`);let n=r.receive(e);n.event.kind===`trailer`?i=n:yield n}if(t.aborted||!i)throw new j(`unavailable`);yield i}catch{throw new j(`unavailable`)}}async preflight(e,t){let n=xe({expected:e,action:t});try{let e=Z(await this.transport.preflight(n),Ee);return e.kind===`ok`&&(W(e.value.preview.version)!==W(n.expected)||W(e.value.preview.action)!==W(n.action))?$(!1):e}catch{return $(!1)}}create(e){return this.execute(`create`,e)}savePlan(e){return this.execute(`save-plan`,e)}generatePlan(e){return this.execute(`generate-plan`,e)}start(e){return this.execute(`start`,e)}check(e){return this.execute(`check`,e)}review(e){return this.execute(`review`,e)}async execute(e,t){let n=Se(t);if(n.action.kind!==e)return{kind:`error`,error:ee(`invalid`)};try{let e=Z(await this.transport.command(n),et);if(e.kind===`ok`){if(e.value.commandId!==n.commandId)return $(!0);tt({identity:{kind:`action`,expected:n.expected,action:n.action},receipt:e.value})}return e}catch{return $(!0)}}async cancel(e){let t=we(e);try{let e=Z(await this.transport.cancel(t),et);if(e.kind===`ok`){if(e.value.commandId!==t.commandId)return $(!0);tt({identity:{kind:`cancel`,epoch:t.epoch,runId:t.runId},receipt:e.value})}return e}catch{return $(!0)}}async receipt(e,t){V(e);try{let n=nt(await this.transport.receipt(e,t));if(n.status===`found`&&n.receipt.commandId!==e)throw Error(`invalid`);return n}catch{return{status:`inconclusive`,error:ee(`receipt-inconclusive`,`uncertain`)}}}async snapshot(e,t){let n=Y(e);try{let e=Z(await this.transport.snapshot(n,t),ot);return e.kind===`ok`&&W(e.value.scope)!==W(n)?$(!1):e}catch{return $(!1)}}async detail(e,t){let n=Ae(e);try{let e=Z(await this.transport.detail(n,t),ut);return e.kind===`ok`&&W(e.value.cursor)!==W(n)?$(!1):e}catch{return $(!1)}}async search(e,t){let n=Ae(e);try{let e=Z(await this.transport.search(n,t),ft);return e.kind===`ok`&&W(e.value.cursor)!==W(n)?$(!1):e}catch{return $(!1)}}},Ci=class{generation=0;snapshotRequest=0;observation;lastSnapshotMs=0;beginSnapshot(){return++this.snapshotRequest}install(e,t,n){if(n!==this.snapshotRequest)return;let r=ot(e),i=this.observation?.snapshot;if(i&&i.storeId===r.storeId&&W(i.scope)===W(r.scope)&&ne(r.committedSeq,i.committedSeq)<0)this.resync();else return this.observation={snapshot:r,connection:`current`,lastObservedMs:t},this.lastSnapshotMs=t,++this.generation}resync(){return this.observation&&(this.observation.connection=`resync`),this.snapshotRequest++,`resync`}get state(){return this.observation&&structuredClone(this.observation)}needsPoll(e){return!this.observation||this.observation.connection===`resync`||e<this.lastSnapshotMs||e-this.lastSnapshotMs>=k.reconcileMs}tick(e){let t=this.observation;t&&t.connection!==`resync`&&(e<t.lastObservedMs||e-t.lastObservedMs>=k.staleMs)&&(t.connection=`stale`)}receive(e,t,n){let r=this.observation;if(!r||t!==this.generation)return`ignored`;if(r.connection===`resync`)return`resync`;let i;try{i=st(e)}catch{return this.resync()}let a=r.snapshot;if(i.storeId!==a.storeId||i.epoch!==a.epoch||W(i.scope)!==W(a.scope))return this.resync();let o=ne(i.committedSeq,a.committedSeq);if(o<0)return`duplicate`;if(i.kind===`heartbeat`)return o>0?this.resync():(r.lastObservedMs=n,r.connection=`current`,`applied`);if(o===0)return`duplicate`;if(i.previousSeq!==a.committedSeq||ht(i.context)!==ht(a.context)||gt(i.context)!==gt(a.context)||i.context.status===`available`&&a.context.status===`available`&&i.context.version.controlRev<a.context.version.controlRev)return this.resync();let s=[...a.runs];for(let e of i.removed){let t=s.findIndex(t=>(t.childRunId??t.runId)===e);if(t===-1||s[t].lifecycle!==`settled`)return this.resync();s.splice(t,1)}for(let e of i.runs){let t=e.childRunId??e.runId,n=s.findIndex(e=>(e.childRunId??e.runId)===t);if(n===-1)s.push(e);else{let t=s[n];if(t.runId!==e.runId||t.childRunId!==e.childRunId||t.assignmentId!==e.assignmentId||W(t.admission)!==W(e.admission))return this.resync();s[n]=e}}if(s.length>k.maxPageEntries)return this.resync();let c={...a,runs:s,context:i.context,committedSeq:i.committedSeq,horizon:{...a.horizon,historicalRuns:{...a.horizon.historicalRuns,snapshotSeq:i.committedSeq}}};try{ot(c)}catch{return this.resync()}return a.runs=s,a.horizon=c.horizon,a.context=i.context,a.committedSeq=i.committedSeq,r.lastObservedMs=n,r.connection=`current`,`applied`}};function wi(e=[],t){if(t!==void 0&&(!Number.isFinite(t)||t<0||t>2147483647))throw RangeError(`invalid abort timeout`);let n=new AbortController,r=new Map,i,a=!1,o=()=>{if(!a){a=!0,clearTimeout(i);for(let[e,t]of r)e.removeEventListener(`abort`,t);r.clear()}},s=e=>{a||(o(),n.abort(e))};for(let t of e){if(!t||r.has(t))continue;if(t.aborted){s(t.reason);break}let e=()=>s(t.reason);r.set(t,e),t.addEventListener(`abort`,e,{once:!0})}return!a&&t!==void 0&&(i=setTimeout(()=>s(new DOMException(`The wait timed out`,`TimeoutError`)),t)),{signal:n.signal,dispose:o}}var Ti={session:`/api/v1/session`,workbenchRead:`/api/v1/workbench/read`,workbenchCommand:`/api/v1/workbench/command`,current:`/api/v1/current`,currentChanges:`/api/v1/current-changes`,activeRuns:`/api/v1/active-runs`,models:`/api/v1/models`,chooseModel:`/api/v1/model-choice`,workspace:`/api/v1/workspace`,tasks:`/api/v1/tasks`,runs:`/api/v1/runs`,messages:`/api/v1/messages`,tools:`/api/v1/tools`,contents:`/api/v1/contents`,events:`/api/v1/history-events`,checks:`/api/v1/checks`,changes:`/api/v1/changes`,reviews:`/api/v1/reviews`,checkObligations:`/api/v1/check-obligations`,entity:`/api/v1/entity`,graph:`/api/v1/graph`,snapshot:`/api/v1/snapshot`,detail:`/api/v1/details`,search:`/api/v1/search`,export:`/api/v1/export`,download:`/api/v1/download`,preflight:`/api/v1/preflight`,command:`/api/v1/commands`,cancel:`/api/v1/cancel`,receipt:`/api/v1/receipt`,detach:`/api/v1/detach`},Ei=`/api/v1/events`,Di=[`tasks`,`runs`,`messages`,`tools`,`contents`,`events`,`checks`,`changes`,`reviews`];function Oi(e,t){if(Di.includes(e)||e===`detail`||e===`search`||e===`entity`||e===`current`||e===`currentChanges`||e===`activeRuns`||e===`workspace`||e===`models`||e===`chooseModel`||e===`workbenchRead`||e===`workbenchCommand`)return k.pageBytes;if(e===`graph`){let e=Object.getOwnPropertyDescriptor(t??{},`kind`)?.value,n=Object.getOwnPropertyDescriptor(t??{},`value`)?.value;if(e===`ok`&&Object.getOwnPropertyDescriptor(n??{},`kind`)?.value===`progress`)return k.pageBytes}return k.controlBytes}function ki(e){return[`preflight`,`command`,`cancel`,`detach`,`chooseModel`,`workbenchCommand`].includes(e)}function Ai(e,t){switch(e){case`workbenchRead`:return vr(t);case`workbenchCommand`:return yr(t);case`session`:case`models`:case`activeRuns`:case`workspace`:case`detach`:if(t!==null)throw new j(`invalid`);return null;case`tasks`:case`runs`:case`messages`:case`tools`:case`contents`:case`events`:case`checks`:case`changes`:case`reviews`:{let n=Dt(t);if(n.reader!==e)throw new j(`invalid`);return n}case`current`:return Jt(t);case`currentChanges`:return Yt(t);case`checkObligations`:case`receipt`:return V(t);case`entity`:return Wt(t);case`graph`:return Ft(t);case`snapshot`:return Y(t);case`detail`:case`search`:return Ae(t);case`export`:case`download`:return Rt(t);case`chooseModel`:return ln(t);case`preflight`:return xe(t);case`command`:return Se(t);case`cancel`:return we(t)}}function ji(e,t){if(Di.includes(e))return Z(t,Nt);switch(e){case`workbenchRead`:case`workbenchCommand`:return Z(t,Or);case`current`:return Z(t,en);case`currentChanges`:return Z(t,tn);case`activeRuns`:return Z(t,Je);case`models`:return Z(t,pn);case`chooseModel`:return Z(t,cn);case`session`:return Z(t,vt);case`workspace`:return Z(t,yt);case`checkObligations`:return Z(t,Ut);case`entity`:return Z(t,Kt);case`graph`:return Z(t,Lt);case`snapshot`:return Z(t,ot);case`detail`:return Z(t,ut);case`search`:return Z(t,ft);case`preflight`:return Z(t,Ee);case`command`:case`cancel`:return Z(t,et);case`receipt`:return nt(t);case`detach`:return Z(t,e=>{if(e!==null)throw new j(`invalid`);return null});default:throw new j(`invalid`)}}function Mi(e){return[...Di,`workbenchRead`,`current`,`currentChanges`,`checkObligations`,`entity`,`graph`,`snapshot`,`detail`,`search`,`export`,`download`,`receipt`].includes(e)}function Ni(e,t){let n=Ti[e];return t===null||ki(e)?n:`${n}?request=${encodeURIComponent(W(t))}`}function Pi(e,t){let n=Ai(e,t),r=typeof n==`object`&&!!n&&Object.hasOwn(n,`navigation`),i=r?Ti[e]:Ni(e,n);return ki(e)||Mi(e)&&(r||te(i)>k.headerBytes/4)?{path:Ti[e],method:`POST`,body:W(n)}:{path:i,method:`GET`}}function Fi(e){W(e,k.viewerBytes);let t=I(Object.getOwnPropertyDescriptor(e,`kind`)?.value,[`snapshot`,`event`,`resync`]);return t===`snapshot`?{kind:t,snapshot:ot(z(e,[`kind`,`snapshot`]).snapshot)}:t===`event`?{kind:t,event:st(z(e,[`kind`,`event`]).event)}:(z(e,[`kind`]),{kind:t})}var Ii=class{options;attachment;csrf=null;fetcher;origin;constructor(e){this.options=e;let t=new URL(e.origin);if(t.origin!==e.origin||t.protocol!==`https:`&&!/^http:\/\/(?:127\.0\.0\.1|\[::1\]):[1-9][0-9]*$/.test(e.origin)||e.project!==void 0&&!/^[a-f0-9]{64}$/.test(e.project))throw new j(`invalid`);this.origin=e.origin,e.build&&=Ze(e.build),this.fetcher=e.fetch??globalThis.fetch.bind(globalThis)}workbenchRead(e,t){return this.request(`workbenchRead`,e,t)}workbenchCommand(e){return this.request(`workbenchCommand`,e)}headers(e){let t={"Cache-Control":`no-store`};if(this.options.build&&(t[`X-Cadence-Build`]=W(this.options.build)),this.attachment&&(t[`X-Cadence-Attachment`]=this.attachment),this.options.localCapability&&(t[`X-Cadence-Local`]=this.options.localCapability),e){if(!this.attachment||!this.options.localCapability&&!this.csrf)throw new j(`stale`);t[`Content-Type`]=`application/json`,this.csrf&&(t[`X-Cadence-CSRF`]=this.csrf)}return t}async request(e,t,n){let r=Pi(e,Ai(e,t)),i=r.method===`POST`,a=this.options.requestTimeoutMs===void 0?void 0:wi([n],this.options.requestTimeoutMs),o=a?.signal??n;try{if(o?.aborted)throw o.reason;let t=await this.fetcher(`${this.origin}${this.options.project?`/projects/${this.options.project}`:``}${r.path}`,{method:r.method,headers:this.headers(i),credentials:`same-origin`,redirect:`error`,signal:o,...i?{body:r.body}:{}}),n;try{e===`session`&&t.ok&&(n=V(t.headers.get(`x-cadence-attachment`)),this.attachment=n)}catch(e){throw await t.body?.cancel().catch(()=>{}),e}let a=await Li(t,Oi(e)),s=ie(a);if(te(a)>Oi(e,s))throw new j(`oversize`);let c=ji(e,s);if(e===`session`){let e=Z(c,vt);if(e.kind===`ok`){if(e.value.authority===`local`!=!!this.options.localCapability)throw new j(`forbidden`);this.attachment=n??V(t.headers.get(`x-cadence-attachment`)),this.csrf=e.value.csrf}}return c}finally{a?.dispose()}}session(e){return this.request(`session`,null,e)}current(e,t){return this.request(`current`,e,t)}currentChanges(e,t){return this.request(`currentChanges`,e,t)}activeRuns(e){return this.request(`activeRuns`,null,e)}models(e){return this.request(`models`,null,e)}chooseModel(e){return this.request(`chooseModel`,ln(e))}workspace(e){return this.request(`workspace`,null,e)}checkObligations(e,t){return this.request(`checkObligations`,V(e),t)}entity(e,t){return this.request(`entity`,Wt(e),t)}tasks(e,t){return this.request(`tasks`,Dt(e),t)}runs(e,t){return this.request(`runs`,Dt(e),t)}messages(e,t){return this.request(`messages`,Dt(e),t)}tools(e,t){return this.request(`tools`,Dt(e),t)}contents(e,t){return this.request(`contents`,Dt(e),t)}events(e,t){return this.request(`events`,Dt(e),t)}checks(e,t){return this.request(`checks`,Dt(e),t)}changes(e,t){return this.request(`changes`,Dt(e),t)}reviews(e,t){return this.request(`reviews`,Dt(e),t)}graph(e,t){return this.request(`graph`,Ft(e),t)}preflight(e){return this.request(`preflight`,xe(e))}command(e){return this.request(`command`,Se(e))}cancel(e){return this.request(`cancel`,we(e))}receipt(e,t){return this.request(`receipt`,V(e),t)}snapshot(e,t){return this.request(`snapshot`,e,t)}detail(e,t){return this.request(`detail`,e,t)}search(e,t){return this.request(`search`,e,t)}async detach(){let e=this.attachment;if(!e)return;let t=Z(await this.request(`detach`,null),e=>{if(e!==null)throw new j(`invalid`);return null});if(t.kind===`error`&&t.error.code!==`stale`&&t.error.code!==`unauthenticated`)throw new j(t.error.code);return this.attachment===e&&(this.attachment=void 0,this.csrf=null),t}async*export(e,t){let n=Pi(`export`,Rt(e)),r=await this.fetcher(`${this.origin}${this.options.project?`/projects/${this.options.project}`:``}${n.path}`,{method:n.method,headers:this.headers(n.method===`POST`),...n.body===void 0?{}:{body:n.body},credentials:`same-origin`,redirect:`error`,signal:t});if(!r.ok||!r.body)throw await r.body?.cancel(),new j(`unavailable`);let i=r.body.getReader(),a=new TextDecoder(`utf-8`,{fatal:!0}),o=``;try{for(;;){let{value:e,done:n}=await i.read();if(t.aborted)throw new j(`unavailable`);for(let t=0;t<(n?1:e.byteLength);t+=k.chunkBytes){o+=n?a.decode():a.decode(e.subarray(t,t+k.chunkBytes),{stream:!0});let r=o.indexOf(`
13
13
  `);for(;r!==-1;){let e=o.slice(0,r);o=o.slice(r+1),yield zt(ie(e,k.controlBytes)),r=o.indexOf(`
14
- `)}if(new TextEncoder().encode(o).length>k.controlBytes)throw new j(`oversize`)}if(n){if(o)throw new j(`invalid`);break}}}finally{await i.cancel().catch(()=>{}),i.releaseLock()}}subscribe(e,t,n){let r=Y(e);if(!this.attachment||!this.options.socket)throw new j(`unavailable`);let i=this.options.socket(`${this.origin.replace(/^http/,`ws`)}${this.options.project?`/projects/${this.options.project}`:``}${Ei}?attachment=${this.attachment}`),a=!1,o=!1,s=Date.now(),c=Date.now(),l=()=>{if(!o){o=!0,a=!1,clearInterval(d);try{i.close()}catch{}u(`closed`)}},u=e=>{try{n(e)}catch{}},d=setInterval(()=>{if(a){Date.now()-s>=k.staleMs&&u(`stale`);try{Date.now()-c>=k.reconcileMs?(i.send(W({kind:`resync`,scope:r})),c=Date.now()):i.send(`{"kind":"ping"}`)}catch{l()}}},k.heartbeatMs);return i.addEventListener(`open`,()=>{if(!o){a=!0;try{i.send(W({kind:`subscribe`,scope:r}))}catch{l()}}}),i.addEventListener(`message`,e=>{if(!o)try{if(typeof e.data!=`string`)throw new j(`invalid`);let n=Fi(ie(e.data,k.viewerBytes));s=Date.now(),u(`current`),t(n)}catch{l()}}),i.addEventListener(`error`,l),i.addEventListener(`close`,l),l}};async function Li(e,t){if(!e.body)throw new j(`invalid`);let n=e.body.getReader(),r=new TextDecoder(`utf-8`,{fatal:!0}),i=0,a=``;try{for(;;){let{value:e,done:o}=await n.read();if(o)return a+r.decode();if(i+=e.byteLength,i>t)throw new j(`oversize`);a+=r.decode(e,{stream:!0})}}finally{await n.cancel().catch(()=>{}),n.releaseLock()}}var Ri={sourceHash:`c4175eef1bd1d98b775484054eed487c3956dc3983a50505df7c506f7952432b`,contractHash:`ee8ae17515fd8baf0aba38eb6a78a27e8c574cda265ddc17884c0741a6fb56b1`,buildId:`1e9f6ba7f993120a45ee35119f586d09377baa18efa2b5607b29842a997f381d`};function zi(e){let t=new Ii({origin:window.location.origin,...e?{project:e}:{},...Ri?{build:{kind:`browser`,...Ri}}:{},socket:e=>new WebSocket(e)});return{client:new Si(t),transport:t}}function Bi(e,t){let n=new URLSearchParams(e).get(`project`),r=new URLSearchParams(t.replace(/^#/,``)).get(`chat`),i=null;try{i=r?nn(r):null}catch{}return{project:n&&/^[a-f0-9]{64}$/.test(n)?n:null,chat:i}}function Vi(e=typeof window>`u`?``:window.location.search){return Bi(e,``).project}function Hi(e=typeof window>`u`?``:window.location.hash){return Bi(``,e).chat}function Ui(){let e=Vi();return e?`/projects/${e}`:``}function Wi(e=typeof window>`u`?``:window.location.hash,t){let n=new URLSearchParams(e.replace(/^#/,``));if(t!==void 0&&Bi(``,e).chat!==t)return{selected:!1,leaf:null};try{return{selected:n.get(`activity`)===`1`,leaf:n.has(`leaf`)?cr(n.get(`leaf`)):null}}catch{return{selected:!1,leaf:null}}}function Gi(e,t){if(e.commandId!==t.commandId)return e;let n=[e.receipt,e.lookup?.status===`found`?e.lookup.receipt:void 0,t.receipt,t.lookup?.status===`found`?t.lookup.receipt:void 0],r,i=!1;for(let t of n)t&&t.commandId===e.commandId&&(r&&(r.operationId!==t.operationId||r.runId!==t.runId||r.created!==null&&r.created.taskId!==t.created?.taskId)||r&&ne(t.committedSeq,r.committedSeq)>0&&(r.created?.state===`published`&&t.created?.state!==`published`||r.admission===`accepted`&&t.admission!==`accepted`||r.execution!==null&&t.execution!==r.execution||r.settlement!==null&&W(t.settlement)!==W(r.settlement))?i=!0:(!r||ne(t.committedSeq,r.committedSeq)>0||W(r)===W(t))&&(r=t));return{commandId:e.commandId,receipt:r,lookup:r?{status:`found`,receipt:r}:t.lookup??e.lookup,error:i?`Conflicting receipt observation refused; prior committed facts preserved.`:r?void 0:t.error??e.error}}function Ki(e,t,n=0){let r=JSON.stringify(t),[i,a]=(0,f.useState)(0),[o,s]=(0,f.useState)({key:r,revision:-1});(0,f.useEffect)(()=>{if(r===`null`)return;let t=new AbortController,a,o=async()=>{let c=await e.workbenchRead(vr(JSON.parse(r)),t.signal);t.signal.aborted||(s(e=>c.kind===`ok`?{key:r,revision:i,value:c.value}:{key:r,revision:i,value:e.key===r?e.value:void 0,error:c.error.code}),n&&(a=setTimeout(()=>void o(),n)))};return o(),()=>{t.abort(),clearTimeout(a)}},[e,r,i,n]);let c=(0,f.useCallback)(()=>a(e=>e+1),[]);return{...o.key===r?o:{},loading:r!==`null`&&(o.key!==r||o.revision!==i),refresh:c}}function qi(e,t){let n=/^\/cadence(?:\s+|$)/.exec(e.trimStart());return n?{mode:`cadence`,text:e.trimStart().slice(n[0].length)}:{mode:t,text:e}}function Ji(e,t){let[n,r]=(0,f.useState)(null),[i,a]=(0,f.useState)([]),o=Ki(e,t?{kind:`conversations`,after:n}:null,n===null?2e3:0),s=o.value?.kind===`conversations`?o.value:void 0;return{value:s,error:o.error,loading:t&&!s&&!o.error,refresh:o.refresh,canPrevious:i.length>0,first:()=>{r(null),a([])},previous:()=>{i.length&&(r(i.at(-1)??null),a(e=>e.slice(0,-1)))},next:()=>{s?.next&&(a(e=>[...e,n]),r(s.next))}}}async function Yi(e){return ie(await Li(e,1048576),1048576)}function Xi(e){return e&&typeof e==`object`&&`kind`in e&&e.kind===`error`&&`error`in e&&e.error&&typeof e.error==`object`&&`code`in e.error?String(e.error.code):`unavailable`}async function Zi(e,t,n){let r=await fetch(e,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:n}),i=await Yi(r);if(!r.ok)throw Error(Xi(i));return t(i)}function Qi(e){return Zi(`/workbench/v1/service`,kn,e)}function $i(e){return Zi(`/workbench/v1/service/release`,An,e)}async function ea(e,t){if(!Ri)throw Error(`unavailable`);let n=await fetch(`/workbench/v1/service`,{method:`POST`,credentials:`same-origin`,redirect:`error`,headers:{"Content-Type":`application/json`,"X-Cadence-CSRF":t,"X-Cadence-Build":JSON.stringify({kind:`browser`,...Ri})},body:JSON.stringify(e)}),r=await Yi(n);if(!n.ok)throw Error(Xi(r));let i=z(r,[`kind`,`job`]);return L(i.kind,`service-job`),En(i.job)}function ta(e,t,n=!0){return!e||e.status===`unavailable`?`unknown`:t||!n?`stale`:e.status}function na(e,t,n){return!t||t.status===`unavailable`?{value:e??t,error:n??`unavailable`}:{value:t,error:void 0}}function ra(e,t){let[n,r]=(0,f.useState)(0),i=(0,f.useRef)(0),a=(0,f.useRef)(0),[o,s]=(0,f.useState)({});(0,f.useEffect)(()=>{if(!e)return;let r=++a.current,i=new AbortController,o=()=>!i.signal.aborted&&a.current===r,c,l=async()=>{if(o()){try{let r=await fetch(`/workbench/v1/projects/${e}`,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:i.signal}),a=await Yi(r);if(!r.ok)throw Error(Xi(a));let c=hn(a);o()&&s(r=>({id:e,revision:n,selectedEpoch:t,...na(r.id===e?r.value:void 0,c)}))}catch(r){o()&&s(i=>({id:e,revision:n,selectedEpoch:t,...na(i.id===e?i.value:void 0,void 0,r instanceof Error?r.message:`unavailable`)}))}o()&&(c=setTimeout(()=>void l(),5e3))}};return l(),()=>{i.abort(),clearTimeout(c)}},[e,n,t]);let c=(0,f.useCallback)(()=>{++a.current;let e=++i.current;return r(e),e},[]),l=t=>{let n=c();s(r=>({id:e,revision:n,selectedEpoch:t,value:{kind:`project-observation`,status:`running`,epoch:t,workspaceId:r.id===e?r.value?.workspaceId??null:null}}))},u=o.id===e?o:{};return{...u,readiness:ta(u.value,u.error,u.revision===n&&u.selectedEpoch===t),refresh:c,prepared:l}}var ia=e=>e===`unauthenticated`||e===`forbidden`,aa=class{api;serial=Promise.resolve();version=0;stopCurrent;pollCurrent;latest;readiness=new Set;nextObservation(){return this.version+1}whenReady(e,t,n=0){return new Promise((r,i)=>{let a=e=>{this.readiness.delete(o),t.removeEventListener(`abort`,s),e?i(e):r()},o=t=>{this.version<n||t.epoch!==e||(t.compatible===!1?a(Error(`unsupported-context`)):t.workspace?.epoch===e&&t.compatible&&!t.error&&t.transportStatus===`current`&&a())},s=()=>a(Error(this.latest?.error??`unavailable`));t.aborted?s():(this.readiness.add(o),t.addEventListener(`abort`,s,{once:!0}),this.latest&&o(this.latest))})}constructor(e){this.api=e}refresh(e=!1){this.pollCurrent?.(e)}observe(e,t){this.stopCurrent?.();let n=++this.version,r=!1,i,a,o,s=new AbortController,c=new Ci,l=0,u=0,d=!1,f=!1,p=0,m=!1,h=!1,g=!1,_={actions:!1,transportStatus:`closed`,attachmentVersion:0};this.latest=_;let v=()=>!r&&n===this.version,y=()=>{if(v()){this.latest={..._,observation:c.state},t(this.latest);for(let e of this.readiness)e(this.latest)}},b=()=>{r||(r=!0,s.abort(),clearInterval(a),clearTimeout(o),u++,i?.(),n===this.version&&(this.pollCurrent=void 0))};this.stopCurrent=b;let x=e=>{this.serial=this.serial.then(e).catch(()=>{v()&&(h=!0,s.abort(),clearInterval(a),clearTimeout(o),u++,i?.(),_.error=`Observation unavailable or detach unconfirmed; explicit re-entry required.`,_.actions=!1,_.transportStatus=`closed`,_.workspace=void 0,c=new Ci,y())})},S=async()=>{await this.api.transport.detach()},C=async(t=!1)=>{if(!v()||!f||d||h)return;d=!0,_.actions=!1;let n=!1;y(),p=Date.now();let r=s.signal;try{let i=async()=>{let e=await this.api.client.session(r);return!v()||r.aborted?!1:e.kind===`error`?(_.actions=!1,_.error=e.error.code,ia(e.error.code)&&w(),!1):(T(e.value),!0)};if(t&&!await i())return;e||(_.transportStatus=`current`);let a=await this.api.client.activeRuns(r);if(!v()||r.aborted)return;if(a.kind===`ok`)_.activeRuns=a.value;else if(ia(a.error.code)){w();return}else _.activeRuns=void 0;y();let o=await this.api.client.workspace(r);if(!v()||r.aborted)return;if(o.kind===`error`){_.error=o.error.code,ia(o.error.code)&&w();return}if(!t&&W(_.workspace?.models??[])!==W(o.value.models)&&!await i())return;if(_.workspace=o.value,e){let t=c.beginSnapshot(),i=await this.api.client.snapshot(e,r);if(!v()||r.aborted)return;if(i.kind===`error`)_.error=i.error.code,ia(i.error.code)&&w();else{let e=c.install(i.value,Date.now(),t);e!==void 0&&(l=e),_.error=void 0,n=!0}}else _.error=void 0,n=!0}catch{v()&&(_.error=`Observation unavailable.`,_.actions=!1,_.transportStatus=`stale`)}finally{d=!1,m=!n,_.actions=n&&g,y()}},w=()=>{h=!0,_.actions=!1,_.transportStatus=`closed`,_.error=`Access revoked; explicit token re-entry required.`,_.workspace=void 0,_.activeRuns=void 0,c=new Ci,s.abort(),clearInterval(a),clearTimeout(o),u++,i?.(),x(S),y()},T=e=>{let t=Ri?{kind:`browser`,...Ri}:null;_.compatible=$e(e.build,t),_.cancelCompatible=$e(e.build,t,!0),g=e.capabilities.actions&&_.compatible},E=async()=>{if(f=!1,await S(),!v()||h)return;let t=await this.api.client.session();if(!v()||h){await S();return}if(t.kind===`error`){h=!0,_.error=`${t.error.code}; explicit re-entry required.`,_.workspace=void 0,c=new Ci,_.actions=!1,y();return}if(f=!0,s=new AbortController,c=new Ci,_={epoch:t.value.epoch,actions:t.value.capabilities.actions,transportStatus:`closed`,attachmentVersion:_.attachmentVersion+1},T(t.value),y(),await C(),!v()||h||!e)return;let n=++u;i=this.api.transport.subscribe(e,e=>{if(v()&&!h&&n===u){if(e.kind===`snapshot`){let t=c.install(e.snapshot,Date.now(),c.beginSnapshot());t!==void 0&&(l=t)}else e.kind===`event`?c.receive(e.event,l,Date.now())===`resync`&&C():C();y()}},e=>{v()&&!h&&n===u&&(_.transportStatus=e,e===`closed`&&(f=!1,_.actions=!1,_.attachmentVersion++,s.abort(),u++,o=setTimeout(()=>x(E),1e3)),y())})};return x(E),this.pollCurrent=e=>{C(e)},a=setInterval(()=>{v()&&!h&&(c.tick(Date.now()),y(),(Date.now()-p>=(m?2e3:3e4)||e&&c.needsPoll(Date.now()))&&C())},1e3),()=>{v()&&(b(),x(S))}}};function oa(e,t,n,r){let i=(0,f.useMemo)(()=>new aa(e),[e]),[a,o]=(0,f.useState)(0),[s,c]=(0,f.useState)({actions:!1,transportStatus:`closed`,attachmentVersion:0}),l=t?.kind,u=t?.id;return(0,f.useEffect)(()=>{if(c({actions:!1,transportStatus:`closed`,attachmentVersion:0}),n)return i.observe(l&&u?{kind:l,id:u}:null,c)},[i,l,u,n,r,a]),{...s,refresh:(e=!1)=>i.refresh(e),whenReady:(e,t,n)=>i.whenReady(e,t,n),reconnect:()=>{let e=i.nextObservation();return o(e=>e+1),e}}}var sa=class{generation=0;identity=``;select(e){e!==this.identity&&(this.identity=e,this.depart())}depart(){this.generation++}ticket(){return this.generation}current(e){return e===this.generation}};function ca({client:e,value:t,onChange:n}){let{t:r,tx:i}=T(),a=(0,f.useRef)(!0),o=(0,f.useRef)(null);(0,f.useEffect)(()=>(a.current=!0,()=>{a.current=!1,o.current?.abort()}),[]);let[s,c]=(0,f.useState)(!1),l=t.receipt??(t.lookup?.status===`found`?t.lookup.receipt:void 0);return(0,h.jsxs)(`section`,{className:`receipt`,"aria-label":r(`Command receipt`),children:[(0,h.jsx)(`h3`,{children:r(`Command receipt`)}),(0,h.jsx)(`code`,{children:t.commandId}),t.error&&(0,h.jsx)(`p`,{role:`alert`,children:i(t.error)}),l&&(0,h.jsxs)(`dl`,{children:[(0,h.jsx)(`dt`,{children:r(`Admission`)}),(0,h.jsx)(`dd`,{children:i(l.admission)}),(0,h.jsx)(`dt`,{children:r(`Execution`)}),(0,h.jsx)(`dd`,{children:l.execution?i(l.execution):r(`not settled`)}),(0,h.jsx)(`dt`,{children:r(`Publication`)}),(0,h.jsx)(`dd`,{children:i(l.publication)}),(0,h.jsx)(`dt`,{children:r(`Run`)}),(0,h.jsx)(`dd`,{children:l.runId??r(`metadata action`)})]}),t.lookup&&t.lookup.status!==`found`&&(0,h.jsx)(`p`,{children:r(`{status}. This observation does not authorize replay.`,{status:i(t.lookup.status)})}),(0,h.jsx)(`button`,{type:`button`,disabled:s,onClick:()=>{c(!0),o.current=new AbortController,e.receipt(t.commandId,o.current.signal).then(e=>{a.current&&(n({commandId:t.commandId,lookup:e}),c(!1))})},children:r(`Observe exact receipt`)})]})}function la(e,t){let n=e??{content:t.content,chunks:[],offset:0},r=n.content,i=t.content;if(r.recordId!==i.recordId||r.version!==i.version||r.field!==i.field||r.sha256!==i.sha256||r.bytes!==i.bytes||n.offset!==(t.range?.start??0))throw Error(`Noncontiguous immutable field`);return{...n,chunks:[...n.chunks,t.text],offset:t.range?.end??0}}function ua(e,t,n){switch(t.reader){case`tasks`:return e.tasks(t,n);case`runs`:return e.runs(t,n);case`messages`:return e.messages(t,n);case`tools`:return e.tools(t,n);case`contents`:return e.contents(t,n);case`events`:return e.events(t,n);case`checks`:return e.checks(t,n);case`changes`:return e.changes(t,n);case`reviews`:return e.reviews(t,n)}}function da(e,t,n,r){return{storeId:e,scope:t,snapshotSeq:n,query:null,recordId:r.recordId,recordVersion:r.version,field:r.field,offset:0}}async function fa(e,t,n){let r={...t,offset:0};delete r.navigation;let i=null,a=!0;for(;r;){if(n.aborted)throw Error(`canceled`);let t=await e.detail(r,n);if(n.aborted)throw Error(`canceled`);if(t.kind===`error`)throw Error(t.error.code);let o=t.value;r=o.next,`kind`in o||(a&&=o.coverage.observed===`complete`,i=la(i,o)),await new Promise(e=>setTimeout(e,0))}if(!i||i.offset!==i.content.bytes)throw Error(`incomplete-content`);return{text:i.chunks.join(``),recordingComplete:a}}function pa(e,t){let n=t?W({reader:t.reader,storeId:t.storeId,scope:t.scope,limit:t.limit}):`absent`,[r,i]=(0,f.useState)(),[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(),[l,u]=(0,f.useState)(t),[d,p]=(0,f.useState)([]),m=(0,f.useRef)(0),[h,g]=(0,f.useState)(n);return h!==n&&(m.current++,g(n),i(void 0),c(void 0),u(t),p([])),(0,f.useEffect)(()=>{let t=++m.current;if(!l){o(!1);return}let n=new AbortController;return o(!0),c(void 0),ua(e,l,n.signal).then(e=>{t===m.current&&(o(!1),e.kind===`error`?c(e.error.code):i(e.value))}).catch(()=>{t===m.current&&(c(`Read unavailable.`),o(!1))}),()=>{n.abort(),m.current++}},[e,l]),{page:r,busy:a,error:s,more:()=>{!a&&r?.next&&(l&&p(e=>[...e,l]),u(r.next))},previous:()=>{!a&&d.length&&(u(d[d.length-1]),p(e=>e.slice(0,-1)))},canPrevious:d.length>0,refresh:()=>{i(void 0),p([]),u(t?{...t}:null)}}}function ma({value:e,compact:t=!1}){let{t:n,tx:r}=T();return t&&e.observed===`complete`&&e.source===`complete`&&!e.redacted&&e.omissions.length===0?(0,h.jsxs)(`details`,{className:`coverage-details`,children:[(0,h.jsx)(`summary`,{children:n(`Recording details`)}),(0,h.jsx)(ma,{value:e})]}):(0,h.jsxs)(`p`,{className:`coverage${e.observed===`complete`&&e.source===`complete`&&!e.redacted&&e.omissions.length===0?``:` partial`}`,children:[n(`Recording: {observed}; source: {source};`,{observed:r(e.observed),source:r(e.source)}),` `,e.redacted?n(`redacted`):n(`no reported redaction`),e.omissions.length>0&&n(`; omitted: {omissions}`,{omissions:e.omissions.map(r).join(`, `)}),n(`. Not a guarantee of complete original source or universal secret detection.`)]})}function ha(e){if(typeof document>`u`)return!1;let t=document.createElement(`textarea`),n=document.activeElement;try{return t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,t.setAttribute(`readonly`,``),document.body.appendChild(t),t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.remove(),n instanceof HTMLElement&&n.isConnected&&n.focus()}}async function ga(e){if(typeof navigator<`u`&&navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)try{return await navigator.clipboard.writeText(e),!0}catch{return ha(e)}return ha(e)}function _a(e={}){let{duration:t=2e3,onSuccess:n,onError:r}=e,i=(0,f.useRef)(!0),[a,o]=(0,f.useState)(!1),s=(0,f.useRef)(null),c=(0,f.useCallback)(()=>{s.current!==null&&(clearTimeout(s.current),s.current=null)},[]),l=(0,f.useCallback)(()=>{c(),o(!1)},[c]);return(0,f.useEffect)(()=>(i.current=!0,()=>{i.current=!1,c()}),[c]),{copied:a,copy:(0,f.useCallback)(async e=>{let a=!1;try{a=await ga(e)}catch(e){a=!1,r&&r(e)}return i.current&&(a?(o(!0),c(),s.current=setTimeout(()=>{o(!1),s.current=null},t),n?.(e)):r&&!a&&r(Error(`Copy failed`))),a},[t,n,r,c]),reset:l}}function va(e){let t=e=>{if(typeof e==`string`||typeof e==`number`){let t=String(e);return t===``?[[]]:t.split(`
14
+ `)}if(new TextEncoder().encode(o).length>k.controlBytes)throw new j(`oversize`)}if(n){if(o)throw new j(`invalid`);break}}}finally{await i.cancel().catch(()=>{}),i.releaseLock()}}subscribe(e,t,n){let r=Y(e);if(!this.attachment||!this.options.socket)throw new j(`unavailable`);let i=this.options.socket(`${this.origin.replace(/^http/,`ws`)}${this.options.project?`/projects/${this.options.project}`:``}${Ei}?attachment=${this.attachment}`),a=!1,o=!1,s=Date.now(),c=Date.now(),l=()=>{if(!o){o=!0,a=!1,clearInterval(d);try{i.close()}catch{}u(`closed`)}},u=e=>{try{n(e)}catch{}},d=setInterval(()=>{if(a){Date.now()-s>=k.staleMs&&u(`stale`);try{Date.now()-c>=k.reconcileMs?(i.send(W({kind:`resync`,scope:r})),c=Date.now()):i.send(`{"kind":"ping"}`)}catch{l()}}},k.heartbeatMs);return i.addEventListener(`open`,()=>{if(!o){a=!0;try{i.send(W({kind:`subscribe`,scope:r}))}catch{l()}}}),i.addEventListener(`message`,e=>{if(!o)try{if(typeof e.data!=`string`)throw new j(`invalid`);let n=Fi(ie(e.data,k.viewerBytes));s=Date.now(),u(`current`),t(n)}catch{l()}}),i.addEventListener(`error`,l),i.addEventListener(`close`,l),l}};async function Li(e,t){if(!e.body)throw new j(`invalid`);let n=e.body.getReader(),r=new TextDecoder(`utf-8`,{fatal:!0}),i=0,a=``;try{for(;;){let{value:e,done:o}=await n.read();if(o)return a+r.decode();if(i+=e.byteLength,i>t)throw new j(`oversize`);a+=r.decode(e,{stream:!0})}}finally{await n.cancel().catch(()=>{}),n.releaseLock()}}var Ri={sourceHash:`099be83aa462f6a3df11b4b97518effafb28cf24bd70af5ddc2f183183c181b8`,contractHash:`ee8ae17515fd8baf0aba38eb6a78a27e8c574cda265ddc17884c0741a6fb56b1`,buildId:`67e998849b4f7edb269938afeb94202d3f5fcf4c9d45cd117405d2995e35492e`};function zi(e){let t=new Ii({origin:window.location.origin,...e?{project:e}:{},...Ri?{build:{kind:`browser`,...Ri}}:{},socket:e=>new WebSocket(e)});return{client:new Si(t),transport:t}}function Bi(e,t){let n=new URLSearchParams(e).get(`project`),r=new URLSearchParams(t.replace(/^#/,``)).get(`chat`),i=null;try{i=r?nn(r):null}catch{}return{project:n&&/^[a-f0-9]{64}$/.test(n)?n:null,chat:i}}function Vi(e=typeof window>`u`?``:window.location.search){return Bi(e,``).project}function Hi(e=typeof window>`u`?``:window.location.hash){return Bi(``,e).chat}function Ui(){let e=Vi();return e?`/projects/${e}`:``}function Wi(e=typeof window>`u`?``:window.location.hash,t){let n=new URLSearchParams(e.replace(/^#/,``));if(t!==void 0&&Bi(``,e).chat!==t)return{selected:!1,leaf:null};try{return{selected:n.get(`activity`)===`1`,leaf:n.has(`leaf`)?cr(n.get(`leaf`)):null}}catch{return{selected:!1,leaf:null}}}function Gi(e,t){if(e.commandId!==t.commandId)return e;let n=[e.receipt,e.lookup?.status===`found`?e.lookup.receipt:void 0,t.receipt,t.lookup?.status===`found`?t.lookup.receipt:void 0],r,i=!1;for(let t of n)t&&t.commandId===e.commandId&&(r&&(r.operationId!==t.operationId||r.runId!==t.runId||r.created!==null&&r.created.taskId!==t.created?.taskId)||r&&ne(t.committedSeq,r.committedSeq)>0&&(r.created?.state===`published`&&t.created?.state!==`published`||r.admission===`accepted`&&t.admission!==`accepted`||r.execution!==null&&t.execution!==r.execution||r.settlement!==null&&W(t.settlement)!==W(r.settlement))?i=!0:(!r||ne(t.committedSeq,r.committedSeq)>0||W(r)===W(t))&&(r=t));return{commandId:e.commandId,receipt:r,lookup:r?{status:`found`,receipt:r}:t.lookup??e.lookup,error:i?`Conflicting receipt observation refused; prior committed facts preserved.`:r?void 0:t.error??e.error}}function Ki(e,t,n=0){let r=JSON.stringify(t),[i,a]=(0,f.useState)(0),[o,s]=(0,f.useState)({key:r,revision:-1});(0,f.useEffect)(()=>{if(r===`null`)return;let t=new AbortController,a,o=async()=>{let c=await e.workbenchRead(vr(JSON.parse(r)),t.signal);t.signal.aborted||(s(e=>c.kind===`ok`?{key:r,revision:i,value:c.value}:{key:r,revision:i,value:e.key===r?e.value:void 0,error:c.error.code}),n&&(a=setTimeout(()=>void o(),n)))};return o(),()=>{t.abort(),clearTimeout(a)}},[e,r,i,n]);let c=(0,f.useCallback)(()=>a(e=>e+1),[]);return{...o.key===r?o:{},loading:r!==`null`&&(o.key!==r||o.revision!==i),refresh:c}}function qi(e,t){let n=/^\/cadence(?:\s+|$)/.exec(e.trimStart());return n?{mode:`cadence`,text:e.trimStart().slice(n[0].length)}:{mode:t,text:e}}function Ji(e,t){let[n,r]=(0,f.useState)(null),[i,a]=(0,f.useState)([]),o=Ki(e,t?{kind:`conversations`,after:n}:null,n===null?2e3:0),s=o.value?.kind===`conversations`?o.value:void 0;return{value:s,error:o.error,loading:t&&!s&&!o.error,refresh:o.refresh,canPrevious:i.length>0,first:()=>{r(null),a([])},previous:()=>{i.length&&(r(i.at(-1)??null),a(e=>e.slice(0,-1)))},next:()=>{s?.next&&(a(e=>[...e,n]),r(s.next))}}}async function Yi(e){return ie(await Li(e,1048576),1048576)}function Xi(e){return e&&typeof e==`object`&&`kind`in e&&e.kind===`error`&&`error`in e&&e.error&&typeof e.error==`object`&&`code`in e.error?String(e.error.code):`unavailable`}async function Zi(e,t,n){let r=await fetch(e,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:n}),i=await Yi(r);if(!r.ok)throw Error(Xi(i));return t(i)}function Qi(e){return Zi(`/workbench/v1/service`,kn,e)}function $i(e){return Zi(`/workbench/v1/service/release`,An,e)}async function ea(e,t){if(!Ri)throw Error(`unavailable`);let n=await fetch(`/workbench/v1/service`,{method:`POST`,credentials:`same-origin`,redirect:`error`,headers:{"Content-Type":`application/json`,"X-Cadence-CSRF":t,"X-Cadence-Build":JSON.stringify({kind:`browser`,...Ri})},body:JSON.stringify(e)}),r=await Yi(n);if(!n.ok)throw Error(Xi(r));let i=z(r,[`kind`,`job`]);return L(i.kind,`service-job`),En(i.job)}function ta(e,t,n=!0){return!e||e.status===`unavailable`?`unknown`:t||!n?`stale`:e.status}function na(e,t,n){return!t||t.status===`unavailable`?{value:e??t,error:n??`unavailable`}:{value:t,error:void 0}}function ra(e,t){let[n,r]=(0,f.useState)(0),i=(0,f.useRef)(0),a=(0,f.useRef)(0),[o,s]=(0,f.useState)({});(0,f.useEffect)(()=>{if(!e)return;let r=++a.current,i=new AbortController,o=()=>!i.signal.aborted&&a.current===r,c,l=async()=>{if(o()){try{let r=await fetch(`/workbench/v1/projects/${e}`,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:i.signal}),a=await Yi(r);if(!r.ok)throw Error(Xi(a));let c=hn(a);o()&&s(r=>({id:e,revision:n,selectedEpoch:t,...na(r.id===e?r.value:void 0,c)}))}catch(r){o()&&s(i=>({id:e,revision:n,selectedEpoch:t,...na(i.id===e?i.value:void 0,void 0,r instanceof Error?r.message:`unavailable`)}))}o()&&(c=setTimeout(()=>void l(),5e3))}};return l(),()=>{i.abort(),clearTimeout(c)}},[e,n,t]);let c=(0,f.useCallback)(()=>{++a.current;let e=++i.current;return r(e),e},[]),l=t=>{let n=c();s(r=>({id:e,revision:n,selectedEpoch:t,value:{kind:`project-observation`,status:`running`,epoch:t,workspaceId:r.id===e?r.value?.workspaceId??null:null}}))},u=o.id===e?o:{};return{...u,readiness:ta(u.value,u.error,u.revision===n&&u.selectedEpoch===t),refresh:c,prepared:l}}var ia=e=>e===`unauthenticated`||e===`forbidden`,aa=class{api;serial=Promise.resolve();version=0;stopCurrent;pollCurrent;latest;readiness=new Set;nextObservation(){return this.version+1}whenReady(e,t,n=0){return new Promise((r,i)=>{let a=e=>{this.readiness.delete(o),t.removeEventListener(`abort`,s),e?i(e):r()},o=t=>{this.version<n||t.epoch!==e||(t.compatible===!1?a(Error(`unsupported-context`)):t.workspace?.epoch===e&&t.compatible&&!t.error&&t.transportStatus===`current`&&a())},s=()=>a(Error(this.latest?.error??`unavailable`));t.aborted?s():(this.readiness.add(o),t.addEventListener(`abort`,s,{once:!0}),this.latest&&o(this.latest))})}constructor(e){this.api=e}refresh(e=!1){this.pollCurrent?.(e)}observe(e,t){this.stopCurrent?.();let n=++this.version,r=!1,i,a,o,s=new AbortController,c=new Ci,l=0,u=0,d=!1,f=!1,p=0,m=!1,h=!1,g=!1,_={actions:!1,transportStatus:`closed`,attachmentVersion:0};this.latest=_;let v=()=>!r&&n===this.version,y=()=>{if(v()){this.latest={..._,observation:c.state},t(this.latest);for(let e of this.readiness)e(this.latest)}},b=()=>{r||(r=!0,s.abort(),clearInterval(a),clearTimeout(o),u++,i?.(),n===this.version&&(this.pollCurrent=void 0))};this.stopCurrent=b;let x=e=>{this.serial=this.serial.then(e).catch(()=>{v()&&(h=!0,s.abort(),clearInterval(a),clearTimeout(o),u++,i?.(),_.error=`Observation unavailable or detach unconfirmed; explicit re-entry required.`,_.actions=!1,_.transportStatus=`closed`,_.workspace=void 0,c=new Ci,y())})},S=async()=>{await this.api.transport.detach()},C=async(t=!1)=>{if(!v()||!f||d||h)return;d=!0,_.actions=!1;let n=!1;y(),p=Date.now();let r=s.signal;try{let i=async()=>{let e=await this.api.client.session(r);return!v()||r.aborted?!1:e.kind===`error`?(_.actions=!1,_.error=e.error.code,ia(e.error.code)&&w(),!1):(T(e.value),!0)};if(t&&!await i())return;e||(_.transportStatus=`current`);let a=await this.api.client.activeRuns(r);if(!v()||r.aborted)return;if(a.kind===`ok`)_.activeRuns=a.value;else if(ia(a.error.code)){w();return}else _.activeRuns=void 0;y();let o=await this.api.client.workspace(r);if(!v()||r.aborted)return;if(o.kind===`error`){_.error=o.error.code,ia(o.error.code)&&w();return}if(!t&&W(_.workspace?.models??[])!==W(o.value.models)&&!await i())return;if(_.workspace=o.value,e){let t=c.beginSnapshot(),i=await this.api.client.snapshot(e,r);if(!v()||r.aborted)return;if(i.kind===`error`)_.error=i.error.code,ia(i.error.code)&&w();else{let e=c.install(i.value,Date.now(),t);e!==void 0&&(l=e),_.error=void 0,n=!0}}else _.error=void 0,n=!0}catch{v()&&(_.error=`Observation unavailable.`,_.actions=!1,_.transportStatus=`stale`)}finally{d=!1,m=!n,_.actions=n&&g,y()}},w=()=>{h=!0,_.actions=!1,_.transportStatus=`closed`,_.error=`Access revoked; explicit token re-entry required.`,_.workspace=void 0,_.activeRuns=void 0,c=new Ci,s.abort(),clearInterval(a),clearTimeout(o),u++,i?.(),x(S),y()},T=e=>{let t=Ri?{kind:`browser`,...Ri}:null;_.compatible=$e(e.build,t),_.cancelCompatible=$e(e.build,t,!0),g=e.capabilities.actions&&_.compatible},E=async()=>{if(f=!1,await S(),!v()||h)return;let t=await this.api.client.session();if(!v()||h){await S();return}if(t.kind===`error`){h=!0,_.error=`${t.error.code}; explicit re-entry required.`,_.workspace=void 0,c=new Ci,_.actions=!1,y();return}if(f=!0,s=new AbortController,c=new Ci,_={epoch:t.value.epoch,actions:t.value.capabilities.actions,transportStatus:`closed`,attachmentVersion:_.attachmentVersion+1},T(t.value),y(),await C(),!v()||h||!e)return;let n=++u;i=this.api.transport.subscribe(e,e=>{if(v()&&!h&&n===u){if(e.kind===`snapshot`){let t=c.install(e.snapshot,Date.now(),c.beginSnapshot());t!==void 0&&(l=t)}else e.kind===`event`?c.receive(e.event,l,Date.now())===`resync`&&C():C();y()}},e=>{v()&&!h&&n===u&&(_.transportStatus=e,e===`closed`&&(f=!1,_.actions=!1,_.attachmentVersion++,s.abort(),u++,o=setTimeout(()=>x(E),1e3)),y())})};return x(E),this.pollCurrent=e=>{C(e)},a=setInterval(()=>{v()&&!h&&(c.tick(Date.now()),y(),(Date.now()-p>=(m?2e3:3e4)||e&&c.needsPoll(Date.now()))&&C())},1e3),()=>{v()&&(b(),x(S))}}};function oa(e,t,n,r){let i=(0,f.useMemo)(()=>new aa(e),[e]),[a,o]=(0,f.useState)(0),[s,c]=(0,f.useState)({actions:!1,transportStatus:`closed`,attachmentVersion:0}),l=t?.kind,u=t?.id;return(0,f.useEffect)(()=>{if(c({actions:!1,transportStatus:`closed`,attachmentVersion:0}),n)return i.observe(l&&u?{kind:l,id:u}:null,c)},[i,l,u,n,r,a]),{...s,refresh:(e=!1)=>i.refresh(e),whenReady:(e,t,n)=>i.whenReady(e,t,n),reconnect:()=>{let e=i.nextObservation();return o(e=>e+1),e}}}var sa=class{generation=0;identity=``;select(e){e!==this.identity&&(this.identity=e,this.depart())}depart(){this.generation++}ticket(){return this.generation}current(e){return e===this.generation}};function ca({client:e,value:t,onChange:n}){let{t:r,tx:i}=T(),a=(0,f.useRef)(!0),o=(0,f.useRef)(null);(0,f.useEffect)(()=>(a.current=!0,()=>{a.current=!1,o.current?.abort()}),[]);let[s,c]=(0,f.useState)(!1),l=t.receipt??(t.lookup?.status===`found`?t.lookup.receipt:void 0);return(0,h.jsxs)(`section`,{className:`receipt`,"aria-label":r(`Command receipt`),children:[(0,h.jsx)(`h3`,{children:r(`Command receipt`)}),(0,h.jsx)(`code`,{children:t.commandId}),t.error&&(0,h.jsx)(`p`,{role:`alert`,children:i(t.error)}),l&&(0,h.jsxs)(`dl`,{children:[(0,h.jsx)(`dt`,{children:r(`Admission`)}),(0,h.jsx)(`dd`,{children:i(l.admission)}),(0,h.jsx)(`dt`,{children:r(`Execution`)}),(0,h.jsx)(`dd`,{children:l.execution?i(l.execution):r(`not settled`)}),(0,h.jsx)(`dt`,{children:r(`Publication`)}),(0,h.jsx)(`dd`,{children:i(l.publication)}),(0,h.jsx)(`dt`,{children:r(`Run`)}),(0,h.jsx)(`dd`,{children:l.runId??r(`metadata action`)})]}),t.lookup&&t.lookup.status!==`found`&&(0,h.jsx)(`p`,{children:r(`{status}. This observation does not authorize replay.`,{status:i(t.lookup.status)})}),(0,h.jsx)(`button`,{type:`button`,disabled:s,onClick:()=>{c(!0),o.current=new AbortController,e.receipt(t.commandId,o.current.signal).then(e=>{a.current&&(n({commandId:t.commandId,lookup:e}),c(!1))})},children:r(`Observe exact receipt`)})]})}function la(e,t){let n=e??{content:t.content,chunks:[],offset:0},r=n.content,i=t.content;if(r.recordId!==i.recordId||r.version!==i.version||r.field!==i.field||r.sha256!==i.sha256||r.bytes!==i.bytes||n.offset!==(t.range?.start??0))throw Error(`Noncontiguous immutable field`);return{...n,chunks:[...n.chunks,t.text],offset:t.range?.end??0}}function ua(e,t,n){switch(t.reader){case`tasks`:return e.tasks(t,n);case`runs`:return e.runs(t,n);case`messages`:return e.messages(t,n);case`tools`:return e.tools(t,n);case`contents`:return e.contents(t,n);case`events`:return e.events(t,n);case`checks`:return e.checks(t,n);case`changes`:return e.changes(t,n);case`reviews`:return e.reviews(t,n)}}function da(e,t,n,r){return{storeId:e,scope:t,snapshotSeq:n,query:null,recordId:r.recordId,recordVersion:r.version,field:r.field,offset:0}}async function fa(e,t,n){let r={...t,offset:0};delete r.navigation;let i=null,a=!0;for(;r;){if(n.aborted)throw Error(`canceled`);let t=await e.detail(r,n);if(n.aborted)throw Error(`canceled`);if(t.kind===`error`)throw Error(t.error.code);let o=t.value;r=o.next,`kind`in o||(a&&=o.coverage.observed===`complete`,i=la(i,o)),await new Promise(e=>setTimeout(e,0))}if(!i||i.offset!==i.content.bytes)throw Error(`incomplete-content`);return{text:i.chunks.join(``),recordingComplete:a}}function pa(e,t){let n=t?W({reader:t.reader,storeId:t.storeId,scope:t.scope,limit:t.limit}):`absent`,[r,i]=(0,f.useState)(),[a,o]=(0,f.useState)(!1),[s,c]=(0,f.useState)(),[l,u]=(0,f.useState)(t),[d,p]=(0,f.useState)([]),m=(0,f.useRef)(0),[h,g]=(0,f.useState)(n);return h!==n&&(m.current++,g(n),i(void 0),c(void 0),u(t),p([])),(0,f.useEffect)(()=>{let t=++m.current;if(!l){o(!1);return}let n=new AbortController;return o(!0),c(void 0),ua(e,l,n.signal).then(e=>{t===m.current&&(o(!1),e.kind===`error`?c(e.error.code):i(e.value))}).catch(()=>{t===m.current&&(c(`Read unavailable.`),o(!1))}),()=>{n.abort(),m.current++}},[e,l]),{page:r,busy:a,error:s,more:()=>{!a&&r?.next&&(l&&p(e=>[...e,l]),u(r.next))},previous:()=>{!a&&d.length&&(u(d[d.length-1]),p(e=>e.slice(0,-1)))},canPrevious:d.length>0,refresh:()=>{i(void 0),p([]),u(t?{...t}:null)}}}function ma({value:e,compact:t=!1}){let{t:n,tx:r}=T();return t&&e.observed===`complete`&&e.source===`complete`&&!e.redacted&&e.omissions.length===0?(0,h.jsxs)(`details`,{className:`coverage-details`,children:[(0,h.jsx)(`summary`,{children:n(`Recording details`)}),(0,h.jsx)(ma,{value:e})]}):(0,h.jsxs)(`p`,{className:`coverage${e.observed===`complete`&&e.source===`complete`&&!e.redacted&&e.omissions.length===0?``:` partial`}`,children:[n(`Recording: {observed}; source: {source};`,{observed:r(e.observed),source:r(e.source)}),` `,e.redacted?n(`redacted`):n(`no reported redaction`),e.omissions.length>0&&n(`; omitted: {omissions}`,{omissions:e.omissions.map(r).join(`, `)}),n(`. Not a guarantee of complete original source or universal secret detection.`)]})}function ha(e){if(typeof document>`u`)return!1;let t=document.createElement(`textarea`),n=document.activeElement;try{return t.value=e,t.style.position=`fixed`,t.style.left=`-9999px`,t.setAttribute(`readonly`,``),document.body.appendChild(t),t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.remove(),n instanceof HTMLElement&&n.isConnected&&n.focus()}}async function ga(e){if(typeof navigator<`u`&&navigator.clipboard&&typeof navigator.clipboard.writeText==`function`)try{return await navigator.clipboard.writeText(e),!0}catch{return ha(e)}return ha(e)}function _a(e={}){let{duration:t=2e3,onSuccess:n,onError:r}=e,i=(0,f.useRef)(!0),[a,o]=(0,f.useState)(!1),s=(0,f.useRef)(null),c=(0,f.useCallback)(()=>{s.current!==null&&(clearTimeout(s.current),s.current=null)},[]),l=(0,f.useCallback)(()=>{c(),o(!1)},[c]);return(0,f.useEffect)(()=>(i.current=!0,()=>{i.current=!1,c()}),[c]),{copied:a,copy:(0,f.useCallback)(async e=>{let a=!1;try{a=await ga(e)}catch(e){a=!1,r&&r(e)}return i.current&&(a?(o(!0),c(),s.current=setTimeout(()=>{o(!1),s.current=null},t),n?.(e)):r&&!a&&r(Error(`Copy failed`))),a},[t,n,r,c]),reset:l}}function va(e){let t=e=>{if(typeof e==`string`||typeof e==`number`){let t=String(e);return t===``?[[]]:t.split(`
15
15
  `).map(e=>e===``?[]:[e])}if(Array.isArray(e)){let n=[];for(let r of e){let e=t(r);if(n.length===0)n=e;else{let t=e[0]??[];n[n.length-1].push(...t),n.push(...e.slice(1))}}return n}if(e&&typeof e==`object`&&`props`in e){let n=e,r=n.props?.children,i={...n.props,children:void 0},a=r==null?[]:t(r);return a.length===0?[[(0,f.createElement)(n.type,i)]]:a.map(e=>[(0,f.createElement)(n.type,i,...e)])}return[[e]]},n=t(e);return n.length>1&&n[n.length-1].length===0&&n.pop(),n}var ya=function(){let e=this.data();e.micromarkExtensions??=[],e.micromarkExtensions.push({flow:{92:ba(!0)},text:{92:ba(!1)}});let t={enter:{backslashMathInline:xa,backslashMathDisplay:xa,backslashMathBlock:xa},exit:{backslashMathInline:Sa,backslashMathDisplay:Sa,backslashMathBlock:Sa}};e.fromMarkdownExtensions??=[],e.fromMarkdownExtensions.push(t)};function ba(e){return{tokenize:function(t,n,r){let i=this,a=93,o=e?`backslashMathBlock`:`backslashMathDisplay`,s;return c;function c(e){return e===92?(s=t.enter(o),t.consume(e),l):r(e)}function l(n){return n!==91&&(e||n!==40)?r(n):(a=n===91?93:41,!e&&n===40&&(o=`backslashMathInline`,s.type=o),t.consume(n),u)}function u(n){return n===null||e&&i.parser.lazy[i.now().line]?r(n):n===-5||n===-4||n===-3?(t.enter(`lineEnding`),t.consume(n),t.exit(`lineEnding`),u):(f(n),n===92?d:u)}function d(i){return i===a?(f(i),t.exit(o),e?p:n):i===null?r(i):i===-5||i===-4||i===-3?u(i):(f(i),u)}function f(e){t.enter(`backslashMathData`),t.consume(e),t.exit(`backslashMathData`)}function p(e){return e===null||e===-5||e===-4||e===-3?n(e):e===32||e===-2||e===-1?(t.enter(`whitespace`),t.consume(e),t.exit(`whitespace`),p):r(e)}},concrete:e,name:e?`backslashMathBlock`:`backslashMathText`}}var xa=function(e){let t=e.type===`backslashMathBlock`,n=e.type!==`backslashMathInline`,r=this.sliceSerialize(e).slice(2,-2).trim(),i={type:`element`,tagName:`code`,properties:{className:[`language-math`,n?`math-display`:`math-inline`]},children:[{type:`text`,value:r}]},a=t?{type:`math`,meta:null,value:r,data:{hName:`pre`,hChildren:[i]}}:{type:`inlineMath`,value:r,data:{hName:`code`,hProperties:i.properties,hChildren:i.children}};this.enter(a,e)},Sa=function(e){this.exit(e)},Ca=(0,f.memo)(function({text:e}){let{t}=T(),[n,r]=(0,f.useState)(!1),{copied:i,copy:a}=_a();return(0,h.jsxs)(`button`,{type:`button`,className:`copy-btn`,title:t(`Copy displayed text`),"aria-label":t(`Copy displayed text`),onClick:()=>{r(!1),a(e).then(e=>r(!e))},children:[i?(0,h.jsx)(vi,{}):(0,h.jsx)(pi,{}),n&&t(`Copy unavailable`)]})}),wa=[s,d,ya],Ta=[s,l,d,ya],Ea=[[c,{strict:!1,throwOnError:!1,trust:!1,maxExpand:1e3}],[u,{detect:!1,ignoreMissing:!0}]];function Da(e){if(e.startsWith(`#`)&&![...e].some(e=>e.charCodeAt(0)<=32))return e;try{let t=new URL(e);return![`https:`,`http:`].includes(t.protocol)||t.username||t.password||t.searchParams.has(`token`)?void 0:e}catch{return}}function Oa({text:e,rawHtml:t=!1,hardBreaks:n=!1}){return(0,h.jsx)(a,{remarkPlugins:n?Ta:wa,rehypePlugins:t?[i,o,...Ea]:Ea,skipHtml:!t,disallowedElements:[`iframe`,`object`,`embed`,`script`,`style`,`video`,`audio`,`source`,`form`,`input`],components:{pre:ja,a:Aa,img:({alt:e})=>(0,h.jsxs)(`span`,{className:`omission`,children:[`[Image omitted: `,e||`external/media content`,`]`]})},children:e})}var ka=(0,f.memo)(function(e){return(0,h.jsx)(`div`,{className:`md`,children:(0,h.jsx)(Oa,{...e})})});function Aa({href:e,children:t}){let n=e&&Da(e);return n?(0,h.jsx)(`a`,{href:n,target:n.startsWith(`#`)?void 0:`_blank`,rel:`noreferrer noopener`,referrerPolicy:`no-referrer`,children:t}):(0,h.jsxs)(`span`,{children:[t,` [link unavailable]`]})}function ja({children:e,node:t,...n}){let r=e&&typeof e==`object`&&`props`in e?e.props?.children:e,i=0,a=va(r).map(e=>{let t=`code-offset:${i}`;return i+=Ma(e).length+1,{key:t,nodes:e}}),o=a.length>1,s=o?`${String(a.length).length+1}ch`:void 0;return(0,h.jsxs)(`div`,{className:`codeblock`,children:[(0,h.jsx)(Ca,{text:Ma(e)}),(0,h.jsx)(`pre`,{...n,children:a.map(({nodes:e,key:t},n)=>(0,h.jsxs)(`div`,{className:`code-line`,children:[o&&(0,h.jsx)(`span`,{className:`code-num`,style:s?{width:s}:void 0,children:n+1}),(0,h.jsx)(`code`,{className:`code-line-body hljs`,children:e})]},t))})]})}function Ma(e){if(typeof e==`string`)return e;if(Array.isArray(e))return e.map(Ma).join(``);if(e&&typeof e==`object`&&`props`in e){let t=e.props;return Ma(t?.children)}return``}function Na(e,t){let n=[],r=t;if(!r)return n;let i=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,{acceptNode(e){let t=e.parentElement;return!t||t.closest(`.search-bar`)||t.closest(`.msg-collapsed`)?NodeFilter.FILTER_REJECT:(e.textContent??``).includes(r)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(let e=i.nextNode();e;e=i.nextNode()){let t=e.textContent??``;if(!e.parentElement?.closest(`[data-retained-field]`))continue;let i=t.indexOf(r);for(;i!==-1;){let a=document.createRange();if(a.setStart(e,i),a.setEnd(e,i+r.length),n.push(a),n.length===1e3)return n;i=t.indexOf(r,i+r.length)}}return n}var Pa=new Map;function Fa(e,t){t.length?Pa.set(e,t):Pa.delete(e);let n=e.endsWith(`-active`);e=n?`cadence-page-active`:`cadence-page`,t=[...Pa].filter(([e])=>e.endsWith(`-active`)===n).flatMap(([,e])=>e);let r=CSS;if(!r.highlights)return;if(t.length===0){r.highlights.delete(e);return}let i=window.Highlight;i&&r.highlights.set(e,new i(...t))}function Ia(e,t){let n=[],r=e;for(;r&&r!==t;){let e=getComputedStyle(r);/(auto|scroll|hidden)/.test(e.overflowY+e.overflowX)&&(r.scrollHeight>r.clientHeight||r.scrollWidth>r.clientWidth)&&n.push(r),r=r.parentElement}return n}function La(e,t){let n=t.startContainer.parentElement;for(let r of Ia(n,e)){let e=t.getBoundingClientRect(),n=r.getBoundingClientRect();if(e.height<=0||e.width<=0)return;e.top>=n.top+4&&e.bottom<=n.bottom-4||(r.scrollTop+=e.top-n.top-(r.clientHeight-e.height)/2),e.left>=n.left+4&&e.right<=n.right-4||(r.scrollLeft+=e.left-n.left-(r.clientWidth-e.width)/2)}let r=t.getBoundingClientRect(),i=e.getBoundingClientRect();if(r.height<=0||r.width<=0)return;let a=r.top>=i.top+6&&r.bottom<=i.bottom-6,o=r.left>=i.left+6&&r.right<=i.right-6;a&&o||(a||(e.scrollTop+=r.top-i.top-(i.height-r.height)/2),o||(e.scrollLeft+=r.left-i.left-(i.width-r.width)/2))}function Ra({container:e,version:t}){let{t:n}=T(),[r,i]=(0,f.useState)(``),[a,o]=(0,f.useState)(0),[s,c]=(0,f.useState)(0),l=(0,f.useRef)([]),u=`cadence-page-${(0,f.useId)().replace(/[^a-z0-9]/gi,``)}`;(0,f.useEffect)(()=>{if(!t)return;let n=e.current,i=n&&r?Na(n,r):[];return l.current=i,c(i.length),o(0),Fa(u,i),()=>Fa(u,[])},[r,e,t,u]);let d=t=>{let n=s?(a+t+s)%s:0;o(n),e.current&&l.current[n]&&(La(e.current,l.current[n]),Fa(`${u}-active`,[l.current[n]]))};return(0,f.useEffect)(()=>()=>Fa(`${u}-active`,[]),[u]),(0,h.jsxs)(`div`,{className:`search-bar toolbar`,children:[(0,h.jsxs)(`label`,{children:[n(`Find on displayed field page`),(0,h.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),d(e.shiftKey?-1:1))}})]}),(0,h.jsxs)(`span`,{children:[s?a+1:0,`/`,s,s>=1e3?n(` (first 1000 visual highlights)`):``,n(`; not whole-history search`)]}),(0,h.jsx)(`button`,{type:`button`,disabled:!s,onClick:()=>d(-1),children:n(`Previous match`)}),(0,h.jsx)(`button`,{type:`button`,disabled:!s,onClick:()=>d(1),children:n(`Next match`)})]})}function za({client:e,cursor:t,highlight:n,render:r,compact:i=!1}){let{t:a,tx:o}=T(),s=W(t),c=(0,f.useMemo)(()=>Ae(JSON.parse(s)),[s]),[l,u]=(0,f.useState)(t),[d,p]=(0,f.useState)(),[m,g]=(0,f.useState)([]),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(),[x,S]=(0,f.useState)(i?`markdown`:`raw`),[C,w]=(0,f.useState)(``),E=(0,f.useRef)(null),D=(0,f.useRef)(null);(0,f.useEffect)(()=>(u(c),g([]),p(void 0),b(void 0),()=>E.current?.abort()),[c]),(0,f.useEffect)(()=>{let t=!0,n=new AbortController;return v(!0),b(void 0),e.detail(l,n.signal).then(e=>{t&&(v(!1),e.kind===`error`?b(e.error.code):p(e.value))}).catch(()=>{t&&(b(`Read unavailable.`),v(!1))}),()=>{t=!1,n.abort()}},[e,l]);let O=async()=>{if(E.current)return;let n=new AbortController;E.current=n,w(a(`Reading all retained field pages…`));try{let r=await fa(e,t,n.signal);if(n.signal.aborted)return;let i=await ga(r.text);if(n.signal.aborted)return;w(i?r.recordingComplete?a(`Copied all retained field bytes (source omissions still apply).`):a(`Copied retained field bytes; recording is incomplete. No complete-source claim.`):a(`Clipboard unavailable.`))}catch{n.signal.aborted||w(a(`Full-field copy refused/incomplete.`))}finally{E.current===n&&(E.current=null)}},k=d&&!(`kind`in d)?d:void 0;return(0,h.jsxs)(`section`,{className:`detail-pane${i?` message-field`:``}`,"aria-label":a(`Retained field`),children:[(0,h.jsxs)(`details`,{className:`field-details`,open:!i||void 0,children:[(0,h.jsx)(`summary`,{children:a(`Field details`)}),(0,h.jsxs)(`div`,{className:`detail-identity`,children:[(0,h.jsx)(`code`,{children:t.recordId}),` v`,t.recordVersion,` /`,` `,t.field&&o(t.field),` /`,` `,a(`snapshot {seq}`,{seq:t.snapshotSeq})]}),n&&(0,h.jsx)(`p`,{children:a(`Exact hit bytes [{start}, {end}); only this immutable field is highlighted.`,{start:n.start,end:n.end})}),(0,h.jsxs)(`div`,{className:`toolbar`,children:[(0,h.jsx)(`button`,{type:`button`,onClick:()=>S(e=>e===`raw`?`markdown`:`raw`),children:a(x===`raw`?`Markdown page`:`Raw page`)}),(0,h.jsx)(`button`,{type:`button`,disabled:!!E.current,onClick:()=>void O(),children:a(`Copy full retained field`)}),!!E.current&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>{E.current?.abort(),E.current=null,w(a(`Copy canceled; execution unchanged.`))},children:a(`Cancel copy`)})]})]}),C&&(0,h.jsx)(`p`,{role:`status`,children:C}),y&&(0,h.jsx)(`p`,{role:`alert`,children:a(`Detail refused: {error}`,{error:o(y)})}),_&&(0,h.jsx)(`p`,{role:`status`,children:a(`Reading…`)}),d&&(0,h.jsx)(ma,{value:d.coverage,compact:i}),d&&`kind`in d&&(0,h.jsx)(`p`,{children:a(`Validation in progress. The retained field is not empty.`)}),k&&(0,h.jsxs)(h.Fragment,{children:[(!i||k.next)&&(0,h.jsxs)(`p`,{children:[a(`Bytes {start}–{end} of {total}.`,{start:k.range?.start??0,end:k.range?.end??0,total:k.content.bytes}),` `,k.next?a(`More retained data available.`):a(`End of field.`)]}),!i&&(0,h.jsx)(Ra,{container:D,version:`${k.content.recordId}:${k.content.version}:${k.range?.start??0}:${x}`}),(0,h.jsx)(`div`,{ref:D,"data-retained-field":!0,children:r?r(k.text):x===`markdown`?(0,h.jsx)(ka,{text:k.text}):(0,h.jsx)(`pre`,{className:`detail-text`,children:(()=>{if(!k||!n||!k.range)return k?.text;let e=Math.max(n.start,k.range.start)-k.range.start,t=Math.min(n.end,k.range.end)-k.range.start;if(t<=e)return k.text;let r=new TextEncoder().encode(k.text),i=(e,t)=>new TextDecoder(`utf-8`,{fatal:!0}).decode(r.subarray(e,t));return(0,h.jsxs)(h.Fragment,{children:[i(0,e),(0,h.jsx)(`mark`,{children:i(e,t)}),i(t,r.length)]})})()})})]}),(!i||m.length>0||d?.next)&&(0,h.jsxs)(`div`,{className:`toolbar`,children:[(0,h.jsx)(`button`,{type:`button`,disabled:_||!m.length,onClick:()=>{u(m[m.length-1]),g(e=>e.slice(0,-1))},children:a(`Previous`)}),(0,h.jsx)(`button`,{type:`button`,disabled:_||!d?.next,onClick:()=>{d?.next&&(g(e=>[...e,l]),u(d.next))},children:d&&`kind`in d?a(`Continue validation`):a(`Next field page`)})]})]})}function Ba({pager:e,compact:t=!1}){let{t:n,tx:r}=T(),{page:i,busy:a,error:o}=e;return(0,h.jsxs)(`div`,{className:`page-controls${t?` compact`:``}`,children:[o&&(0,h.jsx)(`p`,{role:`alert`,children:n(`Read refused: {error}. Retained state has not been repaired.`,{error:r(o)})}),a&&(0,h.jsx)(`p`,{role:`status`,children:n(`Reading bounded history page…`)}),i&&`kind`in i&&(0,h.jsxs)(`p`,{role:`status`,children:[i.kind===`snapshot`?n(`Snapshot selected`):n(`Validating retained history`),n(`; continue this exact read. No data page yet.`)]}),i&&!(t&&i.coverage.observed===`complete`&&i.coverage.source===`complete`&&!i.coverage.redacted&&i.coverage.omissions.length===0)&&(0,h.jsx)(ma,{value:i.coverage,compact:t}),(!t||e.canPrevious)&&(0,h.jsx)(`button`,{type:`button`,disabled:a||!e.canPrevious,onClick:e.previous,children:n(`Previous page`)}),(!t||i?.next)&&(0,h.jsx)(`button`,{type:`button`,disabled:a||!i?.next,onClick:e.more,children:i&&`kind`in i?n(`Continue validation`):n(`Next page`)}),(0,h.jsx)(`button`,{type:`button`,disabled:a,onClick:e.refresh,"aria-label":n(`Observe a new snapshot`),title:n(`Observe a new snapshot`),children:t?(0,h.jsx)(Jr,{"aria-hidden":`true`}):n(`Observe a new snapshot`)}),!t&&i&&!(`kind`in i)&&!i.next&&(0,h.jsx)(`span`,{className:`page-end`,children:i.coverage.observed===`incomplete`?n(`End of this retained snapshot (incomplete).`):n(`End of this retained snapshot.`)})]})}function Va({client:e,seed:t,entityId:n}){let{t:r,tx:i}=T(),a=pa(e,{...t,reader:`contents`}),[o,s]=(0,f.useState)(),c=a.page;return(0,h.jsxs)(`section`,{"aria-label":r(`Retained content fields`),children:[(0,h.jsx)(Ba,{pager:a}),n&&(0,h.jsx)(`p`,{children:(0,h.jsx)(x,{text:r(`Showing matches for entity {entity} on this page only. Continue paging for other fields/versions.`),slots:{entity:(0,h.jsx)(`code`,{children:n})}})}),c&&!(`kind`in c)&&c.records.map(e=>e.kind!==`content`&&e.kind!==`omitted`||n&&e.owner.entity.id!==n?null:e.kind===`omitted`?(0,h.jsxs)(`p`,{className:`omission`,children:[r(`Omitted source block:`),` `,(0,h.jsx)(`code`,{children:JSON.stringify(e.block)})]},`${e.owner.entity.id}:${e.version}:${JSON.stringify(e.block.owner)}`):(0,h.jsxs)(`article`,{children:[(0,h.jsxs)(`p`,{children:[i(e.owner.entity.kind),` `,(0,h.jsx)(`code`,{children:e.owner.entity.id}),` ·`,` `,i(e.content.field),` ·`,` `,r(`{bytes} retained bytes`,{bytes:e.content.bytes})]}),(0,h.jsx)(`pre`,{children:JSON.stringify(e.descriptor.owner)}),(0,h.jsx)(ma,{value:e.coverage}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>{c.request.scope.kind!==`workspace`&&c.request.snapshotSeq!==null&&s(da(c.request.storeId,c.request.scope,c.request.snapshotSeq,e.content))},children:r(`Inspect complete retained field`)})]},`${e.content.recordId}:${e.content.version}`)),o&&(0,h.jsx)(za,{client:e,cursor:o},`${o.recordId}:${o.recordVersion}`)]})}function Ha({client:e,seed:t}){return(0,h.jsx)(Ua,{client:e,seed:t},W(t))}function Ua({client:e,seed:t}){let{t:n,tx:r}=T(),[i,a]=(0,f.useState)(t),[o,s]=(0,f.useState)(),[c,l]=(0,f.useState)(),[u,d]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{let t=!0,n=new AbortController;return d(!0),(i.kind===`message`?e.message(i,n.signal):i.kind===`tool`?e.tool(i,n.signal):e.task(i,n.signal)).then(e=>{t&&(d(!1),e.kind===`error`?l(e.error.code):(s(e.value),l(void 0)))}).catch(()=>{t&&(l(`Read unavailable.`),d(!1))}),()=>{t=!1,n.abort()}},[e,i]),(0,h.jsxs)(`section`,{"aria-label":n(`Exact entity metadata`),children:[u&&(0,h.jsx)(`p`,{children:n(`Reading exact entity version…`)}),c&&(0,h.jsx)(`p`,{role:`alert`,children:n(`Entity refused: {error}`,{error:r(c)})}),o&&`kind`in o&&(0,h.jsx)(ma,{value:o.coverage}),o&&(`kind`in o?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:n(`Entity validation in progress, not missing.`)}),(0,h.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>a(o.next),children:n(`Continue exact entity validation`)})]}):(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:n(`Exact stored owner and associations`)}),(0,h.jsx)(`pre`,{children:JSON.stringify(o.record,null,2)})]}))]})}function Wa(e){let t=Pi(`download`,Rt(e));if(t.method!==`GET`)throw Error(`Native download needs the named GET attachment route.`);let n=document.createElement(`a`);n.href=Ui()+t.path,n.download=`cadence-${e.scope.kind}-${e.scope.id}.${e.format===`markdown`?`md`:`ndjson`}`,n.referrerPolicy=`no-referrer`,document.body.appendChild(n),n.click(),n.remove()}function Ga({title:e,children:t,onClose:n}){let{t:r}=T(),i=(0,f.useRef)(null),a=(0,f.useId)(),o=(0,f.useRef)(n);return o.current=n,(0,f.useEffect)(()=>{let e=document.activeElement,t=i.current;return t?.showModal(),()=>{t?.close(),e instanceof HTMLElement&&e.isConnected&&e.focus({preventScroll:!0})}},[]),(0,h.jsxs)(`dialog`,{ref:i,className:`action-dialog`,"aria-labelledby":a,onCancel:e=>{e.preventDefault(),o.current?.()},children:[(0,h.jsxs)(`header`,{children:[(0,h.jsx)(`h2`,{id:a,children:e}),n&&(0,h.jsx)(`button`,{type:`button`,className:`dialog-close`,"aria-label":r(`Close dialog — no cancellation of accepted work`),title:r(`Close — accepted work is not cancelled`),onClick:n,children:(0,h.jsx)(Hr,{"aria-hidden":`true`})})]}),t]})}function Ka({request:e,onClose:t}){let{t:n,tx:r}=T(),[i]=(0,f.useState)(e),[a,o]=(0,f.useState)(e.format),[s,c]=(0,f.useState)(``);return(0,h.jsxs)(Ga,{title:n(`Export retained history`),onClose:t,children:[(0,h.jsx)(`p`,{children:n(`Selected {kind}: {id} · snapshot {seq}`,{kind:r(i.scope.kind),id:i.scope.id,seq:i.snapshotSeq})}),(0,h.jsxs)(`label`,{children:[n(`Format`),(0,h.jsxs)(`select`,{value:a,onChange:e=>o(e.target.value===`markdown`?`markdown`:`ndjson`),children:[(0,h.jsx)(`option`,{value:`ndjson`,children:n(`NDJSON public archive`)}),(0,h.jsx)(`option`,{value:`markdown`,children:n(`Readable Markdown with footer metadata`)})]})]}),(0,h.jsx)(`p`,{children:n(`Includes retained context, messages/tools, graph, lifecycle, changes, checks, human review and coverage beyond loaded pages. Redactions and source omissions remain.`)}),(0,h.jsx)(`p`,{children:n(`A native browser download request cannot establish completion. Inspect the original EOF and completion trailer/counts/digest in the downloaded artifact; missing footer means incomplete. Revoked access may terminate without a trailer.`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>{try{Wa({...i,format:a}),c(n(`Download requested — completion not verified by this browser UI.`))}catch{c(n(`Download unavailable; no archive claimed complete.`))}},children:n(`Request selected-scope download`)}),(0,h.jsx)(`p`,{role:`status`,children:s})]})}function qa(e,t){if(!t||te(t)>k.queryBytes)throw Error(`Query must be 1–${k.queryBytes} UTF-8 bytes; it was not clipped.`);let{navigation:n,...r}=e;return Ae({...r,query:t,recordId:null,recordVersion:null,field:null,offset:0})}function Ja(e){return e.next?`No hits in this bounded window; search is not finished.`:`No hits in the final retained window. Coverage limits above still apply.`}function Ya({client:e,seed:t,onClose:n,onHit:r}){let{t:i,tx:a}=T(),[o]=(0,f.useState)(t),s=(0,f.useRef)(null),c=(0,f.useRef)(0),[l,u]=(0,f.useState)(``),[d,p]=(0,f.useState)(0),[m,g]=(0,f.useState)(),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(),x=(0,f.useRef)(null),S=(0,f.useCallback)(async(t,n)=>{x.current?.abort();let r=new AbortController;x.current=r,v(!0),b(void 0);try{let i=await e.search(t,r.signal);if(c.current!==n||r.signal.aborted)return;i.kind===`error`?b(i.error.code):(g(i.value),p(0))}catch{c.current===n&&!r.signal.aborted&&b(`Search unavailable or invalid; no automatic retry.`)}finally{c.current===n&&!r.signal.aborted&&v(!1)}},[e]);return(0,f.useEffect)(()=>(s.current?.focus(),()=>{c.current++,x.current?.abort()}),[]),(0,f.useEffect)(()=>{let e=++c.current;if(x.current?.abort(),v(!1),g(void 0),p(0),b(void 0),!l)return;let t;try{t=qa(o,l)}catch{b(`Query must be 1–1024 UTF-8 bytes; it was not clipped.`);return}let n=setTimeout(()=>void S(t,e),300);return()=>{clearTimeout(n),c.current++,x.current?.abort()}},[l,o,S]),(0,h.jsx)(Ga,{title:i(`Search retained history`),onClose:n,children:(0,h.jsxs)(`div`,{className:`gs-modal`,children:[(0,h.jsxs)(`div`,{className:`gs-input-row`,children:[(0,h.jsx)(qr,{}),(0,h.jsx)(`input`,{ref:s,"aria-label":i(`Case-sensitive literal query`),value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`ArrowDown`&&(e.preventDefault(),p(e=>Math.max(0,Math.min(e+1,(m?.hits.length??0)-1)))),e.key===`ArrowUp`&&(e.preventDefault(),p(e=>Math.max(e-1,0))),e.key===`Enter`&&m?.hits[d]&&(e.preventDefault(),r(m.hits[d]),n())}})]}),(0,h.jsx)(`p`,{children:i(`Case-sensitive literal UTF-8 search. Scope {kind} {id}; snapshot {seq}. No regex, provider request or history repair.`,{kind:a(o.scope.kind),id:o.scope.id,seq:o.snapshotSeq})}),(0,h.jsxs)(`div`,{className:`gs-results`,children:[_&&(0,h.jsx)(`p`,{role:`status`,children:i(`Searching bounded retained range…`)}),y&&(0,h.jsx)(`p`,{role:`alert`,children:i(`Search refused: {error}`,{error:a(y)})}),!l&&(0,h.jsx)(`p`,{children:i(`Enter a query to search this selected scope.`)}),m&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(ma,{value:m.coverage}),(0,h.jsxs)(`div`,{className:`gs-section`,children:[(0,h.jsx)(`div`,{className:`gs-section-head`,children:i(`Matches on this page: {count}`,{count:m.hits.length})}),m.hits.map((e,t)=>(0,h.jsxs)(`button`,{type:`button`,className:`gs-item ${d===t?`active`:``}`,onMouseEnter:()=>p(t),onClick:()=>{r(e),n()},children:[(0,h.jsxs)(`span`,{className:`gs-item-title`,children:[a(e.owner.entity.kind),` · `,a(e.content.field),` · v`,e.content.version]}),(0,h.jsx)(`span`,{className:`gs-item-sub`,children:e.preview}),(0,h.jsxs)(`code`,{children:[e.owner.childRunId??e.owner.runId??e.owner.taskId,` `,`/ `,e.content.recordId,` /`,` `,i(`bytes {start}–{end}`,{start:e.range.start,end:e.range.end})]})]},`${e.content.recordId}:${e.content.version}:${e.range.start}`)),m.hits.length===0&&(0,h.jsx)(`p`,{children:a(Ja(m))})]}),(0,h.jsx)(`button`,{type:`button`,disabled:_||!m.next,onClick:()=>{m.next&&S(m.next,++c.current)},children:i(`Continue same snapshot search`)})]})]}),(0,h.jsx)(`footer`,{className:`gs-foot`,children:i(`↑↓ Navigate · Enter Open exact hit · Escape Close. Reopening never resumes execution.`)})]})})}function Xa({run:e,historical:t=!1}){let{t:n,tx:r}=T();return(0,h.jsxs)(`article`,{className:`run-summary`,children:[(0,h.jsxs)(`h3`,{children:[e.assignmentId??e.admission.kind,` ·`,` `,n(t?`historical projection`:`owner projection`)]}),(0,h.jsx)(`p`,{children:(0,h.jsx)(`code`,{children:e.childRunId??e.runId})}),(0,h.jsxs)(`dl`,{children:[(0,h.jsx)(`dt`,{children:n(`Lifecycle`)}),(0,h.jsx)(`dd`,{children:r(e.lifecycle)}),(0,h.jsx)(`dt`,{children:n(`Execution`)}),(0,h.jsx)(`dd`,{children:e.outcome?r(e.outcome):n(`unsettled`)}),(0,h.jsx)(`dt`,{children:n(`Wait/block reason`)}),(0,h.jsx)(`dd`,{children:e.reason?r(e.reason):n(`none reported`)}),(0,h.jsx)(`dt`,{children:n(`Summary publication`)}),(0,h.jsx)(`dd`,{children:r(e.publication)})]}),(0,h.jsx)(ma,{value:e.coverage}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:n(`Native / recording / parent settlement facts (independent of human review)`)}),(0,h.jsx)(`pre`,{children:e.settlement?JSON.stringify(e.settlement,null,2):n(`No settlement recorded`)})]})]})}function Za({client:e,seed:t}){return(0,h.jsx)(Qa,{client:e,seed:t},W(t))}function Qa({client:e,seed:t}){let{t:n,tx:r}=T(),[i,a]=(0,f.useState)(t),[o,s]=(0,f.useState)(),[c,l]=(0,f.useState)(),[u,d]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{let t=!0,n=new AbortController;return d(!0),e.graph(i,n.signal).then(e=>{t&&(d(!1),e.kind===`error`?l(e.error.code):(s(e.value),l(void 0)))}).catch(()=>{t&&(l(`Read unavailable.`),d(!1))}),()=>{t=!1,n.abort()}},[e,i]),(0,h.jsxs)(`section`,{children:[(0,h.jsx)(`h3`,{children:n(`Immutable admitted graph`)}),c&&(0,h.jsx)(`p`,{role:`alert`,children:n(`Graph refused: {error}`,{error:r(c)})}),u&&(0,h.jsx)(`p`,{children:n(`Reading graph…`)}),o&&`kind`in o&&(0,h.jsx)(ma,{value:o.coverage}),o&&(`kind`in o?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{children:n(`Graph validation in progress; not an empty graph.`)}),(0,h.jsx)(`button`,{type:`button`,disabled:u,onClick:()=>a(o.next),children:n(`Continue graph validation`)})]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(za,{client:e,cursor:da(o.request.storeId,o.request.scope,o.request.snapshotSeq,o.graph.plan)}),o.graph.assignments.map(e=>(0,h.jsxs)(`article`,{children:[(0,h.jsxs)(`h4`,{children:[e.id,` / `,e.purpose]}),(0,h.jsx)(ka,{text:e.instructions}),(0,h.jsx)(`p`,{children:n(`Expected: {output}`,{output:e.expectedOutput})}),(0,h.jsx)(`pre`,{children:JSON.stringify({model:e.model,role:e.role,dependencies:e.dependencies},null,2)})]},e.id))]}))]})}function $a({client:e,seed:t,onScope:n}){let{t:r}=T(),i=pa(e,{...t,reader:`runs`}),a=i.page,[o,s]=(0,f.useState)();return(0,h.jsxs)(`section`,{children:[(0,h.jsx)(Ba,{pager:i}),a&&!(`kind`in a)&&a.records.map(e=>e.kind===`run`?(0,h.jsxs)(`article`,{children:[(0,h.jsx)(Xa,{run:e.projection,historical:!0}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>n({kind:e.projection.childRunId?`child`:`run`,id:e.projection.childRunId??e.projection.runId}),children:r(`Open retained episode/child details`)}),e.projection.admission.graph&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>{a.request.scope.kind!==`workspace`&&a.request.snapshotSeq!==null&&e.projection.admission.graph&&s({storeId:a.request.storeId,scope:a.request.scope,snapshotSeq:a.request.snapshotSeq,graph:e.projection.admission.graph})},children:r(`Inspect admitted graph and plan`)})]},e.projection.childRunId??e.projection.runId):null),o&&(0,h.jsx)(Za,{client:e,seed:o},o.graph.recordId)]})}function eo({onOpen:e,disabled:t}){let{t:n}=T();return(0,h.jsx)(`button`,{type:`button`,className:`chip search-toggle`,"aria-label":n(`Search all retained pages in selected scope`),"data-tip":n(`Search all retained pages in selected scope`),disabled:t,onClick:e,children:(0,h.jsx)(qr,{"aria-hidden":`true`})})}function to(e,t,n,r,i){let a=i??t,o=[],s=[],c=0;for(let i of e)n.has(i.id)||(r.has(i.id)?i.top<t.bottom&&i.bottom>t.top&&o.push(i.id):i.top<a.bottom&&i.bottom>a.top||(s.push(i.id),i.bottom<=a.top&&(c+=i.bottom-i.top)));return{show:o,hide:s,shrinkAbove:c}}function no(e,t){if(t.show.length===0&&t.hide.length===0)return e;let n=new Set(e);for(let e of t.show)n.delete(e);for(let e of t.hide)n.add(e);return n}function ro(e,t,n){let r=new Set,i=0;for(let a=e.length-1;a>=0&&!(a<e.length-1&&i>=n);a--){let n=e[a];r.add(n.id),i+=t.get(n.id)??io(n.role,n.customType)}return r}function io(e,t){switch(e){case`user`:return 72;case`assistant`:return 280;case`tool-result`:return 120;case`custom`:return t===`file`?96:72;default:return 60}}function ao(e,t,n,r){let i=n.get(e);return i&&i.len===t?i.h:r}function oo(e,t,n=1800){let[r,i]=(0,f.useState)(()=>new Set),a=(0,f.useRef)(r);a.current=r;let o=(0,f.useRef)(new Map),s=(0,f.useRef)(new Map),c=(0,f.useRef)(new Map),l=(0,f.useRef)(0),u=(0,f.useRef)(new Map);u.current=new Map(t.map(e=>[e.id,e.version]));let d=(0,f.useRef)(new Set);d.current=ro(t,o.current,n);let p=(0,f.useCallback)((e,t)=>{let n=u.current.get(e);n!==void 0&&(s.current.set(e,{h:t,len:n}),o.current.set(e,t))},[]),m=(0,f.useCallback)(()=>{let t=e.current;if(!t)return;let n=t.getBoundingClientRect(),r=[];for(let[e,t]of c.current){let n=t.getBoundingClientRect();r.push({id:e,top:n.top,bottom:n.bottom}),a.current.has(e)||p(e,n.height)}let o=to(r,{top:n.top-1200,bottom:n.bottom+1200},d.current,a.current,{top:n.top-2400,bottom:n.bottom+2400});for(let e of o.hide){let t=c.current.get(e);t&&p(e,t.offsetHeight)}i(e=>no(e,o))},[p,e]),h=(0,f.useCallback)(()=>{l.current||=requestAnimationFrame(()=>{l.current=0,m()})},[m]);return(0,f.useLayoutEffect)(()=>{t.length?m():i(new Set)},[m,t]),(0,f.useEffect)(()=>{let t=new ResizeObserver(h);return e.current&&t.observe(e.current),()=>{t.disconnect(),cancelAnimationFrame(l.current)}},[h,e]),{hidden:r,scheduleSweep:h,recordMeasured:p,register:(0,f.useCallback)(e=>t=>{t?c.current.set(e,t):c.current.delete(e)},[]),placeholder:(0,f.useCallback)((e,t,n)=>ao(e,t,s.current,n),[])}}var so=(0,f.memo)(function({id:e,show:t,height:n,containerRef:r,onMeasured:i,lazyRef:a,children:o}){let s=(0,f.useRef)(null);return(0,f.useLayoutEffect)(()=>{if(!t)return;let n=s.current;if(!n)return;let r=n.offsetHeight;r>0&&i?.(e,r)},[t,e,i]),t?(0,h.jsx)(`div`,{ref:a,"data-lazy-id":e,children:(0,h.jsx)(`div`,{ref:s,children:o})}):(0,h.jsx)(`div`,{ref:a,className:`msg-lazy-ph`,"data-msg-id":e,"data-lazy-id":e,style:{height:n},"aria-hidden":`true`})}),co=(0,f.memo)(function({message:e,client:t,seed:n}){let{t:r,tx:i}=T(),[a,o]=(0,f.useState)(!1);return(0,h.jsxs)(`article`,{className:`msg msg-${e.role}`,"data-msg-id":e.owner.entity.id,children:[(0,h.jsxs)(`header`,{className:`msg-meta`,children:[(0,h.jsx)(`strong`,{className:`msg-role`,children:i(e.role)}),e.state!==`final`&&(0,h.jsx)(`span`,{className:`msg-state`,children:i(e.state)}),(0,h.jsxs)(`button`,{type:`button`,className:`msg-inspect`,"aria-expanded":a,onClick:()=>o(e=>!e),children:[a?(0,h.jsx)(hi,{"aria-hidden":`true`}):(0,h.jsx)(ci,{"aria-hidden":`true`}),r(a?`Collapse`:`Inspect message`)]})]}),(0,h.jsxs)(`div`,{className:`msg-body`,children:[e.role===`tool-result`&&(0,h.jsx)(`p`,{className:`msg-note`,children:r(`Result call: {call}. Kept visible independently of the tool card.`,{call:e.resultCallId??r(`unassociated / orphan`)})}),(0,h.jsx)(`div`,{className:`msg-text`,children:(0,h.jsxs)(`div`,{className:`msg-text-main`,children:[e.finalText&&n.scope.kind!==`workspace`&&n.snapshotSeq!==null?(0,h.jsx)(za,{compact:!0,client:t,cursor:da(n.storeId,n.scope,n.snapshotSeq,e.finalText)}):(0,h.jsx)(`p`,{children:r(`No finalized text field in this snapshot. Inspect retained partial/final blocks and omission metadata below.`)}),a&&(0,h.jsxs)(`div`,{className:`message-inspection`,children:[(0,h.jsx)(`p`,{className:`msg-ident`,children:r(`Child {child} · message {message} · version {version}`,{child:e.owner.childRunId??``,message:e.owner.entity.id,version:e.version})}),(0,h.jsx)(`p`,{className:`msg-note`,children:r(`{state} message record, not execution outcome`,{state:i(e.state)})}),(0,h.jsxs)(`details`,{open:!0,children:[(0,h.jsx)(`summary`,{children:r(`All message blocks, source limits and tool associations`)}),(0,h.jsx)(Va,{client:t,seed:n,entityId:e.owner.entity.id})]})]})]})})]})]})});function lo({messages:e,client:t,seed:n}){let{t:r}=T(),i=(0,f.useRef)(null),a=(0,f.useRef)(!0),o=(0,f.useMemo)(()=>e.map(e=>({id:e.owner.entity.id,role:e.role,version:e.version,message:e})),[e]),s=oo(i,o);return(0,h.jsxs)(`div`,{className:`messages-wrap`,children:[(0,h.jsx)(`div`,{className:`messages`,ref:i,onScroll:e=>{let t=e.currentTarget;a.current=t.scrollHeight-t.scrollTop-t.clientHeight<80,s.scheduleSweep()},children:o.map(({id:e,role:r,message:a})=>(0,h.jsx)(so,{id:e,show:!s.hidden.has(e),height:s.placeholder(e,a.version,r===`user`?100:280),containerRef:i,onMeasured:s.recordMeasured,lazyRef:s.register(e),children:(0,h.jsx)(co,{message:a,client:t,seed:n})},e))}),(0,h.jsxs)(`button`,{type:`button`,className:`scroll-bottom`,onClick:()=>{i.current&&(i.current.scrollTop=i.current.scrollHeight,a.current=!0)},children:[(0,h.jsx)(xi,{"aria-hidden":`true`}),r(`Latest on loaded page`)]})]})}function uo({client:e,seed:t}){let{t:n}=T(),r=pa(e,{...t,reader:`messages`}),i=r.page;return(0,h.jsxs)(`section`,{className:`transcript`,children:[(0,h.jsx)(Ba,{pager:r,compact:!0}),i&&!(`kind`in i)&&t.snapshotSeq!==null&&i.request.snapshotSeq!==t.snapshotSeq&&(0,h.jsx)(`button`,{type:`button`,className:`conversation-update`,disabled:r.busy,onClick:r.refresh,children:n(`New activity — update conversation`)}),i&&!(`kind`in i)&&(0,h.jsxs)(h.Fragment,{children:[i.records.length===0&&(0,h.jsx)(`p`,{className:`empty-note panel-empty`,children:i.next?n(`No message records on this page; more history remains.`):n(`No message records on this page.`)}),(0,h.jsx)(lo,{messages:i.records.filter(e=>e.kind===`message`),client:e,seed:i.request},`${i.request.snapshotSeq}:${i.request.after?.recordId??`first`}`)]})]})}function fo({open:e,onToggle:t,headClassName:n,titleText:r,icon:i,iconClassName:a,titleClassName:o,toggleClassName:s,toggle:c,onHeadContextMenu:l,children:u,after:d}){return(0,h.jsxs)(`div`,{className:`chead ${n}`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`chead-main`,"aria-expanded":e,title:r,onClick:t,onContextMenu:l,children:[c===void 0?(0,h.jsx)(`span`,{className:s?`chead-toggle ${s}`:`chead-toggle`,children:e?(0,h.jsx)(_i,{}):(0,h.jsx)(gi,{})}):c,(0,h.jsx)(`span`,{className:a?`chead-icon ${a}`:`chead-icon`,children:i}),(0,h.jsx)(`span`,{className:o?`chead-title ${o}`:`chead-title`,children:u})]}),d]})}var po=(0,f.memo)(function({record:e,client:t,seed:n}){let{t:r,tx:i}=T(),[a,o]=(0,f.useState)(!1),s=e.result?e.result.isError?r(`SDK tool error observed`):r(`SDK tool end observed`):e.startObserved?r(`Start observed; end not observed in this snapshot`):r(`No start observed`),c=e.result?e.result.isError?`err`:`ok`:e.startObserved?`pending`:``;return(0,h.jsxs)(`div`,{className:`toolcall${c===`err`?` err`:``}`,children:[(0,h.jsx)(fo,{open:a,onToggle:()=>o(e=>!e),headClassName:`toolcall-head`,titleText:r(`Inspect recorded tool call`),icon:(0,h.jsx)(Ur,{}),iconClassName:`toolcall-icon`,titleClassName:`toolcall-name`,after:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`span`,{className:`toolcall-path`,children:r(`Child {child} · call {call} · v{version}`,{child:e.owner.childRunId??``,call:e.owner.entity.id,version:e.version})}),(0,h.jsx)(`span`,{className:`toolcall-badge ${c}`,children:s})]}),children:e.name}),a&&(0,h.jsxs)(`div`,{className:`toolcall-body`,children:[(0,h.jsx)(`p`,{children:r(`SDK tool observations are not native process launch/close or passing parent checks.`)}),(0,h.jsxs)(`dl`,{children:[(0,h.jsx)(`dt`,{children:r(`Source ID`)}),(0,h.jsxs)(`dd`,{children:[i(e.source.disposition),`:`,` `,e.source.value??r(`unavailable`)]}),(0,h.jsx)(`dt`,{children:r(`Declaration`)}),(0,h.jsx)(`dd`,{children:e.declaration?`${e.declaration.messageId} / ${e.declaration.blockId} (${i(String(e.declarationStage))})`:r(`No declaration recorded; orphan result remains accessible`)})]}),(0,h.jsxs)(`div`,{className:`toolcall-output`,children:[(0,h.jsx)(`div`,{className:`toolcall-output-label`,children:r(`Recorded tool end (not parsed from output)`)}),(0,h.jsx)(`pre`,{children:e.result?JSON.stringify(e.result,null,2):r(`No end fact in this snapshot.`)})]}),(0,h.jsx)(`div`,{className:`toolcall-args`,children:(0,h.jsx)(Va,{client:t,seed:n,entityId:e.owner.entity.id})})]})]})}),mo=(e,t,n,r)=>JSON.stringify([e,t,n,r]);function ho({value:e,error:t,opening:n,onOpen:r,represented:i=[]}){let{t:a,tx:o}=T(),s=new Set(e?.projects.flatMap(e=>e.activities.filter(e=>e.sessionId).map(t=>`${e.path}\0${t.sessionId}`))),c=e?.projects.map(e=>({...e,activities:e.activities.filter(t=>!i.includes(mo(e.path,t.source,t.id,t.epoch)))})).filter(e=>e.activities.length);return(0,h.jsxs)(`section`,{className:`lp-section`,"aria-label":a(`Active Pi work`),children:[(0,h.jsx)(`header`,{className:`lp-section-header`,children:(0,h.jsx)(`span`,{className:`lp-section-title`,children:a(`Active Pi work`)})}),(0,h.jsxs)(`div`,{className:`lp-section-body`,children:[e&&(0,h.jsx)(`p`,{className:`panel-hint`,children:a(`{projects} projects · {sessions} sessions`,{projects:e.projects.length,sessions:s.size})}),(t||e?.completeness===`partial`)&&(0,h.jsxs)(`p`,{role:`status`,className:`panel-hint`,children:[a(`Activity observation is partial. Missing work is not known to have finished.`),t?` (${t})`:``]}),i.length>0&&(0,h.jsx)(`p`,{className:`panel-hint`,children:a(`Owner work already listed below is not duplicated here.`)}),!e&&!t&&(0,h.jsx)(`p`,{className:`panel-hint`,children:a(`Discovering active work…`)}),e?.completeness===`complete`&&!t&&!e.projects.length&&(0,h.jsx)(`p`,{className:`panel-hint`,children:a(`No active work observed. Idle terminals and owners are not listed.`)}),c?.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`p`,{className:`panel-hint`,children:e.path}),e.activities.map(t=>(0,h.jsx)(`button`,{type:`button`,className:`session-item`,disabled:n||!t.sessionId||t.history!==`shared`,onClick:()=>r(e.path,t),children:(0,h.jsxs)(`span`,{className:`session-info`,children:[(0,h.jsx)(`span`,{className:`session-title`,children:t.sessionId??a(`Unattributed work`)}),(0,h.jsxs)(`span`,{className:`session-sub`,children:[t.source===`terminal`?a(`Terminal turn (observe only)`):t.source===`turn`?a(`Owner turn`):a(`Owner workflow`),` `,`· `,o(t.phase),` ·`,` `,t.freshness===`current`?a(`Current observation`):t.freshness===`stale`?a(`Stale observation`):a(`Unknown activity`)]}),t.history===`unavailable`&&(0,h.jsx)(`span`,{className:`session-sub`,children:a(`History configuration differs. Activity remains observe-only.`)}),(0,h.jsxs)(`span`,{className:`session-sub`,children:[t.cwd,t.executionCwd?` → ${t.executionCwd}`:``]})]})},`${t.epoch??t.instance}:${t.source}:${t.id}`))]},e.path))]})]})}var go=[`queued`,`running`];function _o(e){return e.replace(/(?:-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})+$/i,``)}var vo=4,yo=1e4;function bo(e,t,n=2e3){let[r,i]=(0,f.useState)(()=>({runs:new Map,failed:!1,unreadable:new Set})),a=(0,f.useRef)({client:e,runs:new Map}),o=JSON.stringify([...new Set(t)]);return(0,f.useEffect)(()=>{let t=new AbortController,r;a.current.client!==e&&(a.current={client:e,runs:new Map});let s=JSON.parse(o),c=new Set(s);for(let e of a.current.runs.keys())c.has(e)||a.current.runs.delete(e);let l=new Map(a.current.runs),u=new Map,d=e=>{let t=new Map;for(let e of s){let n=l.get(e);n&&t.set(e,n)}return i({runs:t,failed:e,unreadable:new Set(u.keys())}),t},f=async n=>{let r=await e.workbenchRead({kind:`workflow`,id:n},t.signal);if(t.signal.aborted)return!1;if(r.kind===`ok`&&r.value.kind===`workflow`&&r.value.response.type===`run`){let e=r.value.response.run;return l.set(n,e),u.delete(n),a.current.runs.set(n,e),!1}return l.has(n)?!0:(u.set(n,Date.now()),!1)},p=async()=>{let e=!1,i=Date.now(),a=s.filter(e=>{let t=l.get(e);return t?go.includes(t.status):i-(u.get(e)??0)>=yo}).reverse();for(let n=0;n<a.length;n+=vo){let r=await Promise.all(a.slice(n,n+vo).map(f));if(t.signal.aborted)return;e||=r.includes(!0),n+vo<a.length&&d(e)}let o=d(e);e||[...o.values()].some(e=>go.includes(e.status))?r=setTimeout(()=>void p(),n):u.size&&(r=setTimeout(()=>void p(),yo))};return p(),()=>{t.abort(),clearTimeout(r)}},[e,o,n]),r}function xo({client:e,active:t,taskId:n,runs:r,snapshot:i,workflowRuns:a=[],selected:o,onOpen:s,onOpenWorkflow:c}){let{t:l,tx:u}=T(),[d,p]=(0,f.useState)(null),[m,g]=(0,f.useState)([]),[_,v]=(0,f.useState)(!1),y=bo(e,a),b=JSON.stringify(t?.status===`complete`?[...new Set(t.runs.map(e=>e.taskId))]:[]);(0,f.useEffect)(()=>{let t=new AbortController,n,r=async()=>{let i=[],a=!1;for(let n of JSON.parse(b)){let r=await e.snapshot({kind:`task`,id:n},t.signal);if(t.signal.aborted)return;if(r.kind===`ok`)for(let e of r.value.runs)e.childRunId&&i.push({taskId:n,run:e,snapshot:r.value.committedSeq});else a=!0}t.signal.aborted||(g(i),v(a),n=setTimeout(()=>void r(),3e3))};return r(),()=>{t.abort(),clearTimeout(n)}},[e,b]);let x=n&&i?r.filter(e=>e.childRunId).map(e=>({taskId:n,run:e,snapshot:i})):[],S=[...m,...x.filter(e=>!m.some(t=>t.run.childRunId===e.run.childRunId))].sort((e,t)=>Number(e.run.lifecycle===`settled`)-Number(t.run.lifecycle===`settled`)),C=[...new Set(a)].flatMap(e=>{let t=y.runs.get(e);return t?t.steps.filter(e=>e.childRunId).map(e=>({run:t,step:e})):[]}).reverse().sort((e,t)=>Number(!go.includes(e.step.status))-Number(!go.includes(t.step.status))),w=S.length+C.length,E=C.filter(({step:e})=>go.includes(e.status)).length+S.filter(e=>e.run.lifecycle!==`settled`).length,D=d??(w>0||!!_);return(0,h.jsxs)(`section`,{className:`agent-dock${D?``:` collapsed`}`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`agent-dock-heading`,"aria-expanded":D,onClick:()=>p(!D),children:[(0,h.jsx)(_i,{}),(0,h.jsx)(di,{}),(0,h.jsx)(`span`,{children:l(`Subagents`)}),(0,h.jsx)(`span`,{className:`lp-count${E?` live`:``}`,children:E?l(`{active} active · {total} total`,{active:E,total:w}):w})]}),D&&(0,h.jsxs)(`div`,{className:`agent-dock-body`,children:[(_||t?.status!==`complete`||y.failed)&&(0,h.jsx)(`p`,{className:`panel-hint`,children:l(`Subagent roster unavailable`)}),w===0&&!_&&t?.status===`complete`&&(0,h.jsx)(`p`,{className:`panel-hint`,children:l(`Cadence research, implementation and review agents appear here.`)}),C.map(({run:e,step:t})=>{let n=_o(t.id);return(0,h.jsxs)(`button`,{type:`button`,className:`agent-dock-row${o?.runId===e.id&&o.stepId===t.id?` active`:``}`,title:e.goal,onClick:()=>c?.({runId:e.id,stepId:t.id,label:n}),children:[(0,h.jsx)(`span`,{className:`agent-dot ${t.status}`}),(0,h.jsxs)(`span`,{className:`agent-dock-label`,children:[(0,h.jsxs)(`strong`,{children:[u(t.kind),` · `,n]}),(0,h.jsx)(`small`,{children:e.goal})]}),(0,h.jsx)(`span`,{className:`ep-state ${t.status}`,children:u(t.status)})]},t.childRunId)}),S.map(e=>(0,h.jsxs)(`button`,{type:`button`,className:`agent-dock-row`,onClick:()=>s(e.taskId,e.run.childRunId,e.snapshot,e.run.assignmentId??l(`Subagent`)),children:[(0,h.jsx)(`span`,{className:`agent-dot ${e.run.outcome??e.run.lifecycle}`}),(0,h.jsxs)(`span`,{className:`agent-dock-label`,children:[(0,h.jsx)(`strong`,{children:e.run.assignmentId??l(`Subagent`)}),(0,h.jsx)(`small`,{children:l(`Task {id}`,{id:e.taskId.slice(0,8)})})]}),(0,h.jsx)(`span`,{className:`ep-state ${e.run.outcome??e.run.lifecycle}`,children:u(e.run.outcome??e.run.lifecycle)})]},e.run.childRunId))]})]})}var So=2e4;async function Co(e,t,n,r){let i=wi([t],So);try{if(i.signal.aborted)throw i.signal.reason;await e(i.signal,n,r)}finally{i.dispose()}}function wo(e){switch(e){case`dispatched`:return`Preparation outcome is unknown ({code}); an execution service may have started. The message was not sent and its draft is kept.`;case`confirmed`:return`Execution preparation was confirmed, but the message was not sent ({code}). Its draft is kept.`;default:return`The message was not sent ({code}). Its draft is kept.`}}function To(e){return e===`none`?`The message was not accepted ({code}). Its draft is kept.`:`Send outcome is unknown ({code}). Observe the original command before sending again; no automatic retry.`}async function Eo(e,t,n){n(t.commandId);let r=await e.workbenchCommand(t);return(r.kind===`ok`||r.error.effect===`none`)&&n(``),r}function Do(e){let t={commandId:crypto.randomUUID(),conversationId:nn(e.id),head:e.head===null?null:cr(e.head)},n=e.location?rn(e.location):void 0;if(n&&n.id!==t.conversationId)throw new j(`stale`);let r=N(e.text,lr,!e.images?.length),i=e.intent===`exit`?{kind:`cadence-exit`,...n?{location:n}:{},...t,revision:P(e.revision,0)}:e.intent===`ordinary`?{kind:`send`,...t,text:r}:{kind:`cadence-send`,...t,text:r,intent:e.intent,revision:P(e.revision,0)};return Object.freeze({text:r,...e.installModel?{installModel:!0}:{},images:Object.freeze([...e.images??[]]),command:Object.freeze(i),...n?{location:Object.freeze(n)}:{},...e.model?{model:Object.freeze(Oo(e.model))}:{}})}function Oo(e){return ue({provider:e.provider,model:e.model,api:e.api,thinking:e.thinking})}function ko(e,t){return Object.freeze({...e,model:Object.freeze(Oo(t))})}function Ao(e,t){if(e.model&&W(e.model)!==W(Oo(t)))throw new j(`stale`)}function jo(e,t){return Object.freeze({...e,preparedEpoch:V(t)})}function Mo(e,t,n){return Object.freeze({...ko(e,t),installModel:!n})}function No(e,t){return e.preparedEpoch?t.status===`ready`?t.epoch===e.preparedEpoch?`ready`:`cancel`:[`stopped`,`not-started`,`incompatible`].includes(t.status)?`cancel`:`wait`:`cancel`}function Po(e,t){return!!e&&e===t}async function Fo(e,t,n,r){if(!r())throw new j(`stale`);if(!t.installModel||!t.model)return n;if(!dn(n.entries,t.model))throw new j(`unsupported-context`);if(n.selected&&W(Oo(n.selected))===W(t.model))return n;let i=await e.chooseModel({expected:n.version,choice:t.model},t.location);if(!r())throw new j(`stale`);if(i.kind===`error`)throw new j(i.error.code);let a=await e.models(void 0,t.location);if(!r())throw new j(`stale`);if(a.kind===`error`)throw new j(a.error.code);if(!a.value.selected||W(a.value.version)!==W(i.value.version)||W(a.value.selected)!==W(i.value.selected))throw new j(`stale`);return Ao(t,a.value.selected),a.value}function Io(e,t){if(e.location&&e.command.kind!==`cadence-exit`&&W(e.location)!==W(t?.conversation??null)||e.preparedEpoch&&e.command.kind!==`cadence-exit`&&t?.epoch!==e.preparedEpoch)throw new j(`stale`);let n=yr(e.command.kind===`cadence-exit`?e.command:{...e.command,model:t});if(n.kind!==`send`&&n.kind!==`cadence-send`&&n.kind!==`cadence-exit`)throw new j(`invalid`);return n}function Lo(e,t,...n){let r=`cadence:draft:${e}:${t}`;try{let e=e=>[e,`${e}:pending`,`${e}:mode`].some(e=>sessionStorage.getItem(e)!==null);if(e(r))return r;for(let r of n){if(!r)continue;let n=`cadence:draft:${r}:${t}`;if(e(n))return n}}catch{}return r}function Ro(e){for(let t of e){if(!Nn.includes(t.type))throw Error(`Use PNG, JPEG or WebP images.`);if(!t.size)throw Error(`Image is empty.`)}}async function zo(e){Ro([e]);let t=new Uint8Array(await e.arrayBuffer());return Fn(t,e.type),t}var Bo=e=>{let t=``;for(let n=0;n<e.length;n+=8192)t+=String.fromCharCode(...e.subarray(n,n+8192));return btoa(t)};async function Vo(e,t,n,r){Ro(n);let i=[];for(let a of n){if(!r())throw Error(`stale`);let n=await zo(a);if(!r())throw Error(`stale`);let o=Bo(n),s=crypto.randomUUID();for(let i=0;i<o.length;i+=Mn.chunkChars){if(!r())throw Error(`stale`);let c=o.slice(i,i+Mn.chunkChars),l=await e.workbenchCommand({kind:`image-upload`,commandId:crypto.randomUUID(),imageId:s,send:t,mimeType:a.type,size:n.length,offset:i,data:c});if(!r())throw Error(`stale`);if(l.kind===`error`)throw Error(l.error.code);if(l.value.kind!==`image-upload`||l.value.imageId!==s||l.value.offset!==i+c.length)throw Error(`invalid`)}i.push(s)}return i.length?{...t,images:i}:t}async function Ho(e,t){let n=[],r=0;for(;;){let i=await t(r);if(i.kind!==`conversation-image`||i.mimeType!==e.mimeType||!i.data.length||i.data.length>Mn.chunkChars)throw Error(`invalid`);if(n.push(i.data),r+=i.data.length,i.next===null)break;if(i.next!==r||i.data.length!==Mn.chunkChars)throw Error(`invalid`)}let i=Pn(n.join(``));return Fn(i,e.mimeType),new Blob([new Uint8Array(i)],{type:e.mimeType})}var Uo=1e3,Wo=1e4,Go=4,Ko=e=>e===`queued`||e===`running`,qo=class extends Error{},Jo=class{client;id;notify;summary=void 0;leaf=null;pinned=null;branches=0;runs=[];attempt=null;commands=[];count=0;first=null;turns=new Map;imageReaders=new Map;details=new Map;error=``;loadingEarlier=!1;running=!1;again=!1;closed=!1;active=!1;timer;abort=new AbortController;reads=0;queue=[];snapshot;constructor(e,t,n){this.client=e,this.id=t,this.notify=n,this.snapshot=this.compose()}view(){return this.snapshot}setActive(e){this.active!==e&&(this.active=e,e?this.tick():clearTimeout(this.timer))}close(){this.closed=!0,this.abort.abort(),clearTimeout(this.timer)}refresh=()=>{this.tick()};choose=e=>{this.closed||this.pinned===e||(this.abort.abort(),this.abort=new AbortController,this.pinned=e,this.summary=void 0,this.error=``,this.forget(),this.publish(),this.tick())};forget(){this.turns.clear(),this.details.clear(),this.imageReaders.clear(),this.first=null,this.count=0}loadEarlier=()=>{this.closed||this.loadingEarlier||!this.first||(this.first=Math.max(0,this.first-3),this.loadingEarlier=!0,this.publish(),this.tick())};publish(){this.closed||(this.snapshot=this.compose(),this.notify())}compose(){let e=[],t=this.count-1;for(;t>=0&&!this.turns.has(t);)t--;for(;t>=(this.first??this.count);t--){let n=this.turns.get(t);if(!n)break;e.unshift(n)}return{summary:this.summary,leaf:this.leaf,pinned:this.pinned!==null,branches:this.branches,runs:this.runs,attempt:this.attempt,commands:this.commands,count:this.count,turns:e,earlier:(e[0]?.ordinal??this.count)>0,loadingEarlier:this.loadingEarlier,error:this.error}}async tick(){if(this.closed||!this.active)return;if(this.running){this.again=!0;return}this.running=!0,clearTimeout(this.timer);let e=this.loadingEarlier,t=this.abort;try{await this.sync(t.signal),t===this.abort&&(this.error=``)}catch(e){if(this.closed)return;t===this.abort&&(this.error=e instanceof qo?e.message:`unavailable`)}finally{this.running=!1}if(e&&(this.loadingEarlier=!1),this.publish(),this.again){this.again=!1,this.tick();return}if(!this.active)return;let n=Ko(this.summary?.status)||[...this.turns.values()].some(e=>Ko(e.header.status));this.timer=setTimeout(()=>void this.tick(),n?Uo:Wo)}async sync(e){let t=this.pinned,n=await this.read({kind:`conversation`,id:this.id,leaf:t,known:this.leaf},e);if(e.aborted)return;if(n.kind!==`conversation`)throw new qo(`invalid`);(!n.continues||n.turns<this.count)&&this.forget();let r=n.leaf===this.leaf?this.count:this.count-1;this.leaf=n.leaf,this.branches=n.branches,this.runs=n.runs,this.attempt=n.attempt,this.commands=n.commands??[],this.summary=n.summary,this.count=n.turns,this.first=Math.min(this.first??Math.max(0,n.turns-2),n.turns),this.publish();let i=[];for(let e=this.first;e<this.count;e++){let t=this.turns.get(e);(!t||e>=r||t.header.stable<t.header.steps||Ko(t.header.status))&&i.push(e)}await Promise.all(i.map(t=>this.load(t,n.leaf,e)))}async load(e,t,n){let r=this.turns.get(e),i=await this.turnRead(e,null,t,n),a=i.turn,o=Array.from({length:a.steps}),s=r?.header.id===a.id?Math.min(r.header.stable,i.start):0;for(let e=0;e<s;e++)o[e]=r?.steps[e];i.steps.forEach((e,t)=>{o[i.start+t]=e});let c=[];for(let e=i.start;e>s;e-=24)c.push(e);for(let r of await Promise.all(c.map(r=>this.turnRead(e,r,t,n))))r.steps.forEach((e,t)=>{let n=r.start+t;n>=s&&n<i.start&&(o[n]=e)});if(!n.aborted){if(o.some(e=>!e))throw new qo(`stale`);this.turns.set(e,{ordinal:e,header:a,steps:o,detail:this.detail(t,a.id,n),image:this.imageReader(t,n)})}}async turnRead(e,t,n,r){let i=await this.read({kind:`conversation-turn`,id:this.id,leaf:n,ordinal:e,before:t},r);if(i.kind!==`conversation-turn`||i.ordinal!==e||i.leaf!==n)throw new qo(`invalid`);return i}imageReader(e,t){let n=e??``,r=this.imageReaders.get(n);return r||(r=async(n,r)=>{let i=wi([t,r]);try{return await Ho(n,t=>this.read({kind:`conversation-image`,id:this.id,leaf:e,...n.live?{live:!0}:{},entry:n.entry,index:n.index,offset:t},i.signal))}finally{i.dispose()}},this.imageReaders.set(n,r)),r}detail(e,t,n){let r=`${e??``}:${t}`,i=this.details.get(r);return i||(i=async(r,i,a)=>{let o=await Promise.all(Array.from({length:i},async(i,o)=>{let s=wi([n,a]);try{let n=await this.read({kind:`conversation-step`,id:this.id,leaf:e,turnId:t,step:r,part:o},s.signal);if(n.kind!==`conversation-step`||n.part!==o)throw new qo(`invalid`);return n.item}finally{s.dispose()}}));return{text:o.map(e=>e.text).join(``),args:o.map(e=>e.args).join(``)}},this.details.set(r,i)),i}async read(e,t=this.abort.signal){this.reads>=Go&&await new Promise(e=>this.queue.push(e)),this.reads++;try{if(this.closed||t.aborted)throw new qo(`stale`);let n=await this.client.workbenchRead(e,t);if(n.kind===`error`)throw new qo(n.error.code);return n.value}finally{this.reads--,this.queue.shift()?.()}}};function Yo(e,t,n,r=null){let[i,a]=(0,f.useState)(null),[o,s]=(0,f.useState)(null);return(0,f.useEffect)(()=>{let n=new Jo(e,t,()=>s(n.view()));return n.choose(r),a(n),s(n.view()),()=>n.close()},[e,t,r]),(0,f.useEffect)(()=>{i?.setActive(n)},[i,n]),{...o??{summary:void 0,leaf:null,pinned:!1,branches:0,runs:[],attempt:null,commands:[],count:0,turns:[],earlier:!1,loadingEarlier:!1,error:``},refresh:i?.refresh??Xo,loadEarlier:i?.loadEarlier??Xo,choose:i?.choose??Xo}}function Xo(){}function Zo(e,t,n,r){let i=t.status===`ready`?t.epoch:null,a=t.status===`ready`?t.attachmentVersion:null,o=i===null&&t.status!==`incompatible`&&t.status!==`preparing`?r:void 0,[s,c]=(0,f.useState)(0),l=(0,f.useRef)(0),u=(0,f.useMemo)(()=>({client:e,epoch:i,attachment:a,refresh:n,revision:s,preview:o}),[e,i,a,n,s,o]),d=(0,f.useRef)(u);d.current=u;let p=(0,f.useRef)(!0);(0,f.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]);let m=(0,f.useCallback)(()=>p.current&&(u.epoch!==null||!!u.preview)&&d.current===u&&l.current===u.revision,[u]),[h,g]=(0,f.useState)();(0,f.useEffect)(()=>{if(u.epoch===null&&!u.preview)return;let t=new AbortController,n=()=>!t.signal.aborted&&m();return u.preview?(u.preview(t.signal).then(e=>{n()&&g({scope:u,preview:e})}).catch(e=>{n()&&g({scope:u,error:e instanceof Error?e.message:`unavailable`})}),()=>t.abort()):(e&&e.models(t.signal).then(e=>{n()&&(e.kind===`error`?g({scope:u,error:e.error.code}):e.value.version.epoch===u.epoch?g({scope:u,catalog:e.value}):g({scope:u,error:`stale`}))}).catch(()=>{n()&&g({scope:u,error:`unavailable`})}),()=>t.abort())},[e,u,m]);let _=h?.scope===u&&m()?h:void 0;return{catalog:_?.catalog,preview:_?.preview,error:_?.error,loading:(i!==null||!!o)&&!_,isCurrent:m,reread(){m()&&c(++l.current)},accept(e){return!m()||e.version.epoch!==u.epoch?!1:(g({scope:u,catalog:e}),!0)}}}async function Qo(e){let t=e.state.proposal;if(!t||!e.state.enabled||!e.current())throw Error(`stale`);let n={conversationId:e.state.id,revision:e.state.revision,proposalId:t.id,digest:t.digest},r=await e.client.workbenchCommand({kind:`cadence-prepare`,commandId:crypto.randomUUID(),...n});if(r.kind!==`ok`)throw Error(r.error.code);if(r.value.kind!==`cadence-grant`||!e.current()||r.value.revision!==e.state.revision||W(r.value.proposal)!==W(t)||Date.now()>=r.value.expiresAt)throw Error(`stale`);let i=crypto.randomUUID();return e.submitting(i),e.client.workbenchCommand({kind:`cadence-approve`,commandId:i,...n,grant:r.value.grant})}function $o(e){return/^(?:退出\s*cadence|关闭\s*cadence(?:模式)?|exit cadence)$/iu.test(e.trim())}function es(e){return/^(?:按(?:这个|本)?计划(?:开始)?(?:执行|实施)|确认(?:计划并)?(?:执行|实施)|approve and execute)[。.!!]?$/iu.test(e.trim())}var ts={off:`Off`,minimal:`Minimal`,low:`Low`,medium:`Medium`,high:`High`,xhigh:`Extra high`,max:`Max`},ns={conflict:`A reply or workflow is still running in this project. Switch models after it finishes.`,stale:`The model list changed. Read the current list before choosing again.`,"auth-unavailable":`This model's credentials are unavailable. Check auth.json or the provider's API key.`,"unsupported-context":`This model or thinking level is not supported.`,uncertain:`The choice was not confirmed. Read the current model before choosing again.`},rs=(e,t)=>e.provider===t.provider&&e.model===t.model&&e.api===t.api&&e.thinking===t.thinking,is=(e,t)=>!!t&&e.provider===t.provider&&e.model===t.model&&e.api===t.api;function as(e,t){let n=e.thinking.filter(e=>e.selectable).map(e=>e.level);if(n.includes(t))return t;let r=e=>le.indexOf(e);return n.reduce((e,n)=>Math.abs(r(n)-r(t))<Math.abs(r(e)-r(t))?n:e)}function os(){let{t:e}=T();return(0,f.useCallback)(t=>`${t.model} · ${e(ts[t.thinking])}`,[e])}function ss({client:e,availability:t,read:n,lastModel:r,draftModel:i,onPreviewChoice:a,locked:o,open:s,onOpenChange:c,onChanged:l,onChosen:u,awaitingSend:d=!1,scope:p=`conversation`}){let{t:m}=T(),g=os(),_=t.status===`ready`,v=n.preview,y=_||!!v||n.loading&&t.status!==`preparing`,b=_?t.epoch:null,x=_?t.attachmentVersion:null,{error:S,loading:C,reread:w}=n,E=_?n.catalog:void 0,D=E??v,[O,k]=(0,f.useState)(``),[A,j]=(0,f.useState)(!1),[ee,M]=(0,f.useState)(``),N=(0,f.useRef)(null),te=(0,f.useRef)(null),P=(0,f.useRef)(null),F=(0,f.useRef)(null),I=(0,f.useRef)(c);I.current=c,(0,f.useEffect)(()=>{k(``)},[e,b,x]);let L=(0,f.useCallback)((e=!0,t)=>{t?I.current(!1,t):I.current(!1),M(``),k(``),e&&te.current?.focus({preventScroll:!0})},[]);(0,f.useEffect)(()=>{if(!s)return;y&&P.current?.focus({preventScroll:!0});let e=e=>{N.current?.contains(e.target)||L(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[s,L,y]);let R=E?.selected??null,z=i??R??(v?r:null)??D?.remembered??null,B=(0,f.useMemo)(()=>{let e=ee.trim().toLowerCase(),t=new Map;for(let n of D?.entries??[])(!e||`${n.provider}/${n.model}`.toLowerCase().includes(e))&&t.set(n.provider,[...t.get(n.provider)??[],n]);return[...t]},[D,ee]),V=D?.entries.find(e=>is(e,z)),H=(_||!!v)&&!!D&&!C&&!S&&n.isCurrent(),U=async(t,r)=>{if(!H||!n.isCurrent()||!D||!t.api||A||o)return;let i=ue({provider:t.provider,model:t.model,api:t.api,thinking:r});if(v&&a)a(i),L(!0,`chosen`);else if(E&&e){if(R&&rs(R,i))L(!0,`chosen`),u?.(i);else{j(!0),k(``);try{let t=await e.chooseModel({expected:E.version,choice:i});if(!n.isCurrent())return;if(t.kind===`error`){k(t.error.code),w();return}let r={...E,version:t.value.version,selected:t.value.selected};if(!n.accept(r))return;l(),L(!0,`chosen`),u?.(i)}catch{n.isCurrent()&&(k(`uncertain`),w())}finally{j(!1)}}}},ne=()=>[...F.current?.querySelectorAll(`button[role=option]:not(:disabled)`)??[]],re=e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;e.preventDefault();let t=ne(),n=t.indexOf(document.activeElement)+(e.key===`ArrowDown`?1:-1);n<0?P.current?.focus():t[Math.min(n,t.length-1)]?.focus()},W=t.status===`stopped`||t.status===`not-started`,ie=D?null:r,G=n.preview||n.loading&&a||S&&a?m(C?`Reading models…`:S?`Model list unavailable`:`Choose a model`):W?m(`Choose a model`):t.status===`preparing`?m(`Preparing execution…`):t.status===`incompatible`?m(`Model selection needs a compatible connection`):t.status===`connecting`?m(`Checking execution state…`):t.status===`unavailable`?m(`Execution state unavailable`):m(C?`Reading models…`:S?`Model list unavailable`:`Choose a model`),ae=z?g(z):W&&ie?m(`Last used: {model}`,{model:g(ie)}):G;return(0,h.jsxs)(`div`,{className:`model-picker`,ref:N,children:[(0,h.jsxs)(`button`,{ref:te,type:`button`,className:`model-trigger${z&&!R||ie?` remembered`:``}${D&&!z?` empty`:``}`,"aria-label":m(`Model: {model}`,{model:ae}),"aria-haspopup":`dialog`,"aria-expanded":s,title:o?m(`Switch models after the current reply finishes.`):i?m(`Choose now; the model is verified when you send.`):ie?m(`Last used model; availability is checked when you send.`):z&&!R?m(`Last used model; it is used again when you send.`):z?`${z.provider}/${z.model} · ${z.api}`:G,onClick:()=>{s?L():(k(``),c(!0))},children:[(0,h.jsx)(di,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{className:`model-trigger-text`,children:ae}),(0,h.jsx)(_i,{"aria-hidden":`true`})]}),s&&(0,h.jsxs)(`div`,{className:`model-popover`,role:`dialog`,"aria-label":m(`Choose a model`),onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),L())},children:[d&&(0,h.jsx)(`p`,{className:`model-popover-lead`,children:m(`Choose a model; your message is sent right after.`)}),v&&(0,h.jsx)(`p`,{className:`model-popover-lead`,children:m(`Choose now; the model is verified when you send.`)}),!y&&!S&&(0,h.jsx)(`p`,{className:`model-popover-lead`,role:`status`,children:t.status===`preparing`?m(`Execution is being prepared for your Send. Models will load when it is ready.`):t.status===`incompatible`?m(`Reload the page to observe a compatible execution connection before choosing a model.`):m(`Model selection is unavailable until the current conversation and execution state are observed.`)}),ie&&(0,h.jsxs)(`p`,{className:`model-popover-lead`,children:[m(`Last used: {model}`,{model:g(ie)}),(0,h.jsx)(`br`,{}),m(`Last used model; availability is checked when you send.`)]}),y&&(0,h.jsxs)(`label`,{className:`model-search`,children:[(0,h.jsx)(qr,{"aria-hidden":`true`}),(0,h.jsx)(`input`,{ref:P,type:`search`,"aria-label":m(`Search models`),placeholder:m(`Search models…`),value:ee,onChange:e=>M(e.target.value),onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),ne()[0]?.focus()):e.key===`Enter`&&(e.preventDefault(),ne()[0]?.click())}})]}),y&&(0,h.jsxs)(`div`,{className:`model-list`,role:`listbox`,"aria-label":m(`Models`),ref:F,onKeyDown:re,children:[C&&(0,h.jsx)(`p`,{className:`model-empty`,role:`status`,children:m(`Reading models…`)}),B.map(([e,t])=>(0,h.jsxs)(`fieldset`,{className:`model-group`,children:[(0,h.jsx)(`legend`,{className:`model-group-label`,children:e}),t.map(e=>{let t=e.eligibility===`candidate`,n=is(e,z);return(0,h.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":n,className:`model-option`,disabled:!H||!t||A||o,title:`${e.provider}/${e.model}${e.api?` · ${e.api}`:``}`,onClick:()=>void U(e,as(e,z?.thinking??`medium`)),children:[(0,h.jsx)(`span`,{className:`model-option-name`,children:e.model}),!t&&(0,h.jsx)(`span`,{className:`model-option-note`,children:e.eligibility===`auth-unavailable`?m(`Credentials unavailable`):m(`Not supported`)}),n&&(!R||!!i)&&(0,h.jsx)(`span`,{className:`model-option-note`,children:m(`Used when you send`)}),n&&(0,h.jsx)(vi,{className:`model-option-check`,"aria-hidden":`true`})]},`${e.provider}/${e.model}`)})]},e)),D?.status===`complete`&&B.length===0&&(0,h.jsx)(`p`,{className:`model-empty`,children:ee.trim()?m(`No matching models.`):m(v?`No models are configured. Add a provider to Pi's models.json or auth.json, then read the list again.`:`No models are configured. Add a provider to Pi's models.json or auth.json, then restart the service.`)})]}),y&&V&&V.thinking.length>1&&(0,h.jsxs)(`div`,{className:`model-thinking`,children:[(0,h.jsx)(`span`,{className:`model-thinking-label`,children:m(`Thinking`)}),V.thinking.map(e=>(0,h.jsx)(`button`,{type:`button`,"aria-label":m(`Thinking level: {level}`,{level:m(ts[e.level])}),"aria-pressed":z?.thinking===e.level,disabled:!H||!e.selectable||A||o,onClick:()=>void U(V,e.level),children:m(ts[e.level])},e.level))]}),(0,h.jsxs)(`div`,{className:`model-popover-notes`,children:[v&&!S&&(0,h.jsx)(`button`,{type:`button`,className:`link`,disabled:C||A,onClick:w,children:m(`Refresh models`)}),o&&(0,h.jsx)(`p`,{children:m(`Switch models after the current reply finishes.`)}),D?.status===`capacity`&&(0,h.jsx)(`p`,{role:`alert`,children:m(`Catalog capacity exceeded; no partial model list is selectable.`)}),!!D?.withheld&&(0,h.jsx)(`p`,{role:`alert`,children:m(D.withheld===1?`{count} model withheld: its provider or model ID contains a credential value (such as an apiKey equal to the provider name) or control characters. Give each credential a value that matches no provider or model ID; restart the service after editing models.json.`:`{count} models withheld: their provider or model IDs contain a credential value (such as an apiKey equal to the provider name) or control characters. Give each credential a value that matches no provider or model ID; restart the service after editing models.json.`,{count:D.withheld})}),(_||!!a)&&S&&(0,h.jsxs)(`p`,{role:`alert`,children:[m(`The model list could not be read ({code}).`,{code:S}),` `,(0,h.jsx)(`button`,{type:`button`,className:`link`,onClick:w,children:m(`Read again`)})]}),O&&(0,h.jsx)(`p`,{role:`alert`,children:ns[O]?m(ns[O]):m(`The model was not changed ({code}).`,{code:O})}),H&&(0,h.jsx)(`p`,{className:`model-popover-scope`,children:m(A?`Switching model…`:p===`next-conversation`?`Used for your next new conversation after choosing a folder.`:`This model is used for future messages in this conversation. Work already started keeps its original model.`)})]})]})]})}function cs(e){let t=new Set(e.map(e=>e.id)),n=new Map;for(let r of e){let e=r.parent!==null&&t.has(r.parent)?r.parent:null,i=n.get(e);i?i.push(r):n.set(e,[r])}let r=[],i=[],a=(e,t)=>{let n=e.length>1;for(let r=e.length-1;r>=0;r--)i.push({node:e[r],depth:n?t+1:t})};for(a(n.get(null)??[],-1);i.length;){let e=i.pop();r.push({...e,depth:Math.max(0,e.depth)}),a(n.get(e.node.id)??[],Math.max(0,e.depth))}return r}function ls({client:e,id:t,leaf:n,onChoose:r,onClose:i}){let{t:a}=T(),o=Ki(e,{kind:`conversation-tree`,id:t,leaf:n}),s=o.value?.kind===`conversation-tree`?o.value:void 0,c=(0,f.useMemo)(()=>cs(s?.nodes??[]),[s]);return(0,h.jsxs)(`section`,{className:`branch-tree`,"aria-label":a(`Conversation branches`),children:[(0,h.jsxs)(`header`,{children:[(0,h.jsx)(`h3`,{children:a(`Conversation branches`)}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":a(`Close`),onClick:i,children:(0,h.jsx)(Hr,{"aria-hidden":`true`})})]}),(0,h.jsx)(`p`,{className:`panel-hint`,children:a(`Each line is a message; indented lines are branches. Choose one to read that branch. The terminal shares this tree (/tree in Pi).`)}),o.error&&(0,h.jsx)(`p`,{role:`alert`,children:b(a,o.error)}),!s&&!o.error&&(0,h.jsx)(`p`,{children:a(`Reading…`)}),s?.truncated&&(0,h.jsx)(`p`,{className:`panel-hint`,children:a(`Only the newest messages are listed.`)}),(0,h.jsx)(`ol`,{className:`branch-rows`,children:c.map(({node:e,depth:t})=>(0,h.jsx)(`li`,{style:{paddingInlineStart:`${t*16}px`},children:(0,h.jsxs)(`button`,{type:`button`,className:`branch-row${e.current?` current`:``}`,"aria-current":e.current?`true`:void 0,title:e.text,onClick:()=>r(e.leaf),children:[(0,h.jsx)(`span`,{className:`branch-text`,children:e.text||`…`}),e.at>0&&(0,h.jsx)(`time`,{dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()})]})},e.id))})]})}function us({active:e,armed:t,known:n,disabled:r,onClick:i}){let{t:a}=T(),o=n?e?`on`:t?`armed`:`off`:`unknown`,s=a(n?e?`Cadence on`:t?`Cadence on next Send`:`Cadence off`:`Cadence state unavailable`);return(0,h.jsxs)(`button`,{type:`button`,className:`mode-toggle ${o}`,"aria-label":s,disabled:r||!n,title:a(e?`Cadence mode is on. Click to exit it.`:t?`Your next message turns on Cadence mode. Click to cancel.`:`Turn on Cadence mode: agree on a plan before implementation.`),onClick:i,children:[(0,h.jsx)(`span`,{className:`mode-switch`,"aria-hidden":`true`}),s]})}function ds(){let[e,t]=(0,f.useState)([]),n=(0,f.useRef)(e),r=(0,f.useRef)(new WeakMap);return{files:e,add:e=>{let i=[...new Set([...n.current,...e])];Ro(i);for(let t of e)r.current.has(t)||r.current.set(t,crypto.randomUUID());n.current=i,t(i)},remove:(0,f.useCallback)(e=>{n.current=n.current.filter(t=>!e.includes(t)),t(n.current)},[]),key:e=>r.current.get(e)}}function fs({file:e,disabled:t,remove:n}){let{t:r}=T(),[i,a]=(0,f.useState)(``),[o,s]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{let t=!0,n=``;return a(``),s(!1),zo(e).then(()=>{t&&(n=URL.createObjectURL(e),a(n))}).catch(()=>{t&&s(!0)}),()=>{t=!1,n&&URL.revokeObjectURL(n)}},[e]),(0,h.jsxs)(`div`,{className:`chat-image-draft`,children:[i&&(0,h.jsx)(`img`,{src:i,alt:e.name}),o&&(0,h.jsx)(`span`,{className:`banner-notice`,children:r(`Invalid image.`)}),(0,h.jsx)(`span`,{title:e.name,children:e.name}),(0,h.jsx)(`button`,{type:`button`,disabled:t,"aria-label":r(`Remove image: {name}`,{name:e.name}),onClick:n,children:`×`})]})}function ps({image:e,read:t}){let{t:n}=T(),[r,i]=(0,f.useState)(``),[a,o]=(0,f.useState)(!1),{entry:s,index:c,mimeType:l,live:u}=e;return(0,f.useEffect)(()=>{let e=new AbortController,n=``;if(i(``),o(!1),!t)o(!0);else return t({entry:s,index:c,mimeType:l,...u?{live:u}:{}},e.signal).then(t=>{e.signal.aborted||(n=URL.createObjectURL(t),i(n))}).catch(()=>{e.signal.aborted||o(!0)}),()=>{e.abort(),n&&URL.revokeObjectURL(n)}},[t,s,c,l,u]),a?(0,h.jsx)(`span`,{className:`banner-notice`,children:n(`Image unavailable.`)}):r?(0,h.jsx)(`a`,{href:r,target:`_blank`,rel:`noreferrer`,"aria-label":n(`Open image`),children:(0,h.jsx)(`img`,{src:r,alt:n(`Attached image`),loading:`lazy`,onError:()=>o(!0)})}):(0,h.jsx)(`span`,{className:`inspector-note`,children:n(`Loading image…`)})}function ms({images:e,turn:t}){return(0,h.jsx)(`div`,{className:`chat-images`,children:e.map(e=>(0,h.jsx)(ps,{image:e,read:t.image},`${e.live?`live`:`session`}:${e.entry}:${e.index}`))})}var hs=/^\s{0,3}(`{3,}|~{3,})/,gs=/^\s{0,3}(?:[-*+]|\d{1,9}[.)])\s/;function _s(e){return e.trim()===``}function vs(e){let t=hs.exec(e);return t?t[1]:null}function ys(e){let t=e.split(`
16
16
  `),n=[],r=[],i=null;for(let e=0;e<t.length;e++){let a=t[e];if(i!==null){let e=vs(a);e&&e[0]===i[0]&&e.length>=i.length&&(i=null),r.push(a);continue}let o=vs(a);if(o&&!_s(a))i=o,r.push(a);else if(_s(a)){let i=e;for(;i<t.length&&_s(t[i]);)i++;if(!(i<t.length&&gs.test(t[i]))&&r.length>0){n.push(r.join(`
17
17
  `)),r=[];continue}r.push(a)}else r.push(a)}return{frozen:n,active:r.join(`
@@ -19,7 +19,7 @@ import{r as e}from"./rolldown-runtime.js";import{n as t,r as n,t as r}from"./rea
19
19
  `).filter(e=>e&&e!==`Hidden thinking, signatures and media are not retained.`);return(0,h.jsxs)(`section`,{className:`chat-turn`,"aria-label":r(`Conversation turn`),children:[o.map(({step:t,index:n})=>(0,h.jsxs)(`article`,{className:`chat-message user`,children:[(0,h.jsx)(`div`,{className:`chat-message-role`,children:r(`You`)}),(0,h.jsx)(zs,{turn:e,index:n,step:t})]},n)),(u||c.length>0)&&(0,h.jsxs)(`article`,{className:`chat-message assistant`,children:[(0,h.jsx)(`div`,{className:`chat-message-role`,children:`Cadence`}),u&&(0,h.jsx)(Rs,{turn:e,steps:s,live:l,answered:c.length>0,toggled:t,onToggle:e=>n?.(a.id,e)}),c.map(({step:t,index:n})=>(0,h.jsx)(zs,{turn:e,index:n,step:t,render:a.status===`running`?e=>(0,h.jsx)(ks,{text:e}):void 0},n))]}),a.execution&&(0,h.jsxs)(`details`,{className:`inspector-note`,children:[(0,h.jsx)(`summary`,{children:r(`Context fixed at admission:`)}),(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`code`,{children:a.execution.cwd}),` ·`,` `,a.execution.model?`${a.execution.model.provider}/${a.execution.model.model} · ${a.execution.model.thinking}`:r(`No model`)]})]}),d.length>0&&(0,h.jsx)(`p`,{className:`inspector-note chat-turn-notice`,children:d.map(e=>i(e)).join(`
20
20
  `)}),![`completed`,`running`,`queued`].includes(a.status)&&(0,h.jsx)(`p`,{className:`ep-state ${a.status}`,children:i(a.status)})]})});function Hs({hint:e,children:t}){let{t:n}=T();return(0,h.jsxs)(`div`,{className:`empty-state chat-welcome`,children:[(0,h.jsx)(`span`,{className:`empty-logo`,"aria-hidden":`true`,children:`C`}),(0,h.jsx)(`h2`,{children:n(`What would you like to work on?`)}),(0,h.jsx)(`p`,{children:e}),t]})}var Us=[`queued`,`running`],Ws=e=>Us.includes(e.status);function Gs(e){return e.diagnostics?.acceptedAt??e.steps.find(e=>e.timing)?.timing?.createdAt??null}function Ks(e){return e.status===`queued`?`queued`:e.phase===`research`?`researching`:e.phase}function qs(e,t,n){let r=[],i=[],a=new Map;if(!e.length)return{start:r,after:a,end:i};let o=e.filter(e=>e.header.at>0),s=e=>Gs(e)??2**53-1;for(let e of[...t].sort((e,t)=>s(e)-s(t))){let t=Gs(e),s=t===null?void 0:o.findLast(e=>e.header.at<=t);t===null||!o.length?i.push(e):s?a.set(s.header.id,[...a.get(s.header.id)??[],e]):n||r.push(e)}return{start:r,after:a,end:i}}function Js(e,t,n,r,i,a){if(t>=e.length)return t;let o=e.slice(-t);if(o.some(e=>!n.has(e)&&!r.has(e)))return t;let s=o.flatMap(e=>{let t=n.get(e),r=t?Gs(t):null;return r===null?[]:[r]}),c=s.length?Math.min(...s):1/0;return a||i!==void 0&&c>=i?t+8:t}function Ys(e,t){let n=e.diagnostics?.acceptedAt,r=e.diagnostics?.settledAt;if(!n||!r||r<n)return``;let i=Math.round((r-n)/1e3);return i<60?t(`{s}s`,{s:i}):i<3600?t(`{m}m {s}s`,{m:Math.floor(i/60),s:i%60}):t(`{h}h {m}m`,{h:Math.floor(i/3600),m:Math.floor(i%3600/60)})}function Xs({client:e,run:t,onOpen:n,onChanged:r}){let{t:i,tx:a}=T(),o=(0,f.useId)(),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(``),d=(0,f.useRef)(!0);(0,f.useEffect)(()=>(d.current=!0,()=>{d.current=!1}),[]);let p=Ws(t),m=p?[a(Ks(t)),t.steps.filter(e=>e.status===`running`).map(e=>_o(e.id)).join(`, `)]:[a(t.status),t.mergedCommit?i(`merged {commit}`,{commit:t.mergedCommit.slice(0,7)}):``,Ys(t,i)],g=p||t.status===`completed`?``:t.notice.split(`
21
21
  `).find(e=>e.trim())??``,_=m.filter(Boolean).join(` · `);return(0,h.jsxs)(`article`,{className:`workflow-line ${t.status}`,"aria-labelledby":o,children:[(0,h.jsxs)(`button`,{type:`button`,className:`workflow-line-open`,title:i(`Open workflow details`),onClick:n,children:[(0,h.jsx)(`span`,{className:`agent-dot ${t.status}`,"aria-hidden":`true`}),(0,h.jsx)(`span`,{className:`workflow-line-goal`,id:o,children:t.goal}),(0,h.jsx)(`span`,{className:`workflow-line-meta ep-state ${t.status}`,title:_,children:_})]}),p&&(0,h.jsxs)(`button`,{type:`button`,className:`ghost workflow-line-stop`,"aria-label":i(`Cancel workflow — request stop`),title:i(`Cancel workflow — request stop`),disabled:s,onClick:()=>{c(!0),u(``),Qs(e,t).then(e=>{d.current&&(u(e),r?.())}).finally(()=>{d.current&&c(!1)})},children:[(0,h.jsx)(Wr,{"aria-hidden":`true`}),i(`Stop`)]}),l?(0,h.jsx)(`p`,{className:`workflow-line-reason`,role:`alert`,children:b(i,l)}):g&&(0,h.jsx)(`p`,{className:`workflow-line-reason`,title:g,children:a(g)})]})}function Zs({proposal:e,canApprove:t,approvalHint:n,onApprove:r}){let{t:i}=T();return(0,h.jsxs)(`section`,{className:`workflow-plan`,"aria-label":i(`Current implementation plan`),children:[(0,h.jsx)(`h3`,{children:i(`Current implementation plan`)}),(0,h.jsx)(`p`,{children:i(`Tools and checks run on the service host, not in a sandbox.`)}),(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`code`,{children:e.cwd}),` · `,e.display?.model]}),(0,h.jsxs)(`p`,{children:[i(`Declared write paths use the checkout root:`),` `,(0,h.jsx)(`code`,{children:e.checkoutRoot??e.cwd})]}),e.display?.branch&&(0,h.jsxs)(`p`,{children:[(0,h.jsx)(`code`,{children:e.display.branch}),` ·`,` `,(0,h.jsx)(`code`,{children:e.display.baseCommit})]}),(0,h.jsx)(`p`,{children:i(`Approval covers this goal and boundary: adaptive implementation, checks, recovery, project knowledge and the displayed local delivery. No push, publication or deployment.`)}),(0,h.jsx)(ka,{text:`## ${e.plan.goal}\n\n${e.plan.acceptance}\n\n${e.plan.decisions}`}),(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:i(`Complete delivery agreement`)}),(0,h.jsx)(ka,{text:nr(e.plan)})]}),e.delivery&&(0,h.jsx)(ka,{text:Zn(e.delivery)}),(0,h.jsx)(`button`,{type:`button`,className:`primary`,disabled:!t,onClick:r,children:i(`Implement this plan`)}),!t&&(0,h.jsx)(`p`,{className:`inspector-note`,role:`status`,children:n??i(`Plan approval is currently unavailable.`)}),(0,h.jsx)(`p`,{children:i(`To change the plan, continue the conversation. A changed plan requires fresh approval.`)})]})}async function Qs(e,t){let n=await e.workbenchCommand({kind:`workflow-cancel`,commandId:crypto.randomUUID(),epoch:t.epoch,runId:t.id});return n.kind===`error`?n.error.code:``}function $s(e){return(0,h.jsx)(ec,{...e},e.id)}function ec({client:e,id:t,onChanged:n,onOpenAgent:r}){let{t:i,tx:a}=T(),[o,s]=(0,f.useState)(1e3),[c,l]=(0,f.useState)(),u=Ki(e,{kind:`workflow`,id:t},o),d=Ki(e,c===void 0?null:{kind:`workflow`,id:t,before:c}),p=d.value?.kind===`workflow`&&d.value.response.type===`run`?d.value.response.run:null,m=u.value?.kind===`workflow`&&u.value.response.type===`run`?u.value.response.run:null,g=c===void 0?m:p,[_,v]=(0,f.useState)(null),y=Ki(e,_?{kind:`workflow-detail`,id:t,stepId:_}:null),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(``),w=m&&[`queued`,`running`].includes(m.status),E=(0,f.useRef)(!0);return(0,f.useEffect)(()=>(E.current=!0,()=>{E.current=!1}),[]),(0,f.useEffect)(()=>{m&&![`queued`,`running`].includes(m.status)&&s(0)},[m]),(0,h.jsxs)(`article`,{className:`workflow-card chat-tool`,"aria-label":i(`Workflow progress`),children:[(0,h.jsxs)(`header`,{children:[(0,h.jsx)(`strong`,{children:m?.goal??i(`Observing workflow`)}),m&&(0,h.jsxs)(`span`,{className:`ep-state ${m.status}`,children:[a(m.phase),` · `,a(m.status)]})]}),(u.error||d.error||S)&&(0,h.jsxs)(`p`,{role:`alert`,children:[S||u.error||d.error,` ·`,` `,i(`State unavailable is not completion. No automatic resubmission.`)]}),m?.execution&&(0,h.jsxs)(`p`,{className:`inspector-note`,children:[i(`Context fixed at admission:`),` `,(0,h.jsx)(`code`,{children:m.execution.cwd}),` ·`,` `,m.execution.model?`${m.execution.model.provider}/${m.execution.model.model} · ${m.execution.model.thinking}`:i(`No model`)]}),m?.notice&&(0,h.jsx)(`p`,{children:m.notice}),m?.delivery&&(0,h.jsx)(tc,{delivery:m.delivery}),m&&(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:`Owner timing and runtime`}),(0,h.jsx)(`pre`,{className:`workflow-detail`,children:or(m)})]}),m?.mergedCommit&&(0,h.jsxs)(`p`,{children:[i(`Actual local merge commit:`),` `,(0,h.jsx)(`code`,{children:m.mergedCommit})]}),m&&(0,h.jsx)(`p`,{className:`inspector-note`,children:i(`Agent review is not human review. Worktrees and retained results are preserved.`)}),m&&(m.revision??0)>0&&(0,h.jsxs)(`p`,{children:[i(`Implementation route updates`),`: `,m.revision]}),m&&((g?.stepsBefore??0)>0||c!==void 0)&&(0,h.jsxs)(`nav`,{className:`workflow-actions`,children:[(g?.stepsBefore??0)>0&&(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>l(g?.stepsBefore),children:i(`Earlier workflow steps`)}),c!==void 0&&(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>{l(void 0),s(1e3)},children:i(`Latest workflow steps`)})]}),g?.steps.map(e=>(0,h.jsxs)(`details`,{className:`chat-tool`,children:[(0,h.jsxs)(`summary`,{children:[a(e.kind),` · `,_o(e.id),` · `,a(e.status)]}),e.exitCode!==null&&(0,h.jsxs)(`p`,{children:[i(`Exit code`),`: `,e.exitCode]}),(0,h.jsx)(ka,{text:e.text}),e.childRunId&&r&&(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>r({runId:t,stepId:e.id,label:_o(e.id)}),children:i(`Open subagent context`)}),e.truncated&&(0,h.jsx)(`p`,{children:i(`Preview is truncated.`)}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>v(e.id),children:i(`Read retained step result`)}),_===e.id&&y.value?.kind===`file`&&(0,h.jsx)(`pre`,{className:`workflow-detail`,children:y.value.text}),_===e.id&&y.error&&(0,h.jsx)(`p`,{role:`alert`,children:y.error})]},e.id)),w&&(0,h.jsx)(`button`,{type:`button`,className:`danger`,disabled:b,onClick:()=>{m&&(x(!0),Qs(e,m).then(e=>{E.current&&(C(e),u.refresh(),n?.())}).finally(()=>{E.current&&x(!1)}))},children:i(`Cancel workflow — request stop`)}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>{u.refresh(),c!==void 0&&d.refresh()},children:i(`Observe current state`)})]})}function tc({delivery:e}){let{t,tx:n}=T(),r=[[t(`Task branch`),e.taskBranch],[t(`Task worktree`),e.worktreeRoot],[t(`Delivery target`),`${e.binding.target.branch} @ ${e.binding.target.head}`],[t(`Worktree preparation`),n(e.preparation)],[t(`Candidate commit`),e.candidate??t(`Not recorded`)],[t(`Candidate acceptance`),e.acceptance?`${t(`Checks and automatic Agent review passed`)} · ${e.acceptance.candidate}`:t(`Not recorded`)],[t(`Local integration`),`${n(e.integration.status)}${e.integration.after?` · ${e.integration.after}`:``}`],[t(`Post-merge checks`),n(e.postChecks)],[t(`Worktree cleanup`),n(e.cleanup.status)]];return(0,h.jsxs)(`section`,{className:`workflow-delivery`,"aria-label":t(`Task branch delivery`),children:[(0,h.jsx)(`dl`,{children:r.map(([e,t])=>(0,h.jsxs)(f.Fragment,{children:[(0,h.jsx)(`dt`,{children:e}),(0,h.jsx)(`dd`,{children:(0,h.jsx)(`code`,{children:t})})]},e))}),e.integration.reason&&(0,h.jsx)(`p`,{children:e.integration.reason}),e.cleanup.reason&&(0,h.jsx)(`p`,{children:e.cleanup.reason}),(0,h.jsx)(`p`,{children:t(`Policy: keep the task branch; no push or deployment.`)})]})}var nc=typeof CSS<`u`&&CSS.supports(`overflow-anchor`,`auto`);function rc(e){try{return sessionStorage.getItem(e)??``}catch{return``}}function ic({client:e,id:t,workspaceId:n,initialCwd:r,initialLeaf:i=null,activitySelected:a=!1,onLocation:o,enabled:s,actionsReady:c=s,prepareForSend:l,legacyWorkspaceId:u,directoryNamespaces:d=[],available:p=s,canInterrupt:m=s,modelAvailability:g,previewModels:_,initialModel:v,onModelChanged:y,onChanged:x,reference:S,onReferenceUsed:C,hidden:w=!1,onOpenAgent:E,onWorkflowRuns:D}){let{t:O,tx:k}=T(),[A]=(0,f.useState)(()=>Lo(n,t,u,...d)),[j,M]=(0,f.useState)(()=>rc(A)),N=ds(),te=N.remove,P=(0,f.useRef)([]),F=(0,f.useRef)(null),[I,L]=(0,f.useState)(()=>rc(`${A}:mode`)===`cadence`?`cadence`:`chat`),[R,z]=(0,f.useState)(!1),[B,V]=(0,f.useState)(``),[H,U]=(0,f.useState)(()=>rc(`${A}:pending`)),[ne,re]=(0,f.useState)(()=>rc(`${A}:model-command`)),[ie,G]=(0,f.useState)(!1),[ae,oe]=(0,f.useState)(!1),[se,ce]=(0,f.useState)(!1),[le,K]=(0,f.useState)(0),de=(0,f.useRef)(null),fe=(0,f.useRef)(!1),pe=(0,f.useRef)(0),me=(0,f.useRef)(new AbortController),[he,q]=(0,f.useState)(!1),[ge,_e]=(0,f.useState)(()=>{try{let e=sessionStorage.getItem(`${A}:model`);if(e)return ue(JSON.parse(e))}catch{}return v??null});(0,f.useEffect)(()=>{try{ge?sessionStorage.setItem(`${A}:model`,JSON.stringify(ge)):sessionStorage.removeItem(`${A}:model`)}catch{}},[A,ge]);let ve=Ki(e,p&&r?{kind:`conversation-context`,location:{id:t,cwd:r}}:null,1e3),ye=ve.value?.kind===`conversation-context`?ve.value.context:void 0,be=!!ye&&!ve.error,xe=ye?.cwd??r,Se=(0,f.useMemo)(()=>({models:n=>xe?e.models(n,{id:t,cwd:xe}):Promise.resolve({kind:`error`,error:ee(`unavailable`)}),chooseModel:n=>xe?e.chooseModel(n,{id:t,cwd:xe}):Promise.resolve({kind:`error`,error:ee(`unavailable`)})}),[e,t,xe]),Ce=he?{status:`preparing`}:g.status===`ready`&&(!p||!be)?{status:ve.error?`unavailable`:`connecting`}:g,we=(0,f.useRef)(Ce);we.current=Ce;let Te=Zo(Se,Ce,`${le}:${ye?.revision??`unobserved`}`,_),Ee=()=>{de.current=null,oe(!1),ce(!1)},J=(e,t)=>{e&&!Te.preview&&!Te.loading?Te.reread():!e&&t!==`chosen`&&Ee(),G(e)},De=(e,t)=>{_e(t?null:e);let n=de.current;ae&&n&&(No(n,we.current)===`cancel`?(Ee(),V(O(`The connection changed. Your model choice and draft are kept; send again when ready.`))):(de.current=Mo(n,e,t),oe(!1),V(``),ce(!0)))},Oe=(0,f.useRef)(o);Oe.current=o,(0,f.useEffect)(()=>{be&&xe&&Oe.current?.({id:t,cwd:xe})},[be,t,xe]);let Y=Yo(e,t,p,i),{turns:ke}=Y,Ae=Y.summary!==void 0,je=Ki(e,p?{kind:`cadence-conversation`,id:t}:null,1e3),X=je.value?.kind===`cadence-conversation`?je.value.state:void 0,Me=X?.enabled===!0,Ne=!!X||!!je.error,Pe=!!X&&!je.error&&!X.notice,Fe=(0,f.useRef)(X);Fe.current=X;let[Ie,Le]=(0,f.useState)(``),Re=(0,f.useRef)(``),ze=qi(j,Me?`cadence`:I),Be=s&&!(a&&!Y.summary)&&be&&Ae&&!Y.error&&Ne&&!(Me&&(je.error||X?.notice))&&!R&&!ae&&!H,Ve=Y.summary??void 0,He=Ve&&(Ve.status===`queued`||Ve.status===`running`),Ue=!!Ve&&Ve.status!==`completed`&&!He,[We,Ge]=(0,f.useState)(!1),Ke=!!l&&s&&(!!Y.error||!!ve.error)&&Y.error!==`retired-conversation`&&ve.error!==`retired-conversation`&&!X?.notice&&!He&&!R&&!H&&!ae,qe=(m||!!l)&&be&&Ae&&Pe&&!Y.error&&!R&&!H&&!He,Je=!!ge&&W(ge)!==W(ye?.model??null),Ye=!!X?.proposal&&!!Ve&&!He&&Ve.status!==`unknown`,Xe=Je?O(`Send with this model before approving a plan.`):Ve?.status===`unknown`?O(`The latest turn's outcome is unknown. Approval waits until it is observed.`):c?Pe?He?O(`Wait for the current reply before approving this plan.`):Ie?O(`Observing plan approval…`):Be?void 0:O(`Read the current conversation context before approving this plan.`):O(`Cadence state unavailable`):O(`Read the current execution state before approving this plan.`),Ze=(0,f.useRef)(null),Qe=(0,f.useRef)(null),$e=(0,f.useRef)(0),et=(0,f.useRef)(!0),[tt,Z]=(0,f.useState)(!1);(0,f.useLayoutEffect)(()=>{!w&&Qe.current&&!et.current&&(Qe.current.scrollTop=$e.current)},[w]);let nt=(0,f.useRef)(!0),rt=(0,f.useRef)(``),it=(0,f.useRef)(j);(0,f.useEffect)(()=>(nt.current=!0,me.current.signal.aborted&&(me.current=new AbortController),()=>{nt.current=!1,me.current.abort()}),[]),(0,f.useEffect)(()=>{try{sessionStorage.setItem(`${A}:mode`,I)}catch{}},[A,I]),(0,f.useEffect)(()=>{try{sessionStorage.setItem(A,j)}catch{}},[j,A]),(0,f.useEffect)(()=>{try{H?sessionStorage.setItem(`${A}:pending`,H):sessionStorage.removeItem(`${A}:pending`)}catch{}},[A,H]),(0,f.useEffect)(()=>{try{H&&ne===H?sessionStorage.setItem(`${A}:model-command`,ne):sessionStorage.removeItem(`${A}:model-command`)}catch{}},[A,H,ne]),(0,f.useEffect)(()=>{S&&(M(e=>`${e}${e?`
22
- `:``}@${S}`),C(),Ze.current?.focus())},[S,C]),(0,f.useEffect)(()=>{let e=Ve?`${Ve.leaf}:${Ve.status}`:``;e&&rt.current!==e&&(rt.current=e,x()),Re.current&&X?.runs.includes(Re.current)&&(Re.current=``,Le(``),V(``)),H&&(Ve?.live?.commandId===H||Y.attempt?.commandId===H||ke.some(e=>e.header.id===H)||Y.commands.includes(H))&&(U(``),Po(H,ne)&&_e(null),re(``),te(P.current),M(e=>e===it.current?``:e),x()),et.current&&Qe.current&&(Qe.current.scrollTop=Qe.current.scrollHeight)},[Ve,ke,H,ne,x,X,Y,te]);let at=(0,f.useMemo)(()=>ke.map(e=>({id:e.header.id,role:`assistant`,version:e.steps.reduce((e,t)=>e+t.text.length+1,e.header.status.length),turn:e})),[ke]),ot=oo(Qe,at),st=(0,f.useRef)(new Map),ct=(0,f.useCallback)((e,t)=>{st.current.set(e,t)},[]),{earlier:lt,loadEarlier:ut}=Y,dt=()=>{let e=Qe.current;e&&!w&&lt&&e.scrollTop<1200&&ut()};(0,f.useEffect)(dt);let ft=ke[0]?.ordinal,pt=(0,f.useRef)({height:0});(0,f.useLayoutEffect)(()=>{let e=Qe.current;if(!e)return;let t=pt.current;!nc&&!et.current&&t.ordinal!==void 0&&ft!==void 0&&ft<t.ordinal&&(e.scrollTop+=e.scrollHeight-t.height),pt.current={ordinal:ft,height:e.scrollHeight}}),(0,f.useEffect)(()=>{try{sessionStorage.removeItem(`${A}:approval`)}catch{}},[A]);let mt=(0,f.useMemo)(()=>[...new Set([...Y.runs,...X?.runs??[]])],[Y.runs,X?.runs]),ht=JSON.stringify(mt.slice(-4));(0,f.useEffect)(()=>{D?.(JSON.parse(ht))},[ht,D]);let[gt,_t]=(0,f.useState)({terminal:8,browser:8}),vt=(0,f.useMemo)(()=>[...new Set([...Y.runs.slice(-gt.terminal),...(X?.runs??[]).slice(-gt.browser)])],[Y.runs,X?.runs,gt]),yt=bo(e,p?vt:[],1e3),bt=ke.find(e=>e.header.at>0)?.header.at,xt=!lt&&ke.length>0;(0,f.useEffect)(()=>{if(!p)return;let e=(e,t)=>Js(e,t,yt.runs,yt.unreadable,bt,xt),t=e(Y.runs,gt.terminal),n=e(X?.runs??[],gt.browser);(t!==gt.terminal||n!==gt.browser)&&_t({terminal:t,browser:n})},[p,Y.runs,X?.runs,gt,yt,bt,xt]);let St=(0,f.useMemo)(()=>qs(ke,yt.runs.values(),lt),[ke,yt.runs,lt]),Ct=[...yt.runs.values()].filter(Ws).at(-1),wt=[...yt.runs.values()].map(e=>`${e.id}:${e.status}`).join();(0,f.useLayoutEffect)(()=>{wt&&et.current&&Qe.current&&(Qe.current.scrollTop=Qe.current.scrollHeight)},[wt]);let Tt=t=>(0,h.jsx)(Xs,{client:e,run:t,onOpen:()=>E?.({runId:t.id,stepId:null,label:t.goal}),onChanged:()=>{je.refresh(),x()}},t.id),Et=async()=>{if(!X?.proposal){V(O(`No plan is awaiting approval.`));return}if(Je||!c||!Pe||!Be||He||Ie||!Ye)return;let t=X,n=pe.current;z(!0),V(``);try{let r=await Qo({client:e,state:t,current:()=>nt.current&&pe.current===n&&Fe.current?.revision===t.revision&&Fe.current?.enabled===!0,submitting:e=>{Re.current=e,Le(e)}});if(!nt.current||pe.current!==n)return;r.kind===`error`?(V(r.error.code),Le(``)):M(e=>es(e)?``:e)}catch(e){nt.current&&pe.current===n&&V(e instanceof Error?e.message:`unavailable`)}finally{nt.current&&pe.current===n&&(z(!1),je.refresh(),Y.refresh(),x())}},Dt=async(n,r)=>{let i=r?.text??n??j,a=r?.images??(n?[]:N.files),o=r?r.command.kind===`cadence-exit`:Me&&$o(i);if(!(o?qe:Be)&&!Ke||He||!i.trim()&&!a.length||r&&(!Be||No(r,we.current)!==`ready`))return;if(o&&a.length){V(O(`Remove images before exiting Cadence.`));return}if(!a.length&&!r&&!n&&Me&&es(i)){c?await Et():V(O(`Execution is not ready to approve this plan. Send a message to refresh the conversation first; nothing was approved.`));return}let s=qi(i,I).mode===`cadence`;if(!Ke&&(Me||s)&&!Pe){V(O(`Cadence state unavailable. Observe the conversation before sending.`));return}if(fe.current)return;fe.current=!0,z(!0),V(``);let u=pe.current,d=()=>nt.current&&pe.current===u,f=!1,p=`not-dispatched`,m=e=>{d()&&(U(e),re(e&&!o?e:``))},h=async e=>{l&&(q(!0),await Co(l,me.current.signal,e,e=>{p=e}),d()&&(q(!1),K(e=>e+1)))};try{if(Ke){if(await h(ye?{id:t,cwd:ye.cwd}:void 0),!d())return;Y.refresh(),ve.refresh(),je.refresh(),x(),V(O(`Execution was prepared, but the conversation was unreadable before Send. Review its restored context and send again; this message was not sent.`));return}let n=r??Do({id:t,head:Y.leaf,text:i,images:a,revision:X?.revision??0,location:ye?{id:t,cwd:ye.cwd}:void 0,installModel:!!ge,model:ge??(Te.catalog?.selected?Oo(Te.catalog.selected):Te.catalog?.remembered??ye?.model??Te.preview?.remembered??void 0),intent:o?`exit`:Me?`message`:s?`enter`:`ordinary`});if(r){if(No(r,we.current)!==`ready`)throw Error(`stale`)}else await h(n.location);if(!d())return;if(n.command.kind===`cadence-exit`){let t=Io(n);it.current=i,f=!0;let r=await Eo(e,t,m);if(!d())return;r.kind===`error`?V(O(To(r.error.effect),{code:r.error.code})):(U(``),L(`chat`),M(e=>e===i?``:e)),je.refresh(),Y.refresh(),x();return}let c=e=>{let t=we.current,r=e??(t.status===`ready`?t.epoch:void 0);r&&No(jo(n,r),t)!==`cancel`?(de.current=jo(n,r),oe(!0)):(Ee(),V(O(`The connection changed. Your model choice and draft are kept; send again when ready.`))),J(!0)},l=await e.models(void 0,n.location);if(!d())return;if(n.preparedEpoch&&l.kind===`ok`&&l.value.version.epoch!==n.preparedEpoch)throw Error(`stale`);let u=l.kind===`ok`?l.value.selected??l.value.remembered:null;if(!n.model&&u&&(n=ko(n,u)),n.installModel&&l.kind===`ok`){if(l={kind:`ok`,value:await Fo(e,n,l.value,d)},!d())return;K(e=>e+1)}let p=n.model??(l.kind===`ok`?l.value.remembered:null);if(l.kind===`ok`&&!l.value.selected&&p){let t=await e.workbenchCommand({kind:`restore-model`,commandId:crypto.randomUUID(),epoch:l.value.version.epoch,...n.location?{location:n.location,expected:l.value.version,choice:p}:{}});if(!d())return;if(t.kind===`error`){V(t.error.code),c(l.value.version.epoch);return}if(l=await e.models(void 0,n.location),!d())return;K(e=>e+1)}if(l.kind!==`ok`||!l.value.selected){c(l.kind===`ok`?l.value.version.epoch:void 0);return}Ao(n,l.value.selected);let g=Io(n,l.value.version);if(n.images.length){let t=l.value.selected;if(!l.value.entries.some(e=>e.provider===t?.provider&&e.model===t?.model&&e.images)){V(O(`The selected model does not support images. Choose a vision model or remove the images.`));return}if(g.kind===`cadence-exit`)throw Error(`invalid`);if(g=await Vo(e,g,n.images,d),!d())return}P.current=n.images,it.current=i,f=!0;let _=await Eo(e,g,m);if(!d())return;_.kind===`error`?V(O(To(_.error.effect),{code:_.error.code})):(te(P.current),_e(null),M(e=>e===it.current?``:e),U(``),g.kind===`cadence-send`&&L(`chat`),At(null)),je.refresh(),Y.refresh(),x()}catch(e){d()&&V(O(f?To():wo(p),{code:e instanceof Error?e.message:`unavailable`}))}finally{pe.current===u&&(fe.current=!1),d()&&(z(!1),q(!1))}},Ot=(0,f.useRef)(Dt);Ot.current=Dt,(0,f.useEffect)(()=>{let e=de.current;if(!e||!se&&!ae)return;let t=No(e,Ce);t===`cancel`?(de.current=null,oe(!1),ce(!1),V(O(`The connection changed. Your model choice and draft are kept; send again when ready.`))):se&&t===`ready`&&Be&&!He&&(ce(!1),de.current=null,Ot.current(void 0,e))},[se,ae,Be,He,Ce,O]),(0,f.useEffect)(()=>{if(!se)return;let e=setTimeout(()=>{ce(!1),de.current=null},1e4);return()=>clearTimeout(e)},[se]);let kt=async()=>{let n=Ve?.live;if(!n||R)return;z(!0);let r=await e.workbenchCommand({kind:`interrupt`,commandId:crypto.randomUUID(),conversationId:t,turnId:n.commandId,epoch:n.epoch});nt.current&&(r.kind===`error`&&V(r.error.code),z(!1),Y.refresh())},At=e=>{++pe.current,me.current.abort(),me.current=new AbortController,de.current=null,fe.current=!1,oe(!1),ce(!1),G(!1),z(!1),q(!1),Y.choose(e),Ge(!1)},jt=R||ae||!!H||!!He,Mt=e=>{if(!jt)try{N.add(e),V(``)}catch(e){V(k(e instanceof Error?e.message:`unavailable`))}};return(0,h.jsxs)(`section`,{className:`chat-workspace`,hidden:w,"aria-label":O(Pe?Me?`Cadence conversation`:`Ordinary conversation`:`Conversation`),children:[(0,h.jsxs)(`header`,{className:`conversation-header`,children:[(0,h.jsxs)(`div`,{className:`conversation-heading`,children:[(0,h.jsx)(Zr,{"aria-hidden":`true`}),(0,h.jsx)(`h2`,{children:Ve?.title??(a?O(`Discovered session`):Y.summary===null?O(`New conversation`):O(`Conversation`))}),(0,h.jsx)(`span`,{className:`conversation-badge`,children:O(Pe?Me?`Cadence on`:`Ordinary`:`Cadence state unavailable`)}),Ve&&(0,h.jsx)(`span`,{className:`conversation-badge`,children:Ve.origin===`terminal`?O(`Started in the terminal`):O(`Started in the WebUI`)})]}),(0,h.jsxs)(`div`,{className:`conversation-branch`,children:[(Y.branches>1||Y.pinned)&&(0,h.jsxs)(`button`,{type:`button`,className:`ghost`,"aria-expanded":We,onClick:()=>Ge(e=>!e),children:[(0,h.jsx)(ai,{"aria-hidden":`true`}),O(`Branches ({count})`,{count:Y.branches})]}),Y.pinned&&(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>At(null),children:O(`Show the latest`)}),Ct&&(0,h.jsx)(`span`,{className:`ep-state running`,children:k(Ks(Ct))}),Ve&&(!Ct||Ue||Me&&!He&&!!X?.proposal)&&(0,h.jsx)(`span`,{className:`ep-state ${Ve.status}`,children:Me?He?O(`Discussing`):Ue?k(Ve.status):X?.proposal?O(`Awaiting plan approval`):O(`Ready for conversation`):k(Ve.status)})]})]}),xe&&(0,h.jsxs)(`p`,{className:`conversation-cwd`,title:xe,children:[O(`Conversation folder:`),` `,(0,h.jsx)(`code`,{children:xe})]}),ve.error&&!Ke&&(0,h.jsx)(`p`,{role:`alert`,className:`inspector-note`,children:b(O,ve.error)}),Ke&&(0,h.jsx)(`p`,{className:`panel-hint`,role:`status`,children:O(`Conversation context is unavailable. Send can prepare execution, but cannot submit this draft until the context is observed.`)}),he&&(0,h.jsx)(`p`,{className:`panel-hint`,role:`status`,children:O(`Preparing execution for this Send…`)}),We&&(0,h.jsx)(ls,{client:e,id:t,leaf:Y.leaf,onChoose:At,onClose:()=>Ge(!1)}),(0,h.jsxs)(`div`,{className:`chat-messages`,ref:Qe,onScroll:()=>{let e=Qe.current;e&&!w&&($e.current=e.scrollTop,et.current=e.scrollHeight-e.scrollTop-e.clientHeight<80,Z(!et.current),dt())},children:[a&&!Y.summary&&(0,h.jsx)(`p`,{role:`status`,className:`panel-hint`,children:O(`Activity was discovered; session history is not yet readable. No transcript was created.`)}),!p&&(0,h.jsx)(`p`,{role:`status`,className:`panel-hint`,children:O(`Conversation content has not been read. You can keep a draft; nothing is sent until the context is available.`)}),Y.summary===null&&!Y.error&&!a&&(0,h.jsx)(Hs,{hint:O(`Type a message below. Turn on Cadence mode to agree on a plan before implementation.`)}),p&&!Y.error&&(!Ae||ke.length===0&&Y.count>0)&&(0,h.jsx)(`p`,{className:`inspector-note chat-reading`,role:`status`,children:O(`Reading this conversation…`)}),ke.length>0&&lt&&(0,h.jsx)(`div`,{className:`chat-earlier`,role:`status`,children:Y.loadingEarlier&&O(`Reading earlier messages…`)}),St.start.map(Tt),at.map(({id:e,version:t,turn:n})=>(0,h.jsxs)(f.Fragment,{children:[(0,h.jsx)(so,{id:e,show:!ot.hidden.has(e),height:ot.placeholder(e,t,320),containerRef:Qe,onMeasured:ot.recordMeasured,lazyRef:ot.register(e),children:(0,h.jsx)(Vs,{turn:n,toggled:st.current.get(e)??null,onToggle:ct})}),St.after.get(e)?.map(Tt),n.header.entry&&n.ordinal<Y.count-1&&!He&&(0,h.jsxs)(`button`,{type:`button`,className:`ghost turn-branch`,title:O(`Show the conversation up to here. The next message starts a new branch; nothing is deleted.`),onClick:()=>At(n.header.entry),children:[(0,h.jsx)(fi,{"aria-hidden":`true`}),O(`Continue from here`)]})]},e)),St.end.map(Tt),Y.attempt&&(0,h.jsxs)(`article`,{className:`chat-attempt`,"aria-label":O(`Message`),children:[(0,h.jsx)(`p`,{className:`chat-attempt-text`,children:Y.attempt.text}),(0,h.jsxs)(`p`,{className:`inspector-note`,children:[(0,h.jsx)(`span`,{className:`ep-state ${Y.attempt.status}`,children:k(Y.attempt.status)}),` `,Y.attempt.notice?k(Y.attempt.notice):``]})]}),X?.enabled&&X.proposal&&(0,h.jsx)(Zs,{proposal:X.proposal,canApprove:!Je&&c&&Be&&Pe&&Ye&&!He&&!Ie,approvalHint:Xe,onApprove:()=>void Et()}),X?.enabled&&!X.proposal&&mt.length===0&&(0,h.jsx)(`p`,{className:`inspector-note`,children:O(`Cadence stays on for this conversation until you explicitly exit.`)}),yt.failed&&(0,h.jsx)(`p`,{className:`inspector-note`,role:`status`,children:O(`Workflow activity unavailable; retained work may still be running.`)}),X?.notice&&(0,h.jsx)(`p`,{role:`alert`,className:`banner-notice`,children:k(X.notice)}),[...new Set([B,Y.error,je.error])].filter(Boolean).map(e=>(0,h.jsx)(`p`,{role:`alert`,className:`banner-notice`,children:b(O,e??``)},e)),Y.error&&Y.summary!==void 0&&(0,h.jsx)(`p`,{role:`status`,className:`inspector-note`,children:O(`Conversation state is not current. Previously read content may be shown; this does not mean work has stopped.`)}),H&&(0,h.jsxs)(`p`,{className:`inspector-note`,children:[O(`Send outcome not yet observed:`),` `,(0,h.jsx)(`code`,{children:H}),` `,(0,h.jsx)(`button`,{type:`button`,onClick:Y.refresh,children:O(`Observe current state`)})]}),Y.pinned&&!He&&(0,h.jsx)(`p`,{className:`inspector-note`,children:O(`You are viewing an earlier point of this conversation. A message sent now starts a new branch here; the rest stays in the session.`)})]}),tt&&(0,h.jsx)(`button`,{type:`button`,className:`chat-scroll-bottom`,"aria-label":O(`Latest messages`),onClick:()=>{Qe.current&&(Qe.current.scrollTop=Qe.current.scrollHeight),et.current=!0},children:(0,h.jsx)(xi,{})}),(0,h.jsxs)(`form`,{className:`chat-composer`,onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&e.preventDefault()},onDrop:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),Mt(Array.from(e.dataTransfer.files)))},onSubmit:e=>{e.preventDefault(),Dt()},children:[(0,h.jsx)(`input`,{ref:F,type:`file`,accept:Nn.join(`,`),multiple:!0,hidden:!0,disabled:jt,"aria-label":O(`Add images`),onChange:e=>{Mt(Array.from(e.currentTarget.files??[])),e.currentTarget.value=``}}),N.files.length>0&&(0,h.jsx)(`div`,{className:`chat-images`,children:N.files.map(e=>(0,h.jsx)(fs,{file:e,disabled:jt,remove:()=>te([e])},N.key(e)))}),!He&&!Ke&&!Be&&!he&&(0,h.jsx)(`p`,{className:`composer-status`,role:`status`,children:O(H?`The last Send is not yet confirmed. No message is resent.`:ae?`Choose a model; your message is sent right after.`:R?`Sending…`:`Sending is unavailable until the current context is observed. Your draft stays here.`)}),(0,h.jsx)(`textarea`,{ref:Ze,disabled:R||!!H||ae,"aria-label":O(`Message`),value:j,placeholder:O(`Message, or /cadence to enter continuous Cadence mode…`),rows:3,onChange:e=>M(e.target.value),onPaste:e=>{let t=Array.from(e.clipboardData.files).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Mt(t))},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Dt())}}),(0,h.jsxs)(`div`,{className:`composer-toolbar`,children:[(0,h.jsx)(`button`,{type:`button`,className:`ghost icon`,disabled:jt,"aria-label":O(`Add images`),title:O(`Add images`),onClick:()=>F.current?.click(),children:(0,h.jsx)(ni,{"aria-hidden":`true`})}),(0,h.jsx)(us,{active:Me,armed:ze.mode===`cadence`,known:Pe,disabled:Me?!qe:!!He||R||!!H||ae,onClick:()=>{Me?Dt(`exit cadence`):ze.mode===`cadence`?(L(`chat`),qi(j,`chat`).mode===`cadence`&&M(ze.text)):L(`cadence`)}}),(0,h.jsx)(ss,{client:Se,availability:Ce,read:Te,lastModel:ye?.model,draftModel:ge,onPreviewChoice:_?e=>De(e,!1):void 0,locked:!!He||R||!!H,open:ie,onOpenChange:J,onChanged:()=>{ve.refresh(),y()},onChosen:e=>De(e,!0),awaitingSend:ae}),(0,h.jsx)(`span`,{className:`composer-hint`,children:Me?O(`Cadence stays on. Confirm one plan before implementation.`):ze.mode===`cadence`?O(`Your next message turns on Cadence mode.`):``}),He?(0,h.jsxs)(`button`,{type:`button`,className:`danger`,disabled:R||!m,onClick:()=>void kt(),children:[(0,h.jsx)(Wr,{}),O(`Stop response`)]}):(0,h.jsxs)(`button`,{type:`submit`,className:`primary`,disabled:!(Me&&$o(j)?qe:Be)&&!Ke||!j.trim()&&!N.files.length,children:[(0,h.jsx)(yi,{}),O(`Send`)]})]})]})]})}function ac({client:e,enabled:t,location:n,onReference:r}){let{t:i}=T(),[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(null),[l,u]=(0,f.useState)(``),d=Ki(e,t?{kind:`files`,path:a,...n?{location:n}:{}}:null),p=Ki(e,t&&s?{kind:`file`,path:s,...n?{location:n}:{}}:null),m=d.value?.kind===`files`?d.value:void 0,g=p.value?.kind===`file`?p.value:void 0;return(0,h.jsxs)(`div`,{className:`files-panel`,children:[(0,h.jsxs)(`header`,{className:`files-toolbar`,children:[(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":i(`Parent folder`),disabled:m?.parent==null,onClick:()=>{m?.parent!=null&&o(m.parent)},children:(0,h.jsx)(yi,{})}),(0,h.jsxs)(`span`,{className:`files-path`,title:n?`${n.cwd}${a?` / ${a}`:``}`:void 0,children:[i(`Conversation folder:`),` `,a||n?.cwd||i(`Not observed`)]}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":i(`Refresh files`),disabled:!t,onClick:()=>{d.refresh(),p.refresh()},children:(0,h.jsx)(Jr,{})})]}),d.error&&(0,h.jsx)(`p`,{className:`inspector-note`,role:`alert`,children:b(i,d.error)}),(0,h.jsxs)(`section`,{className:`file-list`,"aria-label":i(`File list`),children:[t?!m&&!d.error?(0,h.jsx)(`p`,{className:`panel-empty`,role:`status`,children:i(`Reading files…`)}):null:(0,h.jsx)(`p`,{className:`panel-empty`,role:`status`,children:i(n?`Files are unavailable until the execution state is ready.`:`The conversation folder has not been observed.`)}),m?.entries.map(e=>(0,h.jsxs)(`div`,{className:`file-row`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`file-name${s===e.path?` selected`:``}`,title:e.path,onClick:()=>e.directory?o(e.path):c(e.path),children:[e.directory?(0,h.jsx)(oi,{}):(0,h.jsx)(si,{}),(0,h.jsx)(`span`,{children:e.name})]}),(0,h.jsx)(`button`,{type:`button`,className:`file-action`,"aria-label":i(`Reference {path}`,{path:e.name}),disabled:!t||!!d.error,onClick:()=>r(e.path),children:(0,h.jsx)(Yr,{})}),(0,h.jsx)(`button`,{type:`button`,className:`file-action`,"aria-label":i(`Copy path {path}`,{path:e.name}),onClick:()=>void ga(e.path).then(e=>u(e?``:i(`Link copy unavailable.`))),children:(0,h.jsx)(pi,{})})]},e.path)),t&&!d.error&&m?.entries.length===0&&(0,h.jsx)(`p`,{className:`panel-empty`,children:i(`No visible files`)}),m?.limited&&(0,h.jsx)(`p`,{className:`inspector-note`,children:i(`Bounded listing; narrow the directory to see more.`)})]}),s&&(0,h.jsxs)(`section`,{className:`file-preview`,children:[(0,h.jsxs)(`header`,{children:[(0,h.jsx)(`span`,{title:s,children:s}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":i(`Close preview`),onClick:()=>c(null),children:(0,h.jsx)(Hr,{})})]}),p.error&&(0,h.jsx)(`p`,{role:`alert`,children:b(i,p.error)}),g&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`pre`,{children:g.text}),g.limited&&(0,h.jsx)(`p`,{className:`inspector-note`,children:i(`File preview is limited; this is not the complete file.`)})]})]}),l&&(0,h.jsx)(`p`,{role:`alert`,children:l}),(0,h.jsx)(`p`,{className:`files-policy`,children:i(`Readonly preview · references send paths, not file contents`)})]})}var oc=`未命名章节`;function sc(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function cc(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=sc(r||oc),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||oc}})}function lc(e){return e.length>=2}function uc(e){let t=0,n=0;return e.split(`
22
+ `:``}@${S}`),C(),Ze.current?.focus())},[S,C]),(0,f.useEffect)(()=>{let e=Ve?`${Ve.leaf}:${Ve.status}`:``;e&&rt.current!==e&&(rt.current=e,x()),Re.current&&X?.runs.includes(Re.current)&&(Re.current=``,Le(``),V(``)),H&&(Ve?.live?.commandId===H||Y.attempt?.commandId===H||ke.some(e=>e.header.id===H)||Y.commands.includes(H))&&(U(``),Po(H,ne)&&_e(null),re(``),te(P.current),M(e=>e===it.current?``:e),x()),et.current&&Qe.current&&(Qe.current.scrollTop=Qe.current.scrollHeight)},[Ve,ke,H,ne,x,X,Y,te]);let at=(0,f.useMemo)(()=>ke.map(e=>({id:e.header.id,role:`assistant`,version:e.steps.reduce((e,t)=>e+t.text.length+1,e.header.status.length),turn:e})),[ke]),ot=oo(Qe,at),st=(0,f.useRef)(new Map),ct=(0,f.useCallback)((e,t)=>{st.current.set(e,t)},[]),{earlier:lt,loadEarlier:ut}=Y,dt=()=>{let e=Qe.current;e&&!w&&lt&&e.scrollTop<1200&&ut()};(0,f.useEffect)(dt);let ft=ke[0]?.ordinal,pt=(0,f.useRef)({height:0});(0,f.useLayoutEffect)(()=>{let e=Qe.current;if(!e)return;let t=pt.current;!nc&&!et.current&&t.ordinal!==void 0&&ft!==void 0&&ft<t.ordinal&&(e.scrollTop+=e.scrollHeight-t.height),pt.current={ordinal:ft,height:e.scrollHeight}}),(0,f.useEffect)(()=>{try{sessionStorage.removeItem(`${A}:approval`)}catch{}},[A]);let mt=(0,f.useMemo)(()=>[...new Set([...Y.runs,...X?.runs??[]])],[Y.runs,X?.runs]),ht=JSON.stringify(mt.slice(-4));(0,f.useEffect)(()=>{D?.(JSON.parse(ht))},[ht,D]);let[gt,_t]=(0,f.useState)({terminal:8,browser:8}),vt=(0,f.useMemo)(()=>[...new Set([...Y.runs.slice(-gt.terminal),...(X?.runs??[]).slice(-gt.browser)])],[Y.runs,X?.runs,gt]),yt=bo(e,p?vt:[],1e3),bt=ke.find(e=>e.header.at>0)?.header.at,xt=!lt&&ke.length>0;(0,f.useEffect)(()=>{if(!p)return;let e=(e,t)=>Js(e,t,yt.runs,yt.unreadable,bt,xt),t=e(Y.runs,gt.terminal),n=e(X?.runs??[],gt.browser);(t!==gt.terminal||n!==gt.browser)&&_t({terminal:t,browser:n})},[p,Y.runs,X?.runs,gt,yt,bt,xt]);let St=(0,f.useMemo)(()=>qs(ke,yt.runs.values(),lt),[ke,yt.runs,lt]),Ct=[...yt.runs.values()].filter(Ws).at(-1),wt=[...yt.runs.values()].map(e=>`${e.id}:${e.status}`).join();(0,f.useLayoutEffect)(()=>{wt&&et.current&&Qe.current&&(Qe.current.scrollTop=Qe.current.scrollHeight)},[wt]);let Tt=t=>(0,h.jsx)(Xs,{client:e,run:t,onOpen:()=>E?.({runId:t.id,stepId:null,label:t.goal}),onChanged:()=>{je.refresh(),x()}},t.id),Et=async()=>{if(!X?.proposal){V(O(`No plan is awaiting approval.`));return}if(Je||!c||!Pe||!Be||He||Ie||!Ye)return;let t=X,n=pe.current;z(!0),V(``);try{let r=await Qo({client:e,state:t,current:()=>nt.current&&pe.current===n&&Fe.current?.revision===t.revision&&Fe.current?.enabled===!0,submitting:e=>{Re.current=e,Le(e)}});if(!nt.current||pe.current!==n)return;r.kind===`error`?(V(r.error.code),Le(``)):M(e=>es(e)?``:e)}catch(e){nt.current&&pe.current===n&&V(e instanceof Error?e.message:`unavailable`)}finally{nt.current&&pe.current===n&&(z(!1),je.refresh(),Y.refresh(),x())}},Dt=async(n,r)=>{let i=r?.text??n??j,a=r?.images??(n?[]:N.files),o=r?r.command.kind===`cadence-exit`:Me&&$o(i);if(!(o?qe:Be)&&!Ke||He||!i.trim()&&!a.length||r&&(!Be||No(r,we.current)!==`ready`))return;if(o&&a.length){V(O(`Remove images before exiting Cadence.`));return}if(!a.length&&!r&&!n&&Me&&es(i)){c?await Et():V(O(`Execution is not ready to approve this plan. Send a message to refresh the conversation first; nothing was approved.`));return}let s=qi(i,I).mode===`cadence`;if(!Ke&&(Me||s)&&!Pe){V(O(`Cadence state unavailable. Observe the conversation before sending.`));return}if(fe.current)return;fe.current=!0,z(!0),V(``);let u=pe.current,d=()=>nt.current&&pe.current===u,f=!1,p=`not-dispatched`,m=e=>{d()&&(U(e),re(e&&!o?e:``))},h=async e=>{l&&(q(!0),await Co(l,me.current.signal,e,e=>{p=e}),d()&&(q(!1),K(e=>e+1)))};try{if(Ke){if(await h(ye?{id:t,cwd:ye.cwd}:void 0),!d())return;Y.refresh(),ve.refresh(),je.refresh(),x(),V(O(`Execution was prepared, but the conversation was unreadable before Send. Review its restored context and send again; this message was not sent.`));return}let n=r??Do({id:t,head:Y.leaf,text:i,images:a,revision:X?.revision??0,location:ye?{id:t,cwd:ye.cwd}:void 0,installModel:!!ge,model:ge??(Te.catalog?.selected?Oo(Te.catalog.selected):Te.catalog?.remembered??ye?.model??Te.preview?.remembered??void 0),intent:o?`exit`:Me?`message`:s?`enter`:`ordinary`});if(r){if(No(r,we.current)!==`ready`)throw Error(`stale`)}else await h(n.location);if(!d())return;if(n.command.kind===`cadence-exit`){let t=Io(n);it.current=i,f=!0;let r=await Eo(e,t,m);if(!d())return;r.kind===`error`?V(O(To(r.error.effect),{code:r.error.code})):(U(``),L(`chat`),M(e=>e===i?``:e)),je.refresh(),Y.refresh(),x();return}let c=e=>{let t=we.current,r=e??(t.status===`ready`?t.epoch:void 0);r&&No(jo(n,r),t)!==`cancel`?(de.current=jo(n,r),oe(!0)):(Ee(),V(O(`The connection changed. Your model choice and draft are kept; send again when ready.`))),J(!0)},l=await e.models(void 0,n.location);if(!d())return;if(n.preparedEpoch&&l.kind===`ok`&&l.value.version.epoch!==n.preparedEpoch)throw Error(`stale`);let u=l.kind===`ok`?l.value.selected??l.value.remembered:null;if(!n.model&&u&&(n=ko(n,u)),n.installModel&&l.kind===`ok`){if(l={kind:`ok`,value:await Fo(e,n,l.value,d)},!d())return;K(e=>e+1)}let p=n.model??(l.kind===`ok`?l.value.remembered:null);if(l.kind===`ok`&&!l.value.selected&&p){let t=await e.workbenchCommand({kind:`restore-model`,commandId:crypto.randomUUID(),epoch:l.value.version.epoch,...n.location?{location:n.location,expected:l.value.version,choice:p}:{}});if(!d())return;if(t.kind===`error`){V(t.error.code),c(l.value.version.epoch);return}if(l=await e.models(void 0,n.location),!d())return;K(e=>e+1)}if(l.kind!==`ok`||!l.value.selected){c(l.kind===`ok`?l.value.version.epoch:void 0);return}Ao(n,l.value.selected);let g=Io(n,l.value.version);if(n.images.length){let t=l.value.selected;if(!l.value.entries.some(e=>e.provider===t?.provider&&e.model===t?.model&&e.images)){V(O(`The selected model does not support images. Choose a vision model or remove the images.`));return}if(g.kind===`cadence-exit`)throw Error(`invalid`);if(g=await Vo(e,g,n.images,d),!d())return}P.current=n.images,it.current=i,f=!0;let _=await Eo(e,g,m);if(!d())return;_.kind===`error`?V(O(To(_.error.effect),{code:_.error.code})):(te(P.current),_e(null),M(e=>e===it.current?``:e),U(``),g.kind===`cadence-send`&&L(`chat`),At(null)),je.refresh(),Y.refresh(),x()}catch(e){d()&&V(O(f?To():wo(p),{code:e instanceof Error?e.message:`unavailable`}))}finally{pe.current===u&&(fe.current=!1),d()&&(z(!1),q(!1))}},Ot=(0,f.useRef)(Dt);Ot.current=Dt,(0,f.useEffect)(()=>{let e=de.current;if(!e||!se&&!ae)return;let t=No(e,Ce);t===`cancel`?(de.current=null,oe(!1),ce(!1),V(O(`The connection changed. Your model choice and draft are kept; send again when ready.`))):se&&t===`ready`&&Be&&!He&&(ce(!1),de.current=null,Ot.current(void 0,e))},[se,ae,Be,He,Ce,O]),(0,f.useEffect)(()=>{if(!se)return;let e=setTimeout(()=>{ce(!1),de.current=null},1e4);return()=>clearTimeout(e)},[se]);let kt=async()=>{let n=Ve?.live;if(!n||R)return;z(!0);let r=await e.workbenchCommand({kind:`interrupt`,commandId:crypto.randomUUID(),conversationId:t,turnId:n.commandId,epoch:n.epoch});nt.current&&(r.kind===`error`&&V(r.error.code),z(!1),Y.refresh())},At=e=>{++pe.current,me.current.abort(),me.current=new AbortController,de.current=null,fe.current=!1,oe(!1),ce(!1),G(!1),z(!1),q(!1),Y.choose(e),Ge(!1)},jt=R||ae||!!H||!!He,Mt=e=>{if(!jt)try{N.add(e),V(``)}catch(e){V(k(e instanceof Error?e.message:`unavailable`))}};return(0,h.jsxs)(`section`,{className:`chat-workspace`,hidden:w,"aria-label":O(Pe?Me?`Cadence conversation`:`Ordinary conversation`:`Conversation`),children:[(0,h.jsxs)(`header`,{className:`conversation-header`,children:[(0,h.jsxs)(`div`,{className:`conversation-heading`,children:[(0,h.jsx)(Zr,{"aria-hidden":`true`}),(0,h.jsx)(`h2`,{children:Ve?.title??(a?O(`Discovered session`):Y.summary===null?O(`New conversation`):O(`Conversation`))}),(0,h.jsx)(`span`,{className:`conversation-badge`,children:O(Pe?Me?`Cadence on`:`Ordinary`:`Cadence state unavailable`)}),Ve&&(0,h.jsx)(`span`,{className:`conversation-badge`,children:Ve.origin===`terminal`?O(`Started in the terminal`):O(`Started in the WebUI`)})]}),(0,h.jsxs)(`div`,{className:`conversation-branch`,children:[(Y.branches>1||Y.pinned)&&(0,h.jsxs)(`button`,{type:`button`,className:`ghost`,"aria-expanded":We,onClick:()=>Ge(e=>!e),children:[(0,h.jsx)(ai,{"aria-hidden":`true`}),O(`Branches ({count})`,{count:Y.branches})]}),Y.pinned&&(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>At(null),children:O(`Show the latest`)}),Ct&&(0,h.jsx)(`span`,{className:`ep-state running`,children:k(Ks(Ct))}),Ve&&(!Ct||Ue||Me&&!He&&!!X?.proposal)&&(0,h.jsx)(`span`,{className:`ep-state ${Ve.status}`,children:Me?He?O(`Discussing`):Ue?k(Ve.status):X?.proposal?O(`Awaiting plan approval`):O(`Ready for conversation`):k(Ve.status)})]})]}),ve.error&&!Ke&&(0,h.jsx)(`p`,{role:`alert`,className:`inspector-note`,children:b(O,ve.error)}),Ke&&(0,h.jsx)(`p`,{className:`panel-hint`,role:`status`,children:O(`Conversation context is unavailable. Send can prepare execution, but cannot submit this draft until the context is observed.`)}),he&&(0,h.jsx)(`p`,{className:`panel-hint`,role:`status`,children:O(`Preparing execution for this Send…`)}),We&&(0,h.jsx)(ls,{client:e,id:t,leaf:Y.leaf,onChoose:At,onClose:()=>Ge(!1)}),(0,h.jsxs)(`div`,{className:`chat-messages`,ref:Qe,onScroll:()=>{let e=Qe.current;e&&!w&&($e.current=e.scrollTop,et.current=e.scrollHeight-e.scrollTop-e.clientHeight<80,Z(!et.current),dt())},children:[a&&!Y.summary&&(0,h.jsx)(`p`,{role:`status`,className:`panel-hint`,children:O(`Activity was discovered; session history is not yet readable. No transcript was created.`)}),!p&&(0,h.jsx)(`p`,{role:`status`,className:`panel-hint`,children:O(`Conversation content has not been read. You can keep a draft; nothing is sent until the context is available.`)}),Y.summary===null&&!Y.error&&!a&&(0,h.jsx)(Hs,{hint:O(`Type a message below. Turn on Cadence mode to agree on a plan before implementation.`)}),p&&!Y.error&&(!Ae||ke.length===0&&Y.count>0)&&(0,h.jsx)(`p`,{className:`inspector-note chat-reading`,role:`status`,children:O(`Reading this conversation…`)}),ke.length>0&&lt&&(0,h.jsx)(`div`,{className:`chat-earlier`,role:`status`,children:Y.loadingEarlier&&O(`Reading earlier messages…`)}),St.start.map(Tt),at.map(({id:e,version:t,turn:n})=>(0,h.jsxs)(f.Fragment,{children:[(0,h.jsx)(so,{id:e,show:!ot.hidden.has(e),height:ot.placeholder(e,t,320),containerRef:Qe,onMeasured:ot.recordMeasured,lazyRef:ot.register(e),children:(0,h.jsx)(Vs,{turn:n,toggled:st.current.get(e)??null,onToggle:ct})}),St.after.get(e)?.map(Tt),n.header.entry&&n.ordinal<Y.count-1&&!He&&(0,h.jsxs)(`button`,{type:`button`,className:`ghost turn-branch`,title:O(`Show the conversation up to here. The next message starts a new branch; nothing is deleted.`),onClick:()=>At(n.header.entry),children:[(0,h.jsx)(fi,{"aria-hidden":`true`}),O(`Continue from here`)]})]},e)),St.end.map(Tt),Y.attempt&&(0,h.jsxs)(`article`,{className:`chat-attempt`,"aria-label":O(`Message`),children:[(0,h.jsx)(`p`,{className:`chat-attempt-text`,children:Y.attempt.text}),(0,h.jsxs)(`p`,{className:`inspector-note`,children:[(0,h.jsx)(`span`,{className:`ep-state ${Y.attempt.status}`,children:k(Y.attempt.status)}),` `,Y.attempt.notice?k(Y.attempt.notice):``]})]}),X?.enabled&&X.proposal&&(0,h.jsx)(Zs,{proposal:X.proposal,canApprove:!Je&&c&&Be&&Pe&&Ye&&!He&&!Ie,approvalHint:Xe,onApprove:()=>void Et()}),X?.enabled&&!X.proposal&&mt.length===0&&(0,h.jsx)(`p`,{className:`inspector-note`,children:O(`Cadence stays on for this conversation until you explicitly exit.`)}),yt.failed&&(0,h.jsx)(`p`,{className:`inspector-note`,role:`status`,children:O(`Workflow activity unavailable; retained work may still be running.`)}),X?.notice&&(0,h.jsx)(`p`,{role:`alert`,className:`banner-notice`,children:k(X.notice)}),[...new Set([B,Y.error,je.error])].filter(Boolean).map(e=>(0,h.jsx)(`p`,{role:`alert`,className:`banner-notice`,children:b(O,e??``)},e)),Y.error&&Y.summary!==void 0&&(0,h.jsx)(`p`,{role:`status`,className:`inspector-note`,children:O(`Conversation state is not current. Previously read content may be shown; this does not mean work has stopped.`)}),H&&(0,h.jsxs)(`p`,{className:`inspector-note`,children:[O(`Send outcome not yet observed:`),` `,(0,h.jsx)(`code`,{children:H}),` `,(0,h.jsx)(`button`,{type:`button`,onClick:Y.refresh,children:O(`Observe current state`)})]}),Y.pinned&&!He&&(0,h.jsx)(`p`,{className:`inspector-note`,children:O(`You are viewing an earlier point of this conversation. A message sent now starts a new branch here; the rest stays in the session.`)})]}),tt&&(0,h.jsx)(`button`,{type:`button`,className:`chat-scroll-bottom`,"aria-label":O(`Latest messages`),onClick:()=>{Qe.current&&(Qe.current.scrollTop=Qe.current.scrollHeight),et.current=!0},children:(0,h.jsx)(xi,{})}),(0,h.jsxs)(`form`,{className:`chat-composer`,onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&e.preventDefault()},onDrop:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),Mt(Array.from(e.dataTransfer.files)))},onSubmit:e=>{e.preventDefault(),Dt()},children:[(0,h.jsx)(`input`,{ref:F,type:`file`,accept:Nn.join(`,`),multiple:!0,hidden:!0,disabled:jt,"aria-label":O(`Add images`),onChange:e=>{Mt(Array.from(e.currentTarget.files??[])),e.currentTarget.value=``}}),N.files.length>0&&(0,h.jsx)(`div`,{className:`chat-images`,children:N.files.map(e=>(0,h.jsx)(fs,{file:e,disabled:jt,remove:()=>te([e])},N.key(e)))}),!He&&!Ke&&!Be&&!he&&(0,h.jsx)(`p`,{className:`composer-status`,role:`status`,children:O(H?`The last Send is not yet confirmed. No message is resent.`:ae?`Choose a model; your message is sent right after.`:R?`Sending…`:`Sending is unavailable until the current context is observed. Your draft stays here.`)}),(0,h.jsx)(`textarea`,{ref:Ze,disabled:R||!!H||ae,"aria-label":O(`Message`),value:j,placeholder:O(`Message, or /cadence to enter continuous Cadence mode…`),rows:3,onChange:e=>M(e.target.value),onPaste:e=>{let t=Array.from(e.clipboardData.files).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Mt(t))},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Dt())}}),(0,h.jsxs)(`div`,{className:`composer-toolbar`,children:[(0,h.jsx)(`button`,{type:`button`,className:`ghost icon`,disabled:jt,"aria-label":O(`Add images`),title:O(`Add images`),onClick:()=>F.current?.click(),children:(0,h.jsx)(ni,{"aria-hidden":`true`})}),(0,h.jsx)(us,{active:Me,armed:ze.mode===`cadence`,known:Pe,disabled:Me?!qe:!!He||R||!!H||ae,onClick:()=>{Me?Dt(`exit cadence`):ze.mode===`cadence`?(L(`chat`),qi(j,`chat`).mode===`cadence`&&M(ze.text)):L(`cadence`)}}),(0,h.jsx)(ss,{client:Se,availability:Ce,read:Te,lastModel:ye?.model,draftModel:ge,onPreviewChoice:_?e=>De(e,!1):void 0,locked:!!He||R||!!H,open:ie,onOpenChange:J,onChanged:()=>{ve.refresh(),y()},onChosen:e=>De(e,!0),awaitingSend:ae}),(0,h.jsx)(`span`,{className:`composer-hint`,children:Me?O(`Cadence stays on. Confirm one plan before implementation.`):ze.mode===`cadence`?O(`Your next message turns on Cadence mode.`):``}),He?(0,h.jsxs)(`button`,{type:`button`,className:`danger`,disabled:R||!m,onClick:()=>void kt(),children:[(0,h.jsx)(Wr,{}),O(`Stop response`)]}):(0,h.jsxs)(`button`,{type:`submit`,className:`primary`,disabled:!(Me&&$o(j)?qe:Be)&&!Ke||!j.trim()&&!N.files.length,children:[(0,h.jsx)(yi,{}),O(`Send`)]})]})]})]})}function ac({client:e,enabled:t,location:n,onReference:r}){let{t:i}=T(),[a,o]=(0,f.useState)(``),[s,c]=(0,f.useState)(null),[l,u]=(0,f.useState)(``),d=Ki(e,t?{kind:`files`,path:a,...n?{location:n}:{}}:null),p=Ki(e,t&&s?{kind:`file`,path:s,...n?{location:n}:{}}:null),m=d.value?.kind===`files`?d.value:void 0,g=p.value?.kind===`file`?p.value:void 0;return(0,h.jsxs)(`div`,{className:`files-panel`,children:[(0,h.jsxs)(`header`,{className:`files-toolbar`,children:[(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":i(`Parent folder`),disabled:m?.parent==null,onClick:()=>{m?.parent!=null&&o(m.parent)},children:(0,h.jsx)(yi,{})}),(0,h.jsxs)(`span`,{className:`files-path`,title:n?`${n.cwd}${a?` / ${a}`:``}`:void 0,children:[i(`Conversation folder:`),` `,a||n?.cwd||i(`Not observed`)]}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":i(`Refresh files`),disabled:!t,onClick:()=>{d.refresh(),p.refresh()},children:(0,h.jsx)(Jr,{})})]}),d.error&&(0,h.jsx)(`p`,{className:`inspector-note`,role:`alert`,children:b(i,d.error)}),(0,h.jsxs)(`section`,{className:`file-list`,"aria-label":i(`File list`),children:[t?!m&&!d.error?(0,h.jsx)(`p`,{className:`panel-empty`,role:`status`,children:i(`Reading files…`)}):null:(0,h.jsx)(`p`,{className:`panel-empty`,role:`status`,children:i(n?`Files are unavailable until the execution state is ready.`:`The conversation folder has not been observed.`)}),m?.entries.map(e=>(0,h.jsxs)(`div`,{className:`file-row`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`file-name${s===e.path?` selected`:``}`,title:e.path,onClick:()=>e.directory?o(e.path):c(e.path),children:[e.directory?(0,h.jsx)(oi,{}):(0,h.jsx)(si,{}),(0,h.jsx)(`span`,{children:e.name})]}),(0,h.jsx)(`button`,{type:`button`,className:`file-action`,"aria-label":i(`Reference {path}`,{path:e.name}),disabled:!t||!!d.error,onClick:()=>r(e.path),children:(0,h.jsx)(Yr,{})}),(0,h.jsx)(`button`,{type:`button`,className:`file-action`,"aria-label":i(`Copy path {path}`,{path:e.name}),onClick:()=>void ga(e.path).then(e=>u(e?``:i(`Link copy unavailable.`))),children:(0,h.jsx)(pi,{})})]},e.path)),t&&!d.error&&m?.entries.length===0&&(0,h.jsx)(`p`,{className:`panel-empty`,children:i(`No visible files`)}),m?.limited&&(0,h.jsx)(`p`,{className:`inspector-note`,children:i(`Bounded listing; narrow the directory to see more.`)})]}),s&&(0,h.jsxs)(`section`,{className:`file-preview`,children:[(0,h.jsxs)(`header`,{children:[(0,h.jsx)(`span`,{title:s,children:s}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":i(`Close preview`),onClick:()=>c(null),children:(0,h.jsx)(Hr,{})})]}),p.error&&(0,h.jsx)(`p`,{role:`alert`,children:b(i,p.error)}),g&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`pre`,{children:g.text}),g.limited&&(0,h.jsx)(`p`,{className:`inspector-note`,children:i(`File preview is limited; this is not the complete file.`)})]})]}),l&&(0,h.jsx)(`p`,{role:`alert`,children:l}),(0,h.jsx)(`p`,{className:`files-policy`,children:i(`Readonly preview · references send paths, not file contents`)})]})}var oc=`未命名章节`;function sc(e){return String(e??``).trim().replace(/[\s\u3000]+/g,`-`).replace(/[^\p{L}\p{N}_-]+/gu,`-`).replace(/-{2,}/g,`-`).replace(/^-+|-+$/g,``).slice(0,80)||`section`}function cc(e){let t=new Map;return e.map(({level:e,label:n})=>{let r=String(n??``).replace(/\s+/g,` `).trim(),i=sc(r||oc),a=(t.get(i)??0)+1;return t.set(i,a),{level:e,id:a===1?i:`${i}-${a}`,label:r||oc}})}function lc(e){return e.length>=2}function uc(e){let t=0,n=0;return e.split(`
23
23
  `).map(e=>{let r={key:`text-offset:${t}`,number:++n,text:e};return t+=e.length+1,r})}function dc({text:e}){return(0,h.jsx)(`pre`,{className:`scm-diff-pre`,children:uc(e).map(({text:e,key:t})=>{let n=``;return[`diff --git`,`index `,`new file`,`deleted file`,`old mode`,`new mode`,`similarity index`,`rename `,`copy `,`Binary files`,`---`,`+++`].some(t=>e.startsWith(t))?n=`hdr`:e.startsWith(`@@`)?n=`hunk`:e.startsWith(`+`)?n=`add`:e.startsWith(`-`)&&(n=`del`),(0,h.jsx)(`div`,{className:`scm-diff-line ${n}`,children:e||` `},t)})})}function fc({text:e}){let{t}=T(),[n,r]=(0,f.useState)(`raw`),[i,a]=(0,f.useState)(!0),[o,s]=(0,f.useState)(1),[c,l]=(0,f.useState)([]),[u,d]=(0,f.useState)(null),p=(0,f.useRef)(1),m=(0,f.useRef)(null),g=e.split(`
24
24
  `);return(0,f.useLayoutEffect)(()=>{if(n!==`markdown`)return;if(!e){l([]);return}let t=Array.from(m.current?.querySelectorAll(`h1,h2,h3,h4,h5,h6`)??[]),r=cc(t.map(e=>({level:Number(e.tagName[1]),label:e.textContent??``})));r.forEach((e,n)=>{t[n].id=`preview-${e.id}`}),l(r)},[e,n]),(0,h.jsxs)(`div`,{className:`fp-preview`,children:[(0,h.jsxs)(`div`,{className:`fp-head toolbar`,children:[(0,h.jsxs)(`label`,{children:[t(`View`),(0,h.jsxs)(`select`,{value:n,onChange:e=>r(e.target.value===`markdown`?`markdown`:e.target.value===`diff`?`diff`:`raw`),children:[(0,h.jsx)(`option`,{value:`raw`,children:t(`Raw text / lines`)}),(0,h.jsx)(`option`,{value:`markdown`,children:t(`Safe Markdown`)}),(0,h.jsx)(`option`,{value:`diff`,children:t(`Observed diff`)})]})]}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>a(e=>!e),children:t(i?`Wrap: on`:`Wrap: off`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>s(e=>Math.min(2,e+.1)),children:t(`Zoom +`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>s(e=>Math.max(.8,e-.1)),children:t(`Zoom −`)}),(0,h.jsx)(Ca,{text:u?g.slice(u.start-1,u.end).join(`
25
25
  `):e})]}),(0,h.jsx)(`p`,{className:`fp-notice`,children:t(`Captured page only, not a current filesystem read. Line numbers are page-local. Full retained paging and copy are available above.`)}),(0,h.jsx)(`div`,{style:{fontSize:`${o}em`},children:n===`markdown`?(0,h.jsxs)(`div`,{className:`fp-toc-layout`,children:[lc(c)&&(0,h.jsx)(`nav`,{className:`fp-toc`,"aria-label":t(`Page headings`),children:c.map(e=>(0,h.jsx)(`button`,{type:`button`,className:`l${e.level}`,onClick:()=>m.current?.querySelector(`#${CSS.escape(`preview-${e.id}`)}`)?.scrollIntoView({block:`nearest`}),children:e.label},e.id))}),(0,h.jsx)(`div`,{className:`fp-markdown-zoom`,ref:m,children:(0,h.jsx)(ka,{text:e})})]}):n===`diff`?(0,h.jsx)(dc,{text:e}):(0,h.jsx)(`div`,{className:`fp-code ${i?``:`no-wrap`}`,children:uc(e).map(({text:e,number:n,key:r})=>(0,h.jsxs)(`div`,{className:`fp-line ${u&&n>=u.start&&n<=u.end?`sel`:``}`,children:[(0,h.jsx)(`button`,{type:`button`,className:`fp-num`,"aria-label":t(`Select page line {line}`,{line:n}),onClick:e=>{e.shiftKey||(p.current=n),d({start:Math.min(p.current,n),end:Math.max(p.current,n)})},children:n}),(0,h.jsx)(`span`,{className:`fp-code-text`,children:e||` `})]},r))})}),u&&(0,h.jsxs)(`footer`,{className:`fp-foot`,children:[t(`Selected page lines {start}–{end}`,{start:u.start,end:u.end}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>d(null),children:t(`Clear selection`)})]})]})}function pc({client:e,seed:t}){let{t:n,tx:r}=T(),i=pa(e,t),[a,o]=(0,f.useState)(),s=i.page;return(0,h.jsxs)(`section`,{className:`scm-body`,children:[(0,h.jsx)(Ba,{pager:i}),(0,h.jsx)(`p`,{children:n(`Captured observations include pre-existing dirt. They do not attribute every change to Cadence; bounded fingerprints are not filesystem snapshots.`)}),(0,h.jsx)(`div`,{className:`scm-files-list`,children:s&&!(`kind`in s)&&s.records.map(e=>{if(e.kind!==`owner-fact`)return null;let t=e.fact,i=t.kind===`changes`||t.kind===`review`?t.content:t.kind===`check-settled`?t.output:null;return(0,h.jsxs)(`article`,{className:`scm-file`,children:[(0,h.jsxs)(`h3`,{children:[t.kind,` · `,n(`committed #{seq}`,{seq:e.committedSeq})]}),(0,h.jsx)(`pre`,{children:JSON.stringify(t,null,2)}),i&&(0,h.jsx)(`button`,{type:`button`,onClick:()=>{s.request.scope.kind!==`workspace`&&s.request.snapshotSeq!==null&&o(da(s.request.storeId,s.request.scope,s.request.snapshotSeq,i))},children:n(`Inspect full retained {field}`,{field:r(i.field)})})]},e.recordId)})}),a&&(0,h.jsx)(za,{client:e,cursor:a,render:e=>(0,h.jsx)(fc,{text:e})},`${a.recordId}:${a.recordVersion}`)]})}var mc=[`contents`,`checks`,`changes`,`reviews`];function hc({client:e,seed:t}){let{t:n,tx:r}=T(),[i,a]=(0,f.useState)(`contents`);return(0,h.jsxs)(`aside`,{className:`panel panel-right`,children:[(0,h.jsx)(`p`,{className:`inspector-note`,children:n(`History is readonly. Start new work in a conversation with /cadence.`)}),(0,h.jsx)(`nav`,{className:`rp-tabs`,"aria-label":n(`Inspector`),children:mc.map(e=>(0,h.jsx)(`button`,{type:`button`,className:`rp-tab`,"aria-pressed":i===e,onClick:()=>a(e),children:r(e)},e))}),(0,h.jsx)(`div`,{className:`inspector-body`,children:i===`contents`?(0,h.jsx)(Va,{client:e,seed:t}):(0,h.jsx)(pc,{client:e,seed:{...t,reader:i}},i)})]})}var gc={relative:`Enter a full path, for example ~/project.`,invalid:`This folder does not exist. Check the path.`,forbidden:`This location cannot be browsed: it belongs to another account, is protected, or is not a plain folder (for example a link).`,unavailable:`This folder could not be read right now; it may lack read permission. Try again.`},_c=e=>/^(?:~(?:[\\/]|$)|[\\/]|[A-Za-z]:[\\/])/.test(e);function vc(e,t){let n=e.startsWith(`/`)?`/`:`\\`,r=(e,t)=>e.endsWith(n)?e+t:e+n+t,i=!!t&&(e===t||e.startsWith(r(t,``))),a=i?t:/^(?:\\\\[^\\]+\\[^\\]+|[A-Za-z]:\\|\/)/.exec(e)?.[0]??``;if(!a)return{inside:i,trail:[{name:e,path:e}]};let o=i?[]:[{name:a===`/`?`/`:a.replace(/\\$/,``),path:a}],s=a;for(let t of e.slice(a.length).split(/[\\/]/).filter(Boolean))s=r(s,t),o.push({name:t,path:s});return{inside:i,trail:o}}function yc({client:e,current:t,initial:n,home:r,epoch:i,onClose:a,onOpen:o,projects:s=[],selectOnly:c=!1}){let{t:l,tx:u}=T(),[d,p]=(0,f.useState)(),[m,g]=(0,f.useState)(n??t),[_,v]=(0,f.useState)(!1),[y,b]=(0,f.useState)(``),[x,S]=(0,f.useState)(!0),[C,w]=(0,f.useState)(!0),[E,D]=(0,f.useState)(!1),[O,k]=(0,f.useState)(null),A=(0,f.useRef)(!0),j=(0,f.useRef)(void 0),ee=(0,f.useRef)(n??t),M=(0,f.useRef)(null),N=(0,f.useRef)(null),te=async t=>{j.current?.abort();let n=new AbortController;j.current=n,S(!0),k(null);let r=await e.workbenchRead({kind:`directories`,path:t},n.signal).catch(()=>void 0);if(!n.signal.aborted&&A.current){if(j.current=void 0,S(!1),r?.kind===`ok`&&r.value.kind===`directories`)return p(r.value),g(r.value.path),v(!1),b(``),r.value;k({step:`read`,code:r?.kind===`error`?r.error.code:`unavailable`})}},P=(0,f.useRef)(te);(0,f.useEffect)(()=>(A.current=!0,P.current(ee.current).then(()=>{A.current&&w(!1)}),()=>{A.current=!1,j.current?.abort()}),[]),(0,f.useEffect)(()=>{_&&M.current?.select()},[_]),(0,f.useEffect)(()=>{N.current&&(N.current.scrollLeft=N.current.scrollWidth)});let F=e=>{E||te(e)},I=()=>{let e=m.trim();E||(_c(e)?te(e):k({step:`read`,code:`relative`}))},L=(_||!d)&&m.trim()||d?.path||``,R=!E&&!x&&!!L,z=async n=>{if(E||!n||x&&n===d?.path)return;if(n!==d?.path&&!_c(n)){k({step:`read`,code:`relative`});return}D(!0),k(null);let r=n===d?.path?d.path:(await te(n))?.path;if(!A.current)return;if(!r){D(!1);return}if(!o&&r===t){a();return}if(o){try{await o(r),A.current&&a()}catch(e){A.current&&(k({step:`open`,code:e instanceof Error?e.message:`unavailable`}),D(!1))}return}if(!e.workbenchCommand){k({step:`open`,code:`unavailable`}),D(!1);return}let s=await e.workbenchCommand({kind:`open-project`,commandId:crypto.randomUUID(),path:r,epoch:i});if(A.current){if(s.kind===`ok`&&s.value.kind===`project`){let e=new URL(s.value.link);e.protocol===`http:`&&[`127.0.0.1`,`[::1]`].includes(e.hostname)||e.protocol===`https:`?window.location.assign(e.href):(k({step:`open`,code:`unsupported-context`}),D(!1))}else k({step:`open`,code:s.kind===`error`?s.error.code:`unavailable`}),D(!1)}},B=d?vc(d.path,r):void 0,V=y.trim().toLowerCase(),H=d?.entries.filter(e=>e.name.toLowerCase().includes(V))??[],U=O&&(O.step===`read`&&gc[O.code]?l(gc[O.code]):u(O.code));return(0,h.jsxs)(Ga,{title:l(c?`Choose working folder`:`Open working folder`),onClose:a,children:[(0,h.jsx)(`p`,{children:l(c?`Selecting a folder does not start execution. Send prepares it when needed.`:`Choose a folder on the service host. Opening reuses or starts that project's independent service; current work keeps running.`)}),s.length>0&&(0,h.jsxs)(`section`,{className:`cwd-recent`,"aria-label":l(`Recent projects`),children:[(0,h.jsx)(`h3`,{children:l(`Recent projects`)}),(0,h.jsx)(`div`,{className:`cwd-recent-list`,children:s.map(e=>(0,h.jsxs)(`button`,{type:`button`,title:l(`Open {path}`,{path:e.path}),"aria-current":e.current?`true`:void 0,disabled:E,onClick:()=>e.current?a():void z(e.path),children:[(0,h.jsx)(oi,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{children:e.path})]},e.path))})]}),(0,h.jsxs)(`div`,{className:`cwd-location`,children:[B&&!_?(0,h.jsxs)(`nav`,{ref:N,className:`cwd-crumbs`,"aria-label":l(`Current location`),children:[(0,h.jsxs)(`button`,{type:`button`,"aria-label":l(`Home folder`),title:l(`Home folder (~)`),"aria-current":r&&d?.path===r?`location`:void 0,disabled:E,onClick:()=>F(`~`),children:[(0,h.jsx)(ri,{"aria-hidden":`true`}),B.inside&&(0,h.jsx)(`span`,{"aria-hidden":`true`,children:`~`})]}),B.trail.map((e,t)=>(0,h.jsxs)(f.Fragment,{children:[(t>0||B.inside)&&(0,h.jsx)(gi,{"aria-hidden":`true`,className:`cwd-crumb-sep`}),(0,h.jsx)(`button`,{type:`button`,"aria-current":e.path===d?.path?`location`:void 0,disabled:E,onClick:()=>F(e.path),children:e.name})]},e.path))]}):C?(0,h.jsx)(`div`,{className:`cwd-crumbs`}):(0,h.jsx)(`form`,{className:`cwd-input`,onSubmit:e=>{e.preventDefault(),I()},children:(0,h.jsx)(`input`,{ref:M,"aria-label":l(`Folder path`),placeholder:l(`Type or paste a path, then press Enter`),value:m,disabled:E,spellCheck:!1,autoComplete:`off`,enterKeyHint:`go`,onChange:e=>{g(e.target.value),O?.step===`read`&&k(null)},onKeyDown:e=>{e.key===`Escape`&&d&&(e.preventDefault(),v(!1),g(d.path),k(null))}})}),d&&(0,h.jsx)(`button`,{type:`button`,className:`ghost`,"aria-label":l(`Edit path`),title:l(`Edit path`),"aria-pressed":_,disabled:E,onClick:()=>{g(d.path),v(!_),k(null)},children:(0,h.jsx)(li,{"aria-hidden":`true`})})]}),d&&(0,h.jsxs)(`label`,{className:`cwd-filter`,children:[(0,h.jsx)(qr,{"aria-hidden":`true`}),(0,h.jsx)(`input`,{"aria-label":l(`Filter folders`),placeholder:l(`Filter this folder…`),value:y,disabled:E,spellCheck:!1,autoComplete:`off`,onChange:e=>b(e.target.value)})]}),(0,h.jsxs)(`div`,{className:`cwd-picker-list`,"aria-busy":x||void 0,children:[x&&(0,h.jsx)(`p`,{role:`status`,className:`cwd-picker-note`,children:l(`Reading folder…`)}),d?.parent&&(0,h.jsxs)(`button`,{type:`button`,disabled:E,onClick:()=>F(d.parent),children:[(0,h.jsx)(yi,{}),l(`Parent folder`)]}),H.map(e=>(0,h.jsxs)(`button`,{type:`button`,disabled:E,onClick:()=>F(e.path),children:[(0,h.jsx)(oi,{}),(0,h.jsx)(`span`,{children:e.name})]},e.path)),d&&!x&&H.length===0&&(0,h.jsx)(`p`,{className:`cwd-picker-note`,children:l(V?`No matching folders.`:`No subfolders.`)})]}),d?.limited&&(0,h.jsx)(`p`,{className:`inspector-note`,children:l(`Bounded listing; narrow the directory to see more.`)}),U&&(0,h.jsxs)(`p`,{role:`alert`,children:[U,O?.code===`registry-locked`&&(0,h.jsxs)(h.Fragment,{children:[` `,`—`,` `,l(`Another Cadence process is updating the project registry. Try again in a moment; if this persists, run cadence doctor on the service host.`)]})]}),(0,h.jsxs)(`footer`,{className:`cwd-footer`,children:[L&&(0,h.jsxs)(`p`,{className:`cwd-target`,children:[(0,h.jsx)(`span`,{children:l(`Will open:`)}),` `,(0,h.jsx)(`code`,{children:L})]}),(0,h.jsx)(`button`,{type:`button`,className:`primary`,disabled:!R,onClick:()=>void z(L),children:l(E?c?`Selecting folder…`:`Opening folder…`:c?`Use this folder`:`Open this folder`)})]})]})}function bc(e,t=new Set){let n=new Map(e.map(e=>[e.id,e])),r=new Map,i=[];for(let t of e)if(t.parentId&&n.has(t.parentId)){let e=r.get(t.parentId)??[];e.push(t),r.set(t.parentId,e)}else i.push(t);let a=e=>{let t=[],n=[...r.get(e)??[]],i=new Set;for(;n.length>0;){let e=n.shift();if(!e)break;if(i.has(e.id))continue;i.add(e.id),t.push(e);let a=r.get(e.id);a&&n.push(...a)}return t},o=[],s=new Set,c=new Set,l=(e,n)=>{if(s.has(e.id)||c.has(e.id))return;s.add(e.id);let i=r.get(e.id)??[],u=i.length>0,d=u&&t.has(e.id),f=0,p=!1,m=!1,h=!1;if(u){let t=a(e.id);if(f=t.length,p=t.some(e=>e.active),m=t.some(e=>e.failed),h=t.some(e=>e.unknown),d)for(let e of t)c.add(e.id)}if(o.push({c:e,depth:n,hasKids:u,isCollapsed:d,descendantCount:f,hasActive:p,hasFailure:m,hasUnknown:h}),!d)for(let e of i)l(e,n+1)};for(let e of i)l(e,0);for(let t of e)l(t,0);return o}function xc({onConversation:e,disabled:t=!1}){let{t:n}=T();return(0,h.jsx)(`div`,{className:`lp-new`,children:(0,h.jsxs)(`button`,{type:`button`,className:`new-conversation`,disabled:t||!e,onClick:e,children:[(0,h.jsx)(Yr,{"aria-hidden":`true`}),n(`New conversation`)]})})}function Sc({title:e,children:t,className:n=``,count:r}){let[i,a]=(0,f.useState)(!0);return(0,h.jsxs)(`section`,{className:`lp-section ${n}${i?``:` collapsed`}`,children:[(0,h.jsx)(`header`,{className:`lp-section-header`,children:(0,h.jsxs)(`button`,{type:`button`,className:`lp-section-heading`,"aria-expanded":i,onClick:()=>a(e=>!e),children:[i?(0,h.jsx)(_i,{"aria-hidden":`true`}):(0,h.jsx)(gi,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{className:`lp-section-title`,children:e}),r&&(0,h.jsx)(`span`,{className:`lp-count`,children:r})]})}),(0,h.jsx)(`div`,{className:`lp-section-body`,hidden:!i,children:t})]})}function Cc({runs:e,scope:t,snapshot:n,onScope:r}){let{t:i,tx:a}=T(),[o,s]=(0,f.useState)(new Set),c=bc(e.map(e=>({id:e.childRunId??e.runId,parentId:e.childRunId?e.runId:null,label:e.childRunId?e.assignmentId??i(`Subagent`):a(e.admission.kind),active:e.lifecycle!==`settled`,failed:e.outcome===`failed`,unknown:e.outcome===`unknown`})),o);return(0,h.jsx)(`nav`,{className:`conversation-tree`,"aria-label":i(`Runs and assignments`),children:c.map(o=>{let c=e.find(e=>(e.childRunId??e.runId)===o.c.id),l=c?.childRunId?`child`:`run`,u=c?.outcome??c?.lifecycle??`unknown`,d=t?.kind===l&&t.id===o.c.id;return(0,h.jsxs)(`div`,{className:`ep-row`,style:{paddingInlineStart:`${o.depth*14}px`},children:[o.hasKids?(0,h.jsx)(`button`,{type:`button`,className:`ep-toggle`,"aria-label":i(`Toggle assignments`),"aria-expanded":!o.isCollapsed,onClick:()=>s(e=>{let t=new Set(e);return t.has(o.c.id)?t.delete(o.c.id):t.add(o.c.id),t}),children:o.isCollapsed?(0,h.jsx)(gi,{"aria-hidden":`true`}):(0,h.jsx)(_i,{"aria-hidden":`true`})}):(0,h.jsx)(`span`,{className:`ep-toggle-spacer`,"aria-hidden":`true`}),(0,h.jsxs)(`button`,{type:`button`,className:`session-item${d?` active`:``}`,"aria-current":d?`true`:void 0,title:`${o.c.label} · ${o.c.id}`,onClick:()=>r({kind:l,id:o.c.id},n,o.c.label),children:[(0,h.jsx)(`span`,{className:`session-icon`,children:l===`child`?(0,h.jsx)(di,{"aria-hidden":`true`}):(0,h.jsx)(Zr,{"aria-hidden":`true`})}),(0,h.jsxs)(`span`,{className:`session-info`,children:[(0,h.jsx)(`span`,{className:`session-title`,children:o.c.label}),l===`child`&&(0,h.jsx)(`span`,{className:`session-sub`,children:i(`Subagent`)}),o.isCollapsed&&(0,h.jsx)(`span`,{className:`session-sub session-outcome`,children:`${i(`{count} descendants`,{count:o.descendantCount})}${o.hasFailure?i(` / failed child`):``}${o.hasUnknown?i(` / unknown child`):``}`})]}),(0,h.jsx)(`span`,{className:`ep-state ${u}`,children:a(u)})]})]},o.c.id)})})}function wc({pager:e,scope:t,onScope:n,exclude:r}){let{t:i}=T(),a=e.page;return(0,h.jsxs)(`div`,{className:`retained-conversations`,children:[a&&!(`kind`in a)&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(Cc,{runs:a.records.flatMap(e=>e.kind===`run`&&!r.includes(e.projection.runId)?[e.projection]:[]),scope:t,snapshot:a.request.snapshotSeq??void 0,onScope:n}),a.records.length===0&&(0,h.jsx)(`p`,{className:`panel-hint`,children:i(`No retained conversations on this page.`)})]}),(0,h.jsx)(Ba,{pager:e,compact:!0})]})}function Tc({client:e,workspace:t,executionStopped:n=!1,taskId:r,scope:i,runs:a,snapshot:o,activeRuns:s,cancelCompatible:c,canceling:l,onCancel:u,onTask:d,onScope:p,chats:m=[],chatActivityKnown:g=!0,chatHistoryPartial:_=!1,chatHistoryControls:v,conversationId:y,onConversation:b,onNewConversation:x,workflows:S,workflowLinks:C=[],workflowError:w=!1,discovery:E,selectedWorkflow:D,onWorkflow:O,onCancelWorkflow:k}){let{t:A,tx:j}=T(),ee=t?{reader:`tasks`,storeId:t.storeId,scope:{kind:`workspace`,id:t.workspaceId},snapshotSeq:null,after:null,limit:50}:null,M=pa(e,ee),N=pa(e,r&&ee&&t?{...ee,reader:`runs`,scope:{kind:`task`,id:r},snapshotSeq:o??t.committedSeq}:null),te=M.page&&!(`kind`in M.page)?M.page.records.flatMap(e=>e.kind===`task`?[e]:[]):[],P=s?.status===`complete`?s.runs:[],F=te.filter(e=>!P.some(t=>t.taskId===e.owner.taskId)),I=r&&(0,h.jsxs)(`section`,{className:`task-conversations`,"aria-label":A(`Task conversations`),children:[(0,h.jsx)(`h3`,{children:A(`Task conversations`)}),(0,h.jsx)(wc,{pager:N,scope:i,onScope:p,exclude:P.map(e=>e.runId)},r)]}),[L,R]=(0,f.useState)(()=>new Set),z=e=>{let t=C.find(t=>t.runId===e.id)?.conversationId??null;return(0,h.jsxs)(`div`,{className:`conversation-group`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`session-item${D===e.id||t&&t===y?` active`:``}`,onClick:()=>O?.(e,t),title:e.goal,children:[(0,h.jsx)(`span`,{className:`status-dot busy`,"aria-hidden":`true`}),(0,h.jsxs)(`span`,{className:`session-info`,children:[(0,h.jsx)(`span`,{className:`session-title`,children:e.goal}),(0,h.jsxs)(`span`,{className:`session-sub`,children:[A(`Cadence workflow`),` · `,j(e.phase),` · `,j(e.status)]})]})]}),k&&(0,h.jsxs)(`button`,{type:`button`,className:`conversation-stop`,disabled:L.has(e.id),onClick:()=>{R(t=>new Set(t).add(e.id)),k(e).finally(()=>R(t=>{let n=new Set(t);return n.delete(e.id),n}))},children:[(0,h.jsx)(Wr,{"aria-hidden":`true`}),A(`Cancel workflow — request stop`)]})]},e.id)},B=m.filter(e=>e.status===`running`||e.status===`queued`),V=m.filter(e=>!B.includes(e)),H=e=>S?.findLast(t=>C.some(n=>n.runId===t.id&&n.conversationId===e.id)),U=e=>{let t=[`running`,`queued`,`completed`].includes(e.status)?H(e):void 0;return(0,h.jsxs)(`button`,{type:`button`,className:`session-item${e.id===y?` active`:``}`,onClick:()=>b?.(e.id),title:e.title,children:[(0,h.jsx)(`span`,{className:`session-icon`,children:(0,h.jsx)(Zr,{})}),(0,h.jsxs)(`span`,{className:`session-info`,children:[(0,h.jsx)(`span`,{className:`session-title`,children:e.title}),(0,h.jsxs)(`span`,{className:`session-sub`,children:[e.origin===`terminal`?A(`Terminal`):`WebUI`,` ·`,` `,e.cadence?A(`Cadence on`):A(`Ordinary`),` ·`,` `,t?j(Ks(t)):e.cadence&&[`running`,`queued`].includes(e.status)?A(`Discussing`):e.cadence&&e.status===`completed`?A(`Ready for conversation`):j(e.status)]})]})]},e.id)};return(0,h.jsxs)(`aside`,{className:`panel panel-left lp-panel`,children:[E&&(0,h.jsx)(ho,{...E,represented:!n&&E.project?[...(S??[]).map(e=>mo(E.project,`workflow`,e.id,e.epoch)),...B.flatMap(e=>e.live?[mo(E.project,`turn`,e.live.commandId,e.live.epoch)]:[])]:[]}),(0,h.jsx)(xc,{onConversation:x}),!n&&(0,h.jsxs)(Sc,{title:A(`Running work`),count:s?.status===`complete`&&S&&!w&&g?String(P.length+B.length+S.length):A(`Not observed`),className:`running-conversations`,children:[s?.status!==`complete`&&(0,h.jsx)(`p`,{className:`panel-hint`,children:A(`Active roster unavailable; absence is not proof of settlement.`)}),w&&(0,h.jsx)(`p`,{className:`panel-hint`,children:A(`Workflow activity unavailable; retained work may still be running.`)}),!g&&(0,h.jsx)(`p`,{className:`panel-hint`,children:A(`Conversation activity unavailable.`)}),B.map(U),S?.map(z),s?.status===`complete`&&P.length===0&&B.length===0&&S?.length===0&&!w&&g&&(0,h.jsx)(`p`,{className:`panel-hint`,children:A(`No active runs`)}),P.map(e=>{let t=te.find(t=>t.owner.taskId===e.taskId)?.goal;return(0,h.jsxs)(`div`,{className:`conversation-group`,children:[(0,h.jsxs)(`button`,{type:`button`,className:`session-item${r===e.taskId&&i?.kind===`task`?` active`:``}`,onClick:()=>d(e.taskId,t),title:e.runId,children:[(0,h.jsx)(`span`,{className:`status-dot busy`,"aria-hidden":`true`}),(0,h.jsxs)(`span`,{className:`session-info`,children:[(0,h.jsx)(`span`,{className:`session-title`,children:t??A(`Task {id}`,{id:e.taskId.slice(0,8)})}),(0,h.jsxs)(`span`,{className:`session-sub`,children:[j(e.kind),` · `,j(e.stage)]})]})]}),(0,h.jsxs)(`button`,{type:`button`,className:`conversation-stop`,disabled:!c||l.has(e.runId),onClick:()=>u(e.runId),children:[(0,h.jsx)(Wr,{"aria-hidden":`true`}),A(`Cancel run — request stop`)]}),r===e.taskId&&(0,h.jsx)(Cc,{runs:a.filter(t=>t.runId===e.runId),scope:i,onScope:p})]},e.runId)})]}),(0,h.jsxs)(Sc,{title:A(`Conversation history`),count:t?M.page&&!(`kind`in M.page)?`${V.length+F.length}${M.page.next||M.canPrevious||_?`+`:``}`:A(`Not observed`):`${V.length}${_?`+`:``}`,className:`grow`,children:[(0,h.jsxs)(`nav`,{"aria-label":A(`Tasks`),className:`task-list`,children:[V.map(U),F.map(e=>(0,h.jsxs)(`div`,{children:[(0,h.jsxs)(`button`,{type:`button`,className:`session-item${e.owner.taskId===r&&i?.kind===`task`?` active`:``}`,"aria-current":e.owner.taskId===r&&i?.kind===`task`?`true`:void 0,title:e.goal,onClick:()=>d(e.owner.taskId,e.goal),children:[(0,h.jsx)(`span`,{className:`session-icon`,children:(0,h.jsx)(Zr,{"aria-hidden":`true`})}),(0,h.jsxs)(`span`,{className:`session-info`,children:[(0,h.jsx)(`span`,{className:`session-title`,children:e.goal}),(0,h.jsx)(`span`,{className:`session-sub`,children:A(`Task {id}`,{id:e.owner.taskId.slice(0,8)})})]})]}),e.owner.taskId===r&&I]},e.owner.taskId)),M.page&&!(`kind`in M.page)&&F.length===0&&V.length===0&&!_&&(0,h.jsx)(`p`,{className:`panel-hint`,children:A(`No conversations yet.`)}),v,t&&(0,h.jsx)(Ba,{pager:M,compact:!0})]}),!F.some(e=>e.owner.taskId===r)&&I]})]})}var Ec=[`queued`,`running`];function Dc({client:e,agent:t,backLabel:n,onBack:r,onOpenAgent:i}){let{t:a,tx:o}=T(),[s,c]=(0,f.useState)(1e3),l=Ki(e,{kind:`workflow`,id:t.runId},s),u=l.value?.kind===`workflow`&&l.value.response.type===`run`?l.value.response.run:null,d=t.stepId?u?.steps.find(e=>e.id===t.stepId):void 0,p=d?Ec.includes(d.status):!1;(0,f.useEffect)(()=>{u&&!Ec.includes(u.status)&&c(0)},[u]);let m=Ki(e,t.stepId&&(!u||d?.childRunId)?{kind:`workflow-transcript`,id:t.runId,stepId:t.stepId}:null,p||!u?1e3:0),g=m.value?.kind===`workflow-transcript`?m.value.turn:null,_=(0,f.useMemo)(()=>g?As(g):null,[g]),[v,y]=(0,f.useState)(!1),b=Ki(e,v&&t.stepId?{kind:`workflow-detail`,id:t.runId,stepId:t.stepId}:null),x=(0,f.useRef)(null),S=(0,f.useRef)(!0),C=_?.steps.length??0;return(0,f.useEffect)(()=>{C&&S.current&&x.current&&(x.current.scrollTop=x.current.scrollHeight)},[C]),(0,h.jsxs)(`section`,{className:`chat-workspace workflow-agent`,"aria-label":a(`Subagent context`),children:[(0,h.jsxs)(`header`,{className:`conversation-header`,children:[(0,h.jsxs)(`div`,{className:`conversation-heading`,children:[(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:r,children:n}),(0,h.jsx)(di,{"aria-hidden":`true`}),(0,h.jsx)(`h2`,{title:t.stepId??t.runId,children:d?`${o(d.kind)} · ${t.label}`:t.label}),(0,h.jsx)(`span`,{className:`conversation-badge`,children:t.stepId?a(`Subagent`):a(`Workflow`)})]}),(d??u)&&(0,h.jsx)(`span`,{className:`ep-state ${(d??u)?.status}`,children:o((d??u)?.status??``)})]}),(0,h.jsxs)(`div`,{className:`chat-messages`,ref:x,onScroll:e=>{let t=e.currentTarget;S.current=t.scrollHeight-t.scrollTop-t.clientHeight<80},children:[l.error&&(0,h.jsxs)(`p`,{role:`alert`,className:`banner-notice`,children:[l.error,` ·`,` `,a(`State unavailable is not completion. No automatic resubmission.`)]}),u&&t.stepId&&(0,h.jsxs)(`p`,{className:`inspector-note workflow-agent-goal`,children:[a(`Workflow`),`: `,u.goal,` · `,o(u.phase),` · `,o(u.status)]}),!t.stepId&&(0,h.jsx)($s,{client:e,id:t.runId,onOpenAgent:i}),t.stepId&&m.error&&(0,h.jsx)(`p`,{role:`alert`,children:m.error}),t.stepId&&(_?(0,h.jsx)(Vs,{turn:_}):(0,h.jsx)(`p`,{className:`inspector-note`,children:a(`No retained transcript observed yet; absence is not proof of no activity.`)})),d&&(0,h.jsxs)(`section`,{className:`workflow-agent-result`,"aria-label":a(`Step result`),children:[(0,h.jsx)(`h3`,{children:a(`Step result`)}),d.exitCode!==null&&(0,h.jsxs)(`p`,{children:[a(`Exit code`),`: `,d.exitCode]}),d.text?(0,h.jsx)(ka,{text:d.text}):(0,h.jsx)(`p`,{className:`inspector-note`,children:a(`No result yet.`)}),d.truncated&&(0,h.jsx)(`p`,{children:a(`Preview is truncated.`)}),(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>y(!0),children:a(`Read retained step result`)}),v&&b.value?.kind===`file`&&(0,h.jsx)(`pre`,{className:`workflow-detail`,children:b.value.text}),v&&b.error&&(0,h.jsx)(`p`,{role:`alert`,children:b.error})]})]})]})}function Oc({path:e,disabled:t=!1,onClick:n}){let{t:r}=T();return(0,h.jsxs)(`button`,{type:`button`,className:`status-cwd`,title:e||r(`Open working folder`),"aria-label":r(`Switch working folder`),disabled:t,onClick:n,children:[(0,h.jsx)(oi,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{children:e||r(`Open working folder`)}),(0,h.jsx)(_i,{"aria-hidden":`true`})]})}function kc({error:e,observationError:t,projectObservationError:n,unavailable:r=!1,onRefresh:i}){let{t:a}=T(),o=r||t||n;return!e&&!o?null:(0,h.jsxs)(h.Fragment,{children:[e&&(0,h.jsx)(`p`,{className:`banner-notice`,role:`alert`,children:e}),o&&(0,h.jsxs)(`section`,{className:`workspace-notice`,"aria-label":a(`Observation status`),children:[(0,h.jsxs)(`div`,{className:`workspace-notice-summary`,children:[(0,h.jsxs)(`p`,{role:`status`,children:[(0,h.jsx)(`strong`,{children:a(`Latest state unavailable.`)}),` `,a(`Started work may still be running. No message is resent.`)]}),i&&(0,h.jsx)(`button`,{type:`button`,onClick:i,children:a(`Observe current state`)})]}),(t||n)&&(0,h.jsxs)(`details`,{children:[(0,h.jsx)(`summary`,{children:a(`Diagnostic details`)}),n&&(0,h.jsx)(`p`,{children:a(`Project observation: {code}.`,{code:n})}),t&&(0,h.jsx)(`p`,{children:a(`Viewer observation: {code}.`,{code:t})}),(t===`stale`||n===`stale`)&&(0,h.jsx)(`p`,{children:a(`Context changed. Read the current state before confirming a plan.`)})]})]})]})}function Ac(e,t,n){let r=new URL(window.location.origin+window.location.pathname),i=Vi();i&&r.searchParams.set(`project`,i);let a=new URLSearchParams({task:V(e)});if(n&&(a.set(`scope`,JSON.stringify(Y(n.scope))),n.snapshotSeq&&a.set(`snapshot`,U(n.snapshotSeq))),t){let{navigation:e,...n}=t;a.set(`detail`,JSON.stringify(n))}return r.hash=a.toString(),r.href}function jc(){try{let e=new URLSearchParams(window.location.hash.slice(1)),t=V(e.get(`task`)),n=e.get(`detail`),r=e.get(`scope`),i=e.get(`snapshot`),a=r?Y(ie(r)):void 0,o=i?U(i):void 0;if(a?.kind===`task`&&a.id!==t||o&&!a)return null;if(!n)return{taskId:t,scope:a,snapshotSeq:o};let s=Ae(ie(n));return s.navigation?null:{taskId:t,cursor:s,scope:a,snapshotSeq:o}}catch{return null}}var Mc=`cadence-panel-layout-v1`,Nc={left:260,right:360,navigation:!0,inspector:!1};function Pc(e,t=600){return Math.max(220,Math.min(t,e))}function Fc(e){let t={...Nc};try{let n=JSON.parse(e??`null`);if(!n||typeof n!=`object`||Array.isArray(n))return t;for(let e of[`left`,`right`]){let r=n[e];typeof r==`number`&&Number.isFinite(r)&&(t[e]=Pc(r))}for(let e of[`navigation`,`inspector`]){let r=n[e];typeof r==`boolean`&&(t[e]=r)}}catch{}return t}function Ic(e,t){let n=e<=900,r=Pc(t.left,e-560),i=Pc(t.right),a=t.navigation?r:0,o=!n&&e-a-i<560,s=t.inspector&&!o?i:0;return{mobile:n,left:r,right:i,rightOverlay:o,leftMaximum:Pc(e-560-s),rightMaximum:Pc(e-560-a)}}function Lc({side:e,width:t,onResize:n,maximum:r}){let{t:i}=T(),a=(0,f.useRef)(void 0);return(0,f.useEffect)(()=>()=>a.current?.(),[]),(0,h.jsx)(`input`,{type:`range`,min:220,max:r,step:1,value:t,onChange:e=>n(Pc(Number(e.target.value),r)),className:`resize-handle`,tabIndex:0,"aria-orientation":`horizontal`,"aria-label":i(e===`left`?`Resize left pane`:`Resize right pane`),"aria-valuemin":220,"aria-valuemax":r,"aria-valuenow":t,onDoubleClick:()=>n(Pc(e===`left`?260:360,r)),onPointerDown:i=>{i.preventDefault(),a.current?.();let o=i.clientX,s=i=>{n(Pc(t+(i.clientX-o)*(e===`left`?1:-1),r))},c=()=>{window.removeEventListener(`pointermove`,s),window.removeEventListener(`pointerup`,c),window.removeEventListener(`pointercancel`,c),a.current=void 0};a.current=c,window.addEventListener(`pointermove`,s),window.addEventListener(`pointerup`,c,{once:!0}),window.addEventListener(`pointercancel`,c,{once:!0})}})}function Rc(e,t,n,r){(0,f.useEffect)(()=>{if(!n||!t)return;let i=e.current?.querySelector(`.drawer-${t}`),a=document.activeElement,o=()=>Array.from(i?.querySelectorAll(`button:not(:disabled),input,textarea,select,a[href],[tabindex="0"]`)??[]).filter(e=>e.getClientRects().length>0);(o()[0]??i)?.focus({preventScroll:!0});let s=e=>{if(e.key===`Escape`&&(e.preventDefault(),r()),e.key===`Tab`){let t=o(),n=t[0],r=t[t.length-1];if(!n){e.preventDefault();return}e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus({preventScroll:!0})):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus({preventScroll:!0}))}};return i?.addEventListener(`keydown`,s),()=>{i?.removeEventListener(`keydown`,s),a instanceof HTMLElement&&a.isConnected&&a.focus({preventScroll:!0})}},[e,t,n,r])}function zc(){let[e,t]=(0,f.useState)(()=>{try{return Fc(localStorage.getItem(Mc))}catch{return Fc(null)}}),[n,r]=(0,f.useState)(()=>typeof window>`u`?1440:window.innerWidth??1440),[i,a]=(0,f.useState)(null);(0,f.useEffect)(()=>{let e=()=>r(window.innerWidth);return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[]);let o=Ic(n,e),s=(0,f.useCallback)(n=>{let r={...e,...n};t(r);try{localStorage.setItem(Mc,JSON.stringify(r))}catch{}},[e]),c=o.mobile?i:o.rightOverlay&&e.inspector?`right`:null,l=(0,f.useCallback)(()=>{a(null),!o.mobile&&o.rightOverlay&&s({inspector:!1})},[o.mobile,o.rightOverlay,s]);return{...o,overlay:c,closeDrawer:l,setDrawer:a,navigation:e.navigation,inspector:e.inspector,className:`${e.navigation?``:` navigation-hidden`}${e.inspector?``:` inspector-hidden`}${o.rightOverlay?` inspector-overlay`:``}`,toggle(t){o.mobile?a(e=>e===t?null:t):s(t===`left`?{navigation:!e.navigation}:{inspector:!e.inspector})},resize(e,t){s({[e]:t})}}}var Bc=.4,Vc=1.05;function Hc(e){return Math.min(300,e*.86)}function Uc(e,t,n){return n||(t<=144?null:e<=72?`left`:t-e<=72?`right`:null)}function Wc(e,t){let n=Math.abs(e),r=Math.abs(t);return n<12&&r<12?`none`:n>r*1.2?`horizontal`:`vertical`}function Gc(e,t){return e===`left`?t:-t}function Kc(e,t){return Math.max(-e,Math.min(0,-e+t))}function qc(e,t,n){let r=n?e+t:t;return Math.max(0,Math.min(1,r/e))}function Jc(e){let{wasOpen:t,pull:n,width:r,durationMs:i}=e;return i<=320&&Math.abs(n)>=48?n>0:qc(r*Vc,n,t)>=Bc}var Yc=new Set([`auto`,`scroll`,`overlay`]);function Xc(e,t){let n=e instanceof Element?e:null;for(;n;){if(n instanceof HTMLElement&&n.scrollWidth>n.clientWidth+4&&Yc.has(getComputedStyle(n).overflowX))return!0;if(n===t)break;n=n.parentElement}return!1}function Zc(){let e=e=>{e.stopPropagation(),e.preventDefault()};window.addEventListener(`click`,e,{capture:!0,once:!0}),setTimeout(()=>window.removeEventListener(`click`,e,{capture:!0}),400)}function Qc(e){let{enabled:t,open:n,onOpenChange:r,container:i}=e,{panelSelector:a,backdropSelector:o}=e;(0,f.useEffect)(()=>{let e=i.current;if(!t||!e)return;let s=null,c=`none`,l=0,u=0,d=0,f=0,p=!1,m=0,h=0,g=null,_=null,v=()=>{g&&(g.classList.remove(`drawer-dragging`),g.style.transform=``),_&&(_.style.opacity=``),s=null,c=`none`,g=null,_=null,f=0,p=!1},y=t=>{if(v(),t.touches.length!==1)return;let r=t.touches[0];if(!r)return;let i=Uc(r.clientX,window.innerWidth,n);i&&!Xc(t.target,e)&&(s=i,l=r.clientX,u=r.clientY,d=Date.now())},b=t=>{let r=s;if(!r||t.touches.length!==1)return;let i=t.touches[0];if(!i)return;let d=i.clientX-l,v=i.clientY-u;if(c===`none`){let t=Wc(d,v);if(t===`none`)return;if(t===`vertical`){s=null;return}c=`horizontal`,p=n===r,m=Hc(window.innerWidth),h=m*Vc;let i=e.querySelector(a?a(r):`.panel-drawer.drawer-${r}`);if(!i){s=null;return}g=i,_=o===null?null:e.querySelector(o??`.drawer-backdrop`),i.classList.add(`drawer-dragging`)}let y=g;if(!y)return;f=Gc(r,d);let b=Kc(h,p?h+f:f);y.style.transform=`translateX(${r===`left`?b:-b}px)`,_&&(_.style.opacity=String(qc(h,f,p))),t.preventDefault()},x=()=>{let e=s,t=c===`horizontal`&&e!==null&&g!==null,i=f,a=Date.now()-d,o=t?Jc({wasOpen:p,pull:i,width:m,durationMs:a}):!1;v(),t&&e&&o!==(n===e)&&(Zc(),r(o?e:null))},S=()=>v();return e.addEventListener(`touchstart`,y,{passive:!0}),e.addEventListener(`touchmove`,b,{passive:!1}),e.addEventListener(`touchend`,x),e.addEventListener(`touchcancel`,S),()=>{v(),e.removeEventListener(`touchstart`,y),e.removeEventListener(`touchmove`,b),e.removeEventListener(`touchend`,x),e.removeEventListener(`touchcancel`,S)}},[t,n,r,i,a,o])}function $c(e,t,n,r,i=`en`){let a=(e,t)=>v(i,e,t),o=t.filter(e=>e.kind===`owner-fact`||e.kind===`capture-fact`),s=o.map((e,t)=>{let n=e.kind===`owner-fact`?e.fact.kind:e.capture.event.kind,r=e.kind===`capture-fact`?e.link.childRunId:null,o=n.startsWith(`tool`)?`tools`:n.startsWith(`message`)?`model`:`input`;return{key:e.recordId,lane:o,group:`${r??`owner`}:${o}`,groupLabel:`${r??a(`Owner`)} · ${v(i,o)}`,kind:o===`tools`?`tool`:o===`model`?`text`:`system`,title:`#${e.committedSeq} ${n}`,summary:n,source:a(`Committed #{seq}; {who}`,{seq:e.committedSeq,who:r??a(`owner`)}),status:a(`recorded fact`),clock:e.kind===`capture-fact`?a(`Worker-local monotonic observations ({child}): {first}–{last} ms; not aligned to other workers.`,{child:e.link.childRunId,first:e.capture.source.firstObservedMs,last:e.capture.source.lastObservedMs}):a(`Owner observation ({epoch}): {ms} ms; clock origin not established by this reader.`,{epoch:e.link.epoch,ms:e.observedMs}),...e.kind===`owner-fact`&&e.fact.kind===`check-settled`?{dur:e.fact.native.durationMs}:{},t:t*1e3,end:t*1e3}}),c;return{lang:i,onData(e){return c=e,()=>{c=void 0}},readState(){c?.({kind:`state`,conversations:[{id:e,title:a(`{scope} — loaded committed page`,{scope:e}),isStreaming:!1,segCount:s.length}],activeId:e})},readSegments(t){t===e&&c?.({kind:`segs`,convId:t,segs:s,reset:!0})},readSegment(t,n){let r=s.findIndex(e=>e.key===n);t!==e||r<0||c?.({kind:`seg_detail`,convId:t,key:n,seg:s[r],detail:JSON.stringify(o[r],null,2),analysis:{position:a(`Committed sequence {seq}; page ordinal {ordinal}. Timing shown in raw facts only; clocks may not be comparable.`,{seq:o[r].committedSeq,ordinal:r+1})}})},openDetail(t,r){let i=o.find(e=>e.recordId===r);t===e&&i&&n(i)},searchHistory:r}}var el=`modulepreload`,tl=function(e){return`/`+e},nl={},rl=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=tl(t,n),t=s(t),t in nl)return;nl[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:el,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})};function il({client:e,seed:t,onSearch:n}){let{t:r}=T(),i=pa(e,{...t,reader:`events`}),a=i.page;return(0,h.jsxs)(`section`,{className:`timeline-view`,children:[(0,h.jsx)(`p`,{children:r(`Committed order, not wall time. Replay advances visualization only. Raw observations retain clock/sequence provenance; unknown timing is not reconstructed.`)}),(0,h.jsx)(Ba,{pager:i}),a&&!(`kind`in a)&&(0,h.jsx)(al,{client:e,seed:a.request,records:a.records,onSearch:n},`${a.request.snapshotSeq}:${a.request.after?.recordId??`first`}`)]})}function al({client:e,seed:t,records:n,onSearch:r}){let{t:i,locale:a}=T(),o=(0,f.useRef)(null),[s,c]=(0,f.useState)(!1),[l,u]=(0,f.useState)(!1),d=(0,f.useRef)(r);return d.current=r,(0,f.useEffect)(()=>{let e=!1,r;return rl(()=>import(`./timeline-client.js`).then(i=>{!e&&o.current&&(r=i.default.mount(o.current,$c(t.scope.id,n,()=>c(!0),()=>d.current(),a)))}),[]).catch(()=>{e||u(!0)}),()=>{e=!0,r?.()}},[n,t.scope.id,a]),(0,h.jsxs)(h.Fragment,{children:[l&&(0,h.jsx)(`p`,{role:`alert`,children:i(`Bundled timeline unavailable; retained events remain accessible, no CDN fallback.`)}),(0,h.jsx)(`div`,{className:`timeline-mount`,ref:o}),s&&(0,h.jsx)(Va,{client:e,seed:t})]})}var ol=[[`tools`,Ur],[`context`,ti],[`timeline`,mi],[`runs`,ai]];function sl({api:e,onOpenProject:t,onWorkbenchHome:n,workbenchHome:r,projectEntries:i,notices:a,discovery:o,onOpenService:s,project:c,onChooseFolder:l,onPrepareSend:u,directoryNamespaces:d,previewModels:p,initialModel:m}){let{t:g,tx:_,locale:v,setLocale:y}=T(),[b]=(0,f.useState)(()=>e??zi()),[S,C]=(0,f.useState)(()=>typeof window>`u`?``:window.location.hash),[w,E]=(0,f.useState)(!1),[D]=(0,f.useState)(jc),[O,k]=(0,f.useState)(D?.taskId??null),[A,j]=(0,f.useState)(()=>D?null:Hi()??crypto.randomUUID()),ee=Wi(S,A??``),[M,N]=(0,f.useState)(null),[te,P]=(0,f.useState)([]),[F,I]=(0,f.useState)(null),[L,R]=(0,f.useState)(D?`task`:`files`),[z,B]=(0,f.useState)(),[V,H]=(0,f.useState)(),[U,ne]=(0,f.useState)(()=>{let e=typeof history>`u`?null:history.state,t=Hi();return t&&e?.cadenceConversationId===t&&typeof e?.cadenceCwd==`string`?e.cadenceCwd:void 0}),[re]=(0,f.useState)(()=>crypto.randomUUID()),ie=(0,f.useCallback)(()=>B(void 0),[]),[G,ae]=(0,f.useState)(D?D.scope??{kind:`task`,id:D.taskId}:null),oe=ra(c?.id,c?.epoch),se=!c||oe.readiness===`running`,ce=!!c&&(oe.readiness===`stopped`||oe.readiness===`not-started`),le=(0,f.useRef)(null);se&&oe.value?.epoch&&(le.current=oe.value.epoch);let ue=!c||!ce&&(se||le.current!==null),K=oa(b,O?{kind:`task`,id:O}:null,!w&&ue,le.current),de=(0,f.useRef)(!0);(K.workspace||K.observation||K.error||K.transportStatus===`stale`||K.compatible===!1)&&(de.current=!1);let fe=!!(c&&(oe.value||oe.error)),pe=!w&&!!(K.workspace||fe),me=(0,f.useRef)(null);(K.workspace||oe.value?.workspaceId)&&(me.current=K.workspace?.workspaceId??oe.value?.workspaceId??null);let he=u?async(e,t,n)=>{let r=await u(e,t,n);if(e.aborted)throw Error(`stale`);oe.prepared(r);let i=K.reconnect();await K.whenReady(r,e,i)}:void 0,q=Ji(b.client,pe),ge=Ki(b.client,K.workspace&&!w?{kind:`conversation-active`}:null,1e3),_e=ge.value?.kind===`conversation-active`?ge.value.entries:[],ve=[..._e,...(q.value?.entries??[]).filter(e=>!_e.some(t=>t.id===e.id))],ye=Ki(b.client,K.workspace&&!w?{kind:`workflow-active`}:null,2e3),be=ye.value?.kind===`workflow-active`?ye.value:void 0,xe=(0,f.useMemo)(()=>[...new Set([...be?.runs.map(e=>e.id)??[],...te])],[be,te]),Se=Ki(b.client,!c&&K.workspace&&!w?{kind:`projects`}:null),Ce=U??c?.cwd??(Se.value?.kind===`projects`?Se.value.entries.find(e=>e.current)?.path:void 0),we=V?.id===A?V:void 0;(0,f.useEffect)(()=>{we&&Hi()===we.id&&history.replaceState({...history.state,cadenceCwd:we.cwd,cadenceConversationId:we.id},``,location.href)},[we]);let Te=A?we:Ce?{id:re,cwd:Ce}:void 0,Ee=we?.cwd??Ce??(Se.value?.kind===`projects`?Se.value.entries.find(e=>e.current)?.path:void 0)??K.workspace?.rootLabel,J={state:K.observation,transportStatus:K.transportStatus,error:K.error,refresh:K.refresh},De=J.state?.snapshot.scope.kind===`task`&&J.state.snapshot.scope.id===O?J.state.snapshot.context:void 0,Oe=zc(),{mobile:Y,overlay:ke,closeDrawer:Ae}=Oe,je=(0,f.useRef)(null);Qc({enabled:Y&&!w,open:ke,onOpenChange:Oe.setDrawer,container:je}),Rc(je,ke,!w&&!!ke,Ae);let[X,Me]=(0,f.useState)(D?.snapshotSeq),[Ne,Pe]=(0,f.useState)(``),[Fe,Ie]=(0,f.useState)(``),Le=(0,f.useRef)(null),Re=(0,f.useRef)(null),ze=()=>{Re.current&&(Re.current.open=!1)},[Be,Ve]=(0,f.useState)(`messages`),[He,Ue]=(0,f.useState)(!1),[We,Ge]=(0,f.useState)(!1),[Ke,qe]=(0,f.useState)(),[Je,Ye]=(0,f.useState)(D?.cursor),[Xe,Ze]=(0,f.useState)(``),[Qe,$e]=(0,f.useState)([]),[et,tt]=(0,f.useState)(new Set),Z=(0,f.useRef)(!0),nt=e=>{Z.current&&$e(t=>{let n=t.findIndex(t=>t.commandId===e.commandId);return n<0?[...t,e]:t.map((t,r)=>r===n?Gi(t,e):t)})},rt=(0,f.useRef)(new sa),it=W({taskId:O,scope:G,selectedSnapshot:X??null,detached:w,attachment:K.attachmentVersion,workspaceContext:K.workspace?.context??null,observationError:K.error??null});rt.current.select(it),(0,f.useEffect)(()=>(Z.current=!0,()=>{Z.current=!1,rt.current.depart()}),[]);let at=e=>{C(``);let t=e??crypto.randomUUID();e||ne(Ee??Ce),N(null),t!==A&&(P([]),B(void 0)),rt.current.depart(),j(t),k(null),ae(null),Pe(``),Ie(``),qe(void 0),Ye(void 0),Me(void 0),Ve(`messages`),R(`files`),Ae(),history.replaceState({cadenceCwd:Ee??Ce,cadenceConversationId:t},``,`${location.pathname}${location.search}#chat=${t}`)};(0,f.useEffect)(()=>{A&&!window.location.hash&&history.replaceState(null,``,`${location.pathname}${location.search}#chat=${A}`)},[A]);let ot=(e,t)=>{N(null),P([]),j(null),R(`task`),Pe(t??``),Ie(``),Me(void 0),rt.current.depart(),k(e),ae({kind:`task`,id:e}),qe(void 0),Ye(void 0),Ve(`messages`),Ae(),history.replaceState(null,``,Ac(e))};(0,f.useEffect)(()=>{let e=()=>{let e=jc();if(e)N(null),P([]),j(null),R(`task`),rt.current.depart(),Me(e.snapshotSeq),Pe(``),Ie(``),k(e.taskId),ae(e.scope??{kind:`task`,id:e.taskId}),qe(void 0),Ye(e.cursor),Ve(`messages`),Ae();else{let e=Hi();if(e){C(window.location.hash);let t=history.state?.cadenceCwd;typeof t==`string`&&ne(t),B(void 0),N(null),P([]),j(e),k(null),ae(null),R(`files`),rt.current.depart(),Ae()}}};return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[Ae]);let st=(e,t,n)=>{N(null),Me(t),Ie(n??``),rt.current.depart(),ae(e),qe(void 0),Ye(void 0),Ve(`messages`),Ae(),O&&history.replaceState(null,``,Ac(O,void 0,{scope:e,snapshotSeq:t}))},ct=X??J.state?.snapshot.committedSeq??K.workspace?.committedSeq,lt=K.workspace?.storeId,ut=G&&lt&&ct?{storeId:lt,scope:G,snapshotSeq:ct,reader:`messages`,after:null,limit:50}:null,dt=G&&lt&&ct?{storeId:lt,scope:G,snapshotSeq:ct,query:null,recordId:null,recordVersion:null,field:null,offset:0}:null,ft=De?J.state?.snapshot.runs??[]:[],pt=rt.current.ticket(),mt=e=>{nt(e),e.receipt&&rt.current.current(pt)&&K.refresh()},ht=e=>{if(et.has(e)||!K.cancelCompatible||!K.activeRuns)return;let t=crypto.randomUUID(),n=K.activeRuns.epoch;tt(t=>new Set(t).add(e)),nt({commandId:t,error:g(`Stop requested; settlement is not yet confirmed.`)}),b.client.cancel({commandId:t,epoch:n,runId:e}).then(e=>{mt(e.kind===`ok`?{commandId:t,receipt:e.value}:{commandId:t,error:g(`{code}; cancellation effect {effect}. Observe exact receipt.`,{code:e.error.code,effect:e.error.effect})})}).catch(()=>nt({commandId:t,error:g(`Cancellation effect uncertain. Observe exact receipt.`)})).finally(()=>{Z.current&&tt(t=>{let n=new Set(t);return n.delete(e),n})})};if(w)return(0,h.jsxs)(`main`,{className:`entry`,children:[(0,h.jsx)(`span`,{className:`empty-logo`,"aria-hidden":`true`,children:`C`}),(0,h.jsx)(`h1`,{children:g(`Detached`)}),(0,h.jsx)(`p`,{children:g(`Accepted service work continues. No Cancel was requested.`)}),Qe.map(e=>(0,h.jsxs)(`p`,{children:[g(`Observe command after reconnect:`),` `,(0,h.jsx)(`code`,{children:e.commandId})]},e.commandId)),(0,h.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>E(!1),children:g(`Reconnect as a viewer`)})]});let gt=K.activeRuns,_t=gt?.status===`complete`?gt.runs:[],vt=!w&&!K.error&&K.transportStatus===`current`&&(!J.state||J.state.connection===`current`),yt=se&&vt,bt=de.current&&!J.state&&!J.error&&!oe.error&&(!c||!oe.value&&oe.readiness===`unknown`||oe.readiness===`running`),xt=ce?{status:oe.readiness===`not-started`?`not-started`:`stopped`}:K.compatible===!1?{status:`incompatible`}:se&&vt&&K.compatible&&K.epoch&&(!c||oe.value?.epoch===K.epoch)?{status:`ready`,epoch:K.epoch,attachmentVersion:K.attachmentVersion}:{status:bt?`connecting`:`unavailable`},St=w?`Viewer disconnected`:bt?`Connecting…`:c&&oe.readiness===`unknown`?`Project readiness unknown`:c&&oe.readiness===`stale`?`Project observation stale`:ce?`Ready to prepare on Send`:vt?K.workspace?J.state?.connection??(O?`Task snapshot not observed yet`:`Chat ready`):`Viewer observation unavailable`:`Viewer observation stale`;return(0,h.jsxs)(`div`,{className:`app${Oe.className}`,children:[(0,h.jsxs)(`header`,{className:`topbar`,children:[(0,h.jsx)(`button`,{type:`button`,className:`panel-toggle navigation-toggle`,"aria-label":g(`Toggle conversation navigation`),"aria-expanded":Y?ke===`left`:Oe.navigation,onClick:()=>Oe.toggle(`left`),children:(0,h.jsx)(Qr,{"aria-hidden":`true`})}),(0,h.jsxs)(`div`,{className:`topbar-flow`,children:[n&&(0,h.jsx)(`button`,{type:`button`,className:`icon-btn`,"aria-label":g(`Workbench projects`),title:g(`Workbench projects`),onClick:n,children:(0,h.jsx)(oi,{})}),(0,h.jsxs)(`span`,{className:`brand`,children:[(0,h.jsx)(`span`,{className:`brand-logo`,"aria-hidden":`true`,children:`C`}),(0,h.jsx)(`h1`,{className:`brand-name`,children:`Cadence`})]}),(0,h.jsx)(`span`,{className:`tb-spacer`,"aria-hidden":`true`}),G&&(0,h.jsxs)(`nav`,{className:`tb-tabs`,"aria-label":g(`Recorded views`),children:[(0,h.jsxs)(`button`,{type:`button`,className:`tb-tab`,"aria-pressed":Be===`messages`&&!Je,onClick:()=>{Ye(void 0),qe(void 0),Ve(`messages`)},children:[(0,h.jsx)(Zr,{"aria-hidden":`true`}),g(`Conversation`)]}),(0,h.jsxs)(`details`,{className:`view-menu`,ref:Le,onKeyDown:e=>{e.key===`Escape`&&Le.current&&(Le.current.open=!1,Le.current.querySelector(`summary`)?.focus())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(e.currentTarget.open=!1)},children:[(0,h.jsxs)(`summary`,{className:`chip`,children:[Be===`messages`?g(`Details`):_(Be),(0,h.jsx)(_i,{"aria-hidden":`true`})]}),(0,h.jsxs)(`div`,{className:`view-menu-items`,children:[ol.map(([e,t])=>(0,h.jsxs)(`button`,{type:`button`,"aria-pressed":Be===e,onClick:()=>{Ye(void 0),qe(void 0),Ve(e),Le.current&&(Le.current.open=!1,Le.current.querySelector(`summary`)?.focus())},children:[(0,h.jsx)(t,{"aria-hidden":`true`}),_(e)]},e)),(0,h.jsxs)(`div`,{className:`view-menu-actions`,children:[(0,h.jsxs)(`button`,{type:`button`,"aria-label":g(`Export selected scope`),disabled:!ut,onClick:()=>{Le.current&&(Le.current.open=!1,Le.current.querySelector(`summary`)?.focus()),Ge(!0)},children:[(0,h.jsx)(ui,{"aria-hidden":`true`}),g(`Export selected scope`)]}),(0,h.jsxs)(`button`,{type:`button`,"aria-label":g(`Copy token-free link`),disabled:!O,onClick:()=>{O&&ga(Ac(O,Je,G?{scope:G,snapshotSeq:X}:void 0)).then(e=>Ze(e?``:g(`Link copy unavailable.`)))},children:[(0,h.jsx)(ei,{"aria-hidden":`true`}),g(`Copy token-free link`)]})]})]})]})]}),(0,h.jsx)(`span`,{className:`tb-spacer`,"aria-hidden":`true`}),(0,h.jsxs)(`div`,{className:`tb-actions`,children:[G&&(0,h.jsx)(eo,{disabled:!dt,onOpen:()=>Ue(!0)}),(0,h.jsxs)(`button`,{type:`button`,className:`chip chip-lang`,lang:v===`zh`?`en`:`zh-CN`,"aria-label":v===`zh`?`Switch to English`:`切换到中文`,"data-tip":v===`zh`?`Switch to English`:`切换到中文`,onClick:()=>y(v===`zh`?`en`:`zh`),children:[(0,h.jsx)(ii,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{children:v===`zh`?`EN`:`中文`})]}),(0,h.jsxs)(`details`,{className:`more-menu`,ref:Re,onKeyDown:e=>{e.key===`Escape`&&Re.current&&(Re.current.open=!1,Re.current.querySelector(`summary`)?.focus())},onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||(e.currentTarget.open=!1)},children:[(0,h.jsx)(`summary`,{className:`chip`,"aria-label":g(`More`),title:g(`More`),children:(0,h.jsx)(Xr,{"aria-hidden":`true`})}),(0,h.jsxs)(`div`,{className:`more-menu-items`,children:[(0,h.jsxs)(`button`,{type:`button`,"aria-label":g(`Observe current state`),onClick:()=>{ze(),K.refresh(),oe.refresh()},children:[(0,h.jsx)(Jr,{"aria-hidden":`true`}),g(`Refresh status`)]}),s&&(0,h.jsxs)(`button`,{type:`button`,onClick:()=>{ze(),s()},children:[(0,h.jsx)(Kr,{"aria-hidden":`true`}),(0,h.jsxs)(`span`,{className:`more-menu-text`,children:[g(`Cadence service`),(0,h.jsx)(`small`,{children:g(`Version, restart and upgrade.`)})]})]}),(0,h.jsxs)(`button`,{type:`button`,"aria-label":g(`Disconnect this page`),title:g(`Return — accepted work continues`),onClick:()=>{ze(),Ae(),Ue(!1),Ge(!1),rt.current.depart(),E(!0)},children:[(0,h.jsx)($r,{"aria-hidden":`true`}),(0,h.jsxs)(`span`,{className:`more-menu-text`,children:[g(`Disconnect this page`),(0,h.jsx)(`small`,{children:g(`Started work keeps running.`)})]})]}),(0,h.jsxs)(`div`,{className:`more-menu-build${K.compatible===!1?` warn`:``}`,title:Ri?.buildId??g(`unbuilt source`),children:[(0,h.jsx)(`span`,{children:g(`Shared compatibility: {state}.`,{state:K.compatible===void 0?g(`Execution compatibility not observed`):K.compatible?g(`compatible`):g(`unavailable / mismatch — reload built assets; normal actions disabled`)})}),(0,h.jsx)(x,{text:g(`Local browser build: {build}.`),slots:{build:(0,h.jsx)(`code`,{children:Ri?.buildId??g(`unbuilt source`)})}})]})]})]})]})]}),(0,h.jsxs)(`button`,{type:`button`,className:`panel-toggle has-label inspector-toggle`,"aria-label":g(`Toggle workspace panels`),"aria-expanded":Y?ke===`right`:Oe.inspector,onClick:()=>Oe.toggle(`right`),children:[(0,h.jsx)(Gr,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{children:g(G&&L===`task`?`History details`:`Files`)})]})]}),!K.workspace&&_t.length>0&&(0,h.jsx)(`section`,{className:`run-strip`,"aria-label":g(`Execution and cancellation`),children:_t.map(e=>(0,h.jsxs)(`div`,{className:`run-strip-row`,children:[(0,h.jsx)(`span`,{className:`status-dot busy`,"aria-hidden":`true`}),(0,h.jsxs)(`span`,{className:`run-strip-label`,children:[_(e.kind),` `,e.runId,` · `,_(e.stage)]}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>ot(e.taskId),children:g(`Open active task`)}),(0,h.jsxs)(`button`,{type:`button`,className:`danger`,disabled:!K.cancelCompatible||et.has(e.runId),onClick:()=>ht(e.runId),children:[(0,h.jsx)(Wr,{"aria-hidden":`true`}),g(`Cancel run — request stop`)]})]},e.runId))}),a,(0,h.jsx)(kc,{error:Xe,projectObservationError:oe.error,observationError:K.error,unavailable:!bt&&!ce&&!yt,onRefresh:()=>{K.refresh(),oe.refresh()}}),(0,h.jsxs)(`div`,{ref:je,className:`layout`,style:{"--left-w":`${Oe.left}px`,"--right-w":`${Oe.right}px`},children:[(0,h.jsx)(`button`,{type:`button`,"aria-label":g(`Close drawer`),tabIndex:-1,className:`drawer-backdrop persistent${ke?` on`:``}`,onClick:Ae}),(0,h.jsxs)(`section`,{className:`panel-drawer drawer-left${ke===`left`?` open`:``}`,"aria-label":g(`Conversation navigation`),tabIndex:-1,inert:Y?ke!==`left`:!Oe.navigation||ke===`right`,children:[!pe&&(0,h.jsxs)(`aside`,{className:`panel panel-left lp-panel`,children:[o&&(0,h.jsx)(ho,{...o}),(0,h.jsx)(`p`,{className:`panel-empty`,role:`status`,children:g(bt?`Reading conversation history…`:`Conversation history could not be read. This is not an empty history.`)})]}),pe&&(0,h.jsx)(Tc,{discovery:o,client:b.client,workspace:K.workspace,executionStopped:ce,taskId:O,scope:G,runs:ft,snapshot:J.state?.snapshot.committedSeq,activeRuns:K.activeRuns,cancelCompatible:!!K.cancelCompatible,canceling:et,onCancel:ht,chats:ve,chatActivityKnown:ge.value?.kind===`conversation-active`&&!ge.error,chatHistoryPartial:q.loading||q.canPrevious||!!q.value?.next,chatHistoryControls:(0,h.jsxs)(h.Fragment,{children:[q.error&&(0,h.jsx)(`p`,{role:`alert`,children:q.error}),q.loading&&(0,h.jsx)(`p`,{className:`panel-hint`,children:g(`Reading conversation history…`)}),q.canPrevious&&(0,h.jsx)(`button`,{type:`button`,disabled:q.loading,onClick:q.previous,children:g(`Newer conversations`)}),q.value?.next&&(0,h.jsx)(`button`,{type:`button`,disabled:q.loading,onClick:q.next,children:g(`Older conversations`)}),q.canPrevious&&(0,h.jsx)(`button`,{type:`button`,onClick:q.first,children:g(`Latest conversations`)}),q.error&&(0,h.jsx)(`button`,{type:`button`,onClick:q.refresh,children:g(`Observe current state`)})]}),conversationId:A,onConversation:at,onNewConversation:()=>at(),workflows:be?.runs,workflowLinks:be?.links,workflowError:!!ye.error,selectedWorkflow:M?.runId,onWorkflow:(e,t)=>{t?at(t):(N({runId:e.id,stepId:null,label:e.goal}),Ae())},onCancelWorkflow:async e=>{let t=await Qs(b.client,e);t&&Ze(t),ye.refresh()},onTask:ot,onScope:st}),K.workspace&&(0,h.jsx)(xo,{client:b.client,active:K.activeRuns,taskId:O,runs:ft,snapshot:ct,workflowRuns:xe,selected:M,onOpenWorkflow:e=>{N(e),Ae()},onOpen:(e,t,n,r)=>{ot(e),ae({kind:`child`,id:t}),Ie(r),Me(n),history.replaceState(null,``,Ac(e,void 0,{scope:{kind:`child`,id:t},snapshotSeq:n}))}})]}),(0,h.jsx)(Lc,{side:`left`,width:Oe.left,maximum:Oe.leftMaximum,onResize:e=>Oe.resize(`left`,e)}),(0,h.jsxs)(`main`,{className:`main`,inert:ke!==null,children:[A&&c&&!fe&&(0,h.jsx)(`p`,{className:`panel-empty`,role:`status`,children:g(`Reading this conversation…`)}),M&&(0,h.jsx)(Dc,{client:b.client,agent:M,backLabel:g(A?`Back to conversation`:O?`Back to task`:`Back`),onBack:()=>N(null),onOpenAgent:N},`${M.runId}:${M.stepId??``}`),A&&(!c||fe)&&(0,h.jsx)(ic,{client:b.client,id:A,activitySelected:ee.selected,initialLeaf:ee.leaf,initialCwd:Ce,onLocation:H,hidden:!!M,onOpenAgent:N,onWorkflowRuns:P,workspaceId:c?`checkout:${c.path}`:me.current??`connecting`,directoryNamespaces:d,legacyWorkspaceId:c?oe.value?.workspaceId??void 0:void 0,prepareForSend:he,actionsReady:se&&!!K.workspace&&!!K.compatible&&!K.error&&vt,available:pe,canInterrupt:!!K.cancelCompatible,enabled:he?pe:!!K.workspace&&!!K.compatible&&!K.error,modelAvailability:xt,previewModels:p,initialModel:m?.conversationId===A?m.model:void 0,onModelChanged:()=>{rt.current.depart(),K.refresh(!0),oe.refresh()},onChanged:()=>{q.refresh(),K.refresh()},reference:z,onReferenceUsed:ie},`${c?.id??me.current??`connecting`}:${A}:${ee.leaf??``}`),G&&!M&&(0,h.jsxs)(`header`,{className:`conversation-header`,children:[(0,h.jsxs)(`div`,{className:`conversation-heading`,children:[G.kind!==`task`&&O&&(0,h.jsx)(`button`,{type:`button`,className:`ghost`,onClick:()=>ot(O,Ne),children:g(`Back to task`)}),(0,h.jsx)(`h2`,{title:Ne||G.id,children:G.kind===`task`?Ne||g(`Task {id}`,{id:G.id.slice(0,8)}):Fe||g(`{kind} {id}`,{kind:_(G.kind),id:G.id.slice(0,8)})}),G.kind===`child`&&(0,h.jsx)(`span`,{className:`conversation-badge`,children:g(`Subagent`)})]}),(0,h.jsxs)(`details`,{className:`conversation-info`,children:[(0,h.jsxs)(`summary`,{children:[g(`Recorded conversation`),` ·`,` `,g(`snapshot {seq}`,{seq:ct??``})]}),(0,h.jsx)(`code`,{children:G.id}),(0,h.jsx)(`p`,{children:g(`Pages and old outcomes are historical observations, not renewed consent.`)})]})]}),(0,h.jsxs)(`div`,{className:`workspace-content`,hidden:!!A||!!M,children:[!ut&&(0,h.jsxs)(`section`,{className:`empty-state`,children:[(0,h.jsx)(`span`,{className:`empty-logo`,"aria-hidden":`true`,children:`C`}),(0,h.jsx)(`h2`,{children:K.error?g(`Recorded history could not be read.`):g(`Reading recorded history…`)}),(0,h.jsx)(`p`,{children:g(`History is readonly. Start new work in a conversation with /cadence.`)})]}),ut&&Je?(0,h.jsxs)(`div`,{className:`tab-body`,children:[Ke&&(Ke.owner.entity.kind===`task`||Ke.owner.entity.kind===`message`||Ke.owner.entity.kind===`tool`)&&(0,h.jsx)(Ha,{client:b.client,seed:{storeId:Je.storeId,scope:Je.scope,snapshotSeq:Je.snapshotSeq,kind:Ke.owner.entity.kind,id:Ke.owner.entity.id,version:Ke.owner.entity.version}},`${Ke.owner.entity.id}:${Ke.owner.entity.version}`),(0,h.jsx)(za,{client:b.client,cursor:Je,highlight:Ke?.range},`${Je.recordId}:${Je.recordVersion}`)]}):ut&&(0,h.jsxs)(`div`,{className:Be===`messages`||Be===`tools`?`tab-body transcript-body`:`tab-body`,children:[Be===`messages`&&(0,h.jsx)(uo,{client:b.client,seed:ut}),Be===`tools`&&(0,h.jsx)(cl,{client:b.client,seed:ut}),Be===`context`&&(0,h.jsx)(Va,{client:b.client,seed:ut}),Be===`timeline`&&(0,h.jsx)(il,{client:b.client,seed:ut,onSearch:()=>Ue(!0)}),Be===`runs`&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`section`,{className:`run-current`,children:[(0,h.jsx)(`h3`,{children:g(`Runs in the current snapshot`)}),ft.length>0?ft.map(e=>(0,h.jsx)(Xa,{run:e},e.childRunId??e.runId)):(0,h.jsx)(`p`,{className:`panel-empty`,children:De&&J.state?g(`No owner run projection in this snapshot.`):g(`No snapshot observed yet; absence is not proof of settlement.`)})]}),(0,h.jsx)(`h3`,{children:g(`Retained runs`)}),(0,h.jsx)($a,{client:b.client,seed:{...ut,scope:{kind:`task`,id:O??ut.scope.id}},onScope:st},O)]})]},`${G?.kind}:${G?.id}:${X??`current`}`)]}),K.workspace&&Qe.length>0&&(0,h.jsx)(`div`,{className:`receipt-dock`,children:Qe.map(e=>(0,h.jsx)(ca,{client:b.client,value:e,onChange:nt},e.commandId))})]}),(0,h.jsx)(Lc,{side:`right`,width:Oe.right,maximum:Oe.rightMaximum,onResize:e=>Oe.resize(`right`,e)}),(0,h.jsx)(`section`,{className:`panel-drawer drawer-right${ke===`right`?` open`:``}`,"aria-label":g(`Files and history drawer`),tabIndex:-1,inert:Y?ke!==`right`:!Oe.inspector,children:(0,h.jsxs)(`div`,{className:`workbench-right`,children:[(0,h.jsxs)(`nav`,{className:`rp-tabs`,"aria-label":g(`Workspace panels`),children:[(0,h.jsxs)(`button`,{type:`button`,className:`rp-tab`,"aria-pressed":L===`files`||!G,onClick:()=>R(`files`),children:[(0,h.jsx)(oi,{}),g(`Files`)]}),G&&(0,h.jsxs)(`button`,{type:`button`,className:`rp-tab`,"aria-pressed":L===`task`,disabled:!ut,onClick:()=>R(`task`),children:[(0,h.jsx)(ti,{}),g(`History details`)]})]}),L===`files`||!G?(0,h.jsx)(ac,{location:Te,client:b.client,enabled:!!K.workspace&&!!Te,onReference:e=>{A||at(re);let t=!A&&Te?`${Te.cwd.replace(/[\\/]+$/,``)}${Te.cwd.startsWith(`/`)?`/`:`\\`}${e}`:e;B(t),Ae()}},Te?.cwd??`owner`):ut?(0,h.jsx)(hc,{client:b.client,seed:{...ut,scope:{kind:`task`,id:O??ut.scope.id}}},O):(0,h.jsx)(`p`,{className:`panel-empty`,role:`status`,children:K.error?g(`Recorded history could not be read.`):g(`Reading recorded history…`)})]})})]}),(0,h.jsxs)(`footer`,{className:`statusbar`,children:[(0,h.jsxs)(`div`,{className:`statusbar-left`,children:[(0,h.jsxs)(`span`,{className:`status-item`,role:`status`,title:g(`Connection freshness is not execution outcome.`),children:[(0,h.jsx)(`span`,{className:`status-dot ${bt?`busy`:ce?``:!yt||!K.workspace?`error`:J.transportStatus===`current`?J.state?J.state.connection===`current`?`ok`:`busy`:``:`busy`}`,"aria-hidden":`true`}),_(St)]}),c&&(0,h.jsx)(`span`,{className:`status-item faint`,children:g(`Execution service: {status}`,{status:_(oe.readiness)})}),gt?.status===`complete`?_t.length>0&&(0,h.jsx)(`span`,{className:`status-item warn`,children:g(yt?_t.length===1?`{count} active run`:`{count} active runs`:`Last observed: {count} active runs`,{count:_t.length})}):!bt&&!ce&&(0,h.jsx)(`span`,{className:`status-item faint`,children:g(`Active roster unavailable; absence is not proof of settlement.`)})]}),(0,h.jsxs)(`div`,{className:`statusbar-right`,children:[(K.workspace||c)&&(0,h.jsx)(Oc,{path:Ee,onClick:()=>l?l(Ee):I(``)}),K.compatible===!1&&(0,h.jsx)(`span`,{className:`status-item warn`,children:g(`unavailable / mismatch — reload built assets; normal actions disabled`)})]})]}),F!==null&&K.workspace&&(0,h.jsx)(yc,{onOpen:t,projects:i??(Se.value?.kind===`projects`?Se.value.entries:[]),client:b.client,current:Ee??K.workspace.rootLabel,initial:F||void 0,home:r,epoch:K.workspace.epoch,onClose:()=>I(null)}),He&&dt&&(0,h.jsx)(Ya,{client:b.client,seed:dt,onClose:()=>Ue(!1),onHit:e=>{qe(e),Ye(e.cursor),O&&history.replaceState(null,``,Ac(O,e.cursor,G?{scope:G,snapshotSeq:X}:void 0))}}),We&&dt&&(0,h.jsx)(Ka,{request:{storeId:dt.storeId,scope:dt.scope,snapshotSeq:dt.snapshotSeq,format:`ndjson`},onClose:()=>Ge(!1)})]})}function cl({client:e,seed:t}){let n=pa(e,{...t,reader:`tools`}),r=n.page;return(0,h.jsxs)(`section`,{className:`tools-list`,children:[(0,h.jsx)(Ba,{pager:n}),(0,h.jsx)(`div`,{className:`tools-body`,children:r&&!(`kind`in r)&&r.records.map(t=>t.kind===`tool`?(0,h.jsx)(po,{record:t,client:e,seed:r.request},`${t.owner.entity.id}:${t.version}`):null)})]})}var ll=`cadence-last-project`;function ul(){try{let e=localStorage.getItem(ll);return e&&/^[a-f0-9]{64}$/.test(e)?e:null}catch{return null}}function dl(e){try{localStorage.getItem(`cadence-last-project`)!==e&&localStorage.setItem(ll,e)}catch{}}function fl(e){let t=ul();return t?e.projects.find(e=>e.id===t):void 0}async function pl(e,t){try{let n=await fetch(`/workbench/v1/projects/${e}`,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:t});if(!n.ok)return!1;let r=hn(await Yi(n));return(r.workspaceId!==null||r.status===`not-started`)&&!t.aborted}catch{return!1}}async function ml(e,t){if(!Ri)throw Error(`unsupported-context`);let n=await fetch(`/workbench/v1/models${e?`?project=${encodeURIComponent(e)}`:``}`,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:t,headers:{"X-Cadence-Build":JSON.stringify({kind:`browser`,...Ri})}}),r=await Yi(n);if(!n.ok)throw Error(Xi(r));return fn(r)}async function hl(e){let t=await fetch(`/workbench/v1`,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:e}),n=await Yi(t);if(!t.ok)throw Error(Xi(n));return bn(n)}async function gl(e,t,n,r,i){if(!Ri)throw Error(`unsupported-context`);let a={method:`POST`,credentials:`same-origin`,redirect:`error`,signal:r,headers:{"Content-Type":`application/json`,"X-Cadence-CSRF":n.csrf,"X-Cadence-Build":JSON.stringify({kind:`browser`,...Ri})},body:JSON.stringify({...t,epoch:n.epoch})};if(r?.aborted)throw r.reason;let o=fetch(e,a);i?.();let s=await o,c=await Yi(s);if(!s.ok||!c||typeof c!=`object`||!(`kind`in c)||c.kind!==`project`||!(`project`in c))throw Error(Xi(c));let l=mn(c.project);return{project:l,entry:{...n,projects:[...n.projects.filter(e=>e.id!==l.id),l]}}}async function _l(e,t){let n=await hl(t);return gl(`/workbench/v1/select`,{path:e},n,t)}async function vl(e,t,n,r){let i=await hl(t),a=i.projects.find(t=>t.id===e.id);if(!a||a.path!==e.path||a.cwd!==e.cwd)throw Error(`stale`);let o=await gl(`/workbench/v1/prepare-send`,{projectId:e.id,commandId:crypto.randomUUID(),...n?{location:n}:{}},i,t,()=>r?.(`dispatched`));if(!o.project.epoch||o.project.id!==e.id||o.project.path!==e.path||o.project.cwd!==e.cwd)throw Error(`stale`);return r?.(`confirmed`),o}async function yl(e,t,n){if(!t.sessionId||t.history!==`shared`)throw Error(`unavailable`);let r=await _l(t.cwd,n);if(n.aborted||r.project.path!==e||r.project.cwd!==t.cwd)throw Error(`stale`);return r}var bl=[`turn`,`queued`,`running`,`research`,`implementing`,`verifying`,`reviewing`,`recovering`,`learning`,`integrating`,`stopping`,`settling`];function xl(e){let t=z(e,[`id`,`source`,`sessionId`,`cwd`,`leaf`,`history`,`phase`,`freshness`,`observedAt`,`epoch`,`instance`,`executionCwd`]);return{id:V(t.id),source:I(t.source,[`terminal`,`turn`,`workflow`]),sessionId:t.sessionId===null?null:nn(t.sessionId),cwd:N(t.cwd,4096,!0),leaf:t.leaf===null?null:N(t.leaf,128,!0),history:I(t.history,[`shared`,`unavailable`]),phase:I(t.phase,bl),freshness:I(t.freshness,[`current`,`stale`,`unknown`]),observedAt:P(t.observedAt,0),epoch:t.epoch===null?null:V(t.epoch),instance:t.instance===null?null:V(t.instance),executionCwd:t.executionCwd===null?null:N(t.executionCwd,4096,!0)}}function Sl(e){let t=z(e,[`kind`,`epoch`,`observedAt`,`completeness`,`unavailable`,`projects`]);return{kind:L(t.kind,`activity-discovery`),epoch:V(t.epoch),observedAt:P(t.observedAt,0),completeness:I(t.completeness,[`complete`,`partial`]),unavailable:P(t.unavailable,0,1e4),projects:B(t.projects,128,e=>{let t=z(e,[`path`,`activities`]);return{path:N(t.path,4096,!0),activities:B(t.activities,256,xl)}})}}async function Cl(e){if(!Ri)throw Error(`unsupported-context`);let t=wi([e],12e3);try{let e=await fetch(`/workbench/v1/activity`,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:t.signal,headers:{"X-Cadence-Build":JSON.stringify({kind:`browser`,...Ri})}}),n=await Yi(e);if(!e.ok)throw Error(Xi(n));return Sl(n)}finally{t.dispose()}}function wl(e,t){return{...e,completeness:`partial`,unavailable:Math.max(1,e.unavailable),projects:e.projects.map(e=>({...e,activities:e.activities.filter(e=>t-e.observedAt<=12e4).map(e=>({...e,freshness:`unknown`}))})).filter(e=>e.activities.length)}}function Tl(e,t,n,r=Cl){let i=new AbortController,a,o,s=async()=>{try{let a=await r(i.signal);if(i.signal.aborted)return;if(a.epoch!==e)throw n(),Error(`stale`);o=a,t(o,``)}catch(e){if(i.signal.aborted)return;o=o?wl(o,Date.now()):void 0,t(o,e instanceof Error?e.message:`unavailable`)}finally{i.signal.aborted||(a=setTimeout(s,3e3))}};return s(),()=>{i.abort(),clearTimeout(a)}}function El(e,t){let[n,r]=(0,f.useState)(),[i,a]=(0,f.useState)(``);return(0,f.useEffect)(()=>{if(r(void 0),a(``),e)return Tl(e,(e,t)=>{r(e),a(t)},t)},[e,t]),{value:n,error:i}}var Dl=`cadence-recovery-dismissed`,Ol={reboot:`The machine restarted while Cadence was running. Cadence recovered automatically.`,crash:`Cadence ended unexpectedly last time. It recovered automatically.`,restart:`Cadence ran into a problem and restarted itself.`,storage:`Cadence repaired some incomplete files automatically.`},kl={"released-locks":`Released the previous run's locks.`,"stopped-workers":`Stopped {count} leftover worker processes.`,"stopped-owner":`Stopped the unresponsive previous process.`,"continued-history":`History continues after the last complete entry.`,"archived-history":`Unreadable history was archived and a new one was started.`,"archived-state":`Damaged state was archived; it started afresh.`,"rebuilt-registry":`Rebuilt the project registry.`,"removed-temporaries":`Set aside interrupted temporary files.`};function Al(){try{let e=JSON.parse(localStorage.getItem(Dl)??`[]`);return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}catch{return[]}}function jl(e){return e.split(/[\\/]/).filter(Boolean).at(-1)??e}function Ml({notices:e,project:t}){let{t:n}=T(),[r,i]=(0,f.useState)(Al),[a,o]=(0,f.useState)(!1),s=e.filter(e=>!r.includes(e.id)&&(t===void 0||e.scope!==`project`||e.path===t));if(!s.length)return null;let c=s[0],l=()=>{let e=[...r,...s.map(e=>e.id)].slice(-50);try{localStorage.setItem(Dl,JSON.stringify(e))}catch{}i(e)},u=e=>e.scope===`project`&&e.path?n(`Project {name}`,{name:jl(e.path)}):e.scope===`workbench`?n(`Workbench`):n(`Project registry`);return(0,h.jsxs)(`div`,{className:`banner-notice recovery-notice`,role:`status`,children:[(0,h.jsxs)(`span`,{children:[n(Ol[c.cause]),` `,c.cause!==`storage`&&n(`Work that was running is marked as interrupted; start it again when you are ready.`)]}),` `,(0,h.jsx)(`button`,{type:`button`,onClick:()=>o(e=>!e),children:n(a?`Hide details`:`Details`)}),` `,(0,h.jsx)(`button`,{type:`button`,onClick:l,children:n(`Dismiss`)}),a&&(0,h.jsx)(`ul`,{className:`recovery-details`,children:s.map(e=>(0,h.jsxs)(`li`,{children:[(0,h.jsx)(`strong`,{children:u(e)}),` `,(0,h.jsx)(`time`,{dateTime:new Date(e.at).toISOString(),children:new Date(e.at).toLocaleString()}),`: `,e.actions.map(t=>n(kl[t],{count:e.workers})).join(` `),e.archived&&` ${n(`Archived files are kept for 30 days; cadence doctor shows where.`)}`]},e.id))})]})}var Nl={restart:18e4,upgrade:12e5},Pl=1e3,Fl={"fetch-failed":`The release could not be downloaded; the service kept running.`,"stop-unconfirmed":`The running service did not confirm its orderly stop.`,"install-failed":`The package manager could not install the release.`,"not-ready":`The new service did not become ready.`,refused:`The service manager refused the operation.`,interrupted:`The job ended without reporting.`},Il=e=>e instanceof Error?e.message:`unavailable`;function Ll(e,t){if(t.state===`ready`)return t.action===`restart`?e(`Cadence restarted.`):t.version===t.from?e(`Cadence {version} was already installed.`,{version:t.from}):e(`Cadence {version} is running.`,{version:t.version??``});if(t.state===`rolled-back`)return e(`Cadence {to} did not become ready; {version} was reinstalled.`,{to:t.to??``,version:t.version??t.from});if(t.state===`running`)return e(`In progress…`);let n=e(Fl[t.reason??`refused`]);return t.action===`restart`?e(`The restart did not finish: {reason}`,{reason:n}):e(`The upgrade did not finish: {reason}`,{reason:n})}function Rl(e){return e.state===`failed`?e.reason===`fetch-failed`||e.reason===`refused`:e.state===`ready`&&e.action===`upgrade`&&e.version===e.from}function zl(e,t){switch(t){case`npm`:return e(`Installation: npm global.`);case`bun`:return e(`Installation: Bun global.`);case`npm-local`:return e(`Installation: npm local.`);case`bun-local`:return e(`Installation: Bun local.`);case`pi-npm`:return e(`Installation: Pi-managed (npm).`);case`pi-bun`:return e(`Installation: Pi-managed (Bun).`);case`pinned`:return e(`Pi pins this package version; change its package declaration explicitly before upgrading.`);case`not-writable`:return e(`This account cannot write the installation; update it in a terminal.`);case`unsupported-install`:return e(`The installation method could not be safely identified; update it using its original installation method.`)}}function Bl({epoch:e,csrf:t,onClose:n}){let{t:r}=T(),[i,a]=(0,f.useState)(),[o,s]=(0,f.useState)(``),[c,l]=(0,f.useState)(),[u,d]=(0,f.useState)(null),[p,m]=(0,f.useState)(!1),[g,_]=(0,f.useState)(!1),[v,y]=(0,f.useState)(null),[x,S]=(0,f.useState)(!1),[C,w]=(0,f.useState)(),[E,D]=(0,f.useState)(0);(0,f.useEffect)(()=>{let e=new AbortController;return Qi(e.signal).then(a,t=>{e.signal.aborted||s(Il(t))}),()=>e.abort()},[E]),(0,f.useEffect)(()=>{if(!v)return;let{job:e,since:t}=v,n=new AbortController,r,i=async()=>{if(Date.now()-t>Nl[e.action])return w(`timeout`);try{let t=await Qi(n.signal);if(t.job?.id===e.id&&t.job.state!==`running`)return w(t.job)}catch(e){if(n.signal.aborted)return;if(e instanceof j||e instanceof Error&&e.message===`invalid`)return w(`changed`);S(!0)}r=setTimeout(i,Pl)};return r=setTimeout(i,Pl),()=>{n.abort(),clearTimeout(r)}},[v]);let O=()=>{l(`checking`),$i().then(l,()=>l(`failed`)).finally(()=>D(e=>e+1))},k=n=>{i&&(_(!0),s(``),ea({action:n.action,from:i.version,to:n.to,work:i.work,epoch:e},t).then(e=>y({job:e,since:Date.now()})).catch(e=>{s(Il(e)),m(!1),D(e=>e+1)}).finally(()=>_(!1)))};if(v){let{job:e}=v,t=C!==void 0&&(typeof C==`string`||C.state!==`ready`),a=typeof C==`object`&&Rl(C),o=i?.unit;return(0,h.jsxs)(Ga,{title:r(`Cadence service`),onClose:C?n:void 0,children:[(0,h.jsxs)(`section`,{className:`service-progress`,children:[C===void 0?(0,h.jsxs)(`p`,{role:`status`,children:[(0,h.jsx)(`span`,{className:`status-dot busy`,"aria-hidden":`true`}),e.action===`restart`?r(x?`Cadence is starting again…`:`Stopping Cadence…`):r(x?`Installing {to} and starting Cadence…`:`Downloading {to}, then stopping Cadence…`,{to:e.to??``})]}):(0,h.jsxs)(`p`,{role:t?`alert`:`status`,children:[(0,h.jsx)(`span`,{className:`status-dot ${t?`error`:`ok`}`,"aria-hidden":`true`}),C===`timeout`?r(`Cadence did not report back within {minutes} minutes.`,{minutes:Nl[e.action]/6e4}):C===`changed`?r(`Cadence answered with a different version.`):Ll(r,C)]}),(0,h.jsx)(`p`,{children:r(C===void 0?`This runs outside the service: closing or reloading the page does not stop it, and running work is stopped in order.`:a?`The service was not changed; this page stays connected.`:`Reload the page to reconnect to the new service.`)}),t&&o&&(0,h.jsxs)(`p`,{className:`service-commands`,children:[r(`Details in a terminal:`),` `,(0,h.jsxs)(`code`,{children:[`cadence server status`,o.scope===`system`?` --system`:``]}),` `,(0,h.jsxs)(`code`,{children:[`journalctl `,o.scope===`system`?``:`--user `,`-u`,` `,o.name.replace(/\.service$/,`.maintenance.service`)]})]})]}),C!==void 0&&(0,h.jsx)(`footer`,{children:a?(0,h.jsx)(`button`,{type:`button`,onClick:n,children:r(`Close`)}):(0,h.jsx)(`button`,{type:`button`,className:`primary`,onClick:()=>window.location.reload(),children:r(`Reload page`)})})]})}if(u&&i){let e=i.work;return(0,h.jsxs)(Ga,{title:r(`Cadence service`),onClose:n,children:[(0,h.jsxs)(`section`,{children:[(0,h.jsx)(`h3`,{children:u.action===`restart`?r(`Restart Cadence?`):r(`Upgrade Cadence {from} to {to}?`,{from:i.version,to:u.to})}),(0,h.jsx)(`p`,{children:u.action===`restart`?r(`The service stops in order and starts again; this page waits and then reloads.`):r(`The package manager downloads {to} while Cadence keeps running; then the service stops, {to} is installed and the service starts again. If {to} does not become ready, {from} is reinstalled.`,{to:u.to,from:i.version})}),e>0&&(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(`p`,{role:`alert`,children:r(`{count} running workflows or conversations will be stopped.`,{count:e})}),(0,h.jsxs)(`label`,{className:`service-confirm`,children:[(0,h.jsx)(`input`,{type:`checkbox`,checked:p,onChange:e=>m(e.target.checked)}),` `,r(`Stop them and continue`)]})]})]}),o&&(0,h.jsx)(`p`,{role:`alert`,children:b(r,o)}),(0,h.jsxs)(`footer`,{children:[(0,h.jsx)(`button`,{type:`button`,onClick:()=>{d(null),m(!1),s(``)},children:r(`Back`)}),(0,h.jsx)(`button`,{type:`button`,className:e>0?`danger`:`primary`,disabled:g||e>0&&!p,onClick:()=>k(u),children:u.action===`restart`?r(`Restart now`):r(`Upgrade now`)})]})]})}let A=i&&c&&typeof c==`object`?jn(c.version,i.version)>0:!1;return(0,h.jsxs)(Ga,{title:r(`Cadence service`),onClose:n,children:[i?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(`section`,{className:`service-info`,children:[(0,h.jsxs)(`h3`,{children:[`Cadence `,i.version]}),(0,h.jsx)(`p`,{children:zl(r,i.upgrade)}),(0,h.jsx)(`p`,{children:i.unit?r(`Runs as {unit} ({scope} systemd service).`,{unit:i.unit.name,scope:i.unit.scope}):r(`This workbench was not started by Cadence's systemd service, so the page cannot restart or upgrade it. Use cadence server restart in a terminal.`)}),i.job&&(0,h.jsx)(`p`,{children:r(`Last request ({time}): {outcome}`,{time:new Date(i.job.at).toLocaleString(),outcome:Ll(r,i.job)})})]}),i.unit&&(0,h.jsxs)(`section`,{className:`service-info`,children:[(0,h.jsx)(`h3`,{children:r(`Updates`)}),c===void 0||c===`failed`?(0,h.jsxs)(h.Fragment,{children:[c===`failed`&&(0,h.jsx)(`p`,{role:`alert`,children:r(`Update information is unavailable for this installation.`)}),(0,h.jsx)(`button`,{type:`button`,onClick:O,children:r(`Check for updates`)})]}):c===`checking`?(0,h.jsx)(`p`,{role:`status`,children:r(`Asking the package registry for the latest version…`)}):A?c.deprecated?(0,h.jsx)(`p`,{children:r(`{version} is deprecated on npm and is not offered.`,{version:c.version})}):On(i.upgrade)?(0,h.jsxs)(`button`,{type:`button`,className:`primary`,onClick:()=>d({action:`upgrade`,to:c.version}),children:[(0,h.jsx)(bi,{"aria-hidden":`true`}),r(`Upgrade to {version}`,{version:c.version})]}):(0,h.jsx)(`p`,{children:i.upgrade===`not-writable`?r(`{version} is available, but this account cannot write the installation; upgrade it in a terminal.`,{version:c.version}):r(`{version} is available, but this installation requires a manual update using its original installation method.`,{version:c.version})}):(0,h.jsx)(`p`,{children:r(`Cadence {version} is the latest version.`,{version:i.version})})]}),o&&(0,h.jsx)(`p`,{role:`alert`,children:b(r,o)})]}):(0,h.jsx)(`p`,{role:o?`alert`:`status`,children:o?b(r,o):r(`Reading the service…`)}),(0,h.jsx)(`footer`,{children:(0,h.jsxs)(`button`,{type:`button`,disabled:!i?.unit,onClick:()=>d({action:`restart`,to:null}),children:[(0,h.jsx)(Jr,{"aria-hidden":`true`}),r(`Restart service`)]})})]})}function Vl({ready:e,previewModels:t,model:n,onModelChoice:r,projects:i=[],restore:a=null,opening:o=null,onOpenFolder:s,onOpenProject:c,onOpenService:l,children:u,discovery:d}){let{t:p,locale:m,setLocale:g}=T(),[_,v]=(0,f.useState)(!1),y=Zo(null,{status:`not-started`},`home`,t),b=zc(),{mobile:x,overlay:S,closeDrawer:C}=b,w=(0,f.useRef)(null);Qc({enabled:x,open:S,onOpenChange:b.setDrawer,container:w}),Rc(w,S,!!S,C);let E=e=>{C(),s(e)},D=e=>{C(),c?c(e):s(e)},O=e=>e.split(/[\\/]/).filter(Boolean).at(-1)??e;return(0,h.jsxs)(`div`,{className:`app workbench-entry${b.className}`,children:[(0,h.jsxs)(`header`,{className:`topbar`,children:[(0,h.jsx)(`button`,{type:`button`,className:`panel-toggle navigation-toggle`,"aria-label":p(`Toggle conversation navigation`),"aria-expanded":x?S===`left`:b.navigation,onClick:()=>b.toggle(`left`),children:(0,h.jsx)(Qr,{"aria-hidden":`true`})}),(0,h.jsxs)(`div`,{className:`topbar-flow`,children:[(0,h.jsxs)(`span`,{className:`brand`,children:[(0,h.jsx)(`span`,{className:`brand-logo`,"aria-hidden":`true`,children:`C`}),(0,h.jsx)(`h1`,{className:`brand-name`,children:`Cadence`})]}),(0,h.jsx)(`span`,{className:`tb-spacer`}),(0,h.jsxs)(`div`,{className:`tb-actions`,children:[l&&(0,h.jsx)(`button`,{type:`button`,className:`chip`,"aria-label":p(`Cadence service`),"data-tip":p(`Cadence service`),onClick:l,children:(0,h.jsx)(Kr,{"aria-hidden":`true`})}),(0,h.jsxs)(`button`,{type:`button`,className:`chip chip-lang`,lang:m===`zh`?`en`:`zh-CN`,onClick:()=>g(m===`zh`?`en`:`zh`),"aria-label":m===`zh`?`Switch to English`:`切换到中文`,children:[(0,h.jsx)(ii,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{children:m===`zh`?`EN`:`中文`})]})]})]}),(0,h.jsxs)(`button`,{type:`button`,className:`panel-toggle has-label inspector-toggle`,"aria-label":p(`Toggle workspace panels`),"aria-expanded":x?S===`right`:b.inspector,onClick:()=>b.toggle(`right`),children:[(0,h.jsx)(Gr,{"aria-hidden":`true`}),(0,h.jsx)(`span`,{children:p(`Files`)})]})]}),u,(0,h.jsxs)(`div`,{className:`layout`,ref:w,style:{"--left-w":`${b.left}px`,"--right-w":`${b.right}px`},children:[(0,h.jsx)(`button`,{type:`button`,"aria-label":p(`Close drawer`),tabIndex:-1,className:`drawer-backdrop persistent${S?` on`:``}`,onClick:C}),(0,h.jsx)(`section`,{className:`panel-drawer drawer-left${S===`left`?` open`:``}`,"aria-label":p(`Conversation navigation`),tabIndex:-1,inert:x?S!==`left`:!b.navigation||S===`right`,children:(0,h.jsxs)(`aside`,{className:`panel panel-left lp-panel`,children:[d&&(0,h.jsx)(ho,{...d}),(0,h.jsxs)(`section`,{className:`lp-section grow`,children:[(0,h.jsx)(`header`,{className:`lp-section-header`,children:(0,h.jsx)(`span`,{className:`lp-section-title`,children:p(`Conversation history`)})}),(0,h.jsxs)(`div`,{className:`lp-section-body`,children:[(0,h.jsx)(`p`,{className:`panel-hint`,role:`status`,children:a?.status===`checking`?p(`Returning to your last project {name}…`,{name:O(a.path)}):a?.status===`unavailable`?p(`The retained conversations for {name} could not be observed. Choose a folder explicitly; nothing was started.`,{name:O(a.path)}):i.length?p(`Conversations stay with their folder. Select one to read its history; Send prepares execution.`):p(`Choose a working folder to see its conversation history.`)}),i.map(t=>(0,h.jsxs)(`button`,{type:`button`,className:`session-item project-item`,title:t,disabled:!e||!!o,"aria-busy":o===t,onClick:()=>D(t),children:[(0,h.jsx)(`span`,{className:`session-icon`,children:(0,h.jsx)(oi,{"aria-hidden":`true`})}),(0,h.jsxs)(`span`,{className:`session-info`,children:[(0,h.jsx)(`span`,{className:`session-title`,children:O(t)}),(0,h.jsx)(`span`,{className:`session-sub`,children:o===t?p(`Selecting folder…`):t})]})]},t))]})]})]})}),(0,h.jsx)(`main`,{className:`main`,inert:S!==null,children:(0,h.jsxs)(`section`,{className:`chat-workspace`,"aria-label":p(`Ordinary conversation`),children:[(0,h.jsx)(`div`,{className:`chat-messages`,children:(0,h.jsx)(Hs,{hint:p(`Choose a working folder. Execution is prepared only when you send.`),children:(0,h.jsxs)(`button`,{type:`button`,className:`primary welcome-action`,disabled:!e,onClick:()=>E(),children:[(0,h.jsx)(oi,{"aria-hidden":`true`}),p(`Choose a folder…`)]})})}),(0,h.jsxs)(`div`,{className:`chat-composer`,children:[(0,h.jsx)(`textarea`,{disabled:!0,"aria-label":p(`Message`),rows:3,placeholder:p(`Choose a working folder to start chatting.`)}),(0,h.jsxs)(`div`,{className:`composer-toolbar`,children:[(0,h.jsx)(ss,{scope:`next-conversation`,availability:{status:`not-started`},read:y,draftModel:n,onPreviewChoice:r,locked:!e,open:_,onOpenChange:e=>{e&&!y.preview&&!y.loading&&y.reread(),v(e)},onChanged:()=>{}}),(0,h.jsx)(`span`,{className:`composer-hint`,children:p(`Ordinary conversation`)}),(0,h.jsxs)(`button`,{type:`button`,className:`primary`,disabled:!0,children:[(0,h.jsx)(yi,{"aria-hidden":`true`}),p(`Send`)]})]})]})]})}),(0,h.jsx)(`section`,{className:`panel-drawer drawer-right${S===`right`?` open`:``}`,"aria-label":p(`Files`),tabIndex:-1,inert:x?S!==`right`:!b.inspector,children:(0,h.jsxs)(`aside`,{className:`panel files-panel`,children:[(0,h.jsxs)(`header`,{className:`files-toolbar`,children:[(0,h.jsx)(oi,{"aria-hidden":`true`}),p(`Files`)]}),(0,h.jsx)(`p`,{className:`panel-hint`,children:p(`Files appear here after you open a working folder.`)})]})})]}),(0,h.jsxs)(`footer`,{className:`statusbar`,children:[(0,h.jsx)(`div`,{className:`statusbar-left`,children:(0,h.jsx)(`span`,{className:`status-item faint`,children:p(`No working folder selected`)})}),(0,h.jsx)(`div`,{className:`statusbar-right`,children:(0,h.jsx)(Oc,{disabled:!e,onClick:()=>E()})})]})]})}function Hl(){let{t:e}=T(),[t,n]=(0,f.useState)(),[r,i]=(0,f.useState)(null),[a,o]=(0,f.useState)(),[s,c]=(0,f.useState)(Vi),l=(0,f.useCallback)(e=>ml(s??void 0,e),[s]),[u,d]=(0,f.useState)(null),[p,m]=(0,f.useState)(null),[g,_]=(0,f.useState)(``),[v,y]=(0,f.useState)(``),[b,x]=(0,f.useState)(0),[S,C]=(0,f.useState)(!1),[w,E]=(0,f.useState)(null),D=(0,f.useCallback)(()=>x(e=>e+1),[]),O=El(t?.epoch,D),k=(0,f.useRef)(null);(0,f.useEffect)(()=>()=>k.current?.abort(),[]);let M=(0,f.useRef)(new Map),N=(0,f.useRef)(!s),te=(0,f.useRef)(null),P=(0,f.useCallback)(()=>{te.current&&(te.current.abort(),te.current=null,E(null))},[]);(0,f.useEffect)(()=>{let e=new AbortController;return(async()=>{try{let t=await fetch(`/workbench/v1`,{credentials:`same-origin`,redirect:`error`,cache:`no-store`,signal:e.signal}),r=await Yi(t);t.status===400&&Xi(r)===`invalid`?n(null):t.ok?(n(bn(r)),y(``)):y(Xi(r))}catch{e.signal.aborted||y(`unavailable`)}})(),()=>e.abort()},[b]),(0,f.useEffect)(()=>{let e=()=>{k.current?.abort(),P(),E(null),c(Vi())};return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[P]),(0,f.useEffect)(()=>{if(!t||!N.current)return;N.current=!1;let e=fl(t);if(!e)return;let n=new AbortController;te.current=n,E({status:`checking`,path:e.cwd}),pl(e.id,n.signal).then(t=>{n.signal.aborted||(te.current=null,t?(history.replaceState(null,``,`/app?project=${e.id}`),E(null),c(e.id)):E({status:`unavailable`,path:e.cwd}))})},[t]);let F=(0,f.useCallback)((e,n)=>{P(),E(null),s&&history.state?.cadenceCwd===t?.projects.find(e=>e.id===s)?.cwd&&M.current.set(s,window.location.hash);let a=crypto.randomUUID();!s&&e&&!n&&r?(o({conversationId:a,model:r}),i(null)):o(void 0),history.pushState({cadenceCwd:n?.cwd??e?.cwd,cadenceConversationId:n?.sessionId},``,e?`/app?project=${e.id}${n?.sessionId?`#chat=${encodeURIComponent(n.sessionId)}&activity=1${n.leaf?`&leaf=${encodeURIComponent(n.leaf)}`:``}`:!s&&r?`#chat=${a}`:M.current.get(e.id)??`#chat=${a}`}`:`/app`),c(e?.id??null),d(null),window.dispatchEvent(new PopStateEvent(`popstate`))},[s,P,t,r]),I=(0,f.useCallback)(async e=>{k.current?.abort();let t=new AbortController;k.current=t;let r=await _l(e,t.signal);t.signal.aborted||(n(r.entry),F(r.project))},[F]),L=t?{value:O.value,error:O.error,opening:!!p,project:t.projects.find(e=>e.id===s)?.path,onOpen:(e,t)=>{k.current?.abort(),P();let r=new AbortController;k.current=r,m(t.cwd),_(``),yl(e,t,r.signal).then(e=>{r.signal.aborted||(n(e.entry),F(e.project,t))}).catch(e=>{r.signal.aborted||_(e instanceof Error?e.message:`unavailable`)}).finally(()=>{k.current===r&&m(null)})}}:void 0,R=async(e,r,i)=>{let a=t?.projects.find(e=>e.id===s);if(!a)throw Error(`unavailable`);let o=await vl(a,e,r,i);if(e.aborted)throw Error(`stale`);return n(o.entry),o.project.epoch},z=(0,f.useMemo)(()=>({async workbenchRead(e,t){try{if(e.kind!==`directories`)throw new j(`invalid`);let n=await fetch(`/workbench/v1/directories?path=${encodeURIComponent(e.path)}`,{credentials:`same-origin`,redirect:`error`,signal:t}),r=await Yi(n);if(!n.ok){let e=Xi(r);return{kind:`error`,error:ee(A.find(t=>t===e)??`unavailable`)}}return{kind:`ok`,value:Or(r)}}catch{return{kind:`error`,error:ee(`unavailable`)}}}}),[]),B=(0,f.useMemo)(()=>s?zi(s):void 0,[s]),V=t?.projects.find(e=>e.id===s);if((0,f.useEffect)(()=>{V&&dl(V.id)},[V]),t===null)return(0,h.jsx)(sl,{});let H=t&&S&&(0,h.jsx)(Bl,{epoch:t.epoch,csrf:t.csrf,onClose:()=>C(!1)}),U=()=>C(!0),ne=t&&u!==null&&(0,h.jsx)(yc,{selectOnly:!0,client:z,current:``,projects:t.projects.map(e=>({path:e.cwd,current:!1})),initial:u,home:t.home,epoch:t.epoch,onClose:()=>d(null),onOpen:I});return t&&V&&B?(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(sl,{api:B,project:V,previewModels:l,initialModel:a,directoryNamespaces:t?.projects.filter(e=>e.path===V.path).map(e=>e.id).sort(),discovery:L,onPrepareSend:R,onChooseFolder:e=>{k.current?.abort(),d(e??V.cwd)},onOpenProject:I,onWorkbenchHome:()=>F(null),workbenchHome:t.home,projectEntries:t.projects.map(e=>({path:e.cwd,current:e.id===s})),notices:(0,h.jsxs)(h.Fragment,{children:[` `,g&&(0,h.jsx)(`p`,{role:`alert`,children:g}),(0,h.jsx)(Ml,{notices:t.recoveries,project:V.path}),` `]}),onOpenService:U},V.id),H,ne]}):(0,h.jsxs)(h.Fragment,{children:[(0,h.jsxs)(Vl,{discovery:L,ready:!!t,previewModels:t?l:void 0,model:r,onModelChoice:e=>{P(),i(e)},projects:t?.projects.map(e=>e.cwd)??[],restore:w,opening:p,onOpenService:t?U:void 0,onOpenFolder:e=>{P(),_(``),k.current?.abort(),d(e??t?.home??``)},onOpenProject:t=>{p||(P(),_(``),m(t),I(t).catch(n=>_(e(`{path} could not be opened ({code}).`,{path:t,code:n instanceof Error?n.message:`unavailable`}))).finally(()=>m(null)))},children:[g&&(0,h.jsx)(`p`,{role:`alert`,className:`banner-notice`,children:g}),t&&(0,h.jsx)(Ml,{notices:t.recoveries}),v&&(0,h.jsxs)(`p`,{role:`alert`,className:`banner-notice`,children:[v,` `,(0,h.jsx)(`button`,{type:`button`,onClick:()=>x(e=>e+1),children:e(`Reload observation`)})]}),s&&!V&&t&&(0,h.jsx)(`p`,{role:`alert`,className:`banner-notice`,children:e(`Selected project is unavailable. Choose a project explicitly; no directory was reconstructed.`)})]}),ne,H]})}function Ul(){let{t:e}=T();return(0,h.jsxs)(`main`,{className:`entry`,children:[(0,h.jsx)(`h1`,{children:e(`Presentation unavailable`)}),(0,h.jsx)(`p`,{children:e(`No execution result is inferred. Reconnect to observe the owner; accepted work continues.`)}),(0,h.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),children:e(`Reload observation`)})]})}var Wl=class extends f.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?(0,h.jsx)(Ul,{}):this.props.children}},Gl=document.getElementById(`root`);if(!Gl)throw Error(`Application root unavailable`);(0,p.createRoot)(Gl).render((0,h.jsx)(E,{children:(0,h.jsx)(Wl,{children:(0,h.jsx)(Hl,{})})}));export{rl as t};