@theoremjs/studio 0.3.4-next.456.gff60088 → 0.3.4-next.458.gbf7b487
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/package.json +4 -4
- package/page/assets/{Banner-DBzTZFXK.js → Banner-C4MPbvft.js} +2 -2
- package/page/assets/{ConsoleFrame-xxYOJ87g.js → ConsoleFrame-BkzieVRC.js} +1 -1
- package/page/assets/{ContextMenu-BeVF9aNZ.js → ContextMenu-BGP2gdee.js} +2 -2
- package/page/assets/{ToolResultCharts-DBMZY7TW.js → ToolResultCharts-xDwNDd-T.js} +1 -1
- package/page/assets/{TraceInspector-CzHEXIY1.js → TraceInspector-CHpdhiVX.js} +1 -1
- package/page/assets/{TraceOverview-Bxg_mg5E.js → TraceOverview-DCGew7UN.js} +1 -1
- package/page/assets/{browser-engine-9AzaOhwz.js → browser-engine-Ca2pvYX0.js} +1 -1
- package/page/assets/{browser-transport-C4SkWngw.js → browser-transport-DYgEItHi.js} +3 -3
- package/page/assets/{export-agent-Bp0s2CsN.js → export-agent-5rXmF-g1.js} +1 -1
- package/page/assets/{guardrail-tester-CS65cwR5.js → guardrail-tester-B-ZfQFVu.js} +1 -1
- package/page/assets/{index--GBhZcW8.js → index-Dajtrq_Z.js} +6 -6
- package/page/assets/{studio-code-pane-B5U9m4Ds.js → studio-code-pane-CKYRitdD.js} +1 -1
- package/page/assets/{studio-console-UkWyi9VN.js → studio-console-DwhqnNyw.js} +1 -1
- package/page/assets/{studio-decision-CCqMemnt.js → studio-decision-Ckj4UNNt.js} +1 -1
- package/page/assets/{studio-embedding-RTptdueU.js → studio-embedding-8qL_dVlz.js} +1 -1
- package/page/assets/{studio-host-console-4UbIwUY0.js → studio-host-console-BXwwloN4.js} +2 -2
- package/page/assets/{studio-labels-I9r-0TcO.js → studio-labels-C1pvg0JC.js} +1 -1
- package/page/assets/{studio-live-Cn-wK5-R.js → studio-live-26srJ74m.js} +1 -1
- package/page/assets/{studio-map-BWTX2beg.js → studio-map-C5zsJusF.js} +1 -1
- package/page/assets/{studio-trace-replay-BaTeqFr0.js → studio-trace-replay-B38TicvO.js} +1 -1
- package/page/assets/{use-one-call-C0-dw_94.js → use-one-call-DjVkallj.js} +1 -1
- package/page/index.html +5 -5
- package/ui/tree-map.css +43 -0
- package/ui/tree-map.d.ts +7 -1
- package/ui/tree-map.js +10 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolResultCharts-
|
|
2
|
-
import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{c as n,l as r,n as i,u as a}from"./themeProps-3IqahpCr.js";import{n as o,t as s}from"./SegmentedControlItem-BLuJOusN.js";import{t as c}from"./VStack-CkVMcNiK.js";import{n as l,t as u}from"./StackItem-CQviqAfM.js";import{t as d}from"./DateInput-BJt-UTCy.js";import{N as f,c as p,d as m,h,i as ee,j as te,l as ne,s as re}from"./browser-transport-C4SkWngw.js";import{t as ie}from"./mergeProps-ptS-gIMz.js";import{T as ae,m as oe}from"./fieldParts-Cs6Amprh.js";import{t as g}from"./Text-BsiAsowd.js";import{t as se}from"./preload-helper-DpV6A1kQ.js";import{i as ce,l as le,n as _,t as ue}from"./labels-provider-BSiD6Lrb.js";import{n as v}from"./Card-Ghe4ozhC.js";import{t as de}from"./Tooltip-CTEuMRLe.js";import{n as fe}from"./ScrollableArea-C8AVuqnt.js";import{a as pe,t as me}from"./Banner-DBzTZFXK.js";import{a as he,i as ge,n as _e,t as y}from"./arrive-DvbqpeRS.js";import{b as ve,f as ye,h as be,m as xe,n as Se,r as Ce,t as we,v as Te,y as Ee}from"./studio-labels-I9r-0TcO.js";import{c as De,d as Oe,f as ke,l as Ae,u as je}from"./tool-schema-E9NPuDcN.js";import{_ as Me,a as b,b as Ne,c as x,d as Pe,g as Fe,l as S,m as C,n as w,o as Ie,r as Le,t as Re,v as T,y as E}from"./shaped-data-0GUF7Al3.js";import{S as ze,i as Be,u as Ve}from"./turn-client-Dy9-U9_L.js";import{t as He}from"./EmptyState-C8W4JKBZ.js";import{t as Ue}from"./use-second-ticker-VX91zrxj.js";import{i as We,r as Ge}from"./ContextMenu-BeVF9aNZ.js";import{a as Ke,c as qe,d as Je,i as Ye,l as D,o as Xe,r as Ze,t as Qe,u as $e}from"./ConsoleFrame-xxYOJ87g.js";import{i as et}from"./trace-patterns-CS99kExN.js";import{D as tt,I as O,L as nt,N as rt,P as it,S as k,St as at,T as ot,_ as st,b as ct,f as lt,gt as ut,h as dt,j as ft,p as A,v as j,w as pt}from"./index--GBhZcW8.js";import{t as mt}from"./studio-console-UkWyi9VN.js";var ht=4,gt=3,_t=3,M=8,vt=6,N=3,yt=3,bt=/(^|_)(id|ids|lat|lon|lng|latitude|longitude|offset|interval|index|rank|order)$|Id$|^(generationtime_ms|utc_offset_seconds)$/i,xt=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function St(e){if(/\s/.test(e))return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&xt.test(t.pathname)}catch{return!1}}function P(e){return!bt.test(e)}function F(e){return/^[A-Z][A-Z0-9]{1,5}$/.test(e)?e:b(e)}function I(e,t){if(!P(e)||t&&e in t&&Pe(t[e])===void 0)return;let{label:n,unit:r}=Le(e,t);return{label:F(e)===e?e:n,unit:r}}function L(e,t){let n=[];for(let[r,i]of C(e)){if(typeof i!=`number`||!Number.isFinite(i))continue;let e=I(r,t);e&&n.push({key:r,value:i,...e})}return n.sort((e,t)=>Number(t.unit!==void 0)-Number(e.unit!==void 0)).slice(0,ht)}function Ct(e){if(!x(e))return[];for(let[t,n]of C(e)){let r=E(n);if(!x(r)||w(r))continue;let i=Object.values(r);if(i.length===0||!i.every(Ie))continue;let a=L(r,T(e,t));if(a.length>0)return a}return L(e,void 0)}function R(e,t){return new Set(e.map(e=>e[t])).size}function z(e,t,n){return[...new Set(e.flatMap(e=>Object.keys(e)))].filter(n=>n!==t&&e.every(e=>typeof e[n]==`number`||e[n]===null)&&R(e,n)>1).flatMap(e=>{let t=I(e,n);return t?[{key:e,...t}]:[]})}function wt(e){let[t]=e;if(t)return Object.keys(t).find(t=>e.every(e=>typeof e[t]==`string`&&Re.test(e[t])))}function Tt(e){let t=e.map(e=>e.label.split(` `)),[n=[]]=t,r=0;for(;r<n.length&&t.every(e=>e.length>r+1&&e[r]===n[r]);)r++;if(r)return{title:n.slice(0,r).join(` `),series:e.map((e,n)=>{let i=(t[n]??[]).slice(r).join(` `);return{...e,label:i.charAt(0).toUpperCase()+i.slice(1)}})}}function Et(e,t,n,r,i){let a=new Map;for(let e of z(n,r,i)){let t=a.get(e.unit??``)??[];t.push(e),a.set(e.unit??``,t)}return[...a.values()].map(i=>{let a=i.slice(0,_t),o=a.length>1?Tt(a):void 0;return{kind:`time`,key:`${e}:${a.map(e=>e.key).join(`+`)}`,title:a.length===1?a[0]?.label??t:o?.title??(t||a.map(e=>e.label).join(` · `)),x:r,series:o?.series??a,rows:n}})}function Dt(e){let[t]=e,n=t?Me(t):void 0;if(!t||!n||!e.every(e=>typeof e[n]==`string`||typeof e[n]==`number`))return;if(R(e,n)===e.length)return n;let r=t=>e.reduce((e,n)=>e+String(n[t]).length,0),[i]=Object.keys(t).filter(t=>e.every(e=>typeof e[t]==`string`)&&R(e,t)===e.length).sort((e,t)=>r(e)-r(t));return i??n}function Ot(e,t,n,r){let i=Dt(n);return i?z(n,i,r).sort((e,t)=>R(n,t.key)-R(n,e.key)).map(r=>({kind:`category`,key:`${e}:${r.key}`,title:t?`${t} · ${r.label}`:r.label,series:r,rows:n.filter(e=>typeof e[r.key]==`number`).map(e=>({label:String(e[i]),value:e[r.key]})).sort((e,t)=>t.value-e.value).slice(0,M)})):[]}function B(e,t,n,r){if(n.length<N)return[];let i=wt(n);return i?Et(e,t,n,i,r):Ot(e,t,n,r)}function V(e,t,n,r,i){if(i>yt)return[];if(Array.isArray(e)){let i=e.map(E);return i.every(x)?B(t,n,i,r):[]}if(!x(e))return[];let a=w(e);if(a)return B(t,n,Fe(e,a),r);let o=C(e),s=o.filter(([e,t])=>typeof t==`number`&&P(e));if(i>0&&s.length>=N&&s.length===o.length){let e=s.map(([e,t])=>({label:F(e),value:t}));return[{kind:`category`,key:t,title:n,series:{key:`value`,label:n},rows:e.sort((e,t)=>t.value-e.value).slice(0,M)}]}return o.flatMap(([r,a])=>V(E(a),t?`${t}.${r}`:r,i===0?b(r):`${n} › ${b(r)}`,T(e,r),i+1))}function H(e,t,n,r){if(r.size>=vt||n>4)return;let i=E(e);if(typeof i==`string`)St(i)&&!r.has(i)&&r.set(i,{src:i,alt:b(t||`image`)});else if(Array.isArray(i))for(let e of i)H(e,t,n+1,r);else if(x(i))for(let[e,t]of Object.entries(i))H(t,e,n+1,r)}function kt(e){let t=E(e),n=new Map;return H(t,``,0,n),{figures:Ct(t),charts:V(t,``,``,void 0,0).slice(0,gt),images:[...n.values()]}}function At(e){return e.mimeType&&e.data?`data:${e.mimeType};base64,${e.data}`:void 0}function jt(e,t,n){let r=t.flatMap(e=>{let t=At(e);return t?[{type:e.type,src:t,mimeType:e.mimeType}]:[]});return{images:[...r.filter(e=>e.type===`image`).map(({src:e})=>({src:e,alt:n})),...e.images],audio:r.filter(e=>e.type===`audio`).map(({src:e,mimeType:t})=>({src:e,...t?{mimeType:t}:{}}))}}function Mt(e,t){return e.figures.length+e.charts.length+t.images.length+t.audio.length>0}var Nt=864e5,Pt=10;function Ft(e){return e.some(e=>e.includes(`T`))?{tick:Math.abs(Date.parse(e.at(-1)??``)-Date.parse(e[0]??``))<=Nt?{hour:`numeric`}:{month:`short`,day:`numeric`},when:{dateStyle:`medium`,timeStyle:`short`}}:{tick:e.length<=Pt?{weekday:`short`,timeZone:`UTC`}:{month:`short`,day:`numeric`,timeZone:`UTC`},when:{dateStyle:`medium`,timeZone:`UTC`}}}var U=n(),W={base:{k1xSpc:`x3nfvp2`,kGNEyG:`x6s0dn4`,kjj79g:`xl56j7k`,kaIpWk:`x16rqkct`,kmuXW:`x2lah0s`,kzqmXN:`x1xc55vz`,kZKoxP:`xdk7pt`,$$css:!0},pulsing:{kKVMdj:`x1mta51n`,k44tkh:`x1c74tu6`,kyAemX:`x4hg4is`,ko0y90:`xa4qsjk`,$$css:!0},reducedMotion:{kjO2d4:`x1aquc0h`,$$css:!0}},It={success:{kWkggS:`xdsz4j9`,kMwMTN:`xri61p4`,$$css:!0},warning:{kWkggS:`x1q8g9m5`,kMwMTN:`xrebv38`,$$css:!0},error:{kWkggS:`x1pjz0fi`,kMwMTN:`x1m024r3`,$$css:!0},accent:{kWkggS:`x1ewilqj`,kMwMTN:`x17wrial`,$$css:!0},neutral:{kWkggS:`x1q5y3ey`,kMwMTN:`xrkvqaz`,$$css:!0}};function G({variant:e,label:t,isPulsing:n=!1,tooltip:a,icon:o,xstyle:s,className:c,style:l,ref:u,...d}){let f=ae(o),p=(0,U.jsx)(`span`,{ref:u,role:`img`,"aria-label":t,...ie(i(`status-dot`,{variant:e}),r(W.base,It[e],n&&W.pulsing,n&&W.reducedMotion,s),c,l),...d,children:f&&(0,U.jsx)(`span`,{"aria-hidden":`true`,className:`x78zum5 x6s0dn4 xl56j7k x14ju556 x1xc55vz xdk7pt`,children:o})});return a?(0,U.jsx)(de,{content:a,children:p}):p}G.displayName=`StatusDot`;var Lt=new Set([`gate`,`complete`,`error`,`cancel`]);function Rt({call:e,failure:t,isRunning:n}){let r=e?.state?.phase;return r!==void 0&&Lt.has(r)?r:t?`error`:n?`running`:`cancel`}function K({call:e,failure:t}){if(t)return{title:t.error};let n=e?.state;if(n?.phase!==`error`)return null;let{error:r,message:i}=n.failure;return r?r===i?{title:r}:{title:r,description:i}:{title:i}}function zt(e){let t=e.tools.find(t=>t.name===e.picked)??e.tools[0],n=t?e.drafts[t.name]??S(je(t.inputSchema)):``,r=e.calls.filter(e=>e.name===t?.name),i=r.find(t=>t.id===e.shownId)??r[0]??null;return{tool:t,text:n,shown:i,earlier:e.calls.filter(e=>e!==i)}}var q=t(a(),1);function Bt(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`call-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Vt(e,t){let n=[...e.events,t],r=t.type===`tool`&&t.tool.phase===`progress`?t.tool.data:e.progress;return{...e,events:n,call:ze(n)[0]??null,progress:r}}function Ht(e,t){let n=(0,q.useMemo)(()=>ve(e,t),[e,t]),{iface:r,describeFailure:i}=dt(n),[a,o]=(0,q.useState)([]),s=(0,q.useRef)(new Map),c=(0,q.useRef)([]),l=(0,q.useRef)(a);l.current=a,(0,q.useEffect)(()=>{let e=s.current;return()=>{for(let t of e.values())t.abort()}},[]);let u=(0,q.useCallback)((e,t)=>{o(n=>n.map(n=>n.id===e?t(n):n))},[]),d=(0,q.useCallback)(async(e,t)=>{let n=new AbortController;s.current.set(e,n);let r=performance.now();u(e,e=>({...e,isRunning:!0,failure:null}));try{await t(t=>{t.type!==`unsupported`&&t.type!==`malformed`&&u(e,e=>Vt(e,t))},n.signal),u(e,e=>({...e,isRunning:!1,answering:null,elapsedMs:performance.now()-r}))}catch(t){let i=n.signal.aborted?null:f(t);u(e,e=>({...e,isRunning:!1,answering:null,failure:i,elapsedMs:performance.now()-r}))}finally{s.current.get(e)===n&&s.current.delete(e)}},[u]);return{iface:r,describeFailure:i,calls:a,run:(0,q.useCallback)((e,t)=>{let r=Bt();return o(n=>[{id:r,name:e,input:t,events:[],call:null,progress:void 0,isRunning:!0,failure:null,answering:null,startedAt:Date.now(),elapsedMs:null},...n]),d(r,(r,i)=>n.call({name:e,input:t},r,i)),r},[d,n]),answer:(0,q.useCallback)(async(e,t)=>{let r=l.current.find(t=>t.id===e),i=r?.call?.state;if(!r?.call||i?.phase!==`gate`)return;let a=r.call.callId,o=Be(r.call),s=Ee({toolName:r.name,gate:i.gate,sessionPermissions:c.current,resolution:t});s.decision===`approve`&&(c.current=s.sessionPermissions);let f=Ve(r.events);u(e,e=>({...e,answering:t.action})),await d(e,(e,t)=>n.invoke({gateId:a,operationId:o,decision:s.decision,...s.decision===`approve`&&s.secret!==void 0?{secret:s.secret}:{},replay:{name:r.name,input:i.gate.preparedArguments??r.input,gateKind:i.gate.kind,sessionPermissions:c.current,...f?{snapshot:f}:{}}},e,t))},[d,n,u]),cancel:(0,q.useCallback)(e=>{s.current.get(e)?.abort(),s.current.delete(e)},[])}}function Ut(e){return(0,U.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,...e,children:(0,U.jsx)(`path`,{d:`M13.85 0a4.16 4.16 0 0 0-2.95 1.217L1.456 10.66a.835.835 0 0 0 0 1.18.835.835 0 0 0 1.18 0l9.442-9.442a2.49 2.49 0 0 1 3.541 0 2.49 2.49 0 0 1 0 3.541L8.59 12.97l-.1.1a.835.835 0 0 0 0 1.18.835.835 0 0 0 1.18 0l.1-.098 7.03-7.034a2.49 2.49 0 0 1 3.542 0l.049.05a2.49 2.49 0 0 1 0 3.54l-8.54 8.54a1.96 1.96 0 0 0 0 2.755l1.753 1.753a.835.835 0 0 0 1.18 0 .835.835 0 0 0 0-1.18l-1.753-1.753a.266.266 0 0 1 0-.394l8.54-8.54a4.185 4.185 0 0 0 0-5.9l-.05-.05a4.16 4.16 0 0 0-2.95-1.218c-.2 0-.401.02-.6.048a4.17 4.17 0 0 0-1.17-3.552A4.16 4.16 0 0 0 13.85 0m0 3.333a.84.84 0 0 0-.59.245L6.275 10.56a4.186 4.186 0 0 0 0 5.902 4.186 4.186 0 0 0 5.902 0L19.16 9.48a.835.835 0 0 0 0-1.18.835.835 0 0 0-1.18 0l-6.985 6.984a2.49 2.49 0 0 1-3.54 0 2.49 2.49 0 0 1 0-3.54l6.983-6.985a.835.835 0 0 0 0-1.18.84.84 0 0 0-.59-.245`})})}var Wt={search:()=>[],bootstrap:()=>[]},Gt={"--font-family-body":`var(--font-family-code)`},Kt=2;function J({text:e}){return(0,U.jsx)(g,{type:`supporting`,color:`secondary`,maxLines:Kt,children:e})}function qt({field:e,children:t}){return(0,U.jsx)($e,{label:e.label,isRequired:e.isRequired,children:t})}function Jt({field:e,value:t,onChange:n}){let r=_(),[i,a]=(0,q.useState)(()=>t===void 0?``:S(t)),[o,s]=(0,q.useState)(!0);return(0,U.jsx)(k,{label:e.label,isRequired:e.isRequired,size:`sm`,rows:3,value:i,hasSpellCheck:!1,status:o?void 0:{type:`error`,message:r(`@theorem.decision.invalid_json`)},controlStyle:Gt,onChange:e=>{if(a(e),e.trim()===``)s(!0),n(void 0);else try{n(JSON.parse(e)),s(!0)}catch{s(!1)}}})}function Yt({field:e,item:t,value:n,onChange:r}){let i=Array.isArray(n)?n:[],a=he(i);return(0,U.jsx)(D,{label:e.label,isRequired:e.isRequired,description:e.description&&(0,U.jsx)(J,{text:e.description}),children:(0,U.jsxs)(c,{gap:3,children:[a.rows.map(({item:e,index:n,key:o})=>(0,U.jsxs)(l,{gap:2,vAlign:`start`,children:[(0,U.jsx)(u,{size:`fill`,children:(0,U.jsx)(X,{schema:t,value:x(e)?e:{},onChange:e=>r(i.map((t,r)=>r===n?e:t))})}),(0,U.jsx)(Je,{index:n,onRemove:()=>{a.drop(n),r(i.filter((e,t)=>t!==n))}})]},o)),(0,U.jsx)(qe,{field:e.label,onAdd:()=>r([...i,De(t)])})]})})}function Y(e){return{label:e.label,isRequired:e.isRequired,size:`sm`}}function Xt({field:e,options:t,isMenu:n,value:r,onChange:i}){return n?(0,U.jsx)(O,{...Y(e),options:t,value:typeof r==`string`?r:void 0,hasSearch:t.length>10,onChange:i}):(0,U.jsx)(qt,{field:e,children:(0,U.jsx)(l,{children:(0,U.jsx)(o,{label:e.label,size:`sm`,value:typeof r==`string`?r:``,onChange:i,children:t.map(e=>(0,U.jsx)(s,{value:e,label:e},e))})})})}function Zt({field:e,isLong:t,type:n,value:r,onChange:i}){let a=typeof r==`string`?r:``;return t?(0,U.jsx)(k,{...Y(e),rows:3,value:a,onChange:i}):(0,U.jsx)(fe,{...Y(e),type:n,value:a,onChange:i})}function Qt({field:e,value:t,onChange:n}){let r=_(),i=Array.isArray(t)?t:[];return(0,U.jsx)(ot,{...Y(e),value:i.map((e,t)=>({id:`${String(t)}:${String(e)}`,label:String(e)})),searchSource:Wt,hasCreate:!0,debounceMs:0,placeholder:r(`@theorem.decision.add_value`),onChange:e=>n(e.map(e=>typeof i[0]==`number`&&Number.isFinite(Number(e.label))?Number(e.label):e.label))})}var $t={choice:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(Xt,{field:e,options:t.options,isMenu:t.isMenu,value:n,onChange:r}),range:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(lt,{label:e.label,isRequired:e.isRequired,min:t.min,max:t.max,step:1,value:typeof n==`number`?n:t.min,valueDisplay:`text`,onChange:r}),number:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(tt,{...Y(e),value:typeof n==`number`?n:void 0,min:t.min,max:t.max,isIntegerOnly:t.isInteger,isWheelEnabled:!1,onChange:e=>r(e??void 0)}),switch:({field:e,value:t,onChange:n})=>(0,U.jsx)(ct,{label:e.label,value:t===!0,onChange:n}),date:({field:e,value:t,onChange:n})=>(0,U.jsx)(d,{...Y(e),value:typeof t==`string`?t:void 0,onChange:n}),text:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(Zt,{field:e,isLong:t.isLong,type:t.type,value:n,onChange:r}),choices:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(it,{label:e.label,value:Array.isArray(n)?n.filter(e=>typeof e==`string`):[],onChange:r,children:t.options.map(e=>(0,U.jsx)(rt,{label:e,value:e},e))}),words:({field:e,value:t,onChange:n})=>(0,U.jsx)(Qt,{field:e,value:t,onChange:n}),rows:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(Yt,{field:e,item:t.item,value:n,onChange:r}),group:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(D,{label:e.label,isRequired:e.isRequired,description:e.description&&(0,U.jsx)(J,{text:e.description}),children:(0,U.jsx)(X,{schema:t.schema,value:x(n)?n:{},onChange:r})}),json:({field:e,value:t,onChange:n})=>(0,U.jsx)(Jt,{field:e,value:t,onChange:n})};function en({field:e,value:t,onChange:n}){let r=$t[e.control.kind],i=r({field:e,control:e.control,value:t,onChange:n}),a=e.control.kind===`rows`||e.control.kind===`group`;return!e.description||a?i:(0,U.jsxs)(c,{gap:1,children:[i,(0,U.jsx)(J,{text:e.description})]})}var tn=200,nn=18;function rn({control:e}){switch(e.kind){case`number`:case`switch`:case`date`:return!0;case`choice`:return e.isMenu||e.options.join(``).length<=nn;case`text`:return!e.isLong;default:return!1}}function X({schema:e,value:t,onChange:n}){return(0,U.jsx)(A,{columns:{minWidth:tn,repeat:`fill`},gap:3,children:Oe(e).map(e=>(0,U.jsx)(`div`,{style:rn(e)?{minWidth:0,alignSelf:`start`}:{gridColumn:`1 / -1`,minWidth:0},children:(0,U.jsx)(en,{field:e,value:t[e.key],onChange:r=>n(ke(t,e.key,r))})},e.key))})}function an({schema:e,value:t,onChange:n}){return(0,U.jsx)(X,{schema:e,value:t,onChange:n})}var on=(0,q.lazy)(()=>se(()=>import(`./ToolResultCharts-DBMZY7TW.js`).then(e=>({default:e.ToolResultCharts})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77]))),sn=200,cn=236;function ln({images:e}){let[t,n]=(0,q.useState)(null);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(A,{columns:{minWidth:sn,repeat:`fill`},gap:3,children:e.map((e,t)=>(0,U.jsx)(y,{children:(0,U.jsx)(ne,{label:e.alt||`Open image`,padding:0,onClick:()=>n(t),children:(0,U.jsx)(xe,{ratio:4/3,fit:`cover`,children:(0,U.jsx)(`img`,{src:e.src,alt:e.alt,loading:`lazy`})})})},e.src))}),(0,U.jsx)(p,{isOpen:t!==null,onOpenChange:e=>{e||n(null)},media:e.map(e=>({src:e.src,alt:e.alt})),index:t??0,onIndexChange:n})]})}function un({figures:e}){let t=v(),n=(0,q.useMemo)(()=>new Intl.NumberFormat(t,{maximumFractionDigits:2}),[t]);return e.length===0?null:(0,U.jsx)(A,{columns:{minWidth:160,repeat:`fill`},gap:3,children:e.map(e=>(0,U.jsx)(y,{children:(0,U.jsx)(et,{title:e.label,value:Ne(n.format(e.value),e.unit)})},e.key))})}function dn({charts:e}){return e.length===0?null:(0,U.jsx)(q.Suspense,{fallback:(0,U.jsx)(A,{columns:{minWidth:260,repeat:`fill`},gap:3,children:e.map(e=>(0,U.jsx)(y,{children:(0,U.jsx)(m,{height:cn})},e.key))}),children:(0,U.jsx)(on,{charts:e})})}function fn({layout:e,parts:t=[]}){let n=_(),r=(0,q.useMemo)(()=>jt(e,t,n(`@theorem.host.image`)),[e,t,n]);return Mt(e,r)?(0,U.jsxs)(c,{gap:3,children:[(0,U.jsx)(un,{figures:e.figures}),(0,U.jsx)(dn,{charts:e.charts}),r.images.length>0?(0,U.jsx)(ln,{images:r.images}):null,ge(r.audio,e=>e.src).map(({item:e,key:t})=>(0,U.jsx)(y,{children:(0,U.jsx)(be,{src:e.src,mimeType:e.mimeType})},t))]}):null}function pn({output:e,parts:t}){let n=_(),r=(0,q.useMemo)(()=>kt(e),[e]),i=(0,q.useMemo)(()=>r.figures.map(e=>e.key),[r]);return(0,U.jsx)(pt,{value:e,title:n(`@theorem.host.response`),lead:(0,U.jsx)(fn,{layout:r,parts:t}),ledKeys:i})}var mn=8,hn={running:`accent`,gate:`warning`,complete:`success`,error:`error`,cancel:`neutral`};function gn(e,t,n){let r;try{r=JSON.parse(n)}catch{return{ok:!1,note:e(`@theorem.decision.invalid_json`)}}if(!x(r))return{ok:!1,note:e(`@theorem.decision.invalid_json`)};let i=Ae(t.inputSchema,r);return i.length>0?{ok:!1,note:e(`@theorem.host.missing`,{fields:i.join(`, `)}),input:r}:{ok:!0,input:r}}var _n={function:at,http:ut,mcp:Ut},vn=440,yn=2;function bn(e,t){let n=e(`@theorem.host.kind.${t.kind}`);return t.description?`${n} · ${t.description}`:n}function xn({tool:e}){let t=_();return e.access===`read-only`?null:(0,U.jsx)(l,{gap:1,wrap:`wrap`,children:(0,U.jsx)(oe,{label:t(`@theorem.tool.access.${e.access}`),size:`sm`,color:e.access===`destructive`?`red`:`orange`})})}function Sn(e,t,n){return{label:t.call?ye(t.call):t.name,duration:t.isRunning?ce(e,n-t.startedAt):t.elapsedMs==null?null:le(e,t.elapsedMs)}}function Cn({call:e,onAnswer:t}){let n=e.call?.state;return n?.phase===`gate`?n.gate.kind===`auth`?(0,U.jsx)(Ce,{gate:n.gate,toolName:e.name,submitted:e.answering===`auth`,onAuthenticated:n=>void t(e.id,{action:`auth`,secret:n})}):(0,U.jsx)(Se,{gate:n.gate,toolName:e.name,input:e.input,decided:e.answering===`auth`?null:e.answering,onDecision:n=>void t(e.id,{action:n})}):null}function Z(e){let t=e.call?.state;return!!K(e)||t?.phase===`complete`||!e.isRunning}function Q(e){let t=e.call?.state;return!Z(e)&&t?.phase!==`gate`}function wn({call:e,activity:t}){let n=e.call?.state,r=K(e);return(0,U.jsx)(_e,{children:(0,U.jsxs)(c,{gap:3,children:[r?(0,U.jsx)(y,{children:(0,U.jsx)(me,{status:`error`,role:`alert`,title:r.title,description:r.description})}):null,n?.phase===`complete`?(0,U.jsx)(pn,{output:n.output,parts:n.parts}):null,e.isRunning?null:(0,U.jsx)(y,{children:t})]})})}function Tn({call:e,onAnswer:t}){let n=_(),{label:r,duration:i}=Sn(n,e,Ue(e.isRunning));if(Q(e))return(0,U.jsx)(j,{label:r,since:e.startedAt});let a=(0,U.jsx)(g,{size:`sm`,color:`secondary`,children:i?n(`@theorem.host.finished`,{activity:r,duration:i}):r});return(0,U.jsxs)(c,{gap:3,children:[(0,U.jsx)(Cn,{call:e,onAnswer:t}),Z(e)?(0,U.jsx)(wn,{call:e,activity:a}):null]})}function En({calls:e,onPick:t}){let n=_(),r=v(),i=(0,q.useMemo)(()=>new Intl.DateTimeFormat(r,{timeStyle:`medium`}),[r]);return e.length===0?null:(0,U.jsxs)(c,{gap:1,children:[(0,U.jsx)(g,{type:`supporting`,color:`secondary`,as:`h3`,children:n(`@theorem.host.earlier`)}),(0,U.jsx)(We,{hasDividers:!0,density:`compact`,children:e.slice(0,mn).map(e=>{let r=Rt(e);return(0,U.jsx)(Ge,{label:e.name,startContent:(0,U.jsx)(G,{variant:hn[r],label:n(`@theorem.host.status.${r}`),isPulsing:e.isRunning}),endContent:(0,U.jsx)(g,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:i.format(e.startedAt)}),onClick:()=>t(e)},e.id)})})]})}function Dn({tools:e,tool:t,check:n,text:r,view:i,shown:a,onText:o,onPick:s,onView:l,onRun:u,onStop:d}){let f=_(),p=`input`in n?n.input:void 0,m=i===`fields`&&p!==void 0;return(0,U.jsxs)(Ye,{title:f(`@theorem.host.request`),view:m?`fields`:`json`,hasFields:p!==void 0,onView:l,onRun:u,children:[(0,U.jsxs)(c,{gap:2,children:[(0,U.jsx)(O,{label:f(`@theorem.host.tool`),size:`sm`,options:e.map(e=>({value:e.name,label:e.name,icon:_n[e.kind],description:bn(f,e)})),value:t.name,hasSearch:e.length>8,renderOption:e=>(0,U.jsx)(`div`,{style:{width:vn,maxWidth:`100%`,minWidth:0},children:(0,U.jsx)(nt,{icon:e.icon,label:e.label,description:e.description&&(0,U.jsx)(g,{type:`supporting`,color:`secondary`,maxLines:yn,children:e.description})})}),onChange:s}),(0,U.jsx)(xn,{tool:t})]}),m?(0,U.jsx)(an,{schema:t.inputSchema,value:p,onChange:e=>{o(S(e))}},t.name):(0,U.jsx)(Ze,{label:f(`@theorem.host.request`),text:r,isInvalid:p===void 0,onChange:o}),(0,U.jsx)(Xe,{note:n.ok?f(`@theorem.host.shortcut`):n.note,isReady:n.ok,isRunning:a?.isRunning===!0,runLabel:f(`@theorem.host.run`),runningLabel:f(`@theorem.host.running`),stopLabel:f(`@theorem.host.stop`),onRun:u,onStop:()=>{a&&d(a.id)}})]})}function On(e,t,n,r){return!t||!n?.ok||r?.isRunning?null:e.run(t.name,n.input)}function kn(e,t){let n=_(),[r,i]=(0,q.useState)(e.tools[0]?.name),[a,o]=(0,q.useState)({}),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(`fields`),{tool:d,text:f,shown:p,earlier:m}=zt({tools:e.tools,picked:r,drafts:a,calls:t.calls,shownId:s}),h=d?gn(n,d,f):null;return{tool:d,text:f,shown:p,earlier:m,check:h,view:l,setView:u,setPicked:i,setText:e=>{d&&o(t=>({...t,[d.name]:e}))},run:()=>{let e=On(t,d,h,p);e!==null&&c(e)},pick:e=>{i(e.name),o(t=>({...t,[e.name]:S(e.input)})),c(e.id)}}}function An({shown:e,earlier:t,onAnswer:n,onPick:r}){return(0,U.jsxs)(U.Fragment,{children:[e?(0,U.jsx)(Tn,{call:e,onAnswer:n}):null,(0,U.jsx)(En,{calls:t,onPick:r})]})}function jn(e,t,n,r,i){if(!e)return i;let a=r.length===0;return!n&&a?null:(0,U.jsx)(Ke,{label:t,fill:n!=null&&Q(n)&&a,children:i})}function Mn({transport:e,iface:t,host:n,maxWidth:r=`960px`,trace:i,flush:a,columns:o=!1,className:s,style:c}){let l=_(),u=pe(t,e.traces,i),d=kn(t,n),{tool:f,check:p,shown:m,earlier:h}=d;return(0,U.jsxs)(Qe,{inspector:u,maxWidth:r,flush:a,columns:o,requestLabel:l(`@theorem.host.request`),className:s,style:c,children:[f&&p?(0,U.jsx)(Dn,{tools:t.tools,tool:f,check:p,text:d.text,view:d.view,shown:m,onText:d.setText,onPick:d.setPicked,onView:d.setView,onRun:d.run,onStop:n.cancel}):(0,U.jsx)(He,{title:l(`@theorem.host.no_tools`)}),jn(o,l(`@theorem.host.response`),m,h,(0,U.jsx)(An,{shown:m,earlier:h,onAnswer:n.answer,onPick:d.pick}))]})}function Nn(e){let t=_(),n=Ht(e.transport,e.pageTools);return n.describeFailure?(0,U.jsx)(st,{title:n.describeFailure.error}):n.iface?(0,U.jsx)(Mn,{...e,iface:n.iface,host:n}):(0,U.jsx)(j,{label:t(`@theorem.chat.loading`)})}function Pn({endpoint:e,http:t,transport:n,theme:r,mode:i,labels:a,detectCodeLanguage:o,...s}){let c=(0,q.useRef)(t);c.current=t;let l=(0,q.useMemo)(()=>n??te({...c.current,endpoint:e}),[n,e]);return(0,U.jsx)(re,{theme:r,mode:i,children:(0,U.jsx)(ue,{labels:a,children:(0,U.jsx)(ft,{detectCodeLanguage:o,children:(0,U.jsx)(Nn,{...s,transport:l})})})})}var Fn=e({HostView:()=>$,StudioHostConsole:()=>In});function In(e){let t=mt(e,h,ee);return(0,U.jsx)($,{...e,transport:t})}function $({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let o=(0,q.useMemo)(()=>Te(e),[e]);return(0,U.jsx)(Pn,{detectCodeLanguage:!0,labels:we,transport:t,pageTools:o,trace:n,flush:r,columns:i,className:a})}export{$ as HostView,In as StudioHostConsole,Ft as n,Fn as t};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolResultCharts-xDwNDd-T.js","assets/rolldown-runtime-hePW80VL.js","assets/themeProps-3IqahpCr.js","assets/VStack-CkVMcNiK.js","assets/padding.stylex-B76907Zf.js","assets/mergeProps-ptS-gIMz.js","assets/StackItem-CQviqAfM.js","assets/Text-BsiAsowd.js","assets/sharedResizeObserver-4U9Xq5Oq.js","assets/preload-helper-DpV6A1kQ.js","assets/Card-Ghe4ozhC.js","assets/Icon-ZfFwTt8n.js","assets/tokens.stylex-DkHf0P9C.js","assets/devWarning-DxuplmRl.js","assets/useMediaQuery-BCT0NUeZ.js","assets/container.stylex-BmOi-8DQ.js","assets/arrive-DvbqpeRS.js","assets/createReactComponent-CZwsv6DD.js","assets/shaped-data-0GUF7Al3.js","assets/host-patterns-C9RMP16Q.js","assets/TraceOverview-DCGew7UN.js","assets/CodeBlock-Kjgv83A6.js","assets/focusOutline.stylex-BT0kfa4t.js","assets/IconButton-CG5klqF1.js","assets/useTooltip-rxACYEAC.js","assets/useLayerDismissal-BAnTRYTt.js","assets/useClipboard-B1amtN2V.js","assets/useScrollableArea-vxuztwym.js","assets/useDevWarning-Cna3kqg1.js","assets/labels-provider-BSiD6Lrb.js","assets/Tooltip-CTEuMRLe.js","assets/trace-record-BjsBbPRl.js","assets/index-Dajtrq_Z.js","assets/SegmentedControlItem-BLuJOusN.js","assets/fieldParts-Cs6Amprh.js","assets/isRtlElement-BG33-k_H.js","assets/browser-transport-DYgEItHi.js","assets/use-trace-records-BkAYJz0M.js","assets/ScrollableArea-C8AVuqnt.js","assets/IconAlertTriangle-BqAEqqdU.js","assets/Banner-C4MPbvft.js","assets/Center-nHS1JSux.js","assets/IconSearch-BTx66a40.js","assets/schemas-BQ9Jydzb.js","assets/tool-schema-E9NPuDcN.js","assets/reader-BB7aL5yX.js","assets/live-ingress-lDUGPwth.js","assets/trace-schema-9CdEyG6Q.js","assets/stub-DyzmGexy.js","assets/tree-2VeaKg0m.js","assets/types-CMdljBjd.js","assets/useScrollLock-Dyf6PHJt.js","assets/useContainerReveal-BFy8N_QU.js","assets/focusReturn-CTppP2k0.js","assets/Dialog-BDUExlk_.js","assets/chainEventHandlers-C6ttXGfW.js","assets/HoverCard-C6thuzrf.js","assets/CheckboxInput-C9kbVyhK.js","assets/IconEye-BB5aY-wQ.js","assets/studio-labels-C1pvg0JC.js","assets/turn-client-Dy9-U9_L.js","assets/encode-files-DZ4tVtEQ.js","assets/CollapsibleGroup-PavPZ114.js","assets/crypto-Boxudvjl.js","assets/workspace-Cno6Ge26.js","assets/lent-keys-C32ems-I.js","assets/editors-BJX_S59A.js","assets/studio-session-yEqFQo5o.js","assets/EmptyState-C8W4JKBZ.js","assets/use-second-ticker-VX91zrxj.js","assets/use-second-ticker-CnxaP3LD.css","assets/ContextMenu-BGP2gdee.js","assets/useAdaptivePresentation-BY_zvjIp.js","assets/BottomSheet-BQPskY35.js","assets/Section-DJ97F7QE.js","assets/index-Cbs7B46A.css","assets/trace-patterns-CS99kExN.js","assets/CardWall-CBRLdDZW.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{c as n,l as r,n as i,u as a}from"./themeProps-3IqahpCr.js";import{n as o,t as s}from"./SegmentedControlItem-BLuJOusN.js";import{t as c}from"./VStack-CkVMcNiK.js";import{n as l,t as u}from"./StackItem-CQviqAfM.js";import{t as d}from"./DateInput-BJt-UTCy.js";import{N as f,c as p,d as m,h,i as ee,j as te,l as ne,s as re}from"./browser-transport-DYgEItHi.js";import{t as ie}from"./mergeProps-ptS-gIMz.js";import{T as ae,m as oe}from"./fieldParts-Cs6Amprh.js";import{t as g}from"./Text-BsiAsowd.js";import{t as se}from"./preload-helper-DpV6A1kQ.js";import{i as ce,l as le,n as _,t as ue}from"./labels-provider-BSiD6Lrb.js";import{n as v}from"./Card-Ghe4ozhC.js";import{t as de}from"./Tooltip-CTEuMRLe.js";import{n as fe}from"./ScrollableArea-C8AVuqnt.js";import{a as pe,t as me}from"./Banner-C4MPbvft.js";import{a as he,i as ge,n as _e,t as y}from"./arrive-DvbqpeRS.js";import{b as ve,f as ye,h as be,m as xe,n as Se,r as Ce,t as we,v as Te,y as Ee}from"./studio-labels-C1pvg0JC.js";import{c as De,d as Oe,f as ke,l as Ae,u as je}from"./tool-schema-E9NPuDcN.js";import{_ as Me,a as b,b as Ne,c as x,d as Pe,g as Fe,l as S,m as C,n as w,o as Ie,r as Le,t as Re,v as T,y as E}from"./shaped-data-0GUF7Al3.js";import{S as ze,i as Be,u as Ve}from"./turn-client-Dy9-U9_L.js";import{t as He}from"./EmptyState-C8W4JKBZ.js";import{t as Ue}from"./use-second-ticker-VX91zrxj.js";import{i as We,r as Ge}from"./ContextMenu-BGP2gdee.js";import{a as Ke,c as qe,d as Je,i as Ye,l as D,o as Xe,r as Ze,t as Qe,u as $e}from"./ConsoleFrame-BkzieVRC.js";import{i as et}from"./trace-patterns-CS99kExN.js";import{D as tt,I as O,L as nt,N as rt,P as it,S as k,St as at,T as ot,_ as st,b as ct,f as lt,gt as ut,h as dt,j as ft,p as A,v as j,w as pt}from"./index-Dajtrq_Z.js";import{t as mt}from"./studio-console-DwhqnNyw.js";var ht=4,gt=3,_t=3,M=8,vt=6,N=3,yt=3,bt=/(^|_)(id|ids|lat|lon|lng|latitude|longitude|offset|interval|index|rank|order)$|Id$|^(generationtime_ms|utc_offset_seconds)$/i,xt=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function St(e){if(/\s/.test(e))return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&xt.test(t.pathname)}catch{return!1}}function P(e){return!bt.test(e)}function F(e){return/^[A-Z][A-Z0-9]{1,5}$/.test(e)?e:b(e)}function I(e,t){if(!P(e)||t&&e in t&&Pe(t[e])===void 0)return;let{label:n,unit:r}=Le(e,t);return{label:F(e)===e?e:n,unit:r}}function L(e,t){let n=[];for(let[r,i]of C(e)){if(typeof i!=`number`||!Number.isFinite(i))continue;let e=I(r,t);e&&n.push({key:r,value:i,...e})}return n.sort((e,t)=>Number(t.unit!==void 0)-Number(e.unit!==void 0)).slice(0,ht)}function Ct(e){if(!x(e))return[];for(let[t,n]of C(e)){let r=E(n);if(!x(r)||w(r))continue;let i=Object.values(r);if(i.length===0||!i.every(Ie))continue;let a=L(r,T(e,t));if(a.length>0)return a}return L(e,void 0)}function R(e,t){return new Set(e.map(e=>e[t])).size}function z(e,t,n){return[...new Set(e.flatMap(e=>Object.keys(e)))].filter(n=>n!==t&&e.every(e=>typeof e[n]==`number`||e[n]===null)&&R(e,n)>1).flatMap(e=>{let t=I(e,n);return t?[{key:e,...t}]:[]})}function wt(e){let[t]=e;if(t)return Object.keys(t).find(t=>e.every(e=>typeof e[t]==`string`&&Re.test(e[t])))}function Tt(e){let t=e.map(e=>e.label.split(` `)),[n=[]]=t,r=0;for(;r<n.length&&t.every(e=>e.length>r+1&&e[r]===n[r]);)r++;if(r)return{title:n.slice(0,r).join(` `),series:e.map((e,n)=>{let i=(t[n]??[]).slice(r).join(` `);return{...e,label:i.charAt(0).toUpperCase()+i.slice(1)}})}}function Et(e,t,n,r,i){let a=new Map;for(let e of z(n,r,i)){let t=a.get(e.unit??``)??[];t.push(e),a.set(e.unit??``,t)}return[...a.values()].map(i=>{let a=i.slice(0,_t),o=a.length>1?Tt(a):void 0;return{kind:`time`,key:`${e}:${a.map(e=>e.key).join(`+`)}`,title:a.length===1?a[0]?.label??t:o?.title??(t||a.map(e=>e.label).join(` · `)),x:r,series:o?.series??a,rows:n}})}function Dt(e){let[t]=e,n=t?Me(t):void 0;if(!t||!n||!e.every(e=>typeof e[n]==`string`||typeof e[n]==`number`))return;if(R(e,n)===e.length)return n;let r=t=>e.reduce((e,n)=>e+String(n[t]).length,0),[i]=Object.keys(t).filter(t=>e.every(e=>typeof e[t]==`string`)&&R(e,t)===e.length).sort((e,t)=>r(e)-r(t));return i??n}function Ot(e,t,n,r){let i=Dt(n);return i?z(n,i,r).sort((e,t)=>R(n,t.key)-R(n,e.key)).map(r=>({kind:`category`,key:`${e}:${r.key}`,title:t?`${t} · ${r.label}`:r.label,series:r,rows:n.filter(e=>typeof e[r.key]==`number`).map(e=>({label:String(e[i]),value:e[r.key]})).sort((e,t)=>t.value-e.value).slice(0,M)})):[]}function B(e,t,n,r){if(n.length<N)return[];let i=wt(n);return i?Et(e,t,n,i,r):Ot(e,t,n,r)}function V(e,t,n,r,i){if(i>yt)return[];if(Array.isArray(e)){let i=e.map(E);return i.every(x)?B(t,n,i,r):[]}if(!x(e))return[];let a=w(e);if(a)return B(t,n,Fe(e,a),r);let o=C(e),s=o.filter(([e,t])=>typeof t==`number`&&P(e));if(i>0&&s.length>=N&&s.length===o.length){let e=s.map(([e,t])=>({label:F(e),value:t}));return[{kind:`category`,key:t,title:n,series:{key:`value`,label:n},rows:e.sort((e,t)=>t.value-e.value).slice(0,M)}]}return o.flatMap(([r,a])=>V(E(a),t?`${t}.${r}`:r,i===0?b(r):`${n} › ${b(r)}`,T(e,r),i+1))}function H(e,t,n,r){if(r.size>=vt||n>4)return;let i=E(e);if(typeof i==`string`)St(i)&&!r.has(i)&&r.set(i,{src:i,alt:b(t||`image`)});else if(Array.isArray(i))for(let e of i)H(e,t,n+1,r);else if(x(i))for(let[e,t]of Object.entries(i))H(t,e,n+1,r)}function kt(e){let t=E(e),n=new Map;return H(t,``,0,n),{figures:Ct(t),charts:V(t,``,``,void 0,0).slice(0,gt),images:[...n.values()]}}function At(e){return e.mimeType&&e.data?`data:${e.mimeType};base64,${e.data}`:void 0}function jt(e,t,n){let r=t.flatMap(e=>{let t=At(e);return t?[{type:e.type,src:t,mimeType:e.mimeType}]:[]});return{images:[...r.filter(e=>e.type===`image`).map(({src:e})=>({src:e,alt:n})),...e.images],audio:r.filter(e=>e.type===`audio`).map(({src:e,mimeType:t})=>({src:e,...t?{mimeType:t}:{}}))}}function Mt(e,t){return e.figures.length+e.charts.length+t.images.length+t.audio.length>0}var Nt=864e5,Pt=10;function Ft(e){return e.some(e=>e.includes(`T`))?{tick:Math.abs(Date.parse(e.at(-1)??``)-Date.parse(e[0]??``))<=Nt?{hour:`numeric`}:{month:`short`,day:`numeric`},when:{dateStyle:`medium`,timeStyle:`short`}}:{tick:e.length<=Pt?{weekday:`short`,timeZone:`UTC`}:{month:`short`,day:`numeric`,timeZone:`UTC`},when:{dateStyle:`medium`,timeZone:`UTC`}}}var U=n(),W={base:{k1xSpc:`x3nfvp2`,kGNEyG:`x6s0dn4`,kjj79g:`xl56j7k`,kaIpWk:`x16rqkct`,kmuXW:`x2lah0s`,kzqmXN:`x1xc55vz`,kZKoxP:`xdk7pt`,$$css:!0},pulsing:{kKVMdj:`x1mta51n`,k44tkh:`x1c74tu6`,kyAemX:`x4hg4is`,ko0y90:`xa4qsjk`,$$css:!0},reducedMotion:{kjO2d4:`x1aquc0h`,$$css:!0}},It={success:{kWkggS:`xdsz4j9`,kMwMTN:`xri61p4`,$$css:!0},warning:{kWkggS:`x1q8g9m5`,kMwMTN:`xrebv38`,$$css:!0},error:{kWkggS:`x1pjz0fi`,kMwMTN:`x1m024r3`,$$css:!0},accent:{kWkggS:`x1ewilqj`,kMwMTN:`x17wrial`,$$css:!0},neutral:{kWkggS:`x1q5y3ey`,kMwMTN:`xrkvqaz`,$$css:!0}};function G({variant:e,label:t,isPulsing:n=!1,tooltip:a,icon:o,xstyle:s,className:c,style:l,ref:u,...d}){let f=ae(o),p=(0,U.jsx)(`span`,{ref:u,role:`img`,"aria-label":t,...ie(i(`status-dot`,{variant:e}),r(W.base,It[e],n&&W.pulsing,n&&W.reducedMotion,s),c,l),...d,children:f&&(0,U.jsx)(`span`,{"aria-hidden":`true`,className:`x78zum5 x6s0dn4 xl56j7k x14ju556 x1xc55vz xdk7pt`,children:o})});return a?(0,U.jsx)(de,{content:a,children:p}):p}G.displayName=`StatusDot`;var Lt=new Set([`gate`,`complete`,`error`,`cancel`]);function Rt({call:e,failure:t,isRunning:n}){let r=e?.state?.phase;return r!==void 0&&Lt.has(r)?r:t?`error`:n?`running`:`cancel`}function K({call:e,failure:t}){if(t)return{title:t.error};let n=e?.state;if(n?.phase!==`error`)return null;let{error:r,message:i}=n.failure;return r?r===i?{title:r}:{title:r,description:i}:{title:i}}function zt(e){let t=e.tools.find(t=>t.name===e.picked)??e.tools[0],n=t?e.drafts[t.name]??S(je(t.inputSchema)):``,r=e.calls.filter(e=>e.name===t?.name),i=r.find(t=>t.id===e.shownId)??r[0]??null;return{tool:t,text:n,shown:i,earlier:e.calls.filter(e=>e!==i)}}var q=t(a(),1);function Bt(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`call-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function Vt(e,t){let n=[...e.events,t],r=t.type===`tool`&&t.tool.phase===`progress`?t.tool.data:e.progress;return{...e,events:n,call:ze(n)[0]??null,progress:r}}function Ht(e,t){let n=(0,q.useMemo)(()=>ve(e,t),[e,t]),{iface:r,describeFailure:i}=dt(n),[a,o]=(0,q.useState)([]),s=(0,q.useRef)(new Map),c=(0,q.useRef)([]),l=(0,q.useRef)(a);l.current=a,(0,q.useEffect)(()=>{let e=s.current;return()=>{for(let t of e.values())t.abort()}},[]);let u=(0,q.useCallback)((e,t)=>{o(n=>n.map(n=>n.id===e?t(n):n))},[]),d=(0,q.useCallback)(async(e,t)=>{let n=new AbortController;s.current.set(e,n);let r=performance.now();u(e,e=>({...e,isRunning:!0,failure:null}));try{await t(t=>{t.type!==`unsupported`&&t.type!==`malformed`&&u(e,e=>Vt(e,t))},n.signal),u(e,e=>({...e,isRunning:!1,answering:null,elapsedMs:performance.now()-r}))}catch(t){let i=n.signal.aborted?null:f(t);u(e,e=>({...e,isRunning:!1,answering:null,failure:i,elapsedMs:performance.now()-r}))}finally{s.current.get(e)===n&&s.current.delete(e)}},[u]);return{iface:r,describeFailure:i,calls:a,run:(0,q.useCallback)((e,t)=>{let r=Bt();return o(n=>[{id:r,name:e,input:t,events:[],call:null,progress:void 0,isRunning:!0,failure:null,answering:null,startedAt:Date.now(),elapsedMs:null},...n]),d(r,(r,i)=>n.call({name:e,input:t},r,i)),r},[d,n]),answer:(0,q.useCallback)(async(e,t)=>{let r=l.current.find(t=>t.id===e),i=r?.call?.state;if(!r?.call||i?.phase!==`gate`)return;let a=r.call.callId,o=Be(r.call),s=Ee({toolName:r.name,gate:i.gate,sessionPermissions:c.current,resolution:t});s.decision===`approve`&&(c.current=s.sessionPermissions);let f=Ve(r.events);u(e,e=>({...e,answering:t.action})),await d(e,(e,t)=>n.invoke({gateId:a,operationId:o,decision:s.decision,...s.decision===`approve`&&s.secret!==void 0?{secret:s.secret}:{},replay:{name:r.name,input:i.gate.preparedArguments??r.input,gateKind:i.gate.kind,sessionPermissions:c.current,...f?{snapshot:f}:{}}},e,t))},[d,n,u]),cancel:(0,q.useCallback)(e=>{s.current.get(e)?.abort(),s.current.delete(e)},[])}}function Ut(e){return(0,U.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,...e,children:(0,U.jsx)(`path`,{d:`M13.85 0a4.16 4.16 0 0 0-2.95 1.217L1.456 10.66a.835.835 0 0 0 0 1.18.835.835 0 0 0 1.18 0l9.442-9.442a2.49 2.49 0 0 1 3.541 0 2.49 2.49 0 0 1 0 3.541L8.59 12.97l-.1.1a.835.835 0 0 0 0 1.18.835.835 0 0 0 1.18 0l.1-.098 7.03-7.034a2.49 2.49 0 0 1 3.542 0l.049.05a2.49 2.49 0 0 1 0 3.54l-8.54 8.54a1.96 1.96 0 0 0 0 2.755l1.753 1.753a.835.835 0 0 0 1.18 0 .835.835 0 0 0 0-1.18l-1.753-1.753a.266.266 0 0 1 0-.394l8.54-8.54a4.185 4.185 0 0 0 0-5.9l-.05-.05a4.16 4.16 0 0 0-2.95-1.218c-.2 0-.401.02-.6.048a4.17 4.17 0 0 0-1.17-3.552A4.16 4.16 0 0 0 13.85 0m0 3.333a.84.84 0 0 0-.59.245L6.275 10.56a4.186 4.186 0 0 0 0 5.902 4.186 4.186 0 0 0 5.902 0L19.16 9.48a.835.835 0 0 0 0-1.18.835.835 0 0 0-1.18 0l-6.985 6.984a2.49 2.49 0 0 1-3.54 0 2.49 2.49 0 0 1 0-3.54l6.983-6.985a.835.835 0 0 0 0-1.18.84.84 0 0 0-.59-.245`})})}var Wt={search:()=>[],bootstrap:()=>[]},Gt={"--font-family-body":`var(--font-family-code)`},Kt=2;function J({text:e}){return(0,U.jsx)(g,{type:`supporting`,color:`secondary`,maxLines:Kt,children:e})}function qt({field:e,children:t}){return(0,U.jsx)($e,{label:e.label,isRequired:e.isRequired,children:t})}function Jt({field:e,value:t,onChange:n}){let r=_(),[i,a]=(0,q.useState)(()=>t===void 0?``:S(t)),[o,s]=(0,q.useState)(!0);return(0,U.jsx)(k,{label:e.label,isRequired:e.isRequired,size:`sm`,rows:3,value:i,hasSpellCheck:!1,status:o?void 0:{type:`error`,message:r(`@theorem.decision.invalid_json`)},controlStyle:Gt,onChange:e=>{if(a(e),e.trim()===``)s(!0),n(void 0);else try{n(JSON.parse(e)),s(!0)}catch{s(!1)}}})}function Yt({field:e,item:t,value:n,onChange:r}){let i=Array.isArray(n)?n:[],a=he(i);return(0,U.jsx)(D,{label:e.label,isRequired:e.isRequired,description:e.description&&(0,U.jsx)(J,{text:e.description}),children:(0,U.jsxs)(c,{gap:3,children:[a.rows.map(({item:e,index:n,key:o})=>(0,U.jsxs)(l,{gap:2,vAlign:`start`,children:[(0,U.jsx)(u,{size:`fill`,children:(0,U.jsx)(X,{schema:t,value:x(e)?e:{},onChange:e=>r(i.map((t,r)=>r===n?e:t))})}),(0,U.jsx)(Je,{index:n,onRemove:()=>{a.drop(n),r(i.filter((e,t)=>t!==n))}})]},o)),(0,U.jsx)(qe,{field:e.label,onAdd:()=>r([...i,De(t)])})]})})}function Y(e){return{label:e.label,isRequired:e.isRequired,size:`sm`}}function Xt({field:e,options:t,isMenu:n,value:r,onChange:i}){return n?(0,U.jsx)(O,{...Y(e),options:t,value:typeof r==`string`?r:void 0,hasSearch:t.length>10,onChange:i}):(0,U.jsx)(qt,{field:e,children:(0,U.jsx)(l,{children:(0,U.jsx)(o,{label:e.label,size:`sm`,value:typeof r==`string`?r:``,onChange:i,children:t.map(e=>(0,U.jsx)(s,{value:e,label:e},e))})})})}function Zt({field:e,isLong:t,type:n,value:r,onChange:i}){let a=typeof r==`string`?r:``;return t?(0,U.jsx)(k,{...Y(e),rows:3,value:a,onChange:i}):(0,U.jsx)(fe,{...Y(e),type:n,value:a,onChange:i})}function Qt({field:e,value:t,onChange:n}){let r=_(),i=Array.isArray(t)?t:[];return(0,U.jsx)(ot,{...Y(e),value:i.map((e,t)=>({id:`${String(t)}:${String(e)}`,label:String(e)})),searchSource:Wt,hasCreate:!0,debounceMs:0,placeholder:r(`@theorem.decision.add_value`),onChange:e=>n(e.map(e=>typeof i[0]==`number`&&Number.isFinite(Number(e.label))?Number(e.label):e.label))})}var $t={choice:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(Xt,{field:e,options:t.options,isMenu:t.isMenu,value:n,onChange:r}),range:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(lt,{label:e.label,isRequired:e.isRequired,min:t.min,max:t.max,step:1,value:typeof n==`number`?n:t.min,valueDisplay:`text`,onChange:r}),number:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(tt,{...Y(e),value:typeof n==`number`?n:void 0,min:t.min,max:t.max,isIntegerOnly:t.isInteger,isWheelEnabled:!1,onChange:e=>r(e??void 0)}),switch:({field:e,value:t,onChange:n})=>(0,U.jsx)(ct,{label:e.label,value:t===!0,onChange:n}),date:({field:e,value:t,onChange:n})=>(0,U.jsx)(d,{...Y(e),value:typeof t==`string`?t:void 0,onChange:n}),text:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(Zt,{field:e,isLong:t.isLong,type:t.type,value:n,onChange:r}),choices:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(it,{label:e.label,value:Array.isArray(n)?n.filter(e=>typeof e==`string`):[],onChange:r,children:t.options.map(e=>(0,U.jsx)(rt,{label:e,value:e},e))}),words:({field:e,value:t,onChange:n})=>(0,U.jsx)(Qt,{field:e,value:t,onChange:n}),rows:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(Yt,{field:e,item:t.item,value:n,onChange:r}),group:({field:e,control:t,value:n,onChange:r})=>(0,U.jsx)(D,{label:e.label,isRequired:e.isRequired,description:e.description&&(0,U.jsx)(J,{text:e.description}),children:(0,U.jsx)(X,{schema:t.schema,value:x(n)?n:{},onChange:r})}),json:({field:e,value:t,onChange:n})=>(0,U.jsx)(Jt,{field:e,value:t,onChange:n})};function en({field:e,value:t,onChange:n}){let r=$t[e.control.kind],i=r({field:e,control:e.control,value:t,onChange:n}),a=e.control.kind===`rows`||e.control.kind===`group`;return!e.description||a?i:(0,U.jsxs)(c,{gap:1,children:[i,(0,U.jsx)(J,{text:e.description})]})}var tn=200,nn=18;function rn({control:e}){switch(e.kind){case`number`:case`switch`:case`date`:return!0;case`choice`:return e.isMenu||e.options.join(``).length<=nn;case`text`:return!e.isLong;default:return!1}}function X({schema:e,value:t,onChange:n}){return(0,U.jsx)(A,{columns:{minWidth:tn,repeat:`fill`},gap:3,children:Oe(e).map(e=>(0,U.jsx)(`div`,{style:rn(e)?{minWidth:0,alignSelf:`start`}:{gridColumn:`1 / -1`,minWidth:0},children:(0,U.jsx)(en,{field:e,value:t[e.key],onChange:r=>n(ke(t,e.key,r))})},e.key))})}function an({schema:e,value:t,onChange:n}){return(0,U.jsx)(X,{schema:e,value:t,onChange:n})}var on=(0,q.lazy)(()=>se(()=>import(`./ToolResultCharts-xDwNDd-T.js`).then(e=>({default:e.ToolResultCharts})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77]))),sn=200,cn=236;function ln({images:e}){let[t,n]=(0,q.useState)(null);return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(A,{columns:{minWidth:sn,repeat:`fill`},gap:3,children:e.map((e,t)=>(0,U.jsx)(y,{children:(0,U.jsx)(ne,{label:e.alt||`Open image`,padding:0,onClick:()=>n(t),children:(0,U.jsx)(xe,{ratio:4/3,fit:`cover`,children:(0,U.jsx)(`img`,{src:e.src,alt:e.alt,loading:`lazy`})})})},e.src))}),(0,U.jsx)(p,{isOpen:t!==null,onOpenChange:e=>{e||n(null)},media:e.map(e=>({src:e.src,alt:e.alt})),index:t??0,onIndexChange:n})]})}function un({figures:e}){let t=v(),n=(0,q.useMemo)(()=>new Intl.NumberFormat(t,{maximumFractionDigits:2}),[t]);return e.length===0?null:(0,U.jsx)(A,{columns:{minWidth:160,repeat:`fill`},gap:3,children:e.map(e=>(0,U.jsx)(y,{children:(0,U.jsx)(et,{title:e.label,value:Ne(n.format(e.value),e.unit)})},e.key))})}function dn({charts:e}){return e.length===0?null:(0,U.jsx)(q.Suspense,{fallback:(0,U.jsx)(A,{columns:{minWidth:260,repeat:`fill`},gap:3,children:e.map(e=>(0,U.jsx)(y,{children:(0,U.jsx)(m,{height:cn})},e.key))}),children:(0,U.jsx)(on,{charts:e})})}function fn({layout:e,parts:t=[]}){let n=_(),r=(0,q.useMemo)(()=>jt(e,t,n(`@theorem.host.image`)),[e,t,n]);return Mt(e,r)?(0,U.jsxs)(c,{gap:3,children:[(0,U.jsx)(un,{figures:e.figures}),(0,U.jsx)(dn,{charts:e.charts}),r.images.length>0?(0,U.jsx)(ln,{images:r.images}):null,ge(r.audio,e=>e.src).map(({item:e,key:t})=>(0,U.jsx)(y,{children:(0,U.jsx)(be,{src:e.src,mimeType:e.mimeType})},t))]}):null}function pn({output:e,parts:t}){let n=_(),r=(0,q.useMemo)(()=>kt(e),[e]),i=(0,q.useMemo)(()=>r.figures.map(e=>e.key),[r]);return(0,U.jsx)(pt,{value:e,title:n(`@theorem.host.response`),lead:(0,U.jsx)(fn,{layout:r,parts:t}),ledKeys:i})}var mn=8,hn={running:`accent`,gate:`warning`,complete:`success`,error:`error`,cancel:`neutral`};function gn(e,t,n){let r;try{r=JSON.parse(n)}catch{return{ok:!1,note:e(`@theorem.decision.invalid_json`)}}if(!x(r))return{ok:!1,note:e(`@theorem.decision.invalid_json`)};let i=Ae(t.inputSchema,r);return i.length>0?{ok:!1,note:e(`@theorem.host.missing`,{fields:i.join(`, `)}),input:r}:{ok:!0,input:r}}var _n={function:at,http:ut,mcp:Ut},vn=440,yn=2;function bn(e,t){let n=e(`@theorem.host.kind.${t.kind}`);return t.description?`${n} · ${t.description}`:n}function xn({tool:e}){let t=_();return e.access===`read-only`?null:(0,U.jsx)(l,{gap:1,wrap:`wrap`,children:(0,U.jsx)(oe,{label:t(`@theorem.tool.access.${e.access}`),size:`sm`,color:e.access===`destructive`?`red`:`orange`})})}function Sn(e,t,n){return{label:t.call?ye(t.call):t.name,duration:t.isRunning?ce(e,n-t.startedAt):t.elapsedMs==null?null:le(e,t.elapsedMs)}}function Cn({call:e,onAnswer:t}){let n=e.call?.state;return n?.phase===`gate`?n.gate.kind===`auth`?(0,U.jsx)(Ce,{gate:n.gate,toolName:e.name,submitted:e.answering===`auth`,onAuthenticated:n=>void t(e.id,{action:`auth`,secret:n})}):(0,U.jsx)(Se,{gate:n.gate,toolName:e.name,input:e.input,decided:e.answering===`auth`?null:e.answering,onDecision:n=>void t(e.id,{action:n})}):null}function Z(e){let t=e.call?.state;return!!K(e)||t?.phase===`complete`||!e.isRunning}function Q(e){let t=e.call?.state;return!Z(e)&&t?.phase!==`gate`}function wn({call:e,activity:t}){let n=e.call?.state,r=K(e);return(0,U.jsx)(_e,{children:(0,U.jsxs)(c,{gap:3,children:[r?(0,U.jsx)(y,{children:(0,U.jsx)(me,{status:`error`,role:`alert`,title:r.title,description:r.description})}):null,n?.phase===`complete`?(0,U.jsx)(pn,{output:n.output,parts:n.parts}):null,e.isRunning?null:(0,U.jsx)(y,{children:t})]})})}function Tn({call:e,onAnswer:t}){let n=_(),{label:r,duration:i}=Sn(n,e,Ue(e.isRunning));if(Q(e))return(0,U.jsx)(j,{label:r,since:e.startedAt});let a=(0,U.jsx)(g,{size:`sm`,color:`secondary`,children:i?n(`@theorem.host.finished`,{activity:r,duration:i}):r});return(0,U.jsxs)(c,{gap:3,children:[(0,U.jsx)(Cn,{call:e,onAnswer:t}),Z(e)?(0,U.jsx)(wn,{call:e,activity:a}):null]})}function En({calls:e,onPick:t}){let n=_(),r=v(),i=(0,q.useMemo)(()=>new Intl.DateTimeFormat(r,{timeStyle:`medium`}),[r]);return e.length===0?null:(0,U.jsxs)(c,{gap:1,children:[(0,U.jsx)(g,{type:`supporting`,color:`secondary`,as:`h3`,children:n(`@theorem.host.earlier`)}),(0,U.jsx)(We,{hasDividers:!0,density:`compact`,children:e.slice(0,mn).map(e=>{let r=Rt(e);return(0,U.jsx)(Ge,{label:e.name,startContent:(0,U.jsx)(G,{variant:hn[r],label:n(`@theorem.host.status.${r}`),isPulsing:e.isRunning}),endContent:(0,U.jsx)(g,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:i.format(e.startedAt)}),onClick:()=>t(e)},e.id)})})]})}function Dn({tools:e,tool:t,check:n,text:r,view:i,shown:a,onText:o,onPick:s,onView:l,onRun:u,onStop:d}){let f=_(),p=`input`in n?n.input:void 0,m=i===`fields`&&p!==void 0;return(0,U.jsxs)(Ye,{title:f(`@theorem.host.request`),view:m?`fields`:`json`,hasFields:p!==void 0,onView:l,onRun:u,children:[(0,U.jsxs)(c,{gap:2,children:[(0,U.jsx)(O,{label:f(`@theorem.host.tool`),size:`sm`,options:e.map(e=>({value:e.name,label:e.name,icon:_n[e.kind],description:bn(f,e)})),value:t.name,hasSearch:e.length>8,renderOption:e=>(0,U.jsx)(`div`,{style:{width:vn,maxWidth:`100%`,minWidth:0},children:(0,U.jsx)(nt,{icon:e.icon,label:e.label,description:e.description&&(0,U.jsx)(g,{type:`supporting`,color:`secondary`,maxLines:yn,children:e.description})})}),onChange:s}),(0,U.jsx)(xn,{tool:t})]}),m?(0,U.jsx)(an,{schema:t.inputSchema,value:p,onChange:e=>{o(S(e))}},t.name):(0,U.jsx)(Ze,{label:f(`@theorem.host.request`),text:r,isInvalid:p===void 0,onChange:o}),(0,U.jsx)(Xe,{note:n.ok?f(`@theorem.host.shortcut`):n.note,isReady:n.ok,isRunning:a?.isRunning===!0,runLabel:f(`@theorem.host.run`),runningLabel:f(`@theorem.host.running`),stopLabel:f(`@theorem.host.stop`),onRun:u,onStop:()=>{a&&d(a.id)}})]})}function On(e,t,n,r){return!t||!n?.ok||r?.isRunning?null:e.run(t.name,n.input)}function kn(e,t){let n=_(),[r,i]=(0,q.useState)(e.tools[0]?.name),[a,o]=(0,q.useState)({}),[s,c]=(0,q.useState)(null),[l,u]=(0,q.useState)(`fields`),{tool:d,text:f,shown:p,earlier:m}=zt({tools:e.tools,picked:r,drafts:a,calls:t.calls,shownId:s}),h=d?gn(n,d,f):null;return{tool:d,text:f,shown:p,earlier:m,check:h,view:l,setView:u,setPicked:i,setText:e=>{d&&o(t=>({...t,[d.name]:e}))},run:()=>{let e=On(t,d,h,p);e!==null&&c(e)},pick:e=>{i(e.name),o(t=>({...t,[e.name]:S(e.input)})),c(e.id)}}}function An({shown:e,earlier:t,onAnswer:n,onPick:r}){return(0,U.jsxs)(U.Fragment,{children:[e?(0,U.jsx)(Tn,{call:e,onAnswer:n}):null,(0,U.jsx)(En,{calls:t,onPick:r})]})}function jn(e,t,n,r,i){if(!e)return i;let a=r.length===0;return!n&&a?null:(0,U.jsx)(Ke,{label:t,fill:n!=null&&Q(n)&&a,children:i})}function Mn({transport:e,iface:t,host:n,maxWidth:r=`960px`,trace:i,flush:a,columns:o=!1,className:s,style:c}){let l=_(),u=pe(t,e.traces,i),d=kn(t,n),{tool:f,check:p,shown:m,earlier:h}=d;return(0,U.jsxs)(Qe,{inspector:u,maxWidth:r,flush:a,columns:o,requestLabel:l(`@theorem.host.request`),className:s,style:c,children:[f&&p?(0,U.jsx)(Dn,{tools:t.tools,tool:f,check:p,text:d.text,view:d.view,shown:m,onText:d.setText,onPick:d.setPicked,onView:d.setView,onRun:d.run,onStop:n.cancel}):(0,U.jsx)(He,{title:l(`@theorem.host.no_tools`)}),jn(o,l(`@theorem.host.response`),m,h,(0,U.jsx)(An,{shown:m,earlier:h,onAnswer:n.answer,onPick:d.pick}))]})}function Nn(e){let t=_(),n=Ht(e.transport,e.pageTools);return n.describeFailure?(0,U.jsx)(st,{title:n.describeFailure.error}):n.iface?(0,U.jsx)(Mn,{...e,iface:n.iface,host:n}):(0,U.jsx)(j,{label:t(`@theorem.chat.loading`)})}function Pn({endpoint:e,http:t,transport:n,theme:r,mode:i,labels:a,detectCodeLanguage:o,...s}){let c=(0,q.useRef)(t);c.current=t;let l=(0,q.useMemo)(()=>n??te({...c.current,endpoint:e}),[n,e]);return(0,U.jsx)(re,{theme:r,mode:i,children:(0,U.jsx)(ue,{labels:a,children:(0,U.jsx)(ft,{detectCodeLanguage:o,children:(0,U.jsx)(Nn,{...s,transport:l})})})})}var Fn=e({HostView:()=>$,StudioHostConsole:()=>In});function In(e){let t=mt(e,h,ee);return(0,U.jsx)($,{...e,transport:t})}function $({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let o=(0,q.useMemo)(()=>Te(e),[e]);return(0,U.jsx)(Pn,{detectCodeLanguage:!0,labels:we,transport:t,pageTools:o,trace:n,flush:r,columns:i,className:a})}export{$ as HostView,In as StudioHostConsole,Ft as n,Fn as t};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,l as n,n as r,u as i}from"./themeProps-3IqahpCr.js";import{t as a}from"./VStack-CkVMcNiK.js";import{n as o}from"./StackItem-CQviqAfM.js";import{t as s}from"./CodeBlock-Kjgv83A6.js";import{U as c,l}from"./browser-transport-C4SkWngw.js";import{t as u}from"./mergeProps-ptS-gIMz.js";import{g as d,m as f}from"./fieldParts-Cs6Amprh.js";import{t as p}from"./Icon-ZfFwTt8n.js";import{r as m,t as h}from"./IconButton-CG5klqF1.js";import{t as g}from"./Text-BsiAsowd.js";import{c as _,n as v,t as y}from"./labels-provider-BSiD6Lrb.js";import{t as ee}from"./Card-Ghe4ozhC.js";import{t as te}from"./createReactComponent-CZwsv6DD.js";import{n as ne}from"./ScrollableArea-C8AVuqnt.js";import{t as b}from"./IconEye-BB5aY-wQ.js";import{Pr as x,Rr as S,Wt as C}from"./tool-schema-E9NPuDcN.js";import{Mn as w,O as re,a as T}from"./shaped-data-0GUF7Al3.js";import{O as ie}from"./turn-client-Dy9-U9_L.js";import{n as ae}from"./stub-DyzmGexy.js";import{n as oe,r as se}from"./CollapsibleGroup-PavPZ114.js";var E=te(`outline`,`flame`,`Flame`,[[`path`,{d:`M12 10.941c2.333 -3.308 .167 -7.823 -1 -8.941c0 3.395 -2.235 5.299 -3.667 6.706c-1.43 1.408 -2.333 3.294 -2.333 5.588c0 3.704 3.134 6.706 7 6.706c3.866 0 7 -3.002 7 -6.706c0 -1.712 -1.232 -4.403 -2.333 -5.588c-2.084 3.353 -3.257 3.353 -4.667 2.235`,key:`svg-0`}]]),D=[`cancelled`,`interrupted`,`length`,`filtered`,`provider_error`,`stream_incomplete`,`step_limit`],ce=new Set(D);function O(e){return ce.has(e)}function k(e,t,n){if(!e||!O(e.kind)||C(e)||t.some(e=>e.kind===`error`))return;let r=`stop.${e.kind}`;return w(r,{},n)}function A(e,t){let n=(n,r)=>{let i=new Set;return a=>{if(n(a),a.type!==`tool`||a.tool.phase!==`dispatch`)return;let{tool:o}=a;if(!e.pageResult||!o.operationId||r?.aborted)return;let s=JSON.stringify([o.operationId,o.grantId]);if(i.has(s))return;i.add(s);let c=t&&Object.hasOwn(t,o.name)?t[o.name]:void 0,l={callId:o.callId,operationId:o.operationId,grantId:o.grantId};Promise.resolve().then(async()=>{if(r?.aborted)return;let t=c?await Promise.resolve().then(()=>c(o.arguments,l)).catch(()=>({unanswered:!0})):{unanswered:!0};await e.pageResult?.({...l,page:t},r)}).catch(e=>{r?.aborted||n({type:`error`,errorKind:x(e),error:S(e)})})}},r=(e,t)=>{let r=n(e,t);return t=>t.type===`conversation`?e(t):r(t)};return`call`in e?{...e,describe:e.describe.bind(e),invoke:(t,r,i)=>e.invoke(t,n(r,i),i),call:(t,r,i)=>e.call(t,n(r,i),i)}:{...e,describe:e.describe.bind(e),invoke:(t,n,i)=>e.invoke(t,r(n,i),i),turn:(t,n,i)=>e.turn(t,r(n,i),i),steer:e.steer.bind(e),stop:e.stop.bind(e),conversation:e.conversation.bind(e),rewind:e.rewind.bind(e)}}function j(e){if(e.resolution.action===`deny`)return{decision:`deny`};let{resolution:t}=e;return{decision:`approve`,...t.action===`auth`&&t.secret!==void 0?{secret:t.secret}:{},...t.action===`page`?{page:t.page}:{},sessionPermissions:ie(e.sessionPermissions,e.toolName,e.gate.permission)}}var M=`theorem.oauth_complete`;function N(e,t){if(e.source!==t.popup||e.origin!==t.origin)return!1;let n=e.data;return re(n)&&n.type===M&&n.slot===t.slot}function P(e){return{openMessage:{type:`draft`,profile:e.profile,customTools:e.customTools}}}function F(e){let t={};for(let n of e.customTools){if(n.type!==`function`||n.answeredBy!==`page`)continue;let e=n.stubResponse??ae(n.outputSchema);t[n.name]=()=>({output:e})}return t}var I=e(i(),1),L=.02;function R(e){return Array.from({length:e},(e,t)=>t*.73+Math.sin(t*1.17)*.4)}function z(e,t,n,r,i=!1){return i||e===`disconnected`||e===`error`?`idle`:e===`connecting`||e===`reconnecting`?`connecting`:t?`tool`:e===`speaking`||r>L?`output`:n>L?`input`:e===`working`?`working`:`idle`}function B(e){let t=e.timeMs*.001;if(e.frozen)return e.phases.map((e,t)=>{let n=.22+.55*(.5+.5*Math.sin(e*1.7+t*.41));return Math.min(.82,Math.max(.1,n))});let n=e.inputLevel,r=e.outputLevel,i;switch(e.driver){case`output`:i=.18+r*.95;break;case`input`:i=.16+n*.96;break;case`tool`:i=.28+.18*Math.sin(t*5.2)+Math.max(r,n)*.45;break;case`working`:i=.16+.08*Math.sin(t*2.2)+Math.max(r,n)*.45;break;case`connecting`:i=.14+.1*Math.sin(t*3.1);break;default:i=.08+.04*Math.sin(t*1.4)}return e.phases.map((e,n)=>{let r=.72+.28*Math.sin(t*3.4+e),a=.68+.32*Math.sin(t*5.3+n*.62),o=i*r*a;return Math.min(1,Math.max(.06,o))})}var V=t(),H=.06,U={hero:{viewWidth:960,viewHeight:720,preserveAspect:`xMidYMax slice`,strokeWidth:2,barCount:45},pill:{viewWidth:480,viewHeight:120,preserveAspect:`none`,strokeWidth:3,barCount:21},strip:{viewWidth:1600,viewHeight:48,preserveAspect:`none`,strokeWidth:2,barCount:120},default:{viewWidth:480,viewHeight:320,preserveAspect:`xMidYMax meet`,strokeWidth:2,barCount:21}};function W(e){let t=U[e]??U.default,n=(t.viewWidth-t.strokeWidth*t.barCount)/(t.barCount+1);return{...t,gap:n}}function G(e,t,n){let{input:r,output:i}=e.levelsRef?.current??{input:e.inputLevel,output:e.outputLevel},a=e.frozen?{input:0,output:0}:{input:r,output:i};return B({phases:t,timeMs:n,driver:z(e.status,e.toolActive,r,i,e.frozen),inputLevel:a.input,outputLevel:a.output,frozen:e.frozen})}function le(e,t,n,r,i){(0,I.useEffect)(()=>{let a=e.current;if(!a)return;let o=a.children,s=Math.min(r,o.length),c=new Float64Array(s);c.fill(H);let l=i-H*(i-4);for(let e=0;e<s;e++)o[e].y2.baseVal.value=l;let u=0,d=e=>{let r=t.current,a=G(r,n,e),l=r.frozen?.2:.14;for(let e=0;e<s;e++){let t=c[e]+(a[e]-c[e])*l;c[e]=t,o[e].y2.baseVal.value=i-t*(i-4)}u=requestAnimationFrame(d)};return u=requestAnimationFrame(d),()=>{cancelAnimationFrame(u)}},[e,t,n,r,i])}function K({status:e=`disconnected`,inputLevel:t=0,outputLevel:n=0,levelsRef:r,toolActive:i=!1,frozen:a=!1,variant:o=`default`}){let{viewWidth:s,viewHeight:c,preserveAspect:l,strokeWidth:u,barCount:d,gap:f}=W(o),p=(0,I.useMemo)(()=>R(d),[d]),m=(0,I.useMemo)(()=>{let e=Array(d);for(let t=0;t<d;t++)e[t]=f+t*(u+f)+u/2;return e},[d,f,u]),h=(0,I.useRef)(null),g=(0,I.useRef)({status:e,inputLevel:t,outputLevel:n,levelsRef:r,toolActive:i,frozen:a});g.current.status=e,g.current.inputLevel=t,g.current.outputLevel=n,g.current.levelsRef=r,g.current.toolActive=i,g.current.frozen=a,le(h,g,p,d,c);let _=[`ink-wave`,o===`hero`?`ink-wave--hero`:``,o===`pill`?`ink-wave--pill`:``,o===`strip`?`ink-wave--strip`:``].filter(Boolean).join(` `),v=c-H*(c-4);return(0,V.jsx)(`svg`,{ref:h,className:_,"aria-hidden":`true`,viewBox:`0 0 ${String(s)} ${String(c)}`,preserveAspectRatio:l,width:`100%`,height:`100%`,children:m.map(e=>(0,V.jsx)(`line`,{className:`ink-wave__bar`,x1:e,x2:e,y1:c,y2:v,strokeWidth:u,stroke:`currentColor`,strokeLinecap:`square`},e))})}function ue(e){let t=e.toLowerCase();if(t.includes(`webm`))return`webm`;if(t.includes(`wav`))return`wav`;if(t.includes(`mpeg`)||t.includes(`mp3`))return`mp3`;if(t.includes(`mp4`)||t.includes(`m4a`)||t.includes(`aac`))return`m4a`;if(t.includes(`ogg`))return`ogg`}function de(){let e=(0,I.useRef)(null),[t,n]=(0,I.useState)(!1),r=(0,I.useRef)(!1),i=(0,I.useRef)({input:0,output:0}),a=(0,I.useRef)(0);function o(){cancelAnimationFrame(a.current),a.current=0,i.current.output=0}function s(){o();let e=t=>{r.current&&(i.current.output=.28+.22*(.5+.5*Math.sin(t*.008)),a.current=requestAnimationFrame(e))};a.current=requestAnimationFrame(e)}(0,I.useEffect)(()=>()=>{cancelAnimationFrame(a.current)},[]);function c(e){r.current=e,n(e),e?s():o()}async function l(){let t=e.current;if(t){if(!t.paused)t.pause();else try{await t.play()}catch{c(!1)}}}return{playing:t,levelsRef:i,toggle:l,audioProps:{ref:e,preload:`metadata`,onPlay:()=>c(!0),onPause:()=>c(!1),onEnded:()=>{c(!1),e.current&&(e.current.currentTime=0)}}}}var fe=64,pe=160;function me({src:e,mimeType:t=`audio/webm`,label:n,onRemove:r}){let i=v(),{playing:s,levelsRef:c,toggle:u,audioProps:f}=de(),m=n??_(i,ue(t)),g=i(`@theorem.voice_note.remove`,{name:m});return(0,V.jsxs)(o,{gap:1,vAlign:`center`,children:[(0,V.jsx)(l,{label:i(s?`@theorem.voice_note.pause`:`@theorem.voice_note.play`,{name:m}),onClick:()=>{u()},padding:0,width:pe,height:fe,children:(0,V.jsx)(a,{width:`100%`,height:`100%`,paddingInline:2,paddingBlockStart:2,style:{color:`var(--color-icon-primary)`},"aria-hidden":`true`,children:(0,V.jsx)(K,{frozen:!s,levelsRef:c,status:s?`speaking`:`ready`,variant:`pill`})})}),r?(0,V.jsx)(h,{label:g,tooltip:g,variant:`ghost`,size:`sm`,icon:(0,V.jsx)(p,{icon:d}),onClick:r}):null,(0,V.jsx)(`audio`,{...f,src:e,hidden:!0})]})}var q={container:{kVAEAm:`x1n2onr6`,kzqmXN:`xh8yej3`,kVQacm:`x7giv3`,kAzted:`x2lwn1j`,kmuXW:`x2lah0s`,$$css:!0},ellipse:{kaIpWk:`x16rqkct`,$$css:!0}},he={ratio:e=>[{kOBAk4:e==null?e:`x10y9f9r`,$$css:!0},{"--x-aspectRatio":e??void 0}]};function J({ratio:e,shape:t=`rectangle`,fit:i,children:a,xstyle:o,className:s,style:c,ref:l,...d}){return(0,V.jsx)(`div`,{ref:l,...u(r(`aspect-ratio`,{shape:t}),n(q.container,he.ratio(e),t===`ellipse`&&q.ellipse,o),s,c),...d,children:(0,V.jsx)(`div`,{"data-astryx-aspect-ratio-override":i,...{0:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d`},1:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k`}}[i===`center`|0],children:a})})}J.displayName=`AspectRatio`;function ge(e,t){if(!e)return t;let n=e.total+t.total;return!e.cost&&!t.cost?{total:n}:{total:n,cost:{usd:(e.cost?.usd??0)+(t.cost?.usd??0),...!e.cost||!t.cost||e.cost.partial||t.cost.partial?{partial:!0}:{}}}}var _e=new Set(D),ve=new Set([`user-text`,`user-attachment`,`user-voice`]);function ye(e){return ve.has(e.kind)}function Y(e){return e.kind===`turn-done`}function be(e,t){e?.kind===`user`?t.stop&&_e.has(t.stop.kind)&&(e.stop=t.stop):e&&(t.workedMs!==void 0&&(e.workedMs=t.workedMs,e.endedAt=t.endedAt),t.tokens&&(e.usage=ge(e.usage,t.tokens)),t.stop&&(e.stop=t.stop))}function xe(e,t){return!e||e.kind!==(t?`user`:`assistant`)?!1:!(e.kind===`user`&&e.stop)}function Se(e,t){let n=[];for(let r of e){if(r.kind===`turn-done`&&be(n.at(-1),r),Y(r))continue;let e=ye(r),i=n.at(-1);i&&xe(i,e)&&!t?.has(r.id)?i.blocks.push(r):n.push({kind:e?`user`:`assistant`,key:r.id,blocks:[r]})}return n}function Ce(e){return e.filter(e=>e.kind===`text`).map(e=>e.text).filter(Boolean).join(`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,l as n,n as r,u as i}from"./themeProps-3IqahpCr.js";import{t as a}from"./VStack-CkVMcNiK.js";import{n as o}from"./StackItem-CQviqAfM.js";import{t as s}from"./CodeBlock-Kjgv83A6.js";import{U as c,l}from"./browser-transport-DYgEItHi.js";import{t as u}from"./mergeProps-ptS-gIMz.js";import{g as d,m as f}from"./fieldParts-Cs6Amprh.js";import{t as p}from"./Icon-ZfFwTt8n.js";import{r as m,t as h}from"./IconButton-CG5klqF1.js";import{t as g}from"./Text-BsiAsowd.js";import{c as _,n as v,t as y}from"./labels-provider-BSiD6Lrb.js";import{t as ee}from"./Card-Ghe4ozhC.js";import{t as te}from"./createReactComponent-CZwsv6DD.js";import{n as ne}from"./ScrollableArea-C8AVuqnt.js";import{t as b}from"./IconEye-BB5aY-wQ.js";import{Pr as x,Rr as S,Wt as C}from"./tool-schema-E9NPuDcN.js";import{Mn as w,O as re,a as T}from"./shaped-data-0GUF7Al3.js";import{O as ie}from"./turn-client-Dy9-U9_L.js";import{n as ae}from"./stub-DyzmGexy.js";import{n as oe,r as se}from"./CollapsibleGroup-PavPZ114.js";var E=te(`outline`,`flame`,`Flame`,[[`path`,{d:`M12 10.941c2.333 -3.308 .167 -7.823 -1 -8.941c0 3.395 -2.235 5.299 -3.667 6.706c-1.43 1.408 -2.333 3.294 -2.333 5.588c0 3.704 3.134 6.706 7 6.706c3.866 0 7 -3.002 7 -6.706c0 -1.712 -1.232 -4.403 -2.333 -5.588c-2.084 3.353 -3.257 3.353 -4.667 2.235`,key:`svg-0`}]]),D=[`cancelled`,`interrupted`,`length`,`filtered`,`provider_error`,`stream_incomplete`,`step_limit`],ce=new Set(D);function O(e){return ce.has(e)}function k(e,t,n){if(!e||!O(e.kind)||C(e)||t.some(e=>e.kind===`error`))return;let r=`stop.${e.kind}`;return w(r,{},n)}function A(e,t){let n=(n,r)=>{let i=new Set;return a=>{if(n(a),a.type!==`tool`||a.tool.phase!==`dispatch`)return;let{tool:o}=a;if(!e.pageResult||!o.operationId||r?.aborted)return;let s=JSON.stringify([o.operationId,o.grantId]);if(i.has(s))return;i.add(s);let c=t&&Object.hasOwn(t,o.name)?t[o.name]:void 0,l={callId:o.callId,operationId:o.operationId,grantId:o.grantId};Promise.resolve().then(async()=>{if(r?.aborted)return;let t=c?await Promise.resolve().then(()=>c(o.arguments,l)).catch(()=>({unanswered:!0})):{unanswered:!0};await e.pageResult?.({...l,page:t},r)}).catch(e=>{r?.aborted||n({type:`error`,errorKind:x(e),error:S(e)})})}},r=(e,t)=>{let r=n(e,t);return t=>t.type===`conversation`?e(t):r(t)};return`call`in e?{...e,describe:e.describe.bind(e),invoke:(t,r,i)=>e.invoke(t,n(r,i),i),call:(t,r,i)=>e.call(t,n(r,i),i)}:{...e,describe:e.describe.bind(e),invoke:(t,n,i)=>e.invoke(t,r(n,i),i),turn:(t,n,i)=>e.turn(t,r(n,i),i),steer:e.steer.bind(e),stop:e.stop.bind(e),conversation:e.conversation.bind(e),rewind:e.rewind.bind(e)}}function j(e){if(e.resolution.action===`deny`)return{decision:`deny`};let{resolution:t}=e;return{decision:`approve`,...t.action===`auth`&&t.secret!==void 0?{secret:t.secret}:{},...t.action===`page`?{page:t.page}:{},sessionPermissions:ie(e.sessionPermissions,e.toolName,e.gate.permission)}}var M=`theorem.oauth_complete`;function N(e,t){if(e.source!==t.popup||e.origin!==t.origin)return!1;let n=e.data;return re(n)&&n.type===M&&n.slot===t.slot}function P(e){return{openMessage:{type:`draft`,profile:e.profile,customTools:e.customTools}}}function F(e){let t={};for(let n of e.customTools){if(n.type!==`function`||n.answeredBy!==`page`)continue;let e=n.stubResponse??ae(n.outputSchema);t[n.name]=()=>({output:e})}return t}var I=e(i(),1),L=.02;function R(e){return Array.from({length:e},(e,t)=>t*.73+Math.sin(t*1.17)*.4)}function z(e,t,n,r,i=!1){return i||e===`disconnected`||e===`error`?`idle`:e===`connecting`||e===`reconnecting`?`connecting`:t?`tool`:e===`speaking`||r>L?`output`:n>L?`input`:e===`working`?`working`:`idle`}function B(e){let t=e.timeMs*.001;if(e.frozen)return e.phases.map((e,t)=>{let n=.22+.55*(.5+.5*Math.sin(e*1.7+t*.41));return Math.min(.82,Math.max(.1,n))});let n=e.inputLevel,r=e.outputLevel,i;switch(e.driver){case`output`:i=.18+r*.95;break;case`input`:i=.16+n*.96;break;case`tool`:i=.28+.18*Math.sin(t*5.2)+Math.max(r,n)*.45;break;case`working`:i=.16+.08*Math.sin(t*2.2)+Math.max(r,n)*.45;break;case`connecting`:i=.14+.1*Math.sin(t*3.1);break;default:i=.08+.04*Math.sin(t*1.4)}return e.phases.map((e,n)=>{let r=.72+.28*Math.sin(t*3.4+e),a=.68+.32*Math.sin(t*5.3+n*.62),o=i*r*a;return Math.min(1,Math.max(.06,o))})}var V=t(),H=.06,U={hero:{viewWidth:960,viewHeight:720,preserveAspect:`xMidYMax slice`,strokeWidth:2,barCount:45},pill:{viewWidth:480,viewHeight:120,preserveAspect:`none`,strokeWidth:3,barCount:21},strip:{viewWidth:1600,viewHeight:48,preserveAspect:`none`,strokeWidth:2,barCount:120},default:{viewWidth:480,viewHeight:320,preserveAspect:`xMidYMax meet`,strokeWidth:2,barCount:21}};function W(e){let t=U[e]??U.default,n=(t.viewWidth-t.strokeWidth*t.barCount)/(t.barCount+1);return{...t,gap:n}}function G(e,t,n){let{input:r,output:i}=e.levelsRef?.current??{input:e.inputLevel,output:e.outputLevel},a=e.frozen?{input:0,output:0}:{input:r,output:i};return B({phases:t,timeMs:n,driver:z(e.status,e.toolActive,r,i,e.frozen),inputLevel:a.input,outputLevel:a.output,frozen:e.frozen})}function le(e,t,n,r,i){(0,I.useEffect)(()=>{let a=e.current;if(!a)return;let o=a.children,s=Math.min(r,o.length),c=new Float64Array(s);c.fill(H);let l=i-H*(i-4);for(let e=0;e<s;e++)o[e].y2.baseVal.value=l;let u=0,d=e=>{let r=t.current,a=G(r,n,e),l=r.frozen?.2:.14;for(let e=0;e<s;e++){let t=c[e]+(a[e]-c[e])*l;c[e]=t,o[e].y2.baseVal.value=i-t*(i-4)}u=requestAnimationFrame(d)};return u=requestAnimationFrame(d),()=>{cancelAnimationFrame(u)}},[e,t,n,r,i])}function K({status:e=`disconnected`,inputLevel:t=0,outputLevel:n=0,levelsRef:r,toolActive:i=!1,frozen:a=!1,variant:o=`default`}){let{viewWidth:s,viewHeight:c,preserveAspect:l,strokeWidth:u,barCount:d,gap:f}=W(o),p=(0,I.useMemo)(()=>R(d),[d]),m=(0,I.useMemo)(()=>{let e=Array(d);for(let t=0;t<d;t++)e[t]=f+t*(u+f)+u/2;return e},[d,f,u]),h=(0,I.useRef)(null),g=(0,I.useRef)({status:e,inputLevel:t,outputLevel:n,levelsRef:r,toolActive:i,frozen:a});g.current.status=e,g.current.inputLevel=t,g.current.outputLevel=n,g.current.levelsRef=r,g.current.toolActive=i,g.current.frozen=a,le(h,g,p,d,c);let _=[`ink-wave`,o===`hero`?`ink-wave--hero`:``,o===`pill`?`ink-wave--pill`:``,o===`strip`?`ink-wave--strip`:``].filter(Boolean).join(` `),v=c-H*(c-4);return(0,V.jsx)(`svg`,{ref:h,className:_,"aria-hidden":`true`,viewBox:`0 0 ${String(s)} ${String(c)}`,preserveAspectRatio:l,width:`100%`,height:`100%`,children:m.map(e=>(0,V.jsx)(`line`,{className:`ink-wave__bar`,x1:e,x2:e,y1:c,y2:v,strokeWidth:u,stroke:`currentColor`,strokeLinecap:`square`},e))})}function ue(e){let t=e.toLowerCase();if(t.includes(`webm`))return`webm`;if(t.includes(`wav`))return`wav`;if(t.includes(`mpeg`)||t.includes(`mp3`))return`mp3`;if(t.includes(`mp4`)||t.includes(`m4a`)||t.includes(`aac`))return`m4a`;if(t.includes(`ogg`))return`ogg`}function de(){let e=(0,I.useRef)(null),[t,n]=(0,I.useState)(!1),r=(0,I.useRef)(!1),i=(0,I.useRef)({input:0,output:0}),a=(0,I.useRef)(0);function o(){cancelAnimationFrame(a.current),a.current=0,i.current.output=0}function s(){o();let e=t=>{r.current&&(i.current.output=.28+.22*(.5+.5*Math.sin(t*.008)),a.current=requestAnimationFrame(e))};a.current=requestAnimationFrame(e)}(0,I.useEffect)(()=>()=>{cancelAnimationFrame(a.current)},[]);function c(e){r.current=e,n(e),e?s():o()}async function l(){let t=e.current;if(t){if(!t.paused)t.pause();else try{await t.play()}catch{c(!1)}}}return{playing:t,levelsRef:i,toggle:l,audioProps:{ref:e,preload:`metadata`,onPlay:()=>c(!0),onPause:()=>c(!1),onEnded:()=>{c(!1),e.current&&(e.current.currentTime=0)}}}}var fe=64,pe=160;function me({src:e,mimeType:t=`audio/webm`,label:n,onRemove:r}){let i=v(),{playing:s,levelsRef:c,toggle:u,audioProps:f}=de(),m=n??_(i,ue(t)),g=i(`@theorem.voice_note.remove`,{name:m});return(0,V.jsxs)(o,{gap:1,vAlign:`center`,children:[(0,V.jsx)(l,{label:i(s?`@theorem.voice_note.pause`:`@theorem.voice_note.play`,{name:m}),onClick:()=>{u()},padding:0,width:pe,height:fe,children:(0,V.jsx)(a,{width:`100%`,height:`100%`,paddingInline:2,paddingBlockStart:2,style:{color:`var(--color-icon-primary)`},"aria-hidden":`true`,children:(0,V.jsx)(K,{frozen:!s,levelsRef:c,status:s?`speaking`:`ready`,variant:`pill`})})}),r?(0,V.jsx)(h,{label:g,tooltip:g,variant:`ghost`,size:`sm`,icon:(0,V.jsx)(p,{icon:d}),onClick:r}):null,(0,V.jsx)(`audio`,{...f,src:e,hidden:!0})]})}var q={container:{kVAEAm:`x1n2onr6`,kzqmXN:`xh8yej3`,kVQacm:`x7giv3`,kAzted:`x2lwn1j`,kmuXW:`x2lah0s`,$$css:!0},ellipse:{kaIpWk:`x16rqkct`,$$css:!0}},he={ratio:e=>[{kOBAk4:e==null?e:`x10y9f9r`,$$css:!0},{"--x-aspectRatio":e??void 0}]};function J({ratio:e,shape:t=`rectangle`,fit:i,children:a,xstyle:o,className:s,style:c,ref:l,...d}){return(0,V.jsx)(`div`,{ref:l,...u(r(`aspect-ratio`,{shape:t}),n(q.container,he.ratio(e),t===`ellipse`&&q.ellipse,o),s,c),...d,children:(0,V.jsx)(`div`,{"data-astryx-aspect-ratio-override":i,...{0:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d`},1:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k`}}[i===`center`|0],children:a})})}J.displayName=`AspectRatio`;function ge(e,t){if(!e)return t;let n=e.total+t.total;return!e.cost&&!t.cost?{total:n}:{total:n,cost:{usd:(e.cost?.usd??0)+(t.cost?.usd??0),...!e.cost||!t.cost||e.cost.partial||t.cost.partial?{partial:!0}:{}}}}var _e=new Set(D),ve=new Set([`user-text`,`user-attachment`,`user-voice`]);function ye(e){return ve.has(e.kind)}function Y(e){return e.kind===`turn-done`}function be(e,t){e?.kind===`user`?t.stop&&_e.has(t.stop.kind)&&(e.stop=t.stop):e&&(t.workedMs!==void 0&&(e.workedMs=t.workedMs,e.endedAt=t.endedAt),t.tokens&&(e.usage=ge(e.usage,t.tokens)),t.stop&&(e.stop=t.stop))}function xe(e,t){return!e||e.kind!==(t?`user`:`assistant`)?!1:!(e.kind===`user`&&e.stop)}function Se(e,t){let n=[];for(let r of e){if(r.kind===`turn-done`&&be(n.at(-1),r),Y(r))continue;let e=ye(r),i=n.at(-1);i&&xe(i,e)&&!t?.has(r.id)?i.blocks.push(r):n.push({kind:e?`user`:`assistant`,key:r.id,blocks:[r]})}return n}function Ce(e){return e.filter(e=>e.kind===`text`).map(e=>e.text).filter(Boolean).join(`
|
|
2
2
|
|
|
3
3
|
`)}function we(e){let t=e.elapsedMs===void 0?{}:{elapsedMs:e.elapsedMs};return e.streaming?{phase:`working`,...t}:e.elapsedMs!==void 0&&e.elapsedMs>0?{phase:`worked`,elapsedMs:e.elapsedMs}:e.hasTrace?{phase:`worked`}:null}function Te(e){return e.kind===`tool`&&e.tool.state?.phase===`gate`}function Ee(e){for(let t=e.length-1;t>=0;--t)if(e[t]?.kind===`tool`)return t;return-1}function De(e,t,n,r){t.hasTools&&t.index<t.lastToolIndex?e.text.trim()&&n.push({kind:`narration`,id:e.id,text:e.text}):r.push(e)}function Oe(e,t,n,r){e.kind===`thought`?e.text.trim()&&n.push({kind:`reasoning`,id:e.id,text:e.text}):e.kind===`tool`?n.push({kind:`tool`,id:e.id,block:e}):e.kind===`text`?De(e,t,n,r):r.push(e)}function ke(e){let t=e.filter(e=>!Y(e)),n=t.find(Te),r=n?[n]:[],i=t.filter(e=>e!==n),a=Ee(i),o=a>=0,s=[],c=[];for(let[e,t]of i.entries())Oe(t,{hasTools:o,index:e,lastToolIndex:a},s,c);return{trace:s,gatedTools:r,body:c,hasTrace:s.length>0}}function Ae(e){let t=e.at(-1);return t?.kind===`user`?t:void 0}function X(e,t){let n=e[t-1];return n?.kind===`user`?Z(n):e[t]?.key??String(t)}function Z(e){return`${e.key}:reply`}function je(e,t,n){let r=e[t+1];return r?.kind===`assistant`&&r.endedAt!==void 0&&r.workedMs!==void 0?r.endedAt-r.workedMs:n(e[t]?.key??``)}function Me(e){let t=X(e.groups,e.index),n=e.streaming&&e.index===e.groups.length-1,r=e.groups[e.index];if(!n)return r?.kind===`assistant`&&r.workedMs!==void 0?{key:t,live:n,workedMs:r.workedMs,endedAt:r.endedAt}:{key:t,live:n};let i=e.groups[e.index-1],a=i?.kind===`user`?e.spans.get(i.key):void 0;return!i||!a?{key:t,live:n}:{key:t,live:n,startedAt:e.timeOf(i.key)+a.pausedMs}}function Ne(e){let t=e.state?.phase;return t===`cancel`?T(e.name):(t===`complete`||t===`error`?e.activityPast:e.activity)??T(e.name)}function Pe(e,t,n,r){let i=t.request??e(`@theorem.gate.approval.use_tool`,{tool:T(n).toLowerCase()});return r?e(`@theorem.gate.approval.title`,{agent:r,request:i}):e(`@theorem.gate.approval.title_no_agent`,{request:i})}function Fe(e){return typeof e==`string`?e:e==null?``:JSON.stringify(e,null,2)}function Q(e){return(0,V.jsx)(ee,{variant:`bubble`,elevation:`med`,maxWidth:400,children:(0,V.jsxs)(a,{gap:3,children:[(0,V.jsxs)(o,{justify:`between`,align:`start`,gap:3,children:[(0,V.jsx)(g,{type:`large`,weight:`semibold`,children:e.heading}),e.tag]}),e.children]})})}var Ie={"read-only":b,"read-write":c,destructive:E};function Le({access:e}){let t=v();return(0,V.jsxs)(o,{gap:1,align:`center`,children:[(0,V.jsx)(p,{icon:Ie[e],size:`sm`,color:e===`destructive`?`error`:`secondary`}),(0,V.jsx)(g,{type:`supporting`,textWrap:`nowrap`,children:t(`@theorem.tool.access.${e}`)})]})}function $(e){return(0,V.jsx)(y,{children:(0,V.jsx)(Re,{...e})})}function Re({gate:e,toolName:t,agent:n,input:r,decided:i=null,onDecision:a}){let c=v(),l=Fe(e.preparedArguments??r);return(0,V.jsxs)(Q,{heading:Pe(c,e,t,n),tag:e.access?(0,V.jsx)(Le,{access:e.access}):null,children:[e.summary?(0,V.jsx)(g,{color:`secondary`,children:e.summary}):null,l?(0,V.jsx)(oe,{defaultIsOpen:!1,trigger:(0,V.jsx)(g,{type:`supporting`,children:c(`@theorem.gate.approval.input`)}),children:(0,V.jsx)(s,{code:l,language:`json`,size:`sm`})}):null,(0,V.jsxs)(o,{gap:2,justify:`end`,children:[(0,V.jsx)(m,{label:c(`@theorem.gate.approval.deny`),variant:`ghost`,isLoading:i===`deny`,isDisabled:i===`allow`,onClick:()=>a?.(`deny`)}),(0,V.jsx)(m,{label:c(`@theorem.gate.approval.approve`),variant:`primary`,isLoading:i===`allow`,isDisabled:i===`deny`,onClick:()=>a?.(`allow`)})]})]})}function ze({challenge:e}){let t=v();return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(g,{color:`secondary`,children:e.message}),e.resource?(0,V.jsx)(g,{type:`supporting`,color:`secondary`,children:t(`@theorem.gate.auth.resource`,{resource:e.resource})}):null,e.requiredScopes?.length?(0,V.jsx)(o,{gap:1,wrap:`wrap`,children:e.requiredScopes.map(e=>(0,V.jsx)(f,{label:e,size:`sm`},e))}):null]})}function Be(e){return(0,V.jsx)(y,{children:(0,V.jsx)(He,{...e})})}function Ve(e,t){let[n,r]=(0,I.useState)(null);return(0,I.useEffect)(()=>{if(!n)return;function i(i){n&&N(i,{popup:n,slot:e,origin:globalThis.location.origin})&&(r(null),t())}return globalThis.addEventListener(`message`,i),()=>globalThis.removeEventListener(`message`,i)},[n,e,t]),e=>r(globalThis.open(e,`_blank`,`width=600,height=700`))}function He({gate:e,toolName:t,onAuthenticated:n,submitted:r=!1}){let i=v(),a=e.authChallenge,{authType:o,slot:s}=a,[c,l]=(0,I.useState)(``),u=Ve(s,(0,I.useCallback)(()=>n?.(),[n]));function d(){let e=c.trim();e&&(l(``),n?.(e))}return(0,V.jsxs)(Q,{heading:i(`@theorem.gate.auth.title`,{tool:T(t).toLowerCase()}),tag:(0,V.jsx)(g,{type:`supporting`,textWrap:`nowrap`,children:i(`@theorem.gate.tag.${o}`)}),children:[(0,V.jsx)(ze,{challenge:a}),(0,V.jsx)(Ue,{authType:o,authUrl:a.authorizationUrl,slot:s,secret:c,submitted:r,onSecretChange:l,onSubmit:d,onOpenSignIn:u})]})}function Ue(e){let t=v();if(e.submitted)return(0,V.jsx)(se,{variant:`success`,label:t(`@theorem.gate.auth.provided`,{slot:e.slot})});if(e.authType===`oauth2`)return e.authUrl?(0,V.jsx)(o,{justify:`end`,children:(0,V.jsx)(m,{label:t(`@theorem.gate.auth.authorize`),variant:`primary`,onClick:()=>{e.authUrl&&e.onOpenSignIn(e.authUrl)}})}):(0,V.jsx)(g,{color:`secondary`,children:t(`@theorem.gate.auth.no_oauth`)});let n=t(e.authType===`api_key`?`@theorem.gate.auth.api_key`:`@theorem.gate.auth.bearer`),r=t(`@theorem.gate.auth.secret_note`).trim();return(0,V.jsxs)(o,{gap:2,align:`end`,children:[(0,V.jsx)(ne,{type:`password`,label:n,...r?{description:r}:{},value:e.secret,placeholder:t(`@theorem.gate.auth.secret_placeholder`,{slot:e.slot}),autoComplete:`off`,onChange:e.onSecretChange,onEnter:e.onSubmit,width:`100%`}),(0,V.jsx)(m,{label:t(`@theorem.gate.auth.submit`),variant:`primary`,isDisabled:!e.secret.trim(),onClick:e.onSubmit})]})}var We={en:{"@theorem.gate.auth.secret_note":`Used for this call only. theorem doesn't store it.`,"@astryx.chat.status.sending":`sending`,"@astryx.chat.status.sent":`sent`,"@astryx.chat.status.delivered":`delivered`,"@astryx.chat.status.read":`read`}};export{E as S,P as _,Me as a,A as b,Ae as c,X as d,Ne as f,K as g,me as h,Ce as i,Z as l,J as m,$ as n,ke as o,we as p,Be as r,Se as s,We as t,je as u,F as v,k as x,j as y};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,l as n,n as r,u as i}from"./themeProps-3IqahpCr.js";import{h as a}from"./tokens.stylex-DkHf0P9C.js";import{i as o,l as s,u as c}from"./SegmentedControlItem-BLuJOusN.js";import{t as l}from"./VStack-CkVMcNiK.js";import{n as u,t as d}from"./StackItem-CQviqAfM.js";import{A as f,N as p,W as m,s as h,t as g,v as _}from"./browser-transport-C4SkWngw.js";import{t as v}from"./mergeProps-ptS-gIMz.js";import{p as y}from"./fieldParts-Cs6Amprh.js";import{t as b}from"./Icon-ZfFwTt8n.js";import{p as x,r as S,t as C,u as ee}from"./IconButton-CG5klqF1.js";import{d as w,f as T,h as E,o as D,u as O}from"./use-trace-records-BkAYJz0M.js";import{t as k}from"./Text-BsiAsowd.js";import{a as A,n as j,t as M}from"./labels-provider-BSiD6Lrb.js";import{t as N}from"./Dialog-BDUExlk_.js";import{t as P}from"./createReactComponent-CZwsv6DD.js";import{a as F,i as I,t as L}from"./Banner-DBzTZFXK.js";import{t as R}from"./Center-nHS1JSux.js";import{_ as z,g as B,m as te,n as ne,r as re,t as ie,v as ae,y as oe}from"./studio-labels-I9r-0TcO.js";import{Mr as V}from"./tool-schema-E9NPuDcN.js";import{c as H}from"./host-patterns-C9RMP16Q.js";import{Mn as se,fn as ce,pn as le}from"./shaped-data-0GUF7Al3.js";import{S as ue,g as de,r as fe,t as pe}from"./reader-BB7aL5yX.js";import{i as U}from"./live-ingress-lDUGPwth.js";import{i as me,v as he}from"./turn-client-Dy9-U9_L.js";import{r as ge,t as _e}from"./live-messages-dPuowG_o.js";import{t as ve}from"./EmptyState-C8W4JKBZ.js";import"./use-second-ticker-VX91zrxj.js";import{t as ye}from"./Section-DJ97F7QE.js";import{C as be,F as xe,Q as Se,at as Ce,i as we,m as Te,ot as Ee,st as De,xt as Oe}from"./index--GBhZcW8.js";var ke=P(`outline`,`camera-rotate`,`CameraRotate`,[[`path`,{d:`M5 7h1a2 2 0 0 0 2 -2a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1a2 2 0 0 0 2 2h1a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2`,key:`svg-0`}],[`path`,{d:`M11.245 15.904a3 3 0 0 0 3.755 -2.904m-2.25 -2.905a3 3 0 0 0 -3.75 2.905`,key:`svg-1`}],[`path`,{d:`M14 13h2v2`,key:`svg-2`}],[`path`,{d:`M10 13h-2v-2`,key:`svg-3`}]]),Ae=P(`outline`,`microphone-off`,`MicrophoneOff`,[[`path`,{d:`M3 3l18 18`,key:`svg-0`}],[`path`,{d:`M9 5a3 3 0 0 1 6 0v5a3 3 0 0 1 -.13 .874m-2 2a3 3 0 0 1 -3.87 -2.872v-1`,key:`svg-1`}],[`path`,{d:`M5 10a7 7 0 0 0 10.846 5.85m2 -2a6.967 6.967 0 0 0 1.152 -3.85`,key:`svg-2`}],[`path`,{d:`M8 21l8 0`,key:`svg-3`}],[`path`,{d:`M12 17l0 4`,key:`svg-4`}]]),je=P(`outline`,`phone-off`,`PhoneOff`,[[`path`,{d:`M3 21l18 -18`,key:`svg-0`}],[`path`,{d:`M5.831 14.161a15.946 15.946 0 0 1 -2.831 -8.161a2 2 0 0 1 2 -2h4l2 5l-2.5 1.5c.108 .22 .223 .435 .345 .645m1.751 2.277c.843 .84 1.822 1.544 2.904 2.078l1.5 -2.5l5 2v4a2 2 0 0 1 -2 2a15.963 15.963 0 0 1 -10.344 -4.657`,key:`svg-1`}]]),Me=P(`outline`,`phone`,`Phone`,[[`path`,{d:`M5 4h4l2 5l-2.5 1.5a11 11 0 0 0 5 5l1.5 -2.5l5 2v4a2 2 0 0 1 -2 2a16 16 0 0 1 -15 -15a2 2 0 0 1 2 -2`,key:`svg-0`}]]),Ne=P(`outline`,`subtitles`,`Subtitles`,[[`path`,{d:`M18 5a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3l12 0`,key:`svg-0`}],[`path`,{d:`M7 15h5`,key:`svg-1`}],[`path`,{d:`M15 15h2`,key:`svg-2`}],[`path`,{d:`M17 12h-3`,key:`svg-3`}],[`path`,{d:`M11 12h-1`,key:`svg-4`}]]),Pe=P(`outline`,`video-off`,`VideoOff`,[[`path`,{d:`M3 3l18 18`,key:`svg-0`}],[`path`,{d:`M15 11v-1l4.553 -2.276a1 1 0 0 1 1.447 .894v6.764a1 1 0 0 1 -.675 .946`,key:`svg-1`}],[`path`,{d:`M10 6h3a2 2 0 0 1 2 2v3m0 4v1a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-8a2 2 0 0 1 2 -2h1`,key:`svg-2`}]]),Fe=P(`outline`,`video`,`Video`,[[`path`,{d:`M15 10l4.553 -2.276a1 1 0 0 1 1.447 .894v6.764a1 1 0 0 1 -1.447 .894l-4.553 -2.276v-4`,key:`svg-0`}],[`path`,{d:`M3 8a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2l0 -8`,key:`svg-1`}]]);function Ie(e){return e.status===`reconnecting`?`reconnecting`:e.toolName?`calling_tool`:e.connectPhase===`socket`?`connecting`:e.connectPhase===`microphone`?`requesting_mic`:e.status===`speaking`?`speaking`:e.status===`listening`||e.status===`ready`?e.voiceEnabled===!1?`connected`:e.isMuted?`muted`:`listening`:e.status===`connecting`?`connecting`:e.status===`error`?`error`:`ended`}function Le(e){return!(e.isMuted||!e.socketOpen||e.modelPlaying&&e.rms<e.bargeInRmsWhileSpeaking)}function Re(e){let{evidence:t,text:n}=e;return!n||t.kind!==`input_transcription`&&t.kind!==`output_transcription`?null:{text:n,isUser:t.kind===`input_transcription`,interim:t.interim===!0}}function ze(e,t){if(e.phase===void 0){t.toolCalls.push({id:e.callId,name:e.name,arguments:e.arguments,...e.operationId?{operationId:e.operationId}:{}});return}if(e.phase===`cancel`){t.cancelledToolIds.add(e.callId);return}if(e.phase!==`error`)return;let n=t.toolCalls.findIndex(t=>t.id===e.callId);n!==-1&&t.toolCalls.splice(n,1)}function Be(e){if(!(e instanceof Error))return!1;let t=`name`in e&&typeof e.name==`string`?e.name:``;return t===`NotAllowedError`||t===`PermissionDeniedError`||/permission|not allowed|denied/i.test(e.message)}var Ve=`mic-capture-processor`;function He(){return new URL(`data:text/javascript;base64,LyoqCiAqIEF1ZGlvV29ya2xldCBwcm9jZXNzb3IgdGhhdCBmb3J3YXJkcyBtb25vIG1pYyBmcmFtZXMgdG8gdGhlIG1haW4gdGhyZWFkLgogKiBQbGFpbiBKUzogaXQgcnVucyBpbiB0aGUgQXVkaW9Xb3JrbGV0R2xvYmFsU2NvcGUgYXMgaXRzIG93biBtb2R1bGUsIGxvYWRlZAogKiBieSBVUkwgKHNlZSBgLi4vbWljLWNhcHR1cmUudHNgKSwgc28gaXQgaW1wb3J0cyBub3RoaW5nIGFuZCBzaGlwcyBhcyBpcy4KICovCnJlZ2lzdGVyUHJvY2Vzc29yKAogICdtaWMtY2FwdHVyZS1wcm9jZXNzb3InLAogIGNsYXNzIE1pY0NhcHR1cmVQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogICAgcHJvY2VzcyhpbnB1dHMpIHsKICAgICAgY29uc3QgY2hhbm5lbCA9IGlucHV0c1swXVswXTsKICAgICAgY29uc3QgY29weSA9IG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZShjb3B5LCBbY29weS5idWZmZXJdKTsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgfSwKKTsK`,``+import.meta.url)}function Ue(e,t,n=16e3){if(t===n)return We(e);let r=t/n,i=Math.round(e.length/r),a=new Int16Array(i),o=0,s=0;for(;o<a.length;){let t=Math.round((o+1)*r),n=0,i=0;for(let r=s;r<t&&r<e.length;r++)n+=e[r]??0,i++;a[o]=W(i>0?n/i:0),o++,s=t}return a}function We(e){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=W(e[n]??0);return t}function W(e){let t=Math.max(-1,Math.min(1,e));return t<0?t*32768:t*32767}function Ge(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=new Float32Array(e.byteLength/2);for(let e=0;e<n.length;e++){let r=t.getInt16(e*2,!0);n[e]=r/(r<0?32768:32767)}return n}function G(e){return JSON.stringify(e)}function Ke(){return{toolCalls:[],mediaChunks:[],cancelledToolIds:new Set}}var qe=.05,Je=[500,1e3,2e3,4e3,8e3];function K(e){return e instanceof Error?e:new H(`internal`,V(e),{cause:e})}function q(e){if(e&&typeof e.disconnect==`function`)try{e.disconnect()}catch{}}function Ye(e){if(e&&typeof e.getTracks==`function`)for(let t of e.getTracks())t.stop()}function Xe(e){let t=Ce(e.inputFloat32),n=e.hasPlaybackNodes||e.status===`speaking`;return Le({isMuted:e.isMuted,socketOpen:e.wsOpen,modelPlaying:n,rms:t,bargeInRmsWhileSpeaking:qe})}function Ze(e,t){return e===`listening`&&t?`working`:e===`working`&&!t?`listening`:null}var Qe=class{ws=null;audioContext=null;micStream=null;micSource=null;micWorklet=null;micWorkletModuleLoaded=!1;playbackNodes=[];playbackBus=null;playbackAnalyser=null;playbackMeterFrame=0;playbackMeterBuffer=null;nextPlaybackTime=0;status=`disconnected`;serverWorking=!1;micActivating=!1;connectTimeout=null;isMuted=!1;options;inboundChain=Promise.resolve();audioChain=Promise.resolve();toolChain=Promise.resolve();audioEpoch=0;pendingExecuteResults=new Map;context;sentContext;history=[];providerState;sessionOver=!1;droppedAt;lostAt;reconnectTries=0;reconnectTimer=null;constructor(e){this.options=e,this.context=e.context}setStatus(e){this.status=e,(e===`listening`||e===`disconnected`||e===`error`)&&this.clearConnectTimeout(),this.options.onStatusChange?.(e)}get opening(){return this.status===`connecting`||this.status===`reconnecting`}setConnectPhase(e){this.options.onConnectPhase?.(e)}clearConnectTimeout(){this.connectTimeout&&=(clearTimeout(this.connectTimeout),null)}detachWebSocket(){for(let[e,t]of this.pendingExecuteResults)t.reject(new H(`network`,`live session closed before call ${e} settled`));if(this.pendingExecuteResults.clear(),this.ws){this.ws.onopen=null,this.ws.onmessage=null,this.ws.onclose=null,this.ws.onerror=null;try{this.ws.close()}catch{}this.ws=null}}clearReconnect(){this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.reconnectTries=0,this.droppedAt=void 0}teardownConnection(){this.clearConnectTimeout(),this.micActivating=!1,this.setConnectPhase(null),this.detachWebSocket(),this.cleanupAudio()}failSession(e){this.status!==`error`&&this.status!==`disconnected`&&(this.clearReconnect(),this.teardownConnection(),this.options.onError?.(e),this.setStatus(`error`))}createSocket(e){return this.options.createSocket?.()??new WebSocket(e)}connect(){let e=this.lostAt;return this.clearReconnect(),this.lostAt=void 0,e===void 0?(this.providerState=void 0,this.history=[]):this.droppedAt=e,this.open(`connecting`)}startOver(){return this.status!==`connecting`||!this.providerState?!1:(this.providerState=void 0,this.droppedAt=void 0,this.open(`connecting`),!0)}openMessage(){let{slots:e,openMessage:t}=this.options;return{type:`open`,...this.history.length?{history:structuredClone(this.history)}:{},...e?{slots:e}:{},...this.context===void 0?{}:{context:this.context},...this.providerState?{resume:{providerState:this.providerState,awayMs:this.droppedAt===void 0?0:Date.now()-this.droppedAt}}:{},...t?{host:t}:{}}}handleDrop(){!this.providerState||this.sessionOver?(this.teardownConnection(),this.setStatus(`disconnected`)):(this.droppedAt??=Date.now(),this.teardownConnection(),this.setStatus(`reconnecting`),this.scheduleReconnect())}scheduleReconnect(){let e=Je[this.reconnectTries];if(e===void 0){let e=this.droppedAt;this.failSession(new H(`network`,`live call dropped and could not reconnect`)),this.lostAt=e}else this.reconnectTries+=1,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.open(`reconnecting`)},e)}failOpen(e){this.status===`reconnecting`?(this.teardownConnection(),this.scheduleReconnect()):this.startOver()||this.failSession(e)}async open(e){this.teardownConnection(),this.sessionOver=!1,this.setStatus(e),e===`connecting`&&this.setConnectPhase(`socket`);try{let e=globalThis.AudioContext;this.audioContext=new e,this.audioContext.state===`suspended`&&await this.audioContext.resume();let t=globalThis.location.protocol===`https:`?`wss:`:`ws:`,n=this.options.profile?`?profile=${encodeURIComponent(this.options.profile)}`:``,r=`${t}//${globalThis.location.host}/api/live/relay${n}`,i=this.options.relayUrl||r;this.ws=this.createSocket(i),this.ws.binaryType=`arraybuffer`,this.ws.onopen=()=>{let e=this.openMessage();this.sentContext=JSON.stringify(e.context),this.ws?.send(JSON.stringify(e))},this.connectTimeout=setTimeout(()=>{this.opening&&this.failOpen(new H(`timeout`,`live connect timed out`))},2e4),this.ws.onmessage=e=>{this.enqueueServerMessage(e.data)},this.ws.onclose=()=>{this.opening?this.failOpen(new H(`network`,`live socket closed before ready`)):this.handleDrop()},this.ws.onerror=()=>{!this.opening&&this.providerState&&!this.sessionOver?this.handleDrop():this.failOpen(new H(`network`,`live socket error`))}}catch(e){this.failOpen(new H(`internal`,V(e),{cause:e}))}}async ensureAudioContext(){if(!this.audioContext||this.audioContext.state===`closed`){let e=globalThis.AudioContext;this.audioContext=new e,this.audioContext.state===`suspended`&&await this.audioContext.resume()}}async activateMicrophone(){if(!this.micActivating&&this.opening){this.micActivating=!0,this.status===`connecting`&&this.setConnectPhase(`microphone`);try{await this.ensureAudioContext(),this.micStream=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}}),await this.setupMicrophonePipeline(),this.becomeReady()}catch(e){let t=Be(e);this.failSession(new H(t?`auth`:`internal`,V(e),{cause:e,copy:{key:t?`voice.permission`:`voice.unavailable`}}))}finally{this.micActivating=!1}}}sendMicFrame(e,t){let n=Ue(e,t,16e3),r=le(new Uint8Array(n.buffer)),i=this.ws;i?.readyState===WebSocket.OPEN&&i.send(G({type:`audio`,data:r}))}reportMicVolume(e){this.isMuted||this.options.onVolumeLevel?.(Ee(e),!0)}forwardMicBuffer(e){if(this.reportMicVolume(e),Xe({isMuted:this.isMuted,wsOpen:this.ws?.readyState===WebSocket.OPEN,hasPlaybackNodes:this.playbackNodes.length>0,status:this.status,inputFloat32:e})){let t=this.audioContext?this.audioContext.sampleRate:48e3;this.sendMicFrame(e,t)}}async setupMicrophonePipeline(){if(!this.micStream||!this.audioContext)return;this.micSource=this.audioContext.createMediaStreamSource(this.micStream);let e=this.audioContext.createGain();e.gain.value=0,this.micWorkletModuleLoaded||=(await this.audioContext.audioWorklet.addModule(He()),!0),this.micWorklet=new AudioWorkletNode(this.audioContext,Ve),this.micWorklet.port.onmessage=e=>{let t=new Float32Array(e.data);this.forwardMicBuffer(t)},this.micSource.connect(this.micWorklet),this.micWorklet.connect(e),e.connect(this.audioContext.destination)}ensurePlaybackBus(){this.audioContext&&!this.playbackBus&&(this.playbackBus=this.audioContext.createGain(),this.playbackAnalyser=this.audioContext.createAnalyser(),this.playbackAnalyser.fftSize=512,this.playbackAnalyser.smoothingTimeConstant=.35,this.playbackBus.connect(this.playbackAnalyser),this.playbackAnalyser.connect(this.audioContext.destination),this.playbackMeterBuffer=new Uint8Array(this.playbackAnalyser.fftSize))}stopPlaybackMeter(){this.playbackMeterFrame&&=(cancelAnimationFrame(this.playbackMeterFrame),0),this.options.onVolumeLevel?.(0,!1)}startPlaybackMeter(){if(this.playbackMeterFrame)return;let e=()=>{this.playbackNodes.length===0||!this.playbackAnalyser||!this.playbackMeterBuffer?this.stopPlaybackMeter():(this.playbackAnalyser.getByteTimeDomainData(this.playbackMeterBuffer),this.options.onVolumeLevel?.(De(this.playbackMeterBuffer),!1),this.playbackMeterFrame=requestAnimationFrame(e))};this.playbackMeterFrame=requestAnimationFrame(e)}async processServerEnvelope(e){if(await this.tryHandleControlEnvelope(e)||e.type!==`events`)return;let t=this.collectInboundTurn(e.events),n=t.toolCalls.filter(e=>!t.cancelledToolIds.has(e.id));for(let e of n)this.toolChain=this.toolChain.then(()=>this.options.onToolCall(e.name,e.arguments,{callId:e.id,operationId:me(e)})).catch(e=>{this.options.onError?.(K(e))});this.scheduleMediaChunks(t.mediaChunks)}enqueueServerMessage(e){this.inboundChain=this.inboundChain.then(async()=>{if(typeof e!=`string`)return;let t=ge(e);t.type===`unsupported`||t.type===`malformed`?this.options.onTurnEvent?.(t):await this.processServerEnvelope(t)}).catch(e=>{this.options.onError?.(K(e))})}async handleReadyEnvelope(e){this.options.onSessionReady?.({sessionId:e.sessionId,profile:e.profile}),this.options.voiceIngress===!1?this.becomeReady():await this.activateMicrophone()}becomeReady(){this.clearReconnect(),this.setConnectPhase(null),this.setStatus(`listening`),this.flushContext()}handleExecuteToolResultEnvelope(e){let t=this.pendingExecuteResults.get(e.operationId);t&&t.callId===e.callId&&(this.pendingExecuteResults.delete(e.operationId),e.status===`refused`?t.reject(ue(e.body,`request`)):e.status===`dispatched`?t.resolve({status:`dispatched`,grantId:e.grantId,arguments:e.arguments}):e.status===`gated`?t.resolve({status:`gated`,gate:e.gate}):t.resolve({status:`settled`}))}async tryHandleControlEnvelope(e){return e.type===`ready`?(await this.handleReadyEnvelope(e),!0):e.type===`executeToolResult`?(this.handleExecuteToolResultEnvelope(e),!0):e.type===`trace`?(this.options.onTrace?.(e.record),!0):e.type===`error`&&(this.startOver()||(this.sessionOver=!0,this.options.onError?.(ue(e,`unavailable`)),this.setStatus(`error`)),!0)}collectInboundTurn(e){let t=Ke();for(let n of e)this.processTurnEvent(n,t);return t}processTurnEvent(e,t){switch(e.type===`provider_checkpoint`&&e.history&&(this.history=structuredClone(e.history)),(e.type===`provider_checkpoint`||e.type===`done`)&&e.providerState&&(this.providerState=e.providerState),e.type===`provider_warning`&&(this.providerState=void 0),this.options.onTurnEvent?.(e),e.type){case`evidence`:this.handleEvidenceTurnEvent(e);break;case`session`:this.handleSessionTurnEvent(e);break;case`media`:this.collectMediaTurnEvent(e,t);break;case`tool`:ze(e.tool,t);break;case`done`:this.handleDoneTurnEvent(e)}}handleEvidenceTurnEvent(e){let t=Re(e);t&&this.options.onTranscript?.(t.text,t.isUser,{interim:t.interim})}handleSessionTurnEvent(e){if(this.notifySessionLifecycle(e.session))return;this.serverWorking=e.session.kind===`working`;let t=Ze(this.status,this.serverWorking);t&&this.setStatus(t)}notifySessionLifecycle(e){return e.kind===`closing_soon`?(this.options.onSessionClosing?.(e.timeLeftMs),!0):e.kind===`ended`?this.providerState?(this.handleDrop(),!0):(this.sessionOver=!0,this.options.onSessionEnded?.(e),!0):!1}restingStatus(){return this.serverWorking?`working`:`listening`}collectMediaTurnEvent(e,t){e.media.data&&(this.setStatus(`speaking`),t.mediaChunks.push({data:e.media.data,mimeType:e.media.mimeType}))}handleDoneTurnEvent(e){e.interrupted&&this.cancelPlayback(),e.stop.kind!==`generation_complete`&&(this.serverWorking=!1,this.setStatus(`listening`))}scheduleMediaChunks(e){if(e.length===0)return;let t=this.audioEpoch;for(let n of e)this.audioChain=this.audioChain.then(async()=>{t===this.audioEpoch&&await this.enqueueAudioChunk(n.data,n.mimeType)}).catch(e=>{this.options.onError?.(K(e))})}executeToolOnRelay(e){let t=this.ws;if(!t||t.readyState!==WebSocket.OPEN)throw new H(`request`,`live session is not connected`);let n=_e.safeParse({...e,type:`executeTool`});if(!n.success||n.data.type!==`executeTool`)throw new H(`request`,se(`error.request`));let r=n.data;if(this.pendingExecuteResults.has(r.operationId))throw new H(`request`,se(`session.gate_expired`));return new Promise((e,n)=>{this.pendingExecuteResults.set(r.operationId,{callId:r.callId,resolve:e,reject:n});try{t.send(G(r))}catch(e){this.pendingExecuteResults.delete(r.operationId),n(K(e))}})}async enqueueAudioChunk(e,t){if(this.audioContext)try{if(this.ensurePlaybackBus(),!this.playbackBus)return;let n=ce(e),r;if(t?.includes(`wav`)){let e=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength);r=await this.audioContext.decodeAudioData(e)}else{let e=Ge(n);r=this.audioContext.createBuffer(1,e.length,24e3),r.getChannelData(0).set(e)}let i=this.audioContext.createBufferSource();i.buffer=r,i.connect(this.playbackBus);let a=this.audioContext.currentTime,o=Math.max(a,this.nextPlaybackTime);i.start(o),this.nextPlaybackTime=o+r.duration,this.playbackNodes.push(i),this.startPlaybackMeter(),i.onended=()=>{let e=this.playbackNodes.indexOf(i);e!==-1&&this.playbackNodes.splice(e,1),this.playbackNodes.length===0&&(this.stopPlaybackMeter(),this.status===`speaking`&&this.setStatus(this.restingStatus()))}}catch(e){this.options.onError?.(K(e))}}cancelPlayback(){this.audioEpoch+=1,this.audioChain=Promise.resolve();for(let e of this.playbackNodes)try{e.stop(),e.disconnect()}catch{}this.playbackNodes=[],this.stopPlaybackMeter(),this.audioContext&&(this.nextPlaybackTime=this.audioContext.currentTime)}toggleMute(){return this.isMuted=!this.isMuted,this.isMuted}sendText(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(G({type:`text`,text:e}))}setSlots(e){JSON.stringify(e)!==JSON.stringify(this.options.slots)&&(this.options={...this.options,slots:e},this.providerState&&!this.opening&&this.ws?.readyState===WebSocket.OPEN&&this.handleDrop())}setContext(e){this.context=e,this.flushContext()}flushContext(){if(this.opening||this.ws?.readyState!==WebSocket.OPEN)return;let e=JSON.stringify(this.context);e!==this.sentContext&&(this.sentContext=e,this.ws.send(G({type:`context`,context:this.context})))}sendVideo(e,t=`image/jpeg`){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(G({type:`video`,data:e,mimeType:t}))}disconnect(){this.clearReconnect(),this.lostAt=void 0,this.providerState=void 0,this.teardownConnection(),this.setStatus(`disconnected`)}cleanupAudio(){if(this.cancelPlayback(),this.stopPlaybackMeter(),q(this.playbackBus),this.playbackBus=null,this.playbackAnalyser=null,this.playbackMeterBuffer=null,this.micWorklet&&=(this.micWorklet.port.onmessage=null,q(this.micWorklet),null),q(this.micSource),this.micSource=null,Ye(this.micStream),this.micStream=null,this.audioContext&&this.audioContext.state!==`closed`){try{this.audioContext.close()}catch{}this.audioContext=null,this.micWorkletModuleLoaded=!1}}},J=e(i(),1);function $e(){return{turns:[],interimUser:``,interimAgent:``,working:!1}}function et(e,t){return t.length===0?e:[...e,[...t]]}function tt(e,t){return e?t?t.startsWith(e)||e.startsWith(t)?t.length>=e.length?t:e:nt(e,t):e:t}function nt(e,t){return e?t?!e.endsWith(` `)&&!t.startsWith(` `)&&!/^\s/.test(t)&&!/^[\s.,!?;:]/.test(t)?`${e} ${t}`:`${e}${t}`:e:t}function rt(e){return`${String(Date.now())}-${String(e.turns.length)}`}function it(e,t,n,r,i){if(!t)return e;if(r)return n?{...e,interimUser:t}:{...e,interimAgent:t};let a=n?`user`:`agent`,o=[...e.turns],s=o.at(-1),c=n?e.interimUser:e.interimAgent;if(!i?.forceNew&&s?.role===a)o[o.length-1]={...s,text:nt(s.text,t)};else{let n=i?.forceNew?t:tt(c,t);o.push({id:rt(e),role:a,text:n})}return{...e,turns:o,interimUser:n?``:e.interimUser,interimAgent:n?e.interimAgent:``}}function at(e){return e.type===`thought`||e.type===`tool`||e.type===`citation`}function ot(e,t){return e.findIndex(e=>e.role===`work`&&e.events.some(e=>e.type===`tool`&&e.tool.callId===t))}function st(e,t){if(t.type===`tool`&&t.tool.phase!==void 0)return t.tool.phase===`gate`?-1:ot(e,t.tool.callId);let n=e.at(-1)?.role===`work`;return t.type===`thought`&&!(n?t.text:t.text.trim())?-1:n?e.length-1:e.length}function ct(e,t){if(t.type===`done`)return e.working?{...e,working:!1}:e;if(!at(t))return e;let n=st(e.turns,t);if(n===-1)return e;let r=[...e.turns],i=r[n];return r[n]=i?.role===`work`?{...i,events:[...i.events,t]}:{id:rt(e),role:`work`,events:[t]},{...e,turns:r,working:!0}}function lt(e){return e.role===`work`?he(e.events,{idPrefix:e.id}):[{id:e.id,kind:e.role===`user`?`user-text`:`text`,text:e.text}]}var ut=24;function dt(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;return n}function ft(e,t){let n=e.trim();return dt(n,t.trim())>=Math.min(n.length,ut)}function pt(e){return e.filter((t,n)=>{if(t.role!==`agent`)return!0;let r=e.slice(n+1),i=r.findIndex(e=>e.role===`user`);return!(i===-1?r:r.slice(0,i)).some(e=>e.role===`agent`&&ft(t.text,e.text))})}function mt(e,{turns:t,interimUser:n,interimAgent:r}){let i=[...t];n&&i.push({id:`interim-user`,role:`user`,text:n}),r&&i.push({id:`interim-agent`,role:`agent`,text:r});let a=[...e.map((e,t)=>e.map(e=>({...e,id:`${String(t)}:${e.id}`}))),i].map(e=>pt(e).flatMap(lt)).filter(e=>e.length>0);return{blocks:a.flat(),callStarts:a.slice(1).map(e=>e[0].id)}}function ht({working:e,interimAgent:t}){return t!==``||e}function gt(e){return!e.interimUser&&!e.interimAgent?e:{...e,interimUser:``,interimAgent:``}}function _t(e,t){let n=Object.keys(t??{}).sort().join(`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,l as n,n as r,u as i}from"./themeProps-3IqahpCr.js";import{h as a}from"./tokens.stylex-DkHf0P9C.js";import{i as o,l as s,u as c}from"./SegmentedControlItem-BLuJOusN.js";import{t as l}from"./VStack-CkVMcNiK.js";import{n as u,t as d}from"./StackItem-CQviqAfM.js";import{A as f,N as p,W as m,s as h,t as g,v as _}from"./browser-transport-DYgEItHi.js";import{t as v}from"./mergeProps-ptS-gIMz.js";import{p as y}from"./fieldParts-Cs6Amprh.js";import{t as b}from"./Icon-ZfFwTt8n.js";import{p as x,r as S,t as C,u as ee}from"./IconButton-CG5klqF1.js";import{d as w,f as T,h as E,o as D,u as O}from"./use-trace-records-BkAYJz0M.js";import{t as k}from"./Text-BsiAsowd.js";import{a as A,n as j,t as M}from"./labels-provider-BSiD6Lrb.js";import{t as N}from"./Dialog-BDUExlk_.js";import{t as P}from"./createReactComponent-CZwsv6DD.js";import{a as F,i as I,t as L}from"./Banner-C4MPbvft.js";import{t as R}from"./Center-nHS1JSux.js";import{_ as z,g as B,m as te,n as ne,r as re,t as ie,v as ae,y as oe}from"./studio-labels-C1pvg0JC.js";import{Mr as V}from"./tool-schema-E9NPuDcN.js";import{c as H}from"./host-patterns-C9RMP16Q.js";import{Mn as se,fn as ce,pn as le}from"./shaped-data-0GUF7Al3.js";import{S as ue,g as de,r as fe,t as pe}from"./reader-BB7aL5yX.js";import{i as U}from"./live-ingress-lDUGPwth.js";import{i as me,v as he}from"./turn-client-Dy9-U9_L.js";import{r as ge,t as _e}from"./live-messages-dPuowG_o.js";import{t as ve}from"./EmptyState-C8W4JKBZ.js";import"./use-second-ticker-VX91zrxj.js";import{t as ye}from"./Section-DJ97F7QE.js";import{C as be,F as xe,Q as Se,at as Ce,i as we,m as Te,ot as Ee,st as De,xt as Oe}from"./index-Dajtrq_Z.js";var ke=P(`outline`,`camera-rotate`,`CameraRotate`,[[`path`,{d:`M5 7h1a2 2 0 0 0 2 -2a1 1 0 0 1 1 -1h6a1 1 0 0 1 1 1a2 2 0 0 0 2 2h1a2 2 0 0 1 2 2v9a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-9a2 2 0 0 1 2 -2`,key:`svg-0`}],[`path`,{d:`M11.245 15.904a3 3 0 0 0 3.755 -2.904m-2.25 -2.905a3 3 0 0 0 -3.75 2.905`,key:`svg-1`}],[`path`,{d:`M14 13h2v2`,key:`svg-2`}],[`path`,{d:`M10 13h-2v-2`,key:`svg-3`}]]),Ae=P(`outline`,`microphone-off`,`MicrophoneOff`,[[`path`,{d:`M3 3l18 18`,key:`svg-0`}],[`path`,{d:`M9 5a3 3 0 0 1 6 0v5a3 3 0 0 1 -.13 .874m-2 2a3 3 0 0 1 -3.87 -2.872v-1`,key:`svg-1`}],[`path`,{d:`M5 10a7 7 0 0 0 10.846 5.85m2 -2a6.967 6.967 0 0 0 1.152 -3.85`,key:`svg-2`}],[`path`,{d:`M8 21l8 0`,key:`svg-3`}],[`path`,{d:`M12 17l0 4`,key:`svg-4`}]]),je=P(`outline`,`phone-off`,`PhoneOff`,[[`path`,{d:`M3 21l18 -18`,key:`svg-0`}],[`path`,{d:`M5.831 14.161a15.946 15.946 0 0 1 -2.831 -8.161a2 2 0 0 1 2 -2h4l2 5l-2.5 1.5c.108 .22 .223 .435 .345 .645m1.751 2.277c.843 .84 1.822 1.544 2.904 2.078l1.5 -2.5l5 2v4a2 2 0 0 1 -2 2a15.963 15.963 0 0 1 -10.344 -4.657`,key:`svg-1`}]]),Me=P(`outline`,`phone`,`Phone`,[[`path`,{d:`M5 4h4l2 5l-2.5 1.5a11 11 0 0 0 5 5l1.5 -2.5l5 2v4a2 2 0 0 1 -2 2a16 16 0 0 1 -15 -15a2 2 0 0 1 2 -2`,key:`svg-0`}]]),Ne=P(`outline`,`subtitles`,`Subtitles`,[[`path`,{d:`M18 5a3 3 0 0 1 3 3v8a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-8a3 3 0 0 1 3 -3l12 0`,key:`svg-0`}],[`path`,{d:`M7 15h5`,key:`svg-1`}],[`path`,{d:`M15 15h2`,key:`svg-2`}],[`path`,{d:`M17 12h-3`,key:`svg-3`}],[`path`,{d:`M11 12h-1`,key:`svg-4`}]]),Pe=P(`outline`,`video-off`,`VideoOff`,[[`path`,{d:`M3 3l18 18`,key:`svg-0`}],[`path`,{d:`M15 11v-1l4.553 -2.276a1 1 0 0 1 1.447 .894v6.764a1 1 0 0 1 -.675 .946`,key:`svg-1`}],[`path`,{d:`M10 6h3a2 2 0 0 1 2 2v3m0 4v1a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2v-8a2 2 0 0 1 2 -2h1`,key:`svg-2`}]]),Fe=P(`outline`,`video`,`Video`,[[`path`,{d:`M15 10l4.553 -2.276a1 1 0 0 1 1.447 .894v6.764a1 1 0 0 1 -1.447 .894l-4.553 -2.276v-4`,key:`svg-0`}],[`path`,{d:`M3 8a2 2 0 0 1 2 -2h8a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-8a2 2 0 0 1 -2 -2l0 -8`,key:`svg-1`}]]);function Ie(e){return e.status===`reconnecting`?`reconnecting`:e.toolName?`calling_tool`:e.connectPhase===`socket`?`connecting`:e.connectPhase===`microphone`?`requesting_mic`:e.status===`speaking`?`speaking`:e.status===`listening`||e.status===`ready`?e.voiceEnabled===!1?`connected`:e.isMuted?`muted`:`listening`:e.status===`connecting`?`connecting`:e.status===`error`?`error`:`ended`}function Le(e){return!(e.isMuted||!e.socketOpen||e.modelPlaying&&e.rms<e.bargeInRmsWhileSpeaking)}function Re(e){let{evidence:t,text:n}=e;return!n||t.kind!==`input_transcription`&&t.kind!==`output_transcription`?null:{text:n,isUser:t.kind===`input_transcription`,interim:t.interim===!0}}function ze(e,t){if(e.phase===void 0){t.toolCalls.push({id:e.callId,name:e.name,arguments:e.arguments,...e.operationId?{operationId:e.operationId}:{}});return}if(e.phase===`cancel`){t.cancelledToolIds.add(e.callId);return}if(e.phase!==`error`)return;let n=t.toolCalls.findIndex(t=>t.id===e.callId);n!==-1&&t.toolCalls.splice(n,1)}function Be(e){if(!(e instanceof Error))return!1;let t=`name`in e&&typeof e.name==`string`?e.name:``;return t===`NotAllowedError`||t===`PermissionDeniedError`||/permission|not allowed|denied/i.test(e.message)}var Ve=`mic-capture-processor`;function He(){return new URL(`data:text/javascript;base64,LyoqCiAqIEF1ZGlvV29ya2xldCBwcm9jZXNzb3IgdGhhdCBmb3J3YXJkcyBtb25vIG1pYyBmcmFtZXMgdG8gdGhlIG1haW4gdGhyZWFkLgogKiBQbGFpbiBKUzogaXQgcnVucyBpbiB0aGUgQXVkaW9Xb3JrbGV0R2xvYmFsU2NvcGUgYXMgaXRzIG93biBtb2R1bGUsIGxvYWRlZAogKiBieSBVUkwgKHNlZSBgLi4vbWljLWNhcHR1cmUudHNgKSwgc28gaXQgaW1wb3J0cyBub3RoaW5nIGFuZCBzaGlwcyBhcyBpcy4KICovCnJlZ2lzdGVyUHJvY2Vzc29yKAogICdtaWMtY2FwdHVyZS1wcm9jZXNzb3InLAogIGNsYXNzIE1pY0NhcHR1cmVQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogICAgcHJvY2VzcyhpbnB1dHMpIHsKICAgICAgY29uc3QgY2hhbm5lbCA9IGlucHV0c1swXVswXTsKICAgICAgY29uc3QgY29weSA9IG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZShjb3B5LCBbY29weS5idWZmZXJdKTsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgfSwKKTsK`,``+import.meta.url)}function Ue(e,t,n=16e3){if(t===n)return We(e);let r=t/n,i=Math.round(e.length/r),a=new Int16Array(i),o=0,s=0;for(;o<a.length;){let t=Math.round((o+1)*r),n=0,i=0;for(let r=s;r<t&&r<e.length;r++)n+=e[r]??0,i++;a[o]=W(i>0?n/i:0),o++,s=t}return a}function We(e){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=W(e[n]??0);return t}function W(e){let t=Math.max(-1,Math.min(1,e));return t<0?t*32768:t*32767}function Ge(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=new Float32Array(e.byteLength/2);for(let e=0;e<n.length;e++){let r=t.getInt16(e*2,!0);n[e]=r/(r<0?32768:32767)}return n}function G(e){return JSON.stringify(e)}function Ke(){return{toolCalls:[],mediaChunks:[],cancelledToolIds:new Set}}var qe=.05,Je=[500,1e3,2e3,4e3,8e3];function K(e){return e instanceof Error?e:new H(`internal`,V(e),{cause:e})}function q(e){if(e&&typeof e.disconnect==`function`)try{e.disconnect()}catch{}}function Ye(e){if(e&&typeof e.getTracks==`function`)for(let t of e.getTracks())t.stop()}function Xe(e){let t=Ce(e.inputFloat32),n=e.hasPlaybackNodes||e.status===`speaking`;return Le({isMuted:e.isMuted,socketOpen:e.wsOpen,modelPlaying:n,rms:t,bargeInRmsWhileSpeaking:qe})}function Ze(e,t){return e===`listening`&&t?`working`:e===`working`&&!t?`listening`:null}var Qe=class{ws=null;audioContext=null;micStream=null;micSource=null;micWorklet=null;micWorkletModuleLoaded=!1;playbackNodes=[];playbackBus=null;playbackAnalyser=null;playbackMeterFrame=0;playbackMeterBuffer=null;nextPlaybackTime=0;status=`disconnected`;serverWorking=!1;micActivating=!1;connectTimeout=null;isMuted=!1;options;inboundChain=Promise.resolve();audioChain=Promise.resolve();toolChain=Promise.resolve();audioEpoch=0;pendingExecuteResults=new Map;context;sentContext;history=[];providerState;sessionOver=!1;droppedAt;lostAt;reconnectTries=0;reconnectTimer=null;constructor(e){this.options=e,this.context=e.context}setStatus(e){this.status=e,(e===`listening`||e===`disconnected`||e===`error`)&&this.clearConnectTimeout(),this.options.onStatusChange?.(e)}get opening(){return this.status===`connecting`||this.status===`reconnecting`}setConnectPhase(e){this.options.onConnectPhase?.(e)}clearConnectTimeout(){this.connectTimeout&&=(clearTimeout(this.connectTimeout),null)}detachWebSocket(){for(let[e,t]of this.pendingExecuteResults)t.reject(new H(`network`,`live session closed before call ${e} settled`));if(this.pendingExecuteResults.clear(),this.ws){this.ws.onopen=null,this.ws.onmessage=null,this.ws.onclose=null,this.ws.onerror=null;try{this.ws.close()}catch{}this.ws=null}}clearReconnect(){this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.reconnectTries=0,this.droppedAt=void 0}teardownConnection(){this.clearConnectTimeout(),this.micActivating=!1,this.setConnectPhase(null),this.detachWebSocket(),this.cleanupAudio()}failSession(e){this.status!==`error`&&this.status!==`disconnected`&&(this.clearReconnect(),this.teardownConnection(),this.options.onError?.(e),this.setStatus(`error`))}createSocket(e){return this.options.createSocket?.()??new WebSocket(e)}connect(){let e=this.lostAt;return this.clearReconnect(),this.lostAt=void 0,e===void 0?(this.providerState=void 0,this.history=[]):this.droppedAt=e,this.open(`connecting`)}startOver(){return this.status!==`connecting`||!this.providerState?!1:(this.providerState=void 0,this.droppedAt=void 0,this.open(`connecting`),!0)}openMessage(){let{slots:e,openMessage:t}=this.options;return{type:`open`,...this.history.length?{history:structuredClone(this.history)}:{},...e?{slots:e}:{},...this.context===void 0?{}:{context:this.context},...this.providerState?{resume:{providerState:this.providerState,awayMs:this.droppedAt===void 0?0:Date.now()-this.droppedAt}}:{},...t?{host:t}:{}}}handleDrop(){!this.providerState||this.sessionOver?(this.teardownConnection(),this.setStatus(`disconnected`)):(this.droppedAt??=Date.now(),this.teardownConnection(),this.setStatus(`reconnecting`),this.scheduleReconnect())}scheduleReconnect(){let e=Je[this.reconnectTries];if(e===void 0){let e=this.droppedAt;this.failSession(new H(`network`,`live call dropped and could not reconnect`)),this.lostAt=e}else this.reconnectTries+=1,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.open(`reconnecting`)},e)}failOpen(e){this.status===`reconnecting`?(this.teardownConnection(),this.scheduleReconnect()):this.startOver()||this.failSession(e)}async open(e){this.teardownConnection(),this.sessionOver=!1,this.setStatus(e),e===`connecting`&&this.setConnectPhase(`socket`);try{let e=globalThis.AudioContext;this.audioContext=new e,this.audioContext.state===`suspended`&&await this.audioContext.resume();let t=globalThis.location.protocol===`https:`?`wss:`:`ws:`,n=this.options.profile?`?profile=${encodeURIComponent(this.options.profile)}`:``,r=`${t}//${globalThis.location.host}/api/live/relay${n}`,i=this.options.relayUrl||r;this.ws=this.createSocket(i),this.ws.binaryType=`arraybuffer`,this.ws.onopen=()=>{let e=this.openMessage();this.sentContext=JSON.stringify(e.context),this.ws?.send(JSON.stringify(e))},this.connectTimeout=setTimeout(()=>{this.opening&&this.failOpen(new H(`timeout`,`live connect timed out`))},2e4),this.ws.onmessage=e=>{this.enqueueServerMessage(e.data)},this.ws.onclose=()=>{this.opening?this.failOpen(new H(`network`,`live socket closed before ready`)):this.handleDrop()},this.ws.onerror=()=>{!this.opening&&this.providerState&&!this.sessionOver?this.handleDrop():this.failOpen(new H(`network`,`live socket error`))}}catch(e){this.failOpen(new H(`internal`,V(e),{cause:e}))}}async ensureAudioContext(){if(!this.audioContext||this.audioContext.state===`closed`){let e=globalThis.AudioContext;this.audioContext=new e,this.audioContext.state===`suspended`&&await this.audioContext.resume()}}async activateMicrophone(){if(!this.micActivating&&this.opening){this.micActivating=!0,this.status===`connecting`&&this.setConnectPhase(`microphone`);try{await this.ensureAudioContext(),this.micStream=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}}),await this.setupMicrophonePipeline(),this.becomeReady()}catch(e){let t=Be(e);this.failSession(new H(t?`auth`:`internal`,V(e),{cause:e,copy:{key:t?`voice.permission`:`voice.unavailable`}}))}finally{this.micActivating=!1}}}sendMicFrame(e,t){let n=Ue(e,t,16e3),r=le(new Uint8Array(n.buffer)),i=this.ws;i?.readyState===WebSocket.OPEN&&i.send(G({type:`audio`,data:r}))}reportMicVolume(e){this.isMuted||this.options.onVolumeLevel?.(Ee(e),!0)}forwardMicBuffer(e){if(this.reportMicVolume(e),Xe({isMuted:this.isMuted,wsOpen:this.ws?.readyState===WebSocket.OPEN,hasPlaybackNodes:this.playbackNodes.length>0,status:this.status,inputFloat32:e})){let t=this.audioContext?this.audioContext.sampleRate:48e3;this.sendMicFrame(e,t)}}async setupMicrophonePipeline(){if(!this.micStream||!this.audioContext)return;this.micSource=this.audioContext.createMediaStreamSource(this.micStream);let e=this.audioContext.createGain();e.gain.value=0,this.micWorkletModuleLoaded||=(await this.audioContext.audioWorklet.addModule(He()),!0),this.micWorklet=new AudioWorkletNode(this.audioContext,Ve),this.micWorklet.port.onmessage=e=>{let t=new Float32Array(e.data);this.forwardMicBuffer(t)},this.micSource.connect(this.micWorklet),this.micWorklet.connect(e),e.connect(this.audioContext.destination)}ensurePlaybackBus(){this.audioContext&&!this.playbackBus&&(this.playbackBus=this.audioContext.createGain(),this.playbackAnalyser=this.audioContext.createAnalyser(),this.playbackAnalyser.fftSize=512,this.playbackAnalyser.smoothingTimeConstant=.35,this.playbackBus.connect(this.playbackAnalyser),this.playbackAnalyser.connect(this.audioContext.destination),this.playbackMeterBuffer=new Uint8Array(this.playbackAnalyser.fftSize))}stopPlaybackMeter(){this.playbackMeterFrame&&=(cancelAnimationFrame(this.playbackMeterFrame),0),this.options.onVolumeLevel?.(0,!1)}startPlaybackMeter(){if(this.playbackMeterFrame)return;let e=()=>{this.playbackNodes.length===0||!this.playbackAnalyser||!this.playbackMeterBuffer?this.stopPlaybackMeter():(this.playbackAnalyser.getByteTimeDomainData(this.playbackMeterBuffer),this.options.onVolumeLevel?.(De(this.playbackMeterBuffer),!1),this.playbackMeterFrame=requestAnimationFrame(e))};this.playbackMeterFrame=requestAnimationFrame(e)}async processServerEnvelope(e){if(await this.tryHandleControlEnvelope(e)||e.type!==`events`)return;let t=this.collectInboundTurn(e.events),n=t.toolCalls.filter(e=>!t.cancelledToolIds.has(e.id));for(let e of n)this.toolChain=this.toolChain.then(()=>this.options.onToolCall(e.name,e.arguments,{callId:e.id,operationId:me(e)})).catch(e=>{this.options.onError?.(K(e))});this.scheduleMediaChunks(t.mediaChunks)}enqueueServerMessage(e){this.inboundChain=this.inboundChain.then(async()=>{if(typeof e!=`string`)return;let t=ge(e);t.type===`unsupported`||t.type===`malformed`?this.options.onTurnEvent?.(t):await this.processServerEnvelope(t)}).catch(e=>{this.options.onError?.(K(e))})}async handleReadyEnvelope(e){this.options.onSessionReady?.({sessionId:e.sessionId,profile:e.profile}),this.options.voiceIngress===!1?this.becomeReady():await this.activateMicrophone()}becomeReady(){this.clearReconnect(),this.setConnectPhase(null),this.setStatus(`listening`),this.flushContext()}handleExecuteToolResultEnvelope(e){let t=this.pendingExecuteResults.get(e.operationId);t&&t.callId===e.callId&&(this.pendingExecuteResults.delete(e.operationId),e.status===`refused`?t.reject(ue(e.body,`request`)):e.status===`dispatched`?t.resolve({status:`dispatched`,grantId:e.grantId,arguments:e.arguments}):e.status===`gated`?t.resolve({status:`gated`,gate:e.gate}):t.resolve({status:`settled`}))}async tryHandleControlEnvelope(e){return e.type===`ready`?(await this.handleReadyEnvelope(e),!0):e.type===`executeToolResult`?(this.handleExecuteToolResultEnvelope(e),!0):e.type===`trace`?(this.options.onTrace?.(e.record),!0):e.type===`error`&&(this.startOver()||(this.sessionOver=!0,this.options.onError?.(ue(e,`unavailable`)),this.setStatus(`error`)),!0)}collectInboundTurn(e){let t=Ke();for(let n of e)this.processTurnEvent(n,t);return t}processTurnEvent(e,t){switch(e.type===`provider_checkpoint`&&e.history&&(this.history=structuredClone(e.history)),(e.type===`provider_checkpoint`||e.type===`done`)&&e.providerState&&(this.providerState=e.providerState),e.type===`provider_warning`&&(this.providerState=void 0),this.options.onTurnEvent?.(e),e.type){case`evidence`:this.handleEvidenceTurnEvent(e);break;case`session`:this.handleSessionTurnEvent(e);break;case`media`:this.collectMediaTurnEvent(e,t);break;case`tool`:ze(e.tool,t);break;case`done`:this.handleDoneTurnEvent(e)}}handleEvidenceTurnEvent(e){let t=Re(e);t&&this.options.onTranscript?.(t.text,t.isUser,{interim:t.interim})}handleSessionTurnEvent(e){if(this.notifySessionLifecycle(e.session))return;this.serverWorking=e.session.kind===`working`;let t=Ze(this.status,this.serverWorking);t&&this.setStatus(t)}notifySessionLifecycle(e){return e.kind===`closing_soon`?(this.options.onSessionClosing?.(e.timeLeftMs),!0):e.kind===`ended`?this.providerState?(this.handleDrop(),!0):(this.sessionOver=!0,this.options.onSessionEnded?.(e),!0):!1}restingStatus(){return this.serverWorking?`working`:`listening`}collectMediaTurnEvent(e,t){e.media.data&&(this.setStatus(`speaking`),t.mediaChunks.push({data:e.media.data,mimeType:e.media.mimeType}))}handleDoneTurnEvent(e){e.interrupted&&this.cancelPlayback(),e.stop.kind!==`generation_complete`&&(this.serverWorking=!1,this.setStatus(`listening`))}scheduleMediaChunks(e){if(e.length===0)return;let t=this.audioEpoch;for(let n of e)this.audioChain=this.audioChain.then(async()=>{t===this.audioEpoch&&await this.enqueueAudioChunk(n.data,n.mimeType)}).catch(e=>{this.options.onError?.(K(e))})}executeToolOnRelay(e){let t=this.ws;if(!t||t.readyState!==WebSocket.OPEN)throw new H(`request`,`live session is not connected`);let n=_e.safeParse({...e,type:`executeTool`});if(!n.success||n.data.type!==`executeTool`)throw new H(`request`,se(`error.request`));let r=n.data;if(this.pendingExecuteResults.has(r.operationId))throw new H(`request`,se(`session.gate_expired`));return new Promise((e,n)=>{this.pendingExecuteResults.set(r.operationId,{callId:r.callId,resolve:e,reject:n});try{t.send(G(r))}catch(e){this.pendingExecuteResults.delete(r.operationId),n(K(e))}})}async enqueueAudioChunk(e,t){if(this.audioContext)try{if(this.ensurePlaybackBus(),!this.playbackBus)return;let n=ce(e),r;if(t?.includes(`wav`)){let e=n.buffer.slice(n.byteOffset,n.byteOffset+n.byteLength);r=await this.audioContext.decodeAudioData(e)}else{let e=Ge(n);r=this.audioContext.createBuffer(1,e.length,24e3),r.getChannelData(0).set(e)}let i=this.audioContext.createBufferSource();i.buffer=r,i.connect(this.playbackBus);let a=this.audioContext.currentTime,o=Math.max(a,this.nextPlaybackTime);i.start(o),this.nextPlaybackTime=o+r.duration,this.playbackNodes.push(i),this.startPlaybackMeter(),i.onended=()=>{let e=this.playbackNodes.indexOf(i);e!==-1&&this.playbackNodes.splice(e,1),this.playbackNodes.length===0&&(this.stopPlaybackMeter(),this.status===`speaking`&&this.setStatus(this.restingStatus()))}}catch(e){this.options.onError?.(K(e))}}cancelPlayback(){this.audioEpoch+=1,this.audioChain=Promise.resolve();for(let e of this.playbackNodes)try{e.stop(),e.disconnect()}catch{}this.playbackNodes=[],this.stopPlaybackMeter(),this.audioContext&&(this.nextPlaybackTime=this.audioContext.currentTime)}toggleMute(){return this.isMuted=!this.isMuted,this.isMuted}sendText(e){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(G({type:`text`,text:e}))}setSlots(e){JSON.stringify(e)!==JSON.stringify(this.options.slots)&&(this.options={...this.options,slots:e},this.providerState&&!this.opening&&this.ws?.readyState===WebSocket.OPEN&&this.handleDrop())}setContext(e){this.context=e,this.flushContext()}flushContext(){if(this.opening||this.ws?.readyState!==WebSocket.OPEN)return;let e=JSON.stringify(this.context);e!==this.sentContext&&(this.sentContext=e,this.ws.send(G({type:`context`,context:this.context})))}sendVideo(e,t=`image/jpeg`){this.ws&&this.ws.readyState===WebSocket.OPEN&&this.ws.send(G({type:`video`,data:e,mimeType:t}))}disconnect(){this.clearReconnect(),this.lostAt=void 0,this.providerState=void 0,this.teardownConnection(),this.setStatus(`disconnected`)}cleanupAudio(){if(this.cancelPlayback(),this.stopPlaybackMeter(),q(this.playbackBus),this.playbackBus=null,this.playbackAnalyser=null,this.playbackMeterBuffer=null,this.micWorklet&&=(this.micWorklet.port.onmessage=null,q(this.micWorklet),null),q(this.micSource),this.micSource=null,Ye(this.micStream),this.micStream=null,this.audioContext&&this.audioContext.state!==`closed`){try{this.audioContext.close()}catch{}this.audioContext=null,this.micWorkletModuleLoaded=!1}}},J=e(i(),1);function $e(){return{turns:[],interimUser:``,interimAgent:``,working:!1}}function et(e,t){return t.length===0?e:[...e,[...t]]}function tt(e,t){return e?t?t.startsWith(e)||e.startsWith(t)?t.length>=e.length?t:e:nt(e,t):e:t}function nt(e,t){return e?t?!e.endsWith(` `)&&!t.startsWith(` `)&&!/^\s/.test(t)&&!/^[\s.,!?;:]/.test(t)?`${e} ${t}`:`${e}${t}`:e:t}function rt(e){return`${String(Date.now())}-${String(e.turns.length)}`}function it(e,t,n,r,i){if(!t)return e;if(r)return n?{...e,interimUser:t}:{...e,interimAgent:t};let a=n?`user`:`agent`,o=[...e.turns],s=o.at(-1),c=n?e.interimUser:e.interimAgent;if(!i?.forceNew&&s?.role===a)o[o.length-1]={...s,text:nt(s.text,t)};else{let n=i?.forceNew?t:tt(c,t);o.push({id:rt(e),role:a,text:n})}return{...e,turns:o,interimUser:n?``:e.interimUser,interimAgent:n?e.interimAgent:``}}function at(e){return e.type===`thought`||e.type===`tool`||e.type===`citation`}function ot(e,t){return e.findIndex(e=>e.role===`work`&&e.events.some(e=>e.type===`tool`&&e.tool.callId===t))}function st(e,t){if(t.type===`tool`&&t.tool.phase!==void 0)return t.tool.phase===`gate`?-1:ot(e,t.tool.callId);let n=e.at(-1)?.role===`work`;return t.type===`thought`&&!(n?t.text:t.text.trim())?-1:n?e.length-1:e.length}function ct(e,t){if(t.type===`done`)return e.working?{...e,working:!1}:e;if(!at(t))return e;let n=st(e.turns,t);if(n===-1)return e;let r=[...e.turns],i=r[n];return r[n]=i?.role===`work`?{...i,events:[...i.events,t]}:{id:rt(e),role:`work`,events:[t]},{...e,turns:r,working:!0}}function lt(e){return e.role===`work`?he(e.events,{idPrefix:e.id}):[{id:e.id,kind:e.role===`user`?`user-text`:`text`,text:e.text}]}var ut=24;function dt(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n+=1;return n}function ft(e,t){let n=e.trim();return dt(n,t.trim())>=Math.min(n.length,ut)}function pt(e){return e.filter((t,n)=>{if(t.role!==`agent`)return!0;let r=e.slice(n+1),i=r.findIndex(e=>e.role===`user`);return!(i===-1?r:r.slice(0,i)).some(e=>e.role===`agent`&&ft(t.text,e.text))})}function mt(e,{turns:t,interimUser:n,interimAgent:r}){let i=[...t];n&&i.push({id:`interim-user`,role:`user`,text:n}),r&&i.push({id:`interim-agent`,role:`agent`,text:r});let a=[...e.map((e,t)=>e.map(e=>({...e,id:`${String(t)}:${e.id}`}))),i].map(e=>pt(e).flatMap(lt)).filter(e=>e.length>0);return{blocks:a.flat(),callStarts:a.slice(1).map(e=>e[0].id)}}function ht({working:e,interimAgent:t}){return t!==``||e}function gt(e){return!e.interimUser&&!e.interimAgent?e:{...e,interimUser:``,interimAgent:``}}function _t(e,t){let n=Object.keys(t??{}).sort().join(`
|
|
2
2
|
`),r=e?.join(`
|
|
3
3
|
`);(0,J.useEffect)(()=>{r!==void 0&&Se(r?r.split(`
|
|
4
4
|
`):[],n?n.split(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{g as r}from"./fieldParts-Cs6Amprh.js";import{t as i}from"./Icon-ZfFwTt8n.js";import{r as a,t as o}from"./IconButton-CG5klqF1.js";import{t as s}from"./Text-BsiAsowd.js";import{t as c}from"./createReactComponent-CZwsv6DD.js";import{n as l,t as u}from"./ScrollableArea-C8AVuqnt.js";import{n as d,t as f}from"./Center-nHS1JSux.js";import{t as p}from"./IconEye-BB5aY-wQ.js";import{t as m}from"./IconSearch-BTx66a40.js";import{r as h,s as g,t as _}from"./tree-2VeaKg0m.js";import{P as v,i as y}from"./workspace-Cno6Ge26.js";import{a as b,n as x,r as S}from"./studio-session-yEqFQo5o.js";import{t as C}from"./EmptyState-C8W4JKBZ.js";import{t as ee}from"./ContextMenu-BeVF9aNZ.js";import{Dt as w,Et as T,K as E,d as D,dt as O,ft as k,ht as A,lt as j,mt as M,n as N,pt as P,u as F,ut as I,z as L}from"./index--GBhZcW8.js";var R=c(`outline`,`arrows-maximize`,`ArrowsMaximize`,[[`path`,{d:`M16 4l4 0l0 4`,key:`svg-0`}],[`path`,{d:`M14 10l6 -6`,key:`svg-1`}],[`path`,{d:`M8 20l-4 0l0 -4`,key:`svg-2`}],[`path`,{d:`M4 20l6 -6`,key:`svg-3`}],[`path`,{d:`M16 20l4 0l0 -4`,key:`svg-4`}],[`path`,{d:`M14 14l6 6`,key:`svg-5`}],[`path`,{d:`M8 4l-4 0l0 4`,key:`svg-6`}],[`path`,{d:`M4 4l6 6`,key:`svg-7`}]]),z=c(`outline`,`arrows-minimize`,`ArrowsMinimize`,[[`path`,{d:`M5 9l4 0l0 -4`,key:`svg-0`}],[`path`,{d:`M3 3l6 6`,key:`svg-1`}],[`path`,{d:`M5 15l4 0l0 4`,key:`svg-2`}],[`path`,{d:`M3 21l6 -6`,key:`svg-3`}],[`path`,{d:`M19 9l-4 0l0 -4`,key:`svg-4`}],[`path`,{d:`M15 9l6 -6`,key:`svg-5`}],[`path`,{d:`M19 15l-4 0l0 4`,key:`svg-6`}],[`path`,{d:`M15 15l6 6`,key:`svg-7`}]]),B=c(`outline`,`focus-2`,`Focus2`,[[`path`,{d:`M11.5 12a.5 .5 0 1 0 1 0a.5 .5 0 1 0 -1 0`,fill:`currentColor`,key:`svg-0`}],[`path`,{d:`M5 12a7 7 0 1 0 14 0a7 7 0 1 0 -14 0`,key:`svg-1`}],[`path`,{d:`M12 3l0 2`,key:`svg-2`}],[`path`,{d:`M3 12l2 0`,key:`svg-3`}],[`path`,{d:`M12 19l0 2`,key:`svg-4`}],[`path`,{d:`M19 12l2 0`,key:`svg-5`}]]),V=c(`outline`,`layout-grid`,`LayoutGrid`,[[`path`,{d:`M4 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-0`}],[`path`,{d:`M14 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-1`}],[`path`,{d:`M4 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-2`}],[`path`,{d:`M14 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-3`}]]);function H(e,t,n){let r=e=>{let r=t.flatMap(({from:t,to:n})=>t===e.id?[n]:n===e.id?[t]:[]).flatMap(e=>n.get(e)??[]);return r.length===0?1/0:r.reduce((e,t)=>e+t,0)/r.length},i=new Map(e.map(e=>[e.id,r(e)])),a=e=>i.get(e.id)??1/0;return[...e].sort((e,t)=>a(e)===a(t)?0:a(e)-a(t))}function U(e,t,n){return t===`models`?e.modelBindings.map(e=>e.modelId||`New model`).join(`, `):t===`tools`?String(e.tools.allow.filter(e=>n.has(e)).length):t===`outputs`?e.outputs.mode:``}function W(e,t=[]){let n=[],r=new Map(e.agents.map(e=>[e.key,y(e.key)])),i=new Map(e.toolSpecs.map(e=>[e.key,g(e.key)])),a=v(e),o=e.agents.map((e,t)=>{let{agentId:n,profileType:r,handle:o}=e.identity,s=r||`text`;return{id:y(e.key),kind:`agent`,label:n||`New agent`,note:o?`${s} · ${o}`:s,opens:y(e.key),type:s,rows:(a.agents[t]?.children??[]).map(t=>({id:t.id,label:t.label,note:U(e,t.ref.facet,i),opens:t.id,type:t.ref.facet}))}}),s=new Set(o.flatMap(e=>e.rows??[]).map(e=>e.id)),c=(e,t)=>{let n=y(e,t);return s.has(n)?n:y(e)},l=new Map,u=new Map(e.providers.map(e=>[e.id,e.definition])),d=new Map;for(let t of e.agents){let e=c(t.key,`models`);for(let i of t.modelBindings){let a=`model:${i.provider}:${i.apiId}:${i.modelId}`,o=h(i.provider);l.has(o)||l.set(o,{id:o,kind:`provider`,label:i.provider,note:``,opens:u.has(i.provider)?o:y(t.key,_(i.key))});let s=y(t.key,_(i.key)),c=d.get(a);c?c.holds?.push(s):(d.set(a,{id:a,kind:`model`,label:i.modelId||`New model`,note:i.apiId,type:u.get(i.provider),opens:s,holds:[s]}),n.push({from:o,to:a,kind:`serves`})),n.some(t=>t.from===a&&t.to===e)||n.push({from:a,to:e,kind:`runs`});let f=i.compactWith?r.get(i.compactWith):void 0,p=n.some(t=>t.kind===`summarised`&&t.from===e);f&&f!==y(t.key)&&!p&&n.push({from:e,to:f,kind:`summarised`})}for(let e of t.tools.allow){let r=i.get(e);r&&n.push({from:c(t.key,`tools`),to:r,kind:`allows`})}}let f=e.toolSpecs.map(e=>{let t=g(e.key),i=e.toolType===`agent`?r.get(e.agentKey??``):void 0;return i&&n.push({from:t,to:i,kind:`asks`}),{id:t,kind:`tool`,label:e.toolName||`New tool`,note:e.description,opens:t,type:e.toolType}}),p=t.map(t=>{let{setting:i,facet:a}=t,o=`shared:${i.file}:${i.name}`,s=t.agents.filter(e=>r.has(e)),l=i.tools.flatMap(t=>{let n=e.toolSpecs.find(e=>e.toolName===t);return n?[g(n.key)]:[]});for(let e of s)n.push({from:o,to:a?c(e,a):y(e),kind:`sets`});for(let e of l)n.push({from:o,to:e,kind:`sets`});return{id:o,kind:`shared`,label:i.label,note:`${i.name} · ${i.file}:${String(i.line)}`,opens:E(t)??l[0],type:a}}),m=new Map(o.flatMap((e,t)=>[e.id,...(e.rows??[]).map(e=>e.id)].map(e=>[e,t])));for(let e of d.values())[...d.values()].some(t=>t!==e&&t.label===e.label)&&e.note&&(e.long=`${e.label} · ${e.note}`);let b=H([...d.values()],n,m),x=new Map(b.map((e,t)=>[e.id,t])),S=(...e)=>e.filter(e=>e.nodes.length>0);return{columns:[S({label:`Providers`,nodes:H([...l.values()],n,x)}),S({label:`Shared settings`,nodes:H(p,n,m)},{label:`Models`,nodes:b}),S({label:`Profiles`,nodes:o}),S({label:`Tools`,nodes:H(f,n,m)})].filter(e=>e.length>0),links:n}}function G(e){let t=e.columns.flat().flatMap(e=>e.nodes);return new Map(t.flatMap(e=>[e.id,...(e.rows??[]).map(e=>e.id)].map(t=>[t,e])))}function K(e){let t=G(e);return e.links.flatMap(e=>{let n=t.get(e.from)?.id,r=t.get(e.to)?.id;return n!==void 0&&r!==void 0?[{link:e,from:n,to:r}]:[]})}function te(e,t){let n=t.trim().toLowerCase();return n===``?[]:e.columns.flat().flatMap(e=>e.nodes).filter(e=>[e.label,e.long??``,e.note].some(e=>e.toLowerCase().includes(n))).map(e=>e.id)}function ne(e,t){let n=typeof t==`string`?[t]:t,r=K(e),i=(e,t)=>{let i=new Set(n),a=[...n];for(let n=a.pop();n!==void 0;n=a.pop())for(let o of r)o[e]!==n||i.has(o[t])||(i.add(o[t]),a.push(o[t]));return i},a=new Set([...i(`to`,`from`),...i(`from`,`to`)]),o=e.columns.map(e=>e.map(e=>({...e,nodes:e.nodes.filter(e=>a.has(e.id))})).filter(e=>e.nodes.length>0)).filter(e=>e.length>0),s=new Set(r.filter(({from:e,to:t})=>a.has(e)&&a.has(t)).map(({link:e})=>e));return{columns:o,links:e.links.filter(e=>s.has(e))}}var re={serves:[`Serves`,`Served by`],sets:[`Sets`,`Set by`],runs:[`Runs`,`Runs on`],allows:[`Allows`,`Allowed by`],asks:[`Asks`,`Asked by`],summarised:[`Summarised by`,`Summarises for`]};function ie(e,t){let n=G(e),r=new Map;for(let{link:i,from:a,to:o}of K(e)){if(a!==t&&o!==t)continue;let e=re[i.kind][a===t?0:1],s=n.get(a===t?o:a)?.label;s!==void 0&&r.set(e,[...r.get(e)??[],s])}return[...r].map(([e,t])=>`${e} ${t.join(`, `)}.`).join(` `)}function ae(e){return e.kind===`tool`||e.kind===`shared`?2:1}var oe=24,q=8,J=16;function se(e,t,n){let r=new Map,i=(e,t)=>`${e}:${String(t)}`;return K(e).flatMap(({link:e})=>{let[a,o]=[t(e.from),t(e.to)];if(a===void 0||o===void 0||Math.abs(a-o)<n)return[];let s=a<o?1:-1;for(let t of[i(e.from,s),i(e.to,-s)])r.set(t,(r.get(t)??0)+1);return[{link:e,way:s}]}).map(({link:e,way:t})=>{let[n,a]=[i(e.from,t),i(e.to,-t)],o=(r.get(n)??0)>=(r.get(a)??0);return{link:e,way:t,leaves:o,hub:o?n:a}})}function ce(e,t,n={}){let{node:r,card:i,columnGap:a,rowGap:o,heading:s,groupGap:c,padding:l,lineGap:u}=t,{moved:d={},widths:f={},detail:p=!1}=n,m=new Map;e.columns.forEach((e,t)=>{for(let n of e)for(let e of n.nodes)if(!Object.hasOwn(d,e.id))for(let n of[e.id,...(e.rows??[]).map(e=>e.id)])m.set(n,t)});let h=t=>{let n={},a=[],u=[],m=new Map,h=0,g=0;return e.columns.forEach((e,_)=>{let v=t[_]??l,y=l;e.forEach((e,t)=>{t>0&&(y+=c),a.push({label:e.label,x:v,y}),u.push({id:`heading:${_}:${t}`,x:v,y,width:r.width,height:s}),y+=s;for(let t of e.nodes){let e=p?t.rows??[]:[],a=e.length>0||t.note!==``,s=p&&(e.length>0||ae(t)===1)?i.head:r.height,c=p&&!a?i.row:s,l=e.length>0?i.head+e.length*i.row+i.foot:c,_=Math.min(f[t.id]??r.width,r.width),b=Object.hasOwn(d,t.id)?d[t.id]:void 0,x=b?{x:Math.max(b.x,0),y:Math.max(b.y,0)}:{x:v,y};n[t.id]={...x,height:l},u.push({id:t.id,...x,width:_,height:l});let S={left:x.x,right:x.x+_,y:x.y+(p?i.row:c)/2};m.set(t.id,S);for(let[e,n]of(t.rows??[]).entries())m.set(n.id,p?{...S,y:x.y+i.head+e*i.row+i.row/2}:S);h=Math.max(h,x.x+r.width),g=Math.max(g,x.y+l),y+=l+o}y-=o})}),{nodes:n,headings:a,boxes:u,ports:m,right:h,bottom:g}},g=(e,t,n)=>{let{way:i,leaves:a}=e,o={x:i>0?t.right+u:t.left-u,y:t.y},s={x:i>0?n.left-u:n.right+u,y:n.y},c=i>0?Math.max(t.left+r.width,t.right)+u:o.x,l=i>0?s.x:Math.max(n.left+r.width,n.right)+u,d=a?l:c,f=a?-i:i;return{start:o,end:s,side:d,into:f,room:Math.abs(l-c),strip:`${String(d)}:${String(f)}`}},_=t=>{let n=new Map(se(e,e=>t.get(e)?.left,r.width).map(e=>[e.link,e])),i=new Map;for(let e of n.values()){let n=t.get(e.link.from),r=t.get(e.link.to);if(!n||!r||n.y===r.y)continue;let{strip:a}=g(e,n,r),o=i.get(a)??new Map,s=e.leaves?e.link.to:e.link.from,c=o.get(e.hub)??{y:e.leaves?n.y:r.y,joins:[],beside:s};c.joins.push(e.leaves?r.y:n.y),i.set(a,o.set(e.hub,c))}let a=new Map,o=new Map;for(let[e,t]of i){let n=e=>e.reduce((e,t)=>e+t,0)/e.length,r=[...t.values()],i=n(r.flatMap(e=>e.joins))>=n(r.map(e=>e.y)),s=[];for(let[n,r]of[...t].sort(([,e],[,t])=>i?e.y-t.y:t.y-e.y)){let t=Math.min(r.y,...r.joins)-q,i=Math.max(r.y,...r.joins)+q,o=s.findIndex(e=>e.every(e=>i<e.low||t>e.high)),c=o<0?s.length:o;s[c]=[...s[c]??[],{low:t,high:i}],a.set(`${e}:${n}`,c)}let[c]=r;c&&o.set(e,{count:s.length,beside:c.beside,into:Number(e.split(`:`)[1])})}return{spans:n,rails:a,held:o}},v=e.columns.map((e,t)=>l+t*(r.width+a)),y=e.columns.map(()=>0);for(let{count:e,beside:t,into:n}of _(h(v).ports).held.values()){let r=m.get(t);if(r===void 0)continue;let i=n>0?r:r-1;i>=0&&i<y.length&&(y[i]=(y[i]??0)+e+1)}let b=[l];for(let[e,t]of y.entries())b.push((b[e]??l)+r.width+Math.max(a,t*J));let x=h(b),{nodes:S,headings:C,boxes:ee,ports:w}=x,{right:T,bottom:E}=x,{spans:D,rails:O}=_(w),k=a/2,j=Math.max(o/2,u),N=[],P=new Map,F=Math.max(a,...y.map(e=>e*J)),I=K(e).flatMap(({link:e,from:t,to:n})=>{let i=w.get(e.from),o=w.get(e.to);if(!i||!o)return[];let s=ee.filter(e=>e.id!==t&&e.id!==n);if(Math.abs(i.left-o.left)<r.width){let r=i.right+u,a=o.right+u,c=s.filter(e=>e.y<Math.max(i.y,o.y)&&e.y+e.height>Math.min(i.y,o.y)&&e.x<Math.max(r,a)+k&&e.x+e.width>Math.min(i.left,o.left)),l=Math.max(r,a,...c.map(e=>e.x+e.width))+k;return T=Math.max(T,l),[{link:e,from:t,to:n,d:M({x:r,y:i.y},{x:a,y:o.y},l).d}]}let c=D.get(e);if(!c)return[];let{way:l,leaves:d,hub:f}=c,{start:p,end:m,side:h,into:_,room:v,strip:y}=g(c,i,o),b=h+_*Math.min((1+(O.get(`${y}:${f}`)??0))*J,Math.max(v-J,0)),x=v<32?M(p,m):A(p,m,b,q),S=(e,t)=>t>e.y-j&&t<e.y+e.height+j,C=Math.abs(m.x-p.x)<F+a?[]:s.filter(e=>Array.from({length:23},(e,t)=>x.at((t+1)/oe)).some(t=>t.x>e.x&&t.x<e.x+e.width&&S(e,t.y)));if(C.length===0)return[{link:e,from:t,to:n,d:x.d}];let[I,L]=[Math.min(p.x,m.x),Math.max(p.x,m.x)],R=e=>{let t=[...C];for(;;){let n=e<0?Math.min(...t.map(e=>e.y))-j:Math.max(...t.map(e=>e.y+e.height))+j,r=[...s,...N].filter(e=>!t.includes(e)&&e.x<L&&e.x+e.width>I&&S(e,n));if(r.length===0)return n;t.push(...r)}},z=e=>Math.abs(i.y-e)+Math.abs(o.y-e),B=`${f}:${y}`,V=P.get(B)??(()=>{let[e,t]=[R(-1),R(1)],n=e>=0&&z(e)<=z(t)?e:t;return N.push({id:``,x:I,y:n-q+j,width:L-I,height:2*(q-j)}),P.set(B,n),n})();E=Math.max(E,V);let H=d?p.x+l*J:b,U=d?b:m.x-l*J,W={x:(H+U)/2,y:V};return[{link:e,from:t,to:n,d:A(p,W,H,q).d+A(W,m,U,q).d.replace(/^M \S+ \S+/,``)}]});return{width:Math.max((b[Math.max(e.columns.length-1,0)]??l)+r.width,T)+l,height:Math.max(E,l)+l,nodes:S,headings:C,lines:I}}var Y=e(n(),1),le={tokens:{},detail:{},expanded:!1},X=e=>e===void 0?`${x}.map`:`${x}.map.project:${e}`;function ue(e){if(!S(e))return{};let t={};for(let[n,r]of Object.entries(e))S(r)&&typeof r.x==`number`&&typeof r.y==`number`&&(t[n]={x:r.x,y:r.y});return t}function de(e){try{let t=JSON.parse(b()?.getItem(X(e))??`null`);return S(t)?{tokens:ue(t.tokens),detail:ue(t.detail),expanded:t.expanded===!0,...typeof t.family==`string`?{family:t.family}:{}}:le}catch{return le}}function fe(e,t){let{tokens:n,detail:r,expanded:i,family:a}=t,o=Object.keys(n).length===0&&Object.keys(r).length===0&&!i&&a===void 0;try{o?b()?.removeItem(X(e)):b()?.setItem(X(e),JSON.stringify(t))}catch{}}function pe(e){for(let t=e.parentElement;t;t=t.parentElement){let{overflowX:e,overflowY:n}=getComputedStyle(t);if(/auto|scroll/.test(`${e} ${n}`))return t}}function me(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return{left:n.left-r.left+t.scrollLeft,top:n.top-r.top+t.scrollTop}}var he=(e,t)=>Math.min(Math.max(e,0),Math.max(t,0));function ge(e,t){let n=0,r=120,i=()=>{--r;let a=pe(e);if(a&&a.scrollWidth>a.clientWidth){let e=t(a),n=he(e.left,a.scrollWidth-a.clientWidth),r=he(e.top,a.scrollHeight-a.clientHeight);if(a.scrollTo({left:n,top:r,behavior:`instant`}),Math.abs(a.scrollLeft-n)<1&&Math.abs(a.scrollTop-r)<1)return}r>0&&(n=requestAnimationFrame(i))};return i(),()=>{cancelAnimationFrame(n)}}var _e=e=>e.button===0&&e.pointerType!==`touch`;function ve(e,t,n){let{pointerId:r,clientX:i,clientY:a}=e,o=e=>{e.pointerId===r&&t(e.clientX-i,e.clientY-a)},s=e=>{e.pointerId===r&&(globalThis.removeEventListener(`pointermove`,o),globalThis.removeEventListener(`pointerup`,s),globalThis.removeEventListener(`pointercancel`,s),n(e.type===`pointerup`))};globalThis.addEventListener(`pointermove`,o),globalThis.addEventListener(`pointerup`,s),globalThis.addEventListener(`pointercancel`,s)}function ye(e){let[t,n]=(0,Y.useState)(!1);return{panning:t,pan:t=>{if(!_e(t)||t.target.closest(e))return;let r=pe(t.currentTarget);if(!r)return;let{scrollLeft:i,scrollTop:a}=r;n(!0),ve(t,(e,t)=>{r.scrollTo({left:i-e,top:a-t,behavior:`instant`})},()=>{n(!1)})}}}var Z=t(),be={node:{width:240,height:24},card:{head:60,row:28,foot:4},columnGap:96,rowGap:6,heading:24,groupGap:16,padding:24,lineGap:8},xe={...be,node:{width:240,height:84}},Se=28;function Ce(e){return e.length>Se?`${e.slice(0,27)}…`:e}function we({kind:e,type:t,note:n}){return(e===`agent`?k(t):void 0)||(e===`tool`?P(t??``):e===`model`&&t===`typesafe`?F:e===`model`?D(n)??N.modelBinding:e===`provider`?w:e===`shared`&&t&&Object.hasOwn(N,t)?N[t]:e===`agent`?O.text:T)}function Te(e){return Object.hasOwn(N,e)?N[e]:T}function Q(e,t){return e.kind===`agent`?t===e.id||t.startsWith(`${e.id}/`):e.kind===`model`?e.holds?.includes(t)??!1:e.kind===`tool`&&t===e.id}var Ee=4,De=24,Oe={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};function ke(e){let t=L()?.name,[n,r]=(0,Y.useState)(()=>de(t)),i=e=>{r(e),fe(t,e)},{expanded:a}=n,o=e.columns.flat().some(e=>e.nodes.some(e=>e.id===n.family))?n.family:void 0,s=(0,Y.useMemo)(()=>o===void 0?e:ne(e,o),[e,o]),[c,l]=(0,Y.useState)({}),u=a?`detail`:`tokens`;return{expanded:a,family:o,map:s,moved:o===void 0?n[u]:c,put(e,t){o===void 0?t?i({...n,[u]:e}):r({...n,[u]:e}):l(e)},showFamily(e){l({});let{tokens:t,detail:r}=n;i({tokens:t,detail:r,expanded:a,...e===void 0?{}:{family:e}})},expand(){i({...n,expanded:!a})}}}function Ae(e,t,n){let r=(0,Y.useRef)(!1),[i,a]=(0,Y.useState)();return{dragging:i,draggable:i=>({onPointerDown:o=>{r.current=!1;let s=e.nodes[i];if(!s||!_e(o))return;let c;ve(o,(e,r)=>{!c&&Math.hypot(e,r)<Ee||(c||a(i),c={...t,[i]:{x:Math.max(s.x+e,0),y:Math.max(s.y+r,0)}},n(c,!1))},e=>{c&&(r.current=e,globalThis.setTimeout(()=>{r.current=!1},0),a(void 0),n(c,!0))})},onClickCapture:e=>{r.current&&(r.current=!1,e.stopPropagation(),e.preventDefault())},onKeyDown:r=>{let a=r.altKey?Oe[r.key]:void 0,o=e.nodes[i];if(!a||!o)return;r.preventDefault();let s=Math.max(o.x+a.x*De,0),c=Math.max(o.y+a.y*De,0);n({...t,[i]:{x:s,y:c}},!0)}})}}function je(e){let[t,n]=(0,Y.useState)(),[r,i]=(0,Y.useMemo)(()=>{let n=new Set,r=new Set;if(t===void 0)return[n,r];n.add(t);for(let{link:i,from:a,to:o}of e.lines)if([i.from,i.to,a,o].includes(t)){r.add(i);for(let e of[i.from,i.to,a,o])n.add(e)}return[n,r]},[e,t]);return{lit:t,on:r,onLines:i,lights:e=>({onPointerEnter:()=>{n(e)},onPointerLeave:()=>{n(void 0)},onFocus:()=>{n(e)},onBlur:()=>{n(void 0)}})}}function Me(e,t,n){let r=(0,Y.useRef)(n.place);r.current=n.place;let{sizes:i}=n;(0,Y.useEffect)(()=>{let n=e.current;if(!n)return;let a=r.current,o=t===void 0?a:void 0;return ge(n,e=>{let{left:t,top:r}=me(n,e);return o===void 0?{left:t,top:r}:{left:t+o.x+i.node.width/2-e.clientWidth/2,top:r+o.y+o.height/2-e.clientHeight/2}})},[e,t,i])}function Ne(e,t,n){let{family:r,expanded:i,isMoved:a,showFamily:o,expand:s,tidy:c}=n,l=[];e&&e.id!==r&&l.push({label:`Show only its family`,icon:B,onClick:()=>{o(e.id)}});let u=e?.opens;u!==void 0&&l.push({label:`Open`,icon:d,onClick:()=>{t(u)}}),e&&l.push({type:`divider`});let f={label:`Show everything`,icon:p,onClick:()=>{o(void 0)}};return[...l,...r===void 0?[]:[f],{label:i?`Collapse`:`Expand`,icon:i?z:R,onClick:s},{label:`Tidy`,icon:V,isDisabled:!a,onClick:c}]}function Pe({actions:e,query:t,onQuery:n,onClose:s}){let{family:c,expanded:u,isMoved:d,showFamily:f,expand:h,tidy:g}=e;return(0,Z.jsxs)(`div`,{className:`studio-map-tools`,children:[(0,Z.jsx)(l,{label:`Search the map`,isLabelHidden:!0,size:`sm`,width:200,placeholder:`Search`,startIcon:m,hasClear:!0,value:t,onChange:n}),c!==void 0&&(0,Z.jsx)(a,{label:`Show everything`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:p,size:`sm`}),onClick:()=>{f(void 0)}}),d&&(0,Z.jsx)(a,{label:`Tidy`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:V,size:`sm`}),onClick:g}),(0,Z.jsx)(o,{label:u?`Collapse`:`Expand`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:u?z:R,size:`sm`}),tooltip:u?`Show each node as a token`:`Show sections and descriptions`,onClick:h}),(0,Z.jsx)(o,{label:`Close map`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:r,size:`sm`}),tooltip:`Close the map`,onClick:s})]})}function $({node:e,on:t,isFound:n,isDragging:r}){let i=t.has(e.id)||(e.rows??[]).some(e=>t.has(e.id));return{"data-map-node":e.id,"data-on":i?``:void 0,"data-found":n?``:void 0,"data-dragging":r?``:void 0}}function Fe(e){let{node:t,place:n,joins:r,selected:i,onOpen:a,lights:o,drag:s}=e,{opens:c}=t,l=Q(t,i);return(0,Z.jsx)(j,{id:t.id,label:Ce(t.long??t.label),icon:we(t),x:n.x,y:n.y+n.height/2,color:l?`blue`:void 0,description:[t.note,r].filter(Boolean).join(`. `)||void 0,onOpen:c===void 0?void 0:()=>{a(c)},title:(t.long??t.label).length>Se?t.long??t.label:void 0,"aria-current":l?`true`:void 0,...$(e),...o(t.id),...s})}function Ie(e){let{node:t,place:n,joins:r,selected:a,on:o,onOpen:c,lights:l,drag:u}=e,{opens:d}=t,f=t.rows??[],p={left:n.x,top:n.y,height:n.height},m=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{className:`studio-map-name`,children:[(0,Z.jsx)(i,{icon:we(t),size:`sm`}),(0,Z.jsx)(s,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:t.label})]}),t.note&&(0,Z.jsx)(s,{type:`supporting`,maxLines:f.length>0?1:ae(t),hasTruncateTooltip:!1,className:`studio-map-note`,children:t.note})]}),h={type:`button`,title:t.note||void 0,"aria-description":r||void 0,disabled:d===void 0,onClick:()=>{d!==void 0&&c(d)},...l(t.id)};return f.length===0?(0,Z.jsx)(`button`,{...h,...u,...$(e),className:`studio-map-node`,"data-map-token":t.id,style:p,"aria-current":Q(t,a)?`true`:void 0,children:m}):(0,Z.jsxs)(`div`,{className:`studio-map-card`,"data-map-token":t.id,style:p,"data-open":Q(t,a)?``:void 0,...$(e),...u,children:[(0,Z.jsx)(`button`,{...h,className:`studio-map-head`,"aria-current":a===t.id?`true`:void 0,children:m}),f.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`studio-map-row`,"aria-current":a===e.id?`true`:void 0,"data-on":o.has(e.id)?``:void 0,onClick:()=>{c(e.opens)},...l(e.id),children:[(0,Z.jsx)(i,{icon:Te(e.type),size:`sm`}),(0,Z.jsx)(s,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:e.label}),e.note&&(0,Z.jsx)(s,{type:`supporting`,maxLines:1,justify:`end`,hasTruncateTooltip:!1,className:`studio-map-row-note`,children:e.note})]},e.id))]})}function Le({workspace:e,shared:t,selected:n,onOpen:r,onClose:a}){let{expanded:o,family:c,map:l,moved:d,put:p,showFamily:h,expand:g}=ke((0,Y.useMemo)(()=>W(e,t),[e,t])),[_,v]=(0,Y.useState)(``),y=(0,Y.useMemo)(()=>te(l,_),[l,_]),b=(0,Y.useMemo)(()=>_.trim()===``?l:ne(l,y),[l,_,y]),x=_.trim()!==``&&y.length===0,S=(0,Y.useRef)(null),w=o?xe:be,T=(0,Y.useMemo)(()=>({map:b,expanded:o}),[b,o]),E=I(S,T),D=(0,Y.useMemo)(()=>ce(b,w,{moved:d,widths:E,detail:o}),[b,w,o,d,E]),O=b.columns.flat().flatMap(e=>e.nodes),k=O.find(e=>Q(e,n))?.id;Me(S,c,{place:k===void 0?void 0:D.nodes[k],sizes:w});let{dragging:A,draggable:j}=Ae(D,d,p),{panning:M,pan:N}=ye(`[data-map-node]`),{lit:P,on:F,onLines:L,lights:R}=je(D),z={family:c,expanded:o,isMoved:O.some(e=>Object.hasOwn(d,e.id)),showFamily:h,expand:g,tidy:()=>{p({},!0)}},[B,V]=(0,Y.useState)(),H=Ne(O.find(e=>e.id===B),r,z),U=o?Ie:Fe,G=O.find(e=>Q(e,n))?.id,K=e=>L.has(e.link)?2:+(e.from===G||e.to===G),re=[...D.lines].sort((e,t)=>K(e)-K(t));return(0,Z.jsxs)(`div`,{className:`studio-map-frame`,role:`none`,onKeyDown:e=>{e.key===`Escape`&&c!==void 0&&(e.target.closest(`[role="menu"]`)||(e.stopPropagation(),h(void 0)))},children:[(0,Z.jsx)(u,{className:`studio-map-scroll`,axis:`both`,role:`region`,label:`Map`,height:`100%`,overscroll:`allow`,children:(0,Z.jsx)(ee,{items:H,label:`Map actions`,"data-map-field":``,children:(0,Z.jsxs)(`div`,{ref:S,className:`studio-map`,"data-lit":P===void 0||A!==void 0?void 0:``,"data-panning":M?``:void 0,onPointerDown:N,onContextMenuCapture:e=>{V(e.target.closest(`[data-map-node]`)?.dataset.mapNode)},style:{"--map-width":`${String(D.width)}px`,"--map-height":`${String(D.height)}px`,"--map-slot":`${String(w.node.width)}px`,"--map-line":`${String(w.card.row)}px`},children:[(0,Z.jsx)(`svg`,{className:`studio-map-lines`,width:D.width,height:D.height,"aria-hidden":`true`,children:re.map(({link:e,from:t,to:n,d:r})=>(0,Z.jsx)(`path`,{className:`map-line`,d:r,"data-kind":e.kind,"data-on":L.has(e)?``:void 0,"data-open":t===G||n===G?``:void 0},`${e.kind}:${e.from}:${e.to}`))}),D.headings.map(({label:e,x:t,y:n})=>(0,Z.jsx)(`div`,{className:`studio-map-heading`,style:{left:t,top:n},children:(0,Z.jsx)(s,{type:`supporting`,color:`secondary`,weight:`semibold`,children:e})},e)),O.map(e=>{let t=D.nodes[e.id];return t&&(0,Z.jsx)(U,{node:e,place:t,joins:ie(b,e.id),selected:n,on:F,isFound:y.includes(e.id),isDragging:A===e.id,onOpen:r,lights:R,drag:j(e.id)},e.id)})]})})}),x&&(0,Z.jsx)(f,{className:`studio-map-nothing`,children:(0,Z.jsx)(C,{headingLevel:2,icon:(0,Z.jsx)(i,{icon:m,size:`lg`}),title:`Nothing matches`})}),(0,Z.jsx)(Pe,{actions:z,query:_,onQuery:v,onClose:a})]})}export{Le as StudioMap};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{g as r}from"./fieldParts-Cs6Amprh.js";import{t as i}from"./Icon-ZfFwTt8n.js";import{r as a,t as o}from"./IconButton-CG5klqF1.js";import{t as s}from"./Text-BsiAsowd.js";import{t as c}from"./createReactComponent-CZwsv6DD.js";import{n as l,t as u}from"./ScrollableArea-C8AVuqnt.js";import{n as d,t as f}from"./Center-nHS1JSux.js";import{t as p}from"./IconEye-BB5aY-wQ.js";import{t as m}from"./IconSearch-BTx66a40.js";import{r as h,s as g,t as _}from"./tree-2VeaKg0m.js";import{P as v,i as y}from"./workspace-Cno6Ge26.js";import{a as b,n as x,r as S}from"./studio-session-yEqFQo5o.js";import{t as C}from"./EmptyState-C8W4JKBZ.js";import{t as ee}from"./ContextMenu-BGP2gdee.js";import{Dt as w,Et as T,K as E,d as D,dt as O,ft as k,ht as A,lt as j,mt as M,n as N,pt as P,u as F,ut as I,z as L}from"./index-Dajtrq_Z.js";var R=c(`outline`,`arrows-maximize`,`ArrowsMaximize`,[[`path`,{d:`M16 4l4 0l0 4`,key:`svg-0`}],[`path`,{d:`M14 10l6 -6`,key:`svg-1`}],[`path`,{d:`M8 20l-4 0l0 -4`,key:`svg-2`}],[`path`,{d:`M4 20l6 -6`,key:`svg-3`}],[`path`,{d:`M16 20l4 0l0 -4`,key:`svg-4`}],[`path`,{d:`M14 14l6 6`,key:`svg-5`}],[`path`,{d:`M8 4l-4 0l0 4`,key:`svg-6`}],[`path`,{d:`M4 4l6 6`,key:`svg-7`}]]),z=c(`outline`,`arrows-minimize`,`ArrowsMinimize`,[[`path`,{d:`M5 9l4 0l0 -4`,key:`svg-0`}],[`path`,{d:`M3 3l6 6`,key:`svg-1`}],[`path`,{d:`M5 15l4 0l0 4`,key:`svg-2`}],[`path`,{d:`M3 21l6 -6`,key:`svg-3`}],[`path`,{d:`M19 9l-4 0l0 -4`,key:`svg-4`}],[`path`,{d:`M15 9l6 -6`,key:`svg-5`}],[`path`,{d:`M19 15l-4 0l0 4`,key:`svg-6`}],[`path`,{d:`M15 15l6 6`,key:`svg-7`}]]),B=c(`outline`,`focus-2`,`Focus2`,[[`path`,{d:`M11.5 12a.5 .5 0 1 0 1 0a.5 .5 0 1 0 -1 0`,fill:`currentColor`,key:`svg-0`}],[`path`,{d:`M5 12a7 7 0 1 0 14 0a7 7 0 1 0 -14 0`,key:`svg-1`}],[`path`,{d:`M12 3l0 2`,key:`svg-2`}],[`path`,{d:`M3 12l2 0`,key:`svg-3`}],[`path`,{d:`M12 19l0 2`,key:`svg-4`}],[`path`,{d:`M19 12l2 0`,key:`svg-5`}]]),V=c(`outline`,`layout-grid`,`LayoutGrid`,[[`path`,{d:`M4 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-0`}],[`path`,{d:`M14 5a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-1`}],[`path`,{d:`M4 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-2`}],[`path`,{d:`M14 15a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v4a1 1 0 0 1 -1 1h-4a1 1 0 0 1 -1 -1l0 -4`,key:`svg-3`}]]);function H(e,t,n){let r=e=>{let r=t.flatMap(({from:t,to:n})=>t===e.id?[n]:n===e.id?[t]:[]).flatMap(e=>n.get(e)??[]);return r.length===0?1/0:r.reduce((e,t)=>e+t,0)/r.length},i=new Map(e.map(e=>[e.id,r(e)])),a=e=>i.get(e.id)??1/0;return[...e].sort((e,t)=>a(e)===a(t)?0:a(e)-a(t))}function U(e,t,n){return t===`models`?e.modelBindings.map(e=>e.modelId||`New model`).join(`, `):t===`tools`?String(e.tools.allow.filter(e=>n.has(e)).length):t===`outputs`?e.outputs.mode:``}function W(e,t=[]){let n=[],r=new Map(e.agents.map(e=>[e.key,y(e.key)])),i=new Map(e.toolSpecs.map(e=>[e.key,g(e.key)])),a=v(e),o=e.agents.map((e,t)=>{let{agentId:n,profileType:r,handle:o}=e.identity,s=r||`text`;return{id:y(e.key),kind:`agent`,label:n||`New agent`,note:o?`${s} · ${o}`:s,opens:y(e.key),type:s,rows:(a.agents[t]?.children??[]).map(t=>({id:t.id,label:t.label,note:U(e,t.ref.facet,i),opens:t.id,type:t.ref.facet}))}}),s=new Set(o.flatMap(e=>e.rows??[]).map(e=>e.id)),c=(e,t)=>{let n=y(e,t);return s.has(n)?n:y(e)},l=new Map,u=new Map(e.providers.map(e=>[e.id,e.definition])),d=new Map;for(let t of e.agents){let e=c(t.key,`models`);for(let i of t.modelBindings){let a=`model:${i.provider}:${i.apiId}:${i.modelId}`,o=h(i.provider);l.has(o)||l.set(o,{id:o,kind:`provider`,label:i.provider,note:``,opens:u.has(i.provider)?o:y(t.key,_(i.key))});let s=y(t.key,_(i.key)),c=d.get(a);c?c.holds?.push(s):(d.set(a,{id:a,kind:`model`,label:i.modelId||`New model`,note:i.apiId,type:u.get(i.provider),opens:s,holds:[s]}),n.push({from:o,to:a,kind:`serves`})),n.some(t=>t.from===a&&t.to===e)||n.push({from:a,to:e,kind:`runs`});let f=i.compactWith?r.get(i.compactWith):void 0,p=n.some(t=>t.kind===`summarised`&&t.from===e);f&&f!==y(t.key)&&!p&&n.push({from:e,to:f,kind:`summarised`})}for(let e of t.tools.allow){let r=i.get(e);r&&n.push({from:c(t.key,`tools`),to:r,kind:`allows`})}}let f=e.toolSpecs.map(e=>{let t=g(e.key),i=e.toolType===`agent`?r.get(e.agentKey??``):void 0;return i&&n.push({from:t,to:i,kind:`asks`}),{id:t,kind:`tool`,label:e.toolName||`New tool`,note:e.description,opens:t,type:e.toolType}}),p=t.map(t=>{let{setting:i,facet:a}=t,o=`shared:${i.file}:${i.name}`,s=t.agents.filter(e=>r.has(e)),l=i.tools.flatMap(t=>{let n=e.toolSpecs.find(e=>e.toolName===t);return n?[g(n.key)]:[]});for(let e of s)n.push({from:o,to:a?c(e,a):y(e),kind:`sets`});for(let e of l)n.push({from:o,to:e,kind:`sets`});return{id:o,kind:`shared`,label:i.label,note:`${i.name} · ${i.file}:${String(i.line)}`,opens:E(t)??l[0],type:a}}),m=new Map(o.flatMap((e,t)=>[e.id,...(e.rows??[]).map(e=>e.id)].map(e=>[e,t])));for(let e of d.values())[...d.values()].some(t=>t!==e&&t.label===e.label)&&e.note&&(e.long=`${e.label} · ${e.note}`);let b=H([...d.values()],n,m),x=new Map(b.map((e,t)=>[e.id,t])),S=(...e)=>e.filter(e=>e.nodes.length>0);return{columns:[S({label:`Providers`,nodes:H([...l.values()],n,x)}),S({label:`Shared settings`,nodes:H(p,n,m)},{label:`Models`,nodes:b}),S({label:`Profiles`,nodes:o}),S({label:`Tools`,nodes:H(f,n,m)})].filter(e=>e.length>0),links:n}}function G(e){let t=e.columns.flat().flatMap(e=>e.nodes);return new Map(t.flatMap(e=>[e.id,...(e.rows??[]).map(e=>e.id)].map(t=>[t,e])))}function K(e){let t=G(e);return e.links.flatMap(e=>{let n=t.get(e.from)?.id,r=t.get(e.to)?.id;return n!==void 0&&r!==void 0?[{link:e,from:n,to:r}]:[]})}function te(e,t){let n=t.trim().toLowerCase();return n===``?[]:e.columns.flat().flatMap(e=>e.nodes).filter(e=>[e.label,e.long??``,e.note].some(e=>e.toLowerCase().includes(n))).map(e=>e.id)}function ne(e,t){let n=typeof t==`string`?[t]:t,r=K(e),i=(e,t)=>{let i=new Set(n),a=[...n];for(let n=a.pop();n!==void 0;n=a.pop())for(let o of r)o[e]!==n||i.has(o[t])||(i.add(o[t]),a.push(o[t]));return i},a=new Set([...i(`to`,`from`),...i(`from`,`to`)]),o=e.columns.map(e=>e.map(e=>({...e,nodes:e.nodes.filter(e=>a.has(e.id))})).filter(e=>e.nodes.length>0)).filter(e=>e.length>0),s=new Set(r.filter(({from:e,to:t})=>a.has(e)&&a.has(t)).map(({link:e})=>e));return{columns:o,links:e.links.filter(e=>s.has(e))}}var re={serves:[`Serves`,`Served by`],sets:[`Sets`,`Set by`],runs:[`Runs`,`Runs on`],allows:[`Allows`,`Allowed by`],asks:[`Asks`,`Asked by`],summarised:[`Summarised by`,`Summarises for`]};function ie(e,t){let n=G(e),r=new Map;for(let{link:i,from:a,to:o}of K(e)){if(a!==t&&o!==t)continue;let e=re[i.kind][a===t?0:1],s=n.get(a===t?o:a)?.label;s!==void 0&&r.set(e,[...r.get(e)??[],s])}return[...r].map(([e,t])=>`${e} ${t.join(`, `)}.`).join(` `)}function ae(e){return e.kind===`tool`||e.kind===`shared`?2:1}var oe=24,q=8,J=16;function se(e,t,n){let r=new Map,i=(e,t)=>`${e}:${String(t)}`;return K(e).flatMap(({link:e})=>{let[a,o]=[t(e.from),t(e.to)];if(a===void 0||o===void 0||Math.abs(a-o)<n)return[];let s=a<o?1:-1;for(let t of[i(e.from,s),i(e.to,-s)])r.set(t,(r.get(t)??0)+1);return[{link:e,way:s}]}).map(({link:e,way:t})=>{let[n,a]=[i(e.from,t),i(e.to,-t)],o=(r.get(n)??0)>=(r.get(a)??0);return{link:e,way:t,leaves:o,hub:o?n:a}})}function ce(e,t,n={}){let{node:r,card:i,columnGap:a,rowGap:o,heading:s,groupGap:c,padding:l,lineGap:u}=t,{moved:d={},widths:f={},detail:p=!1}=n,m=new Map;e.columns.forEach((e,t)=>{for(let n of e)for(let e of n.nodes)if(!Object.hasOwn(d,e.id))for(let n of[e.id,...(e.rows??[]).map(e=>e.id)])m.set(n,t)});let h=t=>{let n={},a=[],u=[],m=new Map,h=0,g=0;return e.columns.forEach((e,_)=>{let v=t[_]??l,y=l;e.forEach((e,t)=>{t>0&&(y+=c),a.push({label:e.label,x:v,y}),u.push({id:`heading:${_}:${t}`,x:v,y,width:r.width,height:s}),y+=s;for(let t of e.nodes){let e=p?t.rows??[]:[],a=e.length>0||t.note!==``,s=p&&(e.length>0||ae(t)===1)?i.head:r.height,c=p&&!a?i.row:s,l=e.length>0?i.head+e.length*i.row+i.foot:c,_=Math.min(f[t.id]??r.width,r.width),b=Object.hasOwn(d,t.id)?d[t.id]:void 0,x=b?{x:Math.max(b.x,0),y:Math.max(b.y,0)}:{x:v,y};n[t.id]={...x,height:l},u.push({id:t.id,...x,width:_,height:l});let S={left:x.x,right:x.x+_,y:x.y+(p?i.row:c)/2};m.set(t.id,S);for(let[e,n]of(t.rows??[]).entries())m.set(n.id,p?{...S,y:x.y+i.head+e*i.row+i.row/2}:S);h=Math.max(h,x.x+r.width),g=Math.max(g,x.y+l),y+=l+o}y-=o})}),{nodes:n,headings:a,boxes:u,ports:m,right:h,bottom:g}},g=(e,t,n)=>{let{way:i,leaves:a}=e,o={x:i>0?t.right+u:t.left-u,y:t.y},s={x:i>0?n.left-u:n.right+u,y:n.y},c=i>0?Math.max(t.left+r.width,t.right)+u:o.x,l=i>0?s.x:Math.max(n.left+r.width,n.right)+u,d=a?l:c,f=a?-i:i;return{start:o,end:s,side:d,into:f,room:Math.abs(l-c),strip:`${String(d)}:${String(f)}`}},_=t=>{let n=new Map(se(e,e=>t.get(e)?.left,r.width).map(e=>[e.link,e])),i=new Map;for(let e of n.values()){let n=t.get(e.link.from),r=t.get(e.link.to);if(!n||!r||n.y===r.y)continue;let{strip:a}=g(e,n,r),o=i.get(a)??new Map,s=e.leaves?e.link.to:e.link.from,c=o.get(e.hub)??{y:e.leaves?n.y:r.y,joins:[],beside:s};c.joins.push(e.leaves?r.y:n.y),i.set(a,o.set(e.hub,c))}let a=new Map,o=new Map;for(let[e,t]of i){let n=e=>e.reduce((e,t)=>e+t,0)/e.length,r=[...t.values()],i=n(r.flatMap(e=>e.joins))>=n(r.map(e=>e.y)),s=[];for(let[n,r]of[...t].sort(([,e],[,t])=>i?e.y-t.y:t.y-e.y)){let t=Math.min(r.y,...r.joins)-q,i=Math.max(r.y,...r.joins)+q,o=s.findIndex(e=>e.every(e=>i<e.low||t>e.high)),c=o<0?s.length:o;s[c]=[...s[c]??[],{low:t,high:i}],a.set(`${e}:${n}`,c)}let[c]=r;c&&o.set(e,{count:s.length,beside:c.beside,into:Number(e.split(`:`)[1])})}return{spans:n,rails:a,held:o}},v=e.columns.map((e,t)=>l+t*(r.width+a)),y=e.columns.map(()=>0);for(let{count:e,beside:t,into:n}of _(h(v).ports).held.values()){let r=m.get(t);if(r===void 0)continue;let i=n>0?r:r-1;i>=0&&i<y.length&&(y[i]=(y[i]??0)+e+1)}let b=[l];for(let[e,t]of y.entries())b.push((b[e]??l)+r.width+Math.max(a,t*J));let x=h(b),{nodes:S,headings:C,boxes:ee,ports:w}=x,{right:T,bottom:E}=x,{spans:D,rails:O}=_(w),k=a/2,j=Math.max(o/2,u),N=[],P=new Map,F=Math.max(a,...y.map(e=>e*J)),I=K(e).flatMap(({link:e,from:t,to:n})=>{let i=w.get(e.from),o=w.get(e.to);if(!i||!o)return[];let s=ee.filter(e=>e.id!==t&&e.id!==n);if(Math.abs(i.left-o.left)<r.width){let r=i.right+u,a=o.right+u,c=s.filter(e=>e.y<Math.max(i.y,o.y)&&e.y+e.height>Math.min(i.y,o.y)&&e.x<Math.max(r,a)+k&&e.x+e.width>Math.min(i.left,o.left)),l=Math.max(r,a,...c.map(e=>e.x+e.width))+k;return T=Math.max(T,l),[{link:e,from:t,to:n,d:M({x:r,y:i.y},{x:a,y:o.y},l).d}]}let c=D.get(e);if(!c)return[];let{way:l,leaves:d,hub:f}=c,{start:p,end:m,side:h,into:_,room:v,strip:y}=g(c,i,o),b=h+_*Math.min((1+(O.get(`${y}:${f}`)??0))*J,Math.max(v-J,0)),x=v<32?M(p,m):A(p,m,b,q),S=(e,t)=>t>e.y-j&&t<e.y+e.height+j,C=Math.abs(m.x-p.x)<F+a?[]:s.filter(e=>Array.from({length:23},(e,t)=>x.at((t+1)/oe)).some(t=>t.x>e.x&&t.x<e.x+e.width&&S(e,t.y)));if(C.length===0)return[{link:e,from:t,to:n,d:x.d}];let[I,L]=[Math.min(p.x,m.x),Math.max(p.x,m.x)],R=e=>{let t=[...C];for(;;){let n=e<0?Math.min(...t.map(e=>e.y))-j:Math.max(...t.map(e=>e.y+e.height))+j,r=[...s,...N].filter(e=>!t.includes(e)&&e.x<L&&e.x+e.width>I&&S(e,n));if(r.length===0)return n;t.push(...r)}},z=e=>Math.abs(i.y-e)+Math.abs(o.y-e),B=`${f}:${y}`,V=P.get(B)??(()=>{let[e,t]=[R(-1),R(1)],n=e>=0&&z(e)<=z(t)?e:t;return N.push({id:``,x:I,y:n-q+j,width:L-I,height:2*(q-j)}),P.set(B,n),n})();E=Math.max(E,V);let H=d?p.x+l*J:b,U=d?b:m.x-l*J,W={x:(H+U)/2,y:V};return[{link:e,from:t,to:n,d:A(p,W,H,q).d+A(W,m,U,q).d.replace(/^M \S+ \S+/,``)}]});return{width:Math.max((b[Math.max(e.columns.length-1,0)]??l)+r.width,T)+l,height:Math.max(E,l)+l,nodes:S,headings:C,lines:I}}var Y=e(n(),1),le={tokens:{},detail:{},expanded:!1},X=e=>e===void 0?`${x}.map`:`${x}.map.project:${e}`;function ue(e){if(!S(e))return{};let t={};for(let[n,r]of Object.entries(e))S(r)&&typeof r.x==`number`&&typeof r.y==`number`&&(t[n]={x:r.x,y:r.y});return t}function de(e){try{let t=JSON.parse(b()?.getItem(X(e))??`null`);return S(t)?{tokens:ue(t.tokens),detail:ue(t.detail),expanded:t.expanded===!0,...typeof t.family==`string`?{family:t.family}:{}}:le}catch{return le}}function fe(e,t){let{tokens:n,detail:r,expanded:i,family:a}=t,o=Object.keys(n).length===0&&Object.keys(r).length===0&&!i&&a===void 0;try{o?b()?.removeItem(X(e)):b()?.setItem(X(e),JSON.stringify(t))}catch{}}function pe(e){for(let t=e.parentElement;t;t=t.parentElement){let{overflowX:e,overflowY:n}=getComputedStyle(t);if(/auto|scroll/.test(`${e} ${n}`))return t}}function me(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return{left:n.left-r.left+t.scrollLeft,top:n.top-r.top+t.scrollTop}}var he=(e,t)=>Math.min(Math.max(e,0),Math.max(t,0));function ge(e,t){let n=0,r=120,i=()=>{--r;let a=pe(e);if(a&&a.scrollWidth>a.clientWidth){let e=t(a),n=he(e.left,a.scrollWidth-a.clientWidth),r=he(e.top,a.scrollHeight-a.clientHeight);if(a.scrollTo({left:n,top:r,behavior:`instant`}),Math.abs(a.scrollLeft-n)<1&&Math.abs(a.scrollTop-r)<1)return}r>0&&(n=requestAnimationFrame(i))};return i(),()=>{cancelAnimationFrame(n)}}var _e=e=>e.button===0&&e.pointerType!==`touch`;function ve(e,t,n){let{pointerId:r,clientX:i,clientY:a}=e,o=e=>{e.pointerId===r&&t(e.clientX-i,e.clientY-a)},s=e=>{e.pointerId===r&&(globalThis.removeEventListener(`pointermove`,o),globalThis.removeEventListener(`pointerup`,s),globalThis.removeEventListener(`pointercancel`,s),n(e.type===`pointerup`))};globalThis.addEventListener(`pointermove`,o),globalThis.addEventListener(`pointerup`,s),globalThis.addEventListener(`pointercancel`,s)}function ye(e){let[t,n]=(0,Y.useState)(!1);return{panning:t,pan:t=>{if(!_e(t)||t.target.closest(e))return;let r=pe(t.currentTarget);if(!r)return;let{scrollLeft:i,scrollTop:a}=r;n(!0),ve(t,(e,t)=>{r.scrollTo({left:i-e,top:a-t,behavior:`instant`})},()=>{n(!1)})}}}var Z=t(),be={node:{width:240,height:24},card:{head:60,row:28,foot:4},columnGap:96,rowGap:6,heading:24,groupGap:16,padding:24,lineGap:8},xe={...be,node:{width:240,height:84}},Se=28;function Ce(e){return e.length>Se?`${e.slice(0,27)}…`:e}function we({kind:e,type:t,note:n}){return(e===`agent`?k(t):void 0)||(e===`tool`?P(t??``):e===`model`&&t===`typesafe`?F:e===`model`?D(n)??N.modelBinding:e===`provider`?w:e===`shared`&&t&&Object.hasOwn(N,t)?N[t]:e===`agent`?O.text:T)}function Te(e){return Object.hasOwn(N,e)?N[e]:T}function Q(e,t){return e.kind===`agent`?t===e.id||t.startsWith(`${e.id}/`):e.kind===`model`?e.holds?.includes(t)??!1:e.kind===`tool`&&t===e.id}var Ee=4,De=24,Oe={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};function ke(e){let t=L()?.name,[n,r]=(0,Y.useState)(()=>de(t)),i=e=>{r(e),fe(t,e)},{expanded:a}=n,o=e.columns.flat().some(e=>e.nodes.some(e=>e.id===n.family))?n.family:void 0,s=(0,Y.useMemo)(()=>o===void 0?e:ne(e,o),[e,o]),[c,l]=(0,Y.useState)({}),u=a?`detail`:`tokens`;return{expanded:a,family:o,map:s,moved:o===void 0?n[u]:c,put(e,t){o===void 0?t?i({...n,[u]:e}):r({...n,[u]:e}):l(e)},showFamily(e){l({});let{tokens:t,detail:r}=n;i({tokens:t,detail:r,expanded:a,...e===void 0?{}:{family:e}})},expand(){i({...n,expanded:!a})}}}function Ae(e,t,n){let r=(0,Y.useRef)(!1),[i,a]=(0,Y.useState)();return{dragging:i,draggable:i=>({onPointerDown:o=>{r.current=!1;let s=e.nodes[i];if(!s||!_e(o))return;let c;ve(o,(e,r)=>{!c&&Math.hypot(e,r)<Ee||(c||a(i),c={...t,[i]:{x:Math.max(s.x+e,0),y:Math.max(s.y+r,0)}},n(c,!1))},e=>{c&&(r.current=e,globalThis.setTimeout(()=>{r.current=!1},0),a(void 0),n(c,!0))})},onClickCapture:e=>{r.current&&(r.current=!1,e.stopPropagation(),e.preventDefault())},onKeyDown:r=>{let a=r.altKey?Oe[r.key]:void 0,o=e.nodes[i];if(!a||!o)return;r.preventDefault();let s=Math.max(o.x+a.x*De,0),c=Math.max(o.y+a.y*De,0);n({...t,[i]:{x:s,y:c}},!0)}})}}function je(e){let[t,n]=(0,Y.useState)(),[r,i]=(0,Y.useMemo)(()=>{let n=new Set,r=new Set;if(t===void 0)return[n,r];n.add(t);for(let{link:i,from:a,to:o}of e.lines)if([i.from,i.to,a,o].includes(t)){r.add(i);for(let e of[i.from,i.to,a,o])n.add(e)}return[n,r]},[e,t]);return{lit:t,on:r,onLines:i,lights:e=>({onPointerEnter:()=>{n(e)},onPointerLeave:()=>{n(void 0)},onFocus:()=>{n(e)},onBlur:()=>{n(void 0)}})}}function Me(e,t,n){let r=(0,Y.useRef)(n.place);r.current=n.place;let{sizes:i}=n;(0,Y.useEffect)(()=>{let n=e.current;if(!n)return;let a=r.current,o=t===void 0?a:void 0;return ge(n,e=>{let{left:t,top:r}=me(n,e);return o===void 0?{left:t,top:r}:{left:t+o.x+i.node.width/2-e.clientWidth/2,top:r+o.y+o.height/2-e.clientHeight/2}})},[e,t,i])}function Ne(e,t,n){let{family:r,expanded:i,isMoved:a,showFamily:o,expand:s,tidy:c}=n,l=[];e&&e.id!==r&&l.push({label:`Show only its family`,icon:B,onClick:()=>{o(e.id)}});let u=e?.opens;u!==void 0&&l.push({label:`Open`,icon:d,onClick:()=>{t(u)}}),e&&l.push({type:`divider`});let f={label:`Show everything`,icon:p,onClick:()=>{o(void 0)}};return[...l,...r===void 0?[]:[f],{label:i?`Collapse`:`Expand`,icon:i?z:R,onClick:s},{label:`Tidy`,icon:V,isDisabled:!a,onClick:c}]}function Pe({actions:e,query:t,onQuery:n,onClose:s}){let{family:c,expanded:u,isMoved:d,showFamily:f,expand:h,tidy:g}=e;return(0,Z.jsxs)(`div`,{className:`studio-map-tools`,children:[(0,Z.jsx)(l,{label:`Search the map`,isLabelHidden:!0,size:`sm`,width:200,placeholder:`Search`,startIcon:m,hasClear:!0,value:t,onChange:n}),c!==void 0&&(0,Z.jsx)(a,{label:`Show everything`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:p,size:`sm`}),onClick:()=>{f(void 0)}}),d&&(0,Z.jsx)(a,{label:`Tidy`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:V,size:`sm`}),onClick:g}),(0,Z.jsx)(o,{label:u?`Collapse`:`Expand`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:u?z:R,size:`sm`}),tooltip:u?`Show each node as a token`:`Show sections and descriptions`,onClick:h}),(0,Z.jsx)(o,{label:`Close map`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:r,size:`sm`}),tooltip:`Close the map`,onClick:s})]})}function $({node:e,on:t,isFound:n,isDragging:r}){let i=t.has(e.id)||(e.rows??[]).some(e=>t.has(e.id));return{"data-map-node":e.id,"data-on":i?``:void 0,"data-found":n?``:void 0,"data-dragging":r?``:void 0}}function Fe(e){let{node:t,place:n,joins:r,selected:i,onOpen:a,lights:o,drag:s}=e,{opens:c}=t,l=Q(t,i);return(0,Z.jsx)(j,{id:t.id,label:Ce(t.long??t.label),icon:we(t),x:n.x,y:n.y+n.height/2,color:l?`blue`:void 0,description:[t.note,r].filter(Boolean).join(`. `)||void 0,onOpen:c===void 0?void 0:()=>{a(c)},title:(t.long??t.label).length>Se?t.long??t.label:void 0,"aria-current":l?`true`:void 0,...$(e),...o(t.id),...s})}function Ie(e){let{node:t,place:n,joins:r,selected:a,on:o,onOpen:c,lights:l,drag:u}=e,{opens:d}=t,f=t.rows??[],p={left:n.x,top:n.y,height:n.height},m=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{className:`studio-map-name`,children:[(0,Z.jsx)(i,{icon:we(t),size:`sm`}),(0,Z.jsx)(s,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:t.label})]}),t.note&&(0,Z.jsx)(s,{type:`supporting`,maxLines:f.length>0?1:ae(t),hasTruncateTooltip:!1,className:`studio-map-note`,children:t.note})]}),h={type:`button`,title:t.note||void 0,"aria-description":r||void 0,disabled:d===void 0,onClick:()=>{d!==void 0&&c(d)},...l(t.id)};return f.length===0?(0,Z.jsx)(`button`,{...h,...u,...$(e),className:`studio-map-node`,"data-map-token":t.id,style:p,"aria-current":Q(t,a)?`true`:void 0,children:m}):(0,Z.jsxs)(`div`,{className:`studio-map-card`,"data-map-token":t.id,style:p,"data-open":Q(t,a)?``:void 0,...$(e),...u,children:[(0,Z.jsx)(`button`,{...h,className:`studio-map-head`,"aria-current":a===t.id?`true`:void 0,children:m}),f.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`studio-map-row`,"aria-current":a===e.id?`true`:void 0,"data-on":o.has(e.id)?``:void 0,onClick:()=>{c(e.opens)},...l(e.id),children:[(0,Z.jsx)(i,{icon:Te(e.type),size:`sm`}),(0,Z.jsx)(s,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:e.label}),e.note&&(0,Z.jsx)(s,{type:`supporting`,maxLines:1,justify:`end`,hasTruncateTooltip:!1,className:`studio-map-row-note`,children:e.note})]},e.id))]})}function Le({workspace:e,shared:t,selected:n,onOpen:r,onClose:a}){let{expanded:o,family:c,map:l,moved:d,put:p,showFamily:h,expand:g}=ke((0,Y.useMemo)(()=>W(e,t),[e,t])),[_,v]=(0,Y.useState)(``),y=(0,Y.useMemo)(()=>te(l,_),[l,_]),b=(0,Y.useMemo)(()=>_.trim()===``?l:ne(l,y),[l,_,y]),x=_.trim()!==``&&y.length===0,S=(0,Y.useRef)(null),w=o?xe:be,T=(0,Y.useMemo)(()=>({map:b,expanded:o}),[b,o]),E=I(S,T),D=(0,Y.useMemo)(()=>ce(b,w,{moved:d,widths:E,detail:o}),[b,w,o,d,E]),O=b.columns.flat().flatMap(e=>e.nodes),k=O.find(e=>Q(e,n))?.id;Me(S,c,{place:k===void 0?void 0:D.nodes[k],sizes:w});let{dragging:A,draggable:j}=Ae(D,d,p),{panning:M,pan:N}=ye(`[data-map-node]`),{lit:P,on:F,onLines:L,lights:R}=je(D),z={family:c,expanded:o,isMoved:O.some(e=>Object.hasOwn(d,e.id)),showFamily:h,expand:g,tidy:()=>{p({},!0)}},[B,V]=(0,Y.useState)(),H=Ne(O.find(e=>e.id===B),r,z),U=o?Ie:Fe,G=O.find(e=>Q(e,n))?.id,K=e=>L.has(e.link)?2:+(e.from===G||e.to===G),re=[...D.lines].sort((e,t)=>K(e)-K(t));return(0,Z.jsxs)(`div`,{className:`studio-map-frame`,role:`none`,onKeyDown:e=>{e.key===`Escape`&&c!==void 0&&(e.target.closest(`[role="menu"]`)||(e.stopPropagation(),h(void 0)))},children:[(0,Z.jsx)(u,{className:`studio-map-scroll`,axis:`both`,role:`region`,label:`Map`,height:`100%`,overscroll:`allow`,children:(0,Z.jsx)(ee,{items:H,label:`Map actions`,"data-map-field":``,children:(0,Z.jsxs)(`div`,{ref:S,className:`studio-map`,"data-lit":P===void 0||A!==void 0?void 0:``,"data-panning":M?``:void 0,onPointerDown:N,onContextMenuCapture:e=>{V(e.target.closest(`[data-map-node]`)?.dataset.mapNode)},style:{"--map-width":`${String(D.width)}px`,"--map-height":`${String(D.height)}px`,"--map-slot":`${String(w.node.width)}px`,"--map-line":`${String(w.card.row)}px`},children:[(0,Z.jsx)(`svg`,{className:`studio-map-lines`,width:D.width,height:D.height,"aria-hidden":`true`,children:re.map(({link:e,from:t,to:n,d:r})=>(0,Z.jsx)(`path`,{className:`map-line`,d:r,"data-kind":e.kind,"data-on":L.has(e)?``:void 0,"data-open":t===G||n===G?``:void 0},`${e.kind}:${e.from}:${e.to}`))}),D.headings.map(({label:e,x:t,y:n})=>(0,Z.jsx)(`div`,{className:`studio-map-heading`,style:{left:t,top:n},children:(0,Z.jsx)(s,{type:`supporting`,color:`secondary`,weight:`semibold`,children:e})},e)),O.map(e=>{let t=D.nodes[e.id];return t&&(0,Z.jsx)(U,{node:e,place:t,joins:ie(b,e.id),selected:n,on:F,isFound:y.includes(e.id),isDragging:A===e.id,onOpen:r,lights:R,drag:j(e.id)},e.id)})]})})}),x&&(0,Z.jsx)(f,{className:`studio-map-nothing`,children:(0,Z.jsx)(C,{headingLevel:2,icon:(0,Z.jsx)(i,{icon:m,size:`lg`}),title:`Nothing matches`})}),(0,Z.jsx)(Pe,{actions:z,query:_,onQuery:v,onClose:a})]})}export{Le as StudioMap};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{n as r,t as i}from"./SegmentedControlItem-BLuJOusN.js";import{t as a}from"./VStack-CkVMcNiK.js";import{A as o,_ as s,a as c,o as l,s as u,v as d}from"./browser-transport-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{n as r,t as i}from"./SegmentedControlItem-BLuJOusN.js";import{t as a}from"./VStack-CkVMcNiK.js";import{A as o,_ as s,a as c,o as l,s as u,v as d}from"./browser-transport-DYgEItHi.js";import{r as f}from"./IconButton-CG5klqF1.js";import{t as p}from"./Text-BsiAsowd.js";import{n as m,t as h}from"./labels-provider-BSiD6Lrb.js";import{a as g,t as _}from"./Banner-C4MPbvft.js";import{t as v,v as ee}from"./studio-labels-C1pvg0JC.js";import{c as y}from"./host-patterns-C9RMP16Q.js";import{n as b}from"./trace-record-BjsBbPRl.js";import{n as x}from"./trace-schema-9CdEyG6Q.js";import{_ as S}from"./turn-client-Dy9-U9_L.js";import{a as C,i as w,o as T,t as E}from"./ConsoleFrame-BkzieVRC.js";import{C as D,a as O,b as k,g as te,x as ne}from"./index-Dajtrq_Z.js";var A=e=>typeof e==`object`&&!!e&&!Array.isArray(e),j=(e,t)=>e.attributes[t],M=(e,t)=>{let n=j(e,t);return typeof n==`string`?n:void 0};function N(e,t,n){let r=j(t,n);return r===void 0?void 0:b(e,r)}function P(e,t,n){let r=N(e,t,n);return r===void 0?``:typeof r==`string`?r:JSON.stringify(r)}function F(e,t,n){let r=N(e,t,n);return Array.isArray(r)?r.filter(A):[]}var I=e=>Array.isArray(e.parts)?e.parts.filter(A):[],L=e=>BigInt(String(e.startTimeUnixNano)),R=(e,t)=>{let n=L(e)-L(t);return n===0n?0:n<0n?-1:1},re=e=>`content_sha256`in e||`json_sha256`in e;function z(e){let t=e.arguments;if(A(t))return t;if(typeof t!=`string`)return{};try{let e=JSON.parse(t);return A(e)?e:{}}catch{return{}}}function B(e){if(typeof e.content==`string`){if(e.type===`reasoning`)return{type:`thought`,text:e.content};if(e.type===`text`)return{type:`text`,text:e.content}}}function ie(e){let t=[],n=[],r=!1;for(let i of e){let e=I(i),a=e.some(e=>e.type===`text`);for(let i of e){let e=B(i);re(i)?r=!0:e?t.push(e):i.type===`structured`&&!a?t.push({type:`text`,text:JSON.stringify(i.content)}):i.type===`tool_call`&&typeof i.name==`string`?(n.push(i.name),t.push({type:`tool`,tool:{name:i.name,callId:typeof i.id==`string`?i.id:`replay-${String(n.length)}`,arguments:z(i)}})):(i.type===`blob`||i.type===`uri`)&&(r=!0)}}return{events:t,calls:n,missing:r}}function ae(e,t){for(let n=e;n;n=t.get(n.parentSpanId??``)){let e=M(n,`gen_ai.agent.name`);if(M(n,`gen_ai.operation.name`)===`invoke_agent`&&e)return e}return``}var V=e=>M(e,`gen_ai.operation.name`);function oe(e){let t=new Map(e.spans.map(e=>[e.spanId,e]));return e.spans.filter(e=>V(e)===`chat`).toSorted(R).map(n=>{let r=ie(F(e,n,`gen_ai.output.messages`)),i=M(n,`theorem.stop.kind`)??`completed`;return{agent:ae(n,t),...r,events:[...r.events,{type:`done`,stop:{kind:i}}]}})}function se(e){return e.spans.filter(e=>V(e)===`execute_tool`).toSorted(R).map(t=>({name:M(t,`gen_ai.tool.name`)??``,result:P(e,t,`gen_ai.tool.call.result`),failed:M(t,`theorem.tool.outcome`)===`error`}))}function ce(e,t){let n=F(e,t,`gen_ai.input.messages`).findLast(e=>e.role===`user`),r=n?I(n):[];return{text:r.flatMap(e=>e.type===`text`&&typeof e.content==`string`?[e.content]:[]).join(`
|
|
2
2
|
`),attachments:r.filter(e=>e.type===`blob`||e.type===`uri`).length}}function le(e,t){let n=e.spans.filter(e=>V(e)===`execute_tool`).toSorted(R),r=new Set,i=(e,t)=>{let i=n.find(t=>M(t,`gen_ai.tool.call.id`)===e)??n.find(e=>!r.has(e)&&M(e,`gen_ai.tool.name`)===t);return i&&r.add(i),i},a=[];for(let n of F(e,t,`gen_ai.output.messages`))for(let t of I(n)){let n=B(t);if(n)a.push(n);else if(t.type===`tool_call`&&typeof t.name==`string`){let n=typeof t.id==`string`?t.id:`call-${String(a.length)}`;a.push(...ue(e,t.name,n,z(t),i))}}let o=P(e,t,`theorem.error.public`);t.status.code===`ERROR`&&a.push({type:`error`,errorKind:`internal`,error:o||t.status.message});let s=M(t,`theorem.stop.kind`)??`completed`;return a.push({type:`done`,stop:{kind:s}}),a}function ue(e,t,n,r,i){let a=i(n,t),o={type:`tool`,tool:{name:t,callId:n,arguments:r}};if(!a)return[o];let s=Number(L(a)/1000000n),c=P(e,a,`gen_ai.tool.call.result`);return[o,{type:`tool`,tool:{name:t,callId:n,at:s,...M(a,`theorem.tool.outcome`)===`error`?{phase:`error`,failure:{code:M(a,`theorem.tool.failure.code`)??`failed`,kind:`internal`,message:c}}:{phase:`complete`,output:H(c)}}}]}function H(e){try{return JSON.parse(e)}catch{return e}}var de=e=>e.spans.find(e=>!e.parentSpanId);function fe(e){let t=``,n,r=[];return e.forEach((e,i)=>{let a=de(e);if(!a||V(a)!==`invoke_agent`)return;let o=M(a,`gen_ai.agent.name`)??``;t||=o;let s=oe(e),c=se(e),l=r.at(-1);if(o!==t&&l){l.calls.push(...s),l.results.push(...c);return}n??=Number(L(a)/1000000n);let u=ce(e,a);r.push({...u,calls:s,results:c,blocks:S({text:u.text},le(e,a),{idPrefix:`recorded-${String(i)}`})})}),{agent:t,turns:r,...n===void 0?{}:{recordedAt:n}}}function pe(e){if(e.failed)throw Error(e.result);let t=H(e.result);return A(t)?t:{result:t}}var me=e=>{let t=e%100,n=t>=11&&t<=13?`th`:{1:`st`,2:`nd`,3:`rd`}[e%10]??`th`;return`${String(e)}${n}`};function he(e,t,n){if(!e)return`The profile asked the model a ${me(t+1)} time this turn; the recording answered ${String(t)}.`;if(e.missing)return`The recording does not hold all of this reply.`;let r=new Set((n.wireTools??[]).map(e=>e.name)),i=e.calls.find(e=>!r.has(e));return i&&`The recording calls ${i}, which the profile no longer offers.`}function ge(e,t,n){let r=0,i=new Map,a=new Map,o=t=>{let n=a.get(t);if(!n){n=new Map;for(let r of e.turns[t]?.results??[])n.set(r.name,[...n.get(r.name)??[],r]);a.set(t,n)}return n},s=t=>({async*complete(a){let o=e.turns[r]?.calls.filter(e=>e.agent===t)??[],s=`${String(r)} ${t}`,c=i.get(s)??0;i.set(s,c+1);let l=he(o[c],o.length,a);if(l)throw n({turn:r,call:c+1,reason:l}),new y(`request`,`Replay stopped: ${l}`);yield*o[c]?.events??[]}}),c=e=>()=>{let t=o(r).get(e)?.shift();if(!t)throw Error(`The recording has no further result for ${e}.`);return pe(t)},l=new Set(e.turns.flatMap(e=>e.results.map(e=>e.name)));return{provider:n=>s(n.id===t?e.agent:n.id),toolHandlers:Object.fromEntries([...l].map(e=>[e,c(e)])),startTurn:e=>{r=e}}}function U(e){return e.map(e=>{if(e.type===`agent`)return e;let{name:t,description:n,category:r,access:i,permission:a,loadTier:o,paths:s}=e;return{type:`function`,name:t,description:n,category:r,access:i,permission:a,loadTier:o,paths:s,inputSchema:e.inputSchema,outputSchema:e.outputSchema,...e.labels?{labels:e.labels}:{}}})}function _e(e){return{...e,customTools:U(e.customTools),...e.dependencies?{dependencies:e.dependencies.map(e=>({...e,customTools:U(e.customTools)}))}:{}}}function W(e){return e.turns.flatMap(e=>e.blocks)}function ve(e){let t;try{t=JSON.parse(e)}catch{throw new y(`request`,`This file is not JSON.`)}let n=Array.isArray(t)?t:[t];return n.map((e,t)=>{let r=x.safeParse(e);if(r.success)return r.data;let i=n.length>1?` (record ${String(t+1)})`:``;throw new y(`request`,`This file is not a Theorem trace${i}.`)})}var G=e(n(),1),K=t();function ye(e,t,n){return t?l(e,t,{conversationKey:O(),blocks:n}):s(e,n)}var q=e=>`turn ${String(e+1)}`;function J({iface:e,feed:t,trace:n,card:r,conversation:i}){let a=g(e,t,n);return(0,K.jsxs)(E,{inspector:a,maxWidth:`960px`,requestLabel:`Trace`,children:[r,i]})}function Y({iface:e,blocks:t,banner:n,chat:r}){let i=m();return(0,K.jsxs)(C,{label:`Conversation`,children:[n,(0,K.jsx)(D,{blocks:t,handle:i(`@theorem.agent.handle`,{handle:e.identity.handle}),labels:e.labels,streaming:r?.streaming,delivery:r?.delivery,answering:r?.answering,onToolDecision:r&&((e,t)=>{r.handleToolDecision(e,t)}),onAuthenticated:r&&((e,t)=>{r.handleAuthenticated(e,t)})})]})}function be({onImport:e}){let[t,n]=(0,G.useState)(),[r,i]=(0,G.useState)(!1);return(0,K.jsxs)(a,{gap:2,children:[(0,K.jsx)(ne,{label:`Trace file`,isLabelHidden:!0,mode:`dropzone`,accept:`application/json,.json`,isLoading:r,placeholder:`Drop a trace (.json) or choose a file`,value:null,changeAction:async t=>{let r=Array.isArray(t)?t[0]:t;if(r){i(!0);try{e({name:r.name,records:ve(await r.text())}),n(void 0)}catch(e){n(e instanceof Error?e.message:String(e))}finally{i(!1)}}},onChange:()=>void 0}),t?(0,K.jsx)(_,{status:`error`,title:t}):null]})}var xe=e=>e.recordedAt===void 0?void 0:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e.recordedAt);function Se({shown:e,onShown:t}){return(0,K.jsxs)(r,{label:`Show`,size:`sm`,value:e,onChange:e=>{t(e===`replayed`?`replayed`:`recorded`)},children:[(0,K.jsx)(i,{value:`recorded`,label:`Recorded`}),(0,K.jsx)(i,{value:`replayed`,label:`Replayed`})]})}function X({controls:e}){let{script:t,payload:n}=e,r=t.turns.length,i=[t.agent||`No agent`,`${String(r)} ${r===1?`turn`:`turns`}`,xe(t)];return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(a,{gap:0,children:[(0,K.jsx)(p,{type:`label`,maxLines:1,children:e.opened.name}),(0,K.jsx)(p,{type:`supporting`,color:`secondary`,maxLines:1,children:i.filter(Boolean).join(` · `)})]}),t.agent&&t.agent!==n.profile.id?(0,K.jsx)(_,{status:`info`,title:`Recorded with ${t.agent}; a replay runs through ${n.profile.id}.`}):null,r===0?(0,K.jsx)(_,{status:`info`,title:`This trace holds no conversation to replay.`}):null,(0,K.jsx)(k,{label:`Live tools`,description:`Run the profile's tools instead of answering them from the recording.`,value:e.liveTools,onChange:e.onLiveTools})]})}var Z=()=>void 0;function Q({onImport:e,controls:t}){let n=t?.onReplay??Z;return(0,K.jsxs)(w,{title:`Trace`,onRun:n,actions:t?.shown?(0,K.jsx)(Se,{shown:t.shown,onShown:t.onShown}):null,children:[(0,K.jsx)(be,{onImport:e}),t?(0,K.jsx)(X,{controls:t}):null,(0,K.jsx)(T,{note:t?`Answers each model call from the recording, so it needs no keys.`:null,isReady:(t?.script.turns.length??0)>0,isRunning:t?.isRunning??!1,runLabel:t?.shown?`Replay again`:`Replay`,runningLabel:`Replaying`,stopLabel:`Stop`,onRun:n,onStop:t?.onStop??Z})]})}function Ce({status:e,turns:t,onContinue:n,onLive:r}){let[i,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(),l=e=>(0,K.jsx)(f,{label:`Continue live`,variant:`secondary`,size:`sm`,isLoading:i,onClick:async()=>{o(!0),c(void 0);try{await r(e)}catch(e){c(e instanceof Error?e.message:String(e)),o(!1)}}}),u=(()=>{switch(e.kind){case`running`:return(0,K.jsx)(_,{status:`info`,title:`Replaying ${q(e.turn)} of ${String(t)}`});case`waiting`:return(0,K.jsx)(_,{status:`info`,title:`${q(e.turn-1)} waits on you`,description:`Answer it in the conversation, then continue the replay.`,endContent:(0,K.jsx)(f,{label:`Continue replay`,variant:`secondary`,size:`sm`,onClick:()=>{n(e.turn)}})});case`missing`:return(0,K.jsx)(_,{status:`warning`,title:`Replay stopped before ${q(e.turn)}`,description:`It was sent with files, and a trace never holds a file's bytes. Continue live to send it again with yours.`,endContent:l(e.turn)});case`diverged`:{let{turn:t,call:n,reason:r}=e.divergence;return(0,K.jsx)(_,{status:`warning`,title:`Replay stopped at ${q(t)}, model call ${String(n)}`,description:r,endContent:l(t)})}case`failed`:return(0,K.jsx)(_,{status:`error`,title:`Replay stopped at ${q(e.turn)}`,description:e.message,endContent:l(e.turn)});case`done`:return(0,K.jsx)(_,{status:`success`,title:`Replayed ${String(t)} ${t===1?`turn`:`turns`}`,description:`Every model call this profile made was one the recording answered.`})}})();return(0,K.jsxs)(a,{gap:1,children:[u,s?(0,K.jsx)(_,{status:`error`,title:s}):null]})}function $(e){let t=o();for(let n of e)t.push(n);return t}function we({payload:e,iface:t,trace:n,card:r,opened:i,script:a,shown:s,liveTools:l,runtime:u,onLive:d}){let f=(0,G.useRef)(void 0),[p,m]=(0,G.useState)({kind:`running`,turn:0}),[h]=(0,G.useState)(o),g=(0,G.useMemo)(()=>$(i.records),[i.records]),_=(0,G.useMemo)(()=>ge(a,e.profile.id,e=>{f.current??=e}),[a,e.profile.id]),v=(0,G.useMemo)(()=>c(l?e:_e(e),{mode:`byok`,provider:_.provider,...l?{}:{toolHandlers:_.toolHandlers}},{conversationKey:O(),traces:h}),[e,_,l,h]),y=(0,G.useMemo)(()=>l?ee(e):void 0,[l,e]),b=te({transport:v,iface:t,pageTools:y}),{sendText:x,handleStop:S}=b,C=(0,G.useRef)(b.phase);C.current=b.phase;let[w,T]=(0,G.useState)(0);(0,G.useEffect)(()=>{let e=!1,t=async()=>{for(;!e&&C.current===`streaming`;)await new Promise(e=>requestAnimationFrame(e))};return(async()=>{for(let n=w;n<a.turns.length;n+=1){if(await t(),e)return;if(C.current===`gated`)return _.startTurn(n-1),m({kind:`waiting`,turn:n});let{text:r,attachments:i}=a.turns[n];if(i>0)return m({kind:`missing`,turn:n});_.startTurn(n),m({kind:`running`,turn:n});try{let t=await x(r);if(e)return;if(f.current)return m({kind:`diverged`,divergence:f.current});t||--n}catch(e){let t=e instanceof Error?e.message:String(e);return m({kind:`failed`,turn:n,message:t})}}m({kind:`done`})})(),()=>{e=!0,S()}},[w,_,a,x,S]);let E=async t=>{d({...await ye(e,u,a.turns.slice(0,t).flatMap(e=>e.blocks)),text:a.turns[t]?.text??``})},D=s===`replayed`;return(0,K.jsx)(J,{iface:t,feed:D?h:g,trace:n,card:r({isRunning:p.kind===`running`,onStop:()=>{S(),m({kind:`done`})}}),conversation:(0,K.jsx)(Y,{iface:t,blocks:D?[...b.blocks,...b.streamBlocks]:W(a),chat:D?b:void 0,banner:D?(0,K.jsx)(Ce,{status:p,turns:a.turns.length,onContinue:T,onLive:E}):void 0})})}function Te(e){return(0,K.jsx)(u,{children:(0,K.jsx)(h,{labels:v,children:(0,K.jsx)(Ee,{...e})})})}function Ee({payload:e,trace:t,runtime:n,onLive:r}){let i=(0,G.useMemo)(()=>d(e),[e]),[a,o]=(0,G.useState)(),s=(0,G.useMemo)(()=>a&&fe(a.records),[a]),c=(0,G.useMemo)(()=>$(a?.records??[]),[a]),[l,u]=(0,G.useState)(0),[f,p]=(0,G.useState)(`recorded`),[m,h]=(0,G.useState)(!1),g=e=>{o(e),u(0),p(`recorded`)},_=()=>{u(e=>e+1),p(`replayed`)};if(i.type===`live`)return null;if(!a||!s)return(0,K.jsx)(J,{iface:i,feed:c,trace:t,card:(0,K.jsx)(Q,{onImport:g}),conversation:null});let v=({isRunning:t,onStop:n})=>(0,K.jsx)(Q,{onImport:g,controls:{opened:a,script:s,payload:e,shown:l>0?f:null,onShown:p,liveTools:m,onLiveTools:e=>{h(e),l>0&&_()},isRunning:t,onReplay:_,onStop:n}});return l===0?(0,K.jsx)(J,{iface:i,feed:c,trace:t,card:v({isRunning:!1,onStop:()=>void 0}),conversation:(0,K.jsx)(Y,{iface:i,blocks:W(s)})}):(0,K.jsx)(we,{payload:e,iface:i,trace:t,card:v,opened:a,script:s,shown:f,liveTools:m,runtime:n,onLive:r},l)}export{Te as TraceReplay};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{t as r}from"./VStack-CkVMcNiK.js";import{n as i}from"./StackItem-CQviqAfM.js";import{N as a,U as o,c as s,l as c}from"./browser-transport-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{t as r}from"./VStack-CkVMcNiK.js";import{n as i}from"./StackItem-CQviqAfM.js";import{N as a,U as o,c as s,l as c}from"./browser-transport-DYgEItHi.js";import{t as l}from"./Icon-ZfFwTt8n.js";import{t as u}from"./IconButton-CG5klqF1.js";import{t as d}from"./Text-BsiAsowd.js";import{n as f,o as p}from"./labels-provider-BSiD6Lrb.js";import{n as m}from"./Card-Ghe4ozhC.js";import{t as h}from"./Tooltip-CTEuMRLe.js";import{n as g,t as _}from"./arrive-DvbqpeRS.js";import{d as v}from"./reader-BB7aL5yX.js";import{_ as y,b,g as x,y as S}from"./ConsoleFrame-BkzieVRC.js";import{c as C,i as w}from"./trace-patterns-CS99kExN.js";import{t as T}from"./CardWall-CBRLdDZW.js";var E=e(n(),1),D=t(),O=`var(--duration-medium) var(--ease-standard)`,k=12;function A(){let e=m();return(0,E.useMemo)(()=>({percent:new Intl.NumberFormat(e,{style:`percent`,maximumFractionDigits:0}),decimal:new Intl.NumberFormat(e,{maximumFractionDigits:2}),usd:new Intl.NumberFormat(e,{style:`currency`,currency:`USD`,maximumSignificantDigits:2})}),[e])}function j(e){return C(e?`clear`:`shade2`)}function M({value:e,isLead:t}){return(0,D.jsx)(`div`,{style:{height:k,width:`${String(Math.max(e,.01)*100)}%`,borderRadius:4,background:j(t),transition:`width ${O}`}})}function N({title:e,aside:t,detail:n,answer:a}){let o=f(),s=A(),c=Object.entries(a.probabilities).sort(([,e],[,t])=>t-e);return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:a.choice,note:o(`@theorem.decision.confidence`,{percent:s.percent.format(a.confidence)}),children:(0,D.jsx)(r,{gap:2,role:`list`,children:c.map(([e,t])=>(0,D.jsxs)(r,{gap:1,role:`listitem`,"aria-label":o(`@theorem.decision.option`,{label:e,percent:s.percent.format(t)}),children:[(0,D.jsxs)(i,{gap:2,hAlign:`between`,"aria-hidden":!0,children:[(0,D.jsx)(d,{type:`supporting`,color:`secondary`,maxLines:1,children:e}),(0,D.jsx)(d,{type:`supporting`,hasTabularNumbers:!0,children:s.percent.format(t)})]}),(0,D.jsx)(M,{value:t,isLead:e===a.choice})]},e))})})}var P=56;function F(e){let t=e.split(/[:—–]\s/)[0]?.trim()??``;return t&&t.length<=32&&t!==e?t:e}function I({title:e,aside:t,detail:n,answer:i,labels:a}){let o=f(),s=A(),c=a.length,l=Math.min(c-1,Math.max(0,Math.round(i.score)));return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:a[l]===void 0?s.decimal.format(i.score):F(a[l]),note:[o(`@theorem.decision.score_of`,{score:s.decimal.format(i.score),max:s.decimal.format(c-1)}),o(`@theorem.decision.confidence`,{percent:s.percent.format(i.confidence)})].join(` · `),children:(0,D.jsxs)(r,{gap:1,children:[(0,D.jsxs)(`div`,{"aria-hidden":!0,style:{position:`relative`,display:`flex`,alignItems:`flex-end`,gap:4,height:P},children:[a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,height:`${String(Math.max(.04,i.probabilities[String(t)]??0)*100)}%`,borderRadius:4,background:j(t===l),transition:`height ${O}`}},`${String(t)}:${e}`)),(0,D.jsx)(`div`,{style:{position:`absolute`,insetBlock:-4,left:`${String((i.score+.5)/c*100)}%`,width:0,borderInlineStart:`1.5px dashed var(--color-text-secondary)`,transition:`left ${O}`}})]}),(0,D.jsx)(`div`,{style:{display:`flex`,gap:4},children:a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,minWidth:0},title:e,children:(0,D.jsx)(d,{type:`supporting`,color:`secondary`,maxLines:1,children:F(e)})},`${String(t)}:${e}`))}),(0,D.jsx)(`span`,{style:{position:`absolute`,width:1,height:1,overflow:`hidden`,clipPath:`inset(50%)`},children:a.map((e,t)=>o(`@theorem.decision.option`,{label:e,percent:s.percent.format(i.probabilities[String(t)]??0)})).join(`; `)})]})})}function L({title:e,aside:t,detail:n,answer:r}){let i=A();return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:i.decimal.format(r.noul)})}var R=72,z=168;function B(e){let[t,n]=(0,E.useState)(null);return(0,E.useEffect)(()=>{let t=new Image;t.onload=()=>{n({width:t.naturalWidth,height:t.naturalHeight})},t.src=e},[e]),t}function V(e,t){let n=e.style.color;e.style.color=`var(${t})`;let r=getComputedStyle(e).color;return e.style.color=n,r}function H({source:e,box:t,caption:n}){let r=f(),i=S(e),a=B(i),[o,l]=(0,E.useState)(null);if(!a)return null;let u=y(t),d=a.width*(t.right-t.left)/(a.height*(t.bottom-t.top)),p=r(`@theorem.decision.open_box`);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(h,{content:p,children:(0,D.jsx)(c,{label:p,padding:0,onClick:e=>{let n={outline:V(e.currentTarget,`--color-accent`),shade:V(e.currentTarget,`--color-overlay`)};b(i,t,n).then(l)},children:(0,D.jsx)(`div`,{role:`img`,"aria-label":r(`@theorem.decision.box_in`),style:{position:`relative`,overflow:`hidden`,aspectRatio:String(d),height:z,maxWidth:`100%`,borderRadius:4},children:(0,D.jsx)(`img`,{src:i,alt:``,style:{position:`absolute`,width:`${String(u.width)}%`,height:`${String(u.height)}%`,left:`${String(u.left)}%`,top:`${String(u.top)}%`,maxWidth:`none`}})})})}),(0,D.jsx)(s,{isOpen:o!==null,onOpenChange:e=>{e||l(null)},media:{src:o??i,alt:r(`@theorem.decision.box_marked`),caption:n},hasZoom:!0})]})}function U({title:e,aside:t,detail:n,answer:r,field:i,asked:a}){let o=f(),s=a&&x(a.images,a.state,i),c=A(),{top:l,bottom:u,left:d,right:p}=r.box,m=o(`@theorem.decision.box_edges`,{left:c.percent.format(d),top:c.percent.format(l),right:c.percent.format(p),bottom:c.percent.format(u)});return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:m,note:o(`@theorem.decision.confidence`,{percent:c.percent.format(r.confidence)}),children:s?(0,D.jsx)(H,{source:s,box:r.box,caption:`${e}: ${m}`}):(0,D.jsx)(`div`,{"aria-hidden":!0,style:{position:`relative`,height:R,borderRadius:4,border:`1px solid var(--color-border)`},children:(0,D.jsx)(`div`,{style:{position:`absolute`,insetInlineStart:`${String(d*100)}%`,insetBlockStart:`${String(l*100)}%`,width:`${String((p-d)*100)}%`,height:`${String((u-l)*100)}%`,borderRadius:2,background:j(!0),transition:`all ${O}`}})})})}function W({question:e,answer:t,asked:n,onQuestion:r,detail:i}){let a=f(),s=`${e.id} · ${a(`@theorem.decision.type.${e.type}`)}`;if(!t)return null;let c=a(`@theorem.decision.edit_question`,{question:e.id}),d={title:s,detail:i,aside:r?(0,D.jsx)(u,{label:c,tooltip:c,size:`sm`,variant:`ghost`,icon:(0,D.jsx)(l,{icon:o,size:`xsm`,color:`secondary`}),onClick:()=>{r(e.id)}}):void 0};return t.type===`choice`?(0,D.jsx)(N,{...d,answer:t}):t.type===`score`?(0,D.jsx)(I,{...d,answer:t,labels:e.labels}):t.type===`noul`?(0,D.jsx)(L,{...d,answer:t}):(0,D.jsx)(U,{...d,answer:t,field:e.field,asked:n})}function G({model:e,usage:t,elapsedMs:n,isStale:i,tokens:a,children:o}){let s=f(),c=A();return(0,D.jsx)(g,{children:(0,D.jsxs)(r,{gap:3,style:{opacity:i?.5:1,transition:`opacity ${O}`},"aria-busy":i,children:[o,(0,D.jsx)(_,{children:(0,D.jsx)(d,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:p(s,c.usd,{model:e,usage:t,elapsedMs:n,tokens:a})})})]},n??0)})}function K({iface:e,result:t,elapsedMs:n,isStale:r,asked:i,onQuestion:a,questionText:o}){let s=f();return(0,D.jsx)(G,{model:t.model,usage:t.usage,elapsedMs:n,isStale:r,tokens:e=>s(`@theorem.decision.tokens`,{count:e}),children:(0,D.jsx)(T,{minWidth:260,children:e.questions.map(e=>(0,D.jsx)(_,{children:(0,D.jsx)(W,{question:e,answer:t.answers[e.id],asked:i,onQuestion:a,detail:o?.[e.id]})},e.id))})})}var q={status:`idle`,result:null,elapsedMs:null,startedAt:null,failure:null};function J(e,t){for(let n of t??[])e.traces?.push(n)}function Y(e,t,n){let[r,i]=(0,E.useState)(q),o=(0,E.useRef)(null);(0,E.useEffect)(()=>()=>o.current?.abort(),[]);let s=(0,E.useCallback)(()=>{o.current?.abort(),o.current=null,i(e=>e.status===t?{...e,status:e.result?`done`:`idle`,startedAt:null}:e)},[t]),c=(0,E.useCallback)(async(...r)=>{o.current?.abort();let s=new AbortController;o.current=s,i(e=>({status:t,result:e.result,elapsedMs:e.elapsedMs,startedAt:Date.now(),failure:null}));let c=performance.now();try{let t=await n(e,s.signal,...r);if(s.signal.aborted)return;J(e,t.traces),i({status:`done`,result:t.result,elapsedMs:performance.now()-c,startedAt:null,failure:null})}catch(t){if(s.signal.aborted)return;J(e,v(t)),i(e=>({...e,status:`error`,startedAt:null,failure:a(t)}))}finally{o.current===s&&(o.current=null)}},[e,t,n]);return{...r,call:c,cancel:s}}export{A as a,K as i,G as n,M as r,Y as t};
|
package/page/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%23000'/%3E%3Cg transform='translate(4 4)' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4.5 18.5c2 0 3-1.2 4.2-3.4l2.6-5c1-1.9 2.1-3.1 4.2-3.1'/%3E%3Cpath d='M5.5 8.2c1.6-.9 3.2-.4 3.8 1.6l2.3 6.6c.6 1.7 2.1 2.4 3.9 1.7'/%3E%3Ccircle cx='19.5' cy='4.5' r='1.6' fill='%23fff' stroke='none'/%3E%3C/g%3E%3C/svg%3E"
|
|
11
11
|
/>
|
|
12
12
|
<title>theorem studio</title>
|
|
13
|
-
<script type="module" crossorigin src="/studio/assets/index
|
|
13
|
+
<script type="module" crossorigin src="/studio/assets/index-Dajtrq_Z.js"></script>
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/studio/assets/rolldown-runtime-hePW80VL.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/studio/assets/themeProps-3IqahpCr.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/studio/assets/tokens.stylex-DkHf0P9C.js">
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<link rel="modulepreload" crossorigin href="/studio/assets/use-trace-records-BkAYJz0M.js">
|
|
44
44
|
<link rel="modulepreload" crossorigin href="/studio/assets/IconAlertTriangle-BqAEqqdU.js">
|
|
45
45
|
<link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-BSiD6Lrb.js">
|
|
46
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-
|
|
46
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-C4MPbvft.js">
|
|
47
47
|
<link rel="modulepreload" crossorigin href="/studio/assets/arrive-DvbqpeRS.js">
|
|
48
48
|
<link rel="modulepreload" crossorigin href="/studio/assets/Center-nHS1JSux.js">
|
|
49
49
|
<link rel="modulepreload" crossorigin href="/studio/assets/IconSearch-BTx66a40.js">
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
<link rel="modulepreload" crossorigin href="/studio/assets/types-CMdljBjd.js">
|
|
60
60
|
<link rel="modulepreload" crossorigin href="/studio/assets/useScrollLock-Dyf6PHJt.js">
|
|
61
61
|
<link rel="modulepreload" crossorigin href="/studio/assets/useContainerReveal-BFy8N_QU.js">
|
|
62
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-
|
|
62
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-DYgEItHi.js">
|
|
63
63
|
<link rel="modulepreload" crossorigin href="/studio/assets/focusReturn-CTppP2k0.js">
|
|
64
64
|
<link rel="modulepreload" crossorigin href="/studio/assets/chainEventHandlers-C6ttXGfW.js">
|
|
65
65
|
<link rel="modulepreload" crossorigin href="/studio/assets/Dialog-BDUExlk_.js">
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
<link rel="modulepreload" crossorigin href="/studio/assets/encode-files-DZ4tVtEQ.js">
|
|
70
70
|
<link rel="modulepreload" crossorigin href="/studio/assets/turn-client-Dy9-U9_L.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-PavPZ114.js">
|
|
72
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-
|
|
72
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-C1pvg0JC.js">
|
|
73
73
|
<link rel="modulepreload" crossorigin href="/studio/assets/crypto-Boxudvjl.js">
|
|
74
74
|
<link rel="modulepreload" crossorigin href="/studio/assets/workspace-Cno6Ge26.js">
|
|
75
75
|
<link rel="modulepreload" crossorigin href="/studio/assets/lent-keys-C32ems-I.js">
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/studio/assets/EmptyState-C8W4JKBZ.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-VX91zrxj.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/studio/assets/useAdaptivePresentation-BY_zvjIp.js">
|
|
81
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/ContextMenu-
|
|
81
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/ContextMenu-BGP2gdee.js">
|
|
82
82
|
<link rel="modulepreload" crossorigin href="/studio/assets/BottomSheet-BQPskY35.js">
|
|
83
83
|
<link rel="modulepreload" crossorigin href="/studio/assets/Section-DJ97F7QE.js">
|
|
84
84
|
<link rel="stylesheet" crossorigin href="/studio/assets/use-second-ticker-CnxaP3LD.css">
|