@curless/hotel-storefront 0.66.0 → 0.67.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/account/fake-ota.d.ts.map +1 -1
  2. package/dist/account/fake-ota.js +2 -0
  3. package/dist/account/fake-ota.js.map +1 -1
  4. package/dist/account/index.d.ts +20 -0
  5. package/dist/account/index.d.ts.map +1 -1
  6. package/dist/account/index.js +85 -24
  7. package/dist/account/index.js.map +1 -1
  8. package/dist/account/ota-member.d.ts +2 -0
  9. package/dist/account/ota-member.d.ts.map +1 -1
  10. package/dist/account/ota-member.js +2 -0
  11. package/dist/account/ota-member.js.map +1 -1
  12. package/dist/account/pages.d.ts +16 -1
  13. package/dist/account/pages.d.ts.map +1 -1
  14. package/dist/account/pages.js +88 -10
  15. package/dist/account/pages.js.map +1 -1
  16. package/dist/account/requests.d.ts +1 -1
  17. package/dist/account/requests.d.ts.map +1 -1
  18. package/dist/account/store.d.ts +38 -1
  19. package/dist/account/store.d.ts.map +1 -1
  20. package/dist/account/store.js +32 -1
  21. package/dist/account/store.js.map +1 -1
  22. package/dist/card.generated.d.ts +1 -1
  23. package/dist/card.generated.js +2 -2
  24. package/dist/card.generated.js.map +1 -1
  25. package/dist/config.d.ts +20 -0
  26. package/dist/config.d.ts.map +1 -1
  27. package/dist/config.js.map +1 -1
  28. package/dist/otaless/backend.d.ts +6 -0
  29. package/dist/otaless/backend.d.ts.map +1 -1
  30. package/dist/otaless/backend.js +70 -5
  31. package/dist/otaless/backend.js.map +1 -1
  32. package/dist/otaless/booking.d.ts +119 -5
  33. package/dist/otaless/booking.d.ts.map +1 -1
  34. package/dist/otaless/booking.js +477 -59
  35. package/dist/otaless/booking.js.map +1 -1
  36. package/dist/otaless/client.d.ts +83 -7
  37. package/dist/otaless/client.d.ts.map +1 -1
  38. package/dist/otaless/client.js +117 -13
  39. package/dist/otaless/client.js.map +1 -1
  40. package/dist/otaless/fake.d.ts +45 -2
  41. package/dist/otaless/fake.d.ts.map +1 -1
  42. package/dist/otaless/fake.js +94 -10
  43. package/dist/otaless/fake.js.map +1 -1
  44. package/dist/otaless/make.d.ts +8 -0
  45. package/dist/otaless/make.d.ts.map +1 -1
  46. package/dist/otaless/make.js +55 -4
  47. package/dist/otaless/make.js.map +1 -1
  48. package/dist/otaless/places.d.ts +14 -0
  49. package/dist/otaless/places.d.ts.map +1 -1
  50. package/dist/otaless/places.js +108 -1
  51. package/dist/otaless/places.js.map +1 -1
  52. package/dist/pictures.d.ts +19 -0
  53. package/dist/pictures.d.ts.map +1 -0
  54. package/dist/pictures.js +74 -0
  55. package/dist/pictures.js.map +1 -0
  56. package/dist/server.d.ts +17 -2
  57. package/dist/server.d.ts.map +1 -1
  58. package/dist/server.js +415 -40
  59. package/dist/server.js.map +1 -1
  60. package/dist/sessions.d.ts +23 -0
  61. package/dist/sessions.d.ts.map +1 -1
  62. package/dist/sessions.js +39 -1
  63. package/dist/sessions.js.map +1 -1
  64. package/dist/supplier.js +4 -0
  65. package/dist/supplier.js.map +1 -1
  66. package/dist/surface.d.ts +24 -1
  67. package/dist/surface.d.ts.map +1 -1
  68. package/dist/surface.js +31 -4
  69. package/dist/surface.js.map +1 -1
  70. package/dist/tools.d.ts +30 -0
  71. package/dist/tools.d.ts.map +1 -1
  72. package/dist/tools.js +221 -27
  73. package/dist/tools.js.map +1 -1
  74. package/dist/trip-ids.d.ts +38 -1
  75. package/dist/trip-ids.d.ts.map +1 -1
  76. package/dist/trip-ids.js +98 -3
  77. package/dist/trip-ids.js.map +1 -1
  78. package/dist/types.d.ts +69 -1
  79. package/dist/types.d.ts.map +1 -1
  80. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -14,12 +14,13 @@ import { docsPage, privacyPage, termsPage } from './legal.js';
14
14
  import { Misses, WindowCounter } from './limits.js';
15
15
  import { MemberStore } from './members.js';
16
16
  import { paidAnswer } from './paid.js';
17
+ import { picturesApart } from './pictures.js';
17
18
  import { Sessions, cardSupport } from './sessions.js';
18
19
  import { StateDir } from './state.js';
19
20
  import { makeSupplier } from './supplier.js';
20
21
  import { buildInstructions, listTools, tripToolNames } from './surface.js';
21
22
  import { TERMS_META_KEY, agreeToTerms, bookingRefusal, buildOutputSchemas, buildTools, commonFields, contextFor, handleTool, homeListing, identityFor, outputSchemasFor, tripGone, withheldTools, } from './tools.js';
22
- import { TripIds } from './trip-ids.js';
23
+ import { ID_TTL_MS, TAKE_OVER_MS, TripIds, networkOf } from './trip-ids.js';
23
24
  import { TripStore, tripKey } from './trip.js';
24
25
  import { checkDemoData, resolveBrand } from './vocab.js';
25
26
  // The connector itself: one config in, one HTTP app out.
@@ -50,7 +51,7 @@ export const INITIALIZE_PER_MINUTE = 300;
50
51
  * number. Found by reading the boot banner of a container that had just been
51
52
  * deployed (2026-09-22): seventeen tools listed, and "0.7.0" above them.
52
53
  */
53
- export const VERSION = '0.66.0';
54
+ export const VERSION = '0.67.1';
54
55
  /**
55
56
  * The card's resource URI.
56
57
  *
@@ -59,7 +60,7 @@ export const VERSION = '0.66.0';
59
60
  * connector went storefront-v35 → v40 in a single day of UI work for exactly
60
61
  * this reason.
61
62
  */
62
- export const CARD_URI = 'ui://curless/hotel/booking-v130.html';
63
+ export const CARD_URI = 'ui://curless/hotel/booking-v131.html';
63
64
  /** The card as it ships, hashed once - what a host caches under the URI. */
64
65
  const CARD_HTML_SHA = createHash('sha256').update(HOTEL_CARD_HTML).digest('hex');
65
66
  /**
@@ -349,12 +350,37 @@ export const buildServer = (opts) => {
349
350
  * once a connection.
350
351
  */
351
352
  cardNamed: 0,
353
+ /**
354
+ * A new connection of a client that draws no card took over the
355
+ * conversation its first trip id named (0.67.0) - and connections that had
356
+ * a conversation and named another, refused.
357
+ */
358
+ carriedOver: 0,
359
+ notCarried: 0,
352
360
  };
353
361
  const cardNamedSeen = new Set();
354
362
  // Sessions that have acted on their own conversation: `sessions.anchor` -
355
363
  // kept with the session ids, on disk since 0.59.0 (review C1).
356
- /** Sessions whose headers have been noted once (diagnostics, 0.56.1). */
357
- const diagnosed = new Set();
364
+ /**
365
+ * How many times each app's header NAMES have been logged, by where (0.67.0,
366
+ * 总线程 11-11): does Manus - which started a new connection between two
367
+ * turns - send a conversation id of its own that outlives a connection? The
368
+ * first few of each app, at `initialize` and at `tools/call`, in every
369
+ * deployment; never a value. Made-up app names past `HEADER_APPS` are not
370
+ * logged at all: a flood of them would be all this log said.
371
+ */
372
+ const headerLogs = new Map();
373
+ const noteHeaders = (c, at, client, extra) => {
374
+ const who = printable(client ?? '-', 60);
375
+ const k = `${at} ${who}`;
376
+ const n = headerLogs.get(k) ?? 0;
377
+ if (n >= HEADER_LOGS_PER_APP)
378
+ return;
379
+ if (n === 0 && headerLogs.size >= HEADER_APPS)
380
+ return;
381
+ headerLogs.set(k, n + 1);
382
+ console.log(`[mcp] headers ${at} client=${who} n=${n + 1}${extra} ${headerNames(c)}`);
383
+ };
358
384
  // What has outlived its time goes off the disk too, even with nobody asking:
359
385
  // "forgotten two hours after" is a promise the privacy page makes.
360
386
  if (state.persisted) {
@@ -532,9 +558,16 @@ export const buildServer = (opts) => {
532
558
  : {}),
533
559
  signInTool: account.names.signIn,
534
560
  };
561
+ // The signed-in guest's details, for a booking they leave empty (0.67.0).
562
+ deps.guestProfile = account.profileFor;
535
563
  }
536
564
  const ACCOUNT_TOOLS = account ? account.tools() : [];
537
- const TOOLS = buildTools(brand.tools, brand.vocab, caps);
565
+ // ⚠️ WHERE A GUEST SIGNS IN TO AN ACCOUNT, A BOOKING NEEDS NO NAME OR EMAIL IN THE
566
+ // CALL (0.67.0, 总线程 11-11): the account's are used for what the guest leaves out
567
+ // (tools.ts `withProfile`) - and the model is never told them whole, so it could not
568
+ // pass them. A guest not signed in is still asked (`needs-guest`). Every other
569
+ // deployment's list is as it was.
570
+ const TOOLS = buildTools(brand.tools, brand.vocab, caps).map((t) => account && t.name === brand.tools.requestBooking ? profiledBooking(t) : t);
538
571
  const OFFERED = new Set([
539
572
  ...TOOLS.map((t) => t.name),
540
573
  ...ACCOUNT_TOOLS.map((t) => String(t.name)),
@@ -591,6 +624,12 @@ export const buildServer = (opts) => {
591
624
  // a press on the card, never the model's - no tool it can see agrees.
592
625
  brand.tools.acceptTerms,
593
626
  ]);
627
+ /** App-only tools with a refusal of their own for a client that draws no card (see tools/call). */
628
+ const OWN_REFUSALS = new Set([
629
+ ...(account ? [account.names.card] : []),
630
+ ...(memberLogin ? [brand.tools.memberCard] : []),
631
+ brand.tools.acceptTerms,
632
+ ]);
594
633
  const appOnly = (m) => ({
595
634
  ...m,
596
635
  ui: { ...m.ui, visibility: ['app'] },
@@ -629,7 +668,61 @@ export const buildServer = (opts) => {
629
668
  // each answer, never in the tools. So a list read with no session - nothing
630
669
  // said about cards - is not a guess at which client it is. Were the lists
631
670
  // ever to differ, that one is the cardless list: nothing said is "none".
632
- const toolList = () => listTools([...TOOLS.map((t) => homeListing(t, brand, made.hotelCount())), ...ACCOUNT_TOOLS], { ...OUTPUT_SCHEMAS, ...(account?.outputSchemas() ?? {}) }, (name) => (CARDLESS.has(name) ? {} : APP_ONLY.has(name) ? appOnly(meta()) : meta()), TRIP_TOOLS);
671
+ //
672
+ // ⚠️ EXCEPT ONE THING, FOR A SESSION THAT SAID IT DRAWS NO CARD (0.67.0): every
673
+ // tool takes the conversation's `trip`, described as the id its answers give
674
+ // (`WORDS_TRIP_PARAM`) - see `words` in tools/call. A card host's list, and a
675
+ // list read with no session, are as they were, byte for byte.
676
+ const toolList = (words = false) => listTools([...TOOLS.map((t) => homeListing(t, brand, made.hotelCount())), ...ACCOUNT_TOOLS], { ...OUTPUT_SCHEMAS, ...(account?.outputSchemas() ?? {}) }, (name) => (CARDLESS.has(name) ? {} : APP_ONLY.has(name) ? appOnly(meta()) : meta()), TRIP_TOOLS, words);
677
+ /**
678
+ * The tools that change nothing, by their own annotations: called naming no
679
+ * trip by a client that draws no card, they do not anchor a new connection
680
+ * to a conversation of its own (0.67.0, `looking` in tools/call).
681
+ */
682
+ const READ_ONLY = new Set([...TOOLS, ...ACCOUNT_TOOLS]
683
+ .filter((t) => t.annotations?.readOnlyHint === true)
684
+ .map((t) => t.name));
685
+ /**
686
+ * The tools that reach a conversation's bookings - after a take-over from another
687
+ * network, only for the same account signed in again (0.67.1). The trip and the
688
+ * search are not among them.
689
+ */
690
+ const BOOKING_TOOLS = new Set([
691
+ brand.tools.requestBooking,
692
+ brand.tools.bookPicked,
693
+ brand.tools.listBookings,
694
+ brand.tools.previewCancellation,
695
+ brand.tools.cancelBooking,
696
+ brand.tools.refundBooking,
697
+ brand.tools.previewChange,
698
+ brand.tools.changeBooking,
699
+ brand.tools.listBookingAddons,
700
+ brand.tools.addBookingAddon,
701
+ brand.tools.acceptTerms,
702
+ brand.tools.payWithUnionPay,
703
+ ]);
704
+ /** Last used longer ago than a take-over allows - or never said (0.67.1, `TAKE_OVER_MS`). */
705
+ const quietTooLong = (usedAt) => usedAt === undefined || now() - usedAt > TAKE_OVER_MS;
706
+ /** Who a conversation is signed in as, hashed: its account's id, its membership's number (0.67.1). */
707
+ const signedInAs = (key) => [
708
+ account?.whoOf(key) ? `account ${account.whoOf(key)}` : '',
709
+ deps.members.read(key)?.number ? `member ${deps.members.read(key)?.number}` : '',
710
+ ]
711
+ .filter(Boolean)
712
+ .map((w) => createHash('sha256').update(w).digest('base64url'));
713
+ /** A take-over from another network, at a booking: sign in again as the same account - or start over. */
714
+ const signInAgainSaid = (canSignIn) => {
715
+ const tool = account?.names.signIn ?? (memberLogin ? brand.tools.signIn : undefined);
716
+ return canSignIn && tool
717
+ ? `Nothing was done: this conversation was picked up on a connection from another network, so its bookings are reached only once the guest signs in again here, to the same account or membership as before - ${tool} gives the link. The trip and the search are as they were.`
718
+ : 'Nothing was done: this conversation was picked up on a connection from another network, and nobody was signed in to it, so its bookings are not reached from here. Call again without trip to start a new conversation.';
719
+ };
720
+ /** …and of those, the ones that say what a conversation holds: a new connection's empty one is said to be new. */
721
+ const STATE_READS = new Set([
722
+ brand.tools.viewTrip,
723
+ brand.tools.listBookings,
724
+ ...(account ? [account.names.view] : []),
725
+ ]);
633
726
  /** The trip beside an answer, for the card's header - see `TRIP_META_KEY`. */
634
727
  /**
635
728
  * ⚠️ `withId` FALSE FOR A CALL THAT NAMED ANOTHER CONVERSATION'S TRIP (review
@@ -841,10 +934,10 @@ export const buildServer = (opts) => {
841
934
  });
842
935
  // Which app, and whether it said it shows cards - the one thing to look
843
936
  // at when an answer pointed at a card nobody drew. Never the address.
844
- console.log(`[mcp] initialize client=${printable(typeof client === 'string' ? client : '-', 60)} cards=${cards}${
845
- // Where there is an account (0.56.1 diagnostics): the session by an
846
- // 8-character fingerprint, and the NAMES of the headers it came with.
847
- account ? ` s=${h8(sessionId)} ${headerNames(c)}` : ''}`);
937
+ // The session by an 8-character fingerprint (0.56.1; every deployment
938
+ // since 0.67.0), so the lines of one connection can be followed.
939
+ console.log(`[mcp] initialize client=${printable(typeof client === 'string' ? client : '-', 60)} cards=${cards} s=${h8(sessionId)}`);
940
+ noteHeaders(c, 'initialize', typeof client === 'string' ? client : undefined, '');
848
941
  c.header('Mcp-Session-Id', sessionId);
849
942
  return ok(c, id, {
850
943
  protocolVersion: PROTOCOL_VERSION,
@@ -924,7 +1017,7 @@ export const buildServer = (opts) => {
924
1017
  if (method === 'notifications/initialized')
925
1018
  return c.body(null, 202);
926
1019
  if (method === 'tools/list')
927
- return ok(c, id, { tools: toolList() });
1020
+ return ok(c, id, { tools: toolList(sessions.cardsOf(presented) === 'none') });
928
1021
  if (method === 'resources/list') {
929
1022
  const m = meta();
930
1023
  return ok(c, id, {
@@ -976,18 +1069,75 @@ export const buildServer = (opts) => {
976
1069
  const session = presented;
977
1070
  // The card names its trip; the conversation is known by its session. See
978
1071
  // trip-ids.ts for why both exist.
979
- const asked = typeof args.trip === 'string' && args.trip ? args.trip : undefined;
1072
+ let asked = typeof args.trip === 'string' && args.trip ? args.trip : undefined;
980
1073
  calls.issued += 1;
981
- const named = asked ? tripIds.keyFor(asked) : undefined;
1074
+ let named = asked ? tripIds.keyFor(asked) : undefined;
982
1075
  // ⚠️ A TRIP THE CARD NAMES AND WE DO NOT KNOW IS SAID SO - see `tripGone`.
983
1076
  // Anything else it asked is still answered, but with no trip beside it:
984
1077
  // the card would take that trip's id as its own.
985
1078
  const lost = asked !== undefined && named === undefined;
1079
+ // ⚠️ ONLY A CLIENT THAT SAID IT DRAWS CARDS - never one we know nothing
1080
+ // of (`drawsCards` below; 总线程's review of 0.56.1): a session from
1081
+ // before a restart, or a connection that never initialized here, is not
1082
+ // handed the user name in `_meta`.
1083
+ const cardsSaid = sessions.cardsOf(presented);
1084
+ const saidCards = cardsSaid === 'extension' || cardsSaid === 'host';
1085
+ // ⚠️ A CLIENT THAT DRAWS NO CARD CARRIES ITS CONVERSATION BY ITS ID, IN
1086
+ // WORDS (0.67.0, robin's Manus test 11-11). For such a client "this
1087
+ // conversation" was this one connection: Manus started a new one between
1088
+ // two turns, the guest who had just signed in on the old one was a
1089
+ // stranger on the new one, and was sent a second link. Nothing it sends
1090
+ // was seen to outlive a connection (`noteHeaders` looks), so the
1091
+ // conversation's own trip id is given to the model in every answer, and
1092
+ // the model passes it on every call. See `Sessions.bind` for the rules.
1093
+ const words = cardsSaid === 'none';
1094
+ // ⚠️ THE CARD'S OWN TOOLS, ONLY TO A CLIENT THAT SAID IT DRAWS CARDS (0.67.1,
1095
+ // 总线程's review of 0.67.0): Manus does not read `visibility: ['app']` and lists
1096
+ // them to its model - a pick, the booking form's submit, a UnionPay payment. The
1097
+ // account's card tool, the membership's and the terms' have refusals of their
1098
+ // own, with their own words (below); every other one is refused here.
1099
+ if (APP_ONLY.has(name) && !saidCards && !OWN_REFUSALS.has(name)) {
1100
+ calls.accountRefused += 1;
1101
+ console.log(`[mcp] ${printable(name, 60)} refused: card_only - client=${printable(sessions.clientOf(presented) ?? '-', 60)} cards=${cardsSaid ?? '-'}`);
1102
+ return ok(c, id, {
1103
+ content: [
1104
+ {
1105
+ type: 'text',
1106
+ text: `${name} is the booking card's own, and this app draws no card: nothing was done.`,
1107
+ },
1108
+ ],
1109
+ structuredContent: { view: 'error', brand: config.brand, code: 'card_only' },
1110
+ isError: true,
1111
+ });
1112
+ }
1113
+ noteHeaders(c, 'tools/call', sessions.clientOf(presented), ` tool=${printable(name, 60)} s=${h8(presented)} trip=${asked === undefined ? 'none' : lost ? 'lost' : 'named'}`);
1114
+ const from = ip ? addressKey(ip) : undefined;
1115
+ /** Its network, for "the same network" (0.67.1) - never written down or logged. */
1116
+ const network = networkOf(from);
1117
+ const client = sessions.clientOf(presented);
1118
+ /** This connection's conversation, in words - only once it has one (anchored). */
1119
+ const ownInWords = (k) => sessions.isAnchored(presented) ? tripIds.idFor(k, from, true) : undefined;
1120
+ let own = (words ? sessions.boundOf(presented) : undefined) ?? tripKey(session, config.brand);
1121
+ if (words && lost) {
1122
+ console.log(`[mcp] trip-gone tool=${printable(name, 60)} id=${h8(asked ?? '')} knownIds=${tripIds.size} client=${printable(sessions.clientOf(presented) ?? '-', 60)} cards=none`);
1123
+ const mine = ownInWords(own);
1124
+ return ok(c, id, {
1125
+ content: [{ type: 'text', text: tripLostSaid(mine) }],
1126
+ structuredContent: {
1127
+ view: 'error',
1128
+ brand: config.brand,
1129
+ error: 'trip-gone',
1130
+ code: 'trip-gone',
1131
+ ...(mine ? { conversation: conversationOf(mine) } : {}),
1132
+ },
1133
+ isError: true,
1134
+ });
1135
+ }
986
1136
  if (lost && TRIP_TOOLS.has(name)) {
987
1137
  // Which id, from what app - never the address, the arguments or
988
1138
  // anything said in it (2026-10-14: robin met this on a new
989
1139
  // conversation, and nothing said why).
990
- console.log(`[mcp] trip-gone tool=${printable(name, 60)} id=${h8(asked)} knownIds=${tripIds.size} client=${printable(sessions.clientOf(presented) ?? '-', 60)} ua=${printable(c.req.header('user-agent') ?? '-', 80)}`);
1140
+ console.log(`[mcp] trip-gone tool=${printable(name, 60)} id=${h8(asked ?? '')} knownIds=${tripIds.size} client=${printable(sessions.clientOf(presented) ?? '-', 60)} ua=${printable(c.req.header('user-agent') ?? '-', 80)}`);
991
1141
  const gone = tripGone(deps);
992
1142
  return ok(c, id, {
993
1143
  content: [{ type: 'text', text: gone.text }],
@@ -996,14 +1146,103 @@ export const buildServer = (opts) => {
996
1146
  _meta: meta(),
997
1147
  });
998
1148
  }
999
- const own = tripKey(session, config.brand);
1149
+ // ⚠️ AN ID HANDED OUT IN WORDS IS NEVER A CARD'S (0.67.1, 总线程's review of
1150
+ // 0.67.0): a connection that said it draws cards and names one is not the card of
1151
+ // that conversation - its card was never given it - and would reach the terms'
1152
+ // ref in `_meta` the card path hands over.
1153
+ if (!words && asked !== undefined && tripIds.inWords(asked)) {
1154
+ calls.notCarried += 1;
1155
+ console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (an id in words, from a card client) - client=${printable(client ?? '-', 60)}`);
1156
+ return ok(c, id, {
1157
+ content: [{ type: 'text', text: notCarriedSaid(undefined) }],
1158
+ structuredContent: {
1159
+ view: 'error',
1160
+ brand: config.brand,
1161
+ error: 'not_this_conversation',
1162
+ code: 'not_this_conversation',
1163
+ },
1164
+ isError: true,
1165
+ });
1166
+ }
1167
+ /** The conversation the trip id named was quiet too long to be taken over (0.67.1) - said in the answer. */
1168
+ let expired = false;
1169
+ /** This call took a conversation over: from the same network, or not ('-': not known). */
1170
+ let takenOver;
1171
+ if (words && asked !== undefined && named !== undefined && named !== own) {
1172
+ const held = tripIds.inWordsHeld(asked);
1173
+ if (!sessions.isAnchored(presented) && held && quietTooLong(held.usedAt)) {
1174
+ // ⚠️ NOT AFTER HALF AN HOUR (0.67.1): an id is a way back into a conversation
1175
+ // just left, not a pass for weeks - one in a shared or exported transcript is
1176
+ // worth nothing once the conversation has gone quiet. As if no id was passed:
1177
+ // a new, empty conversation, and the answer says so.
1178
+ expired = true;
1179
+ console.log(`[mcp] not carried over: quiet too long s=${h8(presented)} k=${h8(named)} client=${printable(client ?? '-', 60)}`);
1180
+ asked = undefined;
1181
+ named = undefined;
1182
+ }
1183
+ else if (!sessions.isAnchored(presented) &&
1184
+ held &&
1185
+ (held.client ?? '') !== (client ?? '')) {
1186
+ // ⚠️ AS THE SAME APP (0.67.1): Manus's next connection says it is Manus.
1187
+ calls.notCarried += 1;
1188
+ console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (another app) - client=${printable(client ?? '-', 60)}`);
1189
+ return ok(c, id, {
1190
+ content: [{ type: 'text', text: otherAppSaid }],
1191
+ structuredContent: {
1192
+ view: 'error',
1193
+ brand: config.brand,
1194
+ error: 'not_this_conversation',
1195
+ code: 'not_this_conversation',
1196
+ },
1197
+ isError: true,
1198
+ });
1199
+ }
1200
+ else if (!sessions.isAnchored(presented) && held) {
1201
+ // A new connection's first word of a conversation it has not acted
1202
+ // in yet, used in the last half hour by the same app: it takes that
1203
+ // conversation over, and keeps to it - and the one that held it is
1204
+ // turned away from now on (below).
1205
+ sessions.bind(presented, named);
1206
+ own = named;
1207
+ calls.carriedOver += 1;
1208
+ takenOver = tripIds.networkMatch(asked, network);
1209
+ console.log(`[mcp] carried over s=${h8(presented)} k=${h8(named)} tool=${printable(name, 60)} client=${printable(client ?? '-', 60)} address=${takenOver}`);
1210
+ if (takenOver !== 'same') {
1211
+ // ⚠️ FROM ANOTHER NETWORK, THE SIGN-INS END AND THE BOOKINGS WAIT FOR THE SAME
1212
+ // ACCOUNT (0.67.1): an id read off a transcript is not the guest. Who the
1213
+ // conversation was signed in as is kept (hashed) - only that account or
1214
+ // membership signing in again here reaches its bookings; none, and nothing does.
1215
+ const who = signedInAs(named);
1216
+ account?.forget(named);
1217
+ deps.members.clear(named);
1218
+ memberLogin?.cancel(named);
1219
+ tripIds.setAgain(asked, who);
1220
+ }
1221
+ // Held by this connection from now on - whatever this call comes to.
1222
+ tripIds.heldBy(asked, presented, client, network);
1223
+ }
1224
+ else if (sessions.isAnchored(presented)) {
1225
+ // ⚠️ A CONNECTION THAT HAS ITS CONVERSATION NAMES NO OTHER - every tool,
1226
+ // in words (the rule of review P2-1, which the card's tools keep below):
1227
+ // with no card here, an id it did not get from its own answers is one
1228
+ // a page or a message put in front of the model.
1229
+ calls.notCarried += 1;
1230
+ console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation - client=${printable(sessions.clientOf(presented) ?? '-', 60)} cards=none`);
1231
+ const mine = ownInWords(own);
1232
+ return ok(c, id, {
1233
+ content: [{ type: 'text', text: notCarriedSaid(mine) }],
1234
+ structuredContent: {
1235
+ view: 'error',
1236
+ brand: config.brand,
1237
+ error: 'not_this_conversation',
1238
+ code: 'not_this_conversation',
1239
+ ...(mine ? { conversation: conversationOf(mine) } : {}),
1240
+ },
1241
+ isError: true,
1242
+ });
1243
+ }
1244
+ }
1000
1245
  const key = named ?? own;
1001
- // ⚠️ ONLY A CLIENT THAT SAID IT DRAWS CARDS - never one we know nothing
1002
- // of (`drawsCards` below; 总线程's review of 0.56.1): a session from
1003
- // before a restart, or a connection that never initialized here, is not
1004
- // handed the user name in `_meta`.
1005
- const cardsSaid = sessions.cardsOf(presented);
1006
- const saidCards = cardsSaid === 'extension' || cardsSaid === 'host';
1007
1246
  // Its own conversation, by naming none or its own: this session is
1008
1247
  // the conversation's, not a card's.
1009
1248
  const ours = asked === undefined || named === own;
@@ -1014,6 +1253,8 @@ export const buildServer = (opts) => {
1014
1253
  // to hand it to anyway. A session from before 0.59.0 (unknown) is still
1015
1254
  // handed it: a card drawn in a claude.ai conversation open across the
1016
1255
  // deploy would otherwise lose its conversation's trip (see sessions.ts).
1256
+ // (Since 0.67.0 such a client's model is given the id in the answer's
1257
+ // words instead, on purpose - `inWords` below - and never in `_meta`.)
1017
1258
  const handsTripId = ours && cardsSaid !== 'none';
1018
1259
  // ⚠️ DIAGNOSTICS, WHERE THERE IS AN ACCOUNT (0.56.1): which connection
1019
1260
  // reached which conversation, by 8-character fingerprints - never an id,
@@ -1022,18 +1263,67 @@ export const buildServer = (opts) => {
1022
1263
  // assistant looked at another. These lines say how.
1023
1264
  if (account) {
1024
1265
  const trip = asked === undefined ? 'none' : lost ? 'lost' : named === own ? 'own' : 'named';
1025
- if (!diagnosed.has(presented)) {
1026
- diagnosed.add(presented);
1027
- if (diagnosed.size > 100_000)
1028
- diagnosed.clear();
1029
- console.log(`[mcp] first call s=${h8(presented)} ${headerNames(c)}`);
1030
- }
1031
1266
  console.log(`[mcp] call ${printable(name, 60)} s=${h8(presented)} k=${h8(key)} trip=${trip} client=${printable(sessions.clientOf(presented) ?? '-', 40)} cards=${sessions.cardsOf(presented) ?? '-'}`);
1032
1267
  }
1033
- if (ours)
1034
- sessions.anchor(presented);
1268
+ // ⚠️ LOOKING IS NOT ACTING, FOR A CLIENT THAT DRAWS NO CARD (0.67.0): a new
1269
+ // connection whose model looked something up before passing the trip id
1270
+ // it was given would otherwise be anchored to an empty conversation of
1271
+ // its own, and refused the guest's. Only what changes a conversation -
1272
+ // or names its id - anchors one.
1273
+ const looking = words && asked === undefined && READ_ONLY.has(name) && !sessions.isAnchored(presented);
1274
+ if (ours) {
1275
+ if (!looking)
1276
+ sessions.anchor(presented);
1277
+ }
1035
1278
  else if (sessions.isAnchored(presented))
1036
1279
  calls.foreignTrip += 1;
1280
+ /** The conversation's id for the model, in words: a client that draws no card, its own conversation. */
1281
+ const inWords = words && ours ? ownInWords(key) : undefined;
1282
+ if (inWords) {
1283
+ const held = tripIds.inWordsHeld(inWords);
1284
+ // ⚠️ ONE CONNECTION AT A TIME (0.67.1): once a new connection has taken the
1285
+ // conversation over, the one that held it is turned away - a stolen id is not
1286
+ // used beside the guest, and the guest's own old connection is not a second door.
1287
+ if (held?.holder && held.holder !== presented && takenOver === undefined) {
1288
+ calls.notCarried += 1;
1289
+ console.log(`[mcp] ${printable(name, 60)} refused: not_this_conversation (taken over by another connection) - client=${printable(client ?? '-', 60)}`);
1290
+ return ok(c, id, {
1291
+ content: [{ type: 'text', text: movedSaid }],
1292
+ structuredContent: {
1293
+ view: 'error',
1294
+ brand: config.brand,
1295
+ error: 'not_this_conversation',
1296
+ code: 'not_this_conversation',
1297
+ },
1298
+ isError: true,
1299
+ });
1300
+ }
1301
+ // ⚠️ ITS BOOKINGS, AFTER A TAKE-OVER FROM ANOTHER NETWORK, ONLY FOR THE SAME
1302
+ // ACCOUNT SIGNED IN AGAIN (0.67.1) - see `takenOver` above. The trip and the
1303
+ // search are as ever.
1304
+ if (held?.again && BOOKING_TOOLS.has(name)) {
1305
+ const now = signedInAs(key);
1306
+ if (!now.some((w) => held.again?.includes(w))) {
1307
+ calls.accountRefused += 1;
1308
+ console.log(`[mcp] ${printable(name, 60)} refused: sign_in_again`);
1309
+ return ok(c, id, {
1310
+ content: [{ type: 'text', text: signInAgainSaid(held.again.length > 0) }],
1311
+ structuredContent: {
1312
+ view: 'error',
1313
+ brand: config.brand,
1314
+ error: 'sign_in_again',
1315
+ code: 'sign_in_again',
1316
+ conversation: conversationOf(inWords),
1317
+ },
1318
+ isError: true,
1319
+ });
1320
+ }
1321
+ tripIds.setAgain(inWords, undefined);
1322
+ }
1323
+ tripIds.heldBy(inWords, presented, client, network);
1324
+ }
1325
+ /** What every answer to such a client says beside its own words - see `inWordsOf`. */
1326
+ const said = (text, structured) => inWordsOf(text, structured, inWords, looking && STATE_READS.has(name), expired);
1037
1327
  if (account?.has(name)) {
1038
1328
  // ⚠️ WHO MAY NAME WHICH CONVERSATION (review P2-1). The assistant's
1039
1329
  // three: their own, never one a trip id names. The card's: the one
@@ -1084,12 +1374,18 @@ export const buildServer = (opts) => {
1084
1374
  // A card host answered in words is told the link and code it would
1085
1375
  // have drawn - the guest signs in either way.
1086
1376
  ...(saidCards ? {} : { noCards: true }),
1377
+ // The conversation's id, for what its words tell the model to pass on (0.67.0).
1378
+ ...(inWords ? { trip: inWords } : {}),
1087
1379
  });
1088
- return ok(c, id, {
1089
- content: [{ type: 'text', text: answer.text }],
1380
+ const told = said(answer.text, {
1090
1381
  // The deployment's name, logo and tools beside it, as every answer
1091
1382
  // has them: this may be the first card the conversation draws.
1092
- structuredContent: { ...commonFields(deps, key), ...answer.structured },
1383
+ ...commonFields(deps, key),
1384
+ ...answer.structured,
1385
+ });
1386
+ return ok(c, id, {
1387
+ content: [{ type: 'text', text: told.text }],
1388
+ structuredContent: told.structured,
1093
1389
  ...(answer.isError ? { isError: true } : {}),
1094
1390
  _meta: {
1095
1391
  ...(lost
@@ -1208,6 +1504,10 @@ export const buildServer = (opts) => {
1208
1504
  : {}),
1209
1505
  // Only a client that said it draws them - never one we know nothing of (`drawsCards`).
1210
1506
  ...(saidCards ? { drawsCards: true } : {}),
1507
+ // The conversation's id, for what its words tell the model to pass on (0.67.0).
1508
+ ...(inWords ? { tripInWords: inWords } : {}),
1509
+ // …and the conversation it took over, whose bookings are its own (0.67.1).
1510
+ ...(words && own !== tripKey(session, config.brand) ? { conversation: own } : {}),
1211
1511
  });
1212
1512
  // The guest's own details beside the answer, never in it - see `guestsApart`.
1213
1513
  const { shown, guests } = guestsApart(answer.structured);
@@ -1215,9 +1515,15 @@ export const buildServer = (opts) => {
1215
1515
  const { shown: unnamed, who } = memberApart(shown);
1216
1516
  // And the city field's menu - see `CITIES_META_KEY`.
1217
1517
  const { allCities, ...drawn } = unnamed;
1518
+ const told = said(answer.text, drawn);
1519
+ // ⚠️ AND NO PICTURE SENT AS ITSELF, FOR ANY HOST (0.67.0, 总线程 11-12): the
1520
+ // card's CSP would have to name `data:` in `resourceDomains`, which hosts put
1521
+ // in script-src too - and ChatGPT's widgetCSP would change. The backend's
1522
+ // pictures are https now (`imageHosts`); a `data:` one is not drawn.
1523
+ const { shown: pictured } = picturesApart(told.structured, false);
1218
1524
  return ok(c, id, {
1219
- content: [{ type: 'text', text: answer.text }],
1220
- structuredContent: drawn,
1525
+ content: [{ type: 'text', text: told.text }],
1526
+ structuredContent: pictured,
1221
1527
  ...(answer.isError ? { isError: true } : {}),
1222
1528
  // Beside the answer, not inside it: the card needs the trip to badge
1223
1529
  // its header, and the model needs no such list - handing it one is
@@ -1276,18 +1582,87 @@ export const buildServer = (opts) => {
1276
1582
  const printable = (s, max) => s.replace(/[^\x20-\x7e]/g, '?').slice(0, max);
1277
1583
  /** An id as 8 characters of its SHA-256 - the same fingerprint the account's lines use (account/index.ts `tag`). */
1278
1584
  const h8 = (s) => createHash('sha256').update(s).digest('base64url').slice(0, 8);
1585
+ /** `request_*_booking` where an account's details fill what the guest leaves out - see `TOOLS`. */
1586
+ const profiledBooking = (t) => {
1587
+ const schema = t.inputSchema;
1588
+ const props = { ...(schema.properties ?? {}) };
1589
+ const said = (k, words) => {
1590
+ const p = props[k];
1591
+ if (p)
1592
+ props[k] = { ...p, description: `${p.description ?? ''}. ${words}` };
1593
+ };
1594
+ said('name', "Left out: the signed-in account's name, where it has one");
1595
+ said('email', "Left out: the signed-in account's email");
1596
+ said('phone', "Left out: the signed-in account's phone, where it has one");
1597
+ const { required: _was, ...rest } = schema;
1598
+ return { ...t, inputSchema: { ...rest, properties: props } };
1599
+ };
1600
+ /**
1601
+ * The line every answer to a client that draws no card ends with, once its
1602
+ * conversation has an id (0.67.0): the id, and that every later call passes it.
1603
+ * In `structuredContent` too, the same words (`conversation`): a host may hand
1604
+ * its model that rather than the text.
1605
+ */
1606
+ export const conversationSaid = (id) => `This conversation: trip="${id}". Pass trip="${id}" on every later call to these tools - the app may reconnect between turns, and that id is how the next call finds this conversation's trip, sign-in and bookings.`;
1607
+ const conversationOf = (id) => ({ trip: id, said: conversationSaid(id) });
1608
+ /** A new connection's look at what its conversation holds, naming no trip: it holds nothing yet (0.67.0). */
1609
+ export const NEW_CONNECTION_SAID = "This connection is new and holds nothing yet. If an earlier answer in this chat gave a trip id, call again with it as trip: that is how this conversation's trip, sign-in and bookings are found.";
1610
+ /** What an answer to a client that draws no card says beside its own words - see `conversationSaid`. */
1611
+ const inWordsOf = (text, structured, id, fresh, expired = false) => {
1612
+ const told = inWordsOf0(text, structured, id, fresh);
1613
+ return expired
1614
+ ? {
1615
+ text: `${EXPIRED_SAID}\n\n${told.text}`,
1616
+ structured: {
1617
+ ...told.structured,
1618
+ conversation: {
1619
+ ...(told.structured.conversation ?? {}),
1620
+ expired: true,
1621
+ expiredSaid: EXPIRED_SAID,
1622
+ },
1623
+ },
1624
+ }
1625
+ : told;
1626
+ };
1627
+ /** A trip id whose conversation was quiet too long to be taken over (0.67.1). */
1628
+ export const EXPIRED_SAID = 'The trip id passed names a conversation not used for more than 30 minutes, so it was not picked up: this is a new conversation, and nothing of the earlier one - its trip, sign-in or bookings - carries over. The guest signs in again if they need to.';
1629
+ /** Another app naming a conversation (0.67.1). */
1630
+ const otherAppSaid = 'Nothing was done: that trip id names a conversation of another app. Call again without trip to start a conversation here.';
1631
+ /** A connection whose conversation another connection has taken over (0.67.1). */
1632
+ const movedSaid = 'Nothing was done: this conversation has been picked up on another connection, and is reached there alone now. Call again without trip to start a new conversation here.';
1633
+ const inWordsOf0 = (text, structured, id, fresh) => id
1634
+ ? {
1635
+ text: `${text}\n\n${conversationSaid(id)}`,
1636
+ structured: { ...structured, conversation: conversationOf(id) },
1637
+ }
1638
+ : fresh
1639
+ ? {
1640
+ text: `${text}\n\n${NEW_CONNECTION_SAID}`,
1641
+ structured: { ...structured, conversation: { new: true, said: NEW_CONNECTION_SAID } },
1642
+ }
1643
+ : { text, structured };
1644
+ /** A trip id that names nothing, to a client that draws no card (0.67.0). `mine`: this connection's own, if it has one. */
1645
+ const tripLostSaid = (mine) => mine
1646
+ ? `Nothing was done: no conversation here goes by that trip id. This connection's conversation is trip="${mine}" - pass that one.`
1647
+ : `Nothing was done: no conversation here goes by that trip id - it may be mistyped, from another chat, or unused for ${ID_TTL_MS / 86_400_000} days. Call again without trip: that starts a new conversation, and nothing from before carries over to it.`;
1648
+ /** Another conversation's id, from a connection that has its own (0.67.0). */
1649
+ const notCarriedSaid = (mine) => `Nothing was done: this connection already has its conversation${mine ? `, trip="${mine}",` : ''} and acts on no other - a trip id that did not come from this conversation's own answers is not followed.${mine ? ` Pass trip="${mine}".` : ''}`;
1279
1650
  /**
1280
- * The headers a request came with - their NAMES, sorted, never a value - and
1281
- * its user-agent as it is (diagnostics, 0.56.1: is there a conversation id a
1282
- * host sends, as ChatGPT's x-openai-session?). Addresses and cookies are named
1283
- * only.
1651
+ * The headers a request came with - their NAMES, sorted, never a value
1652
+ * (diagnostics, 0.56.1: is there a conversation id a host sends, as ChatGPT's
1653
+ * x-openai-session?). Addresses, cookies and the user-agent are named only:
1654
+ * since 0.67.0 no value at all (总线程 11-11).
1284
1655
  */
1285
1656
  const headerNames = (c) => {
1286
1657
  const names = Object.keys(c.req.header())
1287
1658
  .map((n) => n.toLowerCase())
1288
1659
  .sort();
1289
- return `headers=[${printable(names.join(','), 400)}] ua=${printable(c.req.header('user-agent') ?? '-', 80)}`;
1660
+ return `headers=[${printable(names.join(','), 600)}]`;
1290
1661
  };
1662
+ /** Times each app's header names are logged at `initialize`, and at `tools/call` (0.67.0). */
1663
+ export const HEADER_LOGS_PER_APP = 5;
1664
+ /** Apps whose header names are logged at all, by where - past it, a new name is not (0.67.0). */
1665
+ export const HEADER_APPS = 200;
1291
1666
  export const clientIp = (header) => {
1292
1667
  const last = (header ?? '').split(',').at(-1)?.trim();
1293
1668
  return last || undefined;