fortrip 4.3.1 → 5.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -24
- package/dist/{chunk-63KHFEME.js → chunk-DYSYHQQY.js} +278 -298
- package/dist/cli.js +103 -48
- package/dist/{mcp-bridge-2GXFE2SC.js → mcp-bridge-WB44PZPA.js} +7 -11
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
API,
|
|
4
4
|
COMMANDS,
|
|
5
5
|
COMMAND_GROUPS,
|
|
6
|
+
CURRENCIES,
|
|
6
7
|
CliError,
|
|
7
8
|
EXIT,
|
|
8
9
|
GLOBAL_FLAGS,
|
|
@@ -20,7 +21,6 @@ import {
|
|
|
20
21
|
logout,
|
|
21
22
|
notices,
|
|
22
23
|
order,
|
|
23
|
-
renderGuide,
|
|
24
24
|
renderToolResult,
|
|
25
25
|
resolveApiUrl,
|
|
26
26
|
resolveMcpUrl,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
unwrap,
|
|
29
29
|
usageError,
|
|
30
30
|
whoami
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-DYSYHQQY.js";
|
|
32
32
|
|
|
33
33
|
// src/commands.ts
|
|
34
34
|
import { readFileSync } from "fs";
|
|
@@ -36,7 +36,7 @@ import { parseArgs } from "util";
|
|
|
36
36
|
|
|
37
37
|
// src/environment.ts
|
|
38
38
|
var CURRENCY_COMMANDS = COMMANDS.filter(
|
|
39
|
-
(spec) => spec.flags.some((flag) => flag.field === "
|
|
39
|
+
(spec) => spec.flags.some((flag) => flag.field === "currency")
|
|
40
40
|
).map((spec) => commandInvocation(spec).slice("fortrip ".length)).join(" and ");
|
|
41
41
|
var ENVIRONMENT = [
|
|
42
42
|
{
|
|
@@ -51,8 +51,8 @@ var ENVIRONMENT = [
|
|
|
51
51
|
internal: true
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
|
-
name: "
|
|
55
|
-
help: `Default --
|
|
54
|
+
name: "FORTRIP_CURRENCY",
|
|
55
|
+
help: `Default --currency for ${CURRENCY_COMMANDS}`,
|
|
56
56
|
internal: false
|
|
57
57
|
}
|
|
58
58
|
];
|
|
@@ -75,9 +75,7 @@ function wrap(text, indent) {
|
|
|
75
75
|
return lines;
|
|
76
76
|
}
|
|
77
77
|
function positionals(spec) {
|
|
78
|
-
return (spec.positionals ?? []).map(
|
|
79
|
-
({ name, optional }) => optional ? `[${name}]` : `<${name}>`
|
|
80
|
-
);
|
|
78
|
+
return (spec.positionals ?? []).map(({ name }) => `<${name}>`);
|
|
81
79
|
}
|
|
82
80
|
function label(spec) {
|
|
83
81
|
return [spec.name, ...positionals(spec)].join(" ");
|
|
@@ -154,8 +152,9 @@ ${optionList(GLOBAL_FLAGS)}
|
|
|
154
152
|
Output is compact text on stdout; --json prints it as one line of JSON.
|
|
155
153
|
Errors go to stderr, as text or, with --json, as JSON.
|
|
156
154
|
Exit codes: 0 ok, 1 error (retry once when the error says it is retryable),
|
|
157
|
-
2 invalid arguments, or orders cancel without --max-penalty
|
|
158
|
-
cancelled), 3 not signed in or sign-in not accepted, 4 rate
|
|
155
|
+
2 invalid arguments, or orders cancel without --max-penalty or --close
|
|
156
|
+
(nothing is cancelled), 3 not signed in or sign-in not accepted, 4 rate
|
|
157
|
+
limited.
|
|
159
158
|
|
|
160
159
|
Environment:
|
|
161
160
|
${ENVIRONMENT_LINES}
|
|
@@ -163,8 +162,8 @@ ${ENVIRONMENT_LINES}
|
|
|
163
162
|
}
|
|
164
163
|
|
|
165
164
|
// src/commands.ts
|
|
166
|
-
var UPPER_CASE = /* @__PURE__ */ new Set(["
|
|
167
|
-
var FROM_ENV = {
|
|
165
|
+
var UPPER_CASE = /* @__PURE__ */ new Set(["currency", "destination.countryCode"]);
|
|
166
|
+
var FROM_ENV = { currency: "FORTRIP_CURRENCY" };
|
|
168
167
|
var ONE_ITEM_LISTS = /* @__PURE__ */ new Set(["items"]);
|
|
169
168
|
var GUEST_FIELD = "items.hotel.rooms.guests";
|
|
170
169
|
var ROOMS_FIELD = "items.hotel.rooms";
|
|
@@ -205,16 +204,16 @@ function parseOptions(spec, argv) {
|
|
|
205
204
|
return { values: parsed.values, positionals: parsed.positionals };
|
|
206
205
|
}
|
|
207
206
|
function parseCommand(spec, argv, env) {
|
|
208
|
-
const route = spec.tool
|
|
207
|
+
const route = spec.tool ? HTTP_ROUTES[spec.tool] : void 0;
|
|
209
208
|
if (!route) throw new Error(`${commandInvocation(spec)} sends no request`);
|
|
210
209
|
const { values, positionals: positionals2 } = parseOptions(spec, argv);
|
|
211
210
|
const input = baseBody(values.body);
|
|
212
211
|
const wanted = spec.positionals ?? [];
|
|
213
212
|
if (positionals2.length !== wanted.length) throw usageError(`Usage: ${usageLine(spec)}`);
|
|
214
213
|
wanted.forEach((positional, index) => {
|
|
215
|
-
|
|
214
|
+
input[positional.field] = positionals2[index];
|
|
216
215
|
});
|
|
217
|
-
setFlags(spec, values, input);
|
|
216
|
+
setFlags(spec, values, input, requestCurrency(spec, values, input, env));
|
|
218
217
|
const fromEnv = /* @__PURE__ */ new Map();
|
|
219
218
|
for (const [field, name] of Object.entries(FROM_ENV)) {
|
|
220
219
|
const fallback = env[name]?.trim().toUpperCase();
|
|
@@ -229,16 +228,35 @@ function parseCommand(spec, argv, env) {
|
|
|
229
228
|
const body = Object.fromEntries(Object.entries(input).filter(([field]) => !route.pathFields.includes(field)));
|
|
230
229
|
return { method: "POST", path, body };
|
|
231
230
|
}
|
|
232
|
-
function
|
|
231
|
+
function requestCurrency(spec, values, input, env) {
|
|
232
|
+
const flag = spec.flags.find((candidate) => candidate.field === "currency");
|
|
233
|
+
if (!flag) return "USD";
|
|
234
|
+
const given = values[flag.flag];
|
|
235
|
+
if (typeof given === "string") return given.trim().toUpperCase();
|
|
236
|
+
if (typeof input.currency === "string") {
|
|
237
|
+
const currency = input.currency.trim().toUpperCase();
|
|
238
|
+
input.currency = currency;
|
|
239
|
+
return currency;
|
|
240
|
+
}
|
|
241
|
+
return env[FROM_ENV.currency]?.trim().toUpperCase() || "USD";
|
|
242
|
+
}
|
|
243
|
+
function cancelPreview(spec, argv, env) {
|
|
233
244
|
const flag = spec.tool === "cancel_order" ? spec.flags.find((f) => f.field === "maximumPenalty") : void 0;
|
|
234
245
|
if (!flag) return null;
|
|
235
246
|
const { values, positionals: positionals2 } = parseOptions(spec, argv);
|
|
236
|
-
|
|
247
|
+
const close = values.close === true;
|
|
248
|
+
const penalty = values[flag.flag] !== void 0;
|
|
249
|
+
if (close && penalty) {
|
|
250
|
+
throw usageError(
|
|
251
|
+
`--close and --${flag.flag} can't be given together: --close closes an unpaid order, --${flag.flag} cancels a paid one`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
237
254
|
if (positionals2.length !== 1) throw usageError(`Usage: ${usageLine(spec)}`);
|
|
238
255
|
const input = { orderId: positionals2[0] };
|
|
239
|
-
|
|
256
|
+
const request = close || penalty ? parseCommand(spec, argv, env) : null;
|
|
257
|
+
if (!request) check({ ...spec, tool: "get_order" }, input, HTTP_ROUTES.get_order, /* @__PURE__ */ new Map());
|
|
240
258
|
const orderId = input.orderId;
|
|
241
|
-
return { method: "GET", path: API.order(orderId), flag: `--${flag.flag}`, orderId };
|
|
259
|
+
return { method: "GET", path: API.order(orderId), flag: `--${flag.flag}`, orderId, close, request };
|
|
242
260
|
}
|
|
243
261
|
function check(spec, input, route, fromEnv) {
|
|
244
262
|
const schema = TOOLS.find((tool) => tool.name === spec.tool)?.input;
|
|
@@ -264,7 +282,7 @@ function check(spec, input, route, fromEnv) {
|
|
|
264
282
|
{ details: { issues } }
|
|
265
283
|
);
|
|
266
284
|
}
|
|
267
|
-
function setFlags(spec, values, input) {
|
|
285
|
+
function setFlags(spec, values, input, currency) {
|
|
268
286
|
const given = spec.flags.filter((flag) => values[flag.flag] !== void 0);
|
|
269
287
|
const picked = /* @__PURE__ */ new Map();
|
|
270
288
|
for (const flag of given) {
|
|
@@ -292,7 +310,7 @@ function setFlags(spec, values, input) {
|
|
|
292
310
|
if (flag.field === GUEST_FIELD) {
|
|
293
311
|
setField(input, ROOMS_FIELD, withGuests(getField(input, ROOMS_FIELD), parseGuests(raw)));
|
|
294
312
|
} else {
|
|
295
|
-
setField(input, flag.field, readFlag(flag, raw));
|
|
313
|
+
setField(input, flag.field, readFlag(flag, raw, currency));
|
|
296
314
|
}
|
|
297
315
|
}
|
|
298
316
|
}
|
|
@@ -352,7 +370,7 @@ function setField(body, field, value) {
|
|
|
352
370
|
for (const part of path) node = step(node, part, true);
|
|
353
371
|
node[last] = value;
|
|
354
372
|
}
|
|
355
|
-
function readFlag(flag, raw) {
|
|
373
|
+
function readFlag(flag, raw, currency) {
|
|
356
374
|
if (flag.type === "boolean") return flag.value ?? true;
|
|
357
375
|
const given = Array.isArray(raw) ? raw : [raw];
|
|
358
376
|
switch (flag.field) {
|
|
@@ -362,7 +380,8 @@ function readFlag(flag, raw) {
|
|
|
362
380
|
return given.map(parseRoom);
|
|
363
381
|
case "filters.price.maxPerRoomNight":
|
|
364
382
|
case "total":
|
|
365
|
-
|
|
383
|
+
case "maximumPenalty":
|
|
384
|
+
return { amount: given[0].trim(), currency };
|
|
366
385
|
}
|
|
367
386
|
const parsed = given.map((value) => {
|
|
368
387
|
if (flag.type === "number") return num(flag.flag, value);
|
|
@@ -429,11 +448,6 @@ function withGuests(fromBody, guests) {
|
|
|
429
448
|
return rooms;
|
|
430
449
|
}
|
|
431
450
|
|
|
432
|
-
// src/guide.ts
|
|
433
|
-
function readGuide(topic) {
|
|
434
|
-
return renderGuide("cli", topic).replaceAll("fortrip@latest", `fortrip@${VERSION}`);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
451
|
// ../../node_modules/.pnpm/uqr@0.1.3/node_modules/uqr/dist/index.mjs
|
|
438
452
|
var QrCodeDataType = /* @__PURE__ */ ((QrCodeDataType2) => {
|
|
439
453
|
QrCodeDataType2[QrCodeDataType2["Border"] = -1] = "Border";
|
|
@@ -1170,15 +1184,6 @@ async function run(argv) {
|
|
|
1170
1184
|
process.stdout.write(commandHelp(spec));
|
|
1171
1185
|
return void 0;
|
|
1172
1186
|
}
|
|
1173
|
-
if (spec.group === null && spec.name === "guide") {
|
|
1174
|
-
const { positionals: positionals2 } = parseOptions(spec, rest);
|
|
1175
|
-
const topic = positionals2.join(" ");
|
|
1176
|
-
if (topic !== "" && topic !== "planning") {
|
|
1177
|
-
throw usageError("Usage: fortrip guide [planning]");
|
|
1178
|
-
}
|
|
1179
|
-
process.stdout.write(readGuide(topic || "main"));
|
|
1180
|
-
return void 0;
|
|
1181
|
-
}
|
|
1182
1187
|
const apiUrl = resolveApiUrl();
|
|
1183
1188
|
const log = (line) => process.stderr.write(`${line}
|
|
1184
1189
|
`);
|
|
@@ -1202,29 +1207,78 @@ async function run(argv) {
|
|
|
1202
1207
|
case "mcp": {
|
|
1203
1208
|
parseOptions(spec, rest);
|
|
1204
1209
|
const mcpUrl = resolveMcpUrl(apiUrl);
|
|
1205
|
-
const { runMcpBridge } = await import("./mcp-bridge-
|
|
1210
|
+
const { runMcpBridge } = await import("./mcp-bridge-WB44PZPA.js");
|
|
1206
1211
|
await runMcpBridge(mcpUrl, apiUrl);
|
|
1207
1212
|
return void 0;
|
|
1208
1213
|
}
|
|
1209
1214
|
}
|
|
1210
1215
|
}
|
|
1211
|
-
const preview = cancelPreview(spec, rest);
|
|
1212
|
-
if (preview)
|
|
1213
|
-
const order2 = unwrap(await authorizedRequest(apiUrl, preview.path, { method: preview.method }));
|
|
1214
|
-
throw usageError(notCancelled(spec, preview.flag, preview.orderId, order2));
|
|
1215
|
-
}
|
|
1216
|
+
const preview = cancelPreview(spec, rest, process.env);
|
|
1217
|
+
if (preview) return cancelOrder(apiUrl, spec, preview);
|
|
1216
1218
|
const { method, path, body } = parseCommand(spec, rest, process.env);
|
|
1219
|
+
if (spec.tool === "pay_order" && body) await inOrderCurrency(apiUrl, spec, rest, body);
|
|
1217
1220
|
const data = unwrap(await authorizedRequest(apiUrl, path, { method, body }));
|
|
1218
1221
|
return { data, text: renderToolResult(spec.tool, data, "cli") };
|
|
1219
1222
|
}
|
|
1223
|
+
async function inOrderCurrency(apiUrl, spec, rest, body) {
|
|
1224
|
+
const [orderId] = parseOptions(spec, rest).positionals;
|
|
1225
|
+
const order2 = unwrap(await authorizedRequest(apiUrl, API.order(orderId), { method: "GET" }));
|
|
1226
|
+
const currency = order2?.price?.total?.currency;
|
|
1227
|
+
if (typeof currency !== "string" || !CURRENCIES.includes(currency)) {
|
|
1228
|
+
throw new CliError(
|
|
1229
|
+
`Not sent: the order ${orderId} has no price.total.currency in USD or CNY to pay in.`,
|
|
1230
|
+
EXIT.error
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
body.total = { ...body.total, currency };
|
|
1234
|
+
check(spec, { ...body, orderId }, HTTP_ROUTES.pay_order, /* @__PURE__ */ new Map());
|
|
1235
|
+
}
|
|
1236
|
+
async function cancelOrder(apiUrl, spec, preview) {
|
|
1237
|
+
const { flag, orderId, close, request } = preview;
|
|
1238
|
+
const order2 = unwrap(await authorizedRequest(apiUrl, preview.path, { method: preview.method }));
|
|
1239
|
+
const read = order2;
|
|
1240
|
+
const closable = read?.cancel?.available === true && read.cancel.reason === "unpaid";
|
|
1241
|
+
if (!request || !close && closable) throw usageError(notCancelled(spec, flag, orderId, order2));
|
|
1242
|
+
if (close) {
|
|
1243
|
+
if (read?.status === "expired") return { data: order2, text: renderToolResult("cancel_order", order2, "cli") };
|
|
1244
|
+
if (!closable) {
|
|
1245
|
+
if (read?.cancel?.available === true && read.cancel.reason === "cancellable") {
|
|
1246
|
+
throw usageError(
|
|
1247
|
+
`Not closed: the order is paid. To cancel it under its terms, show the user cancel.penalty and, once they agree, run \`${commandInvocation(spec)} ${orderId} ${flag} <amount>\`.`
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
throw new CliError(["Not closed: nothing was sent.", ...orderLines(order2)].join("\n"), EXIT.error);
|
|
1251
|
+
}
|
|
1252
|
+
const data2 = unwrap(await authorizedRequest(apiUrl, request.path, { method: "POST", body: request.body }));
|
|
1253
|
+
const text = renderToolResult("cancel_order", data2, "cli");
|
|
1254
|
+
if (data2?.status !== "expired") {
|
|
1255
|
+
throw new CliError(["Not closed: it was paid meanwhile.", text].join("\n"), EXIT.error);
|
|
1256
|
+
}
|
|
1257
|
+
return { data: data2, text };
|
|
1258
|
+
}
|
|
1259
|
+
const penalty = read?.cancel?.penalty?.currency;
|
|
1260
|
+
const currency = typeof penalty === "string" ? penalty : read?.price?.total?.currency;
|
|
1261
|
+
if (typeof currency !== "string") {
|
|
1262
|
+
throw new CliError(`Not sent: the order ${orderId} has no currency to send the penalty in.`, EXIT.error);
|
|
1263
|
+
}
|
|
1264
|
+
const body = request.body;
|
|
1265
|
+
body.maximumPenalty = { ...body.maximumPenalty, currency };
|
|
1266
|
+
check(spec, { ...body, orderId }, HTTP_ROUTES.cancel_order, /* @__PURE__ */ new Map());
|
|
1267
|
+
const data = unwrap(await authorizedRequest(apiUrl, request.path, { method: "POST", body }));
|
|
1268
|
+
return { data, text: renderToolResult("cancel_order", data, "cli") };
|
|
1269
|
+
}
|
|
1270
|
+
function orderLines(order2) {
|
|
1271
|
+
return renderToolResult("get_order", order2, "cli").split("\n").filter((text) => text.startsWith("Hotel: ") || text.startsWith("Cancel: "));
|
|
1272
|
+
}
|
|
1220
1273
|
function notCancelled(spec, flag, orderId, order2) {
|
|
1221
|
-
const lines = renderToolResult("get_order", order2, "cli").split("\n").filter((text) => text.startsWith("Hotel: ") || text.startsWith("Cancel: "));
|
|
1222
1274
|
const parsed = order.safeParse(order2);
|
|
1223
1275
|
const cancel = parsed.success ? parsed.data.cancel : void 0;
|
|
1224
|
-
const next = cancel?.available && cancel.
|
|
1276
|
+
const next = cancel?.available && cancel.reason === "unpaid" ? [
|
|
1277
|
+
`Only once the user says they no longer want this order, run \`${commandInvocation(spec)} ${orderId} --close\`.`
|
|
1278
|
+
] : cancel?.available && cancel.penalty ? [
|
|
1225
1279
|
`Show the user the stay, this penalty and this refund, and ask them to confirm. Only after a clear yes, run \`${commandInvocation(spec)} ${orderId} ${flag} ${cancel.penalty.amount}\`.`
|
|
1226
1280
|
] : cancel ? [] : [`${commandInvocation(spec)} needs ${flag}, the penalty the user agreed to.`];
|
|
1227
|
-
return ["Not cancelled: nothing was sent.", ...
|
|
1281
|
+
return ["Not cancelled: nothing was sent.", ...orderLines(order2), ...next].join("\n");
|
|
1228
1282
|
}
|
|
1229
1283
|
function account(data) {
|
|
1230
1284
|
const { apiUrl, userId, email, name } = data;
|
|
@@ -1253,8 +1307,9 @@ function takeJson(argv) {
|
|
|
1253
1307
|
}
|
|
1254
1308
|
function walletCode(argv, data) {
|
|
1255
1309
|
if (argv[0] !== "orders" || argv[1] !== "pay" || !process.stdout.isTTY) return null;
|
|
1256
|
-
const
|
|
1257
|
-
const
|
|
1310
|
+
const methods = data?.payment?.methods;
|
|
1311
|
+
const wallet = Array.isArray(methods) ? methods.find((m) => m?.id === "stripe_alipay_wechat_pay") : void 0;
|
|
1312
|
+
const qrData = wallet?.wechatPay?.qrData;
|
|
1258
1313
|
return typeof qrData === "string" ? terminalQr(qrData, process.stdout.columns) : null;
|
|
1259
1314
|
}
|
|
1260
1315
|
async function main() {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
renderError,
|
|
12
12
|
renderGuide,
|
|
13
13
|
requireToken
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-DYSYHQQY.js";
|
|
15
15
|
|
|
16
16
|
// src/mcp-bridge.ts
|
|
17
17
|
import {
|
|
@@ -208,17 +208,13 @@ function localServer() {
|
|
|
208
208
|
title: spec.title,
|
|
209
209
|
description: spec.description,
|
|
210
210
|
annotations: spec.annotations,
|
|
211
|
-
|
|
211
|
+
outputSchema: passThrough(spec.output)
|
|
212
212
|
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
{ ...config, inputSchema: passThrough(spec.input) },
|
|
219
|
-
handler
|
|
220
|
-
);
|
|
221
|
-
}
|
|
213
|
+
server.registerTool(
|
|
214
|
+
spec.name,
|
|
215
|
+
{ ...config, inputSchema: passThrough(spec.input) },
|
|
216
|
+
handler
|
|
217
|
+
);
|
|
222
218
|
}
|
|
223
219
|
return server;
|
|
224
220
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fortrip",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-rc.2",
|
|
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",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typescript": "^5.9.0",
|
|
34
34
|
"uqr": "0.1.3",
|
|
35
35
|
"zod": "4.4.3",
|
|
36
|
-
"@fortrip/agent-contract": "
|
|
36
|
+
"@fortrip/agent-contract": "5.0.0-rc.2"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsup",
|