@curless/hotel-storefront 0.63.0 → 0.63.2
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/card.generated.d.ts +1 -1
- package/dist/card.generated.js +2 -2
- package/dist/card.generated.js.map +1 -1
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/otaless/backend.d.ts +9 -3
- package/dist/otaless/backend.d.ts.map +1 -1
- package/dist/otaless/backend.js +14 -5
- package/dist/otaless/backend.js.map +1 -1
- package/dist/otaless/booking.d.ts +124 -9
- package/dist/otaless/booking.d.ts.map +1 -1
- package/dist/otaless/booking.js +385 -67
- package/dist/otaless/booking.js.map +1 -1
- package/dist/otaless/client.d.ts +9 -0
- package/dist/otaless/client.d.ts.map +1 -1
- package/dist/otaless/client.js.map +1 -1
- package/dist/otaless/fake.d.ts +7 -0
- package/dist/otaless/fake.d.ts.map +1 -1
- package/dist/otaless/fake.js +7 -2
- package/dist/otaless/fake.js.map +1 -1
- package/dist/otaless/make.d.ts.map +1 -1
- package/dist/otaless/make.js +28 -7
- package/dist/otaless/make.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +51 -4
- package/dist/server.js.map +1 -1
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +3 -1
- package/dist/surface.js.map +1 -1
- package/dist/tools.d.ts +22 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +222 -43
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +24 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/tools.js
CHANGED
|
@@ -1100,7 +1100,7 @@ const allTools = (n, v) => {
|
|
|
1100
1100
|
},
|
|
1101
1101
|
{
|
|
1102
1102
|
name: n.refundBooking,
|
|
1103
|
-
description:
|
|
1103
|
+
description: "Asks the hotel group to refund, in full, a booking made here that has been paid. TWO STEPS: the first call (no `confirmed`) only previews - the amount and the group's own refund terms - and asks nothing of the group; say them to the guest, and only when they say yes call again with `confirmed: true`. The second answer says what the group did with the request.",
|
|
1104
1104
|
annotations: cancels('Refund a booking', open),
|
|
1105
1105
|
inputSchema: {
|
|
1106
1106
|
type: 'object',
|
|
@@ -1114,6 +1114,10 @@ const allTools = (n, v) => {
|
|
|
1114
1114
|
maxLength: REFUND_REASON_MAX,
|
|
1115
1115
|
description: `Optional, the guest's reason in their own words, up to ${REFUND_REASON_MAX} characters`,
|
|
1116
1116
|
},
|
|
1117
|
+
confirmed: {
|
|
1118
|
+
type: 'boolean',
|
|
1119
|
+
description: 'true only after the guest was shown the refund preview this tool answers with and said yes. Without it, the answer is that preview and nothing is asked of the group.',
|
|
1120
|
+
},
|
|
1117
1121
|
},
|
|
1118
1122
|
required: ['booking'],
|
|
1119
1123
|
},
|
|
@@ -1645,13 +1649,21 @@ export const buildOutputSchemas = (n) => ({
|
|
|
1645
1649
|
[n.refundBooking]: {
|
|
1646
1650
|
type: 'object',
|
|
1647
1651
|
properties: {
|
|
1648
|
-
view: { enum: ['booking', 'booking-not-found', 'error'] },
|
|
1652
|
+
view: { enum: ['booking', 'booking-not-found', 'refund-preview', 'error'] },
|
|
1649
1653
|
brand: STR,
|
|
1650
1654
|
toolNames: OBJ,
|
|
1651
1655
|
bookingMode: STR,
|
|
1652
1656
|
demo: BOOL,
|
|
1653
1657
|
booking: OBJ,
|
|
1654
1658
|
total: STR,
|
|
1659
|
+
/** The refund preview: all that would be asked back, the group's terms, and until when the guest can say yes. */
|
|
1660
|
+
amount: STR,
|
|
1661
|
+
/** The amount is what the group says was paid (else what the order asked). */
|
|
1662
|
+
fromPayment: BOOL,
|
|
1663
|
+
/** The request names no amount: what comes back is the group's to decide. */
|
|
1664
|
+
groupDecides: BOOL,
|
|
1665
|
+
terms: STR,
|
|
1666
|
+
until: STR,
|
|
1655
1667
|
/** The refund was asked for; the booking's `payment` says where it stands. */
|
|
1656
1668
|
refundAsked: BOOL,
|
|
1657
1669
|
query: STR,
|
|
@@ -2086,6 +2098,10 @@ const bookingForCard = (b) => ({
|
|
|
2086
2098
|
// brands): the host of the payment page, and the pay-by moment with its
|
|
2087
2099
|
// offset - never a bare ISO string. The card and the model read the same.
|
|
2088
2100
|
...(hostOf(b.payment.url) ? { host: hostOf(b.payment.url) } : {}),
|
|
2101
|
+
// The page closed on its own (Otaless 0.63.2): said, not left to a missing url.
|
|
2102
|
+
...(b.payment.status === 'awaiting' && !b.payment.url && b.payment.method === 'card'
|
|
2103
|
+
? { linkClosed: true, linkClosedSaid: LINK_CLOSED_WORDS }
|
|
2104
|
+
: {}),
|
|
2089
2105
|
...(payByWords(b.payment) ? { payByWords: payByWords(b.payment) } : {}),
|
|
2090
2106
|
amount: formatMoney(b.payment.amount),
|
|
2091
2107
|
// What goes back, where it is not the whole amount, as text too - the
|
|
@@ -2187,10 +2203,13 @@ const paidLine = (deps, b, fee) => {
|
|
|
2187
2203
|
h.notReal
|
|
2188
2204
|
? `Once it is paid the booking is made here - it is not sent to ${h.name} - and ${deps.tools.listBookings} shows it`
|
|
2189
2205
|
: `Once it is paid the stay is booked with ${h.name}, and ${deps.tools.listBookings} shows it`}; unpaid by then, the page closes and nothing is booked or charged.`
|
|
2190
|
-
:
|
|
2191
|
-
//
|
|
2192
|
-
|
|
2193
|
-
|
|
2206
|
+
: deps.backend.otalessBooking
|
|
2207
|
+
? // Otaless 0.63.2: the group's link can close on its own.
|
|
2208
|
+
`**Not booked yet** - ${LINK_CLOSED_WORDS}.`
|
|
2209
|
+
: // ⚠️ NO LINK IS NOT "undefined" (2026-10-21 re-audit, T2-6): a card
|
|
2210
|
+
// page that was closed and could not be opened again leaves a stay
|
|
2211
|
+
// waiting with nowhere to pay it. Say so, and that it lapses.
|
|
2212
|
+
`**Not booked yet.** ${amount} is to be paid on the card page by ${p.payByLocal ?? p.payBy} hotel time, but the page's link is not available just now - ask again later (${deps.tools.listBookings} shows where it stands). Nothing is booked or charged until it is paid; if no page comes by then, the stay lapses and can be asked for again.`;
|
|
2194
2213
|
case 'issued':
|
|
2195
2214
|
return `Confirmed on UnionPay: ${h.name} is being asked to book it now, and ${deps.tools.listBookings} shows when it has. If ${h.name} does not take it, the one-time card is not charged.`;
|
|
2196
2215
|
case 'paid':
|
|
@@ -2234,7 +2253,9 @@ const madeForCard = (deps, b) => {
|
|
|
2234
2253
|
const { confirmationCode: _unconfirmed, ...rest } = card;
|
|
2235
2254
|
return { ...rest, pending: true };
|
|
2236
2255
|
};
|
|
2237
|
-
const bookedLine = (deps, b) => [heldLine(deps, b), couponPointsLine(b, holderOf(deps, b.supplier))]
|
|
2256
|
+
const bookedLine = (deps, b) => [unconfirmedSaid(deps, b), heldLine(deps, b), couponPointsLine(b, holderOf(deps, b.supplier))]
|
|
2257
|
+
.filter(Boolean)
|
|
2258
|
+
.join(' ');
|
|
2238
2259
|
/**
|
|
2239
2260
|
* The coupon a booking used and the points it should earn - on the booking
|
|
2240
2261
|
* itself, so the confirmation says what the review said (§4, §5).
|
|
@@ -3458,9 +3479,26 @@ const notSentStatus = (deps, b) => {
|
|
|
3458
3479
|
? `not sent to ${h.name} - nobody confirms it, and no room is held`
|
|
3459
3480
|
: undefined;
|
|
3460
3481
|
};
|
|
3482
|
+
/**
|
|
3483
|
+
* An `unconfirmed` booking said for what it is (Otaless 0.63.2): a person is
|
|
3484
|
+
* checking a payment that was not the amount asked, or the group never said
|
|
3485
|
+
* whether it was made - it may have been. `undefined` for any other.
|
|
3486
|
+
*/
|
|
3487
|
+
const unconfirmedSaid = (deps, b) => {
|
|
3488
|
+
if (b.status !== 'unconfirmed')
|
|
3489
|
+
return undefined;
|
|
3490
|
+
const group = holderOf(deps, b.supplier).name;
|
|
3491
|
+
if (b.needsPerson === 'paid-amount')
|
|
3492
|
+
return `unconfirmed: ${group} says it was paid, but not at the amount asked - a person is checking the payment. No payment link is given, and this stay cannot be booked again until it is settled.`;
|
|
3493
|
+
if (b.unverifiable)
|
|
3494
|
+
return `unconfirmed: ${group} never confirmed whether it was made, and it could not be found in its bookings - it may have been made. The guest should check with ${group} before booking it again; asked again, a new booking is made.`;
|
|
3495
|
+
return undefined;
|
|
3496
|
+
};
|
|
3497
|
+
/** The words for a payment page that has closed on its own (Otaless 0.63.2). */
|
|
3498
|
+
const LINK_CLOSED_WORDS = 'the payment link is no longer open - look at the bookings again; nothing is paid until it is';
|
|
3461
3499
|
/** A booking for the card and the model's structure, with `notSentStatus` where there is one. */
|
|
3462
3500
|
const listedForCard = (deps, b) => {
|
|
3463
|
-
const said = notSentStatus(deps, b);
|
|
3501
|
+
const said = notSentStatus(deps, b) ?? unconfirmedSaid(deps, b);
|
|
3464
3502
|
return { ...bookingForCard(b), ...(said ? { statusSaid: said } : {}) };
|
|
3465
3503
|
};
|
|
3466
3504
|
/**
|
|
@@ -3512,6 +3550,10 @@ const BOOKING_REFUSALS = new Set([
|
|
|
3512
3550
|
'not-cancelled',
|
|
3513
3551
|
'not-paid',
|
|
3514
3552
|
'not-refunded',
|
|
3553
|
+
'refund-preview',
|
|
3554
|
+
'refunded',
|
|
3555
|
+
'cancel-unknown',
|
|
3556
|
+
'addons-off',
|
|
3515
3557
|
'unknown-addon',
|
|
3516
3558
|
'addon',
|
|
3517
3559
|
'price-changed',
|
|
@@ -3545,18 +3587,39 @@ const refusalAnswer = (deps, key, err) => {
|
|
|
3545
3587
|
? `${how.signInTool} gives the guest a one-time page to sign in to their ${deps.vocab.brand} account.`
|
|
3546
3588
|
: '')
|
|
3547
3589
|
.filter((x, i, all) => !!x && all.indexOf(x) === i);
|
|
3590
|
+
// The guest's words for the refusals whose own message does not say enough
|
|
3591
|
+
// (总线程's review of 0.63.0): a cancellation the group did not confirm may
|
|
3592
|
+
// still stand - never "cancelled".
|
|
3593
|
+
const more = e.code === 'cancel-unknown'
|
|
3594
|
+
? 'The group has not confirmed the cancellation, so the booking may still stand - nothing here has changed. Tell the guest to look at their bookings again in a few minutes.'
|
|
3595
|
+
: e.code === 'refund-preview'
|
|
3596
|
+
? `Nothing was refunded. Show the guest the refund preview first (${deps.tools.refundBooking} without \`confirmed\`), then ask again once they say yes.`
|
|
3597
|
+
: e.code === 'addons-off'
|
|
3598
|
+
? 'Add-ons are not offered here; tell the guest nothing can be added to the booking.'
|
|
3599
|
+
: '';
|
|
3548
3600
|
return {
|
|
3549
3601
|
structured: {
|
|
3550
3602
|
view: 'error',
|
|
3551
3603
|
...common(deps, key),
|
|
3552
3604
|
error: e.code,
|
|
3553
|
-
detail: e.message,
|
|
3605
|
+
detail: more ? `${e.message} ${more}` : e.message,
|
|
3554
3606
|
...(groups.length ? { groups } : {}),
|
|
3555
3607
|
},
|
|
3556
|
-
text: [e.message, ...signIn].join(' '),
|
|
3608
|
+
text: [e.message, more, ...signIn].filter(Boolean).join(' '),
|
|
3557
3609
|
};
|
|
3558
3610
|
};
|
|
3559
|
-
/**
|
|
3611
|
+
/**
|
|
3612
|
+
* The card's copy of the terms to agree to, beside the answer (`_meta`).
|
|
3613
|
+
*
|
|
3614
|
+
* ⚠️ THE TERMS' REF AND FULL TEXT ARE THE CARD'S, NEVER THE MODEL'S (总线程's
|
|
3615
|
+
* review of 0.63.0, binding): a group's terms are text a stranger wrote, and a
|
|
3616
|
+
* model that reads them can be talked into acting on them (prompt injection).
|
|
3617
|
+
* The model gets facts and the sentence `termsSaid`; the card gets this, in
|
|
3618
|
+
* `_meta` - and only a client that said it draws cards (`ToolContext.drawsCards`):
|
|
3619
|
+
* some hosts hand `_meta` to their model.
|
|
3620
|
+
*/
|
|
3621
|
+
export const TERMS_META_KEY = 'curless/terms';
|
|
3622
|
+
/** The longest stretch of a group's refund terms put in the answer. */
|
|
3560
3623
|
const TERMS_TEXT_MAX = 2_000;
|
|
3561
3624
|
/**
|
|
3562
3625
|
* Terms a group sent back, for the GUEST to agree to - as the structure and as
|
|
@@ -3565,19 +3628,23 @@ const TERMS_TEXT_MAX = 2_000;
|
|
|
3565
3628
|
* ⚠️ THE MODEL CANNOT AGREE FOR THE GUEST, and no tool parameter means "agreed":
|
|
3566
3629
|
* the card's button (`acceptTerms`, the card's own tool) or the one-time page
|
|
3567
3630
|
* is the only way, and the words say so first. The text and the structure say
|
|
3568
|
-
* the same (`termsSaid`) - the model reads the structure.
|
|
3631
|
+
* the same (`termsSaid`) - the model reads the structure. Neither carries the
|
|
3632
|
+
* terms' `ref` or their text: see `TERMS_META_KEY`.
|
|
3569
3633
|
*/
|
|
3570
3634
|
const termsAnswer = (deps, ctx, key, terms) => {
|
|
3571
3635
|
const t = deps.tools;
|
|
3636
|
+
// A client that draws no card, or that never said it does, is given the page.
|
|
3637
|
+
const onPage = !!ctx.noCards || !ctx.drawsCards;
|
|
3572
3638
|
const groupNames = [...new Set(terms.map((x) => withZh(x.groupName, x.groupNames, ctx.noCards)))];
|
|
3573
3639
|
const many = groupNames.length > 1;
|
|
3574
|
-
const
|
|
3640
|
+
const where = onPage
|
|
3641
|
+
? "on the one-time page linked below, which opens only in the browser signed in to the guest's account"
|
|
3642
|
+
: 'on the card, with its Agree button';
|
|
3643
|
+
const termsSaid = `Not booked yet: ${listAnd(groupNames)} ${many ? 'ask' : 'asks'} the guest to read and agree to ${many ? 'their' : 'its'} booking terms themselves, ${where}. Nothing is ordered until they do. You cannot agree for them, and do not ask them to say they agree in the chat.`;
|
|
3575
3644
|
const entries = terms.map((x) => {
|
|
3576
|
-
const link =
|
|
3577
|
-
const cut = ctx.noCards && x.text.length > TERMS_TEXT_MAX;
|
|
3645
|
+
const link = onPage ? deps.termsLink?.(key, x.ref) : undefined;
|
|
3578
3646
|
return {
|
|
3579
3647
|
entry: {
|
|
3580
|
-
ref: x.ref,
|
|
3581
3648
|
group: x.group,
|
|
3582
3649
|
groupName: x.groupName,
|
|
3583
3650
|
...(x.groupNames ? { groupNames: x.groupNames } : {}),
|
|
@@ -3589,9 +3656,6 @@ const termsAnswer = (deps, ctx, key, terms) => {
|
|
|
3589
3656
|
rooms: x.rooms,
|
|
3590
3657
|
total: formatMoney(x.total),
|
|
3591
3658
|
totalMoney: x.total,
|
|
3592
|
-
// A client with no card is handed the first part, as the text is; the card has all of it.
|
|
3593
|
-
text: cut ? upTo(x.text, TERMS_TEXT_MAX) : x.text,
|
|
3594
|
-
...(cut ? { textCut: true } : {}),
|
|
3595
3659
|
// ⚠️ THE MOMENT ONLY (0.63.0 screenshots): the card writes it in the viewer's own
|
|
3596
3660
|
// language and time zone. "10:05 UTC, 10 Nov" here was drawn as is in a
|
|
3597
3661
|
// Chinese card - and it is not the hotel's clock anyway (no zone is sent).
|
|
@@ -3599,23 +3663,15 @@ const termsAnswer = (deps, ctx, key, terms) => {
|
|
|
3599
3663
|
...(link ? { link } : {}),
|
|
3600
3664
|
},
|
|
3601
3665
|
link,
|
|
3602
|
-
cut,
|
|
3603
3666
|
x,
|
|
3604
3667
|
};
|
|
3605
3668
|
});
|
|
3606
3669
|
const blocks = entries.map(({ link, x }) => {
|
|
3607
|
-
const longer = x.text.length > TERMS_TEXT_MAX;
|
|
3608
|
-
const shown = longer ? upTo(x.text, TERMS_TEXT_MAX) : x.text;
|
|
3609
3670
|
const until = clockWords(x.until) ?? x.until;
|
|
3610
3671
|
return [
|
|
3611
|
-
`${withZh(x.hotelName, x.hotelNames, ctx.noCards)} · ${x.roomName} · ${stayWords(x.stay)} · ${x.rooms} ${x.rooms === 1 ? 'room' : 'rooms'} · ${formatMoney(x.total)}`,
|
|
3612
|
-
`${x.groupName}'s terms, word for word:`,
|
|
3613
|
-
shown,
|
|
3614
|
-
longer
|
|
3615
|
-
? `(That is the first ${TERMS_TEXT_MAX} of ${x.text.length} characters; the whole text is ${ctx.noCards ? 'on the page' : 'on the card'}.)`
|
|
3616
|
-
: '',
|
|
3672
|
+
`${withZh(x.hotelName, x.hotelNames, ctx.noCards)} · ${x.roomName} · ${stayWords(x.stay)} · ${x.rooms} ${x.rooms === 1 ? 'room' : 'rooms'} · ${formatMoney(x.total)} · ${x.groupName}`,
|
|
3617
3673
|
`They can be agreed to until ${until}.`,
|
|
3618
|
-
|
|
3674
|
+
onPage
|
|
3619
3675
|
? link
|
|
3620
3676
|
? `Give the guest this one-time link to read the terms and agree on ${deps.vocab.brand}'s page - it opens only in the browser signed in to their ${deps.vocab.brand} account, works once, until ${clockWords(link.expiresAt) ?? link.expiresAt}: ${link.url}. When they say they are done, call ${t.listBookings} to see the booking and its payment page.`
|
|
3621
3677
|
: 'These terms can only be agreed to on a client that shows the card; nothing was ordered.'
|
|
@@ -3626,13 +3682,31 @@ const termsAnswer = (deps, ctx, key, terms) => {
|
|
|
3626
3682
|
});
|
|
3627
3683
|
return {
|
|
3628
3684
|
structured: { terms: entries.map((e) => e.entry), termsSaid },
|
|
3629
|
-
text: [
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3685
|
+
text: [termsSaid, ...blocks].filter(Boolean).join('\n\n'),
|
|
3686
|
+
...((ctx.drawsCards && !ctx.noCards) || ctx.termsMeta
|
|
3687
|
+
? {
|
|
3688
|
+
meta: {
|
|
3689
|
+
[TERMS_META_KEY]: {
|
|
3690
|
+
terms: terms.map((x) => ({
|
|
3691
|
+
ref: x.ref,
|
|
3692
|
+
group: x.group,
|
|
3693
|
+
groupName: x.groupName,
|
|
3694
|
+
...(x.groupNames ? { groupNames: x.groupNames } : {}),
|
|
3695
|
+
hotelId: x.hotelId,
|
|
3696
|
+
hotelName: x.hotelName,
|
|
3697
|
+
...(x.hotelNames ? { hotelNames: x.hotelNames } : {}),
|
|
3698
|
+
roomName: x.roomName,
|
|
3699
|
+
stay: x.stay,
|
|
3700
|
+
rooms: x.rooms,
|
|
3701
|
+
total: formatMoney(x.total),
|
|
3702
|
+
totalMoney: x.total,
|
|
3703
|
+
text: x.text,
|
|
3704
|
+
until: x.until,
|
|
3705
|
+
})),
|
|
3706
|
+
},
|
|
3707
|
+
},
|
|
3708
|
+
}
|
|
3709
|
+
: {}),
|
|
3636
3710
|
};
|
|
3637
3711
|
};
|
|
3638
3712
|
const bookingLine = (deps, b, noCards) => {
|
|
@@ -3641,6 +3715,7 @@ const bookingLine = (deps, b, noCards) => {
|
|
|
3641
3715
|
const notSent = holderOf(deps, b.supplier).notReal;
|
|
3642
3716
|
return [
|
|
3643
3717
|
`${b.confirmationCode} · ${withZh(b.hotelName, b.hotelNames, noCards)} · ${stayWords(b.stay, b.hourly)} · ${notSentStatus(deps, b) ??
|
|
3718
|
+
unconfirmedSaid(deps, b) ??
|
|
3644
3719
|
// ⚠️ SAID AS WHAT IT IS - see BookingStatus. Neither booked nor failed.
|
|
3645
3720
|
(b.status === 'unconfirmed'
|
|
3646
3721
|
? 'unconfirmed: whether it was made is not known yet, and a person is confirming it'
|
|
@@ -3664,7 +3739,11 @@ const bookingLine = (deps, b, noCards) => {
|
|
|
3664
3739
|
// client with no card reads "card page" as the booking card's.
|
|
3665
3740
|
b.payment.status === 'awaiting' && b.payment.url
|
|
3666
3741
|
? ` · to be paid on ${hostOf(b.payment.url) ?? 'its payment page'}${payByWords(b.payment) ? ` by ${payByWords(b.payment)}` : ''}: ${b.payment.url}`
|
|
3667
|
-
:
|
|
3742
|
+
: b.payment.status === 'awaiting' &&
|
|
3743
|
+
b.payment.method === 'card' &&
|
|
3744
|
+
deps.backend.otalessBooking
|
|
3745
|
+
? ` · ${LINK_CLOSED_WORDS}`
|
|
3746
|
+
: ` · ${paymentWords(b)}`
|
|
3668
3747
|
: '',
|
|
3669
3748
|
].join('');
|
|
3670
3749
|
};
|
|
@@ -3854,6 +3933,31 @@ const remember = (deps, k, amount) => {
|
|
|
3854
3933
|
m.delete(oldest);
|
|
3855
3934
|
}
|
|
3856
3935
|
};
|
|
3936
|
+
/**
|
|
3937
|
+
* The refund previews' tokens, per conversation and booking (`${key}|refund|${id}`).
|
|
3938
|
+
* ⚠️ SERVER-SIDE ONLY: the token is what lets a refund be asked, and goes to
|
|
3939
|
+
* neither the model nor the card - the card asks again with `confirmed`.
|
|
3940
|
+
*/
|
|
3941
|
+
const refundTokens = new WeakMap();
|
|
3942
|
+
const refundTokensOf = (deps) => {
|
|
3943
|
+
let m = refundTokens.get(deps);
|
|
3944
|
+
if (!m) {
|
|
3945
|
+
m = new Map();
|
|
3946
|
+
refundTokens.set(deps, m);
|
|
3947
|
+
}
|
|
3948
|
+
return m;
|
|
3949
|
+
};
|
|
3950
|
+
const rememberRefund = (deps, k, preview, until) => {
|
|
3951
|
+
const m = refundTokensOf(deps);
|
|
3952
|
+
m.delete(k);
|
|
3953
|
+
m.set(k, { preview, until });
|
|
3954
|
+
while (m.size > MAX_SHOWN) {
|
|
3955
|
+
const oldest = m.keys().next().value;
|
|
3956
|
+
if (oldest === undefined)
|
|
3957
|
+
break;
|
|
3958
|
+
m.delete(oldest);
|
|
3959
|
+
}
|
|
3960
|
+
};
|
|
3857
3961
|
/** "a, b and c" - "a and b" - "a". */
|
|
3858
3962
|
const listAnd = (xs) => xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs.at(-1)}` : (xs[0] ?? '');
|
|
3859
3963
|
/**
|
|
@@ -4614,6 +4718,7 @@ export const contextFor = (deps, key) => {
|
|
|
4614
4718
|
session: key.endsWith(suffix) ? key.slice(0, -suffix.length) : key,
|
|
4615
4719
|
tripKey: key,
|
|
4616
4720
|
noCards: true,
|
|
4721
|
+
termsMeta: true,
|
|
4617
4722
|
};
|
|
4618
4723
|
};
|
|
4619
4724
|
export const identityFor = (deps, key) => identity(deps, contextFor(deps, key), key);
|
|
@@ -5667,6 +5772,7 @@ const bookingAnswer = async (deps, t, ctx, key, store, args, inTrip, lines, show
|
|
|
5667
5772
|
...termsPart.structured,
|
|
5668
5773
|
},
|
|
5669
5774
|
text: [termsPart.text, ...failedText].join('\n'),
|
|
5775
|
+
...(termsPart.meta ? { meta: termsPart.meta } : {}),
|
|
5670
5776
|
};
|
|
5671
5777
|
// Nothing booked at all: every stay said, each with its way on.
|
|
5672
5778
|
return {
|
|
@@ -5766,6 +5872,7 @@ const bookingAnswer = async (deps, t, ctx, key, store, args, inTrip, lines, show
|
|
|
5766
5872
|
return {
|
|
5767
5873
|
structured: { ...answer.structured, view: 'terms', ...termsPart.structured },
|
|
5768
5874
|
text: [termsPart.text, answer.text].join('\n\n'),
|
|
5875
|
+
...(termsPart.meta ? { meta: { ...answer.meta, ...termsPart.meta } } : {}),
|
|
5769
5876
|
};
|
|
5770
5877
|
};
|
|
5771
5878
|
/**
|
|
@@ -7258,15 +7365,87 @@ const answerTool = async (deps, name, rawArgs, ctx) => {
|
|
|
7258
7365
|
const ot = deps.backend.otalessBooking;
|
|
7259
7366
|
const ref = str(args.booking);
|
|
7260
7367
|
const who = identity(deps, ctx, key);
|
|
7261
|
-
const
|
|
7262
|
-
|
|
7263
|
-
: null;
|
|
7264
|
-
if (!booking) {
|
|
7368
|
+
const why = upTo(str(args.reason), REFUND_REASON_MAX) || undefined;
|
|
7369
|
+
if (!ot) {
|
|
7265
7370
|
return {
|
|
7266
|
-
structured: { view: '
|
|
7267
|
-
text:
|
|
7371
|
+
structured: { view: 'error', ...common(deps, key), error: 'not-offered' },
|
|
7372
|
+
text: `Refunds are not asked for through ${deps.vocab.brand}.`,
|
|
7373
|
+
isError: true,
|
|
7268
7374
|
};
|
|
7269
7375
|
}
|
|
7376
|
+
const notFound = () => ({
|
|
7377
|
+
structured: { view: 'booking-not-found', ...common(deps, key), query: ref },
|
|
7378
|
+
text: 'No booking here matches that code. Only bookings made here by this account are known, so nothing was refunded.',
|
|
7379
|
+
});
|
|
7380
|
+
// ⚠️ A REFUND IS TWO STEPS ON THE SERVER (总线程's review of 0.63.0, B). The
|
|
7381
|
+
// preview's token stays here, keyed by conversation and booking: it never
|
|
7382
|
+
// goes to the model or the card, and a `confirmed` is sent only with the
|
|
7383
|
+
// token this conversation was given for this booking, unexpired, once.
|
|
7384
|
+
const preview = async () => {
|
|
7385
|
+
const p = await ot.previewRefund(ref, who);
|
|
7386
|
+
if (!p)
|
|
7387
|
+
return notFound();
|
|
7388
|
+
rememberRefund(deps, `${key}|refund|${p.bookingId}`, p.preview, Date.parse(p.until));
|
|
7389
|
+
const booked = await deps.backend.findBooking(ref, who).catch(() => null);
|
|
7390
|
+
const group = holderOf(deps, p.supplier).name;
|
|
7391
|
+
const hotel = booked ? withZh(booked.hotelName, booked.hotelNames, ctx.noCards) : '';
|
|
7392
|
+
const terms = upTo(p.terms, TERMS_TEXT_MAX);
|
|
7393
|
+
const amount = formatMoney(p.amount);
|
|
7394
|
+
return {
|
|
7395
|
+
structured: {
|
|
7396
|
+
view: 'refund-preview',
|
|
7397
|
+
...common(deps, key),
|
|
7398
|
+
booking: {
|
|
7399
|
+
confirmationCode: p.confirmationCode,
|
|
7400
|
+
supplier: p.supplier,
|
|
7401
|
+
...(booked
|
|
7402
|
+
? {
|
|
7403
|
+
hotelName: booked.hotelName,
|
|
7404
|
+
...(booked.hotelNames ? { hotelNames: booked.hotelNames } : {}),
|
|
7405
|
+
stay: booked.stay,
|
|
7406
|
+
}
|
|
7407
|
+
: {}),
|
|
7408
|
+
},
|
|
7409
|
+
amount,
|
|
7410
|
+
fromPayment: p.fromPayment,
|
|
7411
|
+
groupDecides: p.groupDecides,
|
|
7412
|
+
terms,
|
|
7413
|
+
until: p.until,
|
|
7414
|
+
},
|
|
7415
|
+
text: [
|
|
7416
|
+
`Refund preview for ${p.confirmationCode}${hotel ? ` · ${hotel}` : ''}${booked ? ` · ${stayWords(booked.stay, booked.hourly)}` : ''}: all of ${amount} would be asked back from ${group}.`,
|
|
7417
|
+
p.fromPayment ? `The amount is what ${group} says was paid.` : '',
|
|
7418
|
+
p.groupDecides
|
|
7419
|
+
? `What comes back is what ${group} decides - the request names no amount.`
|
|
7420
|
+
: '',
|
|
7421
|
+
`${group}'s terms, ${p.terms ? `in its own words: "${terms}"` : 'none given'}.`,
|
|
7422
|
+
`Nothing has been asked yet. Say this to the guest and get their yes, then call ${t.refundBooking} again with \`confirmed: true\` (this preview can be used until ${clockWords(p.until) ?? p.until}).`,
|
|
7423
|
+
]
|
|
7424
|
+
.filter(Boolean)
|
|
7425
|
+
.join(' '),
|
|
7426
|
+
};
|
|
7427
|
+
};
|
|
7428
|
+
if (args.confirmed !== true)
|
|
7429
|
+
return await preview();
|
|
7430
|
+
const booked = await deps.backend.findBooking(ref, who).catch(() => null);
|
|
7431
|
+
if (!booked)
|
|
7432
|
+
return notFound();
|
|
7433
|
+
const slot = `${key}|refund|${booked.id}`;
|
|
7434
|
+
const kept = refundTokensOf(deps).get(slot);
|
|
7435
|
+
refundTokensOf(deps).delete(slot); // one use, whatever comes of it
|
|
7436
|
+
if (!kept)
|
|
7437
|
+
return await preview();
|
|
7438
|
+
// The backend holds the clock of the preview (`REFUND_PREVIEW_MS`): one that ran
|
|
7439
|
+
// out is refused there with `refund-preview`, and is shown again here.
|
|
7440
|
+
const booking = await ot.refund(ref, who, why, kept.preview).catch((err) => {
|
|
7441
|
+
if (err?.code === 'refund-preview')
|
|
7442
|
+
return 'again';
|
|
7443
|
+
throw err;
|
|
7444
|
+
});
|
|
7445
|
+
if (booking === 'again')
|
|
7446
|
+
return await preview();
|
|
7447
|
+
if (!booking)
|
|
7448
|
+
return notFound();
|
|
7270
7449
|
return {
|
|
7271
7450
|
structured: {
|
|
7272
7451
|
view: 'booking',
|