@0xmaxma/claude-gateway 2.0.20 → 2.0.21
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 +1 -0
- package/config.template.json +3 -2
- package/dist/agent/builtin-commands.d.ts +4 -0
- package/dist/agent/builtin-commands.d.ts.map +1 -1
- package/dist/agent/builtin-commands.js +11 -4
- package/dist/agent/builtin-commands.js.map +1 -1
- package/dist/agent/command-help.d.ts +11 -2
- package/dist/agent/command-help.d.ts.map +1 -1
- package/dist/agent/command-help.js +27 -8
- package/dist/agent/command-help.js.map +1 -1
- package/dist/agent/model-registry.d.ts +48 -0
- package/dist/agent/model-registry.d.ts.map +1 -0
- package/dist/agent/model-registry.js +144 -0
- package/dist/agent/model-registry.js.map +1 -0
- package/dist/agent/runner.d.ts +60 -42
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +304 -113
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session-confirmations.d.ts +1 -1
- package/dist/agent/session-confirmations.d.ts.map +1 -1
- package/dist/agent/session-confirmations.js +5 -3
- package/dist/agent/session-confirmations.js.map +1 -1
- package/dist/agent/skill-learning/reviewer.d.ts.map +1 -1
- package/dist/agent/skill-learning/reviewer.js +2 -1
- package/dist/agent/skill-learning/reviewer.js.map +1 -1
- package/dist/agent/turn-stream.d.ts +2 -1
- package/dist/agent/turn-stream.d.ts.map +1 -1
- package/dist/agent/turn-stream.js.map +1 -1
- package/dist/api/gateway-router.d.ts.map +1 -1
- package/dist/api/gateway-router.js +4 -0
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/manifest-sources.d.ts.map +1 -1
- package/dist/api/manifest-sources.js +3 -0
- package/dist/api/manifest-sources.js.map +1 -1
- package/dist/api/pstack-router.d.ts +14 -0
- package/dist/api/pstack-router.d.ts.map +1 -0
- package/dist/api/pstack-router.js +93 -0
- package/dist/api/pstack-router.js.map +1 -0
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +29 -24
- package/dist/api/router.js.map +1 -1
- package/dist/automation/computer-use.d.ts.map +1 -1
- package/dist/automation/computer-use.js +8 -1
- package/dist/automation/computer-use.js.map +1 -1
- package/dist/build-provenance.json +4 -4
- package/dist/cli/commands.generated.d.ts.map +1 -1
- package/dist/cli/commands.generated.js +36 -1
- package/dist/cli/commands.generated.js.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +7 -0
- package/dist/config/loader.js.map +1 -1
- package/dist/config/reload-policy.js +1 -1
- package/dist/config/reload-policy.js.map +1 -1
- package/dist/config/watcher.d.ts.map +1 -1
- package/dist/config/watcher.js +2 -0
- package/dist/config/watcher.js.map +1 -1
- package/dist/orchestration/agent-tool-schemas.js +1 -1
- package/dist/orchestration/agent-tool-schemas.js.map +1 -1
- package/dist/orchestration/bridge.d.ts +6 -2
- package/dist/orchestration/bridge.d.ts.map +1 -1
- package/dist/orchestration/bridge.js +120 -5
- package/dist/orchestration/bridge.js.map +1 -1
- package/dist/orchestration/capabilities.d.ts.map +1 -1
- package/dist/orchestration/capabilities.js +10 -3
- package/dist/orchestration/capabilities.js.map +1 -1
- package/dist/orchestration/capacity.d.ts +9 -2
- package/dist/orchestration/capacity.d.ts.map +1 -1
- package/dist/orchestration/capacity.js +18 -7
- package/dist/orchestration/capacity.js.map +1 -1
- package/dist/orchestration/cli-skills.d.ts.map +1 -1
- package/dist/orchestration/cli-skills.js +4 -2
- package/dist/orchestration/cli-skills.js.map +1 -1
- package/dist/orchestration/config.d.ts +17 -0
- package/dist/orchestration/config.d.ts.map +1 -1
- package/dist/orchestration/config.js +21 -1
- package/dist/orchestration/config.js.map +1 -1
- package/dist/orchestration/dashboard-reader-worker.js +5 -3
- package/dist/orchestration/dashboard-reader-worker.js.map +1 -1
- package/dist/orchestration/decisions.d.ts.map +1 -1
- package/dist/orchestration/decisions.js +4 -2
- package/dist/orchestration/decisions.js.map +1 -1
- package/dist/orchestration/delivery.d.ts.map +1 -1
- package/dist/orchestration/delivery.js +1 -0
- package/dist/orchestration/delivery.js.map +1 -1
- package/dist/orchestration/gateway-tasks/computer.d.ts +2 -0
- package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
- package/dist/orchestration/gateway-tasks/computer.js +68 -28
- package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
- package/dist/orchestration/gateway-tasks/controller.d.ts +6 -6
- package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -1
- package/dist/orchestration/input-batch.d.ts +8 -2
- package/dist/orchestration/input-batch.d.ts.map +1 -1
- package/dist/orchestration/input-batch.js +28 -8
- package/dist/orchestration/input-batch.js.map +1 -1
- package/dist/orchestration/mutation-recovery.js +1 -1
- package/dist/orchestration/mutation-recovery.js.map +1 -1
- package/dist/orchestration/notification-mailbox.d.ts.map +1 -1
- package/dist/orchestration/notification-mailbox.js +4 -2
- package/dist/orchestration/notification-mailbox.js.map +1 -1
- package/dist/orchestration/process-turn.d.ts +6 -1
- package/dist/orchestration/process-turn.d.ts.map +1 -1
- package/dist/orchestration/process-turn.js +9 -5
- package/dist/orchestration/process-turn.js.map +1 -1
- package/dist/orchestration/recovery.d.ts.map +1 -1
- package/dist/orchestration/recovery.js +21 -0
- package/dist/orchestration/recovery.js.map +1 -1
- package/dist/orchestration/response-errors.d.ts +5 -0
- package/dist/orchestration/response-errors.d.ts.map +1 -1
- package/dist/orchestration/response-errors.js +25 -0
- package/dist/orchestration/response-errors.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +15 -1
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +148 -29
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/speech.d.ts +3 -0
- package/dist/orchestration/speech.d.ts.map +1 -1
- package/dist/orchestration/speech.js +4 -1
- package/dist/orchestration/speech.js.map +1 -1
- package/dist/orchestration/store.d.ts +5 -0
- package/dist/orchestration/store.d.ts.map +1 -1
- package/dist/orchestration/store.js +13 -5
- package/dist/orchestration/store.js.map +1 -1
- package/dist/orchestration/subagent-tool-schemas.d.ts +12 -0
- package/dist/orchestration/subagent-tool-schemas.d.ts.map +1 -0
- package/dist/orchestration/subagent-tool-schemas.js +23 -0
- package/dist/orchestration/subagent-tool-schemas.js.map +1 -0
- package/dist/orchestration/task-controls.d.ts.map +1 -1
- package/dist/orchestration/task-controls.js +2 -1
- package/dist/orchestration/task-controls.js.map +1 -1
- package/dist/orchestration/task-questions.d.ts.map +1 -1
- package/dist/orchestration/task-questions.js +3 -1
- package/dist/orchestration/task-questions.js.map +1 -1
- package/dist/orchestration/tasks/automation-session.d.ts +12 -0
- package/dist/orchestration/tasks/automation-session.d.ts.map +1 -1
- package/dist/orchestration/tasks/automation-session.js +26 -1
- package/dist/orchestration/tasks/automation-session.js.map +1 -1
- package/dist/orchestration/tasks/driver.d.ts.map +1 -1
- package/dist/orchestration/tasks/driver.js +54 -14
- package/dist/orchestration/tasks/driver.js.map +1 -1
- package/dist/orchestration/tasks/scheduler.d.ts.map +1 -1
- package/dist/orchestration/tasks/scheduler.js +17 -3
- package/dist/orchestration/tasks/scheduler.js.map +1 -1
- package/dist/orchestration/tasks/service.d.ts +110 -34
- package/dist/orchestration/tasks/service.d.ts.map +1 -1
- package/dist/orchestration/tasks/service.js +234 -19
- package/dist/orchestration/tasks/service.js.map +1 -1
- package/dist/orchestration/tasks/task-directive.d.ts.map +1 -1
- package/dist/orchestration/tasks/task-directive.js +5 -1
- package/dist/orchestration/tasks/task-directive.js.map +1 -1
- package/dist/orchestration/telegram-tool-status.d.ts +8 -1
- package/dist/orchestration/telegram-tool-status.d.ts.map +1 -1
- package/dist/orchestration/telegram-tool-status.js +57 -6
- package/dist/orchestration/telegram-tool-status.js.map +1 -1
- package/dist/orchestration/token-ledger.d.ts +14 -0
- package/dist/orchestration/token-ledger.d.ts.map +1 -1
- package/dist/orchestration/token-ledger.js +28 -2
- package/dist/orchestration/token-ledger.js.map +1 -1
- package/dist/orchestration/token-usage.d.ts +14 -0
- package/dist/orchestration/token-usage.d.ts.map +1 -1
- package/dist/orchestration/token-usage.js +16 -2
- package/dist/orchestration/token-usage.js.map +1 -1
- package/dist/orchestration/tool-name.d.ts.map +1 -1
- package/dist/orchestration/tool-name.js +5 -1
- package/dist/orchestration/tool-name.js.map +1 -1
- package/dist/orchestration/types.d.ts +29 -0
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/types.js +11 -0
- package/dist/orchestration/types.js.map +1 -1
- package/dist/orchestration/worker-harness.d.ts.map +1 -1
- package/dist/orchestration/worker-harness.js +5 -2
- package/dist/orchestration/worker-harness.js.map +1 -1
- package/dist/pstack/config.d.ts +48 -0
- package/dist/pstack/config.d.ts.map +1 -0
- package/dist/pstack/config.js +147 -0
- package/dist/pstack/config.js.map +1 -0
- package/dist/pstack/menu.d.ts +71 -0
- package/dist/pstack/menu.d.ts.map +1 -0
- package/dist/pstack/menu.js +286 -0
- package/dist/pstack/menu.js.map +1 -0
- package/dist/pstack/overlay.d.ts +30 -0
- package/dist/pstack/overlay.d.ts.map +1 -0
- package/dist/pstack/overlay.js +121 -0
- package/dist/pstack/overlay.js.map +1 -0
- package/dist/pstack/plugin-info.d.ts +36 -0
- package/dist/pstack/plugin-info.d.ts.map +1 -0
- package/dist/pstack/plugin-info.js +51 -0
- package/dist/pstack/plugin-info.js.map +1 -0
- package/dist/pstack/reflect.d.ts +14 -0
- package/dist/pstack/reflect.d.ts.map +1 -0
- package/dist/pstack/reflect.js +49 -0
- package/dist/pstack/reflect.js.map +1 -0
- package/dist/pstack/setup.d.ts +17 -0
- package/dist/pstack/setup.d.ts.map +1 -0
- package/dist/pstack/setup.js +47 -0
- package/dist/pstack/setup.js.map +1 -0
- package/dist/pstack/sheet.d.ts +19 -0
- package/dist/pstack/sheet.d.ts.map +1 -0
- package/dist/pstack/sheet.js +44 -0
- package/dist/pstack/sheet.js.map +1 -0
- package/dist/pstack/templates.d.ts +14 -0
- package/dist/pstack/templates.d.ts.map +1 -0
- package/dist/pstack/templates.js +41 -0
- package/dist/pstack/templates.js.map +1 -0
- package/dist/session/codex-process.d.ts +0 -3
- package/dist/session/codex-process.d.ts.map +1 -1
- package/dist/session/codex-process.js +8 -3
- package/dist/session/codex-process.js.map +1 -1
- package/dist/session/compactor.d.ts.map +1 -1
- package/dist/session/compactor.js +2 -1
- package/dist/session/compactor.js.map +1 -1
- package/dist/session/process-diagnostics.d.ts +3 -0
- package/dist/session/process-diagnostics.d.ts.map +1 -1
- package/dist/session/process-diagnostics.js +10 -0
- package/dist/session/process-diagnostics.js.map +1 -1
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +9 -4
- package/dist/session/process.js.map +1 -1
- package/dist/session/provider-refusal.d.ts +36 -0
- package/dist/session/provider-refusal.d.ts.map +1 -0
- package/dist/session/provider-refusal.js +109 -0
- package/dist/session/provider-refusal.js.map +1 -0
- package/dist/session/runtime-profile.d.ts +13 -2
- package/dist/session/runtime-profile.d.ts.map +1 -1
- package/dist/session/runtime-profile.js +35 -2
- package/dist/session/runtime-profile.js.map +1 -1
- package/dist/session/worker-extensions.d.ts +5 -2
- package/dist/session/worker-extensions.d.ts.map +1 -1
- package/dist/session/worker-extensions.js +10 -5
- package/dist/session/worker-extensions.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/dashboard-client.d.ts.map +1 -1
- package/dist/ui/dashboard-client.js +14 -4
- package/dist/ui/dashboard-client.js.map +1 -1
- package/dist/ui/dashboard-presentation.d.ts +29 -0
- package/dist/ui/dashboard-presentation.d.ts.map +1 -1
- package/dist/ui/dashboard-presentation.js +26 -1
- package/dist/ui/dashboard-presentation.js.map +1 -1
- package/dist/ui/token-report.d.ts +3 -0
- package/dist/ui/token-report.d.ts.map +1 -1
- package/dist/ui/token-report.js +1 -1
- package/dist/ui/token-report.js.map +1 -1
- package/dist/voice/errors.d.ts +6 -1
- package/dist/voice/errors.d.ts.map +1 -1
- package/dist/voice/errors.js +8 -1
- package/dist/voice/errors.js.map +1 -1
- package/dist/voice/managed-quota.d.ts +29 -3
- package/dist/voice/managed-quota.d.ts.map +1 -1
- package/dist/voice/managed-quota.js +68 -23
- package/dist/voice/managed-quota.js.map +1 -1
- package/dist/voice/notes.d.ts +27 -3
- package/dist/voice/notes.d.ts.map +1 -1
- package/dist/voice/notes.js +59 -10
- package/dist/voice/notes.js.map +1 -1
- package/mcp/lazy-tools.ts +4 -2
- package/mcp/server.ts +6 -2
- package/mcp/tools/tasks/module.ts +3 -1
- package/mcp/tools/telegram/pstack-menu.ts +22 -0
- package/mcp/tools/telegram/pure.ts +40 -0
- package/mcp/tools/telegram/receiver-server.ts +63 -6
- package/package.json +1 -1
package/dist/agent/runner.js
CHANGED
|
@@ -111,60 +111,16 @@ const ANTHROPIC_SOCKET_ERROR = 'socket connection was closed unexpectedly';
|
|
|
111
111
|
// a cap higher than it.
|
|
112
112
|
const TOO_LARGE_HISTORY_LADDER = [process_1.MAX_HISTORY_MESSAGES, 40, 30, 20, 10, 0];
|
|
113
113
|
exports.MAX_IMAGE_SIZE_BYTES = 10 * 1024 * 1024;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// migrateModels(). Nobody is moved onto 5.1 by this change.
|
|
125
|
-
//
|
|
126
|
-
// Both Fable 5.x entries carry the same 200k/1M split as the rest: their CLI
|
|
127
|
-
// catalog entry says `native_1m`, but native 1M only applies when the base URL
|
|
128
|
-
// is api.anthropic.com. Behind a proxy the `[1m]` id suffix and the
|
|
129
|
-
// `context-1m-2025-08-07` beta header are what actually buy the larger window,
|
|
130
|
-
// which is exactly what the paired rows below encode.
|
|
131
|
-
//
|
|
132
|
-
// Opus 5.5 (`claude-opus-5-5`) follows the same convention on its own family:
|
|
133
|
-
// it takes the bare `opus` alias and Opus 5 is demoted to `opus5`, mirroring
|
|
134
|
-
// the Opus 5 -> Opus 4.8 demotion above and the Fable 5.1 -> Fable 5 one.
|
|
135
|
-
// Selection still stores the resolved id, so an agent already on Opus 5 stays
|
|
136
|
-
// on claude-opus-5 — only `/model opus` from now on resolves to 5.5.
|
|
137
|
-
//
|
|
138
|
-
// Sonnet 5.5 (`claude-sonnet-5-5`) does the same on the Sonnet family: it takes
|
|
139
|
-
// `sonnet` / `sonnet[1m]` and Sonnet 5 is demoted to `sonnet5` / `sonnet5[1m]`;
|
|
140
|
-
// Sonnet 4.6 keeps `sonnet46`. An agent already on Sonnet 5 stays on
|
|
141
|
-
// claude-sonnet-5.
|
|
142
|
-
exports.DEFAULT_MODELS = [
|
|
143
|
-
{ id: 'claude-fable-5-1[1m]', label: 'Fable 5.1 (1M)', alias: 'fable[1m]', contextWindow: 1000000 },
|
|
144
|
-
{ id: 'claude-fable-5[1m]', label: 'Fable 5 (1M)', alias: 'fable5[1m]', contextWindow: 1000000 },
|
|
145
|
-
{ id: 'claude-opus-5-5[1m]', label: 'Opus 5.5 (1M)', alias: 'opus[1m]', contextWindow: 1000000 },
|
|
146
|
-
{ id: 'claude-opus-5[1m]', label: 'Opus 5 (1M)', alias: 'opus5[1m]', contextWindow: 1000000 },
|
|
147
|
-
{ id: 'claude-opus-4-8[1m]', label: 'Opus 4.8 (1M)', alias: 'opus48[1m]', contextWindow: 1000000 },
|
|
148
|
-
{ id: 'claude-sonnet-5-5[1m]', label: 'Sonnet 5.5 (1M)', alias: 'sonnet[1m]', contextWindow: 1000000 },
|
|
149
|
-
{ id: 'claude-sonnet-5[1m]', label: 'Sonnet 5 (1M)', alias: 'sonnet5[1m]', contextWindow: 1000000 },
|
|
150
|
-
{ id: 'claude-fable-5-1', label: 'Fable 5.1', alias: 'fable', contextWindow: 200000 },
|
|
151
|
-
{ id: 'claude-fable-5', label: 'Fable 5', alias: 'fable5', contextWindow: 200000 },
|
|
152
|
-
{ id: 'claude-opus-5-5', label: 'Opus 5.5', alias: 'opus', contextWindow: 200000 },
|
|
153
|
-
{ id: 'claude-opus-5', label: 'Opus 5', alias: 'opus5', contextWindow: 200000 },
|
|
154
|
-
{ id: 'claude-opus-4-8', label: 'Opus 4.8', alias: 'opus48', contextWindow: 200000 },
|
|
155
|
-
{ id: 'claude-opus-4-6', label: 'Opus 4.6', alias: 'opus46', contextWindow: 200000 },
|
|
156
|
-
{ id: 'claude-sonnet-5-5', label: 'Sonnet 5.5', alias: 'sonnet', contextWindow: 200000 },
|
|
157
|
-
{ id: 'claude-sonnet-5', label: 'Sonnet 5', alias: 'sonnet5', contextWindow: 200000 },
|
|
158
|
-
{ id: 'claude-sonnet-4-6', label: 'Sonnet 4.6', alias: 'sonnet46', contextWindow: 200000 },
|
|
159
|
-
{ id: 'claude-haiku-4-5-20251001', label: 'Haiku 4.5', alias: 'haiku', contextWindow: 200000 },
|
|
160
|
-
{ id: 'gpt-6-sol[1m]', label: 'GPT 6 Sol', alias: 'gpt6sol', contextWindow: 1050000 },
|
|
161
|
-
{ id: 'gpt-6-astra[1m]', label: 'GPT 6 Astra', alias: 'gpt6astra', contextWindow: 1050000 },
|
|
162
|
-
{ id: 'gpt-6-luna[1m]', label: 'GPT 6 Luna', alias: 'gpt6luna', contextWindow: 1050000 },
|
|
163
|
-
{ id: 'gpt-5.6-sol[1m]', label: 'GPT 5.6 Sol', alias: 'gpt56sol', contextWindow: 1050000 },
|
|
164
|
-
{ id: 'gpt-5.6-terra[1m]', label: 'GPT 5.6 Terra', alias: 'gpt56terra', contextWindow: 1050000 },
|
|
165
|
-
{ id: 'gpt-5.6-luna[1m]', label: 'GPT 5.6 Luna', alias: 'gpt56luna', contextWindow: 1050000 },
|
|
166
|
-
{ id: 'gpt-5.5[1m]', label: 'GPT 5.5', alias: 'gpt55', contextWindow: 1050000 },
|
|
167
|
-
];
|
|
114
|
+
var model_registry_1 = require("./model-registry");
|
|
115
|
+
Object.defineProperty(exports, "DEFAULT_MODELS", { enumerable: true, get: function () { return model_registry_1.DEFAULT_MODELS; } });
|
|
116
|
+
const model_registry_2 = require("./model-registry");
|
|
117
|
+
const plugin_info_1 = require("../pstack/plugin-info");
|
|
118
|
+
const config_4 = require("../pstack/config");
|
|
119
|
+
const sheet_1 = require("../pstack/sheet");
|
|
120
|
+
const setup_1 = require("../pstack/setup");
|
|
121
|
+
const menu_1 = require("../pstack/menu");
|
|
122
|
+
const PSTACK_WRITE_REQUIRED = 'Changing the pstack setup needs an API key with write access to this agent. /pstack-setup without arguments shows it.';
|
|
123
|
+
const PSTACK_SETUP_USAGE = 'Usage: /pstack-setup on | off | <role>: <model-id>[ @<level>] (one per line; "<role>: default" drops an override; "<role> += <model-id>[ @<level>]" / "<role> -= <model-id>" edit a panel list; "default effort: <level|session>").';
|
|
168
124
|
const PROTECTED_WORKSPACE_FILES = [
|
|
169
125
|
'AGENTS.md', 'SOUL.md', 'MEMORY.md', 'CLAUDE.md',
|
|
170
126
|
'IDENTITY.md', 'USER.md', 'HEARTBEAT.md',
|
|
@@ -197,10 +153,10 @@ const RECOVERY_TRIAGE_TIMEOUT_MS = 15000;
|
|
|
197
153
|
// 30s cooldown), so anything older is a finished turn — pruned to keep the
|
|
198
154
|
// budget map from growing unbounded over a long-lived runner (Epic #195, 3b).
|
|
199
155
|
const RECOVERY_BUDGET_TTL_MS = 10 * 60000;
|
|
200
|
-
// Trailing-edge window for coalescing channel messages
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
//
|
|
156
|
+
// Trailing-edge window for coalescing consecutive channel messages (text, images,
|
|
157
|
+
// client-split long text, photo+caption) into a single turn. Reset on every new
|
|
158
|
+
// update, so an album burst or a client-split message is gathered whole. Every
|
|
159
|
+
// non-command message waits this window before its turn starts.
|
|
204
160
|
exports.CHANNEL_COALESCE_WINDOW_MS = 1200;
|
|
205
161
|
/**
|
|
206
162
|
* Move UI-uploaded files from staging (ui-upload/) to permanent per-session storage
|
|
@@ -753,7 +709,7 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
753
709
|
catch { /* already gone */ }
|
|
754
710
|
finish({ stdout: '', timedOut: true });
|
|
755
711
|
}, RECOVERY_TRIAGE_TIMEOUT_MS);
|
|
756
|
-
const child = spawn('claude', ['-p', '--output-format', 'text'], {
|
|
712
|
+
const child = spawn('claude', ['-p', '--output-format', 'text', '--settings', JSON.stringify(plugin_info_1.PSTACK_OFF_SETTINGS)], {
|
|
757
713
|
stdio: ['pipe', 'pipe', 'ignore'],
|
|
758
714
|
});
|
|
759
715
|
child.stdout?.on('data', (d) => { out += String(d); });
|
|
@@ -1384,6 +1340,42 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
1384
1340
|
}
|
|
1385
1341
|
return;
|
|
1386
1342
|
}
|
|
1343
|
+
if (command === 'telegram_pstack') {
|
|
1344
|
+
// A private chat's id is its user's id, as for every Telegram menu here.
|
|
1345
|
+
const chatId = body.chat_id ?? '', payload = body.payload ?? {};
|
|
1346
|
+
if (!/^\d+$/.test(chatId) || payload.user_id !== chatId || typeof payload.data !== 'string' || !/^ps:[\x21-\x7e]{1,61}$/.test(payload.data)) {
|
|
1347
|
+
respond({ success: false }, 400);
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
try {
|
|
1351
|
+
respond({ success: true, ...await this.pstackMenu(payload.data) });
|
|
1352
|
+
}
|
|
1353
|
+
catch (error) {
|
|
1354
|
+
this.logger.error('pstack setup button failed', { data: payload.data, error: String(error) });
|
|
1355
|
+
respond({ success: false, error: 'pstack setup unavailable. Use /pstack_setup again.' });
|
|
1356
|
+
}
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
if (command === 'telegram_voice_retry') {
|
|
1360
|
+
// A private chat's id is its user's id; the runtime also checks the note's sender and chat.
|
|
1361
|
+
const chatId = body.chat_id ?? '', payload = body.payload ?? {};
|
|
1362
|
+
if (!/^\d+$/.test(chatId) || payload.user_id !== chatId || typeof payload.input_id !== 'string' || !/^[a-f0-9-]{36}$/.test(payload.input_id)) {
|
|
1363
|
+
respond({ success: false }, 400);
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
if (!this.agentConfig.orchestration?.enabled || !this.agentConfig.orchestration.channels?.includes('telegram')) {
|
|
1367
|
+
respond({ success: false, error: 'Voice retry requires orchestration mode.' });
|
|
1368
|
+
return;
|
|
1369
|
+
}
|
|
1370
|
+
try {
|
|
1371
|
+
respond({ success: true, ...(await this.getOrchestration()).retryVoiceNote('telegram', chatId, `telegram:${payload.user_id}`, payload.input_id) });
|
|
1372
|
+
}
|
|
1373
|
+
catch (error) {
|
|
1374
|
+
this.logger.warn('Voice note retry refused', { referenceId: payload.input_id, code: error instanceof Error ? error.message : String(error) });
|
|
1375
|
+
respond({ success: false, error: 'This voice note cannot be retried here. Please record it again.' });
|
|
1376
|
+
}
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1387
1379
|
if (command === 'telegram_question') {
|
|
1388
1380
|
const chatId = body.chat_id ?? '', payload = body.payload ?? {};
|
|
1389
1381
|
if (!/^\d+$/.test(chatId) || payload.user_id !== chatId) {
|
|
@@ -1508,7 +1500,7 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
1508
1500
|
// it — fetchModelCatalog is bounded and never rejects.
|
|
1509
1501
|
void this.availableModels()
|
|
1510
1502
|
.then((availableModels) => {
|
|
1511
|
-
const configuredIds = new Set((this.gatewayConfig.gateway.models ??
|
|
1503
|
+
const configuredIds = new Set((this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).map(m => m.id));
|
|
1512
1504
|
const configured = availableModels.filter(m => configuredIds.has(m.id));
|
|
1513
1505
|
const live = availableModels.filter(m => !configuredIds.has(m.id));
|
|
1514
1506
|
respond({
|
|
@@ -2963,7 +2955,7 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
2963
2955
|
async handleSessionCommand(chatId, content, meta = {}) {
|
|
2964
2956
|
const agentId = this.agentConfig.id;
|
|
2965
2957
|
if (content.trim() === '/help') {
|
|
2966
|
-
this.writeAutoForward(chatId, (0, command_help_1.commandHelp)(this.channelFor(chatId),
|
|
2958
|
+
this.writeAutoForward(chatId, (0, command_help_1.commandHelp)(this.channelFor(chatId), this.requiresDurableChannelIngress(this.channelFor(chatId)), this.gatewayConfig.gateway.headless === false));
|
|
2967
2959
|
}
|
|
2968
2960
|
else if (/^\/restart(?:\s|$)/.test(content)) {
|
|
2969
2961
|
await this.restartProcess(chatId);
|
|
@@ -2990,6 +2982,9 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
2990
2982
|
const name = content.replace('/rename', '').trim();
|
|
2991
2983
|
await this.handleCommandRename(agentId, chatId, name);
|
|
2992
2984
|
}
|
|
2985
|
+
else if (/^\/pstack[-_]setup\b/.test(content)) {
|
|
2986
|
+
await this.handleCommandPstackSetup(chatId, content.replace(/^\/pstack[-_]setup(?:@\w+)?/, '').trim(), meta);
|
|
2987
|
+
}
|
|
2993
2988
|
else if (content.startsWith('/models')) {
|
|
2994
2989
|
await this.handleCommandModels(chatId);
|
|
2995
2990
|
}
|
|
@@ -3014,8 +3009,12 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
3014
3009
|
* exactly that state before this.
|
|
3015
3010
|
*/
|
|
3016
3011
|
async handleCommandModels(chatId) {
|
|
3012
|
+
this.writeAutoForward(chatId, (await this.modelList('Switch with /model <id or alias>')).text);
|
|
3013
|
+
}
|
|
3014
|
+
/** The /models list: configured models, then live-only ones, each marked when current. */
|
|
3015
|
+
async modelList(switchHint) {
|
|
3017
3016
|
const models = await this.availableModels();
|
|
3018
|
-
const configuredIds = new Set((this.gatewayConfig.gateway.models ??
|
|
3017
|
+
const configuredIds = new Set((this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).map(m => m.id));
|
|
3019
3018
|
const configured = models.filter(m => configuredIds.has(m.id));
|
|
3020
3019
|
const live = models.filter(m => !configuredIds.has(m.id));
|
|
3021
3020
|
const current = this.agentConfig.claude.model;
|
|
@@ -3031,8 +3030,101 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
3031
3030
|
lines.push(`${marker}${m.label} — \`${m.id}\``);
|
|
3032
3031
|
}
|
|
3033
3032
|
}
|
|
3034
|
-
lines.push('',
|
|
3035
|
-
|
|
3033
|
+
lines.push('', switchHint);
|
|
3034
|
+
return { text: lines.join('\n'), models: [...configured, ...live].map(m => ({ id: m.id, label: m.label, current: m.id === current })) };
|
|
3035
|
+
}
|
|
3036
|
+
/**
|
|
3037
|
+
* /pstack-setup — the gateway's counterpart of pstack's own setup-pstack:
|
|
3038
|
+
* decides whether this agent's workers load pstack, and with which models.
|
|
3039
|
+
* Arguments are pstack-models.md lines, one per line (`<role>: <model-id>`,
|
|
3040
|
+
* `<role>: default` to drop an override, `<role> += <model-id>` / `<role> -= <model-id>`
|
|
3041
|
+
* to edit a panel list, `default effort: <level>`); `on`
|
|
3042
|
+
* sets the agent up with the skill defaults and `off` removes it. Changes
|
|
3043
|
+
* apply to the next worker. Direct messages only, like /model; the bare
|
|
3044
|
+
* form too, so a group is not shown the agent's setup.
|
|
3045
|
+
*/
|
|
3046
|
+
async handleCommandPstackSetup(chatId, arg, meta = {}) {
|
|
3047
|
+
if (!this.isDirectChat(meta)) {
|
|
3048
|
+
this.writeAutoForward(chatId, 'pstack setup is only available in a direct message with the bot — it changes this agent for every chat.');
|
|
3049
|
+
return;
|
|
3050
|
+
}
|
|
3051
|
+
this.writeAutoForward(chatId, arg ? await this.applyPstackSetup(arg) : await this.pstackSetupText());
|
|
3052
|
+
}
|
|
3053
|
+
/** The bare /pstack-setup reply for channels without buttons: status, every role's current model, the syntax and the model IDs. */
|
|
3054
|
+
async pstackSetupText() {
|
|
3055
|
+
return (0, menu_1.pstackMenuText)(await this.pstackMenuState(), PSTACK_SETUP_USAGE);
|
|
3056
|
+
}
|
|
3057
|
+
async pstackMenuState() {
|
|
3058
|
+
const plugin = (0, plugin_info_1.pstackPluginInfo)();
|
|
3059
|
+
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 };
|
|
3060
|
+
}
|
|
3061
|
+
/** Change the saved pstack block (`undefined` removes it) through the same path as the API. */
|
|
3062
|
+
async updatePstack(update) {
|
|
3063
|
+
const result = await (0, setup_1.updatePstackConfig)(this.configPath, this.agentConfig.id, update, await this.selectableModels());
|
|
3064
|
+
if (result.saved)
|
|
3065
|
+
this.agentConfig.pstack = result.saved;
|
|
3066
|
+
else
|
|
3067
|
+
delete this.agentConfig.pstack;
|
|
3068
|
+
return result;
|
|
3069
|
+
}
|
|
3070
|
+
/** Apply `/pstack-setup <arg>` (on, off, or pstack-models.md lines) and describe the outcome. */
|
|
3071
|
+
async applyPstackSetup(arg) {
|
|
3072
|
+
const plugin = (0, plugin_info_1.pstackPluginInfo)();
|
|
3073
|
+
const roles = plugin.installPath ? (0, plugin_info_1.pstackModels)(plugin.installPath) : undefined;
|
|
3074
|
+
try {
|
|
3075
|
+
const { saved } = await this.updatePstack(previous => arg === 'off' ? undefined : arg === 'on' ? previous ?? {} : (0, config_4.applySheetLines)(previous ?? {}, arg, roles && (role => (0, sheet_1.pstackPanelDefault)(roles, role))));
|
|
3076
|
+
if (!saved)
|
|
3077
|
+
return 'pstack is removed from this agent. Its next worker does not load it.';
|
|
3078
|
+
// `on` for an agent already set up saves nothing, so a plugin that cannot be read is only noticed here.
|
|
3079
|
+
if (!roles)
|
|
3080
|
+
return `pstack is set up for this agent, but ${plugin_info_1.PSTACK_PLUGIN_ID} is not installed for Claude Code on this host, so its workers cannot load it. ${plugin_info_1.PSTACK_INSTALL_HINT}`;
|
|
3081
|
+
return `pstack is set up for this agent. The next worker loads it with this sheet:\n\n${(0, sheet_1.renderPstackSheet)(saved, roles)}`;
|
|
3082
|
+
}
|
|
3083
|
+
catch (error) {
|
|
3084
|
+
if (!(error instanceof config_4.PstackConfigError))
|
|
3085
|
+
throw error;
|
|
3086
|
+
return `${error.code}: ${error.message}`;
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
/** One /pstack-setup button (Telegram): apply its change, if any, and render the next screen. */
|
|
3090
|
+
async pstackMenu(data, canWrite = true) {
|
|
3091
|
+
const state = await this.pstackMenuState();
|
|
3092
|
+
let step;
|
|
3093
|
+
try {
|
|
3094
|
+
step = (0, menu_1.pstackMenuStep)(data, state);
|
|
3095
|
+
}
|
|
3096
|
+
catch (error) {
|
|
3097
|
+
if (!(error instanceof config_4.PstackConfigError))
|
|
3098
|
+
throw error;
|
|
3099
|
+
return { ...(0, menu_1.pstackMenuScreen)({ kind: 'home' }, state, `⚠️ ${error.message}`), toast: error.message };
|
|
3100
|
+
}
|
|
3101
|
+
if (step.next === undefined)
|
|
3102
|
+
return (0, menu_1.pstackMenuScreen)(step.view, state);
|
|
3103
|
+
if (!canWrite)
|
|
3104
|
+
return { ...(0, menu_1.pstackMenuScreen)(step.view, state, `⚠️ ${PSTACK_WRITE_REQUIRED}`), toast: PSTACK_WRITE_REQUIRED };
|
|
3105
|
+
let result;
|
|
3106
|
+
try {
|
|
3107
|
+
// Applied again to the saved block, so a change made meanwhile from the API or CLI is kept.
|
|
3108
|
+
result = await this.updatePstack(previous => {
|
|
3109
|
+
const next = (0, menu_1.pstackMenuStep)(data, { ...state, block: previous }).next;
|
|
3110
|
+
return next === undefined ? previous : next ?? undefined;
|
|
3111
|
+
});
|
|
3112
|
+
}
|
|
3113
|
+
catch (error) {
|
|
3114
|
+
if (!(error instanceof config_4.PstackConfigError))
|
|
3115
|
+
throw error;
|
|
3116
|
+
return { ...(0, menu_1.pstackMenuScreen)(step.view, state, `⚠️ ${error.code}: ${error.message}`), toast: error.message };
|
|
3117
|
+
}
|
|
3118
|
+
const unchanged = result.saved === result.previous;
|
|
3119
|
+
// Turn on/off ends the menu with its result and no buttons, as a /voice or /models choice does.
|
|
3120
|
+
if (data === 'ps:on' || data === 'ps:off') {
|
|
3121
|
+
const text = !result.saved ? `pstack is ${unchanged ? 'already off' : 'off'} for ${this.agentConfig.id}. The next worker does not load it.`
|
|
3122
|
+
: `pstack is ${unchanged ? 'already on' : 'on'} for ${this.agentConfig.id}. The next worker loads it.`;
|
|
3123
|
+
return { text: `✅ ${text}`, keyboard: [], done: true, toast: text };
|
|
3124
|
+
}
|
|
3125
|
+
const saved = unchanged ? 'No change.' : !result.saved ? 'pstack is off. The next worker does not load it.'
|
|
3126
|
+
: result.previous ? 'Saved. The next worker uses it.' : 'Saved, and pstack is on now. The next worker uses it.';
|
|
3127
|
+
return { ...(0, menu_1.pstackMenuScreen)(step.view, await this.pstackMenuState(), `✅ ${saved}`), toast: saved };
|
|
3036
3128
|
}
|
|
3037
3129
|
/**
|
|
3038
3130
|
* /model — show the current model, or switch to one from the catalog.
|
|
@@ -3055,9 +3147,7 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
3055
3147
|
+ 'Use /models here to see the list.');
|
|
3056
3148
|
return;
|
|
3057
3149
|
}
|
|
3058
|
-
const
|
|
3059
|
-
const wanted = arg.toLowerCase();
|
|
3060
|
-
const match = models.find((m) => m.id.toLowerCase() === wanted || m.alias.toLowerCase() === wanted);
|
|
3150
|
+
const match = (0, model_registry_2.findModel)(await this.selectableModels(), arg);
|
|
3061
3151
|
if (!match) {
|
|
3062
3152
|
this.writeAutoForward(chatId, `Unknown model "${arg}". Use /models to see the list.`);
|
|
3063
3153
|
return;
|
|
@@ -4420,7 +4510,7 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
4420
4510
|
async dashboardContextWindow(model) {
|
|
4421
4511
|
const models = await this.availableModels();
|
|
4422
4512
|
return models.find(m => m.id === model)?.contextWindow
|
|
4423
|
-
?? (this.gatewayConfig.gateway.models ??
|
|
4513
|
+
?? (this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).find(m => m.id === model)?.contextWindow
|
|
4424
4514
|
?? null;
|
|
4425
4515
|
}
|
|
4426
4516
|
getTokenReport(sessionId) {
|
|
@@ -5279,6 +5369,7 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5279
5369
|
// "/stop now") resolve to their base command instead of falling through to the
|
|
5280
5370
|
// unknown-command branch. The router gate is prefix-based, so these already pass.
|
|
5281
5371
|
const cmd = command.trim().split(/\s+/)[0] ?? '';
|
|
5372
|
+
const arg = command.trim().slice(cmd.length).trim();
|
|
5282
5373
|
// Validate BEFORE persisting anything. Reuse the same api-channel gate as the router
|
|
5283
5374
|
// so an unknown command throws with nothing written — no orphan user row is left, and
|
|
5284
5375
|
// the router surfaces the error/500 exactly as before. After token dispatch + the
|
|
@@ -5288,6 +5379,10 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5288
5379
|
}
|
|
5289
5380
|
if (cmd === '/stop' && this.agentConfig.orchestration?.enabled && opts?.principalId)
|
|
5290
5381
|
this.orchestration?.authorizeSession(sessionId, opts.principalId);
|
|
5382
|
+
// A fresh session has nothing to rename; refused before it is registered, so no empty session is left.
|
|
5383
|
+
if (cmd === '/rename' && opts?.implicitSession) {
|
|
5384
|
+
return { result: { error: 'SESSION_ID_REQUIRED' }, responseText: '⚠️ /rename renames the session given by session_id; send it with the session to rename.', actions: [] };
|
|
5385
|
+
}
|
|
5291
5386
|
// Register session in the api-{chatId} index on first use (same as sendApiMessageStream)
|
|
5292
5387
|
await this.sessionStore.ensureApiSession(agentId, storeChatId, sessionId).catch((err) => {
|
|
5293
5388
|
this.logger.warn('Failed to register API session in index for command', { agentId, chatId, sessionId, error: err.message });
|
|
@@ -5307,16 +5402,121 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5307
5402
|
return;
|
|
5308
5403
|
this.historyDb.insertMessage({ chatId: dbChatId, sessionId, source: 'api', role, content, ts: Date.now(), ...(role === 'user' && opts?.clientMessageId ? { clientMessageId: opts.clientMessageId } : {}) });
|
|
5309
5404
|
};
|
|
5310
|
-
// Persist the full user command before executing so it appears in history.
|
|
5311
|
-
|
|
5405
|
+
// Persist the full user command before executing so it appears in history. A pressed
|
|
5406
|
+
// action (`/orch <token>`, `/pstack-setup ps:…`, `/stop <menu> <n>`) is not something the
|
|
5407
|
+
// user typed, so only its reply is kept, except a setup menu page: that is UI, not
|
|
5408
|
+
// conversation, and would push real messages out of the history a new context starts from.
|
|
5409
|
+
const display = opts?.displayCommand ?? command;
|
|
5410
|
+
const pressed = /^\/(?:orch \S+|pstack[-_]setup ps:\S+|stop [0-9a-f-]{36} \d+)$/.test(display.trim());
|
|
5411
|
+
const menuPage = /^\/pstack[-_]setup ps:\S+$/.test(display.trim());
|
|
5412
|
+
if (!pressed)
|
|
5413
|
+
persist('user', display);
|
|
5312
5414
|
let result;
|
|
5313
5415
|
let responseText;
|
|
5416
|
+
let actions = [];
|
|
5314
5417
|
let forcePersist = false;
|
|
5418
|
+
const confirmScope = { channel: 'api', chatId, thread: '', sessionId, principalId: opts?.principalId ?? '' };
|
|
5419
|
+
const contextCommand = async (operation) => {
|
|
5420
|
+
if (operation === 'clear') {
|
|
5421
|
+
await this.clearContext(sessionId);
|
|
5422
|
+
return { result: { success: true, historyUnchanged: true, historyLimit: 50 }, responseText: 'Claude Code context reset. Chat history is unchanged. Your next message starts a new context with the latest 50 messages.' };
|
|
5423
|
+
}
|
|
5424
|
+
if (operation === 'compact') {
|
|
5425
|
+
await this.compactContext(sessionId, opts?.model);
|
|
5426
|
+
return { result: { success: true, native: true, historyUnchanged: true }, responseText: 'Claude Code context compacted. Chat history is unchanged.' };
|
|
5427
|
+
}
|
|
5428
|
+
await this.restartProcess(sessionId, sessionId);
|
|
5429
|
+
return { result: { restarting: true }, responseText: 'Session is restarting.' };
|
|
5430
|
+
};
|
|
5315
5431
|
try {
|
|
5316
5432
|
if (cmd === '/help') {
|
|
5317
|
-
|
|
5433
|
+
// /tasks is listed only where the web chat is in orchestration mode (orchestration.channels).
|
|
5434
|
+
responseText = (0, command_help_1.commandHelp)('api', this.orchestrationForApi(sessionId));
|
|
5318
5435
|
result = { text: responseText };
|
|
5319
5436
|
}
|
|
5437
|
+
else if ((cmd === '/clear' || cmd === '/compact' || cmd === '/restart') && arg !== 'confirm') {
|
|
5438
|
+
// Asked first, as in the chat channels: Yes/No are one-use actions for this session and key,
|
|
5439
|
+
// valid for five minutes. A caller that has already confirmed sends `<command> confirm`.
|
|
5440
|
+
const menu = this.sessionConfirmations.open(confirmScope, cmd.slice(1));
|
|
5441
|
+
result = { confirmationRequired: true };
|
|
5442
|
+
responseText = `${menu.text}\n\nOr reply ${cmd} confirm.`;
|
|
5443
|
+
actions = menu.buttons.map(button => ({ label: button.label, command: `/orch ${button.data.replace(/^orch:/, '')}` }));
|
|
5444
|
+
}
|
|
5445
|
+
else if (cmd === '/clear' || cmd === '/compact' || cmd === '/restart') {
|
|
5446
|
+
({ result, responseText } = await contextCommand(cmd.slice(1)));
|
|
5447
|
+
}
|
|
5448
|
+
else if (cmd === '/orch' && this.sessionConfirmations.owns(command.trim())) {
|
|
5449
|
+
const chosen = (() => { try {
|
|
5450
|
+
return this.sessionConfirmations.choose(confirmScope, command.trim());
|
|
5451
|
+
}
|
|
5452
|
+
catch (error) {
|
|
5453
|
+
return error;
|
|
5454
|
+
} })();
|
|
5455
|
+
if (chosen instanceof Error) {
|
|
5456
|
+
result = { error: 'CONFIRMATION_UNAVAILABLE' };
|
|
5457
|
+
responseText = chosen.message;
|
|
5458
|
+
}
|
|
5459
|
+
else if (chosen === 'cancel') {
|
|
5460
|
+
result = { cancelled: true };
|
|
5461
|
+
responseText = 'Cancelled.';
|
|
5462
|
+
}
|
|
5463
|
+
else
|
|
5464
|
+
({ result, responseText } = await contextCommand(chosen));
|
|
5465
|
+
}
|
|
5466
|
+
else if (cmd === '/models') {
|
|
5467
|
+
const list = await this.modelList('Change the model with the model picker or PUT /api/v1/agents/:agentId/model.');
|
|
5468
|
+
result = { model: this.agentConfig.claude.model, models: list.models };
|
|
5469
|
+
responseText = list.text;
|
|
5470
|
+
}
|
|
5471
|
+
else if (cmd === '/new' && opts?.implicitSession) {
|
|
5472
|
+
// Without session_id the command already runs in a new session: name that one rather than leave it empty beside another.
|
|
5473
|
+
if (arg)
|
|
5474
|
+
await this.updateApiSession(storeChatId, sessionId, { sessionName: arg });
|
|
5475
|
+
result = { sessionId, sessionName: arg || null };
|
|
5476
|
+
responseText = `New session created${arg ? `: "${arg}"` : ''}. Continue in it with session_id ${sessionId}.`;
|
|
5477
|
+
}
|
|
5478
|
+
else if (cmd === '/new') {
|
|
5479
|
+
// An API client picks its session by session_id, so this creates one and names it; the client opens it.
|
|
5480
|
+
const meta = await this.createApiSession(storeChatId, undefined, arg || undefined);
|
|
5481
|
+
result = { sessionId: meta.id, sessionName: meta.name };
|
|
5482
|
+
responseText = `New session created: "${meta.name}". This conversation stays in the current session; open the new one to continue there.`;
|
|
5483
|
+
}
|
|
5484
|
+
else if (cmd === '/rename') {
|
|
5485
|
+
if (!arg) {
|
|
5486
|
+
result = { error: 'SESSION_NAME_REQUIRED' };
|
|
5487
|
+
responseText = '⚠️ Usage: /rename <new name>\nExample: /rename Design review';
|
|
5488
|
+
}
|
|
5489
|
+
else {
|
|
5490
|
+
result = await this.updateApiSession(storeChatId, sessionId, { sessionName: arg });
|
|
5491
|
+
responseText = `✅ Session renamed to "${arg}"`;
|
|
5492
|
+
}
|
|
5493
|
+
}
|
|
5494
|
+
else if (cmd === '/tasks' || cmd === '/orch') {
|
|
5495
|
+
// The chat channels' task browser; its buttons come back as `/orch <token>`, bound to this session and principal.
|
|
5496
|
+
// The same test /help and message routing use, so what /help lists is what works.
|
|
5497
|
+
const apiOrchestration = this.orchestrationForApi(sessionId) ? this.orchestration : undefined;
|
|
5498
|
+
if (!apiOrchestration || !opts?.principalId) {
|
|
5499
|
+
result = {};
|
|
5500
|
+
responseText = cmd === '/orch' ? 'This action expired or is unavailable. Run the command again.' : 'Task controls require orchestration mode.';
|
|
5501
|
+
}
|
|
5502
|
+
else {
|
|
5503
|
+
apiOrchestration.authorizeSession(sessionId, opts.principalId);
|
|
5504
|
+
let menu;
|
|
5505
|
+
try {
|
|
5506
|
+
menu = await apiOrchestration.channelControls.handle({ channel: 'api', chatId, thread: '', sessionId, principalId: opts.principalId }, cmd === '/tasks' ? '/tasks' : `/orch ${arg}`);
|
|
5507
|
+
}
|
|
5508
|
+
catch {
|
|
5509
|
+
menu = { text: 'Control unavailable or expired. Please open the command again.', buttons: [] };
|
|
5510
|
+
}
|
|
5511
|
+
result = { closed: menu.close === true };
|
|
5512
|
+
responseText = menu.text;
|
|
5513
|
+
actions = menu.buttons.map(button => ({ label: button.label, command: `/orch ${button.data.replace(/^orch:/, '')}` }));
|
|
5514
|
+
}
|
|
5515
|
+
}
|
|
5516
|
+
else if (cmd === '/voice' || cmd === '/voices') {
|
|
5517
|
+
result = {};
|
|
5518
|
+
responseText = 'Voice on the web is set in the voice settings, not with a chat command: GET/PATCH /api/v1/agents/:agentId/voice-settings, and GET /api/v1/agents/:agentId/voice-sessions/voices for the voice list.';
|
|
5519
|
+
}
|
|
5320
5520
|
else if (cmd === '/model') {
|
|
5321
5521
|
const model = this.agentConfig.claude.model;
|
|
5322
5522
|
const hasArg = command.trim().includes(' ');
|
|
@@ -5343,6 +5543,9 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5343
5543
|
const menu = this.orchestration.stopControls.open(sessionId, opts.principalId);
|
|
5344
5544
|
responseText = (0, stop_controls_1.stopMenuText)(menu);
|
|
5345
5545
|
result = { ...menu, responseText };
|
|
5546
|
+
// Same choices as Telegram's /stop buttons; a bare number reply still works too.
|
|
5547
|
+
if (menu.tasks.length)
|
|
5548
|
+
actions = [...menu.tasks.map((t, i) => ({ label: `${i + 1}. ${t.title} (${t.state})`, command: `/stop ${menu.menuId} ${i + 1}` })), { label: 'Dismiss', command: `/stop ${menu.menuId} 0` }];
|
|
5346
5549
|
}
|
|
5347
5550
|
forcePersist = true;
|
|
5348
5551
|
}
|
|
@@ -5362,10 +5565,24 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5362
5565
|
forcePersist = stopped;
|
|
5363
5566
|
}
|
|
5364
5567
|
}
|
|
5365
|
-
else if (cmd === '/
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5568
|
+
else if (cmd === '/pstack-setup' || cmd === '/pstack_setup') {
|
|
5569
|
+
// Changes need the same access as PUT /api/v1/agents/:agentId/pstack.
|
|
5570
|
+
// `ps:…` is a menu button (the Telegram menu's callback data) sent back from the actions.
|
|
5571
|
+
let screen;
|
|
5572
|
+
if (!arg) {
|
|
5573
|
+
responseText = await this.pstackSetupText();
|
|
5574
|
+
screen = (0, menu_1.pstackMenuScreen)({ kind: 'home' }, await this.pstackMenuState());
|
|
5575
|
+
}
|
|
5576
|
+
else if (/^ps:\S+$/.test(arg)) {
|
|
5577
|
+
screen = await this.pstackMenu(arg, !!opts?.canWriteAgent);
|
|
5578
|
+
responseText = screen.text;
|
|
5579
|
+
}
|
|
5580
|
+
else {
|
|
5581
|
+
responseText = opts?.canWriteAgent ? await this.applyPstackSetup(arg) : PSTACK_WRITE_REQUIRED;
|
|
5582
|
+
}
|
|
5583
|
+
result = { pstack: this.agentConfig.pstack ?? null };
|
|
5584
|
+
if (screen && !screen.closed && !screen.done)
|
|
5585
|
+
actions = screen.keyboard.flat().map(button => ({ label: button.text, command: `/pstack-setup ${button.data}` }));
|
|
5369
5586
|
}
|
|
5370
5587
|
else if (cmd === '/session') {
|
|
5371
5588
|
const index = await this.sessionStore.listSessions(agentId, storeChatId, 'api').catch(() => null);
|
|
@@ -5406,16 +5623,6 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5406
5623
|
responseText = `Sessions (${withCounts.length}):\n${lines.join('\n')}`;
|
|
5407
5624
|
}
|
|
5408
5625
|
}
|
|
5409
|
-
else if (cmd === '/clear') {
|
|
5410
|
-
await this.clearContext(sessionId);
|
|
5411
|
-
result = { success: true, historyUnchanged: true, historyLimit: 50 };
|
|
5412
|
-
responseText = 'Claude Code context reset. Chat history is unchanged. Your next message starts a new context with the latest 50 messages.';
|
|
5413
|
-
}
|
|
5414
|
-
else if (cmd === '/compact') {
|
|
5415
|
-
await this.compactContext(sessionId, opts?.model);
|
|
5416
|
-
result = { success: true, native: true, historyUnchanged: true };
|
|
5417
|
-
responseText = 'Claude Code context compacted. Chat history is unchanged.';
|
|
5418
|
-
}
|
|
5419
5626
|
else {
|
|
5420
5627
|
// Passed the gate but has no dispatch branch — BUILTIN_COMMANDS drifted from this
|
|
5421
5628
|
// table. Throw so the failure surfaces (and ends history with an assistant turn via
|
|
@@ -5435,8 +5642,9 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5435
5642
|
// Persist the human-readable response as an assistant turn so the conversation ends with
|
|
5436
5643
|
// an assistant message (the web's computeIsPendingResponse needs last.role !== 'user').
|
|
5437
5644
|
// forcePersist writes it even under skipPersist (set only when /stop cut a turn off).
|
|
5438
|
-
|
|
5439
|
-
|
|
5645
|
+
if (!menuPage)
|
|
5646
|
+
persist('assistant', responseText, forcePersist);
|
|
5647
|
+
return { result, responseText, actions };
|
|
5440
5648
|
}
|
|
5441
5649
|
/**
|
|
5442
5650
|
* Whether an inbound channel message came from a 1:1 chat with the bot.
|
|
@@ -5457,6 +5665,9 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5457
5665
|
*/
|
|
5458
5666
|
isDirectChat(meta) {
|
|
5459
5667
|
const kind = meta['chat_type'] ?? meta['line_chat_type'] ?? meta['slack_chat_type'];
|
|
5668
|
+
// Telegram reports no chat type; a private chat's id is its user's id (groups are negative).
|
|
5669
|
+
if (kind === undefined && this.channelFor(meta['chat_id'] ?? '') === 'telegram')
|
|
5670
|
+
return /^\d+$/.test(meta['chat_id'] ?? '') && meta['chat_id'] === meta['user_id'];
|
|
5460
5671
|
return kind === 'direct' || kind === 'user';
|
|
5461
5672
|
}
|
|
5462
5673
|
/**
|
|
@@ -5479,15 +5690,8 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5479
5690
|
await Promise.all(restartPromises);
|
|
5480
5691
|
return restartPromises.length > 0;
|
|
5481
5692
|
}
|
|
5482
|
-
|
|
5483
|
-
|
|
5484
|
-
* the configured/static list otherwise (issue #409). Cached upstream, so the
|
|
5485
|
-
* six callers that only want one model's context window pay for at most one
|
|
5486
|
-
* fetch a minute between them.
|
|
5487
|
-
*/
|
|
5488
|
-
async availableModels() {
|
|
5489
|
-
const staticModels = this.gatewayConfig.gateway.models ?? exports.DEFAULT_MODELS;
|
|
5490
|
-
return (await (0, model_catalog_1.fetchModelCatalog)(staticModels)) ?? staticModels;
|
|
5693
|
+
availableModels() {
|
|
5694
|
+
return (0, model_registry_2.availableModels)(this.gatewayConfig.gateway.models);
|
|
5491
5695
|
}
|
|
5492
5696
|
/**
|
|
5493
5697
|
* Context window for a model id. Resolving this through the live catalog is
|
|
@@ -5504,24 +5708,11 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5504
5708
|
// /session context use against a fifth of the real window and handing
|
|
5505
5709
|
// SessionCompactor a window small enough to compact far too early.
|
|
5506
5710
|
return models.find((m) => m.id === modelId)?.contextWindow
|
|
5507
|
-
?? (this.gatewayConfig.gateway.models ??
|
|
5711
|
+
?? (this.gatewayConfig.gateway.models ?? model_registry_2.DEFAULT_MODELS).find((m) => m.id === modelId)?.contextWindow
|
|
5508
5712
|
?? (requireKnown ? 0 : model_catalog_1.DEFAULT_CONTEXT_WINDOW);
|
|
5509
5713
|
}
|
|
5510
|
-
|
|
5511
|
-
|
|
5512
|
-
* configured list.
|
|
5513
|
-
*
|
|
5514
|
-
* The union is only for *resolution*, never for the `/models` listing — the
|
|
5515
|
-
* listing has to reflect what upstream actually offers, or a model removed
|
|
5516
|
-
* upstream would linger in the picker forever, which is the bug this all
|
|
5517
|
-
* started from. Without the union a user who switches to a live-only model
|
|
5518
|
-
* is trapped: their previous configured model is no longer nameable.
|
|
5519
|
-
*/
|
|
5520
|
-
async selectableModels() {
|
|
5521
|
-
const live = await this.availableModels();
|
|
5522
|
-
const configured = this.gatewayConfig.gateway.models ?? exports.DEFAULT_MODELS;
|
|
5523
|
-
const ids = new Set(live.map((m) => m.id));
|
|
5524
|
-
return [...live, ...configured.filter((m) => !ids.has(m.id))];
|
|
5714
|
+
selectableModels() {
|
|
5715
|
+
return (0, model_registry_2.selectableModels)(this.gatewayConfig.gateway.models);
|
|
5525
5716
|
}
|
|
5526
5717
|
async setModel(newModel) {
|
|
5527
5718
|
// Allow any model string through — BYOK/third-party models (openrouter/* etc.)
|
|
@@ -5562,7 +5753,7 @@ class AgentRunner extends events_1.EventEmitter {
|
|
|
5562
5753
|
const { promisify } = await Promise.resolve().then(() => __importStar(require('util')));
|
|
5563
5754
|
const execFileAsync = promisify(execFile);
|
|
5564
5755
|
const titlePrompt = `Summarise in 3-5 words as a session title (no punctuation, no quotes): ${prompt}`;
|
|
5565
|
-
const { stdout } = await execFileAsync('claude', ['-p', titlePrompt, '--output-format', 'text', '--model', 'claude-haiku-4-5-20251001'], { timeout: 15000, encoding: 'utf-8' });
|
|
5756
|
+
const { stdout } = await execFileAsync('claude', ['-p', titlePrompt, '--output-format', 'text', '--model', 'claude-haiku-4-5-20251001', '--settings', JSON.stringify(plugin_info_1.PSTACK_OFF_SETTINGS)], { timeout: 15000, encoding: 'utf-8' });
|
|
5566
5757
|
const aiName = stdout.trim().slice(0, 60) || undefined;
|
|
5567
5758
|
if (aiName) {
|
|
5568
5759
|
await this.sessionStore.updateSessionMeta(this.agentConfig.id, chatId, sessionId, { name: aiName }, 'api');
|