@essentialai/cogent-bridge-bundled 3.21.0 → 3.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/cogent-bridge.mjs +80 -24
  2. package/package.json +1 -1
package/cogent-bridge.mjs CHANGED
@@ -26389,8 +26389,8 @@ var init_stdio2 = __esm({
26389
26389
  // src/constants.ts
26390
26390
  import { createRequire } from "node:module";
26391
26391
  function resolveVersion() {
26392
- if ("3.21.0") {
26393
- return "3.21.0";
26392
+ if ("3.21.2") {
26393
+ return "3.21.2";
26394
26394
  }
26395
26395
  try {
26396
26396
  const require2 = createRequire(import.meta.url);
@@ -34253,9 +34253,13 @@ __export(startup_exports, {
34253
34253
  cloudHttpClient: () => cloudHttpClient,
34254
34254
  cloudInbox: () => cloudInbox,
34255
34255
  cloudWsClient: () => cloudWsClient,
34256
+ hasPendingLabelResolve: () => hasPendingLabelResolve,
34257
+ isCloudMode: () => isCloudMode2,
34256
34258
  reinitCloudBackend: () => reinitCloudBackend,
34259
+ resolvePendingLabel: () => resolvePendingLabel,
34257
34260
  runPreflights: () => runPreflights,
34258
34261
  runStartup: () => runStartup,
34262
+ setInboxNotifier: () => setInboxNotifier,
34259
34263
  triggerReRegistration: () => triggerReRegistration
34260
34264
  });
34261
34265
  import os10 from "node:os";
@@ -34264,6 +34268,18 @@ import fs14 from "node:fs/promises";
34264
34268
  import readline2 from "node:readline";
34265
34269
  import { execFile as execFile5 } from "node:child_process";
34266
34270
  import { promisify as promisify4 } from "node:util";
34271
+ function isCloudMode2() {
34272
+ return cloudModeActive;
34273
+ }
34274
+ function setInboxNotifier(fn) {
34275
+ inboxNotifier = fn;
34276
+ bindInboxNotifier();
34277
+ }
34278
+ function bindInboxNotifier() {
34279
+ if (!inboxNotifier || !cloudInbox || notifierBoundTo === cloudInbox) return;
34280
+ cloudInbox.onNewMessage(inboxNotifier);
34281
+ notifierBoundTo = cloudInbox;
34282
+ }
34267
34283
  async function loadPersistedConfig() {
34268
34284
  try {
34269
34285
  const raw = await fs14.readFile(PERSIST_PATH, "utf-8");
@@ -34427,6 +34443,46 @@ function createCloudWsClient(endpoint, sessionId, token, http, inbox, pollInterv
34427
34443
  });
34428
34444
  return client;
34429
34445
  }
34446
+ function hasPendingLabelResolve() {
34447
+ return pendingLabelResolve !== null;
34448
+ }
34449
+ async function resolvePendingLabel() {
34450
+ const pending = pendingLabelResolve;
34451
+ pendingLabelResolve = null;
34452
+ if (!pending) return;
34453
+ let resolvedId;
34454
+ try {
34455
+ const resp = await fetch(
34456
+ `${pending.endpoint}/api/sessions/resolve/${encodeURIComponent(pending.label)}`,
34457
+ { signal: AbortSignal.timeout(2500) }
34458
+ );
34459
+ if (!resp.ok) {
34460
+ logger.warn(
34461
+ `Failed to resolve session label "${pending.label}": HTTP ${resp.status}. Staying in deferred mode \u2014 use cogent_join_session.`
34462
+ );
34463
+ return;
34464
+ }
34465
+ resolvedId = (await resp.json()).sessionId;
34466
+ } catch (err) {
34467
+ logger.warn(
34468
+ `Failed to resolve session label "${pending.label}": ${err}. Staying in deferred mode \u2014 use cogent_join_session.`
34469
+ );
34470
+ return;
34471
+ }
34472
+ logger.info(`Resolved session label "${pending.label}" to UUID ${resolvedId}`);
34473
+ try {
34474
+ const persisted = await loadCredentials();
34475
+ if (persisted && persisted.sessionId === resolvedId && persisted.endpoint === pending.endpoint) {
34476
+ await reinitCloudBackend(pending.endpoint, resolvedId, persisted.token);
34477
+ } else {
34478
+ logger.info(
34479
+ `No persisted token for session ${resolvedId}; staying deferred until cogent_join_session provides one.`
34480
+ );
34481
+ }
34482
+ } catch (err) {
34483
+ logger.warn(`Post-connect label upgrade failed (non-fatal): ${err}`);
34484
+ }
34485
+ }
34430
34486
  async function reinitCloudBackend(endpoint, sessionId, token) {
34431
34487
  const config2 = getConfig();
34432
34488
  cloudHttpClient = new HttpClient(endpoint, token);
@@ -34442,6 +34498,7 @@ async function reinitCloudBackend(endpoint, sessionId, token) {
34442
34498
  if (!cloudInbox) {
34443
34499
  cloudInbox = new MessageInbox();
34444
34500
  }
34501
+ bindInboxNotifier();
34445
34502
  cloudWsClient = createCloudWsClient(
34446
34503
  endpoint,
34447
34504
  sessionId,
@@ -34473,6 +34530,7 @@ async function runStartup() {
34473
34530
  let effectiveToken;
34474
34531
  const effectiveEndpoint = config2.COGENT_ENDPOINT;
34475
34532
  const isCloud = effectiveEndpoint && isCloudEndpoint(effectiveEndpoint);
34533
+ cloudModeActive = Boolean(isCloud);
34476
34534
  if (isCloud && effectiveSessionId && !UUID_V4_RE.test(effectiveSessionId)) {
34477
34535
  const persisted = await loadCredentials();
34478
34536
  if (persisted && persisted.label === effectiveSessionId && persisted.endpoint === effectiveEndpoint) {
@@ -34480,23 +34538,8 @@ async function runStartup() {
34480
34538
  effectiveSessionId = persisted.sessionId;
34481
34539
  effectiveToken = persisted.token;
34482
34540
  } else {
34483
- try {
34484
- const resolveResp = await fetch(
34485
- `${effectiveEndpoint}/api/sessions/resolve/${encodeURIComponent(effectiveSessionId)}`,
34486
- { signal: AbortSignal.timeout(2500) }
34487
- );
34488
- if (resolveResp.ok) {
34489
- const resolved = await resolveResp.json();
34490
- logger.info(`Resolved session label "${effectiveSessionId}" to UUID ${resolved.sessionId}`);
34491
- effectiveSessionId = resolved.sessionId;
34492
- } else {
34493
- logger.warn(`Failed to resolve session label "${effectiveSessionId}": HTTP ${resolveResp.status}. Entering deferred mode.`);
34494
- effectiveSessionId = void 0;
34495
- }
34496
- } catch (err) {
34497
- logger.warn(`Failed to resolve session label: ${err}. Entering deferred mode.`);
34498
- effectiveSessionId = void 0;
34499
- }
34541
+ pendingLabelResolve = { label: effectiveSessionId, endpoint: effectiveEndpoint };
34542
+ effectiveSessionId = void 0;
34500
34543
  }
34501
34544
  }
34502
34545
  if (isCloud) {
@@ -34544,6 +34587,7 @@ async function runStartup() {
34544
34587
  );
34545
34588
  if (isCloud && effectiveSessionId && effectiveToken) {
34546
34589
  cloudInbox = new MessageInbox();
34590
+ bindInboxNotifier();
34547
34591
  cloudHttpClient = new HttpClient(effectiveEndpoint, effectiveToken);
34548
34592
  cloudWsClient = createCloudWsClient(
34549
34593
  effectiveEndpoint,
@@ -34579,7 +34623,7 @@ async function runPreflights() {
34579
34623
  await preflightClaude(config2.COGENT_CLAUDE_PATH);
34580
34624
  }
34581
34625
  }
34582
- var UUID_V4_RE, execFileAsync3, PERSIST_PATH, legacyWarnEmitted, cloudWsClient, cloudInbox, cloudHttpClient, reRegistrationInProgress;
34626
+ var UUID_V4_RE, execFileAsync3, PERSIST_PATH, legacyWarnEmitted, cloudWsClient, cloudInbox, cloudHttpClient, cloudModeActive, inboxNotifier, notifierBoundTo, reRegistrationInProgress, pendingLabelResolve;
34583
34627
  var init_startup = __esm({
34584
34628
  "src/startup.ts"() {
34585
34629
  "use strict";
@@ -34606,7 +34650,11 @@ var init_startup = __esm({
34606
34650
  cloudWsClient = null;
34607
34651
  cloudInbox = null;
34608
34652
  cloudHttpClient = null;
34653
+ cloudModeActive = false;
34654
+ inboxNotifier = null;
34655
+ notifierBoundTo = null;
34609
34656
  reRegistrationInProgress = false;
34657
+ pendingLabelResolve = null;
34610
34658
  }
34611
34659
  });
34612
34660
 
@@ -36806,7 +36854,7 @@ async function main() {
36806
36854
  registerSendMailTool(server);
36807
36855
  registerFetchMailTool(server);
36808
36856
  registerRotateMailCredsTool(server);
36809
- if (cloudInbox) {
36857
+ if (isCloudMode2()) {
36810
36858
  server.registerResource(
36811
36859
  "cogent_inbox",
36812
36860
  "cogent://inbox",
@@ -36814,18 +36862,21 @@ async function main() {
36814
36862
  description: "Incoming messages received via cloud bridge WebSocket. Read this resource to see new messages from other peers.",
36815
36863
  mimeType: "application/json"
36816
36864
  },
36865
+ // Read the inbox LAZILY: in deferred mode it does not exist yet and is
36866
+ // created later by reinitCloudBackend(). An empty inbox is the honest
36867
+ // answer for "connected to cloud, no session joined yet".
36817
36868
  async (uri) => ({
36818
36869
  contents: [{
36819
36870
  uri: uri.href,
36820
36871
  mimeType: "application/json",
36821
36872
  text: JSON.stringify({
36822
- messages: cloudInbox.getUnread(),
36823
- lastMessageId: cloudInbox.getLastMessageId()
36873
+ messages: cloudInbox ? cloudInbox.getUnread() : [],
36874
+ lastMessageId: cloudInbox ? cloudInbox.getLastMessageId() : null
36824
36875
  })
36825
36876
  }]
36826
36877
  })
36827
36878
  );
36828
- cloudInbox.onNewMessage(() => {
36879
+ setInboxNotifier(() => {
36829
36880
  try {
36830
36881
  server.server.sendResourceUpdated({ uri: "cogent://inbox" });
36831
36882
  } catch (err) {
@@ -36839,6 +36890,11 @@ async function main() {
36839
36890
  `${SERVER_NAME} v${SERVER_VERSION} running on stdio
36840
36891
  `
36841
36892
  );
36893
+ void resolvePendingLabel().catch((err) => {
36894
+ logger.warn(
36895
+ `Label resolve error (non-fatal): ${err instanceof Error ? err.message : String(err)}`
36896
+ );
36897
+ });
36842
36898
  void runPreflights().catch((err) => {
36843
36899
  logger.warn(
36844
36900
  `Preflight error (non-fatal): ${err instanceof Error ? err.message : String(err)}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@essentialai/cogent-bridge-bundled",
3
- "version": "3.21.0",
3
+ "version": "3.21.2",
4
4
  "description": "Zero-dependency, pre-bundled Cogent MCP bridge — a single self-contained file for fast cold `npx` startup (used by the Codex plugin, whose MCP startup window is short). Functionally identical to @essentialai/cogent-bridge; carries no npm dependencies so `npx` skips dependency install.",
5
5
  "type": "module",
6
6
  "bin": {