@0xmaxma/claude-gateway 2.1.14 → 2.1.16

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 (107) hide show
  1. package/dist/agent/model-catalog.d.ts +10 -0
  2. package/dist/agent/model-catalog.d.ts.map +1 -1
  3. package/dist/agent/model-catalog.js +93 -25
  4. package/dist/agent/model-catalog.js.map +1 -1
  5. package/dist/agent/model-registry.d.ts +15 -0
  6. package/dist/agent/model-registry.d.ts.map +1 -1
  7. package/dist/agent/model-registry.js +26 -0
  8. package/dist/agent/model-registry.js.map +1 -1
  9. package/dist/agent/runner.d.ts +5 -1
  10. package/dist/agent/runner.d.ts.map +1 -1
  11. package/dist/agent/runner.js +48 -29
  12. package/dist/agent/runner.js.map +1 -1
  13. package/dist/api/gateway-router.js +2 -2
  14. package/dist/api/gateway-router.js.map +1 -1
  15. package/dist/api/packages.d.ts.map +1 -1
  16. package/dist/api/packages.js +12 -11
  17. package/dist/api/packages.js.map +1 -1
  18. package/dist/api/router.d.ts.map +1 -1
  19. package/dist/api/router.js +9 -7
  20. package/dist/api/router.js.map +1 -1
  21. package/dist/build-provenance.json +4 -4
  22. package/dist/cli/commands/update.d.ts.map +1 -1
  23. package/dist/cli/commands/update.js +18 -7
  24. package/dist/cli/commands/update.js.map +1 -1
  25. package/dist/cron/manager.d.ts.map +1 -1
  26. package/dist/cron/manager.js +6 -3
  27. package/dist/cron/manager.js.map +1 -1
  28. package/dist/cron/scheduler.d.ts +1 -0
  29. package/dist/cron/scheduler.d.ts.map +1 -1
  30. package/dist/cron/scheduler.js +76 -5
  31. package/dist/cron/scheduler.js.map +1 -1
  32. package/dist/cron/validate.d.ts +10 -0
  33. package/dist/cron/validate.d.ts.map +1 -0
  34. package/dist/cron/validate.js +37 -0
  35. package/dist/cron/validate.js.map +1 -0
  36. package/dist/heartbeat/parser.d.ts +12 -3
  37. package/dist/heartbeat/parser.d.ts.map +1 -1
  38. package/dist/heartbeat/parser.js +35 -97
  39. package/dist/heartbeat/parser.js.map +1 -1
  40. package/dist/history/types.d.ts +1 -1
  41. package/dist/history/types.js +1 -1
  42. package/dist/orchestration/agent-cli-session.d.ts +58 -6
  43. package/dist/orchestration/agent-cli-session.d.ts.map +1 -1
  44. package/dist/orchestration/agent-cli-session.js +207 -27
  45. package/dist/orchestration/agent-cli-session.js.map +1 -1
  46. package/dist/orchestration/bridge.d.ts +2 -0
  47. package/dist/orchestration/bridge.d.ts.map +1 -1
  48. package/dist/orchestration/bridge.js +54 -14
  49. package/dist/orchestration/bridge.js.map +1 -1
  50. package/dist/orchestration/context-delivery.d.ts +2 -0
  51. package/dist/orchestration/context-delivery.d.ts.map +1 -1
  52. package/dist/orchestration/context-delivery.js +8 -0
  53. package/dist/orchestration/context-delivery.js.map +1 -1
  54. package/dist/orchestration/gateway-tasks/computer.d.ts +2 -0
  55. package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
  56. package/dist/orchestration/gateway-tasks/computer.js +4 -2
  57. package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
  58. package/dist/orchestration/input-images.d.ts +4 -0
  59. package/dist/orchestration/input-images.d.ts.map +1 -1
  60. package/dist/orchestration/input-images.js +28 -0
  61. package/dist/orchestration/input-images.js.map +1 -1
  62. package/dist/orchestration/runtime.d.ts +5 -0
  63. package/dist/orchestration/runtime.d.ts.map +1 -1
  64. package/dist/orchestration/runtime.js +105 -46
  65. package/dist/orchestration/runtime.js.map +1 -1
  66. package/dist/orchestration/session-compaction.d.ts.map +1 -1
  67. package/dist/orchestration/session-compaction.js +16 -6
  68. package/dist/orchestration/session-compaction.js.map +1 -1
  69. package/dist/orchestration/tasks/driver.d.ts.map +1 -1
  70. package/dist/orchestration/tasks/driver.js +12 -1
  71. package/dist/orchestration/tasks/driver.js.map +1 -1
  72. package/dist/orchestration/tasks/pool.d.ts +3 -2
  73. package/dist/orchestration/tasks/pool.d.ts.map +1 -1
  74. package/dist/orchestration/tasks/pool.js +4 -3
  75. package/dist/orchestration/tasks/pool.js.map +1 -1
  76. package/dist/orchestration/tasks/service.d.ts +3 -0
  77. package/dist/orchestration/tasks/service.d.ts.map +1 -1
  78. package/dist/orchestration/tasks/service.js +24 -3
  79. package/dist/orchestration/tasks/service.js.map +1 -1
  80. package/dist/orchestration/token-ledger.d.ts +6 -0
  81. package/dist/orchestration/token-ledger.d.ts.map +1 -1
  82. package/dist/orchestration/token-ledger.js +2 -1
  83. package/dist/orchestration/token-ledger.js.map +1 -1
  84. package/dist/orchestration/types.d.ts +4 -0
  85. package/dist/orchestration/types.d.ts.map +1 -1
  86. package/dist/orchestration/types.js.map +1 -1
  87. package/dist/packages/npm-staging.d.ts +55 -0
  88. package/dist/packages/npm-staging.d.ts.map +1 -0
  89. package/dist/packages/npm-staging.js +349 -0
  90. package/dist/packages/npm-staging.js.map +1 -0
  91. package/dist/packages/registry.d.ts +24 -10
  92. package/dist/packages/registry.d.ts.map +1 -1
  93. package/dist/packages/registry.js +125 -66
  94. package/dist/packages/registry.js.map +1 -1
  95. package/dist/types.d.ts +12 -3
  96. package/dist/types.d.ts.map +1 -1
  97. package/dist/ui/memory-activity.js +1 -1
  98. package/mcp/tools/telegram/callback-failure.ts +10 -4
  99. package/mcp/tools/telegram/model-menu-request.ts +4 -1
  100. package/mcp/tools/telegram/receiver-server.ts +47 -53
  101. package/mcp/tools/telegram/session-list.ts +82 -0
  102. package/mcp/tools/telegram/task-browser.ts +2 -1
  103. package/package.json +1 -1
  104. package/dist/session/compactor.d.ts +0 -53
  105. package/dist/session/compactor.d.ts.map +0 -1
  106. package/dist/session/compactor.js +0 -274
  107. package/dist/session/compactor.js.map +0 -1
@@ -1722,23 +1722,17 @@ class AgentRunner extends events_1.EventEmitter {
1722
1722
  }
1723
1723
  if (command === 'get_models') {
1724
1724
  // Live catalog first, static list as the fallback (issue #409). The
1725
- // picker is a UI action, so a slow or unreachable catalog must not hang
1726
- // it — fetchModelCatalog is bounded and never rejects.
1727
- void this.availableModels()
1728
- .then((availableModels) => {
1729
- const configuredIds = new Set((this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).map(m => m.id));
1730
- const configured = availableModels.filter(m => configuredIds.has(m.id));
1731
- const live = availableModels.filter(m => !configuredIds.has(m.id));
1732
- respond({
1733
- models: availableModels.map(m => ({ id: m.id, label: m.label })),
1734
- configuredModels: configured.map(m => ({ id: m.id, label: m.label })),
1735
- liveModels: live.map(m => ({ id: m.id, label: m.label })),
1736
- });
1737
- })
1738
- // Without this the request would hang and the picker with it: the
1739
- // receiver is blocked on this response. Every other async branch in
1740
- // this handler answers on rejection too.
1741
- .catch((err) => respond({ success: false, error: String(err) }, 500));
1725
+ // picker is a UI action, so it reads the cached catalog and never waits
1726
+ // on the fetch: the receiver gives this callback 10 s.
1727
+ const availableModels = this.availableModelsNow();
1728
+ const configuredIds = new Set((this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).map(m => m.id));
1729
+ const configured = availableModels.filter(m => configuredIds.has(m.id));
1730
+ const live = availableModels.filter(m => !configuredIds.has(m.id));
1731
+ respond({
1732
+ models: availableModels.map(m => ({ id: m.id, label: m.label })),
1733
+ configuredModels: configured.map(m => ({ id: m.id, label: m.label })),
1734
+ liveModels: live.map(m => ({ id: m.id, label: m.label })),
1735
+ });
1742
1736
  return;
1743
1737
  }
1744
1738
  // `/cli` webview terminal viewer — create a pairing on behalf of an
@@ -3255,11 +3249,11 @@ class AgentRunner extends events_1.EventEmitter {
3255
3249
  this.writeAutoForward(chatId, 'Use /models in a direct message with the bot to view available models.');
3256
3250
  return;
3257
3251
  }
3258
- this.writeAutoForward(chatId, (await this.modelList('Switch with /model <id or alias>')).text);
3252
+ this.writeAutoForward(chatId, this.modelList('Switch with /model <id or alias>').text);
3259
3253
  }
3260
3254
  /** The /models list: configured models, then live-only ones, each marked when current. */
3261
- async modelList(switchHint) {
3262
- const models = await this.availableModels();
3255
+ modelList(switchHint) {
3256
+ const models = this.availableModelsNow();
3263
3257
  const configuredIds = new Set((this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).map(m => m.id));
3264
3258
  const configured = models.filter(m => configuredIds.has(m.id));
3265
3259
  const live = models.filter(m => !configuredIds.has(m.id));
@@ -3300,6 +3294,8 @@ class AgentRunner extends events_1.EventEmitter {
3300
3294
  async pstackSetupText() {
3301
3295
  return (0, menu_1.pstackMenuText)(await this.pstackMenuState(), PSTACK_SETUP_USAGE);
3302
3296
  }
3297
+ // Awaits the catalog: the menu validates taps against this list, and its
3298
+ // receiver allows 20 s, well over the catalog deadline.
3303
3299
  async pstackMenuState() {
3304
3300
  const plugin = (0, plugin_info_1.pstackPluginInfo)();
3305
3301
  return { block: this.agentConfig.pstack, plugin: plugin.installPath ? (0, plugin_info_1.pstackModels)(plugin.installPath) : undefined, models: await this.availableModels(), installHint: plugin_info_1.PSTACK_INSTALL_HINT };
@@ -3439,10 +3435,13 @@ class AgentRunner extends events_1.EventEmitter {
3439
3435
  }
3440
3436
  if (!context)
3441
3437
  return { contextUsedPct: null, contextTokens: null, contextWindow: null, contextModel: null, text: '—' };
3442
- const total = context.model ? await this.dashboardContextWindow(context.model) : null;
3438
+ // The turn's own configured model; a legacy measurement has none and ran on the agent default.
3439
+ const configured = 'configuredModel' in context ? context.configuredModel : undefined;
3440
+ const model = context.model ? (0, model_registry_2.contextModelId)(context.model, configured ?? this.agentConfig.claude.model) : null;
3441
+ const total = context.model ? this.dashboardContextWindow(context.model, configured) : null;
3443
3442
  const pct = total && total > 0 ? Math.round(context.used / total * 100) : null;
3444
3443
  const format = (n) => n >= 1000000 ? `${Number((n / 1000000).toFixed(2))}M` : n >= 1000 ? `${Number((n / 1000).toFixed(2))}K` : String(n);
3445
- return { contextUsedPct: pct, contextTokens: context.used, contextWindow: total, contextModel: context.model,
3444
+ return { contextUsedPct: pct, contextTokens: context.used, contextWindow: total, contextModel: model,
3446
3445
  text: `${format(context.used)} / ${total == null ? '—' : format(total)}${pct == null ? '' : ` · ${pct}%`}` };
3447
3446
  }
3448
3447
  async handleCommandSessionInfo(agentId, chatId) {
@@ -4144,6 +4143,9 @@ class AgentRunner extends events_1.EventEmitter {
4144
4143
  await this.sweepStaleSessionDirs();
4145
4144
  await this.sessionOwners();
4146
4145
  await this.startCallbackServer();
4146
+ // Status and listing commands read the cached catalog without waiting on
4147
+ // it, so fetch it now rather than on the first /models after a restart.
4148
+ (0, model_registry_2.prefetchModelCatalog)(this.gatewayConfig.gateway.models);
4147
4149
  if (this.agentConfig.telegram?.botToken) {
4148
4150
  this.receiver = new receiver_1.TelegramReceiver(this.agentConfig, this.callbackPort, this.gatewayConfig.gateway.logDir, this.gatewayConfig.gateway.headless !== false);
4149
4151
  this.receiver.start();
@@ -4767,11 +4769,19 @@ class AgentRunner extends events_1.EventEmitter {
4767
4769
  maxWorkers: this.agentConfig.orchestration?.tasks?.maxConcurrentPerAgent ?? config_2.ORCHESTRATION_DEFAULTS.tasks.maxConcurrentPerAgent,
4768
4770
  idleTtlMs: this.agentConfig.orchestration?.tasks?.workerIdleTtlMs ?? config_2.ORCHESTRATION_DEFAULTS.tasks.workerIdleTtlMs };
4769
4771
  }
4770
- async dashboardContextWindow(model) {
4771
- const models = await this.availableModels();
4772
- return models.find(m => m.id === model)?.contextWindow
4773
- ?? (this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).find(m => m.id === model)?.contextWindow
4774
- ?? null;
4772
+ /** Never waits on the catalog fetch: `/session` and the dashboard only display this. */
4773
+ dashboardContextWindow(measured, configured = this.agentConfig.claude.model) {
4774
+ const lists = [this.availableModelsNow(), this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS];
4775
+ // The configured `[1m]` row first, then the measured id itself: a configured
4776
+ // suffix no list describes (`[200k]`) must still find the base model's window.
4777
+ for (const id of new Set([(0, model_registry_2.contextModelId)(measured, configured), measured])) {
4778
+ for (const list of lists) {
4779
+ const window = list.find(m => m.id === id)?.contextWindow;
4780
+ if (window !== undefined)
4781
+ return window;
4782
+ }
4783
+ }
4784
+ return null;
4775
4785
  }
4776
4786
  getTokenReport(sessionId) {
4777
4787
  const report = this.orchestration?.tokenReport(sessionId);
@@ -5797,7 +5807,7 @@ class AgentRunner extends events_1.EventEmitter {
5797
5807
  ({ result, responseText } = await contextCommand(chosen));
5798
5808
  }
5799
5809
  else if (cmd === '/models') {
5800
- const list = await this.modelList('Change the model with the model picker or PUT /api/v1/agents/:agentId/model.');
5810
+ const list = this.modelList('Change the model with the model picker or PUT /api/v1/agents/:agentId/model.');
5801
5811
  result = { model: this.agentConfig.claude.model, models: list.models };
5802
5812
  responseText = list.text;
5803
5813
  }
@@ -6026,6 +6036,10 @@ class AgentRunner extends events_1.EventEmitter {
6026
6036
  availableModels() {
6027
6037
  return (0, model_registry_2.availableModels)(this.gatewayConfig.gateway.models);
6028
6038
  }
6039
+ /** The cached catalog or the configured list, for paths that must not wait on the fetch. */
6040
+ availableModelsNow() {
6041
+ return (0, model_registry_2.availableModelsNow)(this.gatewayConfig.gateway.models);
6042
+ }
6029
6043
  /**
6030
6044
  * Context window for a model id. Resolving this through the live catalog is
6031
6045
  * what keeps `/session`'s "context used" percentage and `/compact`'s window
@@ -6033,13 +6047,18 @@ class AgentRunner extends events_1.EventEmitter {
6033
6047
  * through to the 200k default no matter how large its real window.
6034
6048
  */
6035
6049
  async contextWindowFor(modelId, requireKnown = false) {
6050
+ // Waits on the catalog only for a model the cache and the configured list
6051
+ // do not describe; a configured model must not hold /compact behind a hung fetch.
6052
+ const cached = this.availableModelsNow().find((m) => m.id === modelId)?.contextWindow;
6053
+ if (cached !== undefined)
6054
+ return cached;
6036
6055
  const models = await this.availableModels();
6037
6056
  // Configured list second, not just as the catalog's fallback: the catalog
6038
6057
  // *replaces* the list rather than merging with it, so a configured model
6039
6058
  // the upstream catalog does not list (the local `[1m]` ids are exactly
6040
6059
  // that shape) would otherwise drop to the 200k default — reporting
6041
6060
  // /session context use against a fifth of the real window and handing
6042
- // SessionCompactor a window small enough to compact far too early.
6061
+ // nightly session compaction a window small enough to compact far too early.
6043
6062
  return models.find((m) => m.id === modelId)?.contextWindow
6044
6063
  ?? (this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).find((m) => m.id === modelId)?.contextWindow
6045
6064
  ?? (requireKnown ? 0 : model_catalog_1.DEFAULT_CONTEXT_WINDOW);