@curless/hotel-storefront 0.62.0 → 0.63.1

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 (63) hide show
  1. package/dist/account/fake-ota.d.ts +9 -0
  2. package/dist/account/fake-ota.d.ts.map +1 -1
  3. package/dist/account/fake-ota.js +7 -2
  4. package/dist/account/fake-ota.js.map +1 -1
  5. package/dist/account/index.d.ts +28 -0
  6. package/dist/account/index.d.ts.map +1 -1
  7. package/dist/account/index.js +402 -2
  8. package/dist/account/index.js.map +1 -1
  9. package/dist/account/pages.d.ts +99 -0
  10. package/dist/account/pages.d.ts.map +1 -1
  11. package/dist/account/pages.js +228 -4
  12. package/dist/account/pages.js.map +1 -1
  13. package/dist/account/requests.d.ts +11 -1
  14. package/dist/account/requests.d.ts.map +1 -1
  15. package/dist/account/requests.js +2 -1
  16. package/dist/account/requests.js.map +1 -1
  17. package/dist/backend.d.ts +27 -0
  18. package/dist/backend.d.ts.map +1 -1
  19. package/dist/backend.js.map +1 -1
  20. package/dist/card.generated.d.ts +1 -1
  21. package/dist/card.generated.js +2 -2
  22. package/dist/card.generated.js.map +1 -1
  23. package/dist/config.d.ts +31 -0
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/config.js +10 -0
  26. package/dist/config.js.map +1 -1
  27. package/dist/legal.d.ts.map +1 -1
  28. package/dist/legal.js +34 -22
  29. package/dist/legal.js.map +1 -1
  30. package/dist/otaless/backend.d.ts +37 -1
  31. package/dist/otaless/backend.d.ts.map +1 -1
  32. package/dist/otaless/backend.js +40 -17
  33. package/dist/otaless/backend.js.map +1 -1
  34. package/dist/otaless/booking.d.ts +86 -5
  35. package/dist/otaless/booking.d.ts.map +1 -1
  36. package/dist/otaless/booking.js +230 -49
  37. package/dist/otaless/booking.js.map +1 -1
  38. package/dist/otaless/client.d.ts +20 -0
  39. package/dist/otaless/client.d.ts.map +1 -1
  40. package/dist/otaless/client.js +20 -3
  41. package/dist/otaless/client.js.map +1 -1
  42. package/dist/otaless/fake.d.ts +7 -0
  43. package/dist/otaless/fake.d.ts.map +1 -1
  44. package/dist/otaless/fake.js +3 -0
  45. package/dist/otaless/fake.js.map +1 -1
  46. package/dist/otaless/make.d.ts.map +1 -1
  47. package/dist/otaless/make.js +42 -5
  48. package/dist/otaless/make.js.map +1 -1
  49. package/dist/server.d.ts +2 -2
  50. package/dist/server.d.ts.map +1 -1
  51. package/dist/server.js +115 -3
  52. package/dist/server.js.map +1 -1
  53. package/dist/surface.d.ts +6 -0
  54. package/dist/surface.d.ts.map +1 -1
  55. package/dist/surface.js +73 -23
  56. package/dist/surface.js.map +1 -1
  57. package/dist/tools.d.ts +251 -52
  58. package/dist/tools.d.ts.map +1 -1
  59. package/dist/tools.js +974 -225
  60. package/dist/tools.js.map +1 -1
  61. package/dist/types.d.ts +32 -0
  62. package/dist/types.d.ts.map +1 -1
  63. package/package.json +1 -1
package/dist/tools.js CHANGED
@@ -146,6 +146,13 @@ export const withheldTools = (n, caps) => new Set([
146
146
  ...(caps.changes || caps.extras ? [] : [n.previewChange, n.changeBooking]),
147
147
  ...(caps.policies === false ? [n.policies] : []),
148
148
  ...(caps.unionpay ? [] : [n.payWithUnionPay]),
149
+ // The group's own checkout (Otaless 0.63.0): the card's agreement to its
150
+ // terms, a paid booking's refund, and the add-ons after a booking - each
151
+ // listed only where the backend says it has them, and never where nothing
152
+ // can be booked.
153
+ ...(caps.groupCheckout && !caps.readOnly ? [] : [n.acceptTerms]),
154
+ ...(caps.refunds && !caps.readOnly ? [] : [n.refundBooking]),
155
+ ...(caps.addons && !caps.readOnly ? [] : [n.listBookingAddons, n.addBookingAddon]),
149
156
  // Nothing can be booked here yet (`readOnly`, Otaless 2026-11-03): no tool
150
157
  // that books, finds, changes or cancels a booking - the card's own two
151
158
  // for Reserve included, so no button that books is drawn.
@@ -333,6 +340,15 @@ const forCapabilities = (tools, n, v, caps) => {
333
340
  }
334
341
  if (!caps.members)
335
342
  out = { ...out, inputSchema: without(out.inputSchema, 'rememberRequests') };
343
+ // ⚠️ THE GROUP'S OWN CHECKOUT (Otaless 0.63.0): a booking is an order with
344
+ // the group, which may first send its terms back for the GUEST to agree
345
+ // to, and is paid on the group's own page. One list for every client, so
346
+ // "the card or a one-time page" - never a card alone.
347
+ if (t.name === n.requestBooking && caps.groupCheckout)
348
+ out = {
349
+ ...out,
350
+ description: `Books the trip's rooms for a named guest through each hotel group's own checkout, one order per stay with the group that stay belongs to. The group may first send its booking terms back for the guest to read and agree to themselves - on the card or on a one-time page, not in the chat - and its payment page, with its host and the time to pay by, is then in the answer. A stay is booked once it is paid; the bookings list says when it has been. Preferences - a bed type, a floor, a late arrival - ride along on the booking as requests.`,
351
+ };
336
352
  // A market's suppliers book differently - its own description says so.
337
353
  if (t.name === n.requestBooking && caps.booking === 'pay-at-hotel' && !v.market) {
338
354
  out = {
@@ -1063,8 +1079,101 @@ const allTools = (n, v) => {
1063
1079
  required: ['name', 'email'],
1064
1080
  },
1065
1081
  },
1082
+ {
1083
+ // ⚠️ THE CARD'S, NEVER THE MODEL'S (`ui.visibility: ['app']`, server.ts),
1084
+ // AND NO PARAMETER HERE (OR ON ANY TOOL) MEANS "AGREED": the guest's
1085
+ // press on "Agree and continue" is the whole of the agreement, and
1086
+ // `ref` only says which terms the card was showing.
1087
+ name: n.acceptTerms,
1088
+ description: `The card's own step when the guest presses "Agree and continue" under a hotel group's booking terms: it sends the guest's agreement to the terms behind \`ref\` and the stay is then booked with the group. It answers like a booking: the group's payment page, the terms again, or why nothing was booked.`,
1089
+ annotations: books(`Agree to booking terms on ${v.brand}`, open),
1090
+ inputSchema: {
1091
+ type: 'object',
1092
+ properties: {
1093
+ ref: {
1094
+ type: 'string',
1095
+ description: 'The terms the card is showing, by the reference the booking answer gave',
1096
+ },
1097
+ },
1098
+ required: ['ref'],
1099
+ },
1100
+ },
1101
+ {
1102
+ name: n.refundBooking,
1103
+ description: "Asks the hotel group to refund, in full, a booking made here that has been paid. TWO STEPS: the first call (no `confirmed`) only previews - the amount and the group's own refund terms - and asks nothing of the group; say them to the guest, and only when they say yes call again with `confirmed: true`. The second answer says what the group did with the request.",
1104
+ annotations: cancels('Refund a booking', open),
1105
+ inputSchema: {
1106
+ type: 'object',
1107
+ properties: {
1108
+ booking: {
1109
+ type: 'string',
1110
+ description: 'The confirmation code or order id, as the booking answer gave it',
1111
+ },
1112
+ reason: {
1113
+ type: 'string',
1114
+ maxLength: REFUND_REASON_MAX,
1115
+ description: `Optional, the guest's reason in their own words, up to ${REFUND_REASON_MAX} characters`,
1116
+ },
1117
+ confirmed: {
1118
+ type: 'boolean',
1119
+ description: 'true only after the guest was shown the refund preview this tool answers with and said yes. Without it, the answer is that preview and nothing is asked of the group.',
1120
+ },
1121
+ },
1122
+ required: ['booking'],
1123
+ },
1124
+ },
1125
+ {
1126
+ name: n.listBookingAddons,
1127
+ description: 'What can be added to a booking made here after it was made - an airport transfer and the like - each with its id, name, price and the details it needs. Only a booking made here has any.',
1128
+ annotations: reads('Add-ons for a booking', open),
1129
+ inputSchema: {
1130
+ type: 'object',
1131
+ properties: {
1132
+ booking: {
1133
+ type: 'string',
1134
+ description: 'The confirmation code or order id, as the booking answer gave it',
1135
+ },
1136
+ },
1137
+ required: ['booking'],
1138
+ },
1139
+ },
1140
+ {
1141
+ name: n.addBookingAddon,
1142
+ description: "Adds one add-on to a booking made here, at the price the add-on list gave. It is meant for an add-on the guest chose, once its price has been said back to them. The answer gives the add-on order's code, status and total.",
1143
+ annotations: books('Add an add-on to a booking', open),
1144
+ inputSchema: {
1145
+ type: 'object',
1146
+ properties: {
1147
+ booking: {
1148
+ type: 'string',
1149
+ description: 'The confirmation code or order id, as the booking answer gave it',
1150
+ },
1151
+ addon: { type: 'string', description: 'The add-on id, as the add-on list gave it' },
1152
+ direction: {
1153
+ type: 'string',
1154
+ enum: ['arrival', 'departure', 'round_trip'],
1155
+ description: 'For a transfer: to the hotel, from it, or both',
1156
+ },
1157
+ flightNo: {
1158
+ type: 'string',
1159
+ description: 'For a transfer: the flight number, e.g. MU5101',
1160
+ },
1161
+ pickupTime: { type: 'string', description: 'For a transfer: the pick-up time, HH:MM' },
1162
+ date: { type: 'string', description: 'The date it is for, YYYY-MM-DD' },
1163
+ quantity: {
1164
+ type: 'integer',
1165
+ minimum: 1,
1166
+ maximum: 20,
1167
+ description: 'How many, 1 to 20. Default 1',
1168
+ },
1169
+ },
1170
+ required: ['booking', 'addon'],
1171
+ },
1172
+ },
1066
1173
  ];
1067
1174
  };
1175
+ /** A guest's reason for a refund, as the group's staff are sent it (`otaless/booking.ts`). */
1176
+ const REFUND_REASON_MAX = 200;
1068
1177
  // The shape of each tool's `structuredContent`, so a reader knows what it is
1069
1178
  // holding without inferring it from one example.
1070
1179
  //
@@ -1140,7 +1249,12 @@ const TRIP_SCHEMA = {
1140
1249
  const CANCEL_SCHEMA = {
1141
1250
  type: 'object',
1142
1251
  properties: {
1143
- view: { enum: ['cancellation-preview', 'cancelled', 'booking-not-found'] },
1252
+ view: { enum: ['cancellation-preview', 'cancelled', 'booking-not-found', 'error'] },
1253
+ /** The fee is not known before the group cancels: `rule` is its terms and no fee is said. */
1254
+ feeUnknown: BOOL,
1255
+ error: STR,
1256
+ detail: STR,
1257
+ groups: ARR,
1144
1258
  /** The coupon the booking used and whether cancelling gives it back. */
1145
1259
  coupon: OBJ,
1146
1260
  brand: STR,
@@ -1325,9 +1439,20 @@ const BOOKING_SCHEMA = {
1325
1439
  properties: {
1326
1440
  // `trip`: nothing was booked and the trip is shown again - its price
1327
1441
  // moved, or (in a market) it holds two groups' stays.
1328
- view: { enum: ['booking', 'needs-guest', 'empty-trip', 'error', 'trip'] },
1442
+ // `terms`: a group sent its booking terms back for the GUEST to agree to - the
1443
+ // stay is neither booked nor failed yet (`terms`, `termsSaid`).
1444
+ view: { enum: ['booking', 'needs-guest', 'empty-trip', 'error', 'trip', 'terms'] },
1329
1445
  /** `coupon`: nothing was booked because the coupon asked for cannot be used (`couponRefused`). */
1330
1446
  notBooked: STR,
1447
+ /** `terms`: the terms waiting for the guest, word for word (`termsOf`). */
1448
+ terms: ARR,
1449
+ /** `terms`: the sentence that says the guest agrees to them themselves, as the text says it. */
1450
+ termsSaid: STR,
1451
+ /** `error`: why, as a code (`BOOKING_REFUSALS` or 'card-only') and in the guest's words. */
1452
+ error: STR,
1453
+ detail: STR,
1454
+ /** A sign-in refusal: the groups the guest must sign in to, `{ code, name, names? }`. */
1455
+ groups: ARR,
1331
1456
  coupon: OBJ,
1332
1457
  couponRefused: OBJ,
1333
1458
  coupons: ARR,
@@ -1503,7 +1628,10 @@ export const buildOutputSchemas = (n) => ({
1503
1628
  [n.listBookings]: {
1504
1629
  type: 'object',
1505
1630
  properties: {
1506
- view: { const: 'bookings' },
1631
+ view: { enum: ['bookings', 'error'] },
1632
+ error: STR,
1633
+ detail: STR,
1634
+ groups: ARR,
1507
1635
  brand: STR,
1508
1636
  toolNames: OBJ,
1509
1637
  bookingMode: STR,
@@ -1516,6 +1644,65 @@ export const buildOutputSchemas = (n) => ({
1516
1644
  },
1517
1645
  [n.previewCancellation]: CANCEL_SCHEMA,
1518
1646
  [n.cancelBooking]: CANCEL_SCHEMA,
1647
+ // The group's own checkout (0.63.0): the card's agreement answers like a booking.
1648
+ [n.acceptTerms]: BOOKING_SCHEMA,
1649
+ [n.refundBooking]: {
1650
+ type: 'object',
1651
+ properties: {
1652
+ view: { enum: ['booking', 'booking-not-found', 'refund-preview', 'error'] },
1653
+ brand: STR,
1654
+ toolNames: OBJ,
1655
+ bookingMode: STR,
1656
+ demo: BOOL,
1657
+ booking: OBJ,
1658
+ total: STR,
1659
+ /** The refund preview: all that would be asked back, the group's terms, and until when the guest can say yes. */
1660
+ amount: STR,
1661
+ terms: STR,
1662
+ until: STR,
1663
+ /** The refund was asked for; the booking's `payment` says where it stands. */
1664
+ refundAsked: BOOL,
1665
+ query: STR,
1666
+ error: STR,
1667
+ detail: STR,
1668
+ groups: ARR,
1669
+ },
1670
+ required: ['view'],
1671
+ },
1672
+ [n.listBookingAddons]: {
1673
+ type: 'object',
1674
+ properties: {
1675
+ view: { enum: ['booking-addons', 'booking-not-found', 'error'] },
1676
+ brand: STR,
1677
+ toolNames: OBJ,
1678
+ bookingMode: STR,
1679
+ demo: BOOL,
1680
+ booking: STR,
1681
+ addons: ARR,
1682
+ query: STR,
1683
+ error: STR,
1684
+ detail: STR,
1685
+ groups: ARR,
1686
+ },
1687
+ required: ['view'],
1688
+ },
1689
+ [n.addBookingAddon]: {
1690
+ type: 'object',
1691
+ properties: {
1692
+ view: { enum: ['booking-addon', 'booking-not-found', 'error'] },
1693
+ brand: STR,
1694
+ toolNames: OBJ,
1695
+ bookingMode: STR,
1696
+ demo: BOOL,
1697
+ booking: STR,
1698
+ addon: OBJ,
1699
+ query: STR,
1700
+ error: STR,
1701
+ detail: STR,
1702
+ groups: ARR,
1703
+ },
1704
+ required: ['view'],
1705
+ },
1519
1706
  [n.previewChange]: CHANGE_SCHEMA,
1520
1707
  [n.changeBooking]: CHANGE_SCHEMA,
1521
1708
  [n.compare]: {
@@ -1733,6 +1920,12 @@ const partyOnTrip = (deps, key, hotelId, args) => {
1733
1920
  * membership number on every call is carrying it further than it has to go.
1734
1921
  */
1735
1922
  const memberBadge = (deps, key) => {
1923
+ // ⚠️ NOTHING WHERE THERE IS NO MEMBERSHIP SIGN-IN (0.63.0): Otaless has none
1924
+ // (\`capabilities.members\`), and \`signedIn: false\` beside a booking made with the
1925
+ // guest's Otaless account was read by the model as "you are not signed in" -
1926
+ // twice in one eval run. The account's own sign-in is said by the account.
1927
+ if (!(deps.backend.capabilities ?? FULL_CAPABILITIES).members)
1928
+ return {};
1736
1929
  const m = deps.members.read(key);
1737
1930
  // ⚠️ `signedIn` ON EVERY ANSWER, false included. The card cleared its tier
1738
1931
  // chip only on the sign-out view, so after signing out in the chat - or a
@@ -1897,6 +2090,11 @@ const bookingForCard = (b) => ({
1897
2090
  ? {
1898
2091
  payment: {
1899
2092
  ...b.payment,
2093
+ // ⚠️ WHERE THE GUEST IS SENT AND BY WHEN, in words (Otaless 0.63.0, all
2094
+ // brands): the host of the payment page, and the pay-by moment with its
2095
+ // offset - never a bare ISO string. The card and the model read the same.
2096
+ ...(hostOf(b.payment.url) ? { host: hostOf(b.payment.url) } : {}),
2097
+ ...(payByWords(b.payment) ? { payByWords: payByWords(b.payment) } : {}),
1900
2098
  amount: formatMoney(b.payment.amount),
1901
2099
  // What goes back, where it is not the whole amount, as text too - the
1902
2100
  // cancelled page says "¥1,601 of the ¥3,202 paid" from it (robin,
@@ -1992,7 +2190,7 @@ const paidLine = (deps, b, fee) => {
1992
2190
  ? `Once UnionPay issues its one-time card, the booking is made here - it is not sent to ${h.name}`
1993
2191
  : `Once UnionPay issues its one-time card, the stay is booked with ${h.name}, who charges that card`}; not confirmed by then, nothing is booked or charged.`
1994
2192
  : p.url
1995
- ? `**Not booked yet.** ${amount} is to be paid on the card page by ${p.payByLocal ?? p.payBy} hotel time: ${p.url}. ${
2193
+ ? `**Not booked yet.** ${amount} is to be paid on ${hostOf(p.url) ?? 'the card page'}${payByWords(p) ? ` by ${payByWords(p)}${p.payByLocal ? ' hotel time' : ''}` : ''}: ${p.url}. ${
1996
2194
  // ⚠️ NOT "BOOKED WITH" A GROUP IT IS NEVER SENT TO (0.55.7, 总线程 11-05).
1997
2195
  h.notReal
1998
2196
  ? `Once it is paid the booking is made here - it is not sent to ${h.name} - and ${deps.tools.listBookings} shows it`
@@ -3273,6 +3471,214 @@ const listedForCard = (deps, b) => {
3273
3471
  const said = notSentStatus(deps, b);
3274
3472
  return { ...bookingForCard(b), ...(said ? { statusSaid: said } : {}) };
3275
3473
  };
3474
+ /**
3475
+ * The host a payment page is on - what a guest checks before they pay - or
3476
+ * nothing when the address is not one.
3477
+ */
3478
+ const hostOf = (url) => {
3479
+ if (!url)
3480
+ return undefined;
3481
+ try {
3482
+ return new URL(url).host || undefined;
3483
+ }
3484
+ catch {
3485
+ return undefined;
3486
+ }
3487
+ };
3488
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
3489
+ /**
3490
+ * A moment as a clock time with its offset - "17:30 UTC+08:00, 10 Nov" - never
3491
+ * a bare ISO string. Read from the string itself: its own offset when it has
3492
+ * one, else UTC, since no hotel record here carries a time zone. Undefined for
3493
+ * anything that is not an ISO moment.
3494
+ */
3495
+ export const clockWords = (iso) => {
3496
+ const m = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2})(?::\d{2}(?:\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?$/.exec(iso ?? '');
3497
+ if (!m)
3498
+ return undefined;
3499
+ const [, , mo, d, hh, mm, zone] = m;
3500
+ const offset = !zone || zone === 'Z'
3501
+ ? 'UTC'
3502
+ : `UTC${zone.slice(0, 3)}:${zone.length === 6 ? zone.slice(4) : zone.slice(3)}`;
3503
+ return `${hh}:${mm} ${offset}, ${Number(d)} ${MONTHS[Number(mo) - 1] ?? mo}`;
3504
+ };
3505
+ /** When a payment page is paid by: the hotel's own clock where the backend gave it, else the moment with its offset. */
3506
+ const payByWords = (p) => p.payByLocal ?? clockWords(p.payBy);
3507
+ /**
3508
+ * The refusals `otaless/booking.ts` raises with a `code` (docs §13.5): each is
3509
+ * answered as `view: 'error'` with the code itself, never as the generic
3510
+ * 'not-bookable' / 'uncertain' - the card says each in its own words, and its
3511
+ * `detail` is already the guest's.
3512
+ */
3513
+ const BOOKING_REFUSALS = new Set([
3514
+ 'sign-in',
3515
+ 'signed-out',
3516
+ 'session-expired',
3517
+ 'guest',
3518
+ 'terms-gone',
3519
+ 'unconfirmed',
3520
+ 'not-cancelled',
3521
+ 'not-paid',
3522
+ 'not-refunded',
3523
+ 'refund-preview',
3524
+ 'refunded',
3525
+ 'cancel-unknown',
3526
+ 'addons-off',
3527
+ 'unknown-addon',
3528
+ 'addon',
3529
+ 'price-changed',
3530
+ ]);
3531
+ /** The three that mean "sign in at this group": they carry the groups (`groups`, provider codes). */
3532
+ const SIGN_IN_REFUSALS = new Set(['sign-in', 'signed-out', 'session-expired']);
3533
+ /**
3534
+ * The answer to a booking refusal, or undefined when `err` is not one.
3535
+ *
3536
+ * ⚠️ `groups` IS READ DEFENSIVELY: a refusal that carries none says nothing of
3537
+ * where to sign in. Per group: the account's link tool with that group's code
3538
+ * where the deployment has one (`ToolDeps.groupSignIn`), else its sign-in tool.
3539
+ */
3540
+ const refusalAnswer = (deps, key, err) => {
3541
+ const e = err;
3542
+ if (!(e instanceof Error) || typeof e.code !== 'string' || !BOOKING_REFUSALS.has(e.code))
3543
+ return undefined;
3544
+ const codes = SIGN_IN_REFUSALS.has(e.code) && Array.isArray(e.groups)
3545
+ ? [...new Set(e.groups.filter((g) => typeof g === 'string' && !!g))]
3546
+ : [];
3547
+ const suppliers = deps.backend.suppliers?.() ?? [];
3548
+ const groups = codes.map((code) => {
3549
+ const s = suppliers.find((x) => x.id === code);
3550
+ return { code, name: s?.name ?? code, ...(s?.names ? { names: s.names } : {}) };
3551
+ });
3552
+ const how = deps.groupSignIn;
3553
+ const signIn = groups
3554
+ .map((g) => how?.linkTool
3555
+ ? `To sign in at ${g.name}: ${how.linkTool} with group "${g.code}" gives the guest a one-time page for it.`
3556
+ : how?.signInTool
3557
+ ? `${how.signInTool} gives the guest a one-time page to sign in to their ${deps.vocab.brand} account.`
3558
+ : '')
3559
+ .filter((x, i, all) => !!x && all.indexOf(x) === i);
3560
+ // The guest's words for the refusals whose own message does not say enough
3561
+ // (总线程's review of 0.63.0): a cancellation the group did not confirm may
3562
+ // still stand - never "cancelled".
3563
+ const more = e.code === 'cancel-unknown'
3564
+ ? 'The group has not confirmed the cancellation, so the booking may still stand - nothing here has changed. Tell the guest to look at their bookings again in a few minutes.'
3565
+ : e.code === 'refund-preview'
3566
+ ? `Nothing was refunded. Show the guest the refund preview first (${deps.tools.refundBooking} without \`confirmed\`), then ask again once they say yes.`
3567
+ : e.code === 'addons-off'
3568
+ ? 'Add-ons are not offered here; tell the guest nothing can be added to the booking.'
3569
+ : '';
3570
+ return {
3571
+ structured: {
3572
+ view: 'error',
3573
+ ...common(deps, key),
3574
+ error: e.code,
3575
+ detail: more ? `${e.message} ${more}` : e.message,
3576
+ ...(groups.length ? { groups } : {}),
3577
+ },
3578
+ text: [e.message, more, ...signIn].filter(Boolean).join(' '),
3579
+ };
3580
+ };
3581
+ /**
3582
+ * The card's copy of the terms to agree to, beside the answer (`_meta`).
3583
+ *
3584
+ * ⚠️ THE TERMS' REF AND FULL TEXT ARE THE CARD'S, NEVER THE MODEL'S (总线程's
3585
+ * review of 0.63.0, binding): a group's terms are text a stranger wrote, and a
3586
+ * model that reads them can be talked into acting on them (prompt injection).
3587
+ * The model gets facts and the sentence `termsSaid`; the card gets this, in
3588
+ * `_meta` - and only a client that said it draws cards (`ToolContext.drawsCards`):
3589
+ * some hosts hand `_meta` to their model.
3590
+ */
3591
+ export const TERMS_META_KEY = 'curless/terms';
3592
+ /** The longest stretch of a group's refund terms put in the answer. */
3593
+ const TERMS_TEXT_MAX = 2_000;
3594
+ /**
3595
+ * Terms a group sent back, for the GUEST to agree to - as the structure and as
3596
+ * words, in the two kinds of host.
3597
+ *
3598
+ * ⚠️ THE MODEL CANNOT AGREE FOR THE GUEST, and no tool parameter means "agreed":
3599
+ * the card's button (`acceptTerms`, the card's own tool) or the one-time page
3600
+ * is the only way, and the words say so first. The text and the structure say
3601
+ * the same (`termsSaid`) - the model reads the structure. Neither carries the
3602
+ * terms' `ref` or their text: see `TERMS_META_KEY`.
3603
+ */
3604
+ const termsAnswer = (deps, ctx, key, terms) => {
3605
+ const t = deps.tools;
3606
+ // A client that draws no card, or that never said it does, is given the page.
3607
+ const onPage = !!ctx.noCards || !ctx.drawsCards;
3608
+ const groupNames = [...new Set(terms.map((x) => withZh(x.groupName, x.groupNames, ctx.noCards)))];
3609
+ const many = groupNames.length > 1;
3610
+ const where = onPage
3611
+ ? "on the one-time page linked below, which opens only in the browser signed in to the guest's account"
3612
+ : 'on the card, with its Agree button';
3613
+ const termsSaid = `Not booked yet: ${listAnd(groupNames)} ${many ? 'ask' : 'asks'} the guest to read and agree to ${many ? 'their' : 'its'} booking terms themselves, ${where}. Nothing is ordered until they do. You cannot agree for them, and do not ask them to say they agree in the chat.`;
3614
+ const entries = terms.map((x) => {
3615
+ const link = onPage ? deps.termsLink?.(key, x.ref) : undefined;
3616
+ return {
3617
+ entry: {
3618
+ group: x.group,
3619
+ groupName: x.groupName,
3620
+ ...(x.groupNames ? { groupNames: x.groupNames } : {}),
3621
+ hotelId: x.hotelId,
3622
+ hotelName: x.hotelName,
3623
+ ...(x.hotelNames ? { hotelNames: x.hotelNames } : {}),
3624
+ roomName: x.roomName,
3625
+ stay: x.stay,
3626
+ rooms: x.rooms,
3627
+ total: formatMoney(x.total),
3628
+ totalMoney: x.total,
3629
+ // ⚠️ THE MOMENT ONLY (0.63.0 screenshots): the card writes it in the viewer's own
3630
+ // language and time zone. "10:05 UTC, 10 Nov" here was drawn as is in a
3631
+ // Chinese card - and it is not the hotel's clock anyway (no zone is sent).
3632
+ until: x.until,
3633
+ ...(link ? { link } : {}),
3634
+ },
3635
+ link,
3636
+ x,
3637
+ };
3638
+ });
3639
+ const blocks = entries.map(({ link, x }) => {
3640
+ const until = clockWords(x.until) ?? x.until;
3641
+ return [
3642
+ `${withZh(x.hotelName, x.hotelNames, ctx.noCards)} · ${x.roomName} · ${stayWords(x.stay)} · ${x.rooms} ${x.rooms === 1 ? 'room' : 'rooms'} · ${formatMoney(x.total)} · ${x.groupName}`,
3643
+ `They can be agreed to until ${until}.`,
3644
+ onPage
3645
+ ? link
3646
+ ? `Give the guest this one-time link to read the terms and agree on ${deps.vocab.brand}'s page - it opens only in the browser signed in to their ${deps.vocab.brand} account, works once, until ${clockWords(link.expiresAt) ?? link.expiresAt}: ${link.url}. When they say they are done, call ${t.listBookings} to see the booking and its payment page.`
3647
+ : 'These terms can only be agreed to on a client that shows the card; nothing was ordered.'
3648
+ : '',
3649
+ ]
3650
+ .filter(Boolean)
3651
+ .join('\n');
3652
+ });
3653
+ return {
3654
+ structured: { terms: entries.map((e) => e.entry), termsSaid },
3655
+ text: [termsSaid, ...blocks].filter(Boolean).join('\n\n'),
3656
+ ...((ctx.drawsCards && !ctx.noCards) || ctx.termsMeta
3657
+ ? {
3658
+ meta: {
3659
+ [TERMS_META_KEY]: {
3660
+ terms: terms.map((x) => ({
3661
+ ref: x.ref,
3662
+ group: x.group,
3663
+ groupName: x.groupName,
3664
+ ...(x.groupNames ? { groupNames: x.groupNames } : {}),
3665
+ hotelId: x.hotelId,
3666
+ hotelName: x.hotelName,
3667
+ ...(x.hotelNames ? { hotelNames: x.hotelNames } : {}),
3668
+ roomName: x.roomName,
3669
+ stay: x.stay,
3670
+ rooms: x.rooms,
3671
+ total: formatMoney(x.total),
3672
+ totalMoney: x.total,
3673
+ text: x.text,
3674
+ until: x.until,
3675
+ })),
3676
+ },
3677
+ },
3678
+ }
3679
+ : {}),
3680
+ };
3681
+ };
3276
3682
  const bookingLine = (deps, b, noCards) => {
3277
3683
  const kinds = b.requests?.kinds ?? [];
3278
3684
  const held = noCards ? heldRoomsWords(b) : '';
@@ -3297,7 +3703,12 @@ const bookingLine = (deps, b, noCards) => {
3297
3703
  : ''}`
3298
3704
  : '',
3299
3705
  b.payment
3300
- ? ` · ${paymentWords(b)}${b.payment.status === 'awaiting' && b.payment.url ? ` by ${b.payment.payByLocal ?? b.payment.payBy}: ${b.payment.url}` : ''}`
3706
+ ? // ⚠️ THE PAGE BY ITS HOST, NOT "THE CARD PAGE" (0.63.0 transcript): beside a
3707
+ // host the old words read "to be paid on the card page - pay on <host>", and a
3708
+ // client with no card reads "card page" as the booking card's.
3709
+ b.payment.status === 'awaiting' && b.payment.url
3710
+ ? ` · to be paid on ${hostOf(b.payment.url) ?? 'its payment page'}${payByWords(b.payment) ? ` by ${payByWords(b.payment)}` : ''}: ${b.payment.url}`
3711
+ : ` · ${paymentWords(b)}`
3301
3712
  : '',
3302
3713
  ].join('');
3303
3714
  };
@@ -3487,6 +3898,31 @@ const remember = (deps, k, amount) => {
3487
3898
  m.delete(oldest);
3488
3899
  }
3489
3900
  };
3901
+ /**
3902
+ * The refund previews' tokens, per conversation and booking (`${key}|refund|${id}`).
3903
+ * ⚠️ SERVER-SIDE ONLY: the token is what lets a refund be asked, and goes to
3904
+ * neither the model nor the card - the card asks again with `confirmed`.
3905
+ */
3906
+ const refundTokens = new WeakMap();
3907
+ const refundTokensOf = (deps) => {
3908
+ let m = refundTokens.get(deps);
3909
+ if (!m) {
3910
+ m = new Map();
3911
+ refundTokens.set(deps, m);
3912
+ }
3913
+ return m;
3914
+ };
3915
+ const rememberRefund = (deps, k, preview, until) => {
3916
+ const m = refundTokensOf(deps);
3917
+ m.delete(k);
3918
+ m.set(k, { preview, until });
3919
+ while (m.size > MAX_SHOWN) {
3920
+ const oldest = m.keys().next().value;
3921
+ if (oldest === undefined)
3922
+ break;
3923
+ m.delete(oldest);
3924
+ }
3925
+ };
3490
3926
  /** "a, b and c" - "a and b" - "a". */
3491
3927
  const listAnd = (xs) => xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}` : (xs[0] ?? '');
3492
3928
  /**
@@ -4199,6 +4635,60 @@ export const tripGone = (deps) => {
4199
4635
  text: detail,
4200
4636
  };
4201
4637
  };
4638
+ /**
4639
+ * The guest's agreement to the terms behind `ref`, and what it came to: the
4640
+ * booking (with its payment page), the group's terms again, or a refusal's
4641
+ * code. THE ONE AGREE STEP: the booking card's own tool (`acceptTerms`) and the
4642
+ * one-time page (account/index.ts, `makeAccount({ terms })`) both end here, and
4643
+ * neither is the model's. Throws the group's refusals (`terms-gone`, `sign-in` …)
4644
+ * as `otaless/booking.ts` raises them: `refusalAnswer` says each.
4645
+ */
4646
+ export const agreeToTerms = async (deps, key, ref, ctx,
4647
+ /** The card's own arguments (a coupon, a request to remember), as it sent them; the page has none. */
4648
+ args = {}) => {
4649
+ const t = deps.tools;
4650
+ const ot = deps.backend.otalessBooking;
4651
+ if (!ot)
4652
+ return {
4653
+ structured: { view: 'error', ...common(deps, key), error: 'not-offered' },
4654
+ text: `Booking terms are not agreed to through ${deps.vocab.brand}.`,
4655
+ isError: true,
4656
+ };
4657
+ const who = identity(deps, ctx, key);
4658
+ const result = await ot.acceptTerms(ref, who);
4659
+ const inTrip = deps.trips.read(key);
4660
+ const answered = await bookingAnswer(deps, t, ctx, key, key, args, inTrip, inTrip, deps.trips.shown(key), result, undefined, [], true);
4661
+ // The picked room's slot, when the stay was booked from there: the same stays leave it.
4662
+ const slot = pickedKey(key);
4663
+ const picked = deps.trips.read(slot);
4664
+ if (picked.length && result.booked.length) {
4665
+ const gone = (l) => result.booked.some((b) => inFailedStay(l, b));
4666
+ if (picked.every(gone))
4667
+ deps.trips.clear(slot);
4668
+ else
4669
+ for (const l of picked)
4670
+ if (gone(l))
4671
+ deps.trips.set(slot, unset(l));
4672
+ }
4673
+ return answered;
4674
+ };
4675
+ /**
4676
+ * The conversation's tool context and identity from its key alone - for the
4677
+ * one-time terms page, which has the key (account layer) and no session id. The
4678
+ * key is `tripKey(session, brand)`; the identity is the same one the tools build.
4679
+ */
4680
+ export const contextFor = (deps, key) => {
4681
+ const suffix = ` ${deps.vocab.brand.toLowerCase()}`;
4682
+ return {
4683
+ session: key.endsWith(suffix) ? key.slice(0, -suffix.length) : key,
4684
+ tripKey: key,
4685
+ noCards: true,
4686
+ termsMeta: true,
4687
+ };
4688
+ };
4689
+ export const identityFor = (deps, key) => identity(deps, contextFor(deps, key), key);
4690
+ /** A booking refusal as its answer (`view: 'error'`, its code), or undefined when `err` is not one. */
4691
+ export const bookingRefusal = refusalAnswer;
4202
4692
  export const handleTool = async (deps, name, rawArgs, ctx) => {
4203
4693
  const { result, written } = await keepingAmounts(async () => {
4204
4694
  // ⚠️ A GROUP THAT DID NOT ANSWER A READ IS AN ANSWER, NOT A FAULT (2026-11-03
@@ -4207,6 +4697,11 @@ export const handleTool = async (deps, name, rawArgs, ctx) => {
4207
4697
  // connector could not answer that" - or, for a search where every group was
4208
4698
  // silent, as the first group's name alone. Said here, naming every group.
4209
4699
  const answer = await answerTool(deps, name, rawArgs, ctx).catch((err) => {
4700
+ // The group's checkout's refusals, from any tool that can get one (a
4701
+ // booking list, a cancellation, a refund, an add-on): answered with their code.
4702
+ const refused = refusalAnswer(deps, ctx.tripKey ?? tripKey(ctx.session, deps.vocab.brand), err);
4703
+ if (refused)
4704
+ return refused;
4210
4705
  const down = unansweredBy(err);
4211
4706
  if (!down)
4212
4707
  throw err;
@@ -5097,6 +5592,254 @@ const putRoomLine = async (deps, t, ctx, key, store, args, detail) => {
5097
5592
  ? { ...now, structured: { ...now.structured, took }, text: `${took}\n${now.text}` }
5098
5593
  : now;
5099
5594
  };
5595
+ /**
5596
+ * What a booking asked for came to, said: the stays booked, those that were not
5597
+ * and why, and any terms a group sent back for the guest to agree to - for
5598
+ * request_booking, for the picked room's booking, and for the card's agreement
5599
+ * to terms (`fromTerms`: only the stays that agreement booked leave the trip).
5600
+ */
5601
+ const bookingAnswer = async (deps, t, ctx, key, store, args, inTrip, lines, shown, result, requests, dropped, fromTerms = false) => {
5602
+ const { booked: made, failed, repeat, reused } = result;
5603
+ // Terms a group sent back: the stay waits for the guest's own agreement.
5604
+ const pendingTerms = result.terms ?? [];
5605
+ // A coupon spent is spent on the member's badge too.
5606
+ await refreshMember(deps, key);
5607
+ // ⚠️ WHAT WAS BOOKED LEAVES THE TRIP; WHAT WAS NOT STAYS IN IT, add-ons
5608
+ // and all - to ask again, or to put another hotel in its place (robin,
5609
+ // 2026-10-14).
5610
+ //
5611
+ // ⚠️ AND A STAY WITH TERMS WAITING IS NEITHER: it stays in the trip until the
5612
+ // guest has agreed and it is booked (then `fromTerms` takes out exactly the
5613
+ // stays that agreement booked, and leaves every other line where it is).
5614
+ const stillOut = (l) => fromTerms
5615
+ ? !made.some((b) => inFailedStay(l, b))
5616
+ : failed.some((f) => inFailedStay(l, f)) || pendingTerms.some((x) => inFailedStay(l, x));
5617
+ if (lines.length === inTrip.length && !lines.some(stillOut))
5618
+ deps.trips.clear(store);
5619
+ else
5620
+ for (const l of lines)
5621
+ if (!stillOut(l))
5622
+ deps.trips.set(store, unset(l));
5623
+ // What is left is priced again, and that price is what the next
5624
+ // booking is held to (ShownQuote).
5625
+ const rest = fromTerms
5626
+ ? lines.some(stillOut)
5627
+ ? await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx)
5628
+ : undefined
5629
+ : lines.length === inTrip.length && !failed.length
5630
+ ? undefined
5631
+ : await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx);
5632
+ const others = rest && (fromTerms || lines.length !== inTrip.length);
5633
+ // What could be booked instead of each, found now (robin, 2026-10-14).
5634
+ const instead = await Promise.all(failed.map((f, i) => i < MAX_FAILED_WITH_ALTERNATIVES
5635
+ ? alternativesFor(deps, f, lines, shown, identity(deps, ctx, key))
5636
+ : Promise.resolve({ hotels: [] })));
5637
+ // ⚠️ REMEMBERED ONLY WHEN ASKED - see `rememberPreferences`. Said either
5638
+ // way, so neither the guest nor the model assumes something was kept.
5639
+ const signedIn = deps.members.read(key);
5640
+ let remembered;
5641
+ if (args.rememberRequests === true) {
5642
+ const lasting = (requests?.kinds ?? []).filter((k) => LASTING_REQUESTS.includes(k));
5643
+ if (!signedIn) {
5644
+ remembered = {
5645
+ kept: [],
5646
+ line: 'Nothing was remembered: saved preferences belong to a membership, and nobody is signed in.',
5647
+ };
5648
+ }
5649
+ else if (!lasting.length) {
5650
+ remembered = {
5651
+ kept: signedIn.preferences ?? [],
5652
+ line: 'Nothing new was remembered: an early check-in, a late arrival and a note are for one stay, not every stay.',
5653
+ };
5654
+ }
5655
+ else {
5656
+ // ADDED TO what is kept, not in place of it: a quiet room remembered
5657
+ // this time silently dropped the king bed remembered last time. A new
5658
+ // request does replace its opposite - twin beds over a king bed.
5659
+ const clash = (k) => lasting.some((n) => OPPOSITES.some((pair) => pair.includes(n) && pair.includes(k)));
5660
+ const merged = [
5661
+ ...(signedIn.preferences ?? []).filter((k) => !lasting.includes(k) && !clash(k)),
5662
+ ...lasting,
5663
+ ];
5664
+ const kept = await deps.backend.rememberPreferences(signedIn, merged);
5665
+ deps.members.set(key, { ...signedIn, preferences: kept });
5666
+ deps.members.setPreferences(signedIn.number, kept);
5667
+ remembered = {
5668
+ kept,
5669
+ line: `Remembered on this ${signedIn.programme} membership for next time: ${kept.map((k) => REQUEST_WORDS[k]).join(', ')}. ${t.forgetPreferences} forgets them.`,
5670
+ };
5671
+ }
5672
+ }
5673
+ // The hotel's own check-in hour, so an early-check-in request is answered
5674
+ // with the time it is early against - London opens at 16:00 and Hong Kong
5675
+ // at 15:00, and a generic "check-in is in the afternoon" is not an answer.
5676
+ // Per booking: each is its own hotel, with its own hour and its own desk.
5677
+ const booked = await Promise.all(made.map(async (booking, i) => {
5678
+ // ⚠️ THE BOOKING IS MADE: a read after it that fails (a group slow to
5679
+ // answer) loses the check-in hour, never the answer.
5680
+ const hotel = await deps.backend.getHotel(booking.hotelId).catch(() => null);
5681
+ return {
5682
+ booking,
5683
+ // The requests that could not both be asked for are said once.
5684
+ asked: requestLines(booking, i === 0 ? dropped : [], hotel?.hotel.checkInFrom),
5685
+ };
5686
+ }));
5687
+ const [first] = booked;
5688
+ const several = booked.length > 1;
5689
+ // The stays asked for minutes before, beside new ones - see `reused`.
5690
+ const earlier = booked.filter(({ booking }) => reused?.includes(booking.id));
5691
+ // The coupon asked for, when the stays asked for before did not carry it
5692
+ // and nothing new did either - see `couponNotUsedOf`.
5693
+ const askedCoupon = couponOf(deps, args);
5694
+ const notUsed = couponNotUsedOf(deps, key, askedCoupon, repeat ? made : earlier.map(({ booking }) => booking), made);
5695
+ const waiting = booked.filter(({ booking }) => confirming(deps, booking)).length;
5696
+ const notBooked = failed.map((f, i) => ({
5697
+ hotelId: f.hotelId,
5698
+ hotelName: f.hotelName,
5699
+ stay: f.stay,
5700
+ ...(f.hourly ? { hourly: f.hourly } : {}),
5701
+ ...(f.roomName ? { roomName: f.roomName } : {}),
5702
+ rooms: roomsIn(lines, f),
5703
+ // What to take out of the trip to put another hotel in its place.
5704
+ roomRefs: lines.flatMap((l) => (l.kind === 'room' && inFailedStay(l, f) ? [l.roomId] : [])),
5705
+ extraRefs: lines.flatMap((l) => (l.kind === 'extra' && inFailedStay(l, f) ? [l.extraId] : [])),
5706
+ why: f.why,
5707
+ ...(f.code ? { code: f.code } : {}),
5708
+ ...(f.args ? { args: f.args } : {}),
5709
+ ...(instead[i]?.city ? { city: instead[i]?.city } : {}),
5710
+ alternatives: (instead[i]?.hotels ?? []).map((h) => ({
5711
+ hotelId: h.id,
5712
+ name: h.name,
5713
+ brand: h.brand,
5714
+ ...(h.forStay
5715
+ ? {
5716
+ total: formatMoney(h.forStay.total),
5717
+ room: h.forStay.room,
5718
+ ...(h.forStay.roomNames ? { roomNames: h.forStay.roomNames } : {}),
5719
+ freeCancellation: h.forStay.freeCancellation,
5720
+ }
5721
+ : {}),
5722
+ })),
5723
+ }));
5724
+ const failedText = notBooked.map((f) => `NOT BOOKED - ${f.hotelName} · ${stayWords(f.stay, f.hourly)}: ${f.why} It is still in the trip.${f.alternatives.length
5725
+ ? ` Bookable instead for the same nights: ${f.alternatives.map((a) => `${a.name}${a.room ? ` (${a.room}` : ''}${a.total ? `${a.room ? ', ' : ' ('}${a.total} for the stay)` : a.room ? ')' : ''} [hotel \`${a.hotelId}\`]`).join('; ')}.`
5726
+ : ''} The guest can ask again, take another hotel, or leave it.`);
5727
+ // Terms waiting for the guest, said first: that is what needs doing.
5728
+ const termsPart = pendingTerms.length ? termsAnswer(deps, ctx, key, pendingTerms) : undefined;
5729
+ if (!first) {
5730
+ if (termsPart)
5731
+ return {
5732
+ structured: {
5733
+ view: 'terms',
5734
+ ...common(deps, key),
5735
+ paid: false,
5736
+ ...(notBooked.length ? { failed: notBooked } : {}),
5737
+ ...termsPart.structured,
5738
+ },
5739
+ text: [termsPart.text, ...failedText].join('\n'),
5740
+ ...(termsPart.meta ? { meta: termsPart.meta } : {}),
5741
+ };
5742
+ // Nothing booked at all: every stay said, each with its way on.
5743
+ return {
5744
+ structured: {
5745
+ view: 'booking',
5746
+ ...common(deps, key),
5747
+ paid: false,
5748
+ failed: notBooked,
5749
+ },
5750
+ text: [
5751
+ `Nothing was booked: ${notBooked.length === 1 ? 'the stay' : `none of the ${notBooked.length} stays`} could be.`,
5752
+ ...failedText,
5753
+ ].join('\n'),
5754
+ };
5755
+ }
5756
+ const answer = {
5757
+ structured: {
5758
+ // ⚠️ 'booking' EVEN WHEN IT IS AWAITING PAYMENT: the card draws a view
5759
+ // only once it knows it, and the card-contract test holds every view
5760
+ // here to that. 香格里拉's card turns this into its own 'payment' step
5761
+ // (booking.status 'awaiting-payment', booking.payment) - and moves the
5762
+ // view with it.
5763
+ view: 'booking',
5764
+ ...common(deps, key),
5765
+ booking: madeForCard(deps, first.booking),
5766
+ // ⚠️ ONE PER STAY - see `requestBooking`. The card draws each with its
5767
+ // own code; `booking` stays the first, for a host that reads one.
5768
+ ...(several
5769
+ ? {
5770
+ bookings: booked.map(({ booking, asked }) => ({
5771
+ ...madeForCard(deps, booking),
5772
+ total: formatMoney(booking.quote.total),
5773
+ ...(asked.length ? { requested: asked } : {}),
5774
+ // Each its own warning colour - it rode on the first alone.
5775
+ ...(booking.requests?.kinds.includes('accessible-room')
5776
+ ? { accessibility: true }
5777
+ : {}),
5778
+ })),
5779
+ }
5780
+ : {}),
5781
+ paid: false,
5782
+ ...(remembered ? { remembered: remembered.kept } : {}),
5783
+ // What they come to together, said by the server like every figure on
5784
+ // the card - never added up there (r10, #15). Only in one currency.
5785
+ ...(several &&
5786
+ booked.every(({ booking }) => booking.quote.total.currency === first.booking.quote.total.currency)
5787
+ ? {
5788
+ totalAll: formatMoney({
5789
+ minor: booked.reduce((n, { booking }) => n + booking.quote.total.minor, 0),
5790
+ currency: first.booking.quote.total.currency,
5791
+ }),
5792
+ }
5793
+ : {}),
5794
+ holdUntil: first.booking.holdUntil,
5795
+ total: formatMoney(first.booking.quote.total),
5796
+ ...(first.asked.length ? { requested: first.asked } : {}),
5797
+ ...(first.booking.requests?.kinds.includes('accessible-room') ? { accessibility: true } : {}),
5798
+ ...(notBooked.length ? { failed: notBooked } : {}),
5799
+ ...(repeat ? { repeat: true } : {}),
5800
+ ...(earlier.length ? { repeated: earlier.map(({ booking }) => booking.id) } : {}),
5801
+ ...(notUsed ? { couponNotUsed: notUsed.structured } : {}),
5802
+ },
5803
+ text: [
5804
+ // ⚠️ THE SAME BOOKING ASKED FOR AGAIN IS SAID TO BE THAT, never a new
5805
+ // one (2026-10-27 audit, F2): it was answered as if just booked.
5806
+ repeat
5807
+ ? `NOTHING NEW WAS BOOKED: the same ${booked.length > 1 ? 'stays' : 'stay'} for the same guest ${booked.length > 1 ? 'were' : 'was'} asked for a few minutes ago, and ${booked.length > 1 ? 'these are the bookings' : 'this is the booking'} made then. A booking for someone else is made under their name.`
5808
+ : earlier.length
5809
+ ? `NOT ALL NEW: ${listAnd(earlier.map(({ booking }) => booking.confirmationCode || booking.hotelName))} ${earlier.length > 1 ? 'were' : 'was'} asked for a few minutes ago for the same guest and ${earlier.length > 1 ? 'are the bookings' : 'is the booking'} made then; the rest were booked now.`
5810
+ : '',
5811
+ notUsed?.said ?? '',
5812
+ // ⚠️ BOOKED IS CONFIRMED: a stay still being confirmed is said as
5813
+ // that, and not counted (总线程, 2026-10-14).
5814
+ notBooked.length || (booked.length > 1 && waiting)
5815
+ ? `${booked.length - waiting} of ${booked.length + notBooked.length} stays booked${waiting ? `, ${waiting} being confirmed by the hotel - no code until it is` : ''}${notBooked.length ? `; ${notBooked.length === 1 ? 'one' : notBooked.length} could not be, said below` : ''} - what was booked stays booked.`
5816
+ : '',
5817
+ several
5818
+ ? `${booked.length} bookings, one for each stay - each hotel keeps its own nights under its own code, and each is ${holderOf(deps, first.booking.supplier).caps.changes ? 'changed or cancelled' : 'cancelled'} on its own.`
5819
+ : '',
5820
+ ...booked.flatMap(({ booking, asked }) => [
5821
+ `**${confirming(deps, booking) ? 'Being confirmed' : booking.confirmationCode}** · ${withZh(booking.hotelName, booking.hotelNames, ctx.noCards)} · ${stayWords(booking.stay, booking.hourly)}`,
5822
+ ctx.noCards ? heldRoomsWords(booking) : '',
5823
+ bookedLine(deps, booking),
5824
+ ...asked,
5825
+ ]),
5826
+ ...failedText,
5827
+ remembered?.line ?? '',
5828
+ others ? `The trip's other stays are still in it, not booked:\n${rest?.text ?? ''}` : '',
5829
+ ]
5830
+ .filter(Boolean)
5831
+ .join('\n'),
5832
+ };
5833
+ if (!termsPart)
5834
+ return answer;
5835
+ // Some stays booked in this call and some waiting for terms: both are said,
5836
+ // the terms first, and the structure is the terms' view with the bookings in it.
5837
+ return {
5838
+ structured: { ...answer.structured, view: 'terms', ...termsPart.structured },
5839
+ text: [termsPart.text, answer.text].join('\n\n'),
5840
+ ...(termsPart.meta ? { meta: { ...answer.meta, ...termsPart.meta } } : {}),
5841
+ };
5842
+ };
5100
5843
  /**
5101
5844
  * Books the rooms in one slot of the trip store for a named guest - THE ONE
5102
5845
  * BOOKING CODE, for the trip (`request_booking`, `store` the trip's own key)
@@ -5177,7 +5920,7 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
5177
5920
  const { requests, dropped } = readRequests(args);
5178
5921
  try {
5179
5922
  const shown = deps.trips.shown(store);
5180
- const { booked: made, failed, repeat, reused, } = await deps.backend.requestBooking(
5923
+ const result = await deps.backend.requestBooking(
5181
5924
  // The coupon the guest named, spent on the one stay it goes on - or
5182
5925
  // nothing is booked (see `TripDraft.coupon`).
5183
5926
  {
@@ -5198,212 +5941,7 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
5198
5941
  // only place an Identity is built; the guest's email still overrides,
5199
5942
  // because a booking is found by the address it was made with.
5200
5943
  { ...identity(deps, ctx, key), email: guest.email }, requests);
5201
- // A coupon spent is spent on the member's badge too.
5202
- await refreshMember(deps, key);
5203
- // ⚠️ WHAT WAS BOOKED LEAVES THE TRIP; WHAT WAS NOT STAYS IN IT, add-ons
5204
- // and all - to ask again, or to put another hotel in its place (robin,
5205
- // 2026-10-14).
5206
- const stillOut = (l) => failed.some((f) => inFailedStay(l, f));
5207
- if (lines.length === inTrip.length && !lines.some(stillOut))
5208
- deps.trips.clear(store);
5209
- else
5210
- for (const l of lines)
5211
- if (!stillOut(l))
5212
- deps.trips.set(store, unset(l));
5213
- // What is left is priced again, and that price is what the next
5214
- // booking is held to (ShownQuote).
5215
- const rest = lines.length === inTrip.length && !failed.length
5216
- ? undefined
5217
- : await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx);
5218
- const others = rest && lines.length !== inTrip.length;
5219
- // What could be booked instead of each, found now (robin, 2026-10-14).
5220
- const instead = await Promise.all(failed.map((f, i) => i < MAX_FAILED_WITH_ALTERNATIVES
5221
- ? alternativesFor(deps, f, lines, shown, identity(deps, ctx, key))
5222
- : Promise.resolve({ hotels: [] })));
5223
- // ⚠️ REMEMBERED ONLY WHEN ASKED - see `rememberPreferences`. Said either
5224
- // way, so neither the guest nor the model assumes something was kept.
5225
- const signedIn = deps.members.read(key);
5226
- let remembered;
5227
- if (args.rememberRequests === true) {
5228
- const lasting = (requests?.kinds ?? []).filter((k) => LASTING_REQUESTS.includes(k));
5229
- if (!signedIn) {
5230
- remembered = {
5231
- kept: [],
5232
- line: 'Nothing was remembered: saved preferences belong to a membership, and nobody is signed in.',
5233
- };
5234
- }
5235
- else if (!lasting.length) {
5236
- remembered = {
5237
- kept: signedIn.preferences ?? [],
5238
- line: 'Nothing new was remembered: an early check-in, a late arrival and a note are for one stay, not every stay.',
5239
- };
5240
- }
5241
- else {
5242
- // ADDED TO what is kept, not in place of it: a quiet room remembered
5243
- // this time silently dropped the king bed remembered last time. A new
5244
- // request does replace its opposite - twin beds over a king bed.
5245
- const clash = (k) => lasting.some((n) => OPPOSITES.some((pair) => pair.includes(n) && pair.includes(k)));
5246
- const merged = [
5247
- ...(signedIn.preferences ?? []).filter((k) => !lasting.includes(k) && !clash(k)),
5248
- ...lasting,
5249
- ];
5250
- const kept = await deps.backend.rememberPreferences(signedIn, merged);
5251
- deps.members.set(key, { ...signedIn, preferences: kept });
5252
- deps.members.setPreferences(signedIn.number, kept);
5253
- remembered = {
5254
- kept,
5255
- line: `Remembered on this ${signedIn.programme} membership for next time: ${kept.map((k) => REQUEST_WORDS[k]).join(', ')}. ${t.forgetPreferences} forgets them.`,
5256
- };
5257
- }
5258
- }
5259
- // The hotel's own check-in hour, so an early-check-in request is answered
5260
- // with the time it is early against - London opens at 16:00 and Hong Kong
5261
- // at 15:00, and a generic "check-in is in the afternoon" is not an answer.
5262
- // Per booking: each is its own hotel, with its own hour and its own desk.
5263
- const booked = await Promise.all(made.map(async (booking, i) => {
5264
- // ⚠️ THE BOOKING IS MADE: a read after it that fails (a group slow to
5265
- // answer) loses the check-in hour, never the answer.
5266
- const hotel = await deps.backend.getHotel(booking.hotelId).catch(() => null);
5267
- return {
5268
- booking,
5269
- // The requests that could not both be asked for are said once.
5270
- asked: requestLines(booking, i === 0 ? dropped : [], hotel?.hotel.checkInFrom),
5271
- };
5272
- }));
5273
- const [first] = booked;
5274
- const several = booked.length > 1;
5275
- // The stays asked for minutes before, beside new ones - see `reused`.
5276
- const earlier = booked.filter(({ booking }) => reused?.includes(booking.id));
5277
- // The coupon asked for, when the stays asked for before did not carry it
5278
- // and nothing new did either - see `couponNotUsedOf`.
5279
- const askedCoupon = couponOf(deps, args);
5280
- const notUsed = couponNotUsedOf(deps, key, askedCoupon, repeat ? made : earlier.map(({ booking }) => booking), made);
5281
- const waiting = booked.filter(({ booking }) => confirming(deps, booking)).length;
5282
- const notBooked = failed.map((f, i) => ({
5283
- hotelId: f.hotelId,
5284
- hotelName: f.hotelName,
5285
- stay: f.stay,
5286
- ...(f.hourly ? { hourly: f.hourly } : {}),
5287
- ...(f.roomName ? { roomName: f.roomName } : {}),
5288
- rooms: roomsIn(lines, f),
5289
- // What to take out of the trip to put another hotel in its place.
5290
- roomRefs: lines.flatMap((l) => (l.kind === 'room' && inFailedStay(l, f) ? [l.roomId] : [])),
5291
- extraRefs: lines.flatMap((l) => l.kind === 'extra' && inFailedStay(l, f) ? [l.extraId] : []),
5292
- why: f.why,
5293
- ...(f.code ? { code: f.code } : {}),
5294
- ...(f.args ? { args: f.args } : {}),
5295
- ...(instead[i]?.city ? { city: instead[i]?.city } : {}),
5296
- alternatives: (instead[i]?.hotels ?? []).map((h) => ({
5297
- hotelId: h.id,
5298
- name: h.name,
5299
- brand: h.brand,
5300
- ...(h.forStay
5301
- ? {
5302
- total: formatMoney(h.forStay.total),
5303
- room: h.forStay.room,
5304
- ...(h.forStay.roomNames ? { roomNames: h.forStay.roomNames } : {}),
5305
- freeCancellation: h.forStay.freeCancellation,
5306
- }
5307
- : {}),
5308
- })),
5309
- }));
5310
- const failedText = notBooked.map((f) => `NOT BOOKED - ${f.hotelName} · ${stayWords(f.stay, f.hourly)}: ${f.why} It is still in the trip.${f.alternatives.length
5311
- ? ` Bookable instead for the same nights: ${f.alternatives.map((a) => `${a.name}${a.room ? ` (${a.room}` : ''}${a.total ? `${a.room ? ', ' : ' ('}${a.total} for the stay)` : a.room ? ')' : ''} [hotel \`${a.hotelId}\`]`).join('; ')}.`
5312
- : ''} The guest can ask again, take another hotel, or leave it.`);
5313
- if (!first) {
5314
- // Nothing booked at all: every stay said, each with its way on.
5315
- return {
5316
- structured: {
5317
- view: 'booking',
5318
- ...common(deps, key),
5319
- paid: false,
5320
- failed: notBooked,
5321
- },
5322
- text: [
5323
- `Nothing was booked: ${notBooked.length === 1 ? 'the stay' : `none of the ${notBooked.length} stays`} could be.`,
5324
- ...failedText,
5325
- ].join('\n'),
5326
- };
5327
- }
5328
- return {
5329
- structured: {
5330
- // ⚠️ 'booking' EVEN WHEN IT IS AWAITING PAYMENT: the card draws a view
5331
- // only once it knows it, and the card-contract test holds every view
5332
- // here to that. 香格里拉's card turns this into its own 'payment' step
5333
- // (booking.status 'awaiting-payment', booking.payment) - and moves the
5334
- // view with it.
5335
- view: 'booking',
5336
- ...common(deps, key),
5337
- booking: madeForCard(deps, first.booking),
5338
- // ⚠️ ONE PER STAY - see `requestBooking`. The card draws each with its
5339
- // own code; `booking` stays the first, for a host that reads one.
5340
- ...(several
5341
- ? {
5342
- bookings: booked.map(({ booking, asked }) => ({
5343
- ...madeForCard(deps, booking),
5344
- total: formatMoney(booking.quote.total),
5345
- ...(asked.length ? { requested: asked } : {}),
5346
- // Each its own warning colour - it rode on the first alone.
5347
- ...(booking.requests?.kinds.includes('accessible-room')
5348
- ? { accessibility: true }
5349
- : {}),
5350
- })),
5351
- }
5352
- : {}),
5353
- paid: false,
5354
- ...(remembered ? { remembered: remembered.kept } : {}),
5355
- // What they come to together, said by the server like every figure on
5356
- // the card - never added up there (r10, #15). Only in one currency.
5357
- ...(several &&
5358
- booked.every(({ booking }) => booking.quote.total.currency === first.booking.quote.total.currency)
5359
- ? {
5360
- totalAll: formatMoney({
5361
- minor: booked.reduce((n, { booking }) => n + booking.quote.total.minor, 0),
5362
- currency: first.booking.quote.total.currency,
5363
- }),
5364
- }
5365
- : {}),
5366
- holdUntil: first.booking.holdUntil,
5367
- total: formatMoney(first.booking.quote.total),
5368
- ...(first.asked.length ? { requested: first.asked } : {}),
5369
- ...(first.booking.requests?.kinds.includes('accessible-room')
5370
- ? { accessibility: true }
5371
- : {}),
5372
- ...(notBooked.length ? { failed: notBooked } : {}),
5373
- ...(repeat ? { repeat: true } : {}),
5374
- ...(earlier.length ? { repeated: earlier.map(({ booking }) => booking.id) } : {}),
5375
- ...(notUsed ? { couponNotUsed: notUsed.structured } : {}),
5376
- },
5377
- text: [
5378
- // ⚠️ THE SAME BOOKING ASKED FOR AGAIN IS SAID TO BE THAT, never a new
5379
- // one (2026-10-27 audit, F2): it was answered as if just booked.
5380
- repeat
5381
- ? `NOTHING NEW WAS BOOKED: the same ${booked.length > 1 ? 'stays' : 'stay'} for the same guest ${booked.length > 1 ? 'were' : 'was'} asked for a few minutes ago, and ${booked.length > 1 ? 'these are the bookings' : 'this is the booking'} made then. A booking for someone else is made under their name.`
5382
- : earlier.length
5383
- ? `NOT ALL NEW: ${listAnd(earlier.map(({ booking }) => booking.confirmationCode || booking.hotelName))} ${earlier.length > 1 ? 'were' : 'was'} asked for a few minutes ago for the same guest and ${earlier.length > 1 ? 'are the bookings' : 'is the booking'} made then; the rest were booked now.`
5384
- : '',
5385
- notUsed?.said ?? '',
5386
- // ⚠️ BOOKED IS CONFIRMED: a stay still being confirmed is said as
5387
- // that, and not counted (总线程, 2026-10-14).
5388
- notBooked.length || (booked.length > 1 && waiting)
5389
- ? `${booked.length - waiting} of ${booked.length + notBooked.length} stays booked${waiting ? `, ${waiting} being confirmed by the hotel - no code until it is` : ''}${notBooked.length ? `; ${notBooked.length === 1 ? 'one' : notBooked.length} could not be, said below` : ''} - what was booked stays booked.`
5390
- : '',
5391
- several
5392
- ? `${booked.length} bookings, one for each stay - each hotel keeps its own nights under its own code, and each is ${holderOf(deps, first.booking.supplier).caps.changes ? 'changed or cancelled' : 'cancelled'} on its own.`
5393
- : '',
5394
- ...booked.flatMap(({ booking, asked }) => [
5395
- `**${confirming(deps, booking) ? 'Being confirmed' : booking.confirmationCode}** · ${withZh(booking.hotelName, booking.hotelNames, ctx.noCards)} · ${stayWords(booking.stay, booking.hourly)}`,
5396
- ctx.noCards ? heldRoomsWords(booking) : '',
5397
- bookedLine(deps, booking),
5398
- ...asked,
5399
- ]),
5400
- ...failedText,
5401
- remembered?.line ?? '',
5402
- others ? `The trip's other stays are still in it, not booked:\n${rest?.text ?? ''}` : '',
5403
- ]
5404
- .filter(Boolean)
5405
- .join('\n'),
5406
- };
5944
+ return await bookingAnswer(deps, t, ctx, key, store, args, inTrip, lines, shown, result, requests, dropped);
5407
5945
  }
5408
5946
  catch (err) {
5409
5947
  const words = guestWords(err, BOOKING_FAULT);
@@ -5412,7 +5950,13 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
5412
5950
  // has seen, and what a second ask books.
5413
5951
  if (err.code === 'price-changed') {
5414
5952
  const again = await currentTrip(deps, key, identity(deps, ctx, key), store, undefined, ctx);
5415
- return { ...again, text: [words, again.text].join('\n\n') };
5953
+ // ⚠️ THE CODE REACHES THE CARD (`notBooked`, as the coupon's does): the trip is
5954
+ // drawn again at today's price, and the card says why nothing was booked.
5955
+ return {
5956
+ ...again,
5957
+ structured: { ...again.structured, notBooked: 'price-changed' },
5958
+ text: [words, again.text].join('\n\n'),
5959
+ };
5416
5960
  }
5417
5961
  // The coupon asked for cannot be used: nothing was booked, and the trip
5418
5962
  // is shown again with it refused and why - the guest decides what next.
@@ -5438,6 +5982,11 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
5438
5982
  ].join('\n\n'),
5439
5983
  };
5440
5984
  }
5985
+ // The group's checkout's own refusals - signed out, a guest detail missing,
5986
+ // terms gone - each with its own code (`BOOKING_REFUSALS`).
5987
+ const refused = refusalAnswer(deps, key, err);
5988
+ if (refused)
5989
+ return refused;
5441
5990
  return {
5442
5991
  structured: {
5443
5992
  view: 'error',
@@ -6752,6 +7301,197 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
6752
7301
  }
6753
7302
  return direct(await bookTripLines(deps, t, ctx, key, pickedKey(key), args, 'Nothing is picked: the guest presses Reserve on a room first.'));
6754
7303
  }
7304
+ // The card's own: the guest pressed "Agree and continue" under a group's
7305
+ // booking terms. ⚠️ THE ONLY AGREEMENT THERE IS: no tool the model sees has a
7306
+ // parameter that means it, and this one is refused to a client that draws no
7307
+ // card (server.ts keeps it from the model of one that does). `ref` only names
7308
+ // the terms the card was showing - they are kept for the guest's own account,
7309
+ // for a few minutes, and used once.
7310
+ if (name === t.acceptTerms) {
7311
+ if (ctx.noCards)
7312
+ return {
7313
+ structured: { view: 'error', ...common(deps, key), error: 'card-only' },
7314
+ text: `${t.acceptTerms} is the booking card's own. Booking terms are agreed to by the guest, on the card or on the one-time page the booking answer gave - never in the chat.`,
7315
+ isError: true,
7316
+ };
7317
+ const ot = deps.backend.otalessBooking;
7318
+ if (!ot)
7319
+ return {
7320
+ structured: { view: 'error', ...common(deps, key), error: 'not-offered' },
7321
+ text: `Booking terms are not agreed to through ${deps.vocab.brand}.`,
7322
+ isError: true,
7323
+ };
7324
+ return await agreeToTerms(deps, key, str(args.ref), ctx, args);
7325
+ }
7326
+ // A paid booking's money back, in full: the guest asked, and the booking and
7327
+ // the amount were said back to them. Only this account's own booking is
7328
+ // known to the backend (`otalessBooking.refund` finds it in its own record).
7329
+ if (name === t.refundBooking) {
7330
+ const ot = deps.backend.otalessBooking;
7331
+ const ref = str(args.booking);
7332
+ const who = identity(deps, ctx, key);
7333
+ const why = upTo(str(args.reason), REFUND_REASON_MAX) || undefined;
7334
+ if (!ot) {
7335
+ return {
7336
+ structured: { view: 'error', ...common(deps, key), error: 'not-offered' },
7337
+ text: `Refunds are not asked for through ${deps.vocab.brand}.`,
7338
+ isError: true,
7339
+ };
7340
+ }
7341
+ const notFound = () => ({
7342
+ structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
7343
+ text: 'No booking here matches that code. Only bookings made here by this account are known, so nothing was refunded.',
7344
+ });
7345
+ // ⚠️ A REFUND IS TWO STEPS ON THE SERVER (总线程's review of 0.63.0, B). The
7346
+ // preview's token stays here, keyed by conversation and booking: it never
7347
+ // goes to the model or the card, and a `confirmed` is sent only with the
7348
+ // token this conversation was given for this booking, unexpired, once.
7349
+ const preview = async () => {
7350
+ const p = await ot.previewRefund(ref, who);
7351
+ if (!p)
7352
+ return notFound();
7353
+ rememberRefund(deps, `${key}|refund|${p.bookingId}`, p.preview, Date.parse(p.until));
7354
+ const booked = await deps.backend.findBooking(ref, who).catch(() => null);
7355
+ const group = holderOf(deps, p.supplier).name;
7356
+ const hotel = booked ? withZh(booked.hotelName, booked.hotelNames, ctx.noCards) : '';
7357
+ const terms = upTo(p.terms, TERMS_TEXT_MAX);
7358
+ const amount = formatMoney(p.amount);
7359
+ return {
7360
+ structured: {
7361
+ view: 'refund-preview',
7362
+ ...common(deps, key),
7363
+ booking: {
7364
+ confirmationCode: p.confirmationCode,
7365
+ supplier: p.supplier,
7366
+ ...(booked
7367
+ ? {
7368
+ hotelName: booked.hotelName,
7369
+ ...(booked.hotelNames ? { hotelNames: booked.hotelNames } : {}),
7370
+ stay: booked.stay,
7371
+ }
7372
+ : {}),
7373
+ },
7374
+ amount,
7375
+ terms,
7376
+ until: p.until,
7377
+ },
7378
+ text: [
7379
+ `Refund preview for ${p.confirmationCode}${hotel ? ` · ${hotel}` : ''}${booked ? ` · ${stayWords(booked.stay, booked.hourly)}` : ''}: all of ${amount} would be asked back from ${group}.`,
7380
+ `${group}'s terms, ${p.terms ? `in its own words: "${terms}"` : 'none given'}.`,
7381
+ `Nothing has been asked yet. Say this to the guest and get their yes, then call ${t.refundBooking} again with \`confirmed: true\` (this preview can be used until ${clockWords(p.until) ?? p.until}).`,
7382
+ ].join(' '),
7383
+ };
7384
+ };
7385
+ if (args.confirmed !== true)
7386
+ return await preview();
7387
+ const booked = await deps.backend.findBooking(ref, who).catch(() => null);
7388
+ if (!booked)
7389
+ return notFound();
7390
+ const slot = `${key}|refund|${booked.id}`;
7391
+ const kept = refundTokensOf(deps).get(slot);
7392
+ refundTokensOf(deps).delete(slot); // one use, whatever comes of it
7393
+ if (!kept)
7394
+ return await preview();
7395
+ // The backend holds the clock of the preview (`REFUND_PREVIEW_MS`): one that ran
7396
+ // out is refused there with `refund-preview`, and is shown again here.
7397
+ const booking = await ot.refund(ref, who, why, kept.preview).catch((err) => {
7398
+ if (err?.code === 'refund-preview')
7399
+ return 'again';
7400
+ throw err;
7401
+ });
7402
+ if (booking === 'again')
7403
+ return await preview();
7404
+ if (!booking)
7405
+ return notFound();
7406
+ return {
7407
+ structured: {
7408
+ view: 'booking',
7409
+ ...common(deps, key),
7410
+ booking: madeForCard(deps, booking),
7411
+ total: formatMoney(booking.quote.total),
7412
+ refundAsked: true,
7413
+ },
7414
+ text: `Refund asked for ${booking.confirmationCode} · ${withZh(booking.hotelName, booking.hotelNames, ctx.noCards)} · ${stayWords(booking.stay, booking.hourly)}: ${booking.payment
7415
+ ? `${paymentWords(booking)} (${formatMoney(booking.payment.amount)} paid).`
7416
+ : 'the group has taken the request.'}`,
7417
+ };
7418
+ }
7419
+ // What can be added to a booking after it is made, and adding one: text and
7420
+ // structure, no card. The id is the one the list gave - the backend checks it
7421
+ // was listed for this very booking a moment ago.
7422
+ if (name === t.listBookingAddons) {
7423
+ const ot = deps.backend.otalessBooking;
7424
+ const ref = str(args.booking);
7425
+ const found = ot ? await ot.addons(ref, identity(deps, ctx, key)) : null;
7426
+ if (!found) {
7427
+ return {
7428
+ structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
7429
+ text: 'No booking here matches that code. Only bookings made here by this account have add-ons to list.',
7430
+ };
7431
+ }
7432
+ const needs = (e) => e.kind === 'transfer'
7433
+ ? 'needs direction (arrival, departure or round_trip), flightNo, pickupTime (HH:MM) and date (YYYY-MM-DD)'
7434
+ : 'needs a date (YYYY-MM-DD) and a quantity, if more than one';
7435
+ return {
7436
+ structured: {
7437
+ view: 'booking-addons',
7438
+ ...common(deps, key),
7439
+ booking: ref,
7440
+ addons: found.map((e) => ({
7441
+ id: e.id,
7442
+ name: e.name,
7443
+ kind: e.kind,
7444
+ description: e.description,
7445
+ price: formatMoney(e.price),
7446
+ per: e.per,
7447
+ needs: needs(e),
7448
+ })),
7449
+ },
7450
+ text: found.length
7451
+ ? [
7452
+ `Add-ons for ${ref}:`,
7453
+ ...found.map((e) => `- ${e.name} (id \`${e.id}\`) — ${formatMoney(e.price)} ${unitWords(e.per)}; ${needs(e)}${e.description ? `. ${e.description}` : ''}`),
7454
+ ].join('\n')
7455
+ : `Nothing can be added to ${ref} just now.`,
7456
+ };
7457
+ }
7458
+ if (name === t.addBookingAddon) {
7459
+ const ot = deps.backend.otalessBooking;
7460
+ const ref = str(args.booking);
7461
+ const addon = str(args.addon);
7462
+ const direction = ['arrival', 'departure', 'round_trip'].includes(str(args.direction))
7463
+ ? str(args.direction)
7464
+ : undefined;
7465
+ const done = ot
7466
+ ? await ot.bookAddon(ref, addon, {
7467
+ ...(direction ? { direction } : {}),
7468
+ ...(str(args.flightNo) ? { flightNo: str(args.flightNo) } : {}),
7469
+ ...(str(args.pickupTime) ? { pickupTime: str(args.pickupTime) } : {}),
7470
+ ...(str(args.date) ? { date: str(args.date) } : {}),
7471
+ ...(typeof args.quantity === 'number' ? { quantity: args.quantity } : {}),
7472
+ }, identity(deps, ctx, key))
7473
+ : null;
7474
+ if (!done) {
7475
+ return {
7476
+ structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
7477
+ text: 'No booking here matches that code. Only bookings made here by this account can have an add-on.',
7478
+ };
7479
+ }
7480
+ return {
7481
+ structured: {
7482
+ view: 'booking-addon',
7483
+ ...common(deps, key),
7484
+ booking: ref,
7485
+ addon: {
7486
+ id: addon,
7487
+ code: done.code,
7488
+ status: done.status,
7489
+ ...(done.total ? { total: formatMoney(done.total) } : {}),
7490
+ },
7491
+ },
7492
+ text: `Added to ${ref}: add-on order ${done.code}, ${done.status || 'taken'}${done.total ? `, ${formatMoney(done.total)}` : ''}.`,
7493
+ };
7494
+ }
6755
7495
  if (name === t.listBookings) {
6756
7496
  const who = identity(deps, ctx, key, args);
6757
7497
  const here = await deps.backend.listBookings(who, typeof args.limit === 'number' ? args.limit : undefined);
@@ -7089,7 +7829,8 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7089
7829
  }
7090
7830
  : {};
7091
7831
  // Money already paid here, and what comes back: see `paidFactsOf`.
7092
- const paid = paidFactsOf(booked, preview);
7832
+ // ⚠️ NOT WHEN THE FEE IS NOT KNOWN: what comes back is then the group's to say.
7833
+ const paid = preview.feeUnknown ? undefined : paidFactsOf(booked, preview);
7093
7834
  const asPreview = {
7094
7835
  structured: {
7095
7836
  view: 'cancellation-preview',
@@ -7118,7 +7859,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7118
7859
  }
7119
7860
  : {}),
7120
7861
  ...ownDemo,
7121
- fee: formatMoney(preview.fee),
7862
+ // ⚠️ THE FEE IS NOT KNOWN BEFORE THE GROUP CANCELS (`feeUnknown`): the rule is
7863
+ // the group's own terms, and no figure - not even "up to" - is said.
7864
+ ...(preview.feeUnknown ? { feeUnknown: true } : { fee: formatMoney(preview.fee) }),
7122
7865
  // What the booking came to, so the fee is read against it (r10 #22).
7123
7866
  ...(booked ? { bookingTotal: formatMoney(booked.quote.total) } : {}),
7124
7867
  // ⚠️ NO "REFUND": nothing was ever paid here - a demonstration takes no
@@ -7159,7 +7902,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7159
7902
  : {}),
7160
7903
  },
7161
7904
  text: [
7162
- `Cancelling ${preview.confirmationCode} would cost ${formatMoney(preview.fee)}${preview.fee.minor === 0 ? ' - nothing' : ''}.`,
7905
+ preview.feeUnknown
7906
+ ? `Cancelling ${preview.confirmationCode}: the fee is not known until ${holderOf(deps, preview.supplier).name} cancels it - it is whatever ${holderOf(deps, preview.supplier).name} charges then, under its own terms:`
7907
+ : `Cancelling ${preview.confirmationCode} would cost ${formatMoney(preview.fee)}${preview.fee.minor === 0 ? ' - nothing' : ''}.`,
7163
7908
  preview.rule,
7164
7909
  preview.coupon
7165
7910
  ? couponBackWords(preview.coupon, formatMoney(preview.fee), false, holderOf(deps, preview.supplier).notReal)
@@ -7203,7 +7948,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7203
7948
  // answers a cancellation with its penalty; the preview was our reading of
7204
7949
  // the rate's terms, and where the two differ the hotel's is the one that
7205
7950
  // will be charged.
7951
+ // ⚠️ AND WHERE THE FEE WAS NOT KNOWN, only what the group says it charged.
7206
7952
  const charged = cancelled.cancellationFee ?? preview.fee;
7953
+ const feeUnsaid = !!preview.feeUnknown && !cancelled.cancellationFee;
7207
7954
  const h = holderOf(deps, cancelled.supplier);
7208
7955
  // What became of the coupon the booking used, said once and handed over in
7209
7956
  // both: the structure's `coupon` and the text's sentence are this one string.
@@ -7234,7 +7981,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7234
7981
  booking: bookingForCard(cancelled),
7235
7982
  ...which,
7236
7983
  ...ownDemo,
7237
- fee: formatMoney(charged),
7984
+ ...(feeUnsaid ? { feeUnknown: true } : { fee: formatMoney(charged) }),
7238
7985
  rule: preview.rule,
7239
7986
  cancellable: false,
7240
7987
  ...(couponNow ? { coupon: couponNow } : {}),
@@ -7242,14 +7989,16 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7242
7989
  text: [
7243
7990
  cancelled.payment
7244
7991
  ? // Paid here in advance: what becomes of the money is the answer.
7245
- `${cancelled.confirmationCode} is ${cancelled.status === 'expired' ? 'called off before it was paid' : 'cancelled'}. ${paidLine(deps, cancelled, charged)}`
7246
- : h.notReal
7247
- ? // The fact, in no environment's word (robin, 2026-11-03); nobody charges
7248
- // a booking that was never sent anything (2026-10-05 audit, P2).
7249
- `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `A real booking on this rate would be charged ${formatMoney(charged)}; this booking was never sent to ${h.name}, and nothing is charged.`}`
7250
- : h.test
7251
- ? `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `A real booking on this rate would be charged ${formatMoney(charged)}; this booking held no room for anyone, and nothing is charged.`}`
7252
- : `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `The hotel charges ${formatMoney(charged)}.`}`,
7992
+ `${cancelled.confirmationCode} is ${cancelled.status === 'expired' ? 'called off before it was paid' : 'cancelled'}. ${paidLine(deps, cancelled, feeUnsaid ? undefined : charged)}`
7993
+ : feeUnsaid
7994
+ ? `${cancelled.confirmationCode} is cancelled. ${h.name} charges whatever its own terms say; the amount is not known here.`
7995
+ : h.notReal
7996
+ ? // The fact, in no environment's word (robin, 2026-11-03); nobody charges
7997
+ // a booking that was never sent anything (2026-10-05 audit, P2).
7998
+ `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `A real booking on this rate would be charged ${formatMoney(charged)}; this booking was never sent to ${h.name}, and nothing is charged.`}`
7999
+ : h.test
8000
+ ? `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `A real booking on this rate would be charged ${formatMoney(charged)}; this booking held no room for anyone, and nothing is charged.`}`
8001
+ : `${cancelled.confirmationCode} is cancelled. ${charged.minor === 0 ? 'No fee.' : `The hotel charges ${formatMoney(charged)}.`}`,
7253
8002
  couponNow?.said ?? '',
7254
8003
  demoBookingNote(deps, cancelled.supplier),
7255
8004
  ]