@0xmaxma/claude-gateway 2.1.13 → 2.1.15

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 (78) 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 +57 -32
  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/orchestration/bridge.d.ts +2 -0
  41. package/dist/orchestration/bridge.d.ts.map +1 -1
  42. package/dist/orchestration/bridge.js +54 -14
  43. package/dist/orchestration/bridge.js.map +1 -1
  44. package/dist/orchestration/runtime.d.ts +2 -0
  45. package/dist/orchestration/runtime.d.ts.map +1 -1
  46. package/dist/orchestration/runtime.js +2 -2
  47. package/dist/orchestration/runtime.js.map +1 -1
  48. package/dist/orchestration/tasks/driver.d.ts.map +1 -1
  49. package/dist/orchestration/tasks/driver.js +4 -0
  50. package/dist/orchestration/tasks/driver.js.map +1 -1
  51. package/dist/orchestration/tasks/service.d.ts +3 -0
  52. package/dist/orchestration/tasks/service.d.ts.map +1 -1
  53. package/dist/orchestration/tasks/service.js +24 -3
  54. package/dist/orchestration/tasks/service.js.map +1 -1
  55. package/dist/orchestration/token-ledger.d.ts +6 -0
  56. package/dist/orchestration/token-ledger.d.ts.map +1 -1
  57. package/dist/orchestration/token-ledger.js +2 -1
  58. package/dist/orchestration/token-ledger.js.map +1 -1
  59. package/dist/orchestration/types.d.ts +4 -0
  60. package/dist/orchestration/types.d.ts.map +1 -1
  61. package/dist/orchestration/types.js.map +1 -1
  62. package/dist/packages/npm-staging.d.ts +55 -0
  63. package/dist/packages/npm-staging.d.ts.map +1 -0
  64. package/dist/packages/npm-staging.js +349 -0
  65. package/dist/packages/npm-staging.js.map +1 -0
  66. package/dist/packages/registry.d.ts +24 -10
  67. package/dist/packages/registry.d.ts.map +1 -1
  68. package/dist/packages/registry.js +125 -66
  69. package/dist/packages/registry.js.map +1 -1
  70. package/dist/types.d.ts +12 -3
  71. package/dist/types.d.ts.map +1 -1
  72. package/mcp/tools/telegram/callback-failure.ts +94 -0
  73. package/mcp/tools/telegram/model-menu-request.ts +4 -1
  74. package/mcp/tools/telegram/receiver-server.ts +107 -95
  75. package/mcp/tools/telegram/session-browser.ts +18 -2
  76. package/mcp/tools/telegram/session-list.ts +82 -0
  77. package/mcp/tools/telegram/task-browser.ts +12 -5
  78. package/package.json +1 -1
@@ -48,6 +48,8 @@ const channel_input_media_1 = require("../orchestration/channel-input-media");
48
48
  const chunks_1 = require("../telegram/chunks");
49
49
  const file_delivery_1 = require("../orchestration/file-delivery");
50
50
  const voice_reply_policy_1 = require("../orchestration/voice-reply-policy");
51
+ const types_1 = require("../orchestration/types");
52
+ const redact_1 = require("../cli/redact");
51
53
  const gateway_config_1 = require("../orchestration/gateway-config");
52
54
  const delivery_1 = require("../orchestration/delivery");
53
55
  const control_delivery_1 = require("../orchestration/control-delivery");
@@ -96,7 +98,7 @@ const screen_1 = require("../shell/screen");
96
98
  const db_1 = require("../history/db");
97
99
  const media_store_1 = require("../history/media-store");
98
100
  const cleanup_1 = require("../history/cleanup");
99
- const types_1 = require("../history/types");
101
+ const types_2 = require("../history/types");
100
102
  const skill_learning_1 = require("./skill-learning");
101
103
  const knowledge_1 = require("./knowledge");
102
104
  const resolve_1 = require("../connectors/resolve");
@@ -1044,7 +1046,7 @@ class AgentRunner extends events_1.EventEmitter {
1044
1046
  // turned every WeChat (and, historically, Slack) message into
1045
1047
  // 'telegram' before, since a new channel added elsewhere is easy to
1046
1048
  // forget adding to a chain of `=== 'x' ? 'x' : ...` checks.
1047
- const channelSource = ((0, types_1.isChatChannel)(meta['source']) ? meta['source'] : 'telegram');
1049
+ const channelSource = ((0, types_2.isChatChannel)(meta['source']) ? meta['source'] : 'telegram');
1048
1050
  this.channelSourceMap.set(chatId, channelSource);
1049
1051
  const channelOrchestration = this.orchestration?.ownsChannel(channelSource, chatId) || (this.agentConfig.orchestration?.enabled && (this.agentConfig.orchestration.channels ?? ['api']).includes(channelSource));
1050
1052
  // Resolve a receiver receipt before fetching media again: an ACK may have
@@ -1654,8 +1656,12 @@ class AgentRunner extends events_1.EventEmitter {
1654
1656
  respond({ success: true, ...menu, text: (0, stop_controls_1.stopMenuText)(menu, true) });
1655
1657
  }
1656
1658
  }
1657
- catch {
1658
- respond({ success: false, error: 'Selection unavailable. Use /stop to refresh the task list.' });
1659
+ catch (error) {
1660
+ // An expired or replaced menu is expected; anything else is a real failure.
1661
+ const code = error instanceof types_1.OrchestrationError ? error.code : undefined;
1662
+ if (code !== 'STOP_MENU_EXPIRED')
1663
+ this.logger.warn('Telegram task_stop failed', { code, error: error instanceof Error ? error.name : typeof error, message: (0, redact_1.redactLine)(String(error instanceof Error ? error.message : error)).replace(/https?:\/\/\S+/g, '[url]').slice(0, 160) });
1664
+ respond({ success: false, error: 'Selection unavailable. Use /stop to refresh the task list.', ...(code ? { code } : {}) });
1659
1665
  }
1660
1666
  return;
1661
1667
  }
@@ -1716,23 +1722,17 @@ class AgentRunner extends events_1.EventEmitter {
1716
1722
  }
1717
1723
  if (command === 'get_models') {
1718
1724
  // Live catalog first, static list as the fallback (issue #409). The
1719
- // picker is a UI action, so a slow or unreachable catalog must not hang
1720
- // it — fetchModelCatalog is bounded and never rejects.
1721
- void this.availableModels()
1722
- .then((availableModels) => {
1723
- const configuredIds = new Set((this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).map(m => m.id));
1724
- const configured = availableModels.filter(m => configuredIds.has(m.id));
1725
- const live = availableModels.filter(m => !configuredIds.has(m.id));
1726
- respond({
1727
- models: availableModels.map(m => ({ id: m.id, label: m.label })),
1728
- configuredModels: configured.map(m => ({ id: m.id, label: m.label })),
1729
- liveModels: live.map(m => ({ id: m.id, label: m.label })),
1730
- });
1731
- })
1732
- // Without this the request would hang and the picker with it: the
1733
- // receiver is blocked on this response. Every other async branch in
1734
- // this handler answers on rejection too.
1735
- .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
+ });
1736
1736
  return;
1737
1737
  }
1738
1738
  // `/cli` webview terminal viewer — create a pairing on behalf of an
@@ -3249,11 +3249,11 @@ class AgentRunner extends events_1.EventEmitter {
3249
3249
  this.writeAutoForward(chatId, 'Use /models in a direct message with the bot to view available models.');
3250
3250
  return;
3251
3251
  }
3252
- 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);
3253
3253
  }
3254
3254
  /** The /models list: configured models, then live-only ones, each marked when current. */
3255
- async modelList(switchHint) {
3256
- const models = await this.availableModels();
3255
+ modelList(switchHint) {
3256
+ const models = this.availableModelsNow();
3257
3257
  const configuredIds = new Set((this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).map(m => m.id));
3258
3258
  const configured = models.filter(m => configuredIds.has(m.id));
3259
3259
  const live = models.filter(m => !configuredIds.has(m.id));
@@ -3294,6 +3294,8 @@ class AgentRunner extends events_1.EventEmitter {
3294
3294
  async pstackSetupText() {
3295
3295
  return (0, menu_1.pstackMenuText)(await this.pstackMenuState(), PSTACK_SETUP_USAGE);
3296
3296
  }
3297
+ // Awaits the catalog: the menu validates taps against this list, and its
3298
+ // receiver allows 20 s, well over the catalog deadline.
3297
3299
  async pstackMenuState() {
3298
3300
  const plugin = (0, plugin_info_1.pstackPluginInfo)();
3299
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 };
@@ -3433,10 +3435,13 @@ class AgentRunner extends events_1.EventEmitter {
3433
3435
  }
3434
3436
  if (!context)
3435
3437
  return { contextUsedPct: null, contextTokens: null, contextWindow: null, contextModel: null, text: '—' };
3436
- 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;
3437
3442
  const pct = total && total > 0 ? Math.round(context.used / total * 100) : null;
3438
3443
  const format = (n) => n >= 1000000 ? `${Number((n / 1000000).toFixed(2))}M` : n >= 1000 ? `${Number((n / 1000).toFixed(2))}K` : String(n);
3439
- return { contextUsedPct: pct, contextTokens: context.used, contextWindow: total, contextModel: context.model,
3444
+ return { contextUsedPct: pct, contextTokens: context.used, contextWindow: total, contextModel: model,
3440
3445
  text: `${format(context.used)} / ${total == null ? '—' : format(total)}${pct == null ? '' : ` · ${pct}%`}` };
3441
3446
  }
3442
3447
  async handleCommandSessionInfo(agentId, chatId) {
@@ -4138,6 +4143,9 @@ class AgentRunner extends events_1.EventEmitter {
4138
4143
  await this.sweepStaleSessionDirs();
4139
4144
  await this.sessionOwners();
4140
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);
4141
4149
  if (this.agentConfig.telegram?.botToken) {
4142
4150
  this.receiver = new receiver_1.TelegramReceiver(this.agentConfig, this.callbackPort, this.gatewayConfig.gateway.logDir, this.gatewayConfig.gateway.headless !== false);
4143
4151
  this.receiver.start();
@@ -4761,11 +4769,19 @@ class AgentRunner extends events_1.EventEmitter {
4761
4769
  maxWorkers: this.agentConfig.orchestration?.tasks?.maxConcurrentPerAgent ?? config_2.ORCHESTRATION_DEFAULTS.tasks.maxConcurrentPerAgent,
4762
4770
  idleTtlMs: this.agentConfig.orchestration?.tasks?.workerIdleTtlMs ?? config_2.ORCHESTRATION_DEFAULTS.tasks.workerIdleTtlMs };
4763
4771
  }
4764
- async dashboardContextWindow(model) {
4765
- const models = await this.availableModels();
4766
- return models.find(m => m.id === model)?.contextWindow
4767
- ?? (this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).find(m => m.id === model)?.contextWindow
4768
- ?? 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;
4769
4785
  }
4770
4786
  getTokenReport(sessionId) {
4771
4787
  const report = this.orchestration?.tokenReport(sessionId);
@@ -5791,7 +5807,7 @@ class AgentRunner extends events_1.EventEmitter {
5791
5807
  ({ result, responseText } = await contextCommand(chosen));
5792
5808
  }
5793
5809
  else if (cmd === '/models') {
5794
- 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.');
5795
5811
  result = { model: this.agentConfig.claude.model, models: list.models };
5796
5812
  responseText = list.text;
5797
5813
  }
@@ -6020,6 +6036,10 @@ class AgentRunner extends events_1.EventEmitter {
6020
6036
  availableModels() {
6021
6037
  return (0, model_registry_2.availableModels)(this.gatewayConfig.gateway.models);
6022
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
+ }
6023
6043
  /**
6024
6044
  * Context window for a model id. Resolving this through the live catalog is
6025
6045
  * what keeps `/session`'s "context used" percentage and `/compact`'s window
@@ -6027,6 +6047,11 @@ class AgentRunner extends events_1.EventEmitter {
6027
6047
  * through to the 200k default no matter how large its real window.
6028
6048
  */
6029
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;
6030
6055
  const models = await this.availableModels();
6031
6056
  // Configured list second, not just as the catalog's fallback: the catalog
6032
6057
  // *replaces* the list rather than merging with it, so a configured model