@theoremjs/agents 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +276 -995
- package/esm/mod.d.ts +33 -19
- package/esm/mod.js +18 -11
- package/esm/src/cli/commands/bench.js +36 -14
- package/esm/src/cli/commands/detect-compile.d.ts +17 -0
- package/esm/src/cli/commands/detect-compile.js +22 -0
- package/esm/src/cli/commands/eval.d.ts +3 -3
- package/esm/src/cli/commands/fuzz-canary.js +55 -16
- package/esm/src/cli/commands/profile.js +4 -4
- package/esm/src/cli/commands/run.d.ts +2 -2
- package/esm/src/cli/commands/run.js +1 -1
- package/esm/src/cli/commands/test.d.ts +4 -3
- package/esm/src/cli/commands/test.js +2 -2
- package/esm/src/cli/index.js +9 -9
- package/esm/src/cli/matrix/fixtures.js +25 -30
- package/esm/src/evals/attachments.d.ts +1 -0
- package/esm/src/evals/attachments.js +4 -2
- package/esm/src/evals/breakdown.d.ts +2 -0
- package/esm/src/evals/breakdown.js +1 -0
- package/esm/src/evals/graders/answer.d.ts +3 -0
- package/esm/src/evals/graders/answer.js +1 -0
- package/esm/src/evals/graders/code.d.ts +7 -31
- package/esm/src/evals/graders/code.js +4 -25
- package/esm/src/evals/graders/judge.d.ts +4 -0
- package/esm/src/evals/graders/judge.js +7 -5
- package/esm/src/evals/graders/latency.d.ts +1 -0
- package/esm/src/evals/graders/latency.js +3 -2
- package/esm/src/evals/graders/live.d.ts +3 -0
- package/esm/src/evals/graders/live.js +2 -0
- package/esm/src/evals/graders/media.js +1 -2
- package/esm/src/evals/graders/shared.js +1 -1
- package/esm/src/evals/graders/transcript.d.ts +2 -0
- package/esm/src/evals/graders/transcript.js +5 -3
- package/esm/src/evals/mod.d.ts +1 -9
- package/esm/src/evals/mod.js +1 -9
- package/esm/src/evals/record.d.ts +6 -0
- package/esm/src/evals/record.js +4 -2
- package/esm/src/evals/rubrics/mod.d.ts +1 -1
- package/esm/src/evals/rubrics/mod.js +1 -1
- package/esm/src/evals/rubrics/mustache.js +1 -1
- package/esm/src/evals/rubrics/types.js +1 -1
- package/esm/src/evals/run.d.ts +9 -52
- package/esm/src/evals/run.js +12 -46
- package/esm/src/evals/suite.d.ts +12 -3
- package/esm/src/evals/suite.js +9 -4
- package/esm/src/evals/summary.d.ts +3 -0
- package/esm/src/evals/summary.js +1 -0
- package/esm/src/evals/trial.d.ts +3 -16
- package/esm/src/evals/trial.js +7 -30
- package/esm/src/evals/types.d.ts +30 -121
- package/esm/src/evals/types.js +3 -16
- package/esm/src/evals/verdict.d.ts +5 -0
- package/esm/src/evals/verdict.js +4 -1
- package/esm/src/guardrails/boundaries.d.ts +41 -0
- package/esm/src/guardrails/boundaries.js +103 -0
- package/esm/src/guardrails/canary-gate.d.ts +1 -0
- package/esm/src/guardrails/canary.d.ts +49 -15
- package/esm/src/guardrails/canary.js +103 -30
- package/esm/src/guardrails/compile-egress.d.ts +6 -5
- package/esm/src/guardrails/compile-egress.js +6 -5
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +3 -1
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +4 -2
- package/esm/src/guardrails/corpus/fuzz-inbound.js +14 -17
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +2 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +4 -2
- package/esm/src/guardrails/corpus/live-attacks.d.ts +2 -0
- package/esm/src/guardrails/corpus/live-attacks.js +6 -1
- package/esm/src/guardrails/corpus/mod.d.ts +1 -1
- package/esm/src/guardrails/corpus/secrets.d.ts +3 -3
- package/esm/src/guardrails/corpus/secrets.js +2 -2
- package/esm/src/guardrails/corpus/strings.d.ts +1 -1
- package/esm/src/guardrails/corpus/strings.js +1 -1
- package/esm/src/guardrails/corpus/types.d.ts +5 -1
- package/esm/src/guardrails/credential-rules.d.ts +36 -0
- package/esm/src/guardrails/credential-rules.js +3001 -0
- package/esm/src/guardrails/credential-scan.d.ts +45 -0
- package/esm/src/guardrails/credential-scan.js +172 -0
- package/esm/src/guardrails/destinations.d.ts +45 -0
- package/esm/src/guardrails/destinations.js +234 -0
- package/esm/src/guardrails/detect-at.d.ts +107 -0
- package/esm/src/guardrails/detect-at.js +434 -0
- package/esm/src/guardrails/detect-reply.d.ts +61 -0
- package/esm/src/guardrails/detect-reply.js +95 -0
- package/esm/src/guardrails/detect-stream.d.ts +33 -0
- package/esm/src/guardrails/detect-stream.js +77 -0
- package/esm/src/guardrails/detectors.d.ts +216 -0
- package/esm/src/guardrails/detectors.js +503 -0
- package/esm/src/guardrails/egress-automata.d.ts +4 -6
- package/esm/src/guardrails/egress-automata.js +24095 -4572
- package/esm/src/guardrails/egress-compiler.d.ts +38 -16
- package/esm/src/guardrails/egress-compiler.js +254 -60
- package/esm/src/guardrails/egress-patterns.d.ts +4 -2
- package/esm/src/guardrails/egress-patterns.js +6 -2
- package/esm/src/guardrails/egress-stream.d.ts +54 -36
- package/esm/src/guardrails/egress-stream.js +253 -124
- package/esm/src/guardrails/egress-urls.d.ts +6 -3
- package/esm/src/guardrails/egress-urls.js +14 -22
- package/esm/src/guardrails/egress.d.ts +26 -86
- package/esm/src/guardrails/egress.js +59 -309
- package/esm/src/guardrails/error.d.ts +13 -8
- package/esm/src/guardrails/error.js +23 -18
- package/esm/src/guardrails/event-schemas.d.ts +46 -3
- package/esm/src/guardrails/event-schemas.js +12 -5
- package/esm/src/guardrails/events.d.ts +5 -1
- package/esm/src/guardrails/events.js +4 -1
- package/esm/src/guardrails/hints.d.ts +14 -0
- package/esm/src/guardrails/hints.js +57 -0
- package/esm/src/guardrails/hits.d.ts +7 -1
- package/esm/src/guardrails/hits.js +12 -1
- package/esm/src/guardrails/host-patterns.d.ts +85 -0
- package/esm/src/guardrails/host-patterns.js +173 -0
- package/esm/src/guardrails/injection-patterns.d.ts +6 -1
- package/esm/src/guardrails/injection-patterns.js +33 -1
- package/esm/src/guardrails/injection-reversed.d.ts +9 -0
- package/esm/src/guardrails/injection-reversed.js +49 -0
- package/esm/src/guardrails/injection.d.ts +17 -1
- package/esm/src/guardrails/injection.js +259 -36
- package/esm/src/guardrails/labels.d.ts +40 -0
- package/esm/src/guardrails/labels.js +874 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +9 -8
- package/esm/src/guardrails/live-outbound-gate.js +100 -107
- package/esm/src/guardrails/mod.d.ts +29 -21
- package/esm/src/guardrails/mod.js +18 -13
- package/esm/src/guardrails/network.d.ts +4 -0
- package/esm/src/guardrails/network.js +21 -19
- package/esm/src/guardrails/normalize.d.ts +15 -1
- package/esm/src/guardrails/normalize.js +34 -1
- package/esm/src/guardrails/policy.d.ts +2 -17
- package/esm/src/guardrails/policy.js +12 -41
- package/esm/src/guardrails/progressive-yield.d.ts +65 -24
- package/esm/src/guardrails/progressive-yield.js +191 -147
- package/esm/src/guardrails/prompt-echo.d.ts +4 -2
- package/esm/src/guardrails/prompt-echo.js +87 -6
- package/esm/src/guardrails/quota.d.ts +1 -0
- package/esm/src/guardrails/quota.js +1 -1
- package/esm/src/guardrails/rules.d.ts +20 -29
- package/esm/src/guardrails/rules.js +23 -30
- package/esm/src/guardrails/sanitize.d.ts +32 -15
- package/esm/src/guardrails/sanitize.js +100 -124
- package/esm/src/guardrails/sensitive-groups.d.ts +21 -0
- package/esm/src/guardrails/sensitive-groups.js +12 -0
- package/esm/src/guardrails/sensitive.d.ts +16 -23
- package/esm/src/guardrails/sensitive.js +168 -47
- package/esm/src/guardrails/serialize.d.ts +1 -0
- package/esm/src/guardrails/testing.d.ts +4 -2
- package/esm/src/guardrails/testing.js +4 -2
- package/esm/src/guardrails/theorem-error.d.ts +4 -1
- package/esm/src/guardrails/theorem-error.js +3 -2
- package/esm/src/guardrails/thought-guard.d.ts +34 -13
- package/esm/src/guardrails/thought-guard.js +264 -64
- package/esm/src/guardrails/tool-directives.d.ts +29 -10
- package/esm/src/guardrails/tool-directives.js +133 -47
- package/esm/src/guardrails/tool-leak.d.ts +26 -0
- package/esm/src/guardrails/tool-leak.js +45 -0
- package/esm/src/guardrails/tool-result.d.ts +45 -14
- package/esm/src/guardrails/tool-result.js +94 -70
- package/esm/src/guardrails/types.d.ts +79 -71
- package/esm/src/guardrails/types.js +11 -7
- package/esm/src/host/client-turn.d.ts +29 -2
- package/esm/src/host/client-turn.js +46 -4
- package/esm/src/host/mint-trace.d.ts +1 -0
- package/esm/src/host/mint-trace.js +3 -2
- package/esm/src/host/mod.d.ts +2 -2
- package/esm/src/host/mod.js +1 -1
- package/esm/src/host/readStreamingJsonStringField.js +2 -43
- package/esm/src/host/reply.d.ts +6 -0
- package/esm/src/host/reply.js +7 -1
- package/esm/src/interface/blocks.d.ts +3 -0
- package/esm/src/interface/blocks.js +84 -14
- package/esm/src/interface/composer-actions.d.ts +4 -0
- package/esm/src/interface/composer-actions.js +5 -3
- package/esm/src/interface/draft.d.ts +6 -0
- package/esm/src/interface/draft.js +22 -11
- package/esm/src/interface/from-profile.d.ts +13 -1
- package/esm/src/interface/from-profile.js +66 -31
- package/esm/src/interface/history.d.ts +9 -3
- package/esm/src/interface/history.js +33 -24
- package/esm/src/interface/inputs.d.ts +1 -0
- package/esm/src/interface/inputs.js +3 -0
- package/esm/src/interface/mod.d.ts +4 -2
- package/esm/src/interface/mod.js +3 -2
- package/esm/src/interface/models.d.ts +7 -0
- package/esm/src/interface/models.js +5 -0
- package/esm/src/interface/pending.d.ts +9 -0
- package/esm/src/interface/pending.js +9 -3
- package/esm/src/interface/profile-interface.js +54 -40
- package/esm/src/interface/session.d.ts +12 -5
- package/esm/src/interface/session.js +17 -10
- package/esm/src/interface/stop.d.ts +13 -0
- package/esm/src/interface/stop.js +28 -0
- package/esm/src/interface/tool-calls.d.ts +14 -2
- package/esm/src/interface/tool-calls.js +64 -10
- package/esm/src/interface/tool-invoke.d.ts +2 -0
- package/esm/src/interface/tool-invoke.js +3 -1
- package/esm/src/interface/tool-media.d.ts +2 -0
- package/esm/src/interface/tool-media.js +2 -1
- package/esm/src/interface/types.d.ts +105 -40
- package/esm/src/interface/types.js +1 -0
- package/esm/src/kernel/api-catalog.d.ts +85 -0
- package/esm/src/kernel/api-catalog.js +229 -0
- package/esm/src/kernel/auth/crypto.d.ts +7 -2
- package/esm/src/kernel/auth/crypto.js +12 -10
- package/esm/src/kernel/auth/oauth.d.ts +2 -1
- package/esm/src/kernel/auth/oauth.js +23 -22
- package/esm/src/kernel/auth/typed-secret.js +2 -2
- package/esm/src/kernel/auth/types.d.ts +13 -0
- package/esm/src/kernel/checkpoint.d.ts +43 -0
- package/esm/src/kernel/checkpoint.js +58 -0
- package/esm/src/kernel/default-scope.d.ts +43 -5
- package/esm/src/kernel/default-scope.js +54 -5
- package/esm/src/kernel/engine/call-trace.d.ts +19 -0
- package/esm/src/kernel/engine/call-trace.js +29 -0
- package/esm/src/kernel/engine/compaction.d.ts +6 -5
- package/esm/src/kernel/engine/compaction.js +12 -11
- package/esm/src/kernel/engine/decision.d.ts +10 -8
- package/esm/src/kernel/engine/decision.js +173 -146
- package/esm/src/kernel/engine/embedding.d.ts +8 -0
- package/esm/src/kernel/engine/embedding.js +118 -0
- package/esm/src/kernel/engine/live-inbound.d.ts +14 -4
- package/esm/src/kernel/engine/live-inbound.js +36 -11
- package/esm/src/kernel/engine/live-ingress.d.ts +6 -0
- package/esm/src/kernel/engine/live-ingress.js +6 -1
- package/esm/src/kernel/engine/repair.js +12 -12
- package/esm/src/kernel/engine/runner/gates.d.ts +2 -2
- package/esm/src/kernel/engine/runner/gates.js +287 -101
- package/esm/src/kernel/engine/runner/mod.d.ts +19 -5
- package/esm/src/kernel/engine/runner/mod.js +107 -56
- package/esm/src/kernel/engine/runner/nested.d.ts +32 -0
- package/esm/src/kernel/engine/runner/nested.js +134 -0
- package/esm/src/kernel/engine/runner/schema-validation.d.ts +24 -3
- package/esm/src/kernel/engine/runner/schema-validation.js +78 -4
- package/esm/src/kernel/engine/runner/stages.d.ts +1 -1
- package/esm/src/kernel/engine/runner/stages.js +1 -8
- package/esm/src/kernel/engine/runner/state.d.ts +33 -12
- package/esm/src/kernel/engine/runner/state.js +11 -1
- package/esm/src/kernel/engine/runner/step-order.d.ts +27 -0
- package/esm/src/kernel/engine/runner/step-order.js +165 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +2 -2
- package/esm/src/kernel/engine/runner/steps.js +328 -169
- package/esm/src/kernel/engine/runner/stream.d.ts +42 -11
- package/esm/src/kernel/engine/runner/stream.js +197 -46
- package/esm/src/kernel/engine/runner/usage.d.ts +5 -5
- package/esm/src/kernel/engine/runner/usage.js +12 -14
- package/esm/src/kernel/engine/session/mod.d.ts +8 -6
- package/esm/src/kernel/engine/session/mod.js +360 -129
- package/esm/src/kernel/engine/session/session-trace.d.ts +10 -10
- package/esm/src/kernel/engine/session/session-trace.js +41 -30
- package/esm/src/kernel/engine/token-estimate.d.ts +10 -64
- package/esm/src/kernel/engine/token-estimate.js +14 -194
- package/esm/src/kernel/engine/tool-trace.d.ts +3 -3
- package/esm/src/kernel/engine/tool-trace.js +2 -1
- package/esm/src/kernel/engine/turn-trace.d.ts +8 -7
- package/esm/src/kernel/engine/turn-trace.js +28 -36
- package/esm/src/kernel/engine/usage.d.ts +6 -0
- package/esm/src/kernel/engine/usage.js +17 -0
- package/esm/src/kernel/interaction-parts.d.ts +3 -0
- package/esm/src/kernel/interaction-parts.js +18 -0
- package/esm/src/kernel/json.d.ts +10 -0
- package/esm/src/kernel/json.js +3 -0
- package/esm/src/kernel/mod.d.ts +38 -11
- package/esm/src/kernel/mod.js +22 -7
- package/esm/src/kernel/profile-graph.d.ts +11 -6
- package/esm/src/kernel/profile-graph.js +14 -7
- package/esm/src/kernel/profile-presence.d.ts +10 -1
- package/esm/src/kernel/profile-presence.js +90 -75
- package/esm/src/kernel/profile-scope.d.ts +7 -3
- package/esm/src/kernel/profile-scope.js +67 -55
- package/esm/src/kernel/protocols/binding.d.ts +65 -0
- package/esm/src/kernel/protocols/binding.js +125 -0
- package/esm/src/kernel/protocols/limits.d.ts +15 -0
- package/esm/src/kernel/protocols/limits.js +28 -0
- package/esm/src/kernel/protocols/mod.d.ts +5 -0
- package/esm/src/kernel/protocols/mod.js +5 -0
- package/esm/src/kernel/protocols/prices.d.ts +36 -0
- package/esm/src/kernel/protocols/prices.js +37 -0
- package/esm/src/kernel/protocols/protocol.d.ts +253 -0
- package/esm/src/kernel/protocols/protocol.js +253 -0
- package/esm/src/kernel/protocols/provider.d.ts +108 -0
- package/esm/src/kernel/protocols/provider.js +143 -0
- package/esm/src/kernel/protocols/runtime.d.ts +55 -0
- package/esm/src/kernel/protocols/runtime.js +534 -0
- package/esm/src/kernel/provider-budget.d.ts +32 -0
- package/esm/src/kernel/provider-budget.js +262 -0
- package/esm/src/kernel/provider-dispatch.d.ts +13 -0
- package/esm/src/kernel/provider-dispatch.js +36 -0
- package/esm/src/kernel/provider-live.d.ts +7 -0
- package/esm/src/kernel/provider-live.js +189 -0
- package/esm/src/kernel/provider-runtime.d.ts +57 -0
- package/esm/src/kernel/provider-runtime.js +524 -0
- package/esm/src/kernel/registry/attachments.d.ts +15 -4
- package/esm/src/kernel/registry/attachments.js +31 -22
- package/esm/src/kernel/registry/catalog.d.ts +6 -0
- package/esm/src/kernel/registry/catalog.js +9 -2
- package/esm/src/kernel/registry/embedding-rules.d.ts +28 -0
- package/esm/src/kernel/registry/embedding-rules.js +66 -0
- package/esm/src/kernel/registry/ingress.d.ts +6 -2
- package/esm/src/kernel/registry/ingress.js +55 -10
- package/esm/src/kernel/registry/kernel-registry.d.ts +3 -0
- package/esm/src/kernel/registry/kernel-registry.js +9 -2
- package/esm/src/kernel/registry/profile-outputs.js +4 -1
- package/esm/src/kernel/registry/profiles.d.ts +38 -14
- package/esm/src/kernel/registry/profiles.js +280 -205
- package/esm/src/kernel/registry/provider-request.d.ts +3 -3
- package/esm/src/kernel/registry/provider-request.js +5 -13
- package/esm/src/kernel/registry/resolve.d.ts +4 -1
- package/esm/src/kernel/registry/resolve.js +59 -58
- package/esm/src/kernel/registry/schemas.d.ts +3 -0
- package/esm/src/kernel/registry/schemas.js +3 -1
- package/esm/src/kernel/registry/slot-fill.d.ts +7 -0
- package/esm/src/kernel/registry/slot-fill.js +22 -0
- package/esm/src/kernel/registry/system-prompt.js +7 -8
- package/esm/src/kernel/registry/vault.d.ts +14 -13
- package/esm/src/kernel/registry/vault.js +1 -14
- package/esm/src/kernel/schema.d.ts +100 -46
- package/esm/src/kernel/schema.js +499 -257
- package/esm/src/kernel/scope.d.ts +12 -5
- package/esm/src/kernel/scope.js +23 -3
- package/esm/src/kernel/stages.d.ts +38 -3
- package/esm/src/kernel/stages.js +82 -39
- package/esm/src/kernel/stop.d.ts +29 -6
- package/esm/src/kernel/stop.js +16 -4
- package/esm/src/kernel/system-parts.js +6 -6
- package/esm/src/kernel/tools/activity-label.d.ts +12 -6
- package/esm/src/kernel/tools/activity-label.js +258 -32
- package/esm/src/kernel/tools/agent.d.ts +66 -0
- package/esm/src/kernel/tools/agent.js +212 -0
- package/esm/src/kernel/tools/coordinate.d.ts +4 -0
- package/esm/src/kernel/tools/coordinate.js +165 -0
- package/esm/src/kernel/tools/events.d.ts +21 -6
- package/esm/src/kernel/tools/events.js +53 -18
- package/esm/src/kernel/tools/execute.d.ts +47 -11
- package/esm/src/kernel/tools/execute.js +508 -136
- package/esm/src/kernel/tools/gate-answer.d.ts +12 -2
- package/esm/src/kernel/tools/gate-answer.js +17 -6
- package/esm/src/kernel/tools/handler-events.d.ts +45 -0
- package/esm/src/kernel/tools/handler-events.js +106 -0
- package/esm/src/kernel/tools/harness.d.ts +1 -0
- package/esm/src/kernel/tools/harness.js +2 -1
- package/esm/src/kernel/tools/http-limit.d.ts +27 -0
- package/esm/src/kernel/tools/http-limit.js +85 -0
- package/esm/src/kernel/tools/invoke.d.ts +27 -5
- package/esm/src/kernel/tools/invoke.js +223 -70
- package/esm/src/kernel/tools/mcp-sessions.d.ts +4 -1
- package/esm/src/kernel/tools/mcp-sessions.js +13 -8
- package/esm/src/kernel/tools/mod.d.ts +4 -3
- package/esm/src/kernel/tools/mod.js +3 -2
- package/esm/src/kernel/tools/model-text.d.ts +10 -5
- package/esm/src/kernel/tools/model-text.js +18 -12
- package/esm/src/kernel/tools/operation.d.ts +76 -0
- package/esm/src/kernel/tools/operation.js +100 -0
- package/esm/src/kernel/tools/page-answer.d.ts +8 -0
- package/esm/src/kernel/tools/page-answer.js +19 -0
- package/esm/src/kernel/tools/permission.d.ts +11 -2
- package/esm/src/kernel/tools/permission.js +12 -12
- package/esm/src/kernel/tools/project.d.ts +4 -1
- package/esm/src/kernel/tools/project.js +32 -2
- package/esm/src/kernel/tools/registry.d.ts +9 -2
- package/esm/src/kernel/tools/registry.js +69 -10
- package/esm/src/kernel/tools/remote.d.ts +40 -6
- package/esm/src/kernel/tools/remote.js +219 -92
- package/esm/src/kernel/tools/resolve.d.ts +3 -0
- package/esm/src/kernel/tools/resolve.js +12 -4
- package/esm/src/kernel/tools/run.d.ts +28 -0
- package/esm/src/kernel/tools/run.js +86 -0
- package/esm/src/kernel/tools/schema.d.ts +3 -3
- package/esm/src/kernel/tools/schema.js +21 -100
- package/esm/src/kernel/tools/signed-in-fetch.d.ts +2 -1
- package/esm/src/kernel/tools/signed-in-fetch.js +3 -3
- package/esm/src/kernel/tools/stage-run.d.ts +27 -4
- package/esm/src/kernel/tools/stage-run.js +75 -17
- package/esm/src/kernel/tools/types.d.ts +235 -25
- package/esm/src/kernel/tools/unchecked-output.d.ts +14 -0
- package/esm/src/kernel/tools/unchecked-output.js +18 -0
- package/esm/src/kernel/turn-events.d.ts +208 -31
- package/esm/src/kernel/turn-events.js +127 -9
- package/esm/src/kernel/types.d.ts +302 -161
- package/esm/src/kernel/util/base64.d.ts +2 -0
- package/esm/src/kernel/util/base64.js +2 -0
- package/esm/src/kernel/util/partial-json.d.ts +23 -0
- package/esm/src/kernel/util/partial-json.js +128 -0
- package/esm/src/kernel/util/record.d.ts +1 -0
- package/esm/src/kernel/util/record.js +1 -0
- package/esm/src/observability/destinations.d.ts +5 -0
- package/esm/src/observability/destinations.js +7 -2
- package/esm/src/observability/jsonl.d.ts +2 -2
- package/esm/src/observability/jsonl.js +15 -22
- package/esm/src/observability/mod.d.ts +3 -3
- package/esm/src/observability/mod.js +2 -2
- package/esm/src/observability/openinference.d.ts +1 -1
- package/esm/src/observability/openinference.js +3 -3
- package/esm/src/observability/otlp.d.ts +3 -0
- package/esm/src/observability/otlp.js +3 -3
- package/esm/src/observability/phoenix.d.ts +1 -0
- package/esm/src/observability/policy.d.ts +3 -0
- package/esm/src/observability/policy.js +5 -1
- package/esm/src/observability/resolve-policy.js +11 -5
- package/esm/src/observability/spans.d.ts +8 -2
- package/esm/src/observability/spans.js +21 -5
- package/esm/src/observability/trace-catalog.d.ts +19 -2
- package/esm/src/observability/trace-catalog.js +128 -87
- package/esm/src/observability/trace-record.js +22 -17
- package/esm/src/observability/trace-schema.d.ts +3 -0
- package/esm/src/observability/trace-schema.js +1 -1
- package/esm/src/observability/trace-sink.d.ts +1 -0
- package/esm/src/observability/trace-sink.js +1 -1
- package/esm/src/observability/trace-span.d.ts +7 -1
- package/esm/src/observability/trace-span.js +3 -1
- package/esm/src/observability/trace.d.ts +2 -0
- package/esm/src/observability/trace.js +4 -2
- package/esm/src/observability/types.d.ts +35 -11
- package/esm/src/observability/types.js +1 -1
- package/esm/src/presets/google/speech-voices.d.ts +1 -0
- package/esm/src/presets/google-limits.d.ts +1 -0
- package/esm/src/presets/google.d.ts +27 -12
- package/esm/src/presets/google.js +34 -25
- package/esm/src/presets/local.d.ts +26 -0
- package/esm/src/presets/local.js +30 -0
- package/esm/src/presets/mod.d.ts +5 -4
- package/esm/src/presets/mod.js +4 -4
- package/esm/src/presets/openrouter.d.ts +14 -1
- package/esm/src/presets/openrouter.js +19 -1
- package/esm/src/providers/embedding-limits.d.ts +7 -0
- package/esm/src/providers/embedding-limits.js +12 -0
- package/esm/src/providers/gemini/embedding-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/embedding-protocol.js +125 -0
- package/esm/src/providers/gemini/interactions-protocol.d.ts +8 -0
- package/esm/src/providers/gemini/interactions-protocol.js +105 -0
- package/esm/src/providers/gemini/live-protocol.d.ts +3 -0
- package/esm/src/providers/gemini/live-protocol.js +191 -0
- package/esm/src/providers/gemini/prices.d.ts +3 -0
- package/esm/src/providers/gemini/prices.js +63 -0
- package/esm/src/providers/gemini/provider.d.ts +7 -0
- package/esm/src/providers/gemini/provider.js +39 -0
- package/esm/src/providers/google/builtins.d.ts +14 -0
- package/esm/src/providers/google/builtins.js +57 -0
- package/esm/src/providers/google/grounding.d.ts +4 -4
- package/esm/src/providers/google/interactions/framing.d.ts +20 -8
- package/esm/src/providers/google/interactions/framing.js +85 -44
- package/esm/src/providers/google/interactions/steps.d.ts +5 -5
- package/esm/src/providers/google/interactions/steps.js +4 -4
- package/esm/src/providers/google/interactions/stream.d.ts +10 -11
- package/esm/src/providers/google/interactions/stream.js +33 -100
- package/esm/src/providers/google/live/framing.d.ts +15 -5
- package/esm/src/providers/google/live/framing.js +25 -25
- package/esm/src/providers/google/live/stream.d.ts +6 -44
- package/esm/src/providers/google/live/stream.js +3 -209
- package/esm/src/providers/google/urls.d.ts +1 -3
- package/esm/src/providers/google/urls.js +1 -3
- package/esm/src/providers/google/usage.js +2 -2
- package/esm/src/providers/live.d.ts +6 -0
- package/esm/src/providers/live.js +6 -0
- package/esm/src/providers/local/embedding-protocol.d.ts +7 -0
- package/esm/src/providers/local/embedding-protocol.js +60 -0
- package/esm/src/providers/local/provider.d.ts +7 -0
- package/esm/src/providers/local/provider.js +28 -0
- package/esm/src/providers/mod.d.ts +28 -7
- package/esm/src/providers/mod.js +19 -3
- package/esm/src/providers/open-ai/protocol.d.ts +3 -0
- package/esm/src/providers/open-ai/protocol.js +189 -0
- package/esm/src/providers/openrouter/embedding-protocol.d.ts +6 -0
- package/esm/src/providers/openrouter/embedding-protocol.js +86 -0
- package/esm/src/providers/openrouter/image.d.ts +0 -9
- package/esm/src/providers/openrouter/image.js +0 -153
- package/esm/src/providers/openrouter/images-protocol.d.ts +3 -0
- package/esm/src/providers/openrouter/images-protocol.js +82 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/compat.js +6 -6
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +2 -2
- package/esm/src/providers/openrouter/openai/reasoning-state.d.ts +2 -0
- package/esm/src/providers/openrouter/openai/reasoning-state.js +31 -0
- package/esm/src/providers/openrouter/protocol.d.ts +8 -0
- package/esm/src/providers/openrouter/protocol.js +171 -0
- package/esm/src/providers/openrouter/provider.d.ts +10 -0
- package/esm/src/providers/openrouter/provider.js +50 -0
- package/esm/src/providers/shared/carried-tool-files.d.ts +7 -0
- package/esm/src/providers/shared/carried-tool-files.js +43 -0
- package/esm/src/providers/shared/pcm.js +2 -2
- package/esm/src/providers/shared/protocol-events.d.ts +8 -0
- package/esm/src/providers/shared/protocol-events.js +20 -0
- package/esm/src/providers/shared/response-identity.d.ts +2 -2
- package/esm/src/providers/shared/retry.d.ts +17 -0
- package/esm/src/providers/shared/retry.js +90 -0
- package/esm/src/providers/shared/sse.d.ts +0 -4
- package/esm/src/providers/shared/sse.js +50 -36
- package/esm/src/providers/shared/tool-args.d.ts +6 -7
- package/esm/src/providers/shared/tool-args.js +10 -6
- package/esm/src/providers/shared/tool-draft.d.ts +16 -0
- package/esm/src/providers/shared/tool-draft.js +14 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +2 -2
- package/esm/src/providers/shared/upstream-tape.js +1 -1
- package/esm/src/providers/system-one/protocol.d.ts +8 -0
- package/esm/src/providers/system-one/protocol.js +93 -0
- package/esm/src/providers/types.d.ts +48 -16
- package/esm/src/providers/types.js +2 -1
- package/esm/src/providers/typesafe/provider.d.ts +7 -0
- package/esm/src/providers/typesafe/provider.js +24 -0
- package/esm/src/surface/formats.d.ts +19 -1
- package/esm/src/surface/formats.js +68 -29
- package/esm/src/surface/mod.d.ts +4 -2
- package/esm/src/surface/mod.js +4 -2
- package/esm/src/surface/runtime.d.ts +4 -0
- package/esm/src/surface/runtime.js +2 -0
- package/esm/src/surface/tools.d.ts +2 -8
- package/esm/src/surface/tools.js +4 -22
- package/esm/src/surface/types.d.ts +6 -0
- package/package.json +5 -13
- package/esm/src/cli/commands/egress-compile.d.ts +0 -17
- package/esm/src/cli/commands/egress-compile.js +0 -25
- package/esm/src/guardrails/egress-policy.d.ts +0 -27
- package/esm/src/guardrails/egress-policy.js +0 -76
- package/esm/src/guardrails/egress-rules.d.ts +0 -54
- package/esm/src/guardrails/egress-rules.js +0 -49
- package/esm/src/guardrails/lexicon.d.ts +0 -30
- package/esm/src/guardrails/lexicon.js +0 -478
- package/esm/src/kernel/engine/media-probe/audio.d.ts +0 -7
- package/esm/src/kernel/engine/media-probe/audio.js +0 -342
- package/esm/src/kernel/engine/media-probe/bytes.d.ts +0 -6
- package/esm/src/kernel/engine/media-probe/bytes.js +0 -26
- package/esm/src/kernel/engine/media-probe/image.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/image.js +0 -171
- package/esm/src/kernel/engine/media-probe/iso-bmff.d.ts +0 -19
- package/esm/src/kernel/engine/media-probe/iso-bmff.js +0 -48
- package/esm/src/kernel/engine/media-probe/matroska.d.ts +0 -35
- package/esm/src/kernel/engine/media-probe/matroska.js +0 -226
- package/esm/src/kernel/engine/media-probe/mp4.d.ts +0 -22
- package/esm/src/kernel/engine/media-probe/mp4.js +0 -279
- package/esm/src/kernel/engine/media-probe/opus.d.ts +0 -4
- package/esm/src/kernel/engine/media-probe/opus.js +0 -23
- package/esm/src/kernel/engine/media-probe/pdf.d.ts +0 -5
- package/esm/src/kernel/engine/media-probe/pdf.js +0 -117
- package/esm/src/kernel/engine/media-probe/video.d.ts +0 -15
- package/esm/src/kernel/engine/media-probe/video.js +0 -49
- package/esm/src/presets/typesafe.d.ts +0 -2
- package/esm/src/presets/typesafe.js +0 -2
- package/esm/src/providers/create-provider.d.ts +0 -21
- package/esm/src/providers/create-provider.js +0 -90
- package/esm/src/providers/decision/usage.d.ts +0 -3
- package/esm/src/providers/decision/usage.js +0 -25
- package/esm/src/providers/google/interactions/mod.d.ts +0 -2
- package/esm/src/providers/google/interactions/mod.js +0 -2
- package/esm/src/providers/google/keys.d.ts +0 -20
- package/esm/src/providers/google/keys.js +0 -87
- package/esm/src/providers/google/live/mod.d.ts +0 -7
- package/esm/src/providers/google/live/mod.js +0 -7
- package/esm/src/providers/google/live/openapi-schema.d.ts +0 -1
- package/esm/src/providers/google/live/openapi-schema.js +0 -42
- package/esm/src/providers/google/live/session.d.ts +0 -14
- package/esm/src/providers/google/live/session.js +0 -150
- package/esm/src/providers/local/local.d.ts +0 -12
- package/esm/src/providers/local/local.js +0 -186
- package/esm/src/providers/local/mod.d.ts +0 -8
- package/esm/src/providers/local/mod.js +0 -8
- package/esm/src/providers/openrouter/cache-control.d.ts +0 -5
- package/esm/src/providers/openrouter/cache-control.js +0 -4
- package/esm/src/providers/openrouter/chat.d.ts +0 -64
- package/esm/src/providers/openrouter/chat.js +0 -490
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +0 -10
- package/esm/src/providers/openrouter/openai/sdk-messages.js +0 -99
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +0 -3
- package/esm/src/providers/openrouter/resolve-api-key.js +0 -8
- package/esm/src/providers/openrouter/speech.d.ts +0 -18
- package/esm/src/providers/openrouter/speech.js +0 -109
- package/esm/src/providers/probe.d.ts +0 -5
- package/esm/src/providers/probe.js +0 -15
- package/esm/src/providers/shared/builtin-wire.d.ts +0 -4
- package/esm/src/providers/shared/builtin-wire.js +0 -9
- package/esm/src/providers/shared/vault.d.ts +0 -13
- package/esm/src/providers/shared/vault.js +0 -41
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { publicError, TheoremError } from '../../guardrails/error.js';
|
|
3
|
+
import { errorKindSchema, guardrailHit, provenance } from '../../guardrails/event-schemas.js';
|
|
4
|
+
import { jsonObjectSchema, jsonValueSchema } from '../json.js';
|
|
5
|
+
import { interactionPartSchema, TURN_EVENT_SCHEMAS, turnHistoryMessageSchema, } from '../turn-events.js';
|
|
6
|
+
export const savedToolInvocationSchema = z.strictObject({
|
|
7
|
+
accepted: jsonObjectSchema,
|
|
8
|
+
preparedInput: jsonValueSchema,
|
|
9
|
+
});
|
|
10
|
+
export function operationUnavailable() {
|
|
11
|
+
const error = new TheoremError('unavailable', '');
|
|
12
|
+
error.message = publicError(error);
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
export async function toolInvocationHash(value) {
|
|
16
|
+
const ordered = (item) => {
|
|
17
|
+
if (Array.isArray(item))
|
|
18
|
+
return item.map(ordered);
|
|
19
|
+
if (item && typeof item === 'object') {
|
|
20
|
+
return Object.fromEntries(Object.entries(item)
|
|
21
|
+
.filter(([, entry]) => entry !== undefined)
|
|
22
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
23
|
+
.map(([key, entry]) => [key, ordered(entry)]));
|
|
24
|
+
}
|
|
25
|
+
return item;
|
|
26
|
+
};
|
|
27
|
+
const data = jsonValueSchema.parse(ordered(operationWireValue(value)));
|
|
28
|
+
const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(JSON.stringify(data)));
|
|
29
|
+
return Array.from(new Uint8Array(hash), (byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
30
|
+
}
|
|
31
|
+
const terminalSchema = TURN_EVENT_SCHEMAS.tool.transform((event, ctx) => {
|
|
32
|
+
if (event.tool.phase === 'complete' || event.tool.phase === 'error') {
|
|
33
|
+
return { ...event, tool: event.tool };
|
|
34
|
+
}
|
|
35
|
+
ctx.addIssue({ code: 'custom' });
|
|
36
|
+
return z.NEVER;
|
|
37
|
+
});
|
|
38
|
+
export const toolOperationOutcomeSchema = z.strictObject({
|
|
39
|
+
event: terminalSchema,
|
|
40
|
+
effects: z.enum(['not_started', 'completed', 'unknown']),
|
|
41
|
+
replay: z.strictObject({
|
|
42
|
+
modelResult: z
|
|
43
|
+
.strictObject({
|
|
44
|
+
finding: z.string(),
|
|
45
|
+
data: jsonValueSchema.optional(),
|
|
46
|
+
parts: z.array(interactionPartSchema).optional(),
|
|
47
|
+
modelText: z.string().optional(),
|
|
48
|
+
provenance: provenance.optional(),
|
|
49
|
+
suspicious: z.array(guardrailHit).optional(),
|
|
50
|
+
})
|
|
51
|
+
.optional(),
|
|
52
|
+
outputRaw: jsonValueSchema.optional(),
|
|
53
|
+
failure: z
|
|
54
|
+
.strictObject({
|
|
55
|
+
code: z.string(),
|
|
56
|
+
kind: errorKindSchema,
|
|
57
|
+
message: z.string(),
|
|
58
|
+
error: z.string().optional(),
|
|
59
|
+
details: jsonValueSchema.optional(),
|
|
60
|
+
})
|
|
61
|
+
.optional(),
|
|
62
|
+
awaiting: z.boolean().optional(),
|
|
63
|
+
denied: z.literal(true).optional(),
|
|
64
|
+
callNotStarted: z.boolean().optional(),
|
|
65
|
+
aborted: z.union([z.boolean(), z.strictObject({ reason: z.string().optional() })]).optional(),
|
|
66
|
+
pendingInject: z
|
|
67
|
+
.array(z.strictObject({ id: z.string().optional(), messages: z.array(turnHistoryMessageSchema) }))
|
|
68
|
+
.optional(),
|
|
69
|
+
}),
|
|
70
|
+
});
|
|
71
|
+
export function operationWireValue(value) {
|
|
72
|
+
const ancestors = new Set();
|
|
73
|
+
const normalize = (item) => {
|
|
74
|
+
if (!item || typeof item !== 'object')
|
|
75
|
+
return item;
|
|
76
|
+
if (ancestors.has(item))
|
|
77
|
+
throw operationUnavailable();
|
|
78
|
+
const prototype = Object.getPrototypeOf(item);
|
|
79
|
+
if (!Array.isArray(item) && prototype !== Object.prototype && prototype !== null) {
|
|
80
|
+
throw operationUnavailable();
|
|
81
|
+
}
|
|
82
|
+
if (Object.hasOwn(item, '__proto__'))
|
|
83
|
+
throw operationUnavailable();
|
|
84
|
+
ancestors.add(item);
|
|
85
|
+
try {
|
|
86
|
+
if (Array.isArray(item))
|
|
87
|
+
return item.map(normalize);
|
|
88
|
+
const entries = Object.entries(Object.getOwnPropertyDescriptors(item));
|
|
89
|
+
if (entries.some(([, descriptor]) => descriptor.get || descriptor.set))
|
|
90
|
+
throw operationUnavailable();
|
|
91
|
+
return Object.fromEntries(entries
|
|
92
|
+
.filter(([, descriptor]) => descriptor.enumerable && descriptor.value !== undefined)
|
|
93
|
+
.map(([key, descriptor]) => [key, normalize(descriptor.value)]));
|
|
94
|
+
}
|
|
95
|
+
finally {
|
|
96
|
+
ancestors.delete(item);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return jsonValueSchema.parse(normalize(value));
|
|
100
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolHandler } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The handler of a function tool the page answers (`answeredBy: 'page'`): it returns what the
|
|
4
|
+
* page sent for the call (`ctx.page.output`), which the tool's `output` schema then checks. A
|
|
5
|
+
* call the page never answered fails to the model. A call run with no answer at all never
|
|
6
|
+
* reaches here: it is held at a `page` gate.
|
|
7
|
+
*/
|
|
8
|
+
export declare function pageAnswerHandler(name: string): ToolHandler<unknown, unknown>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { labelText } from '../../guardrails/labels.js';
|
|
2
|
+
import { uncheckedOutput } from './unchecked-output.js';
|
|
3
|
+
/**
|
|
4
|
+
* The handler of a function tool the page answers (`answeredBy: 'page'`): it returns what the
|
|
5
|
+
* page sent for the call (`ctx.page.output`), which the tool's `output` schema then checks. A
|
|
6
|
+
* call the page never answered fails to the model. A call run with no answer at all never
|
|
7
|
+
* reaches here: it is held at a `page` gate.
|
|
8
|
+
*/
|
|
9
|
+
export function pageAnswerHandler(name) {
|
|
10
|
+
return (_input, ctx) => {
|
|
11
|
+
const { page } = ctx;
|
|
12
|
+
if (page && 'output' in page)
|
|
13
|
+
return uncheckedOutput(page.output);
|
|
14
|
+
const { labels } = ctx.profile;
|
|
15
|
+
if (page?.timedOut)
|
|
16
|
+
throw new Error(labelText('tool.page_timed_out', {}, labels));
|
|
17
|
+
throw new Error(labelText('tool.page_no_answer', { tool: name }, labels));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ToolAccess } from '../schema.js';
|
|
2
|
+
import type { ToolGateBase } from '../turn-events.js';
|
|
3
|
+
import type { InvokeToolResume, ToolGate, ToolLabels, ToolPermission } from './types.js';
|
|
2
4
|
export declare function isResumeContinuation(resume?: InvokeToolResume): boolean;
|
|
3
5
|
export declare function isGateResumeGranted(resume?: InvokeToolResume): boolean;
|
|
4
6
|
export declare function isGateResumeDenied(resume?: InvokeToolResume): boolean;
|
|
5
7
|
export declare function permissionGranted(toolName: string, sessionPermissions?: string[]): boolean;
|
|
6
|
-
|
|
8
|
+
/** What a gate says about the call beyond its kind: the tool's access and its filled request. */
|
|
9
|
+
export type GateDetails = Pick<ToolGateBase, 'access' | 'request'>;
|
|
10
|
+
/** What an approval card says about a call: what it would do, and what the tool can change. */
|
|
11
|
+
export declare function gateDetails(tool: {
|
|
12
|
+
access: ToolAccess;
|
|
13
|
+
labels?: ToolLabels;
|
|
14
|
+
}, input: unknown): GateDetails;
|
|
15
|
+
export declare function checkPermission(toolName: string, permission: ToolPermission, sessionPermissions?: string[], resume?: InvokeToolResume, details?: GateDetails): ToolGate | null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fillActivityLabel } from './activity-label.js';
|
|
1
2
|
export function isResumeContinuation(resume) {
|
|
2
3
|
return typeof resume?.granted === 'boolean';
|
|
3
4
|
}
|
|
@@ -13,26 +14,25 @@ export function permissionGranted(toolName, sessionPermissions) {
|
|
|
13
14
|
}
|
|
14
15
|
return sessionPermissions.includes('*') || sessionPermissions.includes(toolName);
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
/** What an approval card says about a call: what it would do, and what the tool can change. */
|
|
18
|
+
export function gateDetails(tool, input) {
|
|
19
|
+
const request = fillActivityLabel(tool.labels?.request, { input });
|
|
20
|
+
return { access: tool.access, ...(request ? { request } : {}) };
|
|
21
|
+
}
|
|
22
|
+
export function checkPermission(toolName, permission, sessionPermissions, resume, details) {
|
|
17
23
|
if (permission === 'auto') {
|
|
18
24
|
return null;
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
kind: 'permission',
|
|
26
|
-
tool: toolName,
|
|
27
|
-
permission,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
if (permissionGranted(toolName, sessionPermissions)) {
|
|
26
|
+
const granted = permission === 'always_confirm'
|
|
27
|
+
? resume?.granted === true
|
|
28
|
+
: permissionGranted(toolName, sessionPermissions);
|
|
29
|
+
if (granted) {
|
|
31
30
|
return null;
|
|
32
31
|
}
|
|
33
32
|
return {
|
|
34
33
|
kind: 'permission',
|
|
35
34
|
tool: toolName,
|
|
36
35
|
permission,
|
|
36
|
+
...details,
|
|
37
37
|
};
|
|
38
38
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OwnTools } from '../../guardrails/tool-leak.js';
|
|
1
2
|
import type { Profile, ToolId } from '../types.js';
|
|
2
3
|
import type { ToolRegistry } from './registry.js';
|
|
3
4
|
import type { RegisteredTool } from './types.js';
|
|
@@ -5,4 +6,6 @@ declare function projectTools(tools: ToolRegistry, profile: Profile): Array<Regi
|
|
|
5
6
|
name: ToolId;
|
|
6
7
|
missing: true;
|
|
7
8
|
}>;
|
|
8
|
-
|
|
9
|
+
/** The names of the profile's tools and of their parameters (`GuardrailContext.ownTools`). */
|
|
10
|
+
declare function ownToolsOf(tools: ToolRegistry, profile: Profile): OwnTools | undefined;
|
|
11
|
+
export { ownToolsOf, projectTools };
|
|
@@ -8,7 +8,7 @@ function projectTool(tools, name) {
|
|
|
8
8
|
}
|
|
9
9
|
function builtInToolIds(profile) {
|
|
10
10
|
const seen = new Set();
|
|
11
|
-
if (profile.type === 'host' || profile.type === 'decision') {
|
|
11
|
+
if (profile.type === 'host' || profile.type === 'decision' || profile.type === 'embedding') {
|
|
12
12
|
return [];
|
|
13
13
|
}
|
|
14
14
|
for (const binding of Object.values(profile.models)) {
|
|
@@ -22,4 +22,34 @@ function projectTools(tools, profile) {
|
|
|
22
22
|
const ids = [...profileToolAllow(profile), ...builtInToolIds(profile)];
|
|
23
23
|
return ids.map((name) => projectTool(tools, name));
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
/** Adds the name of every property `schema`, a JSON Schema, declares at any depth. */
|
|
26
|
+
function addParams(schema, params) {
|
|
27
|
+
if (Array.isArray(schema)) {
|
|
28
|
+
for (const each of schema)
|
|
29
|
+
addParams(each, params);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (schema === null || typeof schema !== 'object')
|
|
33
|
+
return;
|
|
34
|
+
const { properties, ...rest } = schema;
|
|
35
|
+
if (properties !== null && typeof properties === 'object') {
|
|
36
|
+
for (const [name, property] of Object.entries(properties)) {
|
|
37
|
+
params.add(name);
|
|
38
|
+
addParams(property, params);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const each of Object.values(rest))
|
|
42
|
+
addParams(each, params);
|
|
43
|
+
}
|
|
44
|
+
/** The names of the profile's tools and of their parameters (`GuardrailContext.ownTools`). */
|
|
45
|
+
function ownToolsOf(tools, profile) {
|
|
46
|
+
const projected = projectTools(tools, profile);
|
|
47
|
+
if (projected.length === 0)
|
|
48
|
+
return undefined;
|
|
49
|
+
const params = new Set();
|
|
50
|
+
for (const tool of projected)
|
|
51
|
+
if ('inputSchema' in tool)
|
|
52
|
+
addParams(tool.inputSchema, params);
|
|
53
|
+
return { names: projected.map(({ name }) => name), params: [...params] };
|
|
54
|
+
}
|
|
55
|
+
export { ownToolsOf, projectTools };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { Profile, ProfileId } from '../types.js';
|
|
1
2
|
import { type McpSessionCache } from './mcp-sessions.js';
|
|
2
3
|
import type { RegisteredTool, ToolDefinitionInput } from './types.js';
|
|
4
|
+
/** The tools a scope has registered: register, look up, and list them, find a profile for agent tools, and reset. */
|
|
3
5
|
interface ToolRegistry {
|
|
4
6
|
/** Replaces a tool of the same name. */
|
|
5
7
|
register<TIn, TOut>(def: ToolDefinitionInput<TIn, TOut>): RegisteredTool<TIn, TOut>;
|
|
@@ -9,12 +11,17 @@ interface ToolRegistry {
|
|
|
9
11
|
require(name: string): RegisteredTool;
|
|
10
12
|
has(name: string): boolean;
|
|
11
13
|
list(): RegisteredTool[];
|
|
14
|
+
/** A profile in this scope, for the agent tools that run one. */
|
|
15
|
+
findProfile(id: ProfileId): Profile | undefined;
|
|
12
16
|
/** Also forgets the MCP sessions. */
|
|
13
17
|
reset(): void;
|
|
14
18
|
/** Sessions for this scope's MCP servers that require one; never shared across scopes. */
|
|
15
19
|
readonly mcpSessions: McpSessionCache;
|
|
16
20
|
}
|
|
17
|
-
/**
|
|
18
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Registration is not synchronized: register a scope's tools before its turns or invokes run.
|
|
23
|
+
* `findProfile` is the scope's profiles, which an agent tool names; without it none registers.
|
|
24
|
+
*/
|
|
25
|
+
declare function createToolRegistry(findProfile?: (id: ProfileId) => Profile | undefined): ToolRegistry;
|
|
19
26
|
export type { ToolRegistry };
|
|
20
27
|
export { createToolRegistry };
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { TheoremError } from '../../guardrails/error.js';
|
|
2
|
+
import { profileInputs } from '../registry/catalog.js';
|
|
2
3
|
import { activityLabelProblem } from './activity-label.js';
|
|
4
|
+
import { agentToolInputFor, agentToolOutput, agentToolProfile, normalizeAgent } from './agent.js';
|
|
3
5
|
import { createMcpSessionCache } from './mcp-sessions.js';
|
|
4
|
-
import {
|
|
6
|
+
import { pageAnswerHandler } from './page-answer.js';
|
|
7
|
+
import { assertFixedEndpointOrigin, jsonSchemaFromZod, validateToolSchema } from './schema.js';
|
|
5
8
|
function schemasFromZod(def) {
|
|
6
9
|
const inputSchema = jsonSchemaFromZod(def.input, 'input');
|
|
7
|
-
|
|
10
|
+
validateToolSchema(inputSchema, 'input');
|
|
8
11
|
const outputSchema = jsonSchemaFromZod(def.output, 'output');
|
|
9
|
-
|
|
12
|
+
validateToolSchema(outputSchema, 'output');
|
|
10
13
|
const labels = {
|
|
11
14
|
activity: { input: inputSchema },
|
|
12
15
|
activityPast: { input: inputSchema, output: outputSchema },
|
|
16
|
+
activityFailed: { input: inputSchema },
|
|
17
|
+
request: { input: inputSchema },
|
|
13
18
|
};
|
|
14
|
-
for (const field of ['activity', 'activityPast']) {
|
|
19
|
+
for (const field of ['activity', 'activityPast', 'activityFailed', 'request']) {
|
|
15
20
|
const template = def.labels?.[field];
|
|
16
21
|
const problem = template ? activityLabelProblem(template, labels[field]) : undefined;
|
|
17
22
|
if (problem) {
|
|
@@ -26,23 +31,73 @@ function assertAuthService(name, auth) {
|
|
|
26
31
|
throw new TheoremError('config', `Tool "${name}" signs in with slot "${auth.slot}" but names no service`);
|
|
27
32
|
}
|
|
28
33
|
}
|
|
34
|
+
/** A key in the URL goes in one named query parameter, and nowhere a header or the model's input could also put it. */
|
|
35
|
+
function assertQueryParam(name, auth, inputQueryParams = []) {
|
|
36
|
+
if (auth?.queryParam === undefined)
|
|
37
|
+
return;
|
|
38
|
+
const problem = !auth.queryParam.trim()
|
|
39
|
+
? 'is blank'
|
|
40
|
+
: auth.type !== 'api_key'
|
|
41
|
+
? `is set on a '${auth.type}' sign-in; only an API key goes in the URL` // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
42
|
+
: auth.headerName !== undefined || auth.headerPrefix !== undefined
|
|
43
|
+
? 'is set with headerName or headerPrefix; the key goes in one place' // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
44
|
+
: inputQueryParams.includes(auth.queryParam)
|
|
45
|
+
? `"${auth.queryParam}" is also one of mapping.queryParams` // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
46
|
+
: undefined;
|
|
47
|
+
if (problem) {
|
|
48
|
+
throw new TheoremError('config', `Tool "${name}" auth.queryParam ${problem}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** A limit is a whole number of requests in a window of some time. */
|
|
52
|
+
function assertLimit(name, limit) {
|
|
53
|
+
if (limit === undefined)
|
|
54
|
+
return;
|
|
55
|
+
const whole = Number.isInteger(limit.requests) && limit.requests > 0;
|
|
56
|
+
if (whole && Number.isFinite(limit.windowMs) && limit.windowMs > 0)
|
|
57
|
+
return;
|
|
58
|
+
throw new TheoremError('config', `Tool "${name}" limit needs a whole number of requests above 0 and a window above 0 ms`);
|
|
59
|
+
}
|
|
60
|
+
/** A timeout is some time: a finite number of ms above 0. */
|
|
61
|
+
function assertTimeout(name, timeoutMs) {
|
|
62
|
+
if (timeoutMs === undefined || (Number.isFinite(timeoutMs) && timeoutMs > 0))
|
|
63
|
+
return;
|
|
64
|
+
throw new TheoremError('config', `Tool "${name}" timeoutMs needs a finite number of ms above 0`);
|
|
65
|
+
}
|
|
29
66
|
function normalizeHttp(def) {
|
|
30
67
|
assertFixedEndpointOrigin(def.endpoint);
|
|
31
68
|
assertAuthService(def.name, def.auth);
|
|
69
|
+
assertQueryParam(def.name, def.auth, def.mapping?.queryParams);
|
|
70
|
+
assertLimit(def.name, def.limit);
|
|
71
|
+
assertTimeout(def.name, def.timeoutMs);
|
|
32
72
|
return { ...def, type: 'http', ...schemasFromZod(def) };
|
|
33
73
|
}
|
|
34
74
|
function normalizeMcp(def) {
|
|
35
75
|
assertAuthService(def.name, def.auth);
|
|
76
|
+
assertQueryParam(def.name, def.auth);
|
|
36
77
|
return { ...def, type: 'mcp', ...schemasFromZod(def) };
|
|
37
78
|
}
|
|
38
79
|
function normalizeFunction(def) {
|
|
39
80
|
assertAuthService(def.name, def.auth);
|
|
40
|
-
|
|
81
|
+
assertQueryParam(def.name, def.auth);
|
|
82
|
+
const handler = def.answeredBy === 'page'
|
|
83
|
+
? pageAnswerHandler(def.name)
|
|
84
|
+
: def.handler;
|
|
85
|
+
if (typeof handler !== 'function') {
|
|
86
|
+
throw new TheoremError('config', `Tool '${def.name}' needs a handler, or answeredBy: 'page'`);
|
|
87
|
+
}
|
|
88
|
+
return { ...def, handler, type: 'function', ...schemasFromZod(def) };
|
|
41
89
|
}
|
|
42
|
-
function normalizeToolDefinition(def) {
|
|
90
|
+
function normalizeToolDefinition(def, findProfile, findTool) {
|
|
43
91
|
if (def.type === 'builtin') {
|
|
44
92
|
return def;
|
|
45
93
|
}
|
|
94
|
+
if (def.type === 'agent') {
|
|
95
|
+
const profile = agentToolProfile(def, findProfile, findTool);
|
|
96
|
+
const inputs = profileInputs(profile);
|
|
97
|
+
const input = agentToolInputFor({ type: profile.type, ...(inputs ? { inputs } : {}) }, def);
|
|
98
|
+
const schemas = schemasFromZod({ ...def, input, output: agentToolOutput });
|
|
99
|
+
return normalizeAgent(def, input, schemas);
|
|
100
|
+
}
|
|
46
101
|
if (def.type === 'http') {
|
|
47
102
|
return normalizeHttp(def);
|
|
48
103
|
}
|
|
@@ -51,13 +106,16 @@ function normalizeToolDefinition(def) {
|
|
|
51
106
|
}
|
|
52
107
|
return normalizeFunction(def);
|
|
53
108
|
}
|
|
54
|
-
/**
|
|
55
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Registration is not synchronized: register a scope's tools before its turns or invokes run.
|
|
111
|
+
* `findProfile` is the scope's profiles, which an agent tool names; without it none registers.
|
|
112
|
+
*/
|
|
113
|
+
function createToolRegistry(findProfile = () => undefined) {
|
|
56
114
|
const tools = new Map();
|
|
57
115
|
const mcpSessions = createMcpSessionCache();
|
|
58
116
|
const get = (name) => tools.get(name);
|
|
59
117
|
const register = (def) => {
|
|
60
|
-
const normalized = normalizeToolDefinition(def);
|
|
118
|
+
const normalized = normalizeToolDefinition(def, findProfile, get);
|
|
61
119
|
tools.set(normalized.name, normalized);
|
|
62
120
|
return normalized;
|
|
63
121
|
};
|
|
@@ -68,12 +126,13 @@ function createToolRegistry() {
|
|
|
68
126
|
require(name) {
|
|
69
127
|
const tool = get(name);
|
|
70
128
|
if (!tool) {
|
|
71
|
-
throw new TheoremError('config', `Tool '${name}' is not registered`); //
|
|
129
|
+
throw new TheoremError('config', `Tool '${name}' is not registered`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
72
130
|
}
|
|
73
131
|
return tool;
|
|
74
132
|
},
|
|
75
133
|
has: (name) => tools.has(name),
|
|
76
134
|
list: () => [...tools.values()],
|
|
135
|
+
findProfile,
|
|
77
136
|
reset: () => {
|
|
78
137
|
tools.clear();
|
|
79
138
|
mcpSessions.clear();
|
|
@@ -1,25 +1,50 @@
|
|
|
1
|
+
import type { ApiKeyCredential, BearerCredential } from '../auth/types.js';
|
|
1
2
|
import type { InteractionPart } from '../turn-events.js';
|
|
2
3
|
import type { TurnEvent } from '../types.js';
|
|
3
4
|
import { type ToolCallBase } from './events.js';
|
|
5
|
+
import type { HandlerEvents } from './handler-events.js';
|
|
4
6
|
import { type McpSessionCache } from './mcp-sessions.js';
|
|
7
|
+
import type { ToolOperationClaim } from './operation.js';
|
|
5
8
|
import { type ToolStageSupport } from './stage-run.js';
|
|
6
9
|
import type { HttpToolDef, McpToolDef, ModelToolResult, ToolAuthConfig, ToolBodyOutcome, ToolContext, ToolFailure, ToolGate } from './types.js';
|
|
7
10
|
export type AuthResolveResult = {
|
|
8
11
|
headers: Record<string, string>;
|
|
12
|
+
/** An API key the URL carries in place of a header: the tool's `auth.queryParam` and the key. */
|
|
13
|
+
query?: CredentialQuery;
|
|
9
14
|
/** The response is stripped of this before anyone reads it. */
|
|
10
15
|
secret?: string;
|
|
11
16
|
/** RFC 8707 resource an OAuth token was issued for; it goes nowhere else. */
|
|
12
17
|
audience?: string;
|
|
13
18
|
unauthenticated?: boolean;
|
|
14
19
|
modelMessage?: string;
|
|
20
|
+
/** Why the call fails, under `onUnauthenticated: 'fail'`. */
|
|
21
|
+
failureMessage?: string;
|
|
15
22
|
gate?: ToolGate;
|
|
16
23
|
};
|
|
24
|
+
/** A credential that goes in a query parameter of the URL a call is sent to. */
|
|
25
|
+
export type CredentialQuery = {
|
|
26
|
+
name: string;
|
|
27
|
+
value: string;
|
|
28
|
+
};
|
|
29
|
+
/** `url` with the credential set in its query parameter; `url` itself is left as it was. */
|
|
30
|
+
export declare function withCredentialQuery(url: URL, query: CredentialQuery | undefined): URL;
|
|
31
|
+
/**
|
|
32
|
+
* Where a token or API key goes on a tool's requests: the query parameter the tool names, or a
|
|
33
|
+
* header, `Authorization: Bearer …` for a token and `Authorization: …` for a key unless the tool
|
|
34
|
+
* or the key names another.
|
|
35
|
+
*/
|
|
36
|
+
export declare function credentialPlacement(authConfig: Pick<ToolAuthConfig, 'headerName' | 'headerPrefix' | 'queryParam'>, credential: BearerCredential | ApiKeyCredential): {
|
|
37
|
+
headers: Record<string, string>;
|
|
38
|
+
query?: CredentialQuery;
|
|
39
|
+
};
|
|
40
|
+
/** Finds the auth headers for a call from the host's credential for the tool's slot, refreshing an OAuth token when needed; with no usable credential it returns a gate or a message for the model, per the tool's `onUnauthenticated`. */
|
|
17
41
|
export declare function resolveToolAuth(toolName: string, authConfig: ToolAuthConfig | undefined, ctx: ToolContext, base: ToolCallBase): AsyncGenerator<TurnEvent, AuthResolveResult>;
|
|
18
42
|
export type HttpToolMapping = NonNullable<HttpToolDef['mapping']>;
|
|
19
43
|
export type HttpToolTarget = {
|
|
20
44
|
url: string;
|
|
21
45
|
body?: string;
|
|
22
46
|
};
|
|
47
|
+
/** The URL and, for anything but GET, the JSON body of an HTTP tool call: path parameters fill the endpoint, query parameters go on the URL, and the rest of the input (or `bodyParam`) is the body; throws when a path parameter is missing. */
|
|
23
48
|
export declare function buildHttpToolTarget(endpoint: string, method: HttpToolDef['method'], input: Record<string, unknown>, mapping?: HttpToolMapping): HttpToolTarget;
|
|
24
49
|
export declare function parseToolOutput<T>(schema: {
|
|
25
50
|
safeParse: (data: unknown) => {
|
|
@@ -44,11 +69,13 @@ export declare function parseToolOutput<T>(schema: {
|
|
|
44
69
|
export declare function modelResultFromOutput(data: unknown): ModelToolResult;
|
|
45
70
|
/** The result with the media a tool returned beside its value, when it returned any. */
|
|
46
71
|
export declare function withMedia(result: ModelToolResult, parts: InteractionPart[] | undefined): ModelToolResult;
|
|
72
|
+
/** `sent`: the service refused a request the call already sent, so the call has started. */
|
|
47
73
|
export declare function outcomeFromUnauth(authRes: {
|
|
48
74
|
unauthenticated?: boolean;
|
|
49
75
|
gate?: import('./types.js').ToolGate;
|
|
50
76
|
modelMessage?: string;
|
|
51
|
-
|
|
77
|
+
failureMessage?: string;
|
|
78
|
+
}, sent?: boolean): ToolBodyOutcome | undefined;
|
|
52
79
|
/** A 401 or 403 answer to a request that carried a credential. */
|
|
53
80
|
export type CredentialRefusal = {
|
|
54
81
|
status: number;
|
|
@@ -62,12 +89,13 @@ export declare function refusalAsksForSignIn(refusal: CredentialRefusal): boolea
|
|
|
62
89
|
* the person signs in again. A 403 `insufficient_scope` asks for more access: a
|
|
63
90
|
* sign-in can grant scopes the tool declares, and nothing else, so a request
|
|
64
91
|
* outside them fails with `sign_in.out_of_scope` and the trace records what was
|
|
65
|
-
* asked against what is declared. Any other refusal is the call's failure.
|
|
92
|
+
* asked against what is declared. Any other refusal is the call's failure. `carried` says the
|
|
93
|
+
* request went with a credential, in a header or in the URL.
|
|
66
94
|
*/
|
|
67
95
|
export declare function refusedCredentialOutcome(tool: {
|
|
68
96
|
name: string;
|
|
69
97
|
auth?: ToolAuthConfig;
|
|
70
|
-
}, refusal: CredentialRefusal | undefined,
|
|
98
|
+
}, refusal: CredentialRefusal | undefined, carried: boolean, ctx: ToolContext, base: ToolCallBase): Generator<TurnEvent, ToolBodyOutcome | undefined>;
|
|
71
99
|
/** The most of a tool's response body the kernel reads; past it the call fails instead of exhausting the host's memory. */
|
|
72
100
|
export declare const MAX_TOOL_RESPONSE_BYTES: number;
|
|
73
101
|
/** Every string in `value` with the credential replaced. */
|
|
@@ -76,11 +104,16 @@ export declare function omitSecret(value: unknown, secret: string): unknown;
|
|
|
76
104
|
export declare function failureWithoutSecret(failure: ToolFailure, secret: string): ToolFailure;
|
|
77
105
|
/** Why an OAuth token issued for `audience` may not go to `url` (RFC 8707), or `undefined` when it may. */
|
|
78
106
|
export declare function audienceMismatch(audience: string | undefined, url: URL): string | undefined;
|
|
79
|
-
/**
|
|
80
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Order: schema → permission → auth → preTool/host stages → body. `shown` takes the body while it
|
|
109
|
+
* arrives, as a function tool's drafts.
|
|
110
|
+
*/
|
|
111
|
+
export declare function executeHttpTool(tool: HttpToolDef, rawInput: unknown, ctx: ToolContext, base: ToolCallBase, stages?: ToolStageSupport, beginBody?: (preparedInput: unknown) => Promise<ToolOperationClaim | undefined>, shown?: HandlerEvents): AsyncGenerator<TurnEvent, ToolBodyOutcome>;
|
|
81
112
|
/** Preferred first. */
|
|
82
113
|
export declare const MCP_PROTOCOL_VERSIONS: readonly ["2026-07-28", "2025-11-25", "2025-06-18", "2025-03-26"];
|
|
114
|
+
/** An MCP protocol version the client can speak. */
|
|
83
115
|
export type McpProtocolVersion = (typeof MCP_PROTOCOL_VERSIONS)[number];
|
|
116
|
+
/** A JSON-RPC message from an MCP server: a result or an error. */
|
|
84
117
|
export type McpRpcResponse = {
|
|
85
118
|
jsonrpc?: string;
|
|
86
119
|
id?: unknown;
|
|
@@ -103,8 +136,9 @@ export type McpRpcResponse = {
|
|
|
103
136
|
};
|
|
104
137
|
/** Accepts a JSON body or an SSE (`data:`) stream. */
|
|
105
138
|
export declare function parseMcpRpcResponse(text: string): McpRpcResponse;
|
|
139
|
+
/** True when an MCP error says the server does not accept the protocol version sent. */
|
|
106
140
|
export declare function isUnsupportedMcpProtocolError(error: McpRpcResponse['error']): boolean;
|
|
107
141
|
/** Streamable HTTP, spec revision 2026-07-28. Order: schema → permission → auth → preTool/host stages → body. */
|
|
108
142
|
export declare function executeMcpTool(tool: McpToolDef, rawInput: unknown, ctx: ToolContext, base: ToolCallBase, stages?: ToolStageSupport,
|
|
109
143
|
/** The scope's sessions; without them a session lasts one call. */
|
|
110
|
-
sessions?: McpSessionCache): AsyncGenerator<TurnEvent, ToolBodyOutcome>;
|
|
144
|
+
sessions?: McpSessionCache, beginBody?: (preparedInput: unknown) => Promise<ToolOperationClaim | undefined>): AsyncGenerator<TurnEvent, ToolBodyOutcome>;
|