@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,105 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: embed-text
|
|
3
|
+
description: 'Text-to-vector via sdk.embedder({...}) — embed(string) for single, embedMany(string[]) for batch. Peer primitive on the SDK adapter, not wired into agents. Compose into RAG tools, workflow run steps, or ai.middleware.semanticCache. Triggers: `sdk.embedder`, `EmbedderContract`, `embedder.embed`, `embedder.embedMany`, `EmbeddingResult`, `EmbeddingBatchResult`, `dimensions`; ''embed text'', ''build RAG tool'', ''populate vector store'', ''embedding batch''; typical import `import { OpenAISDK } from "@warlock.js/ai-openai"`. Skip: cache similarity — `@warlock.js/cache/use-cache-similarity/SKILL.md`; pgvector queries — `@warlock.js/cascade/search-by-vector/SKILL.md`; competing libs `langchain` embeddings, raw `openai.embeddings.create`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Embeddings — peer primitive on the SDK adapter
|
|
7
|
+
|
|
8
|
+
`EmbedderContract` is a sibling of `ModelContract` on `SDKAdapterContract`, not part of the agent loop. Text-in / vector-out. No streaming, no tools, no relationship to chat completions.
|
|
9
|
+
|
|
10
|
+
## Contract
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
interface EmbedderContract {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly provider: string;
|
|
16
|
+
readonly dimensions: number; // 0 until first call when no override given
|
|
17
|
+
|
|
18
|
+
embed(input: string): Promise<EmbeddingResult>;
|
|
19
|
+
embedMany(inputs: string[]): Promise<EmbeddingBatchResult>;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Single and batch are deliberately split — different cost profiles, different per-request token caps, different failure modes.
|
|
24
|
+
|
|
25
|
+
The `embedder()` method is **optional** on `SDKAdapterContract` — not every provider supports embeddings:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
if (typeof sdk.embedder === "function") {
|
|
29
|
+
const embedder = sdk.embedder({ name: "text-embedding-3-small" });
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## OpenAI adapter — first implementation
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { OpenAISDK } from "@warlock.js/ai-openai";
|
|
37
|
+
|
|
38
|
+
const openai = new OpenAISDK({ apiKey: process.env.OPENAI_API_KEY! });
|
|
39
|
+
const embedder = openai.embedder({ name: "text-embedding-3-small" });
|
|
40
|
+
|
|
41
|
+
const one = await embedder.embed("Hello, world.");
|
|
42
|
+
// { vector: number[], dimensions: number, usage: { promptTokens, totalTokens } }
|
|
43
|
+
|
|
44
|
+
const many = await embedder.embedMany(["foo", "bar", "baz"]);
|
|
45
|
+
// { vectors: number[][], dimensions: number, usage: { promptTokens, totalTokens } }
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Not wired into the agent loop
|
|
49
|
+
|
|
50
|
+
Embeddings are deliberately not automatic. Consumers obtain an embedder from the adapter and call it directly. Composes into:
|
|
51
|
+
|
|
52
|
+
- **Retrieval tools** the agent can call (RAG pattern).
|
|
53
|
+
- **`run` steps** in a workflow (vector ingest, catalog item embedding).
|
|
54
|
+
- **Query vectors** for `ai.middleware.semanticCache` — see [`@warlock.js/ai/attach-ai-middleware/SKILL.md`](@warlock.js/ai/attach-ai-middleware/SKILL.md).
|
|
55
|
+
- **Cascade vector columns** for native pgvector search — see [`@warlock.js/cascade/search-by-vector/SKILL.md`](@warlock.js/cascade/search-by-vector/SKILL.md).
|
|
56
|
+
- **Cache similarity retrieval** via `cache.set({ vector })` + `cache.similar(...)` — see [`@warlock.js/cache/use-cache-similarity/SKILL.md`](@warlock.js/cache/use-cache-similarity/SKILL.md).
|
|
57
|
+
|
|
58
|
+
## Usage example — workflow `run` step
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
ai.step({
|
|
62
|
+
name: "embed",
|
|
63
|
+
run: async (ctx) => {
|
|
64
|
+
const text = `${ctx.steps.extract.output.name} ${ctx.steps.extract.output.description}`;
|
|
65
|
+
const { vector } = await embedder.embed(text);
|
|
66
|
+
ctx.state.embedding = vector;
|
|
67
|
+
},
|
|
68
|
+
output: { extract: (ctx) => ({ dims: (ctx.state.embedding as number[]).length }) },
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Pattern — RAG tool
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { v } from "@warlock.js/seal";
|
|
76
|
+
|
|
77
|
+
const searchKb = ai.tool({
|
|
78
|
+
name: "searchKb",
|
|
79
|
+
description: "Search the knowledge base for relevant passages.",
|
|
80
|
+
input: v.object({ query: v.string(), k: v.number().optional() }),
|
|
81
|
+
execute: async ({ query, k }) => {
|
|
82
|
+
const { vector } = await embedder.embed(query);
|
|
83
|
+
const hits = await vectorStore.query(vector, { topK: k ?? 5 });
|
|
84
|
+
return hits.map((h) => ({ text: h.text, score: h.score, source: h.source }));
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
ai.agent({ model, tools: [searchKb] });
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Dimensions
|
|
92
|
+
|
|
93
|
+
`embedder.dimensions` is `0` on a fresh embedder when no override is given — populated from the first embed call's response. Pre-seed via the adapter's `dimensions` config option when you need the value before the first call (e.g. to size a vector column in a migration schema).
|
|
94
|
+
|
|
95
|
+
## Retrieval is app-level
|
|
96
|
+
|
|
97
|
+
No built-in vector store. Bring your own (pgvector / Qdrant / Pinecone / Chroma / cache's `similar()`) and wrap it in an `ai.tool({...})`.
|
|
98
|
+
|
|
99
|
+
## See also
|
|
100
|
+
|
|
101
|
+
- [`@warlock.js/ai/run-ai-agent/SKILL.md`](@warlock.js/ai/run-ai-agent/SKILL.md) — composing embedders into tools
|
|
102
|
+
- [`@warlock.js/ai/run-ai-workflow/SKILL.md`](@warlock.js/ai/run-ai-workflow/SKILL.md) — embeddings inside `run` steps
|
|
103
|
+
- [`@warlock.js/ai/persist-ai-data/SKILL.md`](@warlock.js/ai/persist-ai-data/SKILL.md) — performance guidance on vector storage
|
|
104
|
+
- [`@warlock.js/cache/use-cache-similarity/SKILL.md`](@warlock.js/cache/use-cache-similarity/SKILL.md) — cache as a vector store
|
|
105
|
+
- [`@warlock.js/cascade/search-by-vector/SKILL.md`](@warlock.js/cascade/search-by-vector/SKILL.md) — cascade `similarTo` query method
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: handle-ai-errors
|
|
3
|
+
description: 'Typed AIError hierarchy with stable code strings + coarse category for retry-policy dispatch. execute() never throws — errors surface via result.error. Triggers: `AIError`, `ProviderRateLimitError`, `ProviderAuthError`, `ContextLengthExceededError`, `ContentFilterError`, `SchemaValidationError`, `ToolExecutionError`, `WorkflowDriftError`, `BudgetExceededError`, `GuardrailViolationError`, `error.code`, `error.category`; ''handle ai error'', ''retry on rate limit'', ''branch on error code'', ''build fallback ladder''; typical import `import { AIError } from "@warlock.js/ai"`. Skip: log surfacing — `@warlock.js/ai/log-ai-calls/SKILL.md`; native `try / catch` on raw `openai`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Typed errors — `AIError` hierarchy
|
|
7
|
+
|
|
8
|
+
Every error surfaced by `@warlock.js/ai` and every adapter package is an `AIError` subclass with a stable `code`. The base extends platform `Error`; it does NOT extend `HttpError`. Plain `Error` never leaks.
|
|
9
|
+
|
|
10
|
+
## Two invariants
|
|
11
|
+
|
|
12
|
+
1. **`execute()` never throws.** Every `agent.execute()` / `workflow.execute()` resolves with a well-formed result. Failures funnel into `result.error`. Same for `stream.result`.
|
|
13
|
+
2. **Every error is an `AIError`.** Both core and adapter packages funnel everything through `AIError` subclasses. Branch on `error.code` (stable string) or `instanceof`.
|
|
14
|
+
|
|
15
|
+
## Dispatch pattern
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import {
|
|
19
|
+
AIError,
|
|
20
|
+
ProviderRateLimitError,
|
|
21
|
+
ProviderAuthError,
|
|
22
|
+
ContextLengthExceededError,
|
|
23
|
+
ContentFilterError,
|
|
24
|
+
SchemaValidationError,
|
|
25
|
+
ToolExecutionError,
|
|
26
|
+
WorkflowDriftError,
|
|
27
|
+
// ...
|
|
28
|
+
} from "@warlock.js/ai";
|
|
29
|
+
|
|
30
|
+
const result = await agent.execute(input);
|
|
31
|
+
|
|
32
|
+
if (!result.error) return result.data;
|
|
33
|
+
|
|
34
|
+
if (result.error instanceof ProviderRateLimitError) {
|
|
35
|
+
await sleep(result.error.retryAfter ?? 1000);
|
|
36
|
+
return retry();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (result.error instanceof ContextLengthExceededError) {
|
|
40
|
+
return truncateAndRetry(result.error);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Or branch on stable code string (good for persisted logs / metrics)
|
|
44
|
+
switch (result.error.code) {
|
|
45
|
+
case "PROVIDER_RATE_LIMIT": /* ... */ break;
|
|
46
|
+
case "CONTENT_FILTER": /* ... */ break;
|
|
47
|
+
case "WORKFLOW_DRIFT": /* ... */ break;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Codes are the public contract — class names may evolve; codes stay.
|
|
52
|
+
|
|
53
|
+
## Coarse dispatch via `error.category`
|
|
54
|
+
|
|
55
|
+
Too granular to dashboard on `code` — every `AIError` carries a coarser `category`:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
type ErrorCategory =
|
|
59
|
+
| "auth" | "rate-limit" | "timeout" | "validation" | "content-filter"
|
|
60
|
+
| "provider" | "tool" | "cancelled" | "max-trips" | "max-iterations"
|
|
61
|
+
| "max-steps" | "schema" | "drift" | "routing" | "guardrail"
|
|
62
|
+
| "budget" | "quota" | "context-length" | "unknown";
|
|
63
|
+
|
|
64
|
+
switch (result.error.category) {
|
|
65
|
+
case "rate-limit": return retryWithBackoff();
|
|
66
|
+
case "timeout": return retryOnce();
|
|
67
|
+
case "auth": return escalate(); // not retryable
|
|
68
|
+
case "content-filter": return policyMessage(); // not retryable
|
|
69
|
+
case "schema": return repair(); // use agent `repair`
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
metrics.increment("ai.error", { category: result.error.category });
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Each typed subclass declares its `static defaultCategory`. The 4th-arg category override exists only on the base `AIError` for direct `new AIError(...)` usage.
|
|
76
|
+
|
|
77
|
+
## Hierarchy
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
AIError (base — code, category, message, cause?, context?)
|
|
81
|
+
├── AgentExecutionError AGENT_EXEC_FAILED
|
|
82
|
+
│ ├── AgentCancelledError AGENT_CANCELLED { cancelledAt?, reason? } — caller pulled the plug
|
|
83
|
+
│ └── AgentMaxTripsError AGENT_MAX_TRIPS { maxTrips } — runaway tool loop hit the cap
|
|
84
|
+
├── SchemaValidationError SCHEMA_VALIDATION_FAILED { issues? }
|
|
85
|
+
├── ToolExecutionError TOOL_EXEC_FAILED { toolName, tripIndex? }
|
|
86
|
+
├── WorkflowError WORKFLOW_ERROR (base)
|
|
87
|
+
│ ├── StepFailedError STEP_FAILED { stepName, attempts }
|
|
88
|
+
│ ├── WorkflowDriftError WORKFLOW_DRIFT { savedSignature, currentSignature, runId }
|
|
89
|
+
│ ├── WorkflowCancelledError WORKFLOW_CANCELLED { cancelledAt, reason }
|
|
90
|
+
│ ├── MaxStepsExceededError WORKFLOW_MAX_STEPS { maxSteps }
|
|
91
|
+
│ └── RoutingError WORKFLOW_INVALID_GOTO { stepName, targetName }
|
|
92
|
+
├── SupervisorFailedError SUPERVISOR_FAILED (base + authoring/runtime)
|
|
93
|
+
│ ├── MaxIterationsError SUPERVISOR_MAX_ITERATIONS { maxIterations }
|
|
94
|
+
│ ├── SupervisorRoutingError SUPERVISOR_INVALID_ROUTE
|
|
95
|
+
│ ├── SupervisorCancelledError SUPERVISOR_CANCELLED { cancelledAt, reason }
|
|
96
|
+
│ └── SupervisorDriftError SUPERVISOR_DRIFT { savedSignature, currentSignature, runId }
|
|
97
|
+
├── ProviderError PROVIDER_ERROR (base + catch-all)
|
|
98
|
+
│ ├── ProviderRateLimitError PROVIDER_RATE_LIMIT { retryAfter? } — transient
|
|
99
|
+
│ ├── QuotaExceededError PROVIDER_QUOTA_EXCEEDED — NOT retryable (billing cap)
|
|
100
|
+
│ ├── ProviderTimeoutError PROVIDER_TIMEOUT
|
|
101
|
+
│ ├── ContextLengthExceededError CONTEXT_LENGTH_EXCEEDED { limit?, actual?, modelName? }
|
|
102
|
+
│ ├── ContentFilterError CONTENT_FILTER { reason?, categories? }
|
|
103
|
+
│ ├── InvalidRequestError PROVIDER_INVALID_REQUEST
|
|
104
|
+
│ └── ProviderAuthError PROVIDER_AUTH
|
|
105
|
+
├── BudgetExceededError BUDGET_EXCEEDED { limit, actual, unit } — from ai.middleware.budget
|
|
106
|
+
└── GuardrailViolationError GUARDRAIL_VIOLATION { phase, reason } — from ai.middleware.guardrail
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
> `SupervisorFailedError` doubles as the base for the supervisor family **and** the authoring-time error for bad config (e.g. `route` + `router` both set). It carries extra `SUPERVISOR_INTENT_*` / `SUPERVISOR_DISPATCH_CYCLE` codes for specific intent-validation failures.
|
|
110
|
+
|
|
111
|
+
## Error fields
|
|
112
|
+
|
|
113
|
+
- `code` — stable `AIErrorCode` string.
|
|
114
|
+
- `category` — coarse `ErrorCategory`.
|
|
115
|
+
- `message` — human-readable.
|
|
116
|
+
- `cause?` — root error (often a provider SDK error).
|
|
117
|
+
- `context?` — `Record<string, unknown>` for provider-raw diagnostics (`status`, `requestId`, `headers`).
|
|
118
|
+
|
|
119
|
+
Typed fields (`retryAfter`, `toolName`, `issues`, `stepName`, …) are first-class consumer surface.
|
|
120
|
+
|
|
121
|
+
## Retry strategy
|
|
122
|
+
|
|
123
|
+
| Error family | Retryable? |
|
|
124
|
+
| --- | --- |
|
|
125
|
+
| `ProviderRateLimitError` | Yes — back off by `retryAfter` ms |
|
|
126
|
+
| `ProviderTimeoutError` | Yes — short delay |
|
|
127
|
+
| `ProviderError` (generic) | Maybe — depends on cause |
|
|
128
|
+
| `QuotaExceededError` | **No** — needs human intervention |
|
|
129
|
+
| `ProviderAuthError` | **No** — fix config / rotate key |
|
|
130
|
+
| `ContextLengthExceededError` | Only after truncating input |
|
|
131
|
+
| `ContentFilterError` | Usually **no** — the prompt itself is the issue |
|
|
132
|
+
| `SchemaValidationError` | Use agent `repair: { maxAttempts }` instead |
|
|
133
|
+
| `ToolExecutionError` | Depends on `cause` |
|
|
134
|
+
| `WorkflowDriftError` | **No** — manual migration or `force: true` |
|
|
135
|
+
| `WorkflowCancelledError` | **No** — caller-driven cancel |
|
|
136
|
+
| `MaxStepsExceededError` / `RoutingError` | **No** — programmer error |
|
|
137
|
+
| `BudgetExceededError` | **No** — raise the cap, split the workload |
|
|
138
|
+
| `GuardrailViolationError` (`phase: "input"`) | **No** — block / sanitize at product layer |
|
|
139
|
+
| `GuardrailViolationError` (`phase: "output"`) | Sometimes — re-prompt with adjusted system message |
|
|
140
|
+
|
|
141
|
+
## Why extend `Error`, not `HttpError`
|
|
142
|
+
|
|
143
|
+
- `@warlock.js/ai` is a standalone product — used from CLIs / workers / scripts as often as HTTP handlers.
|
|
144
|
+
- Coupling to a web framework pulls HTTP into every consumer.
|
|
145
|
+
- AI errors aren't HTTP errors anyway — "rate limit" is a 429 the *upstream provider* returned, not one the server returns.
|
|
146
|
+
|
|
147
|
+
The **consumer app** layer (`src/app/ai/`) wraps framework errors with its own `AIError` subclass that extends `HttpError`. See `domains/ai/conventions/errors.md`.
|
|
148
|
+
|
|
149
|
+
## OpenAI adapter — status + code dispatch
|
|
150
|
+
|
|
151
|
+
The OpenAI wrapper categorizes via `APIError.status + code` combined:
|
|
152
|
+
|
|
153
|
+
- `APIError.code` is semantically stable (`context_length_exceeded`, `content_filter`, `invalid_api_key`, etc.) across SDK versions; message strings are not.
|
|
154
|
+
- Status alone collapses three distinct failure modes into one bucket (`400` = context-length OR content-filter OR bad-model-name).
|
|
155
|
+
- When `code` is missing (proxied deployments), fall back to `status`.
|
|
156
|
+
- Name-based detection catches `APIConnectionTimeoutError` and Node-level `ETIMEDOUT` / `ECONNABORTED`.
|
|
157
|
+
|
|
158
|
+
## Pattern — full fallback ladder
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
async function runWithFallbacks(input: string) {
|
|
162
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
163
|
+
const { data, error } = await myAgent.execute(input);
|
|
164
|
+
|
|
165
|
+
if (!error) return data;
|
|
166
|
+
|
|
167
|
+
if (error instanceof ProviderRateLimitError) {
|
|
168
|
+
await sleep(error.retryAfter ?? 2000);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (error instanceof ContextLengthExceededError) {
|
|
173
|
+
input = truncate(input, error.limit ?? 4000);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (error instanceof QuotaExceededError || error instanceof ProviderAuthError) {
|
|
178
|
+
throw error; // not retryable
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
throw error; // unknown — give up
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
throw new Error("exhausted retries");
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## See also
|
|
189
|
+
|
|
190
|
+
- [`@warlock.js/ai/run-ai-agent/SKILL.md`](@warlock.js/ai/run-ai-agent/SKILL.md) — `AgentResult.error`
|
|
191
|
+
- [`@warlock.js/ai/run-ai-workflow/SKILL.md`](@warlock.js/ai/run-ai-workflow/SKILL.md) — `WorkflowError` subclasses
|
|
192
|
+
- [`@warlock.js/ai/define-ai-tool/SKILL.md`](@warlock.js/ai/define-ai-tool/SKILL.md) — `ToolExecutionError` wrapping
|
|
193
|
+
- [`@warlock.js/ai/log-ai-calls/SKILL.md`](@warlock.js/ai/log-ai-calls/SKILL.md) — error logging
|
|
194
|
+
- `domains/ai/conventions/errors.md` — framework vs app error convention
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: log-ai-calls
|
|
3
|
+
description: 'Framework logging delegated to @warlock.js/logger — every primitive emits via the log singleton, configure channels / levels / redaction once at boot. Four-arg call convention (module, action, message, context). Triggers: `log.configure`, `log.setMinLevel`, `log.setChannels`, `ConsoleLog`, `FileLog`, `LogChannel`, `redact.paths`, `ai.agent.<name>` / `ai.workflow.<name>` / `ai.supervisor.<name>` modules; ''configure ai logging'', ''mask prompts in logs'', ''silence logs in tests'', ''capture log entries''; typical import `import { log } from "@warlock.js/logger"`. Skip: error hierarchy — `@warlock.js/ai/handle-ai-errors/SKILL.md`; competing libs `pino`, `winston`, `console.log`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Logging — `log` from `@warlock.js/logger`
|
|
7
|
+
|
|
8
|
+
`@warlock.js/ai` does not own a logger contract. Every primitive imports the `log` singleton from [`@warlock.js/logger`](@warlock.js/logger/logger-basics/SKILL.md) directly and emits structured entries through it. Configuration — channels, levels, redaction — lives entirely on the logger.
|
|
9
|
+
|
|
10
|
+
**No `ai.config({ logger })`. No per-primitive `logger:` override.** Configure once at app boot; the framework picks it up.
|
|
11
|
+
|
|
12
|
+
## Installation — configure at boot
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { log, ConsoleLog, FileLog } from "@warlock.js/logger";
|
|
16
|
+
|
|
17
|
+
log.configure({
|
|
18
|
+
channels: [
|
|
19
|
+
new ConsoleLog(),
|
|
20
|
+
new FileLog({ chunk: "daily" }),
|
|
21
|
+
],
|
|
22
|
+
autoFlushOn: ["SIGINT", "SIGTERM", "beforeExit"],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
log.setMinLevel("info");
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
That's it. Every agent / workflow / supervisor running in the process emits to the configured channels.
|
|
29
|
+
|
|
30
|
+
## Call convention — four positional args
|
|
31
|
+
|
|
32
|
+
Every framework log call uses the 4-arg positional form:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
log.info("ai.agent", "trip.started", "agent starting trip", { tripIndex, model });
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
- **`module`** — emitting primitive, name-suffixed (`"ai.agent.<name>"`, `"ai.workflow.<name>"`, `"ai.supervisor.<name>"`); provider adapters use `"ai.openai"` etc.
|
|
39
|
+
- **`action`** — mirrors event names without the primitive prefix (`"trip.started"`, `"tool.called"`).
|
|
40
|
+
- **`message`** — human-readable summary.
|
|
41
|
+
- **`context`** — structured bag of diagnostic fields.
|
|
42
|
+
|
|
43
|
+
`action` strips the prefix of the corresponding event (`agent.trip.started` → `trip.started`) so grep filters and event handlers share vocabulary.
|
|
44
|
+
|
|
45
|
+
## Level mapping
|
|
46
|
+
|
|
47
|
+
| Level | Framework usage |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
| `debug` | Internals (request/response bodies, token counts per trip) |
|
|
50
|
+
| `info` | Milestones (agent starting, agent completed) |
|
|
51
|
+
| `warn` | Retries, repair attempts, recoverable tool failures |
|
|
52
|
+
| `error` | Terminal failures surfaced via `result.error` |
|
|
53
|
+
| `success` | Tool-call success |
|
|
54
|
+
|
|
55
|
+
Streaming deltas are intentionally **not** logged at token granularity — trip boundaries carry the same information at readable volume.
|
|
56
|
+
|
|
57
|
+
## What gets logged
|
|
58
|
+
|
|
59
|
+
### Agent
|
|
60
|
+
|
|
61
|
+
| Action | Level | Context |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `agent.starting` | `info` | inputLength, model, maxTrips |
|
|
64
|
+
| `trip.started` | `debug` | tripIndex |
|
|
65
|
+
| `tool.calling` | `debug` | tool name, action, tripIndex |
|
|
66
|
+
| `tool.called` | `success` | tool name, duration, tripIndex |
|
|
67
|
+
| `tool.failed` | `warn` | tool name, error code, tripIndex |
|
|
68
|
+
| `repair.attempting` | `warn` | tripIndex, validation issues |
|
|
69
|
+
| `agent.completed` | `info` | totalUsage, totalDuration, trip count |
|
|
70
|
+
| `agent.error` | `error` | error code, message, stack |
|
|
71
|
+
|
|
72
|
+
### Workflow
|
|
73
|
+
|
|
74
|
+
`workflow.starting` / `step.starting` / `step.completed` / `step.failed` / `workflow.completed` / `workflow.error`. Module is `ai.workflow.<name>`.
|
|
75
|
+
|
|
76
|
+
### Supervisor
|
|
77
|
+
|
|
78
|
+
`supervisor.starting` / `iteration.starting` / `router.deciding` / `router.decided` / `agent.starting` (per dispatched agent) / `iteration.completed` / `evaluate.verdict` / `supervisor.completed`. Module is `ai.supervisor.<name>`.
|
|
79
|
+
|
|
80
|
+
### Provider adapter
|
|
81
|
+
|
|
82
|
+
`ai.openai` (and future adapters) emit `request` (debug) and `response` (debug) per call, plus `error` on the wrapped `AIError`.
|
|
83
|
+
|
|
84
|
+
## Redaction
|
|
85
|
+
|
|
86
|
+
Redaction is a `@warlock.js/logger` feature — configure once on the logger, applies to every framework log automatically.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
log.configure({
|
|
90
|
+
redact: {
|
|
91
|
+
paths: [
|
|
92
|
+
"context.messages", // prompts
|
|
93
|
+
"context.input", // user input
|
|
94
|
+
"context.apiKey", // never log this anyway, but defense-in-depth
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
See [`@warlock.js/logger/redact-sensitive-log-fields/SKILL.md`](@warlock.js/logger/redact-sensitive-log-fields/SKILL.md) for the full redaction surface.
|
|
101
|
+
|
|
102
|
+
## Events vs. logs — two channels, one source
|
|
103
|
+
|
|
104
|
+
- **Events** are push-model (subscribers), typed payloads, per-execution lifetime — ideal for UI streaming, SSE, metrics.
|
|
105
|
+
- **Logs** are pull-model (written to channels), structured-string + context, persistent — ideal for grep, post-mortem.
|
|
106
|
+
|
|
107
|
+
Both fire from the same internal emit so every event produces both.
|
|
108
|
+
|
|
109
|
+
## Patterns
|
|
110
|
+
|
|
111
|
+
### Silence everything in tests
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import { log } from "@warlock.js/logger";
|
|
115
|
+
|
|
116
|
+
beforeAll(() => log.setChannels([]));
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Capture all framework log entries in a test
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
import { log, LogChannel } from "@warlock.js/logger";
|
|
123
|
+
|
|
124
|
+
class Capture extends LogChannel {
|
|
125
|
+
public name = "capture";
|
|
126
|
+
public entries: any[] = [];
|
|
127
|
+
public log(data) { this.entries.push(data); }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const capture = new Capture();
|
|
131
|
+
log.setChannels([capture]);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
See [`@warlock.js/logger/test-logging-code/SKILL.md`](@warlock.js/logger/test-logging-code/SKILL.md) for the test patterns.
|
|
135
|
+
|
|
136
|
+
## See also
|
|
137
|
+
|
|
138
|
+
- [`@warlock.js/logger/logger-basics/SKILL.md`](@warlock.js/logger/logger-basics/SKILL.md) — logger foundations
|
|
139
|
+
- [`@warlock.js/logger/configure-logger/SKILL.md`](@warlock.js/logger/configure-logger/SKILL.md) — startup setup
|
|
140
|
+
- [`@warlock.js/logger/redact-sensitive-log-fields/SKILL.md`](@warlock.js/logger/redact-sensitive-log-fields/SKILL.md) — redaction
|
|
141
|
+
- [`@warlock.js/ai/handle-ai-errors/SKILL.md`](@warlock.js/ai/handle-ai-errors/SKILL.md) — what lands on the `error` channel
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: persist-ai-data
|
|
3
|
+
description: 'Persistence delegated to @warlock.js/cache — workflow + supervisor snapshot resume via snapshotStore, semantic cache via vector-capable CacheDriver, global default via ai.config({defaultStore}). Covers drift detection + three recovery paths. Triggers: `ai.config`, `defaultStore`, `snapshotStore`, `wf.resume`, `supervisor.resume`, `WorkflowSnapshot`, `SupervisorSnapshot`, `WorkflowDriftError`, `SupervisorDriftError`, `force: true`; ''resume a workflow run'', ''configure snapshot store'', ''handle signature drift'', ''wire pg vector cache''; typical import `import { ai } from "@warlock.js/ai"`. Skip: cache driver catalog — `@warlock.js/cache/cache-basics/SKILL.md`; competing libs `temporal`, `inngest`.'
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Persistence — `@warlock.js/cache` everywhere
|
|
7
|
+
|
|
8
|
+
`@warlock.js/ai` owns no persistence primitives. Anything that needs durable state — supervisor / workflow snapshot resume, semantic cache, future memory — accepts a `CacheDriver` from `@warlock.js/cache`. The cache package ships memory / lru-memory / file / redis / pg drivers; pg adds optional `pgvector` for similarity retrieval.
|
|
9
|
+
|
|
10
|
+
## The big picture
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
┌──────────────┐ ┌─────────────────────────┐
|
|
14
|
+
│ ai.config │ ───▶ │ @warlock.js/cache │
|
|
15
|
+
│ defaultStore │ │ CacheDriver │
|
|
16
|
+
└──────────────┘ │ (memory|redis|pg|...) │
|
|
17
|
+
└────────────▲────────────┘
|
|
18
|
+
│
|
|
19
|
+
┌─────────────────────────────┼─────────────────────────────┐
|
|
20
|
+
┌──────────────┐ ┌────────────────────┐ ┌──────────────────┐
|
|
21
|
+
│ supervisor │ │ workflow │ │ semanticCache │
|
|
22
|
+
│ snapshotStore│ │ snapshotStore │ │ store (vector) │
|
|
23
|
+
└──────────────┘ └────────────────────┘ └──────────────────┘
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Resolution order
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
options.store ?? ai.config({ defaultStore }) ?? undefined
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
When neither is set:
|
|
33
|
+
- **Snapshot consumers** silently skip writes and throw on `resume()`.
|
|
34
|
+
- **Semantic cache** throws at construction.
|
|
35
|
+
|
|
36
|
+
## `ai.config({ defaultStore })` — set once at boot
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { ai } from "@warlock.js/ai";
|
|
40
|
+
import { cache } from "@warlock.js/cache";
|
|
41
|
+
|
|
42
|
+
ai.config({
|
|
43
|
+
defaultStore: cache.driver("redis", { client: redisClient }),
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Every consumer that doesn't supply its own `store` / `snapshotStore` picks this up. Per-declaration overrides win.
|
|
48
|
+
|
|
49
|
+
## Picking a driver
|
|
50
|
+
|
|
51
|
+
| Driver | KV | TTL | Tags | `similar()` | Fits |
|
|
52
|
+
|---|---|---|---|---|---|
|
|
53
|
+
| `memory` / `lru-memory` | ✅ | ✅ | ✅ | ✅ (brute force) | Dev / tests |
|
|
54
|
+
| `file` | ✅ | ✅ | ✅ | ❌ | Single-process persistence |
|
|
55
|
+
| `null` | no-op | no-op | no-op | `[]` | Test isolation |
|
|
56
|
+
| `redis` | ✅ | ✅ | ✅ | (RediSearch, separate phase) | Production KV + future similarity |
|
|
57
|
+
| `pg` | ✅ | ✅ | ✅ | ✅ (pgvector) | Production semantic cache |
|
|
58
|
+
|
|
59
|
+
Brute-force memory drivers carry an `O(N)` similarity scan — fine up to a few thousand entries.
|
|
60
|
+
|
|
61
|
+
## Snapshot resume — workflow + supervisor
|
|
62
|
+
|
|
63
|
+
### Wiring
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
ai.config({ defaultStore: cache.driver("redis", { client }) });
|
|
67
|
+
|
|
68
|
+
const wf = ai.workflow({
|
|
69
|
+
name: "ticket-processor",
|
|
70
|
+
steps: [...],
|
|
71
|
+
// snapshotStore optional — falls back to defaultStore
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const sup = ai.supervisor({
|
|
75
|
+
name: "support-team",
|
|
76
|
+
router: routerAgent,
|
|
77
|
+
intents: { triage, billing, resolver },
|
|
78
|
+
// explicit override when this primitive needs a different driver
|
|
79
|
+
snapshotStore: cache.driver("pg", { client: pgPool, table: "support_runs" }),
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Snapshot shapes
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
type WorkflowSnapshot = {
|
|
87
|
+
runId: string;
|
|
88
|
+
workflowName: string;
|
|
89
|
+
signature: string; // structural fingerprint
|
|
90
|
+
version?: string;
|
|
91
|
+
input: unknown;
|
|
92
|
+
state: Record<string, unknown>;
|
|
93
|
+
steps: Record<string, StepSnapshot>;
|
|
94
|
+
next: string | null;
|
|
95
|
+
status: "running" | "completed" | "failed" | "cancelled";
|
|
96
|
+
startedAt: string;
|
|
97
|
+
savedAt: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
type SupervisorSnapshot = {
|
|
101
|
+
runId: string;
|
|
102
|
+
supervisorName: string;
|
|
103
|
+
signature: string;
|
|
104
|
+
input: string | Record<string, unknown>; // SupervisorInput
|
|
105
|
+
iteration: number; // last *completed* iteration; -1 before any settle
|
|
106
|
+
snapshots: IterationSnapshot[];
|
|
107
|
+
status: "running" | "completed" | "failed" | "cancelled";
|
|
108
|
+
startedAt: string;
|
|
109
|
+
savedAt: string;
|
|
110
|
+
};
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Checkpoint rules
|
|
114
|
+
|
|
115
|
+
- Workflow: snapshot after every step settles. Parallel groups checkpoint atomically.
|
|
116
|
+
- Supervisor: snapshot after every iteration. Plus once on final completion / cancel / fail.
|
|
117
|
+
- Mid-step / mid-iteration crash resumes from the last completed checkpoint — partial work is **not** persisted.
|
|
118
|
+
- **Idempotency is the user's responsibility.** Steps and agents may re-run on resume.
|
|
119
|
+
|
|
120
|
+
## Fresh run vs. resume
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const result = await wf.execute({ input, runId: "ticket-123" });
|
|
124
|
+
const result = await wf.resume("ticket-123");
|
|
125
|
+
|
|
126
|
+
await sup.execute("urgent", { runId: "support-7" });
|
|
127
|
+
await sup.resume("support-7");
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Resume reads the snapshot, rehydrates state, continues from the snapshot's `next`.
|
|
131
|
+
|
|
132
|
+
## Signature drift detection
|
|
133
|
+
|
|
134
|
+
`signature` is a structural fingerprint computed at construction. On `resume()`, current signature is compared to the snapshot's. Mismatch throws `WorkflowDriftError` / `SupervisorDriftError` **without executing**:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
{
|
|
138
|
+
code: "WORKFLOW_DRIFT",
|
|
139
|
+
savedSignature: "abc123…",
|
|
140
|
+
currentSignature: "def456…",
|
|
141
|
+
runId: "ticket-123",
|
|
142
|
+
completedSteps: ["fetch", "extract"],
|
|
143
|
+
pendingStep: "classify",
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Recovery paths
|
|
148
|
+
|
|
149
|
+
Three choices when drift is detected:
|
|
150
|
+
|
|
151
|
+
1. **Discard** — safest when the shape genuinely changed:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
await store.remove("ticket-123");
|
|
155
|
+
await wf.execute({ input, runId: "ticket-123" });
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
2. **Force resume** — escape hatch for trivial edits you know are safe:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
await wf.resume("ticket-123", { force: true });
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
3. **Manual migration** — for changes you can mechanically translate:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const snapshot = await store.get<WorkflowSnapshot>("ticket-123");
|
|
168
|
+
if (snapshot) {
|
|
169
|
+
snapshot.steps.newName = snapshot.steps.oldName;
|
|
170
|
+
delete snapshot.steps.oldName;
|
|
171
|
+
snapshot.signature = wf.signature;
|
|
172
|
+
await store.set("ticket-123", snapshot);
|
|
173
|
+
await wf.resume("ticket-123");
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Semantic cache
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
ai.config({
|
|
181
|
+
defaultStore: cache.driver("pg", {
|
|
182
|
+
client: pgPool,
|
|
183
|
+
vector: { dimensions: 1536, index: "hnsw" },
|
|
184
|
+
}),
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const myAgent = ai.agent({
|
|
188
|
+
model,
|
|
189
|
+
middleware: [
|
|
190
|
+
ai.middleware.semanticCache({
|
|
191
|
+
embedder: openai.embedder({ name: "text-embedding-3-small" }),
|
|
192
|
+
threshold: 0.95,
|
|
193
|
+
ttlMs: 60 * 60 * 1000,
|
|
194
|
+
}),
|
|
195
|
+
],
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The driver must support `similar()`. Without similarity → `CacheUnsupportedError`. See [`@warlock.js/ai/attach-ai-middleware/SKILL.md`](@warlock.js/ai/attach-ai-middleware/SKILL.md).
|
|
200
|
+
|
|
201
|
+
## See also
|
|
202
|
+
|
|
203
|
+
- [`@warlock.js/ai/run-ai-workflow/SKILL.md`](@warlock.js/ai/run-ai-workflow/SKILL.md) — `snapshotStore` + `resume()`
|
|
204
|
+
- [`@warlock.js/ai/run-supervisor/SKILL.md`](@warlock.js/ai/run-supervisor/SKILL.md) — same on supervisor
|
|
205
|
+
- [`@warlock.js/ai/attach-ai-middleware/SKILL.md`](@warlock.js/ai/attach-ai-middleware/SKILL.md) — `semanticCache` middleware
|
|
206
|
+
- [`@warlock.js/ai/handle-ai-errors/SKILL.md`](@warlock.js/ai/handle-ai-errors/SKILL.md) — drift errors
|
|
207
|
+
- [`@warlock.js/cache/cache-basics/SKILL.md`](@warlock.js/cache/cache-basics/SKILL.md) — driver catalog
|