@warlock.js/core 4.7.0 → 4.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/esm/config/config-getter.mjs +5 -5
- package/esm/config/config-getter.mjs.map +1 -1
- package/esm/config/config-loader.mjs +2 -2
- package/esm/config/config-loader.mjs.map +1 -1
- package/esm/connectors/access-connector.mjs +2 -2
- package/esm/connectors/access-connector.mjs.map +1 -1
- package/esm/connectors/ai-connector.mjs +3 -3
- package/esm/connectors/ai-connector.mjs.map +1 -1
- package/esm/connectors/cache-connector.mjs +2 -2
- package/esm/connectors/cache-connector.mjs.map +1 -1
- package/esm/connectors/database-connector.mjs +2 -2
- package/esm/connectors/database-connector.mjs.map +1 -1
- package/esm/connectors/herald-connector.mjs +2 -2
- package/esm/connectors/herald-connector.mjs.map +1 -1
- package/esm/connectors/http-connector.mjs +7 -7
- package/esm/connectors/http-connector.mjs.map +1 -1
- package/esm/connectors/logger-connector.mjs +2 -2
- package/esm/connectors/logger-connector.mjs.map +1 -1
- package/esm/connectors/mail-connector.mjs +2 -2
- package/esm/connectors/mail-connector.mjs.map +1 -1
- package/esm/connectors/notifications-connector.mjs +2 -2
- package/esm/connectors/notifications-connector.mjs.map +1 -1
- package/esm/connectors/socket-connector.mjs +3 -3
- package/esm/connectors/socket-connector.mjs.map +1 -1
- package/esm/http/config.mjs +2 -2
- package/esm/http/config.mjs.map +1 -1
- package/esm/http/createHttpApplication.mjs +2 -2
- package/esm/http/createHttpApplication.mjs.map +1 -1
- package/esm/http/middleware/idempotency.middleware.mjs +5 -5
- package/esm/http/middleware/idempotency.middleware.mjs.map +1 -1
- package/esm/http/middleware/inject-request-context.mjs +2 -2
- package/esm/http/middleware/inject-request-context.mjs.map +1 -1
- package/esm/http/middleware/maintenance.middleware.mjs +4 -4
- package/esm/http/middleware/maintenance.middleware.mjs.map +1 -1
- package/esm/http/plugins.mjs +9 -9
- package/esm/http/plugins.mjs.map +1 -1
- package/esm/http/response.mjs +5 -5
- package/esm/http/response.mjs.map +1 -1
- package/esm/http/server.mjs +4 -4
- package/esm/http/server.mjs.map +1 -1
- package/esm/utils/paths.mjs +2 -2
- package/esm/utils/paths.mjs.map +1 -1
- package/esm/validation/validateAll.mjs +2 -2
- package/esm/validation/validateAll.mjs.map +1 -1
- package/package.json +12 -9
- package/esm/ai/src/agent/agent-input-builder.mjs +0 -133
- package/esm/ai/src/agent/agent-input-builder.mjs.map +0 -1
- package/esm/ai/src/agent/agent-log-event.mjs +0 -101
- package/esm/ai/src/agent/agent-log-event.mjs.map +0 -1
- package/esm/ai/src/agent/agent-stream.mjs +0 -82
- package/esm/ai/src/agent/agent-stream.mjs.map +0 -1
- package/esm/ai/src/agent/agent-to-stream-event.mjs +0 -86
- package/esm/ai/src/agent/agent-to-stream-event.mjs.map +0 -1
- package/esm/ai/src/agent/agent.mjs +0 -1276
- package/esm/ai/src/agent/agent.mjs.map +0 -1
- package/esm/ai/src/agent/index.mjs +0 -5
- package/esm/ai/src/agent/json-stream-guard.mjs +0 -400
- package/esm/ai/src/agent/json-stream-guard.mjs.map +0 -1
- package/esm/ai/src/agent/signature.mjs +0 -57
- package/esm/ai/src/agent/signature.mjs.map +0 -1
- package/esm/ai/src/agent/snapshot.mjs +0 -101
- package/esm/ai/src/agent/snapshot.mjs.map +0 -1
- package/esm/ai/src/agent/spawn-sub-agent.mjs +0 -68
- package/esm/ai/src/agent/spawn-sub-agent.mjs.map +0 -1
- package/esm/ai/src/ai.mjs +0 -191
- package/esm/ai/src/ai.mjs.map +0 -1
- package/esm/ai/src/batch/batch.mjs +0 -198
- package/esm/ai/src/batch/batch.mjs.map +0 -1
- package/esm/ai/src/batch/index.mjs +0 -3
- package/esm/ai/src/batch/run-batch-item.mjs +0 -100
- package/esm/ai/src/batch/run-batch-item.mjs.map +0 -1
- package/esm/ai/src/batch/run-with-concurrency.mjs +0 -39
- package/esm/ai/src/batch/run-with-concurrency.mjs.map +0 -1
- package/esm/ai/src/checkpoint/memory.mjs +0 -0
- package/esm/ai/src/checkpoint/memory.mjs.map +0 -1
- package/esm/ai/src/checkpoint/pg.mjs +0 -265
- package/esm/ai/src/checkpoint/pg.mjs.map +0 -1
- package/esm/ai/src/checkpoint/redis.mjs +0 -200
- package/esm/ai/src/checkpoint/redis.mjs.map +0 -1
- package/esm/ai/src/config.mjs +0 -59
- package/esm/ai/src/config.mjs.map +0 -1
- package/esm/ai/src/contracts/end.type.mjs +0 -47
- package/esm/ai/src/contracts/end.type.mjs.map +0 -1
- package/esm/ai/src/errors/agent-cancelled-error.mjs +0 -43
- package/esm/ai/src/errors/agent-cancelled-error.mjs.map +0 -1
- package/esm/ai/src/errors/agent-drift-error.mjs +0 -31
- package/esm/ai/src/errors/agent-drift-error.mjs.map +0 -1
- package/esm/ai/src/errors/agent-execution-error.mjs +0 -35
- package/esm/ai/src/errors/agent-execution-error.mjs.map +0 -1
- package/esm/ai/src/errors/agent-max-trips-error.mjs +0 -41
- package/esm/ai/src/errors/agent-max-trips-error.mjs.map +0 -1
- package/esm/ai/src/errors/ai-error.mjs +0 -68
- package/esm/ai/src/errors/ai-error.mjs.map +0 -1
- package/esm/ai/src/errors/budget-exceeded-error.mjs +0 -31
- package/esm/ai/src/errors/budget-exceeded-error.mjs.map +0 -1
- package/esm/ai/src/errors/content-filter-error.mjs +0 -28
- package/esm/ai/src/errors/content-filter-error.mjs.map +0 -1
- package/esm/ai/src/errors/context-length-exceeded-error.mjs +0 -31
- package/esm/ai/src/errors/context-length-exceeded-error.mjs.map +0 -1
- package/esm/ai/src/errors/guardrail-violation-error.mjs +0 -41
- package/esm/ai/src/errors/guardrail-violation-error.mjs.map +0 -1
- package/esm/ai/src/errors/index.mjs +0 -40
- package/esm/ai/src/errors/invalid-request-error.mjs +0 -31
- package/esm/ai/src/errors/invalid-request-error.mjs.map +0 -1
- package/esm/ai/src/errors/max-iterations-error.mjs +0 -32
- package/esm/ai/src/errors/max-iterations-error.mjs.map +0 -1
- package/esm/ai/src/errors/max-steps-exceeded-error.mjs +0 -21
- package/esm/ai/src/errors/max-steps-exceeded-error.mjs.map +0 -1
- package/esm/ai/src/errors/orchestrator-cancelled-error.mjs +0 -31
- package/esm/ai/src/errors/orchestrator-cancelled-error.mjs.map +0 -1
- package/esm/ai/src/errors/orchestrator-config-error.mjs +0 -30
- package/esm/ai/src/errors/orchestrator-config-error.mjs.map +0 -1
- package/esm/ai/src/errors/orchestrator-drift-error.mjs +0 -37
- package/esm/ai/src/errors/orchestrator-drift-error.mjs.map +0 -1
- package/esm/ai/src/errors/orchestrator-failed-error.mjs +0 -36
- package/esm/ai/src/errors/orchestrator-failed-error.mjs.map +0 -1
- package/esm/ai/src/errors/outbound-policy-error.mjs +0 -32
- package/esm/ai/src/errors/outbound-policy-error.mjs.map +0 -1
- package/esm/ai/src/errors/planner-cancelled-error.mjs +0 -29
- package/esm/ai/src/errors/planner-cancelled-error.mjs.map +0 -1
- package/esm/ai/src/errors/planner-drift-error.mjs +0 -33
- package/esm/ai/src/errors/planner-drift-error.mjs.map +0 -1
- package/esm/ai/src/errors/planner-failed-error.mjs +0 -37
- package/esm/ai/src/errors/planner-failed-error.mjs.map +0 -1
- package/esm/ai/src/errors/planner-plan-invalid-error.mjs +0 -25
- package/esm/ai/src/errors/planner-plan-invalid-error.mjs.map +0 -1
- package/esm/ai/src/errors/prompt-refinement-error.mjs +0 -27
- package/esm/ai/src/errors/prompt-refinement-error.mjs.map +0 -1
- package/esm/ai/src/errors/provider-auth-error.mjs +0 -26
- package/esm/ai/src/errors/provider-auth-error.mjs.map +0 -1
- package/esm/ai/src/errors/provider-error.mjs +0 -42
- package/esm/ai/src/errors/provider-error.mjs.map +0 -1
- package/esm/ai/src/errors/provider-rate-limit-error.mjs +0 -31
- package/esm/ai/src/errors/provider-rate-limit-error.mjs.map +0 -1
- package/esm/ai/src/errors/provider-timeout-error.mjs +0 -26
- package/esm/ai/src/errors/provider-timeout-error.mjs.map +0 -1
- package/esm/ai/src/errors/quota-exceeded-error.mjs +0 -40
- package/esm/ai/src/errors/quota-exceeded-error.mjs.map +0 -1
- package/esm/ai/src/errors/routing-error.mjs +0 -23
- package/esm/ai/src/errors/routing-error.mjs.map +0 -1
- package/esm/ai/src/errors/schema-validation-error.mjs +0 -37
- package/esm/ai/src/errors/schema-validation-error.mjs.map +0 -1
- package/esm/ai/src/errors/step-failed-error.mjs +0 -19
- package/esm/ai/src/errors/step-failed-error.mjs.map +0 -1
- package/esm/ai/src/errors/supervisor-cancelled-error.mjs +0 -29
- package/esm/ai/src/errors/supervisor-cancelled-error.mjs.map +0 -1
- package/esm/ai/src/errors/supervisor-drift-error.mjs +0 -30
- package/esm/ai/src/errors/supervisor-drift-error.mjs.map +0 -1
- package/esm/ai/src/errors/supervisor-failed-error.mjs +0 -43
- package/esm/ai/src/errors/supervisor-failed-error.mjs.map +0 -1
- package/esm/ai/src/errors/supervisor-routing-error.mjs +0 -39
- package/esm/ai/src/errors/supervisor-routing-error.mjs.map +0 -1
- package/esm/ai/src/errors/tool-execution-error.mjs +0 -32
- package/esm/ai/src/errors/tool-execution-error.mjs.map +0 -1
- package/esm/ai/src/errors/workflow-cancelled-error.mjs +0 -23
- package/esm/ai/src/errors/workflow-cancelled-error.mjs.map +0 -1
- package/esm/ai/src/errors/workflow-drift-error.mjs +0 -24
- package/esm/ai/src/errors/workflow-drift-error.mjs.map +0 -1
- package/esm/ai/src/errors/workflow-error.mjs +0 -18
- package/esm/ai/src/errors/workflow-error.mjs.map +0 -1
- package/esm/ai/src/eval/dataset.mjs +0 -112
- package/esm/ai/src/eval/dataset.mjs.map +0 -1
- package/esm/ai/src/eval/eval-runner.mjs +0 -135
- package/esm/ai/src/eval/eval-runner.mjs.map +0 -1
- package/esm/ai/src/eval/index.mjs +0 -48
- package/esm/ai/src/eval/index.mjs.map +0 -1
- package/esm/ai/src/eval/judge-scorer.mjs +0 -87
- package/esm/ai/src/eval/judge-scorer.mjs.map +0 -1
- package/esm/ai/src/eval/regression.mjs +0 -51
- package/esm/ai/src/eval/regression.mjs.map +0 -1
- package/esm/ai/src/eval/report-json.mjs +0 -33
- package/esm/ai/src/eval/report-json.mjs.map +0 -1
- package/esm/ai/src/eval/report-junit.mjs +0 -60
- package/esm/ai/src/eval/report-junit.mjs.map +0 -1
- package/esm/ai/src/eval/scorers.mjs +0 -101
- package/esm/ai/src/eval/scorers.mjs.map +0 -1
- package/esm/ai/src/guard/detectors/index.mjs +0 -6
- package/esm/ai/src/guard/detectors/injection.mjs +0 -254
- package/esm/ai/src/guard/detectors/injection.mjs.map +0 -1
- package/esm/ai/src/guard/detectors/moderation.mjs +0 -134
- package/esm/ai/src/guard/detectors/moderation.mjs.map +0 -1
- package/esm/ai/src/guard/detectors/pii.mjs +0 -199
- package/esm/ai/src/guard/detectors/pii.mjs.map +0 -1
- package/esm/ai/src/guard/detectors/topic.mjs +0 -99
- package/esm/ai/src/guard/detectors/topic.mjs.map +0 -1
- package/esm/ai/src/guard/errors.mjs +0 -18
- package/esm/ai/src/guard/errors.mjs.map +0 -1
- package/esm/ai/src/guard/guard.mjs +0 -209
- package/esm/ai/src/guard/guard.mjs.map +0 -1
- package/esm/ai/src/guard/guardrail.mjs +0 -22
- package/esm/ai/src/guard/guardrail.mjs.map +0 -1
- package/esm/ai/src/human/errors.mjs +0 -60
- package/esm/ai/src/human/errors.mjs.map +0 -1
- package/esm/ai/src/human/human-approval.mjs +0 -170
- package/esm/ai/src/human/human-approval.mjs.map +0 -1
- package/esm/ai/src/human/policy.mjs +0 -67
- package/esm/ai/src/human/policy.mjs.map +0 -1
- package/esm/ai/src/human/register.mjs +0 -37
- package/esm/ai/src/human/register.mjs.map +0 -1
- package/esm/ai/src/human/resume-seed.mjs +0 -53
- package/esm/ai/src/human/resume-seed.mjs.map +0 -1
- package/esm/ai/src/human/resume.mjs +0 -121
- package/esm/ai/src/human/resume.mjs.map +0 -1
- package/esm/ai/src/human/stores/index.mjs +0 -5
- package/esm/ai/src/human/stores/memory.mjs +0 -91
- package/esm/ai/src/human/stores/memory.mjs.map +0 -1
- package/esm/ai/src/human/stores/pg.mjs +0 -220
- package/esm/ai/src/human/stores/pg.mjs.map +0 -1
- package/esm/ai/src/human/stores/redis.mjs +0 -201
- package/esm/ai/src/human/stores/redis.mjs.map +0 -1
- package/esm/ai/src/image/image-cost.mjs +0 -55
- package/esm/ai/src/image/image-cost.mjs.map +0 -1
- package/esm/ai/src/image/image.mjs +0 -112
- package/esm/ai/src/image/image.mjs.map +0 -1
- package/esm/ai/src/image/index.mjs +0 -4
- package/esm/ai/src/index.mjs +0 -196
- package/esm/ai/src/memory/derive-id.mjs +0 -24
- package/esm/ai/src/memory/derive-id.mjs.map +0 -1
- package/esm/ai/src/memory/episodic-memory.mjs +0 -106
- package/esm/ai/src/memory/episodic-memory.mjs.map +0 -1
- package/esm/ai/src/memory/memory.mjs +0 -166
- package/esm/ai/src/memory/memory.mjs.map +0 -1
- package/esm/ai/src/memory/procedural-memory.mjs +0 -103
- package/esm/ai/src/memory/procedural-memory.mjs.map +0 -1
- package/esm/ai/src/memory/semantic-memory.mjs +0 -80
- package/esm/ai/src/memory/semantic-memory.mjs.map +0 -1
- package/esm/ai/src/memory/working-memory.mjs +0 -62
- package/esm/ai/src/memory/working-memory.mjs.map +0 -1
- package/esm/ai/src/middleware/builtins/budget.mjs +0 -219
- package/esm/ai/src/middleware/builtins/budget.mjs.map +0 -1
- package/esm/ai/src/middleware/builtins/guardrail.mjs +0 -76
- package/esm/ai/src/middleware/builtins/guardrail.mjs.map +0 -1
- package/esm/ai/src/middleware/builtins/semantic-cache.mjs +0 -149
- package/esm/ai/src/middleware/builtins/semantic-cache.mjs.map +0 -1
- package/esm/ai/src/middleware/helpers/compose.mjs +0 -52
- package/esm/ai/src/middleware/helpers/compose.mjs.map +0 -1
- package/esm/ai/src/middleware/helpers/for-tool.mjs +0 -80
- package/esm/ai/src/middleware/helpers/for-tool.mjs.map +0 -1
- package/esm/ai/src/middleware/index.mjs +0 -10
- package/esm/ai/src/middleware/pipeline.mjs +0 -100
- package/esm/ai/src/middleware/pipeline.mjs.map +0 -1
- package/esm/ai/src/middleware/utils/extract-user-text.mjs +0 -47
- package/esm/ai/src/middleware/utils/extract-user-text.mjs.map +0 -1
- package/esm/ai/src/middleware/utils/namespaced-state.mjs +0 -60
- package/esm/ai/src/middleware/utils/namespaced-state.mjs.map +0 -1
- package/esm/ai/src/mock/index.mjs +0 -4
- package/esm/ai/src/mock/mock-agent.mjs +0 -3
- package/esm/ai/src/mock/mock-router.mjs +0 -58
- package/esm/ai/src/mock/mock-router.mjs.map +0 -1
- package/esm/ai/src/model/fallback-model.mjs +0 -218
- package/esm/ai/src/model/fallback-model.mjs.map +0 -1
- package/esm/ai/src/model/index.mjs +0 -3
- package/esm/ai/src/object-stream/index.mjs +0 -4
- package/esm/ai/src/object-stream/parse-partial-json.mjs +0 -78
- package/esm/ai/src/object-stream/parse-partial-json.mjs.map +0 -1
- package/esm/ai/src/object-stream/stream-object.mjs +0 -97
- package/esm/ai/src/object-stream/stream-object.mjs.map +0 -1
- package/esm/ai/src/observe/index.mjs +0 -4
- package/esm/ai/src/observe/observer-registry.mjs +0 -35
- package/esm/ai/src/observe/observer-registry.mjs.map +0 -1
- package/esm/ai/src/observe/resolve-observers.mjs +0 -73
- package/esm/ai/src/observe/resolve-observers.mjs.map +0 -1
- package/esm/ai/src/orchestrator/as-tool.mjs +0 -98
- package/esm/ai/src/orchestrator/as-tool.mjs.map +0 -1
- package/esm/ai/src/orchestrator/checkpoint.mjs +0 -75
- package/esm/ai/src/orchestrator/checkpoint.mjs.map +0 -1
- package/esm/ai/src/orchestrator/commands.mjs +0 -34
- package/esm/ai/src/orchestrator/commands.mjs.map +0 -1
- package/esm/ai/src/orchestrator/compaction.mjs +0 -206
- package/esm/ai/src/orchestrator/compaction.mjs.map +0 -1
- package/esm/ai/src/orchestrator/dispatch.mjs +0 -171
- package/esm/ai/src/orchestrator/dispatch.mjs.map +0 -1
- package/esm/ai/src/orchestrator/emitter.mjs +0 -85
- package/esm/ai/src/orchestrator/emitter.mjs.map +0 -1
- package/esm/ai/src/orchestrator/execution.mjs +0 -395
- package/esm/ai/src/orchestrator/execution.mjs.map +0 -1
- package/esm/ai/src/orchestrator/index.mjs +0 -11
- package/esm/ai/src/orchestrator/load.mjs +0 -49
- package/esm/ai/src/orchestrator/load.mjs.map +0 -1
- package/esm/ai/src/orchestrator/lock.mjs +0 -75
- package/esm/ai/src/orchestrator/lock.mjs.map +0 -1
- package/esm/ai/src/orchestrator/memory.mjs +0 -141
- package/esm/ai/src/orchestrator/memory.mjs.map +0 -1
- package/esm/ai/src/orchestrator/orchestrator-stream.mjs +0 -98
- package/esm/ai/src/orchestrator/orchestrator-stream.mjs.map +0 -1
- package/esm/ai/src/orchestrator/orchestrator.mjs +0 -206
- package/esm/ai/src/orchestrator/orchestrator.mjs.map +0 -1
- package/esm/ai/src/orchestrator/resume.mjs +0 -74
- package/esm/ai/src/orchestrator/resume.mjs.map +0 -1
- package/esm/ai/src/orchestrator/session-lock.mjs +0 -83
- package/esm/ai/src/orchestrator/session-lock.mjs.map +0 -1
- package/esm/ai/src/orchestrator/signature.mjs +0 -120
- package/esm/ai/src/orchestrator/signature.mjs.map +0 -1
- package/esm/ai/src/orchestrator/window.mjs +0 -56
- package/esm/ai/src/orchestrator/window.mjs.map +0 -1
- package/esm/ai/src/planner/dag-scheduler.mjs +0 -97
- package/esm/ai/src/planner/dag-scheduler.mjs.map +0 -1
- package/esm/ai/src/planner/index.mjs +0 -6
- package/esm/ai/src/planner/plan-prompt.mjs +0 -31
- package/esm/ai/src/planner/plan-prompt.mjs.map +0 -1
- package/esm/ai/src/planner/plan-schema.mjs +0 -120
- package/esm/ai/src/planner/plan-schema.mjs.map +0 -1
- package/esm/ai/src/planner/planner-run.mjs +0 -769
- package/esm/ai/src/planner/planner-run.mjs.map +0 -1
- package/esm/ai/src/planner/planner.mjs +0 -144
- package/esm/ai/src/planner/planner.mjs.map +0 -1
- package/esm/ai/src/planner/signature.mjs +0 -27
- package/esm/ai/src/planner/signature.mjs.map +0 -1
- package/esm/ai/src/planner/snapshot.mjs +0 -95
- package/esm/ai/src/planner/snapshot.mjs.map +0 -1
- package/esm/ai/src/prompt/errors.mjs +0 -73
- package/esm/ai/src/prompt/errors.mjs.map +0 -1
- package/esm/ai/src/prompt/index.mjs +0 -4
- package/esm/ai/src/prompt/prompt-langfuse-sync.mjs +0 -104
- package/esm/ai/src/prompt/prompt-langfuse-sync.mjs.map +0 -1
- package/esm/ai/src/prompt/prompt-validate.mjs +0 -170
- package/esm/ai/src/prompt/prompt-validate.mjs.map +0 -1
- package/esm/ai/src/prompt/prompt.mjs +0 -218
- package/esm/ai/src/prompt/prompt.mjs.map +0 -1
- package/esm/ai/src/prompts/index.mjs +0 -3
- package/esm/ai/src/prompts/prompts-manager.mjs +0 -410
- package/esm/ai/src/prompts/prompts-manager.mjs.map +0 -1
- package/esm/ai/src/prompts/prompts-validate.mjs +0 -0
- package/esm/ai/src/prompts/prompts-validate.mjs.map +0 -1
- package/esm/ai/src/rag/as-tool.mjs +0 -48
- package/esm/ai/src/rag/as-tool.mjs.map +0 -1
- package/esm/ai/src/rag/chunk/chunk.mjs +0 -44
- package/esm/ai/src/rag/chunk/chunk.mjs.map +0 -1
- package/esm/ai/src/rag/chunk/fixed.mjs +0 -32
- package/esm/ai/src/rag/chunk/fixed.mjs.map +0 -1
- package/esm/ai/src/rag/chunk/markdown.mjs +0 -75
- package/esm/ai/src/rag/chunk/markdown.mjs.map +0 -1
- package/esm/ai/src/rag/chunk/recursive.mjs +0 -132
- package/esm/ai/src/rag/chunk/recursive.mjs.map +0 -1
- package/esm/ai/src/rag/chunk/sentence.mjs +0 -73
- package/esm/ai/src/rag/chunk/sentence.mjs.map +0 -1
- package/esm/ai/src/rag/hybrid/bm25.mjs +0 -51
- package/esm/ai/src/rag/hybrid/bm25.mjs.map +0 -1
- package/esm/ai/src/rag/hybrid/hybrid-rank.mjs +0 -29
- package/esm/ai/src/rag/hybrid/hybrid-rank.mjs.map +0 -1
- package/esm/ai/src/rag/hybrid/rrf.mjs +0 -30
- package/esm/ai/src/rag/hybrid/rrf.mjs.map +0 -1
- package/esm/ai/src/rag/index.mjs +0 -18
- package/esm/ai/src/rag/loaders/errors.mjs +0 -25
- package/esm/ai/src/rag/loaders/errors.mjs.map +0 -1
- package/esm/ai/src/rag/loaders/index.mjs +0 -7
- package/esm/ai/src/rag/loaders/load-html.mjs +0 -138
- package/esm/ai/src/rag/loaders/load-html.mjs.map +0 -1
- package/esm/ai/src/rag/loaders/load-pdf.mjs +0 -150
- package/esm/ai/src/rag/loaders/load-pdf.mjs.map +0 -1
- package/esm/ai/src/rag/loaders/load-text.mjs +0 -60
- package/esm/ai/src/rag/loaders/load-text.mjs.map +0 -1
- package/esm/ai/src/rag/loaders/load-web.mjs +0 -89
- package/esm/ai/src/rag/loaders/load-web.mjs.map +0 -1
- package/esm/ai/src/rag/rag.mjs +0 -126
- package/esm/ai/src/rag/rag.mjs.map +0 -1
- package/esm/ai/src/rag/rerank/keyword-reranker.mjs +0 -58
- package/esm/ai/src/rag/rerank/keyword-reranker.mjs.map +0 -1
- package/esm/ai/src/rag/rerank/llm-reranker.mjs +0 -85
- package/esm/ai/src/rag/rerank/llm-reranker.mjs.map +0 -1
- package/esm/ai/src/rag/retrieve.mjs +0 -68
- package/esm/ai/src/rag/retrieve.mjs.map +0 -1
- package/esm/ai/src/rag/store/cache-vector-store.mjs +0 -48
- package/esm/ai/src/rag/store/cache-vector-store.mjs.map +0 -1
- package/esm/ai/src/rag/store/pg-vector-store.mjs +0 -328
- package/esm/ai/src/rag/store/pg-vector-store.mjs.map +0 -1
- package/esm/ai/src/rag/transforms/multi-query.mjs +0 -41
- package/esm/ai/src/rag/transforms/multi-query.mjs.map +0 -1
- package/esm/ai/src/security/index.mjs +0 -5
- package/esm/ai/src/security/outbound-policy.mjs +0 -187
- package/esm/ai/src/security/outbound-policy.mjs.map +0 -1
- package/esm/ai/src/security/private-ip.mjs +0 -48
- package/esm/ai/src/security/private-ip.mjs.map +0 -1
- package/esm/ai/src/security/redact.mjs +0 -60
- package/esm/ai/src/security/redact.mjs.map +0 -1
- package/esm/ai/src/serve/serve.mjs +0 -90
- package/esm/ai/src/serve/serve.mjs.map +0 -1
- package/esm/ai/src/serve/sse.mjs +0 -25
- package/esm/ai/src/serve/sse.mjs.map +0 -1
- package/esm/ai/src/serve/stream-to-sse.mjs +0 -37
- package/esm/ai/src/serve/stream-to-sse.mjs.map +0 -1
- package/esm/ai/src/skills/catalog.mjs +0 -140
- package/esm/ai/src/skills/catalog.mjs.map +0 -1
- package/esm/ai/src/skills/index.mjs +0 -11
- package/esm/ai/src/skills/load-skill-tool.mjs +0 -65
- package/esm/ai/src/skills/load-skill-tool.mjs.map +0 -1
- package/esm/ai/src/skills/save-skill-tool.mjs +0 -65
- package/esm/ai/src/skills/save-skill-tool.mjs.map +0 -1
- package/esm/ai/src/skills/skills.mjs +0 -109
- package/esm/ai/src/skills/skills.mjs.map +0 -1
- package/esm/ai/src/skills/sources/directory-source.mjs +0 -108
- package/esm/ai/src/skills/sources/directory-source.mjs.map +0 -1
- package/esm/ai/src/skills/sources/index.mjs +0 -27
- package/esm/ai/src/skills/sources/index.mjs.map +0 -1
- package/esm/ai/src/skills/sources/parse-frontmatter.mjs +0 -46
- package/esm/ai/src/skills/sources/parse-frontmatter.mjs.map +0 -1
- package/esm/ai/src/skills/sources/store-source.mjs +0 -15
- package/esm/ai/src/skills/sources/store-source.mjs.map +0 -1
- package/esm/ai/src/skills/sources/url-source.mjs +0 -117
- package/esm/ai/src/skills/sources/url-source.mjs.map +0 -1
- package/esm/ai/src/snapshot/memory.mjs +0 -81
- package/esm/ai/src/snapshot/memory.mjs.map +0 -1
- package/esm/ai/src/snapshot/pg.mjs +0 -146
- package/esm/ai/src/snapshot/pg.mjs.map +0 -1
- package/esm/ai/src/snapshot/redis.mjs +0 -101
- package/esm/ai/src/snapshot/redis.mjs.map +0 -1
- package/esm/ai/src/speech/index.mjs +0 -3
- package/esm/ai/src/speech/speech.mjs +0 -122
- package/esm/ai/src/speech/speech.mjs.map +0 -1
- package/esm/ai/src/supervisor/as-tool.mjs +0 -74
- package/esm/ai/src/supervisor/as-tool.mjs.map +0 -1
- package/esm/ai/src/supervisor/cancellation.mjs +0 -22
- package/esm/ai/src/supervisor/cancellation.mjs.map +0 -1
- package/esm/ai/src/supervisor/decide.mjs +0 -272
- package/esm/ai/src/supervisor/decide.mjs.map +0 -1
- package/esm/ai/src/supervisor/emitter.mjs +0 -47
- package/esm/ai/src/supervisor/emitter.mjs.map +0 -1
- package/esm/ai/src/supervisor/entries.mjs +0 -206
- package/esm/ai/src/supervisor/entries.mjs.map +0 -1
- package/esm/ai/src/supervisor/execution.mjs +0 -1921
- package/esm/ai/src/supervisor/execution.mjs.map +0 -1
- package/esm/ai/src/supervisor/fan-out.mjs +0 -65
- package/esm/ai/src/supervisor/fan-out.mjs.map +0 -1
- package/esm/ai/src/supervisor/index.mjs +0 -14
- package/esm/ai/src/supervisor/router-factory.mjs +0 -141
- package/esm/ai/src/supervisor/router-factory.mjs.map +0 -1
- package/esm/ai/src/supervisor/router-prompt.mjs +0 -52
- package/esm/ai/src/supervisor/router-prompt.mjs.map +0 -1
- package/esm/ai/src/supervisor/signature.mjs +0 -89
- package/esm/ai/src/supervisor/signature.mjs.map +0 -1
- package/esm/ai/src/supervisor/snapshot.mjs +0 -69
- package/esm/ai/src/supervisor/snapshot.mjs.map +0 -1
- package/esm/ai/src/supervisor/supervisor-stream.mjs +0 -89
- package/esm/ai/src/supervisor/supervisor-stream.mjs.map +0 -1
- package/esm/ai/src/supervisor/supervisor.mjs +0 -144
- package/esm/ai/src/supervisor/supervisor.mjs.map +0 -1
- package/esm/ai/src/system-prompt/index.mjs +0 -7
- package/esm/ai/src/system-prompt/instruction.mjs +0 -57
- package/esm/ai/src/system-prompt/instruction.mjs.map +0 -1
- package/esm/ai/src/system-prompt/persona.mjs +0 -57
- package/esm/ai/src/system-prompt/persona.mjs.map +0 -1
- package/esm/ai/src/system-prompt/refined-system-prompt.mjs +0 -461
- package/esm/ai/src/system-prompt/refined-system-prompt.mjs.map +0 -1
- package/esm/ai/src/system-prompt/render-placeholders.mjs +0 -58
- package/esm/ai/src/system-prompt/render-placeholders.mjs.map +0 -1
- package/esm/ai/src/system-prompt/system-prompt.mjs +0 -286
- package/esm/ai/src/system-prompt/system-prompt.mjs.map +0 -1
- package/esm/ai/src/team/gates.mjs +0 -48
- package/esm/ai/src/team/gates.mjs.map +0 -1
- package/esm/ai/src/team/index.mjs +0 -3
- package/esm/ai/src/team/team.mjs +0 -94
- package/esm/ai/src/team/team.mjs.map +0 -1
- package/esm/ai/src/tool/executable-as-tool.mjs +0 -81
- package/esm/ai/src/tool/executable-as-tool.mjs.map +0 -1
- package/esm/ai/src/tool/index.mjs +0 -4
- package/esm/ai/src/tool/tool.mjs +0 -185
- package/esm/ai/src/tool/tool.mjs.map +0 -1
- package/esm/ai/src/transcribe/audio-input.mjs +0 -84
- package/esm/ai/src/transcribe/audio-input.mjs.map +0 -1
- package/esm/ai/src/transcribe/index.mjs +0 -4
- package/esm/ai/src/transcribe/transcribe.mjs +0 -127
- package/esm/ai/src/transcribe/transcribe.mjs.map +0 -1
- package/esm/ai/src/utils/compute-cost.mjs +0 -112
- package/esm/ai/src/utils/compute-cost.mjs.map +0 -1
- package/esm/ai/src/utils/extract-json-lenient.mjs +0 -97
- package/esm/ai/src/utils/extract-json-lenient.mjs.map +0 -1
- package/esm/ai/src/utils/extract-json-payload.mjs +0 -39
- package/esm/ai/src/utils/extract-json-payload.mjs.map +0 -1
- package/esm/ai/src/utils/generate-run-id.mjs +0 -23
- package/esm/ai/src/utils/generate-run-id.mjs.map +0 -1
- package/esm/ai/src/utils/index.mjs +0 -12
- package/esm/ai/src/utils/json-schema.mjs +0 -89
- package/esm/ai/src/utils/json-schema.mjs.map +0 -1
- package/esm/ai/src/utils/prepare-attachment-part.mjs +0 -232
- package/esm/ai/src/utils/prepare-attachment-part.mjs.map +0 -1
- package/esm/ai/src/utils/resolve-attachment.mjs +0 -74
- package/esm/ai/src/utils/resolve-attachment.mjs.map +0 -1
- package/esm/ai/src/utils/run-context.mjs +0 -89
- package/esm/ai/src/utils/run-context.mjs.map +0 -1
- package/esm/ai/src/utils/safe-json-parse.mjs +0 -22
- package/esm/ai/src/utils/safe-json-parse.mjs.map +0 -1
- package/esm/ai/src/utils/stamp-report-lineage.mjs +0 -45
- package/esm/ai/src/utils/stamp-report-lineage.mjs.map +0 -1
- package/esm/ai/src/vcr/cassette-io.mjs +0 -57
- package/esm/ai/src/vcr/cassette-io.mjs.map +0 -1
- package/esm/ai/src/vcr/errors.mjs +0 -37
- package/esm/ai/src/vcr/errors.mjs.map +0 -1
- package/esm/ai/src/vcr/hash-request.mjs +0 -118
- package/esm/ai/src/vcr/hash-request.mjs.map +0 -1
- package/esm/ai/src/vcr/index.mjs +0 -5
- package/esm/ai/src/vcr/vcr.mjs +0 -248
- package/esm/ai/src/vcr/vcr.mjs.map +0 -1
- package/esm/ai/src/workflow/as-tool.mjs +0 -49
- package/esm/ai/src/workflow/as-tool.mjs.map +0 -1
- package/esm/ai/src/workflow/cancellation.mjs +0 -44
- package/esm/ai/src/workflow/cancellation.mjs.map +0 -1
- package/esm/ai/src/workflow/emitter.mjs +0 -40
- package/esm/ai/src/workflow/emitter.mjs.map +0 -1
- package/esm/ai/src/workflow/engine.mjs +0 -363
- package/esm/ai/src/workflow/engine.mjs.map +0 -1
- package/esm/ai/src/workflow/index.mjs +0 -5
- package/esm/ai/src/workflow/retry.mjs +0 -32
- package/esm/ai/src/workflow/retry.mjs.map +0 -1
- package/esm/ai/src/workflow/router.mjs +0 -56
- package/esm/ai/src/workflow/router.mjs.map +0 -1
- package/esm/ai/src/workflow/run-scoped-emitter.mjs +0 -32
- package/esm/ai/src/workflow/run-scoped-emitter.mjs.map +0 -1
- package/esm/ai/src/workflow/signature.mjs +0 -34
- package/esm/ai/src/workflow/signature.mjs.map +0 -1
- package/esm/ai/src/workflow/snapshot.mjs +0 -77
- package/esm/ai/src/workflow/snapshot.mjs.map +0 -1
- package/esm/ai/src/workflow/state.mjs +0 -37
- package/esm/ai/src/workflow/state.mjs.map +0 -1
- package/esm/ai/src/workflow/step-runner.mjs +0 -370
- package/esm/ai/src/workflow/step-runner.mjs.map +0 -1
- package/esm/ai/src/workflow/step.mjs +0 -37
- package/esm/ai/src/workflow/step.mjs.map +0 -1
- package/esm/ai/src/workflow/workflow.mjs +0 -122
- package/esm/ai/src/workflow/workflow.mjs.map +0 -1
- package/esm/ai-openai/src/embedder.mjs +0 -4
- package/esm/ai-openai/src/image.mjs +0 -5
- package/esm/ai-openai/src/index.mjs +0 -7
- package/esm/ai-openai/src/model.mjs +0 -5
- package/esm/ai-openai/src/sdk.mjs +0 -9
- package/esm/ai-openai/src/speech.mjs +0 -5
- package/esm/ai-openai/src/transcription.mjs +0 -6
- package/esm/ai-openai/src/utils/index.mjs +0 -5
- package/esm/ai-openai/src/utils/to-openai-messages.mjs +0 -3
- package/esm/ai-openai/src/utils/to-openai-tools.mjs +0 -3
- package/esm/ai-openai/src/utils/wrap-openai-error.mjs +0 -4
- package/esm/node_modules/langfuse/lib/index.mjs +0 -1827
- package/esm/node_modules/langfuse/lib/index.mjs.map +0 -1
- package/esm/node_modules/langfuse-core/lib/index.mjs +0 -1770
- package/esm/node_modules/langfuse-core/lib/index.mjs.map +0 -1
- package/esm/node_modules/mustache/mustache.mjs +0 -587
- package/esm/node_modules/mustache/mustache.mjs.map +0 -1
- package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs +0 -180
- package/esm/node_modules/openai/_vendor/partial-json-parser/parser.mjs.map +0 -1
- package/esm/node_modules/openai/auth/workload-identity-auth.mjs +0 -80
- package/esm/node_modules/openai/auth/workload-identity-auth.mjs.map +0 -1
- package/esm/node_modules/openai/azure.mjs +0 -82
- package/esm/node_modules/openai/azure.mjs.map +0 -1
- package/esm/node_modules/openai/client.mjs +0 -638
- package/esm/node_modules/openai/client.mjs.map +0 -1
- package/esm/node_modules/openai/core/api-promise.mjs +0 -75
- package/esm/node_modules/openai/core/api-promise.mjs.map +0 -1
- package/esm/node_modules/openai/core/error.mjs +0 -110
- package/esm/node_modules/openai/core/error.mjs.map +0 -1
- package/esm/node_modules/openai/core/pagination.mjs +0 -160
- package/esm/node_modules/openai/core/pagination.mjs.map +0 -1
- package/esm/node_modules/openai/core/resource.mjs +0 -10
- package/esm/node_modules/openai/core/resource.mjs.map +0 -1
- package/esm/node_modules/openai/core/streaming.mjs +0 -238
- package/esm/node_modules/openai/core/streaming.mjs.map +0 -1
- package/esm/node_modules/openai/index.mjs +0 -8
- package/esm/node_modules/openai/internal/decoders/line.mjs +0 -91
- package/esm/node_modules/openai/internal/decoders/line.mjs.map +0 -1
- package/esm/node_modules/openai/internal/detect-platform.mjs +0 -123
- package/esm/node_modules/openai/internal/detect-platform.mjs.map +0 -1
- package/esm/node_modules/openai/internal/errors.mjs +0 -26
- package/esm/node_modules/openai/internal/errors.mjs.map +0 -1
- package/esm/node_modules/openai/internal/headers.mjs +0 -65
- package/esm/node_modules/openai/internal/headers.mjs.map +0 -1
- package/esm/node_modules/openai/internal/parse.mjs +0 -41
- package/esm/node_modules/openai/internal/parse.mjs.map +0 -1
- package/esm/node_modules/openai/internal/qs/formats.mjs +0 -12
- package/esm/node_modules/openai/internal/qs/formats.mjs.map +0 -1
- package/esm/node_modules/openai/internal/qs/stringify.mjs +0 -179
- package/esm/node_modules/openai/internal/qs/stringify.mjs.map +0 -1
- package/esm/node_modules/openai/internal/qs/utils.mjs +0 -65
- package/esm/node_modules/openai/internal/qs/utils.mjs.map +0 -1
- package/esm/node_modules/openai/internal/request-options.mjs +0 -11
- package/esm/node_modules/openai/internal/request-options.mjs.map +0 -1
- package/esm/node_modules/openai/internal/shims.mjs +0 -77
- package/esm/node_modules/openai/internal/shims.mjs.map +0 -1
- package/esm/node_modules/openai/internal/to-file.mjs +0 -63
- package/esm/node_modules/openai/internal/to-file.mjs.map +0 -1
- package/esm/node_modules/openai/internal/tslib.mjs +0 -16
- package/esm/node_modules/openai/internal/tslib.mjs.map +0 -1
- package/esm/node_modules/openai/internal/uploads.mjs +0 -94
- package/esm/node_modules/openai/internal/uploads.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/base64.mjs +0 -22
- package/esm/node_modules/openai/internal/utils/base64.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/bytes.mjs +0 -26
- package/esm/node_modules/openai/internal/utils/bytes.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/env.mjs +0 -16
- package/esm/node_modules/openai/internal/utils/env.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/log.mjs +0 -58
- package/esm/node_modules/openai/internal/utils/log.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/path.mjs +0 -62
- package/esm/node_modules/openai/internal/utils/path.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/query.mjs +0 -10
- package/esm/node_modules/openai/internal/utils/query.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/sleep.mjs +0 -6
- package/esm/node_modules/openai/internal/utils/sleep.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/uuid.mjs +0 -18
- package/esm/node_modules/openai/internal/utils/uuid.mjs.map +0 -1
- package/esm/node_modules/openai/internal/utils/values.mjs +0 -41
- package/esm/node_modules/openai/internal/utils/values.mjs.map +0 -1
- package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs +0 -247
- package/esm/node_modules/openai/lib/AbstractChatCompletionRunner.mjs.map +0 -1
- package/esm/node_modules/openai/lib/AssistantStream.mjs +0 -472
- package/esm/node_modules/openai/lib/AssistantStream.mjs.map +0 -1
- package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs +0 -26
- package/esm/node_modules/openai/lib/ChatCompletionRunner.mjs.map +0 -1
- package/esm/node_modules/openai/lib/ChatCompletionStream.mjs +0 -423
- package/esm/node_modules/openai/lib/ChatCompletionStream.mjs.map +0 -1
- package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs +0 -26
- package/esm/node_modules/openai/lib/ChatCompletionStreamingRunner.mjs.map +0 -1
- package/esm/node_modules/openai/lib/EventStream.mjs +0 -163
- package/esm/node_modules/openai/lib/EventStream.mjs.map +0 -1
- package/esm/node_modules/openai/lib/ResponsesParser.mjs +0 -94
- package/esm/node_modules/openai/lib/ResponsesParser.mjs.map +0 -1
- package/esm/node_modules/openai/lib/RunnableFunction.mjs +0 -8
- package/esm/node_modules/openai/lib/RunnableFunction.mjs.map +0 -1
- package/esm/node_modules/openai/lib/Util.mjs +0 -19
- package/esm/node_modules/openai/lib/Util.mjs.map +0 -1
- package/esm/node_modules/openai/lib/chatCompletionUtils.mjs +0 -11
- package/esm/node_modules/openai/lib/chatCompletionUtils.mjs.map +0 -1
- package/esm/node_modules/openai/lib/parser.mjs +0 -88
- package/esm/node_modules/openai/lib/parser.mjs.map +0 -1
- package/esm/node_modules/openai/lib/responses/ResponseStream.mjs +0 -231
- package/esm/node_modules/openai/lib/responses/ResponseStream.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/admin.mjs +0 -15
- package/esm/node_modules/openai/resources/admin/admin.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs +0 -81
- package/esm/node_modules/openai/resources/admin/organization/admin-api-keys.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs +0 -31
- package/esm/node_modules/openai/resources/admin/organization/audit-logs.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/certificates.mjs +0 -153
- package/esm/node_modules/openai/resources/admin/organization/certificates.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs +0 -42
- package/esm/node_modules/openai/resources/admin/organization/data-retention.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs +0 -106
- package/esm/node_modules/openai/resources/admin/organization/groups/groups.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs +0 -88
- package/esm/node_modules/openai/resources/admin/organization/groups/roles.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs +0 -88
- package/esm/node_modules/openai/resources/admin/organization/groups/users.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/invites.mjs +0 -83
- package/esm/node_modules/openai/resources/admin/organization/invites.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/organization.mjs +0 -45
- package/esm/node_modules/openai/resources/admin/organization/organization.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs +0 -72
- package/esm/node_modules/openai/resources/admin/organization/projects/api-keys.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs +0 -78
- package/esm/node_modules/openai/resources/admin/organization/projects/certificates.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs +0 -46
- package/esm/node_modules/openai/resources/admin/organization/projects/data-retention.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs +0 -95
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/groups.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs +0 -91
- package/esm/node_modules/openai/resources/admin/organization/projects/groups/roles.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs +0 -45
- package/esm/node_modules/openai/resources/admin/organization/projects/hosted-tool-permissions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs +0 -63
- package/esm/node_modules/openai/resources/admin/organization/projects/model-permissions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs +0 -137
- package/esm/node_modules/openai/resources/admin/organization/projects/projects.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs +0 -51
- package/esm/node_modules/openai/resources/admin/organization/projects/rate-limits.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs +0 -108
- package/esm/node_modules/openai/resources/admin/organization/projects/roles.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs +0 -112
- package/esm/node_modules/openai/resources/admin/organization/projects/service-accounts.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs +0 -106
- package/esm/node_modules/openai/resources/admin/organization/projects/spend-alerts.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs +0 -91
- package/esm/node_modules/openai/resources/admin/organization/projects/users/roles.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs +0 -118
- package/esm/node_modules/openai/resources/admin/organization/projects/users/users.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/roles.mjs +0 -96
- package/esm/node_modules/openai/resources/admin/organization/roles.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs +0 -97
- package/esm/node_modules/openai/resources/admin/organization/spend-alerts.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/usage.mjs +0 -207
- package/esm/node_modules/openai/resources/admin/organization/usage.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs +0 -88
- package/esm/node_modules/openai/resources/admin/organization/users/roles.mjs.map +0 -1
- package/esm/node_modules/openai/resources/admin/organization/users/users.mjs +0 -82
- package/esm/node_modules/openai/resources/admin/organization/users/users.mjs.map +0 -1
- package/esm/node_modules/openai/resources/audio/audio.mjs +0 -21
- package/esm/node_modules/openai/resources/audio/audio.mjs.map +0 -1
- package/esm/node_modules/openai/resources/audio/speech.mjs +0 -39
- package/esm/node_modules/openai/resources/audio/speech.mjs.map +0 -1
- package/esm/node_modules/openai/resources/audio/transcriptions.mjs +0 -22
- package/esm/node_modules/openai/resources/audio/transcriptions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/audio/translations.mjs +0 -21
- package/esm/node_modules/openai/resources/audio/translations.mjs.map +0 -1
- package/esm/node_modules/openai/resources/batches.mjs +0 -54
- package/esm/node_modules/openai/resources/batches.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/assistants.mjs +0 -78
- package/esm/node_modules/openai/resources/beta/assistants.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/beta.mjs +0 -24
- package/esm/node_modules/openai/resources/beta/beta.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs +0 -18
- package/esm/node_modules/openai/resources/beta/chatkit/chatkit.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs +0 -49
- package/esm/node_modules/openai/resources/beta/chatkit/sessions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs +0 -85
- package/esm/node_modules/openai/resources/beta/chatkit/threads.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs +0 -21
- package/esm/node_modules/openai/resources/beta/realtime/realtime.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs +0 -33
- package/esm/node_modules/openai/resources/beta/realtime/sessions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs +0 -33
- package/esm/node_modules/openai/resources/beta/realtime/transcription-sessions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/threads/messages.mjs +0 -83
- package/esm/node_modules/openai/resources/beta/threads/messages.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs +0 -183
- package/esm/node_modules/openai/resources/beta/threads/runs/runs.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs +0 -45
- package/esm/node_modules/openai/resources/beta/threads/runs/steps.mjs.map +0 -1
- package/esm/node_modules/openai/resources/beta/threads/threads.mjs +0 -101
- package/esm/node_modules/openai/resources/beta/threads/threads.mjs.map +0 -1
- package/esm/node_modules/openai/resources/chat/chat.mjs +0 -15
- package/esm/node_modules/openai/resources/chat/chat.mjs.map +0 -1
- package/esm/node_modules/openai/resources/chat/completions/completions.mjs +0 -123
- package/esm/node_modules/openai/resources/chat/completions/completions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/chat/completions/index.mjs +0 -7
- package/esm/node_modules/openai/resources/chat/completions/messages.mjs +0 -35
- package/esm/node_modules/openai/resources/chat/completions/messages.mjs.map +0 -1
- package/esm/node_modules/openai/resources/chat/index.mjs +0 -5
- package/esm/node_modules/openai/resources/completions.mjs +0 -20
- package/esm/node_modules/openai/resources/completions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/containers/containers.mjs +0 -57
- package/esm/node_modules/openai/resources/containers/containers.mjs.map +0 -1
- package/esm/node_modules/openai/resources/containers/files/content.mjs +0 -23
- package/esm/node_modules/openai/resources/containers/files/content.mjs.map +0 -1
- package/esm/node_modules/openai/resources/containers/files/files.mjs +0 -63
- package/esm/node_modules/openai/resources/containers/files/files.mjs.map +0 -1
- package/esm/node_modules/openai/resources/conversations/conversations.mjs +0 -57
- package/esm/node_modules/openai/resources/conversations/conversations.mjs.map +0 -1
- package/esm/node_modules/openai/resources/conversations/items.mjs +0 -57
- package/esm/node_modules/openai/resources/conversations/items.mjs.map +0 -1
- package/esm/node_modules/openai/resources/embeddings.mjs +0 -48
- package/esm/node_modules/openai/resources/embeddings.mjs.map +0 -1
- package/esm/node_modules/openai/resources/evals/evals.mjs +0 -73
- package/esm/node_modules/openai/resources/evals/evals.mjs.map +0 -1
- package/esm/node_modules/openai/resources/evals/runs/output-items.mjs +0 -35
- package/esm/node_modules/openai/resources/evals/runs/output-items.mjs.map +0 -1
- package/esm/node_modules/openai/resources/evals/runs/runs.mjs +0 -72
- package/esm/node_modules/openai/resources/evals/runs/runs.mjs.map +0 -1
- package/esm/node_modules/openai/resources/files.mjs +0 -111
- package/esm/node_modules/openai/resources/files.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs +0 -15
- package/esm/node_modules/openai/resources/fine-tuning/alpha/alpha.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs +0 -60
- package/esm/node_modules/openai/resources/fine-tuning/alpha/graders.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs +0 -15
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/checkpoints.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs +0 -102
- package/esm/node_modules/openai/resources/fine-tuning/checkpoints/permissions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs +0 -24
- package/esm/node_modules/openai/resources/fine-tuning/fine-tuning.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs +0 -34
- package/esm/node_modules/openai/resources/fine-tuning/jobs/checkpoints.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs +0 -148
- package/esm/node_modules/openai/resources/fine-tuning/jobs/jobs.mjs.map +0 -1
- package/esm/node_modules/openai/resources/fine-tuning/methods.mjs +0 -8
- package/esm/node_modules/openai/resources/fine-tuning/methods.mjs.map +0 -1
- package/esm/node_modules/openai/resources/graders/grader-models.mjs +0 -8
- package/esm/node_modules/openai/resources/graders/grader-models.mjs.map +0 -1
- package/esm/node_modules/openai/resources/graders/graders.mjs +0 -15
- package/esm/node_modules/openai/resources/graders/graders.mjs.map +0 -1
- package/esm/node_modules/openai/resources/images.mjs +0 -46
- package/esm/node_modules/openai/resources/images.mjs.map +0 -1
- package/esm/node_modules/openai/resources/index.mjs +0 -27
- package/esm/node_modules/openai/resources/models.mjs +0 -44
- package/esm/node_modules/openai/resources/models.mjs.map +0 -1
- package/esm/node_modules/openai/resources/moderations.mjs +0 -23
- package/esm/node_modules/openai/resources/moderations.mjs.map +0 -1
- package/esm/node_modules/openai/resources/realtime/calls.mjs +0 -79
- package/esm/node_modules/openai/resources/realtime/calls.mjs.map +0 -1
- package/esm/node_modules/openai/resources/realtime/client-secrets.mjs +0 -39
- package/esm/node_modules/openai/resources/realtime/client-secrets.mjs.map +0 -1
- package/esm/node_modules/openai/resources/realtime/realtime.mjs +0 -18
- package/esm/node_modules/openai/resources/realtime/realtime.mjs.map +0 -1
- package/esm/node_modules/openai/resources/responses/input-items.mjs +0 -31
- package/esm/node_modules/openai/resources/responses/input-items.mjs.map +0 -1
- package/esm/node_modules/openai/resources/responses/input-tokens.mjs +0 -27
- package/esm/node_modules/openai/resources/responses/input-tokens.mjs.map +0 -1
- package/esm/node_modules/openai/resources/responses/responses.mjs +0 -110
- package/esm/node_modules/openai/resources/responses/responses.mjs.map +0 -1
- package/esm/node_modules/openai/resources/skills/content.mjs +0 -22
- package/esm/node_modules/openai/resources/skills/content.mjs.map +0 -1
- package/esm/node_modules/openai/resources/skills/skills.mjs +0 -69
- package/esm/node_modules/openai/resources/skills/skills.mjs.map +0 -1
- package/esm/node_modules/openai/resources/skills/versions/content.mjs +0 -23
- package/esm/node_modules/openai/resources/skills/versions/content.mjs.map +0 -1
- package/esm/node_modules/openai/resources/skills/versions/versions.mjs +0 -58
- package/esm/node_modules/openai/resources/skills/versions/versions.mjs.map +0 -1
- package/esm/node_modules/openai/resources/uploads/parts.mjs +0 -34
- package/esm/node_modules/openai/resources/uploads/parts.mjs.map +0 -1
- package/esm/node_modules/openai/resources/uploads/uploads.mjs +0 -84
- package/esm/node_modules/openai/resources/uploads/uploads.mjs.map +0 -1
- package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs +0 -126
- package/esm/node_modules/openai/resources/vector-stores/file-batches.mjs.map +0 -1
- package/esm/node_modules/openai/resources/vector-stores/files.mjs +0 -147
- package/esm/node_modules/openai/resources/vector-stores/files.mjs.map +0 -1
- package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs +0 -87
- package/esm/node_modules/openai/resources/vector-stores/vector-stores.mjs.map +0 -1
- package/esm/node_modules/openai/resources/videos.mjs +0 -115
- package/esm/node_modules/openai/resources/videos.mjs.map +0 -1
- package/esm/node_modules/openai/resources/webhooks/index.mjs +0 -3
- package/esm/node_modules/openai/resources/webhooks/webhooks.mjs +0 -69
- package/esm/node_modules/openai/resources/webhooks/webhooks.mjs.map +0 -1
- package/esm/node_modules/openai/resources/webhooks.mjs +0 -4
- package/esm/node_modules/openai/streaming.mjs +0 -3
- package/esm/node_modules/openai/version.mjs +0 -6
- package/esm/node_modules/openai/version.mjs.map +0 -1
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
//#region ../@warlock.js/ai/src/guard/detectors/topic.ts
|
|
2
|
-
/** Detector name, used as the namespace prefix on every {@link GuardrailMatch.rule}. */
|
|
3
|
-
const DETECTOR_NAME = "topic";
|
|
4
|
-
/**
|
|
5
|
-
* Locate the first occurrence of `term` in `text`. A `string` matches
|
|
6
|
-
* case-insensitively as a substring; a `RegExp` is tested as-is (its own
|
|
7
|
-
* flags decide case-sensitivity). Returns the inclusive `[start, end]`
|
|
8
|
-
* span on a hit, or `undefined` when the term is absent.
|
|
9
|
-
*/
|
|
10
|
-
function locate(text, term) {
|
|
11
|
-
if (typeof term === "string") {
|
|
12
|
-
if (term.length === 0) return;
|
|
13
|
-
const index = text.toLowerCase().indexOf(term.toLowerCase());
|
|
14
|
-
if (index === -1) return;
|
|
15
|
-
return [index, index + term.length - 1];
|
|
16
|
-
}
|
|
17
|
-
const match = new RegExp(term.source, term.flags.replace(/[gy]/g, "")).exec(text);
|
|
18
|
-
if (match === null) return;
|
|
19
|
-
return [match.index, match.index + match[0].length - 1];
|
|
20
|
-
}
|
|
21
|
-
/** A human-readable label for a deny/allow term, used in the match rule + reason. */
|
|
22
|
-
function describeTerm(term) {
|
|
23
|
-
return typeof term === "string" ? term : term.source;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Build the built-in **topic filter** (`ai.guardrail.topic`) — a
|
|
27
|
-
* zero-runtime-dependency {@link GuardrailDetector} that gates text against a
|
|
28
|
-
* deny list, an allow list, or both.
|
|
29
|
-
*
|
|
30
|
-
* - **`deny`** — any term that appears triggers `onMatch`. A `string`
|
|
31
|
-
* matches case-insensitively as a substring; a `RegExp` is tested as-is.
|
|
32
|
-
* The deny list is checked first; the first hit decides the verdict.
|
|
33
|
-
* - **`allow`** — when set, text matching **none** of the allow terms
|
|
34
|
-
* triggers `onMatch` (an allow-list miss). Text matching at least one
|
|
35
|
-
* allow term passes the allow gate.
|
|
36
|
-
*
|
|
37
|
-
* `onMatch` is `"block"` (default) or `"flag"`. With neither list supplied
|
|
38
|
-
* the detector is a no-op that always allows.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ai.guardrail.topic({ deny: ["medical advice", /diagnos\w+/i] });
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* // Stay on-topic: anything not about billing is flagged.
|
|
45
|
-
* ai.guardrail.topic({ allow: ["billing", "invoice", "refund"], onMatch: "flag" });
|
|
46
|
-
*/
|
|
47
|
-
function topic(options) {
|
|
48
|
-
const deny = options.deny ?? [];
|
|
49
|
-
const allow = options.allow ?? [];
|
|
50
|
-
const onMatch = options.onMatch ?? "block";
|
|
51
|
-
return {
|
|
52
|
-
name: DETECTOR_NAME,
|
|
53
|
-
check(text) {
|
|
54
|
-
for (const term of deny) {
|
|
55
|
-
const span = locate(text, term);
|
|
56
|
-
if (span !== void 0) {
|
|
57
|
-
const label = describeTerm(term);
|
|
58
|
-
const match = {
|
|
59
|
-
rule: `${DETECTOR_NAME}.deny.${label}`,
|
|
60
|
-
span,
|
|
61
|
-
label
|
|
62
|
-
};
|
|
63
|
-
return verdict(onMatch, options.reason ?? `Denied topic matched: ${label}.`, [match]);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (allow.length > 0) {
|
|
67
|
-
if (!allow.some((term) => locate(text, term) !== void 0)) {
|
|
68
|
-
const match = {
|
|
69
|
-
rule: `${DETECTOR_NAME}.allow.miss`,
|
|
70
|
-
label: "allow-miss"
|
|
71
|
-
};
|
|
72
|
-
return verdict(onMatch, options.reason ?? "Text matched none of the allowed topics.", [match]);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return { type: "allow" };
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Fold the resolved action into a `block` or `flag` verdict. Topic never
|
|
81
|
-
* redacts — it cannot meaningfully rewrite a whole-text policy miss — so the
|
|
82
|
-
* action is constrained to `"block" | "flag"` at the type level.
|
|
83
|
-
*/
|
|
84
|
-
function verdict(action, reason, matches) {
|
|
85
|
-
if (action === "block") return {
|
|
86
|
-
type: "block",
|
|
87
|
-
reason,
|
|
88
|
-
matches
|
|
89
|
-
};
|
|
90
|
-
return {
|
|
91
|
-
type: "flag",
|
|
92
|
-
reason,
|
|
93
|
-
matches
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
//#endregion
|
|
98
|
-
export { topic };
|
|
99
|
-
//# sourceMappingURL=topic.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"topic.mjs","names":[],"sources":["../../../../../../../../../../@warlock.js/ai/src/guard/detectors/topic.ts"],"sourcesContent":["import type {\n GuardrailMatch,\n GuardrailVerdict,\n SyncGuardrailDetector,\n TopicFilterOptions,\n} from \"../contracts\";\n\n/** Detector name, used as the namespace prefix on every {@link GuardrailMatch.rule}. */\nconst DETECTOR_NAME = \"topic\";\n\n/**\n * Locate the first occurrence of `term` in `text`. A `string` matches\n * case-insensitively as a substring; a `RegExp` is tested as-is (its own\n * flags decide case-sensitivity). Returns the inclusive `[start, end]`\n * span on a hit, or `undefined` when the term is absent.\n */\nfunction locate(text: string, term: string | RegExp): readonly [number, number] | undefined {\n if (typeof term === \"string\") {\n if (term.length === 0) {\n return undefined;\n }\n\n const index = text.toLowerCase().indexOf(term.toLowerCase());\n\n if (index === -1) {\n return undefined;\n }\n\n return [index, index + term.length - 1];\n }\n\n // RegExp: run a non-global copy so a caller-supplied `/g` term cannot leak\n // `lastIndex` between calls and so `.exec` reports a deterministic first hit.\n const probe = new RegExp(term.source, term.flags.replace(/[gy]/g, \"\"));\n const match = probe.exec(text);\n\n if (match === null) {\n return undefined;\n }\n\n return [match.index, match.index + match[0].length - 1];\n}\n\n/** A human-readable label for a deny/allow term, used in the match rule + reason. */\nfunction describeTerm(term: string | RegExp): string {\n return typeof term === \"string\" ? term : term.source;\n}\n\n/**\n * Build the built-in **topic filter** (`ai.guardrail.topic`) — a\n * zero-runtime-dependency {@link GuardrailDetector} that gates text against a\n * deny list, an allow list, or both.\n *\n * - **`deny`** — any term that appears triggers `onMatch`. A `string`\n * matches case-insensitively as a substring; a `RegExp` is tested as-is.\n * The deny list is checked first; the first hit decides the verdict.\n * - **`allow`** — when set, text matching **none** of the allow terms\n * triggers `onMatch` (an allow-list miss). Text matching at least one\n * allow term passes the allow gate.\n *\n * `onMatch` is `\"block\"` (default) or `\"flag\"`. With neither list supplied\n * the detector is a no-op that always allows.\n *\n * @example\n * ai.guardrail.topic({ deny: [\"medical advice\", /diagnos\\w+/i] });\n *\n * @example\n * // Stay on-topic: anything not about billing is flagged.\n * ai.guardrail.topic({ allow: [\"billing\", \"invoice\", \"refund\"], onMatch: \"flag\" });\n */\nexport function topic(options: TopicFilterOptions): SyncGuardrailDetector {\n const deny = options.deny ?? [];\n const allow = options.allow ?? [];\n const onMatch = options.onMatch ?? \"block\";\n\n return {\n name: DETECTOR_NAME,\n check(text: string): GuardrailVerdict {\n // Deny list: the first present term decides the verdict.\n for (const term of deny) {\n const span = locate(text, term);\n\n if (span !== undefined) {\n const label = describeTerm(term);\n const match: GuardrailMatch = {\n rule: `${DETECTOR_NAME}.deny.${label}`,\n span,\n label,\n };\n const reason = options.reason ?? `Denied topic matched: ${label}.`;\n\n return verdict(onMatch, reason, [match]);\n }\n }\n\n // Allow list: matching NONE of the terms is a miss → trigger onMatch.\n if (allow.length > 0) {\n const matchedAny = allow.some(term => locate(text, term) !== undefined);\n\n if (!matchedAny) {\n const match: GuardrailMatch = {\n rule: `${DETECTOR_NAME}.allow.miss`,\n label: \"allow-miss\",\n };\n const reason =\n options.reason ?? \"Text matched none of the allowed topics.\";\n\n return verdict(onMatch, reason, [match]);\n }\n }\n\n return { type: \"allow\" };\n },\n };\n}\n\n/**\n * Fold the resolved action into a `block` or `flag` verdict. Topic never\n * redacts — it cannot meaningfully rewrite a whole-text policy miss — so the\n * action is constrained to `\"block\" | \"flag\"` at the type level.\n */\nfunction verdict(\n action: \"block\" | \"flag\",\n reason: string,\n matches: readonly GuardrailMatch[],\n): GuardrailVerdict {\n if (action === \"block\") {\n return { type: \"block\", reason, matches };\n }\n\n return { type: \"flag\", reason, matches };\n}\n"],"mappings":";;AAQA,MAAM,gBAAgB;;;;;;;AAQtB,SAAS,OAAO,MAAc,MAA8D;CAC1F,IAAI,OAAO,SAAS,UAAU;EAC5B,IAAI,KAAK,WAAW,GAClB;EAGF,MAAM,QAAQ,KAAK,YAAY,CAAC,CAAC,QAAQ,KAAK,YAAY,CAAC;EAE3D,IAAI,UAAU,IACZ;EAGF,OAAO,CAAC,OAAO,QAAQ,KAAK,SAAS,CAAC;CACxC;CAKA,MAAM,QAAQ,IADI,OAAO,KAAK,QAAQ,KAAK,MAAM,QAAQ,SAAS,EAAE,CAClD,CAAC,CAAC,KAAK,IAAI;CAE7B,IAAI,UAAU,MACZ;CAGF,OAAO,CAAC,MAAM,OAAO,MAAM,QAAQ,MAAM,EAAE,CAAC,SAAS,CAAC;AACxD;;AAGA,SAAS,aAAa,MAA+B;CACnD,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK;AAChD;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,MAAM,SAAoD;CACxE,MAAM,OAAO,QAAQ,QAAQ,CAAC;CAC9B,MAAM,QAAQ,QAAQ,SAAS,CAAC;CAChC,MAAM,UAAU,QAAQ,WAAW;CAEnC,OAAO;EACL,MAAM;EACN,MAAM,MAAgC;GAEpC,KAAK,MAAM,QAAQ,MAAM;IACvB,MAAM,OAAO,OAAO,MAAM,IAAI;IAE9B,IAAI,SAAS,QAAW;KACtB,MAAM,QAAQ,aAAa,IAAI;KAC/B,MAAM,QAAwB;MAC5B,MAAM,GAAG,cAAc,QAAQ;MAC/B;MACA;KACF;KAGA,OAAO,QAAQ,SAFA,QAAQ,UAAU,yBAAyB,MAAM,IAEhC,CAAC,KAAK,CAAC;IACzC;GACF;GAGA,IAAI,MAAM,SAAS,GAGjB;QAAI,CAFe,MAAM,MAAK,SAAQ,OAAO,MAAM,IAAI,MAAM,MAE/C,GAAG;KACf,MAAM,QAAwB;MAC5B,MAAM,GAAG,cAAc;MACvB,OAAO;KACT;KAIA,OAAO,QAAQ,SAFb,QAAQ,UAAU,4CAEY,CAAC,KAAK,CAAC;IACzC;;GAGF,OAAO,EAAE,MAAM,QAAQ;EACzB;CACF;AACF;;;;;;AAOA,SAAS,QACP,QACA,QACA,SACkB;CAClB,IAAI,WAAW,SACb,OAAO;EAAE,MAAM;EAAS;EAAQ;CAAQ;CAG1C,OAAO;EAAE,MAAM;EAAQ;EAAQ;CAAQ;AACzC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { GuardrailViolationError } from "../errors/guardrail-violation-error.mjs";
|
|
2
|
-
|
|
3
|
-
//#region ../@warlock.js/ai/src/guard/errors.ts
|
|
4
|
-
/**
|
|
5
|
-
* Curated install string thrown by the optional `moderation` detector on
|
|
6
|
-
* first `check()` when the `openai` peer is absent. Mirrors ai-panoptic's
|
|
7
|
-
* `LANGFUSE_INSTALL_INSTRUCTIONS`.
|
|
8
|
-
*/
|
|
9
|
-
const OPENAI_INSTALL_INSTRUCTIONS = `
|
|
10
|
-
The @warlock.js/ai moderation detector requires the optional "openai" peer.
|
|
11
|
-
Install it with:
|
|
12
|
-
|
|
13
|
-
npm install openai
|
|
14
|
-
`.trim();
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
|
-
export { OPENAI_INSTALL_INSTRUCTIONS };
|
|
18
|
-
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/guard/errors.ts"],"sourcesContent":["/**\n * Error surface for `@warlock.js/ai`.\n *\n * **No new error class.** A `block` verdict reuses the existing\n * `@warlock.js/ai` {@link GuardrailViolationError} verbatim — its category\n * (`\"guardrail\"`) and `phase` field already model exactly what a guard\n * needs, and `phase` is widened by this package to include `\"tool\"` (a\n * source-compatible third value). Re-exported here so the future `guard()`\n * factory has one import site for the typed abort it throws.\n *\n * The optional `moderation` detector's missing-peer failure is an\n * *infrastructure* fault, not a content violation, so it throws a plain\n * `Error` carrying {@link OPENAI_INSTALL_INSTRUCTIONS} (the langfuse-style\n * lazy-import pattern) rather than an `AIError`.\n */\nexport { GuardrailViolationError } from \"../errors/guardrail-violation-error\";\nexport type { GuardrailViolationErrorOptions } from \"../errors/guardrail-violation-error\";\n\n/**\n * Curated install string thrown by the optional `moderation` detector on\n * first `check()` when the `openai` peer is absent. Mirrors ai-panoptic's\n * `LANGFUSE_INSTALL_INSTRUCTIONS`.\n */\nexport const OPENAI_INSTALL_INSTRUCTIONS = `\nThe @warlock.js/ai moderation detector requires the optional \"openai\" peer.\nInstall it with:\n\n npm install openai\n`.trim();\n"],"mappings":";;;;;;;;AAuBA,MAAa,8BAA8B;;;;;EAKzC,KAAK"}
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { GuardrailViolationError } from "../errors/guardrail-violation-error.mjs";
|
|
2
|
-
import { extractUserText } from "../middleware/utils/extract-user-text.mjs";
|
|
3
|
-
import { forTool } from "../middleware/helpers/for-tool.mjs";
|
|
4
|
-
import "./errors.mjs";
|
|
5
|
-
|
|
6
|
-
//#region ../@warlock.js/ai/src/guard/guard.ts
|
|
7
|
-
/** Default middleware name when the caller supplies none. */
|
|
8
|
-
const DEFAULT_NAME = "guardrail";
|
|
9
|
-
/**
|
|
10
|
-
* The `ctx.state` key under which a guard records its `flag` verdicts. The
|
|
11
|
-
* value is an append-only array of {@link FlagRecord}, namespaced by the
|
|
12
|
-
* middleware name so two guards on the same agent never collide and a
|
|
13
|
-
* downstream observer (panoptic, the caller) can read the annotations
|
|
14
|
-
* post-run.
|
|
15
|
-
*/
|
|
16
|
-
function flagsKey(name) {
|
|
17
|
-
return `${name}.flags`;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Append a `flag` record onto the namespaced `ctx.state` array, creating it
|
|
21
|
-
* on first write. Never throws — recording is best-effort annotation.
|
|
22
|
-
*/
|
|
23
|
-
function recordFlag(ctx, name, record) {
|
|
24
|
-
const key = flagsKey(name);
|
|
25
|
-
const existing = ctx.state.get(key);
|
|
26
|
-
const flags = Array.isArray(existing) ? existing : [];
|
|
27
|
-
flags.push(record);
|
|
28
|
-
ctx.state.set(key, flags);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Run a phase's detector array over `text`, in registration order, and fold
|
|
32
|
-
* the verdicts into a single {@link PhaseOutcome}.
|
|
33
|
-
*
|
|
34
|
-
* **Short-circuit.** The first non-`allow`/non-`flag` verdict (a `redact` or
|
|
35
|
-
* `block`) decides the outcome and stops the fold — outer detectors never run
|
|
36
|
-
* after one objects, matching the install-array ordering. `flag` verdicts are
|
|
37
|
-
* recorded into `ctx.state` and the fold continues (allow-but-annotate).
|
|
38
|
-
*
|
|
39
|
-
* **Phase-aware redact downgrade.** A `redact` verdict is only honoured where
|
|
40
|
-
* the seam supports rewrite-and-continue:
|
|
41
|
-
* - `"output"` — `trip.after` may return a replacement `ModelResponse`, so the
|
|
42
|
-
* rewritten text is threaded out.
|
|
43
|
-
* - `"input"` — the core `trip.before` hook can only short-circuit (return a
|
|
44
|
-
* response) or throw; it has **no** rewrite-and-continue seam, so an input
|
|
45
|
-
* `redact` is downgraded to a `block` rather than silently passing the
|
|
46
|
-
* un-redacted prompt through. (Documented on {@link GuardOptions.input}.)
|
|
47
|
-
* - `"tool"` — silently rewriting tool arguments changes the call's
|
|
48
|
-
* side-effects unpredictably, so a tool `redact` is downgraded to a `block`
|
|
49
|
-
* (`tool-arg-redaction-unsupported`) rather than mutating what the tool runs.
|
|
50
|
-
*
|
|
51
|
-
* **Fail-open on detector fault.** A detector's `check()` rejecting is an
|
|
52
|
-
* infrastructure fault, not a content violation — it is recorded as a `flag`
|
|
53
|
-
* (`<detector>.error`) and the fold continues, so a moderation-API outage does
|
|
54
|
-
* not abort every agent run.
|
|
55
|
-
*/
|
|
56
|
-
async function runDetectors(detectors, text, phase, ctx, name) {
|
|
57
|
-
for (const detector of detectors) {
|
|
58
|
-
let verdict;
|
|
59
|
-
try {
|
|
60
|
-
verdict = await detector.check(text, {
|
|
61
|
-
phase,
|
|
62
|
-
ctx
|
|
63
|
-
});
|
|
64
|
-
} catch (error) {
|
|
65
|
-
recordFlag(ctx, name, {
|
|
66
|
-
detector: detector.name,
|
|
67
|
-
phase,
|
|
68
|
-
reason: `detector "${detector.name}" threw: ${error instanceof Error ? error.message : String(error)}`,
|
|
69
|
-
matches: []
|
|
70
|
-
});
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
if (verdict.type === "allow") continue;
|
|
74
|
-
if (verdict.type === "flag") {
|
|
75
|
-
recordFlag(ctx, name, {
|
|
76
|
-
detector: detector.name,
|
|
77
|
-
phase,
|
|
78
|
-
reason: verdict.reason,
|
|
79
|
-
matches: verdict.matches
|
|
80
|
-
});
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
if (verdict.type === "redact") {
|
|
84
|
-
if (phase === "output") return {
|
|
85
|
-
type: "redact",
|
|
86
|
-
text: verdict.text
|
|
87
|
-
};
|
|
88
|
-
return {
|
|
89
|
-
type: "block",
|
|
90
|
-
reason: phase === "tool" ? "tool-arg-redaction-unsupported" : verdict.reason,
|
|
91
|
-
matches: verdict.matches,
|
|
92
|
-
escalate: false
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
type: "block",
|
|
97
|
-
reason: verdict.reason,
|
|
98
|
-
matches: verdict.matches,
|
|
99
|
-
escalate: verdict.escalate ?? false
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return { type: "allow" };
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Realize a `block` outcome: fire the escalation seam (when the verdict asked
|
|
106
|
-
* for it) and throw the typed {@link GuardrailViolationError} on `result.error`.
|
|
107
|
-
* Never returns — always throws.
|
|
108
|
-
*
|
|
109
|
-
* The core `GuardrailViolationError.phase` is typed `"input" | "output"`; this
|
|
110
|
-
* package widens the surfaced `phase` with `"tool"` (a source-compatible third
|
|
111
|
-
* value), so the construction site asserts the wider value through the options
|
|
112
|
-
* shape the error already accepts at runtime.
|
|
113
|
-
*/
|
|
114
|
-
async function block(outcome, phase, ctx, name, escalation) {
|
|
115
|
-
if (outcome.escalate) await escalation?.onBlock?.({
|
|
116
|
-
phase,
|
|
117
|
-
reason: outcome.reason,
|
|
118
|
-
matches: outcome.matches,
|
|
119
|
-
ctx
|
|
120
|
-
});
|
|
121
|
-
throw new GuardrailViolationError(`guardrail "${name}" rejected ${phase} — ${outcome.reason}`, {
|
|
122
|
-
phase,
|
|
123
|
-
reason: outcome.reason,
|
|
124
|
-
guardrail: name
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Build the composed **guardrail middleware** (surfaced as
|
|
129
|
-
* `ai.guardrail(options)`) — one {@link AgentMiddleware} that runs the
|
|
130
|
-
* configured detectors at three hook points and maps each
|
|
131
|
-
* {@link GuardrailVerdict} onto the pipeline's throw / return / record
|
|
132
|
-
* mechanics:
|
|
133
|
-
*
|
|
134
|
-
* - **`input`** detectors run at `trip.before` over the outbound prompt
|
|
135
|
-
* (`extractUserText(ctx.messages)`). `block` / `flag` only — the core
|
|
136
|
-
* `trip.before` seam cannot rewrite-and-continue, so a `redact` verdict here
|
|
137
|
-
* is downgraded to a `block`.
|
|
138
|
-
* - **`output`** detectors run at `trip.after` over `response.content`. Full
|
|
139
|
-
* `allow` / `redact` / `block` / `flag` support — a `redact` returns a
|
|
140
|
-
* replacement `ModelResponse` with the rewritten `content`.
|
|
141
|
-
* - **`tool`** detectors run at `tool.before` over `JSON.stringify(toolArgs)`.
|
|
142
|
-
* `block` / `flag`; a `redact` is downgraded to a `block`
|
|
143
|
-
* (`tool-arg-redaction-unsupported`). Scoped to `toolNames` via the core
|
|
144
|
-
* `forTool(toolNames, mw)` helper when set.
|
|
145
|
-
*
|
|
146
|
-
* **Verdict → action.** Detectors run in registration order; the first
|
|
147
|
-
* `redact` / `block` short-circuits the phase. `block` throws a
|
|
148
|
-
* {@link GuardrailViolationError} on `result.error` (never out of the
|
|
149
|
-
* pipeline); `flag` records the match into `ctx.state` under `<name>.flags`
|
|
150
|
-
* and continues; a `{ type: "block", escalate: true }` verdict awaits
|
|
151
|
-
* `escalation.onBlock` before throwing. A detector that *throws* is treated as
|
|
152
|
-
* an infra fault and fails open (recorded as a flag, run continues).
|
|
153
|
-
*
|
|
154
|
-
* @param options - The {@link GuardOptions}: per-phase detector arrays,
|
|
155
|
-
* optional `toolNames` scope, `escalation` seam, and `name` override.
|
|
156
|
-
* @returns One {@link AgentMiddleware} to pass into `ai.agent({ middleware: [...] })`.
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* const policy = ai.guardrail({
|
|
160
|
-
* name: "compliance",
|
|
161
|
-
* input: [ai.guardrail.injection({ onMatch: "block" })],
|
|
162
|
-
* output: [ai.guardrail.pii({ onMatch: "redact", mask: "[REDACTED:{label}]" })],
|
|
163
|
-
* tool: [ai.guardrail.pii({ onMatch: "block" })],
|
|
164
|
-
* toolNames: ["send_email"],
|
|
165
|
-
* escalation: { async onBlock(e) { await reviewQueue.enqueue(e); } },
|
|
166
|
-
* });
|
|
167
|
-
*
|
|
168
|
-
* const agent = ai.agent({ model, tools: [sendEmail], middleware: [policy] });
|
|
169
|
-
*/
|
|
170
|
-
function guard(options) {
|
|
171
|
-
const name = options.name ?? DEFAULT_NAME;
|
|
172
|
-
const input = options.input ?? [];
|
|
173
|
-
const output = options.output ?? [];
|
|
174
|
-
const tool = options.tool ?? [];
|
|
175
|
-
const escalation = options.escalation;
|
|
176
|
-
const middleware = {
|
|
177
|
-
name,
|
|
178
|
-
trip: {
|
|
179
|
-
async before(ctx) {
|
|
180
|
-
if (input.length === 0) return;
|
|
181
|
-
const prompt = extractUserText(ctx.messages);
|
|
182
|
-
if (!prompt) return;
|
|
183
|
-
const outcome = await runDetectors(input, prompt, "input", ctx, name);
|
|
184
|
-
if (outcome.type === "block") await block(outcome, "input", ctx, name, escalation);
|
|
185
|
-
},
|
|
186
|
-
async after(ctx, response) {
|
|
187
|
-
if (output.length === 0 || !response.content) return;
|
|
188
|
-
const outcome = await runDetectors(output, response.content, "output", ctx, name);
|
|
189
|
-
if (outcome.type === "block") await block(outcome, "output", ctx, name, escalation);
|
|
190
|
-
if (outcome.type === "redact") return {
|
|
191
|
-
...response,
|
|
192
|
-
content: outcome.text
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
if (tool.length > 0) middleware.tool = { async before(ctx) {
|
|
198
|
-
const args = JSON.stringify(ctx.request.input);
|
|
199
|
-
if (!args) return;
|
|
200
|
-
const outcome = await runDetectors(tool, args, "tool", ctx, name);
|
|
201
|
-
if (outcome.type === "block") await block(outcome, "tool", ctx, name, escalation);
|
|
202
|
-
} };
|
|
203
|
-
if (options.toolNames !== void 0 && middleware.tool) return forTool(options.toolNames, middleware);
|
|
204
|
-
return middleware;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
//#endregion
|
|
208
|
-
export { guard };
|
|
209
|
-
//# sourceMappingURL=guard.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guard.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/guard/guard.ts"],"sourcesContent":["import { extractUserText } from \"../middleware/utils/extract-user-text\";\nimport { forTool } from \"../middleware/helpers/for-tool\";\nimport type { AgentMiddleware } from \"../contracts/middleware/middleware.contract\";\nimport type {\n MiddlewareToolContext,\n MiddlewareTripContext,\n} from \"../contracts/middleware/middleware-context.type\";\nimport type { ModelResponse } from \"../contracts/model.contract\";\nimport type {\n GuardOptions,\n GuardrailDetector,\n GuardrailEscalation,\n GuardrailMatch,\n GuardrailPhase,\n GuardrailVerdict,\n} from \"./contracts\";\nimport { GuardrailViolationError } from \"./errors\";\n\n/** Default middleware name when the caller supplies none. */\nconst DEFAULT_NAME = \"guardrail\";\n\n/**\n * The `ctx.state` key under which a guard records its `flag` verdicts. The\n * value is an append-only array of {@link FlagRecord}, namespaced by the\n * middleware name so two guards on the same agent never collide and a\n * downstream observer (panoptic, the caller) can read the annotations\n * post-run.\n */\nfunction flagsKey(name: string): string {\n return `${name}.flags`;\n}\n\n/**\n * One flagged match recorded into `ctx.state`. Mirrors the\n * {@link GuardrailVerdict} `flag` shape plus the phase it fired at, so an\n * observer can reconstruct *what* tripped *where* without re-running the\n * detector.\n */\nexport interface FlagRecord {\n /** The detector that produced the flag. */\n readonly detector: string;\n /** Where the detector was running. */\n readonly phase: GuardrailPhase;\n /** The detector's human-readable reason. */\n readonly reason: string;\n /** The matches the detector recorded. */\n readonly matches: readonly GuardrailMatch[];\n}\n\n/**\n * Append a `flag` record onto the namespaced `ctx.state` array, creating it\n * on first write. Never throws — recording is best-effort annotation.\n */\nfunction recordFlag(\n ctx: MiddlewareTripContext,\n name: string,\n record: FlagRecord,\n): void {\n const key = flagsKey(name);\n const existing = ctx.state.get(key);\n const flags = Array.isArray(existing) ? (existing as FlagRecord[]) : [];\n\n flags.push(record);\n ctx.state.set(key, flags);\n}\n\n/**\n * The outcome of folding a phase's detector array — what the hook should do\n * with the inspected text once every detector has had its say.\n *\n * - `allow` — no detector objected; the hook continues untouched.\n * - `redact` — a detector returned rewritten `text`; the hook substitutes it\n * (output / tool phases only — see {@link runDetectors}).\n * - `block` — a detector rejected; the hook throws a\n * {@link GuardrailViolationError} carrying `reason` / `matches` / `escalate`.\n *\n * `flag` verdicts never reach this type — they are recorded into `ctx.state`\n * as a side effect inside {@link runDetectors} and do not short-circuit the\n * fold, so a flagged-but-otherwise-clean run resolves to `allow`.\n */\ntype PhaseOutcome =\n | { readonly type: \"allow\" }\n | { readonly type: \"redact\"; readonly text: string }\n | {\n readonly type: \"block\";\n readonly reason: string;\n readonly matches?: readonly GuardrailMatch[];\n readonly escalate: boolean;\n };\n\n/**\n * Run a phase's detector array over `text`, in registration order, and fold\n * the verdicts into a single {@link PhaseOutcome}.\n *\n * **Short-circuit.** The first non-`allow`/non-`flag` verdict (a `redact` or\n * `block`) decides the outcome and stops the fold — outer detectors never run\n * after one objects, matching the install-array ordering. `flag` verdicts are\n * recorded into `ctx.state` and the fold continues (allow-but-annotate).\n *\n * **Phase-aware redact downgrade.** A `redact` verdict is only honoured where\n * the seam supports rewrite-and-continue:\n * - `\"output\"` — `trip.after` may return a replacement `ModelResponse`, so the\n * rewritten text is threaded out.\n * - `\"input\"` — the core `trip.before` hook can only short-circuit (return a\n * response) or throw; it has **no** rewrite-and-continue seam, so an input\n * `redact` is downgraded to a `block` rather than silently passing the\n * un-redacted prompt through. (Documented on {@link GuardOptions.input}.)\n * - `\"tool\"` — silently rewriting tool arguments changes the call's\n * side-effects unpredictably, so a tool `redact` is downgraded to a `block`\n * (`tool-arg-redaction-unsupported`) rather than mutating what the tool runs.\n *\n * **Fail-open on detector fault.** A detector's `check()` rejecting is an\n * infrastructure fault, not a content violation — it is recorded as a `flag`\n * (`<detector>.error`) and the fold continues, so a moderation-API outage does\n * not abort every agent run.\n */\nasync function runDetectors(\n detectors: readonly GuardrailDetector[],\n text: string,\n phase: GuardrailPhase,\n ctx: MiddlewareTripContext,\n name: string,\n): Promise<PhaseOutcome> {\n for (const detector of detectors) {\n let verdict: GuardrailVerdict;\n\n try {\n verdict = await detector.check(text, { phase, ctx });\n } catch (error) {\n // Infra fault — fail open: record and continue, never abort the run.\n recordFlag(ctx, name, {\n detector: detector.name,\n phase,\n reason: `detector \"${detector.name}\" threw: ${\n error instanceof Error ? error.message : String(error)\n }`,\n matches: [],\n });\n\n continue;\n }\n\n if (verdict.type === \"allow\") {\n continue;\n }\n\n if (verdict.type === \"flag\") {\n recordFlag(ctx, name, {\n detector: detector.name,\n phase,\n reason: verdict.reason,\n matches: verdict.matches,\n });\n\n continue;\n }\n\n if (verdict.type === \"redact\") {\n if (phase === \"output\") {\n return { type: \"redact\", text: verdict.text };\n }\n\n // Input / tool phases have no safe rewrite-and-continue seam — downgrade\n // to a block so the un-redacted text is never threaded through.\n const reason =\n phase === \"tool\"\n ? \"tool-arg-redaction-unsupported\"\n : verdict.reason;\n\n return {\n type: \"block\",\n reason,\n matches: verdict.matches,\n escalate: false,\n };\n }\n\n // verdict.type === \"block\"\n return {\n type: \"block\",\n reason: verdict.reason,\n matches: verdict.matches,\n escalate: verdict.escalate ?? false,\n };\n }\n\n return { type: \"allow\" };\n}\n\n/**\n * Realize a `block` outcome: fire the escalation seam (when the verdict asked\n * for it) and throw the typed {@link GuardrailViolationError} on `result.error`.\n * Never returns — always throws.\n *\n * The core `GuardrailViolationError.phase` is typed `\"input\" | \"output\"`; this\n * package widens the surfaced `phase` with `\"tool\"` (a source-compatible third\n * value), so the construction site asserts the wider value through the options\n * shape the error already accepts at runtime.\n */\nasync function block(\n outcome: Extract<PhaseOutcome, { type: \"block\" }>,\n phase: GuardrailPhase,\n ctx: MiddlewareTripContext,\n name: string,\n escalation: GuardrailEscalation | undefined,\n): Promise<never> {\n if (outcome.escalate) {\n await escalation?.onBlock?.({\n phase,\n reason: outcome.reason,\n matches: outcome.matches,\n ctx,\n });\n }\n\n throw new GuardrailViolationError(\n `guardrail \"${name}\" rejected ${phase} — ${outcome.reason}`,\n {\n // `phase` is widened to include \"tool\"; the error carries it verbatim.\n phase: phase as \"input\" | \"output\",\n reason: outcome.reason,\n guardrail: name,\n },\n );\n}\n\n/**\n * Build the composed **guardrail middleware** (surfaced as\n * `ai.guardrail(options)`) — one {@link AgentMiddleware} that runs the\n * configured detectors at three hook points and maps each\n * {@link GuardrailVerdict} onto the pipeline's throw / return / record\n * mechanics:\n *\n * - **`input`** detectors run at `trip.before` over the outbound prompt\n * (`extractUserText(ctx.messages)`). `block` / `flag` only — the core\n * `trip.before` seam cannot rewrite-and-continue, so a `redact` verdict here\n * is downgraded to a `block`.\n * - **`output`** detectors run at `trip.after` over `response.content`. Full\n * `allow` / `redact` / `block` / `flag` support — a `redact` returns a\n * replacement `ModelResponse` with the rewritten `content`.\n * - **`tool`** detectors run at `tool.before` over `JSON.stringify(toolArgs)`.\n * `block` / `flag`; a `redact` is downgraded to a `block`\n * (`tool-arg-redaction-unsupported`). Scoped to `toolNames` via the core\n * `forTool(toolNames, mw)` helper when set.\n *\n * **Verdict → action.** Detectors run in registration order; the first\n * `redact` / `block` short-circuits the phase. `block` throws a\n * {@link GuardrailViolationError} on `result.error` (never out of the\n * pipeline); `flag` records the match into `ctx.state` under `<name>.flags`\n * and continues; a `{ type: \"block\", escalate: true }` verdict awaits\n * `escalation.onBlock` before throwing. A detector that *throws* is treated as\n * an infra fault and fails open (recorded as a flag, run continues).\n *\n * @param options - The {@link GuardOptions}: per-phase detector arrays,\n * optional `toolNames` scope, `escalation` seam, and `name` override.\n * @returns One {@link AgentMiddleware} to pass into `ai.agent({ middleware: [...] })`.\n *\n * @example\n * const policy = ai.guardrail({\n * name: \"compliance\",\n * input: [ai.guardrail.injection({ onMatch: \"block\" })],\n * output: [ai.guardrail.pii({ onMatch: \"redact\", mask: \"[REDACTED:{label}]\" })],\n * tool: [ai.guardrail.pii({ onMatch: \"block\" })],\n * toolNames: [\"send_email\"],\n * escalation: { async onBlock(e) { await reviewQueue.enqueue(e); } },\n * });\n *\n * const agent = ai.agent({ model, tools: [sendEmail], middleware: [policy] });\n */\nexport function guard(options: GuardOptions): AgentMiddleware {\n const name = options.name ?? DEFAULT_NAME;\n const input = options.input ?? [];\n const output = options.output ?? [];\n const tool = options.tool ?? [];\n const escalation = options.escalation;\n\n const middleware: AgentMiddleware = {\n name,\n trip: {\n async before(ctx: MiddlewareTripContext): Promise<void> {\n if (input.length === 0) {\n return;\n }\n\n const prompt = extractUserText(ctx.messages);\n\n if (!prompt) {\n return;\n }\n\n const outcome = await runDetectors(input, prompt, \"input\", ctx, name);\n\n if (outcome.type === \"block\") {\n await block(outcome, \"input\", ctx, name, escalation);\n }\n\n // `allow` (incl. any recorded flags) and a downgraded-but-impossible\n // input `redact` (already mapped to block above) fall through — the\n // real model call proceeds with the un-mutated prompt.\n },\n async after(\n ctx: MiddlewareTripContext,\n response: ModelResponse,\n ): Promise<void | ModelResponse> {\n if (output.length === 0 || !response.content) {\n return;\n }\n\n const outcome = await runDetectors(\n output,\n response.content,\n \"output\",\n ctx,\n name,\n );\n\n if (outcome.type === \"block\") {\n await block(outcome, \"output\", ctx, name, escalation);\n }\n\n if (outcome.type === \"redact\") {\n // `trip.after` may return a replacement response — thread the\n // rewritten content back so the caller never sees the original.\n return { ...response, content: outcome.text };\n }\n\n return;\n },\n },\n };\n\n // Only declare the `tool` hook map when there are tool detectors — an empty\n // `tool` array would otherwise make `forTool` scoping a no-op cost.\n if (tool.length > 0) {\n middleware.tool = {\n async before(ctx: MiddlewareToolContext): Promise<void> {\n const args = JSON.stringify(ctx.request.input);\n\n if (!args) {\n return;\n }\n\n const outcome = await runDetectors(tool, args, \"tool\", ctx, name);\n\n if (outcome.type === \"block\") {\n await block(outcome, \"tool\", ctx, name, escalation);\n }\n\n // A tool `redact` is downgraded to `block` inside `runDetectors`, so\n // `redact` is unreachable here; `allow`/`flag` fall through and the\n // real tool dispatch proceeds.\n },\n };\n }\n\n // Scope the `tool` hooks to the named tools when requested — `forTool`\n // leaves `trip` hooks untouched, so input/output detectors still fire for\n // every trip regardless of which tool is being dispatched.\n if (options.toolNames !== undefined && middleware.tool) {\n return forTool(options.toolNames, middleware);\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;AAmBA,MAAM,eAAe;;;;;;;;AASrB,SAAS,SAAS,MAAsB;CACtC,OAAO,GAAG,KAAK;AACjB;;;;;AAuBA,SAAS,WACP,KACA,MACA,QACM;CACN,MAAM,MAAM,SAAS,IAAI;CACzB,MAAM,WAAW,IAAI,MAAM,IAAI,GAAG;CAClC,MAAM,QAAQ,MAAM,QAAQ,QAAQ,IAAK,WAA4B,CAAC;CAEtE,MAAM,KAAK,MAAM;CACjB,IAAI,MAAM,IAAI,KAAK,KAAK;AAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,eAAe,aACb,WACA,MACA,OACA,KACA,MACuB;CACvB,KAAK,MAAM,YAAY,WAAW;EAChC,IAAI;EAEJ,IAAI;GACF,UAAU,MAAM,SAAS,MAAM,MAAM;IAAE;IAAO;GAAI,CAAC;EACrD,SAAS,OAAO;GAEd,WAAW,KAAK,MAAM;IACpB,UAAU,SAAS;IACnB;IACA,QAAQ,aAAa,SAAS,KAAK,WACjC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;IAEvD,SAAS,CAAC;GACZ,CAAC;GAED;EACF;EAEA,IAAI,QAAQ,SAAS,SACnB;EAGF,IAAI,QAAQ,SAAS,QAAQ;GAC3B,WAAW,KAAK,MAAM;IACpB,UAAU,SAAS;IACnB;IACA,QAAQ,QAAQ;IAChB,SAAS,QAAQ;GACnB,CAAC;GAED;EACF;EAEA,IAAI,QAAQ,SAAS,UAAU;GAC7B,IAAI,UAAU,UACZ,OAAO;IAAE,MAAM;IAAU,MAAM,QAAQ;GAAK;GAU9C,OAAO;IACL,MAAM;IACN,QANA,UAAU,SACN,mCACA,QAAQ;IAKZ,SAAS,QAAQ;IACjB,UAAU;GACZ;EACF;EAGA,OAAO;GACL,MAAM;GACN,QAAQ,QAAQ;GAChB,SAAS,QAAQ;GACjB,UAAU,QAAQ,YAAY;EAChC;CACF;CAEA,OAAO,EAAE,MAAM,QAAQ;AACzB;;;;;;;;;;;AAYA,eAAe,MACb,SACA,OACA,KACA,MACA,YACgB;CAChB,IAAI,QAAQ,UACV,MAAM,YAAY,UAAU;EAC1B;EACA,QAAQ,QAAQ;EAChB,SAAS,QAAQ;EACjB;CACF,CAAC;CAGH,MAAM,IAAI,wBACR,cAAc,KAAK,aAAa,MAAM,KAAK,QAAQ,UACnD;EAES;EACP,QAAQ,QAAQ;EAChB,WAAW;CACb,CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,MAAM,SAAwC;CAC5D,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,QAAQ,QAAQ,SAAS,CAAC;CAChC,MAAM,SAAS,QAAQ,UAAU,CAAC;CAClC,MAAM,OAAO,QAAQ,QAAQ,CAAC;CAC9B,MAAM,aAAa,QAAQ;CAE3B,MAAM,aAA8B;EAClC;EACA,MAAM;GACJ,MAAM,OAAO,KAA2C;IACtD,IAAI,MAAM,WAAW,GACnB;IAGF,MAAM,SAAS,gBAAgB,IAAI,QAAQ;IAE3C,IAAI,CAAC,QACH;IAGF,MAAM,UAAU,MAAM,aAAa,OAAO,QAAQ,SAAS,KAAK,IAAI;IAEpE,IAAI,QAAQ,SAAS,SACnB,MAAM,MAAM,SAAS,SAAS,KAAK,MAAM,UAAU;GAMvD;GACA,MAAM,MACJ,KACA,UAC+B;IAC/B,IAAI,OAAO,WAAW,KAAK,CAAC,SAAS,SACnC;IAGF,MAAM,UAAU,MAAM,aACpB,QACA,SAAS,SACT,UACA,KACA,IACF;IAEA,IAAI,QAAQ,SAAS,SACnB,MAAM,MAAM,SAAS,UAAU,KAAK,MAAM,UAAU;IAGtD,IAAI,QAAQ,SAAS,UAGnB,OAAO;KAAE,GAAG;KAAU,SAAS,QAAQ;IAAK;GAIhD;EACF;CACF;CAIA,IAAI,KAAK,SAAS,GAChB,WAAW,OAAO,EAChB,MAAM,OAAO,KAA2C;EACtD,MAAM,OAAO,KAAK,UAAU,IAAI,QAAQ,KAAK;EAE7C,IAAI,CAAC,MACH;EAGF,MAAM,UAAU,MAAM,aAAa,MAAM,MAAM,QAAQ,KAAK,IAAI;EAEhE,IAAI,QAAQ,SAAS,SACnB,MAAM,MAAM,SAAS,QAAQ,KAAK,MAAM,UAAU;CAMtD,EACF;CAMF,IAAI,QAAQ,cAAc,UAAa,WAAW,MAChD,OAAO,QAAQ,QAAQ,WAAW,UAAU;CAG9C,OAAO;AACT"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { injection } from "./detectors/injection.mjs";
|
|
2
|
-
import { pii } from "./detectors/pii.mjs";
|
|
3
|
-
import { topic } from "./detectors/topic.mjs";
|
|
4
|
-
import { moderation } from "./detectors/moderation.mjs";
|
|
5
|
-
import "./detectors/index.mjs";
|
|
6
|
-
import { guard } from "./guard.mjs";
|
|
7
|
-
|
|
8
|
-
//#region ../@warlock.js/ai/src/guard/guardrail.ts
|
|
9
|
-
/**
|
|
10
|
-
* The `ai.guardrail` value: the {@link guard} factory with the detector
|
|
11
|
-
* factories assigned onto it. Built once and shared.
|
|
12
|
-
*/
|
|
13
|
-
const guardrail = Object.assign(guard, {
|
|
14
|
-
pii,
|
|
15
|
-
topic,
|
|
16
|
-
injection,
|
|
17
|
-
moderation
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { guardrail };
|
|
22
|
-
//# sourceMappingURL=guardrail.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"guardrail.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/guard/guardrail.ts"],"sourcesContent":["import type { AgentMiddleware } from \"../contracts/middleware/middleware.contract\";\nimport type {\n GuardOptions,\n GuardrailDetector,\n InjectionDetectorOptions,\n OpenAiModerationOptions,\n PiiDetectorOptions,\n TopicFilterOptions,\n} from \"./contracts\";\nimport { injection, moderation, pii, topic } from \"./detectors\";\nimport { guard } from \"./guard\";\n\n/**\n * The callable `ai.guardrail` surface — the {@link guard} factory with the\n * built-in detector factories attached as methods, so the whole guardrail\n * vocabulary lives under one name:\n *\n * - `ai.guardrail(options)` — build the composed middleware.\n * - `ai.guardrail.pii(o?)` / `.topic(o)` / `.injection(o?)` / `.moderation(o?)`\n * — build a detector to pass into the factory's `input` / `output` / `tool`\n * arrays.\n *\n * @example\n * const policy = ai.guardrail({\n * output: [ai.guardrail.pii({ onMatch: \"redact\" })],\n * });\n */\nexport interface GuardrailFactory {\n /** Build the composed guardrail {@link AgentMiddleware}. */\n (options: GuardOptions): AgentMiddleware;\n /** Built-in PII detector (regex + dictionary, zero runtime dep). */\n pii(options?: PiiDetectorOptions): GuardrailDetector;\n /** Built-in topic filter (allow / deny string | RegExp lists). */\n topic(options: TopicFilterOptions): GuardrailDetector;\n /** Built-in jailbreak / prompt-injection marker detector. */\n injection(options?: InjectionDetectorOptions): GuardrailDetector;\n /** Optional OpenAI-backed moderation detector (lazy `openai` peer). */\n moderation(options?: OpenAiModerationOptions): GuardrailDetector;\n}\n\n/**\n * The `ai.guardrail` value: the {@link guard} factory with the detector\n * factories assigned onto it. Built once and shared.\n */\nexport const guardrail: GuardrailFactory = Object.assign(guard, {\n pii,\n topic,\n injection,\n moderation,\n});\n\n// `ai.guardrail` is registered natively on the core `ai` object (in `../ai`),\n// now that the guardrail suite ships inside `@warlock.js/ai`.\n"],"mappings":";;;;;;;;;;;;AA4CA,MAAa,YAA8B,OAAO,OAAO,OAAO;CAC9D;CACA;CACA;CACA;AACF,CAAC"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { AIError } from "../errors/ai-error.mjs";
|
|
2
|
-
|
|
3
|
-
//#region ../@warlock.js/ai/src/human/errors.ts
|
|
4
|
-
/**
|
|
5
|
-
* A durable approval handler suspended the run rather than denying the
|
|
6
|
-
* call.
|
|
7
|
-
*
|
|
8
|
-
* **Role.** The sentinel a durable {@link import("./contracts").ApprovalHandler}
|
|
9
|
-
* throws after persisting a
|
|
10
|
-
* {@link import("./contracts").PendingInterrupt}. The approval
|
|
11
|
-
* middleware recognizes its own sentinel (an `instanceof` check) and
|
|
12
|
-
* re-throws so the agent run unwinds; the dispatch records it as a failed
|
|
13
|
-
* tool call carrying this typed error. The caller reads
|
|
14
|
-
* `error.interruptId` off the surfaced `result.error`, surfaces it to the
|
|
15
|
-
* reviewer, and later calls `ai.human.resume(...)`.
|
|
16
|
-
*
|
|
17
|
-
* Surfaced via `result.error` like every other `AIError` — the middleware
|
|
18
|
-
* never lets it escape `execute()`.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* if (result.error instanceof InterruptSuspendedError) {
|
|
22
|
-
* await notifyReviewer(result.error.interruptId);
|
|
23
|
-
* return { status: "awaiting-approval", interruptId: result.error.interruptId };
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
var InterruptSuspendedError = class extends AIError {
|
|
27
|
-
constructor(message, options) {
|
|
28
|
-
super("INTERRUPT_SUSPENDED", message, options);
|
|
29
|
-
this.name = "InterruptSuspendedError";
|
|
30
|
-
this.interruptId = options.interruptId;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* A human rejected a gated tool call.
|
|
35
|
-
*
|
|
36
|
-
* **Role.** The typed result of an `{ type: "reject", reason }` decision.
|
|
37
|
-
* The approval middleware throws it from `tool.before`; the agent
|
|
38
|
-
* dispatch records a failed tool call and writes a `role: "tool"`
|
|
39
|
-
* message carrying `reason`, so the **next trip lets the model
|
|
40
|
-
* self-correct** — exactly the existing tool-error feedback path.
|
|
41
|
-
*
|
|
42
|
-
* Surfaced via `result.error` like every other `AIError`.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* if (result.error instanceof ApprovalRejectedError) {
|
|
46
|
-
* logAudit(`${result.error.toolName} rejected: ${result.error.reason}`);
|
|
47
|
-
* }
|
|
48
|
-
*/
|
|
49
|
-
var ApprovalRejectedError = class extends AIError {
|
|
50
|
-
constructor(message, options) {
|
|
51
|
-
super("APPROVAL_REJECTED", message, options);
|
|
52
|
-
this.name = "ApprovalRejectedError";
|
|
53
|
-
this.reason = options.reason;
|
|
54
|
-
this.toolName = options.toolName;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
|
-
export { ApprovalRejectedError, InterruptSuspendedError };
|
|
60
|
-
//# sourceMappingURL=errors.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../../@warlock.js/ai/src/human/errors.ts"],"sourcesContent":["import { AIError, type AIErrorOptions } from \"../errors/ai-error\";\nimport type { AIErrorCode } from \"../errors/error-code.type\";\n\n/**\n * Stable, machine-readable codes this package raises.\n *\n * `@warlock.js/ai`'s `AIErrorCode` is a closed union that (by design)\n * does not enumerate satellite-package codes, and this package must not\n * modify the core union. These codes are therefore declared locally and\n * narrowed into the base `AIError` `code` slot at the single `super(...)`\n * call — the runtime string is exactly what a consumer branches on via\n * `error.code`, identical to every other `AIError`.\n */\nexport type HumanErrorCode = \"INTERRUPT_SUSPENDED\" | \"APPROVAL_REJECTED\";\n\n/**\n * Payload for {@link InterruptSuspendedError}. `interruptId` is the key a\n * later `ai.human.resume(interruptId, decision)` call uses to replay the\n * decision against the persisted interrupt.\n */\nexport type InterruptSuspendedErrorOptions = AIErrorOptions & {\n /** Id of the persisted interrupt awaiting a decision. */\n interruptId: string;\n};\n\n/**\n * A durable approval handler suspended the run rather than denying the\n * call.\n *\n * **Role.** The sentinel a durable {@link import(\"./contracts\").ApprovalHandler}\n * throws after persisting a\n * {@link import(\"./contracts\").PendingInterrupt}. The approval\n * middleware recognizes its own sentinel (an `instanceof` check) and\n * re-throws so the agent run unwinds; the dispatch records it as a failed\n * tool call carrying this typed error. The caller reads\n * `error.interruptId` off the surfaced `result.error`, surfaces it to the\n * reviewer, and later calls `ai.human.resume(...)`.\n *\n * Surfaced via `result.error` like every other `AIError` — the middleware\n * never lets it escape `execute()`.\n *\n * @example\n * if (result.error instanceof InterruptSuspendedError) {\n * await notifyReviewer(result.error.interruptId);\n * return { status: \"awaiting-approval\", interruptId: result.error.interruptId };\n * }\n */\nexport class InterruptSuspendedError extends AIError {\n /** Id of the persisted interrupt awaiting a human decision. */\n public readonly interruptId: string;\n\n public constructor(message: string, options: InterruptSuspendedErrorOptions) {\n super(\"INTERRUPT_SUSPENDED\" as AIErrorCode, message, options);\n\n this.name = \"InterruptSuspendedError\";\n this.interruptId = options.interruptId;\n }\n}\n\n/**\n * Payload for {@link ApprovalRejectedError}. `reason` is the reviewer's\n * explanation, surfaced to the model on the next trip so it can\n * self-correct; `toolName` names the call that was rejected.\n */\nexport type ApprovalRejectedErrorOptions = AIErrorOptions & {\n /** The reviewer's explanation for rejecting the call. */\n reason: string;\n /** Name of the tool whose call was rejected. */\n toolName: string;\n};\n\n/**\n * A human rejected a gated tool call.\n *\n * **Role.** The typed result of an `{ type: \"reject\", reason }` decision.\n * The approval middleware throws it from `tool.before`; the agent\n * dispatch records a failed tool call and writes a `role: \"tool\"`\n * message carrying `reason`, so the **next trip lets the model\n * self-correct** — exactly the existing tool-error feedback path.\n *\n * Surfaced via `result.error` like every other `AIError`.\n *\n * @example\n * if (result.error instanceof ApprovalRejectedError) {\n * logAudit(`${result.error.toolName} rejected: ${result.error.reason}`);\n * }\n */\nexport class ApprovalRejectedError extends AIError {\n /** The reviewer's explanation for rejecting the call. */\n public readonly reason: string;\n\n /** Name of the tool whose call was rejected. */\n public readonly toolName: string;\n\n public constructor(message: string, options: ApprovalRejectedErrorOptions) {\n super(\"APPROVAL_REJECTED\" as AIErrorCode, message, options);\n\n this.name = \"ApprovalRejectedError\";\n this.reason = options.reason;\n this.toolName = options.toolName;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,IAAa,0BAAb,cAA6C,QAAQ;CAInD,AAAO,YAAY,SAAiB,SAAyC;EAC3E,MAAM,uBAAsC,SAAS,OAAO;EAE5D,KAAK,OAAO;EACZ,KAAK,cAAc,QAAQ;CAC7B;AACF;;;;;;;;;;;;;;;;;AA8BA,IAAa,wBAAb,cAA2C,QAAQ;CAOjD,AAAO,YAAY,SAAiB,SAAuC;EACzE,MAAM,qBAAoC,SAAS,OAAO;EAE1D,KAAK,OAAO;EACZ,KAAK,SAAS,QAAQ;EACtB,KAAK,WAAW,QAAQ;CAC1B;AACF"}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { generateRunId } from "../utils/generate-run-id.mjs";
|
|
2
|
-
import { ApprovalRejectedError, InterruptSuspendedError } from "./errors.mjs";
|
|
3
|
-
import { evaluatePolicy } from "./policy.mjs";
|
|
4
|
-
import { takeSeededDecision } from "./resume-seed.mjs";
|
|
5
|
-
|
|
6
|
-
//#region ../@warlock.js/ai/src/human/human-approval.ts
|
|
7
|
-
/** Default middleware name when {@link HumanApprovalOptions.name} is omitted. */
|
|
8
|
-
const DEFAULT_NAME = "human-approval";
|
|
9
|
-
/** Zero usage for a synthetic, no-LLM-spend short-circuit result. */
|
|
10
|
-
const ZERO_USAGE = Object.freeze({
|
|
11
|
-
input: 0,
|
|
12
|
-
output: 0,
|
|
13
|
-
total: 0
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Derive the read-only {@link PolicyContext} the policy + request are
|
|
17
|
-
* built from out of the wrapping {@link MiddlewareToolContext}.
|
|
18
|
-
*/
|
|
19
|
-
function toPolicyContext(ctx) {
|
|
20
|
-
return {
|
|
21
|
-
toolName: ctx.tool.name,
|
|
22
|
-
toolDescription: ctx.tool.description,
|
|
23
|
-
args: ctx.request.input,
|
|
24
|
-
agentName: ctx.agent.name,
|
|
25
|
-
tripIndex: ctx.tripIndex,
|
|
26
|
-
sessionId: ctx.options?.sessionId
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Generate a stable, unique id for a pending interrupt. Shaped
|
|
31
|
-
* `${agentName}.${sessionId ?? "nosession"}.${tripIndex}.${random}` so a
|
|
32
|
-
* reviewer can eyeball the originating run, while the trailing random
|
|
33
|
-
* segment guarantees per-call uniqueness even within one trip.
|
|
34
|
-
*/
|
|
35
|
-
function makeInterruptId(ctx) {
|
|
36
|
-
const session = ctx.options?.sessionId ?? "nosession";
|
|
37
|
-
const random = generateRunId("interrupt");
|
|
38
|
-
return `${ctx.agent.name}.${session}.${ctx.tripIndex}.${random}`;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Build the {@link ApprovalRequest} a human rules on, from the tool
|
|
42
|
-
* context and the policy-derived tags.
|
|
43
|
-
*/
|
|
44
|
-
function buildRequest(ctx, interruptId, tags) {
|
|
45
|
-
return {
|
|
46
|
-
interruptId,
|
|
47
|
-
toolName: ctx.tool.name,
|
|
48
|
-
toolDescription: ctx.tool.description,
|
|
49
|
-
args: ctx.request.input,
|
|
50
|
-
context: {
|
|
51
|
-
agentName: ctx.agent.name,
|
|
52
|
-
tripIndex: ctx.tripIndex,
|
|
53
|
-
sessionId: ctx.options?.sessionId,
|
|
54
|
-
originalInput: ctx.input,
|
|
55
|
-
...tags ? { tags } : {}
|
|
56
|
-
},
|
|
57
|
-
requestedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Synthesize a failed {@link ToolInvokeResult} carrying a typed error.
|
|
62
|
-
*
|
|
63
|
-
* The approval middleware returns this from `tool.before` to
|
|
64
|
-
* **short-circuit** the real tool without throwing: the pipeline treats a
|
|
65
|
-
* defined return as the tool's result, the agent records a failed
|
|
66
|
-
* `ToolCall`, and the model sees `{ error }` on the next trip — exactly
|
|
67
|
-
* the existing tool-error feedback path. Used for both `reject`
|
|
68
|
-
* (`ApprovalRejectedError`) and durable suspend (`InterruptSuspendedError`).
|
|
69
|
-
*/
|
|
70
|
-
function failedResult(error, toolName) {
|
|
71
|
-
const runId = generateRunId("tool");
|
|
72
|
-
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
73
|
-
return {
|
|
74
|
-
error,
|
|
75
|
-
usage: ZERO_USAGE,
|
|
76
|
-
report: {
|
|
77
|
-
runId,
|
|
78
|
-
rootRunId: runId,
|
|
79
|
-
name: toolName,
|
|
80
|
-
type: "tool",
|
|
81
|
-
status: "failed",
|
|
82
|
-
startedAt: nowIso,
|
|
83
|
-
endedAt: nowIso,
|
|
84
|
-
duration: 0,
|
|
85
|
-
usage: ZERO_USAGE,
|
|
86
|
-
children: []
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Human-in-the-loop approval gate for an agent's tool calls — the
|
|
92
|
-
* middleware behind `ai.human.approval(options)`.
|
|
93
|
-
*
|
|
94
|
-
* **Role.** Pauses *before a specific tool call* and routes it to a human
|
|
95
|
-
* who can **approve** (run the real tool unchanged), **reject** (the model
|
|
96
|
-
* sees a typed error and self-corrects), or **edit** (run the tool with
|
|
97
|
-
* reviewer-replaced args). The dangerous subset is chosen by an
|
|
98
|
-
* {@link import("./contracts").InterruptPolicy} (allowlist / denylist /
|
|
99
|
-
* predicate); every other call passes through untouched.
|
|
100
|
-
*
|
|
101
|
-
* **One hook.** Declares only `tool.before`. On each tool dispatch it:
|
|
102
|
-
* 1. evaluates the policy — not gated → returns `void`, the real tool runs;
|
|
103
|
-
* 2. for a gated call, builds an {@link ApprovalRequest} and calls the
|
|
104
|
-
* {@link import("./contracts").ApprovalHandler};
|
|
105
|
-
* 3. applies the returned {@link ApprovalDecision}:
|
|
106
|
-
* - `approve` → returns `void`, the real tool runs;
|
|
107
|
-
* - `reject` → short-circuits a failed `ToolInvokeResult` carrying an
|
|
108
|
-
* {@link ApprovalRejectedError} (the reviewer's `reason` reaches the
|
|
109
|
-
* model);
|
|
110
|
-
* - `edit` → rewrites `ctx.request.input` to the reviewer's args and
|
|
111
|
-
* returns `void`, so the real tool runs with the edited args (schema
|
|
112
|
-
* validation still applies — bad edits surface as a tool error).
|
|
113
|
-
*
|
|
114
|
-
* **Durable mode.** When a `store` is configured and the handler throws
|
|
115
|
-
* {@link InterruptSuspendedError} (after persisting the interrupt
|
|
116
|
-
* out-of-band), the middleware catches its **own** sentinel and
|
|
117
|
-
* short-circuits a failed result carrying it — so the caller reads
|
|
118
|
-
* `result.error.interruptId` and later calls
|
|
119
|
-
* `ai.human.resume(interruptId, decision)`. The middleware **never throws
|
|
120
|
-
* out of the pipeline**: every outcome (skip, approve, reject, edit,
|
|
121
|
-
* suspend) returns normally; only a *handler bug* (a non-sentinel throw)
|
|
122
|
-
* propagates, and even then the agent dispatch funnels it onto
|
|
123
|
-
* `result.error` — `execute()` still never throws.
|
|
124
|
-
*
|
|
125
|
-
* @param options - Policy, handler, optional durable store, optional name.
|
|
126
|
-
* @returns An {@link AgentMiddleware} declaring a single `tool.before` hook.
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* const support = ai.agent({
|
|
130
|
-
* model,
|
|
131
|
-
* tools: [refundCustomer],
|
|
132
|
-
* middleware: [
|
|
133
|
-
* humanApproval({
|
|
134
|
-
* policy: { type: "allowlist", tools: ["refundCustomer"], tags: () => ["money"] },
|
|
135
|
-
* handler: async (req) => ui.prompt(req), // { type: "edit", args: { amount: 5 } }
|
|
136
|
-
* }),
|
|
137
|
-
* ],
|
|
138
|
-
* });
|
|
139
|
-
*/
|
|
140
|
-
function humanApproval(options) {
|
|
141
|
-
const name = options.name ?? DEFAULT_NAME;
|
|
142
|
-
const { policy, handler } = options;
|
|
143
|
-
return {
|
|
144
|
-
name,
|
|
145
|
-
tool: { async before(ctx) {
|
|
146
|
-
const verdict = evaluatePolicy(policy, toPolicyContext(ctx));
|
|
147
|
-
if (!verdict.requiresApproval) return;
|
|
148
|
-
const request = buildRequest(ctx, makeInterruptId(ctx), verdict.tags);
|
|
149
|
-
const seeded = takeSeededDecision(ctx.agent.name);
|
|
150
|
-
let decision;
|
|
151
|
-
if (seeded !== void 0) decision = seeded;
|
|
152
|
-
else try {
|
|
153
|
-
decision = await handler(request);
|
|
154
|
-
} catch (thrown) {
|
|
155
|
-
if (thrown instanceof InterruptSuspendedError) return failedResult(thrown, ctx.tool.name);
|
|
156
|
-
throw thrown;
|
|
157
|
-
}
|
|
158
|
-
if (decision.type === "approve") return;
|
|
159
|
-
if (decision.type === "reject") return failedResult(new ApprovalRejectedError(`Tool call "${ctx.tool.name}" rejected by reviewer — ${decision.reason}`, {
|
|
160
|
-
reason: decision.reason,
|
|
161
|
-
toolName: ctx.tool.name
|
|
162
|
-
}), ctx.tool.name);
|
|
163
|
-
ctx.request.input = decision.args;
|
|
164
|
-
} }
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
//#endregion
|
|
169
|
-
export { humanApproval };
|
|
170
|
-
//# sourceMappingURL=human-approval.mjs.map
|