@theoremjs/studio 0.3.4-next.608.gd007c52 → 0.3.4-next.610.g6ddf39d
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-DNuB7lhC.js → Banner-O0C5KVNy.js} +2 -2
- package/page/assets/CardWall-D63k-4of.js +1 -0
- package/page/assets/{ConsoleFrame-DRsXYFYa.js → ConsoleFrame-DZBnKWKu.js} +1 -1
- package/page/assets/{MenuBottomSheet-Kdylt_it.js → MenuBottomSheet-BgEFW0aD.js} +1 -1
- package/page/assets/{SchemaFields-DRS_ztxv.js → SchemaFields-BEJRfqpK.js} +1 -1
- package/page/assets/{ToolResultCharts-BnCESJwG.js → ToolResultCharts-D2lBPHEZ.js} +1 -1
- package/page/assets/{TraceInspector-DLaTSe9y.js → TraceInspector-BSaIDwyH.js} +1 -1
- package/page/assets/{TraceOverview-CksdzH-8.js → TraceOverview-DjHshucg.js} +1 -1
- package/page/assets/{browser-engine-U4pbMdOL.js → browser-engine-BjJHK9Fj.js} +1 -1
- package/page/assets/{browser-transport-LV_FgVKG.js → browser-transport-Dg00IzNm.js} +3 -3
- package/page/assets/{export-agent-DzvQf-68.js → export-agent-Deaz-SP9.js} +1 -1
- package/page/assets/{guardrail-tester-B1iBUn55.js → guardrail-tester-KplaELLL.js} +1 -1
- package/page/assets/{index-3PUx0L6S.js → index-Cl8kUfgj.js} +8 -8
- package/page/assets/{studio-code-pane-BdQTxi9f.js → studio-code-pane-CPkCgdNL.js} +1 -1
- package/page/assets/{studio-console-DxPHEOtQ.js → studio-console-BZyPvkUO.js} +1 -1
- package/page/assets/{studio-decision-WZ1-fSqO.js → studio-decision-58N5707m.js} +1 -1
- package/page/assets/{studio-embedding-nDQVQxGy.js → studio-embedding-Bb--Fl0W.js} +1 -1
- package/page/assets/{studio-host-console-C-bBbaMQ.js → studio-host-console-BXsksNiY.js} +2 -2
- package/page/assets/{studio-labels-7sgmTzU-.js → studio-labels-1m3jxSy0.js} +1 -1
- package/page/assets/{studio-live-BbaCxmkQ.js → studio-live-DO17Sba3.js} +1 -1
- package/page/assets/{studio-map-D-hwOlzT.js → studio-map-CW6zs4Gl.js} +1 -1
- package/page/assets/{studio-trace-replay-m0JyWXs0.js → studio-trace-replay-3HVWcPKT.js} +1 -1
- package/page/assets/{use-one-call-ufJV1bYw.js → use-one-call-Cj7h9tR9.js} +1 -1
- package/page/index.html +4 -4
- package/page/assets/CardWall-Y542bbCc.js +0 -1
|
@@ -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{t as o}from"./VStack-CkVMcNiK.js";import{n as s}from"./StackItem-CQviqAfM.js";import{E as c,i as l,p as u,s as d,w as f}from"./browser-transport-LV_FgVKG.js";import{t as p}from"./mergeProps-ptS-gIMz.js";import{u as m}from"./fieldParts-B7DYLgh4.js";import{t as h}from"./isRenderable-DHkzpAoQ.js";import{t as g}from"./Text-BOqCfzZC.js";import{t as ee}from"./preload-helper-DpV6A1kQ.js";import{i as te,l as ne,n as _,t as re}from"./labels-provider-Bt3Q2GjB.js";import{n as v}from"./Card-DruykyeB.js";import{t as ie}from"./Tooltip-BWs5DLrM.js";import{a as ae,t as y}from"./Banner-DNuB7lhC.js";import{t as oe}from"./row-keys-WByP9Hsh.js";import{_ as se,f as ce,g as le,m as ue,n as de,r as fe,t as pe,v as me}from"./studio-labels-7sgmTzU-.js";import{l as he,u as ge}from"./tool-schema-CPVHlZ7w.js";import{_ as _e,a as b,b as x,c as S,f as ve,h as C,l as w,n as T,o as ye,r as be,t as xe,v as Se,x as Ce,y as E}from"./shaped-data-C4yaGRz9.js";import{S as D,i as O,u as k}from"./turn-client-CZG4gVtX.js";import{t as A}from"./use-second-ticker-BSCE_-wM.js";import{t as we}from"./EmptyState-C_uF9Wyj.js";import{n as Te,t as Ee}from"./ListItem-QF7KFt0h.js";import{a as De,i as Oe,o as ke,r as Ae,t as je}from"./ConsoleFrame-DRsXYFYa.js";import{i as Me}from"./trace-patterns-D6TbkLLr.js";import{t as Ne}from"./CardWall-Y542bbCc.js";import{t as Pe}from"./SchemaFields-DRS_ztxv.js";import{B as Fe,C as Ie,Dt as Le,K as Re,N as ze,Nt as Be,R as Ve,T as He,U as Ue,V as We,W as Ge,_ as j,g as Ke,m as qe,w as M}from"./index-3PUx0L6S.js";import{t as Je}from"./studio-console-DxPHEOtQ.js";var Ye=4,Xe=3,Ze=3,N=8,Qe=6,P=3,$e=3,et=/(^|_)(id|ids|lat|lon|lng|latitude|longitude|offset|interval|index|rank|order)$|Id$|^(generationtime_ms|utc_offset_seconds)$/i,tt=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function nt(e){if(/\s/.test(e))return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&tt.test(t.pathname)}catch{return!1}}function F(e){return!et.test(e)}function I(e){return/^[A-Z][A-Z0-9]{1,5}$/.test(e)?e:b(e)}function L(e,t){if(!F(e)||t&&e in t&&ve(t[e])===void 0)return;let{label:n,unit:r}=be(e,t);return{label:I(e)===e?e:n,unit:r}}function R(e,t){let n=[];for(let[r,i]of C(e)){if(typeof i!=`number`||!Number.isFinite(i))continue;let e=L(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,Ye)}function rt(e){if(!S(e))return[];for(let[t,n]of C(e)){let r=x(n);if(!S(r)||T(r))continue;let i=Object.values(r);if(i.length===0||!i.every(ye))continue;let a=R(r,E(e,t));if(a.length>0)return a}return R(e,void 0)}function z(e,t){return new Set(e.map(e=>e[t])).size}function B(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)&&z(e,n)>1).flatMap(e=>{let t=L(e,n);return t?[{key:e,...t}]:[]})}function it(e){let[t]=e;if(t)return Object.keys(t).find(t=>e.every(e=>typeof e[t]==`string`&&xe.test(e[t])))}function at(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 ot(e,t,n,r,i){let a=new Map;for(let e of B(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,Ze),o=a.length>1?at(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 st(e){let[t]=e,n=t?Se(t):void 0;if(!t||!n||!e.every(e=>typeof e[n]==`string`||typeof e[n]==`number`))return;if(z(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`)&&z(e,t)===e.length).sort((e,t)=>r(e)-r(t));return i??n}function ct(e,t,n,r){let i=st(n);return i?B(n,i,r).sort((e,t)=>z(n,t.key)-z(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,N)})):[]}function V(e,t,n,r){if(n.length<P)return[];let i=it(n);return i?ot(e,t,n,i,r):ct(e,t,n,r)}function H(e,t,n,r,i){if(i>$e)return[];if(Array.isArray(e)){let i=e.map(x);return i.every(S)?V(t,n,i,r):[]}if(!S(e))return[];let a=T(e);if(a)return V(t,n,_e(e,a),r);let o=C(e),s=o.filter(([e,t])=>typeof t==`number`&&F(e));if(i>0&&s.length>=P&&s.length===o.length){let e=s.map(([e,t])=>({label:I(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,N)}]}return o.flatMap(([r,a])=>H(x(a),t?`${t}.${r}`:r,i===0?b(r):`${n} › ${b(r)}`,E(e,r),i+1))}function U(e,t,n,r){if(r.size>=Qe||n>4)return;let i=x(e);if(typeof i==`string`)nt(i)&&!r.has(i)&&r.set(i,{src:i,alt:b(t||`image`)});else if(Array.isArray(i))for(let e of i)U(e,t,n+1,r);else if(S(i))for(let[e,t]of Object.entries(i))U(t,e,n+1,r)}function lt(e){let t=x(e),n=new Map;return U(t,``,0,n),{figures:rt(t),charts:H(t,``,``,void 0,0).slice(0,Xe),images:[...n.values()]}}function ut(e){return e.mimeType&&e.data?`data:${e.mimeType};base64,${e.data}`:void 0}function dt(e,t,n){let r=t.flatMap(e=>{let t=ut(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 ft(e,t){return e.figures.length+e.charts.length+t.images.length+t.audio.length>0}var pt=864e5,mt=10;function ht(e){return e.some(e=>e.includes(`T`))?{tick:Math.abs(Date.parse(e.at(-1)??``)-Date.parse(e[0]??``))<=pt?{hour:`numeric`}:{month:`short`,day:`numeric`},when:{dateStyle:`medium`,timeStyle:`short`}}:{tick:e.length<=mt?{weekday:`short`,timeZone:`UTC`}:{month:`short`,day:`numeric`,timeZone:`UTC`},when:{dateStyle:`medium`,timeZone:`UTC`}}}var W=n(),G={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}},gt={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 K({variant:e,label:t,isPulsing:n=!1,tooltip:a,icon:o,xstyle:s,className:c,style:l,ref:u,...d}){let f=h(o),m=(0,W.jsx)(`span`,{ref:u,role:`img`,"aria-label":t,...p(i(`status-dot`,{variant:e}),r(G.base,gt[e],n&&G.pulsing,n&&G.reducedMotion,s),c,l),...d,children:f&&(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`x78zum5 x6s0dn4 xl56j7k x14ju556 x1xc55vz xdk7pt`,children:o})});return a?(0,W.jsx)(ie,{content:a,children:m}):m}K.displayName=`StatusDot`;var _t=new Set([`gate`,`complete`,`error`,`cancel`]);function vt({call:e,failure:t,isRunning:n}){let r=e?.state?.phase;return r!==void 0&&_t.has(r)?r:t?`error`:n?`running`:`cancel`}function q({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 yt(e){let t=e.tools.find(t=>t.name===e.picked)??e.tools[0],n=t?e.drafts[t.name]??w(ge(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 J=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 xt(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:D(n)[0]??null,progress:r}}function St(e,t){let n=(0,J.useMemo)(()=>me(e,t),[e,t]),{iface:r,describeFailure:i}=qe(n),[a,o]=(0,J.useState)([]),s=(0,J.useRef)(new Map),l=(0,J.useRef)([]),u=(0,J.useRef)(a);u.current=a,(0,J.useEffect)(()=>{let e=s.current;return()=>{for(let t of e.values())t.abort()}},[]);let d=(0,J.useCallback)((e,t)=>{o(n=>n.map(n=>n.id===e?t(n):n))},[]),f=(0,J.useCallback)(async(e,t)=>{let n=new AbortController;s.current.set(e,n);let r=performance.now();d(e,e=>({...e,isRunning:!0,failure:null}));try{await t(t=>{t.type!==`unsupported`&&t.type!==`malformed`&&d(e,e=>xt(e,t))},n.signal),d(e,e=>({...e,isRunning:!1,answering:null,elapsedMs:performance.now()-r}))}catch(t){let i=n.signal.aborted?null:c(t);d(e,e=>({...e,isRunning:!1,answering:null,failure:i,elapsedMs:performance.now()-r}))}finally{s.current.get(e)===n&&s.current.delete(e)}},[d]);return{iface:r,describeFailure:i,calls:a,run:(0,J.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]),f(r,(r,i)=>n.call({name:e,input:t},r,i)),r},[f,n]),answer:(0,J.useCallback)(async(e,t)=>{let r=u.current.find(t=>t.id===e),i=r?.call?.state;if(!r?.call||i?.phase!==`gate`)return;let a=r.call.callId,o=O(r.call),s=se({toolName:r.name,gate:i.gate,sessionPermissions:l.current,resolution:t});s.decision===`approve`&&(l.current=s.sessionPermissions);let c=k(r.events);d(e,e=>({...e,answering:t.action})),await f(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:l.current,...c?{snapshot:c}:{}}},e,t))},[f,n,d]),cancel:(0,J.useCallback)(e=>{s.current.get(e)?.abort(),s.current.delete(e)},[])}}function Ct(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,...e,children:(0,W.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=(0,J.lazy)(()=>ee(()=>import(`./ToolResultCharts-BnCESJwG.js`).then(e=>({default:e.ToolResultChart})),__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,78,79,80]))),Tt=236,Et=260;function Dt({layout:e,parts:t=[]}){let n=_(),r=v(),i=(0,J.useMemo)(()=>new Intl.NumberFormat(r,{maximumFractionDigits:2}),[r]),a=(0,J.useMemo)(()=>dt(e,t,n(`@theorem.host.image`)),[e,t,n]),[s,c]=(0,J.useState)(null);if(!ft(e,a))return null;let{images:l,audio:u}=a;return(0,W.jsxs)(o,{gap:3,children:[(0,W.jsxs)(Ne,{minWidth:Et,children:[e.figures.map(e=>(0,W.jsx)(M,{children:(0,W.jsx)(Me,{title:e.label,value:Ce(i.format(e.value),e.unit)})},`figure:${e.key}`)),e.charts.map(e=>(0,W.jsx)(M,{children:(0,W.jsx)(J.Suspense,{fallback:(0,W.jsx)(Ue,{height:Tt}),children:(0,W.jsx)(wt,{chart:e})})},`chart:${e.key}`)),l.map((e,t)=>(0,W.jsx)(M,{children:(0,W.jsx)(We,{label:e.alt||`Open image`,padding:0,onClick:()=>c(t),children:(0,W.jsx)(ue,{ratio:4/3,fit:`cover`,children:(0,W.jsx)(`img`,{src:e.src,alt:e.alt,loading:`lazy`})})})},`image:${e.src}`))]}),l.length>0?(0,W.jsx)(Ve,{isOpen:s!==null,onOpenChange:e=>{e||c(null)},media:l.map(e=>({src:e.src,alt:e.alt})),index:s??0,onIndexChange:c}):null,oe(u,e=>e.src).map(({item:e,key:t})=>(0,W.jsx)(M,{children:(0,W.jsx)(Fe,{src:e.src,mimeType:e.mimeType})},t))]})}function Ot({output:e,parts:t}){let n=_(),r=(0,J.useMemo)(()=>lt(e),[e]),i=(0,J.useMemo)(()=>r.figures.map(e=>e.key),[r]);return(0,W.jsx)(Ie,{value:e,title:n(`@theorem.host.response`),lead:(0,W.jsx)(Dt,{layout:r,parts:t}),ledKeys:i})}var kt=8,At={running:`accent`,gate:`warning`,complete:`success`,error:`error`,cancel:`neutral`};function jt(e,t,n){let r;try{r=JSON.parse(n)}catch{return{ok:!1,note:e(`@theorem.decision.invalid_json`)}}if(!S(r))return{ok:!1,note:e(`@theorem.decision.invalid_json`)};let i=he(t.inputSchema,r);return i.length>0?{ok:!1,note:e(`@theorem.host.missing`,{fields:i.join(`, `)}),input:r}:{ok:!0,input:r}}var Mt={function:Be,http:Le,mcp:Ct},Nt=440,Pt=2;function Ft(e,t){let n=e(`@theorem.host.kind.${t.kind}`);return t.description?`${n} · ${t.description}`:n}function It({tool:e}){let t=_();return e.access===`read-only`?null:(0,W.jsx)(s,{gap:1,wrap:`wrap`,children:(0,W.jsx)(m,{label:t(`@theorem.tool.access.${e.access}`),size:`sm`,color:e.access===`destructive`?`red`:`orange`})})}function Lt(e,t,n){return{label:t.call?ce(t.call):t.name,duration:t.isRunning?te(e,n-t.startedAt):t.elapsedMs==null?null:ne(e,t.elapsedMs)}}function Y({call:e,onAnswer:t}){let n=e.call?.state;return n?.phase===`gate`?n.gate.kind===`auth`?(0,W.jsx)(fe,{gate:n.gate,toolName:e.name,submitted:e.answering===`auth`,onAuthenticated:n=>void t(e.id,{action:`auth`,secret:n})}):(0,W.jsx)(de,{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 X(e){let t=e.call?.state;return!!q(e)||t?.phase===`complete`||!e.isRunning}function Z(e){let t=e.call?.state;return!X(e)&&t?.phase!==`gate`}function Rt({call:e,activity:t}){let n=e.call?.state,r=q(e);return(0,W.jsx)(He,{children:(0,W.jsxs)(o,{gap:3,children:[r?(0,W.jsx)(M,{children:(0,W.jsx)(y,{status:`error`,role:`alert`,title:r.title,description:r.description})}):null,n?.phase===`complete`?(0,W.jsx)(Ot,{output:n.output,parts:n.parts}):null,e.isRunning?null:(0,W.jsx)(M,{children:t})]})})}function zt({call:e,onAnswer:t}){let n=_(),{label:r,duration:i}=Lt(n,e,A(e.isRunning));if(Z(e))return(0,W.jsx)(j,{label:r,since:e.startedAt});let a=(0,W.jsx)(g,{size:`sm`,color:`secondary`,children:i?n(`@theorem.host.finished`,{activity:r,duration:i}):r});return(0,W.jsxs)(o,{gap:3,children:[(0,W.jsx)(Y,{call:e,onAnswer:t}),X(e)?(0,W.jsx)(Rt,{call:e,activity:a}):null]})}function Bt({calls:e,onPick:t}){let n=_(),r=v(),i=(0,J.useMemo)(()=>new Intl.DateTimeFormat(r,{timeStyle:`medium`}),[r]);return e.length===0?null:(0,W.jsxs)(o,{gap:1,children:[(0,W.jsx)(g,{type:`supporting`,color:`secondary`,as:`h3`,children:n(`@theorem.host.earlier`)}),(0,W.jsx)(Te,{hasDividers:!0,density:`compact`,children:e.slice(0,kt).map(e=>{let r=vt(e);return(0,W.jsx)(Ee,{label:e.name,startContent:(0,W.jsx)(K,{variant:At[r],label:n(`@theorem.host.status.${r}`),isPulsing:e.isRunning}),endContent:(0,W.jsx)(g,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:i.format(e.startedAt)}),onClick:()=>t(e)},e.id)})})]})}function Vt({tools:e,tool:t,check:n,text:r,view:i,shown:a,onText:s,onPick:c,onView:l,onRun:u,onStop:d}){let f=_(),p=`input`in n?n.input:void 0,m=i===`fields`&&p!==void 0;return(0,W.jsxs)(Oe,{title:f(`@theorem.host.request`),view:m?`fields`:`json`,hasFields:p!==void 0,onView:l,onRun:u,children:[(0,W.jsxs)(o,{gap:2,children:[(0,W.jsx)(Ge,{label:f(`@theorem.host.tool`),size:`sm`,options:e.map(e=>({value:e.name,label:e.name,icon:Mt[e.kind],description:Ft(f,e)})),value:t.name,hasSearch:e.length>8,renderOption:e=>(0,W.jsx)(`div`,{style:{width:Nt,maxWidth:`100%`,minWidth:0},children:(0,W.jsx)(Re,{icon:e.icon,label:e.label,description:e.description&&(0,W.jsx)(g,{type:`supporting`,color:`secondary`,maxLines:Pt,children:e.description})})}),onChange:c}),(0,W.jsx)(It,{tool:t})]}),m?(0,W.jsx)(Pe,{schema:t.inputSchema,value:p,onChange:e=>{s(w(e))}},t.name):(0,W.jsx)(Ae,{label:f(`@theorem.host.request`),text:r,isInvalid:p===void 0,onChange:s}),(0,W.jsx)(ke,{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 Ht(e,t,n,r){return!t||!n?.ok||r?.isRunning?null:e.run(t.name,n.input)}function Ut(e,t){let n=_(),[r,i]=(0,J.useState)(e.tools[0]?.name),[a,o]=(0,J.useState)({}),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(`fields`),{tool:d,text:f,shown:p,earlier:m}=yt({tools:e.tools,picked:r,drafts:a,calls:t.calls,shownId:s}),h=d?jt(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=Ht(t,d,h,p);e!==null&&c(e)},pick:e=>{i(e.name),o(t=>({...t,[e.name]:w(e.input)})),c(e.id)}}}function Wt({shown:e,earlier:t,onAnswer:n,onPick:r}){return(0,W.jsxs)(W.Fragment,{children:[e?(0,W.jsx)(zt,{call:e,onAnswer:n}):null,(0,W.jsx)(Bt,{calls:t,onPick:r})]})}function Gt(e,t,n,r,i){if(!e)return i;let a=r.length===0;return!n&&a?null:(0,W.jsx)(De,{label:t,fill:n!=null&&Z(n)&&a,children:i})}function Kt({transport:e,iface:t,host:n,maxWidth:r=`960px`,trace:i,flush:a,columns:o=!1,className:s,style:c}){let l=_(),u=ae(t,e.traces,i),d=Ut(t,n),{tool:f,check:p,shown:m,earlier:h}=d;return(0,W.jsxs)(je,{inspector:u,maxWidth:r,flush:a,columns:o,requestLabel:l(`@theorem.host.request`),className:s,style:c,children:[f&&p?(0,W.jsx)(Vt,{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,W.jsx)(we,{title:l(`@theorem.host.no_tools`)}),Gt(o,l(`@theorem.host.response`),m,h,(0,W.jsx)(Wt,{shown:m,earlier:h,onAnswer:n.answer,onPick:d.pick}))]})}function qt(e){let t=_(),n=St(e.transport,e.pageTools);return n.describeFailure?(0,W.jsx)(Ke,{title:n.describeFailure.error}):n.iface?(0,W.jsx)(Kt,{...e,iface:n.iface,host:n}):(0,W.jsx)(j,{label:t(`@theorem.chat.loading`)})}function Jt({endpoint:e,http:t,transport:n,theme:r,mode:i,labels:a,detectCodeLanguage:o,...s}){let c=(0,J.useRef)(t);c.current=t;let l=(0,J.useMemo)(()=>n??f({...c.current,endpoint:e}),[n,e]);return(0,W.jsx)(d,{theme:r,mode:i,children:(0,W.jsx)(re,{labels:a,children:(0,W.jsx)(ze,{detectCodeLanguage:o,children:(0,W.jsx)(qt,{...s,transport:l})})})})}var Yt=e({HostView:()=>$,StudioHostConsole:()=>Q});function Q(e){let t=Je(e,u,l);return(0,W.jsx)($,{...e,transport:t})}function $({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let o=(0,J.useMemo)(()=>le(e),[e]);return(0,W.jsx)(Jt,{detectCodeLanguage:!0,labels:pe,transport:t,pageTools:o,trace:n,flush:r,columns:i,className:a})}export{$ as HostView,Q as StudioHostConsole,ht as n,Yt as t};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolResultCharts-D2lBPHEZ.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-BOqCfzZC.js","assets/sharedResizeObserver-4U9Xq5Oq.js","assets/preload-helper-DpV6A1kQ.js","assets/Card-DruykyeB.js","assets/Icon-BqkS-pIq.js","assets/tokens.stylex-DkHf0P9C.js","assets/devWarning-DxuplmRl.js","assets/useMediaQuery-BCT0NUeZ.js","assets/container.stylex-BmOi-8DQ.js","assets/shaped-data-C4yaGRz9.js","assets/host-patterns-F-KZIzkF.js","assets/TraceOverview-DjHshucg.js","assets/useTooltip-c097gL_-.js","assets/useLayerDismissal-BAnTRYTt.js","assets/labels-provider-Bt3Q2GjB.js","assets/IconButton-DVUFx-8p.js","assets/focusOutline.stylex-BT0kfa4t.js","assets/useAnnounce-DTSHZvjg.js","assets/CodeBlock-CfVOtDeO.js","assets/useClipboard-CbN9bb4J.js","assets/useScrollableArea-DuF_pz9m.js","assets/focusableSelector-DXZeMU85.js","assets/Tooltip-BWs5DLrM.js","assets/row-keys-WByP9Hsh.js","assets/createReactComponent-CZwsv6DD.js","assets/trace-record-jV4PFwk_.js","assets/index-Cl8kUfgj.js","assets/SegmentedControlItem-BBGRPrxp.js","assets/fieldParts-B7DYLgh4.js","assets/useResolvedRequired-DbsOcDqy.js","assets/useDevWarning-Z9SoixOP.js","assets/isRtlElement-BG33-k_H.js","assets/plainDate-BHiJcj7o.js","assets/browser-transport-Dg00IzNm.js","assets/use-trace-records-B1vrKQmA.js","assets/ScrollableArea-BHfY7sWH.js","assets/IconAlertTriangle-BqAEqqdU.js","assets/Banner-O0C5KVNy.js","assets/isRenderable-DHkzpAoQ.js","assets/tool-schema-CPVHlZ7w.js","assets/schemas-BQ9Jydzb.js","assets/tree-DfG6CXsC.js","assets/live-ingress-OuSlQ6q7.js","assets/browser-connection-pM-ZbsQr.js","assets/use-second-ticker-BSCE_-wM.js","assets/use-second-ticker-GWBt83pd.css","assets/Center-nHS1JSux.js","assets/IconSearch-BTx66a40.js","assets/reader-D_UCUUJt.js","assets/trace-schema-9CdEyG6Q.js","assets/stub-DSUcPMOV.js","assets/focusReturn-CTppP2k0.js","assets/CheckboxInput-CFZ_Wq8-.js","assets/useScrollLock-Dyf6PHJt.js","assets/Dialog-Sd04KQS2.js","assets/chainEventHandlers-C6ttXGfW.js","assets/HoverCard-DMyWUvwP.js","assets/IconEye-BB5aY-wQ.js","assets/studio-labels-1m3jxSy0.js","assets/turn-client-CZG4gVtX.js","assets/encode-files-DxWGM2XV.js","assets/CollapsibleGroup-FIawJRo4.js","assets/crypto-CY8dSBJ4.js","assets/workspace-CzTPlUdi.js","assets/lent-keys-C32ems-I.js","assets/editors-BJX_S59A.js","assets/studio-session-yEqFQo5o.js","assets/EmptyState-C_uF9Wyj.js","assets/useMenuPress-DLG1QOiE.js","assets/useAdaptivePresentation-Bma4-u1a.js","assets/useFocusReturnVisibility-BHKv5Jwr.js","assets/ListItem-QF7KFt0h.js","assets/index-C9rhrCGT.css","assets/trace-patterns-D6TbkLLr.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{t as o}from"./VStack-CkVMcNiK.js";import{n as s}from"./StackItem-CQviqAfM.js";import{E as c,i as l,p as u,s as d,w as f}from"./browser-transport-Dg00IzNm.js";import{t as p}from"./mergeProps-ptS-gIMz.js";import{u as m}from"./fieldParts-B7DYLgh4.js";import{t as h}from"./isRenderable-DHkzpAoQ.js";import{t as g}from"./Text-BOqCfzZC.js";import{t as ee}from"./preload-helper-DpV6A1kQ.js";import{i as te,l as ne,n as _,t as re}from"./labels-provider-Bt3Q2GjB.js";import{n as v}from"./Card-DruykyeB.js";import{t as ie}from"./Tooltip-BWs5DLrM.js";import{a as ae,t as y}from"./Banner-O0C5KVNy.js";import{t as oe}from"./row-keys-WByP9Hsh.js";import{_ as se,f as ce,g as le,m as ue,n as de,r as fe,t as pe,v as me}from"./studio-labels-1m3jxSy0.js";import{l as he,u as ge}from"./tool-schema-CPVHlZ7w.js";import{_ as _e,a as b,b as x,c as S,f as ve,h as C,l as w,n as T,o as ye,r as be,t as xe,v as Se,x as Ce,y as E}from"./shaped-data-C4yaGRz9.js";import{S as D,i as O,u as k}from"./turn-client-CZG4gVtX.js";import{t as A}from"./use-second-ticker-BSCE_-wM.js";import{t as we}from"./EmptyState-C_uF9Wyj.js";import{n as Te,t as Ee}from"./ListItem-QF7KFt0h.js";import{a as De,i as Oe,o as ke,r as Ae,t as je}from"./ConsoleFrame-DZBnKWKu.js";import{i as Me}from"./trace-patterns-D6TbkLLr.js";import{t as Ne}from"./CardWall-D63k-4of.js";import{t as Pe}from"./SchemaFields-BEJRfqpK.js";import{B as Fe,C as Ie,Dt as Le,K as Re,N as ze,Nt as Be,R as Ve,T as He,U as Ue,V as We,W as Ge,_ as j,g as Ke,m as qe,w as M}from"./index-Cl8kUfgj.js";import{t as Je}from"./studio-console-BZyPvkUO.js";var Ye=4,Xe=3,Ze=3,N=8,Qe=6,P=3,$e=3,et=/(^|_)(id|ids|lat|lon|lng|latitude|longitude|offset|interval|index|rank|order)$|Id$|^(generationtime_ms|utc_offset_seconds)$/i,tt=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function nt(e){if(/\s/.test(e))return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&tt.test(t.pathname)}catch{return!1}}function F(e){return!et.test(e)}function I(e){return/^[A-Z][A-Z0-9]{1,5}$/.test(e)?e:b(e)}function L(e,t){if(!F(e)||t&&e in t&&ve(t[e])===void 0)return;let{label:n,unit:r}=be(e,t);return{label:I(e)===e?e:n,unit:r}}function R(e,t){let n=[];for(let[r,i]of C(e)){if(typeof i!=`number`||!Number.isFinite(i))continue;let e=L(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,Ye)}function rt(e){if(!S(e))return[];for(let[t,n]of C(e)){let r=x(n);if(!S(r)||T(r))continue;let i=Object.values(r);if(i.length===0||!i.every(ye))continue;let a=R(r,E(e,t));if(a.length>0)return a}return R(e,void 0)}function z(e,t){return new Set(e.map(e=>e[t])).size}function B(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)&&z(e,n)>1).flatMap(e=>{let t=L(e,n);return t?[{key:e,...t}]:[]})}function it(e){let[t]=e;if(t)return Object.keys(t).find(t=>e.every(e=>typeof e[t]==`string`&&xe.test(e[t])))}function at(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 ot(e,t,n,r,i){let a=new Map;for(let e of B(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,Ze),o=a.length>1?at(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 st(e){let[t]=e,n=t?Se(t):void 0;if(!t||!n||!e.every(e=>typeof e[n]==`string`||typeof e[n]==`number`))return;if(z(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`)&&z(e,t)===e.length).sort((e,t)=>r(e)-r(t));return i??n}function ct(e,t,n,r){let i=st(n);return i?B(n,i,r).sort((e,t)=>z(n,t.key)-z(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,N)})):[]}function V(e,t,n,r){if(n.length<P)return[];let i=it(n);return i?ot(e,t,n,i,r):ct(e,t,n,r)}function H(e,t,n,r,i){if(i>$e)return[];if(Array.isArray(e)){let i=e.map(x);return i.every(S)?V(t,n,i,r):[]}if(!S(e))return[];let a=T(e);if(a)return V(t,n,_e(e,a),r);let o=C(e),s=o.filter(([e,t])=>typeof t==`number`&&F(e));if(i>0&&s.length>=P&&s.length===o.length){let e=s.map(([e,t])=>({label:I(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,N)}]}return o.flatMap(([r,a])=>H(x(a),t?`${t}.${r}`:r,i===0?b(r):`${n} › ${b(r)}`,E(e,r),i+1))}function U(e,t,n,r){if(r.size>=Qe||n>4)return;let i=x(e);if(typeof i==`string`)nt(i)&&!r.has(i)&&r.set(i,{src:i,alt:b(t||`image`)});else if(Array.isArray(i))for(let e of i)U(e,t,n+1,r);else if(S(i))for(let[e,t]of Object.entries(i))U(t,e,n+1,r)}function lt(e){let t=x(e),n=new Map;return U(t,``,0,n),{figures:rt(t),charts:H(t,``,``,void 0,0).slice(0,Xe),images:[...n.values()]}}function ut(e){return e.mimeType&&e.data?`data:${e.mimeType};base64,${e.data}`:void 0}function dt(e,t,n){let r=t.flatMap(e=>{let t=ut(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 ft(e,t){return e.figures.length+e.charts.length+t.images.length+t.audio.length>0}var pt=864e5,mt=10;function ht(e){return e.some(e=>e.includes(`T`))?{tick:Math.abs(Date.parse(e.at(-1)??``)-Date.parse(e[0]??``))<=pt?{hour:`numeric`}:{month:`short`,day:`numeric`},when:{dateStyle:`medium`,timeStyle:`short`}}:{tick:e.length<=mt?{weekday:`short`,timeZone:`UTC`}:{month:`short`,day:`numeric`,timeZone:`UTC`},when:{dateStyle:`medium`,timeZone:`UTC`}}}var W=n(),G={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}},gt={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 K({variant:e,label:t,isPulsing:n=!1,tooltip:a,icon:o,xstyle:s,className:c,style:l,ref:u,...d}){let f=h(o),m=(0,W.jsx)(`span`,{ref:u,role:`img`,"aria-label":t,...p(i(`status-dot`,{variant:e}),r(G.base,gt[e],n&&G.pulsing,n&&G.reducedMotion,s),c,l),...d,children:f&&(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`x78zum5 x6s0dn4 xl56j7k x14ju556 x1xc55vz xdk7pt`,children:o})});return a?(0,W.jsx)(ie,{content:a,children:m}):m}K.displayName=`StatusDot`;var _t=new Set([`gate`,`complete`,`error`,`cancel`]);function vt({call:e,failure:t,isRunning:n}){let r=e?.state?.phase;return r!==void 0&&_t.has(r)?r:t?`error`:n?`running`:`cancel`}function q({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 yt(e){let t=e.tools.find(t=>t.name===e.picked)??e.tools[0],n=t?e.drafts[t.name]??w(ge(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 J=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 xt(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:D(n)[0]??null,progress:r}}function St(e,t){let n=(0,J.useMemo)(()=>me(e,t),[e,t]),{iface:r,describeFailure:i}=qe(n),[a,o]=(0,J.useState)([]),s=(0,J.useRef)(new Map),l=(0,J.useRef)([]),u=(0,J.useRef)(a);u.current=a,(0,J.useEffect)(()=>{let e=s.current;return()=>{for(let t of e.values())t.abort()}},[]);let d=(0,J.useCallback)((e,t)=>{o(n=>n.map(n=>n.id===e?t(n):n))},[]),f=(0,J.useCallback)(async(e,t)=>{let n=new AbortController;s.current.set(e,n);let r=performance.now();d(e,e=>({...e,isRunning:!0,failure:null}));try{await t(t=>{t.type!==`unsupported`&&t.type!==`malformed`&&d(e,e=>xt(e,t))},n.signal),d(e,e=>({...e,isRunning:!1,answering:null,elapsedMs:performance.now()-r}))}catch(t){let i=n.signal.aborted?null:c(t);d(e,e=>({...e,isRunning:!1,answering:null,failure:i,elapsedMs:performance.now()-r}))}finally{s.current.get(e)===n&&s.current.delete(e)}},[d]);return{iface:r,describeFailure:i,calls:a,run:(0,J.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]),f(r,(r,i)=>n.call({name:e,input:t},r,i)),r},[f,n]),answer:(0,J.useCallback)(async(e,t)=>{let r=u.current.find(t=>t.id===e),i=r?.call?.state;if(!r?.call||i?.phase!==`gate`)return;let a=r.call.callId,o=O(r.call),s=se({toolName:r.name,gate:i.gate,sessionPermissions:l.current,resolution:t});s.decision===`approve`&&(l.current=s.sessionPermissions);let c=k(r.events);d(e,e=>({...e,answering:t.action})),await f(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:l.current,...c?{snapshot:c}:{}}},e,t))},[f,n,d]),cancel:(0,J.useCallback)(e=>{s.current.get(e)?.abort(),s.current.delete(e)},[])}}function Ct(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,...e,children:(0,W.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=(0,J.lazy)(()=>ee(()=>import(`./ToolResultCharts-D2lBPHEZ.js`).then(e=>({default:e.ToolResultChart})),__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,78,79,80]))),Tt=236,Et=260;function Dt({layout:e,parts:t=[]}){let n=_(),r=v(),i=(0,J.useMemo)(()=>new Intl.NumberFormat(r,{maximumFractionDigits:2}),[r]),a=(0,J.useMemo)(()=>dt(e,t,n(`@theorem.host.image`)),[e,t,n]),[s,c]=(0,J.useState)(null);if(!ft(e,a))return null;let{images:l,audio:u}=a;return(0,W.jsxs)(o,{gap:3,children:[(0,W.jsxs)(Ne,{minWidth:Et,children:[e.figures.map(e=>(0,W.jsx)(M,{children:(0,W.jsx)(Me,{title:e.label,value:Ce(i.format(e.value),e.unit)})},`figure:${e.key}`)),e.charts.map(e=>(0,W.jsx)(J.Suspense,{fallback:(0,W.jsx)(M,{children:(0,W.jsx)(Ue,{height:Tt})}),children:(0,W.jsx)(M,{children:(0,W.jsx)(wt,{chart:e})})},`chart:${e.key}`)),l.map((e,t)=>(0,W.jsx)(M,{children:(0,W.jsx)(We,{label:e.alt||`Open image`,padding:0,onClick:()=>c(t),children:(0,W.jsx)(ue,{ratio:4/3,fit:`cover`,children:(0,W.jsx)(`img`,{src:e.src,alt:e.alt,loading:`lazy`})})})},`image:${e.src}`))]}),l.length>0?(0,W.jsx)(Ve,{isOpen:s!==null,onOpenChange:e=>{e||c(null)},media:l.map(e=>({src:e.src,alt:e.alt})),index:s??0,onIndexChange:c}):null,oe(u,e=>e.src).map(({item:e,key:t})=>(0,W.jsx)(M,{children:(0,W.jsx)(Fe,{src:e.src,mimeType:e.mimeType})},t))]})}function Ot({output:e,parts:t}){let n=_(),r=(0,J.useMemo)(()=>lt(e),[e]),i=(0,J.useMemo)(()=>r.figures.map(e=>e.key),[r]);return(0,W.jsx)(Ie,{value:e,title:n(`@theorem.host.response`),lead:(0,W.jsx)(Dt,{layout:r,parts:t}),ledKeys:i})}var kt=8,At={running:`accent`,gate:`warning`,complete:`success`,error:`error`,cancel:`neutral`};function jt(e,t,n){let r;try{r=JSON.parse(n)}catch{return{ok:!1,note:e(`@theorem.decision.invalid_json`)}}if(!S(r))return{ok:!1,note:e(`@theorem.decision.invalid_json`)};let i=he(t.inputSchema,r);return i.length>0?{ok:!1,note:e(`@theorem.host.missing`,{fields:i.join(`, `)}),input:r}:{ok:!0,input:r}}var Mt={function:Be,http:Le,mcp:Ct},Nt=440,Pt=2;function Ft(e,t){let n=e(`@theorem.host.kind.${t.kind}`);return t.description?`${n} · ${t.description}`:n}function It({tool:e}){let t=_();return e.access===`read-only`?null:(0,W.jsx)(s,{gap:1,wrap:`wrap`,children:(0,W.jsx)(m,{label:t(`@theorem.tool.access.${e.access}`),size:`sm`,color:e.access===`destructive`?`red`:`orange`})})}function Lt(e,t,n){return{label:t.call?ce(t.call):t.name,duration:t.isRunning?te(e,n-t.startedAt):t.elapsedMs==null?null:ne(e,t.elapsedMs)}}function Y({call:e,onAnswer:t}){let n=e.call?.state;return n?.phase===`gate`?n.gate.kind===`auth`?(0,W.jsx)(fe,{gate:n.gate,toolName:e.name,submitted:e.answering===`auth`,onAuthenticated:n=>void t(e.id,{action:`auth`,secret:n})}):(0,W.jsx)(de,{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 X(e){let t=e.call?.state;return!!q(e)||t?.phase===`complete`||!e.isRunning}function Z(e){let t=e.call?.state;return!X(e)&&t?.phase!==`gate`}function Rt({call:e,activity:t}){let n=e.call?.state,r=q(e);return(0,W.jsx)(He,{children:(0,W.jsxs)(o,{gap:3,children:[r?(0,W.jsx)(M,{children:(0,W.jsx)(y,{status:`error`,role:`alert`,title:r.title,description:r.description})}):null,n?.phase===`complete`?(0,W.jsx)(Ot,{output:n.output,parts:n.parts}):null,e.isRunning?null:(0,W.jsx)(M,{children:t})]})})}function zt({call:e,onAnswer:t}){let n=_(),{label:r,duration:i}=Lt(n,e,A(e.isRunning));if(Z(e))return(0,W.jsx)(j,{label:r,since:e.startedAt});let a=(0,W.jsx)(g,{size:`sm`,color:`secondary`,children:i?n(`@theorem.host.finished`,{activity:r,duration:i}):r});return(0,W.jsxs)(o,{gap:3,children:[(0,W.jsx)(Y,{call:e,onAnswer:t}),X(e)?(0,W.jsx)(Rt,{call:e,activity:a}):null]})}function Bt({calls:e,onPick:t}){let n=_(),r=v(),i=(0,J.useMemo)(()=>new Intl.DateTimeFormat(r,{timeStyle:`medium`}),[r]);return e.length===0?null:(0,W.jsxs)(o,{gap:1,children:[(0,W.jsx)(g,{type:`supporting`,color:`secondary`,as:`h3`,children:n(`@theorem.host.earlier`)}),(0,W.jsx)(Te,{hasDividers:!0,density:`compact`,children:e.slice(0,kt).map(e=>{let r=vt(e);return(0,W.jsx)(Ee,{label:e.name,startContent:(0,W.jsx)(K,{variant:At[r],label:n(`@theorem.host.status.${r}`),isPulsing:e.isRunning}),endContent:(0,W.jsx)(g,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:i.format(e.startedAt)}),onClick:()=>t(e)},e.id)})})]})}function Vt({tools:e,tool:t,check:n,text:r,view:i,shown:a,onText:s,onPick:c,onView:l,onRun:u,onStop:d}){let f=_(),p=`input`in n?n.input:void 0,m=i===`fields`&&p!==void 0;return(0,W.jsxs)(Oe,{title:f(`@theorem.host.request`),view:m?`fields`:`json`,hasFields:p!==void 0,onView:l,onRun:u,children:[(0,W.jsxs)(o,{gap:2,children:[(0,W.jsx)(Ge,{label:f(`@theorem.host.tool`),size:`sm`,options:e.map(e=>({value:e.name,label:e.name,icon:Mt[e.kind],description:Ft(f,e)})),value:t.name,hasSearch:e.length>8,renderOption:e=>(0,W.jsx)(`div`,{style:{width:Nt,maxWidth:`100%`,minWidth:0},children:(0,W.jsx)(Re,{icon:e.icon,label:e.label,description:e.description&&(0,W.jsx)(g,{type:`supporting`,color:`secondary`,maxLines:Pt,children:e.description})})}),onChange:c}),(0,W.jsx)(It,{tool:t})]}),m?(0,W.jsx)(Pe,{schema:t.inputSchema,value:p,onChange:e=>{s(w(e))}},t.name):(0,W.jsx)(Ae,{label:f(`@theorem.host.request`),text:r,isInvalid:p===void 0,onChange:s}),(0,W.jsx)(ke,{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 Ht(e,t,n,r){return!t||!n?.ok||r?.isRunning?null:e.run(t.name,n.input)}function Ut(e,t){let n=_(),[r,i]=(0,J.useState)(e.tools[0]?.name),[a,o]=(0,J.useState)({}),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(`fields`),{tool:d,text:f,shown:p,earlier:m}=yt({tools:e.tools,picked:r,drafts:a,calls:t.calls,shownId:s}),h=d?jt(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=Ht(t,d,h,p);e!==null&&c(e)},pick:e=>{i(e.name),o(t=>({...t,[e.name]:w(e.input)})),c(e.id)}}}function Wt({shown:e,earlier:t,onAnswer:n,onPick:r}){return(0,W.jsxs)(W.Fragment,{children:[e?(0,W.jsx)(zt,{call:e,onAnswer:n}):null,(0,W.jsx)(Bt,{calls:t,onPick:r})]})}function Gt(e,t,n,r,i){if(!e)return i;let a=r.length===0;return!n&&a?null:(0,W.jsx)(De,{label:t,fill:n!=null&&Z(n)&&a,children:i})}function Kt({transport:e,iface:t,host:n,maxWidth:r=`960px`,trace:i,flush:a,columns:o=!1,className:s,style:c}){let l=_(),u=ae(t,e.traces,i),d=Ut(t,n),{tool:f,check:p,shown:m,earlier:h}=d;return(0,W.jsxs)(je,{inspector:u,maxWidth:r,flush:a,columns:o,requestLabel:l(`@theorem.host.request`),className:s,style:c,children:[f&&p?(0,W.jsx)(Vt,{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,W.jsx)(we,{title:l(`@theorem.host.no_tools`)}),Gt(o,l(`@theorem.host.response`),m,h,(0,W.jsx)(Wt,{shown:m,earlier:h,onAnswer:n.answer,onPick:d.pick}))]})}function qt(e){let t=_(),n=St(e.transport,e.pageTools);return n.describeFailure?(0,W.jsx)(Ke,{title:n.describeFailure.error}):n.iface?(0,W.jsx)(Kt,{...e,iface:n.iface,host:n}):(0,W.jsx)(j,{label:t(`@theorem.chat.loading`)})}function Jt({endpoint:e,http:t,transport:n,theme:r,mode:i,labels:a,detectCodeLanguage:o,...s}){let c=(0,J.useRef)(t);c.current=t;let l=(0,J.useMemo)(()=>n??f({...c.current,endpoint:e}),[n,e]);return(0,W.jsx)(d,{theme:r,mode:i,children:(0,W.jsx)(re,{labels:a,children:(0,W.jsx)(ze,{detectCodeLanguage:o,children:(0,W.jsx)(qt,{...s,transport:l})})})})}var Yt=e({HostView:()=>$,StudioHostConsole:()=>Q});function Q(e){let t=Je(e,u,l);return(0,W.jsx)($,{...e,transport:t})}function $({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let o=(0,J.useMemo)(()=>le(e),[e]);return(0,W.jsx)(Jt,{detectCodeLanguage:!0,labels:pe,transport:t,pageTools:o,trace:n,flush:r,columns:i,className:a})}export{$ as HostView,Q as StudioHostConsole,ht as n,Yt 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{k as s}from"./browser-transport-
|
|
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{k as s}from"./browser-transport-Dg00IzNm.js";import{t as c}from"./mergeProps-ptS-gIMz.js";import{u as l}from"./fieldParts-B7DYLgh4.js";import{t as u}from"./Icon-BqkS-pIq.js";import{t as d}from"./Text-BOqCfzZC.js";import{n as f,t as p}from"./labels-provider-Bt3Q2GjB.js";import{t as ee}from"./Card-DruykyeB.js";import{n as m}from"./IconButton-DVUFx-8p.js";import{t as h}from"./CodeBlock-CfVOtDeO.js";import{t as g}from"./createReactComponent-CZwsv6DD.js";import{n as _}from"./ScrollableArea-BHfY7sWH.js";import{t as v}from"./IconEye-BB5aY-wQ.js";import{Kt as y}from"./tool-schema-CPVHlZ7w.js";import{A as te,Ir as ne,Or as re,a as b,wr as ie}from"./shaped-data-C4yaGRz9.js";import{O as ae}from"./turn-client-CZG4gVtX.js";import{n as x}from"./stub-DSUcPMOV.js";import{n as S,r as C}from"./CollapsibleGroup-FIawJRo4.js";var w=g(`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`}]]),T=[`cancelled`,`interrupted`,`length`,`filtered`,`provider_error`,`stream_incomplete`,`step_limit`],E=new Set(T);function D(e){return E.has(e)}function O(e,t,n){if(!e||!D(e.kind)||y(e)||t.some(e=>e.kind===`error`))return;let r=`stop.${e.kind}`;return ne(r,{},n)}function k(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:ie(e),error:re(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 A(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:ae(e.sessionPermissions,e.toolName,e.gate.permission)}}var j=`theorem.oauth_complete`;function M(e,t){if(e.source!==t.popup||e.origin!==t.origin)return!1;let n=e.data;return te(n)&&n.type===j&&n.slot===t.slot}function N(e){return{openMessage:{type:`draft`,profile:e.profile,customTools:e.customTools}}}function P(e){let t={};for(let n of e.customTools){if(n.type!==`function`||n.answeredBy!==`page`)continue;let e=n.stubResponse??x(n.outputSchema);t[n.name]=()=>({output:e})}return t}var F=t(),I={container:{kVAEAm:`x1n2onr6`,kzqmXN:`xh8yej3`,kVQacm:`x7giv3`,kAzted:`x2lwn1j`,kmuXW:`x2lah0s`,$$css:!0},ellipse:{kaIpWk:`x16rqkct`,$$css:!0}},L={ratio:e=>[{kOBAk4:e==null?e:`x10y9f9r`,$$css:!0},{"--x-aspectRatio":e??void 0}]};function R({ratio:e,shape:t=`rectangle`,fit:i,children:a,xstyle:o,className:s,style:l,ref:u,...d}){return(0,F.jsx)(`div`,{ref:u,...c(r(`aspect-ratio`,{shape:t}),n(I.container,L.ratio(e),t===`ellipse`&&I.ellipse,o),s,l),...d,children:(0,F.jsx)(`div`,{"data-astryx-aspect-ratio-override":i,...{0:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d`},8:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k`},4:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq`},12:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq`},2:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x492jj3`},10:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k x492jj3`},6:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq x492jj3`},14:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq x492jj3`},1:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x16lv2iq`},9:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k x16lv2iq`},5:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq x16lv2iq`},13:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq x16lv2iq`},3:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x16lv2iq`},11:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k x16lv2iq`},7:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d xyz6fim x1m6kvgq x16lv2iq`},15:{className:`x10l6tqk x13vifvy x1o0tod xh8yej3 x5yr21d x78zum5 x6s0dn4 xl56j7k xyz6fim x1m6kvgq x16lv2iq`}}[(i===`center`)<<3|(i===`cover`||i===`contain`)<<2|(i===`cover`)<<1|i===`contain`],children:a})})}R.displayName=`AspectRatio`;function z(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 B={citation:`last`};function V(e,t){if(!t)return[...e];let n=[],r=[],i=[];for(let a of e){let e=t[a.kind];e===`first`?n.push(a):e===`last`?i.push(a):r.push(a)}return[...n,...r,...i]}var H=new Set(T),U=new Set([`user-text`,`user-attachment`,`user-voice`]);function W(e){return U.has(e.kind)}function G(e){return e.kind===`turn-done`}function K(e,t){e?.kind===`user`?t.stop&&H.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=z(e.usage,t.tokens)),t.stop&&(e.stop=t.stop))}function q(e,t){return!e||e.kind!==(t?`user`:`assistant`)?!1:!(e.kind===`user`&&e.stop)}function J(e,t){let n=[];for(let r of e){if(r.kind===`turn-done`&&K(n.at(-1),r),G(r))continue;let e=W(r),i=n.at(-1);i&&q(i,e)&&!t?.has(r.id)?i.blocks.push(r):n.push({kind:e?`user`:`assistant`,key:r.id,blocks:[r]})}return n}function oe(e){return e.filter(e=>e.kind===`text`).map(e=>e.text).filter(Boolean).join(`
|
|
2
2
|
|
|
3
3
|
`)}function se(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 ce(e){return e.kind===`tool`&&e.tool.state?.phase===`gate`}function le(e){for(let t=e.length-1;t>=0;--t)if(e[t]?.kind===`tool`)return t;return-1}function ue(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 de(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`?ue(e,t,n,r):r.push(e)}function fe(e,t){let n=e.filter(e=>!G(e)),r=n.find(ce),i=r?[r]:[],a=n.filter(e=>e!==r),o=le(a),s=o>=0,c=[],l=[];for(let[e,t]of a.entries())de(t,{hasTools:s,index:e,lastToolIndex:o},c,l);return{trace:c,gatedTools:i,body:V(l,t?.bodyKindPlacement??B),hasTrace:c.length>0}}function pe(e){let t=e.at(-1);return t?.kind===`user`?t:void 0}function Y(e,t){let n=e[t-1];return n?.kind===`user`?X(n):e[t]?.key??String(t)}function X(e){return`${e.key}:reply`}function me(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 he(e){let t=Y(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 ge(e){let t=e.state?.phase;return t===`cancel`?b(e.name):(t===`complete`||t===`error`?e.activityPast:e.activity)??b(e.name)}var Z=e(i(),1);function _e(e,t,n,r){let i=t.request??e(`@theorem.gate.approval.use_tool`,{tool:b(n).toLowerCase()});return r?e(`@theorem.gate.approval.title`,{agent:r,request:i}):e(`@theorem.gate.approval.title_no_agent`,{request:i})}function ve(e){return typeof e==`string`?e:e==null?``:JSON.stringify(e,null,2)}function Q(e){return(0,F.jsx)(ee,{variant:`bubble`,elevation:`med`,maxWidth:400,children:(0,F.jsxs)(a,{gap:3,children:[(0,F.jsxs)(o,{justify:`between`,align:`start`,gap:3,children:[(0,F.jsx)(d,{type:`large`,weight:`semibold`,children:e.heading}),e.tag]}),e.children]})})}var ye={"read-only":v,"read-write":s,destructive:w};function be({access:e}){let t=f();return(0,F.jsxs)(o,{gap:1,align:`center`,children:[(0,F.jsx)(u,{icon:ye[e],size:`sm`,color:e===`destructive`?`error`:`secondary`}),(0,F.jsx)(d,{type:`supporting`,textWrap:`nowrap`,children:t(`@theorem.tool.access.${e}`)})]})}function $(e){return(0,F.jsx)(p,{children:(0,F.jsx)(xe,{...e})})}function xe({gate:e,toolName:t,agent:n,input:r,decided:i=null,onDecision:a}){let s=f(),c=ve(e.preparedArguments??r);return(0,F.jsxs)(Q,{heading:_e(s,e,t,n),tag:e.access?(0,F.jsx)(be,{access:e.access}):null,children:[e.summary?(0,F.jsx)(d,{color:`secondary`,children:e.summary}):null,c?(0,F.jsx)(S,{defaultIsOpen:!1,trigger:(0,F.jsx)(d,{type:`supporting`,children:s(`@theorem.gate.approval.input`)}),children:(0,F.jsx)(h,{code:c,language:`json`,size:`sm`})}):null,(0,F.jsxs)(o,{gap:2,justify:`end`,children:[(0,F.jsx)(m,{label:s(`@theorem.gate.approval.deny`),variant:`ghost`,isLoading:i===`deny`,isDisabled:i===`allow`,onClick:()=>a?.(`deny`)}),(0,F.jsx)(m,{label:s(`@theorem.gate.approval.approve`),variant:`primary`,isLoading:i===`allow`,isDisabled:i===`deny`,onClick:()=>a?.(`allow`)})]})]})}function Se({challenge:e}){let t=f();return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(d,{color:`secondary`,children:e.message}),e.resource?(0,F.jsx)(d,{type:`supporting`,color:`secondary`,children:t(`@theorem.gate.auth.resource`,{resource:e.resource})}):null,e.requiredScopes?.length?(0,F.jsx)(o,{gap:1,wrap:`wrap`,children:e.requiredScopes.map(e=>(0,F.jsx)(l,{label:e,size:`sm`},e))}):null]})}function Ce(e){return(0,F.jsx)(p,{children:(0,F.jsx)(Te,{...e})})}function we(e,t){let[n,r]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{if(!n)return;function i(i){n&&M(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 Te({gate:e,toolName:t,onAuthenticated:n,submitted:r=!1}){let i=f(),a=e.authChallenge,{authType:o,slot:s}=a,[c,l]=(0,Z.useState)(``),u=we(s,(0,Z.useCallback)(()=>n?.(),[n]));function p(){let e=c.trim();e&&(l(``),n?.(e))}return(0,F.jsxs)(Q,{heading:i(`@theorem.gate.auth.title`,{tool:b(t).toLowerCase()}),tag:(0,F.jsx)(d,{type:`supporting`,textWrap:`nowrap`,children:i(`@theorem.gate.tag.${o}`)}),children:[(0,F.jsx)(Se,{challenge:a}),(0,F.jsx)(Ee,{authType:o,authUrl:a.authorizationUrl,slot:s,secret:c,submitted:r,onSecretChange:l,onSubmit:p,onOpenSignIn:u})]})}function Ee(e){let t=f();if(e.submitted)return(0,F.jsx)(C,{variant:`success`,label:t(`@theorem.gate.auth.provided`,{slot:e.slot})});if(e.authType===`oauth2`)return e.authUrl?(0,F.jsx)(o,{justify:`end`,children:(0,F.jsx)(m,{label:t(`@theorem.gate.auth.authorize`),variant:`primary`,onClick:()=>{e.authUrl&&e.onOpenSignIn(e.authUrl)}})}):(0,F.jsx)(d,{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,F.jsxs)(o,{gap:2,align:`end`,children:[(0,F.jsx)(_,{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,F.jsx)(m,{label:t(`@theorem.gate.auth.submit`),variant:`primary`,isDisabled:!e.secret.trim(),onClick:e.onSubmit})]})}var De={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{A as _,he as a,w as b,pe as c,Y as d,ge as f,P as g,N as h,oe as i,X as l,R as m,$ as n,fe as o,se as p,Ce as r,J as s,De as t,me as u,k as v,O 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{c as o,i as s,l as c}from"./SegmentedControlItem-BBGRPrxp.js";import{t as l}from"./VStack-CkVMcNiK.js";import{n as u,t as d}from"./StackItem-CQviqAfM.js";import{A as f,E as p,S as m,g as h,s as g,t as _}from"./browser-transport-LV_FgVKG.js";import{t as v}from"./mergeProps-ptS-gIMz.js";import{l as y}from"./fieldParts-B7DYLgh4.js";import{t as b}from"./Icon-BqkS-pIq.js";import{d as x,f as S,h as C,o as ee,u as w}from"./use-trace-records-B1vrKQmA.js";import{t as T}from"./Text-BOqCfzZC.js";import{a as E,n as D,t as O}from"./labels-provider-Bt3Q2GjB.js";import{a as k,c as A,n as j,t as M}from"./IconButton-DVUFx-8p.js";import{t as N}from"./Dialog-Sd04KQS2.js";import{t as P}from"./createReactComponent-CZwsv6DD.js";import{a as F,i as I,t as L}from"./Banner-DNuB7lhC.js";import{t as R}from"./Center-nHS1JSux.js";import{_ as te,g as ne,h as re,m as ie,n as ae,r as oe,t as se}from"./studio-labels-7sgmTzU-.js";import{c as z}from"./host-patterns-F-KZIzkF.js";import{Ir as ce,Sr as B,er as le,tr as ue}from"./shaped-data-C4yaGRz9.js";import{S as V,g as de,r as fe,t as H}from"./reader-D_UCUUJt.js";import{i as U}from"./live-ingress-OuSlQ6q7.js";import{i as pe,v as me}from"./turn-client-CZG4gVtX.js";import{r as he,t as ge}from"./live-messages-DzRBDO3t.js";import"./use-second-ticker-BSCE_-wM.js";import{t as _e}from"./EmptyState-C_uF9Wyj.js";import{Ct as ve,G as ye,Mt as be,S as xe,St as Se,i as W,mt as Ce,p as we,q as Te,xt as Ee,z as De}from"./index-3PUx0L6S.js";var Oe=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`}]]),ke=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`}]]),Ae=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`}]]),je=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`}]]),Me=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`}]]),Ne=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`}]]),Pe=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 Fe(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 Ie(e){return!(e.isMuted||!e.socketOpen||e.modelPlaying&&e.rms<e.bargeInRmsWhileSpeaking)}function Le(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 Re(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 ze(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 Be=`mic-capture-processor`;function Ve(){return new URL(`data:text/javascript;base64,LyoqCiAqIEF1ZGlvV29ya2xldCBwcm9jZXNzb3IgdGhhdCBmb3J3YXJkcyBtb25vIG1pYyBmcmFtZXMgdG8gdGhlIG1haW4gdGhyZWFkLgogKiBQbGFpbiBKUzogaXQgcnVucyBpbiB0aGUgQXVkaW9Xb3JrbGV0R2xvYmFsU2NvcGUgYXMgaXRzIG93biBtb2R1bGUsIGxvYWRlZAogKiBieSBVUkwgKHNlZSBgLi4vbWljLWNhcHR1cmUudHNgKSwgc28gaXQgaW1wb3J0cyBub3RoaW5nIGFuZCBzaGlwcyBhcyBpcy4KICovCnJlZ2lzdGVyUHJvY2Vzc29yKAogICdtaWMtY2FwdHVyZS1wcm9jZXNzb3InLAogIGNsYXNzIE1pY0NhcHR1cmVQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogICAgcHJvY2VzcyhpbnB1dHMpIHsKICAgICAgY29uc3QgY2hhbm5lbCA9IGlucHV0c1swXVswXTsKICAgICAgY29uc3QgY29weSA9IG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZShjb3B5LCBbY29weS5idWZmZXJdKTsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgfSwKKTsK`,``+import.meta.url)}function He(e,t,n=16e3){if(t===n)return Ue(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]=We(i>0?n/i:0),o++,s=t}return a}function Ue(e){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=We(e[n]??0);return t}function We(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 z(`internal`,B(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=Ee(e.inputFloat32),n=e.hasPlaybackNodes||e.status===`speaking`;return Ie({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 z(`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 z(`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 z(`timeout`,`live connect timed out`))},2e4),this.ws.onmessage=e=>{this.enqueueServerMessage(e.data)},this.ws.onclose=()=>{this.opening?this.failOpen(new z(`network`,`live socket closed before ready`)):this.handleDrop()},this.ws.onerror=()=>{!this.opening&&this.providerState&&!this.sessionOver?this.handleDrop():this.failOpen(new z(`network`,`live socket error`))}}catch(e){this.failOpen(new z(`internal`,B(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=ze(e);this.failSession(new z(t?`auth`:`internal`,B(e),{cause:e,copy:{key:t?`voice.permission`:`voice.unavailable`}}))}finally{this.micActivating=!1}}}sendMicFrame(e,t){let n=He(e,t,16e3),r=ue(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?.(Se(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(Ve()),!0),this.micWorklet=new AudioWorkletNode(this.audioContext,Be),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?.(ve(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:pe(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=he(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(V(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?.(V(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`:Re(e.tool,t);break;case`done`:this.handleDoneTurnEvent(e)}}handleEvidenceTurnEvent(e){let t=Le(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 z(`request`,`live session is not connected`);let n=ge.safeParse({...e,type:`executeTool`});if(!n.success||n.data.type!==`executeTool`)throw new z(`request`,ce(`error.request`));let r=n.data;if(this.pendingExecuteResults.has(r.operationId))throw new z(`request`,ce(`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=le(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`?me(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{c as o,i as s,l as c}from"./SegmentedControlItem-BBGRPrxp.js";import{t as l}from"./VStack-CkVMcNiK.js";import{n as u,t as d}from"./StackItem-CQviqAfM.js";import{A as f,E as p,S as m,g as h,s as g,t as _}from"./browser-transport-Dg00IzNm.js";import{t as v}from"./mergeProps-ptS-gIMz.js";import{l as y}from"./fieldParts-B7DYLgh4.js";import{t as b}from"./Icon-BqkS-pIq.js";import{d as x,f as S,h as C,o as ee,u as w}from"./use-trace-records-B1vrKQmA.js";import{t as T}from"./Text-BOqCfzZC.js";import{a as E,n as D,t as O}from"./labels-provider-Bt3Q2GjB.js";import{a as k,c as A,n as j,t as M}from"./IconButton-DVUFx-8p.js";import{t as N}from"./Dialog-Sd04KQS2.js";import{t as P}from"./createReactComponent-CZwsv6DD.js";import{a as F,i as I,t as L}from"./Banner-O0C5KVNy.js";import{t as R}from"./Center-nHS1JSux.js";import{_ as te,g as ne,h as re,m as ie,n as ae,r as oe,t as se}from"./studio-labels-1m3jxSy0.js";import{c as z}from"./host-patterns-F-KZIzkF.js";import{Ir as ce,Sr as B,er as le,tr as ue}from"./shaped-data-C4yaGRz9.js";import{S as V,g as de,r as fe,t as H}from"./reader-D_UCUUJt.js";import{i as U}from"./live-ingress-OuSlQ6q7.js";import{i as pe,v as me}from"./turn-client-CZG4gVtX.js";import{r as he,t as ge}from"./live-messages-DzRBDO3t.js";import"./use-second-ticker-BSCE_-wM.js";import{t as _e}from"./EmptyState-C_uF9Wyj.js";import{Ct as ve,G as ye,Mt as be,S as xe,St as Se,i as W,mt as Ce,p as we,q as Te,xt as Ee,z as De}from"./index-Cl8kUfgj.js";var Oe=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`}]]),ke=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`}]]),Ae=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`}]]),je=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`}]]),Me=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`}]]),Ne=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`}]]),Pe=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 Fe(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 Ie(e){return!(e.isMuted||!e.socketOpen||e.modelPlaying&&e.rms<e.bargeInRmsWhileSpeaking)}function Le(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 Re(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 ze(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 Be=`mic-capture-processor`;function Ve(){return new URL(`data:text/javascript;base64,LyoqCiAqIEF1ZGlvV29ya2xldCBwcm9jZXNzb3IgdGhhdCBmb3J3YXJkcyBtb25vIG1pYyBmcmFtZXMgdG8gdGhlIG1haW4gdGhyZWFkLgogKiBQbGFpbiBKUzogaXQgcnVucyBpbiB0aGUgQXVkaW9Xb3JrbGV0R2xvYmFsU2NvcGUgYXMgaXRzIG93biBtb2R1bGUsIGxvYWRlZAogKiBieSBVUkwgKHNlZSBgLi4vbWljLWNhcHR1cmUudHNgKSwgc28gaXQgaW1wb3J0cyBub3RoaW5nIGFuZCBzaGlwcyBhcyBpcy4KICovCnJlZ2lzdGVyUHJvY2Vzc29yKAogICdtaWMtY2FwdHVyZS1wcm9jZXNzb3InLAogIGNsYXNzIE1pY0NhcHR1cmVQcm9jZXNzb3IgZXh0ZW5kcyBBdWRpb1dvcmtsZXRQcm9jZXNzb3IgewogICAgcHJvY2VzcyhpbnB1dHMpIHsKICAgICAgY29uc3QgY2hhbm5lbCA9IGlucHV0c1swXVswXTsKICAgICAgY29uc3QgY29weSA9IG5ldyBGbG9hdDMyQXJyYXkoY2hhbm5lbCk7CiAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZShjb3B5LCBbY29weS5idWZmZXJdKTsKICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgfSwKKTsK`,``+import.meta.url)}function He(e,t,n=16e3){if(t===n)return Ue(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]=We(i>0?n/i:0),o++,s=t}return a}function Ue(e){let t=new Int16Array(e.length);for(let n=0;n<e.length;n++)t[n]=We(e[n]??0);return t}function We(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 z(`internal`,B(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=Ee(e.inputFloat32),n=e.hasPlaybackNodes||e.status===`speaking`;return Ie({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 z(`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 z(`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 z(`timeout`,`live connect timed out`))},2e4),this.ws.onmessage=e=>{this.enqueueServerMessage(e.data)},this.ws.onclose=()=>{this.opening?this.failOpen(new z(`network`,`live socket closed before ready`)):this.handleDrop()},this.ws.onerror=()=>{!this.opening&&this.providerState&&!this.sessionOver?this.handleDrop():this.failOpen(new z(`network`,`live socket error`))}}catch(e){this.failOpen(new z(`internal`,B(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=ze(e);this.failSession(new z(t?`auth`:`internal`,B(e),{cause:e,copy:{key:t?`voice.permission`:`voice.unavailable`}}))}finally{this.micActivating=!1}}}sendMicFrame(e,t){let n=He(e,t,16e3),r=ue(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?.(Se(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(Ve()),!0),this.micWorklet=new AudioWorkletNode(this.audioContext,Be),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?.(ve(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:pe(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=he(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(V(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?.(V(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`:Re(e.tool,t);break;case`done`:this.handleDoneTurnEvent(e)}}handleEvidenceTurnEvent(e){let t=Le(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 z(`request`,`live session is not connected`);let n=ge.safeParse({...e,type:`executeTool`});if(!n.success||n.data.type!==`executeTool`)throw new z(`request`,ce(`error.request`));let r=n.data;if(this.pendingExecuteResults.has(r.operationId))throw new z(`request`,ce(`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=le(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`?me(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&&Ce(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{p as r}from"./fieldParts-B7DYLgh4.js";import{t as i}from"./Icon-BqkS-pIq.js";import{t as a}from"./Text-BOqCfzZC.js";import{n as o,t as s}from"./IconButton-DVUFx-8p.js";import{t as c}from"./createReactComponent-CZwsv6DD.js";import{n as l,t as u}from"./ScrollableArea-BHfY7sWH.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-DfG6CXsC.js";import{F as v,i as y}from"./workspace-CzTPlUdi.js";import{a as b,n as x,r as S}from"./studio-session-yEqFQo5o.js";import{t as C}from"./EmptyState-C_uF9Wyj.js";import{$ as w,Et as T,F as E,J as D,Lt as O,Q as k,Rt as A,Tt as j,X as M,Z as N,et as P,n as F,nt as I,u as L}from"./index-3PUx0L6S.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,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??``):r.get(e.stageAgentKey??``);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:I(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 ee(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 te(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 ne={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 re(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=ne[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 ie(e){return e.kind===`tool`||e.kind===`shared`?2:1}var ae=24,q=8,J=16;function oe(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 se(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||ie(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(oe(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:w,ports:E}=x,{right:D,bottom:O}=x,{spans:k,rails:A}=_(E),M=a/2,N=Math.max(o/2,u),P=[],F=new Map,I=Math.max(a,...y.map(e=>e*J)),L=K(e).flatMap(({link:e,from:t,to:n})=>{let i=E.get(e.from),o=E.get(e.to);if(!i||!o)return[];let s=w.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)+M&&e.x+e.width>Math.min(i.left,o.left)),l=Math.max(r,a,...c.map(e=>e.x+e.width))+M;return D=Math.max(D,l),[{link:e,from:t,to:n,d:j({x:r,y:i.y},{x:a,y:o.y},l).d}]}let c=k.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+(A.get(`${y}:${f}`)??0))*J,Math.max(v-J,0)),x=v<32?j(p,m):T(p,m,b,q),S=(e,t)=>t>e.y-N&&t<e.y+e.height+N,C=Math.abs(m.x-p.x)<I+a?[]:s.filter(e=>Array.from({length:23},(e,t)=>x.at((t+1)/ae)).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[L,R]=[Math.min(p.x,m.x),Math.max(p.x,m.x)],z=e=>{let t=[...C];for(;;){let n=e<0?Math.min(...t.map(e=>e.y))-N:Math.max(...t.map(e=>e.y+e.height))+N,r=[...s,...P].filter(e=>!t.includes(e)&&e.x<R&&e.x+e.width>L&&S(e,n));if(r.length===0)return n;t.push(...r)}},B=e=>Math.abs(i.y-e)+Math.abs(o.y-e),V=`${f}:${y}`,H=F.get(V)??(()=>{let[e,t]=[z(-1),z(1)],n=e>=0&&B(e)<=B(t)?e:t;return P.push({id:``,x:L,y:n-q+N,width:R-L,height:2*(q-N)}),F.set(V,n),n})();O=Math.max(O,H);let U=d?p.x+l*J:b,W=d?b:m.x-l*J,G={x:(U+W)/2,y:H};return[{link:e,from:t,to:n,d:T(p,G,U,q).d+T(G,m,W,q).d.replace(/^M \S+ \S+/,``)}]});return{width:Math.max((b[Math.max(e.columns.length-1,0)]??l)+r.width,D)+l,height:Math.max(O,l)+l,nodes:S,headings:C,lines:L}}var Y=e(n(),1),ce={tokens:{},detail:{},expanded:!1},X=e=>e===void 0?`${x}.map`:`${x}.map.project:${e}`;function le(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 ue(e){try{let t=JSON.parse(b()?.getItem(X(e))??`null`);return S(t)?{tokens:le(t.tokens),detail:le(t.detail),expanded:t.expanded===!0,...typeof t.family==`string`?{family:t.family}:{}}:ce}catch{return ce}}function de(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 fe(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 pe(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 me=(e,t)=>Math.min(Math.max(e,0),Math.max(t,0));function he(e,t){let n=0,r=120,i=()=>{--r;let a=fe(e);if(a&&a.scrollWidth>a.clientWidth){let e=t(a),n=me(e.left,a.scrollWidth-a.clientWidth),r=me(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 ge=e=>e.button===0&&e.pointerType!==`touch`;function _e(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 ve(e){let[t,n]=(0,Y.useState)(!1);return{panning:t,pan:t=>{if(!ge(t)||t.target.closest(e))return;let r=fe(t.currentTarget);if(!r)return;let{scrollLeft:i,scrollTop:a}=r;n(!0),_e(t,(e,t)=>{r.scrollTo({left:i-e,top:a-t,behavior:`instant`})},()=>{n(!1)})}}}var Z=t(),ye={node:{width:240,height:24},card:{head:60,row:28,foot:4},columnGap:96,rowGap:6,heading:24,groupGap:16,padding:24,lineGap:8},be={...ye,node:{width:240,height:84}},xe=28;function Se(e){return e.length>xe?`${e.slice(0,27)}…`:e}function Ce({kind:e,type:t,note:n}){return(e===`agent`?w(t):void 0)||(e===`tool`?P(t??``):e===`model`?L(n)??F.modelBinding:e===`provider`?A:e===`shared`&&t&&Object.hasOwn(F,t)?F[t]:e===`agent`?k.text:O)}function we(e){return Object.hasOwn(F,e)?F[e]:O}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 Te=4,Ee=24,De={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};function Oe(e){let t=D()?.name,[n,r]=(0,Y.useState)(()=>ue(t)),i=e=>{r(e),de(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:te(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 ke(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||!ge(o))return;let c;_e(o,(e,r)=>{!c&&Math.hypot(e,r)<Te||(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?De[r.key]:void 0,o=e.nodes[i];if(!a||!o)return;r.preventDefault();let s=Math.max(o.x+a.x*Ee,0),c=Math.max(o.y+a.y*Ee,0);n({...t,[i]:{x:s,y:c}},!0)}})}}function Ae(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 je(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 he(n,e=>{let{left:t,top:r}=pe(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 Me(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 Ne({actions:e,query:t,onQuery:n,onClose:a}){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)(o,{label:`Show everything`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:p,size:`sm`}),onClick:()=>{f(void 0)}}),d&&(0,Z.jsx)(o,{label:`Tidy`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:V,size:`sm`}),onClick:g}),(0,Z.jsx)(s,{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)(s,{label:`Close map`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:r,size:`sm`}),tooltip:`Close the map`,onClick:a})]})}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 Pe(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)(M,{id:t.id,label:Se(t.long??t.label),icon:Ce(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>xe?t.long??t.label:void 0,"aria-current":l?`true`:void 0,...$(e),...o(t.id),...s})}function Fe(e){let{node:t,place:n,joins:r,selected:o,on:s,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:Ce(t),size:`sm`}),(0,Z.jsx)(a,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:t.label})]}),t.note&&(0,Z.jsx)(a,{type:`supporting`,maxLines:f.length>0?1:ie(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,o)?`true`:void 0,children:m}):(0,Z.jsxs)(`div`,{className:`studio-map-card`,"data-map-token":t.id,style:p,"data-open":Q(t,o)?``:void 0,...$(e),...u,children:[(0,Z.jsx)(`button`,{...h,className:`studio-map-head`,"aria-current":o===t.id?`true`:void 0,children:m}),f.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`studio-map-row`,"aria-current":o===e.id?`true`:void 0,"data-on":s.has(e.id)?``:void 0,onClick:()=>{c(e.opens)},...l(e.id),children:[(0,Z.jsx)(i,{icon:we(e.type),size:`sm`}),(0,Z.jsx)(a,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:e.label}),e.note&&(0,Z.jsx)(a,{type:`supporting`,maxLines:1,justify:`end`,hasTruncateTooltip:!1,className:`studio-map-row-note`,children:e.note})]},e.id))]})}function Ie({workspace:e,shared:t,selected:n,onOpen:r,onClose:o}){let{expanded:s,family:c,map:l,moved:d,put:p,showFamily:h,expand:g}=Oe((0,Y.useMemo)(()=>W(e,t),[e,t])),[_,v]=(0,Y.useState)(``),y=(0,Y.useMemo)(()=>ee(l,_),[l,_]),b=(0,Y.useMemo)(()=>_.trim()===``?l:te(l,y),[l,_,y]),x=_.trim()!==``&&y.length===0,S=(0,Y.useRef)(null),w=s?be:ye,T=(0,Y.useMemo)(()=>({map:b,expanded:s}),[b,s]),D=N(S,T),O=(0,Y.useMemo)(()=>se(b,w,{moved:d,widths:D,detail:s}),[b,w,s,d,D]),k=b.columns.flat().flatMap(e=>e.nodes),A=k.find(e=>Q(e,n))?.id;je(S,c,{place:A===void 0?void 0:O.nodes[A],sizes:w});let{dragging:j,draggable:M}=ke(O,d,p),{panning:P,pan:F}=ve(`[data-map-node]`),{lit:I,on:L,onLines:R,lights:z}=Ae(O),B={family:c,expanded:s,isMoved:k.some(e=>Object.hasOwn(d,e.id)),showFamily:h,expand:g,tidy:()=>{p({},!0)}},[V,H]=(0,Y.useState)(),U=Me(k.find(e=>e.id===V),r,B),G=s?Fe:Pe,K=k.find(e=>Q(e,n))?.id,ne=e=>R.has(e.link)?2:+(e.from===K||e.to===K),ie=[...O.lines].sort((e,t)=>ne(e)-ne(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)(E,{items:U,label:`Map actions`,"data-map-field":``,children:(0,Z.jsxs)(`div`,{ref:S,className:`studio-map`,"data-lit":I===void 0||j!==void 0?void 0:``,"data-panning":P?``:void 0,onPointerDown:F,onContextMenuCapture:e=>{H(e.target.closest(`[data-map-node]`)?.dataset.mapNode)},style:{"--map-width":`${String(O.width)}px`,"--map-height":`${String(O.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:O.width,height:O.height,"aria-hidden":`true`,children:ie.map(({link:e,from:t,to:n,d:r})=>(0,Z.jsx)(`path`,{className:`map-line`,d:r,"data-kind":e.kind,"data-on":R.has(e)?``:void 0,"data-open":t===K||n===K?``:void 0},`${e.kind}:${e.from}:${e.to}`))}),O.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)(a,{type:`supporting`,color:`secondary`,weight:`semibold`,children:e})},e)),k.map(e=>{let t=O.nodes[e.id];return t&&(0,Z.jsx)(G,{node:e,place:t,joins:re(b,e.id),selected:n,on:L,isFound:y.includes(e.id),isDragging:j===e.id,onOpen:r,lights:z,drag:M(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)(Ne,{actions:B,query:_,onQuery:v,onClose:o})]})}export{Ie as StudioMap};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{p as r}from"./fieldParts-B7DYLgh4.js";import{t as i}from"./Icon-BqkS-pIq.js";import{t as a}from"./Text-BOqCfzZC.js";import{n as o,t as s}from"./IconButton-DVUFx-8p.js";import{t as c}from"./createReactComponent-CZwsv6DD.js";import{n as l,t as u}from"./ScrollableArea-BHfY7sWH.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-DfG6CXsC.js";import{F as v,i as y}from"./workspace-CzTPlUdi.js";import{a as b,n as x,r as S}from"./studio-session-yEqFQo5o.js";import{t as C}from"./EmptyState-C_uF9Wyj.js";import{$ as w,Et as T,F as E,J as D,Lt as O,Q as k,Rt as A,Tt as j,X as M,Z as N,et as P,n as F,nt as I,u as L}from"./index-Cl8kUfgj.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,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??``):r.get(e.stageAgentKey??``);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:I(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 ee(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 te(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 ne={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 re(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=ne[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 ie(e){return e.kind===`tool`||e.kind===`shared`?2:1}var ae=24,q=8,J=16;function oe(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 se(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||ie(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(oe(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:w,ports:E}=x,{right:D,bottom:O}=x,{spans:k,rails:A}=_(E),M=a/2,N=Math.max(o/2,u),P=[],F=new Map,I=Math.max(a,...y.map(e=>e*J)),L=K(e).flatMap(({link:e,from:t,to:n})=>{let i=E.get(e.from),o=E.get(e.to);if(!i||!o)return[];let s=w.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)+M&&e.x+e.width>Math.min(i.left,o.left)),l=Math.max(r,a,...c.map(e=>e.x+e.width))+M;return D=Math.max(D,l),[{link:e,from:t,to:n,d:j({x:r,y:i.y},{x:a,y:o.y},l).d}]}let c=k.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+(A.get(`${y}:${f}`)??0))*J,Math.max(v-J,0)),x=v<32?j(p,m):T(p,m,b,q),S=(e,t)=>t>e.y-N&&t<e.y+e.height+N,C=Math.abs(m.x-p.x)<I+a?[]:s.filter(e=>Array.from({length:23},(e,t)=>x.at((t+1)/ae)).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[L,R]=[Math.min(p.x,m.x),Math.max(p.x,m.x)],z=e=>{let t=[...C];for(;;){let n=e<0?Math.min(...t.map(e=>e.y))-N:Math.max(...t.map(e=>e.y+e.height))+N,r=[...s,...P].filter(e=>!t.includes(e)&&e.x<R&&e.x+e.width>L&&S(e,n));if(r.length===0)return n;t.push(...r)}},B=e=>Math.abs(i.y-e)+Math.abs(o.y-e),V=`${f}:${y}`,H=F.get(V)??(()=>{let[e,t]=[z(-1),z(1)],n=e>=0&&B(e)<=B(t)?e:t;return P.push({id:``,x:L,y:n-q+N,width:R-L,height:2*(q-N)}),F.set(V,n),n})();O=Math.max(O,H);let U=d?p.x+l*J:b,W=d?b:m.x-l*J,G={x:(U+W)/2,y:H};return[{link:e,from:t,to:n,d:T(p,G,U,q).d+T(G,m,W,q).d.replace(/^M \S+ \S+/,``)}]});return{width:Math.max((b[Math.max(e.columns.length-1,0)]??l)+r.width,D)+l,height:Math.max(O,l)+l,nodes:S,headings:C,lines:L}}var Y=e(n(),1),ce={tokens:{},detail:{},expanded:!1},X=e=>e===void 0?`${x}.map`:`${x}.map.project:${e}`;function le(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 ue(e){try{let t=JSON.parse(b()?.getItem(X(e))??`null`);return S(t)?{tokens:le(t.tokens),detail:le(t.detail),expanded:t.expanded===!0,...typeof t.family==`string`?{family:t.family}:{}}:ce}catch{return ce}}function de(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 fe(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 pe(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 me=(e,t)=>Math.min(Math.max(e,0),Math.max(t,0));function he(e,t){let n=0,r=120,i=()=>{--r;let a=fe(e);if(a&&a.scrollWidth>a.clientWidth){let e=t(a),n=me(e.left,a.scrollWidth-a.clientWidth),r=me(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 ge=e=>e.button===0&&e.pointerType!==`touch`;function _e(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 ve(e){let[t,n]=(0,Y.useState)(!1);return{panning:t,pan:t=>{if(!ge(t)||t.target.closest(e))return;let r=fe(t.currentTarget);if(!r)return;let{scrollLeft:i,scrollTop:a}=r;n(!0),_e(t,(e,t)=>{r.scrollTo({left:i-e,top:a-t,behavior:`instant`})},()=>{n(!1)})}}}var Z=t(),ye={node:{width:240,height:24},card:{head:60,row:28,foot:4},columnGap:96,rowGap:6,heading:24,groupGap:16,padding:24,lineGap:8},be={...ye,node:{width:240,height:84}},xe=28;function Se(e){return e.length>xe?`${e.slice(0,27)}…`:e}function Ce({kind:e,type:t,note:n}){return(e===`agent`?w(t):void 0)||(e===`tool`?P(t??``):e===`model`?L(n)??F.modelBinding:e===`provider`?A:e===`shared`&&t&&Object.hasOwn(F,t)?F[t]:e===`agent`?k.text:O)}function we(e){return Object.hasOwn(F,e)?F[e]:O}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 Te=4,Ee=24,De={ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0},ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1}};function Oe(e){let t=D()?.name,[n,r]=(0,Y.useState)(()=>ue(t)),i=e=>{r(e),de(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:te(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 ke(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||!ge(o))return;let c;_e(o,(e,r)=>{!c&&Math.hypot(e,r)<Te||(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?De[r.key]:void 0,o=e.nodes[i];if(!a||!o)return;r.preventDefault();let s=Math.max(o.x+a.x*Ee,0),c=Math.max(o.y+a.y*Ee,0);n({...t,[i]:{x:s,y:c}},!0)}})}}function Ae(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 je(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 he(n,e=>{let{left:t,top:r}=pe(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 Me(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 Ne({actions:e,query:t,onQuery:n,onClose:a}){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)(o,{label:`Show everything`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:p,size:`sm`}),onClick:()=>{f(void 0)}}),d&&(0,Z.jsx)(o,{label:`Tidy`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:V,size:`sm`}),onClick:g}),(0,Z.jsx)(s,{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)(s,{label:`Close map`,variant:`ghost`,size:`sm`,icon:(0,Z.jsx)(i,{icon:r,size:`sm`}),tooltip:`Close the map`,onClick:a})]})}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 Pe(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)(M,{id:t.id,label:Se(t.long??t.label),icon:Ce(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>xe?t.long??t.label:void 0,"aria-current":l?`true`:void 0,...$(e),...o(t.id),...s})}function Fe(e){let{node:t,place:n,joins:r,selected:o,on:s,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:Ce(t),size:`sm`}),(0,Z.jsx)(a,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:t.label})]}),t.note&&(0,Z.jsx)(a,{type:`supporting`,maxLines:f.length>0?1:ie(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,o)?`true`:void 0,children:m}):(0,Z.jsxs)(`div`,{className:`studio-map-card`,"data-map-token":t.id,style:p,"data-open":Q(t,o)?``:void 0,...$(e),...u,children:[(0,Z.jsx)(`button`,{...h,className:`studio-map-head`,"aria-current":o===t.id?`true`:void 0,children:m}),f.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`studio-map-row`,"aria-current":o===e.id?`true`:void 0,"data-on":s.has(e.id)?``:void 0,onClick:()=>{c(e.opens)},...l(e.id),children:[(0,Z.jsx)(i,{icon:we(e.type),size:`sm`}),(0,Z.jsx)(a,{type:`supporting`,color:`inherit`,weight:`medium`,maxLines:1,hasTruncateTooltip:!1,children:e.label}),e.note&&(0,Z.jsx)(a,{type:`supporting`,maxLines:1,justify:`end`,hasTruncateTooltip:!1,className:`studio-map-row-note`,children:e.note})]},e.id))]})}function Ie({workspace:e,shared:t,selected:n,onOpen:r,onClose:o}){let{expanded:s,family:c,map:l,moved:d,put:p,showFamily:h,expand:g}=Oe((0,Y.useMemo)(()=>W(e,t),[e,t])),[_,v]=(0,Y.useState)(``),y=(0,Y.useMemo)(()=>ee(l,_),[l,_]),b=(0,Y.useMemo)(()=>_.trim()===``?l:te(l,y),[l,_,y]),x=_.trim()!==``&&y.length===0,S=(0,Y.useRef)(null),w=s?be:ye,T=(0,Y.useMemo)(()=>({map:b,expanded:s}),[b,s]),D=N(S,T),O=(0,Y.useMemo)(()=>se(b,w,{moved:d,widths:D,detail:s}),[b,w,s,d,D]),k=b.columns.flat().flatMap(e=>e.nodes),A=k.find(e=>Q(e,n))?.id;je(S,c,{place:A===void 0?void 0:O.nodes[A],sizes:w});let{dragging:j,draggable:M}=ke(O,d,p),{panning:P,pan:F}=ve(`[data-map-node]`),{lit:I,on:L,onLines:R,lights:z}=Ae(O),B={family:c,expanded:s,isMoved:k.some(e=>Object.hasOwn(d,e.id)),showFamily:h,expand:g,tidy:()=>{p({},!0)}},[V,H]=(0,Y.useState)(),U=Me(k.find(e=>e.id===V),r,B),G=s?Fe:Pe,K=k.find(e=>Q(e,n))?.id,ne=e=>R.has(e.link)?2:+(e.from===K||e.to===K),ie=[...O.lines].sort((e,t)=>ne(e)-ne(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)(E,{items:U,label:`Map actions`,"data-map-field":``,children:(0,Z.jsxs)(`div`,{ref:S,className:`studio-map`,"data-lit":I===void 0||j!==void 0?void 0:``,"data-panning":P?``:void 0,onPointerDown:F,onContextMenuCapture:e=>{H(e.target.closest(`[data-map-node]`)?.dataset.mapNode)},style:{"--map-width":`${String(O.width)}px`,"--map-height":`${String(O.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:O.width,height:O.height,"aria-hidden":`true`,children:ie.map(({link:e,from:t,to:n,d:r})=>(0,Z.jsx)(`path`,{className:`map-line`,d:r,"data-kind":e.kind,"data-on":R.has(e)?``:void 0,"data-open":t===K||n===K?``:void 0},`${e.kind}:${e.from}:${e.to}`))}),O.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)(a,{type:`supporting`,color:`secondary`,weight:`semibold`,children:e})},e)),k.map(e=>{let t=O.nodes[e.id];return t&&(0,Z.jsx)(G,{node:e,place:t,joins:re(b,e.id),selected:n,on:L,isFound:y.includes(e.id),isDragging:j===e.id,onOpen:r,lights:z,drag:M(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)(Ne,{actions:B,query:_,onQuery:v,onClose:o})]})}export{Ie 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-BBGRPrxp.js";import{t as a}from"./VStack-CkVMcNiK.js";import{n as o,t as s}from"./StackItem-CQviqAfM.js";import{C as c,S as l,a as u,g as d,h as f,o as p,s as m}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-BBGRPrxp.js";import{t as a}from"./VStack-CkVMcNiK.js";import{n as o,t as s}from"./StackItem-CQviqAfM.js";import{C as c,S as l,a as u,g as d,h as f,o as p,s as m}from"./browser-transport-Dg00IzNm.js";import{p as h}from"./fieldParts-B7DYLgh4.js";import{t as g}from"./Icon-BqkS-pIq.js";import{t as _}from"./Text-BOqCfzZC.js";import{n as v,t as y}from"./labels-provider-Bt3Q2GjB.js";import{n as b,t as x}from"./IconButton-DVUFx-8p.js";import{a as S,t as C}from"./Banner-O0C5KVNy.js";import{g as ee,t as w}from"./studio-labels-1m3jxSy0.js";import{c as T}from"./host-patterns-F-KZIzkF.js";import{T as E}from"./shaped-data-C4yaGRz9.js";import{n as D}from"./trace-record-jV4PFwk_.js";import{n as O}from"./trace-schema-9CdEyG6Q.js";import{_ as te}from"./turn-client-CZG4gVtX.js";import{a as ne,i as re,o as ie,t as ae}from"./ConsoleFrame-DZBnKWKu.js";import{S as oe,a as k,b as se,h as ce,y as le}from"./index-Cl8kUfgj.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:D(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};function z(e){let t=e.endTimeUnixNano;if(!t)return;let n=L(e),r=BigInt(String(t));if(r<=n)return;let i=Number(n/1000000n),a=Number(r/1000000n);if(!(!Number.isFinite(i)||!Number.isFinite(a)||a<=i))return{startedAt:i,endedAt:a}}function ue(e){let t=z(e);if(t)return{workedMs:t.endedAt-t.startedAt,endedAt:t.endedAt}}function de(e,t){let n=ue(t);if(!n)return e;let r=e.findLastIndex(e=>e.kind===`turn-done`);return r<0?e:e.map((e,t)=>t===r?{...e,...n}:e)}var fe=e=>`content_sha256`in e||`json_sha256`in e;function B(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 V(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 pe(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=V(i);fe(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:B(i)}})):(i.type===`blob`||i.type===`uri`)&&(r=!0)}}return{events:t,calls:n,missing:r}}function me(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 H=e=>M(e,`gen_ai.operation.name`);function he(e){let t=new Map(e.spans.map(e=>[e.spanId,e]));return e.spans.filter(e=>H(e)===`chat`).toSorted(R).map(n=>{let r=pe(F(e,n,`gen_ai.output.messages`)),i=M(n,`theorem.stop.kind`)??`completed`;return{agent:me(n,t),...r,events:[...r.events,{type:`done`,stop:{kind:i}}]}})}function ge(e){return e.spans.filter(e=>H(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 U(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 _e(e,t){let n=[];for(let r of t.events??[]){if(r.name!==`theorem.grounding`)continue;let i=r.attributes.sources;if(i===void 0)continue;let a=D(e,i);if(!Array.isArray(a))continue;let o=[];for(let e of a)A(e)&&typeof e.title==`string`&&typeof e.uri==`string`&&o.push({title:e.title,uri:e.uri,type:e.type===`maps`?`maps`:`web`,...typeof e.placeId==`string`?{placeId:e.placeId}:{}});if(o.length){let e=M(t,`gen_ai.tool.call.id`);n.push({type:`citation`,sources:o,...e?{callId:e}:{}})}}return n}function ve(e,t){let n=e.spans.filter(e=>H(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=V(t);if(n)a.push(n);else if(t.type===`structured`&&t.content!==void 0)a.push({type:`structured`,structured:t.content});else if(t.type===`tool_call`&&typeof t.name==`string`){let n=typeof t.id==`string`?t.id:`call-${String(a.length)}`;a.push(...ye(e,t.name,n,B(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 ye(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=z(a),c=s?.startedAt??Number(L(a)/1000000n),l=s?.endedAt??c,u=P(e,a,`gen_ai.tool.call.result`),d=M(a,`theorem.tool.outcome`)===`error`?{phase:`error`,failure:{code:M(a,`theorem.tool.failure.code`)??`failed`,kind:`internal`,message:u},readBack:u}:{phase:`complete`,output:W(u),readBack:u};return[o,{type:`tool`,tool:{name:t,callId:n,phase:`running`,at:c}},{type:`tool`,tool:{name:t,callId:n,at:l,...d}},..._e(e,a)]}function W(e){try{return JSON.parse(e)}catch{return e}}function be(e){let t=``,n,r=[];return e.forEach((e,i)=>{let a=E(e);if(!a||H(a)!==`invoke_agent`)return;let o=M(a,`gen_ai.agent.name`)??``;t||=o;let s=he(e),c=ge(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=U(e,a);r.push({...u,calls:s,results:c,blocks:de(te({text:u.text},ve(e,a),{idPrefix:`recorded-${String(i)}`}),a)})}),{agent:t,turns:r,...n===void 0?{}:{recordedAt:n}}}function xe(e){if(e.failed)throw Error(e.result);let t=W(e.result);return A(t)?t:{result:t}}var Se=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 Ce(e,t,n){if(!e)return`The profile asked the model a ${Se(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 we(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=Ce(o[c],o.length,a);if(l)throw n({turn:r,call:c+1,reason:l}),new T(`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 xe(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 G(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 Te(e){return{...e,customTools:G(e.customTools),...e.dependencies?{dependencies:e.dependencies.map(e=>({...e,customTools:G(e.customTools)}))}:{}}}function K(e){return e.turns.flatMap(e=>e.blocks)}function Ee(e){let t=Array.isArray(e)?e:[e];return t.map((e,n)=>{let r=O.safeParse(e);if(r.success)return r.data;let i=t.length>1?` (record ${String(n+1)})`:``;throw new T(`request`,`This file is not a Theorem trace${i}.`)})}function De(e){let t;try{t=JSON.parse(e)}catch{throw new T(`request`,`This file is not JSON.`)}return Ee(t)}var q=e(n(),1),J=t();function Oe(e,t,n){return t?p(e,t,{conversationKey:k(),blocks:n}):f(e,n)}var Y=e=>`turn ${String(e+1)}`;function X({iface:e,feed:t,trace:n,card:r,conversation:i}){let a=S(e,t,n);return(0,J.jsxs)(ae,{inspector:a,maxWidth:`960px`,requestLabel:`Trace`,children:[r,i]})}function Z({iface:e,blocks:t,banner:n,chat:r}){let i=v();return(0,J.jsxs)(ne,{label:`Conversation`,children:[n,(0,J.jsx)(oe,{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 ke({onImport:e}){let[t,n]=(0,q.useState)(),[r,i]=(0,q.useState)(!1);return(0,J.jsxs)(a,{gap:2,children:[(0,J.jsx)(se,{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:De(await r.text())}),n(void 0)}catch(e){n(e instanceof Error?e.message:String(e))}finally{i(!1)}}},onChange:()=>void 0}),t?(0,J.jsx)(C,{status:`error`,title:t}):null]})}var Ae=e=>e.recordedAt===void 0?void 0:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e.recordedAt);function je({shown:e,onShown:t}){return(0,J.jsxs)(r,{label:`Show`,size:`sm`,value:e,onChange:e=>{t(e===`replayed`?`replayed`:`recorded`)},children:[(0,J.jsx)(i,{value:`recorded`,label:`Recorded`}),(0,J.jsx)(i,{value:`replayed`,label:`Replayed`})]})}function Me({controls:e}){let{script:t,payload:n}=e,r=t.turns.length,i=[t.agent||`No agent`,`${String(r)} ${r===1?`turn`:`turns`}`,Ae(t)];return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(o,{gap:2,vAlign:`center`,children:[(0,J.jsx)(s,{size:`fill`,children:(0,J.jsxs)(a,{gap:0,children:[(0,J.jsx)(_,{type:`label`,maxLines:1,children:e.opened.name}),(0,J.jsx)(_,{type:`supporting`,color:`secondary`,maxLines:1,children:i.filter(Boolean).join(` · `)})]})}),(0,J.jsx)(x,{label:`Clear trace`,variant:`ghost`,size:`sm`,icon:(0,J.jsx)(g,{icon:h,size:`sm`}),isDisabled:e.isRunning,onClick:e.onClear})]}),t.agent&&t.agent!==n.profile.id?(0,J.jsx)(C,{status:`info`,title:`Recorded with ${t.agent}; a replay runs through ${n.profile.id}.`}):null,r===0?(0,J.jsx)(C,{status:`info`,title:`This trace holds no conversation to replay.`}):null,(0,J.jsx)(le,{label:`Live tools`,description:`Run the profile's tools instead of answering them from the recording.`,value:e.liveTools,onChange:e.onLiveTools})]})}var Q=()=>void 0;function $({onImport:e,controls:t}){let n=t?.onReplay??Q;return(0,J.jsxs)(re,{title:`Trace`,onRun:n,actions:t?.shown?(0,J.jsx)(je,{shown:t.shown,onShown:t.onShown}):null,children:[(0,J.jsx)(ke,{onImport:e}),t?(0,J.jsx)(Me,{controls:t}):null,(0,J.jsx)(ie,{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??Q})]})}function Ne({status:e,turns:t,onContinue:n,onLive:r}){let[i,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(),l=e=>(0,J.jsx)(b,{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,J.jsx)(C,{status:`info`,title:`Replaying ${Y(e.turn)} of ${String(t)}`});case`waiting`:return(0,J.jsx)(C,{status:`info`,title:`${Y(e.turn-1)} waits on you`,description:`Answer it in the conversation, then continue the replay.`,endContent:(0,J.jsx)(b,{label:`Continue replay`,variant:`secondary`,size:`sm`,onClick:()=>{n(e.turn)}})});case`missing`:return(0,J.jsx)(C,{status:`warning`,title:`Replay stopped before ${Y(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,J.jsx)(C,{status:`warning`,title:`Replay stopped at ${Y(t)}, model call ${String(n)}`,description:r,endContent:l(t)})}case`failed`:return(0,J.jsx)(C,{status:`error`,title:`Replay stopped at ${Y(e.turn)}`,description:e.message,endContent:l(e.turn)});case`done`:return(0,J.jsx)(C,{status:`success`,title:`Replayed ${String(t)} ${t===1?`turn`:`turns`}`,description:`Every model call this profile made was one the recording answered.`})}})();return(0,J.jsxs)(a,{gap:1,children:[u,s?(0,J.jsx)(C,{status:`error`,title:s}):null]})}function Pe({payload:e,iface:t,trace:n,card:r,opened:i,script:a,shown:o,liveTools:s,runtime:d,onLive:f}){let p=(0,q.useRef)(void 0),[m,h]=(0,q.useState)({kind:`running`,turn:0}),[g]=(0,q.useState)(l),_=(0,q.useMemo)(()=>c(i.records),[i.records]),v=(0,q.useMemo)(()=>we(a,e.profile.id,e=>{p.current??=e}),[a,e.profile.id]),y=(0,q.useMemo)(()=>u(s?e:Te(e),{mode:`byok`,provider:v.provider,...s?{}:{toolHandlers:v.toolHandlers}},{conversationKey:k(),traces:g}),[e,v,s,g]),b=(0,q.useMemo)(()=>s?ee(e):void 0,[s,e]),x=ce({transport:y,iface:t,pageTools:b}),{sendText:S,handleStop:C}=x,w=(0,q.useRef)(x.phase);w.current=x.phase;let[T,E]=(0,q.useState)(0);(0,q.useEffect)(()=>{let e=!1,t=async()=>{for(;!e&&w.current===`streaming`;)await new Promise(e=>requestAnimationFrame(e))};return(async()=>{for(let n=T;n<a.turns.length;n+=1){if(await t(),e)return;if(w.current===`gated`)return v.startTurn(n-1),h({kind:`waiting`,turn:n});let{text:r,attachments:i}=a.turns[n];if(i>0)return h({kind:`missing`,turn:n});v.startTurn(n),h({kind:`running`,turn:n});try{let t=await S(r);if(e)return;if(p.current)return h({kind:`diverged`,divergence:p.current});t||--n}catch(e){let t=e instanceof Error?e.message:String(e);return h({kind:`failed`,turn:n,message:t})}}h({kind:`done`})})(),()=>{e=!0,C()}},[T,v,a,S,C]);let D=async t=>{f({...await Oe(e,d,a.turns.slice(0,t).flatMap(e=>e.blocks)),text:a.turns[t]?.text??``})},O=o===`replayed`;return(0,J.jsx)(X,{iface:t,feed:O?g:_,trace:n,card:r({isRunning:m.kind===`running`,onStop:()=>{C(),h({kind:`done`})}}),conversation:(0,J.jsx)(Z,{iface:t,blocks:O?[...x.blocks,...x.streamBlocks]:K(a),chat:O?x:void 0,banner:O?(0,J.jsx)(Ne,{status:m,turns:a.turns.length,onContinue:E,onLive:D}):void 0})})}function Fe(e){return(0,J.jsx)(m,{children:(0,J.jsx)(y,{labels:w,children:(0,J.jsx)(Ie,{...e})})})}function Ie({payload:e,trace:t,runtime:n,onLive:r,opened:i,onOpened:a,onClear:o}){let s=(0,q.useMemo)(()=>d(e),[e]),l=(0,q.useMemo)(()=>i&&be(i.records),[i]),u=(0,q.useMemo)(()=>c(i?.records??[]),[i]),[f,p]=(0,q.useState)(),[m,h]=(0,q.useState)(!1),g=f?.of===i&&f?.agent===e.profile.id?f:void 0,_=g?.attempt??0,v=g?.shown??`recorded`,y=e=>{g&&p({...g,shown:e})},b=()=>{i&&p({of:i,agent:e.profile.id,attempt:_+1,shown:`replayed`})};if(s.type===`live`)return null;if(!i||!l)return(0,J.jsx)(X,{iface:s,feed:u,trace:t,card:(0,J.jsx)($,{onImport:a}),conversation:null});let x=({isRunning:t,onStop:n})=>(0,J.jsx)($,{onImport:a,controls:{opened:i,script:l,payload:e,shown:_>0?v:null,onShown:y,liveTools:m,onLiveTools:e=>{h(e),_>0&&b()},isRunning:t,onReplay:b,onStop:n,onClear:o}});return _===0?(0,J.jsx)(X,{iface:s,feed:u,trace:t,card:x({isRunning:!1,onStop:()=>void 0}),conversation:(0,J.jsx)(Z,{iface:s,blocks:K(l)})}):(0,J.jsx)(Pe,{payload:e,iface:s,trace:t,card:x,opened:i,script:l,shown:v,liveTools:m,runtime:n,onLive:r},_)}export{Fe 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{E as a,k as o}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{E as a,k as o}from"./browser-transport-Dg00IzNm.js";import{t as s}from"./Icon-BqkS-pIq.js";import{t as c}from"./Text-BOqCfzZC.js";import{n as l,o as u}from"./labels-provider-Bt3Q2GjB.js";import{n as d}from"./Card-DruykyeB.js";import{t as f}from"./IconButton-DVUFx-8p.js";import{t as p}from"./Tooltip-BWs5DLrM.js";import{d as m}from"./reader-D_UCUUJt.js";import{_ as h,b as g,g as _,y as v}from"./ConsoleFrame-DZBnKWKu.js";import{c as y,i as b}from"./trace-patterns-D6TbkLLr.js";import{t as x}from"./CardWall-D63k-4of.js";import{R as S,T as C,V as w,w as T}from"./index-Cl8kUfgj.js";var E=e(n(),1),D=t(),O=`var(--duration-medium) var(--ease-standard)`,k=12;function A(){let e=d();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 y(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=l(),s=A(),u=Object.entries(a.probabilities).sort(([,e],[,t])=>t-e);return(0,D.jsx)(b,{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:u.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)(c,{type:`supporting`,color:`secondary`,maxLines:1,children:e}),(0,D.jsx)(c,{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=l(),s=A(),u=a.length,d=Math.min(u-1,Math.max(0,Math.round(i.score)));return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:a[d]===void 0?s.decimal.format(i.score):F(a[d]),note:[o(`@theorem.decision.score_of`,{score:s.decimal.format(i.score),max:s.decimal.format(u-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===d),transition:`height ${O}`}},`${String(t)}:${e}`)),(0,D.jsx)(`div`,{style:{position:`absolute`,insetBlock:-4,left:`${String((i.score+.5)/u*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)(c,{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)(b,{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=l(),i=v(e),a=B(i),[o,s]=(0,E.useState)(null);if(!a)return null;let c=h(t),u=a.width*(t.right-t.left)/(a.height*(t.bottom-t.top)),d=r(`@theorem.decision.open_box`);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(p,{content:d,children:(0,D.jsx)(w,{label:d,padding:0,onClick:e=>{let n={outline:V(e.currentTarget,`--color-accent`),shade:V(e.currentTarget,`--color-overlay`)};g(i,t,n).then(s)},children:(0,D.jsx)(`div`,{role:`img`,"aria-label":r(`@theorem.decision.box_in`),style:{position:`relative`,overflow:`hidden`,aspectRatio:String(u),height:z,maxWidth:`100%`,borderRadius:4},children:(0,D.jsx)(`img`,{src:i,alt:``,style:{position:`absolute`,width:`${String(c.width)}%`,height:`${String(c.height)}%`,left:`${String(c.left)}%`,top:`${String(c.top)}%`,maxWidth:`none`}})})})}),(0,D.jsx)(S,{isOpen:o!==null,onOpenChange:e=>{e||s(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,image:i,asked:a}){let o=l(),s=a&&_(a.images,a.state,i),c=A(),{top:u,bottom:d,left:f,right:p}=r.box,m=o(`@theorem.decision.box_edges`,{left:c.percent.format(f),top:c.percent.format(u),right:c.percent.format(p),bottom:c.percent.format(d)});return(0,D.jsx)(b,{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(f*100)}%`,insetBlockStart:`${String(u*100)}%`,width:`${String((p-f)*100)}%`,height:`${String((d-u)*100)}%`,borderRadius:2,background:j(!0),transition:`all ${O}`}})})})}function W({question:e,answer:t,asked:n,onQuestion:r,detail:i}){let a=l(),c=`${e.id} · ${a(`@theorem.decision.type.${e.type}`)}`;if(!t)return null;let u=a(`@theorem.decision.edit_question`,{question:e.id}),d={title:c,detail:i,aside:r?(0,D.jsx)(f,{label:u,tooltip:u,size:`sm`,variant:`ghost`,icon:(0,D.jsx)(s,{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,image:e.image,asked:n})}function G({model:e,usage:t,elapsedMs:n,isStale:i,tokens:a,children:o}){let s=l(),d=A();return(0,D.jsx)(C,{children:(0,D.jsxs)(r,{gap:3,style:{opacity:i?.5:1,transition:`opacity ${O}`},"aria-busy":i,children:[o,(0,D.jsx)(T,{children:(0,D.jsx)(c,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:u(s,d.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=l();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)(x,{minWidth:260,children:e.questions.map(e=>(0,D.jsx)(T,{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,m(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-Cl8kUfgj.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">
|
|
@@ -54,14 +54,14 @@
|
|
|
54
54
|
<link rel="modulepreload" crossorigin href="/studio/assets/tree-DfG6CXsC.js">
|
|
55
55
|
<link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-pM-ZbsQr.js">
|
|
56
56
|
<link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-BSCE_-wM.js">
|
|
57
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-
|
|
57
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-O0C5KVNy.js">
|
|
58
58
|
<link rel="modulepreload" crossorigin href="/studio/assets/row-keys-WByP9Hsh.js">
|
|
59
59
|
<link rel="modulepreload" crossorigin href="/studio/assets/Center-nHS1JSux.js">
|
|
60
60
|
<link rel="modulepreload" crossorigin href="/studio/assets/IconSearch-BTx66a40.js">
|
|
61
61
|
<link rel="modulepreload" crossorigin href="/studio/assets/trace-schema-9CdEyG6Q.js">
|
|
62
62
|
<link rel="modulepreload" crossorigin href="/studio/assets/stub-DSUcPMOV.js">
|
|
63
63
|
<link rel="modulepreload" crossorigin href="/studio/assets/reader-D_UCUUJt.js">
|
|
64
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-
|
|
64
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-Dg00IzNm.js">
|
|
65
65
|
<link rel="modulepreload" crossorigin href="/studio/assets/focusReturn-CTppP2k0.js">
|
|
66
66
|
<link rel="modulepreload" crossorigin href="/studio/assets/CheckboxInput-CFZ_Wq8-.js">
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/studio/assets/useScrollLock-Dyf6PHJt.js">
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
<link rel="modulepreload" crossorigin href="/studio/assets/encode-files-DxWGM2XV.js">
|
|
75
75
|
<link rel="modulepreload" crossorigin href="/studio/assets/turn-client-CZG4gVtX.js">
|
|
76
76
|
<link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-FIawJRo4.js">
|
|
77
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-
|
|
77
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-1m3jxSy0.js">
|
|
78
78
|
<link rel="modulepreload" crossorigin href="/studio/assets/crypto-CY8dSBJ4.js">
|
|
79
79
|
<link rel="modulepreload" crossorigin href="/studio/assets/workspace-CzTPlUdi.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/studio/assets/lent-keys-C32ems-I.js">
|
|
@@ -1 +0,0 @@
|
|
|
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";var i=e(n(),1);function a(e,t,n){return Math.max(1,Math.floor((e+n)/(t+n)))}function o(e,t,n){let r=Array.from({length:t},()=>0);return{places:e.map(e=>{let t=r.indexOf(Math.min(...r)),i=r[t]??0;return e!==0&&(r[t]=i+(e??0)+n),{column:t,top:i}}),height:Math.max(0,Math.max(...r)-n)}}var s=t();function c(e,t){return e.width===t.width&&e.gap===t.gap&&e.heights.length===t.heights.length&&e.heights.every((e,n)=>e===t.heights[n])}function l({minWidth:e,children:t}){let n=i.Children.toArray(t),l=(e,t)=>(0,i.isValidElement)(e)&&e.key!==null?e.key:String(t),u=(0,i.useRef)(null),d=(0,i.useRef)([]),f=(0,i.useRef)(null),[p,m]=(0,i.useState)({width:0,gap:0,heights:[]}),h=a(p.width,e,p.gap),g=(p.width-p.gap*(h-1))/h,{places:_,height:v}=o(n.map((e,t)=>p.heights[t]),h,p.gap),y=p.width>0;return d.current.length=n.length,(0,i.useLayoutEffect)(()=>{let e=u.current;if(!e)return;let t=()=>{let t={width:e.clientWidth,gap:Number.parseFloat(getComputedStyle(e).rowGap)||0,heights:d.current.map(e=>e?.offsetHeight)};m(e=>c(e,t)?e:t)};t();let n=new ResizeObserver(t);n.observe(e);for(let e of d.current)e&&n.observe(e);return f.current=n,()=>{n.disconnect(),f.current=null}},[]),(0,s.jsx)(r,{ref:u,gap:3,style:y?{position:`relative`,height:v}:void 0,children:n.map((e,t)=>{let n=_[t];return(0,s.jsx)(`div`,{ref:e=>(d.current[t]=e,e&&f.current?.observe(e),()=>{e&&f.current?.unobserve(e)}),style:y&&n?{position:`absolute`,top:n.top,left:n.column*(g+p.gap),width:g}:void 0,children:e},l(e,t))})})}export{l as t};
|