@curless/hotel-storefront 0.81.0 → 0.82.0

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 (83) hide show
  1. package/dist/account/addon-pages.d.ts +22 -0
  2. package/dist/account/addon-pages.d.ts.map +1 -0
  3. package/dist/account/addon-pages.js +282 -0
  4. package/dist/account/addon-pages.js.map +1 -0
  5. package/dist/account/index.d.ts +40 -0
  6. package/dist/account/index.d.ts.map +1 -1
  7. package/dist/account/index.js +292 -18
  8. package/dist/account/index.js.map +1 -1
  9. package/dist/account/ota-member.d.ts +15 -0
  10. package/dist/account/ota-member.d.ts.map +1 -1
  11. package/dist/account/ota-member.js +21 -5
  12. package/dist/account/ota-member.js.map +1 -1
  13. package/dist/account/pages.d.ts +24 -2
  14. package/dist/account/pages.d.ts.map +1 -1
  15. package/dist/account/pages.js +92 -33
  16. package/dist/account/pages.js.map +1 -1
  17. package/dist/account/requests.d.ts +11 -1
  18. package/dist/account/requests.d.ts.map +1 -1
  19. package/dist/account/requests.js +2 -1
  20. package/dist/account/requests.js.map +1 -1
  21. package/dist/backend.d.ts +7 -0
  22. package/dist/backend.d.ts.map +1 -1
  23. package/dist/backend.js.map +1 -1
  24. package/dist/card.generated.d.ts +1 -1
  25. package/dist/card.generated.js +2 -2
  26. package/dist/card.generated.js.map +1 -1
  27. package/dist/config.d.ts +4 -1
  28. package/dist/config.d.ts.map +1 -1
  29. package/dist/config.js +12 -5
  30. package/dist/config.js.map +1 -1
  31. package/dist/legal.d.ts.map +1 -1
  32. package/dist/legal.js +10 -3
  33. package/dist/legal.js.map +1 -1
  34. package/dist/otaless/addons-answers.d.ts +17 -0
  35. package/dist/otaless/addons-answers.d.ts.map +1 -0
  36. package/dist/otaless/addons-answers.js +170 -0
  37. package/dist/otaless/addons-answers.js.map +1 -0
  38. package/dist/otaless/addons.d.ts +218 -0
  39. package/dist/otaless/addons.d.ts.map +1 -0
  40. package/dist/otaless/addons.js +758 -0
  41. package/dist/otaless/addons.js.map +1 -0
  42. package/dist/otaless/booking.d.ts +64 -0
  43. package/dist/otaless/booking.d.ts.map +1 -1
  44. package/dist/otaless/booking.js +156 -0
  45. package/dist/otaless/booking.js.map +1 -1
  46. package/dist/otaless/client.d.ts +2 -0
  47. package/dist/otaless/client.d.ts.map +1 -1
  48. package/dist/otaless/client.js.map +1 -1
  49. package/dist/otaless/fake.d.ts +22 -0
  50. package/dist/otaless/fake.d.ts.map +1 -1
  51. package/dist/otaless/fake.js +40 -7
  52. package/dist/otaless/fake.js.map +1 -1
  53. package/dist/otaless/make.d.ts +4 -3
  54. package/dist/otaless/make.d.ts.map +1 -1
  55. package/dist/otaless/make.js +22 -7
  56. package/dist/otaless/make.js.map +1 -1
  57. package/dist/otaless/shop-answers.d.ts +15 -6
  58. package/dist/otaless/shop-answers.d.ts.map +1 -1
  59. package/dist/otaless/shop-answers.js +60 -26
  60. package/dist/otaless/shop-answers.js.map +1 -1
  61. package/dist/otaless/shop-fake.d.ts +31 -1
  62. package/dist/otaless/shop-fake.d.ts.map +1 -1
  63. package/dist/otaless/shop-fake.js +79 -3
  64. package/dist/otaless/shop-fake.js.map +1 -1
  65. package/dist/otaless/shop-service.d.ts +12 -6
  66. package/dist/otaless/shop-service.d.ts.map +1 -1
  67. package/dist/otaless/shop-service.js +15 -7
  68. package/dist/otaless/shop-service.js.map +1 -1
  69. package/dist/otaless/shop.d.ts +18 -9
  70. package/dist/otaless/shop.d.ts.map +1 -1
  71. package/dist/otaless/shop.js +95 -17
  72. package/dist/otaless/shop.js.map +1 -1
  73. package/dist/server.d.ts +1 -1
  74. package/dist/server.d.ts.map +1 -1
  75. package/dist/server.js +49 -5
  76. package/dist/server.js.map +1 -1
  77. package/dist/surface.js +2 -2
  78. package/dist/surface.js.map +1 -1
  79. package/dist/tools.d.ts +132 -13
  80. package/dist/tools.d.ts.map +1 -1
  81. package/dist/tools.js +268 -97
  82. package/dist/tools.js.map +1 -1
  83. package/package.json +1 -1
package/dist/tools.js CHANGED
@@ -8,6 +8,7 @@ import { DESCRIPTION_MAX, POLICY_MAX, hotelName, hotelText } from './fence.js';
8
8
  import { clockOf, minutesOf, startProblem, stayWords, windowWords } from './hourly.js';
9
9
  import { amountsIn, formatMoney, keepingAmounts, money, multiplyMoney, toMinor } from './money.js';
10
10
  import { namedExactly, roomNamesOf, roomTypeNamed, withTraditional } from './names.js';
11
+ import { cardAnswer, hotelListAnswer, prepareRefusal, preparedAnswer, } from './otaless/addons-answers.js';
11
12
  import { buyAnswer, finishAnswer, itemAnswer, listAnswer, ordersPart, previewAnswer, shopSignInAnswer, } from './otaless/shop-answers.js';
12
13
  import { looksLikeShopOrder, unitCentsOf } from './otaless/shop-service.js';
13
14
  import { overlapsOf } from './overlap.js';
@@ -195,6 +196,8 @@ export const withheldTools = (n, caps) => new Set([
195
196
  // its buy tool only where buying is open too. The names exist only with `data.otaless.shop`.
196
197
  ...(n.listShopItems && !(caps.shop && !caps.readOnly) ? [n.listShopItems] : []),
197
198
  ...(n.buyShopItem && !(caps.shop && caps.shopBuy && !caps.readOnly) ? [n.buyShopItem] : []),
199
+ // The card's own add-ons tool (0.82.0): only where the hotel's add-ons or the shop are on.
200
+ ...(n.cardAddons && !((caps.addons || caps.shop) && !caps.readOnly) ? [n.cardAddons] : []),
198
201
  // Nothing can be booked here yet (`readOnly`, Otaless 2026-11-03): no tool
199
202
  // that books, finds, changes or cancels a booking - the card's own two
200
203
  // for Reserve included, so no button that books is drawn.
@@ -1273,8 +1276,11 @@ const allTools = (n, v) => {
1273
1276
  },
1274
1277
  {
1275
1278
  name: n.addBookingAddon,
1276
- 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.",
1277
- annotations: books('Add an add-on to a booking', open),
1279
+ // ⚠️ 0.82.0: THIS TOOL NEVER ADDS ANYTHING. It prepares the add-on and answers with a one-time page
1280
+ // the GUEST opens and presses confirm on (the same press the card's button is): nothing is sent to the
1281
+ // group, and nothing is ever said to be added, until that press.
1282
+ description: 'Prepares adding one add-on to a booking made here, at the price the add-on list gave. It does NOT add it: the answer gives a one-time page address for the guest to open in the browser signed in to their account, where they see the add-on, the price, the total and the booking, and press confirm themselves. Pass that link on; never say the add-on was added until the guest has confirmed it and the booking says so. It checks the id, the details and the price again as it prepares, and refuses a booking that is not theirs or is over.',
1283
+ annotations: books('Prepare an add-on for a booking', open),
1278
1284
  inputSchema: {
1279
1285
  type: 'object',
1280
1286
  properties: {
@@ -1297,8 +1303,14 @@ const allTools = (n, v) => {
1297
1303
  quantity: {
1298
1304
  type: 'integer',
1299
1305
  minimum: 1,
1300
- maximum: 20,
1301
- description: 'How many, 1 to 20. Default 1',
1306
+ maximum: 10,
1307
+ description: 'How many, 1 to 10, for an add-on that is bought by the piece. Default 1',
1308
+ },
1309
+ partySize: {
1310
+ type: 'integer',
1311
+ minimum: 1,
1312
+ maximum: 10,
1313
+ description: 'For a transfer: how many passengers, 1 to 10. Default 1',
1302
1314
  },
1303
1315
  },
1304
1316
  required: ['booking', 'addon'],
@@ -1334,8 +1346,8 @@ const allTools = (n, v) => {
1334
1346
  ? [
1335
1347
  {
1336
1348
  name: n.buyShopItem,
1337
- description: "Orders one shop item to go with the guest's own hotel booking. It makes the order on the shop's checkout page and answers with that page's address: nothing is charged until the guest pays on that page. It checks the price against the one the guest was shown and refuses a booking that is not theirs or is over.",
1338
- annotations: orders('Order a shop item', open),
1349
+ description: "Prepares buying one shop item to go with the guest's own hotel booking. It does NOT order or charge anything: the answer gives a one-time page address for the guest to open in the browser signed in to their account, where they see the item, the quantity and the total and press confirm themselves - and when they do, the backend charges a card linked to their account, or gives a payment link if there is none. Pass that link on; never say the item was ordered or paid until the guest confirmed and the shop says so. It checks the price against the one the guest was shown and refuses a booking that is not theirs or is over.",
1350
+ annotations: books('Prepare a shop purchase', open),
1339
1351
  inputSchema: {
1340
1352
  type: 'object',
1341
1353
  properties: {
@@ -1369,6 +1381,51 @@ const allTools = (n, v) => {
1369
1381
  },
1370
1382
  ]
1371
1383
  : []),
1384
+ // ⚠️ THE CARD'S OWN STEPS FOR ADDING TO A BOOKING (0.82.0, app-only: server.ts). Every write needs the
1385
+ // guest's own press on the confirm screen: its `press` is made once per screen, and a value the
1386
+ // screen did not show is `used`. No parameter here means "confirmed" - the press is the whole yes.
1387
+ ...(n.cardAddons
1388
+ ? [
1389
+ {
1390
+ name: n.cardAddons,
1391
+ description: "The card's own add-ons steps for a booking made here: `view` reads what can be added (the hotel's own services and the shop's goods) fresh; `book_hotel_addon` and `buy_shop_item` are the guest's press on a confirm screen that showed the item, the quantity and the total - each answers with `addonResult` and a fresh `addonsView`. Never the assistant's: nothing here is called without the guest's press.",
1392
+ annotations: orders('Add to a booking', open),
1393
+ inputSchema: {
1394
+ type: 'object',
1395
+ properties: {
1396
+ action: { type: 'string', enum: ['view', 'book_hotel_addon', 'buy_shop_item'] },
1397
+ booking: {
1398
+ type: 'string',
1399
+ description: "The confirmation code of the guest's own booking",
1400
+ },
1401
+ catalogId: { type: 'string', description: 'book_hotel_addon: the add-on id' },
1402
+ direction: { type: 'string', enum: ['arrival', 'departure', 'round_trip'] },
1403
+ flightNo: { type: 'string' },
1404
+ pickupTime: { type: 'string', description: 'HH:MM' },
1405
+ date: { type: 'string', description: 'YYYY-MM-DD' },
1406
+ quantity: { type: 'integer', minimum: 1, maximum: 10 },
1407
+ partySize: { type: 'integer', minimum: 1, maximum: 10 },
1408
+ shownTotal: {
1409
+ type: 'string',
1410
+ description: 'book_hotel_addon: the total the confirm screen showed, 2 decimals',
1411
+ },
1412
+ currency: { type: 'string', description: 'The currency the screen showed' },
1413
+ item: { type: 'string', description: 'buy_shop_item: the shop item id' },
1414
+ option: { type: 'string', description: 'buy_shop_item: the option, as listed' },
1415
+ shownUnit: {
1416
+ type: 'string',
1417
+ description: 'buy_shop_item: the price of one the screen showed, 2 decimals',
1418
+ },
1419
+ press: {
1420
+ type: 'string',
1421
+ description: 'Made once per confirm screen and sent again unchanged on a retry of the same screen',
1422
+ },
1423
+ },
1424
+ required: ['action', 'booking'],
1425
+ },
1426
+ },
1427
+ ]
1428
+ : []),
1372
1429
  ];
1373
1430
  };
1374
1431
  /** A guest's reason for a refund, as the group's staff are sent it (`otaless/booking.ts`). */
@@ -1735,8 +1792,11 @@ const BOOKING_SCHEMA = {
1735
1792
  */
1736
1793
  export const buildOutputSchemas = (n) => {
1737
1794
  const base = baseOutputSchemas(n);
1738
- if (!n.listShopItems)
1795
+ if (!n.listShopItems && !n.cardAddons)
1739
1796
  return base;
1797
+ // Only the add-ons card tool (no shop): its own schema, and nothing else touched.
1798
+ if (!n.listShopItems)
1799
+ return { ...base, ...shopSchemas(n) };
1740
1800
  const widen = (name, views, more) => {
1741
1801
  const s = base[name];
1742
1802
  if (!s)
@@ -1774,6 +1834,24 @@ export const buildOutputSchemas = (n) => {
1774
1834
  };
1775
1835
  /** The shop tools' answers. */
1776
1836
  const shopSchemas = (n) => ({
1837
+ ...(n.cardAddons
1838
+ ? {
1839
+ [n.cardAddons]: {
1840
+ type: 'object',
1841
+ properties: {
1842
+ view: { enum: ['addons', 'error'] },
1843
+ brand: STR,
1844
+ toolNames: OBJ,
1845
+ bookingMode: STR,
1846
+ addonsView: OBJ,
1847
+ addonResult: OBJ,
1848
+ error: STR,
1849
+ detail: STR,
1850
+ },
1851
+ required: ['view'],
1852
+ },
1853
+ }
1854
+ : {}),
1777
1855
  ...(n.listShopItems
1778
1856
  ? {
1779
1857
  [n.listShopItems]: {
@@ -1800,10 +1878,11 @@ const shopSchemas = (n) => ({
1800
1878
  [n.buyShopItem]: {
1801
1879
  type: 'object',
1802
1880
  properties: {
1803
- view: { enum: ['shop-buy', 'error'] },
1881
+ view: { enum: ['shop-buy', 'addon-confirm', 'error'] },
1804
1882
  brand: STR,
1805
1883
  toolNames: OBJ,
1806
1884
  bookingMode: STR,
1885
+ confirm: OBJ,
1807
1886
  outcome: STR,
1808
1887
  order: OBJ,
1809
1888
  checkoutUrl: STR,
@@ -2021,13 +2100,14 @@ const baseOutputSchemas = (n) => ({
2021
2100
  [n.addBookingAddon]: {
2022
2101
  type: 'object',
2023
2102
  properties: {
2024
- view: { enum: ['booking-addon', 'booking-not-found', 'error'] },
2103
+ view: { enum: ['booking-addon', 'addon-confirm', 'booking-not-found', 'error'] },
2025
2104
  brand: STR,
2026
2105
  toolNames: OBJ,
2027
2106
  bookingMode: STR,
2028
2107
  demo: BOOL,
2029
2108
  booking: STR,
2030
2109
  addon: OBJ,
2110
+ confirm: OBJ,
2031
2111
  query: STR,
2032
2112
  error: STR,
2033
2113
  detail: STR,
@@ -2754,9 +2834,15 @@ const common = (deps, key) => {
2754
2834
  ...(deps.primary ? { primary: deps.primary } : {}),
2755
2835
  ...(deps.fonts ? { fonts: deps.fonts } : {}),
2756
2836
  ...(deps.showName ? { showName: true } : {}),
2757
- toolNames: deps.offered
2758
- ? Object.fromEntries(Object.entries(deps.tools).filter(([, name]) => deps.offered?.has(name)))
2759
- : deps.tools,
2837
+ toolNames: (() => {
2838
+ const names = deps.offered
2839
+ ? Object.fromEntries(Object.entries(deps.tools).filter(([, name]) => deps.offered?.has(name)))
2840
+ : { ...deps.tools };
2841
+ // 0.82.0 (contract with the card): the card-only add-ons tool is `toolNames.addonsCard`, only
2842
+ // where it exists - every other deployment's map is exactly what it was.
2843
+ const card = deps.tools.cardAddons;
2844
+ return card && names.cardAddons ? { ...names, addonsCard: card } : names;
2845
+ })(),
2760
2846
  bookingMode: caps.booking,
2761
2847
  // In a market each group says whether it needs a phone (`market.suppliers`).
2762
2848
  ...(caps.requiresPhone && !deps.backend.suppliers ? { phoneRequired: true } : {}),
@@ -4190,6 +4276,16 @@ const hostOf = (url) => {
4190
4276
  return undefined;
4191
4277
  }
4192
4278
  };
4279
+ /**
4280
+ * No confirm page can be made for the guest (not signed in to the account, too many links just now,
4281
+ * or no account page here): nothing was prepared, and it is said so - the add-on is never done any
4282
+ * other way.
4283
+ */
4284
+ const noConfirmPage = (base) => ({
4285
+ structured: { view: 'error', ...base, error: 'no-confirm-page' },
4286
+ text: "Nothing was prepared: a one-time page for the guest to confirm on could not be made (they must be signed in to their account here, and not asked for too many links at once). Nothing was added, ordered or charged - and it is never done without the guest's own confirm.",
4287
+ isError: true,
4288
+ });
4193
4289
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
4194
4290
  /**
4195
4291
  * A moment as a clock time with its offset - "17:30 UTC+08:00, 10 Nov" - never
@@ -8838,9 +8934,10 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8838
8934
  : 'the group has taken the request.'}`,
8839
8935
  };
8840
8936
  }
8841
- // The add-on shop (`capabilities.shop`): goods beside the rooms - read here, bought only where buying
8842
- // is open. Text and structure, no card. Every rule about money is in otaless/shop.ts and
8843
- // shop-service.ts; this only asks and words the answer.
8937
+ // The add-on shop (`capabilities.shop`): goods beside the rooms - read here; BOUGHT only by the guest's
8938
+ // own confirm (0.82.0): the card's press (`cardAddons`) or the one-time page the buy tool PREPARES.
8939
+ // Text and structure, no card. Every rule about money is in otaless/shop.ts, shop-service.ts and
8940
+ // addons.ts; this only asks and words the answer.
8844
8941
  if (t.listShopItems && name === t.listShopItems) {
8845
8942
  const shop = deps.backend.otalessShop;
8846
8943
  const base = common(deps, key);
@@ -8853,7 +8950,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8853
8950
  const lang = deps.lang === 'zh' ? 'zh' : 'en';
8854
8951
  const item = str(args.item);
8855
8952
  if (item)
8856
- return itemAnswer(base, await shop.item(item, lang), item, shop.buyOpen);
8953
+ return itemAnswer(base, await shop.item(item, lang), item, shop.buyOpen, deps.shopLink);
8857
8954
  const query = str(args.query).slice(0, 100);
8858
8955
  const category = str(args.category).slice(0, 60);
8859
8956
  const maxPrice = typeof args.maxPrice === 'number' && Number.isFinite(args.maxPrice) && args.maxPrice >= 0
@@ -8865,105 +8962,162 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8865
8962
  ...(maxPrice !== undefined ? { maxPrice } : {}),
8866
8963
  lang,
8867
8964
  });
8868
- return listAnswer(base, found, { ...(query ? { query } : {}), ...(category ? { category } : {}), maxPrice }, shop.buyOpen);
8965
+ return listAnswer(base, found, { ...(query ? { query } : {}), ...(category ? { category } : {}), maxPrice }, shop.buyOpen, deps.shopLink);
8869
8966
  }
8967
+ // ⚠️ NEVER BUYS (0.82.0): it checks the item, the booking and the price the guest was shown, and
8968
+ // PREPARES a one-time confirm page. The purchase is the guest's press on that page.
8870
8969
  if (t.buyShopItem && name === t.buyShopItem) {
8871
- const shop = deps.backend.otalessShop;
8970
+ const api = deps.backend.otalessAddons;
8872
8971
  const base = common(deps, key);
8873
- const used = { ordersTool: t.listBookings, signIn: deps.groupSignIn?.signInTool };
8874
- if (!shop?.buyOpen)
8972
+ const used = {
8973
+ ordersTool: t.listBookings,
8974
+ signIn: deps.groupSignIn?.signInTool,
8975
+ ...(deps.shopLink ? { shopLink: deps.shopLink } : {}),
8976
+ };
8977
+ if (!api?.buyOpen)
8875
8978
  return buyAnswer(base, { outcome: 'off' }, used);
8876
8979
  const unitCents = unitCentsOf(args.unitPrice);
8877
8980
  const currency = str(args.currency).toUpperCase();
8878
- // ⚠️ THE PRICE THE GUEST WAS SHOWN IS PART OF THE ASK: without it nothing is sent.
8981
+ // ⚠️ THE PRICE THE GUEST WAS SHOWN IS PART OF THE ASK: without it nothing is prepared.
8879
8982
  if (unitCents === undefined || !/^[A-Z]{3}$/.test(currency))
8880
8983
  return buyAnswer(base, { outcome: 'refused', why: 'shown' }, used);
8881
- const answer = await shop.buy(identity(deps, ctx, key), {
8882
- itemId: str(args.item),
8984
+ const lang = deps.lang === 'zh' ? 'zh' : 'en';
8985
+ const who = identity(deps, ctx, key);
8986
+ const prepared = await api.prepareShop(who, {
8987
+ item: str(args.item),
8883
8988
  ...(str(args.option) ? { option: str(args.option) } : {}),
8884
8989
  quantity: typeof args.quantity === 'number' ? args.quantity : 0,
8885
8990
  booking: str(args.booking),
8886
- unitCents,
8991
+ unitPrice: (unitCents / 100).toFixed(2),
8887
8992
  currency,
8888
- lang: deps.lang === 'zh' ? 'zh' : 'en',
8889
- });
8890
- return buyAnswer(base, answer, used);
8993
+ }, lang);
8994
+ if (!prepared.ok)
8995
+ return prepareRefusal(base, str(args.booking), prepared.result, deps.shopLink);
8996
+ const link = deps.addonLink?.(key, prepared.ref, lang);
8997
+ if (!link) {
8998
+ api.discard(who, prepared.ref);
8999
+ return noConfirmPage(base);
9000
+ }
9001
+ return preparedAnswer(base, prepared, link, (iso) => clockWords(iso) ?? iso);
8891
9002
  }
8892
- // What can be added to a booking after it is made, and adding one: text and
8893
- // structure, no card. The id is the one the list gave - the backend checks it
8894
- // was listed for this very booking a moment ago.
9003
+ // The card's own add-ons steps (0.82.0, app-only): the guest's press on a confirm screen. ⚠️ NO
9004
+ // PARAMETER MEANS "CONFIRMED" EXCEPT THE `press` THE CARD MADE FOR THAT SCREEN, with the values it
9005
+ // showed; a client that draws no card is refused (server.ts keeps it from the model of one that does).
9006
+ if (t.cardAddons && name === t.cardAddons) {
9007
+ const base = common(deps, key);
9008
+ if (ctx.noCards)
9009
+ return {
9010
+ structured: { view: 'error', ...base, error: 'card-only' },
9011
+ text: `${t.cardAddons} is the booking card's own: add-ons are confirmed by the guest, on the page ${t.addBookingAddon ?? t.buyShopItem ?? 'the add-on tools'} gives them - never in the chat.`,
9012
+ isError: true,
9013
+ };
9014
+ const api = deps.backend.otalessAddons;
9015
+ if (!api)
9016
+ return {
9017
+ structured: { view: 'error', ...base, error: 'not-offered' },
9018
+ text: `Add-ons are not offered through ${deps.vocab.brand}.`,
9019
+ isError: true,
9020
+ };
9021
+ const who = identity(deps, ctx, key);
9022
+ const lang = deps.lang === 'zh' ? 'zh' : 'en';
9023
+ const booking = str(args.booking);
9024
+ const action = str(args.action);
9025
+ const num = (v) => typeof v === 'number' && Number.isFinite(v) ? v : undefined;
9026
+ let result;
9027
+ if (action === 'book_hotel_addon') {
9028
+ const dir = str(args.direction);
9029
+ result = await api.bookHotel(who, {
9030
+ booking,
9031
+ catalogId: str(args.catalogId),
9032
+ ...(dir === 'arrival' || dir === 'departure' || dir === 'round_trip'
9033
+ ? { direction: dir }
9034
+ : dir
9035
+ ? { direction: dir }
9036
+ : {}),
9037
+ ...(str(args.flightNo) ? { flightNo: str(args.flightNo) } : {}),
9038
+ ...(str(args.pickupTime) ? { pickupTime: str(args.pickupTime) } : {}),
9039
+ ...(str(args.date) ? { date: str(args.date) } : {}),
9040
+ ...(num(args.quantity) !== undefined ? { quantity: num(args.quantity) } : {}),
9041
+ ...(num(args.partySize) !== undefined ? { partySize: num(args.partySize) } : {}),
9042
+ shownTotal: str(args.shownTotal),
9043
+ currency: str(args.currency).toUpperCase(),
9044
+ press: str(args.press),
9045
+ });
9046
+ }
9047
+ else if (action === 'buy_shop_item') {
9048
+ result = await api.buyShop(who, {
9049
+ booking,
9050
+ item: str(args.item),
9051
+ ...(str(args.option) ? { option: str(args.option) } : {}),
9052
+ quantity: num(args.quantity) ?? 0,
9053
+ shownUnit: str(args.shownUnit),
9054
+ currency: str(args.currency).toUpperCase(),
9055
+ press: str(args.press),
9056
+ }, lang);
9057
+ }
9058
+ else if (action !== 'view') {
9059
+ return {
9060
+ structured: { view: 'error', ...base, error: 'bad-input' },
9061
+ text: 'action is view, book_hotel_addon or buy_shop_item.',
9062
+ isError: true,
9063
+ };
9064
+ }
9065
+ // Every answer carries the view as it is NOW - after a write too.
9066
+ const fresh = await api.view(who, booking, lang);
9067
+ return cardAnswer(base, fresh, result);
9068
+ }
9069
+ // What can be added to a booking after it is made: text and structure, no card. The id is the one
9070
+ // the list gave. ⚠️ NEITHER TOOL ADDS ANYTHING (0.82.0): the list reads, the other PREPARES a one-time page.
8895
9071
  if (name === t.listBookingAddons) {
8896
- const ot = deps.backend.otalessBooking;
9072
+ const api = deps.backend.otalessAddons;
8897
9073
  const ref = str(args.booking);
8898
- const found = ot ? await ot.addons(ref, identity(deps, ctx, key)) : null;
8899
- if (!found) {
9074
+ const base = common(deps, key);
9075
+ if (!api?.hotelOn)
8900
9076
  return {
8901
- structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
8902
- text: 'No booking here matches that code. Only bookings made here by this account have add-ons to list.',
9077
+ structured: { view: 'error', ...base, error: 'not-offered' },
9078
+ text: 'Nothing can be added to a booking here.',
9079
+ isError: true,
8903
9080
  };
8904
- }
8905
- const needs = (e) => e.kind === 'transfer'
8906
- ? 'needs direction (arrival, departure or round_trip), flightNo, pickupTime (HH:MM) and date (YYYY-MM-DD)'
8907
- : 'needs a date (YYYY-MM-DD) and a quantity, if more than one';
8908
- return {
8909
- structured: {
8910
- view: 'booking-addons',
8911
- ...common(deps, key),
8912
- booking: ref,
8913
- addons: found.map((e) => ({
8914
- id: e.id,
8915
- name: e.name,
8916
- kind: e.kind,
8917
- description: e.description,
8918
- price: formatMoney(e.price),
8919
- per: e.per,
8920
- needs: needs(e),
8921
- })),
8922
- },
8923
- text: found.length
8924
- ? [
8925
- `Add-ons for ${ref}:`,
8926
- ...found.map((e) => `- ${e.name} (id \`${e.id}\`) — ${formatMoney(e.price)} ${unitWords(e.per)}; ${needs(e)}${e.description ? `. ${e.description}` : ''}`),
8927
- ].join('\n')
8928
- : `Nothing can be added to ${ref} just now.`,
8929
- };
9081
+ return hotelListAnswer(base, ref, await api.view(identity(deps, ctx, key), ref, deps.lang === 'zh' ? 'zh' : 'en'), {
9082
+ add: t.addBookingAddon,
9083
+ });
8930
9084
  }
8931
9085
  if (name === t.addBookingAddon) {
8932
- const ot = deps.backend.otalessBooking;
9086
+ const api = deps.backend.otalessAddons;
8933
9087
  const ref = str(args.booking);
8934
- const addon = str(args.addon);
8935
- const direction = ['arrival', 'departure', 'round_trip'].includes(str(args.direction))
8936
- ? str(args.direction)
8937
- : undefined;
8938
- const done = ot
8939
- ? await ot.bookAddon(ref, addon, {
8940
- ...(direction ? { direction } : {}),
8941
- ...(str(args.flightNo) ? { flightNo: str(args.flightNo) } : {}),
8942
- ...(str(args.pickupTime) ? { pickupTime: str(args.pickupTime) } : {}),
8943
- ...(str(args.date) ? { date: str(args.date) } : {}),
8944
- ...(typeof args.quantity === 'number' ? { quantity: args.quantity } : {}),
8945
- }, identity(deps, ctx, key))
8946
- : null;
8947
- if (!done) {
9088
+ const base = common(deps, key);
9089
+ if (!api?.hotelOn)
8948
9090
  return {
8949
- structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
8950
- text: 'No booking here matches that code. Only bookings made here by this account can have an add-on.',
9091
+ structured: { view: 'error', ...base, error: 'not-offered' },
9092
+ text: 'Nothing can be added to a booking here.',
9093
+ isError: true,
8951
9094
  };
9095
+ const dir = str(args.direction);
9096
+ const lang = deps.lang === 'zh' ? 'zh' : 'en';
9097
+ const who = identity(deps, ctx, key);
9098
+ const num = (v) => typeof v === 'number' && Number.isFinite(v) ? v : undefined;
9099
+ const prepared = await api.prepareHotel(who, {
9100
+ booking: ref,
9101
+ catalogId: str(args.addon),
9102
+ ...(dir === 'arrival' || dir === 'departure' || dir === 'round_trip'
9103
+ ? { direction: dir }
9104
+ : dir
9105
+ ? { direction: dir }
9106
+ : {}),
9107
+ ...(str(args.flightNo) ? { flightNo: str(args.flightNo) } : {}),
9108
+ ...(str(args.pickupTime) ? { pickupTime: str(args.pickupTime) } : {}),
9109
+ ...(str(args.date) ? { date: str(args.date) } : {}),
9110
+ ...(num(args.quantity) !== undefined ? { quantity: num(args.quantity) } : {}),
9111
+ ...(num(args.partySize) !== undefined ? { partySize: num(args.partySize) } : {}),
9112
+ }, lang);
9113
+ if (!prepared.ok)
9114
+ return prepareRefusal(base, ref, prepared.result, deps.shopLink);
9115
+ const link = deps.addonLink?.(key, prepared.ref, lang);
9116
+ if (!link) {
9117
+ api.discard(who, prepared.ref);
9118
+ return noConfirmPage(base);
8952
9119
  }
8953
- return {
8954
- structured: {
8955
- view: 'booking-addon',
8956
- ...common(deps, key),
8957
- booking: ref,
8958
- addon: {
8959
- id: addon,
8960
- code: done.code,
8961
- status: done.status,
8962
- ...(done.total ? { total: formatMoney(done.total) } : {}),
8963
- },
8964
- },
8965
- text: `Added to ${ref}: add-on order ${done.code}, ${done.status || 'taken'}${done.total ? `, ${formatMoney(done.total)}` : ''}.`,
8966
- };
9120
+ return preparedAnswer(base, prepared, link, (iso) => clockWords(iso) ?? iso);
8967
9121
  }
8968
9122
  if (name === t.listBookings) {
8969
9123
  const who = identity(deps, ctx, key, args);
@@ -8993,14 +9147,21 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8993
9147
  // The add-on shop's orders, after the hotel bookings (`capabilities.shop`; nothing without it).
8994
9148
  // Not with a code asked for: that looks for one hotel booking.
8995
9149
  const shopApi = deps.backend.otalessShop;
9150
+ // ⚠️ ADD-ONS (0.82.0): only where `addons` or the shop is on, and only for a live booking of this account.
9151
+ const addonsApi = deps.backend.otalessAddons;
9152
+ const addable = addonsApi ? bookings.filter((b) => addonsApi.canAdd(b)) : [];
8996
9153
  const shopPart = shopApi && !code
8997
- ? ordersPart(await shopApi.orders(who, deps.lang === 'zh' ? 'zh' : 'en'))
9154
+ ? ordersPart(await shopApi.orders(who, deps.lang === 'zh' ? 'zh' : 'en'), deps.shopLink)
8998
9155
  : undefined;
8999
9156
  return {
9000
9157
  structured: {
9001
9158
  view: 'bookings',
9002
9159
  ...common(deps, key),
9003
- bookings: bookings.map((b) => listedForCard(deps, b)),
9160
+ bookings: bookings.map((b) => ({
9161
+ ...listedForCard(deps, b),
9162
+ // 0.82.0: a live booking of this account can have add-ons added (the card's button).
9163
+ ...(addable.includes(b) ? { addons: true } : {}),
9164
+ })),
9004
9165
  count: bookings.length,
9005
9166
  ...(shopPart?.structured ?? {}),
9006
9167
  // What was looked for, so a card can say THAT did not match rather
@@ -9022,6 +9183,16 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
9022
9183
  ? 'No bookings on this account.'
9023
9184
  : 'No bookings in this conversation. A booking made elsewhere is found with its confirmation code and the email it was made with.',
9024
9185
  missing.said,
9186
+ addable.length
9187
+ ? `Add-ons can be added to ${addable.map((b) => b.confirmationCode).join(', ')}: ${[
9188
+ deps.backend.capabilities?.addons && t.listBookingAddons
9189
+ ? `${t.listBookingAddons} lists the hotel's own services`
9190
+ : '',
9191
+ shopApi && t.listShopItems ? `${t.listShopItems} lists the shop's goods` : '',
9192
+ ]
9193
+ .filter(Boolean)
9194
+ .join('; ')}. The guest confirms each one on a page it gives them - nothing is added by the assistant.`
9195
+ : '',
9025
9196
  shopPart?.text ?? '',
9026
9197
  ]
9027
9198
  .filter(Boolean)
@@ -9279,12 +9450,12 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
9279
9450
  const shopLang = deps.lang === 'zh' ? 'zh' : 'en';
9280
9451
  const shopMine = shopApi && looksLikeShopOrder(ref) ? await shopApi.mine(who, ref, shopLang) : false;
9281
9452
  if (shopMine === 'shop-sign-in')
9282
- return shopSignInAnswer(common(deps, key));
9453
+ return shopSignInAnswer(common(deps, key), deps.shopLink);
9283
9454
  if (shopApi && shopMine) {
9284
9455
  const base = common(deps, key);
9285
9456
  if (name === t.previewCancellation || args.confirmed !== true)
9286
- return previewAnswer(base, await shopApi.preview(who, ref.trim(), shopLang), t.cancelBooking, (iso) => clockWords(iso) ?? iso);
9287
- return finishAnswer(base, await shopApi.finish(who, ref.trim(), shopLang), t.previewCancellation, t.listBookings);
9457
+ return previewAnswer(base, await shopApi.preview(who, ref.trim(), shopLang), t.cancelBooking, (iso) => clockWords(iso) ?? iso, deps.shopLink);
9458
+ return finishAnswer(base, await shopApi.finish(who, ref.trim(), shopLang), t.previewCancellation, t.listBookings, deps.shopLink);
9288
9459
  }
9289
9460
  const { found: preview, tooMany } = await guarded(deps, ctx, who, ref, () => deps.backend.previewCancellation(ref, who));
9290
9461
  if (!preview) {