@theoremjs/studio 0.3.4-next.677.g14b70fe → 0.3.4-next.693.g4ab1526

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 (141) hide show
  1. package/asks.d.ts +9 -2
  2. package/asks.js +19 -10
  3. package/browser-connection.d.ts +1 -1
  4. package/browser-connection.js +3 -1
  5. package/browser-execution.js +1 -0
  6. package/compile-workspace.js +12 -5
  7. package/compile.d.ts +4 -2
  8. package/compile.js +58 -37
  9. package/cookbooks/catalog.d.ts +2 -2
  10. package/cookbooks/catalog.js +300 -53
  11. package/cookbooks/project.js +1 -0
  12. package/cookbooks/tools.js +64 -0
  13. package/draft.d.ts +21 -5
  14. package/draft.js +25 -2
  15. package/guardrail-probe.d.ts +3 -1
  16. package/guardrail-probe.js +37 -5
  17. package/mod.d.ts +2 -2
  18. package/mod.js +2 -2
  19. package/package.json +4 -4
  20. package/page/assets/Banner-DrRNC3MG.js +4 -0
  21. package/page/assets/Center-CgO0c-qo.js +1 -0
  22. package/page/assets/{ConsoleFrame-BFCYCApu.js → ConsoleFrame-BvgFGqp2.js} +3 -3
  23. package/page/assets/{MenuBottomSheet-CezET_qZ.js → MenuBottomSheet-BZecY8fw.js} +1 -1
  24. package/page/assets/{SchemaFields-CIF3WtC0.js → SchemaFields-BNNkvyyO.js} +1 -1
  25. package/page/assets/{ToolResultCharts-D3pQGTH1.js → ToolResultCharts-C3CPsfXl.js} +1 -1
  26. package/page/assets/{TraceInspector-Bx3j_185.js → TraceInspector-36e6ozKD.js} +1 -1
  27. package/page/assets/{TraceOverview-ChpCMZRa.js → TraceOverview-CSdJ_cYY.js} +3 -3
  28. package/page/assets/{_virtual_studio-type-sources-BwSqfSwd.js → _virtual_studio-type-sources-DSpwr3WK.js} +143 -13
  29. package/page/assets/browser-connection-dads1eyK.js +3 -0
  30. package/page/assets/browser-engine-CugH58NS.js +13 -0
  31. package/page/assets/browser-transport-GzhRiBdm.js +45 -0
  32. package/page/assets/{crypto-CD14HeXH.js → crypto-B8dqEoWf.js} +1 -1
  33. package/page/assets/{encode-files-DhoC5hWG.js → encode-files-CHeRLBO8.js} +1 -1
  34. package/page/assets/{export-agent-nlvsxs9-.js → export-agent-botXSyoH.js} +3 -3
  35. package/page/assets/{guardrail-tester-C7r03f5Z.js → guardrail-tester-DYR7EPIy.js} +2 -2
  36. package/page/assets/index-B7sK7d-l.js +153 -0
  37. package/page/assets/live-messages-DN_q2nBN.js +1 -0
  38. package/page/assets/project-address-DjxPZuyn.js +1 -0
  39. package/page/assets/reader-DHN96tSr.js +5 -0
  40. package/page/assets/{schemas-BQ9Jydzb.js → schemas-D7cgkv3L.js} +1 -1
  41. package/page/assets/shaped-data-CJQ3W_RE.js +20 -0
  42. package/page/assets/{stub-nxRsh1jo.js → stub-U6wDGe3P.js} +25 -7
  43. package/page/assets/studio-code-pane-Boy63AK2.js +8 -0
  44. package/page/assets/{studio-console-BgymsByi.js → studio-console-B7zL133d.js} +1 -1
  45. package/page/assets/studio-decision-CbRjfbvG.js +1 -0
  46. package/page/assets/studio-embedding-DQ0QrEsu.js +2 -0
  47. package/page/assets/{studio-host-console-DtepSA77.js → studio-host-console-DDA2Um2-.js} +2 -2
  48. package/page/assets/{studio-labels-BZbz7-uL.js → studio-labels-jYWBoEyP.js} +1 -1
  49. package/page/assets/studio-live-D0YRu2zQ.js +5 -0
  50. package/page/assets/studio-map-C4Ra1QqL.js +1 -0
  51. package/page/assets/studio-session-CPnJaHc-.js +1 -0
  52. package/page/assets/studio-trace-replay-D-f2p7k9.js +3 -0
  53. package/page/assets/{studio-type-checker-BbUSqqOS.js → studio-type-checker-CVNPnko-.js} +1 -1
  54. package/page/assets/tool-schema-BDG2_rlP.js +17 -0
  55. package/page/assets/{trace-record-DxgSKmYY.js → trace-record-DoXjxrmJ.js} +1 -1
  56. package/page/assets/trace-schema--4IGmLeE.js +1 -0
  57. package/page/assets/tree-CcEbNvms.js +3 -0
  58. package/page/assets/turn-client-BmOSpCgw.js +2 -0
  59. package/page/assets/{use-one-call-DE5HvQsv.js → use-one-call-B3t-kfc5.js} +1 -1
  60. package/page/assets/{use-second-ticker-CEwOSS-d.js → use-second-ticker-CWjCHLG6.js} +1 -1
  61. package/page/assets/workspace-DUfaxr-g.js +1 -0
  62. package/page/index.html +20 -19
  63. package/people.d.ts +2 -0
  64. package/people.js +3 -1
  65. package/policy.js +1 -0
  66. package/providers.d.ts +2 -2
  67. package/providers.js +8 -3
  68. package/read-source.js +34 -7
  69. package/registrations.d.ts +23 -3
  70. package/runtime-scope.d.ts +6 -3
  71. package/runtime-scope.js +16 -4
  72. package/runtime.js +14 -2
  73. package/server/draft-handler.d.ts +4 -4
  74. package/server/draft-handler.js +3 -2
  75. package/server/draft-probe.d.ts +9 -1
  76. package/server/draft-probe.js +2 -1
  77. package/server/handler.js +71 -25
  78. package/server/live.d.ts +7 -1
  79. package/server/live.js +11 -4
  80. package/server/run-traces.d.ts +5 -1
  81. package/server/run-traces.js +7 -3
  82. package/server/save-new.js +5 -5
  83. package/server/save-session.js +4 -2
  84. package/server/serve.js +2 -1
  85. package/server/test-key.d.ts +2 -2
  86. package/server/test-key.js +1 -1
  87. package/slot-values.d.ts +2 -0
  88. package/slot-values.js +22 -0
  89. package/source.js +11 -4
  90. package/tool-readers.d.ts +23 -0
  91. package/tool-readers.js +60 -0
  92. package/tools.js +4 -1
  93. package/types.d.ts +3 -1
  94. package/ui/inspector-context.js +1 -1
  95. package/ui/lib/project-traces.d.ts +5 -0
  96. package/ui/lib/project-traces.js +21 -3
  97. package/ui/lib/studio-page.d.ts +6 -1
  98. package/ui/lib/studio-page.js +33 -31
  99. package/ui/lib/studio-project.d.ts +8 -1
  100. package/ui/lib/studio-project.js +19 -1
  101. package/ui/lib/studio-session.d.ts +2 -0
  102. package/ui/lib/studio-session.js +40 -2
  103. package/ui/lib/studio-store.d.ts +2 -2
  104. package/ui/lib/studio-store.js +9 -5
  105. package/ui/lib/tool-probe.d.ts +2 -0
  106. package/ui/lib/tool-probe.js +3 -2
  107. package/ui/lib/type-icons.d.ts +1 -0
  108. package/ui/lib/type-icons.js +2 -1
  109. package/ui/profile-editor.js +57 -21
  110. package/ui/studio-compare.d.ts +14 -4
  111. package/ui/studio-compare.js +58 -24
  112. package/ui/studio-live.d.ts +1 -1
  113. package/ui/studio-live.js +8 -3
  114. package/ui/studio-runner.d.ts +3 -2
  115. package/ui/studio-runner.js +16 -14
  116. package/ui/studio-screen.d.ts +1 -1
  117. package/ui/studio-screen.js +26 -20
  118. package/ui/studio-settings.js +3 -1
  119. package/ui/studio-trace-replay.js +7 -1
  120. package/workspace.js +3 -2
  121. package/page/assets/Banner-BkgdSxW_.js +0 -4
  122. package/page/assets/Center-nHS1JSux.js +0 -1
  123. package/page/assets/browser-connection-DSUHVCT5.js +0 -3
  124. package/page/assets/browser-engine-D1mbS8b9.js +0 -11
  125. package/page/assets/browser-transport-C8PD0IJk.js +0 -45
  126. package/page/assets/index-B7om06iO.js +0 -145
  127. package/page/assets/live-messages-CiLmR89m.js +0 -1
  128. package/page/assets/reader-DrOfMM8I.js +0 -5
  129. package/page/assets/shaped-data-H1miOZm2.js +0 -20
  130. package/page/assets/studio-code-pane-DA_z5w6h.js +0 -8
  131. package/page/assets/studio-decision-DWnr99n-.js +0 -1
  132. package/page/assets/studio-embedding-DCvI007w.js +0 -2
  133. package/page/assets/studio-live-CnyzlN29.js +0 -5
  134. package/page/assets/studio-map-DduCJzK7.js +0 -1
  135. package/page/assets/studio-session-CjUQSXx0.js +0 -1
  136. package/page/assets/studio-trace-replay-C0UPMVSt.js +0 -3
  137. package/page/assets/tool-schema-BmRYaywn.js +0 -17
  138. package/page/assets/trace-schema-9CdEyG6Q.js +0 -1
  139. package/page/assets/tree-3N-1RPZz.js +0 -3
  140. package/page/assets/turn-client-DN8PawJr.js +0 -2
  141. package/page/assets/workspace-CTSW941G.js +0 -1
@@ -0,0 +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-CcEbNvms.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-B7om06iO.js"></script>
13
+ <script type="module" crossorigin src="/studio/assets/index-B7sK7d-l.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">
@@ -46,22 +46,22 @@
46
46
  <link rel="modulepreload" crossorigin href="/studio/assets/IconAlertTriangle-BqAEqqdU.js">
47
47
  <link rel="modulepreload" crossorigin href="/studio/assets/isRenderable-DHkzpAoQ.js">
48
48
  <link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-t4c-5JMk.js">
49
- <link rel="modulepreload" crossorigin href="/studio/assets/schemas-BQ9Jydzb.js">
49
+ <link rel="modulepreload" crossorigin href="/studio/assets/schemas-D7cgkv3L.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-H1miOZm2.js">
52
- <link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-BmRYaywn.js">
51
+ <link rel="modulepreload" crossorigin href="/studio/assets/shaped-data-CJQ3W_RE.js">
52
+ <link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-BDG2_rlP.js">
53
53
  <link rel="modulepreload" crossorigin href="/studio/assets/live-ingress-OuSlQ6q7.js">
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-BkgdSxW_.js">
54
+ <link rel="modulepreload" crossorigin href="/studio/assets/tree-CcEbNvms.js">
55
+ <link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-dads1eyK.js">
56
+ <link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-CWjCHLG6.js">
57
+ <link rel="modulepreload" crossorigin href="/studio/assets/Banner-DrRNC3MG.js">
58
58
  <link rel="modulepreload" crossorigin href="/studio/assets/row-keys-WByP9Hsh.js">
59
- <link rel="modulepreload" crossorigin href="/studio/assets/Center-nHS1JSux.js">
59
+ <link rel="modulepreload" crossorigin href="/studio/assets/Center-CgO0c-qo.js">
60
60
  <link rel="modulepreload" crossorigin href="/studio/assets/IconSearch-BTx66a40.js">
61
- <link rel="modulepreload" crossorigin href="/studio/assets/trace-schema-9CdEyG6Q.js">
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-C8PD0IJk.js">
61
+ <link rel="modulepreload" crossorigin href="/studio/assets/trace-schema--4IGmLeE.js">
62
+ <link rel="modulepreload" crossorigin href="/studio/assets/stub-U6wDGe3P.js">
63
+ <link rel="modulepreload" crossorigin href="/studio/assets/reader-DHN96tSr.js">
64
+ <link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-GzhRiBdm.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,16 @@
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-DhoC5hWG.js">
75
- <link rel="modulepreload" crossorigin href="/studio/assets/turn-client-DN8PawJr.js">
74
+ <link rel="modulepreload" crossorigin href="/studio/assets/encode-files-CHeRLBO8.js">
75
+ <link rel="modulepreload" crossorigin href="/studio/assets/turn-client-BmOSpCgw.js">
76
76
  <link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-BsIYDnJR.js">
77
- <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-BZbz7-uL.js">
78
- <link rel="modulepreload" crossorigin href="/studio/assets/crypto-CD14HeXH.js">
79
- <link rel="modulepreload" crossorigin href="/studio/assets/workspace-CTSW941G.js">
77
+ <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-jYWBoEyP.js">
78
+ <link rel="modulepreload" crossorigin href="/studio/assets/crypto-B8dqEoWf.js">
79
+ <link rel="modulepreload" crossorigin href="/studio/assets/workspace-DUfaxr-g.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-CjUQSXx0.js">
82
+ <link rel="modulepreload" crossorigin href="/studio/assets/project-address-DjxPZuyn.js">
83
+ <link rel="modulepreload" crossorigin href="/studio/assets/studio-session-CPnJaHc-.js">
83
84
  <link rel="modulepreload" crossorigin href="/studio/assets/EmptyState-C_uF9Wyj.js">
84
85
  <link rel="modulepreload" crossorigin href="/studio/assets/useMenuPress-DLG1QOiE.js">
85
86
  <link rel="modulepreload" crossorigin href="/studio/assets/useAdaptivePresentation-Bma4-u1a.js">
package/people.d.ts CHANGED
@@ -45,6 +45,8 @@ export interface StudioPeopleOffer {
45
45
  }
46
46
  /** The header each run carries the builder's pick in. No header is no one. */
47
47
  export declare const ACTING_AS_HEADER = "x-theorem-studio-acting-as";
48
+ /** The pick on a live socket's address: a browser's `WebSocket` sends no headers. */
49
+ export declare const ACTING_AS_PARAM = "acting-as";
48
50
  /** The session a run acting as no one is in. */
49
51
  export declare const NO_ONE_SESSION = "theorem-studio-local";
50
52
  /** The pick as a header value: the label may be any text, and a header holds only some. */
package/people.js CHANGED
@@ -11,6 +11,8 @@
11
11
  import { z } from 'zod';
12
12
  /** The header each run carries the builder's pick in. No header is no one. */
13
13
  export const ACTING_AS_HEADER = 'x-theorem-studio-acting-as';
14
+ /** The pick on a live socket's address: a browser's `WebSocket` sends no headers. */
15
+ export const ACTING_AS_PARAM = 'acting-as';
14
16
  /** The session a run acting as no one is in. */
15
17
  export const NO_ONE_SESSION = 'theorem-studio-local';
16
18
  const nameSchema = z.object({ id: z.string().min(1), label: z.string().min(1) });
@@ -40,7 +42,7 @@ export function actingAsSession(actingAs) {
40
42
  }
41
43
  /** Reads a run's pick and checks its place is one the setup offers. */
42
44
  export function readActingAs(request, people) {
43
- const sent = request.headers.get(ACTING_AS_HEADER);
45
+ const sent = request.headers.get(ACTING_AS_HEADER) ?? new URL(request.url).searchParams.get(ACTING_AS_PARAM);
44
46
  if (sent === null)
45
47
  return { ok: true, actingAs: undefined };
46
48
  let value;
package/policy.js CHANGED
@@ -65,6 +65,7 @@ const MODEL_IDS = {
65
65
  text: 'fast',
66
66
  image: 'image',
67
67
  speech: 'voice',
68
+ transcription: 'transcription',
68
69
  live: 'live',
69
70
  decision: 'decision',
70
71
  embedding: 'embedding',
package/providers.d.ts CHANGED
@@ -119,7 +119,7 @@ export interface ProtocolOptionField {
119
119
  /** Where it sits under the model's `options`, dotted: `store`, `cache.mode`. */
120
120
  path: string;
121
121
  label: string;
122
- kind: 'boolean' | 'choice' | 'text' | 'number';
122
+ kind: 'boolean' | 'choice' | 'text' | 'number' | 'names';
123
123
  /** The protocol refuses the model without it. */
124
124
  required: boolean;
125
125
  /** What the protocol says the option is. */
@@ -135,7 +135,7 @@ export interface ProtocolOptionField {
135
135
  }
136
136
  /**
137
137
  * The options `protocol` takes, a field per setting, read from its own schema. A setting inside an
138
- * object is a field of its own; one a row cannot hold (a list, a free record) is left to code. Given
138
+ * object is a field of its own; one a row cannot hold (a list of objects, a free record) is left to code. Given
139
139
  * the model, an option it refuses is left out, unless `options` already holds it: that row stays,
140
140
  * where its issue shows.
141
141
  */
package/providers.js CHANGED
@@ -208,11 +208,11 @@ export function modelRoute(providers, type, binding) {
208
208
  };
209
209
  }
210
210
  function isModelProfileType(type) {
211
- return ['text', 'image', 'speech', 'live', 'decision', 'embedding'].includes(type);
211
+ return ['text', 'image', 'speech', 'transcription', 'live', 'decision', 'embedding'].includes(type);
212
212
  }
213
213
  /**
214
214
  * The options `protocol` takes, a field per setting, read from its own schema. A setting inside an
215
- * object is a field of its own; one a row cannot hold (a list, a free record) is left to code. Given
215
+ * object is a field of its own; one a row cannot hold (a list of objects, a free record) is left to code. Given
216
216
  * the model, an option it refuses is left out, unless `options` already holds it: that row stays,
217
217
  * where its issue shows.
218
218
  */
@@ -272,6 +272,8 @@ function fieldsOf(node, prefix, held) {
272
272
  }
273
273
  if (property.type === 'boolean')
274
274
  return [{ ...base, kind: 'boolean' }];
275
+ if (property.type === 'array' && property.items?.type === 'string')
276
+ return [{ ...base, kind: 'names' }];
275
277
  if (property.type === 'string')
276
278
  return [{ ...base, kind: 'text' }];
277
279
  if (property.type === 'number' || property.type === 'integer')
@@ -281,7 +283,10 @@ function fieldsOf(node, prefix, held) {
281
283
  }
282
284
  /** An option's name as a row labels it: `persistViaInteractionId` is Persist via interaction id. */
283
285
  function optionLabel(name) {
284
- const words = name.replace(/([a-z0-9])([A-Z])/g, '$1 $2').toLowerCase();
286
+ const words = name
287
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
288
+ .replace(/_/g, ' ')
289
+ .toLowerCase();
285
290
  return words.charAt(0).toUpperCase() + words.slice(1);
286
291
  }
287
292
  /** The value at `path` in `options`. */
package/read-source.js CHANGED
@@ -500,12 +500,12 @@ function readCall(src, parsed) {
500
500
  if (typeof id !== 'string' || !isRecord(spec)) {
501
501
  src.fail('registerStructured() needs an id and a spec.');
502
502
  }
503
- parsed.structured = { id, spec };
503
+ parsed.structures.push({ id, spec });
504
504
  }
505
505
  }
506
506
  function parseModule(text, of = 'profile') {
507
507
  const src = new Src(text, of);
508
- const parsed = { tools: [], spans: [] };
508
+ const parsed = { tools: [], structures: [], spans: [] };
509
509
  for (src.skip(); !src.done; src.skip()) {
510
510
  if (src.peekIdent() === 'import') {
511
511
  src.expectIdent();
@@ -544,12 +544,29 @@ function markup(value, srcMessage) {
544
544
  .map((part) => {
545
545
  if (typeof part === 'string')
546
546
  return part;
547
+ if (Array.isArray(part))
548
+ return markup(part, srcMessage);
547
549
  if (isRecord(part) && typeof part.private === 'string')
548
550
  return `{private: ${part.private}}`;
549
551
  throw new ReadFail(srcMessage, 1, 1);
550
552
  })
551
553
  .join('');
552
554
  }
555
+ /** A prompt as the draft holds it: one entry per line, and a bare `{ private }` is no line. */
556
+ function promptLines(value, current) {
557
+ const srcMessage = 'The system prompt has to be text.';
558
+ const lines = Array.isArray(value) ? value : [value];
559
+ const texts = lines.map((line) => {
560
+ if (Array.isArray(value) && typeof line !== 'string' && !Array.isArray(line)) {
561
+ throw new ReadFail(srcMessage, 1, 1);
562
+ }
563
+ return markup(line, srcMessage);
564
+ });
565
+ return (texts.length ? texts : ['']).map((text, at) => ({
566
+ key: current[at]?.key ?? draftKey('line'),
567
+ text,
568
+ }));
569
+ }
553
570
  function jsonText(value) {
554
571
  if (value === undefined)
555
572
  return '';
@@ -847,6 +864,7 @@ function toolOf(spec, current, agentKeyOf) {
847
864
  // A page tool's source has no handler: its stub is the studio's own, so it is kept.
848
865
  stubOutputJson: page ? current?.stubOutputJson : stubOf(type, spec),
849
866
  answeredBy: page ? 'page' : undefined,
867
+ after: spec.after === true ? true : undefined,
850
868
  ...toolRoute(spec),
851
869
  agentKey: agentId ? agentKeyOf?.(agentId) : undefined,
852
870
  maxCallsPerTurn: whole(spec.maxCallsPerTurn),
@@ -971,14 +989,13 @@ function allowTools(registered, allow, spans) {
971
989
  }
972
990
  function identityOf(current, profile, type) {
973
991
  const identity = record(profile.identity) ?? {};
974
- const byRole = identity.systemByRole;
975
992
  return {
976
993
  ...current,
977
994
  agentId: text(profile.id),
978
995
  profileType: type,
979
996
  handle: text(identity.handle),
980
- system: markup(identity.system, 'The system prompt has to be text.'),
981
- systemByRoleJson: isRecord(byRole) || Array.isArray(byRole) ? jsonText(byRole) : '',
997
+ system: promptLines(identity.system, current.system),
998
+ conditionsJson: isRecord(identity.conditions) ? jsonText(identity.conditions) : '',
982
999
  };
983
1000
  }
984
1001
  function modelsOf(profile) {
@@ -1045,14 +1062,24 @@ function itemRulesOf(items) {
1045
1062
  record(rule)?.onFail === 'fix' ? 'fix' : 'drop',
1046
1063
  ]));
1047
1064
  }
1048
- function outputsOf(outputs, structured) {
1065
+ function outputsOf(outputs, structures) {
1066
+ const picks = record(outputs?.structured);
1067
+ const structured = picks
1068
+ ? structures.find(({ id }) => id === text(picks.fallback))
1069
+ : structures[0];
1049
1070
  const schemaId = structured?.id ?? text(outputs?.structured);
1071
+ const shapes = Object.entries(record(picks?.map) ?? {}).map(([choice, id]) => ({
1072
+ choice,
1073
+ schemaId: text(id),
1074
+ schemaJson: jsonText(structures.find((shape) => shape.id === id)?.spec.jsonSchema),
1075
+ }));
1050
1076
  const streaming = record(outputs?.streaming);
1051
1077
  const validation = record(outputs?.validation);
1052
1078
  return {
1053
1079
  mode: schemaId ? 'structured' : 'text',
1054
1080
  schemaId,
1055
1081
  schemaJson: jsonText(structured?.spec.jsonSchema),
1082
+ ...(picks ? { bySlot: { slot: text(picks.by), shapes } } : {}),
1056
1083
  streamMode: text(streaming?.mode),
1057
1084
  streamThoughts: streaming?.streamThoughts !== false,
1058
1085
  validationEnabled: validation !== undefined,
@@ -1220,7 +1247,7 @@ function draftFrom(parsed, current, agentKeyOf) {
1220
1247
  tools: { t2Loader: text(tools.t2Loader), parallel: tools.parallel === true },
1221
1248
  toolSpecs: [],
1222
1249
  inputs: inputs && type !== 'decision' ? inputsOf(inputs, current.inputs) : current.inputs,
1223
- outputs: outputs || parsed.structured ? outputsOf(outputs, parsed.structured) : current.outputs,
1250
+ outputs: outputs || parsed.structures.length ? outputsOf(outputs, parsed.structures) : current.outputs,
1224
1251
  turnBehaviour: section(profile.turnBehaviour, turnOf, current.turnBehaviour),
1225
1252
  guardrails: section(profile.guardrails, guardrailsOf, current.guardrails),
1226
1253
  observability: section(profile.observability, observabilityOf, current.observability),
@@ -1,3 +1,4 @@
1
+ import type { DecisionQuestion } from '@theoremjs/agents';
1
2
  import type { StructuredSpec, ToolAuthConfig, ToolLabels } from '@theoremjs/agents/kernel';
2
3
  import type { HttpMethod, ToolAccess, ToolLoadTier, ToolPermission } from '@theoremjs/agents/schema';
3
4
  /** The kernel's auth config; the host's OAuth endpoints are never set from the studio. */
@@ -6,6 +7,11 @@ export type StudioToolLabels = Pick<ToolLabels, 'activity' | 'activityPast' | 'a
6
7
  export type StructuredRegistration = {
7
8
  id: string;
8
9
  spec: StructuredSpec;
10
+ /** The shapes a slot's value picks, beside the fallback `id`. */
11
+ also?: {
12
+ id: string;
13
+ spec: StructuredSpec;
14
+ }[];
9
15
  };
10
16
  export type FunctionToolRegistration = {
11
17
  type: 'function';
@@ -19,12 +25,16 @@ export type FunctionToolRegistration = {
19
25
  inputSchema: Record<string, unknown>;
20
26
  outputSchema: Record<string, unknown>;
21
27
  labels?: StudioToolLabels;
28
+ /** The model can name tools of its step that finish before this one starts. */
29
+ after?: boolean;
22
30
  /**Overrides the generic stub. */
23
31
  stubResponse?: Record<string, unknown>;
24
32
  /** The page answers the call: the kernel supplies the handler, and the page sends the output. */
25
33
  answeredBy?: 'page';
26
- /** The decision or text profile that reads this tool's output at `post_tool`. */
34
+ /** The decision profile that reads this tool's output at `post_tool`. */
27
35
  stageAgent?: string;
36
+ /** What `stageAgent` asks of each passage, by id. A run fills it from that agent. */
37
+ stageQuestions?: Record<string, DecisionQuestion>;
28
38
  };
29
39
  export type HttpToolRegistration = {
30
40
  type: 'http';
@@ -48,8 +58,12 @@ export type HttpToolRegistration = {
48
58
  inputSchema: Record<string, unknown>;
49
59
  outputSchema: Record<string, unknown>;
50
60
  labels?: StudioToolLabels;
51
- /** The decision or text profile that reads this tool's output at `post_tool`. */
61
+ /** The model can name tools of its step that finish before this one starts. */
62
+ after?: boolean;
63
+ /** The decision profile that reads this tool's output at `post_tool`. */
52
64
  stageAgent?: string;
65
+ /** What `stageAgent` asks of each passage, by id. A run fills it from that agent. */
66
+ stageQuestions?: Record<string, DecisionQuestion>;
53
67
  };
54
68
  export type McpToolRegistration = {
55
69
  type: 'mcp';
@@ -72,8 +86,12 @@ export type McpToolRegistration = {
72
86
  inputSchema: Record<string, unknown>;
73
87
  outputSchema: Record<string, unknown>;
74
88
  labels?: StudioToolLabels;
75
- /** The decision or text profile that reads this tool's output at `post_tool`. */
89
+ /** The model can name tools of its step that finish before this one starts. */
90
+ after?: boolean;
91
+ /** The decision profile that reads this tool's output at `post_tool`. */
76
92
  stageAgent?: string;
93
+ /** What `stageAgent` asks of each passage, by id. A run fills it from that agent. */
94
+ stageQuestions?: Record<string, DecisionQuestion>;
77
95
  };
78
96
  /** Runs one turn of another registered agent; its schemas are the kernel's fixed ones. */
79
97
  export type AgentToolRegistration = {
@@ -91,5 +109,7 @@ export type AgentToolRegistration = {
91
109
  inputSchema: Record<string, unknown>;
92
110
  outputSchema: Record<string, unknown>;
93
111
  labels?: StudioToolLabels;
112
+ /** The model can name tools of its step that finish before this one starts. */
113
+ after?: boolean;
94
114
  };
95
115
  export type ToolRegistration = FunctionToolRegistration | HttpToolRegistration | McpToolRegistration | AgentToolRegistration;
@@ -2,7 +2,7 @@
2
2
  * Studio drafts, each run on a kernel scope of its own. Two visitors can
3
3
  * name the same profile, tool, or schema without either one seeing the other's.
4
4
  */
5
- import { defineProfile, type KernelScope, type Profile, type ProfileDefinition, type Provider, type ResolveHost, type ToolExecutionCoordinator } from '@theoremjs/agents';
5
+ import { defineProfile, type KernelScope, type Profile, type ProfileDefinition, type Provider, type RegisteredProvider, type ResolveHost, type ToolExecutionCoordinator } from '@theoremjs/agents';
6
6
  import { type DetectSpec } from '@theoremjs/agents/guardrails';
7
7
  import type { AgentCall, AgentCallHook, ProviderHostOptions, TurnModel } from '@theoremjs/agents/kernel';
8
8
  export interface StudioProviderOptions extends ProviderHostOptions {
@@ -34,6 +34,8 @@ export interface StudioRuntimeBase {
34
34
  } | undefined | Promise<{
35
35
  refuse: string;
36
36
  } | undefined>;
37
+ /** Before a tool's reader reads each passage: throw to stop it, and the model reads the output whole. */
38
+ onReaderCall?: () => void | Promise<void>;
37
39
  }
38
40
  /** A run, and what it runs on: a run on lent keys carries the keys it is held to. */
39
41
  export type StudioRuntime = StudioRuntimeBase & StudioRunsOn;
@@ -76,9 +78,10 @@ export declare function studioScope(profile: ProfileDefinition, customTools: rea
76
78
  /**
77
79
  * A new scope holding drafts as written, the last one returned: no runtime
78
80
  * rewrites their guardrails or checks their model bindings. For a run that
79
- * calls no model and reaches no host. Never cache or share it.
81
+ * calls no model and reaches no host. Never cache or share it. `providers` are the project's: a
82
+ * draft's model names them, and they stand over a studio provider of the same id.
80
83
  */
81
- export declare function writtenScope(drafts: readonly StudioDependency[]): Promise<{
84
+ export declare function writtenScope(drafts: readonly StudioDependency[], providers?: readonly RegisteredProvider[]): Promise<{
82
85
  scope: KernelScope;
83
86
  profile: Profile | undefined;
84
87
  }>;
package/runtime-scope.js CHANGED
@@ -165,8 +165,11 @@ function withDraftItemChecks(def) {
165
165
  };
166
166
  }
167
167
  function runtimeProfileDefinition(def, runtime) {
168
- // A speech, decision, or embedding profile calls no tools: no network or taint hold governs it.
169
- if (def.type === 'speech' || def.type === 'decision' || def.type === 'embedding')
168
+ // A speech, transcription, decision, or embedding profile calls no tools: no network or taint hold governs it.
169
+ if (def.type === 'speech' ||
170
+ def.type === 'transcription' ||
171
+ def.type === 'decision' ||
172
+ def.type === 'embedding')
170
173
  return def;
171
174
  // A host runs one tool per call, so a turn never reads before it acts; the kernel refuses taint there.
172
175
  if (def.type === 'host') {
@@ -319,11 +322,20 @@ export async function studioScope(profile, customTools, structured, runtime, dep
319
322
  /**
320
323
  * A new scope holding drafts as written, the last one returned: no runtime
321
324
  * rewrites their guardrails or checks their model bindings. For a run that
322
- * calls no model and reaches no host. Never cache or share it.
325
+ * calls no model and reaches no host. Never cache or share it. `providers` are the project's: a
326
+ * draft's model names them, and they stand over a studio provider of the same id.
323
327
  */
324
- export async function writtenScope(drafts) {
328
+ export async function writtenScope(drafts, providers = []) {
325
329
  const scope = createKernelScope();
326
330
  registerRuntimeProviders(scope);
331
+ for (const { definition, id, connection, keySlot, fallbackKeySlot } of providers) {
332
+ scope.providers.replace(definition, {
333
+ id,
334
+ connection,
335
+ ...(keySlot ? { keySlot } : {}),
336
+ ...(fallbackKeySlot ? { fallbackKeySlot } : {}),
337
+ });
338
+ }
327
339
  let profile;
328
340
  for (const draft of drafts) {
329
341
  await refuseSlowSchemaPatterns(draft.customTools);
package/runtime.js CHANGED
@@ -6,6 +6,7 @@ import { answerReply, checkRequest, conversationView, messageReply, openConversa
6
6
  import { STUDIO_TRACE_DESTINATION } from "./policy.js";
7
7
  import { studioReader } from "./reader.js";
8
8
  import { agentCallHook, runtimeProvider, studioScope, } from "./runtime-scope.js";
9
+ import { bothStages, toolReaderStage, toolReaders } from "./tool-readers.js";
9
10
  import { createStudioTraceRouter } from "./traces.js";
10
11
  // Profiles that write to the studio destination get their records back on the run's own stream.
11
12
  export const studioTraces = createStudioTraceRouter();
@@ -67,6 +68,7 @@ function studioRunner(args) {
67
68
  pageExecution: runtime.pageExecution,
68
69
  metadata,
69
70
  input: turn.input,
71
+ ...turn.stated,
70
72
  ...(turn.conversationId ? { conversationId: turn.conversationId } : {}),
71
73
  providerState: turn.providerState,
72
74
  sessionPermissions: args.sessionPermissions,
@@ -83,6 +85,7 @@ function studioRunner(args) {
83
85
  },
84
86
  ...(args.model ? { model: args.model } : {}),
85
87
  ...(args.effort ? { effort: args.effort } : {}),
88
+ ...(args.stated ? { stated: args.stated } : {}),
86
89
  signal,
87
90
  };
88
91
  }
@@ -150,11 +153,20 @@ export async function* streamStudioTurn(args) {
150
153
  sessionPermissions,
151
154
  ...(request.model ? { model: request.model } : {}),
152
155
  ...(request.effort ? { effort: request.effort } : {}),
156
+ ...(request.stated ? { stated: request.stated } : {}),
153
157
  signal,
154
- onStage: steerStage(args.steer, inbox),
158
+ onStage: bothStages(steerStage(args.steer, inbox), toolReaderStage(toolReaders(args.customTools), async (reader, state) => {
159
+ await runtime.onReaderCall?.();
160
+ return scope.runDecision({ profile: reader.profile, state, questions: reader.questions, signal }, runtimeProvider(runtime, scope, scope.profiles.get(reader.profile)));
161
+ })),
155
162
  });
156
163
  if (!host || !opened) {
157
- return runner.run({ input: message.input, model: request.model, effort: request.effort });
164
+ return runner.run({
165
+ input: message.input,
166
+ model: request.model,
167
+ effort: request.effort,
168
+ ...(request.stated ? { stated: request.stated } : {}),
169
+ });
158
170
  }
159
171
  const walkAway = walked.map(({ reference, invoke }) => ({
160
172
  ...reference,
@@ -34,8 +34,8 @@ export type StudioDraftHandlerOptions = {
34
34
  lent?: LentRuntime;
35
35
  /**
36
36
  * Spends one of `kind` for whoever sent `request`, before it runs. Throw a `TheoremError` to refuse
37
- * it: the screen reads the error's wording. Every decision, host tool call, and agent tool turn on
38
- * the lent keys passes through it. Default: nothing is counted.
37
+ * it: the screen reads the error's wording. Every decision, host tool call, agent tool turn, and
38
+ * passage a tool's reader reads on the lent keys passes through it. Default: nothing is counted.
39
39
  */
40
40
  spend?: (kind: StudioSpend, request: Request) => void | Promise<void>;
41
41
  /**
@@ -64,8 +64,8 @@ export type StudioDraftHandlerOptions = {
64
64
  * whatever the draft says, so no visitor reaches the host's own network.
65
65
  */
66
66
  draftNetwork?: boolean;
67
- /** A provider the project registers from a definition of its own, so its key can be checked. */
68
- projectProvider?: (id: string) => RegisteredProvider | undefined;
67
+ /** The project's providers: a key is checked on them, and a probed draft's models name them. */
68
+ projectProviders?: () => readonly RegisteredProvider[];
69
69
  };
70
70
  /**
71
71
  * Answers a request under `STUDIO_BASE`; `defer` keeps work running after the reply (a Worker's
@@ -79,6 +79,7 @@ export function createStudioDraftHandler(options = {}) {
79
79
  execution: boundary.toolExecution,
80
80
  pageExecution: boundary.pageExecution,
81
81
  onAgentCall: agentCall(request),
82
+ onReaderCall: spend && (() => spend('decision', request)),
82
83
  });
83
84
  /** A draft as a run takes it. */
84
85
  const draftRun = (lent, draft, boundary, request) => ({
@@ -199,11 +200,11 @@ export function createStudioDraftHandler(options = {}) {
199
200
  const path = new URL(request.url).pathname;
200
201
  const route = path.startsWith(`${STUDIO_BASE}/`) ? path.slice(STUDIO_BASE.length + 1) : '';
201
202
  const routes = {
202
- probe: (asked) => draftProbe(asked, options.onProbePassed, defer ?? (() => { })),
203
+ probe: (asked) => draftProbe(asked, options.onProbePassed, defer ?? (() => { }), options.projectProviders?.() ?? []),
203
204
  'test-key': (asked) => testKey(asked, {
204
205
  resolveHost,
205
206
  draftNetwork: options.draftNetwork,
206
- projectProvider: options.projectProvider,
207
+ projectProviders: options.projectProviders,
207
208
  }),
208
209
  'test-connection': (asked) => testConnection(asked, { resolveHost, draftNetwork: options.draftNetwork }),
209
210
  ...(lent ? lentRoutes(lent) : {}),
@@ -1,3 +1,11 @@
1
+ /**
2
+ * `POST <base>/probe`: one text sent across every guardrail boundary of the draft, each on a
3
+ * scripted model, so no key is spent and no host is reached. With `only`, the draft reads with that
4
+ * detector alone: what the others would catch passes there.
5
+ *
6
+ * @module
7
+ */
8
+ import { type RegisteredProvider } from '@theoremjs/agents';
1
9
  import { type GuardrailProbeAnswer } from '../guardrail-probe.ts';
2
10
  /** A probed text some boundary let through, and what each boundary's guardrails did with it. */
3
11
  export type ProbeEntry = {
@@ -11,4 +19,4 @@ export type ProbeEntry = {
11
19
  * some boundary passed, run with every detector and not one of the battery's, goes to `onPassed`
12
20
  * through `defer`, after the answer: one that fails never fails a probe.
13
21
  */
14
- export declare function draftProbe(request: Request, onPassed: ((entry: ProbeEntry, at: Date) => Promise<void>) | undefined, defer: (work: Promise<unknown>) => void): Promise<Response>;
22
+ export declare function draftProbe(request: Request, onPassed: ((entry: ProbeEntry, at: Date) => Promise<void>) | undefined, defer: (work: Promise<unknown>) => void, projectProviders: readonly RegisteredProvider[]): Promise<Response>;
@@ -31,7 +31,7 @@ function isBatteryText(text) {
31
31
  * some boundary passed, run with every detector and not one of the battery's, goes to `onPassed`
32
32
  * through `defer`, after the answer: one that fails never fails a probe.
33
33
  */
34
- export async function draftProbe(request, onPassed, defer) {
34
+ export async function draftProbe(request, onPassed, defer, projectProviders) {
35
35
  let labels;
36
36
  try {
37
37
  const body = await readBody(request, probeRequestSchema);
@@ -41,6 +41,7 @@ export async function draftProbe(request, onPassed, defer) {
41
41
  customTools: body.customTools ?? [],
42
42
  structured: body.structured,
43
43
  dependencies: body.dependencies,
44
+ projectProviders,
44
45
  text: body.text,
45
46
  only: body.only,
46
47
  signal: request.signal,