@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
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/debug-timeline.ts","../src/health-monitor.ts"],"names":["KNOWN_EVENT_TYPES","BLOCKED_IMPORT_KEYS","createDebugTimeline","options","maxEvents","goToSnapshot","events","nextId","listeners","event","fullEvent","overflow","listener","err","agentId","e","type","snapshotId","startMs","endMs","cutoffId","sliceEnd","i","json","parsed","key","data","validated","evt","createDebugTimelinePlugin","timeline","getSnapshotId","resolverStartTimes","id","active","resolver","req","startTime","_req","error","errorMessage","DEFAULT_WEIGHTS","createHealthMonitor","config","windowMs","maxNormalLatencyMs","maxEventsPerAgent","weights","value","weightSum","circuitStates","generation","cachedAll","cachedGen","getAgentEvents","agentEvents","pruneAndCap","now","cutoff","firstValid","excessFromCap","computeScore","successRate","avgLatency","s","normalizedLatency","state","circuitScore","raw","buildMetrics","successes","failures","avgLatencyMs","lastErrors","latencyMs","result"],"mappings":"aAgBA,IAAMA,CAAAA,CAAiC,IAAI,GAAA,CAAI,CAC7C,cACA,gBAAA,CACA,aAAA,CACA,aAAA,CACA,iBAAA,CACA,qBAAA,CACA,gBAAA,CACA,mBAAA,CACA,gBAAA,CACA,mBACA,mBAAA,CACA,eAAA,CACA,kBAAA,CACA,eAAA,CACA,kBAAA,CACA,iBAAA,CACA,gBAAA,CACA,oBAAA,CACA,oBACA,mBAAA,CACA,sBAAA,CACA,YAAA,CACA,aAAA,CACA,iBACA,cAAA,CACA,SAAA,CACA,iBAAA,CACA,oBAAA,CACA,aACA,eAAA,CACA,YAAA,CACA,eAAA,CACA,WACF,CAAC,CAAA,CAqDKC,CAAAA,CAAsB,IAAI,IAAI,CAClC,WAAA,CACA,aAAA,CACA,WAAA,CACA,UAAA,CACA,SAAA,CACA,gBACF,CAAC,EAoBM,SAASC,CAAAA,CACdC,CAAAA,CAAgC,EAAC,CAClB,CACf,IAAMC,CAAAA,CAAYD,EAAQ,SAAA,EAAa,GAAA,CACjCE,CAAAA,CAAeF,CAAAA,CAAQ,aAG7B,GAAI,CAAC,MAAA,CAAO,QAAA,CAASC,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A,GAAeE,CAAAA,EAAaD,CAAAA,CAC9B,OAAOA,EAGT,IAAMuB,CAAAA,CAA6C,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,CACrE,IAAA,IAAW7D,CAAAA,IAAWR,EAAO,IAAA,EAAK,CAChCqE,CAAAA,CAAO7D,CAAO,EAAIuD,CAAAA,CAAavD,CAAO,CAAA,CAGxC,OAAAsC,EAAYuB,CAAAA,CACZtB,CAAAA,CAAYF,CAAAA,CAELwB,CACT,CAAA,CAEA,cAAA,CAAe7D,CAAAA,CAAyB,CACtC,OAAO+C,CAAAA,CAAa/C,CAAO,CAC7B,CAAA,CAEA,mBAAmBA,CAAAA,CAAiBoD,CAAAA,CAAiC,CACnEhB,CAAAA,CAAc,IAAIpC,CAAAA,CAASoD,CAAK,CAAA,CAChCf,CAAAA,GACF,CAAA,CAEA,KAAA,EAAc,CACZ7C,CAAAA,CAAO,OAAM,CACb4C,CAAAA,CAAc,KAAA,EAAM,CACpBC,IACAC,CAAAA,CAAY,IAAA,CACZC,CAAAA,CAAY,GACd,CACF,CACF","file":"chunk-WOFIBIPW.cjs","sourcesContent":["/**\n * Debug Timeline — AI-specific event log with snapshot correlation.\n *\n * Records agent lifecycle events (start, complete, error, guardrail checks,\n * approvals, handoffs, patterns) and correlates them with core time-travel\n * snapshots for visual timeline UIs and fork-and-replay debugging.\n *\n * Zero-cost when debug=false — the timeline is simply `null`.\n *\n * @module\n */\n\nimport type { Plugin } from \"@directive-run/core\";\nimport type { DebugEvent, DebugEventType } from \"./types.js\";\n\n/** A12: Known event types for import validation */\nconst KNOWN_EVENT_TYPES: Set<string> = new Set([\n \"agent_start\",\n \"agent_complete\",\n \"agent_error\",\n \"agent_retry\",\n \"guardrail_check\",\n \"constraint_evaluate\",\n \"resolver_start\",\n \"resolver_complete\",\n \"resolver_error\",\n \"approval_request\",\n \"approval_response\",\n \"handoff_start\",\n \"handoff_complete\",\n \"pattern_start\",\n \"pattern_complete\",\n \"dag_node_update\",\n \"breakpoint_hit\",\n \"breakpoint_resumed\",\n \"derivation_update\",\n \"scratchpad_update\",\n \"reflection_iteration\",\n \"race_start\",\n \"race_winner\",\n \"race_cancelled\",\n \"debate_round\",\n \"reroute\",\n \"checkpoint_save\",\n \"checkpoint_restore\",\n \"task_start\",\n \"task_complete\",\n \"task_error\",\n \"task_progress\",\n \"goal_step\",\n]);\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Callback fired when a new event is recorded */\nexport type DebugTimelineListener = (event: DebugEvent) => void;\n\n/** Debug timeline instance */\nexport interface DebugTimeline {\n /** Record a new event (id is auto-assigned) */\n record(event: Omit<DebugEvent, \"id\"> & Record<string, unknown>): DebugEvent;\n /** Get all events in order */\n getEvents(): DebugEvent[];\n /** Get events for a specific agent */\n getEventsForAgent(agentId: string): DebugEvent[];\n /** Get events by type with type narrowing */\n getEventsByType<T extends DebugEventType>(\n type: T,\n ): Extract<DebugEvent, { type: T }>[];\n /** Get events at a specific snapshot */\n getEventsAtSnapshot(snapshotId: number): DebugEvent[];\n /** Get events in a time range */\n getEventsInRange(startMs: number, endMs: number): DebugEvent[];\n /** Fork from a snapshot — truncates events after it and calls goTo */\n forkFrom(snapshotId: number): void;\n /** Export timeline as JSON */\n export(): string;\n /** Import timeline from JSON */\n import(json: string): void;\n /** Clear all events */\n clear(): void;\n /** Subscribe to new events. Returns unsubscribe function. */\n subscribe(listener: DebugTimelineListener): () => void;\n /** Current number of events */\n readonly length: number;\n}\n\n/** Options for creating a debug timeline */\nexport interface DebugTimelineOptions {\n /** Maximum events before eviction. @default 2000 */\n maxEvents?: number;\n /** Callback to get current snapshot ID from the system */\n getSnapshotId?: () => number | null;\n /** Callback to navigate to a snapshot (for forkFrom) */\n goToSnapshot?: (snapshotId: number) => void;\n}\n\n// ============================================================================\n// Implementation\n// ============================================================================\n\nconst BLOCKED_IMPORT_KEYS = new Set([\n \"__proto__\",\n \"constructor\",\n \"prototype\",\n \"toString\",\n \"valueOf\",\n \"hasOwnProperty\",\n]);\n\n/**\n * Create a debug timeline for recording and correlating AI events.\n *\n * @example\n * ```typescript\n * const timeline = createDebugTimeline({ maxEvents: 1000 });\n *\n * timeline.record({\n * type: \"agent_start\",\n * timestamp: Date.now(),\n * agentId: \"researcher\",\n * snapshotId: null,\n * inputLength: 42,\n * });\n *\n * const agentEvents = timeline.getEventsForAgent(\"researcher\");\n * ```\n */\nexport function createDebugTimeline(\n options: DebugTimelineOptions = {},\n): DebugTimeline {\n const maxEvents = options.maxEvents ?? 2000;\n const goToSnapshot = options.goToSnapshot;\n\n // Validate config\n if (!Number.isFinite(maxEvents) || maxEvents < 1) {\n throw new Error(\"[Directive DebugTimeline] maxEvents must be >= 1\");\n }\n\n let events: DebugEvent[] = [];\n let nextId = 0;\n const listeners = new Set<DebugTimelineListener>();\n\n const timeline: DebugTimeline = {\n record(event: Omit<DebugEvent, \"id\">): DebugEvent {\n const fullEvent = { ...event, id: nextId++ } as DebugEvent;\n events.push(fullEvent);\n\n // Batch eviction — single splice instead of per-element shift\n const overflow = events.length - maxEvents;\n if (overflow > 0) {\n events.splice(0, overflow);\n }\n\n // Notify listeners\n for (const listener of listeners) {\n try {\n listener(fullEvent);\n } catch (err) {\n // A6: Log listener errors in dev mode instead of swallowing silently\n if (\n typeof process !== \"undefined\" &&\n process.env?.NODE_ENV !== \"production\"\n ) {\n console.error(\n \"[Directive DebugTimeline] Listener threw:\",\n err instanceof Error ? err.message : err,\n );\n }\n }\n }\n\n return fullEvent;\n },\n\n getEvents(): DebugEvent[] {\n return [...events];\n },\n\n getEventsForAgent(agentId: string): DebugEvent[] {\n return events.filter((e) => e.agentId === agentId);\n },\n\n getEventsByType<T extends DebugEventType>(\n type: T,\n ): Extract<DebugEvent, { type: T }>[] {\n return events.filter((e) => e.type === type) as Extract<\n DebugEvent,\n { type: T }\n >[];\n },\n\n getEventsAtSnapshot(snapshotId: number): DebugEvent[] {\n return events.filter((e) => e.snapshotId === snapshotId);\n },\n\n getEventsInRange(startMs: number, endMs: number): DebugEvent[] {\n return events.filter(\n (e) => e.timestamp >= startMs && e.timestamp <= endMs,\n );\n },\n\n forkFrom(snapshotId: number): void {\n // A8: Single reverse scan instead of two .filter() passes\n let cutoffId = -1;\n for (let i = events.length - 1; i >= 0; i--) {\n if (\n events[i]!.snapshotId !== null &&\n events[i]!.snapshotId! <= snapshotId\n ) {\n cutoffId = events[i]!.id;\n break;\n }\n }\n\n if (cutoffId >= 0) {\n // Find the index to slice at (events are monotonic by id)\n let sliceEnd = events.length;\n for (let i = events.length - 1; i >= 0; i--) {\n if (events[i]!.id <= cutoffId) {\n sliceEnd = i + 1;\n break;\n }\n }\n events = events.slice(0, sliceEnd);\n } else {\n // No matching events — clear all\n events = [];\n }\n\n // Navigate the system to the snapshot\n if (goToSnapshot) {\n goToSnapshot(snapshotId);\n }\n },\n\n export(): string {\n return JSON.stringify({ version: 1, events, nextId });\n },\n\n import(json: string): void {\n let parsed: unknown;\n try {\n parsed = JSON.parse(json);\n } catch {\n throw new Error(\"[Directive DebugTimeline] Invalid JSON\");\n }\n\n if (!parsed || typeof parsed !== \"object\") {\n throw new Error(\"[Directive DebugTimeline] Invalid timeline data\");\n }\n\n // Prototype pollution defense\n for (const key of Object.keys(parsed)) {\n if (BLOCKED_IMPORT_KEYS.has(key)) {\n throw new Error(\n `[Directive DebugTimeline] Blocked key in import: ${key}`,\n );\n }\n }\n\n const data = parsed as {\n version?: number;\n events?: unknown[];\n nextId?: number;\n };\n\n if (!Array.isArray(data.events)) {\n throw new Error(\"[Directive DebugTimeline] Missing events array\");\n }\n\n // Validate each event has required fields\n const validated: DebugEvent[] = [];\n for (const evt of data.events) {\n if (!evt || typeof evt !== \"object\") {\n continue;\n }\n\n // Prototype pollution defense on event objects\n for (const key of Object.keys(evt)) {\n if (BLOCKED_IMPORT_KEYS.has(key)) {\n throw new Error(\n `[Directive DebugTimeline] Blocked key in event: ${key}`,\n );\n }\n }\n\n const e = evt as Record<string, unknown>;\n // A12: Also validate that event type is a known DebugEventType\n if (\n typeof e.id === \"number\" &&\n typeof e.type === \"string\" &&\n KNOWN_EVENT_TYPES.has(e.type) &&\n typeof e.timestamp === \"number\"\n ) {\n validated.push(evt as DebugEvent);\n }\n }\n\n // Enforce maxEvents cap on imported data\n events =\n validated.length > maxEvents ? validated.slice(-maxEvents) : validated;\n nextId = typeof data.nextId === \"number\" ? data.nextId : validated.length;\n },\n\n clear(): void {\n events = [];\n nextId = 0;\n },\n\n subscribe(listener: DebugTimelineListener): () => void {\n listeners.add(listener);\n\n return () => {\n listeners.delete(listener);\n };\n },\n\n get length(): number {\n return events.length;\n },\n };\n\n return timeline;\n}\n\n// ============================================================================\n// Plugin Factory\n// ============================================================================\n\n/**\n * Create a Directive plugin that bridges core constraint/resolver events\n * to the debug timeline.\n *\n * @example\n * ```typescript\n * const timeline = createDebugTimeline();\n * const plugin = createDebugTimelinePlugin(timeline, () => system.history?.currentIndex ?? null);\n * ```\n */\nexport function createDebugTimelinePlugin(\n timeline: DebugTimeline,\n getSnapshotId: () => number | null,\n): Plugin {\n const resolverStartTimes = new Map<string, number>();\n\n return {\n name: \"directive-ai-debug-timeline\",\n\n onConstraintEvaluate(id: string, active: boolean) {\n timeline.record({\n type: \"constraint_evaluate\",\n timestamp: Date.now(),\n snapshotId: getSnapshotId(),\n constraintId: id,\n fired: active,\n });\n },\n\n onResolverStart(resolver: string, req) {\n resolverStartTimes.set(resolver, Date.now());\n timeline.record({\n type: \"resolver_start\",\n timestamp: Date.now(),\n snapshotId: getSnapshotId(),\n resolverId: resolver,\n requirementType: req.requirement.type,\n });\n },\n\n onResolverComplete(resolver: string) {\n const startTime = resolverStartTimes.get(resolver);\n resolverStartTimes.delete(resolver);\n timeline.record({\n type: \"resolver_complete\",\n timestamp: Date.now(),\n snapshotId: getSnapshotId(),\n resolverId: resolver,\n durationMs: startTime ? Date.now() - startTime : 0,\n });\n },\n\n onResolverError(resolver: string, _req, error) {\n const startTime = resolverStartTimes.get(resolver);\n resolverStartTimes.delete(resolver);\n const errorMessage =\n error instanceof Error ? error.message : String(error);\n timeline.record({\n type: \"resolver_error\",\n timestamp: Date.now(),\n snapshotId: getSnapshotId(),\n resolverId: resolver,\n errorMessage,\n durationMs: startTime ? Date.now() - startTime : 0,\n });\n },\n };\n}\n","/**\n * Health Monitor — tracks per-agent health metrics for self-healing networks.\n *\n * Pure computation module with zero Directive dependency.\n * Maintains a rolling window of success/failure events and computes a health\n * score from 0-100 based on configurable weights.\n *\n * @module\n */\n\nimport type { HealthMonitorConfig } from \"./types.js\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Circuit state values */\nexport type HealthCircuitState = \"CLOSED\" | \"OPEN\" | \"HALF_OPEN\";\n\n/** Per-agent health metrics */\nexport interface AgentHealthMetrics {\n agentId: string;\n circuitState: HealthCircuitState;\n successRate: number;\n avgLatencyMs: number;\n recentFailures: number;\n recentSuccesses: number;\n healthScore: number;\n /** Last N error messages (most recent last) */\n lastErrors: string[];\n}\n\n/** Internal event record */\ninterface HealthEvent {\n success: boolean;\n latencyMs: number;\n timestamp: number;\n errorMessage?: string;\n}\n\n/** Health monitor instance */\nexport interface HealthMonitor {\n recordSuccess(agentId: string, latencyMs: number): void;\n recordFailure(agentId: string, latencyMs: number, error?: Error): void;\n getMetrics(agentId: string): AgentHealthMetrics;\n getAllMetrics(): Record<string, AgentHealthMetrics>;\n /** Returns a 0-100 health score. Returns 50 (neutral) when no data is available for the agent. */\n getHealthScore(agentId: string): number;\n updateCircuitState(agentId: string, state: HealthCircuitState): void;\n /** Reset all metrics. Useful for testing. */\n reset(): void;\n}\n\n// ============================================================================\n// Implementation\n// ============================================================================\n\nconst DEFAULT_WINDOW_MS = 60_000;\nconst DEFAULT_MAX_NORMAL_LATENCY_MS = 5_000;\nconst DEFAULT_MAX_EVENTS_PER_AGENT = 1_000;\nconst DEFAULT_MAX_STORED_ERRORS = 5;\nconst DEFAULT_WEIGHTS = {\n successRate: 0.5,\n latency: 0.3,\n circuitState: 0.2,\n};\n\n/**\n * Create a health monitor that tracks per-agent metrics.\n *\n * @example\n * ```typescript\n * const monitor = createHealthMonitor({ windowMs: 30000 });\n *\n * monitor.recordSuccess(\"agent-a\", 120);\n * monitor.recordFailure(\"agent-a\", 5000, new Error(\"timeout\"));\n *\n * const score = monitor.getHealthScore(\"agent-a\");\n * console.log(score); // 0-100\n * ```\n */\nexport function createHealthMonitor(\n config: HealthMonitorConfig = {},\n): HealthMonitor {\n const windowMs = config.windowMs ?? DEFAULT_WINDOW_MS;\n const maxNormalLatencyMs =\n config.maxNormalLatencyMs ?? DEFAULT_MAX_NORMAL_LATENCY_MS;\n const maxEventsPerAgent =\n config.maxEventsPerAgent ?? DEFAULT_MAX_EVENTS_PER_AGENT;\n const weights = {\n successRate: config.weights?.successRate ?? DEFAULT_WEIGHTS.successRate,\n latency: config.weights?.latency ?? DEFAULT_WEIGHTS.latency,\n circuitState: config.weights?.circuitState ?? DEFAULT_WEIGHTS.circuitState,\n };\n\n // Validate config\n if (!Number.isFinite(windowMs) || windowMs <= 0) {\n throw new Error(\n \"[Directive HealthMonitor] windowMs must be a positive number\",\n );\n }\n if (!Number.isFinite(maxNormalLatencyMs) || maxNormalLatencyMs <= 0) {\n throw new Error(\n \"[Directive HealthMonitor] maxNormalLatencyMs must be a positive number\",\n );\n }\n if (!Number.isFinite(maxEventsPerAgent) || maxEventsPerAgent < 1) {\n throw new Error(\"[Directive HealthMonitor] maxEventsPerAgent must be >= 1\");\n }\n\n // A14: Validate individual weight bounds\n for (const [key, value] of Object.entries(weights)) {\n if (value < 0 || value > 1) {\n throw new Error(\n `[Directive HealthMonitor] weight \"${key}\" must be between 0 and 1 (got ${value})`,\n );\n }\n }\n\n // Validate weights sum approximately to 1.0\n const weightSum =\n weights.successRate + weights.latency + weights.circuitState;\n if (Math.abs(weightSum - 1.0) > 0.01) {\n throw new Error(\n `[Directive HealthMonitor] weights must sum to ~1.0 (tolerance: ±0.01, got ${weightSum.toFixed(4)})`,\n );\n }\n\n const events = new Map<string, HealthEvent[]>();\n const circuitStates = new Map<string, HealthCircuitState>();\n\n // L4: Generation counter for getAllMetrics caching\n let generation = 0;\n let cachedAll: Record<string, AgentHealthMetrics> | null = null;\n let cachedGen = -1;\n\n function getAgentEvents(agentId: string): HealthEvent[] {\n let agentEvents = events.get(agentId);\n if (!agentEvents) {\n agentEvents = [];\n events.set(agentId, agentEvents);\n }\n\n return agentEvents;\n }\n\n function pruneAndCap(agentEvents: HealthEvent[], now: number): void {\n // Time-based pruning: find first event within the window\n const cutoff = now - windowMs;\n let firstValid = 0;\n while (\n firstValid < agentEvents.length &&\n agentEvents[firstValid]!.timestamp < cutoff\n ) {\n firstValid++;\n }\n\n // Cap-based pruning: ensure we don't exceed maxEventsPerAgent\n const excessFromCap = agentEvents.length - firstValid - maxEventsPerAgent;\n if (excessFromCap > 0) {\n firstValid += excessFromCap;\n }\n\n // Batch remove all expired/excess events in one operation\n if (firstValid > 0) {\n agentEvents.splice(0, firstValid);\n }\n }\n\n function computeScore(agentId: string): number {\n const agentEvents = events.get(agentId);\n if (!agentEvents || agentEvents.length === 0) {\n return 50; // No data = neutral\n }\n\n const now = Date.now();\n pruneAndCap(agentEvents, now);\n\n if (agentEvents.length === 0) {\n return 50;\n }\n\n const successes = agentEvents.filter((e) => e.success).length;\n const successRate = successes / agentEvents.length;\n\n const avgLatency =\n agentEvents.reduce((s, e) => s + e.latencyMs, 0) / agentEvents.length;\n const normalizedLatency = Math.min(avgLatency / maxNormalLatencyMs, 1);\n\n const state = circuitStates.get(agentId) ?? \"CLOSED\";\n const circuitScore =\n state === \"CLOSED\" ? 1 : state === \"HALF_OPEN\" ? 0.5 : 0;\n\n const raw =\n successRate * weights.successRate +\n (1 - normalizedLatency) * weights.latency +\n circuitScore * weights.circuitState;\n\n return Math.round(raw * 100);\n }\n\n function buildMetrics(agentId: string): AgentHealthMetrics {\n const agentEvents = getAgentEvents(agentId);\n const now = Date.now();\n pruneAndCap(agentEvents, now);\n\n const successes = agentEvents.filter((e) => e.success).length;\n const failures = agentEvents.length - successes;\n const successRate =\n agentEvents.length > 0 ? successes / agentEvents.length : 0;\n const avgLatencyMs =\n agentEvents.length > 0\n ? agentEvents.reduce((s, e) => s + e.latencyMs, 0) / agentEvents.length\n : 0;\n\n // Collect last N error messages\n const lastErrors: string[] = [];\n for (\n let i = agentEvents.length - 1;\n i >= 0 && lastErrors.length < DEFAULT_MAX_STORED_ERRORS;\n i--\n ) {\n if (agentEvents[i]!.errorMessage) {\n lastErrors.unshift(agentEvents[i]!.errorMessage!);\n }\n }\n\n return {\n agentId,\n circuitState: circuitStates.get(agentId) ?? \"CLOSED\",\n successRate,\n avgLatencyMs,\n recentFailures: failures,\n recentSuccesses: successes,\n healthScore: computeScore(agentId),\n lastErrors,\n };\n }\n\n return {\n recordSuccess(agentId: string, latencyMs: number): void {\n const agentEvents = getAgentEvents(agentId);\n agentEvents.push({ success: true, latencyMs, timestamp: Date.now() });\n // A9: Prune on write path to prevent unbounded growth between reads\n pruneAndCap(agentEvents, Date.now());\n generation++;\n },\n\n recordFailure(agentId: string, latencyMs: number, error?: Error): void {\n const agentEvents = getAgentEvents(agentId);\n agentEvents.push({\n success: false,\n latencyMs,\n timestamp: Date.now(),\n errorMessage: error?.message,\n });\n // A9: Prune on write path to prevent unbounded growth between reads\n pruneAndCap(agentEvents, Date.now());\n generation++;\n },\n\n getMetrics(agentId: string): AgentHealthMetrics {\n return buildMetrics(agentId);\n },\n\n getAllMetrics(): Record<string, AgentHealthMetrics> {\n // L4: Return cached result when no writes have occurred\n if (generation === cachedGen && cachedAll) {\n return cachedAll;\n }\n\n const result: Record<string, AgentHealthMetrics> = Object.create(null);\n for (const agentId of events.keys()) {\n result[agentId] = buildMetrics(agentId);\n }\n\n cachedAll = result;\n cachedGen = generation;\n\n return result;\n },\n\n getHealthScore(agentId: string): number {\n return computeScore(agentId);\n },\n\n updateCircuitState(agentId: string, state: HealthCircuitState): void {\n circuitStates.set(agentId, state);\n generation++;\n },\n\n reset(): void {\n events.clear();\n circuitStates.clear();\n generation++;\n cachedAll = null;\n cachedGen = -1;\n },\n };\n}\n"]}
@@ -0,0 +1,37 @@
1
+ 'use strict';var chunk3WO4MWJM_cjs=require('./chunk-3WO4MWJM.cjs');var M=class{constructor(n){this.max=n;if(n<1)throw new Error(`[Directive Evals] concurrency must be >= 1, got ${n}`)}queue=[];active=0;async acquire(n){if(this.active<this.max){this.active++;return}return new Promise((r,s)=>{let a={resolve:r,reject:s};this.queue.push(a),n&&n.addEventListener("abort",()=>{let t=this.queue.indexOf(a);t!==-1&&(this.queue.splice(t,1),s(new Error("Semaphore acquire aborted")));},{once:true});})}release(){if(this.active<=0)return;this.active--;let n=this.queue.shift();n&&(this.active++,n.resolve());}};function N(e,n){return typeof n=="function"?{name:e,fn:n,threshold:.5,weight:1}:{...n,name:e,threshold:n.threshold??.5,weight:n.weight??1}}function P(e,n){let r=0,s=0;for(let[a,t]of Object.entries(e)){let u=n[a]?.weight??1,i=Number.isFinite(t.score)?t.score:0;r+=i*u,s+=u;}return s===0?0:r/s}function T(e,n){let r=0,s=0;for(let[a,t]of Object.entries(e)){let u=n[a]?.weight??1,i=Number.isFinite(t)?t:0;r+=i*u,s+=u;}return s===0?0:r/s}var k={pii:[/\b\d{3}-\d{2}-\d{4}\b/,/\b(?:4\d{3}|5[1-5]\d{2}|6011)\d{12}\b/,/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/],violence:[/\b(kill|murder|attack|bomb|weapon|shoot|stab)\b/i],self_harm:[/\b(suicide|self[- ]harm|cut myself)\b/i],illegal:[/\b(hack into|break into|steal|counterfeit)\b/i]};function _(e){return {name:"cost",fn:n=>{let r=Date.now(),s=n.result.totalTokens,a=s/e.maxTokensPerRun,t;return a<=.5?t=1:a>=2?t=0:t=1-(a-.5)/1.5,{score:t,passed:s<=e.maxTokensPerRun,reason:`${s} tokens (budget: ${e.maxTokensPerRun})`,durationMs:Date.now()-r}},threshold:.5,weight:1}}function J(e){return {name:"latency",fn:n=>{let r=Date.now(),s=n.runDurationMs,a=s/e.maxMs,t;return a<=.5?t=1:a>=2?t=0:t=1-(a-.5)/1.5,{score:t,passed:s<=e.maxMs,reason:`${Math.round(s)}ms (max: ${e.maxMs}ms)`,durationMs:Date.now()-r}},threshold:.5,weight:1}}function F(e){if(e.minLength!==void 0&&e.maxLength!==void 0&&e.minLength>e.maxLength)throw new Error("[Directive Evals] evalOutputLength: minLength must be <= maxLength");return {name:"outputLength",fn:n=>{let r=Date.now(),a=String(n.result.output).length,t=e.minLength??0,o=e.maxLength??Number.POSITIVE_INFINITY,u=a>=t&&a<=o,i;return u?i=1:a<t?i=t>0?Math.max(0,a/t):0:i=o>0&&o!==Number.POSITIVE_INFINITY?Math.max(0,1-(a-o)/o):0,{score:i,passed:u,reason:`${a} chars (range: ${t}-${o===Number.POSITIVE_INFINITY?"\u221E":o})`,durationMs:Date.now()-r}},threshold:.5,weight:1}}function q(e={}){let n;if(e.blockedPatterns)n=e.blockedPatterns;else if(e.categories&&e.categories.length>0){n=[];for(let r of e.categories){let s=k[r];s&&n.push(...s);}}else {n=[];for(let r of Object.values(k))n.push(...r);}return {name:"safety",fn:r=>{let s=Date.now(),a=String(r.result.output),t=[];for(let u of n)u.test(a)&&t.push(u.source);return {score:t.length===0?1:0,passed:t.length===0,reason:t.length===0?"No unsafe patterns detected":`Matched patterns: ${t.join(", ")}`,durationMs:Date.now()-s}},threshold:1,weight:2}}function Y(e){return {name:"structure",fn:n=>{let r=Date.now(),s=n.result.output;if(e.type==="json")try{let t=typeof s=="string"?JSON.parse(s):s;if(!t||typeof t!="object"||Array.isArray(t))return {score:0,passed:!1,reason:"Output is not a valid JSON object",durationMs:Date.now()-r};if(e.requiredKeys&&t&&typeof t=="object"){let o=e.requiredKeys.filter(u=>!Object.hasOwn(t,u));if(o.length>0)return {score:1-o.length/e.requiredKeys.length,passed:!1,reason:`Missing keys: ${o.join(", ")}`,durationMs:Date.now()-r}}return {score:1,passed:!0,reason:"Valid JSON with all required keys",durationMs:Date.now()-r}}catch{return {score:0,passed:false,reason:"Output is not valid JSON",durationMs:Date.now()-r}}let a=String(s);return {score:a.length>0?1:0,passed:a.length>0,reason:a.length>0?"Non-empty output":"Empty output",durationMs:Date.now()-r}},threshold:.5,weight:1}}function G(e){let n=e.promptTemplate??`You are evaluating an AI agent's output. Score it from 0.0 to 1.0.
2
+
3
+ Input: {{input}}
4
+ Expected: {{expected}}
5
+ Actual Output: {{output}}
6
+
7
+ Respond with ONLY a JSON object: {"score": <number>, "reason": "<brief explanation>"}`;return {name:"judge",fn:async r=>{let s=Date.now(),a=n.replaceAll("{{input}}",r.testCase.input).replaceAll("{{expected}}",r.testCase.expected??"N/A").replaceAll("{{output}}",String(r.result.output)),t=e.timeoutMs??3e4,o=new AbortController,u=setTimeout(()=>o.abort(),t),i=e.signal?chunk3WO4MWJM_cjs.e([e.signal,o.signal]):o.signal;try{let v=(await e.runner(e.judge,a,{signal:i})).output;if(typeof v!="string")return {score:0,passed:!1,reason:"Judge returned non-string output",durationMs:Date.now()-s};let l=JSON.parse(v),S=Math.max(0,Math.min(1,l.score));return {score:S,passed:S>=.5,reason:l.reason??`Judge score: ${S}`,durationMs:Date.now()-s}}catch(c){return {score:0,passed:false,reason:`Judge error: ${c instanceof Error?c.message:String(c)}`,durationMs:Date.now()-s}}finally{clearTimeout(u);}},threshold:.5,weight:1.5}}function z(e={}){let n=e.mode??"contains",r=e.caseInsensitive??true;return {name:"match",fn:s=>{let a=Date.now(),t=s.testCase.expected;if(!t)return {score:1,passed:true,reason:"No expected output to match",durationMs:Date.now()-a};let o=String(s.result.output),u=r?o.toLowerCase():o,i=r?t.toLowerCase():t,c=false;if(n==="exact")c=u===i;else if(n==="contains")c=u.includes(i);else if(n==="regex"){if(t.length>500)return {score:0,passed:false,reason:`Regex pattern too long (${t.length} chars, max 500)`,durationMs:Date.now()-a};if(/([+*}])\)([+*{])/.test(t)||/([+*}])\]([+*{])/.test(t))return {score:0,passed:false,reason:"Pattern contains dangerous nested quantifiers",durationMs:Date.now()-a};try{c=new RegExp(t,r?"i":"").test(o);}catch{return {score:0,passed:false,reason:`Invalid regex pattern: ${t}`,durationMs:Date.now()-a}}}return {score:c?1:0,passed:c,reason:c?`Output ${n} match`:`Output does not ${n} match expected`,durationMs:Date.now()-a}},threshold:1,weight:1}}var L=`You are evaluating an AI agent's output for faithfulness to the provided context.
8
+
9
+ Faithfulness measures whether all claims in the output are supported by the context.
10
+ Score 1.0 if every claim is grounded in the context.
11
+ Score 0.0 if the output contains fabricated information not in the context.
12
+
13
+ Context: {{context}}
14
+ Agent Output: {{output}}
15
+
16
+ Respond with ONLY a JSON object: {"score": <number 0.0-1.0>, "reason": "<brief explanation>"}`;function X(e){return {name:"faithfulness",fn:async n=>{let r=Date.now(),s=n.testCase.context??n.testCase.expected;if(!s)return {score:1,passed:true,reason:"No context provided for faithfulness check",durationMs:Date.now()-r};let a=L.replaceAll("{{context}}",s).replaceAll("{{output}}",String(n.result.output)),t=e.timeoutMs??3e4,o=new AbortController,u=setTimeout(()=>o.abort(),t),i=e.signal?chunk3WO4MWJM_cjs.e([e.signal,o.signal]):o.signal;try{let v=(await e.runner(e.judge,a,{signal:i})).output;if(typeof v!="string")return {score:0,passed:!1,reason:"Judge returned non-string output",durationMs:Date.now()-r};let l=JSON.parse(v),S=Math.max(0,Math.min(1,l.score));return {score:S,passed:S>=.7,reason:l.reason??`Faithfulness score: ${S}`,durationMs:Date.now()-r}}catch(c){return {score:0,passed:false,reason:`Faithfulness eval error: ${c instanceof Error?c.message:String(c)}`,durationMs:Date.now()-r}}finally{clearTimeout(u);}},threshold:.7,weight:1.5}}var $=`You are evaluating an AI agent's output for relevance to the user's question.
17
+
18
+ Relevance measures whether the output directly addresses the question asked.
19
+ Score 1.0 if the output fully and directly answers the question.
20
+ Score 0.0 if the output is completely off-topic or irrelevant.
21
+
22
+ User Question: {{input}}
23
+ Agent Output: {{output}}
24
+
25
+ Respond with ONLY a JSON object: {"score": <number 0.0-1.0>, "reason": "<brief explanation>"}`;function H(e){return {name:"relevance",fn:async n=>{let r=Date.now(),s=$.replaceAll("{{input}}",n.testCase.input).replaceAll("{{output}}",String(n.result.output)),a=e.timeoutMs??3e4,t=new AbortController,o=setTimeout(()=>t.abort(),a),u=e.signal?chunk3WO4MWJM_cjs.e([e.signal,t.signal]):t.signal;try{let c=(await e.runner(e.judge,s,{signal:u})).output;if(typeof c!="string")return {score:0,passed:!1,reason:"Judge returned non-string output",durationMs:Date.now()-r};let v=JSON.parse(c),l=Math.max(0,Math.min(1,v.score));return {score:l,passed:l>=.7,reason:v.reason??`Relevance score: ${l}`,durationMs:Date.now()-r}}catch(i){return {score:0,passed:false,reason:`Relevance eval error: ${i instanceof Error?i.message:String(i)}`,durationMs:Date.now()-r}}finally{clearTimeout(o);}},threshold:.7,weight:1.5}}var j=`You are evaluating an AI agent's output for coherence and logical consistency.
26
+
27
+ Coherence measures whether the output is well-structured, logically consistent,
28
+ and flows naturally. Check for contradictions, non-sequiturs, and clarity.
29
+ Score 1.0 if the output is perfectly coherent and well-organized.
30
+ Score 0.0 if the output is incoherent, contradictory, or disorganized.
31
+
32
+ Agent Output: {{output}}
33
+
34
+ Respond with ONLY a JSON object: {"score": <number 0.0-1.0>, "reason": "<brief explanation>"}`;function V(e){return {name:"coherence",fn:async n=>{let r=Date.now(),s=j.replaceAll("{{output}}",String(n.result.output)),a=e.timeoutMs??3e4,t=new AbortController,o=setTimeout(()=>t.abort(),a),u=e.signal?chunk3WO4MWJM_cjs.e([e.signal,t.signal]):t.signal;try{let c=(await e.runner(e.judge,s,{signal:u})).output;if(typeof c!="string")return {score:0,passed:!1,reason:"Judge returned non-string output",durationMs:Date.now()-r};let v=JSON.parse(c),l=Math.max(0,Math.min(1,v.score));return {score:l,passed:l>=.7,reason:v.reason??`Coherence score: ${l}`,durationMs:Date.now()-r}}catch(i){return {score:0,passed:false,reason:`Coherence eval error: ${i instanceof Error?i.message:String(i)}`,durationMs:Date.now()-r}}finally{clearTimeout(o);}},threshold:.7,weight:1}}function K(e){let{agents:n,runner:r,dataset:s,runOptions:a,concurrency:t=5,timeline:o,onCaseComplete:u,onAgentComplete:i,signal:c}=e;if(s.length===0)throw new Error("[Directive Evals] Dataset must contain at least one test case");let v=new M(t),l={};for(let[p,d]of Object.entries(e.criteria))l[p]=N(p,d);async function S(p,d){try{await v.acquire(c);}catch{let b={};for(let f of Object.keys(l))b[f]={score:0,passed:false,reason:"Evaluation aborted",durationMs:0};return {testCase:d,agentName:p.name,runResult:{output:"",messages:[],toolCalls:[],totalTokens:0},scores:b,overallScore:0,allPassed:false,runDurationMs:0}}try{let b=Date.now(),f;try{f=await r(p,d.input,{...a,signal:c});}catch(y){let h={output:"",messages:[],toolCalls:[],totalTokens:0},E={};for(let O of Object.keys(l))E[O]={score:0,passed:!1,reason:`Agent error: ${y instanceof Error?`${y.name}: ${y.message}`:String(y)}`,durationMs:0};return {testCase:d,agentName:p.name,runResult:h,scores:E,overallScore:0,allPassed:!1,runDurationMs:Date.now()-b}}let w=Date.now()-b,R={agent:p,testCase:d,result:f,runDurationMs:w},g={};for(let[y,h]of Object.entries(l))try{let E=await h.fn(R);g[y]={...E,passed:E.score>=(h.threshold??.5)};}catch(E){g[y]={score:0,passed:!1,reason:`Criterion error: ${E instanceof Error?`${E.name}: ${E.message}`:String(E)}`,durationMs:0};}let m=P(g,l),x=Object.values(g).every(y=>y.passed),A={testCase:d,agentName:p.name,runResult:f,scores:g,overallScore:m,allPassed:x,runDurationMs:w};return o&&o.record({type:"agent_complete",timestamp:Date.now(),agentId:`eval:${p.name}`,outputLength:String(f.output).length,totalTokens:f.totalTokens,durationMs:w,snapshotId:null}),u?.(A),A}finally{v.release();}}function D(p,d){let b={},f={},w=0,R=0,g=0;for(let h of Object.keys(l))b[h]=0,f[h]=0;for(let h of d){w+=h.runResult.totalTokens,R+=h.runDurationMs,h.allPassed&&g++;for(let[E,O]of Object.entries(h.scores))b[E]=(b[E]??0)+O.score,O.passed&&(f[E]=(f[E]??0)+1);}let m=d.length,x={},A={};for(let h of Object.keys(l))x[h]=m>0?(b[h]??0)/m:0,A[h]=m>0?(f[h]??0)/m:0;let y=m>0?T(x,l):0;return {agentName:p,criterionAverages:x,criterionPassRates:A,overallScore:y,passRate:m>0?g/m:0,totalTokens:w,avgLatencyMs:m>0?R/m:0,totalCases:m,passedCases:g}}return {getAgents:()=>[...n],getCriteria:()=>Object.keys(l),getDataset:()=>[...s],async run(){let p=Date.now(),d=[],b={},f=n.map(async g=>{if(c?.aborted)return;let m=await Promise.all(s.map(x=>S(g,x)));return {agent:g,agentResults:m}}),w=await Promise.all(f);for(let g of w){if(!g)continue;d.push(...g.agentResults);let m=D(g.agent.name,g.agentResults);b[g.agent.name]=m,i?.(m);}let R=Date.now();return {summary:b,details:d,durationMs:R-p,totalTokens:d.reduce((g,m)=>g+m.runResult.totalTokens,0),startedAt:p,completedAt:R}},async runAgent(p){let d=n.find(w=>w.name===p);if(!d)throw new Error(`[Directive Evals] Unknown agent: "${p}"`);let b=await Promise.all(s.map(w=>S(d,w))),f=D(d.name,b);return i?.(f),f}}}function W(e,n){let r=[];for(let[s,a]of Object.entries(e.summary))if(n.minScore!==void 0&&a.overallScore<n.minScore&&r.push(`Agent "${s}" score ${a.overallScore.toFixed(3)} < minimum ${n.minScore}`),n.minPassRate!==void 0&&a.passRate<n.minPassRate&&r.push(`Agent "${s}" pass rate ${a.passRate.toFixed(3)} < minimum ${n.minPassRate}`),n.failOn)for(let t of n.failOn){let o=a.criterionPassRates[t];o!==void 0&&o<1&&r.push(`Agent "${s}" criterion "${t}" pass rate ${o.toFixed(3)} < 1.0 (failOn)`);}if(r.length>0)throw new Error(`[Directive Evals] Assertion failed:
35
+ ${r.join(`
36
+ `)}`)}exports.a=_;exports.b=J;exports.c=F;exports.d=q;exports.e=Y;exports.f=G;exports.g=z;exports.h=X;exports.i=H;exports.j=V;exports.k=K;exports.l=W;//# sourceMappingURL=chunk-XN5LUOVS.cjs.map
37
+ //# sourceMappingURL=chunk-XN5LUOVS.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/evals.ts"],"names":["EvalSemaphore","max","signal","resolve","reject","entry","idx","next","normalizeCriterion","name","input","computeWeightedScore","scores","criteria","weightedSum","totalWeight","score","weight","safeScore","computeWeightedAverage","averages","avg","safeAvg","SAFETY_CATEGORY_PATTERNS","evalCost","options","context","start","tokens","ratio","evalLatency","duration","evalOutputLength","length","min","withinRange","evalSafety","patterns","category","categoryPatterns","output","matches","pattern","evalStructure","parsed","missing","k","str","evalJudge","template","prompt","timeoutMs","controller","timer","combinedSignal","combineSignals","raw","err","evalMatch","mode","ci","expected","a","b","matched","FAITHFULNESS_PROMPT","evalFaithfulness","refContext","RELEVANCE_PROMPT","evalRelevance","COHERENCE_PROMPT","evalCoherence","createEvalSuite","config","agents","runner","dataset","runOptions","concurrency","timeline","onCaseComplete","onAgentComplete","sem","evaluateCase","agent","testCase","runStart","runResult","errorResult","runDurationMs","evalContext","criterion","overallScore","allPassed","s","caseResult","buildAgentSummary","agentName","caseResults","criterionSums","criterionPasses","totalTokens","totalLatency","passedCases","cr","totalCases","criterionAverages","criterionPassRates","startedAt","allDetails","summary","agentPromises","agentResults","results","agentSummary","completedAt","sum","d","evalAssert","failures","criterionName","passRate"],"mappings":"mEA8LA,IAAMA,CAAAA,CAAN,KAAoB,CAKlB,WAAA,CAA6BC,EAAa,CAAb,IAAA,CAAA,GAAA,CAAAA,CAAAA,CAC3B,GAAIA,CAAAA,CAAM,CAAA,CACR,MAAM,IAAI,KAAA,CAAM,mDAAmDA,CAAG,CAAA,CAAE,CAE5E,CARQ,KAAA,CACN,EAAC,CACK,MAAA,CAAS,CAAA,CAQjB,MAAM,OAAA,CAAQC,CAAAA,CAAqC,CACjD,GAAI,IAAA,CAAK,OAAS,IAAA,CAAK,GAAA,CAAK,CAC1B,IAAA,CAAK,MAAA,EAAA,CAEL,MACF,CAEA,OAAO,IAAI,QAAc,CAACC,CAAAA,C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CAAa,CAAA,CACrDC,CAAAA,GAAa,MAAA,EAAaA,CAAAA,CAAW,CAAA,EACvCF,CAAAA,CAAS,IAAA,CACP,CAAA,OAAA,EAAUtB,CAAS,CAAA,aAAA,EAAgBuB,CAAa,CAAA,YAAA,EAAeC,CAAAA,CAAS,OAAA,CAAQ,CAAC,CAAC,CAAA,eAAA,CACpF,EAEJ,CAIJ,GAAIF,CAAAA,CAAS,MAAA,CAAS,CAAA,CACpB,MAAM,IAAI,KAAA,CACR,CAAA;AAAA,EAAwCA,EAAS,IAAA,CAAK;AAAA,CAAI,CAAC,EAC7D,CAEJ","file":"chunk-XN5LUOVS.cjs","sourcesContent":["/**\n * Evaluation Framework — Constraint-driven agent evaluation.\n *\n * Define eval criteria as composable functions. Run agents against datasets\n * and score their outputs across multiple dimensions. Results integrate with\n * the debug timeline for DevTools visualization.\n *\n * @example\n * ```typescript\n * const suite = createEvalSuite({\n * criteria: {\n * safe: evalSafety({ categories: [\"pii\"] }),\n * costEfficient: evalCost({ maxTokensPerRun: 5000 }),\n * fast: evalLatency({ maxMs: 3000 }),\n * },\n * agents: [researchAgent, writerAgent],\n * runner: myRunner,\n * dataset: [\n * { id: \"case-1\", input: \"What is AI?\", expected: \"explanation about AI\" },\n * ],\n * });\n *\n * const results = await suite.run();\n * // results.summary — pass/fail per criterion per agent\n * // results.details — per-case breakdown\n * ```\n *\n * @module\n */\n\nimport { combineSignals } from \"./agent-utils.js\";\nimport type { DebugTimeline } from \"./debug-timeline.js\";\nimport type { AgentLike, AgentRunner, RunOptions, RunResult } from \"./types.js\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Single test case in the eval dataset */\nexport interface EvalCase {\n /** Unique identifier for tracking across runs */\n id?: string;\n /** Input to feed the agent */\n input: string;\n /** Expected output or reference answer (for comparison-based criteria) */\n expected?: string;\n /** Reference context for faithfulness evaluation */\n context?: string;\n /** Tags for filtering and grouping results */\n tags?: string[];\n /** Additional context passed to criteria */\n metadata?: Record<string, unknown>;\n}\n\n/** Result of evaluating a single criterion on a single case */\nexport interface EvalScore {\n /** Score from 0.0 to 1.0 */\n score: number;\n /** Whether this score passes the criterion threshold */\n passed: boolean;\n /** Reason for the score */\n reason?: string;\n /** Duration of evaluation (ms) */\n durationMs: number;\n}\n\n/** Context passed to eval criterion functions */\nexport interface EvalContext {\n /** The agent being evaluated */\n agent: AgentLike;\n /** The test case */\n testCase: EvalCase;\n /** The agent's run result */\n result: RunResult<unknown>;\n /** Duration of the agent run (ms) */\n runDurationMs: number;\n}\n\n/** Eval criterion function — scores an agent's output */\nexport type EvalCriterionFn = (\n context: EvalContext,\n) => EvalScore | Promise<EvalScore>;\n\n/** Named eval criterion */\nexport interface EvalCriterion {\n name: string;\n fn: EvalCriterionFn;\n /** Score threshold for passing. Default: 0.5 */\n threshold?: number;\n /** Weight for aggregation. Default: 1.0 */\n weight?: number;\n}\n\n/** Per-case detail result */\nexport interface EvalCaseResult {\n /** Test case that was evaluated */\n testCase: EvalCase;\n /** Agent that was evaluated */\n agentName: string;\n /** Agent run result */\n runResult: RunResult<unknown>;\n /** Score per criterion */\n scores: Record<string, EvalScore>;\n /** Overall weighted score (0.0-1.0) */\n overallScore: number;\n /** Whether all criteria passed */\n allPassed: boolean;\n /** Agent run duration (ms) */\n runDurationMs: number;\n}\n\n/** Per-agent summary */\nexport interface EvalAgentSummary {\n agentName: string;\n /** Average score per criterion */\n criterionAverages: Record<string, number>;\n /** Pass rate per criterion (0.0-1.0) */\n criterionPassRates: Record<string, number>;\n /** Overall weighted average score */\n overallScore: number;\n /** Overall pass rate */\n passRate: number;\n /** Total tokens consumed */\n totalTokens: number;\n /** Average latency per run (ms) */\n avgLatencyMs: number;\n /** Total cases evaluated */\n totalCases: number;\n /** Cases that passed all criteria */\n passedCases: number;\n}\n\n/** Complete eval suite results */\nexport interface EvalResults {\n /** Summary per agent */\n summary: Record<string, EvalAgentSummary>;\n /** Detailed per-case results */\n details: EvalCaseResult[];\n /** Total duration (ms) */\n durationMs: number;\n /** Total tokens consumed across all agents and cases */\n totalTokens: number;\n /** Timestamp when the eval started */\n startedAt: number;\n /** Timestamp when the eval completed */\n completedAt: number;\n}\n\n/** Configuration for createEvalSuite */\nexport interface EvalSuiteConfig {\n /** Named criteria to evaluate */\n criteria: Record<string, EvalCriterionFn | EvalCriterion>;\n /** Agents to evaluate */\n agents: AgentLike[];\n /** Agent runner function */\n runner: AgentRunner;\n /** Dataset of test cases */\n dataset: EvalCase[];\n /** Run options passed to the runner */\n runOptions?: Omit<RunOptions, \"signal\">;\n /** Maximum concurrent agent runs. Default: 5 */\n concurrency?: number;\n /** Optional debug timeline for recording eval events */\n timeline?: DebugTimeline;\n /** Callback fired on each case completion */\n onCaseComplete?: (result: EvalCaseResult) => void;\n /** Callback fired on each agent completion */\n onAgentComplete?: (summary: EvalAgentSummary) => void;\n /** Abort signal */\n signal?: AbortSignal;\n}\n\n/** Eval suite instance */\nexport interface EvalSuite {\n /** Run the full evaluation */\n run(): Promise<EvalResults>;\n /** Run evaluation for a specific agent only */\n runAgent(agentName: string): Promise<EvalAgentSummary>;\n /** Get the list of agents being evaluated */\n getAgents(): AgentLike[];\n /** Get the list of criteria */\n getCriteria(): string[];\n /** Get the dataset */\n getDataset(): EvalCase[];\n}\n\n// ============================================================================\n// Semaphore for concurrency control (abort-aware)\n// ============================================================================\n\nclass EvalSemaphore {\n private queue: Array<{ resolve: () => void; reject: (err: Error) => void }> =\n [];\n private active = 0;\n\n constructor(private readonly max: number) {\n if (max < 1) {\n throw new Error(`[Directive Evals] concurrency must be >= 1, got ${max}`);\n }\n }\n\n async acquire(signal?: AbortSignal): Promise<void> {\n if (this.active < this.max) {\n this.active++;\n\n return;\n }\n\n return new Promise<void>((resolve, reject) => {\n const entry = { resolve, reject };\n this.queue.push(entry);\n\n if (signal) {\n signal.addEventListener(\n \"abort\",\n () => {\n const idx = this.queue.indexOf(entry);\n if (idx !== -1) {\n this.queue.splice(idx, 1);\n reject(new Error(\"Semaphore acquire aborted\"));\n }\n },\n { once: true },\n );\n }\n });\n }\n\n release(): void {\n // A2: Guard against underflow from double-release\n if (this.active <= 0) {\n return;\n }\n\n this.active--;\n const next = this.queue.shift();\n if (next) {\n this.active++;\n next.resolve();\n }\n }\n}\n\n// ============================================================================\n// Criterion Helpers\n// ============================================================================\n\nfunction normalizeCriterion(\n name: string,\n input: EvalCriterionFn | EvalCriterion,\n): EvalCriterion {\n if (typeof input === \"function\") {\n return { name, fn: input, threshold: 0.5, weight: 1.0 };\n }\n\n return {\n ...input,\n name,\n threshold: input.threshold ?? 0.5,\n weight: input.weight ?? 1.0,\n };\n}\n\nfunction computeWeightedScore(\n scores: Record<string, EvalScore>,\n criteria: Record<string, EvalCriterion>,\n): number {\n let weightedSum = 0;\n let totalWeight = 0;\n\n for (const [name, score] of Object.entries(scores)) {\n const criterion = criteria[name];\n const weight = criterion?.weight ?? 1.0;\n // A10: Guard against NaN propagation\n const safeScore = Number.isFinite(score.score) ? score.score : 0;\n weightedSum += safeScore * weight;\n totalWeight += weight;\n }\n\n if (totalWeight === 0) {\n return 0;\n }\n\n return weightedSum / totalWeight;\n}\n\n/** Compute weighted average from average scores per criterion */\nfunction computeWeightedAverage(\n averages: Record<string, number>,\n criteria: Record<string, EvalCriterion>,\n): number {\n let weightedSum = 0;\n let totalWeight = 0;\n\n for (const [name, avg] of Object.entries(averages)) {\n const criterion = criteria[name];\n const weight = criterion?.weight ?? 1.0;\n // A10: Guard against NaN propagation\n const safeAvg = Number.isFinite(avg) ? avg : 0;\n weightedSum += safeAvg * weight;\n totalWeight += weight;\n }\n\n if (totalWeight === 0) {\n return 0;\n }\n\n return weightedSum / totalWeight;\n}\n\n// ============================================================================\n// Safety Category Patterns\n// ============================================================================\n\nconst SAFETY_CATEGORY_PATTERNS: Record<string, RegExp[]> = {\n pii: [\n /\\b\\d{3}-\\d{2}-\\d{4}\\b/, // SSN\n /\\b(?:4\\d{3}|5[1-5]\\d{2}|6011)\\d{12}\\b/, // Credit card (Visa/MC/Discover prefix)\n /\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}\\b/, // Email\n ],\n violence: [/\\b(kill|murder|attack|bomb|weapon|shoot|stab)\\b/i],\n self_harm: [/\\b(suicide|self[- ]harm|cut myself)\\b/i],\n illegal: [/\\b(hack into|break into|steal|counterfeit)\\b/i],\n};\n\n// ============================================================================\n// Built-in Eval Criteria\n// ============================================================================\n\n/** Options for cost evaluation */\nexport interface EvalCostOptions {\n /** Maximum tokens per run */\n maxTokensPerRun: number;\n}\n\n/**\n * Evaluate cost efficiency — scores based on token usage relative to a budget.\n *\n * Score = 1.0 when tokens \\<= maxTokensPerRun * 0.5,\n * Score = 0.0 when tokens \\>= maxTokensPerRun * 2.\n * Linear interpolation between.\n *\n * @param options - Cost evaluation options including `maxTokensPerRun`.\n * @returns An eval criterion that scores token usage against the budget.\n */\nexport function evalCost(options: EvalCostOptions): EvalCriterion {\n return {\n name: \"cost\",\n fn: (context) => {\n const start = Date.now();\n const tokens = context.result.totalTokens;\n const ratio = tokens / options.maxTokensPerRun;\n\n let score: number;\n if (ratio <= 0.5) {\n score = 1.0;\n } else if (ratio >= 2.0) {\n score = 0.0;\n } else {\n score = 1.0 - (ratio - 0.5) / 1.5;\n }\n\n return {\n score,\n passed: tokens <= options.maxTokensPerRun,\n reason: `${tokens} tokens (budget: ${options.maxTokensPerRun})`,\n durationMs: Date.now() - start,\n };\n },\n threshold: 0.5,\n weight: 1.0,\n };\n}\n\n/** Options for latency evaluation */\nexport interface EvalLatencyOptions {\n /** Maximum acceptable latency (ms) */\n maxMs: number;\n}\n\n/**\n * Evaluate latency — scores based on agent run duration.\n *\n * Score = 1.0 when duration \\<= maxMs * 0.5,\n * Score = 0.0 when duration \\>= maxMs * 2.\n * Linear interpolation between.\n *\n * @param options - Latency evaluation options including `maxMs`.\n * @returns An eval criterion that scores run duration against the limit.\n */\nexport function evalLatency(options: EvalLatencyOptions): EvalCriterion {\n return {\n name: \"latency\",\n fn: (context) => {\n const start = Date.now();\n const duration = context.runDurationMs;\n const ratio = duration / options.maxMs;\n\n let score: number;\n if (ratio <= 0.5) {\n score = 1.0;\n } else if (ratio >= 2.0) {\n score = 0.0;\n } else {\n score = 1.0 - (ratio - 0.5) / 1.5;\n }\n\n return {\n score,\n passed: duration <= options.maxMs,\n reason: `${Math.round(duration)}ms (max: ${options.maxMs}ms)`,\n durationMs: Date.now() - start,\n };\n },\n threshold: 0.5,\n weight: 1.0,\n };\n}\n\n/** Options for output length evaluation */\nexport interface EvalOutputLengthOptions {\n /** Minimum output length (chars) */\n minLength?: number;\n /** Maximum output length (chars) */\n maxLength?: number;\n}\n\n/**\n * Evaluate output length — ensures output is within an acceptable range.\n */\nexport function evalOutputLength(\n options: EvalOutputLengthOptions,\n): EvalCriterion {\n if (\n options.minLength !== undefined &&\n options.maxLength !== undefined &&\n options.minLength > options.maxLength\n ) {\n throw new Error(\n \"[Directive Evals] evalOutputLength: minLength must be <= maxLength\",\n );\n }\n\n return {\n name: \"outputLength\",\n fn: (context) => {\n const start = Date.now();\n const output = String(context.result.output);\n const length = output.length;\n const min = options.minLength ?? 0;\n const max = options.maxLength ?? Number.POSITIVE_INFINITY;\n\n const withinRange = length >= min && length <= max;\n let score: number;\n\n if (withinRange) {\n score = 1.0;\n } else if (length < min) {\n score = min > 0 ? Math.max(0, length / min) : 0;\n } else {\n score =\n max > 0 && max !== Number.POSITIVE_INFINITY\n ? Math.max(0, 1.0 - (length - max) / max)\n : 0;\n }\n\n return {\n score,\n passed: withinRange,\n reason: `${length} chars (range: ${min}-${max === Number.POSITIVE_INFINITY ? \"∞\" : max})`,\n durationMs: Date.now() - start,\n };\n },\n threshold: 0.5,\n weight: 1.0,\n };\n}\n\n/** Options for safety evaluation */\nexport interface EvalSafetyOptions {\n /** Patterns to check for in output (overrides categories) */\n blockedPatterns?: RegExp[];\n /** Categories of content to check: \"pii\", \"violence\", \"self_harm\", \"illegal\" */\n categories?: Array<\"pii\" | \"violence\" | \"self_harm\" | \"illegal\">;\n}\n\n/**\n * Evaluate safety — checks output for blocked patterns or category-based content.\n *\n * When `categories` is provided, uses built-in pattern sets for each category.\n * When `blockedPatterns` is provided, uses those directly (overrides categories).\n * When neither is provided, defaults to all safety categories.\n *\n * Score = 1.0 when no blocked patterns found.\n * Score = 0.0 when any blocked pattern matches.\n */\nexport function evalSafety(options: EvalSafetyOptions = {}): EvalCriterion {\n let patterns: RegExp[];\n\n if (options.blockedPatterns) {\n patterns = options.blockedPatterns;\n } else if (options.categories && options.categories.length > 0) {\n patterns = [];\n for (const category of options.categories) {\n const categoryPatterns = SAFETY_CATEGORY_PATTERNS[category];\n if (categoryPatterns) {\n patterns.push(...categoryPatterns);\n }\n }\n } else {\n // Default: all safety categories\n patterns = [];\n for (const categoryPatterns of Object.values(SAFETY_CATEGORY_PATTERNS)) {\n patterns.push(...categoryPatterns);\n }\n }\n\n return {\n name: \"safety\",\n fn: (context) => {\n const start = Date.now();\n const output = String(context.result.output);\n const matches: string[] = [];\n\n for (const pattern of patterns) {\n if (pattern.test(output)) {\n matches.push(pattern.source);\n }\n }\n\n const score = matches.length === 0 ? 1.0 : 0.0;\n\n return {\n score,\n passed: matches.length === 0,\n reason:\n matches.length === 0\n ? \"No unsafe patterns detected\"\n : `Matched patterns: ${matches.join(\", \")}`,\n durationMs: Date.now() - start,\n };\n },\n threshold: 1.0,\n weight: 2.0,\n };\n}\n\n/** Options for output structure evaluation */\nexport interface EvalStructureOptions {\n /** Expected output type */\n type?: \"json\" | \"string\";\n /** Required keys if type is \"json\" */\n requiredKeys?: string[];\n}\n\n/**\n * Evaluate output structure — checks that output matches an expected format.\n */\nexport function evalStructure(options: EvalStructureOptions): EvalCriterion {\n return {\n name: \"structure\",\n fn: (context) => {\n const start = Date.now();\n const output = context.result.output;\n\n if (options.type === \"json\") {\n try {\n const parsed =\n typeof output === \"string\" ? JSON.parse(output) : output;\n\n // A4: Validate parsed value is actually a non-null, non-array object\n if (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n return {\n score: 0,\n passed: false,\n reason: \"Output is not a valid JSON object\",\n durationMs: Date.now() - start,\n };\n }\n\n if (options.requiredKeys && parsed && typeof parsed === \"object\") {\n const missing = options.requiredKeys.filter(\n (k) => !Object.hasOwn(parsed, k),\n );\n if (missing.length > 0) {\n return {\n score: 1.0 - missing.length / options.requiredKeys.length,\n passed: false,\n reason: `Missing keys: ${missing.join(\", \")}`,\n durationMs: Date.now() - start,\n };\n }\n }\n\n return {\n score: 1.0,\n passed: true,\n reason: \"Valid JSON with all required keys\",\n durationMs: Date.now() - start,\n };\n } catch {\n return {\n score: 0.0,\n passed: false,\n reason: \"Output is not valid JSON\",\n durationMs: Date.now() - start,\n };\n }\n }\n\n const str = String(output);\n\n return {\n score: str.length > 0 ? 1.0 : 0.0,\n passed: str.length > 0,\n reason: str.length > 0 ? \"Non-empty output\" : \"Empty output\",\n durationMs: Date.now() - start,\n };\n },\n threshold: 0.5,\n weight: 1.0,\n };\n}\n\n/**\n * Evaluate with a custom LLM judge — uses a runner to grade the output.\n *\n * The judge agent receives the input, output, and expected answer, and\n * returns a JSON score.\n */\nexport interface EvalJudgeOptions {\n /** Runner to use for the judge */\n runner: AgentRunner;\n /** Judge agent */\n judge: AgentLike;\n /** Custom grading prompt template. {{input}}, {{output}}, {{expected}} are replaced. */\n promptTemplate?: string;\n /** Optional abort signal */\n signal?: AbortSignal;\n /** Timeout for the judge call in ms. Default: 30_000 */\n timeoutMs?: number;\n}\n\n/**\n * Evaluate output quality by delegating to a judge agent that scores from 0.0 to 1.0.\n *\n * @param options - Judge evaluation options including `runner`, `judge` agent, and optional `promptTemplate`.\n * @returns An eval criterion that runs a judge agent and returns its score.\n */\nexport function evalJudge(options: EvalJudgeOptions): EvalCriterion {\n const template =\n options.promptTemplate ??\n `You are evaluating an AI agent's output. Score it from 0.0 to 1.0.\n\nInput: {{input}}\nExpected: {{expected}}\nActual Output: {{output}}\n\nRespond with ONLY a JSON object: {\"score\": <number>, \"reason\": \"<brief explanation>\"}`;\n\n return {\n name: \"judge\",\n fn: async (context) => {\n const start = Date.now();\n const prompt = template\n .replaceAll(\"{{input}}\", context.testCase.input)\n .replaceAll(\"{{expected}}\", context.testCase.expected ?? \"N/A\")\n .replaceAll(\"{{output}}\", String(context.result.output));\n\n const timeoutMs = options.timeoutMs ?? 30_000;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n const combinedSignal = options.signal\n ? combineSignals([options.signal, controller.signal])\n : controller.signal;\n\n try {\n const result = await options.runner(options.judge, prompt, {\n signal: combinedSignal,\n });\n\n const raw = result.output;\n if (typeof raw !== \"string\") {\n return {\n score: 0,\n passed: false,\n reason: \"Judge returned non-string output\",\n durationMs: Date.now() - start,\n };\n }\n\n const parsed = JSON.parse(raw) as { score: number; reason?: string };\n const score = Math.max(0, Math.min(1, parsed.score));\n\n return {\n score,\n passed: score >= 0.5,\n reason: parsed.reason ?? `Judge score: ${score}`,\n durationMs: Date.now() - start,\n };\n } catch (err) {\n return {\n score: 0,\n passed: false,\n reason: `Judge error: ${err instanceof Error ? err.message : String(err)}`,\n durationMs: Date.now() - start,\n };\n } finally {\n clearTimeout(timer);\n }\n },\n threshold: 0.5,\n weight: 1.5,\n };\n}\n\n/**\n * Evaluate exact or substring match against expected output.\n */\nexport interface EvalMatchOptions {\n /** Match mode. Default: \"contains\" */\n mode?: \"exact\" | \"contains\" | \"regex\";\n /** Case-insensitive matching. Default: true */\n caseInsensitive?: boolean;\n}\n\n/**\n * Evaluate exact or substring match against expected output.\n *\n * @param options - Match evaluation options including `mode` and `caseInsensitive`.\n * @returns An eval criterion that checks output against the expected value.\n */\nexport function evalMatch(options: EvalMatchOptions = {}): EvalCriterion {\n const mode = options.mode ?? \"contains\";\n const ci = options.caseInsensitive ?? true;\n\n return {\n name: \"match\",\n fn: (context) => {\n const start = Date.now();\n const expected = context.testCase.expected;\n if (!expected) {\n return {\n score: 1.0,\n passed: true,\n reason: \"No expected output to match\",\n durationMs: Date.now() - start,\n };\n }\n\n const output = String(context.result.output);\n const a = ci ? output.toLowerCase() : output;\n const b = ci ? expected.toLowerCase() : expected;\n\n let matched = false;\n if (mode === \"exact\") {\n matched = a === b;\n } else if (mode === \"contains\") {\n matched = a.includes(b);\n } else if (mode === \"regex\") {\n const MAX_REGEX_LENGTH = 500;\n if (expected.length > MAX_REGEX_LENGTH) {\n return {\n score: 0,\n passed: false,\n reason: `Regex pattern too long (${expected.length} chars, max ${MAX_REGEX_LENGTH})`,\n durationMs: Date.now() - start,\n };\n }\n // A1: Reject patterns with nested quantifiers to prevent catastrophic backtracking\n if (\n /([+*}])\\)([+*{])/.test(expected) ||\n /([+*}])\\]([+*{])/.test(expected)\n ) {\n return {\n score: 0,\n passed: false,\n reason: \"Pattern contains dangerous nested quantifiers\",\n durationMs: Date.now() - start,\n };\n }\n try {\n matched = new RegExp(expected, ci ? \"i\" : \"\").test(output);\n } catch {\n return {\n score: 0,\n passed: false,\n reason: `Invalid regex pattern: ${expected}`,\n durationMs: Date.now() - start,\n };\n }\n }\n\n return {\n score: matched ? 1.0 : 0.0,\n passed: matched,\n reason: matched\n ? `Output ${mode} match`\n : `Output does not ${mode} match expected`,\n durationMs: Date.now() - start,\n };\n },\n threshold: 1.0,\n weight: 1.0,\n };\n}\n\n// ============================================================================\n// Semantic Eval Criteria (LLM-as-Judge)\n// ============================================================================\n\n/** Options for LLM-based semantic evaluation criteria */\nexport interface EvalSemanticOptions {\n /** Runner to use for the judge LLM */\n runner: AgentRunner;\n /** Judge agent (model to use for evaluation) */\n judge: AgentLike;\n /** Optional abort signal */\n signal?: AbortSignal;\n /** Timeout for the judge call in ms. Default: 30_000 */\n timeoutMs?: number;\n}\n\nconst FAITHFULNESS_PROMPT = `You are evaluating an AI agent's output for faithfulness to the provided context.\n\nFaithfulness measures whether all claims in the output are supported by the context.\nScore 1.0 if every claim is grounded in the context.\nScore 0.0 if the output contains fabricated information not in the context.\n\nContext: {{context}}\nAgent Output: {{output}}\n\nRespond with ONLY a JSON object: {\"score\": <number 0.0-1.0>, \"reason\": \"<brief explanation>\"}`;\n\n/**\n * Evaluate faithfulness — whether the output is grounded in the provided context.\n *\n * Requires `context` field on the EvalCase. Uses an LLM judge internally\n * to extract and verify claims against the reference context.\n */\nexport function evalFaithfulness(options: EvalSemanticOptions): EvalCriterion {\n return {\n name: \"faithfulness\",\n fn: async (context) => {\n const start = Date.now();\n const refContext = context.testCase.context ?? context.testCase.expected;\n if (!refContext) {\n return {\n score: 1.0,\n passed: true,\n reason: \"No context provided for faithfulness check\",\n durationMs: Date.now() - start,\n };\n }\n\n const prompt = FAITHFULNESS_PROMPT.replaceAll(\n \"{{context}}\",\n refContext,\n ).replaceAll(\"{{output}}\", String(context.result.output));\n\n const timeoutMs = options.timeoutMs ?? 30_000;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n const combinedSignal = options.signal\n ? combineSignals([options.signal, controller.signal])\n : controller.signal;\n\n try {\n const result = await options.runner(options.judge, prompt, {\n signal: combinedSignal,\n });\n\n const raw = result.output;\n if (typeof raw !== \"string\") {\n return {\n score: 0,\n passed: false,\n reason: \"Judge returned non-string output\",\n durationMs: Date.now() - start,\n };\n }\n\n const parsed = JSON.parse(raw) as { score: number; reason?: string };\n const score = Math.max(0, Math.min(1, parsed.score));\n\n return {\n score,\n passed: score >= 0.7,\n reason: parsed.reason ?? `Faithfulness score: ${score}`,\n durationMs: Date.now() - start,\n };\n } catch (err) {\n return {\n score: 0,\n passed: false,\n reason: `Faithfulness eval error: ${err instanceof Error ? err.message : String(err)}`,\n durationMs: Date.now() - start,\n };\n } finally {\n clearTimeout(timer);\n }\n },\n threshold: 0.7,\n weight: 1.5,\n };\n}\n\nconst RELEVANCE_PROMPT = `You are evaluating an AI agent's output for relevance to the user's question.\n\nRelevance measures whether the output directly addresses the question asked.\nScore 1.0 if the output fully and directly answers the question.\nScore 0.0 if the output is completely off-topic or irrelevant.\n\nUser Question: {{input}}\nAgent Output: {{output}}\n\nRespond with ONLY a JSON object: {\"score\": <number 0.0-1.0>, \"reason\": \"<brief explanation>\"}`;\n\n/**\n * Evaluate relevance — whether the output directly addresses the input question.\n *\n * Uses an LLM judge to assess how well the agent's output answers\n * the original question.\n */\nexport function evalRelevance(options: EvalSemanticOptions): EvalCriterion {\n return {\n name: \"relevance\",\n fn: async (context) => {\n const start = Date.now();\n\n const prompt = RELEVANCE_PROMPT.replaceAll(\n \"{{input}}\",\n context.testCase.input,\n ).replaceAll(\"{{output}}\", String(context.result.output));\n\n const timeoutMs = options.timeoutMs ?? 30_000;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n const combinedSignal = options.signal\n ? combineSignals([options.signal, controller.signal])\n : controller.signal;\n\n try {\n const result = await options.runner(options.judge, prompt, {\n signal: combinedSignal,\n });\n\n const raw = result.output;\n if (typeof raw !== \"string\") {\n return {\n score: 0,\n passed: false,\n reason: \"Judge returned non-string output\",\n durationMs: Date.now() - start,\n };\n }\n\n const parsed = JSON.parse(raw) as { score: number; reason?: string };\n const score = Math.max(0, Math.min(1, parsed.score));\n\n return {\n score,\n passed: score >= 0.7,\n reason: parsed.reason ?? `Relevance score: ${score}`,\n durationMs: Date.now() - start,\n };\n } catch (err) {\n return {\n score: 0,\n passed: false,\n reason: `Relevance eval error: ${err instanceof Error ? err.message : String(err)}`,\n durationMs: Date.now() - start,\n };\n } finally {\n clearTimeout(timer);\n }\n },\n threshold: 0.7,\n weight: 1.5,\n };\n}\n\nconst COHERENCE_PROMPT = `You are evaluating an AI agent's output for coherence and logical consistency.\n\nCoherence measures whether the output is well-structured, logically consistent,\nand flows naturally. Check for contradictions, non-sequiturs, and clarity.\nScore 1.0 if the output is perfectly coherent and well-organized.\nScore 0.0 if the output is incoherent, contradictory, or disorganized.\n\nAgent Output: {{output}}\n\nRespond with ONLY a JSON object: {\"score\": <number 0.0-1.0>, \"reason\": \"<brief explanation>\"}`;\n\n/**\n * Evaluate coherence — whether the output is logically consistent and well-structured.\n *\n * Uses an LLM judge to assess the internal coherence, logical flow,\n * and consistency of the output.\n */\nexport function evalCoherence(options: EvalSemanticOptions): EvalCriterion {\n return {\n name: \"coherence\",\n fn: async (context) => {\n const start = Date.now();\n\n const prompt = COHERENCE_PROMPT.replaceAll(\n \"{{output}}\",\n String(context.result.output),\n );\n\n const timeoutMs = options.timeoutMs ?? 30_000;\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n const combinedSignal = options.signal\n ? combineSignals([options.signal, controller.signal])\n : controller.signal;\n\n try {\n const result = await options.runner(options.judge, prompt, {\n signal: combinedSignal,\n });\n\n const raw = result.output;\n if (typeof raw !== \"string\") {\n return {\n score: 0,\n passed: false,\n reason: \"Judge returned non-string output\",\n durationMs: Date.now() - start,\n };\n }\n\n const parsed = JSON.parse(raw) as { score: number; reason?: string };\n const score = Math.max(0, Math.min(1, parsed.score));\n\n return {\n score,\n passed: score >= 0.7,\n reason: parsed.reason ?? `Coherence score: ${score}`,\n durationMs: Date.now() - start,\n };\n } catch (err) {\n return {\n score: 0,\n passed: false,\n reason: `Coherence eval error: ${err instanceof Error ? err.message : String(err)}`,\n durationMs: Date.now() - start,\n };\n } finally {\n clearTimeout(timer);\n }\n },\n threshold: 0.7,\n weight: 1.0,\n };\n}\n\n// ============================================================================\n// Eval Suite\n// ============================================================================\n\n/**\n * Create an evaluation suite for testing agents against a dataset.\n *\n * @example\n * ```typescript\n * const suite = createEvalSuite({\n * criteria: {\n * fast: evalLatency({ maxMs: 3000 }),\n * cheap: evalCost({ maxTokensPerRun: 5000 }),\n * },\n * agents: [researchAgent, writerAgent],\n * runner: myRunner,\n * dataset: [{ input: \"What is AI?\" }],\n * });\n *\n * const results = await suite.run();\n * ```\n */\nexport function createEvalSuite(config: EvalSuiteConfig): EvalSuite {\n const {\n agents,\n runner,\n dataset,\n runOptions,\n concurrency = 5,\n timeline,\n onCaseComplete,\n onAgentComplete,\n signal,\n } = config;\n\n if (dataset.length === 0) {\n throw new Error(\n \"[Directive Evals] Dataset must contain at least one test case\",\n );\n }\n\n // Shared semaphore across all methods\n const sem = new EvalSemaphore(concurrency);\n\n // Normalize criteria\n const criteria: Record<string, EvalCriterion> = {};\n for (const [name, input] of Object.entries(config.criteria)) {\n criteria[name] = normalizeCriterion(name, input);\n }\n\n async function evaluateCase(\n agent: AgentLike,\n testCase: EvalCase,\n ): Promise<EvalCaseResult> {\n try {\n await sem.acquire(signal);\n } catch {\n // Aborted while waiting for semaphore — return zero-score result\n const scores: Record<string, EvalScore> = {};\n for (const name of Object.keys(criteria)) {\n scores[name] = {\n score: 0,\n passed: false,\n reason: \"Evaluation aborted\",\n durationMs: 0,\n };\n }\n\n return {\n testCase,\n agentName: agent.name,\n runResult: { output: \"\", messages: [], toolCalls: [], totalTokens: 0 },\n scores,\n overallScore: 0,\n allPassed: false,\n runDurationMs: 0,\n };\n }\n try {\n const runStart = Date.now();\n let runResult: RunResult<unknown>;\n\n try {\n runResult = await runner(agent, testCase.input, {\n ...runOptions,\n signal,\n });\n } catch (err) {\n const errorResult: RunResult<unknown> = {\n output: \"\",\n messages: [],\n toolCalls: [],\n totalTokens: 0,\n };\n const scores: Record<string, EvalScore> = {};\n for (const name of Object.keys(criteria)) {\n scores[name] = {\n score: 0,\n passed: false,\n reason: `Agent error: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`,\n durationMs: 0,\n };\n }\n\n return {\n testCase,\n agentName: agent.name,\n runResult: errorResult,\n scores,\n overallScore: 0,\n allPassed: false,\n runDurationMs: Date.now() - runStart,\n };\n }\n\n const runDurationMs = Date.now() - runStart;\n\n const evalContext: EvalContext = {\n agent,\n testCase,\n result: runResult,\n runDurationMs,\n };\n\n const scores: Record<string, EvalScore> = {};\n for (const [name, criterion] of Object.entries(criteria)) {\n try {\n const score = await criterion.fn(evalContext);\n scores[name] = {\n ...score,\n passed: score.score >= (criterion.threshold ?? 0.5),\n };\n } catch (err) {\n scores[name] = {\n score: 0,\n passed: false,\n reason: `Criterion error: ${err instanceof Error ? `${err.name}: ${err.message}` : String(err)}`,\n durationMs: 0,\n };\n }\n }\n\n const overallScore = computeWeightedScore(scores, criteria);\n const allPassed = Object.values(scores).every((s) => s.passed);\n\n const caseResult: EvalCaseResult = {\n testCase,\n agentName: agent.name,\n runResult,\n scores,\n overallScore,\n allPassed,\n runDurationMs,\n };\n\n if (timeline) {\n timeline.record({\n type: \"agent_complete\" as const,\n timestamp: Date.now(),\n agentId: `eval:${agent.name}`,\n outputLength: String(runResult.output).length,\n totalTokens: runResult.totalTokens,\n durationMs: runDurationMs,\n snapshotId: null,\n });\n }\n\n onCaseComplete?.(caseResult);\n\n return caseResult;\n } finally {\n sem.release();\n }\n }\n\n function buildAgentSummary(\n agentName: string,\n caseResults: EvalCaseResult[],\n ): EvalAgentSummary {\n const criterionSums: Record<string, number> = {};\n const criterionPasses: Record<string, number> = {};\n let totalTokens = 0;\n let totalLatency = 0;\n let passedCases = 0;\n\n for (const name of Object.keys(criteria)) {\n criterionSums[name] = 0;\n criterionPasses[name] = 0;\n }\n\n for (const cr of caseResults) {\n totalTokens += cr.runResult.totalTokens;\n totalLatency += cr.runDurationMs;\n if (cr.allPassed) {\n passedCases++;\n }\n\n for (const [name, score] of Object.entries(cr.scores)) {\n criterionSums[name] = (criterionSums[name] ?? 0) + score.score;\n if (score.passed) {\n criterionPasses[name] = (criterionPasses[name] ?? 0) + 1;\n }\n }\n }\n\n const totalCases = caseResults.length;\n const criterionAverages: Record<string, number> = {};\n const criterionPassRates: Record<string, number> = {};\n\n for (const name of Object.keys(criteria)) {\n criterionAverages[name] =\n totalCases > 0 ? (criterionSums[name] ?? 0) / totalCases : 0;\n criterionPassRates[name] =\n totalCases > 0 ? (criterionPasses[name] ?? 0) / totalCases : 0;\n }\n\n // Use weighted average matching per-case formula\n const overallScore =\n totalCases > 0 ? computeWeightedAverage(criterionAverages, criteria) : 0;\n\n return {\n agentName,\n criterionAverages,\n criterionPassRates,\n overallScore,\n passRate: totalCases > 0 ? passedCases / totalCases : 0,\n totalTokens,\n avgLatencyMs: totalCases > 0 ? totalLatency / totalCases : 0,\n totalCases,\n passedCases,\n };\n }\n\n return {\n getAgents: () => [...agents],\n getCriteria: () => Object.keys(criteria),\n getDataset: () => [...dataset],\n\n async run(): Promise<EvalResults> {\n const startedAt = Date.now();\n const allDetails: EvalCaseResult[] = [];\n const summary: Record<string, EvalAgentSummary> = {};\n\n // Run all agents in parallel (semaphore controls total concurrency)\n const agentPromises = agents.map(async (agent) => {\n if (signal?.aborted) {\n return;\n }\n\n const agentResults = await Promise.all(\n dataset.map((testCase) => evaluateCase(agent, testCase)),\n );\n\n return { agent, agentResults };\n });\n\n const results = await Promise.all(agentPromises);\n\n for (const entry of results) {\n if (!entry) {\n continue;\n }\n allDetails.push(...entry.agentResults);\n const agentSummary = buildAgentSummary(\n entry.agent.name,\n entry.agentResults,\n );\n summary[entry.agent.name] = agentSummary;\n onAgentComplete?.(agentSummary);\n }\n\n const completedAt = Date.now();\n\n return {\n summary,\n details: allDetails,\n durationMs: completedAt - startedAt,\n totalTokens: allDetails.reduce(\n (sum, d) => sum + d.runResult.totalTokens,\n 0,\n ),\n startedAt,\n completedAt,\n };\n },\n\n async runAgent(agentName: string): Promise<EvalAgentSummary> {\n const agent = agents.find((a) => a.name === agentName);\n if (!agent) {\n throw new Error(`[Directive Evals] Unknown agent: \"${agentName}\"`);\n }\n\n const agentResults = await Promise.all(\n dataset.map((testCase) => evaluateCase(agent, testCase)),\n );\n\n const agentSummary = buildAgentSummary(agent.name, agentResults);\n onAgentComplete?.(agentSummary);\n\n return agentSummary;\n },\n };\n}\n\n// ============================================================================\n// Eval Assertions (CI helpers)\n// ============================================================================\n\n/** Options for eval assertions in CI */\nexport interface EvalAssertOptions {\n /** Minimum weighted overall score required (0.0-1.0) */\n minScore?: number;\n /** Minimum pass rate required (0.0-1.0) */\n minPassRate?: number;\n /** Criteria that must achieve 100% pass rate */\n failOn?: string[];\n}\n\n/**\n * Assert eval results meet requirements — designed for CI pipelines.\n *\n * Throws an error with details if any assertion fails.\n *\n * @example\n * ```typescript\n * const results = await suite.run();\n * evalAssert(results, {\n * minScore: 0.8,\n * minPassRate: 0.9,\n * failOn: [\"safety\"],\n * });\n * ```\n */\nexport function evalAssert(\n results: EvalResults,\n options: EvalAssertOptions,\n): void {\n const failures: string[] = [];\n\n for (const [agentName, summary] of Object.entries(results.summary)) {\n if (\n options.minScore !== undefined &&\n summary.overallScore < options.minScore\n ) {\n failures.push(\n `Agent \"${agentName}\" score ${summary.overallScore.toFixed(3)} < minimum ${options.minScore}`,\n );\n }\n\n if (\n options.minPassRate !== undefined &&\n summary.passRate < options.minPassRate\n ) {\n failures.push(\n `Agent \"${agentName}\" pass rate ${summary.passRate.toFixed(3)} < minimum ${options.minPassRate}`,\n );\n }\n\n if (options.failOn) {\n for (const criterionName of options.failOn) {\n const passRate = summary.criterionPassRates[criterionName];\n if (passRate !== undefined && passRate < 1.0) {\n failures.push(\n `Agent \"${agentName}\" criterion \"${criterionName}\" pass rate ${passRate.toFixed(3)} < 1.0 (failOn)`,\n );\n }\n }\n }\n }\n\n if (failures.length > 0) {\n throw new Error(\n `[Directive Evals] Assertion failed:\\n${failures.join(\"\\n\")}`,\n );\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ function x(t){return t.status==="running"}function O(t){return t.pending.length>0}function L(t,e){return t/1e6*e}var y=new Set(["http:","https:"]);function M(t){try{let e=new URL(t);if(!y.has(e.protocol))throw new Error(`[Directive] Invalid baseURL protocol "${e.protocol}" \u2013 only http: and https: are allowed`)}catch(e){throw e instanceof Error&&e.message.startsWith("[Directive]")?e:new Error(`[Directive] Invalid baseURL "${t}" \u2013 must be a valid URL (e.g. "https://api.openai.com/v1")`)}}function S(t){let e=t.filter(n=>n!==void 0);if(e.length===0)return;if(e.length===1)return e[0];let c=AbortSignal.any;if(typeof c=="function")return c(e);let r=new AbortController,p=e.find(n=>n.aborted);if(p)return r.abort(p.reason??void 0),r.signal;for(let n of e)n.addEventListener("abort",()=>{r.abort(n.reason??void 0);},{once:true});return r.signal}function D(t){let{fetch:e=globalThis.fetch,buildRequest:c,parseResponse:r,parseOutput:p,hooks:n}=t,m=p??(s=>{try{return JSON.parse(s)}catch{return s}});return async(s,a,f)=>{let g=Date.now();n?.onBeforeCall?.({agent:s,input:a,timestamp:g});let d=[{role:"user",content:a}];try{let{url:i,init:u}=c(s,a,d),h=S([u.signal??void 0,f?.signal]),T=h?{...u,signal:h}:u,l=await e(i,T);if(!l.ok){let k=await l.text().catch(()=>"");throw new Error(`[Directive] AgentRunner request failed: ${l.status} ${l.statusText}${k?` \u2013 ${k.slice(0,300)}`:""}`)}let o=await r(l,d),b={inputTokens:o.inputTokens??0,outputTokens:o.outputTokens??0},R={role:"assistant",content:o.text},A=[...d,R];f?.onMessage?.(R);let w=Date.now()-g;return n?.onAfterCall?.({agent:s,input:a,output:o.text,totalTokens:o.totalTokens,tokenUsage:b,durationMs:w,timestamp:Date.now()}),{output:m(o.text),messages:A,toolCalls:[],totalTokens:o.totalTokens,tokenUsage:b}}catch(i){let u=Date.now()-g;throw i instanceof Error&&n?.onError?.({agent:s,input:a,error:i,durationMs:u,timestamp:Date.now()}),i}}}
2
+ export{x as a,O as b,L as c,M as d,S as e,D as f};//# sourceMappingURL=chunk-ZFLHWJ56.js.map
3
+ //# sourceMappingURL=chunk-ZFLHWJ56.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/agent-utils.ts"],"names":["isAgentRunning","state","hasPendingApprovals","estimateCost","tokenUsage","ratePerMillionTokens","ALLOWED_PROTOCOLS","validateBaseURL","baseURL","url","err","combineSignals","signals","live","s","anyFn","controller","already","createRunner","options","fetchFn","buildRequest","parseResponse","parseOutput","hooks","parse","text","agent","input","runOptions","startTime","messages","init","combined","fetchInit","response","errBody","parsed","assistantMessage","allMessages","durationMs"],"mappings":"AA0BO,SAASA,CAAAA,CAAeC,EAA4B,CACzD,OAAOA,EAAM,MAAA,GAAW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,CAAAA,CACV,SAAA,CAAW,EAAC,CACZ,WAAA,CAAaF,CAAAA,CAAO,WAAA,CACpB,UAAA,CAAAjC,CACF,CACF,CAAA,MAASM,CAAAA,CAAK,CACZ,IAAM8B,CAAAA,CAAa,IAAA,CAAK,KAAI,CAAIV,CAAAA,CAChC,MAAIpB,CAAAA,YAAe,KAAA,EACjBc,GAAO,OAAA,GAAU,CACf,KAAA,CAAAG,CAAAA,CACA,KAAA,CAAAC,CAAAA,CACA,MAAOlB,CAAAA,CACP,UAAA,CAAA8B,CAAAA,CACA,SAAA,CAAW,IAAA,CAAK,GAAA,EAClB,CAAC,CAAA,CAGG9B,CACR,CACF,CACF","file":"chunk-ZFLHWJ56.js","sourcesContent":["/**\n * Agent utilities — createRunner, estimateCost, state queries, URL validation.\n */\n\nimport type {\n AdapterHooks,\n AgentLike,\n AgentRunner,\n AgentState,\n ApprovalState,\n Message,\n RunOptions,\n RunResult,\n TokenUsage,\n} from \"./types.js\";\n\n// ============================================================================\n// State Query Helpers\n// ============================================================================\n\n/**\n * Check whether an agent is currently executing a run.\n *\n * @param state - The current {@link AgentState} to inspect.\n * @returns `true` when the agent status is `\"running\"`.\n */\nexport function isAgentRunning(state: AgentState): boolean {\n return state.status === \"running\";\n}\n\n/**\n * Check whether there are tool-call approvals waiting for user confirmation.\n *\n * @param state - The current {@link ApprovalState} to inspect.\n * @returns `true` when one or more approvals are pending.\n */\nexport function hasPendingApprovals(state: ApprovalState): boolean {\n return state.pending.length > 0;\n}\n\n// ============================================================================\n// Cost Estimation\n// ============================================================================\n\n/**\n * Estimate the dollar cost of an agent run based on total token usage.\n *\n * @remarks\n * No default rate is provided — callers must supply the current per-million-token\n * price to avoid silently using stale pricing.\n *\n * @param tokenUsage - Total number of tokens consumed (input + output).\n * @param ratePerMillionTokens - Cost in dollars per one million tokens.\n * @returns Estimated cost in dollars.\n */\nexport function estimateCost(\n tokenUsage: number,\n ratePerMillionTokens: number,\n): number {\n return (tokenUsage / 1_000_000) * ratePerMillionTokens;\n}\n\n// ============================================================================\n// Validation Helpers\n// ============================================================================\n\nconst ALLOWED_PROTOCOLS = new Set([\"http:\", \"https:\"]);\n\n/**\n * Validate that a base URL uses the `http:` or `https:` protocol.\n * Throws immediately at adapter creation time (not at call time) to surface\n * configuration errors before any LLM requests are made.\n *\n * @param baseURL - The base URL string to validate.\n * @throws When the URL is malformed or uses a protocol other than `http:` or `https:`.\n */\nexport function validateBaseURL(baseURL: string): void {\n try {\n const url = new URL(baseURL);\n if (!ALLOWED_PROTOCOLS.has(url.protocol)) {\n throw new Error(\n `[Directive] Invalid baseURL protocol \"${url.protocol}\" – only http: and https: are allowed`,\n );\n }\n } catch (err) {\n if (err instanceof Error && err.message.startsWith(\"[Directive]\")) {\n throw err;\n }\n\n throw new Error(\n `[Directive] Invalid baseURL \"${baseURL}\" – must be a valid URL (e.g. \"https://api.openai.com/v1\")`,\n );\n }\n}\n\n// ============================================================================\n// AbortSignal combination helper\n// ============================================================================\n\n/**\n * Combine multiple `AbortSignal`s into one — the resulting signal aborts\n * as soon as ANY input signal aborts. Falls back to a manual controller\n * wiring on runtimes without `AbortSignal.any` (Node < 20).\n *\n * @internal\n */\nexport function combineSignals(\n signals: ReadonlyArray<AbortSignal | undefined>,\n): AbortSignal | undefined {\n const live = signals.filter((s): s is AbortSignal => s !== undefined);\n if (live.length === 0) return undefined;\n if (live.length === 1) return live[0];\n\n // Prefer the standard helper when available (Node 20.3+, modern browsers).\n const anyFn = (\n AbortSignal as unknown as {\n any?: (signals: readonly AbortSignal[]) => AbortSignal;\n }\n ).any;\n if (typeof anyFn === \"function\") {\n return anyFn(live);\n }\n\n // Fallback: manual controller. If any input is already aborted, the\n // result is too — wire listeners for the rest.\n const controller = new AbortController();\n const already = live.find((s) => s.aborted);\n if (already) {\n controller.abort(\n (already as AbortSignal & { reason?: unknown }).reason ?? undefined,\n );\n\n return controller.signal;\n }\n for (const s of live) {\n s.addEventListener(\n \"abort\",\n () => {\n controller.abort(\n (s as AbortSignal & { reason?: unknown }).reason ?? undefined,\n );\n },\n { once: true },\n );\n }\n\n return controller.signal;\n}\n\n// ============================================================================\n// createRunner Helper\n// ============================================================================\n\n/** Parsed response from an LLM provider */\nexport interface ParsedResponse {\n text: string;\n totalTokens: number;\n /** Input token count, when available from the provider */\n inputTokens?: number;\n /** Output token count, when available from the provider */\n outputTokens?: number;\n}\n\n/** Options for creating an AgentRunner from buildRequest/parseResponse */\nexport interface CreateRunnerOptions {\n fetch?: typeof globalThis.fetch;\n buildRequest: (\n agent: AgentLike,\n input: string,\n messages: Message[],\n ) => { url: string; init: RequestInit };\n parseResponse: (\n response: Response,\n messages: Message[],\n ) => Promise<ParsedResponse>;\n parseOutput?: <T>(text: string) => T;\n /** Lifecycle hooks for tracing, logging, and metrics */\n hooks?: AdapterHooks;\n}\n\n/**\n * Create an {@link AgentRunner} from `buildRequest`/`parseResponse` helpers, reducing\n * ~50 lines of fetch boilerplate to ~20 lines of configuration.\n *\n * @remarks\n * Supports lifecycle hooks for observability:\n * - `onBeforeCall` fires before each API request\n * - `onAfterCall` fires after a successful response (includes token breakdown)\n * - `onError` fires when the request fails\n *\n * Output parsing defaults to `JSON.parse` with a string fallback. Supply a custom\n * `parseOutput` to override (e.g. for structured output schemas).\n *\n * @param options - Configuration for the runner, including request building, response parsing, and hooks.\n * @returns An {@link AgentRunner} function that performs LLM calls via fetch.\n *\n * @example\n * ```typescript\n * const runClaude = createRunner({\n * buildRequest: (agent, input) => ({\n * url: \"/api/claude\",\n * init: {\n * method: \"POST\",\n * headers: { \"Content-Type\": \"application/json\" },\n * body: JSON.stringify({\n * model: agent.model ?? \"claude-haiku-4-5-20251001\",\n * system: agent.instructions ?? \"\",\n * messages: [{ role: \"user\", content: input }],\n * }),\n * },\n * }),\n * parseResponse: async (res) => {\n * const data = await res.json();\n * const inputTokens = data.usage?.input_tokens ?? 0;\n * const outputTokens = data.usage?.output_tokens ?? 0;\n * return {\n * text: data.content?.[0]?.text ?? \"\",\n * totalTokens: inputTokens + outputTokens,\n * inputTokens,\n * outputTokens,\n * };\n * },\n * hooks: {\n * onAfterCall: ({ durationMs, tokenUsage }) => {\n * console.log(`LLM call: ${durationMs}ms, ${tokenUsage.inputTokens}in/${tokenUsage.outputTokens}out`);\n * },\n * },\n * });\n * ```\n *\n * @public\n */\nexport function createRunner(options: CreateRunnerOptions): AgentRunner {\n const {\n fetch: fetchFn = globalThis.fetch,\n buildRequest,\n parseResponse,\n parseOutput,\n hooks,\n } = options;\n\n const defaultParseOutput = <T>(text: string): T => {\n try {\n return JSON.parse(text) as T;\n } catch {\n return text as unknown as T;\n }\n };\n\n const parse = parseOutput ?? defaultParseOutput;\n\n return async <T = unknown>(\n agent: AgentLike,\n input: string,\n runOptions?: RunOptions,\n ): Promise<RunResult<T>> => {\n const startTime = Date.now();\n hooks?.onBeforeCall?.({ agent, input, timestamp: startTime });\n\n const messages: Message[] = [{ role: \"user\", content: input }];\n\n try {\n const { url, init } = buildRequest(agent, input, messages);\n\n // (Sec MAJOR) Combine signals — `buildRequest` may set\n // `init.signal` (e.g. `AbortSignal.timeout(timeoutMs)`) and the\n // caller may pass their own via `runOptions.signal`. Naively\n // overwriting one with the other silently disables whichever was\n // dropped. `combineSignals` aborts as soon as either fires.\n const combined = combineSignals([\n init.signal ?? undefined,\n runOptions?.signal,\n ]);\n const fetchInit: RequestInit = combined\n ? { ...init, signal: combined }\n : init;\n\n const response = await fetchFn(url, fetchInit);\n\n if (!response.ok) {\n const errBody = await response.text().catch(() => \"\");\n\n throw new Error(\n `[Directive] AgentRunner request failed: ${response.status} ${response.statusText}${errBody ? ` – ${errBody.slice(0, 300)}` : \"\"}`,\n );\n }\n\n const parsed = await parseResponse(response, messages);\n const tokenUsage: TokenUsage = {\n inputTokens: parsed.inputTokens ?? 0,\n outputTokens: parsed.outputTokens ?? 0,\n };\n\n const assistantMessage: Message = {\n role: \"assistant\",\n content: parsed.text,\n };\n const allMessages: Message[] = [...messages, assistantMessage];\n\n runOptions?.onMessage?.(assistantMessage);\n\n const durationMs = Date.now() - startTime;\n hooks?.onAfterCall?.({\n agent,\n input,\n output: parsed.text,\n totalTokens: parsed.totalTokens,\n tokenUsage,\n durationMs,\n timestamp: Date.now(),\n });\n\n return {\n output: parse<T>(parsed.text),\n messages: allMessages,\n toolCalls: [],\n totalTokens: parsed.totalTokens,\n tokenUsage,\n };\n } catch (err) {\n const durationMs = Date.now() - startTime;\n if (err instanceof Error) {\n hooks?.onError?.({\n agent,\n input,\n error: err,\n durationMs,\n timestamp: Date.now(),\n });\n }\n\n throw err;\n }\n };\n}\n"]}
@@ -0,0 +1,87 @@
1
+ import { Plugin } from '@directive-run/core';
2
+ import { l as DebugEvent, g as DebugEventType } from './types-DJ09LjZX.cjs';
3
+
4
+ /**
5
+ * Debug Timeline — AI-specific event log with snapshot correlation.
6
+ *
7
+ * Records agent lifecycle events (start, complete, error, guardrail checks,
8
+ * approvals, handoffs, patterns) and correlates them with core time-travel
9
+ * snapshots for visual timeline UIs and fork-and-replay debugging.
10
+ *
11
+ * Zero-cost when debug=false — the timeline is simply `null`.
12
+ *
13
+ * @module
14
+ */
15
+
16
+ /** Callback fired when a new event is recorded */
17
+ type DebugTimelineListener = (event: DebugEvent) => void;
18
+ /** Debug timeline instance */
19
+ interface DebugTimeline {
20
+ /** Record a new event (id is auto-assigned) */
21
+ record(event: Omit<DebugEvent, "id"> & Record<string, unknown>): DebugEvent;
22
+ /** Get all events in order */
23
+ getEvents(): DebugEvent[];
24
+ /** Get events for a specific agent */
25
+ getEventsForAgent(agentId: string): DebugEvent[];
26
+ /** Get events by type with type narrowing */
27
+ getEventsByType<T extends DebugEventType>(type: T): Extract<DebugEvent, {
28
+ type: T;
29
+ }>[];
30
+ /** Get events at a specific snapshot */
31
+ getEventsAtSnapshot(snapshotId: number): DebugEvent[];
32
+ /** Get events in a time range */
33
+ getEventsInRange(startMs: number, endMs: number): DebugEvent[];
34
+ /** Fork from a snapshot — truncates events after it and calls goTo */
35
+ forkFrom(snapshotId: number): void;
36
+ /** Export timeline as JSON */
37
+ export(): string;
38
+ /** Import timeline from JSON */
39
+ import(json: string): void;
40
+ /** Clear all events */
41
+ clear(): void;
42
+ /** Subscribe to new events. Returns unsubscribe function. */
43
+ subscribe(listener: DebugTimelineListener): () => void;
44
+ /** Current number of events */
45
+ readonly length: number;
46
+ }
47
+ /** Options for creating a debug timeline */
48
+ interface DebugTimelineOptions {
49
+ /** Maximum events before eviction. @default 2000 */
50
+ maxEvents?: number;
51
+ /** Callback to get current snapshot ID from the system */
52
+ getSnapshotId?: () => number | null;
53
+ /** Callback to navigate to a snapshot (for forkFrom) */
54
+ goToSnapshot?: (snapshotId: number) => void;
55
+ }
56
+ /**
57
+ * Create a debug timeline for recording and correlating AI events.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const timeline = createDebugTimeline({ maxEvents: 1000 });
62
+ *
63
+ * timeline.record({
64
+ * type: "agent_start",
65
+ * timestamp: Date.now(),
66
+ * agentId: "researcher",
67
+ * snapshotId: null,
68
+ * inputLength: 42,
69
+ * });
70
+ *
71
+ * const agentEvents = timeline.getEventsForAgent("researcher");
72
+ * ```
73
+ */
74
+ declare function createDebugTimeline(options?: DebugTimelineOptions): DebugTimeline;
75
+ /**
76
+ * Create a Directive plugin that bridges core constraint/resolver events
77
+ * to the debug timeline.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const timeline = createDebugTimeline();
82
+ * const plugin = createDebugTimelinePlugin(timeline, () => system.history?.currentIndex ?? null);
83
+ * ```
84
+ */
85
+ declare function createDebugTimelinePlugin(timeline: DebugTimeline, getSnapshotId: () => number | null): Plugin;
86
+
87
+ export { type DebugTimeline as D, type DebugTimelineListener as a, type DebugTimelineOptions as b, createDebugTimeline as c, createDebugTimelinePlugin as d };
@@ -0,0 +1,87 @@
1
+ import { Plugin } from '@directive-run/core';
2
+ import { l as DebugEvent, g as DebugEventType } from './types-DJ09LjZX.js';
3
+
4
+ /**
5
+ * Debug Timeline — AI-specific event log with snapshot correlation.
6
+ *
7
+ * Records agent lifecycle events (start, complete, error, guardrail checks,
8
+ * approvals, handoffs, patterns) and correlates them with core time-travel
9
+ * snapshots for visual timeline UIs and fork-and-replay debugging.
10
+ *
11
+ * Zero-cost when debug=false — the timeline is simply `null`.
12
+ *
13
+ * @module
14
+ */
15
+
16
+ /** Callback fired when a new event is recorded */
17
+ type DebugTimelineListener = (event: DebugEvent) => void;
18
+ /** Debug timeline instance */
19
+ interface DebugTimeline {
20
+ /** Record a new event (id is auto-assigned) */
21
+ record(event: Omit<DebugEvent, "id"> & Record<string, unknown>): DebugEvent;
22
+ /** Get all events in order */
23
+ getEvents(): DebugEvent[];
24
+ /** Get events for a specific agent */
25
+ getEventsForAgent(agentId: string): DebugEvent[];
26
+ /** Get events by type with type narrowing */
27
+ getEventsByType<T extends DebugEventType>(type: T): Extract<DebugEvent, {
28
+ type: T;
29
+ }>[];
30
+ /** Get events at a specific snapshot */
31
+ getEventsAtSnapshot(snapshotId: number): DebugEvent[];
32
+ /** Get events in a time range */
33
+ getEventsInRange(startMs: number, endMs: number): DebugEvent[];
34
+ /** Fork from a snapshot — truncates events after it and calls goTo */
35
+ forkFrom(snapshotId: number): void;
36
+ /** Export timeline as JSON */
37
+ export(): string;
38
+ /** Import timeline from JSON */
39
+ import(json: string): void;
40
+ /** Clear all events */
41
+ clear(): void;
42
+ /** Subscribe to new events. Returns unsubscribe function. */
43
+ subscribe(listener: DebugTimelineListener): () => void;
44
+ /** Current number of events */
45
+ readonly length: number;
46
+ }
47
+ /** Options for creating a debug timeline */
48
+ interface DebugTimelineOptions {
49
+ /** Maximum events before eviction. @default 2000 */
50
+ maxEvents?: number;
51
+ /** Callback to get current snapshot ID from the system */
52
+ getSnapshotId?: () => number | null;
53
+ /** Callback to navigate to a snapshot (for forkFrom) */
54
+ goToSnapshot?: (snapshotId: number) => void;
55
+ }
56
+ /**
57
+ * Create a debug timeline for recording and correlating AI events.
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * const timeline = createDebugTimeline({ maxEvents: 1000 });
62
+ *
63
+ * timeline.record({
64
+ * type: "agent_start",
65
+ * timestamp: Date.now(),
66
+ * agentId: "researcher",
67
+ * snapshotId: null,
68
+ * inputLength: 42,
69
+ * });
70
+ *
71
+ * const agentEvents = timeline.getEventsForAgent("researcher");
72
+ * ```
73
+ */
74
+ declare function createDebugTimeline(options?: DebugTimelineOptions): DebugTimeline;
75
+ /**
76
+ * Create a Directive plugin that bridges core constraint/resolver events
77
+ * to the debug timeline.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const timeline = createDebugTimeline();
82
+ * const plugin = createDebugTimelinePlugin(timeline, () => system.history?.currentIndex ?? null);
83
+ * ```
84
+ */
85
+ declare function createDebugTimelinePlugin(timeline: DebugTimeline, getSnapshotId: () => number | null): Plugin;
86
+
87
+ export { type DebugTimeline as D, type DebugTimelineListener as a, type DebugTimelineOptions as b, createDebugTimeline as c, createDebugTimelinePlugin as d };
@@ -0,0 +1,2 @@
1
+ 'use strict';var chunkIR3IHBVQ_cjs=require('./chunk-IR3IHBVQ.cjs'),chunkWOFIBIPW_cjs=require('./chunk-WOFIBIPW.cjs');Object.defineProperty(exports,"connectDevTools",{enumerable:true,get:function(){return chunkIR3IHBVQ_cjs.b}});Object.defineProperty(exports,"createDevToolsServer",{enumerable:true,get:function(){return chunkIR3IHBVQ_cjs.a}});Object.defineProperty(exports,"createWsTransport",{enumerable:true,get:function(){return chunkIR3IHBVQ_cjs.c}});Object.defineProperty(exports,"createDebugTimeline",{enumerable:true,get:function(){return chunkWOFIBIPW_cjs.a}});Object.defineProperty(exports,"createDebugTimelinePlugin",{enumerable:true,get:function(){return chunkWOFIBIPW_cjs.b}});Object.defineProperty(exports,"createHealthMonitor",{enumerable:true,get:function(){return chunkWOFIBIPW_cjs.c}});//# sourceMappingURL=devtools.cjs.map
2
+ //# sourceMappingURL=devtools.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"devtools.cjs"}