@danceiny/gotry 0.0.1-rc.16 → 0.0.1-rc.18

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.
Files changed (229) hide show
  1. package/README.md +161 -116
  2. package/README.zh-CN.md +173 -144
  3. package/bin/gotry-booking-copilot.js +53 -0
  4. package/bin/gotry-bootstrap.js +113 -66
  5. package/bin/gotry-inner.js +436 -70
  6. package/bin/gotry-runtime-resolution.d.ts +27 -0
  7. package/bin/gotry-runtime-resolution.js +50 -0
  8. package/bin/gotry.js +1 -1
  9. package/cordis.gotry-patch.yml +5 -1
  10. package/dist/capabilities/agent-reach-deep.js +1 -1
  11. package/dist/capabilities/agent-reach.js +1 -1
  12. package/dist/capabilities/anything.js +1 -1
  13. package/dist/capabilities/artifacts.js +1 -1
  14. package/dist/capabilities/effect.js +1 -1
  15. package/dist/capabilities/fact-log.js +1 -1
  16. package/dist/capabilities/flyai.js +20 -6
  17. package/dist/capabilities/hbcli.js +1 -1
  18. package/dist/capabilities/incident-log.js +1 -1
  19. package/dist/capabilities/model-override.js +18 -0
  20. package/dist/capabilities/opensky.js +1 -1
  21. package/dist/capabilities/resilience.js +1 -1
  22. package/dist/capabilities/session/action-cache.js +1 -1
  23. package/dist/capabilities/session/adapters/ctrip-flight.js +1 -1
  24. package/dist/capabilities/session/adapters/meituan-local.js +1 -1
  25. package/dist/capabilities/session/benchmark.js +1 -1
  26. package/dist/capabilities/session/extension-bridge.js +19 -6
  27. package/dist/capabilities/session/extension-channel.js +3 -3
  28. package/dist/capabilities/session/extension-distribution.js +234 -0
  29. package/dist/capabilities/session/extract.js +1 -1
  30. package/dist/capabilities/session/golden-score.js +92 -0
  31. package/dist/capabilities/session/health-watch.js +1 -1
  32. package/dist/capabilities/session/read-guard.js +1 -1
  33. package/dist/capabilities/session/static-flight-golden.js +137 -0
  34. package/dist/capabilities/session/transport.js +1 -1
  35. package/dist/capabilities/session/wizard.js +21 -251
  36. package/dist/capabilities/session-consent.js +1 -1
  37. package/dist/capabilities/session-login.js +11 -5
  38. package/dist/capabilities/session-search.js +46 -4
  39. package/dist/capabilities/weather.js +168 -46
  40. package/dist/data/session-golden-20.json +25 -0
  41. package/dist/data/sf-golden-manifest.json +102 -0
  42. package/dist/data/sf-static-routes.json +91 -0
  43. package/dist/scripts/action-cache-tests.js +1 -1
  44. package/dist/scripts/agent-planning-budget-e2e.js +227 -0
  45. package/dist/scripts/agent-planning-budget-tests.js +173 -0
  46. package/dist/scripts/agent-reach-deep-tests.js +1 -1
  47. package/dist/scripts/agent-reach-tests.js +1 -1
  48. package/dist/scripts/agent-reach-wrapper-tests.js +1 -1
  49. package/dist/scripts/anything-tests.js +1 -1
  50. package/dist/scripts/async-collect.js +1 -1
  51. package/dist/scripts/benchmark-environment-bridge-e2e.js +981 -0
  52. package/dist/scripts/benchmark-environment-bridge-tests.js +2544 -0
  53. package/dist/scripts/booking-copilot-availability-ledger-binding-tests.js +335 -0
  54. package/dist/scripts/booking-copilot-availability-policy-v2-tests.js +1355 -0
  55. package/dist/scripts/booking-copilot-bin-proof-tests.js +89 -0
  56. package/dist/scripts/booking-copilot-crossrepo-fixture-server.js +113 -0
  57. package/dist/scripts/booking-copilot-dsh-core-proof-tests.js +356 -0
  58. package/dist/scripts/booking-copilot-dsh-planner-proof-tests.js +557 -0
  59. package/dist/scripts/booking-copilot-dsh-plugin-proof-tests.js +140 -0
  60. package/dist/scripts/booking-copilot-event-sequence-concurrency-proof-tests.js +202 -0
  61. package/dist/scripts/booking-copilot-gap-code-contract-proof-tests.js +102 -0
  62. package/dist/scripts/booking-copilot-operation-ledger-concurrency-proof-tests.js +374 -0
  63. package/dist/scripts/booking-copilot-receipt-ledger-concurrency-proof-tests.js +447 -0
  64. package/dist/scripts/booking-copilot-runtime-proof-tests.js +205 -0
  65. package/dist/scripts/booking-copilot-server-proof-tests.js +317 -0
  66. package/dist/scripts/booking-copilot-startup-proof-tests.js +283 -0
  67. package/dist/scripts/booking-copilot-v2-runtime-proof-tests.js +3935 -0
  68. package/dist/scripts/booking-saga-tests.js +1 -1
  69. package/dist/scripts/booking-surface-contract-proof-tests.js +393 -0
  70. package/dist/scripts/booking-surface-v2-contract-proof-tests.js +1174 -0
  71. package/dist/scripts/bootstrap-tests.js +45 -39
  72. package/dist/scripts/build-changelog.js +1 -1
  73. package/dist/scripts/changelog-tests.js +1 -1
  74. package/dist/scripts/companion-tests.js +1 -1
  75. package/dist/scripts/diff-test.js +1 -1
  76. package/dist/scripts/dsh-runtime-closure-tests.js +225 -0
  77. package/dist/scripts/dsh-runtime-closure.js +150 -0
  78. package/dist/scripts/effect-tests.js +1 -1
  79. package/dist/scripts/engine-run.js +1 -1
  80. package/dist/scripts/engine-tests.js +1 -1
  81. package/dist/scripts/evaluation-cadence-tests.js +347 -0
  82. package/dist/scripts/evaluation-contract-tests.js +574 -0
  83. package/dist/scripts/extension-distribution-cli.js +35 -0
  84. package/dist/scripts/extension-distribution-tests.js +341 -0
  85. package/dist/scripts/extension-tests.js +128 -23
  86. package/dist/scripts/fact-gate-tests.js +1 -1
  87. package/dist/scripts/flyai-tests.js +1 -1
  88. package/dist/scripts/hbcli-e2e-tests.js +1 -1
  89. package/dist/scripts/hbcli-tests.js +1 -1
  90. package/dist/scripts/health-watch-cli.js +1 -1
  91. package/dist/scripts/i18n-tests.js +1 -1
  92. package/dist/scripts/incident-tests.js +1 -1
  93. package/dist/scripts/journey-tests.js +1 -1
  94. package/dist/scripts/ledger-tests.js +1 -1
  95. package/dist/scripts/ledger-workflow-crash.js +1 -1
  96. package/dist/scripts/memory-capture-tests.js +1 -1
  97. package/dist/scripts/memory-decay-tests.js +1 -1
  98. package/dist/scripts/memory-metrics.js +1 -1
  99. package/dist/scripts/memory-value-report.js +1 -1
  100. package/dist/scripts/model-override-e2e.js +176 -0
  101. package/dist/scripts/nightly-evidence-tests.js +1 -1
  102. package/dist/scripts/nightly-evidence.js +1 -1
  103. package/dist/scripts/nudge-digest.js +1 -1
  104. package/dist/scripts/onboarding-tests.js +21 -53
  105. package/dist/scripts/opensky-check.js +1 -1
  106. package/dist/scripts/opensky-tests.js +1 -1
  107. package/dist/scripts/pnpm-dsh-closure-proof.js +20 -0
  108. package/dist/scripts/price-drift-tests.js +1 -1
  109. package/dist/scripts/price-drift-watch.js +1 -1
  110. package/dist/scripts/probe-poi-tests.js +1 -1
  111. package/dist/scripts/product-metrics.js +1 -1
  112. package/dist/scripts/publish-preverify.js +40 -4
  113. package/dist/scripts/realtime-pricing-tests.js +1 -1
  114. package/dist/scripts/replay-async.js +1 -1
  115. package/dist/scripts/replay-real.js +1 -1
  116. package/dist/scripts/replay.js +1 -1
  117. package/dist/scripts/session-attach-diagnose.js +1 -1
  118. package/dist/scripts/session-attach-poc.js +1 -1
  119. package/dist/scripts/session-benchmark.js +1 -1
  120. package/dist/scripts/session-extract-tests.js +1 -1
  121. package/dist/scripts/session-login.js +1 -1
  122. package/dist/scripts/session-tests.js +70 -20
  123. package/dist/scripts/sf-live-benchmark.js +338 -0
  124. package/dist/scripts/sf-live-cli-tests.js +21 -0
  125. package/dist/scripts/sf-soft-score-tests.js +108 -0
  126. package/dist/scripts/sf-summary.js +93 -0
  127. package/dist/scripts/skeleton-check.js +1 -1
  128. package/dist/scripts/skeleton-integration-test.js +1 -1
  129. package/dist/scripts/skills-contract-tests.js +1 -1
  130. package/dist/scripts/smoke-session-gate-tests.js +29 -0
  131. package/dist/scripts/smoke.js +79 -33
  132. package/dist/scripts/state-cli-tests.js +1 -1
  133. package/dist/scripts/state-cli.js +1 -1
  134. package/dist/scripts/static-golden-tests.js +299 -0
  135. package/dist/scripts/time-eval-tests.js +1 -1
  136. package/dist/scripts/travel-timeline-tests.js +1 -1
  137. package/dist/scripts/unified-tests.js +1 -1
  138. package/dist/scripts/weather-tests.js +694 -44
  139. package/dist/scripts/z3-race-tests.js +1 -1
  140. package/dist/src/artifact-gate.js +1 -1
  141. package/dist/src/benchmark-agent-conformance.js +370 -0
  142. package/dist/src/benchmark-environment-bridge.js +384 -0
  143. package/dist/src/benchmark-headless-child-diagnostics.js +173 -0
  144. package/dist/src/benchmark-tool-isolation.js +124 -0
  145. package/dist/src/bookable-facts.js +1 -1
  146. package/dist/src/booking-saga.js +1 -1
  147. package/dist/src/booking-surface/availability-policy-v2.js +830 -0
  148. package/dist/src/booking-surface/canonical-schema.js +113 -0
  149. package/dist/src/booking-surface/contracts-v2.js +89 -0
  150. package/dist/src/booking-surface/contracts.js +46 -0
  151. package/dist/src/booking-surface/dsh-planner.js +453 -0
  152. package/dist/src/booking-surface/dsh-plugin.js +93 -0
  153. package/dist/src/booking-surface/error-codes.js +94 -0
  154. package/dist/src/booking-surface/index.js +15 -0
  155. package/dist/src/booking-surface/profile.js +68 -0
  156. package/dist/src/booking-surface/runtime-v2.js +1771 -0
  157. package/dist/src/booking-surface/runtime.js +351 -0
  158. package/dist/src/booking-surface/server-v2.js +334 -0
  159. package/dist/src/booking-surface/server.js +302 -0
  160. package/dist/src/booking-surface/startup.js +159 -0
  161. package/dist/src/booking-surface/validation-v2.js +319 -0
  162. package/dist/src/booking-surface/validation.js +809 -0
  163. package/dist/src/bridge.js +1 -1
  164. package/dist/src/companions.js +1 -1
  165. package/dist/src/contracts.js +1 -1
  166. package/dist/src/dsh-llm.js +1 -1
  167. package/dist/src/engine.js +1 -1
  168. package/dist/src/evaluation-cadence.js +234 -0
  169. package/dist/src/evaluation-contracts.js +906 -0
  170. package/dist/src/i18n.js +1 -1
  171. package/dist/src/index.js +50 -19
  172. package/dist/src/journey.js +1 -1
  173. package/dist/src/loop.js +1 -1
  174. package/dist/src/memory-capture.js +1 -1
  175. package/dist/src/memory-decay.js +1 -1
  176. package/dist/src/memory-utility.js +1 -1
  177. package/dist/src/mock-llm.js +1 -1
  178. package/dist/src/model.js +1 -1
  179. package/dist/src/realtime-pricing.js +1 -1
  180. package/dist/src/slot-spec.js +1 -1
  181. package/dist/src/state-ledger.js +2 -1
  182. package/dist/src/time-anchor.js +1 -1
  183. package/dist/src/tool-budget.js +136 -0
  184. package/dist/src/tool-packet.js +1 -1
  185. package/dist/src/travel-slots.js +1 -1
  186. package/dist/src/travel-timeline.js +1 -1
  187. package/dist/src/unified.js +1 -1
  188. package/dist/src/wish-pool.js +1 -1
  189. package/dist/src/z3-shared.js +1 -1
  190. package/extension/README.md +31 -7
  191. package/package.json +286 -11
  192. package/schemas/booking.surface.v1.schema.json +927 -0
  193. package/schemas/booking.surface.v2.schema.json +61 -0
  194. package/ts/capabilities/flyai.ts +16 -3
  195. package/ts/capabilities/session/extension-bridge.ts +37 -14
  196. package/ts/capabilities/session/extension-channel.ts +6 -3
  197. package/ts/capabilities/session/extension-distribution.ts +264 -0
  198. package/ts/capabilities/session/golden-score.ts +139 -0
  199. package/ts/capabilities/session/health-watch.ts +1 -1
  200. package/ts/capabilities/session/static-flight-golden.ts +209 -0
  201. package/ts/capabilities/session/wizard.ts +34 -176
  202. package/ts/capabilities/session-login.ts +15 -5
  203. package/ts/capabilities/session-search.ts +40 -3
  204. package/ts/capabilities/weather.ts +141 -52
  205. package/ts/package.json +3 -3
  206. package/ts/src/benchmark-agent-conformance.ts +448 -0
  207. package/ts/src/benchmark-environment-bridge.ts +348 -0
  208. package/ts/src/benchmark-headless-child-diagnostics.ts +184 -0
  209. package/ts/src/benchmark-tool-isolation.ts +166 -0
  210. package/ts/src/booking-surface/availability-policy-v2.ts +523 -0
  211. package/ts/src/booking-surface/canonical-schema.js +113 -0
  212. package/ts/src/booking-surface/contracts-v2.ts +118 -0
  213. package/ts/src/booking-surface/contracts.ts +380 -0
  214. package/ts/src/booking-surface/dsh-planner.ts +452 -0
  215. package/ts/src/booking-surface/dsh-plugin.js +93 -0
  216. package/ts/src/booking-surface/error-codes.ts +101 -0
  217. package/ts/src/booking-surface/index.ts +12 -0
  218. package/ts/src/booking-surface/profile.ts +42 -0
  219. package/ts/src/booking-surface/runtime-v2.ts +1466 -0
  220. package/ts/src/booking-surface/runtime.ts +483 -0
  221. package/ts/src/booking-surface/server-v2.ts +247 -0
  222. package/ts/src/booking-surface/server.ts +324 -0
  223. package/ts/src/booking-surface/startup.ts +196 -0
  224. package/ts/src/booking-surface/validation-v2.ts +205 -0
  225. package/ts/src/booking-surface/validation.ts +453 -0
  226. package/ts/src/index.ts +64 -11
  227. package/ts/src/state-ledger.ts +1 -0
  228. package/ts/src/tool-budget.ts +165 -0
  229. package/dist/scripts/wizard-bootstrap.js +0 -32
@@ -0,0 +1,319 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { Ajv2020 } from 'ajv/dist/2020.js';
3
+ import { BOOKING_READ_ACTION_KINDS_V2, BOOKING_V2_BLOCKER_CODES, BOOKING_V2_GAP_CODES } from './contracts-v2.js';
4
+ const schema = JSON.parse(readFileSync(new URL('../../../schemas/booking.surface.v2.schema.json', import.meta.url), 'utf8'));
5
+ const v1 = JSON.parse(readFileSync(new URL('../../../schemas/booking.surface.v1.schema.json', import.meta.url), 'utf8'));
6
+ const ajv = new Ajv2020({
7
+ allErrors: true,
8
+ strict: true
9
+ });
10
+ ajv.addSchema(v1);
11
+ ajv.addSchema(schema);
12
+ const validate = ajv.compile(schema);
13
+ const validateActionCanonical = ajv.compile({
14
+ $ref: `${schema.$id}#/$defs/Action`
15
+ });
16
+ const validateBlockerCanonical = ajv.compile({
17
+ $ref: `${schema.$id}#/$defs/Blocker`
18
+ });
19
+ const validateApprovalCanonical = ajv.compile({
20
+ $ref: `${schema.$id}#/$defs/Approval`
21
+ });
22
+ const validateEventCanonical = ajv.compile({
23
+ $ref: `${schema.$id}#/$defs/Event`
24
+ });
25
+ const kinds = new Set(BOOKING_READ_ACTION_KINDS_V2);
26
+ const codes = new Set(BOOKING_V2_BLOCKER_CODES);
27
+ const gapCodes = new Set(BOOKING_V2_GAP_CODES);
28
+ const safeOpaque = (value)=>typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9:._-]*$/.test(value);
29
+ const safeRequestKey = (value)=>typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9:._-]{7,127}$/.test(value) && !secret.test(value);
30
+ 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;
31
+ const technicalEmail = /^(?:schema|version)@[a-z0-9-]+\.example$/i;
32
+ const currencyAmount = /\b(?:[A-Z]{3}\s*\d+(?:\.\d+)?|\d+(?:\.\d+)?\s*[A-Z]{3})\b/;
33
+ const rfc3339DateTime = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|([+-])(\d{2}):(\d{2}))$/;
34
+ export function isBookingDateTimeV2(value) {
35
+ if (typeof value !== 'string') return false;
36
+ const match = rfc3339DateTime.exec(value);
37
+ if (!match) return false;
38
+ const [, yearText, monthText, dayText, hourText, minuteText, secondText] = match;
39
+ const year = Number(yearText);
40
+ const month = Number(monthText);
41
+ const day = Number(dayText);
42
+ const hour = Number(hourText);
43
+ const minute = Number(minuteText);
44
+ const second = Number(secondText);
45
+ const offsetHour = match[9] === undefined ? 0 : Number(match[9]);
46
+ const offsetMinute = match[10] === undefined ? 0 : Number(match[10]);
47
+ if (month < 1 || month > 12 || hour > 23 || minute > 59 || second > 59 || offsetHour > 23 || offsetMinute > 59) return false;
48
+ const daysInMonth = new Date(Date.UTC(year, month, 0)).getUTCDate();
49
+ if (day < 1 || day > daysInMonth) return false;
50
+ return !Number.isNaN(Date.parse(value));
51
+ }
52
+ function normalizedWords(value) {
53
+ return value.normalize('NFKC').replace(/[^\p{L}\p{N}.]+/gu, ' ').trim();
54
+ }
55
+ function hasSupplierCost(value) {
56
+ const normalized = normalizedWords(value);
57
+ const lower = normalized.toLowerCase();
58
+ return /\b(?:supplier|vendor|internal)\b/.test(lower) && /\b(?:cost|rate|price)\b/.test(lower) && currencyAmount.test(normalized.toUpperCase());
59
+ }
60
+ function hasInternationalPhone(value) {
61
+ const normalized = value.normalize('NFKC');
62
+ for (const plusIndex of normalized.split('').flatMap((char, index)=>char === '+' ? [
63
+ index
64
+ ] : [])){
65
+ let digits = '';
66
+ for (const char of normalized.slice(plusIndex + 1, plusIndex + 48)){
67
+ if (/\d/u.test(char)) digits += char;
68
+ else if (/\p{L}|@/u.test(char)) break;
69
+ if (digits.length > 15) break;
70
+ }
71
+ if (/^[1-9]\d{7,14}$/.test(digits)) return true;
72
+ }
73
+ return false;
74
+ }
75
+ function hasPaymentCard(value) {
76
+ const normalized = value.normalize('NFKC');
77
+ const candidates = normalized.match(/(?:\d[ -]?){12,18}\d/g) ?? [];
78
+ const explicitlyLabeled = /\b(?:card|payment|visa|mastercard)\b/i.test(normalized);
79
+ return candidates.some((candidate)=>(explicitlyLabeled || /[ -]/.test(candidate)) && luhn(candidate));
80
+ }
81
+ function hasSensitiveText(value, opts = {}) {
82
+ const normalized = value.normalize('NFKC');
83
+ if (normalized.includes('@') && !technicalEmail.test(normalized.trim())) return true;
84
+ return secret.test(normalized) || hasInternationalPhone(normalized) || hasSupplierCost(normalized) || !opts.allowOpaqueNumericId && hasPaymentCard(normalized);
85
+ }
86
+ function luhn(value) {
87
+ const digits = value.replaceAll(/\D/g, '');
88
+ if (digits.length < 13 || digits.length > 19) return false;
89
+ let sum = 0;
90
+ for(let i = digits.length - 1, parity = 0; i >= 0; i--, parity++){
91
+ let n = Number(digits[i]);
92
+ if (parity % 2 === 1) {
93
+ n *= 2;
94
+ if (n > 9) n -= 9;
95
+ }
96
+ sum += n;
97
+ }
98
+ return sum % 10 === 0;
99
+ }
100
+ const opaqueFieldNames = new Set([
101
+ 'eventId',
102
+ 'taskId',
103
+ 'contextRef',
104
+ 'actionId',
105
+ 'hotelRef',
106
+ 'offerRef',
107
+ 'offerVersionRef',
108
+ 'checkedOfferVersionRef',
109
+ 'currentOfferVersionRef',
110
+ 'verifiedOfferRef',
111
+ 'orderRef',
112
+ 'searchSessionRef',
113
+ 'handoffRef',
114
+ 'questionId',
115
+ 'blockerId',
116
+ 'approvalId',
117
+ 'sourceActionId',
118
+ 'targetActionId',
119
+ 'sourceTurnId',
120
+ 'turnId',
121
+ 'requestKey',
122
+ 'taskHandle',
123
+ 'nonce',
124
+ 'deliveryNonce',
125
+ 'optionDigest',
126
+ 'sourceReceiptDigest',
127
+ 'valueDigest'
128
+ ]);
129
+ function isOpaqueFieldPath(path) {
130
+ const clean = path.replace(/\[\]$/g, '');
131
+ const field = clean.split('.').at(-1);
132
+ return field ? opaqueFieldNames.has(field) || field.endsWith('Ref') || field.endsWith('Refs') : false;
133
+ }
134
+ const scan = (v, path = '$')=>typeof v === 'string' ? hasSensitiveText(v, {
135
+ allowOpaqueNumericId: isOpaqueFieldPath(path)
136
+ }) : Array.isArray(v) ? v.some((child)=>scan(child, `${path}[]`)) : !!v && typeof v === 'object' ? Object.entries(v).some(([k, x])=>/cost|price/i.test(k) ? /supplier|internal|wholesale/i.test(String(x)) : scan(x, `${path}.${k}`)) : false;
137
+ export function isSafeBookingRequestKeyV2(value) {
138
+ return safeRequestKey(value);
139
+ }
140
+ function errors(v) {
141
+ return (v.errors ?? []).map((e)=>`${e.instancePath || '$'}: ${e.message ?? e.keyword}`);
142
+ }
143
+ function workspaceErrors(workspace, path) {
144
+ const e = [];
145
+ if (!workspace || typeof workspace !== 'object' || Array.isArray(workspace)) return e;
146
+ const loadedOffers = Array.isArray(workspace.loadedOffers) ? workspace.loadedOffers : [];
147
+ const offerRefs = loadedOffers.map((offer)=>offer?.offerRef).filter((ref)=>typeof ref === 'string');
148
+ const offerVersionRefs = loadedOffers.map((offer)=>offer?.offerVersionRef).filter((ref)=>typeof ref === 'string');
149
+ if (new Set(offerRefs).size !== offerRefs.length) e.push(`${path}.loadedOffers: duplicate offerRef`);
150
+ if (new Set(offerVersionRefs).size !== offerVersionRefs.length) e.push(`${path}.loadedOffers: duplicate offerVersionRef`);
151
+ const verified = workspace.verifiedOffer;
152
+ if (verified !== undefined) {
153
+ if (!loadedOffers.some((offer)=>offer?.offerRef === verified.offerRef && offer?.offerVersionRef === verified.offerVersionRef)) e.push(`${path}.verifiedOffer: loaded offer version required`);
154
+ if (!safeOpaque(verified.verifiedOfferRef) || !isBookingDateTimeV2(verified.expiresAt)) e.push(`${path}.verifiedOffer: safe ref and parseable expiry required`);
155
+ }
156
+ return e;
157
+ }
158
+ function cross(value) {
159
+ const e = [];
160
+ if (scan(value)) e.push('$: unsafe PII/payment/supplier-cost/credential text');
161
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return e;
162
+ const x = value;
163
+ const semantic = x.kind === 'action.receipt.continuation' ? x.receipt : x;
164
+ if (x.workspace && x.kind !== 'user.turn.ingress') e.push(...workspaceErrors(x.workspace, '$.workspace'));
165
+ if (x.schemaVersion === 'booking.surface.v2' && Array.isArray(x.loadedOffers)) e.push(...workspaceErrors(x, '$'));
166
+ if (x.kind === 'user.turn.ingress') {
167
+ if (!safeRequestKey(x.requestKey)) e.push('$.requestKey: safe opaque request key required');
168
+ const workspace = x.workspace;
169
+ e.push(...workspaceErrors(workspace, '$.workspace'));
170
+ const visibleHotels = Array.isArray(workspace?.visibleHotels) ? workspace.visibleHotels : [];
171
+ const loadedOffers = Array.isArray(workspace?.loadedOffers) ? workspace.loadedOffers : [];
172
+ if (workspace?.focusedHotelRef !== undefined && !visibleHotels.some((hotel)=>hotel?.hotelRef === workspace.focusedHotelRef)) e.push('$.workspace.focusedHotelRef: visible hotel required');
173
+ const selectedOffer = workspace?.selectedOfferRef === undefined ? undefined : loadedOffers.find((offer)=>offer?.offerRef === workspace.selectedOfferRef);
174
+ if (workspace?.selectedOfferRef !== undefined && !selectedOffer) e.push('$.workspace.selectedOfferRef: loaded offer required');
175
+ if (selectedOffer && !visibleHotels.some((hotel)=>hotel?.hotelRef === selectedOffer.hotelRef)) e.push('$.workspace.selectedOfferRef: offer hotel must be visible');
176
+ }
177
+ if (semantic !== x && semantic?.resultContract?.hardCriteriaMet === true && semantic.resultContract.blockers?.length) e.push('$.receipt.resultContract: hardCriteriaMet cannot coexist with blockers');
178
+ if (kinds.has(x.kind)) {
179
+ const allowed = {
180
+ 'search.patch': [
181
+ 'patch'
182
+ ],
183
+ 'search.run': [],
184
+ 'results.view.patch': [
185
+ 'patch'
186
+ ],
187
+ 'hotel.focus': [
188
+ 'hotelRef'
189
+ ],
190
+ 'hotel.select': [
191
+ 'hotelRef'
192
+ ],
193
+ 'offers.query': [
194
+ 'hotelRefs',
195
+ 'criteria'
196
+ ],
197
+ 'offers.view.patch': [
198
+ 'hotelRef',
199
+ 'criteria'
200
+ ],
201
+ 'offers.compare': [
202
+ 'offerRefs',
203
+ 'requestedCount'
204
+ ],
205
+ 'offer.select': [
206
+ 'offerRef',
207
+ 'offerVersionRef'
208
+ ],
209
+ 'offer.check': [
210
+ 'offerRef',
211
+ 'offerVersionRef'
212
+ ],
213
+ 'checkout.prepare': [
214
+ 'offerRef',
215
+ 'offerVersionRef',
216
+ 'verifiedOfferRef'
217
+ ],
218
+ 'order.observe': [
219
+ 'orderRef'
220
+ ]
221
+ };
222
+ const input = x.input;
223
+ if (!input || typeof input !== 'object' || Array.isArray(input) || Object.keys(input).some((k)=>!allowed[x.kind].includes(k))) e.push('$.input: closed kind-specific input required');
224
+ }
225
+ if (x.kind === 'action.receipt' && x.resultContract?.hardCriteriaMet === true && x.resultContract.blockers?.length) e.push('$.resultContract: hardCriteriaMet cannot coexist with blockers');
226
+ if (x.kind === 'user.turn' && Array.isArray(x.request?.approval)) e.push('$.request.approval: at most one approval');
227
+ if (x.kind === 'action.receipt' || x.kind === 'action.receipt.continuation') {
228
+ const r = x.kind === 'action.receipt.continuation' ? x.receipt : x;
229
+ if (r?.resultContract?.gapCodes?.some((code)=>!gapCodes.has(String(code)))) e.push('$.resultContract.gapCodes: unregistered gap code');
230
+ const observation = r?.observation;
231
+ if (observation?.kind === 'offer.availability') {
232
+ if (r.status === 'applied' && (observation.available !== true || !observation.verifiedOfferRef || observation.currentOfferVersionRef !== observation.checkedOfferVersionRef || observation.changedFactRefs?.length || observation.gapCodes?.length)) e.push('$.observation: applied availability requires unchanged checked/current version, verified ref, and no gaps');
233
+ if (r.status === 'applied' && (r.resultContract?.outcome !== 'complete' || r.resultContract?.hardCriteriaMet !== true || r.resultContract?.gapCodes?.length || r.resultContract?.blockers?.length)) e.push('$.resultContract: applied availability requires complete hard-criteria result without gaps or blockers');
234
+ if (r.status === 'changed' && (observation.available !== true || !observation.currentOfferVersionRef || observation.currentOfferVersionRef === observation.checkedOfferVersionRef || !observation.changedFactRefs?.length || observation.verifiedOfferRef)) e.push('$.observation: changed availability requires available replacement current version without verified ref');
235
+ if ((r.status === 'unavailable' || r.status === 'no_match') && (observation.available !== false || observation.currentOfferVersionRef || observation.verifiedOfferRef)) e.push('$.observation: negative availability must not expose current or verified version');
236
+ if (r.status !== 'applied' && observation.verifiedOfferRef) e.push('$.observation: only applied availability may expose verified ref');
237
+ }
238
+ }
239
+ const blocker = x.blocker ?? x.question?.blocker;
240
+ if (blocker && !/^(searchDraft|results|offers|checkout)(\.[A-Za-z][A-Za-z0-9_]*){0,3}$/.test(blocker.criterionPath ?? '')) e.push('$.blocker.criterionPath: closed criterion path required');
241
+ if (blocker?.evidence?.factRefs && new Set(blocker.evidence.factRefs).size !== blocker.evidence.factRefs.length) e.push('$.blocker.evidence.factRefs: unique refs required');
242
+ if (x.kind === 'question' && blocker && Array.isArray(x.question?.approvalOptions)) {
243
+ for (const [i, option] of x.question.approvalOptions.entries()){
244
+ const result = validateApprovalAgainstBlocker(option?.approval, blocker);
245
+ if (!result.ok) e.push(...result.errors.map((error)=>`$.question.approvalOptions[${i}].${error.slice(2)}`));
246
+ }
247
+ }
248
+ if (kinds.has(String(x.kind)) && x.relaxationApprovalRef) {
249
+ const ref = x.relaxationApprovalRef;
250
+ if (ref.contextRef !== x.contextRef) e.push('$.relaxationApprovalRef.contextRef: must match action');
251
+ if (ref.sourceRevision !== x.expectedRevision) e.push('$.relaxationApprovalRef.sourceRevision: must equal action revision');
252
+ if (ref.targetActionKind !== x.kind) e.push('$.relaxationApprovalRef.targetActionKind: must match action kind');
253
+ if (ref.targetActionId !== x.actionId) e.push('$.relaxationApprovalRef.targetActionId: must match action id');
254
+ if (!safeOpaque(ref.nonce) || !isBookingDateTimeV2(ref.expiresAt)) e.push('$.relaxationApprovalRef: invalid expiry or nonce');
255
+ }
256
+ if (x.kind === 'question' && (!Array.isArray(x.question?.approvalOptions) || x.question.approvalOptions.length < 1 || x.question.approvalOptions.length > 2)) e.push('$.question.approvalOptions: one or two options required');
257
+ return e;
258
+ }
259
+ export function validateBookingSurfaceV2(value) {
260
+ const ok = validate(value);
261
+ const e = ok ? [] : errors(validate);
262
+ e.push(...cross(value));
263
+ return e.length ? {
264
+ ok: false,
265
+ errors: e
266
+ } : {
267
+ ok: true
268
+ };
269
+ }
270
+ function fromCanonical(fn, value) {
271
+ const ok = fn(value);
272
+ const e = ok ? [] : errors(fn);
273
+ e.push(...cross(value));
274
+ return e.length ? {
275
+ ok: false,
276
+ errors: e
277
+ } : {
278
+ ok: true
279
+ };
280
+ }
281
+ export function validateBookingReadActionV2(value) {
282
+ return fromCanonical(validateActionCanonical, value);
283
+ }
284
+ export function validateCriterionBlockerV2(value) {
285
+ return fromCanonical(validateBlockerCanonical, value);
286
+ }
287
+ export function validateRelaxationApprovalV2(value) {
288
+ return fromCanonical(validateApprovalCanonical, value);
289
+ }
290
+ export function validateBookingSurfaceEventV2(value) {
291
+ return fromCanonical(validateEventCanonical, value);
292
+ }
293
+ export function validateApprovalAgainstBlocker(approval, blocker) {
294
+ const a = approval;
295
+ const b = blocker;
296
+ const blockerResult = validateCriterionBlockerV2(b);
297
+ if (!blockerResult.ok) return blockerResult;
298
+ const approvalResult = validateRelaxationApprovalV2(a);
299
+ if (!approvalResult.ok) return approvalResult;
300
+ const fields = [
301
+ 'blockerId',
302
+ 'sourceActionId',
303
+ 'sourceReceiptDigest',
304
+ 'scope',
305
+ 'code',
306
+ 'criterionPath',
307
+ 'valueDigest'
308
+ ];
309
+ const mismatches = fields.filter((field)=>a[field] !== b?.[field]);
310
+ return mismatches.length ? {
311
+ ok: false,
312
+ errors: mismatches.map((field)=>`$.${field}: approval does not match blocker`)
313
+ } : {
314
+ ok: true
315
+ };
316
+ }
317
+
318
+
319
+ //# sourceURL=ts/src/booking-surface/validation-v2.ts