@0xmaxma/claude-gateway 1.4.9 → 1.5.0
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.
- package/README.md +24 -1
- package/config.template.json +1 -0
- package/dist/agent/runner.d.ts +14 -0
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +59 -0
- package/dist/agent/runner.js.map +1 -1
- package/dist/api/gateway-router.d.ts +20 -0
- package/dist/api/gateway-router.d.ts.map +1 -1
- package/dist/api/gateway-router.js +214 -0
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/line-webhook-router.d.ts +5 -0
- package/dist/api/line-webhook-router.d.ts.map +1 -1
- package/dist/api/line-webhook-router.js +63 -0
- package/dist/api/line-webhook-router.js.map +1 -1
- package/dist/apps/agent-manager.d.ts.map +1 -1
- package/dist/apps/agent-manager.js +14 -0
- package/dist/apps/agent-manager.js.map +1 -1
- package/dist/cli-viewer/pairing-store.d.ts +117 -0
- package/dist/cli-viewer/pairing-store.d.ts.map +1 -0
- package/dist/cli-viewer/pairing-store.js +196 -0
- package/dist/cli-viewer/pairing-store.js.map +1 -0
- package/dist/cli-viewer/telegram-initdata.d.ts +21 -0
- package/dist/cli-viewer/telegram-initdata.d.ts.map +1 -0
- package/dist/cli-viewer/telegram-initdata.js +74 -0
- package/dist/cli-viewer/telegram-initdata.js.map +1 -0
- package/dist/cli-viewer/url.d.ts +13 -0
- package/dist/cli-viewer/url.d.ts.map +1 -0
- package/dist/cli-viewer/url.js +27 -0
- package/dist/cli-viewer/url.js.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/cli-viewer-ui.d.ts +37 -0
- package/dist/ui/cli-viewer-ui.d.ts.map +1 -0
- package/dist/ui/cli-viewer-ui.js +274 -0
- package/dist/ui/cli-viewer-ui.js.map +1 -0
- package/mcp/tools/discord/module.ts +99 -1
- package/mcp/tools/telegram/receiver-server.ts +41 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ A self-hosted multi-agent gateway for Claude Code. Connect Claude agents to Tele
|
|
|
29
29
|
- **App Store** — install, update, and host Docker-compose apps on the gateway; apps get a reverse proxy at `/app/:name/:portName/*`, optional Unix socket bridge for host scripts, and optional AI agent injection
|
|
30
30
|
- **Self-update API** — check for newer versions of `claude-gateway` and `claude-code` and trigger an update via a single API call; no SSH or shell access needed
|
|
31
31
|
- **Session persistence** — conversation history saved and restored across restarts
|
|
32
|
-
- **PTY shell (wrap-shell mode)** — optional interactive pseudo-terminal backend (`gateway.headless: false`) for tools that require a real TTY; includes a live browser viewer (xterm.js) and a `/api/v1/sessions/:sessionId/screen` endpoint that returns the visible screen as plain text — agents can poll it to detect hang states, menus, or unexpected output without parsing ANSI escape codes; app-agents always stay headless
|
|
32
|
+
- **PTY shell (wrap-shell mode)** — optional interactive pseudo-terminal backend (`gateway.headless: false`) for tools that require a real TTY; includes a live browser viewer (xterm.js) and a `/api/v1/sessions/:sessionId/screen` endpoint that returns the visible screen as plain text — agents can poll it to detect hang states, menus, or unexpected output without parsing ANSI escape codes; a `/cli` chat command (Telegram/Discord/LINE) opens the same viewer for a single agent, agent-scoped and without an admin key; app-agents always stay headless
|
|
33
33
|
|
|
34
34
|
---
|
|
35
35
|
|
|
@@ -346,6 +346,18 @@ Network interface the HTTP/WebSocket server binds to. Defaults to `127.0.0.1` (l
|
|
|
346
346
|
|
|
347
347
|
> **⚠️ Upgrade note:** the default bind changed from `0.0.0.0` to `127.0.0.1` (configVersion 1.0.13). To avoid silently cutting off external access, the config migrator is **behavior-preserving**: whenever it upgrades a config that never set `gateway.bind`, it pins `bind` to `0.0.0.0` and logs a one-time warning, so a deployment that was reachable from another host stays reachable. This applies to *any* upgraded config with no `bind` key — including one already stamped `1.0.13` that never received a bind (an earlier version gated this on `< 1.0.13` and left such configs stuck on the `127.0.0.1` default). New installs (no prior config, so no migration runs) keep the secure `127.0.0.1` default. If you *want* localhost-only after upgrading, set `gateway.bind` to `127.0.0.1` explicitly (or the `GATEWAY_BIND` env var).
|
|
348
348
|
|
|
349
|
+
### `gateway.publicUrl`
|
|
350
|
+
|
|
351
|
+
Absolute, externally-reachable origin of the gateway (for example `https://gateway.example.com`, or `https://host.example.com/gateway` behind an ingress path prefix). The process cannot infer its own public URL — it binds localhost by default and sits behind a reverse proxy — so it must be set explicitly for features that hand out a phone-openable link. Currently that is the `/cli` terminal viewer; when `publicUrl` is unset, `/cli` replies that the viewer is not configured. Leave it blank to keep `/cli` disabled. A trailing slash is optional. Use an `https://` origin — Telegram Mini Apps require HTTPS.
|
|
352
|
+
|
|
353
|
+
```json
|
|
354
|
+
{
|
|
355
|
+
"gateway": {
|
|
356
|
+
"publicUrl": "https://gateway.example.com"
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
349
361
|
### Terminal Viewer — interactive terminal mode
|
|
350
362
|
|
|
351
363
|
The dashboard's **Terminal Viewer** opens read-only (a live mirror of the PTY). A toggle in the top-right of the viewer switches it into an **interactive terminal**: keystrokes typed into the panel — printable characters, Enter, arrows, Ctrl-combos, Esc — are streamed into the live PTY, and the panel title changes to reflect the active mode. This is a per-browser client-side choice (Issue #201); there is no server config flag to enable it.
|
|
@@ -357,6 +369,17 @@ Because interactive mode turns a read-only view into a remote-write surface, acc
|
|
|
357
369
|
|
|
358
370
|
Inbound frames are always bounded (text-only, size-capped) and are dropped for headless sessions (no PTY).
|
|
359
371
|
|
|
372
|
+
#### `/cli` — open the terminal viewer from chat
|
|
373
|
+
|
|
374
|
+
The `/cli` command (Telegram, Discord, LINE) opens the same live terminal viewer for **one agent**, without an admin key. It requires `gateway.publicUrl` and an agent running with `gateway.headless: false`. Unlike the admin dashboard, a `/cli` session is **agent-scoped**: its cookie and PTY ticket can only reach the originating agent's own sessions — never another agent, the process tree, or a cross-agent stream.
|
|
375
|
+
|
|
376
|
+
The viewer link is never a credential; unlocking it requires a proof tied to an allowlist-gated chat action:
|
|
377
|
+
|
|
378
|
+
- **Telegram** opens a Mini App and the gateway verifies Telegram's signed `initData` (HMAC with the agent's own bot token) — nothing secret rides in the URL, and the `initData` user must match the user who ran `/cli`.
|
|
379
|
+
- **Discord** and **LINE** send an open-viewer link plus an **Approve** button; the browser stays locked until you approve in the chat, so a leaked or forwarded link cannot be unlocked by anyone who cannot approve there.
|
|
380
|
+
|
|
381
|
+
The first browser to open a link owns it (opening the link in a second browser is rejected), the viewer defaults to read-only (toggle for input), and viewer sessions expire (30 min) — send `/cli` again to reconnect.
|
|
382
|
+
|
|
360
383
|
### `gateway.api.keys`
|
|
361
384
|
|
|
362
385
|
Each key has a `key` string (supports `${ENV_VAR}` interpolation), an optional `description`, and an `agents` field — either an array of agent IDs or `"*"` for full access. Keys support both `Authorization: Bearer` and `X-Api-Key` headers.
|
package/config.template.json
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"logDir": "~/.claude-gateway/logs",
|
|
16
16
|
"timezone": "Asia/Bangkok",
|
|
17
17
|
"bind": "127.0.0.1",
|
|
18
|
+
"publicUrl": "",
|
|
18
19
|
"models": [
|
|
19
20
|
{ "id": "claude-fable-5[1m]", "label": "Fable 5 (1M)", "alias": "fable[1m]", "contextWindow": 1000000 },
|
|
20
21
|
{ "id": "claude-opus-5[1m]", "label": "Opus 5 (1M)", "alias": "opus[1m]", "contextWindow": 1000000 },
|
package/dist/agent/runner.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import { AgentConfig, GatewayConfig, Logger, ModelConfig, StreamEvent, ApiAttachment, ImageParams } from '../types';
|
|
3
3
|
import { type SkillRegistry } from '../skills';
|
|
4
|
+
import { type CliChannel } from '../cli-viewer/pairing-store';
|
|
4
5
|
import { HistoryDB } from '../history/db';
|
|
5
6
|
export declare const MAX_IMAGE_SIZE_BYTES: number;
|
|
6
7
|
export declare const DEFAULT_MODELS: ModelConfig[];
|
|
@@ -111,6 +112,19 @@ export declare class AgentRunner extends EventEmitter {
|
|
|
111
112
|
* invoked when autoRecover is enabled.
|
|
112
113
|
*/
|
|
113
114
|
private recoveryTriageSpawn;
|
|
115
|
+
/**
|
|
116
|
+
* Create a `/cli` webview pairing for an already-authenticated chat user.
|
|
117
|
+
* Shared by the receiver callback (Telegram/Discord subprocesses) and the
|
|
118
|
+
* in-process LINE webhook so both mint links the same way. Returns null when
|
|
119
|
+
* `gateway.publicUrl` is not configured (no link can be built).
|
|
120
|
+
*/
|
|
121
|
+
createCliPairing(channel: CliChannel, userId: string): {
|
|
122
|
+
pairingId: string;
|
|
123
|
+
code: string;
|
|
124
|
+
url: string;
|
|
125
|
+
} | null;
|
|
126
|
+
/** Approve (or deny) a `/cli` pairing on behalf of the authenticated chat user. */
|
|
127
|
+
approveCliPairing(channel: CliChannel, pairingId: string, userId: string, deny?: boolean): 'ok' | 'mismatch' | 'gone';
|
|
114
128
|
/**
|
|
115
129
|
* Handle POST /command requests from the receiver process.
|
|
116
130
|
* Supports: get_model, set_model, restart.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/agent/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMtC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAW,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAS7H,OAAO,EAA0C,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/agent/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMtC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,EAAW,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC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M,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAmB7F,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAW5I,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWxE;;;;OAIG;IACG,oBAAoB,CACxB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,EACxC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,SAAS,EAAE;QACT,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;QACtC,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;QACnC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;KAC/B,EACD,IAAI,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAC1B,OAAO,CAAC,MAAM,IAAI,CAAC;IAiItB,OAAO,CAAC,iBAAiB;IA2CzB;;;OAGG;IACH,eAAe,IAAI,MAAM;IAIzB;;;;;;OAMG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAoBnC"}
|
package/dist/agent/runner.js
CHANGED
|
@@ -55,6 +55,8 @@ const recovery_executor_1 = require("./recovery-executor");
|
|
|
55
55
|
const recovery_policy_1 = require("./recovery-policy");
|
|
56
56
|
const incident_1 = require("./incident");
|
|
57
57
|
const pty_stream_registry_1 = require("../shell/pty-stream-registry");
|
|
58
|
+
const pairing_store_1 = require("../cli-viewer/pairing-store");
|
|
59
|
+
const url_1 = require("../cli-viewer/url");
|
|
58
60
|
const screen_1 = require("../shell/screen");
|
|
59
61
|
const db_1 = require("../history/db");
|
|
60
62
|
const media_store_1 = require("../history/media-store");
|
|
@@ -575,6 +577,26 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
575
577
|
this.recoveryBudgets.delete(key);
|
|
576
578
|
}
|
|
577
579
|
}
|
|
580
|
+
/**
|
|
581
|
+
* Create a `/cli` webview pairing for an already-authenticated chat user.
|
|
582
|
+
* Shared by the receiver callback (Telegram/Discord subprocesses) and the
|
|
583
|
+
* in-process LINE webhook so both mint links the same way. Returns null when
|
|
584
|
+
* `gateway.publicUrl` is not configured (no link can be built).
|
|
585
|
+
*/
|
|
586
|
+
createCliPairing(channel, userId) {
|
|
587
|
+
if (!(0, pairing_store_1.isCliChannel)(channel) || !userId)
|
|
588
|
+
return null;
|
|
589
|
+
if (!(0, url_1.buildCliUrl)(this.gatewayConfig.gateway.publicUrl, 'probe'))
|
|
590
|
+
return null;
|
|
591
|
+
const { pairingId, code } = pairing_store_1.cliPairingStore.create(this.agentConfig.id, channel, userId);
|
|
592
|
+
return { pairingId, code, url: (0, url_1.buildCliUrl)(this.gatewayConfig.gateway.publicUrl, pairingId) };
|
|
593
|
+
}
|
|
594
|
+
/** Approve (or deny) a `/cli` pairing on behalf of the authenticated chat user. */
|
|
595
|
+
approveCliPairing(channel, pairingId, userId, deny = false) {
|
|
596
|
+
return deny
|
|
597
|
+
? pairing_store_1.cliPairingStore.deny(pairingId, channel, userId)
|
|
598
|
+
: pairing_store_1.cliPairingStore.approve(pairingId, channel, userId);
|
|
599
|
+
}
|
|
578
600
|
/**
|
|
579
601
|
* Handle POST /command requests from the receiver process.
|
|
580
602
|
* Supports: get_model, set_model, restart.
|
|
@@ -602,6 +624,43 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
602
624
|
respond({ models: availableModels.map(m => ({ id: m.id, label: m.label })) });
|
|
603
625
|
return;
|
|
604
626
|
}
|
|
627
|
+
// `/cli` webview terminal viewer — create a pairing on behalf of an
|
|
628
|
+
// already-authenticated chat user. The channel receiver has verified the
|
|
629
|
+
// user against its allowlist before calling this; we bind the pairing to that
|
|
630
|
+
// (channel, user) so only that same user can approve it or (Telegram) match
|
|
631
|
+
// its initData. The browser-facing routes live on the gateway; here we only
|
|
632
|
+
// mint the pairing and hand back the phone-openable link.
|
|
633
|
+
if (command === 'cli_pair') {
|
|
634
|
+
const payload = body.payload ?? {};
|
|
635
|
+
const channel = payload['channel'];
|
|
636
|
+
const userId = typeof payload['user_id'] === 'string' ? payload['user_id'] : '';
|
|
637
|
+
if (!(0, pairing_store_1.isCliChannel)(channel) || !userId) {
|
|
638
|
+
respond({ success: false, error: 'invalid_request' }, 400);
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
const pairing = this.createCliPairing(channel, userId);
|
|
642
|
+
if (!pairing) {
|
|
643
|
+
respond({ success: false, error: 'not_configured' });
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
respond({ success: true, ...pairing });
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
// `/cli` approve/deny — the authenticated chat user acted on the pairing.
|
|
650
|
+
if (command === 'cli_approve') {
|
|
651
|
+
const payload = body.payload ?? {};
|
|
652
|
+
const channel = payload['channel'];
|
|
653
|
+
const pairingId = typeof payload['pairing_id'] === 'string' ? payload['pairing_id'] : '';
|
|
654
|
+
const userId = typeof payload['user_id'] === 'string' ? payload['user_id'] : '';
|
|
655
|
+
const deny = payload['deny'] === true;
|
|
656
|
+
if (!(0, pairing_store_1.isCliChannel)(channel) || !pairingId || !userId) {
|
|
657
|
+
respond({ success: false, error: 'invalid_request' }, 400);
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
const result = this.approveCliPairing(channel, pairingId, userId, deny);
|
|
661
|
+
respond({ success: result === 'ok', result });
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
605
664
|
if (command === 'set_model') {
|
|
606
665
|
const newModel = typeof body.payload?.model === 'string' ? body.payload.model : '';
|
|
607
666
|
try {
|