@fungi.computer/grove 0.7.0 → 0.7.1
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/dist/assets/animation-Ca8A_H2p.js +1 -0
- package/dist/assets/{anthropic-messages-CDm0hoBV.js → anthropic-messages-7sgt1UHG.js} +3 -3
- package/dist/assets/{azure-openai-responses-BjoRAOlM.js → azure-openai-responses-ifioVRLI.js} +1 -1
- package/dist/assets/burger-Bew_dWQ5.js +1 -0
- package/dist/assets/cat-CyeMJpek.js +1 -0
- package/dist/assets/{extension-hook-CmoMuW6C.js → client-BgsArGc4.js} +130 -130
- package/dist/assets/compat-C_BaSpng.js +2 -0
- package/dist/assets/extension-hook-BmxyPufU.js +1 -0
- package/dist/assets/extensions-D4sT3fnw.js +1 -0
- package/dist/assets/{google-generative-ai-xdelq2ko.js → google-generative-ai-DTrjA_Kq.js} +1 -1
- package/dist/assets/{google-shared-P7z8Pe9d.js → google-shared-CC7Fhi9a.js} +1 -1
- package/dist/assets/{google-vertex-8hsu6Eaf.js → google-vertex-g2QdhHGh.js} +1 -1
- package/dist/assets/index-eTK6Oges.js +109 -0
- package/dist/assets/{mistral-conversations-JKMpJrPb.js → mistral-conversations-PsOnrdNU.js} +1 -1
- package/dist/assets/{mushroom-ur0TNKww.js → mushroom-Bws8KRYq.js} +1 -1
- package/dist/assets/{node.browser-GHKlzSn3.js → node.browser-BXQd5-t8.js} +1 -1
- package/dist/assets/{openai-codex-responses-CidQ12Xa.js → openai-codex-responses-iLzgcq4d.js} +1 -1
- package/dist/assets/openai-codex.models-B_MCwO6E.js +1 -0
- package/dist/assets/{openai-completions-D9RzypE9.js → openai-completions-BKmKKKO6.js} +1 -1
- package/dist/assets/{openai-responses-BXeaL2BV.js → openai-responses-CPrT1qyt.js} +1 -1
- package/dist/assets/{openai-responses-shared-Da1jFqQB.js → openai-responses-shared-D1m_goPG.js} +1 -1
- package/dist/assets/parakeet-MIo5GJJ1.js +36 -0
- package/dist/assets/parakeet-conversation-BAsHp-EG.js +4 -0
- package/dist/assets/renderer-gIZ0s6fA.js +1 -0
- package/dist/assets/{runtime-core-DKpk6tKT.js → runtime-core-tDPMDDqR.js} +2 -2
- package/dist/assets/sigil-DQZqONrR.js +31 -0
- package/dist/assets/{transform-messages-YmXk5TtR.js → transform-messages-B1nXfhYd.js} +1 -1
- package/dist/assets/website-conversation-CwS3UatH.js +1 -0
- package/dist/index.html +4 -2
- package/package.json +6 -6
- package/dist/assets/burger-DGewjCsv.js +0 -1
- package/dist/assets/cat-CRMM8U8H.js +0 -1
- package/dist/assets/compat-tatm8WJ0.js +0 -2
- package/dist/assets/extensions-CrmxvtfG.js +0 -1
- package/dist/assets/index-CCJvRnqn.js +0 -174
- package/dist/assets/parakeet-conversation-DYlN7oL9.js +0 -4
- package/dist/assets/renderer-BKCye2Ev.js +0 -1
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Ca as t,Ji as n,Sa as r,_a as i,ca as a,ea as o,ga as s,ir as c,la as l,ma as u,mt as d,nr as f,va as p}from"./Effect-CtszBD7f.js";import{Ca as m,Fi as ee,Hi as te,Jr as ne,Kr as re,Ni as h,Si as ie,Ta as g,Ti as ae,Yr as _,Zi as oe,Zr as v,ba as y,br as se,ca as b,di as ce,ea as x,ei as S,fa as C,fi as le,ga as w,i as T,ia as ue,ii as E,ji as de,mi as D,pi as O,ri as k,ti as fe,ui as A,wa as j,wi as M,xi as N,zi as P}from"./extension-hook-CmoMuW6C.js";import{A as F,C as pe,D as me,E as he,O as ge,S as _e,T as ve,_ as ye,_t as be,a as xe,at as Se,bt as Ce,ct as we,dt as Te,ft as Ee,gt as De,ht as Oe,i as ke,it as Ae,k as I,lt as je,mt as L,o as Me,ot as Ne,pt as Pe,r as Fe,s as Ie,st as Le,ut as R,v as Re,vt as ze,w as Be,yt as Ve}from"./index-CCJvRnqn.js";import"./extensions-CrmxvtfG.js";var He=(e,t)=>{if(e.length<=t)return e;let n=Math.max(1,Math.floor((t-1)/2));return`${e.slice(0,n)}…${e.slice(-(t-n-1))}`},z=(e,t)=>e.length<=t?e:`${e.slice(0,t-1)}…`,Ue=e=>e.map(([e,t])=>({label:e,value:t}));function We(e,t){let{record:n}=e,r=Math.max(0,n.expiresAt-t);return[[`Agent`,`${n.requester.displayName} · ${n.requester.agentId??`none`}`],[`Session`,n.requester.sessionId??`none`],[`Requester`,n.requester.principalId],[`Request`,`${n.module}.${n.operation} · ${n.access}`],[`Input`,`${n.description.inputBytes.toLocaleString()} bytes · SHA-256 ${n.description.inputSha256.slice(0,8)}…${n.description.inputSha256.slice(-6)}`],[`Expires`,`in ${String(Math.floor(r/36e5))} h ${String(Math.floor(r%36e5/6e4))} m`],[`Record`,`${n.recordId} · revision ${String(n.revision)}`]]}function Ge(e){return[`Undo`,e.record.reversibility===`irreversible-external`?`Can't be undone`:`Can be undone`]}function Ke(e,t){let{record:n}=e;return{content:{title:`Allow ${n.module} · ${n.operation}?`,summary:`${n.requester.displayName} wants to use a connected tool.`,facts:[{label:`Effect`,value:(n.access===`write`?`Changes data in Fungi`:`Changes things outside Fungi`)+(n.reversibility===`irreversible-external`?` · can't be undone`:``)}],details:Ue([Ge(e),...We(e,t)])}}}function qe(e,t,n,r,i){let a=t.prefix?.join(` `),o=a!==void 0&&t.alwaysAllowUnavailableReason===void 0,s=t.command,c=`Allow \`${s}\`?`.length<=n?`Allow \`${s}\`?`:`Allow this command?`,l=t.cwd===r?`~`:t.cwd.startsWith(`${r}/`)?`~${t.cwd.slice(r.length)}`:t.cwd,u=Math.max(8,(n-8)*2-2),d=t.justification.length<=u?`“${t.justification}”`:`“${t.justification.slice(0,u-1)}…”`,f=[[`Folder`,He(l,Math.max(8,n-10))],[`Why`,d]];t.kind===`extension-install`&&f.push([`Note`,`Extensions run inside Fungi with access to every Agent.`]),o&&t.alwaysAllowCoverage!==void 0&&f.push([`Scope`,z(t.alwaysAllowCoverage,Math.max(8,n-12))]),!o&&t.warning!==void 0&&f.push([`Warning`,t.warning]);let p=o?`Always allow “${He(a,Math.max(8,n-5-32))}” in this project…`:void 0,m=[[`Command`,s]];return t.argv!==void 0&&m.push([`Arguments`,JSON.stringify(t.argv)]),m.push([`Folder`,t.cwd],[`Runs`,`Outside the sandbox, as you`],Ge(e)),!o&&t.alwaysAllowUnavailableReason!==void 0?m.push([`Rule`,t.alwaysAllowUnavailableReason]):t.form===`shell`?m.push([`Rule`,`Shell command: no Always-allow rule can match it.`]):o&&(m.push([`Rule`,`“${a}” would match \`${a} …\` in this project`]),t.alwaysAllowCoverage!==void 0&&m.push([`Coverage`,t.alwaysAllowCoverage]),t.risk!==void 0&&m.push([`Risk`,t.risk.detail])),!o&&t.warning!==void 0&&m.push([`Warning`,t.warning]),m.push(...We(e,i)),{content:{title:c,body:c===`Allow this command?`?s:void 0,bodyLabel:c===`Allow this command?`?`Command`:void 0,summary:`${e.record.requester.displayName} wants to run this outside the sandbox, as you.`,facts:Ue(f),details:Ue(m)},always:p===void 0?void 0:z(p,Math.max(12,n-5)),confirmation:o?{title:`Always allow “${a}” in this project?`,body:z(t.alwaysAllowCoverage??`Any Workspace Agent here can then run \`${a} …\` without asking.`,Math.max(12,(n-8)*2-2))}:void 0,confirmWarning:o?t.risk?.summary:void 0,confirmYes:o?`Always allow “${a}” and run it now`:void 0}}function Je(e,t,n){let r=Math.min(n.width,60);return t===void 0?Ke(e,n.now):qe(e,t,r,n.home,n.now)}function Ye(e,t){switch(e){case`stale-revision`:case`already-answered`:return`This request changed. Look again before answering.`;case`expired`:return`This request expired. Nothing ran.`;case`not-eligible`:if(t===`always-allow`)return`Always allow isn't available for this command. Approve once or deny.`}return`Couldn't answer (${e}). Nothing ran.`}var Xe=`Couldn't send your answer. It may not have been recorded.`;async function Ze(e,t){let{view:n,source:r}=t,i=Je(n,r.review,{width:t.width,home:t.home,now:t.now}),a=n.record;try{let n,o,s=!1;for(;n===void 0;){let c=await e.prompt({type:`decision`,message:i.content.title,summary:s?`Automatic approval is on for this family.`:i.content.summary,facts:i.content.facts?.map(e=>({...e})),body:i.content.body,bodyLabel:i.content.bodyLabel,details:i.content.details?.map(e=>({...e})),options:[{value:`approve`,label:`Approve once`},...i.always===void 0?[]:[{value:`always`,label:i.always}],...r.family===void 0||s?[]:[{value:`family`,label:r.family.label}],{value:`deny`,label:`Deny`}],other:{label:`Deny and say why…`,placeholder:`A short reason for the Agent (optional)`,maxLength:t.noteLimit,blank:`deny`}});if(!t.stillCurrent())return{kind:`abandoned`};if(c.text!==void 0)o=c.text.trim()||void 0,n=`deny`;else if(c.selected[0]===`always`){let r=i.confirmation,a=await e.prompt({type:`decision`,message:r?.title??i.content.title,summary:i.confirmWarning,body:r?.body,options:[{value:`back`,label:`Back`},{value:`always-allow`,label:i.confirmYes??`Always allow`}],escape:`back`});if(!t.stillCurrent())return{kind:`abandoned`};a.selected[0]===`always-allow`&&(n=`always-allow`)}else if(c.selected[0]===`family`&&r.family!==void 0){let n=await e.prompt({type:`decision`,message:`${r.family.label}?`,summary:`Later ${a.module} requests that ${a.access===`write`?`change data in Fungi`:`reach outside Fungi`} will run without asking.`,options:[{value:`back`,label:`Back`},{value:`family`,label:r.family.label}],escape:`back`});if(!t.stillCurrent()||n.selected[0]===`family`&&(s=await r.family.enable(),!t.stillCurrent()))return{kind:`abandoned`}}else c.selected[0]===`approve`?n=`approve`:c.selected[0]===`deny`&&(n=`deny`)}let c={recordId:a.recordId,decision:n,expectedRevision:a.revision},l=await r.answer(o===void 0?c:{...c,denialNote:o});return t.stillCurrent()?l.kind===`refused`?{kind:`refused`,message:Ye(l.reason??`unknown`,n)}:{kind:`answered`}:{kind:`abandoned`}}catch(n){return e.signal.aborted?{kind:`abandoned`}:(t.onFailure(n),{kind:`refused`,message:Xe})}}var B=e(Ce(),1),Qe=()=>void 0,$e=()=>()=>void 0;function et(e){let{source:t,store:n,enabled:r,home:i,width:a,noteLimit:o,onFailure:s}=e,c=(0,B.useRef)(s);c.current=s;let l=(0,B.useRef)({home:i,width:a,noteLimit:o});l.current={home:i,width:a,noteLimit:o};let u=(0,B.useSyncExternalStore)(t?.subscribe??$e,t?.snapshot??Qe),d=(0,B.useRef)(u);d.current=u;let f=u===void 0?void 0:JSON.stringify([`approval`,u.record.recordId,u.record.revision,u.canAnswer]);(0,B.useEffect)(()=>{let e=d.current;if(!r||t===void 0||e===void 0||!e.canAnswer||f===void 0)return;let{home:i,width:a,noteLimit:o}=l.current,s=me({title:`Approval`}),u=s.begin(),p=()=>{let n=t.snapshot();return!u.interaction.signal.aborted&&n?.record.recordId===e.record.recordId&&n.record.revision===e.record.revision&&n.canAnswer},m=n.awaiting.add({key:f,kind:`approval`,arrivedAt:Date.now(),host:s});return Ze(u.interaction,{view:e,source:t,home:i,width:a,now:Date.now(),noteLimit:o,stillCurrent:p,onFailure:e=>{c.current(e)}}).then(e=>{e.kind===`refused`?u.settle({status:`failed`,message:e.message}):(m(),u.settle(e.kind===`answered`?{status:`handled`}:{status:`cancelled`}))}),()=>{m(),s.cancel()}},[t,f,r,n])}var V=ze(),H=O.check(w(1),C(256)),tt=S.check(x(1),b(2**53-1)),nt=S.check(x(0),b(2**53-1)),rt=E([`write`,`external`]),it=D({module:A(H),access:rt}),at=D({agentId:A(H)}),ot=D({principalId:H,agentId:A(H),sessionId:A(H),displayName:H}),st=D({title:O.check(w(1),C(512)),inputBytes:S.check(x(0)),inputSha256:O.check(y(/^[a-f0-9]{64}$/))}),ct=D({kind:k(`pending_approval`),recordId:H,description:st}),lt=E([`requested`,`pending`,`approved`,`claimed`,`applied`,`denied`,`expired`,`outcome_unknown`]),ut=E([`not-found`,`not-eligible`,`already-answered`,`stale-revision`,`expired`,`declined`,`fenced`,`not-granted`,`read-only`,`pending`,`in-flight`,`outcome-unknown`,`identity-conflict`]),dt=O.check(w(1),C(512),y(/^(?=.*\S)[^\p{Cc}\u2028\u2029]*$/u)),ft=_(D({kind:k(`artifact`),ref:O.check(y(/^sha256:[a-f0-9]{64}$/)),mediaType:k(`image/png`),bytes:S.check(x(1),b(5242880))})).check(C(4)),pt=D({recordId:H,requester:ot,module:H,operation:H,access:rt,description:st,evidence:g(ft),authorityFence:H,reversibility:E([`reversible`,`irreversible-external`]),state:lt,by:A(N([D({kind:k(`human`),memberId:H}),D({kind:k(`policy`)})])),reason:A(ut),denialNote:g(dt),requestedAt:nt,expiresAt:nt,updatedAt:nt,revision:tt}),mt=D({record:pt,canAnswer:v,canSetAutoApprove:v});D({state:g(lt),cursor:g(H),limit:g(S.check(x(1),b(100)))}),D({recordId:H}),D({recordId:H,decision:E([`approve`,`deny`]),expectedRevision:tt,denialNote:g(dt)});var ht=D({scope:at,family:it,enabled:v}),gt=D({kind:k(`refused`),reason:ut,denialNote:g(dt)});h(P(pt),{onExcessProperty:`error`}),ee(P(pt)),h(D({record_json:O})),h(P(fe)),ee(P(fe)),h(D({input_json:O,output_json:A(O)}));var _t=gt,vt=D({items:_(mt),nextCursor:A(O)}),yt=N([D({kind:k(`answered`),view:mt}),_t]),bt=N([D({kind:k(`updated`),rule:ht}),_t]),U=e=>Ee(r().transform(t=>h(e,{onExcessProperty:`error`})(t))),xt=De(`approvals`,1,l(()=>Pe({list:L(U(vt)),get:L(U(A(mt))),answer:L(U(yt)),setAutoApprove:L(U(bt))}))),W=ae(e=>ge.safeParse(e).success,{representation:{id:`@fungi.computer/whistle/catalog-step/v1`,payload:null}});d(()=>re());var G=O.pipe(M(w(1)),M(C(4e3)),M(y(/\S/u,{message:`Goal objective is blank`}))),St=O.pipe(M(w(1)),M(C(1e3)),M(y(/\S/u))),Ct=O.pipe(M(w(1)),M(C(256))),wt=S.check(x(0)),Tt=D({kind:E([`person`,`blocked`,`stalled`,`cancelled`,`failed`,`no-terminal`]),detail:A(O)}),K=D({revision:O,objective:G,state:E([`active`,`paused`]),startedAt:wt,pauseCause:A(Tt)}),Et=D({sequence:S.check(oe(0)),objective:G,outcome:E([`achieved`,`cleared`]),reason:A(St),endedAt:wt,afterSequence:S.check(x(0))}),Dt=N([D({action:k(`set`),objective:G,requestId:Ct,expectedRevision:j(A(O)),confirmed:j(v)}),D({action:E([`pause`,`resume`,`replace`,`clear`,`clear-ask`]),confirmed:j(v)}),D({})]),Ot=D({goal:A(K),ended:_(Et).check(C(16)),omitted:S.check(x(0))}),kt={id:T.make(`botanical-session-goal`),commands:{goal:{scope:`session`,input:Dt,output:W},pause:{scope:`session`,input:D({}),output:K},resume:{scope:`session`,input:D({}),output:K},clear:{scope:`session`,input:D({}),output:D({})},set:{scope:`session`,input:D({objective:G,expectedRevision:A(O),requestId:Ct,adoptCommandId:g(Ct)}),output:D({goal:K,accepted:D({status:k(`accepted`),commandId:O})})}},projection:{schema:Ot}},q=e=>{let t=e.replace(/\s+/gu,` `).trim();return t.length<=80?t:`${t.slice(0,79)}…`},At=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};function jt(e){let t=e.state===`active`,n=t?`Pursuing goal since ${At(e.startedAt)}`:`Goal paused (/goal resume)`,r=!t&&e.pauseCause?.detail!=null?[q(e.pauseCause.detail)]:[],i={id:`goal`,title:[n,q(e.objective),...r].join(` · `),tone:t?`running`:`muted`,actions:[{id:`goal`,label:t?`Pause goal`:`Resume goal`,input:{action:t?`pause`:`resume`}}]};return q(e.objective)===e.objective?i:{...i,detail:e.objective.slice(0,1024)}}function Mt(e){let t={id:`goal-ended`,title:`${e.outcome===`achieved`?`Goal achieved`:`Goal cleared`} · ${q(e.objective)}`,tone:e.outcome===`achieved`?`settled`:`muted`},n=e.reason===null?t:{...t,detail:e.reason};return{id:String(e.sequence),sequence:e.sequence,at:e.endedAt,commandId:null,afterSequence:e.afterSequence,rows:[n]}}var Nt=I(kt,{promptPresentation:`footer`,contribute:e=>{if(e.status!==`running`||e.value===null)return{chips:[],panel:[],timeline:{cells:[],omitted:0},waiting:null};let{goal:t,ended:n,omitted:r}=e.value;return{chips:[],panel:t===null?[]:[jt(t)],timeline:{cells:n.map(Mt),omitted:r},waiting:null}}}),Pt=O.pipe(M(w(1)),M(C(256))),J=O.pipe(M(w(1)),M(C(262144))),Ft=D({expression:O.pipe(M(w(1)),M(C(256))),timeZone:O.pipe(M(w(1)),M(C(128)))}),Y=D({loopId:O,origin:E([`human`,`model`]),expiresAt:A(S),prompt:J,mode:E([`self_paced`,`fixed_interval`]),cron:A(Ft),state:E([`active`,`paused`,`finished`,`failed`,`cancelled`]),commandId:O,reason:A(O),nextDueAt:A(S),lastError:A(O),consecutiveFailures:S.pipe(M(x(0)))}),It=D({after:g(Pt),limit:g(S.pipe(M(te({minimum:1,maximum:64}))))}),Lt=O.pipe(M(w(1)),M(C(200))),Rt=D({loop:Y,accepted:D({status:k(`accepted`),commandId:O})}),zt=N([D({action:k(`start`),text:J,requestId:Lt}),D({action:E([`status`,`pause`,`resume`,`stop`,`stop-ask`,`new`]),confirmed:j(v)}),D({})]),Bt=D({loop:Y}),Vt=D({sessionId:Pt,loopId:Y.fields.loopId}),Ht={id:T.make(`botanical-session-loop`),commands:{list:{scope:`agent`,input:It,output:_(D({...Y.fields,sessionId:Pt})).pipe(M(C(64)))},pauseLoop:{scope:`agent`,input:Vt,output:Y},resumeLoop:{scope:`agent`,input:Vt,output:Y},stopLoop:{scope:`agent`,input:Vt,output:Y},loop:{scope:`session`,input:zt,output:W},startSelfPaced:{scope:`session`,input:D({prompt:J,requestId:Lt}),output:Rt},startFixedInterval:{scope:`session`,input:D({prompt:J,requestId:Lt,...Ft.fields}),output:Rt},pause:{scope:`session`,input:D({}),output:Y},resume:{scope:`session`,input:D({}),output:Y},stop:{scope:`session`,input:D({}),output:Y}},projection:{schema:Bt}},Ut=e=>{let t=e.replace(/\s+/gu,` `).trim();return t.length<=60?t:`${t.slice(0,59)}…`},Wt=e=>e.state===`failed`?`error`:e.state===`active`?`running`:e.state===`paused`?`muted`:`settled`,Gt=e=>new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`}).format(e),Kt=I(Ht,{promptPresentation:`footer`,contribute:e=>{if(e.status!==`running`||e.value===null)return{chips:[],panel:[],timeline:{cells:[],omitted:0},waiting:null};let{loop:t}=e.value,n=t.state===`active`&&t.nextDueAt!==null;return{chips:t.state!==`active`&&t.state!==`paused`?[]:[{id:`loop`,order:2,row:{id:`loop`,title:`Loop ${t.mode===`self_paced`?`self-paced`:`fixed`}${n?` (waiting)`:``}`,tone:Wt(t)}}],panel:[{id:`loop`,title:`Loop · ${t.state} · ${t.mode===`self_paced`?`self-paced`:`${t.cron?.expression??`fixed`} ${t.cron?.timeZone??``}`}${t.nextDueAt===null?``:` · Next ${Gt(t.nextDueAt)}`} · ${Ut(t.prompt)}`,detail:[t.reason,t.prompt].filter(e=>e!==null).join(`
|
|
2
|
-
`).slice(0,1024),tone:Wt(t)},...t.lastError===null?[]:[{id:`error`,title:t.lastError.slice(0,4096),tone:`error`}]],timeline:{cells:[],omitted:0},waiting:n?{summary:`Waiting until ${Gt(t.nextDueAt)}`,cancel:{id:`loop`,label:`stop loop`,input:{action:`stop-ask`}}}:null}}});function qt(e){return D({nextSequence:S.check(oe(0)),omitted:S.check(x(0)),events:_(D({id:O,sequence:S,at:S,commandId:A(O),event:e}))})}new TextEncoder;var Jt=D({explanation:g(O.pipe(M(C(2e3)))),steps:_(D({step:O.pipe(M(w(1)),M(C(500))),status:E([`pending`,`in_progress`,`completed`])})).pipe(M(C(50)))});Jt.pipe(M(m(e=>e.steps.filter(e=>e.status===`in_progress`).length<=1||`At most one plan step may be in progress`)));function Yt(e){return e.steps.some(e=>e.status!==`completed`)}var Xt=D({plan:Jt,history:qt(Jt)}),Zt=N([D({action:k(`clear`)}),D({})]),Qt={id:T.make(`botanical-session-plan`),commands:{plan:{scope:`session`,input:Zt,output:W}},projection:{schema:Xt}},$t=e=>{let t=e.steps.findIndex(e=>e.status===`in_progress`),n=e.steps.filter(e=>e.status===`completed`).length;return{title:(t<0?e.steps.find(e=>e.status===`pending`):e.steps[t])?.step??`Plan complete`,detail:`${String(t<0?n:t+1)}/${String(e.steps.length)}`}},en=e=>e.steps.map((e,t)=>({id:String(t),title:e.step,tone:e.status===`completed`?`settled`:e.status===`in_progress`?`running`:`muted`})),tn=I(Qt,{contribute:e=>({chips:[],panel:e.status!==`running`||e.value===null||!Yt(e.value.plan)?[]:[{id:`plan`,...$t(e.value.plan),actions:[{id:`plan`,label:`Clear plan`,input:{action:`clear`}}],inspection:{commandId:`plan`,title:`Plan`,rows:en(e.value.plan)}}],timeline:{cells:[],omitted:0},waiting:null})}),X=e=>O.check(w(1),C(e),y(/\S/u)),nn=D({id:X(32).check(y(/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/u)),header:X(12),question:X(1e3),options:_(D({label:X(60),description:X(300)})).check(w(2),C(4),m(e=>new Set(e.map(e=>e.label)).size===e.length||`Option labels must be unique`,{representation:{id:`botanical/ask/unique-option-labels`,payload:null}})),multiple:g(v)}),rn=_(nn).check(w(1),C(4),m(e=>new Set(e.map(e=>e.id)).size===e.length||`Question ids must be unique`,{representation:{id:`botanical/ask/unique-question-ids`,payload:null}})),an=D({askId:O,waitingOn:g(se),questions:rn,status:E([`live`,`parked`]),createdAt:ce,expiresAt:A(ce)}),on=D({asks:_(an).check(C(4))}),sn=X(256),cn=le(nn.fields.id,D({selected:_(X(60)).check(C(4)),text:g(O.check(C(4e3)))})),Z=D({askId:X(256),requestId:sn,answers:cn}),ln=D({askId:X(256),requestId:sn,note:g(O.check(C(4e3)))}),un=E([`answered`,`declined`,`withdrawn`,`expired`,`cancelled`,`undeliverable`]),dn=N([D({result:k(`accepted`),via:E([`in_turn`,`follow_up`]),commandId:g(X(256))}),D({result:k(`closed`),status:un}),D({result:k(`not_found`)})]),fn=D({result:k(`refused`),reason:k(`not_sender`)}),pn=N([dn,fn]),mn=D({kind:k(`agent`),agentId:X(256)}),hn=N([D({result:k(`escalated`),to:k(`person`)}),D({result:k(`closed`),status:un}),D({result:k(`not_found`)}),fn]),gn=D({askId:X(256)}),_n={askId:Z.fields.askId,requestId:sn,index:ce.check(ue(),te({minimum:0,maximum:3})),answers:cn},vn=N([D({stage:k(`decision`),..._n,answer:cn.value}),D({askId:Z.fields.askId}),D({})]),yn={id:T.make(`botanical-session-question`),commands:{answerFlow:{scope:`session`,input:vn,output:W},answer:{scope:`session`,input:Z,output:dn},answerAgent:{scope:`session`,input:Z,output:D({result:pn,answeredBy:mn})},escalateAgent:{scope:`session`,input:gn,output:hn},decline:{scope:`session`,input:ln,output:dn},list:{scope:`session`,input:D({}),output:on}},projection:{schema:on}},bn=I(yn,{contribute:e=>({chips:[],panel:e.status!==`running`||e.value===null?[]:e.value.asks.map(e=>{let t=e.questions[0],n=`${t?.question??`Question`}${e.questions.length>1?` (+${String(e.questions.length-1)} more)`:``}`,r=t?.options.map(e=>e.label).join(` · `)??``;return e.waitingOn===void 0?{id:e.askId,title:n,detail:r,tone:`attention`,actions:[{id:`answerFlow`,label:`Answer`,input:{askId:e.askId},awaiting:`question`}]}:{id:e.askId,title:`waiting on ${e.waitingOn.name} · ${n}`,detail:r,tone:`muted`,actions:[{id:`answerFlow`,label:`Answer`,input:{askId:e.askId}}]}}),timeline:{cells:[],omitted:0},waiting:null})}),Q=O.check(w(1),C(256)),xn=E([`working`,`waiting_on_agent`,`needs_you`,`idle`,`failed`,`unavailable`]),Sn=D({agentId:Q,name:Q,sessionId:A(Q),state:xn,attention:g(O.check(C(200))),waitingOn:g(Q),ask:g(D({askId:Q,questions:rn}))}),Cn=D({agents:_(Sn).check(C(16)),more:S.check(x(0)),expanded:v}),wn={agentId:Q,sessionId:Q},Tn=N(vn.members.map(e=>D({...e.fields,...wn}))),En={agents:{scope:`session`,input:D({}),output:W},answerChild:{scope:`session`,input:Tn,output:W}},Dn={id:T.make(`botanical-session-subagents`),commands:En,projection:{schema:Cn}},$={working:{label:`working`,tone:`running`,status:`info`},waiting_on_agent:{label:`waiting`,tone:`muted`,status:`neutral`},needs_you:{label:`needs you`,tone:`attention`,status:`warning`},idle:{label:`idle`,tone:`settled`,status:`success`},failed:{label:`failed`,tone:`error`,status:`error`},unavailable:{label:`unavailable`,tone:`muted`,status:`neutral`}};function On(e){return e.state===`waiting_on_agent`?`waiting on ${e.waitingOn??`its parent`}`:$[e.state].label}function kn(e){let t=$[e.state],n={id:e.agentId,title:`${e.name} · ${On(e)}`,tone:t.tone,status:{label:On(e),tone:t.status}},r=e.ask?.questions[0]?.question??e.attention,i=r===void 0?n:{...n,detail:r.slice(0,200)};if(e.sessionId===null)return{...i,detail:e.attention??`not messaged yet`};let a={...i,open:{params:[{key:`agent`,value:e.agentId},{key:`session`,value:e.sessionId}]}};if(e.ask===void 0)return a;let o={id:`answerChild`,label:`Answer`,input:{agentId:e.agentId,sessionId:e.sessionId,askId:e.ask.askId}};return{...a,actions:[e.state===`needs_you`?{...o,awaiting:`question`}:o]}}function An(e){let t=t=>e.agents.filter(e=>e.state===t).length,n=e.agents.filter(e=>e.state===`waiting_on_agent`),r=[...new Set(n.map(e=>e.waitingOn??`its parent`))].map(e=>`${String(n.filter(t=>(t.waitingOn??`its parent`)===e).length)} waiting on ${e}`),i=[...[`working`].map(e=>[e,t(e)]).filter(([,e])=>e>0).map(([e,t])=>`${String(t)} ${$[e].label}`),...r,...[`needs_you`,`failed`,`unavailable`].map(e=>[e,t(e)]).filter(([,e])=>e>0).map(([e,t])=>`${String(t)} ${$[e].label}`)],a=e.agents.length+e.more,o=t(`needs_you`)>0?`attention`:t(`failed`)>0?`error`:t(`working`)>0?`running`:`muted`;return{id:`summary`,title:[`${String(a)} sub-agent${a===1?``:`s`}`,...i,`/agents shows them`].join(` · `),tone:o}}var jn=I(Dn,{contribute:e=>({chips:[],panel:e.status!==`running`||e.value===null?[]:e.value.agents.length>0&&!e.value.expanded?[An(e.value)]:[...e.value.agents.map(kn),...e.value.more===0?[]:[{id:`more`,title:`${String(e.value.more)} more sub-agent${e.value.more===1?``:`s`}`,tone:`muted`}]],timeline:{cells:[],omitted:0},waiting:null})});function Mn(e,t){if(e===null||!URL.canParse(t))return!1;let n=new URL(t);return n.protocol!==`https:`||n.hash!==`#team-billing`?!1:(e.openTeamBilling().catch(t=>(console.error(`Chat Billing navigation failed`,t),e.showToast({message:`Billing could not be opened. Please try again.`,tone:`error`}))),!0)}function Nn(e,t){e!==null&&e.showToast({message:t.message,tone:t.variant}).catch(e=>{console.error(`Chat toast failed`,e)})}function Pn(e){if(e.name!==`execute`||e.status!==`completed`)return;let t=e.result?.content;if(t?.length!==1||t[0]?.type!==`text`)return;let n=de(P(ie))(t[0].text);if(f(n))return;let r=he.safeParse(n.value);return r.success?r.data.file:void 0}function Fn({item:e,ui:t}){let n=Pn(e),[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(!1);if(!n)return null;let s=async()=>{i(!0),o(!1);try{await t.openNavigation(n)}catch(e){console.error(`Chat file navigation failed`,e),o(!0)}finally{i(!1)}};return(0,V.jsxs)(`div`,{className:`px-3 py-2`,children:[(0,V.jsx)(F,{variant:`ghost`,size:`sm`,disabled:r,onClick:()=>void s(),type:`button`,children:r?`Opening file…`:`Open ${n.path} in Inkcap`}),a?(0,V.jsx)(`p`,{role:`alert`,children:`The file could not be opened. Try again.`}):null]})}var In=N([D({kind:k(`compose`),text:O.pipe(M(w(1)),M(C(2e3)))}),D({kind:k(`navigate`),params:_(D({key:O.pipe(M(w(1)),M(C(64))),value:O.pipe(M(C(1024)))})).pipe(M(C(16)))})]);N([D({role:O.pipe(M(w(1)),M(C(80))),intent:In}),D({appId:O.pipe(M(w(1)),M(C(128))),intent:In})],{mode:`oneOf`});var Ln=i({displayName:p().min(1).max(80).nullable()}).nullable(),Rn=De(`apps.open`,1,l(()=>Pe({open:Oe,role:L(Ee(Ln))}))),zn=(e,t)=>e.require(Rn).open(t);De(`apps.call`,1,l(()=>Pe({call:L(Ee(r().transform(e=>Ve(e))))})));var Bn=u({printId:p().min(1).max(256),destination:i({computerId:p().min(1),path:p().min(1)}),format:n([`png`,`jpeg`,`gif`,`webp`])}),Vn=a(),Hn=o(Vn).or(s(p(),Vn).transform(e=>Object.values(e)));function Un(e,t){let n=Bn.safeParse(e);if(n.success)return[n.data];if(t>=3)return[];let r=Hn.safeParse(e);return r.success?r.data.flatMap(e=>Un(e,t+1)):[]}var Wn=Vn.transform(e=>Un(e,0)).pipe(o(Bn).min(1).max(8));function Gn(e){if(e.name!==`execute`||e.status!==`completed`||e.result===void 0)return;let t=e.result.content,n=t.at(0);if(n?.type!==`text`||t.slice(1).some(e=>e.type!==`image`))return;let r=de(P(ie))(n.text);if(f(r))return;let i=Wn.safeParse(r.value);return i.success?i.data:void 0}function Kn(e){return Gn(e)!==void 0}function qn({printId:e,pictures:t,capabilities:n}){let[r,i]=(0,B.useState)(!1),[a,o]=(0,B.useState)(!1),s=async()=>{i(!0),o(!1);try{await zn(n,{role:`media`,intent:{kind:`navigate`,params:[{key:`print`,value:e}]}})}catch(e){console.error(`Chat print navigation failed`,e),o(!0)}finally{i(!1)}};return(0,V.jsxs)(`div`,{className:`flex flex-col items-start gap-2 px-3 py-2`,children:[t.map((e,t)=>(0,V.jsx)(`img`,{alt:`Panel saved in Prints`,className:`max-w-full rounded-box`,src:`data:${e.mimeType};base64,${e.data}`,style:{maxHeight:320}},t)),(0,V.jsx)(F,{variant:`outline`,size:`sm`,disabled:r,onClick:()=>void s(),type:`button`,children:r?`Opening Prints…`:`Open in Prints`}),a?(0,V.jsx)(`p`,{role:`alert`,children:`Prints could not be opened. Try again.`}):null]})}function Jn({item:e,capabilities:t}){let n=Gn(e);if(n&&t){let r=(e.result?.content??[]).flatMap(e=>e.type===`image`?[e]:[]),i=r.length===n.length;return(0,V.jsx)(V.Fragment,{children:n.map((e,n)=>(0,V.jsx)(qn,{printId:e.printId,pictures:i?r.slice(n,n+1):n===0?r:[],capabilities:t},e.printId))})}return null}var Yn=de(P(ct),{onExcessProperty:`error`});function Xn(e){if(!(e.status!==`completed`||e.result?.isError))for(let t of e.result?.content??[]){if(t.type!==`text`)continue;let e=Yn(t.text);if(c(e))return e.value.recordId}}var Zn=(0,B.createContext)(void 0);function Qn(){return(0,B.useContext)(Zn)}var $n=`Couldn't send your answer. It may not have been recorded.`;function er({recordId:e,attempt:t,capabilities:n,agentId:r,publish:i}){let a=Be(),[o,s]=(0,B.useState)(),c=(0,B.useRef)(void 0),l=(0,B.useRef)(new Set),u=(0,B.useCallback)(t=>{c.current=t??void 0,s(t),i(e,{view:t,failed:!1});for(let e of l.current)e()},[i,e]);(0,B.useEffect)(()=>{c.current=void 0,s(void 0)},[n]),(0,B.useEffect)(()=>{let t=!0;async function r(){try{let r=await n.require(xt).get({recordId:e});t&&u(r)}catch(n){console.warn(`Grove could not read the approval`,n),t&&i(e,{view:null,failed:!0})}}return r(),()=>{t=!1}},[n,e,t,u,i]);let d=o?.canAnswer===!0&&o.record.state===`pending`,f=o?.canSetAutoApprove===!0,p=o?.record.module,m=o?.record.access;return et({source:(0,B.useMemo)(()=>{if(d)return{snapshot:()=>c.current,subscribe:e=>(l.current.add(e),()=>{l.current.delete(e)}),answer:async e=>{let t=n.require(xt),r=e.decision===`always-allow`?void 0:{recordId:e.recordId,decision:e.decision,expectedRevision:e.expectedRevision};if(r===void 0)return{kind:`refused`,reason:`not-eligible`};let i=await t.answer(e.denialNote===void 0?r:{...r,denialNote:e.denialNote});return i.kind===`answered`&&u(i.view),i},family:!f||p===void 0||m===void 0?void 0:{label:`Always approve this family`,enable:async()=>(await n.require(xt).setAutoApprove({scope:{agentId:r},family:{module:p,access:m},enabled:!0})).kind===`updated`}}},[d,n,r,f,p,m,u]),store:a,enabled:!0,home:``,width:72,noteLimit:512,onFailure:tr}),null}function tr(e){console.warn($n,e)}function nr({capabilities:e,agentId:t,children:n}){let r=ve(),i=(0,B.useMemo)(()=>{let e=new Set;for(let t of[...r.settled,...r.tail])if(t.kind===`tool_group`)for(let n of t.tools){let t=Xn(n);t!==void 0&&e.add(t)}return[...e]},[r.settled,r.tail]),[a,o]=(0,B.useState)(new Map),[s,c]=(0,B.useState)(new Map),l=(0,B.useCallback)((e,t)=>{o(n=>new Map(n).set(e,t))},[]),u=(0,B.useMemo)(()=>({entry:e=>a.get(e),refresh:e=>{c(t=>new Map(t).set(e,(t.get(e)??0)+1))},agentId:t}),[a,t]);return(0,V.jsxs)(Zn.Provider,{value:e===void 0?void 0:u,children:[e===void 0?null:i.map(n=>(0,V.jsx)(er,{recordId:n,attempt:s.get(n)??0,capabilities:e,agentId:t,publish:l},n)),n]})}var rr={requested:`Approval requested.`,pending:`Pending approval.`,approved:`Approved. Waiting to run.`,applied:`Done.`,denied:`Denied.`,expired:`Expired. Nothing ran.`,claimed:`Dispatch in progress.`,outcome_unknown:`Outcome unknown. Check before trying again.`};function ir({view:e,scope:t,onRefresh:n,onAnswer:r}){let{record:i}=e,a=e.canAnswer&&i.state===`pending`;return(0,V.jsxs)(Se,{role:`group`,"aria-label":`Approval request`,density:`compact`,children:[(0,V.jsxs)(we,{children:[(0,V.jsxs)(je,{children:[a?`Allow `:``,i.module,` · `,i.operation,a?`?`:``]}),(0,V.jsxs)(`p`,{children:[i.requester.displayName,` wants to use a connected tool.`]})]}),(0,V.jsxs)(Ne,{className:`min-w-0 space-y-2`,children:[(0,V.jsxs)(`p`,{children:[`Effect`,` `,i.access===`write`?`Changes data in Fungi`:`Changes things outside Fungi`,i.reversibility===`irreversible-external`?` · can't be undone`:``]}),(0,V.jsx)(`p`,{role:`status`,children:a?`Waiting for your answer.`:rr[i.state]}),(0,V.jsxs)(`details`,{children:[(0,V.jsx)(`summary`,{children:`Details`}),(0,V.jsxs)(`p`,{children:[`Requester: `,i.requester.principalId]}),(0,V.jsxs)(`p`,{children:[`Agent: `,i.requester.displayName,` ·`,` `,i.requester.agentId??`none`]}),(0,V.jsxs)(`p`,{children:[`Session: `,i.requester.sessionId??`none`]}),(0,V.jsxs)(`p`,{children:[`Request: `,i.module,`.`,i.operation,` · `,i.access]}),(0,V.jsxs)(`p`,{children:[`Undo:`,` `,i.reversibility===`irreversible-external`?`Can't be undone`:`Can be undone`]}),(0,V.jsxs)(`p`,{children:[`Can answer: `,e.canAnswer?`Yes`:`No`]}),(0,V.jsxs)(`p`,{children:[`Can set auto-approve: `,e.canSetAutoApprove?`Yes`:`No`]}),i.by?.kind===`policy`?(0,V.jsx)(`p`,{children:`Auto-approved by policy`}):null,(0,V.jsx)(`p`,{children:i.description.title}),(0,V.jsxs)(`p`,{className:`break-all`,children:[`Input: `,i.description.inputBytes,` bytes · SHA-256`,` `,i.description.inputSha256]}),(0,V.jsxs)(`p`,{children:[`Record: `,i.recordId,` · revision `,i.revision]}),e.canSetAutoApprove?(0,V.jsxs)(`p`,{children:[`Policy scope:`,` `,t.agentId===null?`whole home`:`agent ${t.agentId}`]}):null]})]}),(0,V.jsxs)(Le,{className:`flex flex-wrap gap-2`,children:[a?(0,V.jsx)(F,{variant:`outline`,onClick:r,children:`Answer`}):null,(0,V.jsx)(F,{variant:`ghost`,onClick:n,children:`Refresh approval`})]})]})}function ar({recordId:e}){let t=Qn(),n=Be(),r=t?.entry(e);return t===void 0||r===void 0?null:r.failed?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{role:`alert`,children:`Couldn't load this approval. Try again.`}),(0,V.jsx)(F,{variant:`ghost`,onClick:()=>{t.refresh(e)},children:`Refresh approval`})]}):r.view===null||r.view.record.state===`expired`?null:(0,V.jsx)(ir,{view:r.view,scope:{agentId:t.agentId},onRefresh:()=>{t.refresh(e)},onAnswer:()=>{n.awaiting.focus()}})}var or=(0,B.forwardRef)(function({heading:e,eyebrow:t,cover:n,action:r,children:i,className:a,...o},s){return(0,V.jsxs)(Se,{...o,className:R(`caps-game-share`,a),ref:s,children:[n?(0,V.jsx)(`div`,{className:`caps-game-share-cover`,children:n}):null,(0,V.jsxs)(we,{children:[t,(0,V.jsx)(`h3`,{className:`caps-game-share-heading`,children:e})]}),(0,V.jsx)(Ne,{className:`gap-sm`,children:i}),(0,V.jsx)(Le,{children:(0,V.jsx)(F,{asChild:!0,variant:`primary`,className:`caps-game-share-action`,children:r})})]})});function sr(e){let t=0;return e.map(e=>{let n={...e,offset:t};return t+=e.text.length,n})}function cr({value:e,label:t,fieldLabel:n,displayValue:r,layout:i,title:a,tokens:o,className:s,...c}){let l=(0,B.useId)(),[u,d]=(0,B.useState)({kind:`ready`}),f=o?o.map(e=>e.text).join(``):e,p=async()=>{d(await navigator.clipboard.writeText(f).then(()=>({kind:`copied`}),e=>({kind:`failed`,cause:e})))};if(n!==void 0)return(0,V.jsxs)(`div`,{...c,className:R(`caps-copy-field-input`,s),children:[(0,V.jsx)(Me,{htmlFor:l,children:n}),(0,V.jsxs)(xe,{children:[(0,V.jsx)(Ie,{className:`caps-copy-field-control`,"aria-label":n,id:l,onFocus:e=>{e.currentTarget.select()},readOnly:!0,value:r??f}),(0,V.jsx)(F,{onClick:()=>void p(),size:`sm`,variant:`outline`,children:u.kind===`copied`?`Copied`:t??`Copy`})]}),u.kind===`failed`?(0,V.jsx)(`span`,{role:`status`,children:`Could not copy. Select the text to copy it.`}):null]});let m=u.kind===`copied`?`Copied`:u.kind===`failed`?`Copy failed`:t??`Copy`;return i===`block`?(0,V.jsxs)(`figure`,{...c,className:R(`caps-copy-field-block`,s),"data-state":u.kind,children:[(0,V.jsxs)(`figcaption`,{className:`caps-copy-field-header`,children:[(0,V.jsx)(`span`,{className:`caps-copy-field-title`,children:a}),(0,V.jsxs)(F,{onClick:()=>void p(),size:`sm`,variant:u.kind===`copied`?`ghost`:`outline`,children:[u.kind===`copied`?(0,V.jsx)(Re,{"aria-hidden":`true`,size:15}):(0,V.jsx)(ye,{"aria-hidden":`true`,size:15}),m]}),(0,V.jsx)(Ae,{role:`status`,children:u.kind===`copied`?`Copied to the clipboard`:u.kind===`failed`?`Could not copy. Select the code to copy it.`:``})]}),(0,V.jsx)(`pre`,{className:`caps-copy-field-code`,tabIndex:0,children:(0,V.jsx)(`code`,{children:o?sr(o).map(e=>(0,V.jsx)(`span`,{className:`caps-copy-field-token`,"data-kind":e.kind,children:e.text},e.offset)):f})})]}):(0,V.jsxs)(`div`,{...c,className:R(`caps-copy-field`,s),children:[(0,V.jsx)(`code`,{className:`caps-copy-field-value`,children:f}),(0,V.jsxs)(F,{"aria-label":`${m}: ${f}`,onClick:()=>void p(),size:`sm`,variant:`outline`,children:[u.kind===`copied`?(0,V.jsx)(Re,{size:15}):(0,V.jsx)(ye,{size:15}),m]})]})}var lr=u({game:u({title:p().min(1),summary:p(),coverUrl:t().nullable(),shareUrl:t()})});function ur(e){let t=/(?:^|\n)\s*Share:\s*(https?:\/\/[^\s<>]+)/iu.exec(e);if(!t?.[1])return null;let n=t[1].replace(/[.,;!?]+$/u,``);if(!URL.canParse(n))return null;let r=new URL(n);return r.username||r.password||r.hash||r.protocol===`http:`&&![`localhost`,`127.0.0.1`].includes(r.hostname)?null:r.href}function dr(e){return ur(e)?e.split(`
|
|
3
|
-
`).filter(e=>!/^\s*Share:\s*/iu.test(e)).join(`
|
|
4
|
-
`).trim():e}function fr(e){let t=new URL(e),n=/^\/([a-z0-9]+(?:-[a-z0-9]+)*)\/?$/u.exec(t.pathname)?.[1];return!n||t.search?null:new URL(`/api/games/${n}`,t.origin)}function pr({reply:e,previewGame:t}){let n=ur(e),r=n?fr(n):null,{data:i}=be({queryKey:Te.of(null,`game-share`,n),enabled:r!==null&&t===void 0,queryFn:async({signal:e})=>{if(!r)return null;let t=await fetch(r,{signal:e});if(!t.ok)return null;let i=lr.safeParse(await t.json());return i.success&&i.data.game.shareUrl===n?i.data.game:null}}),a=t??i;if(!n)return null;let o=new URL(n),s=`${o.host}${o.pathname.replace(/\/$/u,``)}`,c=a?.coverUrl&&r?t?a.coverUrl:new URL(`${r.pathname}/cover`,r.origin).href:null;return(0,V.jsxs)(or,{"data-game-share-card":`true`,"data-theme":`vishnu`,heading:a?.title??`Your game is ready`,eyebrow:(0,V.jsx)(ke,{tone:`secondary`,variant:`quiet`,children:`Made with your Agent`}),cover:c?(0,V.jsx)(`img`,{alt:`A scene from ${a?.title??`your game`}`,src:c}):null,action:(0,V.jsx)(`a`,{href:n,rel:`noopener noreferrer`,target:`_blank`,children:`Play ↗`}),children:[a?.summary?(0,V.jsx)(`p`,{className:`text-sm`,children:a.summary}):null,(0,V.jsx)(cr,{displayValue:s,fieldLabel:`Share link`,label:`Copy link`,value:n})]})}var mr=[Nt,Kt,tn,bn,jn],hr=e=>(0,V.jsx)(pr,{reply:e});function gr({prefill:e,onPrefilled:t}){let n=pe(),r=(0,B.useRef)(null);return(0,B.useEffect)(()=>{!e||r.current===e.requestId||(r.current=e.requestId,n.setDraft(e.text),t())},[n.setDraft,t,e]),null}function _r({session:e,draftIdentity:t,connection:n,commands:r,prefill:i=null,onPrefilled:a=()=>void 0,onOpen:o}){let s=n?.ui??null,c=n?.capabilities,l=(0,B.useCallback)(e=>Mn(s,e),[s]),u=(0,B.useCallback)(e=>{let t=Xn(e);return t!==void 0&&c!==void 0?(0,V.jsx)(ar,{recordId:t},t):s?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Fn,{item:e,ui:s}),(0,V.jsx)(Jn,{item:e,capabilities:c})]}):null},[s,c]),d=(0,B.useCallback)(e=>c!==void 0&&Kn(e),[c]),f=(0,B.useCallback)(e=>{Nn(s,e)},[s]);return(0,V.jsxs)(_e,{session:e,draftIdentity:t,clients:mr,authorOf:ne,onToast:f,children:[(0,V.jsx)(gr,{prefill:i,onPrefilled:a}),(0,V.jsx)(nr,{capabilities:c,agentId:t.agentId,children:(0,V.jsx)(Fe,{onLink:l,onOpen:o,composerActionVariant:`outline`,commands:r,renderAssistantAttachment:hr,formatAssistantText:dr,renderToolActions:u,claimsToolMedia:d})})]})}export{_r as ParakeetConversation};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e,t}from"./rolldown-runtime-hePW80VL.js";import{j as n,mt as r,r as i,t as a,va as o}from"./Effect-CtszBD7f.js";import{i as s,t as c}from"./document-Bagsf-XI.js";import{$ as l,B as u,F as d,G as f,H as p,I as m,J as h,K as g,L as _,M as ee,N as v,P as y,Q as te,R as ne,U as b,V as re,W as x,X as S,Y as C,Z as ie,et as ae,j as oe,nt as se,q as w,rt as T,tt as E,z as ce}from"./index-CCJvRnqn.js";var D=(e,t)=>{if(te(t,`<`)){let n=t[1]===`<`,r=e._tail,i=r?r._offset+r._delay:0;return n?i:i+r.duration}},O=(e,t)=>{let n=e.iterationDuration;if(n===1e-11&&(n=0),C(t))return n;if(g(+t))return+t;let r=t,i=e?e.labels:null,a=!f(i),o=D(e,r),s=!C(o),c=se.exec(r);if(c){let e=c[0],t=r.split(e),l=a&&t[0]?i[t[0]]:n,u=s?o:a?l:n,d=+t[1];return ce(u,d,e[0])}return s?o:a?C(i[r])?n:i[r]:n};function le(e){return p((e.iterationDuration+e._loopDelay)*e.iterationCount-e._loopDelay)||1e-11}function k(e,t,n,r,i,a){let o=g(e.duration)&&e.duration<=1e-11?n-E:n;t.composition&&ne(t,o,1,1,T.AUTO);let s=r?new oe(r,e,t,o,!1,i,a):new y(e,t,o);return t.composition&&s.init(!0),re(t,s),b(t,e=>{let n=e._offset+e._delay+e.duration;n>t.iterationDuration&&(t.iterationDuration=n)}),t.duration=le(t),t}var A=0,j=class extends y{constructor(e={}){super(e,null,0),++A,this.id=C(e.id)?A:e.id,this.duration=0,this.labels={};let t=e.defaults,n=l.defaults;this.defaults=t?S(t,n):n,this.composition=u(e.composition,!0),this.onRender=e.onRender||n.onRender;let r=u(e.playbackEase,n.playbackEase);this._ease=r?ee(r):null,this.iterationDuration=0}add(e,t,n){let r=w(t),i=w(e);if(r||i){if(this._hasChildren=!0,r){let r=t,i=l.editor&&l.editor.addTimelineChild,a=n&&n.type===`Stagger`&&l.editor,o=x(n)?n:null;if(o||a){let t=v(e),a=this.duration,s=this.iterationDuration,c=r.id,u=0,d=t.length,f=i?i(e,r,this.id,n,d):null,p=o||l.editor.resolveStagger(n.defaultValue);t.forEach(e=>{let n={...f||r};this.duration=a,this.iterationDuration=s,C(c)||(n.id=c+`-`+u);let i=O(this,p(e,u,t,null,this));k(n,this,i,e,u,t),u++})}else{let t=i?i(e,r,this.id,n):r,a=n&&n.type?n.defaultValue:n;k(t,this,O(this,a),e)}}else k(e,this,O(this,t));return this.composition&&this.init(!0),this}}sync(e,t){if(C(e)||e&&C(e.pause))return this;e.pause();let n=+(e.effect?e.effect.getTiming().duration:e.duration);!C(e)&&!C(e.persist)&&(e.persist=!0);let r=l.editor,i=r&&r.addTimelineChild;r&&r.addTimelineSync&&(t=r.addTimelineSync(e,t,this.id),r.addTimelineChild=null);let a=this.add(e,{currentTime:[0,n],duration:n,delay:0,ease:`linear`,playbackEase:`linear`},t);return r&&(r.addTimelineChild=i),a}set(e,t,n){return C(t)?this:(t.duration=E,t.composition=ae.replace,this.add(e,t,n))}call(e,t){return C(e)||e&&!x(e)?this:(l.editor&&l.editor.addTimelineCall&&(t=l.editor.addTimelineCall(e,t,this.id)),this.add({duration:0,delay:0,onComplete:()=>e(this)},t))}label(e,t){return C(e)||e&&!h(e)?this:(l.editor&&l.editor.addTimelineLabel&&(t=l.editor.addTimelineLabel(e,t,this.id)),this.labels[e]=O(this,t),this)}remove(e,t){return m(v(e),this,t),this}stretch(e){let t=this.duration;if(t===ie(e))return this;let n=e/t,r=this.labels;b(this,e=>e.stretch(e.duration*n));for(let e in r)r[e]*=n;return super.stretch(e)}refresh(){return b(this,e=>{e.refresh&&e.refresh()}),this}revert(){return super.revert(),b(this,e=>e.revert,!0),_(this)}then(e){return super.then(e)}},M=e=>l.editor?l.editor.addTimeline(e):new j(e).init(),N=t(((e,t)=>{(function(e,n){typeof t==`object`&&t.exports?t.exports=n():e.Zdog=n()})(e,function(){var e={};e.TAU=Math.PI*2,e.extend=function(e,t){for(var n in t)e[n]=t[n];return e},e.lerp=function(e,t,n){return(t-e)*n+e},e.modulo=function(e,t){return(e%t+t)%t};var t={2:function(e){return e*e},3:function(e){return e*e*e},4:function(e){return e*e*e*e},5:function(e){return e*e*e*e*e}};return e.easeInOut=function(e,n){if(n==1)return e;e=Math.max(0,Math.min(1,e));var r=e<.5,i=r?e:1-e;i/=.5;var a=(t[n]||t[2])(i);return a/=2,r?a:1-a},e})})),P=t(((e,t)=>{(function(e,n){typeof t==`object`&&t.exports?t.exports=n():e.Zdog.CanvasRenderer=n()})(e,function(){var e={isCanvas:!0};return e.begin=function(e){e.beginPath()},e.move=function(e,t,n){e.moveTo(n.x,n.y)},e.line=function(e,t,n){e.lineTo(n.x,n.y)},e.bezier=function(e,t,n,r,i){e.bezierCurveTo(n.x,n.y,r.x,r.y,i.x,i.y)},e.closePath=function(e){e.closePath()},e.setPath=function(){},e.renderPath=function(t,n,r,i){this.begin(t,n),r.forEach(function(r){r.render(t,n,e)}),i&&this.closePath(t,n)},e.stroke=function(e,t,n,r,i){n&&(e.strokeStyle=r,e.lineWidth=i,e.stroke())},e.fill=function(e,t,n,r){n&&(e.fillStyle=r,e.fill())},e.end=function(){},e})})),F=t(((e,t)=>{(function(e,n){typeof t==`object`&&t.exports?t.exports=n():e.Zdog.SvgRenderer=n()})(e,function(){var e={isSvg:!0},t=e.round=function(e){return Math.round(e*1e3)/1e3};function n(e){return t(e.x)+`,`+t(e.y)+` `}return e.begin=function(){},e.move=function(e,t,r){return`M`+n(r)},e.line=function(e,t,r){return`L`+n(r)},e.bezier=function(e,t,r,i,a){return`C`+n(r)+n(i)+n(a)},e.closePath=function(){return`Z`},e.setPath=function(e,t,n){t.setAttribute(`d`,n)},e.renderPath=function(t,n,r,i){var a=``;r.forEach(function(r){a+=r.render(t,n,e)}),i&&(a+=this.closePath(t,n)),this.setPath(t,n,a)},e.stroke=function(e,t,n,r,i){n&&(t.setAttribute(`stroke`,r),t.setAttribute(`stroke-width`,i))},e.fill=function(e,t,n,r){var i=n?r:`none`;t.setAttribute(`fill`,i)},e.end=function(e,t){e.appendChild(t)},e})})),I=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N());else{var r=e.Zdog;r.Vector=n(r)}})(e,function(e){function t(e){this.set(e)}var n=e.TAU;t.prototype.set=function(e){return this.x=e&&e.x||0,this.y=e&&e.y||0,this.z=e&&e.z||0,this},t.prototype.write=function(e){return e?(this.x=e.x==null?this.x:e.x,this.y=e.y==null?this.y:e.y,this.z=e.z==null?this.z:e.z,this):this},t.prototype.rotate=function(e){if(e)return this.rotateZ(e.z),this.rotateY(e.y),this.rotateX(e.x),this},t.prototype.rotateZ=function(e){r(this,e,`x`,`y`)},t.prototype.rotateX=function(e){r(this,e,`y`,`z`)},t.prototype.rotateY=function(e){r(this,e,`x`,`z`)};function r(e,t,r,i){if(!(!t||t%n===0)){var a=Math.cos(t),o=Math.sin(t),s=e[r],c=e[i];e[r]=s*a-c*o,e[i]=c*a+s*o}}t.prototype.isSame=function(e){return e?this.x===e.x&&this.y===e.y&&this.z===e.z:!1},t.prototype.add=function(e){return e?(this.x+=e.x||0,this.y+=e.y||0,this.z+=e.z||0,this):this},t.prototype.subtract=function(e){return e?(this.x-=e.x||0,this.y-=e.y||0,this.z-=e.z||0,this):this},t.prototype.multiply=function(e){return e==null||(typeof e==`number`?(this.x*=e,this.y*=e,this.z*=e):(this.x*=e.x==null?1:e.x,this.y*=e.y==null?1:e.y,this.z*=e.z==null?1:e.z)),this},t.prototype.transform=function(e,t,n){return this.multiply(n),this.rotate(t),this.add(e),this},t.prototype.lerp=function(t,n){return this.x=e.lerp(this.x,t.x||0,n),this.y=e.lerp(this.y,t.y||0,n),this.z=e.lerp(this.z,t.z||0,n),this},t.prototype.magnitude=function(){return i(this.x*this.x+this.y*this.y+this.z*this.z)};function i(e){return Math.abs(e-1)<1e-8?1:Math.sqrt(e)}return t.prototype.magnitude2d=function(){return i(this.x*this.x+this.y*this.y)},t.prototype.copy=function(){return new t(this)},t})})),L=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),I(),P(),F());else{var r=e.Zdog;r.Anchor=n(r,r.Vector,r.CanvasRenderer,r.SvgRenderer)}})(e,function(e,t,n,r){var i=e.TAU,a={x:1,y:1,z:1};function o(e){this.create(e||{})}o.prototype.create=function(n){this.children=[],e.extend(this,this.constructor.defaults),this.setOptions(n),this.translate=new t(n.translate),this.rotate=new t(n.rotate),this.scale=new t(a).multiply(this.scale),this.origin=new t,this.renderOrigin=new t,this.addTo&&this.addTo.addChild(this)},o.defaults={},o.optionKeys=Object.keys(o.defaults).concat([`rotate`,`translate`,`scale`,`addTo`]),o.prototype.setOptions=function(e){var t=this.constructor.optionKeys;for(var n in e)t.indexOf(n)!=-1&&(this[n]=e[n])},o.prototype.addChild=function(e){this.children.indexOf(e)==-1&&(e.remove(),e.addTo=this,this.children.push(e))},o.prototype.removeChild=function(e){var t=this.children.indexOf(e);t!=-1&&this.children.splice(t,1)},o.prototype.remove=function(){this.addTo&&this.addTo.removeChild(this)},o.prototype.update=function(){this.reset(),this.children.forEach(function(e){e.update()}),this.transform(this.translate,this.rotate,this.scale)},o.prototype.reset=function(){this.renderOrigin.set(this.origin)},o.prototype.transform=function(e,t,n){this.renderOrigin.transform(e,t,n),this.children.forEach(function(r){r.transform(e,t,n)})},o.prototype.updateGraph=function(){this.update(),this.updateFlatGraph(),this.flatGraph.forEach(function(e){e.updateSortValue()}),this.flatGraph.sort(o.shapeSorter)},o.shapeSorter=function(e,t){return e.sortValue-t.sortValue},Object.defineProperty(o.prototype,"flatGraph",{get:function(){return this._flatGraph||this.updateFlatGraph(),this._flatGraph},set:function(e){this._flatGraph=e}}),o.prototype.updateFlatGraph=function(){this.flatGraph=this.getFlatGraph()},o.prototype.getFlatGraph=function(){var e=[this];return this.addChildFlatGraph(e)},o.prototype.addChildFlatGraph=function(e){return this.children.forEach(function(t){var n=t.getFlatGraph();Array.prototype.push.apply(e,n)}),e},o.prototype.updateSortValue=function(){this.sortValue=this.renderOrigin.z},o.prototype.render=function(){},o.prototype.renderGraphCanvas=function(e){if(!e)throw Error(`ctx is `+e+`. Canvas context required for render. Check .renderGraphCanvas( ctx ).`);this.flatGraph.forEach(function(t){t.render(e,n)})},o.prototype.renderGraphSvg=function(e){if(!e)throw Error(`svg is `+e+`. SVG required for render. Check .renderGraphSvg( svg ).`);this.flatGraph.forEach(function(t){t.render(e,r)})},o.prototype.copy=function(t){var n={};this.constructor.optionKeys.forEach(function(e){n[e]=this[e]},this),e.extend(n,t);var r=this.constructor;return new r(n)},o.prototype.copyGraph=function(e){var t=this.copy(e);return this.children.forEach(function(e){e.copyGraph({addTo:t})}),t},o.prototype.normalizeRotate=function(){this.rotate.x=e.modulo(this.rotate.x,i),this.rotate.y=e.modulo(this.rotate.y,i),this.rotate.z=e.modulo(this.rotate.z,i)};function s(t){return function(n){function r(e){this.create(e||{})}return r.prototype=Object.create(t.prototype),r.prototype.constructor=r,r.defaults=e.extend({},t.defaults),e.extend(r.defaults,n),r.optionKeys=t.optionKeys.slice(0),Object.keys(r.defaults).forEach(function(e){!r.optionKeys.indexOf(e)!=1&&r.optionKeys.push(e)}),r.subclass=s(r),r}}return o.subclass=s(o),o})})),R=t(((e,t)=>{(function(e,n){typeof t==`object`&&t.exports?t.exports=n():e.Zdog.Dragger=n()})(e,function(){var e=typeof window<`u`,t=`mousedown`,n=`mousemove`,r=`mouseup`;e&&(window.PointerEvent?(t=`pointerdown`,n=`pointermove`,r=`pointerup`):`ontouchstart`in window&&(t=`touchstart`,n=`touchmove`,r=`touchend`));function i(){}function a(e){this.create(e||{})}return a.prototype.create=function(e){this.onDragStart=e.onDragStart||i,this.onDragMove=e.onDragMove||i,this.onDragEnd=e.onDragEnd||i,this.bindDrag(e.startElement)},a.prototype.bindDrag=function(e){e=this.getQueryElement(e),e&&(e.style.touchAction=`none`,e.addEventListener(t,this))},a.prototype.getQueryElement=function(e){return typeof e==`string`&&(e=document.querySelector(e)),e},a.prototype.handleEvent=function(e){var t=this[`on`+e.type];t&&t.call(this,e)},a.prototype.onmousedown=a.prototype.onpointerdown=function(e){this.dragStart(e,e)},a.prototype.ontouchstart=function(e){this.dragStart(e,e.changedTouches[0])},a.prototype.dragStart=function(t,i){t.preventDefault(),this.dragStartX=i.pageX,this.dragStartY=i.pageY,e&&(window.addEventListener(n,this),window.addEventListener(r,this)),this.onDragStart(i)},a.prototype.ontouchmove=function(e){this.dragMove(e,e.changedTouches[0])},a.prototype.onmousemove=a.prototype.onpointermove=function(e){this.dragMove(e,e)},a.prototype.dragMove=function(e,t){e.preventDefault();var n=t.pageX-this.dragStartX,r=t.pageY-this.dragStartY;this.onDragMove(t,n,r)},a.prototype.onmouseup=a.prototype.onpointerup=a.prototype.ontouchend=a.prototype.dragEnd=function(){window.removeEventListener(n,this),window.removeEventListener(r,this),this.onDragEnd()},a})})),z=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),L(),R());else{var r=e.Zdog;r.Illustration=n(r,r.Anchor,r.Dragger)}})(e,function(e,t,n){function r(){}var i=e.TAU,a=t.subclass({element:void 0,centered:!0,zoom:1,dragRotate:!1,resize:!1,onPrerender:r,onDragStart:r,onDragMove:r,onDragEnd:r,onResize:r});e.extend(a.prototype,n.prototype),a.prototype.create=function(e){t.prototype.create.call(this,e),n.prototype.create.call(this,e),this.setElement(this.element),this.setDragRotate(this.dragRotate),this.setResize(this.resize)},a.prototype.setElement=function(e){if(e=this.getQueryElement(e),!e)throw Error(`Zdog.Illustration element required. Set to `+e);var t=e.nodeName.toLowerCase();t==`canvas`?this.setCanvas(e):t==`svg`&&this.setSvg(e)},a.prototype.setSize=function(e,t){e=Math.round(e),t=Math.round(t),this.isCanvas?this.setSizeCanvas(e,t):this.isSvg&&this.setSizeSvg(e,t)},a.prototype.setResize=function(e){this.resize=e,this.resizeListener||=this.onWindowResize.bind(this),e?(window.addEventListener(`resize`,this.resizeListener),this.onWindowResize()):window.removeEventListener(`resize`,this.resizeListener)},a.prototype.onWindowResize=function(){this.setMeasuredSize(),this.onResize(this.width,this.height)},a.prototype.setMeasuredSize=function(){var e,t;if(this.resize==`fullscreen`)e=window.innerWidth,t=window.innerHeight;else{var n=this.element.getBoundingClientRect();e=n.width,t=n.height}this.setSize(e,t)},a.prototype.renderGraph=function(e){this.isCanvas?this.renderGraphCanvas(e):this.isSvg&&this.renderGraphSvg(e)},a.prototype.updateRenderGraph=function(e){this.updateGraph(),this.renderGraph(e)},a.prototype.setCanvas=function(e){this.element=e,this.isCanvas=!0,this.ctx=this.element.getContext(`2d`),this.setSizeCanvas(e.width,e.height)},a.prototype.setSizeCanvas=function(e,t){this.width=e,this.height=t;var n=this.pixelRatio=window.devicePixelRatio||1;this.element.width=this.canvasWidth=e*n,this.element.height=this.canvasHeight=t*n,n>1&&!this.resize&&(this.element.style.width=e+`px`,this.element.style.height=t+`px`)},a.prototype.renderGraphCanvas=function(e){e||=this,this.prerenderCanvas(),t.prototype.renderGraphCanvas.call(e,this.ctx),this.postrenderCanvas()},a.prototype.prerenderCanvas=function(){var e=this.ctx;if(e.lineCap=`round`,e.lineJoin=`round`,e.clearRect(0,0,this.canvasWidth,this.canvasHeight),e.save(),this.centered){var t=this.width/2*this.pixelRatio,n=this.height/2*this.pixelRatio;e.translate(t,n)}var r=this.pixelRatio*this.zoom;e.scale(r,r),this.onPrerender(e)},a.prototype.postrenderCanvas=function(){this.ctx.restore()},a.prototype.setSvg=function(e){this.element=e,this.isSvg=!0,this.pixelRatio=1;var t=e.getAttribute(`width`),n=e.getAttribute(`height`);this.setSizeSvg(t,n)},a.prototype.setSizeSvg=function(e,t){this.width=e,this.height=t;var n=e/this.zoom,r=t/this.zoom,i=this.centered?-n/2:0,a=this.centered?-r/2:0;this.element.setAttribute(`viewBox`,i+` `+a+` `+n+` `+r),this.resize?(this.element.removeAttribute(`width`),this.element.removeAttribute(`height`)):(this.element.setAttribute(`width`,e),this.element.setAttribute(`height`,t))},a.prototype.renderGraphSvg=function(e){e||=this,o(this.element),this.onPrerender(this.element),t.prototype.renderGraphSvg.call(e,this.element)};function o(e){for(;e.firstChild;)e.removeChild(e.firstChild)}return a.prototype.setDragRotate=function(e){if(e)e===!0&&(e=this);else return;this.dragRotate=e,this.bindDrag(this.element)},a.prototype.dragStart=function(){this.dragStartRX=this.dragRotate.rotate.x,this.dragStartRY=this.dragRotate.rotate.y,n.prototype.dragStart.apply(this,arguments)},a.prototype.dragMove=function(e,t){var r=t.pageX-this.dragStartX,a=t.pageY-this.dragStartY,o=Math.min(this.width,this.height),s=r/o*i,c=a/o*i;this.dragRotate.rotate.x=this.dragStartRX-c,this.dragRotate.rotate.y=this.dragStartRY-s,n.prototype.dragMove.apply(this,arguments)},a})})),B=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(I());else{var r=e.Zdog;r.PathCommand=n(r.Vector)}})(e,function(e){function t(t,i,a){this.method=t,this.points=i.map(n),this.renderPoints=i.map(r),this.previousPoint=a,this.endRenderPoint=this.renderPoints[this.renderPoints.length-1],t==`arc`&&(this.controlPoints=[new e,new e])}function n(t){return t instanceof e?t:new e(t)}function r(t){return new e(t)}t.prototype.reset=function(){var e=this.points;this.renderPoints.forEach(function(t,n){var r=e[n];t.set(r)})},t.prototype.transform=function(e,t,n){this.renderPoints.forEach(function(r){r.transform(e,t,n)})},t.prototype.render=function(e,t,n){return this[this.method](e,t,n)},t.prototype.move=function(e,t,n){return n.move(e,t,this.renderPoints[0])},t.prototype.line=function(e,t,n){return n.line(e,t,this.renderPoints[0])},t.prototype.bezier=function(e,t,n){var r=this.renderPoints[0],i=this.renderPoints[1],a=this.renderPoints[2];return n.bezier(e,t,r,i,a)};var i=9/16;return t.prototype.arc=function(e,t,n){var r=this.previousPoint,a=this.renderPoints[0],o=this.renderPoints[1],s=this.controlPoints[0],c=this.controlPoints[1];return s.set(r).lerp(a,i),c.set(o).lerp(a,i),n.bezier(e,t,s,c,o)},t})})),V=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),I(),B(),L());else{var r=e.Zdog;r.Shape=n(r,r.Vector,r.PathCommand,r.Anchor)}})(e,function(e,t,n,r){var i=r.subclass({stroke:1,fill:!1,color:`#333`,closed:!0,visible:!0,path:[{}],front:{z:1},backface:!0});i.prototype.create=function(e){r.prototype.create.call(this,e),this.updatePath(),this.front=new t(e.front||this.front),this.renderFront=new t(this.front),this.renderNormal=new t};var a=[`move`,`line`,`bezier`,`arc`];i.prototype.updatePath=function(){this.setPath(),this.updatePathCommands()},i.prototype.setPath=function(){},i.prototype.updatePathCommands=function(){var e;this.pathCommands=this.path.map(function(t,r){var i=Object.keys(t),o=i[0],s=t[o];(i.length!=1||a.indexOf(o)==-1)&&(o=`line`,s=t),(o==`line`||o==`move`)&&!Array.isArray(s)&&(s=[s]),o=r===0?`move`:o;var c=new n(o,s,e);return e=c.endRenderPoint,c})},i.prototype.reset=function(){this.renderOrigin.set(this.origin),this.renderFront.set(this.front),this.pathCommands.forEach(function(e){e.reset()})},i.prototype.transform=function(e,t,n){this.renderOrigin.transform(e,t,n),this.renderFront.transform(e,t,n),this.renderNormal.set(this.renderOrigin).subtract(this.renderFront),this.pathCommands.forEach(function(r){r.transform(e,t,n)}),this.children.forEach(function(r){r.transform(e,t,n)})},i.prototype.updateSortValue=function(){var e=this.pathCommands.length,t=this.pathCommands[0].endRenderPoint,n=this.pathCommands[e-1].endRenderPoint;e>2&&t.isSame(n)&&--e;for(var r=0,i=0;i<e;i++)r+=this.pathCommands[i].endRenderPoint.z;this.sortValue=r/e},i.prototype.render=function(e,t){var n=this.pathCommands.length;if(!(!this.visible||!n)&&(this.isFacingBack=this.renderNormal.z>0,!(!this.backface&&this.isFacingBack))){if(!t)throw Error(`Zdog renderer required. Set to `+t);var r=n==1;t.isCanvas&&r?this.renderCanvasDot(e,t):this.renderPath(e,t)}};var o=e.TAU;i.prototype.renderCanvasDot=function(e){var t=this.getLineWidth();if(t){e.fillStyle=this.getRenderColor();var n=this.pathCommands[0].endRenderPoint;e.beginPath();var r=t/2;e.arc(n.x,n.y,r,0,o),e.fill()}},i.prototype.getLineWidth=function(){return this.stroke?this.stroke==1?1:this.stroke:0},i.prototype.getRenderColor=function(){return typeof this.backface==`string`&&this.isFacingBack?this.backface:this.color},i.prototype.renderPath=function(e,t){var n=this.getRenderElement(e,t),r=(this.pathCommands.length!=2||this.pathCommands[1].method!=`line`)&&this.closed,i=this.getRenderColor();t.renderPath(e,n,this.pathCommands,r),t.stroke(e,n,this.stroke,i,this.getLineWidth()),t.fill(e,n,this.fill,i),t.end(e,n)};var s=`http://www.w3.org/2000/svg`;return i.prototype.getRenderElement=function(e,t){if(t.isSvg)return this.svgElement||(this.svgElement=document.createElementNS(s,`path`),this.svgElement.setAttribute(`stroke-linecap`,`round`),this.svgElement.setAttribute(`stroke-linejoin`,`round`)),this.svgElement},i})})),H=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(L());else{var r=e.Zdog;r.Group=n(r.Anchor)}})(e,function(e){var t=e.subclass({updateSort:!1,visible:!0});return t.prototype.updateSortValue=function(){var t=0;this.flatGraph.forEach(function(e){e.updateSortValue(),t+=e.sortValue}),this.sortValue=t/this.flatGraph.length,this.updateSort&&this.flatGraph.sort(e.shapeSorter)},t.prototype.render=function(e,t){this.visible&&this.flatGraph.forEach(function(n){n.render(e,t)})},t.prototype.updateFlatGraph=function(){var e=[];this.flatGraph=this.addChildFlatGraph(e)},t.prototype.getFlatGraph=function(){return[this]},t})})),U=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(V());else{var r=e.Zdog;r.Rect=n(r.Shape)}})(e,function(e){var t=e.subclass({width:1,height:1});return t.prototype.setPath=function(){var e=this.width/2,t=this.height/2;this.path=[{x:-e,y:-t},{x:e,y:-t},{x:e,y:t},{x:-e,y:t}]},t})})),ue=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(V());else{var r=e.Zdog;r.RoundedRect=n(r.Shape)}})(e,function(e){var t=e.subclass({width:1,height:1,cornerRadius:.25,closed:!1});return t.prototype.setPath=function(){var e=this.width/2,t=this.height/2,n=Math.min(e,t),r=Math.min(this.cornerRadius,n),i=e-r,a=t-r,o=[{x:i,y:-t},{arc:[{x:e,y:-t},{x:e,y:-a}]}];a&&o.push({x:e,y:a}),o.push({arc:[{x:e,y:t},{x:i,y:t}]}),i&&o.push({x:-i,y:t}),o.push({arc:[{x:-e,y:t},{x:-e,y:a}]}),a&&o.push({x:-e,y:-a}),o.push({arc:[{x:-e,y:-t},{x:-i,y:-t}]}),i&&o.push({x:i,y:-t}),this.path=o},t})})),W=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(V());else{var r=e.Zdog;r.Ellipse=n(r.Shape)}})(e,function(e){var t=e.subclass({diameter:1,width:void 0,height:void 0,quarters:4,closed:!1});return t.prototype.setPath=function(){var e=this.width==null?this.diameter:this.width,t=this.height==null?this.diameter:this.height,n=e/2,r=t/2;this.path=[{x:0,y:-r},{arc:[{x:n,y:-r},{x:n,y:0}]}],this.quarters>1&&this.path.push({arc:[{x:n,y:r},{x:0,y:r}]}),this.quarters>2&&this.path.push({arc:[{x:-n,y:r},{x:-n,y:0}]}),this.quarters>3&&this.path.push({arc:[{x:-n,y:-r},{x:0,y:-r}]})},t})})),de=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),V());else{var r=e.Zdog;r.Polygon=n(r,r.Shape)}})(e,function(e,t){var n=t.subclass({sides:3,radius:.5}),r=e.TAU;return n.prototype.setPath=function(){this.path=[];for(var e=0;e<this.sides;e++){var t=e/this.sides*r-r/4,n=Math.cos(t)*this.radius,i=Math.sin(t)*this.radius;this.path.push({x:n,y:i})}},n})})),fe=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),I(),L(),W());else{var r=e.Zdog;r.Hemisphere=n(r,r.Vector,r.Anchor,r.Ellipse)}})(e,function(e,t,n,r){var i=r.subclass({fill:!0}),a=e.TAU;i.prototype.create=function(){r.prototype.create.apply(this,arguments),this.apex=new n({addTo:this,translate:{z:this.diameter/2}}),this.renderCentroid=new t},i.prototype.updateSortValue=function(){this.renderCentroid.set(this.renderOrigin).lerp(this.apex.renderOrigin,3/8),this.sortValue=this.renderCentroid.z},i.prototype.render=function(e,t){this.renderDome(e,t),r.prototype.render.apply(this,arguments)},i.prototype.renderDome=function(e,t){if(this.visible){var n=this.getDomeRenderElement(e,t),r=Math.atan2(this.renderNormal.y,this.renderNormal.x),i=this.diameter/2*this.renderNormal.magnitude(),o=this.renderOrigin.x,s=this.renderOrigin.y;if(t.isCanvas){var c=r+a/4,l=r-a/4;e.beginPath(),e.arc(o,s,i,c,l)}else t.isSvg&&(r=(r-a/4)/a*360,this.domeSvgElement.setAttribute(`d`,`M `+-i+`,0 A `+i+`,`+i+` 0 0 1 `+i+`,0`),this.domeSvgElement.setAttribute(`transform`,`translate(`+o+`,`+s+` ) rotate(`+r+`)`));t.stroke(e,n,this.stroke,this.color,this.getLineWidth()),t.fill(e,n,this.fill,this.color),t.end(e,n)}};var o=`http://www.w3.org/2000/svg`;return i.prototype.getDomeRenderElement=function(e,t){if(t.isSvg)return this.domeSvgElement||(this.domeSvgElement=document.createElementNS(o,`path`),this.domeSvgElement.setAttribute(`stroke-linecap`,`round`),this.domeSvgElement.setAttribute(`stroke-linejoin`,`round`)),this.domeSvgElement},i})})),pe=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),B(),V(),H(),W());else{var r=e.Zdog;r.Cylinder=n(r,r.PathCommand,r.Shape,r.Group,r.Ellipse)}})(e,function(e,t,n,r,i){function a(){}var o=r.subclass({color:`#333`,updateSort:!0});o.prototype.create=function(){r.prototype.create.apply(this,arguments),this.pathCommands=[new t(`move`,[{}]),new t(`line`,[{}])]},o.prototype.render=function(e,t){this.renderCylinderSurface(e,t),r.prototype.render.apply(this,arguments)},o.prototype.renderCylinderSurface=function(e,t){if(this.visible){var n=this.getRenderElement(e,t),r=this.frontBase,i=this.rearBase,a=r.renderNormal.magnitude(),o=r.diameter*a+r.getLineWidth();this.pathCommands[0].renderPoints[0].set(r.renderOrigin),this.pathCommands[1].renderPoints[0].set(i.renderOrigin),t.isCanvas&&(e.lineCap=`butt`),t.renderPath(e,n,this.pathCommands),t.stroke(e,n,!0,this.color,o),t.end(e,n),t.isCanvas&&(e.lineCap=`round`)}};var s=`http://www.w3.org/2000/svg`;o.prototype.getRenderElement=function(e,t){if(t.isSvg)return this.svgElement||=document.createElementNS(s,`path`),this.svgElement},o.prototype.copyGraph=a;var c=i.subclass();c.prototype.copyGraph=a;var l=n.subclass({diameter:1,length:1,frontFace:void 0,fill:!0}),u=e.TAU;return l.prototype.create=function(){n.prototype.create.apply(this,arguments),this.group=new o({addTo:this,color:this.color,visible:this.visible});var e=this.length/2,t=this.backface||!0;this.frontBase=this.group.frontBase=new i({addTo:this.group,diameter:this.diameter,translate:{z:e},rotate:{y:u/2},color:this.color,stroke:this.stroke,fill:this.fill,backface:this.frontFace||t,visible:this.visible}),this.rearBase=this.group.rearBase=this.frontBase.copy({translate:{z:-e},rotate:{y:0},backface:t})},l.prototype.render=function(){},[`stroke`,`fill`,`color`,`visible`].forEach(function(e){var t=`_`+e;Object.defineProperty(l.prototype,e,{get:function(){return this[t]},set:function(n){this[t]=n,this.frontBase&&(this.frontBase[e]=n,this.rearBase[e]=n,this.group[e]=n)}})}),l})})),me=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),I(),B(),L(),W());else{var r=e.Zdog;r.Cone=n(r,r.Vector,r.PathCommand,r.Anchor,r.Ellipse)}})(e,function(e,t,n,r,i){var a=i.subclass({length:1,fill:!0}),o=e.TAU;a.prototype.create=function(){i.prototype.create.apply(this,arguments),this.apex=new r({addTo:this,translate:{z:this.length}}),this.renderApex=new t,this.renderCentroid=new t,this.tangentA=new t,this.tangentB=new t,this.surfacePathCommands=[new n(`move`,[{}]),new n(`line`,[{}]),new n(`line`,[{}])]},a.prototype.updateSortValue=function(){this.renderCentroid.set(this.renderOrigin).lerp(this.apex.renderOrigin,1/3),this.sortValue=this.renderCentroid.z},a.prototype.render=function(e,t){this.renderConeSurface(e,t),i.prototype.render.apply(this,arguments)},a.prototype.renderConeSurface=function(e,t){if(this.visible){this.renderApex.set(this.apex.renderOrigin).subtract(this.renderOrigin);var n=this.renderNormal.magnitude(),r=this.renderApex.magnitude2d(),i=this.renderNormal.magnitude2d(),a=Math.acos(i/n),s=Math.sin(a),c=this.diameter/2*n;if(c*s<r){var l=Math.atan2(this.renderNormal.y,this.renderNormal.x)+o/2,u=r/s,d=Math.acos(c/u),f=this.tangentA,p=this.tangentB;f.x=Math.cos(d)*c*s,f.y=Math.sin(d)*c,p.set(this.tangentA),p.y*=-1,f.rotateZ(l),p.rotateZ(l),f.add(this.renderOrigin),p.add(this.renderOrigin),this.setSurfaceRenderPoint(0,f),this.setSurfaceRenderPoint(1,this.apex.renderOrigin),this.setSurfaceRenderPoint(2,p);var m=this.getSurfaceRenderElement(e,t);t.renderPath(e,m,this.surfacePathCommands),t.stroke(e,m,this.stroke,this.color,this.getLineWidth()),t.fill(e,m,this.fill,this.color),t.end(e,m)}}};var s=`http://www.w3.org/2000/svg`;return a.prototype.getSurfaceRenderElement=function(e,t){if(t.isSvg)return this.surfaceSvgElement||(this.surfaceSvgElement=document.createElementNS(s,`path`),this.surfaceSvgElement.setAttribute(`stroke-linecap`,`round`),this.surfaceSvgElement.setAttribute(`stroke-linejoin`,`round`)),this.surfaceSvgElement},a.prototype.setSurfaceRenderPoint=function(e,t){this.surfacePathCommands[e].renderPoints[0].set(t)},a})})),he=t(((e,t)=>{(function(e,n){if(typeof t==`object`&&t.exports)t.exports=n(N(),L(),V(),U());else{var r=e.Zdog;r.Box=n(r,r.Anchor,r.Shape,r.Rect)}})(e,function(e,t,n,r){var i=r.subclass();i.prototype.copyGraph=function(){};var a=e.TAU,o=[`frontFace`,`rearFace`,`leftFace`,`rightFace`,`topFace`,`bottomFace`],s=e.extend({},n.defaults);delete s.path,o.forEach(function(e){s[e]=!0}),e.extend(s,{width:1,height:1,depth:1,fill:!0});var c=t.subclass(s);return c.prototype.create=function(e){t.prototype.create.call(this,e),this.updatePath(),this.fill=this.fill},c.prototype.updatePath=function(){o.forEach(function(e){this[e]=this[e]},this)},o.forEach(function(e){var t=`_`+e;Object.defineProperty(c.prototype,e,{get:function(){return this[t]},set:function(n){this[t]=n,this.setFace(e,n)}})}),c.prototype.setFace=function(e,t){var n=e+`Rect`,r=this[n];if(!t){this.removeChild(r);return}var a=this.getFaceOptions(e);a.color=typeof t==`string`?t:this.color,r?r.setOptions(a):r=this[n]=new i(a),r.updatePath(),this.addChild(r)},c.prototype.getFaceOptions=function(e){return{frontFace:{width:this.width,height:this.height,translate:{z:this.depth/2}},rearFace:{width:this.width,height:this.height,translate:{z:-this.depth/2},rotate:{y:a/2}},leftFace:{width:this.depth,height:this.height,translate:{x:-this.width/2},rotate:{y:-a/4}},rightFace:{width:this.depth,height:this.height,translate:{x:this.width/2},rotate:{y:a/4}},topFace:{width:this.width,height:this.depth,translate:{y:-this.height/2},rotate:{x:-a/4}},bottomFace:{width:this.width,height:this.depth,translate:{y:this.height/2},rotate:{x:a/4}}}[e]},[`color`,`stroke`,`fill`,`backface`,`front`,`visible`].forEach(function(e){var t=`_`+e;Object.defineProperty(c.prototype,e,{get:function(){return this[t]},set:function(n){this[t]=n,o.forEach(function(t){var r=this[t+`Rect`],i=typeof this[t]==`string`;r&&!(e==`color`&&i)&&(r[e]=n)},this)}})}),c})})),G=e(t(((e,t)=>{(function(e,n){typeof t==`object`&&t.exports?t.exports=n(N(),P(),F(),I(),L(),R(),z(),B(),V(),H(),U(),ue(),W(),de(),fe(),pe(),me(),he()):typeof define==`function`&&define.amd&&define(`zdog`,[],e.Zdog)})(e,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_){return e.CanvasRenderer=t,e.SvgRenderer=n,e.Vector=r,e.Anchor=i,e.Dragger=a,e.Illustration=o,e.PathCommand=s,e.Shape=c,e.Group=l,e.Rect=u,e.RoundedRect=d,e.Ellipse=f,e.Polygon=p,e.Hemisphere=m,e.Cylinder=h,e.Cone=g,e.Box=_,e})}))(),1),K=new Map([[`idle`,{geometry:{},motion:{target:`root`,translate:{y:.5},durationMs:2e3,repeat:`yoyo`},mouseInfluence:1}],[`listening`,{geometry:{},motion:{target:`root`,rotate:{x:-.2},durationMs:300,repeat:`yoyo`},mouseInfluence:.3}],[`processing`,{geometry:{},mouseInfluence:.2}],[`speaking`,{geometry:{},motion:{target:`root`,translate:{y:.5},durationMs:1500,repeat:`yoyo`},mouseInfluence:0,mouthCycle:[{durationMs:100,mouth:`open`},{durationMs:150,mouth:`base`},{durationMs:100,mouth:`open`},{durationMs:200,mouth:`base`}]}],[`thinking`,{geometry:{},motion:{target:`root`,rotate:{z:.1},durationMs:800,repeat:`yoyo`},mouseInfluence:0}],[`error`,{geometry:{expression:`dead`},mouseInfluence:.1}]]),ge=48,q=(e,t)=>Math.min(e,t)/ge,J=e=>e!==void 0&&e>0?e:1,Y=(e,t,n,r)=>{let i=Math.min(1,Math.sqrt(n/(e*t*r*r)));return[Math.max(1,Math.floor(e*i)),Math.max(1,Math.floor(t*i))]},X=(e,t)=>{if(!Number.isFinite(e))throw Error(`Sprite ${t} must be finite`)},Z=(e,t)=>{let n=e.ownerDocument.defaultView,r=n?.getComputedStyle(e)?.[t]??``,i=Number.parseFloat(r);if(i>0&&r.trim().endsWith(`px`))return i;let a=e.style[t],o=Number.parseFloat(a);if(o>0&&a.trim().endsWith(`px`))return o;let s=e.getBoundingClientRect(),c=t===`width`?s.width:s.height;if(c>0)return c;for(let r=e.parentElement;r;r=r.parentElement){let e=n?.getComputedStyle(r)[t],i=Number.parseFloat(e??``);if(i>0&&e?.trim().endsWith(`px`))return i}return e[t]||48},Q=e=>{if(!e)return{};let t={};return e.x!==void 0&&(t.x=e.x),e.y!==void 0&&(t.y=e.y),e.z!==void 0&&(t.z=e.z),t},$=e=>e?e<=.5?`small`:e<=.8?`medium`:`big`:`off`,_e=e=>{let t=new Map,n=new Map;for(let r of e.nodes){let e=r.parent===void 0?void 0:t.get(r.parent),i={kind:r.kind,name:r.options.name,children:[],options:r.options};t.set(r.id,i),i.name&&n.set(i.name,i),e?.children.push(i)}let r=t.get(e.root);if(!r)throw Error(`Portable Zdog scene has no root`);let i=new Map;for(let[n,r]of Object.entries(e.variants)){let e=new Map;for(let[n,i]of Object.entries(r)){let r=t.get(i);if(!r)throw Error(`Portable Zdog variant node is missing: ${i}`);e.set(n,r)}i.set(n,e)}return{root:r,nodesByName:n,variants:i,palette:e.palette,activities:e.activities,expressions:e.expressions}},ve=class{internals;target;view;onInvalidate;maxPixels;originalStyle;originalHasInlineWidth;originalHasInlineHeight;originalWidthAttribute;originalHeightAttribute;illustration;avatar;animationPivot;items=new Map;variantItems=new Map;palette;mouseListener;resizeObserver;animationTween=null;mouthCycleTimeline=null;entryTween=null;mouseX=0;mouseY=0;mouseInfluence=1;dirty=!0;destroyed=!1;paused=!1;lastRenderTime=0;constructor({target:e,scene:t,onInvalidate:n,palette:r,maxPixels:i}){this.target=e,this.view=e.ownerDocument.defaultView,this.onInvalidate=n,this.maxPixels=i,this.originalStyle=e.getAttribute(`style`),this.originalHasInlineWidth=e.style.width!==``,this.originalHasInlineHeight=e.style.height!==``,this.originalWidthAttribute=e.getAttribute(`width`),this.originalHeightAttribute=e.getAttribute(`height`),this.internals=_e(t),this.palette={...this.internals.palette};for(let[e,t]of Object.entries(r??{})){if(!(e in this.internals.palette))throw Error(`Unknown Sprite palette slot: ${e}`);t!==void 0&&(this.palette[e]=t)}let a=Z(e,`width`),o=Z(e,`height`),[s,c]=Y(a,o,i,J(this.view?.devicePixelRatio));e.width=Math.round(s),e.height=Math.round(c),this.illustration=new G.Illustration({element:e,resize:!1,zoom:q(s,c)}),this.illustration.setSize(s,c),this.preserveCanvasStyle(a,o),this.avatar=new G.Group({addTo:this.illustration,rotate:{x:-G.TAU/1.05}}),this.animationPivot=new G.Group({addTo:this.avatar}),this.createScene(this.internals.root,this.animationPivot),this.indexVariants(),this.mouseListener=e=>{this.onMouseMove(e)},this.view?.addEventListener(`mousemove`,this.mouseListener);let l=globalThis.ResizeObserver;this.resizeObserver=new l(()=>{this.destroyed||this.resize()});try{this.resizeObserver.observe(e),this.present({activity:t.defaultPresentation.activity,expression:t.defaultPresentation.expression})}catch(e){throw this.stopAnimations(),this.view?.removeEventListener(`mousemove`,this.mouseListener),this.resizeObserver.disconnect(),e}}present(e){if(this.assertAlive(),!(e.expression in this.internals.expressions))throw Error(`Unknown Sprite expression: ${e.expression}`);if(!(e.activity in this.internals.activities)&&!K.has(e.activity))throw Error(`Unknown Sprite activity: ${e.activity}`);this.stopAnimations();let t=this.activitySpec(e.activity),n=this.internals.expressions[e.expression],r=t.geometry?.expression??e.expression,i=this.internals.expressions[r]??n;this.mouseInfluence=t.mouseInfluence??1,this.applyVariants(i,t.geometry),this.resetPivot(),t.motion&&this.startMotion(t.motion,!0),i?.motion&&this.startMotion(i.motion,!1),t.mouthCycle&&this.internals.variants.get(`mouth`)?.size&&this.startMouthCycle(t.mouthCycle,i),this.dirty=!0,this.pause(this.paused)}setPalette(e){this.assertAlive();for(let t of Object.keys(e))if(!Object.hasOwn(this.internals.palette,t))throw Error(`Unknown Sprite palette slot: ${t}`);Object.assign(this.palette,this.internals.palette,e);for(let[e,t]of this.items){for(let n of[`color`,`backface`,`frontFace`]){let r=e.options[n],i=s(r);i&&(t[n]=this.palette[i])}e.kind===`cylinder`&&t.frontBase!==void 0&&t.rearBase!==void 0&&(t.frontFace?t.frontBase.backface=t.frontFace:t.backface?t.frontBase.backface=t.backface:t.frontBase.backface=!0,t.backface?t.rearBase.backface=t.backface:t.rearBase.backface=!0)}this.dirty=!0,this.onInvalidate()}pause(e){this.paused=e;for(let t of[this.animationTween,this.mouthCycleTimeline,this.entryTween])e?t?.pause():t?.resume()}seek(e){if(X(e,`timeMs`),e<0)throw RangeError(`timeMs must be nonnegative`);this.pause(!0);for(let t of[this.animationTween,this.mouthCycleTimeline,this.entryTween])t?.seek(e);this.dirty=!0,this.renderStill()}tick(e){if(this.destroyed||!this.illustration.ctx)return!1;let t=this.hasActiveTween();return(this.dirty||t||this.mouseNeedsRender())&&e-this.lastRenderTime>=1e3/24&&(this.updateMouseTracking(),this.illustration.updateRenderGraph(),this.lastRenderTime=e,this.dirty=!1),this.dirty||this.hasActiveTween()||this.mouseNeedsRender()}renderStill(){this.destroyed||!this.dirty||!this.illustration.ctx||(this.illustration.updateRenderGraph(),this.dirty=!1)}resize(){this.assertAlive();let e=Z(this.target,`width`),t=Z(this.target,`height`),[n,r]=Y(e,t,this.maxPixels,J(this.view?.devicePixelRatio));this.illustration.zoom=q(n,r),this.illustration.setSize(n,r),this.preserveCanvasStyle(e,t),this.dirty=!0,this.onInvalidate()}destroy(){if(this.destroyed)throw Error(`Sprite instance has already been destroyed`);this.destroyed=!0,this.stopAnimations(),this.view?.removeEventListener(`mousemove`,this.mouseListener),this.resizeObserver.disconnect();let e=this.target.getContext(`2d`);e&&e.clearRect(0,0,this.target.width,this.target.height),this.restoreCanvasAttributes()}createScene(e,t){let n={...e.options};delete n.parent,delete n.name,delete n.x,delete n.y,delete n.z,n.addTo=t,n.translate?n.translate=Q(n.translate):(e.options.x!==void 0||e.options.y!==void 0||e.options.z!==void 0)&&(n.translate=Q({x:e.options.x,y:e.options.y,z:e.options.z}));let r=s(n.color);r&&(n.color=this.palette[r]);let i=s(n.backface);i&&(n.backface=this.palette[i]);let a=s(n.frontFace);a&&(n.frontFace=this.palette[a]);let o;switch(e.kind){case`group`:o=new G.Group(n);break;case`shape`:n.path=n.path??[{}],o=new G.Shape(n);break;case`ellipse`:o=new G.Ellipse(n);break;case`hemisphere`:o=new G.Hemisphere(n);break;case`cylinder`:o=new G.Cylinder(n)}this.items.set(e,o);for(let t of e.children)this.createScene(t,o);return o}indexVariants(){for(let[e,t]of this.internals.variants.entries()){let n=new Map;for(let[e,r]of t.entries()){let t=this.items.get(r);t&&n.set(e,t)}this.variantItems.set(e,n)}}applyVariants(e,t){for(let e of this.variantItems.values())for(let t of e.values())t.visible=!1;let n={...e?.variants};for(let[t,r]of Object.entries(e?.variantChoices??{})){let e=r[Math.min(r.length-1,Math.floor(Math.random()*r.length))];e!==void 0&&(n[t]=e)}t?.eyes&&(n.eyes=t.eyes),t?.mouth&&(n.mouth=t.mouth),t?.blush===void 0?e?.blush!==void 0&&(n.blush=$(e.blush)):n.blush=$(t.blush);for(let[e,t]of Object.entries(n)){let n=this.variantItems.get(e)?.get(t);n&&(n.visible=!0)}}activitySpec(e){let t=K.get(e)??{geometry:{},mouseInfluence:1},n=this.internals.activities[e];if(!n)return t;let r=n.motion??t.motion,i=n.mouthCycle??t.mouthCycle,a={...t,...n,geometry:{...t.geometry,...n.geometry}};return r!==void 0&&(a.motion=r),i!==void 0&&(a.mouthCycle=i),a}startMotion(e,t){let n=this.internals.nodesByName.get(e.target),r=n===this.internals.root?this.animationPivot:n?this.items.get(n):void 0;if(!r)return;let i=M({loop:e.repeat===`loop`||e.repeat===`yoyo`,alternate:e.repeat===`yoyo`}),a=e.durationMs??1e3;e.translate&&i.add(r.translate,{...Q(e.translate),duration:a,ease:`inOutSine`},0),e.rotate&&i.add(r.rotate,{...Q(e.rotate),duration:a,ease:`inOutSine`},0),t?this.animationTween=i:this.entryTween=i}startMouthCycle(e,t){let n=[],r=0;for(let i of e)X(i.durationMs,`mouthCycle.durationMs`),r+=i.durationMs,n.push({until:r,mouth:i.mouth===`open`?`open`:t?.variants?.mouth});let i;this.mouthCycleTimeline=d({duration:r,loop:!0,onUpdate:e=>{let t=n.find(t=>e.iterationCurrentTime<t.until)?.mouth;t&&t!==i&&(i=t,this.showVariant(`mouth`,t))},onLoop:()=>{i=void 0}})}showVariant(e,t){let n=this.variantItems.get(e);if(n===void 0)return;let r=n.get(t);if(r!==void 0){for(let e of n.values())e.visible=!1;r.visible=!0,this.dirty=!0}}resetPivot(){Object.assign(this.animationPivot.rotate,{x:0,y:0,z:0}),Object.assign(this.animationPivot.translate,{x:0,y:0,z:0}),Object.assign(this.avatar.rotate,{x:-G.TAU/1.05,y:0,z:0})}stopAnimations(){this.animationTween?.cancel(),this.mouthCycleTimeline?.cancel(),this.entryTween?.cancel(),this.animationTween=null,this.mouthCycleTimeline=null,this.entryTween=null}hasActiveTween(){return[this.animationTween,this.mouthCycleTimeline,this.entryTween].some(e=>e!==null&&!e.paused&&!e.completed&&!e.cancelled)}onMouseMove(e){if(this.destroyed||this.paused)return;let t=this.target.getBoundingClientRect(),n=t.width||1,r=t.height||1;this.mouseX=Math.max(-1,Math.min(1,(e.clientX-t.left-n/2)/(n/2))),this.mouseY=Math.max(-1,Math.min(1,(e.clientY-t.top-r/2)/(r/2))),this.dirty=!0,this.onInvalidate()}updateMouseTracking(){let e=-this.mouseX*.4*this.mouseInfluence,t=-G.TAU/1.05-this.mouseY*.2*this.mouseInfluence,n=(e-this.avatar.rotate.y)*.08,r=(t-this.avatar.rotate.x)*.08;this.avatar.rotate.y+=n,this.avatar.rotate.x+=r,(Math.abs(n)>.001||Math.abs(r)>.001)&&(this.dirty=!0)}mouseNeedsRender(){return Math.abs(this.avatar.rotate.y+this.mouseX*.4*this.mouseInfluence)>.001||Math.abs(this.avatar.rotate.x+G.TAU/1.05+this.mouseY*.2*this.mouseInfluence)>.001}assertAlive(){if(this.destroyed)throw Error(`Sprite instance has been destroyed`)}restoreCanvasAttributes(){this.originalStyle===null?this.target.removeAttribute(`style`):this.target.setAttribute(`style`,this.originalStyle),this.originalWidthAttribute===null?this.target.removeAttribute(`width`):this.target.setAttribute(`width`,this.originalWidthAttribute),this.originalHeightAttribute===null?this.target.removeAttribute(`height`):this.target.setAttribute(`height`,this.originalHeightAttribute)}preserveCanvasStyle(e,t){this.originalStyle!==null&&this.target.setAttribute(`style`,this.originalStyle),this.originalHasInlineWidth||(this.target.style.width=`${String(Math.round(e))}px`),this.originalHasInlineHeight||(this.target.style.height=`${String(Math.round(t))}px`)}},ye=e=>new ve(e),be=e=>n(function*(){let t=c.parse(e.document.data),n=yield*a(r(()=>e.target.ownerDocument.createElement(`canvas`)),e=>r(()=>{e.remove()}));n.style.cssText=`width:100%;height:100%;display:block`,e.target.replaceChildren(n);let s=e.target.ownerDocument.defaultView;if(!s)throw Error(`Zdog avatar requires a browser window`);let l,u=!0,d=!1,f=()=>{u||d||l!==void 0||(l=s.requestAnimationFrame(e=>{l=void 0,m.tick(e)&&f()}))},p=()=>{d||(u?m.renderStill():f())},m=yield*a(r(()=>ye({target:n,scene:t,onInvalidate:p,maxPixels:e.maxPixels})),e=>r(()=>{e.destroy()}));yield*i(()=>r(()=>{d=!0,l!==void 0&&s.cancelAnimationFrame(l)})),m.pause(!0);let h=!1,g,_;return{activities:[`idle`,`listening`,`processing`,`speaking`,`thinking`,`error`,...Object.keys(t.activities)],expressions:[t.defaultPresentation.expression,...Object.keys(t.expressions)].filter((e,t,n)=>n.indexOf(e)===t),set(e){let n={};for(let[t,r]of Object.entries(e.appearance)){let e=o().safeParse(r);if(!e.success)throw Error(`Zdog palette value must be a color: ${t}`);n[t]=e.data}let r=JSON.stringify(n);r!==_&&(m.setPalette(n),_=r);let i=e.expression??t.defaultPresentation.expression;if(!i)throw Error(`Zdog avatar needs an expression`);let a=JSON.stringify([e.activity,i]);a!==g&&(m.present({activity:e.activity,expression:i}),g=a),h=e.timeMs!==void 0,e.timeMs!==void 0&&m.seek(e.timeMs),p()},pause(e){u=h||e,m.pause(u),u&&l!==void 0&&(s.cancelAnimationFrame(l),l=void 0),p()}}});export{be as t};
|