@0xmaxma/claude-gateway 2.1.2 → 2.1.3
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/dist/apps/agent-manager.d.ts +15 -0
- package/dist/apps/agent-manager.d.ts.map +1 -1
- package/dist/apps/agent-manager.js +66 -1
- package/dist/apps/agent-manager.js.map +1 -1
- package/dist/apps/compose-generator.d.ts +4 -0
- package/dist/apps/compose-generator.d.ts.map +1 -1
- package/dist/apps/compose-generator.js +19 -3
- package/dist/apps/compose-generator.js.map +1 -1
- package/dist/apps/installer.d.ts +7 -3
- package/dist/apps/installer.d.ts.map +1 -1
- package/dist/apps/installer.js +84 -18
- package/dist/apps/installer.js.map +1 -1
- package/dist/apps/registry.d.ts +1 -0
- package/dist/apps/registry.d.ts.map +1 -1
- package/dist/build-provenance.json +4 -4
- package/dist/orchestration/delivery.d.ts.map +1 -1
- package/dist/orchestration/delivery.js +17 -8
- package/dist/orchestration/delivery.js.map +1 -1
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +21 -11
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/store.d.ts +9 -0
- package/dist/orchestration/store.d.ts.map +1 -1
- package/dist/orchestration/store.js +13 -1
- package/dist/orchestration/store.js.map +1 -1
- package/dist/orchestration/telegram-speech.d.ts.map +1 -1
- package/dist/orchestration/telegram-speech.js +0 -2
- package/dist/orchestration/telegram-speech.js.map +1 -1
- package/dist/voice/errors.d.ts +1 -3
- package/dist/voice/errors.d.ts.map +1 -1
- package/dist/voice/errors.js +8 -3
- package/dist/voice/errors.js.map +1 -1
- package/dist/voice/notes.d.ts.map +1 -1
- package/dist/voice/notes.js +1 -0
- package/dist/voice/notes.js.map +1 -1
- package/mcp/tools/apps/skills/create-app-yaml/SKILL.md +1 -1
- package/package.json +1 -1
package/dist/apps/installer.js
CHANGED
|
@@ -45,6 +45,7 @@ const os = __importStar(require("node:os"));
|
|
|
45
45
|
const crypto = __importStar(require("node:crypto"));
|
|
46
46
|
const node_child_process_1 = require("node:child_process");
|
|
47
47
|
const compose_generator_1 = require("./compose-generator");
|
|
48
|
+
const agent_manager_1 = require("./agent-manager");
|
|
48
49
|
const cleanup_1 = require("../history/cleanup");
|
|
49
50
|
const config_num_1 = require("../utils/config-num");
|
|
50
51
|
// ─── Constants ────────────────────────────────────────────────────────────────
|
|
@@ -104,6 +105,20 @@ const APP_NAME_RE = /^[a-z0-9][a-z0-9-]{1,63}$/;
|
|
|
104
105
|
* scheduler at boot — config is untrusted input, so a typo must degrade to UTC,
|
|
105
106
|
* never crash the gateway.
|
|
106
107
|
*/
|
|
108
|
+
/** How app.yaml changes the app's agent registration, or null when name, path and presence all match. */
|
|
109
|
+
function agentIdentityChange(oldAgent, newAgent) {
|
|
110
|
+
if (!oldAgent && newAgent)
|
|
111
|
+
return `adds agent "${newAgent.name}"`;
|
|
112
|
+
if (oldAgent && !newAgent)
|
|
113
|
+
return `removes agent "${oldAgent.name}"`;
|
|
114
|
+
if (!oldAgent || !newAgent)
|
|
115
|
+
return null;
|
|
116
|
+
if (oldAgent.name !== newAgent.name)
|
|
117
|
+
return `renames agent "${oldAgent.name}" to "${newAgent.name}"`;
|
|
118
|
+
if (path.posix.resolve('/', oldAgent.path) !== path.posix.resolve('/', newAgent.path))
|
|
119
|
+
return `moves agent "${newAgent.name}" from ${oldAgent.path} to ${newAgent.path}`;
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
107
122
|
function isValidTimezone(tz) {
|
|
108
123
|
if (typeof tz !== 'string' || tz.length === 0)
|
|
109
124
|
return false;
|
|
@@ -810,8 +825,12 @@ class AppInstaller {
|
|
|
810
825
|
// Restore config that carries generated secrets, so the app boots with the
|
|
811
826
|
// same credentials the volume data was created under.
|
|
812
827
|
this.copyIfExists(path.join(staging, 'config', '.env'), path.join(appDir, '.env'));
|
|
828
|
+
if (entry.agentDeclaration)
|
|
829
|
+
(0, agent_manager_1.writeAgentEnvFile)(appDir, entry.agentDeclaration);
|
|
813
830
|
log(`Starting "${appName}" on restored data`);
|
|
814
|
-
|
|
831
|
+
// Recreate: compose does not notice a changed env_file, so a plain `up`
|
|
832
|
+
// would restart the containers with the pre-restore .env/.env.agent.
|
|
833
|
+
await this.composeUp(appName, appDir, undefined, { forceRecreate: true });
|
|
815
834
|
await this.registry.updateStatus(appName, 'running').catch(() => { });
|
|
816
835
|
log(`Restore of "${backupId}" complete`);
|
|
817
836
|
return {
|
|
@@ -1559,6 +1578,7 @@ class AppInstaller {
|
|
|
1559
1578
|
if (generated.agentDeclaration && this.agentManager && agentPaths) {
|
|
1560
1579
|
await this.agentManager.injectAgentService(entry);
|
|
1561
1580
|
this.log(job, `Agent service injected for ${generated.agentDeclaration.name}`);
|
|
1581
|
+
this.logAgentEnv(job, generated.agentDeclaration);
|
|
1562
1582
|
// Pre-pull the agent base image so compose up --wait doesn't time out during pull
|
|
1563
1583
|
this.log(job, 'Pre-pulling agent base image');
|
|
1564
1584
|
try {
|
|
@@ -1730,6 +1750,7 @@ class AppInstaller {
|
|
|
1730
1750
|
};
|
|
1731
1751
|
if (generated.agentDeclaration && this.agentManager && agentPaths) {
|
|
1732
1752
|
await this.agentManager.injectAgentService(newEntry);
|
|
1753
|
+
this.logAgentEnv(job, generated.agentDeclaration);
|
|
1733
1754
|
}
|
|
1734
1755
|
// Pin the images the app is running before the build takes their tags
|
|
1735
1756
|
// over. A `build:` service's new image reuses the old tag
|
|
@@ -1999,9 +2020,10 @@ class AppInstaller {
|
|
|
1999
2020
|
/**
|
|
2000
2021
|
* Reconfigure an installed app: merge env vars and/or override host ports,
|
|
2001
2022
|
* then force-recreate the container in place. No clone, no dir swap — the app
|
|
2002
|
-
* stays at its current commit/appDir; only its .env
|
|
2003
|
-
* compose port mappings
|
|
2004
|
-
* this is an `up --force-recreate`,
|
|
2023
|
+
* stays at its current commit/appDir; only its .env, (optionally) its
|
|
2024
|
+
* compose port mappings and its agent's memory settings change. Named
|
|
2025
|
+
* volumes and their data survive because this is an `up --force-recreate`,
|
|
2026
|
+
* never a `down -v`.
|
|
2005
2027
|
*/
|
|
2006
2028
|
async runReconfigure(job, appName, options) {
|
|
2007
2029
|
job.status = 'running';
|
|
@@ -2026,11 +2048,12 @@ class AppInstaller {
|
|
|
2026
2048
|
// Snapshot the current on-disk state BEFORE any mutation so a failed
|
|
2027
2049
|
// recreate can be rolled back. Both an env-only and a port change rewrite
|
|
2028
2050
|
// .env and force-recreate the container; a port change additionally rewrites
|
|
2029
|
-
// the live compose file and swaps proxy routes
|
|
2051
|
+
// the live compose file and swaps proxy routes, and an app agent's service is
|
|
2052
|
+
// re-injected into it. If the new container never
|
|
2030
2053
|
// comes up the app would otherwise be left down (or, for a port change,
|
|
2031
2054
|
// unreachable with routes gone and compose/registry mismatched).
|
|
2032
2055
|
const envPath = path.join(appDir, '.env');
|
|
2033
|
-
const oldComposeContent =
|
|
2056
|
+
const oldComposeContent = fs.existsSync(composePath) ? fs.readFileSync(composePath, 'utf-8') : null;
|
|
2034
2057
|
const oldEnvContent = fs.existsSync(envPath) ? fs.readFileSync(envPath, 'utf-8') : null;
|
|
2035
2058
|
const oldPorts = entry.ports;
|
|
2036
2059
|
// Compute (and validate) the port metadata. Always generate to a TEMP file
|
|
@@ -2051,6 +2074,16 @@ class AppInstaller {
|
|
|
2051
2074
|
fs.rmSync(tmpCompose, { force: true });
|
|
2052
2075
|
}
|
|
2053
2076
|
}
|
|
2077
|
+
// Reconfigure applies the agent's settings but not its identity: a renamed,
|
|
2078
|
+
// moved, added or removed agent needs the deregister/re-register that only
|
|
2079
|
+
// update and install do. Refuse before anything is touched.
|
|
2080
|
+
const oldAgent = entry.agentDeclaration ?? null;
|
|
2081
|
+
const newAgent = generated.agentDeclaration;
|
|
2082
|
+
const agentChange = agentIdentityChange(oldAgent, newAgent);
|
|
2083
|
+
if (agentChange) {
|
|
2084
|
+
throw new Error(`app.yaml for "${appName}" ${agentChange} — reconfigure cannot change the agent registration; use update or reinstall instead`);
|
|
2085
|
+
}
|
|
2086
|
+
const nextEntry = newAgent ? { ...entry, agentDeclaration: newAgent } : entry;
|
|
2054
2087
|
// Host-port collision across other installed apps (only if ports changed).
|
|
2055
2088
|
// Runs before the live compose is touched, so a collision leaves nothing to
|
|
2056
2089
|
// undo on disk.
|
|
@@ -2067,14 +2100,12 @@ class AppInstaller {
|
|
|
2067
2100
|
try {
|
|
2068
2101
|
// Swap in the newly-generated compose only now that we're inside the
|
|
2069
2102
|
// guard (finding F2). Regenerating drops the injected agent service, so we
|
|
2070
|
-
// re-inject it. An env-only reconfigure
|
|
2103
|
+
// re-inject it. An env-only reconfigure re-injects it too when the agent
|
|
2104
|
+
// was injected (it has agentPaths), so an agent service from before #618
|
|
2105
|
+
// stops reading the app's full .env.
|
|
2071
2106
|
if (hasPortChange) {
|
|
2072
2107
|
this.log(job, 'Updating docker-compose.yml');
|
|
2073
2108
|
fs.writeFileSync(composePath, newComposeContent);
|
|
2074
|
-
if (generated.agentDeclaration && this.agentManager) {
|
|
2075
|
-
const agentPaths = entry.agentPaths ?? this.agentManager.detectAgentPaths();
|
|
2076
|
-
await this.agentManager.injectAgentService({ ...entry, agentPaths });
|
|
2077
|
-
}
|
|
2078
2109
|
}
|
|
2079
2110
|
// Merge the new env vars onto the existing .env: keys not supplied are
|
|
2080
2111
|
// preserved, and existing generated-secret values are carried over rather
|
|
@@ -2082,6 +2113,12 @@ class AppInstaller {
|
|
|
2082
2113
|
this.log(job, 'Writing .env');
|
|
2083
2114
|
const mergedEnv = { ...this.readEnvFile(appDir), ...(options.envVars ?? {}) };
|
|
2084
2115
|
this.writeEnvFile(appDir, appName, generated, mergedEnv);
|
|
2116
|
+
// After .env: injecting rewrites .env.agent from it.
|
|
2117
|
+
if (newAgent && this.agentManager && (hasPortChange || entry.agentPaths)) {
|
|
2118
|
+
const agentPaths = entry.agentPaths ?? this.agentManager.detectAgentPaths();
|
|
2119
|
+
await this.agentManager.injectAgentService({ ...nextEntry, agentPaths });
|
|
2120
|
+
this.logAgentEnv(job, newAgent);
|
|
2121
|
+
}
|
|
2085
2122
|
// Deregister old proxy routes before the port mapping changes (the proxy is
|
|
2086
2123
|
// bound to the old hostPort).
|
|
2087
2124
|
if (hasPortChange) {
|
|
@@ -2092,11 +2129,10 @@ class AppInstaller {
|
|
|
2092
2129
|
// `up`, not a `down -v`, so named volumes (and their data) survive.
|
|
2093
2130
|
this.log(job, 'Recreating container');
|
|
2094
2131
|
await this.composeUp(appName, appDir, job, { forceRecreate: true });
|
|
2095
|
-
|
|
2096
|
-
//
|
|
2097
|
-
//
|
|
2098
|
-
|
|
2099
|
-
const updatedEntry = { ...entry, updatedAt: new Date().toISOString() };
|
|
2132
|
+
// Persist the reconfigure: the container is up again (an app reconfigured
|
|
2133
|
+
// while stopped or errored is now running), updatedAt is bumped, and the
|
|
2134
|
+
// port mappings + proxy routes are refreshed only when a host port changed.
|
|
2135
|
+
const updatedEntry = { ...nextEntry, status: 'running', updatedAt: new Date().toISOString() };
|
|
2100
2136
|
if (hasPortChange) {
|
|
2101
2137
|
updatedEntry.ports = generated.ports.map((p) => ({
|
|
2102
2138
|
name: p.name,
|
|
@@ -2126,9 +2162,17 @@ class AppInstaller {
|
|
|
2126
2162
|
fs.writeFileSync(envPath, oldEnvContent, { mode: 0o600 });
|
|
2127
2163
|
fs.chmodSync(envPath, 0o600);
|
|
2128
2164
|
}
|
|
2129
|
-
if (
|
|
2165
|
+
if (oldComposeContent !== null) {
|
|
2130
2166
|
fs.writeFileSync(composePath, oldComposeContent);
|
|
2131
2167
|
}
|
|
2168
|
+
if (oldAgent) {
|
|
2169
|
+
try {
|
|
2170
|
+
(0, agent_manager_1.writeAgentEnvFile)(appDir, oldAgent);
|
|
2171
|
+
}
|
|
2172
|
+
catch (envErr) {
|
|
2173
|
+
this.log(job, `Could not restore .env.agent: ${envErr.message}`);
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2132
2176
|
await this.composeUp(appName, appDir, job, { forceRecreate: true });
|
|
2133
2177
|
if (hasPortChange) {
|
|
2134
2178
|
this.callbacks.registerRoutes(appName, oldPorts.map((p) => ({
|
|
@@ -2147,6 +2191,22 @@ class AppInstaller {
|
|
|
2147
2191
|
}
|
|
2148
2192
|
throw reconfErr;
|
|
2149
2193
|
}
|
|
2194
|
+
// Write the declared isolate_memory/disable_archive into the agent's
|
|
2195
|
+
// config.json entry. When they differ from what the agent runs with, the
|
|
2196
|
+
// config watcher replaces its runner once idle, as after an update.
|
|
2197
|
+
if (newAgent && this.agentManager) {
|
|
2198
|
+
let synced;
|
|
2199
|
+
try {
|
|
2200
|
+
synced = await this.agentManager.syncMemoryModes(nextEntry);
|
|
2201
|
+
}
|
|
2202
|
+
catch (err) {
|
|
2203
|
+
// apps.json already holds the new modes; gateway start applies them from there.
|
|
2204
|
+
throw new Error(`Reconfigure applied, but agent "${newAgent.name}" config entry was not updated (${err.message}) — its memory settings take effect at the next gateway start`);
|
|
2205
|
+
}
|
|
2206
|
+
this.log(job, synced
|
|
2207
|
+
? `Agent "${newAgent.name}" memory settings written — a changed isolate_memory or disable_archive applies once the agent is idle`
|
|
2208
|
+
: `Agent "${newAgent.name}" is not registered — its memory settings apply at the next gateway start`);
|
|
2209
|
+
}
|
|
2150
2210
|
const proxyUrls = {};
|
|
2151
2211
|
for (const p of generated.ports) {
|
|
2152
2212
|
proxyUrls[p.name] = `/app/${appName}/${p.name}/`;
|
|
@@ -2156,7 +2216,7 @@ class AppInstaller {
|
|
|
2156
2216
|
appName,
|
|
2157
2217
|
proxyUrls,
|
|
2158
2218
|
secretKeys: generated.secretKeys,
|
|
2159
|
-
agentDeclaration:
|
|
2219
|
+
agentDeclaration: newAgent,
|
|
2160
2220
|
};
|
|
2161
2221
|
job.updatedAt = Date.now();
|
|
2162
2222
|
this.log(job, `Reconfigure complete: ${JSON.stringify(proxyUrls)}`);
|
|
@@ -2245,6 +2305,12 @@ class AppInstaller {
|
|
|
2245
2305
|
}
|
|
2246
2306
|
return generatedNames;
|
|
2247
2307
|
}
|
|
2308
|
+
/** Say which app secrets the agent container gets: an agent from before #618 had them all. */
|
|
2309
|
+
logAgentEnv(job, declaration) {
|
|
2310
|
+
this.log(job, declaration.env?.length
|
|
2311
|
+
? `Agent container gets app secrets: ${declaration.env.join(', ')}`
|
|
2312
|
+
: 'Agent container gets no app secrets (app.yaml services.agent.env is not set)');
|
|
2313
|
+
}
|
|
2248
2314
|
/** Parse an app's existing .env into a key→value map (empty if absent). */
|
|
2249
2315
|
readEnvFile(appDir) {
|
|
2250
2316
|
const envPath = path.join(appDir, '.env');
|