@warlock.js/core 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -5
- package/README.md +47 -11
- package/esm/ai/src/agent/agent-input-builder.mjs +132 -0
- package/esm/ai/src/agent/agent-input-builder.mjs.map +1 -0
- package/esm/ai/src/agent/agent-log-event.mjs +101 -0
- package/esm/ai/src/agent/agent-log-event.mjs.map +1 -0
- package/esm/ai/src/agent/agent-stream.mjs +82 -0
- package/esm/ai/src/agent/agent-stream.mjs.map +1 -0
- package/esm/ai/src/agent/agent-to-stream-event.mjs +86 -0
- package/esm/ai/src/agent/agent-to-stream-event.mjs.map +1 -0
- package/esm/ai/src/agent/agent.mjs +1157 -0
- package/esm/ai/src/agent/agent.mjs.map +1 -0
- package/esm/ai/src/agent/index.mjs +5 -0
- package/esm/ai/src/agent/json-stream-guard.mjs +400 -0
- package/esm/ai/src/agent/json-stream-guard.mjs.map +1 -0
- package/esm/ai/src/agent/spawn-sub-agent.mjs +68 -0
- package/esm/ai/src/agent/spawn-sub-agent.mjs.map +1 -0
- package/esm/ai/src/ai.mjs +155 -0
- package/esm/ai/src/ai.mjs.map +1 -0
- package/esm/ai/src/batch/batch.mjs +198 -0
- package/esm/ai/src/batch/batch.mjs.map +1 -0
- package/esm/ai/src/batch/index.mjs +3 -0
- package/esm/ai/src/batch/run-batch-item.mjs +100 -0
- package/esm/ai/src/batch/run-batch-item.mjs.map +1 -0
- package/esm/ai/src/batch/run-with-concurrency.mjs +39 -0
- package/esm/ai/src/batch/run-with-concurrency.mjs.map +1 -0
- package/esm/ai/src/checkpoint/memory.mjs +0 -0
- package/esm/ai/src/checkpoint/memory.mjs.map +1 -0
- package/esm/ai/src/checkpoint/pg.mjs +265 -0
- package/esm/ai/src/checkpoint/pg.mjs.map +1 -0
- package/esm/ai/src/checkpoint/redis.mjs +200 -0
- package/esm/ai/src/checkpoint/redis.mjs.map +1 -0
- package/esm/ai/src/config.mjs +59 -0
- package/esm/ai/src/config.mjs.map +1 -0
- package/esm/ai/src/contracts/end.type.mjs +47 -0
- package/esm/ai/src/contracts/end.type.mjs.map +1 -0
- package/esm/ai/src/errors/agent-cancelled-error.mjs +43 -0
- package/esm/ai/src/errors/agent-cancelled-error.mjs.map +1 -0
- package/esm/ai/src/errors/agent-execution-error.mjs +35 -0
- package/esm/ai/src/errors/agent-execution-error.mjs.map +1 -0
- package/esm/ai/src/errors/agent-max-trips-error.mjs +41 -0
- package/esm/ai/src/errors/agent-max-trips-error.mjs.map +1 -0
- package/esm/ai/src/errors/ai-error.mjs +68 -0
- package/esm/ai/src/errors/ai-error.mjs.map +1 -0
- package/esm/ai/src/errors/budget-exceeded-error.mjs +31 -0
- package/esm/ai/src/errors/budget-exceeded-error.mjs.map +1 -0
- package/esm/ai/src/errors/content-filter-error.mjs +28 -0
- package/esm/ai/src/errors/content-filter-error.mjs.map +1 -0
- package/esm/ai/src/errors/context-length-exceeded-error.mjs +31 -0
- package/esm/ai/src/errors/context-length-exceeded-error.mjs.map +1 -0
- package/esm/ai/src/errors/guardrail-violation-error.mjs +41 -0
- package/esm/ai/src/errors/guardrail-violation-error.mjs.map +1 -0
- package/esm/ai/src/errors/index.mjs +37 -0
- package/esm/ai/src/errors/invalid-request-error.mjs +31 -0
- package/esm/ai/src/errors/invalid-request-error.mjs.map +1 -0
- package/esm/ai/src/errors/max-iterations-error.mjs +32 -0
- package/esm/ai/src/errors/max-iterations-error.mjs.map +1 -0
- package/esm/ai/src/errors/max-steps-exceeded-error.mjs +21 -0
- package/esm/ai/src/errors/max-steps-exceeded-error.mjs.map +1 -0
- package/esm/ai/src/errors/orchestrator-cancelled-error.mjs +31 -0
- package/esm/ai/src/errors/orchestrator-cancelled-error.mjs.map +1 -0
- package/esm/ai/src/errors/orchestrator-config-error.mjs +30 -0
- package/esm/ai/src/errors/orchestrator-config-error.mjs.map +1 -0
- package/esm/ai/src/errors/orchestrator-drift-error.mjs +37 -0
- package/esm/ai/src/errors/orchestrator-drift-error.mjs.map +1 -0
- package/esm/ai/src/errors/orchestrator-failed-error.mjs +36 -0
- package/esm/ai/src/errors/orchestrator-failed-error.mjs.map +1 -0
- package/esm/ai/src/errors/outbound-policy-error.mjs +32 -0
- package/esm/ai/src/errors/outbound-policy-error.mjs.map +1 -0
- package/esm/ai/src/errors/planner-cancelled-error.mjs +29 -0
- package/esm/ai/src/errors/planner-cancelled-error.mjs.map +1 -0
- package/esm/ai/src/errors/planner-failed-error.mjs +37 -0
- package/esm/ai/src/errors/planner-failed-error.mjs.map +1 -0
- package/esm/ai/src/errors/planner-plan-invalid-error.mjs +25 -0
- package/esm/ai/src/errors/planner-plan-invalid-error.mjs.map +1 -0
- package/esm/ai/src/errors/provider-auth-error.mjs +26 -0
- package/esm/ai/src/errors/provider-auth-error.mjs.map +1 -0
- package/esm/ai/src/errors/provider-error.mjs +42 -0
- package/esm/ai/src/errors/provider-error.mjs.map +1 -0
- package/esm/ai/src/errors/provider-rate-limit-error.mjs +31 -0
- package/esm/ai/src/errors/provider-rate-limit-error.mjs.map +1 -0
- package/esm/ai/src/errors/provider-timeout-error.mjs +26 -0
- package/esm/ai/src/errors/provider-timeout-error.mjs.map +1 -0
- package/esm/ai/src/errors/quota-exceeded-error.mjs +40 -0
- package/esm/ai/src/errors/quota-exceeded-error.mjs.map +1 -0
- package/esm/ai/src/errors/routing-error.mjs +23 -0
- package/esm/ai/src/errors/routing-error.mjs.map +1 -0
- package/esm/ai/src/errors/schema-validation-error.mjs +37 -0
- package/esm/ai/src/errors/schema-validation-error.mjs.map +1 -0
- package/esm/ai/src/errors/step-failed-error.mjs +19 -0
- package/esm/ai/src/errors/step-failed-error.mjs.map +1 -0
- package/esm/ai/src/errors/supervisor-cancelled-error.mjs +29 -0
- package/esm/ai/src/errors/supervisor-cancelled-error.mjs.map +1 -0
- package/esm/ai/src/errors/supervisor-drift-error.mjs +30 -0
- package/esm/ai/src/errors/supervisor-drift-error.mjs.map +1 -0
- package/esm/ai/src/errors/supervisor-failed-error.mjs +43 -0
- package/esm/ai/src/errors/supervisor-failed-error.mjs.map +1 -0
- package/esm/ai/src/errors/supervisor-routing-error.mjs +39 -0
- package/esm/ai/src/errors/supervisor-routing-error.mjs.map +1 -0
- package/esm/ai/src/errors/tool-execution-error.mjs +32 -0
- package/esm/ai/src/errors/tool-execution-error.mjs.map +1 -0
- package/esm/ai/src/errors/workflow-cancelled-error.mjs +23 -0
- package/esm/ai/src/errors/workflow-cancelled-error.mjs.map +1 -0
- package/esm/ai/src/errors/workflow-drift-error.mjs +24 -0
- package/esm/ai/src/errors/workflow-drift-error.mjs.map +1 -0
- package/esm/ai/src/errors/workflow-error.mjs +18 -0
- package/esm/ai/src/errors/workflow-error.mjs.map +1 -0
- package/esm/ai/src/eval/dataset.mjs +112 -0
- package/esm/ai/src/eval/dataset.mjs.map +1 -0
- package/esm/ai/src/eval/eval-runner.mjs +135 -0
- package/esm/ai/src/eval/eval-runner.mjs.map +1 -0
- package/esm/ai/src/eval/index.mjs +48 -0
- package/esm/ai/src/eval/index.mjs.map +1 -0
- package/esm/ai/src/eval/judge-scorer.mjs +87 -0
- package/esm/ai/src/eval/judge-scorer.mjs.map +1 -0
- package/esm/ai/src/eval/regression.mjs +51 -0
- package/esm/ai/src/eval/regression.mjs.map +1 -0
- package/esm/ai/src/eval/report-json.mjs +33 -0
- package/esm/ai/src/eval/report-json.mjs.map +1 -0
- package/esm/ai/src/eval/report-junit.mjs +60 -0
- package/esm/ai/src/eval/report-junit.mjs.map +1 -0
- package/esm/ai/src/eval/scorers.mjs +101 -0
- package/esm/ai/src/eval/scorers.mjs.map +1 -0
- package/esm/ai/src/guard/detectors/index.mjs +6 -0
- package/esm/ai/src/guard/detectors/injection.mjs +254 -0
- package/esm/ai/src/guard/detectors/injection.mjs.map +1 -0
- package/esm/ai/src/guard/detectors/moderation.mjs +134 -0
- package/esm/ai/src/guard/detectors/moderation.mjs.map +1 -0
- package/esm/ai/src/guard/detectors/pii.mjs +199 -0
- package/esm/ai/src/guard/detectors/pii.mjs.map +1 -0
- package/esm/ai/src/guard/detectors/topic.mjs +99 -0
- package/esm/ai/src/guard/detectors/topic.mjs.map +1 -0
- package/esm/ai/src/guard/errors.mjs +18 -0
- package/esm/ai/src/guard/errors.mjs.map +1 -0
- package/esm/ai/src/guard/guard.mjs +209 -0
- package/esm/ai/src/guard/guard.mjs.map +1 -0
- package/esm/ai/src/guard/guardrail.mjs +22 -0
- package/esm/ai/src/guard/guardrail.mjs.map +1 -0
- package/esm/ai/src/human/errors.mjs +60 -0
- package/esm/ai/src/human/errors.mjs.map +1 -0
- package/esm/ai/src/human/human-approval.mjs +170 -0
- package/esm/ai/src/human/human-approval.mjs.map +1 -0
- package/esm/ai/src/human/policy.mjs +67 -0
- package/esm/ai/src/human/policy.mjs.map +1 -0
- package/esm/ai/src/human/register.mjs +37 -0
- package/esm/ai/src/human/register.mjs.map +1 -0
- package/esm/ai/src/human/resume-seed.mjs +53 -0
- package/esm/ai/src/human/resume-seed.mjs.map +1 -0
- package/esm/ai/src/human/resume.mjs +121 -0
- package/esm/ai/src/human/resume.mjs.map +1 -0
- package/esm/ai/src/human/stores/index.mjs +5 -0
- package/esm/ai/src/human/stores/memory.mjs +91 -0
- package/esm/ai/src/human/stores/memory.mjs.map +1 -0
- package/esm/ai/src/human/stores/pg.mjs +220 -0
- package/esm/ai/src/human/stores/pg.mjs.map +1 -0
- package/esm/ai/src/human/stores/redis.mjs +201 -0
- package/esm/ai/src/human/stores/redis.mjs.map +1 -0
- package/esm/ai/src/index.mjs +174 -0
- package/esm/ai/src/memory/derive-id.mjs +24 -0
- package/esm/ai/src/memory/derive-id.mjs.map +1 -0
- package/esm/ai/src/memory/episodic-memory.mjs +106 -0
- package/esm/ai/src/memory/episodic-memory.mjs.map +1 -0
- package/esm/ai/src/memory/memory.mjs +166 -0
- package/esm/ai/src/memory/memory.mjs.map +1 -0
- package/esm/ai/src/memory/procedural-memory.mjs +103 -0
- package/esm/ai/src/memory/procedural-memory.mjs.map +1 -0
- package/esm/ai/src/memory/semantic-memory.mjs +80 -0
- package/esm/ai/src/memory/semantic-memory.mjs.map +1 -0
- package/esm/ai/src/memory/working-memory.mjs +62 -0
- package/esm/ai/src/memory/working-memory.mjs.map +1 -0
- package/esm/ai/src/middleware/builtins/budget.mjs +219 -0
- package/esm/ai/src/middleware/builtins/budget.mjs.map +1 -0
- package/esm/ai/src/middleware/builtins/guardrail.mjs +76 -0
- package/esm/ai/src/middleware/builtins/guardrail.mjs.map +1 -0
- package/esm/ai/src/middleware/builtins/semantic-cache.mjs +149 -0
- package/esm/ai/src/middleware/builtins/semantic-cache.mjs.map +1 -0
- package/esm/ai/src/middleware/helpers/compose.mjs +52 -0
- package/esm/ai/src/middleware/helpers/compose.mjs.map +1 -0
- package/esm/ai/src/middleware/helpers/for-tool.mjs +80 -0
- package/esm/ai/src/middleware/helpers/for-tool.mjs.map +1 -0
- package/esm/ai/src/middleware/index.mjs +10 -0
- package/esm/ai/src/middleware/pipeline.mjs +100 -0
- package/esm/ai/src/middleware/pipeline.mjs.map +1 -0
- package/esm/ai/src/middleware/utils/extract-user-text.mjs +47 -0
- package/esm/ai/src/middleware/utils/extract-user-text.mjs.map +1 -0
- package/esm/ai/src/middleware/utils/namespaced-state.mjs +60 -0
- package/esm/ai/src/middleware/utils/namespaced-state.mjs.map +1 -0
- package/esm/ai/src/mock/index.mjs +4 -0
- package/esm/ai/src/mock/mock-agent.mjs +3 -0
- package/esm/ai/src/mock/mock-router.mjs +58 -0
- package/esm/ai/src/mock/mock-router.mjs.map +1 -0
- package/esm/ai/src/model/fallback-model.mjs +218 -0
- package/esm/ai/src/model/fallback-model.mjs.map +1 -0
- package/esm/ai/src/model/index.mjs +3 -0
- package/esm/ai/src/object-stream/index.mjs +4 -0
- package/esm/ai/src/object-stream/parse-partial-json.mjs +78 -0
- package/esm/ai/src/object-stream/parse-partial-json.mjs.map +1 -0
- package/esm/ai/src/object-stream/stream-object.mjs +97 -0
- package/esm/ai/src/object-stream/stream-object.mjs.map +1 -0
- package/esm/ai/src/observe/index.mjs +4 -0
- package/esm/ai/src/observe/observer-registry.mjs +35 -0
- package/esm/ai/src/observe/observer-registry.mjs.map +1 -0
- package/esm/ai/src/observe/resolve-observers.mjs +73 -0
- package/esm/ai/src/observe/resolve-observers.mjs.map +1 -0
- package/esm/ai/src/orchestrator/as-tool.mjs +98 -0
- package/esm/ai/src/orchestrator/as-tool.mjs.map +1 -0
- package/esm/ai/src/orchestrator/checkpoint.mjs +75 -0
- package/esm/ai/src/orchestrator/checkpoint.mjs.map +1 -0
- package/esm/ai/src/orchestrator/commands.mjs +34 -0
- package/esm/ai/src/orchestrator/commands.mjs.map +1 -0
- package/esm/ai/src/orchestrator/compaction.mjs +206 -0
- package/esm/ai/src/orchestrator/compaction.mjs.map +1 -0
- package/esm/ai/src/orchestrator/dispatch.mjs +171 -0
- package/esm/ai/src/orchestrator/dispatch.mjs.map +1 -0
- package/esm/ai/src/orchestrator/emitter.mjs +85 -0
- package/esm/ai/src/orchestrator/emitter.mjs.map +1 -0
- package/esm/ai/src/orchestrator/execution.mjs +395 -0
- package/esm/ai/src/orchestrator/execution.mjs.map +1 -0
- package/esm/ai/src/orchestrator/index.mjs +11 -0
- package/esm/ai/src/orchestrator/load.mjs +49 -0
- package/esm/ai/src/orchestrator/load.mjs.map +1 -0
- package/esm/ai/src/orchestrator/lock.mjs +75 -0
- package/esm/ai/src/orchestrator/lock.mjs.map +1 -0
- package/esm/ai/src/orchestrator/memory.mjs +141 -0
- package/esm/ai/src/orchestrator/memory.mjs.map +1 -0
- package/esm/ai/src/orchestrator/orchestrator-stream.mjs +98 -0
- package/esm/ai/src/orchestrator/orchestrator-stream.mjs.map +1 -0
- package/esm/ai/src/orchestrator/orchestrator.mjs +206 -0
- package/esm/ai/src/orchestrator/orchestrator.mjs.map +1 -0
- package/esm/ai/src/orchestrator/resume.mjs +74 -0
- package/esm/ai/src/orchestrator/resume.mjs.map +1 -0
- package/esm/ai/src/orchestrator/session-lock.mjs +83 -0
- package/esm/ai/src/orchestrator/session-lock.mjs.map +1 -0
- package/esm/ai/src/orchestrator/signature.mjs +120 -0
- package/esm/ai/src/orchestrator/signature.mjs.map +1 -0
- package/esm/ai/src/orchestrator/window.mjs +56 -0
- package/esm/ai/src/orchestrator/window.mjs.map +1 -0
- package/esm/ai/src/planner/dag-scheduler.mjs +97 -0
- package/esm/ai/src/planner/dag-scheduler.mjs.map +1 -0
- package/esm/ai/src/planner/index.mjs +6 -0
- package/esm/ai/src/planner/plan-prompt.mjs +31 -0
- package/esm/ai/src/planner/plan-prompt.mjs.map +1 -0
- package/esm/ai/src/planner/plan-schema.mjs +120 -0
- package/esm/ai/src/planner/plan-schema.mjs.map +1 -0
- package/esm/ai/src/planner/planner-run.mjs +614 -0
- package/esm/ai/src/planner/planner-run.mjs.map +1 -0
- package/esm/ai/src/planner/planner.mjs +120 -0
- package/esm/ai/src/planner/planner.mjs.map +1 -0
- package/esm/ai/src/planner/signature.mjs +27 -0
- package/esm/ai/src/planner/signature.mjs.map +1 -0
- package/esm/ai/src/prompt/errors.mjs +73 -0
- package/esm/ai/src/prompt/errors.mjs.map +1 -0
- package/esm/ai/src/prompt/index.mjs +4 -0
- package/esm/ai/src/prompt/prompt-langfuse-sync.mjs +104 -0
- package/esm/ai/src/prompt/prompt-langfuse-sync.mjs.map +1 -0
- package/esm/ai/src/prompt/prompt-validate.mjs +170 -0
- package/esm/ai/src/prompt/prompt-validate.mjs.map +1 -0
- package/esm/ai/src/prompt/prompt.mjs +218 -0
- package/esm/ai/src/prompt/prompt.mjs.map +1 -0
- package/esm/ai/src/prompts/index.mjs +3 -0
- package/esm/ai/src/prompts/prompts-manager.mjs +410 -0
- package/esm/ai/src/prompts/prompts-manager.mjs.map +1 -0
- package/esm/ai/src/prompts/prompts-validate.mjs +200 -0
- package/esm/ai/src/prompts/prompts-validate.mjs.map +1 -0
- package/esm/ai/src/rag/as-tool.mjs +48 -0
- package/esm/ai/src/rag/as-tool.mjs.map +1 -0
- package/esm/ai/src/rag/chunk/chunk.mjs +44 -0
- package/esm/ai/src/rag/chunk/chunk.mjs.map +1 -0
- package/esm/ai/src/rag/chunk/fixed.mjs +32 -0
- package/esm/ai/src/rag/chunk/fixed.mjs.map +1 -0
- package/esm/ai/src/rag/chunk/markdown.mjs +75 -0
- package/esm/ai/src/rag/chunk/markdown.mjs.map +1 -0
- package/esm/ai/src/rag/chunk/recursive.mjs +132 -0
- package/esm/ai/src/rag/chunk/recursive.mjs.map +1 -0
- package/esm/ai/src/rag/chunk/sentence.mjs +73 -0
- package/esm/ai/src/rag/chunk/sentence.mjs.map +1 -0
- package/esm/ai/src/rag/index.mjs +7 -0
- package/esm/ai/src/rag/rag.mjs +126 -0
- package/esm/ai/src/rag/rag.mjs.map +1 -0
- package/esm/ai/src/rag/rerank/keyword-reranker.mjs +58 -0
- package/esm/ai/src/rag/rerank/keyword-reranker.mjs.map +1 -0
- package/esm/ai/src/rag/rerank/llm-reranker.mjs +85 -0
- package/esm/ai/src/rag/rerank/llm-reranker.mjs.map +1 -0
- package/esm/ai/src/rag/retrieve.mjs +68 -0
- package/esm/ai/src/rag/retrieve.mjs.map +1 -0
- package/esm/ai/src/rag/store/cache-vector-store.mjs +48 -0
- package/esm/ai/src/rag/store/cache-vector-store.mjs.map +1 -0
- package/esm/ai/src/security/index.mjs +5 -0
- package/esm/ai/src/security/outbound-policy.mjs +187 -0
- package/esm/ai/src/security/outbound-policy.mjs.map +1 -0
- package/esm/ai/src/security/private-ip.mjs +48 -0
- package/esm/ai/src/security/private-ip.mjs.map +1 -0
- package/esm/ai/src/security/redact.mjs +60 -0
- package/esm/ai/src/security/redact.mjs.map +1 -0
- package/esm/ai/src/serve/serve.mjs +90 -0
- package/esm/ai/src/serve/serve.mjs.map +1 -0
- package/esm/ai/src/serve/sse.mjs +25 -0
- package/esm/ai/src/serve/sse.mjs.map +1 -0
- package/esm/ai/src/serve/stream-to-sse.mjs +37 -0
- package/esm/ai/src/serve/stream-to-sse.mjs.map +1 -0
- package/esm/ai/src/skills/catalog.mjs +140 -0
- package/esm/ai/src/skills/catalog.mjs.map +1 -0
- package/esm/ai/src/skills/index.mjs +11 -0
- package/esm/ai/src/skills/load-skill-tool.mjs +65 -0
- package/esm/ai/src/skills/load-skill-tool.mjs.map +1 -0
- package/esm/ai/src/skills/save-skill-tool.mjs +65 -0
- package/esm/ai/src/skills/save-skill-tool.mjs.map +1 -0
- package/esm/ai/src/skills/skills.mjs +109 -0
- package/esm/ai/src/skills/skills.mjs.map +1 -0
- package/esm/ai/src/skills/sources/directory-source.mjs +108 -0
- package/esm/ai/src/skills/sources/directory-source.mjs.map +1 -0
- package/esm/ai/src/skills/sources/index.mjs +27 -0
- package/esm/ai/src/skills/sources/index.mjs.map +1 -0
- package/esm/ai/src/skills/sources/parse-frontmatter.mjs +46 -0
- package/esm/ai/src/skills/sources/parse-frontmatter.mjs.map +1 -0
- package/esm/ai/src/skills/sources/store-source.mjs +15 -0
- package/esm/ai/src/skills/sources/store-source.mjs.map +1 -0
- package/esm/ai/src/skills/sources/url-source.mjs +117 -0
- package/esm/ai/src/skills/sources/url-source.mjs.map +1 -0
- package/esm/ai/src/snapshot/memory.mjs +81 -0
- package/esm/ai/src/snapshot/memory.mjs.map +1 -0
- package/esm/ai/src/snapshot/pg.mjs +146 -0
- package/esm/ai/src/snapshot/pg.mjs.map +1 -0
- package/esm/ai/src/snapshot/redis.mjs +101 -0
- package/esm/ai/src/snapshot/redis.mjs.map +1 -0
- package/esm/ai/src/supervisor/as-tool.mjs +74 -0
- package/esm/ai/src/supervisor/as-tool.mjs.map +1 -0
- package/esm/ai/src/supervisor/cancellation.mjs +22 -0
- package/esm/ai/src/supervisor/cancellation.mjs.map +1 -0
- package/esm/ai/src/supervisor/decide.mjs +272 -0
- package/esm/ai/src/supervisor/decide.mjs.map +1 -0
- package/esm/ai/src/supervisor/emitter.mjs +47 -0
- package/esm/ai/src/supervisor/emitter.mjs.map +1 -0
- package/esm/ai/src/supervisor/entries.mjs +206 -0
- package/esm/ai/src/supervisor/entries.mjs.map +1 -0
- package/esm/ai/src/supervisor/execution.mjs +1921 -0
- package/esm/ai/src/supervisor/execution.mjs.map +1 -0
- package/esm/ai/src/supervisor/fan-out.mjs +65 -0
- package/esm/ai/src/supervisor/fan-out.mjs.map +1 -0
- package/esm/ai/src/supervisor/index.mjs +14 -0
- package/esm/ai/src/supervisor/router-factory.mjs +141 -0
- package/esm/ai/src/supervisor/router-factory.mjs.map +1 -0
- package/esm/ai/src/supervisor/router-prompt.mjs +52 -0
- package/esm/ai/src/supervisor/router-prompt.mjs.map +1 -0
- package/esm/ai/src/supervisor/signature.mjs +89 -0
- package/esm/ai/src/supervisor/signature.mjs.map +1 -0
- package/esm/ai/src/supervisor/snapshot.mjs +69 -0
- package/esm/ai/src/supervisor/snapshot.mjs.map +1 -0
- package/esm/ai/src/supervisor/supervisor-stream.mjs +89 -0
- package/esm/ai/src/supervisor/supervisor-stream.mjs.map +1 -0
- package/esm/ai/src/supervisor/supervisor.mjs +144 -0
- package/esm/ai/src/supervisor/supervisor.mjs.map +1 -0
- package/esm/ai/src/system-prompt/index.mjs +6 -0
- package/esm/ai/src/system-prompt/instruction.mjs +57 -0
- package/esm/ai/src/system-prompt/instruction.mjs.map +1 -0
- package/esm/ai/src/system-prompt/persona.mjs +57 -0
- package/esm/ai/src/system-prompt/persona.mjs.map +1 -0
- package/esm/ai/src/system-prompt/render-placeholders.mjs +58 -0
- package/esm/ai/src/system-prompt/render-placeholders.mjs.map +1 -0
- package/esm/ai/src/system-prompt/system-prompt.mjs +267 -0
- package/esm/ai/src/system-prompt/system-prompt.mjs.map +1 -0
- package/esm/ai/src/team/gates.mjs +48 -0
- package/esm/ai/src/team/gates.mjs.map +1 -0
- package/esm/ai/src/team/index.mjs +3 -0
- package/esm/ai/src/team/team.mjs +94 -0
- package/esm/ai/src/team/team.mjs.map +1 -0
- package/esm/ai/src/tool/executable-as-tool.mjs +81 -0
- package/esm/ai/src/tool/executable-as-tool.mjs.map +1 -0
- package/esm/ai/src/tool/index.mjs +4 -0
- package/esm/ai/src/tool/tool.mjs +185 -0
- package/esm/ai/src/tool/tool.mjs.map +1 -0
- package/esm/ai/src/utils/compute-cost.mjs +112 -0
- package/esm/ai/src/utils/compute-cost.mjs.map +1 -0
- package/esm/ai/src/utils/extract-json-lenient.mjs +97 -0
- package/esm/ai/src/utils/extract-json-lenient.mjs.map +1 -0
- package/esm/ai/src/utils/extract-json-payload.mjs +39 -0
- package/esm/ai/src/utils/extract-json-payload.mjs.map +1 -0
- package/esm/ai/src/utils/generate-run-id.mjs +23 -0
- package/esm/ai/src/utils/generate-run-id.mjs.map +1 -0
- package/esm/ai/src/utils/index.mjs +12 -0
- package/esm/ai/src/utils/json-schema.mjs +89 -0
- package/esm/ai/src/utils/json-schema.mjs.map +1 -0
- package/esm/ai/src/utils/prepare-attachment-part.mjs +232 -0
- package/esm/ai/src/utils/prepare-attachment-part.mjs.map +1 -0
- package/esm/ai/src/utils/resolve-attachment.mjs +74 -0
- package/esm/ai/src/utils/resolve-attachment.mjs.map +1 -0
- package/esm/ai/src/utils/run-context.mjs +89 -0
- package/esm/ai/src/utils/run-context.mjs.map +1 -0
- package/esm/ai/src/utils/safe-json-parse.mjs +22 -0
- package/esm/ai/src/utils/safe-json-parse.mjs.map +1 -0
- package/esm/ai/src/utils/stamp-report-lineage.mjs +45 -0
- package/esm/ai/src/utils/stamp-report-lineage.mjs.map +1 -0
- package/esm/ai/src/vcr/cassette-io.mjs +57 -0
- package/esm/ai/src/vcr/cassette-io.mjs.map +1 -0
- package/esm/ai/src/vcr/errors.mjs +37 -0
- package/esm/ai/src/vcr/errors.mjs.map +1 -0
- package/esm/ai/src/vcr/hash-request.mjs +118 -0
- package/esm/ai/src/vcr/hash-request.mjs.map +1 -0
- package/esm/ai/src/vcr/index.mjs +5 -0
- package/esm/ai/src/vcr/vcr.mjs +248 -0
- package/esm/ai/src/vcr/vcr.mjs.map +1 -0
- package/esm/ai/src/workflow/as-tool.mjs +49 -0
- package/esm/ai/src/workflow/as-tool.mjs.map +1 -0
- package/esm/ai/src/workflow/cancellation.mjs +44 -0
- package/esm/ai/src/workflow/cancellation.mjs.map +1 -0
- package/esm/ai/src/workflow/emitter.mjs +40 -0
- package/esm/ai/src/workflow/emitter.mjs.map +1 -0
- package/esm/ai/src/workflow/engine.mjs +363 -0
- package/esm/ai/src/workflow/engine.mjs.map +1 -0
- package/esm/ai/src/workflow/index.mjs +5 -0
- package/esm/ai/src/workflow/retry.mjs +32 -0
- package/esm/ai/src/workflow/retry.mjs.map +1 -0
- package/esm/ai/src/workflow/router.mjs +56 -0
- package/esm/ai/src/workflow/router.mjs.map +1 -0
- package/esm/ai/src/workflow/run-scoped-emitter.mjs +32 -0
- package/esm/ai/src/workflow/run-scoped-emitter.mjs.map +1 -0
- package/esm/ai/src/workflow/signature.mjs +34 -0
- package/esm/ai/src/workflow/signature.mjs.map +1 -0
- package/esm/ai/src/workflow/snapshot.mjs +77 -0
- package/esm/ai/src/workflow/snapshot.mjs.map +1 -0
- package/esm/ai/src/workflow/state.mjs +37 -0
- package/esm/ai/src/workflow/state.mjs.map +1 -0
- package/esm/ai/src/workflow/step-runner.mjs +370 -0
- package/esm/ai/src/workflow/step-runner.mjs.map +1 -0
- package/esm/ai/src/workflow/step.mjs +37 -0
- package/esm/ai/src/workflow/step.mjs.map +1 -0
- package/esm/ai/src/workflow/workflow.mjs +122 -0
- package/esm/ai/src/workflow/workflow.mjs.map +1 -0
- package/esm/ai-openai/src/embedder.mjs +4 -0
- package/esm/ai-openai/src/index.mjs +4 -0
- package/esm/ai-openai/src/model.mjs +5 -0
- package/esm/ai-openai/src/sdk.mjs +6 -0
- package/esm/ai-openai/src/utils/index.mjs +4 -0
- package/esm/ai-openai/src/utils/to-openai-tools.mjs +3 -0
- package/esm/ai-openai/src/utils/wrap-openai-error.mjs +4 -0
- package/esm/cli/commands/dev-server.command.mjs +1 -1
- package/esm/cli/commands/dev-server.command.mjs.map +1 -1
- package/esm/cli/commands/generate/templates/stubs.mjs +3 -4
- package/esm/cli/commands/generate/templates/stubs.mjs.map +1 -1
- package/esm/connectors/ai-connector.d.mts +43 -0
- package/esm/connectors/ai-connector.d.mts.map +1 -0
- package/esm/connectors/ai-connector.mjs +56 -0
- package/esm/connectors/ai-connector.mjs.map +1 -0
- package/esm/connectors/cache-connector.d.mts +5 -0
- package/esm/connectors/cache-connector.d.mts.map +1 -1
- package/esm/connectors/cache-connector.mjs +7 -0
- package/esm/connectors/cache-connector.mjs.map +1 -1
- package/esm/connectors/connectors-manager.d.mts +6 -2
- package/esm/connectors/connectors-manager.d.mts.map +1 -1
- package/esm/connectors/connectors-manager.mjs +8 -2
- package/esm/connectors/connectors-manager.mjs.map +1 -1
- package/esm/connectors/http-connector.mjs.map +1 -1
- package/esm/connectors/index.d.mts +1 -0
- package/esm/connectors/index.mjs +1 -0
- package/esm/connectors/socket-connector.d.mts +16 -1
- package/esm/connectors/socket-connector.d.mts.map +1 -1
- package/esm/connectors/socket-connector.mjs +28 -5
- package/esm/connectors/socket-connector.mjs.map +1 -1
- package/esm/connectors/storage.connector.d.mts +7 -0
- package/esm/connectors/storage.connector.d.mts.map +1 -1
- package/esm/connectors/storage.connector.mjs +7 -0
- package/esm/connectors/storage.connector.mjs.map +1 -1
- package/esm/connectors/types.d.mts +3 -2
- package/esm/connectors/types.d.mts.map +1 -1
- package/esm/connectors/types.mjs +1 -0
- package/esm/connectors/types.mjs.map +1 -1
- package/esm/dev-server/development-server.mjs +2 -14
- package/esm/dev-server/development-server.mjs.map +1 -1
- package/esm/dev-server/file-event-handler.mjs +15 -3
- package/esm/dev-server/file-event-handler.mjs.map +1 -1
- package/esm/generations/add-command.action.mjs +61 -12
- package/esm/generations/add-command.action.mjs.map +1 -1
- package/esm/generations/stubs.mjs +31 -1
- package/esm/generations/stubs.mjs.map +1 -1
- package/esm/http/middleware/cache-response-middleware.d.mts +1 -1
- package/esm/http/middleware/cache-response-middleware.d.mts.map +1 -1
- package/esm/http/middleware/cache-response-middleware.mjs +15 -6
- package/esm/http/middleware/cache-response-middleware.mjs.map +1 -1
- package/esm/http/middleware/concurrency-limit.middleware.mjs +2 -0
- package/esm/http/middleware/concurrency-limit.middleware.mjs.map +1 -1
- package/esm/http/middleware/idempotency.middleware.d.mts.map +1 -1
- package/esm/http/middleware/idempotency.middleware.mjs +4 -1
- package/esm/http/middleware/idempotency.middleware.mjs.map +1 -1
- package/esm/http/middleware/maintenance.middleware.mjs +2 -1
- package/esm/http/middleware/maintenance.middleware.mjs.map +1 -1
- package/esm/http/request.d.mts +9 -2
- package/esm/http/request.d.mts.map +1 -1
- package/esm/http/request.mjs +15 -3
- package/esm/http/request.mjs.map +1 -1
- package/esm/http/response.d.mts +12 -0
- package/esm/http/response.d.mts.map +1 -1
- package/esm/http/response.mjs +19 -2
- package/esm/http/response.mjs.map +1 -1
- package/esm/http/server.d.mts.map +1 -1
- package/esm/http/server.mjs +1 -1
- package/esm/http/server.mjs.map +1 -1
- package/esm/index.d.mts +6 -2
- package/esm/index.mjs +5 -1
- package/esm/node_modules/langfuse/lib/index.mjs +1827 -0
- package/esm/node_modules/langfuse/lib/index.mjs.map +1 -0
- package/esm/node_modules/langfuse-core/lib/index.mjs +1770 -0
- package/esm/node_modules/langfuse-core/lib/index.mjs.map +1 -0
- package/esm/node_modules/mustache/mustache.mjs +587 -0
- package/esm/node_modules/mustache/mustache.mjs.map +1 -0
- package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs +180 -0
- package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs.map +1 -0
- package/esm/node_modules/openai/auth/workload-identity-auth.mjs +80 -0
- package/esm/node_modules/openai/auth/workload-identity-auth.mjs.map +1 -0
- package/esm/node_modules/openai/azure.mjs +82 -0
- package/esm/node_modules/openai/azure.mjs.map +1 -0
- package/esm/node_modules/openai/client.mjs +638 -0
- package/esm/node_modules/openai/client.mjs.map +1 -0
- package/esm/node_modules/openai/core/api-promise.mjs +75 -0
- package/esm/node_modules/openai/core/api-promise.mjs.map +1 -0
- package/esm/node_modules/openai/core/error.mjs +110 -0
- package/esm/node_modules/openai/core/error.mjs.map +1 -0
- package/esm/node_modules/openai/core/pagination.mjs +160 -0
- package/esm/node_modules/openai/core/pagination.mjs.map +1 -0
- package/esm/node_modules/openai/core/resource.mjs +10 -0
- package/esm/node_modules/openai/core/resource.mjs.map +1 -0
- package/esm/node_modules/openai/core/streaming.mjs +238 -0
- package/esm/node_modules/openai/core/streaming.mjs.map +1 -0
- package/esm/node_modules/openai/index.mjs +8 -0
- package/esm/node_modules/openai/internal/decoders/line.mjs +91 -0
- package/esm/node_modules/openai/internal/decoders/line.mjs.map +1 -0
- package/esm/node_modules/openai/internal/detect-platform.mjs +123 -0
- package/esm/node_modules/openai/internal/detect-platform.mjs.map +1 -0
- package/esm/node_modules/openai/internal/errors.mjs +26 -0
- package/esm/node_modules/openai/internal/errors.mjs.map +1 -0
- package/esm/node_modules/openai/internal/headers.mjs +65 -0
- package/esm/node_modules/openai/internal/headers.mjs.map +1 -0
- package/esm/node_modules/openai/internal/parse.mjs +41 -0
- package/esm/node_modules/openai/internal/parse.mjs.map +1 -0
- package/esm/node_modules/openai/internal/qs/formats.mjs +12 -0
- package/esm/node_modules/openai/internal/qs/formats.mjs.map +1 -0
- package/esm/node_modules/openai/internal/qs/stringify.mjs +179 -0
- package/esm/node_modules/openai/internal/qs/stringify.mjs.map +1 -0
- package/esm/node_modules/openai/internal/qs/utils.mjs +65 -0
- package/esm/node_modules/openai/internal/qs/utils.mjs.map +1 -0
- package/esm/node_modules/openai/internal/request-options.mjs +11 -0
- package/esm/node_modules/openai/internal/request-options.mjs.map +1 -0
- package/esm/node_modules/openai/internal/shims.mjs +77 -0
- package/esm/node_modules/openai/internal/shims.mjs.map +1 -0
- package/esm/node_modules/openai/internal/to-file.mjs +63 -0
- package/esm/node_modules/openai/internal/to-file.mjs.map +1 -0
- package/esm/node_modules/openai/internal/tslib.mjs +16 -0
- package/esm/node_modules/openai/internal/tslib.mjs.map +1 -0
- package/esm/node_modules/openai/internal/uploads.mjs +94 -0
- package/esm/node_modules/openai/internal/uploads.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/base64.mjs +22 -0
- package/esm/node_modules/openai/internal/utils/base64.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/bytes.mjs +26 -0
- package/esm/node_modules/openai/internal/utils/bytes.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/env.mjs +16 -0
- package/esm/node_modules/openai/internal/utils/env.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/log.mjs +58 -0
- package/esm/node_modules/openai/internal/utils/log.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/path.mjs +62 -0
- package/esm/node_modules/openai/internal/utils/path.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/query.mjs +10 -0
- package/esm/node_modules/openai/internal/utils/query.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/sleep.mjs +6 -0
- package/esm/node_modules/openai/internal/utils/sleep.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/uuid.mjs +18 -0
- package/esm/node_modules/openai/internal/utils/uuid.mjs.map +1 -0
- package/esm/node_modules/openai/internal/utils/values.mjs +41 -0
- package/esm/node_modules/openai/internal/utils/values.mjs.map +1 -0
- package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +247 -0
- package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs.map +1 -0
- package/esm/node_modules/openai/lib/AssistantStream.mjs +472 -0
- package/esm/node_modules/openai/lib/AssistantStream.mjs.map +1 -0
- package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs +26 -0
- package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs.map +1 -0
- package/esm/node_modules/openai/lib/ChatCompletionStream.mjs +423 -0
- package/esm/node_modules/openai/lib/ChatCompletionStream.mjs.map +1 -0
- package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +26 -0
- package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs.map +1 -0
- package/esm/node_modules/openai/lib/EventStream.mjs +163 -0
- package/esm/node_modules/openai/lib/EventStream.mjs.map +1 -0
- package/esm/node_modules/openai/lib/ResponsesParser.mjs +94 -0
- package/esm/node_modules/openai/lib/ResponsesParser.mjs.map +1 -0
- package/esm/node_modules/openai/lib/RunnableFunction.mjs +8 -0
- package/esm/node_modules/openai/lib/RunnableFunction.mjs.map +1 -0
- package/esm/node_modules/openai/lib/Util.mjs +19 -0
- package/esm/node_modules/openai/lib/Util.mjs.map +1 -0
- package/esm/node_modules/openai/lib/chatCompletionUtils.mjs +11 -0
- package/esm/node_modules/openai/lib/chatCompletionUtils.mjs.map +1 -0
- package/esm/node_modules/openai/lib/parser.mjs +88 -0
- package/esm/node_modules/openai/lib/parser.mjs.map +1 -0
- package/esm/node_modules/openai/lib/responses/ResponseStream.mjs +231 -0
- package/esm/node_modules/openai/lib/responses/ResponseStream.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/admin.mjs +15 -0
- package/esm/node_modules/openai/resources/admin/admin.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +81 -0
- package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs +31 -0
- package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/certificates.mjs +153 -0
- package/esm/node_modules/openai/resources/admin/organization/certificates.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs +42 -0
- package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs +106 -0
- package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs +88 -0
- package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs +88 -0
- package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/invites.mjs +83 -0
- package/esm/node_modules/openai/resources/admin/organization/invites.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/organization.mjs +45 -0
- package/esm/node_modules/openai/resources/admin/organization/organization.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +72 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs +78 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +46 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +95 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +91 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +45 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +63 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs +137 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +51 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs +108 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +112 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +106 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +91 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs +118 -0
- package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/roles.mjs +96 -0
- package/esm/node_modules/openai/resources/admin/organization/roles.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs +97 -0
- package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/usage.mjs +207 -0
- package/esm/node_modules/openai/resources/admin/organization/usage.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs +88 -0
- package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs.map +1 -0
- package/esm/node_modules/openai/resources/admin/organization/users/users.mjs +82 -0
- package/esm/node_modules/openai/resources/admin/organization/users/users.mjs.map +1 -0
- package/esm/node_modules/openai/resources/audio/audio.mjs +21 -0
- package/esm/node_modules/openai/resources/audio/audio.mjs.map +1 -0
- package/esm/node_modules/openai/resources/audio/speech.mjs +39 -0
- package/esm/node_modules/openai/resources/audio/speech.mjs.map +1 -0
- package/esm/node_modules/openai/resources/audio/transcriptions.mjs +22 -0
- package/esm/node_modules/openai/resources/audio/transcriptions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/audio/translations.mjs +21 -0
- package/esm/node_modules/openai/resources/audio/translations.mjs.map +1 -0
- package/esm/node_modules/openai/resources/batches.mjs +54 -0
- package/esm/node_modules/openai/resources/batches.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/assistants.mjs +78 -0
- package/esm/node_modules/openai/resources/beta/assistants.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/beta.mjs +24 -0
- package/esm/node_modules/openai/resources/beta/beta.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs +18 -0
- package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs +49 -0
- package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs +85 -0
- package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs +21 -0
- package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs +33 -0
- package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +33 -0
- package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/threads/messages.mjs +83 -0
- package/esm/node_modules/openai/resources/beta/threads/messages.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs +183 -0
- package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs +45 -0
- package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs.map +1 -0
- package/esm/node_modules/openai/resources/beta/threads/threads.mjs +101 -0
- package/esm/node_modules/openai/resources/beta/threads/threads.mjs.map +1 -0
- package/esm/node_modules/openai/resources/chat/chat.mjs +15 -0
- package/esm/node_modules/openai/resources/chat/chat.mjs.map +1 -0
- package/esm/node_modules/openai/resources/chat/completions/completions.mjs +123 -0
- package/esm/node_modules/openai/resources/chat/completions/completions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/chat/completions/index.mjs +7 -0
- package/esm/node_modules/openai/resources/chat/completions/messages.mjs +35 -0
- package/esm/node_modules/openai/resources/chat/completions/messages.mjs.map +1 -0
- package/esm/node_modules/openai/resources/chat/index.mjs +5 -0
- package/esm/node_modules/openai/resources/completions.mjs +20 -0
- package/esm/node_modules/openai/resources/completions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/containers/containers.mjs +57 -0
- package/esm/node_modules/openai/resources/containers/containers.mjs.map +1 -0
- package/esm/node_modules/openai/resources/containers/files/content.mjs +23 -0
- package/esm/node_modules/openai/resources/containers/files/content.mjs.map +1 -0
- package/esm/node_modules/openai/resources/containers/files/files.mjs +63 -0
- package/esm/node_modules/openai/resources/containers/files/files.mjs.map +1 -0
- package/esm/node_modules/openai/resources/conversations/conversations.mjs +57 -0
- package/esm/node_modules/openai/resources/conversations/conversations.mjs.map +1 -0
- package/esm/node_modules/openai/resources/conversations/items.mjs +57 -0
- package/esm/node_modules/openai/resources/conversations/items.mjs.map +1 -0
- package/esm/node_modules/openai/resources/embeddings.mjs +48 -0
- package/esm/node_modules/openai/resources/embeddings.mjs.map +1 -0
- package/esm/node_modules/openai/resources/evals/evals.mjs +73 -0
- package/esm/node_modules/openai/resources/evals/evals.mjs.map +1 -0
- package/esm/node_modules/openai/resources/evals/runs/output-items.mjs +35 -0
- package/esm/node_modules/openai/resources/evals/runs/output-items.mjs.map +1 -0
- package/esm/node_modules/openai/resources/evals/runs/runs.mjs +72 -0
- package/esm/node_modules/openai/resources/evals/runs/runs.mjs.map +1 -0
- package/esm/node_modules/openai/resources/files.mjs +111 -0
- package/esm/node_modules/openai/resources/files.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +15 -0
- package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +60 -0
- package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +15 -0
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +102 -0
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +24 -0
- package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +34 -0
- package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +148 -0
- package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs.map +1 -0
- package/esm/node_modules/openai/resources/fine-tuning/methods.mjs +8 -0
- package/esm/node_modules/openai/resources/fine-tuning/methods.mjs.map +1 -0
- package/esm/node_modules/openai/resources/graders/grader-models.mjs +8 -0
- package/esm/node_modules/openai/resources/graders/grader-models.mjs.map +1 -0
- package/esm/node_modules/openai/resources/graders/graders.mjs +15 -0
- package/esm/node_modules/openai/resources/graders/graders.mjs.map +1 -0
- package/esm/node_modules/openai/resources/images.mjs +46 -0
- package/esm/node_modules/openai/resources/images.mjs.map +1 -0
- package/esm/node_modules/openai/resources/index.mjs +27 -0
- package/esm/node_modules/openai/resources/models.mjs +44 -0
- package/esm/node_modules/openai/resources/models.mjs.map +1 -0
- package/esm/node_modules/openai/resources/moderations.mjs +23 -0
- package/esm/node_modules/openai/resources/moderations.mjs.map +1 -0
- package/esm/node_modules/openai/resources/realtime/calls.mjs +79 -0
- package/esm/node_modules/openai/resources/realtime/calls.mjs.map +1 -0
- package/esm/node_modules/openai/resources/realtime/client-secrets.mjs +39 -0
- package/esm/node_modules/openai/resources/realtime/client-secrets.mjs.map +1 -0
- package/esm/node_modules/openai/resources/realtime/realtime.mjs +18 -0
- package/esm/node_modules/openai/resources/realtime/realtime.mjs.map +1 -0
- package/esm/node_modules/openai/resources/responses/input-items.mjs +31 -0
- package/esm/node_modules/openai/resources/responses/input-items.mjs.map +1 -0
- package/esm/node_modules/openai/resources/responses/input-tokens.mjs +27 -0
- package/esm/node_modules/openai/resources/responses/input-tokens.mjs.map +1 -0
- package/esm/node_modules/openai/resources/responses/responses.mjs +110 -0
- package/esm/node_modules/openai/resources/responses/responses.mjs.map +1 -0
- package/esm/node_modules/openai/resources/skills/content.mjs +22 -0
- package/esm/node_modules/openai/resources/skills/content.mjs.map +1 -0
- package/esm/node_modules/openai/resources/skills/skills.mjs +69 -0
- package/esm/node_modules/openai/resources/skills/skills.mjs.map +1 -0
- package/esm/node_modules/openai/resources/skills/versions/content.mjs +23 -0
- package/esm/node_modules/openai/resources/skills/versions/content.mjs.map +1 -0
- package/esm/node_modules/openai/resources/skills/versions/versions.mjs +58 -0
- package/esm/node_modules/openai/resources/skills/versions/versions.mjs.map +1 -0
- package/esm/node_modules/openai/resources/uploads/parts.mjs +34 -0
- package/esm/node_modules/openai/resources/uploads/parts.mjs.map +1 -0
- package/esm/node_modules/openai/resources/uploads/uploads.mjs +84 -0
- package/esm/node_modules/openai/resources/uploads/uploads.mjs.map +1 -0
- package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs +126 -0
- package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs.map +1 -0
- package/esm/node_modules/openai/resources/vector-stores/files.mjs +147 -0
- package/esm/node_modules/openai/resources/vector-stores/files.mjs.map +1 -0
- package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs +87 -0
- package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs.map +1 -0
- package/esm/node_modules/openai/resources/videos.mjs +115 -0
- package/esm/node_modules/openai/resources/videos.mjs.map +1 -0
- package/esm/node_modules/openai/resources/webhooks/index.mjs +3 -0
- package/esm/node_modules/openai/resources/webhooks/webhooks.mjs +69 -0
- package/esm/node_modules/openai/resources/webhooks/webhooks.mjs.map +1 -0
- package/esm/node_modules/openai/resources/webhooks.mjs +4 -0
- package/esm/node_modules/openai/streaming.mjs +3 -0
- package/esm/node_modules/openai/version.mjs +6 -0
- package/esm/node_modules/openai/version.mjs.map +1 -0
- package/esm/repositories/adapters/cascade/cascade-query-builder.d.mts +9 -0
- package/esm/repositories/adapters/cascade/cascade-query-builder.d.mts.map +1 -1
- package/esm/repositories/adapters/cascade/cascade-query-builder.mjs +32 -5
- package/esm/repositories/adapters/cascade/cascade-query-builder.mjs.map +1 -1
- package/esm/repositories/adapters/cascade/filter-applicator.mjs +17 -3
- package/esm/repositories/adapters/cascade/filter-applicator.mjs.map +1 -1
- package/esm/repositories/repository.manager.d.mts +11 -1
- package/esm/repositories/repository.manager.d.mts.map +1 -1
- package/esm/repositories/repository.manager.mjs +79 -25
- package/esm/repositories/repository.manager.mjs.map +1 -1
- package/esm/router/route-registry.mjs +19 -10
- package/esm/router/route-registry.mjs.map +1 -1
- package/esm/router/router.d.mts.map +1 -1
- package/esm/router/router.mjs +7 -4
- package/esm/router/router.mjs.map +1 -1
- package/esm/storage/drivers/cloud-driver.d.mts.map +1 -1
- package/esm/storage/drivers/cloud-driver.mjs +48 -12
- package/esm/storage/drivers/cloud-driver.mjs.map +1 -1
- package/esm/storage/drivers/do-spaces-driver.mjs +1 -1
- package/esm/storage/drivers/do-spaces-driver.mjs.map +1 -1
- package/esm/storage/drivers/local-driver.d.mts +8 -0
- package/esm/storage/drivers/local-driver.d.mts.map +1 -1
- package/esm/storage/drivers/local-driver.mjs +19 -4
- package/esm/storage/drivers/local-driver.mjs.map +1 -1
- package/esm/storage/drivers/r2-driver.mjs +1 -1
- package/esm/storage/drivers/r2-driver.mjs.map +1 -1
- package/esm/storage/drivers/s3-driver.mjs +1 -1
- package/esm/storage/drivers/s3-driver.mjs.map +1 -1
- package/esm/storage/index.d.mts +4 -1
- package/esm/storage/index.mjs +3 -0
- package/esm/storage/scoped-storage.d.mts +8 -4
- package/esm/storage/scoped-storage.d.mts.map +1 -1
- package/esm/storage/scoped-storage.mjs +21 -6
- package/esm/storage/scoped-storage.mjs.map +1 -1
- package/esm/storage/storage.d.mts +12 -4
- package/esm/storage/storage.d.mts.map +1 -1
- package/esm/storage/storage.mjs +23 -9
- package/esm/storage/storage.mjs.map +1 -1
- package/esm/storage/types.d.mts +33 -5
- package/esm/storage/types.d.mts.map +1 -1
- package/esm/storage/utils/contain-path.d.mts +23 -0
- package/esm/storage/utils/contain-path.d.mts.map +1 -0
- package/esm/storage/utils/contain-path.mjs +35 -0
- package/esm/storage/utils/contain-path.mjs.map +1 -0
- package/esm/storage/utils/safe-fetch.d.mts +68 -0
- package/esm/storage/utils/safe-fetch.d.mts.map +1 -0
- package/esm/storage/utils/safe-fetch.mjs +205 -0
- package/esm/storage/utils/safe-fetch.mjs.map +1 -0
- package/esm/storage/utils/storage-error.d.mts +35 -0
- package/esm/storage/utils/storage-error.d.mts.map +1 -0
- package/esm/storage/utils/storage-error.mjs +17 -0
- package/esm/storage/utils/storage-error.mjs.map +1 -0
- package/esm/use-cases/use-case-pipeline.mjs +4 -1
- package/esm/use-cases/use-case-pipeline.mjs.map +1 -1
- package/esm/use-cases/use-case.mjs +12 -4
- package/esm/use-cases/use-case.mjs.map +1 -1
- package/esm/use-cases/use-cases-registry.d.mts +12 -4
- package/esm/use-cases/use-cases-registry.d.mts.map +1 -1
- package/esm/use-cases/use-cases-registry.mjs +13 -3
- package/esm/use-cases/use-cases-registry.mjs.map +1 -1
- package/esm/utils/npm-registry.d.mts +1 -1
- package/esm/utils/npm-registry.mjs +2 -2
- package/esm/utils/npm-registry.mjs.map +1 -1
- package/llms-full.txt +29 -1
- package/package.json +9 -9
- package/skills/add-connector/SKILL.md +6 -1
- package/skills/configure-app/SKILL.md +23 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/utils/stamp-report-lineage.ts
|
|
2
|
+
/**
|
|
3
|
+
* Walk a freshly-built report tree and stamp lineage fields onto
|
|
4
|
+
* every node:
|
|
5
|
+
*
|
|
6
|
+
* - `rootRunId` — rewritten to `stamp.rootRunId` everywhere. Composite
|
|
7
|
+
* children built by inner primitives carry their own self-root; this
|
|
8
|
+
* walk overrides it so the outer root wins (single coherent run id
|
|
9
|
+
* across the whole tree).
|
|
10
|
+
* - `parentRunId` — root node gets `stamp.parentRunId`; descendants
|
|
11
|
+
* derive theirs from each parent's own `runId`.
|
|
12
|
+
* - `sessionId` — propagated when provided.
|
|
13
|
+
* - `reportSchemaVersion` — stamped only on the root (the value is the
|
|
14
|
+
* same for the whole tree; storing it on every node would waste
|
|
15
|
+
* space).
|
|
16
|
+
*
|
|
17
|
+
* Designed to run ONCE per top-level `buildResult` call. Each
|
|
18
|
+
* primitive's executor invokes this on the assembled root report just
|
|
19
|
+
* before returning; nested primitives produced their own subtree with
|
|
20
|
+
* a self-root, and this pass relinks everything to the outer caller's
|
|
21
|
+
* lineage.
|
|
22
|
+
*
|
|
23
|
+
* Mutates the report in place — internal use only, before the report
|
|
24
|
+
* is exposed via `result.report`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const root = this.buildBareReport();
|
|
28
|
+
* stampReportLineage(root, { rootRunId: this.runId, sessionId: this.options?.sessionId });
|
|
29
|
+
* return { ..., report: root };
|
|
30
|
+
*/
|
|
31
|
+
function stampReportLineage(root, stamp) {
|
|
32
|
+
root.reportSchemaVersion = 1;
|
|
33
|
+
walk(root, stamp.rootRunId, stamp.parentRunId, stamp.sessionId);
|
|
34
|
+
}
|
|
35
|
+
function walk(node, rootRunId, parentRunId, sessionId) {
|
|
36
|
+
node.rootRunId = rootRunId;
|
|
37
|
+
if (parentRunId !== void 0) node.parentRunId = parentRunId;
|
|
38
|
+
else delete node.parentRunId;
|
|
39
|
+
if (sessionId !== void 0) node.sessionId = sessionId;
|
|
40
|
+
for (const child of node.children) walk(child, rootRunId, node.runId, sessionId);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { stampReportLineage };
|
|
45
|
+
//# sourceMappingURL=stamp-report-lineage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stamp-report-lineage.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/utils/stamp-report-lineage.ts"],"sourcesContent":["import type { BaseReport } from \"../contracts/result/base-report.type\";\nimport { REPORT_SCHEMA_VERSION } from \"../contracts/result/base-report.type\";\n\n/**\n * Options for {@link stampReportLineage}. Every field is optional —\n * the caller supplies whichever pieces it knows. Missing pieces are\n * left untouched (existing values on the report survive).\n */\nexport type LineageStamp = {\n /**\n * The outermost run-id this subtree belongs to. When set, EVERY\n * node in the subtree gets its `rootRunId` rewritten to this\n * value — overrides any inner self-roots produced by nested\n * `buildResult` calls.\n */\n rootRunId: string;\n /**\n * Run-id of the immediate parent of THIS subtree's top node. Each\n * descendant's `parentRunId` is then derived from its own walk\n * position (its parent's `runId`).\n */\n parentRunId?: string;\n /**\n * Caller-supplied session identifier — propagates to every node in\n * the subtree. Skipped when undefined.\n */\n sessionId?: string;\n};\n\n/**\n * Walk a freshly-built report tree and stamp lineage fields onto\n * every node:\n *\n * - `rootRunId` — rewritten to `stamp.rootRunId` everywhere. Composite\n * children built by inner primitives carry their own self-root; this\n * walk overrides it so the outer root wins (single coherent run id\n * across the whole tree).\n * - `parentRunId` — root node gets `stamp.parentRunId`; descendants\n * derive theirs from each parent's own `runId`.\n * - `sessionId` — propagated when provided.\n * - `reportSchemaVersion` — stamped only on the root (the value is the\n * same for the whole tree; storing it on every node would waste\n * space).\n *\n * Designed to run ONCE per top-level `buildResult` call. Each\n * primitive's executor invokes this on the assembled root report just\n * before returning; nested primitives produced their own subtree with\n * a self-root, and this pass relinks everything to the outer caller's\n * lineage.\n *\n * Mutates the report in place — internal use only, before the report\n * is exposed via `result.report`.\n *\n * @example\n * const root = this.buildBareReport();\n * stampReportLineage(root, { rootRunId: this.runId, sessionId: this.options?.sessionId });\n * return { ..., report: root };\n */\nexport function stampReportLineage(root: BaseReport, stamp: LineageStamp): void {\n root.reportSchemaVersion = REPORT_SCHEMA_VERSION;\n\n walk(root, stamp.rootRunId, stamp.parentRunId, stamp.sessionId);\n}\n\nfunction walk(node: BaseReport, rootRunId: string, parentRunId?: string, sessionId?: string): void {\n node.rootRunId = rootRunId;\n\n if (parentRunId !== undefined) {\n node.parentRunId = parentRunId;\n } else {\n delete node.parentRunId;\n }\n\n if (sessionId !== undefined) {\n node.sessionId = sessionId;\n }\n\n for (const child of node.children) {\n walk(child, rootRunId, node.runId, sessionId);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,SAAgB,mBAAmB,MAAkB,OAA2B;CAC9E,KAAK;CAEL,KAAK,MAAM,MAAM,WAAW,MAAM,aAAa,MAAM,SAAS;AAChE;AAEA,SAAS,KAAK,MAAkB,WAAmB,aAAsB,WAA0B;CACjG,KAAK,YAAY;CAEjB,IAAI,gBAAgB,QAClB,KAAK,cAAc;MAEnB,OAAO,KAAK;CAGd,IAAI,cAAc,QAChB,KAAK,YAAY;CAGnB,KAAK,MAAM,SAAS,KAAK,UACvB,KAAK,OAAO,WAAW,KAAK,OAAO,SAAS;AAEhD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/vcr/cassette-io.ts
|
|
2
|
+
let fsModule;
|
|
3
|
+
/**
|
|
4
|
+
* Resolve `node:fs/promises` once and memoize it.
|
|
5
|
+
*/
|
|
6
|
+
async function loadFs() {
|
|
7
|
+
if (!fsModule) fsModule = await import("node:fs/promises");
|
|
8
|
+
return fsModule;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Build a fresh, empty cassette for a model identity. Used when the path
|
|
12
|
+
* does not exist yet (first record run).
|
|
13
|
+
*/
|
|
14
|
+
function emptyCassette(model, provider) {
|
|
15
|
+
return {
|
|
16
|
+
version: 1,
|
|
17
|
+
model,
|
|
18
|
+
provider,
|
|
19
|
+
entries: []
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Load a cassette from disk. Returns a fresh empty cassette (not an error)
|
|
24
|
+
* when the file does not exist — the common first-record case. Any other I/O
|
|
25
|
+
* or parse failure rejects so corruption is never silently swallowed.
|
|
26
|
+
*/
|
|
27
|
+
async function loadCassette(path, model, provider) {
|
|
28
|
+
const fs = await loadFs();
|
|
29
|
+
let raw;
|
|
30
|
+
try {
|
|
31
|
+
raw = await fs.readFile(path, "utf8");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error.code === "ENOENT") return emptyCassette(model, provider);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
const parsed = JSON.parse(raw);
|
|
37
|
+
return {
|
|
38
|
+
version: 1,
|
|
39
|
+
model: parsed.model ?? model,
|
|
40
|
+
provider: parsed.provider ?? provider,
|
|
41
|
+
entries: Array.isArray(parsed.entries) ? parsed.entries : []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Write a cassette to disk as pretty-printed JSON, creating the parent
|
|
46
|
+
* directory if needed so a brand-new `./cassettes/foo.json` path just works.
|
|
47
|
+
*/
|
|
48
|
+
async function saveCassette(path, cassette) {
|
|
49
|
+
const fs = await loadFs();
|
|
50
|
+
const dir = (await import("node:path")).dirname(path);
|
|
51
|
+
if (dir && dir !== "." && dir !== path) await fs.mkdir(dir, { recursive: true });
|
|
52
|
+
await fs.writeFile(path, JSON.stringify(cassette, void 0, 2), "utf8");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
export { emptyCassette, loadCassette, saveCassette };
|
|
57
|
+
//# sourceMappingURL=cassette-io.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cassette-io.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/vcr/cassette-io.ts"],"sourcesContent":["import type { Cassette } from \"./vcr.type\";\n\n/**\n * Lazily-resolved `node:fs/promises` module. VCR cassette I/O only touches\n * disk on construct (load) and on `save()` — keeping the import lazy means\n * importing the `vcr` factory never eagerly pulls `node:fs`, which keeps the\n * surface usable in non-node bundles that never call a disk path.\n */\ntype FsPromises = typeof import(\"node:fs/promises\");\n\nlet fsModule: FsPromises | undefined;\n\n/**\n * Resolve `node:fs/promises` once and memoize it.\n */\nasync function loadFs(): Promise<FsPromises> {\n if (!fsModule) {\n fsModule = await import(\"node:fs/promises\");\n }\n\n return fsModule;\n}\n\n/**\n * Build a fresh, empty cassette for a model identity. Used when the path\n * does not exist yet (first record run).\n */\nexport function emptyCassette(model: string, provider: string): Cassette {\n return {\n version: 1,\n model,\n provider,\n entries: [],\n };\n}\n\n/**\n * Load a cassette from disk. Returns a fresh empty cassette (not an error)\n * when the file does not exist — the common first-record case. Any other I/O\n * or parse failure rejects so corruption is never silently swallowed.\n */\nexport async function loadCassette(\n path: string,\n model: string,\n provider: string,\n): Promise<Cassette> {\n const fs = await loadFs();\n\n let raw: string;\n\n try {\n raw = await fs.readFile(path, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return emptyCassette(model, provider);\n }\n\n throw error;\n }\n\n const parsed = JSON.parse(raw) as Cassette;\n\n return {\n version: 1,\n model: parsed.model ?? model,\n provider: parsed.provider ?? provider,\n entries: Array.isArray(parsed.entries) ? parsed.entries : [],\n };\n}\n\n/**\n * Write a cassette to disk as pretty-printed JSON, creating the parent\n * directory if needed so a brand-new `./cassettes/foo.json` path just works.\n */\nexport async function saveCassette(path: string, cassette: Cassette): Promise<void> {\n const fs = await loadFs();\n const nodePath = await import(\"node:path\");\n const dir = nodePath.dirname(path);\n\n if (dir && dir !== \".\" && dir !== path) {\n await fs.mkdir(dir, { recursive: true });\n }\n\n await fs.writeFile(path, JSON.stringify(cassette, undefined, 2), \"utf8\");\n}\n"],"mappings":";AAUA,IAAI;;;;AAKJ,eAAe,SAA8B;CAC3C,IAAI,CAAC,UACH,WAAW,MAAM,OAAO;CAG1B,OAAO;AACT;;;;;AAMA,SAAgB,cAAc,OAAe,UAA4B;CACvE,OAAO;EACL,SAAS;EACT;EACA;EACA,SAAS,CAAC;CACZ;AACF;;;;;;AAOA,eAAsB,aACpB,MACA,OACA,UACmB;CACnB,MAAM,KAAK,MAAM,OAAO;CAExB,IAAI;CAEJ,IAAI;EACF,MAAM,MAAM,GAAG,SAAS,MAAM,MAAM;CACtC,SAAS,OAAO;EACd,IAAK,MAAgC,SAAS,UAC5C,OAAO,cAAc,OAAO,QAAQ;EAGtC,MAAM;CACR;CAEA,MAAM,SAAS,KAAK,MAAM,GAAG;CAE7B,OAAO;EACL,SAAS;EACT,OAAO,OAAO,SAAS;EACvB,UAAU,OAAO,YAAY;EAC7B,SAAS,MAAM,QAAQ,OAAO,OAAO,IAAI,OAAO,UAAU,CAAC;CAC7D;AACF;;;;;AAMA,eAAsB,aAAa,MAAc,UAAmC;CAClF,MAAM,KAAK,MAAM,OAAO;CAExB,MAAM,OAAM,MADW,OAAO,aACV,CAAC,QAAQ,IAAI;CAEjC,IAAI,OAAO,QAAQ,OAAO,QAAQ,MAChC,MAAM,GAAG,MAAM,KAAK,EAAE,WAAW,KAAK,CAAC;CAGzC,MAAM,GAAG,UAAU,MAAM,KAAK,UAAU,UAAU,QAAW,CAAC,GAAG,MAAM;AACzE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AIError } from "../errors/ai-error.mjs";
|
|
2
|
+
|
|
3
|
+
//#region ../@warlock.js/ai/src/vcr/errors.ts
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a `vcr(model, { mode: "replay" })` call finds no cassette
|
|
6
|
+
* entry matching the request hash.
|
|
7
|
+
*
|
|
8
|
+
* **The whole point of deterministic tests.** VCR in `replay` mode never
|
|
9
|
+
* falls back to a live provider call on a miss — that would silently
|
|
10
|
+
* re-introduce network/non-determinism into a test that asked for the
|
|
11
|
+
* opposite. Instead it throws this error so the run fails loud, telling
|
|
12
|
+
* the developer to re-record the cassette (run once in `record`/`auto`).
|
|
13
|
+
*
|
|
14
|
+
* Extends {@link AIError} directly (not `ProviderError`) — a cassette miss
|
|
15
|
+
* is a harness/config failure, not a provider failure.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* try {
|
|
19
|
+
* await vcrModel.complete(messages);
|
|
20
|
+
* } catch (error) {
|
|
21
|
+
* if (error instanceof VcrCassetteMissError) {
|
|
22
|
+
* console.error("Re-record the cassette:", error.path);
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
*/
|
|
26
|
+
var VcrCassetteMissError = class extends AIError {
|
|
27
|
+
constructor(message, options) {
|
|
28
|
+
super("VCR_CASSETTE_MISS", message, options);
|
|
29
|
+
this.name = "VcrCassetteMissError";
|
|
30
|
+
this.requestHash = options?.requestHash;
|
|
31
|
+
this.path = options?.path;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { VcrCassetteMissError };
|
|
37
|
+
//# sourceMappingURL=errors.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/vcr/errors.ts"],"sourcesContent":["import { AIError } from \"../errors/ai-error\";\nimport type { AIErrorOptions } from \"../errors/ai-error\";\n\n/**\n * Payload for {@link VcrCassetteMissError}. Carries the looked-up request\n * hash and the cassette path so a failing CI run names exactly which call\n * was not recorded.\n */\nexport type VcrCassetteMissErrorOptions = AIErrorOptions & {\n /** The normalized request hash that found no matching cassette entry. */\n requestHash?: string;\n /** Cassette file path the lookup ran against. */\n path?: string;\n};\n\n/**\n * Thrown when a `vcr(model, { mode: \"replay\" })` call finds no cassette\n * entry matching the request hash.\n *\n * **The whole point of deterministic tests.** VCR in `replay` mode never\n * falls back to a live provider call on a miss — that would silently\n * re-introduce network/non-determinism into a test that asked for the\n * opposite. Instead it throws this error so the run fails loud, telling\n * the developer to re-record the cassette (run once in `record`/`auto`).\n *\n * Extends {@link AIError} directly (not `ProviderError`) — a cassette miss\n * is a harness/config failure, not a provider failure.\n *\n * @example\n * try {\n * await vcrModel.complete(messages);\n * } catch (error) {\n * if (error instanceof VcrCassetteMissError) {\n * console.error(\"Re-record the cassette:\", error.path);\n * }\n * }\n */\nexport class VcrCassetteMissError extends AIError {\n public readonly requestHash?: string;\n public readonly path?: string;\n\n public constructor(message: string, options?: VcrCassetteMissErrorOptions) {\n super(\"VCR_CASSETTE_MISS\", message, options);\n this.name = \"VcrCassetteMissError\";\n this.requestHash = options?.requestHash;\n this.path = options?.path;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAqCA,IAAa,uBAAb,cAA0C,QAAQ;CAIhD,AAAO,YAAY,SAAiB,SAAuC;EACzE,MAAM,qBAAqB,SAAS,OAAO;EAC3C,KAAK,OAAO;EACZ,KAAK,cAAc,SAAS;EAC5B,KAAK,OAAO,SAAS;CACvB;AACF"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
//#region ../@warlock.js/ai/src/vcr/hash-request.ts
|
|
2
|
+
/**
|
|
3
|
+
* Default `ModelCallOptions` fields folded into the request hash. These are
|
|
4
|
+
* the inputs that materially change the model's output; everything else
|
|
5
|
+
* (notably `signal` and unknown provider keys) is excluded so an otherwise
|
|
6
|
+
* identical logical call still matches its recording.
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_HASH_OPTIONS = [
|
|
9
|
+
"temperature",
|
|
10
|
+
"maxTokens",
|
|
11
|
+
"responseSchema",
|
|
12
|
+
"tools",
|
|
13
|
+
"reasoning"
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Reduce a tool to the parts the model actually conditions on: its name,
|
|
17
|
+
* description, and the *shape* of its input schema. Two tools that differ
|
|
18
|
+
* only by object identity (a fresh schema instance per import) hash
|
|
19
|
+
* identically; a real contract change (renamed field, new description)
|
|
20
|
+
* invalidates the recording.
|
|
21
|
+
*
|
|
22
|
+
* The input schema is fingerprinted structurally — a Standard Schema is an
|
|
23
|
+
* opaque object, so we serialize its enumerable own keys rather than
|
|
24
|
+
* attempting to read its internals.
|
|
25
|
+
*/
|
|
26
|
+
function fingerprintTool(tool) {
|
|
27
|
+
return {
|
|
28
|
+
name: tool.name,
|
|
29
|
+
description: tool.description,
|
|
30
|
+
input: tool.input ? schemaShape(tool.input) : void 0
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Produce a stable, JSON-safe fingerprint of an arbitrary schema object.
|
|
35
|
+
* Records only the structural skeleton (own enumerable keys, recursively)
|
|
36
|
+
* so harmless instance differences don't perturb the hash while a genuine
|
|
37
|
+
* structural change does.
|
|
38
|
+
*/
|
|
39
|
+
function schemaShape(value, depth = 0) {
|
|
40
|
+
if (depth > 6 || value === null || typeof value !== "object") return typeof value;
|
|
41
|
+
if (Array.isArray(value)) return value.map((item) => schemaShape(item, depth + 1));
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const key of Object.keys(value).sort()) out[key] = schemaShape(value[key], depth + 1);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Pick the hashable subset of `options`, normalizing `tools` into their
|
|
48
|
+
* name+description+schema-shape fingerprint. `signal` and any field not in
|
|
49
|
+
* `hashOptions` are dropped.
|
|
50
|
+
*/
|
|
51
|
+
function pickOptions(options, hashOptions) {
|
|
52
|
+
if (!options) return {};
|
|
53
|
+
const picked = {};
|
|
54
|
+
for (const key of hashOptions) {
|
|
55
|
+
const value = options[key];
|
|
56
|
+
if (value === void 0) continue;
|
|
57
|
+
if (key === "tools" && Array.isArray(value)) {
|
|
58
|
+
picked[key] = value.map(fingerprintTool);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
picked[key] = value;
|
|
62
|
+
}
|
|
63
|
+
return picked;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Recursively sort object keys so two logically-equal payloads serialize to
|
|
67
|
+
* byte-identical JSON regardless of property insertion order.
|
|
68
|
+
*/
|
|
69
|
+
function canonicalize(value) {
|
|
70
|
+
if (value === null || typeof value !== "object") return value;
|
|
71
|
+
if (Array.isArray(value)) return value.map(canonicalize);
|
|
72
|
+
const out = {};
|
|
73
|
+
for (const key of Object.keys(value).sort()) out[key] = canonicalize(value[key]);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Non-cryptographic 53-bit string hash (FNV-style, cyrb53). Deterministic
|
|
78
|
+
* across runs and platforms; collision-resistant enough for a per-cassette
|
|
79
|
+
* keyspace. Returned as a base-36 string.
|
|
80
|
+
*/
|
|
81
|
+
function hashString(input) {
|
|
82
|
+
let h1 = 3735928559;
|
|
83
|
+
let h2 = 1103547991;
|
|
84
|
+
for (let i = 0; i < input.length; i++) {
|
|
85
|
+
const ch = input.charCodeAt(i);
|
|
86
|
+
h1 = Math.imul(h1 ^ ch, 2654435761);
|
|
87
|
+
h2 = Math.imul(h2 ^ ch, 1597334677);
|
|
88
|
+
}
|
|
89
|
+
h1 = Math.imul(h1 ^ h1 >>> 16, 2246822507);
|
|
90
|
+
h1 ^= Math.imul(h2 ^ h2 >>> 13, 3266489909);
|
|
91
|
+
h2 = Math.imul(h2 ^ h2 >>> 16, 2246822507);
|
|
92
|
+
h2 ^= Math.imul(h1 ^ h1 >>> 13, 3266489909);
|
|
93
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Compute the stable VCR request hash for a model call.
|
|
97
|
+
*
|
|
98
|
+
* The hash covers the full `messages` array plus the picked, normalized
|
|
99
|
+
* `options` subset (see {@link DEFAULT_HASH_OPTIONS}). Inputs are
|
|
100
|
+
* canonicalized (recursive key sort) before serialization so property order
|
|
101
|
+
* never affects the result. `signal` and unknown provider keys are excluded.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const a = hashRequest(messages, { temperature: 0.2 });
|
|
105
|
+
* const b = hashRequest(messages, { temperature: 0.2, signal });
|
|
106
|
+
* // a === b — signal is excluded.
|
|
107
|
+
*/
|
|
108
|
+
function hashRequest(messages, options, hashOptions = DEFAULT_HASH_OPTIONS) {
|
|
109
|
+
const payload = canonicalize({
|
|
110
|
+
messages,
|
|
111
|
+
options: pickOptions(options, hashOptions)
|
|
112
|
+
});
|
|
113
|
+
return hashString(JSON.stringify(payload));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { DEFAULT_HASH_OPTIONS, hashRequest };
|
|
118
|
+
//# sourceMappingURL=hash-request.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-request.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/vcr/hash-request.ts"],"sourcesContent":["import type { Message } from \"../contracts/conversation-message.type\";\nimport type { ModelCallOptions } from \"../contracts/model.contract\";\nimport type { ToolConfig } from \"../contracts/tool.contract\";\n\n/**\n * Default `ModelCallOptions` fields folded into the request hash. These are\n * the inputs that materially change the model's output; everything else\n * (notably `signal` and unknown provider keys) is excluded so an otherwise\n * identical logical call still matches its recording.\n */\nexport const DEFAULT_HASH_OPTIONS: readonly string[] = [\n \"temperature\",\n \"maxTokens\",\n \"responseSchema\",\n \"tools\",\n \"reasoning\",\n];\n\n/**\n * Reduce a tool to the parts the model actually conditions on: its name,\n * description, and the *shape* of its input schema. Two tools that differ\n * only by object identity (a fresh schema instance per import) hash\n * identically; a real contract change (renamed field, new description)\n * invalidates the recording.\n *\n * The input schema is fingerprinted structurally — a Standard Schema is an\n * opaque object, so we serialize its enumerable own keys rather than\n * attempting to read its internals.\n */\nfunction fingerprintTool(tool: ToolConfig<unknown, unknown>): unknown {\n return {\n name: tool.name,\n description: tool.description,\n input: tool.input ? schemaShape(tool.input) : undefined,\n };\n}\n\n/**\n * Produce a stable, JSON-safe fingerprint of an arbitrary schema object.\n * Records only the structural skeleton (own enumerable keys, recursively)\n * so harmless instance differences don't perturb the hash while a genuine\n * structural change does.\n */\nfunction schemaShape(value: unknown, depth = 0): unknown {\n if (depth > 6 || value === null || typeof value !== \"object\") {\n return typeof value;\n }\n\n if (Array.isArray(value)) {\n return value.map((item) => schemaShape(item, depth + 1));\n }\n\n const out: Record<string, unknown> = {};\n\n for (const key of Object.keys(value as Record<string, unknown>).sort()) {\n out[key] = schemaShape((value as Record<string, unknown>)[key], depth + 1);\n }\n\n return out;\n}\n\n/**\n * Pick the hashable subset of `options`, normalizing `tools` into their\n * name+description+schema-shape fingerprint. `signal` and any field not in\n * `hashOptions` are dropped.\n */\nfunction pickOptions(\n options: ModelCallOptions | undefined,\n hashOptions: readonly string[],\n): Record<string, unknown> {\n if (!options) {\n return {};\n }\n\n const picked: Record<string, unknown> = {};\n\n for (const key of hashOptions) {\n const value = options[key];\n\n if (value === undefined) {\n continue;\n }\n\n if (key === \"tools\" && Array.isArray(value)) {\n picked[key] = (value as ToolConfig<unknown, unknown>[]).map(fingerprintTool);\n continue;\n }\n\n picked[key] = value;\n }\n\n return picked;\n}\n\n/**\n * Recursively sort object keys so two logically-equal payloads serialize to\n * byte-identical JSON regardless of property insertion order.\n */\nfunction canonicalize(value: unknown): unknown {\n if (value === null || typeof value !== \"object\") {\n return value;\n }\n\n if (Array.isArray(value)) {\n return value.map(canonicalize);\n }\n\n const out: Record<string, unknown> = {};\n\n for (const key of Object.keys(value as Record<string, unknown>).sort()) {\n out[key] = canonicalize((value as Record<string, unknown>)[key]);\n }\n\n return out;\n}\n\n/**\n * Non-cryptographic 53-bit string hash (FNV-style, cyrb53). Deterministic\n * across runs and platforms; collision-resistant enough for a per-cassette\n * keyspace. Returned as a base-36 string.\n */\nfunction hashString(input: string): string {\n let h1 = 0xdeadbeef;\n let h2 = 0x41c6ce57;\n\n for (let i = 0; i < input.length; i++) {\n const ch = input.charCodeAt(i);\n\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n\n const combined = 4294967296 * (2097151 & h2) + (h1 >>> 0);\n\n return combined.toString(36);\n}\n\n/**\n * Compute the stable VCR request hash for a model call.\n *\n * The hash covers the full `messages` array plus the picked, normalized\n * `options` subset (see {@link DEFAULT_HASH_OPTIONS}). Inputs are\n * canonicalized (recursive key sort) before serialization so property order\n * never affects the result. `signal` and unknown provider keys are excluded.\n *\n * @example\n * const a = hashRequest(messages, { temperature: 0.2 });\n * const b = hashRequest(messages, { temperature: 0.2, signal });\n * // a === b — signal is excluded.\n */\nexport function hashRequest(\n messages: Message[],\n options?: ModelCallOptions,\n hashOptions: readonly string[] = DEFAULT_HASH_OPTIONS,\n): string {\n const payload = canonicalize({\n messages,\n options: pickOptions(options, hashOptions),\n });\n\n return hashString(JSON.stringify(payload));\n}\n"],"mappings":";;;;;;;AAUA,MAAa,uBAA0C;CACrD;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;AAaA,SAAS,gBAAgB,MAA6C;CACpE,OAAO;EACL,MAAM,KAAK;EACX,aAAa,KAAK;EAClB,OAAO,KAAK,QAAQ,YAAY,KAAK,KAAK,IAAI;CAChD;AACF;;;;;;;AAQA,SAAS,YAAY,OAAgB,QAAQ,GAAY;CACvD,IAAI,QAAQ,KAAK,UAAU,QAAQ,OAAO,UAAU,UAClD,OAAO,OAAO;CAGhB,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,KAAK,SAAS,YAAY,MAAM,QAAQ,CAAC,CAAC;CAGzD,MAAM,MAA+B,CAAC;CAEtC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAgC,CAAC,CAAC,KAAK,GACnE,IAAI,OAAO,YAAa,MAAkC,MAAM,QAAQ,CAAC;CAG3E,OAAO;AACT;;;;;;AAOA,SAAS,YACP,SACA,aACyB;CACzB,IAAI,CAAC,SACH,OAAO,CAAC;CAGV,MAAM,SAAkC,CAAC;CAEzC,KAAK,MAAM,OAAO,aAAa;EAC7B,MAAM,QAAQ,QAAQ;EAEtB,IAAI,UAAU,QACZ;EAGF,IAAI,QAAQ,WAAW,MAAM,QAAQ,KAAK,GAAG;GAC3C,OAAO,OAAQ,MAAyC,IAAI,eAAe;GAC3E;EACF;EAEA,OAAO,OAAO;CAChB;CAEA,OAAO;AACT;;;;;AAMA,SAAS,aAAa,OAAyB;CAC7C,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,OAAO;CAGT,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,YAAY;CAG/B,MAAM,MAA+B,CAAC;CAEtC,KAAK,MAAM,OAAO,OAAO,KAAK,KAAgC,CAAC,CAAC,KAAK,GACnE,IAAI,OAAO,aAAc,MAAkC,IAAI;CAGjE,OAAO;AACT;;;;;;AAOA,SAAS,WAAW,OAAuB;CACzC,IAAI,KAAK;CACT,IAAI,KAAK;CAET,KAAK,IAAI,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;EACrC,MAAM,KAAK,MAAM,WAAW,CAAC;EAE7B,KAAK,KAAK,KAAK,KAAK,IAAI,UAAU;EAClC,KAAK,KAAK,KAAK,KAAK,IAAI,UAAU;CACpC;CAEA,KAAK,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;CAC3C,MAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;CAC5C,KAAK,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;CAC3C,MAAM,KAAK,KAAK,KAAM,OAAO,IAAK,UAAU;CAI5C,QAFiB,cAAc,UAAU,OAAO,OAAO,GAExC,CAAC,SAAS,EAAE;AAC7B;;;;;;;;;;;;;;AAeA,SAAgB,YACd,UACA,SACA,cAAiC,sBACzB;CACR,MAAM,UAAU,aAAa;EAC3B;EACA,SAAS,YAAY,SAAS,WAAW;CAC3C,CAAC;CAED,OAAO,WAAW,KAAK,UAAU,OAAO,CAAC;AAC3C"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { redact } from "../security/redact.mjs";
|
|
2
|
+
import { emptyCassette, loadCassette, saveCassette } from "./cassette-io.mjs";
|
|
3
|
+
import { VcrCassetteMissError } from "./errors.mjs";
|
|
4
|
+
import { DEFAULT_HASH_OPTIONS, hashRequest } from "./hash-request.mjs";
|
|
5
|
+
|
|
6
|
+
//#region ../@warlock.js/ai/src/vcr/vcr.ts
|
|
7
|
+
/**
|
|
8
|
+
* Internal decorator that wraps an inner `ModelContract`, intercepting only
|
|
9
|
+
* `complete()`/`stream()` and delegating every identity getter to the inner
|
|
10
|
+
* model. Drives the record/replay state machine over a single in-memory
|
|
11
|
+
* {@link Cassette}.
|
|
12
|
+
*
|
|
13
|
+
* **Why a class.** It holds mutable per-instance state (the loaded cassette,
|
|
14
|
+
* the dirty flag, the load promise) behind a stable `ModelContract` surface;
|
|
15
|
+
* the public API is the `vcr()` factory, never `new`.
|
|
16
|
+
*/
|
|
17
|
+
var Vcr = class {
|
|
18
|
+
constructor(inner, options) {
|
|
19
|
+
this.inner = inner;
|
|
20
|
+
this.dirty = false;
|
|
21
|
+
this.warnedVerbatim = false;
|
|
22
|
+
this.path = options.path;
|
|
23
|
+
this.mode = options.mode ?? "auto";
|
|
24
|
+
this.hashOptions = options.hashOptions ?? DEFAULT_HASH_OPTIONS;
|
|
25
|
+
this.recordRequest = options.recordRequest ?? "verbatim";
|
|
26
|
+
this.redactRequestHook = options.redactRequest;
|
|
27
|
+
this.redactResponseHook = options.redactResponse;
|
|
28
|
+
this.redactErrorHook = options.redactError;
|
|
29
|
+
this.loadedCassette = emptyCassette(inner.name, inner.provider);
|
|
30
|
+
}
|
|
31
|
+
/** Inner model identifier — delegated verbatim. */
|
|
32
|
+
get name() {
|
|
33
|
+
return this.inner.name;
|
|
34
|
+
}
|
|
35
|
+
/** Inner provider — delegated verbatim. */
|
|
36
|
+
get provider() {
|
|
37
|
+
return this.inner.provider;
|
|
38
|
+
}
|
|
39
|
+
/** Inner capability flags — delegated verbatim. */
|
|
40
|
+
get capabilities() {
|
|
41
|
+
return this.inner.capabilities;
|
|
42
|
+
}
|
|
43
|
+
/** Inner pricing — delegated verbatim so cost accounting is unchanged. */
|
|
44
|
+
get pricing() {
|
|
45
|
+
return this.inner.pricing;
|
|
46
|
+
}
|
|
47
|
+
/** Loaded/recorded cassette, exposed for assertions. */
|
|
48
|
+
get cassette() {
|
|
49
|
+
return this.loadedCassette;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Load the on-disk cassette exactly once. Pure `record` mode skips the
|
|
53
|
+
* read — it always writes fresh — but the in-memory cassette still starts
|
|
54
|
+
* empty so a record run never accidentally replays a stale entry.
|
|
55
|
+
*/
|
|
56
|
+
async ensureLoaded() {
|
|
57
|
+
if (this.loadPromise) return this.loadPromise;
|
|
58
|
+
this.loadPromise = this.mode === "record" ? Promise.resolve() : (async () => {
|
|
59
|
+
this.loadedCassette = await loadCassette(this.path, this.inner.name, this.inner.provider);
|
|
60
|
+
})();
|
|
61
|
+
return this.loadPromise;
|
|
62
|
+
}
|
|
63
|
+
/** Find a recorded entry whose hash matches the current request. */
|
|
64
|
+
findEntry(hash) {
|
|
65
|
+
return this.loadedCassette.entries.find((entry) => entry.requestHash === hash);
|
|
66
|
+
}
|
|
67
|
+
/** Re-throw a recorded error by reconstructing a plain `Error`. */
|
|
68
|
+
throwRecordedError(entry) {
|
|
69
|
+
const error = new Error(entry.error?.message ?? "Recorded error");
|
|
70
|
+
error.name = entry.error?.name ?? "Error";
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Non-streaming call. In `replay` a miss throws; in `auto`/`record` a miss
|
|
75
|
+
* calls the inner model and records the outcome (response or error).
|
|
76
|
+
*/
|
|
77
|
+
async complete(messages, options) {
|
|
78
|
+
await this.ensureLoaded();
|
|
79
|
+
const hash = hashRequest(messages, options, this.hashOptions);
|
|
80
|
+
if (this.mode !== "record") {
|
|
81
|
+
const entry = this.findEntry(hash);
|
|
82
|
+
if (entry) {
|
|
83
|
+
if (entry.error) this.throwRecordedError(entry);
|
|
84
|
+
if (entry.response) return entry.response;
|
|
85
|
+
}
|
|
86
|
+
if (this.mode === "replay") throw new VcrCassetteMissError(`No cassette entry for this request (model "${this.inner.name}", hash ${hash}).`, {
|
|
87
|
+
requestHash: hash,
|
|
88
|
+
path: this.path
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
const response = await this.inner.complete(messages, options);
|
|
93
|
+
this.record({
|
|
94
|
+
requestHash: hash,
|
|
95
|
+
request: {
|
|
96
|
+
messages,
|
|
97
|
+
options
|
|
98
|
+
},
|
|
99
|
+
response
|
|
100
|
+
});
|
|
101
|
+
return response;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
this.record({
|
|
104
|
+
requestHash: hash,
|
|
105
|
+
request: {
|
|
106
|
+
messages,
|
|
107
|
+
options
|
|
108
|
+
},
|
|
109
|
+
error: {
|
|
110
|
+
name: error.name,
|
|
111
|
+
message: error.message
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
throw error;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Streaming call. On replay the stored `chunks` are re-yielded in order
|
|
119
|
+
* (reproducing the `delta`/`tool-call`/`done` sequence) or the stored
|
|
120
|
+
* error is re-thrown. On record the inner stream is buffered into
|
|
121
|
+
* `chunks[]` while being re-emitted, then recorded once exhausted.
|
|
122
|
+
*/
|
|
123
|
+
async *stream(messages, options) {
|
|
124
|
+
await this.ensureLoaded();
|
|
125
|
+
const hash = hashRequest(messages, options, this.hashOptions);
|
|
126
|
+
if (this.mode !== "record") {
|
|
127
|
+
const entry = this.findEntry(hash);
|
|
128
|
+
if (entry) {
|
|
129
|
+
if (entry.error) this.throwRecordedError(entry);
|
|
130
|
+
if (entry.chunks) {
|
|
131
|
+
for (const chunk of entry.chunks) yield chunk;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (this.mode === "replay") throw new VcrCassetteMissError(`No cassette entry for this request (model "${this.inner.name}", hash ${hash}).`, {
|
|
136
|
+
requestHash: hash,
|
|
137
|
+
path: this.path
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const chunks = [];
|
|
141
|
+
try {
|
|
142
|
+
for await (const chunk of this.inner.stream(messages, options)) {
|
|
143
|
+
chunks.push(chunk);
|
|
144
|
+
yield chunk;
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
this.record({
|
|
148
|
+
requestHash: hash,
|
|
149
|
+
request: {
|
|
150
|
+
messages,
|
|
151
|
+
options
|
|
152
|
+
},
|
|
153
|
+
error: {
|
|
154
|
+
name: error.name,
|
|
155
|
+
message: error.message
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
this.record({
|
|
161
|
+
requestHash: hash,
|
|
162
|
+
request: {
|
|
163
|
+
messages,
|
|
164
|
+
options
|
|
165
|
+
},
|
|
166
|
+
chunks
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Append an entry to the in-memory cassette and mark it dirty, applying
|
|
171
|
+
* the configured request/response/error redaction first (S2). Pure
|
|
172
|
+
* `replay` never reaches this path, so no replay run is ever dirtied.
|
|
173
|
+
*/
|
|
174
|
+
record(entry) {
|
|
175
|
+
this.loadedCassette.entries.push(this.applyRedaction(entry));
|
|
176
|
+
this.dirty = true;
|
|
177
|
+
this.maybeWarnVerbatim();
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Apply the persisted-body privacy controls to an entry before it is
|
|
181
|
+
* stored. The request body follows `recordRequest`; response/error
|
|
182
|
+
* redactors are applied only when supplied. Replay matching is by the
|
|
183
|
+
* recomputed hash (kept verbatim), so none of this affects replay.
|
|
184
|
+
*/
|
|
185
|
+
applyRedaction(entry) {
|
|
186
|
+
const out = {
|
|
187
|
+
requestHash: entry.requestHash,
|
|
188
|
+
request: entry.request
|
|
189
|
+
};
|
|
190
|
+
if (this.recordRequest === "hash-only") out.request = { messages: [] };
|
|
191
|
+
else if (this.recordRequest === "redacted") out.request = this.redactRequestHook ? this.redactRequestHook(entry.request) : redact(entry.request);
|
|
192
|
+
if (entry.response) out.response = this.redactResponseHook ? this.redactResponseHook(entry.response) : entry.response;
|
|
193
|
+
if (entry.chunks) out.chunks = entry.chunks;
|
|
194
|
+
if (entry.error) out.error = this.redactErrorHook ? this.redactErrorHook(entry.error) : entry.error;
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Warn once (outside tests) when the cassette is recording verbatim
|
|
199
|
+
* request bodies — they may carry prompts, tool args, and PII, so the
|
|
200
|
+
* file is not safe to commit until sanitized.
|
|
201
|
+
*/
|
|
202
|
+
maybeWarnVerbatim() {
|
|
203
|
+
if (this.warnedVerbatim || this.recordRequest !== "verbatim") return;
|
|
204
|
+
if (process.env.VITEST || process.env.NODE_ENV === "test") return;
|
|
205
|
+
this.warnedVerbatim = true;
|
|
206
|
+
console.warn(`[warlock-ai] VCR is recording verbatim request bodies to "${this.path}" — prompts, tool args, and any PII are stored unredacted. Sanitize before committing, or set recordRequest: "redacted" | "hash-only".`);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Flush newly recorded entries to `path`. No-op when nothing was recorded
|
|
210
|
+
* (pure replay, or a record/auto run that only ever hit cached entries).
|
|
211
|
+
*/
|
|
212
|
+
async save() {
|
|
213
|
+
if (!this.dirty) return;
|
|
214
|
+
await saveCassette(this.path, this.loadedCassette);
|
|
215
|
+
this.dirty = false;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Wrap any `ModelContract` in a record/replay decorator backed by a JSON
|
|
220
|
+
* cassette on disk.
|
|
221
|
+
*
|
|
222
|
+
* **What it does.** Intercepts only `complete()`/`stream()` — the single
|
|
223
|
+
* seam every agent trip funnels through — and delegates `name`, `provider`,
|
|
224
|
+
* `capabilities`, and `pricing` to the inner model untouched. On a call it
|
|
225
|
+
* computes a stable hash over `{ messages, picked options }` and, depending
|
|
226
|
+
* on `mode`:
|
|
227
|
+
*
|
|
228
|
+
* - **`record`** — always calls the inner model and appends a cassette entry.
|
|
229
|
+
* - **`replay`** — returns the matching entry (or re-yields its chunks /
|
|
230
|
+
* re-throws its error); a miss throws `VcrCassetteMissError`, never a live
|
|
231
|
+
* call.
|
|
232
|
+
* - **`auto`** (default) — replays a hit, records a miss.
|
|
233
|
+
*
|
|
234
|
+
* Composes *below* `fallbackModel` and works with any adapter because it
|
|
235
|
+
* depends only on `ModelContract`. Call `save()` to flush new entries.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* const model = vcr(liveModel, { path: "./cassettes/support.json" });
|
|
239
|
+
* const response = await model.complete(messages);
|
|
240
|
+
* await model.save(); // first run records; later runs replay deterministically.
|
|
241
|
+
*/
|
|
242
|
+
function vcr(model, options) {
|
|
243
|
+
return new Vcr(model, options);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
//#endregion
|
|
247
|
+
export { vcr };
|
|
248
|
+
//# sourceMappingURL=vcr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcr.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/vcr/vcr.ts"],"sourcesContent":["import type { Message } from \"../contracts/conversation-message.type\";\nimport type {\n ModelCallOptions,\n ModelCapabilities,\n ModelContract,\n ModelResponse,\n ModelStreamChunk,\n} from \"../contracts/model.contract\";\nimport type { ModelPricing } from \"../contracts/result/model-pricing.type\";\nimport { redact } from \"../security/redact\";\nimport { emptyCassette, loadCassette, saveCassette } from \"./cassette-io\";\nimport { VcrCassetteMissError } from \"./errors\";\nimport { DEFAULT_HASH_OPTIONS, hashRequest } from \"./hash-request\";\nimport type { Cassette, CassetteEntry, VcrMode, VcrModel, VcrOptions } from \"./vcr.type\";\n\n/**\n * Internal decorator that wraps an inner `ModelContract`, intercepting only\n * `complete()`/`stream()` and delegating every identity getter to the inner\n * model. Drives the record/replay state machine over a single in-memory\n * {@link Cassette}.\n *\n * **Why a class.** It holds mutable per-instance state (the loaded cassette,\n * the dirty flag, the load promise) behind a stable `ModelContract` surface;\n * the public API is the `vcr()` factory, never `new`.\n */\nclass Vcr implements VcrModel {\n private readonly mode: VcrMode;\n private readonly path: string;\n private readonly hashOptions: readonly string[];\n\n /** Loaded + newly recorded entries. Mutated in place as we record. */\n private loadedCassette: Cassette;\n\n /** Set when an entry is recorded so `save()` knows there's work to flush. */\n private dirty = false;\n\n /** One-shot lazy load of the on-disk cassette, shared across calls. */\n private loadPromise: Promise<void> | undefined;\n\n /** Persisted-body privacy controls (S2). */\n private readonly recordRequest: NonNullable<VcrOptions[\"recordRequest\"]>;\n private readonly redactRequestHook: VcrOptions[\"redactRequest\"];\n private readonly redactResponseHook: VcrOptions[\"redactResponse\"];\n private readonly redactErrorHook: VcrOptions[\"redactError\"];\n\n /** Verbatim-recording warning fires at most once per instance. */\n private warnedVerbatim = false;\n\n public constructor(\n private readonly inner: ModelContract,\n options: VcrOptions,\n ) {\n this.path = options.path;\n this.mode = options.mode ?? \"auto\";\n this.hashOptions = options.hashOptions ?? DEFAULT_HASH_OPTIONS;\n this.recordRequest = options.recordRequest ?? \"verbatim\";\n this.redactRequestHook = options.redactRequest;\n this.redactResponseHook = options.redactResponse;\n this.redactErrorHook = options.redactError;\n this.loadedCassette = emptyCassette(inner.name, inner.provider);\n }\n\n /** Inner model identifier — delegated verbatim. */\n public get name(): string {\n return this.inner.name;\n }\n\n /** Inner provider — delegated verbatim. */\n public get provider(): string {\n return this.inner.provider;\n }\n\n /** Inner capability flags — delegated verbatim. */\n public get capabilities(): ModelCapabilities | undefined {\n return this.inner.capabilities;\n }\n\n /** Inner pricing — delegated verbatim so cost accounting is unchanged. */\n public get pricing(): ModelPricing | undefined {\n return this.inner.pricing;\n }\n\n /** Loaded/recorded cassette, exposed for assertions. */\n public get cassette(): Cassette {\n return this.loadedCassette;\n }\n\n /**\n * Load the on-disk cassette exactly once. Pure `record` mode skips the\n * read — it always writes fresh — but the in-memory cassette still starts\n * empty so a record run never accidentally replays a stale entry.\n */\n private async ensureLoaded(): Promise<void> {\n if (this.loadPromise) {\n return this.loadPromise;\n }\n\n this.loadPromise =\n this.mode === \"record\"\n ? Promise.resolve()\n : (async () => {\n this.loadedCassette = await loadCassette(\n this.path,\n this.inner.name,\n this.inner.provider,\n );\n })();\n\n return this.loadPromise;\n }\n\n /** Find a recorded entry whose hash matches the current request. */\n private findEntry(hash: string): CassetteEntry | undefined {\n return this.loadedCassette.entries.find((entry) => entry.requestHash === hash);\n }\n\n /** Re-throw a recorded error by reconstructing a plain `Error`. */\n private throwRecordedError(entry: CassetteEntry): never {\n const error = new Error(entry.error?.message ?? \"Recorded error\");\n\n error.name = entry.error?.name ?? \"Error\";\n\n throw error;\n }\n\n /**\n * Non-streaming call. In `replay` a miss throws; in `auto`/`record` a miss\n * calls the inner model and records the outcome (response or error).\n */\n public async complete(messages: Message[], options?: ModelCallOptions): Promise<ModelResponse> {\n await this.ensureLoaded();\n\n const hash = hashRequest(messages, options, this.hashOptions);\n\n if (this.mode !== \"record\") {\n const entry = this.findEntry(hash);\n\n if (entry) {\n if (entry.error) {\n this.throwRecordedError(entry);\n }\n\n if (entry.response) {\n return entry.response;\n }\n }\n\n if (this.mode === \"replay\") {\n throw new VcrCassetteMissError(\n `No cassette entry for this request (model \"${this.inner.name}\", hash ${hash}).`,\n { requestHash: hash, path: this.path },\n );\n }\n }\n\n try {\n const response = await this.inner.complete(messages, options);\n\n this.record({ requestHash: hash, request: { messages, options }, response });\n\n return response;\n } catch (error) {\n this.record({\n requestHash: hash,\n request: { messages, options },\n error: { name: (error as Error).name, message: (error as Error).message },\n });\n\n throw error;\n }\n }\n\n /**\n * Streaming call. On replay the stored `chunks` are re-yielded in order\n * (reproducing the `delta`/`tool-call`/`done` sequence) or the stored\n * error is re-thrown. On record the inner stream is buffered into\n * `chunks[]` while being re-emitted, then recorded once exhausted.\n */\n public async *stream(\n messages: Message[],\n options?: ModelCallOptions,\n ): AsyncIterable<ModelStreamChunk> {\n await this.ensureLoaded();\n\n const hash = hashRequest(messages, options, this.hashOptions);\n\n if (this.mode !== \"record\") {\n const entry = this.findEntry(hash);\n\n if (entry) {\n if (entry.error) {\n this.throwRecordedError(entry);\n }\n\n if (entry.chunks) {\n for (const chunk of entry.chunks) {\n yield chunk;\n }\n\n return;\n }\n }\n\n if (this.mode === \"replay\") {\n throw new VcrCassetteMissError(\n `No cassette entry for this request (model \"${this.inner.name}\", hash ${hash}).`,\n { requestHash: hash, path: this.path },\n );\n }\n }\n\n const chunks: ModelStreamChunk[] = [];\n\n try {\n for await (const chunk of this.inner.stream(messages, options)) {\n chunks.push(chunk);\n\n yield chunk;\n }\n } catch (error) {\n this.record({\n requestHash: hash,\n request: { messages, options },\n error: { name: (error as Error).name, message: (error as Error).message },\n });\n\n throw error;\n }\n\n this.record({ requestHash: hash, request: { messages, options }, chunks });\n }\n\n /**\n * Append an entry to the in-memory cassette and mark it dirty, applying\n * the configured request/response/error redaction first (S2). Pure\n * `replay` never reaches this path, so no replay run is ever dirtied.\n */\n private record(entry: CassetteEntry): void {\n this.loadedCassette.entries.push(this.applyRedaction(entry));\n this.dirty = true;\n this.maybeWarnVerbatim();\n }\n\n /**\n * Apply the persisted-body privacy controls to an entry before it is\n * stored. The request body follows `recordRequest`; response/error\n * redactors are applied only when supplied. Replay matching is by the\n * recomputed hash (kept verbatim), so none of this affects replay.\n */\n private applyRedaction(entry: CassetteEntry): CassetteEntry {\n const out: CassetteEntry = {\n requestHash: entry.requestHash,\n request: entry.request,\n };\n\n if (this.recordRequest === \"hash-only\") {\n out.request = { messages: [] };\n } else if (this.recordRequest === \"redacted\") {\n out.request = this.redactRequestHook\n ? this.redactRequestHook(entry.request)\n : redact(entry.request);\n }\n\n if (entry.response) {\n out.response = this.redactResponseHook\n ? this.redactResponseHook(entry.response)\n : entry.response;\n }\n if (entry.chunks) {\n out.chunks = entry.chunks;\n }\n if (entry.error) {\n out.error = this.redactErrorHook\n ? this.redactErrorHook(entry.error)\n : entry.error;\n }\n\n return out;\n }\n\n /**\n * Warn once (outside tests) when the cassette is recording verbatim\n * request bodies — they may carry prompts, tool args, and PII, so the\n * file is not safe to commit until sanitized.\n */\n private maybeWarnVerbatim(): void {\n if (this.warnedVerbatim || this.recordRequest !== \"verbatim\") return;\n if (process.env.VITEST || process.env.NODE_ENV === \"test\") return;\n\n this.warnedVerbatim = true;\n console.warn(\n `[warlock-ai] VCR is recording verbatim request bodies to \"${this.path}\" — prompts, tool args, and any PII are stored unredacted. ` +\n 'Sanitize before committing, or set recordRequest: \"redacted\" | \"hash-only\".',\n );\n }\n\n /**\n * Flush newly recorded entries to `path`. No-op when nothing was recorded\n * (pure replay, or a record/auto run that only ever hit cached entries).\n */\n public async save(): Promise<void> {\n if (!this.dirty) {\n return;\n }\n\n await saveCassette(this.path, this.loadedCassette);\n this.dirty = false;\n }\n}\n\n/**\n * Wrap any `ModelContract` in a record/replay decorator backed by a JSON\n * cassette on disk.\n *\n * **What it does.** Intercepts only `complete()`/`stream()` — the single\n * seam every agent trip funnels through — and delegates `name`, `provider`,\n * `capabilities`, and `pricing` to the inner model untouched. On a call it\n * computes a stable hash over `{ messages, picked options }` and, depending\n * on `mode`:\n *\n * - **`record`** — always calls the inner model and appends a cassette entry.\n * - **`replay`** — returns the matching entry (or re-yields its chunks /\n * re-throws its error); a miss throws `VcrCassetteMissError`, never a live\n * call.\n * - **`auto`** (default) — replays a hit, records a miss.\n *\n * Composes *below* `fallbackModel` and works with any adapter because it\n * depends only on `ModelContract`. Call `save()` to flush new entries.\n *\n * @example\n * const model = vcr(liveModel, { path: \"./cassettes/support.json\" });\n * const response = await model.complete(messages);\n * await model.save(); // first run records; later runs replay deterministically.\n */\nexport function vcr(model: ModelContract, options: VcrOptions): VcrModel {\n return new Vcr(model, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAyBA,IAAM,MAAN,MAA8B;CAuB5B,AAAO,YACL,AAAiB,OACjB,SACA;EAFiB;eAfH;wBAYS;EAMvB,KAAK,OAAO,QAAQ;EACpB,KAAK,OAAO,QAAQ,QAAQ;EAC5B,KAAK,cAAc,QAAQ,eAAe;EAC1C,KAAK,gBAAgB,QAAQ,iBAAiB;EAC9C,KAAK,oBAAoB,QAAQ;EACjC,KAAK,qBAAqB,QAAQ;EAClC,KAAK,kBAAkB,QAAQ;EAC/B,KAAK,iBAAiB,cAAc,MAAM,MAAM,MAAM,QAAQ;CAChE;;CAGA,IAAW,OAAe;EACxB,OAAO,KAAK,MAAM;CACpB;;CAGA,IAAW,WAAmB;EAC5B,OAAO,KAAK,MAAM;CACpB;;CAGA,IAAW,eAA8C;EACvD,OAAO,KAAK,MAAM;CACpB;;CAGA,IAAW,UAAoC;EAC7C,OAAO,KAAK,MAAM;CACpB;;CAGA,IAAW,WAAqB;EAC9B,OAAO,KAAK;CACd;;;;;;CAOA,MAAc,eAA8B;EAC1C,IAAI,KAAK,aACP,OAAO,KAAK;EAGd,KAAK,cACH,KAAK,SAAS,WACV,QAAQ,QAAQ,KACf,YAAY;GACX,KAAK,iBAAiB,MAAM,aAC1B,KAAK,MACL,KAAK,MAAM,MACX,KAAK,MAAM,QACb;EACF,EAAC,CAAE;EAET,OAAO,KAAK;CACd;;CAGA,AAAQ,UAAU,MAAyC;EACzD,OAAO,KAAK,eAAe,QAAQ,MAAM,UAAU,MAAM,gBAAgB,IAAI;CAC/E;;CAGA,AAAQ,mBAAmB,OAA6B;EACtD,MAAM,QAAQ,IAAI,MAAM,MAAM,OAAO,WAAW,gBAAgB;EAEhE,MAAM,OAAO,MAAM,OAAO,QAAQ;EAElC,MAAM;CACR;;;;;CAMA,MAAa,SAAS,UAAqB,SAAoD;EAC7F,MAAM,KAAK,aAAa;EAExB,MAAM,OAAO,YAAY,UAAU,SAAS,KAAK,WAAW;EAE5D,IAAI,KAAK,SAAS,UAAU;GAC1B,MAAM,QAAQ,KAAK,UAAU,IAAI;GAEjC,IAAI,OAAO;IACT,IAAI,MAAM,OACR,KAAK,mBAAmB,KAAK;IAG/B,IAAI,MAAM,UACR,OAAO,MAAM;GAEjB;GAEA,IAAI,KAAK,SAAS,UAChB,MAAM,IAAI,qBACR,8CAA8C,KAAK,MAAM,KAAK,UAAU,KAAK,KAC7E;IAAE,aAAa;IAAM,MAAM,KAAK;GAAK,CACvC;EAEJ;EAEA,IAAI;GACF,MAAM,WAAW,MAAM,KAAK,MAAM,SAAS,UAAU,OAAO;GAE5D,KAAK,OAAO;IAAE,aAAa;IAAM,SAAS;KAAE;KAAU;IAAQ;IAAG;GAAS,CAAC;GAE3E,OAAO;EACT,SAAS,OAAO;GACd,KAAK,OAAO;IACV,aAAa;IACb,SAAS;KAAE;KAAU;IAAQ;IAC7B,OAAO;KAAE,MAAO,MAAgB;KAAM,SAAU,MAAgB;IAAQ;GAC1E,CAAC;GAED,MAAM;EACR;CACF;;;;;;;CAQA,OAAc,OACZ,UACA,SACiC;EACjC,MAAM,KAAK,aAAa;EAExB,MAAM,OAAO,YAAY,UAAU,SAAS,KAAK,WAAW;EAE5D,IAAI,KAAK,SAAS,UAAU;GAC1B,MAAM,QAAQ,KAAK,UAAU,IAAI;GAEjC,IAAI,OAAO;IACT,IAAI,MAAM,OACR,KAAK,mBAAmB,KAAK;IAG/B,IAAI,MAAM,QAAQ;KAChB,KAAK,MAAM,SAAS,MAAM,QACxB,MAAM;KAGR;IACF;GACF;GAEA,IAAI,KAAK,SAAS,UAChB,MAAM,IAAI,qBACR,8CAA8C,KAAK,MAAM,KAAK,UAAU,KAAK,KAC7E;IAAE,aAAa;IAAM,MAAM,KAAK;GAAK,CACvC;EAEJ;EAEA,MAAM,SAA6B,CAAC;EAEpC,IAAI;GACF,WAAW,MAAM,SAAS,KAAK,MAAM,OAAO,UAAU,OAAO,GAAG;IAC9D,OAAO,KAAK,KAAK;IAEjB,MAAM;GACR;EACF,SAAS,OAAO;GACd,KAAK,OAAO;IACV,aAAa;IACb,SAAS;KAAE;KAAU;IAAQ;IAC7B,OAAO;KAAE,MAAO,MAAgB;KAAM,SAAU,MAAgB;IAAQ;GAC1E,CAAC;GAED,MAAM;EACR;EAEA,KAAK,OAAO;GAAE,aAAa;GAAM,SAAS;IAAE;IAAU;GAAQ;GAAG;EAAO,CAAC;CAC3E;;;;;;CAOA,AAAQ,OAAO,OAA4B;EACzC,KAAK,eAAe,QAAQ,KAAK,KAAK,eAAe,KAAK,CAAC;EAC3D,KAAK,QAAQ;EACb,KAAK,kBAAkB;CACzB;;;;;;;CAQA,AAAQ,eAAe,OAAqC;EAC1D,MAAM,MAAqB;GACzB,aAAa,MAAM;GACnB,SAAS,MAAM;EACjB;EAEA,IAAI,KAAK,kBAAkB,aACzB,IAAI,UAAU,EAAE,UAAU,CAAC,EAAE;OACxB,IAAI,KAAK,kBAAkB,YAChC,IAAI,UAAU,KAAK,oBACf,KAAK,kBAAkB,MAAM,OAAO,IACpC,OAAO,MAAM,OAAO;EAG1B,IAAI,MAAM,UACR,IAAI,WAAW,KAAK,qBAChB,KAAK,mBAAmB,MAAM,QAAQ,IACtC,MAAM;EAEZ,IAAI,MAAM,QACR,IAAI,SAAS,MAAM;EAErB,IAAI,MAAM,OACR,IAAI,QAAQ,KAAK,kBACb,KAAK,gBAAgB,MAAM,KAAK,IAChC,MAAM;EAGZ,OAAO;CACT;;;;;;CAOA,AAAQ,oBAA0B;EAChC,IAAI,KAAK,kBAAkB,KAAK,kBAAkB,YAAY;EAC9D,IAAI,QAAQ,IAAI,UAAU,QAAQ,IAAI,aAAa,QAAQ;EAE3D,KAAK,iBAAiB;EACtB,QAAQ,KACN,6DAA6D,KAAK,KAAK,uIAEzE;CACF;;;;;CAMA,MAAa,OAAsB;EACjC,IAAI,CAAC,KAAK,OACR;EAGF,MAAM,aAAa,KAAK,MAAM,KAAK,cAAc;EACjD,KAAK,QAAQ;CACf;AACF;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,IAAI,OAAsB,SAA+B;CACvE,OAAO,IAAI,IAAI,OAAO,OAAO;AAC/B"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { WorkflowError } from "../errors/workflow-error.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
3
|
+
import { compositeAsTool } from "../tool/tool.mjs";
|
|
4
|
+
|
|
5
|
+
//#region ../@warlock.js/ai/src/workflow/as-tool.ts
|
|
6
|
+
/**
|
|
7
|
+
* Wrap a `WorkflowInstance` as a `ToolContract` so an agent can invoke
|
|
8
|
+
* it inside its tool-call loop. Closes the agent-calls-workflow
|
|
9
|
+
* composition gap.
|
|
10
|
+
*
|
|
11
|
+
* Behavior:
|
|
12
|
+
* - Tool `name` mirrors `workflow.name` — workflows without a name throw
|
|
13
|
+
* `WorkflowError` at wrap time (the agent surface needs a stable id).
|
|
14
|
+
* - Tool `input` is the supplied `inputSchema`; the validated value is
|
|
15
|
+
* forwarded straight to `workflow.execute(input)`.
|
|
16
|
+
* - On `result.error`, the workflow error is wrapped in
|
|
17
|
+
* `ToolExecutionError` with `cause` set to the original
|
|
18
|
+
* `WorkflowError` subclass — the agent's tool-call loop sees a
|
|
19
|
+
* uniform error class regardless of which primitive failed.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const wf = workflow({ name: "triage", steps: [...] });
|
|
23
|
+
* const triageTool = asTool(wf, {
|
|
24
|
+
* description: "Run the support-ticket triage flow",
|
|
25
|
+
* inputSchema: ticketSchema,
|
|
26
|
+
* });
|
|
27
|
+
* const a = ai.agent({ model, tools: [triageTool] });
|
|
28
|
+
*/
|
|
29
|
+
function asTool(workflowInstance, options) {
|
|
30
|
+
if (!workflowInstance.name || typeof workflowInstance.name !== "string") throw new WorkflowError("workflow.asTool(): workflow must have a `name` to be wrapped as a tool");
|
|
31
|
+
return compositeAsTool({
|
|
32
|
+
name: workflowInstance.name,
|
|
33
|
+
description: options.description ?? `Invoke workflow "${workflowInstance.name}" as a tool.`,
|
|
34
|
+
input: options.inputSchema,
|
|
35
|
+
execute: async (input, ctx) => {
|
|
36
|
+
const result = await workflowInstance.execute(input, ctx?.signal ? { signal: ctx.signal } : void 0);
|
|
37
|
+
if (result.error) throw result.error;
|
|
38
|
+
return {
|
|
39
|
+
data: result.data,
|
|
40
|
+
usage: result.usage,
|
|
41
|
+
report: result.report
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { asTool };
|
|
49
|
+
//# sourceMappingURL=as-tool.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"as-tool.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/workflow/as-tool.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { WorkflowInstance } from \"../contracts/workflow/workflow.contract\";\nimport { WorkflowError } from \"../errors\";\nimport { compositeAsTool, type ToolContract } from \"../tool/tool\";\n\n/**\n * Wrap a `WorkflowInstance` as a `ToolContract` so an agent can invoke\n * it inside its tool-call loop. Closes the agent-calls-workflow\n * composition gap.\n *\n * Behavior:\n * - Tool `name` mirrors `workflow.name` — workflows without a name throw\n * `WorkflowError` at wrap time (the agent surface needs a stable id).\n * - Tool `input` is the supplied `inputSchema`; the validated value is\n * forwarded straight to `workflow.execute(input)`.\n * - On `result.error`, the workflow error is wrapped in\n * `ToolExecutionError` with `cause` set to the original\n * `WorkflowError` subclass — the agent's tool-call loop sees a\n * uniform error class regardless of which primitive failed.\n *\n * @example\n * const wf = workflow({ name: \"triage\", steps: [...] });\n * const triageTool = asTool(wf, {\n * description: \"Run the support-ticket triage flow\",\n * inputSchema: ticketSchema,\n * });\n * const a = ai.agent({ model, tools: [triageTool] });\n */\nexport function asTool<TInput, TOutput, TToolInput = TInput>(\n workflowInstance: WorkflowInstance<TInput, TOutput>,\n options: {\n description?: string;\n inputSchema: StandardSchemaV1<TToolInput>;\n },\n): ToolContract<TToolInput, TOutput> {\n if (!workflowInstance.name || typeof workflowInstance.name !== \"string\") {\n throw new WorkflowError(\n \"workflow.asTool(): workflow must have a `name` to be wrapped as a tool\",\n );\n }\n\n return compositeAsTool<TToolInput, TOutput>({\n name: workflowInstance.name,\n description: options.description ?? `Invoke workflow \"${workflowInstance.name}\" as a tool.`,\n input: options.inputSchema,\n execute: async (input, ctx) => {\n // Relay the outer agent's cancellation signal so cancelling the\n // parent aborts this nested workflow run (C2).\n const result = await workflowInstance.execute(\n input as unknown as TInput,\n ctx?.signal ? { signal: ctx.signal } : undefined,\n );\n\n if (result.error) {\n // Throw the workflow error so the surrounding wrapper catches\n // it and produces a `ToolExecutionError` with `cause` pointing\n // back at the original `WorkflowError` subclass — keeps the\n // agent's tool-call loop seeing one uniform error class\n // regardless of which primitive failed.\n throw result.error;\n }\n\n return {\n data: result.data as TOutput,\n usage: result.usage,\n report: result.report,\n };\n },\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,SAAgB,OACd,kBACA,SAImC;CACnC,IAAI,CAAC,iBAAiB,QAAQ,OAAO,iBAAiB,SAAS,UAC7D,MAAM,IAAI,cACR,wEACF;CAGF,OAAO,gBAAqC;EAC1C,MAAM,iBAAiB;EACvB,aAAa,QAAQ,eAAe,oBAAoB,iBAAiB,KAAK;EAC9E,OAAO,QAAQ;EACf,SAAS,OAAO,OAAO,QAAQ;GAG7B,MAAM,SAAS,MAAM,iBAAiB,QACpC,OACA,KAAK,SAAS,EAAE,QAAQ,IAAI,OAAO,IAAI,MACzC;GAEA,IAAI,OAAO,OAMT,MAAM,OAAO;GAGf,OAAO;IACL,MAAM,OAAO;IACb,OAAO,OAAO;IACd,QAAQ,OAAO;GACjB;EACF;CACF,CAAC;AACH"}
|