ktemia 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/index.cjs +1053 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +371 -0
- package/dist/index.d.ts +371 -0
- package/dist/index.js +1001 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -2
package/dist/index.js
ADDED
|
@@ -0,0 +1,1001 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var BRAND = /* @__PURE__ */ Symbol.for("ktemia.error");
|
|
3
|
+
var KtemiaError = class _KtemiaError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
status;
|
|
6
|
+
param;
|
|
7
|
+
retryable;
|
|
8
|
+
retryAfter;
|
|
9
|
+
body;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options.message);
|
|
12
|
+
this.name = "KtemiaError";
|
|
13
|
+
this.code = options.code;
|
|
14
|
+
this.status = options.status;
|
|
15
|
+
this.param = options.param;
|
|
16
|
+
this.retryable = options.retryable ?? false;
|
|
17
|
+
this.retryAfter = options.retryAfter;
|
|
18
|
+
this.body = options.body;
|
|
19
|
+
Object.defineProperty(this, BRAND, { value: true });
|
|
20
|
+
}
|
|
21
|
+
static [Symbol.hasInstance](value) {
|
|
22
|
+
if (this !== _KtemiaError) return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
23
|
+
return typeof value === "object" && value !== null && value[BRAND] === true;
|
|
24
|
+
}
|
|
25
|
+
/** A plain object safe to hand to a model or a log line. Never holds the key. */
|
|
26
|
+
toJSON() {
|
|
27
|
+
return {
|
|
28
|
+
code: this.code,
|
|
29
|
+
message: this.message,
|
|
30
|
+
retryable: this.retryable,
|
|
31
|
+
...this.param ? { param: this.param } : {},
|
|
32
|
+
...this.retryAfter !== void 0 ? { retryAfter: this.retryAfter } : {}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var KtemiaValidationError = class extends KtemiaError {
|
|
37
|
+
constructor(param, message) {
|
|
38
|
+
super({
|
|
39
|
+
code: "INVALID_INPUT",
|
|
40
|
+
status: 400,
|
|
41
|
+
param,
|
|
42
|
+
message: `${message} Nothing was sent to Ktemia, so no quota was used.`
|
|
43
|
+
});
|
|
44
|
+
this.name = "KtemiaValidationError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var EMPTY_RESULT_CODES = /* @__PURE__ */ new Set(["NO_RESULTS", "NO_MORE_RESULTS"]);
|
|
48
|
+
function isKtemiaError(error) {
|
|
49
|
+
return error instanceof KtemiaError;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/validate.ts
|
|
53
|
+
var MAX_PASSENGERS = 9;
|
|
54
|
+
var MAX_NIGHTS = 30;
|
|
55
|
+
var MIN_LEGS = 2;
|
|
56
|
+
var MAX_LEGS = 6;
|
|
57
|
+
var DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
58
|
+
var PLACE_RE = /^[A-Z]{3,4}$/;
|
|
59
|
+
var TIME_RE = /^([01]\d|2[0-3]):(00|30)$/;
|
|
60
|
+
function earliestDate(now) {
|
|
61
|
+
const d = new Date(now.getTime());
|
|
62
|
+
d.setUTCDate(d.getUTCDate() - 1);
|
|
63
|
+
return d.toISOString().slice(0, 10);
|
|
64
|
+
}
|
|
65
|
+
function checkDate(value, param, now = /* @__PURE__ */ new Date()) {
|
|
66
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
67
|
+
const match = DATE_RE.exec(text);
|
|
68
|
+
if (!match) {
|
|
69
|
+
throw new KtemiaValidationError(
|
|
70
|
+
param,
|
|
71
|
+
`${param} must be a date written YYYY-MM-DD, for example 2027-03-14.`
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const [, y, m, d] = match;
|
|
75
|
+
const parsed = new Date(Date.UTC(Number(y), Number(m) - 1, Number(d)));
|
|
76
|
+
if (parsed.toISOString().slice(0, 10) !== text) {
|
|
77
|
+
throw new KtemiaValidationError(param, `${param} is not a real calendar date: ${text}.`);
|
|
78
|
+
}
|
|
79
|
+
if (text < earliestDate(now)) {
|
|
80
|
+
throw new KtemiaValidationError(
|
|
81
|
+
param,
|
|
82
|
+
`${param} ${text} is in the past. Ask the user for a future date.`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return text;
|
|
86
|
+
}
|
|
87
|
+
function checkPlace(value, param) {
|
|
88
|
+
const code = typeof value === "string" ? value.trim().toUpperCase() : "";
|
|
89
|
+
if (!PLACE_RE.test(code)) {
|
|
90
|
+
throw new KtemiaValidationError(
|
|
91
|
+
param,
|
|
92
|
+
`${param} must be a 3 or 4 letter IATA airport or city code such as LHR or LON, not a place name. Resolve the name with a lookup (kind "airport") first.`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return code;
|
|
96
|
+
}
|
|
97
|
+
function checkText(value, param, hint) {
|
|
98
|
+
const text = typeof value === "string" ? value.trim() : typeof value === "number" ? String(value) : "";
|
|
99
|
+
if (!text) throw new KtemiaValidationError(param, `${param} is required. ${hint}`);
|
|
100
|
+
return text;
|
|
101
|
+
}
|
|
102
|
+
function checkTime(value, param) {
|
|
103
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
104
|
+
if (!TIME_RE.test(text)) {
|
|
105
|
+
throw new KtemiaValidationError(
|
|
106
|
+
param,
|
|
107
|
+
`${param} must be HH:MM in 24-hour time, on the hour or half hour, for example 09:30.`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return text;
|
|
111
|
+
}
|
|
112
|
+
function daysBetween(from, to) {
|
|
113
|
+
return (Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 864e5;
|
|
114
|
+
}
|
|
115
|
+
function checkPassengers(p) {
|
|
116
|
+
const adults = p.adults ?? 1;
|
|
117
|
+
const children = p.children ?? 0;
|
|
118
|
+
const infants = p.infantsOnLap ?? 0;
|
|
119
|
+
for (const [name, n] of Object.entries({ adults, children, infantsOnLap: infants })) {
|
|
120
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
121
|
+
throw new KtemiaValidationError(`passengers.${name}`, `passengers.${name} must be a whole number of 0 or more.`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const total = adults + children + infants;
|
|
125
|
+
if (total === 0) {
|
|
126
|
+
throw new KtemiaValidationError("passengers", "A flight search needs at least one passenger.");
|
|
127
|
+
}
|
|
128
|
+
if (total > MAX_PASSENGERS) {
|
|
129
|
+
throw new KtemiaValidationError(
|
|
130
|
+
"passengers",
|
|
131
|
+
`At most ${MAX_PASSENGERS} passengers fit in one search (got ${total}). Split the group into several searches.`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
if (infants > adults) {
|
|
135
|
+
throw new KtemiaValidationError(
|
|
136
|
+
"passengers.infantsOnLap",
|
|
137
|
+
"Each lap infant needs an adult. Count an infant with their own seat as a child instead."
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function checkFlightSearch(params, now = /* @__PURE__ */ new Date()) {
|
|
142
|
+
const body = { ...params };
|
|
143
|
+
const flat = [params.origin, params.destination, params.departureDate, params.returnDate].some(
|
|
144
|
+
(v) => v !== void 0 && v !== null && v !== ""
|
|
145
|
+
);
|
|
146
|
+
const hasLegs = Array.isArray(params.legs) && params.legs.length > 0;
|
|
147
|
+
if (flat && hasLegs) {
|
|
148
|
+
throw new KtemiaValidationError(
|
|
149
|
+
"legs",
|
|
150
|
+
"Pass either origin, destination and departureDate (one-way or return), or legs (multi-city), not both."
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (hasLegs) {
|
|
154
|
+
const legs = params.legs;
|
|
155
|
+
if (legs.length < MIN_LEGS || legs.length > MAX_LEGS) {
|
|
156
|
+
throw new KtemiaValidationError(
|
|
157
|
+
"legs",
|
|
158
|
+
`A multi-city trip has ${MIN_LEGS} to ${MAX_LEGS} legs (got ${legs.length}). Use origin and destination for a one-way trip.`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
let previous = "";
|
|
162
|
+
body.legs = legs.map((leg, i) => {
|
|
163
|
+
const date = checkDate(leg.date, `legs[${i}].date`, now);
|
|
164
|
+
if (previous && date < previous) {
|
|
165
|
+
throw new KtemiaValidationError(`legs[${i}].date`, "Legs must be in travel order, each on or after the one before.");
|
|
166
|
+
}
|
|
167
|
+
previous = date;
|
|
168
|
+
return {
|
|
169
|
+
origin: checkPlace(leg.origin, `legs[${i}].origin`),
|
|
170
|
+
destination: checkPlace(leg.destination, `legs[${i}].destination`),
|
|
171
|
+
date
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
} else {
|
|
175
|
+
for (const name of ["origin", "destination", "departureDate"]) {
|
|
176
|
+
if (!params[name]) {
|
|
177
|
+
throw new KtemiaValidationError(
|
|
178
|
+
name,
|
|
179
|
+
`A flight search needs origin, destination and departureDate (${name} is missing). Ask the user rather than guessing.`
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
body.origin = checkPlace(params.origin, "origin");
|
|
184
|
+
body.destination = checkPlace(params.destination, "destination");
|
|
185
|
+
body.departureDate = checkDate(params.departureDate, "departureDate", now);
|
|
186
|
+
if (params.returnDate) {
|
|
187
|
+
body.returnDate = checkDate(params.returnDate, "returnDate", now);
|
|
188
|
+
if (body.returnDate < body.departureDate) {
|
|
189
|
+
throw new KtemiaValidationError("returnDate", "returnDate is before departureDate.");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (params.passengers) checkPassengers(params.passengers);
|
|
194
|
+
return body;
|
|
195
|
+
}
|
|
196
|
+
function checkHotelSearch(params, now = /* @__PURE__ */ new Date()) {
|
|
197
|
+
const location = checkText(
|
|
198
|
+
params.location,
|
|
199
|
+
"location",
|
|
200
|
+
'Use the locationId from a lookup with kind "hotelLocation"; a city name is not accepted.'
|
|
201
|
+
);
|
|
202
|
+
const checkin = checkDate(params.checkin, "checkin", now);
|
|
203
|
+
const checkout = checkDate(params.checkout, "checkout", now);
|
|
204
|
+
const nights = daysBetween(checkin, checkout);
|
|
205
|
+
if (nights < 1) {
|
|
206
|
+
throw new KtemiaValidationError("checkout", "checkout must be at least one day after checkin.");
|
|
207
|
+
}
|
|
208
|
+
if (nights > MAX_NIGHTS) {
|
|
209
|
+
throw new KtemiaValidationError(
|
|
210
|
+
"checkout",
|
|
211
|
+
`Stays are limited to ${MAX_NIGHTS} nights (got ${nights}). Split a longer stay into several searches.`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
return { ...params, location, checkin, checkout };
|
|
215
|
+
}
|
|
216
|
+
function checkCarSearch(params, now = /* @__PURE__ */ new Date()) {
|
|
217
|
+
const pickupLocation = checkText(
|
|
218
|
+
params.pickupLocation,
|
|
219
|
+
"pickupLocation",
|
|
220
|
+
'Use the locationId from a lookup with kind "carLocation".'
|
|
221
|
+
);
|
|
222
|
+
const pickupDate = checkDate(params.pickupDate, "pickupDate", now);
|
|
223
|
+
const dropoffDate = checkDate(params.dropoffDate, "dropoffDate", now);
|
|
224
|
+
if (dropoffDate < pickupDate) {
|
|
225
|
+
throw new KtemiaValidationError("dropoffDate", "dropoffDate cannot be before pickupDate.");
|
|
226
|
+
}
|
|
227
|
+
const body = { ...params, pickupLocation, pickupDate, dropoffDate };
|
|
228
|
+
if (params.dropoffLocation !== void 0 && params.dropoffLocation !== "") {
|
|
229
|
+
body.dropoffLocation = checkText(params.dropoffLocation, "dropoffLocation", "Omit it to return the car where it was collected.");
|
|
230
|
+
}
|
|
231
|
+
if (params.pickupTime) body.pickupTime = checkTime(params.pickupTime, "pickupTime");
|
|
232
|
+
if (params.dropoffTime) body.dropoffTime = checkTime(params.dropoffTime, "dropoffTime");
|
|
233
|
+
return body;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// src/client.ts
|
|
237
|
+
var VERSION = "0.1.0";
|
|
238
|
+
var DEFAULT_BASE_URL = "https://api.ktemia.com";
|
|
239
|
+
var API_KEYS_URL = "https://app.ktemia.com/api-keys";
|
|
240
|
+
var MAX_RETRY_AFTER_SECONDS = 30;
|
|
241
|
+
var SERVER_RETRY_DELAY_MS = 1e3;
|
|
242
|
+
var LOOKUP_PATHS = {
|
|
243
|
+
airport: "/flights/airports",
|
|
244
|
+
airline: "/flights/airlines",
|
|
245
|
+
hotelLocation: "/hotels/locations",
|
|
246
|
+
carLocation: "/cars/locations"
|
|
247
|
+
};
|
|
248
|
+
function env(name) {
|
|
249
|
+
const value = globalThis.process?.env?.[name];
|
|
250
|
+
return value && value.trim() ? value.trim() : void 0;
|
|
251
|
+
}
|
|
252
|
+
function resolveBaseUrl(explicit) {
|
|
253
|
+
const raw = (explicit ?? env("KTEMIA_API_URL") ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
254
|
+
const url = new URL(raw);
|
|
255
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1";
|
|
256
|
+
if (url.protocol !== "https:" && !local) {
|
|
257
|
+
throw new KtemiaError({
|
|
258
|
+
code: "INSECURE_API_URL",
|
|
259
|
+
status: 0,
|
|
260
|
+
message: `The Ktemia base URL must use https (got ${url.protocol}//${url.host}).`
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
return raw;
|
|
264
|
+
}
|
|
265
|
+
function parseErrorBody(body) {
|
|
266
|
+
if (typeof body !== "object" || body === null) return null;
|
|
267
|
+
const error = body.error;
|
|
268
|
+
if (typeof error !== "object" || error === null) return null;
|
|
269
|
+
const { code, message, param } = error;
|
|
270
|
+
if (typeof code !== "string" || typeof message !== "string") return null;
|
|
271
|
+
return { code, message, ...typeof param === "string" ? { param } : {} };
|
|
272
|
+
}
|
|
273
|
+
function parseRetryAfter(header) {
|
|
274
|
+
if (header === null || header.trim() === "") return void 0;
|
|
275
|
+
const value = header.trim();
|
|
276
|
+
let seconds = Number(value);
|
|
277
|
+
if (!Number.isFinite(seconds)) {
|
|
278
|
+
const at = Date.parse(value);
|
|
279
|
+
if (Number.isNaN(at)) return void 0;
|
|
280
|
+
seconds = (at - Date.now()) / 1e3;
|
|
281
|
+
}
|
|
282
|
+
return Math.min(Math.max(Math.ceil(seconds), 0), MAX_RETRY_AFTER_SECONDS);
|
|
283
|
+
}
|
|
284
|
+
function errorFromResponse(response, body) {
|
|
285
|
+
const parsed = parseErrorBody(body);
|
|
286
|
+
const status = response.status;
|
|
287
|
+
const retryAfter = parseRetryAfter(response.headers.get("Retry-After"));
|
|
288
|
+
if (status === 429) {
|
|
289
|
+
const code = parsed?.code ?? "RATE_LIMIT_EXCEEDED";
|
|
290
|
+
if (code === "QUOTA_EXCEEDED") {
|
|
291
|
+
const limit = response.headers.get("X-Quota-Limit");
|
|
292
|
+
return new KtemiaError({
|
|
293
|
+
code,
|
|
294
|
+
status,
|
|
295
|
+
body,
|
|
296
|
+
retryable: false,
|
|
297
|
+
message: (parsed?.message ?? "The monthly request quota for this account is used up.") + " Retrying will not help, and another key on the same account shares the same quota." + (limit ? ` The plan allows ${limit} requests a month.` : "") + " Check the key status (free) for the reset date, or upgrade at https://www.ktemia.com/pricing/."
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return new KtemiaError({
|
|
301
|
+
code,
|
|
302
|
+
status,
|
|
303
|
+
body,
|
|
304
|
+
retryable: true,
|
|
305
|
+
...retryAfter !== void 0 ? { retryAfter } : {},
|
|
306
|
+
message: (parsed?.message ?? "Too many requests per second.") + ` This is a speed limit, not the monthly quota: wait ${retryAfter ?? "a few"} seconds and retry.`
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
if (parsed) {
|
|
310
|
+
return new KtemiaError({
|
|
311
|
+
code: parsed.code,
|
|
312
|
+
status,
|
|
313
|
+
body,
|
|
314
|
+
retryable: status >= 500,
|
|
315
|
+
...parsed.param ? { param: parsed.param } : {},
|
|
316
|
+
message: parsed.message
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
return new KtemiaError({
|
|
320
|
+
code: status >= 500 ? "UPSTREAM_ERROR" : "REQUEST_FAILED",
|
|
321
|
+
status,
|
|
322
|
+
body,
|
|
323
|
+
retryable: status >= 500,
|
|
324
|
+
message: `The Ktemia API returned HTTP ${status}.`
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
function compact(obj) {
|
|
328
|
+
const out = {};
|
|
329
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
330
|
+
if (value !== void 0 && value !== null) out[key] = value;
|
|
331
|
+
}
|
|
332
|
+
return out;
|
|
333
|
+
}
|
|
334
|
+
var VerticalResource = class {
|
|
335
|
+
constructor(client, vertical, check) {
|
|
336
|
+
this.client = client;
|
|
337
|
+
this.vertical = vertical;
|
|
338
|
+
this.check = check;
|
|
339
|
+
}
|
|
340
|
+
client;
|
|
341
|
+
vertical;
|
|
342
|
+
check;
|
|
343
|
+
/**
|
|
344
|
+
* Starts a search and reads its first page. Costs two requests.
|
|
345
|
+
* A search that matches nothing returns a page with `noResults` set.
|
|
346
|
+
*/
|
|
347
|
+
async search(params, options = {}) {
|
|
348
|
+
const body = compact(this.check(params));
|
|
349
|
+
let started;
|
|
350
|
+
try {
|
|
351
|
+
started = await this.client.request("POST", `/${this.vertical}/search`, {
|
|
352
|
+
body,
|
|
353
|
+
signal: options.signal
|
|
354
|
+
});
|
|
355
|
+
} catch (error) {
|
|
356
|
+
if (error instanceof KtemiaError && EMPTY_RESULT_CODES.has(error.code)) {
|
|
357
|
+
return this.empty("", error);
|
|
358
|
+
}
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
if (!started.searchToken) {
|
|
362
|
+
throw new KtemiaError({
|
|
363
|
+
code: "UPSTREAM_ERROR",
|
|
364
|
+
status: 502,
|
|
365
|
+
retryable: true,
|
|
366
|
+
message: `Ktemia started a ${this.vertical} search but returned no search token.`
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
return this.page(started.searchToken, options);
|
|
370
|
+
}
|
|
371
|
+
/** Reads the page at `token`: a searchToken, or the nextToken of the previous page. Costs one request. */
|
|
372
|
+
async page(token, options = {}) {
|
|
373
|
+
const t = checkText(token, "token", "Use the nextToken from the previous page.");
|
|
374
|
+
try {
|
|
375
|
+
const body = await this.client.request("GET", `/${this.vertical}/results`, {
|
|
376
|
+
query: { token: t },
|
|
377
|
+
signal: options.signal
|
|
378
|
+
});
|
|
379
|
+
return { ...body, vertical: this.vertical, token: t, hasMore: Boolean(body.hasMore) };
|
|
380
|
+
} catch (error) {
|
|
381
|
+
if (error instanceof KtemiaError && EMPTY_RESULT_CODES.has(error.code)) {
|
|
382
|
+
return this.empty(t, error);
|
|
383
|
+
}
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/** Every price and booking link for one result. `token` is the token of the page it appeared on. */
|
|
388
|
+
async details(token, resultId, options = {}) {
|
|
389
|
+
const query = {
|
|
390
|
+
token: checkText(token, "token", "Use the token of the page the result appeared on."),
|
|
391
|
+
resultId: checkText(resultId, "resultId", "Use the id of a result from a search page.")
|
|
392
|
+
};
|
|
393
|
+
return this.client.request("GET", `/${this.vertical}/details`, {
|
|
394
|
+
query,
|
|
395
|
+
signal: options.signal
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
empty(token, error) {
|
|
399
|
+
return {
|
|
400
|
+
vertical: this.vertical,
|
|
401
|
+
token,
|
|
402
|
+
hasMore: false,
|
|
403
|
+
[this.vertical]: [],
|
|
404
|
+
noResults: { code: error.code, message: error.message }
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
var HotelsResource = class extends VerticalResource {
|
|
409
|
+
constructor(kt) {
|
|
410
|
+
super(kt, "hotels", (p) => checkHotelSearch(p));
|
|
411
|
+
this.kt = kt;
|
|
412
|
+
}
|
|
413
|
+
kt;
|
|
414
|
+
/** Guest reviews for one hotel. Pages are numbered, starting at 1. Costs one request. */
|
|
415
|
+
async reviews(params, options = {}) {
|
|
416
|
+
const hotelId = checkText(params.hotelId, "hotelId", "Use the id of a hotel from a search result.");
|
|
417
|
+
return this.kt.request("GET", "/hotels/reviews", {
|
|
418
|
+
query: compact({ ...params, hotelId }),
|
|
419
|
+
signal: options.signal
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
var Ktemia = class {
|
|
424
|
+
flights;
|
|
425
|
+
hotels;
|
|
426
|
+
cars;
|
|
427
|
+
apiKey;
|
|
428
|
+
baseUrl;
|
|
429
|
+
timeoutMs;
|
|
430
|
+
maxRetries;
|
|
431
|
+
fetchImpl;
|
|
432
|
+
clientId;
|
|
433
|
+
sleep;
|
|
434
|
+
constructor(options = {}) {
|
|
435
|
+
this.apiKey = options.apiKey?.trim() || env("KTEMIA_API_KEY");
|
|
436
|
+
this.baseUrl = resolveBaseUrl(options.baseUrl);
|
|
437
|
+
this.timeoutMs = options.timeoutMs ?? 6e4;
|
|
438
|
+
this.maxRetries = Math.max(0, options.maxRetries ?? 2);
|
|
439
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
440
|
+
this.clientId = options.userAgent ?? `ktemia-js/${VERSION}`;
|
|
441
|
+
this.sleep = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
442
|
+
this.flights = new VerticalResource(this, "flights", (p) => checkFlightSearch(p));
|
|
443
|
+
this.hotels = new HotelsResource(this);
|
|
444
|
+
this.cars = new VerticalResource(this, "cars", (p) => checkCarSearch(p));
|
|
445
|
+
}
|
|
446
|
+
/** Plan, rate limits, and remaining monthly quota. Free: never counts against the quota. */
|
|
447
|
+
keyStatus(options = {}) {
|
|
448
|
+
return this.request("GET", "/key", { signal: options.signal });
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Resolves a place or airline name to the codes searches need: IATA codes
|
|
452
|
+
* for flights, a locationId for hotels and cars. Costs one request.
|
|
453
|
+
*/
|
|
454
|
+
async lookup(params, options = {}) {
|
|
455
|
+
const path = LOOKUP_PATHS[params.kind];
|
|
456
|
+
if (!path) {
|
|
457
|
+
throw new KtemiaError({
|
|
458
|
+
code: "INVALID_INPUT",
|
|
459
|
+
status: 400,
|
|
460
|
+
param: "kind",
|
|
461
|
+
message: `kind must be one of ${Object.keys(LOOKUP_PATHS).join(", ")}.`
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const query = checkText(params.query, "query", "Pass a place, airport, or airline name.");
|
|
465
|
+
const body = await this.request("GET", path, {
|
|
466
|
+
query: compact({
|
|
467
|
+
query,
|
|
468
|
+
country: params.country,
|
|
469
|
+
locale: params.locale,
|
|
470
|
+
// Only the car endpoint takes a location type; others reject it.
|
|
471
|
+
...params.kind === "carLocation" && params.type ? { type: params.type } : {}
|
|
472
|
+
}),
|
|
473
|
+
signal: options.signal
|
|
474
|
+
});
|
|
475
|
+
return { kind: params.kind, ...body };
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Low-level call to any Ktemia endpoint, with the same authentication,
|
|
479
|
+
* error mapping, and retries as the typed methods.
|
|
480
|
+
*/
|
|
481
|
+
async request(method, path, options = {}) {
|
|
482
|
+
if (!this.apiKey) {
|
|
483
|
+
throw new KtemiaError({
|
|
484
|
+
code: "MISSING_API_KEY",
|
|
485
|
+
status: 401,
|
|
486
|
+
message: `No Ktemia API key. Set the KTEMIA_API_KEY environment variable or pass apiKey. Create a free key at ${API_KEYS_URL}; the Free plan includes 100 requests a month.`
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
const url = new URL(this.baseUrl + path);
|
|
490
|
+
for (const [key, value] of Object.entries(options.query ?? {})) {
|
|
491
|
+
if (value === void 0 || value === null) continue;
|
|
492
|
+
if (Array.isArray(value)) {
|
|
493
|
+
if (value.length) url.searchParams.set(key, value.map(String).join(","));
|
|
494
|
+
} else {
|
|
495
|
+
url.searchParams.set(key, String(value));
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
let rateLimitRetries = 0;
|
|
499
|
+
let serverRetried = false;
|
|
500
|
+
for (; ; ) {
|
|
501
|
+
let error;
|
|
502
|
+
try {
|
|
503
|
+
return await this.once(method, url, options);
|
|
504
|
+
} catch (caught) {
|
|
505
|
+
if (!(caught instanceof KtemiaError)) throw caught;
|
|
506
|
+
error = caught;
|
|
507
|
+
}
|
|
508
|
+
if (options.signal?.aborted) throw error;
|
|
509
|
+
if (error.code === "RATE_LIMIT_EXCEEDED" && rateLimitRetries < this.maxRetries) {
|
|
510
|
+
rateLimitRetries++;
|
|
511
|
+
await this.sleep((error.retryAfter ?? 1) * 1e3);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
if (error.retryable && error.code !== "RATE_LIMIT_EXCEEDED" && !serverRetried) {
|
|
515
|
+
serverRetried = true;
|
|
516
|
+
await this.sleep(SERVER_RETRY_DELAY_MS);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
throw error;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async once(method, url, options) {
|
|
523
|
+
const controller = new AbortController();
|
|
524
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
525
|
+
const onAbort = () => controller.abort();
|
|
526
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
527
|
+
let response;
|
|
528
|
+
try {
|
|
529
|
+
response = await this.fetchImpl(url, {
|
|
530
|
+
method,
|
|
531
|
+
headers: {
|
|
532
|
+
"X-API-Key": this.apiKey,
|
|
533
|
+
"X-Ktemia-Client": this.clientId,
|
|
534
|
+
Accept: "application/json",
|
|
535
|
+
...options.body !== void 0 ? { "Content-Type": "application/json" } : {}
|
|
536
|
+
},
|
|
537
|
+
...options.body !== void 0 ? { body: JSON.stringify(options.body) } : {},
|
|
538
|
+
signal: controller.signal,
|
|
539
|
+
// The key must never follow a redirect to another host.
|
|
540
|
+
redirect: "error"
|
|
541
|
+
});
|
|
542
|
+
} catch (cause) {
|
|
543
|
+
if (options.signal?.aborted) {
|
|
544
|
+
throw new KtemiaError({ code: "ABORTED", status: 0, message: "The request was cancelled." });
|
|
545
|
+
}
|
|
546
|
+
if (cause instanceof Error && cause.name === "AbortError") {
|
|
547
|
+
throw new KtemiaError({
|
|
548
|
+
code: "TIMEOUT",
|
|
549
|
+
status: 0,
|
|
550
|
+
retryable: true,
|
|
551
|
+
message: `The Ktemia API did not answer within ${Math.round(this.timeoutMs / 1e3)} seconds.`
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
throw new KtemiaError({
|
|
555
|
+
code: "NETWORK_ERROR",
|
|
556
|
+
status: 0,
|
|
557
|
+
retryable: true,
|
|
558
|
+
message: `Could not reach the Ktemia API: ${cause instanceof Error ? cause.message : String(cause)}`
|
|
559
|
+
});
|
|
560
|
+
} finally {
|
|
561
|
+
clearTimeout(timer);
|
|
562
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
563
|
+
}
|
|
564
|
+
const text = await response.text();
|
|
565
|
+
let body;
|
|
566
|
+
if (text) {
|
|
567
|
+
try {
|
|
568
|
+
body = JSON.parse(text);
|
|
569
|
+
} catch {
|
|
570
|
+
body = void 0;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (response.ok) {
|
|
574
|
+
if (body === void 0) {
|
|
575
|
+
throw new KtemiaError({
|
|
576
|
+
code: "UPSTREAM_ERROR",
|
|
577
|
+
status: response.status,
|
|
578
|
+
retryable: true,
|
|
579
|
+
message: "The Ktemia API answered with something that was not JSON."
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
return body;
|
|
583
|
+
}
|
|
584
|
+
throw errorFromResponse(response, body);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
// src/tools.json
|
|
589
|
+
var tools_default = {
|
|
590
|
+
specVersion: 1,
|
|
591
|
+
_comment: [
|
|
592
|
+
"Single source of truth for tool names, prose, enums, and defaults.",
|
|
593
|
+
"Both the TypeScript and Python servers read this file, so an agent sees",
|
|
594
|
+
"identical tool behaviour whether it was installed with npx or uvx.",
|
|
595
|
+
"Validation schemas stay native (zod / pydantic); only the shared contract",
|
|
596
|
+
"lives here. A parity test asserts both implementations expose exactly the",
|
|
597
|
+
"tool and parameter names below."
|
|
598
|
+
],
|
|
599
|
+
shared: {
|
|
600
|
+
quotaNote: "Costs one API request against the account's monthly quota. Starting a search and reading each page are separate requests.",
|
|
601
|
+
tokenLifetimeNote: "Tokens are opaque and expire one hour after the search starts. Page through with the nextToken from the previous page; when nextToken is absent there are no more pages. If a token has expired, start a new search rather than retrying the same token.",
|
|
602
|
+
askDoNotGuessNote: "Ask the user for anything missing rather than guessing. A guessed city or date searches the wrong trip, spends quota, and returns confident nonsense.",
|
|
603
|
+
quotaErrorNote: "On QUOTA_EXCEEDED, stop: the monthly allowance is gone and retrying cannot help. On RATE_LIMIT_EXCEEDED, wait for the Retry-After interval and retry; that one is only a speed limit.",
|
|
604
|
+
searchNotBookNote: "Ktemia searches and compares. It does not book, hold, or pay for anything. Booking links in the results hand off to the provider's own site."
|
|
605
|
+
},
|
|
606
|
+
enums: {
|
|
607
|
+
cabin: ["economy", "premiumEconomy", "business", "first"],
|
|
608
|
+
alliance: ["oneworld", "skyteam", "starAlliance"],
|
|
609
|
+
sortOrder: ["asc", "desc"],
|
|
610
|
+
flightSortBy: ["bestValue", "price", "duration", "departure", "arrival"],
|
|
611
|
+
hotelSortBy: ["bestValue", "price", "rating", "stars", "distance"],
|
|
612
|
+
carSortBy: ["bestValue", "price", "rating", "distance"],
|
|
613
|
+
carClass: ["small", "medium", "large", "suv", "van", "pickup", "luxury", "convertible"],
|
|
614
|
+
transmission: ["automatic", "manual"],
|
|
615
|
+
priceMode: ["total", "perDay"],
|
|
616
|
+
locationType: ["city", "airport", "all"],
|
|
617
|
+
reviewSort: ["recent", "oldest", "highestScore", "lowestScore"],
|
|
618
|
+
travelerType: ["families", "couples", "solo", "friends", "business"],
|
|
619
|
+
reviewSource: ["booking", "agoda", "priceline"],
|
|
620
|
+
lookupKind: ["airport", "airline", "hotelLocation", "carLocation"],
|
|
621
|
+
vertical: ["flights", "hotels", "cars"]
|
|
622
|
+
},
|
|
623
|
+
limits: {
|
|
624
|
+
maxPassengersPerType: 9,
|
|
625
|
+
searchTokenTtlSeconds: 3600
|
|
626
|
+
},
|
|
627
|
+
tools: [
|
|
628
|
+
{
|
|
629
|
+
name: "ktemia_key_status",
|
|
630
|
+
title: "Check Ktemia plan and remaining quota",
|
|
631
|
+
description: "Report the plan, rate limits, and remaining monthly request quota for the configured API key. This is the only Ktemia call that is free: it does not count against the quota, and it keeps answering after the quota is spent, so it is how you diagnose a QUOTA_EXCEEDED error and find the reset date. Call it before a long run of searches to check the budget. The quota is shared across every key on an account, so adding a key does not add requests.",
|
|
632
|
+
annotations: {
|
|
633
|
+
readOnlyHint: true,
|
|
634
|
+
destructiveHint: false,
|
|
635
|
+
idempotentHint: true,
|
|
636
|
+
openWorldHint: false
|
|
637
|
+
},
|
|
638
|
+
params: {}
|
|
639
|
+
},
|
|
640
|
+
{
|
|
641
|
+
name: "ktemia_lookup",
|
|
642
|
+
title: "Look up airport, airline, or location codes",
|
|
643
|
+
description: "Resolve a plain-language place or airline name into the codes the search tools need. Use kind='airport' for flight origins and destinations (returns IATA airport codes such as LHR, and city codes such as LON that cover every airport in a metro area), kind='airline' for two-letter carrier codes, kind='hotelLocation' for a hotel search location id, and kind='carLocation' for a rental pickup location id. Flight searches take the code field; hotel and car searches take the locationId field, which is a numeric string and not a city name. Resolve an ambiguous name here instead of guessing a code.",
|
|
644
|
+
annotations: {
|
|
645
|
+
readOnlyHint: true,
|
|
646
|
+
destructiveHint: false,
|
|
647
|
+
idempotentHint: false,
|
|
648
|
+
openWorldHint: true
|
|
649
|
+
},
|
|
650
|
+
params: {
|
|
651
|
+
kind: {
|
|
652
|
+
description: "What to resolve. Flight searches need 'airport'; hotel and car searches need 'hotelLocation' and 'carLocation'.",
|
|
653
|
+
enum: "lookupKind",
|
|
654
|
+
required: true
|
|
655
|
+
},
|
|
656
|
+
query: {
|
|
657
|
+
description: "Place, airport, or airline name, for example 'London' or 'Delta'.",
|
|
658
|
+
required: true
|
|
659
|
+
},
|
|
660
|
+
type: {
|
|
661
|
+
description: "For kind='carLocation' only: narrow to city centres or airports.",
|
|
662
|
+
enum: "locationType",
|
|
663
|
+
default: "city"
|
|
664
|
+
},
|
|
665
|
+
country: {
|
|
666
|
+
description: "Two-letter market code (ISO 3166-1 alpha-2) biasing results, for example 'GB'."
|
|
667
|
+
},
|
|
668
|
+
locale: {
|
|
669
|
+
description: "Language for returned names.",
|
|
670
|
+
default: "en"
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
name: "ktemia_search_flights",
|
|
676
|
+
title: "Search flights",
|
|
677
|
+
description: "Search and compare flights across providers. Call with trip details to start a search and read the first page; call again with only nextToken to read the next page. A trip is either one-way or return (origin, destination, departureDate, optional returnDate) or multi-city (legs). The two forms are mutually exclusive. Origins and destinations are IATA airport or city codes - use ktemia_lookup to resolve a place name first.",
|
|
678
|
+
annotations: {
|
|
679
|
+
readOnlyHint: true,
|
|
680
|
+
destructiveHint: false,
|
|
681
|
+
idempotentHint: false,
|
|
682
|
+
openWorldHint: true
|
|
683
|
+
},
|
|
684
|
+
params: {
|
|
685
|
+
nextToken: {
|
|
686
|
+
description: "Read the next page of an existing search. When set, every other parameter is ignored."
|
|
687
|
+
},
|
|
688
|
+
origin: {
|
|
689
|
+
description: "Departure IATA airport or city code, for example 'LHR' or 'LON'."
|
|
690
|
+
},
|
|
691
|
+
destination: {
|
|
692
|
+
description: "Arrival IATA airport or city code, for example 'JFK' or 'NYC'."
|
|
693
|
+
},
|
|
694
|
+
departureDate: {
|
|
695
|
+
description: "Outbound date as YYYY-MM-DD. Must not be in the past."
|
|
696
|
+
},
|
|
697
|
+
returnDate: {
|
|
698
|
+
description: "Return date as YYYY-MM-DD for a round trip. Omit for one-way."
|
|
699
|
+
},
|
|
700
|
+
legs: {
|
|
701
|
+
description: "Multi-city itinerary as a list of { origin, destination, date }, in travel order. Mutually exclusive with origin/destination/departureDate."
|
|
702
|
+
},
|
|
703
|
+
cabin: {
|
|
704
|
+
description: "Cabin class to price.",
|
|
705
|
+
enum: "cabin",
|
|
706
|
+
default: "economy"
|
|
707
|
+
},
|
|
708
|
+
passengers: {
|
|
709
|
+
description: "Traveller counts: adults (12 and over), children (2-11), infantsOnLap (under 2, on an adult's lap). Defaults to one adult. Count seniors, students and youths as adults, and an infant in their own seat as a child. At most 9 in total, and no more lap infants than adults."
|
|
710
|
+
},
|
|
711
|
+
maxStops: {
|
|
712
|
+
description: "Maximum stops per leg. 0 is non-stop only."
|
|
713
|
+
},
|
|
714
|
+
airlines: {
|
|
715
|
+
description: "Restrict to these two-letter IATA airline codes, from ktemia_lookup with kind='airline' or availableFilters on a results page."
|
|
716
|
+
},
|
|
717
|
+
alliances: {
|
|
718
|
+
description: "Restrict to these airline alliances.",
|
|
719
|
+
enum: "alliance"
|
|
720
|
+
},
|
|
721
|
+
maxPrice: {
|
|
722
|
+
description: "Drop results above this total price."
|
|
723
|
+
},
|
|
724
|
+
sortBy: {
|
|
725
|
+
description: "Result ordering.",
|
|
726
|
+
enum: "flightSortBy",
|
|
727
|
+
default: "bestValue"
|
|
728
|
+
},
|
|
729
|
+
sortOrder: {
|
|
730
|
+
description: "Sort direction.",
|
|
731
|
+
enum: "sortOrder"
|
|
732
|
+
},
|
|
733
|
+
country: {
|
|
734
|
+
description: "Two-letter market code to price in, for example 'US'. It selects the market, and prices come back in that country's currency. There is no currency parameter."
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
},
|
|
738
|
+
{
|
|
739
|
+
name: "ktemia_search_hotels",
|
|
740
|
+
title: "Search hotels and stays",
|
|
741
|
+
description: "Search and compare hotels and other stays across providers. Call with stay details to start a search and read the first page; call again with only nextToken for the next page. The location must be an id from ktemia_lookup with kind='hotelLocation' - a free-text city name is not accepted.",
|
|
742
|
+
annotations: {
|
|
743
|
+
readOnlyHint: true,
|
|
744
|
+
destructiveHint: false,
|
|
745
|
+
idempotentHint: false,
|
|
746
|
+
openWorldHint: true
|
|
747
|
+
},
|
|
748
|
+
params: {
|
|
749
|
+
nextToken: {
|
|
750
|
+
description: "Read the next page of an existing search. When set, every other parameter is ignored."
|
|
751
|
+
},
|
|
752
|
+
location: {
|
|
753
|
+
description: "Location id from ktemia_lookup with kind='hotelLocation' - the locationId field of a result, for example '29230'."
|
|
754
|
+
},
|
|
755
|
+
checkin: {
|
|
756
|
+
description: "Check-in date as YYYY-MM-DD."
|
|
757
|
+
},
|
|
758
|
+
checkout: {
|
|
759
|
+
description: "Check-out date as YYYY-MM-DD. Must be after checkin."
|
|
760
|
+
},
|
|
761
|
+
adults: {
|
|
762
|
+
description: "Number of adults.",
|
|
763
|
+
default: 2
|
|
764
|
+
},
|
|
765
|
+
rooms: {
|
|
766
|
+
description: "Number of rooms.",
|
|
767
|
+
default: 1
|
|
768
|
+
},
|
|
769
|
+
childAges: {
|
|
770
|
+
description: "Ages of children sharing the room, as a list of years."
|
|
771
|
+
},
|
|
772
|
+
minStars: {
|
|
773
|
+
description: "Minimum star rating, 1 to 5."
|
|
774
|
+
},
|
|
775
|
+
minRating: {
|
|
776
|
+
description: "Minimum guest review score."
|
|
777
|
+
},
|
|
778
|
+
maxPrice: {
|
|
779
|
+
description: "Drop results above this price."
|
|
780
|
+
},
|
|
781
|
+
freeCancellation: {
|
|
782
|
+
description: "Only rates that can be cancelled free of charge.",
|
|
783
|
+
default: false
|
|
784
|
+
},
|
|
785
|
+
amenities: {
|
|
786
|
+
description: "Required amenities, for example 'wifi' or 'pool'."
|
|
787
|
+
},
|
|
788
|
+
providers: {
|
|
789
|
+
description: "Restrict to these booking providers, using an id from availableFilters.bookingSites.options on a results page, for example 'Booking.com'. Guessed names match nothing."
|
|
790
|
+
},
|
|
791
|
+
sortBy: {
|
|
792
|
+
description: "Result ordering.",
|
|
793
|
+
enum: "hotelSortBy",
|
|
794
|
+
default: "bestValue"
|
|
795
|
+
},
|
|
796
|
+
sortOrder: {
|
|
797
|
+
description: "Sort direction.",
|
|
798
|
+
enum: "sortOrder"
|
|
799
|
+
},
|
|
800
|
+
country: {
|
|
801
|
+
description: "Two-letter market code to price in, for example 'US'. It selects the market, and prices come back in that country's currency. There is no currency parameter."
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
name: "ktemia_search_cars",
|
|
807
|
+
title: "Search rental cars",
|
|
808
|
+
description: "Search and compare rental cars across agencies. Call with rental details to start a search and read the first page; call again with only nextToken for the next page. The pickup location must be an id from ktemia_lookup with kind='carLocation'. Omit dropoffLocation for a same-location return.",
|
|
809
|
+
annotations: {
|
|
810
|
+
readOnlyHint: true,
|
|
811
|
+
destructiveHint: false,
|
|
812
|
+
idempotentHint: false,
|
|
813
|
+
openWorldHint: true
|
|
814
|
+
},
|
|
815
|
+
params: {
|
|
816
|
+
nextToken: {
|
|
817
|
+
description: "Read the next page of an existing search. When set, every other parameter is ignored."
|
|
818
|
+
},
|
|
819
|
+
pickupLocation: {
|
|
820
|
+
description: "Pickup location id from ktemia_lookup with kind='carLocation' - the locationId field of a result."
|
|
821
|
+
},
|
|
822
|
+
dropoffLocation: {
|
|
823
|
+
description: "Drop-off location id. Omit to return the car where it was collected."
|
|
824
|
+
},
|
|
825
|
+
pickupDate: {
|
|
826
|
+
description: "Pickup date as YYYY-MM-DD."
|
|
827
|
+
},
|
|
828
|
+
dropoffDate: {
|
|
829
|
+
description: "Drop-off date as YYYY-MM-DD. Must be on or after pickupDate."
|
|
830
|
+
},
|
|
831
|
+
pickupTime: {
|
|
832
|
+
description: "Pickup time as HH:MM, 24-hour.",
|
|
833
|
+
default: "12:00"
|
|
834
|
+
},
|
|
835
|
+
dropoffTime: {
|
|
836
|
+
description: "Drop-off time as HH:MM, 24-hour.",
|
|
837
|
+
default: "12:00"
|
|
838
|
+
},
|
|
839
|
+
driverAge: {
|
|
840
|
+
description: "Driver age. Under 25 often carries a young-driver surcharge."
|
|
841
|
+
},
|
|
842
|
+
carClass: {
|
|
843
|
+
description: "Keep only this vehicle class. Omit to allow any class.",
|
|
844
|
+
enum: "carClass"
|
|
845
|
+
},
|
|
846
|
+
transmission: {
|
|
847
|
+
description: "Gearbox type. Relevant outside North America, where manual is common.",
|
|
848
|
+
enum: "transmission"
|
|
849
|
+
},
|
|
850
|
+
maxPrice: {
|
|
851
|
+
description: "Drop results above this price."
|
|
852
|
+
},
|
|
853
|
+
providers: {
|
|
854
|
+
description: "Restrict to these booking providers, using an id from availableFilters.bookingSites on a results page, for example 'Booking.com'. Guessed names match nothing."
|
|
855
|
+
},
|
|
856
|
+
agencies: {
|
|
857
|
+
description: "Restrict to these rental agencies, using an id from availableFilters.agency on a results page - the lowercase id such as 'hertz', not the display label such as 'Hertz'."
|
|
858
|
+
},
|
|
859
|
+
sortBy: {
|
|
860
|
+
description: "Result ordering.",
|
|
861
|
+
enum: "carSortBy",
|
|
862
|
+
default: "bestValue"
|
|
863
|
+
},
|
|
864
|
+
sortOrder: {
|
|
865
|
+
description: "Sort direction.",
|
|
866
|
+
enum: "sortOrder"
|
|
867
|
+
},
|
|
868
|
+
priceMode: {
|
|
869
|
+
description: "What each price shows: the rental total, or the average daily rate. Every option also carries perDay either way. maxPrice always caps the total.",
|
|
870
|
+
enum: "priceMode",
|
|
871
|
+
default: "total"
|
|
872
|
+
},
|
|
873
|
+
country: {
|
|
874
|
+
description: "Two-letter market code to price in, for example 'US'. It selects the market, and prices come back in that country's currency. There is no currency parameter."
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
name: "ktemia_get_details",
|
|
880
|
+
title: "Get full prices and booking links for one result",
|
|
881
|
+
description: "Expand a single search result into every available price and booking link. Pass the vertical, the token from the search that produced the result, and that result's id. Use this when the user has chosen a candidate and wants the real price or a way to book, since search pages carry only the leading offers.",
|
|
882
|
+
annotations: {
|
|
883
|
+
readOnlyHint: true,
|
|
884
|
+
destructiveHint: false,
|
|
885
|
+
idempotentHint: false,
|
|
886
|
+
openWorldHint: true
|
|
887
|
+
},
|
|
888
|
+
params: {
|
|
889
|
+
vertical: {
|
|
890
|
+
description: "Which search the result came from.",
|
|
891
|
+
enum: "vertical",
|
|
892
|
+
required: true
|
|
893
|
+
},
|
|
894
|
+
token: {
|
|
895
|
+
description: "The searchToken or nextToken of the page the result appeared on.",
|
|
896
|
+
required: true
|
|
897
|
+
},
|
|
898
|
+
resultId: {
|
|
899
|
+
description: "The id of the chosen result, taken from the search response.",
|
|
900
|
+
required: true
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
},
|
|
904
|
+
{
|
|
905
|
+
name: "ktemia_get_hotel_reviews",
|
|
906
|
+
title: "Get guest reviews for a hotel",
|
|
907
|
+
description: "Read guest reviews for one hotel, with optional filters and paging. Use it to answer qualitative questions - whether the breakfast is worth it, how the rooms sound at night - that a price comparison cannot settle. Pages are numbered here, unlike the token-based search tools.",
|
|
908
|
+
annotations: {
|
|
909
|
+
readOnlyHint: true,
|
|
910
|
+
destructiveHint: false,
|
|
911
|
+
idempotentHint: false,
|
|
912
|
+
openWorldHint: true
|
|
913
|
+
},
|
|
914
|
+
params: {
|
|
915
|
+
hotelId: {
|
|
916
|
+
description: "Hotel id from a hotel search result or its details.",
|
|
917
|
+
required: true
|
|
918
|
+
},
|
|
919
|
+
sortBy: {
|
|
920
|
+
description: "Review ordering.",
|
|
921
|
+
enum: "reviewSort",
|
|
922
|
+
default: "recent"
|
|
923
|
+
},
|
|
924
|
+
travelerTypes: {
|
|
925
|
+
description: "Keep only reviews from these kinds of traveller. Send one or more.",
|
|
926
|
+
enum: "travelerType"
|
|
927
|
+
},
|
|
928
|
+
months: {
|
|
929
|
+
description: "Keep only stays in these calendar months, 1 for January through 12 for December - for example [6, 7, 8] for summer stays. This is the month of the stay in any year, not a recent window; for the newest reviews, use sortBy='recent' instead."
|
|
930
|
+
},
|
|
931
|
+
sources: {
|
|
932
|
+
description: "Read reviews from only these sites. Omit to read all three.",
|
|
933
|
+
enum: "reviewSource"
|
|
934
|
+
},
|
|
935
|
+
search: {
|
|
936
|
+
description: "Only reviews containing this phrase, for example 'air conditioning'."
|
|
937
|
+
},
|
|
938
|
+
page: {
|
|
939
|
+
description: "Page number, starting at 1.",
|
|
940
|
+
default: 1
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
]
|
|
945
|
+
};
|
|
946
|
+
|
|
947
|
+
// src/spec.ts
|
|
948
|
+
var spec = tools_default;
|
|
949
|
+
var TOOL_NAMES = spec.tools.map((t) => t.name);
|
|
950
|
+
function toolSpec(name) {
|
|
951
|
+
const found = spec.tools.find((t) => t.name === name);
|
|
952
|
+
if (!found) throw new Error(`No Ktemia tool named "${name}" in the tool spec.`);
|
|
953
|
+
return found;
|
|
954
|
+
}
|
|
955
|
+
function toolDescription(name, notes = []) {
|
|
956
|
+
return [toolSpec(name).description, ...notes.map((n) => sharedNote(n))].join(" ");
|
|
957
|
+
}
|
|
958
|
+
function paramDescription(name, param) {
|
|
959
|
+
const found = toolSpec(name).params[param];
|
|
960
|
+
if (!found) throw new Error(`Ktemia tool "${name}" has no parameter "${param}".`);
|
|
961
|
+
return found.description;
|
|
962
|
+
}
|
|
963
|
+
function enumValues(name) {
|
|
964
|
+
const found = spec.enums[name];
|
|
965
|
+
if (!found || found.length === 0) throw new Error(`No Ktemia enum named "${name}".`);
|
|
966
|
+
return found;
|
|
967
|
+
}
|
|
968
|
+
function sharedNote(name) {
|
|
969
|
+
const found = spec.shared[name];
|
|
970
|
+
if (!found) throw new Error(`No shared note named "${name}" in the tool spec.`);
|
|
971
|
+
return found;
|
|
972
|
+
}
|
|
973
|
+
export {
|
|
974
|
+
API_KEYS_URL,
|
|
975
|
+
DEFAULT_BASE_URL,
|
|
976
|
+
EMPTY_RESULT_CODES,
|
|
977
|
+
HotelsResource,
|
|
978
|
+
Ktemia,
|
|
979
|
+
KtemiaError,
|
|
980
|
+
KtemiaValidationError,
|
|
981
|
+
MAX_LEGS,
|
|
982
|
+
MAX_NIGHTS,
|
|
983
|
+
MAX_PASSENGERS,
|
|
984
|
+
MIN_LEGS,
|
|
985
|
+
TOOL_NAMES,
|
|
986
|
+
VERSION,
|
|
987
|
+
VerticalResource,
|
|
988
|
+
checkCarSearch,
|
|
989
|
+
checkDate,
|
|
990
|
+
checkFlightSearch,
|
|
991
|
+
checkHotelSearch,
|
|
992
|
+
checkPlace,
|
|
993
|
+
enumValues,
|
|
994
|
+
isKtemiaError,
|
|
995
|
+
paramDescription,
|
|
996
|
+
parseRetryAfter,
|
|
997
|
+
sharedNote,
|
|
998
|
+
toolDescription,
|
|
999
|
+
toolSpec
|
|
1000
|
+
};
|
|
1001
|
+
//# sourceMappingURL=index.js.map
|