@directive-run/ai 0.1.1 → 0.3.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 (44) hide show
  1. package/README.md +97 -73
  2. package/dist/anthropic.cjs +1 -1
  3. package/dist/anthropic.cjs.map +1 -1
  4. package/dist/anthropic.d.cts +5 -9
  5. package/dist/anthropic.d.ts +5 -9
  6. package/dist/anthropic.js +1 -1
  7. package/dist/anthropic.js.map +1 -1
  8. package/dist/gemini.cjs +3 -0
  9. package/dist/gemini.cjs.map +1 -0
  10. package/dist/gemini.d.cts +93 -0
  11. package/dist/gemini.d.ts +93 -0
  12. package/dist/gemini.js +3 -0
  13. package/dist/gemini.js.map +1 -0
  14. package/dist/index.cjs +117 -45
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +1376 -2118
  17. package/dist/index.d.ts +1376 -2118
  18. package/dist/index.js +117 -45
  19. package/dist/index.js.map +1 -1
  20. package/dist/multi-agent-orchestrator-CxL8ycw_.d.cts +2290 -0
  21. package/dist/multi-agent-orchestrator-uMp8bLfV.d.ts +2290 -0
  22. package/dist/ollama.cjs.map +1 -1
  23. package/dist/ollama.d.cts +3 -2
  24. package/dist/ollama.d.ts +3 -2
  25. package/dist/ollama.js.map +1 -1
  26. package/dist/openai.cjs +2 -2
  27. package/dist/openai.cjs.map +1 -1
  28. package/dist/openai.d.cts +4 -8
  29. package/dist/openai.d.ts +4 -8
  30. package/dist/openai.js +2 -2
  31. package/dist/openai.js.map +1 -1
  32. package/dist/semantic-cache-F0psCRuz.d.cts +271 -0
  33. package/dist/semantic-cache-F0psCRuz.d.ts +271 -0
  34. package/dist/testing.cjs +42 -7
  35. package/dist/testing.cjs.map +1 -1
  36. package/dist/testing.d.cts +365 -5
  37. package/dist/testing.d.ts +365 -5
  38. package/dist/testing.js +42 -7
  39. package/dist/testing.js.map +1 -1
  40. package/dist/types-Co4BzMiH.d.cts +1373 -0
  41. package/dist/types-Co4BzMiH.d.ts +1373 -0
  42. package/package.json +8 -3
  43. package/dist/types-BKCdgKC-.d.cts +0 -300
  44. package/dist/types-BKCdgKC-.d.ts +0 -300
@@ -1,10 +1,10 @@
1
- import { AgentOrchestrator, OrchestratorOptions } from './index.cjs';
2
- import { A as ApprovalRequest, I as InputGuardrailData, O as OutputGuardrailData, M as Message, T as ToolCallGuardrailData, a as ToolCall, G as GuardrailResult, b as AgentLike, c as AgentRunner, R as RunOptions, d as GuardrailFn, e as GuardrailContext } from './types-BKCdgKC-.cjs';
1
+ import { o as ApprovalRequest, u as BreakpointModifications, I as InputGuardrailData, O as OutputGuardrailData, M as Message, T as ToolCallGuardrailData, a_ as ToolCall, ad as GuardrailResult, A as AgentLike, b as AgentRunner, R as RunOptions, v as BreakpointRequest, C as Checkpoint, V as DagExecutionContext, X as DagNodeStatus, aN as RerouteEvent, aS as Scratchpad, a1 as DebugEventType, L as CheckpointStore, aj as InMemoryCheckpointStore, W as DagNode, Z as DagPattern, D as DebugEvent, G as GuardrailFn, aa as GuardrailContext } from './types-Co4BzMiH.cjs';
2
+ import { w as MultiAgentOrchestrator, x as MultiAgentOrchestratorOptions, c as AgentOrchestrator, O as OrchestratorOptions, H as HealthMonitor, C as MultiplexedStreamChunk, D as DebugTimeline, X as ReflectionEvaluator } from './multi-agent-orchestrator-CxL8ycw_.cjs';
3
3
  import '@directive-run/core';
4
4
  import '@directive-run/core/plugins';
5
5
 
6
6
  /**
7
- * OpenAI Agents Testing Utilities
7
+ * Directive AI Testing Utilities
8
8
  *
9
9
  * Provides testing helpers for:
10
10
  * - Mock agent runners with configurable responses
@@ -14,7 +14,7 @@ import '@directive-run/core/plugins';
14
14
  *
15
15
  * @example
16
16
  * ```typescript
17
- * import { createMockAgentRunner, testGuardrail, createApprovalSimulator } from '@directive-run/ai';
17
+ * import { createMockAgentRunner, testGuardrail, createApprovalSimulator } from '@directive-run/ai/testing';
18
18
  *
19
19
  * describe('MyOrchestrator', () => {
20
20
  * it('should block PII in input', async () => {
@@ -341,5 +341,365 @@ declare function createTimeController(startTime?: number): {
341
341
  set(time: number): void;
342
342
  reset(): void;
343
343
  };
344
+ /** Options for test multi-agent orchestrator */
345
+ interface TestMultiAgentOrchestratorOptions extends Omit<MultiAgentOrchestratorOptions, "runner"> {
346
+ /** Mock responses keyed by agent ID — internally mapped to agent names for the mock runner */
347
+ mockResponses?: Record<string, MockAgentConfig>;
348
+ /** Default mock response for unmatched agents */
349
+ defaultMockResponse?: MockAgentConfig;
350
+ }
351
+ /** Test multi-agent orchestrator with additional testing utilities */
352
+ interface TestMultiAgentOrchestrator extends MultiAgentOrchestrator {
353
+ /** The mock runner */
354
+ mockRunner: MockAgentRunner;
355
+ /** Approval simulator */
356
+ approvalSimulator: ApprovalSimulator;
357
+ /** Get recorded agent calls */
358
+ getCalls(): RecordedCall[];
359
+ /** Get approval requests */
360
+ getApprovalRequests(): ApprovalRequest[];
361
+ /** Reset all state */
362
+ resetAll(): void;
363
+ }
364
+ /**
365
+ * Create a test multi-agent orchestrator with mocking and simulation built in.
366
+ *
367
+ * @example
368
+ * ```typescript
369
+ * const test = createTestMultiAgentOrchestrator({
370
+ * agents: {
371
+ * researcher: { agent: { name: 'researcher' } },
372
+ * writer: { agent: { name: 'writer' } },
373
+ * },
374
+ * mockResponses: {
375
+ * researcher: { output: 'Research results', totalTokens: 100 },
376
+ * writer: { output: 'Written article', totalTokens: 200 },
377
+ * },
378
+ * });
379
+ *
380
+ * const result = await test.runAgent('researcher', 'What is AI?');
381
+ * expect(result.output).toBe('Research results');
382
+ * expect(test.getCalls()).toHaveLength(1);
383
+ * ```
384
+ */
385
+ declare function createTestMultiAgentOrchestrator(options: TestMultiAgentOrchestratorOptions): TestMultiAgentOrchestrator;
386
+ /**
387
+ * Assert that a multi-agent orchestrator has specific state.
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * assertMultiAgentState(orchestrator, {
392
+ * agentStatus: { researcher: 'completed', writer: 'idle' },
393
+ * globalTokens: { min: 0, max: 1000 },
394
+ * pendingHandoffs: 0,
395
+ * });
396
+ * ```
397
+ */
398
+ declare function assertMultiAgentState(orchestrator: MultiAgentOrchestrator, expected: {
399
+ agentStatus?: Record<string, "idle" | "running" | "completed" | "error">;
400
+ totalTokens?: {
401
+ agentId?: string;
402
+ min?: number;
403
+ max?: number;
404
+ };
405
+ globalTokens?: {
406
+ min?: number;
407
+ max?: number;
408
+ };
409
+ pendingHandoffs?: number;
410
+ }): void;
411
+
412
+ /**
413
+ * Create a test DAG pattern from a simplified node spec.
414
+ *
415
+ * @example
416
+ * ```typescript
417
+ * const pattern = createTestDag({
418
+ * A: { agent: "researcher" },
419
+ * B: { agent: "writer", deps: ["A"] },
420
+ * C: { agent: "reviewer", deps: ["B"] },
421
+ * });
422
+ * ```
423
+ */
424
+ declare function createTestDag<T = unknown>(nodes: Record<string, Pick<DagNode, "agent" | "deps" | "when" | "transform" | "timeout" | "priority">>, merge?: (context: DagExecutionContext) => T | Promise<T>, options?: {
425
+ timeout?: number;
426
+ maxConcurrent?: number;
427
+ onNodeError?: "fail" | "skip-downstream" | "continue";
428
+ }): DagPattern<T>;
429
+ /**
430
+ * Assert that a DAG execution produced the expected node statuses.
431
+ *
432
+ * @example
433
+ * ```typescript
434
+ * assertDagExecution(context, {
435
+ * nodeStatuses: { A: "completed", B: "completed", C: "skipped" },
436
+ * completedNodes: ["A", "B"],
437
+ * skippedNodes: ["C"],
438
+ * });
439
+ * ```
440
+ */
441
+ declare function assertDagExecution(context: DagExecutionContext, expected: {
442
+ nodeStatuses?: Record<string, DagNodeStatus>;
443
+ completedNodes?: string[];
444
+ skippedNodes?: string[];
445
+ errorNodes?: string[];
446
+ outputContains?: Record<string, unknown>;
447
+ }): void;
448
+
449
+ /**
450
+ * Create a test debug timeline pre-populated with events.
451
+ *
452
+ * @example
453
+ * ```typescript
454
+ * const timeline = createTestTimeline([
455
+ * { type: "agent_start", agentId: "researcher", inputLength: 42 },
456
+ * { type: "agent_complete", agentId: "researcher", outputLength: 100, durationMs: 500, totalTokens: 200 },
457
+ * ]);
458
+ *
459
+ * expect(timeline.getEventsForAgent("researcher")).toHaveLength(2);
460
+ * ```
461
+ */
462
+ declare function createTestTimeline(events?: Array<Partial<DebugEvent> & {
463
+ type: DebugEventType;
464
+ }>, options?: {
465
+ maxEvents?: number;
466
+ }): DebugTimeline;
467
+ /**
468
+ * Assert that a debug timeline contains expected events.
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * assertTimelineEvents(timeline, {
473
+ * totalEvents: 5,
474
+ * eventTypes: ["agent_start", "guardrail_check", "agent_complete"],
475
+ * agentEvents: { researcher: 3, writer: 2 },
476
+ * hasType: "guardrail_check",
477
+ * });
478
+ * ```
479
+ */
480
+ declare function assertTimelineEvents(timeline: DebugTimeline, expected: {
481
+ totalEvents?: number;
482
+ minEvents?: number;
483
+ maxEvents?: number;
484
+ eventTypes?: DebugEventType[];
485
+ agentEvents?: Record<string, number>;
486
+ hasType?: DebugEventType;
487
+ doesNotHaveType?: DebugEventType;
488
+ }): void;
489
+
490
+ /**
491
+ * Create a runner that always fails, useful for testing self-healing.
492
+ *
493
+ * @example
494
+ * ```typescript
495
+ * const failing = createFailingRunner(new Error("Provider down"));
496
+ * const orchestrator = createAgentOrchestrator({
497
+ * runner: failing,
498
+ * selfHealing: { fallbackRunners: [backupRunner] },
499
+ * });
500
+ * ```
501
+ */
502
+ declare function createFailingRunner(error?: Error, options?: {
503
+ delay?: number;
504
+ failAfter?: number;
505
+ }): AgentRunner;
506
+ /**
507
+ * Assert that an agent was rerouted during execution.
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * const events: RerouteEvent[] = [];
512
+ * const orchestrator = createMultiAgentOrchestrator({
513
+ * selfHealing: {
514
+ * onReroute: (event) => events.push(event),
515
+ * },
516
+ * });
517
+ *
518
+ * // ... trigger reroute ...
519
+ * assertRerouted(events, {
520
+ * fromAgent: "primary",
521
+ * toAgent: "backup",
522
+ * reason: /circuit breaker/i,
523
+ * });
524
+ * ```
525
+ */
526
+ declare function assertRerouted(events: RerouteEvent[], expected: {
527
+ fromAgent?: string;
528
+ toAgent?: string;
529
+ reason?: string | RegExp;
530
+ minReroutes?: number;
531
+ }): void;
532
+ /**
533
+ * Assert the health state of an agent in the health monitor.
534
+ *
535
+ * @example
536
+ * ```typescript
537
+ * assertAgentHealth(monitor, "researcher", {
538
+ * minScore: 70,
539
+ * circuitState: "CLOSED",
540
+ * });
541
+ * ```
542
+ */
543
+ declare function assertAgentHealth(monitor: HealthMonitor, agentId: string, expected: {
544
+ minScore?: number;
545
+ maxScore?: number;
546
+ circuitState?: "CLOSED" | "OPEN" | "HALF_OPEN";
547
+ minSuccessRate?: number;
548
+ }): void;
549
+ /**
550
+ * Create a test checkpoint store (wraps InMemoryCheckpointStore with assertion helpers).
551
+ *
552
+ * @example
553
+ * ```typescript
554
+ * const store = createTestCheckpointStore();
555
+ * const orchestrator = createAgentOrchestrator({ runner, checkpointStore: store });
556
+ * const cp = await orchestrator.checkpoint();
557
+ * expect(store.saved).toHaveLength(1);
558
+ * ```
559
+ */
560
+ declare function createTestCheckpointStore(maxCheckpoints?: number): CheckpointStore & {
561
+ saved: Checkpoint[];
562
+ inner: InMemoryCheckpointStore;
563
+ /** Get the most recently saved checkpoint */
564
+ getLatest: () => Checkpoint | undefined;
565
+ };
566
+ /**
567
+ * Assert that a checkpoint has expected properties.
568
+ */
569
+ declare function assertCheckpoint(checkpoint: Checkpoint, expected: {
570
+ orchestratorType?: "single" | "multi";
571
+ hasTimeline?: boolean;
572
+ hasMemory?: boolean;
573
+ hasSystemExport?: boolean;
574
+ label?: string;
575
+ }): void;
576
+ /** Options for the breakpoint simulator */
577
+ interface BreakpointSimulatorOptions {
578
+ /** Auto-resume after this delay (ms). Default: 0 (immediate) */
579
+ autoResumeDelay?: number;
580
+ /** Modifications to apply on resume */
581
+ modifications?: BreakpointModifications;
582
+ /** If true, cancel instead of resume */
583
+ cancel?: boolean;
584
+ /** Cancel reason */
585
+ cancelReason?: string;
586
+ }
587
+ /**
588
+ * Create a breakpoint simulator that auto-resolves breakpoints.
589
+ *
590
+ * @example
591
+ * ```typescript
592
+ * const simulator = createBreakpointSimulator({ autoResumeDelay: 10 });
593
+ * const orchestrator = createAgentOrchestrator({
594
+ * runner,
595
+ * breakpoints: [{ type: "pre_agent_run" }],
596
+ * onBreakpoint: simulator.handler,
597
+ * });
598
+ * // Run agent — breakpoint fires and auto-resumes
599
+ * await orchestrator.run("test input");
600
+ * expect(simulator.hits).toHaveLength(1);
601
+ * ```
602
+ */
603
+ /** Minimal interface for breakpoint-capable orchestrators */
604
+ interface BreakpointCapable {
605
+ resumeBreakpoint(id: string, modifications?: BreakpointModifications): void;
606
+ cancelBreakpoint(id: string, reason?: string): void;
607
+ }
608
+ declare function createBreakpointSimulator(options?: BreakpointSimulatorOptions): {
609
+ handler: (request: BreakpointRequest) => void;
610
+ hits: BreakpointRequest[];
611
+ attachTo: (orchestrator: BreakpointCapable) => void;
612
+ };
613
+ /**
614
+ * Assert that a breakpoint was hit with expected properties.
615
+ */
616
+ declare function assertBreakpointHit(hits: BreakpointRequest[], expected: {
617
+ type?: string;
618
+ agentId?: string;
619
+ count?: number;
620
+ }): void;
621
+ /**
622
+ * Create a mock SafeParseable schema for testing.
623
+ *
624
+ * @example
625
+ * ```typescript
626
+ * const schema = createMockSchema((data) => typeof data === "object" && data !== null);
627
+ * const orchestrator = createAgentOrchestrator({
628
+ * runner,
629
+ * outputSchema: schema,
630
+ * });
631
+ * ```
632
+ */
633
+ declare function createMockSchema<T>(validate: (data: unknown) => boolean, description?: string): {
634
+ safeParse: (data: unknown) => {
635
+ success: boolean;
636
+ data?: T;
637
+ error?: {
638
+ message: string;
639
+ };
640
+ };
641
+ description?: string;
642
+ };
643
+ /**
644
+ * Collect all chunks from a multiplexed stream into an array.
645
+ *
646
+ * @example
647
+ * ```typescript
648
+ * const { stream } = orchestrator.runParallelStream(["a", "b"], "input", merge);
649
+ * const chunks = await collectMultiplexedStream(stream);
650
+ * expect(chunks.length).toBeGreaterThan(0);
651
+ * ```
652
+ */
653
+ declare function collectMultiplexedStream(stream: AsyncIterable<MultiplexedStreamChunk>): Promise<MultiplexedStreamChunk[]>;
654
+ /**
655
+ * Assert properties of collected multiplexed stream chunks.
656
+ */
657
+ declare function assertMultiplexedStream(chunks: MultiplexedStreamChunk[], expected: {
658
+ agentIds?: string[];
659
+ minChunks?: number;
660
+ hasDone?: boolean;
661
+ hasErrors?: boolean;
662
+ }): void;
663
+ /**
664
+ * Create a test reflection evaluator that passes after N iterations.
665
+ *
666
+ * @example
667
+ * ```typescript
668
+ * const evaluator = createTestReflectionEvaluator({ passAfter: 2 });
669
+ * const reflective = withReflection(runner, { evaluate: evaluator });
670
+ * ```
671
+ */
672
+ declare function createTestReflectionEvaluator(options?: {
673
+ /** Pass after this many evaluations (1 = pass on first try). Default: 1 */
674
+ passAfter?: number;
675
+ /** Feedback to provide on failure */
676
+ feedback?: string;
677
+ /** Score to assign (0-1) */
678
+ score?: number;
679
+ }): ReflectionEvaluator;
680
+ /**
681
+ * Assert that a scratchpad contains expected values.
682
+ *
683
+ * @example
684
+ * ```typescript
685
+ * assertScratchpadState(orchestrator.scratchpad!, {
686
+ * "plan.status": "complete",
687
+ * "research.results": expect.any(Array),
688
+ * });
689
+ * ```
690
+ */
691
+ declare function assertScratchpadState(scratchpad: Scratchpad, expected: Record<string, unknown>): void;
692
+ /**
693
+ * Assert that derived values match expected values.
694
+ *
695
+ * @example
696
+ * ```typescript
697
+ * assertDerivedValues(orchestrator, {
698
+ * totalRuns: 3,
699
+ * allComplete: true,
700
+ * });
701
+ * ```
702
+ */
703
+ declare function assertDerivedValues(orchestrator: MultiAgentOrchestrator, expected: Record<string, unknown>): void;
344
704
 
345
- export { type ApprovalSimulator, type ApprovalSimulatorOptions, type ConstraintSnapshot, type GuardrailTestInput, type GuardrailTestResult, type MockAgentConfig, type MockAgentRunner, type MockAgentRunnerOptions, type RecordedCall, type TestOrchestrator, type TestOrchestratorOptions, assertOrchestratorState, createApprovalSimulator, createConstraintRecorder, createMockAgentRunner, createTestOrchestrator, createTimeController, testGuardrail, testGuardrailBatch };
705
+ export { type ApprovalSimulator, type ApprovalSimulatorOptions, type BreakpointCapable, type BreakpointSimulatorOptions, type ConstraintSnapshot, type GuardrailTestInput, type GuardrailTestResult, type MockAgentConfig, type MockAgentRunner, type MockAgentRunnerOptions, type RecordedCall, type TestMultiAgentOrchestrator, type TestMultiAgentOrchestratorOptions, type TestOrchestrator, type TestOrchestratorOptions, assertAgentHealth, assertBreakpointHit, assertCheckpoint, assertDagExecution, assertDerivedValues, assertMultiAgentState, assertMultiplexedStream, assertOrchestratorState, assertRerouted, assertScratchpadState, assertTimelineEvents, collectMultiplexedStream, createApprovalSimulator, createBreakpointSimulator, createConstraintRecorder, createFailingRunner, createMockAgentRunner, createMockSchema, createTestCheckpointStore, createTestDag, createTestMultiAgentOrchestrator, createTestOrchestrator, createTestReflectionEvaluator, createTestTimeline, createTimeController, testGuardrail, testGuardrailBatch };