@curless/hotel-storefront 0.91.0 → 0.93.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/README.md +5 -2
- package/dist/account/index.js +1 -1
- package/dist/account/index.js.map +1 -1
- package/dist/backend.d.ts +4 -4
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +2 -2
- package/dist/card.generated.d.ts +1 -1
- package/dist/card.generated.js +2 -2
- package/dist/card.generated.js.map +1 -1
- package/dist/choices.d.ts.map +1 -1
- package/dist/choices.js +1 -1
- package/dist/choices.js.map +1 -1
- package/dist/cidr.d.ts +4 -36
- package/dist/cidr.d.ts.map +1 -1
- package/dist/cidr.js +10 -113
- package/dist/cidr.js.map +1 -1
- package/dist/config.d.ts +14 -14
- package/dist/config.d.ts.map +1 -1
- package/dist/huazhu/backend.d.ts +3 -8
- package/dist/huazhu/backend.d.ts.map +1 -1
- package/dist/huazhu/backend.js +35 -68
- package/dist/huazhu/backend.js.map +1 -1
- package/dist/huazhu/booking-list.d.ts +56 -0
- package/dist/huazhu/booking-list.d.ts.map +1 -0
- package/dist/huazhu/booking-list.js +87 -0
- package/dist/huazhu/booking-list.js.map +1 -0
- package/dist/huazhu/make.d.ts.map +1 -1
- package/dist/huazhu/make.js +7 -35
- package/dist/huazhu/make.js.map +1 -1
- package/dist/huazhu/order-words.d.ts +9 -0
- package/dist/huazhu/order-words.d.ts.map +1 -0
- package/dist/huazhu/order-words.js +58 -0
- package/dist/huazhu/order-words.js.map +1 -0
- package/dist/huazhu/usage-row.d.ts +5 -0
- package/dist/huazhu/usage-row.d.ts.map +1 -0
- package/dist/huazhu/usage-row.js +23 -0
- package/dist/huazhu/usage-row.js.map +1 -0
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/legal.d.ts.map +1 -1
- package/dist/legal.js +9 -11
- package/dist/legal.js.map +1 -1
- package/dist/not-booked.d.ts +8 -0
- package/dist/not-booked.d.ts.map +1 -0
- package/dist/not-booked.js +8 -0
- package/dist/not-booked.js.map +1 -0
- package/dist/openai-conversation.d.ts +50 -0
- package/dist/openai-conversation.d.ts.map +1 -0
- package/dist/openai-conversation.js +83 -0
- package/dist/openai-conversation.js.map +1 -0
- package/dist/out-of-list.d.ts +74 -0
- package/dist/out-of-list.d.ts.map +1 -0
- package/dist/out-of-list.js +150 -0
- package/dist/out-of-list.js.map +1 -0
- package/dist/present.d.ts +2 -2
- package/dist/present.d.ts.map +1 -1
- package/dist/ranges-check-cli.js +19 -7
- package/dist/ranges-check-cli.js.map +1 -1
- package/dist/ranges-check.d.ts +19 -15
- package/dist/ranges-check.d.ts.map +1 -1
- package/dist/ranges-check.js +57 -109
- package/dist/ranges-check.js.map +1 -1
- package/dist/server.d.ts +14 -18
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +102 -161
- package/dist/server.js.map +1 -1
- package/dist/source-allowlist.d.ts +4 -10
- package/dist/source-allowlist.d.ts.map +1 -1
- package/dist/source-allowlist.js +28 -45
- package/dist/source-allowlist.js.map +1 -1
- package/dist/source-ranges.d.ts.map +1 -1
- package/dist/source-ranges.js +23 -308
- package/dist/source-ranges.js.map +1 -1
- package/dist/source-refusal-log.d.ts +13 -0
- package/dist/source-refusal-log.d.ts.map +1 -0
- package/dist/source-refusal-log.js +50 -0
- package/dist/source-refusal-log.js.map +1 -0
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +2 -2
- package/dist/surface.js.map +1 -1
- package/dist/tools/args.d.ts.map +1 -1
- package/dist/tools/booking-answer.d.ts.map +1 -1
- package/dist/tools/booking-answer.js +9 -1
- package/dist/tools/booking-answer.js.map +1 -1
- package/dist/tools/cancel-facts.d.ts.map +1 -1
- package/dist/tools/capability-adjust.d.ts +1 -1
- package/dist/tools/capability-adjust.d.ts.map +1 -1
- package/dist/tools/capability-adjust.js +1 -16
- package/dist/tools/capability-adjust.js.map +1 -1
- package/dist/tools/get-hotel.d.ts +5 -0
- package/dist/tools/get-hotel.d.ts.map +1 -1
- package/dist/tools/get-hotel.js +19 -1
- package/dist/tools/get-hotel.js.map +1 -1
- package/dist/tools/hotel-bookable.d.ts +22 -0
- package/dist/tools/hotel-bookable.d.ts.map +1 -0
- package/dist/tools/hotel-bookable.js +49 -0
- package/dist/tools/hotel-bookable.js.map +1 -0
- package/dist/tools/hotel-choices.js +4 -4
- package/dist/tools/hotel-choices.js.map +1 -1
- package/dist/tools/list-hotels-ask.d.ts.map +1 -1
- package/dist/tools/list-hotels-page.d.ts.map +1 -1
- package/dist/tools/list-hotels-page.js +13 -2
- package/dist/tools/list-hotels-page.js.map +1 -1
- package/dist/tools/output-schemas.d.ts +4 -3
- package/dist/tools/output-schemas.d.ts.map +1 -1
- package/dist/tools/output-schemas.js +4 -3
- package/dist/tools/output-schemas.js.map +1 -1
- package/dist/tools/paid-lines.d.ts.map +1 -1
- package/dist/tools/paid-lines.js +1 -1
- package/dist/tools/paid-lines.js.map +1 -1
- package/dist/tools/payment-words.d.ts.map +1 -1
- package/dist/tools/put-room-line.d.ts.map +1 -1
- package/dist/tools/put-room-line.js +27 -1
- package/dist/tools/put-room-line.js.map +1 -1
- package/dist/tools/quote-card.d.ts.map +1 -1
- package/dist/tools/request-words.d.ts +1 -1
- package/dist/tools/request-words.d.ts.map +1 -1
- package/dist/tools/request-words.js +2 -2
- package/dist/tools/request-words.js.map +1 -1
- package/dist/tools/room-choices.js +4 -4
- package/dist/tools/room-choices.js.map +1 -1
- package/dist/tools/tool-defs-browse.js +1 -1
- package/dist/tools/tool-defs-browse.js.map +1 -1
- package/dist/tools/tool-set.js +1 -1
- package/dist/tools/tool-set.js.map +1 -1
- package/dist/types.d.ts +9 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/usage/boot.d.ts +3 -0
- package/dist/usage/boot.d.ts.map +1 -1
- package/dist/usage/boot.js +2 -1
- package/dist/usage/boot.js.map +1 -1
- package/dist/usage/order-words.d.ts +10 -0
- package/dist/usage/order-words.d.ts.map +1 -0
- package/dist/usage/order-words.js +2 -0
- package/dist/usage/order-words.js.map +1 -0
- package/dist/usage/platform.d.ts +7 -1
- package/dist/usage/platform.d.ts.map +1 -1
- package/dist/usage/platform.js +6 -2
- package/dist/usage/platform.js.map +1 -1
- package/dist/usage/recorder.d.ts +10 -0
- package/dist/usage/recorder.d.ts.map +1 -1
- package/dist/usage/recorder.js +39 -1
- package/dist/usage/recorder.js.map +1 -1
- package/package.json +3 -2
package/dist/server.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash, createHmac, randomBytes, randomUUID, timingSafeEqual } from
|
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { BRAND_FONTS, BRAND_FONTS_VERSION, familiesOf, fontAsset, fontHeaders, isBrandFont, weightsOf, } from '@curless/brand-fonts';
|
|
5
|
+
import { createPlatformRanges } from '@curless/platform-ranges';
|
|
5
6
|
import { Hono } from 'hono';
|
|
6
7
|
import { bodyLimit } from 'hono/body-limit';
|
|
7
8
|
import { SIGN_IN_META_KEY, addressKey, makeAccount } from './account/index.js';
|
|
@@ -17,6 +18,8 @@ import { checkLegal, docsPage, privacyPage, supportPage, termsPage, } from './le
|
|
|
17
18
|
import { Misses, WindowCounter } from './limits.js';
|
|
18
19
|
import { MemberStore } from './members.js';
|
|
19
20
|
import { inFullCurrency } from './money.js';
|
|
21
|
+
import { OPENAI_KEY_PREFIX, makeOpenAiConversation } from './openai-conversation.js';
|
|
22
|
+
import { OutOfList, cardSourceOf, cardSourcesMode } from './out-of-list.js';
|
|
20
23
|
import { paidAnswer } from './paid.js';
|
|
21
24
|
import { PICTURES_PATH, PictureStore, picturesAs } from './pictures.js';
|
|
22
25
|
import { Sessions, cardSupport } from './sessions.js';
|
|
@@ -29,7 +32,6 @@ import { MEMBER_SIGN_IN_META_KEY, TERMS_META_KEY, agreeToTerms, bookingRefusal,
|
|
|
29
32
|
import { ID_TTL_MS, LIVE_MS, SAME_NETWORK_MS, SignInClaims, TAKE_OVER_MS, TripIds, networkOf, prefixWords, } from './trip-ids.js';
|
|
30
33
|
import { TripStore, tripKey } from './trip.js';
|
|
31
34
|
import { startUsage } from './usage/boot.js';
|
|
32
|
-
import { OPENAI, rangesOf } from './usage/platform.js';
|
|
33
35
|
import { aBrandOf, checkDemoData, keyBrandOf, resolveBrand, upFirst, } from './vocab.js';
|
|
34
36
|
// The connector itself: one config in, one HTTP app out.
|
|
35
37
|
//
|
|
@@ -59,7 +61,7 @@ export const INITIALIZE_PER_MINUTE = 300;
|
|
|
59
61
|
* number. Found by reading the boot banner of a container that had just been
|
|
60
62
|
* deployed (2026-09-22): seventeen tools listed, and "0.7.0" above them.
|
|
61
63
|
*/
|
|
62
|
-
export const VERSION = '0.
|
|
64
|
+
export const VERSION = '0.93.0';
|
|
63
65
|
/**
|
|
64
66
|
* The card's resource URI.
|
|
65
67
|
*
|
|
@@ -341,6 +343,23 @@ export const buildServer = (opts) => {
|
|
|
341
343
|
const keyBrand = keyBrandOf(brand.vocab);
|
|
342
344
|
const now = opts.now ?? (() => Date.now());
|
|
343
345
|
const state = new StateDir(stateDirOf(config, opts));
|
|
346
|
+
// ⚠️ OPENAI'S AND ANTHROPIC'S RANGES, AS THEY ARE NOW (@curless/platform-ranges, started by
|
|
347
|
+
// index.ts): every check that asks "is this address OpenAI's / Anthropic's" asks this list.
|
|
348
|
+
const platformRanges = opts.platformRanges ??
|
|
349
|
+
createPlatformRanges({
|
|
350
|
+
...(state.dir ? { stateDir: join(state.dir, 'platform-ranges') } : {}),
|
|
351
|
+
...(opts.rangesLog ? { log: opts.rangesLog } : {}),
|
|
352
|
+
});
|
|
353
|
+
/** Calls from outside those lists - counted and logged, see out-of-list.ts. */
|
|
354
|
+
const outOfList = new OutOfList(now, opts.rangesLog, () => platformRanges.running ? platformRanges.refresh() : undefined);
|
|
355
|
+
const fromOpenAi = (address) => platformRanges.has('openai', address);
|
|
356
|
+
/** One call from outside the lists: counted and logged - the network only, never the address. */
|
|
357
|
+
const noteOutOfList = (c, check, outcome, about) => outOfList.noteRequest({
|
|
358
|
+
address: sourceOf(c),
|
|
359
|
+
userAgent: c.req.header('user-agent'),
|
|
360
|
+
openaiSession: c.req.header('x-openai-session') !== undefined,
|
|
361
|
+
...about,
|
|
362
|
+
}, check, outcome, (e) => sourceFault('noting a call from outside the lists', e, 'not counted'));
|
|
344
363
|
/** Faults in the allowlist itself - see the /mcp middleware. Counted; logged once a minute at most, by kind, never with the request. */
|
|
345
364
|
let sourceFaults = 0;
|
|
346
365
|
let sourceFaultLoggedAt = Number.NEGATIVE_INFINITY;
|
|
@@ -356,6 +375,7 @@ export const buildServer = (opts) => {
|
|
|
356
375
|
const SOURCE_FILE = 'source-shadow.json';
|
|
357
376
|
const sources = makeSourceAllowlist(config.sourceAllowlist, opts.env ?? process.env, {
|
|
358
377
|
now,
|
|
378
|
+
live: platformRanges,
|
|
359
379
|
...(opts.hostOf ? { hostOf: opts.hostOf } : {}),
|
|
360
380
|
onFault: (doing, e) => sourceFault(doing, e, 'its line not written'),
|
|
361
381
|
// The shadow's samples survive a deploy (总线程 11-12). A write that fails
|
|
@@ -427,62 +447,16 @@ export const buildServer = (opts) => {
|
|
|
427
447
|
againFile?.changed();
|
|
428
448
|
return key;
|
|
429
449
|
})();
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
* trusted_proxies, so whatever the caller sent there is replaced), or the connection's
|
|
441
|
-
* own address where that is public. NEVER `X-Caller-Forwarded-For` - Caddy's verbatim
|
|
442
|
-
* copy of the caller's own header - or any other header the caller writes: the
|
|
443
|
-
* header's value is not a secret (OpenAI sends it to the connectors a conversation
|
|
444
|
-
* uses; whether it differs per connector is not documented), the address it is
|
|
445
|
-
* called from is what nobody else has;
|
|
446
|
-
* - the value has the shape of ChatGPT's (`OPENAI_SESSION_SHAPE`);
|
|
447
|
-
* - the client did not say it draws no card: a client in words carries its
|
|
448
|
-
* conversation by its id, in words (`Sessions.bind`), and that is left as it is.
|
|
449
|
-
* The key is `oai:` and 32 hex characters of an HMAC of the value - never the value
|
|
450
|
-
* itself, in a key, a log line or the state directory - under a key of its own, made
|
|
451
|
-
* from `againKey` with a label: kept in the state directory, so a restart still finds
|
|
452
|
-
* the conversation; unknown to anyone who reads the header elsewhere. Then `tripKey`,
|
|
453
|
-
* as any conversation's.
|
|
454
|
-
* `HOTEL_OPENAI_CONVERSATION=off` turns it off: every call keyed by its connection again.
|
|
455
|
-
*/
|
|
456
|
-
const openaiOn = (opts.env ?? process.env).HOTEL_OPENAI_CONVERSATION !== 'off';
|
|
457
|
-
const openaiMac = createHmac('sha256', againKey).update('hotel-openai-conversation-v1').digest();
|
|
458
|
-
/** Headers not taken since the line that last said so - counts only, never a value or an address. */
|
|
459
|
-
const openaiSkipped = { outside: 0, shape: 0, loggedAt: Number.NEGATIVE_INFINITY };
|
|
460
|
-
const openaiConversation = (c) => {
|
|
461
|
-
if (!openaiOn)
|
|
462
|
-
return undefined;
|
|
463
|
-
const raw = c.req.header('x-openai-session');
|
|
464
|
-
if (raw === undefined)
|
|
465
|
-
return undefined;
|
|
466
|
-
const why = !OPENAI.has(sourceOf(c))
|
|
467
|
-
? 'outside'
|
|
468
|
-
: !OPENAI_SESSION_SHAPE.test(raw)
|
|
469
|
-
? 'shape'
|
|
470
|
-
: undefined;
|
|
471
|
-
if (why) {
|
|
472
|
-
// So a list of OpenAI's ranges that has fallen behind shows up as lines.
|
|
473
|
-
openaiSkipped[why] += 1;
|
|
474
|
-
const t = now();
|
|
475
|
-
if (t - openaiSkipped.loggedAt >= OPENAI_SKIPPED_LOG_MS) {
|
|
476
|
-
console.log(`[mcp] x-openai-session not taken: outside OpenAI's ranges=${openaiSkipped.outside} not its shape=${openaiSkipped.shape}`);
|
|
477
|
-
openaiSkipped.outside = 0;
|
|
478
|
-
openaiSkipped.shape = 0;
|
|
479
|
-
openaiSkipped.loggedAt = t;
|
|
480
|
-
}
|
|
481
|
-
return undefined;
|
|
482
|
-
}
|
|
483
|
-
const mac = createHmac('sha256', openaiMac).update(raw).digest('hex').slice(0, 32);
|
|
484
|
-
return tripKey(`${OPENAI_KEY_PREFIX}${mac}`, keyBrand);
|
|
485
|
-
};
|
|
450
|
+
// ChatGPT's conversation is its `X-OpenAI-Session` header, from OpenAI's own addresses only
|
|
451
|
+
// (openai-conversation.ts: why, and what is not taken). `HOTEL_OPENAI_CONVERSATION=off` turns it off.
|
|
452
|
+
const takeOpenAiConversation = makeOpenAiConversation({
|
|
453
|
+
enabled: (opts.env ?? process.env).HOTEL_OPENAI_CONVERSATION !== 'off',
|
|
454
|
+
againKey,
|
|
455
|
+
keyBrand,
|
|
456
|
+
now,
|
|
457
|
+
fromOpenAi,
|
|
458
|
+
});
|
|
459
|
+
const openaiConversation = (c, about) => takeOpenAiConversation(c.req.header('x-openai-session'), sourceOf(c), () => noteOutOfList(c, 'openai-session', 'refused', about));
|
|
486
460
|
const misses = new Misses(now);
|
|
487
461
|
// ⚠️ THE "refused: no session id" LINE, ONE A MINUTE A METHOD (2026-11-12). Claude
|
|
488
462
|
// (`Claude-User`) probes `server/discover` - the 2026-07-28 revision's
|
|
@@ -652,6 +626,7 @@ export const buildServer = (opts) => {
|
|
|
652
626
|
enabled: config.usage?.enabled === true,
|
|
653
627
|
env: opts.env ?? process.env,
|
|
654
628
|
stateDir: state.dir,
|
|
629
|
+
ranges: platformRanges,
|
|
655
630
|
roleOf: (tool) => usageRoles.get(tool) ?? 'other',
|
|
656
631
|
now,
|
|
657
632
|
quiet: opts.background === false,
|
|
@@ -694,7 +669,7 @@ export const buildServer = (opts) => {
|
|
|
694
669
|
const renewOn = (opts.env ?? process.env).HOTEL_TRIP_RENEW !== 'off';
|
|
695
670
|
const claims = new SignInClaims(now);
|
|
696
671
|
/** `HOTEL_CARD_SOURCES=off`: a card's call from anywhere, as before 0.75.1 (tools/call). */
|
|
697
|
-
const
|
|
672
|
+
const cardSources = cardSourcesMode((opts.env ?? process.env).HOTEL_CARD_SOURCES);
|
|
698
673
|
/**
|
|
699
674
|
* How soon after the holding connection's own last call a reconnect is refused (0.84.2, P1-8 ①,
|
|
700
675
|
* `LIVE_MS`): `HOTEL_RECONNECT_LIVE_SECONDS` sets it in seconds (0 turns it off - as before 0.84.2,
|
|
@@ -1063,20 +1038,9 @@ export const buildServer = (opts) => {
|
|
|
1063
1038
|
*/
|
|
1064
1039
|
const bookingUsage = (b) => {
|
|
1065
1040
|
const own = typeof b?.id === 'string' ? backend.usageOf?.(b.id) : undefined;
|
|
1041
|
+
// The group's own words (hn, city, room, ...) come along with its ids.
|
|
1066
1042
|
if (own)
|
|
1067
|
-
return {
|
|
1068
|
-
order: own.order,
|
|
1069
|
-
code: own.code,
|
|
1070
|
-
hotel: own.hotelId,
|
|
1071
|
-
checkIn: own.checkIn,
|
|
1072
|
-
checkOut: own.checkOut,
|
|
1073
|
-
unpaid: own.unpaid,
|
|
1074
|
-
total: own.total,
|
|
1075
|
-
cur: own.cur,
|
|
1076
|
-
beforeTax: own.beforeTax,
|
|
1077
|
-
nights: own.nights,
|
|
1078
|
-
rooms: own.rooms,
|
|
1079
|
-
};
|
|
1043
|
+
return { ...own, hotel: own.hotelId };
|
|
1080
1044
|
const stay = (b?.stay ?? {});
|
|
1081
1045
|
return {
|
|
1082
1046
|
order: typeof b?.orderNumber === 'string' ? b.orderNumber : undefined,
|
|
@@ -1511,6 +1475,13 @@ export const buildServer = (opts) => {
|
|
|
1511
1475
|
...(account?.health() ?? {}),
|
|
1512
1476
|
...(memberLogin?.health() ?? {}),
|
|
1513
1477
|
...(usage ? { usage: usage.health() } : {}),
|
|
1478
|
+
// ⚠️ OPENAI'S AND ANTHROPIC'S RANGES: where each list came from, how old it is (`stale`:
|
|
1479
|
+
// nothing newer than 3 days has been read), and the calls that came from outside them,
|
|
1480
|
+
// by platform guessed and check, since start (out-of-list.ts). docs/mcp-source-allowlist.md.
|
|
1481
|
+
platformRanges: {
|
|
1482
|
+
lists: platformRanges.status(),
|
|
1483
|
+
outOfList: outOfList.health(),
|
|
1484
|
+
},
|
|
1514
1485
|
// New sessions by platform, and who came from elsewhere (by network only).
|
|
1515
1486
|
...(sources
|
|
1516
1487
|
? {
|
|
@@ -1603,6 +1574,21 @@ export const buildServer = (opts) => {
|
|
|
1603
1574
|
return c.json({ jsonrpc: '2.0', id: id ?? null, result });
|
|
1604
1575
|
};
|
|
1605
1576
|
const fail = (c, id, code, message) => c.json({ jsonrpc: '2.0', id: id ?? null, error: { code, message } });
|
|
1577
|
+
/** A call refused as not this conversation's: counted, one line (the tool and client, no id, no address), the one answer. */
|
|
1578
|
+
const notCarried = (c, id, name, client, why, said = notCarriedSaid(undefined)) => {
|
|
1579
|
+
calls.notCarried += 1;
|
|
1580
|
+
console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (${why}) - client=${printable(client ?? '-', 60)}`);
|
|
1581
|
+
return ok(c, id, {
|
|
1582
|
+
content: [{ type: 'text', text: said }],
|
|
1583
|
+
structuredContent: {
|
|
1584
|
+
view: 'error',
|
|
1585
|
+
brand: config.brand,
|
|
1586
|
+
error: 'not_this_conversation',
|
|
1587
|
+
code: 'not_this_conversation',
|
|
1588
|
+
},
|
|
1589
|
+
isError: true,
|
|
1590
|
+
});
|
|
1591
|
+
};
|
|
1606
1592
|
app.post('/mcp', bodyLimit({
|
|
1607
1593
|
maxSize: MAX_BODY_BYTES,
|
|
1608
1594
|
onError: (c) => c.json({ jsonrpc: '2.0', id: null, error: { code: -32600, message: 'request too large' } }, 413),
|
|
@@ -1985,34 +1971,40 @@ export const buildServer = (opts) => {
|
|
|
1985
1971
|
/** This connection's conversation, in words - only once it has one (anchored). */
|
|
1986
1972
|
const ownInWords = (k) => sessions.isAnchored(presented) ? tripIds.idFor(k, from, true) : undefined;
|
|
1987
1973
|
/** This ChatGPT conversation's key, from OpenAI's own addresses (0.75.1) - see `openaiConversation`. */
|
|
1988
|
-
const chatgpt = words ? undefined : openaiConversation(c);
|
|
1974
|
+
const chatgpt = words ? undefined : openaiConversation(c, { tool: name, client });
|
|
1989
1975
|
let own = (words ? sessions.boundOf(presented) : undefined) ?? chatgpt ?? tripKey(session, keyBrand);
|
|
1990
1976
|
// ⚠️ A CARD'S CALL COMES FROM A PLATFORM'S OWN ADDRESSES (P1-a, risk A - 0.75.1, 总线程
|
|
1991
1977
|
// 11-18). A call that names a conversation not its own - by a trip id or a sign-in's
|
|
1992
1978
|
// claim - is a card's, or says it is: ChatGPT's card calls from OpenAI's published
|
|
1993
1979
|
// ranges, claude.ai's from Anthropic's (source-ranges.ts), and nothing else draws a card
|
|
1994
1980
|
// that does this. Anyone's script elsewhere that said it draws cards and named a trip id
|
|
1995
|
-
// it had come by was the conversation's card;
|
|
1981
|
+
// it had come by was the conversation's card; until 2026-11-27 it was turned away before any
|
|
1982
|
+
// tool ran. Now it is COUNTED AND LOGGED instead (out-of-list.ts) unless
|
|
1983
|
+
// `HOTEL_CARD_SOURCES=enforce` - see the block that follows.
|
|
1996
1984
|
// By `sourceOf` ALONE, as `openaiConversation`: never a header the caller writes. Our own
|
|
1997
1985
|
// side of the proxy passes too (`cardSourceOf` 'local': no address, a private or a
|
|
1998
1986
|
// loopback one - a test, a local preview): a request from outside comes through Caddy,
|
|
1999
1987
|
// which writes its public address. `HOTEL_CARD_SOURCES=off` turns it off. NOT for a
|
|
2000
1988
|
// client in words: its own rules (`inWords`, below).
|
|
2001
|
-
// ⚠️ A RANGE LIST FALLEN BEHIND
|
|
1989
|
+
// ⚠️ A RANGE LIST FALLEN BEHIND turned real cards away here (2026-11-27); the lists renew
|
|
1990
|
+
// themselves now (@curless/platform-ranges), and this no longer refuses on the address alone.
|
|
2002
1991
|
const cardShaped = !words && asked !== undefined && (named === undefined ? claims.has(asked) : named !== own);
|
|
2003
|
-
if (cardShaped &&
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
1992
|
+
if (cardShaped &&
|
|
1993
|
+
cardSources !== 'off' &&
|
|
1994
|
+
cardSourceOf(sourceOf(c), platformRanges) === undefined) {
|
|
1995
|
+
// ⚠️ NOT TURNED AWAY BY DEFAULT ANY MORE (2026-11-27): a card's call from outside
|
|
1996
|
+
// the lists is handled as usual - the lists renew themselves, and the day they are behind,
|
|
1997
|
+
// real cards must not pay for it - and counted and logged (out-of-list.ts). What guards a
|
|
1998
|
+
// conversation then is what guards one called from inside the lists: the checks below
|
|
1999
|
+
// (the conversation's own key, `oai:`, ids given out again, ids in words).
|
|
2000
|
+
// `HOTEL_CARD_SOURCES=enforce` is the way back to the refusal of 0.75.1.
|
|
2001
|
+
noteOutOfList(c, 'card-source', cardSources === 'enforce' ? 'refused' : 'handled', {
|
|
2002
|
+
tool: name,
|
|
2003
|
+
client,
|
|
2015
2004
|
});
|
|
2005
|
+
if (cardSources === 'enforce') {
|
|
2006
|
+
return notCarried(c, id, name, client, "a card's call from outside the platforms' ranges");
|
|
2007
|
+
}
|
|
2016
2008
|
}
|
|
2017
2009
|
// ⚠️ A TRIP ID GIVEN OUT AGAIN AT A SIGN-IN (P1-a, risk A - 0.75.1, 总线程 11-18). Since a
|
|
2018
2010
|
// sign-in, the conversation goes by a new id (`TripIds.renew`, `renewTrip`), and the one
|
|
@@ -2126,18 +2118,7 @@ export const buildServer = (opts) => {
|
|
|
2126
2118
|
// that conversation - its card was never given it - and would reach the terms'
|
|
2127
2119
|
// ref in `_meta` the card path hands over.
|
|
2128
2120
|
if (!words && asked !== undefined && tripIds.inWords(asked)) {
|
|
2129
|
-
|
|
2130
|
-
console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (an id in words, from a card client) - client=${printable(client ?? '-', 60)}`);
|
|
2131
|
-
return ok(c, id, {
|
|
2132
|
-
content: [{ type: 'text', text: notCarriedSaid(undefined) }],
|
|
2133
|
-
structuredContent: {
|
|
2134
|
-
view: 'error',
|
|
2135
|
-
brand: config.brand,
|
|
2136
|
-
error: 'not_this_conversation',
|
|
2137
|
-
code: 'not_this_conversation',
|
|
2138
|
-
},
|
|
2139
|
-
isError: true,
|
|
2140
|
-
});
|
|
2121
|
+
return notCarried(c, id, name, client, 'an id in words, from a card client');
|
|
2141
2122
|
}
|
|
2142
2123
|
// ⚠️ A CHATGPT CONVERSATION'S TRIP IS ITS OWN ALONE (0.75.1 - and P1-a, risk A, 总线程
|
|
2143
2124
|
// 11-18). Its own cards carry its header, as every ChatGPT call does, so a trip under an
|
|
@@ -2153,18 +2134,22 @@ export const buildServer = (opts) => {
|
|
|
2153
2134
|
// does HOTEL_OPENAI_CONVERSATION=off, for the cards drawn while it was on. Not for a
|
|
2154
2135
|
// client in words: it names no card's id (`inWords`), and its answer is its own (below).
|
|
2155
2136
|
if (!words && named !== undefined && named !== own && named.startsWith(OPENAI_KEY_PREFIX)) {
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2137
|
+
// From OUTSIDE the lists (no header taken, not OpenAI's address): handled as usual,
|
|
2138
|
+
// counted and logged, like any card's call from there (`HOTEL_CARD_SOURCES=enforce`
|
|
2139
|
+
// refuses it again). From INSIDE the lists - another conversation's trip, or no header
|
|
2140
|
+
// - it is refused as ever: that is no list that is behind (out-of-list.ts).
|
|
2141
|
+
// Outside BOTH lists and not our own side of the proxy (`cardSourceOf`), as the card-source
|
|
2142
|
+
// check: from Anthropic's ranges, a private or a loopback address it is refused as ever.
|
|
2143
|
+
const outside = chatgpt === undefined && cardSourceOf(sourceOf(c), platformRanges) === undefined;
|
|
2144
|
+
if (!outside || cardSources === 'enforce') {
|
|
2145
|
+
if (outside)
|
|
2146
|
+
noteOutOfList(c, 'openai-trip', 'refused', { tool: name, client });
|
|
2147
|
+
return notCarried(c, id, name, client, chatgpt !== undefined
|
|
2148
|
+
? "another ChatGPT conversation's trip"
|
|
2149
|
+
: "a ChatGPT conversation's trip, from outside it");
|
|
2150
|
+
}
|
|
2151
|
+
if (cardSources !== 'off')
|
|
2152
|
+
noteOutOfList(c, 'openai-trip', 'handled', { tool: name, client });
|
|
2168
2153
|
}
|
|
2169
2154
|
/** The conversation the trip id named was quiet too long to be taken over (0.67.1) - said in the answer. */
|
|
2170
2155
|
let expired = false;
|
|
@@ -2186,18 +2171,7 @@ export const buildServer = (opts) => {
|
|
|
2186
2171
|
held &&
|
|
2187
2172
|
(held.client ?? '') !== (client ?? '')) {
|
|
2188
2173
|
// ⚠️ AS THE SAME APP (0.67.1): Manus's next connection says it is Manus.
|
|
2189
|
-
|
|
2190
|
-
console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (another app) - client=${printable(client ?? '-', 60)}`);
|
|
2191
|
-
return ok(c, id, {
|
|
2192
|
-
content: [{ type: 'text', text: otherAppSaid }],
|
|
2193
|
-
structuredContent: {
|
|
2194
|
-
view: 'error',
|
|
2195
|
-
brand: config.brand,
|
|
2196
|
-
error: 'not_this_conversation',
|
|
2197
|
-
code: 'not_this_conversation',
|
|
2198
|
-
},
|
|
2199
|
-
isError: true,
|
|
2200
|
-
});
|
|
2174
|
+
return notCarried(c, id, name, client, 'another app', otherAppSaid);
|
|
2201
2175
|
}
|
|
2202
2176
|
else if (!sessions.isAnchored(presented) && held) {
|
|
2203
2177
|
// ⚠️ WHERE IT CAME FROM, BY PREFIX ALONE (0.84.2, the 11-25 code audit's P1-8, option C ④):
|
|
@@ -2401,18 +2375,7 @@ export const buildServer = (opts) => {
|
|
|
2401
2375
|
// conversation over, the one that held it is turned away - a stolen id is not
|
|
2402
2376
|
// used beside the guest, and the guest's own old connection is not a second door.
|
|
2403
2377
|
if (held?.holder && held.holder !== presented && takenOver === undefined) {
|
|
2404
|
-
|
|
2405
|
-
console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (taken over by another connection) - client=${printable(client ?? '-', 60)}`);
|
|
2406
|
-
return ok(c, id, {
|
|
2407
|
-
content: [{ type: 'text', text: movedSaid }],
|
|
2408
|
-
structuredContent: {
|
|
2409
|
-
view: 'error',
|
|
2410
|
-
brand: config.brand,
|
|
2411
|
-
error: 'not_this_conversation',
|
|
2412
|
-
code: 'not_this_conversation',
|
|
2413
|
-
},
|
|
2414
|
-
isError: true,
|
|
2415
|
-
});
|
|
2378
|
+
return notCarried(c, id, name, client, 'taken over by another connection', movedSaid);
|
|
2416
2379
|
}
|
|
2417
2380
|
// ⚠️ ITS BOOKINGS, AFTER A TAKE-OVER FROM ANOTHER NETWORK, ONLY FOR THE SAME
|
|
2418
2381
|
// ACCOUNT SIGNED IN AGAIN (0.67.1) - see `takenOver` above. The trip and the
|
|
@@ -2746,6 +2709,7 @@ export const buildServer = (opts) => {
|
|
|
2746
2709
|
tripIds,
|
|
2747
2710
|
sessions,
|
|
2748
2711
|
...(sources ? { sources } : {}),
|
|
2712
|
+
platformRanges,
|
|
2749
2713
|
...(usage ? { usage } : {}),
|
|
2750
2714
|
flush: () => {
|
|
2751
2715
|
state.flush();
|
|
@@ -2753,6 +2717,7 @@ export const buildServer = (opts) => {
|
|
|
2753
2717
|
},
|
|
2754
2718
|
// The bookings in flight first, then the usage lines still queued.
|
|
2755
2719
|
drain: async () => {
|
|
2720
|
+
platformRanges.stop();
|
|
2756
2721
|
await (made.drain?.() ?? Promise.resolve());
|
|
2757
2722
|
await usage?.flush();
|
|
2758
2723
|
},
|
|
@@ -2850,32 +2815,8 @@ export const HEADER_APPS = 200;
|
|
|
2850
2815
|
*/
|
|
2851
2816
|
const sourceOf = (c) => sourceAddress(clientIp(c.req.header('x-forwarded-for')), c.env?.incoming?.socket
|
|
2852
2817
|
?.remoteAddress);
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
* printable ASCII other than the space (0x21-0x7E). ChatGPT sends 79 opaque ones, one
|
|
2856
|
-
* per conversation (moody's access log, docs/shopify-connectors.md). Anything else -
|
|
2857
|
-
* shorter, longer, a space, a control character or a non-ASCII one, or two headers
|
|
2858
|
-
* joined with ", " - is not taken, and the call is keyed by its connection as before.
|
|
2859
|
-
*/
|
|
2860
|
-
export const OPENAI_SESSION_SHAPE = /^[\x21-\x7e]{16,256}$/;
|
|
2861
|
-
/** What a ChatGPT conversation's key starts with - a session id we issue (a UUID) never does. */
|
|
2862
|
-
export const OPENAI_KEY_PREFIX = 'oai:';
|
|
2863
|
-
/** How often, at most, the count of `X-OpenAI-Session` headers not taken is logged. */
|
|
2864
|
-
const OPENAI_SKIPPED_LOG_MS = 10 * 60_000;
|
|
2865
|
-
/** The platforms whose cards call us: ChatGPT's from OpenAI's published ranges, claude.ai's from Anthropic's. */
|
|
2866
|
-
const CARD_PLATFORMS = [OPENAI, rangesOf('anthropic')];
|
|
2867
|
-
/**
|
|
2868
|
-
* Where a card's call came from (0.75.1, risk A), by `sourceOf` alone: 'platform' - OpenAI's or
|
|
2869
|
-
* Anthropic's published ranges; 'local' - our own side of the proxy: no address, a private or a
|
|
2870
|
-
* loopback one (a test, a local preview - a request from outside comes through Caddy, which
|
|
2871
|
-
* writes its public address); undefined - anywhere else.
|
|
2872
|
-
*/
|
|
2873
|
-
export const cardSourceOf = (address) => {
|
|
2874
|
-
const a = parseAddress(address);
|
|
2875
|
-
if (!a || isPrivateAddress(a))
|
|
2876
|
-
return 'local';
|
|
2877
|
-
return CARD_PLATFORMS.some((r) => r.has(address)) ? 'platform' : undefined;
|
|
2878
|
-
};
|
|
2818
|
+
export { OPENAI_KEY_PREFIX, OPENAI_SESSION_SHAPE } from './openai-conversation.js';
|
|
2819
|
+
export { cardSourceOf, cardSourcesMode } from './out-of-list.js';
|
|
2879
2820
|
/** Sign-ins, and sign-outs, one conversation may make in ten minutes (0.75.1, risk A) - each. */
|
|
2880
2821
|
export const SIGN_STEPS_PER_TEN_MINUTES = 6;
|
|
2881
2822
|
export const clientIp = (header) => {
|