fortrip 4.1.0 → 4.2.0-rc.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/README.md
CHANGED
|
@@ -83,7 +83,7 @@ other command that needs to save a sign-in exits 1 too. The error says to set
|
|
|
83
83
|
| `orders get <orderId>` | Show an order and its status |
|
|
84
84
|
| `orders list` | List your orders, newest first |
|
|
85
85
|
| `orders cancel <orderId>` | Cancel an order under its terms, for the penalty the user agreed to |
|
|
86
|
-
| `orders pay <orderId>` | Pay an order
|
|
86
|
+
| `orders pay <orderId>` | Pay an order with a Link wallet token (US and Canada) or with Alipay or WeChat Pay, instead of its payment link |
|
|
87
87
|
| `login` | Sign in through the browser |
|
|
88
88
|
| `logout` | Revoke and forget the saved token |
|
|
89
89
|
| `whoami` | Show the signed-in account |
|
|
@@ -106,7 +106,9 @@ same.
|
|
|
106
106
|
|
|
107
107
|
`hotels book` creates an unpaid order and prints a payment link for it.
|
|
108
108
|
Nothing is charged until the person pays on the page the link opens, or
|
|
109
|
-
approves a shared payment token for `orders pay` in their wallet
|
|
109
|
+
approves a shared payment token for `orders pay` in their wallet, or
|
|
110
|
+
scans the WeChat Pay code or opens the Alipay link that `orders pay --wallet`
|
|
111
|
+
prints. Orders
|
|
110
112
|
are paid in USD whatever `--display-currency` shows.
|
|
111
113
|
|
|
112
114
|
`orders get` and `orders list` say of each order whether it can be cancelled
|
package/THIRD-PARTY-NOTICES
CHANGED
|
@@ -28,3 +28,29 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
28
28
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
29
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
30
|
SOFTWARE.
|
|
31
|
+
|
|
32
|
+
================================================================================
|
|
33
|
+
uqr 0.1.3 (MIT)
|
|
34
|
+
--------------------------------------------------------------------------------
|
|
35
|
+
MIT License
|
|
36
|
+
|
|
37
|
+
Copyright (c) Project Nayuki
|
|
38
|
+
Copyright (c) 2023 Anthony Fu <https://github.com/antfu>
|
|
39
|
+
|
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
41
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
42
|
+
in the Software without restriction, including without limitation the rights
|
|
43
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
44
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
45
|
+
furnished to do so, subject to the following conditions:
|
|
46
|
+
|
|
47
|
+
The above copyright notice and this permission notice shall be included in all
|
|
48
|
+
copies or substantial portions of the Software.
|
|
49
|
+
|
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
51
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
52
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
53
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
54
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
55
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
56
|
+
SOFTWARE.
|
|
@@ -14679,7 +14679,7 @@ var LIMITS = {
|
|
|
14679
14679
|
nightsFortrip: 30,
|
|
14680
14680
|
nightsSupplier: 15,
|
|
14681
14681
|
offersHotels: 15,
|
|
14682
|
-
offersPerHotelDefault:
|
|
14682
|
+
offersPerHotelDefault: 10,
|
|
14683
14683
|
offersPerHotelMax: 20,
|
|
14684
14684
|
pageSizeDefault: 20,
|
|
14685
14685
|
pageSizeMax: 50,
|
|
@@ -15132,7 +15132,7 @@ function selectedOf(instruments) {
|
|
|
15132
15132
|
var payOrderInput = strictInput({
|
|
15133
15133
|
orderId: orderId.describe("The orderId of the order to pay."),
|
|
15134
15134
|
sharedPaymentToken: external_exports.string({ error: sharedPaymentTokenError }).regex(sharedPaymentTokenRe, { error: sharedPaymentTokenError }).optional().describe(
|
|
15135
|
-
"The shared payment token (spt_\u2026) the user approved for this order, requested with the order's payment.credentialLimits. Exactly one of sharedPaymentToken and
|
|
15135
|
+
"The shared payment token (spt_\u2026) the user approved for this order, requested with the order's payment.credentialLimits. Exactly one of sharedPaymentToken, payment and method."
|
|
15136
15136
|
),
|
|
15137
15137
|
payment: strictInput({
|
|
15138
15138
|
instruments: external_exports.array(ucpInstrument, { error: instrumentsError }).min(1, { error: instrumentsError }).max(8, { error: instrumentsError }).describe("The instruments, exactly one of them selected.")
|
|
@@ -15168,19 +15168,28 @@ var payOrderInput = strictInput({
|
|
|
15168
15168
|
});
|
|
15169
15169
|
}
|
|
15170
15170
|
}).optional().describe(
|
|
15171
|
-
"UCP's Complete Checkout payment, in place of sharedPaymentToken: the token as the stripe_payment_token credential of the one selected stripe_payments card instrument. Exactly one of sharedPaymentToken and
|
|
15171
|
+
"UCP's Complete Checkout payment, in place of sharedPaymentToken: the token as the stripe_payment_token credential of the one selected stripe_payments card instrument. Exactly one of sharedPaymentToken, payment and method."
|
|
15172
|
+
),
|
|
15173
|
+
method: oneOf("method", ["alipay_wechat_pay"]).optional().describe(
|
|
15174
|
+
"Pay with Alipay or WeChat Pay instead of a token: opens the payment and returns payment.wallets. Exactly one of sharedPaymentToken, payment and method."
|
|
15172
15175
|
),
|
|
15173
15176
|
total: usdMoney.describe(
|
|
15174
15177
|
"The total the user approved: the order's price.total, exactly as returned."
|
|
15175
15178
|
)
|
|
15176
15179
|
}).superRefine((input, ctx) => {
|
|
15177
|
-
|
|
15180
|
+
const given = [
|
|
15181
|
+
["sharedPaymentToken", input.sharedPaymentToken],
|
|
15182
|
+
["payment", input.payment],
|
|
15183
|
+
["method", input.method]
|
|
15184
|
+
].filter(([, value]) => value !== void 0);
|
|
15185
|
+
const extra = given.length > 1 ? given.at(-1) : void 0;
|
|
15186
|
+
if (extra) {
|
|
15178
15187
|
ctx.addIssue({
|
|
15179
15188
|
code: "custom",
|
|
15180
|
-
path: [
|
|
15181
|
-
message: "Send
|
|
15189
|
+
path: [extra[0]],
|
|
15190
|
+
message: "Send exactly one of sharedPaymentToken, payment and method"
|
|
15182
15191
|
});
|
|
15183
|
-
} else if (
|
|
15192
|
+
} else if (given.length === 0) {
|
|
15184
15193
|
ctx.addIssue({
|
|
15185
15194
|
code: "custom",
|
|
15186
15195
|
path: ["sharedPaymentToken"],
|
|
@@ -15440,8 +15449,14 @@ var payFlags = flagsOf(payOrderInput, [
|
|
|
15440
15449
|
field: "sharedPaymentToken",
|
|
15441
15450
|
type: "string",
|
|
15442
15451
|
placeholder: "<spt_\u2026>",
|
|
15443
|
-
|
|
15444
|
-
|
|
15452
|
+
description: "Required unless --wallet. The spt_\u2026 token the user's Link wallet issued for this order."
|
|
15453
|
+
},
|
|
15454
|
+
{
|
|
15455
|
+
flag: "wallet",
|
|
15456
|
+
field: "method",
|
|
15457
|
+
type: "boolean",
|
|
15458
|
+
value: "alipay_wechat_pay",
|
|
15459
|
+
description: "Pay with Alipay or WeChat Pay instead of a token: prints the WeChat Pay code and both links."
|
|
15445
15460
|
},
|
|
15446
15461
|
{
|
|
15447
15462
|
flag: "total",
|
|
@@ -15521,7 +15536,7 @@ var COMMANDS = [
|
|
|
15521
15536
|
{
|
|
15522
15537
|
group: "orders",
|
|
15523
15538
|
name: "pay",
|
|
15524
|
-
summary: "Pay an order
|
|
15539
|
+
summary: "Pay an order with a Link wallet token (US and Canada) or with Alipay or WeChat Pay, instead of its payment link",
|
|
15525
15540
|
tool: "pay_order",
|
|
15526
15541
|
flags: payFlags,
|
|
15527
15542
|
positionals: [positional(payOrderInput, "orderId")]
|
|
@@ -15606,12 +15621,12 @@ var FRAGMENTS = {
|
|
|
15606
15621
|
"errors": "{{#if claude-skill cli}}\n## Errors\n\n{{#if claude-skill}}A tool error{{/if}}{{#if cli}}An error on stderr{{/if}} carries `code`, `message` and `retryable`, and `retryAfterSeconds` when waiting helps; many carry `details`. Search errors are under Search. Ordering errors:\n\n| `code` | Do this |\n|---|---|\n| `offer_changed` (409) | The price or terms changed since the offer: `changes` lists every change (`worse` says which are worse for the user) and `offer` is the new offer. Show the user every change and ask again; if they still want it, order the new offer, and confirm the new order before giving its link |\n| `offer_expired` (409) | Get offers again and let the user choose again |\n| `offer_unavailable` (422) | The offer is sold out or was refused: get offers again and let the user choose again |\n| `order_in_progress` (409) | The same order is still being created: wait `retryAfterSeconds`, then {{#if claude-skill}}call again with the same details{{/if}}{{#if cli}}run the command again with identical flags{{/if}} |\n| `offer_already_ordered` (409) | This offer was already ordered with other details: show that order (`orderId`) instead. An offer is ordered once |\n| `order_exists` (409) | This stay already has an open order for one of these guests (`orderId`, `status`): show it instead of ordering again. A party with none of its guests can order the stay from a new offer (get offers again), and so can the user once the stay's order is confirmed, cancelled or refused by the hotel. It also answers when the stay's earlier order failed at the hotel with its outcome unknown, or the stay has had 20 orders; for those, the user emails {{support}} |\n| `order_attempts_exhausted` (409) | This order can't be tried again: the user emails {{support}} with its `reference` |\n| `order_removed` (410) | The order was never completed and no payment is held: get offers again and order the new offer (the order keeps its `orderId`) |\n| `stay_unsupported` (422) | `mixed_occupancy`: order once per party; `max_nights`: at most `max` nights per order |\n| `stay_in_past` (422) | Check-in has passed in the hotel's time zone: ask for new dates |\n| `ordering_paused` (503) | Ordering is paused on Fortrip's side: tell the user, and try again only after `retryAfterSeconds` (10 minutes or more) |\n\nAny code:\n\n- `invalid_request` (400): `details.issues` lists each bad field; fix them. For amenities, `details.filterable` lists those that can filter.\n- `cursor_invalid` (400): the page is gone; search again from the first page.\n- `not_found` (404): no such hotel, or no such order for this user.\n- `rate_limited` (429): wait `retryAfterSeconds`, then retry once.\n- `service_unavailable` (503) and `supplier_unavailable` (503 or 504): wait `retryAfterSeconds`, then retry once with the same details; if it fails again, tell the user.\n- Any other code: read `message`. If `retryable` is true, wait `retryAfterSeconds` and retry once; otherwise tell the user instead of guessing.\n{{/if}}\n",
|
|
15607
15622
|
"meals": '{{#if claude-skill cli}}\n## Presenting an offer\n\nGive the user, for each offer:\n\n- the room (`room.name`, beds, size) and the total, as above;\n- the meals: `meals.included` (breakfast, lunch, dinner) or `allInclusive`, with `guestsCoveredPerRoom`. Fewer than the guests per room means not everyone gets the meals (breakfast for 1 with 2 adults in the room): say who is covered. `unspecifiedMainMeals` counts main meals the hotel didn\'t name. With `known: false`, the meals are unknown: say so, and don\'t call it room only;\n- cancellation: `status` (`free`, `partial_penalty`, `non_refundable` or `unknown`), `freeCancellationEndsAt` (null with `free`: free until check-in) and the `penalties`. Times are in UTC: also give them in the hotel\'s `timeZone`;\n- confirmation: `mode` `instant` or `on_request` (within `withinMinutes`);\n- fees payable at the property (`payAtProperty.items`), in the property\'s currency. `disclosure: "incomplete"` means there can be fees not listed: say so.\n\nAn offer expires at `expiresAt`, about 30 minutes after it was made; after that, get offers again.\n\n"Not listed" is not "no": `listed: false` (amenities, policies, rooms), `null` and `unknown` mean the source didn\'t say. Tell the user it\'s unknown instead of turning it into "no".\n{{/if}}\n{{#if mcp}}\n- "Not listed" or "unknown" is not "no".\n{{/if}}\n',
|
|
15608
15623
|
"occupancy": "{{#if claude-skill cli}}\n## Rooms and guests\n\n- {{#if mcp claude-skill}}`stay.rooms` lists each room's party as `{ adults, childrenAges }`: two rooms of 2 adults, one with a child of 6, is `[{ adults: 2, childrenAges: [6] }, { adults: 2, childrenAges: [] }]`{{/if}}{{#if cli}}`--room <adults[:age,\u2026]>`, once per room, gives each room's party: two rooms of 2 adults, one with a child of 6, is `--room 2:6 --room 2`{{/if}}.\n- Ask each child's age; offers need it.\n- If the party doesn't split evenly across the rooms (3 adults in 2 rooms), ask the user how it splits.\n{{/if}}\n- Offers and orders take one party per call, every room the same: for different parties, order once per party.{{#if claude-skill cli}} `{{tool:hotels offers}}` answers `stay_unsupported` (`mixed_occupancy`) for mixed rooms; `{{tool:hotels search}}` accepts them but prices only from the dates, with the note `party_split_required`.{{/if}}\n{{#if claude-skill cli}}\n- Limits: 1\u2013{{limit:rooms}} rooms, 1\u2013{{limit:adultsPerRoom}} adults and 0\u2013{{limit:childrenPerRoom}} children (aged 0\u2013{{limit:childAgeMax}}) per room, 1\u2013{{limit:nightsSupplier}} nights, up to {{limit:offersHotels}} hotels per `{{tool:hotels offers}}` call. A longer stay answers `stay_unsupported` (`max_nights`): ask the user whether to split it into consecutive stays, each its own order.\n{{/if}}\n",
|
|
15609
|
-
"order": '{{#if claude-skill cli}}\n## Workflow\n\n1. **Search** with `{{tool:hotels search}}` for candidate hotels: a destination, `{{arg:text}}` or both, and the stay\'s dates and rooms for indicative prices.\n{{#if cli}}\n\n ```bash\n {{tool:hotels search}} --place-name Bangkok --country TH --check-in 2026-11-10 \\\n --check-out 2026-11-12 --room 2 --stars-min 4 --sort price_asc --limit 10\n ```\n\n{{/if}}\n2. **Details** (optional) with `{{tool:hotels get}}`, when the user asks about a hotel or a stated preference needs evidence (a pool, a policy, room size). For a details-only question, call it directly when you know the hotel\'s `hotelId`; otherwise find the hotel with `{{tool:hotels search}}`.\n{{#if cli}}\n\n ```bash\n {{tool:hotels get}} <hotelId> [--rooms]\n ```\n\n{{/if}}\n3. **Offers** with `{{tool:hotels offers}}` for a few shortlisted hotels, with the dates and rooms the user will order. It takes about 15 seconds. A hotel is available only once this returns an offer for it.\n{{#if cli}}\n\n ```bash\n {{tool:hotels offers}} --hotel <hotelId> --hotel <hotelId> --check-in 2026-11-10 \\\n --check-out 2026-11-12 --room 2 --room 2 [--require-free-cancellation]\n ```\n\n{{/if}}\n4. **Order** with `{{tool:hotels book}}`, once the user has picked one offer and given the guests and the contact (see Ordering).\n{{#if cli}}\n\n ```bash\n {{tool:hotels book}} --offer <offerId> --guest 1:John:Smith --guest 2:Mary:Smith \\\n --first-name John --last-name Smith --email john@example.com \\\n --phone "+8613800000000"\n ```\n\n{{/if}}\n5. **Confirm, then give the payment link**, as in "Before giving the payment link" below.\n6. **After payment**, check the order with `{{tool:orders get}}` (see After payment).\n\n## Search\n\n### Where\n\n- **A place by name:** {{#if mcp claude-skill}}`{ kind: "place_name", name, countryCode }`{{/if}}{{#if cli}}`--place-name <name> --country <CC>`{{/if}}, in any language (Kyoto or \u4EAC\u90FD). The country is required: ask the user when it isn\'t clear. Names match exactly, ignoring only case and spacing: accents, hyphens, apostrophes and periods count ("K\xF6ln" or "Cologne", not "Koln"; "St. Moritz", not "St Moritz").\n- If several places bear the name, the answer is `destination_ambiguous` with up to {{limit:candidatesShown}} candidates and their hotel counts: ask the user which one they mean, then search it by its `placeId`; never pick one yourself.\n- `destination_not_found` with `no_match` means no place of that name in that country: check the spelling and accents, or try another name for the place. Its `nameAsText` counts the hotels that a `{{arg:text}}` search for the name would find.\n- **A place from an earlier answer:** {{#if mcp claude-skill}}`{ kind: "place", placeId }`{{/if}}{{#if cli}}`--place <placeId>`{{/if}}.\n- **Near a point:** {{#if mcp claude-skill}}`{ kind: "point", location: { lat, lng } }`{{/if}}{{#if cli}}`--point <lat,lng>`{{/if}}, for "near X" when you know where X is.\n- **A whole country:** {{#if mcp claude-skill}}`{ kind: "country", countryCode }`{{/if}}{{#if cli}}`--country-only <CC>`{{/if}}, as for the Maldives.\n- Countries, regions (states, provinces), prefecture-level cities in China and main islands cover their whole area. Towns, neighbourhoods, districts, small islands and points cover a circle of {{limit:radiusMetersDefault}} meters; `{{arg:destination.radiusMeters}}` sets another, up to {{limit:radiusMetersMax}} meters, and narrows an area to a circle around its center.\n- **Localities:** an area search lists its `localities`, the towns its hotels belong to, each with a `placeId`, its hotel `count` and the places it `includes` (Patong is part of Phuket). To search one, pass it as {{#if mcp claude-skill}}`{ kind: "locality", placeId }`{{/if}}{{#if cli}}`--locality <placeId>`{{/if}}. A town that isn\'t a locality answers `destination_not_found` with `not_a_locality` and the `hub` it belongs to: search the hub, or the town itself with {{#if mcp claude-skill}}`kind: "place"`{{/if}}{{#if cli}}`--place`{{/if}} for a circle around it.\n- A price sort or price filter over more than {{limit:poolLimit}} hotels (in an area, or for text alone) answers `search_too_broad` with `matched` and the top `localities`: show them and ask the user which they prefer, unless the request already names one of them; search that one by its `placeId` as a locality, never by its name.\n\n### Text\n\n`{{arg:text}}` matches exact words in hotel names and addresses, in Chinese or English:\n\n- Every word must match as written: plurals, accents, spacing and abbreviations count ("hostel" and "hostels", "St Regis" and "Saint Regis" find different hotels). Hyphens and apostrophes don\'t (Ritz-Carlton finds Ritz Carlton).\n- In Chinese, matching follows word segmentation, so part of a name can match unrelated hotels (\u5E0C\u5C14 is not \u5E0C\u5C14\u987F).\n- Use only distinctive words: a hotel or brand name, a district or a landmark. Not "hotel", "near", "cheap" or "best".\n- Typos return nothing: "Shangahi" finds no hotel.\n- Place names belong in the destination: "Maldives" as text finds a hotel named Maldives in China.\n\n### Filters\n\n- Stars run from 1 to 5 in half steps{{#if mcp claude-skill}} (`filters.stars`){{/if}}. "4 stars" as {{#if mcp claude-skill}}`{ min: 4, max: 4 }`{{/if}}{{#if cli}}`--stars-min 4 --stars-max 4`{{/if}} leaves out 4.5: unless the user means exactly 4, use {{#if mcp claude-skill}}`{ min: 4 }`{{/if}}{{#if cli}}`--stars-min 4`{{/if}} or ask. Unrated hotels are left out whenever stars are filtered.\n- `{{arg:filters.amenities}}` takes only the amenities that can filter (such as pool, parking, wifi); others, such as gym or spa, show in `{{tool:hotels get}}` but can\'t filter. A hotel matches only when it lists the amenity, and about half the hotels list no amenities at all (`coverage.excludedNoFacilityData` counts those left out): "not listed" is not "absent".\n- `{{arg:filters.price.maxPerRoomNight}}` bounds the indicative price per room per night, in USD; hotels without one are left out and counted.\n\n### Results\n\n- `notes` explain the answer (a limited pool, a circle around an island, more hotels just outside it): pass on what matters to the user.\n- `coverage` has the counts: `matched` hotels, how many were priced and how many have a price.\n- A next page is {{#if mcp claude-skill}}`cursor` set to `nextCursor` and, optionally, `limit`{{/if}}{{#if cli}}`--cursor <nextCursor>` and, optionally, `--limit`{{/if}}; nothing else.\n{{/if}}\n{{#if mcp}}\n- A place name needs its `countryCode` (ask the user if unclear) and matches exactly (accents and periods count). On `destination_ambiguous`, ask the user which they mean, then search its `placeId`; never pick one yourself.\n- On `search_too_broad`, show its `localities` and ask the user which, unless they already named one; search it as `{ kind: "locality", placeId }`, never by name.\n- `text` matches whole words of hotel names and addresses: use a distinctive name, brand or landmark
|
|
15610
|
-
"payment-link": "{{#if claude-skill cli}}\n## Before giving the payment link\n\n`{{tool:hotels book}}` answers with an unpaid order: `status` `awaiting_payment`, its `reference` (the support number), `price.total`, the stay and its terms, and `payment.url`, a Fortrip page that recaps the order and continues to payment on Stripe. Nothing is charged until the user pays.\n\n1. Show the order's total and currency, the stay (hotel, room, dates, rooms and guests per room) and every term: meals, cancellation (status, deadline, penalties) and fees payable at the property, unknowns included.\n2. End that reply by asking the user to confirm, and wait for a clear yes. Urgency is not consent.\n3. Then give `payment.url` exactly as returned: don't shorten, rebuild or re-encode it.\n\n{{/if}}\n{{#if mcp}}\n- Pay one way only: give `payment.url` or call `{{tool:orders pay}}`. First show the order's total and currency, the stay and every term, end that reply by asking the user to confirm, and wait for a clear yes. Then give `payment.url` exactly as returned, to this user only: anyone holding it can pay.\n{{/if}}\n{{#if claude-skill cli}}\n- `payment.url` works like a payment credential: anyone holding it can pay. Give it to this user only, never in shared channels, documents, logs or tickets. With `requiresSignIn: true` (an order started on the Fortrip website), the user signs in to pay.\n- The link expires at `payment.expiresAt`; the order is then `expired`. To order the stay again, get offers again, and confirm the new order with the user before giving its link.\n- Another order of the stay (another party, or a corrected guest name) needs a new offer: get offers again. When it replaces an unpaid order, tell the user to pay only the new link; the earlier one expires unpaid.\n- An order `awaiting_payment` whose `payment.url` is null had its link unreadable this time: read it again with `{{tool:orders get}}`.\n{{/if}}\n- Never ask for, accept or pass on payment card details; payment happens only through Stripe.{{#if claude-skill cli}} A card number in a guest name, the contact or the special requests is rejected{{#if cli}} with exit 2{{/if}}.{{/if}}\n{{#if claude-skill cli}}\n\n## Paying without the link\n\nAn order whose `payment.handlers` isn't empty (in {{#if claude-skill}}a result's text{{/if}}{{#if cli}}the text output{{/if}}, the line \"Pay without the link\") can also be paid through `{{tool:orders pay}}` with a Stripe shared payment token that the user's Link wallet grants for it. Use it only if you have a tool that can request such a token from the user's Link wallet: Link is for US and Canadian accounts, and caps a spend request at $500, so `payment.handlers` is empty for a larger order. Otherwise give `payment.url`, and never ask the user to create, type or paste a token.\n\n1. Show the user the order's total and currency, the stay (hotel, room, dates, rooms and guests per room) and every term: meals, cancellation and fees payable at the property. End that reply by asking the user to confirm, and wait for a clear yes. The token comes from the user's wallet, never from card details.\n2. Request the token from the user's Link wallet with the handler's `config.business_profile` and `payment.credentialLimits`: `maxAmount` (in cents), `currency` and `expiresAt`.\n3. {{#if claude-skill}}Call{{/if}}{{#if cli}}Run{{/if}} `{{tool:orders pay}}` with the token and the order's `price.total`{{#if cli}} (`--token`, `--total`){{/if}}{{#if claude-skill}}, the token as `sharedPaymentToken` or in UCP's `payment.instruments`{{/if}}. The order is then `confirming`, its payment `authorized`: check it as after payment.\n\nThe charge is in USD: a card in another currency may add a foreign transaction fee. Pay one way only: either give `payment.url` or {{#if claude-skill}}call{{/if}}{{#if cli}}run{{/if}} `{{tool:orders pay}}`. Once `{{tool:orders pay}}` succeeds, `payment.url` stops working; a payment that fails leaves the link open. `payment_total_changed` means the total sent isn't the order's (`details.total`); the order's total hasn't changed: confirm it with the user, then {{#if claude-skill}}call{{/if}}{{#if cli}}run{{/if}} `{{tool:orders pay}}` again with it and the same token. `payment_declined`: the user picks another payment method in their wallet, or pays by link. `payment_action_required`: the card needs a verification this can't give: pay by link. `payment_credential_invalid`: request a new token with the order's `payment.credentialLimits`. `service_unavailable`: call `{{tool:orders pay}}` again with the same token, never a new one. A token pays one order only.\n\n## After payment\n\nCheck the order with `{{tool:orders get}}`:\n\n- `confirming` while the hotel confirms, then `confirmed` with the hotel's `confirmationNumber`.\n- `failed`: no stay was booked; `payment.status` says whether the payment was released or refunded.\n- `needs_attention`: Fortrip is looking into it; the user can email {{support}} with the `reference`.\n- `manageUrl` is the user's own page for the order.\n{{/if}}\n",
|
|
15624
|
+
"order": '{{#if claude-skill cli}}\n## Workflow\n\n1. **Search** with `{{tool:hotels search}}` for candidate hotels: a destination, `{{arg:text}}` or both, and the stay\'s dates and rooms for indicative prices.\n{{#if cli}}\n\n ```bash\n {{tool:hotels search}} --place-name Bangkok --country TH --check-in 2026-11-10 \\\n --check-out 2026-11-12 --room 2 --stars-min 4 --sort price_asc --limit 10\n ```\n\n{{/if}}\n2. **Details** (optional) with `{{tool:hotels get}}`, when the user asks about a hotel or a stated preference needs evidence (a pool, a policy, room size). For a details-only question, call it directly when you know the hotel\'s `hotelId`; otherwise find the hotel with `{{tool:hotels search}}`.\n{{#if cli}}\n\n ```bash\n {{tool:hotels get}} <hotelId> [--rooms]\n ```\n\n{{/if}}\n3. **Offers** with `{{tool:hotels offers}}` for a few shortlisted hotels, with the dates and rooms the user will order. It takes about 15 seconds. A hotel is available only once this returns an offer for it.\n{{#if cli}}\n\n ```bash\n {{tool:hotels offers}} --hotel <hotelId> --hotel <hotelId> --check-in 2026-11-10 \\\n --check-out 2026-11-12 --room 2 --room 2 [--require-free-cancellation]\n ```\n\n{{/if}}\n4. **Order** with `{{tool:hotels book}}`, once the user has picked one offer and given the guests and the contact (see Ordering).\n{{#if cli}}\n\n ```bash\n {{tool:hotels book}} --offer <offerId> --guest 1:John:Smith --guest 2:Mary:Smith \\\n --first-name John --last-name Smith --email john@example.com \\\n --phone "+8613800000000"\n ```\n\n{{/if}}\n5. **Confirm, then give the payment link**, as in "Before giving the payment link" below.\n6. **After payment**, check the order with `{{tool:orders get}}` (see After payment).\n\n## Search\n\n### Where\n\n- **A place by name:** {{#if mcp claude-skill}}`{ kind: "place_name", name, countryCode }`{{/if}}{{#if cli}}`--place-name <name> --country <CC>`{{/if}}, in any language (Kyoto or \u4EAC\u90FD). The country is required: ask the user when it isn\'t clear. Names match exactly, ignoring only case and spacing: accents, hyphens, apostrophes and periods count ("K\xF6ln" or "Cologne", not "Koln"; "St. Moritz", not "St Moritz").\n- If several places bear the name, the answer is `destination_ambiguous` with up to {{limit:candidatesShown}} candidates and their hotel counts: ask the user which one they mean, then search it by its `placeId`; never pick one yourself.\n- `destination_not_found` with `no_match` means no place of that name in that country: check the spelling and accents, or try another name for the place. Its `nameAsText` counts the hotels that a `{{arg:text}}` search for the name would find.\n- **A place from an earlier answer:** {{#if mcp claude-skill}}`{ kind: "place", placeId }`{{/if}}{{#if cli}}`--place <placeId>`{{/if}}.\n- **Near a point:** {{#if mcp claude-skill}}`{ kind: "point", location: { lat, lng } }`{{/if}}{{#if cli}}`--point <lat,lng>`{{/if}}, for "near X" when you know where X is.\n- **A whole country:** {{#if mcp claude-skill}}`{ kind: "country", countryCode }`{{/if}}{{#if cli}}`--country-only <CC>`{{/if}}, as for the Maldives.\n- Countries, regions (states, provinces), prefecture-level cities in China and main islands cover their whole area. Towns, neighbourhoods, districts, small islands and points cover a circle of {{limit:radiusMetersDefault}} meters; `{{arg:destination.radiusMeters}}` sets another, up to {{limit:radiusMetersMax}} meters, and narrows an area to a circle around its center.\n- **Localities:** an area search lists its `localities`, the towns its hotels belong to, each with a `placeId`, its hotel `count` and the places it `includes` (Patong is part of Phuket). To search one, pass it as {{#if mcp claude-skill}}`{ kind: "locality", placeId }`{{/if}}{{#if cli}}`--locality <placeId>`{{/if}}. A town that isn\'t a locality answers `destination_not_found` with `not_a_locality` and the `hub` it belongs to: search the hub, or the town itself with {{#if mcp claude-skill}}`kind: "place"`{{/if}}{{#if cli}}`--place`{{/if}} for a circle around it.\n- A price sort or price filter over more than {{limit:poolLimit}} hotels (in an area, or for text alone) answers `search_too_broad` with `matched` and the top `localities`: show them and ask the user which they prefer, unless the request already names one of them; search that one by its `placeId` as a locality, never by its name.\n\n### Text\n\n`{{arg:text}}` matches exact words in hotel names and addresses, in Chinese or English:\n\n- Every word must match as written: plurals, accents, spacing and abbreviations count ("hostel" and "hostels", "St Regis" and "Saint Regis" find different hotels). Hyphens and apostrophes don\'t (Ritz-Carlton finds Ritz Carlton).\n- In Chinese, matching follows word segmentation, so part of a name can match unrelated hotels (\u5E0C\u5C14 is not \u5E0C\u5C14\u987F).\n- Use only distinctive words: a hotel or brand name, a district or a landmark. Not "hotel", "near", "cheap" or "best".\n- Typos return nothing: "Shangahi" finds no hotel.\n- Place names belong in the destination: "Maldives" as text finds a hotel named Maldives in China.\n\n### Filters\n\n- Stars run from 1 to 5 in half steps{{#if mcp claude-skill}} (`filters.stars`){{/if}}. "4 stars" as {{#if mcp claude-skill}}`{ min: 4, max: 4 }`{{/if}}{{#if cli}}`--stars-min 4 --stars-max 4`{{/if}} leaves out 4.5: unless the user means exactly 4, use {{#if mcp claude-skill}}`{ min: 4 }`{{/if}}{{#if cli}}`--stars-min 4`{{/if}} or ask. Unrated hotels are left out whenever stars are filtered.\n- `{{arg:filters.amenities}}` takes only the amenities that can filter (such as pool, parking, wifi); others, such as gym or spa, show in `{{tool:hotels get}}` but can\'t filter. A hotel matches only when it lists the amenity, and about half the hotels list no amenities at all (`coverage.excludedNoFacilityData` counts those left out): "not listed" is not "absent".\n- `{{arg:filters.price.maxPerRoomNight}}` bounds the indicative price per room per night, in USD; hotels without one are left out and counted.\n\n### Results\n\n- `notes` explain the answer (a limited pool, a circle around an island, more hotels just outside it): pass on what matters to the user.\n- `coverage` has the counts: `matched` hotels, how many were priced and how many have a price.\n- A next page is {{#if mcp claude-skill}}`cursor` set to `nextCursor` and, optionally, `limit`{{/if}}{{#if cli}}`--cursor <nextCursor>` and, optionally, `--limit`{{/if}}; nothing else.\n{{/if}}\n{{#if mcp}}\n- A place name needs its `countryCode` (ask the user if unclear) and matches exactly (accents and periods count). On `destination_ambiguous`, ask the user which they mean, then search its `placeId`; never pick one yourself.\n- On `search_too_broad`, show its `localities` and ask the user which, unless they already named one; search it as `{ kind: "locality", placeId }`, never by name.\n- `text` matches whole words of hotel names and addresses: use a distinctive name, brand or landmark.\n{{/if}}\n',
|
|
15625
|
+
"payment-link": "{{#if claude-skill cli}}\n## Before giving the payment link\n\n`{{tool:hotels book}}` answers with an unpaid order: `status` `awaiting_payment`, its `reference` (the support number), `price.total`, the stay and its terms, and `payment.url`, a Fortrip page that recaps the order and continues to payment on Stripe. Nothing is charged until the user pays.\n\n1. Show the order's total and currency, the stay (hotel, room, dates, rooms and guests per room) and every term: meals, cancellation (status, deadline, penalties) and fees payable at the property, unknowns included.\n2. End that reply by asking the user to confirm, and wait for a clear yes. Urgency is not consent.\n3. Then give `payment.url` exactly as returned: don't shorten, rebuild or re-encode it.\n\n{{/if}}\n{{#if mcp}}\n- Pay one way only: give `payment.url` or call `{{tool:orders pay}}`. First show the order's total and currency, the stay and every term, end that reply by asking the user to confirm, and wait for a clear yes. Then give `payment.url` exactly as returned, to this user only: anyone holding it can pay.\n{{/if}}\n{{#if claude-skill cli}}\n- `payment.url` works like a payment credential: anyone holding it can pay. Give it to this user only, never in shared channels, documents, logs or tickets. With `requiresSignIn: true` (an order started on the Fortrip website), the user signs in to pay.\n- The link expires at `payment.expiresAt`; the order is then `expired`. To order the stay again, get offers again, and confirm the new order with the user before giving its link.\n- Another order of the stay (another party, or a corrected guest name) needs a new offer: get offers again. When it replaces an unpaid order, tell the user to pay only the new link; the earlier one expires unpaid.\n- An order `awaiting_payment` whose `payment.url` is null had its link unreadable this time: read it again with `{{tool:orders get}}`.\n{{/if}}\n- Never ask for, accept or pass on payment card details; payment happens only through Stripe.{{#if claude-skill cli}} A card number in a guest name, the contact or the special requests is rejected{{#if cli}} with exit 2{{/if}}.{{/if}}\n{{#if claude-skill cli}}\n\n## Paying without the link\n\nAn order whose `payment.handlers` isn't empty (in {{#if claude-skill}}a result's text{{/if}}{{#if cli}}the text output{{/if}}, the line \"Pay without the link\") can also be paid through `{{tool:orders pay}}` with a Stripe shared payment token that the user's Link wallet grants for it. Use it only if you have a tool that can request such a token from the user's Link wallet: Link is for US and Canadian accounts, and caps a spend request at $500, so `payment.handlers` is empty for a larger order. Otherwise give `payment.url`, and never ask the user to create, type or paste a token.\n\n1. Show the user the order's total and currency, the stay (hotel, room, dates, rooms and guests per room) and every term: meals, cancellation and fees payable at the property. End that reply by asking the user to confirm, and wait for a clear yes. The token comes from the user's wallet, never from card details.\n2. Request the token from the user's Link wallet with the handler's `config.business_profile` and `payment.credentialLimits`: `maxAmount` (in cents), `currency` and `expiresAt`.\n3. {{#if claude-skill}}Call{{/if}}{{#if cli}}Run{{/if}} `{{tool:orders pay}}` with the token and the order's `price.total`{{#if cli}} (`--token`, `--total`){{/if}}{{#if claude-skill}}, the token as `sharedPaymentToken` or in UCP's `payment.instruments`{{/if}}. The order is then `confirming`, its payment `authorized`: check it as after payment.\n\nThe charge is in USD: a card in another currency may add a foreign transaction fee. Pay one way only: either give `payment.url` or {{#if claude-skill}}call{{/if}}{{#if cli}}run{{/if}} `{{tool:orders pay}}`. Once `{{tool:orders pay}}` succeeds, `payment.url` stops working; a payment that fails leaves the link open. `payment_total_changed` means the total sent isn't the order's (`details.total`); the order's total hasn't changed: confirm it with the user, then {{#if claude-skill}}call{{/if}}{{#if cli}}run{{/if}} `{{tool:orders pay}}` again with it and the same token. `payment_declined`: the user picks another payment method in their wallet, or pays by link. `payment_action_required`: the card needs a verification this can't give: pay by link. `payment_credential_invalid`: request a new token with the order's `payment.credentialLimits`. `service_unavailable`: call `{{tool:orders pay}}` again with the same token, never a new one. A token pays one order only.\n\n## Paying with Alipay or WeChat Pay\n\nAn order whose result text has the line \"Pay with Alipay or WeChat Pay\" can be paid in the user's Alipay or WeChat wallet, with no token: it is for users who have a mainland-China wallet. {{#if claude-skill}}Call{{/if}}{{#if cli}}Run{{/if}} `{{tool:orders pay}}` {{#if claude-skill}}with `method` `alipay_wechat_pay`{{/if}}{{#if cli}}the way that line shows{{/if}} and the order's `price.total`, only after the user has confirmed.\n\n1. Show the user the order's total in USD, the stay (hotel, room, dates, rooms and guests per room) and every term: meals, cancellation and fees payable at the property. End that reply by asking the user to confirm, and wait for a clear yes. Pay one way only: `payment.url` or this.\n2. Then show `payment.wallets`: the WeChat Pay code as an image if you can, and both links (WeChat Pay and Alipay). The user pays once, by either. Alipay and WeChat Pay charge at once; if the hotel can't confirm, the payment is refunded in full. The total is in US dollars, and the wallets show it in yuan at their rate.\n3. Check the order with `{{tool:orders get}}` until it isn't `awaiting_payment`.\n\nA code goes dead when the user opens the Alipay link instead, or when it expires. Then `payment.wallets.wechatPay.qrData` is null: tell the user to open the WeChat link again, or {{#if claude-skill}}call{{/if}}{{#if cli}}run{{/if}} `{{tool:orders pay}}` again for a new code.\n\nWeChat can't scan a code shown on the same phone's screen. Offer both ways, since you can't tell which device the user is on: save the image and scan it from the album (WeChat, then Scan, then Album), or open the WeChat link on another screen; on a phone, the Alipay link opens the Alipay app.\n\n## After payment\n\nCheck the order with `{{tool:orders get}}`:\n\n- `confirming` while the hotel confirms, then `confirmed` with the hotel's `confirmationNumber`.\n- `failed`: no stay was booked; `payment.status` says whether the payment was released or refunded.\n- `needs_attention`: Fortrip is looking into it; the user can email {{support}} with the `reference`.\n- `manageUrl` is the user's own page for the order.\n{{/if}}\n",
|
|
15611
15626
|
"planning": "# Planning a hotel stay\n\nRead this when the request is more than one hotel for fixed dates: flexible dates, a budget, split stays, several destinations, or \"find me the best\". The rules in {{#if mcp}}the server instructions{{/if}}{{#if claude-skill}}SKILL.md{{/if}}{{#if cli}}`{{tool:guide}}`{{/if}} still apply (call order, destinations, one party per offer and order, confirming the order `{{tool:hotels book}}` returns before giving the payment link); this covers what to ask, how to compare and how to present.{{#if cli}} As there, `fortrip` is short for `npx -y fortrip@latest`.{{/if}}\n\n## What to collect\n\nKeep track of: dates (or the flexible window), nights, destination(s) with their country, rooms and the guests in each room, room constraints (beds, connecting rooms, accessibility), budget, and what the user said matters most (cheapest, most flexible, closest to X).\n\nOffers and orders take one party per call, every room the same, so if the party doesn't split evenly across the rooms, ask how it splits. Rooms for different parties are priced and ordered separately, each order with its own payment link.\n\nAsk only for what changes which hotels qualify or how they rank. \"4 stars\" as {{#if mcp claude-skill}}`{ min: 4, max: 4 }`{{/if}}{{#if cli}}`--stars-min 4 --stars-max 4`{{/if}} leaves out 4.5: unless the user means exactly 4, use {{#if mcp claude-skill}}`{ min: 4 }`{{/if}}{{#if cli}}`--stars-min 4`{{/if}} or ask. If children come along, ask each child's age; `{{tool:hotels offers}}` needs it. Don't ask for trip type or style: infer it from the conversation or leave it general. When a place name is ambiguous, ask which place the user means.\n\n## Evidence\n\n- A `{{tool:hotels search}}` price is an indicative estimate per room per night, not a quote. Never call a search result available or bookable, and once you have offers, compare offers only. A hotel without a search price can still have offers.\n- Use `{{tool:hotels get}}` only when a stated preference needs evidence (a pool, a policy, room size). An amenity or policy it doesn't list is unknown, not absent.\n- A hotel is available only once `{{tool:hotels offers}}` returned an offer for it.\n- Anything {{#if mcp claude-skill}}the tools{{/if}}{{#if cli}}the CLI{{/if}} didn't return, such as reviews, style, price trends or exchange rates other than `approx`, is unknown. Say so instead of filling it in.\n\n## Ranking\n\n1. Drop options that break a hard constraint (dates, guests, budget cap, required facility). Compare a budget in the unit the user gave it: per night, per room or for the whole stay. An offer's `price.total` covers the whole stay and every room, in USD.\n2. Keep only options with a live offer.\n3. Order by the user's stated main goal. Goals they didn't state don't count.\n4. Use other preferences only to break ties.\n\nUse the cheapest comparable offer as the baseline unless the user fixed the room type. Show at most three plans, each with its price difference from the baseline and what it trades off (meals, cancellation, location, confirmation). Keep hotel names as returned and dates in the user's notation.\n\nFor a split stay or several destinations, price each leg with its own `{{tool:hotels offers}}` call and add up the legs. Each leg is a separate `{{tool:hotels book}}` call, with its own confirmation and its own payment link.\n\n## Stop and say so\n\n- `{{tool:hotels offers}}` covers up to {{limit:offersHotels}} hotels per call and takes about 15 seconds, and its offers expire after about 30 minutes. If the request needs more hotels or date combinations than a few calls can cover, narrow it with the user, or present the result as a comparison of the hotels you priced, not the best overall.\n- When a search is too broad to price, show its localities and ask the user which they prefer, unless the request already names one of them; never pick one yourself.\n- Urgency is not consent. Call `{{tool:hotels book}}` only for the offer the user picked, and give its payment link only after the user confirms the total, currency, stay and terms of the order `{{tool:hotels book}}` returned.\n",
|
|
15612
15627
|
"presentation": "{{#if claude-skill}}\n## Presenting hotels\n\nIf your interface can show rich elements, show each hotel as a card with only what Fortrip's tools returned for it in this conversation: photo, name, stars, region and price, and once you have offers every term that changes the choice (meals and who they cover, cancellation, fees payable at the property, confirmation), an unknown one as unknown. Label a search's `price.fromPerRoomNight` as an estimate per room-night and an offer's `price.total` as the whole stay for all rooms, in USD, and draw a map only from returned `location` coordinates. Offer the choices you need to ask anyway (dates, a locality, which offer) as options to pick. Otherwise use a short list. Keep hotel names as returned, and never invent photos, ratings, reviews, prices, terms or coordinates.\n{{/if}}\n",
|
|
15613
15628
|
"prices": "{{#if claude-skill cli}}\n## Prices and currency\n\n- A search price (`price.fromPerRoomNight`) is indicative and not bookable: the lowest price of one unit (a room or, at a hostel, possibly a bed) per night, for any party and often any date, and it can be well above or below the offers. Call it an estimate, quote `{{tool:hotels offers}}` prices, and never call a search result available or bookable. `price: null` means there is no indicative price, not that the hotel is full; about half the hotels have none for given dates.\n{{/if}}\n{{#if mcp}}\n- Search prices are indicative, not bookable: quote `{{tool:hotels offers}}` prices.\n{{/if}}\n- {{#if claude-skill cli}}In an offer or order, {{/if}}`price.total` is the whole stay for all rooms and is what is charged, in USD for offers and the orders made from them.{{#if claude-skill cli}} `perNightAllRooms` is the total per night; to compare with a per-room budget, also divide by the rooms.{{/if}} Stripe's page may let the user pay in their card's local currency at Stripe's rate{{#if claude-skill cli}} (Adaptive Pricing): say so plainly, and that the USD total is the price{{/if}}. `approx`{{#if claude-skill cli}}, in `{{arg:displayCurrency}}`, with its `rateDate`,{{/if}} is an estimate, never the charge.\n{{#if claude-skill cli}}\n- `{{arg:displayCurrency}}`{{#if cli}} (or `FORTRIP_DISPLAY_CURRENCY`){{/if}} is `USD` or `CNY`: `CNY` adds `approx` in yuan to suit a user who thinks in it. It never changes the charge.\n- Fees payable at the property (`payAtProperty`) are separate, in the property's own currency, not converted.\n- After payment, `payment.localCharge` is what the card paid in its own currency. Orders made on the Fortrip website can be charged in another currency: `payment.chargeCurrency` says which.\n{{/if}}\n",
|
|
15614
|
-
"scope": "{{#if claude-skill cli}}\n# Fortrip hotel stays\n\n{{/if}}\nFortrip: hotel search, live offers and orders with a payment link.{{#if claude-skill cli}} Not for flights, activities, or changing an existing order.{{/if}}\n\n{{#if mcp}}\nCall order: `{{tool:hotels search}}` \u2192 (optional) `{{tool:hotels get}}` \u2192 `{{tool:hotels offers}}` \u2192 `{{tool:hotels book}}`; after the user pays, `{{tool:orders get}}`; `{{tool:orders list}}` lists
|
|
15629
|
+
"scope": "{{#if claude-skill cli}}\n# Fortrip hotel stays\n\n{{/if}}\nFortrip: hotel search, live offers and orders with a payment link.{{#if claude-skill cli}} Not for flights, activities, or changing an existing order.{{/if}}\n\n{{#if mcp}}\nCall order: `{{tool:hotels search}}` \u2192 (optional) `{{tool:hotels get}}` \u2192 `{{tool:hotels offers}}` \u2192 `{{tool:hotels book}}`; after the user pays, `{{tool:orders get}}`; `{{tool:orders list}}` lists, `{{tool:orders cancel}}` cancels, `{{tool:orders pay}}` pays by token or Alipay/WeChat Pay. `{{tool:guide}}` returns Fortrip's guidance for flexible dates, budgets or several destinations.\n{{/if}}\n{{#if claude-skill}}\nThe tools are on Fortrip's MCP server, named `fortrip` in this plugin (a Fortrip connector added on claude.ai can show under its own name). They're written `fortrip:<tool>` below:\n{{/if}}\n{{#if cli}}\nThe `fortrip` CLI (npm package `fortrip`) calls Fortrip as the signed-in user and prints each answer as compact text (`--json` prints its JSON):\n{{/if}}\n{{#if claude-skill cli}}\n\n| {{#if claude-skill}}Tool{{/if}}{{#if cli}}Command{{/if}} | Returns |\n|---|---|\n| `{{tool:hotels search}}` | Hotels in a place, near a point or matching a name (`{{arg:text}}`), with indicative prices |\n| `{{tool:hotels get}}` | One hotel's address, check-in and check-out times, description, policies, amenities and rooms; no prices |\n| `{{tool:hotels offers}}` | Live offers (room, meals, total in USD, cancellation terms) for up to {{limit:offersHotels}} hotels |\n| `{{tool:hotels book}}` | An unpaid order for one offer, with its terms and a payment link |\n| `{{tool:orders get}}` | One order and its status, including whether the hotel confirmed it |\n| `{{tool:orders list}}` | The user's orders, newest first, including those made on the Fortrip website |\n| `{{tool:orders cancel}}` | Cancels an order under its terms, for the penalty the user agreed to, and refunds the rest |\n| `{{tool:orders pay}}` | Pays an order without its link, by a shared payment token from the user's wallet, or with Alipay or WeChat Pay |\n\nFor flexible dates, a budget, split stays, several destinations or \"find me the best\", {{#if claude-skill}}read [references/planning.md](references/planning.md){{/if}}{{#if cli}}also run `{{tool:guide}} planning`{{/if}} before searching.\n{{/if}}\n",
|
|
15615
15630
|
"setup": "{{#if cli}}\n## Setup\n\nRun every command as `npx -y fortrip@latest <command>` (Node.js 22 or newer). The examples below shorten that to `fortrip`; `fortrip <command> --help` lists a command's flags. `{{tool:hotels search}}`, `{{tool:hotels offers}}` and `{{tool:hotels book}}` also take `--body '<json>'` (or `--body @file.json`), the raw request body; flags override its fields. Add `--json` to any command that calls Fortrip to get its answer as one line of JSON instead of text.\n\nWhen the user first asks about hotels, run `{{tool:whoami}}` before asking follow-up questions, so the sign-in can happen while they answer.\n\n{{/if}}\n{{#if claude-skill cli}}\n## Sign-in\n\n{{/if}}\nSign-in happens only in the browser. Never ask the user to paste a token.\n{{#if claude-skill}}\n\nIf none of these tools are available, Fortrip isn't connected: tell the user to add the Fortrip connector or plugin and sign in.\n{{/if}}\n{{#if mcp claude-skill}}\nIf a tool says the user isn't signed in, ask them to reconnect.\n{{/if}}\n{{#if cli}}\n\nIf a command exits with code **3** and stderr has `loginUrl`, show it to the user as a link together with `userCode`, e.g. \"Sign in to Fortrip: <loginUrl> (code <userCode>), then tell me when you're done.\" When they confirm, rerun the same command; it finishes the sign-in itself. Don't run `{{tool:login}}`: it waits for up to 10 minutes. Commands that exit 3 together share one `loginUrl`; show it once. If the rerun gives a different `loginUrl`, show that one.\n\nWhen Fortrip no longer accepts the saved sign-in (it was revoked, or it expired and couldn't be renewed), the command also exits 3 with a `loginUrl`; handle it the same way. The saved sign-in is kept until the user approves the new link.\n\nIn CI or a sandbox without a browser, the user can set `FORTRIP_TOKEN` instead. Exit 3 with `tokenSource: \"FORTRIP_TOKEN\"` means Fortrip didn't accept that token: tell the user to replace or unset it.\n\n## Exit codes\n\n| Code | Meaning | What to do |\n|---|---|---|\n| 0 | Success; the answer on stdout | Continue |\n| 1 | Any other error: an error from Fortrip (see Errors), a network error or a timeout | Read the error on stderr. If `retryable` is true, wait `retryAfterSeconds` (or a few seconds) and retry once |\n| 2 | Invalid arguments, or `invalid_request` from Fortrip | Fix the flags; the error lists each bad field with a message |\n| 3 | Not signed in | Show `loginUrl` to the user, then rerun (above) |\n| 4 | Rate limited | Wait `retryAfterSeconds`, then retry once |\n\nOutput on stdout or stderr can carry `warning` (with `recoveryFile` when a sign-in couldn't be saved): pass it on to the user.\n{{/if}}\n",
|
|
15616
15631
|
"support": "{{#if claude-skill cli}}\n## Cancelling an order\n\n`{{tool:orders get}}` and `{{tool:orders list}}` say of each order whether the user can cancel it now (`cancel.available`), and then the penalty under its terms (`cancel.penalty`) and the refund, what was paid less the penalty (`cancel.refund`), both in the charge currency; otherwise `cancel.reason` says why not.\n\n1. Show the user the stay (hotel, dates), `cancel.penalty` and `cancel.refund` (amount and currency). A refund of 0 means nothing is paid back: say so plainly.\n2. End that reply by asking the user to confirm the cancellation, and wait for a clear yes.\n3. Then {{#if claude-skill}}call{{/if}}{{#if cli}}run{{/if}} `{{tool:orders cancel}}` with `{{arg:maximumPenalty}}` set to `cancel.penalty.amount` as shown. Never state a refund the order didn't return, and never choose or work out an amount yourself.\n\nThe order is then `cancelling`, and `cancelled` once the hotel has cancelled and the refund is issued: check it with `{{tool:orders get}}`. If the hotel refuses, the order is `confirmed` again with `cancel.reason` `refused`. `cancellation_changed` (409) means the penalty is now higher than the one the user agreed to: read the order again and ask the user again. `order_not_cancellable` (409) says why in `reason`.{{#if cli}} Without `--max-penalty`, `{{tool:orders cancel}}` cancels nothing: it prints the penalty and the refund and exits 2.{{/if}}\n\n## Changes and support\n\n{{/if}}\n{{#if mcp}}For changes{{/if}}{{#if claude-skill}}These tools can't change an order: for changes{{/if}}{{#if cli}}The CLI can't change an order: for changes{{/if}}, a cancellation that `{{tool:orders cancel}}` can't make, or other problems, the user emails {{support}} with the order's `reference` (never `payment.url`).\n"
|
|
15617
15632
|
};
|
|
@@ -16245,6 +16260,24 @@ var order = openObject({
|
|
|
16245
16260
|
)
|
|
16246
16261
|
}).nullable().describe(
|
|
16247
16262
|
"What the shared payment token for pay_order must allow. null exactly when handlers is []."
|
|
16263
|
+
),
|
|
16264
|
+
/** Paying with Alipay or WeChat Pay through `pay_order`'s `method`.
|
|
16265
|
+
* `null` when it is neither offered for the order nor open on it. */
|
|
16266
|
+
wallets: openObject({
|
|
16267
|
+
open: external_exports.boolean().describe("Whether pay_order has opened a wallet payment on this order."),
|
|
16268
|
+
current: openEnum(["wechat_pay", "alipay"]).nullable().describe("The wallet the payment is on now; null until it is open."),
|
|
16269
|
+
wechatPay: openObject({
|
|
16270
|
+
qrData: external_exports.string().nullable().describe(
|
|
16271
|
+
"The WeChat Pay code's content, to draw as a QR code; null when there is no live code (open wechatPay.url for one)."
|
|
16272
|
+
),
|
|
16273
|
+
qrImageUrl: external_exports.string().nullable().describe("A 480 px PNG of the same code."),
|
|
16274
|
+
url: external_exports.string().describe("A link, on fortrip.ai, for the user to pay with WeChat Pay; anyone holding it can pay.")
|
|
16275
|
+
}).nullable().describe("The WeChat Pay code and link; null until the payment is open."),
|
|
16276
|
+
alipay: openObject({
|
|
16277
|
+
url: external_exports.string().describe("A link, on fortrip.ai, for the user to pay with Alipay; anyone holding it can pay.")
|
|
16278
|
+
}).nullable().describe("The Alipay link; null until the payment is open.")
|
|
16279
|
+
}).nullable().describe(
|
|
16280
|
+
"Paying with Alipay or WeChat Pay: pass method alipay_wechat_pay to pay_order to open it. null when the order can't be paid this way and none is open."
|
|
16248
16281
|
)
|
|
16249
16282
|
}),
|
|
16250
16283
|
/** Whether the user can cancel the order now and, when they can, its
|
|
@@ -16291,6 +16324,9 @@ var CALLS = {
|
|
|
16291
16324
|
cancel: "call cancel_order",
|
|
16292
16325
|
penalty: 'Pass maximumPenalty as the number in cancel.penalty.amount ("120.00" \u2192 120).',
|
|
16293
16326
|
pay: "call pay_order",
|
|
16327
|
+
payWallet: " with method alipay_wechat_pay",
|
|
16328
|
+
get: "call get_order",
|
|
16329
|
+
poll: "poll get_order",
|
|
16294
16330
|
payWith: "call pay_order with it and the order's price.total",
|
|
16295
16331
|
paid: "pay_order"
|
|
16296
16332
|
},
|
|
@@ -16298,6 +16334,9 @@ var CALLS = {
|
|
|
16298
16334
|
cancel: "run `fortrip orders cancel <orderId> --max-penalty <n>`",
|
|
16299
16335
|
penalty: "Pass the penalty's amount as --max-penalty (120.00 for a penalty of USD 120.00).",
|
|
16300
16336
|
pay: "run `fortrip orders pay`",
|
|
16337
|
+
payWallet: " with --wallet",
|
|
16338
|
+
get: "run `fortrip orders get <orderId>`",
|
|
16339
|
+
poll: "poll it with `fortrip orders get <orderId>`",
|
|
16301
16340
|
payWith: "run `fortrip orders pay <orderId> --token <spt_\u2026> --total <total>` with the token and the order's total",
|
|
16302
16341
|
paid: "`fortrip orders pay`"
|
|
16303
16342
|
}
|
|
@@ -16312,6 +16351,11 @@ function payNextStep(surface) {
|
|
|
16312
16351
|
return `To pay without the link: only if you have a tool that can request a Stripe shared payment token from the user's Link wallet (US and Canadian Link accounts), and the order's payment.handlers isn't empty. Otherwise give payment.url, and never ask the user to create, type or paste a token. Before you ${c.pay}, show the user the order's total and currency, the stay (hotel, room, dates, rooms and guests per room) and every term (meals, cancellation, fees payable at the property), then end your reply by asking them to confirm, and wait for a clear yes. Then request the token for this order from the user's Link wallet with the handler's config.business_profile and payment.credentialLimits (maxAmount in cents, currency, expiresAt), and ${c.payWith}. The charge is in USD: a card in another currency may add a foreign transaction fee. Pay one way only: either give payment.url or ${c.pay}. Once ${c.paid} succeeds, payment.url stops working; a failed payment leaves it open.`;
|
|
16313
16352
|
}
|
|
16314
16353
|
var PAY_NEXT_STEP = payNextStep("mcp");
|
|
16354
|
+
function walletNextStep(surface) {
|
|
16355
|
+
const c = CALLS[surface];
|
|
16356
|
+
return `Before you ${c.pay}${c.payWallet}, show the user the order's total in USD, the stay (hotel, room, dates, rooms and guests per room) and every term (meals, cancellation, fees payable at the property), then ask them to confirm, and wait for a clear yes. Then show payment.wallets: the WeChat code as an image if you can, and both links. The user pays once, by one of them. Alipay and WeChat Pay charge at once; if the hotel can't confirm, the payment is refunded in full. Then ${c.poll}.`;
|
|
16357
|
+
}
|
|
16358
|
+
var WALLET_NEXT_STEP = walletNextStep("mcp");
|
|
16315
16359
|
var nextStep = external_exports.string().optional().describe(
|
|
16316
16360
|
"What to show and ask before giving a payment.url. Present when the answer holds a non-null payment.url, and only then."
|
|
16317
16361
|
);
|
|
@@ -16365,7 +16409,7 @@ var TOOLS = [
|
|
|
16365
16409
|
{
|
|
16366
16410
|
name: "book_hotel",
|
|
16367
16411
|
title: "Create hotel order and payment link",
|
|
16368
|
-
description: `Order one offer from get_hotel_offers. The answer is an unpaid order with a payment link: status awaiting_payment, the total, the stay and its terms, and payment.url, a Fortrip page
|
|
16412
|
+
description: `Order one offer from get_hotel_offers. The answer is an unpaid order with a payment link: status awaiting_payment, the total, the stay and its terms, and payment.url, a Fortrip page to pay on. Nothing is charged until the order is paid, on that page or with pay_order (or Alipay/WeChat Pay); anyone holding the link can pay. Send the contact and, for each room of the offer, at least one guest. If the price or terms changed since the offer, the answer is offer_changed with every change and a new offer: show the changes and ask the user again before ordering it. Sending the same details again returns the same order. An offer is ordered once: for another order of the stay (another party, or a corrected guest name), get offers again and order the new offer; when it replaces an unpaid order, tell the user to pay only the new link, as the earlier one expires unpaid. To cancel an order, use cancel_order; for changes, or a cancellation cancel_order can't make, the user emails ${SUPPORT_EMAIL} with the order's reference.`,
|
|
16369
16413
|
annotations: {
|
|
16370
16414
|
readOnlyHint: false,
|
|
16371
16415
|
idempotentHint: false,
|
|
@@ -16406,8 +16450,8 @@ var TOOLS = [
|
|
|
16406
16450
|
},
|
|
16407
16451
|
{
|
|
16408
16452
|
name: "pay_order",
|
|
16409
|
-
title: "Pay order
|
|
16410
|
-
description: "Pay an order
|
|
16453
|
+
title: "Pay order by token or Alipay/WeChat Pay",
|
|
16454
|
+
description: "Pay an order without its link, by shared payment token or Alipay/WeChat Pay (method alipay_wechat_pay). Token: only if payment.handlers isn't empty and you can request one from the user's Link wallet (US and Canadian accounts); never ask the user for one. First show the user the USD total, the stay and every term (meals, cancellation, fees payable at the property), ask them to confirm, and wait for a clear yes. Token: request it with config.business_profile and payment.credentialLimits; pass it with price.total. Wallet: pass method, price.total; show payment.wallets (the WeChat code as an image if you can, both links); they pay once, by either; if the code is dead, the WeChat link opens a new one, or call again. Pay one way only: payment.url or pay_order. On success payment.url stops working; on failure it stays open. Then poll get_order. payment_total_changed: confirm details.total, retry. payment_credential_invalid: new token. service_unavailable: retry. Else payment.url. A token pays one order only.",
|
|
16411
16455
|
annotations: {
|
|
16412
16456
|
readOnlyHint: false,
|
|
16413
16457
|
idempotentHint: true,
|
|
@@ -16860,6 +16904,7 @@ function paymentLines(o, surface) {
|
|
|
16860
16904
|
lines.push("Payment link: could not be read this time; read this order again for it.");
|
|
16861
16905
|
}
|
|
16862
16906
|
if (p.handlers.length > 0) lines.push(handlersLine(o, surface));
|
|
16907
|
+
if (p.wallets) lines.push(...walletLines(p.wallets, surface));
|
|
16863
16908
|
lines.push(cancelLine(o));
|
|
16864
16909
|
lines.push(`Manage: ${o.manageUrl}`);
|
|
16865
16910
|
return lines;
|
|
@@ -16877,6 +16922,26 @@ function handlersLine(o, surface) {
|
|
|
16877
16922
|
`First show the user the total and currency, the stay and every term, and wait for a clear yes. Pay one way only: the link or ${surface === "cli" ? "`fortrip orders pay`" : "pay_order"}.`
|
|
16878
16923
|
].join(" ");
|
|
16879
16924
|
}
|
|
16925
|
+
function walletLines(w, surface) {
|
|
16926
|
+
const c = CALLS[surface];
|
|
16927
|
+
if (!w.open) {
|
|
16928
|
+
const pay = surface === "cli" ? "run `fortrip orders pay <orderId> --wallet --total <total>`" : "call pay_order with method alipay_wechat_pay and the order's price.total";
|
|
16929
|
+
return [`Pay with Alipay or WeChat Pay: ${pay}.`];
|
|
16930
|
+
}
|
|
16931
|
+
const lines = [];
|
|
16932
|
+
const wechat = w.wechatPay;
|
|
16933
|
+
if (wechat) {
|
|
16934
|
+
const live = wechat.qrData !== null && wechat.qrImageUrl !== null;
|
|
16935
|
+
lines.push(
|
|
16936
|
+
!live ? `WeChat Pay: a new code at ${wechat.url}` : surface === "cli" ? `WeChat Pay: open ${wechat.url}` : `WeChat Pay: , or a full-size code at ${wechat.url}`
|
|
16937
|
+
);
|
|
16938
|
+
}
|
|
16939
|
+
if (w.alipay) lines.push(`Alipay: ${w.alipay.url}`);
|
|
16940
|
+
lines.push(
|
|
16941
|
+
`Show the user the WeChat Pay code as an image if you can, and both links. They pay once, by either. Then ${c.get} until the order isn't awaiting_payment.`
|
|
16942
|
+
);
|
|
16943
|
+
return lines;
|
|
16944
|
+
}
|
|
16880
16945
|
function cancelLine(o) {
|
|
16881
16946
|
const c = o.cancel;
|
|
16882
16947
|
if (o.status === "awaiting_payment" && !c.available && c.reason === "not_confirmed") {
|
|
@@ -17388,6 +17453,7 @@ ${raw(data)}`;
|
|
|
17388
17453
|
text2,
|
|
17389
17454
|
ORDER_TOOLS.has(tool) && holdsPaymentUrl(data) ? ORDER_NEXT_STEP : "",
|
|
17390
17455
|
ORDER_TOOLS.has(tool) && holdsHandlers(data) ? payNextStep(surface) : "",
|
|
17456
|
+
ORDER_TOOLS.has(tool) && holdsWalletOffer(data) ? walletNextStep(surface) : "",
|
|
17391
17457
|
CANCEL_TOOLS.has(tool) && holdsCancellable(data) ? cancelNextStep(surface) : ""
|
|
17392
17458
|
].filter(Boolean).join("\n\n");
|
|
17393
17459
|
}
|
|
@@ -17432,6 +17498,18 @@ function holdsHandlers(value, seen = /* @__PURE__ */ new Set()) {
|
|
|
17432
17498
|
}
|
|
17433
17499
|
return Object.values(value).some((v) => holdsHandlers(v, seen));
|
|
17434
17500
|
}
|
|
17501
|
+
function holdsWalletOffer(value, seen = /* @__PURE__ */ new Set()) {
|
|
17502
|
+
if (typeof value !== "object" || value === null || seen.has(value)) return false;
|
|
17503
|
+
seen.add(value);
|
|
17504
|
+
const payment = value.payment;
|
|
17505
|
+
if (typeof payment === "object" && payment !== null) {
|
|
17506
|
+
const wallets = payment.wallets;
|
|
17507
|
+
if (typeof wallets === "object" && wallets !== null && wallets.open === false) {
|
|
17508
|
+
return true;
|
|
17509
|
+
}
|
|
17510
|
+
}
|
|
17511
|
+
return Object.values(value).some((v) => holdsWalletOffer(v, seen));
|
|
17512
|
+
}
|
|
17435
17513
|
function holdsCancellable(value, seen = /* @__PURE__ */ new Set()) {
|
|
17436
17514
|
if (typeof value !== "object" || value === null || seen.has(value)) return false;
|
|
17437
17515
|
seen.add(value);
|
|
@@ -17446,6 +17524,7 @@ function withConsent(tool, surface, text2, orders) {
|
|
|
17446
17524
|
text2,
|
|
17447
17525
|
orders.some((o) => o.payment.url !== null) ? ORDER_NEXT_STEP : "",
|
|
17448
17526
|
orders.some((o) => o.payment.handlers.length > 0) ? payNextStep(surface) : "",
|
|
17527
|
+
orders.some((o) => o.payment.wallets?.open === false) ? walletNextStep(surface) : "",
|
|
17449
17528
|
CANCEL_TOOLS.has(tool) && orders.some((o) => o.cancel.available) ? cancelNextStep(surface) : ""
|
|
17450
17529
|
].filter(Boolean).join("\n\n");
|
|
17451
17530
|
}
|
|
@@ -17453,7 +17532,7 @@ function withConsent(tool, surface, text2, orders) {
|
|
|
17453
17532
|
// ../contract/package.json
|
|
17454
17533
|
var package_default = {
|
|
17455
17534
|
name: "@fortrip/agent-contract",
|
|
17456
|
-
version: "4.
|
|
17535
|
+
version: "4.2.0-rc.1",
|
|
17457
17536
|
license: "Apache-2.0",
|
|
17458
17537
|
description: "The contract of Fortrip's agent API (https://api.fortrip.ai/v1) and its MCP server: limits, paths, request and response schemas, error codes and field rules.",
|
|
17459
17538
|
type: "module",
|
package/dist/cli.js
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
unwrap,
|
|
27
27
|
usageError,
|
|
28
28
|
whoami
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-LWFIUOYU.js";
|
|
30
30
|
|
|
31
31
|
// src/commands.ts
|
|
32
32
|
import { readFileSync } from "fs";
|
|
@@ -440,6 +440,684 @@ function readGuide(topic) {
|
|
|
440
440
|
return renderGuide("cli", topic).replaceAll("fortrip@latest", `fortrip@${VERSION}`);
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
+
// ../../node_modules/.pnpm/uqr@0.1.3/node_modules/uqr/dist/index.mjs
|
|
444
|
+
var QrCodeDataType = /* @__PURE__ */ ((QrCodeDataType2) => {
|
|
445
|
+
QrCodeDataType2[QrCodeDataType2["Border"] = -1] = "Border";
|
|
446
|
+
QrCodeDataType2[QrCodeDataType2["Data"] = 0] = "Data";
|
|
447
|
+
QrCodeDataType2[QrCodeDataType2["Function"] = 1] = "Function";
|
|
448
|
+
QrCodeDataType2[QrCodeDataType2["Position"] = 2] = "Position";
|
|
449
|
+
QrCodeDataType2[QrCodeDataType2["Timing"] = 3] = "Timing";
|
|
450
|
+
QrCodeDataType2[QrCodeDataType2["Alignment"] = 4] = "Alignment";
|
|
451
|
+
return QrCodeDataType2;
|
|
452
|
+
})(QrCodeDataType || {});
|
|
453
|
+
var LOW = [0, 1];
|
|
454
|
+
var MEDIUM = [1, 0];
|
|
455
|
+
var QUARTILE = [2, 3];
|
|
456
|
+
var HIGH = [3, 2];
|
|
457
|
+
var EccMap = {
|
|
458
|
+
L: LOW,
|
|
459
|
+
M: MEDIUM,
|
|
460
|
+
Q: QUARTILE,
|
|
461
|
+
H: HIGH
|
|
462
|
+
};
|
|
463
|
+
var NUMERIC_REGEX = /^\d*$/;
|
|
464
|
+
var ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+./:-]*$/;
|
|
465
|
+
var ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
|
|
466
|
+
var MIN_VERSION = 1;
|
|
467
|
+
var MAX_VERSION = 40;
|
|
468
|
+
var PENALTY_N1 = 3;
|
|
469
|
+
var PENALTY_N2 = 3;
|
|
470
|
+
var PENALTY_N3 = 40;
|
|
471
|
+
var PENALTY_N4 = 10;
|
|
472
|
+
var ECC_CODEWORDS_PER_BLOCK = [
|
|
473
|
+
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
|
474
|
+
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
|
|
475
|
+
[-1, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
|
476
|
+
// Low
|
|
477
|
+
[-1, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28],
|
|
478
|
+
// Medium
|
|
479
|
+
[-1, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30],
|
|
480
|
+
// Quartile
|
|
481
|
+
[-1, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
|
|
482
|
+
// High
|
|
483
|
+
];
|
|
484
|
+
var NUM_ERROR_CORRECTION_BLOCKS = [
|
|
485
|
+
// Version: (note that index 0 is for padding, and is set to an illegal value)
|
|
486
|
+
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
|
|
487
|
+
[-1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25],
|
|
488
|
+
// Low
|
|
489
|
+
[-1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49],
|
|
490
|
+
// Medium
|
|
491
|
+
[-1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68],
|
|
492
|
+
// Quartile
|
|
493
|
+
[-1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81]
|
|
494
|
+
// High
|
|
495
|
+
];
|
|
496
|
+
var QrCode = class {
|
|
497
|
+
/* -- Constructor (low level) and fields -- */
|
|
498
|
+
// Creates a new QR Code with the given version number,
|
|
499
|
+
// error correction level, data codeword bytes, and mask number.
|
|
500
|
+
// This is a low-level API that most users should not use directly.
|
|
501
|
+
// A mid-level API is the encodeSegments() function.
|
|
502
|
+
constructor(version, ecc, dataCodewords, msk) {
|
|
503
|
+
this.version = version;
|
|
504
|
+
this.ecc = ecc;
|
|
505
|
+
if (version < MIN_VERSION || version > MAX_VERSION)
|
|
506
|
+
throw new RangeError("Version value out of range");
|
|
507
|
+
if (msk < -1 || msk > 7)
|
|
508
|
+
throw new RangeError("Mask value out of range");
|
|
509
|
+
this.size = version * 4 + 17;
|
|
510
|
+
const row = Array.from({ length: this.size }).fill(false);
|
|
511
|
+
for (let i = 0; i < this.size; i++) {
|
|
512
|
+
this.modules.push(row.slice());
|
|
513
|
+
this.types.push(row.map(() => 0));
|
|
514
|
+
}
|
|
515
|
+
this.drawFunctionPatterns();
|
|
516
|
+
const allCodewords = this.addEccAndInterleave(dataCodewords);
|
|
517
|
+
this.drawCodewords(allCodewords);
|
|
518
|
+
if (msk === -1) {
|
|
519
|
+
let minPenalty = 1e9;
|
|
520
|
+
for (let i = 0; i < 8; i++) {
|
|
521
|
+
this.applyMask(i);
|
|
522
|
+
this.drawFormatBits(i);
|
|
523
|
+
const penalty = this.getPenaltyScore();
|
|
524
|
+
if (penalty < minPenalty) {
|
|
525
|
+
msk = i;
|
|
526
|
+
minPenalty = penalty;
|
|
527
|
+
}
|
|
528
|
+
this.applyMask(i);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
this.mask = msk;
|
|
532
|
+
this.applyMask(msk);
|
|
533
|
+
this.drawFormatBits(msk);
|
|
534
|
+
}
|
|
535
|
+
/* -- Fields -- */
|
|
536
|
+
// The width and height of this QR Code, measured in modules, between
|
|
537
|
+
// 21 and 177 (inclusive). This is equal to version * 4 + 17.
|
|
538
|
+
size;
|
|
539
|
+
// The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
|
|
540
|
+
// Even if a QR Code is created with automatic masking requested (mask = -1),
|
|
541
|
+
// the resulting object still has a mask value between 0 and 7.
|
|
542
|
+
mask;
|
|
543
|
+
// The modules of this QR Code (false = light, true = dark).
|
|
544
|
+
// Immutable after constructor finishes. Accessed through getModule().
|
|
545
|
+
modules = [];
|
|
546
|
+
types = [];
|
|
547
|
+
/* -- Accessor methods -- */
|
|
548
|
+
// Returns the color of the module (pixel) at the given coordinates, which is false
|
|
549
|
+
// for light or true for dark. The top left corner has the coordinates (x=0, y=0).
|
|
550
|
+
// If the given coordinates are out of bounds, then false (light) is returned.
|
|
551
|
+
getModule(x, y) {
|
|
552
|
+
return x >= 0 && x < this.size && y >= 0 && y < this.size && this.modules[y][x];
|
|
553
|
+
}
|
|
554
|
+
/* -- Private helper methods for constructor: Drawing function modules -- */
|
|
555
|
+
// Reads this object's version field, and draws and marks all function modules.
|
|
556
|
+
drawFunctionPatterns() {
|
|
557
|
+
for (let i = 0; i < this.size; i++) {
|
|
558
|
+
this.setFunctionModule(6, i, i % 2 === 0, QrCodeDataType.Timing);
|
|
559
|
+
this.setFunctionModule(i, 6, i % 2 === 0, QrCodeDataType.Timing);
|
|
560
|
+
}
|
|
561
|
+
this.drawFinderPattern(3, 3);
|
|
562
|
+
this.drawFinderPattern(this.size - 4, 3);
|
|
563
|
+
this.drawFinderPattern(3, this.size - 4);
|
|
564
|
+
const alignPatPos = this.getAlignmentPatternPositions();
|
|
565
|
+
const numAlign = alignPatPos.length;
|
|
566
|
+
for (let i = 0; i < numAlign; i++) {
|
|
567
|
+
for (let j = 0; j < numAlign; j++) {
|
|
568
|
+
if (!(i === 0 && j === 0 || i === 0 && j === numAlign - 1 || i === numAlign - 1 && j === 0))
|
|
569
|
+
this.drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
this.drawFormatBits(0);
|
|
573
|
+
this.drawVersion();
|
|
574
|
+
}
|
|
575
|
+
// Draws two copies of the format bits (with its own error correction code)
|
|
576
|
+
// based on the given mask and this object's error correction level field.
|
|
577
|
+
drawFormatBits(mask) {
|
|
578
|
+
const data = this.ecc[1] << 3 | mask;
|
|
579
|
+
let rem = data;
|
|
580
|
+
for (let i = 0; i < 10; i++)
|
|
581
|
+
rem = rem << 1 ^ (rem >>> 9) * 1335;
|
|
582
|
+
const bits = (data << 10 | rem) ^ 21522;
|
|
583
|
+
for (let i = 0; i <= 5; i++)
|
|
584
|
+
this.setFunctionModule(8, i, getBit(bits, i));
|
|
585
|
+
this.setFunctionModule(8, 7, getBit(bits, 6));
|
|
586
|
+
this.setFunctionModule(8, 8, getBit(bits, 7));
|
|
587
|
+
this.setFunctionModule(7, 8, getBit(bits, 8));
|
|
588
|
+
for (let i = 9; i < 15; i++)
|
|
589
|
+
this.setFunctionModule(14 - i, 8, getBit(bits, i));
|
|
590
|
+
for (let i = 0; i < 8; i++)
|
|
591
|
+
this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
|
|
592
|
+
for (let i = 8; i < 15; i++)
|
|
593
|
+
this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
|
|
594
|
+
this.setFunctionModule(8, this.size - 8, true);
|
|
595
|
+
}
|
|
596
|
+
// Draws two copies of the version bits (with its own error correction code),
|
|
597
|
+
// based on this object's version field, iff 7 <= version <= 40.
|
|
598
|
+
drawVersion() {
|
|
599
|
+
if (this.version < 7)
|
|
600
|
+
return;
|
|
601
|
+
let rem = this.version;
|
|
602
|
+
for (let i = 0; i < 12; i++)
|
|
603
|
+
rem = rem << 1 ^ (rem >>> 11) * 7973;
|
|
604
|
+
const bits = this.version << 12 | rem;
|
|
605
|
+
for (let i = 0; i < 18; i++) {
|
|
606
|
+
const color = getBit(bits, i);
|
|
607
|
+
const a = this.size - 11 + i % 3;
|
|
608
|
+
const b = Math.floor(i / 3);
|
|
609
|
+
this.setFunctionModule(a, b, color);
|
|
610
|
+
this.setFunctionModule(b, a, color);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
// Draws a 9*9 finder pattern including the border separator,
|
|
614
|
+
// with the center module at (x, y). Modules can be out of bounds.
|
|
615
|
+
drawFinderPattern(x, y) {
|
|
616
|
+
for (let dy = -4; dy <= 4; dy++) {
|
|
617
|
+
for (let dx = -4; dx <= 4; dx++) {
|
|
618
|
+
const dist = Math.max(Math.abs(dx), Math.abs(dy));
|
|
619
|
+
const xx = x + dx;
|
|
620
|
+
const yy = y + dy;
|
|
621
|
+
if (xx >= 0 && xx < this.size && yy >= 0 && yy < this.size)
|
|
622
|
+
this.setFunctionModule(xx, yy, dist !== 2 && dist !== 4, QrCodeDataType.Position);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
// Draws a 5*5 alignment pattern, with the center module
|
|
627
|
+
// at (x, y). All modules must be in bounds.
|
|
628
|
+
drawAlignmentPattern(x, y) {
|
|
629
|
+
for (let dy = -2; dy <= 2; dy++) {
|
|
630
|
+
for (let dx = -2; dx <= 2; dx++) {
|
|
631
|
+
this.setFunctionModule(
|
|
632
|
+
x + dx,
|
|
633
|
+
y + dy,
|
|
634
|
+
Math.max(Math.abs(dx), Math.abs(dy)) !== 1,
|
|
635
|
+
QrCodeDataType.Alignment
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
// Sets the color of a module and marks it as a function module.
|
|
641
|
+
// Only used by the constructor. Coordinates must be in bounds.
|
|
642
|
+
setFunctionModule(x, y, isDark, type = QrCodeDataType.Function) {
|
|
643
|
+
this.modules[y][x] = isDark;
|
|
644
|
+
this.types[y][x] = type;
|
|
645
|
+
}
|
|
646
|
+
/* -- Private helper methods for constructor: Codewords and masking -- */
|
|
647
|
+
// Returns a new byte string representing the given data with the appropriate error correction
|
|
648
|
+
// codewords appended to it, based on this object's version and error correction level.
|
|
649
|
+
addEccAndInterleave(data) {
|
|
650
|
+
const ver = this.version;
|
|
651
|
+
const ecl = this.ecc;
|
|
652
|
+
if (data.length !== getNumDataCodewords(ver, ecl))
|
|
653
|
+
throw new RangeError("Invalid argument");
|
|
654
|
+
const numBlocks = NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
655
|
+
const blockEccLen = ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver];
|
|
656
|
+
const rawCodewords = Math.floor(getNumRawDataModules(ver) / 8);
|
|
657
|
+
const numShortBlocks = numBlocks - rawCodewords % numBlocks;
|
|
658
|
+
const shortBlockLen = Math.floor(rawCodewords / numBlocks);
|
|
659
|
+
const blocks = [];
|
|
660
|
+
const rsDiv = reedSolomonComputeDivisor(blockEccLen);
|
|
661
|
+
for (let i = 0, k = 0; i < numBlocks; i++) {
|
|
662
|
+
const dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
|
|
663
|
+
k += dat.length;
|
|
664
|
+
const ecc = reedSolomonComputeRemainder(dat, rsDiv);
|
|
665
|
+
if (i < numShortBlocks)
|
|
666
|
+
dat.push(0);
|
|
667
|
+
blocks.push(dat.concat(ecc));
|
|
668
|
+
}
|
|
669
|
+
const result = [];
|
|
670
|
+
for (let i = 0; i < blocks[0].length; i++) {
|
|
671
|
+
blocks.forEach((block, j) => {
|
|
672
|
+
if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks)
|
|
673
|
+
result.push(block[i]);
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
return result;
|
|
677
|
+
}
|
|
678
|
+
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
|
|
679
|
+
// data area of this QR Code. Function modules need to be marked off before this is called.
|
|
680
|
+
drawCodewords(data) {
|
|
681
|
+
if (data.length !== Math.floor(getNumRawDataModules(this.version) / 8))
|
|
682
|
+
throw new RangeError("Invalid argument");
|
|
683
|
+
let i = 0;
|
|
684
|
+
for (let right = this.size - 1; right >= 1; right -= 2) {
|
|
685
|
+
if (right === 6)
|
|
686
|
+
right = 5;
|
|
687
|
+
for (let vert = 0; vert < this.size; vert++) {
|
|
688
|
+
for (let j = 0; j < 2; j++) {
|
|
689
|
+
const x = right - j;
|
|
690
|
+
const upward = (right + 1 & 2) === 0;
|
|
691
|
+
const y = upward ? this.size - 1 - vert : vert;
|
|
692
|
+
if (!this.types[y][x] && i < data.length * 8) {
|
|
693
|
+
this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
|
|
694
|
+
i++;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
// XORs the codeword modules in this QR Code with the given mask pattern.
|
|
701
|
+
// The function modules must be marked and the codeword bits must be drawn
|
|
702
|
+
// before masking. Due to the arithmetic of XOR, calling applyMask() with
|
|
703
|
+
// the same mask value a second time will undo the mask. A final well-formed
|
|
704
|
+
// QR Code needs exactly one (not zero, two, etc.) mask applied.
|
|
705
|
+
applyMask(mask) {
|
|
706
|
+
if (mask < 0 || mask > 7)
|
|
707
|
+
throw new RangeError("Mask value out of range");
|
|
708
|
+
for (let y = 0; y < this.size; y++) {
|
|
709
|
+
for (let x = 0; x < this.size; x++) {
|
|
710
|
+
let invert;
|
|
711
|
+
switch (mask) {
|
|
712
|
+
case 0:
|
|
713
|
+
invert = (x + y) % 2 === 0;
|
|
714
|
+
break;
|
|
715
|
+
case 1:
|
|
716
|
+
invert = y % 2 === 0;
|
|
717
|
+
break;
|
|
718
|
+
case 2:
|
|
719
|
+
invert = x % 3 === 0;
|
|
720
|
+
break;
|
|
721
|
+
case 3:
|
|
722
|
+
invert = (x + y) % 3 === 0;
|
|
723
|
+
break;
|
|
724
|
+
case 4:
|
|
725
|
+
invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0;
|
|
726
|
+
break;
|
|
727
|
+
case 5:
|
|
728
|
+
invert = x * y % 2 + x * y % 3 === 0;
|
|
729
|
+
break;
|
|
730
|
+
case 6:
|
|
731
|
+
invert = (x * y % 2 + x * y % 3) % 2 === 0;
|
|
732
|
+
break;
|
|
733
|
+
case 7:
|
|
734
|
+
invert = ((x + y) % 2 + x * y % 3) % 2 === 0;
|
|
735
|
+
break;
|
|
736
|
+
default:
|
|
737
|
+
throw new Error("Unreachable");
|
|
738
|
+
}
|
|
739
|
+
if (!this.types[y][x] && invert)
|
|
740
|
+
this.modules[y][x] = !this.modules[y][x];
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
// Calculates and returns the penalty score based on state of this QR Code's current modules.
|
|
745
|
+
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
|
|
746
|
+
getPenaltyScore() {
|
|
747
|
+
let result = 0;
|
|
748
|
+
for (let y = 0; y < this.size; y++) {
|
|
749
|
+
let runColor = false;
|
|
750
|
+
let runX = 0;
|
|
751
|
+
const runHistory = [0, 0, 0, 0, 0, 0, 0];
|
|
752
|
+
for (let x = 0; x < this.size; x++) {
|
|
753
|
+
if (this.modules[y][x] === runColor) {
|
|
754
|
+
runX++;
|
|
755
|
+
if (runX === 5)
|
|
756
|
+
result += PENALTY_N1;
|
|
757
|
+
else if (runX > 5)
|
|
758
|
+
result++;
|
|
759
|
+
} else {
|
|
760
|
+
this.finderPenaltyAddHistory(runX, runHistory);
|
|
761
|
+
if (!runColor)
|
|
762
|
+
result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
763
|
+
runColor = this.modules[y][x];
|
|
764
|
+
runX = 1;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runX, runHistory) * PENALTY_N3;
|
|
768
|
+
}
|
|
769
|
+
for (let x = 0; x < this.size; x++) {
|
|
770
|
+
let runColor = false;
|
|
771
|
+
let runY = 0;
|
|
772
|
+
const runHistory = [0, 0, 0, 0, 0, 0, 0];
|
|
773
|
+
for (let y = 0; y < this.size; y++) {
|
|
774
|
+
if (this.modules[y][x] === runColor) {
|
|
775
|
+
runY++;
|
|
776
|
+
if (runY === 5)
|
|
777
|
+
result += PENALTY_N1;
|
|
778
|
+
else if (runY > 5)
|
|
779
|
+
result++;
|
|
780
|
+
} else {
|
|
781
|
+
this.finderPenaltyAddHistory(runY, runHistory);
|
|
782
|
+
if (!runColor)
|
|
783
|
+
result += this.finderPenaltyCountPatterns(runHistory) * PENALTY_N3;
|
|
784
|
+
runColor = this.modules[y][x];
|
|
785
|
+
runY = 1;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
result += this.finderPenaltyTerminateAndCount(runColor, runY, runHistory) * PENALTY_N3;
|
|
789
|
+
}
|
|
790
|
+
for (let y = 0; y < this.size - 1; y++) {
|
|
791
|
+
for (let x = 0; x < this.size - 1; x++) {
|
|
792
|
+
const color = this.modules[y][x];
|
|
793
|
+
if (color === this.modules[y][x + 1] && color === this.modules[y + 1][x] && color === this.modules[y + 1][x + 1]) {
|
|
794
|
+
result += PENALTY_N2;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
let dark = 0;
|
|
799
|
+
for (const row of this.modules)
|
|
800
|
+
dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark);
|
|
801
|
+
const total = this.size * this.size;
|
|
802
|
+
const k = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1;
|
|
803
|
+
result += k * PENALTY_N4;
|
|
804
|
+
return result;
|
|
805
|
+
}
|
|
806
|
+
/* -- Private helper functions -- */
|
|
807
|
+
// Returns an ascending list of positions of alignment patterns for this version number.
|
|
808
|
+
// Each position is in the range [0,177), and are used on both the x and y axes.
|
|
809
|
+
// This could be implemented as lookup table of 40 variable-length lists of integers.
|
|
810
|
+
getAlignmentPatternPositions() {
|
|
811
|
+
if (this.version === 1) {
|
|
812
|
+
return [];
|
|
813
|
+
} else {
|
|
814
|
+
const numAlign = Math.floor(this.version / 7) + 2;
|
|
815
|
+
const step2 = this.version === 32 ? 26 : Math.ceil((this.version * 4 + 4) / (numAlign * 2 - 2)) * 2;
|
|
816
|
+
const result = [6];
|
|
817
|
+
for (let pos = this.size - 7; result.length < numAlign; pos -= step2)
|
|
818
|
+
result.splice(1, 0, pos);
|
|
819
|
+
return result;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// Can only be called immediately after a light run is added, and
|
|
823
|
+
// returns either 0, 1, or 2. A helper function for getPenaltyScore().
|
|
824
|
+
finderPenaltyCountPatterns(runHistory) {
|
|
825
|
+
const n = runHistory[1];
|
|
826
|
+
const core = n > 0 && runHistory[2] === n && runHistory[3] === n * 3 && runHistory[4] === n && runHistory[5] === n;
|
|
827
|
+
return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0);
|
|
828
|
+
}
|
|
829
|
+
// Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore().
|
|
830
|
+
finderPenaltyTerminateAndCount(currentRunColor, currentRunLength, runHistory) {
|
|
831
|
+
if (currentRunColor) {
|
|
832
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
833
|
+
currentRunLength = 0;
|
|
834
|
+
}
|
|
835
|
+
currentRunLength += this.size;
|
|
836
|
+
this.finderPenaltyAddHistory(currentRunLength, runHistory);
|
|
837
|
+
return this.finderPenaltyCountPatterns(runHistory);
|
|
838
|
+
}
|
|
839
|
+
// Pushes the given value to the front and drops the last value. A helper function for getPenaltyScore().
|
|
840
|
+
finderPenaltyAddHistory(currentRunLength, runHistory) {
|
|
841
|
+
if (runHistory[0] === 0)
|
|
842
|
+
currentRunLength += this.size;
|
|
843
|
+
runHistory.pop();
|
|
844
|
+
runHistory.unshift(currentRunLength);
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
function appendBits(val, len, bb) {
|
|
848
|
+
if (len < 0 || len > 31 || val >>> len !== 0)
|
|
849
|
+
throw new RangeError("Value out of range");
|
|
850
|
+
for (let i = len - 1; i >= 0; i--)
|
|
851
|
+
bb.push(val >>> i & 1);
|
|
852
|
+
}
|
|
853
|
+
function getBit(x, i) {
|
|
854
|
+
return (x >>> i & 1) !== 0;
|
|
855
|
+
}
|
|
856
|
+
var QrSegment = class {
|
|
857
|
+
// Creates a new QR Code segment with the given attributes and data.
|
|
858
|
+
// The character count (numChars) must agree with the mode and the bit buffer length,
|
|
859
|
+
// but the constraint isn't checked. The given bit buffer is cloned and stored.
|
|
860
|
+
constructor(mode, numChars, bitData) {
|
|
861
|
+
this.mode = mode;
|
|
862
|
+
this.numChars = numChars;
|
|
863
|
+
this.bitData = bitData;
|
|
864
|
+
if (numChars < 0)
|
|
865
|
+
throw new RangeError("Invalid argument");
|
|
866
|
+
this.bitData = bitData.slice();
|
|
867
|
+
}
|
|
868
|
+
/* -- Methods -- */
|
|
869
|
+
// Returns a new copy of the data bits of this segment.
|
|
870
|
+
getData() {
|
|
871
|
+
return this.bitData.slice();
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
var MODE_NUMERIC = [1, 10, 12, 14];
|
|
875
|
+
var MODE_ALPHANUMERIC = [2, 9, 11, 13];
|
|
876
|
+
var MODE_BYTE = [4, 8, 16, 16];
|
|
877
|
+
function numCharCountBits(mode, ver) {
|
|
878
|
+
return mode[Math.floor((ver + 7) / 17) + 1];
|
|
879
|
+
}
|
|
880
|
+
function makeBytes(data) {
|
|
881
|
+
const bb = [];
|
|
882
|
+
for (const b of data)
|
|
883
|
+
appendBits(b, 8, bb);
|
|
884
|
+
return new QrSegment(MODE_BYTE, data.length, bb);
|
|
885
|
+
}
|
|
886
|
+
function makeNumeric(digits) {
|
|
887
|
+
if (!isNumeric(digits))
|
|
888
|
+
throw new RangeError("String contains non-numeric characters");
|
|
889
|
+
const bb = [];
|
|
890
|
+
for (let i = 0; i < digits.length; ) {
|
|
891
|
+
const n = Math.min(digits.length - i, 3);
|
|
892
|
+
appendBits(Number.parseInt(digits.substring(i, i + n), 10), n * 3 + 1, bb);
|
|
893
|
+
i += n;
|
|
894
|
+
}
|
|
895
|
+
return new QrSegment(MODE_NUMERIC, digits.length, bb);
|
|
896
|
+
}
|
|
897
|
+
function makeAlphanumeric(text) {
|
|
898
|
+
if (!isAlphanumeric(text))
|
|
899
|
+
throw new RangeError("String contains unencodable characters in alphanumeric mode");
|
|
900
|
+
const bb = [];
|
|
901
|
+
let i;
|
|
902
|
+
for (i = 0; i + 2 <= text.length; i += 2) {
|
|
903
|
+
let temp = ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
|
|
904
|
+
temp += ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
|
|
905
|
+
appendBits(temp, 11, bb);
|
|
906
|
+
}
|
|
907
|
+
if (i < text.length)
|
|
908
|
+
appendBits(ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6, bb);
|
|
909
|
+
return new QrSegment(MODE_ALPHANUMERIC, text.length, bb);
|
|
910
|
+
}
|
|
911
|
+
function makeSegments(text) {
|
|
912
|
+
if (text === "")
|
|
913
|
+
return [];
|
|
914
|
+
else if (isNumeric(text))
|
|
915
|
+
return [makeNumeric(text)];
|
|
916
|
+
else if (isAlphanumeric(text))
|
|
917
|
+
return [makeAlphanumeric(text)];
|
|
918
|
+
else
|
|
919
|
+
return [makeBytes(toUtf8ByteArray(text))];
|
|
920
|
+
}
|
|
921
|
+
function isNumeric(text) {
|
|
922
|
+
return NUMERIC_REGEX.test(text);
|
|
923
|
+
}
|
|
924
|
+
function isAlphanumeric(text) {
|
|
925
|
+
return ALPHANUMERIC_REGEX.test(text);
|
|
926
|
+
}
|
|
927
|
+
function getTotalBits(segs, version) {
|
|
928
|
+
let result = 0;
|
|
929
|
+
for (const seg of segs) {
|
|
930
|
+
const ccbits = numCharCountBits(seg.mode, version);
|
|
931
|
+
if (seg.numChars >= 1 << ccbits)
|
|
932
|
+
return Number.POSITIVE_INFINITY;
|
|
933
|
+
result += 4 + ccbits + seg.bitData.length;
|
|
934
|
+
}
|
|
935
|
+
return result;
|
|
936
|
+
}
|
|
937
|
+
function toUtf8ByteArray(str) {
|
|
938
|
+
str = encodeURI(str);
|
|
939
|
+
const result = [];
|
|
940
|
+
for (let i = 0; i < str.length; i++) {
|
|
941
|
+
if (str.charAt(i) !== "%") {
|
|
942
|
+
result.push(str.charCodeAt(i));
|
|
943
|
+
} else {
|
|
944
|
+
result.push(Number.parseInt(str.substring(i + 1, i + 3), 16));
|
|
945
|
+
i += 2;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
return result;
|
|
949
|
+
}
|
|
950
|
+
function getNumRawDataModules(ver) {
|
|
951
|
+
if (ver < MIN_VERSION || ver > MAX_VERSION)
|
|
952
|
+
throw new RangeError("Version number out of range");
|
|
953
|
+
let result = (16 * ver + 128) * ver + 64;
|
|
954
|
+
if (ver >= 2) {
|
|
955
|
+
const numAlign = Math.floor(ver / 7) + 2;
|
|
956
|
+
result -= (25 * numAlign - 10) * numAlign - 55;
|
|
957
|
+
if (ver >= 7)
|
|
958
|
+
result -= 36;
|
|
959
|
+
}
|
|
960
|
+
return result;
|
|
961
|
+
}
|
|
962
|
+
function getNumDataCodewords(ver, ecl) {
|
|
963
|
+
return Math.floor(getNumRawDataModules(ver) / 8) - ECC_CODEWORDS_PER_BLOCK[ecl[0]][ver] * NUM_ERROR_CORRECTION_BLOCKS[ecl[0]][ver];
|
|
964
|
+
}
|
|
965
|
+
function reedSolomonComputeDivisor(degree) {
|
|
966
|
+
if (degree < 1 || degree > 255)
|
|
967
|
+
throw new RangeError("Degree out of range");
|
|
968
|
+
const result = [];
|
|
969
|
+
for (let i = 0; i < degree - 1; i++)
|
|
970
|
+
result.push(0);
|
|
971
|
+
result.push(1);
|
|
972
|
+
let root = 1;
|
|
973
|
+
for (let i = 0; i < degree; i++) {
|
|
974
|
+
for (let j = 0; j < result.length; j++) {
|
|
975
|
+
result[j] = reedSolomonMultiply(result[j], root);
|
|
976
|
+
if (j + 1 < result.length)
|
|
977
|
+
result[j] ^= result[j + 1];
|
|
978
|
+
}
|
|
979
|
+
root = reedSolomonMultiply(root, 2);
|
|
980
|
+
}
|
|
981
|
+
return result;
|
|
982
|
+
}
|
|
983
|
+
function reedSolomonComputeRemainder(data, divisor) {
|
|
984
|
+
const result = divisor.map((_) => 0);
|
|
985
|
+
for (const b of data) {
|
|
986
|
+
const factor = b ^ result.shift();
|
|
987
|
+
result.push(0);
|
|
988
|
+
divisor.forEach((coef, i) => result[i] ^= reedSolomonMultiply(coef, factor));
|
|
989
|
+
}
|
|
990
|
+
return result;
|
|
991
|
+
}
|
|
992
|
+
function reedSolomonMultiply(x, y) {
|
|
993
|
+
if (x >>> 8 !== 0 || y >>> 8 !== 0)
|
|
994
|
+
throw new RangeError("Byte out of range");
|
|
995
|
+
let z = 0;
|
|
996
|
+
for (let i = 7; i >= 0; i--) {
|
|
997
|
+
z = z << 1 ^ (z >>> 7) * 285;
|
|
998
|
+
z ^= (y >>> i & 1) * x;
|
|
999
|
+
}
|
|
1000
|
+
return z;
|
|
1001
|
+
}
|
|
1002
|
+
function encodeSegments(segs, ecl, minVersion = 1, maxVersion = 40, mask = -1, boostEcl = true) {
|
|
1003
|
+
if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) {
|
|
1004
|
+
throw new RangeError("Invalid value");
|
|
1005
|
+
}
|
|
1006
|
+
let version;
|
|
1007
|
+
let dataUsedBits;
|
|
1008
|
+
for (version = minVersion; ; version++) {
|
|
1009
|
+
const dataCapacityBits2 = getNumDataCodewords(version, ecl) * 8;
|
|
1010
|
+
const usedBits = getTotalBits(segs, version);
|
|
1011
|
+
if (usedBits <= dataCapacityBits2) {
|
|
1012
|
+
dataUsedBits = usedBits;
|
|
1013
|
+
break;
|
|
1014
|
+
}
|
|
1015
|
+
if (version >= maxVersion)
|
|
1016
|
+
throw new RangeError("Data too long");
|
|
1017
|
+
}
|
|
1018
|
+
for (const newEcl of [MEDIUM, QUARTILE, HIGH]) {
|
|
1019
|
+
if (boostEcl && dataUsedBits <= getNumDataCodewords(version, newEcl) * 8)
|
|
1020
|
+
ecl = newEcl;
|
|
1021
|
+
}
|
|
1022
|
+
const bb = [];
|
|
1023
|
+
for (const seg of segs) {
|
|
1024
|
+
appendBits(seg.mode[0], 4, bb);
|
|
1025
|
+
appendBits(seg.numChars, numCharCountBits(seg.mode, version), bb);
|
|
1026
|
+
for (const b of seg.getData())
|
|
1027
|
+
bb.push(b);
|
|
1028
|
+
}
|
|
1029
|
+
const dataCapacityBits = getNumDataCodewords(version, ecl) * 8;
|
|
1030
|
+
appendBits(0, Math.min(4, dataCapacityBits - bb.length), bb);
|
|
1031
|
+
appendBits(0, (8 - bb.length % 8) % 8, bb);
|
|
1032
|
+
for (let padByte = 236; bb.length < dataCapacityBits; padByte ^= 236 ^ 17)
|
|
1033
|
+
appendBits(padByte, 8, bb);
|
|
1034
|
+
const dataCodewords = Array.from({ length: Math.ceil(bb.length / 8) }, () => 0);
|
|
1035
|
+
bb.forEach((b, i) => dataCodewords[i >>> 3] |= b << 7 - (i & 7));
|
|
1036
|
+
return new QrCode(version, ecl, dataCodewords, mask);
|
|
1037
|
+
}
|
|
1038
|
+
function encode(data, options) {
|
|
1039
|
+
const {
|
|
1040
|
+
ecc = "L",
|
|
1041
|
+
boostEcc = false,
|
|
1042
|
+
minVersion = 1,
|
|
1043
|
+
maxVersion = 40,
|
|
1044
|
+
maskPattern = -1,
|
|
1045
|
+
border = 1
|
|
1046
|
+
} = options || {};
|
|
1047
|
+
const segment = typeof data === "string" ? makeSegments(data) : Array.isArray(data) ? [makeBytes(data)] : void 0;
|
|
1048
|
+
if (!segment)
|
|
1049
|
+
throw new Error(`uqr only supports encoding string and binary data, but got: ${typeof data}`);
|
|
1050
|
+
const qr = encodeSegments(
|
|
1051
|
+
segment,
|
|
1052
|
+
EccMap[ecc],
|
|
1053
|
+
minVersion,
|
|
1054
|
+
maxVersion,
|
|
1055
|
+
maskPattern,
|
|
1056
|
+
boostEcc
|
|
1057
|
+
);
|
|
1058
|
+
const result = addBorder({
|
|
1059
|
+
version: qr.version,
|
|
1060
|
+
maskPattern: qr.mask,
|
|
1061
|
+
size: qr.size,
|
|
1062
|
+
data: qr.modules,
|
|
1063
|
+
types: qr.types
|
|
1064
|
+
}, border);
|
|
1065
|
+
if (options?.invert)
|
|
1066
|
+
result.data = result.data.map((row) => row.map((mod) => !mod));
|
|
1067
|
+
options?.onEncoded?.(result);
|
|
1068
|
+
return result;
|
|
1069
|
+
}
|
|
1070
|
+
function addBorder(input, border = 1) {
|
|
1071
|
+
if (!border)
|
|
1072
|
+
return input;
|
|
1073
|
+
const { size } = input;
|
|
1074
|
+
const newSize = size + border * 2;
|
|
1075
|
+
input.size = newSize;
|
|
1076
|
+
input.data.forEach((row) => {
|
|
1077
|
+
for (let i = 0; i < border; i++) {
|
|
1078
|
+
row.unshift(false);
|
|
1079
|
+
row.push(false);
|
|
1080
|
+
}
|
|
1081
|
+
});
|
|
1082
|
+
for (let i = 0; i < border; i++) {
|
|
1083
|
+
input.data.unshift(Array.from({ length: newSize }, (_) => false));
|
|
1084
|
+
input.data.push(Array.from({ length: newSize }, (_) => false));
|
|
1085
|
+
}
|
|
1086
|
+
const b = QrCodeDataType.Border;
|
|
1087
|
+
input.types.forEach((row) => {
|
|
1088
|
+
for (let i = 0; i < border; i++) {
|
|
1089
|
+
row.unshift(b);
|
|
1090
|
+
row.push(b);
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
for (let i = 0; i < border; i++) {
|
|
1094
|
+
input.types.unshift(Array.from({ length: newSize }, (_) => b));
|
|
1095
|
+
input.types.push(Array.from({ length: newSize }, (_) => b));
|
|
1096
|
+
}
|
|
1097
|
+
return input;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// src/qr.ts
|
|
1101
|
+
function halfBlocks(modules) {
|
|
1102
|
+
const lines = [];
|
|
1103
|
+
for (let y = 0; y < modules.length; y += 2) {
|
|
1104
|
+
const top = modules[y] ?? [];
|
|
1105
|
+
const bottom = modules[y + 1] ?? [];
|
|
1106
|
+
let line = "";
|
|
1107
|
+
for (let x = 0; x < top.length; x++) {
|
|
1108
|
+
line += top[x] ? bottom[x] ? "\u2588" : "\u2580" : bottom[x] ? "\u2584" : " ";
|
|
1109
|
+
}
|
|
1110
|
+
lines.push(line);
|
|
1111
|
+
}
|
|
1112
|
+
return lines;
|
|
1113
|
+
}
|
|
1114
|
+
function terminalQr(data, columns) {
|
|
1115
|
+
const { data: modules } = encode(data, { ecc: "M", border: 2 });
|
|
1116
|
+
const width = modules[0]?.length ?? 0;
|
|
1117
|
+
if (columns === void 0 || columns < width) return null;
|
|
1118
|
+
return halfBlocks(modules).map((line) => `\x1B[30;47m${line}\x1B[0m`).join("\n");
|
|
1119
|
+
}
|
|
1120
|
+
|
|
443
1121
|
// src/cli.ts
|
|
444
1122
|
function globalFlag(name) {
|
|
445
1123
|
const option = GLOBAL_FLAGS.find((candidate) => candidate.flag === name);
|
|
@@ -530,7 +1208,7 @@ async function run(argv) {
|
|
|
530
1208
|
case "mcp": {
|
|
531
1209
|
parseOptions(spec, rest);
|
|
532
1210
|
const mcpUrl = resolveMcpUrl(apiUrl);
|
|
533
|
-
const { runMcpBridge } = await import("./mcp-bridge-
|
|
1211
|
+
const { runMcpBridge } = await import("./mcp-bridge-A7MBMCM6.js");
|
|
534
1212
|
await runMcpBridge(mcpUrl, apiUrl);
|
|
535
1213
|
return void 0;
|
|
536
1214
|
}
|
|
@@ -579,6 +1257,12 @@ function takeJson(argv) {
|
|
|
579
1257
|
const kept = before.filter((arg) => arg !== JSON_FLAG);
|
|
580
1258
|
return { json: kept.length < before.length, argv: [...kept, ...after] };
|
|
581
1259
|
}
|
|
1260
|
+
function walletCode(argv, data) {
|
|
1261
|
+
if (argv[0] !== "orders" || argv[1] !== "pay" || !process.stdout.isTTY) return null;
|
|
1262
|
+
const wallets = data?.payment?.wallets;
|
|
1263
|
+
const qrData = wallets?.wechatPay?.qrData;
|
|
1264
|
+
return typeof qrData === "string" ? terminalQr(qrData, process.stdout.columns) : null;
|
|
1265
|
+
}
|
|
582
1266
|
async function main() {
|
|
583
1267
|
const { json, argv } = takeJson(process.argv.slice(2));
|
|
584
1268
|
try {
|
|
@@ -591,6 +1275,10 @@ async function main() {
|
|
|
591
1275
|
`);
|
|
592
1276
|
} else {
|
|
593
1277
|
process.stdout.write(`${[text, ...fieldLines(notices)].join("\n")}
|
|
1278
|
+
`);
|
|
1279
|
+
const code = walletCode(argv, data);
|
|
1280
|
+
if (code) process.stdout.write(`Or scan this WeChat Pay code:
|
|
1281
|
+
${code}
|
|
594
1282
|
`);
|
|
595
1283
|
}
|
|
596
1284
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fortrip",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0-rc.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Search, price and book Fortrip hotels from the terminal or an AI agent.",
|
|
6
6
|
"mcpName": "io.github.FortripEngineering/fortrip",
|
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
"tsup": "^8.5.1",
|
|
32
32
|
"tsx": "^4.20.0",
|
|
33
33
|
"typescript": "^5.9.0",
|
|
34
|
+
"uqr": "0.1.3",
|
|
34
35
|
"zod": "4.4.3",
|
|
35
|
-
"@fortrip/agent-contract": "4.
|
|
36
|
+
"@fortrip/agent-contract": "4.2.0-rc.1"
|
|
36
37
|
},
|
|
37
38
|
"scripts": {
|
|
38
39
|
"build": "tsup",
|