@curless/hotel-storefront 0.80.3 → 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 (106) 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 +54 -0
  6. package/dist/account/index.d.ts.map +1 -1
  7. package/dist/account/index.js +719 -61
  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 +39 -4
  14. package/dist/account/pages.d.ts.map +1 -1
  15. package/dist/account/pages.js +104 -42
  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/account/wallet-pages.d.ts +84 -0
  22. package/dist/account/wallet-pages.d.ts.map +1 -0
  23. package/dist/account/wallet-pages.js +229 -0
  24. package/dist/account/wallet-pages.js.map +1 -0
  25. package/dist/account/wallet.d.ts +163 -0
  26. package/dist/account/wallet.d.ts.map +1 -0
  27. package/dist/account/wallet.js +365 -0
  28. package/dist/account/wallet.js.map +1 -0
  29. package/dist/backend.d.ts +25 -0
  30. package/dist/backend.d.ts.map +1 -1
  31. package/dist/backend.js.map +1 -1
  32. package/dist/card-v168.generated.d.ts +6 -0
  33. package/dist/card-v168.generated.d.ts.map +1 -0
  34. package/dist/card-v168.generated.js +10 -0
  35. package/dist/card-v168.generated.js.map +1 -0
  36. package/dist/card.generated.d.ts +1 -1
  37. package/dist/card.generated.js +2 -2
  38. package/dist/card.generated.js.map +1 -1
  39. package/dist/config.d.ts +51 -2
  40. package/dist/config.d.ts.map +1 -1
  41. package/dist/config.js +21 -1
  42. package/dist/config.js.map +1 -1
  43. package/dist/legal.d.ts.map +1 -1
  44. package/dist/legal.js +33 -4
  45. package/dist/legal.js.map +1 -1
  46. package/dist/otaless/addons-answers.d.ts +17 -0
  47. package/dist/otaless/addons-answers.d.ts.map +1 -0
  48. package/dist/otaless/addons-answers.js +170 -0
  49. package/dist/otaless/addons-answers.js.map +1 -0
  50. package/dist/otaless/addons.d.ts +218 -0
  51. package/dist/otaless/addons.d.ts.map +1 -0
  52. package/dist/otaless/addons.js +758 -0
  53. package/dist/otaless/addons.js.map +1 -0
  54. package/dist/otaless/booking.d.ts +64 -0
  55. package/dist/otaless/booking.d.ts.map +1 -1
  56. package/dist/otaless/booking.js +156 -0
  57. package/dist/otaless/booking.js.map +1 -1
  58. package/dist/otaless/client.d.ts +111 -0
  59. package/dist/otaless/client.d.ts.map +1 -1
  60. package/dist/otaless/client.js +44 -4
  61. package/dist/otaless/client.js.map +1 -1
  62. package/dist/otaless/fake.d.ts +114 -0
  63. package/dist/otaless/fake.d.ts.map +1 -1
  64. package/dist/otaless/fake.js +305 -7
  65. package/dist/otaless/fake.js.map +1 -1
  66. package/dist/otaless/make.d.ts +41 -1
  67. package/dist/otaless/make.d.ts.map +1 -1
  68. package/dist/otaless/make.js +165 -2
  69. package/dist/otaless/make.js.map +1 -1
  70. package/dist/otaless/shop-answers.d.ts +81 -0
  71. package/dist/otaless/shop-answers.d.ts.map +1 -0
  72. package/dist/otaless/shop-answers.js +378 -0
  73. package/dist/otaless/shop-answers.js.map +1 -0
  74. package/dist/otaless/shop-client.d.ts +133 -0
  75. package/dist/otaless/shop-client.d.ts.map +1 -0
  76. package/dist/otaless/shop-client.js +201 -0
  77. package/dist/otaless/shop-client.js.map +1 -0
  78. package/dist/otaless/shop-fake.d.ts +130 -0
  79. package/dist/otaless/shop-fake.d.ts.map +1 -0
  80. package/dist/otaless/shop-fake.js +335 -0
  81. package/dist/otaless/shop-fake.js.map +1 -0
  82. package/dist/otaless/shop-service.d.ts +111 -0
  83. package/dist/otaless/shop-service.d.ts.map +1 -0
  84. package/dist/otaless/shop-service.js +195 -0
  85. package/dist/otaless/shop-service.js.map +1 -0
  86. package/dist/otaless/shop.d.ts +169 -0
  87. package/dist/otaless/shop.d.ts.map +1 -0
  88. package/dist/otaless/shop.js +793 -0
  89. package/dist/otaless/shop.js.map +1 -0
  90. package/dist/otaless/wallet.d.ts +160 -0
  91. package/dist/otaless/wallet.d.ts.map +1 -0
  92. package/dist/otaless/wallet.js +650 -0
  93. package/dist/otaless/wallet.js.map +1 -0
  94. package/dist/server.d.ts +14 -3
  95. package/dist/server.d.ts.map +1 -1
  96. package/dist/server.js +89 -16
  97. package/dist/server.js.map +1 -1
  98. package/dist/surface.d.ts +7 -0
  99. package/dist/surface.d.ts.map +1 -1
  100. package/dist/surface.js +15 -1
  101. package/dist/surface.js.map +1 -1
  102. package/dist/tools.d.ts +223 -99
  103. package/dist/tools.d.ts.map +1 -1
  104. package/dist/tools.js +484 -75
  105. package/dist/tools.js.map +1 -1
  106. package/package.json +1 -1
package/dist/tools.js CHANGED
@@ -8,6 +8,9 @@ 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';
12
+ import { buyAnswer, finishAnswer, itemAnswer, listAnswer, ordersPart, previewAnswer, shopSignInAnswer, } from './otaless/shop-answers.js';
13
+ import { looksLikeShopOrder, unitCentsOf } from './otaless/shop-service.js';
11
14
  import { overlapsOf } from './overlap.js';
12
15
  import { MAX_COMPARED, MAX_CONS, MAX_DAYS, MAX_ITEMS_PER_DAY, MAX_MOMENTS, MAX_PROS, buildItinerary, candidatesFor, compareHotels, namesMoreThanOne, nightlyIncludesTaxes, } from './present.js';
13
16
  import { withReference } from './reference.js';
@@ -189,6 +192,12 @@ export const withheldTools = (n, caps) => new Set([
189
192
  // now says that), so a guest - or a model - never has two ways out of one booking.
190
193
  n.refundBooking,
191
194
  ...(caps.addons && !caps.readOnly ? [] : [n.listBookingAddons, n.addBookingAddon]),
195
+ // The add-on shop (`capabilities.shop`, docs §17.6): its listing where the deployment has it, and
196
+ // its buy tool only where buying is open too. The names exist only with `data.otaless.shop`.
197
+ ...(n.listShopItems && !(caps.shop && !caps.readOnly) ? [n.listShopItems] : []),
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] : []),
192
201
  // Nothing can be booked here yet (`readOnly`, Otaless 2026-11-03): no tool
193
202
  // that books, finds, changes or cancels a booking - the card's own two
194
203
  // for Reserve included, so no button that books is drawn.
@@ -1267,8 +1276,11 @@ const allTools = (n, v) => {
1267
1276
  },
1268
1277
  {
1269
1278
  name: n.addBookingAddon,
1270
- 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.",
1271
- 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),
1272
1284
  inputSchema: {
1273
1285
  type: 'object',
1274
1286
  properties: {
@@ -1291,13 +1303,129 @@ const allTools = (n, v) => {
1291
1303
  quantity: {
1292
1304
  type: 'integer',
1293
1305
  minimum: 1,
1294
- maximum: 20,
1295
- 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',
1296
1314
  },
1297
1315
  },
1298
1316
  required: ['booking', 'addon'],
1299
1317
  },
1300
1318
  },
1319
+ // The add-on shop (`capabilities.shop`): goods sold beside the rooms. Not instructions - what the tools do.
1320
+ ...(n.listShopItems
1321
+ ? [
1322
+ {
1323
+ name: n.listShopItems,
1324
+ description: "The add-on goods in Otaless's shop - things to buy for a stay, not rooms - each with its id, name, price and currency, whether it is available and its options. With `item` it opens one item. It only reads the shop; nothing is ordered.",
1325
+ annotations: reads('Shop items', open),
1326
+ inputSchema: {
1327
+ type: 'object',
1328
+ properties: {
1329
+ query: { type: 'string', description: 'Words in the item name' },
1330
+ category: { type: 'string', description: "One of the shop's categories" },
1331
+ maxPrice: {
1332
+ type: 'number',
1333
+ minimum: 0,
1334
+ description: "The highest price, in the shop's currency (US dollars)",
1335
+ },
1336
+ item: {
1337
+ type: 'string',
1338
+ description: 'An item id, as this tool listed it, for that one item in detail',
1339
+ },
1340
+ },
1341
+ },
1342
+ },
1343
+ ]
1344
+ : []),
1345
+ ...(n.buyShopItem
1346
+ ? [
1347
+ {
1348
+ name: n.buyShopItem,
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),
1351
+ inputSchema: {
1352
+ type: 'object',
1353
+ properties: {
1354
+ item: { type: 'string', description: 'The item id, as the shop listing gave it' },
1355
+ option: {
1356
+ type: 'string',
1357
+ description: "One of the item's options, exactly as listed - for an item that has options",
1358
+ },
1359
+ quantity: {
1360
+ type: 'integer',
1361
+ minimum: 1,
1362
+ maximum: 10,
1363
+ description: 'How many, 1 to 10',
1364
+ },
1365
+ booking: {
1366
+ type: 'string',
1367
+ description: "The confirmation code of the guest's own hotel booking this goes with",
1368
+ },
1369
+ unitPrice: {
1370
+ type: 'number',
1371
+ exclusiveMinimum: 0,
1372
+ description: 'The price of one, as the guest was shown it',
1373
+ },
1374
+ currency: {
1375
+ type: 'string',
1376
+ description: 'Its currency code, as the guest was shown it',
1377
+ },
1378
+ },
1379
+ required: ['item', 'quantity', 'booking', 'unitPrice', 'currency'],
1380
+ },
1381
+ },
1382
+ ]
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
+ : []),
1301
1429
  ];
1302
1430
  };
1303
1431
  /** A guest's reason for a refund, as the group's staff are sent it (`otaless/booking.ts`). */
@@ -1657,7 +1785,123 @@ const BOOKING_SCHEMA = {
1657
1785
  },
1658
1786
  required: ['view'],
1659
1787
  };
1660
- export const buildOutputSchemas = (n) => ({
1788
+ /**
1789
+ * ⚠️ ONLY WHERE THE SHOP'S NAMES EXIST (`data.otaless.shop`): its two tools' schemas, and the
1790
+ * shop views a bookings list and a cancellation may also answer with. Everywhere else the schemas
1791
+ * are the ones above, untouched.
1792
+ */
1793
+ export const buildOutputSchemas = (n) => {
1794
+ const base = baseOutputSchemas(n);
1795
+ if (!n.listShopItems && !n.cardAddons)
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) };
1800
+ const widen = (name, views, more) => {
1801
+ const s = base[name];
1802
+ if (!s)
1803
+ return;
1804
+ base[name] = {
1805
+ ...s,
1806
+ properties: {
1807
+ ...s.properties,
1808
+ view: { enum: [...(s.properties.view?.enum ?? []), ...views] },
1809
+ ...more,
1810
+ },
1811
+ };
1812
+ };
1813
+ widen(n.listBookings, [], {
1814
+ shopOrders: ARR,
1815
+ shopOrdersUnavailable: BOOL,
1816
+ shopOrdersNeedShopSignIn: BOOL,
1817
+ });
1818
+ const cancelMore = {
1819
+ shopOrder: OBJ,
1820
+ kind: STR,
1821
+ charged: STR,
1822
+ refund: STR,
1823
+ refundMinor: { type: 'number' },
1824
+ shopSaidMinor: { type: 'number' },
1825
+ pointsTakenBack: BOOL,
1826
+ until: STR,
1827
+ toolToConfirm: STR,
1828
+ done: STR,
1829
+ };
1830
+ const cancelViews = ['shop-order-preview', 'shop-order-done', 'shop-order-unknown'];
1831
+ widen(n.previewCancellation, cancelViews, cancelMore);
1832
+ widen(n.cancelBooking, cancelViews, cancelMore);
1833
+ return { ...base, ...shopSchemas(n) };
1834
+ };
1835
+ /** The shop tools' answers. */
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
+ : {}),
1855
+ ...(n.listShopItems
1856
+ ? {
1857
+ [n.listShopItems]: {
1858
+ type: 'object',
1859
+ properties: {
1860
+ view: { enum: ['shop-items', 'shop-item', 'shop-item-not-found', 'error'] },
1861
+ brand: STR,
1862
+ toolNames: OBJ,
1863
+ bookingMode: STR,
1864
+ items: ARR,
1865
+ item: OBJ,
1866
+ count: { type: 'number' },
1867
+ buyOpen: BOOL,
1868
+ query: STR,
1869
+ error: STR,
1870
+ detail: STR,
1871
+ },
1872
+ required: ['view'],
1873
+ },
1874
+ }
1875
+ : {}),
1876
+ ...(n.buyShopItem
1877
+ ? {
1878
+ [n.buyShopItem]: {
1879
+ type: 'object',
1880
+ properties: {
1881
+ view: { enum: ['shop-buy', 'addon-confirm', 'error'] },
1882
+ brand: STR,
1883
+ toolNames: OBJ,
1884
+ bookingMode: STR,
1885
+ confirm: OBJ,
1886
+ outcome: STR,
1887
+ order: OBJ,
1888
+ checkoutUrl: STR,
1889
+ checkoutHost: STR,
1890
+ now: OBJ,
1891
+ cancelled: BOOL,
1892
+ needsPerson: BOOL,
1893
+ overShown: BOOL,
1894
+ charged: STR,
1895
+ orderId: STR,
1896
+ error: STR,
1897
+ detail: STR,
1898
+ },
1899
+ required: ['view'],
1900
+ },
1901
+ }
1902
+ : {}),
1903
+ });
1904
+ const baseOutputSchemas = (n) => ({
1661
1905
  [n.listHotels]: {
1662
1906
  type: 'object',
1663
1907
  properties: {
@@ -1856,13 +2100,14 @@ export const buildOutputSchemas = (n) => ({
1856
2100
  [n.addBookingAddon]: {
1857
2101
  type: 'object',
1858
2102
  properties: {
1859
- view: { enum: ['booking-addon', 'booking-not-found', 'error'] },
2103
+ view: { enum: ['booking-addon', 'addon-confirm', 'booking-not-found', 'error'] },
1860
2104
  brand: STR,
1861
2105
  toolNames: OBJ,
1862
2106
  bookingMode: STR,
1863
2107
  demo: BOOL,
1864
2108
  booking: STR,
1865
2109
  addon: OBJ,
2110
+ confirm: OBJ,
1866
2111
  query: STR,
1867
2112
  error: STR,
1868
2113
  detail: STR,
@@ -2589,9 +2834,15 @@ const common = (deps, key) => {
2589
2834
  ...(deps.primary ? { primary: deps.primary } : {}),
2590
2835
  ...(deps.fonts ? { fonts: deps.fonts } : {}),
2591
2836
  ...(deps.showName ? { showName: true } : {}),
2592
- toolNames: deps.offered
2593
- ? Object.fromEntries(Object.entries(deps.tools).filter(([, name]) => deps.offered?.has(name)))
2594
- : 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
+ })(),
2595
2846
  bookingMode: caps.booking,
2596
2847
  // In a market each group says whether it needs a phone (`market.suppliers`).
2597
2848
  ...(caps.requiresPhone && !deps.backend.suppliers ? { phoneRequired: true } : {}),
@@ -4025,6 +4276,16 @@ const hostOf = (url) => {
4025
4276
  return undefined;
4026
4277
  }
4027
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
+ });
4028
4289
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
4029
4290
  /**
4030
4291
  * A moment as a clock time with its offset - "17:30 UTC+08:00, 10 Nov" - never
@@ -8673,81 +8934,190 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8673
8934
  : 'the group has taken the request.'}`,
8674
8935
  };
8675
8936
  }
8676
- // What can be added to a booking after it is made, and adding one: text and
8677
- // structure, no card. The id is the one the list gave - the backend checks it
8678
- // was listed for this very booking a moment ago.
8679
- if (name === t.listBookingAddons) {
8680
- const ot = deps.backend.otalessBooking;
8681
- const ref = str(args.booking);
8682
- const found = ot ? await ot.addons(ref, identity(deps, ctx, key)) : null;
8683
- if (!found) {
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.
8941
+ if (t.listShopItems && name === t.listShopItems) {
8942
+ const shop = deps.backend.otalessShop;
8943
+ const base = common(deps, key);
8944
+ if (!shop)
8684
8945
  return {
8685
- structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
8686
- text: 'No booking here matches that code. Only bookings made here by this account have add-ons to list.',
8946
+ structured: { view: 'error', ...base, error: 'not-offered' },
8947
+ text: `There is no shop through ${deps.vocab.brand}.`,
8948
+ isError: true,
8687
8949
  };
8688
- }
8689
- const needs = (e) => e.kind === 'transfer'
8690
- ? 'needs direction (arrival, departure or round_trip), flightNo, pickupTime (HH:MM) and date (YYYY-MM-DD)'
8691
- : 'needs a date (YYYY-MM-DD) and a quantity, if more than one';
8692
- return {
8693
- structured: {
8694
- view: 'booking-addons',
8695
- ...common(deps, key),
8696
- booking: ref,
8697
- addons: found.map((e) => ({
8698
- id: e.id,
8699
- name: e.name,
8700
- kind: e.kind,
8701
- description: e.description,
8702
- price: formatMoney(e.price),
8703
- per: e.per,
8704
- needs: needs(e),
8705
- })),
8706
- },
8707
- text: found.length
8708
- ? [
8709
- `Add-ons for ${ref}:`,
8710
- ...found.map((e) => `- ${e.name} (id \`${e.id}\`) — ${formatMoney(e.price)} ${unitWords(e.per)}; ${needs(e)}${e.description ? `. ${e.description}` : ''}`),
8711
- ].join('\n')
8712
- : `Nothing can be added to ${ref} just now.`,
8950
+ const lang = deps.lang === 'zh' ? 'zh' : 'en';
8951
+ const item = str(args.item);
8952
+ if (item)
8953
+ return itemAnswer(base, await shop.item(item, lang), item, shop.buyOpen, deps.shopLink);
8954
+ const query = str(args.query).slice(0, 100);
8955
+ const category = str(args.category).slice(0, 60);
8956
+ const maxPrice = typeof args.maxPrice === 'number' && Number.isFinite(args.maxPrice) && args.maxPrice >= 0
8957
+ ? args.maxPrice
8958
+ : undefined;
8959
+ const found = await shop.items({
8960
+ ...(query ? { keyword: query } : {}),
8961
+ ...(category ? { category } : {}),
8962
+ ...(maxPrice !== undefined ? { maxPrice } : {}),
8963
+ lang,
8964
+ });
8965
+ return listAnswer(base, found, { ...(query ? { query } : {}), ...(category ? { category } : {}), maxPrice }, shop.buyOpen, deps.shopLink);
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.
8969
+ if (t.buyShopItem && name === t.buyShopItem) {
8970
+ const api = deps.backend.otalessAddons;
8971
+ const base = common(deps, key);
8972
+ const used = {
8973
+ ordersTool: t.listBookings,
8974
+ signIn: deps.groupSignIn?.signInTool,
8975
+ ...(deps.shopLink ? { shopLink: deps.shopLink } : {}),
8713
8976
  };
8977
+ if (!api?.buyOpen)
8978
+ return buyAnswer(base, { outcome: 'off' }, used);
8979
+ const unitCents = unitCentsOf(args.unitPrice);
8980
+ const currency = str(args.currency).toUpperCase();
8981
+ // ⚠️ THE PRICE THE GUEST WAS SHOWN IS PART OF THE ASK: without it nothing is prepared.
8982
+ if (unitCents === undefined || !/^[A-Z]{3}$/.test(currency))
8983
+ return buyAnswer(base, { outcome: 'refused', why: 'shown' }, used);
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),
8988
+ ...(str(args.option) ? { option: str(args.option) } : {}),
8989
+ quantity: typeof args.quantity === 'number' ? args.quantity : 0,
8990
+ booking: str(args.booking),
8991
+ unitPrice: (unitCents / 100).toFixed(2),
8992
+ currency,
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);
8714
9002
  }
8715
- if (name === t.addBookingAddon) {
8716
- const ot = deps.backend.otalessBooking;
8717
- const ref = str(args.booking);
8718
- const addon = str(args.addon);
8719
- const direction = ['arrival', 'departure', 'round_trip'].includes(str(args.direction))
8720
- ? str(args.direction)
8721
- : undefined;
8722
- const done = ot
8723
- ? await ot.bookAddon(ref, addon, {
8724
- ...(direction ? { direction } : {}),
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
+ : {}),
8725
9037
  ...(str(args.flightNo) ? { flightNo: str(args.flightNo) } : {}),
8726
9038
  ...(str(args.pickupTime) ? { pickupTime: str(args.pickupTime) } : {}),
8727
9039
  ...(str(args.date) ? { date: str(args.date) } : {}),
8728
- ...(typeof args.quantity === 'number' ? { quantity: args.quantity } : {}),
8729
- }, identity(deps, ctx, key))
8730
- : null;
8731
- if (!done) {
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') {
8732
9059
  return {
8733
- structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
8734
- text: 'No booking here matches that code. Only bookings made here by this account can have an add-on.',
9060
+ structured: { view: 'error', ...base, error: 'bad-input' },
9061
+ text: 'action is view, book_hotel_addon or buy_shop_item.',
9062
+ isError: true,
8735
9063
  };
8736
9064
  }
8737
- return {
8738
- structured: {
8739
- view: 'booking-addon',
8740
- ...common(deps, key),
8741
- booking: ref,
8742
- addon: {
8743
- id: addon,
8744
- code: done.code,
8745
- status: done.status,
8746
- ...(done.total ? { total: formatMoney(done.total) } : {}),
8747
- },
8748
- },
8749
- text: `Added to ${ref}: add-on order ${done.code}, ${done.status || 'taken'}${done.total ? `, ${formatMoney(done.total)}` : ''}.`,
8750
- };
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.
9071
+ if (name === t.listBookingAddons) {
9072
+ const api = deps.backend.otalessAddons;
9073
+ const ref = str(args.booking);
9074
+ const base = common(deps, key);
9075
+ if (!api?.hotelOn)
9076
+ return {
9077
+ structured: { view: 'error', ...base, error: 'not-offered' },
9078
+ text: 'Nothing can be added to a booking here.',
9079
+ isError: true,
9080
+ };
9081
+ return hotelListAnswer(base, ref, await api.view(identity(deps, ctx, key), ref, deps.lang === 'zh' ? 'zh' : 'en'), {
9082
+ add: t.addBookingAddon,
9083
+ });
9084
+ }
9085
+ if (name === t.addBookingAddon) {
9086
+ const api = deps.backend.otalessAddons;
9087
+ const ref = str(args.booking);
9088
+ const base = common(deps, key);
9089
+ if (!api?.hotelOn)
9090
+ return {
9091
+ structured: { view: 'error', ...base, error: 'not-offered' },
9092
+ text: 'Nothing can be added to a booking here.',
9093
+ isError: true,
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);
9119
+ }
9120
+ return preparedAnswer(base, prepared, link, (iso) => clockWords(iso) ?? iso);
8751
9121
  }
8752
9122
  if (name === t.listBookings) {
8753
9123
  const who = identity(deps, ctx, key, args);
@@ -8774,12 +9144,26 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8774
9144
  : code && !str(args.email)
8775
9145
  ? 'A booking made elsewhere needs the email it was made with as well as its code.'
8776
9146
  : 'No booking matches that confirmation code and email. Both are needed, as they are on the confirmation.';
9147
+ // The add-on shop's orders, after the hotel bookings (`capabilities.shop`; nothing without it).
9148
+ // Not with a code asked for: that looks for one hotel booking.
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)) : [];
9153
+ const shopPart = shopApi && !code
9154
+ ? ordersPart(await shopApi.orders(who, deps.lang === 'zh' ? 'zh' : 'en'), deps.shopLink)
9155
+ : undefined;
8777
9156
  return {
8778
9157
  structured: {
8779
9158
  view: 'bookings',
8780
9159
  ...common(deps, key),
8781
- 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
+ })),
8782
9165
  count: bookings.length,
9166
+ ...(shopPart?.structured ?? {}),
8783
9167
  // What was looked for, so a card can say THAT did not match rather
8784
9168
  // than "nothing in this conversation".
8785
9169
  ...(missed ? { notFound: code, notFoundLine: missLine } : {}),
@@ -8799,6 +9183,17 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8799
9183
  ? 'No bookings on this account.'
8800
9184
  : 'No bookings in this conversation. A booking made elsewhere is found with its confirmation code and the email it was made with.',
8801
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
+ : '',
9196
+ shopPart?.text ?? '',
8802
9197
  ]
8803
9198
  .filter(Boolean)
8804
9199
  .join('\n'),
@@ -9048,6 +9443,20 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
9048
9443
  if (name === t.previewCancellation || name === t.cancelBooking) {
9049
9444
  const ref = str(args.booking);
9050
9445
  const who = identity(deps, ctx, key, args);
9446
+ // ⚠️ A SHOP ORDER, NOT A HOTEL BOOKING: a UUID-shaped id that THIS account's shop orders hold
9447
+ // (`looksLikeShopOrder` - no hotel order id has that shape - and then `mine`). The same two steps:
9448
+ // what it would do, then the cancel or the refund that was shown - see shop-service.ts.
9449
+ const shopApi = deps.backend.otalessShop;
9450
+ const shopLang = deps.lang === 'zh' ? 'zh' : 'en';
9451
+ const shopMine = shopApi && looksLikeShopOrder(ref) ? await shopApi.mine(who, ref, shopLang) : false;
9452
+ if (shopMine === 'shop-sign-in')
9453
+ return shopSignInAnswer(common(deps, key), deps.shopLink);
9454
+ if (shopApi && shopMine) {
9455
+ const base = common(deps, key);
9456
+ if (name === t.previewCancellation || args.confirmed !== true)
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);
9459
+ }
9051
9460
  const { found: preview, tooMany } = await guarded(deps, ctx, who, ref, () => deps.backend.previewCancellation(ref, who));
9052
9461
  if (!preview) {
9053
9462
  return {