@warlock.js/ai 4.1.15 → 4.2.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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/cjs/index.cjs +88 -87
- package/cjs/index.cjs.map +1 -1
- package/esm/agent/agent-config.type.d.mts +1 -1
- package/esm/agent/agent-config.type.d.mts.map +1 -1
- package/esm/agent/agent-input-builder.mjs +1 -1
- package/esm/agent/agent-input-builder.mjs.map +1 -1
- package/esm/agent/agent-log-event.mjs +1 -1
- package/esm/agent/agent-log-event.mjs.map +1 -1
- package/esm/agent/agent-stream.d.mts +1 -1
- package/esm/agent/agent-stream.d.mts.map +1 -1
- package/esm/agent/agent-stream.mjs +1 -1
- package/esm/agent/agent-stream.mjs.map +1 -1
- package/esm/agent/agent-to-stream-event.mjs +1 -1
- package/esm/agent/agent-to-stream-event.mjs.map +1 -1
- package/esm/agent/agent.d.mts +1 -1
- package/esm/agent/agent.d.mts.map +1 -1
- package/esm/agent/agent.mjs +1 -1
- package/esm/agent/agent.mjs.map +1 -1
- package/esm/agent/json-stream-guard.mjs +1 -1
- package/esm/agent/json-stream-guard.mjs.map +1 -1
- package/esm/ai.d.mts +1 -1
- package/esm/ai.d.mts.map +1 -1
- package/esm/ai.mjs +1 -1
- package/esm/ai.mjs.map +1 -1
- package/esm/config.d.mts +1 -1
- package/esm/config.d.mts.map +1 -1
- package/esm/config.mjs +1 -1
- package/esm/config.mjs.map +1 -1
- package/esm/contracts/agent/agent-options.type.d.mts +1 -1
- package/esm/contracts/agent/agent-options.type.d.mts.map +1 -1
- package/esm/contracts/agent/agent.contract.d.mts +1 -1
- package/esm/contracts/agent/agent.contract.d.mts.map +1 -1
- package/esm/contracts/attachment.type.d.mts +1 -1
- package/esm/contracts/attachment.type.d.mts.map +1 -1
- package/esm/contracts/content-part.type.d.mts +1 -1
- package/esm/contracts/content-part.type.d.mts.map +1 -1
- package/esm/contracts/conversation-message.type.d.mts +1 -1
- package/esm/contracts/conversation-message.type.d.mts.map +1 -1
- package/esm/contracts/embedder.contract.d.mts +1 -1
- package/esm/contracts/embedder.contract.d.mts.map +1 -1
- package/esm/contracts/end.type.d.mts +1 -1
- package/esm/contracts/end.type.d.mts.map +1 -1
- package/esm/contracts/end.type.mjs +1 -1
- package/esm/contracts/end.type.mjs.map +1 -1
- package/esm/contracts/events/agent-events.type.d.mts +1 -1
- package/esm/contracts/events/agent-events.type.d.mts.map +1 -1
- package/esm/contracts/events/complete-event.type.d.mts +1 -1
- package/esm/contracts/events/complete-event.type.d.mts.map +1 -1
- package/esm/contracts/events/event-identity.type.d.mts +1 -1
- package/esm/contracts/events/event-identity.type.d.mts.map +1 -1
- package/esm/contracts/events/event-map.type.d.mts +1 -1
- package/esm/contracts/events/event-map.type.d.mts.map +1 -1
- package/esm/contracts/events/supervisor-events.type.d.mts +1 -1
- package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -1
- package/esm/contracts/events/usage-event.type.d.mts +1 -1
- package/esm/contracts/events/usage-event.type.d.mts.map +1 -1
- package/esm/contracts/events/workflow-events.type.d.mts +1 -1
- package/esm/contracts/events/workflow-events.type.d.mts.map +1 -1
- package/esm/contracts/executable.contract.d.mts +1 -1
- package/esm/contracts/executable.contract.d.mts.map +1 -1
- package/esm/contracts/finish-reason.type.d.mts +1 -1
- package/esm/contracts/finish-reason.type.d.mts.map +1 -1
- package/esm/contracts/middleware/middleware-context.type.d.mts +1 -1
- package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -1
- package/esm/contracts/middleware/middleware-state.type.d.mts +1 -1
- package/esm/contracts/middleware/middleware-state.type.d.mts.map +1 -1
- package/esm/contracts/middleware/middleware.contract.d.mts +1 -1
- package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -1
- package/esm/contracts/model-tool-call-request.type.d.mts +1 -1
- package/esm/contracts/model-tool-call-request.type.d.mts.map +1 -1
- package/esm/contracts/model.contract.d.mts +1 -1
- package/esm/contracts/model.contract.d.mts.map +1 -1
- package/esm/contracts/placeholders.type.d.mts +1 -1
- package/esm/contracts/placeholders.type.d.mts.map +1 -1
- package/esm/contracts/result/agent-result.type.d.mts +1 -1
- package/esm/contracts/result/agent-result.type.d.mts.map +1 -1
- package/esm/contracts/result/attempt-entry.type.d.mts +1 -1
- package/esm/contracts/result/attempt-entry.type.d.mts.map +1 -1
- package/esm/contracts/result/base-report.type.d.mts +1 -1
- package/esm/contracts/result/base-report.type.d.mts.map +1 -1
- package/esm/contracts/result/base-report.type.mjs +1 -1
- package/esm/contracts/result/base-report.type.mjs.map +1 -1
- package/esm/contracts/result/base-result.type.d.mts +1 -1
- package/esm/contracts/result/base-result.type.d.mts.map +1 -1
- package/esm/contracts/result/execute-result.type.d.mts +1 -1
- package/esm/contracts/result/execute-result.type.d.mts.map +1 -1
- package/esm/contracts/result/execution-report.type.d.mts +1 -1
- package/esm/contracts/result/execution-report.type.d.mts.map +1 -1
- package/esm/contracts/result/llm-trip.type.d.mts +1 -1
- package/esm/contracts/result/llm-trip.type.d.mts.map +1 -1
- package/esm/contracts/result/model-pricing.type.d.mts +1 -1
- package/esm/contracts/result/model-pricing.type.d.mts.map +1 -1
- package/esm/contracts/result/session-send-result.type.d.mts +1 -1
- package/esm/contracts/result/session-send-result.type.d.mts.map +1 -1
- package/esm/contracts/result/step-result.type.d.mts +1 -1
- package/esm/contracts/result/step-result.type.d.mts.map +1 -1
- package/esm/contracts/result/supervisor-result.type.d.mts +1 -1
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -1
- package/esm/contracts/result/tool-call.type.d.mts +1 -1
- package/esm/contracts/result/tool-call.type.d.mts.map +1 -1
- package/esm/contracts/result/usage.type.d.mts +1 -1
- package/esm/contracts/result/usage.type.d.mts.map +1 -1
- package/esm/contracts/result/workflow-result.type.d.mts +1 -1
- package/esm/contracts/result/workflow-result.type.d.mts.map +1 -1
- package/esm/contracts/sdk-adapter.contract.d.mts +1 -1
- package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -1
- package/esm/contracts/stream/stream-event.type.d.mts +1 -1
- package/esm/contracts/stream/stream-event.type.d.mts.map +1 -1
- package/esm/contracts/stream/stream.contract.d.mts +1 -1
- package/esm/contracts/stream/stream.contract.d.mts.map +1 -1
- package/esm/contracts/streaming-tool-guard-config.type.d.mts +1 -1
- package/esm/contracts/streaming-tool-guard-config.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/ack-entry.type.d.mts +1 -1
- package/esm/contracts/supervisor/ack-entry.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/classifier-context.type.d.mts +1 -1
- package/esm/contracts/supervisor/classifier-context.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/dispatch-context.type.d.mts +1 -1
- package/esm/contracts/supervisor/dispatch-context.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/evaluate-context.type.d.mts +1 -1
- package/esm/contracts/supervisor/evaluate-context.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/intent-entry.type.d.mts +1 -1
- package/esm/contracts/supervisor/intent-entry.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts +1 -1
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/next.type.d.mts +1 -1
- package/esm/contracts/supervisor/next.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/route-context.type.d.mts +1 -1
- package/esm/contracts/supervisor/route-context.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/router-entry.type.d.mts +1 -1
- package/esm/contracts/supervisor/router-entry.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-config.type.d.mts +1 -1
- package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts +1 -1
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-input.type.d.mts +1 -1
- package/esm/contracts/supervisor/supervisor-input.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +1 -1
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts +1 -1
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts.map +1 -1
- package/esm/contracts/supervisor/supervisor.contract.d.mts +1 -1
- package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -1
- package/esm/contracts/system-prompt.contract.d.mts +1 -1
- package/esm/contracts/system-prompt.contract.d.mts.map +1 -1
- package/esm/contracts/tool.contract.d.mts +1 -1
- package/esm/contracts/tool.contract.d.mts.map +1 -1
- package/esm/contracts/workflow/next-step-result.type.d.mts +1 -1
- package/esm/contracts/workflow/next-step-result.type.d.mts.map +1 -1
- package/esm/contracts/workflow/retry-config.type.d.mts +1 -1
- package/esm/contracts/workflow/retry-config.type.d.mts.map +1 -1
- package/esm/contracts/workflow/step.contract.d.mts +1 -1
- package/esm/contracts/workflow/step.contract.d.mts.map +1 -1
- package/esm/contracts/workflow/workflow-context.type.d.mts +1 -1
- package/esm/contracts/workflow/workflow-context.type.d.mts.map +1 -1
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts +1 -1
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts.map +1 -1
- package/esm/contracts/workflow/workflow.contract.d.mts +1 -1
- package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -1
- package/esm/errors/agent-cancelled-error.d.mts +1 -1
- package/esm/errors/agent-cancelled-error.d.mts.map +1 -1
- package/esm/errors/agent-cancelled-error.mjs +1 -1
- package/esm/errors/agent-cancelled-error.mjs.map +1 -1
- package/esm/errors/agent-execution-error.d.mts +1 -1
- package/esm/errors/agent-execution-error.d.mts.map +1 -1
- package/esm/errors/agent-execution-error.mjs +1 -1
- package/esm/errors/agent-execution-error.mjs.map +1 -1
- package/esm/errors/agent-max-trips-error.d.mts +1 -1
- package/esm/errors/agent-max-trips-error.d.mts.map +1 -1
- package/esm/errors/agent-max-trips-error.mjs +1 -1
- package/esm/errors/agent-max-trips-error.mjs.map +1 -1
- package/esm/errors/ai-error.d.mts +1 -1
- package/esm/errors/ai-error.d.mts.map +1 -1
- package/esm/errors/ai-error.mjs +1 -1
- package/esm/errors/ai-error.mjs.map +1 -1
- package/esm/errors/budget-exceeded-error.d.mts +1 -1
- package/esm/errors/budget-exceeded-error.d.mts.map +1 -1
- package/esm/errors/budget-exceeded-error.mjs +1 -1
- package/esm/errors/budget-exceeded-error.mjs.map +1 -1
- package/esm/errors/content-filter-error.d.mts +1 -1
- package/esm/errors/content-filter-error.d.mts.map +1 -1
- package/esm/errors/content-filter-error.mjs +1 -1
- package/esm/errors/content-filter-error.mjs.map +1 -1
- package/esm/errors/context-length-exceeded-error.d.mts +1 -1
- package/esm/errors/context-length-exceeded-error.d.mts.map +1 -1
- package/esm/errors/context-length-exceeded-error.mjs +1 -1
- package/esm/errors/context-length-exceeded-error.mjs.map +1 -1
- package/esm/errors/error-category.type.d.mts +1 -1
- package/esm/errors/error-category.type.d.mts.map +1 -1
- package/esm/errors/error-code.type.d.mts +1 -1
- package/esm/errors/error-code.type.d.mts.map +1 -1
- package/esm/errors/guardrail-violation-error.d.mts +1 -1
- package/esm/errors/guardrail-violation-error.d.mts.map +1 -1
- package/esm/errors/guardrail-violation-error.mjs +1 -1
- package/esm/errors/guardrail-violation-error.mjs.map +1 -1
- package/esm/errors/invalid-request-error.d.mts +1 -1
- package/esm/errors/invalid-request-error.d.mts.map +1 -1
- package/esm/errors/invalid-request-error.mjs +1 -1
- package/esm/errors/invalid-request-error.mjs.map +1 -1
- package/esm/errors/max-iterations-error.d.mts +1 -1
- package/esm/errors/max-iterations-error.d.mts.map +1 -1
- package/esm/errors/max-iterations-error.mjs +1 -1
- package/esm/errors/max-iterations-error.mjs.map +1 -1
- package/esm/errors/max-steps-exceeded-error.d.mts +1 -1
- package/esm/errors/max-steps-exceeded-error.d.mts.map +1 -1
- package/esm/errors/max-steps-exceeded-error.mjs +1 -1
- package/esm/errors/max-steps-exceeded-error.mjs.map +1 -1
- package/esm/errors/provider-auth-error.d.mts +1 -1
- package/esm/errors/provider-auth-error.d.mts.map +1 -1
- package/esm/errors/provider-auth-error.mjs +1 -1
- package/esm/errors/provider-auth-error.mjs.map +1 -1
- package/esm/errors/provider-error.d.mts +1 -1
- package/esm/errors/provider-error.d.mts.map +1 -1
- package/esm/errors/provider-error.mjs +1 -1
- package/esm/errors/provider-error.mjs.map +1 -1
- package/esm/errors/provider-rate-limit-error.d.mts +1 -1
- package/esm/errors/provider-rate-limit-error.d.mts.map +1 -1
- package/esm/errors/provider-rate-limit-error.mjs +1 -1
- package/esm/errors/provider-rate-limit-error.mjs.map +1 -1
- package/esm/errors/provider-timeout-error.d.mts +1 -1
- package/esm/errors/provider-timeout-error.d.mts.map +1 -1
- package/esm/errors/provider-timeout-error.mjs +1 -1
- package/esm/errors/provider-timeout-error.mjs.map +1 -1
- package/esm/errors/quota-exceeded-error.d.mts +1 -1
- package/esm/errors/quota-exceeded-error.d.mts.map +1 -1
- package/esm/errors/quota-exceeded-error.mjs +1 -1
- package/esm/errors/quota-exceeded-error.mjs.map +1 -1
- package/esm/errors/routing-error.d.mts +1 -1
- package/esm/errors/routing-error.d.mts.map +1 -1
- package/esm/errors/routing-error.mjs +1 -1
- package/esm/errors/routing-error.mjs.map +1 -1
- package/esm/errors/schema-validation-error.d.mts +1 -1
- package/esm/errors/schema-validation-error.d.mts.map +1 -1
- package/esm/errors/schema-validation-error.mjs +1 -1
- package/esm/errors/schema-validation-error.mjs.map +1 -1
- package/esm/errors/step-failed-error.d.mts +1 -1
- package/esm/errors/step-failed-error.d.mts.map +1 -1
- package/esm/errors/step-failed-error.mjs +1 -1
- package/esm/errors/step-failed-error.mjs.map +1 -1
- package/esm/errors/supervisor-cancelled-error.d.mts +1 -1
- package/esm/errors/supervisor-cancelled-error.d.mts.map +1 -1
- package/esm/errors/supervisor-cancelled-error.mjs +1 -1
- package/esm/errors/supervisor-cancelled-error.mjs.map +1 -1
- package/esm/errors/supervisor-drift-error.d.mts +1 -1
- package/esm/errors/supervisor-drift-error.d.mts.map +1 -1
- package/esm/errors/supervisor-drift-error.mjs +1 -1
- package/esm/errors/supervisor-drift-error.mjs.map +1 -1
- package/esm/errors/supervisor-failed-error.d.mts +1 -1
- package/esm/errors/supervisor-failed-error.d.mts.map +1 -1
- package/esm/errors/supervisor-failed-error.mjs +1 -1
- package/esm/errors/supervisor-failed-error.mjs.map +1 -1
- package/esm/errors/supervisor-routing-error.d.mts +1 -1
- package/esm/errors/supervisor-routing-error.d.mts.map +1 -1
- package/esm/errors/supervisor-routing-error.mjs +1 -1
- package/esm/errors/supervisor-routing-error.mjs.map +1 -1
- package/esm/errors/tool-execution-error.d.mts +1 -1
- package/esm/errors/tool-execution-error.d.mts.map +1 -1
- package/esm/errors/tool-execution-error.mjs +1 -1
- package/esm/errors/tool-execution-error.mjs.map +1 -1
- package/esm/errors/workflow-cancelled-error.d.mts +1 -1
- package/esm/errors/workflow-cancelled-error.d.mts.map +1 -1
- package/esm/errors/workflow-cancelled-error.mjs +1 -1
- package/esm/errors/workflow-cancelled-error.mjs.map +1 -1
- package/esm/errors/workflow-drift-error.d.mts +1 -1
- package/esm/errors/workflow-drift-error.d.mts.map +1 -1
- package/esm/errors/workflow-drift-error.mjs +1 -1
- package/esm/errors/workflow-drift-error.mjs.map +1 -1
- package/esm/errors/workflow-error.d.mts +1 -1
- package/esm/errors/workflow-error.d.mts.map +1 -1
- package/esm/errors/workflow-error.mjs +1 -1
- package/esm/errors/workflow-error.mjs.map +1 -1
- package/esm/middleware/builtins/budget.d.mts +1 -1
- package/esm/middleware/builtins/budget.d.mts.map +1 -1
- package/esm/middleware/builtins/budget.mjs +1 -1
- package/esm/middleware/builtins/budget.mjs.map +1 -1
- package/esm/middleware/builtins/guardrail.d.mts +1 -1
- package/esm/middleware/builtins/guardrail.d.mts.map +1 -1
- package/esm/middleware/builtins/guardrail.mjs +1 -1
- package/esm/middleware/builtins/guardrail.mjs.map +1 -1
- package/esm/middleware/builtins/semantic-cache.d.mts +1 -1
- package/esm/middleware/builtins/semantic-cache.d.mts.map +1 -1
- package/esm/middleware/builtins/semantic-cache.mjs +1 -1
- package/esm/middleware/builtins/semantic-cache.mjs.map +1 -1
- package/esm/middleware/helpers/compose.d.mts +1 -1
- package/esm/middleware/helpers/compose.d.mts.map +1 -1
- package/esm/middleware/helpers/compose.mjs +1 -1
- package/esm/middleware/helpers/compose.mjs.map +1 -1
- package/esm/middleware/helpers/for-tool.d.mts +1 -1
- package/esm/middleware/helpers/for-tool.d.mts.map +1 -1
- package/esm/middleware/helpers/for-tool.mjs +1 -1
- package/esm/middleware/helpers/for-tool.mjs.map +1 -1
- package/esm/middleware/pipeline.d.mts +1 -1
- package/esm/middleware/pipeline.d.mts.map +1 -1
- package/esm/middleware/pipeline.mjs +1 -1
- package/esm/middleware/pipeline.mjs.map +1 -1
- package/esm/middleware/utils/extract-user-text.d.mts +1 -1
- package/esm/middleware/utils/extract-user-text.d.mts.map +1 -1
- package/esm/middleware/utils/extract-user-text.mjs +1 -1
- package/esm/middleware/utils/extract-user-text.mjs.map +1 -1
- package/esm/middleware/utils/namespaced-state.d.mts +1 -1
- package/esm/middleware/utils/namespaced-state.d.mts.map +1 -1
- package/esm/middleware/utils/namespaced-state.mjs +1 -1
- package/esm/middleware/utils/namespaced-state.mjs.map +1 -1
- package/esm/mock/mock-agent.d.mts +1 -1
- package/esm/mock/mock-agent.d.mts.map +1 -1
- package/esm/mock/mock-agent.mjs +1 -1
- package/esm/mock/mock-agent.mjs.map +1 -1
- package/esm/mock/mock-config.type.d.mts +1 -1
- package/esm/mock/mock-config.type.d.mts.map +1 -1
- package/esm/mock/mock-model.d.mts +1 -1
- package/esm/mock/mock-model.d.mts.map +1 -1
- package/esm/mock/mock-model.mjs +1 -1
- package/esm/mock/mock-model.mjs.map +1 -1
- package/esm/mock/mock-sdk.d.mts +1 -1
- package/esm/mock/mock-sdk.d.mts.map +1 -1
- package/esm/mock/mock-sdk.mjs +1 -1
- package/esm/mock/mock-sdk.mjs.map +1 -1
- package/esm/supervisor/as-tool.d.mts +1 -1
- package/esm/supervisor/as-tool.d.mts.map +1 -1
- package/esm/supervisor/as-tool.mjs +1 -1
- package/esm/supervisor/as-tool.mjs.map +1 -1
- package/esm/supervisor/cancellation.d.mts +1 -1
- package/esm/supervisor/cancellation.d.mts.map +1 -1
- package/esm/supervisor/cancellation.mjs +1 -1
- package/esm/supervisor/cancellation.mjs.map +1 -1
- package/esm/supervisor/decide.mjs +1 -1
- package/esm/supervisor/decide.mjs.map +1 -1
- package/esm/supervisor/emitter.d.mts +1 -1
- package/esm/supervisor/emitter.d.mts.map +1 -1
- package/esm/supervisor/emitter.mjs +1 -1
- package/esm/supervisor/emitter.mjs.map +1 -1
- package/esm/supervisor/entries.d.mts +1 -1
- package/esm/supervisor/entries.d.mts.map +1 -1
- package/esm/supervisor/entries.mjs +1 -1
- package/esm/supervisor/entries.mjs.map +1 -1
- package/esm/supervisor/execution.d.mts +1 -1
- package/esm/supervisor/execution.d.mts.map +1 -1
- package/esm/supervisor/execution.mjs +1 -1
- package/esm/supervisor/execution.mjs.map +1 -1
- package/esm/supervisor/router-prompt.d.mts +1 -1
- package/esm/supervisor/router-prompt.d.mts.map +1 -1
- package/esm/supervisor/router-prompt.mjs +1 -1
- package/esm/supervisor/router-prompt.mjs.map +1 -1
- package/esm/supervisor/signature.d.mts +1 -1
- package/esm/supervisor/signature.d.mts.map +1 -1
- package/esm/supervisor/signature.mjs +1 -1
- package/esm/supervisor/signature.mjs.map +1 -1
- package/esm/supervisor/snapshot.d.mts +1 -1
- package/esm/supervisor/snapshot.d.mts.map +1 -1
- package/esm/supervisor/snapshot.mjs +1 -1
- package/esm/supervisor/snapshot.mjs.map +1 -1
- package/esm/supervisor/supervisor-stream.d.mts +1 -1
- package/esm/supervisor/supervisor-stream.d.mts.map +1 -1
- package/esm/supervisor/supervisor-stream.mjs +1 -1
- package/esm/supervisor/supervisor-stream.mjs.map +1 -1
- package/esm/supervisor/supervisor.d.mts +1 -1
- package/esm/supervisor/supervisor.d.mts.map +1 -1
- package/esm/supervisor/supervisor.mjs +1 -1
- package/esm/supervisor/supervisor.mjs.map +1 -1
- package/esm/system-prompt/instruction.d.mts +1 -1
- package/esm/system-prompt/instruction.d.mts.map +1 -1
- package/esm/system-prompt/instruction.mjs +1 -1
- package/esm/system-prompt/instruction.mjs.map +1 -1
- package/esm/system-prompt/persona.d.mts +1 -1
- package/esm/system-prompt/persona.d.mts.map +1 -1
- package/esm/system-prompt/persona.mjs +1 -1
- package/esm/system-prompt/persona.mjs.map +1 -1
- package/esm/system-prompt/render-placeholders.d.mts +1 -1
- package/esm/system-prompt/render-placeholders.d.mts.map +1 -1
- package/esm/system-prompt/render-placeholders.mjs +1 -1
- package/esm/system-prompt/render-placeholders.mjs.map +1 -1
- package/esm/system-prompt/system-prompt.d.mts +1 -1
- package/esm/system-prompt/system-prompt.d.mts.map +1 -1
- package/esm/system-prompt/system-prompt.mjs +1 -1
- package/esm/system-prompt/system-prompt.mjs.map +1 -1
- package/esm/tool/tool.d.mts +1 -1
- package/esm/tool/tool.d.mts.map +1 -1
- package/esm/tool/tool.mjs +3 -2
- package/esm/tool/tool.mjs.map +1 -1
- package/esm/utils/compute-cost.d.mts +1 -1
- package/esm/utils/compute-cost.d.mts.map +1 -1
- package/esm/utils/compute-cost.mjs +1 -1
- package/esm/utils/compute-cost.mjs.map +1 -1
- package/esm/utils/extract-json-payload.d.mts +1 -1
- package/esm/utils/extract-json-payload.d.mts.map +1 -1
- package/esm/utils/extract-json-payload.mjs +1 -1
- package/esm/utils/extract-json-payload.mjs.map +1 -1
- package/esm/utils/generate-run-id.d.mts +1 -1
- package/esm/utils/generate-run-id.d.mts.map +1 -1
- package/esm/utils/generate-run-id.mjs +1 -1
- package/esm/utils/generate-run-id.mjs.map +1 -1
- package/esm/utils/json-schema.d.mts +1 -1
- package/esm/utils/json-schema.d.mts.map +1 -1
- package/esm/utils/json-schema.mjs +1 -1
- package/esm/utils/json-schema.mjs.map +1 -1
- package/esm/utils/prepare-attachment-part.d.mts +1 -1
- package/esm/utils/prepare-attachment-part.d.mts.map +1 -1
- package/esm/utils/prepare-attachment-part.mjs +1 -1
- package/esm/utils/prepare-attachment-part.mjs.map +1 -1
- package/esm/utils/resolve-attachment.d.mts +1 -1
- package/esm/utils/resolve-attachment.d.mts.map +1 -1
- package/esm/utils/resolve-attachment.mjs +1 -1
- package/esm/utils/resolve-attachment.mjs.map +1 -1
- package/esm/utils/safe-json-parse.d.mts +1 -1
- package/esm/utils/safe-json-parse.d.mts.map +1 -1
- package/esm/utils/safe-json-parse.mjs +1 -1
- package/esm/utils/safe-json-parse.mjs.map +1 -1
- package/esm/utils/stamp-report-lineage.d.mts +1 -1
- package/esm/utils/stamp-report-lineage.d.mts.map +1 -1
- package/esm/utils/stamp-report-lineage.mjs +1 -1
- package/esm/utils/stamp-report-lineage.mjs.map +1 -1
- package/esm/utils/token-count.d.mts +1 -1
- package/esm/utils/token-count.d.mts.map +1 -1
- package/esm/utils/token-count.mjs +1 -1
- package/esm/utils/token-count.mjs.map +1 -1
- package/esm/workflow/as-tool.mjs +1 -1
- package/esm/workflow/as-tool.mjs.map +1 -1
- package/esm/workflow/cancellation.mjs +1 -1
- package/esm/workflow/cancellation.mjs.map +1 -1
- package/esm/workflow/emitter.mjs +1 -1
- package/esm/workflow/emitter.mjs.map +1 -1
- package/esm/workflow/engine.mjs +1 -1
- package/esm/workflow/engine.mjs.map +1 -1
- package/esm/workflow/retry.mjs +1 -1
- package/esm/workflow/retry.mjs.map +1 -1
- package/esm/workflow/router.mjs +1 -1
- package/esm/workflow/router.mjs.map +1 -1
- package/esm/workflow/run-scoped-emitter.mjs +1 -1
- package/esm/workflow/run-scoped-emitter.mjs.map +1 -1
- package/esm/workflow/signature.d.mts +1 -1
- package/esm/workflow/signature.d.mts.map +1 -1
- package/esm/workflow/signature.mjs +1 -1
- package/esm/workflow/signature.mjs.map +1 -1
- package/esm/workflow/snapshot.mjs +1 -1
- package/esm/workflow/snapshot.mjs.map +1 -1
- package/esm/workflow/state.mjs +1 -1
- package/esm/workflow/state.mjs.map +1 -1
- package/esm/workflow/step-runner.mjs +1 -1
- package/esm/workflow/step-runner.mjs.map +1 -1
- package/esm/workflow/step.d.mts +1 -1
- package/esm/workflow/step.d.mts.map +1 -1
- package/esm/workflow/step.mjs +1 -1
- package/esm/workflow/step.mjs.map +1 -1
- package/esm/workflow/workflow.d.mts +1 -1
- package/esm/workflow/workflow.d.mts.map +1 -1
- package/esm/workflow/workflow.mjs +1 -1
- package/esm/workflow/workflow.mjs.map +1 -1
- package/package.json +3 -3
|
@@ -9,7 +9,7 @@ import { CompleteEvent } from "../contracts/events/complete-event.type.mjs";
|
|
|
9
9
|
import { UsageEvent } from "../contracts/events/usage-event.type.mjs";
|
|
10
10
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
11
11
|
|
|
12
|
-
//#region
|
|
12
|
+
//#region ../@warlock.js/ai/src/agent/agent-config.type.d.ts
|
|
13
13
|
/**
|
|
14
14
|
* Map of factory-level event handlers. Every key is optional; handlers
|
|
15
15
|
* registered here fire on every `execute()` / `stream()` call made
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-config.type.d.mts","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"agent-config.type.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent-config.type.ts"],"mappings":";;;;;;;;;;;;;;;AAgBA;;KAAY,kBAAA,GAAqB,OAAA,eACnB,aAAA,IAAiB,OAAA,EAAS,aAAA,CAAc,CAAA;;;;;;;;;;;;AAAE;AA0BxD;;;;;;;;;;;KAAY,WAAA;EA0FW;;;;;;;;;;;;EA7ErB,IAAA;EAuBO;;;;;;;EAfP,WAAA;EA+BA;;;;;;;;;;;;EAlBA,OAAA,WAuEW;EArEX,KAAA,EAAO,aAAA;EAkFP;;;;EA7EA,YAAA,GAAe,oBAAA,WA6E+C;EA3E9D,KAAA,GAAQ,YAAA;EAER,YAAA,GAAe,YAAA;;;;;EAKf,QAAA;EAEA,YAAA,GAAe,gBAAA;;;;;;;;;EASf,MAAA,GAAS,gBAAA,CAAiB,OAAA;;;;;;EAM1B,EAAA,GAAK,kBAAA;;;;;;;;;;;;EAYL,UAAA,GAAa,eAAA;;;;;;;;;;;EAWb,kBAAA,GAAqB,wBAAA;;;;;;;;;;;;;;;EAerB,OAAA,IAAW,KAAA,EAAO,UAAA,YAAsB,OAAA;;;;;;;;;;;;;EAaxC,UAAA,IAAc,KAAA,EAAO,aAAA,CAAc,OAAA,aAAoB,OAAA;AAAA"}
|
|
@@ -4,7 +4,7 @@ import { extractJsonSchema } from "../utils/json-schema.mjs";
|
|
|
4
4
|
import { prepareAttachmentPart } from "../utils/prepare-attachment-part.mjs";
|
|
5
5
|
import "../utils/index.mjs";
|
|
6
6
|
|
|
7
|
-
//#region
|
|
7
|
+
//#region ../@warlock.js/ai/src/agent/agent-input-builder.ts
|
|
8
8
|
/**
|
|
9
9
|
* Assemble the seed conversation for an agent execution. Runs exactly
|
|
10
10
|
* once per run — subsequent trips append to the same message list.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-input-builder.mjs","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"agent-input-builder.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent-input-builder.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { AgentExecuteOptions } from \"../contracts/agent/agent-options.type\";\nimport type { Attachment } from \"../contracts/attachment.type\";\nimport type { ContentPart } from \"../contracts/content-part.type\";\nimport type { Message } from \"../contracts/conversation-message.type\";\nimport type { Placeholders } from \"../contracts/placeholders.type\";\nimport { InvalidRequestError } from \"../errors\";\nimport { extractJsonSchema, prepareAttachmentPart } from \"../utils\";\nimport type { AgentConfig } from \"./agent-config.type\";\n\n/**\n * Outcome of `buildAgentInputMessages` — the seeded message list and\n * the JSON Schema cached for every trip's\n * `ModelCallOptions.responseSchema`. `responseSchema` is `undefined`\n * when the caller didn't ask for structured output.\n */\nexport type AgentInputBuildResult = {\n messages: Message[];\n responseSchema?: Record<string, unknown>;\n};\n\n/**\n * Assemble the seed conversation for an agent execution. Runs exactly\n * once per run — subsequent trips append to the same message list.\n *\n * Responsibilities (previously three methods on `Execution`):\n * 1. Merge factory + per-call placeholders.\n * 2. Resolve the system prompt (string, contract, or absent).\n * 3. When an output schema is supplied:\n * - cache its JSON Schema form for `ModelCallOptions.responseSchema`\n * so native-structured-output providers enforce it at the token\n * level;\n * - fall back to a soft system-prompt instruction for providers\n * that don't advertise `structuredOutput` capability.\n * 4. Append caller-supplied `history` (e.g. session-level prior turns).\n * 5. Shape the user message — plain string in the common case,\n * multipart `ContentPart[]` when `attachments` are present. Image\n * attachments require model vision capability; mismatch throws\n * `InvalidRequestError` here rather than failing opaquely at the\n * provider.\n *\n * Extracted from the `Execution` class to isolate the declarative\n * input-shaping phase from the stateful trip loop.\n */\nexport async function buildAgentInputMessages<TOutput>(params: {\n config: AgentConfig<TOutput>;\n input: string;\n options?: AgentExecuteOptions<TOutput>;\n}): Promise<AgentInputBuildResult> {\n const { config, input, options } = params;\n\n const placeholders: Placeholders = {\n ...config.placeholders,\n ...options?.placeholders,\n };\n\n const systemPrompt = options?.systemPrompt ?? config.systemPrompt;\n let systemContent = \"\";\n\n if (typeof systemPrompt === \"string\") {\n systemContent = systemPrompt;\n } else if (systemPrompt) {\n systemContent = systemPrompt.resolve(placeholders);\n }\n\n const { responseSchema, instruction } = resolveStructuredOutput({\n outputSchema: options?.output ?? config.output,\n overrideResponseSchema: options?.responseSchema,\n modelSupportsStructuredOutput: Boolean(config.model.capabilities?.structuredOutput),\n });\n\n if (instruction) {\n systemContent = systemContent ? `${systemContent}\\n\\n${instruction}` : instruction;\n }\n\n const messages: Message[] = [];\n\n if (systemContent) {\n messages.push({ role: \"system\", content: systemContent });\n }\n\n if (options?.history) {\n messages.push(...options.history);\n }\n\n const userContent = await buildUserMessageContent({\n input,\n attachments: options?.attachments,\n modelName: config.model.name,\n modelSupportsVision: Boolean(config.model.capabilities?.vision),\n });\n\n messages.push({ role: \"user\", content: userContent });\n\n return { messages, responseSchema };\n}\n\n/**\n * Build the user message `content` field. Plain string when no\n * attachments (the hot path) — keeps wire payloads small. Multipart\n * `ContentPart[]` when attachments exist: input text first, resolved\n * parts in declaration order.\n */\nasync function buildUserMessageContent(params: {\n input: string;\n attachments?: Attachment[];\n modelName: string;\n modelSupportsVision: boolean;\n}): Promise<string | ContentPart[]> {\n const { input, attachments, modelName, modelSupportsVision } = params;\n\n if (!attachments || attachments.length === 0) {\n return input;\n }\n\n const parts: ContentPart[] = await Promise.all(\n attachments.map((attachment) => prepareAttachmentPart(attachment)),\n );\n\n const hasImage = parts.some((part) => part.type === \"image\");\n\n if (hasImage && !modelSupportsVision) {\n throw new InvalidRequestError(\n `Model \"${modelName}\" does not declare vision capability — image attachments are not supported`,\n { context: { modelName } },\n );\n }\n\n return [{ type: \"text\", text: input }, ...parts];\n}\n\n/**\n * When the caller supplied an `output` schema, resolve two artifacts:\n *\n * - `responseSchema` — extracted JSON Schema to attach on every trip.\n * Adapters that natively support structured output (OpenAI's\n * `response_format: json_schema`) consume it; others ignore it.\n * - `instruction` — a soft fallback appended to the system prompt\n * **only** for models without native structured-output capability.\n * Capable adapters skip it to save tokens and avoid redundancy.\n */\nfunction resolveStructuredOutput(params: {\n outputSchema?: StandardSchemaV1<unknown>;\n overrideResponseSchema?: Record<string, unknown>;\n modelSupportsStructuredOutput: boolean;\n}): {\n responseSchema?: Record<string, unknown>;\n instruction?: string;\n} {\n const { outputSchema, overrideResponseSchema, modelSupportsStructuredOutput } = params;\n\n if (!outputSchema) {\n return {};\n }\n\n const responseSchema = overrideResponseSchema ?? extractJsonSchema(outputSchema);\n\n if (modelSupportsStructuredOutput) {\n return { responseSchema };\n }\n\n const schemaHint = responseSchema\n ? `\\n\\nThe response MUST match this JSON Schema:\\n${JSON.stringify(responseSchema, null, 2)}`\n : \"\";\n\n const instruction = [\n \"You MUST respond with a single valid JSON value only.\",\n \"Do not wrap it in markdown code fences. Do not include prose, commentary, or explanation — JSON only.\",\n schemaHint,\n ]\n .join(\"\")\n .trim();\n\n return { responseSchema, instruction };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,eAAsB,wBAAiC,QAIpB;CACjC,MAAM,EAAE,QAAQ,OAAO,YAAY;CAEnC,MAAM,eAA6B;EACjC,GAAG,OAAO;EACV,GAAG,SAAS;CACd;CAEA,MAAM,eAAe,SAAS,gBAAgB,OAAO;CACrD,IAAI,gBAAgB;CAEpB,IAAI,OAAO,iBAAiB,UAC1B,gBAAgB;MACX,IAAI,cACT,gBAAgB,aAAa,QAAQ,YAAY;CAGnD,MAAM,EAAE,gBAAgB,gBAAgB,wBAAwB;EAC9D,cAAc,SAAS,UAAU,OAAO;EACxC,wBAAwB,SAAS;EACjC,+BAA+B,QAAQ,OAAO,MAAM,cAAc,gBAAgB;CACpF,CAAC;CAED,IAAI,aACF,gBAAgB,gBAAgB,GAAG,cAAc,MAAM,gBAAgB;CAGzE,MAAM,WAAsB,CAAC;CAE7B,IAAI,eACF,SAAS,KAAK;EAAE,MAAM;EAAU,SAAS;CAAc,CAAC;CAG1D,IAAI,SAAS,SACX,SAAS,KAAK,GAAG,QAAQ,OAAO;CAGlC,MAAM,cAAc,MAAM,wBAAwB;EAChD;EACA,aAAa,SAAS;EACtB,WAAW,OAAO,MAAM;EACxB,qBAAqB,QAAQ,OAAO,MAAM,cAAc,MAAM;CAChE,CAAC;CAED,SAAS,KAAK;EAAE,MAAM;EAAQ,SAAS;CAAY,CAAC;CAEpD,OAAO;EAAE;EAAU;CAAe;AACpC;;;;;;;AAQA,eAAe,wBAAwB,QAKH;CAClC,MAAM,EAAE,OAAO,aAAa,WAAW,wBAAwB;CAE/D,IAAI,CAAC,eAAe,YAAY,WAAW,GACzC,OAAO;CAGT,MAAM,QAAuB,MAAM,QAAQ,IACzC,YAAY,KAAK,eAAe,sBAAsB,UAAU,CAAC,CACnE;CAIA,IAFiB,MAAM,MAAM,SAAS,KAAK,SAAS,OAEzC,KAAK,CAAC,qBACf,MAAM,IAAI,oBACR,UAAU,UAAU,6EACpB,EAAE,SAAS,EAAE,UAAU,EAAE,CAC3B;CAGF,OAAO,CAAC;EAAE,MAAM;EAAQ,MAAM;CAAM,GAAG,GAAG,KAAK;AACjD;;;;;;;;;;;AAYA,SAAS,wBAAwB,QAO/B;CACA,MAAM,EAAE,cAAc,wBAAwB,kCAAkC;CAEhF,IAAI,CAAC,cACH,OAAO,CAAC;CAGV,MAAM,iBAAiB,0BAA0B,kBAAkB,YAAY;CAE/E,IAAI,+BACF,OAAO,EAAE,eAAe;CAe1B,OAAO;EAAE;EAAgB,aARL;GAClB;GACA;GANiB,iBACf,kDAAkD,KAAK,UAAU,gBAAgB,MAAM,CAAC,MACxF;EAMJ,CAAC,CACE,KAAK,EAAE,CAAC,CACR,KAEgC;CAAE;AACvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-log-event.mjs","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"agent-log-event.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent-log-event.ts"],"sourcesContent":["import type { Logger } from \"@warlock.js/logger\";\nimport type { AgentEventMap } from \"../contracts/events/event-map.type\";\nimport type { LLMTrip } from \"../contracts/result/llm-trip.type\";\nimport type { ToolCall } from \"../contracts/result/tool-call.type\";\nimport type { Usage } from \"../contracts/result/usage.type\";\n\n/**\n * Aggregate snapshot the agent-level log entries need at emission time\n * (agent completion + model name + running totals). Passed instead of\n * storing a back-reference to the Execution class — keeps this helper\n * a pure function.\n */\nexport type AgentLogContext = {\n /** Dotted logger module, e.g. `\"ai.agent.my-writer\"`. */\n module: string;\n /** Maximum trips configured for this run — logged once on `agent.starting`. */\n maxTrips: number;\n /** Model identifier — logged once on `agent.starting`. */\n modelName: string;\n /** Final running usage totals at the moment `agent.completed` fires. */\n totalUsage: Usage;\n /** Monotonic duration (ms) since start at the moment `agent.completed` fires. */\n totalDurationMs: number;\n /** All trips recorded so far — logged count on `agent.completed`. */\n trips: LLMTrip[];\n /** All tool calls recorded so far — logged count on `agent.completed`. */\n toolCalls: ToolCall[];\n};\n\n/**\n * Structured logging for agent lifecycle events. Mirrors\n * `Execution.emit`'s call sites without touching class state — the\n * caller passes the ambient snapshot in `ctx`, we route each event to\n * the right logger level and enrich with the per-event forensic\n * detail.\n *\n * Log-level convention:\n * - `info` — lifecycle boundaries (agent starting / completed) users\n * want to see at default verbosity\n * - `debug` — per-trip + per-tool progress (hot-path, opt-in)\n * - `success` — trip completion + tool success (terminal per-step state)\n * - `warn` — tool failures (recoverable, agent loop continues)\n * - `error` — agent-level terminal errors\n *\n * Streaming deltas (`agent.trip.streaming`) are intentionally skipped\n * to avoid token-granularity log spam.\n */\nexport function logAgentEvent<K extends keyof AgentEventMap>(\n logger: Logger,\n ctx: AgentLogContext,\n event: K,\n payload: AgentEventMap[K],\n): void {\n const action = event.replace(/^agent\\./, \"\");\n\n switch (event) {\n case \"agent.starting\": {\n const { input } = payload as AgentEventMap[\"agent.starting\"];\n logger.info(ctx.module, action, \"agent starting\", {\n maxTrips: ctx.maxTrips,\n model: ctx.modelName,\n inputLength: input.length,\n });\n return;\n }\n\n case \"agent.trip.started\": {\n const { tripIndex } = payload as AgentEventMap[\"agent.trip.started\"];\n logger.debug(ctx.module, action, \"trip started\", { tripIndex });\n return;\n }\n\n case \"agent.trip.streaming\": {\n // Deltas are too high-volume to log at token granularity.\n // Skipped on purpose; debug level still fires on trip boundaries.\n return;\n }\n\n case \"agent.trip.completed\": {\n const { trip } = payload as AgentEventMap[\"agent.trip.completed\"];\n logger.success(ctx.module, action, \"trip completed\", {\n tripIndex: trip.index,\n duration: trip.duration,\n usage: trip.usage,\n finishReason: trip.finishReason,\n });\n return;\n }\n\n case \"agent.tool.calling\": {\n const { tool, tripIndex } =\n payload as AgentEventMap[\"agent.tool.calling\"];\n logger.debug(ctx.module, action, `calling tool \"${tool.name}\"`, {\n tool: tool.name,\n action: tool.action,\n tripIndex,\n });\n return;\n }\n\n case \"agent.tool.called\": {\n const toolCall = payload as AgentEventMap[\"agent.tool.called\"];\n logger.success(ctx.module, action, `tool \"${toolCall.name}\" finished`, {\n tool: toolCall.name,\n duration: toolCall.duration,\n tripIndex: toolCall.tripIndex,\n });\n return;\n }\n\n case \"agent.tool.failed\": {\n const { tool, error, tripIndex } =\n payload as AgentEventMap[\"agent.tool.failed\"];\n\n logger.warn(ctx.module, action, `tool \"${tool.name}\" failed`, {\n tool: tool.name,\n tripIndex,\n error: {\n code: error.code,\n message: error.message,\n name: error.name,\n stack: error.stack,\n },\n });\n return;\n }\n\n case \"agent.completed\": {\n logger.info(ctx.module, action, \"agent completed\", {\n duration: ctx.totalDurationMs,\n usage: ctx.totalUsage,\n trips: ctx.trips.length,\n tools: ctx.toolCalls.length,\n });\n return;\n }\n\n case \"agent.error\": {\n const { error } = payload as AgentEventMap[\"agent.error\"];\n logger.error(ctx.module, action, error.message, {\n code: error.code,\n context: error.context,\n });\n return;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,cACd,QACA,KACA,OACA,SACM;CACN,MAAM,SAAS,MAAM,QAAQ,YAAY,EAAE;CAE3C,QAAQ,OAAR;EACE,KAAK,kBAAkB;GACrB,MAAM,EAAE,UAAU;GAClB,OAAO,KAAK,IAAI,QAAQ,QAAQ,kBAAkB;IAChD,UAAU,IAAI;IACd,OAAO,IAAI;IACX,aAAa,MAAM;GACrB,CAAC;GACD;EACF;EAEA,KAAK,sBAAsB;GACzB,MAAM,EAAE,cAAc;GACtB,OAAO,MAAM,IAAI,QAAQ,QAAQ,gBAAgB,EAAE,UAAU,CAAC;GAC9D;EACF;EAEA,KAAK,wBAGH;EAGF,KAAK,wBAAwB;GAC3B,MAAM,EAAE,SAAS;GACjB,OAAO,QAAQ,IAAI,QAAQ,QAAQ,kBAAkB;IACnD,WAAW,KAAK;IAChB,UAAU,KAAK;IACf,OAAO,KAAK;IACZ,cAAc,KAAK;GACrB,CAAC;GACD;EACF;EAEA,KAAK,sBAAsB;GACzB,MAAM,EAAE,MAAM,cACZ;GACF,OAAO,MAAM,IAAI,QAAQ,QAAQ,iBAAiB,KAAK,KAAK,IAAI;IAC9D,MAAM,KAAK;IACX,QAAQ,KAAK;IACb;GACF,CAAC;GACD;EACF;EAEA,KAAK,qBAAqB;GACxB,MAAM,WAAW;GACjB,OAAO,QAAQ,IAAI,QAAQ,QAAQ,SAAS,SAAS,KAAK,aAAa;IACrE,MAAM,SAAS;IACf,UAAU,SAAS;IACnB,WAAW,SAAS;GACtB,CAAC;GACD;EACF;EAEA,KAAK,qBAAqB;GACxB,MAAM,EAAE,MAAM,OAAO,cACnB;GAEF,OAAO,KAAK,IAAI,QAAQ,QAAQ,SAAS,KAAK,KAAK,WAAW;IAC5D,MAAM,KAAK;IACX;IACA,OAAO;KACL,MAAM,MAAM;KACZ,SAAS,MAAM;KACf,MAAM,MAAM;KACZ,OAAO,MAAM;IACf;GACF,CAAC;GACD;EACF;EAEA,KAAK;GACH,OAAO,KAAK,IAAI,QAAQ,QAAQ,mBAAmB;IACjD,UAAU,IAAI;IACd,OAAO,IAAI;IACX,OAAO,IAAI,MAAM;IACjB,OAAO,IAAI,UAAU;GACvB,CAAC;GACD;EAGF,KAAK,eAAe;GAClB,MAAM,EAAE,UAAU;GAClB,OAAO,MAAM,IAAI,QAAQ,QAAQ,MAAM,SAAS;IAC9C,MAAM,MAAM;IACZ,SAAS,MAAM;GACjB,CAAC;GACD;EACF;CACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StreamEvent } from "../contracts/stream/stream-event.type.mjs";
|
|
2
2
|
import { StreamContract } from "../contracts/stream/stream.contract.mjs";
|
|
3
|
-
//#region
|
|
3
|
+
//#region ../@warlock.js/ai/src/agent/agent-stream.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Internal async-queue `StreamContract` used by `agent().stream()`.
|
|
6
6
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-stream.d.mts","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"agent-stream.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent-stream.ts"],"mappings":";;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;AAGmB;AAQnB;;;;;;;;KAXY,gBAAA;EACV,IAAA,CAAK,KAAA,EAAO,WAAA;EACZ,GAAA,CAAI,MAAA,EAAQ,OAAA;EACZ,IAAA,CAAK,KAAA,EAAO,KAAA;AAAA;AAAA,iBAQE,iBAAA;EACd,UAAA,EAAY,gBAAA,CAAiB,OAAA;EAC7B,MAAA,EAAQ,cAAA,CAAe,OAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-stream.mjs","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"agent-stream.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent-stream.ts"],"sourcesContent":["import type { StreamContract, StreamEvent } from \"../contracts\";\n\n/**\n * Internal async-queue `StreamContract` used by `agent().stream()`.\n *\n * **Role.** The bridge between a streaming `Execution` (which runs in the\n * background, pushing events as they happen) and a consumer that reads\n * those events with `for await` or an `on(...)` handler map.\n *\n * **Responsibility.**\n * - Owns: the event queue, the pending-read promise chain, the terminal\n * `result` promise, and any user-registered event handlers.\n * - Does NOT own: any knowledge of agents, models, or tool calls — it is a\n * generic producer/consumer pipe parameterized by `TResult`. The streaming\n * execution writes via `push()` / `end()` / `fail()`; the consumer reads\n * via the AsyncIterable surface.\n *\n * Events are coalesced into a queue so that a consumer that starts\n * iterating late still sees every event in order — nothing is dropped. The\n * `on()` handlers fire the moment an event is pushed, independent of\n * whether anyone is iterating.\n *\n * @example\n * // Inside agent.stream():\n * const { controller, stream } = createAgentStream<AgentResult<TOutput>>();\n * new Execution(config, input, options, controller).run();\n * return stream;\n *\n * // Consumer:\n * for await (const event of stream) {\n * if (event.type === \"streaming\") process.stdout.write(event.delta);\n * }\n * const result = await stream.result;\n */\nexport type StreamController<TResult> = {\n push(event: StreamEvent): void;\n end(result: TResult): void;\n fail(error: Error): void;\n};\n\ntype PendingRead = {\n resolve(value: IteratorResult<StreamEvent>): void;\n reject(error: Error): void;\n};\n\nexport function createAgentStream<TResult>(): {\n controller: StreamController<TResult>;\n stream: StreamContract<TResult>;\n} {\n const queue: StreamEvent[] = [];\n const pending: PendingRead[] = [];\n const handlers = new Map<StreamEvent[\"type\"], (event: StreamEvent) => void>();\n\n let closed = false;\n let failure: Error | undefined;\n let resolveResult!: (value: TResult) => void;\n let rejectResult!: (error: Error) => void;\n\n const result = new Promise<TResult>((resolve, reject) => {\n resolveResult = resolve;\n rejectResult = reject;\n });\n\n const controller: StreamController<TResult> = {\n push(event) {\n const handler = handlers.get(event.type);\n\n if (handler) {\n try {\n handler(event);\n } catch {\n // User-provided stream handlers must never crash the agent.\n // Swallow — structured logging attaches here in Phase 0.5.\n }\n }\n\n const reader = pending.shift();\n\n if (reader) {\n reader.resolve({ value: event, done: false });\n return;\n }\n\n queue.push(event);\n },\n\n end(finalResult) {\n closed = true;\n resolveResult(finalResult);\n\n while (pending.length > 0) {\n const reader = pending.shift();\n\n reader?.resolve({ value: undefined, done: true });\n }\n },\n\n fail(error) {\n closed = true;\n failure = error;\n rejectResult(error);\n\n while (pending.length > 0) {\n const reader = pending.shift();\n\n reader?.reject(error);\n }\n },\n };\n\n const iterator: AsyncIterator<StreamEvent> = {\n next() {\n if (queue.length > 0) {\n return Promise.resolve({ value: queue.shift()!, done: false });\n }\n\n if (closed) {\n if (failure) {\n return Promise.reject(failure);\n }\n\n return Promise.resolve({ value: undefined, done: true });\n }\n\n return new Promise<IteratorResult<StreamEvent>>((resolve, reject) => {\n pending.push({ resolve, reject });\n });\n },\n };\n\n const stream: StreamContract<TResult> = {\n result,\n on(handlerMap) {\n for (const [key, handler] of Object.entries(handlerMap)) {\n if (handler) {\n handlers.set(\n key as StreamEvent[\"type\"],\n handler as (event: StreamEvent) => void,\n );\n }\n }\n\n return stream;\n },\n [Symbol.asyncIterator]() {\n return iterator;\n },\n };\n\n return { controller, stream };\n}\n"],"mappings":";AA6CA,SAAgB,oBAGd;CACA,MAAM,QAAuB,CAAC;CAC9B,MAAM,UAAyB,CAAC;CAChC,MAAM,2BAAW,IAAI,IAAuD;CAE5E,IAAI,SAAS;CACb,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,MAAM,SAAS,IAAI,SAAkB,SAAS,WAAW;EACvD,gBAAgB;EAChB,eAAe;CACjB,CAAC;CAED,MAAM,aAAwC;EAC5C,KAAK,OAAO;GACV,MAAM,UAAU,SAAS,IAAI,MAAM,IAAI;GAEvC,IAAI,SACF,IAAI;IACF,QAAQ,KAAK;GACf,QAAQ,CAGR;GAGF,MAAM,SAAS,QAAQ,MAAM;GAE7B,IAAI,QAAQ;IACV,OAAO,QAAQ;KAAE,OAAO;KAAO,MAAM;IAAM,CAAC;IAC5C;GACF;GAEA,MAAM,KAAK,KAAK;EAClB;EAEA,IAAI,aAAa;GACf,SAAS;GACT,cAAc,WAAW;GAEzB,OAAO,QAAQ,SAAS,GAGtB,AAFe,QAAQ,MAElB,CAAC,EAAE,QAAQ;IAAE,OAAO;IAAW,MAAM;GAAK,CAAC;EAEpD;EAEA,KAAK,OAAO;GACV,SAAS;GACT,UAAU;GACV,aAAa,KAAK;GAElB,OAAO,QAAQ,SAAS,GAGtB,AAFe,QAAQ,MAElB,CAAC,EAAE,OAAO,KAAK;EAExB;CACF;CAEA,MAAM,WAAuC,EAC3C,OAAO;EACL,IAAI,MAAM,SAAS,GACjB,OAAO,QAAQ,QAAQ;GAAE,OAAO,MAAM,MAAM;GAAI,MAAM;EAAM,CAAC;EAG/D,IAAI,QAAQ;GACV,IAAI,SACF,OAAO,QAAQ,OAAO,OAAO;GAG/B,OAAO,QAAQ,QAAQ;IAAE,OAAO;IAAW,MAAM;GAAK,CAAC;EACzD;EAEA,OAAO,IAAI,SAAsC,SAAS,WAAW;GACnE,QAAQ,KAAK;IAAE;IAAS;GAAO,CAAC;EAClC,CAAC;CACH,EACF;CAEA,MAAM,SAAkC;EACtC;EACA,GAAG,YAAY;GACb,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,UAAU,GACpD,IAAI,SACF,SAAS,IACP,KACA,OACF;GAIJ,OAAO;EACT;EACA,CAAC,OAAO,iBAAiB;GACvB,OAAO;EACT;CACF;CAEA,OAAO;EAAE;EAAY;CAAO;AAC9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region ../@warlock.js/ai/src/agent/agent-to-stream-event.ts
|
|
2
2
|
/**
|
|
3
3
|
* Map an internal `AgentEventMap` entry into the public `StreamEvent`
|
|
4
4
|
* shape. Event names are the same dot-notation strings on both sides;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-to-stream-event.mjs","names":["called"],"sources":["
|
|
1
|
+
{"version":3,"file":"agent-to-stream-event.mjs","names":["called"],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent-to-stream-event.ts"],"sourcesContent":["import type { AgentEventMap } from \"../contracts/events/event-map.type\";\nimport type { StreamEventBody } from \"../contracts/stream/stream-event.type\";\n\n/**\n * Map an internal `AgentEventMap` entry into the public `StreamEvent`\n * shape. Event names are the same dot-notation strings on both sides;\n * only the payload shape needs per-event translation — the notable\n * case is `agent.tool.called`, whose event-map payload is a bare\n * `ToolCall` but whose stream wrapper is `{ toolCall }`.\n *\n * Extracted from the `Execution` class in `agent.ts` because it's\n * fully stateless (pure function of event name + payload) and used\n * only from the stream-forwarding path. Keeps the class focused on\n * stateful orchestration.\n */\nexport function agentEventToStreamEvent<K extends keyof AgentEventMap>(\n event: K,\n payload: AgentEventMap[K],\n): StreamEventBody | undefined {\n switch (event) {\n case \"agent.starting\": {\n const { input } = payload as AgentEventMap[\"agent.starting\"];\n return { type: \"agent.starting\", input };\n }\n\n case \"agent.trip.started\": {\n const { tripIndex, input } =\n payload as AgentEventMap[\"agent.trip.started\"];\n return { type: \"agent.trip.started\", tripIndex, input };\n }\n\n case \"agent.trip.streaming\": {\n const { delta, tripIndex } =\n payload as AgentEventMap[\"agent.trip.streaming\"];\n return { type: \"agent.trip.streaming\", delta, tripIndex };\n }\n\n case \"agent.tool.calling\": {\n const { tool, input, tripIndex } =\n payload as AgentEventMap[\"agent.tool.calling\"];\n return { type: \"agent.tool.calling\", tool, input, tripIndex };\n }\n\n case \"agent.tool.called\": {\n const called = payload as AgentEventMap[\"agent.tool.called\"];\n // Split off the agent's enriched ToolCall record from the tool meta\n // so the stream event surface mirrors the bus payload shape.\n const { tool, ...toolCall } = called;\n return { type: \"agent.tool.called\", toolCall, tool };\n }\n\n case \"agent.tool.failed\": {\n const { tool, error, tripIndex } =\n payload as AgentEventMap[\"agent.tool.failed\"];\n return { type: \"agent.tool.failed\", tool, error, tripIndex };\n }\n\n case \"agent.trip.completed\": {\n const { trip } = payload as AgentEventMap[\"agent.trip.completed\"];\n return { type: \"agent.trip.completed\", trip };\n }\n\n case \"agent.completed\": {\n return { type: \"agent.completed\" };\n }\n\n case \"agent.error\": {\n const { error } = payload as AgentEventMap[\"agent.error\"];\n return { type: \"agent.error\", error };\n }\n\n default: {\n return undefined;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAgB,wBACd,OACA,SAC6B;CAC7B,QAAQ,OAAR;EACE,KAAK,kBAAkB;GACrB,MAAM,EAAE,UAAU;GAClB,OAAO;IAAE,MAAM;IAAkB;GAAM;EACzC;EAEA,KAAK,sBAAsB;GACzB,MAAM,EAAE,WAAW,UACjB;GACF,OAAO;IAAE,MAAM;IAAsB;IAAW;GAAM;EACxD;EAEA,KAAK,wBAAwB;GAC3B,MAAM,EAAE,OAAO,cACb;GACF,OAAO;IAAE,MAAM;IAAwB;IAAO;GAAU;EAC1D;EAEA,KAAK,sBAAsB;GACzB,MAAM,EAAE,MAAM,OAAO,cACnB;GACF,OAAO;IAAE,MAAM;IAAsB;IAAM;IAAO;GAAU;EAC9D;EAEA,KAAK,qBAAqB;GAIxB,MAAM,EAAE,MAAM,GAAG,aAAaA;GAC9B,OAAO;IAAE,MAAM;IAAqB;IAAU;GAAK;EACrD;EAEA,KAAK,qBAAqB;GACxB,MAAM,EAAE,MAAM,OAAO,cACnB;GACF,OAAO;IAAE,MAAM;IAAqB;IAAM;IAAO;GAAU;EAC7D;EAEA,KAAK,wBAAwB;GAC3B,MAAM,EAAE,SAAS;GACjB,OAAO;IAAE,MAAM;IAAwB;GAAK;EAC9C;EAEA,KAAK,mBACH,OAAO,EAAE,MAAM,kBAAkB;EAGnC,KAAK,eAAe;GAClB,MAAM,EAAE,UAAU;GAClB,OAAO;IAAE,MAAM;IAAe;GAAM;EACtC;EAEA,SACE;CAEJ;AACF"}
|
package/esm/agent/agent.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentContract } from "../contracts/agent/agent.contract.mjs";
|
|
2
2
|
import { AgentConfig } from "./agent-config.type.mjs";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/ai/src/agent/agent.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Creates an executable AI agent from the given configuration.
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.mts","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"agent.d.mts","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent.ts"],"mappings":";;;;;;;AAgLA;;;;;;;;;;;;;;;;AAA6F;;;;;;;;;;;iBAA7E,KAAA,oBAAyB,MAAA,EAAQ,WAAA,CAAY,OAAA,IAAW,aAAA,CAAc,OAAA"}
|
package/esm/agent/agent.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { agentEventToStreamEvent } from "./agent-to-stream-event.mjs";
|
|
|
19
19
|
import { JsonStreamGuard } from "./json-stream-guard.mjs";
|
|
20
20
|
import { log } from "@warlock.js/logger";
|
|
21
21
|
|
|
22
|
-
//#region
|
|
22
|
+
//#region ../@warlock.js/ai/src/agent/agent.ts
|
|
23
23
|
const LOG_MODULE = "ai.agent";
|
|
24
24
|
/**
|
|
25
25
|
* Detect abort-flavored errors surfaced by SDK HTTP layers — the
|
package/esm/agent/agent.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/agent/agent.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport type {\n AgentContract,\n AgentEventHandler,\n AgentEventMap,\n AgentExecuteOptions,\n AgentResult,\n BaseReport,\n CompleteEvent,\n FinishReason,\n LLMTrip,\n Message,\n MiddlewareExecuteContext,\n MiddlewareState,\n MiddlewareToolContext,\n MiddlewareTripContext,\n ModelResponse,\n ModelToolCallRequest,\n StreamContract,\n StreamEventBody,\n StreamingToolGuardConfig,\n ToolCall,\n ToolEventMeta,\n Usage,\n UsageEvent,\n WithoutIdentity,\n} from \"../contracts\";\nimport {\n AgentCancelledError,\n AgentExecutionError,\n AgentMaxTripsError,\n AIError,\n SchemaValidationError,\n} from \"../errors\";\nimport { runPipeline } from \"../middleware\";\nimport type { ToolContract, ToolInvokeResult } from \"../tool/tool\";\nimport {\n accumulateCost,\n computeCost,\n extractJsonPayload,\n generateRunId,\n safeJsonParse,\n stampReportLineage,\n} from \"../utils\";\nimport type { AgentConfig } from \"./agent-config.type\";\nimport { buildAgentInputMessages } from \"./agent-input-builder\";\nimport { logAgentEvent } from \"./agent-log-event\";\nimport { createAgentStream, type StreamController } from \"./agent-stream\";\nimport { agentEventToStreamEvent } from \"./agent-to-stream-event\";\nimport { JsonStreamGuard } from \"./json-stream-guard\";\n\nconst LOG_MODULE = \"ai.agent\";\n\n/**\n * Detect abort-flavored errors surfaced by SDK HTTP layers — the\n * DOM `AbortError`, axios `ERR_CANCELED`, node-fetch's own\n * `AbortError`. Used to classify them as cancellation rather than\n * generic agent-execution failures.\n */\nfunction isAbortLike(err: unknown): boolean {\n if (!err || typeof err !== \"object\") return false;\n\n const e = err as { name?: unknown; code?: unknown };\n\n return e.name === \"AbortError\" || e.code === \"ERR_CANCELED\" || e.code === \"ABORT_ERR\";\n}\n\n/**\n * Readable synthetic name for agents constructed without an explicit\n * `name`. Format: `anon_<provider>_<model>[_<tool1>+<tool2>+...]` —\n * deterministic (same config → same name across restarts) and\n * human-readable in logs / workflow snapshots.\n *\n * Keeps drift detection honest for the `ai.agent({ model })`\n * one-liner without punishing it with a hashed id nobody can read.\n */\nfunction synthesizeAgentName<T>(config: AgentConfig<T>): string {\n const provider = (config.model as unknown as { provider?: string })?.provider ?? \"unknown\";\n const model = config.model?.name ?? \"unknown\";\n const tools = (config.tools ?? [])\n .map((tool) => tool.name)\n .sort()\n .join(\"+\");\n\n const base = `anon_${sanitize(provider)}_${sanitize(model)}`;\n return tools ? `${base}_${sanitize(tools, { keepPlus: true })}` : base;\n}\n\nfunction sanitize(value: string, opts: { keepPlus?: boolean } = {}): string {\n const allowed = opts.keepPlus ? /[^a-zA-Z0-9._+-]/g : /[^a-zA-Z0-9._-]/g;\n return value.replace(allowed, \"-\");\n}\n\n/**\n * Authoring-time check on the middleware array. Throws an\n * `AgentExecutionError` with `context: { authoring: true }` the\n * moment an invalid entry is found — the agent factory surface is\n * where config bugs should surface, not ten trips into a run.\n *\n * Validates:\n * - Every entry is a non-null object with a non-empty string `name`.\n * - No two entries share the same `name` (would silently collide on\n * `ctx.state` keys and produce impossible-to-debug behavior).\n *\n * Does NOT validate that hook maps contain callable functions —\n * that would catch late-binding bugs but also reject legitimate\n * patterns like `before` being conditionally `undefined`. Runtime\n * dispatch handles missing hooks safely.\n */\nfunction validateMiddleware(middleware: ReadonlyArray<unknown> | undefined): void {\n if (!middleware || middleware.length === 0) {\n return;\n }\n\n const seen = new Set<string>();\n\n for (let index = 0; index < middleware.length; index++) {\n const entry = middleware[index];\n\n if (!entry || typeof entry !== \"object\") {\n throw new AgentExecutionError(\n `middleware[${index}] must be an object; received ${entry === null ? \"null\" : typeof entry}`,\n { context: { authoring: true, index } },\n );\n }\n\n const name = (entry as { name?: unknown }).name;\n\n if (typeof name !== \"string\" || name.length === 0) {\n throw new AgentExecutionError(`middleware[${index}] must have a non-empty string \"name\"`, {\n context: { authoring: true, index },\n });\n }\n\n if (seen.has(name)) {\n throw new AgentExecutionError(\n `duplicate middleware name \"${name}\" — each middleware needs a unique name so ctx.state keys do not collide`,\n { context: { authoring: true, index, name } },\n );\n }\n\n seen.add(name);\n }\n}\n\n/**\n * Creates an executable AI agent from the given configuration.\n *\n * The agent runs a bounded trip loop: each trip calls the model, dispatches\n * any requested tool calls, then loops until the model stops or `maxTrips`\n * is reached. Each `execute()` / `stream()` call spawns a fresh internal\n * `Execution` instance — the factory itself holds no state across calls.\n *\n * `execute()` never throws — any error is attached to the returned result\n * under `result.error`. `stream()` surfaces errors both on the terminal\n * `error` stream event and via the `stream.result` promise.\n *\n * @example\n * const myAgent = agent({\n * model: openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: \"You are a helpful assistant.\",\n * tools: [searchTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the capital of Egypt?\");\n *\n * @example\n * const stream = myAgent.stream(\"Write a haiku about Cairo.\");\n *\n * for await (const event of stream) {\n * if (event.type === \"streaming\") process.stdout.write(event.delta);\n * }\n *\n * const result = await stream.result;\n */\nexport function agent<TOutput = unknown>(config: AgentConfig<TOutput>): AgentContract<TOutput> {\n // Authoring-time validation of the middleware array. Rejects two\n // classes of bug that would otherwise surface as opaque failures\n // mid-execution: (a) entries that aren't proper middleware\n // objects (null, undefined, missing `name`), and (b) two\n // middlewares sharing the same `name`, which would silently\n // collide on `ctx.state` keys. Fail fast, fail loud — per the\n // authoring-time rules in `domains/ai/conventions/errors.md`.\n validateMiddleware(config.middleware);\n\n // Resolve the agent's identity. Explicit `name` wins; otherwise we\n // synthesize a DETERMINISTIC fingerprint from the config's\n // identity-defining fields (model + provider + tool names). Same\n // config across process restarts produces the same synthetic name,\n // so workflow signature drift detection stays honest for agents\n // composed into workflows without explicit names.\n const isAnonymous = !config.name || typeof config.name !== \"string\";\n const name = isAnonymous ? synthesizeAgentName(config) : (config.name as string);\n const resolvedConfig: AgentConfig<TOutput> = { ...config, name };\n\n // Instance-level handlers registered via `.on()`. Stored here\n // (factory-scope) so every `execute()` / `stream()` call on this\n // agent sees the same set. Each event name gets its own Set so\n // `off()` can remove a specific handler without disturbing others.\n const instanceHandlers = new Map<\n keyof AgentEventMap,\n Set<AgentEventHandler<keyof AgentEventMap>>\n >();\n\n function on<K extends keyof AgentEventMap>(event: K, handler: AgentEventHandler<K>): () => void {\n const existing = instanceHandlers.get(event);\n const bucket = existing ?? new Set<AgentEventHandler<keyof AgentEventMap>>();\n\n if (!existing) {\n instanceHandlers.set(event, bucket);\n }\n\n bucket.add(handler as AgentEventHandler<keyof AgentEventMap>);\n\n return () => off(event, handler);\n }\n\n function off<K extends keyof AgentEventMap>(event: K, handler: AgentEventHandler<K>): void {\n const bucket = instanceHandlers.get(event);\n\n if (!bucket) {\n return;\n }\n\n bucket.delete(handler as AgentEventHandler<keyof AgentEventMap>);\n\n if (bucket.size === 0) {\n instanceHandlers.delete(event);\n }\n }\n\n return {\n name,\n isAnonymous,\n description: config.description,\n async execute(\n input: string,\n options?: AgentExecuteOptions<TOutput>,\n ): Promise<AgentResult<TOutput>> {\n return new Execution<TOutput>(\n resolvedConfig,\n input,\n options,\n undefined,\n instanceHandlers,\n ).run();\n },\n\n stream(\n input: string,\n options?: AgentExecuteOptions<TOutput>,\n ): StreamContract<AgentResult<TOutput>> {\n const { controller, stream } = createAgentStream<AgentResult<TOutput>>();\n\n const execution = new Execution<TOutput>(\n resolvedConfig,\n input,\n options,\n controller,\n instanceHandlers,\n );\n\n void execution.run();\n\n return stream;\n },\n\n on,\n off,\n };\n}\n\n/**\n * Name → handler-set map shared between the `agent()` factory and its\n * per-call `Execution`. Each `.on()` registration mutates this map;\n * every `Execution` reads from the same reference so additions and\n * removals take effect mid-flight.\n */\ntype InstanceHandlerMap = Map<keyof AgentEventMap, Set<AgentEventHandler<keyof AgentEventMap>>>;\n\n/**\n * Per-call driver that owns the full lifecycle of a single\n * `agent.execute()` or `agent.stream()` invocation.\n *\n * **Role.** An `Execution` is the short-lived state container and phase\n * orchestrator for one agent run. The public `agent()` factory stays purely\n * functional — all mutable bookkeeping (trips, tool calls, usage totals,\n * message history, terminal error, parsed output) lives here so each call\n * gets a fresh, isolated instance.\n *\n * **Responsibility.**\n * - Owns: building the initial message list, driving the bounded trip loop,\n * dispatching tool calls safely, parsing the final output against the\n * caller's schema, emitting lifecycle events (to both the user handler\n * and, in stream mode, the `StreamController`), and producing the\n * `AgentResult`.\n * - Does NOT own: how the model produces responses (delegated to\n * `ModelContract.complete` / `ModelContract.stream`), how tools execute\n * (delegated to `ToolContract.invoke`), the async-queue plumbing for\n * streaming (delegated to `createAgentStream`), or any cross-call state\n * (factory-level concerns live in `agent()`).\n *\n * Streaming mode is opt-in via the fourth constructor argument: pass a\n * `StreamController` and every event is mirrored into it while model calls\n * are driven via `model.stream()` instead of `model.complete()`. The public\n * contract of `execute()` says it never throws — `Execution` enforces that\n * by funneling every unexpected error into `this.error` and returning a\n * well-formed result regardless of what went wrong.\n *\n * Not exported — consumers interact only with the `agent()` factory (see\n * §4.2 of code-style.md — \"per-call execution state across phases\").\n *\n * @example\n * // Non-streaming — inside agent.execute():\n * const result = await new Execution(config, input, options).run();\n *\n * @example\n * // Streaming — inside agent.stream():\n * const { controller, stream } = createAgentStream();\n * void new Execution(config, input, options, controller).run();\n * return stream;\n */\nclass Execution<TOutput> {\n private readonly trips: LLMTrip[] = [];\n private readonly toolCalls: ToolCall[] = [];\n private readonly usage: Usage = { input: 0, output: 0, total: 0 };\n private readonly messages: Message[] = [];\n private readonly maxTrips: number;\n private readonly startedAt = new Date();\n private readonly start = performance.now();\n private readonly runId = generateRunId(\"agent\");\n private readonly logger: Logger = log;\n private readonly middleware: ReadonlyArray<\n NonNullable<AgentConfig<TOutput>[\"middleware\"]>[number]\n >;\n private readonly middlewareState: MiddlewareState = new Map();\n\n private error?: AIError;\n private data?: TOutput;\n private responseSchema?: Record<string, unknown>;\n\n public constructor(\n private readonly config: AgentConfig<TOutput>,\n private readonly input: string,\n private readonly options?: AgentExecuteOptions<TOutput>,\n private readonly streamController?: StreamController<AgentResult<TOutput>>,\n private readonly instanceHandlers?: InstanceHandlerMap,\n ) {\n this.maxTrips = config.maxTrips ?? 10;\n this.middleware = config.middleware ?? [];\n }\n\n /**\n * Base middleware context shared by every level. `state` is the\n * single mutable bag threaded through `execute`, `trip`, and `tool`\n * hooks for the lifetime of this execution — fresh per `execute()`\n * call, never reused across runs.\n */\n private buildExecuteContext(): MiddlewareExecuteContext {\n return {\n agent: {\n name: this.config.name ?? this.config.model.name,\n isAnonymous: !this.config.name,\n },\n model: {\n name: this.config.model.name,\n provider: this.config.model.provider,\n },\n input: this.input,\n options: this.options as AgentExecuteOptions<unknown> | undefined,\n state: this.middlewareState,\n signal: this.options?.signal,\n };\n }\n\n /**\n * Entry point for a single agent execution. Wraps the real work\n * (`runCore`) in the `execute`-level middleware pipeline, then\n * emits the terminal `agent.completed` / `agent.error` events and\n * closes the stream (if any) with the post-pipeline result — so\n * middleware that short-circuits or transforms the final result\n * still produces a well-formed public outcome.\n *\n * Must never throw: any error that escapes the pipeline is\n * converted into an `AgentResult` with `error` populated before\n * returning, preserving the `agent.execute()` public contract.\n */\n public async run(): Promise<AgentResult<TOutput>> {\n const context = this.buildExecuteContext();\n\n let result: AgentResult<TOutput>;\n\n try {\n result = (await runPipeline(\n this.middleware,\n \"execute\",\n context,\n () => this.runCore(),\n this.logger,\n )) as AgentResult<TOutput>;\n } catch (thrown) {\n this.error = this.toAIError(thrown);\n result = this.buildResult();\n }\n\n if (result.error) {\n this.emit(\"agent.error\", { error: result.error });\n }\n\n this.emit(\"agent.completed\", { result });\n\n // Fire the `onComplete` hook with a flat payload (runId +\n // durationMs pre-extracted) for audit-log consumers. Awaited but\n // errors swallowed so consumer bugs cannot crash the agent or\n // interfere with the result returned to the caller.\n await this.fireCompleteHook(result);\n\n this.streamController?.end(result);\n\n return result;\n }\n\n /**\n * Inner body wrapped by the `execute`-level pipeline. Drives the\n * full lifecycle — build messages → emit starting → run trip loop\n * → parse output → build result. Catches any unexpected throw and\n * funnels it into `this.error` so the returned result is always\n * well-formed; `execute`-level `after` hooks receive the result,\n * with `error` populated when things went wrong.\n */\n private async runCore(): Promise<AgentResult<TOutput>> {\n try {\n await this.buildInitialMessages();\n\n this.emit(\"agent.starting\", { input: this.input });\n\n await this.runTripLoop();\n\n const parseOutcome = await this.parseOutput();\n\n if (parseOutcome === \"failed\" && this.options?.repair) {\n await this.runRepairLoop();\n }\n } catch (thrown) {\n this.error = this.toAIError(thrown);\n }\n\n return this.buildResult();\n }\n\n /**\n * Resolve the system prompt (string or `SystemPromptContract`), merge\n * placeholders from config + execute options, inject a structured-output\n * instruction when the caller wants typed output but the model can't\n * enforce it natively, prepend any conversation history, and append the\n * user input. Produces the initial `messages` array the first trip sends\n * to the model. Runs exactly once per execution.\n */\n private async buildInitialMessages(): Promise<void> {\n const { messages, responseSchema } = await buildAgentInputMessages({\n config: this.config,\n input: this.input,\n options: this.options,\n });\n this.messages.push(...messages);\n this.responseSchema = responseSchema;\n }\n\n /**\n * Drive sequential trips up to `maxTrips`. Each trip may stop the loop\n * naturally (model returned a non-tool-call finish), abort it (model\n * threw), or continue it (model requested tools). When the loop exits\n * after the cap without a natural stop, records a \"Max trips exceeded\"\n * error so the caller can distinguish runaway tool loops from a real result.\n */\n private async runTripLoop(): Promise<void> {\n for (let tripIndex = 0; tripIndex < this.maxTrips; tripIndex++) {\n if (this.options?.signal?.aborted) {\n this.error = this.makeCancelledError();\n return;\n }\n\n const tripInput = tripIndex === 0 ? this.input : \"[tool results]\";\n const outcome = await this.runTrip(tripIndex, tripInput);\n\n if (outcome === \"error\" || outcome === \"stop\") {\n return;\n }\n }\n\n const lastTrip = this.trips[this.trips.length - 1];\n\n if (lastTrip?.finishReason === \"tool_calls\") {\n this.error = new AgentMaxTripsError(\"Max trips exceeded\", {\n maxTrips: this.maxTrips,\n });\n }\n }\n\n /**\n * Execute one round-trip to the model. Aggregates usage into the running\n * total, dispatches any requested tool calls, appends the assistant +\n * tool-result messages for the next trip, and records an `LLMTrip`.\n * Returns an outcome that tells `runTripLoop` whether to continue, stop,\n * or abort.\n */\n private async runTrip(\n tripIndex: number,\n tripInput: string,\n ): Promise<\"continue\" | \"stop\" | \"error\"> {\n this.emit(\"agent.trip.started\", { tripIndex, input: tripInput });\n\n const tripStartedAt = new Date();\n const tripStart = performance.now();\n\n let response: ModelResponse;\n\n try {\n response = await this.runTripThroughPipeline(tripIndex);\n } catch (thrown) {\n this.error = this.toAIError(thrown);\n\n const failedTrip: LLMTrip = {\n index: tripIndex,\n input: tripInput,\n output: \"\",\n finishReason: \"error\",\n startedAt: tripStartedAt.toISOString(),\n endedAt: new Date().toISOString(),\n duration: performance.now() - tripStart,\n usage: { input: 0, output: 0, total: 0 },\n error: this.error,\n };\n\n this.trips.push(failedTrip);\n\n this.emit(\"agent.trip.completed\", { trip: failedTrip });\n this.emit(\"agent.error\", { error: this.error });\n\n return \"error\";\n }\n\n // Attach per-trip cost breakdown using the model's pricing table\n // (when configured). Done at the framework boundary so stored trip\n // records carry historical cost — Panoptic and other archive\n // consumers never re-derive against today's pricing, and the\n // input/output/cached split stays queryable without joining to a\n // pricing table at all.\n if (response.usage.cost === undefined) {\n response.usage.cost = computeCost(response.usage, this.config.model.pricing);\n }\n\n this.usage.input += response.usage.input;\n this.usage.output += response.usage.output;\n this.usage.total += response.usage.total;\n if (response.usage.cachedTokens !== undefined) {\n this.usage.cachedTokens = (this.usage.cachedTokens ?? 0) + response.usage.cachedTokens;\n }\n this.usage.cost = accumulateCost(this.usage.cost, response.usage.cost);\n\n // Fire the `onUsage` hook with a flat, pre-packaged payload so\n // cost-ledger code receives stable identity (runId, model+provider)\n // without joining from elsewhere. Awaited but errors swallowed.\n await this.fireUsageHook(tripIndex, response.usage);\n\n const isToolCallTrip =\n response.finishReason === \"tool_calls\" &&\n response.toolCalls !== undefined &&\n response.toolCalls.length > 0;\n\n const tripToolCalls: ToolCall[] = [];\n\n if (isToolCallTrip) {\n this.messages.push({\n role: \"assistant\",\n content: response.content,\n toolCalls: response.toolCalls,\n });\n\n for (const toolCallRequest of response.toolCalls!) {\n const record = await this.dispatchToolCall(toolCallRequest, tripIndex);\n\n tripToolCalls.push(record);\n }\n }\n\n const trip: LLMTrip = {\n index: tripIndex,\n input: tripInput,\n output: response.content,\n finishReason: response.finishReason,\n startedAt: tripStartedAt.toISOString(),\n endedAt: new Date().toISOString(),\n duration: performance.now() - tripStart,\n usage: response.usage,\n toolCalls: tripToolCalls.length > 0 ? tripToolCalls : undefined,\n };\n\n this.trips.push(trip);\n\n this.emit(\"agent.trip.completed\", { trip });\n\n if (!isToolCallTrip) {\n return \"stop\";\n }\n\n // Terminate the trip loop when EVERY tool call this trip is\n // `mode: \"silent\"`. Silent tools don't feed their result back\n // to the model — the prose the model streamed alongside the\n // tool call IS the final reply. The \"all\" rule is load-bearing:\n // if any feedback tool was called too, its result still needs\n // to round-trip, so we must continue.\n //\n // Composite (`asTool`-wrapped) tools never set `mode: \"silent\"`\n // in v1 — silent-composite mechanics are deferred per plan\n // 2026-05-07-silent-tools.md (Q4). They behave as feedback.\n const allSilent = response.toolCalls!.every((request) => {\n const registered = this.config.tools?.find((tool) => tool.name === request.name);\n return registered?.mode === \"silent\";\n });\n\n return allSilent ? \"stop\" : \"continue\";\n }\n\n /**\n * Route `getModelResponse` through the `trip`-level middleware\n * pipeline. `trip.before` hooks can short-circuit the trip by\n * returning a synthetic `ModelResponse` (semantic cache hit).\n * `trip.after` hooks can transform the response before the trip\n * record is built or any tool calls are dispatched. `trip.onError`\n * hooks can recover from provider failures (fallback chain).\n */\n private async runTripThroughPipeline(tripIndex: number): Promise<ModelResponse> {\n const context: MiddlewareTripContext = {\n ...this.buildExecuteContext(),\n tripIndex,\n messages: this.messages,\n };\n\n return (await runPipeline(\n this.middleware,\n \"trip\",\n context,\n () => this.getModelResponse(tripIndex),\n this.logger,\n )) as ModelResponse;\n }\n\n /**\n * Produce the `ModelResponse` for the current trip. In non-streaming\n * mode, delegates straight to `model.complete()`. In streaming mode,\n * drains `model.stream()` while emitting `streaming` events per delta\n * and accumulates the chunks into the same `ModelResponse` shape, so the\n * rest of the trip pipeline (tool dispatch, trip record, usage\n * aggregation) stays identical between the two modes.\n */\n private async getModelResponse(tripIndex: number): Promise<ModelResponse> {\n const callOptions = {\n ...this.config.modelOptions,\n tools: this.config.tools ?? [],\n ...(this.responseSchema ? { responseSchema: this.responseSchema } : {}),\n ...(this.options?.signal ? { signal: this.options.signal } : {}),\n };\n\n if (!this.streamController) {\n return this.config.model.complete(this.messages, callOptions);\n }\n\n let content = \"\";\n let finishReason: FinishReason = \"stop\";\n let usage: Usage = { input: 0, output: 0, total: 0 };\n const toolCalls: ModelToolCallRequest[] = [];\n const recoveredCalls: ModelToolCallRequest[] = [];\n\n const guardConfig = this.resolveStreamingToolGuard();\n const guard = guardConfig\n ? new JsonStreamGuard({\n tools: (this.config.tools ?? []) as ReadonlyArray<ToolContract<unknown, unknown>>,\n maxBufferBytes: guardConfig.maxBufferBytes,\n onSafeDelta: (delta) => {\n content += delta;\n\n this.emit(\"agent.trip.streaming\", { delta, tripIndex });\n },\n onRecoveredCall: (request) => {\n recoveredCalls.push(request);\n },\n })\n : undefined;\n\n for await (const chunk of this.config.model.stream(this.messages, callOptions)) {\n // Mid-stream abort — break out cleanly instead of continuing to\n // consume the iterator. The underlying fetch is already\n // cancelled via `signal` forwarded in callOptions; this covers\n // adapters that don't honor signal natively and keeps mock\n // models consistent under cancellation tests.\n if (this.options?.signal?.aborted) {\n throw this.makeCancelledError();\n }\n\n if (chunk.type === \"delta\") {\n if (guard) {\n await guard.feed(chunk.content);\n } else {\n content += chunk.content;\n\n this.emit(\"agent.trip.streaming\", { delta: chunk.content, tripIndex });\n }\n\n continue;\n }\n\n if (chunk.type === \"tool-call\") {\n toolCalls.push({\n id: chunk.id,\n name: chunk.name,\n input: chunk.input,\n ...(chunk.providerMetadata ? { providerMetadata: chunk.providerMetadata } : {}),\n });\n\n continue;\n }\n\n finishReason = chunk.finishReason;\n usage = chunk.usage;\n }\n\n if (guard) {\n await guard.finalize();\n }\n\n // Dedupe synthesized calls against real ones the provider streamed\n // structurally — the model occasionally emits BOTH channels for\n // the same call (real tool-call chunk + narrated JSON envelope).\n // Real wins; the synthesized duplicate is dropped so dispatch\n // doesn't run twice. See plan 2026-05-22 §Q5.\n const dedupedRecovered = recoveredCalls.filter(\n (recovered) => !isDuplicateToolCall(recovered, toolCalls),\n );\n\n const mergedToolCalls = [...toolCalls, ...dedupedRecovered];\n\n // When the guard recovered any calls but the model reported a\n // natural `\"stop\"`, override to `\"tool_calls\"` so the agent's\n // dispatch loop (`runTrip` → `isToolCallTrip`) actually fires.\n // Without this the guard silently suppresses the leaked JSON but\n // never dispatches the real action — chips never render.\n const resolvedFinishReason: FinishReason =\n dedupedRecovered.length > 0 && finishReason === \"stop\" ? \"tool_calls\" : finishReason;\n\n return {\n content,\n finishReason: resolvedFinishReason,\n usage,\n toolCalls: mergedToolCalls.length > 0 ? mergedToolCalls : undefined,\n };\n }\n\n /**\n * Resolve the effective `streamingToolGuard` for this trip.\n * Per-call options win over the agent-level config when the key is\n * explicitly present on options (including the explicit `undefined`\n * \"disable for this call\" form). Returns `undefined` when no guard\n * should run.\n */\n private resolveStreamingToolGuard(): StreamingToolGuardConfig | undefined {\n if (\n this.options !== undefined &&\n Object.prototype.hasOwnProperty.call(this.options, \"streamingToolGuard\")\n ) {\n return this.options.streamingToolGuard;\n }\n\n return this.config.streamingToolGuard;\n }\n\n /**\n * Dispatch a single tool call requested by the model. Looks up the tool\n * by name, invokes it via the safe `ToolContract.invoke` entry, pushes a\n * matching tool-result message into `this.messages` so the next trip can\n * see it, and emits the right lifecycle event (`tool-called` on success,\n * `tool-calling-failed` when the tool is unregistered or invoke returned\n * an error). Never throws — always returns a `ToolCall` record.\n */\n private async dispatchToolCall(\n toolCallRequest: ModelToolCallRequest,\n tripIndex: number,\n ): Promise<ToolCall> {\n const registeredTool = this.config.tools?.find((tool) => tool.name === toolCallRequest.name);\n\n if (!registeredTool) {\n const error = new AgentExecutionError(`Tool not registered: ${toolCallRequest.name}`, {\n context: { toolName: toolCallRequest.name, tripIndex },\n });\n\n const nowIso = new Date().toISOString();\n\n const record: ToolCall = {\n runId: generateRunId(\"tool\"),\n rootRunId: this.runId,\n name: toolCallRequest.name,\n type: \"tool\",\n status: \"failed\",\n startedAt: nowIso,\n endedAt: nowIso,\n duration: 0,\n usage: { input: 0, output: 0, total: 0 },\n children: [],\n tripIndex,\n input: toolCallRequest.input,\n error,\n ...(toolCallRequest.recoveredFrom ? { recoveredFrom: toolCallRequest.recoveredFrom } : {}),\n };\n\n this.toolCalls.push(record);\n\n this.messages.push({\n role: \"tool\",\n toolCallId: toolCallRequest.id,\n content: JSON.stringify({ error: error.message }),\n });\n\n // Stub meta — there's no real tool to describe. Carries the\n // requested name for log correlation and an explanatory\n // description so consumers don't see an empty string.\n this.emit(\"agent.tool.failed\", {\n tool: {\n name: toolCallRequest.name,\n description: \"(unregistered tool — no description available)\",\n },\n input: toolCallRequest.input,\n error,\n tripIndex,\n });\n\n return record;\n }\n\n // Build the lightweight event meta once. Resolves `action` to a\n // string here so consumers receive plain data rather than having\n // to re-evaluate a callback on every event.\n const toolMeta: ToolEventMeta = {\n name: registeredTool.name,\n description: registeredTool.description,\n action: resolveToolAction(registeredTool, toolCallRequest.input),\n };\n\n this.emit(\"agent.tool.calling\", {\n tool: toolMeta,\n input: toolCallRequest.input,\n tripIndex,\n });\n\n const toolContext: MiddlewareToolContext = {\n ...this.buildExecuteContext(),\n tripIndex,\n messages: this.messages,\n tool: {\n name: registeredTool.name,\n description: registeredTool.description,\n mode: registeredTool.mode,\n },\n request: toolCallRequest,\n };\n\n let invokeResult: ToolInvokeResult<unknown>;\n\n try {\n invokeResult = (await runPipeline(\n this.middleware,\n \"tool\",\n toolContext,\n () => registeredTool.invoke(toolCallRequest.input, this.options?.toolCtx),\n this.logger,\n )) as ToolInvokeResult<unknown>;\n } catch (thrown) {\n // A `tool`-level middleware hook threw. The real invoke never\n // throws (it funnels errors into `result.error`), so only a\n // middleware abort or a bug reaches this branch. Synthesize a\n // failed-invoke record so the tool-call trace stays consistent.\n const error = this.toAIError(thrown);\n const nowIso = new Date().toISOString();\n const emptyUsage: Usage = { input: 0, output: 0, total: 0 };\n\n const failedRunId = generateRunId(\"tool\");\n invokeResult = {\n error,\n usage: emptyUsage,\n report: {\n runId: failedRunId,\n rootRunId: failedRunId,\n name: registeredTool.name,\n version: registeredTool.version,\n type: \"tool\",\n status: \"failed\",\n startedAt: nowIso,\n endedAt: nowIso,\n duration: 0,\n usage: emptyUsage,\n children: [],\n },\n };\n }\n\n // The agent-level ToolCall record merges the tool's own invocation\n // report with agent-side enrichments (tripIndex, input, output,\n // error). When the underlying tool was an `asTool`-wrapped\n // composite, its inner report becomes the sole child of this\n // ToolCall — preserving the full nested tree while keeping this\n // node's own `type` as `\"tool\"` (from the agent's POV it *was* a\n // tool dispatch).\n const innerReport = invokeResult.report;\n const isComposite = innerReport.type !== \"tool\";\n\n const record: ToolCall = {\n runId: innerReport.runId,\n rootRunId: this.runId,\n name: toolCallRequest.name,\n version: registeredTool.version,\n type: \"tool\",\n status: innerReport.status,\n startedAt: innerReport.startedAt,\n endedAt: innerReport.endedAt,\n duration: innerReport.duration,\n usage: invokeResult.usage,\n children: isComposite ? [innerReport] : innerReport.children,\n tripIndex,\n input: toolCallRequest.input,\n output: invokeResult.data,\n error: invokeResult.error,\n ...(toolCallRequest.recoveredFrom ? { recoveredFrom: toolCallRequest.recoveredFrom } : {}),\n };\n\n this.toolCalls.push(record);\n\n // Roll child usage into the agent's accumulator. Leaf tools\n // contribute zero; `asTool`-wrapped composites contribute the\n // full cost of the inner agent/workflow/supervisor run.\n this.usage.input += invokeResult.usage.input;\n this.usage.output += invokeResult.usage.output;\n this.usage.total += invokeResult.usage.total;\n this.usage.cost = accumulateCost(this.usage.cost, invokeResult.usage.cost);\n\n this.messages.push({\n role: \"tool\",\n toolCallId: toolCallRequest.id,\n content: invokeResult.error\n ? JSON.stringify({ error: invokeResult.error.message })\n : JSON.stringify(invokeResult.data ?? null),\n });\n\n if (invokeResult.error) {\n this.emit(\"agent.tool.failed\", {\n tool: toolMeta,\n input: toolCallRequest.input,\n error: invokeResult.error,\n tripIndex,\n });\n } else {\n this.emit(\"agent.tool.called\", { ...record, tool: toolMeta });\n }\n\n return record;\n }\n\n /**\n * Parse the final trip output against the user-supplied schema (if any).\n * Failures populate `this.error` but never throw. Returns an outcome the\n * caller uses to decide whether self-repair is worth attempting:\n *\n * - `\"skipped\"` — no schema, or a prior trip-level error already set\n * `this.error` (model crash, max trips). Not repairable; the failure\n * isn't a parse problem the model can fix by re-asking.\n * - `\"failed\"` — schema present, output text either failed JSON.parse\n * or failed `~standard.validate`. Repairable via `runRepairLoop`.\n * - `\"success\"` — parsed and validated; `this.data` populated.\n */\n private async parseOutput(): Promise<\"success\" | \"failed\" | \"skipped\"> {\n const schema = this.options?.output ?? this.config.output;\n\n if (!schema || this.error) {\n return \"skipped\";\n }\n\n const finalTrip = this.trips[this.trips.length - 1];\n const text = finalTrip?.output ?? \"\";\n\n if (!text) {\n return \"skipped\";\n }\n\n const payload = extractJsonPayload(text);\n const sentinel = Symbol(\"parse-failed\");\n const parsed = safeJsonParse<unknown>(payload, sentinel);\n\n if (parsed === sentinel) {\n this.error = new SchemaValidationError(\"Failed to parse model output as JSON\", {\n context: { text },\n });\n return \"failed\";\n }\n\n const validation = await (schema as StandardSchemaV1<TOutput>)[\"~standard\"].validate(parsed);\n\n if (validation.issues) {\n const summary = validation.issues.map((issue) => issue.message).join(\"; \");\n this.error = new SchemaValidationError(summary, {\n issues: validation.issues,\n });\n return \"failed\";\n }\n\n this.data = validation.value;\n return \"success\";\n }\n\n /**\n * Opt-in self-repair loop for `output` schema failures. Triggered only\n * when `options.repair` is set and `parseOutput()` returned `\"failed\"`.\n *\n * Each attempt:\n * 1. Pushes the bad assistant response into `this.messages` (so the\n * model can see what it just produced).\n * 2. Pushes a corrective user message naming the validation/parse error.\n * 3. Runs another trip — counted against the same `maxTrips` cap as\n * normal trips so a stuck model can't loop forever.\n * 4. Re-parses. Stops on success, on a trip-level error, or when\n * either `maxAttempts` or `maxTrips` is exhausted.\n *\n * Resets `this.error` and `this.data` before each attempt so the final\n * outcome (success or last failure) is what surfaces to the caller.\n */\n private async runRepairLoop(): Promise<void> {\n const maxAttempts = this.options?.repair?.maxAttempts ?? 1;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (this.trips.length >= this.maxTrips) {\n return;\n }\n\n const lastTrip = this.trips[this.trips.length - 1];\n const badResponse = lastTrip?.output ?? \"\";\n const failureReason = this.error?.message ?? \"unknown validation failure\";\n\n this.error = undefined;\n this.data = undefined;\n\n this.messages.push({ role: \"assistant\", content: badResponse });\n\n this.messages.push({\n role: \"user\",\n content: [\n `Your previous response failed validation: ${failureReason}.`,\n \"Respond again with valid JSON only — no prose, no markdown fences, no commentary.\",\n ].join(\" \"),\n });\n\n const tripIndex = this.trips.length;\n\n this.logger.warn(LOG_MODULE, \"repair.attempting\", \"retrying after validation failure\", {\n attempt: attempt + 1,\n maxAttempts,\n reason: failureReason,\n });\n\n const outcome = await this.runTrip(tripIndex, \"[repair attempt]\");\n\n if (outcome === \"error\") {\n return;\n }\n\n const parseOutcome = await this.parseOutput();\n\n if (parseOutcome === \"success\") {\n return;\n }\n }\n }\n\n /**\n * Build the final `AgentResult` snapshot from accumulated state\n * (trips, tool calls, data/error, usage, timing).\n *\n * Pure — no side effects. `run()` owns terminal event emission and\n * stream closure so the post-pipeline result (possibly transformed\n * or short-circuited by an `execute`-level middleware) is what\n * flows out to consumers and listeners.\n *\n * Trips, tool calls, status, and timing live under `report` so the\n * root stays focused on the four things callers reach for most:\n * `data`, `text`, `usage`, `error`.\n */\n private buildResult(): AgentResult<TOutput> {\n const finalTrip = this.trips[this.trips.length - 1];\n const endedAt = new Date();\n\n const agentName = this.config.name ?? this.config.model.name;\n const status: BaseReport[\"status\"] = this.error\n ? this.error instanceof AgentCancelledError\n ? \"cancelled\"\n : \"failed\"\n : \"completed\";\n\n const report = {\n runId: this.runId,\n rootRunId: this.runId,\n name: agentName,\n version: this.config.version,\n type: \"agent\" as const,\n status,\n startedAt: this.startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n duration: performance.now() - this.start,\n usage: this.usage,\n children: this.toolCalls,\n model: {\n name: this.config.model.name,\n provider: this.config.model.provider,\n },\n trips: this.trips,\n };\n\n // Stamp lineage on the assembled tree exactly once per run.\n // Rewrites any inner self-roots from composite children to this\n // run's id, stamps `reportSchemaVersion` on the root, and\n // propagates `sessionId` to every node.\n stampReportLineage(report, {\n rootRunId: this.runId,\n sessionId: this.options?.sessionId,\n });\n\n return {\n type: \"agent\",\n data: this.data,\n text: finalTrip?.output,\n report,\n usage: this.usage,\n error: this.error,\n };\n }\n\n /**\n * Normalize any thrown value into an `AIError`. `AIError` instances\n * pass through untouched; provider-adapter SDK errors are caught by\n * the adapter and already arrive typed, so this branch mainly\n * handles runtime crashes (TypeError, ReferenceError) inside\n * model.complete / model.stream and non-Error values (`throw \"bad\"`).\n */\n private toAIError(thrown: unknown): AIError {\n if (thrown instanceof AIError) {\n return thrown;\n }\n\n // Classify abort-flavored errors (DOMException \"AbortError\",\n // node-fetch's `FetchError` with name \"AbortError\", `ERR_CANCELED`\n // from the OpenAI SDK's axios-ish layer) as cancelled instead of\n // a generic exec failure so callers can route retries correctly.\n if (isAbortLike(thrown)) {\n return this.makeCancelledError();\n }\n\n const message = thrown instanceof Error ? thrown.message : String(thrown);\n\n return new AgentExecutionError(message, { cause: thrown });\n }\n\n /**\n * Build the typed cancelled error that both the trip-loop guard\n * and the mid-stream guard emit. Captures the abort reason when\n * one was supplied to `controller.abort(reason)` so logs and\n * telemetry can see what cancelled the run.\n */\n private makeCancelledError(): AgentCancelledError {\n const reason = this.options?.signal?.reason;\n const reasonText = reason === undefined ? \"\" : String(reason);\n\n return new AgentCancelledError(\"agent execution cancelled\", {\n cause: reason,\n cancelledAt: new Date().toISOString(),\n reason: reasonText,\n });\n }\n\n /**\n * Fire a single event through all three subscription tiers in order\n * — factory → instance → per-call — and mirror it into the\n * `StreamController` when streaming is active. A throwing user\n * handler must never crash the agent, so every dispatch is wrapped\n * in `safeCall`. Stream events are converted from the internal\n * `AgentEventMap` payload to the public `StreamEvent` shape because\n * some of them differ (e.g. the tool-called payload vs stream\n * event).\n */\n private emit<K extends keyof AgentEventMap>(\n event: K,\n payload: WithoutIdentity<AgentEventMap[K]>,\n ): void {\n // Inject run identity once, here, so every subscription tier and\n // the stream see it. `rootRunId === runId` for a standalone run;\n // nested propagation lands in a follow-up.\n const fullPayload = {\n ...payload,\n runId: this.runId,\n rootRunId: this.runId,\n } as AgentEventMap[K];\n\n this.logEvent(event, fullPayload);\n\n const factoryHandler = this.config.on?.[event] as AgentEventHandler<K> | undefined;\n\n if (factoryHandler) {\n safeCall(factoryHandler, fullPayload);\n }\n\n const bucket = this.instanceHandlers?.get(event);\n\n if (bucket) {\n for (const handler of bucket) {\n safeCall(handler as AgentEventHandler<K>, fullPayload);\n }\n }\n\n const perCallHandler = this.options?.on?.[event] as AgentEventHandler<K> | undefined;\n\n if (perCallHandler) {\n safeCall(perCallHandler, fullPayload);\n }\n\n if (this.streamController) {\n const body = this.toStreamEvent(event, fullPayload);\n\n if (body) {\n this.streamController.push({\n runId: this.runId,\n rootRunId: this.runId,\n ...body,\n });\n }\n }\n }\n\n /**\n * Emit a structured log line for a lifecycle event. The action\n * string mirrors the event name with the `agent.` prefix stripped\n * (`agent.trip.started` → `trip.started`) so log grep filters and\n * event handlers read the same vocabulary. Level mapping follows\n * the convention documented on `@warlock.js/logger`'s `Logger`.\n */\n private logEvent<K extends keyof AgentEventMap>(event: K, payload: AgentEventMap[K]): void {\n const agentName = this.config.name || this.config.model.name;\n logAgentEvent(\n this.logger,\n {\n module: `${LOG_MODULE}.${agentName}`,\n maxTrips: this.maxTrips,\n modelName: this.config.model.name,\n totalUsage: this.usage,\n totalDurationMs: performance.now() - this.start,\n trips: this.trips,\n toolCalls: this.toolCalls,\n },\n event,\n payload,\n );\n }\n\n private toStreamEvent<K extends keyof AgentEventMap>(\n event: K,\n payload: AgentEventMap[K],\n ): StreamEventBody | undefined {\n return agentEventToStreamEvent(event, payload);\n }\n\n /**\n * Invoke the `onUsage` hook (when configured) with a flat payload\n * carrying stable identity. Awaits the handler so async ledger\n * writes complete before the next trip starts; swallows any throw\n * so consumer bugs cannot crash the agent. Sync handlers wrapped\n * via `Promise.resolve()` so the await is safe in either case.\n */\n private async fireUsageHook(tripIndex: number, tripUsage: Usage): Promise<void> {\n const handler = this.config.onUsage;\n if (!handler) return;\n\n const event: UsageEvent = {\n runId: this.runId,\n tripIndex,\n model: {\n name: this.config.model.name,\n provider: this.config.model.provider,\n },\n usage: { ...tripUsage },\n timestamp: new Date().toISOString(),\n };\n\n try {\n await Promise.resolve(handler(event));\n } catch (err) {\n this.logger.warn(LOG_MODULE, \"onUsage.hook.error\", \"onUsage handler threw\", {\n runId: this.runId,\n tripIndex,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n /**\n * Invoke the `onComplete` hook (when configured) once at the end\n * of every run. Receives the full `AgentResult` plus pre-extracted\n * `runId` and `durationMs`. Same swallow-and-log error policy as\n * `fireUsageHook`.\n */\n private async fireCompleteHook(result: AgentResult<TOutput>): Promise<void> {\n const handler = this.config.onComplete;\n if (!handler) return;\n\n const event: CompleteEvent<TOutput> = {\n result,\n runId: this.runId,\n durationMs: performance.now() - this.start,\n };\n\n try {\n await Promise.resolve(handler(event));\n } catch (err) {\n this.logger.warn(LOG_MODULE, \"onComplete.hook.error\", \"onComplete handler threw\", {\n runId: this.runId,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n}\n\n/**\n * Decide whether a guard-synthesized tool call duplicates a real one\n * the provider already streamed structurally. Match key is\n * `name + key-sorted JSON of input` so identical calls (regardless of\n * argument key order) collapse, but two legitimate calls to the same\n * tool with different inputs still both dispatch.\n */\nfunction isDuplicateToolCall(\n recovered: ModelToolCallRequest,\n realCalls: ReadonlyArray<ModelToolCallRequest>,\n): boolean {\n const recoveredKey = `${recovered.name}|${stableStringify(recovered.input)}`;\n\n for (const real of realCalls) {\n const realKey = `${real.name}|${stableStringify(real.input)}`;\n\n if (realKey === recoveredKey) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * `JSON.stringify` variant that sorts object keys at every nesting\n * level so structurally-equal inputs serialize to identical strings.\n * Used only for dedupe-key comparison; never surfaces to consumers.\n */\nfunction stableStringify(value: unknown): string {\n return JSON.stringify(value, (_key, val) => {\n if (val !== null && typeof val === \"object\" && !Array.isArray(val)) {\n const source = val as Record<string, unknown>;\n const sorted: Record<string, unknown> = {};\n\n for (const key of Object.keys(source).sort()) {\n sorted[key] = source[key];\n }\n\n return sorted;\n }\n\n return val;\n });\n}\n\n/**\n * Invoke a user-supplied event handler without letting exceptions\n * escape the agent. Thrown errors are swallowed — structured logging\n * attaches here in Phase 0.5 so operators still see the failure.\n */\nfunction safeCall<T>(handler: (payload: T) => void, payload: T): void {\n try {\n handler(payload);\n } catch {\n // Intentionally swallowed — user handlers never crash the agent.\n }\n}\n\n/**\n * Resolve a tool's `action` declaration into a plain string for\n * inclusion in `ToolEventMeta`. Static strings pass through;\n * function-shaped actions are invoked with the validated input.\n *\n * Defensive: if the user's callback throws, swallow and return\n * `undefined` rather than crashing the agent — UI strings are not\n * worth aborting an LLM dispatch over.\n */\nfunction resolveToolAction(\n tool: ToolContract<unknown, unknown>,\n input: unknown,\n): string | undefined {\n if (tool.action === undefined) return undefined;\n if (typeof tool.action === \"string\") return tool.action;\n try {\n return tool.action(input);\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAM,aAAa;;;;;;;AAQnB,SAAS,YAAY,KAAuB;CAC1C,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAE5C,MAAM,IAAI;CAEV,OAAO,EAAE,SAAS,gBAAgB,EAAE,SAAS,kBAAkB,EAAE,SAAS;AAC5E;;;;;;;;;;AAWA,SAAS,oBAAuB,QAAgC;CAC9D,MAAM,WAAY,OAAO,OAA4C,YAAY;CACjF,MAAM,QAAQ,OAAO,OAAO,QAAQ;CACpC,MAAM,SAAS,OAAO,SAAS,CAAC,GAC7B,KAAK,SAAS,KAAK,IAAI,EACvB,KAAK,EACL,KAAK,GAAG;CAEX,MAAM,OAAO,QAAQ,SAAS,QAAQ,EAAE,GAAG,SAAS,KAAK;CACzD,OAAO,QAAQ,GAAG,KAAK,GAAG,SAAS,OAAO,EAAE,UAAU,KAAK,CAAC,MAAM;AACpE;AAEA,SAAS,SAAS,OAAe,OAA+B,CAAC,GAAW;CAC1E,MAAM,UAAU,KAAK,WAAW,sBAAsB;CACtD,OAAO,MAAM,QAAQ,SAAS,GAAG;AACnC;;;;;;;;;;;;;;;;;AAkBA,SAAS,mBAAmB,YAAsD;CAChF,IAAI,CAAC,cAAc,WAAW,WAAW,GACvC;CAGF,MAAM,uBAAO,IAAI,IAAY;CAE7B,KAAK,IAAI,QAAQ,GAAG,QAAQ,WAAW,QAAQ,SAAS;EACtD,MAAM,QAAQ,WAAW;EAEzB,IAAI,CAAC,SAAS,OAAO,UAAU,UAC7B,MAAM,IAAI,oBACR,cAAc,MAAM,gCAAgC,UAAU,O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G,UAAU,KAAK,GAAG,gBAAgB,UAAU,KAAK;CAEzE,KAAK,MAAM,QAAQ,WAGjB,IAAI,GAFe,KAAK,KAAK,GAAG,gBAAgB,KAAK,KAAK,QAE1C,cACd,OAAO;CAIX,OAAO;AACT;;;;;;AAOA,SAAS,gBAAgB,OAAwB;CAC/C,OAAO,KAAK,UAAU,QAAQ,MAAM,QAAQ;EAC1C,IAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,CAAC,MAAM,QAAQ,GAAG,GAAG;GAClE,MAAM,SAAS;GACf,MAAM,SAAkC,CAAC;GAEzC,KAAK,MAAM,OAAO,OAAO,KAAK,MAAM,EAAE,KAAK,GACzC,OAAO,OAAO,OAAO;GAGvB,OAAO;EACT;EAEA,OAAO;CACT,CAAC;AACH;;;;;;AAOA,SAAS,SAAY,SAA+B,SAAkB;CACpE,IAAI;EACF,QAAQ,OAAO;CACjB,QAAQ,CAER;AACF;;;;;;;;;;AAWA,SAAS,kBACP,MACA,OACoB;CACpB,IAAI,KAAK,WAAW,QAAW,OAAO;CACtC,IAAI,OAAO,KAAK,WAAW,UAAU,OAAO,KAAK;CACjD,IAAI;EACF,OAAO,KAAK,OAAO,KAAK;CAC1B,QAAQ;EACN;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"agent.mjs","names":[],"sources":["../../../../../../../@warlock.js/ai/src/agent/agent.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport { log, type Logger } from \"@warlock.js/logger\";\nimport type {\n AgentContract,\n AgentEventHandler,\n AgentEventMap,\n AgentExecuteOptions,\n AgentResult,\n BaseReport,\n CompleteEvent,\n FinishReason,\n LLMTrip,\n Message,\n MiddlewareExecuteContext,\n MiddlewareState,\n MiddlewareToolContext,\n MiddlewareTripContext,\n ModelResponse,\n ModelToolCallRequest,\n StreamContract,\n StreamEventBody,\n StreamingToolGuardConfig,\n ToolCall,\n ToolEventMeta,\n Usage,\n UsageEvent,\n WithoutIdentity,\n} from \"../contracts\";\nimport {\n AgentCancelledError,\n AgentExecutionError,\n AgentMaxTripsError,\n AIError,\n SchemaValidationError,\n} from \"../errors\";\nimport { runPipeline } from \"../middleware\";\nimport type { ToolContract, ToolInvokeResult } from \"../tool/tool\";\nimport {\n accumulateCost,\n computeCost,\n extractJsonPayload,\n generateRunId,\n safeJsonParse,\n stampReportLineage,\n} from \"../utils\";\nimport type { AgentConfig } from \"./agent-config.type\";\nimport { buildAgentInputMessages } from \"./agent-input-builder\";\nimport { logAgentEvent } from \"./agent-log-event\";\nimport { createAgentStream, type StreamController } from \"./agent-stream\";\nimport { agentEventToStreamEvent } from \"./agent-to-stream-event\";\nimport { JsonStreamGuard } from \"./json-stream-guard\";\n\nconst LOG_MODULE = \"ai.agent\";\n\n/**\n * Detect abort-flavored errors surfaced by SDK HTTP layers — the\n * DOM `AbortError`, axios `ERR_CANCELED`, node-fetch's own\n * `AbortError`. Used to classify them as cancellation rather than\n * generic agent-execution failures.\n */\nfunction isAbortLike(err: unknown): boolean {\n if (!err || typeof err !== \"object\") return false;\n\n const e = err as { name?: unknown; code?: unknown };\n\n return e.name === \"AbortError\" || e.code === \"ERR_CANCELED\" || e.code === \"ABORT_ERR\";\n}\n\n/**\n * Readable synthetic name for agents constructed without an explicit\n * `name`. Format: `anon_<provider>_<model>[_<tool1>+<tool2>+...]` —\n * deterministic (same config → same name across restarts) and\n * human-readable in logs / workflow snapshots.\n *\n * Keeps drift detection honest for the `ai.agent({ model })`\n * one-liner without punishing it with a hashed id nobody can read.\n */\nfunction synthesizeAgentName<T>(config: AgentConfig<T>): string {\n const provider = (config.model as unknown as { provider?: string })?.provider ?? \"unknown\";\n const model = config.model?.name ?? \"unknown\";\n const tools = (config.tools ?? [])\n .map((tool) => tool.name)\n .sort()\n .join(\"+\");\n\n const base = `anon_${sanitize(provider)}_${sanitize(model)}`;\n return tools ? `${base}_${sanitize(tools, { keepPlus: true })}` : base;\n}\n\nfunction sanitize(value: string, opts: { keepPlus?: boolean } = {}): string {\n const allowed = opts.keepPlus ? /[^a-zA-Z0-9._+-]/g : /[^a-zA-Z0-9._-]/g;\n return value.replace(allowed, \"-\");\n}\n\n/**\n * Authoring-time check on the middleware array. Throws an\n * `AgentExecutionError` with `context: { authoring: true }` the\n * moment an invalid entry is found — the agent factory surface is\n * where config bugs should surface, not ten trips into a run.\n *\n * Validates:\n * - Every entry is a non-null object with a non-empty string `name`.\n * - No two entries share the same `name` (would silently collide on\n * `ctx.state` keys and produce impossible-to-debug behavior).\n *\n * Does NOT validate that hook maps contain callable functions —\n * that would catch late-binding bugs but also reject legitimate\n * patterns like `before` being conditionally `undefined`. Runtime\n * dispatch handles missing hooks safely.\n */\nfunction validateMiddleware(middleware: ReadonlyArray<unknown> | undefined): void {\n if (!middleware || middleware.length === 0) {\n return;\n }\n\n const seen = new Set<string>();\n\n for (let index = 0; index < middleware.length; index++) {\n const entry = middleware[index];\n\n if (!entry || typeof entry !== \"object\") {\n throw new AgentExecutionError(\n `middleware[${index}] must be an object; received ${entry === null ? \"null\" : typeof entry}`,\n { context: { authoring: true, index } },\n );\n }\n\n const name = (entry as { name?: unknown }).name;\n\n if (typeof name !== \"string\" || name.length === 0) {\n throw new AgentExecutionError(`middleware[${index}] must have a non-empty string \"name\"`, {\n context: { authoring: true, index },\n });\n }\n\n if (seen.has(name)) {\n throw new AgentExecutionError(\n `duplicate middleware name \"${name}\" — each middleware needs a unique name so ctx.state keys do not collide`,\n { context: { authoring: true, index, name } },\n );\n }\n\n seen.add(name);\n }\n}\n\n/**\n * Creates an executable AI agent from the given configuration.\n *\n * The agent runs a bounded trip loop: each trip calls the model, dispatches\n * any requested tool calls, then loops until the model stops or `maxTrips`\n * is reached. Each `execute()` / `stream()` call spawns a fresh internal\n * `Execution` instance — the factory itself holds no state across calls.\n *\n * `execute()` never throws — any error is attached to the returned result\n * under `result.error`. `stream()` surfaces errors both on the terminal\n * `error` stream event and via the `stream.result` promise.\n *\n * @example\n * const myAgent = agent({\n * model: openai.model({ name: \"gpt-4o\" }),\n * systemPrompt: \"You are a helpful assistant.\",\n * tools: [searchTool],\n * });\n *\n * const result = await myAgent.execute(\"What is the capital of Egypt?\");\n *\n * @example\n * const stream = myAgent.stream(\"Write a haiku about Cairo.\");\n *\n * for await (const event of stream) {\n * if (event.type === \"streaming\") process.stdout.write(event.delta);\n * }\n *\n * const result = await stream.result;\n */\nexport function agent<TOutput = unknown>(config: AgentConfig<TOutput>): AgentContract<TOutput> {\n // Authoring-time validation of the middleware array. Rejects two\n // classes of bug that would otherwise surface as opaque failures\n // mid-execution: (a) entries that aren't proper middleware\n // objects (null, undefined, missing `name`), and (b) two\n // middlewares sharing the same `name`, which would silently\n // collide on `ctx.state` keys. Fail fast, fail loud — per the\n // authoring-time rules in `domains/ai/conventions/errors.md`.\n validateMiddleware(config.middleware);\n\n // Resolve the agent's identity. Explicit `name` wins; otherwise we\n // synthesize a DETERMINISTIC fingerprint from the config's\n // identity-defining fields (model + provider + tool names). Same\n // config across process restarts produces the same synthetic name,\n // so workflow signature drift detection stays honest for agents\n // composed into workflows without explicit names.\n const isAnonymous = !config.name || typeof config.name !== \"string\";\n const name = isAnonymous ? synthesizeAgentName(config) : (config.name as string);\n const resolvedConfig: AgentConfig<TOutput> = { ...config, name };\n\n // Instance-level handlers registered via `.on()`. Stored here\n // (factory-scope) so every `execute()` / `stream()` call on this\n // agent sees the same set. Each event name gets its own Set so\n // `off()` can remove a specific handler without disturbing others.\n const instanceHandlers = new Map<\n keyof AgentEventMap,\n Set<AgentEventHandler<keyof AgentEventMap>>\n >();\n\n function on<K extends keyof AgentEventMap>(event: K, handler: AgentEventHandler<K>): () => void {\n const existing = instanceHandlers.get(event);\n const bucket = existing ?? new Set<AgentEventHandler<keyof AgentEventMap>>();\n\n if (!existing) {\n instanceHandlers.set(event, bucket);\n }\n\n bucket.add(handler as AgentEventHandler<keyof AgentEventMap>);\n\n return () => off(event, handler);\n }\n\n function off<K extends keyof AgentEventMap>(event: K, handler: AgentEventHandler<K>): void {\n const bucket = instanceHandlers.get(event);\n\n if (!bucket) {\n return;\n }\n\n bucket.delete(handler as AgentEventHandler<keyof AgentEventMap>);\n\n if (bucket.size === 0) {\n instanceHandlers.delete(event);\n }\n }\n\n return {\n name,\n isAnonymous,\n description: config.description,\n async execute(\n input: string,\n options?: AgentExecuteOptions<TOutput>,\n ): Promise<AgentResult<TOutput>> {\n return new Execution<TOutput>(\n resolvedConfig,\n input,\n options,\n undefined,\n instanceHandlers,\n ).run();\n },\n\n stream(\n input: string,\n options?: AgentExecuteOptions<TOutput>,\n ): StreamContract<AgentResult<TOutput>> {\n const { controller, stream } = createAgentStream<AgentResult<TOutput>>();\n\n const execution = new Execution<TOutput>(\n resolvedConfig,\n input,\n options,\n controller,\n instanceHandlers,\n );\n\n void execution.run();\n\n return stream;\n },\n\n on,\n off,\n };\n}\n\n/**\n * Name → handler-set map shared between the `agent()` factory and its\n * per-call `Execution`. Each `.on()` registration mutates this map;\n * every `Execution` reads from the same reference so additions and\n * removals take effect mid-flight.\n */\ntype InstanceHandlerMap = Map<keyof AgentEventMap, Set<AgentEventHandler<keyof AgentEventMap>>>;\n\n/**\n * Per-call driver that owns the full lifecycle of a single\n * `agent.execute()` or `agent.stream()` invocation.\n *\n * **Role.** An `Execution` is the short-lived state container and phase\n * orchestrator for one agent run. The public `agent()` factory stays purely\n * functional — all mutable bookkeeping (trips, tool calls, usage totals,\n * message history, terminal error, parsed output) lives here so each call\n * gets a fresh, isolated instance.\n *\n * **Responsibility.**\n * - Owns: building the initial message list, driving the bounded trip loop,\n * dispatching tool calls safely, parsing the final output against the\n * caller's schema, emitting lifecycle events (to both the user handler\n * and, in stream mode, the `StreamController`), and producing the\n * `AgentResult`.\n * - Does NOT own: how the model produces responses (delegated to\n * `ModelContract.complete` / `ModelContract.stream`), how tools execute\n * (delegated to `ToolContract.invoke`), the async-queue plumbing for\n * streaming (delegated to `createAgentStream`), or any cross-call state\n * (factory-level concerns live in `agent()`).\n *\n * Streaming mode is opt-in via the fourth constructor argument: pass a\n * `StreamController` and every event is mirrored into it while model calls\n * are driven via `model.stream()` instead of `model.complete()`. The public\n * contract of `execute()` says it never throws — `Execution` enforces that\n * by funneling every unexpected error into `this.error` and returning a\n * well-formed result regardless of what went wrong.\n *\n * Not exported — consumers interact only with the `agent()` factory (see\n * §4.2 of code-style.md — \"per-call execution state across phases\").\n *\n * @example\n * // Non-streaming — inside agent.execute():\n * const result = await new Execution(config, input, options).run();\n *\n * @example\n * // Streaming — inside agent.stream():\n * const { controller, stream } = createAgentStream();\n * void new Execution(config, input, options, controller).run();\n * return stream;\n */\nclass Execution<TOutput> {\n private readonly trips: LLMTrip[] = [];\n private readonly toolCalls: ToolCall[] = [];\n private readonly usage: Usage = { input: 0, output: 0, total: 0 };\n private readonly messages: Message[] = [];\n private readonly maxTrips: number;\n private readonly startedAt = new Date();\n private readonly start = performance.now();\n private readonly runId = generateRunId(\"agent\");\n private readonly logger: Logger = log;\n private readonly middleware: ReadonlyArray<\n NonNullable<AgentConfig<TOutput>[\"middleware\"]>[number]\n >;\n private readonly middlewareState: MiddlewareState = new Map();\n\n private error?: AIError;\n private data?: TOutput;\n private responseSchema?: Record<string, unknown>;\n\n public constructor(\n private readonly config: AgentConfig<TOutput>,\n private readonly input: string,\n private readonly options?: AgentExecuteOptions<TOutput>,\n private readonly streamController?: StreamController<AgentResult<TOutput>>,\n private readonly instanceHandlers?: InstanceHandlerMap,\n ) {\n this.maxTrips = config.maxTrips ?? 10;\n this.middleware = config.middleware ?? [];\n }\n\n /**\n * Base middleware context shared by every level. `state` is the\n * single mutable bag threaded through `execute`, `trip`, and `tool`\n * hooks for the lifetime of this execution — fresh per `execute()`\n * call, never reused across runs.\n */\n private buildExecuteContext(): MiddlewareExecuteContext {\n return {\n agent: {\n name: this.config.name ?? this.config.model.name,\n isAnonymous: !this.config.name,\n },\n model: {\n name: this.config.model.name,\n provider: this.config.model.provider,\n },\n input: this.input,\n options: this.options as AgentExecuteOptions<unknown> | undefined,\n state: this.middlewareState,\n signal: this.options?.signal,\n };\n }\n\n /**\n * Entry point for a single agent execution. Wraps the real work\n * (`runCore`) in the `execute`-level middleware pipeline, then\n * emits the terminal `agent.completed` / `agent.error` events and\n * closes the stream (if any) with the post-pipeline result — so\n * middleware that short-circuits or transforms the final result\n * still produces a well-formed public outcome.\n *\n * Must never throw: any error that escapes the pipeline is\n * converted into an `AgentResult` with `error` populated before\n * returning, preserving the `agent.execute()` public contract.\n */\n public async run(): Promise<AgentResult<TOutput>> {\n const context = this.buildExecuteContext();\n\n let result: AgentResult<TOutput>;\n\n try {\n result = (await runPipeline(\n this.middleware,\n \"execute\",\n context,\n () => this.runCore(),\n this.logger,\n )) as AgentResult<TOutput>;\n } catch (thrown) {\n this.error = this.toAIError(thrown);\n result = this.buildResult();\n }\n\n if (result.error) {\n this.emit(\"agent.error\", { error: result.error });\n }\n\n this.emit(\"agent.completed\", { result });\n\n // Fire the `onComplete` hook with a flat payload (runId +\n // durationMs pre-extracted) for audit-log consumers. Awaited but\n // errors swallowed so consumer bugs cannot crash the agent or\n // interfere with the result returned to the caller.\n await this.fireCompleteHook(result);\n\n this.streamController?.end(result);\n\n return result;\n }\n\n /**\n * Inner body wrapped by the `execute`-level pipeline. Drives the\n * full lifecycle — build messages → emit starting → run trip loop\n * → parse output → build result. Catches any unexpected throw and\n * funnels it into `this.error` so the returned result is always\n * well-formed; `execute`-level `after` hooks receive the result,\n * with `error` populated when things went wrong.\n */\n private async runCore(): Promise<AgentResult<TOutput>> {\n try {\n await this.buildInitialMessages();\n\n this.emit(\"agent.starting\", { input: this.input });\n\n await this.runTripLoop();\n\n const parseOutcome = await this.parseOutput();\n\n if (parseOutcome === \"failed\" && this.options?.repair) {\n await this.runRepairLoop();\n }\n } catch (thrown) {\n this.error = this.toAIError(thrown);\n }\n\n return this.buildResult();\n }\n\n /**\n * Resolve the system prompt (string or `SystemPromptContract`), merge\n * placeholders from config + execute options, inject a structured-output\n * instruction when the caller wants typed output but the model can't\n * enforce it natively, prepend any conversation history, and append the\n * user input. Produces the initial `messages` array the first trip sends\n * to the model. Runs exactly once per execution.\n */\n private async buildInitialMessages(): Promise<void> {\n const { messages, responseSchema } = await buildAgentInputMessages({\n config: this.config,\n input: this.input,\n options: this.options,\n });\n this.messages.push(...messages);\n this.responseSchema = responseSchema;\n }\n\n /**\n * Drive sequential trips up to `maxTrips`. Each trip may stop the loop\n * naturally (model returned a non-tool-call finish), abort it (model\n * threw), or continue it (model requested tools). When the loop exits\n * after the cap without a natural stop, records a \"Max trips exceeded\"\n * error so the caller can distinguish runaway tool loops from a real result.\n */\n private async runTripLoop(): Promise<void> {\n for (let tripIndex = 0; tripIndex < this.maxTrips; tripIndex++) {\n if (this.options?.signal?.aborted) {\n this.error = this.makeCancelledError();\n return;\n }\n\n const tripInput = tripIndex === 0 ? this.input : \"[tool results]\";\n const outcome = await this.runTrip(tripIndex, tripInput);\n\n if (outcome === \"error\" || outcome === \"stop\") {\n return;\n }\n }\n\n const lastTrip = this.trips[this.trips.length - 1];\n\n if (lastTrip?.finishReason === \"tool_calls\") {\n this.error = new AgentMaxTripsError(\"Max trips exceeded\", {\n maxTrips: this.maxTrips,\n });\n }\n }\n\n /**\n * Execute one round-trip to the model. Aggregates usage into the running\n * total, dispatches any requested tool calls, appends the assistant +\n * tool-result messages for the next trip, and records an `LLMTrip`.\n * Returns an outcome that tells `runTripLoop` whether to continue, stop,\n * or abort.\n */\n private async runTrip(\n tripIndex: number,\n tripInput: string,\n ): Promise<\"continue\" | \"stop\" | \"error\"> {\n this.emit(\"agent.trip.started\", { tripIndex, input: tripInput });\n\n const tripStartedAt = new Date();\n const tripStart = performance.now();\n\n let response: ModelResponse;\n\n try {\n response = await this.runTripThroughPipeline(tripIndex);\n } catch (thrown) {\n this.error = this.toAIError(thrown);\n\n const failedTrip: LLMTrip = {\n index: tripIndex,\n input: tripInput,\n output: \"\",\n finishReason: \"error\",\n startedAt: tripStartedAt.toISOString(),\n endedAt: new Date().toISOString(),\n duration: performance.now() - tripStart,\n usage: { input: 0, output: 0, total: 0 },\n error: this.error,\n };\n\n this.trips.push(failedTrip);\n\n this.emit(\"agent.trip.completed\", { trip: failedTrip });\n this.emit(\"agent.error\", { error: this.error });\n\n return \"error\";\n }\n\n // Attach per-trip cost breakdown using the model's pricing table\n // (when configured). Done at the framework boundary so stored trip\n // records carry historical cost — Panoptic and other archive\n // consumers never re-derive against today's pricing, and the\n // input/output/cached split stays queryable without joining to a\n // pricing table at all.\n if (response.usage.cost === undefined) {\n response.usage.cost = computeCost(response.usage, this.config.model.pricing);\n }\n\n this.usage.input += response.usage.input;\n this.usage.output += response.usage.output;\n this.usage.total += response.usage.total;\n if (response.usage.cachedTokens !== undefined) {\n this.usage.cachedTokens = (this.usage.cachedTokens ?? 0) + response.usage.cachedTokens;\n }\n this.usage.cost = accumulateCost(this.usage.cost, response.usage.cost);\n\n // Fire the `onUsage` hook with a flat, pre-packaged payload so\n // cost-ledger code receives stable identity (runId, model+provider)\n // without joining from elsewhere. Awaited but errors swallowed.\n await this.fireUsageHook(tripIndex, response.usage);\n\n const isToolCallTrip =\n response.finishReason === \"tool_calls\" &&\n response.toolCalls !== undefined &&\n response.toolCalls.length > 0;\n\n const tripToolCalls: ToolCall[] = [];\n\n if (isToolCallTrip) {\n this.messages.push({\n role: \"assistant\",\n content: response.content,\n toolCalls: response.toolCalls,\n });\n\n for (const toolCallRequest of response.toolCalls!) {\n const record = await this.dispatchToolCall(toolCallRequest, tripIndex);\n\n tripToolCalls.push(record);\n }\n }\n\n const trip: LLMTrip = {\n index: tripIndex,\n input: tripInput,\n output: response.content,\n finishReason: response.finishReason,\n startedAt: tripStartedAt.toISOString(),\n endedAt: new Date().toISOString(),\n duration: performance.now() - tripStart,\n usage: response.usage,\n toolCalls: tripToolCalls.length > 0 ? tripToolCalls : undefined,\n };\n\n this.trips.push(trip);\n\n this.emit(\"agent.trip.completed\", { trip });\n\n if (!isToolCallTrip) {\n return \"stop\";\n }\n\n // Terminate the trip loop when EVERY tool call this trip is\n // `mode: \"silent\"`. Silent tools don't feed their result back\n // to the model — the prose the model streamed alongside the\n // tool call IS the final reply. The \"all\" rule is load-bearing:\n // if any feedback tool was called too, its result still needs\n // to round-trip, so we must continue.\n //\n // Composite (`asTool`-wrapped) tools never set `mode: \"silent\"`\n // in v1 — silent-composite mechanics are deferred per plan\n // 2026-05-07-silent-tools.md (Q4). They behave as feedback.\n const allSilent = response.toolCalls!.every((request) => {\n const registered = this.config.tools?.find((tool) => tool.name === request.name);\n return registered?.mode === \"silent\";\n });\n\n return allSilent ? \"stop\" : \"continue\";\n }\n\n /**\n * Route `getModelResponse` through the `trip`-level middleware\n * pipeline. `trip.before` hooks can short-circuit the trip by\n * returning a synthetic `ModelResponse` (semantic cache hit).\n * `trip.after` hooks can transform the response before the trip\n * record is built or any tool calls are dispatched. `trip.onError`\n * hooks can recover from provider failures (fallback chain).\n */\n private async runTripThroughPipeline(tripIndex: number): Promise<ModelResponse> {\n const context: MiddlewareTripContext = {\n ...this.buildExecuteContext(),\n tripIndex,\n messages: this.messages,\n };\n\n return (await runPipeline(\n this.middleware,\n \"trip\",\n context,\n () => this.getModelResponse(tripIndex),\n this.logger,\n )) as ModelResponse;\n }\n\n /**\n * Produce the `ModelResponse` for the current trip. In non-streaming\n * mode, delegates straight to `model.complete()`. In streaming mode,\n * drains `model.stream()` while emitting `streaming` events per delta\n * and accumulates the chunks into the same `ModelResponse` shape, so the\n * rest of the trip pipeline (tool dispatch, trip record, usage\n * aggregation) stays identical between the two modes.\n */\n private async getModelResponse(tripIndex: number): Promise<ModelResponse> {\n const callOptions = {\n ...this.config.modelOptions,\n tools: this.config.tools ?? [],\n ...(this.responseSchema ? { responseSchema: this.responseSchema } : {}),\n ...(this.options?.signal ? { signal: this.options.signal } : {}),\n };\n\n if (!this.streamController) {\n return this.config.model.complete(this.messages, callOptions);\n }\n\n let content = \"\";\n let finishReason: FinishReason = \"stop\";\n let usage: Usage = { input: 0, output: 0, total: 0 };\n const toolCalls: ModelToolCallRequest[] = [];\n const recoveredCalls: ModelToolCallRequest[] = [];\n\n const guardConfig = this.resolveStreamingToolGuard();\n const guard = guardConfig\n ? new JsonStreamGuard({\n tools: (this.config.tools ?? []) as ReadonlyArray<ToolContract<unknown, unknown>>,\n maxBufferBytes: guardConfig.maxBufferBytes,\n onSafeDelta: (delta) => {\n content += delta;\n\n this.emit(\"agent.trip.streaming\", { delta, tripIndex });\n },\n onRecoveredCall: (request) => {\n recoveredCalls.push(request);\n },\n })\n : undefined;\n\n for await (const chunk of this.config.model.stream(this.messages, callOptions)) {\n // Mid-stream abort — break out cleanly instead of continuing to\n // consume the iterator. The underlying fetch is already\n // cancelled via `signal` forwarded in callOptions; this covers\n // adapters that don't honor signal natively and keeps mock\n // models consistent under cancellation tests.\n if (this.options?.signal?.aborted) {\n throw this.makeCancelledError();\n }\n\n if (chunk.type === \"delta\") {\n if (guard) {\n await guard.feed(chunk.content);\n } else {\n content += chunk.content;\n\n this.emit(\"agent.trip.streaming\", { delta: chunk.content, tripIndex });\n }\n\n continue;\n }\n\n if (chunk.type === \"tool-call\") {\n toolCalls.push({\n id: chunk.id,\n name: chunk.name,\n input: chunk.input,\n ...(chunk.providerMetadata ? { providerMetadata: chunk.providerMetadata } : {}),\n });\n\n continue;\n }\n\n finishReason = chunk.finishReason;\n usage = chunk.usage;\n }\n\n if (guard) {\n await guard.finalize();\n }\n\n // Dedupe synthesized calls against real ones the provider streamed\n // structurally — the model occasionally emits BOTH channels for\n // the same call (real tool-call chunk + narrated JSON envelope).\n // Real wins; the synthesized duplicate is dropped so dispatch\n // doesn't run twice. See plan 2026-05-22 §Q5.\n const dedupedRecovered = recoveredCalls.filter(\n (recovered) => !isDuplicateToolCall(recovered, toolCalls),\n );\n\n const mergedToolCalls = [...toolCalls, ...dedupedRecovered];\n\n // When the guard recovered any calls but the model reported a\n // natural `\"stop\"`, override to `\"tool_calls\"` so the agent's\n // dispatch loop (`runTrip` → `isToolCallTrip`) actually fires.\n // Without this the guard silently suppresses the leaked JSON but\n // never dispatches the real action — chips never render.\n const resolvedFinishReason: FinishReason =\n dedupedRecovered.length > 0 && finishReason === \"stop\" ? \"tool_calls\" : finishReason;\n\n return {\n content,\n finishReason: resolvedFinishReason,\n usage,\n toolCalls: mergedToolCalls.length > 0 ? mergedToolCalls : undefined,\n };\n }\n\n /**\n * Resolve the effective `streamingToolGuard` for this trip.\n * Per-call options win over the agent-level config when the key is\n * explicitly present on options (including the explicit `undefined`\n * \"disable for this call\" form). Returns `undefined` when no guard\n * should run.\n */\n private resolveStreamingToolGuard(): StreamingToolGuardConfig | undefined {\n if (\n this.options !== undefined &&\n Object.prototype.hasOwnProperty.call(this.options, \"streamingToolGuard\")\n ) {\n return this.options.streamingToolGuard;\n }\n\n return this.config.streamingToolGuard;\n }\n\n /**\n * Dispatch a single tool call requested by the model. Looks up the tool\n * by name, invokes it via the safe `ToolContract.invoke` entry, pushes a\n * matching tool-result message into `this.messages` so the next trip can\n * see it, and emits the right lifecycle event (`tool-called` on success,\n * `tool-calling-failed` when the tool is unregistered or invoke returned\n * an error). Never throws — always returns a `ToolCall` record.\n */\n private async dispatchToolCall(\n toolCallRequest: ModelToolCallRequest,\n tripIndex: number,\n ): Promise<ToolCall> {\n const registeredTool = this.config.tools?.find((tool) => tool.name === toolCallRequest.name);\n\n if (!registeredTool) {\n const error = new AgentExecutionError(`Tool not registered: ${toolCallRequest.name}`, {\n context: { toolName: toolCallRequest.name, tripIndex },\n });\n\n const nowIso = new Date().toISOString();\n\n const record: ToolCall = {\n runId: generateRunId(\"tool\"),\n rootRunId: this.runId,\n name: toolCallRequest.name,\n type: \"tool\",\n status: \"failed\",\n startedAt: nowIso,\n endedAt: nowIso,\n duration: 0,\n usage: { input: 0, output: 0, total: 0 },\n children: [],\n tripIndex,\n input: toolCallRequest.input,\n error,\n ...(toolCallRequest.recoveredFrom ? { recoveredFrom: toolCallRequest.recoveredFrom } : {}),\n };\n\n this.toolCalls.push(record);\n\n this.messages.push({\n role: \"tool\",\n toolCallId: toolCallRequest.id,\n content: JSON.stringify({ error: error.message }),\n });\n\n // Stub meta — there's no real tool to describe. Carries the\n // requested name for log correlation and an explanatory\n // description so consumers don't see an empty string.\n this.emit(\"agent.tool.failed\", {\n tool: {\n name: toolCallRequest.name,\n description: \"(unregistered tool — no description available)\",\n },\n input: toolCallRequest.input,\n error,\n tripIndex,\n });\n\n return record;\n }\n\n // Build the lightweight event meta once. Resolves `action` to a\n // string here so consumers receive plain data rather than having\n // to re-evaluate a callback on every event.\n const toolMeta: ToolEventMeta = {\n name: registeredTool.name,\n description: registeredTool.description,\n action: resolveToolAction(registeredTool, toolCallRequest.input),\n };\n\n this.emit(\"agent.tool.calling\", {\n tool: toolMeta,\n input: toolCallRequest.input,\n tripIndex,\n });\n\n const toolContext: MiddlewareToolContext = {\n ...this.buildExecuteContext(),\n tripIndex,\n messages: this.messages,\n tool: {\n name: registeredTool.name,\n description: registeredTool.description,\n mode: registeredTool.mode,\n },\n request: toolCallRequest,\n };\n\n let invokeResult: ToolInvokeResult<unknown>;\n\n try {\n invokeResult = (await runPipeline(\n this.middleware,\n \"tool\",\n toolContext,\n () => registeredTool.invoke(toolCallRequest.input, this.options?.toolCtx),\n this.logger,\n )) as ToolInvokeResult<unknown>;\n } catch (thrown) {\n // A `tool`-level middleware hook threw. The real invoke never\n // throws (it funnels errors into `result.error`), so only a\n // middleware abort or a bug reaches this branch. Synthesize a\n // failed-invoke record so the tool-call trace stays consistent.\n const error = this.toAIError(thrown);\n const nowIso = new Date().toISOString();\n const emptyUsage: Usage = { input: 0, output: 0, total: 0 };\n\n const failedRunId = generateRunId(\"tool\");\n invokeResult = {\n error,\n usage: emptyUsage,\n report: {\n runId: failedRunId,\n rootRunId: failedRunId,\n name: registeredTool.name,\n version: registeredTool.version,\n type: \"tool\",\n status: \"failed\",\n startedAt: nowIso,\n endedAt: nowIso,\n duration: 0,\n usage: emptyUsage,\n children: [],\n },\n };\n }\n\n // The agent-level ToolCall record merges the tool's own invocation\n // report with agent-side enrichments (tripIndex, input, output,\n // error). When the underlying tool was an `asTool`-wrapped\n // composite, its inner report becomes the sole child of this\n // ToolCall — preserving the full nested tree while keeping this\n // node's own `type` as `\"tool\"` (from the agent's POV it *was* a\n // tool dispatch).\n const innerReport = invokeResult.report;\n const isComposite = innerReport.type !== \"tool\";\n\n const record: ToolCall = {\n runId: innerReport.runId,\n rootRunId: this.runId,\n name: toolCallRequest.name,\n version: registeredTool.version,\n type: \"tool\",\n status: innerReport.status,\n startedAt: innerReport.startedAt,\n endedAt: innerReport.endedAt,\n duration: innerReport.duration,\n usage: invokeResult.usage,\n children: isComposite ? [innerReport] : innerReport.children,\n tripIndex,\n input: toolCallRequest.input,\n output: invokeResult.data,\n error: invokeResult.error,\n ...(toolCallRequest.recoveredFrom ? { recoveredFrom: toolCallRequest.recoveredFrom } : {}),\n };\n\n this.toolCalls.push(record);\n\n // Roll child usage into the agent's accumulator. Leaf tools\n // contribute zero; `asTool`-wrapped composites contribute the\n // full cost of the inner agent/workflow/supervisor run.\n this.usage.input += invokeResult.usage.input;\n this.usage.output += invokeResult.usage.output;\n this.usage.total += invokeResult.usage.total;\n this.usage.cost = accumulateCost(this.usage.cost, invokeResult.usage.cost);\n\n this.messages.push({\n role: \"tool\",\n toolCallId: toolCallRequest.id,\n content: invokeResult.error\n ? JSON.stringify({ error: invokeResult.error.message })\n : JSON.stringify(invokeResult.data ?? null),\n });\n\n if (invokeResult.error) {\n this.emit(\"agent.tool.failed\", {\n tool: toolMeta,\n input: toolCallRequest.input,\n error: invokeResult.error,\n tripIndex,\n });\n } else {\n this.emit(\"agent.tool.called\", { ...record, tool: toolMeta });\n }\n\n return record;\n }\n\n /**\n * Parse the final trip output against the user-supplied schema (if any).\n * Failures populate `this.error` but never throw. Returns an outcome the\n * caller uses to decide whether self-repair is worth attempting:\n *\n * - `\"skipped\"` — no schema, or a prior trip-level error already set\n * `this.error` (model crash, max trips). Not repairable; the failure\n * isn't a parse problem the model can fix by re-asking.\n * - `\"failed\"` — schema present, output text either failed JSON.parse\n * or failed `~standard.validate`. Repairable via `runRepairLoop`.\n * - `\"success\"` — parsed and validated; `this.data` populated.\n */\n private async parseOutput(): Promise<\"success\" | \"failed\" | \"skipped\"> {\n const schema = this.options?.output ?? this.config.output;\n\n if (!schema || this.error) {\n return \"skipped\";\n }\n\n const finalTrip = this.trips[this.trips.length - 1];\n const text = finalTrip?.output ?? \"\";\n\n if (!text) {\n return \"skipped\";\n }\n\n const payload = extractJsonPayload(text);\n const sentinel = Symbol(\"parse-failed\");\n const parsed = safeJsonParse<unknown>(payload, sentinel);\n\n if (parsed === sentinel) {\n this.error = new SchemaValidationError(\"Failed to parse model output as JSON\", {\n context: { text },\n });\n return \"failed\";\n }\n\n const validation = await (schema as StandardSchemaV1<TOutput>)[\"~standard\"].validate(parsed);\n\n if (validation.issues) {\n const summary = validation.issues.map((issue) => issue.message).join(\"; \");\n this.error = new SchemaValidationError(summary, {\n issues: validation.issues,\n });\n return \"failed\";\n }\n\n this.data = validation.value;\n return \"success\";\n }\n\n /**\n * Opt-in self-repair loop for `output` schema failures. Triggered only\n * when `options.repair` is set and `parseOutput()` returned `\"failed\"`.\n *\n * Each attempt:\n * 1. Pushes the bad assistant response into `this.messages` (so the\n * model can see what it just produced).\n * 2. Pushes a corrective user message naming the validation/parse error.\n * 3. Runs another trip — counted against the same `maxTrips` cap as\n * normal trips so a stuck model can't loop forever.\n * 4. Re-parses. Stops on success, on a trip-level error, or when\n * either `maxAttempts` or `maxTrips` is exhausted.\n *\n * Resets `this.error` and `this.data` before each attempt so the final\n * outcome (success or last failure) is what surfaces to the caller.\n */\n private async runRepairLoop(): Promise<void> {\n const maxAttempts = this.options?.repair?.maxAttempts ?? 1;\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n if (this.trips.length >= this.maxTrips) {\n return;\n }\n\n const lastTrip = this.trips[this.trips.length - 1];\n const badResponse = lastTrip?.output ?? \"\";\n const failureReason = this.error?.message ?? \"unknown validation failure\";\n\n this.error = undefined;\n this.data = undefined;\n\n this.messages.push({ role: \"assistant\", content: badResponse });\n\n this.messages.push({\n role: \"user\",\n content: [\n `Your previous response failed validation: ${failureReason}.`,\n \"Respond again with valid JSON only — no prose, no markdown fences, no commentary.\",\n ].join(\" \"),\n });\n\n const tripIndex = this.trips.length;\n\n this.logger.warn(LOG_MODULE, \"repair.attempting\", \"retrying after validation failure\", {\n attempt: attempt + 1,\n maxAttempts,\n reason: failureReason,\n });\n\n const outcome = await this.runTrip(tripIndex, \"[repair attempt]\");\n\n if (outcome === \"error\") {\n return;\n }\n\n const parseOutcome = await this.parseOutput();\n\n if (parseOutcome === \"success\") {\n return;\n }\n }\n }\n\n /**\n * Build the final `AgentResult` snapshot from accumulated state\n * (trips, tool calls, data/error, usage, timing).\n *\n * Pure — no side effects. `run()` owns terminal event emission and\n * stream closure so the post-pipeline result (possibly transformed\n * or short-circuited by an `execute`-level middleware) is what\n * flows out to consumers and listeners.\n *\n * Trips, tool calls, status, and timing live under `report` so the\n * root stays focused on the four things callers reach for most:\n * `data`, `text`, `usage`, `error`.\n */\n private buildResult(): AgentResult<TOutput> {\n const finalTrip = this.trips[this.trips.length - 1];\n const endedAt = new Date();\n\n const agentName = this.config.name ?? this.config.model.name;\n const status: BaseReport[\"status\"] = this.error\n ? this.error instanceof AgentCancelledError\n ? \"cancelled\"\n : \"failed\"\n : \"completed\";\n\n const report = {\n runId: this.runId,\n rootRunId: this.runId,\n name: agentName,\n version: this.config.version,\n type: \"agent\" as const,\n status,\n startedAt: this.startedAt.toISOString(),\n endedAt: endedAt.toISOString(),\n duration: performance.now() - this.start,\n usage: this.usage,\n children: this.toolCalls,\n model: {\n name: this.config.model.name,\n provider: this.config.model.provider,\n },\n trips: this.trips,\n };\n\n // Stamp lineage on the assembled tree exactly once per run.\n // Rewrites any inner self-roots from composite children to this\n // run's id, stamps `reportSchemaVersion` on the root, and\n // propagates `sessionId` to every node.\n stampReportLineage(report, {\n rootRunId: this.runId,\n sessionId: this.options?.sessionId,\n });\n\n return {\n type: \"agent\",\n data: this.data,\n text: finalTrip?.output,\n report,\n usage: this.usage,\n error: this.error,\n };\n }\n\n /**\n * Normalize any thrown value into an `AIError`. `AIError` instances\n * pass through untouched; provider-adapter SDK errors are caught by\n * the adapter and already arrive typed, so this branch mainly\n * handles runtime crashes (TypeError, ReferenceError) inside\n * model.complete / model.stream and non-Error values (`throw \"bad\"`).\n */\n private toAIError(thrown: unknown): AIError {\n if (thrown instanceof AIError) {\n return thrown;\n }\n\n // Classify abort-flavored errors (DOMException \"AbortError\",\n // node-fetch's `FetchError` with name \"AbortError\", `ERR_CANCELED`\n // from the OpenAI SDK's axios-ish layer) as cancelled instead of\n // a generic exec failure so callers can route retries correctly.\n if (isAbortLike(thrown)) {\n return this.makeCancelledError();\n }\n\n const message = thrown instanceof Error ? thrown.message : String(thrown);\n\n return new AgentExecutionError(message, { cause: thrown });\n }\n\n /**\n * Build the typed cancelled error that both the trip-loop guard\n * and the mid-stream guard emit. Captures the abort reason when\n * one was supplied to `controller.abort(reason)` so logs and\n * telemetry can see what cancelled the run.\n */\n private makeCancelledError(): AgentCancelledError {\n const reason = this.options?.signal?.reason;\n const reasonText = reason === undefined ? \"\" : String(reason);\n\n return new AgentCancelledError(\"agent execution cancelled\", {\n cause: reason,\n cancelledAt: new Date().toISOString(),\n reason: reasonText,\n });\n }\n\n /**\n * Fire a single event through all three subscription tiers in order\n * — factory → instance → per-call — and mirror it into the\n * `StreamController` when streaming is active. A throwing user\n * handler must never crash the agent, so every dispatch is wrapped\n * in `safeCall`. Stream events are converted from the internal\n * `AgentEventMap` payload to the public `StreamEvent` shape because\n * some of them differ (e.g. the tool-called payload vs stream\n * event).\n */\n private emit<K extends keyof AgentEventMap>(\n event: K,\n payload: WithoutIdentity<AgentEventMap[K]>,\n ): void {\n // Inject run identity once, here, so every subscription tier and\n // the stream see it. `rootRunId === runId` for a standalone run;\n // nested propagation lands in a follow-up.\n const fullPayload = {\n ...payload,\n runId: this.runId,\n rootRunId: this.runId,\n } as AgentEventMap[K];\n\n this.logEvent(event, fullPayload);\n\n const factoryHandler = this.config.on?.[event] as AgentEventHandler<K> | undefined;\n\n if (factoryHandler) {\n safeCall(factoryHandler, fullPayload);\n }\n\n const bucket = this.instanceHandlers?.get(event);\n\n if (bucket) {\n for (const handler of bucket) {\n safeCall(handler as AgentEventHandler<K>, fullPayload);\n }\n }\n\n const perCallHandler = this.options?.on?.[event] as AgentEventHandler<K> | undefined;\n\n if (perCallHandler) {\n safeCall(perCallHandler, fullPayload);\n }\n\n if (this.streamController) {\n const body = this.toStreamEvent(event, fullPayload);\n\n if (body) {\n this.streamController.push({\n runId: this.runId,\n rootRunId: this.runId,\n ...body,\n });\n }\n }\n }\n\n /**\n * Emit a structured log line for a lifecycle event. The action\n * string mirrors the event name with the `agent.` prefix stripped\n * (`agent.trip.started` → `trip.started`) so log grep filters and\n * event handlers read the same vocabulary. Level mapping follows\n * the convention documented on `@warlock.js/logger`'s `Logger`.\n */\n private logEvent<K extends keyof AgentEventMap>(event: K, payload: AgentEventMap[K]): void {\n const agentName = this.config.name || this.config.model.name;\n logAgentEvent(\n this.logger,\n {\n module: `${LOG_MODULE}.${agentName}`,\n maxTrips: this.maxTrips,\n modelName: this.config.model.name,\n totalUsage: this.usage,\n totalDurationMs: performance.now() - this.start,\n trips: this.trips,\n toolCalls: this.toolCalls,\n },\n event,\n payload,\n );\n }\n\n private toStreamEvent<K extends keyof AgentEventMap>(\n event: K,\n payload: AgentEventMap[K],\n ): StreamEventBody | undefined {\n return agentEventToStreamEvent(event, payload);\n }\n\n /**\n * Invoke the `onUsage` hook (when configured) with a flat payload\n * carrying stable identity. Awaits the handler so async ledger\n * writes complete before the next trip starts; swallows any throw\n * so consumer bugs cannot crash the agent. Sync handlers wrapped\n * via `Promise.resolve()` so the await is safe in either case.\n */\n private async fireUsageHook(tripIndex: number, tripUsage: Usage): Promise<void> {\n const handler = this.config.onUsage;\n if (!handler) return;\n\n const event: UsageEvent = {\n runId: this.runId,\n tripIndex,\n model: {\n name: this.config.model.name,\n provider: this.config.model.provider,\n },\n usage: { ...tripUsage },\n timestamp: new Date().toISOString(),\n };\n\n try {\n await Promise.resolve(handler(event));\n } catch (err) {\n this.logger.warn(LOG_MODULE, \"onUsage.hook.error\", \"onUsage handler threw\", {\n runId: this.runId,\n tripIndex,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n\n /**\n * Invoke the `onComplete` hook (when configured) once at the end\n * of every run. Receives the full `AgentResult` plus pre-extracted\n * `runId` and `durationMs`. Same swallow-and-log error policy as\n * `fireUsageHook`.\n */\n private async fireCompleteHook(result: AgentResult<TOutput>): Promise<void> {\n const handler = this.config.onComplete;\n if (!handler) return;\n\n const event: CompleteEvent<TOutput> = {\n result,\n runId: this.runId,\n durationMs: performance.now() - this.start,\n };\n\n try {\n await Promise.resolve(handler(event));\n } catch (err) {\n this.logger.warn(LOG_MODULE, \"onComplete.hook.error\", \"onComplete handler threw\", {\n runId: this.runId,\n error: err instanceof Error ? err.message : String(err),\n });\n }\n }\n}\n\n/**\n * Decide whether a guard-synthesized tool call duplicates a real one\n * the provider already streamed structurally. Match key is\n * `name + key-sorted JSON of input` so identical calls (regardless of\n * argument key order) collapse, but two legitimate calls to the same\n * tool with different inputs still both dispatch.\n */\nfunction isDuplicateToolCall(\n recovered: ModelToolCallRequest,\n realCalls: ReadonlyArray<ModelToolCallRequest>,\n): boolean {\n const recoveredKey = `${recovered.name}|${stableStringify(recovered.input)}`;\n\n for (const real of realCalls) {\n const realKey = `${real.name}|${stableStringify(real.input)}`;\n\n if (realKey === recoveredKey) {\n return true;\n }\n }\n\n return false;\n}\n\n/**\n * `JSON.stringify` variant that sorts object keys at every nesting\n * level so structurally-equal inputs serialize to identical strings.\n * Used only for dedupe-key comparison; never surfaces to consumers.\n */\nfunction stableStringify(value: unknown): string {\n return JSON.stringify(value, (_key, val) => {\n if (val !== null && typeof val === \"object\" && !Array.isArray(val)) {\n const source = val as Record<string, unknown>;\n const sorted: Record<string, unknown> = {};\n\n for (const key of Object.keys(source).sort()) {\n sorted[key] = source[key];\n }\n\n return sorted;\n }\n\n return val;\n });\n}\n\n/**\n * Invoke a user-supplied event handler without letting exceptions\n * escape the agent. Thrown errors are swallowed — structured logging\n * attaches here in Phase 0.5 so operators still see the failure.\n */\nfunction safeCall<T>(handler: (payload: T) => void, payload: T): void {\n try {\n handler(payload);\n } catch {\n // Intentionally swallowed — user handlers never crash the agent.\n }\n}\n\n/**\n * Resolve a tool's `action` declaration into a plain string for\n * inclusion in `ToolEventMeta`. Static strings pass through;\n * function-shaped actions are invoked with the validated input.\n *\n * Defensive: if the user's callback throws, swallow and return\n * `undefined` rather than crashing the agent — UI strings are not\n * worth aborting an LLM dispatch over.\n */\nfunction resolveToolAction(\n tool: ToolContract<unknown, unknown>,\n input: unknown,\n): string | undefined {\n if (tool.action === undefined) return undefined;\n if (typeof tool.action === \"string\") return tool.action;\n try {\n return tool.action(input);\n } catch {\n return undefined;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAM,aAAa;;;;;;;AAQnB,SAAS,YAAY,KAAuB;CAC1C,IAAI,CAAC,OAAO,OAAO,QAAQ,UAAU,OAAO;CAE5C,MAAM,IAAI;CAEV,OAAO,EAAE,SAAS,gBAAgB,EAAE,SAAS,kBAAkB,EAAE,SAAS;AAC5E;;;;;;;;;;AAWA,SAAS,oBAAuB,QAAgC;CAC9D,MAAM,WAAY,OAAO,OAA4C,YAAY;CACjF,MAAM,QAAQ,OAAO,OAAO,QAAQ;CACpC,MAAM,SAAS,OAAO,SAAS,CAAC,EAAC,CAC9B,KAAK,SAAS,KAAK,IAAI,CAAC,CACxB,KAAK,CAAC,CACN,KAAK,GAAG;CAEX,MAAM,OAAO,QAAQ,SAAS,QAAQ,EAAE,GAAG,SAAS,KAAK;CACzD,OAAO,QAAQ,GAAG,KAAK,GAAG,SAAS,OAAO,EAAE,UAAU,KAAK,CAAC,MA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