@theoremjs/studio 0.3.4-next.757.gde44a4d → 0.3.4-next.759.g46e0e27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/compile.d.ts +3 -3
  2. package/compile.js +70 -101
  3. package/cookbooks/catalog.js +14 -28
  4. package/draft.d.ts +24 -28
  5. package/draft.js +11 -12
  6. package/guardrail-probe.js +1 -30
  7. package/mod.d.ts +2 -2
  8. package/mod.js +2 -2
  9. package/package.json +4 -4
  10. package/page/assets/{ConsoleFrame-D309UtSL.js → ConsoleFrame-IP80BbVy.js} +1 -1
  11. package/page/assets/{MenuBottomSheet-CVBLnUiO.js → MenuBottomSheet-B90IZU5_.js} +1 -1
  12. package/page/assets/{SchemaFields-muOTQM8x.js → SchemaFields-BBCNN0DQ.js} +1 -1
  13. package/page/assets/{ToolResultCharts-Bhesjbc4.js → ToolResultCharts-BA5C4s_d.js} +1 -1
  14. package/page/assets/{Toolbar-t4I6MDV_.js → Toolbar-cLeL30W1.js} +1 -1
  15. package/page/assets/{TraceInspector-BqEGN_46.js → TraceInspector-6xElMxMt.js} +1 -1
  16. package/page/assets/{TraceOverview-DLEqvRF2.js → TraceOverview-BgjbNvh5.js} +1 -1
  17. package/page/assets/{_virtual_studio-type-sources-Cc4WAdgD.js → _virtual_studio-type-sources-_88V0ngH.js} +37 -44
  18. package/page/assets/browser-connection-C1_PJcSQ.js +1 -0
  19. package/page/assets/browser-engine-VzmlJFEv.js +16 -0
  20. package/page/assets/browser-transport-JN5LOARG.js +45 -0
  21. package/page/assets/compile-BJuLB_as.js +2 -0
  22. package/page/assets/{encode-files-CeZxxjYd.js → encode-files-CCet4LKE.js} +1 -1
  23. package/page/assets/{export-agent-CYZqQ4ll.js → export-agent-BzdhT7lw.js} +8 -8
  24. package/page/assets/{guardrail-tester-D-_i4Zuj.js → guardrail-tester-M-A7EKhq.js} +1 -1
  25. package/page/assets/index-BHZr7HfC.js +149 -0
  26. package/page/assets/index-BYDlXF8Q.css +1 -0
  27. package/page/assets/live-messages-tG47aB12.js +1 -0
  28. package/page/assets/{prompt-row-CIxkqX9Q.js → prompt-row-BUe2Ni0Y.js} +2 -2
  29. package/page/assets/reader-SzTjS7rw.js +5 -0
  30. package/page/assets/{registry-DP0ArymS.js → registry-BrmnEhgs.js} +1 -1
  31. package/page/assets/schema-BztznKB7.js +3 -0
  32. package/page/assets/{shaped-data-DCfLI4gb.js → shaped-data-D15FDUcH.js} +3 -3
  33. package/page/assets/{stub-REBz-ZC7.js → stub-CJG-5zBe.js} +1 -1
  34. package/page/assets/studio-code-pane-k8fWxZOU.js +10 -0
  35. package/page/assets/{studio-console-DHgwXKne.js → studio-console-BANFk07G.js} +1 -1
  36. package/page/assets/{studio-decision-B_EdxnvG.js → studio-decision-DFj8AA2c.js} +1 -1
  37. package/page/assets/{studio-embedding-mZIx4qHD.js → studio-embedding-CZy7UHg8.js} +1 -1
  38. package/page/assets/{studio-host-console-BmB0sSsX.js → studio-host-console-CRxuC6E-.js} +2 -2
  39. package/page/assets/{studio-labels-BRouZt4M.js → studio-labels-3Sq86Mzp.js} +1 -1
  40. package/page/assets/studio-live-BcOCiV63.js +5 -0
  41. package/page/assets/{studio-map-8aIk_pdY.js → studio-map-CCtcfniD.js} +1 -1
  42. package/page/assets/{studio-trace-replay-BaF2UAqT.js → studio-trace-replay-C5t6OfXY.js} +1 -1
  43. package/page/assets/{studio-type-checker-JZuu4iVI.js → studio-type-checker-o2Q6t4mP.js} +1 -1
  44. package/page/assets/{tool-schema-BwaPiLtT.js → tool-schema-D26IAEC3.js} +1 -1
  45. package/page/assets/trace-record-jocyYEPa.js +1 -0
  46. package/page/assets/tree-B0fXPCwG.js +3 -0
  47. package/page/assets/{turn-client-B3jV7UKH.js → turn-client-eM8VIbMd.js} +1 -1
  48. package/page/assets/{types-BDx4pnrt.js → types-CfC3vRXO.js} +1 -1
  49. package/page/assets/{use-one-call-BKLi6fk_.js → use-one-call-Drfw4kwV.js} +1 -1
  50. package/page/assets/{workspace-B6d08n7C.js → workspace-BlOYHATA.js} +1 -1
  51. package/page/index.html +17 -17
  52. package/prompt-doc.d.ts +1 -1
  53. package/prompt-doc.js +2 -2
  54. package/read-source.js +26 -39
  55. package/section-notes.d.ts +1 -2
  56. package/section-notes.js +1 -2
  57. package/system-markup.d.ts +1 -1
  58. package/system-markup.js +1 -1
  59. package/ui/lib/export-agent.js +9 -26
  60. package/ui/lib/studio-page.d.ts +9 -16
  61. package/ui/lib/studio-page.js +28 -38
  62. package/ui/profile-editor.js +46 -93
  63. package/ui/prompt-editor.d.ts +1 -1
  64. package/ui/prompt-editor.js +11 -11
  65. package/ui/prompt-line-node.d.ts +5 -5
  66. package/ui/prompt-line-node.js +9 -9
  67. package/ui/prompt-row.d.ts +3 -3
  68. package/ui/prompt-row.js +3 -3
  69. package/ui/studio-compare.d.ts +4 -2
  70. package/ui/studio-compare.js +6 -5
  71. package/ui/studio-live.d.ts +1 -1
  72. package/ui/studio-live.js +2 -2
  73. package/ui/studio-runner.d.ts +4 -3
  74. package/ui/studio-runner.js +9 -9
  75. package/ui/studio-screen.js +5 -2
  76. package/ui/studio.css +3 -3
  77. package/page/assets/browser-connection-159CdeHX.js +0 -1
  78. package/page/assets/browser-engine-Fi7MROTb.js +0 -16
  79. package/page/assets/browser-transport-C_sHZVPa.js +0 -45
  80. package/page/assets/compile-iB2CAmRL.js +0 -2
  81. package/page/assets/index-DakRjE8R.css +0 -1
  82. package/page/assets/index-DuTrjzLN.js +0 -149
  83. package/page/assets/live-messages-D-SPyR3e.js +0 -1
  84. package/page/assets/reader-DtOL_I1x.js +0 -5
  85. package/page/assets/schema-Cv4HAfBT.js +0 -3
  86. package/page/assets/studio-code-pane-DEBuOivy.js +0 -10
  87. package/page/assets/studio-live-Cy09vyLv.js +0 -5
  88. package/page/assets/trace-record--uEnDt_D.js +0 -1
  89. package/page/assets/tree-CL4ETBd5.js +0 -3
  90. package/slot-values.d.ts +0 -2
  91. package/slot-values.js +0 -22
@@ -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-CL4ETBd5.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 T(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 ne(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 K(C({v:5,agents:[n],toolSpecs:e.toolSpecs,providers:e.providers,selected:h(n.key,t),chatWith:n.key,starts:{agents:{},tools:{},providers:{}}}))}function re(e,t){let n=e.agents.find(e=>e.key===t);return n&&{..._(n,[],e.providers),toolSpecs:e.toolSpecs}}function ie(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 ae(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 D(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 O(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 k(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 A(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 j=(e,t)=>e===t||N(e)===N(t),M=new WeakMap;function N(e){if(typeof e!=`object`||!e)return d(e);let t=M.get(e);if(t!==void 0)return t;let n=d(e);return M.set(e,n),n}var P=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function oe(e){let{agents:t,tools:n,providers:r}=e.starts;return e.agents.every(e=>j(e,t[e.key]))&&e.toolSpecs.every(e=>j(e,n[e.key]))&&e.providers.every(e=>j(e,r[e.id]))&&Object.keys(n).length===e.toolSpecs.length}function se(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 ce(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 F(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=ce(r,d&&e(d,f,e=>`${d}_${e}`),u,a);if(c.length===0&&j(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 le(e,t,n){if(n.facet===`identity`)return F(e,t);if(n.facet===`toolSpec`)return X(e,n.key);let r=F(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=ue(a,i,n);return j(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 ue(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:de(e,t,n.facet)}function de(e,t,n){return{...e,[n]:t[n]}}function I(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 L(e,t){let n=I(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=>j(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 R(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 z(e,t){return R(e)!==t}var B=`(agent|line|model|tool|question|criterion|reference)-[0-9a-f]{8}`,V=RegExp(`^${B}$`);function H(e){let t=new Map;return JSON.stringify(e).replace(RegExp(`\\b${B}\\b`,`g`),e=>(t.has(e)||t.set(e,`#${t.size}`),t.get(e)??e))}function fe(e,t){let n=t.map(H),r=new Set,i=[],a=[];for(let o of e){let e=H(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&&H(i(l))===H(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 me(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 fe(e,t))i(n,r);else if(P(e)&&P(t))for(let[n,a]of Object.entries(e)){let e=t[n];n===`key`?typeof a==`string`&&typeof e==`string`&&a!==e&&V.test(a)&&V.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=>P(e)&&typeof e.key==`string`);function G(e,t,n,r,i){if(j(e,n)||j(t,n))return t;if(P(e)&&P(t)&&P(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)):j(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?j(e,t)||i.conflict([...r,l++],void 0,e):(i.updated([...r,s.length]),s.push(e),l+=1)}return s}if(j(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 j(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 he(e,t,n){let r=me(pe(I(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})})):j(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 H(r)===H(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: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(!P(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={...P(e)?e:{}},o=Y(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function ge(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(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]=[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 j(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||j(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=>w(e).filter(e=>e===t).length);return{models:n.reduce((e,t)=>e+t,0),agents:n.filter(e=>e>0).length}}function _e(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 ve(t,n){return{id:e(`provider`,t,e=>`provider_${e}`),definition:n,connection:{}}}function ye(e,t){return e.providers.some(e=>e.id===t.id)?e:C({...e,providers:[...e.providers,t],selected:o(t.id)})}function be(e,t){return!e.providers.some(e=>e.id===t)||Q(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 xe(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 Se(e){return e.providers.flatMap(t=>{let n=e.starts.providers[t.id];return n&&j(n,t)?[t.id]:[]})}function Ce(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 we(e,n){return $(e.key,t(_(e,[],n)))}function Te(e){return{agents:e.agents.map(t=>we(t,e.providers)),tools:n(e.toolSpecs)}}export{ge as A,le as C,k as D,h as E,Te as F,d as I,Z as M,E as N,se as O,g as P,F as S,Ce as T,O as _,oe as a,xe as b,R as c,he as d,_e as f,L as g,Se as h,p as i,ie as j,ne as k,re as l,Q as m,ye as n,D as o,ve as p,ee as r,z as s,ae as t,T as u,A as v,X as w,I as x,be 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-B0fXPCwG.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 T(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 ne(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 K(C({v:5,agents:[n],toolSpecs:e.toolSpecs,providers:e.providers,selected:h(n.key,t),chatWith:n.key,starts:{agents:{},tools:{},providers:{}}}))}function re(e,t){let n=e.agents.find(e=>e.key===t);return n&&{..._(n,[],e.providers),toolSpecs:e.toolSpecs}}function ie(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 ae(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 D(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 O(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 k(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 A(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 j=(e,t)=>e===t||N(e)===N(t),M=new WeakMap;function N(e){if(typeof e!=`object`||!e)return d(e);let t=M.get(e);if(t!==void 0)return t;let n=d(e);return M.set(e,n),n}var P=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function oe(e){let{agents:t,tools:n,providers:r}=e.starts;return e.agents.every(e=>j(e,t[e.key]))&&e.toolSpecs.every(e=>j(e,n[e.key]))&&e.providers.every(e=>j(e,r[e.id]))&&Object.keys(n).length===e.toolSpecs.length}function se(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 ce(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 F(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=ce(r,d&&e(d,f,e=>`${d}_${e}`),u,a);if(c.length===0&&j(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 le(e,t,n){if(n.facet===`identity`)return F(e,t);if(n.facet===`toolSpec`)return X(e,n.key);let r=F(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=ue(a,i,n);return j(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 ue(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:de(e,t,n.facet)}function de(e,t,n){return{...e,[n]:t[n]}}function I(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 L(e,t){let n=I(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=>j(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 R(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 z(e,t){return R(e)!==t}var B=`(agent|line|model|tool|question|criterion|reference)-[0-9a-f]{8}`,V=RegExp(`^${B}$`);function H(e){let t=new Map;return JSON.stringify(e).replace(RegExp(`\\b${B}\\b`,`g`),e=>(t.has(e)||t.set(e,`#${t.size}`),t.get(e)??e))}function fe(e,t){let n=t.map(H),r=new Set,i=[],a=[];for(let o of e){let e=H(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&&H(i(l))===H(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 me(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 fe(e,t))i(n,r);else if(P(e)&&P(t))for(let[n,a]of Object.entries(e)){let e=t[n];n===`key`?typeof a==`string`&&typeof e==`string`&&a!==e&&V.test(a)&&V.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=>P(e)&&typeof e.key==`string`);function G(e,t,n,r,i){if(j(e,n)||j(t,n))return t;if(P(e)&&P(t)&&P(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)):j(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?j(e,t)||i.conflict([...r,l++],void 0,e):(i.updated([...r,s.length]),s.push(e),l+=1)}return s}if(j(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 j(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 he(e,t,n){let r=me(pe(I(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})})):j(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 H(r)===H(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: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(!P(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={...P(e)?e:{}},o=Y(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function ge(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(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]=[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 j(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||j(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=>w(e).filter(e=>e===t).length);return{models:n.reduce((e,t)=>e+t,0),agents:n.filter(e=>e>0).length}}function _e(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 ve(t,n){return{id:e(`provider`,t,e=>`provider_${e}`),definition:n,connection:{}}}function ye(e,t){return e.providers.some(e=>e.id===t.id)?e:C({...e,providers:[...e.providers,t],selected:o(t.id)})}function be(e,t){return!e.providers.some(e=>e.id===t)||Q(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 xe(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 Se(e){return e.providers.flatMap(t=>{let n=e.starts.providers[t.id];return n&&j(n,t)?[t.id]:[]})}function Ce(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 we(e,n){return $(e.key,t(_(e,[],n)))}function Te(e){return{agents:e.agents.map(t=>we(t,e.providers)),tools:n(e.toolSpecs)}}export{ge as A,le as C,k as D,h as E,Te as F,d as I,Z as M,E as N,se as O,g as P,F as S,Ce as T,O as _,oe as a,xe as b,R as c,he as d,_e as f,L as g,Se as h,p as i,ie as j,ne as k,re as l,Q as m,ye as n,D as o,ve as p,ee as r,z as s,ae as t,T as u,A as v,X as w,I as x,be 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-DuTrjzLN.js"></script>
13
+ <script type="module" crossorigin src="/studio/assets/index-BHZr7HfC.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-BpCwr7Mf.js">
@@ -47,23 +47,23 @@
47
47
  <link rel="modulepreload" crossorigin href="/studio/assets/IconAlertTriangle-BqAEqqdU.js">
48
48
  <link rel="modulepreload" crossorigin href="/studio/assets/schemas-D7cgkv3L.js">
49
49
  <link rel="modulepreload" crossorigin href="/studio/assets/host-patterns-F-KZIzkF.js">
50
- <link rel="modulepreload" crossorigin href="/studio/assets/shaped-data-DCfLI4gb.js">
51
- <link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-BwaPiLtT.js">
50
+ <link rel="modulepreload" crossorigin href="/studio/assets/shaped-data-D15FDUcH.js">
51
+ <link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-D26IAEC3.js">
52
52
  <link rel="modulepreload" crossorigin href="/studio/assets/live-ingress-OuSlQ6q7.js">
53
- <link rel="modulepreload" crossorigin href="/studio/assets/tree-CL4ETBd5.js">
54
- <link rel="modulepreload" crossorigin href="/studio/assets/schema-Cv4HAfBT.js">
55
- <link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-159CdeHX.js">
56
- <link rel="modulepreload" crossorigin href="/studio/assets/types-BDx4pnrt.js">
57
- <link rel="modulepreload" crossorigin href="/studio/assets/compile-iB2CAmRL.js">
53
+ <link rel="modulepreload" crossorigin href="/studio/assets/tree-B0fXPCwG.js">
54
+ <link rel="modulepreload" crossorigin href="/studio/assets/schema-BztznKB7.js">
55
+ <link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-C1_PJcSQ.js">
56
+ <link rel="modulepreload" crossorigin href="/studio/assets/types-CfC3vRXO.js">
57
+ <link rel="modulepreload" crossorigin href="/studio/assets/compile-BJuLB_as.js">
58
58
  <link rel="modulepreload" crossorigin href="/studio/assets/row-keys-WByP9Hsh.js">
59
59
  <link rel="modulepreload" crossorigin href="/studio/assets/Center-CgO0c-qo.js">
60
60
  <link rel="modulepreload" crossorigin href="/studio/assets/IconFilter-BO98ezum.js">
61
61
  <link rel="modulepreload" crossorigin href="/studio/assets/IconSearch-BTx66a40.js">
62
62
  <link rel="modulepreload" crossorigin href="/studio/assets/trace-schema--4IGmLeE.js">
63
- <link rel="modulepreload" crossorigin href="/studio/assets/stub-REBz-ZC7.js">
64
- <link rel="modulepreload" crossorigin href="/studio/assets/reader-DtOL_I1x.js">
65
- <link rel="modulepreload" crossorigin href="/studio/assets/registry-DP0ArymS.js">
66
- <link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-C_sHZVPa.js">
63
+ <link rel="modulepreload" crossorigin href="/studio/assets/stub-CJG-5zBe.js">
64
+ <link rel="modulepreload" crossorigin href="/studio/assets/reader-SzTjS7rw.js">
65
+ <link rel="modulepreload" crossorigin href="/studio/assets/registry-BrmnEhgs.js">
66
+ <link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-JN5LOARG.js">
67
67
  <link rel="modulepreload" crossorigin href="/studio/assets/focusReturn-CTppP2k0.js">
68
68
  <link rel="modulepreload" crossorigin href="/studio/assets/isRenderable-DHkzpAoQ.js">
69
69
  <link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-Dc-AJqPH.js">
@@ -77,12 +77,12 @@
77
77
  <link rel="modulepreload" crossorigin href="/studio/assets/CodeBlock-DzXH_9DF.js">
78
78
  <link rel="modulepreload" crossorigin href="/studio/assets/HoverCard-DMHc1Gh1.js">
79
79
  <link rel="modulepreload" crossorigin href="/studio/assets/TextInput-D1GkClqk.js">
80
- <link rel="modulepreload" crossorigin href="/studio/assets/encode-files-CeZxxjYd.js">
81
- <link rel="modulepreload" crossorigin href="/studio/assets/turn-client-B3jV7UKH.js">
80
+ <link rel="modulepreload" crossorigin href="/studio/assets/encode-files-CCet4LKE.js">
81
+ <link rel="modulepreload" crossorigin href="/studio/assets/turn-client-eM8VIbMd.js">
82
82
  <link rel="modulepreload" crossorigin href="/studio/assets/Badge-D78MvW22.js">
83
83
  <link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-D1qiJpkR.js">
84
- <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-BRouZt4M.js">
85
- <link rel="modulepreload" crossorigin href="/studio/assets/workspace-B6d08n7C.js">
84
+ <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-3Sq86Mzp.js">
85
+ <link rel="modulepreload" crossorigin href="/studio/assets/workspace-BlOYHATA.js">
86
86
  <link rel="modulepreload" crossorigin href="/studio/assets/lent-keys-C32ems-I.js">
87
87
  <link rel="modulepreload" crossorigin href="/studio/assets/editors-BJX_S59A.js">
88
88
  <link rel="modulepreload" crossorigin href="/studio/assets/project-address-DjxPZuyn.js">
@@ -99,7 +99,7 @@
99
99
  <link rel="modulepreload" crossorigin href="/studio/assets/ListItem-MWWVygeh.js">
100
100
  <link rel="modulepreload" crossorigin href="/studio/assets/MenuBottomSheetActionList-CYZ56fty.js">
101
101
  <link rel="stylesheet" crossorigin href="/studio/assets/use-second-ticker-GWBt83pd.css">
102
- <link rel="stylesheet" crossorigin href="/studio/assets/index-DakRjE8R.css">
102
+ <link rel="stylesheet" crossorigin href="/studio/assets/index-BYDlXF8Q.css">
103
103
  <style>html{color-scheme:dark}html,body{margin:0;background:#000}html[data-boot-pending],html[data-boot-pending] body{background:#262626}html[data-boot-pending] .astryx-app-shell{height:100dvh}html[data-boot-pending] .astryx-app-shell-sidenav{position:absolute;inset-block:0;inset-inline-start:0;z-index:0;width:3rem}html[data-boot-pending] #astryx-app-shell-main{position:relative;z-index:1;width:100%;height:100%;max-width:none;margin:0;border-radius:0;clip-path:none;background:#262626;color:#fff}html[data-boot-pending] #astryx-app-shell-main>:not([data-boot]){visibility:hidden}html[data-boot-pending] [data-boot]{position:absolute;inset:0;z-index:2;display:grid;place-items:center;background:#262626;color:#fff}</style>
104
104
  <noscript> <style>html[data-boot-pending],html[data-boot-pending] body{background:#000}html[data-boot-pending] #astryx-app-shell-main>:not([data-boot]){visibility:visible !important}[data-boot]{display:none !important}</style>
105
105
  </noscript>
package/prompt-doc.d.ts CHANGED
@@ -10,7 +10,7 @@ declare function openedDoc(text: string): string | undefined;
10
10
  declare function promptMarkup(json: string): string;
11
11
  /** A `when`'s checks, each as `name is value`. */
12
12
  declare const checksOf: (when: string | null) => string[];
13
- /** One condition holds one value; picking the value it already has takes it off. */
13
+ /** One `when` holds one value; picking the value it already has takes it off. */
14
14
  declare function withCheck(when: string | null, name: string, value: string): string | null;
15
15
  /** The `when` left once one check is off. */
16
16
  declare const withoutCheck: (when: string | null, check: string) => string | null;
package/prompt-doc.js CHANGED
@@ -87,7 +87,7 @@ function promptDoc(lines) {
87
87
  return JSON.stringify({ root: { ...shell, children: [EMPTY_LINE] } });
88
88
  const children = roots.flatMap(({ when, root }, at) => {
89
89
  const blocks = root.children ?? [];
90
- // why: lines side by side under one condition read as one stretch; `withWhen` writes it back.
90
+ // why: lines side by side under one `when` read as one stretch; `withWhen` writes it back.
91
91
  const continues = when !== null && roots[at - 1]?.when === when;
92
92
  return continues ? blocks : [{ type: PROMPT_LINE, version: 1, when }, ...blocks];
93
93
  });
@@ -215,7 +215,7 @@ function settledLine(line) {
215
215
  }
216
216
  /** A `when`'s checks, each as `name is value`. */
217
217
  const checksOf = (when) => (when ? when.split(' and ') : []);
218
- /** One condition holds one value; picking the value it already has takes it off. */
218
+ /** One `when` holds one value; picking the value it already has takes it off. */
219
219
  function withCheck(when, name, value) {
220
220
  const check = `${name} is ${value}`;
221
221
  const had = checksOf(when);
package/read-source.js CHANGED
@@ -590,20 +590,27 @@ function promptText(value) {
590
590
  }
591
591
  return texts.join('\n\n');
592
592
  }
593
- /** Conditions as the draft holds them: a row each, keeping the row of a name it already has. */
594
- function conditionRows(value, current) {
595
- if (value === undefined)
596
- return [];
597
- const srcMessage = 'Conditions have to be lists of values.';
598
- if (!isRecord(value))
599
- throw new ReadFail(srcMessage, 1, 1);
600
- return Object.entries(value).map(([name, values]) => {
601
- if (!Array.isArray(values))
602
- throw new ReadFail(srcMessage, 1, 1);
593
+ /** A file's options as rows, each keeping the key the row of its name had. */
594
+ function optionRows(value, isShownInChat, current) {
595
+ const byName = new Map(current.map((option) => [option.name, option]));
596
+ return Object.entries(record(value) ?? {}).map(([name, decl]) => {
597
+ const previous = byName.get(name);
598
+ const option = record(decl);
599
+ const entries = Array.isArray(option?.choices) ? option.choices : [];
600
+ const choices = entries.map((entry, index) => {
601
+ const choice = record(entry);
602
+ return {
603
+ key: previous?.choices[index]?.key ?? draftKey('choice'),
604
+ value: text(choice?.value),
605
+ description: text(choice?.description),
606
+ };
607
+ });
603
608
  return {
604
- key: current.find((row) => row.name === name)?.key ?? draftKey('condition'),
609
+ key: previous?.key ?? draftKey('option'),
605
610
  name,
606
- values: values.map((each) => text(each)),
611
+ label: text(option?.label),
612
+ isShownInChat,
613
+ choices,
607
614
  };
608
615
  });
609
616
  }
@@ -1036,7 +1043,10 @@ function identityOf(current, profile, type) {
1036
1043
  profileType: type,
1037
1044
  handle: text(identity.handle),
1038
1045
  system: promptText(identity.system),
1039
- conditions: conditionRows(identity.conditions, current.conditions),
1046
+ options: [
1047
+ ...optionRows(identity.options, false, current.options),
1048
+ ...optionRows(record(profile.inputs)?.options, true, current.options),
1049
+ ],
1040
1050
  };
1041
1051
  }
1042
1052
  function modelsOf(profile) {
@@ -1060,29 +1070,7 @@ function isContextSender(value) {
1060
1070
  function limitsByMimeOf(value) {
1061
1071
  return Object.fromEntries(Object.entries(record(value) ?? {}).filter((entry) => typeof entry[1] === 'number'));
1062
1072
  }
1063
- /** A file's slots as rows, each keeping the key the slot of its name had. */
1064
- function slotsOf(value, current) {
1065
- const byName = new Map(current.map((slot) => [slot.name, slot]));
1066
- return Object.entries(record(value) ?? {}).map(([name, decl]) => {
1067
- const previous = byName.get(name);
1068
- const rich = record(decl);
1069
- const entries = Array.isArray(decl)
1070
- ? decl
1071
- : Array.isArray(rich?.choices)
1072
- ? rich.choices
1073
- : [];
1074
- const choices = entries.map((entry, index) => {
1075
- const choice = record(entry);
1076
- return {
1077
- key: previous?.choices[index]?.key ?? draftKey('choice'),
1078
- value: choice ? text(choice.value) : text(entry),
1079
- description: text(choice?.description),
1080
- };
1081
- });
1082
- return { key: previous?.key ?? draftKey('slot'), name, label: text(rich?.label), choices };
1083
- });
1084
- }
1085
- function inputsOf(inputs, current) {
1073
+ function inputsOf(inputs) {
1086
1074
  const context = record(inputs.context);
1087
1075
  return {
1088
1076
  text: inputs.text !== false,
@@ -1092,7 +1080,6 @@ function inputsOf(inputs, current) {
1092
1080
  maxBytes: whole(inputs.maxBytes),
1093
1081
  maxTurnBytes: whole(inputs.maxTurnBytes),
1094
1082
  limitsByMime: limitsByMimeOf(inputs.limitsByMime),
1095
- slots: slotsOf(inputs.slots, current.slots),
1096
1083
  contextFrom: strings(context?.from).filter(isContextSender),
1097
1084
  contextMaxChars: whole(context?.maxChars),
1098
1085
  };
@@ -1120,7 +1107,7 @@ function outputsOf(outputs, structures) {
1120
1107
  mode: schemaId ? 'structured' : 'text',
1121
1108
  schemaId,
1122
1109
  schemaJson: jsonText(structured?.spec.jsonSchema),
1123
- ...(picks ? { bySlot: { slot: text(picks.by), shapes } } : {}),
1110
+ ...(picks ? { byOption: { option: text(picks.by), shapes } } : {}),
1124
1111
  streamMode: text(streaming?.mode),
1125
1112
  streamThoughts: streaming?.streamThoughts !== false,
1126
1113
  validationEnabled: validation !== undefined,
@@ -1270,7 +1257,7 @@ function draftFrom(parsed, current, agentKeyOf) {
1270
1257
  modelBindings: Object.entries(record(profile.models) ?? {}).map(([modelId, spec]) => bindingOf(modelId, spec, byModelId.get(modelId), agentKeyOf, parsed.spans)),
1271
1258
  tools: { t2Loader: text(tools.t2Loader), parallel: tools.parallel === true },
1272
1259
  toolSpecs: [],
1273
- inputs: inputs && type !== 'decision' ? inputsOf(inputs, current.inputs) : current.inputs,
1260
+ inputs: inputs && type !== 'decision' ? inputsOf(inputs) : current.inputs,
1274
1261
  outputs: outputs || parsed.structures.length ? outputsOf(outputs, parsed.structures) : current.outputs,
1275
1262
  turnBehaviour: section(profile.turnBehaviour, turnOf, current.turnBehaviour),
1276
1263
  guardrails: section(profile.guardrails, guardrailsOf, current.guardrails),
@@ -1,7 +1,7 @@
1
1
  /** What a section's title says on hover, where no one catalog field describes the section. */
2
2
  declare const SECTION_HINTS: {
3
3
  readonly profile: "What this profile is called, and what kind it is.";
4
- readonly system: "What the model is told, and the conditions that decide which lines go out.";
4
+ readonly system: "What the model is told, and the options that decide which lines go out.";
5
5
  readonly modelPolicy: "Which model runs by default, and whether it can be switched.";
6
6
  readonly generation: "How this model writes its reply.";
7
7
  readonly limits: "What a message may carry.";
@@ -22,7 +22,6 @@ declare const SECTION_NOTES: {
22
22
  readonly models: "Add a model here, then select its binding in the tree to configure it.";
23
23
  readonly 'models.decision': "A decision uses one model. Select its binding in the tree to configure it.";
24
24
  readonly decisionModel: "This binding answers the questions configured under Decision.";
25
- readonly slots: "Each slot's picker sets what the preview sends. It is not saved in the profile.";
26
25
  readonly context: "Preview is what the studio sends as the page. It is not saved in the profile.";
27
26
  readonly compaction: "The studio's chat compacts only before a turn.";
28
27
  readonly quota: "Studio runs are not counted.";
package/section-notes.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /** What a section's title says on hover, where no one catalog field describes the section. */
2
2
  const SECTION_HINTS = {
3
3
  profile: 'What this profile is called, and what kind it is.',
4
- system: 'What the model is told, and the conditions that decide which lines go out.',
4
+ system: 'What the model is told, and the options that decide which lines go out.',
5
5
  modelPolicy: 'Which model runs by default, and whether it can be switched.',
6
6
  generation: 'How this model writes its reply.',
7
7
  limits: 'What a message may carry.',
@@ -22,7 +22,6 @@ const SECTION_NOTES = {
22
22
  models: 'Add a model here, then select its binding in the tree to configure it.',
23
23
  'models.decision': 'A decision uses one model. Select its binding in the tree to configure it.',
24
24
  decisionModel: 'This binding answers the questions configured under Decision.',
25
- slots: "Each slot's picker sets what the preview sends. It is not saved in the profile.",
26
25
  context: 'Preview is what the studio sends as the page. It is not saved in the profile.',
27
26
  compaction: "The studio's chat compacts only before a turn.",
28
27
  quota: 'Studio runs are not counted.',
@@ -22,7 +22,7 @@ declare function parseSystemMarkup(text: string): SystemMarkup;
22
22
  /**
23
23
  * A plain line as the kernel sends it once the studio opens it: each stretch between blank lines
24
24
  * is a line of its own, with a blank line between them either way.
25
- * invariant: A text with a `when` stretch stays whole, since opening it would make that stretch a condition.
25
+ * invariant: A text with a `when` stretch stays whole, since opening it would put that stretch under a `when`.
26
26
  */
27
27
  declare function plainLines(line: string): string[];
28
28
  export type { SystemMarkup };
package/system-markup.js CHANGED
@@ -71,7 +71,7 @@ function parseSystemMarkup(text) {
71
71
  /**
72
72
  * A plain line as the kernel sends it once the studio opens it: each stretch between blank lines
73
73
  * is a line of its own, with a blank line between them either way.
74
- * invariant: A text with a `when` stretch stays whole, since opening it would make that stretch a condition.
74
+ * invariant: A text with a `when` stretch stays whole, since opening it would put that stretch under a `when`.
75
75
  */
76
76
  function plainLines(line) {
77
77
  const lines = line.trim().split(BLANK_LINE);
@@ -94,30 +94,13 @@ function browserFile(path, name, component, endpoint, what, props = []) {
94
94
  ].join('\n')}\n`,
95
95
  };
96
96
  }
97
- /** Allowed value strings from a slot declaration (legacy list or `{ choices }`). */
98
- function slotChoiceValues(decl) {
99
- if (Array.isArray(decl)) {
100
- return decl.filter((value) => typeof value === 'string');
101
- }
102
- if (!decl || typeof decl !== 'object' || Array.isArray(decl))
103
- return [];
104
- const choices = decl.choices;
105
- if (!Array.isArray(choices))
106
- return [];
107
- return choices.flatMap((choice) => {
108
- if (!choice || typeof choice !== 'object' || Array.isArray(choice))
109
- return [];
110
- const value = choice.value;
111
- return typeof value === 'string' ? [value] : [];
112
- });
113
- }
114
- /** What the agent takes from its page and its server: `inputs.slots` and `inputs.context`. */
97
+ /** What the agent takes from its page and its server: `inputs.options` and `inputs.context`. */
115
98
  function pageInputs({ profile }) {
116
99
  const inputs = 'inputs' in profile ? profile.inputs : undefined;
117
- const raw = inputs && 'slots' in inputs ? (inputs.slots ?? {}) : {};
118
- const slots = Object.entries(raw).map(([name, decl]) => [name, slotChoiceValues(decl)]);
100
+ const declared = inputs && 'options' in inputs ? (inputs.options ?? {}) : {};
101
+ const options = Object.entries(declared).map(([name, decl]) => [name, decl.choices.map(({ value }) => value)]);
119
102
  const context = inputs && 'context' in inputs ? inputs.context : undefined;
120
- return { slots, from: context?.from ?? [] };
103
+ return { options, from: context?.from ?? [] };
121
104
  }
122
105
  /** The chat's prop for the tools this page answers: a function per tool, returning its output. */
123
106
  function pageToolsProp(agent) {
@@ -131,13 +114,13 @@ function pageToolsProp(agent) {
131
114
  '}}',
132
115
  ];
133
116
  }
134
- /** The chat's props for what the page supplies: a value per slot, and its context. */
117
+ /** The chat's props for what the page supplies: a value per option, and its context. */
135
118
  function pageProps(agent) {
136
- const { slots, from } = pageInputs(agent);
137
- const picked = slots.map(([name, allowed]) => `${JSON.stringify(name)}: ${JSON.stringify(allowed.at(0) ?? '')}`);
119
+ const { options, from } = pageInputs(agent);
120
+ const picked = options.map(([name, allowed]) => `${JSON.stringify(name)}: ${JSON.stringify(allowed.at(0) ?? '')}`);
138
121
  return [
139
- ...slots.map(([name, allowed]) => `// ${name}: ${allowed.join(' | ')}`),
140
- ...(slots.length > 0 ? [`slots={{ ${picked.join(', ')} }}`] : []),
122
+ ...options.map(([name, allowed]) => `// ${name}: ${allowed.join(' | ')}`),
123
+ ...(options.length > 0 ? [`options={{ ${picked.join(', ')} }}`] : []),
141
124
  ...(from.includes('client')
142
125
  ? ['// What this page tells the agent: any JSON.', 'context={{}}']
143
126
  : []),
@@ -1,40 +1,33 @@
1
1
  /**
2
- * What the studio's page sends an agent: a value for each of its slots and its context
2
+ * What the studio's page sends an agent: a value for each of its options and its context
3
3
  * package. Kept in this tab beside the conversation, never in the profile.
4
4
  */
5
5
  import type { StatedTurn } from '@theoremjs/web/client';
6
- import { type SlotDraft, type StudioRunPayload } from '../../mod.ts';
7
- /** What the builder set: the value picked for each slot and condition, and the context as typed. */
6
+ import { type StudioRunPayload } from '../../mod.ts';
7
+ /** What the builder set: the value picked for each option, and the context as typed. */
8
8
  export interface PageValues {
9
- slots: Record<string, string>;
10
- conditions: Record<string, string>;
9
+ options: Record<string, string>;
11
10
  contextJson: string;
12
11
  }
13
12
  /** What the agent takes from a page. */
14
13
  export interface PageInputs {
15
- /** Allowed values per slot name (descriptions stay on the profile / chat UI). */
16
- slots: Record<string, readonly string[]>;
17
- /** Allowed values per condition name: which prompt lines the turn gets. */
18
- conditions: Record<string, readonly string[]>;
14
+ /** The options a person picks, by name, with their values. */
15
+ person: Record<string, readonly string[]>;
16
+ /** The options the host's code states, by name, with their values. */
17
+ code: Record<string, readonly string[]>;
19
18
  takesContext: boolean;
20
19
  /** The tools the page answers. Only a call asks the page. */
21
20
  pageTools: string[];
22
21
  }
23
22
  /** The context a blank preview box suggests. */
24
23
  export declare const CONTEXT_PLACEHOLDER = "{\n \"page\": \"Checkout\"\n}";
25
- /** The slots a draft has so far that a page can pick from: each named, with a value, once. */
26
- export declare function draftSlots(slots: readonly SlotDraft[]): {
27
- name: string;
28
- label: string;
29
- values: string[];
30
- }[];
31
24
  /** Why typed context is not sent, when it is not JSON. */
32
25
  export declare function contextErrorOf(contextJson: string): string | undefined;
33
26
  /** What the compiled agent takes from a page, or null when it takes nothing. */
34
27
  export declare function pageInputsOf(payload: StudioRunPayload): PageInputs | null;
35
28
  /** What goes with a turn or a call. Context that is not JSON is not sent, and says why. */
36
29
  export declare function sentPageValues(inputs: PageInputs | null, values: PageValues): {
37
- slots?: Record<string, string>;
30
+ options?: Record<string, string>;
38
31
  stated?: StatedTurn;
39
32
  context?: unknown;
40
33
  contextError?: string;
@@ -1,28 +1,22 @@
1
1
  /**
2
- * What the studio's page sends an agent: a value for each of its slots and its context
2
+ * What the studio's page sends an agent: a value for each of its options and its context
3
3
  * package. Kept in this tab beside the conversation, never in the profile.
4
4
  */
5
5
  import { useCallback, useSyncExternalStore } from 'react';
6
6
  import { studioPageTools } from "../../mod.js";
7
- import { choiceValues } from "../../slot-values.js";
8
7
  import { isRecord, session } from "./studio-session.js";
9
8
  const PAGE_PREFIX = 'theorem.studio.v2.page:';
10
- const NO_PAGE_VALUES = { slots: {}, conditions: {}, contextJson: '' };
9
+ const NO_PAGE_VALUES = { options: {}, contextJson: '' };
11
10
  /** The context a blank preview box suggests. */
12
11
  export const CONTEXT_PLACEHOLDER = `{
13
12
  "page": "Checkout"
14
13
  }`;
15
- /** The slots a draft has so far that a page can pick from: each named, with a value, once. */
16
- export function draftSlots(slots) {
17
- const seen = new Set();
18
- return slots.flatMap((slot) => {
19
- const name = slot.name.trim();
20
- const values = slot.choices.map((choice) => choice.value.trim()).filter(Boolean);
21
- if (!name || !values.length || seen.has(name))
22
- return [];
23
- seen.add(name);
24
- return [{ name, label: slot.label.trim() || name, values }];
25
- });
14
+ /** Each option's values, by name. */
15
+ function namedValues(options) {
16
+ return Object.fromEntries(Object.entries(options ?? {}).map(([name, decl]) => [
17
+ name,
18
+ decl.choices.map(({ value }) => value),
19
+ ]));
26
20
  }
27
21
  /** Why typed context is not sent, when it is not JSON. */
28
22
  export function contextErrorOf(contextJson) {
@@ -48,41 +42,40 @@ export function pageInputsOf(payload) {
48
42
  return null;
49
43
  }
50
44
  const inputs = 'inputs' in profile ? profile.inputs : undefined;
51
- const raw = inputs?.slots ?? {};
52
- const slots = Object.fromEntries(Object.entries(raw).flatMap(([name, decl]) => {
53
- const values = choiceValues(decl);
54
- return values ? [[name, values]] : [];
55
- }));
56
- const conditions = profile.identity.conditions ?? {};
45
+ const person = namedValues(inputs?.options);
46
+ const code = namedValues(profile.identity.options);
57
47
  const takesContext = inputs?.context?.from.includes('client') ?? false;
58
48
  const pageTools = Object.keys(studioPageTools(payload));
59
- const takesNothing = !Object.keys(slots).length && !Object.keys(conditions).length && !takesContext;
49
+ const takesNothing = !Object.keys(person).length && !Object.keys(code).length && !takesContext;
60
50
  if (takesNothing && !pageTools.length)
61
51
  return null;
62
- return { slots, conditions, takesContext, pageTools };
52
+ return { person, code, takesContext, pageTools };
63
53
  }
64
54
  /** The value a pick sends: the one picked while the profile still lists it, else its first. */
65
55
  function pickedValue(allowed, picked) {
66
56
  return allowed.find((value) => value === picked) ?? allowed.at(0) ?? '';
67
57
  }
68
- /** The turn's path and conditions as picked: the `path` condition is the turn's own path. */
58
+ /** Each option's pick. */
59
+ function picksOf(declared, values) {
60
+ return Object.fromEntries(Object.entries(declared).map(([name, allowed]) => [
61
+ name,
62
+ pickedValue(allowed, values.options[name]),
63
+ ]));
64
+ }
65
+ /** The turn's path and options as picked: the `path` option is the turn's own path. */
69
66
  function statedTurn(inputs, values) {
70
- const picks = Object.entries(inputs.conditions).map(([name, allowed]) => [name, pickedValue(allowed, values.conditions[name])]);
71
- if (!picks.length)
67
+ if (!Object.keys(inputs.code).length)
72
68
  return undefined;
73
- const { path, ...conditions } = Object.fromEntries(picks);
74
- return { ...(path === undefined ? {} : { path }), conditions };
69
+ const { path, ...options } = picksOf(inputs.code, values);
70
+ return { ...(path === undefined ? {} : { path }), options };
75
71
  }
76
72
  /** What goes with a turn or a call. Context that is not JSON is not sent, and says why. */
77
73
  export function sentPageValues(inputs, values) {
78
74
  if (!inputs)
79
75
  return {};
80
- const names = Object.keys(inputs.slots);
81
- const slots = names.length
82
- ? Object.fromEntries(names.map((name) => [name, pickedValue(inputs.slots[name] ?? [], values.slots[name])]))
83
- : undefined;
76
+ const options = Object.keys(inputs.person).length ? picksOf(inputs.person, values) : undefined;
84
77
  const stated = statedTurn(inputs, values);
85
- const sent = { slots, ...(stated ? { stated } : {}) };
78
+ const sent = { options, ...(stated ? { stated } : {}) };
86
79
  const typed = inputs.takesContext ? values.contextJson.trim() : '';
87
80
  if (!typed)
88
81
  return sent;
@@ -94,14 +87,11 @@ export function sentPageValues(inputs, values) {
94
87
  function loadPageValues(agentKey) {
95
88
  try {
96
89
  const kept = JSON.parse(session()?.getItem(`${PAGE_PREFIX}${agentKey}`) ?? 'null');
97
- if (!isRecord(kept) || !isRecord(kept.slots) || typeof kept.contextJson !== 'string') {
90
+ if (!isRecord(kept) || !isRecord(kept.options) || typeof kept.contextJson !== 'string') {
98
91
  return NO_PAGE_VALUES;
99
92
  }
100
- const slots = Object.fromEntries(Object.entries(kept.slots).filter((entry) => typeof entry[1] === 'string'));
101
- const conditions = isRecord(kept.conditions)
102
- ? Object.fromEntries(Object.entries(kept.conditions).filter((entry) => typeof entry[1] === 'string'))
103
- : {};
104
- return { slots, conditions, contextJson: kept.contextJson };
93
+ const options = Object.fromEntries(Object.entries(kept.options).filter((entry) => typeof entry[1] === 'string'));
94
+ return { options, contextJson: kept.contextJson };
105
95
  }
106
96
  catch {
107
97
  return NO_PAGE_VALUES;