@directive-run/ai 1.23.1 → 1.24.0

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 (93) hide show
  1. package/README.md +27 -0
  2. package/dist/anthropic.cjs +1 -1
  3. package/dist/anthropic.cjs.map +1 -1
  4. package/dist/anthropic.d.cts +33 -1
  5. package/dist/anthropic.d.ts +33 -1
  6. package/dist/anthropic.js +1 -1
  7. package/dist/anthropic.js.map +1 -1
  8. package/dist/{chunk-QMSLWAMH.cjs → chunk-25OLDNZ3.cjs} +3 -3
  9. package/dist/{chunk-QMSLWAMH.cjs.map → chunk-25OLDNZ3.cjs.map} +1 -1
  10. package/dist/chunk-2Y4YWZDV.js +3 -0
  11. package/dist/chunk-2Y4YWZDV.js.map +1 -0
  12. package/dist/{chunk-J2Q5KKPN.js → chunk-437ADRES.js} +3 -3
  13. package/dist/{chunk-J2Q5KKPN.js.map → chunk-437ADRES.js.map} +1 -1
  14. package/dist/{chunk-2FPL5W2H.cjs → chunk-4LENWYLG.cjs} +7 -7
  15. package/dist/{chunk-2FPL5W2H.cjs.map → chunk-4LENWYLG.cjs.map} +1 -1
  16. package/dist/chunk-4TDH6ZTX.cjs +3 -0
  17. package/dist/chunk-4TDH6ZTX.cjs.map +1 -0
  18. package/dist/{chunk-K64WKZ22.cjs → chunk-AEX7HKNM.cjs} +2 -2
  19. package/dist/chunk-AEX7HKNM.cjs.map +1 -0
  20. package/dist/{chunk-4VP67W7L.js → chunk-CMH5TJGN.js} +4 -4
  21. package/dist/{chunk-4VP67W7L.js.map → chunk-CMH5TJGN.js.map} +1 -1
  22. package/dist/{chunk-XGOTVPN6.js → chunk-EUB4NVVN.js} +3 -3
  23. package/dist/{chunk-XGOTVPN6.js.map → chunk-EUB4NVVN.js.map} +1 -1
  24. package/dist/{chunk-EW77VF5K.js → chunk-H7UFBMLV.js} +3 -3
  25. package/dist/{chunk-EW77VF5K.js.map → chunk-H7UFBMLV.js.map} +1 -1
  26. package/dist/{chunk-FSSCGRAM.js → chunk-L6H6Y6IK.js} +3 -3
  27. package/dist/{chunk-FSSCGRAM.js.map → chunk-L6H6Y6IK.js.map} +1 -1
  28. package/dist/{chunk-JMG5GZAH.cjs → chunk-L7QHLH6U.cjs} +4 -4
  29. package/dist/{chunk-JMG5GZAH.cjs.map → chunk-L7QHLH6U.cjs.map} +1 -1
  30. package/dist/{chunk-F73AKFDB.cjs → chunk-LPTC3N2Z.cjs} +7 -7
  31. package/dist/{chunk-F73AKFDB.cjs.map → chunk-LPTC3N2Z.cjs.map} +1 -1
  32. package/dist/{chunk-UR5BMWEN.js → chunk-XMEJN4FA.js} +2 -2
  33. package/dist/chunk-XMEJN4FA.js.map +1 -0
  34. package/dist/{chunk-XN5LUOVS.cjs → chunk-ZUNORULG.cjs} +7 -7
  35. package/dist/{chunk-XN5LUOVS.cjs.map → chunk-ZUNORULG.cjs.map} +1 -1
  36. package/dist/{debug-timeline-Sc9cxgxV.d.cts → debug-timeline-B_bXRStF.d.cts} +1 -1
  37. package/dist/{debug-timeline-C5Dzs2r_.d.ts → debug-timeline-Btt-iaak.d.ts} +1 -1
  38. package/dist/devtools.d.cts +5 -5
  39. package/dist/devtools.d.ts +5 -5
  40. package/dist/evals.cjs +1 -1
  41. package/dist/evals.d.cts +2 -2
  42. package/dist/evals.d.ts +2 -2
  43. package/dist/evals.js +1 -1
  44. package/dist/gemini.cjs +1 -1
  45. package/dist/gemini.d.cts +1 -1
  46. package/dist/gemini.d.ts +1 -1
  47. package/dist/gemini.js +1 -1
  48. package/dist/{guardrails-export-BL8ozXSj.d.ts → guardrails-export-lvaBJlt6.d.ts} +1 -1
  49. package/dist/{guardrails-export-ByaYNGvG.d.cts → guardrails-export-pmpQjIKb.d.cts} +1 -1
  50. package/dist/guardrails.cjs +1 -1
  51. package/dist/guardrails.d.cts +2 -2
  52. package/dist/guardrails.d.ts +2 -2
  53. package/dist/guardrails.js +1 -1
  54. package/dist/{health-monitor-C9v10_tj.d.cts → health-monitor-DqAzufyM.d.cts} +1 -1
  55. package/dist/{health-monitor-J2eKmP--.d.ts → health-monitor-DrlBF6n9.d.ts} +1 -1
  56. package/dist/index.cjs +4 -4
  57. package/dist/index.d.cts +12 -8
  58. package/dist/index.d.ts +12 -8
  59. package/dist/index.js +1 -1
  60. package/dist/{multi-agent-orchestrator-ZZ63F75F.js → multi-agent-orchestrator-PI7X7ZGP.js} +2 -2
  61. package/dist/{multi-agent-orchestrator-ZZ63F75F.js.map → multi-agent-orchestrator-PI7X7ZGP.js.map} +1 -1
  62. package/dist/multi-agent-orchestrator-Z5NK4HIJ.cjs +2 -0
  63. package/dist/{multi-agent-orchestrator-DUMT67N5.cjs.map → multi-agent-orchestrator-Z5NK4HIJ.cjs.map} +1 -1
  64. package/dist/multi-agent.cjs +1 -1
  65. package/dist/multi-agent.d.cts +6 -6
  66. package/dist/multi-agent.d.ts +6 -6
  67. package/dist/multi-agent.js +1 -1
  68. package/dist/ollama.cjs +1 -1
  69. package/dist/ollama.d.cts +1 -1
  70. package/dist/ollama.d.ts +1 -1
  71. package/dist/ollama.js +1 -1
  72. package/dist/openai.cjs +1 -1
  73. package/dist/openai.d.cts +1 -1
  74. package/dist/openai.d.ts +1 -1
  75. package/dist/openai.js +1 -1
  76. package/dist/{orchestrator-types-BT-NIFOe.d.cts → orchestrator-types-B9nrJYFx.d.cts} +3 -3
  77. package/dist/{orchestrator-types-DMuSD8Vq.d.ts → orchestrator-types-ByqFuu3O.d.ts} +3 -3
  78. package/dist/predicate.d.cts +1 -1
  79. package/dist/predicate.d.ts +1 -1
  80. package/dist/testing.cjs +1 -1
  81. package/dist/testing.d.cts +4 -4
  82. package/dist/testing.d.ts +4 -4
  83. package/dist/testing.js +1 -1
  84. package/dist/{types-6NoeLyrD.d.cts → types-BzpGfUA2.d.cts} +10 -0
  85. package/dist/{types-6NoeLyrD.d.ts → types-BzpGfUA2.d.ts} +10 -0
  86. package/package.json +2 -2
  87. package/dist/chunk-3WO4MWJM.cjs +0 -3
  88. package/dist/chunk-3WO4MWJM.cjs.map +0 -1
  89. package/dist/chunk-K64WKZ22.cjs.map +0 -1
  90. package/dist/chunk-UR5BMWEN.js.map +0 -1
  91. package/dist/chunk-ZFLHWJ56.js +0 -3
  92. package/dist/chunk-ZFLHWJ56.js.map +0 -1
  93. package/dist/multi-agent-orchestrator-DUMT67N5.cjs +0 -2
@@ -1,4 +1,4 @@
1
- import {q,f,r,g,i as i$1,k,m,o,p,n,s,x,w,h,c,d,e,l,j,a as a$2,u,t as t$1}from'./chunk-4VP67W7L.js';import {i,a as a$1,d as d$1,g as g$1}from'./chunk-UR5BMWEN.js';import {a,b}from'./chunk-FBT73WFY.js';import {b as b$1}from'./chunk-HRR45JZX.js';import {t,createModule,createSystem}from'@directive-run/core';import {requirementGuard,createCallbackPlugin,setBridgeFact,getBridgeFact}from'@directive-run/core/adapter-utils';var Qe=500,Ze=200,et=false;function xt(ve){let{runner:ne,factsSchema:be={},init:we,constraints:tt={},resolvers:nt={},guardrails:q$1={},onApprovalRequest:le,autoApproveToolCalls:de=true,maxTokenBudget:I,budgetWarningThreshold:re=.8,onBudgetWarning:Te,budgetEstimateTokens:ae,retryInsideCircuit:Re=false,plugins:rt=[],debug:Ae=false,approvalTimeoutMs:pe=3e5,agentRetry:oe,hooks:Se={},memory:M,circuitBreaker:j$1,selfHealing:R,outputSchema:at,maxSchemaRetries:ot,checkpointStore:Ce,breakpoints:_,onBreakpoint:st,breakpointTimeoutMs:it}=ve,D=typeof Ae=="object"?true:!!Ae,ge=5e3;if(D&&R&&!j$1&&console.warn("[Directive] selfHealing config has no effect without a circuitBreaker \u2014 fallback behavior requires the circuit breaker to detect failures."),re<0||re>1)throw new Error(`[Directive Orchestrator] budgetWarningThreshold must be between 0 and 1, got ${re}`);if(!de&&!le)throw new Error(`[Directive] Invalid approval configuration: autoApproveToolCalls is false but no onApprovalRequest callback provided. Tool calls would wait for approval indefinitely. Either:
1
+ import {q,f,r,g,i as i$1,k,m,o,p,n,s,x,w,h,c,d,e,l,j,a as a$2,u,t as t$1}from'./chunk-CMH5TJGN.js';import {i,a as a$1,d as d$1,g as g$1}from'./chunk-XMEJN4FA.js';import {a,b}from'./chunk-FBT73WFY.js';import {b as b$1}from'./chunk-HRR45JZX.js';import {t,createModule,createSystem}from'@directive-run/core';import {requirementGuard,createCallbackPlugin,setBridgeFact,getBridgeFact}from'@directive-run/core/adapter-utils';var Qe=500,Ze=200,et=false;function xt(ve){let{runner:ne,factsSchema:be={},init:we,constraints:tt={},resolvers:nt={},guardrails:q$1={},onApprovalRequest:le,autoApproveToolCalls:de=true,maxTokenBudget:I,budgetWarningThreshold:re=.8,onBudgetWarning:Te,budgetEstimateTokens:ae,retryInsideCircuit:Re=false,plugins:rt=[],debug:Ae=false,approvalTimeoutMs:pe=3e5,agentRetry:oe,hooks:Se={},memory:M,circuitBreaker:j$1,selfHealing:R,outputSchema:at,maxSchemaRetries:ot,checkpointStore:Ce,breakpoints:_,onBreakpoint:st,breakpointTimeoutMs:it}=ve,D=typeof Ae=="object"?true:!!Ae,ge=5e3;if(D&&R&&!j$1&&console.warn("[Directive] selfHealing config has no effect without a circuitBreaker \u2014 fallback behavior requires the circuit breaker to detect failures."),re<0||re>1)throw new Error(`[Directive Orchestrator] budgetWarningThreshold must be between 0 and 1, got ${re}`);if(!de&&!le)throw new Error(`[Directive] Invalid approval configuration: autoApproveToolCalls is false but no onApprovalRequest callback provided. Tool calls would wait for approval indefinitely. Either:
2
2
  - Set autoApproveToolCalls: true to auto-approve all tool calls
3
3
  - Provide an onApprovalRequest callback to handle approvals programmatically`);function W(e,t){try{Se[e]?.(t);}catch(a){D&&console.debug(`[Directive] hooks.${e} threw:`,a);}}let Oe=["agent","approval","conversation","toolCalls"];for(let e of Object.keys(be))if(Oe.includes(e))throw new Error(`[Directive] Facts schema key "${e}" conflicts with orchestrator state. Reserved keys: ${Oe.join(", ")}. Rename your fact to avoid the collision.`);let ut={facts:{...i.facts,...be,__budgetWarningFired:t.boolean()},derivations:{},events:{},requirements:{}},Ee,n$1,_e=q(tt);I&&(_e.__budgetLimit={priority:100,when:e=>f(e).tokenUsage>I,require:{type:"__PAUSE_BUDGET_EXCEEDED"}});let De=r(nt,(e,t,a,r)=>Ee(e,t,a,r),()=>n$1.facts);De.__pause={requirement:requirementGuard("__PAUSE_BUDGET_EXCEEDED"),resolve:async(e,t)=>{let a=f(t.facts);g(t.facts,{...a,status:"paused"});}};let y=null;D&&(y=a({getSnapshotId:()=>{try{return n$1.history?.currentIndex??null}catch{return null}},goToSnapshot:e=>{try{n$1.history?.goTo?.(e);}catch{}}}));let ct=createCallbackPlugin("directive-ai-callbacks",{}),lt=createModule("directive-ai-orchestrator",{schema:ut,init:e=>{if(g(e,{status:"idle",currentAgent:null,input:null,output:null,error:null,tokenUsage:0,turnCount:0,startedAt:null,completedAt:null}),i$1(e,{pending:[],approved:[],rejected:[]}),k(e,[]),m(e,[]),o(e,{pending:[],resolved:[],cancelled:[]}),setBridgeFact(e,"__budgetWarningFired",false),we){let t=p(e),a={...e,...t};we(a);}},constraints:_e,resolvers:De}),xe=[...rt,ct];D&&y&&xe.push(b(y,()=>{try{return n$1.history?.currentIndex??null}catch{return null}})),n$1=createSystem({module:lt,plugins:xe,history:D?true:void 0}),n$1.start();let $={count:0};function Be(e,t){if(ae===void 0)return 0;if(typeof ae=="number")return Math.max(0,Math.floor(ae));try{let a=ae(t,e);return Number.isFinite(a)?Math.max(0,Math.floor(a)):0}catch{return 0}}async function Ie(e,t,a,r,s){let c=0;if(I){let g=f(n$1.facts).tokenUsage;if(c=Be(e,t),g+$.count+c>I)throw new Error(`[Directive] Agent budget would be exceeded by this call: current=${g} + in-flight=${$.count} + estimate=${c} > maxTokenBudget=${I}. Raise \`maxTokenBudget\`, lower \`budgetEstimateTokens\`, or reset \`tokenUsage\`.`);$.count+=c;}try{return await dt(e,t,a,r,s)}finally{I&&c>0&&($.count=Math.max(0,$.count-c));}}async function Me(e,t,a){let r=Be(e,t);if(r<=0)return await a();$.count+=r;try{return await a()}finally{$.count=Math.max(0,$.count-r);}}async function $e(e,t,a,r){if(!R)throw e;if(R.fallbackRunners)for(let s of R.fallbackRunners)try{let c={originalAgent:t.name,reroutedTo:"fallback-runner",reason:e instanceof Error?e.message:String(e),timestamp:Date.now()};try{R.onReroute?.(c);}catch{}return y&&y.record({type:"reroute",timestamp:Date.now(),agentId:t.name,snapshotId:null,from:t.name,to:"fallback-runner",reason:e instanceof Error?e.message:String(e)}),await Me(t,a,()=>s(t,a,r))}catch{}if(R.fallbackAgent)try{let s={originalAgent:t.name,reroutedTo:R.fallbackAgent.name,reason:e instanceof Error?e.message:String(e),timestamp:Date.now()};try{R.onReroute?.(s);}catch{}y&&y.record({type:"reroute",timestamp:Date.now(),agentId:t.name,snapshotId:null,from:t.name,to:R.fallbackAgent.name,reason:e instanceof Error?e.message:String(e)});let c=R.fallbackAgent;return await Me(c,a,()=>ne(c,a,r))}catch{}if(R.degradation==="fallback-response"&&R.fallbackResponse!==void 0)return {output:R.fallbackResponse,messages:[],toolCalls:[],totalTokens:0};throw e}async function dt(e,t,a,r,s){if(j$1&&Re)try{return await j$1.execute(()=>Fe(e,t,a,r,s))}catch(c){return $e(c,e,t,r)}try{return await Fe(e,t,a,r,s)}catch(c){if(j$1||R)return $e(c,e,t,r);throw c}}async function Fe(e$1,t,a,r,s){let c$1=Date.now();if(M){let o=M.getContextMessages();if(o.length>0){let i=o.map(p=>`${p.role}: ${p.content}`).join(`
4
4
  `);e$1={...e$1,instructions:`${e$1.instructions??""}
@@ -12,5 +12,5 @@ Solutions:
12
12
  2. Set autoApproveToolCalls: true to auto-approve
13
13
  3. Increase approvalTimeoutMs (current: ${pe}ms)
14
14
  See: https://directive.run/docs/ai/running-agents`));},pe);})}function Pe(){return {...p(n$1.facts)}}return {system:n$1,get facts(){return Pe()},get totalTokens(){return f(n$1.facts).tokenUsage},get timeline(){return y},async run(e,t,a){return Ie(e,t,Pe(),void 0,a)},runStream(e$1,t,a={}){let r=new AbortController,s=1e4,c$1=[],g$1=[],b=false,F=Date.now(),C=0,A=1e5,l$1="",K;a.signal&&(K=()=>r.abort(),a.signal.addEventListener("abort",K,{once:true}));let ie=()=>{K&&a.signal&&a.signal.removeEventListener("abort",K);},h$1=d=>{if(b)return;let w=g$1.shift();w?w(d):(c$1.push(d),c$1.length>s&&c$1.shift());},o=()=>{b=true,ie();for(let d of g$1)d(null);g$1.length=0;},i=null,p=a.liveContext;if(p){if(p.mode!==void 0&&!et&&(et=true,console.warn("[Directive] liveContext.mode is deprecated and has no runtime behavior \u2014 the 1.x landing ships abort-and-emit only. Remove the field; automatic re-prompt semantics will return in a follow-up RFC.")),D&&p.system===n$1){let Y=["agent","conversation","approvalState"],u=p.keys.filter(k=>Y.some(T=>k.startsWith(T)));u.length>0&&console.warn(`[Directive] liveContext watches bridge-state keys (${u.join(", ")}) on the orchestrator's own system. The orchestrator's own setAgentState / setConversation / approvalState writes will trigger interruptWhen, self-looping the run. Use a separate system for liveContext, or scope \`keys\` to user-fact namespaces.`);}let d=p.notifyOn??"interrupt-only",w=p.interruptWhen??(()=>true),E=new Set(p.keys),X=p.system.facts.$store;if(typeof X?.subscribe=="function"){let Y=X.toObject?.()??{};i=X.subscribe(p.keys,()=>{if(b)return;let u=X.toObject?.()??{},k=[];for(let v of p.keys)u[v]!==Y[v]&&k.push(v);if(Y=u,k.length===0)return;let T=k.filter(v=>E.has(v));if(T.length===0)return;let f=false;try{f=w(u,T);}catch(v){console.error("[Directive] liveContext.interruptWhen threw \u2014 treating as non-interrupt",v),f=false;}try{p.onContextUpdate?.(T);}catch(v){console.error("[Directive] liveContext.onContextUpdate threw",v);}f?(h$1({type:"interrupted",reason:"liveContext.interruptWhen",partialOutput:l$1,changedKeys:T}),r.abort()):d==="all-changes"&&h$1({type:"context_updated",changedKeys:T});});}}let O=()=>{i&&(i(),i=null);},m$1=(async()=>{h$1({type:"progress",phase:"starting",message:"Running input guardrails"});try{let d$1=t,w=(q$1.input??[]).map((u,k)=>c(u,k,"input"));for(let u of w){let{name:k}=u,T={agentName:e$1.name,input:d$1,facts:n$1.facts.$store.toObject()},f=await d(u,{input:d$1,agentName:e$1.name},T);if(!f.passed)throw h$1({type:"guardrail_triggered",guardrailName:k,reason:f.reason??"Input validation failed",partialOutput:l$1,stopped:!0}),new a$1({code:"INPUT_GUARDRAIL_FAILED",message:`Input guardrail "${k}" failed: ${f.reason}`,guardrailName:k,guardrailType:"input",userMessage:f.reason??"Input validation failed",agentName:e$1.name,input:d$1});f.transformed!==void 0&&(d$1=f.transformed);}h$1({type:"progress",phase:"generating",message:"Starting agent"}),n$1.batch(()=>{let u=f(n$1.facts);g(n$1.facts,{...u,status:"running",currentAgent:e$1.name,input:d$1,startedAt:Date.now()});});let E=await e(ne,e$1,d$1,{signal:r.signal,onMessage:u=>{let k$1=j(n$1.facts);if(k(n$1.facts,[...k$1,u]),h$1({type:"message",message:u}),u.role==="assistant"&&u.content){let T=Math.ceil(u.content.length/4);C+=T,l$1+=u.content,l$1.length>A&&(l$1=l$1.slice(-A)),h$1({type:"token",data:u.content,tokenCount:C});}},onToolCall:async u=>{h$1({type:"tool_start",tool:u.name,toolCallId:u.id,arguments:u.arguments});let k=(q$1.toolCall??[]).map((f,v)=>c(f,v,"toolCall"));for(let f of k){let{name:v}=f,ue={agentName:e$1.name,input:d$1,facts:n$1.facts.$store.toObject()},ce=await d(f,{toolCall:u,agentName:e$1.name,input:d$1},ue);if(!ce.passed)throw h$1({type:"guardrail_triggered",guardrailName:v,reason:ce.reason??"Tool call blocked",partialOutput:l$1,stopped:!0}),new a$1({code:"TOOL_CALL_GUARDRAIL_FAILED",message:`Tool call guardrail "${v}" failed: ${ce.reason}`,guardrailName:v,guardrailType:"toolCall",userMessage:ce.reason??"Tool call blocked",data:{toolCall:u},agentName:e$1.name,input:d$1})}if(!de){let f=`tool-${u.id}`;h$1({type:"approval_required",requestId:f,toolName:u.name});let v={id:f,type:"tool_call",agentName:e$1.name,description:`Tool call: ${u.name}`,data:u,requestedAt:Date.now()};n$1.batch(()=>{let ue=h(n$1.facts);i$1(n$1.facts,{...ue,pending:[...ue.pending,v]});}),le?.(v),await Le(f,r.signal),h$1({type:"approval_resolved",requestId:f,approved:!0});}let T=l(n$1.facts);m(n$1.facts,[...T,u]),u.result&&h$1({type:"tool_end",tool:u.name,toolCallId:u.id,result:u.result});}},oe);h$1({type:"progress",phase:"finishing",message:"Running output guardrails"});let X=(q$1.output??[]).map((u,k)=>c(u,k,"output"));for(let u of X){let{name:k}=u,T={agentName:e$1.name,input:d$1,facts:n$1.facts.$store.toObject()},f=await d(u,{output:E.output,agentName:e$1.name,input:d$1,messages:E.messages},T);if(!f.passed)throw h$1({type:"guardrail_triggered",guardrailName:k,reason:f.reason??"Output validation failed",partialOutput:typeof E.output=="string"?E.output:"",stopped:!0}),new a$1({code:"OUTPUT_GUARDRAIL_FAILED",message:`Output guardrail "${k}" failed: ${f.reason}`,guardrailName:k,guardrailType:"output",userMessage:f.reason??"Output validation failed",agentName:e$1.name,input:d$1});f.transformed!==void 0&&(E.output=f.transformed);}n$1.batch(()=>{let u=f(n$1.facts);g(n$1.facts,{...u,status:"completed",output:E.output,tokenUsage:u.tokenUsage+E.totalTokens,turnCount:u.turnCount+E.messages.length,completedAt:Date.now()});});let Y=Date.now()-F;return h$1({type:"done",totalTokens:E.totalTokens,duration:Y,droppedTokens:0}),o(),E}catch(d){throw h$1({type:"error",error:d instanceof Error?d:new Error(String(d))}),o(),d}})();m$1.catch(()=>{});let x={[Symbol.asyncIterator](){return {async next(){return c$1.length>0?{done:false,value:c$1.shift()}:b?{done:true,value:void 0}:new Promise(d=>{g$1.push(w=>{d(w===null?{done:true,value:void 0}:{done:false,value:w});});})}}}},L=false;return m$1.finally(()=>{L||O();}).catch(()=>{}),{stream:x,result:m$1,abort:()=>{r.abort(),O(),o();},interrupt:d=>{L=true,h$1({type:"interrupted",reason:d??"caller.interrupt",partialOutput:l$1,changedKeys:[]}),r.abort();}}},async waitForIdle(e){let t=()=>f(n$1.facts).status!=="running";if(t())return;let a=Date.now();for(;!t();){if(e!==void 0&&Date.now()-a>e)throw new Error("[Directive Orchestrator] waitForIdle timed out");await new Promise(r=>setTimeout(r,50));}},approve(e){n$1.batch(()=>{let t=h(n$1.facts);if(!t.pending.some(s=>s.id===e)){D&&console.debug(`[Directive] approve() ignored: no pending request "${e}"`);return}let a=200,r=[...t.approved,e];i$1(n$1.facts,{...t,pending:t.pending.filter(s=>s.id!==e),approved:r.length>a?r.slice(-a):r});});},reject(e,t){n$1.batch(()=>{let a=h(n$1.facts);if(!a.pending.some(g=>g.id===e)){D&&console.debug(`[Directive] reject() ignored: no pending request "${e}"`);return}t&&D&&console.debug(`[Directive] Request ${e} rejected: ${t}`);let r={id:e,reason:t,rejectedAt:Date.now()},s=200,c=[...a.rejected,r];i$1(n$1.facts,{...a,pending:a.pending.filter(g=>g.id!==e),rejected:c.length>s?c.slice(-s):c});});},pause(){let e=f(n$1.facts);g(n$1.facts,{...e,status:"paused"});},resume(){let e=f(n$1.facts);e.status==="paused"&&g(n$1.facts,{...e,status:e.currentAgent?"running":"idle"});},reset(){n$1.batch(()=>{g(n$1.facts,{status:"idle",currentAgent:null,input:null,output:null,error:null,tokenUsage:0,turnCount:0,startedAt:null,completedAt:null}),i$1(n$1.facts,{pending:[],approved:[],rejected:[]}),k(n$1.facts,[]),m(n$1.facts,[]),o(n$1.facts,{pending:[],resolved:[],cancelled:[]}),setBridgeFact(n$1.facts,"__budgetWarningFired",false);}),H.clear(),Q.clear();},async checkpoint(e){if(f(n$1.facts).status==="running")throw new Error("[Directive] Cannot checkpoint while agent is running");if(!n$1.history?.export)throw new Error("[Directive] Checkpointing requires history. Set `debug: true` in orchestrator options.");let a={version:1,id:w(),createdAt:new Date().toISOString(),label:e?.label,systemExport:n$1.history.export(),timelineExport:y?.export()??null,localState:{type:"single"},memoryExport:M?M.export?.()??null:null,orchestratorType:"single"};return Ce&&await Ce.save(a),a},restore(e,t){if(!x(e))throw new Error("[Directive] Invalid checkpoint data");if(e.orchestratorType!=="single")throw new Error("[Directive] Cannot restore multi-agent checkpoint in single-agent orchestrator");if(!n$1.history?.import)throw new Error("[Directive] Restoring a checkpoint requires history. Set `debug: true` in orchestrator options.");n$1.history.import(e.systemExport),t?.restoreTimeline!==false&&e.timelineExport&&y&&y.import(e.timelineExport),e.memoryExport!==null&&M&&M.import&&M.import(e.memoryExport);},resumeBreakpoint(e,t){t&&H.set(e,t),n$1.batch(()=>{let a=n(n$1.facts),r=[...a.resolved,e];o(n$1.facts,{...a,pending:a.pending.filter(s=>s.id!==e),resolved:r.length>s?r.slice(-s):r});});},cancelBreakpoint(e,t){t&&Q.set(e,t),n$1.batch(()=>{let a=n(n$1.facts),r=[...a.cancelled,e];o(n$1.facts,{...a,pending:a.pending.filter(s=>s.id!==e),cancelled:r.length>s?r.slice(-s):r});});},getPendingBreakpoints(){return [...n(n$1.facts).pending]},destroy(){n$1.destroy();}}}
15
- export{xt as a};//# sourceMappingURL=chunk-XGOTVPN6.js.map
16
- //# sourceMappingURL=chunk-XGOTVPN6.js.map
15
+ export{xt as a};//# sourceMappingURL=chunk-EUB4NVVN.js.map
16
+ //# sourceMappingURL=chunk-EUB4NVVN.js.map