@curless/hotel-storefront 0.74.3 → 0.74.5

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
@@ -1263,6 +1263,8 @@ const CANCEL_SCHEMA = {
1263
1263
  view: { enum: ['cancellation-preview', 'cancelled', 'booking-not-found', 'error'] },
1264
1264
  /** The fee is not known before the group cancels: `rule` is its terms and no fee is said. */
1265
1265
  feeUnknown: BOOL,
1266
+ /** The group answered with terms the guest has not agreed to: `rule` is ours, not the group's (0.74.5). */
1267
+ termsNew: BOOL,
1266
1268
  error: STR,
1267
1269
  detail: STR,
1268
1270
  groups: ARR,
@@ -4292,6 +4294,13 @@ const listAnd = (xs) => xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs.
4292
4294
  const askLater = (card) => card
4293
4295
  ? 'Do not look again in this turn - no second call for it: tell the guest, who can press Try again (重试) on the card when they want to look again.'
4294
4296
  : 'Do not look again in this turn - no second call for it: tell the guest, and that they can ask you to look again later.';
4297
+ /** The groups a failed stay names (Otaless's `link-first`, 0.74.5) - codes only. */
4298
+ const groupsOfFailed = (f) => {
4299
+ const g = f.groups;
4300
+ return Array.isArray(g)
4301
+ ? [...new Set(g.filter((x) => typeof x === 'string' && !!x))]
4302
+ : [];
4303
+ };
4295
4304
  /** No group kept quiet about - `degradedOf`'s default. */
4296
4305
  const NONE_QUIET = new Set();
4297
4306
  /**
@@ -4325,45 +4334,73 @@ card = !noCards,
4325
4334
  * old one neither - and said in `quietSaid` as a fact, in the text alike: mention it
4326
4335
  * only if the guest asks about that group. No 「重试」, no "name a city".
4327
4336
  */
4328
- quiet = NONE_QUIET) => {
4337
+ quiet = NONE_QUIET,
4338
+ /**
4339
+ * ⚠️ A SEARCH THAT HAS SOMETHING TO SHOW DOES NOT REMIND THE GUEST OF A GROUP THAT DID NOT
4340
+ * ANSWER (0.74.4, robin 11-17: 「没关系,报错的就这样灰着就行,不用有报错信息」 - Otaless's home
4341
+ * with a grey 「shopify」 under 「shopify didn't respond just now… Try again」, its /site
4342
+ * listing a group with no LIST_HOTELS, 60411). Set, a group that did not answer - every
4343
+ * group, every deployment - is said as a group kept quiet about is: a fact in `quietSaid`
4344
+ * and the text alike, to mention only if the guest asks about it; no 「重试」, no "do not
4345
+ * look again". It stays in `degraded`, which the card draws as a greyed chip, nothing more.
4346
+ * Not set where nothing is shown because of it (a search with nothing read), nor for "my
4347
+ * bookings" and the rest. A search of the group the guest asked for by name is always that:
4348
+ * only that group is asked, so one that did not answer leaves nothing read - and is said.
4349
+ */
4350
+ hush = false) => {
4329
4351
  const all = answer.degraded ?? [];
4330
4352
  if (all.length === 0)
4331
4353
  return { structured: {}, said: '' };
4332
4354
  const named = (d) => withZh(d.name, d.names, noCards);
4333
4355
  const hushed = all.filter((d) => quiet.has(d.supplier));
4334
4356
  const down = all.filter((d) => !quiet.has(d.supplier));
4335
- const hushedSilent = hushed.filter((d) => d.why !== 'needs-place');
4357
+ /** Did not answer, said only as the fact (`hush`) - and still drawn greyed. */
4358
+ const softly = (d) => hush && d.why !== 'needs-place';
4359
+ const loud = down.filter((d) => !softly(d));
4360
+ // In the market's own order: a group kept quiet beside one said softly is one sentence.
4361
+ const factSilent = all.filter((d) => d.why !== 'needs-place' && (quiet.has(d.supplier) || softly(d)));
4336
4362
  const hushedUnplaced = hushed.filter((d) => d.why === 'needs-place');
4363
+ const factOf = all.filter((d) => quiet.has(d.supplier) || softly(d));
4337
4364
  const noneOf = (n) => `so none of ${n === 1 ? 'its' : 'their'} ${noun} is in this list`;
4338
- const quietSaid = hushed.length
4365
+ const quietSaid = factOf.length
4339
4366
  ? `${[
4340
- hushedSilent.length
4341
- ? `${listAnd(hushedSilent.map(named))} did not answer this time, ${noneOf(hushedSilent.length)}`
4367
+ factSilent.length
4368
+ ? `${listAnd(factSilent.map(named))} did not answer this time, ${noneOf(factSilent.length)}`
4342
4369
  : '',
4343
4370
  hushedUnplaced.length
4344
4371
  ? `${listAnd(hushedUnplaced.map(named))} ${hushedUnplaced.length === 1 ? 'is' : 'are'} looked up only once a country or a city is named, ${noneOf(hushedUnplaced.length)}`
4345
4372
  : '',
4346
4373
  ]
4347
4374
  .filter(Boolean)
4348
- .join('; ')}; mention this only if the guest asks about ${listOrWords(hushed.map(named))}.`
4375
+ .join('; ')}; mention this only if the guest asks about ${listOrWords(factOf.map(named))}.`
4349
4376
  : '';
4350
- const quietPart = hushed.length
4351
- ? {
4352
- quietGroups: hushed.map((d) => ({
4353
- supplier: d.supplier,
4354
- name: d.name,
4355
- ...(d.why ? { why: d.why } : {}),
4356
- })),
4357
- quietSaid,
4358
- }
4359
- : {};
4377
+ const quietPart = {
4378
+ ...(hushed.length
4379
+ ? {
4380
+ quietGroups: hushed.map((d) => ({
4381
+ supplier: d.supplier,
4382
+ name: d.name,
4383
+ ...(d.why ? { why: d.why } : {}),
4384
+ })),
4385
+ }
4386
+ : {}),
4387
+ ...(quietSaid ? { quietSaid } : {}),
4388
+ };
4360
4389
  if (down.length === 0)
4361
4390
  return { structured: quietPart, said: quietSaid };
4391
+ // Every one that did not answer, greyed on the card - said aloud or not.
4392
+ const degraded = down.map((d) => ({
4393
+ supplier: d.supplier,
4394
+ name: d.name,
4395
+ ...(d.why ? { why: d.why } : {}),
4396
+ }));
4397
+ if (loud.length === 0)
4398
+ return { structured: { degraded, ...quietPart }, said: quietSaid };
4362
4399
  // ⚠️ A GROUP NOT LOOKED UP IS NOT A GROUP THAT DID NOT ANSWER (0.67.0, 总线程
4363
4400
  // 11-11): Accor is found only with a country or a city named. Said as that,
4364
4401
  // beside - not instead of - the groups that really were silent.
4365
- const silent = down.filter((d) => d.why !== 'needs-place');
4366
- const unplaced = down.filter((d) => d.why === 'needs-place');
4402
+ const silent = loud.filter((d) => d.why !== 'needs-place');
4403
+ const unplaced = loud.filter((d) => d.why === 'needs-place');
4367
4404
  const saidOf = (list) => listAnd(list.map((d) => withZh(d.name, d.names, noCards)));
4368
4405
  const parts = [];
4369
4406
  if (silent.length) {
@@ -4377,11 +4414,7 @@ quiet = NONE_QUIET) => {
4377
4414
  const said = parts.join(' ');
4378
4415
  return {
4379
4416
  structured: {
4380
- degraded: down.map((d) => ({
4381
- supplier: d.supplier,
4382
- name: d.name,
4383
- ...(d.why ? { why: d.why } : {}),
4384
- })),
4417
+ degraded,
4385
4418
  degradedSaid: said,
4386
4419
  ...quietPart,
4387
4420
  },
@@ -6297,6 +6330,8 @@ const bookingAnswer = async (deps, t, ctx, key, store, args, inTrip, lines, show
6297
6330
  why: f.why,
6298
6331
  ...(f.code ? { code: f.code } : {}),
6299
6332
  ...(f.args ? { args: f.args } : {}),
6333
+ // The group a link is asked of (0.74.5, `link-first`): the card's Link button names it.
6334
+ ...(groupsOfFailed(f).length ? { groups: groupsOfFailed(f) } : {}),
6300
6335
  ...(instead[i]?.city ? { city: instead[i]?.city } : {}),
6301
6336
  alternatives: (instead[i]?.hotels ?? []).map((h) => ({
6302
6337
  hotelId: h.id,
@@ -6312,7 +6347,22 @@ const bookingAnswer = async (deps, t, ctx, key, store, args, inTrip, lines, show
6312
6347
  : {}),
6313
6348
  })),
6314
6349
  }));
6315
- const failedText = notBooked.map((f) => `NOT BOOKED - ${f.hotelName} · ${stayWords(f.stay, f.hourly)}: ${f.why} It is still in the trip.${f.alternatives.length
6350
+ // A stay refused for a link or the account's sign-in (0.74.5): the tool for it, as a booking
6351
+ // refused for that alone says (`refusalAnswer`).
6352
+ const signInFor = (f) => {
6353
+ const how = deps.groupSignIn;
6354
+ if (f.code === 'link-first' && how?.linkTool)
6355
+ return (f.groups ?? [])
6356
+ .map((code) => {
6357
+ const name = deps.backend.suppliers?.().find((x) => x.id === code)?.name ?? code;
6358
+ return ` To link the guest's ${name} membership: ${how.linkTool} with group "${code}" gives the guest a one-time page for it.`;
6359
+ })
6360
+ .join('');
6361
+ if ((f.code === 'sign-in' || f.code === 'signed-out') && how?.signInTool)
6362
+ return ` ${how.signInTool} gives the guest a one-time page to sign in to their ${deps.vocab.brand} account.`;
6363
+ return '';
6364
+ };
6365
+ const failedText = notBooked.map((f) => `NOT BOOKED - ${f.hotelName} · ${stayWords(f.stay, f.hourly)}: ${f.why}${signInFor(f)} It is still in the trip.${f.alternatives.length
6316
6366
  ? ` Bookable instead for the same nights: ${f.alternatives.map((a) => `${a.name}${a.room ? ` (${a.room}` : ''}${a.total ? `${a.room ? ', ' : ' ('}${a.total} for the stay)` : a.room ? ')' : ''} [hotel \`${a.hotelId}\`]`).join('; ')}.`
6317
6367
  : ''} The guest can ask again, take another hotel, or leave it.`);
6318
6368
  // Terms waiting for the guest, said first: that is what needs doing.
@@ -6741,7 +6791,17 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
6741
6791
  : h);
6742
6792
  const offset = asked.offset ?? 0;
6743
6793
  const total = Math.max(answer.total, offset + hotels.length);
6744
- const cities = [...new Set(hotels.map((h) => h.city))];
6794
+ // One city however its group writes it (0.74.5: Accor's "SINGAPORE" beside "Singapore").
6795
+ const cities = [
6796
+ ...hotels
6797
+ .reduce((m, h) => {
6798
+ const k = h.city.trim().toLowerCase();
6799
+ if (!m.has(k))
6800
+ m.set(k, h.city);
6801
+ return m;
6802
+ }, new Map())
6803
+ .values(),
6804
+ ];
6745
6805
  // How many were left behind. The group has ninety-odd properties, so an
6746
6806
  // unnarrowed browse is a page of a much longer list, and neither the card
6747
6807
  // nor the model may present the page as the whole answer.
@@ -6966,7 +7026,9 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
6966
7026
  : `${c.name} (${c.count})`)
6967
7027
  .join(', ');
6968
7028
  const n = deps.vocab.nounPlural;
6969
- const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier));
7029
+ // Places to choose from: a group that did not answer is a greyed chip, said only if asked
7030
+ // (0.74.4) - with nothing to show, it is why, and said.
7031
+ const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier), total > 0);
6970
7032
  if (namedCountry) {
6971
7033
  const [only] = countries;
6972
7034
  return {
@@ -7022,7 +7084,6 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7022
7084
  };
7023
7085
  }
7024
7086
  if (hotels.length === 0) {
7025
- const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier));
7026
7087
  const nearest = (answer.nearest ?? []).map((h) => ({
7027
7088
  ...h,
7028
7089
  summary: hotelText('description', h.name, h.summary, DESCRIPTION_MAX).text,
@@ -7044,13 +7105,18 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7044
7105
  const capCurrency = answer.currencies[0] ?? cheapest?.currency ?? 'HKD';
7045
7106
  const cap = formatMoney(money(toMinor(Number(ceiling), capCurrency), capCurrency));
7046
7107
  const pastTheEnd = answer.total > 0 && offset > 0;
7108
+ /** Empty for a reason of its own - a page past the end, the filters, the ceiling. */
7109
+ const emptyOfItself = pastTheEnd || filteredEmpty || ceilingEmpty;
7110
+ // ⚠️ SAID ONLY IF ASKED WHERE IT IS NOT WHY IT IS EMPTY (0.74.4): where nothing could be
7111
+ // read at all, the groups that did not answer are the reason, and said.
7112
+ const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier), emptyOfItself);
7047
7113
  // ⚠️ NOTHING READ IS NOT "NOTHING MATCHES" (0.59.0, review U4): with every
7048
7114
  // group silent - or held back by a limit of ours (otaless/limits.ts) - the
7049
7115
  // answer said "No hotels match that" beside "did not answer in time", and
7050
7116
  // the card offered another city. What was not asked, or not answered, is
7051
7117
  // said as that; what our limit held back is said in its own words
7052
7118
  // (`unapplied`), which this branch did not read.
7053
- const unread = !pastTheEnd && !filteredEmpty && !ceilingEmpty && !!degraded.structured.degraded;
7119
+ const unread = !emptyOfItself && !!degraded.structured.degraded;
7054
7120
  const why = pastTheEnd
7055
7121
  ? `That page is past the end: ${answer.total} match, so \`offset\` 0 to ${answer.total - 1} is where they are.`
7056
7122
  : filteredEmpty
@@ -7281,7 +7347,8 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7281
7347
  priceNotes.unshift(weekend);
7282
7348
  // Every one by name and city, and that there are no others - or, told
7283
7349
  // only "2 hotels", the model asked for the list again to learn which.
7284
- const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier));
7350
+ // Hotels to show: a group that did not answer is a greyed chip, said only if asked (0.74.4).
7351
+ const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier), true);
7285
7352
  const unplaced = unplacedOf(deps, answer, !!asked.city);
7286
7353
  const inAll = homeList
7287
7354
  ? `There are ${total} ${branded(deps.vocab, deps.vocab.nounPlural)} here in all, and this answer lists every one: ${hotels
@@ -7690,11 +7757,12 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7690
7757
  total = found.total;
7691
7758
  degradedFound = found;
7692
7759
  }
7693
- // `look_up` draws no card: the guest asks again in words (`askLater`).
7694
- const degraded = degradedOf(deps, degradedFound, undefined, ctx?.noCards, false, quietIn(deps));
7760
+ const unique = [...new Set(ids)];
7761
+ // `look_up` draws no card: the guest asks again in words (`askLater`) - where nothing
7762
+ // was found. Where something was, a group that did not answer is said only if asked (0.74.4).
7763
+ const degraded = degradedOf(deps, degradedFound, undefined, ctx?.noCards, false, quietIn(deps), unique.length > 0);
7695
7764
  // A city no table here knows: what was read is not that city's (0.55.5).
7696
7765
  const unplaced = unplacedOf(deps, degradedFound, true);
7697
- const unique = [...new Set(ids)];
7698
7766
  // A name that fits more than one is said with the ones it fits; the rest are not found.
7699
7767
  const notFound = dropped.filter((d) => !candidates.some((c) => c.for === d));
7700
7768
  const fitsMany = [...new Set(candidates.map((c) => c.for))].map((ref) => `"${ref}" ${namesMoreThanOne(candidates.filter((c) => c.for === ref), branded(deps.vocab, deps.vocab.noun))}`);
@@ -8549,6 +8617,8 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
8549
8617
  // ⚠️ THE FEE IS NOT KNOWN BEFORE THE GROUP CANCELS (`feeUnknown`): the rule is
8550
8618
  // the group's own terms, and no figure - not even "up to" - is said.
8551
8619
  ...(preview.feeUnknown ? { feeUnknown: true } : { fee: formatMoney(preview.fee) }),
8620
+ // Its `rule` is ours, for the model (0.74.5): the card says it in its own words.
8621
+ ...(preview.termsNew ? { termsNew: true } : {}),
8552
8622
  // What the booking came to, so the fee is read against it (r10 #22).
8553
8623
  ...(booked ? { bookingTotal: formatMoney(booked.quote.total) } : {}),
8554
8624
  // ⚠️ NO "REFUND": nothing was ever paid here - a demonstration takes no