@danceiny/gotry 0.0.1-rc.8 → 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 -217
- 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 -49
- 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 +968 -0
- 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 +126 -0
- package/dist/capabilities/session/adapters/ctrip-flight.js +141 -0
- 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 +54 -0
- 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 +50 -0
- 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 +107 -0
- package/dist/capabilities/session/static-flight-golden.js +150 -0
- package/dist/capabilities/session/transport.js +109 -0
- 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 +686 -0
- 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 +72 -0
- 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 +68 -10
- 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 +67 -0
- 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 +480 -0
- package/dist/scripts/ledger-workflow-crash.js +32 -0
- 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 +49 -0
- package/dist/scripts/memory-lifecycle-tests.js +657 -0
- package/dist/scripts/memory-lifecycle.js +196 -0
- package/dist/scripts/memory-metrics.js +29 -31
- 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 +43 -42
- 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 +31 -0
- package/dist/scripts/session-attach-poc.js +62 -0
- 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 +60 -0
- package/dist/scripts/session-link-tests.js +478 -0
- package/dist/scripts/session-login.js +29 -0
- package/dist/scripts/session-tests.js +862 -0
- 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 +703 -219
- 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 +261 -0
- package/dist/scripts/state-cli.js +585 -0
- 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 +59 -0
- 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 +86 -0
- 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 +2305 -731
- 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 +358 -162
- package/dist/src/memory-capture.js +180 -32
- package/dist/src/memory-decay.js +47 -0
- 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 +767 -0
- 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 +59 -0
- 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 +538 -360
- 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 +296 -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 +2107 -224
- 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 +278 -40
- 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 +360 -89
- package/ts/src/wish-pool.ts +79 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/** Production composition entry for GoTry's BFF-only Booking Copilot server. */
|
|
2
|
+
import { mkdirSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { ensureLedger } from '../state-ledger.js';
|
|
6
|
+
import { buildDshPlannerEnvironment, createDshEmbeddedBookingPlanner, } from './dsh-planner.js';
|
|
7
|
+
import { BookingCopilotTaskRuntime } from './runtime.js';
|
|
8
|
+
import { BOOKING_COPILOT_INGRESS_MODES } from './contracts.js';
|
|
9
|
+
import { startBookingCopilotServer, } from './server.js';
|
|
10
|
+
const DEFAULT_DEPENDENCIES = {
|
|
11
|
+
ensureLedger,
|
|
12
|
+
runtimeFactory: (ledger) => new BookingCopilotTaskRuntime(ledger),
|
|
13
|
+
createPlanner: createDshEmbeddedBookingPlanner,
|
|
14
|
+
startServer: startBookingCopilotServer,
|
|
15
|
+
};
|
|
16
|
+
function parsePort(raw) {
|
|
17
|
+
if (raw === undefined || raw === '')
|
|
18
|
+
return 3_082;
|
|
19
|
+
const value = Number(raw);
|
|
20
|
+
if (!Number.isSafeInteger(value) || value < 0 || value > 65_535)
|
|
21
|
+
throw new Error('booking_copilot_invalid_port');
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
/** Operator-tunable planner deadline; the bounds mirror the planner's own validation. */
|
|
25
|
+
function parsePlannerTurnTimeout(raw) {
|
|
26
|
+
if (raw === undefined || raw.trim() === '')
|
|
27
|
+
return undefined;
|
|
28
|
+
const value = Number(raw);
|
|
29
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 120_000) {
|
|
30
|
+
throw new Error('booking_copilot_planner_timeout_invalid');
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
export function resolveBookingCopilotStartupConfig(env = process.env) {
|
|
35
|
+
const apiKey = env.GOTRY_BOOKING_COPILOT_API_KEY ?? '';
|
|
36
|
+
if (!apiKey)
|
|
37
|
+
throw new Error('booking_copilot_api_key_required');
|
|
38
|
+
const stateRoot = env.GOTRY_BOOKING_COPILOT_STATE_ROOT ?? '';
|
|
39
|
+
if (!stateRoot)
|
|
40
|
+
throw new Error('booking_copilot_state_root_required');
|
|
41
|
+
if (!isAbsolute(stateRoot))
|
|
42
|
+
throw new Error('booking_copilot_state_root_must_be_absolute');
|
|
43
|
+
const artifactId = env.GOTRY_BOOKING_COPILOT_ARTIFACT_ID || undefined;
|
|
44
|
+
if (artifactId !== undefined && !/^[0-9a-f]{40}$/.test(artifactId)) {
|
|
45
|
+
throw new Error('booking_copilot_artifact_id_invalid');
|
|
46
|
+
}
|
|
47
|
+
const rawIngressMode = env.GOTRY_BOOKING_COPILOT_INGRESS_MODE;
|
|
48
|
+
const ingressMode = rawIngressMode === undefined || rawIngressMode === '' ? 'bff-bound-turn-only' : rawIngressMode;
|
|
49
|
+
if (!BOOKING_COPILOT_INGRESS_MODES.includes(ingressMode)) {
|
|
50
|
+
throw new Error('booking_copilot_ingress_mode_invalid');
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
apiKey,
|
|
54
|
+
stateRoot,
|
|
55
|
+
host: env.GOTRY_BOOKING_COPILOT_HOST || '127.0.0.1',
|
|
56
|
+
port: parsePort(env.GOTRY_BOOKING_COPILOT_PORT),
|
|
57
|
+
artifactId,
|
|
58
|
+
plannerTurnTimeoutMs: parsePlannerTurnTimeout(env.GOTRY_BOOKING_COPILOT_PLANNER_TIMEOUT_MS),
|
|
59
|
+
ingressMode: ingressMode,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
async function closeAll(server, planner, ledger) {
|
|
63
|
+
const failures = [];
|
|
64
|
+
for (const close of [
|
|
65
|
+
server ? () => server.close() : undefined,
|
|
66
|
+
planner ? () => planner.close() : undefined,
|
|
67
|
+
ledger ? () => Promise.resolve(ledger.close()) : undefined,
|
|
68
|
+
]) {
|
|
69
|
+
if (!close)
|
|
70
|
+
continue;
|
|
71
|
+
try {
|
|
72
|
+
await close();
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
failures.push(error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (failures.length === 1)
|
|
79
|
+
throw failures[0];
|
|
80
|
+
if (failures.length > 1)
|
|
81
|
+
throw new AggregateError(failures, 'booking_copilot_shutdown_failed');
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Boot one process-scoped dsh core and task-scoped sessions behind the typed
|
|
85
|
+
* HTTP/SSE server. Only the HTTP layer receives the BFF deployment key.
|
|
86
|
+
*/
|
|
87
|
+
export async function startBookingCopilotFromEnvironment(env = process.env, dependencies = DEFAULT_DEPENDENCIES) {
|
|
88
|
+
const config = resolveBookingCopilotStartupConfig(env);
|
|
89
|
+
const activeDependencies = dependencies;
|
|
90
|
+
const hasIngressBinding = Boolean(activeDependencies.ingressBinding);
|
|
91
|
+
const hasPrincipal = Boolean(activeDependencies.principal);
|
|
92
|
+
if (hasIngressBinding !== hasPrincipal)
|
|
93
|
+
throw new Error('booking_copilot_ingress_binding_pair_required');
|
|
94
|
+
const ingressPair = hasIngressBinding && hasPrincipal;
|
|
95
|
+
if (ingressPair && env.GOTRY_BOOKING_COPILOT_INGRESS_MODE !== undefined && config.ingressMode === 'bff-bound-turn-only') {
|
|
96
|
+
throw new Error('booking_copilot_ingress_mode_conflict');
|
|
97
|
+
}
|
|
98
|
+
if (!ingressPair && config.ingressMode === 'bff-ingress-binding')
|
|
99
|
+
throw new Error('booking_copilot_ingress_binding_required');
|
|
100
|
+
if (ingressPair && (typeof activeDependencies.ingressBinding?.bind !== 'function'
|
|
101
|
+
|| typeof activeDependencies.principal?.subject !== 'string' || activeDependencies.principal.subject.length === 0 || activeDependencies.principal.subject.length > 256
|
|
102
|
+
|| typeof activeDependencies.principal?.scope !== 'string' || activeDependencies.principal.scope.length === 0 || activeDependencies.principal.scope.length > 256)) {
|
|
103
|
+
throw new Error('booking_copilot_ingress_binding_invalid');
|
|
104
|
+
}
|
|
105
|
+
const activeIngressMode = ingressPair ? 'bff-ingress-binding' : 'bff-bound-turn-only';
|
|
106
|
+
mkdirSync(config.stateRoot, { recursive: true });
|
|
107
|
+
let ledger;
|
|
108
|
+
let planner;
|
|
109
|
+
let server;
|
|
110
|
+
try {
|
|
111
|
+
ledger = dependencies.ensureLedger(config.stateRoot);
|
|
112
|
+
const plannerOptions = {
|
|
113
|
+
stateRoot: config.stateRoot,
|
|
114
|
+
env: buildDshPlannerEnvironment(env),
|
|
115
|
+
...(config.plannerTurnTimeoutMs === undefined ? {} : { turnTimeoutMs: config.plannerTurnTimeoutMs }),
|
|
116
|
+
};
|
|
117
|
+
const runtime = activeDependencies.runtimeFactory(ledger);
|
|
118
|
+
planner = await activeDependencies.createPlanner(plannerOptions);
|
|
119
|
+
server = await activeDependencies.startServer({
|
|
120
|
+
apiKey: config.apiKey, runtime, plannerFactory: planner.plannerFactory,
|
|
121
|
+
...(ingressPair ? { ingressBinding: activeDependencies.ingressBinding, principal: activeDependencies.principal } : {}),
|
|
122
|
+
ingressMode: activeIngressMode,
|
|
123
|
+
host: config.host, port: config.port, artifactId: config.artifactId,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
try {
|
|
128
|
+
await closeAll(server, planner, ledger);
|
|
129
|
+
}
|
|
130
|
+
catch (cleanupError) {
|
|
131
|
+
throw new AggregateError([error, cleanupError], 'booking_copilot_startup_and_cleanup_failed');
|
|
132
|
+
}
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
let closed = false;
|
|
136
|
+
return {
|
|
137
|
+
port: server.port,
|
|
138
|
+
async close() {
|
|
139
|
+
if (closed)
|
|
140
|
+
return;
|
|
141
|
+
closed = true;
|
|
142
|
+
await closeAll(server, planner, ledger);
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
async function runCli() {
|
|
147
|
+
const handle = await startBookingCopilotFromEnvironment();
|
|
148
|
+
process.stderr.write(`[gotry-booking-copilot] listening on http://127.0.0.1:${handle.port}/a2a/booking-copilot/turn\n`);
|
|
149
|
+
let stopping = false;
|
|
150
|
+
const stop = () => {
|
|
151
|
+
if (stopping)
|
|
152
|
+
return;
|
|
153
|
+
stopping = true;
|
|
154
|
+
void handle.close().then(() => process.exit(0), (error) => {
|
|
155
|
+
process.stderr.write(`[gotry-booking-copilot] shutdown failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
process.once('SIGINT', stop);
|
|
160
|
+
process.once('SIGTERM', stop);
|
|
161
|
+
}
|
|
162
|
+
const invokedPath = process.argv[1] ? resolve(process.argv[1]) : '';
|
|
163
|
+
if (invokedPath === fileURLToPath(import.meta.url)) {
|
|
164
|
+
runCli().catch((error) => {
|
|
165
|
+
process.stderr.write(`[gotry-booking-copilot] startup failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { Ajv2020 } from 'ajv/dist/2020.js';
|
|
3
|
+
import { BOOKING_READ_ACTION_KINDS, BOOKING_BLOCKER_CODES, BOOKING_GAP_CODES } from './contracts.js';
|
|
4
|
+
const schema = JSON.parse(readFileSync(new URL('../../../schemas/booking.surface.schema.json', import.meta.url), 'utf8'));
|
|
5
|
+
const intentSchema = JSON.parse(readFileSync(new URL('../../../schemas/booking.intent.schema.json', import.meta.url), 'utf8'));
|
|
6
|
+
/** Canonical schema bytes (single source of truth) for prompt/tool derivations elsewhere. */
|
|
7
|
+
export const bookingSurfaceSchema = schema;
|
|
8
|
+
const ajv = new Ajv2020({ allErrors: true, strict: true });
|
|
9
|
+
ajv.addSchema(schema);
|
|
10
|
+
const validate = ajv.compile(schema);
|
|
11
|
+
const validateActionCanonical = ajv.compile({ $ref: `${schema.$id}#/$defs/Action` });
|
|
12
|
+
const validateBlockerCanonical = ajv.compile({ $ref: `${schema.$id}#/$defs/Blocker` });
|
|
13
|
+
const validateApprovalCanonical = ajv.compile({ $ref: `${schema.$id}#/$defs/Approval` });
|
|
14
|
+
const validateEventCanonical = ajv.compile({ $ref: `${schema.$id}#/$defs/Event` });
|
|
15
|
+
const validateIntentCanonical = ajv.compile(intentSchema);
|
|
16
|
+
const kinds = new Set(BOOKING_READ_ACTION_KINDS);
|
|
17
|
+
const codes = new Set(BOOKING_BLOCKER_CODES);
|
|
18
|
+
const gapCodes = new Set(BOOKING_GAP_CODES);
|
|
19
|
+
const safeOpaque = (value) => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9:._-]*$/.test(value);
|
|
20
|
+
const safeRequestKey = (value) => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9:._-]{7,127}$/.test(value) && !secret.test(value);
|
|
21
|
+
const secret = /(?:Bearer\s+\S|\bsk-(?!ill(?:s)?\b)[A-Za-z0-9_-]{12,}|\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+)/i;
|
|
22
|
+
// `.example` is reserved for documentation, so these identifiers cannot be a
|
|
23
|
+
// real mailbox. Do not allowlist lookalikes on routable domains.
|
|
24
|
+
const technicalEmail = /^(?:schema|version)@[a-z0-9-]+\.example$/i;
|
|
25
|
+
const currencyAmount = /\b(?:[A-Z]{3}\s*\d+(?:\.\d+)?|\d+(?:\.\d+)?\s*[A-Z]{3})\b/;
|
|
26
|
+
const rfc3339DateTime = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|([+-])(\d{2}):(\d{2}))$/;
|
|
27
|
+
export function isBookingDateTime(value) {
|
|
28
|
+
if (typeof value !== 'string')
|
|
29
|
+
return false;
|
|
30
|
+
const match = rfc3339DateTime.exec(value);
|
|
31
|
+
if (!match)
|
|
32
|
+
return false;
|
|
33
|
+
const [, yearText, monthText, dayText, hourText, minuteText, secondText] = match;
|
|
34
|
+
const year = Number(yearText);
|
|
35
|
+
const month = Number(monthText);
|
|
36
|
+
const day = Number(dayText);
|
|
37
|
+
const hour = Number(hourText);
|
|
38
|
+
const minute = Number(minuteText);
|
|
39
|
+
const second = Number(secondText);
|
|
40
|
+
const offsetHour = match[9] === undefined ? 0 : Number(match[9]);
|
|
41
|
+
const offsetMinute = match[10] === undefined ? 0 : Number(match[10]);
|
|
42
|
+
if (month < 1 || month > 12 || hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59)
|
|
43
|
+
return false;
|
|
44
|
+
const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
|
|
45
|
+
if (day < 1 || day > daysInMonth)
|
|
46
|
+
return false;
|
|
47
|
+
return !Number.isNaN(Date.parse(value));
|
|
48
|
+
}
|
|
49
|
+
function normalizedWords(value) {
|
|
50
|
+
return value.normalize('NFKC').replace(/[^\p{L}\p{N}.]+/gu, ' ').trim();
|
|
51
|
+
}
|
|
52
|
+
function hasSupplierCost(value) {
|
|
53
|
+
const normalized = normalizedWords(value);
|
|
54
|
+
const lower = normalized.toLowerCase();
|
|
55
|
+
return (/\b(?:supplier|vendor|internal)\b/.test(lower) &&
|
|
56
|
+
/\b(?:cost|rate|price)\b/.test(lower) &&
|
|
57
|
+
currencyAmount.test(normalized.toUpperCase()));
|
|
58
|
+
}
|
|
59
|
+
function hasInternationalPhone(value) {
|
|
60
|
+
const normalized = value.normalize('NFKC');
|
|
61
|
+
for (const plusIndex of normalized.split('').flatMap((char, index) => char === '+' ? [index] : [])) {
|
|
62
|
+
let digits = '';
|
|
63
|
+
for (const char of normalized.slice(plusIndex + 1, plusIndex + 48)) {
|
|
64
|
+
if (/\d/u.test(char))
|
|
65
|
+
digits += char;
|
|
66
|
+
else if (/\p{L}|@/u.test(char))
|
|
67
|
+
break;
|
|
68
|
+
if (digits.length > 15)
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
if (/^[1-9]\d{7,14}$/.test(digits))
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function hasPaymentCard(value) {
|
|
77
|
+
const normalized = value.normalize('NFKC');
|
|
78
|
+
const candidates = normalized.match(/(?:\d[ -]?){12,18}\d/g) ?? [];
|
|
79
|
+
const explicitlyLabeled = /\b(?:card|payment|visa|mastercard)\b/i.test(normalized);
|
|
80
|
+
return candidates.some((candidate) => (explicitlyLabeled || /[ -]/.test(candidate)) && luhn(candidate));
|
|
81
|
+
}
|
|
82
|
+
function hasSensitiveText(value, opts = {}) {
|
|
83
|
+
const normalized = value.normalize('NFKC');
|
|
84
|
+
if (normalized.includes('@') && !technicalEmail.test(normalized.trim()))
|
|
85
|
+
return true;
|
|
86
|
+
return secret.test(normalized) || hasInternationalPhone(normalized) || hasSupplierCost(normalized) || (!opts.allowOpaqueNumericId && hasPaymentCard(normalized));
|
|
87
|
+
}
|
|
88
|
+
function luhn(value) { const digits = value.replaceAll(/\D/g, ''); if (digits.length < 13 || digits.length > 19)
|
|
89
|
+
return false; let sum = 0; for (let i = digits.length - 1, parity = 0; i >= 0; i--, parity++) {
|
|
90
|
+
let n = Number(digits[i]);
|
|
91
|
+
if (parity % 2 === 1) {
|
|
92
|
+
n *= 2;
|
|
93
|
+
if (n > 9)
|
|
94
|
+
n -= 9;
|
|
95
|
+
}
|
|
96
|
+
sum += n;
|
|
97
|
+
} return sum % 10 === 0; }
|
|
98
|
+
const opaqueFieldNames = new Set([
|
|
99
|
+
'eventId', 'taskId', 'contextRef', 'actionId', 'hotelRef', 'offerRef', 'offerVersionRef', 'checkedOfferVersionRef', 'currentOfferVersionRef', 'verifiedOfferRef',
|
|
100
|
+
'orderRef', 'searchSessionRef', 'handoffRef', 'questionId', 'blockerId', 'approvalId',
|
|
101
|
+
'sourceActionId', 'targetActionId', 'sourceTurnId', 'turnId', 'requestKey', 'taskHandle',
|
|
102
|
+
'nonce', 'deliveryNonce', 'optionDigest', 'sourceReceiptDigest', 'valueDigest',
|
|
103
|
+
]);
|
|
104
|
+
function isOpaqueFieldPath(path) {
|
|
105
|
+
const clean = path.replace(/\[\]$/g, '');
|
|
106
|
+
const field = clean.split('.').at(-1);
|
|
107
|
+
return field ? opaqueFieldNames.has(field) || field.endsWith('Ref') || field.endsWith('Refs') : false;
|
|
108
|
+
}
|
|
109
|
+
const scan = (v, path = '$') => typeof v === 'string'
|
|
110
|
+
? hasSensitiveText(v, { allowOpaqueNumericId: isOpaqueFieldPath(path) })
|
|
111
|
+
: Array.isArray(v)
|
|
112
|
+
? v.some((child) => scan(child, `${path}[]`))
|
|
113
|
+
: !!v && typeof v === 'object'
|
|
114
|
+
? Object.entries(v).some(([k, x]) => /cost|price/i.test(k) ? /supplier|internal|wholesale/i.test(String(x)) : scan(x, `${path}.${k}`))
|
|
115
|
+
: false;
|
|
116
|
+
export function isSafeBookingRequestKey(value) { return safeRequestKey(value); }
|
|
117
|
+
function errors(v) { return (v.errors ?? []).map(e => `${e.instancePath || '$'}: ${e.message ?? e.keyword}`); }
|
|
118
|
+
function workspaceErrors(workspace, path) {
|
|
119
|
+
const e = [];
|
|
120
|
+
if (!workspace || typeof workspace !== 'object' || Array.isArray(workspace))
|
|
121
|
+
return e;
|
|
122
|
+
const loadedOffers = Array.isArray(workspace.loadedOffers) ? workspace.loadedOffers : [];
|
|
123
|
+
const offerRefs = loadedOffers.map((offer) => offer?.offerRef).filter((ref) => typeof ref === 'string');
|
|
124
|
+
const offerVersionRefs = loadedOffers.map((offer) => offer?.offerVersionRef).filter((ref) => typeof ref === 'string');
|
|
125
|
+
if (new Set(offerRefs).size !== offerRefs.length)
|
|
126
|
+
e.push(`${path}.loadedOffers: duplicate offerRef`);
|
|
127
|
+
if (new Set(offerVersionRefs).size !== offerVersionRefs.length)
|
|
128
|
+
e.push(`${path}.loadedOffers: duplicate offerVersionRef`);
|
|
129
|
+
const shortlisted = Array.isArray(workspace.shortlistedOfferRefs) ? workspace.shortlistedOfferRefs : [];
|
|
130
|
+
if (shortlisted.some((ref) => typeof ref !== 'string' || !loadedOffers.some((offer) => offer?.offerRef === ref))) {
|
|
131
|
+
e.push(`${path}.shortlistedOfferRefs: every ref must be a loaded offer`);
|
|
132
|
+
}
|
|
133
|
+
if (workspace.selectedOfferRef !== undefined && !loadedOffers.some((offer) => offer?.offerRef === workspace.selectedOfferRef)) {
|
|
134
|
+
e.push(`${path}.selectedOfferRef: loaded offer required`);
|
|
135
|
+
}
|
|
136
|
+
const verified = workspace.verifiedOffer;
|
|
137
|
+
if (verified !== undefined) {
|
|
138
|
+
if (!loadedOffers.some((offer) => offer?.offerRef === verified.offerRef && offer?.offerVersionRef === verified.offerVersionRef))
|
|
139
|
+
e.push(`${path}.verifiedOffer: loaded offer version required`);
|
|
140
|
+
if (!safeOpaque(verified.verifiedOfferRef) || !isBookingDateTime(verified.expiresAt))
|
|
141
|
+
e.push(`${path}.verifiedOffer: safe ref and parseable expiry required`);
|
|
142
|
+
}
|
|
143
|
+
return e;
|
|
144
|
+
}
|
|
145
|
+
function cross(value) {
|
|
146
|
+
const e = [];
|
|
147
|
+
if (scan(value))
|
|
148
|
+
e.push('$: unsafe PII/payment/supplier-cost/credential text');
|
|
149
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
150
|
+
return e;
|
|
151
|
+
const x = value;
|
|
152
|
+
const semantic = x.kind === 'action.receipt.continuation' ? x.receipt : x;
|
|
153
|
+
if (x.workspace && x.kind !== 'user.turn.ingress')
|
|
154
|
+
e.push(...workspaceErrors(x.workspace, '$.workspace'));
|
|
155
|
+
if (x.schemaVersion === 'booking.surface' && Array.isArray(x.loadedOffers))
|
|
156
|
+
e.push(...workspaceErrors(x, '$'));
|
|
157
|
+
if (x.kind === 'user.turn.ingress') {
|
|
158
|
+
if (!safeRequestKey(x.requestKey))
|
|
159
|
+
e.push('$.requestKey: safe opaque request key required');
|
|
160
|
+
const workspace = x.workspace;
|
|
161
|
+
e.push(...workspaceErrors(workspace, '$.workspace'));
|
|
162
|
+
const visibleHotels = Array.isArray(workspace?.visibleHotels) ? workspace.visibleHotels : [];
|
|
163
|
+
const loadedOffers = Array.isArray(workspace?.loadedOffers) ? workspace.loadedOffers : [];
|
|
164
|
+
if (workspace?.focusedHotelRef !== undefined && !visibleHotels.some((hotel) => hotel?.hotelRef === workspace.focusedHotelRef))
|
|
165
|
+
e.push('$.workspace.focusedHotelRef: visible hotel required');
|
|
166
|
+
const selectedOffer = workspace?.selectedOfferRef === undefined ? undefined : loadedOffers.find((offer) => offer?.offerRef === workspace.selectedOfferRef);
|
|
167
|
+
if (workspace?.selectedOfferRef !== undefined && !selectedOffer)
|
|
168
|
+
e.push('$.workspace.selectedOfferRef: loaded offer required');
|
|
169
|
+
if (selectedOffer && !visibleHotels.some((hotel) => hotel?.hotelRef === selectedOffer.hotelRef))
|
|
170
|
+
e.push('$.workspace.selectedOfferRef: offer hotel must be visible');
|
|
171
|
+
}
|
|
172
|
+
if (semantic !== x && semantic?.resultContract?.hardCriteriaMet === true && semantic.resultContract.blockers?.length)
|
|
173
|
+
e.push('$.receipt.resultContract: hardCriteriaMet cannot coexist with blockers');
|
|
174
|
+
if (kinds.has(x.kind)) {
|
|
175
|
+
const allowed = {
|
|
176
|
+
'search.patch': ['patch'], 'search.run': [], 'results.view.patch': ['patch'],
|
|
177
|
+
'hotel.focus': ['hotelRef'], 'hotel.select': ['hotelRef'],
|
|
178
|
+
'offers.query': ['hotelRefs', 'criteria'], 'offers.view.patch': ['hotelRef', 'criteria'],
|
|
179
|
+
'offers.compare': ['offerRefs', 'requestedCount'], 'offer.select': ['offerRef', 'offerVersionRef'],
|
|
180
|
+
'offer.check': ['offerRef', 'offerVersionRef'], 'checkout.prepare': ['offerRef', 'offerVersionRef', 'verifiedOfferRef'], 'order.observe': ['orderRef'],
|
|
181
|
+
};
|
|
182
|
+
const input = x.input;
|
|
183
|
+
if (!input || typeof input !== 'object' || Array.isArray(input) || Object.keys(input).some(k => !allowed[x.kind].includes(k)))
|
|
184
|
+
e.push('$.input: closed kind-specific input required');
|
|
185
|
+
}
|
|
186
|
+
if (x.kind === 'action.receipt' && x.resultContract?.hardCriteriaMet === true && x.resultContract.blockers?.length)
|
|
187
|
+
e.push('$.resultContract: hardCriteriaMet cannot coexist with blockers');
|
|
188
|
+
if (x.kind === 'user.turn' && Array.isArray(x.request?.approval))
|
|
189
|
+
e.push('$.request.approval: at most one approval');
|
|
190
|
+
if (x.kind === 'action.receipt' || x.kind === 'action.receipt.continuation') {
|
|
191
|
+
const r = x.kind === 'action.receipt.continuation' ? x.receipt : x;
|
|
192
|
+
if (r?.resultContract?.gapCodes?.some((code) => !gapCodes.has(String(code))))
|
|
193
|
+
e.push('$.resultContract.gapCodes: unregistered gap code');
|
|
194
|
+
const observation = r?.observation;
|
|
195
|
+
if (observation?.kind === 'offer.availability') {
|
|
196
|
+
if (r.status === 'applied' && (observation.available !== true || !observation.verifiedOfferRef || observation.currentOfferVersionRef !== observation.checkedOfferVersionRef || observation.changedFactRefs?.length || observation.gapCodes?.length))
|
|
197
|
+
e.push('$.observation: applied availability requires unchanged checked/current version, verified ref, and no gaps');
|
|
198
|
+
if (r.status === 'applied' && (r.resultContract?.outcome !== 'complete' || r.resultContract?.hardCriteriaMet !== true || r.resultContract?.gapCodes?.length || r.resultContract?.blockers?.length))
|
|
199
|
+
e.push('$.resultContract: applied availability requires complete hard-criteria result without gaps or blockers');
|
|
200
|
+
if (r.status === 'changed' && (observation.available !== true || !observation.currentOfferVersionRef || observation.currentOfferVersionRef === observation.checkedOfferVersionRef || !observation.changedFactRefs?.length || observation.verifiedOfferRef))
|
|
201
|
+
e.push('$.observation: changed availability requires available replacement current version without verified ref');
|
|
202
|
+
if ((r.status === 'unavailable' || r.status === 'no_match') && (observation.available !== false || observation.currentOfferVersionRef || observation.verifiedOfferRef))
|
|
203
|
+
e.push('$.observation: negative availability must not expose current or verified version');
|
|
204
|
+
if (r.status !== 'applied' && observation.verifiedOfferRef)
|
|
205
|
+
e.push('$.observation: only applied availability may expose verified ref');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const blocker = x.blocker ?? x.question?.blocker;
|
|
209
|
+
if (blocker && !/^(searchDraft|results|offers|checkout)(\.[A-Za-z][A-Za-z0-9_]*){0,3}$/.test(blocker.criterionPath ?? ''))
|
|
210
|
+
e.push('$.blocker.criterionPath: closed criterion path required');
|
|
211
|
+
if (blocker?.evidence?.factRefs && new Set(blocker.evidence.factRefs).size !== blocker.evidence.factRefs.length)
|
|
212
|
+
e.push('$.blocker.evidence.factRefs: unique refs required');
|
|
213
|
+
if (x.kind === 'question' && blocker && Array.isArray(x.question?.approvalOptions)) {
|
|
214
|
+
for (const [i, option] of x.question.approvalOptions.entries()) {
|
|
215
|
+
const result = validateApprovalAgainstBlocker(option?.approval, blocker);
|
|
216
|
+
if (!result.ok)
|
|
217
|
+
e.push(...result.errors.map(error => `$.question.approvalOptions[${i}].${error.slice(2)}`));
|
|
218
|
+
if (option?.approval?.taskId !== x.taskId)
|
|
219
|
+
e.push(`$.question.approvalOptions[${i}].approval.taskId: must match event`);
|
|
220
|
+
if (option?.approval?.contextRef !== x.contextRef)
|
|
221
|
+
e.push(`$.question.approvalOptions[${i}].approval.contextRef: must match event`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (kinds.has(String(x.kind)) && x.relaxationApprovalRef) {
|
|
225
|
+
const ref = x.relaxationApprovalRef;
|
|
226
|
+
if (ref.contextRef !== x.contextRef)
|
|
227
|
+
e.push('$.relaxationApprovalRef.contextRef: must match action');
|
|
228
|
+
if (ref.sourceRevision !== x.expectedRevision)
|
|
229
|
+
e.push('$.relaxationApprovalRef.sourceRevision: must equal action revision');
|
|
230
|
+
if (ref.targetActionKind !== x.kind)
|
|
231
|
+
e.push('$.relaxationApprovalRef.targetActionKind: must match action kind');
|
|
232
|
+
if (ref.targetActionId !== x.actionId)
|
|
233
|
+
e.push('$.relaxationApprovalRef.targetActionId: must match action id');
|
|
234
|
+
// Expiry and one-time consumption are runtime concerns; validation checks only structure/binding.
|
|
235
|
+
if (!safeOpaque(ref.nonce) || !isBookingDateTime(ref.expiresAt))
|
|
236
|
+
e.push('$.relaxationApprovalRef: invalid expiry or nonce');
|
|
237
|
+
}
|
|
238
|
+
if (x.kind === 'question' && (!Array.isArray(x.question?.approvalOptions) || x.question.approvalOptions.length < 1 || x.question.approvalOptions.length > 2))
|
|
239
|
+
e.push('$.question.approvalOptions: one or two options required');
|
|
240
|
+
return e;
|
|
241
|
+
}
|
|
242
|
+
export function validateBookingSurface(value) { const ok = validate(value); const e = ok ? [] : errors(validate); e.push(...cross(value)); return e.length ? { ok: false, errors: e } : { ok: true }; }
|
|
243
|
+
function fromCanonical(fn, value) { const ok = fn(value); const e = ok ? [] : errors(fn); e.push(...cross(value)); return e.length ? { ok: false, errors: e } : { ok: true }; }
|
|
244
|
+
export function validateBookingReadAction(value) { return fromCanonical(validateActionCanonical, value); }
|
|
245
|
+
export function validateCriterionBlocker(value) { return fromCanonical(validateBlockerCanonical, value); }
|
|
246
|
+
export function validateRelaxationApproval(value) { return fromCanonical(validateApprovalCanonical, value); }
|
|
247
|
+
export function validateBookingSurfaceEvent(value) { return fromCanonical(validateEventCanonical, value); }
|
|
248
|
+
export function validateBookingIntentProjection(value) { return fromCanonical(validateIntentCanonical, value); }
|
|
249
|
+
export function validateApprovalAgainstBlocker(approval, blocker) {
|
|
250
|
+
const a = approval;
|
|
251
|
+
const b = blocker;
|
|
252
|
+
const blockerResult = validateCriterionBlocker(b);
|
|
253
|
+
if (!blockerResult.ok)
|
|
254
|
+
return blockerResult;
|
|
255
|
+
const approvalResult = validateRelaxationApproval(a);
|
|
256
|
+
if (!approvalResult.ok)
|
|
257
|
+
return approvalResult;
|
|
258
|
+
const fields = ['blockerId', 'sourceActionId', 'sourceReceiptDigest', 'scope', 'code', 'criterionPath', 'valueDigest'];
|
|
259
|
+
const mismatches = fields.filter(field => a[field] !== b?.[field]);
|
|
260
|
+
return mismatches.length ? { ok: false, errors: mismatches.map(field => `$.${field}: approval does not match blocker`) } : { ok: true };
|
|
261
|
+
}
|
package/dist/src/bridge.js
CHANGED
|
@@ -1,34 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GoTry 桥接工具集(纯 Node 版,无 Python 依赖):
|
|
3
|
+
* - ensureStateDir: 状态目录创建
|
|
4
|
+
* - recordLatency: 延迟日志追加
|
|
5
|
+
* - readJson / writeJson: JSON 文件安全读写
|
|
6
|
+
*
|
|
7
|
+
* 历史:曾有 callFeasibilityEngine 用 spawn(.venv/bin/python) 起 Python CLI,
|
|
8
|
+
* 作为 TS 求解的回退路径。D-7 切轨后 unified solveChoiceSegment 是唯一求解入口,
|
|
9
|
+
* Python oracle 路径于 v0.0.1-rc.2 移除——npm 一键分发不再需要 Python 运行时依赖。
|
|
10
|
+
*/
|
|
1
11
|
import { appendFile, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
12
|
import { join } from 'node:path';
|
|
13
|
+
/** 状态目录:动机画像 / wish pool 的落盘位置(红线 6:用户数据可见、可编辑、可删除) */
|
|
3
14
|
export async function ensureStateDir(root) {
|
|
4
15
|
const dir = join(root, 'gotry-state');
|
|
5
|
-
await mkdir(dir, {
|
|
6
|
-
recursive: true
|
|
7
|
-
});
|
|
16
|
+
await mkdir(dir, { recursive: true });
|
|
8
17
|
return dir;
|
|
9
18
|
}
|
|
19
|
+
/** JSON 安全读取:文件不存在返回 fallback,解析失败抛错 */
|
|
10
20
|
export async function readJson(path, fallback) {
|
|
11
21
|
try {
|
|
12
22
|
const text = await readFile(path, 'utf-8');
|
|
13
23
|
return JSON.parse(text);
|
|
14
|
-
}
|
|
15
|
-
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
if (e.code === 'ENOENT')
|
|
27
|
+
return fallback;
|
|
16
28
|
throw e;
|
|
17
29
|
}
|
|
18
30
|
}
|
|
31
|
+
/** JSON 原子写入 */
|
|
19
32
|
export async function writeJson(path, value) {
|
|
20
33
|
const tmp = `${path}.tmp`;
|
|
21
34
|
await writeFile(tmp, JSON.stringify(value, null, 2), 'utf-8');
|
|
22
35
|
const { rename } = await import('node:fs/promises');
|
|
23
36
|
await rename(tmp, path);
|
|
24
37
|
}
|
|
38
|
+
/** 桥接延迟日志(追加式;T5 成本工程的度量数据源之一) */
|
|
25
39
|
export async function recordLatency(logPath, latencyMs, kind) {
|
|
26
|
-
await appendFile(logPath, JSON.stringify({
|
|
27
|
-
ts: new Date().toISOString(),
|
|
28
|
-
kind,
|
|
29
|
-
latencyMs
|
|
30
|
-
}) + '\n');
|
|
40
|
+
await appendFile(logPath, JSON.stringify({ ts: new Date().toISOString(), kind, latencyMs }) + '\n');
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
//# sourceURL=/Users/bytedance/work/gotry/ts/src/bridge.ts
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 同行人档案(memory-design M5 层,P2):同行人及其约束(行动/健康/偏好)的持久化。
|
|
3
|
+
*
|
|
4
|
+
* 立场(memory-design §1):
|
|
5
|
+
* - 溯源 P0:每条约束伴 evidence(用户原话),追加不删史;
|
|
6
|
+
* - 约束只进排序与行程结构建议,永不进硬过滤;
|
|
7
|
+
* - **负面清单守卫**:证件号/电话/地址等敏感字段拒收入库(需要时后端从登录态
|
|
8
|
+
* 填充,fail-closed)——health 存的是「高血压/晕车」这类行为约束,不是病历;
|
|
9
|
+
* - upsert 合并语义同 mergeProfile:追加不删史/同内容幂等。
|
|
10
|
+
*/
|
|
11
|
+
/** 负面清单:命中即拒收(红线 6 + 隐私立场) */
|
|
12
|
+
const SENSITIVE_PATTERNS = [
|
|
13
|
+
{ re: /\d{15,17}[Xx]?/, label: '疑似证件号/卡号' },
|
|
14
|
+
{ re: /1[3-9]\d{9}/, label: '疑似手机号' },
|
|
15
|
+
{ re: /(护照|身份证|证件号|通行证)\s*号?\s*[::]?\s*\w+/i, label: '证件信息' },
|
|
16
|
+
];
|
|
17
|
+
/** 守门:内容命中负面清单 → 返回拒收理由;否则 null */
|
|
18
|
+
export function sensitiveViolation(text) {
|
|
19
|
+
for (const { re, label } of SENSITIVE_PATTERNS) {
|
|
20
|
+
if (re.test(text))
|
|
21
|
+
return `负面清单拒收:${label}不入库(需要时由后端从登录态填充)`;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
/** 稳定主键:label 去空白 */
|
|
26
|
+
export function companionId(label) {
|
|
27
|
+
return label.replace(/\s+/g, '');
|
|
28
|
+
}
|
|
29
|
+
function mergeStrArray(oldArr, newArr) {
|
|
30
|
+
const a = oldArr ?? [];
|
|
31
|
+
let added = false;
|
|
32
|
+
for (const x of newArr ?? []) {
|
|
33
|
+
if (!a.includes(x)) {
|
|
34
|
+
a.push(x);
|
|
35
|
+
added = true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { merged: a, added };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* upsert 合并(纯函数,不改入参):同 companion_id 按 label 归并——
|
|
42
|
+
* constraints 逐字段取新值(新值覆盖旧行为约束,追加数组项),evidence 追加不删史,
|
|
43
|
+
* 全量无新增 → 幂等 no-op(appended:false)。
|
|
44
|
+
*/
|
|
45
|
+
export function upsertCompanion(profiles, patch) {
|
|
46
|
+
if (!patch.label?.trim())
|
|
47
|
+
return { profiles, appended: false, companionId: '', reason: 'label 必填' };
|
|
48
|
+
const violation = sensitiveViolation(JSON.stringify(patch));
|
|
49
|
+
if (violation)
|
|
50
|
+
return { profiles, appended: false, companionId: '', reason: violation };
|
|
51
|
+
const id = companionId(patch.label);
|
|
52
|
+
const existing = profiles.find(p => p.companion_id === id);
|
|
53
|
+
if (!existing) {
|
|
54
|
+
const full = {
|
|
55
|
+
schema: 'companion_profile.v1',
|
|
56
|
+
companion_id: id,
|
|
57
|
+
label: patch.label.trim(),
|
|
58
|
+
constraints: {
|
|
59
|
+
mobility: patch.constraints.mobility,
|
|
60
|
+
health: patch.constraints.health ? [...patch.constraints.health] : undefined,
|
|
61
|
+
prefs: patch.constraints.prefs ? [...patch.constraints.prefs] : undefined,
|
|
62
|
+
},
|
|
63
|
+
evidence: [patch.evidence],
|
|
64
|
+
ts: new Date().toISOString(),
|
|
65
|
+
};
|
|
66
|
+
return { profiles: [...profiles, full], appended: true, companionId: id };
|
|
67
|
+
}
|
|
68
|
+
const mergedConstraints = {
|
|
69
|
+
mobility: patch.constraints.mobility ?? existing.constraints.mobility,
|
|
70
|
+
health: mergeStrArray(existing.constraints.health, patch.constraints.health).merged,
|
|
71
|
+
prefs: mergeStrArray(existing.constraints.prefs, patch.constraints.prefs).merged,
|
|
72
|
+
};
|
|
73
|
+
const ev = mergeStrArray(existing.evidence, [patch.evidence]);
|
|
74
|
+
const healthLen = mergedConstraints.health?.length ?? 0;
|
|
75
|
+
const prefsLen = mergedConstraints.prefs?.length ?? 0;
|
|
76
|
+
const changed = mergedConstraints.mobility !== existing.constraints.mobility ||
|
|
77
|
+
healthLen !== (existing.constraints.health?.length ?? 0) ||
|
|
78
|
+
prefsLen !== (existing.constraints.prefs?.length ?? 0) ||
|
|
79
|
+
ev.added;
|
|
80
|
+
if (!changed)
|
|
81
|
+
return { profiles, appended: false, companionId: id };
|
|
82
|
+
const next = profiles.map(p => p.companion_id === id
|
|
83
|
+
? { ...p, constraints: mergedConstraints, evidence: ev.merged, ts: new Date().toISOString() }
|
|
84
|
+
: p);
|
|
85
|
+
return { profiles: next, appended: true, companionId: id };
|
|
86
|
+
}
|
package/dist/src/contracts.js
CHANGED
|
@@ -1,64 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage 1 契约层(S1,docs/design/stage1-top-down-design.md §2)——顶层数据与工具面契约。
|
|
3
|
+
*
|
|
4
|
+
* 自顶向下纪律:本文件是唯一权威契约。实现(mock 循环/求解器挂载/真 LLM)都向这里对齐;
|
|
5
|
+
* 契约变更需走设计文档升版,不随实现漂移。
|
|
6
|
+
* 责任铁律:LLM 只做问句组织/翻译/解释;判定与算术永远是确定性组件。
|
|
7
|
+
*/
|
|
8
|
+
/** 工具注册表:名字 → IO 类型(dsh 插件按此生成 parameters/output schema) */
|
|
1
9
|
export const TOOL_CONTRACTS = {
|
|
2
10
|
'gotry_interview_next': {},
|
|
3
11
|
'gotry_spec_extract': {},
|
|
4
12
|
'gotry_solve': {},
|
|
5
13
|
'gotry_render': {},
|
|
6
|
-
'gotry_wish_pool_add': {}
|
|
14
|
+
'gotry_wish_pool_add': {},
|
|
7
15
|
};
|
|
16
|
+
// ---- wire schema(dsh 注册用的 JSON Schema 面;type:'json' 根 + 关键字段文档) ----
|
|
8
17
|
export const TRIP_STATE_JSON_SCHEMA = {
|
|
9
18
|
type: 'object',
|
|
10
19
|
additionalProperties: false,
|
|
11
20
|
properties: {
|
|
12
21
|
calendar: {
|
|
13
|
-
type: 'object',
|
|
14
|
-
|
|
15
|
-
description: '年份与已断言的星期映射;一次断言终身使用,冲突必须显式指出'
|
|
22
|
+
type: 'object', additionalProperties: true,
|
|
23
|
+
description: '年份与已断言的星期映射;一次断言终身使用,冲突必须显式指出',
|
|
16
24
|
},
|
|
17
25
|
profile: {
|
|
18
|
-
type: 'object',
|
|
19
|
-
|
|
20
|
-
description: 'workWindow(带 evidence)/companions/budgetTier/bookedResources/motivation'
|
|
21
|
-
},
|
|
22
|
-
spec: {
|
|
23
|
-
type: 'json',
|
|
24
|
-
description: '统一行程模型 JourneySpec(见 unified.ts)'
|
|
25
|
-
},
|
|
26
|
-
solve: {
|
|
27
|
-
type: 'json',
|
|
28
|
-
description: '求解结果(锚点/排除/红旗/建议)'
|
|
26
|
+
type: 'object', additionalProperties: true,
|
|
27
|
+
description: 'workWindow(带 evidence)/companions/budgetTier/bookedResources/motivation',
|
|
29
28
|
},
|
|
29
|
+
spec: { type: 'json', description: '统一行程模型 JourneySpec(见 unified.ts)' },
|
|
30
|
+
solve: { type: 'json', description: '求解结果(锚点/排除/红旗/建议)' },
|
|
30
31
|
gates: {
|
|
31
32
|
type: 'array',
|
|
32
33
|
description: '待决问题,只能是选择题',
|
|
33
34
|
items: {
|
|
34
|
-
type: 'object',
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
id: {
|
|
38
|
-
type: 'string'
|
|
39
|
-
},
|
|
40
|
-
question: {
|
|
41
|
-
type: 'string'
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
35
|
+
type: 'object', additionalProperties: true,
|
|
36
|
+
properties: { id: { type: 'string' }, question: { type: 'string' } },
|
|
37
|
+
},
|
|
45
38
|
},
|
|
46
|
-
wishes: {
|
|
47
|
-
type: 'array',
|
|
48
|
-
description: '「下一次出发」清单',
|
|
49
|
-
items: {
|
|
50
|
-
type: 'object',
|
|
51
|
-
additionalProperties: true
|
|
52
|
-
}
|
|
53
|
-
}
|
|
39
|
+
wishes: { type: 'array', description: '「下一次出发」清单', items: { type: 'object', additionalProperties: true } },
|
|
54
40
|
},
|
|
55
|
-
required: [
|
|
56
|
-
'calendar',
|
|
57
|
-
'profile',
|
|
58
|
-
'gates',
|
|
59
|
-
'wishes'
|
|
60
|
-
]
|
|
41
|
+
required: ['calendar', 'profile', 'gates', 'wishes'],
|
|
61
42
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//# sourceURL=/Users/bytedance/work/gotry/ts/src/contracts.ts
|