@rivet-dev/agentos 0.2.16-rc.1 → 0.2.16-rc.2
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.
- package/assets/inspector-tabs-app/assets/__vite-browser-external-2447137e-BIHI7g3E.js +1 -0
- package/assets/inspector-tabs-app/assets/filesystem-DQPPvVO9.js +1 -0
- package/assets/inspector-tabs-app/assets/hooks-CdZ_23e1.js +1 -0
- package/assets/inspector-tabs-app/assets/index-CvS46tYl.js +110 -0
- package/assets/inspector-tabs-app/assets/index-DG_s1YoH.css +1 -0
- package/assets/inspector-tabs-app/assets/scroll-area-D0TYc2jF.js +1 -0
- package/assets/inspector-tabs-app/assets/system-C1DTBU1d.js +2 -0
- package/assets/inspector-tabs-app/assets/terminal-DhW76lRS.js +13 -0
- package/assets/inspector-tabs-app/assets/transcript-OolSpSiF.js +1 -0
- package/assets/inspector-tabs-app/assets/{useSuspenseQuery-BXmNSEVQ.js → useSuspenseQuery-j2bgzu1R.js} +1 -1
- package/assets/inspector-tabs-app/assets/vm-boot-gate-DG5U7SkD.js +1 -0
- package/assets/inspector-tabs-app/assets/vm-status-badges-CKabwPpS.js +5 -0
- package/assets/inspector-tabs-app/index.html +2 -2
- package/dist/index.d.ts +45 -2
- package/dist/index.js +335 -18
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/assets/inspector-tabs-app/assets/filesystem-Ce_1E-AG.js +0 -1
- package/assets/inspector-tabs-app/assets/index-AMqbzdhN.js +0 -126
- package/assets/inspector-tabs-app/assets/index-tcfmhW06.css +0 -1
- package/assets/inspector-tabs-app/assets/system-AIh54aFR.js +0 -2
- package/assets/inspector-tabs-app/assets/transcript-D07sAUKE.js +0 -1
- package/assets/inspector-tabs-app/assets/vm-boot-gate-CzDOFOZU.js +0 -1
- package/assets/inspector-tabs-app/assets/vm-status-badges-CnUikLsX.js +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as f,u as te,r as l,l as ne,b as Y,c as re,m as oe,j as e,I as F,S as ae,P as ie,A as le,d as K,e as P,C as ce,f as de,g as H,h as U,i as W,k as ue,n as pe}from"./index-CvS46tYl.js";import{u as xe}from"./useSuspenseQuery-j2bgzu1R.js";import{S as G}from"./scroll-area-D0TYc2jF.js";import{V as me}from"./vm-status-badges-CKabwPpS.js";function fe({event:n}){var r,u;switch(n.kind){case"user":return e.jsx("div",{className:"flex justify-end",children:e.jsx("div",{className:"max-w-[80%] whitespace-pre-wrap rounded-2xl rounded-br-md bg-muted px-3.5 py-2 text-sm",children:n.text||"—"})});case"assistant":return e.jsx("div",{className:"flex",children:e.jsx("div",{className:"max-w-[85%] whitespace-pre-wrap text-sm leading-relaxed",children:n.text||"—"})});case"thinking":return e.jsx("div",{className:"flex",children:e.jsx("div",{className:"max-w-[85%] whitespace-pre-wrap text-xs italic leading-relaxed text-muted-foreground/70",children:n.text||"—"})});case"tool":{const a=n.input!==void 0||n.output!==void 0||!!((r=n.locations)!=null&&r.length),o=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-mono",children:n.tool}),n.status?e.jsx("span",{className:"rounded-full border px-1.5 py-px text-[10px]",children:n.status}):null]});return a?e.jsxs("details",{className:"group rounded-lg border border-foreground/10 bg-muted/20 text-xs text-muted-foreground",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-2 px-2.5 py-1.5 [&::-webkit-details-marker]:hidden",children:[e.jsx(W,{className:"size-3 shrink-0 transition-transform group-open:rotate-90"}),o]}),e.jsxs("div",{className:"flex flex-col gap-2 border-t border-foreground/10 px-2.5 py-2",children:[n.input!==void 0?e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 text-[10px] text-muted-foreground/70",children:"Input"}),e.jsx("pre",{className:"max-h-40 overflow-y-auto whitespace-pre-wrap break-words rounded bg-muted/50 p-2 font-mono text-[11px] leading-relaxed",children:JSON.stringify(n.input,null,2)})]}):null,n.output!==void 0?e.jsxs("div",{children:[e.jsx("div",{className:"mb-1 text-[10px] text-muted-foreground/70",children:"Output"}),e.jsx("pre",{className:"max-h-48 overflow-y-auto whitespace-pre-wrap break-words rounded bg-muted/50 p-2 font-mono text-[11px] leading-relaxed",children:n.output})]}):null,(u=n.locations)!=null&&u.length?e.jsx("div",{className:"font-mono text-[11px] text-muted-foreground/70",children:n.locations.join(" ")}):null]})]}):e.jsx("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:o})}case"plan":return e.jsxs("div",{className:"rounded-lg border border-foreground/10 bg-muted/20 px-2.5 py-2 text-xs text-muted-foreground",children:[e.jsx("div",{className:"mb-1 text-[10px] text-muted-foreground/70",children:"Plan"}),e.jsx("ul",{className:"flex flex-col gap-1",children:n.entries.map((a,o)=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx(P,{color:a.status==="completed"?"green":a.status==="in_progress"?"amber":"muted",className:"mt-1"}),e.jsx("span",{className:H("min-w-0 flex-1",a.status==="completed"&&"text-muted-foreground/60 line-through"),children:a.content})]},`${o}-${a.content.slice(0,24)}`))})]});case"notice":return e.jsx("div",{className:"text-center text-[11px] text-muted-foreground/60",children:n.text});case"permission":return e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-amber-500/30 bg-amber-500/5 px-2.5 py-1.5 text-xs text-amber-500/90",children:[e.jsx(P,{color:"amber",className:"size-1.5"}),n.text]});case"error":return e.jsx("div",{className:"whitespace-pre-wrap text-sm text-destructive",children:n.text});default:return e.jsxs("details",{className:"group text-xs text-muted-foreground/70",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-center gap-1.5 [&::-webkit-details-marker]:hidden",children:[e.jsx(W,{className:"size-3 shrink-0 transition-transform group-open:rotate-90"}),e.jsx("span",{className:"font-mono",children:n.label})]}),e.jsx("pre",{className:"mt-1.5 max-h-48 overflow-y-auto whitespace-pre-wrap break-words rounded bg-muted/50 p-2 font-mono text-[11px] leading-relaxed",children:JSON.stringify(n.json,null,2)})]})}}function he({count:n}){const r=l.useRef(null),u=l.useRef(!0);return l.useEffect(()=>{const a=r.current,o=a==null?void 0:a.closest("[data-radix-scroll-area-viewport]");if(!a||!o)return;const c=new IntersectionObserver(([x])=>{u.current=x.isIntersecting},{root:o,rootMargin:"0px 0px 96px 0px"});return c.observe(a),()=>c.disconnect()},[]),l.useEffect(()=>{var a;u.current&&((a=r.current)==null||a.scrollIntoView({block:"end"}))},[n]),e.jsx("div",{ref:r,className:"h-px"})}function ge(n){const r=[],u=new Map;let a=null;for(const o of n){const c=r[r.length-1];if((o.kind==="user"||o.kind==="assistant"||o.kind==="thinking")&&(c==null?void 0:c.kind)===o.kind){r[r.length-1]={...c,text:c.text+o.text};continue}if(o.kind==="tool"&&o.toolCallId){const x=u.get(o.toolCallId);if(x!==void 0){const p=r[x];r[x]={...p,tool:o.tool!==o.toolCallId?o.tool:p.tool,status:o.status??p.status,input:o.input??p.input,output:o.output??p.output,locations:o.locations??p.locations};continue}u.set(o.toolCallId,r.length)}if(o.kind==="plan"){if(a!==null){r[a]={...r[a],entries:o.entries};continue}a=r.length}r.push(o)}return r}function ye(){return e.jsx("div",{className:"flex items-center gap-1 px-1 py-0.5","aria-label":"Turn in progress",children:[0,1,2].map(n=>e.jsx("span",{className:"size-1.5 animate-pulse rounded-full bg-muted-foreground/50",style:{animationDelay:`${n*200}ms`}},n))})}const D="agentos-inspector:composer-agent-type",L="agentos-inspector:composer-env",J=n=>`agentos-inspector:transcript:${n}`,X=JSON.stringify({ANTHROPIC_API_KEY:"",OPENCODE_CONFIG_CONTENT:JSON.stringify({model:"anthropic/claude-haiku-4-5-20251001"})},null,2);function ve(){const n=(localStorage.getItem(D)??"opencode").trim()||"opencode",r=localStorage.getItem(L)??X;let u;try{u=JSON.parse(r)}catch(a){throw new Error(`Session env is not valid JSON: ${a.message}`)}return{agentType:n,env:u}}function Ne({actorId:n,sessionId:r,sessionStatus:u,onSessionCreated:a,onErrorEvent:o,onBusyChange:c}){const[x,p]=l.useState(""),[g,R]=l.useState(!1),S=i=>{R(i),c==null||c(i)},[v,N]=l.useState(!1),[j,k]=l.useState(!1),[C,O]=l.useState(()=>localStorage.getItem(D)??"opencode"),[b,A]=l.useState(()=>localStorage.getItem(L)??X),E=l.useRef(null),T=(Y({...f.softwareQueryOptions(n),enabled:j}).data??[]).filter(i=>i.name.endsWith("· agent")).map(i=>{var d;return((d=i.name.split(" · ")[0])==null?void 0:d.split("/").pop())??""}).filter(Boolean),w=async()=>{const i=x.trim();if(!(!i||g)){S(!0),p("");try{let d=r;if(!d){let h;try{h=JSON.parse(b)}catch(_){throw new Error(`Session env is not valid JSON: ${_.message}`)}d=await f.createSession(C.trim()||"opencode",{env:h}),a(d)}E.current=d,await f.sendPrompt(d,i)}catch(d){let h=ue(d)?` — ${d.hint}`:"";r&&u!=="running"&&(h=" — this session is idle (not live in the current VM boot). Send without a selection to start a fresh session, or resume it from a client."),o(`${d instanceof Error?d.message:String(d)}${h}`)}finally{E.current=null,S(!1)}}},I=async()=>{const i=E.current??r;if(i)try{await pe(i)||(N(!0),o("Stop is not supported by this runtime (no cancelPrompt action)."))}catch(d){o(d instanceof Error?d.message:String(d))}};return e.jsx("div",{className:"shrink-0",children:e.jsxs("div",{className:"mx-auto w-full max-w-3xl px-3 pb-3",children:[j&&!r?e.jsxs("div",{className:"mb-2 flex flex-col gap-2 rounded-xl border bg-muted/30 p-3 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-24 shrink-0 text-muted-foreground",children:"Agent type"}),e.jsx("input",{value:C,onChange:i=>{O(i.target.value),localStorage.setItem(D,i.target.value)},list:"agentos-composer-agent-types",className:"flex-1 rounded border bg-background px-2 py-1 font-mono"}),e.jsx("datalist",{id:"agentos-composer-agent-types",children:T.map(i=>e.jsx("option",{value:i},i))})]}),e.jsxs("label",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"w-24 shrink-0 pt-1 text-muted-foreground",children:"Session env"}),e.jsx("textarea",{value:b,onChange:i=>{A(i.target.value),localStorage.setItem(L,i.target.value)},rows:4,spellCheck:!1,className:"flex-1 resize-y rounded border bg-background px-2 py-1 font-mono"})]}),e.jsx("div",{className:"text-muted-foreground/70",children:"Used when sending without a session: creates one with these options. Values stay in this browser."})]}):null,e.jsxs("div",{className:"rounded-2xl border bg-muted/40 transition-colors focus-within:border-ring/60",children:[e.jsx("textarea",{value:x,onChange:i=>p(i.target.value),onKeyDown:i=>{i.key==="Enter"&&!i.shiftKey&&(i.preventDefault(),w())},placeholder:r?"Prompt this session…":"Prompt a new session…",rows:2,className:"max-h-48 min-h-[3.25rem] w-full resize-none bg-transparent px-4 pt-3 text-sm placeholder:text-muted-foreground/50 focus:outline-none"}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2.5",children:[r?null:e.jsxs("button",{type:"button",onClick:()=>k(i=>!i),title:"New-session options (agent, env)",className:"inline-flex items-center gap-1 rounded px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:[e.jsx("span",{"aria-hidden":"true",className:"text-sm leading-none",children:"+"}),"Options"]}),e.jsx("span",{className:"ml-auto"}),g?e.jsx("button",{type:"button",onClick:()=>void I(),disabled:v,title:v?"This runtime has no cancelPrompt action":"Stop the running turn",className:"inline-flex size-8 items-center justify-center rounded-md bg-foreground/90 text-background transition-opacity hover:opacity-80 disabled:opacity-40",children:e.jsx("span",{"aria-hidden":"true",className:"block size-2.5 rounded-[2px] bg-current"})}):e.jsx("button",{type:"button",onClick:()=>void w(),disabled:!x.trim(),title:"Send (⏎)",className:"inline-flex size-8 items-center justify-center rounded-md bg-primary text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-40",children:e.jsx("svg",{viewBox:"0 0 16 16",className:"size-4",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M8 13V3M4 7l4-4 4 4"})})})]})]})]})})}function Ce({actorId:n}){var V;const{data:r}=xe(f.sessionsQueryOptions(n)),u=te(),[a,o]=l.useState(()=>{try{const s=sessionStorage.getItem(J(n));if(!s)return;const t=JSON.parse(s);return t.selected===null||typeof t.selected=="string"?t.selected:void 0}catch{return}});l.useEffect(()=>{try{a===void 0?sessionStorage.removeItem(J(n)):sessionStorage.setItem(J(n),JSON.stringify({selected:a}))}catch(s){console.warn("agentos inspector: failed to persist transcript state",s)}},[n,a]);const c=a===void 0||typeof a=="string"&&!r.some(s=>s.sessionId===a)?((V=r[0])==null?void 0:V.sessionId)??null:a,x=l.useMemo(()=>ne(r),[r]),p=s=>x.has(s.sessionId),{data:g=[]}=Y(f.transcriptQueryOptions(n,c)),S=re().useEvent,[v,N]=l.useState([]),j=l.useRef(0),k=l.useRef(c);k.current=c,l.useEffect(()=>{N([])},[c]),S("sessionEvent",s=>{const t=s,y=k.current;if(!y||!(t!=null&&t.sessionId)||t.sessionId!==y)return;let m=oe(t);t.type==="permission_request"&&m.kind==="permission"&&(m={...m,text:`${m.text} (answer in the banner above)`});const q=j.current++;N(B=>{if(t.durability==="durable"){const se=t.type==="agent_message_chunk"||t.type==="agent_thought_chunk";return[...B.filter($=>$.seq!==m.seq&&!(se&&$.kind===m.kind&&!Number.isInteger($.seq)&&$.seq<m.seq)),{...m,liveKey:q}]}return[...B,{...m,liveKey:q}]})}),S("agentExit",s=>{const t=s,y=k.current;if(!y||(t==null?void 0:t.sessionId)!==y)return;const m=j.current++;N(q=>[...q,{kind:"error",seq:-1-m,liveKey:m,text:`Agent crashed (exit ${t.exitCode??"?"}) — restart: ${t.restart}${t.restartCount?` (attempt ${t.restartCount})`:""}`}])});const C=s=>{const t=j.current++;N(y=>[...y,{kind:"error",seq:-1-t,liveKey:t,text:s}])},O=s=>{o(s),u.invalidateQueries({queryKey:f.sessionsQueryOptions(n).queryKey})},[b,A]=l.useState(!1),[E,z]=l.useState(!1),[T,w]=l.useState(""),I=T.trim().toLowerCase(),i=I?r.filter(s=>s.sessionId.toLowerCase().includes(I)||s.agent.toLowerCase().includes(I)):r,[d,h]=l.useState(null),_=async()=>{if(!b){A(!0),h(null);try{const{agentType:s,env:t}=ve();O(await f.createSession(s,{env:t}))}catch(s){h(s)}finally{A(!1)}}},[M,Z]=l.useState(!1),ee=async s=>{try{await f.closeSession(s)}catch(t){C(t instanceof Error?t.message:String(t))}o(void 0),u.invalidateQueries({queryKey:f.sessionsQueryOptions(n).queryKey})},Q=l.useMemo(()=>{const s=new Set(g.map(t=>t.seq));return ge([...g.map(t=>({...t,key:`b-${t.seq}`})),...v.filter(t=>!s.has(t.seq)).map(t=>({...t,key:`l-${t.liveKey}`}))])},[g,v]);return e.jsxs("div",{className:"flex h-full min-h-0",children:[e.jsxs("div",{className:"flex h-full w-64 shrink-0 flex-col border-r",children:[e.jsxs("div",{className:"flex items-center px-3 pb-1 pt-2.5",children:[e.jsxs("span",{className:"text-[11px] font-medium text-muted-foreground",children:["Sessions",x.size>0?` · ${x.size} live`:""]}),e.jsx("span",{className:"ml-auto"}),e.jsx(F,{title:"Search sessions by id",onClick:()=>z(s=>(s&&w(""),!s)),className:"mr-1",children:e.jsx(ae,{className:"size-3.5"})}),e.jsx(F,{title:b?"Creating session…":"New session",onClick:()=>void _(),disabled:b,children:e.jsx(ie,{className:"size-3.5"})})]}),E?e.jsx("div",{className:"px-3 pb-1.5",children:e.jsx("input",{value:T,onChange:s=>w(s.target.value),onKeyDown:s=>{s.key==="Escape"&&(w(""),z(!1))},spellCheck:!1,autoFocus:!0,"aria-label":"Search sessions",placeholder:"session id or agent",className:"w-full rounded border bg-background px-2 py-1 font-mono text-xs focus:outline-none"})}):null,d?e.jsx(le,{error:d,className:"border-b py-2"}):null,r.length===0?e.jsx(K,{children:"No sessions yet."}):e.jsx(G,{className:"min-h-0 flex-1",children:e.jsxs("div",{className:"p-1.5",children:[i.length===0?e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:"No sessions match."}):null,i.map(s=>e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>o(s.sessionId),onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&o(s.sessionId)},className:H("group flex w-full cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-left",s.sessionId===c?"bg-muted":"hover:bg-muted/50"),children:[e.jsx(P,{color:p(s)?"green":"muted"}),e.jsxs("div",{className:"min-w-0 flex-1",title:p(s)?"Live in the current VM":"Idle — persisted, not loaded in the current VM",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[e.jsxs("span",{className:"truncate font-mono",children:["…",s.sessionId.slice(-12)]}),e.jsx(ce,{value:s.sessionId,className:"opacity-0 focus:opacity-100 group-hover:opacity-100"})]}),e.jsxs("div",{className:"truncate text-[10px] text-muted-foreground/60",children:[s.agent," · ",de(Date.parse(s.createdAt))]})]}),p(s)?e.jsx("button",{type:"button",onClick:t=>{t.stopPropagation(),ee(s.sessionId)},title:"End the live agent process; the transcript stays","aria-label":"Close session",className:"text-muted-foreground/40 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 group-hover:opacity-100",children:e.jsx("svg",{viewBox:"0 0 12 12",className:"size-2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M3 3l6 6M9 3l-6 6"})})}):null]},s.sessionId))]})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsx("div",{className:"absolute right-3 top-2 z-10",children:e.jsx(me,{actorId:n})}),c?e.jsx(e.Fragment,{children:Q.length===0&&!M?e.jsx(K,{children:e.jsxs("div",{className:"flex flex-col items-center gap-5",children:[e.jsx(U,{className:"w-44"}),e.jsx("span",{children:"No activity yet — send a prompt below."})]})}):e.jsx(G,{className:"min-h-0 flex-1",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-3xl flex-col gap-3 px-4 py-4",children:[Q.map(s=>e.jsx(fe,{event:s},s.key)),M?e.jsx(ye,{}):null,e.jsx(he,{count:g.length+v.length})]})})}):e.jsx(K,{children:e.jsxs("div",{className:"flex flex-col items-center gap-5",children:[e.jsx(U,{className:"w-44"}),e.jsx("span",{children:"No session selected — press + or send a prompt below to start one."})]})}),e.jsx(Ne,{actorId:n,sessionId:c,sessionStatus:c?(()=>{const s=r.find(t=>t.sessionId===c);return s&&p(s)?"running":"idle"})():void 0,onSessionCreated:O,onErrorEvent:C,onBusyChange:Z})]})]})}export{Ce as TranscriptTabConnected};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Y as r,Q as u,N as s}from"./index-
|
|
1
|
+
import{Y as r,Q as u,N as s}from"./index-CvS46tYl.js";function t(e,a){return r({...e,enabled:!0,suspense:!0,throwOnError:s,placeholderData:void 0},u)}export{t as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var K=e=>{throw TypeError(e)};var E=(e,t,s)=>t.has(e)||K("Cannot "+s);var r=(e,t,s)=>(E(e,t,"read from private field"),s?s.call(e):t.get(e)),y=(e,t,s)=>t.has(e)?K("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),f=(e,t,s,i)=>(E(e,t,"write to private field"),i?i.call(e,s):t.set(e,s),s),v=(e,t,s)=>(E(e,t,"access private method"),s);import{v as A,x as N,a0 as R,a1 as Q,w as k,u as U,r as x,J as q,a2 as L,b as V,a3 as B,j as m,d as D,h as F}from"./index-CvS46tYl.js";var n,l,o,h,u,C,M,P,G=(P=class extends A{constructor(t,s){super();y(this,u);y(this,n);y(this,l);y(this,o);y(this,h);f(this,n,t),this.setOptions(s),this.bindMethods(),v(this,u,C).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var i;const s=this.options;this.options=r(this,n).defaultMutationOptions(t),N(this.options,s)||r(this,n).getMutationCache().notify({type:"observerOptionsUpdated",mutation:r(this,o),observer:this}),s!=null&&s.mutationKey&&this.options.mutationKey&&R(s.mutationKey)!==R(this.options.mutationKey)?this.reset():((i=r(this,o))==null?void 0:i.state.status)==="pending"&&r(this,o).setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=r(this,o))==null||t.removeObserver(this)}onMutationUpdate(t){v(this,u,C).call(this),v(this,u,M).call(this,t)}getCurrentResult(){return r(this,l)}reset(){var t;(t=r(this,o))==null||t.removeObserver(this),f(this,o,void 0),v(this,u,C).call(this),v(this,u,M).call(this)}mutate(t,s){var i;return f(this,h,s),(i=r(this,o))==null||i.removeObserver(this),f(this,o,r(this,n).getMutationCache().build(r(this,n),this.options)),r(this,o).addObserver(this),r(this,o).execute(t)}},n=new WeakMap,l=new WeakMap,o=new WeakMap,h=new WeakMap,u=new WeakSet,C=function(){var s;const t=((s=r(this,o))==null?void 0:s.state)??Q();f(this,l,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},M=function(t){k.batch(()=>{var s,i,a,p,c,g,S,w;if(r(this,h)&&this.hasListeners()){const b=r(this,l).variables,O=r(this,l).context,j={client:r(this,n),meta:this.options.meta,mutationKey:this.options.mutationKey};if((t==null?void 0:t.type)==="success"){try{(i=(s=r(this,h)).onSuccess)==null||i.call(s,t.data,b,O,j)}catch(d){Promise.reject(d)}try{(p=(a=r(this,h)).onSettled)==null||p.call(a,t.data,null,b,O,j)}catch(d){Promise.reject(d)}}else if((t==null?void 0:t.type)==="error"){try{(g=(c=r(this,h)).onError)==null||g.call(c,t.error,b,O,j)}catch(d){Promise.reject(d)}try{(w=(S=r(this,h)).onSettled)==null||w.call(S,void 0,t.error,b,O,j)}catch(d){Promise.reject(d)}}}this.listeners.forEach(b=>{b(r(this,l))})})},P);function T(e,t){const s=U(),[i]=x.useState(()=>new G(s,e));x.useEffect(()=>{i.setOptions(e)},[i,e]);const a=x.useSyncExternalStore(x.useCallback(c=>i.subscribe(k.batchCalls(c)),[i]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),p=x.useCallback((c,g)=>{i.mutate(c,g).catch(q)},[i]);if(a.error&&L(i.options.throwOnError,[a.error]))throw a.error;return{...a,mutate:p,mutateAsync:a.mutate}}function W({actorId:e,note:t,actionLabel:s,children:i}){const a=V(B(e)),[p,c]=x.useState(!1);return a.data&&!a.data.booted&&!p?m.jsx(D,{children:m.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[m.jsx(F,{className:"mb-3 w-44"}),m.jsx("span",{children:t}),m.jsx("button",{type:"button",onClick:()=>c(!0),className:"rounded-md border px-2.5 py-1 text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:s})]})}):m.jsx(m.Fragment,{children:i})}export{W as V,T as u};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{k as h,b,a3 as j,r as x,c as v,j as t,e as $,g as N,i as w,C as d,f as g}from"./index-CvS46tYl.js";function k(s){return h(s)&&s.layer==="contract"}function C(s,r){if((r==null?void 0:r.kind)==="shutdown"){const a=r.reason??"unknown";return a==="error"?{tone:"red",label:"VM shut down after an error"}:{tone:"muted",label:`VM shut down (${a})`}}return s?s.sidecar&&s.sidecar.state!=="ready"?{tone:"red",label:`sidecar ${s.sidecar.state}`}:!s.booted&&(r==null?void 0:r.kind)!=="booted"?{tone:"muted",label:"VM not booted"}:null:null}function S({actorId:s,align:r="right"}){const a=b(j(s)),[p,c]=x.useState(null),[u,f]=x.useState(!1),m=v().useEvent;if(m("vmBooted",()=>{c({kind:"booted"}),a.refetch()}),m("vmShutdown",e=>{c({kind:"shutdown",reason:e==null?void 0:e.reason}),a.refetch()}),a.error&&k(a.error))return null;const n=a.data,o=a.error?{tone:"muted",label:"health unavailable"}:C(n,p),i=((n==null?void 0:n.warnings.length)??0)+((n==null?void 0:n.agentExits.length)??0);return!o&&i===0?null:t.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 text-xs",children:[o?t.jsxs("span",{className:N("inline-flex items-center gap-1.5 rounded border px-2 py-0.5 text-[11px]",o.tone==="red"?"border-destructive/40 text-destructive":"border-foreground/15 text-muted-foreground"),children:[t.jsx($,{color:o.tone==="red"?"red":"muted"}),o.label]}):null,i>0?t.jsxs("span",{className:"relative",children:[t.jsxs("button",{type:"button",onClick:()=>f(e=>!e),className:"inline-flex items-center gap-1 rounded border border-amber-500/40 px-2 py-0.5 text-[11px] text-amber-500 transition-colors hover:bg-amber-500/10",children:[i," warning",i===1?"":"s",t.jsx(w,{className:`size-2.5 transition-transform ${u?"rotate-90":""}`})]}),u&&n?t.jsxs("div",{className:`absolute top-full z-20 mt-1 max-h-64 w-80 overflow-y-auto rounded-md border bg-background p-2 text-[11px] leading-relaxed shadow-lg ${r==="right"?"right-0":"left-0"}`,children:[n.warnings.length>0?t.jsxs("div",{className:"mb-2",children:[t.jsxs("div",{className:"mb-1 flex items-center gap-1 font-medium text-muted-foreground",children:["Limit warnings",t.jsx(d,{value:n.warnings.map(e=>`${new Date(e.ts).toISOString()} ${e.limit} ${e.observed}/${e.capacity} · ${e.fillPercent}%`).join(`
|
|
2
|
+
`)})]}),n.warnings.map((e,l)=>t.jsxs("div",{className:"flex items-center gap-2 font-mono",children:[t.jsxs("span",{children:[e.limit," ",e.observed,"/",e.capacity," · ",e.fillPercent,"%"]}),t.jsx("span",{className:"ml-auto text-muted-foreground",children:g(e.ts)})]},`w-${l}`))]}):null,n.agentExits.length>0?t.jsxs("div",{className:"mb-2",children:[t.jsxs("div",{className:"mb-1 flex items-center gap-1 font-medium text-muted-foreground",children:["Agent exits",t.jsx(d,{value:n.agentExits.map(e=>`${new Date(e.ts).toISOString()} ${e.agentType} session=${e.sessionId} exit=${e.exitCode??"?"} restart=${e.restart} (${e.restartCount})`).join(`
|
|
3
|
+
`)})]}),n.agentExits.map((e,l)=>t.jsxs("div",{className:"flex items-center gap-2 font-mono",children:[t.jsxs("span",{children:[e.agentType," exit ",e.exitCode??"?"," · ",e.restart," (",e.restartCount,")"]}),t.jsx("span",{className:"ml-auto text-muted-foreground",children:g(e.ts)})]},`e-${l}`))]}):null,n.stderrTail.length>0?t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1 flex items-center gap-1 font-medium text-muted-foreground",children:["Adapter stderr (tail)",t.jsx(d,{value:n.stderrTail.map(e=>e.line).join(`
|
|
4
|
+
`)})]}),t.jsx("pre",{className:"whitespace-pre-wrap break-words font-mono text-muted-foreground",children:n.stderrTail.map(e=>e.line).join(`
|
|
5
|
+
`)})]}):null]}):null]}):null]})}export{S as V};
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
<meta charset="utf-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>agentOS inspector</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
8
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-CvS46tYl.js"></script>
|
|
8
|
+
<link rel="stylesheet" crossorigin href="./assets/index-DG_s1YoH.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
11
11
|
<div id="root"></div>
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,11 @@ interface VmShutdownPayload {
|
|
|
13
13
|
}
|
|
14
14
|
type ProcessOutputPayload = ProcessOutput;
|
|
15
15
|
type ProcessExitPayload = ProcessExit;
|
|
16
|
-
|
|
16
|
+
/** `seq` orders this chunk against `ShellSnapshot.seq`; it is 0 when the shell
|
|
17
|
+
* has no server-side emulator and therefore no replay. */
|
|
18
|
+
type ShellDataPayload = ShellData & {
|
|
19
|
+
seq: number;
|
|
20
|
+
};
|
|
17
21
|
type ShellExitPayload = ShellExit;
|
|
18
22
|
type SerializableCronEvent = CronEvent;
|
|
19
23
|
type ActorData = {
|
|
@@ -115,6 +119,41 @@ interface RuntimeHealth {
|
|
|
115
119
|
agentExits: RuntimeAgentExit[];
|
|
116
120
|
stderrTail: RuntimeStderrLine[];
|
|
117
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* One live shell from the observe-only `listShells` action. A shell outlives
|
|
124
|
+
* the page that opened it and keeps the VM awake until closed, so enumeration
|
|
125
|
+
* is server-owned rather than tracked per client.
|
|
126
|
+
*/
|
|
127
|
+
interface ShellInfo {
|
|
128
|
+
shellId: string;
|
|
129
|
+
/** Epoch ms when the shell was opened through this actor. */
|
|
130
|
+
openedAt: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* How much of a shell's history a snapshot repaints.
|
|
134
|
+
*
|
|
135
|
+
* - `none` — sequence number only; the caller repaints nothing.
|
|
136
|
+
* - `screen` — the visible viewport, cursor, and terminal modes.
|
|
137
|
+
* - `scrollback` — the retained scrollback above the viewport, then `screen`.
|
|
138
|
+
*/
|
|
139
|
+
type ShellReplayMode = "none" | "screen" | "scrollback";
|
|
140
|
+
/**
|
|
141
|
+
* Server-rendered repaint for a shell that is already running. `data` is an
|
|
142
|
+
* ANSI stream to write verbatim into a fresh terminal.
|
|
143
|
+
*/
|
|
144
|
+
interface ShellSnapshot {
|
|
145
|
+
shellId: string;
|
|
146
|
+
mode: ShellReplayMode;
|
|
147
|
+
/**
|
|
148
|
+
* Sequence of the last `shellData` chunk folded into this snapshot.
|
|
149
|
+
* Broadcasts carry the same counter, so a client applies the snapshot and
|
|
150
|
+
* then only the chunks whose `seq` is greater — no gap, no double-render.
|
|
151
|
+
*/
|
|
152
|
+
seq: number;
|
|
153
|
+
cols: number;
|
|
154
|
+
rows: number;
|
|
155
|
+
data: string;
|
|
156
|
+
}
|
|
118
157
|
type SerializableCronAction = {
|
|
119
158
|
type: "session";
|
|
120
159
|
agentType: string;
|
|
@@ -200,6 +239,8 @@ declare function createAgentOsActions(options?: AgentOsOptions, hooks?: AgentOsE
|
|
|
200
239
|
openShell: (c: AnyContext, options?: _rivet_dev_agentos_core.ShellOptions | undefined) => Promise<{
|
|
201
240
|
shellId: string;
|
|
202
241
|
}>;
|
|
242
|
+
listShells: (c: AnyContext) => Promise<ShellInfo[]>;
|
|
243
|
+
shellSnapshot: (c: AnyContext, shellId: string, mode?: ShellReplayMode) => Promise<ShellSnapshot | null>;
|
|
203
244
|
writeShell: (c: AnyContext, shellId: string, data: string | Uint8Array<ArrayBufferLike>) => Promise<void>;
|
|
204
245
|
resizeShell: (c: AnyContext, shellId: string, cols: number, rows: number) => Promise<void>;
|
|
205
246
|
closeShell: (c: AnyContext, shellId: string) => Promise<void>;
|
|
@@ -320,6 +361,8 @@ declare function createAgentOsActions(options?: AgentOsOptions, hooks?: AgentOsE
|
|
|
320
361
|
open: (c: AnyContext, options?: _rivet_dev_agentos_core.ShellOptions | undefined) => Promise<{
|
|
321
362
|
shellId: string;
|
|
322
363
|
}>;
|
|
364
|
+
list: (c: AnyContext) => Promise<ShellInfo[]>;
|
|
365
|
+
snapshot: (c: AnyContext, shellId: string, mode?: ShellReplayMode) => Promise<ShellSnapshot | null>;
|
|
323
366
|
write: (c: AnyContext, shellId: string, data: string | Uint8Array<ArrayBufferLike>) => Promise<void>;
|
|
324
367
|
resize: (c: AnyContext, shellId: string, cols: number, rows: number) => Promise<void>;
|
|
325
368
|
wait: (c: AnyContext, shellId: string) => Promise<number>;
|
|
@@ -419,4 +462,4 @@ declare function createAgentOS<TState = undefined, TConnParams = undefined, TCon
|
|
|
419
462
|
*/
|
|
420
463
|
declare const setup: typeof setup$1;
|
|
421
464
|
|
|
422
|
-
export { type ActorData, type ActorLanguageSpawnOptions, type ActorSpawnOptions, type AgentOsActorConfigInput as AgentOSActorConfigInput, type AgentOsActorConfigInput as AgentOSConfigInput, type AgentOsActions, type AgentOsActorConfigInput, type AgentOsActorExtras, type AgentOsEventHooks, type AgentOsEvents, type ProcessExitPayload, type ProcessOutputPayload, type RuntimeAgentExit, type RuntimeHealth, type RuntimeLimitWarning, type RuntimeSidecarInfo, type RuntimeStderrLine, type SerializableCronAction, type SerializableCronEvent, type SerializableCronJobInfo, type SerializableCronJobOptions, type ShellDataPayload, type ShellExitPayload, type VmBootedPayload, type VmFetchOptions, type VmFetchResponse, type VmFetchStreamChunk, type VmFetchStreamHead, type VmShutdownPayload, createAgentOS as agentOS, createAgentOS, createAgentOsActions, setup };
|
|
465
|
+
export { type ActorData, type ActorLanguageSpawnOptions, type ActorSpawnOptions, type AgentOsActorConfigInput as AgentOSActorConfigInput, type AgentOsActorConfigInput as AgentOSConfigInput, type AgentOsActions, type AgentOsActorConfigInput, type AgentOsActorExtras, type AgentOsEventHooks, type AgentOsEvents, type ProcessExitPayload, type ProcessOutputPayload, type RuntimeAgentExit, type RuntimeHealth, type RuntimeLimitWarning, type RuntimeSidecarInfo, type RuntimeStderrLine, type SerializableCronAction, type SerializableCronEvent, type SerializableCronJobInfo, type SerializableCronJobOptions, type ShellDataPayload, type ShellExitPayload, type ShellInfo, type ShellReplayMode, type ShellSnapshot, type VmBootedPayload, type VmFetchOptions, type VmFetchResponse, type VmFetchStreamChunk, type VmFetchStreamHead, type VmShutdownPayload, createAgentOS as agentOS, createAgentOS, createAgentOsActions, setup };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
__publicField
|
|
3
|
+
} from "./chunk-V6TY7KAL.js";
|
|
2
4
|
|
|
3
5
|
// src/index.ts
|
|
4
6
|
import { setup as rivetkitSetup } from "rivetkit";
|
|
@@ -18,6 +20,270 @@ import {
|
|
|
18
20
|
} from "rivetkit";
|
|
19
21
|
import { db } from "rivetkit/db";
|
|
20
22
|
import { migrations } from "rivetkit/unstable/migrations";
|
|
23
|
+
|
|
24
|
+
// src/shell-replay.ts
|
|
25
|
+
import { readFile } from "fs/promises";
|
|
26
|
+
import { createRequire } from "module";
|
|
27
|
+
var MAX_REPLAY_SHELLS = 32;
|
|
28
|
+
var MAX_SCROLLBACK_LINES = 1e3;
|
|
29
|
+
var MAX_COLS = 1e3;
|
|
30
|
+
var MAX_ROWS = 1e3;
|
|
31
|
+
var DEFAULT_COLS = 80;
|
|
32
|
+
var DEFAULT_ROWS = 24;
|
|
33
|
+
var ghosttyPromise;
|
|
34
|
+
async function loadGhostty() {
|
|
35
|
+
ghosttyPromise ?? (ghosttyPromise = (async () => {
|
|
36
|
+
const require2 = createRequire(import.meta.url);
|
|
37
|
+
const { Ghostty } = await import("ghostty-web");
|
|
38
|
+
const bytes = await readFile(
|
|
39
|
+
require2.resolve("ghostty-web/ghostty-vt.wasm")
|
|
40
|
+
);
|
|
41
|
+
const { instance } = await WebAssembly.instantiate(bytes, {
|
|
42
|
+
env: { log: () => {
|
|
43
|
+
} }
|
|
44
|
+
});
|
|
45
|
+
return new Ghostty(instance);
|
|
46
|
+
})());
|
|
47
|
+
return ghosttyPromise;
|
|
48
|
+
}
|
|
49
|
+
var CELL_BOLD = 1;
|
|
50
|
+
var CELL_ITALIC = 2;
|
|
51
|
+
var CELL_UNDERLINE = 4;
|
|
52
|
+
var CELL_STRIKETHROUGH = 8;
|
|
53
|
+
var CELL_INVERSE = 16;
|
|
54
|
+
var CELL_INVISIBLE = 32;
|
|
55
|
+
var CELL_BLINK = 64;
|
|
56
|
+
var CELL_FAINT = 128;
|
|
57
|
+
var RESTORED_DEC_MODES = [
|
|
58
|
+
1,
|
|
59
|
+
// DECCKM — application cursor keys
|
|
60
|
+
7,
|
|
61
|
+
// DECAWM — autowrap
|
|
62
|
+
1e3,
|
|
63
|
+
// mouse: click tracking
|
|
64
|
+
1002,
|
|
65
|
+
// mouse: button-event tracking
|
|
66
|
+
1003,
|
|
67
|
+
// mouse: any-event tracking
|
|
68
|
+
1004,
|
|
69
|
+
// focus in/out reporting
|
|
70
|
+
1005,
|
|
71
|
+
// mouse: UTF-8 coordinates
|
|
72
|
+
1006,
|
|
73
|
+
// mouse: SGR coordinates
|
|
74
|
+
1015,
|
|
75
|
+
// mouse: urxvt coordinates
|
|
76
|
+
2004
|
|
77
|
+
// bracketed paste
|
|
78
|
+
];
|
|
79
|
+
var DEFAULT_STYLE = { fg: null, bg: null, flags: 0 };
|
|
80
|
+
function rgb(r, g, b) {
|
|
81
|
+
return r << 16 | g << 8 | b;
|
|
82
|
+
}
|
|
83
|
+
function styleOf(cell, defaultFg, defaultBg) {
|
|
84
|
+
const fg = rgb(cell.fg_r, cell.fg_g, cell.fg_b);
|
|
85
|
+
const bg = rgb(cell.bg_r, cell.bg_g, cell.bg_b);
|
|
86
|
+
return {
|
|
87
|
+
fg: fg === defaultFg ? null : fg,
|
|
88
|
+
bg: bg === defaultBg ? null : bg,
|
|
89
|
+
flags: cell.flags
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function sameStyle(a, b) {
|
|
93
|
+
return a.fg === b.fg && a.bg === b.bg && a.flags === b.flags;
|
|
94
|
+
}
|
|
95
|
+
function sgr(style) {
|
|
96
|
+
const params = [0];
|
|
97
|
+
if (style.flags & CELL_BOLD) params.push(1);
|
|
98
|
+
if (style.flags & CELL_FAINT) params.push(2);
|
|
99
|
+
if (style.flags & CELL_ITALIC) params.push(3);
|
|
100
|
+
if (style.flags & CELL_UNDERLINE) params.push(4);
|
|
101
|
+
if (style.flags & CELL_BLINK) params.push(5);
|
|
102
|
+
if (style.flags & CELL_INVERSE) params.push(7);
|
|
103
|
+
if (style.flags & CELL_INVISIBLE) params.push(8);
|
|
104
|
+
if (style.flags & CELL_STRIKETHROUGH) params.push(9);
|
|
105
|
+
if (style.fg !== null) {
|
|
106
|
+
params.push(
|
|
107
|
+
38,
|
|
108
|
+
2,
|
|
109
|
+
style.fg >> 16 & 255,
|
|
110
|
+
style.fg >> 8 & 255,
|
|
111
|
+
style.fg & 255
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
if (style.bg !== null) {
|
|
115
|
+
params.push(
|
|
116
|
+
48,
|
|
117
|
+
2,
|
|
118
|
+
style.bg >> 16 & 255,
|
|
119
|
+
style.bg >> 8 & 255,
|
|
120
|
+
style.bg & 255
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return `\x1B[${params.join(";")}m`;
|
|
124
|
+
}
|
|
125
|
+
function serializeRow(cells, cols, defaultFg, defaultBg, graphemeAt) {
|
|
126
|
+
let lastMeaningful = -1;
|
|
127
|
+
for (let x = 0; x < cols; x++) {
|
|
128
|
+
const cell = cells[x];
|
|
129
|
+
if (!cell) continue;
|
|
130
|
+
const blank = cell.codepoint === 0 || cell.codepoint === 32;
|
|
131
|
+
if (!blank || !sameStyle(styleOf(cell, defaultFg, defaultBg), DEFAULT_STYLE)) {
|
|
132
|
+
lastMeaningful = x;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (lastMeaningful < 0) return "\x1B[0m\x1B[K";
|
|
136
|
+
let out = "";
|
|
137
|
+
let current = DEFAULT_STYLE;
|
|
138
|
+
out += sgr(current);
|
|
139
|
+
for (let x = 0; x <= lastMeaningful; x++) {
|
|
140
|
+
const cell = cells[x];
|
|
141
|
+
if (!cell) {
|
|
142
|
+
out += " ";
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (cell.width === 0) continue;
|
|
146
|
+
const style = styleOf(cell, defaultFg, defaultBg);
|
|
147
|
+
if (!sameStyle(style, current)) {
|
|
148
|
+
out += sgr(style);
|
|
149
|
+
current = style;
|
|
150
|
+
}
|
|
151
|
+
if (cell.grapheme_len > 0) {
|
|
152
|
+
out += graphemeAt(x);
|
|
153
|
+
} else if (cell.codepoint === 0) {
|
|
154
|
+
out += " ";
|
|
155
|
+
} else {
|
|
156
|
+
out += String.fromCodePoint(cell.codepoint);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return `${out}\x1B[0m\x1B[K`;
|
|
160
|
+
}
|
|
161
|
+
function clamp(value, fallback, max) {
|
|
162
|
+
if (!Number.isFinite(value) || value === void 0 || value <= 0)
|
|
163
|
+
return fallback;
|
|
164
|
+
return Math.min(Math.floor(value), max);
|
|
165
|
+
}
|
|
166
|
+
var ShellReplayStore = class {
|
|
167
|
+
constructor() {
|
|
168
|
+
__publicField(this, "entries", /* @__PURE__ */ new Map());
|
|
169
|
+
__publicField(this, "ghostty", null);
|
|
170
|
+
}
|
|
171
|
+
/** Instantiates the WASM module. Callers must await this before opening a
|
|
172
|
+
* shell so that `open` itself can be synchronous: a PTY starts producing
|
|
173
|
+
* output the moment it exists, and any await between opening it and
|
|
174
|
+
* subscribing is a window where output is lost to every consumer. */
|
|
175
|
+
async warm() {
|
|
176
|
+
this.ghostty ?? (this.ghostty = await loadGhostty());
|
|
177
|
+
}
|
|
178
|
+
open(shellId, cols, rows) {
|
|
179
|
+
if (this.entries.has(shellId)) return;
|
|
180
|
+
if (this.entries.size >= MAX_REPLAY_SHELLS) {
|
|
181
|
+
throw new Error(
|
|
182
|
+
`agent-os shell replay limit reached (${MAX_REPLAY_SHELLS} emulators); close a shell or raise MAX_REPLAY_SHELLS in shell-replay.ts`
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (!this.ghostty) {
|
|
186
|
+
throw new Error("agent-os shell replay used before warm() resolved");
|
|
187
|
+
}
|
|
188
|
+
const width = clamp(cols, DEFAULT_COLS, MAX_COLS);
|
|
189
|
+
const height = clamp(rows, DEFAULT_ROWS, MAX_ROWS);
|
|
190
|
+
const term = this.ghostty.createTerminal(width, height, {
|
|
191
|
+
scrollbackLimit: MAX_SCROLLBACK_LINES
|
|
192
|
+
});
|
|
193
|
+
term.write("\x1Bc");
|
|
194
|
+
this.entries.set(shellId, { term, cols: width, rows: height, seq: 0 });
|
|
195
|
+
}
|
|
196
|
+
/** Feeds one broadcast chunk and returns its sequence number. Clients use
|
|
197
|
+
* it to drop chunks a snapshot already contains. Returns 0 when this shell
|
|
198
|
+
* has no emulator, which clients read as "no replay available". */
|
|
199
|
+
feed(shellId, data) {
|
|
200
|
+
const entry = this.entries.get(shellId);
|
|
201
|
+
if (!entry) return 0;
|
|
202
|
+
entry.term.write(data);
|
|
203
|
+
return ++entry.seq;
|
|
204
|
+
}
|
|
205
|
+
resize(shellId, cols, rows) {
|
|
206
|
+
const entry = this.entries.get(shellId);
|
|
207
|
+
if (!entry) return;
|
|
208
|
+
entry.cols = clamp(cols, entry.cols, MAX_COLS);
|
|
209
|
+
entry.rows = clamp(rows, entry.rows, MAX_ROWS);
|
|
210
|
+
entry.term.resize(entry.cols, entry.rows);
|
|
211
|
+
}
|
|
212
|
+
close(shellId) {
|
|
213
|
+
const entry = this.entries.get(shellId);
|
|
214
|
+
if (!entry) return;
|
|
215
|
+
this.entries.delete(shellId);
|
|
216
|
+
entry.term.free();
|
|
217
|
+
}
|
|
218
|
+
has(shellId) {
|
|
219
|
+
return this.entries.has(shellId);
|
|
220
|
+
}
|
|
221
|
+
snapshot(shellId, mode) {
|
|
222
|
+
const entry = this.entries.get(shellId);
|
|
223
|
+
if (!entry) return null;
|
|
224
|
+
const { term, cols, rows, seq } = entry;
|
|
225
|
+
const base = { shellId, seq, cols, rows };
|
|
226
|
+
if (mode === "none") return { ...base, mode, data: "" };
|
|
227
|
+
term.update();
|
|
228
|
+
const colors = term.getColors();
|
|
229
|
+
const defaultFg = rgb(
|
|
230
|
+
colors.foreground.r,
|
|
231
|
+
colors.foreground.g,
|
|
232
|
+
colors.foreground.b
|
|
233
|
+
);
|
|
234
|
+
const defaultBg = rgb(
|
|
235
|
+
colors.background.r,
|
|
236
|
+
colors.background.g,
|
|
237
|
+
colors.background.b
|
|
238
|
+
);
|
|
239
|
+
const alternate = term.isAlternateScreen();
|
|
240
|
+
let out = "\x1Bc";
|
|
241
|
+
if (mode === "scrollback" && !alternate) {
|
|
242
|
+
const available = Math.min(
|
|
243
|
+
term.getScrollbackLength(),
|
|
244
|
+
MAX_SCROLLBACK_LINES
|
|
245
|
+
);
|
|
246
|
+
for (let i = available; i > 0; i--) {
|
|
247
|
+
const offset = i - 1;
|
|
248
|
+
const line = term.getScrollbackLine(offset);
|
|
249
|
+
if (!line) continue;
|
|
250
|
+
out += serializeRow(
|
|
251
|
+
line,
|
|
252
|
+
cols,
|
|
253
|
+
defaultFg,
|
|
254
|
+
defaultBg,
|
|
255
|
+
(col) => term.getScrollbackGraphemeString(offset, col)
|
|
256
|
+
);
|
|
257
|
+
out += "\r\n";
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (alternate) out += "\x1B[?1049h";
|
|
261
|
+
for (const decMode of RESTORED_DEC_MODES) {
|
|
262
|
+
out += term.getMode(decMode) ? `\x1B[?${decMode}h` : `\x1B[?${decMode}l`;
|
|
263
|
+
}
|
|
264
|
+
const viewport = term.getViewport();
|
|
265
|
+
out += "\x1B[H";
|
|
266
|
+
for (let y = 0; y < rows; y++) {
|
|
267
|
+
if (y > 0) out += "\r\n";
|
|
268
|
+
const row = viewport.slice(y * cols, (y + 1) * cols);
|
|
269
|
+
out += serializeRow(
|
|
270
|
+
row,
|
|
271
|
+
cols,
|
|
272
|
+
defaultFg,
|
|
273
|
+
defaultBg,
|
|
274
|
+
(col) => term.getGraphemeString(y, col)
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
const cursor = term.getCursor();
|
|
278
|
+
const cy = Math.min(Math.max(cursor.viewportY, 0), rows - 1) + 1;
|
|
279
|
+
const cx = Math.min(Math.max(cursor.viewportX, 0), cols - 1) + 1;
|
|
280
|
+
out += `\x1B[0m\x1B[${cy};${cx}H`;
|
|
281
|
+
out += cursor.visible ? "\x1B[?25h" : "\x1B[?25l";
|
|
282
|
+
return { ...base, mode, data: out };
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
// src/actor.ts
|
|
21
287
|
var DEFAULT_ACTION_TIMEOUT_MS = 2147483647;
|
|
22
288
|
var DEFAULT_SLEEP_GRACE_PERIOD_MS = 15 * 6e4;
|
|
23
289
|
var DEFAULT_PREVIEW_TTL_SECONDS = 3600;
|
|
@@ -31,6 +297,7 @@ var ACTOR_SQLITE_INLINE_THRESHOLD = 64 * 1024;
|
|
|
31
297
|
var ROOT_NAMESPACE = "agentos-root";
|
|
32
298
|
var PREVIEW_PATH_PATTERN = /^\/fetch\/([a-f0-9]{48})(\/.*)?$/;
|
|
33
299
|
var MAX_SQLITE_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
300
|
+
var MAX_OPEN_SHELLS = 32;
|
|
34
301
|
var ACTOR_SQLITE_MIGRATIONS = [
|
|
35
302
|
{
|
|
36
303
|
version: 1,
|
|
@@ -91,6 +358,9 @@ function runtimeFor(c) {
|
|
|
91
358
|
if (!runtime) {
|
|
92
359
|
runtime = {
|
|
93
360
|
vm: null,
|
|
361
|
+
bootedVm: null,
|
|
362
|
+
openShells: /* @__PURE__ */ new Map(),
|
|
363
|
+
shellReplay: new ShellReplayStore(),
|
|
94
364
|
subscribedSessions: /* @__PURE__ */ new Map(),
|
|
95
365
|
vmCleanupRan: false,
|
|
96
366
|
fetchStreamHolds: /* @__PURE__ */ new Map()
|
|
@@ -243,6 +513,7 @@ async function ensureVm(c, options) {
|
|
|
243
513
|
}
|
|
244
514
|
}
|
|
245
515
|
vm.onCronEvent((cronEvent) => c.broadcast("cronEvent", cronEvent));
|
|
516
|
+
runtime.bootedVm = vm;
|
|
246
517
|
c.broadcast("vmBooted", {});
|
|
247
518
|
c.log.info({
|
|
248
519
|
msg: "agent-os vm booted",
|
|
@@ -254,6 +525,7 @@ async function ensureVm(c, options) {
|
|
|
254
525
|
return await runtime.vm;
|
|
255
526
|
} catch (error) {
|
|
256
527
|
runtime.vm = null;
|
|
528
|
+
runtime.bootedVm = null;
|
|
257
529
|
c.log.error({
|
|
258
530
|
msg: "agent-os vm bootstrap failed",
|
|
259
531
|
actorId: c.actorId,
|
|
@@ -268,6 +540,7 @@ async function disposeVm(c, reason) {
|
|
|
268
540
|
const runtime = runtimes.get(c.actorId);
|
|
269
541
|
if (!runtime) return;
|
|
270
542
|
const vm = runtime.vm;
|
|
543
|
+
runtime.bootedVm = null;
|
|
271
544
|
runtimes.delete(c.actorId);
|
|
272
545
|
for (const unsubscribers of runtime.subscribedSessions.values()) {
|
|
273
546
|
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
@@ -813,14 +1086,30 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
813
1086
|
},
|
|
814
1087
|
openShell: async (c, ...args) => {
|
|
815
1088
|
const vm = await ensureVm(c, options);
|
|
1089
|
+
const runtime = runtimeFor(c);
|
|
1090
|
+
if (runtime.openShells.size >= MAX_OPEN_SHELLS) {
|
|
1091
|
+
throw new Error(
|
|
1092
|
+
`agent-os shell limit reached (${MAX_OPEN_SHELLS} open); close a shell or raise MAX_OPEN_SHELLS`
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1095
|
+
await runtime.shellReplay.warm();
|
|
816
1096
|
const shell = vm.terminal.open(...args);
|
|
1097
|
+
runtime.openShells.set(shell.shellId, { openedAt: Date.now() });
|
|
1098
|
+
runtime.shellReplay.open(shell.shellId, args[0]?.cols, args[0]?.rows);
|
|
817
1099
|
const unsubscribeData = vm.onShellData(
|
|
818
1100
|
shell.shellId,
|
|
819
|
-
(event2) => c.broadcast("shellData",
|
|
1101
|
+
(event2) => c.broadcast("shellData", {
|
|
1102
|
+
...event2,
|
|
1103
|
+
seq: runtime.shellReplay.feed(event2.shellId, event2.data)
|
|
1104
|
+
})
|
|
820
1105
|
);
|
|
821
1106
|
const unsubscribeStderr = vm.onShellStderr(
|
|
822
1107
|
shell.shellId,
|
|
823
|
-
(event2) =>
|
|
1108
|
+
(event2) => (
|
|
1109
|
+
// A diagnostic tap carrying bytes `shellData` already delivered, so
|
|
1110
|
+
// it is never folded into replay and carries no sequence.
|
|
1111
|
+
c.broadcast("shellStderr", { ...event2, seq: 0 })
|
|
1112
|
+
)
|
|
824
1113
|
);
|
|
825
1114
|
const unsubscribeExit = vm.onShellExit(
|
|
826
1115
|
shell.shellId,
|
|
@@ -828,6 +1117,8 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
828
1117
|
);
|
|
829
1118
|
void c.keepAwake(
|
|
830
1119
|
vm.terminal.wait(shell.shellId).finally(() => {
|
|
1120
|
+
runtime.openShells.delete(shell.shellId);
|
|
1121
|
+
runtime.shellReplay.close(shell.shellId);
|
|
831
1122
|
unsubscribeData();
|
|
832
1123
|
unsubscribeStderr();
|
|
833
1124
|
unsubscribeExit();
|
|
@@ -841,8 +1132,29 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
841
1132
|
);
|
|
842
1133
|
return shell;
|
|
843
1134
|
},
|
|
1135
|
+
// Observe-only: enumerates shells this actor opened without booting a
|
|
1136
|
+
// sleeping VM (a sleeping VM has none). Clients must not track shell ids
|
|
1137
|
+
// themselves — a shell outlives the page that opened it and keeps the VM
|
|
1138
|
+
// awake, so it has to stay discoverable.
|
|
1139
|
+
listShells: async (c) => {
|
|
1140
|
+
const runtime = runtimes.get(c.actorId);
|
|
1141
|
+
if (!runtime?.bootedVm) return [];
|
|
1142
|
+
return [...runtime.openShells.entries()].map(([shellId, entry]) => ({ shellId, openedAt: entry.openedAt })).sort((a, b) => a.openedAt - b.openedAt);
|
|
1143
|
+
},
|
|
844
1144
|
writeShell: async (c, ...args) => (await ensureVm(c, options)).terminal.write(...args),
|
|
845
|
-
resizeShell: async (c, ...args) =>
|
|
1145
|
+
resizeShell: async (c, ...args) => {
|
|
1146
|
+
const result = (await ensureVm(c, options)).terminal.resize(...args);
|
|
1147
|
+
runtimeFor(c).shellReplay.resize(args[0], args[1], args[2]);
|
|
1148
|
+
return result;
|
|
1149
|
+
},
|
|
1150
|
+
// Observe-only, like `listShells`: repainting a shell must never boot a
|
|
1151
|
+
// VM, and a sleeping VM has no live shells to repaint. Returns `null`
|
|
1152
|
+
// for an unknown shell so a client falls back to no replay.
|
|
1153
|
+
shellSnapshot: async (c, shellId, mode = "screen") => {
|
|
1154
|
+
const runtime = runtimes.get(c.actorId);
|
|
1155
|
+
if (!runtime?.bootedVm) return null;
|
|
1156
|
+
return runtime.shellReplay.snapshot(shellId, mode);
|
|
1157
|
+
},
|
|
846
1158
|
closeShell: async (c, ...args) => (await ensureVm(c, options)).terminal.close(...args),
|
|
847
1159
|
waitShell: async (c, ...args) => (await ensureVm(c, options)).terminal.wait(...args),
|
|
848
1160
|
httpRequest: async (c, ...args) => (await ensureVm(c, options)).network.httpRequest(...args),
|
|
@@ -927,20 +1239,15 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
927
1239
|
let booted = false;
|
|
928
1240
|
let sessions = null;
|
|
929
1241
|
let sidecar = null;
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
sidecar = {
|
|
940
|
-
state: description.state,
|
|
941
|
-
activeVmCount: description.activeVmCount
|
|
942
|
-
};
|
|
943
|
-
}
|
|
1242
|
+
const vm = runtime?.bootedVm;
|
|
1243
|
+
if (runtime && vm) {
|
|
1244
|
+
booted = true;
|
|
1245
|
+
sessions = runtime.subscribedSessions.size;
|
|
1246
|
+
const description = vm.sidecar.describe();
|
|
1247
|
+
sidecar = {
|
|
1248
|
+
state: description.state,
|
|
1249
|
+
activeVmCount: description.activeVmCount
|
|
1250
|
+
};
|
|
944
1251
|
}
|
|
945
1252
|
return {
|
|
946
1253
|
booted,
|
|
@@ -1228,6 +1535,8 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
1228
1535
|
},
|
|
1229
1536
|
terminal: {
|
|
1230
1537
|
open: flat.openShell,
|
|
1538
|
+
list: flat.listShells,
|
|
1539
|
+
snapshot: flat.shellSnapshot,
|
|
1231
1540
|
write: flat.writeShell,
|
|
1232
1541
|
resize: flat.resizeShell,
|
|
1233
1542
|
wait: flat.waitShell,
|
|
@@ -1313,6 +1622,8 @@ function createAgentOsActions(options, hooks = {}, preview = {}, maxSessionSubsc
|
|
|
1313
1622
|
writeProcessStdin: nested.process.writeStdin,
|
|
1314
1623
|
closeProcessStdin: nested.process.closeStdin,
|
|
1315
1624
|
openShell: nested.terminal.open,
|
|
1625
|
+
listShells: nested.terminal.list,
|
|
1626
|
+
shellSnapshot: nested.terminal.snapshot,
|
|
1316
1627
|
writeShell: nested.terminal.write,
|
|
1317
1628
|
resizeShell: nested.terminal.resize,
|
|
1318
1629
|
closeShell: nested.terminal.close,
|
|
@@ -1434,6 +1745,12 @@ var AGENTOS_INSPECTOR_CONFIG = {
|
|
|
1434
1745
|
source: INSPECTOR_TABS_ASSET_DIR,
|
|
1435
1746
|
icon: "folder-tree"
|
|
1436
1747
|
},
|
|
1748
|
+
{
|
|
1749
|
+
id: "terminal",
|
|
1750
|
+
label: "Terminal",
|
|
1751
|
+
source: INSPECTOR_TABS_ASSET_DIR,
|
|
1752
|
+
icon: "terminal"
|
|
1753
|
+
},
|
|
1437
1754
|
{
|
|
1438
1755
|
id: "system",
|
|
1439
1756
|
label: "System",
|