@curless/hotel-storefront 0.92.0 → 0.94.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.
Files changed (59) hide show
  1. package/README.md +5 -2
  2. package/dist/card.generated.d.ts +1 -1
  3. package/dist/card.generated.js +2 -2
  4. package/dist/card.generated.js.map +1 -1
  5. package/dist/cidr.d.ts +3 -21
  6. package/dist/cidr.d.ts.map +1 -1
  7. package/dist/cidr.js +9 -56
  8. package/dist/cidr.js.map +1 -1
  9. package/dist/index.js +11 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/openai-conversation.d.ts +50 -0
  12. package/dist/openai-conversation.d.ts.map +1 -0
  13. package/dist/openai-conversation.js +83 -0
  14. package/dist/openai-conversation.js.map +1 -0
  15. package/dist/out-of-list.d.ts +74 -0
  16. package/dist/out-of-list.d.ts.map +1 -0
  17. package/dist/out-of-list.js +150 -0
  18. package/dist/out-of-list.js.map +1 -0
  19. package/dist/ranges-check-cli.js +19 -7
  20. package/dist/ranges-check-cli.js.map +1 -1
  21. package/dist/ranges-check.d.ts +19 -15
  22. package/dist/ranges-check.d.ts.map +1 -1
  23. package/dist/ranges-check.js +57 -109
  24. package/dist/ranges-check.js.map +1 -1
  25. package/dist/server.d.ts +14 -18
  26. package/dist/server.d.ts.map +1 -1
  27. package/dist/server.js +100 -148
  28. package/dist/server.js.map +1 -1
  29. package/dist/source-allowlist.d.ts +4 -10
  30. package/dist/source-allowlist.d.ts.map +1 -1
  31. package/dist/source-allowlist.js +28 -45
  32. package/dist/source-allowlist.js.map +1 -1
  33. package/dist/source-ranges.d.ts.map +1 -1
  34. package/dist/source-ranges.js +23 -418
  35. package/dist/source-ranges.js.map +1 -1
  36. package/dist/source-refusal-log.d.ts +13 -0
  37. package/dist/source-refusal-log.d.ts.map +1 -0
  38. package/dist/source-refusal-log.js +50 -0
  39. package/dist/source-refusal-log.js.map +1 -0
  40. package/dist/tools/compare.d.ts.map +1 -1
  41. package/dist/tools/compare.js +5 -0
  42. package/dist/tools/compare.js.map +1 -1
  43. package/dist/tools/hotel-bookable.d.ts +13 -0
  44. package/dist/tools/hotel-bookable.d.ts.map +1 -1
  45. package/dist/tools/hotel-bookable.js +22 -0
  46. package/dist/tools/hotel-bookable.js.map +1 -1
  47. package/dist/usage/boot.d.ts +3 -0
  48. package/dist/usage/boot.d.ts.map +1 -1
  49. package/dist/usage/boot.js +2 -1
  50. package/dist/usage/boot.js.map +1 -1
  51. package/dist/usage/platform.d.ts +7 -1
  52. package/dist/usage/platform.d.ts.map +1 -1
  53. package/dist/usage/platform.js +6 -2
  54. package/dist/usage/platform.js.map +1 -1
  55. package/dist/usage/recorder.d.ts +2 -0
  56. package/dist/usage/recorder.d.ts.map +1 -1
  57. package/dist/usage/recorder.js +1 -0
  58. package/dist/usage/recorder.js.map +1 -1
  59. package/package.json +2 -1
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.92.0';
64
+ export const VERSION = '0.94.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
- * ⚠️ ONE CHATGPT CONVERSATION, ONE KEY (0.75.1, 总线程 11-18). ChatGPT opens a new MCP
432
- * connection - a new `initialize`, a new `Mcp-Session-Id` - for every tool call, so a
433
- * conversation keyed by its connection was a new one on every card: the sign-in, the
434
- * membership links and the trip of the card before were not on the next (k=3OUE2Bfr,
435
- * then k=BHb9E1dS, in one conversation). Every call ChatGPT makes - the model's and the
436
- * card's - carries `X-OpenAI-Session`, its pseudonymous id of the conversation, so that
437
- * is the conversation's key - on three conditions, or the call is keyed as before:
438
- * - the request reached Caddy from one of OpenAI's published ranges (`OPENAI`), by
439
- * `sourceOf` ALONE: the last `X-Forwarded-For` entry, which Caddy writes (it has no
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 cardSourcesOn = (opts.env ?? process.env).HOTEL_CARD_SOURCES !== 'off';
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,
@@ -1500,6 +1475,13 @@ export const buildServer = (opts) => {
1500
1475
  ...(account?.health() ?? {}),
1501
1476
  ...(memberLogin?.health() ?? {}),
1502
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
+ },
1503
1485
  // New sessions by platform, and who came from elsewhere (by network only).
1504
1486
  ...(sources
1505
1487
  ? {
@@ -1592,6 +1574,21 @@ export const buildServer = (opts) => {
1592
1574
  return c.json({ jsonrpc: '2.0', id: id ?? null, result });
1593
1575
  };
1594
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
+ };
1595
1592
  app.post('/mcp', bodyLimit({
1596
1593
  maxSize: MAX_BODY_BYTES,
1597
1594
  onError: (c) => c.json({ jsonrpc: '2.0', id: null, error: { code: -32600, message: 'request too large' } }, 413),
@@ -1974,34 +1971,40 @@ export const buildServer = (opts) => {
1974
1971
  /** This connection's conversation, in words - only once it has one (anchored). */
1975
1972
  const ownInWords = (k) => sessions.isAnchored(presented) ? tripIds.idFor(k, from, true) : undefined;
1976
1973
  /** This ChatGPT conversation's key, from OpenAI's own addresses (0.75.1) - see `openaiConversation`. */
1977
- const chatgpt = words ? undefined : openaiConversation(c);
1974
+ const chatgpt = words ? undefined : openaiConversation(c, { tool: name, client });
1978
1975
  let own = (words ? sessions.boundOf(presented) : undefined) ?? chatgpt ?? tripKey(session, keyBrand);
1979
1976
  // ⚠️ A CARD'S CALL COMES FROM A PLATFORM'S OWN ADDRESSES (P1-a, risk A - 0.75.1, 总线程
1980
1977
  // 11-18). A call that names a conversation not its own - by a trip id or a sign-in's
1981
1978
  // claim - is a card's, or says it is: ChatGPT's card calls from OpenAI's published
1982
1979
  // ranges, claude.ai's from Anthropic's (source-ranges.ts), and nothing else draws a card
1983
1980
  // that does this. Anyone's script elsewhere that said it draws cards and named a trip id
1984
- // it had come by was the conversation's card; now it is turned away before any tool runs.
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.
1985
1984
  // By `sourceOf` ALONE, as `openaiConversation`: never a header the caller writes. Our own
1986
1985
  // side of the proxy passes too (`cardSourceOf` 'local': no address, a private or a
1987
1986
  // loopback one - a test, a local preview): a request from outside comes through Caddy,
1988
1987
  // which writes its public address. `HOTEL_CARD_SOURCES=off` turns it off. NOT for a
1989
1988
  // client in words: its own rules (`inWords`, below).
1990
- // ⚠️ A RANGE LIST FALLEN BEHIND (`ranges-check`) turns real cards away here.
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.
1991
1991
  const cardShaped = !words && asked !== undefined && (named === undefined ? claims.has(asked) : named !== own);
1992
- if (cardShaped && cardSourcesOn && cardSourceOf(sourceOf(c)) === undefined) {
1993
- calls.notCarried += 1;
1994
- console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (a card's call from outside the platforms' ranges) - client=${printable(client ?? '-', 60)}`);
1995
- return ok(c, id, {
1996
- content: [{ type: 'text', text: notCarriedSaid(undefined) }],
1997
- structuredContent: {
1998
- view: 'error',
1999
- brand: config.brand,
2000
- error: 'not_this_conversation',
2001
- code: 'not_this_conversation',
2002
- },
2003
- isError: true,
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,
2004
2004
  });
2005
+ if (cardSources === 'enforce') {
2006
+ return notCarried(c, id, name, client, "a card's call from outside the platforms' ranges");
2007
+ }
2005
2008
  }
2006
2009
  // ⚠️ A TRIP ID GIVEN OUT AGAIN AT A SIGN-IN (P1-a, risk A - 0.75.1, 总线程 11-18). Since a
2007
2010
  // sign-in, the conversation goes by a new id (`TripIds.renew`, `renewTrip`), and the one
@@ -2115,18 +2118,7 @@ export const buildServer = (opts) => {
2115
2118
  // that conversation - its card was never given it - and would reach the terms'
2116
2119
  // ref in `_meta` the card path hands over.
2117
2120
  if (!words && asked !== undefined && tripIds.inWords(asked)) {
2118
- calls.notCarried += 1;
2119
- console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (an id in words, from a card client) - client=${printable(client ?? '-', 60)}`);
2120
- return ok(c, id, {
2121
- content: [{ type: 'text', text: notCarriedSaid(undefined) }],
2122
- structuredContent: {
2123
- view: 'error',
2124
- brand: config.brand,
2125
- error: 'not_this_conversation',
2126
- code: 'not_this_conversation',
2127
- },
2128
- isError: true,
2129
- });
2121
+ return notCarried(c, id, name, client, 'an id in words, from a card client');
2130
2122
  }
2131
2123
  // ⚠️ A CHATGPT CONVERSATION'S TRIP IS ITS OWN ALONE (0.75.1 - and P1-a, risk A, 总线程
2132
2124
  // 11-18). Its own cards carry its header, as every ChatGPT call does, so a trip under an
@@ -2142,18 +2134,22 @@ export const buildServer = (opts) => {
2142
2134
  // does HOTEL_OPENAI_CONVERSATION=off, for the cards drawn while it was on. Not for a
2143
2135
  // client in words: it names no card's id (`inWords`), and its answer is its own (below).
2144
2136
  if (!words && named !== undefined && named !== own && named.startsWith(OPENAI_KEY_PREFIX)) {
2145
- calls.notCarried += 1;
2146
- console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (${chatgpt !== undefined ? "another ChatGPT conversation's trip" : "a ChatGPT conversation's trip, from outside it"}) - client=${printable(client ?? '-', 60)}`);
2147
- return ok(c, id, {
2148
- content: [{ type: 'text', text: notCarriedSaid(undefined) }],
2149
- structuredContent: {
2150
- view: 'error',
2151
- brand: config.brand,
2152
- error: 'not_this_conversation',
2153
- code: 'not_this_conversation',
2154
- },
2155
- isError: true,
2156
- });
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 });
2157
2153
  }
2158
2154
  /** The conversation the trip id named was quiet too long to be taken over (0.67.1) - said in the answer. */
2159
2155
  let expired = false;
@@ -2175,18 +2171,7 @@ export const buildServer = (opts) => {
2175
2171
  held &&
2176
2172
  (held.client ?? '') !== (client ?? '')) {
2177
2173
  // ⚠️ AS THE SAME APP (0.67.1): Manus's next connection says it is Manus.
2178
- calls.notCarried += 1;
2179
- console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (another app) - client=${printable(client ?? '-', 60)}`);
2180
- return ok(c, id, {
2181
- content: [{ type: 'text', text: otherAppSaid }],
2182
- structuredContent: {
2183
- view: 'error',
2184
- brand: config.brand,
2185
- error: 'not_this_conversation',
2186
- code: 'not_this_conversation',
2187
- },
2188
- isError: true,
2189
- });
2174
+ return notCarried(c, id, name, client, 'another app', otherAppSaid);
2190
2175
  }
2191
2176
  else if (!sessions.isAnchored(presented) && held) {
2192
2177
  // ⚠️ WHERE IT CAME FROM, BY PREFIX ALONE (0.84.2, the 11-25 code audit's P1-8, option C ④):
@@ -2390,18 +2375,7 @@ export const buildServer = (opts) => {
2390
2375
  // conversation over, the one that held it is turned away - a stolen id is not
2391
2376
  // used beside the guest, and the guest's own old connection is not a second door.
2392
2377
  if (held?.holder && held.holder !== presented && takenOver === undefined) {
2393
- calls.notCarried += 1;
2394
- console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (taken over by another connection) - client=${printable(client ?? '-', 60)}`);
2395
- return ok(c, id, {
2396
- content: [{ type: 'text', text: movedSaid }],
2397
- structuredContent: {
2398
- view: 'error',
2399
- brand: config.brand,
2400
- error: 'not_this_conversation',
2401
- code: 'not_this_conversation',
2402
- },
2403
- isError: true,
2404
- });
2378
+ return notCarried(c, id, name, client, 'taken over by another connection', movedSaid);
2405
2379
  }
2406
2380
  // ⚠️ ITS BOOKINGS, AFTER A TAKE-OVER FROM ANOTHER NETWORK, ONLY FOR THE SAME
2407
2381
  // ACCOUNT SIGNED IN AGAIN (0.67.1) - see `takenOver` above. The trip and the
@@ -2735,6 +2709,7 @@ export const buildServer = (opts) => {
2735
2709
  tripIds,
2736
2710
  sessions,
2737
2711
  ...(sources ? { sources } : {}),
2712
+ platformRanges,
2738
2713
  ...(usage ? { usage } : {}),
2739
2714
  flush: () => {
2740
2715
  state.flush();
@@ -2742,6 +2717,7 @@ export const buildServer = (opts) => {
2742
2717
  },
2743
2718
  // The bookings in flight first, then the usage lines still queued.
2744
2719
  drain: async () => {
2720
+ platformRanges.stop();
2745
2721
  await (made.drain?.() ?? Promise.resolve());
2746
2722
  await usage?.flush();
2747
2723
  },
@@ -2839,32 +2815,8 @@ export const HEADER_APPS = 200;
2839
2815
  */
2840
2816
  const sourceOf = (c) => sourceAddress(clientIp(c.req.header('x-forwarded-for')), c.env?.incoming?.socket
2841
2817
  ?.remoteAddress);
2842
- /**
2843
- * ChatGPT's conversation id, as it is taken (0.75.1): 16 to 256 characters, every one
2844
- * printable ASCII other than the space (0x21-0x7E). ChatGPT sends 79 opaque ones, one
2845
- * per conversation (moody's access log, docs/shopify-connectors.md). Anything else -
2846
- * shorter, longer, a space, a control character or a non-ASCII one, or two headers
2847
- * joined with ", " - is not taken, and the call is keyed by its connection as before.
2848
- */
2849
- export const OPENAI_SESSION_SHAPE = /^[\x21-\x7e]{16,256}$/;
2850
- /** What a ChatGPT conversation's key starts with - a session id we issue (a UUID) never does. */
2851
- export const OPENAI_KEY_PREFIX = 'oai:';
2852
- /** How often, at most, the count of `X-OpenAI-Session` headers not taken is logged. */
2853
- const OPENAI_SKIPPED_LOG_MS = 10 * 60_000;
2854
- /** The platforms whose cards call us: ChatGPT's from OpenAI's published ranges, claude.ai's from Anthropic's. */
2855
- const CARD_PLATFORMS = [OPENAI, rangesOf('anthropic')];
2856
- /**
2857
- * Where a card's call came from (0.75.1, risk A), by `sourceOf` alone: 'platform' - OpenAI's or
2858
- * Anthropic's published ranges; 'local' - our own side of the proxy: no address, a private or a
2859
- * loopback one (a test, a local preview - a request from outside comes through Caddy, which
2860
- * writes its public address); undefined - anywhere else.
2861
- */
2862
- export const cardSourceOf = (address) => {
2863
- const a = parseAddress(address);
2864
- if (!a || isPrivateAddress(a))
2865
- return 'local';
2866
- return CARD_PLATFORMS.some((r) => r.has(address)) ? 'platform' : undefined;
2867
- };
2818
+ export { OPENAI_KEY_PREFIX, OPENAI_SESSION_SHAPE } from './openai-conversation.js';
2819
+ export { cardSourceOf, cardSourcesMode } from './out-of-list.js';
2868
2820
  /** Sign-ins, and sign-outs, one conversation may make in ten minutes (0.75.1, risk A) - each. */
2869
2821
  export const SIGN_STEPS_PER_TEN_MINUTES = 6;
2870
2822
  export const clientIp = (header) => {