@curless/hotel-storefront 0.59.0 → 0.60.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.
package/dist/tools.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { aboutLines } from './about.js';
2
2
  import { DEFAULT_PAGE, FULL_CAPABILITIES, LASTING_REQUESTS, MAX_PAGE, REQUEST_KINDS, REQUEST_NOTE_MAX, guestTooLong, notPricedForNoAnswer, unansweredBy, unitWords, } from './backend.js';
3
+ import { PAY_WORDS, allOrEach, choiceBlock, payOf, paymentOf, saysOwn, sentenceOf, setsApart, sharedBy, spreadOf, } from './choices.js';
3
4
  import { usedOnWords } from './coupon-words.js';
4
5
  import { MAX_GUESTS, addDays, dateOptions, dayWords, isDay, nights as nightsBetween, stayDayWords, toDay, weekendOf, weekendWords, } from './dates.js';
5
6
  import { FACILITIES } from './facilities.js';
@@ -168,6 +169,16 @@ export const withheldTools = (n, caps) => new Set([
168
169
  * answer that would otherwise say how to book.
169
170
  */
170
171
  export const readOnlyWords = (v) => `Nothing can be booked through ${v.brand} yet: it shows ${v.noun}s, rooms and prices only. When the guest wants to book, say so plainly - nothing is booked or held - and suggest booking with the ${v.noun}'s own group directly, on its website or app, with the ${v.noun}, room and dates from here.`;
172
+ /**
173
+ * Said with every price where nothing can be booked yet (`capabilities.readOnly`;
174
+ * 总线程 11-09, Manus on Otaless after 0.59.0): asked for a hotel's rooms after a
175
+ * comparison, the model answered from the comparison - which said nothing of
176
+ * it - and called them "两种可订房型", with nowhere to book. On a list, a hotel's
177
+ * page, a comparison and a plan, in the text and, word for word, in the
178
+ * structure (`notBookable`); what `readOnlyWords` tells it to do when the guest
179
+ * asks to book, in one sentence.
180
+ */
181
+ export const notBookableWords = (v) => `Nothing can be booked through ${v.brand} yet: never call a ${v.noun}, room or rate here bookable (可订) - to book, the guest uses the ${v.noun}'s own group, on its website or app, with the ${v.noun}, room and dates from here.`;
171
182
  const forCapabilities = (tools, n, v, caps) => {
172
183
  const withheld = withheldTools(n, caps);
173
184
  const without = (schema, ...keys) => {
@@ -2817,6 +2828,8 @@ const waysOnWords = (group, atHotel) => `give the ways on in the same reply, nev
2817
2828
  * structure (`noRooms`): the model reads the structure.
2818
2829
  */
2819
2830
  export const notOnSaleWords = (group, why) => `${why.replace(/[.\s]+$/, '')} - ${NOT_SOLD_OUT}. To book it, the guest can use ${group}'s own channels: its app, its website or by phone.`;
2831
+ /** `notBookableWords` where nothing can be booked here, else nothing - see there. */
2832
+ const notBookableOf = (deps) => (deps.backend.capabilities ?? FULL_CAPABILITIES).readOnly ? notBookableWords(deps.vocab) : '';
2820
2833
  /** The group a hotel is with, by name - the deployment's own brand outside a market. */
2821
2834
  const groupNameOf = (deps, hotelId) => holderOf(deps, deps.backend.supplierOf?.(hotelId)).name;
2822
2835
  /** A rate's cancellation terms in the supplier's own words (`Room.terms`), quoted - or that none were given. */
@@ -2906,73 +2919,167 @@ const breakfastColumn = (r) => {
2906
2919
  const said = (r.labels ?? []).find((l) => l.startsWith('breakfast'));
2907
2920
  return said ? LABEL_WORDS[said] : facetsOf(r).breakfast ? 'breakfast included' : 'no breakfast';
2908
2921
  };
2909
- /** A rate's labels other than its breakfast - " [promotion, paid in advance - not booked here]" - or nothing. */
2910
- const otherLabelWords = (r) => labelWords({ ...r, labels: (r.labels ?? []).filter((l) => !isMealLabel(l)) });
2922
+ /** A rate's labels other than its breakfast and its payment - "booked-ahead rate" - as words. */
2923
+ const otherLabelsOf = (r) => (r.labels ?? [])
2924
+ .filter((l) => !isMealLabel(l))
2925
+ .map((l) => LABEL_WORDS[l])
2926
+ .join(', ');
2911
2927
  /**
2912
2928
  * A hotel's rooms for the nights as the numbered choices a client that draws no
2913
- * card tells the guest (robin 11-06: 「房型选择…看看有没有办法在文字版优化下」).
2929
+ * card tells the guest (robin 11-06: 「房型选择…看看有没有办法在文字版优化下」;
2930
+ * as paragraphs since robin 11-09 - see choices.ts).
2931
+ *
2932
+ * One choice per ROOM TYPE, cheapest first, at its lowest rate, with how many
2933
+ * other rates the type has: what the card shows a guest who can tap, in lines
2934
+ * they can answer with a number. The room id `addToTrip` takes for that number
2935
+ * is not in them: the ids follow, in one line of their own (`idsByNumber`).
2936
+ * Every type is in the answer, numbered, so "the sixth" is one the model can
2937
+ * name when the guest asks for the rest; the guest is shown the first
2938
+ * `ROOM_CHOICES_SHOWN`, and the others as a count.
2914
2939
  *
2915
- * One row per ROOM TYPE, cheapest first - name · bed · breakfast · cancelling ·
2916
- * the whole stay's total - at its lowest rate, with how many other rates the
2917
- * type has: what the card shows a guest who can tap, in a line they can answer
2918
- * with its number. The room id `addToTrip` takes for that number is not on
2919
- * the line: the ids follow the lines, in one line of their own (`idsByNumber`). Every row is in the answer, numbered, so "the sixth" is a row
2920
- * the model can name when the guest asks for the rest; the guest is shown the
2921
- * first `ROOM_CHOICES_SHOWN`, and the others as a count.
2940
+ * What every type has - its breakfast, its terms, its price, its other rates,
2941
+ * how it is paid - is said once before them (`said`), and what most have once
2942
+ * as what holds unless one says otherwise; each type says only what sets it
2943
+ * apart (robin 11-09: the same sentence five times over, on Huazhu's five).
2922
2944
  *
2923
- * ⚠️ HOW IT IS PAID STAYS ON THE ROW (2026-11-02 audit, P1-5): a rate paid in
2924
- * advance cannot be booked here, and a row that said only its price would let
2925
- * the model offer it.
2945
+ * ⚠️ HOW EACH IS PAID CAN BE TOLD (2026-11-02 audit, P1-5): see `paymentOf`.
2926
2946
  */
2927
- const roomChoiceRows = (rooms, roomsWanted) => byRoomType(rooms)
2928
- .map((type) => ({
2929
- type,
2930
- r: type.rooms.reduce((a, b) => (b.stayTotal.minor < a.stayTotal.minor ? b : a)),
2931
- }))
2932
- .sort((a, b) => a.r.stayTotal.minor - b.r.stayTotal.minor)
2933
- .map(({ type, r }, i) => {
2934
- const others = type.rooms.length - 1;
2935
- const more = others
2936
- ? `${others} more ${others === 1 ? 'rate' : 'rates'} on this room type`
2937
- : '';
2947
+ const roomChoicesBlock = (rooms, roomsWanted,
2948
+ /** The group a stay paid in advance is booked with instead. */
2949
+ group,
2950
+ /** Nothing can be booked here (`capabilities.readOnly`): said once, and no payment told apart. */
2951
+ readOnly = false) => {
2952
+ const rows = byRoomType(rooms)
2953
+ .map((type) => ({
2954
+ type,
2955
+ r: type.rooms.reduce((a, b) => (b.stayTotal.minor < a.stayTotal.minor ? b : a)),
2956
+ }))
2957
+ .sort((a, b) => a.r.stayTotal.minor - b.r.stayTotal.minor)
2958
+ .map(({ type, r }) => ({ type, r, others: type.rooms.length - 1 }));
2959
+ const many = roomsWanted > 1;
2960
+ const price = (r) => r.hourly
2961
+ ? `${formatMoney(r.stayTotal)} for ${r.hourly.hours} hours`
2962
+ : many
2963
+ ? `${formatMoney(multiplyMoney(r.stayTotal, roomsWanted))} for ${roomsWanted} rooms`
2964
+ : formatMoney(r.stayTotal);
2938
2965
  // ⚠️ "BEFORE TAXES" ONLY WHERE IT IS SO (0.55.3): see `nightlyIncludesTaxes`.
2939
- const night = nightWords(true, nightlyIncludesTaxes(r));
2940
- const total = r.hourly
2941
- ? `${priceWords(r, true)}${more ? ` (${more})` : ''}`
2942
- : `${roomsWanted > 1
2943
- ? `${formatMoney(multiplyMoney(r.stayTotal, roomsWanted))} for ${roomsWanted} rooms, for the stay incl. taxes and fees (${formatMoney(r.nightly)} ${night} a room`
2944
- : `${formatMoney(r.stayTotal)} for the stay incl. taxes and fees (${formatMoney(r.nightly)} ${night}`}${more ? `; ${more}` : ''})`;
2966
+ const nightly = (r) => r.hourly
2967
+ ? ''
2968
+ : `${formatMoney(r.nightly)} ${nightWords(true, nightlyIncludesTaxes(r))}${many ? ', per room' : ''}`;
2969
+ const more = (n) => n ? `${n} more ${n === 1 ? 'rate' : 'rates'} on this room type` : '';
2970
+ // Breakfast and terms are said for most as "unless one says otherwise"; the
2971
+ // rest only where every one is the same.
2972
+ const spread = {
2973
+ beds: allOrEach(spreadOf(rows.map(({ r }) => r.beds ?? ''))),
2974
+ breakfast: spreadOf(rows.map(({ r }) => breakfastColumn(r))),
2975
+ cancel: spreadOf(rows.map(({ r }) => cancelWords(r))),
2976
+ labels: allOrEach(spreadOf(rows.map(({ r }) => otherLabelsOf(r)))),
2977
+ nightly: allOrEach(spreadOf(rows.map(({ r }) => nightly(r)))),
2978
+ more: allOrEach(spreadOf(rows.map(({ others }) => String(others)))),
2979
+ price: allOrEach(spreadOf(rows.map(({ r }) => price(r)))),
2980
+ };
2981
+ const pay = readOnly
2982
+ ? { said: '', tags: [] }
2983
+ : paymentOf(rows.map(({ r }) => payOf(r)), 'room', group);
2984
+ const lowest = Math.min(...rows.map(({ r }) => r.stayTotal.minor));
2985
+ const apart = {
2986
+ cheapest: setsApart(rows.map(({ r }) => !r.hourly && r.stayTotal.minor === lowest)),
2987
+ breakfast: setsApart(rows.map(({ r }) => facetsOf(r).breakfast)),
2988
+ free: setsApart(rows.map(({ r }) => facetsOf(r).freeCancellation)),
2989
+ family: setsApart(rows.map(({ r }) => r.sleeps >= FAMILY_SLEEPS)),
2990
+ };
2991
+ const blocks = rows.map(({ type, r, others }, i) => {
2992
+ const family = r.sleeps >= FAMILY_SLEEPS ? `sleeps ${r.sleeps}` : '';
2993
+ const beds = saysOwn(spread.beds, r.beds ?? '') ? (r.beds ?? '') : '';
2994
+ return choiceBlock(i + 1, {
2995
+ title: withZh(type.name, r.roomType ? r.roomType.names : r.names, true),
2996
+ sentence: sentenceOf([
2997
+ // A room for a family says so: "three of us" is chosen by it.
2998
+ [beds, family]
2999
+ .filter(Boolean)
3000
+ .join(', '),
3001
+ saysOwn(spread.breakfast, breakfastColumn(r)) ? breakfastColumn(r) : '',
3002
+ saysOwn(spread.cancel, cancelWords(r)) ? cancelWords(r) : '',
3003
+ saysOwn(spread.labels, otherLabelsOf(r)) ? otherLabelsOf(r) : '',
3004
+ rows.length < 2 && !readOnly ? PAY_WORDS[payOf(r)] : '',
3005
+ r.hourly
3006
+ ? `starting between ${r.hourly.earliestStart} and ${r.hourly.latestStart} today, out by ${r.hourly.latestEnd}`
3007
+ : '',
3008
+ [
3009
+ saysOwn(spread.nightly, nightly(r)) ? nightly(r) : '',
3010
+ saysOwn(spread.more, String(others)) ? more(others) : '',
3011
+ ]
3012
+ .filter(Boolean)
3013
+ .join('; '),
3014
+ ]),
3015
+ tags: [
3016
+ pay.tags[i] ?? '',
3017
+ apart.cheapest && r.stayTotal.minor === lowest ? 'Cheapest' : '',
3018
+ apart.breakfast && facetsOf(r).breakfast ? 'Breakfast' : '',
3019
+ apart.free && facetsOf(r).freeCancellation ? 'Free cancellation' : '',
3020
+ apart.family && r.sleeps >= FAMILY_SLEEPS ? `Sleeps ${r.sleeps}` : '',
3021
+ ].filter(Boolean),
3022
+ price: price(r),
3023
+ });
3024
+ });
3025
+ // What every one has, and what most have, said once before them.
3026
+ const first = rows[0]?.r;
3027
+ const samePrice = sharedBy(spread.price);
3028
+ const shared = [
3029
+ sharedBy(spread.beds),
3030
+ sharedBy(spread.breakfast),
3031
+ sharedBy(spread.cancel),
3032
+ sharedBy(spread.labels),
3033
+ samePrice ? '' : sharedBy(spread.nightly),
3034
+ sharedBy(spread.more) && sharedBy(spread.more) !== '0'
3035
+ ? `${sharedBy(spread.more)} more ${sharedBy(spread.more) === '1' ? 'rate' : 'rates'} on each`
3036
+ : '',
3037
+ ].filter(Boolean);
3038
+ const most = [spread.breakfast, spread.cancel]
3039
+ .map((s) => (s.kind === 'most' ? s.value : ''))
3040
+ .filter(Boolean);
3041
+ const said = [
3042
+ first?.hourly
3043
+ ? "Prices are for each room's hours, taxes and fees included."
3044
+ : samePrice && rows.length > 1
3045
+ ? `All ${rows.length} are ${samePrice}${many ? '' : ' for the stay'}, taxes and fees included${sharedBy(spread.nightly) ? ` (${sharedBy(spread.nightly)})` : ''}.`
3046
+ : many
3047
+ ? `Prices are for ${roomsWanted} rooms for the whole stay, taxes and fees included.`
3048
+ : 'Prices are for the stay, taxes and fees included.',
3049
+ shared.length ? `Every one: ${shared.join('; ')}.` : '',
3050
+ most.length ? `Unless a room says otherwise: ${most.join('; ')}.` : '',
3051
+ pay.said,
3052
+ readOnly
3053
+ ? `Nothing can be booked here yet: to book, use these rooms and dates with ${group}, on its own website or app.`
3054
+ : '',
3055
+ ]
3056
+ .filter(Boolean)
3057
+ .join(' ');
2945
3058
  return {
2946
- line: `${i + 1}. ${[
2947
- withZh(type.name, r.roomType ? r.roomType.names : r.names, true),
2948
- r.beds,
2949
- // A room for a family says so: "three of us" is chosen by it.
2950
- r.sleeps >= FAMILY_SLEEPS ? `sleeps ${r.sleeps}` : '',
2951
- breakfastColumn(r),
2952
- cancelWords(r),
2953
- total,
2954
- ]
2955
- .filter(Boolean)
2956
- .join(' · ')}${otherLabelWords(r)}`,
2957
- id: r.id,
3059
+ said,
3060
+ blocks,
3061
+ ids: rows.map(({ r }) => r.id),
3062
+ notes: rows.map(({ r }) => readOnly ? '' : r.notSoldHere ? 'paid in advance - not booked here' : ''),
2958
3063
  };
2959
- });
3064
+ };
2960
3065
  /**
2961
- * The ids behind numbered lines, in one line after them (总线程 11-09): with the
3066
+ * The ids behind numbered choices, in one line after them (总线程 11-09): with the
2962
3067
  * id on each line - "— room `x`" - the model was to copy the line and drop its
2963
3068
  * end, and on Manus it rewrote the lines and dropped the numbers instead. The
2964
- * lines are now the guest's as they stand; this line is the model's.
3069
+ * choices are the guest's as they stand; this line is the model's - and it
3070
+ * marks each one not booked here too (P1-5), where the choices may say it once
3071
+ * for all.
2965
3072
  */
2966
- const idsByNumber = (what, ids, from = 1) => `${what} ids by number, for your calls - never for the guest: ${ids
2967
- .map((id, i) => `${from + i} = \`${id}\``)
3073
+ const idsByNumber = (what, ids, from = 1, notes = []) => `${what} ids by number, for your calls - never for the guest: ${ids
3074
+ .map((id, i) => `${from + i} = \`${id}\`${notes[i] ? ` (${notes[i]})` : ''}`)
2968
3075
  .join('; ')}.`;
2969
3076
  /**
2970
- * What the assistant is told to do with `roomChoiceRows` - in the text and,
2971
- * word for word, in the structure (`roomChoices`): the model reads the structure.
3077
+ * What the assistant is told to do with the choices - in the text and, word for
3078
+ * word, in the structure (`roomChoices`): the model reads the structure.
2972
3079
  */
2973
- const roomChoicesLead = (types, when) => `Say the dates first, as they are here - ${when} - then copy the numbered lines below into your reply as they stand, one line each, each starting with its number ("1.")${types === 1 ? ' - the one line too, as "1."' : ''}; in the guest's language, with every number and figure kept - ${types > ROOM_CHOICES_SHOWN
3080
+ const roomChoicesLead = (types, when) => `Say the dates first, as they are here - ${when} - then copy what follows into your reply as it stands, in this order: the sentence of what the rooms share, then each room as its own lines - its number and name in bold ("**1. …**"${types === 1 ? ', the one room too' : ''}), the sentence of what sets it apart where there is one, and its tags ending in its price - with a blank line between rooms. In the guest's language, with every number and figure kept and nothing added; never a table, and nothing said again on a room that the sentence before them says - ${types > ROOM_CHOICES_SHOWN
2974
3081
  ? `the first ${ROOM_CHOICES_SHOWN}, then "${types - ROOM_CHOICES_SHOWN} more room ${types - ROOM_CHOICES_SHOWN === 1 ? 'type' : 'types'}" in one line (the rest are below, for a guest who asks)`
2975
- : 'every one'}. The guest answers with a number or by describing one: a number is that line's room, by the ids after the lines.`;
3082
+ : 'every one'}. The guest answers with a number or by describing one: a number is that room, by the ids after the rooms.`;
2976
3083
  /**
2977
3084
  * Today at a hotel, for the dates offered to a guest who named none: its own
2978
3085
  * date where the backend gives it (`todayThere`); else the sun's, from where it
@@ -3005,27 +3112,32 @@ numbers) => {
3005
3112
  .join(', or ')}, or dates of their own. Do not number those: the numbers are the ${numbers}'. Never ask for dates before showing the ${numbers}; a guest who names other nights is asked again with them.`;
3006
3113
  };
3007
3114
  /**
3008
- * The lead and the numbered rows - in the text and, word for word, in `roomChoices`.
3115
+ * The lead, what the rooms share and the choices - in the text and, word for
3116
+ * word, in `roomChoices`.
3009
3117
  *
3010
3118
  * ⚠️ WHAT CANNOT BE BOOKED HERE IS SAID BEFORE THE LIST (robin's Manus run, 11-06,
3011
3119
  * via 总线程): nine Huazhu rates, every one paid in advance, and "none of these can
3012
- * be booked here" came after all of them. `before` is that sentence, first.
3120
+ * be booked here" came after all of them. `before` is that sentence, first; the
3121
+ * sentence of what the rooms share says it to the guest.
3013
3122
  */
3014
- const roomChoicesOf = (rooms, roomsWanted, when, before) => {
3015
- const rows = roomChoiceRows(rooms, roomsWanted);
3123
+ const roomChoicesOf = (rooms, roomsWanted, when, before, group, readOnly = false) => {
3124
+ const c = roomChoicesBlock(rooms, roomsWanted, group, readOnly);
3016
3125
  return [
3017
3126
  ...(before ? [before] : []),
3018
- roomChoicesLead(rows.length, when),
3019
- ...rows.map((r) => r.line),
3020
- idsByNumber('Room', rows.map((r) => r.id)),
3127
+ roomChoicesLead(c.blocks.length, when),
3128
+ ...(c.said ? [c.said] : []),
3129
+ // The blank lines are in the strings: the text's lines are joined after
3130
+ // empty ones are dropped, and the text and `roomChoices` say the same.
3131
+ `\n${c.blocks.join('\n\n')}`,
3132
+ `\n${idsByNumber('Room', c.ids, 1, c.notes)}`,
3021
3133
  ];
3022
3134
  };
3023
- /** The sentence said before the rooms where some - or all - of them are paid in advance and not booked here. */
3135
+ /** What is said before the rooms where some - or all - of them are paid in advance and not booked here. */
3024
3136
  const notSoldFirst = (rooms, notSold) => !notSold
3025
3137
  ? ''
3026
3138
  : rooms.length > 0 && rooms.every((r) => r.notSoldHere)
3027
- ? `Every rate here for these nights is paid in advance, so none of them can be booked here yet and none is paid at the hotel - say that first, before the list. ${notSold}`
3028
- : `${notSold} Say it before the list.`;
3139
+ ? `Every rate here for these nights is paid in advance, so none of them can be booked here yet and none is paid at the hotel - the sentence before the rooms says so; keep it first. ${notSold}`
3140
+ : `${notSold} The sentence before the rooms says which are not bookable here; keep it before them.`;
3029
3141
  /**
3030
3142
  * What a hotel's rooms look like to the assistant for the nights: one line per
3031
3143
  * type, and with filters only the rates that meet ALL of them. None meeting
@@ -3043,11 +3155,15 @@ saidWhen,
3043
3155
  * What is said before the list to a client that draws no card: rates paid in
3044
3156
  * advance (`notSoldFirst`), and other arrivals that cost less (`dateFlex`).
3045
3157
  */
3046
- before) => {
3158
+ before,
3159
+ /** The group a stay paid in advance is booked with instead - see `paymentOf`. */
3160
+ group = '',
3161
+ /** Nothing can be booked here - see `roomChoicesBlock`. */
3162
+ readOnly = false) => {
3047
3163
  // A type with several rates is priced from its cheapest: say how to reach another.
3048
3164
  const lines = (rs) => [
3049
3165
  ...(noCards
3050
- ? roomChoicesOf(rs, roomsWanted, saidWhen ?? when, before)
3166
+ ? roomChoicesOf(rs, roomsWanted, saidWhen ?? when, before, group, readOnly)
3051
3167
  : roomTypeLines(rs, roomsWanted, terms)),
3052
3168
  ...(byRoomType(rs).some((t) => t.rooms.length > 1)
3053
3169
  ? [
@@ -4182,76 +4298,72 @@ export const HOTEL_CHOICES_SHOWN = 6;
4182
4298
  // a model handed one Huazhu hotel wrote it as a sentence with no number, and the
4183
4299
  // guest's next 「第1家」 had nothing to point at. The lines are the guest's as
4184
4300
  // they stand, a single one included; the ids are after them, for the model.
4185
- export const LIST_NOT_DRAWN = `Nothing was drawn: this app shows no cards, so the guest has seen none of these hotels. Copy the numbered lines below into your reply as they stand, in this order and with these numbers, each starting with its number ("1.") - a single line too, as "1."; in the guest's language, with every figure kept and nothing that is not in them - at most ${HOTEL_CHOICES_SHOWN}, and any more as a count the guest can ask for, never a pick of your own. The guest answers with a number or a name; the ids after the lines are for your calls:`;
4301
+ export const LIST_NOT_DRAWN = `Nothing was drawn: this app shows no cards, so the guest has seen none of these hotels. Copy what follows into your reply as it stands, in this order and with these numbers: the sentence of what the hotels share where there is one, then each hotel as its own lines - its number and name in bold ("**1. …**", a single hotel too), the sentence of what sets it apart, and its tags ending in its price - with a blank line between hotels. In the guest's language, with every figure kept and nothing that is not in them; never a table, and nothing said again on a hotel that the sentence before them says - at most ${HOTEL_CHOICES_SHOWN}, and any more as a count the guest can ask for, never a pick of your own. The guest answers with a number or a name; the ids after the hotels are for your calls:`;
4186
4302
  /**
4187
- * One hotel of a list as a line, for a client that shows no cards.
4303
+ * A list's hotels as the numbered choices a client that shows no cards tells
4304
+ * the guest - one paragraph each (robin 11-09; see choices.ts): its name; a
4305
+ * sentence of where it is, its group where the name does not carry it, its
4306
+ * rating, a few of its own facilities and the room it is priced at; two tags
4307
+ * at most and its price. What every hotel here has - the same facilities, the
4308
+ * same terms, how the prices are paid - is said once before them.
4309
+ *
4310
+ * ⚠️ ONLY WHAT THE GROUP SAYS OF IT (总线程 11-06): never a word the data does not
4311
+ * carry - a distance is not given, so "nearest" is not said.
4188
4312
  *
4189
- * ⚠️ WHETHER IT CAN BE BOOKED HERE IS ON THE LINE (2026-11-02 audit, P1-5): a
4313
+ * ⚠️ WHETHER EACH PRICE CAN BE BOOKED HERE CAN BE TOLD (2026-11-02 audit, P1-5): a
4190
4314
  * Huazhu hotel whose only rate tonight is paid in advance was listed as
4191
- * "¥783.02 for the stay", with the sentence that such rates are not booked
4192
- * here said once at the top - a model reading the line could tell the guest it
4193
- * can be booked. Each priced line says how its rate is paid and what it costs
4194
- * to cancel, as the card's tile does.
4315
+ * "¥783.02 for the stay" - a model reading the line could tell the guest it can
4316
+ * be booked. See `paymentOf`.
4195
4317
  */
4196
- const listedInWords = (h, n, tags = []) => {
4197
- const where = [h.area, h.city]
4318
+ const hotelChoicesBlock = (hotels,
4319
+ /** The first hotel's number less one - a list is numbered across its pages. */
4320
+ offset,
4321
+ /** The group a hotel is with, in a market - its name is ours, not the backend's code. */
4322
+ groupOf,
4323
+ /** The group a price paid in advance is booked with instead. */
4324
+ group,
4325
+ /** Nothing can be booked here (`capabilities.readOnly`): said once, and no payment told apart. */
4326
+ readOnly = false) => {
4327
+ const n = hotels.length;
4328
+ const key = (x) => x.toLowerCase().replace(/[^\p{L}\p{N}]/gu, '');
4329
+ // ⚠️ THE GROUP BY OUR NAME FOR IT (总线程 11-09): Otaless gives a hotel's brand as
4330
+ // its group's code - ATOUR, CLUBMED - and a brand that is only that is said as
4331
+ // the group is configured (Atour(亚朵)). A real brand of its own stays as given.
4332
+ const groupWords = (h) => {
4333
+ if (!h.brand)
4334
+ return '';
4335
+ const g = groupOf(h);
4336
+ const isGroup = !!g && (key(h.brand) === key(g.id) || key(h.brand) === key(g.name));
4337
+ const plain = isGroup && g ? g.name : hotelName(h.brand);
4338
+ const named = key(hotelName(h.name));
4339
+ if (named.includes(key(plain)) || (isGroup && g?.names?.zh && named.includes(key(g.names.zh))))
4340
+ return '';
4341
+ return isGroup && g ? withZh(g.name, g.names, true) : plain;
4342
+ };
4343
+ const cities = spreadOf(hotels.map((h) => (h.city ? hotelName(h.city) : '')));
4344
+ const whereOf = (h) => (cities.kind === 'all' ? [h.area] : [h.area, h.city])
4198
4345
  .filter((x) => !!x)
4199
4346
  .map((x) => hotelName(x))
4200
4347
  .join(', ');
4201
- const f = h.forStay;
4202
- const terms = f
4203
- ? [
4204
- f.refundable === false ? 'non-refundable' : f.freeCancellation ? 'free to cancel' : '',
4205
- f.payment === 'prepaid'
4206
- ? f.notSoldHere
4207
- ? 'paid in advance - not booked here'
4208
- : 'paid in advance'
4209
- : f.payment === 'at-hotel'
4210
- ? 'paid at the hotel'
4211
- : '',
4212
- ].filter(Boolean)
4213
- : [];
4214
- const price = f
4215
- ? `${formatMoney(f.total)} for the stay incl. taxes and fees, ${withZh(f.room, f.roomNames, true)}${f.rooms > 1 ? ` × ${f.rooms}` : ''}${terms.length ? ` [${terms.join(', ')}]` : ''}`
4216
- : h.noRoomsForStay
4217
- ? // ⚠️ NOT SOLD HERE IS NOT SOLD OUT (2026-11-03 review, U11): a hotel with no
4218
- // rooms on sale through this connector was told as "no room for those
4219
- // nights", and the model said "no vacancy tonight" - as if another night
4220
- // would do. It says what the hotel's own page says.
4221
- h.noRoomsForStayCode === 'none-on-sale'
4222
- ? h.noRoomsForStay
4223
- : 'no room for those nights'
4224
- : h.fromNightly
4225
- ? `from ${formatMoney(h.fromNightly)} ${nightWords(true, h.fromNightlyTaxes === 'unknown')}`
4226
- : '';
4227
- // ⚠️ ONLY WHAT THE GROUP SAYS OF IT (总线程 11-06): its brand where the name
4228
- // does not carry it, its rating where there is one, and a few of its own
4229
- // facilities - a short line the guest can tell hotels apart by, nothing made up.
4230
- const brand = h.brand && !hotelName(h.name).toLowerCase().includes(h.brand.toLowerCase())
4231
- ? hotelName(h.brand)
4232
- : '';
4233
- const rated = h.rating
4234
- ? `rated ${h.rating.value}/${h.rating.scaleMax}${h.rating.count ? ` from ${h.rating.count} reviews` : ''}`
4235
- : '';
4236
- const has = h.amenities.slice(0, 3).map(hotelName).filter(Boolean);
4237
- return `${n}. ${withZh(h.name, h.names?.name, true)}${[where, brand, rated]
4238
- .filter(Boolean)
4239
- .map((x) => ` · ${x}`)
4240
- .join('')}${price ? `: ${price}` : ''}${has.length ? `; has ${has.join(', ')}` : ''}${tags.length ? `\n tags: ${tags.join(' · ')}` : ''}`;
4241
- };
4242
- /**
4243
- * What sets each hotel of a list apart, from what the list itself says (总线程
4244
- * 11-06, after RollingGo's text answers - "Most central · 5-star · SGD 244"): the
4245
- * lowest price and the best rating among them, and a stay's own free cancelling
4246
- * and breakfast. Never a word the data does not carry - a distance is not given,
4247
- * so none is said.
4248
- */
4249
- const listTagsOf = (hotels) => {
4348
+ const facilitiesOf = (h) => h.amenities.slice(0, 3).map(hotelName).filter(Boolean).join(', ');
4349
+ const facilities = allOrEach(spreadOf(hotels.map(facilitiesOf)));
4350
+ const priced = hotels.filter((h) => h.forStay);
4351
+ const cancelOf = (h) => h.forStay?.refundable === false
4352
+ ? 'non-refundable'
4353
+ : h.forStay?.freeCancellation
4354
+ ? 'free to cancel'
4355
+ : '';
4356
+ const cancel = spreadOf(priced.map(cancelOf));
4357
+ const pay = readOnly
4358
+ ? { said: '', tags: [] }
4359
+ : paymentOf(priced.map((h) => payOf(h.forStay ?? {})), 'hotel', group, `Every price here is a rate paid in advance, which cannot be booked here yet; a hotel's own rooms show any rate paid at the hotel, or book with ${group} in its own app or on its website.`);
4360
+ const payTag = (h) => (h.forStay ? (pay.tags[priced.indexOf(h)] ?? '') : '');
4361
+ // The cheapest, in one currency, and the best rated - among more than one.
4250
4362
  const priceOf = (h) => h.forStay?.total ?? h.fromNightly;
4251
- const priced = hotels.filter((h) => priceOf(h));
4252
- const oneCurrency = new Set(priced.map((h) => priceOf(h)?.currency)).size === 1;
4253
- const lowest = priced.length > 1 && oneCurrency
4254
- ? Math.min(...priced.map((h) => priceOf(h)?.minor ?? Number.POSITIVE_INFINITY))
4363
+ const withPrice = hotels.filter((h) => priceOf(h));
4364
+ const oneCurrency = new Set(withPrice.map((h) => priceOf(h)?.currency)).size === 1;
4365
+ const lowest = withPrice.length > 1 && oneCurrency
4366
+ ? Math.min(...withPrice.map((h) => priceOf(h)?.minor ?? Number.POSITIVE_INFINITY))
4255
4367
  : undefined;
4256
4368
  const score = (h) => (h.rating ? h.rating.value / h.rating.scaleMax : -1);
4257
4369
  const rated = hotels.filter((h) => h.rating);
@@ -4260,14 +4372,91 @@ const listTagsOf = (hotels) => {
4260
4372
  ((!!h.forStay.meal && h.forStay.meal.plan !== 'none') ||
4261
4373
  (h.forStay.labels ?? []).some((l) => l.startsWith('breakfast')));
4262
4374
  const free = (h) => !!h.forStay?.freeCancellation;
4263
- // A tag every one of them would carry sets none apart.
4264
- const apart = (has) => !hotels.every(has);
4265
- return hotels.map((h) => [
4266
- lowest !== undefined && priceOf(h)?.minor === lowest ? 'lowest price in this list' : '',
4267
- best !== undefined && score(h) === best ? 'best rated in this list' : '',
4268
- free(h) && apart(free) ? 'free to cancel' : '',
4269
- breakfast(h) && apart(breakfast) ? 'breakfast included' : '',
4270
- ].filter(Boolean));
4375
+ const isLowest = (h) => lowest !== undefined && priceOf(h)?.minor === lowest;
4376
+ const isBest = (h) => best !== undefined && score(h) === best;
4377
+ const placeOf = (h) => hotelName((cities.kind === 'all' ? h.area : (h.area ?? h.city)) ?? '');
4378
+ const apart = {
4379
+ lowest: setsApart(hotels.map(isLowest)),
4380
+ best: setsApart(hotels.map(isBest)),
4381
+ free: setsApart(hotels.map(free)),
4382
+ breakfast: setsApart(hotels.map(breakfast)),
4383
+ };
4384
+ const blocks = hotels.map((h, i) => {
4385
+ const f = h.forStay;
4386
+ const owner = groupWords(h);
4387
+ const where = whereOf(h);
4388
+ const room = f
4389
+ ? `${withZh(f.room, f.roomNames, true)}${f.rooms > 1 ? ` × ${f.rooms}` : ''}`
4390
+ : '';
4391
+ const terms = f &&
4392
+ saysOwn(cancel, cancelOf(h)) &&
4393
+ // A rate whose own name already says it is not told it again.
4394
+ !(cancelOf(h) === 'non-refundable' && SAYS_NON_REFUNDABLE.test(f.room)) &&
4395
+ !(cancelOf(h) === 'free to cancel' && /free cancellation|免费取消|可取消/i.test(f.room))
4396
+ ? cancelOf(h)
4397
+ : '';
4398
+ const place = placeOf(h);
4399
+ return choiceBlock(offset + i + 1, {
4400
+ title: withZh(h.name, h.names?.name, true),
4401
+ sentence: sentenceOf([
4402
+ owner && where ? `${owner}, in ${where}` : owner || (where ? `in ${where}` : ''),
4403
+ h.rating
4404
+ ? `rated ${h.rating.value}/${h.rating.scaleMax}${h.rating.count ? ` from ${h.rating.count} reviews` : ''}`
4405
+ : '',
4406
+ saysOwn(facilities, facilitiesOf(h)) ? facilitiesOf(h) : '',
4407
+ // "The price is for" - not "cheapest room", which the tag `Cheapest` means of the hotel.
4408
+ room ? `the price is for its ${room}${terms ? `, ${terms}` : ''}` : '',
4409
+ // One price alone has no tag to set it apart: its payment is in its sentence.
4410
+ f && priced.length < 2 && !readOnly ? PAY_WORDS[payOf(f)] : '',
4411
+ // ⚠️ NOT SOLD HERE IS NOT SOLD OUT (2026-11-03 review, U11): a hotel with no
4412
+ // rooms on sale through this connector says what its own page says.
4413
+ !f && h.noRoomsForStay
4414
+ ? h.noRoomsForStayCode === 'none-on-sale'
4415
+ ? h.noRoomsForStay
4416
+ : 'no room for those nights'
4417
+ : '',
4418
+ ]),
4419
+ tags: [
4420
+ payTag(h),
4421
+ apart.lowest && isLowest(h) ? 'Cheapest' : '',
4422
+ apart.best && isBest(h) ? 'Best rated' : '',
4423
+ apart.free && free(h) ? 'Free cancellation' : '',
4424
+ apart.breakfast && breakfast(h) ? 'Breakfast' : '',
4425
+ // Where it is, when that sets it apart and there is room for it.
4426
+ n > 1 && place && setsApart(hotels.map((x) => placeOf(x) === place)) ? place : '',
4427
+ ].filter(Boolean),
4428
+ price: f
4429
+ ? f.hours
4430
+ ? `${formatMoney(f.total)} for ${f.hours} hours`
4431
+ : `${formatMoney(f.total)}${f.rooms > 1 ? ` for ${f.rooms} rooms` : ''}`
4432
+ : h.noRoomsForStay
4433
+ ? h.noRoomsForStayCode === 'none-on-sale'
4434
+ ? 'Not on sale here'
4435
+ : 'No room for those nights'
4436
+ : h.fromNightly
4437
+ ? `from ${formatMoney(h.fromNightly)} ${nightWords(true, h.fromNightlyTaxes === 'unknown')}`
4438
+ : '',
4439
+ });
4440
+ });
4441
+ const said = [
4442
+ sharedBy(facilities) && n > 1 ? `All have ${sharedBy(facilities)}.` : '',
4443
+ cancel.kind === 'all' && cancel.value
4444
+ ? `Every price here is ${cancel.value}.`
4445
+ : cancel.kind === 'most' && cancel.value
4446
+ ? `Unless a hotel says otherwise, its price is ${cancel.value}.`
4447
+ : '',
4448
+ pay.said,
4449
+ readOnly
4450
+ ? 'Nothing can be booked here yet: to book, use the hotel and dates with its own group, on its website or app.'
4451
+ : '',
4452
+ ]
4453
+ .filter(Boolean)
4454
+ .join(' ');
4455
+ return {
4456
+ said,
4457
+ blocks,
4458
+ notes: hotels.map((h) => !readOnly && h.forStay?.notSoldHere ? 'its price is paid in advance - not booked here' : ''),
4459
+ };
4271
4460
  };
4272
4461
  /**
4273
4462
  * What a client that draws no card is told of a list asked for without dates
@@ -5860,11 +6049,19 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
5860
6049
  // To a client that draws no card, the hotels as numbered lines - numbered
5861
6050
  // across pages, so "the 23rd" on the second page is still one hotel. In the
5862
6051
  // text and, word for word, in the structure (`hotelChoices`).
5863
- const tagsOf = ctx.noCards ? listTagsOf(hotels) : [];
5864
- const hotelChoices = ctx.noCards && hotels.length
6052
+ const notBookable = notBookableOf(deps);
6053
+ const listed = ctx.noCards && hotels.length
6054
+ ? hotelChoicesBlock(hotels, offset, (h) => {
6055
+ const id = deps.backend.supplierOf?.(h.id);
6056
+ return id ? deps.backend.suppliers?.().find((g) => g.id === id) : undefined;
6057
+ }, groupNameOf(deps, (notSoldOn ?? hotels[0]).id), !!notBookable)
6058
+ : undefined;
6059
+ const hotelChoices = listed
5865
6060
  ? [
5866
- ...hotels.map((h, i) => listedInWords(h, offset + i + 1, tagsOf[i])),
5867
- idsByNumber('Hotel', hotels.map((h) => h.id), offset + 1),
6061
+ ...(listed.said ? [listed.said, ''] : []),
6062
+ listed.blocks.join('\n\n'),
6063
+ '',
6064
+ idsByNumber('Hotel', hotels.map((h) => h.id), offset + 1, listed.notes),
5868
6065
  ].join('\n')
5869
6066
  : '';
5870
6067
  // …and, asked without dates, what its prices are - first of the notes.
@@ -5950,6 +6147,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
5950
6147
  ...(fromPrices ? { stayDefault: fromPrices } : {}),
5951
6148
  ...(ctx.drawsCards && hotels.length ? { cardShows: ON_CARD.hotels } : {}),
5952
6149
  ...(notSold ? { notSoldHere: notSold } : {}),
6150
+ ...(notBookable ? { notBookable } : {}),
5953
6151
  },
5954
6152
  text: [
5955
6153
  inAll ||
@@ -5962,6 +6160,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
5962
6160
  more > 0
5963
6161
  ? `— ${offset ? `${offset + 1} to ${offset + hotels.length}` : hotels.length} in this answer and ${more} more. A city, a country or a filter narrows it; \`offset\` ${offset + hotels.length} is the next page.`
5964
6162
  : '',
6163
+ notBookable,
5965
6164
  ...priceNotes,
5966
6165
  widened?.found ? `Nothing matched ${widened.from}, so this is ${widened.to}.` : '',
5967
6166
  degraded.said,
@@ -6190,8 +6389,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
6190
6389
  const saidWhen = byTheHour
6191
6390
  ? `today, ${dayWords(stay.checkIn)}, ${stay.guests} ${stay.guests === 1 ? 'guest' : 'guests'}`
6192
6391
  : `${stayDayWords(stay.checkIn, stay.checkOut)}, ${stay.guests} ${stay.guests === 1 ? 'guest' : 'guests'}${roomsWanted > 1 ? `, ${roomsWanted} rooms` : ''}`;
6392
+ const notBookable = notBookableOf(deps);
6193
6393
  const roomChoices = ctx.noCards && choosable.length
6194
- ? roomChoicesOf(choosable, roomsWanted, saidWhen, before).join('\n')
6394
+ ? roomChoicesOf(choosable, roomsWanted, saidWhen, before, groupNameOf(deps, h.id), !!notBookable).join('\n')
6195
6395
  : undefined;
6196
6396
  // ⚠️ 「这周末」 WORKED OUT AS SATURDAY NIGHT (总线程 11-09, claude.ai and Manus
6197
6397
  // both) is said back first, in both - see `weekendOf`.
@@ -6216,17 +6416,19 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
6216
6416
  ...(memberRates ? { memberRates } : {}),
6217
6417
  ...flex.structured,
6218
6418
  ...(ctx.drawsCards && enough.length ? { cardShows: ON_CARD.rooms } : {}),
6419
+ ...(notBookable ? { notBookable } : {}),
6219
6420
  },
6220
6421
  text: [
6221
6422
  weekend,
6222
6423
  memberRates?.said ?? '',
6424
+ notBookable,
6223
6425
  ...roomsText(ctx.noCards ? withZh(h.name, h.names?.name, true) : h.name, byTheHour
6224
6426
  ? (rs) => `${rs.length} ${rs.length === 1 ? 'room' : 'rooms'} by the hour for today, ${stay.checkIn}, ${stay.guests} guests`
6225
6427
  : (rs) =>
6226
6428
  // ⚠️ THE WEEKDAYS, to a client that draws no card: the dates
6227
6429
  // the model worked out of 「下周五住两晚」 are said back as the
6228
6430
  // guest can check them (robin 11-06).
6229
- `${offerCount(rs)} for ${ctx.noCards ? `${stayDayWords(stay.checkIn, stay.checkOut)}, ${stay.checkIn} to ${stay.checkOut}` : `${stay.checkIn} to ${stay.checkOut}`}, ${stay.guests} guests${roomsWanted > 1 ? `, ${roomsWanted} rooms` : ''}`, byTheHour ? `today, ${stay.checkIn}` : `${stay.checkIn} to ${stay.checkOut}`, enough, roomsWanted, terms, ctx.noCards, saidWhen, before),
6431
+ `${offerCount(rs)} for ${ctx.noCards ? `${stayDayWords(stay.checkIn, stay.checkOut)}, ${stay.checkIn} to ${stay.checkOut}` : `${stay.checkIn} to ${stay.checkOut}`}, ${stay.guests} guests${roomsWanted > 1 ? `, ${roomsWanted} rooms` : ''}`, byTheHour ? `today, ${stay.checkIn}` : `${stay.checkIn} to ${stay.checkOut}`, enough, roomsWanted, terms, ctx.noCards, saidWhen, before, groupNameOf(deps, h.id), !!notBookable),
6230
6432
  // Said before the list to a client that draws no card (`before`).
6231
6433
  ctx.noCards && choosable.length ? '' : flexSaid,
6232
6434
  ctx.noCards && choosable.length ? '' : notSold,
@@ -7100,6 +7302,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7100
7302
  const stayWords = comparison.stay
7101
7303
  ? ` for ${comparison.stay.checkIn} to ${comparison.stay.checkOut}`
7102
7304
  : '';
7305
+ const notBookable = notBookableOf(deps);
7103
7306
  return {
7104
7307
  structured: {
7105
7308
  view: 'comparison',
@@ -7112,8 +7315,10 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7112
7315
  // In both, like the itinerary's: a host with no card may hand its
7113
7316
  // model this rather than the text.
7114
7317
  ...(ctx.noCards ? { notDrawn: COMPARISON_NOT_DRAWN } : {}),
7318
+ ...(notBookable ? { notBookable } : {}),
7115
7319
  },
7116
7320
  text: [
7321
+ notBookable,
7117
7322
  // The card carries the table; the text carries only what the model
7118
7323
  // could not see before it asked - what was dropped, and why.
7119
7324
  //
@@ -7231,6 +7436,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7231
7436
  const overlaps = overlapsOf(stayItems.flatMap((x) => x.checkIn && x.checkOut
7232
7437
  ? [{ hotelId: x.id, name: hotelName(x.name), checkIn: x.checkIn, checkOut: x.checkOut }]
7233
7438
  : []));
7439
+ const notBookable = notBookableOf(deps);
7234
7440
  return {
7235
7441
  structured: {
7236
7442
  view: 'itinerary',
@@ -7248,9 +7454,11 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7248
7454
  // In both, like the nudges: a host with no card may hand its model
7249
7455
  // this rather than the text.
7250
7456
  ...(ctx.noCards ? { notDrawn: PLAN_NOT_DRAWN } : {}),
7457
+ ...(notBookable && stays.length ? { notBookable } : {}),
7251
7458
  },
7252
7459
  text: [
7253
7460
  `**${plan.title}** · ${plan.days.length} ${plan.days.length === 1 ? 'day' : 'days'}. ${gap}`,
7461
+ stays.length ? notBookable : '',
7254
7462
  ...(stays.length
7255
7463
  ? [
7256
7464
  `Priced stays (${plan.stay?.guests ?? 2} guests; ${t.addToTrip} takes each one's hotel id, room id and dates):`,