@0xmaxma/claude-gateway 1.7.9 → 1.8.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 +178 -44
- package/dist/agent/builtin-commands.js +2 -2
- package/dist/agent/builtin-commands.js.map +1 -1
- package/dist/agent/dreaming/accept.d.ts.map +1 -1
- package/dist/agent/dreaming/accept.js +4 -1
- package/dist/agent/dreaming/accept.js.map +1 -1
- package/dist/agent/dreaming/config.d.ts.map +1 -1
- package/dist/agent/dreaming/config.js +2 -0
- package/dist/agent/dreaming/config.js.map +1 -1
- package/dist/agent/dreaming/reviewer.d.ts.map +1 -1
- package/dist/agent/dreaming/reviewer.js +9 -2
- package/dist/agent/dreaming/reviewer.js.map +1 -1
- package/dist/agent/dreaming/staleness.d.ts +7 -1
- package/dist/agent/dreaming/staleness.d.ts.map +1 -1
- package/dist/agent/dreaming/staleness.js +17 -2
- package/dist/agent/dreaming/staleness.js.map +1 -1
- package/dist/agent/dreaming/types.d.ts +17 -1
- package/dist/agent/dreaming/types.d.ts.map +1 -1
- package/dist/agent/knowledge/archive-db.d.ts +43 -0
- package/dist/agent/knowledge/archive-db.d.ts.map +1 -1
- package/dist/agent/knowledge/archive-db.js +130 -0
- package/dist/agent/knowledge/archive-db.js.map +1 -1
- package/dist/agent/knowledge/config.d.ts +3 -1
- package/dist/agent/knowledge/config.d.ts.map +1 -1
- package/dist/agent/knowledge/config.js +32 -10
- package/dist/agent/knowledge/config.js.map +1 -1
- package/dist/agent/knowledge/index.d.ts +11 -4
- package/dist/agent/knowledge/index.d.ts.map +1 -1
- package/dist/agent/knowledge/index.js +22 -1
- package/dist/agent/knowledge/index.js.map +1 -1
- package/dist/agent/knowledge/indexer.d.ts +0 -7
- package/dist/agent/knowledge/indexer.d.ts.map +1 -1
- package/dist/agent/knowledge/indexer.js +34 -7
- package/dist/agent/knowledge/indexer.js.map +1 -1
- package/dist/agent/knowledge/lifecycle.d.ts +20 -4
- package/dist/agent/knowledge/lifecycle.d.ts.map +1 -1
- package/dist/agent/knowledge/lifecycle.js +33 -4
- package/dist/agent/knowledge/lifecycle.js.map +1 -1
- package/dist/agent/knowledge/reflection.d.ts +114 -0
- package/dist/agent/knowledge/reflection.d.ts.map +1 -0
- package/dist/agent/knowledge/reflection.js +447 -0
- package/dist/agent/knowledge/reflection.js.map +1 -0
- package/dist/agent/knowledge/shared-dedup.d.ts +85 -0
- package/dist/agent/knowledge/shared-dedup.d.ts.map +1 -0
- package/dist/agent/knowledge/shared-dedup.js +187 -0
- package/dist/agent/knowledge/shared-dedup.js.map +1 -0
- package/dist/agent/knowledge/shared-promote.d.ts +82 -7
- package/dist/agent/knowledge/shared-promote.d.ts.map +1 -1
- package/dist/agent/knowledge/shared-promote.js +244 -11
- package/dist/agent/knowledge/shared-promote.js.map +1 -1
- package/dist/agent/knowledge/shared-staleness.d.ts +51 -0
- package/dist/agent/knowledge/shared-staleness.d.ts.map +1 -0
- package/dist/agent/knowledge/shared-staleness.js +149 -0
- package/dist/agent/knowledge/shared-staleness.js.map +1 -0
- package/dist/agent/knowledge/shared-writer.d.ts +19 -0
- package/dist/agent/knowledge/shared-writer.d.ts.map +1 -1
- package/dist/agent/knowledge/shared-writer.js +42 -0
- package/dist/agent/knowledge/shared-writer.js.map +1 -1
- package/dist/agent/knowledge/types.d.ts +24 -0
- package/dist/agent/knowledge/types.d.ts.map +1 -1
- package/dist/agent/model-catalog.d.ts +62 -0
- package/dist/agent/model-catalog.d.ts.map +1 -0
- package/dist/agent/model-catalog.js +264 -0
- package/dist/agent/model-catalog.js.map +1 -0
- package/dist/agent/runner.d.ts +83 -0
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +281 -51
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/workspace-loader.d.ts +17 -2
- package/dist/agent/workspace-loader.d.ts.map +1 -1
- package/dist/agent/workspace-loader.js +17 -1
- package/dist/agent/workspace-loader.js.map +1 -1
- package/dist/api/cron-router.d.ts +12 -8
- package/dist/api/cron-router.d.ts.map +1 -1
- package/dist/api/cron-router.js +82 -16
- package/dist/api/cron-router.js.map +1 -1
- package/dist/api/gateway-router.d.ts +4 -0
- package/dist/api/gateway-router.d.ts.map +1 -1
- package/dist/api/gateway-router.js +16 -1
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/manifest-sources.d.ts +15 -0
- package/dist/api/manifest-sources.d.ts.map +1 -0
- package/dist/api/manifest-sources.js +27 -0
- package/dist/api/manifest-sources.js.map +1 -0
- package/dist/api/meta-router.d.ts +13 -0
- package/dist/api/meta-router.d.ts.map +1 -0
- package/dist/api/meta-router.js +26 -0
- package/dist/api/meta-router.js.map +1 -0
- package/dist/api/packages.d.ts.map +1 -1
- package/dist/api/packages.js +18 -198
- package/dist/api/packages.js.map +1 -1
- package/dist/api/route-registry.d.ts +81 -0
- package/dist/api/route-registry.d.ts.map +1 -0
- package/dist/api/route-registry.js +44 -0
- package/dist/api/route-registry.js.map +1 -0
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +21 -3
- package/dist/api/router.js.map +1 -1
- package/dist/apps/compose-generator.js +7 -4
- package/dist/apps/compose-generator.js.map +1 -1
- package/dist/apps/installer.d.ts +154 -0
- package/dist/apps/installer.d.ts.map +1 -1
- package/dist/apps/installer.js +657 -54
- package/dist/apps/installer.js.map +1 -1
- package/dist/cli/args.d.ts +25 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +55 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/colors.d.ts +37 -0
- package/dist/cli/colors.d.ts.map +1 -0
- package/dist/cli/colors.js +63 -0
- package/dist/cli/colors.js.map +1 -0
- package/dist/cli/command-names.d.ts +98 -0
- package/dist/cli/command-names.d.ts.map +1 -0
- package/dist/cli/command-names.js +109 -0
- package/dist/cli/command-names.js.map +1 -0
- package/dist/cli/commands/agents.d.ts +28 -0
- package/dist/cli/commands/agents.d.ts.map +1 -0
- package/dist/cli/commands/agents.js +321 -0
- package/dist/cli/commands/agents.js.map +1 -0
- package/dist/cli/commands/channels.d.ts +17 -0
- package/dist/cli/commands/channels.d.ts.map +1 -0
- package/dist/cli/commands/channels.js +101 -0
- package/dist/cli/commands/channels.js.map +1 -0
- package/dist/cli/commands/debug-bundle.d.ts +6 -0
- package/dist/cli/commands/debug-bundle.d.ts.map +1 -0
- package/dist/cli/commands/debug-bundle.js +220 -0
- package/dist/cli/commands/debug-bundle.js.map +1 -0
- package/dist/cli/commands/doctor.d.ts +3 -0
- package/dist/cli/commands/doctor.d.ts.map +1 -0
- package/dist/cli/commands/doctor.js +104 -0
- package/dist/cli/commands/doctor.js.map +1 -0
- package/dist/cli/commands/gateway.d.ts +12 -0
- package/dist/cli/commands/gateway.d.ts.map +1 -0
- package/dist/cli/commands/gateway.js +145 -0
- package/dist/cli/commands/gateway.js.map +1 -0
- package/dist/cli/commands/service.d.ts +33 -0
- package/dist/cli/commands/service.d.ts.map +1 -0
- package/dist/cli/commands/service.js +513 -0
- package/dist/cli/commands/service.js.map +1 -0
- package/dist/cli/commands/update.d.ts +16 -0
- package/dist/cli/commands/update.d.ts.map +1 -0
- package/dist/cli/commands/update.js +149 -0
- package/dist/cli/commands/update.js.map +1 -0
- package/dist/cli/commands.generated.d.ts +4 -0
- package/dist/cli/commands.generated.d.ts.map +1 -0
- package/dist/cli/commands.generated.js +220 -0
- package/dist/cli/commands.generated.js.map +1 -0
- package/dist/cli/health.d.ts +31 -0
- package/dist/cli/health.d.ts.map +1 -0
- package/dist/cli/health.js +49 -0
- package/dist/cli/health.js.map +1 -0
- package/dist/cli/http-client.d.ts +140 -0
- package/dist/cli/http-client.d.ts.map +1 -0
- package/dist/cli/http-client.js +332 -0
- package/dist/cli/http-client.js.map +1 -0
- package/dist/cli/index.d.ts +27 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +372 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/manager.d.ts +64 -0
- package/dist/cli/manager.d.ts.map +1 -0
- package/dist/cli/manager.js +181 -0
- package/dist/cli/manager.js.map +1 -0
- package/dist/cli/output.d.ts +49 -0
- package/dist/cli/output.d.ts.map +1 -0
- package/dist/cli/output.js +101 -0
- package/dist/cli/output.js.map +1 -0
- package/dist/cli/prompt.d.ts +29 -0
- package/dist/cli/prompt.d.ts.map +1 -0
- package/dist/cli/prompt.js +154 -0
- package/dist/cli/prompt.js.map +1 -0
- package/dist/cli/redact.d.ts +3 -0
- package/dist/cli/redact.d.ts.map +1 -0
- package/dist/cli/redact.js +33 -0
- package/dist/cli/redact.js.map +1 -0
- package/dist/cli/types.d.ts +22 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +4 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/config/bootstrap.d.ts +33 -0
- package/dist/config/bootstrap.d.ts.map +1 -0
- package/dist/config/bootstrap.js +117 -0
- package/dist/config/bootstrap.js.map +1 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +5 -1
- package/dist/config/loader.js.map +1 -1
- package/dist/config/watcher.d.ts.map +1 -1
- package/dist/config/watcher.js +2 -35
- package/dist/config/watcher.js.map +1 -1
- package/dist/discord/receiver.d.ts +6 -1
- package/dist/discord/receiver.d.ts.map +1 -1
- package/dist/discord/receiver.js +9 -1
- package/dist/discord/receiver.js.map +1 -1
- package/dist/entry.d.ts +3 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +83 -0
- package/dist/entry.js.map +1 -0
- package/dist/index.js +197 -47
- package/dist/index.js.map +1 -1
- package/dist/load-dotenv.d.ts +2 -0
- package/dist/load-dotenv.d.ts.map +1 -0
- package/dist/load-dotenv.js +68 -0
- package/dist/load-dotenv.js.map +1 -0
- package/dist/packages/registry.d.ts +50 -0
- package/dist/packages/registry.d.ts.map +1 -0
- package/dist/packages/registry.js +209 -0
- package/dist/packages/registry.js.map +1 -0
- package/dist/session/process.d.ts +20 -3
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +120 -5
- package/dist/session/process.js.map +1 -1
- package/dist/shell/claude-pty-shell.js +146 -27
- package/dist/shell/claude-pty-shell.js.map +1 -1
- package/dist/shell/draft-phantom.d.ts +49 -0
- package/dist/shell/draft-phantom.d.ts.map +1 -0
- package/dist/shell/draft-phantom.js +59 -0
- package/dist/shell/draft-phantom.js.map +1 -0
- package/dist/shell/submit-diag.d.ts +67 -0
- package/dist/shell/submit-diag.d.ts.map +1 -0
- package/dist/shell/submit-diag.js +69 -0
- package/dist/shell/submit-diag.js.map +1 -0
- package/dist/shutdown-signals.d.ts +47 -0
- package/dist/shutdown-signals.d.ts.map +1 -0
- package/dist/shutdown-signals.js +62 -0
- package/dist/shutdown-signals.js.map +1 -0
- package/dist/telegram/receiver.d.ts +6 -1
- package/dist/telegram/receiver.d.ts.map +1 -1
- package/dist/telegram/receiver.js +9 -1
- package/dist/telegram/receiver.js.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/orphan-receivers.d.ts +90 -0
- package/dist/utils/orphan-receivers.d.ts.map +1 -0
- package/dist/utils/orphan-receivers.js +218 -0
- package/dist/utils/orphan-receivers.js.map +1 -0
- package/dist/utils/paths.d.ts +16 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +60 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/stop-child.d.ts +21 -0
- package/dist/utils/stop-child.d.ts.map +1 -0
- package/dist/utils/stop-child.js +64 -0
- package/dist/utils/stop-child.js.map +1 -0
- package/lib/pairing.ts +1 -1
- package/mcp/tools/agent/handlers.ts +1 -1
- package/mcp/tools/discord/module.ts +23 -15
- package/mcp/tools/discord/receiver-server.ts +4 -0
- package/mcp/tools/memory/archive-reader.test.ts +25 -1
- package/mcp/tools/memory/archive-reader.ts +70 -12
- package/mcp/tools/memory/archive-writer.test.ts +168 -0
- package/mcp/tools/memory/archive-writer.ts +137 -0
- package/mcp/tools/memory/module.test.ts +187 -0
- package/mcp/tools/memory/module.ts +192 -6
- package/mcp/tools/telegram/module.ts +10 -2
- package/mcp/tools/telegram/receiver-server.ts +15 -6
- package/mcp/tools/telegram/typing.ts +178 -34
- package/package.json +6 -4
package/dist/api/packages.js
CHANGED
|
@@ -5,24 +5,8 @@ exports._resetLock = _resetLock;
|
|
|
5
5
|
exports._setLock = _setLock;
|
|
6
6
|
exports.createPackagesRouter = createPackagesRouter;
|
|
7
7
|
const express_1 = require("express");
|
|
8
|
-
const child_process_1 = require("child_process");
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const path_1 = require("path");
|
|
11
8
|
const auth_1 = require("./auth");
|
|
12
|
-
const
|
|
13
|
-
// URL param "name" → package config.
|
|
14
|
-
// claude-gateway is a genuine npm global — keep npm detect/update.
|
|
15
|
-
// claude-code ships via the native installer (no longer an npm global), so
|
|
16
|
-
// detect from the `claude` binary and update via its native updater.
|
|
17
|
-
const PACKAGES = {
|
|
18
|
-
'claude-gateway': { npm: '@0xmaxma/claude-gateway', detect: 'npm', update: 'npm' },
|
|
19
|
-
'claude-code': {
|
|
20
|
-
npm: '@anthropic-ai/claude-code',
|
|
21
|
-
detect: 'binary',
|
|
22
|
-
bin: 'claude',
|
|
23
|
-
update: 'native',
|
|
24
|
-
},
|
|
25
|
-
};
|
|
9
|
+
const registry_1 = require("../packages/registry");
|
|
26
10
|
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
27
11
|
let versionCache = null;
|
|
28
12
|
let isUpdating = false;
|
|
@@ -35,123 +19,6 @@ function _resetLock() {
|
|
|
35
19
|
function _setLock() {
|
|
36
20
|
isUpdating = true;
|
|
37
21
|
}
|
|
38
|
-
function getNpmListVersion(packageName) {
|
|
39
|
-
try {
|
|
40
|
-
const output = (0, child_process_1.execSync)(`npm list -g ${packageName} --depth=0 --json`, {
|
|
41
|
-
encoding: 'utf-8',
|
|
42
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
43
|
-
timeout: 10000,
|
|
44
|
-
});
|
|
45
|
-
const parsed = JSON.parse(output);
|
|
46
|
-
return parsed.dependencies?.[packageName]?.version ?? null;
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
// Resolve the installed version by shelling out to the binary on PATH
|
|
53
|
-
// (e.g. `claude --version` → "2.1.207 (Claude Code)"). Parses the leading
|
|
54
|
-
// semver (with optional prerelease) and returns null on any failure —
|
|
55
|
-
// binary missing, non-zero exit, or unparseable output. `bin` is always a
|
|
56
|
-
// trusted constant from PACKAGES, never request-derived.
|
|
57
|
-
function getBinaryVersion(bin) {
|
|
58
|
-
try {
|
|
59
|
-
const output = (0, child_process_1.execSync)(`${bin} --version`, {
|
|
60
|
-
encoding: 'utf-8',
|
|
61
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
62
|
-
timeout: 10000,
|
|
63
|
-
});
|
|
64
|
-
// `claude --version` prints the version first (e.g. "2.1.207 (Claude Code)").
|
|
65
|
-
// Anchor to the start of the trimmed output so a version-like token later in
|
|
66
|
-
// the line can never be mistaken for the installed version.
|
|
67
|
-
const match = output.trim().match(/^(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)/);
|
|
68
|
-
return match ? match[1] : null;
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Resolve the currently-installed version per the package's detect strategy.
|
|
75
|
-
function resolveCurrent(config) {
|
|
76
|
-
if (config.detect === 'binary' && config.bin) {
|
|
77
|
-
return getBinaryVersion(config.bin);
|
|
78
|
-
}
|
|
79
|
-
return getNpmListVersion(config.npm);
|
|
80
|
-
}
|
|
81
|
-
// An update is available only when `latest` is strictly newer than `current`.
|
|
82
|
-
// Using semver ordering (not `current !== latest`) avoids a false "update
|
|
83
|
-
// available" when the installed version is *ahead* of the npm-registry latest
|
|
84
|
-
// — e.g. a native-installer channel that leads the npm dist-tag.
|
|
85
|
-
function updateAvailable(current, latest) {
|
|
86
|
-
return !!(current && latest && (0, migrator_1.compareSemver)(latest, current) > 0);
|
|
87
|
-
}
|
|
88
|
-
async function getLatestVersion(packageName) {
|
|
89
|
-
const encodedName = packageName.replace('/', '%2F');
|
|
90
|
-
const res = await fetch(`https://registry.npmjs.org/${encodedName}/latest`);
|
|
91
|
-
if (!res.ok)
|
|
92
|
-
return null;
|
|
93
|
-
const data = (await res.json());
|
|
94
|
-
return data.version ?? null;
|
|
95
|
-
}
|
|
96
|
-
async function fetchAllPackageVersions() {
|
|
97
|
-
const configs = Object.values(PACKAGES);
|
|
98
|
-
// Run all synchronous current-version lookups before entering async Promise.all
|
|
99
|
-
const currents = configs.map(resolveCurrent);
|
|
100
|
-
return Promise.all(configs.map(async (config, i) => {
|
|
101
|
-
const current = currents[i];
|
|
102
|
-
const latest = await getLatestVersion(config.npm);
|
|
103
|
-
return {
|
|
104
|
-
package: config.npm,
|
|
105
|
-
current,
|
|
106
|
-
latest,
|
|
107
|
-
hasUpdate: updateAvailable(current, latest),
|
|
108
|
-
};
|
|
109
|
-
}));
|
|
110
|
-
}
|
|
111
|
-
function getNpmGlobalRoot() {
|
|
112
|
-
return (0, child_process_1.execSync)('npm root -g', {
|
|
113
|
-
encoding: 'utf-8',
|
|
114
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
115
|
-
timeout: 10000,
|
|
116
|
-
}).trim();
|
|
117
|
-
}
|
|
118
|
-
function cleanStaleNpmTempDirs(npmRoot, packageName) {
|
|
119
|
-
const match = packageName.match(/^(@[^/]+)\/(.+)$/);
|
|
120
|
-
if (!match)
|
|
121
|
-
return;
|
|
122
|
-
const [, scope, basename] = match;
|
|
123
|
-
const scopeDir = (0, path_1.join)(npmRoot, scope);
|
|
124
|
-
let entries;
|
|
125
|
-
try {
|
|
126
|
-
entries = (0, fs_1.readdirSync)(scopeDir, { withFileTypes: false });
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const prefix = `.${basename}-`;
|
|
132
|
-
for (const entry of entries) {
|
|
133
|
-
if (entry.startsWith(prefix)) {
|
|
134
|
-
try {
|
|
135
|
-
(0, fs_1.rmSync)((0, path_1.join)(scopeDir, entry), { recursive: true, force: true });
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
// best-effort: ignore errors on individual temp dir removal
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function removePackageDir(npmRoot, packageName) {
|
|
144
|
-
const match = packageName.match(/^(@[^/]+)\/(.+)$/);
|
|
145
|
-
if (!match)
|
|
146
|
-
return;
|
|
147
|
-
const [, scope, basename] = match;
|
|
148
|
-
try {
|
|
149
|
-
(0, fs_1.rmSync)((0, path_1.join)(npmRoot, scope, basename), { recursive: true, force: true });
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
// best-effort
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
22
|
function createPackagesRouter(apiKeys) {
|
|
156
23
|
const router = (0, express_1.Router)();
|
|
157
24
|
if (apiKeys?.length) {
|
|
@@ -172,7 +39,7 @@ function createPackagesRouter(apiKeys) {
|
|
|
172
39
|
}
|
|
173
40
|
let packages;
|
|
174
41
|
try {
|
|
175
|
-
packages = await fetchAllPackageVersions();
|
|
42
|
+
packages = await (0, registry_1.fetchAllPackageVersions)();
|
|
176
43
|
}
|
|
177
44
|
catch {
|
|
178
45
|
res.status(503).json({ error: 'registry unavailable' });
|
|
@@ -191,16 +58,16 @@ function createPackagesRouter(apiKeys) {
|
|
|
191
58
|
}
|
|
192
59
|
}
|
|
193
60
|
const { name } = req.params;
|
|
194
|
-
const config = PACKAGES[name];
|
|
61
|
+
const config = registry_1.PACKAGES[name];
|
|
195
62
|
if (!config) {
|
|
196
63
|
res.status(404).json({ error: `unknown package: ${name}` });
|
|
197
64
|
return;
|
|
198
65
|
}
|
|
199
66
|
const packageName = config.npm;
|
|
200
|
-
const from = resolveCurrent(config);
|
|
67
|
+
const from = (0, registry_1.resolveCurrent)(config);
|
|
201
68
|
let latest;
|
|
202
69
|
try {
|
|
203
|
-
latest = await getLatestVersion(packageName);
|
|
70
|
+
latest = await (0, registry_1.getLatestVersion)(packageName);
|
|
204
71
|
}
|
|
205
72
|
catch {
|
|
206
73
|
res.status(503).json({ error: 'registry unavailable' });
|
|
@@ -211,7 +78,7 @@ function createPackagesRouter(apiKeys) {
|
|
|
211
78
|
return;
|
|
212
79
|
}
|
|
213
80
|
// Already on latest (or ahead of it) — no install needed
|
|
214
|
-
if (from && !updateAvailable(from, latest)) {
|
|
81
|
+
if (from && !(0, registry_1.updateAvailable)(from, latest)) {
|
|
215
82
|
res.json({ package: packageName, from, to: from, updated: false, warning: null });
|
|
216
83
|
return;
|
|
217
84
|
}
|
|
@@ -226,82 +93,35 @@ function createPackagesRouter(apiKeys) {
|
|
|
226
93
|
// via their own updater. npm install -g would write a separate npm copy
|
|
227
94
|
// that isn't the running binary, so it must not be used here.
|
|
228
95
|
if (config.update === 'native' && config.bin) {
|
|
229
|
-
|
|
230
|
-
try {
|
|
231
|
-
(0, child_process_1.execSync)(`${config.bin} update`, {
|
|
232
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
233
|
-
timeout: 300000,
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
catch (err) {
|
|
237
|
-
updateErr = err;
|
|
238
|
-
}
|
|
96
|
+
const updateErr = (0, registry_1.runNativeUpdate)(config);
|
|
239
97
|
if (updateErr !== null) {
|
|
240
|
-
|
|
241
|
-
updateErr.message ??
|
|
242
|
-
'update failed';
|
|
243
|
-
res.status(500).json({ error: stderr });
|
|
98
|
+
res.status(500).json({ error: updateErr });
|
|
244
99
|
return;
|
|
245
100
|
}
|
|
246
101
|
// Invalidate version cache and re-read the actual binary version.
|
|
247
102
|
// The native updater may legitimately be a no-op (already newest on its
|
|
248
103
|
// own channel), so report `updated` from whether the version changed.
|
|
249
104
|
versionCache = null;
|
|
250
|
-
const to = resolveCurrent(config);
|
|
105
|
+
const to = (0, registry_1.resolveCurrent)(config);
|
|
251
106
|
res.json({ package: packageName, from, to, updated: to !== from, warning: null });
|
|
252
107
|
return;
|
|
253
108
|
}
|
|
254
109
|
// npm-global packages (e.g. claude-gateway) update via npm install -g.
|
|
255
|
-
|
|
256
|
-
let npmRoot = '';
|
|
257
|
-
try {
|
|
258
|
-
npmRoot = getNpmGlobalRoot();
|
|
259
|
-
}
|
|
260
|
-
catch {
|
|
261
|
-
// non-fatal: skip pre-clean if npm root unavailable
|
|
262
|
-
}
|
|
263
|
-
// Pre-clean any stale npm temp dirs left by previous interrupted installs
|
|
264
|
-
if (npmRoot) {
|
|
265
|
-
cleanStaleNpmTempDirs(npmRoot, packageName);
|
|
266
|
-
}
|
|
267
|
-
let installErr = null;
|
|
268
|
-
try {
|
|
269
|
-
(0, child_process_1.execSync)(`npm install -g ${packageName}@latest`, {
|
|
270
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
271
|
-
timeout: 300000,
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
catch (err) {
|
|
275
|
-
const stderr = err.stderr?.toString() ?? '';
|
|
276
|
-
if (npmRoot && (stderr.includes('ENOTEMPTY') || stderr.includes('ENOTDIR'))) {
|
|
277
|
-
// Remove stale temp dirs and the partially-installed package dir, then retry once
|
|
278
|
-
cleanStaleNpmTempDirs(npmRoot, packageName);
|
|
279
|
-
removePackageDir(npmRoot, packageName);
|
|
280
|
-
try {
|
|
281
|
-
(0, child_process_1.execSync)(`npm install -g ${packageName}@latest`, {
|
|
282
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
283
|
-
timeout: 300000,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
catch (retryErr) {
|
|
287
|
-
installErr = retryErr;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
installErr = err;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
110
|
+
const installErr = (0, registry_1.installNpmLatest)(packageName);
|
|
294
111
|
if (installErr !== null) {
|
|
295
|
-
|
|
296
|
-
res.status(500).json({ error: stderr });
|
|
112
|
+
res.status(500).json({ error: installErr });
|
|
297
113
|
return;
|
|
298
114
|
}
|
|
299
115
|
// Invalidate version cache after successful install
|
|
300
116
|
versionCache = null;
|
|
301
|
-
const to = getNpmListVersion(packageName);
|
|
117
|
+
const to = (0, registry_1.getNpmListVersion)(packageName);
|
|
302
118
|
if (name === 'claude-gateway') {
|
|
303
|
-
|
|
304
|
-
|
|
119
|
+
// `claimSupervisorEnv()` scrubs the inherited markers at boot and records
|
|
120
|
+
// the supervisor in their place; the raw markers are still honoured for
|
|
121
|
+
// a server embedded without going through that entry point.
|
|
122
|
+
const claimed = process.env.CLAUDE_GATEWAY_SUPERVISOR;
|
|
123
|
+
const isSystemd = claimed === 'systemd' || !!process.env.INVOCATION_ID;
|
|
124
|
+
const isPm2 = claimed === 'pm2' || !!process.env.PM2_HOME || process.env.pm_id !== undefined;
|
|
305
125
|
const isManaged = isSystemd || isPm2;
|
|
306
126
|
res.json({
|
|
307
127
|
package: packageName,
|
package/dist/api/packages.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packages.js","sourceRoot":"","sources":["../../src/api/packages.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"packages.js","sourceRoot":"","sources":["../../src/api/packages.ts"],"names":[],"mappings":";;AAmCA,kCAEC;AAED,gCAEC;AAED,4BAEC;AAED,oDA2IC;AA1LD,qCAAoD;AAEpD,iCAA0D;AAC1D,mDAU8B;AAiB9B,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,IAAI,YAAY,GAAsB,IAAI,CAAC;AAC3C,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB,SAAgB,WAAW;IACzB,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED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;gBACN,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7E,CAAC;QACH,CAAC;gBAAS,CAAC;YACT,UAAU,GAAG,KAAK,CAAC;QACrB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Router, RequestHandler } from 'express';
|
|
2
|
+
/**
|
|
3
|
+
* Route registry — the single source of truth that ties an HTTP route to its
|
|
4
|
+
* friendly CLI command and its documentation entry.
|
|
5
|
+
*
|
|
6
|
+
* A converted router registers each route with {@link defineRoute}, which does
|
|
7
|
+
* two things in one call:
|
|
8
|
+
* 1. mounts the handler on the Express router exactly as `router.get(...)` would, and
|
|
9
|
+
* 2. records the route's metadata (method, path, auth, CLI mapping) into a
|
|
10
|
+
* module-global manifest.
|
|
11
|
+
*
|
|
12
|
+
* Because the mount and the metadata come from the same call, they can never
|
|
13
|
+
* drift. The manifest feeds:
|
|
14
|
+
* - `GET /api/v1/_meta/routes` at runtime (populated as routers are created), and
|
|
15
|
+
* - `scripts/gen-cli.ts` at build time (which calls each converted router
|
|
16
|
+
* factory with throwaway deps to populate the manifest WITHOUT booting the
|
|
17
|
+
* server — handlers are mounted but never invoked, so no deps are needed).
|
|
18
|
+
*
|
|
19
|
+
* Adding a CLI-exposed endpoint is therefore a single edit: one `defineRoute`
|
|
20
|
+
* call yields the API route, the CLI command, and the doc entry together.
|
|
21
|
+
*/
|
|
22
|
+
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
23
|
+
/** Auth requirement for a route, for docs/help only (the actual enforcement is
|
|
24
|
+
* the router's own middleware — this is descriptive metadata). */
|
|
25
|
+
export type AuthLevel = 'none' | 'key' | 'admin';
|
|
26
|
+
/** A CLI flag derived from a query or body parameter. */
|
|
27
|
+
export interface CliFlag {
|
|
28
|
+
/** Flag name as typed on the CLI, e.g. `agent` → `--agent`. */
|
|
29
|
+
name: string;
|
|
30
|
+
/** Where the value is sent: query string or request body. */
|
|
31
|
+
in: 'query' | 'body';
|
|
32
|
+
/** A boolean flag (`--force`) takes no value. */
|
|
33
|
+
boolean?: boolean;
|
|
34
|
+
required?: boolean;
|
|
35
|
+
description?: string;
|
|
36
|
+
}
|
|
37
|
+
/** Maps a route to a friendly `<noun> <verb>` CLI command. */
|
|
38
|
+
export interface CliMapping {
|
|
39
|
+
/** Resource group, plural for resources (`crons`, `agents`, `sessions`). */
|
|
40
|
+
noun: string;
|
|
41
|
+
/** Action within the noun (`list`, `create`, `run`, `restart`). */
|
|
42
|
+
verb: string;
|
|
43
|
+
/** Path params in order → positional CLI args (`:id` → `['id']`). */
|
|
44
|
+
args?: string[];
|
|
45
|
+
/** Query/body params exposed as `--flags`. Body-heavy routes may also accept a
|
|
46
|
+
* generic `--data <json>`; declared body flags are merged over it. */
|
|
47
|
+
flags?: CliFlag[];
|
|
48
|
+
}
|
|
49
|
+
/** One route's metadata. `cli: null` marks a route intentionally NOT exposed as
|
|
50
|
+
* a friendly command (still reachable via the `api` passthrough). */
|
|
51
|
+
export interface RouteDef {
|
|
52
|
+
method: HttpMethod;
|
|
53
|
+
path: string;
|
|
54
|
+
auth: AuthLevel;
|
|
55
|
+
summary: string;
|
|
56
|
+
cli?: CliMapping | null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clear the manifest. Call before repopulating (codegen, tests).
|
|
60
|
+
*
|
|
61
|
+
* Not called anywhere on the live server boot path today — `defineRoute`'s own
|
|
62
|
+
* dedup keeps re-mounting the same routes from piling up duplicates, but if a
|
|
63
|
+
* `GatewayRouter` is ever re-instantiated in-process with a *different* route
|
|
64
|
+
* set (e.g. a future hot-reload path), stale entries from the first
|
|
65
|
+
* instantiation would linger here and leak into `GET /_meta/routes`. Call this
|
|
66
|
+
* before any such re-instantiation.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resetRegisteredRoutes(): void;
|
|
69
|
+
/** Snapshot of the manifest (deep-copied so callers can't mutate it). */
|
|
70
|
+
export declare function getRegisteredRoutes(): RouteDef[];
|
|
71
|
+
/**
|
|
72
|
+
* Mount `handlers` on `router` for `def.method`/`def.path` (identical to
|
|
73
|
+
* `router[method](path, ...handlers)`) AND record `def` in the manifest.
|
|
74
|
+
*
|
|
75
|
+
* The metadata is deduped by `method + path` so that calling a router factory
|
|
76
|
+
* more than once (as tests do per-app, and codegen does across a run) does not
|
|
77
|
+
* pile up duplicate entries. The mount always happens so each router instance
|
|
78
|
+
* gets its own routes.
|
|
79
|
+
*/
|
|
80
|
+
export declare function defineRoute(router: Router, def: RouteDef, ...handlers: RequestHandler[]): void;
|
|
81
|
+
//# sourceMappingURL=route-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-registry.d.ts","sourceRoot":"","sources":["../../src/api/route-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;AAErE;mEACmE;AACnE,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;AAEjD,yDAAyD;AACzD,MAAM,WAAW,OAAO;IACtB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,6DAA6D;IAC7D,EAAE,EAAE,OAAO,GAAG,MAAM,CAAC;IACrB,iDAAiD;IACjD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,8DAA8D;AAC9D,MAAM,WAAW,UAAU;IACzB,4EAA4E;IAC5E,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB;2EACuE;IACvE,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;CACnB;AAED;sEACsE;AACtE,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;CACzB;AAID;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,IAAI,QAAQ,EAAE,CAEhD;AAMD;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI,CAO9F"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetRegisteredRoutes = resetRegisteredRoutes;
|
|
4
|
+
exports.getRegisteredRoutes = getRegisteredRoutes;
|
|
5
|
+
exports.defineRoute = defineRoute;
|
|
6
|
+
const registered = [];
|
|
7
|
+
/**
|
|
8
|
+
* Clear the manifest. Call before repopulating (codegen, tests).
|
|
9
|
+
*
|
|
10
|
+
* Not called anywhere on the live server boot path today — `defineRoute`'s own
|
|
11
|
+
* dedup keeps re-mounting the same routes from piling up duplicates, but if a
|
|
12
|
+
* `GatewayRouter` is ever re-instantiated in-process with a *different* route
|
|
13
|
+
* set (e.g. a future hot-reload path), stale entries from the first
|
|
14
|
+
* instantiation would linger here and leak into `GET /_meta/routes`. Call this
|
|
15
|
+
* before any such re-instantiation.
|
|
16
|
+
*/
|
|
17
|
+
function resetRegisteredRoutes() {
|
|
18
|
+
registered.length = 0;
|
|
19
|
+
}
|
|
20
|
+
/** Snapshot of the manifest (deep-copied so callers can't mutate it). */
|
|
21
|
+
function getRegisteredRoutes() {
|
|
22
|
+
return registered.map((r) => ({ ...r, cli: r.cli ? { ...r.cli } : r.cli }));
|
|
23
|
+
}
|
|
24
|
+
function metaKey(method, path) {
|
|
25
|
+
return `${method} ${path}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Mount `handlers` on `router` for `def.method`/`def.path` (identical to
|
|
29
|
+
* `router[method](path, ...handlers)`) AND record `def` in the manifest.
|
|
30
|
+
*
|
|
31
|
+
* The metadata is deduped by `method + path` so that calling a router factory
|
|
32
|
+
* more than once (as tests do per-app, and codegen does across a run) does not
|
|
33
|
+
* pile up duplicate entries. The mount always happens so each router instance
|
|
34
|
+
* gets its own routes.
|
|
35
|
+
*/
|
|
36
|
+
function defineRoute(router, def, ...handlers) {
|
|
37
|
+
const key = metaKey(def.method, def.path);
|
|
38
|
+
if (!registered.some((r) => metaKey(r.method, r.path) === key)) {
|
|
39
|
+
registered.push({ ...def, cli: def.cli ? { ...def.cli } : def.cli });
|
|
40
|
+
}
|
|
41
|
+
const m = def.method.toLowerCase();
|
|
42
|
+
router[m](def.path, ...handlers);
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=route-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-registry.js","sourceRoot":"","sources":["../../src/api/route-registry.ts"],"names":[],"mappings":";;AA4EA,sDAEC;AAGD,kDAEC;AAeD,kCAOC;AAzCD,MAAM,UAAU,GAAe,EAAE,CAAC;AAElC;;;;;;;;;GASG;AACH,SAAgB,qBAAqB;IACnC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC;AACxB,CAAC;AAED,yEAAyE;AACzE,SAAgB,mBAAmB;IACjC,OAAO,UAAU,CAA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AE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAe,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/api/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAqB,MAAM,SAAS,CAAC;AAOpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAe,WAAW,EAAE,MAAM,UAAU,CAAC;AAgDzE,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAExD;AAMD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAEtD;AAoID,wBAAgB,eAAe,CAC7B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EACtC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EACtC,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW,EAAE,GACrB,MAAM,CAwjGR"}
|
package/dist/api/router.js
CHANGED
|
@@ -51,6 +51,8 @@ const types_1 = require("../history/types");
|
|
|
51
51
|
const wizard_state_1 = require("./wizard-state");
|
|
52
52
|
const pending_senders_1 = require("./pending-senders");
|
|
53
53
|
const create_agent_prompts_1 = require("../agent/create-agent-prompts");
|
|
54
|
+
const model_catalog_1 = require("../agent/model-catalog");
|
|
55
|
+
const runner_2 = require("../agent/runner");
|
|
54
56
|
const MAX_MESSAGE_LENGTH = 10000;
|
|
55
57
|
const DEFAULT_TIMEOUT_MS = 60000;
|
|
56
58
|
/**
|
|
@@ -546,10 +548,26 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
|
|
|
546
548
|
/**
|
|
547
549
|
* GET /api/v1/models
|
|
548
550
|
*
|
|
549
|
-
* List
|
|
551
|
+
* List the models this gateway offers. Fetches the live catalog when a base
|
|
552
|
+
* URL is configured and falls back to the gateway's configured/static list —
|
|
553
|
+
* without the fetch this endpoint could only ever report what was written
|
|
554
|
+
* into config.json at provisioning time (issue #409).
|
|
550
555
|
*/
|
|
551
|
-
router.get('/v1/models', auth, (_req, res) => {
|
|
552
|
-
|
|
556
|
+
router.get('/v1/models', auth, async (_req, res) => {
|
|
557
|
+
// `?? DEFAULT_MODELS`, not `?? []`, and that is load-bearing rather than
|
|
558
|
+
// cosmetic. fetchModelCatalog caches one parsed catalog per process, and
|
|
559
|
+
// the alias/contextWindow/multiplier on it are inherited from whichever
|
|
560
|
+
// caller's list populated the cache first. AgentRunner passes
|
|
561
|
+
// `gateway.models ?? DEFAULT_MODELS`; if this route passed `[]` on a
|
|
562
|
+
// gateway whose config has no `gateway.models`, one request here would
|
|
563
|
+
// cache a catalog with every alias set to its id and every context window
|
|
564
|
+
// at the 200k default — and the picker and all six contextWindowFor()
|
|
565
|
+
// callers would read that degraded list for the next 60 seconds. It also
|
|
566
|
+
// makes this endpoint agree with the picker on an unconfigured gateway
|
|
567
|
+
// instead of reporting no models at all.
|
|
568
|
+
const staticModels = models ?? runner_2.DEFAULT_MODELS;
|
|
569
|
+
const available = (await (0, model_catalog_1.fetchModelCatalog)(staticModels)) ?? staticModels;
|
|
570
|
+
res.json({ models: available.map((m) => ({ id: m.id, name: m.label, alias: m.alias, contextWindow: m.contextWindow, multiplier: m.multiplier ?? 1 })) });
|
|
553
571
|
});
|
|
554
572
|
/**
|
|
555
573
|
* GET /api/v1/agents
|