@danceiny/gotry 0.0.1-rc.9 → 0.2.0-rc.27
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 +172 -219
- package/README.zh-CN.md +222 -0
- package/bin/gotry-backend.js +53 -0
- package/bin/gotry-booking-copilot.js +53 -0
- package/bin/gotry-bootstrap.js +1744 -0
- package/bin/gotry-inner.js +733 -83
- package/bin/gotry-process-liveness.d.ts +27 -0
- package/bin/gotry-process-liveness.js +97 -0
- package/bin/gotry-runtime-resolution.d.ts +27 -0
- package/bin/gotry-runtime-resolution.js +49 -0
- package/bin/gotry.js +1 -1
- package/client/client.js +203 -0
- package/cordis.gotry-patch.yml +80 -56
- package/data/airline-airports.json +39 -0
- package/data/stations-12306-verify.json +524 -0
- package/dist/capabilities/agent-reach-deep.js +45 -122
- package/dist/capabilities/agent-reach.js +101 -146
- package/dist/capabilities/anything.js +135 -94
- package/dist/capabilities/artifacts.js +370 -0
- package/dist/capabilities/channel-health.js +131 -0
- package/dist/capabilities/channel-registry.js +256 -0
- package/dist/capabilities/doctor.js +546 -0
- package/dist/capabilities/effect.js +394 -0
- package/dist/capabilities/external-event.js +149 -0
- package/dist/capabilities/fact-log.js +55 -0
- package/dist/capabilities/flyai-config.js +337 -0
- package/dist/capabilities/flyai.js +947 -110
- package/dist/capabilities/fx-contract.js +293 -0
- package/dist/capabilities/geo-atlas.js +246 -0
- package/dist/capabilities/ground-transfer.js +509 -0
- package/dist/capabilities/hbcli.js +260 -123
- package/dist/capabilities/hotelbyte-transaction.js +194 -0
- package/dist/capabilities/incident-log.js +131 -61
- package/dist/capabilities/itinerary-artifact.js +190 -0
- package/dist/capabilities/itinerary-deck-artifact.js +194 -0
- package/dist/capabilities/itinerary-deck-export.js +339 -0
- package/dist/capabilities/lavish-local.js +924 -0
- package/dist/capabilities/model-override.js +38 -0
- package/dist/capabilities/opensky.js +54 -43
- package/dist/capabilities/resilience.js +191 -0
- package/dist/capabilities/session/action-cache.js +50 -44
- package/dist/capabilities/session/adapters/ctrip-flight.js +120 -62
- package/dist/capabilities/session/adapters/ctrip-hotel.js +222 -0
- package/dist/capabilities/session/adapters/dida-portal.js +274 -0
- package/dist/capabilities/session/adapters/meituan-local.js +35 -54
- package/dist/capabilities/session/adapters/rail-12306.js +342 -0
- package/dist/capabilities/session/benchmark.js +189 -0
- package/dist/capabilities/session/bridge-ledger.js +224 -0
- package/dist/capabilities/session/extension-bridge.js +636 -0
- package/dist/capabilities/session/extension-channel.js +109 -0
- package/dist/capabilities/session/extension-distribution.js +230 -0
- package/dist/capabilities/session/extract.js +31 -21
- package/dist/capabilities/session/golden-score.js +114 -0
- package/dist/capabilities/session/health-watch.js +215 -0
- package/dist/capabilities/session/read-guard.js +75 -24
- package/dist/capabilities/session/static-flight-golden.js +150 -0
- package/dist/capabilities/session/transport.js +97 -83
- package/dist/capabilities/session/wizard.js +117 -0
- package/dist/capabilities/session-consent.js +178 -0
- package/dist/capabilities/session-login.js +170 -0
- package/dist/capabilities/session-search.js +635 -44
- package/dist/capabilities/spawn-bounded.js +203 -0
- package/dist/capabilities/sponsor-plugin.js +341 -0
- package/dist/capabilities/visa-policy.js +140 -0
- package/dist/capabilities/weather.js +243 -138
- package/dist/data/session-golden-20.json +25 -0
- package/dist/data/sf-golden-manifest.json +103 -0
- package/dist/data/sf-static-routes.json +91 -0
- package/dist/scripts/action-cache-tests.js +24 -59
- package/dist/scripts/agent-planning-turn-deadline-e2e.js +242 -0
- package/dist/scripts/agent-planning-turn-deadline-tests.js +185 -0
- package/dist/scripts/agent-reach-deep-tests.js +30 -40
- package/dist/scripts/agent-reach-error-tests.js +354 -0
- package/dist/scripts/agent-reach-tests.js +26 -18
- package/dist/scripts/agent-reach-wrapper-tests.js +50 -50
- package/dist/scripts/anything-tests.js +116 -60
- package/dist/scripts/artifact-client-contract-tests.js +220 -0
- package/dist/scripts/artifacts-capability-tests.js +727 -0
- package/dist/scripts/async-collect.js +50 -11
- package/dist/scripts/benchmark-environment-bridge-e2e.js +741 -0
- package/dist/scripts/benchmark-environment-bridge-tests.js +1452 -0
- package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +126 -0
- package/dist/scripts/booking-copilot-availability-policy-tests.js +265 -0
- package/dist/scripts/booking-copilot-bin-proof-tests.js +66 -0
- package/dist/scripts/booking-copilot-cleanup-proof-helper.js +76 -0
- package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +144 -0
- package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +424 -0
- package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +2839 -0
- package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +309 -0
- package/dist/scripts/booking-copilot-dsh-readiness-proof.js +238 -0
- package/dist/scripts/booking-copilot-dsh-warmer-proof.js +123 -0
- package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +156 -0
- package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +70 -0
- package/dist/scripts/booking-copilot-intent-proof-tests.js +422 -0
- package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +184 -0
- package/dist/scripts/booking-copilot-planner-live-probe.js +95 -0
- package/dist/scripts/booking-copilot-proof-runtime.js +42 -0
- package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +210 -0
- package/dist/scripts/booking-copilot-runtime-proof-tests.js +2349 -0
- package/dist/scripts/booking-copilot-server-proof-tests.js +784 -0
- package/dist/scripts/booking-copilot-startup-proof-tests.js +94 -0
- package/dist/scripts/booking-executor-tests.js +80 -0
- package/dist/scripts/booking-recovery-chain-tests.js +182 -0
- package/dist/scripts/booking-saga-tests.js +125 -0
- package/dist/scripts/booking-surface-contract-proof-tests.js +212 -0
- package/dist/scripts/bootstrap-tests.js +1479 -0
- package/dist/scripts/bridge-events-tests.js +239 -0
- package/dist/scripts/bridge-ledger-tests.js +428 -0
- package/dist/scripts/build-changelog.js +238 -0
- package/dist/scripts/build-metrics-report.js +331 -0
- package/dist/scripts/changelog-tests.js +118 -0
- package/dist/scripts/channel-probe-tests.js +103 -0
- package/dist/scripts/channel-probe.js +169 -0
- package/dist/scripts/channel-registry-tests.js +208 -0
- package/dist/scripts/companion-tests.js +25 -70
- package/dist/scripts/dida-cookie-probe.js +87 -0
- package/dist/scripts/dida-runner-stop-tests.js +311 -0
- package/dist/scripts/dida-sw-probe.js +114 -0
- package/dist/scripts/diff-test.js +17 -12
- package/dist/scripts/doctor-tests.js +564 -0
- package/dist/scripts/dsh-artifact-e2e.js +279 -0
- package/dist/scripts/dsh-artifact-web-e2e.js +675 -0
- package/dist/scripts/dsh-http-proxy-sse-proof.js +90 -0
- package/dist/scripts/dsh-runtime-closure-tests.js +182 -0
- package/dist/scripts/dsh-runtime-closure.js +162 -0
- package/dist/scripts/dsh-session-v3-migration-proof.js +109 -0
- package/dist/scripts/dsh-subprocess-local-proof.js +150 -0
- package/dist/scripts/dsh-target-closure-proof.js +178 -0
- package/dist/scripts/effect-tests.js +539 -0
- package/dist/scripts/engine-run.js +1 -3
- package/dist/scripts/engine-tests.js +16 -10
- package/dist/scripts/evaluation-cadence-tests.js +174 -0
- package/dist/scripts/evaluation-contract-tests.js +268 -0
- package/dist/scripts/extension-distribution-cli.js +39 -0
- package/dist/scripts/extension-distribution-tests.js +443 -0
- package/dist/scripts/extension-tests.js +988 -0
- package/dist/scripts/external-event-tests.js +350 -0
- package/dist/scripts/fact-gate-tests.js +869 -0
- package/dist/scripts/fixtures/extension-bridge-unref-child.mjs +21 -0
- package/dist/scripts/flight-hotel-anchor-363-registered-e2e.js +169 -0
- package/dist/scripts/flight-malformed-tests.js +159 -0
- package/dist/scripts/flyai-setup-tests.js +228 -0
- package/dist/scripts/flyai-setup-tool-tests.js +54 -0
- package/dist/scripts/flyai-tests.js +692 -0
- package/dist/scripts/flyai-tool-registration-contract-tests.js +91 -0
- package/dist/scripts/fx-contract-tests.js +201 -0
- package/dist/scripts/g5-guard-tests.js +131 -0
- package/dist/scripts/g5-guard.js +189 -0
- package/dist/scripts/gen-lunar-anchors.js +106 -0
- package/dist/scripts/geo-atlas-tests.js +283 -0
- package/dist/scripts/gotry-backend-kernel-tests.js +206 -0
- package/dist/scripts/gotry-try-demo-tests.js +79 -0
- package/dist/scripts/gotry-try-demo.js +49 -0
- package/dist/scripts/ground-transfer-tests.js +956 -0
- package/dist/scripts/hbcli-e2e-tests.js +159 -0
- package/dist/scripts/hbcli-live-optin-tests.js +96 -0
- package/dist/scripts/hbcli-release-contract-tests.js +122 -0
- package/dist/scripts/hbcli-tests.js +121 -69
- package/dist/scripts/health-watch-cli.js +73 -0
- package/dist/scripts/hotel-date-gate-tests.js +496 -0
- package/dist/scripts/hotelbyte-reconcile-tests.js +141 -0
- package/dist/scripts/hotelbyte-spawn-e2e-tests.js +373 -0
- package/dist/scripts/i18n-tests.js +41 -0
- package/dist/scripts/incident-tests.js +281 -87
- package/dist/scripts/issue-194-job-id-guard-tests.js +106 -0
- package/dist/scripts/issue-233-cancel-refund-commission-tests.js +392 -0
- package/dist/scripts/issue-271-liveness-tests.js +569 -0
- package/dist/scripts/issue-289-model-retry-real-tests.js +296 -0
- package/dist/scripts/issue-289-model-retry-tests.js +441 -0
- package/dist/scripts/issue-289-web-retry-e2e.js +630 -0
- package/dist/scripts/issue-338-home-city-e2e.js +577 -0
- package/dist/scripts/issue343-real-entry-e2e.js +160 -0
- package/dist/scripts/issue436-persisted-routing-e2e.js +247 -0
- package/dist/scripts/itinerary-artifact-tests.js +368 -0
- package/dist/scripts/itinerary-deck-artifact-tests.js +416 -0
- package/dist/scripts/itinerary-deck-export-tests.js +552 -0
- package/dist/scripts/itinerary-deck-tests.js +435 -0
- package/dist/scripts/itinerary-html-tests.js +426 -0
- package/dist/scripts/journey-tests.js +22 -27
- package/dist/scripts/kernel-manifest-evidence.js +109 -0
- package/dist/scripts/kernel-manifest-gate.js +126 -0
- package/dist/scripts/kernel-manifest-tests.js +212 -0
- package/dist/scripts/kernel-manifest-trace-entry.js +7 -0
- package/dist/scripts/kernel-manifest-trace-hook.mjs +28 -0
- package/dist/scripts/kernel-manifest.js +369 -0
- package/dist/scripts/lavish-local-tests.js +1226 -0
- package/dist/scripts/lavish-product-tools-tests.js +537 -0
- package/dist/scripts/ledger-repair-apply-tests.js +316 -0
- package/dist/scripts/ledger-repair-plan-tests.js +375 -0
- package/dist/scripts/ledger-tests.js +382 -246
- package/dist/scripts/ledger-workflow-crash.js +10 -20
- package/dist/scripts/managed-dsh-cleanup-diagnostic-proof.js +184 -0
- package/dist/scripts/managed-dsh-close-failure-proof.js +172 -0
- package/dist/scripts/managed-dsh-run-port-proof.js +153 -0
- package/dist/scripts/managed-dsh-terminal-proof.js +252 -0
- package/dist/scripts/map-tools-vendor-package-proof.js +365 -0
- package/dist/scripts/memory-capture-tests.js +242 -61
- package/dist/scripts/memory-decay-tests.js +18 -52
- package/dist/scripts/memory-lifecycle-tests.js +657 -0
- package/dist/scripts/memory-lifecycle.js +196 -0
- package/dist/scripts/memory-metrics.js +24 -12
- package/dist/scripts/memory-value-report.js +631 -0
- package/dist/scripts/memory-value-tests.js +328 -0
- package/dist/scripts/metrics-report-tests.js +151 -0
- package/dist/scripts/model-override-e2e.js +137 -0
- package/dist/scripts/nightly-evidence-tests.js +161 -0
- package/dist/scripts/nightly-evidence.js +286 -0
- package/dist/scripts/nudge-digest.js +39 -28
- package/dist/scripts/observability-tests.js +381 -0
- package/dist/scripts/onboarding-tests.js +161 -0
- package/dist/scripts/opensky-check.js +18 -13
- package/dist/scripts/opensky-tests.js +28 -28
- package/dist/scripts/persona-surface-guard-tests.js +49 -0
- package/dist/scripts/pnpm-dsh-closure-proof.js +17 -0
- package/dist/scripts/policy-anchor-359-registered-e2e.js +214 -0
- package/dist/scripts/price-drift-tests.js +340 -0
- package/dist/scripts/price-drift-watch.js +447 -0
- package/dist/scripts/probe-poi-tests.js +53 -45
- package/dist/scripts/product-metrics.js +483 -0
- package/dist/scripts/publish-preverify.js +110 -0
- package/dist/scripts/realtime-pricing-tests.js +76 -0
- package/dist/scripts/recall-tests.js +513 -0
- package/dist/scripts/replay-async.js +20 -18
- package/dist/scripts/replay-real.js +18 -18
- package/dist/scripts/replay.js +52 -82
- package/dist/scripts/session-attach-diagnose.js +20 -20
- package/dist/scripts/session-attach-poc.js +34 -37
- package/dist/scripts/session-benchmark.js +180 -0
- package/dist/scripts/session-dida-live-e2e.js +199 -0
- package/dist/scripts/session-extract-tests.js +14 -35
- package/dist/scripts/session-link-tests.js +478 -0
- package/dist/scripts/session-login.js +27 -46
- package/dist/scripts/session-tests.js +796 -96
- package/dist/scripts/session-zones-tests.js +358 -0
- package/dist/scripts/sf-live-benchmark.js +367 -0
- package/dist/scripts/sf-live-challenge-stop-tests.js +453 -0
- package/dist/scripts/sf-live-cli-tests.js +92 -0
- package/dist/scripts/sf-live-options.js +46 -0
- package/dist/scripts/sf-manifest-tests.js +30 -0
- package/dist/scripts/sf-manifest.js +33 -0
- package/dist/scripts/sf-soft-score-tests.js +67 -0
- package/dist/scripts/sf-summary-tests.js +324 -0
- package/dist/scripts/sf-summary.js +525 -0
- package/dist/scripts/share-tests.js +432 -0
- package/dist/scripts/skeleton-check.js +16 -14
- package/dist/scripts/skeleton-integration-test.js +28 -11
- package/dist/scripts/skills-contract-tests.js +51 -46
- package/dist/scripts/smoke-session-gate-tests.js +21 -0
- package/dist/scripts/smoke.js +690 -246
- package/dist/scripts/spawn-bounded-abort-tests.js +241 -0
- package/dist/scripts/sponsor-reuse-tests.js +262 -0
- package/dist/scripts/state-cli-tests.js +226 -101
- package/dist/scripts/state-cli.js +550 -199
- package/dist/scripts/state-repair-cli.js +66 -0
- package/dist/scripts/state-repair-tests.js +140 -0
- package/dist/scripts/static-golden-tests.js +165 -0
- package/dist/scripts/time-eval-tests.js +210 -192
- package/dist/scripts/travel-timeline-tests.js +29 -93
- package/dist/scripts/turn-handoff-collect-tests.js +169 -0
- package/dist/scripts/turn-handoff-collect.js +161 -0
- package/dist/scripts/turn-policy-tests.js +55 -0
- package/dist/scripts/typed-contract-canary.js +176 -0
- package/dist/scripts/tz-resolver-sanity.js +50 -0
- package/dist/scripts/tz-resolver-tests.js +584 -0
- package/dist/scripts/unified-tests.js +23 -19
- package/dist/scripts/visa-policy-tests.js +62 -0
- package/dist/scripts/weather-tests.js +276 -41
- package/dist/scripts/wish-channel-gate-tests.js +54 -0
- package/dist/scripts/write-gate-tests.js +522 -0
- package/dist/scripts/z3-lifecycle-fault-tests.js +188 -0
- package/dist/scripts/z3-lifecycle-tests.js +170 -0
- package/dist/scripts/z3-race-repeat-tests.js +39 -0
- package/dist/scripts/z3-race-tests.js +41 -0
- package/dist/src/artifact-gate.js +829 -0
- package/dist/src/backend/kernel.js +91 -0
- package/dist/src/backend/modules/booking-copilot.js +92 -0
- package/dist/src/backend/modules/booking-executor.js +124 -0
- package/dist/src/backend/modules/session-search.js +551 -0
- package/dist/src/benchmark-agent-conformance.js +578 -0
- package/dist/src/benchmark-environment-bridge.js +515 -0
- package/dist/src/benchmark-headless-child-diagnostics.js +166 -0
- package/dist/src/benchmark-tool-isolation.js +151 -0
- package/dist/src/bookable-facts.js +533 -0
- package/dist/src/booking-saga.js +97 -0
- package/dist/src/booking-surface/availability-policy.js +697 -0
- package/dist/src/booking-surface/booking-intent.js +43 -0
- package/dist/src/booking-surface/cancel-refund-commission.js +379 -0
- package/dist/src/booking-surface/canonical-schema.js +116 -0
- package/dist/src/booking-surface/contracts.js +75 -0
- package/dist/src/booking-surface/dsh-planner.js +1854 -0
- package/dist/src/booking-surface/dsh-plugin.js +378 -0
- package/dist/src/booking-surface/dsh-worker.js +98 -0
- package/dist/src/booking-surface/error-codes.js +231 -0
- package/dist/src/booking-surface/index.js +9 -0
- package/dist/src/booking-surface/managed-dsh-cleanup-diagnostic.js +97 -0
- package/dist/src/booking-surface/managed-dsh-run-port.js +244 -0
- package/dist/src/booking-surface/profile.js +24 -0
- package/dist/src/booking-surface/recovery-chain.js +367 -0
- package/dist/src/booking-surface/runtime.js +1968 -0
- package/dist/src/booking-surface/server.js +674 -0
- package/dist/src/booking-surface/startup.js +168 -0
- package/dist/src/booking-surface/validation.js +261 -0
- package/dist/src/bridge.js +20 -13
- package/dist/src/companions.js +48 -74
- package/dist/src/contracts.js +21 -43
- package/dist/src/dsh-llm.js +97 -111
- package/dist/src/engine.js +276 -193
- package/dist/src/evaluation-cadence.js +97 -0
- package/dist/src/evaluation-contracts.js +283 -0
- package/dist/src/flight-pack-adapter.js +54 -0
- package/dist/src/flight-pack-contract.js +2 -0
- package/dist/src/flyai-setup-tool.js +70 -0
- package/dist/src/gotry-backend.js +125 -0
- package/dist/src/hotel-date-gate.js +118 -0
- package/dist/src/i18n.js +88 -0
- package/dist/src/index.js +2227 -882
- package/dist/src/itinerary-deck.js +139 -0
- package/dist/src/itinerary-doc-shared.js +661 -0
- package/dist/src/itinerary-html.js +131 -0
- package/dist/src/journey.js +155 -108
- package/dist/src/lavish-tools.js +400 -0
- package/dist/src/ledger-repair-apply.js +538 -0
- package/dist/src/ledger-repair-plan.js +463 -0
- package/dist/src/loop.js +319 -160
- package/dist/src/memory-capture.js +180 -32
- package/dist/src/memory-decay.js +30 -14
- package/dist/src/memory-lifecycle.js +1310 -0
- package/dist/src/memory-utility.js +27 -40
- package/dist/src/mock-llm.js +36 -61
- package/dist/src/model.js +81 -36
- package/dist/src/realtime-pricing.js +103 -0
- package/dist/src/recall/card.js +74 -0
- package/dist/src/recall/evaluator.js +140 -0
- package/dist/src/recall/integration.js +17 -0
- package/dist/src/recall/tick.js +166 -0
- package/dist/src/session-link/plan-it-action.js +48 -0
- package/dist/src/session-link/session-link.js +248 -0
- package/dist/src/session-zones.js +507 -0
- package/dist/src/share/adapters.js +51 -0
- package/dist/src/share/share-consent.js +76 -0
- package/dist/src/share/share-deck.js +58 -0
- package/dist/src/share/share-token.js +146 -0
- package/dist/src/slot-spec.js +84 -106
- package/dist/src/state-ledger.js +435 -516
- package/dist/src/state-repair.js +299 -0
- package/dist/src/subagent-job-id-guard.js +58 -0
- package/dist/src/time-anchor.js +231 -33
- package/dist/src/tool-packet.js +20 -8
- package/dist/src/travel-slots.js +58 -35
- package/dist/src/travel-timeline.js +44 -63
- package/dist/src/turn-deadline.js +287 -0
- package/dist/src/turn-policy.js +118 -0
- package/dist/src/tz-resolver.js +143 -0
- package/dist/src/unified.js +535 -359
- package/dist/src/wish-pool.js +42 -12
- package/dist/src/write-gate.js +495 -0
- package/dist/src/z3-shared.js +284 -0
- package/extension/README.md +21 -0
- package/extension/README.zh-CN.md +21 -0
- package/extension/background.js +463 -0
- package/extension/content-bridge.js +270 -0
- package/extension/content-main.js +111 -0
- package/extension/manifest.json +60 -0
- package/package.json +407 -14
- package/schemas/booking.intent.schema.json +193 -0
- package/schemas/booking.surface.schema.json +2622 -0
- package/ts/capabilities/agent-reach-deep.ts +114 -0
- package/ts/capabilities/agent-reach.ts +198 -0
- package/ts/capabilities/anything.ts +255 -0
- package/ts/capabilities/artifacts.ts +428 -0
- package/ts/capabilities/fact-log.ts +54 -0
- package/ts/capabilities/flyai-config.ts +388 -0
- package/ts/capabilities/flyai.ts +1274 -0
- package/ts/capabilities/hbcli.ts +253 -71
- package/ts/capabilities/incident-log.ts +88 -59
- package/ts/capabilities/itinerary-artifact.ts +214 -0
- package/ts/capabilities/itinerary-deck-artifact.ts +218 -0
- package/ts/capabilities/itinerary-deck-export.ts +378 -0
- package/ts/capabilities/opensky.ts +121 -0
- package/ts/capabilities/session/action-cache.ts +148 -0
- package/ts/capabilities/session/adapters/ctrip-flight.ts +181 -0
- package/ts/capabilities/session/adapters/ctrip-hotel.ts +238 -0
- package/ts/capabilities/session/adapters/dida-portal.ts +338 -0
- package/ts/capabilities/session/adapters/meituan-local.ts +70 -0
- package/ts/capabilities/session/adapters/rail-12306.ts +392 -0
- package/ts/capabilities/session/benchmark.ts +276 -0
- package/ts/capabilities/session/bridge-ledger.ts +333 -0
- package/ts/capabilities/session/extension-bridge.ts +794 -0
- package/ts/capabilities/session/extension-channel.ts +144 -0
- package/ts/capabilities/session/extension-distribution.ts +266 -0
- package/ts/capabilities/session/extract.ts +54 -0
- package/ts/capabilities/session/golden-score.ts +139 -0
- package/ts/capabilities/session/health-watch.ts +264 -0
- package/ts/capabilities/session/read-guard.ts +141 -0
- package/ts/capabilities/session/static-flight-golden.ts +209 -0
- package/ts/capabilities/session/transport.ts +146 -0
- package/ts/capabilities/session/wizard.ts +140 -0
- package/ts/capabilities/session-consent.ts +211 -0
- package/ts/capabilities/session-login.ts +208 -0
- package/ts/capabilities/session-search.ts +893 -0
- package/ts/capabilities/weather.ts +330 -0
- package/ts/dsh-runtime/vendor/README.md +68 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/LICENSE +21 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.en.md +405 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/README.md +404 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/client/client.js +1584 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/cordis.patch.yml +5 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/icon.svg +5 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/amap.js +595 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/nominatim.js +63 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/osrm.js +58 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/clients/photon.js +55 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-file.js +87 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config-route.js +131 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/config.js +16 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/geo.js +232 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/index.js +120 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/settings-ns.js +40 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/staticmap-route.js +115 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/geocode.js +127 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/poi.js +84 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/tools/routes.js +267 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/amap.d.ts +90 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/nominatim.d.ts +17 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/osrm.d.ts +15 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/clients/photon.d.ts +22 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-file.d.ts +33 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config-route.d.ts +23 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/config.d.ts +23 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/geo.d.ts +61 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/index.d.ts +18 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/settings-ns.d.ts +14 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/staticmap-route.d.ts +31 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/geocode.d.ts +11 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/poi.d.ts +9 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/tools/routes.d.ts +75 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types/types.d.ts +68 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/lib/types.js +16 -0
- package/ts/dsh-runtime/vendor/dsh-map-tools/package.json +97 -0
- package/ts/package.json +293 -3
- package/ts/scripts/async-collect.ts +91 -0
- package/ts/scripts/map-tools-vendor-package-proof.ts +404 -0
- package/ts/scripts/skeleton-check.ts +1 -1
- package/ts/scripts/skeleton-integration-test.ts +23 -1
- package/ts/scripts/state-cli.ts +568 -0
- package/ts/scripts/turn-handoff-collect.ts +178 -0
- package/ts/src/artifact-gate.ts +991 -0
- package/ts/src/benchmark-agent-conformance.ts +619 -0
- package/ts/src/benchmark-environment-bridge.ts +538 -0
- package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
- package/ts/src/benchmark-tool-isolation.ts +166 -0
- package/ts/src/bookable-facts.ts +837 -0
- package/ts/src/booking-saga.ts +133 -0
- package/ts/src/booking-surface/availability-policy.ts +522 -0
- package/ts/src/booking-surface/booking-intent.ts +86 -0
- package/ts/src/booking-surface/cancel-refund-commission.ts +488 -0
- package/ts/src/booking-surface/canonical-schema.js +116 -0
- package/ts/src/booking-surface/contracts.ts +475 -0
- package/ts/src/booking-surface/dsh-planner.ts +1949 -0
- package/ts/src/booking-surface/dsh-plugin.js +378 -0
- package/ts/src/booking-surface/dsh-worker.ts +110 -0
- package/ts/src/booking-surface/error-codes.ts +241 -0
- package/ts/src/booking-surface/index.ts +9 -0
- package/ts/src/booking-surface/managed-dsh-cleanup-diagnostic.ts +151 -0
- package/ts/src/booking-surface/managed-dsh-run-port.ts +273 -0
- package/ts/src/booking-surface/profile.ts +42 -0
- package/ts/src/booking-surface/recovery-chain.ts +409 -0
- package/ts/src/booking-surface/runtime.ts +1793 -0
- package/ts/src/booking-surface/server.ts +733 -0
- package/ts/src/booking-surface/startup.ts +201 -0
- package/ts/src/booking-surface/validation.ts +217 -0
- package/ts/src/companions.ts +113 -0
- package/ts/src/contracts.ts +13 -3
- package/ts/src/dsh-llm.ts +44 -11
- package/ts/src/flyai-setup-tool.ts +77 -0
- package/ts/src/index.ts +1948 -198
- package/ts/src/itinerary-deck.ts +189 -0
- package/ts/src/itinerary-doc-shared.ts +741 -0
- package/ts/src/itinerary-html.ts +171 -0
- package/ts/src/loop.ts +223 -25
- package/ts/src/memory-capture.ts +283 -0
- package/ts/src/memory-decay.ts +55 -0
- package/ts/src/memory-utility.ts +70 -0
- package/ts/src/mock-llm.ts +4 -8
- package/ts/src/model.ts +88 -2
- package/ts/src/recall/card.ts +106 -0
- package/ts/src/recall/evaluator.ts +170 -0
- package/ts/src/recall/integration.ts +35 -0
- package/ts/src/recall/tick.ts +213 -0
- package/ts/src/session-link/plan-it-action.ts +78 -0
- package/ts/src/session-link/session-link.ts +275 -0
- package/ts/src/share/adapters.ts +93 -0
- package/ts/src/share/share-consent.ts +105 -0
- package/ts/src/share/share-deck.ts +85 -0
- package/ts/src/share/share-token.ts +166 -0
- package/ts/src/slot-spec.ts +172 -0
- package/ts/src/state-ledger.ts +912 -0
- package/ts/src/subagent-job-id-guard.ts +72 -0
- package/ts/src/time-anchor.ts +338 -0
- package/ts/src/tool-packet.ts +32 -0
- package/ts/src/travel-slots.ts +219 -0
- package/ts/src/travel-timeline.ts +83 -0
- package/ts/src/turn-deadline.ts +366 -0
- package/ts/src/turn-policy.ts +154 -0
- package/ts/src/unified.ts +354 -88
- package/ts/src/wish-pool.ts +79 -0
- package/dist/scripts/session-attach-wait.js +0 -41
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
/** Provider-neutral execution and terminal contract for benchmark agents. */
|
|
2
|
+
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
4
|
+
import { createUserMessage } from '@deepseek-ai/dsh-llm'
|
|
5
|
+
import {
|
|
6
|
+
classifyBenchmarkTurnEnd,
|
|
7
|
+
createBenchmarkDiagnosticArbiter,
|
|
8
|
+
emitBenchmarkChildDiagnostic,
|
|
9
|
+
type BenchmarkChildFailureCode,
|
|
10
|
+
} from './benchmark-headless-child-diagnostics.ts'
|
|
11
|
+
|
|
12
|
+
export const MAX_CONFORMANCE_RETRIES = 1 as const
|
|
13
|
+
export const BENCHMARK_BRIDGE_CALL_REQUIRED = 'BENCHMARK_BRIDGE_CALL_REQUIRED'
|
|
14
|
+
export const BENCHMARK_BRIDGE_CALL_FAILED = 'BENCHMARK_BRIDGE_CALL_FAILED'
|
|
15
|
+
export const BENCHMARK_BRIDGE_TIMED_OUT = 'BENCHMARK_BRIDGE_TIMED_OUT'
|
|
16
|
+
export const BENCHMARK_BRIDGE_RUNNER_FAILED = 'BENCHMARK_BRIDGE_RUNNER_FAILED'
|
|
17
|
+
export const BENCHMARK_BRIDGE_SPAWN_FAILED = 'BENCHMARK_BRIDGE_SPAWN_FAILED'
|
|
18
|
+
export const BENCHMARK_BRIDGE_OUTPUT_TRUNCATED = 'BENCHMARK_BRIDGE_OUTPUT_TRUNCATED'
|
|
19
|
+
export const BENCHMARK_TERMINAL_INVALID = 'BENCHMARK_TERMINAL_INVALID'
|
|
20
|
+
export const BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED = 'BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED'
|
|
21
|
+
export const BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE = 'BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE'
|
|
22
|
+
|
|
23
|
+
const IDENTIFIER = /^[A-Za-z][A-Za-z0-9_.-]*$/
|
|
24
|
+
const MAX_TERMINAL_BYTES = 1024 * 1024
|
|
25
|
+
const BENCHMARK_TOOL_RESULT_SCHEMA_VERSION = 'gotry_benchmark_tool_result_v1'
|
|
26
|
+
const BENCHMARK_DOMAIN_RECOVERIES = new Set(['none', 'retry_same', 'revise_arguments', 'choose_alternative'])
|
|
27
|
+
|
|
28
|
+
// Round 12(issue #215):terminal body schema 是「无数据值的 closed 结构合同」——
|
|
29
|
+
// 只允许结构关键字(type/properties/required/additionalProperties/items),enum/
|
|
30
|
+
// const/example/default 等可夹带数据值的注解面一律禁止,对象必须 additionalProperties:
|
|
31
|
+
// false,大小/深度/节点数有界。校验语义 fail-closed:不补键、不删多余键、不转类型。
|
|
32
|
+
const TERMINAL_BODY_SCHEMA_MAX_BYTES = 16 * 1024
|
|
33
|
+
const TERMINAL_BODY_SCHEMA_MAX_DEPTH = 8
|
|
34
|
+
const TERMINAL_BODY_SCHEMA_MAX_NODES = 256
|
|
35
|
+
const TERMINAL_BODY_SCHEMA_MAX_PROPERTIES = 256
|
|
36
|
+
const TERMINAL_BODY_SCALAR_TYPES = new Set(['string', 'number', 'integer', 'boolean', 'null'])
|
|
37
|
+
const TERMINAL_BODY_VALUE_MAX_NODES = 10_000
|
|
38
|
+
const TERMINAL_BODY_VALUE_MAX_DEPTH = 24
|
|
39
|
+
|
|
40
|
+
/** Structural-only, closed JSON schema for the terminal body (no data-bearing keywords). */
|
|
41
|
+
export type TerminalBodySchema = {
|
|
42
|
+
type: 'object'
|
|
43
|
+
properties: Record<string, TerminalBodySchema>
|
|
44
|
+
required: string[]
|
|
45
|
+
additionalProperties: false
|
|
46
|
+
} | {
|
|
47
|
+
type: 'array'
|
|
48
|
+
items: TerminalBodySchema
|
|
49
|
+
} | {
|
|
50
|
+
type: 'string' | 'number' | 'integer' | 'boolean' | 'null'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface TerminalOutputConfig {
|
|
54
|
+
tag: string
|
|
55
|
+
max_bytes: number
|
|
56
|
+
body_schema: TerminalBodySchema
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type TerminalOutputValue =
|
|
60
|
+
| { ok: true; value: Record<string, unknown> }
|
|
61
|
+
| { ok: false; error: 'invalid_terminal_output' }
|
|
62
|
+
|
|
63
|
+
export interface BenchmarkBridgeProjection {
|
|
64
|
+
readonly toolName: string
|
|
65
|
+
readonly allowedTools: readonly string[]
|
|
66
|
+
readonly terminal: Readonly<TerminalOutputConfig>
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type RetryMode = 'none' | 'call' | 'terminal'
|
|
70
|
+
|
|
71
|
+
interface TurnState {
|
|
72
|
+
readonly turn: number
|
|
73
|
+
readonly validCallIds: Set<string>
|
|
74
|
+
retryCount: number
|
|
75
|
+
retryMode: RetryMode
|
|
76
|
+
successfulResultStep?: number
|
|
77
|
+
domainOutcomeStep?: number
|
|
78
|
+
lastBridgeResponseStep?: number
|
|
79
|
+
bridgeCallFailed: boolean
|
|
80
|
+
bridgeFailureCode?: string
|
|
81
|
+
retryRedispatchAttempted: boolean
|
|
82
|
+
lastAssistant?: {
|
|
83
|
+
step: number
|
|
84
|
+
text: string
|
|
85
|
+
interrupted: boolean
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type BenchmarkConformanceDecision =
|
|
90
|
+
| { kind: 'accept' }
|
|
91
|
+
| { kind: 'steer'; mode: Exclude<RetryMode, 'none'> }
|
|
92
|
+
| { kind: 'reject'; code: string }
|
|
93
|
+
|
|
94
|
+
export interface BenchmarkAgentConformance {
|
|
95
|
+
readonly retryMode: RetryMode
|
|
96
|
+
readonly retryCount: number
|
|
97
|
+
observe(event: unknown): void
|
|
98
|
+
stopping(turn: number): BenchmarkConformanceDecision
|
|
99
|
+
guardBridgeExecution(): string | undefined
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function plainObject(value: unknown): value is Record<string, unknown> {
|
|
103
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function validateTerminalOutputConfig(value: unknown): value is TerminalOutputConfig {
|
|
107
|
+
if (!plainObject(value)) return false
|
|
108
|
+
const keys = Object.keys(value).sort()
|
|
109
|
+
return JSON.stringify(keys) === JSON.stringify(['body_schema', 'max_bytes', 'tag'])
|
|
110
|
+
&& typeof value.tag === 'string'
|
|
111
|
+
&& IDENTIFIER.test(value.tag)
|
|
112
|
+
&& typeof value.max_bytes === 'number'
|
|
113
|
+
&& Number.isInteger(value.max_bytes)
|
|
114
|
+
&& value.max_bytes >= 1
|
|
115
|
+
&& value.max_bytes <= MAX_TERMINAL_BYTES
|
|
116
|
+
&& validateTerminalBodySchema(value.body_schema)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Accept only the closed structural dialect: exact keyword sets per node, bounded size. */
|
|
120
|
+
export function validateTerminalBodySchema(value: unknown): value is TerminalBodySchema {
|
|
121
|
+
let serialized: string
|
|
122
|
+
try {
|
|
123
|
+
serialized = JSON.stringify(value)
|
|
124
|
+
} catch {
|
|
125
|
+
return false
|
|
126
|
+
}
|
|
127
|
+
if (typeof serialized !== 'string' || Buffer.byteLength(serialized, 'utf8') > TERMINAL_BODY_SCHEMA_MAX_BYTES) return false
|
|
128
|
+
const pending: Array<{ node: unknown; depth: number }> = [{ node: value, depth: 0 }]
|
|
129
|
+
const seen = new Set<object>()
|
|
130
|
+
let nodes = 0
|
|
131
|
+
let properties = 0
|
|
132
|
+
while (pending.length > 0) {
|
|
133
|
+
const { node, depth } = pending.pop()!
|
|
134
|
+
if (!plainObject(node) || seen.has(node) || ++nodes > TERMINAL_BODY_SCHEMA_MAX_NODES || depth > TERMINAL_BODY_SCHEMA_MAX_DEPTH) return false
|
|
135
|
+
seen.add(node)
|
|
136
|
+
const type = node.type
|
|
137
|
+
if (type === 'object') {
|
|
138
|
+
if (!exactKeys(node, ['type', 'properties', 'required', 'additionalProperties'])
|
|
139
|
+
|| !plainObject(node.properties)
|
|
140
|
+
|| !Array.isArray(node.required)
|
|
141
|
+
|| node.additionalProperties !== false) return false
|
|
142
|
+
const entries = Object.entries(node.properties)
|
|
143
|
+
properties += entries.length
|
|
144
|
+
if (properties > TERMINAL_BODY_SCHEMA_MAX_PROPERTIES
|
|
145
|
+
|| entries.some(([key, child]) => key.length === 0 || key.length > 64 || !plainObject(child))) return false
|
|
146
|
+
if (node.required.length > entries.length
|
|
147
|
+
|| new Set(node.required).size !== node.required.length
|
|
148
|
+
|| node.required.some(key => typeof key !== 'string' || !Object.hasOwn(node.properties as Record<string, unknown>, key))) return false
|
|
149
|
+
for (const [, child] of entries) pending.push({ node: child, depth: depth + 1 })
|
|
150
|
+
continue
|
|
151
|
+
}
|
|
152
|
+
if (type === 'array') {
|
|
153
|
+
if (!exactKeys(node, ['type', 'items']) || !plainObject(node.items)) return false
|
|
154
|
+
pending.push({ node: node.items, depth: depth + 1 })
|
|
155
|
+
continue
|
|
156
|
+
}
|
|
157
|
+
if (typeof type !== 'string' || !TERMINAL_BODY_SCALAR_TYPES.has(type) || !exactKeys(node, ['type'])) return false
|
|
158
|
+
}
|
|
159
|
+
return plainObject(value) && value.type === 'object'
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function exactKeys(value: Record<string, unknown>, allowed: readonly string[]): boolean {
|
|
163
|
+
return Object.keys(value).every(key => allowed.includes(key))
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Strict structural validation: exact keys, exact types, no coercion, no autofix. */
|
|
167
|
+
export function validateTerminalBodyValue(value: unknown, schema: TerminalBodySchema): boolean {
|
|
168
|
+
const pending: Array<{ value: unknown; schema: TerminalBodySchema; depth: number }> = [{ value, schema, depth: 0 }]
|
|
169
|
+
let nodes = 0
|
|
170
|
+
while (pending.length > 0) {
|
|
171
|
+
const current = pending.pop()!
|
|
172
|
+
if (++nodes > TERMINAL_BODY_VALUE_MAX_NODES || current.depth > TERMINAL_BODY_VALUE_MAX_DEPTH) return false
|
|
173
|
+
const { schema: node } = current
|
|
174
|
+
if (node.type === 'object') {
|
|
175
|
+
const record = current.value
|
|
176
|
+
if (!plainObject(record)) return false
|
|
177
|
+
const properties = node.properties as Record<string, TerminalBodySchema>
|
|
178
|
+
for (const key of node.required) {
|
|
179
|
+
if (!Object.hasOwn(record, key)) return false
|
|
180
|
+
}
|
|
181
|
+
for (const [key, child] of Object.entries(record)) {
|
|
182
|
+
const childSchema = properties[key]
|
|
183
|
+
if (!childSchema) return false
|
|
184
|
+
pending.push({ value: child, schema: childSchema, depth: current.depth + 1 })
|
|
185
|
+
}
|
|
186
|
+
continue
|
|
187
|
+
}
|
|
188
|
+
if (node.type === 'array') {
|
|
189
|
+
if (!Array.isArray(current.value)) return false
|
|
190
|
+
for (const item of current.value) pending.push({ value: item, schema: node.items, depth: current.depth + 1 })
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
if (node.type === 'string') { if (typeof current.value !== 'string') return false; continue }
|
|
194
|
+
if (node.type === 'boolean') { if (typeof current.value !== 'boolean') return false; continue }
|
|
195
|
+
if (node.type === 'null') { if (current.value !== null) return false; continue }
|
|
196
|
+
if (node.type === 'integer') { if (typeof current.value !== 'number' || !Number.isSafeInteger(current.value)) return false; continue }
|
|
197
|
+
if (typeof current.value !== 'number' || !Number.isFinite(current.value)) return false
|
|
198
|
+
}
|
|
199
|
+
return true
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Deterministic single-source structural outline projected into system prompt and correction alike. */
|
|
203
|
+
export function terminalSchemaOutline(schema: TerminalBodySchema): string {
|
|
204
|
+
const render = (node: TerminalBodySchema, depth: number): string => {
|
|
205
|
+
if (depth > TERMINAL_BODY_SCHEMA_MAX_DEPTH) return '…'
|
|
206
|
+
if (node.type === 'object') {
|
|
207
|
+
const properties = node.properties as Record<string, TerminalBodySchema>
|
|
208
|
+
const required = new Set(node.required)
|
|
209
|
+
const parts = Object.entries(properties).map(([key, child]) => `${required.has(key) ? '' : '?'}${key}:${render(child, depth + 1)}`)
|
|
210
|
+
return `object{${parts.join(',')}}`
|
|
211
|
+
}
|
|
212
|
+
if (node.type === 'array') return `array<${render(node.items, depth + 1)}>`
|
|
213
|
+
return node.type
|
|
214
|
+
}
|
|
215
|
+
return render(schema, 0)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function invalidTerminal(): TerminalOutputValue {
|
|
219
|
+
return { ok: false, error: 'invalid_terminal_output' }
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** 剥离推理模型的思考标签对(如 MiniMax/DeepSeek 的 <think>…</think>):当代模型
|
|
223
|
+
* 即便被明令「只回终态包」也会以思考块前缀输出——不剥则严格终态门对推理模型
|
|
224
|
+
* 结构性失效(Round 9 治理面实测)。只剥配对的推理标签本体,其余前后缀仍 fail-closed。 */
|
|
225
|
+
function stripReasoningBlocks(raw: string): string {
|
|
226
|
+
return raw.replace(/<think>[\s\S]*?<\/think>\s*/gi, '')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Parse exactly one configured tag pair containing one JSON object. */
|
|
230
|
+
export function parseBenchmarkTerminal(raw: string, config: TerminalOutputConfig): TerminalOutputValue {
|
|
231
|
+
if (!validateTerminalOutputConfig(config)) return invalidTerminal()
|
|
232
|
+
if (Buffer.byteLength(raw, 'utf8') > config.max_bytes) return invalidTerminal()
|
|
233
|
+
|
|
234
|
+
const trimmed = stripReasoningBlocks(raw).trim()
|
|
235
|
+
const opening = `<${config.tag}>`
|
|
236
|
+
const closing = `</${config.tag}>`
|
|
237
|
+
if (!trimmed.startsWith(opening) || !trimmed.endsWith(closing)) return invalidTerminal()
|
|
238
|
+
if (trimmed.indexOf(opening) !== trimmed.lastIndexOf(opening)
|
|
239
|
+
|| trimmed.indexOf(closing) !== trimmed.lastIndexOf(closing)) return invalidTerminal()
|
|
240
|
+
const body = trimmed.slice(opening.length, -closing.length)
|
|
241
|
+
if (body.length === 0 || body.includes('```')) return invalidTerminal()
|
|
242
|
+
|
|
243
|
+
try {
|
|
244
|
+
const value: unknown = JSON.parse(body)
|
|
245
|
+
if (!plainObject(value)) return invalidTerminal()
|
|
246
|
+
// Round 12(#215):同一份 closed body schema 在接受终态前 fail-closed 校验——
|
|
247
|
+
// 结构不合法的终态永不进入正式计分链,不做任何 autofix。
|
|
248
|
+
if (!validateTerminalBodyValue(value, config.body_schema)) return invalidTerminal()
|
|
249
|
+
return { ok: true, value }
|
|
250
|
+
} catch {
|
|
251
|
+
return invalidTerminal()
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** Backward-compatible name used by the bridge contract tests. */
|
|
256
|
+
export const validateTerminalOutput = parseBenchmarkTerminal
|
|
257
|
+
|
|
258
|
+
function eventData(event: unknown): { type: string; data: Record<string, unknown> } | undefined {
|
|
259
|
+
if (!plainObject(event) || typeof event.type !== 'string' || !plainObject(event.data)) return undefined
|
|
260
|
+
return { type: event.type, data: event.data }
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function eventTurn(data: Record<string, unknown>): number | undefined {
|
|
264
|
+
return typeof data.turn === 'number' && Number.isInteger(data.turn) ? data.turn : undefined
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function parseToolArguments(value: unknown): Record<string, unknown> | undefined {
|
|
268
|
+
if (plainObject(value)) return value
|
|
269
|
+
if (typeof value !== 'string') return undefined
|
|
270
|
+
try {
|
|
271
|
+
const parsed: unknown = JSON.parse(value)
|
|
272
|
+
return plainObject(parsed) ? parsed : undefined
|
|
273
|
+
} catch {
|
|
274
|
+
return undefined
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function assistantText(data: Record<string, unknown>): { text: string; interrupted: boolean } | undefined {
|
|
279
|
+
if (!plainObject(data.message) || !Array.isArray(data.message.content)) return undefined
|
|
280
|
+
const text = data.message.content
|
|
281
|
+
.filter(block => plainObject(block) && block.type === 'text' && typeof block.text === 'string')
|
|
282
|
+
.map(block => String((block as Record<string, unknown>).text))
|
|
283
|
+
.join('')
|
|
284
|
+
return { text, interrupted: data.interrupted === true }
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
type BridgeResultStatus = { kind: 'result' } | { kind: 'domain' } | { kind: 'failure'; code: string }
|
|
288
|
+
|
|
289
|
+
function bridgeResultStatus(data: Record<string, unknown>, callId: string): BridgeResultStatus | undefined {
|
|
290
|
+
if (!plainObject(data.message) || !plainObject(data.message.source)) return undefined
|
|
291
|
+
if (data.message.source.callId !== callId || !Array.isArray(data.message.content)) return undefined
|
|
292
|
+
// 0.2.0-rc.2 线型:tool/result 的身份与错误位在 message 顶层
|
|
293
|
+
// (toolCallId/isError),content 是文本载荷块;旧线型的 {type:'tool-result'} 块已不存在。
|
|
294
|
+
if (data.message.toolCallId !== callId || data.message.isError === true) return undefined
|
|
295
|
+
const text = data.message.content
|
|
296
|
+
.filter(candidate => plainObject(candidate) && candidate.type === 'text' && typeof candidate.text === 'string')
|
|
297
|
+
.map(candidate => String((candidate as Record<string, unknown>).text))
|
|
298
|
+
.join('')
|
|
299
|
+
try {
|
|
300
|
+
const parsed: unknown = JSON.parse(text)
|
|
301
|
+
if (!plainObject(parsed)) return undefined
|
|
302
|
+
const keys = Object.keys(parsed).sort().join(',')
|
|
303
|
+
if (parsed.ok === true && keys === 'ok,result' && (plainObject(parsed.result) || Array.isArray(parsed.result))) return { kind: 'result' }
|
|
304
|
+
if (parsed.ok === true && keys === 'ok,outcome' && plainObject(parsed.outcome)) {
|
|
305
|
+
const outcomeKeys = Object.keys(parsed.outcome).sort().join(',')
|
|
306
|
+
if (outcomeKeys === 'code,recovery,schema_version,status'
|
|
307
|
+
&& parsed.outcome.schema_version === BENCHMARK_TOOL_RESULT_SCHEMA_VERSION
|
|
308
|
+
&& (parsed.outcome.status === 'miss' || parsed.outcome.status === 'error')
|
|
309
|
+
&& typeof parsed.outcome.code === 'string'
|
|
310
|
+
&& IDENTIFIER.test(parsed.outcome.code)
|
|
311
|
+
&& typeof parsed.outcome.recovery === 'string'
|
|
312
|
+
&& BENCHMARK_DOMAIN_RECOVERIES.has(parsed.outcome.recovery)) return { kind: 'domain' }
|
|
313
|
+
return undefined
|
|
314
|
+
}
|
|
315
|
+
if (parsed.ok === false && typeof parsed.error === 'string') {
|
|
316
|
+
const exactFailure = parsed.error === 'runner_failed'
|
|
317
|
+
? (keys === 'error,ok' || (keys === 'error,exit_code,ok,signal'
|
|
318
|
+
&& (parsed.exit_code === null || (typeof parsed.exit_code === 'number' && Number.isInteger(parsed.exit_code)))
|
|
319
|
+
&& (parsed.signal === null || typeof parsed.signal === 'string')))
|
|
320
|
+
: parsed.error === 'invalid_arguments'
|
|
321
|
+
? keys === 'error,ok,reason' && typeof parsed.reason === 'string'
|
|
322
|
+
: keys === 'error,ok'
|
|
323
|
+
if (!exactFailure) return undefined
|
|
324
|
+
const code = parsed.error === 'timed_out'
|
|
325
|
+
? BENCHMARK_BRIDGE_TIMED_OUT
|
|
326
|
+
: parsed.error === 'runner_failed'
|
|
327
|
+
? BENCHMARK_BRIDGE_RUNNER_FAILED
|
|
328
|
+
: parsed.error === 'spawn_failed'
|
|
329
|
+
? BENCHMARK_BRIDGE_SPAWN_FAILED
|
|
330
|
+
: parsed.error === 'output_truncated'
|
|
331
|
+
? BENCHMARK_BRIDGE_OUTPUT_TRUNCATED
|
|
332
|
+
: BENCHMARK_BRIDGE_CALL_FAILED
|
|
333
|
+
return { kind: 'failure', code }
|
|
334
|
+
}
|
|
335
|
+
return undefined
|
|
336
|
+
} catch {
|
|
337
|
+
return undefined
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function benchmarkChildFailureForConformanceCode(code: string): BenchmarkChildFailureCode {
|
|
342
|
+
if (code === BENCHMARK_BRIDGE_TIMED_OUT) return 'child_bridge_timed_out'
|
|
343
|
+
if (code === BENCHMARK_BRIDGE_RUNNER_FAILED) return 'child_bridge_runner_failed'
|
|
344
|
+
if (code === BENCHMARK_BRIDGE_SPAWN_FAILED) return 'child_bridge_spawn_failed'
|
|
345
|
+
if (code === BENCHMARK_BRIDGE_OUTPUT_TRUNCATED) return 'child_bridge_output_truncated'
|
|
346
|
+
if (code === BENCHMARK_BRIDGE_CALL_FAILED) return 'child_bridge_failure'
|
|
347
|
+
return 'child_conformance_failure'
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function newTurn(turn: number): TurnState {
|
|
351
|
+
return {
|
|
352
|
+
turn,
|
|
353
|
+
validCallIds: new Set(),
|
|
354
|
+
retryCount: 0,
|
|
355
|
+
retryMode: 'none',
|
|
356
|
+
bridgeCallFailed: false,
|
|
357
|
+
retryRedispatchAttempted: false,
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/** Deterministic controller used by both runtime wiring and offline contracts. */
|
|
362
|
+
export function createBenchmarkAgentConformance(projection: BenchmarkBridgeProjection): BenchmarkAgentConformance {
|
|
363
|
+
let state: TurnState | undefined
|
|
364
|
+
|
|
365
|
+
const controller: BenchmarkAgentConformance = {
|
|
366
|
+
get retryMode() { return state?.retryMode ?? 'none' },
|
|
367
|
+
get retryCount() { return state?.retryCount ?? 0 },
|
|
368
|
+
|
|
369
|
+
observe(rawEvent: unknown): void {
|
|
370
|
+
const event = eventData(rawEvent)
|
|
371
|
+
if (!event) return
|
|
372
|
+
const turn = eventTurn(event.data)
|
|
373
|
+
|
|
374
|
+
if (event.type === 'turn/start' && turn !== undefined) {
|
|
375
|
+
state = newTurn(turn)
|
|
376
|
+
return
|
|
377
|
+
}
|
|
378
|
+
if (event.type === 'turn/end') {
|
|
379
|
+
if (state && turn === state.turn) state = undefined
|
|
380
|
+
return
|
|
381
|
+
}
|
|
382
|
+
if (!state || turn !== state.turn) return
|
|
383
|
+
|
|
384
|
+
if (event.type === 'tool/call') {
|
|
385
|
+
if (event.data.name !== projection.toolName) return
|
|
386
|
+
if (state.retryMode === 'terminal') {
|
|
387
|
+
state.retryRedispatchAttempted = true
|
|
388
|
+
return
|
|
389
|
+
}
|
|
390
|
+
if (typeof event.data.callId !== 'string') return
|
|
391
|
+
const args = parseToolArguments(event.data.arguments)
|
|
392
|
+
// Round 8(issue #100/#102):bridge 工具 typed 泛化后,模型出参为平铺形态
|
|
393
|
+
const flat = args && plainObject(args) ? args : undefined
|
|
394
|
+
if (flat?.action === 'call'
|
|
395
|
+
&& typeof flat.tool === 'string'
|
|
396
|
+
&& projection.allowedTools.includes(flat.tool)) {
|
|
397
|
+
state.validCallIds.add(event.data.callId)
|
|
398
|
+
}
|
|
399
|
+
return
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (event.type === 'tool/result') {
|
|
403
|
+
if (!plainObject(event.data.message) || !plainObject(event.data.message.source)) return
|
|
404
|
+
const callId = event.data.message.source.callId
|
|
405
|
+
if (typeof callId !== 'string' || !state.validCallIds.has(callId)) return
|
|
406
|
+
const resultStatus = bridgeResultStatus(event.data, callId)
|
|
407
|
+
if (typeof event.data.step === 'number') state.lastBridgeResponseStep = event.data.step
|
|
408
|
+
if (resultStatus?.kind === 'result') {
|
|
409
|
+
state.successfulResultStep = typeof event.data.step === 'number'
|
|
410
|
+
? event.data.step
|
|
411
|
+
: state.successfulResultStep
|
|
412
|
+
} else if (resultStatus?.kind === 'domain') {
|
|
413
|
+
state.domainOutcomeStep = typeof event.data.step === 'number'
|
|
414
|
+
? event.data.step
|
|
415
|
+
: state.domainOutcomeStep
|
|
416
|
+
} else {
|
|
417
|
+
state.bridgeCallFailed = true
|
|
418
|
+
state.bridgeFailureCode = resultStatus?.code ?? BENCHMARK_BRIDGE_CALL_FAILED
|
|
419
|
+
}
|
|
420
|
+
return
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (event.type === 'assistant/message') {
|
|
424
|
+
const assistant = assistantText(event.data)
|
|
425
|
+
if (!assistant || typeof event.data.step !== 'number') return
|
|
426
|
+
state.lastAssistant = { step: event.data.step, ...assistant }
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
stopping(turn: number): BenchmarkConformanceDecision {
|
|
431
|
+
if (!state || state.turn !== turn) {
|
|
432
|
+
return { kind: 'reject', code: BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE }
|
|
433
|
+
}
|
|
434
|
+
if (state.retryRedispatchAttempted) {
|
|
435
|
+
return { kind: 'reject', code: BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED }
|
|
436
|
+
}
|
|
437
|
+
if (state.bridgeCallFailed && state.successfulResultStep === undefined) {
|
|
438
|
+
return { kind: 'reject', code: state.bridgeFailureCode ?? BENCHMARK_BRIDGE_CALL_FAILED }
|
|
439
|
+
}
|
|
440
|
+
if (state.successfulResultStep === undefined && state.domainOutcomeStep === undefined) {
|
|
441
|
+
if (state.retryCount >= MAX_CONFORMANCE_RETRIES) {
|
|
442
|
+
return { kind: 'reject', code: BENCHMARK_BRIDGE_CALL_REQUIRED }
|
|
443
|
+
}
|
|
444
|
+
state.retryCount += 1
|
|
445
|
+
state.retryMode = 'call'
|
|
446
|
+
return { kind: 'steer', mode: 'call' }
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const terminal = state.lastAssistant
|
|
450
|
+
const terminalIsValid = terminal !== undefined
|
|
451
|
+
&& !terminal.interrupted
|
|
452
|
+
&& terminal.step > state.lastBridgeResponseStep!
|
|
453
|
+
&& parseBenchmarkTerminal(terminal.text, projection.terminal).ok
|
|
454
|
+
if (terminalIsValid) return { kind: 'accept' }
|
|
455
|
+
if (state.retryCount >= MAX_CONFORMANCE_RETRIES) {
|
|
456
|
+
return { kind: 'reject', code: BENCHMARK_TERMINAL_INVALID }
|
|
457
|
+
}
|
|
458
|
+
state.retryCount += 1
|
|
459
|
+
state.retryMode = 'terminal'
|
|
460
|
+
return { kind: 'steer', mode: 'terminal' }
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
guardBridgeExecution(): string | undefined {
|
|
464
|
+
return state?.retryMode === 'terminal'
|
|
465
|
+
? BENCHMARK_BRIDGE_RETRY_CALL_NOT_ALLOWED
|
|
466
|
+
: undefined
|
|
467
|
+
},
|
|
468
|
+
}
|
|
469
|
+
return controller
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
type Disposer = () => void | Promise<void>
|
|
473
|
+
type ScopedAgent = {
|
|
474
|
+
id?: unknown
|
|
475
|
+
session?: object
|
|
476
|
+
steer?: (message: unknown) => void
|
|
477
|
+
ctx?: {
|
|
478
|
+
tools?: { guard?: (check: (execution: { name: string }) => string | undefined) => unknown }
|
|
479
|
+
effect?: (action: () => unknown, label?: string) => unknown
|
|
480
|
+
on?: (event: string, listener: (...args: any[]) => unknown, options?: { prepend?: boolean }) => unknown
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
type EventBus = {
|
|
484
|
+
on?: (event: string, listener: (...args: any[]) => unknown, options?: { prepend?: boolean }) => unknown
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function requireDisposer(value: unknown, capability: string): Disposer {
|
|
488
|
+
if (typeof value !== 'function') throw new Error(`benchmark conformance ${capability} disposer unavailable`)
|
|
489
|
+
return value as Disposer
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
function correctionMessage(mode: Exclude<RetryMode, 'none'>, projection: BenchmarkBridgeProjection) {
|
|
493
|
+
const text = mode === 'call'
|
|
494
|
+
? `BENCHMARK_CONFORMANCE_CALL: Execute exactly one native ${projection.toolName} action:"call" now. Describing an intended CLI, shell, or Python command does not execute it.`
|
|
495
|
+
: `BENCHMARK_CONFORMANCE_TERMINAL: Reuse the existing successful tool result. Do not call any tool. Reply only <${projection.terminal.tag}> with one JSON object matching exactly ${terminalSchemaOutline(projection.terminal.body_schema)} — no extra keys, no missing keys, exact types.`
|
|
496
|
+
return createUserMessage({
|
|
497
|
+
content: [{ type: 'text' as const, text }],
|
|
498
|
+
// 0.2.0-rc.2 的 MessageSourceMap 移除了 'plugin' kind;基准纠偏消息是
|
|
499
|
+
// 插件注入的指令,归入 system-prompt(运行时自产注入),不冒充真实用户输入。
|
|
500
|
+
source: { kind: 'system-prompt' as const },
|
|
501
|
+
})
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function systemSection(projection: BenchmarkBridgeProjection): { name: string; text: string } {
|
|
505
|
+
const allowed = projection.allowedTools.join(', ')
|
|
506
|
+
const outline = terminalSchemaOutline(projection.terminal.body_schema)
|
|
507
|
+
return {
|
|
508
|
+
name: 'benchmark:agent-conformance',
|
|
509
|
+
text: [
|
|
510
|
+
'Benchmark execution contract:',
|
|
511
|
+
`- Translate every task instruction to use a CLI, shell, Python, or agent_env.cli into the native tool ${projection.toolName}; do not merely describe the intended command.`,
|
|
512
|
+
`- Call it with exactly {"action":"call","tool":"<one of: ${allowed}>","arguments":{...}}.`,
|
|
513
|
+
'- action:"tools" is discovery only and does not satisfy the required environment call.',
|
|
514
|
+
`- After a successful tool result, reply only <${projection.terminal.tag}> with one JSON object matching exactly ${outline} — no extra keys, no missing keys, exact types; no prose or code fence.`,
|
|
515
|
+
'- If a terminal-format correction arrives, reuse the existing result and do not call the tool again.',
|
|
516
|
+
].join('\n'),
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
/** Install conformance only after the exact benchmark bridge isolation layer. */
|
|
521
|
+
export function installBenchmarkAgentConformance(
|
|
522
|
+
ctx: Context,
|
|
523
|
+
projection: BenchmarkBridgeProjection,
|
|
524
|
+
diagnosticWriter: (code: BenchmarkChildFailureCode) => void = emitBenchmarkChildDiagnostic,
|
|
525
|
+
): void {
|
|
526
|
+
const bus = ctx as unknown as EventBus
|
|
527
|
+
if (typeof bus.on !== 'function') throw new Error('benchmark conformance event bus unavailable')
|
|
528
|
+
|
|
529
|
+
const byAgent = new WeakMap<object, BenchmarkAgentConformance>()
|
|
530
|
+
const bySession = new WeakMap<object, BenchmarkAgentConformance>()
|
|
531
|
+
const sessionKeys = new WeakMap<object, string>()
|
|
532
|
+
let sessionOrdinal = 0
|
|
533
|
+
const diagnostics = createBenchmarkDiagnosticArbiter(diagnosticWriter)
|
|
534
|
+
|
|
535
|
+
bus.on('agent/created', (payload: { agent?: ScopedAgent }) => {
|
|
536
|
+
const agent = payload.agent
|
|
537
|
+
if (!agent || typeof agent !== 'object' || !agent.session) {
|
|
538
|
+
throw new Error('benchmark conformance created agent unavailable')
|
|
539
|
+
}
|
|
540
|
+
if (typeof agent.steer !== 'function') throw new Error('benchmark conformance steering unavailable')
|
|
541
|
+
if (typeof agent.ctx?.tools?.guard !== 'function') throw new Error('benchmark conformance scoped guard unavailable')
|
|
542
|
+
if (typeof agent.ctx.effect !== 'function') throw new Error('benchmark conformance scoped effect unavailable')
|
|
543
|
+
if (typeof agent.ctx.on !== 'function') throw new Error('benchmark conformance scoped event bus unavailable')
|
|
544
|
+
|
|
545
|
+
const controller = createBenchmarkAgentConformance(projection)
|
|
546
|
+
byAgent.set(agent, controller)
|
|
547
|
+
bySession.set(agent.session, controller)
|
|
548
|
+
sessionKeys.set(agent.session, `session-${++sessionOrdinal}`)
|
|
549
|
+
try {
|
|
550
|
+
requireDisposer(agent.ctx.effect.call(agent.ctx, function* () {
|
|
551
|
+
yield requireDisposer(agent.ctx!.tools!.guard!(execution => {
|
|
552
|
+
if (execution.name !== projection.toolName) return undefined
|
|
553
|
+
return controller.guardBridgeExecution()
|
|
554
|
+
}), 'scoped guard')
|
|
555
|
+
yield requireDisposer(agent.ctx!.on!.call(agent.ctx, 'system-prompt/assemble', async (
|
|
556
|
+
_assembly: unknown,
|
|
557
|
+
_context: unknown,
|
|
558
|
+
next?: () => Promise<unknown>,
|
|
559
|
+
) => {
|
|
560
|
+
if (typeof next !== 'function') throw new Error('benchmark conformance assembly continuation unavailable')
|
|
561
|
+
const result = await next()
|
|
562
|
+
if (!plainObject(result)) throw new Error('benchmark conformance assembly result unavailable')
|
|
563
|
+
const sections = Array.isArray(result.sections) ? result.sections : []
|
|
564
|
+
return { ...result, sections: [...sections, systemSection(projection)] }
|
|
565
|
+
}, { prepend: true }), 'scoped assembly listener')
|
|
566
|
+
}, 'benchmark-agent-conformance'), 'scoped effect')
|
|
567
|
+
} catch (error) {
|
|
568
|
+
byAgent.delete(agent)
|
|
569
|
+
bySession.delete(agent.session)
|
|
570
|
+
throw error
|
|
571
|
+
}
|
|
572
|
+
})
|
|
573
|
+
|
|
574
|
+
bus.on('session/event', (session: object, event: unknown) => {
|
|
575
|
+
bySession.get(session)?.observe(event)
|
|
576
|
+
if (typeof event === 'object' && event !== null && (event as { type?: unknown }).type === 'turn/end') {
|
|
577
|
+
const key = sessionKeys.get(session)
|
|
578
|
+
if (key !== undefined) {
|
|
579
|
+
diagnostics.offer(key, classifyBenchmarkTurnEnd((event as { data?: { reason?: unknown } }).data?.reason))
|
|
580
|
+
diagnostics.flush(key)
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
})
|
|
584
|
+
bus.on('session/disposed', (session: object) => {
|
|
585
|
+
const key = sessionKeys.get(session)
|
|
586
|
+
if (key !== undefined) diagnostics.flush(key)
|
|
587
|
+
sessionKeys.delete(session)
|
|
588
|
+
bySession.delete(session)
|
|
589
|
+
})
|
|
590
|
+
bus.on('agent/disposed', (payload: { agent?: ScopedAgent }) => {
|
|
591
|
+
const agent = payload.agent
|
|
592
|
+
if (!agent || typeof agent !== 'object') return
|
|
593
|
+
byAgent.delete(agent)
|
|
594
|
+
if (agent.session) bySession.delete(agent.session)
|
|
595
|
+
})
|
|
596
|
+
bus.on('agent/turn-stopping', (payload: { agent?: ScopedAgent; session?: object; turn?: number }) => {
|
|
597
|
+
const agent = payload.agent
|
|
598
|
+
const session = agent?.session ?? payload.session
|
|
599
|
+
const key = session && typeof session === 'object' ? sessionKeys.get(session) : undefined
|
|
600
|
+
if (!agent || typeof agent !== 'object' || typeof payload.turn !== 'number') {
|
|
601
|
+
if (key !== undefined) diagnostics.offer(key, 'child_conformance_failure')
|
|
602
|
+
else diagnosticWriter('child_conformance_failure')
|
|
603
|
+
throw new Error(BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE)
|
|
604
|
+
}
|
|
605
|
+
const controller = byAgent.get(agent)
|
|
606
|
+
if (!controller) {
|
|
607
|
+
if (key !== undefined) diagnostics.offer(key, 'child_conformance_failure')
|
|
608
|
+
else diagnosticWriter('child_conformance_failure')
|
|
609
|
+
throw new Error(BENCHMARK_CONFORMANCE_STATE_UNAVAILABLE)
|
|
610
|
+
}
|
|
611
|
+
const decision = controller.stopping(payload.turn)
|
|
612
|
+
if (decision.kind === 'reject') {
|
|
613
|
+
if (key !== undefined) diagnostics.offer(key, benchmarkChildFailureForConformanceCode(decision.code))
|
|
614
|
+
else diagnosticWriter(benchmarkChildFailureForConformanceCode(decision.code))
|
|
615
|
+
throw new Error(decision.code)
|
|
616
|
+
}
|
|
617
|
+
if (decision.kind === 'steer') agent.steer!(correctionMessage(decision.mode, projection))
|
|
618
|
+
}, { prepend: true })
|
|
619
|
+
}
|