@warlock.js/ai 4.1.1
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/README.md +72 -0
- package/cjs/index.cjs +8625 -0
- package/cjs/index.cjs.map +1 -0
- package/esm/agent/agent-config.type.d.mts +160 -0
- package/esm/agent/agent-config.type.d.mts.map +1 -0
- package/esm/agent/agent-input-builder.mjs +111 -0
- package/esm/agent/agent-input-builder.mjs.map +1 -0
- package/esm/agent/agent-log-event.mjs +101 -0
- package/esm/agent/agent-log-event.mjs.map +1 -0
- package/esm/agent/agent-stream.d.mts +47 -0
- package/esm/agent/agent-stream.d.mts.map +1 -0
- package/esm/agent/agent-stream.mjs +82 -0
- package/esm/agent/agent-stream.mjs.map +1 -0
- package/esm/agent/agent-to-stream-event.mjs +86 -0
- package/esm/agent/agent-to-stream-event.mjs.map +1 -0
- package/esm/agent/agent.d.mts +38 -0
- package/esm/agent/agent.d.mts.map +1 -0
- package/esm/agent/agent.mjs +974 -0
- package/esm/agent/agent.mjs.map +1 -0
- package/esm/agent/index.d.mts +3 -0
- package/esm/agent/index.mjs +4 -0
- package/esm/agent/json-stream-guard.mjs +400 -0
- package/esm/agent/json-stream-guard.mjs.map +1 -0
- package/esm/ai.d.mts +64 -0
- package/esm/ai.d.mts.map +1 -0
- package/esm/ai.mjs +65 -0
- package/esm/ai.mjs.map +1 -0
- package/esm/config.d.mts +79 -0
- package/esm/config.d.mts.map +1 -0
- package/esm/config.mjs +43 -0
- package/esm/config.mjs.map +1 -0
- package/esm/contracts/agent/agent-options.type.d.mts +132 -0
- package/esm/contracts/agent/agent-options.type.d.mts.map +1 -0
- package/esm/contracts/agent/agent.contract.d.mts +92 -0
- package/esm/contracts/agent/agent.contract.d.mts.map +1 -0
- package/esm/contracts/agent/index.d.mts +2 -0
- package/esm/contracts/attachment.type.d.mts +100 -0
- package/esm/contracts/attachment.type.d.mts.map +1 -0
- package/esm/contracts/content-part.type.d.mts +55 -0
- package/esm/contracts/content-part.type.d.mts.map +1 -0
- package/esm/contracts/conversation-message.type.d.mts +51 -0
- package/esm/contracts/conversation-message.type.d.mts.map +1 -0
- package/esm/contracts/embedder.contract.d.mts +69 -0
- package/esm/contracts/embedder.contract.d.mts.map +1 -0
- package/esm/contracts/end.type.d.mts +53 -0
- package/esm/contracts/end.type.d.mts.map +1 -0
- package/esm/contracts/end.type.mjs +47 -0
- package/esm/contracts/end.type.mjs.map +1 -0
- package/esm/contracts/events/agent-events.type.d.mts +71 -0
- package/esm/contracts/events/agent-events.type.d.mts.map +1 -0
- package/esm/contracts/events/complete-event.type.d.mts +33 -0
- package/esm/contracts/events/complete-event.type.d.mts.map +1 -0
- package/esm/contracts/events/event-identity.type.d.mts +30 -0
- package/esm/contracts/events/event-identity.type.d.mts.map +1 -0
- package/esm/contracts/events/event-map.type.d.mts +80 -0
- package/esm/contracts/events/event-map.type.d.mts.map +1 -0
- package/esm/contracts/events/index.d.mts +7 -0
- package/esm/contracts/events/supervisor-events.type.d.mts +162 -0
- package/esm/contracts/events/supervisor-events.type.d.mts.map +1 -0
- package/esm/contracts/events/usage-event.type.d.mts +39 -0
- package/esm/contracts/events/usage-event.type.d.mts.map +1 -0
- package/esm/contracts/events/workflow-events.type.d.mts +51 -0
- package/esm/contracts/events/workflow-events.type.d.mts.map +1 -0
- package/esm/contracts/executable.contract.d.mts +25 -0
- package/esm/contracts/executable.contract.d.mts.map +1 -0
- package/esm/contracts/finish-reason.type.d.mts +17 -0
- package/esm/contracts/finish-reason.type.d.mts.map +1 -0
- package/esm/contracts/index.d.mts +63 -0
- package/esm/contracts/middleware/index.d.mts +3 -0
- package/esm/contracts/middleware/middleware-context.type.d.mts +99 -0
- package/esm/contracts/middleware/middleware-context.type.d.mts.map +1 -0
- package/esm/contracts/middleware/middleware-state.type.d.mts +34 -0
- package/esm/contracts/middleware/middleware-state.type.d.mts.map +1 -0
- package/esm/contracts/middleware/middleware.contract.d.mts +140 -0
- package/esm/contracts/middleware/middleware.contract.d.mts.map +1 -0
- package/esm/contracts/model-tool-call-request.type.d.mts +58 -0
- package/esm/contracts/model-tool-call-request.type.d.mts.map +1 -0
- package/esm/contracts/model.contract.d.mts +164 -0
- package/esm/contracts/model.contract.d.mts.map +1 -0
- package/esm/contracts/placeholders.type.d.mts +23 -0
- package/esm/contracts/placeholders.type.d.mts.map +1 -0
- package/esm/contracts/result/agent-result.type.d.mts +33 -0
- package/esm/contracts/result/agent-result.type.d.mts.map +1 -0
- package/esm/contracts/result/attempt-entry.type.d.mts +40 -0
- package/esm/contracts/result/attempt-entry.type.d.mts.map +1 -0
- package/esm/contracts/result/base-report.type.d.mts +137 -0
- package/esm/contracts/result/base-report.type.d.mts.map +1 -0
- package/esm/contracts/result/base-report.type.mjs +17 -0
- package/esm/contracts/result/base-report.type.mjs.map +1 -0
- package/esm/contracts/result/base-result.type.d.mts +26 -0
- package/esm/contracts/result/base-result.type.d.mts.map +1 -0
- package/esm/contracts/result/execute-result.type.d.mts +40 -0
- package/esm/contracts/result/execute-result.type.d.mts.map +1 -0
- package/esm/contracts/result/execution-report.type.d.mts +50 -0
- package/esm/contracts/result/execution-report.type.d.mts.map +1 -0
- package/esm/contracts/result/index.d.mts +14 -0
- package/esm/contracts/result/llm-trip.type.d.mts +36 -0
- package/esm/contracts/result/llm-trip.type.d.mts.map +1 -0
- package/esm/contracts/result/model-pricing.type.d.mts +51 -0
- package/esm/contracts/result/model-pricing.type.d.mts.map +1 -0
- package/esm/contracts/result/session-send-result.type.d.mts +29 -0
- package/esm/contracts/result/session-send-result.type.d.mts.map +1 -0
- package/esm/contracts/result/step-result.type.d.mts +43 -0
- package/esm/contracts/result/step-result.type.d.mts.map +1 -0
- package/esm/contracts/result/supervisor-result.type.d.mts +86 -0
- package/esm/contracts/result/supervisor-result.type.d.mts.map +1 -0
- package/esm/contracts/result/tool-call.type.d.mts +44 -0
- package/esm/contracts/result/tool-call.type.d.mts.map +1 -0
- package/esm/contracts/result/usage.type.d.mts +57 -0
- package/esm/contracts/result/usage.type.d.mts.map +1 -0
- package/esm/contracts/result/workflow-result.type.d.mts +45 -0
- package/esm/contracts/result/workflow-result.type.d.mts.map +1 -0
- package/esm/contracts/sdk-adapter.contract.d.mts +77 -0
- package/esm/contracts/sdk-adapter.contract.d.mts.map +1 -0
- package/esm/contracts/stream/stream-event.type.d.mts +68 -0
- package/esm/contracts/stream/stream-event.type.d.mts.map +1 -0
- package/esm/contracts/stream/stream.contract.d.mts +61 -0
- package/esm/contracts/stream/stream.contract.d.mts.map +1 -0
- package/esm/contracts/streaming-tool-guard-config.type.d.mts +78 -0
- package/esm/contracts/streaming-tool-guard-config.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/ack-entry.type.d.mts +97 -0
- package/esm/contracts/supervisor/ack-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/classifier-context.type.d.mts +189 -0
- package/esm/contracts/supervisor/classifier-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/dispatch-context.type.d.mts +235 -0
- package/esm/contracts/supervisor/dispatch-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/evaluate-context.type.d.mts +124 -0
- package/esm/contracts/supervisor/evaluate-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/index.d.mts +16 -0
- package/esm/contracts/supervisor/intent-entry.type.d.mts +254 -0
- package/esm/contracts/supervisor/intent-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts +117 -0
- package/esm/contracts/supervisor/iteration-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/next.type.d.mts +25 -0
- package/esm/contracts/supervisor/next.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/route-context.type.d.mts +91 -0
- package/esm/contracts/supervisor/route-context.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/router-entry.type.d.mts +67 -0
- package/esm/contracts/supervisor/router-entry.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts +356 -0
- package/esm/contracts/supervisor/supervisor-config.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts +90 -0
- package/esm/contracts/supervisor/supervisor-execute-options.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-input.type.d.mts +24 -0
- package/esm/contracts/supervisor/supervisor-input.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts +49 -0
- package/esm/contracts/supervisor/supervisor-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts +16 -0
- package/esm/contracts/supervisor/supervisor-stream-event.type.d.mts.map +1 -0
- package/esm/contracts/supervisor/supervisor.contract.d.mts +126 -0
- package/esm/contracts/supervisor/supervisor.contract.d.mts.map +1 -0
- package/esm/contracts/system-prompt.contract.d.mts +118 -0
- package/esm/contracts/system-prompt.contract.d.mts.map +1 -0
- package/esm/contracts/tool.contract.d.mts +161 -0
- package/esm/contracts/tool.contract.d.mts.map +1 -0
- package/esm/contracts/workflow/index.d.mts +6 -0
- package/esm/contracts/workflow/next-step-result.type.d.mts +17 -0
- package/esm/contracts/workflow/next-step-result.type.d.mts.map +1 -0
- package/esm/contracts/workflow/retry-config.type.d.mts +19 -0
- package/esm/contracts/workflow/retry-config.type.d.mts.map +1 -0
- package/esm/contracts/workflow/step.contract.d.mts +189 -0
- package/esm/contracts/workflow/step.contract.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow-context.type.d.mts +45 -0
- package/esm/contracts/workflow/workflow-context.type.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts +24 -0
- package/esm/contracts/workflow/workflow-snapshot.type.d.mts.map +1 -0
- package/esm/contracts/workflow/workflow.contract.d.mts +142 -0
- package/esm/contracts/workflow/workflow.contract.d.mts.map +1 -0
- package/esm/errors/agent-cancelled-error.d.mts +49 -0
- package/esm/errors/agent-cancelled-error.d.mts.map +1 -0
- package/esm/errors/agent-cancelled-error.mjs +43 -0
- package/esm/errors/agent-cancelled-error.mjs.map +1 -0
- package/esm/errors/agent-execution-error.d.mts +32 -0
- package/esm/errors/agent-execution-error.d.mts.map +1 -0
- package/esm/errors/agent-execution-error.mjs +35 -0
- package/esm/errors/agent-execution-error.mjs.map +1 -0
- package/esm/errors/agent-max-trips-error.d.mts +45 -0
- package/esm/errors/agent-max-trips-error.d.mts.map +1 -0
- package/esm/errors/agent-max-trips-error.mjs +41 -0
- package/esm/errors/agent-max-trips-error.mjs.map +1 -0
- package/esm/errors/ai-error.d.mts +94 -0
- package/esm/errors/ai-error.d.mts.map +1 -0
- package/esm/errors/ai-error.mjs +68 -0
- package/esm/errors/ai-error.mjs.map +1 -0
- package/esm/errors/budget-exceeded-error.d.mts +41 -0
- package/esm/errors/budget-exceeded-error.d.mts.map +1 -0
- package/esm/errors/budget-exceeded-error.mjs +31 -0
- package/esm/errors/budget-exceeded-error.mjs.map +1 -0
- package/esm/errors/content-filter-error.d.mts +33 -0
- package/esm/errors/content-filter-error.d.mts.map +1 -0
- package/esm/errors/content-filter-error.mjs +28 -0
- package/esm/errors/content-filter-error.mjs.map +1 -0
- package/esm/errors/context-length-exceeded-error.d.mts +38 -0
- package/esm/errors/context-length-exceeded-error.d.mts.map +1 -0
- package/esm/errors/context-length-exceeded-error.mjs +31 -0
- package/esm/errors/context-length-exceeded-error.mjs.map +1 -0
- package/esm/errors/error-category.type.d.mts +30 -0
- package/esm/errors/error-category.type.d.mts.map +1 -0
- package/esm/errors/error-code.type.d.mts +19 -0
- package/esm/errors/error-code.type.d.mts.map +1 -0
- package/esm/errors/guardrail-violation-error.d.mts +55 -0
- package/esm/errors/guardrail-violation-error.d.mts.map +1 -0
- package/esm/errors/guardrail-violation-error.mjs +41 -0
- package/esm/errors/guardrail-violation-error.mjs.map +1 -0
- package/esm/errors/index.d.mts +29 -0
- package/esm/errors/index.mjs +29 -0
- package/esm/errors/invalid-request-error.d.mts +27 -0
- package/esm/errors/invalid-request-error.d.mts.map +1 -0
- package/esm/errors/invalid-request-error.mjs +31 -0
- package/esm/errors/invalid-request-error.mjs.map +1 -0
- package/esm/errors/max-iterations-error.d.mts +31 -0
- package/esm/errors/max-iterations-error.d.mts.map +1 -0
- package/esm/errors/max-iterations-error.mjs +32 -0
- package/esm/errors/max-iterations-error.mjs.map +1 -0
- package/esm/errors/max-steps-exceeded-error.d.mts +20 -0
- package/esm/errors/max-steps-exceeded-error.d.mts.map +1 -0
- package/esm/errors/max-steps-exceeded-error.mjs +21 -0
- package/esm/errors/max-steps-exceeded-error.mjs.map +1 -0
- package/esm/errors/provider-auth-error.d.mts +22 -0
- package/esm/errors/provider-auth-error.d.mts.map +1 -0
- package/esm/errors/provider-auth-error.mjs +26 -0
- package/esm/errors/provider-auth-error.mjs.map +1 -0
- package/esm/errors/provider-error.d.mts +38 -0
- package/esm/errors/provider-error.d.mts.map +1 -0
- package/esm/errors/provider-error.mjs +42 -0
- package/esm/errors/provider-error.mjs.map +1 -0
- package/esm/errors/provider-rate-limit-error.d.mts +34 -0
- package/esm/errors/provider-rate-limit-error.d.mts.map +1 -0
- package/esm/errors/provider-rate-limit-error.mjs +31 -0
- package/esm/errors/provider-rate-limit-error.mjs.map +1 -0
- package/esm/errors/provider-timeout-error.d.mts +22 -0
- package/esm/errors/provider-timeout-error.d.mts.map +1 -0
- package/esm/errors/provider-timeout-error.mjs +26 -0
- package/esm/errors/provider-timeout-error.mjs.map +1 -0
- package/esm/errors/quota-exceeded-error.d.mts +36 -0
- package/esm/errors/quota-exceeded-error.d.mts.map +1 -0
- package/esm/errors/quota-exceeded-error.mjs +40 -0
- package/esm/errors/quota-exceeded-error.mjs.map +1 -0
- package/esm/errors/routing-error.d.mts +23 -0
- package/esm/errors/routing-error.d.mts.map +1 -0
- package/esm/errors/routing-error.mjs +23 -0
- package/esm/errors/routing-error.mjs.map +1 -0
- package/esm/errors/schema-validation-error.d.mts +40 -0
- package/esm/errors/schema-validation-error.d.mts.map +1 -0
- package/esm/errors/schema-validation-error.mjs +37 -0
- package/esm/errors/schema-validation-error.mjs.map +1 -0
- package/esm/errors/step-failed-error.d.mts +20 -0
- package/esm/errors/step-failed-error.d.mts.map +1 -0
- package/esm/errors/step-failed-error.mjs +19 -0
- package/esm/errors/step-failed-error.mjs.map +1 -0
- package/esm/errors/supervisor-cancelled-error.d.mts +29 -0
- package/esm/errors/supervisor-cancelled-error.d.mts.map +1 -0
- package/esm/errors/supervisor-cancelled-error.mjs +29 -0
- package/esm/errors/supervisor-cancelled-error.mjs.map +1 -0
- package/esm/errors/supervisor-drift-error.d.mts +31 -0
- package/esm/errors/supervisor-drift-error.d.mts.map +1 -0
- package/esm/errors/supervisor-drift-error.mjs +30 -0
- package/esm/errors/supervisor-drift-error.mjs.map +1 -0
- package/esm/errors/supervisor-failed-error.d.mts +40 -0
- package/esm/errors/supervisor-failed-error.d.mts.map +1 -0
- package/esm/errors/supervisor-failed-error.mjs +43 -0
- package/esm/errors/supervisor-failed-error.mjs.map +1 -0
- package/esm/errors/supervisor-routing-error.d.mts +44 -0
- package/esm/errors/supervisor-routing-error.d.mts.map +1 -0
- package/esm/errors/supervisor-routing-error.mjs +39 -0
- package/esm/errors/supervisor-routing-error.mjs.map +1 -0
- package/esm/errors/tool-execution-error.d.mts +35 -0
- package/esm/errors/tool-execution-error.d.mts.map +1 -0
- package/esm/errors/tool-execution-error.mjs +32 -0
- package/esm/errors/tool-execution-error.mjs.map +1 -0
- package/esm/errors/workflow-cancelled-error.d.mts +23 -0
- package/esm/errors/workflow-cancelled-error.d.mts.map +1 -0
- package/esm/errors/workflow-cancelled-error.mjs +23 -0
- package/esm/errors/workflow-cancelled-error.mjs.map +1 -0
- package/esm/errors/workflow-drift-error.d.mts +25 -0
- package/esm/errors/workflow-drift-error.d.mts.map +1 -0
- package/esm/errors/workflow-drift-error.mjs +24 -0
- package/esm/errors/workflow-drift-error.mjs.map +1 -0
- package/esm/errors/workflow-error.d.mts +15 -0
- package/esm/errors/workflow-error.d.mts.map +1 -0
- package/esm/errors/workflow-error.mjs +18 -0
- package/esm/errors/workflow-error.mjs.map +1 -0
- package/esm/index.d.mts +137 -0
- package/esm/index.mjs +81 -0
- package/esm/middleware/builtins/budget.d.mts +103 -0
- package/esm/middleware/builtins/budget.d.mts.map +1 -0
- package/esm/middleware/builtins/budget.mjs +100 -0
- package/esm/middleware/builtins/budget.mjs.map +1 -0
- package/esm/middleware/builtins/guardrail.d.mts +92 -0
- package/esm/middleware/builtins/guardrail.d.mts.map +1 -0
- package/esm/middleware/builtins/guardrail.mjs +76 -0
- package/esm/middleware/builtins/guardrail.mjs.map +1 -0
- package/esm/middleware/builtins/semantic-cache.d.mts +106 -0
- package/esm/middleware/builtins/semantic-cache.d.mts.map +1 -0
- package/esm/middleware/builtins/semantic-cache.mjs +149 -0
- package/esm/middleware/builtins/semantic-cache.mjs.map +1 -0
- package/esm/middleware/helpers/compose.d.mts +42 -0
- package/esm/middleware/helpers/compose.d.mts.map +1 -0
- package/esm/middleware/helpers/compose.mjs +52 -0
- package/esm/middleware/helpers/compose.mjs.map +1 -0
- package/esm/middleware/helpers/for-tool.d.mts +55 -0
- package/esm/middleware/helpers/for-tool.d.mts.map +1 -0
- package/esm/middleware/helpers/for-tool.mjs +80 -0
- package/esm/middleware/helpers/for-tool.mjs.map +1 -0
- package/esm/middleware/helpers/index.d.mts +2 -0
- package/esm/middleware/index.d.mts +8 -0
- package/esm/middleware/index.mjs +10 -0
- package/esm/middleware/pipeline.d.mts +70 -0
- package/esm/middleware/pipeline.d.mts.map +1 -0
- package/esm/middleware/pipeline.mjs +100 -0
- package/esm/middleware/pipeline.mjs.map +1 -0
- package/esm/middleware/utils/extract-user-text.d.mts +33 -0
- package/esm/middleware/utils/extract-user-text.d.mts.map +1 -0
- package/esm/middleware/utils/extract-user-text.mjs +40 -0
- package/esm/middleware/utils/extract-user-text.mjs.map +1 -0
- package/esm/middleware/utils/index.d.mts +2 -0
- package/esm/middleware/utils/namespaced-state.d.mts +60 -0
- package/esm/middleware/utils/namespaced-state.d.mts.map +1 -0
- package/esm/middleware/utils/namespaced-state.mjs +60 -0
- package/esm/middleware/utils/namespaced-state.mjs.map +1 -0
- package/esm/mock/index.d.mts +4 -0
- package/esm/mock/index.mjs +5 -0
- package/esm/mock/mock-agent.d.mts +41 -0
- package/esm/mock/mock-agent.d.mts.map +1 -0
- package/esm/mock/mock-agent.mjs +39 -0
- package/esm/mock/mock-agent.mjs.map +1 -0
- package/esm/mock/mock-config.type.d.mts +31 -0
- package/esm/mock/mock-config.type.d.mts.map +1 -0
- package/esm/mock/mock-model.d.mts +94 -0
- package/esm/mock/mock-model.d.mts.map +1 -0
- package/esm/mock/mock-model.mjs +150 -0
- package/esm/mock/mock-model.mjs.map +1 -0
- package/esm/mock/mock-sdk.d.mts +25 -0
- package/esm/mock/mock-sdk.d.mts.map +1 -0
- package/esm/mock/mock-sdk.mjs +37 -0
- package/esm/mock/mock-sdk.mjs.map +1 -0
- package/esm/supervisor/as-tool.d.mts +45 -0
- package/esm/supervisor/as-tool.d.mts.map +1 -0
- package/esm/supervisor/as-tool.mjs +80 -0
- package/esm/supervisor/as-tool.mjs.map +1 -0
- package/esm/supervisor/cancellation.d.mts +12 -0
- package/esm/supervisor/cancellation.d.mts.map +1 -0
- package/esm/supervisor/cancellation.mjs +22 -0
- package/esm/supervisor/cancellation.mjs.map +1 -0
- package/esm/supervisor/decide.mjs +272 -0
- package/esm/supervisor/decide.mjs.map +1 -0
- package/esm/supervisor/emitter.d.mts +27 -0
- package/esm/supervisor/emitter.d.mts.map +1 -0
- package/esm/supervisor/emitter.mjs +47 -0
- package/esm/supervisor/emitter.mjs.map +1 -0
- package/esm/supervisor/entries.d.mts +141 -0
- package/esm/supervisor/entries.d.mts.map +1 -0
- package/esm/supervisor/entries.mjs +206 -0
- package/esm/supervisor/entries.mjs.map +1 -0
- package/esm/supervisor/execution.d.mts +637 -0
- package/esm/supervisor/execution.d.mts.map +1 -0
- package/esm/supervisor/execution.mjs +1868 -0
- package/esm/supervisor/execution.mjs.map +1 -0
- package/esm/supervisor/index.d.mts +11 -0
- package/esm/supervisor/index.mjs +12 -0
- package/esm/supervisor/router-prompt.d.mts +56 -0
- package/esm/supervisor/router-prompt.d.mts.map +1 -0
- package/esm/supervisor/router-prompt.mjs +52 -0
- package/esm/supervisor/router-prompt.mjs.map +1 -0
- package/esm/supervisor/signature.d.mts +28 -0
- package/esm/supervisor/signature.d.mts.map +1 -0
- package/esm/supervisor/signature.mjs +89 -0
- package/esm/supervisor/signature.mjs.map +1 -0
- package/esm/supervisor/snapshot.d.mts +54 -0
- package/esm/supervisor/snapshot.d.mts.map +1 -0
- package/esm/supervisor/snapshot.mjs +77 -0
- package/esm/supervisor/snapshot.mjs.map +1 -0
- package/esm/supervisor/supervisor-stream.d.mts +29 -0
- package/esm/supervisor/supervisor-stream.d.mts.map +1 -0
- package/esm/supervisor/supervisor-stream.mjs +89 -0
- package/esm/supervisor/supervisor-stream.mjs.map +1 -0
- package/esm/supervisor/supervisor.d.mts +27 -0
- package/esm/supervisor/supervisor.d.mts.map +1 -0
- package/esm/supervisor/supervisor.mjs +138 -0
- package/esm/supervisor/supervisor.mjs.map +1 -0
- package/esm/system-prompt/instruction.d.mts +52 -0
- package/esm/system-prompt/instruction.d.mts.map +1 -0
- package/esm/system-prompt/instruction.mjs +57 -0
- package/esm/system-prompt/instruction.mjs.map +1 -0
- package/esm/system-prompt/persona.d.mts +52 -0
- package/esm/system-prompt/persona.d.mts.map +1 -0
- package/esm/system-prompt/persona.mjs +57 -0
- package/esm/system-prompt/persona.mjs.map +1 -0
- package/esm/system-prompt/render-placeholders.d.mts +31 -0
- package/esm/system-prompt/render-placeholders.d.mts.map +1 -0
- package/esm/system-prompt/render-placeholders.mjs +58 -0
- package/esm/system-prompt/render-placeholders.mjs.map +1 -0
- package/esm/system-prompt/system-prompt.d.mts +117 -0
- package/esm/system-prompt/system-prompt.d.mts.map +1 -0
- package/esm/system-prompt/system-prompt.mjs +137 -0
- package/esm/system-prompt/system-prompt.mjs.map +1 -0
- package/esm/tool/index.d.mts +1 -0
- package/esm/tool/index.mjs +3 -0
- package/esm/tool/tool.d.mts +64 -0
- package/esm/tool/tool.d.mts.map +1 -0
- package/esm/tool/tool.mjs +184 -0
- package/esm/tool/tool.mjs.map +1 -0
- package/esm/utils/compute-cost.d.mts +58 -0
- package/esm/utils/compute-cost.d.mts.map +1 -0
- package/esm/utils/compute-cost.mjs +87 -0
- package/esm/utils/compute-cost.mjs.map +1 -0
- package/esm/utils/extract-json-payload.d.mts +33 -0
- package/esm/utils/extract-json-payload.d.mts.map +1 -0
- package/esm/utils/extract-json-payload.mjs +39 -0
- package/esm/utils/extract-json-payload.mjs.map +1 -0
- package/esm/utils/generate-run-id.d.mts +20 -0
- package/esm/utils/generate-run-id.d.mts.map +1 -0
- package/esm/utils/generate-run-id.mjs +23 -0
- package/esm/utils/generate-run-id.mjs.map +1 -0
- package/esm/utils/index.d.mts +9 -0
- package/esm/utils/index.mjs +11 -0
- package/esm/utils/json-schema.d.mts +57 -0
- package/esm/utils/json-schema.d.mts.map +1 -0
- package/esm/utils/json-schema.mjs +89 -0
- package/esm/utils/json-schema.mjs.map +1 -0
- package/esm/utils/prepare-attachment-part.d.mts +36 -0
- package/esm/utils/prepare-attachment-part.d.mts.map +1 -0
- package/esm/utils/prepare-attachment-part.mjs +140 -0
- package/esm/utils/prepare-attachment-part.mjs.map +1 -0
- package/esm/utils/resolve-attachment.d.mts +33 -0
- package/esm/utils/resolve-attachment.d.mts.map +1 -0
- package/esm/utils/resolve-attachment.mjs +73 -0
- package/esm/utils/resolve-attachment.mjs.map +1 -0
- package/esm/utils/safe-json-parse.d.mts +14 -0
- package/esm/utils/safe-json-parse.d.mts.map +1 -0
- package/esm/utils/safe-json-parse.mjs +22 -0
- package/esm/utils/safe-json-parse.mjs.map +1 -0
- package/esm/utils/stamp-report-lineage.d.mts +61 -0
- package/esm/utils/stamp-report-lineage.d.mts.map +1 -0
- package/esm/utils/stamp-report-lineage.mjs +47 -0
- package/esm/utils/stamp-report-lineage.mjs.map +1 -0
- package/esm/utils/token-count.d.mts +15 -0
- package/esm/utils/token-count.d.mts.map +1 -0
- package/esm/utils/token-count.mjs +18 -0
- package/esm/utils/token-count.mjs.map +1 -0
- package/esm/workflow/as-tool.mjs +55 -0
- package/esm/workflow/as-tool.mjs.map +1 -0
- package/esm/workflow/cancellation.mjs +44 -0
- package/esm/workflow/cancellation.mjs.map +1 -0
- package/esm/workflow/emitter.mjs +40 -0
- package/esm/workflow/emitter.mjs.map +1 -0
- package/esm/workflow/engine.mjs +362 -0
- package/esm/workflow/engine.mjs.map +1 -0
- package/esm/workflow/index.d.mts +3 -0
- package/esm/workflow/index.mjs +5 -0
- package/esm/workflow/retry.mjs +32 -0
- package/esm/workflow/retry.mjs.map +1 -0
- package/esm/workflow/router.mjs +56 -0
- package/esm/workflow/router.mjs.map +1 -0
- package/esm/workflow/run-scoped-emitter.mjs +32 -0
- package/esm/workflow/run-scoped-emitter.mjs.map +1 -0
- package/esm/workflow/signature.d.mts +7 -0
- package/esm/workflow/signature.d.mts.map +1 -0
- package/esm/workflow/signature.mjs +34 -0
- package/esm/workflow/signature.mjs.map +1 -0
- package/esm/workflow/snapshot.mjs +71 -0
- package/esm/workflow/snapshot.mjs.map +1 -0
- package/esm/workflow/state.mjs +37 -0
- package/esm/workflow/state.mjs.map +1 -0
- package/esm/workflow/step-runner.mjs +371 -0
- package/esm/workflow/step-runner.mjs.map +1 -0
- package/esm/workflow/step.d.mts +19 -0
- package/esm/workflow/step.d.mts.map +1 -0
- package/esm/workflow/step.mjs +37 -0
- package/esm/workflow/step.mjs.map +1 -0
- package/esm/workflow/workflow.d.mts +12 -0
- package/esm/workflow/workflow.d.mts.map +1 -0
- package/esm/workflow/workflow.mjs +116 -0
- package/esm/workflow/workflow.mjs.map +1 -0
- package/llms-full.txt +2293 -0
- package/llms.txt +20 -0
- package/package.json +37 -0
- package/skills/README.md +53 -0
- package/skills/ai-basics/SKILL.md +95 -0
- package/skills/attach-ai-middleware/SKILL.md +184 -0
- package/skills/define-ai-tool/SKILL.md +186 -0
- package/skills/embed-text/SKILL.md +105 -0
- package/skills/handle-ai-errors/SKILL.md +194 -0
- package/skills/log-ai-calls/SKILL.md +141 -0
- package/skills/persist-ai-data/SKILL.md +207 -0
- package/skills/pick-ai-provider/SKILL.md +164 -0
- package/skills/run-ai-agent/SKILL.md +267 -0
- package/skills/run-ai-workflow/SKILL.md +258 -0
- package/skills/run-supervisor/SKILL.md +309 -0
- package/skills/write-system-prompt/SKILL.md +129 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { RoutingError } from "../errors/routing-error.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/ai/src/workflow/router.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolve the next step to run after `step` completes. Tries
|
|
7
|
+
* step-level `nextStep` first, then workflow-level, then falls
|
|
8
|
+
* through (returns `undefined`, engine picks the next declared step).
|
|
9
|
+
*
|
|
10
|
+
* Throws `RoutingError` when either callback throws — routing is
|
|
11
|
+
* authoritative, so a broken router terminates the workflow instead
|
|
12
|
+
* of being retried.
|
|
13
|
+
*/
|
|
14
|
+
async function resolveNextStep(params) {
|
|
15
|
+
const { step, definition, ctx } = params;
|
|
16
|
+
if (step.nextStep) {
|
|
17
|
+
let outcome;
|
|
18
|
+
try {
|
|
19
|
+
outcome = await step.nextStep(ctx);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
throw new RoutingError(`workflow "${definition.name}": step "${step.name}" nextStep threw`, {
|
|
22
|
+
stepName: step.name,
|
|
23
|
+
cause: err
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const mapped = mapNextStep(outcome);
|
|
27
|
+
if (mapped !== void 0) return mapped;
|
|
28
|
+
}
|
|
29
|
+
if (definition.nextStep) {
|
|
30
|
+
let outcome;
|
|
31
|
+
try {
|
|
32
|
+
outcome = await definition.nextStep(step.name, ctx);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
throw new RoutingError(`workflow "${definition.name}": workflow-level nextStep threw after "${step.name}"`, {
|
|
35
|
+
stepName: step.name,
|
|
36
|
+
cause: err
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const mapped = mapNextStep(outcome);
|
|
40
|
+
if (mapped !== void 0) return mapped;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function mapNextStep(outcome) {
|
|
44
|
+
if (!outcome) return void 0;
|
|
45
|
+
if ("end" in outcome && outcome.end === true) return "end";
|
|
46
|
+
if ("goto" in outcome && typeof outcome.goto === "string") return outcome.goto;
|
|
47
|
+
}
|
|
48
|
+
function nextDeclaredStep(definition, currentName) {
|
|
49
|
+
const idx = definition.steps.findIndex((s) => s.name === currentName);
|
|
50
|
+
if (idx === -1) return null;
|
|
51
|
+
return definition.steps[idx + 1]?.name ?? null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { mapNextStep, nextDeclaredStep, resolveNextStep };
|
|
56
|
+
//# sourceMappingURL=router.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/workflow/router.ts"],"sourcesContent":["import type { NextStepResult } from \"../contracts/workflow/next-step-result.type\";\nimport type { StepDefinition } from \"../contracts/workflow/step.contract\";\nimport type { WorkflowContext } from \"../contracts/workflow/workflow-context.type\";\nimport type { WorkflowDefinition } from \"../contracts/workflow/workflow.contract\";\nimport { RoutingError } from \"../errors\";\n\n/**\n * Resolve the next step to run after `step` completes. Tries\n * step-level `nextStep` first, then workflow-level, then falls\n * through (returns `undefined`, engine picks the next declared step).\n *\n * Throws `RoutingError` when either callback throws — routing is\n * authoritative, so a broken router terminates the workflow instead\n * of being retried.\n */\nexport async function resolveNextStep<T>(params: {\n step: StepDefinition;\n definition: WorkflowDefinition<any, T, any, any>;\n ctx: WorkflowContext;\n}): Promise<\"end\" | string | undefined> {\n const { step, definition, ctx } = params;\n\n if (step.nextStep) {\n let outcome: NextStepResult;\n try {\n outcome = await step.nextStep(ctx);\n } catch (err) {\n throw new RoutingError(\n `workflow \"${definition.name}\": step \"${step.name}\" nextStep threw`,\n { stepName: step.name, cause: err },\n );\n }\n const mapped = mapNextStep(outcome);\n if (mapped !== undefined) return mapped;\n }\n\n if (definition.nextStep) {\n let outcome: NextStepResult;\n try {\n outcome = await definition.nextStep(step.name, ctx);\n } catch (err) {\n throw new RoutingError(\n `workflow \"${definition.name}\": workflow-level nextStep threw after \"${step.name}\"`,\n { stepName: step.name, cause: err },\n );\n }\n const mapped = mapNextStep(outcome);\n if (mapped !== undefined) return mapped;\n }\n\n return undefined;\n}\n\nexport function mapNextStep(\n outcome: NextStepResult,\n): \"end\" | string | undefined {\n if (!outcome) return undefined;\n if (\"end\" in outcome && outcome.end === true) return \"end\";\n if (\"goto\" in outcome && typeof outcome.goto === \"string\")\n return outcome.goto;\n return undefined;\n}\n\nexport function nextDeclaredStep<T>(\n definition: WorkflowDefinition<any, T, any, any>,\n currentName: string,\n): string | null {\n const idx = definition.steps.findIndex(s => s.name === currentName);\n if (idx === -1) return null;\n return definition.steps[idx + 1]?.name ?? null;\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,eAAsB,gBAAmB,QAID;CACtC,MAAM,EAAE,MAAM,YAAY,QAAQ;CAElC,IAAI,KAAK,UAAU;EACjB,IAAI;EACJ,IAAI;GACF,UAAU,MAAM,KAAK,SAAS,GAAG;EACnC,SAAS,KAAK;GACZ,MAAM,IAAI,aACR,aAAa,WAAW,KAAK,WAAW,KAAK,KAAK,mBAClD;IAAE,UAAU,KAAK;IAAM,OAAO;GAAI,CACpC;EACF;EACA,MAAM,SAAS,YAAY,OAAO;EAClC,IAAI,WAAW,QAAW,OAAO;CACnC;CAEA,IAAI,WAAW,UAAU;EACvB,IAAI;EACJ,IAAI;GACF,UAAU,MAAM,WAAW,SAAS,KAAK,MAAM,GAAG;EACpD,SAAS,KAAK;GACZ,MAAM,IAAI,aACR,aAAa,WAAW,KAAK,0CAA0C,KAAK,KAAK,IACjF;IAAE,UAAU,KAAK;IAAM,OAAO;GAAI,CACpC;EACF;EACA,MAAM,SAAS,YAAY,OAAO;EAClC,IAAI,WAAW,QAAW,OAAO;CACnC;AAGF;AAEA,SAAgB,YACd,SAC4B;CAC5B,IAAI,CAAC,SAAS,OAAO;CACrB,IAAI,SAAS,WAAW,QAAQ,QAAQ,MAAM,OAAO;CACrD,IAAI,UAAU,WAAW,OAAO,QAAQ,SAAS,UAC/C,OAAO,QAAQ;AAEnB;AAEA,SAAgB,iBACd,YACA,aACe;CACf,MAAM,MAAM,WAAW,MAAM,WAAU,MAAK,EAAE,SAAS,WAAW;CAClE,IAAI,QAAQ,IAAI,OAAO;CACvB,OAAO,WAAW,MAAM,MAAM,IAAI,QAAQ;AAC5C"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region ../../@warlock.js/ai/src/workflow/run-scoped-emitter.ts
|
|
2
|
+
/**
|
|
3
|
+
* Bind a factory-scoped `WorkflowEmitter` to one run's identity.
|
|
4
|
+
*
|
|
5
|
+
* The engine and step-runner emit bare payloads through this sink;
|
|
6
|
+
* it injects `runId` / `rootRunId` once and delegates to the real
|
|
7
|
+
* three-tier emitter. This is the single place workflow run identity
|
|
8
|
+
* is stamped — the alternative (editing every `emitter.emit` call
|
|
9
|
+
* site) would be ~15 scattered edits and easy to miss one.
|
|
10
|
+
*
|
|
11
|
+
* `rootRunId === runId` for a standalone run; nested propagation
|
|
12
|
+
* (a child workflow inheriting an outer run's root) lands in a
|
|
13
|
+
* follow-up.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Inside runWorkflow(), once per execution:
|
|
17
|
+
* const emitter = runScopedEmitter(params.emitter, { runId, rootRunId: runId });
|
|
18
|
+
* emitter.emit("workflow.starting", { workflowName, input }, executionHandlers);
|
|
19
|
+
*/
|
|
20
|
+
function runScopedEmitter(emitter, identity) {
|
|
21
|
+
return { emit(event, payload, executionHandlers) {
|
|
22
|
+
const fullPayload = {
|
|
23
|
+
...payload,
|
|
24
|
+
...identity
|
|
25
|
+
};
|
|
26
|
+
emitter.emit(event, fullPayload, executionHandlers);
|
|
27
|
+
} };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { runScopedEmitter };
|
|
32
|
+
//# sourceMappingURL=run-scoped-emitter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-scoped-emitter.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/workflow/run-scoped-emitter.ts"],"sourcesContent":["import type { EventIdentity } from \"../contracts/events/event-identity.type\";\nimport type { WorkflowEventMap } from \"../contracts/events/event-map.type\";\nimport type { WorkflowEventHandlers } from \"../contracts/workflow/workflow.contract\";\nimport type { WorkflowEmitter, WorkflowEventSink } from \"./emitter\";\n\n/**\n * Bind a factory-scoped `WorkflowEmitter` to one run's identity.\n *\n * The engine and step-runner emit bare payloads through this sink;\n * it injects `runId` / `rootRunId` once and delegates to the real\n * three-tier emitter. This is the single place workflow run identity\n * is stamped — the alternative (editing every `emitter.emit` call\n * site) would be ~15 scattered edits and easy to miss one.\n *\n * `rootRunId === runId` for a standalone run; nested propagation\n * (a child workflow inheriting an outer run's root) lands in a\n * follow-up.\n *\n * @example\n * // Inside runWorkflow(), once per execution:\n * const emitter = runScopedEmitter(params.emitter, { runId, rootRunId: runId });\n * emitter.emit(\"workflow.starting\", { workflowName, input }, executionHandlers);\n */\nexport function runScopedEmitter(\n emitter: WorkflowEmitter,\n identity: EventIdentity,\n): WorkflowEventSink {\n return {\n emit(event, payload, executionHandlers?: WorkflowEventHandlers) {\n const fullPayload = {\n ...payload,\n ...identity,\n } as WorkflowEventMap[typeof event];\n\n emitter.emit(event, fullPayload, executionHandlers);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,iBACd,SACA,UACmB;CACnB,OAAO,EACL,KAAK,OAAO,SAAS,mBAA2C;EAC9D,MAAM,cAAc;GAClB,GAAG;GACH,GAAG;EACL;EAEA,QAAQ,KAAK,OAAO,aAAa,iBAAiB;CACpD,EACF;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WorkflowDefinition } from "../contracts/workflow/workflow.contract.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../../@warlock.js/ai/src/workflow/signature.d.ts
|
|
4
|
+
declare function computeSignature<T>(definition: WorkflowDefinition<any, T, any, any>): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { computeSignature };
|
|
7
|
+
//# sourceMappingURL=signature.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/workflow/signature.ts"],"mappings":";;;iBAoCgB,gBAAA,GAAA,CAAoB,UAAA,EAAY,kBAAkB,MAAM,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region ../../@warlock.js/ai/src/workflow/signature.ts
|
|
2
|
+
function stepFingerprint(step) {
|
|
3
|
+
const tag = step.parallel ? "parallel" : step.agent ? "agent" : step.run ? "run" : "empty";
|
|
4
|
+
const agentName = step.agent?.name;
|
|
5
|
+
return {
|
|
6
|
+
n: step.name,
|
|
7
|
+
t: tag,
|
|
8
|
+
a: agentName,
|
|
9
|
+
c: step.parallel?.map((child) => stepFingerprint(child)) ?? null
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* FNV-1a 32-bit hash — deterministic, no crypto dependency.
|
|
14
|
+
*/
|
|
15
|
+
function hash(input) {
|
|
16
|
+
let h = 2166136261;
|
|
17
|
+
for (let i = 0; i < input.length; i++) {
|
|
18
|
+
h ^= input.charCodeAt(i);
|
|
19
|
+
h = h + ((h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24)) >>> 0;
|
|
20
|
+
}
|
|
21
|
+
return h.toString(16).padStart(8, "0");
|
|
22
|
+
}
|
|
23
|
+
function computeSignature(definition) {
|
|
24
|
+
const fingerprint = {
|
|
25
|
+
n: definition.name,
|
|
26
|
+
v: definition.version ?? null,
|
|
27
|
+
s: definition.steps.map((step) => stepFingerprint(step))
|
|
28
|
+
};
|
|
29
|
+
return hash(JSON.stringify(fingerprint));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { computeSignature };
|
|
34
|
+
//# sourceMappingURL=signature.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/workflow/signature.ts"],"sourcesContent":["import type { StepDefinition } from \"../contracts/workflow/step.contract\";\nimport type { WorkflowDefinition } from \"../contracts/workflow/workflow.contract\";\n\nfunction stepFingerprint(step: StepDefinition): unknown {\n const tag = step.parallel\n ? \"parallel\"\n : step.agent\n ? \"agent\"\n : step.run\n ? \"run\"\n : \"empty\";\n\n const agentName = step.agent?.name;\n\n return {\n n: step.name,\n t: tag,\n a: agentName,\n c: step.parallel?.map(child => stepFingerprint(child)) ?? null,\n };\n}\n\n/**\n * FNV-1a 32-bit hash — deterministic, no crypto dependency.\n */\nfunction hash(input: string): string {\n let h = 0x811c9dc5;\n\n for (let i = 0; i < input.length; i++) {\n h ^= input.charCodeAt(i);\n h = (h + ((h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24))) >>> 0;\n }\n\n return h.toString(16).padStart(8, \"0\");\n}\n\nexport function computeSignature<T>(definition: WorkflowDefinition<any, T, any, any>): string {\n const fingerprint = {\n n: definition.name,\n v: definition.version ?? null,\n s: definition.steps.map(step => stepFingerprint(step)),\n };\n\n return hash(JSON.stringify(fingerprint));\n}\n"],"mappings":";AAGA,SAAS,gBAAgB,MAA+B;CACtD,MAAM,MAAM,KAAK,WACb,aACA,KAAK,QACH,UACA,KAAK,MACH,QACA;CAER,MAAM,YAAY,KAAK,OAAO;CAE9B,OAAO;EACL,GAAG,KAAK;EACR,GAAG;EACH,GAAG;EACH,GAAG,KAAK,UAAU,KAAI,UAAS,gBAAgB,KAAK,CAAC,KAAK;CAC5D;AACF;;;;AAKA,SAAS,KAAK,OAAuB;CACnC,IAAI,IAAI;CAER,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,KAAK,MAAM,WAAW,CAAC;EACvB,IAAK,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,SAAU;CACxE;CAEA,OAAO,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AACvC;AAEA,SAAgB,iBAAoB,YAA0D;CAC5F,MAAM,cAAc;EAClB,GAAG,WAAW;EACd,GAAG,WAAW,WAAW;EACzB,GAAG,WAAW,MAAM,KAAI,SAAQ,gBAAgB,IAAI,CAAC;CACvD;CAEA,OAAO,KAAK,KAAK,UAAU,WAAW,CAAC;AACzC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { WorkflowError } from "../errors/workflow-error.mjs";
|
|
2
|
+
import { WorkflowDriftError } from "../errors/workflow-drift-error.mjs";
|
|
3
|
+
import "../errors/index.mjs";
|
|
4
|
+
import { resolveDefaultStore } from "../config.mjs";
|
|
5
|
+
|
|
6
|
+
//#region ../../@warlock.js/ai/src/workflow/snapshot.ts
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the effective snapshot store: the workflow's own
|
|
9
|
+
* `snapshotStore` field wins; absent that, fall back to the global
|
|
10
|
+
* default set via `ai.config({ defaultStore })`.
|
|
11
|
+
*/
|
|
12
|
+
function resolveSnapshotStore(definition) {
|
|
13
|
+
return definition.snapshotStore ?? resolveDefaultStore();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Write the current run's state to the configured `KVStore`. Returns
|
|
17
|
+
* an outcome object instead of throwing so the engine can surface
|
|
18
|
+
* persistence failures via events + logs without aborting the run.
|
|
19
|
+
* Callers decide whether a failed checkpoint is fatal.
|
|
20
|
+
*
|
|
21
|
+
* No-op (returns `{ ok: true }`) when the workflow has no store
|
|
22
|
+
* configured — the common in-memory test case.
|
|
23
|
+
*/
|
|
24
|
+
async function persistSnapshot(params) {
|
|
25
|
+
const store = resolveSnapshotStore(params.definition);
|
|
26
|
+
if (!store) return { ok: true };
|
|
27
|
+
const snapshot = {
|
|
28
|
+
runId: params.runId,
|
|
29
|
+
workflowName: params.definition.name,
|
|
30
|
+
signature: params.signature,
|
|
31
|
+
version: params.definition.version,
|
|
32
|
+
input: params.input,
|
|
33
|
+
state: { ...params.state },
|
|
34
|
+
steps: { ...params.steps },
|
|
35
|
+
next: params.next,
|
|
36
|
+
status: params.status,
|
|
37
|
+
startedAt: params.startedAt,
|
|
38
|
+
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
await store.set(params.runId, snapshot);
|
|
42
|
+
return { ok: true };
|
|
43
|
+
} catch (err) {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
error: err
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Load a prior run's snapshot from the store and run the drift
|
|
52
|
+
* check. Throws `WorkflowError` when no snapshot exists, and
|
|
53
|
+
* `WorkflowDriftError` when the stored signature doesn't match the
|
|
54
|
+
* current definition (unless `force` is set).
|
|
55
|
+
*/
|
|
56
|
+
async function loadSnapshotForResume(params) {
|
|
57
|
+
const store = resolveSnapshotStore(params.definition);
|
|
58
|
+
if (!store) throw new WorkflowError(`workflow "${params.definition.name}" has no store configured — set \`snapshotStore\` on the definition or call \`ai.config({ defaultStore })\` at boot before calling resume()`);
|
|
59
|
+
const snap = await store.get(params.runId) ?? null;
|
|
60
|
+
if (!snap) throw new WorkflowError(`workflow "${params.definition.name}": no snapshot for runId "${params.runId}"`);
|
|
61
|
+
if (!params.options?.force && snap.signature !== params.signature) throw new WorkflowDriftError(`workflow "${params.definition.name}" signature drift on resume`, {
|
|
62
|
+
savedSignature: snap.signature,
|
|
63
|
+
currentSignature: params.signature,
|
|
64
|
+
runId: params.runId
|
|
65
|
+
});
|
|
66
|
+
return snap;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { loadSnapshotForResume, persistSnapshot };
|
|
71
|
+
//# sourceMappingURL=snapshot.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/workflow/snapshot.ts"],"sourcesContent":["import { resolveDefaultStore } from \"../config\";\nimport type { StepSnapshot } from \"../contracts/result/step-result.type\";\nimport type { WorkflowSnapshot } from \"../contracts/workflow/workflow-snapshot.type\";\nimport type {\n WorkflowDefinition,\n WorkflowResumeOptions,\n} from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowDriftError, WorkflowError } from \"../errors\";\n\n/**\n * Resolve the effective snapshot store: the workflow's own\n * `snapshotStore` field wins; absent that, fall back to the global\n * default set via `ai.config({ defaultStore })`.\n */\nfunction resolveSnapshotStore<T>(definition: WorkflowDefinition<any, T, any, any>) {\n return definition.snapshotStore ?? resolveDefaultStore();\n}\n\nexport type PersistParams<T> = {\n definition: WorkflowDefinition<any, T, any, any>;\n signature: string;\n runId: string;\n startedAt: string;\n input: unknown;\n state: Record<string, unknown>;\n steps: Record<string, StepSnapshot>;\n next: string | null;\n status: WorkflowSnapshot[\"status\"];\n};\n\nexport type PersistOutcome = { ok: true } | { ok: false; error: unknown };\n\n/**\n * Write the current run's state to the configured `KVStore`. Returns\n * an outcome object instead of throwing so the engine can surface\n * persistence failures via events + logs without aborting the run.\n * Callers decide whether a failed checkpoint is fatal.\n *\n * No-op (returns `{ ok: true }`) when the workflow has no store\n * configured — the common in-memory test case.\n */\nexport async function persistSnapshot<T>(\n params: PersistParams<T>,\n): Promise<PersistOutcome> {\n const store = resolveSnapshotStore(params.definition);\n\n if (!store) return { ok: true };\n\n const snapshot: WorkflowSnapshot = {\n runId: params.runId,\n workflowName: params.definition.name,\n signature: params.signature,\n version: params.definition.version,\n input: params.input,\n state: { ...params.state },\n steps: { ...params.steps },\n next: params.next,\n status: params.status,\n startedAt: params.startedAt,\n savedAt: new Date().toISOString(),\n };\n\n try {\n await store.set(params.runId, snapshot);\n return { ok: true };\n } catch (err) {\n return { ok: false, error: err };\n }\n}\n\n/**\n * Load a prior run's snapshot from the store and run the drift\n * check. Throws `WorkflowError` when no snapshot exists, and\n * `WorkflowDriftError` when the stored signature doesn't match the\n * current definition (unless `force` is set).\n */\nexport async function loadSnapshotForResume<T>(params: {\n definition: WorkflowDefinition<any, T, any, any>;\n signature: string;\n runId: string;\n options?: WorkflowResumeOptions;\n}): Promise<WorkflowSnapshot> {\n const store = resolveSnapshotStore(params.definition);\n\n if (!store) {\n throw new WorkflowError(\n `workflow \"${params.definition.name}\" has no store configured — set \\`snapshotStore\\` on the definition or call \\`ai.config({ defaultStore })\\` at boot before calling resume()`,\n );\n }\n\n const snap = (await store.get<WorkflowSnapshot>(params.runId)) ?? null;\n\n if (!snap) {\n throw new WorkflowError(\n `workflow \"${params.definition.name}\": no snapshot for runId \"${params.runId}\"`,\n );\n }\n\n if (!params.options?.force && snap.signature !== params.signature) {\n throw new WorkflowDriftError(\n `workflow \"${params.definition.name}\" signature drift on resume`,\n {\n savedSignature: snap.signature,\n currentSignature: params.signature,\n runId: params.runId,\n },\n );\n }\n\n return snap;\n}\n"],"mappings":";;;;;;;;;;;AAcA,SAAS,qBAAwB,YAAkD;CACjF,OAAO,WAAW,iBAAiB,oBAAoB;AACzD;;;;;;;;;;AAyBA,eAAsB,gBACpB,QACyB;CACzB,MAAM,QAAQ,qBAAqB,OAAO,UAAU;CAEpD,IAAI,CAAC,OAAO,OAAO,EAAE,IAAI,KAAK;CAE9B,MAAM,WAA6B;EACjC,OAAO,OAAO;EACd,cAAc,OAAO,WAAW;EAChC,WAAW,OAAO;EAClB,SAAS,OAAO,WAAW;EAC3B,OAAO,OAAO;EACd,OAAO,EAAE,GAAG,OAAO,MAAM;EACzB,OAAO,EAAE,GAAG,OAAO,MAAM;EACzB,MAAM,OAAO;EACb,QAAQ,OAAO;EACf,WAAW,OAAO;EAClB,0BAAS,IAAI,KAAK,GAAE,YAAY;CAClC;CAEA,IAAI;EACF,MAAM,MAAM,IAAI,OAAO,OAAO,QAAQ;EACtC,OAAO,EAAE,IAAI,KAAK;CACpB,SAAS,KAAK;EACZ,OAAO;GAAE,IAAI;GAAO,OAAO;EAAI;CACjC;AACF;;;;;;;AAQA,eAAsB,sBAAyB,QAKjB;CAC5B,MAAM,QAAQ,qBAAqB,OAAO,UAAU;CAEpD,IAAI,CAAC,OACH,MAAM,IAAI,cACR,aAAa,OAAO,WAAW,KAAK,4IACtC;CAGF,MAAM,OAAQ,MAAM,MAAM,IAAsB,OAAO,KAAK,KAAM;CAElE,IAAI,CAAC,MACH,MAAM,IAAI,cACR,aAAa,OAAO,WAAW,KAAK,4BAA4B,OAAO,MAAM,EAC/E;CAGF,IAAI,CAAC,OAAO,SAAS,SAAS,KAAK,cAAc,OAAO,WACtD,MAAM,IAAI,mBACR,aAAa,OAAO,WAAW,KAAK,8BACpC;EACE,gBAAgB,KAAK;EACrB,kBAAkB,OAAO;EACzB,OAAO,OAAO;CAChB,CACF;CAGF,OAAO;AACT"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { WorkflowError } from "../errors/workflow-error.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/ai/src/workflow/state.ts
|
|
5
|
+
/**
|
|
6
|
+
* Deep-clone workflow state. Uses `structuredClone` — handles Date,
|
|
7
|
+
* Map, Set, ArrayBuffer, nested objects, arrays, primitives. Throws
|
|
8
|
+
* a typed `WorkflowError` on older runtimes (pre-Node-17) rather
|
|
9
|
+
* than silently falling back to a JSON round-trip that would drop
|
|
10
|
+
* non-serializable values like Dates without warning.
|
|
11
|
+
*
|
|
12
|
+
* Workflow state should stay serializable anyway (it round-trips
|
|
13
|
+
* through `KVStore` on every checkpoint). If `structuredClone` chokes
|
|
14
|
+
* on a value, that's a bug in the user's state — surface it.
|
|
15
|
+
*/
|
|
16
|
+
function cloneState(value) {
|
|
17
|
+
if (typeof structuredClone !== "function") throw new WorkflowError("workflow state cloning requires `structuredClone` (Node 17+ or a modern browser)");
|
|
18
|
+
return structuredClone(value);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Recursively freeze `value` and every nested plain object / array so
|
|
22
|
+
* consumers of `ctx.steps[x].state` or `report.state` can't mutate
|
|
23
|
+
* historical snapshots. Already-frozen values are skipped.
|
|
24
|
+
*/
|
|
25
|
+
function deepFreeze(value) {
|
|
26
|
+
if (value === null || typeof value !== "object") return value;
|
|
27
|
+
if (Object.isFrozen(value)) return value;
|
|
28
|
+
for (const key of Object.keys(value)) {
|
|
29
|
+
const child = value[key];
|
|
30
|
+
if (child && typeof child === "object") deepFreeze(child);
|
|
31
|
+
}
|
|
32
|
+
return Object.freeze(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { cloneState, deepFreeze };
|
|
37
|
+
//# sourceMappingURL=state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/workflow/state.ts"],"sourcesContent":["import { WorkflowError } from \"../errors\";\n\n/**\n * Deep-clone workflow state. Uses `structuredClone` — handles Date,\n * Map, Set, ArrayBuffer, nested objects, arrays, primitives. Throws\n * a typed `WorkflowError` on older runtimes (pre-Node-17) rather\n * than silently falling back to a JSON round-trip that would drop\n * non-serializable values like Dates without warning.\n *\n * Workflow state should stay serializable anyway (it round-trips\n * through `KVStore` on every checkpoint). If `structuredClone` chokes\n * on a value, that's a bug in the user's state — surface it.\n */\nexport function cloneState<T>(value: T): T {\n if (typeof structuredClone !== \"function\") {\n throw new WorkflowError(\n \"workflow state cloning requires `structuredClone` (Node 17+ or a modern browser)\",\n );\n }\n\n return structuredClone(value);\n}\n\n/**\n * Recursively freeze `value` and every nested plain object / array so\n * consumers of `ctx.steps[x].state` or `report.state` can't mutate\n * historical snapshots. Already-frozen values are skipped.\n */\nexport function deepFreeze<T>(value: T): T {\n if (value === null || typeof value !== \"object\") return value;\n if (Object.isFrozen(value)) return value;\n\n for (const key of Object.keys(value as Record<string, unknown>)) {\n const child = (value as Record<string, unknown>)[key];\n if (child && typeof child === \"object\") deepFreeze(child);\n }\n\n return Object.freeze(value);\n}\n"],"mappings":";;;;;;;;;;;;;;;AAaA,SAAgB,WAAc,OAAa;CACzC,IAAI,OAAO,oBAAoB,YAC7B,MAAM,IAAI,cACR,kFACF;CAGF,OAAO,gBAAgB,KAAK;AAC9B;;;;;;AAOA,SAAgB,WAAc,OAAa;CACzC,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CACxD,IAAI,OAAO,SAAS,KAAK,GAAG,OAAO;CAEnC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAgC,GAAG;EAC/D,MAAM,QAAS,MAAkC;EACjD,IAAI,SAAS,OAAO,UAAU,UAAU,WAAW,KAAK;CAC1D;CAEA,OAAO,OAAO,OAAO,KAAK;AAC5B"}
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import { AIError } from "../errors/ai-error.mjs";
|
|
2
|
+
import { WorkflowError } from "../errors/workflow-error.mjs";
|
|
3
|
+
import { SchemaValidationError } from "../errors/schema-validation-error.mjs";
|
|
4
|
+
import { StepFailedError } from "../errors/step-failed-error.mjs";
|
|
5
|
+
import { WorkflowCancelledError } from "../errors/workflow-cancelled-error.mjs";
|
|
6
|
+
import "../errors/index.mjs";
|
|
7
|
+
import { createCancelledError, sleep } from "./cancellation.mjs";
|
|
8
|
+
import { cloneState, deepFreeze } from "./state.mjs";
|
|
9
|
+
import { isAbortError, resolveBackoff, resolveRetryConfig } from "./retry.mjs";
|
|
10
|
+
|
|
11
|
+
//#region ../../@warlock.js/ai/src/workflow/step-runner.ts
|
|
12
|
+
/**
|
|
13
|
+
* Narrow an `executionResult` to an `AgentResult` when the step ran
|
|
14
|
+
* an agent. Custom `run` steps return arbitrary values, so the
|
|
15
|
+
* `type: "agent"` discriminant keeps us honest.
|
|
16
|
+
*/
|
|
17
|
+
function asAgentResult(result) {
|
|
18
|
+
if (!result || typeof result !== "object") return void 0;
|
|
19
|
+
if (result.type !== "agent") return void 0;
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Drive one step's full lifecycle — skip evaluation, parallel
|
|
24
|
+
* dispatch, retry loop around before → run|agent → output → after.
|
|
25
|
+
* Returns a mutable snapshot; the engine deep-freezes it before
|
|
26
|
+
* exposing.
|
|
27
|
+
*/
|
|
28
|
+
async function executeStep(params) {
|
|
29
|
+
const { step, emitter, executionHandlers, logger, logModule, signal } = params;
|
|
30
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
31
|
+
const stepStartPerf = performance.now();
|
|
32
|
+
params.step.on?.starting?.({ step: step.name });
|
|
33
|
+
emitter.emit("workflow.step.starting", { step: step.name }, executionHandlers);
|
|
34
|
+
logger.debug(logModule, "step.starting", `${step.name} step starting`, { step: step.name });
|
|
35
|
+
const stepState = cloneState(params.state);
|
|
36
|
+
try {
|
|
37
|
+
if (step.skip) {
|
|
38
|
+
if (await step.skip(params.buildContext({ state: stepState }))) {
|
|
39
|
+
const endedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
40
|
+
const duration = performance.now() - stepStartPerf;
|
|
41
|
+
emitter.emit("workflow.step.skipped", { step: step.name }, executionHandlers);
|
|
42
|
+
logger.debug(logModule, "step.skipped", `${step.name} step skipped`, { step: step.name });
|
|
43
|
+
return {
|
|
44
|
+
output: void 0,
|
|
45
|
+
skipped: true,
|
|
46
|
+
status: "skipped",
|
|
47
|
+
startedAt,
|
|
48
|
+
endedAt,
|
|
49
|
+
duration,
|
|
50
|
+
attempts: 0,
|
|
51
|
+
attemptHistory: [],
|
|
52
|
+
state: stepState
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
return buildFailedSnapshot(step, stepState, startedAt, stepStartPerf, 1, [failedAttempt(1, err, (/* @__PURE__ */ new Date()).toISOString(), performance.now())]);
|
|
58
|
+
}
|
|
59
|
+
if (step.parallel && step.parallel.length > 0) return runParallelStep({
|
|
60
|
+
...params,
|
|
61
|
+
step,
|
|
62
|
+
stepState,
|
|
63
|
+
startedAt,
|
|
64
|
+
startPerf: stepStartPerf
|
|
65
|
+
});
|
|
66
|
+
const retryConfig = resolveRetryConfig(step, params.workflowDefaultRetry);
|
|
67
|
+
const attempts = [];
|
|
68
|
+
const totalAttempts = Math.max(1, retryConfig.attempts ?? 1);
|
|
69
|
+
let lastError;
|
|
70
|
+
let executionResult;
|
|
71
|
+
let output;
|
|
72
|
+
let succeeded = false;
|
|
73
|
+
for (let attempt = 1; attempt <= totalAttempts; attempt++) {
|
|
74
|
+
if (signal?.aborted) throw createCancelledError(signal);
|
|
75
|
+
const attemptStart = (/* @__PURE__ */ new Date()).toISOString();
|
|
76
|
+
const attemptStartPerf = performance.now();
|
|
77
|
+
try {
|
|
78
|
+
const attemptState = cloneState(params.state);
|
|
79
|
+
if (step.before) await step.before(params.buildContext({ state: attemptState }));
|
|
80
|
+
if (step.agent) {
|
|
81
|
+
const { prompt, ...agentOpts } = step.input ? await step.input(params.buildContext({ state: attemptState })) : { prompt: "" };
|
|
82
|
+
const result = await step.agent.execute(prompt, {
|
|
83
|
+
...agentOpts,
|
|
84
|
+
signal
|
|
85
|
+
});
|
|
86
|
+
executionResult = result;
|
|
87
|
+
if (result.usage) {
|
|
88
|
+
params.usage.input += result.usage.input ?? 0;
|
|
89
|
+
params.usage.output += result.usage.output ?? 0;
|
|
90
|
+
params.usage.total += result.usage.total ?? 0;
|
|
91
|
+
}
|
|
92
|
+
if (result.error) throw result.error;
|
|
93
|
+
} else if (step.run) executionResult = await step.run(params.buildContext({ state: attemptState }));
|
|
94
|
+
if (step.output) {
|
|
95
|
+
const extracted = await step.output.extract(params.buildContext({
|
|
96
|
+
state: attemptState,
|
|
97
|
+
agentResult: executionResult
|
|
98
|
+
}));
|
|
99
|
+
output = await validateSchema(step.output.schema, extracted);
|
|
100
|
+
} else output = void 0;
|
|
101
|
+
if (step.after) await step.after(params.buildContext({
|
|
102
|
+
state: attemptState,
|
|
103
|
+
agentResult: executionResult
|
|
104
|
+
}));
|
|
105
|
+
Object.assign(stepState, attemptState);
|
|
106
|
+
attempts.push({
|
|
107
|
+
index: attempt,
|
|
108
|
+
startedAt: attemptStart,
|
|
109
|
+
endedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
110
|
+
duration: performance.now() - attemptStartPerf,
|
|
111
|
+
status: "success"
|
|
112
|
+
});
|
|
113
|
+
succeeded = true;
|
|
114
|
+
break;
|
|
115
|
+
} catch (err) {
|
|
116
|
+
if (isAbortError(err) || err instanceof WorkflowCancelledError) throw createCancelledError(signal);
|
|
117
|
+
attempts.push({
|
|
118
|
+
index: attempt,
|
|
119
|
+
startedAt: attemptStart,
|
|
120
|
+
endedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
121
|
+
duration: performance.now() - attemptStartPerf,
|
|
122
|
+
status: "failed",
|
|
123
|
+
error: toAIError(err)
|
|
124
|
+
});
|
|
125
|
+
lastError = err;
|
|
126
|
+
if (!(attempt < totalAttempts && (retryConfig.retryOn ? retryConfig.retryOn(err, attempt) !== false : true))) break;
|
|
127
|
+
emitter.emit("workflow.step.retrying", {
|
|
128
|
+
step: step.name,
|
|
129
|
+
attempt: attempt + 1,
|
|
130
|
+
totalAttempts,
|
|
131
|
+
lastError: err
|
|
132
|
+
}, params.executionHandlers);
|
|
133
|
+
step.on?.retrying?.({
|
|
134
|
+
step: step.name,
|
|
135
|
+
attempt: attempt + 1,
|
|
136
|
+
totalAttempts,
|
|
137
|
+
lastError: err
|
|
138
|
+
});
|
|
139
|
+
logger.warn(logModule, "step.retrying", `${step.name} step retrying`, {
|
|
140
|
+
step: step.name,
|
|
141
|
+
attempt: attempt + 1
|
|
142
|
+
});
|
|
143
|
+
retryConfig.onRetry?.(attempt + 1, err);
|
|
144
|
+
const delay = resolveBackoff(attempt, retryConfig.backoff);
|
|
145
|
+
if (delay > 0) await sleep(delay, signal);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const endedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
149
|
+
const duration = performance.now() - stepStartPerf;
|
|
150
|
+
if (!succeeded) {
|
|
151
|
+
const aiError = toAIError(lastError);
|
|
152
|
+
const stepError = new StepFailedError(`step "${step.name}" failed after ${attempts.length} attempt(s): ${aiError.message}`, {
|
|
153
|
+
stepName: step.name,
|
|
154
|
+
attempts: attempts.length,
|
|
155
|
+
cause: aiError
|
|
156
|
+
});
|
|
157
|
+
emitter.emit("workflow.step.failed", {
|
|
158
|
+
step: step.name,
|
|
159
|
+
error: stepError,
|
|
160
|
+
attempts: attempts.length
|
|
161
|
+
}, params.executionHandlers);
|
|
162
|
+
step.on?.failed?.({
|
|
163
|
+
step: step.name,
|
|
164
|
+
error: stepError,
|
|
165
|
+
attempts: attempts.length
|
|
166
|
+
});
|
|
167
|
+
logger.error(logModule, "step.failed", `${step.name} step failed`, {
|
|
168
|
+
step: step.name,
|
|
169
|
+
attempts: attempts.length,
|
|
170
|
+
code: stepError.code
|
|
171
|
+
});
|
|
172
|
+
const failedAgentResult = asAgentResult(executionResult);
|
|
173
|
+
return {
|
|
174
|
+
output: void 0,
|
|
175
|
+
skipped: false,
|
|
176
|
+
status: "failed",
|
|
177
|
+
startedAt,
|
|
178
|
+
endedAt,
|
|
179
|
+
duration,
|
|
180
|
+
attempts: attempts.length,
|
|
181
|
+
attemptHistory: attempts,
|
|
182
|
+
error: stepError,
|
|
183
|
+
state: stepState,
|
|
184
|
+
executionResult: executionResult && typeof executionResult === "object" ? executionResult : void 0,
|
|
185
|
+
agentReport: failedAgentResult?.report,
|
|
186
|
+
agentUsage: failedAgentResult?.usage
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
emitter.emit("workflow.step.completed", {
|
|
190
|
+
step: step.name,
|
|
191
|
+
output,
|
|
192
|
+
duration
|
|
193
|
+
}, params.executionHandlers);
|
|
194
|
+
step.on?.completed?.({
|
|
195
|
+
step: step.name,
|
|
196
|
+
output,
|
|
197
|
+
duration
|
|
198
|
+
});
|
|
199
|
+
logger.debug(logModule, "step.completed", "step completed", {
|
|
200
|
+
step: step.name,
|
|
201
|
+
duration
|
|
202
|
+
});
|
|
203
|
+
const completedAgentResult = asAgentResult(executionResult);
|
|
204
|
+
return {
|
|
205
|
+
output,
|
|
206
|
+
skipped: false,
|
|
207
|
+
status: "completed",
|
|
208
|
+
startedAt,
|
|
209
|
+
endedAt,
|
|
210
|
+
duration,
|
|
211
|
+
attempts: attempts.length,
|
|
212
|
+
attemptHistory: attempts,
|
|
213
|
+
state: stepState,
|
|
214
|
+
executionResult: executionResult && typeof executionResult === "object" ? executionResult : void 0,
|
|
215
|
+
agentReport: completedAgentResult?.report,
|
|
216
|
+
agentUsage: completedAgentResult?.usage
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
async function runParallelStep(params) {
|
|
220
|
+
const { step, emitter, executionHandlers, logger, logModule, signal } = params;
|
|
221
|
+
const sharedState = params.stepState;
|
|
222
|
+
const childSnapshots = {};
|
|
223
|
+
let firstError;
|
|
224
|
+
const results = await Promise.all((step.parallel ?? []).map(async (child) => {
|
|
225
|
+
const snap = await executeStep({
|
|
226
|
+
step: child,
|
|
227
|
+
state: sharedState,
|
|
228
|
+
emitter,
|
|
229
|
+
executionHandlers,
|
|
230
|
+
logger,
|
|
231
|
+
logModule,
|
|
232
|
+
signal,
|
|
233
|
+
buildContext: params.buildContext,
|
|
234
|
+
usage: params.usage
|
|
235
|
+
});
|
|
236
|
+
Object.assign(sharedState, snap.state);
|
|
237
|
+
return {
|
|
238
|
+
child,
|
|
239
|
+
snap
|
|
240
|
+
};
|
|
241
|
+
}));
|
|
242
|
+
for (const { child, snap } of results) {
|
|
243
|
+
childSnapshots[child.name] = finalizeSnapshot(snap);
|
|
244
|
+
if (snap.status === "failed" && !firstError && snap.error) firstError = snap.error;
|
|
245
|
+
}
|
|
246
|
+
const endedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
247
|
+
const duration = performance.now() - params.startPerf;
|
|
248
|
+
let output;
|
|
249
|
+
if (step.output) try {
|
|
250
|
+
const ctx = params.buildContext({ state: sharedState });
|
|
251
|
+
const ctxWithChildren = {
|
|
252
|
+
...ctx,
|
|
253
|
+
steps: {
|
|
254
|
+
...ctx.steps,
|
|
255
|
+
[step.name]: {
|
|
256
|
+
...childSnapshots,
|
|
257
|
+
steps: childSnapshots,
|
|
258
|
+
status: firstError ? "failed" : "completed"
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
const extracted = await step.output.extract(ctxWithChildren);
|
|
263
|
+
output = await validateSchema(step.output.schema, extracted);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
firstError = firstError ?? toAIError(err);
|
|
266
|
+
}
|
|
267
|
+
const status = firstError ? "failed" : "completed";
|
|
268
|
+
if (status === "completed") {
|
|
269
|
+
emitter.emit("workflow.step.completed", {
|
|
270
|
+
step: step.name,
|
|
271
|
+
output,
|
|
272
|
+
duration
|
|
273
|
+
}, executionHandlers);
|
|
274
|
+
step.on?.completed?.({
|
|
275
|
+
step: step.name,
|
|
276
|
+
output,
|
|
277
|
+
duration
|
|
278
|
+
});
|
|
279
|
+
} else {
|
|
280
|
+
emitter.emit("workflow.step.failed", {
|
|
281
|
+
step: step.name,
|
|
282
|
+
error: firstError,
|
|
283
|
+
attempts: 1
|
|
284
|
+
}, executionHandlers);
|
|
285
|
+
step.on?.failed?.({
|
|
286
|
+
step: step.name,
|
|
287
|
+
error: firstError,
|
|
288
|
+
attempts: 1
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
return {
|
|
292
|
+
output,
|
|
293
|
+
skipped: false,
|
|
294
|
+
status,
|
|
295
|
+
startedAt: params.startedAt,
|
|
296
|
+
endedAt,
|
|
297
|
+
duration,
|
|
298
|
+
attempts: 1,
|
|
299
|
+
attemptHistory: [],
|
|
300
|
+
error: firstError,
|
|
301
|
+
state: sharedState,
|
|
302
|
+
steps: childSnapshots
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function finalizeSnapshot(snap) {
|
|
306
|
+
return Object.freeze({
|
|
307
|
+
output: snap.output,
|
|
308
|
+
skipped: snap.skipped,
|
|
309
|
+
status: snap.status,
|
|
310
|
+
startedAt: snap.startedAt,
|
|
311
|
+
endedAt: snap.endedAt,
|
|
312
|
+
duration: snap.duration,
|
|
313
|
+
attempts: snap.attempts,
|
|
314
|
+
attemptHistory: snap.attemptHistory,
|
|
315
|
+
error: snap.error,
|
|
316
|
+
state: deepFreeze(cloneState(snap.state)),
|
|
317
|
+
executionResult: snap.executionResult,
|
|
318
|
+
agentReport: snap.agentReport,
|
|
319
|
+
agentUsage: snap.agentUsage,
|
|
320
|
+
steps: snap.steps
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function buildFailedSnapshot(step, state, startedAt, startPerf, attemptsCount, attemptHistory) {
|
|
324
|
+
const endedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
325
|
+
const duration = performance.now() - startPerf;
|
|
326
|
+
const lastErr = attemptHistory[attemptHistory.length - 1]?.error;
|
|
327
|
+
return {
|
|
328
|
+
output: void 0,
|
|
329
|
+
skipped: false,
|
|
330
|
+
status: "failed",
|
|
331
|
+
startedAt,
|
|
332
|
+
endedAt,
|
|
333
|
+
duration,
|
|
334
|
+
attempts: attemptsCount,
|
|
335
|
+
attemptHistory,
|
|
336
|
+
error: lastErr ? new StepFailedError(`step "${step.name}" skip threw: ${lastErr.message}`, {
|
|
337
|
+
stepName: step.name,
|
|
338
|
+
attempts: attemptsCount,
|
|
339
|
+
cause: lastErr
|
|
340
|
+
}) : new StepFailedError(`step "${step.name}" failed`, {
|
|
341
|
+
stepName: step.name,
|
|
342
|
+
attempts: attemptsCount
|
|
343
|
+
}),
|
|
344
|
+
state
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
function failedAttempt(index, err, startedAt, startPerf) {
|
|
348
|
+
return {
|
|
349
|
+
index,
|
|
350
|
+
startedAt,
|
|
351
|
+
endedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
352
|
+
duration: performance.now() - startPerf,
|
|
353
|
+
status: "failed",
|
|
354
|
+
error: toAIError(err)
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function toAIError(err) {
|
|
358
|
+
if (err instanceof AIError) return err;
|
|
359
|
+
if (err instanceof Error) return new WorkflowError(err.message, { cause: err });
|
|
360
|
+
return new WorkflowError(String(err));
|
|
361
|
+
}
|
|
362
|
+
async function validateSchema(schema, value) {
|
|
363
|
+
if (!schema) return value;
|
|
364
|
+
const result = await schema["~standard"].validate(value);
|
|
365
|
+
if ("issues" in result && result.issues) throw new SchemaValidationError("workflow step output failed schema validation", { issues: result.issues });
|
|
366
|
+
return result.value;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
//#endregion
|
|
370
|
+
export { executeStep, finalizeSnapshot, toAIError };
|
|
371
|
+
//# sourceMappingURL=step-runner.mjs.map
|