@theoremjs/studio 0.3.4-next.647.g436b659 → 0.3.4-next.671.gfa09ab2
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/README.md +8 -5
- package/cookbooks/catalog.js +18 -5
- package/cookbooks/tools.js +3 -3
- package/label-areas.d.ts +133 -0
- package/label-areas.js +154 -0
- package/mod.d.ts +4 -3
- package/mod.js +4 -3
- package/package.json +4 -4
- package/page/assets/Banner-DEVAsFER.js +4 -0
- package/page/assets/{ConsoleFrame-B7rArrs0.js → ConsoleFrame-CqUUcrR4.js} +1 -1
- package/page/assets/{MenuBottomSheet-CRiCEOWg.js → MenuBottomSheet-DOa09vl1.js} +1 -1
- package/page/assets/{SchemaFields-BoySuRuC.js → SchemaFields-CMwMU1Px.js} +1 -1
- package/page/assets/{ToolResultCharts-C_qojgbn.js → ToolResultCharts-CW23-D1x.js} +1 -1
- package/page/assets/{TraceInspector-DSLg92wY.js → TraceInspector-h030OQ82.js} +1 -1
- package/page/assets/{TraceOverview-TDZ4GUIz.js → TraceOverview-BsON_uZj.js} +1 -1
- package/page/assets/{_virtual_studio-type-sources-B0cSCDug.js → _virtual_studio-type-sources-BwSqfSwd.js} +23 -4
- package/page/assets/browser-connection-DSUHVCT5.js +3 -0
- package/page/assets/browser-engine-Cf6d-zNH.js +11 -0
- package/page/assets/browser-transport-BK4cbTE_.js +45 -0
- package/page/assets/{crypto-B6qD6nxk.js → crypto-CD14HeXH.js} +1 -1
- package/page/assets/{encode-files-CM9H0Lq5.js → encode-files-DhoC5hWG.js} +1 -1
- package/page/assets/{export-agent-BuZ4GIKx.js → export-agent-CaHsJPsM.js} +1 -1
- package/page/assets/{guardrail-tester-bc9lxU9X.js → guardrail-tester-BDhFLvT5.js} +1 -1
- package/page/assets/index-CqwmMJ4C.js +145 -0
- package/page/assets/{live-messages-CHHEtxno.js → live-messages-CiLmR89m.js} +1 -1
- package/page/assets/reader-DrOfMM8I.js +5 -0
- package/page/assets/shaped-data-H1miOZm2.js +20 -0
- package/page/assets/{stub-CWjTbSMX.js → stub-nxRsh1jo.js} +4 -4
- package/page/assets/{studio-code-pane-DevKnszl.js → studio-code-pane-C1wH63Y2.js} +3 -3
- package/page/assets/{studio-console-kpYOJazO.js → studio-console-DRzo4yTy.js} +1 -1
- package/page/assets/{studio-decision-Dq5LDTrl.js → studio-decision-C7QWMm7Q.js} +1 -1
- package/page/assets/{studio-embedding-Cebwv5_l.js → studio-embedding-D8KroBXY.js} +1 -1
- package/page/assets/{studio-host-console-CaaVHxrN.js → studio-host-console-HkX8BerX.js} +2 -2
- package/page/assets/{studio-labels-BQOD-taS.js → studio-labels-6w1SKC2D.js} +1 -1
- package/page/assets/studio-live-BmVeXAu4.js +5 -0
- package/page/assets/{studio-map-BOaPPVXK.js → studio-map-5ZU1nicW.js} +1 -1
- package/page/assets/studio-session-CjUQSXx0.js +1 -0
- package/page/assets/studio-trace-replay-CSbJSN5e.js +3 -0
- package/page/assets/{studio-type-checker-BQmVytwu.js → studio-type-checker-BbUSqqOS.js} +1 -1
- package/page/assets/tool-schema-BmRYaywn.js +17 -0
- package/page/assets/{trace-record-CtL5_CIg.js → trace-record-DxgSKmYY.js} +1 -1
- package/page/assets/tree-3N-1RPZz.js +3 -0
- package/page/assets/{turn-client-yriGS51g.js → turn-client-DN8PawJr.js} +2 -2
- package/page/assets/{use-one-call-8QTXCYlp.js → use-one-call-Br2IVJLU.js} +1 -1
- package/page/assets/{use-second-ticker-rObooyH6.js → use-second-ticker-CEwOSS-d.js} +1 -1
- package/page/assets/{workspace-WKa0_gWg.js → workspace-CTSW941G.js} +1 -1
- package/page/index.html +16 -16
- package/replay.d.ts +13 -8
- package/replay.js +33 -31
- package/run-payload.d.ts +20 -6
- package/run-payload.js +85 -13
- package/runtime-scope.js +1 -0
- package/runtime.js +1 -0
- package/server/project.js +5 -32
- package/transport.d.ts +1 -3
- package/transport.js +0 -9
- package/ui/inspector.js +11 -5
- package/ui/lib/acting-as.js +1 -6
- package/ui/lib/run-keys.d.ts +15 -5
- package/ui/lib/run-keys.js +80 -16
- package/ui/lib/studio-conversation.d.ts +2 -3
- package/ui/lib/studio-conversation.js +28 -65
- package/ui/lib/studio-keep.d.ts +34 -0
- package/ui/lib/studio-keep.js +202 -0
- package/ui/lib/studio-map-kept.d.ts +2 -2
- package/ui/lib/studio-map-kept.js +5 -10
- package/ui/lib/studio-open.d.ts +1 -1
- package/ui/lib/studio-open.js +5 -5
- package/ui/lib/studio-page.js +1 -7
- package/ui/lib/studio-restore.d.ts +2 -3
- package/ui/lib/studio-restore.js +8 -48
- package/ui/lib/studio-run-open.d.ts +10 -5
- package/ui/lib/studio-run-open.js +18 -9
- package/ui/lib/studio-session.d.ts +38 -5
- package/ui/lib/studio-session.js +133 -3
- package/ui/lib/studio-store.js +8 -30
- package/ui/profile-editor.js +37 -185
- package/ui/studio-compare.js +239 -46
- package/ui/studio-run.js +29 -15
- package/ui/studio-screen.d.ts +1 -1
- package/ui/studio-screen.js +8 -9
- package/ui/studio-trace-replay.js +39 -14
- package/vite.mjs +1 -1
- package/page/assets/Banner-CzP7eU2F.js +0 -4
- package/page/assets/browser-connection-QNf4S7Ff.js +0 -3
- package/page/assets/browser-engine-DpEz1HOI.js +0 -11
- package/page/assets/browser-transport-sRqTLzGF.js +0 -45
- package/page/assets/index-CVYQrx1w.js +0 -145
- package/page/assets/reader-DlrsIIkn.js +0 -5
- package/page/assets/shaped-data-DAdn_XvU.js +0 -20
- package/page/assets/studio-live-Bz8YuQcb.js +0 -5
- package/page/assets/studio-session-yEqFQo5o.js +0 -1
- package/page/assets/studio-trace-replay-Ck0X9hTR.js +0 -3
- package/page/assets/tool-schema-B_EOjDjg.js +0 -17
- package/page/assets/tree-DM7jRXMx.js +0 -3
- package/run-payload-core.d.ts +0 -28
- package/run-payload-core.js +0 -117
|
@@ -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-DM7jRXMx.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 v(e,t){let n=e.agents.find(e=>e.key===t);return n&&_(n,e.toolSpecs,e.providers)}function y(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 b(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 x(e,t,n){return e.agents.map(e=>e.key===t?n(e):e)}var S=e=>e.key,C=e=>e.id;function w(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(T)){let t=e.starts.providers[n];t&&!(n in a)&&(a[n]=t)}return{...e,starts:{agents:t,tools:i,providers:a}}}var T=e=>e.modelBindings.map(e=>e.provider);function ee(e,t){let n=new Set(e.providers.map(C)),r=[...new Set(t.flatMap(T))].flatMap(t=>{let r=e.starts.providers[t];return r&&!n.has(t)?[r]:[]});return r.length?[...e.providers,...r]:e.providers}function E(e,t){let n=e.agents.find(e=>e.key===t);return n?w({...e,starts:{...e.starts,agents:{...e.starts.agents,[t]:n}}}):e}function D(e,t,n,r){if(!e.agents.some(e=>e.key===t))return e;let i=r?b(e.toolSpecs,[...r]):e.toolSpecs;return w({...e,toolSpecs:b(i,n.toolSpecs),agents:x(e,t,()=>y(n,t))})}function te(e,t=`identity`){let n=y(e);return K(w({v:5,agents:[n],toolSpecs:e.toolSpecs,providers:e.providers,selected:h(n.key,t),chatWith:n.key,starts:{agents:{},tools:{},providers:{}}}))}function ne(e,t){let n=e.agents.find(e=>e.key===t);return n&&{..._(n,[],e.providers),toolSpecs:e.toolSpecs}}function re(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 w({...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 ie(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=y({...n,identity:{...n.identity,agentId:o}});return s.tools.allow=n.toolSpecs.map(e=>r.get(e.toolName)??e.key),w({...t,agents:[...t.agents,s],toolSpecs:[...t.toolSpecs,...n.toolSpecs.filter(e=>!r.has(e.toolName))],selected:p(s.key)})}function ae(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),w({...t,agents:l,selected:p(s.key)})}function oe(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 w({...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 se(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:x(e,t,()=>({...i,tools:{...i.tools,allow:a}}))}}function ce(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 w({...e,agents:n,toolSpecs:e.toolSpecs.filter(e=>e.key!==t),selected:e.selected===s(t)?p(e.agents[0]?.key??``):e.selected})}var O=(e,t)=>e===t||A(e)===A(t),k=new WeakMap;function A(e){if(typeof e!=`object`||!e)return d(e);let t=k.get(e);if(t!==void 0)return t;let n=d(e);return k.set(e,n),n}var j=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function M(e){let{agents:t,tools:n,providers:r}=e.starts;return e.agents.every(e=>O(e,t[e.key]))&&e.toolSpecs.every(e=>O(e,n[e.key]))&&e.providers.every(e=>O(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 N(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&&O(m,i))return t;let h=ee(t,[r]),_={...t,agents:x(t,n,()=>m),toolSpecs:l,providers:h};return g(_,_.selected)?_:{..._,selected:p(n)}}function de(e,t,n){if(n.facet===`identity`)return N(e,t);if(n.facet===`toolSpec`)return X(e,n.key);let r=N(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 O(o,a)?e:{...e,agents:x(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:P(e,t,n.facet)}function P(e,t,n){return{...e,[n]:t[n]}}function F(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 I(e,t){let n=F(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=>O(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(S,e.agents,e.starts.agents,n.agents,n.starts.agents),a=r(S,e.toolSpecs,e.starts.tools,n.toolSpecs,n.starts.tools),o=r(C,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 L(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 R(e,t){return L(e)!==t}var z=/^(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}$/;function B(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 V(e,t){let n=t.map(B),r=new Set,i=[],a=[];for(let o of e){let e=B(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 pe(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&&B(i(l))===B(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 H(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 V(e,t))i(n,r);else if(j(e)&&j(t))for(let[n,a]of Object.entries(e)){let e=t[n];n===`key`?typeof a==`string`&&typeof e==`string`&&a!==e&&z.test(a)&&z.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 U=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)&&new Set(e).size===e.length,W=e=>Array.isArray(e)&&e.every(e=>j(e)&&typeof e.key==`string`);function G(e,t,n,r,i){if(O(e,n)||O(t,n))return t;if(j(e)&&j(t)&&j(n)){let a={};for(let o of new Set([...Object.keys(n),...Object.keys(t),...Object.keys(e)])){let s=G(e[o],t[o],n[o],[...r,o],i);s!==void 0&&(a[o]=s)}return a}if(W(e)&&W(t)&&W(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(G(t,e,n,c,i)):O(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?O(e,t)||i.conflict([...r,l++],void 0,e):(i.updated([...r,s.length]),s.push(e),l+=1)}return s}if(O(e,t))return i.updated(r),n;if(U(e)&&U(t)&&U(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 K(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 O(a,e)?e:a}),a=w({...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 me(e,t,n){let r=H(pe(F(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(G(r,s,c,[],{updated:e=>i.push({...l,path:e}),conflict:(e,t,n)=>a.push({...l,path:e,mine:t,theirs:n})})):O(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 B(r)===B(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`,S,e=>e.identity.agentId,e.agents,e.starts.agents,r.agents,r.starts.agents,n?.agents),c=o(`tool`,S,e=>e.toolName,e.toolSpecs,e.starts.tools,r.toolSpecs,r.starts.tools,n?.toolSpecs),l=o(`provider`,C,C,e.providers,e.starts.providers,r.providers,r.starts.providers,n?.providers);return{workspace:K({...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 q=Object.freeze({gone:!0});function J(e){if(Array.isArray(e))return e.filter(e=>e!==q).map(J);if(!j(e))return e;let t=Object.entries(e).map(([e,t])=>[e,J(t)]);return Object.fromEntries(t)}function Y(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?q:Y(e,i,n):e);let a={...j(e)?e:{}},o=Y(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function he(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?Y(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(S,r,a.tools,t);else if(t.kind===`provider`)i=o(C,i,a.providers,t);else{if(n=o(S,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]=[J(n),J(r)],K({...e.workspace,agents:n,toolSpecs:r,providers:i,starts:a})}function X(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 O(o,i)?t:{...t,toolSpecs:t.toolSpecs.map(e=>e.key===n?o:e)}}function Z(e,t){let n=e.providers.find(e=>e.id===t.id);return!n||O(n,t)?e:{...e,providers:e.providers.map(e=>e.id===t.id?t:e)}}function Q(e,t){let n=e.agents.map(e=>T(e).filter(e=>e===t).length);return{models:n.reduce((e,t)=>e+t,0),agents:n.filter(e=>e>0).length}}function ge(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()||`Unnamed model`),agents:e.agents.filter(e=>e.key!==t&&e.modelBindings.some(a)).map(e=>e.identity.agentId.trim()||`Unnamed agent`)}}function _e(t,n){return{id:e(`provider`,t,e=>`provider_${e}`),definition:n,connection:{}}}function ve(e,t){return e.providers.some(e=>e.id===t.id)?e:w({...e,providers:[...e.providers,t],selected:o(t.id)})}function ye(e,t){return!e.providers.some(e=>e.id===t)||Q(e,t).models>0?e:w({...e,providers:e.providers.filter(e=>e.id!==t),selected:e.selected===o(t)?p(e.agents[0]?.key??``):e.selected})}function be(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 xe(e){return e.providers.flatMap(t=>{let n=e.starts.providers[t.id];return n&&O(n,t)?[t.id]:[]})}function Se(e,t){let n=e.starts.providers[t];return n?Z(e,n):e}function $(e,t){return{...t,id:p(e,t.id),children:t.children.map(t=>$(e,t))}}function Ce(e,n){return $(e.key,t(_(e,[],n)))}function we(e){return{agents:e.agents.map(t=>Ce(t,e.providers)),tools:n(e.toolSpecs)}}export{he as A,de as C,se as D,h as E,we as F,d as I,Z as M,te as N,le as O,g as P,N as S,Se as T,oe as _,M as a,be as b,L as c,me as d,ge as f,I as g,xe as h,p as i,re as j,D as k,ne as l,Q as m,ve as n,ae as o,_e as p,v as r,R as s,ie as t,E as u,ce as v,X as w,F as x,ye 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-3N-1RPZz.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 v(e,t){let n=e.agents.find(e=>e.key===t);return n&&_(n,e.toolSpecs,e.providers)}function y(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 b(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 x(e,t,n){return e.agents.map(e=>e.key===t?n(e):e)}var S=e=>e.key,C=e=>e.id;function w(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(T)){let t=e.starts.providers[n];t&&!(n in a)&&(a[n]=t)}return{...e,starts:{agents:t,tools:i,providers:a}}}var T=e=>e.modelBindings.map(e=>e.provider);function ee(e,t){let n=new Set(e.providers.map(C)),r=[...new Set(t.flatMap(T))].flatMap(t=>{let r=e.starts.providers[t];return r&&!n.has(t)?[r]:[]});return r.length?[...e.providers,...r]:e.providers}function E(e,t){let n=e.agents.find(e=>e.key===t);return n?w({...e,starts:{...e.starts,agents:{...e.starts.agents,[t]:n}}}):e}function D(e,t,n,r){if(!e.agents.some(e=>e.key===t))return e;let i=r?b(e.toolSpecs,[...r]):e.toolSpecs;return w({...e,toolSpecs:b(i,n.toolSpecs),agents:x(e,t,()=>y(n,t))})}function te(e,t=`identity`){let n=y(e);return K(w({v:5,agents:[n],toolSpecs:e.toolSpecs,providers:e.providers,selected:h(n.key,t),chatWith:n.key,starts:{agents:{},tools:{},providers:{}}}))}function ne(e,t){let n=e.agents.find(e=>e.key===t);return n&&{..._(n,[],e.providers),toolSpecs:e.toolSpecs}}function re(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 w({...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 ie(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=y({...n,identity:{...n.identity,agentId:o}});return s.tools.allow=n.toolSpecs.map(e=>r.get(e.toolName)??e.key),w({...t,agents:[...t.agents,s],toolSpecs:[...t.toolSpecs,...n.toolSpecs.filter(e=>!r.has(e.toolName))],selected:p(s.key)})}function ae(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),w({...t,agents:l,selected:p(s.key)})}function oe(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 w({...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 se(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:x(e,t,()=>({...i,tools:{...i.tools,allow:a}}))}}function ce(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 w({...e,agents:n,toolSpecs:e.toolSpecs.filter(e=>e.key!==t),selected:e.selected===s(t)?p(e.agents[0]?.key??``):e.selected})}var O=(e,t)=>e===t||A(e)===A(t),k=new WeakMap;function A(e){if(typeof e!=`object`||!e)return d(e);let t=k.get(e);if(t!==void 0)return t;let n=d(e);return k.set(e,n),n}var j=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function M(e){let{agents:t,tools:n,providers:r}=e.starts;return e.agents.every(e=>O(e,t[e.key]))&&e.toolSpecs.every(e=>O(e,n[e.key]))&&e.providers.every(e=>O(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 N(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&&O(m,i))return t;let h=ee(t,[r]),_={...t,agents:x(t,n,()=>m),toolSpecs:l,providers:h};return g(_,_.selected)?_:{..._,selected:p(n)}}function de(e,t,n){if(n.facet===`identity`)return N(e,t);if(n.facet===`toolSpec`)return X(e,n.key);let r=N(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 O(o,a)?e:{...e,agents:x(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:P(e,t,n.facet)}function P(e,t,n){return{...e,[n]:t[n]}}function F(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 I(e,t){let n=F(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=>O(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(S,e.agents,e.starts.agents,n.agents,n.starts.agents),a=r(S,e.toolSpecs,e.starts.tools,n.toolSpecs,n.starts.tools),o=r(C,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 L(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 R(e,t){return L(e)!==t}var z=/^(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}$/;function B(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 V(e,t){let n=t.map(B),r=new Set,i=[],a=[];for(let o of e){let e=B(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 pe(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&&B(i(l))===B(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 H(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 V(e,t))i(n,r);else if(j(e)&&j(t))for(let[n,a]of Object.entries(e)){let e=t[n];n===`key`?typeof a==`string`&&typeof e==`string`&&a!==e&&z.test(a)&&z.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 U=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)&&new Set(e).size===e.length,W=e=>Array.isArray(e)&&e.every(e=>j(e)&&typeof e.key==`string`);function G(e,t,n,r,i){if(O(e,n)||O(t,n))return t;if(j(e)&&j(t)&&j(n)){let a={};for(let o of new Set([...Object.keys(n),...Object.keys(t),...Object.keys(e)])){let s=G(e[o],t[o],n[o],[...r,o],i);s!==void 0&&(a[o]=s)}return a}if(W(e)&&W(t)&&W(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(G(t,e,n,c,i)):O(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?O(e,t)||i.conflict([...r,l++],void 0,e):(i.updated([...r,s.length]),s.push(e),l+=1)}return s}if(O(e,t))return i.updated(r),n;if(U(e)&&U(t)&&U(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 K(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 O(a,e)?e:a}),a=w({...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 me(e,t,n){let r=H(pe(F(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(G(r,s,c,[],{updated:e=>i.push({...l,path:e}),conflict:(e,t,n)=>a.push({...l,path:e,mine:t,theirs:n})})):O(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 B(r)===B(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`,S,e=>e.identity.agentId,e.agents,e.starts.agents,r.agents,r.starts.agents,n?.agents),c=o(`tool`,S,e=>e.toolName,e.toolSpecs,e.starts.tools,r.toolSpecs,r.starts.tools,n?.toolSpecs),l=o(`provider`,C,C,e.providers,e.starts.providers,r.providers,r.starts.providers,n?.providers);return{workspace:K({...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 q=Object.freeze({gone:!0});function J(e){if(Array.isArray(e))return e.filter(e=>e!==q).map(J);if(!j(e))return e;let t=Object.entries(e).map(([e,t])=>[e,J(t)]);return Object.fromEntries(t)}function Y(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?q:Y(e,i,n):e);let a={...j(e)?e:{}},o=Y(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function he(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?Y(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(S,r,a.tools,t);else if(t.kind===`provider`)i=o(C,i,a.providers,t);else{if(n=o(S,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]=[J(n),J(r)],K({...e.workspace,agents:n,toolSpecs:r,providers:i,starts:a})}function X(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 O(o,i)?t:{...t,toolSpecs:t.toolSpecs.map(e=>e.key===n?o:e)}}function Z(e,t){let n=e.providers.find(e=>e.id===t.id);return!n||O(n,t)?e:{...e,providers:e.providers.map(e=>e.id===t.id?t:e)}}function Q(e,t){let n=e.agents.map(e=>T(e).filter(e=>e===t).length);return{models:n.reduce((e,t)=>e+t,0),agents:n.filter(e=>e>0).length}}function ge(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()||`Unnamed model`),agents:e.agents.filter(e=>e.key!==t&&e.modelBindings.some(a)).map(e=>e.identity.agentId.trim()||`Unnamed agent`)}}function _e(t,n){return{id:e(`provider`,t,e=>`provider_${e}`),definition:n,connection:{}}}function ve(e,t){return e.providers.some(e=>e.id===t.id)?e:w({...e,providers:[...e.providers,t],selected:o(t.id)})}function ye(e,t){return!e.providers.some(e=>e.id===t)||Q(e,t).models>0?e:w({...e,providers:e.providers.filter(e=>e.id!==t),selected:e.selected===o(t)?p(e.agents[0]?.key??``):e.selected})}function be(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 xe(e){return e.providers.flatMap(t=>{let n=e.starts.providers[t.id];return n&&O(n,t)?[t.id]:[]})}function Se(e,t){let n=e.starts.providers[t];return n?Z(e,n):e}function $(e,t){return{...t,id:p(e,t.id),children:t.children.map(t=>$(e,t))}}function Ce(e,n){return $(e.key,t(_(e,[],n)))}function we(e){return{agents:e.agents.map(t=>Ce(t,e.providers)),tools:n(e.toolSpecs)}}export{he as A,de as C,se as D,h as E,we as F,d as I,Z as M,te as N,le as O,g as P,N as S,Se as T,oe as _,M as a,be as b,L as c,me as d,ge as f,I as g,xe as h,p as i,re as j,D as k,ne as l,Q as m,ve as n,ae as o,_e as p,v as r,R as s,ie as t,E as u,ce as v,X as w,F as x,ye 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-CqwmMJ4C.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">
|
|
@@ -48,20 +48,20 @@
|
|
|
48
48
|
<link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-t4c-5JMk.js">
|
|
49
49
|
<link rel="modulepreload" crossorigin href="/studio/assets/schemas-BQ9Jydzb.js">
|
|
50
50
|
<link rel="modulepreload" crossorigin href="/studio/assets/host-patterns-F-KZIzkF.js">
|
|
51
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/shaped-data-
|
|
52
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-
|
|
51
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/shaped-data-H1miOZm2.js">
|
|
52
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-BmRYaywn.js">
|
|
53
53
|
<link rel="modulepreload" crossorigin href="/studio/assets/live-ingress-OuSlQ6q7.js">
|
|
54
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/tree-
|
|
55
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-
|
|
56
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-
|
|
57
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-
|
|
54
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/tree-3N-1RPZz.js">
|
|
55
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-DSUHVCT5.js">
|
|
56
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-CEwOSS-d.js">
|
|
57
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/Banner-DEVAsFER.js">
|
|
58
58
|
<link rel="modulepreload" crossorigin href="/studio/assets/row-keys-WByP9Hsh.js">
|
|
59
59
|
<link rel="modulepreload" crossorigin href="/studio/assets/Center-nHS1JSux.js">
|
|
60
60
|
<link rel="modulepreload" crossorigin href="/studio/assets/IconSearch-BTx66a40.js">
|
|
61
61
|
<link rel="modulepreload" crossorigin href="/studio/assets/trace-schema-9CdEyG6Q.js">
|
|
62
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/stub-
|
|
63
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/reader-
|
|
64
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-
|
|
62
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/stub-nxRsh1jo.js">
|
|
63
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/reader-DrOfMM8I.js">
|
|
64
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-BK4cbTE_.js">
|
|
65
65
|
<link rel="modulepreload" crossorigin href="/studio/assets/focusReturn-CTppP2k0.js">
|
|
66
66
|
<link rel="modulepreload" crossorigin href="/studio/assets/CheckboxInput-CFZ_Wq8-.js">
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/studio/assets/useScrollLock-Dyf6PHJt.js">
|
|
@@ -71,15 +71,15 @@
|
|
|
71
71
|
<link rel="modulepreload" crossorigin href="/studio/assets/CodeBlock-CfVOtDeO.js">
|
|
72
72
|
<link rel="modulepreload" crossorigin href="/studio/assets/HoverCard-DMyWUvwP.js">
|
|
73
73
|
<link rel="modulepreload" crossorigin href="/studio/assets/IconEye-BB5aY-wQ.js">
|
|
74
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/encode-files-
|
|
75
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/turn-client-
|
|
74
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/encode-files-DhoC5hWG.js">
|
|
75
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/turn-client-DN8PawJr.js">
|
|
76
76
|
<link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-BsIYDnJR.js">
|
|
77
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-
|
|
78
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/crypto-
|
|
79
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/workspace-
|
|
77
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-6w1SKC2D.js">
|
|
78
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/crypto-CD14HeXH.js">
|
|
79
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/workspace-CTSW941G.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/studio/assets/lent-keys-C32ems-I.js">
|
|
81
81
|
<link rel="modulepreload" crossorigin href="/studio/assets/editors-BJX_S59A.js">
|
|
82
|
-
<link rel="modulepreload" crossorigin href="/studio/assets/studio-session-
|
|
82
|
+
<link rel="modulepreload" crossorigin href="/studio/assets/studio-session-CjUQSXx0.js">
|
|
83
83
|
<link rel="modulepreload" crossorigin href="/studio/assets/EmptyState-C_uF9Wyj.js">
|
|
84
84
|
<link rel="modulepreload" crossorigin href="/studio/assets/useMenuPress-DLG1QOiE.js">
|
|
85
85
|
<link rel="modulepreload" crossorigin href="/studio/assets/useAdaptivePresentation-Bma4-u1a.js">
|
package/replay.d.ts
CHANGED
|
@@ -42,11 +42,15 @@ export interface ReplayTurn {
|
|
|
42
42
|
/** The turn as the person saw it. */
|
|
43
43
|
blocks: TranscriptBlock[];
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
45
|
+
/** One conversation of a recording, as a replay reads it. */
|
|
46
46
|
export interface ReplayScript {
|
|
47
47
|
/** The agent the conversation was with. */
|
|
48
48
|
agent: string;
|
|
49
|
+
/** Its `gen_ai.conversation.id`; absent when its turns carried none. */
|
|
50
|
+
conversation?: string;
|
|
49
51
|
turns: ReplayTurn[];
|
|
52
|
+
/** The records its turns came from, in the file's order. */
|
|
53
|
+
records: TraceRecord[];
|
|
50
54
|
/** When the first turn started (epoch ms). */
|
|
51
55
|
recordedAt?: number;
|
|
52
56
|
}
|
|
@@ -65,13 +69,14 @@ export type ReplayDivergence = {
|
|
|
65
69
|
tool: string;
|
|
66
70
|
});
|
|
67
71
|
/**
|
|
68
|
-
* The
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
72
|
+
* The conversations a run's records stand for, in the order each began. Each record whose root
|
|
73
|
+
* is an agent's turn is a turn of the conversation its `gen_ai.conversation.id` names; one agent's
|
|
74
|
+
* turns with no id are one conversation. A record whose root's parent span is in a turn's record
|
|
75
|
+
* (a turn a host ran under `traceparent`) adds its calls to that turn; an agent tool's turn is
|
|
76
|
+
* already inside its caller's record. Compactions between turns and records of anything else (a
|
|
77
|
+
* host's tool call, a decision) hold no turn.
|
|
73
78
|
*/
|
|
74
|
-
export declare function
|
|
79
|
+
export declare function replayScripts(records: readonly TraceRecord[]): ReplayScript[];
|
|
75
80
|
export interface Replay {
|
|
76
81
|
/** Answers each model call from the recording: pass as the runtime's `provider`. */
|
|
77
82
|
provider: (profile: Profile) => TurnModel;
|
|
@@ -99,7 +104,7 @@ export declare function recordedPayload(payload: StudioRunPayload): StudioRunPay
|
|
|
99
104
|
/** The conversation as the person saw it, every turn. */
|
|
100
105
|
export declare function recordedTranscript(script: ReplayScript): TranscriptBlock[];
|
|
101
106
|
/**
|
|
102
|
-
* The
|
|
107
|
+
* The recording's first conversation, opened as history: the same blocks Replay exchange shows and
|
|
103
108
|
* Continue live seeds. Goals and any host that starts on a recorded trace use this, not a second
|
|
104
109
|
* hand-written exchange. Each assistant `turn-done` carries `workedMs` / `endedAt` from its root
|
|
105
110
|
* span, as a live chat's `stampWorked` would. Each settled tool carries `startedAt` / `endedAt`
|
package/replay.js
CHANGED
|
@@ -313,45 +313,51 @@ function compactionOnly(record, root) {
|
|
|
313
313
|
return !sent.text && sent.attachments === 0;
|
|
314
314
|
}
|
|
315
315
|
/**
|
|
316
|
-
* The
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
316
|
+
* The conversations a run's records stand for, in the order each began. Each record whose root
|
|
317
|
+
* is an agent's turn is a turn of the conversation its `gen_ai.conversation.id` names; one agent's
|
|
318
|
+
* turns with no id are one conversation. A record whose root's parent span is in a turn's record
|
|
319
|
+
* (a turn a host ran under `traceparent`) adds its calls to that turn; an agent tool's turn is
|
|
320
|
+
* already inside its caller's record. Compactions between turns and records of anything else (a
|
|
321
|
+
* host's tool call, a decision) hold no turn.
|
|
321
322
|
*/
|
|
322
|
-
export function
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const turns = [];
|
|
326
|
-
const others = new Set();
|
|
327
|
-
/** The turn each recorded span belongs to, by `traceId:spanId`. */
|
|
323
|
+
export function replayScripts(records) {
|
|
324
|
+
const scripts = new Map();
|
|
325
|
+
/** The turn each recorded span belongs to, by `traceId:spanId`, and its conversation. */
|
|
328
326
|
const owners = new Map();
|
|
329
|
-
const claim = (record,
|
|
327
|
+
const claim = (record, owner) => {
|
|
330
328
|
for (const span of record.spans)
|
|
331
|
-
owners.set(spanKey(span.traceId, span.spanId),
|
|
329
|
+
owners.set(spanKey(span.traceId, span.spanId), owner);
|
|
330
|
+
owner.script.records.push(record);
|
|
332
331
|
};
|
|
333
332
|
records.forEach((record, index) => {
|
|
334
333
|
const root = recordRoot(record);
|
|
335
334
|
if (!root || operation(root) !== 'invoke_agent' || compactionOnly(record, root))
|
|
336
335
|
return;
|
|
337
|
-
const name = stringAttribute(root, 'gen_ai.agent.name') ?? '';
|
|
338
336
|
const calls = recordCalls(record);
|
|
339
337
|
const results = recordResults(record);
|
|
340
338
|
const parent = root.parentSpanId
|
|
341
339
|
? owners.get(spanKey(root.traceId, root.parentSpanId))
|
|
342
340
|
: undefined;
|
|
343
341
|
if (parent) {
|
|
344
|
-
parent.calls.push(...calls);
|
|
345
|
-
parent.results.push(...results);
|
|
342
|
+
parent.turn.calls.push(...calls);
|
|
343
|
+
parent.turn.results.push(...results);
|
|
346
344
|
claim(record, parent);
|
|
347
345
|
return;
|
|
348
346
|
}
|
|
349
|
-
agent
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
347
|
+
const agent = stringAttribute(root, 'gen_ai.agent.name') ?? '';
|
|
348
|
+
const conversation = stringAttribute(root, 'gen_ai.conversation.id');
|
|
349
|
+
const key = `${agent}\u0000${conversation ?? ''}`;
|
|
350
|
+
let script = scripts.get(key);
|
|
351
|
+
if (!script) {
|
|
352
|
+
script = {
|
|
353
|
+
agent,
|
|
354
|
+
...(conversation === undefined ? {} : { conversation }),
|
|
355
|
+
turns: [],
|
|
356
|
+
records: [],
|
|
357
|
+
recordedAt: Number(startOf(root) / 1000000n),
|
|
358
|
+
};
|
|
359
|
+
scripts.set(key, script);
|
|
353
360
|
}
|
|
354
|
-
recordedAt ??= Number(startOf(root) / 1000000n);
|
|
355
361
|
const sent = userMessage(record, root);
|
|
356
362
|
const turn = {
|
|
357
363
|
...sent,
|
|
@@ -361,15 +367,10 @@ export function replayScript(records) {
|
|
|
361
367
|
idPrefix: `recorded-${String(index)}`,
|
|
362
368
|
}), root),
|
|
363
369
|
};
|
|
364
|
-
turns.push(turn);
|
|
365
|
-
claim(record, turn);
|
|
370
|
+
script.turns.push(turn);
|
|
371
|
+
claim(record, { turn, script });
|
|
366
372
|
});
|
|
367
|
-
|
|
368
|
-
const agents = [agent, ...others].join(', ');
|
|
369
|
-
// labels-exempt: builder diagnostic
|
|
370
|
-
throw new TheoremError('request', `This file holds conversations of more than one agent (${agents}). Open a file with one agent's turns.`);
|
|
371
|
-
}
|
|
372
|
-
return { agent, turns, ...(recordedAt === undefined ? {} : { recordedAt }) };
|
|
373
|
+
return [...scripts.values()];
|
|
373
374
|
}
|
|
374
375
|
/** A recorded result as a function tool returns it: its JSON object, else its text. */
|
|
375
376
|
function resultOutput(result) {
|
|
@@ -493,14 +494,15 @@ export function recordedTranscript(script) {
|
|
|
493
494
|
return script.turns.flatMap((turn) => turn.blocks);
|
|
494
495
|
}
|
|
495
496
|
/**
|
|
496
|
-
* The
|
|
497
|
+
* The recording's first conversation, opened as history: the same blocks Replay exchange shows and
|
|
497
498
|
* Continue live seeds. Goals and any host that starts on a recorded trace use this, not a second
|
|
498
499
|
* hand-written exchange. Each assistant `turn-done` carries `workedMs` / `endedAt` from its root
|
|
499
500
|
* span, as a live chat's `stampWorked` would. Each settled tool carries `startedAt` / `endedAt`
|
|
500
501
|
* from its `execute_tool` span (via running then settle), as a live turn would.
|
|
501
502
|
*/
|
|
502
503
|
export function openingFromRecords(records) {
|
|
503
|
-
|
|
504
|
+
const [first] = replayScripts(records);
|
|
505
|
+
return first ? recordedTranscript(first) : [];
|
|
504
506
|
}
|
|
505
507
|
/** One record of a trace file, or why it is not one; `where` names its place in the file. */
|
|
506
508
|
function traceRecordAt(value, where) {
|
package/run-payload.d.ts
CHANGED
|
@@ -2,9 +2,7 @@ import type { DecisionAsset, DecisionQuestion, ProfileDefinition } from '@theore
|
|
|
2
2
|
import type { StudioConnectionMode } from './policy.ts';
|
|
3
3
|
import type { StudioProvider } from './providers.ts';
|
|
4
4
|
import type { StructuredRegistration, ToolRegistration } from './registrations.ts';
|
|
5
|
-
import { createStudioRunId, keptStudioRunIds, readStudioRunIdFromUrl, STUDIO_RUN_INDEX_KEY, STUDIO_RUN_PAYLOAD_CAP, STUDIO_RUN_PAYLOAD_KEY, STUDIO_RUN_PAYLOAD_KEY_PREFIX, type StudioRunIndex, type StudioRunIndexEntry, studioRunPayloadKey, upsertStudioRunIndex } from './run-payload-core.ts';
|
|
6
5
|
import type { StudioDependency } from './runtime-scope.ts';
|
|
7
|
-
export { createStudioRunId, keptStudioRunIds, readStudioRunIdFromUrl, STUDIO_RUN_INDEX_KEY, STUDIO_RUN_PAYLOAD_CAP, STUDIO_RUN_PAYLOAD_KEY, STUDIO_RUN_PAYLOAD_KEY_PREFIX, type StudioRunIndex, type StudioRunIndexEntry, studioRunPayloadKey, upsertStudioRunIndex, };
|
|
8
6
|
export type StudioRunPayload = {
|
|
9
7
|
/** Execution choice only. Credentials never belong in this persisted payload. */
|
|
10
8
|
connectionMode?: StudioConnectionMode;
|
|
@@ -23,7 +21,23 @@ export type StudioRunPayload = {
|
|
|
23
21
|
/** The agents this one names, each after the agents it names; registered before it. */
|
|
24
22
|
dependencies?: StudioDependency[];
|
|
25
23
|
};
|
|
26
|
-
/**
|
|
27
|
-
export declare function
|
|
28
|
-
export declare function
|
|
29
|
-
export declare function
|
|
24
|
+
/** The outline of a kept run, or null when `raw` is not one. `defineProfile` checks its profiles when the run opens. */
|
|
25
|
+
export declare function keptStudioRun(raw: unknown): StudioRunPayload | null;
|
|
26
|
+
export declare function createStudioRunId(): string;
|
|
27
|
+
export declare function readStudioRunIdFromUrl(url?: string | {
|
|
28
|
+
href: string;
|
|
29
|
+
}): string | null;
|
|
30
|
+
/** A tool's credentials in a run: what its kept copy masks, and the run tab asks the studio tab for. */
|
|
31
|
+
export type StudioRunCredentials = Record<string, {
|
|
32
|
+
endpoint?: string;
|
|
33
|
+
serverUrl?: string;
|
|
34
|
+
headers?: Record<string, string>;
|
|
35
|
+
}>;
|
|
36
|
+
/** The run as this browser keeps it: each tool's URLs and headers with their credentials masked. */
|
|
37
|
+
export declare function maskedStudioRun(payload: StudioRunPayload): StudioRunPayload;
|
|
38
|
+
/** Each tool's credentials in `payload`, by tool name. */
|
|
39
|
+
export declare function studioRunCredentials(payload: StudioRunPayload): StudioRunCredentials;
|
|
40
|
+
/** Whether keeping the run masked anything, so the run tab needs the studio tab's credentials. */
|
|
41
|
+
export declare function studioRunIsMasked(payload: StudioRunPayload): boolean;
|
|
42
|
+
/** A kept run with what its copy masked put back from `held`, the studio tab's credentials. */
|
|
43
|
+
export declare function withStudioRunCredentials(payload: StudioRunPayload, held: StudioRunCredentials): StudioRunPayload;
|
package/run-payload.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { maskHeaders, maskUrl, unmaskHeaders, unmaskUrl } from '@theoremjs/agents/surface';
|
|
1
2
|
import { z } from 'zod';
|
|
2
|
-
import { clearStudioRunPayloadRecord, createStudioRunId, keptStudioRunIds, loadStudioRunPayloadRecord, readStudioRunIdFromUrl, STUDIO_RUN_INDEX_KEY, STUDIO_RUN_PAYLOAD_CAP, STUDIO_RUN_PAYLOAD_KEY, STUDIO_RUN_PAYLOAD_KEY_PREFIX, saveStudioRunPayloadRecord, studioRunPayloadKey, upsertStudioRunIndex, } from "./run-payload-core.js";
|
|
3
|
-
export { createStudioRunId, keptStudioRunIds, readStudioRunIdFromUrl, STUDIO_RUN_INDEX_KEY, STUDIO_RUN_PAYLOAD_CAP, STUDIO_RUN_PAYLOAD_KEY, STUDIO_RUN_PAYLOAD_KEY_PREFIX, studioRunPayloadKey, upsertStudioRunIndex, };
|
|
4
3
|
const kept = z.looseObject({
|
|
5
4
|
profile: z.looseObject({ id: z.string() }),
|
|
6
5
|
customTools: z.array(z.looseObject({ name: z.string() })),
|
|
@@ -10,17 +9,90 @@ const keptRun = kept.extend({
|
|
|
10
9
|
agentId: z.string(),
|
|
11
10
|
dependencies: z.array(kept).optional(),
|
|
12
11
|
});
|
|
13
|
-
/**
|
|
14
|
-
export function
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
export function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
/** The outline of a kept run, or null when `raw` is not one. `defineProfile` checks its profiles when the run opens. */
|
|
13
|
+
export function keptStudioRun(raw) {
|
|
14
|
+
return keptRun.safeParse(raw).success ? raw : null;
|
|
15
|
+
}
|
|
16
|
+
export function createStudioRunId() {
|
|
17
|
+
return crypto.randomUUID();
|
|
18
|
+
}
|
|
19
|
+
export function readStudioRunIdFromUrl(url = typeof window !== 'undefined'
|
|
20
|
+
? globalThis.location
|
|
21
|
+
: { href: '' }) {
|
|
22
|
+
const href = typeof url === 'string' ? url : url.href;
|
|
23
|
+
if (!href)
|
|
21
24
|
return null;
|
|
22
|
-
|
|
25
|
+
try {
|
|
26
|
+
const parsed = new URL(href, 'http://localhost');
|
|
27
|
+
const run = parsed.searchParams.get('run')?.trim();
|
|
28
|
+
return run && run.length > 0 ? run : null;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function eachTool(payload) {
|
|
35
|
+
return [
|
|
36
|
+
...payload.customTools,
|
|
37
|
+
...(payload.dependencies ?? []).flatMap((dependency) => dependency.customTools),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
function mapTools(payload, change) {
|
|
41
|
+
return {
|
|
42
|
+
...payload,
|
|
43
|
+
customTools: payload.customTools.map(change),
|
|
44
|
+
...(payload.dependencies
|
|
45
|
+
? {
|
|
46
|
+
dependencies: payload.dependencies.map((dependency) => ({
|
|
47
|
+
...dependency,
|
|
48
|
+
customTools: dependency.customTools.map(change),
|
|
49
|
+
})),
|
|
50
|
+
}
|
|
51
|
+
: {}),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** The run as this browser keeps it: each tool's URLs and headers with their credentials masked. */
|
|
55
|
+
export function maskedStudioRun(payload) {
|
|
56
|
+
return mapTools(payload, (tool) => {
|
|
57
|
+
if (tool.type === 'http')
|
|
58
|
+
return {
|
|
59
|
+
...tool,
|
|
60
|
+
endpoint: maskUrl(tool.endpoint),
|
|
61
|
+
...(tool.headers ? { headers: maskHeaders(tool.headers) } : {}),
|
|
62
|
+
};
|
|
63
|
+
if (tool.type === 'mcp')
|
|
64
|
+
return {
|
|
65
|
+
...tool,
|
|
66
|
+
serverUrl: maskUrl(tool.serverUrl),
|
|
67
|
+
...(tool.headers ? { headers: maskHeaders(tool.headers) } : {}),
|
|
68
|
+
};
|
|
69
|
+
return tool;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/** Each tool's credentials in `payload`, by tool name. */
|
|
73
|
+
export function studioRunCredentials(payload) {
|
|
74
|
+
const held = {};
|
|
75
|
+
for (const tool of eachTool(payload)) {
|
|
76
|
+
if (tool.type === 'http')
|
|
77
|
+
held[tool.name] = { endpoint: tool.endpoint, headers: tool.headers };
|
|
78
|
+
if (tool.type === 'mcp')
|
|
79
|
+
held[tool.name] = { serverUrl: tool.serverUrl, headers: tool.headers };
|
|
80
|
+
}
|
|
81
|
+
return held;
|
|
82
|
+
}
|
|
83
|
+
/** Whether keeping the run masked anything, so the run tab needs the studio tab's credentials. */
|
|
84
|
+
export function studioRunIsMasked(payload) {
|
|
85
|
+
return JSON.stringify(maskedStudioRun(payload)) !== JSON.stringify(payload);
|
|
23
86
|
}
|
|
24
|
-
|
|
25
|
-
|
|
87
|
+
/** A kept run with what its copy masked put back from `held`, the studio tab's credentials. */
|
|
88
|
+
export function withStudioRunCredentials(payload, held) {
|
|
89
|
+
return mapTools(payload, (tool) => {
|
|
90
|
+
const real = held[tool.name];
|
|
91
|
+
if (!real || (tool.type !== 'http' && tool.type !== 'mcp'))
|
|
92
|
+
return tool;
|
|
93
|
+
const headers = tool.headers && real.headers ? { headers: unmaskHeaders(tool.headers, real.headers) } : {};
|
|
94
|
+
if (tool.type === 'http')
|
|
95
|
+
return { ...tool, endpoint: unmaskUrl(tool.endpoint, real.endpoint ?? ''), ...headers };
|
|
96
|
+
return { ...tool, serverUrl: unmaskUrl(tool.serverUrl, real.serverUrl ?? ''), ...headers };
|
|
97
|
+
});
|
|
26
98
|
}
|
package/runtime-scope.js
CHANGED
|
@@ -31,6 +31,7 @@ function scriptedProvider(id, protocolId, model) {
|
|
|
31
31
|
name: 'Scripted',
|
|
32
32
|
description: 'Answers with the events a scripted model gives.',
|
|
33
33
|
endpoints: { text: '/', image: '/', speech: '/' },
|
|
34
|
+
operationNames: { text: 'chat', image: 'generate_content', speech: 'generate_content' },
|
|
34
35
|
options: z.record(z.string(), z.json()),
|
|
35
36
|
create: (context) => ({
|
|
36
37
|
async *complete(request) {
|
package/runtime.js
CHANGED
|
@@ -67,6 +67,7 @@ function studioRunner(args) {
|
|
|
67
67
|
pageExecution: runtime.pageExecution,
|
|
68
68
|
metadata,
|
|
69
69
|
input: turn.input,
|
|
70
|
+
...(turn.conversationId ? { conversationId: turn.conversationId } : {}),
|
|
70
71
|
providerState: turn.providerState,
|
|
71
72
|
sessionPermissions: args.sessionPermissions,
|
|
72
73
|
resolveHost: runtime.resolveHost,
|
package/server/project.js
CHANGED
|
@@ -12,47 +12,20 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @module
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
17
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
18
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
return path;
|
|
22
|
-
};
|
|
23
|
-
import { basename, dirname, resolve } from 'node:path';
|
|
24
|
-
import { pathToFileURL } from 'node:url';
|
|
15
|
+
import { basename } from 'node:path';
|
|
25
16
|
import { defaultKernelScope } from '@theoremjs/agents';
|
|
17
|
+
import { loadSetup } from '@theoremjs/agents/cli';
|
|
26
18
|
import { editedImages, editedQuestions, registerEdits } from "./edits.js";
|
|
27
19
|
import { createStudioHandler } from "./handler.js";
|
|
28
|
-
/**
|
|
29
|
-
* The application's turn wiring: the `theorem` its entry exports. A setup written before the entry
|
|
30
|
-
* existed fails here, and says what moved where.
|
|
31
|
-
*/
|
|
32
|
-
async function wiringOf(setupPath, setup) {
|
|
33
|
-
const moved = ['default', 'provider'].filter((name) => setup[name] !== undefined);
|
|
34
|
-
if (moved.length > 0) {
|
|
35
|
-
throw new Error(`${setupPath} exports ${moved.map((name) => `\`${name}\``).join(' and ')}. The app's wiring moved to its entry: export \`theorem\` (a TurnWiring) from the entry, with registration in \`theorem.register\` and keys in \`theorem.provider\`, and export \`entry\` from the setup.`);
|
|
36
|
-
}
|
|
37
|
-
if (typeof setup.entry !== 'string' || !setup.entry) {
|
|
38
|
-
throw new Error(`${setupPath} names no entry. Export \`entry\`: the path of your app's entry point, relative to the setup file, which exports \`theorem\` (a TurnWiring).`);
|
|
39
|
-
}
|
|
40
|
-
const entryPath = resolve(dirname(resolve(setupPath)), setup.entry);
|
|
41
|
-
const entry = await import(__rewriteRelativeImportExtension(pathToFileURL(entryPath).href));
|
|
42
|
-
const theorem = entry.theorem;
|
|
43
|
-
if (!theorem || typeof theorem !== 'object') {
|
|
44
|
-
throw new Error(`${setup.entry} exports no \`theorem\`. Export the TurnWiring your app runs its turns with: \`export const theorem: TurnWiring = { register, provider, prepare }\`.`);
|
|
45
|
-
}
|
|
46
|
-
return theorem;
|
|
47
|
-
}
|
|
48
20
|
/** The line this prints once it listens. `serve.ts` waits for it. */
|
|
49
21
|
export const PROJECT_READY = 'theorem-studio-project-ready';
|
|
50
22
|
if (import.meta.main) {
|
|
51
23
|
const [setupPath = '', ...flags] = Deno.args;
|
|
52
24
|
const flag = (name) => flags[flags.indexOf(`--${name}`) + 1] ?? '';
|
|
53
25
|
const port = Number(flag('port'));
|
|
54
|
-
const
|
|
55
|
-
const
|
|
26
|
+
const loaded = await loadSetup(setupPath);
|
|
27
|
+
const setup = loaded.setup;
|
|
28
|
+
const { theorem } = loaded;
|
|
56
29
|
await theorem.register?.();
|
|
57
30
|
const load = await new Response(Deno.stdin.readable).json();
|
|
58
31
|
let { questions, images } = setup;
|
package/transport.d.ts
CHANGED
|
@@ -8,13 +8,11 @@ import { type TurnEvent } from '@theoremjs/agents';
|
|
|
8
8
|
import { type ProfileInterface, type TranscriptBlock } from '@theoremjs/agents/interface';
|
|
9
9
|
import { type ChatLineSink, type ConversationLine, type DecisionTransport, type EmbeddingTransport, type HostTransport, type HttpOptions, type MalformedEvent, type TheoremTransport, type TraceFeed, type TurnEventSink, type UnsupportedEvent } from '@theoremjs/web/client';
|
|
10
10
|
import { z } from 'zod';
|
|
11
|
-
import {
|
|
11
|
+
import type { StudioRunPayload } from './run-payload.ts';
|
|
12
12
|
import type { StudioTraceLine } from './traces.ts';
|
|
13
13
|
export declare function studioInterface(payload: StudioRunPayload): ProfileInterface;
|
|
14
14
|
/** False for a run kept by a package whose settings this one no longer takes. */
|
|
15
15
|
export declare function studioRunDefines(payload: StudioRunPayload): boolean;
|
|
16
|
-
/** Clears every kept run this package no longer defines. */
|
|
17
|
-
export declare function clearStaleStudioRuns(store?: Storage | null): void;
|
|
18
16
|
/** The server picks the id, so a steer reaches only a run this browser started. */
|
|
19
17
|
export type StudioSteerLine = {
|
|
20
18
|
type: 'steer_inbox';
|
package/transport.js
CHANGED
|
@@ -10,7 +10,6 @@ import { createToolRegistry } from '@theoremjs/agents/kernel';
|
|
|
10
10
|
import { CHAT_LINES, createTraceFeed, decisionAssets, decisionInterface, embeddingInterface, fetchConversation, fetchRewound, fetchStarted, hostInterface, postDecision, postEmbedding, postJson, postNdjson, } from '@theoremjs/web/client';
|
|
11
11
|
import { z } from 'zod';
|
|
12
12
|
import { uncompiled } from "./compile.js";
|
|
13
|
-
import { clearStudioRunPayload, keptStudioRunIds, loadStudioRunPayload, } from "./run-payload.js";
|
|
14
13
|
import { registerStudioTools } from "./tools.js";
|
|
15
14
|
/**
|
|
16
15
|
* The agents the payload's agent names come first, so its agent tools find them. The patterns
|
|
@@ -43,14 +42,6 @@ export function studioRunDefines(payload) {
|
|
|
43
42
|
throw err;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
/** Clears every kept run this package no longer defines. */
|
|
47
|
-
export function clearStaleStudioRuns(store) {
|
|
48
|
-
for (const id of keptStudioRunIds(store)) {
|
|
49
|
-
const payload = loadStudioRunPayload(id, store);
|
|
50
|
-
if (!payload || !studioRunDefines(payload))
|
|
51
|
-
clearStudioRunPayload(id, store);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
45
|
/** A trace record's line on a run's stream, as the page reads it. */
|
|
55
46
|
export const studioTraceLine = z.object({ type: z.literal('trace'), record: traceRecordSchema });
|
|
56
47
|
true;
|
package/ui/inspector.js
CHANGED
|
@@ -22,7 +22,7 @@ import { Tooltip } from '@astryxdesign/core/Tooltip';
|
|
|
22
22
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
23
23
|
import { IconArrowBackUp, IconCheck, IconCode, IconCopy } from '@tabler/icons-react';
|
|
24
24
|
import { fieldMeta } from '@theoremjs/agents';
|
|
25
|
-
import { useContext } from 'react';
|
|
25
|
+
import { useContext, useState } from 'react';
|
|
26
26
|
import { originLabel, originPlace, originShortLabel, STUDIO_PROFILE_TYPES } from "../mod.js";
|
|
27
27
|
import { ISSUE_ROW_ATTRIBUTE, ListBadges, SaidOrigin, useFieldStatus, useRowOrigin, } from "./inspector-context.js";
|
|
28
28
|
import { tabFills } from "./lib/tab-fills.js";
|
|
@@ -146,11 +146,17 @@ function FillRow({ label, path, required, status, note, children, }) {
|
|
|
146
146
|
*/
|
|
147
147
|
export function TextRow(props) {
|
|
148
148
|
const { status: fieldStatus, required, unset, control } = useFieldRow(props);
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
const [cut, setCut] = useState(false);
|
|
150
|
+
const note = cut
|
|
151
|
+
? { type: 'warning', message: `Cut to ${props.maxLength} characters, the most it takes.` }
|
|
152
|
+
: undefined;
|
|
153
|
+
const status = props.status ?? fieldStatus ?? note;
|
|
154
|
+
return (_jsx(FillRow, { label: props.label, path: props.path, required: required, status: props.status ?? fieldStatus, note: note, children: _jsx(TextInput, { ...control, status: status, value: props.value, placeholder: props.placeholder ?? props.hint ?? unset, onKeyDown: tabFills(props.value, props.placeholder, props.onChange),
|
|
155
|
+
// why: TextInput takes no maxLength, so what is typed or pasted past it is cut here, and said.
|
|
152
156
|
onChange: (next) => {
|
|
153
|
-
|
|
157
|
+
const chars = Array.from(next);
|
|
158
|
+
setCut(props.maxLength !== undefined && chars.length > props.maxLength);
|
|
159
|
+
props.onChange(chars.slice(0, props.maxLength).join(''));
|
|
154
160
|
} }) }));
|
|
155
161
|
}
|
|
156
162
|
/**
|