@danceiny/gotry 0.0.1-rc.16 → 0.0.1-rc.17
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 +47 -13
- package/README.zh-CN.md +20 -10
- package/bin/gotry-booking-copilot.js +53 -0
- package/bin/gotry-bootstrap.js +111 -51
- package/bin/gotry-inner.js +442 -60
- package/bin/gotry-runtime-resolution.d.ts +27 -0
- package/bin/gotry-runtime-resolution.js +50 -0
- package/bin/gotry.js +1 -1
- package/cordis.gotry-patch.yml +5 -1
- package/dist/capabilities/agent-reach-deep.js +1 -1
- package/dist/capabilities/agent-reach.js +1 -1
- package/dist/capabilities/anything.js +1 -1
- package/dist/capabilities/artifacts.js +1 -1
- package/dist/capabilities/effect.js +1 -1
- package/dist/capabilities/fact-log.js +1 -1
- package/dist/capabilities/flyai.js +20 -6
- package/dist/capabilities/hbcli.js +1 -1
- package/dist/capabilities/incident-log.js +1 -1
- package/dist/capabilities/model-override.js +18 -0
- package/dist/capabilities/opensky.js +1 -1
- package/dist/capabilities/resilience.js +1 -1
- package/dist/capabilities/session/action-cache.js +1 -1
- package/dist/capabilities/session/adapters/ctrip-flight.js +1 -1
- package/dist/capabilities/session/adapters/meituan-local.js +1 -1
- package/dist/capabilities/session/benchmark.js +1 -1
- package/dist/capabilities/session/extension-bridge.js +19 -6
- package/dist/capabilities/session/extension-channel.js +3 -3
- package/dist/capabilities/session/extension-distribution.js +234 -0
- package/dist/capabilities/session/extract.js +1 -1
- package/dist/capabilities/session/golden-score.js +92 -0
- package/dist/capabilities/session/health-watch.js +1 -1
- package/dist/capabilities/session/read-guard.js +1 -1
- package/dist/capabilities/session/static-flight-golden.js +137 -0
- package/dist/capabilities/session/transport.js +1 -1
- package/dist/capabilities/session/wizard.js +21 -251
- package/dist/capabilities/session-consent.js +1 -1
- package/dist/capabilities/session-login.js +11 -5
- package/dist/capabilities/session-search.js +46 -4
- package/dist/capabilities/weather.js +168 -46
- package/dist/data/session-golden-20.json +25 -0
- package/dist/data/sf-golden-manifest.json +102 -0
- package/dist/data/sf-static-routes.json +91 -0
- package/dist/scripts/action-cache-tests.js +1 -1
- package/dist/scripts/agent-planning-budget-e2e.js +227 -0
- package/dist/scripts/agent-planning-budget-tests.js +173 -0
- package/dist/scripts/agent-reach-deep-tests.js +1 -1
- package/dist/scripts/agent-reach-tests.js +1 -1
- package/dist/scripts/agent-reach-wrapper-tests.js +1 -1
- package/dist/scripts/anything-tests.js +1 -1
- package/dist/scripts/async-collect.js +1 -1
- package/dist/scripts/benchmark-environment-bridge-e2e.js +981 -0
- package/dist/scripts/benchmark-environment-bridge-tests.js +2544 -0
- package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +335 -0
- package/dist/scripts/booking-copilot-availability-policy-v2-tests.js +1355 -0
- package/dist/scripts/booking-copilot-bin-proof-tests.js +89 -0
- package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +113 -0
- package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +356 -0
- package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +557 -0
- package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +140 -0
- package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +202 -0
- package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +102 -0
- package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +374 -0
- package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +447 -0
- package/dist/scripts/booking-copilot-runtime-proof-tests.js +205 -0
- package/dist/scripts/booking-copilot-server-proof-tests.js +317 -0
- package/dist/scripts/booking-copilot-startup-proof-tests.js +283 -0
- package/dist/scripts/booking-copilot-v2-runtime-proof-tests.js +3935 -0
- package/dist/scripts/booking-saga-tests.js +1 -1
- package/dist/scripts/booking-surface-contract-proof-tests.js +393 -0
- package/dist/scripts/booking-surface-v2-contract-proof-tests.js +1174 -0
- package/dist/scripts/bootstrap-tests.js +30 -10
- package/dist/scripts/build-changelog.js +1 -1
- package/dist/scripts/changelog-tests.js +1 -1
- package/dist/scripts/companion-tests.js +1 -1
- package/dist/scripts/diff-test.js +1 -1
- package/dist/scripts/dsh-runtime-closure-tests.js +225 -0
- package/dist/scripts/dsh-runtime-closure.js +150 -0
- package/dist/scripts/effect-tests.js +1 -1
- package/dist/scripts/engine-run.js +1 -1
- package/dist/scripts/engine-tests.js +1 -1
- package/dist/scripts/evaluation-cadence-tests.js +347 -0
- package/dist/scripts/evaluation-contract-tests.js +574 -0
- package/dist/scripts/extension-distribution-cli.js +35 -0
- package/dist/scripts/extension-distribution-tests.js +341 -0
- package/dist/scripts/extension-tests.js +128 -23
- package/dist/scripts/fact-gate-tests.js +1 -1
- package/dist/scripts/flyai-tests.js +1 -1
- package/dist/scripts/hbcli-e2e-tests.js +1 -1
- package/dist/scripts/hbcli-tests.js +1 -1
- package/dist/scripts/health-watch-cli.js +1 -1
- package/dist/scripts/i18n-tests.js +1 -1
- package/dist/scripts/incident-tests.js +1 -1
- package/dist/scripts/journey-tests.js +1 -1
- package/dist/scripts/ledger-tests.js +1 -1
- package/dist/scripts/ledger-workflow-crash.js +1 -1
- package/dist/scripts/memory-capture-tests.js +1 -1
- package/dist/scripts/memory-decay-tests.js +1 -1
- package/dist/scripts/memory-metrics.js +1 -1
- package/dist/scripts/memory-value-report.js +1 -1
- package/dist/scripts/model-override-e2e.js +176 -0
- package/dist/scripts/nightly-evidence-tests.js +1 -1
- package/dist/scripts/nightly-evidence.js +1 -1
- package/dist/scripts/nudge-digest.js +1 -1
- package/dist/scripts/onboarding-tests.js +21 -53
- package/dist/scripts/opensky-check.js +1 -1
- package/dist/scripts/opensky-tests.js +1 -1
- package/dist/scripts/pnpm-dsh-closure-proof.js +20 -0
- package/dist/scripts/price-drift-tests.js +1 -1
- package/dist/scripts/price-drift-watch.js +1 -1
- package/dist/scripts/probe-poi-tests.js +1 -1
- package/dist/scripts/product-metrics.js +1 -1
- package/dist/scripts/publish-preverify.js +40 -4
- package/dist/scripts/realtime-pricing-tests.js +1 -1
- package/dist/scripts/replay-async.js +1 -1
- package/dist/scripts/replay-real.js +1 -1
- package/dist/scripts/replay.js +1 -1
- package/dist/scripts/session-attach-diagnose.js +1 -1
- package/dist/scripts/session-attach-poc.js +1 -1
- package/dist/scripts/session-benchmark.js +1 -1
- package/dist/scripts/session-extract-tests.js +1 -1
- package/dist/scripts/session-login.js +1 -1
- package/dist/scripts/session-tests.js +70 -20
- package/dist/scripts/sf-live-benchmark.js +338 -0
- package/dist/scripts/sf-live-cli-tests.js +21 -0
- package/dist/scripts/sf-soft-score-tests.js +108 -0
- package/dist/scripts/sf-summary.js +93 -0
- package/dist/scripts/skeleton-check.js +1 -1
- package/dist/scripts/skeleton-integration-test.js +1 -1
- package/dist/scripts/skills-contract-tests.js +1 -1
- package/dist/scripts/smoke-session-gate-tests.js +29 -0
- package/dist/scripts/smoke.js +79 -33
- package/dist/scripts/state-cli-tests.js +1 -1
- package/dist/scripts/state-cli.js +1 -1
- package/dist/scripts/static-golden-tests.js +299 -0
- package/dist/scripts/time-eval-tests.js +1 -1
- package/dist/scripts/travel-timeline-tests.js +1 -1
- package/dist/scripts/unified-tests.js +1 -1
- package/dist/scripts/weather-tests.js +694 -44
- package/dist/scripts/z3-race-tests.js +1 -1
- package/dist/src/artifact-gate.js +1 -1
- package/dist/src/benchmark-agent-conformance.js +370 -0
- package/dist/src/benchmark-environment-bridge.js +384 -0
- package/dist/src/benchmark-headless-child-diagnostics.js +173 -0
- package/dist/src/benchmark-tool-isolation.js +124 -0
- package/dist/src/bookable-facts.js +1 -1
- package/dist/src/booking-saga.js +1 -1
- package/dist/src/booking-surface/availability-policy-v2.js +830 -0
- package/dist/src/booking-surface/canonical-schema.js +113 -0
- package/dist/src/booking-surface/contracts-v2.js +89 -0
- package/dist/src/booking-surface/contracts.js +46 -0
- package/dist/src/booking-surface/dsh-planner.js +453 -0
- package/dist/src/booking-surface/dsh-plugin.js +93 -0
- package/dist/src/booking-surface/error-codes.js +94 -0
- package/dist/src/booking-surface/index.js +15 -0
- package/dist/src/booking-surface/profile.js +68 -0
- package/dist/src/booking-surface/runtime-v2.js +1771 -0
- package/dist/src/booking-surface/runtime.js +351 -0
- package/dist/src/booking-surface/server-v2.js +334 -0
- package/dist/src/booking-surface/server.js +302 -0
- package/dist/src/booking-surface/startup.js +159 -0
- package/dist/src/booking-surface/validation-v2.js +319 -0
- package/dist/src/booking-surface/validation.js +809 -0
- package/dist/src/bridge.js +1 -1
- package/dist/src/companions.js +1 -1
- package/dist/src/contracts.js +1 -1
- package/dist/src/dsh-llm.js +1 -1
- package/dist/src/engine.js +1 -1
- package/dist/src/evaluation-cadence.js +234 -0
- package/dist/src/evaluation-contracts.js +906 -0
- package/dist/src/i18n.js +1 -1
- package/dist/src/index.js +50 -19
- package/dist/src/journey.js +1 -1
- package/dist/src/loop.js +1 -1
- package/dist/src/memory-capture.js +1 -1
- package/dist/src/memory-decay.js +1 -1
- package/dist/src/memory-utility.js +1 -1
- package/dist/src/mock-llm.js +1 -1
- package/dist/src/model.js +1 -1
- package/dist/src/realtime-pricing.js +1 -1
- package/dist/src/slot-spec.js +1 -1
- package/dist/src/state-ledger.js +2 -1
- package/dist/src/time-anchor.js +1 -1
- package/dist/src/tool-budget.js +136 -0
- package/dist/src/tool-packet.js +1 -1
- package/dist/src/travel-slots.js +1 -1
- package/dist/src/travel-timeline.js +1 -1
- package/dist/src/unified.js +1 -1
- package/dist/src/wish-pool.js +1 -1
- package/dist/src/z3-shared.js +1 -1
- package/extension/README.md +31 -7
- package/package.json +286 -11
- package/schemas/booking.surface.v1.schema.json +927 -0
- package/schemas/booking.surface.v2.schema.json +61 -0
- package/ts/capabilities/flyai.ts +16 -3
- package/ts/capabilities/session/extension-bridge.ts +37 -14
- package/ts/capabilities/session/extension-channel.ts +6 -3
- package/ts/capabilities/session/extension-distribution.ts +264 -0
- package/ts/capabilities/session/golden-score.ts +139 -0
- package/ts/capabilities/session/health-watch.ts +1 -1
- package/ts/capabilities/session/static-flight-golden.ts +209 -0
- package/ts/capabilities/session/wizard.ts +34 -176
- package/ts/capabilities/session-login.ts +15 -5
- package/ts/capabilities/session-search.ts +40 -3
- package/ts/capabilities/weather.ts +141 -52
- package/ts/package.json +3 -3
- package/ts/src/benchmark-agent-conformance.ts +448 -0
- package/ts/src/benchmark-environment-bridge.ts +348 -0
- package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
- package/ts/src/benchmark-tool-isolation.ts +166 -0
- package/ts/src/booking-surface/availability-policy-v2.ts +523 -0
- package/ts/src/booking-surface/canonical-schema.js +113 -0
- package/ts/src/booking-surface/contracts-v2.ts +118 -0
- package/ts/src/booking-surface/contracts.ts +380 -0
- package/ts/src/booking-surface/dsh-planner.ts +452 -0
- package/ts/src/booking-surface/dsh-plugin.js +93 -0
- package/ts/src/booking-surface/error-codes.ts +101 -0
- package/ts/src/booking-surface/index.ts +12 -0
- package/ts/src/booking-surface/profile.ts +42 -0
- package/ts/src/booking-surface/runtime-v2.ts +1466 -0
- package/ts/src/booking-surface/runtime.ts +483 -0
- package/ts/src/booking-surface/server-v2.ts +247 -0
- package/ts/src/booking-surface/server.ts +324 -0
- package/ts/src/booking-surface/startup.ts +196 -0
- package/ts/src/booking-surface/validation-v2.ts +205 -0
- package/ts/src/booking-surface/validation.ts +453 -0
- package/ts/src/index.ts +64 -11
- package/ts/src/state-ledger.ts +1 -0
- package/ts/src/tool-budget.ts +165 -0
- package/dist/scripts/wizard-bootstrap.js +0 -32
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
const root = resolve(import.meta.dirname, '../..');
|
|
7
|
+
const packageJson = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'));
|
|
8
|
+
assert.equal(packageJson.bin?.['gotry-booking-copilot'], 'bin/gotry-booking-copilot.js');
|
|
9
|
+
const build = spawnSync(process.execPath, [
|
|
10
|
+
'scripts/build-dist.mjs'
|
|
11
|
+
], {
|
|
12
|
+
cwd: root,
|
|
13
|
+
encoding: 'utf8'
|
|
14
|
+
});
|
|
15
|
+
assert.equal(build.status, 0, build.stderr || build.stdout);
|
|
16
|
+
const bin = join(root, 'bin/gotry-booking-copilot.js');
|
|
17
|
+
const missingKey = spawnSync(process.execPath, [
|
|
18
|
+
bin
|
|
19
|
+
], {
|
|
20
|
+
cwd: root,
|
|
21
|
+
env: {
|
|
22
|
+
PATH: process.env.PATH
|
|
23
|
+
},
|
|
24
|
+
encoding: 'utf8'
|
|
25
|
+
});
|
|
26
|
+
assert.equal(missingKey.status, 1);
|
|
27
|
+
assert.match(missingKey.stderr, /booking_copilot_api_key_required/);
|
|
28
|
+
const stateRoot = mkdtempSync(join(tmpdir(), 'gotry-booking-bin-'));
|
|
29
|
+
try {
|
|
30
|
+
const child = spawn(process.execPath, [
|
|
31
|
+
bin
|
|
32
|
+
], {
|
|
33
|
+
cwd: root,
|
|
34
|
+
env: {
|
|
35
|
+
PATH: process.env.PATH,
|
|
36
|
+
GOTRY_BOOKING_COPILOT_API_KEY: 'fixture-bff-key',
|
|
37
|
+
GOTRY_BOOKING_COPILOT_STATE_ROOT: stateRoot,
|
|
38
|
+
GOTRY_BOOKING_COPILOT_HOST: '127.0.0.1',
|
|
39
|
+
GOTRY_BOOKING_COPILOT_PORT: '0',
|
|
40
|
+
DEEPSEEK_API_KEY: 'fixture-model-key'
|
|
41
|
+
},
|
|
42
|
+
stdio: [
|
|
43
|
+
'ignore',
|
|
44
|
+
'pipe',
|
|
45
|
+
'pipe'
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
let stderr = '';
|
|
49
|
+
child.stderr.setEncoding('utf8');
|
|
50
|
+
child.stderr.on('data', (chunk)=>{
|
|
51
|
+
stderr += chunk;
|
|
52
|
+
});
|
|
53
|
+
await new Promise((resolveReady, reject)=>{
|
|
54
|
+
const timeout = setTimeout(()=>reject(new Error(`booking copilot bin did not listen: ${stderr}`)), 10_000);
|
|
55
|
+
const inspect = ()=>{
|
|
56
|
+
if (!stderr.includes('/a2a/booking-copilot/turn')) return;
|
|
57
|
+
clearTimeout(timeout);
|
|
58
|
+
resolveReady();
|
|
59
|
+
};
|
|
60
|
+
child.stderr.on('data', inspect);
|
|
61
|
+
child.once('exit', (code)=>{
|
|
62
|
+
clearTimeout(timeout);
|
|
63
|
+
reject(new Error(`booking copilot bin exited before listen: ${code}: ${stderr}`));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
assert.match(stderr, /listening on http:\/\/127\.0\.0\.1:\d+\/a2a\/booking-copilot\/turn/);
|
|
67
|
+
assert.ok(!stderr.includes('fixture-bff-key'));
|
|
68
|
+
assert.ok(!stderr.includes('fixture-model-key'));
|
|
69
|
+
child.kill('SIGTERM');
|
|
70
|
+
const exit = await new Promise((resolveExit)=>{
|
|
71
|
+
child.once('exit', (code, signal)=>resolveExit({
|
|
72
|
+
code,
|
|
73
|
+
signal
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
assert.deepEqual(exit, {
|
|
77
|
+
code: 0,
|
|
78
|
+
signal: null
|
|
79
|
+
}, `graceful shutdown failed: ${stderr}`);
|
|
80
|
+
} finally{
|
|
81
|
+
rmSync(stateRoot, {
|
|
82
|
+
recursive: true,
|
|
83
|
+
force: true
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
console.log('BOOKING COPILOT BIN PROOF: startup failure/listen/SIGTERM lifecycle OK');
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
//# sourceURL=ts/scripts/booking-copilot-bin-proof-tests.ts
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { ensureLedger } from '../src/state-ledger.js';
|
|
5
|
+
import { BOOKING_SURFACE_SCHEMA_SHA256, BOOKING_SURFACE_SCHEMA_VERSION } from '../src/booking-surface/contracts.js';
|
|
6
|
+
import { BookingCopilotTaskRuntime } from '../src/booking-surface/runtime.js';
|
|
7
|
+
import { startBookingCopilotServer } from '../src/booking-surface/server.js';
|
|
8
|
+
const API_KEY = 'test-only-cross-repo-key';
|
|
9
|
+
const stateRoot = mkdtempSync(join(tmpdir(), 'gotry-booking-copilot-crossrepo-'));
|
|
10
|
+
const ledger = ensureLedger(stateRoot);
|
|
11
|
+
let sequence = 0;
|
|
12
|
+
const plannerFactory = (initialTask)=>{
|
|
13
|
+
let receiptObserved = initialTask.lastReceipt !== undefined;
|
|
14
|
+
return {
|
|
15
|
+
async next ({ turn, task }) {
|
|
16
|
+
if (turn.kind === 'action.receipt.continuation') {
|
|
17
|
+
receiptObserved = true;
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
kind: 'terminal',
|
|
21
|
+
terminal: {
|
|
22
|
+
status: 'completed',
|
|
23
|
+
summary: 'Fixture receipt observed.',
|
|
24
|
+
factRefs: []
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
if (receiptObserved) {
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
kind: 'terminal',
|
|
33
|
+
terminal: {
|
|
34
|
+
status: 'completed',
|
|
35
|
+
summary: 'Fixture task already has a receipt.',
|
|
36
|
+
factRefs: []
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
const action = task.surface === 'payment_link' ? {
|
|
42
|
+
schemaVersion: BOOKING_SURFACE_SCHEMA_VERSION,
|
|
43
|
+
kind: 'hotel.select',
|
|
44
|
+
actionId: 'cross-repo-action-1',
|
|
45
|
+
contextRef: task.contextRef,
|
|
46
|
+
expectedRevision: task.revision,
|
|
47
|
+
reason: 'Select the requested hotel.',
|
|
48
|
+
factRefs: [],
|
|
49
|
+
input: {
|
|
50
|
+
hotelRef: 'hotel-proof-1'
|
|
51
|
+
}
|
|
52
|
+
} : {
|
|
53
|
+
schemaVersion: BOOKING_SURFACE_SCHEMA_VERSION,
|
|
54
|
+
kind: 'search.run',
|
|
55
|
+
actionId: 'cross-repo-action-1',
|
|
56
|
+
contextRef: task.contextRef,
|
|
57
|
+
expectedRevision: task.revision,
|
|
58
|
+
reason: 'Run the requested search.',
|
|
59
|
+
factRefs: [],
|
|
60
|
+
input: {}
|
|
61
|
+
};
|
|
62
|
+
return [
|
|
63
|
+
{
|
|
64
|
+
kind: 'operation',
|
|
65
|
+
action
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
async function main() {
|
|
72
|
+
const runtime = new BookingCopilotTaskRuntime(ledger, {
|
|
73
|
+
idFactory: (prefix)=>`${prefix}-cross-repo-${++sequence}`,
|
|
74
|
+
now: ()=>'2026-08-31T00:00:00.000Z'
|
|
75
|
+
});
|
|
76
|
+
const handle = await startBookingCopilotServer({
|
|
77
|
+
apiKey: API_KEY,
|
|
78
|
+
runtime,
|
|
79
|
+
plannerFactory,
|
|
80
|
+
host: '127.0.0.1',
|
|
81
|
+
port: 0
|
|
82
|
+
});
|
|
83
|
+
process.stdout.write(`BOOKING_COPILOT_FIXTURE_STARTUP=${JSON.stringify({
|
|
84
|
+
url: `http://127.0.0.1:${handle.port}`,
|
|
85
|
+
version: BOOKING_SURFACE_SCHEMA_VERSION,
|
|
86
|
+
sha256: BOOKING_SURFACE_SCHEMA_SHA256
|
|
87
|
+
})}\n`);
|
|
88
|
+
await new Promise((resolve)=>{
|
|
89
|
+
const stop = ()=>resolve();
|
|
90
|
+
process.once('SIGTERM', stop);
|
|
91
|
+
process.once('SIGINT', stop);
|
|
92
|
+
});
|
|
93
|
+
await handle.close();
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
await main();
|
|
97
|
+
} catch (error) {
|
|
98
|
+
process.stderr.write(`booking-copilot-crossrepo-fixture failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
99
|
+
process.exitCode = 1;
|
|
100
|
+
} finally{
|
|
101
|
+
try {
|
|
102
|
+
ledger.close();
|
|
103
|
+
} catch (error) {
|
|
104
|
+
process.stderr.write(`booking-copilot-crossrepo-fixture ledger close failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
105
|
+
}
|
|
106
|
+
rmSync(stateRoot, {
|
|
107
|
+
recursive: true,
|
|
108
|
+
force: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//# sourceURL=ts/scripts/booking-copilot-crossrepo-fixture-server.ts
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { createDshEmbeddedBookingPlanner, createDshEmbeddedBookingPlannerV2, DSH_EMBEDDED_BOOKING_TOOL_NAMES } from '../src/booking-surface/dsh-planner.js';
|
|
7
|
+
const action = {
|
|
8
|
+
schemaVersion: 'booking.surface.v1',
|
|
9
|
+
kind: 'search.run',
|
|
10
|
+
actionId: 'action-real-dsh-1',
|
|
11
|
+
contextRef: 'ctx-real-dsh-1',
|
|
12
|
+
expectedRevision: 0,
|
|
13
|
+
reason: 'Run the authoritative workspace search.',
|
|
14
|
+
factRefs: [],
|
|
15
|
+
input: {}
|
|
16
|
+
};
|
|
17
|
+
function sse(res, chunks) {
|
|
18
|
+
res.writeHead(200, {
|
|
19
|
+
'content-type': 'text/event-stream; charset=utf-8',
|
|
20
|
+
'cache-control': 'no-cache'
|
|
21
|
+
});
|
|
22
|
+
for (const chunk of chunks)res.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
|
23
|
+
res.end('data: [DONE]\n\n');
|
|
24
|
+
}
|
|
25
|
+
function objectKeys(value) {
|
|
26
|
+
if (Array.isArray(value)) return value.flatMap(objectKeys);
|
|
27
|
+
if (typeof value !== 'object' || value === null) return [];
|
|
28
|
+
return Object.entries(value).flatMap(([key, child])=>[
|
|
29
|
+
key,
|
|
30
|
+
...objectKeys(child)
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
const requests = [];
|
|
34
|
+
let modelCall = 0;
|
|
35
|
+
const modelServer = createServer((req, res)=>{
|
|
36
|
+
const parts = [];
|
|
37
|
+
req.on('data', (part)=>parts.push(part));
|
|
38
|
+
req.on('end', ()=>{
|
|
39
|
+
const body = JSON.parse(Buffer.concat(parts).toString('utf8'));
|
|
40
|
+
requests.push({
|
|
41
|
+
headers: req.headers,
|
|
42
|
+
body
|
|
43
|
+
});
|
|
44
|
+
modelCall += 1;
|
|
45
|
+
if (modelCall === 1) {
|
|
46
|
+
sse(res, [
|
|
47
|
+
{
|
|
48
|
+
id: 'chatcmpl-booking-1',
|
|
49
|
+
object: 'chat.completion.chunk',
|
|
50
|
+
created: 0,
|
|
51
|
+
model: 'deepseek-v4-flash',
|
|
52
|
+
choices: [
|
|
53
|
+
{
|
|
54
|
+
index: 0,
|
|
55
|
+
delta: {
|
|
56
|
+
role: 'assistant',
|
|
57
|
+
tool_calls: [
|
|
58
|
+
{
|
|
59
|
+
index: 0,
|
|
60
|
+
id: 'call-booking-1',
|
|
61
|
+
type: 'function',
|
|
62
|
+
function: {
|
|
63
|
+
name: 'booking_search_hotels',
|
|
64
|
+
arguments: JSON.stringify({
|
|
65
|
+
decision: {
|
|
66
|
+
kind: 'operation',
|
|
67
|
+
action
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
finish_reason: 'tool_calls'
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
usage: {
|
|
78
|
+
prompt_tokens: 10,
|
|
79
|
+
completion_tokens: 5,
|
|
80
|
+
total_tokens: 15
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
]);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (modelCall === 3) {
|
|
87
|
+
sse(res, [
|
|
88
|
+
{
|
|
89
|
+
id: 'chatcmpl-booking-v2-continuation',
|
|
90
|
+
object: 'chat.completion.chunk',
|
|
91
|
+
created: 0,
|
|
92
|
+
model: 'deepseek-v4-flash',
|
|
93
|
+
choices: [
|
|
94
|
+
{
|
|
95
|
+
index: 0,
|
|
96
|
+
delta: {
|
|
97
|
+
role: 'assistant',
|
|
98
|
+
tool_calls: [
|
|
99
|
+
{
|
|
100
|
+
index: 0,
|
|
101
|
+
id: 'call-booking-v2-continuation',
|
|
102
|
+
type: 'function',
|
|
103
|
+
function: {
|
|
104
|
+
name: 'booking_search_hotels',
|
|
105
|
+
arguments: JSON.stringify({
|
|
106
|
+
decision: {
|
|
107
|
+
kind: 'terminal',
|
|
108
|
+
terminal: {
|
|
109
|
+
status: 'stopped',
|
|
110
|
+
summary: 'v2 continuation handled',
|
|
111
|
+
factRefs: []
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
finish_reason: 'tool_calls'
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
]);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
sse(res, [
|
|
127
|
+
{
|
|
128
|
+
id: 'chatcmpl-booking-2',
|
|
129
|
+
object: 'chat.completion.chunk',
|
|
130
|
+
created: 0,
|
|
131
|
+
model: 'deepseek-v4-flash',
|
|
132
|
+
choices: [
|
|
133
|
+
{
|
|
134
|
+
index: 0,
|
|
135
|
+
delta: {
|
|
136
|
+
role: 'assistant',
|
|
137
|
+
content: 'Typed decision emitted.'
|
|
138
|
+
},
|
|
139
|
+
finish_reason: 'stop'
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
usage: {
|
|
143
|
+
prompt_tokens: 20,
|
|
144
|
+
completion_tokens: 4,
|
|
145
|
+
total_tokens: 24
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
await new Promise((resolve, reject)=>{
|
|
152
|
+
modelServer.once('error', reject);
|
|
153
|
+
modelServer.listen(0, '127.0.0.1', ()=>resolve());
|
|
154
|
+
});
|
|
155
|
+
const address = modelServer.address();
|
|
156
|
+
assert.ok(typeof address === 'object' && address);
|
|
157
|
+
const stateRoot = mkdtempSync(join(tmpdir(), 'gotry-booking-dsh-core-'));
|
|
158
|
+
const workspace = {
|
|
159
|
+
schemaVersion: 'booking.surface.v1',
|
|
160
|
+
contextRef: action.contextRef,
|
|
161
|
+
surface: 'tenant',
|
|
162
|
+
revision: 0,
|
|
163
|
+
locale: 'zh-CN',
|
|
164
|
+
currency: 'AED',
|
|
165
|
+
searchDraft: {},
|
|
166
|
+
results: {
|
|
167
|
+
status: 'idle'
|
|
168
|
+
},
|
|
169
|
+
visibleHotels: [],
|
|
170
|
+
loadedOffers: [],
|
|
171
|
+
shortlistedOfferRefs: [],
|
|
172
|
+
capabilities: {
|
|
173
|
+
surface: 'tenant',
|
|
174
|
+
allowedActions: [
|
|
175
|
+
'search.run'
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const turn = {
|
|
180
|
+
schemaVersion: 'booking.surface.v1',
|
|
181
|
+
kind: 'user.turn',
|
|
182
|
+
taskId: 'task-real-dsh-1',
|
|
183
|
+
workspace: {
|
|
184
|
+
...workspace,
|
|
185
|
+
capabilities: {
|
|
186
|
+
...workspace.capabilities,
|
|
187
|
+
allowedActions: [
|
|
188
|
+
...workspace.capabilities.allowedActions
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
request: {
|
|
193
|
+
text: '执行当前酒店搜索'
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const task = {
|
|
197
|
+
schemaVersion: 'booking.surface.v1',
|
|
198
|
+
taskId: 'task-real-dsh-1',
|
|
199
|
+
contextRef: action.contextRef,
|
|
200
|
+
surface: 'tenant',
|
|
201
|
+
revision: 0,
|
|
202
|
+
allowedActions: [
|
|
203
|
+
'search.run'
|
|
204
|
+
],
|
|
205
|
+
userTurnCount: 1,
|
|
206
|
+
lastUserTurnDigest: 'digest-only',
|
|
207
|
+
phase: 'planning',
|
|
208
|
+
lastSequence: 0
|
|
209
|
+
};
|
|
210
|
+
let planner;
|
|
211
|
+
try {
|
|
212
|
+
planner = await createDshEmbeddedBookingPlanner({
|
|
213
|
+
stateRoot,
|
|
214
|
+
env: {
|
|
215
|
+
PATH: process.env.PATH,
|
|
216
|
+
DEEPSEEK_API_KEY: 'fixture-model-key',
|
|
217
|
+
DEEPSEEK_BASE_URL: `http://127.0.0.1:${address.port}/v1`,
|
|
218
|
+
GOTRY_BOOKING_COPILOT_API_KEY: 'must-not-enter-dsh',
|
|
219
|
+
HOTELBYTE_TOKEN: 'must-not-enter-dsh'
|
|
220
|
+
},
|
|
221
|
+
maxTokens: 512
|
|
222
|
+
});
|
|
223
|
+
const decisions = await planner.plannerFactory(task).next({
|
|
224
|
+
turn,
|
|
225
|
+
task
|
|
226
|
+
});
|
|
227
|
+
assert.deepEqual(decisions, [
|
|
228
|
+
{
|
|
229
|
+
kind: 'operation',
|
|
230
|
+
action
|
|
231
|
+
}
|
|
232
|
+
]);
|
|
233
|
+
assert.equal(requests.length, 2, 'real dsh loop executes the typed tool then reaches idle');
|
|
234
|
+
const toolNames = requests[0].body.tools.map((tool)=>tool.function.name).sort();
|
|
235
|
+
assert.deepEqual(toolNames, [
|
|
236
|
+
...DSH_EMBEDDED_BOOKING_TOOL_NAMES
|
|
237
|
+
].sort(), 'real model request exposes exactly the seven embedded tools');
|
|
238
|
+
assert.ok(!toolNames.some((name)=>/gotry_book|payment|holder|guest/i.test(name)), 'real model request exposes no booking write or PII tool');
|
|
239
|
+
const executableKeys = requests[0].body.tools.flatMap((tool)=>objectKeys(tool.function.parameters));
|
|
240
|
+
assert.ok(!executableKeys.some((key)=>/^(book|payment|holder|guest|portalToken|supplierCost)$/i.test(key)), 'tool inputs expose no write or PII field');
|
|
241
|
+
assert.equal(requests[0].headers.authorization, 'Bearer fixture-model-key');
|
|
242
|
+
assert.ok(!JSON.stringify(requests).includes('must-not-enter-dsh'), 'BFF and portal credentials never enter the dsh model transport');
|
|
243
|
+
const v2Workspace = {
|
|
244
|
+
schemaVersion: 'booking.surface.v2',
|
|
245
|
+
contextRef: 'ctx-real-dsh-v2',
|
|
246
|
+
surface: 'tenant',
|
|
247
|
+
revision: 1,
|
|
248
|
+
locale: 'en-US',
|
|
249
|
+
currency: 'AED',
|
|
250
|
+
searchDraft: {},
|
|
251
|
+
results: {
|
|
252
|
+
status: 'idle'
|
|
253
|
+
},
|
|
254
|
+
visibleHotels: [],
|
|
255
|
+
loadedOffers: [],
|
|
256
|
+
shortlistedOfferRefs: [],
|
|
257
|
+
capabilities: {
|
|
258
|
+
surface: 'tenant',
|
|
259
|
+
allowedActions: [
|
|
260
|
+
'search.run'
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const v2Task = {
|
|
265
|
+
schemaVersion: 'booking.surface.v2',
|
|
266
|
+
taskId: 'task-real-dsh-v2',
|
|
267
|
+
contextRef: v2Workspace.contextRef,
|
|
268
|
+
surface: 'tenant',
|
|
269
|
+
revision: 1,
|
|
270
|
+
allowedActions: [
|
|
271
|
+
'search.run'
|
|
272
|
+
],
|
|
273
|
+
userTurnCount: 1,
|
|
274
|
+
operationCount: 1,
|
|
275
|
+
phase: 'planning',
|
|
276
|
+
lastSequence: 1,
|
|
277
|
+
availability: {
|
|
278
|
+
initialized: true,
|
|
279
|
+
recoveryStarted: false,
|
|
280
|
+
availabilityPhase: 'need_offers',
|
|
281
|
+
activeHotelOrdinal: 0,
|
|
282
|
+
hotelRefs: [],
|
|
283
|
+
hotels: {},
|
|
284
|
+
attempts: [],
|
|
285
|
+
queryReservations: []
|
|
286
|
+
},
|
|
287
|
+
workspaceSnapshot: v2Workspace
|
|
288
|
+
};
|
|
289
|
+
const v2Continuation = {
|
|
290
|
+
schemaVersion: 'booking.surface.v2',
|
|
291
|
+
kind: 'action.receipt.continuation',
|
|
292
|
+
taskId: v2Task.taskId,
|
|
293
|
+
workspace: v2Workspace,
|
|
294
|
+
receipt: {
|
|
295
|
+
schemaVersion: 'booking.surface.v2',
|
|
296
|
+
kind: 'action.receipt',
|
|
297
|
+
actionId: 'action-real-dsh-v2',
|
|
298
|
+
contextRef: v2Workspace.contextRef,
|
|
299
|
+
status: 'applied',
|
|
300
|
+
revision: 1,
|
|
301
|
+
observation: {
|
|
302
|
+
kind: 'search.state',
|
|
303
|
+
resultCount: 1
|
|
304
|
+
},
|
|
305
|
+
resultContract: {
|
|
306
|
+
outcome: 'complete',
|
|
307
|
+
hardCriteriaMet: true,
|
|
308
|
+
factRefs: [],
|
|
309
|
+
gapCodes: [],
|
|
310
|
+
blockers: [],
|
|
311
|
+
relaxationsApplied: []
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
const v2Planner = await createDshEmbeddedBookingPlannerV2({
|
|
316
|
+
stateRoot,
|
|
317
|
+
env: {
|
|
318
|
+
PATH: process.env.PATH,
|
|
319
|
+
DEEPSEEK_API_KEY: 'fixture-model-key',
|
|
320
|
+
DEEPSEEK_BASE_URL: `http://127.0.0.1:${address.port}/v1`
|
|
321
|
+
},
|
|
322
|
+
maxTokens: 512
|
|
323
|
+
});
|
|
324
|
+
try {
|
|
325
|
+
const continuationDecisions = await v2Planner.plannerFactory(v2Task).next({
|
|
326
|
+
turn: v2Continuation,
|
|
327
|
+
task: {
|
|
328
|
+
...v2Task,
|
|
329
|
+
lastReceipt: v2Continuation.receipt
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
assert.deepEqual(continuationDecisions, [
|
|
333
|
+
{
|
|
334
|
+
kind: 'terminal',
|
|
335
|
+
terminal: {
|
|
336
|
+
status: 'stopped',
|
|
337
|
+
summary: 'v2 continuation handled',
|
|
338
|
+
factRefs: []
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
], 'real dsh v2 accepts action.receipt.continuation through the typed planner seam');
|
|
342
|
+
} finally{
|
|
343
|
+
await v2Planner.close();
|
|
344
|
+
}
|
|
345
|
+
} finally{
|
|
346
|
+
await planner?.close();
|
|
347
|
+
await new Promise((resolve, reject)=>modelServer.close((error)=>error ? reject(error) : resolve()));
|
|
348
|
+
rmSync(stateRoot, {
|
|
349
|
+
recursive: true,
|
|
350
|
+
force: true
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
console.log('BOOKING COPILOT DSH CORE PROOF: real subprocess/sdk/plugin/tool-call/session event/idle OK');
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
//# sourceURL=ts/scripts/booking-copilot-dsh-core-proof-tests.ts
|