@agentage/extension 0.15.0 → 0.15.2
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/contracts/index.d.ts +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/discovery/discovery.d.ts +10 -25
- package/dist/discovery/discovery.js +7 -1
- package/dist/discovery/discovery.schema.d.ts +45 -0
- package/dist/discovery/discovery.schema.js +33 -4
- package/dist/discovery/served-extras.d.ts +8 -0
- package/dist/discovery/served-extras.js +10 -0
- package/dist/host/daemon/add.d.ts +2 -0
- package/dist/host/daemon/add.js +10 -1
- package/dist/host/daemon/child-files.d.ts +2 -2
- package/dist/host/daemon/child-files.js +16 -8
- package/dist/host/daemon/child.d.ts +1 -1
- package/dist/host/daemon/child.js +8 -11
- package/dist/host/daemon/daemon-files.js +18 -3
- package/dist/host/daemon/daemon.js +3 -3
- package/dist/host/daemon/health-routes.d.ts +0 -1
- package/dist/host/daemon/health-routes.js +2 -2
- package/dist/host/daemon/installation.js +2 -4
- package/dist/host/daemon/json-file.d.ts +2 -0
- package/dist/host/daemon/json-file.js +38 -10
- package/dist/host/daemon/ops.js +4 -2
- package/dist/host/daemon/proxy.d.ts +6 -1
- package/dist/host/daemon/proxy.js +13 -4
- package/dist/host/daemon/redact-stream.d.ts +4 -0
- package/dist/host/daemon/redact-stream.js +24 -0
- package/dist/host/daemon/reload-marker.js +2 -1
- package/dist/host/daemon/reload.js +3 -4
- package/dist/host/daemon/routes.js +9 -5
- package/dist/host/daemon/seal-reach.js +1 -1
- package/dist/host/daemon/seal.d.ts +2 -2
- package/dist/host/daemon/seal.js +1 -1
- package/dist/host/daemon/start-checks.d.ts +1 -1
- package/dist/host/daemon/start-checks.js +6 -5
- package/dist/host/daemon/supervisor.d.ts +1 -4
- package/dist/host/daemon/supervisor.js +15 -17
- package/dist/host/host-extension.d.ts +3 -0
- package/dist/host/host-extension.js +12 -2
- package/dist/host/host-parts.d.ts +1 -1
- package/dist/host/host-parts.js +11 -4
- package/dist/host/serve-host.js +4 -3
- package/dist/manifest/parts.d.ts +2 -1
- package/dist/manifest/parts.js +1 -1
- package/dist/mcp/mcp-app.d.ts +0 -1
- package/dist/mcp/mcp-app.js +1 -1
- package/dist/runtime/part-mounts.d.ts +3 -1
- package/dist/runtime/part-mounts.js +7 -2
- package/dist/server/app.d.ts +2 -3
- package/dist/server/app.js +0 -1
- package/dist/tool/build.d.ts +1 -0
- package/dist/tool/build.js +3 -2
- package/dist/tool/check.d.ts +1 -1
- package/dist/tool/check.js +2 -1
- package/dist/tool/format.d.ts +1 -0
- package/dist/tool/format.js +3 -1
- package/dist/tool/record-extras.js +5 -12
- package/dist/worker/clock.d.ts +0 -1
- package/dist/worker/clock.js +1 -1
- package/dist/worker/scheduler.d.ts +1 -1
- package/dist/worker/scheduler.js +12 -2
- package/package.json +1 -1
- package/schemas/extension-discovery.schema.json +61 -34
- package/schemas/extension-record.schema.json +1 -1
- package/dist/host/daemon/reload-route.d.ts +0 -4
- package/dist/host/daemon/reload-route.js +0 -21
|
@@ -6,18 +6,27 @@ import { carriesHostToken } from './host-token.js';
|
|
|
6
6
|
import { enter } from './lane.js';
|
|
7
7
|
import {} from './entries.js';
|
|
8
8
|
import {} from './limits.js';
|
|
9
|
+
import { stopsNow } from './stopping.js';
|
|
10
|
+
import {} from './supervisor.js';
|
|
11
|
+
// With no child: the daemon stops, a change still holds it (state still running), or its state.
|
|
12
|
+
const noLane = (entry, stopping) => {
|
|
13
|
+
if (stopping?.signal.aborted)
|
|
14
|
+
return stopsNow();
|
|
15
|
+
const now = entry.state === 'running' ? 'changing' : entry.state;
|
|
16
|
+
return fail('UNAVAILABLE', `${entry.id} is ${now}: try again`, { retryAfter: 5 });
|
|
17
|
+
};
|
|
9
18
|
// 404 not installed or disabled (chosen, not to retry); 503 starting, failed, or held past gateMs.
|
|
10
|
-
const laneFor = async (entries, id,
|
|
19
|
+
const laneFor = async (entries, id, limits) => {
|
|
11
20
|
const entry = entries.get(id);
|
|
12
21
|
if (!entry)
|
|
13
22
|
throw fail('NOT_FOUND', `${id} is not installed`);
|
|
14
23
|
if (entry.state === 'disabled')
|
|
15
24
|
throw fail('NOT_FOUND', `${id} is disabled`);
|
|
16
25
|
if (entry.gate)
|
|
17
|
-
await Promise.race([entry.gate, sleep(gateMs, undefined, { ref: false })]);
|
|
26
|
+
await Promise.race([entry.gate, sleep(limits.gateMs, undefined, { ref: false })]);
|
|
18
27
|
const lane = entry.lane;
|
|
19
28
|
if (!lane)
|
|
20
|
-
throw
|
|
29
|
+
throw noLane(entry, limits.stopping);
|
|
21
30
|
// Counted in the same tick it is read: a swap cannot stop this child before the request is open.
|
|
22
31
|
return { lane, leave: enter(lane) };
|
|
23
32
|
};
|
|
@@ -92,6 +101,6 @@ const forward = (req, res, next, { to, ms, hostToken }) => {
|
|
|
92
101
|
};
|
|
93
102
|
// ANY /api/{id}/* and /mcp/{id} (C1): the same lane, the same refusals (404 unknown, 503 not running).
|
|
94
103
|
export const proxyTo = (entries, limits, hostToken) => async (req, res, next) => {
|
|
95
|
-
const to = await laneFor(entries, String(req.params['id']), limits
|
|
104
|
+
const to = await laneFor(entries, String(req.params['id']), limits);
|
|
96
105
|
forward(req, res, next, { to, ms: limits.answerMs, hostToken });
|
|
97
106
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Readable, type Writable } from 'node:stream';
|
|
2
|
+
export declare const PENDING_MAX: number;
|
|
3
|
+
export declare const redactedLines: (write: (text: string) => void, secrets: Record<string, string>) => (chunk?: string) => void;
|
|
4
|
+
export declare const pipeRedacted: (from: Readable | null, to: Writable, secrets: Record<string, string>) => void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {} from 'node:stream';
|
|
2
|
+
import { maskedForms, redact } from './start-checks.js';
|
|
3
|
+
// Past this, a line with no newline is written up to a tail that could hold a split secret.
|
|
4
|
+
export const PENDING_MAX = 64 * 1024;
|
|
5
|
+
// By line, so a value split over two chunks is masked too; a call with no chunk flushes the rest.
|
|
6
|
+
export const redactedLines = (write, secrets) => {
|
|
7
|
+
const keep = Math.max(0, (maskedForms(secrets)[0]?.length ?? 1) - 1);
|
|
8
|
+
let rest = '';
|
|
9
|
+
return (chunk) => {
|
|
10
|
+
const lines = (rest + (chunk ?? '\n')).split('\n');
|
|
11
|
+
rest = lines.pop() ?? '';
|
|
12
|
+
const cut = rest.length > PENDING_MAX ? rest.length - keep : 0;
|
|
13
|
+
const out = `${lines.join('\n')}${lines.length && chunk !== undefined ? '\n' : ''}`;
|
|
14
|
+
if (out || cut)
|
|
15
|
+
write(redact(out + rest.slice(0, cut), secrets));
|
|
16
|
+
rest = rest.slice(cut);
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
// A child stream to the daemon's own, masked; its rest is written at the end.
|
|
20
|
+
export const pipeRedacted = (from, to, secrets) => {
|
|
21
|
+
const out = redactedLines((text) => to.write(text), secrets);
|
|
22
|
+
from?.on('data', (chunk) => out(chunk.toString()));
|
|
23
|
+
from?.once('end', () => out());
|
|
24
|
+
};
|
|
@@ -2,12 +2,13 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { cp, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import {} from '../../log/log.js';
|
|
5
|
+
import { runDirOf } from './daemon-files.js';
|
|
5
6
|
import {} from './supervisor.js';
|
|
6
7
|
// D14 (revised): the child runs dist/; dist.next/ is the watcher's tree and stays; dist.prev/ is the last good.
|
|
7
8
|
const DIST = 'dist';
|
|
8
9
|
const NEXT = 'dist.next';
|
|
9
10
|
const PREV = 'dist.prev';
|
|
10
|
-
const markerOf = (configDir, id) => join(configDir,
|
|
11
|
+
const markerOf = (configDir, id) => join(runDirOf(configDir, id), 'reload.json');
|
|
11
12
|
const gone = (path) => rm(path, { recursive: true, force: true });
|
|
12
13
|
// Written once a stale dist.prev is gone: marker and dist.prev together mean a swap not confirmed.
|
|
13
14
|
export const markReload = async (configDir, id, dir) => {
|
|
@@ -3,8 +3,8 @@ import { fail } from '../../envelope/envelope.js';
|
|
|
3
3
|
import { parse } from '../../envelope/parse.js';
|
|
4
4
|
import { entryOf } from './entries.js';
|
|
5
5
|
import { confirmReload, markReload, swapBack, swapIn, unmarkReload } from './reload-marker.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { halt, hold } from './gate.js';
|
|
7
|
+
import { startEntry } from './supervisor.js';
|
|
8
8
|
const ReloadSchema = z.strictObject({});
|
|
9
9
|
// Only a linked working copy has a build to reload; a disabled one stays stopped.
|
|
10
10
|
const folderOf = (entry) => {
|
|
@@ -34,13 +34,12 @@ const restoreLast = async (deps, entry, dir, swapped) => {
|
|
|
34
34
|
// The new child runs: what is left to clean is best-effort, never a second start.
|
|
35
35
|
const settle = async (deps, entry, dir) => {
|
|
36
36
|
await confirmReload(deps.configDir, entry.id, dir).catch((err) => deps.log.warn('a reload left dist.prev or its marker', { id: entry.id, reason: err.message }));
|
|
37
|
-
resetRestarts(entry);
|
|
38
37
|
return answer(entry);
|
|
39
38
|
};
|
|
40
39
|
const tryNew = async (deps, entry, dir) => {
|
|
41
40
|
await markReload(deps.configDir, entry.id, dir);
|
|
42
41
|
const swapped = await swapIn(dir);
|
|
43
|
-
const err = await startEntry(deps, entry);
|
|
42
|
+
const err = await startEntry(deps, entry, true);
|
|
44
43
|
if (!err)
|
|
45
44
|
return settle(deps, entry, dir);
|
|
46
45
|
await restoreLast(deps, entry, dir, swapped);
|
|
@@ -13,7 +13,7 @@ import { changeExtension, removeExtension } from './ops.js';
|
|
|
13
13
|
import {} from './pending.js';
|
|
14
14
|
import { waitAtMost } from './queue.js';
|
|
15
15
|
import { proxyTo } from './proxy.js';
|
|
16
|
-
import {
|
|
16
|
+
import { reloadExtension } from './reload.js';
|
|
17
17
|
import { stopsNow } from './stopping.js';
|
|
18
18
|
import {} from './supervisor.js';
|
|
19
19
|
const reasonOf = (err) => err.details?.reason;
|
|
@@ -36,6 +36,7 @@ const runner = (deps, info, p) => (what, fn) => p.track(what, () => waitAtMost(d
|
|
|
36
36
|
await checkReadable(deps, info);
|
|
37
37
|
return fn();
|
|
38
38
|
}));
|
|
39
|
+
const purge = (q) => q['purge'] === 'true';
|
|
39
40
|
const changes = (deps, entries, info, p) => {
|
|
40
41
|
const run = runner(deps, info, p);
|
|
41
42
|
const id = (params) => String(params['id']);
|
|
@@ -47,21 +48,24 @@ const changes = (deps, entries, info, p) => {
|
|
|
47
48
|
const what = { op: 'update', id: id(params) };
|
|
48
49
|
res.json(ok(await run(what, () => changeExtension(deps, entries, id(params), body))));
|
|
49
50
|
};
|
|
50
|
-
const purge = (q) => q['purge'] === 'true';
|
|
51
51
|
const remove = async ({ params, query }, res) => {
|
|
52
52
|
const what = { op: 'remove', id: id(params) };
|
|
53
53
|
res.json(ok(await run(what, () => removeExtension(deps, entries, what.id, purge(query)))));
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
const reload = async ({ params, body }, res) => {
|
|
56
|
+
const what = { op: 'reload', id: id(params) };
|
|
57
|
+
res.json(ok(await run(what, () => reloadExtension(deps, entries, what.id, body))));
|
|
58
|
+
};
|
|
59
|
+
return { add, change, remove, reload };
|
|
56
60
|
};
|
|
57
61
|
const hostRoutes = (app, deps, entries, info, p) => {
|
|
58
62
|
app.get('/host/extensions', (_req, res) => void res.json(ok([...entries.values()].map(listed))));
|
|
59
63
|
const json = express.json({ limit: BODY_LIMIT });
|
|
60
|
-
const { add, change, remove } = changes(deps, entries, info, p);
|
|
64
|
+
const { add, change, remove, reload } = changes(deps, entries, info, p);
|
|
61
65
|
app.post('/host/extensions', json, add);
|
|
62
66
|
app.patch('/host/extensions/:id', json, change);
|
|
63
67
|
app.delete('/host/extensions/:id', remove);
|
|
64
|
-
|
|
68
|
+
app.post('/host/extensions/:id/reload', json, reload);
|
|
65
69
|
};
|
|
66
70
|
// C5 and C1: /health, discovery, /host/* (host token), /api/{id}/* and /mcp/{id} to the child; Host and Origin first.
|
|
67
71
|
export const daemonApp = (deps, entries, port, info, hostToken) => {
|
|
@@ -32,7 +32,7 @@ export const assertReach = (reads, writes, configDir, id) => {
|
|
|
32
32
|
if (star)
|
|
33
33
|
throw refused(star, 'has a * that Node reads as a wildcard');
|
|
34
34
|
const configs = [configDir, real(configDir)];
|
|
35
|
-
const open = reads.find((grant) => configs.some((config) => exposes(
|
|
35
|
+
const open = reads.find((grant) => [grant, real(grant)].some((path) => configs.some((config) => exposes(path, config, id))));
|
|
36
36
|
if (open)
|
|
37
37
|
throw refused(open, 'would expose the agentage config folder');
|
|
38
38
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export type Seal = 'on' | 'off';
|
|
2
|
-
export declare const SEAL_FLOOR = "Node 22.22.2 or 24.14.1";
|
|
3
2
|
export declare const sealOf: (version: string) => Seal;
|
|
4
3
|
export declare const permissionFlag: (version: string) => boolean;
|
|
5
4
|
export declare const sealOffReason: (version: string) => string;
|
|
6
5
|
export declare const treeOf: (dir: string) => string;
|
|
7
6
|
export declare const kitReadDirs: (main: string) => string[];
|
|
8
|
-
|
|
7
|
+
interface SealAt {
|
|
9
8
|
id: string;
|
|
10
9
|
main: string;
|
|
11
10
|
dir: string;
|
|
@@ -14,3 +13,4 @@ export interface SealAt {
|
|
|
14
13
|
dataDir: string;
|
|
15
14
|
}
|
|
16
15
|
export declare const sealFlags: ({ id, main, dir, configDir, runDir, dataDir }: SealAt) => string[];
|
|
16
|
+
export {};
|
package/dist/host/daemon/seal.js
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from 'node:os';
|
|
|
3
3
|
import { dirname, join, parse, sep } from 'node:path';
|
|
4
4
|
import { assertReach, real } from './seal-reach.js';
|
|
5
5
|
// C2: the permission model with the bypass fixes of D2; the same rule as e2e sealFloorMet.
|
|
6
|
-
|
|
6
|
+
const SEAL_FLOOR = 'Node 22.22.2 or 24.14.1';
|
|
7
7
|
const versionOf = (version) => version.split('.').map(Number);
|
|
8
8
|
const atLeast = (version, major, minor, patch) => {
|
|
9
9
|
const [a = 0, b = 0, c = 0] = versionOf(version);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ExtensionPackage } from '../../manifest/manifest.schema.js';
|
|
2
|
-
export declare const NEEDS_SECRET = "NEEDS_SECRET";
|
|
3
2
|
export declare const assertSecrets: (pkg: ExtensionPackage, secrets: Record<string, string>) => void;
|
|
4
3
|
export declare const needsSecret: (err: unknown) => boolean;
|
|
5
4
|
export declare const healthy: (port: number, ms: number) => Promise<void>;
|
|
5
|
+
export declare const maskedForms: (secrets: Record<string, string>) => string[];
|
|
6
6
|
export declare const redact: (text: string, secrets: Record<string, string>) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {} from '../../manifest/manifest.schema.js';
|
|
2
2
|
import { hostParts, mountedIn } from '../../manifest/parts.js';
|
|
3
|
-
|
|
3
|
+
const NEEDS_SECRET = 'NEEDS_SECRET';
|
|
4
4
|
// C6: a declared secret of a server part with no value; the daemon checks it before the fork.
|
|
5
5
|
export const assertSecrets = (pkg, secrets) => {
|
|
6
6
|
const names = new Set(hostParts(pkg).flatMap((part) => mountedIn(pkg, part)));
|
|
@@ -21,8 +21,9 @@ export const healthy = async (port, ms) => {
|
|
|
21
21
|
if (res.status !== 200)
|
|
22
22
|
throw new Error(`health answered ${res.status}`);
|
|
23
23
|
};
|
|
24
|
-
//
|
|
25
|
-
export const
|
|
24
|
+
// Each value raw and as it shows inside a JSON log row (quotes, backslashes escaped).
|
|
25
|
+
export const maskedForms = (secrets) => [...new Set(Object.values(secrets).flatMap((v) => [v, JSON.stringify(v).slice(1, -1)]))]
|
|
26
26
|
.filter((value) => value.length >= 4)
|
|
27
|
-
.sort((a, b) => b.length - a.length)
|
|
28
|
-
|
|
27
|
+
.sort((a, b) => b.length - a.length);
|
|
28
|
+
// A secret value this child was given never reaches error, /health, the list or the log.
|
|
29
|
+
export const redact = (text, secrets) => maskedForms(secrets).reduce((out, value) => out.split(value).join('***'), text);
|
|
@@ -7,7 +7,6 @@ import { type PendingChanges } from './pending.js';
|
|
|
7
7
|
import { type Queue } from './queue.js';
|
|
8
8
|
import { type Retry } from './restart.js';
|
|
9
9
|
import { type Stopping } from './stopping.js';
|
|
10
|
-
export { halt, hold } from './gate.js';
|
|
11
10
|
export interface InstallSpec {
|
|
12
11
|
id: string;
|
|
13
12
|
version?: string;
|
|
@@ -53,8 +52,6 @@ export interface SupervisorDeps extends Limits {
|
|
|
53
52
|
unsynced: Set<string>;
|
|
54
53
|
}
|
|
55
54
|
export declare const valuesOf: (configDir: string, id: string) => Promise<Values>;
|
|
56
|
-
export declare const
|
|
57
|
-
export declare const startEntry: (deps: SupervisorDeps, entry: Entry) => Promise<Error | undefined>;
|
|
58
|
-
export declare const restore: (deps: SupervisorDeps, entry: Entry) => Promise<void>;
|
|
55
|
+
export declare const startEntry: (deps: SupervisorDeps, entry: Entry, fresh?: boolean) => Promise<Error | undefined>;
|
|
59
56
|
export declare const startFailed: (entry: Entry, err: unknown) => import("../../envelope/envelope.js").Failure;
|
|
60
57
|
export declare const swap: (deps: SupervisorDeps, entry: Entry, to: Next, undo?: () => Promise<unknown>) => Promise<void>;
|
|
@@ -13,7 +13,6 @@ import {} from './queue.js';
|
|
|
13
13
|
import { crashed, healthyFor, reasonOf, resetRestarts } from './restart.js';
|
|
14
14
|
import { assertSecrets, healthy, redact } from './start-checks.js';
|
|
15
15
|
import {} from './stopping.js';
|
|
16
|
-
export { halt, hold } from './gate.js';
|
|
17
16
|
export const valuesOf = async (configDir, id) => ({
|
|
18
17
|
settings: await readValues(configDir, 'settings', id),
|
|
19
18
|
secrets: (await readValues(configDir, 'secrets', id)),
|
|
@@ -28,25 +27,27 @@ const dirOf = async (deps, entry, install, given) => {
|
|
|
28
27
|
return entry.dir;
|
|
29
28
|
return (await runInstaller(deps, { id: entry.id, version: install.version })).dir;
|
|
30
29
|
};
|
|
31
|
-
// A new child for
|
|
32
|
-
|
|
33
|
-
const dir = await dirOf(deps, entry, install,
|
|
30
|
+
// A new child for to, healthy, then the route; fresh: a start the owner asked for (restarts reset).
|
|
31
|
+
const launchFor = async (deps, entry, to, fresh) => {
|
|
32
|
+
const dir = await dirOf(deps, entry, to.install, to.dir);
|
|
34
33
|
const pkg = await readManifest(dir);
|
|
35
|
-
assertSecrets(pkg, values.secrets);
|
|
36
|
-
const spec = { id: entry.id, dir, dataDir: dataDirOf(deps.configDir, entry.id), ...values };
|
|
34
|
+
assertSecrets(pkg, to.values.secrets);
|
|
35
|
+
const spec = { id: entry.id, dir, dataDir: dataDirOf(deps.configDir, entry.id), ...to.values };
|
|
37
36
|
const child = await deps
|
|
38
37
|
.launch({ ...spec, origin: deps.origin(), storeOpenMs: deps.healthMs })
|
|
39
|
-
.catch((err) => Promise.reject(Object.assign(err, { message: redact(err.message, values.secrets) })));
|
|
38
|
+
.catch((err) => Promise.reject(Object.assign(err, { message: redact(err.message, to.values.secrets) })));
|
|
40
39
|
await healthy(child.port, deps.healthMs).catch(async (err) => {
|
|
41
40
|
await child.stop();
|
|
42
41
|
throw err;
|
|
43
42
|
});
|
|
44
|
-
Object.assign(entry, { dir, version: pkg.version });
|
|
45
43
|
const lane = laneOf(child);
|
|
46
|
-
|
|
44
|
+
Object.assign(entry, { dir, version: pkg.version, lane, state: 'running', error: undefined });
|
|
45
|
+
if (fresh)
|
|
46
|
+
resetRestarts(entry);
|
|
47
|
+
// Watched only once it is the route: an exit that came before this line is seen, not lost.
|
|
48
|
+
const words = (how) => redact(reasonOf(how), to.values.secrets);
|
|
47
49
|
void child.exited.then((how) => exitedEarly(deps, entry, lane, words(how)));
|
|
48
50
|
healthyFor(deps, entry, lane);
|
|
49
|
-
return lane;
|
|
50
51
|
};
|
|
51
52
|
// A child that exits while it is the route restarts (C6); a retired one was detached first.
|
|
52
53
|
const exitedEarly = (deps, entry, lane, why) => {
|
|
@@ -60,12 +61,11 @@ const failed = (deps, entry, err) => {
|
|
|
60
61
|
deps.log.warn('extension failed to start', { id: entry.id, reason: entry.error });
|
|
61
62
|
};
|
|
62
63
|
// The install and values of installation.json, as they are on disk; the error when it failed.
|
|
63
|
-
export const startEntry = async (deps, entry) => {
|
|
64
|
+
export const startEntry = async (deps, entry, fresh = false) => {
|
|
64
65
|
entry.state = 'starting';
|
|
65
66
|
try {
|
|
66
67
|
const values = await valuesOf(deps.configDir, entry.id);
|
|
67
|
-
|
|
68
|
-
Object.assign(entry, { state: 'running', error: undefined });
|
|
68
|
+
await launchFor(deps, entry, { install: entry.install, values }, fresh);
|
|
69
69
|
return undefined;
|
|
70
70
|
}
|
|
71
71
|
catch (err) {
|
|
@@ -80,7 +80,7 @@ const restartEntry = async (deps, entry) => {
|
|
|
80
80
|
crashed(deps, entry, err.message, () => restartEntry(deps, entry));
|
|
81
81
|
};
|
|
82
82
|
// The old install again after a refused change; a disabled one stays stopped.
|
|
83
|
-
|
|
83
|
+
const restore = async (deps, entry) => {
|
|
84
84
|
if (entry.install.enabled === false)
|
|
85
85
|
entry.state = 'disabled';
|
|
86
86
|
else
|
|
@@ -96,9 +96,7 @@ export const startFailed = (entry, err) => {
|
|
|
96
96
|
export const swap = async (deps, entry, to, undo = async () => undefined) => {
|
|
97
97
|
try {
|
|
98
98
|
await halt(entry, deps.drainMs);
|
|
99
|
-
|
|
100
|
-
Object.assign(entry, { state: 'running', error: undefined });
|
|
101
|
-
resetRestarts(entry);
|
|
99
|
+
await launchFor(deps, entry, to, true);
|
|
102
100
|
}
|
|
103
101
|
catch (err) {
|
|
104
102
|
await undo();
|
|
@@ -4,6 +4,7 @@ import { type HealthBody } from '../health/health.schema.js';
|
|
|
4
4
|
import { type Log } from '../log/log.js';
|
|
5
5
|
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
6
6
|
import { type HostPartKind } from '../manifest/parts.js';
|
|
7
|
+
import { type Env } from '../runtime/build-info.js';
|
|
7
8
|
import { type PartAppBase } from '../server/app.js';
|
|
8
9
|
export interface HostOptions {
|
|
9
10
|
dataDir: string;
|
|
@@ -29,5 +30,7 @@ export interface HostExtras {
|
|
|
29
30
|
guard?: (pkg: ExtensionPackage, log: Log) => Promise<Partial<PartAppBase>>;
|
|
30
31
|
build?: BuildInfo;
|
|
31
32
|
}
|
|
33
|
+
export declare const JOB_STOP_MS = 3000;
|
|
34
|
+
export declare const hostBuildInfo: (env: Env, dir: string) => Promise<BuildInfo>;
|
|
32
35
|
export declare const hostWith: (dir: string, opts: HostOptions, extras: HostExtras) => Promise<HostedExtension>;
|
|
33
36
|
export declare const hostExtension: (dir: string, opts: HostOptions) => Promise<HostedExtension>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { stat } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
5
|
import {} from 'express';
|
|
3
6
|
import {} from '../discovery/discovery.js';
|
|
4
7
|
import { healthBody } from '../health/health.js';
|
|
@@ -32,6 +35,8 @@ const baseOf = async (h) => {
|
|
|
32
35
|
const { pkg, log, build, onExit } = h;
|
|
33
36
|
return { pkg, log, build, onExit, guards, ...guard, checks, clockRate, ...resolved };
|
|
34
37
|
};
|
|
38
|
+
// A running job ends before the store closes, within the daemon's 5 s before SIGKILL.
|
|
39
|
+
export const JOB_STOP_MS = 3_000;
|
|
35
40
|
// The jobs stop before the store closes: a tick never writes to a closed store.
|
|
36
41
|
const hostedOf = (h, hosted, base) => {
|
|
37
42
|
const { id } = h.pkg.agentage;
|
|
@@ -41,10 +46,15 @@ const hostedOf = (h, hosted, base) => {
|
|
|
41
46
|
const at = { instance, startedAt, clockRate };
|
|
42
47
|
const health = () => healthBody({ extension: id, part: 'api', parts, version, build, checks, ...at });
|
|
43
48
|
let stopped;
|
|
44
|
-
const close = () =>
|
|
49
|
+
const close = async () => {
|
|
50
|
+
await Promise.race([hosted.stop(), sleep(JOB_STOP_MS, undefined, { ref: false })]);
|
|
51
|
+
await h.store?.close();
|
|
52
|
+
};
|
|
45
53
|
const stop = () => (stopped ??= close());
|
|
46
54
|
return { id, version, parts, app, health, stop };
|
|
47
55
|
};
|
|
56
|
+
// BUILD_TIME of an image, else the installed package's time: the same across restarts.
|
|
57
|
+
export const hostBuildInfo = async (env, dir) => buildInfoFromEnv(env, (await stat(join(dir, 'package.json'))).mtime);
|
|
48
58
|
// hostExtension with the extras of the entry (dist/host/main.js).
|
|
49
59
|
export const hostWith = async (dir, opts, extras) => {
|
|
50
60
|
const pkg = await readManifest(dir);
|
|
@@ -53,7 +63,7 @@ export const hostWith = async (dir, opts, extras) => {
|
|
|
53
63
|
const at = { dir, dataDir: opts.dataDir, runDir: opts.runDir, openMs };
|
|
54
64
|
const store = await openHostStore(pkg, at, log);
|
|
55
65
|
const onExit = once(opts.onExit ?? (() => undefined));
|
|
56
|
-
const build = extras.build ??
|
|
66
|
+
const build = extras.build ?? (await hostBuildInfo({}, dir));
|
|
57
67
|
const h = { dir, pkg, log, opts, extras, store, onExit, build };
|
|
58
68
|
try {
|
|
59
69
|
const base = await baseOf(h);
|
package/dist/host/host-parts.js
CHANGED
|
@@ -2,8 +2,9 @@ import {} from 'express';
|
|
|
2
2
|
import { createContext } from '../context/context.js';
|
|
3
3
|
import { readSecrets, secretsFrom } from '../context/secrets.js';
|
|
4
4
|
import { settingsOf } from '../context/settings.js';
|
|
5
|
-
import {} from '../discovery/discovery.js';
|
|
5
|
+
import { hostedRecordOf } from '../discovery/discovery.js';
|
|
6
6
|
import { readOpenapi } from '../discovery/openapi.js';
|
|
7
|
+
import { migrationsOf } from '../discovery/served-extras.js';
|
|
7
8
|
import { createLog } from '../log/log.js';
|
|
8
9
|
import {} from '../manifest/manifest.schema.js';
|
|
9
10
|
import { hostParts } from '../manifest/parts.js';
|
|
@@ -58,18 +59,24 @@ const mountsOf = async (h, parts, base) => {
|
|
|
58
59
|
}
|
|
59
60
|
catch (err) {
|
|
60
61
|
for (const m of mounts)
|
|
61
|
-
m.stop?.();
|
|
62
|
+
void m.stop?.();
|
|
62
63
|
throw err;
|
|
63
64
|
}
|
|
64
65
|
return mounts;
|
|
65
66
|
};
|
|
67
|
+
// The record a part image reads from its build, here from what each part serves.
|
|
68
|
+
const recordOf = async (h, parts, mounts) => {
|
|
69
|
+
const extras = Object.assign(await migrationsOf(h.dir, h.pkg), ...mounts.map((m) => m.record));
|
|
70
|
+
return hostedRecordOf(h.pkg, h.build, parts, extras);
|
|
71
|
+
};
|
|
66
72
|
// The api at /api/{id}/*, the mcp at /mcp/{id}, the worker jobs; one /health with every check.
|
|
67
73
|
export const hostPartsOf = async (h, base) => {
|
|
68
74
|
const parts = hostParts(h.pkg);
|
|
69
75
|
const mounts = await mountsOf(h, parts, base);
|
|
70
76
|
const mount = (app) => mounts.forEach((m) => m.mount(app));
|
|
71
|
-
const
|
|
77
|
+
const record = await recordOf(h, parts, mounts);
|
|
78
|
+
const app = createPartApp({ ...base, parts, part: 'api', mount, record });
|
|
72
79
|
const start = () => mounts.forEach((m) => m.start?.());
|
|
73
|
-
const stop = () => mounts.
|
|
80
|
+
const stop = async () => void (await Promise.all(mounts.map((m) => m.stop?.())));
|
|
74
81
|
return { app, parts, start, stop };
|
|
75
82
|
};
|
package/dist/host/serve-host.js
CHANGED
|
@@ -2,11 +2,11 @@ import {} from 'node:http';
|
|
|
2
2
|
import {} from 'node:net';
|
|
3
3
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
4
4
|
import { createLog } from '../log/log.js';
|
|
5
|
-
import {
|
|
5
|
+
import {} from '../runtime/build-info.js';
|
|
6
6
|
import { listen, shutdownOn } from '../server/serve.js';
|
|
7
7
|
import { loopbackPorts } from './daemon/guard.js';
|
|
8
8
|
import { guardOf, hostEnvOf } from './host-env.js';
|
|
9
|
-
import { hostWith } from './host-extension.js';
|
|
9
|
+
import { hostBuildInfo, hostWith } from './host-extension.js';
|
|
10
10
|
export const ORPHAN_MS = 10_000;
|
|
11
11
|
// The port to the daemon; its IPC channel closed: drain, and exit within ORPHAN_MS in any case.
|
|
12
12
|
export const announce = (port, stop, exit = process.exit) => {
|
|
@@ -56,7 +56,8 @@ export const serveHost = async (env, deps = {}) => {
|
|
|
56
56
|
// C2: on loopback the child checks Host and Origin itself, for its own port and the daemon's.
|
|
57
57
|
const local = { localOnly: at.bind === '127.0.0.1', localPorts: loopbackPorts(origin) };
|
|
58
58
|
const opts = { dataDir, runDir, settings, origin, storeOpenMs, onExit: hook.onExit, ...local };
|
|
59
|
-
const
|
|
59
|
+
const build = await hostBuildInfo(env, at.dir);
|
|
60
|
+
const host = await hostWith(at.dir, opts, { secretsDir, guard, build });
|
|
60
61
|
const server = await listen(host.app, at.port, at.bind);
|
|
61
62
|
const { log, stop } = drainOn(server, host, deps, at.drainMs);
|
|
62
63
|
const { port } = server.address();
|
package/dist/manifest/parts.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface NormalizedParts {
|
|
|
8
8
|
}
|
|
9
9
|
export declare const normalizeParts: (parts: Parts) => NormalizedParts;
|
|
10
10
|
export declare const imageParts: (pkg: ExtensionPackage) => ImagePartKind[];
|
|
11
|
-
|
|
11
|
+
declare const HOST_PARTS: readonly ["api", "mcp", "worker"];
|
|
12
12
|
export type HostPartKind = (typeof HOST_PARTS)[number];
|
|
13
13
|
export declare const hostParts: (pkg: ExtensionPackage) => HostPartKind[];
|
|
14
14
|
export declare const entryOf: (pkg: ExtensionPackage, part: ImagePartKind | "cli") => string;
|
|
@@ -21,3 +21,4 @@ export declare const unmountedIn: (pkg: ExtensionPackage | undefined, part: Imag
|
|
|
21
21
|
export declare const storeOf: (pkg: ExtensionPackage) => StoreKind | undefined;
|
|
22
22
|
export declare const hasStore: (pkg: ExtensionPackage, kind: StoreKind) => boolean;
|
|
23
23
|
export declare const migratesStore: (pkg: ExtensionPackage) => boolean;
|
|
24
|
+
export {};
|
package/dist/manifest/parts.js
CHANGED
|
@@ -22,7 +22,7 @@ export const imageParts = (pkg) => {
|
|
|
22
22
|
return IMAGE_PART_KINDS.filter((kind) => code[kind] !== undefined);
|
|
23
23
|
};
|
|
24
24
|
// The parts one host process runs (the daemon's child, the one container); pages and ui wait for phase 2.
|
|
25
|
-
|
|
25
|
+
const HOST_PARTS = ['api', 'mcp', 'worker'];
|
|
26
26
|
export const hostParts = (pkg) => HOST_PARTS.filter((kind) => imageParts(pkg).includes(kind));
|
|
27
27
|
export const entryOf = (pkg, part) => normalizeParts(pkg.agentage.parts).code[part]?.entry ?? `./dist/${part}/index.js`;
|
|
28
28
|
export const secretNames = (pkg) => (pkg.agentage.secrets ?? []).map((s) => (typeof s === 'string' ? s : s.name));
|
package/dist/mcp/mcp-app.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export interface McpAppOptions extends PartAppBase {
|
|
|
6
6
|
listing: 'open' | 'token';
|
|
7
7
|
paths?: string[];
|
|
8
8
|
}
|
|
9
|
-
export declare const MCP_PATH = "/mcp";
|
|
10
9
|
export declare const mcpPathOf: (id: string) => string;
|
|
11
10
|
export declare const mountMcp: (app: Express, options: McpAppOptions) => void;
|
|
12
11
|
export declare const createMcpApp: (options: McpAppOptions) => Express;
|
package/dist/mcp/mcp-app.js
CHANGED
|
@@ -10,7 +10,7 @@ import { declaredType, printable } from '../log/who.js';
|
|
|
10
10
|
import { BODY_LIMIT, createPartApp, PUBLIC_CORS } from '../server/app.js';
|
|
11
11
|
import { serverFactory } from './server.js';
|
|
12
12
|
import { prefixed } from './tools.js';
|
|
13
|
-
|
|
13
|
+
const MCP_PATH = '/mcp';
|
|
14
14
|
// The endpoint of an extension on a host that runs many: the daemon routes it to its child.
|
|
15
15
|
export const mcpPathOf = (id) => `${MCP_PATH}/${id}`;
|
|
16
16
|
const MCP_HEADERS = ['Mcp-Protocol-Version', 'Mcp-Method', 'Mcp-Name', 'Accept'];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Express } from 'express';
|
|
2
2
|
import { type PartContext } from '../context/context.js';
|
|
3
|
+
import { type RecordExtras } from '../discovery/discovery.js';
|
|
3
4
|
import { type HealthCheck } from '../health/health.js';
|
|
4
5
|
import { type ImportModule } from '../manifest/entry.js';
|
|
5
6
|
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
@@ -23,7 +24,8 @@ export interface PartMount {
|
|
|
23
24
|
mount: (app: Express) => void;
|
|
24
25
|
checks?: Record<string, HealthCheck>;
|
|
25
26
|
start?: () => void;
|
|
26
|
-
stop?: () => void
|
|
27
|
+
stop?: () => void | Promise<void>;
|
|
28
|
+
record?: RecordExtras;
|
|
27
29
|
}
|
|
28
30
|
export declare const callCreate: <C>(input: RunnerInput, part: ImagePartKind, ctx: C) => Promise<unknown>;
|
|
29
31
|
export declare const MOUNTS: Record<HostPartKind, (input: RunnerInput) => Promise<PartMount>>;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {} from 'express';
|
|
2
2
|
import { generatedOpenapi } from '../api/openapi-doc.js';
|
|
3
3
|
import {} from '../context/context.js';
|
|
4
|
+
import {} from '../discovery/discovery.js';
|
|
5
|
+
import { openapiPath } from '../discovery/openapi.js';
|
|
6
|
+
import { toolRecords } from '../discovery/served-extras.js';
|
|
4
7
|
import {} from '../health/health.js';
|
|
5
8
|
import { loadCreate } from '../manifest/entry.js';
|
|
6
9
|
import {} from '../manifest/manifest.schema.js';
|
|
@@ -23,7 +26,8 @@ const api = async (input) => {
|
|
|
23
26
|
// Declared routes guard at their own scope, whatever the committed file says.
|
|
24
27
|
const openapi = routes.length > 0 ? generatedOpenapi(input.pkg, routes) : input.openapi;
|
|
25
28
|
const options = { ...input.base, router, routes, openapi, wellKnown: documents };
|
|
26
|
-
|
|
29
|
+
const record = openapi ? { openapi: openapiPath(input.pkg.agentage.id) } : {};
|
|
30
|
+
return { mount: (app) => mountApiRoutes(app, { ...options, aliases: input.apiAliases }), record };
|
|
27
31
|
};
|
|
28
32
|
const mcp = async (input) => {
|
|
29
33
|
const registry = createToolRegistry();
|
|
@@ -32,7 +36,8 @@ const mcp = async (input) => {
|
|
|
32
36
|
const token = !input.openListing && ctx.settings['mcp.listing'] === 'token';
|
|
33
37
|
const listing = token ? 'token' : 'open';
|
|
34
38
|
const options = { ...input.base, tools: registry.tools, listing, paths: input.mcpPaths };
|
|
35
|
-
|
|
39
|
+
const tools = toolRecords(input.pkg.agentage.id, registry.tools);
|
|
40
|
+
return { mount: (app) => mountMcp(app, options), record: tools.length ? { tools } : {} };
|
|
36
41
|
};
|
|
37
42
|
const worker = async (input) => {
|
|
38
43
|
const ctx = input.ctx();
|
package/dist/server/app.d.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { type Express, type RequestHandler } from 'express';
|
|
|
3
3
|
import { type HelmetOptions } from 'helmet';
|
|
4
4
|
import { type WellKnownEntry } from '../api/well-known.js';
|
|
5
5
|
import { type TokenCheck } from '../auth/token-check.js';
|
|
6
|
-
import { type BuildInfo } from '../discovery/discovery.js';
|
|
7
|
-
import { type ExtensionRecord } from '../discovery/discovery.schema.js';
|
|
6
|
+
import { type BuildInfo, type ServedRecord } from '../discovery/discovery.js';
|
|
8
7
|
import { type HealthCheck } from '../health/health.js';
|
|
9
8
|
import { type Log } from '../log/log.js';
|
|
10
9
|
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
@@ -14,7 +13,7 @@ export interface PartAppBase {
|
|
|
14
13
|
pkg: ExtensionPackage;
|
|
15
14
|
build: BuildInfo;
|
|
16
15
|
log: Log;
|
|
17
|
-
record?:
|
|
16
|
+
record?: ServedRecord | null;
|
|
18
17
|
ownImage?: string;
|
|
19
18
|
origin?: string;
|
|
20
19
|
checks?: Record<string, HealthCheck>;
|
package/dist/server/app.js
CHANGED
|
@@ -6,7 +6,6 @@ import { agcidMiddleware } from '../agcid/scope.js';
|
|
|
6
6
|
import { routeAccess, sameShape } from '../auth/route-access.js';
|
|
7
7
|
import { setCaller } from '../auth/token-check.js';
|
|
8
8
|
import { discoveryDocument, recordOf, } from '../discovery/discovery.js';
|
|
9
|
-
import {} from '../discovery/discovery.schema.js';
|
|
10
9
|
import { apiPrefix } from '../discovery/openapi.js';
|
|
11
10
|
import { createHealthHandler } from '../health/health.js';
|
|
12
11
|
import {} from '../log/log.js';
|
package/dist/tool/build.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export interface BuildResult {
|
|
|
33
33
|
images: BuiltImage[];
|
|
34
34
|
container?: BuiltContainer;
|
|
35
35
|
recordFile?: string;
|
|
36
|
+
warnings?: string[];
|
|
36
37
|
}
|
|
37
38
|
export declare const imageTag: (registry: string, pkg: ExtensionPackage, part: ImagePartKind) => string;
|
|
38
39
|
export declare const recordFor: (dir: string, pkg: ExtensionPackage, info: BuildInfo, images: BuiltImage[]) => Promise<ExtensionRecord>;
|
package/dist/tool/build.js
CHANGED
|
@@ -83,10 +83,11 @@ export const build = async (options = {}, deps = { run: runCommand }) => {
|
|
|
83
83
|
const parts = options.container ? containerParts(pkg) : undefined;
|
|
84
84
|
const info = await resolveBuildInfo(dir, options.env ?? process.env, deps.run);
|
|
85
85
|
await compile(dir, pkg, deps.run);
|
|
86
|
-
await assertConforms(dir, { run: deps.run });
|
|
86
|
+
const warnings = await assertConforms(dir, { run: deps.run });
|
|
87
87
|
const base = { dir, pkg, info };
|
|
88
88
|
const built = parts
|
|
89
89
|
? await containerOf(base, parts, options, deps)
|
|
90
90
|
: await partImages(base, options, deps);
|
|
91
|
-
|
|
91
|
+
const warned = warnings.length > 0 ? { warnings } : {};
|
|
92
|
+
return { id: pkg.agentage.id, version: pkg.version, ...info, ...built, ...warned };
|
|
92
93
|
};
|
package/dist/tool/check.d.ts
CHANGED
|
@@ -37,4 +37,4 @@ export interface CheckReport {
|
|
|
37
37
|
export declare const NOT_BUILT = "is missing: build the package first (npm run build)";
|
|
38
38
|
export declare const RULES: readonly CheckRule[];
|
|
39
39
|
export declare const check: (at: string, options?: CheckOptions) => Promise<CheckReport>;
|
|
40
|
-
export declare const assertConforms: (dir: string, options?: CheckOptions) => Promise<
|
|
40
|
+
export declare const assertConforms: (dir: string, options?: CheckOptions) => Promise<string[]>;
|