@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,89 @@
|
|
|
1
|
+
//#region ../../@warlock.js/ai/src/supervisor/signature.ts
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic structural fingerprint of a supervisor definition.
|
|
4
|
+
* Persisted on every snapshot so `resume()` can detect drift between
|
|
5
|
+
* the saved run and the current definition. Covers:
|
|
6
|
+
*
|
|
7
|
+
* - Supervisor name.
|
|
8
|
+
* - Every intent key + its resolved description + the underlying
|
|
9
|
+
* unit's stable identity (agent name, workflow name + signature,
|
|
10
|
+
* or `"callback"` marker for dev-callback intents).
|
|
11
|
+
* - Router agent's name (if the supervisor uses LLM routing).
|
|
12
|
+
* - Whether a deterministic `route` callback is configured (but not
|
|
13
|
+
* its contents — route callbacks are code, not data).
|
|
14
|
+
* - Whether an `evaluate` callback is configured.
|
|
15
|
+
* - `initialAgent` when set.
|
|
16
|
+
* - `maxIterations` (a semantic shape change, not a cosmetic one).
|
|
17
|
+
*
|
|
18
|
+
* Does NOT cover: system prompt text, logger, store identity, per-
|
|
19
|
+
* event handlers — all runtime knobs that don't change the shape of
|
|
20
|
+
* a resumable run.
|
|
21
|
+
*/
|
|
22
|
+
function computeSignature(config, entries) {
|
|
23
|
+
const intentsFingerprint = [...entries.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([intent, entry]) => ({
|
|
24
|
+
k: intent,
|
|
25
|
+
d: entry.description,
|
|
26
|
+
u: fingerprintUnit(entry)
|
|
27
|
+
}));
|
|
28
|
+
const fingerprint = {
|
|
29
|
+
n: config.name,
|
|
30
|
+
a: intentsFingerprint,
|
|
31
|
+
r: resolveRouterName(config.router),
|
|
32
|
+
rc: config.route ? 1 : 0,
|
|
33
|
+
e: config.evaluate ? 1 : 0,
|
|
34
|
+
i: config.initialAgent ?? null,
|
|
35
|
+
m: config.maxIterations ?? null,
|
|
36
|
+
c: resolveClassifierFingerprint(config.classifier)
|
|
37
|
+
};
|
|
38
|
+
return hash(JSON.stringify(fingerprint));
|
|
39
|
+
}
|
|
40
|
+
function resolveRouterName(router) {
|
|
41
|
+
if (!router) return null;
|
|
42
|
+
if (typeof router.execute === "function") return router.name ?? null;
|
|
43
|
+
return router.agent?.name ?? null;
|
|
44
|
+
}
|
|
45
|
+
function resolveClassifierFingerprint(classifier) {
|
|
46
|
+
if (!classifier) return null;
|
|
47
|
+
if (typeof classifier === "function") return { t: "callback" };
|
|
48
|
+
if (typeof classifier.execute === "function") return {
|
|
49
|
+
t: "agent",
|
|
50
|
+
n: classifier.name ?? null
|
|
51
|
+
};
|
|
52
|
+
if (typeof classifier.run === "function") return { t: "callback" };
|
|
53
|
+
if (typeof classifier.agent?.execute === "function") return {
|
|
54
|
+
t: "agent",
|
|
55
|
+
n: classifier.agent?.name ?? null
|
|
56
|
+
};
|
|
57
|
+
return { t: "unknown" };
|
|
58
|
+
}
|
|
59
|
+
function fingerprintUnit(entry) {
|
|
60
|
+
if (entry.type === "callback") return { t: "callback" };
|
|
61
|
+
if (entry.type === "workflow") {
|
|
62
|
+
const workflow = entry.unit;
|
|
63
|
+
return {
|
|
64
|
+
t: "workflow",
|
|
65
|
+
n: workflow.name,
|
|
66
|
+
s: workflow.signature
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
t: "agent",
|
|
71
|
+
n: entry.unit.name
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* FNV-1a 32-bit — same hash `workflow/signature.ts` uses. Deterministic,
|
|
76
|
+
* no crypto dependency, cheap; signatures are 8-char hex.
|
|
77
|
+
*/
|
|
78
|
+
function hash(input) {
|
|
79
|
+
let h = 2166136261;
|
|
80
|
+
for (let i = 0; i < input.length; i++) {
|
|
81
|
+
h ^= input.charCodeAt(i);
|
|
82
|
+
h = h + ((h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24)) >>> 0;
|
|
83
|
+
}
|
|
84
|
+
return h.toString(16).padStart(8, "0");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { computeSignature };
|
|
89
|
+
//# sourceMappingURL=signature.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signature.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/signature.ts"],"sourcesContent":["import { ClassifierAgentEntry, ClassifierRunEntry } from \"../contracts\";\nimport type { SupervisorConfig } from \"../contracts/supervisor/supervisor-config.type\";\nimport type { ResolvedIntentEntry } from \"./entries\";\n\n/**\n * Deterministic structural fingerprint of a supervisor definition.\n * Persisted on every snapshot so `resume()` can detect drift between\n * the saved run and the current definition. Covers:\n *\n * - Supervisor name.\n * - Every intent key + its resolved description + the underlying\n * unit's stable identity (agent name, workflow name + signature,\n * or `\"callback\"` marker for dev-callback intents).\n * - Router agent's name (if the supervisor uses LLM routing).\n * - Whether a deterministic `route` callback is configured (but not\n * its contents — route callbacks are code, not data).\n * - Whether an `evaluate` callback is configured.\n * - `initialAgent` when set.\n * - `maxIterations` (a semantic shape change, not a cosmetic one).\n *\n * Does NOT cover: system prompt text, logger, store identity, per-\n * event handlers — all runtime knobs that don't change the shape of\n * a resumable run.\n */\nexport function computeSignature(\n config: SupervisorConfig<unknown>,\n entries: Map<string, ResolvedIntentEntry>,\n): string {\n const intentsFingerprint = [...entries.entries()]\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([intent, entry]) => ({\n k: intent,\n d: entry.description,\n u: fingerprintUnit(entry),\n }));\n\n const fingerprint = {\n n: config.name,\n a: intentsFingerprint,\n r: resolveRouterName(config.router),\n rc: config.route ? 1 : 0,\n e: config.evaluate ? 1 : 0,\n i: config.initialAgent ?? null,\n m: config.maxIterations ?? null,\n // Phase 7 / decisions §37 — classifier is part of structural identity.\n // Resume drift detection notices when the classifier swap changes\n // routing semantics. Same fingerprint shape as router (agent name\n // when applicable; \"callback\" marker for callback form).\n c: resolveClassifierFingerprint(config.classifier),\n };\n\n return hash(JSON.stringify(fingerprint));\n}\n\nfunction resolveRouterName(router: SupervisorConfig<unknown>[\"router\"]): string | null {\n if (!router) {\n return null;\n }\n\n if (typeof (router as { execute?: unknown }).execute === \"function\") {\n return (router as { name?: string }).name ?? null;\n }\n\n return (router as { agent?: { name?: string } }).agent?.name ?? null;\n}\n\nfunction resolveClassifierFingerprint(\n classifier: SupervisorConfig<unknown>[\"classifier\"],\n): unknown {\n if (!classifier) {\n return null;\n }\n\n if (typeof classifier === \"function\") {\n return { t: \"callback\" };\n }\n\n if (typeof (classifier as { execute?: unknown }).execute === \"function\") {\n return { t: \"agent\", n: (classifier as { name?: string }).name ?? null };\n }\n\n if (typeof (classifier as ClassifierRunEntry).run === \"function\") {\n return { t: \"callback\" };\n }\n\n if (typeof (classifier as ClassifierAgentEntry).agent?.execute === \"function\") {\n return {\n t: \"agent\",\n n: (classifier as ClassifierAgentEntry).agent?.name ?? null,\n };\n }\n\n return { t: \"unknown\" };\n}\n\nfunction fingerprintUnit(entry: ResolvedIntentEntry): unknown {\n if (entry.type === \"callback\") {\n // Callbacks are dev code — fingerprint the type + intent name\n // only (the closure itself can't be hashed deterministically).\n // Drift detection covers add/remove/rename of callback intents,\n // not edits to the function body. Same trade-off as `route`.\n return { t: \"callback\" };\n }\n\n if (entry.type === \"workflow\") {\n const workflow = entry.unit;\n return { t: \"workflow\", n: workflow.name, s: workflow.signature };\n }\n\n return { t: \"agent\", n: entry.unit.name };\n}\n\n/**\n * FNV-1a 32-bit — same hash `workflow/signature.ts` uses. Deterministic,\n * no crypto dependency, cheap; signatures are 8-char hex.\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,iBACd,QACA,SACQ;CACR,MAAM,qBAAqB,CAAC,GAAG,QAAQ,QAAQ,CAAC,EAC7C,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,EACrC,KAAK,CAAC,QAAQ,YAAY;EACzB,GAAG;EACH,GAAG,MAAM;EACT,GAAG,gBAAgB,KAAK;CAC1B,EAAE;CAEJ,MAAM,cAAc;EAClB,GAAG,OAAO;EACV,GAAG;EACH,GAAG,kBAAkB,OAAO,MAAM;EAClC,IAAI,OAAO,QAAQ,IAAI;EACvB,GAAG,OAAO,WAAW,IAAI;EACzB,GAAG,OAAO,gBAAgB;EAC1B,GAAG,OAAO,iBAAiB;EAK3B,GAAG,6BAA6B,OAAO,UAAU;CACnD;CAEA,OAAO,KAAK,KAAK,UAAU,WAAW,CAAC;AACzC;AAEA,SAAS,kBAAkB,QAA4D;CACrF,IAAI,CAAC,QACH,OAAO;CAGT,IAAI,OAAQ,OAAiC,YAAY,YACvD,OAAQ,OAA6B,QAAQ;CAG/C,OAAQ,OAAyC,OAAO,QAAQ;AAClE;AAEA,SAAS,6BACP,YACS;CACT,IAAI,CAAC,YACH,OAAO;CAGT,IAAI,OAAO,eAAe,YACxB,OAAO,EAAE,GAAG,WAAW;CAGzB,IAAI,OAAQ,WAAqC,YAAY,YAC3D,OAAO;EAAE,GAAG;EAAS,GAAI,WAAiC,QAAQ;CAAK;CAGzE,IAAI,OAAQ,WAAkC,QAAQ,YACpD,OAAO,EAAE,GAAG,WAAW;CAGzB,IAAI,OAAQ,WAAoC,OAAO,YAAY,YACjE,OAAO;EACL,GAAG;EACH,GAAI,WAAoC,OAAO,QAAQ;CACzD;CAGF,OAAO,EAAE,GAAG,UAAU;AACxB;AAEA,SAAS,gBAAgB,OAAqC;CAC5D,IAAI,MAAM,SAAS,YAKjB,OAAO,EAAE,GAAG,WAAW;CAGzB,IAAI,MAAM,SAAS,YAAY;EAC7B,MAAM,WAAW,MAAM;EACvB,OAAO;GAAE,GAAG;GAAY,GAAG,SAAS;GAAM,GAAG,SAAS;EAAU;CAClE;CAEA,OAAO;EAAE,GAAG;EAAS,GAAG,MAAM,KAAK;CAAK;AAC1C;;;;;AAMA,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"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IterationSnapshot } from "../contracts/supervisor/iteration-snapshot.type.mjs";
|
|
2
|
+
import { SupervisorInput } from "../contracts/supervisor/supervisor-input.type.mjs";
|
|
3
|
+
import { SupervisorConfig } from "../contracts/supervisor/supervisor-config.type.mjs";
|
|
4
|
+
import { SupervisorResumeOptions } from "../contracts/supervisor/supervisor-execute-options.type.mjs";
|
|
5
|
+
import { SupervisorSnapshot, SupervisorSnapshotStatus } from "../contracts/supervisor/supervisor-snapshot.type.mjs";
|
|
6
|
+
|
|
7
|
+
//#region ../../@warlock.js/ai/src/supervisor/snapshot.d.ts
|
|
8
|
+
type PersistParams = {
|
|
9
|
+
config: SupervisorConfig<unknown>;
|
|
10
|
+
signature: string;
|
|
11
|
+
runId: string;
|
|
12
|
+
input: SupervisorInput;
|
|
13
|
+
startedAt: string;
|
|
14
|
+
iteration: number;
|
|
15
|
+
snapshots: IterationSnapshot[];
|
|
16
|
+
status: SupervisorSnapshotStatus;
|
|
17
|
+
};
|
|
18
|
+
type PersistOutcome = {
|
|
19
|
+
ok: true;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
error: unknown;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Write the current run state to the resolved snapshot store. No-op
|
|
26
|
+
* (ok) when neither the supervisor's `snapshotStore` nor the global
|
|
27
|
+
* `defaultStore` is configured. Failures are returned as
|
|
28
|
+
* `{ ok: false }` rather than thrown so the engine can surface them
|
|
29
|
+
* via events/logs without aborting the run — callers decide whether
|
|
30
|
+
* a failed checkpoint is fatal.
|
|
31
|
+
*/
|
|
32
|
+
declare function persistSupervisorSnapshot(params: PersistParams): Promise<PersistOutcome>;
|
|
33
|
+
/**
|
|
34
|
+
* Load a persisted snapshot for `resume()` and run the drift check.
|
|
35
|
+
* Throws `SupervisorFailedError` when no store is configured or when
|
|
36
|
+
* the run is missing; throws `SupervisorDriftError` when the stored
|
|
37
|
+
* signature doesn't match the current definition (unless `force` is
|
|
38
|
+
* set).
|
|
39
|
+
*/
|
|
40
|
+
declare function loadSnapshotForResume(params: {
|
|
41
|
+
config: SupervisorConfig<unknown>;
|
|
42
|
+
signature: string;
|
|
43
|
+
runId: string;
|
|
44
|
+
options?: SupervisorResumeOptions;
|
|
45
|
+
}): Promise<SupervisorSnapshot>;
|
|
46
|
+
/**
|
|
47
|
+
* Canonical key shape used in the KVStore. Prefixed so supervisor
|
|
48
|
+
* snapshots don't collide with workflow / session snapshots in a
|
|
49
|
+
* shared store.
|
|
50
|
+
*/
|
|
51
|
+
declare function snapshotKey(runId: string): string;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { loadSnapshotForResume, persistSupervisorSnapshot, snapshotKey };
|
|
54
|
+
//# sourceMappingURL=snapshot.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/snapshot.ts"],"mappings":";;;;;;;KAoBY,aAAA;EACV,MAAA,EAAQ,gBAAA;EACR,SAAA;EACA,KAAA;EACA,KAAA,EAAO,eAAA;EACP,SAAA;EACA,SAAA;EACA,SAAA,EAAW,iBAAA;EACX,MAAA,EAAQ,wBAAA;AAAA;AAAA,KAGE,cAAA;EAAmB,EAAA;AAAA;EAAe,EAAA;EAAW,KAAA;AAAA;;;;;;;;;iBAUnC,yBAAA,CACpB,MAAA,EAAQ,aAAA,GACP,OAAA,CAAQ,cAAA;AAZX;;;;;;;AAAA,iBA+CsB,qBAAA,CAAsB,MAAA;EAC1C,MAAA,EAAQ,gBAAA;EACR,SAAA;EACA,KAAA;EACA,OAAA,GAAU,uBAAA;AAAA,IACR,OAAA,CAAQ,kBAAA;;;;;;iBAuCI,WAAA,CAAY,KAAa"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { SupervisorFailedError } from "../errors/supervisor-failed-error.mjs";
|
|
2
|
+
import { SupervisorDriftError } from "../errors/supervisor-drift-error.mjs";
|
|
3
|
+
import "../errors/index.mjs";
|
|
4
|
+
import { resolveDefaultStore } from "../config.mjs";
|
|
5
|
+
|
|
6
|
+
//#region ../../@warlock.js/ai/src/supervisor/snapshot.ts
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the effective snapshot store: the supervisor's own
|
|
9
|
+
* `snapshotStore` field wins; absent that, fall back to the global
|
|
10
|
+
* default set via `ai.config({ defaultStore })`.
|
|
11
|
+
*/
|
|
12
|
+
function resolveSnapshotStore(config) {
|
|
13
|
+
return config.snapshotStore ?? resolveDefaultStore();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Write the current run state to the resolved snapshot store. No-op
|
|
17
|
+
* (ok) when neither the supervisor's `snapshotStore` nor the global
|
|
18
|
+
* `defaultStore` is configured. Failures are returned as
|
|
19
|
+
* `{ ok: false }` rather than thrown so the engine can surface them
|
|
20
|
+
* via events/logs without aborting the run — callers decide whether
|
|
21
|
+
* a failed checkpoint is fatal.
|
|
22
|
+
*/
|
|
23
|
+
async function persistSupervisorSnapshot(params) {
|
|
24
|
+
const store = resolveSnapshotStore(params.config);
|
|
25
|
+
if (!store) return { ok: true };
|
|
26
|
+
const snapshot = {
|
|
27
|
+
runId: params.runId,
|
|
28
|
+
supervisorName: params.config.name,
|
|
29
|
+
signature: params.signature,
|
|
30
|
+
input: params.input,
|
|
31
|
+
iteration: params.iteration,
|
|
32
|
+
snapshots: params.snapshots,
|
|
33
|
+
status: params.status,
|
|
34
|
+
startedAt: params.startedAt,
|
|
35
|
+
savedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
await store.set(snapshotKey(params.runId), snapshot);
|
|
39
|
+
return { ok: true };
|
|
40
|
+
} catch (error) {
|
|
41
|
+
return {
|
|
42
|
+
ok: false,
|
|
43
|
+
error
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Load a persisted snapshot for `resume()` and run the drift check.
|
|
49
|
+
* Throws `SupervisorFailedError` when no store is configured or when
|
|
50
|
+
* the run is missing; throws `SupervisorDriftError` when the stored
|
|
51
|
+
* signature doesn't match the current definition (unless `force` is
|
|
52
|
+
* set).
|
|
53
|
+
*/
|
|
54
|
+
async function loadSnapshotForResume(params) {
|
|
55
|
+
const store = resolveSnapshotStore(params.config);
|
|
56
|
+
if (!store) throw new SupervisorFailedError(`supervisor "${params.config.name}" has no store configured — set \`snapshotStore\` on the config or call \`ai.config({ defaultStore })\` at boot before calling resume()`, { context: { runId: params.runId } });
|
|
57
|
+
const snapshot = await store.get(snapshotKey(params.runId)) ?? null;
|
|
58
|
+
if (!snapshot) throw new SupervisorFailedError(`supervisor "${params.config.name}": no snapshot for runId "${params.runId}"`, { context: { runId: params.runId } });
|
|
59
|
+
if (!params.options?.force && snapshot.signature !== params.signature) throw new SupervisorDriftError(`supervisor "${params.config.name}" signature drift on resume`, {
|
|
60
|
+
savedSignature: snapshot.signature,
|
|
61
|
+
currentSignature: params.signature,
|
|
62
|
+
runId: params.runId
|
|
63
|
+
});
|
|
64
|
+
return snapshot;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Canonical key shape used in the KVStore. Prefixed so supervisor
|
|
68
|
+
* snapshots don't collide with workflow / session snapshots in a
|
|
69
|
+
* shared store.
|
|
70
|
+
*/
|
|
71
|
+
function snapshotKey(runId) {
|
|
72
|
+
return `supervisor:${runId}`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { loadSnapshotForResume, persistSupervisorSnapshot, snapshotKey };
|
|
77
|
+
//# sourceMappingURL=snapshot.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/snapshot.ts"],"sourcesContent":["import { resolveDefaultStore } from \"../config\";\nimport type { IterationSnapshot } from \"../contracts/supervisor/iteration-snapshot.type\";\nimport type { SupervisorConfig } from \"../contracts/supervisor/supervisor-config.type\";\nimport type { SupervisorResumeOptions } from \"../contracts/supervisor/supervisor-execute-options.type\";\nimport type { SupervisorInput } from \"../contracts/supervisor/supervisor-input.type\";\nimport type {\n SupervisorSnapshot,\n SupervisorSnapshotStatus,\n} from \"../contracts/supervisor/supervisor-snapshot.type\";\nimport { SupervisorDriftError, SupervisorFailedError } from \"../errors\";\n\n/**\n * Resolve the effective snapshot store: the supervisor's own\n * `snapshotStore` field wins; absent that, fall back to the global\n * default set via `ai.config({ defaultStore })`.\n */\nfunction resolveSnapshotStore(config: SupervisorConfig<unknown>) {\n return config.snapshotStore ?? resolveDefaultStore();\n}\n\nexport type PersistParams = {\n config: SupervisorConfig<unknown>;\n signature: string;\n runId: string;\n input: SupervisorInput;\n startedAt: string;\n iteration: number;\n snapshots: IterationSnapshot[];\n status: SupervisorSnapshotStatus;\n};\n\nexport type PersistOutcome = { ok: true } | { ok: false; error: unknown };\n\n/**\n * Write the current run state to the resolved snapshot store. No-op\n * (ok) when neither the supervisor's `snapshotStore` nor the global\n * `defaultStore` is configured. Failures are returned as\n * `{ ok: false }` rather than thrown so the engine can surface them\n * via events/logs without aborting the run — callers decide whether\n * a failed checkpoint is fatal.\n */\nexport async function persistSupervisorSnapshot(\n params: PersistParams,\n): Promise<PersistOutcome> {\n const store = resolveSnapshotStore(params.config);\n\n if (!store) {\n return { ok: true };\n }\n\n const snapshot: SupervisorSnapshot = {\n runId: params.runId,\n supervisorName: params.config.name,\n signature: params.signature,\n input: params.input,\n iteration: params.iteration,\n snapshots: params.snapshots,\n status: params.status,\n startedAt: params.startedAt,\n savedAt: new Date().toISOString(),\n };\n\n try {\n await store.set(snapshotKey(params.runId), snapshot);\n\n return { ok: true };\n } catch (error) {\n return { ok: false, error };\n }\n}\n\n/**\n * Load a persisted snapshot for `resume()` and run the drift check.\n * Throws `SupervisorFailedError` when no store is configured or when\n * the run is missing; throws `SupervisorDriftError` when the stored\n * signature doesn't match the current definition (unless `force` is\n * set).\n */\nexport async function loadSnapshotForResume(params: {\n config: SupervisorConfig<unknown>;\n signature: string;\n runId: string;\n options?: SupervisorResumeOptions;\n}): Promise<SupervisorSnapshot> {\n const store = resolveSnapshotStore(params.config);\n\n if (!store) {\n throw new SupervisorFailedError(\n `supervisor \"${params.config.name}\" has no store configured — set \\`snapshotStore\\` on the config or call \\`ai.config({ defaultStore })\\` at boot before calling resume()`,\n { context: { runId: params.runId } },\n );\n }\n\n const snapshot =\n (await store.get<SupervisorSnapshot>(snapshotKey(params.runId))) ?? null;\n\n if (!snapshot) {\n throw new SupervisorFailedError(\n `supervisor \"${params.config.name}\": no snapshot for runId \"${params.runId}\"`,\n { context: { runId: params.runId } },\n );\n }\n\n if (!params.options?.force && snapshot.signature !== params.signature) {\n throw new SupervisorDriftError(\n `supervisor \"${params.config.name}\" signature drift on resume`,\n {\n savedSignature: snapshot.signature,\n currentSignature: params.signature,\n runId: params.runId,\n },\n );\n }\n\n return snapshot;\n}\n\n/**\n * Canonical key shape used in the KVStore. Prefixed so supervisor\n * snapshots don't collide with workflow / session snapshots in a\n * shared store.\n */\nexport function snapshotKey(runId: string): string {\n return `supervisor:${runId}`;\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAS,qBAAqB,QAAmC;CAC/D,OAAO,OAAO,iBAAiB,oBAAoB;AACrD;;;;;;;;;AAuBA,eAAsB,0BACpB,QACyB;CACzB,MAAM,QAAQ,qBAAqB,OAAO,MAAM;CAEhD,IAAI,CAAC,OACH,OAAO,EAAE,IAAI,KAAK;CAGpB,MAAM,WAA+B;EACnC,OAAO,OAAO;EACd,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO;EAClB,OAAO,OAAO;EACd,WAAW,OAAO;EAClB,WAAW,OAAO;EAClB,QAAQ,OAAO;EACf,WAAW,OAAO;EAClB,0BAAS,IAAI,KAAK,GAAE,YAAY;CAClC;CAEA,IAAI;EACF,MAAM,MAAM,IAAI,YAAY,OAAO,KAAK,GAAG,QAAQ;EAEnD,OAAO,EAAE,IAAI,KAAK;CACpB,SAAS,OAAO;EACd,OAAO;GAAE,IAAI;GAAO;EAAM;CAC5B;AACF;;;;;;;;AASA,eAAsB,sBAAsB,QAKZ;CAC9B,MAAM,QAAQ,qBAAqB,OAAO,MAAM;CAEhD,IAAI,CAAC,OACH,MAAM,IAAI,sBACR,eAAe,OAAO,OAAO,KAAK,0IAClC,EAAE,SAAS,EAAE,OAAO,OAAO,MAAM,EAAE,CACrC;CAGF,MAAM,WACH,MAAM,MAAM,IAAwB,YAAY,OAAO,KAAK,CAAC,KAAM;CAEtE,IAAI,CAAC,UACH,MAAM,IAAI,sBACR,eAAe,OAAO,OAAO,KAAK,4BAA4B,OAAO,MAAM,IAC3E,EAAE,SAAS,EAAE,OAAO,OAAO,MAAM,EAAE,CACrC;CAGF,IAAI,CAAC,OAAO,SAAS,SAAS,SAAS,cAAc,OAAO,WAC1D,MAAM,IAAI,qBACR,eAAe,OAAO,OAAO,KAAK,8BAClC;EACE,gBAAgB,SAAS;EACzB,kBAAkB,OAAO;EACzB,OAAO,OAAO;CAChB,CACF;CAGF,OAAO;AACT;;;;;;AAOA,SAAgB,YAAY,OAAuB;CACjD,OAAO,cAAc;AACvB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { StreamContract } from "../contracts/stream/stream.contract.mjs";
|
|
2
|
+
import { SupervisorStreamEvent } from "../contracts/supervisor/supervisor-stream-event.type.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/ai/src/supervisor/supervisor-stream.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Internal async-queue controller driving `supervisor.stream()`.
|
|
7
|
+
* Mirrors `StreamController` from `agent-stream.ts` — same
|
|
8
|
+
* producer/consumer pipe, same semantics, parameterized by the
|
|
9
|
+
* supervisor event union and terminal result type.
|
|
10
|
+
*/
|
|
11
|
+
type SupervisorStreamController<TResult> = {
|
|
12
|
+
push(event: SupervisorStreamEvent): void;
|
|
13
|
+
end(result: TResult): void;
|
|
14
|
+
fail(error: Error): void;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Factory mirroring `createAgentStream`. Returns a paired
|
|
18
|
+
* `{ controller, stream }` — the `SupervisorExecution` pushes events
|
|
19
|
+
* into the controller while the caller iterates (or awaits `.result`)
|
|
20
|
+
* on the stream side. See `agent-stream.ts` for the full role
|
|
21
|
+
* description.
|
|
22
|
+
*/
|
|
23
|
+
declare function createSupervisorStream<TResult>(): {
|
|
24
|
+
controller: SupervisorStreamController<TResult>;
|
|
25
|
+
stream: StreamContract<TResult, SupervisorStreamEvent>;
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { SupervisorStreamController, createSupervisorStream };
|
|
29
|
+
//# sourceMappingURL=supervisor-stream.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-stream.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/supervisor-stream.ts"],"mappings":";;;;;AAaA;;;;;KAAY,0BAAA;EACV,IAAA,CAAK,KAAA,EAAO,qBAAA;EACZ,GAAA,CAAI,MAAA,EAAQ,OAAA;EACZ,IAAA,CAAK,KAAA,EAAO,KAAA;AAAA;;;;;;;;iBAeE,sBAAA,SAAA,CAAA;EACd,UAAA,EAAY,0BAAA,CAA2B,OAAA;EACvC,MAAA,EAAQ,cAAA,CAAe,OAAA,EAAS,qBAAA;AAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
//#region ../../@warlock.js/ai/src/supervisor/supervisor-stream.ts
|
|
2
|
+
/**
|
|
3
|
+
* Factory mirroring `createAgentStream`. Returns a paired
|
|
4
|
+
* `{ controller, stream }` — the `SupervisorExecution` pushes events
|
|
5
|
+
* into the controller while the caller iterates (or awaits `.result`)
|
|
6
|
+
* on the stream side. See `agent-stream.ts` for the full role
|
|
7
|
+
* description.
|
|
8
|
+
*/
|
|
9
|
+
function createSupervisorStream() {
|
|
10
|
+
const queue = [];
|
|
11
|
+
const pending = [];
|
|
12
|
+
const handlers = /* @__PURE__ */ new Map();
|
|
13
|
+
let closed = false;
|
|
14
|
+
let failure;
|
|
15
|
+
let resolveResult;
|
|
16
|
+
let rejectResult;
|
|
17
|
+
const result = new Promise((resolve, reject) => {
|
|
18
|
+
resolveResult = resolve;
|
|
19
|
+
rejectResult = reject;
|
|
20
|
+
});
|
|
21
|
+
const controller = {
|
|
22
|
+
push(event) {
|
|
23
|
+
const handler = handlers.get(event.type);
|
|
24
|
+
if (handler) try {
|
|
25
|
+
handler(event);
|
|
26
|
+
} catch {}
|
|
27
|
+
const reader = pending.shift();
|
|
28
|
+
if (reader) {
|
|
29
|
+
reader.resolve({
|
|
30
|
+
value: event,
|
|
31
|
+
done: false
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
queue.push(event);
|
|
36
|
+
},
|
|
37
|
+
end(finalResult) {
|
|
38
|
+
closed = true;
|
|
39
|
+
resolveResult(finalResult);
|
|
40
|
+
while (pending.length > 0) pending.shift()?.resolve({
|
|
41
|
+
value: void 0,
|
|
42
|
+
done: true
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
fail(error) {
|
|
46
|
+
closed = true;
|
|
47
|
+
failure = error;
|
|
48
|
+
rejectResult(error);
|
|
49
|
+
while (pending.length > 0) pending.shift()?.reject(error);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const iterator = { next() {
|
|
53
|
+
if (queue.length > 0) return Promise.resolve({
|
|
54
|
+
value: queue.shift(),
|
|
55
|
+
done: false
|
|
56
|
+
});
|
|
57
|
+
if (closed) {
|
|
58
|
+
if (failure) return Promise.reject(failure);
|
|
59
|
+
return Promise.resolve({
|
|
60
|
+
value: void 0,
|
|
61
|
+
done: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
pending.push({
|
|
66
|
+
resolve,
|
|
67
|
+
reject
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
} };
|
|
71
|
+
const stream = {
|
|
72
|
+
result,
|
|
73
|
+
on(handlerMap) {
|
|
74
|
+
for (const [key, handler] of Object.entries(handlerMap)) if (handler) handlers.set(key, handler);
|
|
75
|
+
return stream;
|
|
76
|
+
},
|
|
77
|
+
[Symbol.asyncIterator]() {
|
|
78
|
+
return iterator;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
controller,
|
|
83
|
+
stream
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { createSupervisorStream };
|
|
89
|
+
//# sourceMappingURL=supervisor-stream.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor-stream.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/supervisor-stream.ts"],"sourcesContent":["import type { StreamContract } from \"../contracts/stream/stream.contract\";\nimport type { SupervisorStreamEvent } from \"../contracts/supervisor/supervisor-stream-event.type\";\n\n// Re-export so internal callers that already imported from this file\n// keep working unchanged. Canonical home is the contracts barrel.\nexport type { SupervisorStreamEvent };\n\n/**\n * Internal async-queue controller driving `supervisor.stream()`.\n * Mirrors `StreamController` from `agent-stream.ts` — same\n * producer/consumer pipe, same semantics, parameterized by the\n * supervisor event union and terminal result type.\n */\nexport type SupervisorStreamController<TResult> = {\n push(event: SupervisorStreamEvent): void;\n end(result: TResult): void;\n fail(error: Error): void;\n};\n\ntype PendingRead = {\n resolve(value: IteratorResult<SupervisorStreamEvent>): void;\n reject(error: Error): void;\n};\n\n/**\n * Factory mirroring `createAgentStream`. Returns a paired\n * `{ controller, stream }` — the `SupervisorExecution` pushes events\n * into the controller while the caller iterates (or awaits `.result`)\n * on the stream side. See `agent-stream.ts` for the full role\n * description.\n */\nexport function createSupervisorStream<TResult>(): {\n controller: SupervisorStreamController<TResult>;\n stream: StreamContract<TResult, SupervisorStreamEvent>;\n} {\n const queue: SupervisorStreamEvent[] = [];\n const pending: PendingRead[] = [];\n const handlers = new Map<string, (event: SupervisorStreamEvent) => void>();\n\n let closed = false;\n let failure: Error | undefined;\n let resolveResult!: (value: TResult) => void;\n let rejectResult!: (error: Error) => void;\n\n const result = new Promise<TResult>((resolve, reject) => {\n resolveResult = resolve;\n rejectResult = reject;\n });\n\n const controller: SupervisorStreamController<TResult> = {\n push(event) {\n const handler = handlers.get(event.type);\n\n if (handler) {\n try {\n handler(event);\n } catch {\n // Stream handlers must never crash the supervisor.\n }\n }\n\n const reader = pending.shift();\n\n if (reader) {\n reader.resolve({ value: event, done: false });\n return;\n }\n\n queue.push(event);\n },\n\n end(finalResult) {\n closed = true;\n resolveResult(finalResult);\n\n while (pending.length > 0) {\n pending.shift()?.resolve({ value: undefined, done: true });\n }\n },\n\n fail(error) {\n closed = true;\n failure = error;\n rejectResult(error);\n\n while (pending.length > 0) {\n pending.shift()?.reject(error);\n }\n },\n };\n\n const iterator: AsyncIterator<SupervisorStreamEvent> = {\n next() {\n if (queue.length > 0) {\n return Promise.resolve({ value: queue.shift()!, done: false });\n }\n\n if (closed) {\n if (failure) {\n return Promise.reject(failure);\n }\n\n return Promise.resolve({ value: undefined, done: true });\n }\n\n return new Promise<IteratorResult<SupervisorStreamEvent>>(\n (resolve, reject) => {\n pending.push({ resolve, reject });\n },\n );\n },\n };\n\n // The `StreamContract<TResult>` shape is shared across primitives —\n // it types `on()` over the generic `StreamEvent` union (agent\n // events). Supervisor events are a distinct discriminated union\n // with the same `type`-keyed shape, so we satisfy the contract via\n // a structural cast — handlers see the supervisor events at their\n // correct narrowed types.\n const stream = {\n result,\n on(handlerMap) {\n for (const [key, handler] of Object.entries(handlerMap)) {\n if (handler) {\n handlers.set(key, handler as (event: SupervisorStreamEvent) => void);\n }\n }\n\n return stream;\n },\n [Symbol.asyncIterator]() {\n return iterator;\n },\n } as StreamContract<TResult, SupervisorStreamEvent>;\n\n return { controller, stream };\n}\n"],"mappings":";;;;;;;;AA+BA,SAAgB,yBAGd;CACA,MAAM,QAAiC,CAAC;CACxC,MAAM,UAAyB,CAAC;CAChC,MAAM,2BAAW,IAAI,IAAoD;CAEzE,IAAI,SAAS;CACb,IAAI;CACJ,IAAI;CACJ,IAAI;CAEJ,MAAM,SAAS,IAAI,SAAkB,SAAS,WAAW;EACvD,gBAAgB;EAChB,eAAe;CACjB,CAAC;CAED,MAAM,aAAkD;EACtD,KAAK,OAAO;GACV,MAAM,UAAU,SAAS,IAAI,MAAM,IAAI;GAEvC,IAAI,SACF,IAAI;IACF,QAAQ,KAAK;GACf,QAAQ,CAER;GAGF,MAAM,SAAS,QAAQ,MAAM;GAE7B,IAAI,QAAQ;IACV,OAAO,QAAQ;KAAE,OAAO;KAAO,MAAM;IAAM,CAAC;IAC5C;GACF;GAEA,MAAM,KAAK,KAAK;EAClB;EAEA,IAAI,aAAa;GACf,SAAS;GACT,cAAc,WAAW;GAEzB,OAAO,QAAQ,SAAS,GACtB,QAAQ,MAAM,GAAG,QAAQ;IAAE,OAAO;IAAW,MAAM;GAAK,CAAC;EAE7D;EAEA,KAAK,OAAO;GACV,SAAS;GACT,UAAU;GACV,aAAa,KAAK;GAElB,OAAO,QAAQ,SAAS,GACtB,QAAQ,MAAM,GAAG,OAAO,KAAK;EAEjC;CACF;CAEA,MAAM,WAAiD,EACrD,OAAO;EACL,IAAI,MAAM,SAAS,GACjB,OAAO,QAAQ,QAAQ;GAAE,OAAO,MAAM,MAAM;GAAI,MAAM;EAAM,CAAC;EAG/D,IAAI,QAAQ;GACV,IAAI,SACF,OAAO,QAAQ,OAAO,OAAO;GAG/B,OAAO,QAAQ,QAAQ;IAAE,OAAO;IAAW,MAAM;GAAK,CAAC;EACzD;EAEA,OAAO,IAAI,SACR,SAAS,WAAW;GACnB,QAAQ,KAAK;IAAE;IAAS;GAAO,CAAC;EAClC,CACF;CACF,EACF;CAQA,MAAM,SAAS;EACb;EACA,GAAG,YAAY;GACb,KAAK,MAAM,CAAC,KAAK,YAAY,OAAO,QAAQ,UAAU,GACpD,IAAI,SACF,SAAS,IAAI,KAAK,OAAiD;GAIvE,OAAO;EACT;EACA,CAAC,OAAO,iBAAiB;GACvB,OAAO;EACT;CACF;CAEA,OAAO;EAAE;EAAY;CAAO;AAC9B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SupervisorIntentValue } from "../contracts/supervisor/intent-entry.type.mjs";
|
|
2
|
+
import { SupervisorConfig } from "../contracts/supervisor/supervisor-config.type.mjs";
|
|
3
|
+
import { SupervisorContract } from "../contracts/supervisor/supervisor.contract.mjs";
|
|
4
|
+
|
|
5
|
+
//#region ../../@warlock.js/ai/src/supervisor/supervisor.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* `ai.supervisor(config)` — construct a `SupervisorContract`. Validates
|
|
8
|
+
* the config at author time (throws `SupervisorFailedError` on bad
|
|
9
|
+
* shape), resolves agent entries, computes a stable structural
|
|
10
|
+
* signature, wires the three-tier event emitter, and returns an
|
|
11
|
+
* instance that satisfies `ExecutableContract` so it can compose into
|
|
12
|
+
* tools, outer agents, and (future) orchestrators uniformly.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const support = ai.supervisor({
|
|
16
|
+
* name: "customer-support",
|
|
17
|
+
* router: routerAgent,
|
|
18
|
+
* intents: { triage, orderLookup, billingLookup, resolver },
|
|
19
|
+
* evaluate: (ctx) => ctx.result.resolver?.output ? { satisfied: true } : undefined,
|
|
20
|
+
* output: z.object({ response: z.string(), refund: z.boolean() }),
|
|
21
|
+
* maxIterations: 6,
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
declare function supervisor<TOutput = unknown, TState = TOutput, TIntents extends Record<string, SupervisorIntentValue> = Record<string, SupervisorIntentValue>, TArtifacts = Record<string, unknown>>(config: SupervisorConfig<TOutput, TState, TIntents, TArtifacts>): SupervisorContract<TOutput>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { supervisor };
|
|
27
|
+
//# sourceMappingURL=supervisor.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/supervisor.ts"],"mappings":";;;;;;;AA8CA;;;;;;;;;;;;;;;;iBAAgB,UAAA,6BAEL,OAAA,mBACQ,MAAA,SAAe,qBAAA,IAAyB,MAAA,SAAe,qBAAA,gBAC3D,MAAA,kBAAA,CACb,MAAA,EAAQ,gBAAA,CAAiB,OAAA,EAAS,MAAA,EAAQ,QAAA,EAAU,UAAA,IAAc,kBAAA,CAAmB,OAAA"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { SupervisorFailedError } from "../errors/supervisor-failed-error.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
3
|
+
import { asTool } from "./as-tool.mjs";
|
|
4
|
+
import { SupervisorEmitter } from "./emitter.mjs";
|
|
5
|
+
import { assertRouterDescriptions, resolveIntentEntries } from "./entries.mjs";
|
|
6
|
+
import { loadSnapshotForResume } from "./snapshot.mjs";
|
|
7
|
+
import { SupervisorExecution } from "./execution.mjs";
|
|
8
|
+
import { computeSignature } from "./signature.mjs";
|
|
9
|
+
import { createSupervisorStream } from "./supervisor-stream.mjs";
|
|
10
|
+
|
|
11
|
+
//#region ../../@warlock.js/ai/src/supervisor/supervisor.ts
|
|
12
|
+
/**
|
|
13
|
+
* `ai.supervisor(config)` — construct a `SupervisorContract`. Validates
|
|
14
|
+
* the config at author time (throws `SupervisorFailedError` on bad
|
|
15
|
+
* shape), resolves agent entries, computes a stable structural
|
|
16
|
+
* signature, wires the three-tier event emitter, and returns an
|
|
17
|
+
* instance that satisfies `ExecutableContract` so it can compose into
|
|
18
|
+
* tools, outer agents, and (future) orchestrators uniformly.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const support = ai.supervisor({
|
|
22
|
+
* name: "customer-support",
|
|
23
|
+
* router: routerAgent,
|
|
24
|
+
* intents: { triage, orderLookup, billingLookup, resolver },
|
|
25
|
+
* evaluate: (ctx) => ctx.result.resolver?.output ? { satisfied: true } : undefined,
|
|
26
|
+
* output: z.object({ response: z.string(), refund: z.boolean() }),
|
|
27
|
+
* maxIterations: 6,
|
|
28
|
+
* });
|
|
29
|
+
*/
|
|
30
|
+
function supervisor(config) {
|
|
31
|
+
validateFactoryConfig(config);
|
|
32
|
+
const entries = resolveIntentEntries(config.intents, config.name);
|
|
33
|
+
assertRouterDescriptions(config, entries);
|
|
34
|
+
if (config.initialAgent && !entries.has(config.initialAgent)) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`initialAgent\` "${config.initialAgent}" is not a key in \`intents\``, { context: { authoring: true } });
|
|
35
|
+
const signature = computeSignature(config, entries);
|
|
36
|
+
const emitter = new SupervisorEmitter(config.on);
|
|
37
|
+
async function execute(input, options) {
|
|
38
|
+
return new SupervisorExecution({
|
|
39
|
+
config,
|
|
40
|
+
entries,
|
|
41
|
+
signature,
|
|
42
|
+
emitter,
|
|
43
|
+
input,
|
|
44
|
+
runId: options?.runId ?? generateRunId(),
|
|
45
|
+
options
|
|
46
|
+
}).run();
|
|
47
|
+
}
|
|
48
|
+
function stream(input, options) {
|
|
49
|
+
const runId = options?.runId ?? generateRunId();
|
|
50
|
+
const { controller, stream: contract } = createSupervisorStream();
|
|
51
|
+
new SupervisorExecution({
|
|
52
|
+
config,
|
|
53
|
+
entries,
|
|
54
|
+
signature,
|
|
55
|
+
emitter,
|
|
56
|
+
input,
|
|
57
|
+
runId,
|
|
58
|
+
options,
|
|
59
|
+
streamController: controller
|
|
60
|
+
}).run();
|
|
61
|
+
return contract;
|
|
62
|
+
}
|
|
63
|
+
async function resume(runId, options) {
|
|
64
|
+
const snapshot = await loadSnapshotForResume({
|
|
65
|
+
config,
|
|
66
|
+
signature,
|
|
67
|
+
runId,
|
|
68
|
+
options
|
|
69
|
+
});
|
|
70
|
+
return new SupervisorExecution({
|
|
71
|
+
config,
|
|
72
|
+
entries,
|
|
73
|
+
signature,
|
|
74
|
+
emitter,
|
|
75
|
+
input: snapshot.input,
|
|
76
|
+
runId,
|
|
77
|
+
options,
|
|
78
|
+
resumeFrom: snapshot
|
|
79
|
+
}).run();
|
|
80
|
+
}
|
|
81
|
+
const instance = {
|
|
82
|
+
name: config.name,
|
|
83
|
+
signature,
|
|
84
|
+
execute,
|
|
85
|
+
stream,
|
|
86
|
+
resume,
|
|
87
|
+
on(event, handler) {
|
|
88
|
+
return emitter.on(event, handler);
|
|
89
|
+
},
|
|
90
|
+
off(event, handler) {
|
|
91
|
+
emitter.off(event, handler);
|
|
92
|
+
},
|
|
93
|
+
asTool(options) {
|
|
94
|
+
return asTool(instance, options);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return instance;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Factory-time validation. Enforces the XOR + pairing rules the design
|
|
101
|
+
* locked in §2 and surfaces any violation as a typed
|
|
102
|
+
* `SupervisorFailedError` tagged `authoring: true`.
|
|
103
|
+
*/
|
|
104
|
+
function validateFactoryConfig(config) {
|
|
105
|
+
if (!config.name || typeof config.name !== "string") throw new SupervisorFailedError("ai.supervisor: `name` is required and must be a string", { context: { authoring: true } });
|
|
106
|
+
if (!config.intents || typeof config.intents !== "object") throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`intents\` is required`, { context: { authoring: true } });
|
|
107
|
+
const hasRoute = typeof config.route === "function";
|
|
108
|
+
const hasRouter = !!config.router;
|
|
109
|
+
if (hasRouter) {
|
|
110
|
+
const router = config.router;
|
|
111
|
+
const isBareAgent = typeof router.execute === "function";
|
|
112
|
+
const isEntryForm = !isBareAgent && typeof router.agent === "object" && typeof router.agent?.execute === "function";
|
|
113
|
+
if (!isBareAgent && !isEntryForm) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`router\` must be an agent contract or a \`{ agent, placeholders?, input? }\` entry`, { context: { authoring: true } });
|
|
114
|
+
}
|
|
115
|
+
if (hasRoute && hasRouter) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`route\` and \`router\` are mutually exclusive — configure exactly one`, { context: { authoring: true } });
|
|
116
|
+
const hasClassifier = config.classifier !== void 0;
|
|
117
|
+
if (!hasRoute && !hasRouter && !hasClassifier) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): one of \`route\`, \`router\`, or \`classifier\` is required`, { context: { authoring: true } });
|
|
118
|
+
if (hasClassifier && config.initialAgent) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`classifier\` and \`initialAgent\` are mutually exclusive — both decide which intent runs first. Pick one.`, { context: { authoring: true } });
|
|
119
|
+
if (config.ack !== void 0) {
|
|
120
|
+
const ack = config.ack;
|
|
121
|
+
const isCallback = typeof ack === "function";
|
|
122
|
+
const isAgentEntry = typeof ack === "object" && ack !== null && typeof ack.agent?.execute === "function";
|
|
123
|
+
const isRunEntry = typeof ack === "object" && ack !== null && typeof ack.run === "function";
|
|
124
|
+
if (!isCallback && !isAgentEntry && !isRunEntry) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`ack\` must be an \`{ agent, ... }\` entry, an \`{ run, ... }\` entry, or a bare callback function`, { context: { authoring: true } });
|
|
125
|
+
if (isAgentEntry && isRunEntry) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`ack\` cannot declare both \`agent\` and \`run\` — pick one`, { context: { authoring: true } });
|
|
126
|
+
}
|
|
127
|
+
if (config.maxIterations !== void 0 && config.maxIterations < 1) throw new SupervisorFailedError(`ai.supervisor("${config.name}"): \`maxIterations\` must be >= 1`, { context: {
|
|
128
|
+
authoring: true,
|
|
129
|
+
maxIterations: config.maxIterations
|
|
130
|
+
} });
|
|
131
|
+
}
|
|
132
|
+
function generateRunId() {
|
|
133
|
+
return `sup_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
export { supervisor };
|
|
138
|
+
//# sourceMappingURL=supervisor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supervisor.mjs","names":[],"sources":["../../../../../../@warlock.js/ai/src/supervisor/supervisor.ts"],"sourcesContent":["import type { SupervisorEventMap } from \"../contracts/events/event-map.type\";\nimport type { SupervisorResult } from \"../contracts/result/supervisor-result.type\";\nimport type { StreamContract } from \"../contracts/stream/stream.contract\";\nimport type { SupervisorIntentValue } from \"../contracts/supervisor/intent-entry.type\";\nimport type {\n SupervisorConfig,\n SupervisorEventHandler,\n} from \"../contracts/supervisor/supervisor-config.type\";\nimport type {\n SupervisorExecuteOptions,\n SupervisorResumeOptions,\n} from \"../contracts/supervisor/supervisor-execute-options.type\";\nimport type { SupervisorInput } from \"../contracts/supervisor/supervisor-input.type\";\nimport type { SupervisorStreamEvent } from \"../contracts/supervisor/supervisor-stream-event.type\";\nimport type {\n SupervisorAsToolOptions,\n SupervisorContract,\n} from \"../contracts/supervisor/supervisor.contract\";\nimport { SupervisorFailedError } from \"../errors\";\nimport type { ToolContract } from \"../tool/tool\";\nimport { asTool } from \"./as-tool\";\nimport { SupervisorEmitter } from \"./emitter\";\nimport { assertRouterDescriptions, resolveIntentEntries } from \"./entries\";\nimport { SupervisorExecution } from \"./execution\";\nimport { computeSignature } from \"./signature\";\nimport { loadSnapshotForResume } from \"./snapshot\";\nimport { createSupervisorStream } from \"./supervisor-stream\";\n\n/**\n * `ai.supervisor(config)` — construct a `SupervisorContract`. Validates\n * the config at author time (throws `SupervisorFailedError` on bad\n * shape), resolves agent entries, computes a stable structural\n * signature, wires the three-tier event emitter, and returns an\n * instance that satisfies `ExecutableContract` so it can compose into\n * tools, outer agents, and (future) orchestrators uniformly.\n *\n * @example\n * const support = ai.supervisor({\n * name: \"customer-support\",\n * router: routerAgent,\n * intents: { triage, orderLookup, billingLookup, resolver },\n * evaluate: (ctx) => ctx.result.resolver?.output ? { satisfied: true } : undefined,\n * output: z.object({ response: z.string(), refund: z.boolean() }),\n * maxIterations: 6,\n * });\n */\nexport function supervisor<\n TOutput = unknown,\n TState = TOutput,\n TIntents extends Record<string, SupervisorIntentValue> = Record<string, SupervisorIntentValue>,\n TArtifacts = Record<string, unknown>,\n>(config: SupervisorConfig<TOutput, TState, TIntents, TArtifacts>): SupervisorContract<TOutput> {\n validateFactoryConfig(config as unknown as SupervisorConfig<TOutput>);\n\n const entries = resolveIntentEntries(config.intents, config.name);\n\n assertRouterDescriptions(config as SupervisorConfig<unknown>, entries);\n\n if (config.initialAgent && !entries.has(config.initialAgent)) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): \\`initialAgent\\` \"${config.initialAgent}\" is not a key in \\`intents\\``,\n { context: { authoring: true } },\n );\n }\n\n const signature = computeSignature(config as SupervisorConfig<unknown>, entries);\n const emitter = new SupervisorEmitter(config.on);\n\n async function execute(\n input: SupervisorInput,\n options?: SupervisorExecuteOptions,\n ): Promise<SupervisorResult<TOutput>> {\n const runId = options?.runId ?? generateRunId();\n\n const execution = new SupervisorExecution<TOutput>({\n config: config as unknown as SupervisorConfig<TOutput>,\n entries,\n signature,\n emitter,\n input,\n runId,\n options,\n });\n\n return execution.run();\n }\n\n function stream(\n input: SupervisorInput,\n options?: SupervisorExecuteOptions,\n ): StreamContract<SupervisorResult<TOutput>, SupervisorStreamEvent> {\n const runId = options?.runId ?? generateRunId();\n const { controller, stream: contract } = createSupervisorStream<SupervisorResult<TOutput>>();\n\n const execution = new SupervisorExecution<TOutput>({\n config: config as unknown as SupervisorConfig<TOutput>,\n entries,\n signature,\n emitter,\n input,\n runId,\n options,\n streamController: controller,\n });\n\n void execution.run();\n\n return contract;\n }\n\n async function resume(\n runId: string,\n options?: SupervisorResumeOptions,\n ): Promise<SupervisorResult<TOutput>> {\n const snapshot = await loadSnapshotForResume({\n config: config as SupervisorConfig<unknown>,\n signature,\n runId,\n options,\n });\n\n const execution = new SupervisorExecution<TOutput>({\n config: config as unknown as SupervisorConfig<TOutput>,\n entries,\n signature,\n emitter,\n input: snapshot.input,\n runId,\n options,\n resumeFrom: snapshot,\n });\n\n return execution.run();\n }\n\n const instance: SupervisorContract<TOutput> = {\n name: config.name,\n signature,\n execute,\n stream,\n resume,\n on<K extends keyof SupervisorEventMap>(\n event: K,\n handler: SupervisorEventHandler<K>,\n ): () => void {\n return emitter.on(event, handler);\n },\n off<K extends keyof SupervisorEventMap>(event: K, handler: SupervisorEventHandler<K>): void {\n emitter.off(event, handler);\n },\n asTool<TToolInput = string>(\n options: SupervisorAsToolOptions<TToolInput>,\n ): ToolContract<TToolInput, TOutput> {\n return asTool<TOutput, TToolInput>(instance, options);\n },\n };\n\n return instance;\n}\n\n/**\n * Factory-time validation. Enforces the XOR + pairing rules the design\n * locked in §2 and surfaces any violation as a typed\n * `SupervisorFailedError` tagged `authoring: true`.\n */\nfunction validateFactoryConfig<T>(config: SupervisorConfig<T>): void {\n if (!config.name || typeof config.name !== \"string\") {\n throw new SupervisorFailedError(\"ai.supervisor: `name` is required and must be a string\", {\n context: { authoring: true },\n });\n }\n\n if (!config.intents || typeof config.intents !== \"object\") {\n throw new SupervisorFailedError(`ai.supervisor(\"${config.name}\"): \\`intents\\` is required`, {\n context: { authoring: true },\n });\n }\n\n const hasRoute = typeof config.route === \"function\";\n const hasRouter = !!config.router;\n\n if (hasRouter) {\n const router = config.router as { execute?: unknown } | { agent?: { execute?: unknown } };\n const isBareAgent = typeof (router as { execute?: unknown }).execute === \"function\";\n const isEntryForm =\n !isBareAgent &&\n typeof (router as { agent?: { execute?: unknown } }).agent === \"object\" &&\n typeof (router as { agent?: { execute?: unknown } }).agent?.execute === \"function\";\n\n if (!isBareAgent && !isEntryForm) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): \\`router\\` must be an agent contract or a \\`{ agent, placeholders?, input? }\\` entry`,\n { context: { authoring: true } },\n );\n }\n }\n\n if (hasRoute && hasRouter) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): \\`route\\` and \\`router\\` are mutually exclusive — configure exactly one`,\n { context: { authoring: true } },\n );\n }\n\n // Phase 7 / decisions §37 — `classifier` is the iter-0 prelude;\n // satisfies the \"must have a dispatch source\" rule on its own.\n // Composes with router/route (classifier drives iter 0; router/route\n // takes iter 1+). When configured alone, supervisor terminates after\n // iter 0's branch settles.\n const hasClassifier = config.classifier !== undefined;\n\n if (!hasRoute && !hasRouter && !hasClassifier) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): one of \\`route\\`, \\`router\\`, or \\`classifier\\` is required`,\n { context: { authoring: true } },\n );\n }\n\n // Phase 7 — classifier and initialAgent both decide what runs first.\n // Coexistence is meaningless; throw loudly.\n if (hasClassifier && config.initialAgent) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): \\`classifier\\` and \\`initialAgent\\` are mutually exclusive — both decide which intent runs first. Pick one.`,\n { context: { authoring: true } },\n );\n }\n\n // Phase 3.4 (Q9) — evaluate now pairs with both `route` and\n // `router`. State-driven termination is useful in either dispatch\n // mode; the historical router-only restriction was incidental,\n // not principled.\n\n if (config.ack !== undefined) {\n const ack = config.ack;\n const isCallback = typeof ack === \"function\";\n const isAgentEntry =\n typeof ack === \"object\" &&\n ack !== null &&\n typeof (ack as { agent?: { execute?: unknown } }).agent?.execute === \"function\";\n const isRunEntry =\n typeof ack === \"object\" &&\n ack !== null &&\n typeof (ack as { run?: unknown }).run === \"function\";\n\n if (!isCallback && !isAgentEntry && !isRunEntry) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): \\`ack\\` must be an \\`{ agent, ... }\\` entry, an \\`{ run, ... }\\` entry, or a bare callback function`,\n { context: { authoring: true } },\n );\n }\n\n if (isAgentEntry && isRunEntry) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): \\`ack\\` cannot declare both \\`agent\\` and \\`run\\` — pick one`,\n { context: { authoring: true } },\n );\n }\n }\n\n if (config.maxIterations !== undefined && config.maxIterations < 1) {\n throw new SupervisorFailedError(\n `ai.supervisor(\"${config.name}\"): \\`maxIterations\\` must be >= 1`,\n { context: { authoring: true, maxIterations: config.maxIterations } },\n );\n }\n}\n\nfunction generateRunId(): string {\n return `sup_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,SAAgB,WAKd,QAA8F;CAC9F,sBAAsB,MAA8C;CAEpE,MAAM,UAAU,qBAAqB,OAAO,SAAS,OAAO,IAAI;CAEhE,yBAAyB,QAAqC,OAAO;CAErE,IAAI,OAAO,gBAAgB,CAAC,QAAQ,IAAI,OAAO,YAAY,GACzD,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,wBAAwB,OAAO,aAAa,gCAC1E,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAGF,MAAM,YAAY,iBAAiB,QAAqC,OAAO;CAC/E,MAAM,UAAU,IAAI,kBAAkB,OAAO,EAAE;CAE/C,eAAe,QACb,OACA,SACoC;EAapC,OAAO,IAVe,oBAA6B;GACzC;GACR;GACA;GACA;GACA;GACA,OARY,SAAS,SAAS,cAAc;GAS5C;EACF,CAEe,EAAE,IAAI;CACvB;CAEA,SAAS,OACP,OACA,SACkE;EAClE,MAAM,QAAQ,SAAS,SAAS,cAAc;EAC9C,MAAM,EAAE,YAAY,QAAQ,aAAa,uBAAkD;EAa3F,AAAK,IAXiB,oBAA6B;GACzC;GACR;GACA;GACA;GACA;GACA;GACA;GACA,kBAAkB;EACpB,CAEa,EAAE,IAAI;EAEnB,OAAO;CACT;CAEA,eAAe,OACb,OACA,SACoC;EACpC,MAAM,WAAW,MAAM,sBAAsB;GACnC;GACR;GACA;GACA;EACF,CAAC;EAaD,OAAO,IAXe,oBAA6B;GACzC;GACR;GACA;GACA;GACA,OAAO,SAAS;GAChB;GACA;GACA,YAAY;EACd,CAEe,EAAE,IAAI;CACvB;CAEA,MAAM,WAAwC;EAC5C,MAAM,OAAO;EACb;EACA;EACA;EACA;EACA,GACE,OACA,SACY;GACZ,OAAO,QAAQ,GAAG,OAAO,OAAO;EAClC;EACA,IAAwC,OAAU,SAA0C;GAC1F,QAAQ,IAAI,OAAO,OAAO;EAC5B;EACA,OACE,SACmC;GACnC,OAAO,OAA4B,UAAU,OAAO;EACtD;CACF;CAEA,OAAO;AACT;;;;;;AAOA,SAAS,sBAAyB,QAAmC;CACnE,IAAI,CAAC,OAAO,QAAQ,OAAO,OAAO,SAAS,UACzC,MAAM,IAAI,sBAAsB,0DAA0D,EACxF,SAAS,EAAE,WAAW,KAAK,EAC7B,CAAC;CAGH,IAAI,CAAC,OAAO,WAAW,OAAO,OAAO,YAAY,UAC/C,MAAM,IAAI,sBAAsB,kBAAkB,OAAO,KAAK,8BAA8B,EAC1F,SAAS,EAAE,WAAW,KAAK,EAC7B,CAAC;CAGH,MAAM,WAAW,OAAO,OAAO,UAAU;CACzC,MAAM,YAAY,CAAC,CAAC,OAAO;CAE3B,IAAI,WAAW;EACb,MAAM,SAAS,OAAO;EACtB,MAAM,cAAc,OAAQ,OAAiC,YAAY;EACzE,MAAM,cACJ,CAAC,eACD,OAAQ,OAA6C,UAAU,YAC/D,OAAQ,OAA6C,OAAO,YAAY;EAE1E,IAAI,CAAC,eAAe,CAAC,aACnB,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,2FAC9B,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAEJ;CAEA,IAAI,YAAY,WACd,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,8EAC9B,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAQF,MAAM,gBAAgB,OAAO,eAAe;CAE5C,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,eAC9B,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,kEAC9B,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAKF,IAAI,iBAAiB,OAAO,cAC1B,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,kHAC9B,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAQF,IAAI,OAAO,QAAQ,QAAW;EAC5B,MAAM,MAAM,OAAO;EACnB,MAAM,aAAa,OAAO,QAAQ;EAClC,MAAM,eACJ,OAAO,QAAQ,YACf,QAAQ,QACR,OAAQ,IAA0C,OAAO,YAAY;EACvE,MAAM,aACJ,OAAO,QAAQ,YACf,QAAQ,QACR,OAAQ,IAA0B,QAAQ;EAE5C,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,YACnC,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,0GAC9B,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;EAGF,IAAI,gBAAgB,YAClB,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,mEAC9B,EAAE,SAAS,EAAE,WAAW,KAAK,EAAE,CACjC;CAEJ;CAEA,IAAI,OAAO,kBAAkB,UAAa,OAAO,gBAAgB,GAC/D,MAAM,IAAI,sBACR,kBAAkB,OAAO,KAAK,qCAC9B,EAAE,SAAS;EAAE,WAAW;EAAM,eAAe,OAAO;CAAc,EAAE,CACtE;AAEJ;AAEA,SAAS,gBAAwB;CAC/B,OAAO,OAAO,KAAK,IAAI,EAAE,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE;AACjF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Placeholders } from "../contracts/placeholders.type.mjs";
|
|
2
|
+
import { InstructionContract } from "../contracts/system-prompt.contract.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../@warlock.js/ai/src/system-prompt/instruction.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Concrete `InstructionContract` — a reusable directive block.
|
|
7
|
+
*
|
|
8
|
+
* **Role.** A single addressable prompt block representing one rule the
|
|
9
|
+
* agent must follow (`"Always respond in {{language|English}}."`). Exists
|
|
10
|
+
* as its own type so the same instruction can be shared across many
|
|
11
|
+
* prompts and agents, each render supplying its own placeholder map.
|
|
12
|
+
*
|
|
13
|
+
* **Responsibility.**
|
|
14
|
+
* - Owns: the `type: "instruction"` discriminator, the raw template text,
|
|
15
|
+
* and the placeholder-rendering step.
|
|
16
|
+
* - Does NOT own: ordering relative to other instructions, joining with a
|
|
17
|
+
* persona, or any surrounding prompt composition — those concerns live
|
|
18
|
+
* in `SystemPrompt`.
|
|
19
|
+
*
|
|
20
|
+
* Users construct via the `ai.instruction()` factory — `new Instruction()`
|
|
21
|
+
* is not the public API (see §4.2 of code-style.md).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const replyInLanguage = ai.instruction("Respond in {{language|English}}.");
|
|
25
|
+
*
|
|
26
|
+
* const prompt = ai.systemPrompt()
|
|
27
|
+
* .persona("You are Alex.")
|
|
28
|
+
* .instruction(replyInLanguage)
|
|
29
|
+
* .instruction("Always include code examples.");
|
|
30
|
+
*/
|
|
31
|
+
declare class Instruction implements InstructionContract {
|
|
32
|
+
readonly text: string;
|
|
33
|
+
readonly type: "instruction";
|
|
34
|
+
constructor(text: string);
|
|
35
|
+
/**
|
|
36
|
+
* Substitute `{{mustache}}` placeholders in the instruction text against
|
|
37
|
+
* the supplied map. Delegates to the shared `renderPlaceholders` helper
|
|
38
|
+
* so persona / instruction / system-prompt rendering stays identical.
|
|
39
|
+
*/
|
|
40
|
+
resolve(placeholders?: Placeholders): string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an `Instruction` from raw template text.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const replyIn = instruction("Respond in {{language|English}}.");
|
|
47
|
+
* const cite = instruction("Always cite sources inline.");
|
|
48
|
+
*/
|
|
49
|
+
declare function instruction(text: string): Instruction;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { Instruction, instruction };
|
|
52
|
+
//# sourceMappingURL=instruction.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instruction.d.mts","names":[],"sources":["../../../../../../@warlock.js/ai/src/system-prompt/instruction.ts"],"mappings":";;;;;;AA8BA;;;;;;;;;;;;;AAY4C;AAY5C;;;;AAAsD;;;;;;cAxBzC,WAAA,YAAuB,mBAAmB;EAAA,SAGlB,IAAA;EAAA,SAFnB,IAAA;cAEmB,IAAA;;;;;;EAS5B,OAAA,CAAQ,YAAA,GAAe,YAAA;AAAA;;;;;;;;iBAYhB,WAAA,CAAY,IAAA,WAAe,WAAW"}
|