@theoremjs/agents 0.3.0 → 0.3.2
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 +277 -995
- package/esm/mod.d.ts +34 -20
- package/esm/mod.js +19 -12
- 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 +25 -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 +881 -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 +30 -22
- package/esm/src/guardrails/mod.js +19 -14
- 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 +4 -1
- package/esm/src/guardrails/quota.js +7 -2
- 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 +5 -2
- package/esm/src/guardrails/theorem-error.js +6 -3
- 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 +8 -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 +174 -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 +329 -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 +130 -88
- 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 +102 -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/api-error.d.ts +2 -0
- package/esm/src/providers/google/api-error.js +26 -18
- 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 +4 -210
- 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 +18 -0
- package/esm/src/providers/shared/retry.js +89 -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
|
@@ -33,7 +33,7 @@ function joinPath(prefix, key) {
|
|
|
33
33
|
return prefix ? `${prefix}.${key}` : key;
|
|
34
34
|
}
|
|
35
35
|
function pushMissing(path, failures) {
|
|
36
|
-
failures.push({ path, error: `required field '${path}' is missing` }); //
|
|
36
|
+
failures.push({ path, error: `required field '${path}' is missing` }); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
37
37
|
}
|
|
38
38
|
async function runFieldValidator(path, value, validator, slots, failures) {
|
|
39
39
|
if (!validator) {
|
|
@@ -45,7 +45,7 @@ async function runFieldValidator(path, value, validator, slots, failures) {
|
|
|
45
45
|
}
|
|
46
46
|
failures.push({
|
|
47
47
|
path,
|
|
48
|
-
error: check.error || check.finding || `Validation failed for '${path}'`, //
|
|
48
|
+
error: check.error || check.finding || `Validation failed for '${path}'`, // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
async function visitProperty(args) {
|
|
@@ -87,7 +87,7 @@ async function walkObject(schema, value, pathPrefix, fields, slots, failures) {
|
|
|
87
87
|
async function collectValidationFailures(jsonSchema, structured, fields, slots) {
|
|
88
88
|
const root = asObjectSchema(jsonSchema);
|
|
89
89
|
if (!root) {
|
|
90
|
-
throw new TheoremError('config', 'structured validation requires a JSON Schema object root'); //
|
|
90
|
+
throw new TheoremError('config', 'structured validation requires a JSON Schema object root'); // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
91
91
|
}
|
|
92
92
|
const failures = [];
|
|
93
93
|
if (!asRecord(structured)) {
|
|
@@ -99,7 +99,81 @@ async function collectValidationFailures(jsonSchema, structured, fields, slots)
|
|
|
99
99
|
await walkObject(root, structured, '', fields, slots, failures);
|
|
100
100
|
return failures;
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Whether a validator keyed by `path` can run against `jsonSchema`: each segment is a
|
|
104
|
+
* property or required key of an object schema, as `collectValidationFailures` walks it.
|
|
105
|
+
*/
|
|
106
|
+
function schemaReaches(jsonSchema, path) {
|
|
107
|
+
let schema = jsonSchema;
|
|
108
|
+
for (const key of path.split('.')) {
|
|
109
|
+
const object = asObjectSchema(schema);
|
|
110
|
+
if (!object) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const props = propertySchemas(object);
|
|
114
|
+
if (!Object.hasOwn(props, key) && !requiredKeys(object).includes(key)) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
schema = props[key];
|
|
118
|
+
}
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
102
121
|
function formatValidationFailures(failures) {
|
|
103
122
|
return failures.map((f) => f.error).join('; ');
|
|
104
123
|
}
|
|
105
|
-
|
|
124
|
+
/** The value at a dotted path, reached through object properties only. */
|
|
125
|
+
function valueAt(structured, path) {
|
|
126
|
+
let value = structured;
|
|
127
|
+
for (const key of path.split('.')) {
|
|
128
|
+
value = asRecord(value)?.[key];
|
|
129
|
+
}
|
|
130
|
+
return value;
|
|
131
|
+
}
|
|
132
|
+
/** `structured` with the list at `path` replaced; every object on the way is copied. */
|
|
133
|
+
function withListAt(structured, path, list) {
|
|
134
|
+
const [key, ...rest] = path.split('.');
|
|
135
|
+
const record = asRecord(structured) ?? {};
|
|
136
|
+
if (key === undefined)
|
|
137
|
+
return structured;
|
|
138
|
+
return {
|
|
139
|
+
...record,
|
|
140
|
+
[key]: rest.length ? withListAt(record[key], rest.join('.'), list) : list,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/** Each item an item rule refuses, in the reply's own order. A path with no list has no items. */
|
|
144
|
+
async function collectItemFailures(structured, items, turn) {
|
|
145
|
+
const failures = [];
|
|
146
|
+
for (const [path, rule] of Object.entries(items ?? {})) {
|
|
147
|
+
const list = valueAt(structured, path);
|
|
148
|
+
if (!Array.isArray(list))
|
|
149
|
+
continue;
|
|
150
|
+
for (const [index, item] of list.entries()) {
|
|
151
|
+
const check = await rule.check(item, turn);
|
|
152
|
+
if (check.isValid)
|
|
153
|
+
continue;
|
|
154
|
+
failures.push({
|
|
155
|
+
path,
|
|
156
|
+
index,
|
|
157
|
+
item,
|
|
158
|
+
reason: check.error || check.finding || `Validation failed for '${path}'`, // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
|
|
159
|
+
onFail: rule.onFail,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return failures;
|
|
164
|
+
}
|
|
165
|
+
/** The schema of one item of the list at `path`, or `undefined` when the path reaches no list with one. */
|
|
166
|
+
function itemSchemaAt(jsonSchema, path) {
|
|
167
|
+
let schema = jsonSchema;
|
|
168
|
+
for (const key of path.split('.')) {
|
|
169
|
+
const object = asObjectSchema(schema);
|
|
170
|
+
if (!object)
|
|
171
|
+
return undefined;
|
|
172
|
+
schema = propertySchemas(object)[key];
|
|
173
|
+
}
|
|
174
|
+
const list = asRecord(schema);
|
|
175
|
+
if (list?.type !== 'array')
|
|
176
|
+
return undefined;
|
|
177
|
+
return asRecord(list.items) ?? undefined;
|
|
178
|
+
}
|
|
179
|
+
export { collectItemFailures, collectValidationFailures, formatValidationFailures, isAbsent, itemSchemaAt, schemaReaches, valueAt, withListAt, };
|
|
@@ -20,7 +20,7 @@ export interface ApplyTurnStageResult {
|
|
|
20
20
|
injectCount: number;
|
|
21
21
|
warnings: StageApplyWarning[];
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
23
|
+
/** Sanitized stage injects extend portable history. */
|
|
24
24
|
export declare function applyStageInjects(state: StepExecutionState, stage: TurnStage, units: readonly InjectUnit[], extra?: {
|
|
25
25
|
callId?: string;
|
|
26
26
|
toolName?: string;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { throwIfAborted } from '../../../guardrails/error.js';
|
|
2
2
|
import { injectedStageEvent, injectMessages, runStage, } from '../../stages.js';
|
|
3
3
|
import { profileAllowsInject } from '../../stop.js';
|
|
4
|
-
/**
|
|
4
|
+
/** Sanitized stage injects extend portable history. */
|
|
5
5
|
export function* applyStageInjects(state, stage, units, extra) {
|
|
6
6
|
const inject = injectMessages(units);
|
|
7
7
|
if (inject.length === 0)
|
|
8
8
|
return 0;
|
|
9
9
|
state.currentHistory.push(...inject);
|
|
10
|
-
if (state.interactionsContinuation) {
|
|
11
|
-
for (const msg of inject) {
|
|
12
|
-
if (msg.role === 'tool')
|
|
13
|
-
continue;
|
|
14
|
-
state.interactionsContinuation.messages.push(msg);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
10
|
const landed = injectedStageEvent(stage, units, extra);
|
|
18
11
|
if (landed) {
|
|
19
12
|
state.allEmittedEvents.push(landed);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { type TurnDestinations } from '../../../guardrails/destinations.js';
|
|
1
2
|
import { type GivenUrlSets } from '../../../guardrails/egress-urls.js';
|
|
3
|
+
import type { OwnTools } from '../../../guardrails/tool-leak.js';
|
|
2
4
|
import type { GuardrailHit, TurnTaint } from '../../../guardrails/types.js';
|
|
3
5
|
import type { SpanHandle } from '../../../observability/trace-span.js';
|
|
6
|
+
import type { AgentCaller } from '../../tools/agent.js';
|
|
4
7
|
import type { ToolRegistry } from '../../tools/registry.js';
|
|
5
|
-
import type { InteractionPart, ModelBinding, Profile, ResolvedGeneration, TurnEvent, TurnHistoryMessage, TurnRequest, TurnStop } from '../../types.js';
|
|
6
|
-
import type {
|
|
8
|
+
import type { InteractionPart, ModelBinding, Profile, ResolvedGeneration, TurnEvent, TurnHistoryMessage, TurnRequest, TurnStop, TurnToolResult } from '../../types.js';
|
|
9
|
+
import type { ItemFailure } from './schema-validation.js';
|
|
7
10
|
import type { CallUsage } from './usage.js';
|
|
8
11
|
interface TurnTraceState {
|
|
9
12
|
/** The turn's `invoke_agent` span; model calls and tools open under it. */
|
|
@@ -16,11 +19,13 @@ interface TurnTraceState {
|
|
|
16
19
|
interface StepExecutionState {
|
|
17
20
|
/** The turn's scope's tools: calls and provider builtins are looked up here. */
|
|
18
21
|
tools: ToolRegistry;
|
|
22
|
+
/** Runs the turn's agent tools; absent where none can run (a compactor's own turn). */
|
|
23
|
+
agents?: AgentCaller;
|
|
19
24
|
trace: TurnTraceState;
|
|
20
25
|
currentHistory: TurnHistoryMessage[];
|
|
21
26
|
stepCount: number;
|
|
22
|
-
/**
|
|
23
|
-
|
|
27
|
+
/** Model calls sent again this turn under the profile's resumption (`executeResumedStep`). */
|
|
28
|
+
resumes: number;
|
|
24
29
|
allEmittedEvents: TurnEvent[];
|
|
25
30
|
attemptEvents: TurnEvent[];
|
|
26
31
|
/**
|
|
@@ -28,6 +33,8 @@ interface StepExecutionState {
|
|
|
28
33
|
* streamed, so the attempt gate must release the buffered text rather than drop it.
|
|
29
34
|
*/
|
|
30
35
|
withheldVisible?: boolean;
|
|
36
|
+
/** The reply text the stream's gate released this attempt, as it released it. */
|
|
37
|
+
released: string;
|
|
31
38
|
/** The canary opening the last provider call ended on, read in front of the next call's reply. */
|
|
32
39
|
canaryCarry?: string;
|
|
33
40
|
/** What the last provider call's thoughts ended on, read in front of the next call's thoughts. */
|
|
@@ -36,23 +43,37 @@ interface StepExecutionState {
|
|
|
36
43
|
promptLeaks?: GuardrailHit[];
|
|
37
44
|
/** Untrusted content read so far, so a later tool call is judged against all the turn ingested. */
|
|
38
45
|
taint?: TurnTaint;
|
|
46
|
+
/** The destinations the turn has read, by who wrote them, so a tool call's own are judged against them. */
|
|
47
|
+
destinations: TurnDestinations;
|
|
39
48
|
/** Every URL the model has been given this turn (`GuardrailContext.givenUrls`). */
|
|
40
49
|
givenUrls: GivenUrlSets;
|
|
50
|
+
/** The names of the profile's tools and of their parameters (`GuardrailContext.ownTools`). */
|
|
51
|
+
ownTools?: OwnTools;
|
|
52
|
+
/** Set once the model is given the canary this turn (`GuardrailContext.canaryGiven`). */
|
|
53
|
+
canaryGiven: boolean;
|
|
54
|
+
/** What the canary scan already read this turn (`requestGivesCanary`). */
|
|
55
|
+
canaryScanned: WeakSet<object>;
|
|
56
|
+
/** Every tool call the turn completed, for the checks on a reply's items (`ItemCheckTurn`). */
|
|
57
|
+
toolResults: TurnToolResult[];
|
|
41
58
|
/** Last provider stop from a discarded provider `done` event. */
|
|
42
59
|
lastStop?: TurnStop;
|
|
43
|
-
|
|
44
|
-
/** Tool results and stage injects pending for the next step's Interactions `continuation`. */
|
|
45
|
-
interactionsContinuation?: {
|
|
46
|
-
previousInteractionId: string;
|
|
47
|
-
messages: TurnHistoryMessage[];
|
|
48
|
-
};
|
|
60
|
+
providerState?: import('../../checkpoint.js').ProviderCheckpoint;
|
|
49
61
|
/** Usage of the last model call; a continuation's prompt estimate extends it. */
|
|
50
62
|
lastCall?: CallUsage;
|
|
51
63
|
}
|
|
64
|
+
/** A reply waiting on its refused items: the attempt under way is rewriting only those. */
|
|
65
|
+
interface PendingItemFix {
|
|
66
|
+
/** The reply the items were refused in; the rewritten ones go back into it. */
|
|
67
|
+
reply: unknown;
|
|
68
|
+
refused: ItemFailure[];
|
|
69
|
+
/** The profile's own structured schema, put back once the rewrite returns. */
|
|
70
|
+
structured: ResolvedGeneration['structured'];
|
|
71
|
+
}
|
|
52
72
|
interface AttemptFlowState {
|
|
53
73
|
currentAttempt: number;
|
|
54
74
|
currentReq: TurnRequest;
|
|
55
75
|
currentGen: ResolvedGeneration;
|
|
76
|
+
pendingItemFix?: PendingItemFix;
|
|
56
77
|
}
|
|
57
78
|
declare function recordStepEvent(event: TurnEvent, state: StepExecutionState): void;
|
|
58
79
|
/** Append user parts to turn history as one user message (plain text stays a string). */
|
|
@@ -69,8 +90,8 @@ declare function openTurnState(args: {
|
|
|
69
90
|
profile: Profile;
|
|
70
91
|
generation: ResolvedGeneration;
|
|
71
92
|
trace: TurnTraceState;
|
|
72
|
-
mediaFamily: MediaTokenFamily | undefined;
|
|
73
93
|
allEmittedEvents?: TurnEvent[];
|
|
94
|
+
agents?: AgentCaller;
|
|
74
95
|
}): StepExecutionState;
|
|
75
|
-
export type { AttemptFlowState, StepExecutionState, TurnTraceState };
|
|
96
|
+
export type { AttemptFlowState, PendingItemFix, StepExecutionState, TurnTraceState };
|
|
76
97
|
export { appendUserInput, openTurnState, recordStepEvent };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { turnDestinations } from '../../../guardrails/destinations.js';
|
|
1
2
|
import { givenUrlSets } from '../../../guardrails/egress-urls.js';
|
|
3
|
+
import { ownToolsOf } from '../../tools/project.js';
|
|
2
4
|
function recordStepEvent(event, state) {
|
|
3
5
|
state.allEmittedEvents.push(event);
|
|
4
6
|
state.attemptEvents.push(event);
|
|
@@ -21,15 +23,23 @@ function appendUserInput(state, parts) {
|
|
|
21
23
|
*/
|
|
22
24
|
function openTurnState(args) {
|
|
23
25
|
const { profile, generation } = args;
|
|
26
|
+
const ownTools = ownToolsOf(args.tools, profile);
|
|
24
27
|
const state = {
|
|
25
28
|
tools: args.tools,
|
|
26
29
|
trace: args.trace,
|
|
27
30
|
currentHistory: [...(generation.history ?? [])],
|
|
28
31
|
stepCount: 0,
|
|
29
|
-
|
|
32
|
+
resumes: 0,
|
|
33
|
+
toolResults: [],
|
|
30
34
|
allEmittedEvents: args.allEmittedEvents ?? [],
|
|
31
35
|
attemptEvents: [],
|
|
36
|
+
released: '',
|
|
32
37
|
givenUrls: givenUrlSets(),
|
|
38
|
+
destinations: turnDestinations(),
|
|
39
|
+
canaryGiven: false,
|
|
40
|
+
canaryScanned: new WeakSet(),
|
|
41
|
+
...(ownTools ? { ownTools } : {}),
|
|
42
|
+
...(args.agents ? { agents: args.agents } : {}),
|
|
33
43
|
};
|
|
34
44
|
if (profile.type === 'text') {
|
|
35
45
|
appendUserInput(state, generation.input);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { StepWait } from '../../tools/stage-run.js';
|
|
2
|
+
import type { TurnEvent } from '../../types.js';
|
|
3
|
+
/** One step's calls: when each may start, and who waits for whom. */
|
|
4
|
+
export interface StepOrder {
|
|
5
|
+
/** Resolves when the call may start: at once side by side, once every call before it settles one at a time. */
|
|
6
|
+
start(callId: string): Promise<void>;
|
|
7
|
+
/** Marks the call settled; what waits for it goes on. */
|
|
8
|
+
settle(callId: string): void;
|
|
9
|
+
wait: StepWait;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The order of a step's calls. Side by side, every call starts at once. One at a time,
|
|
13
|
+
* each starts when every call before it has settled. A call whose `pre_tool` answers `waitFor`
|
|
14
|
+
* is held until those calls settle. A wait on a call outside the step fails; so does a wait
|
|
15
|
+
* that can never end, because the call waited for waits for this one or runs after it. Every
|
|
16
|
+
* call whose own wait closes such a loop fails.
|
|
17
|
+
*/
|
|
18
|
+
export declare function stepOrder(callIds: readonly string[], parallel: boolean, signal?: AbortSignal): StepOrder;
|
|
19
|
+
/** Runs a call's body once the step lets it start, and settles it however the body ends. */
|
|
20
|
+
export declare function inStep<T>(order: StepOrder, callId: string, body: () => AsyncGenerator<TurnEvent, T>): AsyncGenerator<TurnEvent, T>;
|
|
21
|
+
/**
|
|
22
|
+
* Runs tools side by side and passes on each event as it comes. Returns each run's
|
|
23
|
+
* settlement by its place in `runs`, `undefined` where there was no run.
|
|
24
|
+
*
|
|
25
|
+
* why: One run that throws ends them all; the rest are closed so none keeps running unseen.
|
|
26
|
+
*/
|
|
27
|
+
export declare function runSideBySide<T>(runs: (AsyncGenerator<TurnEvent, T | undefined> | undefined)[]): AsyncGenerator<TurnEvent, (T | undefined)[]>;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { throwIfAborted } from '../../../guardrails/error.js';
|
|
2
|
+
/**
|
|
3
|
+
* A promise and the function that settles it. `Promise.withResolvers` would do, but the React
|
|
4
|
+
* package compiles the kernel against ES2023, which lacks it.
|
|
5
|
+
*/
|
|
6
|
+
function settleable() {
|
|
7
|
+
let resolve = () => undefined;
|
|
8
|
+
const promise = new Promise((settle) => {
|
|
9
|
+
resolve = settle;
|
|
10
|
+
});
|
|
11
|
+
return { promise, resolve };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The order of a step's calls. Side by side, every call starts at once. One at a time,
|
|
15
|
+
* each starts when every call before it has settled. A call whose `pre_tool` answers `waitFor`
|
|
16
|
+
* is held until those calls settle. A wait on a call outside the step fails; so does a wait
|
|
17
|
+
* that can never end, because the call waited for waits for this one or runs after it. Every
|
|
18
|
+
* call whose own wait closes such a loop fails.
|
|
19
|
+
*/
|
|
20
|
+
export function stepOrder(callIds, parallel, signal) {
|
|
21
|
+
const settled = new Set();
|
|
22
|
+
const done = new Map(callIds.map((id) => [id, settleable()]));
|
|
23
|
+
const waits = new Map();
|
|
24
|
+
const held = new Map();
|
|
25
|
+
const unhook = new Map();
|
|
26
|
+
const earlier = (callId) => (parallel ? [] : callIds.slice(0, callIds.indexOf(callId)));
|
|
27
|
+
for (const id of callIds) {
|
|
28
|
+
const before = earlier(id);
|
|
29
|
+
if (before.length > 0)
|
|
30
|
+
waits.set(id, new Map(before.map((target) => [target, 'after'])));
|
|
31
|
+
}
|
|
32
|
+
/** The calls from `from` to `to` along unsettled waits, or `undefined` when none leads there. */
|
|
33
|
+
const pathTo = (from, to, seen = new Set()) => {
|
|
34
|
+
if (from === to)
|
|
35
|
+
return [to];
|
|
36
|
+
if (seen.has(from) || settled.has(from))
|
|
37
|
+
return undefined;
|
|
38
|
+
seen.add(from);
|
|
39
|
+
for (const next of waits.get(from)?.keys() ?? []) {
|
|
40
|
+
const rest = pathTo(next, to, seen);
|
|
41
|
+
if (rest)
|
|
42
|
+
return [from, ...rest];
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
};
|
|
46
|
+
const release = (id, outcome) => {
|
|
47
|
+
held.get(id)?.(outcome);
|
|
48
|
+
held.delete(id);
|
|
49
|
+
unhook.get(id)?.();
|
|
50
|
+
unhook.delete(id);
|
|
51
|
+
for (const [target, kind] of waits.get(id) ?? []) {
|
|
52
|
+
if (kind === 'asked')
|
|
53
|
+
waits.get(id)?.delete(target);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const doneOf = (id) => done.get(id)?.promise ?? Promise.resolve();
|
|
57
|
+
return {
|
|
58
|
+
start: async (callId) => {
|
|
59
|
+
await Promise.all(earlier(callId).map(doneOf));
|
|
60
|
+
throwIfAborted(signal);
|
|
61
|
+
},
|
|
62
|
+
settle: (callId) => {
|
|
63
|
+
settled.add(callId);
|
|
64
|
+
waits.delete(callId);
|
|
65
|
+
done.get(callId)?.resolve();
|
|
66
|
+
},
|
|
67
|
+
wait: (callId, waitFor) => {
|
|
68
|
+
const unknown = waitFor.filter((id) => !done.has(id));
|
|
69
|
+
if (unknown.length > 0) {
|
|
70
|
+
return Promise.resolve({ ok: false, reason: 'unknown', callIds: unknown });
|
|
71
|
+
}
|
|
72
|
+
const pending = waitFor.filter((id) => !settled.has(id));
|
|
73
|
+
if (pending.length === 0)
|
|
74
|
+
return Promise.resolve({ ok: true });
|
|
75
|
+
const own = waits.get(callId) ?? new Map();
|
|
76
|
+
waits.set(callId, own);
|
|
77
|
+
for (const id of pending)
|
|
78
|
+
own.set(id, 'asked');
|
|
79
|
+
const loops = pending.flatMap((id) => {
|
|
80
|
+
const path = pathTo(id, callId);
|
|
81
|
+
return path ? [{ id, path }] : [];
|
|
82
|
+
});
|
|
83
|
+
if (loops.length > 0) {
|
|
84
|
+
// why: Every call whose own wait is part of the loop is held for nothing that can come; each fails.
|
|
85
|
+
for (const { path } of loops) {
|
|
86
|
+
for (const [index, id] of path.entries()) {
|
|
87
|
+
const next = path[index + 1];
|
|
88
|
+
if (next !== undefined && id !== callId && waits.get(id)?.get(next) === 'asked') {
|
|
89
|
+
release(id, { ok: false, reason: 'cycle', callIds: [next] });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
release(callId, { ok: false, reason: 'cycle', callIds: loops.map(({ id }) => id) });
|
|
94
|
+
return Promise.resolve({
|
|
95
|
+
ok: false,
|
|
96
|
+
reason: 'cycle',
|
|
97
|
+
callIds: loops.map(({ id }) => id),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const outcome = settleable();
|
|
101
|
+
held.set(callId, outcome.resolve);
|
|
102
|
+
Promise.all(pending.map(doneOf)).then(() => release(callId, { ok: true }));
|
|
103
|
+
const aborted = new Promise((_, reject) => {
|
|
104
|
+
if (!signal)
|
|
105
|
+
return;
|
|
106
|
+
const onAbort = () => reject(signal.reason);
|
|
107
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
108
|
+
unhook.set(callId, () => signal.removeEventListener('abort', onAbort));
|
|
109
|
+
});
|
|
110
|
+
// why: An aborted turn ends the wait with the abort; the call settles as aborted.
|
|
111
|
+
aborted.catch(() => { });
|
|
112
|
+
return Promise.race([outcome.promise, aborted]);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
/** Runs a call's body once the step lets it start, and settles it however the body ends. */
|
|
117
|
+
export async function* inStep(order, callId, body) {
|
|
118
|
+
try {
|
|
119
|
+
await order.start(callId);
|
|
120
|
+
return yield* body();
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
order.settle(callId);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Runs tools side by side and passes on each event as it comes. Returns each run's
|
|
128
|
+
* settlement by its place in `runs`, `undefined` where there was no run.
|
|
129
|
+
*
|
|
130
|
+
* why: One run that throws ends them all; the rest are closed so none keeps running unseen.
|
|
131
|
+
*/
|
|
132
|
+
export async function* runSideBySide(runs) {
|
|
133
|
+
const settled = runs.map(() => undefined);
|
|
134
|
+
const waiting = new Map();
|
|
135
|
+
const pull = (index, run) => {
|
|
136
|
+
const next = run.next().then((result) => ({ index, next: result }));
|
|
137
|
+
// why: A run that fails after another already threw is closed below; its failure has nowhere to go.
|
|
138
|
+
next.catch(() => { });
|
|
139
|
+
waiting.set(index, next);
|
|
140
|
+
};
|
|
141
|
+
runs.forEach((run, index) => {
|
|
142
|
+
if (run)
|
|
143
|
+
pull(index, run);
|
|
144
|
+
});
|
|
145
|
+
try {
|
|
146
|
+
while (waiting.size > 0) {
|
|
147
|
+
const { index, next } = await Promise.race(waiting.values());
|
|
148
|
+
waiting.delete(index);
|
|
149
|
+
const run = runs[index];
|
|
150
|
+
if (next.done || !run) {
|
|
151
|
+
if (next.done)
|
|
152
|
+
settled[index] = next.value;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
yield next.value;
|
|
156
|
+
pull(index, run);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
for (const index of waiting.keys()) {
|
|
161
|
+
runs[index]?.return(undefined).catch(() => { });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return settled;
|
|
165
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { BoundSystem } from '../../system-parts.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Profile, ResolvedGeneration, TurnEvent, TurnModel, TurnRequest } from '../../types.js';
|
|
3
3
|
import { type StepExecutionState } from './state.js';
|
|
4
4
|
declare function executeAttempt(args: {
|
|
5
5
|
safe: TurnRequest;
|
|
6
6
|
profile: Profile;
|
|
7
7
|
generation: ResolvedGeneration;
|
|
8
8
|
system: BoundSystem;
|
|
9
|
-
provider:
|
|
9
|
+
provider: TurnModel;
|
|
10
10
|
state: StepExecutionState;
|
|
11
11
|
}): AsyncGenerator<TurnEvent, {
|
|
12
12
|
latestStructured?: unknown;
|