@theoremjs/studio 0.3.4-next.562.g43efe6a → 0.3.4-next.568.g56a6770
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/draft.d.ts +4 -3
- package/draft.js +3 -3
- package/origins.d.ts +2 -7
- package/origins.js +16 -9
- package/package.json +4 -4
- package/page/assets/Banner-DkTfuDQL.js +4 -0
- package/page/assets/{ConsoleFrame-CAJZyEO2.js → ConsoleFrame-DpmaIFNA.js} +1 -1
- package/page/assets/{ContextMenu-B4QfIs55.js → ContextMenu-DUg5EAc3.js} +2 -2
- package/page/assets/{MenuBottomSheet-DAWcmJrl.js → MenuBottomSheet-BzvbOSC7.js} +1 -1
- package/page/assets/{SchemaFields-klwSsa5v.js → SchemaFields-CvvTA5G0.js} +1 -1
- package/page/assets/{ToolResultCharts-CFJXBAnq.js → ToolResultCharts-m34zwylz.js} +1 -1
- package/page/assets/{TraceInspector-DurRvzW4.js → TraceInspector-R154ztZP.js} +1 -1
- package/page/assets/{TraceOverview-C7sm61G3.js → TraceOverview-Kjtz36un.js} +1 -1
- package/page/assets/browser-connection-D9jsfxnA.js +3 -0
- package/page/assets/browser-engine-B8XR_ZbP.js +11 -0
- package/page/assets/browser-transport-Dqr5ADge.js +45 -0
- package/page/assets/{export-agent-CpuPHkBF.js → export-agent-R4BrhtK6.js} +1 -1
- package/page/assets/{guardrail-tester-DcAALNW8.js → guardrail-tester-BkORyuGe.js} +1 -1
- package/page/assets/{index-CpiaUZvj.js → index-CL8kmb-k.js} +29 -29
- package/page/assets/{live-messages-D1DPu8uD.js → live-messages-Chl3Ye0D.js} +1 -1
- package/page/assets/reader-Cn4QuGp2.js +5 -0
- package/page/assets/{studio-code-pane-BpRCPuxB.js → studio-code-pane-BjOQD9Pb.js} +2 -2
- package/page/assets/{studio-console-C4EH5FV2.js → studio-console-mcS0zGCx.js} +1 -1
- package/page/assets/{studio-decision-D59j-wNe.js → studio-decision-DnCRf8tO.js} +1 -1
- package/page/assets/studio-embedding-Bu_EmNWP.js +2 -0
- package/page/assets/{studio-host-console-BRHcbshh.js → studio-host-console-PiLn9X4d.js} +2 -2
- package/page/assets/{studio-labels-CPxUMksx.js → studio-labels-Uq8vTOQK.js} +1 -1
- package/page/assets/{studio-live-C_s1RniX.js → studio-live-peAVx7gB.js} +2 -2
- package/page/assets/{studio-map-C6C6Y9Zt.js → studio-map-Dd0KWehe.js} +1 -1
- package/page/assets/{studio-trace-replay-B3tegdb5.js → studio-trace-replay-CHaMJyVf.js} +2 -2
- package/page/assets/{tree-Cy9xwG_l.js → tree-BxJ7bZId.js} +1 -1
- package/page/assets/{turn-client-mCvAwEgO.js → turn-client-CFuTLOCL.js} +1 -1
- package/page/assets/{use-one-call-B3GIPvzI.js → use-one-call-Drr32qAt.js} +1 -1
- package/page/assets/use-second-ticker-DQqJ4pIV.js +1 -0
- package/page/assets/{workspace-BFrc6kx2.js → workspace-D9otnmy3.js} +1 -1
- package/page/index.html +14 -14
- package/server/project-source.js +43 -0
- package/shared-carry.d.ts +4 -1
- package/shared-carry.js +1 -1
- package/ui/inspector-context.js +1 -1
- package/ui/lib/studio-restore.js +3 -1
- package/ui/profile-editor.js +46 -4
- package/ui/studio-screen.js +4 -6
- package/page/assets/Banner-D7PiJb6d.js +0 -2
- package/page/assets/browser-engine-DWIBJUBO.js +0 -11
- package/page/assets/browser-transport-BYhKkw64.js +0 -47
- package/page/assets/reader-BJZH_Cmn.js +0 -7
- package/page/assets/studio-embedding-DTiqRBrp.js +0 -2
- package/page/assets/types-CB42MysU.js +0 -1
- package/page/assets/use-second-ticker-DhbZ0Soz.js +0 -1
|
@@ -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{
|
|
2
|
-
`),attachments:r.filter(e=>e.type===`blob`||e.type===`uri`).length}}function pe(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)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 me(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(...U(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 U(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}},...pe(e,a)]}function W(e){try{return JSON.parse(e)}catch{return e}}function he(e){let t=``,n,r=[];return e.forEach((e,i)=>{let a=x(e);if(!a||H(a)!==`invoke_agent`)return;let o=M(a,`gen_ai.agent.name`)??``;t||=o;let s=ue(e),c=de(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=fe(e,a);r.push({...u,calls:s,results:c,blocks:oe(w({text:u.text},me(e,a),{idPrefix:`recorded-${String(i)}`}),a)})}),{agent:t,turns:r,...n===void 0?{}:{recordedAt:n}}}function ge(e){if(e.failed)throw Error(e.result);let t=W(e.result);return A(t)?t:{result:t}}var _e=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 ve(e,t,n){if(!e)return`The profile asked the model a ${_e(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 ye(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=ve(o[c],o.length,a);if(l)throw n({turn:r,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)throw Error(`The recording has no further result for ${e}.`);return ge(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 be(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 xe(e){let t=Array.isArray(e)?e:[e];return t.map((e,n)=>{let r=C.safeParse(e);if(r.success)return r.data;let i=t.length>1?` (record ${String(n+1)})`:``;throw new b(`request`,`This file is not a Theorem trace${i}.`)})}function Se(e){let t;try{t=JSON.parse(e)}catch{throw new b(`request`,`This file is not JSON.`)}return xe(t)}var q=e(n(),1),J=t();function Ce(e,t,n){return t?u(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=_(e,t,n);return(0,J.jsxs)(O,{inspector:a,maxWidth:`960px`,requestLabel:`Trace`,children:[r,i]})}function Z({iface:e,blocks:t,banner:n,chat:r}){let i=m();return(0,J.jsxs)(T,{label:`Conversation`,children:[n,(0,J.jsx)(te,{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 we({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)(ne,{label:`Trace file`,isLabelHidden:!0,mode:`dropzone`,accept:`application/json,.json`,isLoading:r,placeholder:`Drop a trace (.json) or choose a file`,value:null,changeAction:async t=>{let r=Array.isArray(t)?t[0]:t;if(r){i(!0);try{e({name:r.name,records:Se(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)(v,{status:`error`,title:t}):null]})}var Te=e=>e.recordedAt===void 0?void 0:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e.recordedAt);function Ee({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 De({controls:e}){let{script:t,payload:n}=e,r=t.turns.length,i=[t.agent||`No agent`,`${String(r)} ${r===1?`turn`:`turns`}`,Te(t)];return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(a,{gap:0,children:[(0,J.jsx)(p,{type:`label`,maxLines:1,children:e.opened.name}),(0,J.jsx)(p,{type:`supporting`,color:`secondary`,maxLines:1,children:i.filter(Boolean).join(` · `)})]}),t.agent&&t.agent!==n.profile.id?(0,J.jsx)(v,{status:`info`,title:`Recorded with ${t.agent}; a replay runs through ${n.profile.id}.`}):null,r===0?(0,J.jsx)(v,{status:`info`,title:`This trace holds no conversation to replay.`}):null,(0,J.jsx)(ie,{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)(E,{title:`Trace`,onRun:n,actions:t?.shown?(0,J.jsx)(Ee,{shown:t.shown,onShown:t.onShown}):null,children:[(0,J.jsx)(we,{onImport:e}),t?(0,J.jsx)(De,{controls:t}):null,(0,J.jsx)(D,{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 Oe({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)(g,{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)(v,{status:`info`,title:`Replaying ${Y(e.turn)} of ${String(t)}`});case`waiting`:return(0,J.jsx)(v,{status:`info`,title:`${Y(e.turn-1)} waits on you`,description:`Answer it in the conversation, then continue the replay.`,endContent:(0,J.jsx)(g,{label:`Continue replay`,variant:`secondary`,size:`sm`,onClick:()=>{n(e.turn)}})});case`missing`:return(0,J.jsx)(v,{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)(v,{status:`warning`,title:`Replay stopped at ${Y(t)}, model call ${String(n)}`,description:r,endContent:l(t)})}case`failed`:return(0,J.jsx)(v,{status:`error`,title:`Replay stopped at ${Y(e.turn)}`,description:e.message,endContent:l(e.turn)});case`done`:return(0,J.jsx)(v,{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)(v,{status:`error`,title:s}):null]})}function ke({payload:e,iface:t,trace:n,card:r,opened:i,script:a,shown:l,liveTools:u,runtime:d,onLive:f}){let p=(0,q.useRef)(void 0),[m,h]=(0,q.useState)({kind:`running`,turn:0}),[g]=(0,q.useState)(o),_=(0,q.useMemo)(()=>s(i.records),[i.records]),v=(0,q.useMemo)(()=>ye(a,e.profile.id,e=>{p.current??=e}),[a,e.profile.id]),y=(0,q.useMemo)(()=>c(u?e:be(e),{mode:`byok`,provider:v.provider,...u?{}:{toolHandlers:v.toolHandlers}},{conversationKey:k(),traces:g}),[e,v,u,g]),b=(0,q.useMemo)(()=>u?ee(e):void 0,[u,e]),x=re({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 Ce(e,d,a.turns.slice(0,t).flatMap(e=>e.blocks)),text:a.turns[t]?.text??``})},O=l===`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)(Oe,{status:m,turns:a.turns.length,onContinue:E,onLive:D}):void 0})})}function Ae(e){return(0,J.jsx)(d,{children:(0,J.jsx)(h,{labels:y,children:(0,J.jsx)(je,{...e})})})}function je({payload:e,trace:t,runtime:n,onLive:r}){let i=(0,q.useMemo)(()=>l(e),[e]),[a,o]=(0,q.useState)(),c=(0,q.useMemo)(()=>a&&he(a.records),[a]),u=(0,q.useMemo)(()=>s(a?.records??[]),[a]),[d,f]=(0,q.useState)(0),[p,m]=(0,q.useState)(`recorded`),[h,g]=(0,q.useState)(!1),_=e=>{o(e),f(0),m(`recorded`)},v=()=>{f(e=>e+1),m(`replayed`)};if(i.type===`live`)return null;if(!a||!c)return(0,J.jsx)(X,{iface:i,feed:u,trace:t,card:(0,J.jsx)($,{onImport:_}),conversation:null});let y=({isRunning:t,onStop:n})=>(0,J.jsx)($,{onImport:_,controls:{opened:a,script:c,payload:e,shown:d>0?p:null,onShown:m,liveTools:h,onLiveTools:e=>{g(e),d>0&&v()},isRunning:t,onReplay:v,onStop:n}});return d===0?(0,J.jsx)(X,{iface:i,feed:u,trace:t,card:y({isRunning:!1,onStop:()=>void 0}),conversation:(0,J.jsx)(Z,{iface:i,blocks:K(c)})}):(0,J.jsx)(ke,{payload:e,iface:i,trace:t,card:y,opened:a,script:c,shown:p,liveTools:h,runtime:n,onLive:r},d)}export{Ae as TraceReplay};
|
|
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{D as o,E as s,a as c,b as l,o as u,s as d,y as f}from"./browser-transport-Dqr5ADge.js";import{t as p}from"./Text-BOqCfzZC.js";import{n as m,t as h}from"./labels-provider-DkA22zkP.js";import{n as g}from"./IconButton-DVUFx-8p.js";import{a as _,t as v}from"./Banner-DkTfuDQL.js";import{t as y,v as ee}from"./studio-labels-Uq8vTOQK.js";import{c as b}from"./host-patterns-F-KZIzkF.js";import{w as x}from"./shaped-data-AVV4e7rW.js";import{n as S}from"./trace-record-Dtrz7WQ7.js";import{n as C}from"./trace-schema-9CdEyG6Q.js";import{_ as w}from"./turn-client-CFuTLOCL.js";import{a as T,i as E,o as D,t as O}from"./ConsoleFrame-DpmaIFNA.js";import{S as te,a as k,b as ne,h as re,y as ie}from"./index-CL8kmb-k.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:S(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 ae(e){let t=z(e);if(t)return{workedMs:t.endedAt-t.startedAt,endedAt:t.endedAt}}function oe(e,t){let n=ae(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 se=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 ce(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);se(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 le(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 ue(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=ce(F(e,n,`gen_ai.output.messages`)),i=M(n,`theorem.stop.kind`)??`completed`;return{agent:le(n,t),...r,events:[...r.events,{type:`done`,stop:{kind:i}}]}})}function de(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 fe(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
|
+
`),attachments:r.filter(e=>e.type===`blob`||e.type===`uri`).length}}function pe(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)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 me(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(...U(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 U(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}},...pe(e,a)]}function W(e){try{return JSON.parse(e)}catch{return e}}function he(e){let t=``,n,r=[];return e.forEach((e,i)=>{let a=x(e);if(!a||H(a)!==`invoke_agent`)return;let o=M(a,`gen_ai.agent.name`)??``;t||=o;let s=ue(e),c=de(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=fe(e,a);r.push({...u,calls:s,results:c,blocks:oe(w({text:u.text},me(e,a),{idPrefix:`recorded-${String(i)}`}),a)})}),{agent:t,turns:r,...n===void 0?{}:{recordedAt:n}}}function ge(e){if(e.failed)throw Error(e.result);let t=W(e.result);return A(t)?t:{result:t}}var _e=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 ve(e,t,n){if(!e)return`The profile asked the model a ${_e(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 ye(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=ve(o[c],o.length,a);if(l)throw n({turn:r,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)throw Error(`The recording has no further result for ${e}.`);return ge(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 be(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 xe(e){let t=Array.isArray(e)?e:[e];return t.map((e,n)=>{let r=C.safeParse(e);if(r.success)return r.data;let i=t.length>1?` (record ${String(n+1)})`:``;throw new b(`request`,`This file is not a Theorem trace${i}.`)})}function Se(e){let t;try{t=JSON.parse(e)}catch{throw new b(`request`,`This file is not JSON.`)}return xe(t)}var q=e(n(),1),J=t();function Ce(e,t,n){return t?u(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=_(e,t,n);return(0,J.jsxs)(O,{inspector:a,maxWidth:`960px`,requestLabel:`Trace`,children:[r,i]})}function Z({iface:e,blocks:t,banner:n,chat:r}){let i=m();return(0,J.jsxs)(T,{label:`Conversation`,children:[n,(0,J.jsx)(te,{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 we({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)(ne,{label:`Trace file`,isLabelHidden:!0,mode:`dropzone`,accept:`application/json,.json`,isLoading:r,placeholder:`Drop a trace (.json) or choose a file`,value:null,changeAction:async t=>{let r=Array.isArray(t)?t[0]:t;if(r){i(!0);try{e({name:r.name,records:Se(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)(v,{status:`error`,title:t}):null]})}var Te=e=>e.recordedAt===void 0?void 0:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e.recordedAt);function Ee({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 De({controls:e}){let{script:t,payload:n}=e,r=t.turns.length,i=[t.agent||`No agent`,`${String(r)} ${r===1?`turn`:`turns`}`,Te(t)];return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(a,{gap:0,children:[(0,J.jsx)(p,{type:`label`,maxLines:1,children:e.opened.name}),(0,J.jsx)(p,{type:`supporting`,color:`secondary`,maxLines:1,children:i.filter(Boolean).join(` · `)})]}),t.agent&&t.agent!==n.profile.id?(0,J.jsx)(v,{status:`info`,title:`Recorded with ${t.agent}; a replay runs through ${n.profile.id}.`}):null,r===0?(0,J.jsx)(v,{status:`info`,title:`This trace holds no conversation to replay.`}):null,(0,J.jsx)(ie,{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)(E,{title:`Trace`,onRun:n,actions:t?.shown?(0,J.jsx)(Ee,{shown:t.shown,onShown:t.onShown}):null,children:[(0,J.jsx)(we,{onImport:e}),t?(0,J.jsx)(De,{controls:t}):null,(0,J.jsx)(D,{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 Oe({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)(g,{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)(v,{status:`info`,title:`Replaying ${Y(e.turn)} of ${String(t)}`});case`waiting`:return(0,J.jsx)(v,{status:`info`,title:`${Y(e.turn-1)} waits on you`,description:`Answer it in the conversation, then continue the replay.`,endContent:(0,J.jsx)(g,{label:`Continue replay`,variant:`secondary`,size:`sm`,onClick:()=>{n(e.turn)}})});case`missing`:return(0,J.jsx)(v,{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)(v,{status:`warning`,title:`Replay stopped at ${Y(t)}, model call ${String(n)}`,description:r,endContent:l(t)})}case`failed`:return(0,J.jsx)(v,{status:`error`,title:`Replay stopped at ${Y(e.turn)}`,description:e.message,endContent:l(e.turn)});case`done`:return(0,J.jsx)(v,{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)(v,{status:`error`,title:s}):null]})}function ke({payload:e,iface:t,trace:n,card:r,opened:i,script:a,shown:l,liveTools:u,runtime:d,onLive:f}){let p=(0,q.useRef)(void 0),[m,h]=(0,q.useState)({kind:`running`,turn:0}),[g]=(0,q.useState)(s),_=(0,q.useMemo)(()=>o(i.records),[i.records]),v=(0,q.useMemo)(()=>ye(a,e.profile.id,e=>{p.current??=e}),[a,e.profile.id]),y=(0,q.useMemo)(()=>c(u?e:be(e),{mode:`byok`,provider:v.provider,...u?{}:{toolHandlers:v.toolHandlers}},{conversationKey:k(),traces:g}),[e,v,u,g]),b=(0,q.useMemo)(()=>u?ee(e):void 0,[u,e]),x=re({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 Ce(e,d,a.turns.slice(0,t).flatMap(e=>e.blocks)),text:a.turns[t]?.text??``})},O=l===`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)(Oe,{status:m,turns:a.turns.length,onContinue:E,onLive:D}):void 0})})}function Ae(e){return(0,J.jsx)(d,{children:(0,J.jsx)(h,{labels:y,children:(0,J.jsx)(je,{...e})})})}function je({payload:e,trace:t,runtime:n,onLive:r}){let i=(0,q.useMemo)(()=>l(e),[e]),[a,s]=(0,q.useState)(),c=(0,q.useMemo)(()=>a&&he(a.records),[a]),u=(0,q.useMemo)(()=>o(a?.records??[]),[a]),[d,f]=(0,q.useState)(0),[p,m]=(0,q.useState)(`recorded`),[h,g]=(0,q.useState)(!1),_=e=>{s(e),f(0),m(`recorded`)},v=()=>{f(e=>e+1),m(`replayed`)};if(i.type===`live`)return null;if(!a||!c)return(0,J.jsx)(X,{iface:i,feed:u,trace:t,card:(0,J.jsx)($,{onImport:_}),conversation:null});let y=({isRunning:t,onStop:n})=>(0,J.jsx)($,{onImport:_,controls:{opened:a,script:c,payload:e,shown:d>0?p:null,onShown:m,liveTools:h,onLiveTools:e=>{g(e),d>0&&v()},isRunning:t,onReplay:v,onStop:n}});return d===0?(0,J.jsx)(X,{iface:i,feed:u,trace:t,card:y({isRunning:!1,onStop:()=>void 0}),conversation:(0,J.jsx)(Z,{iface:i,blocks:K(c)})}):(0,J.jsx)(ke,{payload:e,iface:i,trace:t,card:y,opened:a,script:c,shown:p,liveTools:h,runtime:n,onLive:r},d)}export{Ae as TraceReplay};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{$n as e,C as t,Cr as n,M as r,Vt as i,ar as a,br as o,h as ee,j as s,mn as c,mr as l,n as u,p as d,pr as te,qt as ne,t as re,ur as ie,y as ae,yn as oe,z as se}from"./tool-schema-DCF2M0n_.js";import{En as f,Sn as p,qt as m,rn as h,tn as g}from"./shaped-data-AVV4e7rW.js";import{a as _,r as v}from"./live-ingress-OuSlQ6q7.js";var ce=[{id:`identity`,profilePath:`identity`,role:`root`,optional:!1,editor:`structural`,label:`Identity`,ownsFields:[`profile.id`,`profile.type`]},{id:`models`,profilePath:`models`,role:`spine`,optional:!1,editor:`structural`,label:`Models`,ownsFields:[`profile.defaultModel`,`profile.allowModelSelect`,`profile.maxSteps`,`providerContinuation`]},{id:`modelBinding`,profilePath:`models.*`,role:`branch`,parent:`models`,optional:!1,editor:`structural`,label:`Model binding`},{id:`decision`,profilePath:`decision`,role:`spine`,optional:!1,editor:`structural`,label:`Decision`,ownsFields:[`inputs`]},{id:`image`,profilePath:`image`,role:`spine`,optional:!1,editor:`structural`,label:`Image`},{id:`speech`,profilePath:`speech`,role:`spine`,optional:!1,editor:`structural`,label:`Speech`},{id:`live`,profilePath:`live`,role:`spine`,optional:!1,editor:`structural`,label:`Live`},{id:`tools`,profilePath:`tools`,role:`spine`,optional:!1,editor:`structural`,label:`Tools`},{id:`toolSpec`,profilePath:`tools.allow`,role:`branch`,parent:`tools`,optional:!0,editor:`structural`,label:`Tool`},{id:`inputs`,profilePath:`inputs`,role:`spine`,optional:!1,editor:`structural`,label:`Inputs`},{id:`outputs`,profilePath:`outputs`,role:`spine`,optional:!0,editor:`structural`,label:`Outputs`},{id:`turnBehaviour`,profilePath:`turnBehaviour`,role:`spine`,optional:!0,editor:`structural`,label:`Turn behaviour`},{id:`guardrails`,profilePath:`guardrails`,role:`spine`,optional:!0,editor:`structural`,label:`Guardrails`},{id:`observability`,profilePath:`observability`,role:`spine`,optional:!0,editor:`structural`,label:`Observability`},{id:`labels`,profilePath:`labels`,role:`spine`,optional:!0,editor:`structural`,label:`Labels`}],le={identity:o,inputs:n(`inputs`).filter(e=>e!==`decision`)},y=ce.map(e=>({...e,profileTypes:le[e.id]??n(e.profilePath)}));function ue(e){return y.find(t=>t.id===e)}function de(e){return e.modelBindings.length>1}function fe(e){return e.modelBindings.some(t=>t.provider!==`local`&&!r(e.providers,t).keySlot)}function b(e,t){let n={provider:t.provider,keySlot:t.keySlot||e.models.key,fallbackKeySlot:t.fallbackKeySlot||e.models.fallbackKey},i=r(e.providers,n);return{...i,given:{keySlot:!!i.keySlot&&!n.keySlot,fallbackKeySlot:!!i.fallbackKeySlot&&!n.fallbackKeySlot}}}function pe(e,t){let n=new Set(e.modelBindings.filter(n=>{let r=b(e,n);return r.keySlot===t||r.fallbackKeySlot===t}).map(e=>e.provider));return e.providers.filter(e=>n.has(e.id))}function me(e){let t=e.efforts.map(({alias:e})=>e.trim()).filter(Boolean);return new Set(t).size>1}function he(e){return e.attachmentsAccept.length>0||e.voiceAccept.length>0}var ge=a,x=[{name:`operationTimeoutMs`,label:`Call timeout`,units:`ms`,isTimer:!0},{name:`connectTimeoutMs`,label:`Connect timeout`,units:`ms`,isTimer:!0},{name:`liveStepTimeoutMs`,label:`Live step timeout`,units:`ms`,isTimer:!0},{name:`maxWireRecordBytes`,label:`Wire record`,units:`bytes`,isTimer:!1},{name:`maxWireResponseBytes`,label:`Wire response`,units:`bytes`,isTimer:!1},{name:`maxEventBytes`,label:`Event`,units:`bytes`,isTimer:!1},{name:`maxStepBytes`,label:`Step`,units:`bytes`,isTimer:!1},{name:`maxStepEvents`,label:`Step events`,units:`events`,isTimer:!1},{name:`maxPendingToolCalls`,label:`Tool calls`,units:`calls`,isTimer:!1}],S=2147483647,C={compactMaxTokens:32e3,compactAt:.75,compactKeep:4},w={"continue.instruction":`turnBehaviour`,"canary.bind_note":`guardrails`,"quota.exhausted":`guardrails`,"repair.default_guidance":`outputs`,"egress.default_repair_guidance":`guardrails`,"egress.refusal":`guardrails`};function T(e){return`${e}-${crypto.randomUUID().slice(0,8)}`}function E(e){return{key:T(`model`),modelId:`fast`,protocol:`openRouterOpenAi`,provider:`openrouter`,apiId:``,options:{},timeoutMs:null,efforts:[],defaultEffort:``,allowEffortSelect:!1,summaries:null,maxOutputTokens:null,temperature:null,builtInTools:[],...e}}var D=`Studio stub tool — returns a fixed result.`;function O(e){return{key:T(`tool`),toolName:`my_tool`,toolType:`function`,description:D,category:`studio`,access:ie[0],permission:l[0],loadTier:te[0],paths:[`*`],inputJson:re,outputJson:u,...e}}function k(e,t,n){return(!e.description.trim()||e.description===D)&&n?{agentKey:t,description:`Asks ${n} and returns its answer.`}:{agentKey:t}}function A(){return{name:``,kind:`words`,pattern:``,flags:``,words:[]}}function j(){return{key:``,label:``,at:f(p,()=>`ignore`),patterns:[A()],hint:``}}function M(){let e=oe(void 0);return{canaryBindNote:``,detect:f(m,t=>({...e.detect[t]})),sources:Object.fromEntries(g.map(e=>[e,{theorem:!0,patterns:[],hint:``}])),own:[],quotaEnabled:!1,quotaPerDay:null,quotaMessage:``,allow:{ungiven_images:{hosts:[],fromTools:!0},ungiven_links:{hosts:[],fromTools:!0}},innocentNames:[],blockedReplyOnBlock:``,blockedReplyMaxRetries:null,egressRepairGuidance:``,egressRefusal:``,allowPrivateNetworks:!1,allowedHosts:[],allowedSchemes:[],taintAfterRemoteRead:``,taintRemoteDestination:``}}function N(){let e=_({});return{writeTo:d,destination:d,sampleRate:e.sampleRate,include:{...e.include},scrub:{sensitive
|
|
1
|
+
import{$n as e,C as t,Cr as n,M as r,Vt as i,ar as a,br as o,h as ee,j as s,mn as c,mr as l,n as u,p as d,pr as te,qt as ne,t as re,ur as ie,y as ae,yn as oe,z as se}from"./tool-schema-DCF2M0n_.js";import{En as f,Sn as p,qt as m,rn as h,tn as g}from"./shaped-data-AVV4e7rW.js";import{a as _,r as v}from"./live-ingress-OuSlQ6q7.js";var ce=[{id:`identity`,profilePath:`identity`,role:`root`,optional:!1,editor:`structural`,label:`Identity`,ownsFields:[`profile.id`,`profile.type`]},{id:`models`,profilePath:`models`,role:`spine`,optional:!1,editor:`structural`,label:`Models`,ownsFields:[`profile.defaultModel`,`profile.allowModelSelect`,`profile.maxSteps`,`providerContinuation`]},{id:`modelBinding`,profilePath:`models.*`,role:`branch`,parent:`models`,optional:!1,editor:`structural`,label:`Model binding`},{id:`decision`,profilePath:`decision`,role:`spine`,optional:!1,editor:`structural`,label:`Decision`,ownsFields:[`inputs`]},{id:`image`,profilePath:`image`,role:`spine`,optional:!1,editor:`structural`,label:`Image`},{id:`speech`,profilePath:`speech`,role:`spine`,optional:!1,editor:`structural`,label:`Speech`},{id:`live`,profilePath:`live`,role:`spine`,optional:!1,editor:`structural`,label:`Live`},{id:`tools`,profilePath:`tools`,role:`spine`,optional:!1,editor:`structural`,label:`Tools`},{id:`toolSpec`,profilePath:`tools.allow`,role:`branch`,parent:`tools`,optional:!0,editor:`structural`,label:`Tool`},{id:`inputs`,profilePath:`inputs`,role:`spine`,optional:!1,editor:`structural`,label:`Inputs`},{id:`outputs`,profilePath:`outputs`,role:`spine`,optional:!0,editor:`structural`,label:`Outputs`},{id:`turnBehaviour`,profilePath:`turnBehaviour`,role:`spine`,optional:!0,editor:`structural`,label:`Turn behaviour`},{id:`guardrails`,profilePath:`guardrails`,role:`spine`,optional:!0,editor:`structural`,label:`Guardrails`},{id:`observability`,profilePath:`observability`,role:`spine`,optional:!0,editor:`structural`,label:`Observability`},{id:`labels`,profilePath:`labels`,role:`spine`,optional:!0,editor:`structural`,label:`Labels`}],le={identity:o,inputs:n(`inputs`).filter(e=>e!==`decision`)},y=ce.map(e=>({...e,profileTypes:le[e.id]??n(e.profilePath)}));function ue(e){return y.find(t=>t.id===e)}function de(e){return e.modelBindings.length>1}function fe(e){return e.modelBindings.some(t=>t.provider!==`local`&&!r(e.providers,t).keySlot)}function b(e,t){let n={provider:t.provider,keySlot:t.keySlot||e.models.key,fallbackKeySlot:t.fallbackKeySlot||e.models.fallbackKey},i=r(e.providers,n);return{...i,given:{keySlot:!!i.keySlot&&!n.keySlot,fallbackKeySlot:!!i.fallbackKeySlot&&!n.fallbackKeySlot}}}function pe(e,t){let n=new Set(e.modelBindings.filter(n=>{let r=b(e,n);return r.keySlot===t||r.fallbackKeySlot===t}).map(e=>e.provider));return e.providers.filter(e=>n.has(e.id))}function me(e){let t=e.efforts.map(({alias:e})=>e.trim()).filter(Boolean);return new Set(t).size>1}function he(e){return e.attachmentsAccept.length>0||e.voiceAccept.length>0}var ge=a,x=[{name:`operationTimeoutMs`,label:`Call timeout`,units:`ms`,isTimer:!0},{name:`connectTimeoutMs`,label:`Connect timeout`,units:`ms`,isTimer:!0},{name:`liveStepTimeoutMs`,label:`Live step timeout`,units:`ms`,isTimer:!0},{name:`maxWireRecordBytes`,label:`Wire record`,units:`bytes`,isTimer:!1},{name:`maxWireResponseBytes`,label:`Wire response`,units:`bytes`,isTimer:!1},{name:`maxEventBytes`,label:`Event`,units:`bytes`,isTimer:!1},{name:`maxStepBytes`,label:`Step`,units:`bytes`,isTimer:!1},{name:`maxStepEvents`,label:`Step events`,units:`events`,isTimer:!1},{name:`maxPendingToolCalls`,label:`Tool calls`,units:`calls`,isTimer:!1}],S=2147483647,C={compactMaxTokens:32e3,compactAt:.75,compactKeep:4},w={"continue.instruction":`turnBehaviour`,"canary.bind_note":`guardrails`,"quota.exhausted":`guardrails`,"repair.default_guidance":`outputs`,"egress.default_repair_guidance":`guardrails`,"egress.refusal":`guardrails`};function T(e){return`${e}-${crypto.randomUUID().slice(0,8)}`}function E(e){return{key:T(`model`),modelId:`fast`,protocol:`openRouterOpenAi`,provider:`openrouter`,apiId:``,options:{},timeoutMs:null,efforts:[],defaultEffort:``,allowEffortSelect:!1,summaries:null,maxOutputTokens:null,temperature:null,builtInTools:[],...e}}var D=`Studio stub tool — returns a fixed result.`;function O(e){return{key:T(`tool`),toolName:`my_tool`,toolType:`function`,description:D,category:`studio`,access:ie[0],permission:l[0],loadTier:te[0],paths:[`*`],inputJson:re,outputJson:u,...e}}function k(e,t,n){return(!e.description.trim()||e.description===D)&&n?{agentKey:t,description:`Asks ${n} and returns its answer.`}:{agentKey:t}}function A(){return{name:``,kind:`words`,pattern:``,flags:``,words:[]}}function j(){return{key:``,label:``,at:f(p,()=>`ignore`),patterns:[A()],hint:``}}function M(){let e=oe(void 0);return{canaryBindNote:``,detect:f(m,t=>({...e.detect[t]})),sources:Object.fromEntries(g.map(e=>[e,{theorem:!0,patterns:[],hint:``}])),own:[],quotaEnabled:!1,quotaPerDay:null,quotaMessage:``,allow:{ungiven_images:{hosts:[],fromTools:!0},ungiven_links:{hosts:[],fromTools:!0}},innocentNames:[],blockedReplyOnBlock:``,blockedReplyMaxRetries:null,egressRepairGuidance:``,egressRefusal:``,allowPrivateNetworks:!1,allowedHosts:[],allowedSchemes:[],taintAfterRemoteRead:``,taintRemoteDestination:``}}function N(){let e=_({});return{writeTo:d,destination:d,sampleRate:e.sampleRate,include:{...e.include},scrub:{sensitive:e.scrub.sensitive,injection:e.scrub.injection,canary:e.scrub.canary},retainForDays:null,rotateAfterMiB:null,resourceJson:``}}function P(e){return e.map(([e,t])=>({key:T(`criterion`),label:e,text:t}))}function F(){return{contract:`guardrails.tool_call.v1`,maxStateBytes:null,questions:[{key:T(`question`),id:`verdict`,type:`choice`,instructions:`Given what the user asked for and what the call would do, should it run?`,criteria:P([[`allow`,`Safe, and what the user asked for.`],[`flag`,`Probably fine, but unusual or sensitive enough for a person to look first.`],[`block`,`Harmful, or clearly beyond what the user asked for.`]])},{key:T(`question`),id:`risk`,type:`score`,instructions:`How much harm would this call do if it were wrong?`,criteria:P([[``,`Low: reversible, and affects only the user.`],[``,`High: hard to undo, or affects other people or money.`]])}],images:[]}}var I=JSON.stringify({context:`The user asked the agent to tidy up old screenshots on their desktop.`,tool_call:{name:`delete_files`,path:`~/Documents`,recursive:!0},outcome:`Would delete 1,284 files, including tax_return_2025.pdf.`},null,2),L=JSON.stringify(`The user asked to tidy screenshots. The proposed call recursively deletes 1,284 files, including a tax return.`),_e=`To clear your desktop, select the screenshots and move them to the Trash. Empty the Trash to delete them for good.(Screen captures save to the desktop by default. You can change where they go in the Screenshot app's Options menu.(Press Command-Shift-5 to record the screen or capture a window. Recordings are saved as movie files next to your screenshots.(Stacks group desktop files by kind, date or tag, so a cluttered desktop folds into a few piles you can open one at a time.(Deleted files stay in the Trash for 30 days. Drag a file out of the Trash to put it back where it was.(When your disk is almost full, open Storage settings and review the largest files. Old downloads and installers are safe to remove.(Offloading unused apps frees space and keeps their documents. Reinstalling an app brings its data back.(Photos you have backed up can be optimised so the originals live in the cloud and smaller copies stay on the device.(Your plan renews on the same date each month. You can see the next charge under Billing, then Upcoming invoices.(To get a refund, open the invoice and choose Request refund. Charges from the last 14 days are refunded in full.(Update your card under Billing, then Payment methods. The new card is used for the next renewal, not for past invoices.(Annual plans cost two months less than paying monthly. Switching mid-term credits the unused months to the new plan.(Invoices are emailed as PDFs and list your company name and tax number. Edit those details before the invoice is issued.(Turn on two-step verification under Security. You will be asked for a code from your authenticator app each time you sign in on a new device.(If you forget your password, choose Forgot password on the sign-in page. The reset link expires after one hour.(Review signed-in devices under Security and sign out any you don't recognise. This ends their sessions immediately.(Passkeys replace your password with your fingerprint or face. Create one under Security, then Passkeys.(To close your account, export your data first. Closing deletes your workspace after a 30-day grace period.(Share a folder by choosing Share, then entering an email address. Viewers can read; editors can change and delete.(Public links work for anyone who has them. Set an expiry date, or turn the link off to stop sharing at once.(Transfer ownership of a folder before you leave a team, or its contents will be archived with your account.(Lisbon has mild, wet winters and warm, dry summers. Expect highs near 28 °C in August.(The best months for the Algarve coast are May, June and September, when the beaches are warm and the crowds are thin.(Trams in Lisbon climb the steep hills of Alfama and Graça. Line 28 is the famous one, and the busiest.(For a crisp pizza base, preheat the oven and the baking tray together at the highest setting for at least thirty minutes.(Rest steak for five minutes after cooking so the juices settle back into the meat instead of running onto the board.`.split(`(`).join(`
|
|
2
2
|
|
|
3
3
|
`),ve=`How do I delete every screenshot on my desktop?`;function ye(e,t=`choice`){let n=K(`question`,e.decision.questions.map(e=>e.id),e=>`question_${e}`);return{key:T(`question`),id:n,type:t,instructions:``,criteria:z(t)}}function be(e,t,n){let r=t.replace(/\.[^.]*$/,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``)||`image`,i=K(r,e.decision.images.map(e=>e.name),e=>`${r}_${e}`);return{key:T(`image`),name:i,...n}}function xe(e){let t=K(`slot`,e.map(e=>e.name),e=>`slot_${String(e)}`);return{key:T(`slot`),name:t,label:``,choices:[R(),R()]}}function R(){return{key:T(`choice`),value:``,description:``}}function z(e){return e===`noul`||e===`box`?[]:P(e===`choice`?[[`yes`,``],[`no`,``]]:[[``,``],[``,``]])}function Se(){return{identity:{agentId:``,profileType:``,handle:``,system:``,systemByRoleJson:``},included:[`observability`,`labels`],models:{defaultModel:``,allowModelSelect:!1,maxSteps:null,key:``},modelBindings:[],providers:[...t],tools:{t2Loader:``,parallel:!1},toolSpecs:[],inputs:{text:!0,attachmentsAccept:[],voiceAccept:[],maxFiles:null,maxBytes:null,maxTurnBytes:null,limitsByMime:{},slots:[],contextFrom:[],contextMaxChars:null},outputs:{mode:`text`,schemaId:``,schemaJson:``,streamMode:``,streamThoughts:!0,validationEnabled:!1,maxRetries:null,itemRules:{},repairGuidance:``},turnBehaviour:{resumeEnabled:!1,allowContinue:[],autoContinue:[],maxContinues:null,continueInstruction:``,allowSteering:ne({type:`text`}),atStepLimit:`stop`},guardrails:M(),observability:N(),image:{aspectRatio:``,resolution:``,mimeType:``,quality:``,background:``,n:null,seed:null,outputCompression:null,includeText:!1,references:[]},speech:{voice:``,style:``,speed:null,format:``},live:{ingressAudio:v(`audio`),ingressVideo:v(`video`),ingressText:v(`text`),voice:``,sessionResumption:!1,greeting:``,resumedPrompt:``,resumedAfterMs:null,contextCompression:!1,compressionTriggerTokens:null,compressionTargetTokens:null,transcriptionInput:!1,transcriptionOutput:!1,vadActivityHandling:``,vadStartSensitivity:``,vadEndSensitivity:``,vadPrefixPaddingMs:null,vadSilenceDurationMs:null},decision:F(),labels:{}}}var Ce=new Set([`guardrails`]);function B(e,t){return e.profileTypes.includes(t)&&!(t===`decision`&&Ce.has(e.id))}function V(e){let t=e.identity.profileType;if(!t)return[`identity`];let n=new Set(e.included);return y.filter(e=>e.role!==`branch`&&B(e,t)&&(!e.optional||n.has(e.id))).map(e=>e.id)}function H(e,t){let r=e.identity.profileType;return r!==``&&n(t).includes(r)}function we(e){return H(e,`identity.system`)&&h(e.guardrails.detect,`canary_leak`)}function Te(e){let t=e.identity.profileType;return t!==``&&i.includes(t)}function U(e){let t=e.identity.profileType;return t?y.filter(n=>n.role===`spine`&&n.optional&&B(n,t)&&!e.included.includes(n.id)).map(e=>e.id):[]}function Ee(t){return{...t,attachmentsAccept:t.attachmentsAccept.filter(t=>c(e,t)),voiceAccept:[]}}function De(e,t,n){let r=e.modelBindings.find(e=>e.key===t);return r?{...e,models:n.modelId!==void 0&&e.models.defaultModel===r.modelId?{...e.models,defaultModel:n.modelId}:e.models,modelBindings:e.modelBindings.map(e=>e.key===t?{...e,...n}:e)}:e}function W(e,t){if(t.some(t=>t.modelId===e))return e;let[n,...r]=t;return n&&!r.length?n.modelId:``}function Oe(e,t){if(!e.modelBindings.find(e=>e.key===t))return e;let n=e.modelBindings.filter(e=>e.key!==t);return{...e,models:{...e.models,defaultModel:W(e.models.defaultModel,n)},modelBindings:n}}function G(e,t){let n=e.identity.profileType,r=n&&n!==`host`?n:`text`,i=e.modelBindings.map(e=>e.modelId),a=ae(r,t),o=K(a.modelId,i,e=>`${a.modelId}${e}`);return E({...a,modelId:o})}function ke(e){return O({toolName:K(`my_tool`,e.toolSpecs.map(e=>e.toolName),e=>`my_tool_${e}`)})}function K(e,t,n){let r=new Set(t),i=e;for(let e=2;r.has(i);e++)i=n(e);return i}function Ae(e,t,n){if(t===`host`)return{...e,identity:{...e.identity,profileType:t}};let r=e.modelBindings.filter(r=>{let i=s(e.providers,t,r),a=e.providers.find(e=>e.id===r.provider);return se(a,t,r.protocol)&&!Ne(n,t,i)}),i={...e,identity:{...e.identity,profileType:t},modelBindings:r},a=r.length?r:[G(i,n?.start)],o=!e.models.key&&fe({...i,modelBindings:a}),c=t===`speech`&&!e.speech.voice.trim()&&a.some(n=>ee(s(e.providers,t,n)));return{...i,inputs:t===`image`?Ee(e.inputs):e.inputs,...c?{speech:{...e.speech,voice:je}}:{},models:{...e.models,defaultModel:W(e.models.defaultModel,a),key:o?Pe:e.models.key},modelBindings:a}}var je=`Kore`,Me=[`text`,`image`,`speech`,`live`,`decision`];function Ne(e,t,n){if(!e)return!1;let r=t=>e.models(t,n.definition).some(e=>e.id===n.apiId.trim());return!r(t)&&Me.some(e=>e!==t&&r(e))}var Pe=`slot_a`;function Fe(e,t){return U(e).includes(t)?{...e,included:[...e.included,t]}:e}function Ie(e,t){return{...e,included:e.included.filter(e=>e!==t)}}function q(e){return`modelBinding:${e}`}var J=`toolSpec:`;function Y(e){return`${J}${e}`}function X(e){return e.startsWith(J)?e.slice(9):void 0}var Z=`provider:`;function Le(e){return`${Z}${e}`}function Re(e){return e.startsWith(Z)?e.slice(9):void 0}var ze=new Map(y.map(e=>[e.id,e.label]));function Q(e){return ze.get(e)??e}function Be(e,t){let[n,r]=t.split(`:`,2);if(n===`modelBinding`&&r!==void 0)return e.modelBindings.some(e=>e.key===r)?{facet:n,key:r}:void 0;let i=X(t);if(i!==void 0)return e.toolSpecs.some(e=>e.key===i)?{facet:`toolSpec`,key:i}:void 0;let a=V(e);if(r===void 0&&a.includes(t))return{facet:t}}function Ve(e,t){return t===`models`?e.modelBindings.map(e=>({id:q(e.key),ref:{facet:`modelBinding`,key:e.key},label:e.modelId.trim()||Q(`modelBinding`),children:[]})):t===`tools`?$(e.toolSpecs):[]}function $(e){return e.map(e=>({id:Y(e.key),ref:{facet:`toolSpec`,key:e.key},label:e.toolName.trim()||Q(`toolSpec`),children:[]}))}function He(e){let t=V(e).filter(e=>e!==`identity`).map(t=>({id:t,ref:{facet:t},label:Q(t),children:Ve(e,t)}));return{id:`identity`,ref:{facet:`identity`},label:e.identity.agentId.trim()||Q(`identity`),children:t}}export{be as A,Ae as B,V as C,U as D,K as E,xe as F,de as G,De as H,R as I,y as J,he as K,ke as L,G as M,j as N,Fe as O,A as P,we as R,H as S,Ie as T,b as U,Te as V,me as W,ue as Y,S as _,He as a,E as b,$ as c,ve as d,_e as f,ge as g,x as h,Be as i,ye as j,z as k,C as l,w as m,Re as n,X as o,L as p,pe as q,Le as r,Y as s,q as t,I as u,k as v,T as w,O as x,Se as y,Oe as z};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Ln as e,zt as t}from"./tool-schema-DCF2M0n_.js";import{c as n}from"./host-patterns-F-KZIzkF.js";import{Un as r,en as i,j as a}from"./shaped-data-AVV4e7rW.js";import{F as o
|
|
1
|
+
import{Ln as e,zt as t}from"./tool-schema-DCF2M0n_.js";import{c as n}from"./host-patterns-F-KZIzkF.js";import{Un as r,en as i,j as a}from"./shaped-data-AVV4e7rW.js";import{F as o}from"./reader-Cn4QuGp2.js";import{M as s}from"./browser-connection-D9jsfxnA.js";import{r as c}from"./encode-files-BCf3-Q7y.js";function l(e,t){let r=typeof t==`string`?t.trim():``;if(!r)throw new n(`request`,`A typed credential must be a non-empty string`);if(e===`bearer`)return{type:`bearer`,token:r};if(e===`api_key`)return{type:`api_key`,key:r};throw new n(`request`,`A '${e}' sign-in takes no typed credential; the host's callback saves it`)}function ee(e,t){if(!e)throw new n(`request`,`a typed credential answers only a sign-in gate`);return{slot:e.slot,credential:l(e.authType,t)}}var u=18e5;function te(e,t){let r=t??u;if(!Number.isFinite(r)||r<=0)throw new n(`config`,`${e} gateTtlMs must be a positive number of milliseconds; got ${r}.`);return r}function ne(e,t,n){return t-e>=n}var d=[`approve`,`deny`,`abandon`];function f(e,t=!1){return e.decision===`approve`?{granted:!0,...e.edited?{edited:e.edited}:{},...t?{signIn:t}:{}}:{granted:!1,cause:e.decision===`deny`?`declined`:`abandoned`,...t?{signIn:t}:{}}}function p(e,t,n){return n!==`session_consent`||e.includes(t)?[...e]:[...e,t]}function re(e,t,r){let{callId:i,decision:a,input:o,secret:s,page:c}=e;if((o!==void 0||s!==void 0||c!==void 0)&&a!==`approve`)throw new n(`request`,`only an approval takes edited input, a secret, or a page answer (call ${i})`);if(a!==`approve`)return{resume:f({decision:a},t.auth!==void 0),input:t.arguments,sessionPermissions:[...r]};let l=s===void 0?void 0:ee(t.auth,s);return{resume:{...f(o===void 0?{decision:a}:{decision:a,edited:{from:t.arguments}},t.auth!==void 0),...t.gateKind?{gateKind:t.gateKind}:{}},input:o??t.arguments,sessionPermissions:p(r,t.name,t.permission),...l?{typed:l}:{},...c?{page:c}:{}}}var m={'"':`"`,"\\":`\\`,"/":`/`,b:`\b`,f:`\f`,n:`
|
|
2
2
|
`,r:`\r`,t:` `};function h(e,t){let n=``,r=t+1;for(;r<e.length;){let t=e.charAt(r);if(t===`"`)return{text:n,end:r+1};if(t!==`\\`){n+=t,r++;continue}if(r+1>=e.length)break;let i=e.charAt(r+1);if(i===`u`){let t=e.slice(r+2,r+6);if(t.length<4)break;if(/^[0-9a-fA-F]{4}$/.test(t)){n+=String.fromCharCode(Number.parseInt(t,16)),r+=6;continue}}n+=m[i]??i,r+=2}return{text:n}}function g(e,t){let n=t;for(;/\s/.test(e.charAt(n));)n++;return n}function ie(e,t){if(e.charAt(t)===`"`){let n=h(e,t);return n.end===void 0?void 0:_(e,t,n.end)}let n=0;for(let r=t;r<e.length;r++){let i=e.charAt(r);if(i===`"`){let t=h(e,r).end;if(t===void 0)return;r=t-1}else if(i===`{`||i===`[`)n++;else if(i===`}`||i===`]`){if(n===0)return _(e,t,r);if(n--,n===0)return _(e,t,r+1)}else if(i===`,`&&n===0)return _(e,t,r)}}function _(e,t,n){try{return{value:JSON.parse(e.slice(t,n)),end:n}}catch{return}}function v(e){let t={},n=g(e,0);if(e.charAt(n)!==`{`)return t;for(n++;;){if(n=g(e,n),e.charAt(n)===`,`&&(n=g(e,n+1)),e.charAt(n)!==`"`)return t;let r=h(e,n);if(r.end===void 0||(n=g(e,r.end),e.charAt(n)!==`:`)||(n=g(e,n+1),n>=e.length))return t;let i=ie(e,n);if(!i)return e.charAt(n)===`"`&&(t[r.text]=h(e,n).text),t;t[r.text]=i.value,n=i.end}}function y(e,t){if(t.phase===void 0)return{name:t.name,callId:t.callId,...t.operationId?{operationId:t.operationId}:{},arguments:t.arguments,...t.reasoning?{reasoning:t.reasoning}:{},...t.stepId?{stepId:t.stepId}:{},artifacts:[]};if(e===void 0)throw new n(`bad_response`,`Tool event '${t.phase}' for call '${t.callId}' arrived before the call.`);if(e.callId!==t.callId||e.name!==t.name)throw new n(`bad_response`,r(`error.bad_response`));switch(t.phase){case`running`:{let{endedAt:n,outputDraft:r,...i}=e;return{...i,state:t,startedAt:t.at,...t.edited?{edited:t.edited}:{},...t.activity?{activity:t.activity}:{}}}case`complete`:return{...b(e),state:t,endedAt:t.at,...t.activityPast?{activityPast:t.activityPast}:{}};case`error`:return{...b(e),state:t,endedAt:t.at,...t.activityPast?{activityPast:t.activityPast}:{}};case`cancel`:case`gate`:return{...b(e),state:t,endedAt:t.at};case`draft`:return{...e,outputDraft:(e.outputDraft??``)+t.text};case`artifact`:return{...e,artifacts:[...e.artifacts,t.artifact]};case`dispatch`:case`progress`:case`trace`:case`warning`:return e}}function b(e){let{outputDraft:t,...n}=e;return n}function x(e,t){return{arguments:{},artifacts:[],...e,name:t.name,callId:t.callId,draft:(e?.draft??``)+t.text}}function ae(e){let t=new Map;for(let n of e){if(n.type===`tool_draft`){t.set(n.callId,x(t.get(n.callId),n));continue}if(n.type!==`tool`)continue;let{tool:e}=n,r=e.operationId??e.callId;e.phase===void 0&&t.get(e.callId)?.draft!==void 0&&t.delete(e.callId),t.set(r,y(t.get(r),e))}return[...t.values()]}function S(e){return(e.state?.phase===`gate`?e.state.gate.preparedArguments:void 0)??e.edited?.to??e.arguments}function C(e,t){return e.type!==`tool`||e.tool.callId!==t?!1:e.tool.phase===`complete`||e.tool.phase===`error`}var w={avif:`image/avif`,gif:`image/gif`,heic:`image/heic`,heif:`image/heif`,jpeg:`image/jpeg`,jpg:`image/jpeg`,png:`image/png`,svg:`image/svg+xml`,webp:`image/webp`,mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,ogv:`video/ogg`,mp3:`audio/mpeg`,m4a:`audio/mp4`,ogg:`audio/ogg`,wav:`audio/wav`};function oe(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n<=0||n===t.length-1?void 0:w[t.slice(n+1).toLowerCase()]}function se(e){let t=e.trim();if(t.length===0)return;let n;try{n=new URL(t)}catch{return}if(n.protocol!==`http:`&&n.protocol!==`https:`)return;let r=oe(n.pathname);if(r)return{url:n.href,mimeType:r}}var ce=/^(.*)\/thumb(\/.+\/([^/]+))\/(\d+)px-\3(?:\.[a-z0-9]+)?$/i;function le(e){let t=new URL(e),n=t.hostname.split(`.`).slice(-2).join(`.`);for(let e of[...t.searchParams.keys()])e.startsWith(`utm_`)&&t.searchParams.delete(e);let r=ce.exec(t.pathname);return{key:`${n}${r?`${r[1]}${r[2]}`:t.pathname}${t.search}`,width:r?Number(r[4]):1/0}}function ue(e){let t=new Map,n=[],r=e=>{if(typeof e==`string`){let r=se(e);if(!r)return;let i=le(r.url),a=t.get(i.key);if(!a){t.set(i.key,{index:n.length,largest:i.width,smallest:i.width}),n.push(r);return}let o=n[a.index];i.width>a.largest?(a.largest=i.width,n[a.index]={...o,url:r.url,previewUrl:o.previewUrl??o.url}):i.width<a.smallest&&(a.smallest=i.width,n[a.index]={...o,previewUrl:r.url})}else if(Array.isArray(e))for(let t of e)r(t);else if(typeof e==`object`&&e)for(let t of Object.values(e))r(t)};return r(e),n}var T=0;function E(e){return e===`user`?`user-${globalThis.crypto.randomUUID()}`:(T+=1,`${e}-${String(T)}`)}function de(e,t){return e?.kind===t}function D(e,t,n,r){let i=e.at(-1);de(i,t)?i.text+=n:e.push({id:E(r),kind:t,text:n})}function O(e,t){let n=e.at(-1),r=n?.kind===`text`||n?.kind===`thought`;e.splice(r?e.length-1:e.length,0,t)}function k(e,t){return e.find(e=>e.kind===`tool`&&e.id===t)}function A(e,t){let n=`tool-${t.operationId??t.callId}`,r=k(e,n),i=y(r?.tool,t);if(r){r.tool=i;return}let a=t.phase===void 0?k(e,`tool-${t.callId}`):void 0;a?.tool.draft===void 0?e.push({id:n,kind:`tool`,tool:i}):(a.id=n,a.tool=i)}function j(e,t){let n=`tool-${t.callId}`,r=k(e,n),i=x(r?.tool,t);r?r.tool=i:e.push({id:n,kind:`tool`,tool:i})}function M(e){return e.findLast(e=>e.kind===`structured`&&e.draft!==void 0)}function N(e,t,n){let r=M(e),i=(r?.draft??``)+t;r?(r.draft=i,r.value=v(i)):e.push({id:E(n),kind:`structured`,value:v(i),draft:i})}function P(e,t,n){let r=M(e);r?(r.value=t,delete r.draft):e.push({id:E(n),kind:`structured`,value:t})}function F(e,t){return e.type===t.type?e.placeId&&t.placeId?e.placeId===t.placeId:e.uri===t.uri:!1}function I(e,t,n){let r=e.find(e=>e.kind===`citation`&&e.callId===t.callId),i=r?[...r.sources]:[];for(let e of t.sources)i.some(t=>F(t,e))||i.push(e);r?r.sources=i:e.push({id:E(n),kind:`citation`,sources:i,...t.callId===void 0?{}:{callId:t.callId}})}function L(e,t,n,r){if(t.phase===`complete`&&t.output!==void 0)for(let i of ue(t.output))r.has(i.url)||(r.add(i.url),e.push({id:E(n),kind:`media`,mimeType:i.mimeType,url:i.url,...i.previewUrl?{previewUrl:i.previewUrl}:{}}))}function R(e,t){return e.messages.flatMap(e=>{if(e.role!==`user`)return[];let n=e.parts??[],r=[e.content??``,...n.map(e=>`text`in e?e.text:``)].join(``).trim();return[...r?[{id:E(t),kind:`user-text`,text:r}]:[],...n.flatMap(e=>`text`in e?[]:[{id:E(t),kind:e.type===`audio`?`user-voice`:`user-attachment`,name:e.mimeType,mimeType:e.mimeType,...`data`in e?{sizeBytes:Math.floor(e.data.length*3/4),data:e.data}:{sizeBytes:0}}])]})}function z(e,t=`user`){let n=[],r=e.text?.trim();r&&n.push({id:E(t),kind:`user-text`,text:r});for(let r of e.attachments??[])n.push({id:E(t),kind:`user-attachment`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});for(let r of e.voice??[])n.push({id:E(t),kind:`user-voice`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});return n}function B(e,t){switch(e.type){case`media`:return e.media?{id:E(t),kind:`media`,mimeType:e.media.mimeType,data:e.media.data}:void 0;case`grounding`:return{id:E(t),kind:`grounding`,grounding:e.grounding};case`evidence`:return{id:E(t),kind:`evidence`,evidence:e.evidence};case`error`:return e.error?{id:E(t),kind:`error`,message:e.error}:void 0;case`done`:return{id:E(t),kind:`turn-done`,stop:e.stop,tokens:e.tokens,interactionId:e.interactionId,compaction:e.compaction!==void 0};default:return}}function V(t,n={}){let r=n.idPrefix??`turn`,i=n.showThoughts??!0;T=0;let a=[],o=new Set;for(let n of e(t))switch(n.type){case`thought`:i&&n.text&&D(a,`thought`,n.text,r);break;case`text`:n.text&&D(a,`text`,n.text,r);break;case`tool_draft`:j(a,n);break;case`tool`:A(a,n.tool),L(a,n.tool,r,o);break;case`structured_draft`:N(a,n.text,r);break;case`structured`:P(a,n.structured,r);break;case`citation`:I(a,n,r);break;case`guardrail`:O(a,{id:E(r),kind:`guardrail`,guardrail:n.guardrail});break;case`stage`:for(let e of n.injected??[])a.push(...R(e,r));break;default:{let e=B(n,r);e&&a.push(e)}}return a}function H(e,t,n={}){return[...z(e,`user`),...V(t,n)]}function fe(e){if(!e)return i;let{detect:t,patterns:n}=e;if(!n)return t;let r=Object.fromEntries(Object.entries(n).map(([e,{theorem:t}])=>[e,{theorem:t,matchers:[]}]));return{...t,sources:r}}function pe(e,t){if(e.text===void 0)return e;let n=a(e.text,`user`,fe(t));return{...e,text:n.text??e.text}}function U(e,t,n){let r=o(e,t);if(!r.ok)return{ok:!1,issues:r.issues};let i=pe(t,n);return{ok:!0,draft:i,blocks:z(i)}}function W(e,t){if(t)return e.models[t]}function G(e){return!!(e.allowModelSelect&&Object.keys(e.models).length>=2)}function K(e,t){let n=W(e,t);return n?.allowEffortSelect?Object.keys(n.efforts??{}).length>=2:!1}function q(e,t){let n=W(e,t);if(!n?.efforts)return;let r=n.defaultEffort?.trim();return r&&n.efforts[r]?r:Object.keys(n.efforts)[0]}function me(e){return G(e)?Object.entries(e.models).map(([e,t])=>({id:e,label:t.apiId})):[]}function he(e,t){if(!K(e,t))return[];let n=W(e,t);return n?.efforts?Object.entries(n.efforts).map(([e,t])=>({alias:e,level:t})):[]}function ge(e){let t=new Set;for(let n of e)if(n.type===`tool`&&n.tool.phase===`complete`)for(let e of s(n.tool.output)??[])t.add(e);return[...t]}function _e(e){let n=t(e,e=>e.type===`done`&&e.tools!==void 0);return n?.type===`done`?n.tools:void 0}function J(e){return e?.streaming?.streamThoughts!==!1}function Y(e){return e.defaultModel??Object.keys(e.models)[0]}function ve(e,t,n){let r=t.model!==void 0&&Object.hasOwn(e.models,t.model)&&(n===void 0||t.model!==Y(n))?t.model:Y(e),i=r===void 0?void 0:e.models[r]?.efforts;return{model:r,effort:r===t.model&&t.effort!==void 0&&i!==void 0&&Object.hasOwn(i,t.effort)&&(n===void 0||t.effort!==q(n,r))?t.effort:q(e,r)}}function X(e){if(!e.operationId)throw new n(`request`,r(`session.gate_expired`));return e.operationId}function ye(e,t){return t.selectedModel??Y(e)}function be(e,t,n){if(!n||!Object.hasOwn(e.models,n))return;let r=e.models[n];if(r.allowEffortSelect)return t.selectedEffort??r.defaultEffort}function Z(e,t){let n=ye(e,t),r=e.allowModelSelect?n:void 0,i=be(e,t,n);return{...r?{model:r}:{},...i?{effort:i}:{}}}function xe(e,t,n){return{name:n.name,input:n.input,...n.gateKind?{gateKind:n.gateKind}:{},sessionPermissions:n.sessionPermissions??t.sessionPermissions,...t.toolSnapshot?{snapshot:t.toolSnapshot}:{},...t.promotedToolIds.length?{promoted:[...t.promotedToolIds]}:{},...Z(e,t)}}function Q(e){return{...e.conversation?{conversation:e.conversation}:{},...e.turnId?{turnId:e.turnId}:{}}}function Se(e,t,n,r={}){let i=(r.walkAway?.calls??[]).map(e=>({callId:e.callId,operationId:X(e)}));return{...Q(r),...Z(e,t),input:n,...i.length?{abandon:i}:{},replay:{sessionPermissions:t.sessionPermissions}}}function Ce(e,t,n,r={}){return{...Q(r),gateId:n.gateId,operationId:n.operationId,decision:n.decision,...n.secret===void 0?{}:{secret:n.secret},...n.page===void 0?{}:{page:n.page},replay:xe(e,t,{...n,gateKind:n.gateKind??(t.gatedTool?.callId===n.gateId?t.gatedTool.gateKind:void 0)})}}function $(e,t){return U(e.inputs,t,e.guardrails)}function we(e,t,n,r=[]){return $(e,{...t.trim()?{text:t}:{},...n.length?{attachments:c(n)}:{},...r.length?{voice:c(r)}:{}})}function Te(e,t){return V(t,{showThoughts:J(e.outputs)})}export{d as C,f as D,te as E,p as O,ae as S,ne as T,H as _,we as a,C as b,J as c,q as d,K as f,U as g,G as h,X as i,ge as l,me as m,Se as n,$ as o,he as p,Te as r,ve as s,Ce as t,_e as u,V as v,re as w,S as x,y};
|
|
@@ -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{
|
|
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{A as a,N as o,c as s,l as c}from"./browser-transport-Dqr5ADge.js";import{t as l}from"./Icon-BqkS-pIq.js";import{t as u}from"./Text-BOqCfzZC.js";import{n as d,o as f}from"./labels-provider-DkA22zkP.js";import{n as p}from"./Card-DruykyeB.js";import{t as m}from"./IconButton-DVUFx-8p.js";import{t as h}from"./Tooltip-BWs5DLrM.js";import{n as g,t as _}from"./arrive-DvbqpeRS.js";import{d as v}from"./reader-Cn4QuGp2.js";import{_ as y,b,g as x,y as S}from"./ConsoleFrame-DpmaIFNA.js";import{c as C,i as w}from"./trace-patterns-D6TbkLLr.js";import{t as T}from"./CardWall-CBRLdDZW.js";var E=e(n(),1),D=t(),O=`var(--duration-medium) var(--ease-standard)`,k=12;function A(){let e=p();return(0,E.useMemo)(()=>({percent:new Intl.NumberFormat(e,{style:`percent`,maximumFractionDigits:0}),decimal:new Intl.NumberFormat(e,{maximumFractionDigits:2}),usd:new Intl.NumberFormat(e,{style:`currency`,currency:`USD`,maximumSignificantDigits:2})}),[e])}function j(e){return C(e?`clear`:`shade2`)}function M({value:e,isLead:t}){return(0,D.jsx)(`div`,{style:{height:k,width:`${String(Math.max(e,.01)*100)}%`,borderRadius:4,background:j(t),transition:`width ${O}`}})}function N({title:e,aside:t,detail:n,answer:a}){let o=d(),s=A(),c=Object.entries(a.probabilities).sort(([,e],[,t])=>t-e);return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:a.choice,note:o(`@theorem.decision.confidence`,{percent:s.percent.format(a.confidence)}),children:(0,D.jsx)(r,{gap:2,role:`list`,children:c.map(([e,t])=>(0,D.jsxs)(r,{gap:1,role:`listitem`,"aria-label":o(`@theorem.decision.option`,{label:e,percent:s.percent.format(t)}),children:[(0,D.jsxs)(i,{gap:2,hAlign:`between`,"aria-hidden":!0,children:[(0,D.jsx)(u,{type:`supporting`,color:`secondary`,maxLines:1,children:e}),(0,D.jsx)(u,{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=d(),s=A(),c=a.length,l=Math.min(c-1,Math.max(0,Math.round(i.score)));return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:a[l]===void 0?s.decimal.format(i.score):F(a[l]),note:[o(`@theorem.decision.score_of`,{score:s.decimal.format(i.score),max:s.decimal.format(c-1)}),o(`@theorem.decision.confidence`,{percent:s.percent.format(i.confidence)})].join(` · `),children:(0,D.jsxs)(r,{gap:1,children:[(0,D.jsxs)(`div`,{"aria-hidden":!0,style:{position:`relative`,display:`flex`,alignItems:`flex-end`,gap:4,height:P},children:[a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,height:`${String(Math.max(.04,i.probabilities[String(t)]??0)*100)}%`,borderRadius:4,background:j(t===l),transition:`height ${O}`}},`${String(t)}:${e}`)),(0,D.jsx)(`div`,{style:{position:`absolute`,insetBlock:-4,left:`${String((i.score+.5)/c*100)}%`,width:0,borderInlineStart:`1.5px dashed var(--color-text-secondary)`,transition:`left ${O}`}})]}),(0,D.jsx)(`div`,{style:{display:`flex`,gap:4},children:a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,minWidth:0},title:e,children:(0,D.jsx)(u,{type:`supporting`,color:`secondary`,maxLines:1,children:F(e)})},`${String(t)}:${e}`))}),(0,D.jsx)(`span`,{style:{position:`absolute`,width:1,height:1,overflow:`hidden`,clipPath:`inset(50%)`},children:a.map((e,t)=>o(`@theorem.decision.option`,{label:e,percent:s.percent.format(i.probabilities[String(t)]??0)})).join(`; `)})]})})}function L({title:e,aside:t,detail:n,answer:r}){let i=A();return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:i.decimal.format(r.noul)})}var R=72,z=168;function B(e){let[t,n]=(0,E.useState)(null);return(0,E.useEffect)(()=>{let t=new Image;t.onload=()=>{n({width:t.naturalWidth,height:t.naturalHeight})},t.src=e},[e]),t}function V(e,t){let n=e.style.color;e.style.color=`var(${t})`;let r=getComputedStyle(e).color;return e.style.color=n,r}function H({source:e,box:t,caption:n}){let r=d(),i=S(e),a=B(i),[o,l]=(0,E.useState)(null);if(!a)return null;let u=y(t),f=a.width*(t.right-t.left)/(a.height*(t.bottom-t.top)),p=r(`@theorem.decision.open_box`);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(h,{content:p,children:(0,D.jsx)(c,{label:p,padding:0,onClick:e=>{let n={outline:V(e.currentTarget,`--color-accent`),shade:V(e.currentTarget,`--color-overlay`)};b(i,t,n).then(l)},children:(0,D.jsx)(`div`,{role:`img`,"aria-label":r(`@theorem.decision.box_in`),style:{position:`relative`,overflow:`hidden`,aspectRatio:String(f),height:z,maxWidth:`100%`,borderRadius:4},children:(0,D.jsx)(`img`,{src:i,alt:``,style:{position:`absolute`,width:`${String(u.width)}%`,height:`${String(u.height)}%`,left:`${String(u.left)}%`,top:`${String(u.top)}%`,maxWidth:`none`}})})})}),(0,D.jsx)(s,{isOpen:o!==null,onOpenChange:e=>{e||l(null)},media:{src:o??i,alt:r(`@theorem.decision.box_marked`),caption:n},hasZoom:!0})]})}function U({title:e,aside:t,detail:n,answer:r,image:i,asked:a}){let o=d(),s=a&&x(a.images,a.state,i),c=A(),{top:l,bottom:u,left:f,right:p}=r.box,m=o(`@theorem.decision.box_edges`,{left:c.percent.format(f),top:c.percent.format(l),right:c.percent.format(p),bottom:c.percent.format(u)});return(0,D.jsx)(w,{title:e,aside:t,detail:n,value:m,note:o(`@theorem.decision.confidence`,{percent:c.percent.format(r.confidence)}),children:s?(0,D.jsx)(H,{source:s,box:r.box,caption:`${e}: ${m}`}):(0,D.jsx)(`div`,{"aria-hidden":!0,style:{position:`relative`,height:R,borderRadius:4,border:`1px solid var(--color-border)`},children:(0,D.jsx)(`div`,{style:{position:`absolute`,insetInlineStart:`${String(f*100)}%`,insetBlockStart:`${String(l*100)}%`,width:`${String((p-f)*100)}%`,height:`${String((u-l)*100)}%`,borderRadius:2,background:j(!0),transition:`all ${O}`}})})})}function W({question:e,answer:t,asked:n,onQuestion:r,detail:i}){let a=d(),s=`${e.id} · ${a(`@theorem.decision.type.${e.type}`)}`;if(!t)return null;let c=a(`@theorem.decision.edit_question`,{question:e.id}),u={title:s,detail:i,aside:r?(0,D.jsx)(m,{label:c,tooltip:c,size:`sm`,variant:`ghost`,icon:(0,D.jsx)(l,{icon:o,size:`xsm`,color:`secondary`}),onClick:()=>{r(e.id)}}):void 0};return t.type===`choice`?(0,D.jsx)(N,{...u,answer:t}):t.type===`score`?(0,D.jsx)(I,{...u,answer:t,labels:e.labels}):t.type===`noul`?(0,D.jsx)(L,{...u,answer:t}):(0,D.jsx)(U,{...u,answer:t,image:e.image,asked:n})}function G({model:e,usage:t,elapsedMs:n,isStale:i,tokens:a,children:o}){let s=d(),c=A();return(0,D.jsx)(g,{children:(0,D.jsxs)(r,{gap:3,style:{opacity:i?.5:1,transition:`opacity ${O}`},"aria-busy":i,children:[o,(0,D.jsx)(_,{children:(0,D.jsx)(u,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:f(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=d();return(0,D.jsx)(G,{model:t.model,usage:t.usage,elapsedMs:n,isStale:r,tokens:e=>s(`@theorem.decision.tokens`,{count:e}),children:(0,D.jsx)(T,{minWidth:260,children:e.questions.map(e=>(0,D.jsx)(_,{children:(0,D.jsx)(W,{question:e,answer:t.answers[e.id],asked:i,onQuestion:a,detail:o?.[e.id]})},e.id))})})}var q={status:`idle`,result:null,elapsedMs:null,startedAt:null,failure:null};function J(e,t){for(let n of t??[])e.traces?.push(n)}function Y(e,t,n){let[r,i]=(0,E.useState)(q),o=(0,E.useRef)(null);(0,E.useEffect)(()=>()=>o.current?.abort(),[]);let s=(0,E.useCallback)(()=>{o.current?.abort(),o.current=null,i(e=>e.status===t?{...e,status:e.result?`done`:`idle`,startedAt:null}:e)},[t]),c=(0,E.useCallback)(async(...r)=>{o.current?.abort();let s=new AbortController;o.current=s,i(e=>({status:t,result:e.result,elapsedMs:e.elapsedMs,startedAt:Date.now(),failure:null}));let c=performance.now();try{let t=await n(e,s.signal,...r);if(s.signal.aborted)return;J(e,t.traces),i({status:`done`,result:t.result,elapsedMs:performance.now()-c,startedAt:null,failure:null})}catch(t){if(s.signal.aborted)return;J(e,v(t)),i(e=>({...e,status:`error`,startedAt:null,failure:a(t)}))}finally{o.current===s&&(o.current=null)}},[e,t,n]);return{...r,call:c,cancel:s}}export{A as a,K as i,G as n,M as r,Y as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{u as t}from"./themeProps-3IqahpCr.js";import{hr as n}from"./tool-schema-DCF2M0n_.js";var r=n.filter(e=>e!==`builtin`),i=`Tool type must be ${r.join(`, `).replace(/, ([^,]+)$/,`, or $1`)}.`,a=e(t(),1);function o(e){let[t,n]=(0,a.useState)(()=>Date.now());return(0,a.useEffect)(()=>{if(!e)return;n(Date.now());let t=globalThis.setInterval(()=>n(Date.now()),1e3);return()=>globalThis.clearInterval(t)},[e]),t}export{r as n,i as r,o as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{E as e,a as t,c as n,i as r,n as i,o as a,r as o,s,w as c,y as l}from"./tree-Cy9xwG_l.js";function u(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function d(e){let t=e=>{if(Array.isArray(e))return e.map(t);if(!u(e))return e;let n=Object.keys(e).filter(t=>e[t]!==void 0).sort();return Object.fromEntries(n.map(n=>[n,t(e[n])]))};return JSON.stringify(t(e))??`undefined`}var f=`agent:`;function p(e,t=`identity`){return t===`identity`?`${f}${e}`:`${f}${e}/${t}`}function m(e){if(!e.startsWith(f))return;let t=e.slice(6),n=t.indexOf(`/`);return n<0?{key:t,inner:`identity`}:{key:t.slice(0,n),inner:t.slice(n+1)}}function h(e,t){return a(t)===void 0?p(e,t):t}function g(e,t){let n=a(t);if(n!==void 0)return e.toolSpecs.some(e=>e.key===n)?{tool:n}:void 0;let o=i(t);if(o!==void 0)return e.providers.some(e=>e.id===o)?{provider:o}:void 0;let s=m(t),c=s&&e.agents.find(e=>e.key===s.key);if(!s||!c||a(s.inner)!==void 0)return;let l=r(_(c,[],e.providers),s.inner);return l?{agent:c.key,ref:l}:void 0}function _(e,t,n){let{key:r,tools:{allow:i,...a},...o}=e,s=new Map(t.map(e=>[e.key,e]));return{...o,providers:n,tools:a,toolSpecs:i.flatMap(e=>s.get(e)??[])}}function ee(e,t){let n=e.agents.find(e=>e.key===t);return n&&_(n,e.toolSpecs,e.providers)}function v(e,t=c(`agent`)){let{toolSpecs:n,tools:r,providers:i,...a}=e;return{...a,key:t,tools:{...r,allow:n.map(e=>e.key)}}}function y(e,t){let n=new Map(t.map(e=>[e.key,e])),r=new Set(e.map(e=>e.key)),i=t.filter(e=>!r.has(e.key));return!e.some(e=>(n.get(e.key)??e)!==e)&&i.length===0?e:[...e.map(e=>n.get(e.key)??e),...i]}function b(e,t,n){return e.agents.map(e=>e.key===t?n(e):e)}var x=e=>e.key,S=e=>e.id;function C(e){let t=Object.fromEntries(e.agents.map(t=>[t.key,e.starts.agents[t.key]??t])),n=new Map(e.toolSpecs.map(e=>[e.key,e])),r=new Set([...n.keys(),...Object.values(t).flatMap(e=>e.tools.allow)]),i={};for(let t of r){let r=e.starts.tools[t]??n.get(t);r&&(i[t]=r)}let a=Object.fromEntries(e.providers.map(t=>[t.id,e.starts.providers[t.id]??t]));for(let n of Object.values(t).flatMap(w)){let t=e.starts.providers[n];t&&!(n in a)&&(a[n]=t)}return{...e,starts:{agents:t,tools:i,providers:a}}}var w=e=>e.modelBindings.map(e=>e.provider);function te(e,t){let n=new Set(e.providers.map(S)),r=[...new Set(t.flatMap(w))].flatMap(t=>{let r=e.starts.providers[t];return r&&!n.has(t)?[r]:[]});return r.length?[...e.providers,...r]:e.providers}function ne(e,t){let n=e.agents.find(e=>e.key===t);return n?C({...e,starts:{...e.starts,agents:{...e.starts.agents,[t]:n}}}):e}function T(e,t,n,r){if(!e.agents.some(e=>e.key===t))return e;let i=r?y(e.toolSpecs,[...r]):e.toolSpecs;return C({...e,toolSpecs:y(i,n.toolSpecs),agents:b(e,t,()=>v(n,t))})}function E(e,t=`identity`){let n=v(e);return G(C({v:5,agents:[n],toolSpecs:e.toolSpecs,providers:e.providers,selected:h(n.key,t),chatWith:n.key,starts:{agents:{},tools:{},providers:{}}}))}function D(e,t){let n=e.agents.find(e=>e.key===t);return n&&{..._(n,[],e.providers),toolSpecs:e.toolSpecs}}function O(e,t,n){if(!e.agents.find(e=>e.key===t))return e;let r=new Set(n.toolSpecs.map(e=>e.key)),i=new Set(e.toolSpecs.map(e=>e.key)),a=n.toolSpecs.filter(e=>!i.has(e.key)).map(e=>e.key),o=e=>e.filter(e=>r.has(e)),{toolSpecs:s,providers:c,tools:l,...u}=n;return C({...e,toolSpecs:n.toolSpecs,agents:e.agents.map(e=>e.key===t?{...u,key:t,tools:{...l,allow:[...o(e.tools.allow),...a]}}:e.tools.allow.every(e=>r.has(e))?e:{...e,tools:{...e.tools,allow:o(e.tools.allow)}})})}function re(t,n=l()){let r=new Map(t.toolSpecs.map(e=>[e.toolName,e.key])),i=n.identity.agentId.trim(),a=t.agents.map(e=>e.identity.agentId),o=i&&e(i,a,e=>`${i}_${e}`),s=v({...n,identity:{...n.identity,agentId:o}});return s.tools.allow=n.toolSpecs.map(e=>r.get(e.toolName)??e.key),C({...t,agents:[...t.agents,s],toolSpecs:[...t.toolSpecs,...n.toolSpecs.filter(e=>!r.has(e.toolName))],selected:p(s.key)})}function ie(t,n){let r=t.agents.findIndex(e=>e.key===n),i=t.agents[r];if(!i)return t;let a=i.identity.agentId.trim()||`agent`,o=t.agents.map(e=>e.identity.agentId),s={...structuredClone(i),key:c(`agent`)};s.identity.agentId=e(`${a}_copy`,o,e=>`${a}_copy${e}`);let l=[...t.agents];return l.splice(r+1,0,s),C({...t,agents:l,selected:p(s.key)})}function ae(e,t){let n=e.agents.findIndex(e=>e.key===t);if(n<0||e.agents.length===1)return e;let r=e.agents[n+1]??e.agents[n-1];if(!r)return e;let i=new Set(e.toolSpecs.filter(e=>e.toolType===`agent`&&e.agentKey===t).map(e=>e.key)),a=e.agents.filter(e=>e.key!==t).map(e=>({...e,tools:{...e.tools,allow:e.tools.allow.filter(e=>!i.has(e))},modelBindings:e.modelBindings.map(e=>e.compactWith===t?{...e,compactWith:void 0}:e)})),o=m(e.selected)?.key===t||[...i].some(t=>e.selected===s(t));return C({...e,agents:a,toolSpecs:e.toolSpecs.filter(e=>!i.has(e.key)).map(e=>e.stageAgentKey===t?{...e,stageAgentKey:void 0}:e),selected:o?p(r.key):e.selected,chatWith:e.chatWith===t?r.key:e.chatWith})}function oe(e,t,n,r){let i=e.agents.find(e=>e.key===t);if(!i||!e.toolSpecs.some(e=>e.key===n)||i.tools.allow.includes(n)===r)return e;let a=r?[...i.tools.allow,n]:i.tools.allow.filter(e=>e!==n);return{...e,agents:b(e,t,()=>({...i,tools:{...i.tools,allow:a}}))}}function se(e,t){if(!e.toolSpecs.some(e=>e.key===t))return e;let n=e.agents.map(e=>e.tools.allow.includes(t)?{...e,tools:{...e.tools,allow:e.tools.allow.filter(e=>e!==t)}}:e);return C({...e,agents:n,toolSpecs:e.toolSpecs.filter(e=>e.key!==t),selected:e.selected===s(t)?p(e.agents[0]?.key??``):e.selected})}var k=(e,t)=>d(e)===d(t),A=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function ce(e){let{agents:t,tools:n,providers:r}=e.starts;return e.agents.every(e=>k(e,t[e.key]))&&e.toolSpecs.every(e=>k(e,n[e.key]))&&e.providers.every(e=>k(e,r[e.id]))&&Object.keys(n).length===e.toolSpecs.length}function le(e){return{...e,starts:{agents:Object.fromEntries(e.agents.map(e=>[e.key,e])),tools:Object.fromEntries(e.toolSpecs.map(e=>[e.key,e])),providers:Object.fromEntries(e.providers.map(e=>[e.id,e]))}}}function ue(e,t,n,r){return{...e,identity:{...e.identity,agentId:t},tools:{...e.tools,allow:e.tools.allow.filter(e=>n.has(e))},modelBindings:e.modelBindings.map(e=>e.compactWith&&!r.has(e.compactWith)?{...e,compactWith:void 0}:e)}}function j(t,n){let r=t.starts.agents[n],i=t.agents.find(e=>e.key===n);if(!r||!i)return t;let a=new Set(t.agents.map(e=>e.key)),o=new Set(t.toolSpecs.map(e=>e.key)),s=t.toolSpecs.map(e=>e.toolName),c=[];for(let n of r.tools.allow){let r=t.starts.tools[n];if(o.has(n)||!r||r.toolType===`agent`&&!a.has(r.agentKey??``))continue;let i=e(r.toolName,s,e=>`${r.toolName}_${e}`);s.push(i),c.push({...r,toolName:i})}let l=c.length?[...t.toolSpecs,...c]:t.toolSpecs,u=new Set(l.map(e=>e.key)),d=r.identity.agentId,f=t.agents.filter(e=>e.key!==n).map(e=>e.identity.agentId),m=ue(r,d&&e(d,f,e=>`${d}_${e}`),u,a);if(c.length===0&&k(m,i))return t;let h=te(t,[r]),_={...t,agents:b(t,n,()=>m),toolSpecs:l,providers:h};return g(_,_.selected)?_:{..._,selected:p(n)}}function de(e,t,n){if(n.facet===`identity`)return j(e,t);if(n.facet===`toolSpec`)return Y(e,n.key);let r=j(e,t),i=r.agents.find(e=>e.key===t),a=e.agents.find(e=>e.key===t);if(r===e||!i||!a)return e;let o=fe(a,i,n);return k(o,a)?e:{...e,agents:b(e,t,()=>o),toolSpecs:n.facet===`tools`?r.toolSpecs:e.toolSpecs,providers:n.facet===`models`||n.facet===`modelBinding`?r.providers:e.providers}}function fe(e,t,n){if(n.facet===`models`)return{...e,models:t.models,modelBindings:t.modelBindings};if(n.facet===`modelBinding`){let r=t.modelBindings.find(e=>e.key===n.key);return r?{...e,modelBindings:e.modelBindings.map(e=>e.key===n.key?r:e)}:e}return n.facet===`toolSpec`?e:M(e,t,n.facet)}function M(e,t,n){return{...e,[n]:t[n]}}function N(e,t){let n=new Map(Object.values(t.starts.agents).map(e=>[e.identity.agentId,e.key])),r=new Map(Object.values(t.starts.tools).map(e=>[e.toolName,e.key])),i=JSON.stringify(e),a=(e,t)=>{t!==void 0&&t!==e&&(i=i.split(e).join(t))};for(let t of e.agents)a(t.key,n.get(t.identity.agentId));for(let t of e.toolSpecs)a(t.key,r.get(t.toolName));let o=JSON.parse(i);return{...o,selected:g(o,t.selected)?t.selected:o.selected,chatWith:o.agents.some(e=>e.key===t.chatWith)?t.chatWith:o.chatWith}}function P(e,t){let n=N(t,e),r=(e,t,n,r,i)=>{let a=new Map(r.map(t=>[e(t),t])),o=new Set([...t.map(e),...Object.keys(n)]),s=t.map(t=>k(t,n[e(t)])?a.get(e(t))??t:t),c=s.filter(t=>!(e(t)in i)).map(t=>[e(t),n[e(t)]??t]);return{held:[...s,...r.filter(t=>!o.has(e(t)))],starts:{...Object.fromEntries(c),...i}}},i=r(x,e.agents,e.starts.agents,n.agents,n.starts.agents),a=r(x,e.toolSpecs,e.starts.tools,n.toolSpecs,n.starts.tools),o=r(S,e.providers,e.starts.providers,n.providers,n.starts.providers);return{...e,agents:i.held,toolSpecs:a.held,providers:o.held,starts:{agents:i.starts,tools:a.starts,providers:o.starts}}}function F(e){let t=new Map,n=e=>{if(Array.isArray(e))for(let t of e)n(t);else if(typeof e==`object`&&e)for(let[r,i]of Object.entries(e))r!==`key`||typeof i!=`string`?n(i):t.has(i)||t.set(i,`#${t.size}`)},r=e=>typeof e==`string`?t.get(e)??e:Array.isArray(e)?e.map(r):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[t.get(e)??e,r(n)])),i={agents:e.agents,toolSpecs:e.toolSpecs,providers:e.providers};n(i);let a=JSON.stringify(r(i)),o=2166136261,s=16777619;for(let e=0;e<a.length;e+=1){let t=a.charCodeAt(e);o=Math.imul(o^t,16777619),s=Math.imul(s^t,2246822507)}return`${a.length.toString(36)}-${(o>>>0).toString(36)}${(s>>>0).toString(36)}`}function I(e,t){return F(e)!==t}var L=/^(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}$/;function R(e){let t=new Map;return JSON.stringify(e).replace(/\b(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}\b/g,e=>(t.has(e)||t.set(e,`#${t.size}`),t.get(e)??e))}function z(e,t){let n=t.map(R),r=new Set,i=[],a=[];for(let o of e){let e=R(o),s=n.findIndex((t,n)=>t===e&&!r.has(n));s<0?a.push(o):(r.add(s),i.push([o,t[s]]))}let o=t.filter((e,t)=>!r.has(t));for(let[e,t]of a.slice(0,o.length).entries())i.push([t,o[e]]);return i}function B(e,t){let n=JSON.stringify(e),r=(e,t,r,i)=>{let a=new Set(r.map(e=>e.key)),o=new Set(e.map(e=>e.key)),s=e.flatMap(e=>a.has(e.key)?[]:t[e.key]??[]),c=r.filter(e=>!o.has(e.key)&&!t[e.key]),[l,u]=[s[0],c[0]];s.length===1&&c.length===1&&l&&u&&R(i(l))===R(i(u))&&(n=n.split(u.key).join(l.key))};return r(t.agents,t.starts.agents,e.agents,e=>({...e,identity:{...e.identity,agentId:``}})),r(t.toolSpecs,t.starts.tools,e.toolSpecs,e=>({...e,toolName:``})),JSON.parse(n)}function V(e,t){let n=JSON.stringify(e);for(let e=0;e<4;e+=1){let e=JSON.parse(n),r=new Map,i=(e,t)=>{if(Array.isArray(e)&&Array.isArray(t))for(let[n,r]of z(e,t))i(n,r);else if(A(e)&&A(t))for(let[n,a]of Object.entries(e)){let e=t[n];n===`key`?typeof a==`string`&&typeof e==`string`&&a!==e&&L.test(a)&&L.test(e)&&r.set(e,a):i(a,e)}};for(let n of e.agents)i(t.agents[n.key],n);for(let n of e.toolSpecs)i(t.tools[n.key],n);if(r.size===0)return e;for(let[e,t]of r)n=n.split(e).join(t)}return JSON.parse(n)}var H=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)&&new Set(e).size===e.length,U=e=>Array.isArray(e)&&e.every(e=>A(e)&&typeof e.key==`string`);function W(e,t,n,r,i){if(k(e,n)||k(t,n))return t;if(A(e)&&A(t)&&A(n)){let a={};for(let o of new Set([...Object.keys(n),...Object.keys(t),...Object.keys(e)])){let s=W(e[o],t[o],n[o],[...r,o],i);s!==void 0&&(a[o]=s)}return a}if(U(e)&&U(t)&&U(n)){let a=new Map(e.map(e=>[e.key,e])),o=new Map(n.map(e=>[e.key,e])),s=[];for(let e of t){let[t,n]=[a.get(e.key),o.get(e.key)],c=[...r,s.length];t?n?s.push(W(t,e,n,c,i)):k(e,t)?i.updated(c):(i.conflict(c,e,void 0),s.push(e)):s.push(e)}let c=new Set(t.map(e=>e.key)),l=s.length;for(let e of n){if(c.has(e.key))continue;let t=a.get(e.key);t?k(e,t)||i.conflict([...r,l++],void 0,e):(i.updated([...r,s.length]),s.push(e),l+=1)}return s}if(k(e,t))return i.updated(r),n;if(H(e)&&H(t)&&H(n)){let a=e.filter(e=>!n.includes(e)),o=n.filter(n=>!e.includes(n)&&!t.includes(n));return i.updated(r),[...t.filter(e=>!a.includes(e)),...o]}return i.conflict(r,t,n),t}function G(e){let t=new Set(e.agents.map(e=>e.key)),n=e.toolSpecs.filter(e=>e.toolType!==`agent`||t.has(e.agentKey??``)).map(e=>e.stageAgentKey&&!t.has(e.stageAgentKey)?{...e,stageAgentKey:void 0}:e),r=new Set(n.map(e=>e.key)),i=e.agents.map(e=>{let n=e.tools.allow.filter(e=>r.has(e)),i=e.modelBindings.map(e=>e.compactWith&&!t.has(e.compactWith)?{...e,compactWith:void 0}:e),a={...e,tools:{...e.tools,allow:n},modelBindings:i};return k(a,e)?e:a}),a=C({...e,agents:i,toolSpecs:n}),o=i[0];return{...a,selected:g(a,a.selected)||!o?a.selected:p(o.key),chatWith:t.has(a.chatWith)||!o?a.chatWith:o.key}}function pe(e,t,n){let r=V(B(N(t,e),e),e.starts),i=[],a=[],o=(e,t,n,r,o,s,c,l)=>{let u=new Map(s.map(e=>[t(e),e])),d=new Set(r.map(e=>t(e))),f=new Set(r.map(e=>n(o[t(e)]??e))),p=new Set(l?.map(n)),m=[],h={...c};for(let s of r){let[r,c]=[o[t(s)],u.get(t(s))],l={kind:e,key:t(s),name:n(c??r??s)};!r||!c&&!p.has(n(r))?(m.push(s),h[t(s)]=r??s):c?m.push(W(r,s,c,[],{updated:e=>i.push({...l,path:e}),conflict:(e,t,n)=>a.push({...l,path:e,mine:t,theirs:n})})):k(s,r)?i.push({...l,path:[]}):(a.push({...l,path:[],mine:s,theirs:void 0}),m.push(s),h[t(s)]=r)}let g=e=>{let r=o[t(e)]??l?.find(t=>n(t)===n(e)&&!f.has(n(t)));if(r)return R(r)===R(e)?`unchanged`:`changed`};for(let r of s){if(d.has(t(r)))continue;let o={kind:e,key:t(r),name:n(r),path:[]},s=g(r);s===`changed`?a.push({...o,mine:void 0,theirs:r}):s===void 0&&(m.push(r),i.push(o))}return{held:m,starts:h}},s=o(`agent`,x,e=>e.identity.agentId,e.agents,e.starts.agents,r.agents,r.starts.agents,n?.agents),c=o(`tool`,x,e=>e.toolName,e.toolSpecs,e.starts.tools,r.toolSpecs,r.starts.tools,n?.toolSpecs),l=o(`provider`,S,S,e.providers,e.starts.providers,r.providers,r.starts.providers,n?.providers);return{workspace:G({...e,agents:s.held,toolSpecs:c.held,providers:l.held,starts:{agents:s.starts,tools:c.starts,providers:l.starts}}),updated:i,conflicts:a,files:r}}var K=Object.freeze({gone:!0});function q(e){if(Array.isArray(e))return e.filter(e=>e!==K).map(q);if(!A(e))return e;let t=Object.entries(e).map(([e,t])=>[e,q(t)]);return Object.fromEntries(t)}function J(e,t,n){let[r,...i]=t;if(r===void 0)return n;if(Array.isArray(e))return typeof r==`number`&&r>=e.length?n===void 0?e:[...e,n]:e.map((e,t)=>t===r?i.length===0&&n===void 0?K:J(e,i,n):e);let a={...A(e)?e:{}},o=J(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function me(e,t){let{agents:n,toolSpecs:r,providers:i}=e.workspace,a={agents:{...e.workspace.starts.agents},tools:{...e.workspace.starts.tools},providers:{...e.workspace.starts.providers}},o=(e,t,n,r)=>r.path.length>0?t.map(t=>e(t)===r.key?J(t,r.path,r.theirs):t):r.theirs===void 0?(delete n[r.key],t.filter(t=>e(t)!==r.key)):(n[r.key]=r.theirs,[...t,r.theirs]);for(let s of new Set(t)){let t=e.conflicts[s];if(t){if(t.kind===`tool`)r=o(x,r,a.tools,t);else if(t.kind===`provider`)i=o(S,i,a.providers,t);else{if(n=o(x,n,a.agents,t),t.path.length>0||t.theirs===void 0)continue;let i=new Set(r.map(e=>e.key)),s=e.files.toolSpecs.filter(e=>e.toolType===`agent`&&e.agentKey===t.key&&!i.has(e.key));for(let e of s)a.tools[e.key]=e;r=[...r,...s],n=n.map(t=>{let n=e.files.agents.find(e=>e.key===t.key)?.tools.allow??[],r=s.map(e=>e.key).filter(e=>n.includes(e)&&!t.tools.allow.includes(e));return r.length?{...t,tools:{...t.tools,allow:[...t.tools.allow,...r]}}:t})}}}return[n,r]=[q(n),q(r)],G({...e.workspace,agents:n,toolSpecs:r,providers:i,starts:a})}function Y(t,n){let r=t.starts.tools[n],i=t.toolSpecs.find(e=>e.key===n);if(!r||!i)return t;let a=t.toolSpecs.filter(e=>e.key!==n).map(e=>e.toolName),o={...r,toolName:e(r.toolName,a,e=>`${r.toolName}_${e}`)};return k(o,i)?t:{...t,toolSpecs:t.toolSpecs.map(e=>e.key===n?o:e)}}function X(e,t){let n=e.providers.find(e=>e.id===t.id);return!n||k(n,t)?e:{...e,providers:e.providers.map(e=>e.id===t.id?t:e)}}function Z(e,t){let n=e.agents.map(e=>w(e).filter(e=>e===t).length);return{models:n.reduce((e,t)=>e+t,0),agents:n.filter(e=>e>0).length}}function Q(e,t,n,r,i){let a=e=>e.provider===r&&e.apiId.trim()===i.trim();return{models:(e.agents.find(e=>e.key===t)?.modelBindings??[]).filter(e=>e.key!==n&&a(e)).map(e=>e.modelId.trim()||`new`),agents:e.agents.filter(e=>e.key!==t&&e.modelBindings.some(a)).map(e=>e.identity.agentId.trim()||`New agent`)}}function he(t,n){return{id:e(`provider`,t,e=>`provider_${e}`),definition:n,connection:{}}}function ge(e,t){return e.providers.some(e=>e.id===t.id)?e:C({...e,providers:[...e.providers,t],selected:o(t.id)})}function _e(e,t){return!e.providers.some(e=>e.id===t)||Z(e,t).models>0?e:C({...e,providers:e.providers.filter(e=>e.id!==t),selected:e.selected===o(t)?p(e.agents[0]?.key??``):e.selected})}function ve(e,t,n){let r=n.trim();if(!e.providers.some(e=>e.id===t)||!r||e.providers.some(e=>e.id===r))return e;let{[t]:i,...a}=e.starts.providers,s=e=>e.provider===t;return{...e,providers:e.providers.map(e=>e.id===t?{...e,id:r}:e),agents:e.agents.map(e=>e.modelBindings.some(s)?{...e,modelBindings:e.modelBindings.map(e=>s(e)?{...e,provider:r}:e)}:e),selected:e.selected===o(t)?o(r):e.selected,starts:{...e.starts,providers:i?{...a,[r]:{...i,id:r}}:a}}}function ye(e){return e.providers.flatMap(t=>{let n=e.starts.providers[t.id];return n&&k(n,t)?[t.id]:[]})}function be(e,t){let n=e.starts.providers[t];return n?X(e,n):e}function $(e,t){return{...t,id:p(e,t.id),children:t.children.map(t=>$(e,t))}}function xe(e,n){let r=$(e.key,t(_(e,[],n)));return e.identity.agentId.trim()?r:{...r,label:`New agent`}}function Se(e){return{agents:e.agents.map(t=>xe(t,e.providers)),tools:n(e.toolSpecs)}}export{me as A,de as C,oe as D,h as E,Se as F,d as I,X as M,E as N,le as O,g as P,j as S,be as T,ae as _,ce as a,ve as b,F as c,pe as d,Q as f,P as g,ye as h,p as i,O as j,T as k,D as l,Z as m,ge as n,ie as o,he as p,ee as r,I as s,re as t,ne as u,se as v,Y as w,N as x,_e as y};
|
|
1
|
+
import{E as e,a as t,c as n,i as r,n as i,o as a,r as o,s,w as c,y as l}from"./tree-BxJ7bZId.js";function u(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function d(e){let t=e=>{if(Array.isArray(e))return e.map(t);if(!u(e))return e;let n=Object.keys(e).filter(t=>e[t]!==void 0).sort();return Object.fromEntries(n.map(n=>[n,t(e[n])]))};return JSON.stringify(t(e))??`undefined`}var f=`agent:`;function p(e,t=`identity`){return t===`identity`?`${f}${e}`:`${f}${e}/${t}`}function m(e){if(!e.startsWith(f))return;let t=e.slice(6),n=t.indexOf(`/`);return n<0?{key:t,inner:`identity`}:{key:t.slice(0,n),inner:t.slice(n+1)}}function h(e,t){return a(t)===void 0?p(e,t):t}function g(e,t){let n=a(t);if(n!==void 0)return e.toolSpecs.some(e=>e.key===n)?{tool:n}:void 0;let o=i(t);if(o!==void 0)return e.providers.some(e=>e.id===o)?{provider:o}:void 0;let s=m(t),c=s&&e.agents.find(e=>e.key===s.key);if(!s||!c||a(s.inner)!==void 0)return;let l=r(_(c,[],e.providers),s.inner);return l?{agent:c.key,ref:l}:void 0}function _(e,t,n){let{key:r,tools:{allow:i,...a},...o}=e,s=new Map(t.map(e=>[e.key,e]));return{...o,providers:n,tools:a,toolSpecs:i.flatMap(e=>s.get(e)??[])}}function ee(e,t){let n=e.agents.find(e=>e.key===t);return n&&_(n,e.toolSpecs,e.providers)}function v(e,t=c(`agent`)){let{toolSpecs:n,tools:r,providers:i,...a}=e;return{...a,key:t,tools:{...r,allow:n.map(e=>e.key)}}}function y(e,t){let n=new Map(t.map(e=>[e.key,e])),r=new Set(e.map(e=>e.key)),i=t.filter(e=>!r.has(e.key));return!e.some(e=>(n.get(e.key)??e)!==e)&&i.length===0?e:[...e.map(e=>n.get(e.key)??e),...i]}function b(e,t,n){return e.agents.map(e=>e.key===t?n(e):e)}var x=e=>e.key,S=e=>e.id;function C(e){let t=Object.fromEntries(e.agents.map(t=>[t.key,e.starts.agents[t.key]??t])),n=new Map(e.toolSpecs.map(e=>[e.key,e])),r=new Set([...n.keys(),...Object.values(t).flatMap(e=>e.tools.allow)]),i={};for(let t of r){let r=e.starts.tools[t]??n.get(t);r&&(i[t]=r)}let a=Object.fromEntries(e.providers.map(t=>[t.id,e.starts.providers[t.id]??t]));for(let n of Object.values(t).flatMap(w)){let t=e.starts.providers[n];t&&!(n in a)&&(a[n]=t)}return{...e,starts:{agents:t,tools:i,providers:a}}}var w=e=>e.modelBindings.map(e=>e.provider);function te(e,t){let n=new Set(e.providers.map(S)),r=[...new Set(t.flatMap(w))].flatMap(t=>{let r=e.starts.providers[t];return r&&!n.has(t)?[r]:[]});return r.length?[...e.providers,...r]:e.providers}function ne(e,t){let n=e.agents.find(e=>e.key===t);return n?C({...e,starts:{...e.starts,agents:{...e.starts.agents,[t]:n}}}):e}function T(e,t,n,r){if(!e.agents.some(e=>e.key===t))return e;let i=r?y(e.toolSpecs,[...r]):e.toolSpecs;return C({...e,toolSpecs:y(i,n.toolSpecs),agents:b(e,t,()=>v(n,t))})}function E(e,t=`identity`){let n=v(e);return G(C({v:5,agents:[n],toolSpecs:e.toolSpecs,providers:e.providers,selected:h(n.key,t),chatWith:n.key,starts:{agents:{},tools:{},providers:{}}}))}function D(e,t){let n=e.agents.find(e=>e.key===t);return n&&{..._(n,[],e.providers),toolSpecs:e.toolSpecs}}function O(e,t,n){if(!e.agents.find(e=>e.key===t))return e;let r=new Set(n.toolSpecs.map(e=>e.key)),i=new Set(e.toolSpecs.map(e=>e.key)),a=n.toolSpecs.filter(e=>!i.has(e.key)).map(e=>e.key),o=e=>e.filter(e=>r.has(e)),{toolSpecs:s,providers:c,tools:l,...u}=n;return C({...e,toolSpecs:n.toolSpecs,agents:e.agents.map(e=>e.key===t?{...u,key:t,tools:{...l,allow:[...o(e.tools.allow),...a]}}:e.tools.allow.every(e=>r.has(e))?e:{...e,tools:{...e.tools,allow:o(e.tools.allow)}})})}function re(t,n=l()){let r=new Map(t.toolSpecs.map(e=>[e.toolName,e.key])),i=n.identity.agentId.trim(),a=t.agents.map(e=>e.identity.agentId),o=i&&e(i,a,e=>`${i}_${e}`),s=v({...n,identity:{...n.identity,agentId:o}});return s.tools.allow=n.toolSpecs.map(e=>r.get(e.toolName)??e.key),C({...t,agents:[...t.agents,s],toolSpecs:[...t.toolSpecs,...n.toolSpecs.filter(e=>!r.has(e.toolName))],selected:p(s.key)})}function ie(t,n){let r=t.agents.findIndex(e=>e.key===n),i=t.agents[r];if(!i)return t;let a=i.identity.agentId.trim()||`agent`,o=t.agents.map(e=>e.identity.agentId),s={...structuredClone(i),key:c(`agent`)};s.identity.agentId=e(`${a}_copy`,o,e=>`${a}_copy${e}`);let l=[...t.agents];return l.splice(r+1,0,s),C({...t,agents:l,selected:p(s.key)})}function ae(e,t){let n=e.agents.findIndex(e=>e.key===t);if(n<0||e.agents.length===1)return e;let r=e.agents[n+1]??e.agents[n-1];if(!r)return e;let i=new Set(e.toolSpecs.filter(e=>e.toolType===`agent`&&e.agentKey===t).map(e=>e.key)),a=e.agents.filter(e=>e.key!==t).map(e=>({...e,tools:{...e.tools,allow:e.tools.allow.filter(e=>!i.has(e))},modelBindings:e.modelBindings.map(e=>e.compactWith===t?{...e,compactWith:void 0}:e)})),o=m(e.selected)?.key===t||[...i].some(t=>e.selected===s(t));return C({...e,agents:a,toolSpecs:e.toolSpecs.filter(e=>!i.has(e.key)).map(e=>e.stageAgentKey===t?{...e,stageAgentKey:void 0}:e),selected:o?p(r.key):e.selected,chatWith:e.chatWith===t?r.key:e.chatWith})}function oe(e,t,n,r){let i=e.agents.find(e=>e.key===t);if(!i||!e.toolSpecs.some(e=>e.key===n)||i.tools.allow.includes(n)===r)return e;let a=r?[...i.tools.allow,n]:i.tools.allow.filter(e=>e!==n);return{...e,agents:b(e,t,()=>({...i,tools:{...i.tools,allow:a}}))}}function se(e,t){if(!e.toolSpecs.some(e=>e.key===t))return e;let n=e.agents.map(e=>e.tools.allow.includes(t)?{...e,tools:{...e.tools,allow:e.tools.allow.filter(e=>e!==t)}}:e);return C({...e,agents:n,toolSpecs:e.toolSpecs.filter(e=>e.key!==t),selected:e.selected===s(t)?p(e.agents[0]?.key??``):e.selected})}var k=(e,t)=>d(e)===d(t),A=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function ce(e){let{agents:t,tools:n,providers:r}=e.starts;return e.agents.every(e=>k(e,t[e.key]))&&e.toolSpecs.every(e=>k(e,n[e.key]))&&e.providers.every(e=>k(e,r[e.id]))&&Object.keys(n).length===e.toolSpecs.length}function le(e){return{...e,starts:{agents:Object.fromEntries(e.agents.map(e=>[e.key,e])),tools:Object.fromEntries(e.toolSpecs.map(e=>[e.key,e])),providers:Object.fromEntries(e.providers.map(e=>[e.id,e]))}}}function ue(e,t,n,r){return{...e,identity:{...e.identity,agentId:t},tools:{...e.tools,allow:e.tools.allow.filter(e=>n.has(e))},modelBindings:e.modelBindings.map(e=>e.compactWith&&!r.has(e.compactWith)?{...e,compactWith:void 0}:e)}}function j(t,n){let r=t.starts.agents[n],i=t.agents.find(e=>e.key===n);if(!r||!i)return t;let a=new Set(t.agents.map(e=>e.key)),o=new Set(t.toolSpecs.map(e=>e.key)),s=t.toolSpecs.map(e=>e.toolName),c=[];for(let n of r.tools.allow){let r=t.starts.tools[n];if(o.has(n)||!r||r.toolType===`agent`&&!a.has(r.agentKey??``))continue;let i=e(r.toolName,s,e=>`${r.toolName}_${e}`);s.push(i),c.push({...r,toolName:i})}let l=c.length?[...t.toolSpecs,...c]:t.toolSpecs,u=new Set(l.map(e=>e.key)),d=r.identity.agentId,f=t.agents.filter(e=>e.key!==n).map(e=>e.identity.agentId),m=ue(r,d&&e(d,f,e=>`${d}_${e}`),u,a);if(c.length===0&&k(m,i))return t;let h=te(t,[r]),_={...t,agents:b(t,n,()=>m),toolSpecs:l,providers:h};return g(_,_.selected)?_:{..._,selected:p(n)}}function de(e,t,n){if(n.facet===`identity`)return j(e,t);if(n.facet===`toolSpec`)return Y(e,n.key);let r=j(e,t),i=r.agents.find(e=>e.key===t),a=e.agents.find(e=>e.key===t);if(r===e||!i||!a)return e;let o=fe(a,i,n);return k(o,a)?e:{...e,agents:b(e,t,()=>o),toolSpecs:n.facet===`tools`?r.toolSpecs:e.toolSpecs,providers:n.facet===`models`||n.facet===`modelBinding`?r.providers:e.providers}}function fe(e,t,n){if(n.facet===`models`)return{...e,models:t.models,modelBindings:t.modelBindings};if(n.facet===`modelBinding`){let r=t.modelBindings.find(e=>e.key===n.key);return r?{...e,modelBindings:e.modelBindings.map(e=>e.key===n.key?r:e)}:e}return n.facet===`toolSpec`?e:M(e,t,n.facet)}function M(e,t,n){return{...e,[n]:t[n]}}function N(e,t){let n=new Map(Object.values(t.starts.agents).map(e=>[e.identity.agentId,e.key])),r=new Map(Object.values(t.starts.tools).map(e=>[e.toolName,e.key])),i=JSON.stringify(e),a=(e,t)=>{t!==void 0&&t!==e&&(i=i.split(e).join(t))};for(let t of e.agents)a(t.key,n.get(t.identity.agentId));for(let t of e.toolSpecs)a(t.key,r.get(t.toolName));let o=JSON.parse(i);return{...o,selected:g(o,t.selected)?t.selected:o.selected,chatWith:o.agents.some(e=>e.key===t.chatWith)?t.chatWith:o.chatWith}}function P(e,t){let n=N(t,e),r=(e,t,n,r,i)=>{let a=new Map(r.map(t=>[e(t),t])),o=new Set([...t.map(e),...Object.keys(n)]),s=t.map(t=>k(t,n[e(t)])?a.get(e(t))??t:t),c=s.filter(t=>!(e(t)in i)).map(t=>[e(t),n[e(t)]??t]);return{held:[...s,...r.filter(t=>!o.has(e(t)))],starts:{...Object.fromEntries(c),...i}}},i=r(x,e.agents,e.starts.agents,n.agents,n.starts.agents),a=r(x,e.toolSpecs,e.starts.tools,n.toolSpecs,n.starts.tools),o=r(S,e.providers,e.starts.providers,n.providers,n.starts.providers);return{...e,agents:i.held,toolSpecs:a.held,providers:o.held,starts:{agents:i.starts,tools:a.starts,providers:o.starts}}}function F(e){let t=new Map,n=e=>{if(Array.isArray(e))for(let t of e)n(t);else if(typeof e==`object`&&e)for(let[r,i]of Object.entries(e))r!==`key`||typeof i!=`string`?n(i):t.has(i)||t.set(i,`#${t.size}`)},r=e=>typeof e==`string`?t.get(e)??e:Array.isArray(e)?e.map(r):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[t.get(e)??e,r(n)])),i={agents:e.agents,toolSpecs:e.toolSpecs,providers:e.providers};n(i);let a=JSON.stringify(r(i)),o=2166136261,s=16777619;for(let e=0;e<a.length;e+=1){let t=a.charCodeAt(e);o=Math.imul(o^t,16777619),s=Math.imul(s^t,2246822507)}return`${a.length.toString(36)}-${(o>>>0).toString(36)}${(s>>>0).toString(36)}`}function I(e,t){return F(e)!==t}var L=/^(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}$/;function R(e){let t=new Map;return JSON.stringify(e).replace(/\b(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}\b/g,e=>(t.has(e)||t.set(e,`#${t.size}`),t.get(e)??e))}function z(e,t){let n=t.map(R),r=new Set,i=[],a=[];for(let o of e){let e=R(o),s=n.findIndex((t,n)=>t===e&&!r.has(n));s<0?a.push(o):(r.add(s),i.push([o,t[s]]))}let o=t.filter((e,t)=>!r.has(t));for(let[e,t]of a.slice(0,o.length).entries())i.push([t,o[e]]);return i}function B(e,t){let n=JSON.stringify(e),r=(e,t,r,i)=>{let a=new Set(r.map(e=>e.key)),o=new Set(e.map(e=>e.key)),s=e.flatMap(e=>a.has(e.key)?[]:t[e.key]??[]),c=r.filter(e=>!o.has(e.key)&&!t[e.key]),[l,u]=[s[0],c[0]];s.length===1&&c.length===1&&l&&u&&R(i(l))===R(i(u))&&(n=n.split(u.key).join(l.key))};return r(t.agents,t.starts.agents,e.agents,e=>({...e,identity:{...e.identity,agentId:``}})),r(t.toolSpecs,t.starts.tools,e.toolSpecs,e=>({...e,toolName:``})),JSON.parse(n)}function V(e,t){let n=JSON.stringify(e);for(let e=0;e<4;e+=1){let e=JSON.parse(n),r=new Map,i=(e,t)=>{if(Array.isArray(e)&&Array.isArray(t))for(let[n,r]of z(e,t))i(n,r);else if(A(e)&&A(t))for(let[n,a]of Object.entries(e)){let e=t[n];n===`key`?typeof a==`string`&&typeof e==`string`&&a!==e&&L.test(a)&&L.test(e)&&r.set(e,a):i(a,e)}};for(let n of e.agents)i(t.agents[n.key],n);for(let n of e.toolSpecs)i(t.tools[n.key],n);if(r.size===0)return e;for(let[e,t]of r)n=n.split(e).join(t)}return JSON.parse(n)}var H=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)&&new Set(e).size===e.length,U=e=>Array.isArray(e)&&e.every(e=>A(e)&&typeof e.key==`string`);function W(e,t,n,r,i){if(k(e,n)||k(t,n))return t;if(A(e)&&A(t)&&A(n)){let a={};for(let o of new Set([...Object.keys(n),...Object.keys(t),...Object.keys(e)])){let s=W(e[o],t[o],n[o],[...r,o],i);s!==void 0&&(a[o]=s)}return a}if(U(e)&&U(t)&&U(n)){let a=new Map(e.map(e=>[e.key,e])),o=new Map(n.map(e=>[e.key,e])),s=[];for(let e of t){let[t,n]=[a.get(e.key),o.get(e.key)],c=[...r,s.length];t?n?s.push(W(t,e,n,c,i)):k(e,t)?i.updated(c):(i.conflict(c,e,void 0),s.push(e)):s.push(e)}let c=new Set(t.map(e=>e.key)),l=s.length;for(let e of n){if(c.has(e.key))continue;let t=a.get(e.key);t?k(e,t)||i.conflict([...r,l++],void 0,e):(i.updated([...r,s.length]),s.push(e),l+=1)}return s}if(k(e,t))return i.updated(r),n;if(H(e)&&H(t)&&H(n)){let a=e.filter(e=>!n.includes(e)),o=n.filter(n=>!e.includes(n)&&!t.includes(n));return i.updated(r),[...t.filter(e=>!a.includes(e)),...o]}return i.conflict(r,t,n),t}function G(e){let t=new Set(e.agents.map(e=>e.key)),n=e.toolSpecs.filter(e=>e.toolType!==`agent`||t.has(e.agentKey??``)).map(e=>e.stageAgentKey&&!t.has(e.stageAgentKey)?{...e,stageAgentKey:void 0}:e),r=new Set(n.map(e=>e.key)),i=e.agents.map(e=>{let n=e.tools.allow.filter(e=>r.has(e)),i=e.modelBindings.map(e=>e.compactWith&&!t.has(e.compactWith)?{...e,compactWith:void 0}:e),a={...e,tools:{...e.tools,allow:n},modelBindings:i};return k(a,e)?e:a}),a=C({...e,agents:i,toolSpecs:n}),o=i[0];return{...a,selected:g(a,a.selected)||!o?a.selected:p(o.key),chatWith:t.has(a.chatWith)||!o?a.chatWith:o.key}}function pe(e,t,n){let r=V(B(N(t,e),e),e.starts),i=[],a=[],o=(e,t,n,r,o,s,c,l)=>{let u=new Map(s.map(e=>[t(e),e])),d=new Set(r.map(e=>t(e))),f=new Set(r.map(e=>n(o[t(e)]??e))),p=new Set(l?.map(n)),m=[],h={...c};for(let s of r){let[r,c]=[o[t(s)],u.get(t(s))],l={kind:e,key:t(s),name:n(c??r??s)};!r||!c&&!p.has(n(r))?(m.push(s),h[t(s)]=r??s):c?m.push(W(r,s,c,[],{updated:e=>i.push({...l,path:e}),conflict:(e,t,n)=>a.push({...l,path:e,mine:t,theirs:n})})):k(s,r)?i.push({...l,path:[]}):(a.push({...l,path:[],mine:s,theirs:void 0}),m.push(s),h[t(s)]=r)}let g=e=>{let r=o[t(e)]??l?.find(t=>n(t)===n(e)&&!f.has(n(t)));if(r)return R(r)===R(e)?`unchanged`:`changed`};for(let r of s){if(d.has(t(r)))continue;let o={kind:e,key:t(r),name:n(r),path:[]},s=g(r);s===`changed`?a.push({...o,mine:void 0,theirs:r}):s===void 0&&(m.push(r),i.push(o))}return{held:m,starts:h}},s=o(`agent`,x,e=>e.identity.agentId,e.agents,e.starts.agents,r.agents,r.starts.agents,n?.agents),c=o(`tool`,x,e=>e.toolName,e.toolSpecs,e.starts.tools,r.toolSpecs,r.starts.tools,n?.toolSpecs),l=o(`provider`,S,S,e.providers,e.starts.providers,r.providers,r.starts.providers,n?.providers);return{workspace:G({...e,agents:s.held,toolSpecs:c.held,providers:l.held,starts:{agents:s.starts,tools:c.starts,providers:l.starts}}),updated:i,conflicts:a,files:r}}var K=Object.freeze({gone:!0});function q(e){if(Array.isArray(e))return e.filter(e=>e!==K).map(q);if(!A(e))return e;let t=Object.entries(e).map(([e,t])=>[e,q(t)]);return Object.fromEntries(t)}function J(e,t,n){let[r,...i]=t;if(r===void 0)return n;if(Array.isArray(e))return typeof r==`number`&&r>=e.length?n===void 0?e:[...e,n]:e.map((e,t)=>t===r?i.length===0&&n===void 0?K:J(e,i,n):e);let a={...A(e)?e:{}},o=J(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function me(e,t){let{agents:n,toolSpecs:r,providers:i}=e.workspace,a={agents:{...e.workspace.starts.agents},tools:{...e.workspace.starts.tools},providers:{...e.workspace.starts.providers}},o=(e,t,n,r)=>r.path.length>0?t.map(t=>e(t)===r.key?J(t,r.path,r.theirs):t):r.theirs===void 0?(delete n[r.key],t.filter(t=>e(t)!==r.key)):(n[r.key]=r.theirs,[...t,r.theirs]);for(let s of new Set(t)){let t=e.conflicts[s];if(t){if(t.kind===`tool`)r=o(x,r,a.tools,t);else if(t.kind===`provider`)i=o(S,i,a.providers,t);else{if(n=o(x,n,a.agents,t),t.path.length>0||t.theirs===void 0)continue;let i=new Set(r.map(e=>e.key)),s=e.files.toolSpecs.filter(e=>e.toolType===`agent`&&e.agentKey===t.key&&!i.has(e.key));for(let e of s)a.tools[e.key]=e;r=[...r,...s],n=n.map(t=>{let n=e.files.agents.find(e=>e.key===t.key)?.tools.allow??[],r=s.map(e=>e.key).filter(e=>n.includes(e)&&!t.tools.allow.includes(e));return r.length?{...t,tools:{...t.tools,allow:[...t.tools.allow,...r]}}:t})}}}return[n,r]=[q(n),q(r)],G({...e.workspace,agents:n,toolSpecs:r,providers:i,starts:a})}function Y(t,n){let r=t.starts.tools[n],i=t.toolSpecs.find(e=>e.key===n);if(!r||!i)return t;let a=t.toolSpecs.filter(e=>e.key!==n).map(e=>e.toolName),o={...r,toolName:e(r.toolName,a,e=>`${r.toolName}_${e}`)};return k(o,i)?t:{...t,toolSpecs:t.toolSpecs.map(e=>e.key===n?o:e)}}function X(e,t){let n=e.providers.find(e=>e.id===t.id);return!n||k(n,t)?e:{...e,providers:e.providers.map(e=>e.id===t.id?t:e)}}function Z(e,t){let n=e.agents.map(e=>w(e).filter(e=>e===t).length);return{models:n.reduce((e,t)=>e+t,0),agents:n.filter(e=>e>0).length}}function Q(e,t,n,r,i){let a=e=>e.provider===r&&e.apiId.trim()===i.trim();return{models:(e.agents.find(e=>e.key===t)?.modelBindings??[]).filter(e=>e.key!==n&&a(e)).map(e=>e.modelId.trim()||`new`),agents:e.agents.filter(e=>e.key!==t&&e.modelBindings.some(a)).map(e=>e.identity.agentId.trim()||`New agent`)}}function he(t,n){return{id:e(`provider`,t,e=>`provider_${e}`),definition:n,connection:{}}}function ge(e,t){return e.providers.some(e=>e.id===t.id)?e:C({...e,providers:[...e.providers,t],selected:o(t.id)})}function _e(e,t){return!e.providers.some(e=>e.id===t)||Z(e,t).models>0?e:C({...e,providers:e.providers.filter(e=>e.id!==t),selected:e.selected===o(t)?p(e.agents[0]?.key??``):e.selected})}function ve(e,t,n){let r=n.trim();if(!e.providers.some(e=>e.id===t)||!r||e.providers.some(e=>e.id===r))return e;let{[t]:i,...a}=e.starts.providers,s=e=>e.provider===t;return{...e,providers:e.providers.map(e=>e.id===t?{...e,id:r}:e),agents:e.agents.map(e=>e.modelBindings.some(s)?{...e,modelBindings:e.modelBindings.map(e=>s(e)?{...e,provider:r}:e)}:e),selected:e.selected===o(t)?o(r):e.selected,starts:{...e.starts,providers:i?{...a,[r]:{...i,id:r}}:a}}}function ye(e){return e.providers.flatMap(t=>{let n=e.starts.providers[t.id];return n&&k(n,t)?[t.id]:[]})}function be(e,t){let n=e.starts.providers[t];return n?X(e,n):e}function $(e,t){return{...t,id:p(e,t.id),children:t.children.map(t=>$(e,t))}}function xe(e,n){let r=$(e.key,t(_(e,[],n)));return e.identity.agentId.trim()?r:{...r,label:`New agent`}}function Se(e){return{agents:e.agents.map(t=>xe(t,e.providers)),tools:n(e.toolSpecs)}}export{me as A,de as C,oe as D,h as E,Se as F,d as I,X as M,E as N,le as O,g as P,j as S,be as T,ae as _,ce as a,ve as b,F as c,pe as d,Q as f,P as g,ye as h,p as i,O as j,T as k,D as l,Z as m,ge as n,ie as o,he as p,ee as r,I as s,re as t,ne as u,se as v,Y as w,N as x,_e as y};
|
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-CL8kmb-k.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">
|
|
@@ -47,22 +47,23 @@
|
|
|
47
47
|
<link rel="modulepreload" crossorigin href="/studio/assets/IconAlertTriangle-BqAEqqdU.js">
|
|
48
48
|
<link rel="modulepreload" crossorigin href="/studio/assets/isRenderable-DHkzpAoQ.js">
|
|
49
49
|
<link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-DkA22zkP.js">
|
|
50
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-D7PiJb6d.js">
|
|
51
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/arrive-DvbqpeRS.js">
|
|
52
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/Center-nHS1JSux.js">
|
|
53
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/IconSearch-BTx66a40.js">
|
|
54
50
|
<link rel="modulepreload" crossorigin href="/studio/assets/schemas-BQ9Jydzb.js">
|
|
55
51
|
<link rel="modulepreload" crossorigin href="/studio/assets/host-patterns-F-KZIzkF.js">
|
|
56
52
|
<link rel="modulepreload" crossorigin href="/studio/assets/shaped-data-AVV4e7rW.js">
|
|
57
53
|
<link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-DCF2M0n_.js">
|
|
58
54
|
<link rel="modulepreload" crossorigin href="/studio/assets/live-ingress-OuSlQ6q7.js">
|
|
55
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/tree-BxJ7bZId.js">
|
|
56
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-D9jsfxnA.js">
|
|
57
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-DQqJ4pIV.js">
|
|
58
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-DkTfuDQL.js">
|
|
59
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/arrive-DvbqpeRS.js">
|
|
60
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/Center-nHS1JSux.js">
|
|
61
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/IconSearch-BTx66a40.js">
|
|
59
62
|
<link rel="modulepreload" crossorigin href="/studio/assets/trace-schema-9CdEyG6Q.js">
|
|
60
63
|
<link rel="modulepreload" crossorigin href="/studio/assets/stub-BMUhx6B5.js">
|
|
61
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/reader-
|
|
62
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/tree-Cy9xwG_l.js">
|
|
63
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/types-CB42MysU.js">
|
|
64
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/reader-Cn4QuGp2.js">
|
|
64
65
|
<link rel="modulepreload" crossorigin href="/studio/assets/useContainerReveal-BFy8N_QU.js">
|
|
65
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-
|
|
66
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-Dqr5ADge.js">
|
|
66
67
|
<link rel="modulepreload" crossorigin href="/studio/assets/focusReturn-CTppP2k0.js">
|
|
67
68
|
<link rel="modulepreload" crossorigin href="/studio/assets/CheckboxInput-CFZ_Wq8-.js">
|
|
68
69
|
<link rel="modulepreload" crossorigin href="/studio/assets/chainEventHandlers-C6ttXGfW.js">
|
|
@@ -72,21 +73,20 @@
|
|
|
72
73
|
<link rel="modulepreload" crossorigin href="/studio/assets/HoverCard-DMyWUvwP.js">
|
|
73
74
|
<link rel="modulepreload" crossorigin href="/studio/assets/IconEye-BB5aY-wQ.js">
|
|
74
75
|
<link rel="modulepreload" crossorigin href="/studio/assets/encode-files-BCf3-Q7y.js">
|
|
75
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/turn-client-
|
|
76
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/turn-client-CFuTLOCL.js">
|
|
76
77
|
<link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-FIawJRo4.js">
|
|
77
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-
|
|
78
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-Uq8vTOQK.js">
|
|
78
79
|
<link rel="modulepreload" crossorigin href="/studio/assets/crypto-CrMpJY2D.js">
|
|
79
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/workspace-
|
|
80
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/workspace-D9otnmy3.js">
|
|
80
81
|
<link rel="modulepreload" crossorigin href="/studio/assets/lent-keys-C32ems-I.js">
|
|
81
82
|
<link rel="modulepreload" crossorigin href="/studio/assets/editors-BJX_S59A.js">
|
|
82
83
|
<link rel="modulepreload" crossorigin href="/studio/assets/studio-session-yEqFQo5o.js">
|
|
83
84
|
<link rel="modulepreload" crossorigin href="/studio/assets/EmptyState-C_uF9Wyj.js">
|
|
84
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-DhbZ0Soz.js">
|
|
85
85
|
<link rel="modulepreload" crossorigin href="/studio/assets/useMenuPress-DLG1QOiE.js">
|
|
86
86
|
<link rel="modulepreload" crossorigin href="/studio/assets/ListItem-QF7KFt0h.js">
|
|
87
87
|
<link rel="modulepreload" crossorigin href="/studio/assets/MenuBottomSheetActionList-3L0HS4Kf.js">
|
|
88
88
|
<link rel="modulepreload" crossorigin href="/studio/assets/useAdaptivePresentation-Bma4-u1a.js">
|
|
89
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/ContextMenu-
|
|
89
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/ContextMenu-DUg5EAc3.js">
|
|
90
90
|
<link rel="modulepreload" crossorigin href="/studio/assets/useFocusReturnVisibility-BHKv5Jwr.js">
|
|
91
91
|
<link rel="stylesheet" crossorigin href="/studio/assets/use-second-ticker-GWBt83pd.css">
|
|
92
92
|
<link rel="stylesheet" crossorigin href="/studio/assets/index-C9rhrCGT.css">
|
package/server/project-source.js
CHANGED
|
@@ -324,6 +324,25 @@ function providerId(project, at, depth) {
|
|
|
324
324
|
? { node: id.initializer, source: held.source, env: held.env }
|
|
325
325
|
: undefined;
|
|
326
326
|
}
|
|
327
|
+
/** The objects a spread picks between, or undefined when it does not pick. */
|
|
328
|
+
function branches(from) {
|
|
329
|
+
const node = unwrapped(from);
|
|
330
|
+
if (ts.isConditionalExpression(node))
|
|
331
|
+
return [node.whenTrue, node.whenFalse];
|
|
332
|
+
if (ts.isBinaryExpression(node) &&
|
|
333
|
+
node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken)
|
|
334
|
+
return [node.right];
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
/** Whether a spread of this adds nothing: `{}`, `undefined`, `null` or `false`. */
|
|
338
|
+
function isNothing(node) {
|
|
339
|
+
const value = unwrapped(node);
|
|
340
|
+
if (ts.isObjectLiteralExpression(value))
|
|
341
|
+
return value.properties.length === 0;
|
|
342
|
+
return (value.kind === ts.SyntaxKind.NullKeyword ||
|
|
343
|
+
value.kind === ts.SyntaxKind.FalseKeyword ||
|
|
344
|
+
(ts.isIdentifier(value) && value.text === 'undefined'));
|
|
345
|
+
}
|
|
327
346
|
/**
|
|
328
347
|
* The object an expression writes out: an object literal, or a provider's `model()` call. Each
|
|
329
348
|
* spread is followed to the object it names. Undefined for anything else.
|
|
@@ -348,6 +367,9 @@ export function shapeOf(project, at, depth = 0) {
|
|
|
348
367
|
// A spread of nothing adds nothing.
|
|
349
368
|
if (inner === MISSING)
|
|
350
369
|
return;
|
|
370
|
+
const chosen = branches(inner.node);
|
|
371
|
+
if (chosen && chosenSpread(chosen.map((node) => ({ ...inner, node }))))
|
|
372
|
+
return;
|
|
351
373
|
const held = shapeOf(project, inner, depth + 1);
|
|
352
374
|
if (!held) {
|
|
353
375
|
shape.open = { node: written, source: at.source, after: new Set() };
|
|
@@ -363,6 +385,27 @@ export function shapeOf(project, at, depth = 0) {
|
|
|
363
385
|
shape.open?.after.add(entry.key);
|
|
364
386
|
}
|
|
365
387
|
};
|
|
388
|
+
/**
|
|
389
|
+
* A spread that picks between objects (`cond ? { a } : {}`, `cond && { a }`) sets each key of
|
|
390
|
+
* each one in code, at the key: which one holds is the code's. False when one cannot be read.
|
|
391
|
+
*/
|
|
392
|
+
const chosenSpread = (chosen) => {
|
|
393
|
+
const shapes = [];
|
|
394
|
+
for (const branch of chosen) {
|
|
395
|
+
const inner = step(project, branch, depth + 1);
|
|
396
|
+
if (inner === MISSING || isNothing(inner.node))
|
|
397
|
+
continue;
|
|
398
|
+
const held = shapeOf(project, inner, depth + 1);
|
|
399
|
+
if (!held || held.open)
|
|
400
|
+
return false;
|
|
401
|
+
shapes.push(held);
|
|
402
|
+
}
|
|
403
|
+
for (const held of shapes) {
|
|
404
|
+
for (const { key, property, source } of held.entries.values())
|
|
405
|
+
put({ key, source, ...(property ? { property } : {}) });
|
|
406
|
+
}
|
|
407
|
+
return true;
|
|
408
|
+
};
|
|
366
409
|
if (ts.isObjectLiteralExpression(node)) {
|
|
367
410
|
shape.own = { node, source: at.source };
|
|
368
411
|
for (const property of node.properties) {
|
package/shared-carry.d.ts
CHANGED
|
@@ -105,7 +105,10 @@ export interface Ask {
|
|
|
105
105
|
places: AskPlace[];
|
|
106
106
|
}
|
|
107
107
|
/** A place as the question shows it: the file's name and the line. The folders it is in are for whoever asks. */
|
|
108
|
-
export declare function shortPlace({ file, line }:
|
|
108
|
+
export declare function shortPlace({ file, line }: {
|
|
109
|
+
file: string;
|
|
110
|
+
line?: number;
|
|
111
|
+
}): string;
|
|
109
112
|
/** The question's line as its text and the places it names, in the order it says them. */
|
|
110
113
|
export declare function askParts(ask: Ask): Array<string | AskPlace>;
|
|
111
114
|
/** What the builder is asked before a change to a shared value is made: the question, then its cause and effect. */
|
package/shared-carry.js
CHANGED
|
@@ -432,7 +432,7 @@ const placeText = ({ file, line }) => `${file}:${String(line)}`;
|
|
|
432
432
|
/** A place as the question shows it: the file's name and the line. The folders it is in are for whoever asks. */
|
|
433
433
|
export function shortPlace({ file, line }) {
|
|
434
434
|
const name = file.slice(Math.max(file.lastIndexOf('/'), file.lastIndexOf('\\')) + 1);
|
|
435
|
-
return `${name === file ? '' : '…/'}${name}
|
|
435
|
+
return `${name === file ? '' : '…/'}${name}${line ? `:${String(line)}` : ''}`;
|
|
436
436
|
}
|
|
437
437
|
/** The question's line as its text and the places it names, in the order it says them. */
|
|
438
438
|
export function askParts(ask) {
|
package/ui/inspector-context.js
CHANGED
|
@@ -45,7 +45,7 @@ export function useRowOrigin(path) {
|
|
|
45
45
|
return undefined;
|
|
46
46
|
return {
|
|
47
47
|
origin,
|
|
48
|
-
said: origin === held.scope.section || origin ===
|
|
48
|
+
said: origin === held.scope.section || origin === above,
|
|
49
49
|
open: () => {
|
|
50
50
|
held.open(origin);
|
|
51
51
|
},
|
package/ui/lib/studio-restore.js
CHANGED
|
@@ -40,12 +40,14 @@ function isWorkspace(value) {
|
|
|
40
40
|
if (!isRecord(starts.providers))
|
|
41
41
|
return false;
|
|
42
42
|
const blank = createBlankDraft();
|
|
43
|
+
// why: a scrub switch is on, off, or whose patterns clean the trace; only the record is checked.
|
|
44
|
+
const shape = { ...blank, observability: { ...blank.observability, scrub: {} } };
|
|
43
45
|
const workspace = value;
|
|
44
46
|
return agents.every((agent) => isRecord(agent) &&
|
|
45
47
|
typeof agent.key === 'string' &&
|
|
46
48
|
isRecord(agent.tools) &&
|
|
47
49
|
Array.isArray(agent.tools.allow) &&
|
|
48
|
-
hasShapeOf(agentDraft(workspace, agent.key),
|
|
50
|
+
hasShapeOf(agentDraft(workspace, agent.key), shape));
|
|
49
51
|
}
|
|
50
52
|
function isStoredWorkspace(value) {
|
|
51
53
|
return (isRecord(value) &&
|
package/ui/profile-editor.js
CHANGED
|
@@ -1717,11 +1717,52 @@ const INCLUDE_FLAGS = [
|
|
|
1717
1717
|
{ key: 'guardrailDecisions', label: 'Decisions' },
|
|
1718
1718
|
{ key: 'guardrailMatchPreview', label: 'Match preview' },
|
|
1719
1719
|
];
|
|
1720
|
-
const
|
|
1720
|
+
const SCRUB_ROWS = [
|
|
1721
1721
|
{ key: 'sensitive', label: 'Sensitive' },
|
|
1722
1722
|
{ key: 'injection', label: 'Injection' },
|
|
1723
1723
|
{ key: 'canary', label: 'Canary' },
|
|
1724
1724
|
];
|
|
1725
|
+
const SCRUB_CHOICES = [
|
|
1726
|
+
{ value: 'on', label: 'On', description: 'With the patterns each detector reads the turn with' },
|
|
1727
|
+
{
|
|
1728
|
+
value: 'both',
|
|
1729
|
+
label: "Theorem's and yours",
|
|
1730
|
+
description: 'Both sides, whatever the turn reads with',
|
|
1731
|
+
},
|
|
1732
|
+
{ value: 'theorem', label: "Theorem's only" },
|
|
1733
|
+
{
|
|
1734
|
+
value: 'host',
|
|
1735
|
+
label: 'Yours only',
|
|
1736
|
+
description: 'Your guardrails.detect patterns and detectors',
|
|
1737
|
+
},
|
|
1738
|
+
{ value: 'off', label: 'Off' },
|
|
1739
|
+
];
|
|
1740
|
+
// why: the canary is Theorem's, so only its side means anything.
|
|
1741
|
+
const CANARY_CHOICES = [
|
|
1742
|
+
{ value: 'on', label: 'On' },
|
|
1743
|
+
{ value: 'off', label: 'Off' },
|
|
1744
|
+
];
|
|
1745
|
+
/** The choice a scrub switch is: the object form names the sides, each on when left out. */
|
|
1746
|
+
function scrubChoice(name, value) {
|
|
1747
|
+
if (typeof value === 'boolean')
|
|
1748
|
+
return value ? 'on' : 'off';
|
|
1749
|
+
const theorem = value.theorem ?? true;
|
|
1750
|
+
if (name === 'canary')
|
|
1751
|
+
return theorem ? 'on' : 'off';
|
|
1752
|
+
const host = value.host ?? true;
|
|
1753
|
+
if (theorem && host)
|
|
1754
|
+
return 'both';
|
|
1755
|
+
if (theorem)
|
|
1756
|
+
return 'theorem';
|
|
1757
|
+
return host ? 'host' : 'off';
|
|
1758
|
+
}
|
|
1759
|
+
const SCRUB_SWITCHES = {
|
|
1760
|
+
on: true,
|
|
1761
|
+
both: { theorem: true, host: true },
|
|
1762
|
+
theorem: { theorem: true, host: false },
|
|
1763
|
+
host: { theorem: false, host: true },
|
|
1764
|
+
off: false,
|
|
1765
|
+
};
|
|
1725
1766
|
/** A set of on-or-off flags as one checklist: the ones on are checked. */
|
|
1726
1767
|
function FlagList({ label, path, flags, value, onChange, }) {
|
|
1727
1768
|
return (_jsx(CheckboxList, { label: label, isLabelHidden: true, density: "compact", value: flags.filter((flag) => value[flag.key]).map((flag) => flag.key), onChange: (checked) => {
|
|
@@ -1750,9 +1791,10 @@ function TracesSection({ observability, set }) {
|
|
|
1750
1791
|
function TraceContentSections({ observability, set }) {
|
|
1751
1792
|
return (_jsxs(_Fragment, { children: [_jsx(InspectorSection, { path: "observability.include", children: _jsx(FlagList, { label: "Keep", path: "observability.include", flags: INCLUDE_FLAGS, value: observability.include, onChange: (include) => {
|
|
1752
1793
|
set({ include });
|
|
1753
|
-
} }) }), _jsx(InspectorSection, { path: "observability.scrub", children: _jsx(
|
|
1754
|
-
|
|
1755
|
-
|
|
1794
|
+
} }) }), _jsx(InspectorSection, { path: "observability.scrub", children: SCRUB_ROWS.map(({ key, label }) => (_jsx(ChoiceRow, { label: label, path: `observability.scrub.${key}`, value: scrubChoice(key, observability.scrub[key]), options: key === 'canary' ? CANARY_CHOICES : SCRUB_CHOICES, onChange: (choice) => {
|
|
1795
|
+
if (choice)
|
|
1796
|
+
set({ scrub: { ...observability.scrub, [key]: SCRUB_SWITCHES[choice] } });
|
|
1797
|
+
} }, key))) })] }));
|
|
1756
1798
|
}
|
|
1757
1799
|
function TraceStorageSection({ observability, set }) {
|
|
1758
1800
|
return (_jsxs(InspectorSection, { title: "Storage", note: sectionNote('traces.storage'), children: [_jsx(NumberRow, { label: "Keep for", path: "observability.retainForDays", field: "retainForDays", units: "days", value: observability.retainForDays, isIntegerOnly: true, onChange: (retainForDays) => {
|