@theoremjs/studio 0.3.4-next.715.geef22fd → 0.3.4-next.721.g7ff150a

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 (58) hide show
  1. package/browser-execution.d.ts +3 -2
  2. package/browser-execution.js +2 -0
  3. package/browser-live.js +2 -1
  4. package/browser-transport.js +1 -0
  5. package/package.json +4 -4
  6. package/page/assets/Banner-CvzDCsXL.js +3 -0
  7. package/page/assets/{ConsoleFrame-dOTqIkpb.js → ConsoleFrame-DwVyTmlI.js} +1 -1
  8. package/page/assets/{MenuBottomSheet-DeuZCVb-.js → MenuBottomSheet-DfwpdQHV.js} +1 -1
  9. package/page/assets/{SchemaFields-DeuNDrvj.js → SchemaFields-DDqEu_Dl.js} +1 -1
  10. package/page/assets/{ToolResultCharts-B-pokquL.js → ToolResultCharts-DgVbZ6tY.js} +1 -1
  11. package/page/assets/{TraceInspector-CvJ0wx9n.js → TraceInspector-D0_MVLtt.js} +1 -1
  12. package/page/assets/{TraceOverview-cIjJwpvK.js → TraceOverview-DKnXuaLk.js} +1 -1
  13. package/page/assets/{_virtual_studio-type-sources-BxnDf9BC.js → _virtual_studio-type-sources-BSY0b1_W.js} +65 -115
  14. package/page/assets/browser-connection-DMLe-0pv.js +3 -0
  15. package/page/assets/browser-engine-Daccda1E.js +13 -0
  16. package/page/assets/{browser-transport-DKhZ4zo1.js → browser-transport-Ddqv2L5-.js} +3 -3
  17. package/page/assets/{crypto-BnoW7FFO.js → crypto-DjhcOJmp.js} +1 -1
  18. package/page/assets/{encode-files-DoLGXgup.js → encode-files-BF1rsZES.js} +1 -1
  19. package/page/assets/{export-agent-CO4lAMum.js → export-agent-CDiThjyY.js} +1 -1
  20. package/page/assets/{guardrail-tester-Slctc2oI.js → guardrail-tester-BjJ6KSvt.js} +1 -1
  21. package/page/assets/index-Cvl7QJ2f.js +149 -0
  22. package/page/assets/live-messages-eYYz6aFz.js +1 -0
  23. package/page/assets/reader-DAdKx3ZF.js +5 -0
  24. package/page/assets/{shaped-data-7q5Be8sp.js → shaped-data-BRffby3g.js} +1 -1
  25. package/page/assets/{stub--LOYiyQO.js → stub-4NoUUWes.js} +1 -1
  26. package/page/assets/{studio-code-pane-CuccT4Ur.js → studio-code-pane-OXpOLYem.js} +3 -3
  27. package/page/assets/{studio-console-DwxLzV9_.js → studio-console-DdjCZJRm.js} +1 -1
  28. package/page/assets/{studio-decision-w6OjVUM3.js → studio-decision-Dd4-ZPqy.js} +1 -1
  29. package/page/assets/{studio-embedding-CxFoTvOd.js → studio-embedding-BCfUGzri.js} +1 -1
  30. package/page/assets/{studio-host-console-BhQSkUhA.js → studio-host-console-CwErqojz.js} +2 -2
  31. package/page/assets/{studio-labels-q6eBFSru.js → studio-labels-BZFUS19x.js} +1 -1
  32. package/page/assets/studio-live-ChYgN-57.js +5 -0
  33. package/page/assets/{studio-map-DlkGoGam.js → studio-map-CKgv43yP.js} +1 -1
  34. package/page/assets/{studio-trace-replay-Ccv4ToIz.js → studio-trace-replay-vOG3xvRR.js} +2 -2
  35. package/page/assets/{studio-type-checker-Dm2eit0p.js → studio-type-checker-BO-lN_65.js} +1 -1
  36. package/page/assets/{tool-schema-6RWBAqGO.js → tool-schema-C7lMQU0w.js} +7 -7
  37. package/page/assets/{trace-record-Dm2jEhUR.js → trace-record-Doo6lYDI.js} +1 -1
  38. package/page/assets/tree-BpAzPK_j.js +3 -0
  39. package/page/assets/{turn-client-OLK12Fyi.js → turn-client-CMgd-m7p.js} +2 -2
  40. package/page/assets/{use-one-call-CLndFp2X.js → use-one-call-B_8i95fw.js} +1 -1
  41. package/page/assets/{use-second-ticker-D6JSf9B3.js → use-second-ticker-Bx4tqkhi.js} +1 -1
  42. package/page/assets/{workspace-DSAX72vF.js → workspace-CUvoWPwb.js} +1 -1
  43. package/page/index.html +15 -15
  44. package/replay.js +1 -0
  45. package/runtime-scope.d.ts +10 -1
  46. package/runtime-scope.js +7 -0
  47. package/runtime.js +3 -0
  48. package/server/handler.js +2 -1
  49. package/server/live.js +5 -1
  50. package/ui/profile-editor.js +34 -4
  51. package/page/assets/Banner-CrhjYjDy.js +0 -3
  52. package/page/assets/browser-connection-CuWeoI9s.js +0 -3
  53. package/page/assets/browser-engine-C3SeJyrA.js +0 -13
  54. package/page/assets/index-CAK9cdCh.js +0 -149
  55. package/page/assets/live-messages-M0vS3YB0.js +0 -1
  56. package/page/assets/reader-747-Cvu8.js +0 -5
  57. package/page/assets/studio-live-D5NjMEky.js +0 -5
  58. package/page/assets/tree-DcCW259J.js +0 -3
@@ -1 +1 @@
1
- import{$n as e,C as t,H as n,Ot as r,Qn as i,S as a,U as o,Xn as s,Yn as c,qt as l,w as u}from"./shaped-data-7q5Be8sp.js";var d=/^data:([^;,]+);base64,/;function f(e){if(typeof(e.mime_type??e.mimeType)==`string`&&typeof e.data==`string`)return`data`;if(typeof e.media_type==`string`&&typeof e.b64_json==`string`)return`b64_json`}var p=`sha256`,m=`text_sha256`;async function h(t){let n=await e(t);return n?{kind:p,hash:n.hash}:{kind:m,hash:await i(t)}}async function g(e){let t=d.exec(e);if(!t)return e;let{kind:n,hash:r}=await h(e.slice(t[0].length));return`data:${t[1]};${n},${r}`}async function _(e){let t=f(e),n,r=await Promise.all(Object.entries(e).map(async([e,r])=>{if(e===t&&typeof r==`string`){let{kind:t,hash:i}=await h(r);return n=t,[e,i]}return[e,await v(r)]})),i=Object.fromEntries(r);return n&&(i.dataKind=n),i}function v(e){return typeof e==`string`?g(e):Array.isArray(e)?Promise.all(e.map(e=>v(e))):e&&typeof e==`object`?_(e):Promise.resolve(e)}function y(e,t){return t.reduce((e,t)=>r(e,t),e)}function b(e,t){return t.some(Boolean)?s(e,e=>y(e,t)):e}async function x(e,t){return b(await v(e),t)}var S=`https://github.com/open-telemetry/semantic-conventions-genai/tree/8ffdf56`,C=`content_sha256`,w=`json_sha256`,T=[`gen_ai.usage.`,`theorem.usage.`],E={"theorem.upstream.row":`upstreamLog`,"theorem.wire.request":`outboundWire`,"theorem.guardrail":`guardrailDecisions`},D=`raw`,O=`match`,k=[`injection`,`tool_instructions`];function A(e,t){return e===!0||e!==!1&&e[t]}function j(e,{scrub:t,detect:r}){let{sensitive:i,injection:a}=t;return l(e,[...i?o(e,c,i,r):[],...A(i,`host`)?n(e,r):[],...a?o(e,k,a,r):[]])}async function M(e,t){let n=await i(e);return t.content[n]=e,t.known.set(e,n),n}function N(e,t){let{[t]:n,...r}=e;return r}async function P(n,r){if(t(n)){let e=y(j(n.$content,r),r.canaries);return{...N(n,`$content`),[C]:await M(e,r)}}if(a(n)){let t=N(n,`$bytes`),r=await e(n.$bytes);return r?{...t,content_sha256:r.hash,bytes:r.bytes}:{...t,invalid_base64:!0,text_sha256:await i(n.$bytes)}}return u(n)?n:await R(n,e=>P(e,r))}function F(e,t){return typeof e==`string`?t(e):Array.isArray(e)?e.map(e=>F(e,t)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,F(n,t)])):e}function I(e,t){return F(e,e=>{let n=j(e,t),r=t.known.get(n);return r?{[C]:r}:n})}async function L(e,t){if(u(e)){let n=await x(e.$json,t.canaries),r=JSON.stringify(I(n,t)),a=await i(r);return t.content[a]=r,{...N(e,`$json`),[w]:a}}return await R(e,e=>L(e,t))}async function R(e,t){if(Array.isArray(e))return await Promise.all(e.map(t));if(e&&typeof e==`object`){let n=await Promise.all(Object.entries(e).map(async([e,n])=>[e,await t(n)]));return Object.fromEntries(n)}return e}async function z(e,t){let n=await Promise.all(Object.entries(e).map(async([e,n])=>[e,await t(n)]));return Object.fromEntries(n)}async function B(e,t){let n=await Promise.all(e.events.map(async e=>({...e,attributes:await z(e.attributes,t)})));return{...e,attributes:await z(e.attributes,t),events:n}}function V(e,t){return t.usage?e:Object.fromEntries(Object.entries(e).filter(([e])=>!T.some(t=>e.startsWith(t))))}function H(e){return e.map(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return e;let{[O]:t,...n}=e;return n})}function U(e,t){let n=E[e.name];if(n&&!t[n])return;if(e.name===`theorem.grounding`&&!t.evidenceRaw){let{[D]:t,...n}=e.attributes;return{...e,attributes:n}}let{hits:r}=e.attributes;return e.name===`theorem.guardrail`&&!t.guardrailMatchPreview&&Array.isArray(r)?{...e,attributes:{...e.attributes,hits:H(r)}}:e}function W(e,t){return{...e,attributes:V(e.attributes,t),events:e.events.flatMap(e=>U(e,t)??[])}}function G(e){return Object.entries(e).flatMap(([e,t])=>t?[e]:[])}async function K(e){let{policy:t}=e,n={scrub:t.scrub,detect:t.detect,canaries:A(t.scrub.canary,`theorem`)?e.canaries??[]:[],content:{},known:new Map},r=e.spans.map(e=>W(e,t.include)),[i]=r;i&&(i.attributes={...i.attributes,"theorem.record.include":G(t.include),"theorem.record.scrub":G(t.scrub)});let a=await Promise.all(r.map(e=>B(e,e=>P(e,n)))),o=await Promise.all(a.map(e=>B(e,e=>L(e,n))));return{v:3,schemaUrl:S,resource:{...t.resource},...e.metadata?{metadata:e.metadata}:{},spans:o,content:n.content}}function q(e,t){if(Array.isArray(t))return t.map(t=>q(e,t));if(!t||typeof t!=`object`)return t;let n=Object.fromEntries(Object.entries(t).map(([t,n])=>[t,q(e,n)])),{[C]:r,[w]:i,...a}=n,o=typeof r==`string`?e.content[r]:void 0;if(o!==void 0)return Object.keys(a).length===0?o:{...a,content:o};let s=typeof i==`string`?e.content[i]:void 0;if(s===void 0)return n;let c=q(e,JSON.parse(s));return Object.keys(a).length===0?c:c&&typeof c==`object`&&!Array.isArray(c)?{...c,...a}:n}export{q as n,K as t};
1
+ import{$n as e,C as t,H as n,Ot as r,Qn as i,S as a,U as o,Xn as s,Yn as c,qt as l,w as u}from"./shaped-data-BRffby3g.js";var d=/^data:([^;,]+);base64,/;function f(e){if(typeof(e.mime_type??e.mimeType)==`string`&&typeof e.data==`string`)return`data`;if(typeof e.media_type==`string`&&typeof e.b64_json==`string`)return`b64_json`}var p=`sha256`,m=`text_sha256`;async function h(t){let n=await e(t);return n?{kind:p,hash:n.hash}:{kind:m,hash:await i(t)}}async function g(e){let t=d.exec(e);if(!t)return e;let{kind:n,hash:r}=await h(e.slice(t[0].length));return`data:${t[1]};${n},${r}`}async function _(e){let t=f(e),n,r=await Promise.all(Object.entries(e).map(async([e,r])=>{if(e===t&&typeof r==`string`){let{kind:t,hash:i}=await h(r);return n=t,[e,i]}return[e,await v(r)]})),i=Object.fromEntries(r);return n&&(i.dataKind=n),i}function v(e){return typeof e==`string`?g(e):Array.isArray(e)?Promise.all(e.map(e=>v(e))):e&&typeof e==`object`?_(e):Promise.resolve(e)}function y(e,t){return t.reduce((e,t)=>r(e,t),e)}function b(e,t){return t.some(Boolean)?s(e,e=>y(e,t)):e}async function x(e,t){return b(await v(e),t)}var S=`https://github.com/open-telemetry/semantic-conventions-genai/tree/8ffdf56`,C=`content_sha256`,w=`json_sha256`,T=[`gen_ai.usage.`,`theorem.usage.`],E={"theorem.upstream.row":`upstreamLog`,"theorem.wire.request":`outboundWire`,"theorem.guardrail":`guardrailDecisions`},D=`raw`,O=`match`,k=[`injection`,`tool_instructions`];function A(e,t){return e===!0||e!==!1&&e[t]}function j(e,{scrub:t,detect:r}){let{sensitive:i,injection:a}=t;return l(e,[...i?o(e,c,i,r):[],...A(i,`host`)?n(e,r):[],...a?o(e,k,a,r):[]])}async function M(e,t){let n=await i(e);return t.content[n]=e,t.known.set(e,n),n}function N(e,t){let{[t]:n,...r}=e;return r}async function P(n,r){if(t(n)){let e=y(j(n.$content,r),r.canaries);return{...N(n,`$content`),[C]:await M(e,r)}}if(a(n)){let t=N(n,`$bytes`),r=await e(n.$bytes);return r?{...t,content_sha256:r.hash,bytes:r.bytes}:{...t,invalid_base64:!0,text_sha256:await i(n.$bytes)}}return u(n)?n:await R(n,e=>P(e,r))}function F(e,t){return typeof e==`string`?t(e):Array.isArray(e)?e.map(e=>F(e,t)):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,F(n,t)])):e}function I(e,t){return F(e,e=>{let n=j(e,t),r=t.known.get(n);return r?{[C]:r}:n})}async function L(e,t){if(u(e)){let n=await x(e.$json,t.canaries),r=JSON.stringify(I(n,t)),a=await i(r);return t.content[a]=r,{...N(e,`$json`),[w]:a}}return await R(e,e=>L(e,t))}async function R(e,t){if(Array.isArray(e))return await Promise.all(e.map(t));if(e&&typeof e==`object`){let n=await Promise.all(Object.entries(e).map(async([e,n])=>[e,await t(n)]));return Object.fromEntries(n)}return e}async function z(e,t){let n=await Promise.all(Object.entries(e).map(async([e,n])=>[e,await t(n)]));return Object.fromEntries(n)}async function B(e,t){let n=await Promise.all(e.events.map(async e=>({...e,attributes:await z(e.attributes,t)})));return{...e,attributes:await z(e.attributes,t),events:n}}function V(e,t){return t.usage?e:Object.fromEntries(Object.entries(e).filter(([e])=>!T.some(t=>e.startsWith(t))))}function H(e){return e.map(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return e;let{[O]:t,...n}=e;return n})}function U(e,t){let n=E[e.name];if(n&&!t[n])return;if(e.name===`theorem.grounding`&&!t.evidenceRaw){let{[D]:t,...n}=e.attributes;return{...e,attributes:n}}let{hits:r}=e.attributes;return e.name===`theorem.guardrail`&&!t.guardrailMatchPreview&&Array.isArray(r)?{...e,attributes:{...e.attributes,hits:H(r)}}:e}function W(e,t){return{...e,attributes:V(e.attributes,t),events:e.events.flatMap(e=>U(e,t)??[])}}function G(e){return Object.entries(e).flatMap(([e,t])=>t?[e]:[])}async function K(e){let{policy:t}=e,n={scrub:t.scrub,detect:t.detect,canaries:A(t.scrub.canary,`theorem`)?e.canaries??[]:[],content:{},known:new Map},r=e.spans.map(e=>W(e,t.include)),[i]=r;i&&(i.attributes={...i.attributes,"theorem.record.include":G(t.include),"theorem.record.scrub":G(t.scrub)});let a=await Promise.all(r.map(e=>B(e,e=>P(e,n)))),o=await Promise.all(a.map(e=>B(e,e=>L(e,n))));return{v:3,schemaUrl:S,resource:{...t.resource},...e.metadata?{metadata:e.metadata}:{},spans:o,content:n.content}}function q(e,t){if(Array.isArray(t))return t.map(t=>q(e,t));if(!t||typeof t!=`object`)return t;let n=Object.fromEntries(Object.entries(t).map(([t,n])=>[t,q(e,n)])),{[C]:r,[w]:i,...a}=n,o=typeof r==`string`?e.content[r]:void 0;if(o!==void 0)return Object.keys(a).length===0?o:{...a,content:o};let s=typeof i==`string`?e.content[i]:void 0;if(s===void 0)return n;let c=q(e,JSON.parse(s));return Object.keys(a).length===0?c:c&&typeof c==`object`&&!Array.isArray(c)?{...c,...a}:n}export{q as n,K as t};
@@ -0,0 +1,3 @@
1
+ import{C as e,Kt as t,M as n,Qt as r,Tn as i,bn as a,h as o,j as s,n as c,p as l,t as u,y as d,z as ee}from"./tool-schema-C7lMQU0w.js";import{An as te,Cn as ne,Hn as re,Nn as f,Pn as ie,Sn as ae,Wn as oe,an as se,br as p,gr as m,pn as h,yn as g}from"./shaped-data-BRffby3g.js";import{a as _,r as v}from"./live-ingress-OuSlQ6q7.js";var ce=[{id:`identity`,profilePath:`identity`,role:`root`,optional:!1,editor:`structural`,label:`Identity`,ownsFields:[`profile.id`,`profile.type`]},{id:`models`,profilePath:`models`,role:`spine`,optional:!1,editor:`structural`,label:`Models`,ownsFields:[`profile.defaultModel`,`profile.allowModelSelect`,`profile.maxSteps`,`providerContinuation`]},{id:`modelBinding`,profilePath:`models.*`,role:`branch`,parent:`models`,optional:!1,editor:`structural`,label:`Model binding`},{id:`decision`,profilePath:`decision`,role:`spine`,optional:!1,editor:`structural`,label:`Decision`,ownsFields:[`inputs`]},{id:`image`,profilePath:`image`,role:`spine`,optional:!1,editor:`structural`,label:`Image`},{id:`speech`,profilePath:`speech`,role:`spine`,optional:!1,editor:`structural`,label:`Speech`},{id:`live`,profilePath:`live`,role:`spine`,optional:!1,editor:`structural`,label:`Live`},{id:`tools`,profilePath:`tools`,role:`spine`,optional:!1,editor:`structural`,label:`Tools`},{id:`toolSpec`,profilePath:`tools.allow`,role:`branch`,parent:`tools`,optional:!0,editor:`structural`,label:`Tool`},{id:`inputs`,profilePath:`inputs`,role:`spine`,optional:!1,editor:`structural`,label:`Inputs`},{id:`outputs`,profilePath:`outputs`,role:`spine`,optional:!0,editor:`structural`,label:`Outputs`},{id:`turnBehaviour`,profilePath:`turnBehaviour`,role:`spine`,optional:!0,editor:`structural`,label:`Turn behaviour`},{id:`guardrails`,profilePath:`guardrails`,role:`spine`,optional:!0,editor:`structural`,label:`Guardrails`},{id:`observability`,profilePath:`observability`,role:`spine`,optional:!0,editor:`structural`,label:`Observability`},{id:`labels`,profilePath:`labels`,role:`spine`,optional:!0,editor:`structural`,label:`Labels`}],le={identity:te,inputs:f(`inputs`).filter(e=>e!==`decision`)},y=ce.map(e=>({...e,profileTypes:le[e.id]??f(e.profilePath)}));function ue(e){return y.find(t=>t.id===e)}function de(e){return e.modelBindings.length>1}function fe(e){return e.modelBindings.some(t=>t.provider!==`local`&&!n(e.providers,t).keySlot)}function b(e,t){let r={provider:t.provider,keySlot:t.keySlot||e.models.key,fallbackKeySlot:t.fallbackKeySlot||e.models.fallbackKey},i=n(e.providers,r);return{...i,given:{keySlot:!!i.keySlot&&!r.keySlot,fallbackKeySlot:!!i.fallbackKeySlot&&!r.fallbackKeySlot}}}function pe(e,t){let n=new Set(e.modelBindings.filter(n=>{let r=b(e,n);return r.keySlot===t||r.fallbackKeySlot===t}).map(e=>e.provider));return e.providers.filter(e=>n.has(e.id))}function me(e){let t=e.efforts.map(({alias:e})=>e.trim()).filter(Boolean);return new Set(t).size>1}function he(e){return e.attachmentsAccept.length>0||e.voiceAccept.length>0}var ge=h,x=[{name:`operationTimeoutMs`,label:`Call timeout`,units:`ms`,isTimer:!0},{name:`connectTimeoutMs`,label:`Connect timeout`,units:`ms`,isTimer:!0},{name:`liveStepTimeoutMs`,label:`Live step timeout`,units:`ms`,isTimer:!0},{name:`maxWireRecordBytes`,label:`Wire record`,units:`bytes`,isTimer:!1},{name:`maxWireResponseBytes`,label:`Wire response`,units:`bytes`,isTimer:!1},{name:`maxEventBytes`,label:`Event`,units:`bytes`,isTimer:!1},{name:`maxStepBytes`,label:`Step`,units:`bytes`,isTimer:!1},{name:`maxStepEvents`,label:`Step events`,units:`events`,isTimer:!1},{name:`maxPendingToolCalls`,label:`Tool calls`,units:`calls`,isTimer:!1}],S=2147483647,C={compactMaxTokens:32e3,compactAt:.75,compactKeep:4},w={"continue.instruction":`turnBehaviour`,"canary.bind_note":`guardrails`,"quota.exhausted":`guardrails`,"repair.default_guidance":`outputs`,"egress.default_repair_guidance":`guardrails`,"egress.refusal":`guardrails`};function T(e){return`${e}-${crypto.randomUUID().slice(0,8)}`}function E(e){return{key:T(`model`),modelId:`fast`,protocol:`openRouterOpenAi`,provider:`openrouter`,apiId:``,options:{},timeoutMs:null,efforts:[],defaultEffort:``,allowEffortSelect:!1,summaries:null,maxOutputTokens:null,temperature:null,builtInTools:[],...e}}var D=`Studio stub tool — returns a fixed result.`;function O(e){return{key:T(`tool`),toolName:`my_tool`,toolType:`function`,description:D,category:`studio`,access:g[0],permission:ne[0],loadTier:ae[0],paths:[`*`],inputJson:u,outputJson:c,...e}}function k(e,t,n){return(!e.description.trim()||e.description===D)&&n?{agentKey:t,description:`Asks ${n} and returns its answer.`}:{agentKey:t}}function A(){return{name:``,kind:`words`,pattern:``,flags:``,words:[]}}function j(){return{key:``,label:``,at:p(m,()=>`ignore`),patterns:[A()],hint:``}}function M(){let e=i(void 0);return{canaryBindNote:``,detect:p(ie,t=>({...e.detect[t]})),sources:Object.fromEntries(re.map(e=>[e,{theorem:!0,patterns:[],hint:``}])),own:[],quotaEnabled:!1,quotaPerDay:null,quotaMessage:``,allow:{ungiven_images:{hosts:[],fromTools:!0},ungiven_links:{hosts:[],fromTools:!0}},innocentNames:[],blockedReplyOnBlock:``,blockedReplyMaxRetries:null,egressRepairGuidance:``,egressRefusal:``,allowPrivateNetworks:!1,allowedHosts:[],allowedSchemes:[],taintAfterRemoteRead:``,taintRemoteDestination:``}}function N(){let e=_({});return{writeTo:l,destination:l,sampleRate:e.sampleRate,include:{...e.include},scrub:{sensitive:e.scrub.sensitive,injection:e.scrub.injection,canary:e.scrub.canary},retainForDays:null,rotateAfterMiB:null,resourceJson:``}}function P(e){return e.map(([e,t])=>({key:T(`criterion`),label:e,text:t}))}function F(){return{contract:`guardrails.tool_call.v1`,maxStateBytes:null,questions:[{key:T(`question`),id:`verdict`,type:`choice`,instructions:`Given what the user asked for and what the call would do, should it run?`,criteria:P([[`allow`,`Safe, and what the user asked for.`],[`flag`,`Probably fine, but unusual or sensitive enough for a person to look first.`],[`block`,`Harmful, or clearly beyond what the user asked for.`]])},{key:T(`question`),id:`risk`,type:`score`,instructions:`How much harm would this call do if it were wrong?`,criteria:P([[``,`Low: reversible, and affects only the user.`],[``,`High: hard to undo, or affects other people or money.`]])}],images:[]}}var I=JSON.stringify({context:`The user asked the agent to tidy up old screenshots on their desktop.`,tool_call:{name:`delete_files`,path:`~/Documents`,recursive:!0},outcome:`Would delete 1,284 files, including tax_return_2025.pdf.`},null,2),L=JSON.stringify(`The user asked to tidy screenshots. The proposed call recursively deletes 1,284 files, including a tax return.`),_e=`To clear your desktop, select the screenshots and move them to the Trash. Empty the Trash to delete them for good.(Screen captures save to the desktop by default. You can change where they go in the Screenshot app's Options menu.(Press Command-Shift-5 to record the screen or capture a window. Recordings are saved as movie files next to your screenshots.(Stacks group desktop files by kind, date or tag, so a cluttered desktop folds into a few piles you can open one at a time.(Deleted files stay in the Trash for 30 days. Drag a file out of the Trash to put it back where it was.(When your disk is almost full, open Storage settings and review the largest files. Old downloads and installers are safe to remove.(Offloading unused apps frees space and keeps their documents. Reinstalling an app brings its data back.(Photos you have backed up can be optimised so the originals live in the cloud and smaller copies stay on the device.(Your plan renews on the same date each month. You can see the next charge under Billing, then Upcoming invoices.(To get a refund, open the invoice and choose Request refund. Charges from the last 14 days are refunded in full.(Update your card under Billing, then Payment methods. The new card is used for the next renewal, not for past invoices.(Annual plans cost two months less than paying monthly. Switching mid-term credits the unused months to the new plan.(Invoices are emailed as PDFs and list your company name and tax number. Edit those details before the invoice is issued.(Turn on two-step verification under Security. You will be asked for a code from your authenticator app each time you sign in on a new device.(If you forget your password, choose Forgot password on the sign-in page. The reset link expires after one hour.(Review signed-in devices under Security and sign out any you don't recognise. This ends their sessions immediately.(Passkeys replace your password with your fingerprint or face. Create one under Security, then Passkeys.(To close your account, export your data first. Closing deletes your workspace after a 30-day grace period.(Share a folder by choosing Share, then entering an email address. Viewers can read; editors can change and delete.(Public links work for anyone who has them. Set an expiry date, or turn the link off to stop sharing at once.(Transfer ownership of a folder before you leave a team, or its contents will be archived with your account.(Lisbon has mild, wet winters and warm, dry summers. Expect highs near 28 °C in August.(The best months for the Algarve coast are May, June and September, when the beaches are warm and the crowds are thin.(Trams in Lisbon climb the steep hills of Alfama and Graça. Line 28 is the famous one, and the busiest.(For a crisp pizza base, preheat the oven and the baking tray together at the highest setting for at least thirty minutes.(Rest steak for five minutes after cooking so the juices settle back into the meat instead of running onto the board.`.split(`(`).join(`
2
+
3
+ `),ve=`How do I delete every screenshot on my desktop?`;function ye(e,t=`choice`){let n=q(`question`,e.decision.questions.map(e=>e.id),e=>`question_${e}`);return{key:T(`question`),id:n,type:t,instructions:``,criteria:B(t)}}function be(e,t,n){let r=t.replace(/\.[^.]*$/,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``)||`image`,i=q(r,e.decision.images.map(e=>e.name),e=>`${r}_${e}`);return{key:T(`image`),name:i,...n}}function xe(e){let t=q(`slot`,e.map(e=>e.name),e=>`slot_${String(e)}`);return{key:T(`slot`),name:t,label:``,choices:[z(),z()]}}function R(){return{key:T(`condition`),name:``,values:[]}}function z(){return{key:T(`choice`),value:``,description:``}}function Se(){return{key:T(`criterion`),label:``,text:``}}function B(e){return e===`noul`||e===`box`?[]:P(e===`choice`?[[`yes`,``],[`no`,``]]:[[``,``],[``,``]])}function Ce(){return{identity:{agentId:``,profileType:``,handle:``,system:``,conditions:[]},included:[`observability`,`labels`],models:{defaultModel:``,allowModelSelect:!1,maxSteps:null,key:``},modelBindings:[],providers:[...e],tools:{t2Loader:``,parallel:!1},toolSpecs:[],inputs:{text:!0,attachmentsAccept:[],voiceAccept:[],maxFiles:null,maxBytes:null,maxTurnBytes:null,limitsByMime:{},slots:[],contextFrom:[],contextMaxChars:null},outputs:{mode:`text`,schemaId:``,schemaJson:``,streamMode:``,streamThoughts:!0,validationEnabled:!1,maxRetries:null,itemRules:{},repairGuidance:``},turnBehaviour:{resumeEnabled:!1,allowContinue:[],autoContinue:[],maxContinues:null,continueInstruction:``,allowSteering:r({type:`text`}),atStepLimit:`stop`},guardrails:M(),observability:N(),image:{aspectRatio:``,resolution:``,mimeType:``,quality:``,background:``,n:null,seed:null,outputCompression:null,includeText:!1,references:[]},speech:{voice:``,style:``,speed:null,format:``},live:{ingressAudio:v(`audio`),ingressVideo:v(`video`),ingressText:v(`text`),voice:``,sessionResumption:!1,greeting:``,resumedPrompt:``,resumedAfterMs:null,contextCompression:!1,compressionTriggerTokens:null,compressionTargetTokens:null,transcriptionInput:!1,transcriptionOutput:!1,vadActivityHandling:``,vadStartSensitivity:``,vadEndSensitivity:``,vadPrefixPaddingMs:null,vadSilenceDurationMs:null},decision:F(),labels:{}}}var we=new Set([`guardrails`]);function V(e,t){return e.profileTypes.includes(t)&&!(t===`decision`&&we.has(e.id))}function H(e){let t=e.identity.profileType;if(!t)return[`identity`];let n=new Set(e.included);return y.filter(e=>e.role!==`branch`&&V(e,t)&&(!e.optional||n.has(e.id))).map(e=>e.id)}function U(e,t){let n=e.identity.profileType;return n!==``&&f(t).includes(n)}function Te(e){return U(e,`identity.system`)&&oe(e.guardrails.detect,`canary_leak`)}function Ee(e){let n=e.identity.profileType;return n!==``&&t.includes(n)}function W(e){let t=e.identity.profileType;return t?y.filter(n=>n.role===`spine`&&n.optional&&V(n,t)&&!e.included.includes(n.id)).map(e=>e.id):[]}function De(e){return{...e,attachmentsAccept:e.attachmentsAccept.filter(e=>a(se,e)),voiceAccept:[]}}function Oe(e){return{...e,text:!1,attachmentsAccept:[],voiceAccept:e.voiceAccept.length?e.voiceAccept:[`audio/*`]}}function ke(e,t,n){let r=e.modelBindings.find(e=>e.key===t);return r?{...e,models:n.modelId!==void 0&&e.models.defaultModel===r.modelId?{...e.models,defaultModel:n.modelId}:e.models,modelBindings:e.modelBindings.map(e=>e.key===t?{...e,...n}:e)}:e}function G(e,t){if(t.some(t=>t.modelId===e))return e;let[n,...r]=t;return n&&!r.length?n.modelId:``}function Ae(e,t){if(!e.modelBindings.find(e=>e.key===t))return e;let n=e.modelBindings.filter(e=>e.key!==t);return{...e,models:{...e.models,defaultModel:G(e.models.defaultModel,n)},modelBindings:n}}function K(e,t){let n=e.identity.profileType,r=n&&n!==`host`?n:`text`,i=e.modelBindings.map(e=>e.modelId),a=d(r,t),o=q(a.modelId,i,e=>`${a.modelId}${e}`);return E({...a,modelId:o})}function je(e){return O({toolName:q(`my_tool`,e.toolSpecs.map(e=>e.toolName),e=>`my_tool_${e}`)})}function q(e,t,n){let r=new Set(t),i=e;for(let e=2;r.has(i);e++)i=n(e);return i}function Me(e,t,n){if(t===`host`)return{...e,identity:{...e.identity,profileType:t}};let r=e.modelBindings.filter(r=>{let i=s(e.providers,t,r),a=e.providers.find(e=>e.id===r.provider);return ee(a,t,r.protocol)&&!Fe(n,t,i)}),i={...e,identity:{...e.identity,profileType:t},modelBindings:r},a=r.length?r:[K(i,n?.start)],c=!e.models.key&&fe({...i,modelBindings:a}),l=t===`speech`&&!e.speech.voice.trim()&&a.some(n=>o(s(e.providers,t,n)));return{...i,inputs:t===`image`?De(e.inputs):t===`transcription`?Oe(e.inputs):e.inputs,...l?{speech:{...e.speech,voice:Ne}}:{},models:{...e.models,defaultModel:G(e.models.defaultModel,a),key:c?Ie:e.models.key},modelBindings:a}}var Ne=`Kore`,Pe=[`text`,`image`,`speech`,`transcription`,`live`,`decision`];function Fe(e,t,n){if(!e)return!1;let r=t=>e.models(t,n.definition).some(e=>e.id===n.apiId.trim());return!r(t)&&Pe.some(e=>e!==t&&r(e))}var Ie=`slot_a`;function Le(e,t){return W(e).includes(t)?{...e,included:[...e.included,t]}:e}function Re(e,t){return{...e,included:e.included.filter(e=>e!==t)}}function J(e){return`modelBinding:${e}`}var Y=`toolSpec:`;function X(e){return`${Y}${e}`}function Z(e){return e.startsWith(Y)?e.slice(9):void 0}var Q=`provider:`;function ze(e){return`${Q}${e}`}function Be(e){return e.startsWith(Q)?e.slice(9):void 0}var Ve=new Map(y.map(e=>[e.id,e.label]));function He(e){return Ve.get(e)??e}function Ue(e,t){let[n,r]=t.split(`:`,2);if(n===`modelBinding`&&r!==void 0)return e.modelBindings.some(e=>e.key===r)?{facet:n,key:r}:void 0;let i=Z(t);if(i!==void 0)return e.toolSpecs.some(e=>e.key===i)?{facet:`toolSpec`,key:i}:void 0;let a=H(e);if(r===void 0&&a.includes(t))return{facet:t}}function We(e,t){return t===`models`?e.modelBindings.map(e=>({id:J(e.key),ref:{facet:`modelBinding`,key:e.key},label:e.modelId.trim()||`Unnamed model`,children:[]})):t===`tools`?$(e.toolSpecs):[]}function $(e){return e.map(e=>({id:X(e.key),ref:{facet:`toolSpec`,key:e.key},label:e.toolName.trim()||`Unnamed tool`,children:[]}))}function Ge(e){let t=H(e).filter(e=>e!==`identity`).map(t=>({id:t,ref:{facet:t},label:He(t),children:We(e,t)}));return{id:`identity`,ref:{facet:`identity`},label:e.identity.agentId.trim()||`Unnamed agent`,children:t}}export{B as A,Te as B,H as C,W as D,q as E,j as F,b as G,Me as H,A as I,he as J,me as K,xe as L,be as M,ye as N,Le as O,K as P,z as R,U as S,Re as T,Ee as U,Ae as V,ke as W,y as X,pe as Y,ue as Z,S as _,Ge as a,E as b,$ as c,ve as d,_e as f,ge as g,x as h,Ue as i,Se as j,R as k,C as l,w as m,Be as n,Z as o,L as p,de as q,ze as r,X as s,J as t,I as u,k as v,T as w,O as x,Ce as y,je as z};
@@ -1,2 +1,2 @@
1
- import{Ht as e,Kn as t,Vn as n}from"./tool-schema-6RWBAqGO.js";import{c as r}from"./host-patterns-F-KZIzkF.js";import{Lr as i,M as a,Vn as o}from"./shaped-data-7q5Be8sp.js";import{I as s}from"./reader-747-Cvu8.js";import{M as c}from"./browser-connection-CuWeoI9s.js";import{r as l}from"./encode-files-DoLGXgup.js";function u(e,t){let n=typeof t==`string`?t.trim():``;if(!n)throw new r(`request`,`A typed credential must be a non-empty string`);if(e===`bearer`)return{type:`bearer`,token:n};if(e===`api_key`)return{type:`api_key`,key:n};throw new r(`request`,`A '${e}' sign-in takes no typed credential; the host's callback saves it`)}function d(e,t){if(!e)throw new r(`request`,`a typed credential answers only a sign-in gate`);return{slot:e.slot,credential:u(e.authType,t)}}function ee(e,t){if(t!==void 0){if(!Number.isFinite(t)||t<=0)throw new r(`config`,`${e} gateTtlMs must be a positive number of milliseconds; got ${t}.`);return t}}function te(e,t,n){return n!==void 0&&t-e>=n}var f=[`approve`,`deny`,`abandon`];function p(e,t=!1){return e.decision===`approve`?{granted:!0,...e.edited?{edited:e.edited}:{},...t?{signIn:t}:{}}:{granted:!1,cause:e.decision===`deny`?`declined`:`abandoned`,...t?{signIn:t}:{}}}function m(e,t,n){return n!==`session_consent`||e.includes(t)?[...e]:[...e,t]}function ne(e,t,n){let{callId:i,decision:a,input:o,secret:s,page:c}=e;if((o!==void 0||s!==void 0||c!==void 0)&&a!==`approve`)throw new r(`request`,`only an approval takes edited input, a secret, or a page answer (call ${i})`);if(a!==`approve`)return{resume:p({decision:a},t.auth!==void 0),input:t.arguments,sessionPermissions:[...n]};let l=s===void 0?void 0:d(t.auth,s);return{resume:{...p(o===void 0?{decision:a}:{decision:a,edited:{from:t.arguments}},t.auth!==void 0),...t.gateKind?{gateKind:t.gateKind}:{}},input:o??t.arguments,sessionPermissions:m(n,t.name,t.permission),...l?{typed:l}:{},...c?{page:c}:{}}}var re={'"':`"`,"\\":`\\`,"/":`/`,b:`\b`,f:`\f`,n:`
2
- `,r:`\r`,t:` `};function h(e,t){let n=``,r=t+1;for(;r<e.length;){let t=e.charAt(r);if(t===`"`)return{text:n,end:r+1};if(t!==`\\`){n+=t,r++;continue}if(r+1>=e.length)break;let i=e.charAt(r+1);if(i===`u`){let t=e.slice(r+2,r+6);if(t.length<4)break;if(/^[0-9a-fA-F]{4}$/.test(t)){n+=String.fromCharCode(Number.parseInt(t,16)),r+=6;continue}}n+=re[i]??i,r+=2}return{text:n}}function g(e,t){let n=t;for(;/\s/.test(e.charAt(n));)n++;return n}function ie(e,t){if(e.charAt(t)===`"`){let n=h(e,t);return n.end===void 0?void 0:_(e,t,n.end)}let n=0;for(let r=t;r<e.length;r++){let i=e.charAt(r);if(i===`"`){let t=h(e,r).end;if(t===void 0)return;r=t-1}else if(i===`{`||i===`[`)n++;else if(i===`}`||i===`]`){if(n===0)return _(e,t,r);if(n--,n===0)return _(e,t,r+1)}else if(i===`,`&&n===0)return _(e,t,r)}}function _(e,t,n){try{return{value:JSON.parse(e.slice(t,n)),end:n}}catch{return}}function v(e){let t={},n=g(e,0);if(e.charAt(n)!==`{`)return t;for(n++;;){if(n=g(e,n),e.charAt(n)===`,`&&(n=g(e,n+1)),e.charAt(n)!==`"`)return t;let r=h(e,n);if(r.end===void 0||(n=g(e,r.end),e.charAt(n)!==`:`)||(n=g(e,n+1),n>=e.length))return t;let i=ie(e,n);if(!i)return e.charAt(n)===`"`&&(t[r.text]=h(e,n).text),t;t[r.text]=i.value,n=i.end}}function y(e,t){if(t.phase===void 0)return{name:t.name,callId:t.callId,...t.operationId?{operationId:t.operationId}:{},arguments:t.arguments,...t.reasoning?{reasoning:t.reasoning}:{},...t.stepId?{stepId:t.stepId}:{},artifacts:[]};if(e===void 0)throw new r(`bad_response`,`Tool event '${t.phase}' for call '${t.callId}' arrived before the call.`);if(e.callId!==t.callId||e.name!==t.name)throw new r(`bad_response`,i(`error.bad_response`));switch(t.phase){case`running`:{let{endedAt:n,outputDraft:r,...i}=e;return{...i,state:t,startedAt:t.at,...t.edited?{edited:t.edited}:{},...t.activity?{activity:t.activity}:{}}}case`complete`:case`error`:return{...b(e),state:t,endedAt:t.at,...t.activityPast?{activityPast:t.activityPast}:{}};case`cancel`:case`gate`:case`background`:return{...b(e),state:t,endedAt:t.at};case`draft`:return{...e,outputDraft:(e.outputDraft??``)+t.text};case`artifact`:return{...e,artifacts:[...e.artifacts,t.artifact]};case`progress`:return se(e,t.data);case`dispatch`:case`trace`:case`warning`:return e}}function b(e){let{outputDraft:t,...n}=e;return n}function x(e,t){return{arguments:{},artifacts:[],...e,name:t.name,callId:t.callId,draft:(e?.draft??``)+t.text}}function S(e,t){if(t.type===`tool_draft`){e.set(t.callId,x(e.get(t.callId),t));return}let{tool:n}=t,r=n.operationId??n.callId;n.phase===void 0&&e.get(n.callId)?.draft!==void 0&&e.delete(n.callId),e.set(r,y(e.get(r),n))}function ae(e){let t=new Map;for(let n of e)(n.type===`tool_draft`||n.type===`tool`)&&S(t,n);return[...t.values()]}function oe(e){if(typeof e!=`object`||!e||!(`agent`in e)||!(`event`in e))return;let{event:n}=e;if(n?.type!==`tool`&&n?.type!==`tool_draft`)return;let r=t.safeParse(n);return r.success?r.data:void 0}function se(e,t){let n=oe(t),r=n&&ce(e.steps??[],n);return r?{...e,steps:r}:e}function ce(e,t){let n=new Map(e.map(e=>[e.operationId??e.callId,e]));if(t.type===`tool`&&t.tool.phase!==void 0){let e=n.get(t.tool.operationId??t.tool.callId);if(e?.callId!==t.tool.callId||e.name!==t.tool.name)return}return S(n,t),[...n.values()]}function le(e){return(e.state?.phase===`gate`?e.state.gate.preparedArguments:void 0)??e.edited?.to??e.arguments}function ue(e,t){return e.type!==`tool`||e.tool.callId!==t?!1:e.tool.phase===`complete`||e.tool.phase===`error`||e.tool.phase===`background`}var de={avif:`image/avif`,gif:`image/gif`,heic:`image/heic`,heif:`image/heif`,jpeg:`image/jpeg`,jpg:`image/jpeg`,png:`image/png`,svg:`image/svg+xml`,webp:`image/webp`,mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,ogv:`video/ogg`,mp3:`audio/mpeg`,m4a:`audio/mp4`,ogg:`audio/ogg`,wav:`audio/wav`};function fe(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n<=0||n===t.length-1?void 0:de[t.slice(n+1).toLowerCase()]}function pe(e){let t=e.trim();if(t.length===0)return;let n;try{n=new URL(t)}catch{return}if(n.protocol!==`http:`&&n.protocol!==`https:`)return;let r=fe(n.pathname);if(r)return{url:n.href,mimeType:r}}var me=/^(.*)\/thumb(\/.+\/([^/]+))\/(\d+)px-\3(?:\.[a-z0-9]+)?$/i;function he(e){let t=new URL(e),n=t.hostname.split(`.`).slice(-2).join(`.`);for(let e of[...t.searchParams.keys()])e.startsWith(`utm_`)&&t.searchParams.delete(e);let r=me.exec(t.pathname);return{key:`${n}${r?`${r[1]}${r[2]}`:t.pathname}${t.search}`,width:r?Number(r[4]):1/0}}function ge(e){let t=new Map,n=[],r=e=>{if(typeof e==`string`){let r=pe(e);if(!r)return;let i=he(r.url),a=t.get(i.key);if(!a){t.set(i.key,{index:n.length,largest:i.width,smallest:i.width}),n.push(r);return}let o=n[a.index];i.width>a.largest?(a.largest=i.width,n[a.index]={...o,url:r.url,previewUrl:o.previewUrl??o.url}):i.width<a.smallest&&(a.smallest=i.width,n[a.index]={...o,previewUrl:r.url})}else if(Array.isArray(e))for(let t of e)r(t);else if(typeof e==`object`&&e)for(let t of Object.values(e))r(t)};return r(e),n}var C=0;function w(e){return e===`user`?`user-${globalThis.crypto.randomUUID()}`:(C+=1,`${e}-${String(C)}`)}function T(e,t){return e?.kind===t}function E(e,t,n,r){let i=e.at(-1);T(i,t)?i.text+=n:e.push({id:w(r),kind:t,text:n})}function D(e,t){let n=e.at(-1),r=n?.kind===`text`||n?.kind===`thought`;e.splice(r?e.length-1:e.length,0,t)}function O(e,t){return e.find(e=>e.kind===`tool`&&e.id===t)}function k(e,t){let n=`tool-${t.operationId??t.callId}`,r=O(e,n),i=y(r?.tool,t);if(r){r.tool=i;return}let a=t.phase===void 0?O(e,`tool-${t.callId}`):void 0;a?.tool.draft===void 0?e.push({id:n,kind:`tool`,tool:i}):(a.id=n,a.tool=i)}function A(e,t){let n=`tool-${t.callId}`,r=O(e,n),i=x(r?.tool,t);r?r.tool=i:e.push({id:n,kind:`tool`,tool:i})}function j(e){return e.findLast(e=>e.kind===`structured`&&e.draft!==void 0)}function M(e,t,n){let r=j(e),i=(r?.draft??``)+t;r?(r.draft=i,r.value=v(i)):e.push({id:w(n),kind:`structured`,value:v(i),draft:i})}function N(e,t,n){let r=j(e);r?(r.value=t,delete r.draft):e.push({id:w(n),kind:`structured`,value:t})}function P(e,t){return e.type===t.type?e.placeId&&t.placeId?e.placeId===t.placeId:e.uri===t.uri:!1}function F(e,t,n){let r=e.find(e=>e.kind===`citation`&&e.callId===t.callId),i=r?[...r.sources]:[];for(let e of t.sources)i.some(t=>P(t,e))||i.push(e);r?r.sources=i:e.push({id:w(n),kind:`citation`,sources:i,...t.callId===void 0?{}:{callId:t.callId}})}function I(e,t,n,r){if(t.phase===`complete`&&t.output!==void 0)for(let i of ge(t.output))r.has(i.url)||(r.add(i.url),e.push({id:w(n),kind:`media`,mimeType:i.mimeType,url:i.url,...i.previewUrl?{previewUrl:i.previewUrl}:{}}))}function L(e,t){return e.messages.flatMap(e=>{if(e.role!==`user`)return[];let n=e.parts??[],r=[e.content??``,...n.map(e=>`text`in e?e.text:``)].join(``).trim();return[...r?[{id:w(t),kind:`user-text`,text:r}]:[],...n.flatMap(e=>`text`in e?[]:[{id:w(t),kind:e.type===`audio`?`user-voice`:`user-attachment`,name:e.mimeType,mimeType:e.mimeType,...`data`in e?{sizeBytes:Math.floor(e.data.length*3/4),data:e.data}:{sizeBytes:0}}])]})}function R(e,t=`user`){let n=[],r=e.text?.trim();r&&n.push({id:w(t),kind:`user-text`,text:r});for(let r of e.attachments??[])n.push({id:w(t),kind:`user-attachment`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});for(let r of e.voice??[])n.push({id:w(t),kind:`user-voice`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});return n}function _e(e,t){switch(e.type){case`media`:return e.media?{id:w(t),kind:`media`,mimeType:e.media.mimeType,data:e.media.data}:void 0;case`grounding`:return{id:w(t),kind:`grounding`,grounding:e.grounding};case`evidence`:return{id:w(t),kind:`evidence`,evidence:e.evidence};case`error`:return e.error?{id:w(t),kind:`error`,message:e.error}:void 0;case`done`:return{id:w(t),kind:`turn-done`,stop:e.stop,tokens:e.tokens,interactionId:e.interactionId,compaction:e.compaction!==void 0};default:return}}function ve(e,t,n){if(t.phase===`complete`)for(let r of t.parts??[])r.type!==`text`&&e.push({id:w(n),kind:`media`,mimeType:r.mimeType,...`data`in r?{data:r.data}:{url:r.uri}})}function z(e,t={}){let r=t.idPrefix??`turn`,i=t.showThoughts??!0;C=0;let a=[],o=new Set;for(let t of n(e))switch(t.type){case`thought`:i&&t.text&&E(a,`thought`,t.text,r);break;case`text`:t.text&&E(a,`text`,t.text,r);break;case`tool_draft`:A(a,t);break;case`tool`:k(a,t.tool),I(a,t.tool,r,o),ve(a,t.tool,r);break;case`structured_draft`:M(a,t.text,r);break;case`structured`:N(a,t.structured,r);break;case`citation`:F(a,t,r);break;case`guardrail`:D(a,{id:w(r),kind:`guardrail`,guardrail:t.guardrail});break;case`stage`:for(let e of t.injected??[])a.push(...L(e,r));break;default:{let e=_e(t,r);e&&a.push(e)}}return a}function ye(e,t,n={}){return[...R(e,`user`),...z(t,n)]}function be(e){if(!e)return o;let{detect:t,patterns:n}=e;if(!n)return t;let r=Object.fromEntries(Object.entries(n).map(([e,{theorem:t}])=>[e,{theorem:t,matchers:[]}]));return{...t,sources:r}}function xe(e,t){if(e.text===void 0)return e;let n=a(e.text,`user`,be(t));return{...e,text:n.text??e.text}}function B(e,t,n){let r=s(e,t);if(!r.ok)return{ok:!1,issues:r.issues};let i=xe(t,n);return{ok:!0,draft:i,blocks:R(i)}}function V(e,t){if(t)return e.models[t]}function H(e){return!!(e.allowModelSelect&&Object.keys(e.models).length>=2)}function U(e,t){let n=V(e,t);return n?.allowEffortSelect?Object.keys(n.efforts??{}).length>=2:!1}function W(e,t){let n=V(e,t);if(!n?.efforts)return;let r=n.defaultEffort?.trim();return r&&n.efforts[r]?r:Object.keys(n.efforts)[0]}function Se(e){return H(e)?Object.entries(e.models).map(([e,t])=>({id:e,label:t.apiId})):[]}function Ce(e,t){if(!U(e,t))return[];let n=V(e,t);return n?.efforts?Object.entries(n.efforts).map(([e,t])=>({alias:e,level:t})):[]}function G(e){let t=new Set;for(let n of e)if(n.type===`tool`&&n.tool.phase===`complete`)for(let e of c(n.tool.output)??[])t.add(e);return[...t]}function K(t){let n=e(t,e=>e.type===`done`&&e.tools!==void 0);return n?.type===`done`?n.tools:void 0}function we(t){let n=K(t)?.visible??[],r=e(t,e=>e.type===`done`&&e.steps!==void 0);return{promoted:[...new Set([...n,...G(t)])],stepsTaken:r?.type===`done`?r.steps??0:0}}function q(e){return e?.streaming?.streamThoughts!==!1}function J(e){return e.defaultModel??Object.keys(e.models)[0]}function Te(e,t,n){let r=t.model!==void 0&&Object.hasOwn(e.models,t.model)&&(n===void 0||t.model!==J(n))?t.model:J(e),i=r===void 0?void 0:e.models[r]?.efforts;return{model:r,effort:r===t.model&&t.effort!==void 0&&i!==void 0&&Object.hasOwn(i,t.effort)&&(n===void 0||t.effort!==W(n,r))?t.effort:W(e,r)}}function Y(e){if(!e.operationId)throw new r(`request`,i(`session.gate_expired`));return e.operationId}function Ee(e,t){return t.selectedModel??J(e)}function X(e,t,n){let r=t.selectedEffort;if(!n||!Object.hasOwn(e.models,n))return r;let i=e.models[n];return i.allowEffortSelect?r??i.defaultEffort:r===W(e,n)?void 0:r}function Z(e,t){let n=Ee(e,t),r=e.allowModelSelect||n!==J(e)?n:void 0,i=X(e,t,n);return{...r?{model:r}:{},...i?{effort:i}:{}}}function De(e,t,n){return{name:n.name,input:n.input,...n.gateKind?{gateKind:n.gateKind}:{},sessionPermissions:n.sessionPermissions??t.sessionPermissions,...t.toolSnapshot?{snapshot:t.toolSnapshot}:{},...t.promotedToolIds.length?{promoted:[...t.promotedToolIds]}:{},...Z(e,t)}}function Q(e){return{...e.conversation?{conversation:e.conversation}:{},...e.turnId?{turnId:e.turnId}:{}}}function Oe(e,t,n,r={}){let i=(r.walkAway?.calls??[]).map(e=>({callId:e.callId,operationId:Y(e)}));return{...Q(r),...Z(e,t),input:n,...i.length?{abandon:i}:{},replay:{sessionPermissions:t.sessionPermissions}}}function ke(e,t,n,r={}){return{...Q(r),gateId:n.gateId,operationId:n.operationId,decision:n.decision,...n.secret===void 0?{}:{secret:n.secret},...n.page===void 0?{}:{page:n.page},replay:De(e,t,{...n,gateKind:n.gateKind??(t.gatedTool?.callId===n.gateId?t.gatedTool.gateKind:void 0)})}}function $(e,t){return B(e.inputs,t,e.guardrails)}function Ae(e,t,n,r=[]){return $(e,{...t.trim()?{text:t}:{},...n.length?{attachments:l(n)}:{},...r.length?{voice:l(r)}:{}})}function je(e,t){return z(t,{showThoughts:q(e.outputs)})}export{ae as C,ee as D,te as E,p as O,le as S,ne as T,B as _,Ae as a,y as b,q as c,K as d,W as f,H as g,Se as h,Y as i,m as k,G as l,Ce as m,Oe as n,$ as o,U as p,je as r,Te as s,ke as t,we as u,ye as v,f as w,ue as x,z as y};
1
+ import{Jn as e,Un as t,Wt as n}from"./tool-schema-C7lMQU0w.js";import{c as r}from"./host-patterns-F-KZIzkF.js";import{Lr as i,M as a,Vn as o}from"./shaped-data-BRffby3g.js";import{I as s}from"./reader-DAdKx3ZF.js";import{M as c}from"./browser-connection-DMLe-0pv.js";import{r as l}from"./encode-files-BF1rsZES.js";function u(e,t){let n=typeof t==`string`?t.trim():``;if(!n)throw new r(`request`,`A typed credential must be a non-empty string`);if(e===`bearer`)return{type:`bearer`,token:n};if(e===`api_key`)return{type:`api_key`,key:n};throw new r(`request`,`A '${e}' sign-in takes no typed credential; the host's callback saves it`)}function d(e,t){if(!e)throw new r(`request`,`a typed credential answers only a sign-in gate`);return{slot:e.slot,credential:u(e.authType,t)}}function ee(e,t){if(t!==void 0){if(!Number.isFinite(t)||t<=0)throw new r(`config`,`${e} gateTtlMs must be a positive number of milliseconds; got ${t}.`);return t}}function te(e,t,n){return n!==void 0&&t-e>=n}var f=[`approve`,`deny`,`abandon`];function p(e,t=!1){return e.decision===`approve`?{granted:!0,...e.edited?{edited:e.edited}:{},...t?{signIn:t}:{}}:{granted:!1,cause:e.decision===`deny`?`declined`:`abandoned`,...t?{signIn:t}:{}}}function m(e,t,n){return n!==`session_consent`||e.includes(t)?[...e]:[...e,t]}function ne(e,t,n){let{callId:i,decision:a,input:o,secret:s,page:c}=e;if((o!==void 0||s!==void 0||c!==void 0)&&a!==`approve`)throw new r(`request`,`only an approval takes edited input, a secret, or a page answer (call ${i})`);if(a!==`approve`)return{resume:p({decision:a},t.auth!==void 0),input:t.arguments,sessionPermissions:[...n]};let l=s===void 0?void 0:d(t.auth,s);return{resume:{...p(o===void 0?{decision:a}:{decision:a,edited:{from:t.arguments}},t.auth!==void 0),...t.gateKind?{gateKind:t.gateKind}:{}},input:o??t.arguments,sessionPermissions:m(n,t.name,t.permission),...l?{typed:l}:{},...c?{page:c}:{}}}var re={'"':`"`,"\\":`\\`,"/":`/`,b:`\b`,f:`\f`,n:`
2
+ `,r:`\r`,t:` `};function h(e,t){let n=``,r=t+1;for(;r<e.length;){let t=e.charAt(r);if(t===`"`)return{text:n,end:r+1};if(t!==`\\`){n+=t,r++;continue}if(r+1>=e.length)break;let i=e.charAt(r+1);if(i===`u`){let t=e.slice(r+2,r+6);if(t.length<4)break;if(/^[0-9a-fA-F]{4}$/.test(t)){n+=String.fromCharCode(Number.parseInt(t,16)),r+=6;continue}}n+=re[i]??i,r+=2}return{text:n}}function g(e,t){let n=t;for(;/\s/.test(e.charAt(n));)n++;return n}function ie(e,t){if(e.charAt(t)===`"`){let n=h(e,t);return n.end===void 0?void 0:_(e,t,n.end)}let n=0;for(let r=t;r<e.length;r++){let i=e.charAt(r);if(i===`"`){let t=h(e,r).end;if(t===void 0)return;r=t-1}else if(i===`{`||i===`[`)n++;else if(i===`}`||i===`]`){if(n===0)return _(e,t,r);if(n--,n===0)return _(e,t,r+1)}else if(i===`,`&&n===0)return _(e,t,r)}}function _(e,t,n){try{return{value:JSON.parse(e.slice(t,n)),end:n}}catch{return}}function v(e){let t={},n=g(e,0);if(e.charAt(n)!==`{`)return t;for(n++;;){if(n=g(e,n),e.charAt(n)===`,`&&(n=g(e,n+1)),e.charAt(n)!==`"`)return t;let r=h(e,n);if(r.end===void 0||(n=g(e,r.end),e.charAt(n)!==`:`)||(n=g(e,n+1),n>=e.length))return t;let i=ie(e,n);if(!i)return e.charAt(n)===`"`&&(t[r.text]=h(e,n).text),t;t[r.text]=i.value,n=i.end}}function y(e,t){if(t.phase===void 0)return{name:t.name,callId:t.callId,...t.operationId?{operationId:t.operationId}:{},arguments:t.arguments,...t.reasoning?{reasoning:t.reasoning}:{},...t.stepId?{stepId:t.stepId}:{},artifacts:[]};if(e===void 0)throw new r(`bad_response`,`Tool event '${t.phase}' for call '${t.callId}' arrived before the call.`);if(e.callId!==t.callId||e.name!==t.name)throw new r(`bad_response`,i(`error.bad_response`));switch(t.phase){case`running`:{let{endedAt:n,outputDraft:r,...i}=e;return{...i,state:t,startedAt:t.at,...t.edited?{edited:t.edited}:{},...t.activity?{activity:t.activity}:{}}}case`complete`:case`error`:return{...b(e),state:t,endedAt:t.at,...t.activityPast?{activityPast:t.activityPast}:{}};case`cancel`:case`gate`:case`background`:return{...b(e),state:t,endedAt:t.at};case`draft`:return{...e,outputDraft:(e.outputDraft??``)+t.text};case`artifact`:return{...e,artifacts:[...e.artifacts,t.artifact]};case`progress`:return se(e,t.data);case`dispatch`:case`trace`:case`warning`:return e}}function b(e){let{outputDraft:t,...n}=e;return n}function x(e,t){return{arguments:{},artifacts:[],...e,name:t.name,callId:t.callId,draft:(e?.draft??``)+t.text}}function S(e,t){if(t.type===`tool_draft`){e.set(t.callId,x(e.get(t.callId),t));return}let{tool:n}=t,r=n.operationId??n.callId;n.phase===void 0&&e.get(n.callId)?.draft!==void 0&&e.delete(n.callId),e.set(r,y(e.get(r),n))}function ae(e){let t=new Map;for(let n of e)(n.type===`tool_draft`||n.type===`tool`)&&S(t,n);return[...t.values()]}function oe(t){if(typeof t!=`object`||!t||!(`agent`in t)||!(`event`in t))return;let{event:n}=t;if(n?.type!==`tool`&&n?.type!==`tool_draft`)return;let r=e.safeParse(n);return r.success?r.data:void 0}function se(e,t){let n=oe(t),r=n&&ce(e.steps??[],n);return r?{...e,steps:r}:e}function ce(e,t){let n=new Map(e.map(e=>[e.operationId??e.callId,e]));if(t.type===`tool`&&t.tool.phase!==void 0){let e=n.get(t.tool.operationId??t.tool.callId);if(e?.callId!==t.tool.callId||e.name!==t.tool.name)return}return S(n,t),[...n.values()]}function le(e){return(e.state?.phase===`gate`?e.state.gate.preparedArguments:void 0)??e.edited?.to??e.arguments}function ue(e,t){return e.type!==`tool`||e.tool.callId!==t?!1:e.tool.phase===`complete`||e.tool.phase===`error`||e.tool.phase===`background`}var de={avif:`image/avif`,gif:`image/gif`,heic:`image/heic`,heif:`image/heif`,jpeg:`image/jpeg`,jpg:`image/jpeg`,png:`image/png`,svg:`image/svg+xml`,webp:`image/webp`,mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,ogv:`video/ogg`,mp3:`audio/mpeg`,m4a:`audio/mp4`,ogg:`audio/ogg`,wav:`audio/wav`};function fe(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n<=0||n===t.length-1?void 0:de[t.slice(n+1).toLowerCase()]}function pe(e){let t=e.trim();if(t.length===0)return;let n;try{n=new URL(t)}catch{return}if(n.protocol!==`http:`&&n.protocol!==`https:`)return;let r=fe(n.pathname);if(r)return{url:n.href,mimeType:r}}var me=/^(.*)\/thumb(\/.+\/([^/]+))\/(\d+)px-\3(?:\.[a-z0-9]+)?$/i;function he(e){let t=new URL(e),n=t.hostname.split(`.`).slice(-2).join(`.`);for(let e of[...t.searchParams.keys()])e.startsWith(`utm_`)&&t.searchParams.delete(e);let r=me.exec(t.pathname);return{key:`${n}${r?`${r[1]}${r[2]}`:t.pathname}${t.search}`,width:r?Number(r[4]):1/0}}function ge(e){let t=new Map,n=[],r=e=>{if(typeof e==`string`){let r=pe(e);if(!r)return;let i=he(r.url),a=t.get(i.key);if(!a){t.set(i.key,{index:n.length,largest:i.width,smallest:i.width}),n.push(r);return}let o=n[a.index];i.width>a.largest?(a.largest=i.width,n[a.index]={...o,url:r.url,previewUrl:o.previewUrl??o.url}):i.width<a.smallest&&(a.smallest=i.width,n[a.index]={...o,previewUrl:r.url})}else if(Array.isArray(e))for(let t of e)r(t);else if(typeof e==`object`&&e)for(let t of Object.values(e))r(t)};return r(e),n}var C=0;function w(e){return e===`user`?`user-${globalThis.crypto.randomUUID()}`:(C+=1,`${e}-${String(C)}`)}function T(e,t){return e?.kind===t}function E(e,t,n,r){let i=e.at(-1);T(i,t)?i.text+=n:e.push({id:w(r),kind:t,text:n})}function D(e,t){let n=e.at(-1),r=n?.kind===`text`||n?.kind===`thought`;e.splice(r?e.length-1:e.length,0,t)}function O(e,t){return e.find(e=>e.kind===`tool`&&e.id===t)}function k(e,t){let n=`tool-${t.operationId??t.callId}`,r=O(e,n),i=y(r?.tool,t);if(r){r.tool=i;return}let a=t.phase===void 0?O(e,`tool-${t.callId}`):void 0;a?.tool.draft===void 0?e.push({id:n,kind:`tool`,tool:i}):(a.id=n,a.tool=i)}function A(e,t){let n=`tool-${t.callId}`,r=O(e,n),i=x(r?.tool,t);r?r.tool=i:e.push({id:n,kind:`tool`,tool:i})}function j(e){return e.findLast(e=>e.kind===`structured`&&e.draft!==void 0)}function M(e,t,n){let r=j(e),i=(r?.draft??``)+t;r?(r.draft=i,r.value=v(i)):e.push({id:w(n),kind:`structured`,value:v(i),draft:i})}function N(e,t,n){let r=j(e);r?(r.value=t,delete r.draft):e.push({id:w(n),kind:`structured`,value:t})}function P(e,t){return e.type===t.type?e.placeId&&t.placeId?e.placeId===t.placeId:e.uri===t.uri:!1}function F(e,t,n){let r=e.find(e=>e.kind===`citation`&&e.callId===t.callId),i=r?[...r.sources]:[];for(let e of t.sources)i.some(t=>P(t,e))||i.push(e);r?r.sources=i:e.push({id:w(n),kind:`citation`,sources:i,...t.callId===void 0?{}:{callId:t.callId}})}function I(e,t,n,r){if(t.phase===`complete`&&t.output!==void 0)for(let i of ge(t.output))r.has(i.url)||(r.add(i.url),e.push({id:w(n),kind:`media`,mimeType:i.mimeType,url:i.url,...i.previewUrl?{previewUrl:i.previewUrl}:{}}))}function L(e,t){return e.messages.flatMap(e=>{if(e.role!==`user`)return[];let n=e.parts??[],r=[e.content??``,...n.map(e=>`text`in e?e.text:``)].join(``).trim();return[...r?[{id:w(t),kind:`user-text`,text:r}]:[],...n.flatMap(e=>`text`in e?[]:[{id:w(t),kind:e.type===`audio`?`user-voice`:`user-attachment`,name:e.mimeType,mimeType:e.mimeType,...`data`in e?{sizeBytes:Math.floor(e.data.length*3/4),data:e.data}:{sizeBytes:0}}])]})}function R(e,t=`user`){let n=[],r=e.text?.trim();r&&n.push({id:w(t),kind:`user-text`,text:r});for(let r of e.attachments??[])n.push({id:w(t),kind:`user-attachment`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});for(let r of e.voice??[])n.push({id:w(t),kind:`user-voice`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});return n}function _e(e,t){switch(e.type){case`media`:return e.media?{id:w(t),kind:`media`,mimeType:e.media.mimeType,data:e.media.data}:void 0;case`grounding`:return{id:w(t),kind:`grounding`,grounding:e.grounding};case`evidence`:return{id:w(t),kind:`evidence`,evidence:e.evidence};case`error`:return e.error?{id:w(t),kind:`error`,message:e.error}:void 0;case`done`:return{id:w(t),kind:`turn-done`,stop:e.stop,tokens:e.tokens,interactionId:e.interactionId,compaction:e.compaction!==void 0};default:return}}function ve(e,t,n){if(t.phase===`complete`)for(let r of t.parts??[])r.type!==`text`&&e.push({id:w(n),kind:`media`,mimeType:r.mimeType,...`data`in r?{data:r.data}:{url:r.uri}})}function z(e,n={}){let r=n.idPrefix??`turn`,i=n.showThoughts??!0;C=0;let a=[],o=new Set;for(let n of t(e))switch(n.type){case`thought`:i&&n.text&&E(a,`thought`,n.text,r);break;case`text`:n.text&&E(a,`text`,n.text,r);break;case`tool_draft`:A(a,n);break;case`tool`:k(a,n.tool),I(a,n.tool,r,o),ve(a,n.tool,r);break;case`structured_draft`:M(a,n.text,r);break;case`structured`:N(a,n.structured,r);break;case`citation`:F(a,n,r);break;case`guardrail`:D(a,{id:w(r),kind:`guardrail`,guardrail:n.guardrail});break;case`stage`:for(let e of n.injected??[])a.push(...L(e,r));break;default:{let e=_e(n,r);e&&a.push(e)}}return a}function ye(e,t,n={}){return[...R(e,`user`),...z(t,n)]}function be(e){if(!e)return o;let{detect:t,patterns:n}=e;if(!n)return t;let r=Object.fromEntries(Object.entries(n).map(([e,{theorem:t}])=>[e,{theorem:t,matchers:[]}]));return{...t,sources:r}}function xe(e,t){if(e.text===void 0)return e;let n=a(e.text,`user`,be(t));return{...e,text:n.text??e.text}}function B(e,t,n){let r=s(e,t);if(!r.ok)return{ok:!1,issues:r.issues};let i=xe(t,n);return{ok:!0,draft:i,blocks:R(i)}}function V(e,t){if(t)return e.models[t]}function H(e){return!!(e.allowModelSelect&&Object.keys(e.models).length>=2)}function U(e,t){let n=V(e,t);return n?.allowEffortSelect?Object.keys(n.efforts??{}).length>=2:!1}function W(e,t){let n=V(e,t);if(!n?.efforts)return;let r=n.defaultEffort?.trim();return r&&n.efforts[r]?r:Object.keys(n.efforts)[0]}function Se(e){return H(e)?Object.entries(e.models).map(([e,t])=>({id:e,label:t.apiId})):[]}function Ce(e,t){if(!U(e,t))return[];let n=V(e,t);return n?.efforts?Object.entries(n.efforts).map(([e,t])=>({alias:e,level:t})):[]}function G(e){let t=new Set;for(let n of e)if(n.type===`tool`&&n.tool.phase===`complete`)for(let e of c(n.tool.output)??[])t.add(e);return[...t]}function K(e){let t=n(e,e=>e.type===`done`&&e.tools!==void 0);return t?.type===`done`?t.tools:void 0}function we(e){let t=K(e)?.visible??[],r=n(e,e=>e.type===`done`&&e.steps!==void 0);return{promoted:[...new Set([...t,...G(e)])],stepsTaken:r?.type===`done`?r.steps??0:0}}function q(e){return e?.streaming?.streamThoughts!==!1}function J(e){return e.defaultModel??Object.keys(e.models)[0]}function Te(e,t,n){let r=t.model!==void 0&&Object.hasOwn(e.models,t.model)&&(n===void 0||t.model!==J(n))?t.model:J(e),i=r===void 0?void 0:e.models[r]?.efforts;return{model:r,effort:r===t.model&&t.effort!==void 0&&i!==void 0&&Object.hasOwn(i,t.effort)&&(n===void 0||t.effort!==W(n,r))?t.effort:W(e,r)}}function Y(e){if(!e.operationId)throw new r(`request`,i(`session.gate_expired`));return e.operationId}function Ee(e,t){return t.selectedModel??J(e)}function X(e,t,n){let r=t.selectedEffort;if(!n||!Object.hasOwn(e.models,n))return r;let i=e.models[n];return i.allowEffortSelect?r??i.defaultEffort:r===W(e,n)?void 0:r}function Z(e,t){let n=Ee(e,t),r=e.allowModelSelect||n!==J(e)?n:void 0,i=X(e,t,n);return{...r?{model:r}:{},...i?{effort:i}:{}}}function De(e,t,n){return{name:n.name,input:n.input,...n.gateKind?{gateKind:n.gateKind}:{},sessionPermissions:n.sessionPermissions??t.sessionPermissions,...t.toolSnapshot?{snapshot:t.toolSnapshot}:{},...t.promotedToolIds.length?{promoted:[...t.promotedToolIds]}:{},...Z(e,t)}}function Q(e){return{...e.conversation?{conversation:e.conversation}:{},...e.turnId?{turnId:e.turnId}:{}}}function Oe(e,t,n,r={}){let i=(r.walkAway?.calls??[]).map(e=>({callId:e.callId,operationId:Y(e)}));return{...Q(r),...Z(e,t),input:n,...i.length?{abandon:i}:{},replay:{sessionPermissions:t.sessionPermissions}}}function ke(e,t,n,r={}){return{...Q(r),gateId:n.gateId,operationId:n.operationId,decision:n.decision,...n.secret===void 0?{}:{secret:n.secret},...n.page===void 0?{}:{page:n.page},replay:De(e,t,{...n,gateKind:n.gateKind??(t.gatedTool?.callId===n.gateId?t.gatedTool.gateKind:void 0)})}}function $(e,t){return B(e.inputs,t,e.guardrails)}function Ae(e,t,n,r=[]){return $(e,{...t.trim()?{text:t}:{},...n.length?{attachments:l(n)}:{},...r.length?{voice:l(r)}:{}})}function je(e,t){return z(t,{showThoughts:q(e.outputs)})}export{ae as C,ee as D,te as E,p as O,le as S,ne as T,B as _,Ae as a,y as b,q as c,K as d,W as f,H as g,Se as h,Y as i,m as k,G as l,Ce as m,Oe as n,$ as o,U as p,je as r,Te as s,ke as t,we as u,ye as v,f as w,ue as x,z as y};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{t as r}from"./VStack-CkVMcNiK.js";import{n as i}from"./StackItem-CQviqAfM.js";import{S as a,T as o}from"./browser-transport-DKhZ4zo1.js";import{t as s}from"./Icon-BqkS-pIq.js";import{t as c}from"./Text-BOqCfzZC.js";import{n as l,o as u}from"./labels-provider-uONlWExD.js";import{n as d}from"./Card-DruykyeB.js";import{t as f}from"./IconButton-DVUFx-8p.js";import{t as p}from"./Tooltip-BWs5DLrM.js";import{d as m}from"./reader-747-Cvu8.js";import{_ as h,b as g,g as _,y as v}from"./ConsoleFrame-dOTqIkpb.js";import{c as y,i as b}from"./trace-patterns-D6TbkLLr.js";import{n as x}from"./studio-console-DwxLzV9_.js";import{D as S,O as C,V as w,W as T}from"./index-CAK9cdCh.js";var E=e(n(),1),D=t(),O=`var(--duration-medium) var(--ease-standard)`,k=12;function A(){let e=d();return(0,E.useMemo)(()=>({percent:new Intl.NumberFormat(e,{style:`percent`,maximumFractionDigits:0}),decimal:new Intl.NumberFormat(e,{maximumFractionDigits:2}),usd:new Intl.NumberFormat(e,{style:`currency`,currency:`USD`,maximumSignificantDigits:2})}),[e])}function j(e){return y(e?`clear`:`shade2`)}function M({value:e,isLead:t}){return(0,D.jsx)(`div`,{style:{height:k,width:`${String(Math.max(e,.01)*100)}%`,borderRadius:4,background:j(t),transition:`width ${O}`}})}function N({title:e,aside:t,detail:n,answer:a}){let o=l(),s=A(),u=Object.entries(a.probabilities).sort(([,e],[,t])=>t-e);return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:a.choice,note:o(`@theorem.decision.confidence`,{percent:s.percent.format(a.confidence)}),children:(0,D.jsx)(r,{gap:2,role:`list`,children:u.map(([e,t])=>(0,D.jsxs)(r,{gap:1,role:`listitem`,"aria-label":o(`@theorem.decision.option`,{label:e,percent:s.percent.format(t)}),children:[(0,D.jsxs)(i,{gap:2,hAlign:`between`,"aria-hidden":!0,children:[(0,D.jsx)(c,{type:`supporting`,color:`secondary`,maxLines:1,children:e}),(0,D.jsx)(c,{type:`supporting`,hasTabularNumbers:!0,children:s.percent.format(t)})]}),(0,D.jsx)(M,{value:t,isLead:e===a.choice})]},e))})})}var P=56;function F(e){let t=e.split(/[:—–]\s/)[0]?.trim()??``;return t&&t.length<=32&&t!==e?t:e}function I({title:e,aside:t,detail:n,answer:i,labels:a}){let o=l(),s=A(),u=a.length,d=Math.min(u-1,Math.max(0,Math.round(i.score)));return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:a[d]===void 0?s.decimal.format(i.score):F(a[d]),note:[o(`@theorem.decision.score_of`,{score:s.decimal.format(i.score),max:s.decimal.format(u-1)}),o(`@theorem.decision.confidence`,{percent:s.percent.format(i.confidence)})].join(` · `),children:(0,D.jsxs)(r,{gap:1,children:[(0,D.jsxs)(`div`,{"aria-hidden":!0,style:{position:`relative`,display:`flex`,alignItems:`flex-end`,gap:4,height:P},children:[a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,height:`${String(Math.max(.04,i.probabilities[String(t)]??0)*100)}%`,borderRadius:4,background:j(t===d),transition:`height ${O}`}},`${String(t)}:${e}`)),(0,D.jsx)(`div`,{style:{position:`absolute`,insetBlock:-4,left:`${String((i.score+.5)/u*100)}%`,width:0,borderInlineStart:`1.5px dashed var(--color-text-secondary)`,transition:`left ${O}`}})]}),(0,D.jsx)(`div`,{style:{display:`flex`,gap:4},children:a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,minWidth:0},title:e,children:(0,D.jsx)(c,{type:`supporting`,color:`secondary`,maxLines:1,children:F(e)})},`${String(t)}:${e}`))}),(0,D.jsx)(`span`,{style:{position:`absolute`,width:1,height:1,overflow:`hidden`,clipPath:`inset(50%)`},children:a.map((e,t)=>o(`@theorem.decision.option`,{label:e,percent:s.percent.format(i.probabilities[String(t)]??0)})).join(`; `)})]})})}function L({title:e,aside:t,detail:n,answer:r}){let i=A();return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:i.decimal.format(r.noul)})}var R=72,z=168;function B(e){let[t,n]=(0,E.useState)(null);return(0,E.useEffect)(()=>{let t=new Image;t.onload=()=>{n({width:t.naturalWidth,height:t.naturalHeight})},t.src=e},[e]),t}function V(e,t){let n=e.style.color;e.style.color=`var(${t})`;let r=getComputedStyle(e).color;return e.style.color=n,r}function H({source:e,box:t,caption:n}){let r=l(),i=v(e),a=B(i),[o,s]=(0,E.useState)(null);if(!a)return null;let c=h(t),u=a.width*(t.right-t.left)/(a.height*(t.bottom-t.top)),d=r(`@theorem.decision.open_box`);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(p,{content:d,children:(0,D.jsx)(T,{label:d,padding:0,onClick:e=>{let n={outline:V(e.currentTarget,`--color-accent`),shade:V(e.currentTarget,`--color-overlay`)};g(i,t,n).then(s)},children:(0,D.jsx)(`div`,{role:`img`,"aria-label":r(`@theorem.decision.box_in`),style:{position:`relative`,overflow:`hidden`,aspectRatio:String(u),height:z,maxWidth:`100%`,borderRadius:4},children:(0,D.jsx)(`img`,{src:i,alt:``,style:{position:`absolute`,width:`${String(c.width)}%`,height:`${String(c.height)}%`,left:`${String(c.left)}%`,top:`${String(c.top)}%`,maxWidth:`none`}})})})}),(0,D.jsx)(w,{isOpen:o!==null,onOpenChange:e=>{e||s(null)},media:{src:o??i,alt:r(`@theorem.decision.box_marked`),caption:n},hasZoom:!0})]})}function U({title:e,aside:t,detail:n,answer:r,image:i,asked:a}){let o=l(),s=a&&_(a.images,a.state,i),c=A(),{top:u,bottom:d,left:f,right:p}=r.box,m=o(`@theorem.decision.box_edges`,{left:c.percent.format(f),top:c.percent.format(u),right:c.percent.format(p),bottom:c.percent.format(d)});return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:m,note:o(`@theorem.decision.confidence`,{percent:c.percent.format(r.confidence)}),children:s?(0,D.jsx)(H,{source:s,box:r.box,caption:`${e}: ${m}`}):(0,D.jsx)(`div`,{"aria-hidden":!0,style:{position:`relative`,height:R,borderRadius:4,border:`1px solid var(--color-border)`},children:(0,D.jsx)(`div`,{style:{position:`absolute`,insetInlineStart:`${String(f*100)}%`,insetBlockStart:`${String(u*100)}%`,width:`${String((p-f)*100)}%`,height:`${String((d-u)*100)}%`,borderRadius:2,background:j(!0),transition:`all ${O}`}})})})}function W({question:e,answer:t,asked:n,onQuestion:r,detail:i}){let a=l(),c=`${e.id} · ${a(`@theorem.decision.type.${e.type}`)}`;if(!t)return null;let u=a(`@theorem.decision.edit_question`,{question:e.id}),d={title:c,detail:i,aside:r?(0,D.jsx)(f,{label:u,tooltip:u,size:`sm`,variant:`ghost`,icon:(0,D.jsx)(s,{icon:o,size:`xsm`,color:`secondary`}),onClick:()=>{r(e.id)}}):void 0};return t.type===`choice`?(0,D.jsx)(N,{...d,answer:t}):t.type===`score`?(0,D.jsx)(I,{...d,answer:t,labels:e.labels}):t.type===`noul`?(0,D.jsx)(L,{...d,answer:t}):(0,D.jsx)(U,{...d,answer:t,image:e.image,asked:n})}function G({model:e,usage:t,elapsedMs:n,isStale:i,tokens:a,children:o}){let s=l(),d=A();return(0,D.jsx)(C,{children:(0,D.jsxs)(r,{gap:3,style:{opacity:i?.5:1,transition:`opacity ${O}`},"aria-busy":i,children:[o,(0,D.jsx)(S,{children:(0,D.jsx)(c,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:u(s,d.usd,{model:e,usage:t,elapsedMs:n,tokens:a})})})]},n??0)})}function K({iface:e,result:t,elapsedMs:n,isStale:r,asked:i,onQuestion:a,questionText:o}){let s=l();return(0,D.jsx)(G,{model:t.model,usage:t.usage,elapsedMs:n,isStale:r,tokens:e=>s(`@theorem.decision.tokens`,{count:e}),children:(0,D.jsx)(x,{minWidth:260,children:e.questions.map(e=>(0,D.jsx)(S,{children:(0,D.jsx)(W,{question:e,answer:t.answers[e.id],asked:i,onQuestion:a,detail:o?.[e.id]})},e.id))})})}var q={status:`idle`,result:null,elapsedMs:null,startedAt:null,failure:null};function J(e,t){for(let n of t??[])e.traces?.push(n)}function Y(e,t,n){let[r,i]=(0,E.useState)(q),o=(0,E.useRef)(null);(0,E.useEffect)(()=>()=>o.current?.abort(),[]);let s=(0,E.useCallback)(()=>{o.current?.abort(),o.current=null,i(e=>e.status===t?{...e,status:e.result?`done`:`idle`,startedAt:null}:e)},[t]),c=(0,E.useCallback)(async(...r)=>{o.current?.abort();let s=new AbortController;o.current=s,i(e=>({status:t,result:e.result,elapsedMs:e.elapsedMs,startedAt:Date.now(),failure:null}));let c=performance.now();try{let t=await n(e,s.signal,...r);if(s.signal.aborted)return;J(e,t.traces),i({status:`done`,result:t.result,elapsedMs:performance.now()-c,startedAt:null,failure:null})}catch(t){if(s.signal.aborted)return;J(e,m(t)),i(e=>({...e,status:`error`,startedAt:null,failure:a(t)}))}finally{o.current===s&&(o.current=null)}},[e,t,n]);return{...r,call:c,cancel:s}}export{A as a,K as i,G as n,M as r,Y as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{t as r}from"./VStack-CkVMcNiK.js";import{n as i}from"./StackItem-CQviqAfM.js";import{S as a,T as o}from"./browser-transport-Ddqv2L5-.js";import{t as s}from"./Icon-BqkS-pIq.js";import{t as c}from"./Text-BOqCfzZC.js";import{n as l,o as u}from"./labels-provider-uONlWExD.js";import{n as d}from"./Card-DruykyeB.js";import{t as f}from"./IconButton-DVUFx-8p.js";import{t as p}from"./Tooltip-BWs5DLrM.js";import{d as m}from"./reader-DAdKx3ZF.js";import{_ as h,b as g,g as _,y as v}from"./ConsoleFrame-DwVyTmlI.js";import{c as y,i as b}from"./trace-patterns-D6TbkLLr.js";import{n as x}from"./studio-console-DdjCZJRm.js";import{D as S,O as C,V as w,W as T}from"./index-Cvl7QJ2f.js";var E=e(n(),1),D=t(),O=`var(--duration-medium) var(--ease-standard)`,k=12;function A(){let e=d();return(0,E.useMemo)(()=>({percent:new Intl.NumberFormat(e,{style:`percent`,maximumFractionDigits:0}),decimal:new Intl.NumberFormat(e,{maximumFractionDigits:2}),usd:new Intl.NumberFormat(e,{style:`currency`,currency:`USD`,maximumSignificantDigits:2})}),[e])}function j(e){return y(e?`clear`:`shade2`)}function M({value:e,isLead:t}){return(0,D.jsx)(`div`,{style:{height:k,width:`${String(Math.max(e,.01)*100)}%`,borderRadius:4,background:j(t),transition:`width ${O}`}})}function N({title:e,aside:t,detail:n,answer:a}){let o=l(),s=A(),u=Object.entries(a.probabilities).sort(([,e],[,t])=>t-e);return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:a.choice,note:o(`@theorem.decision.confidence`,{percent:s.percent.format(a.confidence)}),children:(0,D.jsx)(r,{gap:2,role:`list`,children:u.map(([e,t])=>(0,D.jsxs)(r,{gap:1,role:`listitem`,"aria-label":o(`@theorem.decision.option`,{label:e,percent:s.percent.format(t)}),children:[(0,D.jsxs)(i,{gap:2,hAlign:`between`,"aria-hidden":!0,children:[(0,D.jsx)(c,{type:`supporting`,color:`secondary`,maxLines:1,children:e}),(0,D.jsx)(c,{type:`supporting`,hasTabularNumbers:!0,children:s.percent.format(t)})]}),(0,D.jsx)(M,{value:t,isLead:e===a.choice})]},e))})})}var P=56;function F(e){let t=e.split(/[:—–]\s/)[0]?.trim()??``;return t&&t.length<=32&&t!==e?t:e}function I({title:e,aside:t,detail:n,answer:i,labels:a}){let o=l(),s=A(),u=a.length,d=Math.min(u-1,Math.max(0,Math.round(i.score)));return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:a[d]===void 0?s.decimal.format(i.score):F(a[d]),note:[o(`@theorem.decision.score_of`,{score:s.decimal.format(i.score),max:s.decimal.format(u-1)}),o(`@theorem.decision.confidence`,{percent:s.percent.format(i.confidence)})].join(` · `),children:(0,D.jsxs)(r,{gap:1,children:[(0,D.jsxs)(`div`,{"aria-hidden":!0,style:{position:`relative`,display:`flex`,alignItems:`flex-end`,gap:4,height:P},children:[a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,height:`${String(Math.max(.04,i.probabilities[String(t)]??0)*100)}%`,borderRadius:4,background:j(t===d),transition:`height ${O}`}},`${String(t)}:${e}`)),(0,D.jsx)(`div`,{style:{position:`absolute`,insetBlock:-4,left:`${String((i.score+.5)/u*100)}%`,width:0,borderInlineStart:`1.5px dashed var(--color-text-secondary)`,transition:`left ${O}`}})]}),(0,D.jsx)(`div`,{style:{display:`flex`,gap:4},children:a.map((e,t)=>(0,D.jsx)(`div`,{style:{flex:1,minWidth:0},title:e,children:(0,D.jsx)(c,{type:`supporting`,color:`secondary`,maxLines:1,children:F(e)})},`${String(t)}:${e}`))}),(0,D.jsx)(`span`,{style:{position:`absolute`,width:1,height:1,overflow:`hidden`,clipPath:`inset(50%)`},children:a.map((e,t)=>o(`@theorem.decision.option`,{label:e,percent:s.percent.format(i.probabilities[String(t)]??0)})).join(`; `)})]})})}function L({title:e,aside:t,detail:n,answer:r}){let i=A();return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:i.decimal.format(r.noul)})}var R=72,z=168;function B(e){let[t,n]=(0,E.useState)(null);return(0,E.useEffect)(()=>{let t=new Image;t.onload=()=>{n({width:t.naturalWidth,height:t.naturalHeight})},t.src=e},[e]),t}function V(e,t){let n=e.style.color;e.style.color=`var(${t})`;let r=getComputedStyle(e).color;return e.style.color=n,r}function H({source:e,box:t,caption:n}){let r=l(),i=v(e),a=B(i),[o,s]=(0,E.useState)(null);if(!a)return null;let c=h(t),u=a.width*(t.right-t.left)/(a.height*(t.bottom-t.top)),d=r(`@theorem.decision.open_box`);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(p,{content:d,children:(0,D.jsx)(T,{label:d,padding:0,onClick:e=>{let n={outline:V(e.currentTarget,`--color-accent`),shade:V(e.currentTarget,`--color-overlay`)};g(i,t,n).then(s)},children:(0,D.jsx)(`div`,{role:`img`,"aria-label":r(`@theorem.decision.box_in`),style:{position:`relative`,overflow:`hidden`,aspectRatio:String(u),height:z,maxWidth:`100%`,borderRadius:4},children:(0,D.jsx)(`img`,{src:i,alt:``,style:{position:`absolute`,width:`${String(c.width)}%`,height:`${String(c.height)}%`,left:`${String(c.left)}%`,top:`${String(c.top)}%`,maxWidth:`none`}})})})}),(0,D.jsx)(w,{isOpen:o!==null,onOpenChange:e=>{e||s(null)},media:{src:o??i,alt:r(`@theorem.decision.box_marked`),caption:n},hasZoom:!0})]})}function U({title:e,aside:t,detail:n,answer:r,image:i,asked:a}){let o=l(),s=a&&_(a.images,a.state,i),c=A(),{top:u,bottom:d,left:f,right:p}=r.box,m=o(`@theorem.decision.box_edges`,{left:c.percent.format(f),top:c.percent.format(u),right:c.percent.format(p),bottom:c.percent.format(d)});return(0,D.jsx)(b,{title:e,aside:t,detail:n,value:m,note:o(`@theorem.decision.confidence`,{percent:c.percent.format(r.confidence)}),children:s?(0,D.jsx)(H,{source:s,box:r.box,caption:`${e}: ${m}`}):(0,D.jsx)(`div`,{"aria-hidden":!0,style:{position:`relative`,height:R,borderRadius:4,border:`1px solid var(--color-border)`},children:(0,D.jsx)(`div`,{style:{position:`absolute`,insetInlineStart:`${String(f*100)}%`,insetBlockStart:`${String(u*100)}%`,width:`${String((p-f)*100)}%`,height:`${String((d-u)*100)}%`,borderRadius:2,background:j(!0),transition:`all ${O}`}})})})}function W({question:e,answer:t,asked:n,onQuestion:r,detail:i}){let a=l(),c=`${e.id} · ${a(`@theorem.decision.type.${e.type}`)}`;if(!t)return null;let u=a(`@theorem.decision.edit_question`,{question:e.id}),d={title:c,detail:i,aside:r?(0,D.jsx)(f,{label:u,tooltip:u,size:`sm`,variant:`ghost`,icon:(0,D.jsx)(s,{icon:o,size:`xsm`,color:`secondary`}),onClick:()=>{r(e.id)}}):void 0};return t.type===`choice`?(0,D.jsx)(N,{...d,answer:t}):t.type===`score`?(0,D.jsx)(I,{...d,answer:t,labels:e.labels}):t.type===`noul`?(0,D.jsx)(L,{...d,answer:t}):(0,D.jsx)(U,{...d,answer:t,image:e.image,asked:n})}function G({model:e,usage:t,elapsedMs:n,isStale:i,tokens:a,children:o}){let s=l(),d=A();return(0,D.jsx)(C,{children:(0,D.jsxs)(r,{gap:3,style:{opacity:i?.5:1,transition:`opacity ${O}`},"aria-busy":i,children:[o,(0,D.jsx)(S,{children:(0,D.jsx)(c,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:u(s,d.usd,{model:e,usage:t,elapsedMs:n,tokens:a})})})]},n??0)})}function K({iface:e,result:t,elapsedMs:n,isStale:r,asked:i,onQuestion:a,questionText:o}){let s=l();return(0,D.jsx)(G,{model:t.model,usage:t.usage,elapsedMs:n,isStale:r,tokens:e=>s(`@theorem.decision.tokens`,{count:e}),children:(0,D.jsx)(x,{minWidth:260,children:e.questions.map(e=>(0,D.jsx)(S,{children:(0,D.jsx)(W,{question:e,answer:t.answers[e.id],asked:i,onQuestion:a,detail:o?.[e.id]})},e.id))})})}var q={status:`idle`,result:null,elapsedMs:null,startedAt:null,failure:null};function J(e,t){for(let n of t??[])e.traces?.push(n)}function Y(e,t,n){let[r,i]=(0,E.useState)(q),o=(0,E.useRef)(null);(0,E.useEffect)(()=>()=>o.current?.abort(),[]);let s=(0,E.useCallback)(()=>{o.current?.abort(),o.current=null,i(e=>e.status===t?{...e,status:e.result?`done`:`idle`,startedAt:null}:e)},[t]),c=(0,E.useCallback)(async(...r)=>{o.current?.abort();let s=new AbortController;o.current=s,i(e=>({status:t,result:e.result,elapsedMs:e.elapsedMs,startedAt:Date.now(),failure:null}));let c=performance.now();try{let t=await n(e,s.signal,...r);if(s.signal.aborted)return;J(e,t.traces),i({status:`done`,result:t.result,elapsedMs:performance.now()-c,startedAt:null,failure:null})}catch(t){if(s.signal.aborted)return;J(e,m(t)),i(e=>({...e,status:`error`,startedAt:null,failure:a(t)}))}finally{o.current===s&&(o.current=null)}},[e,t,n]);return{...r,call:c,cancel:s}}export{A as a,K as i,G as n,M as r,Y as t};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{u as t}from"./themeProps-3IqahpCr.js";import{wn as n}from"./shaped-data-7q5Be8sp.js";var r=/\{\s*private\s*:/g,i=/\n(?:[ \t]*\n)+/;function a(e){let[t,...n]=e;if(t===void 0)return;if(n.length===0&&typeof t==`string`)return t.trim()||void 0;let r=[...e],i=e.at(-1);typeof t==`string`&&(r[0]=t.trimStart()),typeof i==`string`&&(r[r.length-1]=i.trimEnd());let a=r.filter(e=>e!==``),[o,...s]=a;return s.length===0&&typeof o==`string`?o:a}function o(e){let t=[[]],n=e=>{let[n=``,...r]=e.split(i);t.at(-1)?.push(n),t.push(...r.map(e=>[e]))},o=0;for(let i of e.matchAll(r)){if(i.index<o)continue;let r=1,a=i.index+i[0].length;for(;a<e.length&&r>0;a++)e[a]===`{`?r++:e[a]===`}`&&r--;if(n(e.slice(o,i.index)),r>0)return{ok:!1,message:`The {private: section on line ${String(t.length)} has no closing }.`};let s=e.slice(i.index+i[0].length,a-1).trim();if(!s)return{ok:!1,message:`The {private: section on line ${String(t.length)} is empty.`};t.at(-1)?.push({private:s}),o=a}return n(e.slice(o)),{ok:!0,lines:t.flatMap(e=>{let t=a(e.filter(e=>e!==``));return t===void 0?[]:[t]})}}var s=n.filter(e=>e!==`builtin`),c=`Tool type must be ${s.join(`, `).replace(/, ([^,]+)$/,`, or $1`)}.`,l=e(t(),1);function u(e){let[t,n]=(0,l.useState)(()=>Date.now());return(0,l.useEffect)(()=>{if(!e)return;n(Date.now());let t=globalThis.setInterval(()=>n(Date.now()),1e3);return()=>globalThis.clearInterval(t)},[e]),t}export{o as i,s as n,c as r,u as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{u as t}from"./themeProps-3IqahpCr.js";import{wn as n}from"./shaped-data-BRffby3g.js";var r=/\{\s*private\s*:/g,i=/\n(?:[ \t]*\n)+/;function a(e){let[t,...n]=e;if(t===void 0)return;if(n.length===0&&typeof t==`string`)return t.trim()||void 0;let r=[...e],i=e.at(-1);typeof t==`string`&&(r[0]=t.trimStart()),typeof i==`string`&&(r[r.length-1]=i.trimEnd());let a=r.filter(e=>e!==``),[o,...s]=a;return s.length===0&&typeof o==`string`?o:a}function o(e){let t=[[]],n=e=>{let[n=``,...r]=e.split(i);t.at(-1)?.push(n),t.push(...r.map(e=>[e]))},o=0;for(let i of e.matchAll(r)){if(i.index<o)continue;let r=1,a=i.index+i[0].length;for(;a<e.length&&r>0;a++)e[a]===`{`?r++:e[a]===`}`&&r--;if(n(e.slice(o,i.index)),r>0)return{ok:!1,message:`The {private: section on line ${String(t.length)} has no closing }.`};let s=e.slice(i.index+i[0].length,a-1).trim();if(!s)return{ok:!1,message:`The {private: section on line ${String(t.length)} is empty.`};t.at(-1)?.push({private:s}),o=a}return n(e.slice(o)),{ok:!0,lines:t.flatMap(e=>{let t=a(e.filter(e=>e!==``));return t===void 0?[]:[t]})}}var s=n.filter(e=>e!==`builtin`),c=`Tool type must be ${s.join(`, `).replace(/, ([^,]+)$/,`, or $1`)}.`,l=e(t(),1);function u(e){let[t,n]=(0,l.useState)(()=>Date.now());return(0,l.useEffect)(()=>{if(!e)return;n(Date.now());let t=globalThis.setInterval(()=>n(Date.now()),1e3);return()=>globalThis.clearInterval(t)},[e]),t}export{o as i,s as n,c as r,u as t};
@@ -1 +1 @@
1
- import{E as e,a as t,c as n,i as r,n as i,o as a,r as o,s,w as c,y as l}from"./tree-DcCW259J.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-BpAzPK_j.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-CAK9cdCh.js"></script>
13
+ <script type="module" crossorigin src="/studio/assets/index-Cvl7QJ2f.js"></script>
14
14
  <link rel="modulepreload" crossorigin href="/studio/assets/rolldown-runtime-hePW80VL.js">
15
15
  <link rel="modulepreload" crossorigin href="/studio/assets/themeProps-3IqahpCr.js">
16
16
  <link rel="modulepreload" crossorigin href="/studio/assets/tokens.stylex-DkHf0P9C.js">
@@ -48,20 +48,20 @@
48
48
  <link rel="modulepreload" crossorigin href="/studio/assets/labels-provider-uONlWExD.js">
49
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-7q5Be8sp.js">
52
- <link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-6RWBAqGO.js">
51
+ <link rel="modulepreload" crossorigin href="/studio/assets/shaped-data-BRffby3g.js">
52
+ <link rel="modulepreload" crossorigin href="/studio/assets/tool-schema-C7lMQU0w.js">
53
53
  <link rel="modulepreload" crossorigin href="/studio/assets/live-ingress-OuSlQ6q7.js">
54
- <link rel="modulepreload" crossorigin href="/studio/assets/tree-DcCW259J.js">
55
- <link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-CuWeoI9s.js">
56
- <link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-D6JSf9B3.js">
57
- <link rel="modulepreload" crossorigin href="/studio/assets/Banner-CrhjYjDy.js">
54
+ <link rel="modulepreload" crossorigin href="/studio/assets/tree-BpAzPK_j.js">
55
+ <link rel="modulepreload" crossorigin href="/studio/assets/browser-connection-DMLe-0pv.js">
56
+ <link rel="modulepreload" crossorigin href="/studio/assets/use-second-ticker-Bx4tqkhi.js">
57
+ <link rel="modulepreload" crossorigin href="/studio/assets/Banner-CvzDCsXL.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/IconSearch-BTx66a40.js">
61
61
  <link rel="modulepreload" crossorigin href="/studio/assets/trace-schema--4IGmLeE.js">
62
- <link rel="modulepreload" crossorigin href="/studio/assets/stub--LOYiyQO.js">
63
- <link rel="modulepreload" crossorigin href="/studio/assets/reader-747-Cvu8.js">
64
- <link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-DKhZ4zo1.js">
62
+ <link rel="modulepreload" crossorigin href="/studio/assets/stub-4NoUUWes.js">
63
+ <link rel="modulepreload" crossorigin href="/studio/assets/reader-DAdKx3ZF.js">
64
+ <link rel="modulepreload" crossorigin href="/studio/assets/browser-transport-Ddqv2L5-.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,12 +71,12 @@
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-DoLGXgup.js">
75
- <link rel="modulepreload" crossorigin href="/studio/assets/turn-client-OLK12Fyi.js">
74
+ <link rel="modulepreload" crossorigin href="/studio/assets/encode-files-BF1rsZES.js">
75
+ <link rel="modulepreload" crossorigin href="/studio/assets/turn-client-CMgd-m7p.js">
76
76
  <link rel="modulepreload" crossorigin href="/studio/assets/CollapsibleGroup-BsIYDnJR.js">
77
- <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-q6eBFSru.js">
78
- <link rel="modulepreload" crossorigin href="/studio/assets/crypto-BnoW7FFO.js">
79
- <link rel="modulepreload" crossorigin href="/studio/assets/workspace-DSAX72vF.js">
77
+ <link rel="modulepreload" crossorigin href="/studio/assets/studio-labels-BZFUS19x.js">
78
+ <link rel="modulepreload" crossorigin href="/studio/assets/crypto-DjhcOJmp.js">
79
+ <link rel="modulepreload" crossorigin href="/studio/assets/workspace-CUvoWPwb.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
82
  <link rel="modulepreload" crossorigin href="/studio/assets/project-address-DjxPZuyn.js">
package/replay.js CHANGED
@@ -471,6 +471,7 @@ export function recordedTools(tools) {
471
471
  inputSchema: tool.inputSchema,
472
472
  outputSchema: tool.outputSchema,
473
473
  ...(tool.labels ? { labels: tool.labels } : {}),
474
+ ...(tool.background ? { background: tool.background } : {}),
474
475
  };
475
476
  });
476
477
  }
@@ -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 RegisteredProvider, type ResolveHost, type ToolExecutionCoordinator } from '@theoremjs/agents';
5
+ import { defineProfile, type KernelScope, type Profile, type ProfileDefinition, type Provider, type RegisteredProvider, type ResolveHost, type ToolBackgroundService, 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 {
@@ -14,12 +14,21 @@ export interface StudioProviderOptions extends ProviderHostOptions {
14
14
  import { type StudioRunsOn } from './lent-keys.ts';
15
15
  import type { StructuredRegistration, ToolRegistration } from './registrations.ts';
16
16
  import { type StudioToolHandlers } from './tools.ts';
17
+ /**
18
+ * A detached call's service for a run whose session lives as long as the work does: the studio's
19
+ * own server, or the page's tab.
20
+ * why: the session keeps each call's state and end, and a conversation read shows them, so a late
21
+ * event has nowhere else to go.
22
+ */
23
+ export declare const STUDIO_BACKGROUND: ToolBackgroundService;
17
24
  /** What a run holds besides what it runs on. */
18
25
  export interface StudioRuntimeBase {
19
26
  /** A project's own provider definitions, registered after the studio's. */
20
27
  providerDefinitions?: readonly Provider[];
21
28
  execution?: ToolExecutionCoordinator;
22
29
  pageExecution?: import('@theoremjs/agents').PageToolExecution;
30
+ /** Without it every tool runs inline, whatever its `background` setting. */
31
+ background?: ToolBackgroundService;
23
32
  providers?: StudioProviderOptions;
24
33
  hostOptions?: (profile: Profile, model?: string) => ProviderHostOptions;
25
34
  /** Answers every model call with a scripted model, in place of the profile's provider. */
package/runtime-scope.js CHANGED
@@ -11,6 +11,13 @@ import { lentCompression, runtimeNetwork } from "./lent-keys.js";
11
11
  import { modelBindingViolation } from "./policy.js";
12
12
  import { localProviderAddress, registerStudioProvider, STUDIO_PROVIDERS } from "./providers.js";
13
13
  import { registerDefined } from "./tools.js";
14
+ /**
15
+ * A detached call's service for a run whose session lives as long as the work does: the studio's
16
+ * own server, or the page's tab.
17
+ * why: the session keeps each call's state and end, and a conversation read shows them, so a late
18
+ * event has nowhere else to go.
19
+ */
20
+ export const STUDIO_BACKGROUND = { detached() { }, event() { } };
14
21
  /** The protocol event a scripted model's event stands for. */
15
22
  function protocolEvent(event) {
16
23
  if (event.type === 'tool')
package/runtime.js CHANGED
@@ -66,6 +66,7 @@ function studioRunner(args) {
66
66
  profile: profile.id,
67
67
  execution: runtime.execution,
68
68
  pageExecution: runtime.pageExecution,
69
+ background: runtime.background,
69
70
  metadata,
70
71
  input: turn.input,
71
72
  ...turn.stated,
@@ -234,6 +235,7 @@ function answerReplayed(scope, profile, request, replay, runtime) {
234
235
  resolveHost: runtime.resolveHost,
235
236
  execution: runtime.execution,
236
237
  pageExecution: runtime.pageExecution,
238
+ background: runtime.background,
237
239
  onAgentCall: agentCallHook(scope, runtime),
238
240
  };
239
241
  }
@@ -338,6 +340,7 @@ export async function* streamStudioCall(args) {
338
340
  profile: profile.id,
339
341
  execution: args.runtime.execution,
340
342
  pageExecution: args.runtime.pageExecution,
343
+ background: args.runtime.background,
341
344
  name: args.call.name,
342
345
  input: args.call.input,
343
346
  sessionPermissions: args.sessionPermissions,
package/server/handler.js CHANGED
@@ -26,7 +26,7 @@ import { STUDIO_TRACE_DESTINATION } from "../policy.js";
26
26
  import { kernelDefinition, modelSlots, registerStudioProvider, } from "../providers.js";
27
27
  import { readStudioSource } from "../read-source.js";
28
28
  import { STUDIO_READER } from "../reader.js";
29
- import { withPatterns } from "../runtime-scope.js";
29
+ import { STUDIO_BACKGROUND, withPatterns } from "../runtime-scope.js";
30
30
  import { studioSource } from "../source.js";
31
31
  import { createStudioDraftHandler, STUDIO_BASE } from "./draft-handler.js";
32
32
  import { errorJson } from "./draft-replies.js";
@@ -525,6 +525,7 @@ function profileHandlers(options, problems) {
525
525
  ...(isStateless ? {} : { conversationStore: chatStore() }),
526
526
  // The studio's page is the builder's own: its picks choose the prompt lines.
527
527
  pageStatesTurn: true,
528
+ background: () => STUDIO_BACKGROUND,
528
529
  ...shared,
529
530
  });
530
531
  served.set(profile.id, withRunTraces(isStateless ? chat : startsConversations(chat, profile, chatStore(), shared.session)));
package/server/live.js CHANGED
@@ -10,6 +10,7 @@ import { clientError } from '@theoremjs/agents/host';
10
10
  import { createMemorySessionStore, createTheoremSessionBoundary, parseLiveOpenMessage, } from '@theoremjs/web/server';
11
11
  import { attachStudioLiveSession } from "../live-session-bridge.js";
12
12
  import { STUDIO_READER } from "../reader.js";
13
+ import { STUDIO_BACKGROUND } from "../runtime-scope.js";
13
14
  /** The call's records reach the page through its own sink, so the bridge has no route to close. */
14
15
  const NO_ROUTE = { metadata: {}, close: () => { } };
15
16
  /**
@@ -59,8 +60,11 @@ async function relay(socket, profile, provider, boundary, { host }) {
59
60
  session = await runSession({
60
61
  ...(await boundary.prepareLiveOpen(open)),
61
62
  profile: profile.id,
63
+ execution: boundary.toolExecution,
64
+ pageExecution: boundary.pageExecution,
65
+ background: STUDIO_BACKGROUND,
62
66
  ...(host === undefined ? {} : { host }),
63
- }, { ...provider, execution: boundary.toolExecution, pageExecution: boundary.pageExecution }, pageSink(socket, profile));
67
+ }, provider, pageSink(socket, profile));
64
68
  }
65
69
  catch (error) {
66
70
  if (socket.readyState !== WebSocket.OPEN)
@@ -23,7 +23,7 @@ import { Thumbnail } from '@astryxdesign/core/Thumbnail';
23
23
  import { Token } from '@astryxdesign/core/Token';
24
24
  import { Tooltip } from '@astryxdesign/core/Tooltip';
25
25
  import { VStack } from '@astryxdesign/core/VStack';
26
- import { IconAbc, IconAdjustmentsHorizontal, IconAlertTriangle, IconAlignLeft, IconAntennaBars1, IconAntennaBars2, IconAntennaBars3, IconAntennaBars4, IconAntennaBars5, IconAntennaBarsOff, IconArrowDown, IconArrowLeft, IconArrowUp, IconBan, IconBandage, IconBiohazard, IconBolt, IconBraces, IconBulb, IconBulbOff, IconCertificate, IconCheck, IconChevronRight, IconCircleDashed, IconDatabase, IconDeviceDesktop, IconEraser, IconEye, IconEyeOff, IconFeather, IconFlag, IconFlame, IconFlask, IconFold, IconGauge, IconHandOff, IconHandStop, IconHeadset, IconHourglass, IconHttpDelete, IconHttpGet, IconHttpPatch, IconHttpPost, IconHttpPut, IconInfoCircle, IconInputAi, IconKey, IconLayersUnion, IconLockOpen, IconLogin, IconMessage, IconMicrophone, IconPackage, IconPaperclip, IconPencil, IconPlayerPause, IconPlayerPlay, IconPlayerStop, IconPlayerTrackNext, IconPlugConnected, IconPlus, IconRefresh, IconRegex, IconRuler, IconSearch, IconSend, IconServer, IconShieldLock, IconShieldOff, IconShieldSearch, IconSquareRoundedNumber0, IconSquareRoundedNumber2, IconTool, IconTrash, IconUser, IconUserCheck, IconWaveSine, IconWriting, IconX, } from '@tabler/icons-react';
26
+ import { IconAbc, IconAdjustmentsHorizontal, IconAlertTriangle, IconAlignLeft, IconAntennaBars1, IconAntennaBars2, IconAntennaBars3, IconAntennaBars4, IconAntennaBars5, IconAntennaBarsOff, IconArrowDown, IconArrowLeft, IconArrowUp, IconBan, IconBandage, IconBiohazard, IconBolt, IconBraces, IconBulb, IconBulbOff, IconCertificate, IconCheck, IconChevronRight, IconCircleDashed, IconClock, IconDatabase, IconDeviceDesktop, IconEraser, IconEye, IconEyeOff, IconFeather, IconFlag, IconFlame, IconFlask, IconFold, IconGauge, IconHandOff, IconHandStop, IconHeadset, IconHourglass, IconHttpDelete, IconHttpGet, IconHttpPatch, IconHttpPost, IconHttpPut, IconInfoCircle, IconInputAi, IconKey, IconLayersUnion, IconLockOpen, IconLogin, IconMessage, IconMessageQuestion, IconMicrophone, IconPackage, IconPaperclip, IconPencil, IconPlayerPause, IconPlayerPlay, IconPlayerStop, IconPlayerTrackNext, IconPlugConnected, IconPlus, IconRefresh, IconRegex, IconRuler, IconSearch, IconSend, IconServer, IconShieldLock, IconShieldOff, IconShieldSearch, IconSquareRoundedNumber0, IconSquareRoundedNumber2, IconTool, IconTrash, IconUser, IconUserCheck, IconWaveSine, IconWriting, IconX, } from '@tabler/icons-react';
27
27
  import { ATTACHMENT_ACCEPT_MIMES, CONTINUE_STOP_KINDS, fieldMeta, HTTP_METHODS, IMAGE_ATTACHMENT_ACCEPT_MIMES, labelDefault, PROFILE_HANDLE_MAX_CHARS, PROFILE_ID_MAX_CHARS, profileGraphFacet, SPEECH_AUDIO_FORMATS, THINKING_LEVELS, VOICE_ACCEPT_MIMES, } from '@theoremjs/agents';
28
28
  import { BOUNDARIES, BOUNDARY_META, DETECT_ACTION_META, DETECT_ACTIONS, DETECTOR_BOUNDARIES, DETECTOR_GROUP_META, DETECTOR_GROUPS, DETECTOR_META, DETECTORS, TOOL_BOUNDARIES, TOOL_KINDS, } from '@theoremjs/agents/guardrails';
29
29
  import { MODEL_SELECT_MIN_MODELS } from '@theoremjs/agents/interface';
@@ -227,9 +227,9 @@ function ModelPolicySection({ draft, type, set, }) {
227
227
  set({ allowModelSelect });
228
228
  } }), type !== 'embedding' && (_jsxs(_Fragment, { children: [_jsx(SegmentedRow, { label: "Conversation history kept by", path: "providerContinuation.history", field: "providerHistory", value: models.providerHistory ?? 'host', segments: HISTORY_HOLDER_SEGMENTS, onChange: (providerHistory) => {
229
229
  set({ providerHistory });
230
- } }), _jsx(NumberRow, { label: "Max steps", path: "profile.maxSteps", units: "steps", field: "maxSteps", value: models.maxSteps, min: 1, isIntegerOnly: true, onChange: (maxSteps) => {
230
+ } }), draftAllows(draft, 'profile.maxSteps') && (_jsx(NumberRow, { label: "Max steps", path: "profile.maxSteps", units: "steps", field: "maxSteps", value: models.maxSteps, min: 1, isIntegerOnly: true, onChange: (maxSteps) => {
231
231
  set({ maxSteps });
232
- } })] })), _jsx(SlotRow, { label: "Key slot", path: "models.*.keySlot", field: "key", value: models.key, onChange: (key) => {
232
+ } }))] })), _jsx(SlotRow, { label: "Key slot", path: "models.*.keySlot", field: "key", value: models.key, onChange: (key) => {
233
233
  set({ key });
234
234
  } }), _jsx(SlotRow, { label: "Fallback slot", path: "models.*.fallbackKeySlot", field: "fallbackKey", value: models.fallbackKey ?? '', onChange: (fallbackKey) => {
235
235
  set({ fallbackKey });
@@ -1864,6 +1864,24 @@ const PERMISSION_SEGMENTS = [
1864
1864
  { value: 'session_consent', label: 'Once a session', icon: IconUserCheck },
1865
1865
  { value: 'always_confirm', label: 'Every call', icon: IconHandStop },
1866
1866
  ];
1867
+ const BACKGROUND_SEGMENTS = [
1868
+ { value: 'never', label: 'Never', icon: IconPlayerPause },
1869
+ { value: 'ask', label: 'Model asks', icon: IconMessageQuestion },
1870
+ { value: 'always', label: 'Always', icon: IconPlayerTrackNext },
1871
+ { value: 'afterMs', label: 'After a time', icon: IconClock },
1872
+ ];
1873
+ /** A newly picked wait, until the builder sets their own. */
1874
+ const BACKGROUND_AFTER_MS = 10_000;
1875
+ function backgroundSegment(background) {
1876
+ if (typeof background === 'object')
1877
+ return 'afterMs';
1878
+ return background ?? 'never';
1879
+ }
1880
+ function backgroundOf(segment, afterMs) {
1881
+ if (segment === 'afterMs')
1882
+ return { afterMs: afterMs ?? BACKGROUND_AFTER_MS };
1883
+ return segment === 'never' ? undefined : segment;
1884
+ }
1867
1885
  const METHOD_SEGMENTS = [
1868
1886
  { value: 'GET', label: 'GET', icon: IconHttpGet },
1869
1887
  { value: 'POST', label: 'POST', icon: IconHttpPost },
@@ -2276,13 +2294,25 @@ function AuthSection({ tool, set }) {
2276
2294
  set({ authType: next });
2277
2295
  } }), authType !== 'none' && _jsx(AuthCredentialRows, { tool: tool, authType: authType, set: set }), authType === 'oauth2' && _jsx(OAuthRows, { tool: tool, set: set })] }));
2278
2296
  }
2297
+ /** When the model gets its reply: the setting, and the time for one that waits. */
2298
+ function BackgroundRows({ tool, set }) {
2299
+ const { background } = tool;
2300
+ const afterMs = typeof background === 'object' ? background.afterMs : null;
2301
+ return (_jsxs(_Fragment, { children: [_jsx(SegmentedRow, { label: "Background", path: "registerTool.background", field: "background", value: backgroundSegment(background), segments: BACKGROUND_SEGMENTS, onChange: (segment) => {
2302
+ set({ background: backgroundOf(segment, afterMs) });
2303
+ } }), afterMs === null ? null : (_jsx(NumberRow, { label: "After", path: "registerTool.background.afterMs", field: "background", value: afterMs, min: 0, isIntegerOnly: true, units: "ms", onChange: (next) => {
2304
+ if (next !== null)
2305
+ set({ background: { afterMs: next } });
2306
+ } }))] }));
2307
+ }
2279
2308
  /** Who may call the tool, whether it asks first, when it loads and on which paths. */
2280
2309
  function PolicySection({ draft, tool, set, }) {
2310
+ const isLoader = draft.tools.t2Loader.trim() === tool.toolName.trim();
2281
2311
  return (_jsxs(InspectorSection, { title: "Policy", children: [_jsx(SegmentedRow, { label: "Access", path: "registerTool.access", field: "access", value: tool.access, segments: ACCESS_SEGMENTS, onChange: (access) => {
2282
2312
  set({ access });
2283
2313
  } }), _jsx(SegmentedRow, { label: "Permission", path: "registerTool.permission", field: "permission", value: tool.permission, segments: PERMISSION_SEGMENTS, onChange: (permission) => {
2284
2314
  set({ permission });
2285
- } }), _jsx(SegmentedRow, { label: "Load tier", path: "registerTool.loadTier", field: "loadTier", value: tool.loadTier, segments: LOAD_TIER_SEGMENTS, warning: loadTierWarning(draft, tool.loadTier), onChange: (loadTier) => {
2315
+ } }), tool.answeredBy === 'page' || isLoader ? null : _jsx(BackgroundRows, { tool: tool, set: set }), _jsx(SegmentedRow, { label: "Load tier", path: "registerTool.loadTier", field: "loadTier", value: tool.loadTier, segments: LOAD_TIER_SEGMENTS, warning: loadTierWarning(draft, tool.loadTier), onChange: (loadTier) => {
2286
2316
  set({ loadTier });
2287
2317
  } }), _jsx(NamesRow, { label: "Paths", path: "registerTool.paths", field: "paths", value: tool.paths, placeholder: "Every path (*)", onChange: (paths) => {
2288
2318
  set({ paths });