@directive-run/ai 1.12.0 → 1.14.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 (142) hide show
  1. package/dist/anthropic.cjs +1 -1
  2. package/dist/anthropic.d.cts +1 -1
  3. package/dist/anthropic.d.ts +1 -1
  4. package/dist/anthropic.js +1 -1
  5. package/dist/anthropic.js.map +1 -1
  6. package/dist/{chunk-XV2QSBBE.cjs → chunk-2TD4ZSGZ.cjs} +7 -7
  7. package/dist/{chunk-XV2QSBBE.cjs.map → chunk-2TD4ZSGZ.cjs.map} +1 -1
  8. package/dist/chunk-3WO4MWJM.cjs +3 -0
  9. package/dist/chunk-3WO4MWJM.cjs.map +1 -0
  10. package/dist/chunk-5JQ2A3JK.js +2 -0
  11. package/dist/chunk-5JQ2A3JK.js.map +1 -0
  12. package/dist/chunk-A22KLB23.cjs +67 -0
  13. package/dist/chunk-A22KLB23.cjs.map +1 -0
  14. package/dist/chunk-A5K77UDX.cjs +4 -0
  15. package/dist/chunk-A5K77UDX.cjs.map +1 -0
  16. package/dist/chunk-DN5NAJM6.js +6 -0
  17. package/dist/chunk-DN5NAJM6.js.map +1 -0
  18. package/dist/chunk-FABDFT74.cjs +6 -0
  19. package/dist/chunk-FABDFT74.cjs.map +1 -0
  20. package/dist/chunk-FBT73WFY.js +2 -0
  21. package/dist/chunk-FBT73WFY.js.map +1 -0
  22. package/dist/chunk-FFRWQNK7.cjs +7 -0
  23. package/dist/chunk-FFRWQNK7.cjs.map +1 -0
  24. package/dist/chunk-IR3IHBVQ.cjs +2 -0
  25. package/dist/chunk-IR3IHBVQ.cjs.map +1 -0
  26. package/dist/chunk-IUGSMTBE.js +16 -0
  27. package/dist/{chunk-Q3PQLWBR.js.map → chunk-IUGSMTBE.js.map} +1 -1
  28. package/dist/chunk-J2Q5KKPN.js +37 -0
  29. package/dist/chunk-J2Q5KKPN.js.map +1 -0
  30. package/dist/chunk-K64WKZ22.cjs +2 -0
  31. package/dist/chunk-K64WKZ22.cjs.map +1 -0
  32. package/dist/chunk-LKY4K5TV.cjs +11 -0
  33. package/dist/chunk-LKY4K5TV.cjs.map +1 -0
  34. package/dist/chunk-LXUMJKGJ.js +67 -0
  35. package/dist/chunk-LXUMJKGJ.js.map +1 -0
  36. package/dist/chunk-NNAQ4ZH2.js +11 -0
  37. package/dist/chunk-NNAQ4ZH2.js.map +1 -0
  38. package/dist/chunk-PD772MSE.cjs +30 -0
  39. package/dist/chunk-PD772MSE.cjs.map +1 -0
  40. package/dist/chunk-POBEEJR6.js +30 -0
  41. package/dist/chunk-POBEEJR6.js.map +1 -0
  42. package/dist/chunk-QRXWLD6H.js +4 -0
  43. package/dist/chunk-QRXWLD6H.js.map +1 -0
  44. package/dist/chunk-UR4ZGO7V.js +7 -0
  45. package/dist/chunk-UR4ZGO7V.js.map +1 -0
  46. package/dist/chunk-UR5BMWEN.js +2 -0
  47. package/dist/chunk-UR5BMWEN.js.map +1 -0
  48. package/dist/chunk-WOFIBIPW.cjs +2 -0
  49. package/dist/chunk-WOFIBIPW.cjs.map +1 -0
  50. package/dist/chunk-XN5LUOVS.cjs +37 -0
  51. package/dist/chunk-XN5LUOVS.cjs.map +1 -0
  52. package/dist/chunk-ZFLHWJ56.js +3 -0
  53. package/dist/chunk-ZFLHWJ56.js.map +1 -0
  54. package/dist/debug-timeline-DpnRMnLU.d.cts +87 -0
  55. package/dist/debug-timeline-L13P-U2I.d.ts +87 -0
  56. package/dist/devtools.cjs +2 -0
  57. package/dist/devtools.cjs.map +1 -0
  58. package/dist/devtools.d.cts +354 -0
  59. package/dist/devtools.d.ts +354 -0
  60. package/dist/devtools.js +2 -0
  61. package/dist/devtools.js.map +1 -0
  62. package/dist/evals.cjs +2 -0
  63. package/dist/evals.cjs.map +1 -0
  64. package/dist/evals.d.cts +361 -0
  65. package/dist/evals.d.ts +361 -0
  66. package/dist/evals.js +2 -0
  67. package/dist/evals.js.map +1 -0
  68. package/dist/gemini.cjs +1 -1
  69. package/dist/gemini.d.cts +1 -1
  70. package/dist/gemini.d.ts +1 -1
  71. package/dist/gemini.js +1 -1
  72. package/dist/gemini.js.map +1 -1
  73. package/dist/guardrails.cjs +2 -0
  74. package/dist/guardrails.cjs.map +1 -0
  75. package/dist/guardrails.d.cts +618 -0
  76. package/dist/guardrails.d.ts +618 -0
  77. package/dist/guardrails.js +2 -0
  78. package/dist/guardrails.js.map +1 -0
  79. package/dist/health-monitor-C6xoXrQz.d.cts +55 -0
  80. package/dist/health-monitor-qL9RNMH3.d.ts +55 -0
  81. package/dist/index.cjs +21 -99
  82. package/dist/index.cjs.map +1 -1
  83. package/dist/index.d.cts +1202 -4542
  84. package/dist/index.d.ts +1202 -4542
  85. package/dist/index.js +21 -99
  86. package/dist/index.js.map +1 -1
  87. package/dist/mcp.cjs +2 -0
  88. package/dist/mcp.cjs.map +1 -0
  89. package/dist/mcp.d.cts +450 -0
  90. package/dist/mcp.d.ts +450 -0
  91. package/dist/mcp.js +2 -0
  92. package/dist/mcp.js.map +1 -0
  93. package/dist/multi-agent-orchestrator-QWWQKKGX.js +2 -0
  94. package/dist/{multi-agent-orchestrator-4PXNYRHB.js.map → multi-agent-orchestrator-QWWQKKGX.js.map} +1 -1
  95. package/dist/multi-agent-orchestrator-Y5U4JCFO.cjs +2 -0
  96. package/dist/{multi-agent-orchestrator-KFGTEGE5.cjs.map → multi-agent-orchestrator-Y5U4JCFO.cjs.map} +1 -1
  97. package/dist/multi-agent.cjs +2 -0
  98. package/dist/multi-agent.cjs.map +1 -0
  99. package/dist/multi-agent.d.cts +1429 -0
  100. package/dist/multi-agent.d.ts +1429 -0
  101. package/dist/multi-agent.js +2 -0
  102. package/dist/multi-agent.js.map +1 -0
  103. package/dist/ollama.cjs +1 -1
  104. package/dist/ollama.d.cts +1 -1
  105. package/dist/ollama.d.ts +1 -1
  106. package/dist/ollama.js +2 -2
  107. package/dist/ollama.js.map +1 -1
  108. package/dist/openai.cjs +1 -1
  109. package/dist/openai.d.cts +2 -2
  110. package/dist/openai.d.ts +2 -2
  111. package/dist/openai.js +1 -1
  112. package/dist/openai.js.map +1 -1
  113. package/dist/{orchestrator-types-CTfIKk0W.d.ts → orchestrator-types-DGBhL6mc.d.ts} +5 -138
  114. package/dist/{orchestrator-types-Bh8r3_Sq.d.cts → orchestrator-types-DeIMRLR7.d.cts} +5 -138
  115. package/dist/predicate.cjs +2 -0
  116. package/dist/predicate.cjs.map +1 -0
  117. package/dist/predicate.d.cts +371 -0
  118. package/dist/predicate.d.ts +371 -0
  119. package/dist/predicate.js +2 -0
  120. package/dist/predicate.js.map +1 -0
  121. package/dist/{semantic-cache-nBpQqILc.d.cts → semantic-cache-DM7ev7NQ.d.cts} +1 -1
  122. package/dist/{semantic-cache-nBpQqILc.d.ts → semantic-cache-DM7ev7NQ.d.ts} +1 -1
  123. package/dist/testing.cjs +1 -1
  124. package/dist/testing.cjs.map +1 -1
  125. package/dist/testing.d.cts +4 -2
  126. package/dist/testing.d.ts +4 -2
  127. package/dist/testing.js +1 -1
  128. package/dist/testing.js.map +1 -1
  129. package/dist/{types-CRmwFnVk.d.cts → types-DJ09LjZX.d.cts} +1 -1
  130. package/dist/{types-CRmwFnVk.d.ts → types-DJ09LjZX.d.ts} +1 -1
  131. package/package.json +32 -2
  132. package/dist/chunk-Q3PQLWBR.js +0 -16
  133. package/dist/chunk-RW4R3O5P.js +0 -72
  134. package/dist/chunk-RW4R3O5P.js.map +0 -1
  135. package/dist/chunk-W6MVJKWN.cjs +0 -3
  136. package/dist/chunk-W6MVJKWN.cjs.map +0 -1
  137. package/dist/chunk-W6WZBQER.js +0 -3
  138. package/dist/chunk-W6WZBQER.js.map +0 -1
  139. package/dist/chunk-X3VQ5F7D.cjs +0 -72
  140. package/dist/chunk-X3VQ5F7D.cjs.map +0 -1
  141. package/dist/multi-agent-orchestrator-4PXNYRHB.js +0 -2
  142. package/dist/multi-agent-orchestrator-KFGTEGE5.cjs +0 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/testing.ts"],"names":["createMockAgentRunner","options","defaultResponse","responses","recordCalls","onRun","calls","responseMap","currentDefault","agent","input","runOptions","config","generated","resolve","messages","message","toolCalls","toolCall","name","testGuardrail","guardrail","testInput","context","data","fullContext","start","result","duration","expectedReason","expected","testGuardrailBatch","testCases","results","failures","i","testCase","createApprovalSimulator","autoApprove","autoReject","delay","recordRequests","requests","pendingRequests","requestWaiters","request","waiter","requestId","pending","reason","r","predicate","timeoutMs","existing","reject","entry","req","timeout","idx","createTestOrchestrator","mockResponses","defaultMockResponse","orchestratorOptions","mockRunner","approvalSimulator","orchestrator","createAgentOrchestrator","testOrchestrator","createConstraintRecorder","snapshots","assertOrchestratorState","state","min","max","exact","len","createTimeController","startTime","currentTime","initial","ms","time","createTestMultiAgentOrchestrator","mockTaskConfigs","existingTasks","taskId","createMockTask","responsesByName","agentId","registration","createMultiAgentOrchestrator","assertMultiAgentState","expectedStatus","allStates","total","sum","s","pendingCount","output","_input","signal","timer","createTestDag","nodes","merge","dag","assertDagExecution","nodeId","actual","expectedOutput","createTestTimeline","events","timeline","createDebugTimeline","event","assertTimelineEvents","type","e","expectedCount","createFailingRunner","error","callCount","failAfter","_agent","_runOptions","assertRerouted","assertAgentHealth","monitor","metrics","createTestCheckpointStore","maxCheckpoints","inner","InMemoryCheckpointStore","saved","checkpoint","id","assertCheckpoint","createBreakpointSimulator","hits","orchestratorRef","attached","doResolve","orch","assertBreakpointHit","h","types","agents","createMockSchema","validate","description","collectMultiplexedStream","stream","chunks","chunk","assertMultiplexedStream","seenAgents","c","createTestReflectionEvaluator","passAfter","feedback","score","_output","_context","passed","assertScratchpadState","scratchpad","all","key","expectedValue","assertDerivedValues","derived","sortedStringify","v"],"mappings":"gFA6IO,SAASA,EACdC,CAAAA,CAAkC,GACjB,CACjB,GAAM,CACJ,eAAA,CAAAC,CAAAA,CAAkB,CAAE,MAAA,CAAQ,gBAAiB,WAAA,CAAa,EAAG,EAC7D,SAAA,CAAAC,CAAAA,C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ent runners with configurable responses\n * - Guardrail testing with assertions\n * - Approval workflow simulation\n * - Snapshot testing for constraint evaluation\n *\n * @example\n * ```typescript\n * import { createMockAgentRunner, testGuardrail, createApprovalSimulator } from '@directive-run/ai/testing';\n *\n * describe('MyOrchestrator', () => {\n * it('should block PII in input', async () => {\n * const result = await testGuardrail(createPIIGuardrail(), {\n * input: 'My SSN is 123-45-6789',\n * });\n * expect(result.passed).toBe(false);\n * expect(result.reason).toContain('PII');\n * });\n * });\n * ```\n */\n\nimport {\n type AgentOrchestrator,\n type OrchestratorOptions,\n createAgentOrchestrator,\n} from \"./agent-orchestrator.js\";\nimport type {\n BreakpointModifications,\n BreakpointRequest,\n} from \"./breakpoints.js\";\nimport {\n type Checkpoint,\n type CheckpointStore,\n InMemoryCheckpointStore,\n} from \"./checkpoint.js\";\nimport {\n type MultiAgentOrchestrator,\n type MultiAgentOrchestratorOptions,\n type TaskRegistration,\n createMultiAgentOrchestrator,\n} from \"./multi-agent-orchestrator.js\";\nimport type { MultiplexedStreamChunk } from \"./streaming.js\";\nimport type {\n AgentLike,\n AgentRunner,\n ApprovalRequest,\n GuardrailContext,\n GuardrailFn,\n GuardrailResult,\n InputGuardrailData,\n Message,\n OutputGuardrailData,\n RunOptions,\n RunResult,\n ToolCall,\n ToolCallGuardrailData,\n} from \"./types.js\";\n\n// ============================================================================\n// Mock Agent Runner\n// ============================================================================\n\n/** Configuration for mock agent responses */\nexport interface MockAgentConfig<T = unknown> {\n /** Final output to return */\n output: T;\n /** Messages to emit during run */\n messages?: Message[];\n /** Tool calls to emit during run */\n toolCalls?: ToolCall[];\n /** Total tokens to report */\n totalTokens?: number;\n /** Delay before responding (ms) */\n delay?: number;\n /** Error to throw instead of returning */\n error?: Error;\n /** Function to generate dynamic responses */\n generate?: (input: string, agent: AgentLike) => Partial<MockAgentConfig<T>>;\n}\n\n/** Mock agent runner options */\nexport interface MockAgentRunnerOptions {\n /** Default response for unmatched agents */\n defaultResponse?: MockAgentConfig;\n /** Responses keyed by agent name */\n responses?: Record<string, MockAgentConfig>;\n /** Record all calls for assertions */\n recordCalls?: boolean;\n /** Callback for each run */\n onRun?: (agent: AgentLike, input: string) => void;\n}\n\n/** Recorded call for assertions */\nexport interface RecordedCall {\n agent: AgentLike;\n input: string;\n options?: RunOptions;\n timestamp: number;\n}\n\n/** Mock agent runner instance */\nexport interface MockAgentRunner {\n /** The run function to pass to orchestrator */\n run: AgentRunner;\n /** Get all recorded calls */\n getCalls(): RecordedCall[];\n /** Get calls for a specific agent */\n getCallsFor(agentName: string): RecordedCall[];\n /** Clear recorded calls */\n clearCalls(): void;\n /** Set response for an agent */\n setResponse<T>(agentName: string, config: MockAgentConfig<T>): void;\n /** Set default response */\n setDefaultResponse<T>(config: MockAgentConfig<T>): void;\n}\n\n/**\n * Create a mock agent runner for testing.\n *\n * @example\n * ```typescript\n * const mock = createMockAgentRunner({\n * responses: {\n * 'my-agent': {\n * output: 'Hello, world!',\n * totalTokens: 100,\n * },\n * },\n * });\n *\n * const orchestrator = createAgentOrchestrator({ runner: mock.run });\n * const result = await orchestrator.run(myAgent, 'Hi');\n *\n * expect(result.output).toBe('Hello, world!');\n * expect(mock.getCalls()).toHaveLength(1);\n * ```\n */\nexport function createMockAgentRunner(\n options: MockAgentRunnerOptions = {},\n): MockAgentRunner {\n const {\n defaultResponse = { output: \"mock response\", totalTokens: 10 },\n responses = {},\n recordCalls = true,\n onRun,\n } = options;\n\n const calls: RecordedCall[] = [];\n const responseMap = new Map<string, MockAgentConfig>(\n Object.entries(responses),\n );\n let currentDefault = defaultResponse;\n\n const run: AgentRunner = async <T>(\n agent: AgentLike,\n input: string,\n runOptions?: RunOptions,\n ): Promise<RunResult<T>> => {\n onRun?.(agent, input);\n\n if (recordCalls) {\n calls.push({\n agent,\n input,\n options: runOptions,\n timestamp: Date.now(),\n });\n }\n\n // Get config for this agent\n let config = responseMap.get(agent.name) ?? currentDefault;\n\n // Apply dynamic generation if present\n if (config.generate) {\n const generated = config.generate(input, agent);\n config = { ...config, ...generated };\n }\n\n // Handle error case\n if (config.error) {\n throw config.error;\n }\n\n // Apply delay\n if (config.delay && config.delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, config.delay));\n }\n\n // Emit messages\n const messages = config.messages ?? [];\n for (const message of messages) {\n runOptions?.onMessage?.(message);\n }\n\n // Emit tool calls\n const toolCalls = config.toolCalls ?? [];\n for (const toolCall of toolCalls) {\n runOptions?.onToolCall?.(toolCall);\n }\n\n return {\n output: config.output as T,\n messages,\n toolCalls,\n totalTokens: config.totalTokens ?? 10,\n };\n };\n\n return {\n run,\n getCalls: () => [...calls],\n getCallsFor: (name) => calls.filter((c) => c.agent.name === name),\n clearCalls: () => (calls.length = 0),\n setResponse: (name, config) => responseMap.set(name, config),\n setDefaultResponse: (config) => (currentDefault = config),\n };\n}\n\n// ============================================================================\n// Guardrail Testing\n// ============================================================================\n\n/** Test input for guardrail testing */\nexport type GuardrailTestInput<T> = T extends InputGuardrailData\n ? { input: string; agentName?: string }\n : T extends OutputGuardrailData\n ? {\n output: unknown;\n agentName?: string;\n input?: string;\n messages?: Message[];\n }\n : T extends ToolCallGuardrailData\n ? { toolCall: ToolCall; agentName?: string; input?: string }\n : Partial<T>;\n\n/** Extended guardrail result with test assertions */\nexport interface GuardrailTestResult extends GuardrailResult {\n /** Time taken to evaluate (ms) */\n duration: number;\n /** The data that was tested */\n testedData: unknown;\n /** Assert that the guardrail passed */\n assertPassed(): void;\n /** Assert that the guardrail failed */\n assertFailed(expectedReason?: string | RegExp): void;\n /** Assert that transformation occurred */\n assertTransformed(expected?: unknown): void;\n}\n\n/**\n * Test a guardrail with assertions.\n *\n * @example\n * ```typescript\n * // Test PII detection\n * const result = await testGuardrail(createPIIGuardrail(), {\n * input: 'My SSN is 123-45-6789',\n * });\n * result.assertFailed(/PII/);\n *\n * // Test input transformation\n * const redactResult = await testGuardrail(createPIIGuardrail({ redact: true }), {\n * input: 'My SSN is 123-45-6789',\n * });\n * redactResult.assertPassed();\n * redactResult.assertTransformed();\n * ```\n */\nexport async function testGuardrail<T>(\n guardrail: GuardrailFn<T>,\n testInput: GuardrailTestInput<T>,\n context?: Partial<GuardrailContext>,\n): Promise<GuardrailTestResult> {\n // Build full data object\n const data = {\n agentName: \"test-agent\",\n input: \"\",\n ...testInput,\n } as unknown as T;\n\n // Build context\n const fullContext: GuardrailContext = {\n agentName: (testInput as { agentName?: string }).agentName ?? \"test-agent\",\n input: (testInput as { input?: string }).input ?? \"\",\n facts: context?.facts ?? {},\n ...context,\n };\n\n const start = Date.now();\n const result = await guardrail(data, fullContext);\n const duration = Date.now() - start;\n\n return {\n ...result,\n duration,\n testedData: data,\n assertPassed() {\n if (!result.passed) {\n throw new Error(\n `Expected guardrail to pass, but it failed: ${result.reason}`,\n );\n }\n },\n assertFailed(expectedReason) {\n if (result.passed) {\n throw new Error(\"Expected guardrail to fail, but it passed\");\n }\n if (expectedReason !== undefined) {\n if (\n typeof expectedReason === \"string\" &&\n !result.reason?.includes(expectedReason)\n ) {\n throw new Error(\n `Expected failure reason to include \"${expectedReason}\", got: ${result.reason}`,\n );\n }\n if (\n expectedReason instanceof RegExp &&\n !expectedReason.test(result.reason ?? \"\")\n ) {\n throw new Error(\n `Expected failure reason to match ${expectedReason}, got: ${result.reason}`,\n );\n }\n }\n },\n assertTransformed(expected) {\n if (result.transformed === undefined) {\n throw new Error(\n \"Expected guardrail to transform input, but no transformation occurred\",\n );\n }\n if (expected !== undefined && result.transformed !== expected) {\n throw new Error(\n `Expected transformation to be ${JSON.stringify(expected)}, got: ${JSON.stringify(result.transformed)}`,\n );\n }\n },\n };\n}\n\n/**\n * Test multiple inputs against a guardrail.\n *\n * @example\n * ```typescript\n * const results = await testGuardrailBatch(createPIIGuardrail(), [\n * { input: 'Hello world', expect: 'pass' },\n * { input: 'My SSN is 123-45-6789', expect: 'fail' },\n * { input: 'Email: test@example.com', expect: 'fail' },\n * ]);\n *\n * expect(results.allPassed()).toBe(true);\n * ```\n */\nexport async function testGuardrailBatch<T>(\n guardrail: GuardrailFn<T>,\n testCases: Array<{\n input: GuardrailTestInput<T>;\n expect: \"pass\" | \"fail\" | \"transform\";\n context?: Partial<GuardrailContext>;\n }>,\n): Promise<{\n results: GuardrailTestResult[];\n allPassed(): boolean;\n failures(): Array<{\n index: number;\n expected: string;\n actual: GuardrailTestResult;\n }>;\n}> {\n const results: GuardrailTestResult[] = [];\n const failures: Array<{\n index: number;\n expected: string;\n actual: GuardrailTestResult;\n }> = [];\n\n for (let i = 0; i < testCases.length; i++) {\n const testCase = testCases[i]!;\n const result = await testGuardrail(\n guardrail,\n testCase.input,\n testCase.context,\n );\n results.push(result);\n\n const actualOutcome = !result.passed\n ? \"fail\"\n : result.transformed !== undefined\n ? \"transform\"\n : \"pass\";\n\n if (actualOutcome !== testCase.expect) {\n failures.push({ index: i, expected: testCase.expect, actual: result });\n }\n }\n\n return {\n results,\n allPassed: () => failures.length === 0,\n failures: () => failures,\n };\n}\n\n// ============================================================================\n// Approval Simulation\n// ============================================================================\n\n/** Approval simulator options */\nexport interface ApprovalSimulatorOptions {\n /** Auto-approve requests matching this predicate */\n autoApprove?: (request: ApprovalRequest) => boolean;\n /** Auto-reject requests matching this predicate */\n autoReject?: (request: ApprovalRequest) => boolean | string;\n /** Delay before auto-approval/rejection (ms) */\n delay?: number;\n /** Record all requests for assertions */\n recordRequests?: boolean;\n}\n\n/** Approval simulator instance */\nexport interface ApprovalSimulator {\n /** Handle an approval request */\n handle(request: ApprovalRequest): Promise<\"approved\" | \"rejected\">;\n /** Get all recorded requests */\n getRequests(): ApprovalRequest[];\n /** Clear recorded requests */\n clearRequests(): void;\n /** Manually approve a request */\n approve(requestId: string): void;\n /** Manually reject a request */\n reject(requestId: string, reason?: string): void;\n /** Wait for a specific request */\n waitForRequest(\n predicate: (req: ApprovalRequest) => boolean,\n timeoutMs?: number,\n ): Promise<ApprovalRequest>;\n}\n\n/**\n * Create an approval simulator for testing approval workflows.\n *\n * @example\n * ```typescript\n * const simulator = createApprovalSimulator({\n * autoApprove: (req) => req.type === 'tool_call' && req.data.name === 'search',\n * autoReject: (req) => req.type === 'tool_call' && req.data.name === 'delete',\n * });\n *\n * // Use in tests\n * orchestrator.onApprovalRequest = (req) => simulator.handle(req);\n * ```\n */\nexport function createApprovalSimulator(\n options: ApprovalSimulatorOptions = {},\n): ApprovalSimulator {\n const { autoApprove, autoReject, delay = 0, recordRequests = true } = options;\n\n const requests: ApprovalRequest[] = [];\n const pendingRequests = new Map<\n string,\n {\n request: ApprovalRequest;\n resolve: (decision: \"approved\" | \"rejected\") => void;\n }\n >();\n const requestWaiters: Array<{\n predicate: (req: ApprovalRequest) => boolean;\n resolve: (req: ApprovalRequest) => void;\n }> = [];\n\n return {\n async handle(request: ApprovalRequest): Promise<\"approved\" | \"rejected\"> {\n if (recordRequests) {\n requests.push(request);\n }\n\n // Notify waiters (resolve matching ones, remove them from array)\n for (let i = requestWaiters.length - 1; i >= 0; i--) {\n const waiter = requestWaiters[i]!;\n if (waiter.predicate(request)) {\n requestWaiters.splice(i, 1);\n waiter.resolve(request);\n }\n }\n\n // Apply delay\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n\n // Check auto-reject first (security-first)\n if (autoReject) {\n const rejectResult = autoReject(request);\n if (rejectResult) {\n return \"rejected\";\n }\n }\n\n // Check auto-approve\n if (autoApprove?.(request)) {\n return \"approved\";\n }\n\n // Wait for manual decision\n return new Promise((resolve) => {\n pendingRequests.set(request.id, { request, resolve });\n });\n },\n\n getRequests: () => [...requests],\n clearRequests: () => (requests.length = 0),\n\n approve(requestId: string) {\n const pending = pendingRequests.get(requestId);\n if (pending) {\n pending.resolve(\"approved\");\n pendingRequests.delete(requestId);\n }\n },\n\n reject(requestId: string, reason?: string) {\n const pending = pendingRequests.get(requestId);\n if (pending) {\n pending.resolve(\"rejected\");\n pendingRequests.delete(requestId);\n // Store reason on the request for test assertions\n const request = requests.find((r) => r.id === requestId);\n if (request) {\n (\n request as ApprovalRequest & { rejectionReason?: string }\n ).rejectionReason = reason;\n }\n }\n },\n\n waitForRequest(predicate, timeoutMs = 5000): Promise<ApprovalRequest> {\n // Check existing requests first\n const existing = requests.find(predicate);\n if (existing) {\n return Promise.resolve(existing);\n }\n\n // Wait for future request\n return new Promise((resolve, reject) => {\n const entry = {\n predicate,\n resolve: (req: ApprovalRequest) => {\n clearTimeout(timeout);\n resolve(req);\n },\n };\n\n const timeout = setTimeout(() => {\n const idx = requestWaiters.indexOf(entry);\n if (idx >= 0) {\n requestWaiters.splice(idx, 1);\n }\n reject(new Error(\"Timeout waiting for approval request\"));\n }, timeoutMs);\n\n requestWaiters.push(entry);\n });\n },\n };\n}\n\n// ============================================================================\n// Test Orchestrator Factory\n// ============================================================================\n\n/** Options for test orchestrator */\nexport interface TestOrchestratorOptions<F extends Record<string, unknown>>\n extends Omit<OrchestratorOptions<F>, \"runner\"> {\n /** Mock responses for agents */\n mockResponses?: Record<string, MockAgentConfig>;\n /** Default mock response */\n defaultMockResponse?: MockAgentConfig;\n}\n\n/** Test orchestrator with additional testing utilities */\nexport interface TestOrchestrator<F extends Record<string, unknown>>\n extends AgentOrchestrator<F> {\n /** The mock runner */\n mockRunner: MockAgentRunner;\n /** Approval simulator */\n approvalSimulator: ApprovalSimulator;\n /** Get recorded agent calls */\n getCalls(): RecordedCall[];\n /** Get approval requests */\n getApprovalRequests(): ApprovalRequest[];\n /** Reset all state */\n resetAll(): void;\n}\n\n/**\n * Create a test orchestrator with mocking and simulation built in.\n *\n * @example\n * ```typescript\n * const test = createTestOrchestrator({\n * mockResponses: {\n * 'my-agent': { output: 'test response' },\n * },\n * constraints: {\n * needsApproval: {\n * when: () => true,\n * require: { type: 'NEED_APPROVAL' },\n * },\n * },\n * });\n *\n * await test.run(myAgent, 'Hello');\n * expect(test.getCalls()).toHaveLength(1);\n * ```\n */\nexport function createTestOrchestrator<\n F extends Record<string, unknown> = Record<string, never>,\n>(options: TestOrchestratorOptions<F> = {}): TestOrchestrator<F> {\n const { mockResponses, defaultMockResponse, ...orchestratorOptions } =\n options;\n\n const mockRunner = createMockAgentRunner({\n responses: mockResponses,\n defaultResponse: defaultMockResponse,\n });\n\n const approvalSimulator = createApprovalSimulator();\n\n const orchestrator = createAgentOrchestrator<F>({\n ...orchestratorOptions,\n runner: mockRunner.run,\n onApprovalRequest: (req) => {\n approvalSimulator.handle(req);\n orchestratorOptions.onApprovalRequest?.(req);\n },\n });\n\n // Use Object.create to preserve getters instead of { ...orchestrator } which evaluates them once\n const testOrchestrator = Object.create(orchestrator) as TestOrchestrator<F>;\n testOrchestrator.mockRunner = mockRunner;\n testOrchestrator.approvalSimulator = approvalSimulator;\n testOrchestrator.getCalls = () => mockRunner.getCalls();\n testOrchestrator.getApprovalRequests = () => approvalSimulator.getRequests();\n testOrchestrator.resetAll = () => {\n orchestrator.reset();\n mockRunner.clearCalls();\n approvalSimulator.clearRequests();\n };\n\n return testOrchestrator;\n}\n\n// ============================================================================\n// Snapshot Testing\n// ============================================================================\n\n/** Constraint evaluation snapshot */\nexport interface ConstraintSnapshot {\n constraintId: string;\n triggered: boolean;\n requirement?: unknown;\n facts: Record<string, unknown>;\n timestamp: number;\n}\n\n/**\n * Create a constraint evaluation recorder for snapshot testing.\n *\n * @example\n * ```typescript\n * const recorder = createConstraintRecorder();\n * const orchestrator = createAgentOrchestrator({\n * plugins: [recorder.plugin],\n * });\n *\n * await orchestrator.run(agent, 'Hello');\n *\n * expect(recorder.getSnapshots()).toMatchSnapshot();\n * ```\n */\nexport function createConstraintRecorder(): {\n plugin: {\n name: string;\n onRequirementCreated: (data: {\n constraintId: string;\n requirement: unknown;\n facts: unknown;\n }) => void;\n };\n getSnapshots(): ConstraintSnapshot[];\n clearSnapshots(): void;\n} {\n const snapshots: ConstraintSnapshot[] = [];\n\n return {\n plugin: {\n name: \"constraint-recorder\",\n onRequirementCreated(data) {\n snapshots.push({\n constraintId: data.constraintId,\n triggered: true,\n requirement: data.requirement,\n facts: data.facts as Record<string, unknown>,\n timestamp: Date.now(),\n });\n },\n },\n getSnapshots: () => [...snapshots],\n clearSnapshots: () => (snapshots.length = 0),\n };\n}\n\n// ============================================================================\n// Assertion Helpers\n// ============================================================================\n\n/**\n * Assert that an orchestrator has specific state.\n *\n * @example\n * ```typescript\n * assertOrchestratorState(orchestrator, {\n * agentStatus: 'completed',\n * tokenUsage: { min: 0, max: 1000 },\n * pendingApprovals: 0,\n * });\n * ```\n */\nexport function assertOrchestratorState<F extends Record<string, unknown>>(\n orchestrator: AgentOrchestrator<F>,\n expected: {\n agentStatus?: \"idle\" | \"running\" | \"paused\" | \"completed\" | \"error\";\n tokenUsage?: { min?: number; max?: number; exact?: number };\n pendingApprovals?: number;\n conversationLength?: { min?: number; max?: number; exact?: number };\n },\n): void {\n const state = orchestrator.facts;\n\n if (\n expected.agentStatus !== undefined &&\n state.agent.status !== expected.agentStatus\n ) {\n throw new Error(\n `Expected agent status to be \"${expected.agentStatus}\", got \"${state.agent.status}\"`,\n );\n }\n\n if (expected.tokenUsage !== undefined) {\n const { min, max, exact } = expected.tokenUsage;\n if (exact !== undefined && state.agent.tokenUsage !== exact) {\n throw new Error(\n `Expected token usage to be exactly ${exact}, got ${state.agent.tokenUsage}`,\n );\n }\n if (min !== undefined && state.agent.tokenUsage < min) {\n throw new Error(\n `Expected token usage to be at least ${min}, got ${state.agent.tokenUsage}`,\n );\n }\n if (max !== undefined && state.agent.tokenUsage > max) {\n throw new Error(\n `Expected token usage to be at most ${max}, got ${state.agent.tokenUsage}`,\n );\n }\n }\n\n if (\n expected.pendingApprovals !== undefined &&\n state.approval.pending.length !== expected.pendingApprovals\n ) {\n throw new Error(\n `Expected ${expected.pendingApprovals} pending approvals, got ${state.approval.pending.length}`,\n );\n }\n\n if (expected.conversationLength !== undefined) {\n const { min, max, exact } = expected.conversationLength;\n const len = state.conversation.length;\n if (exact !== undefined && len !== exact) {\n throw new Error(\n `Expected conversation length to be exactly ${exact}, got ${len}`,\n );\n }\n if (min !== undefined && len < min) {\n throw new Error(\n `Expected conversation length to be at least ${min}, got ${len}`,\n );\n }\n if (max !== undefined && len > max) {\n throw new Error(\n `Expected conversation length to be at most ${max}, got ${len}`,\n );\n }\n }\n}\n\n// ============================================================================\n// Fake Timers Support\n// ============================================================================\n\n/**\n * Create a time controller for testing time-dependent behavior.\n *\n * @example\n * ```typescript\n * const time = createTimeController();\n *\n * // Override Date.now\n * const originalNow = Date.now;\n * Date.now = () => time.now();\n *\n * time.advance(1000); // Advance 1 second\n *\n * // Restore\n * Date.now = originalNow;\n * ```\n */\nexport function createTimeController(startTime = Date.now()): {\n now(): number;\n advance(ms: number): void;\n set(time: number): void;\n reset(): void;\n} {\n let currentTime = startTime;\n const initial = startTime;\n\n return {\n now: () => currentTime,\n advance: (ms) => {\n currentTime += ms;\n },\n set: (time) => {\n currentTime = time;\n },\n reset: () => {\n currentTime = initial;\n },\n };\n}\n\n// ============================================================================\n// Multi-Agent Test Orchestrator\n// ============================================================================\n\n/** Options for test multi-agent orchestrator */\nexport interface TestMultiAgentOrchestratorOptions\n extends Omit<MultiAgentOrchestratorOptions, \"runner\"> {\n /** Mock responses keyed by agent ID — internally mapped to agent names for the mock runner */\n mockResponses?: Record<string, MockAgentConfig>;\n /** Default mock response for unmatched agents */\n defaultMockResponse?: MockAgentConfig;\n /** Mock tasks keyed by task ID — auto-generates TaskRegistration wrappers */\n mockTasks?: Record<\n string,\n { output: unknown; delay?: number; shouldError?: boolean }\n >;\n}\n\n/** Test multi-agent orchestrator with additional testing utilities */\nexport interface TestMultiAgentOrchestrator extends MultiAgentOrchestrator {\n /** The mock runner */\n mockRunner: MockAgentRunner;\n /** Approval simulator */\n approvalSimulator: ApprovalSimulator;\n /** Get recorded agent calls */\n getCalls(): RecordedCall[];\n /** Get approval requests */\n getApprovalRequests(): ApprovalRequest[];\n /** Reset all state */\n resetAll(): void;\n}\n\n/**\n * Create a test multi-agent orchestrator with mocking and simulation built in.\n *\n * @example\n * ```typescript\n * const test = createTestMultiAgentOrchestrator({\n * agents: {\n * researcher: { agent: { name: 'researcher' } },\n * writer: { agent: { name: 'writer' } },\n * },\n * mockResponses: {\n * researcher: { output: 'Research results', totalTokens: 100 },\n * writer: { output: 'Written article', totalTokens: 200 },\n * },\n * });\n *\n * const result = await test.runAgent('researcher', 'What is AI?');\n * expect(result.output).toBe('Research results');\n * expect(test.getCalls()).toHaveLength(1);\n * ```\n */\nexport function createTestMultiAgentOrchestrator(\n options: TestMultiAgentOrchestratorOptions,\n): TestMultiAgentOrchestrator {\n const {\n mockResponses = {},\n defaultMockResponse,\n mockTasks: mockTaskConfigs,\n ...orchestratorOptions\n } = options;\n\n // Convert mockTasks into real TaskRegistration entries\n if (mockTaskConfigs) {\n const existingTasks = orchestratorOptions.tasks ?? {};\n for (const [taskId, config] of Object.entries(mockTaskConfigs)) {\n if (!existingTasks[taskId]) {\n existingTasks[taskId] = createMockTask(config.output, {\n delay: config.delay,\n shouldError: config.shouldError,\n });\n }\n }\n orchestratorOptions.tasks = existingTasks;\n }\n\n // Map mock responses by agent name (from agent registration)\n const responsesByName: Record<string, MockAgentConfig> = {};\n for (const [agentId, config] of Object.entries(mockResponses)) {\n const registration = orchestratorOptions.agents[agentId];\n if (registration) {\n responsesByName[registration.agent.name] = config;\n }\n }\n\n const mockRunner = createMockAgentRunner({\n responses: responsesByName,\n defaultResponse: defaultMockResponse,\n });\n\n const approvalSimulator = createApprovalSimulator();\n\n const orchestrator = createMultiAgentOrchestrator({\n ...orchestratorOptions,\n runner: mockRunner.run,\n onApprovalRequest: (req) => {\n approvalSimulator.handle(req);\n orchestratorOptions.onApprovalRequest?.(req);\n },\n });\n\n // Use Object.create to preserve getters (derived, scratchpad, timeline, etc.)\n // instead of { ...orchestrator } which evaluates getters at spread time\n const testOrchestrator = Object.create(\n orchestrator,\n ) as TestMultiAgentOrchestrator;\n testOrchestrator.mockRunner = mockRunner;\n testOrchestrator.approvalSimulator = approvalSimulator;\n testOrchestrator.getCalls = () => mockRunner.getCalls();\n testOrchestrator.getApprovalRequests = () => approvalSimulator.getRequests();\n testOrchestrator.resetAll = () => {\n orchestrator.reset();\n mockRunner.clearCalls();\n approvalSimulator.clearRequests();\n };\n\n return testOrchestrator;\n}\n\n// ============================================================================\n// Multi-Agent Assertion Helpers\n// ============================================================================\n\n/**\n * Assert that a multi-agent orchestrator has specific state.\n *\n * @example\n * ```typescript\n * assertMultiAgentState(orchestrator, {\n * agentStatus: { researcher: 'completed', writer: 'idle' },\n * globalTokens: { min: 0, max: 1000 },\n * pendingHandoffs: 0,\n * });\n * ```\n */\nexport function assertMultiAgentState(\n orchestrator: MultiAgentOrchestrator,\n expected: {\n agentStatus?: Record<string, \"idle\" | \"running\" | \"completed\" | \"error\">;\n taskStatus?: Record<string, string>;\n totalTokens?: { agentId?: string; min?: number; max?: number };\n globalTokens?: { min?: number; max?: number };\n pendingHandoffs?: number;\n },\n): void {\n if (expected.taskStatus) {\n for (const [taskId, expectedStatus] of Object.entries(\n expected.taskStatus,\n )) {\n const state = orchestrator.getTaskState(taskId);\n if (!state) {\n throw new Error(\n `Expected task \"${taskId}\" to exist, but it was not found`,\n );\n }\n if (state.status !== expectedStatus) {\n throw new Error(\n `Expected task \"${taskId}\" status to be \"${expectedStatus}\", got \"${state.status}\"`,\n );\n }\n }\n }\n\n if (expected.agentStatus) {\n for (const [agentId, expectedStatus] of Object.entries(\n expected.agentStatus,\n )) {\n const state = orchestrator.getAgentState(agentId);\n if (!state) {\n throw new Error(\n `Expected agent \"${agentId}\" to exist, but it was not found`,\n );\n }\n if (state.status !== expectedStatus) {\n throw new Error(\n `Expected agent \"${agentId}\" status to be \"${expectedStatus}\", got \"${state.status}\"`,\n );\n }\n }\n }\n\n if (expected.totalTokens) {\n const { agentId, min, max } = expected.totalTokens;\n if (agentId) {\n const state = orchestrator.getAgentState(agentId);\n if (!state) {\n throw new Error(\n `Expected agent \"${agentId}\" to exist, but it was not found`,\n );\n }\n if (min !== undefined && state.totalTokens < min) {\n throw new Error(\n `Expected agent \"${agentId}\" tokens to be at least ${min}, got ${state.totalTokens}`,\n );\n }\n if (max !== undefined && state.totalTokens > max) {\n throw new Error(\n `Expected agent \"${agentId}\" tokens to be at most ${max}, got ${state.totalTokens}`,\n );\n }\n } else {\n const allStates = orchestrator.getAllAgentStates();\n const total = Object.values(allStates).reduce(\n (sum, s) => sum + s.totalTokens,\n 0,\n );\n if (min !== undefined && total < min) {\n throw new Error(\n `Expected total tokens to be at least ${min}, got ${total}`,\n );\n }\n if (max !== undefined && total > max) {\n throw new Error(\n `Expected total tokens to be at most ${max}, got ${total}`,\n );\n }\n }\n }\n\n if (expected.globalTokens) {\n const { min, max } = expected.globalTokens;\n const total = orchestrator.totalTokens;\n if (min !== undefined && total < min) {\n throw new Error(\n `Expected global tokens to be at least ${min}, got ${total}`,\n );\n }\n if (max !== undefined && total > max) {\n throw new Error(\n `Expected global tokens to be at most ${max}, got ${total}`,\n );\n }\n }\n\n if (expected.pendingHandoffs !== undefined) {\n const pendingCount = orchestrator.getPendingHandoffs().length;\n if (pendingCount !== expected.pendingHandoffs) {\n throw new Error(\n `Expected ${expected.pendingHandoffs} pending handoffs, got ${pendingCount}`,\n );\n }\n }\n}\n\n// ============================================================================\n// Mock Task Helpers\n// ============================================================================\n\n/**\n * Create a mock TaskRegistration for testing.\n *\n * @example\n * ```typescript\n * const task = createMockTask({ result: \"processed\" }, { delay: 100 });\n * const orchestrator = createTestMultiAgentOrchestrator({\n * agents: { writer: { agent: { name: \"writer\" } } },\n * tasks: { process: task },\n * });\n * ```\n */\nexport function createMockTask(\n output: unknown,\n options?: {\n delay?: number;\n shouldError?: boolean;\n label?: string;\n description?: string;\n },\n): TaskRegistration {\n return {\n run: async (_input: string, signal: AbortSignal) => {\n if (signal.aborted) {\n throw new Error(\"Task aborted\");\n }\n if (options?.delay && options.delay > 0) {\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(resolve, options.delay);\n signal.addEventListener(\n \"abort\",\n () => {\n clearTimeout(timer);\n reject(new Error(\"Task aborted\"));\n },\n { once: true },\n );\n });\n }\n\n if (options?.shouldError) {\n throw new Error(\"Mock task error\");\n }\n\n return output;\n },\n label: options?.label ?? \"Mock Task\",\n description: options?.description,\n };\n}\n\n// ============================================================================\n// DAG Testing Helpers\n// ============================================================================\n\nimport { dag } from \"./multi-agent-orchestrator.js\";\nimport type {\n DagExecutionContext,\n DagNode,\n DagNodeStatus,\n DagPattern,\n} from \"./types.js\";\n\n/**\n * Create a test DAG pattern from a simplified node spec.\n *\n * @example\n * ```typescript\n * const pattern = createTestDag({\n * A: { handler: \"researcher\" },\n * B: { handler: \"writer\", deps: [\"A\"] },\n * C: { handler: \"reviewer\", deps: [\"B\"] },\n * });\n * ```\n */\nexport function createTestDag<T = unknown>(\n nodes: Record<\n string,\n Pick<\n DagNode,\n \"handler\" | \"deps\" | \"when\" | \"transform\" | \"timeout\" | \"priority\"\n >\n >,\n merge?: (context: DagExecutionContext) => T | Promise<T>,\n options?: {\n timeout?: number;\n maxConcurrent?: number;\n onNodeError?: \"fail\" | \"skip-downstream\" | \"continue\";\n },\n): DagPattern<T> {\n const defaultMerge = (context: DagExecutionContext) =>\n context.outputs as unknown as T;\n\n return dag<T>(nodes, merge ?? defaultMerge, options);\n}\n\n/**\n * Assert that a DAG execution produced the expected node statuses.\n *\n * @example\n * ```typescript\n * assertDagExecution(context, {\n * nodeStatuses: { A: \"completed\", B: \"completed\", C: \"skipped\" },\n * completedNodes: [\"A\", \"B\"],\n * skippedNodes: [\"C\"],\n * });\n * ```\n */\nexport function assertDagExecution(\n context: DagExecutionContext,\n expected: {\n nodeStatuses?: Record<string, DagNodeStatus>;\n completedNodes?: string[];\n skippedNodes?: string[];\n errorNodes?: string[];\n outputContains?: Record<string, unknown>;\n },\n): void {\n if (expected.nodeStatuses) {\n for (const [nodeId, expectedStatus] of Object.entries(\n expected.nodeStatuses,\n )) {\n const actual = context.statuses[nodeId];\n if (actual !== expectedStatus) {\n throw new Error(\n `Expected node \"${nodeId}\" status to be \"${expectedStatus}\", got \"${actual}\"`,\n );\n }\n }\n }\n\n if (expected.completedNodes) {\n for (const nodeId of expected.completedNodes) {\n if (context.statuses[nodeId] !== \"completed\") {\n throw new Error(\n `Expected node \"${nodeId}\" to be completed, got \"${context.statuses[nodeId]}\"`,\n );\n }\n }\n }\n\n if (expected.skippedNodes) {\n for (const nodeId of expected.skippedNodes) {\n if (context.statuses[nodeId] !== \"skipped\") {\n throw new Error(\n `Expected node \"${nodeId}\" to be skipped, got \"${context.statuses[nodeId]}\"`,\n );\n }\n }\n }\n\n if (expected.errorNodes) {\n for (const nodeId of expected.errorNodes) {\n if (context.statuses[nodeId] !== \"error\") {\n throw new Error(\n `Expected node \"${nodeId}\" to be error, got \"${context.statuses[nodeId]}\"`,\n );\n }\n }\n }\n\n if (expected.outputContains) {\n for (const [nodeId, expectedOutput] of Object.entries(\n expected.outputContains,\n )) {\n const actual = context.outputs[nodeId];\n if (actual !== expectedOutput) {\n throw new Error(\n `Expected node \"${nodeId}\" output to be ${JSON.stringify(expectedOutput)}, got ${JSON.stringify(actual)}`,\n );\n }\n }\n }\n}\n\n// ============================================================================\n// Debug Timeline Testing Helpers\n// ============================================================================\n\nimport { type DebugTimeline, createDebugTimeline } from \"./debug-timeline.js\";\nimport type { DebugEvent, DebugEventType } from \"./types.js\";\n\n/**\n * Create a test debug timeline pre-populated with events.\n *\n * @example\n * ```typescript\n * const timeline = createTestTimeline([\n * { type: \"agent_start\", agentId: \"researcher\", inputLength: 42 },\n * { type: \"agent_complete\", agentId: \"researcher\", outputLength: 100, durationMs: 500, totalTokens: 200 },\n * ]);\n *\n * expect(timeline.getEventsForAgent(\"researcher\")).toHaveLength(2);\n * ```\n */\nexport function createTestTimeline(\n events?: Array<Partial<DebugEvent> & { type: DebugEventType }>,\n options?: { maxEvents?: number },\n): DebugTimeline {\n const timeline = createDebugTimeline({\n maxEvents: options?.maxEvents ?? 500,\n });\n\n if (events) {\n for (const event of events) {\n timeline.record({\n timestamp: Date.now(),\n snapshotId: null,\n agentId: \"\",\n ...event,\n } as Omit<DebugEvent, \"id\">);\n }\n }\n\n return timeline;\n}\n\n/**\n * Assert that a debug timeline contains expected events.\n *\n * @example\n * ```typescript\n * assertTimelineEvents(timeline, {\n * totalEvents: 5,\n * eventTypes: [\"agent_start\", \"guardrail_check\", \"agent_complete\"],\n * agentEvents: { researcher: 3, writer: 2 },\n * hasType: \"guardrail_check\",\n * });\n * ```\n */\nexport function assertTimelineEvents(\n timeline: DebugTimeline,\n expected: {\n totalEvents?: number;\n minEvents?: number;\n maxEvents?: number;\n eventTypes?: DebugEventType[];\n agentEvents?: Record<string, number>;\n hasType?: DebugEventType;\n doesNotHaveType?: DebugEventType;\n },\n): void {\n const events = timeline.getEvents();\n\n if (\n expected.totalEvents !== undefined &&\n events.length !== expected.totalEvents\n ) {\n throw new Error(\n `Expected ${expected.totalEvents} timeline events, got ${events.length}`,\n );\n }\n\n if (expected.minEvents !== undefined && events.length < expected.minEvents) {\n throw new Error(\n `Expected at least ${expected.minEvents} timeline events, got ${events.length}`,\n );\n }\n\n if (expected.maxEvents !== undefined && events.length > expected.maxEvents) {\n throw new Error(\n `Expected at most ${expected.maxEvents} timeline events, got ${events.length}`,\n );\n }\n\n if (expected.eventTypes) {\n for (const type of expected.eventTypes) {\n const found = events.some((e) => e.type === type);\n if (!found) {\n throw new Error(\n `Expected timeline to contain event of type \"${type}\", but none found`,\n );\n }\n }\n }\n\n if (expected.agentEvents) {\n for (const [agentId, expectedCount] of Object.entries(\n expected.agentEvents,\n )) {\n const actual = timeline.getEventsForAgent(agentId).length;\n if (actual !== expectedCount) {\n throw new Error(\n `Expected ${expectedCount} events for agent \"${agentId}\", got ${actual}`,\n );\n }\n }\n }\n\n if (expected.hasType) {\n const found = events.some((e) => e.type === expected.hasType);\n if (!found) {\n throw new Error(\n `Expected timeline to contain event of type \"${expected.hasType}\"`,\n );\n }\n }\n\n if (expected.doesNotHaveType) {\n const found = events.some((e) => e.type === expected.doesNotHaveType);\n if (found) {\n throw new Error(\n `Expected timeline NOT to contain event of type \"${expected.doesNotHaveType}\"`,\n );\n }\n }\n}\n\n// ============================================================================\n// Self-Healing Testing Helpers\n// ============================================================================\n\nimport type { HealthMonitor } from \"./health-monitor.js\";\nimport type { ReflectionEvaluator } from \"./reflection.js\";\nimport type { RerouteEvent, Scratchpad } from \"./types.js\";\n\n/**\n * Create a runner that always fails, useful for testing self-healing.\n *\n * @example\n * ```typescript\n * const failing = createFailingRunner(new Error(\"Provider down\"));\n * const orchestrator = createAgentOrchestrator({\n * runner: failing,\n * selfHealing: { fallbackRunners: [backupRunner] },\n * });\n * ```\n */\nexport function createFailingRunner(\n error?: Error,\n options?: { delay?: number; failAfter?: number },\n): AgentRunner {\n let callCount = 0;\n const failAfter = options?.failAfter ?? 0;\n\n return async <T>(\n _agent: AgentLike,\n _input: string,\n _runOptions?: RunOptions,\n ): Promise<RunResult<T>> => {\n callCount++;\n\n if (failAfter > 0 && callCount <= failAfter) {\n return {\n output: \"success\" as T,\n messages: [],\n toolCalls: [],\n totalTokens: 10,\n };\n }\n\n if (options?.delay && options.delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, options.delay));\n }\n\n throw error ?? new Error(\"Runner failed\");\n };\n}\n\n/**\n * Assert that an agent was rerouted during execution.\n *\n * @example\n * ```typescript\n * const events: RerouteEvent[] = [];\n * const orchestrator = createMultiAgentOrchestrator({\n * selfHealing: {\n * onReroute: (event) => events.push(event),\n * },\n * });\n *\n * // ... trigger reroute ...\n * assertRerouted(events, {\n * fromAgent: \"primary\",\n * toAgent: \"backup\",\n * reason: /circuit breaker/i,\n * });\n * ```\n */\nexport function assertRerouted(\n events: RerouteEvent[],\n expected: {\n fromAgent?: string;\n toAgent?: string;\n reason?: string | RegExp;\n minReroutes?: number;\n },\n): void {\n if (events.length === 0) {\n throw new Error(\"Expected at least one reroute event, but none occurred\");\n }\n\n if (\n expected.minReroutes !== undefined &&\n events.length < expected.minReroutes\n ) {\n throw new Error(\n `Expected at least ${expected.minReroutes} reroute events, got ${events.length}`,\n );\n }\n\n if (expected.fromAgent) {\n const found = events.some((e) => e.originalAgent === expected.fromAgent);\n if (!found) {\n throw new Error(\n `Expected reroute from agent \"${expected.fromAgent}\", but no matching event found`,\n );\n }\n }\n\n if (expected.toAgent) {\n const found = events.some((e) => e.reroutedTo === expected.toAgent);\n if (!found) {\n throw new Error(\n `Expected reroute to agent \"${expected.toAgent}\", but no matching event found`,\n );\n }\n }\n\n if (expected.reason) {\n const found = events.some((e) => {\n if (typeof expected.reason === \"string\") {\n return e.reason.includes(expected.reason);\n }\n\n return expected.reason!.test(e.reason);\n });\n if (!found) {\n throw new Error(\n `Expected reroute reason matching ${expected.reason}, but no matching event found`,\n );\n }\n }\n}\n\n/**\n * Assert the health state of an agent in the health monitor.\n *\n * @example\n * ```typescript\n * assertAgentHealth(monitor, \"researcher\", {\n * minScore: 70,\n * circuitState: \"CLOSED\",\n * });\n * ```\n */\nexport function assertAgentHealth(\n monitor: HealthMonitor,\n agentId: string,\n expected: {\n minScore?: number;\n maxScore?: number;\n circuitState?: \"CLOSED\" | \"OPEN\" | \"HALF_OPEN\";\n minSuccessRate?: number;\n },\n): void {\n const metrics = monitor.getMetrics(agentId);\n\n if (\n expected.minScore !== undefined &&\n metrics.healthScore < expected.minScore\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" health score to be at least ${expected.minScore}, got ${metrics.healthScore}`,\n );\n }\n\n if (\n expected.maxScore !== undefined &&\n metrics.healthScore > expected.maxScore\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" health score to be at most ${expected.maxScore}, got ${metrics.healthScore}`,\n );\n }\n\n if (\n expected.circuitState !== undefined &&\n metrics.circuitState !== expected.circuitState\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" circuit state to be \"${expected.circuitState}\", got \"${metrics.circuitState}\"`,\n );\n }\n\n if (\n expected.minSuccessRate !== undefined &&\n metrics.successRate < expected.minSuccessRate\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" success rate to be at least ${expected.minSuccessRate}, got ${metrics.successRate}`,\n );\n }\n}\n\n// ============================================================================\n// Checkpoint Test Helpers\n// ============================================================================\n\n/**\n * Create a test checkpoint store (wraps InMemoryCheckpointStore with assertion helpers).\n *\n * @example\n * ```typescript\n * const store = createTestCheckpointStore();\n * const orchestrator = createAgentOrchestrator({ runner, checkpointStore: store });\n * const cp = await orchestrator.checkpoint();\n * expect(store.saved).toHaveLength(1);\n * ```\n */\nexport function createTestCheckpointStore(\n maxCheckpoints = 100,\n): CheckpointStore & {\n saved: Checkpoint[];\n inner: InMemoryCheckpointStore;\n /** Get the most recently saved checkpoint */\n getLatest: () => Checkpoint | undefined;\n} {\n const inner = new InMemoryCheckpointStore({ maxCheckpoints });\n const saved: Checkpoint[] = [];\n\n return {\n inner,\n saved,\n getLatest: () => saved[saved.length - 1],\n async save(checkpoint: Checkpoint): Promise<string> {\n saved.push(checkpoint);\n\n return inner.save(checkpoint);\n },\n load: (id: string) => inner.load(id),\n list: () => inner.list(),\n delete: (id: string) => inner.delete(id),\n clear: () => inner.clear(),\n prune: () => inner.prune(),\n };\n}\n\n/**\n * Assert that a checkpoint has expected properties.\n */\nexport function assertCheckpoint(\n checkpoint: Checkpoint,\n expected: {\n orchestratorType?: \"single\" | \"multi\";\n hasTimeline?: boolean;\n hasMemory?: boolean;\n hasSystemExport?: boolean;\n label?: string;\n },\n): void {\n if (\n expected.orchestratorType !== undefined &&\n checkpoint.orchestratorType !== expected.orchestratorType\n ) {\n throw new Error(\n `Expected checkpoint orchestratorType \"${expected.orchestratorType}\", got \"${checkpoint.orchestratorType}\"`,\n );\n }\n\n if (\n expected.hasSystemExport === true &&\n (!checkpoint.systemExport || checkpoint.systemExport === \"\")\n ) {\n throw new Error(\n \"Expected checkpoint to have non-empty systemExport, but it was empty\",\n );\n }\n\n if (expected.hasTimeline === true && checkpoint.timelineExport === null) {\n throw new Error(\n \"Expected checkpoint to have timeline export, but it was null\",\n );\n }\n\n if (expected.hasTimeline === false && checkpoint.timelineExport !== null) {\n throw new Error(\n \"Expected checkpoint to have no timeline export, but it was present\",\n );\n }\n\n if (expected.hasMemory === true && checkpoint.memoryExport === null) {\n throw new Error(\n \"Expected checkpoint to have memory export, but it was null\",\n );\n }\n\n if (expected.hasMemory === false && checkpoint.memoryExport !== null) {\n throw new Error(\n \"Expected checkpoint to have no memory export, but it was present\",\n );\n }\n\n if (expected.label !== undefined && checkpoint.label !== expected.label) {\n throw new Error(\n `Expected checkpoint label \"${expected.label}\", got \"${checkpoint.label}\"`,\n );\n }\n}\n\n// ============================================================================\n// Breakpoint Test Helpers\n// ============================================================================\n\n/** Options for the breakpoint simulator */\nexport interface BreakpointSimulatorOptions {\n /** Auto-resume after this delay (ms). Default: 0 (immediate) */\n autoResumeDelay?: number;\n /** Modifications to apply on resume */\n modifications?: BreakpointModifications;\n /** If true, cancel instead of resume */\n cancel?: boolean;\n /** Cancel reason */\n cancelReason?: string;\n}\n\n/**\n * Create a breakpoint simulator that auto-resolves breakpoints.\n *\n * @example\n * ```typescript\n * const simulator = createBreakpointSimulator({ autoResumeDelay: 10 });\n * const orchestrator = createAgentOrchestrator({\n * runner,\n * breakpoints: [{ type: \"pre_agent_run\" }],\n * onBreakpoint: simulator.handler,\n * });\n * // Run agent — breakpoint fires and auto-resumes\n * await orchestrator.run(\"test input\");\n * expect(simulator.hits).toHaveLength(1);\n * ```\n */\n/** Minimal interface for breakpoint-capable orchestrators */\nexport interface BreakpointCapable {\n resumeBreakpoint(id: string, modifications?: BreakpointModifications): void;\n cancelBreakpoint(id: string, reason?: string): void;\n}\n\n/**\n * Create a breakpoint simulator that auto-resolves breakpoints for testing.\n *\n * @param options - Simulator options including `autoResumeDelay` and `modifications`.\n * @returns An object with `handler`, `hits`, and `attachTo` for test assertions.\n */\nexport function createBreakpointSimulator(\n options: BreakpointSimulatorOptions = {},\n): {\n handler: (request: BreakpointRequest) => void;\n hits: BreakpointRequest[];\n attachTo: (orchestrator: BreakpointCapable) => void;\n} {\n const hits: BreakpointRequest[] = [];\n let orchestratorRef: BreakpointCapable | null = null;\n let attached = false;\n\n const handler = (request: BreakpointRequest) => {\n hits.push(request);\n\n if (!attached) {\n throw new Error(\n \"[Directive] BreakpointSimulator: handler called but attachTo() was never called. \" +\n \"Breakpoints will not be resolved. Call simulator.attachTo(orchestrator) after creation.\",\n );\n }\n\n const delay = options.autoResumeDelay ?? 0;\n\n const doResolve = () => {\n if (!orchestratorRef) {\n return;\n }\n if (options.cancel) {\n orchestratorRef.cancelBreakpoint(request.id, options.cancelReason);\n } else {\n orchestratorRef.resumeBreakpoint(request.id, options.modifications);\n }\n };\n\n if (delay > 0) {\n setTimeout(doResolve, delay);\n } else {\n // Use queueMicrotask so the breakpoint state is written before we resolve\n queueMicrotask(doResolve);\n }\n };\n\n return {\n handler,\n hits,\n attachTo: (orch: BreakpointCapable) => {\n orchestratorRef = orch;\n attached = true;\n },\n };\n}\n\n/**\n * Assert that a breakpoint was hit with expected properties.\n */\nexport function assertBreakpointHit(\n hits: BreakpointRequest[],\n expected: {\n type?: string;\n agentId?: string;\n count?: number;\n },\n): void {\n if (expected.count !== undefined && hits.length !== expected.count) {\n throw new Error(\n `Expected ${expected.count} breakpoint hits, got ${hits.length}`,\n );\n }\n\n if (expected.type) {\n const found = hits.some((h) => h.type === expected.type);\n if (!found) {\n const types = hits.map((h) => h.type).join(\", \");\n\n throw new Error(\n `Expected breakpoint of type \"${expected.type}\", found types: [${types}]`,\n );\n }\n }\n\n if (expected.agentId) {\n const found = hits.some((h) => h.agentId === expected.agentId);\n if (!found) {\n const agents = hits.map((h) => h.agentId).join(\", \");\n\n throw new Error(\n `Expected breakpoint for agent \"${expected.agentId}\", found agents: [${agents}]`,\n );\n }\n }\n}\n\n// ============================================================================\n// Structured Output Test Helpers\n// ============================================================================\n\n/**\n * Create a mock SafeParseable schema for testing.\n *\n * @example\n * ```typescript\n * const schema = createMockSchema((data) => typeof data === \"object\" && data !== null);\n * const orchestrator = createAgentOrchestrator({\n * runner,\n * outputSchema: schema,\n * });\n * ```\n */\nexport function createMockSchema<T>(\n validate: (data: unknown) => boolean,\n description?: string,\n): {\n safeParse: (data: unknown) => {\n success: boolean;\n data?: T;\n error?: { message: string };\n };\n description?: string;\n} {\n return {\n safeParse: (data: unknown) => {\n if (validate(data)) {\n return { success: true, data: data as T };\n }\n\n return { success: false, error: { message: \"Validation failed\" } };\n },\n description,\n };\n}\n\n// ============================================================================\n// Multiplexed Stream Test Helpers\n// ============================================================================\n\n/**\n * Collect all chunks from a multiplexed stream into an array.\n *\n * @example\n * ```typescript\n * const { stream } = orchestrator.runParallelStream([\"a\", \"b\"], \"input\", merge);\n * const chunks = await collectMultiplexedStream(stream);\n * expect(chunks.length).toBeGreaterThan(0);\n * ```\n */\nexport async function collectMultiplexedStream(\n stream: AsyncIterable<MultiplexedStreamChunk>,\n): Promise<MultiplexedStreamChunk[]> {\n const chunks: MultiplexedStreamChunk[] = [];\n for await (const chunk of stream) {\n chunks.push(chunk);\n }\n\n return chunks;\n}\n\n/**\n * Assert properties of collected multiplexed stream chunks.\n */\nexport function assertMultiplexedStream(\n chunks: MultiplexedStreamChunk[],\n expected: {\n agentIds?: string[];\n minChunks?: number;\n hasDone?: boolean;\n hasErrors?: boolean;\n },\n): void {\n if (expected.minChunks !== undefined && chunks.length < expected.minChunks) {\n throw new Error(\n `Expected at least ${expected.minChunks} chunks, got ${chunks.length}`,\n );\n }\n\n if (expected.agentIds) {\n const seenAgents = new Set(chunks.map((c) => c.agentId));\n for (const agentId of expected.agentIds) {\n if (!seenAgents.has(agentId)) {\n throw new Error(\n `Expected chunks from agent \"${agentId}\", found agents: [${[...seenAgents].join(\", \")}]`,\n );\n }\n }\n }\n\n if (expected.hasDone === true) {\n const hasDone = chunks.some((c) => c.chunk.type === \"done\");\n if (!hasDone) {\n throw new Error(\"Expected at least one 'done' chunk, found none\");\n }\n }\n\n if (expected.hasErrors === true) {\n const hasError = chunks.some((c) => c.chunk.type === \"error\");\n if (!hasError) {\n throw new Error(\"Expected at least one 'error' chunk, found none\");\n }\n }\n\n if (expected.hasErrors === false) {\n const hasError = chunks.some((c) => c.chunk.type === \"error\");\n if (hasError) {\n throw new Error(\"Expected no 'error' chunks, but found some\");\n }\n }\n}\n\n// ============================================================================\n// Reflection Test Helpers\n// ============================================================================\n\n/**\n * Create a test reflection evaluator that passes after N iterations.\n *\n * @example\n * ```typescript\n * const evaluator = createTestReflectionEvaluator({ passAfter: 2 });\n * const reflective = withReflection(runner, { evaluate: evaluator });\n * ```\n */\nexport function createTestReflectionEvaluator(options?: {\n /** Pass after this many evaluations (1 = pass on first try). Default: 1 */\n passAfter?: number;\n /** Feedback to provide on failure */\n feedback?: string;\n /** Score to assign (0-1) */\n score?: number;\n}): ReflectionEvaluator {\n const passAfter = options?.passAfter ?? 1;\n const feedback = options?.feedback ?? \"Needs improvement\";\n const score = options?.score;\n let callCount = 0;\n\n return (_output: unknown, _context) => {\n callCount++;\n const passed = callCount >= passAfter;\n\n return {\n passed,\n feedback: passed ? undefined : feedback,\n score: score ?? (passed ? 1 : 0.5),\n };\n };\n}\n\n// ============================================================================\n// Scratchpad Test Helpers\n// ============================================================================\n\n/**\n * Assert that a scratchpad contains expected values.\n *\n * @example\n * ```typescript\n * assertScratchpadState(orchestrator.scratchpad!, {\n * \"plan.status\": \"complete\",\n * \"research.results\": expect.any(Array),\n * });\n * ```\n */\nexport function assertScratchpadState(\n scratchpad: Scratchpad,\n expected: Record<string, unknown>,\n): void {\n const all = scratchpad.getAll();\n for (const [key, expectedValue] of Object.entries(expected)) {\n const actual = all[key];\n if (actual !== expectedValue) {\n throw new Error(\n `Expected scratchpad key \"${key}\" to be ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actual)}`,\n );\n }\n }\n}\n\n// ============================================================================\n// Derivation Test Helpers\n// ============================================================================\n\n/**\n * Assert that derived values match expected values.\n *\n * @example\n * ```typescript\n * assertDerivedValues(orchestrator, {\n * totalRuns: 3,\n * allComplete: true,\n * });\n * ```\n */\nexport function assertDerivedValues(\n orchestrator: MultiAgentOrchestrator,\n expected: Record<string, unknown>,\n): void {\n const derived = orchestrator.derived;\n for (const [key, expectedValue] of Object.entries(expected)) {\n const actual = derived[key];\n if (typeof expectedValue === \"object\" && expectedValue !== null) {\n // Sort keys for order-independent comparison\n const sortedStringify = (v: unknown): string =>\n JSON.stringify(v, Object.keys(v as Record<string, unknown>).sort());\n if (sortedStringify(actual) !== sortedStringify(expectedValue)) {\n throw new Error(\n `Expected derived value \"${key}\" to be ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actual)}`,\n );\n }\n } else if (actual !== expectedValue) {\n throw new Error(\n `Expected derived value \"${key}\" to be ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actual)}`,\n );\n }\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/testing.ts"],"names":["createMockAgentRunner","options","defaultResponse","responses","recordCalls","onRun","calls","responseMap","currentDefault","agent","input","runOptions","config","generated","resolve","messages","message","toolCalls","toolCall","name","testGuardrail","guardrail","testInput","context","data","fullContext","start","result","duration","expectedReason","expected","testGuardrailBatch","testCases","results","failures","i","testCase","createApprovalSimulator","autoApprove","autoReject","delay","recordRequests","requests","pendingRequests","requestWaiters","request","waiter","requestId","pending","reason","r","predicate","timeoutMs","existing","reject","entry","req","timeout","idx","createTestOrchestrator","mockResponses","defaultMockResponse","orchestratorOptions","mockRunner","approvalSimulator","orchestrator","createAgentOrchestrator","testOrchestrator","createConstraintRecorder","snapshots","assertOrchestratorState","state","min","max","exact","len","createTimeController","startTime","currentTime","initial","ms","time","createTestMultiAgentOrchestrator","mockTaskConfigs","existingTasks","taskId","createMockTask","responsesByName","agentId","registration","createMultiAgentOrchestrator","assertMultiAgentState","expectedStatus","allStates","total","sum","s","pendingCount","output","_input","signal","timer","createTestDag","nodes","merge","dag","assertDagExecution","nodeId","actual","expectedOutput","createTestTimeline","events","timeline","createDebugTimeline","event","assertTimelineEvents","type","e","expectedCount","createFailingRunner","error","callCount","failAfter","_agent","_runOptions","assertRerouted","assertAgentHealth","monitor","metrics","createTestCheckpointStore","maxCheckpoints","inner","InMemoryCheckpointStore","saved","checkpoint","id","assertCheckpoint","createBreakpointSimulator","hits","orchestratorRef","attached","doResolve","orch","assertBreakpointHit","h","types","agents","createMockSchema","validate","description","collectMultiplexedStream","stream","chunks","chunk","assertMultiplexedStream","seenAgents","c","createTestReflectionEvaluator","passAfter","feedback","score","_output","_context","passed","assertScratchpadState","scratchpad","all","key","expectedValue","assertDerivedValues","derived","sortedStringify","v"],"mappings":"8LA6IO,SAASA,EACdC,CAAAA,CAAkC,GACjB,CACjB,GAAM,CACJ,eAAA,CAAAC,CAAAA,CAAkB,CAAE,MAAA,CAAQ,gBAAiB,WAAA,CAAa,EAAG,EAC7D,SAAA,CAAAC,CAAAA,CAAY,EAAC,CACb,WAAA,CAAAC,CAAAA,CAAc,IAAA,CACd,MAAAC,CACF,CAAA,CAAIJ,EAEEK,CAAAA,CAAwB,GACxBC,CAAAA,CAAc,IAAI,IACtB,MAAA,CAAO,OAAA,CAAQJ,CAAS,CAC1B,CAAA,CACIK,EAAiBN,CAAAA,CAyDrB,OAAO,CACL,GAAA,CAxDuB,MACvBO,CAAAA,CACAC,CAAAA,CACAC,IAC0B,CAC1BN,CAAAA,GAAQI,EAAOC,CAAK,CAAA,CAEhBN,GACFE,CAAAA,CAAM,IAAA,CAAK,CACT,KAAA,CAAAG,CAAAA,CACA,MAAAC,CAAAA,CACA,OAAA,CAASC,EACT,SAAA,CAAW,IAAA,CAAK,KAClB,CAAC,CAAA,CAIH,IAAIC,EAASL,CAAAA,CAAY,GAAA,CAAIE,EAAM,IAAI,CAAA,EAAKD,EAG5C,GAAII,CAAAA,CAAO,SAAU,CACnB,IAAMC,EAAYD,CAAAA,CAAO,QAAA,CAASF,EAAOD,CAAK,CAAA,CAC9CG,EAAS,CAAE,GAAGA,CAAAA,CAAQ,GAAGC,CAAU,EACrC,CAGA,GAAID,CAAAA,CAAO,KAAA,CACT,MA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,CAAM,CAAA,GAAM+D,CAAAA,CAAgBH,CAAa,CAAA,CAC3D,MAAM,IAAI,KAAA,CACR,CAAA,wBAAA,EAA2BD,CAAG,CAAA,QAAA,EAAW,IAAA,CAAK,UAAUC,CAAa,CAAC,SAAS,IAAA,CAAK,SAAA,CAAU5D,CAAM,CAAC,CAAA,CACvG,CAEJ,CAAA,KAAA,GAAWA,IAAW4D,CAAAA,CACpB,MAAM,IAAI,KAAA,CACR,CAAA,wBAAA,EAA2BD,CAAG,CAAA,QAAA,EAAW,IAAA,CAAK,UAAUC,CAAa,CAAC,SAAS,IAAA,CAAK,SAAA,CAAU5D,CAAM,CAAC,CAAA,CACvG,CAEJ,CACF","file":"testing.js","sourcesContent":["/**\n * Directive AI Testing Utilities\n *\n * Provides testing helpers for:\n * - Mock agent runners with configurable responses\n * - Guardrail testing with assertions\n * - Approval workflow simulation\n * - Snapshot testing for constraint evaluation\n *\n * @example\n * ```typescript\n * import { createMockAgentRunner, testGuardrail, createApprovalSimulator } from '@directive-run/ai/testing';\n *\n * describe('MyOrchestrator', () => {\n * it('should block PII in input', async () => {\n * const result = await testGuardrail(createPIIGuardrail(), {\n * input: 'My SSN is 123-45-6789',\n * });\n * expect(result.passed).toBe(false);\n * expect(result.reason).toContain('PII');\n * });\n * });\n * ```\n */\n\nimport {\n type AgentOrchestrator,\n type OrchestratorOptions,\n createAgentOrchestrator,\n} from \"./agent-orchestrator.js\";\nimport type {\n BreakpointModifications,\n BreakpointRequest,\n} from \"./breakpoints.js\";\nimport {\n type Checkpoint,\n type CheckpointStore,\n InMemoryCheckpointStore,\n} from \"./checkpoint.js\";\nimport {\n type MultiAgentOrchestrator,\n type MultiAgentOrchestratorOptions,\n type TaskRegistration,\n createMultiAgentOrchestrator,\n} from \"./multi-agent-orchestrator.js\";\nimport type { MultiplexedStreamChunk } from \"./streaming.js\";\nimport type {\n AgentLike,\n AgentRunner,\n ApprovalRequest,\n GuardrailContext,\n GuardrailFn,\n GuardrailResult,\n InputGuardrailData,\n Message,\n OutputGuardrailData,\n RunOptions,\n RunResult,\n ToolCall,\n ToolCallGuardrailData,\n} from \"./types.js\";\n\n// ============================================================================\n// Mock Agent Runner\n// ============================================================================\n\n/** Configuration for mock agent responses */\nexport interface MockAgentConfig<T = unknown> {\n /** Final output to return */\n output: T;\n /** Messages to emit during run */\n messages?: Message[];\n /** Tool calls to emit during run */\n toolCalls?: ToolCall[];\n /** Total tokens to report */\n totalTokens?: number;\n /** Delay before responding (ms) */\n delay?: number;\n /** Error to throw instead of returning */\n error?: Error;\n /** Function to generate dynamic responses */\n generate?: (input: string, agent: AgentLike) => Partial<MockAgentConfig<T>>;\n}\n\n/** Mock agent runner options */\nexport interface MockAgentRunnerOptions {\n /** Default response for unmatched agents */\n defaultResponse?: MockAgentConfig;\n /** Responses keyed by agent name */\n responses?: Record<string, MockAgentConfig>;\n /** Record all calls for assertions */\n recordCalls?: boolean;\n /** Callback for each run */\n onRun?: (agent: AgentLike, input: string) => void;\n}\n\n/** Recorded call for assertions */\nexport interface RecordedCall {\n agent: AgentLike;\n input: string;\n options?: RunOptions;\n timestamp: number;\n}\n\n/** Mock agent runner instance */\nexport interface MockAgentRunner {\n /** The run function to pass to orchestrator */\n run: AgentRunner;\n /** Get all recorded calls */\n getCalls(): RecordedCall[];\n /** Get calls for a specific agent */\n getCallsFor(agentName: string): RecordedCall[];\n /** Clear recorded calls */\n clearCalls(): void;\n /** Set response for an agent */\n setResponse<T>(agentName: string, config: MockAgentConfig<T>): void;\n /** Set default response */\n setDefaultResponse<T>(config: MockAgentConfig<T>): void;\n}\n\n/**\n * Create a mock agent runner for testing.\n *\n * @example\n * ```typescript\n * const mock = createMockAgentRunner({\n * responses: {\n * 'my-agent': {\n * output: 'Hello, world!',\n * totalTokens: 100,\n * },\n * },\n * });\n *\n * const orchestrator = createAgentOrchestrator({ runner: mock.run });\n * const result = await orchestrator.run(myAgent, 'Hi');\n *\n * expect(result.output).toBe('Hello, world!');\n * expect(mock.getCalls()).toHaveLength(1);\n * ```\n */\nexport function createMockAgentRunner(\n options: MockAgentRunnerOptions = {},\n): MockAgentRunner {\n const {\n defaultResponse = { output: \"mock response\", totalTokens: 10 },\n responses = {},\n recordCalls = true,\n onRun,\n } = options;\n\n const calls: RecordedCall[] = [];\n const responseMap = new Map<string, MockAgentConfig>(\n Object.entries(responses),\n );\n let currentDefault = defaultResponse;\n\n const run: AgentRunner = async <T>(\n agent: AgentLike,\n input: string,\n runOptions?: RunOptions,\n ): Promise<RunResult<T>> => {\n onRun?.(agent, input);\n\n if (recordCalls) {\n calls.push({\n agent,\n input,\n options: runOptions,\n timestamp: Date.now(),\n });\n }\n\n // Get config for this agent\n let config = responseMap.get(agent.name) ?? currentDefault;\n\n // Apply dynamic generation if present\n if (config.generate) {\n const generated = config.generate(input, agent);\n config = { ...config, ...generated };\n }\n\n // Handle error case\n if (config.error) {\n throw config.error;\n }\n\n // Apply delay\n if (config.delay && config.delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, config.delay));\n }\n\n // Emit messages\n const messages = config.messages ?? [];\n for (const message of messages) {\n runOptions?.onMessage?.(message);\n }\n\n // Emit tool calls\n const toolCalls = config.toolCalls ?? [];\n for (const toolCall of toolCalls) {\n runOptions?.onToolCall?.(toolCall);\n }\n\n return {\n output: config.output as T,\n messages,\n toolCalls,\n totalTokens: config.totalTokens ?? 10,\n };\n };\n\n return {\n run,\n getCalls: () => [...calls],\n getCallsFor: (name) => calls.filter((c) => c.agent.name === name),\n clearCalls: () => (calls.length = 0),\n setResponse: (name, config) => responseMap.set(name, config),\n setDefaultResponse: (config) => (currentDefault = config),\n };\n}\n\n// ============================================================================\n// Guardrail Testing\n// ============================================================================\n\n/** Test input for guardrail testing */\nexport type GuardrailTestInput<T> = T extends InputGuardrailData\n ? { input: string; agentName?: string }\n : T extends OutputGuardrailData\n ? {\n output: unknown;\n agentName?: string;\n input?: string;\n messages?: Message[];\n }\n : T extends ToolCallGuardrailData\n ? { toolCall: ToolCall; agentName?: string; input?: string }\n : Partial<T>;\n\n/** Extended guardrail result with test assertions */\nexport interface GuardrailTestResult extends GuardrailResult {\n /** Time taken to evaluate (ms) */\n duration: number;\n /** The data that was tested */\n testedData: unknown;\n /** Assert that the guardrail passed */\n assertPassed(): void;\n /** Assert that the guardrail failed */\n assertFailed(expectedReason?: string | RegExp): void;\n /** Assert that transformation occurred */\n assertTransformed(expected?: unknown): void;\n}\n\n/**\n * Test a guardrail with assertions.\n *\n * @example\n * ```typescript\n * // Test PII detection\n * const result = await testGuardrail(createPIIGuardrail(), {\n * input: 'My SSN is 123-45-6789',\n * });\n * result.assertFailed(/PII/);\n *\n * // Test input transformation\n * const redactResult = await testGuardrail(createPIIGuardrail({ redact: true }), {\n * input: 'My SSN is 123-45-6789',\n * });\n * redactResult.assertPassed();\n * redactResult.assertTransformed();\n * ```\n */\nexport async function testGuardrail<T>(\n guardrail: GuardrailFn<T>,\n testInput: GuardrailTestInput<T>,\n context?: Partial<GuardrailContext>,\n): Promise<GuardrailTestResult> {\n // Build full data object\n const data = {\n agentName: \"test-agent\",\n input: \"\",\n ...testInput,\n } as unknown as T;\n\n // Build context\n const fullContext: GuardrailContext = {\n agentName: (testInput as { agentName?: string }).agentName ?? \"test-agent\",\n input: (testInput as { input?: string }).input ?? \"\",\n facts: context?.facts ?? {},\n ...context,\n };\n\n const start = Date.now();\n const result = await guardrail(data, fullContext);\n const duration = Date.now() - start;\n\n return {\n ...result,\n duration,\n testedData: data,\n assertPassed() {\n if (!result.passed) {\n throw new Error(\n `Expected guardrail to pass, but it failed: ${result.reason}`,\n );\n }\n },\n assertFailed(expectedReason) {\n if (result.passed) {\n throw new Error(\"Expected guardrail to fail, but it passed\");\n }\n if (expectedReason !== undefined) {\n if (\n typeof expectedReason === \"string\" &&\n !result.reason?.includes(expectedReason)\n ) {\n throw new Error(\n `Expected failure reason to include \"${expectedReason}\", got: ${result.reason}`,\n );\n }\n if (\n expectedReason instanceof RegExp &&\n !expectedReason.test(result.reason ?? \"\")\n ) {\n throw new Error(\n `Expected failure reason to match ${expectedReason}, got: ${result.reason}`,\n );\n }\n }\n },\n assertTransformed(expected) {\n if (result.transformed === undefined) {\n throw new Error(\n \"Expected guardrail to transform input, but no transformation occurred\",\n );\n }\n if (expected !== undefined && result.transformed !== expected) {\n throw new Error(\n `Expected transformation to be ${JSON.stringify(expected)}, got: ${JSON.stringify(result.transformed)}`,\n );\n }\n },\n };\n}\n\n/**\n * Test multiple inputs against a guardrail.\n *\n * @example\n * ```typescript\n * const results = await testGuardrailBatch(createPIIGuardrail(), [\n * { input: 'Hello world', expect: 'pass' },\n * { input: 'My SSN is 123-45-6789', expect: 'fail' },\n * { input: 'Email: test@example.com', expect: 'fail' },\n * ]);\n *\n * expect(results.allPassed()).toBe(true);\n * ```\n */\nexport async function testGuardrailBatch<T>(\n guardrail: GuardrailFn<T>,\n testCases: Array<{\n input: GuardrailTestInput<T>;\n expect: \"pass\" | \"fail\" | \"transform\";\n context?: Partial<GuardrailContext>;\n }>,\n): Promise<{\n results: GuardrailTestResult[];\n allPassed(): boolean;\n failures(): Array<{\n index: number;\n expected: string;\n actual: GuardrailTestResult;\n }>;\n}> {\n const results: GuardrailTestResult[] = [];\n const failures: Array<{\n index: number;\n expected: string;\n actual: GuardrailTestResult;\n }> = [];\n\n for (let i = 0; i < testCases.length; i++) {\n const testCase = testCases[i]!;\n const result = await testGuardrail(\n guardrail,\n testCase.input,\n testCase.context,\n );\n results.push(result);\n\n const actualOutcome = !result.passed\n ? \"fail\"\n : result.transformed !== undefined\n ? \"transform\"\n : \"pass\";\n\n if (actualOutcome !== testCase.expect) {\n failures.push({ index: i, expected: testCase.expect, actual: result });\n }\n }\n\n return {\n results,\n allPassed: () => failures.length === 0,\n failures: () => failures,\n };\n}\n\n// ============================================================================\n// Approval Simulation\n// ============================================================================\n\n/** Approval simulator options */\nexport interface ApprovalSimulatorOptions {\n /** Auto-approve requests matching this predicate */\n autoApprove?: (request: ApprovalRequest) => boolean;\n /** Auto-reject requests matching this predicate */\n autoReject?: (request: ApprovalRequest) => boolean | string;\n /** Delay before auto-approval/rejection (ms) */\n delay?: number;\n /** Record all requests for assertions */\n recordRequests?: boolean;\n}\n\n/** Approval simulator instance */\nexport interface ApprovalSimulator {\n /** Handle an approval request */\n handle(request: ApprovalRequest): Promise<\"approved\" | \"rejected\">;\n /** Get all recorded requests */\n getRequests(): ApprovalRequest[];\n /** Clear recorded requests */\n clearRequests(): void;\n /** Manually approve a request */\n approve(requestId: string): void;\n /** Manually reject a request */\n reject(requestId: string, reason?: string): void;\n /** Wait for a specific request */\n waitForRequest(\n predicate: (req: ApprovalRequest) => boolean,\n timeoutMs?: number,\n ): Promise<ApprovalRequest>;\n}\n\n/**\n * Create an approval simulator for testing approval workflows.\n *\n * @example\n * ```typescript\n * const simulator = createApprovalSimulator({\n * autoApprove: (req) => req.type === 'tool_call' && req.data.name === 'search',\n * autoReject: (req) => req.type === 'tool_call' && req.data.name === 'delete',\n * });\n *\n * // Use in tests\n * orchestrator.onApprovalRequest = (req) => simulator.handle(req);\n * ```\n */\nexport function createApprovalSimulator(\n options: ApprovalSimulatorOptions = {},\n): ApprovalSimulator {\n const { autoApprove, autoReject, delay = 0, recordRequests = true } = options;\n\n const requests: ApprovalRequest[] = [];\n const pendingRequests = new Map<\n string,\n {\n request: ApprovalRequest;\n resolve: (decision: \"approved\" | \"rejected\") => void;\n }\n >();\n const requestWaiters: Array<{\n predicate: (req: ApprovalRequest) => boolean;\n resolve: (req: ApprovalRequest) => void;\n }> = [];\n\n return {\n async handle(request: ApprovalRequest): Promise<\"approved\" | \"rejected\"> {\n if (recordRequests) {\n requests.push(request);\n }\n\n // Notify waiters (resolve matching ones, remove them from array)\n for (let i = requestWaiters.length - 1; i >= 0; i--) {\n const waiter = requestWaiters[i]!;\n if (waiter.predicate(request)) {\n requestWaiters.splice(i, 1);\n waiter.resolve(request);\n }\n }\n\n // Apply delay\n if (delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, delay));\n }\n\n // Check auto-reject first (security-first)\n if (autoReject) {\n const rejectResult = autoReject(request);\n if (rejectResult) {\n return \"rejected\";\n }\n }\n\n // Check auto-approve\n if (autoApprove?.(request)) {\n return \"approved\";\n }\n\n // Wait for manual decision\n return new Promise((resolve) => {\n pendingRequests.set(request.id, { request, resolve });\n });\n },\n\n getRequests: () => [...requests],\n clearRequests: () => (requests.length = 0),\n\n approve(requestId: string) {\n const pending = pendingRequests.get(requestId);\n if (pending) {\n pending.resolve(\"approved\");\n pendingRequests.delete(requestId);\n }\n },\n\n reject(requestId: string, reason?: string) {\n const pending = pendingRequests.get(requestId);\n if (pending) {\n pending.resolve(\"rejected\");\n pendingRequests.delete(requestId);\n // Store reason on the request for test assertions\n const request = requests.find((r) => r.id === requestId);\n if (request) {\n (\n request as ApprovalRequest & { rejectionReason?: string }\n ).rejectionReason = reason;\n }\n }\n },\n\n waitForRequest(predicate, timeoutMs = 5000): Promise<ApprovalRequest> {\n // Check existing requests first\n const existing = requests.find(predicate);\n if (existing) {\n return Promise.resolve(existing);\n }\n\n // Wait for future request\n return new Promise((resolve, reject) => {\n const entry = {\n predicate,\n resolve: (req: ApprovalRequest) => {\n clearTimeout(timeout);\n resolve(req);\n },\n };\n\n const timeout = setTimeout(() => {\n const idx = requestWaiters.indexOf(entry);\n if (idx >= 0) {\n requestWaiters.splice(idx, 1);\n }\n reject(new Error(\"Timeout waiting for approval request\"));\n }, timeoutMs);\n\n requestWaiters.push(entry);\n });\n },\n };\n}\n\n// ============================================================================\n// Test Orchestrator Factory\n// ============================================================================\n\n/** Options for test orchestrator */\nexport interface TestOrchestratorOptions<F extends Record<string, unknown>>\n extends Omit<OrchestratorOptions<F>, \"runner\"> {\n /** Mock responses for agents */\n mockResponses?: Record<string, MockAgentConfig>;\n /** Default mock response */\n defaultMockResponse?: MockAgentConfig;\n}\n\n/** Test orchestrator with additional testing utilities */\nexport interface TestOrchestrator<F extends Record<string, unknown>>\n extends AgentOrchestrator<F> {\n /** The mock runner */\n mockRunner: MockAgentRunner;\n /** Approval simulator */\n approvalSimulator: ApprovalSimulator;\n /** Get recorded agent calls */\n getCalls(): RecordedCall[];\n /** Get approval requests */\n getApprovalRequests(): ApprovalRequest[];\n /** Reset all state */\n resetAll(): void;\n}\n\n/**\n * Create a test orchestrator with mocking and simulation built in.\n *\n * @example\n * ```typescript\n * const test = createTestOrchestrator({\n * mockResponses: {\n * 'my-agent': { output: 'test response' },\n * },\n * constraints: {\n * needsApproval: {\n * when: () => true,\n * require: { type: 'NEED_APPROVAL' },\n * },\n * },\n * });\n *\n * await test.run(myAgent, 'Hello');\n * expect(test.getCalls()).toHaveLength(1);\n * ```\n */\nexport function createTestOrchestrator<\n F extends Record<string, unknown> = Record<string, never>,\n>(options: TestOrchestratorOptions<F> = {}): TestOrchestrator<F> {\n const { mockResponses, defaultMockResponse, ...orchestratorOptions } =\n options;\n\n const mockRunner = createMockAgentRunner({\n responses: mockResponses,\n defaultResponse: defaultMockResponse,\n });\n\n const approvalSimulator = createApprovalSimulator();\n\n const orchestrator = createAgentOrchestrator<F>({\n ...orchestratorOptions,\n runner: mockRunner.run,\n onApprovalRequest: (req) => {\n approvalSimulator.handle(req);\n orchestratorOptions.onApprovalRequest?.(req);\n },\n });\n\n // Use Object.create to preserve getters instead of { ...orchestrator } which evaluates them once\n const testOrchestrator = Object.create(orchestrator) as TestOrchestrator<F>;\n testOrchestrator.mockRunner = mockRunner;\n testOrchestrator.approvalSimulator = approvalSimulator;\n testOrchestrator.getCalls = () => mockRunner.getCalls();\n testOrchestrator.getApprovalRequests = () => approvalSimulator.getRequests();\n testOrchestrator.resetAll = () => {\n orchestrator.reset();\n mockRunner.clearCalls();\n approvalSimulator.clearRequests();\n };\n\n return testOrchestrator;\n}\n\n// ============================================================================\n// Snapshot Testing\n// ============================================================================\n\n/** Constraint evaluation snapshot */\nexport interface ConstraintSnapshot {\n constraintId: string;\n triggered: boolean;\n requirement?: unknown;\n facts: Record<string, unknown>;\n timestamp: number;\n}\n\n/**\n * Create a constraint evaluation recorder for snapshot testing.\n *\n * @example\n * ```typescript\n * const recorder = createConstraintRecorder();\n * const orchestrator = createAgentOrchestrator({\n * plugins: [recorder.plugin],\n * });\n *\n * await orchestrator.run(agent, 'Hello');\n *\n * expect(recorder.getSnapshots()).toMatchSnapshot();\n * ```\n */\nexport function createConstraintRecorder(): {\n plugin: {\n name: string;\n onRequirementCreated: (data: {\n constraintId: string;\n requirement: unknown;\n facts: unknown;\n }) => void;\n };\n getSnapshots(): ConstraintSnapshot[];\n clearSnapshots(): void;\n} {\n const snapshots: ConstraintSnapshot[] = [];\n\n return {\n plugin: {\n name: \"constraint-recorder\",\n onRequirementCreated(data) {\n snapshots.push({\n constraintId: data.constraintId,\n triggered: true,\n requirement: data.requirement,\n facts: data.facts as Record<string, unknown>,\n timestamp: Date.now(),\n });\n },\n },\n getSnapshots: () => [...snapshots],\n clearSnapshots: () => (snapshots.length = 0),\n };\n}\n\n// ============================================================================\n// Assertion Helpers\n// ============================================================================\n\n/**\n * Assert that an orchestrator has specific state.\n *\n * @example\n * ```typescript\n * assertOrchestratorState(orchestrator, {\n * agentStatus: 'completed',\n * tokenUsage: { min: 0, max: 1000 },\n * pendingApprovals: 0,\n * });\n * ```\n */\nexport function assertOrchestratorState<F extends Record<string, unknown>>(\n orchestrator: AgentOrchestrator<F>,\n expected: {\n agentStatus?: \"idle\" | \"running\" | \"paused\" | \"completed\" | \"error\";\n tokenUsage?: { min?: number; max?: number; exact?: number };\n pendingApprovals?: number;\n conversationLength?: { min?: number; max?: number; exact?: number };\n },\n): void {\n const state = orchestrator.facts;\n\n if (\n expected.agentStatus !== undefined &&\n state.agent.status !== expected.agentStatus\n ) {\n throw new Error(\n `Expected agent status to be \"${expected.agentStatus}\", got \"${state.agent.status}\"`,\n );\n }\n\n if (expected.tokenUsage !== undefined) {\n const { min, max, exact } = expected.tokenUsage;\n if (exact !== undefined && state.agent.tokenUsage !== exact) {\n throw new Error(\n `Expected token usage to be exactly ${exact}, got ${state.agent.tokenUsage}`,\n );\n }\n if (min !== undefined && state.agent.tokenUsage < min) {\n throw new Error(\n `Expected token usage to be at least ${min}, got ${state.agent.tokenUsage}`,\n );\n }\n if (max !== undefined && state.agent.tokenUsage > max) {\n throw new Error(\n `Expected token usage to be at most ${max}, got ${state.agent.tokenUsage}`,\n );\n }\n }\n\n if (\n expected.pendingApprovals !== undefined &&\n state.approval.pending.length !== expected.pendingApprovals\n ) {\n throw new Error(\n `Expected ${expected.pendingApprovals} pending approvals, got ${state.approval.pending.length}`,\n );\n }\n\n if (expected.conversationLength !== undefined) {\n const { min, max, exact } = expected.conversationLength;\n const len = state.conversation.length;\n if (exact !== undefined && len !== exact) {\n throw new Error(\n `Expected conversation length to be exactly ${exact}, got ${len}`,\n );\n }\n if (min !== undefined && len < min) {\n throw new Error(\n `Expected conversation length to be at least ${min}, got ${len}`,\n );\n }\n if (max !== undefined && len > max) {\n throw new Error(\n `Expected conversation length to be at most ${max}, got ${len}`,\n );\n }\n }\n}\n\n// ============================================================================\n// Fake Timers Support\n// ============================================================================\n\n/**\n * Create a time controller for testing time-dependent behavior.\n *\n * @example\n * ```typescript\n * const time = createTimeController();\n *\n * // Override Date.now\n * const originalNow = Date.now;\n * Date.now = () => time.now();\n *\n * time.advance(1000); // Advance 1 second\n *\n * // Restore\n * Date.now = originalNow;\n * ```\n */\nexport function createTimeController(startTime = Date.now()): {\n now(): number;\n advance(ms: number): void;\n set(time: number): void;\n reset(): void;\n} {\n let currentTime = startTime;\n const initial = startTime;\n\n return {\n now: () => currentTime,\n advance: (ms) => {\n currentTime += ms;\n },\n set: (time) => {\n currentTime = time;\n },\n reset: () => {\n currentTime = initial;\n },\n };\n}\n\n// ============================================================================\n// Multi-Agent Test Orchestrator\n// ============================================================================\n\n/** Options for test multi-agent orchestrator */\nexport interface TestMultiAgentOrchestratorOptions\n extends Omit<MultiAgentOrchestratorOptions, \"runner\"> {\n /** Mock responses keyed by agent ID — internally mapped to agent names for the mock runner */\n mockResponses?: Record<string, MockAgentConfig>;\n /** Default mock response for unmatched agents */\n defaultMockResponse?: MockAgentConfig;\n /** Mock tasks keyed by task ID — auto-generates TaskRegistration wrappers */\n mockTasks?: Record<\n string,\n { output: unknown; delay?: number; shouldError?: boolean }\n >;\n}\n\n/** Test multi-agent orchestrator with additional testing utilities */\nexport interface TestMultiAgentOrchestrator extends MultiAgentOrchestrator {\n /** The mock runner */\n mockRunner: MockAgentRunner;\n /** Approval simulator */\n approvalSimulator: ApprovalSimulator;\n /** Get recorded agent calls */\n getCalls(): RecordedCall[];\n /** Get approval requests */\n getApprovalRequests(): ApprovalRequest[];\n /** Reset all state */\n resetAll(): void;\n}\n\n/**\n * Create a test multi-agent orchestrator with mocking and simulation built in.\n *\n * @example\n * ```typescript\n * const test = createTestMultiAgentOrchestrator({\n * agents: {\n * researcher: { agent: { name: 'researcher' } },\n * writer: { agent: { name: 'writer' } },\n * },\n * mockResponses: {\n * researcher: { output: 'Research results', totalTokens: 100 },\n * writer: { output: 'Written article', totalTokens: 200 },\n * },\n * });\n *\n * const result = await test.runAgent('researcher', 'What is AI?');\n * expect(result.output).toBe('Research results');\n * expect(test.getCalls()).toHaveLength(1);\n * ```\n */\nexport function createTestMultiAgentOrchestrator(\n options: TestMultiAgentOrchestratorOptions,\n): TestMultiAgentOrchestrator {\n const {\n mockResponses = {},\n defaultMockResponse,\n mockTasks: mockTaskConfigs,\n ...orchestratorOptions\n } = options;\n\n // Convert mockTasks into real TaskRegistration entries\n if (mockTaskConfigs) {\n const existingTasks = orchestratorOptions.tasks ?? {};\n for (const [taskId, config] of Object.entries(mockTaskConfigs)) {\n if (!existingTasks[taskId]) {\n existingTasks[taskId] = createMockTask(config.output, {\n delay: config.delay,\n shouldError: config.shouldError,\n });\n }\n }\n orchestratorOptions.tasks = existingTasks;\n }\n\n // Map mock responses by agent name (from agent registration)\n const responsesByName: Record<string, MockAgentConfig> = {};\n for (const [agentId, config] of Object.entries(mockResponses)) {\n const registration = orchestratorOptions.agents[agentId];\n if (registration) {\n responsesByName[registration.agent.name] = config;\n }\n }\n\n const mockRunner = createMockAgentRunner({\n responses: responsesByName,\n defaultResponse: defaultMockResponse,\n });\n\n const approvalSimulator = createApprovalSimulator();\n\n const orchestrator = createMultiAgentOrchestrator({\n ...orchestratorOptions,\n runner: mockRunner.run,\n onApprovalRequest: (req) => {\n approvalSimulator.handle(req);\n orchestratorOptions.onApprovalRequest?.(req);\n },\n });\n\n // Use Object.create to preserve getters (derived, scratchpad, timeline, etc.)\n // instead of { ...orchestrator } which evaluates getters at spread time\n const testOrchestrator = Object.create(\n orchestrator,\n ) as TestMultiAgentOrchestrator;\n testOrchestrator.mockRunner = mockRunner;\n testOrchestrator.approvalSimulator = approvalSimulator;\n testOrchestrator.getCalls = () => mockRunner.getCalls();\n testOrchestrator.getApprovalRequests = () => approvalSimulator.getRequests();\n testOrchestrator.resetAll = () => {\n orchestrator.reset();\n mockRunner.clearCalls();\n approvalSimulator.clearRequests();\n };\n\n return testOrchestrator;\n}\n\n// ============================================================================\n// Multi-Agent Assertion Helpers\n// ============================================================================\n\n/**\n * Assert that a multi-agent orchestrator has specific state.\n *\n * @example\n * ```typescript\n * assertMultiAgentState(orchestrator, {\n * agentStatus: { researcher: 'completed', writer: 'idle' },\n * globalTokens: { min: 0, max: 1000 },\n * pendingHandoffs: 0,\n * });\n * ```\n */\nexport function assertMultiAgentState(\n orchestrator: MultiAgentOrchestrator,\n expected: {\n agentStatus?: Record<string, \"idle\" | \"running\" | \"completed\" | \"error\">;\n taskStatus?: Record<string, string>;\n totalTokens?: { agentId?: string; min?: number; max?: number };\n globalTokens?: { min?: number; max?: number };\n pendingHandoffs?: number;\n },\n): void {\n if (expected.taskStatus) {\n for (const [taskId, expectedStatus] of Object.entries(\n expected.taskStatus,\n )) {\n const state = orchestrator.getTaskState(taskId);\n if (!state) {\n throw new Error(\n `Expected task \"${taskId}\" to exist, but it was not found`,\n );\n }\n if (state.status !== expectedStatus) {\n throw new Error(\n `Expected task \"${taskId}\" status to be \"${expectedStatus}\", got \"${state.status}\"`,\n );\n }\n }\n }\n\n if (expected.agentStatus) {\n for (const [agentId, expectedStatus] of Object.entries(\n expected.agentStatus,\n )) {\n const state = orchestrator.getAgentState(agentId);\n if (!state) {\n throw new Error(\n `Expected agent \"${agentId}\" to exist, but it was not found`,\n );\n }\n if (state.status !== expectedStatus) {\n throw new Error(\n `Expected agent \"${agentId}\" status to be \"${expectedStatus}\", got \"${state.status}\"`,\n );\n }\n }\n }\n\n if (expected.totalTokens) {\n const { agentId, min, max } = expected.totalTokens;\n if (agentId) {\n const state = orchestrator.getAgentState(agentId);\n if (!state) {\n throw new Error(\n `Expected agent \"${agentId}\" to exist, but it was not found`,\n );\n }\n if (min !== undefined && state.totalTokens < min) {\n throw new Error(\n `Expected agent \"${agentId}\" tokens to be at least ${min}, got ${state.totalTokens}`,\n );\n }\n if (max !== undefined && state.totalTokens > max) {\n throw new Error(\n `Expected agent \"${agentId}\" tokens to be at most ${max}, got ${state.totalTokens}`,\n );\n }\n } else {\n const allStates = orchestrator.getAllAgentStates();\n const total = Object.values(allStates).reduce(\n (sum, s) => sum + s.totalTokens,\n 0,\n );\n if (min !== undefined && total < min) {\n throw new Error(\n `Expected total tokens to be at least ${min}, got ${total}`,\n );\n }\n if (max !== undefined && total > max) {\n throw new Error(\n `Expected total tokens to be at most ${max}, got ${total}`,\n );\n }\n }\n }\n\n if (expected.globalTokens) {\n const { min, max } = expected.globalTokens;\n const total = orchestrator.totalTokens;\n if (min !== undefined && total < min) {\n throw new Error(\n `Expected global tokens to be at least ${min}, got ${total}`,\n );\n }\n if (max !== undefined && total > max) {\n throw new Error(\n `Expected global tokens to be at most ${max}, got ${total}`,\n );\n }\n }\n\n if (expected.pendingHandoffs !== undefined) {\n const pendingCount = orchestrator.getPendingHandoffs().length;\n if (pendingCount !== expected.pendingHandoffs) {\n throw new Error(\n `Expected ${expected.pendingHandoffs} pending handoffs, got ${pendingCount}`,\n );\n }\n }\n}\n\n// ============================================================================\n// Mock Task Helpers\n// ============================================================================\n\n/**\n * Create a mock TaskRegistration for testing.\n *\n * @example\n * ```typescript\n * const task = createMockTask({ result: \"processed\" }, { delay: 100 });\n * const orchestrator = createTestMultiAgentOrchestrator({\n * agents: { writer: { agent: { name: \"writer\" } } },\n * tasks: { process: task },\n * });\n * ```\n */\nexport function createMockTask(\n output: unknown,\n options?: {\n delay?: number;\n shouldError?: boolean;\n label?: string;\n description?: string;\n },\n): TaskRegistration {\n return {\n run: async (_input: string, signal: AbortSignal) => {\n if (signal.aborted) {\n throw new Error(\"Task aborted\");\n }\n if (options?.delay && options.delay > 0) {\n await new Promise<void>((resolve, reject) => {\n const timer = setTimeout(resolve, options.delay);\n signal.addEventListener(\n \"abort\",\n () => {\n clearTimeout(timer);\n reject(new Error(\"Task aborted\"));\n },\n { once: true },\n );\n });\n }\n\n if (options?.shouldError) {\n throw new Error(\"Mock task error\");\n }\n\n return output;\n },\n label: options?.label ?? \"Mock Task\",\n description: options?.description,\n };\n}\n\n// ============================================================================\n// DAG Testing Helpers\n// ============================================================================\n\nimport { dag } from \"./multi-agent-orchestrator.js\";\nimport type {\n DagExecutionContext,\n DagNode,\n DagNodeStatus,\n DagPattern,\n} from \"./types.js\";\n\n/**\n * Create a test DAG pattern from a simplified node spec.\n *\n * @example\n * ```typescript\n * const pattern = createTestDag({\n * A: { handler: \"researcher\" },\n * B: { handler: \"writer\", deps: [\"A\"] },\n * C: { handler: \"reviewer\", deps: [\"B\"] },\n * });\n * ```\n */\nexport function createTestDag<T = unknown>(\n nodes: Record<\n string,\n Pick<\n DagNode,\n \"handler\" | \"deps\" | \"when\" | \"transform\" | \"timeout\" | \"priority\"\n >\n >,\n merge?: (context: DagExecutionContext) => T | Promise<T>,\n options?: {\n timeout?: number;\n maxConcurrent?: number;\n onNodeError?: \"fail\" | \"skip-downstream\" | \"continue\";\n },\n): DagPattern<T> {\n const defaultMerge = (context: DagExecutionContext) =>\n context.outputs as unknown as T;\n\n return dag<T>(nodes, merge ?? defaultMerge, options);\n}\n\n/**\n * Assert that a DAG execution produced the expected node statuses.\n *\n * @example\n * ```typescript\n * assertDagExecution(context, {\n * nodeStatuses: { A: \"completed\", B: \"completed\", C: \"skipped\" },\n * completedNodes: [\"A\", \"B\"],\n * skippedNodes: [\"C\"],\n * });\n * ```\n */\nexport function assertDagExecution(\n context: DagExecutionContext,\n expected: {\n nodeStatuses?: Record<string, DagNodeStatus>;\n completedNodes?: string[];\n skippedNodes?: string[];\n errorNodes?: string[];\n outputContains?: Record<string, unknown>;\n },\n): void {\n if (expected.nodeStatuses) {\n for (const [nodeId, expectedStatus] of Object.entries(\n expected.nodeStatuses,\n )) {\n const actual = context.statuses[nodeId];\n if (actual !== expectedStatus) {\n throw new Error(\n `Expected node \"${nodeId}\" status to be \"${expectedStatus}\", got \"${actual}\"`,\n );\n }\n }\n }\n\n if (expected.completedNodes) {\n for (const nodeId of expected.completedNodes) {\n if (context.statuses[nodeId] !== \"completed\") {\n throw new Error(\n `Expected node \"${nodeId}\" to be completed, got \"${context.statuses[nodeId]}\"`,\n );\n }\n }\n }\n\n if (expected.skippedNodes) {\n for (const nodeId of expected.skippedNodes) {\n if (context.statuses[nodeId] !== \"skipped\") {\n throw new Error(\n `Expected node \"${nodeId}\" to be skipped, got \"${context.statuses[nodeId]}\"`,\n );\n }\n }\n }\n\n if (expected.errorNodes) {\n for (const nodeId of expected.errorNodes) {\n if (context.statuses[nodeId] !== \"error\") {\n throw new Error(\n `Expected node \"${nodeId}\" to be error, got \"${context.statuses[nodeId]}\"`,\n );\n }\n }\n }\n\n if (expected.outputContains) {\n for (const [nodeId, expectedOutput] of Object.entries(\n expected.outputContains,\n )) {\n const actual = context.outputs[nodeId];\n if (actual !== expectedOutput) {\n throw new Error(\n `Expected node \"${nodeId}\" output to be ${JSON.stringify(expectedOutput)}, got ${JSON.stringify(actual)}`,\n );\n }\n }\n }\n}\n\n// ============================================================================\n// Debug Timeline Testing Helpers\n// ============================================================================\n\nimport { type DebugTimeline, createDebugTimeline } from \"./debug-timeline.js\";\nimport type { DebugEvent, DebugEventType } from \"./types.js\";\n\n/**\n * Create a test debug timeline pre-populated with events.\n *\n * @example\n * ```typescript\n * const timeline = createTestTimeline([\n * { type: \"agent_start\", agentId: \"researcher\", inputLength: 42 },\n * { type: \"agent_complete\", agentId: \"researcher\", outputLength: 100, durationMs: 500, totalTokens: 200 },\n * ]);\n *\n * expect(timeline.getEventsForAgent(\"researcher\")).toHaveLength(2);\n * ```\n */\nexport function createTestTimeline(\n events?: Array<Partial<DebugEvent> & { type: DebugEventType }>,\n options?: { maxEvents?: number },\n): DebugTimeline {\n const timeline = createDebugTimeline({\n maxEvents: options?.maxEvents ?? 500,\n });\n\n if (events) {\n for (const event of events) {\n timeline.record({\n timestamp: Date.now(),\n snapshotId: null,\n agentId: \"\",\n ...event,\n } as Omit<DebugEvent, \"id\">);\n }\n }\n\n return timeline;\n}\n\n/**\n * Assert that a debug timeline contains expected events.\n *\n * @example\n * ```typescript\n * assertTimelineEvents(timeline, {\n * totalEvents: 5,\n * eventTypes: [\"agent_start\", \"guardrail_check\", \"agent_complete\"],\n * agentEvents: { researcher: 3, writer: 2 },\n * hasType: \"guardrail_check\",\n * });\n * ```\n */\nexport function assertTimelineEvents(\n timeline: DebugTimeline,\n expected: {\n totalEvents?: number;\n minEvents?: number;\n maxEvents?: number;\n eventTypes?: DebugEventType[];\n agentEvents?: Record<string, number>;\n hasType?: DebugEventType;\n doesNotHaveType?: DebugEventType;\n },\n): void {\n const events = timeline.getEvents();\n\n if (\n expected.totalEvents !== undefined &&\n events.length !== expected.totalEvents\n ) {\n throw new Error(\n `Expected ${expected.totalEvents} timeline events, got ${events.length}`,\n );\n }\n\n if (expected.minEvents !== undefined && events.length < expected.minEvents) {\n throw new Error(\n `Expected at least ${expected.minEvents} timeline events, got ${events.length}`,\n );\n }\n\n if (expected.maxEvents !== undefined && events.length > expected.maxEvents) {\n throw new Error(\n `Expected at most ${expected.maxEvents} timeline events, got ${events.length}`,\n );\n }\n\n if (expected.eventTypes) {\n for (const type of expected.eventTypes) {\n const found = events.some((e) => e.type === type);\n if (!found) {\n throw new Error(\n `Expected timeline to contain event of type \"${type}\", but none found`,\n );\n }\n }\n }\n\n if (expected.agentEvents) {\n for (const [agentId, expectedCount] of Object.entries(\n expected.agentEvents,\n )) {\n const actual = timeline.getEventsForAgent(agentId).length;\n if (actual !== expectedCount) {\n throw new Error(\n `Expected ${expectedCount} events for agent \"${agentId}\", got ${actual}`,\n );\n }\n }\n }\n\n if (expected.hasType) {\n const found = events.some((e) => e.type === expected.hasType);\n if (!found) {\n throw new Error(\n `Expected timeline to contain event of type \"${expected.hasType}\"`,\n );\n }\n }\n\n if (expected.doesNotHaveType) {\n const found = events.some((e) => e.type === expected.doesNotHaveType);\n if (found) {\n throw new Error(\n `Expected timeline NOT to contain event of type \"${expected.doesNotHaveType}\"`,\n );\n }\n }\n}\n\n// ============================================================================\n// Self-Healing Testing Helpers\n// ============================================================================\n\nimport type { HealthMonitor } from \"./health-monitor.js\";\nimport type { ReflectionEvaluator } from \"./reflection.js\";\nimport type { RerouteEvent, Scratchpad } from \"./types.js\";\n\n/**\n * Create a runner that always fails, useful for testing self-healing.\n *\n * @example\n * ```typescript\n * const failing = createFailingRunner(new Error(\"Provider down\"));\n * const orchestrator = createAgentOrchestrator({\n * runner: failing,\n * selfHealing: { fallbackRunners: [backupRunner] },\n * });\n * ```\n */\nexport function createFailingRunner(\n error?: Error,\n options?: { delay?: number; failAfter?: number },\n): AgentRunner {\n let callCount = 0;\n const failAfter = options?.failAfter ?? 0;\n\n return async <T>(\n _agent: AgentLike,\n _input: string,\n _runOptions?: RunOptions,\n ): Promise<RunResult<T>> => {\n callCount++;\n\n if (failAfter > 0 && callCount <= failAfter) {\n return {\n output: \"success\" as T,\n messages: [],\n toolCalls: [],\n totalTokens: 10,\n };\n }\n\n if (options?.delay && options.delay > 0) {\n await new Promise((resolve) => setTimeout(resolve, options.delay));\n }\n\n throw error ?? new Error(\"Runner failed\");\n };\n}\n\n/**\n * Assert that an agent was rerouted during execution.\n *\n * @example\n * ```typescript\n * const events: RerouteEvent[] = [];\n * const orchestrator = createMultiAgentOrchestrator({\n * selfHealing: {\n * onReroute: (event) => events.push(event),\n * },\n * });\n *\n * // ... trigger reroute ...\n * assertRerouted(events, {\n * fromAgent: \"primary\",\n * toAgent: \"backup\",\n * reason: /circuit breaker/i,\n * });\n * ```\n */\nexport function assertRerouted(\n events: RerouteEvent[],\n expected: {\n fromAgent?: string;\n toAgent?: string;\n reason?: string | RegExp;\n minReroutes?: number;\n },\n): void {\n if (events.length === 0) {\n throw new Error(\"Expected at least one reroute event, but none occurred\");\n }\n\n if (\n expected.minReroutes !== undefined &&\n events.length < expected.minReroutes\n ) {\n throw new Error(\n `Expected at least ${expected.minReroutes} reroute events, got ${events.length}`,\n );\n }\n\n if (expected.fromAgent) {\n const found = events.some((e) => e.originalAgent === expected.fromAgent);\n if (!found) {\n throw new Error(\n `Expected reroute from agent \"${expected.fromAgent}\", but no matching event found`,\n );\n }\n }\n\n if (expected.toAgent) {\n const found = events.some((e) => e.reroutedTo === expected.toAgent);\n if (!found) {\n throw new Error(\n `Expected reroute to agent \"${expected.toAgent}\", but no matching event found`,\n );\n }\n }\n\n if (expected.reason) {\n const found = events.some((e) => {\n if (typeof expected.reason === \"string\") {\n return e.reason.includes(expected.reason);\n }\n\n return expected.reason!.test(e.reason);\n });\n if (!found) {\n throw new Error(\n `Expected reroute reason matching ${expected.reason}, but no matching event found`,\n );\n }\n }\n}\n\n/**\n * Assert the health state of an agent in the health monitor.\n *\n * @example\n * ```typescript\n * assertAgentHealth(monitor, \"researcher\", {\n * minScore: 70,\n * circuitState: \"CLOSED\",\n * });\n * ```\n */\nexport function assertAgentHealth(\n monitor: HealthMonitor,\n agentId: string,\n expected: {\n minScore?: number;\n maxScore?: number;\n circuitState?: \"CLOSED\" | \"OPEN\" | \"HALF_OPEN\";\n minSuccessRate?: number;\n },\n): void {\n const metrics = monitor.getMetrics(agentId);\n\n if (\n expected.minScore !== undefined &&\n metrics.healthScore < expected.minScore\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" health score to be at least ${expected.minScore}, got ${metrics.healthScore}`,\n );\n }\n\n if (\n expected.maxScore !== undefined &&\n metrics.healthScore > expected.maxScore\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" health score to be at most ${expected.maxScore}, got ${metrics.healthScore}`,\n );\n }\n\n if (\n expected.circuitState !== undefined &&\n metrics.circuitState !== expected.circuitState\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" circuit state to be \"${expected.circuitState}\", got \"${metrics.circuitState}\"`,\n );\n }\n\n if (\n expected.minSuccessRate !== undefined &&\n metrics.successRate < expected.minSuccessRate\n ) {\n throw new Error(\n `Expected agent \"${agentId}\" success rate to be at least ${expected.minSuccessRate}, got ${metrics.successRate}`,\n );\n }\n}\n\n// ============================================================================\n// Checkpoint Test Helpers\n// ============================================================================\n\n/**\n * Create a test checkpoint store (wraps InMemoryCheckpointStore with assertion helpers).\n *\n * @example\n * ```typescript\n * const store = createTestCheckpointStore();\n * const orchestrator = createAgentOrchestrator({ runner, checkpointStore: store });\n * const cp = await orchestrator.checkpoint();\n * expect(store.saved).toHaveLength(1);\n * ```\n */\nexport function createTestCheckpointStore(\n maxCheckpoints = 100,\n): CheckpointStore & {\n saved: Checkpoint[];\n inner: InMemoryCheckpointStore;\n /** Get the most recently saved checkpoint */\n getLatest: () => Checkpoint | undefined;\n} {\n const inner = new InMemoryCheckpointStore({ maxCheckpoints });\n const saved: Checkpoint[] = [];\n\n return {\n inner,\n saved,\n getLatest: () => saved[saved.length - 1],\n async save(checkpoint: Checkpoint): Promise<string> {\n saved.push(checkpoint);\n\n return inner.save(checkpoint);\n },\n load: (id: string) => inner.load(id),\n list: () => inner.list(),\n delete: (id: string) => inner.delete(id),\n clear: () => inner.clear(),\n prune: () => inner.prune(),\n };\n}\n\n/**\n * Assert that a checkpoint has expected properties.\n */\nexport function assertCheckpoint(\n checkpoint: Checkpoint,\n expected: {\n orchestratorType?: \"single\" | \"multi\";\n hasTimeline?: boolean;\n hasMemory?: boolean;\n hasSystemExport?: boolean;\n label?: string;\n },\n): void {\n if (\n expected.orchestratorType !== undefined &&\n checkpoint.orchestratorType !== expected.orchestratorType\n ) {\n throw new Error(\n `Expected checkpoint orchestratorType \"${expected.orchestratorType}\", got \"${checkpoint.orchestratorType}\"`,\n );\n }\n\n if (\n expected.hasSystemExport === true &&\n (!checkpoint.systemExport || checkpoint.systemExport === \"\")\n ) {\n throw new Error(\n \"Expected checkpoint to have non-empty systemExport, but it was empty\",\n );\n }\n\n if (expected.hasTimeline === true && checkpoint.timelineExport === null) {\n throw new Error(\n \"Expected checkpoint to have timeline export, but it was null\",\n );\n }\n\n if (expected.hasTimeline === false && checkpoint.timelineExport !== null) {\n throw new Error(\n \"Expected checkpoint to have no timeline export, but it was present\",\n );\n }\n\n if (expected.hasMemory === true && checkpoint.memoryExport === null) {\n throw new Error(\n \"Expected checkpoint to have memory export, but it was null\",\n );\n }\n\n if (expected.hasMemory === false && checkpoint.memoryExport !== null) {\n throw new Error(\n \"Expected checkpoint to have no memory export, but it was present\",\n );\n }\n\n if (expected.label !== undefined && checkpoint.label !== expected.label) {\n throw new Error(\n `Expected checkpoint label \"${expected.label}\", got \"${checkpoint.label}\"`,\n );\n }\n}\n\n// ============================================================================\n// Breakpoint Test Helpers\n// ============================================================================\n\n/** Options for the breakpoint simulator */\nexport interface BreakpointSimulatorOptions {\n /** Auto-resume after this delay (ms). Default: 0 (immediate) */\n autoResumeDelay?: number;\n /** Modifications to apply on resume */\n modifications?: BreakpointModifications;\n /** If true, cancel instead of resume */\n cancel?: boolean;\n /** Cancel reason */\n cancelReason?: string;\n}\n\n/**\n * Create a breakpoint simulator that auto-resolves breakpoints.\n *\n * @example\n * ```typescript\n * const simulator = createBreakpointSimulator({ autoResumeDelay: 10 });\n * const orchestrator = createAgentOrchestrator({\n * runner,\n * breakpoints: [{ type: \"pre_agent_run\" }],\n * onBreakpoint: simulator.handler,\n * });\n * // Run agent — breakpoint fires and auto-resumes\n * await orchestrator.run(\"test input\");\n * expect(simulator.hits).toHaveLength(1);\n * ```\n */\n/** Minimal interface for breakpoint-capable orchestrators */\nexport interface BreakpointCapable {\n resumeBreakpoint(id: string, modifications?: BreakpointModifications): void;\n cancelBreakpoint(id: string, reason?: string): void;\n}\n\n/**\n * Create a breakpoint simulator that auto-resolves breakpoints for testing.\n *\n * @param options - Simulator options including `autoResumeDelay` and `modifications`.\n * @returns An object with `handler`, `hits`, and `attachTo` for test assertions.\n */\nexport function createBreakpointSimulator(\n options: BreakpointSimulatorOptions = {},\n): {\n handler: (request: BreakpointRequest) => void;\n hits: BreakpointRequest[];\n attachTo: (orchestrator: BreakpointCapable) => void;\n} {\n const hits: BreakpointRequest[] = [];\n let orchestratorRef: BreakpointCapable | null = null;\n let attached = false;\n\n const handler = (request: BreakpointRequest) => {\n hits.push(request);\n\n if (!attached) {\n throw new Error(\n \"[Directive] BreakpointSimulator: handler called but attachTo() was never called. \" +\n \"Breakpoints will not be resolved. Call simulator.attachTo(orchestrator) after creation.\",\n );\n }\n\n const delay = options.autoResumeDelay ?? 0;\n\n const doResolve = () => {\n if (!orchestratorRef) {\n return;\n }\n if (options.cancel) {\n orchestratorRef.cancelBreakpoint(request.id, options.cancelReason);\n } else {\n orchestratorRef.resumeBreakpoint(request.id, options.modifications);\n }\n };\n\n if (delay > 0) {\n setTimeout(doResolve, delay);\n } else {\n // Use queueMicrotask so the breakpoint state is written before we resolve\n queueMicrotask(doResolve);\n }\n };\n\n return {\n handler,\n hits,\n attachTo: (orch: BreakpointCapable) => {\n orchestratorRef = orch;\n attached = true;\n },\n };\n}\n\n/**\n * Assert that a breakpoint was hit with expected properties.\n */\nexport function assertBreakpointHit(\n hits: BreakpointRequest[],\n expected: {\n type?: string;\n agentId?: string;\n count?: number;\n },\n): void {\n if (expected.count !== undefined && hits.length !== expected.count) {\n throw new Error(\n `Expected ${expected.count} breakpoint hits, got ${hits.length}`,\n );\n }\n\n if (expected.type) {\n const found = hits.some((h) => h.type === expected.type);\n if (!found) {\n const types = hits.map((h) => h.type).join(\", \");\n\n throw new Error(\n `Expected breakpoint of type \"${expected.type}\", found types: [${types}]`,\n );\n }\n }\n\n if (expected.agentId) {\n const found = hits.some((h) => h.agentId === expected.agentId);\n if (!found) {\n const agents = hits.map((h) => h.agentId).join(\", \");\n\n throw new Error(\n `Expected breakpoint for agent \"${expected.agentId}\", found agents: [${agents}]`,\n );\n }\n }\n}\n\n// ============================================================================\n// Structured Output Test Helpers\n// ============================================================================\n\n/**\n * Create a mock SafeParseable schema for testing.\n *\n * @example\n * ```typescript\n * const schema = createMockSchema((data) => typeof data === \"object\" && data !== null);\n * const orchestrator = createAgentOrchestrator({\n * runner,\n * outputSchema: schema,\n * });\n * ```\n */\nexport function createMockSchema<T>(\n validate: (data: unknown) => boolean,\n description?: string,\n): {\n safeParse: (data: unknown) => {\n success: boolean;\n data?: T;\n error?: { message: string };\n };\n description?: string;\n} {\n return {\n safeParse: (data: unknown) => {\n if (validate(data)) {\n return { success: true, data: data as T };\n }\n\n return { success: false, error: { message: \"Validation failed\" } };\n },\n description,\n };\n}\n\n// ============================================================================\n// Multiplexed Stream Test Helpers\n// ============================================================================\n\n/**\n * Collect all chunks from a multiplexed stream into an array.\n *\n * @example\n * ```typescript\n * const { stream } = orchestrator.runParallelStream([\"a\", \"b\"], \"input\", merge);\n * const chunks = await collectMultiplexedStream(stream);\n * expect(chunks.length).toBeGreaterThan(0);\n * ```\n */\nexport async function collectMultiplexedStream(\n stream: AsyncIterable<MultiplexedStreamChunk>,\n): Promise<MultiplexedStreamChunk[]> {\n const chunks: MultiplexedStreamChunk[] = [];\n for await (const chunk of stream) {\n chunks.push(chunk);\n }\n\n return chunks;\n}\n\n/**\n * Assert properties of collected multiplexed stream chunks.\n */\nexport function assertMultiplexedStream(\n chunks: MultiplexedStreamChunk[],\n expected: {\n agentIds?: string[];\n minChunks?: number;\n hasDone?: boolean;\n hasErrors?: boolean;\n },\n): void {\n if (expected.minChunks !== undefined && chunks.length < expected.minChunks) {\n throw new Error(\n `Expected at least ${expected.minChunks} chunks, got ${chunks.length}`,\n );\n }\n\n if (expected.agentIds) {\n const seenAgents = new Set(chunks.map((c) => c.agentId));\n for (const agentId of expected.agentIds) {\n if (!seenAgents.has(agentId)) {\n throw new Error(\n `Expected chunks from agent \"${agentId}\", found agents: [${[...seenAgents].join(\", \")}]`,\n );\n }\n }\n }\n\n if (expected.hasDone === true) {\n const hasDone = chunks.some((c) => c.chunk.type === \"done\");\n if (!hasDone) {\n throw new Error(\"Expected at least one 'done' chunk, found none\");\n }\n }\n\n if (expected.hasErrors === true) {\n const hasError = chunks.some((c) => c.chunk.type === \"error\");\n if (!hasError) {\n throw new Error(\"Expected at least one 'error' chunk, found none\");\n }\n }\n\n if (expected.hasErrors === false) {\n const hasError = chunks.some((c) => c.chunk.type === \"error\");\n if (hasError) {\n throw new Error(\"Expected no 'error' chunks, but found some\");\n }\n }\n}\n\n// ============================================================================\n// Reflection Test Helpers\n// ============================================================================\n\n/**\n * Create a test reflection evaluator that passes after N iterations.\n *\n * @example\n * ```typescript\n * const evaluator = createTestReflectionEvaluator({ passAfter: 2 });\n * const reflective = withReflection(runner, { evaluate: evaluator });\n * ```\n */\nexport function createTestReflectionEvaluator(options?: {\n /** Pass after this many evaluations (1 = pass on first try). Default: 1 */\n passAfter?: number;\n /** Feedback to provide on failure */\n feedback?: string;\n /** Score to assign (0-1) */\n score?: number;\n}): ReflectionEvaluator {\n const passAfter = options?.passAfter ?? 1;\n const feedback = options?.feedback ?? \"Needs improvement\";\n const score = options?.score;\n let callCount = 0;\n\n return (_output: unknown, _context) => {\n callCount++;\n const passed = callCount >= passAfter;\n\n return {\n passed,\n feedback: passed ? undefined : feedback,\n score: score ?? (passed ? 1 : 0.5),\n };\n };\n}\n\n// ============================================================================\n// Scratchpad Test Helpers\n// ============================================================================\n\n/**\n * Assert that a scratchpad contains expected values.\n *\n * @example\n * ```typescript\n * assertScratchpadState(orchestrator.scratchpad!, {\n * \"plan.status\": \"complete\",\n * \"research.results\": expect.any(Array),\n * });\n * ```\n */\nexport function assertScratchpadState(\n scratchpad: Scratchpad,\n expected: Record<string, unknown>,\n): void {\n const all = scratchpad.getAll();\n for (const [key, expectedValue] of Object.entries(expected)) {\n const actual = all[key];\n if (actual !== expectedValue) {\n throw new Error(\n `Expected scratchpad key \"${key}\" to be ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actual)}`,\n );\n }\n }\n}\n\n// ============================================================================\n// Derivation Test Helpers\n// ============================================================================\n\n/**\n * Assert that derived values match expected values.\n *\n * @example\n * ```typescript\n * assertDerivedValues(orchestrator, {\n * totalRuns: 3,\n * allComplete: true,\n * });\n * ```\n */\nexport function assertDerivedValues(\n orchestrator: MultiAgentOrchestrator,\n expected: Record<string, unknown>,\n): void {\n const derived = orchestrator.derived;\n for (const [key, expectedValue] of Object.entries(expected)) {\n const actual = derived[key];\n if (typeof expectedValue === \"object\" && expectedValue !== null) {\n // Sort keys for order-independent comparison\n const sortedStringify = (v: unknown): string =>\n JSON.stringify(v, Object.keys(v as Record<string, unknown>).sort());\n if (sortedStringify(actual) !== sortedStringify(expectedValue)) {\n throw new Error(\n `Expected derived value \"${key}\" to be ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actual)}`,\n );\n }\n } else if (actual !== expectedValue) {\n throw new Error(\n `Expected derived value \"${key}\" to be ${JSON.stringify(expectedValue)}, got ${JSON.stringify(actual)}`,\n );\n }\n }\n}\n"]}
@@ -1453,4 +1453,4 @@ interface CheckpointDiff {
1453
1453
  nodesCompleted?: string[];
1454
1454
  }
1455
1455
 
1456
- export { type ConstraintEvaluateEvent as $, type AgentLike as A, type BreakpointState as B, type CheckpointDiff as C, type DagNode as D, type ApprovalRequestEvent as E, type ApprovalResponseEvent as F, type GuardrailFn as G, type BreakpointConfig as H, type InputGuardrailData as I, type BreakpointContext as J, type BreakpointHitEvent as K, type BreakpointModifications as L, type Message as M, type BreakpointRequest as N, type OutputGuardrailData as O, type PatternCheckpointState as P, type BreakpointResumedEvent as Q, type RelaxationTier as R, type SchemaValidator as S, type ToolCallGuardrailData as T, type BreakpointState$1 as U, type BreakpointType as V, type Checkpoint as W, type CheckpointContext as X, type CheckpointLocalState as Y, type CheckpointRestoreEvent as Z, type CheckpointSaveEvent as _, type AdapterHooks as a, type TaskProgressEvent as a$, type CrossAgentDerivationFn as a0, type CrossAgentSnapshot as a1, type DagCheckpointState as a2, type DagNodeStatus as a3, type DagNodeUpdateEvent as a4, type DebateCheckpointState as a5, type DebateRoundEvent as a6, type DebugEventBase as a7, type DebugEventType as a8, type DerivationUpdateEvent as a9, type PatternCheckpointBase as aA, type PatternCompleteEvent as aB, type PatternStartEvent as aC, type RaceCancelledEvent as aD, type RaceStartEvent as aE, type RaceWinnerEvent as aF, type ReflectCheckpointState as aG, type ReflectionIterationEvent as aH, type RejectedRequest as aI, type RelaxationContext as aJ, type RelaxationRecord as aK, type RelaxationStrategy as aL, type RerouteDebugEvent as aM, type RerouteEvent as aN, type ResolverCompleteEvent as aO, type ResolverErrorEvent as aP, type ResolverStartEvent as aQ, type SchemaValidationResult as aR, type Scratchpad as aS, type ScratchpadUpdateEvent as aT, type SelfHealingConfig as aU, type SequentialCheckpointState as aV, type SingleAgentCheckpointLocalState as aW, type StreamingCallbackRunner as aX, type SupervisorCheckpointState as aY, type TaskCompleteEvent as aZ, type TaskErrorEvent as a_, type GoalCheckpointConfig as aa, type GoalCheckpointState as ab, type GoalStepMetrics as ac, type GuardrailCheckEvent as ad, type GuardrailContext as ae, GuardrailError as af, type GuardrailErrorCode as ag, type GuardrailResult as ah, type GuardrailRetryConfig as ai, type GuardrailsConfig as aj, type HandoffCompleteEvent as ak, type HandoffStartEvent as al, type HealthMonitorConfig as am, InMemoryCheckpointStore as an, type InMemoryCheckpointStoreOptions as ao, MAX_BREAKPOINT_HISTORY as ap, type MultiAgentBreakpointType as aq, type MultiAgentCheckpointLocalState as ar, type MultiAgentLifecycleHooks as as, type MultiAgentSelfHealingConfig as at, type NamedGuardrail as au, type OrchestratorDebugConfig as av, type OrchestratorLifecycleHooks as aw, type OrchestratorResolver as ax, type OrchestratorResolverContext as ay, type OrchestratorState as az, type AgentRunner as b, type TaskStartEvent as b0, type TokenUsage as b1, type ToolCall as b2, createBreakpointId as b3, createCheckpointId as b4, createInitialBreakpointState as b5, isGuardrailError as b6, matchBreakpoint as b7, validateCheckpoint as b8, type ApprovalState as c, type AgentState as d, type CheckpointStore as e, type CheckpointProgress as f, type AgentSelectionStrategy as g, type DagExecutionContext as h, type DagPattern as i, type GoalNode as j, type GoalMetrics as k, type PatternCheckpointConfig as l, type GoalPattern as m, type RunResult as n, type OrchestratorConstraint as o, type RunOptions as p, type DebugEvent as q, type GoalResult as r, type AgentCircuitBreakerConfig as s, type AgentCompleteEvent as t, type AgentErrorEvent as u, type AgentHealthState as v, type AgentRetryConfig as w, type AgentRetryEvent as x, type AgentStartEvent as y, type ApprovalRequest as z };
1456
+ export { type MultiAgentBreakpointType as $, type ApprovalRequest as A, type BreakpointModifications as B, type Checkpoint as C, type DagExecutionContext as D, type GoalPattern as E, type GoalNode as F, type GuardrailResult as G, type HealthMonitorConfig as H, type InputGuardrailData as I, type AgentSelectionStrategy as J, type RelaxationTier as K, type GoalResult as L, type Message as M, type NamedGuardrail as N, type OutputGuardrailData as O, type PatternCheckpointConfig as P, type GoalCheckpointState as Q, type RunOptions as R, type Scratchpad as S, type ToolCallGuardrailData as T, type SequentialCheckpointState as U, type SupervisorCheckpointState as V, type ReflectCheckpointState as W, type DebateCheckpointState as X, type DagCheckpointState as Y, type MultiAgentLifecycleHooks as Z, type MultiAgentSelfHealingConfig as _, type ToolCall as a, type TaskProgressEvent as a$, type CrossAgentDerivationFn as a0, type ApprovalState as a1, type AgentState as a2, type AgentCircuitBreakerConfig as a3, type AgentCompleteEvent as a4, type AgentErrorEvent as a5, type AgentHealthState as a6, type AgentRetryEvent as a7, type AgentStartEvent as a8, type ApprovalRequestEvent as a9, type HandoffStartEvent as aA, type InMemoryCheckpointStoreOptions as aB, MAX_BREAKPOINT_HISTORY as aC, type MultiAgentCheckpointLocalState as aD, type OrchestratorResolverContext as aE, type PatternCheckpointBase as aF, type PatternCheckpointState as aG, type PatternCompleteEvent as aH, type PatternStartEvent as aI, type RaceCancelledEvent as aJ, type RaceStartEvent as aK, type RaceWinnerEvent as aL, type ReflectionIterationEvent as aM, type RejectedRequest as aN, type RelaxationContext as aO, type RelaxationRecord as aP, type RelaxationStrategy as aQ, type RerouteDebugEvent as aR, type ResolverCompleteEvent as aS, type ResolverErrorEvent as aT, type ResolverStartEvent as aU, type SchemaValidationResult as aV, type SchemaValidator as aW, type ScratchpadUpdateEvent as aX, type SingleAgentCheckpointLocalState as aY, type TaskCompleteEvent as aZ, type TaskErrorEvent as a_, type ApprovalResponseEvent as aa, type BreakpointContext as ab, type BreakpointHitEvent as ac, type BreakpointResumedEvent as ad, type BreakpointState$1 as ae, type BreakpointType as af, type CheckpointContext as ag, type CheckpointDiff as ah, type CheckpointLocalState as ai, type CheckpointProgress as aj, type CheckpointRestoreEvent as ak, type CheckpointSaveEvent as al, type ConstraintEvaluateEvent as am, type CrossAgentSnapshot as an, type DagNodeUpdateEvent as ao, type DebateRoundEvent as ap, type DebugEventBase as aq, type DerivationUpdateEvent as ar, type GoalCheckpointConfig as as, type GoalMetrics as at, type GoalStepMetrics as au, type GuardrailCheckEvent as av, GuardrailError as aw, type GuardrailErrorCode as ax, type GuardrailRetryConfig as ay, type HandoffCompleteEvent as az, type AgentLike as b, type TaskStartEvent as b0, type TokenUsage as b1, createBreakpointId as b2, createCheckpointId as b3, createInitialBreakpointState as b4, isGuardrailError as b5, matchBreakpoint as b6, validateCheckpoint as b7, type BreakpointState as b8, type AgentRunner as c, type BreakpointRequest as d, type DagNodeStatus as e, type RerouteEvent as f, type DebugEventType as g, type CheckpointStore as h, InMemoryCheckpointStore as i, type DagNode as j, type DagPattern as k, type DebugEvent as l, type GuardrailFn as m, type GuardrailContext as n, type AdapterHooks as o, type StreamingCallbackRunner as p, type RunResult as q, type OrchestratorState as r, type OrchestratorConstraint as s, type OrchestratorResolver as t, type GuardrailsConfig as u, type OrchestratorDebugConfig as v, type AgentRetryConfig as w, type OrchestratorLifecycleHooks as x, type SelfHealingConfig as y, type BreakpointConfig as z };
@@ -1453,4 +1453,4 @@ interface CheckpointDiff {
1453
1453
  nodesCompleted?: string[];
1454
1454
  }
1455
1455
 
1456
- export { type ConstraintEvaluateEvent as $, type AgentLike as A, type BreakpointState as B, type CheckpointDiff as C, type DagNode as D, type ApprovalRequestEvent as E, type ApprovalResponseEvent as F, type GuardrailFn as G, type BreakpointConfig as H, type InputGuardrailData as I, type BreakpointContext as J, type BreakpointHitEvent as K, type BreakpointModifications as L, type Message as M, type BreakpointRequest as N, type OutputGuardrailData as O, type PatternCheckpointState as P, type BreakpointResumedEvent as Q, type RelaxationTier as R, type SchemaValidator as S, type ToolCallGuardrailData as T, type BreakpointState$1 as U, type BreakpointType as V, type Checkpoint as W, type CheckpointContext as X, type CheckpointLocalState as Y, type CheckpointRestoreEvent as Z, type CheckpointSaveEvent as _, type AdapterHooks as a, type TaskProgressEvent as a$, type CrossAgentDerivationFn as a0, type CrossAgentSnapshot as a1, type DagCheckpointState as a2, type DagNodeStatus as a3, type DagNodeUpdateEvent as a4, type DebateCheckpointState as a5, type DebateRoundEvent as a6, type DebugEventBase as a7, type DebugEventType as a8, type DerivationUpdateEvent as a9, type PatternCheckpointBase as aA, type PatternCompleteEvent as aB, type PatternStartEvent as aC, type RaceCancelledEvent as aD, type RaceStartEvent as aE, type RaceWinnerEvent as aF, type ReflectCheckpointState as aG, type ReflectionIterationEvent as aH, type RejectedRequest as aI, type RelaxationContext as aJ, type RelaxationRecord as aK, type RelaxationStrategy as aL, type RerouteDebugEvent as aM, type RerouteEvent as aN, type ResolverCompleteEvent as aO, type ResolverErrorEvent as aP, type ResolverStartEvent as aQ, type SchemaValidationResult as aR, type Scratchpad as aS, type ScratchpadUpdateEvent as aT, type SelfHealingConfig as aU, type SequentialCheckpointState as aV, type SingleAgentCheckpointLocalState as aW, type StreamingCallbackRunner as aX, type SupervisorCheckpointState as aY, type TaskCompleteEvent as aZ, type TaskErrorEvent as a_, type GoalCheckpointConfig as aa, type GoalCheckpointState as ab, type GoalStepMetrics as ac, type GuardrailCheckEvent as ad, type GuardrailContext as ae, GuardrailError as af, type GuardrailErrorCode as ag, type GuardrailResult as ah, type GuardrailRetryConfig as ai, type GuardrailsConfig as aj, type HandoffCompleteEvent as ak, type HandoffStartEvent as al, type HealthMonitorConfig as am, InMemoryCheckpointStore as an, type InMemoryCheckpointStoreOptions as ao, MAX_BREAKPOINT_HISTORY as ap, type MultiAgentBreakpointType as aq, type MultiAgentCheckpointLocalState as ar, type MultiAgentLifecycleHooks as as, type MultiAgentSelfHealingConfig as at, type NamedGuardrail as au, type OrchestratorDebugConfig as av, type OrchestratorLifecycleHooks as aw, type OrchestratorResolver as ax, type OrchestratorResolverContext as ay, type OrchestratorState as az, type AgentRunner as b, type TaskStartEvent as b0, type TokenUsage as b1, type ToolCall as b2, createBreakpointId as b3, createCheckpointId as b4, createInitialBreakpointState as b5, isGuardrailError as b6, matchBreakpoint as b7, validateCheckpoint as b8, type ApprovalState as c, type AgentState as d, type CheckpointStore as e, type CheckpointProgress as f, type AgentSelectionStrategy as g, type DagExecutionContext as h, type DagPattern as i, type GoalNode as j, type GoalMetrics as k, type PatternCheckpointConfig as l, type GoalPattern as m, type RunResult as n, type OrchestratorConstraint as o, type RunOptions as p, type DebugEvent as q, type GoalResult as r, type AgentCircuitBreakerConfig as s, type AgentCompleteEvent as t, type AgentErrorEvent as u, type AgentHealthState as v, type AgentRetryConfig as w, type AgentRetryEvent as x, type AgentStartEvent as y, type ApprovalRequest as z };
1456
+ export { type MultiAgentBreakpointType as $, type ApprovalRequest as A, type BreakpointModifications as B, type Checkpoint as C, type DagExecutionContext as D, type GoalPattern as E, type GoalNode as F, type GuardrailResult as G, type HealthMonitorConfig as H, type InputGuardrailData as I, type AgentSelectionStrategy as J, type RelaxationTier as K, type GoalResult as L, type Message as M, type NamedGuardrail as N, type OutputGuardrailData as O, type PatternCheckpointConfig as P, type GoalCheckpointState as Q, type RunOptions as R, type Scratchpad as S, type ToolCallGuardrailData as T, type SequentialCheckpointState as U, type SupervisorCheckpointState as V, type ReflectCheckpointState as W, type DebateCheckpointState as X, type DagCheckpointState as Y, type MultiAgentLifecycleHooks as Z, type MultiAgentSelfHealingConfig as _, type ToolCall as a, type TaskProgressEvent as a$, type CrossAgentDerivationFn as a0, type ApprovalState as a1, type AgentState as a2, type AgentCircuitBreakerConfig as a3, type AgentCompleteEvent as a4, type AgentErrorEvent as a5, type AgentHealthState as a6, type AgentRetryEvent as a7, type AgentStartEvent as a8, type ApprovalRequestEvent as a9, type HandoffStartEvent as aA, type InMemoryCheckpointStoreOptions as aB, MAX_BREAKPOINT_HISTORY as aC, type MultiAgentCheckpointLocalState as aD, type OrchestratorResolverContext as aE, type PatternCheckpointBase as aF, type PatternCheckpointState as aG, type PatternCompleteEvent as aH, type PatternStartEvent as aI, type RaceCancelledEvent as aJ, type RaceStartEvent as aK, type RaceWinnerEvent as aL, type ReflectionIterationEvent as aM, type RejectedRequest as aN, type RelaxationContext as aO, type RelaxationRecord as aP, type RelaxationStrategy as aQ, type RerouteDebugEvent as aR, type ResolverCompleteEvent as aS, type ResolverErrorEvent as aT, type ResolverStartEvent as aU, type SchemaValidationResult as aV, type SchemaValidator as aW, type ScratchpadUpdateEvent as aX, type SingleAgentCheckpointLocalState as aY, type TaskCompleteEvent as aZ, type TaskErrorEvent as a_, type ApprovalResponseEvent as aa, type BreakpointContext as ab, type BreakpointHitEvent as ac, type BreakpointResumedEvent as ad, type BreakpointState$1 as ae, type BreakpointType as af, type CheckpointContext as ag, type CheckpointDiff as ah, type CheckpointLocalState as ai, type CheckpointProgress as aj, type CheckpointRestoreEvent as ak, type CheckpointSaveEvent as al, type ConstraintEvaluateEvent as am, type CrossAgentSnapshot as an, type DagNodeUpdateEvent as ao, type DebateRoundEvent as ap, type DebugEventBase as aq, type DerivationUpdateEvent as ar, type GoalCheckpointConfig as as, type GoalMetrics as at, type GoalStepMetrics as au, type GuardrailCheckEvent as av, GuardrailError as aw, type GuardrailErrorCode as ax, type GuardrailRetryConfig as ay, type HandoffCompleteEvent as az, type AgentLike as b, type TaskStartEvent as b0, type TokenUsage as b1, createBreakpointId as b2, createCheckpointId as b3, createInitialBreakpointState as b4, isGuardrailError as b5, matchBreakpoint as b6, validateCheckpoint as b7, type BreakpointState as b8, type AgentRunner as c, type BreakpointRequest as d, type DagNodeStatus as e, type RerouteEvent as f, type DebugEventType as g, type CheckpointStore as h, InMemoryCheckpointStore as i, type DagNode as j, type DagPattern as k, type DebugEvent as l, type GuardrailFn as m, type GuardrailContext as n, type AdapterHooks as o, type StreamingCallbackRunner as p, type RunResult as q, type OrchestratorState as r, type OrchestratorConstraint as s, type OrchestratorResolver as t, type GuardrailsConfig as u, type OrchestratorDebugConfig as v, type AgentRetryConfig as w, type OrchestratorLifecycleHooks as x, type SelfHealingConfig as y, type BreakpointConfig as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directive-run/ai",
3
- "version": "1.12.0",
3
+ "version": "1.14.0",
4
4
  "description": "AI guardrails and orchestration for Directive. Prompt injection, PII detection, cost tracking, multi-agent patterns.",
5
5
  "license": "(MIT OR Apache-2.0)",
6
6
  "author": "Jason Comes",
@@ -73,6 +73,36 @@
73
73
  "types": "./dist/gemini.d.ts",
74
74
  "require": "./dist/gemini.cjs",
75
75
  "import": "./dist/gemini.js"
76
+ },
77
+ "./multi-agent": {
78
+ "types": "./dist/multi-agent.d.ts",
79
+ "require": "./dist/multi-agent.cjs",
80
+ "import": "./dist/multi-agent.js"
81
+ },
82
+ "./predicate": {
83
+ "types": "./dist/predicate.d.ts",
84
+ "require": "./dist/predicate.cjs",
85
+ "import": "./dist/predicate.js"
86
+ },
87
+ "./guardrails": {
88
+ "types": "./dist/guardrails.d.ts",
89
+ "require": "./dist/guardrails.cjs",
90
+ "import": "./dist/guardrails.js"
91
+ },
92
+ "./devtools": {
93
+ "types": "./dist/devtools.d.ts",
94
+ "require": "./dist/devtools.cjs",
95
+ "import": "./dist/devtools.js"
96
+ },
97
+ "./evals": {
98
+ "types": "./dist/evals.d.ts",
99
+ "require": "./dist/evals.cjs",
100
+ "import": "./dist/evals.js"
101
+ },
102
+ "./mcp": {
103
+ "types": "./dist/mcp.d.ts",
104
+ "require": "./dist/mcp.cjs",
105
+ "import": "./dist/mcp.js"
76
106
  }
77
107
  },
78
108
  "files": [
@@ -85,7 +115,7 @@
85
115
  "@types/node": "^25.2.0",
86
116
  "tsup": "^8.3.5",
87
117
  "typescript": "^5.7.2",
88
- "@directive-run/core": "1.12.0"
118
+ "@directive-run/core": "1.14.0"
89
119
  },
90
120
  "scripts": {
91
121
  "build": "tsup",