@curless/hotel-storefront 0.71.4 → 0.72.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.
package/dist/tools.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { aboutLines } from './about.js';
2
- import { DEFAULT_PAGE, FULL_CAPABILITIES, LASTING_REQUESTS, MAX_PAGE, REQUEST_KINDS, REQUEST_NOTE_MAX, guestTooLong, notPricedForNoAnswer, unansweredBy, unitWords, } from './backend.js';
2
+ import { DEFAULT_PAGE, FULL_CAPABILITIES, LASTING_REQUESTS, MAX_PAGE, REQUEST_KINDS, REQUEST_NOTE_MAX, guestTooLong, maskedEmail, notPricedForNoAnswer, unansweredBy, unitWords, wholeEmail, } from './backend.js';
3
3
  import { PAY_WORDS, allOrEach, choiceBlock, payOf, paymentOf, saysOwn, sentenceOf, setsApart, sharedBy, spreadOf, } from './choices.js';
4
4
  import { usedOnWords } from './coupon-words.js';
5
5
  import { MAX_GUESTS, addDays, dateOptions, dayWords, isDay, nights as nightsBetween, stayDayWords, toDay, weekendOf, weekendWords, } from './dates.js';
@@ -1452,6 +1452,10 @@ const BOOKING_SCHEMA = {
1452
1452
  /** `error`: why, as a code (`BOOKING_REFUSALS` or 'card-only') and in the guest's words. */
1453
1453
  error: STR,
1454
1454
  detail: STR,
1455
+ /** `needs-guest`: what the booking still needs, in words ('a name', 'a complete email', …). */
1456
+ missing: STRS,
1457
+ /** `needs-guest`: the email given was hidden (「•」) or not a whole address - turned away (`wholeEmail`). */
1458
+ emailRefused: BOOL,
1455
1459
  /** A sign-in refusal: the groups the guest must sign in to, `{ code, name, names? }`. */
1456
1460
  groups: ARR,
1457
1461
  coupon: OBJ,
@@ -1546,6 +1550,10 @@ export const buildOutputSchemas = (n) => ({
1546
1550
  degraded: ARR,
1547
1551
  /** What `degraded` means, as the text says it: not that those groups have none here. */
1548
1552
  degradedSaid: STR,
1553
+ /** In a market: the groups kept quiet about (`data.quietGroups`) that did not answer, or were not looked up - never drawn (`degradedOf`). */
1554
+ quietGroups: ARR,
1555
+ /** What `quietGroups` means, as the text says it: mention it only if the guest asks about that group. */
1556
+ quietSaid: STR,
1549
1557
  /** Nothing found because nothing could be read - every group silent or held back (0.59.0, U4). */
1550
1558
  unread: BOOL,
1551
1559
  /** What was asked and not done, in the backend's own sentences - a limit of ours, too. */
@@ -1843,6 +1851,9 @@ export const buildOutputSchemas = (n) => ({
1843
1851
  /** A \`city\` read in a market: the groups that did not answer in time (\`degradedOf\`). */
1844
1852
  degraded: ARR,
1845
1853
  degradedSaid: STR,
1854
+ /** The groups kept quiet about (\`data.quietGroups\`): mention them only if the guest asks (\`degradedOf\`). */
1855
+ quietGroups: ARR,
1856
+ quietSaid: STR,
1846
1857
  /** A \`city\` not recognised as a place: what was read is not that city's (\`unplacedOf\`). */
1847
1858
  unplaced: STR,
1848
1859
  unplacedSaid: STR,
@@ -4234,6 +4245,8 @@ const listAnd = (xs) => xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs.
4234
4245
  const askLater = (card) => card
4235
4246
  ? '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.'
4236
4247
  : '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.';
4248
+ /** No group kept quiet about - `degradedOf`'s default. */
4249
+ const NONE_QUIET = new Set();
4237
4250
  /**
4238
4251
  * The groups of a market that did not answer a search, as the sentence the
4239
4252
  * model is told and the fields the card draws its own line from - the same
@@ -4255,10 +4268,50 @@ noun = deps.vocab.nounPlural,
4255
4268
  */
4256
4269
  noCards = false,
4257
4270
  /** This answer draws a card, with its 「重试」 (`askLater`) - not so for `look_up`, which draws none. */
4258
- card = !noCards) => {
4259
- const down = answer.degraded ?? [];
4260
- if (down.length === 0)
4271
+ card = !noCards,
4272
+ /**
4273
+ * The groups kept quiet about here - a search's (`quietIn`), never a list of bookings.
4274
+ *
4275
+ * ⚠️ NOT A REMINDER EVERY TIME (robin 11-16: 「有 Accor 酒店的城市显示 Accor 就好了,没有的
4276
+ * 默认就是不显示,没必要一直提醒」). A quiet group that did not answer, or was not looked
4277
+ * up without a place, is left out of `degraded` - so no card draws a line for it, an
4278
+ * old one neither - and said in `quietSaid` as a fact, in the text alike: mention it
4279
+ * only if the guest asks about that group. No 「重试」, no "name a city".
4280
+ */
4281
+ quiet = NONE_QUIET) => {
4282
+ const all = answer.degraded ?? [];
4283
+ if (all.length === 0)
4261
4284
  return { structured: {}, said: '' };
4285
+ const named = (d) => withZh(d.name, d.names, noCards);
4286
+ const hushed = all.filter((d) => quiet.has(d.supplier));
4287
+ const down = all.filter((d) => !quiet.has(d.supplier));
4288
+ const hushedSilent = hushed.filter((d) => d.why !== 'needs-place');
4289
+ const hushedUnplaced = hushed.filter((d) => d.why === 'needs-place');
4290
+ const noneOf = (n) => `so none of ${n === 1 ? 'its' : 'their'} ${noun} is in this list`;
4291
+ const quietSaid = hushed.length
4292
+ ? `${[
4293
+ hushedSilent.length
4294
+ ? `${listAnd(hushedSilent.map(named))} did not answer this time, ${noneOf(hushedSilent.length)}`
4295
+ : '',
4296
+ hushedUnplaced.length
4297
+ ? `${listAnd(hushedUnplaced.map(named))} ${hushedUnplaced.length === 1 ? 'is' : 'are'} looked up only once a country or a city is named, ${noneOf(hushedUnplaced.length)}`
4298
+ : '',
4299
+ ]
4300
+ .filter(Boolean)
4301
+ .join('; ')}; mention this only if the guest asks about ${listOrWords(hushed.map(named))}.`
4302
+ : '';
4303
+ const quietPart = hushed.length
4304
+ ? {
4305
+ quietGroups: hushed.map((d) => ({
4306
+ supplier: d.supplier,
4307
+ name: d.name,
4308
+ ...(d.why ? { why: d.why } : {}),
4309
+ })),
4310
+ quietSaid,
4311
+ }
4312
+ : {};
4313
+ if (down.length === 0)
4314
+ return { structured: quietPart, said: quietSaid };
4262
4315
  // ⚠️ A GROUP NOT LOOKED UP IS NOT A GROUP THAT DID NOT ANSWER (0.67.0, 总线程
4263
4316
  // 11-11): Accor is found only with a country or a city named. Said as that,
4264
4317
  // beside - not instead of - the groups that really were silent.
@@ -4283,10 +4336,24 @@ card = !noCards) => {
4283
4336
  ...(d.why ? { why: d.why } : {}),
4284
4337
  })),
4285
4338
  degradedSaid: said,
4339
+ ...quietPart,
4286
4340
  },
4287
- said,
4341
+ said: [said, quietSaid].filter(Boolean).join(' '),
4288
4342
  };
4289
4343
  };
4344
+ /**
4345
+ * The groups a search keeps quiet about (`ToolDeps.quietGroups`) - less the one
4346
+ * the guest asked for (`filters.supplier`): a list of Accor's own hotels that
4347
+ * has none because Accor did not answer says so, with its 「重试」.
4348
+ */
4349
+ const quietIn = (deps, asked) => {
4350
+ const quiet = deps.quietGroups;
4351
+ if (!quiet?.size)
4352
+ return NONE_QUIET;
4353
+ if (!asked || !quiet.has(asked))
4354
+ return quiet;
4355
+ return new Set([...quiet].filter((g) => g !== asked));
4356
+ };
4290
4357
  /**
4291
4358
  * A place no table here knows (`HotelSearchResult.unplaced`), as the sentence the
4292
4359
  * model is told and the field the card draws its own line from.
@@ -6379,9 +6446,13 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
6379
6446
  ? lines.some((l) => !!holderOf(deps, deps.backend.supplierOf?.(l.hotelId)).caps.requiresPhone)
6380
6447
  : !!(deps.backend.capabilities ?? FULL_CAPABILITIES).requiresPhone;
6381
6448
  const phone = str(args.phone);
6449
+ // ⚠️ A HIDDEN OR HALF EMAIL IS NO EMAIL (0.71.5, 总线程 11-13 P3 - `wholeEmail`): the
6450
+ // account's masked `x•••@c•••.ai` passed back is turned away here, with the guest asked
6451
+ // for the whole address - never handed to the terms page, never sent to the backend.
6452
+ const halfEmail = !!guest.email && !wholeEmail(guest.email);
6382
6453
  const missing = [
6383
6454
  !guest.name && 'a name',
6384
- !guest.email.includes('@') && 'an email',
6455
+ !guest.email ? 'an email' : halfEmail && 'a complete email',
6385
6456
  phoneNeeded && phone.replace(/\D/g, '').length < 6 && 'a phone number',
6386
6457
  // Too long is as unusable as missing - see GUEST_LIMITS.
6387
6458
  ...guestTooLong({ ...guest, phone }),
@@ -6390,9 +6461,27 @@ const bookTripLines = async (deps, t, ctx, key, store, args, nothingThere) => {
6390
6461
  const said = missing.length > 1
6391
6462
  ? `${missing.slice(0, -1).join(', ')} and ${missing.at(-1)}`
6392
6463
  : (missing[0] ?? '');
6464
+ const detail = [
6465
+ `The booking needs ${said}.`,
6466
+ halfEmail
6467
+ ? maskedEmail(guest.email)
6468
+ ? 'The email given is hidden (it has "•" in it), not the guest\'s whole address - a masked email, such as the one an account answer shows, cannot be booked with.'
6469
+ : 'The email given is not a whole email address (name@example.com).'
6470
+ : '',
6471
+ `Ask the guest for ${missing.length > 1 ? 'them' : 'it'}${halfEmail ? ' - their full email address, typed out' : ''} - do not use a ${phoneNeeded ? 'name, email or phone number' : 'name or email'} you know from anywhere else.`,
6472
+ ]
6473
+ .filter(Boolean)
6474
+ .join(' ');
6393
6475
  return {
6394
- structured: { view: 'needs-guest', ...common(deps, key), missing },
6395
- text: `The booking needs ${said}. Ask the guest for ${missing.length > 1 ? 'them' : 'it'} - do not use a ${phoneNeeded ? 'name, email or phone number' : 'name or email'} you know from anywhere else.`,
6476
+ structured: {
6477
+ view: 'needs-guest',
6478
+ ...common(deps, key),
6479
+ missing,
6480
+ ...(halfEmail ? { emailRefused: true } : {}),
6481
+ // What the text says, word for word - a host that reads only this has it too.
6482
+ detail,
6483
+ },
6484
+ text: detail,
6396
6485
  };
6397
6486
  }
6398
6487
  const { requests, dropped } = readRequests(args);
@@ -6828,7 +6917,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
6828
6917
  : `${c.name} (${c.count})`)
6829
6918
  .join(', ');
6830
6919
  const n = deps.vocab.nounPlural;
6831
- const degraded = degradedOf(deps, answer, undefined, ctx?.noCards);
6920
+ const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier));
6832
6921
  if (namedCountry) {
6833
6922
  const [only] = countries;
6834
6923
  return {
@@ -6884,7 +6973,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
6884
6973
  };
6885
6974
  }
6886
6975
  if (hotels.length === 0) {
6887
- const degraded = degradedOf(deps, answer, undefined, ctx?.noCards);
6976
+ const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier));
6888
6977
  const nearest = (answer.nearest ?? []).map((h) => ({
6889
6978
  ...h,
6890
6979
  summary: hotelText('description', h.name, h.summary, DESCRIPTION_MAX).text,
@@ -7143,7 +7232,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7143
7232
  priceNotes.unshift(weekend);
7144
7233
  // Every one by name and city, and that there are no others - or, told
7145
7234
  // only "2 hotels", the model asked for the list again to learn which.
7146
- const degraded = degradedOf(deps, answer, undefined, ctx?.noCards);
7235
+ const degraded = degradedOf(deps, answer, undefined, ctx?.noCards, undefined, quietIn(deps, asked.filters?.supplier));
7147
7236
  const unplaced = unplacedOf(deps, answer, !!asked.city);
7148
7237
  const inAll = homeList
7149
7238
  ? `There are ${total} ${branded(deps.vocab, deps.vocab.nounPlural)} here in all, and this answer lists every one: ${hotels
@@ -7553,7 +7642,7 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
7553
7642
  degradedFound = found;
7554
7643
  }
7555
7644
  // `look_up` draws no card: the guest asks again in words (`askLater`).
7556
- const degraded = degradedOf(deps, degradedFound, undefined, ctx?.noCards, false);
7645
+ const degraded = degradedOf(deps, degradedFound, undefined, ctx?.noCards, false, quietIn(deps));
7557
7646
  // A city no table here knows: what was read is not that city's (0.55.5).
7558
7647
  const unplaced = unplacedOf(deps, degradedFound, true);
7559
7648
  const unique = [...new Set(ids)];