@0xmaxma/claude-gateway 2.1.14 โ†’ 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 (77) 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 +47 -28
  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 +10 -4
  73. package/mcp/tools/telegram/model-menu-request.ts +4 -1
  74. package/mcp/tools/telegram/receiver-server.ts +47 -53
  75. package/mcp/tools/telegram/session-list.ts +82 -0
  76. package/mcp/tools/telegram/task-browser.ts +2 -1
  77. package/package.json +1 -1
@@ -0,0 +1,82 @@
1
+ import { InlineKeyboard } from 'grammy'
2
+ import { CallbackHttpError, callbackRejection } from './callback-failure'
3
+
4
+ export type SessionListEntry = { id: string; name: string; messageCount: number; lastActive: number }
5
+
6
+ /** Sessions shown per /sessions page. Each costs up to two buttons, so a page
7
+ * stays far below Telegram's 100-button limit on one inline keyboard. */
8
+ export const SESSIONS_PER_PAGE = 8
9
+ /** Telegram caps callback_data at 64 UTF-8 bytes. */
10
+ const MAX_DATA_BYTES = 64
11
+
12
+ const fits = (data: string) => Buffer.byteLength(data, 'utf8') <= MAX_DATA_BYTES
13
+ // Cut on code points: a split surrogate pair is invalid UTF-8 and Telegram
14
+ // rejects the whole message. An empty button label is rejected too.
15
+ const clip = (value: string, max: number) => {
16
+ const chars = [...value.replace(/\s+/g, ' ').trim()]
17
+ return chars.length > max ? chars.slice(0, max - 1).join('') + 'โ€ฆ' : chars.join('') || 'Untitled'
18
+ }
19
+
20
+ function age(now: number, lastActive: number): string {
21
+ const minutes = Math.max(0, Math.round((now - lastActive) / 60000))
22
+ return minutes < 60 ? `${minutes}m ago` : `${Math.round(minutes / 60)}h ago`
23
+ }
24
+
25
+ /** Builds one page of the /sessions menu, newest first. `page` is clamped, so a
26
+ * stale Prev/Next button after a delete still lands on a real page. */
27
+ export function sessionListMenu(sessions: SessionListEntry[], activeId: string, page: number, now = Date.now()): { text: string; reply_markup: InlineKeyboard; page: number; pages: number } {
28
+ // A session whose callback would exceed 64 bytes cannot be switched to or
29
+ // deleted from a button, so it is listed in the count but never sent as one.
30
+ // Each tap re-reads the list, so a session active between taps moves to page 1.
31
+ const sorted = [...sessions].sort((a, b) => b.lastActive - a.lastActive || a.id.localeCompare(b.id))
32
+ const pages = Math.max(1, Math.ceil(sorted.length / SESSIONS_PER_PAGE))
33
+ const current = Math.min(Math.max(0, Number.isInteger(page) ? page : 0), pages - 1)
34
+ const shown = sorted.slice(current * SESSIONS_PER_PAGE, (current + 1) * SESSIONS_PER_PAGE)
35
+
36
+ const keyboard = new InlineKeyboard()
37
+ for (const s of shown) {
38
+ const switchData = `session_switch:${s.id}`
39
+ if (!fits(switchData)) continue
40
+ const label = s.id === activeId ? `๐ŸŸข ${clip(s.name, 38)}` : clip(s.name, 40)
41
+ keyboard.text(label, switchData)
42
+ if (sorted.length > 1 && fits(`session_delete_confirm:${s.id}`)) keyboard.text('๐Ÿ—‘', `session_delete:${s.id}`)
43
+ keyboard.row()
44
+ }
45
+ if (current > 0) keyboard.text('โ€น Prev', `session_page:${current - 1}`)
46
+ if (current + 1 < pages) keyboard.text('Next โ€บ', `session_page:${current + 1}`)
47
+ if (pages > 1) keyboard.row()
48
+ keyboard.text('โž• New Session', 'session_new').row()
49
+ keyboard.text('Dismiss', 'session_back')
50
+
51
+ const lines = [`๐Ÿ—‚ Sessions (${sorted.length})${pages > 1 ? ` ยท Page ${current + 1}/${pages}` : ''}`, '']
52
+ for (const s of shown) {
53
+ lines.push(`${s.id === activeId ? '๐ŸŸข' : 'โšช'} ${clip(s.name, 60)} ยท ${s.messageCount} msgs ยท ${age(now, s.lastActive)}`)
54
+ }
55
+ lines.push('', 'Tap a session to switch, ๐Ÿ—‘ to delete')
56
+ return { text: lines.join('\n'), reply_markup: keyboard, page: current, pages }
57
+ }
58
+
59
+ /** Reads the chat's sessions from the agent (`list_sessions`). Throws with the
60
+ * HTTP status or the agent's reason so the failure log keeps the cause. */
61
+ export async function listSessionsRequest(base: string | undefined, chatId: string, timeoutMs = 10000): Promise<{ sessions: SessionListEntry[]; activeId: string }> {
62
+ if (!base) throw Error('not_configured')
63
+ const response = await fetch(base + '/command', {
64
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, signal: AbortSignal.timeout(timeoutMs),
65
+ body: JSON.stringify({ command: 'list_sessions', chat_id: chatId }),
66
+ })
67
+ const result = await response.json().catch(error => { throw response.ok ? error : new CallbackHttpError(response.status) }) as { success?: boolean; sessions?: unknown; activeSessionId?: unknown } | null
68
+ if (!response.ok) throw new CallbackHttpError(response.status, result)
69
+ // A successful list_sessions reply carries `sessions` and no `success` flag.
70
+ if (result?.success === false || !Array.isArray(result?.sessions)) throw callbackRejection(result)
71
+ // Only the id is needed to switch or delete; the other fields are display-only,
72
+ // so a row missing them is still listed (an unnamed one shows as Untitled).
73
+ const rows = result.sessions as Array<Partial<SessionListEntry> | null>
74
+ const sessions = rows.filter(s => typeof s?.id === 'string' && s.id !== '').map(s => ({
75
+ id: s!.id!,
76
+ name: typeof s!.name === 'string' ? s!.name : '',
77
+ messageCount: Number.isFinite(s!.messageCount) ? s!.messageCount! : 0,
78
+ lastActive: Number.isFinite(s!.lastActive) ? s!.lastActive! : 0,
79
+ }))
80
+ if (sessions.length < rows.length) process.stderr.write(`telegram channel: /sessions skipped ${rows.length - sessions.length} session row(s) without an id\n`)
81
+ return { sessions, activeId: typeof result.activeSessionId === 'string' ? result.activeSessionId : '' }
82
+ }
@@ -26,7 +26,8 @@ interface Dependencies {
26
26
  }
27
27
  const description = (e: any) => String(e?.description ?? e?.message ?? '');
28
28
  const absent = (e: any) => /message to (?:edit|delete) not found|message_id_invalid/i.test(description(e));
29
- const unchanged = (e: any) => /message is not modified/i.test(description(e));
29
+ /** Telegram refused an edit because the message already shows this content. */
30
+ export const unchanged = (e: any) => /message is not modified/i.test(description(e));
30
31
  export class LiveTaskBrowser {
31
32
  private entries = new Map<string, Entry>();
32
33
  private locks = new Map<string, Promise<unknown>>();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmaxma/claude-gateway",
3
- "version": "2.1.14",
3
+ "version": "2.1.15",
4
4
  "description": "Multi-agent gateway for Claude",
5
5
  "repository": {
6
6
  "type": "git",