@theoremjs/studio 0.3.4-next.849.g2dfd688 → 0.3.4-next.851.g9ebce61

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.
Files changed (30) hide show
  1. package/package.json +4 -4
  2. package/page/assets/{BottomSheet-BU_q07Pu.js → BottomSheet-BAmU8YgD.js} +1 -1
  3. package/page/assets/{ConsoleFrame-BdoxZuCl.js → ConsoleFrame-Dz65yVLC.js} +1 -1
  4. package/page/assets/{DateInput-Ba_gQciK.js → DateInput-DUwL1wep.js} +1 -1
  5. package/page/assets/{MenuBottomSheet-DzV8Rj-g.js → MenuBottomSheet-DfZYjgL0.js} +1 -1
  6. package/page/assets/{SchemaFields-BZ1Bg3rY.js → SchemaFields-D7UGra6l.js} +1 -1
  7. package/page/assets/{TokenizerBottomSheet-BQ4ohVwg.js → TokenizerBottomSheet-C38WRzIr.js} +1 -1
  8. package/page/assets/{ToolResultCharts-CwrmmfSZ.js → ToolResultCharts-Cx0g4QOl.js} +1 -1
  9. package/page/assets/{Toolbar-BMBcV6X0.js → Toolbar-DAp_Uw5z.js} +1 -1
  10. package/page/assets/{TraceInspector-CGpRZXK0.js → TraceInspector-EPGzIZ77.js} +1 -1
  11. package/page/assets/{TraceOverview-Dr6hOfR9.js → TraceOverview-B2Q3oXth.js} +1 -1
  12. package/page/assets/{browser-engine-BCFYmD6Q.js → browser-engine-BLzr3h8d.js} +1 -1
  13. package/page/assets/{browser-transport-CdxnEWFT.js → browser-transport-eZfjcJk5.js} +2 -2
  14. package/page/assets/{export-agent-Dbwb4YsP.js → export-agent-CWRtT-CD.js} +1 -1
  15. package/page/assets/{guardrail-tester-DtEKy9ti.js → guardrail-tester-ChwY3tNK.js} +1 -1
  16. package/page/assets/{index-BBpoxm3h.js → index-CiwarrRR.js} +10 -10
  17. package/page/assets/{json-code-BfYu_Ujp.js → json-code-B-K2AgWe.js} +1 -1
  18. package/page/assets/{labels-provider-DfcbklTS.js → labels-provider-9Mz_CB_a.js} +2 -2
  19. package/page/assets/{prompt-row-dyRbyxGp.js → prompt-row-b0TB5Vmr.js} +1 -1
  20. package/page/assets/{studio-code-pane-Dfp5qlks.js → studio-code-pane-mGW79UA_.js} +1 -1
  21. package/page/assets/{studio-console-BRHnSGec.js → studio-console-CCRqaMr7.js} +1 -1
  22. package/page/assets/{studio-decision-nI10mNX8.js → studio-decision-uoibaDre.js} +1 -1
  23. package/page/assets/{studio-embedding-Cu_UnSQw.js → studio-embedding-DROnuZS6.js} +1 -1
  24. package/page/assets/{studio-host-console-DdC9yHpu.js → studio-host-console-C8aseoTf.js} +2 -2
  25. package/page/assets/{studio-labels-C7fQh1G6.js → studio-labels-BZWk1UYO.js} +2 -2
  26. package/page/assets/{studio-live-ijfCPHHU.js → studio-live-yHnMF1Qq.js} +2 -2
  27. package/page/assets/{studio-map-CxG1-y0J.js → studio-map-CrNgkX45.js} +1 -1
  28. package/page/assets/{studio-trace-replay-DxaVyWUU.js → studio-trace-replay-B07jE5Hs.js} +1 -1
  29. package/page/assets/{use-one-call-PnjzVY-f.js → use-one-call-59M2irwm.js} +1 -1
  30. package/page/index.html +4 -4
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{t as r}from"./StackItem-ClAjT294.js";import{t as i}from"./Icon-Cluq4EiW.js";import{a}from"./fieldParts-DOfguMAs.js";import{t as o}from"./Text-BDwNaqzZ.js";import{t as s}from"./Button-98PahHB4.js";import{_ as c,a as l,f as u,g as d,o as f,p,s as m}from"./browser-transport-CdxnEWFT.js";import{i as h,r as g}from"./row-keys-0Bn7ZyYy.js";import{g as _,t as v}from"./studio-labels-C7fQh1G6.js";import{t as y}from"./IconHistory-DdcWdeRG.js";import{c as b}from"./host-patterns-F-KZIzkF.js";import{T as x}from"./shaped-data-CjB-teds.js";import{n as S}from"./trace-record-CchShZYV.js";import{n as C}from"./trace-schema--4IGmLeE.js";import{v as w}from"./turn-client-_TUC5_DY.js";import{n as T,t as E}from"./labels-provider-DfcbklTS.js";import{t as D}from"./HStack-CqE4exX9.js";import{t as O}from"./IconButton-Jbcy-K-d.js";import{t as k}from"./VStack-CCYGIv4A.js";import{a as A,i as j,o as M,t as N}from"./ConsoleFrame-BdoxZuCl.js";import{D as P,E as ee,F as te,H as ne,L as re,N as ie,P as ae,Xt as oe,l as se,o as F,vt as ce,yt as le}from"./index-BBpoxm3h.js";var I=e=>typeof e==`object`&&!!e&&!Array.isArray(e),L=(e,t)=>e.attributes[t],R=(e,t)=>{let n=L(e,t);return typeof n==`string`?n:void 0};function z(e,t,n){let r=L(t,n);return r===void 0?void 0:S(e,r)}function B(e,t,n){let r=z(e,t,n);return r===void 0?``:typeof r==`string`?r:JSON.stringify(r)}function V(e,t,n){let r=z(e,t,n);return Array.isArray(r)?r.filter(I):[]}var H=e=>Array.isArray(e.parts)?e.parts.filter(I):[],U=e=>BigInt(String(e.startTimeUnixNano)),W=(e,t)=>{let n=U(e)-U(t);return n===0n?0:n<0n?-1:1};function G(e){let t=e.endTimeUnixNano;if(!t)return;let n=U(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=G(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 K(e){let t=e.arguments;if(I(t))return t;if(typeof t!=`string`)return{};try{let e=JSON.parse(t);return I(e)?e:{}}catch{return{}}}function q(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=H(i),a=e.some(e=>e.type===`text`);for(let i of e){let e=q(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:K(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=R(n,`gen_ai.agent.name`);if(R(n,`gen_ai.operation.name`)===`invoke_agent`&&e)return e}return``}var J=e=>R(e,`gen_ai.operation.name`);function he(e){let t=new Map(e.spans.map(e=>[e.spanId,e]));return e.spans.filter(e=>J(e)===`chat`).toSorted(W).map(n=>{let r=pe(V(e,n,`gen_ai.output.messages`)),i=R(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=>J(e)===`execute_tool`).toSorted(W).map(t=>({name:R(t,`gen_ai.tool.name`)??``,result:B(e,t,`gen_ai.tool.call.result`),failed:R(t,`theorem.tool.outcome`)===`error`}))}function _e(e,t){let n=V(e,t,`gen_ai.input.messages`).findLast(e=>e.role===`user`),r=n?H(n):[];return{text:r.flatMap(e=>e.type===`text`&&typeof e.content==`string`?[e.content]:[]).join(`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{t as r}from"./StackItem-ClAjT294.js";import{t as i}from"./Icon-Cluq4EiW.js";import{a}from"./fieldParts-DOfguMAs.js";import{t as o}from"./Text-BDwNaqzZ.js";import{t as s}from"./Button-98PahHB4.js";import{_ as c,a as l,f as u,g as d,o as f,p,s as m}from"./browser-transport-eZfjcJk5.js";import{i as h,r as g}from"./row-keys-0Bn7ZyYy.js";import{g as _,t as v}from"./studio-labels-BZWk1UYO.js";import{t as y}from"./IconHistory-DdcWdeRG.js";import{c as b}from"./host-patterns-F-KZIzkF.js";import{T as x}from"./shaped-data-CjB-teds.js";import{n as S}from"./trace-record-CchShZYV.js";import{n as C}from"./trace-schema--4IGmLeE.js";import{v as w}from"./turn-client-_TUC5_DY.js";import{n as T,t as E}from"./labels-provider-9Mz_CB_a.js";import{t as D}from"./HStack-CqE4exX9.js";import{t as O}from"./IconButton-Jbcy-K-d.js";import{t as k}from"./VStack-CCYGIv4A.js";import{a as A,i as j,o as M,t as N}from"./ConsoleFrame-Dz65yVLC.js";import{D as P,E as ee,F as te,H as ne,L as re,N as ie,P as ae,Xt as oe,l as se,o as F,vt as ce,yt as le}from"./index-CiwarrRR.js";var I=e=>typeof e==`object`&&!!e&&!Array.isArray(e),L=(e,t)=>e.attributes[t],R=(e,t)=>{let n=L(e,t);return typeof n==`string`?n:void 0};function z(e,t,n){let r=L(t,n);return r===void 0?void 0:S(e,r)}function B(e,t,n){let r=z(e,t,n);return r===void 0?``:typeof r==`string`?r:JSON.stringify(r)}function V(e,t,n){let r=z(e,t,n);return Array.isArray(r)?r.filter(I):[]}var H=e=>Array.isArray(e.parts)?e.parts.filter(I):[],U=e=>BigInt(String(e.startTimeUnixNano)),W=(e,t)=>{let n=U(e)-U(t);return n===0n?0:n<0n?-1:1};function G(e){let t=e.endTimeUnixNano;if(!t)return;let n=U(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=G(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 K(e){let t=e.arguments;if(I(t))return t;if(typeof t!=`string`)return{};try{let e=JSON.parse(t);return I(e)?e:{}}catch{return{}}}function q(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=H(i),a=e.some(e=>e.type===`text`);for(let i of e){let e=q(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:K(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=R(n,`gen_ai.agent.name`);if(R(n,`gen_ai.operation.name`)===`invoke_agent`&&e)return e}return``}var J=e=>R(e,`gen_ai.operation.name`);function he(e){let t=new Map(e.spans.map(e=>[e.spanId,e]));return e.spans.filter(e=>J(e)===`chat`).toSorted(W).map(n=>{let r=pe(V(e,n,`gen_ai.output.messages`)),i=R(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=>J(e)===`execute_tool`).toSorted(W).map(t=>({name:R(t,`gen_ai.tool.name`)??``,result:B(e,t,`gen_ai.tool.call.result`),failed:R(t,`theorem.tool.outcome`)===`error`}))}function _e(e,t){let n=V(e,t,`gen_ai.input.messages`).findLast(e=>e.role===`user`),r=n?H(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 ve(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=S(e,i);if(!Array.isArray(a))continue;let o=[];for(let e of a)I(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=R(t,`gen_ai.tool.call.id`);n.push({type:`citation`,sources:o,...e?{callId:e}:{}})}}return n}function ye(e,t){let n=e.spans.filter(e=>J(e)===`execute_tool`).toSorted(W),r=new Set,i=(e,t)=>{let i=n.find(t=>R(t,`gen_ai.tool.call.id`)===e)??n.find(e=>!r.has(e)&&R(e,`gen_ai.tool.name`)===t);return i&&r.add(i),i},a=[];for(let n of V(e,t,`gen_ai.output.messages`))for(let t of H(n)){let n=q(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(...be(e,t.name,n,K(t),i))}}let o=B(e,t,`theorem.error.public`);t.status.code===`ERROR`&&a.push({type:`error`,errorKind:`internal`,error:o||t.status.message});let s=R(t,`theorem.stop.kind`)??`completed`;return a.push({type:`done`,stop:{kind:s}}),a}function be(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=G(a),c=s?.startedAt??Number(U(a)/1000000n),l=s?.endedAt??c,u=B(e,a,`gen_ai.tool.call.result`),d=R(a,`theorem.tool.outcome`)===`error`?{phase:`error`,failure:{code:R(a,`theorem.tool.failure.code`)??`failed`,kind:`internal`,message:u},readBack:u}:{phase:`complete`,output:xe(e,a,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}},...ve(e,a)]}function xe(e,t,n){return`theorem.tool.data`in t.attributes?z(e,t,`theorem.tool.data`):Se(n)}function Se(e){try{return JSON.parse(e)}catch{return e}}var Ce=(e,t)=>`${e}:${t}`;function we(e,t){if(!t.events.some(e=>e.name===`theorem.compaction`))return!1;let n=_e(e,t);return!n.text&&n.attachments===0}function Te(e){let t=new Map,n=new Map,r=(e,t)=>{for(let r of e.spans)n.set(Ce(r.traceId,r.spanId),t);t.script.records.push(e)};return e.forEach((e,i)=>{let a=x(e);if(!a||J(a)!==`invoke_agent`||we(e,a))return;let o=he(e),s=ge(e),c=a.parentSpanId?n.get(Ce(a.traceId,a.parentSpanId)):void 0;if(c){c.turn.calls.push(...o),c.turn.results.push(...s),r(e,c);return}let l=R(a,`gen_ai.agent.name`)??``,u=R(a,`gen_ai.conversation.id`),d=`${l}\u0000${u??``}`,f=t.get(d);f||(f={agent:l,...u===void 0?{}:{conversation:u},turns:[],records:[],recordedAt:Number(U(a)/1000000n)},t.set(d,f));let p=_e(e,a),m={...p,calls:o,results:s,blocks:de(w({text:p.text},ye(e,a),{idPrefix:`recorded-${String(i)}`}),a)};f.turns.push(m),r(e,{turn:m,script:f})}),[...t.values()]}function Ee(e){if(e.failed)throw Error(e.result);let t=Se(e.result);return I(t)?t:{result:t}}var De=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 Oe(e,t,n){if(!e)return`The profile asked the model a ${De(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 ke(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=Oe(o[c],o.length,a);if(l)throw n({turn:r,agent:t,call:c+1,reason:l}),new b(`request`,`Replay stopped: ${l}`);yield*o[c]?.events??[]}}),c=e=>()=>{let t=o(r).get(e)?.shift();if(!t){let t=`The recording has no further result for ${e}.`;throw n({turn:r,tool:e,reason:t}),new b(`request`,`Replay stopped: ${t}`)}return Ee(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 Ae(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}:{},...e.background?{background:e.background}:{}}})}function je(e){return{...e,customTools:Ae(e.customTools),...e.dependencies?{dependencies:e.dependencies.map(e=>({...e,customTools:Ae(e.customTools)}))}:{}}}function Me(e){return e.turns.flatMap(e=>e.blocks)}function Ne(e,t){let n=C.safeParse(e);if(n.success)return n.data;let r=I(e)?e.v:void 0,i=typeof r==`number`&&r!==3?`This trace is version ${String(r)}${t}; the studio reads version 3.`:`This file is not a Theorem trace${t}.`;throw new b(`request`,i)}function Pe(e){let t=Array.isArray(e)?e:[e];return t.map((e,n)=>Ne(e,t.length>1?` (record ${String(n+1)})`:``))}function Fe(e){try{return Pe(JSON.parse(e))}catch(e){if(e instanceof b)throw e}let t=e.split(`
3
3
  `).map((e,t)=>({line:e,at:t+1})).filter(({line:e})=>e.trim());if(t.length<2)throw new b(`request`,`This file is not JSON.`);return t.map(({line:e,at:t})=>{let n;try{n=JSON.parse(e)}catch{throw new b(`request`,`Line ${String(t)} of this file is not JSON.`)}return Ne(n,` (line ${String(t)})`)})}var Y=e(t(),1),X=n();function Ie(e,t,n){return t?f(e,t,{conversationKey:F(),blocks:n}):u(e,n)}var Z=e=>`turn ${String(e+1)}`;function Q({iface:e,feed:t,trace:n,card:r,conversation:i}){let a=ie(e,t,n);return(0,X.jsxs)(N,{inspector:a,maxWidth:`960px`,requestLabel:`Trace`,children:[r,i]})}function Le({iface:e,blocks:t,banner:n,chat:r}){let i=T();return(0,X.jsxs)(A,{label:`Conversation`,children:[n,(0,X.jsx)(re,{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 Re({onImport:e}){let[t,n]=(0,Y.useState)(),[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(k,{gap:2,children:[(0,X.jsx)(te,{label:`Trace file`,isLabelHidden:!0,mode:`dropzone`,accept:`application/json,.json,.jsonl`,isLoading:r,placeholder:`Drop a trace (.json or .jsonl) or choose a file`,value:null,changeAction:async t=>{let r=Array.isArray(t)?t[0]:t;if(r){i(!0);try{let t=Fe(await r.text());e({name:r.name,records:t}),n(void 0)}catch(e){n(e instanceof Error?e.message:String(e))}finally{i(!1)}}},onChange:()=>void 0}),t?(0,X.jsx)(P,{status:`error`,title:t}):null]})}var ze=e=>e.recordedAt===void 0?void 0:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e.recordedAt);function Be({shown:e,onShown:t}){return(0,X.jsx)(ne,{label:`Replayed`,tooltip:e===`replayed`?`Recorded`:`Replayed`,size:`sm`,isIconOnly:!0,icon:(0,X.jsx)(i,{icon:y,size:`sm`}),pressedIcon:(0,X.jsx)(i,{icon:oe,size:`sm`}),isPressed:e===`replayed`,onPressedChange:e=>{t(e?`replayed`:`recorded`)}})}function Ve({controls:e}){let{script:t,payload:n}=e,s=t.turns.length,c=[t.agent||`No agent`,`${String(s)} ${s===1?`turn`:`turns`}`,ze(t)];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(D,{gap:2,vAlign:`center`,children:[(0,X.jsx)(r,{size:`fill`,children:(0,X.jsxs)(k,{gap:0,children:[(0,X.jsx)(o,{type:`label`,maxLines:1,children:e.opened.name}),(0,X.jsx)(o,{type:`supporting`,color:`secondary`,maxLines:1,children:c.filter(Boolean).join(` · `)})]})}),(0,X.jsx)(O,{label:`Clear trace`,variant:`ghost`,size:`sm`,icon:(0,X.jsx)(i,{icon:a,size:`sm`}),isDisabled:e.isRunning,onClick:e.onClear})]}),e.count>1?(0,X.jsxs)(D,{gap:1,vAlign:`center`,children:[(0,X.jsx)(O,{label:`Previous conversation`,variant:`ghost`,size:`sm`,icon:(0,X.jsx)(i,{icon:h,size:`sm`}),isDisabled:e.isRunning||e.picked===0,onClick:()=>{e.onPick(e.picked-1)}}),(0,X.jsxs)(o,{type:`supporting`,children:[`Conversation `,String(e.picked+1),` of `,String(e.count)]}),(0,X.jsx)(O,{label:`Next conversation`,variant:`ghost`,size:`sm`,icon:(0,X.jsx)(i,{icon:g,size:`sm`}),isDisabled:e.isRunning||e.picked===e.count-1,onClick:()=>{e.onPick(e.picked+1)}})]}):null,t.agent&&t.agent!==n.profile.id?(0,X.jsx)(P,{status:`info`,title:`Recorded with ${t.agent}; a replay runs through ${n.profile.id}.`}):null,s===0?(0,X.jsx)(P,{status:`info`,title:`This trace holds no conversation to replay.`}):null,(0,X.jsx)(ae,{label:`Live tools`,description:`Run the profile's tools instead of answering them from the recording.`,value:e.liveTools,onChange:e.onLiveTools})]})}var He=()=>void 0;function $({onImport:e,controls:t}){let n=t?.onReplay??He;return(0,X.jsxs)(j,{title:`Trace`,onRun:n,actions:t?.shown?(0,X.jsx)(Be,{shown:t.shown,onShown:t.onShown}):null,children:[(0,X.jsx)(Re,{onImport:e}),t?(0,X.jsx)(Ve,{controls:t}):null,(0,X.jsx)(M,{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??He})]})}function Ue({status:e,turns:t,onContinue:n,onLive:r}){let[i,a]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(),l=e=>(0,X.jsx)(s,{label:`Continue live`,variant:`secondary`,size:`sm`,isLoading:i,onClick:async()=>{a(!0),c(void 0);try{await r(e)}catch(e){c(e instanceof Error?e.message:String(e)),a(!1)}}}),u=(()=>{switch(e.kind){case`running`:return(0,X.jsx)(P,{status:`info`,title:`Replaying ${Z(e.turn)} of ${String(t)}`});case`waiting`:return(0,X.jsx)(P,{status:`info`,title:`${Z(e.turn-1)} waits on you`,description:`Answer it in the conversation, then continue the replay.`,endContent:(0,X.jsx)(s,{label:`Continue replay`,variant:`secondary`,size:`sm`,onClick:()=>{n(e.turn)}})});case`missing`:return(0,X.jsx)(P,{status:`warning`,title:`Replay stopped before ${Z(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 t=e.divergence,n=`tool`in t?`the ${t.tool} tool`:`${t.agent}'s model call ${String(t.call)}`;return(0,X.jsx)(P,{status:`warning`,title:`Replay stopped at ${Z(t.turn)}, ${n}`,description:t.reason,endContent:l(t.turn)})}case`stopped`:return(0,X.jsx)(P,{status:`info`,title:`Replay stopped at ${Z(e.turn)}`,description:`You stopped it. Continue live to go on from here with the profile's model.`,endContent:l(e.turn)});case`failed`:return(0,X.jsx)(P,{status:`error`,title:`Replay stopped at ${Z(e.turn)}`,description:e.message,endContent:l(e.turn)});case`done`:return(0,X.jsx)(P,{status:`success`,title:`Replayed ${String(t)} ${t===1?`turn`:`turns`}`,description:`Every model call this profile made was one the recording answered.`})}})();return(0,X.jsxs)(k,{gap:1,children:[u,o?(0,X.jsx)(P,{status:`error`,title:o}):null]})}function We({payload:e,iface:t,trace:n,card:r,records:i,script:a,shown:o,liveTools:s,runtime:u,onLive:f}){let p=le(),{actingAs:m}=se(),h=(0,Y.useRef)(void 0),[g,v]=(0,Y.useState)({kind:`running`,turn:0}),[y]=(0,Y.useState)(d),b=(0,Y.useMemo)(()=>c(i),[i]),x=(0,Y.useMemo)(()=>ke(a,e.profile.id,e=>{h.current??=e}),[a,e.profile.id]),S=(0,Y.useMemo)(()=>l(s?e:je(e),{mode:`byok`,provider:x.provider,...s?{}:{toolHandlers:x.toolHandlers}},{conversationKey:F(),traces:y}),[e,x,s,y]),C=(0,Y.useMemo)(()=>s?_(e):void 0,[s,e]),w=ee({transport:S,iface:t,pageTools:C}),{sendText:T,handleStop:E}=w,D=(0,Y.useRef)(w.phase);D.current=w.phase;let[O,k]=(0,Y.useState)(0),A=(0,Y.useRef)(!1),j=(0,Y.useRef)(E);j.current=E,(0,Y.useEffect)(()=>()=>j.current(),[]),(0,Y.useEffect)(()=>{let e=!1,t=async()=>{for(;!e&&D.current===`streaming`;)await new Promise(e=>requestAnimationFrame(e))};return(async()=>{for(let n=O;n<a.turns.length;n+=1){if(await t(),e||A.current)return;if(D.current===`gated`)return x.startTurn(n-1),v({kind:`waiting`,turn:n});let{text:r,attachments:i}=a.turns[n];if(i>0)return v({kind:`missing`,turn:n});x.startTurn(n),v({kind:`running`,turn:n});try{let t=await T(r);if(e||A.current)return;if(h.current)return v({kind:`diverged`,divergence:h.current});t||--n}catch(e){let t=e instanceof Error?e.message:String(e);return v({kind:`failed`,turn:n,message:t})}}v({kind:`done`})})(),()=>{e=!0}},[O,x,a,T]);let M=async t=>{let n=a.turns.slice(0,t).flatMap(e=>e.blocks);f({...p?await ce(p,e.agentId,n,m):await Ie(e,u,n),text:a.turns[t]?.text??``})},N=o===`replayed`;return(0,X.jsx)(Q,{iface:t,feed:N?y:b,trace:n,card:r({isRunning:g.kind===`running`,onStop:()=>{A.current=!0,E(),v(e=>e.kind===`running`?{kind:`stopped`,turn:e.turn}:e)}}),conversation:(0,X.jsx)(Le,{iface:t,blocks:N?[...w.blocks,...w.streamBlocks]:Me(a),chat:N?w:void 0,banner:N?(0,X.jsx)(Ue,{status:g,turns:a.turns.length,onContinue:k,onLive:M}):void 0})})}function Ge(e){return(0,X.jsx)(m,{children:(0,X.jsx)(E,{labels:v,children:(0,X.jsx)(Je,{...e})})})}var Ke={agent:``,turns:[],records:[]};function qe(e,t,n){if(t.length<=1||!n)return e;let r=new Set(t.flatMap(e=>e.records)),i=new Set(n.records);return e.filter(e=>i.has(e)||!r.has(e))}function Je({payload:e,trace:t,runtime:n,onLive:r,opened:i,onOpened:a,onClear:o}){let s=(0,Y.useMemo)(()=>p(e),[e]),l=(0,Y.useMemo)(()=>i?Te(i.records):[],[i]),[u,d]=(0,Y.useState)(),f=u&&u.of===i?u.index:0,m=i?l[f]??Ke:void 0,h=(0,Y.useMemo)(()=>qe(i?.records??[],l,m),[i,l,m]),g=(0,Y.useMemo)(()=>c(h),[h]),[_,v]=(0,Y.useState)(),[y,b]=(0,Y.useState)(!1),x=_&&_.of===m&&_.agent===e.profile.id?_:void 0,S=x?.attempt??0,C=x?.shown??`recorded`,w=e=>{x&&v({...x,shown:e})},T=()=>{m&&v({of:m,agent:e.profile.id,attempt:S+1,shown:`replayed`})};if(s.type===`live`)return null;if(!i||!m)return(0,X.jsx)(Q,{iface:s,feed:g,trace:t,card:(0,X.jsx)($,{onImport:a}),conversation:null});let E=({isRunning:t,onStop:n})=>(0,X.jsx)($,{onImport:a,controls:{opened:i,script:m,picked:f,count:l.length,onPick:e=>{d({of:i,index:e})},payload:e,shown:S>0?C:null,onShown:w,liveTools:y,onLiveTools:e=>{b(e),S>0&&T()},isRunning:t,onReplay:T,onStop:n,onClear:o}});return S===0?(0,X.jsx)(Q,{iface:s,feed:g,trace:t,card:E({isRunning:!1,onStop:()=>void 0}),conversation:(0,X.jsx)(Le,{iface:s,blocks:Me(m)})}):(0,X.jsx)(We,{payload:e,iface:s,trace:t,card:E,records:h,script:m,shown:C,liveTools:y,runtime:n,onLive:r},S)}export{Ge as TraceReplay};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{t as r}from"./Icon-Cluq4EiW.js";import{t as i}from"./Text-BDwNaqzZ.js";import{b as a,w as o}from"./browser-transport-CdxnEWFT.js";import{t as s}from"./Tooltip-Dhy5lIDA.js";import{d as c}from"./reader-CVIM-dZI.js";import{n as l,o as u}from"./labels-provider-DfcbklTS.js";import{t as d}from"./useLocale-d7ARRGFj.js";import{t as f}from"./HStack-CqE4exX9.js";import{t as p}from"./IconButton-Jbcy-K-d.js";import{t as m}from"./VStack-CCYGIv4A.js";import{_ as h,b as g,g as _,y as v}from"./ConsoleFrame-BdoxZuCl.js";import{c as y,i as b}from"./trace-patterns-DFMwRU00.js";import{n as x}from"./studio-console-BRHnSGec.js";import{B as S,st as C,ut as w,z as T}from"./index-BBpoxm3h.js";var E=e(t(),1),D=n(),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:r}){let a=l(),o=A(),s=Object.entries(r.probabilities).sort(([,e],[,t])=>t-e);return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:r.choice,note:a(`@theorem.decision.confidence`,{percent:o.percent.format(r.confidence)}),children:(0,D.jsx)(m,{gap:2,role:`list`,children:s.map(([e,t])=>(0,D.jsxs)(m,{gap:1,role:`listitem`,"aria-label":a(`@theorem.decision.option`,{label:e,percent:o.percent.format(t)}),children:[(0,D.jsxs)(f,{gap:2,hAlign:`between`,"aria-hidden":!0,children:[(0,D.jsx)(i,{type:`supporting`,color:`secondary`,maxLines:1,children:e}),(0,D.jsx)(i,{type:`supporting`,hasTabularNumbers:!0,children:o.percent.format(t)})]}),(0,D.jsx)(M,{value:t,isLead:e===r.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:r,labels:a}){let o=l(),s=A(),c=a.length,u=Math.min(c-1,Math.max(0,Math.round(r.score)));return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:a[u]===void 0?s.decimal.format(r.score):F(a[u]),note:[o(`@theorem.decision.score_of`,{score:s.decimal.format(r.score),max:s.decimal.format(c-1)}),o(`@theorem.decision.confidence`,{percent:s.percent.format(r.confidence)})].join(` · `),children:(0,D.jsxs)(m,{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,r.probabilities[String(t)]??0)*100)}%`,borderRadius:4,background:j(t===u),transition:`height ${O}`}},`${String(t)}:${e}`)),(0,D.jsx)(`div`,{style:{position:`absolute`,insetBlock:-4,left:`${String((r.score+.5)/c*100)}%`,width:0,borderInlineStart:`1.5px dashed var(--color-text-secondary)`,transition:`left ${O}`}})]}),(0,D.jsx)(`div`,{style:{display:`flex`,gap:4},children:a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,minWidth:0},title:e,children:(0,D.jsx)(i,{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(r.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,c]=(0,E.useState)(null);if(!a)return null;let u=h(t),d=a.width*(t.right-t.left)/(a.height*(t.bottom-t.top)),f=r(`@theorem.decision.open_box`);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(s,{content:f,children:(0,D.jsx)(w,{label:f,padding:0,onClick:e=>{let n={outline:V(e.currentTarget,`--color-accent`),shade:V(e.currentTarget,`--color-overlay`)};g(i,t,n).then(c)},children:(0,D.jsx)(`div`,{role:`img`,"aria-label":r(`@theorem.decision.box_in`),style:{position:`relative`,overflow:`hidden`,aspectRatio:String(d),height:z,maxWidth:`100%`,borderRadius:4},children:(0,D.jsx)(`img`,{src:i,alt:``,style:{position:`absolute`,width:`${String(u.width)}%`,height:`${String(u.height)}%`,left:`${String(u.left)}%`,top:`${String(u.top)}%`,maxWidth:`none`}})})})}),(0,D.jsx)(C,{isOpen:o!==null,onOpenChange:e=>{e||c(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:i,detail:a}){let s=l(),c=`${e.id} · ${s(`@theorem.decision.type.${e.type}`)}`;if(!t)return null;let u=s(`@theorem.decision.edit_question`,{question:e.id}),d={title:c,detail:a,aside:i?(0,D.jsx)(p,{label:u,tooltip:u,size:`sm`,variant:`ghost`,icon:(0,D.jsx)(r,{icon:o,size:`xsm`,color:`secondary`}),onClick:()=>{i(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:r,tokens:a,children:o}){let s=l(),c=A();return(0,D.jsx)(S,{children:(0,D.jsxs)(m,{gap:3,style:{opacity:r?.5:1,transition:`opacity ${O}`},"aria-busy":r,children:[o,(0,D.jsx)(T,{children:(0,D.jsx)(i,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:u(s,c.usd,{model:e,usage:t,elapsedMs:n,tokens:a})})})]},n??0)})}function K({iface:e,result:t,elapsedMs:n,isStale:r,asked:i,onQuestion:a,questionText:o}){let s=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]),l=(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 l=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()-l,startedAt:null,failure:null})}catch(t){if(s.signal.aborted)return;J(e,c(t)),i(e=>({...e,status:`error`,startedAt:null,failure:a(t)}))}finally{o.current===s&&(o.current=null)}},[e,t,n]);return{...r,call:l,cancel:s}}export{A as a,K as i,G as n,M as r,Y as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{t as r}from"./Icon-Cluq4EiW.js";import{t as i}from"./Text-BDwNaqzZ.js";import{b as a,w as o}from"./browser-transport-eZfjcJk5.js";import{t as s}from"./Tooltip-Dhy5lIDA.js";import{d as c}from"./reader-CVIM-dZI.js";import{n as l,o as u}from"./labels-provider-9Mz_CB_a.js";import{t as d}from"./useLocale-d7ARRGFj.js";import{t as f}from"./HStack-CqE4exX9.js";import{t as p}from"./IconButton-Jbcy-K-d.js";import{t as m}from"./VStack-CCYGIv4A.js";import{_ as h,b as g,g as _,y as v}from"./ConsoleFrame-Dz65yVLC.js";import{c as y,i as b}from"./trace-patterns-DFMwRU00.js";import{n as x}from"./studio-console-CCRqaMr7.js";import{B as S,st as C,ut as w,z as T}from"./index-CiwarrRR.js";var E=e(t(),1),D=n(),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:r}){let a=l(),o=A(),s=Object.entries(r.probabilities).sort(([,e],[,t])=>t-e);return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:r.choice,note:a(`@theorem.decision.confidence`,{percent:o.percent.format(r.confidence)}),children:(0,D.jsx)(m,{gap:2,role:`list`,children:s.map(([e,t])=>(0,D.jsxs)(m,{gap:1,role:`listitem`,"aria-label":a(`@theorem.decision.option`,{label:e,percent:o.percent.format(t)}),children:[(0,D.jsxs)(f,{gap:2,hAlign:`between`,"aria-hidden":!0,children:[(0,D.jsx)(i,{type:`supporting`,color:`secondary`,maxLines:1,children:e}),(0,D.jsx)(i,{type:`supporting`,hasTabularNumbers:!0,children:o.percent.format(t)})]}),(0,D.jsx)(M,{value:t,isLead:e===r.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:r,labels:a}){let o=l(),s=A(),c=a.length,u=Math.min(c-1,Math.max(0,Math.round(r.score)));return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:a[u]===void 0?s.decimal.format(r.score):F(a[u]),note:[o(`@theorem.decision.score_of`,{score:s.decimal.format(r.score),max:s.decimal.format(c-1)}),o(`@theorem.decision.confidence`,{percent:s.percent.format(r.confidence)})].join(` · `),children:(0,D.jsxs)(m,{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,r.probabilities[String(t)]??0)*100)}%`,borderRadius:4,background:j(t===u),transition:`height ${O}`}},`${String(t)}:${e}`)),(0,D.jsx)(`div`,{style:{position:`absolute`,insetBlock:-4,left:`${String((r.score+.5)/c*100)}%`,width:0,borderInlineStart:`1.5px dashed var(--color-text-secondary)`,transition:`left ${O}`}})]}),(0,D.jsx)(`div`,{style:{display:`flex`,gap:4},children:a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,minWidth:0},title:e,children:(0,D.jsx)(i,{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(r.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,c]=(0,E.useState)(null);if(!a)return null;let u=h(t),d=a.width*(t.right-t.left)/(a.height*(t.bottom-t.top)),f=r(`@theorem.decision.open_box`);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(s,{content:f,children:(0,D.jsx)(w,{label:f,padding:0,onClick:e=>{let n={outline:V(e.currentTarget,`--color-accent`),shade:V(e.currentTarget,`--color-overlay`)};g(i,t,n).then(c)},children:(0,D.jsx)(`div`,{role:`img`,"aria-label":r(`@theorem.decision.box_in`),style:{position:`relative`,overflow:`hidden`,aspectRatio:String(d),height:z,maxWidth:`100%`,borderRadius:4},children:(0,D.jsx)(`img`,{src:i,alt:``,style:{position:`absolute`,width:`${String(u.width)}%`,height:`${String(u.height)}%`,left:`${String(u.left)}%`,top:`${String(u.top)}%`,maxWidth:`none`}})})})}),(0,D.jsx)(C,{isOpen:o!==null,onOpenChange:e=>{e||c(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:i,detail:a}){let s=l(),c=`${e.id} · ${s(`@theorem.decision.type.${e.type}`)}`;if(!t)return null;let u=s(`@theorem.decision.edit_question`,{question:e.id}),d={title:c,detail:a,aside:i?(0,D.jsx)(p,{label:u,tooltip:u,size:`sm`,variant:`ghost`,icon:(0,D.jsx)(r,{icon:o,size:`xsm`,color:`secondary`}),onClick:()=>{i(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:r,tokens:a,children:o}){let s=l(),c=A();return(0,D.jsx)(S,{children:(0,D.jsxs)(m,{gap:3,style:{opacity:r?.5:1,transition:`opacity ${O}`},"aria-busy":r,children:[o,(0,D.jsx)(T,{children:(0,D.jsx)(i,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:u(s,c.usd,{model:e,usage:t,elapsedMs:n,tokens:a})})})]},n??0)})}function K({iface:e,result:t,elapsedMs:n,isStale:r,asked:i,onQuestion:a,questionText:o}){let s=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]),l=(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 l=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()-l,startedAt:null,failure:null})}catch(t){if(s.signal.aborted)return;J(e,c(t)),i(e=>({...e,status:`error`,startedAt:null,failure:a(t)}))}finally{o.current===s&&(o.current=null)}},[e,t,n]);return{...r,call:l,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-BBpoxm3h.js"></script>
13
+ <script type="module" crossorigin src="/studio/assets/index-CiwarrRR.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-Bo2jNkIC.js">
16
16
  <link rel="modulepreload" crossorigin href="/studio/assets/tokens.stylex-a4pw9QVe.js">
@@ -90,7 +90,7 @@
90
90
  <link rel="modulepreload" crossorigin href="/studio/assets/stub-CeHLNUXC.js">
91
91
  <link rel="modulepreload" crossorigin href="/studio/assets/reader-CVIM-dZI.js">
92
92
  <link rel="modulepreload" crossorigin href="/studio/assets/registry-BpOBaSGc.js">
93
- <link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-CdxnEWFT.js">
93
+ <link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-eZfjcJk5.js">
94
94
  <link rel="modulepreload" crossorigin href="/studio/assets/useClipboard-CAtohmvr.js">
95
95
  <link rel="modulepreload" crossorigin href="/studio/assets/highlightRanges-B7TRPq9q.js">
96
96
  <link rel="modulepreload" crossorigin href="/studio/assets/CodeBlock-D7u2qG-t.js">
@@ -103,9 +103,9 @@
103
103
  <link rel="modulepreload" crossorigin href="/studio/assets/turn-client-_TUC5_DY.js">
104
104
  <link rel="modulepreload" crossorigin href="/studio/assets/Badge-Cj3D81QB.js">
105
105
  <link rel="modulepreload" crossorigin href="/studio/assets/useTranslator-Ba7ULSHc.js">
106
- <link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-DfcbklTS.js">
106
+ <link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-9Mz_CB_a.js">
107
107
  <link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-D_hnA9UR.js">
108
- <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-C7fQh1G6.js">
108
+ <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-BZWk1UYO.js">
109
109
  <link rel="modulepreload" crossorigin href="/studio/assets/project-address-DjxPZuyn.js">
110
110
  <link rel="modulepreload" crossorigin href="/studio/assets/workspace-BpNR3COy.js">
111
111
  <link rel="modulepreload" crossorigin href="/studio/assets/lent-keys-C32ems-I.js">