@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
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import { isAbortError, TheoremError, toErrorEvent,
|
|
1
|
+
import { isAbortError, TheoremError, toErrorEvent, withPublicLabels, } from '../../guardrails/error.js';
|
|
2
|
+
import { projectGuardrailTurnEvent } from '../../guardrails/events.js';
|
|
2
3
|
import { resolveTraceWriter } from '../../observability/policy.js';
|
|
3
|
-
import {
|
|
4
|
+
import { writeTrace } from '../../observability/trace.js';
|
|
5
|
+
import { buildRecord } from '../../observability/trace-record.js';
|
|
4
6
|
import { startTrace, } from '../../observability/trace-span.js';
|
|
7
|
+
import { invokeAgentCaller } from '../engine/runner/mod.js';
|
|
8
|
+
import { inStep, runSideBySide, stepOrder } from '../engine/runner/step-order.js';
|
|
5
9
|
import { startToolTrace, toolSpanName } from '../engine/tool-trace.js';
|
|
6
|
-
import { optional, traceLinks } from '../engine/turn-trace.js';
|
|
10
|
+
import { endThrownSpan, optional, traceLinks } from '../engine/turn-trace.js';
|
|
7
11
|
import { pickModel } from '../registry/resolve.js';
|
|
8
12
|
import { turnDoneOf } from '../turn-events.js';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
13
|
+
import { coordinateTool } from './coordinate.js';
|
|
14
|
+
import { failedActivity, failureEvent, newCallId, toolCallArguments, toolCallRequestEvent, } from './events.js';
|
|
15
|
+
import { authorizeToolReplay, executeRegisteredTool, } from './execute.js';
|
|
16
|
+
import { cloneTurnToolSnapshot, prepareTurnToolSnapshot, profileToolsParallel, promoteLoadedTools, } from './resolve.js';
|
|
12
17
|
import { plainToolInput } from './schema.js';
|
|
13
18
|
function turnRequestFromInvoke(request) {
|
|
14
19
|
return {
|
|
@@ -22,24 +27,25 @@ function turnRequestFromInvoke(request) {
|
|
|
22
27
|
}
|
|
23
28
|
async function prepareInvokeSnapshot(registry, request, profile) {
|
|
24
29
|
const req = turnRequestFromInvoke(request);
|
|
25
|
-
if (profile.type === 'decision') {
|
|
26
|
-
throw new TheoremError('request', `Profile ${profile.id}: type 'decision' cannot invoke tools`); //
|
|
30
|
+
if (profile.type === 'decision' || profile.type === 'embedding') {
|
|
31
|
+
throw new TheoremError('request', `Profile ${profile.id}: type 'decision' cannot invoke tools`); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
27
32
|
}
|
|
28
33
|
const model = profile.type === 'host' ? undefined : pickModel(profile, request.model);
|
|
29
34
|
return await prepareTurnToolSnapshot(registry.tools, profile, req, model);
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
|
-
*
|
|
33
|
-
* the tool.
|
|
37
|
+
* One trace record around an invoke, written however it ends, including an early stop or a
|
|
38
|
+
* failure before the tool. The profile's labels and guardrail policy shape every event. An unknown
|
|
39
|
+
* profile is recorded under the standard observability policy: there is none to read.
|
|
34
40
|
*/
|
|
35
|
-
async function*
|
|
41
|
+
async function* invokeInTrace(registry, request, spanName, sinkOverride, run) {
|
|
36
42
|
const known = registry.profiles.find(request.profile);
|
|
37
43
|
const { sink, policy } = resolveTraceWriter({
|
|
38
44
|
override: sinkOverride,
|
|
39
45
|
observability: known?.observability,
|
|
46
|
+
guardrails: known?.guardrails,
|
|
40
47
|
});
|
|
41
|
-
const
|
|
42
|
-
const tree = startTrace(toolSpanName(request.name), {
|
|
48
|
+
const tree = startTrace(spanName, {
|
|
43
49
|
attributes: {
|
|
44
50
|
'gen_ai.agent.name': request.profile,
|
|
45
51
|
...optional('gen_ai.conversation.id', request.conversationId),
|
|
@@ -47,83 +53,230 @@ async function* invokeTool(registry, request, sinkOverride) {
|
|
|
47
53
|
links: traceLinks(request.links),
|
|
48
54
|
...(request.traceparent ? { traceparent: request.traceparent } : {}),
|
|
49
55
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return tree.root;
|
|
53
|
-
};
|
|
54
|
-
const failBeforeTool = (end) => startToolTrace(openSpan, {
|
|
55
|
-
name: request.name,
|
|
56
|
-
callId,
|
|
57
|
-
call: { arguments: toolCallArguments(plainToolInput(request.input)) },
|
|
58
|
-
}).end(end);
|
|
56
|
+
// why: Agent tool calls run nested turns in this record; their canaries are scrubbed from it.
|
|
57
|
+
const canaries = [];
|
|
59
58
|
try {
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
yield
|
|
59
|
+
const labels = known?.labels;
|
|
60
|
+
for await (const event of run.events(tree, canaries)) {
|
|
61
|
+
// invariant: A match is the caught text itself; it leaves only when the profile asks for it.
|
|
62
|
+
yield projectGuardrailTurnEvent(withPublicLabels(event, labels), policy.include.guardrailMatchPreview);
|
|
64
63
|
}
|
|
64
|
+
run.ended?.(tree);
|
|
65
65
|
}
|
|
66
66
|
catch (err) {
|
|
67
|
-
|
|
67
|
+
run.failed(tree, err);
|
|
68
68
|
throw err;
|
|
69
69
|
}
|
|
70
70
|
finally {
|
|
71
|
-
await
|
|
71
|
+
await writeTrace(sink, buildRecord({
|
|
72
|
+
spans: tree.collect(),
|
|
73
|
+
policy,
|
|
74
|
+
canaries,
|
|
75
|
+
...(request.metadata ? { metadata: request.metadata } : {}),
|
|
76
|
+
}), policy);
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
|
-
|
|
79
|
+
/** Close the call's span for a failure before its tool ran. */
|
|
80
|
+
function failCallBeforeTool(openSpan, invoke, callId) {
|
|
81
|
+
return (end) => startToolTrace(openSpan, {
|
|
82
|
+
name: invoke.name,
|
|
83
|
+
callId,
|
|
84
|
+
call: { arguments: toolCallArguments(plainToolInput(invoke.input)) },
|
|
85
|
+
}).end(end);
|
|
86
|
+
}
|
|
87
|
+
/** The profile an invoke runs under, and its own copy of the tool snapshot. */
|
|
88
|
+
async function invokeSnapshot(registry, request) {
|
|
75
89
|
const profile = registry.profiles.get(request.profile);
|
|
76
90
|
const snapshot = request.snapshot
|
|
77
91
|
? cloneTurnToolSnapshot(request.snapshot)
|
|
78
92
|
: await prepareInvokeSnapshot(registry, request, profile);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
return { profile, snapshot };
|
|
94
|
+
}
|
|
95
|
+
function invokeTool(registry, request, sinkOverride) {
|
|
96
|
+
return startInvoke(registry, request, sinkOverride).events;
|
|
97
|
+
}
|
|
98
|
+
function startInvoke(registry, request, sinkOverride) {
|
|
99
|
+
const callId = request.callId ?? newCallId(request.name);
|
|
100
|
+
const invoke = {
|
|
101
|
+
...request,
|
|
102
|
+
operationId: request.operationId ?? crypto.randomUUID(),
|
|
103
|
+
};
|
|
104
|
+
const openSpan = (tree) => (_name, attributes) => {
|
|
105
|
+
tree.root.set(attributes);
|
|
106
|
+
return tree.root;
|
|
107
|
+
};
|
|
108
|
+
const events = invokeInTrace(registry, invoke, toolSpanName(invoke.name), sinkOverride, {
|
|
109
|
+
events: (tree, canaries) => invokeTraced(registry, invoke, callId, openSpan(tree), failCallBeforeTool(openSpan(tree), invoke, callId), tree.root.traceparent(), canaries),
|
|
110
|
+
failed: (tree, err) => failCallBeforeTool(openSpan(tree), invoke, callId)(isAbortError(err) ? { outcome: 'cancelled' } : { outcome: 'error', thrown: err }),
|
|
111
|
+
});
|
|
112
|
+
return { name: invoke.name, callId, events };
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Runs the host's calls as one step, the way a turn runs the model's. Every call the step names
|
|
116
|
+
* itself is announced with the step's id before any runs. With `tools.parallel` they run side by
|
|
117
|
+
* side, otherwise one at a time in the order given; a call whose `pre_tool` answers `waitFor`
|
|
118
|
+
* starts once those calls in the step settle. Each call's events arrive as it gives them, and its
|
|
119
|
+
* terminal `tool` event says it settled. The calls share one snapshot. A call that gates waits for
|
|
120
|
+
* its own approval while the others run; the step then ends `gate`. One trace record holds a span
|
|
121
|
+
* per call under the step's root, rooted under the host span when one is given.
|
|
122
|
+
*/
|
|
123
|
+
function invokeToolStep(registry, request, sinkOverride) {
|
|
124
|
+
return startInvokeStep(registry, request, sinkOverride).events;
|
|
125
|
+
}
|
|
126
|
+
function startInvokeStep(registry, request, sinkOverride) {
|
|
127
|
+
const { calls: given, ...shared } = request;
|
|
128
|
+
const calls = given.map((call) => {
|
|
129
|
+
const callId = call.callId ?? newCallId(call.name);
|
|
130
|
+
return {
|
|
131
|
+
callId,
|
|
132
|
+
invoke: {
|
|
133
|
+
...shared,
|
|
134
|
+
name: call.name,
|
|
135
|
+
input: call.input,
|
|
136
|
+
callId,
|
|
137
|
+
operationId: call.operationId ?? crypto.randomUUID(),
|
|
138
|
+
},
|
|
139
|
+
// why: A model's call was already announced by its turn; only a call the step names itself is announced here.
|
|
140
|
+
announce: call.callId === undefined,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
const events = invokeInTrace(registry, request, `tool_step ${request.profile}`, sinkOverride, {
|
|
144
|
+
events: (tree, canaries) => invokeStepTraced(registry, request, calls, (name, attributes) => tree.root.child(name, { attributes }), tree.root.traceparent(), canaries),
|
|
145
|
+
ended: (tree) => tree.root.end({ code: 'OK' }),
|
|
146
|
+
failed: (tree, err) => {
|
|
147
|
+
if (isAbortError(err))
|
|
148
|
+
tree.root.end();
|
|
149
|
+
else
|
|
150
|
+
endThrownSpan(tree.root, err);
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
calls: calls.map(({ callId, invoke }) => ({ name: invoke.name, callId })),
|
|
155
|
+
events,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
async function* invokeStepTraced(registry, request, calls, openSpan, traceparent, canaries) {
|
|
159
|
+
const { profile, snapshot } = await invokeSnapshot(registry, request);
|
|
160
|
+
const stepId = crypto.randomUUID();
|
|
161
|
+
for (const { callId, invoke, announce } of calls) {
|
|
162
|
+
if (!announce)
|
|
163
|
+
continue;
|
|
164
|
+
yield toolCallRequestEvent({ name: invoke.name, callId, operationId: invoke.operationId }, toolCallArguments(invoke.input), { stepId, stepCallCount: calls.length });
|
|
82
165
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
166
|
+
const order = stepOrder(calls.map(({ callId }) => callId), profileToolsParallel(profile) === true, request.signal);
|
|
167
|
+
const step = {
|
|
168
|
+
stepCalls: calls.map(({ callId, invoke }) => ({
|
|
169
|
+
callId,
|
|
170
|
+
tool: invoke.name,
|
|
171
|
+
input: toolCallArguments(invoke.input),
|
|
172
|
+
})),
|
|
173
|
+
wait: order.wait,
|
|
174
|
+
};
|
|
175
|
+
let gated = false;
|
|
176
|
+
try {
|
|
177
|
+
// why: As in a turn's step, one call that throws ends the step; the others are closed.
|
|
178
|
+
const settlements = yield* runSideBySide(calls.map(({ callId, invoke }) => inStep(order, callId, () => runCall(registry, invoke, profile, snapshot, callId, openSpan, failCallBeforeTool(openSpan, invoke, callId), canaries, step))));
|
|
179
|
+
gated = settlements.some((settlement) => settlement?.gated !== undefined);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
yield toErrorEvent(err);
|
|
183
|
+
}
|
|
184
|
+
yield turnDoneOf({
|
|
185
|
+
stop: { kind: gated ? 'gate' : 'completed' },
|
|
186
|
+
traceparent,
|
|
187
|
+
}, snapshot);
|
|
188
|
+
}
|
|
189
|
+
async function* invokeTraced(registry, request, callId, openSpan, failBeforeTool, traceparent, canaries) {
|
|
190
|
+
const { profile, snapshot } = await invokeSnapshot(registry, request);
|
|
191
|
+
// why: A model's call was already announced by its turn.
|
|
192
|
+
if (request.callId === undefined) {
|
|
193
|
+
yield toolCallRequestEvent({ name: request.name, callId, operationId: request.operationId }, toolCallArguments(request.input));
|
|
91
194
|
}
|
|
92
195
|
let gated = false;
|
|
93
196
|
try {
|
|
94
|
-
const
|
|
95
|
-
const settlement = yield* executeRegisteredTool({
|
|
96
|
-
tools: registry.tools,
|
|
97
|
-
profile,
|
|
98
|
-
name: request.name,
|
|
99
|
-
input: request.input,
|
|
100
|
-
callId,
|
|
101
|
-
ctx: {
|
|
102
|
-
sessionPermissions: request.sessionPermissions,
|
|
103
|
-
credentials: request.credentials,
|
|
104
|
-
resolveHost: request.resolveHost,
|
|
105
|
-
path: request.path,
|
|
106
|
-
signal: request.signal,
|
|
107
|
-
resume: request.resume,
|
|
108
|
-
host: request.host,
|
|
109
|
-
},
|
|
110
|
-
snapshot,
|
|
111
|
-
openSpan,
|
|
112
|
-
stages: {
|
|
113
|
-
handlers,
|
|
114
|
-
profile,
|
|
115
|
-
step: 1,
|
|
116
|
-
history: () => [],
|
|
117
|
-
injectAllowed: false,
|
|
118
|
-
host: request.host,
|
|
119
|
-
signal: request.signal,
|
|
120
|
-
},
|
|
121
|
-
});
|
|
197
|
+
const settlement = yield* runCall(registry, request, profile, snapshot, callId, openSpan, failBeforeTool, canaries);
|
|
122
198
|
gated = settlement.gated !== undefined;
|
|
123
199
|
}
|
|
124
200
|
catch (err) {
|
|
125
201
|
yield toErrorEvent(err);
|
|
126
202
|
}
|
|
127
|
-
yield turnDoneOf({
|
|
203
|
+
yield turnDoneOf({
|
|
204
|
+
stop: { kind: gated ? 'gate' : 'completed' },
|
|
205
|
+
traceparent,
|
|
206
|
+
}, snapshot);
|
|
207
|
+
}
|
|
208
|
+
/** One call, coordinated: replayed when its operation already ran, else executed. */
|
|
209
|
+
function runCall(registry, request, profile, snapshot, callId, openSpan, failBeforeTool, canaries, step) {
|
|
210
|
+
return coordinateTool(request.execution, {
|
|
211
|
+
operationId: request.operationId ?? crypto.randomUUID(),
|
|
212
|
+
callId,
|
|
213
|
+
profileId: profile.id,
|
|
214
|
+
toolId: request.name,
|
|
215
|
+
}, {
|
|
216
|
+
input: request.input,
|
|
217
|
+
resume: request.resume,
|
|
218
|
+
snapshot,
|
|
219
|
+
context: {
|
|
220
|
+
model: request.model,
|
|
221
|
+
turnInput: request.turnInput,
|
|
222
|
+
promoted: request.promoted,
|
|
223
|
+
},
|
|
224
|
+
}, request.signal, (beginBody) => invokePrepared(registry, request, profile, snapshot, callId, openSpan, failBeforeTool, canaries, beginBody, step), (outcome) => authorizeToolReplay({
|
|
225
|
+
outcome,
|
|
226
|
+
tools: registry.tools,
|
|
227
|
+
profile,
|
|
228
|
+
name: request.name,
|
|
229
|
+
resume: request.resume,
|
|
230
|
+
snapshot,
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
async function* invokePrepared(registry, request, profile, snapshot, callId, openSpan, failBeforeTool, canaries, beginBody, step) {
|
|
234
|
+
if (request.promoted?.length) {
|
|
235
|
+
const { failure } = promoteLoadedTools(registry.tools, snapshot, request.promoted, profile);
|
|
236
|
+
if (failure) {
|
|
237
|
+
failBeforeTool({ outcome: 'error', failure });
|
|
238
|
+
yield failureEvent({
|
|
239
|
+
name: request.name,
|
|
240
|
+
callId,
|
|
241
|
+
operationId: request.operationId,
|
|
242
|
+
activityFailed: failedActivity(request.name, profile.labels),
|
|
243
|
+
}, failure);
|
|
244
|
+
return { failure, callNotStarted: true };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const handlers = request.onStage ? [request.onStage] : [];
|
|
248
|
+
return yield* executeRegisteredTool({
|
|
249
|
+
tools: registry.tools,
|
|
250
|
+
beginBody,
|
|
251
|
+
agents: invokeAgentCaller(registry, request, canaries),
|
|
252
|
+
profile,
|
|
253
|
+
name: request.name,
|
|
254
|
+
input: request.input,
|
|
255
|
+
callId,
|
|
256
|
+
ctx: {
|
|
257
|
+
operationId: request.operationId,
|
|
258
|
+
sessionPermissions: request.sessionPermissions,
|
|
259
|
+
credentials: request.credentials,
|
|
260
|
+
resolveHost: request.resolveHost,
|
|
261
|
+
path: request.path,
|
|
262
|
+
signal: request.signal,
|
|
263
|
+
resume: request.resume,
|
|
264
|
+
page: request.page,
|
|
265
|
+
pageExecution: request.pageExecution,
|
|
266
|
+
host: request.host,
|
|
267
|
+
},
|
|
268
|
+
snapshot,
|
|
269
|
+
openSpan,
|
|
270
|
+
stages: {
|
|
271
|
+
handlers,
|
|
272
|
+
profile,
|
|
273
|
+
step: 1,
|
|
274
|
+
history: () => [],
|
|
275
|
+
injectAllowed: false,
|
|
276
|
+
host: request.host,
|
|
277
|
+
signal: request.signal,
|
|
278
|
+
...step,
|
|
279
|
+
},
|
|
280
|
+
});
|
|
128
281
|
}
|
|
129
|
-
export { invokeTool };
|
|
282
|
+
export { invokeTool, invokeToolStep, startInvoke, startInvokeStep };
|
|
@@ -16,5 +16,8 @@ export interface McpSessionCache {
|
|
|
16
16
|
}
|
|
17
17
|
export declare function createMcpSessionCache(now?: () => number): McpSessionCache;
|
|
18
18
|
export declare function isMcpSessionId(value: string | null): value is string;
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* One session per server and credential. The URL is hashed with the headers, since a key can sit
|
|
21
|
+
* in either; the credential is never kept.
|
|
22
|
+
*/
|
|
20
23
|
export declare function mcpSessionKey(url: string, headers: Record<string, string>): Promise<string>;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
const MAX_SESSIONS = 256;
|
|
6
6
|
const IDLE_MS = 30 * 60 * 1000;
|
|
7
|
-
// The spec allows visible ASCII only; the cap keeps a server from bloating every later request.
|
|
7
|
+
// why: The spec allows visible ASCII only; the cap keeps a server from bloating every later request.
|
|
8
8
|
const SESSION_ID = /^[\x21-\x7E]{1,256}$/;
|
|
9
9
|
export function createMcpSessionCache(now = Date.now) {
|
|
10
10
|
const sessions = new Map();
|
|
@@ -17,7 +17,7 @@ export function createMcpSessionCache(now = Date.now) {
|
|
|
17
17
|
sessions.delete(key);
|
|
18
18
|
if (now() - entry.usedAt > IDLE_MS)
|
|
19
19
|
return undefined;
|
|
20
|
-
// Re-inserting keeps the map in least-recently-used order for eviction.
|
|
20
|
+
// why: Re-inserting keeps the map in least-recently-used order for eviction.
|
|
21
21
|
sessions.set(key, { ...entry, usedAt: now() });
|
|
22
22
|
return { id: entry.id, protocolVersion: entry.protocolVersion };
|
|
23
23
|
},
|
|
@@ -53,12 +53,17 @@ export function createMcpSessionCache(now = Date.now) {
|
|
|
53
53
|
export function isMcpSessionId(value) {
|
|
54
54
|
return value !== null && SESSION_ID.test(value);
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* One session per server and credential. The URL is hashed with the headers, since a key can sit
|
|
58
|
+
* in either; the credential is never kept.
|
|
59
|
+
*/
|
|
57
60
|
export async function mcpSessionKey(url, headers) {
|
|
58
|
-
const canonical = JSON.stringify(
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
+
const canonical = JSON.stringify([
|
|
62
|
+
url,
|
|
63
|
+
Object.entries(headers)
|
|
64
|
+
.map(([name, value]) => [name.toLowerCase(), value])
|
|
65
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),
|
|
66
|
+
]);
|
|
61
67
|
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonical));
|
|
62
|
-
|
|
63
|
-
return `${url}\n${hex.join('')}`;
|
|
68
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
64
69
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export { coerceToolResultParts, executeRegisteredTool, leanToolResultData, projectForModel, } from './execute.js';
|
|
1
|
+
export { authorizeToolReplay, coerceToolResultParts, executeRegisteredTool, leanToolResultData, projectForModel, } from './execute.js';
|
|
2
2
|
export { askUserTool, registerHarnessTools } from './harness.js';
|
|
3
3
|
export { formatToolResult } from './model-text.js';
|
|
4
4
|
export type { ToolRegistry } from './registry.js';
|
|
5
5
|
export { createToolRegistry } from './registry.js';
|
|
6
|
-
export type { McpProtocolVersion, McpRpcResponse } from './remote.js';
|
|
7
|
-
export { buildHttpToolTarget, executeHttpTool, executeMcpTool, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, parseMcpRpcResponse, resolveToolAuth, } from './remote.js';
|
|
6
|
+
export type { CredentialQuery, McpProtocolVersion, McpRpcResponse } from './remote.js';
|
|
7
|
+
export { buildHttpToolTarget, credentialPlacement, executeHttpTool, executeMcpTool, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, parseMcpRpcResponse, resolveToolAuth, withCredentialQuery, } from './remote.js';
|
|
8
8
|
export { cloneTurnToolSnapshot, prepareTurnToolSnapshot } from './resolve.js';
|
|
9
9
|
export type * from './types.js';
|
|
10
|
+
export { UncheckedOutput, uncheckedOutput } from './unchecked-output.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { coerceToolResultParts, executeRegisteredTool, leanToolResultData, projectForModel, } from './execute.js';
|
|
1
|
+
export { authorizeToolReplay, coerceToolResultParts, executeRegisteredTool, leanToolResultData, projectForModel, } from './execute.js';
|
|
2
2
|
export { askUserTool, registerHarnessTools } from './harness.js';
|
|
3
3
|
export { formatToolResult } from './model-text.js';
|
|
4
4
|
export { createToolRegistry } from './registry.js';
|
|
5
|
-
export { buildHttpToolTarget, executeHttpTool, executeMcpTool, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, parseMcpRpcResponse, resolveToolAuth, } from './remote.js';
|
|
5
|
+
export { buildHttpToolTarget, credentialPlacement, executeHttpTool, executeMcpTool, isUnsupportedMcpProtocolError, MCP_PROTOCOL_VERSIONS, parseMcpRpcResponse, resolveToolAuth, withCredentialQuery, } from './remote.js';
|
|
6
6
|
export { cloneTurnToolSnapshot, prepareTurnToolSnapshot } from './resolve.js';
|
|
7
|
+
export { UncheckedOutput, uncheckedOutput } from './unchecked-output.js';
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { resolveGuardrailPolicy } from '../../guardrails/policy.js';
|
|
2
|
-
import type { Provenance } from '../../guardrails/types.js';
|
|
3
1
|
import type { ModelToolResult, ToolFailure } from './types.js';
|
|
4
2
|
/**
|
|
5
3
|
* Every transport and replay formats through here, so the model's view of a call cannot drift.
|
|
6
4
|
* Never embeds `parts[].data`: media travels on `TurnHistoryMessage.parts`. A result without
|
|
7
|
-
* `modelText` (a host replaying a transcript)
|
|
5
|
+
* `modelText` (a host replaying a transcript) has no profile in hand, so every detector's
|
|
6
|
+
* matches are replaced.
|
|
8
7
|
*/
|
|
9
8
|
export declare function formatToolResult(result: ModelToolResult): string;
|
|
10
|
-
/**
|
|
11
|
-
export declare function
|
|
9
|
+
/** A failure as the kernel reports it to the model. The message is used as given. */
|
|
10
|
+
export declare function frameToolFailure(failure: Pick<ToolFailure, 'code' | 'message' | 'details'>): ModelToolResult;
|
|
11
|
+
/**
|
|
12
|
+
* A failure framed with no profile in hand: the message is remote-authored on HTTP and MCP
|
|
13
|
+
* tools, so every detector's matches are replaced first. A call that settles through the
|
|
14
|
+
* executor reads the message at its own boundary instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatToolFailureForModel(failure: Pick<ToolFailure, 'code' | 'message' | 'details'>): ModelToolResult;
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { composeToolText
|
|
1
|
+
import { redactDetectors } from '../../guardrails/detect-at.js';
|
|
2
|
+
import { DETECTORS } from '../../guardrails/detectors.js';
|
|
3
|
+
import { composeToolText } from '../../guardrails/tool-result.js';
|
|
4
4
|
/**
|
|
5
5
|
* Every transport and replay formats through here, so the model's view of a call cannot drift.
|
|
6
6
|
* Never embeds `parts[].data`: media travels on `TurnHistoryMessage.parts`. A result without
|
|
7
|
-
* `modelText` (a host replaying a transcript)
|
|
7
|
+
* `modelText` (a host replaying a transcript) has no profile in hand, so every detector's
|
|
8
|
+
* matches are replaced.
|
|
8
9
|
*/
|
|
9
10
|
export function formatToolResult(result) {
|
|
10
11
|
if (result.modelText !== undefined) {
|
|
11
12
|
return result.modelText;
|
|
12
13
|
}
|
|
13
|
-
return
|
|
14
|
+
return redactDetectors(composeToolText(result.finding, result.data), DETECTORS);
|
|
14
15
|
}
|
|
15
|
-
/**
|
|
16
|
-
export function
|
|
17
|
-
const safe = provenance
|
|
18
|
-
? guardToolFailureText(failure.message, provenance, policy).text
|
|
19
|
-
: sanitizeText(failure.message);
|
|
16
|
+
/** A failure as the kernel reports it to the model. The message is used as given. */
|
|
17
|
+
export function frameToolFailure(failure) {
|
|
20
18
|
return {
|
|
21
|
-
finding: `Tool error (${failure.code}): ${
|
|
22
|
-
// The finding already says the code and message; only details are new.
|
|
19
|
+
finding: `Tool error (${failure.code}): ${failure.message}`,
|
|
20
|
+
// why: The finding already says the code and message; only details are new.
|
|
23
21
|
...(failure.details !== undefined ? { data: { details: failure.details } } : {}),
|
|
24
22
|
};
|
|
25
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* A failure framed with no profile in hand: the message is remote-authored on HTTP and MCP
|
|
26
|
+
* tools, so every detector's matches are replaced first. A call that settles through the
|
|
27
|
+
* executor reads the message at its own boundary instead.
|
|
28
|
+
*/
|
|
29
|
+
export function formatToolFailureForModel(failure) {
|
|
30
|
+
return frameToolFailure({ ...failure, message: redactDetectors(failure.message, DETECTORS) });
|
|
31
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { TheoremError } from '../../guardrails/error.js';
|
|
3
|
+
import { type JsonObject, type JsonValue } from '../json.js';
|
|
4
|
+
import type { GateReference, TurnEventOf } from '../turn-events.js';
|
|
5
|
+
import type { TurnHistoryMessage } from '../types.js';
|
|
6
|
+
import type { ModelToolResult, PageAnswer, ToolFailure } from './types.js';
|
|
7
|
+
export type TerminalToolEvent = TurnEventOf<'tool'> & {
|
|
8
|
+
tool: Extract<TurnEventOf<'tool'>['tool'], {
|
|
9
|
+
phase: 'complete' | 'error';
|
|
10
|
+
}>;
|
|
11
|
+
};
|
|
12
|
+
export interface SavedToolInvocation {
|
|
13
|
+
accepted: JsonObject;
|
|
14
|
+
preparedInput: JsonValue;
|
|
15
|
+
}
|
|
16
|
+
export declare const savedToolInvocationSchema: z.ZodType<SavedToolInvocation>;
|
|
17
|
+
export interface ToolOperationIdentity extends GateReference {
|
|
18
|
+
profileId: string;
|
|
19
|
+
toolId: string;
|
|
20
|
+
invocationHash: string;
|
|
21
|
+
invocation?: SavedToolInvocation;
|
|
22
|
+
}
|
|
23
|
+
export interface ToolOperationClaim extends ToolOperationIdentity {
|
|
24
|
+
claimToken: string;
|
|
25
|
+
}
|
|
26
|
+
export interface PageToolDispatch {
|
|
27
|
+
grantId: string;
|
|
28
|
+
result: Promise<PageAnswer>;
|
|
29
|
+
}
|
|
30
|
+
export interface PageToolExecution {
|
|
31
|
+
dispatch(claim: ToolOperationClaim, signal?: AbortSignal): Promise<PageToolDispatch>;
|
|
32
|
+
}
|
|
33
|
+
export interface ToolOperationOutcome {
|
|
34
|
+
event: TerminalToolEvent;
|
|
35
|
+
effects: 'not_started' | 'completed' | 'unknown';
|
|
36
|
+
replay: {
|
|
37
|
+
modelResult?: ModelToolResult;
|
|
38
|
+
outputRaw?: unknown;
|
|
39
|
+
failure?: ToolFailure;
|
|
40
|
+
awaiting?: boolean;
|
|
41
|
+
denied?: true;
|
|
42
|
+
callNotStarted?: boolean;
|
|
43
|
+
aborted?: boolean | {
|
|
44
|
+
reason?: string;
|
|
45
|
+
};
|
|
46
|
+
pendingInject?: {
|
|
47
|
+
id?: string;
|
|
48
|
+
messages: TurnHistoryMessage[];
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export type ToolOperationUncertainty = 'execution_interrupted' | 'settlement_write_failed' | 'worker_lost';
|
|
53
|
+
export type BeginToolOperationResult = {
|
|
54
|
+
kind: 'acquired';
|
|
55
|
+
claimToken: string;
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'settled';
|
|
58
|
+
outcome: ToolOperationOutcome;
|
|
59
|
+
} | {
|
|
60
|
+
kind: 'running';
|
|
61
|
+
} | {
|
|
62
|
+
kind: 'uncertain';
|
|
63
|
+
};
|
|
64
|
+
export interface ToolExecutionCoordinator {
|
|
65
|
+
lookup(operation: ToolOperationIdentity): Promise<Exclude<BeginToolOperationResult, {
|
|
66
|
+
kind: 'acquired';
|
|
67
|
+
}> | undefined>;
|
|
68
|
+
begin(operation: ToolOperationIdentity): Promise<BeginToolOperationResult>;
|
|
69
|
+
settle(claim: ToolOperationClaim, outcome: ToolOperationOutcome): Promise<void>;
|
|
70
|
+
settleNotStarted(operation: ToolOperationIdentity, outcome: ToolOperationOutcome): Promise<void>;
|
|
71
|
+
markUncertain(claim: ToolOperationClaim, reason: ToolOperationUncertainty): Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
export declare function operationUnavailable(): TheoremError;
|
|
74
|
+
export declare function toolInvocationHash(value: unknown): Promise<string>;
|
|
75
|
+
export declare const toolOperationOutcomeSchema: z.ZodType<ToolOperationOutcome>;
|
|
76
|
+
export declare function operationWireValue(value: unknown): JsonValue;
|