@agentage/extension 0.14.0 → 0.15.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 +3 -1
- package/dist/health/health.d.ts +2 -0
- package/dist/health/health.js +4 -2
- package/dist/health/health.schema.d.ts +9 -0
- package/dist/health/health.schema.js +3 -0
- package/dist/host/clock-rate.d.ts +1 -0
- package/dist/host/clock-rate.js +12 -0
- package/dist/host/daemon/add.js +24 -3
- package/dist/host/daemon/child-files.d.ts +20 -0
- package/dist/host/daemon/child-files.js +45 -0
- package/dist/host/daemon/child.d.ts +10 -4
- package/dist/host/daemon/child.js +63 -37
- package/dist/host/daemon/daemon-files.d.ts +3 -0
- package/dist/host/daemon/daemon-files.js +5 -1
- package/dist/host/daemon/daemon.d.ts +1 -0
- package/dist/host/daemon/daemon.js +21 -6
- package/dist/host/daemon/gate.d.ts +3 -0
- package/dist/host/daemon/gate.js +19 -0
- package/dist/host/daemon/guard.d.ts +2 -1
- package/dist/host/daemon/guard.js +16 -4
- package/dist/host/daemon/health-routes.d.ts +17 -0
- package/dist/host/daemon/health-routes.js +61 -0
- package/dist/host/daemon/host-token.d.ts +6 -0
- package/dist/host/daemon/host-token.js +28 -0
- package/dist/host/daemon/last-words.d.ts +2 -0
- package/dist/host/daemon/last-words.js +28 -0
- package/dist/host/daemon/limits.d.ts +4 -0
- package/dist/host/daemon/limits.js +7 -0
- package/dist/host/daemon/ops.js +4 -1
- package/dist/host/daemon/pending.d.ts +1 -1
- package/dist/host/daemon/proxy.d.ts +1 -1
- package/dist/host/daemon/proxy.js +16 -8
- package/dist/host/daemon/reload-marker.d.ts +8 -0
- package/dist/host/daemon/reload-marker.js +56 -0
- package/dist/host/daemon/reload-route.d.ts +4 -0
- package/dist/host/daemon/reload-route.js +21 -0
- package/dist/host/daemon/reload.d.ts +10 -0
- package/dist/host/daemon/reload.js +73 -0
- package/dist/host/daemon/restart.d.ts +14 -0
- package/dist/host/daemon/restart.js +59 -0
- package/dist/host/daemon/routes.d.ts +2 -10
- package/dist/host/daemon/routes.js +13 -31
- package/dist/host/daemon/run-lock.d.ts +1 -0
- package/dist/host/daemon/run-lock.js +15 -0
- package/dist/host/daemon/seal-reach.d.ts +2 -0
- package/dist/host/daemon/seal-reach.js +38 -0
- package/dist/host/daemon/seal.d.ts +16 -0
- package/dist/host/daemon/seal.js +71 -0
- package/dist/host/daemon/start-checks.d.ts +6 -0
- package/dist/host/daemon/start-checks.js +28 -0
- package/dist/host/daemon/supervisor.d.ts +9 -3
- package/dist/host/daemon/supervisor.js +33 -40
- package/dist/host/data-lock.d.ts +2 -1
- package/dist/host/data-lock.js +25 -6
- package/dist/host/host-env.d.ts +1 -0
- package/dist/host/host-env.js +2 -0
- package/dist/host/host-extension.d.ts +4 -0
- package/dist/host/host-extension.js +23 -43
- package/dist/host/host-parts.d.ts +25 -0
- package/dist/host/host-parts.js +75 -0
- package/dist/host/host-store.d.ts +3 -0
- package/dist/host/host-store.js +21 -2
- package/dist/host/main.js +2 -0
- package/dist/host/part-checks.d.ts +2 -0
- package/dist/host/part-checks.js +19 -0
- package/dist/host/serve-host.js +6 -3
- package/dist/manifest/parts.d.ts +3 -0
- package/dist/manifest/parts.js +3 -0
- package/dist/mcp/mcp-app.d.ts +4 -0
- package/dist/mcp/mcp-app.js +11 -11
- package/dist/runtime/part-mounts.d.ts +29 -0
- package/dist/runtime/part-mounts.js +52 -0
- package/dist/runtime/part-runners.d.ts +2 -15
- package/dist/runtime/part-runners.js +13 -58
- package/dist/server/app.d.ts +3 -0
- package/dist/server/app.js +16 -16
- package/dist/tool/check.d.ts +2 -0
- package/dist/tool/check.js +23 -8
- package/dist/tool/container-parts.d.ts +1 -1
- package/dist/tool/container-parts.js +6 -6
- package/dist/tool/format.js +15 -8
- package/dist/tool/kit-version.d.ts +2 -0
- package/dist/tool/kit-version.js +12 -0
- package/dist/worker/clock.d.ts +6 -0
- package/dist/worker/clock.js +21 -0
- package/dist/worker/scheduler.d.ts +1 -0
- package/dist/worker/scheduler.js +6 -2
- package/package.json +1 -1
- package/schemas/health.schema.json +17 -0
package/dist/host/host-store.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { mkdir } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
4
|
import {} from '../log/log.js';
|
|
3
5
|
import {} from '../manifest/manifest.schema.js';
|
|
4
6
|
import { hasStore } from '../manifest/parts.js';
|
|
5
7
|
import { migrate } from '../store/migrations.js';
|
|
6
8
|
import { createPgliteStore } from '../store/pglite-store.js';
|
|
7
|
-
import { lockDataDir } from './data-lock.js';
|
|
9
|
+
import { DATA_DIR_LOCKED, lockDataDir } from './data-lock.js';
|
|
8
10
|
const unlocked = async () => undefined;
|
|
9
11
|
// How long the host waits for the store to open (and to close); the daemon sets its healthMs.
|
|
10
12
|
export const STORE_OPEN_MS = 120_000;
|
|
@@ -12,18 +14,35 @@ const within = (work, ms) => Promise.race([
|
|
|
12
14
|
work,
|
|
13
15
|
new Promise((resolve) => setTimeout(() => resolve('late'), ms).unref()),
|
|
14
16
|
]);
|
|
17
|
+
const LOCK_RETRY_MS = 100;
|
|
18
|
+
// A holder that is still draining (an old child, an orphan) lets go soon: retry until openMs.
|
|
19
|
+
export const lockWithin = async (dataDir, openMs, lock = `${dataDir}.lock`) => {
|
|
20
|
+
const until = Date.now() + openMs;
|
|
21
|
+
for (;;) {
|
|
22
|
+
try {
|
|
23
|
+
return await lockDataDir(dataDir, lock);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
if (err.code !== DATA_DIR_LOCKED || Date.now() >= until)
|
|
27
|
+
throw err;
|
|
28
|
+
await sleep(LOCK_RETRY_MS);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
15
32
|
// A close past openMs keeps the data lock: PGlite may still write there until the process exits.
|
|
16
33
|
const closer = (store, release, openMs) => async () => {
|
|
17
34
|
const closed = await within(store.close().catch(() => undefined), openMs);
|
|
18
35
|
if (closed !== 'late')
|
|
19
36
|
await release();
|
|
20
37
|
};
|
|
38
|
+
// C2: in run/{id} when the daemon gives it; an old <dataDir>.lock is then not read (the daemon cleared it).
|
|
39
|
+
export const lockOf = ({ dataDir, runDir }) => runDir ? join(runDir, 'store.lock') : `${dataDir}.lock`;
|
|
21
40
|
// Locks dataDir, then opens PGlite in it and migrates; past openMs the part starts, /health says not ready.
|
|
22
41
|
const open = async (at, log) => {
|
|
23
42
|
const { dir, dataDir, openMs } = at;
|
|
24
43
|
if (dataDir)
|
|
25
44
|
await mkdir(dataDir, { recursive: true });
|
|
26
|
-
const release = dataDir ? await
|
|
45
|
+
const release = dataDir ? await lockWithin(dataDir, openMs, lockOf(at)) : unlocked;
|
|
27
46
|
const store = createPgliteStore((s) => migrate(s, dir, log), {
|
|
28
47
|
dataDir: dataDir || undefined,
|
|
29
48
|
from: dir,
|
package/dist/host/main.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createLog } from '../log/log.js';
|
|
3
|
+
import { startHostClock } from './clock-rate.js';
|
|
3
4
|
import { serveHost } from './serve-host.js';
|
|
4
5
|
// The daemon's child and the one container: `node .../dist/host/main.js`, settings from env.
|
|
5
6
|
const crash = (err) => {
|
|
@@ -7,4 +8,5 @@ const crash = (err) => {
|
|
|
7
8
|
process.exit(1);
|
|
8
9
|
};
|
|
9
10
|
process.on('uncaughtException', crash);
|
|
11
|
+
startHostClock(process.env);
|
|
10
12
|
await serveHost(process.env).catch(crash);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { worstOf } from '../health/health.js';
|
|
2
|
+
import {} from '../health/health.schema.js';
|
|
3
|
+
const statusOf = (check) => check().catch(() => 'unavailable');
|
|
4
|
+
// Both checks of one name run; /health shows the worse status.
|
|
5
|
+
const bothOf = (first, second) => async () => worstOf(await Promise.all([statusOf(first), statusOf(second)]));
|
|
6
|
+
// One part's view of the host's one map: its own names and the host's stay unique, a name of another part joins.
|
|
7
|
+
export const partChecks = (shared, reserved) => {
|
|
8
|
+
const own = new Set();
|
|
9
|
+
return new Proxy(shared, {
|
|
10
|
+
has: (_target, name) => own.has(String(name)) || reserved.has(String(name)),
|
|
11
|
+
set: (target, name, check) => {
|
|
12
|
+
const key = String(name);
|
|
13
|
+
own.add(key);
|
|
14
|
+
const before = target[key];
|
|
15
|
+
target[key] = before ? bothOf(before, check) : check;
|
|
16
|
+
return true;
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
};
|
package/dist/host/serve-host.js
CHANGED
|
@@ -4,6 +4,7 @@ import { setTimeout as sleep } from 'node:timers/promises';
|
|
|
4
4
|
import { createLog } from '../log/log.js';
|
|
5
5
|
import { buildInfoFromEnv } from '../runtime/build-info.js';
|
|
6
6
|
import { listen, shutdownOn } from '../server/serve.js';
|
|
7
|
+
import { loopbackPorts } from './daemon/guard.js';
|
|
7
8
|
import { guardOf, hostEnvOf } from './host-env.js';
|
|
8
9
|
import { hostWith } from './host-extension.js';
|
|
9
10
|
export const ORPHAN_MS = 10_000;
|
|
@@ -51,13 +52,15 @@ export const serveHost = async (env, deps = {}) => {
|
|
|
51
52
|
const at = hostEnvOf(env);
|
|
52
53
|
const guard = guardOf(env, at);
|
|
53
54
|
const hook = exitHook();
|
|
54
|
-
const { dataDir, settings, origin, secretsDir, storeOpenMs } = at;
|
|
55
|
-
|
|
55
|
+
const { dataDir, runDir, settings, origin, secretsDir, storeOpenMs } = at;
|
|
56
|
+
// C2: on loopback the child checks Host and Origin itself, for its own port and the daemon's.
|
|
57
|
+
const local = { localOnly: at.bind === '127.0.0.1', localPorts: loopbackPorts(origin) };
|
|
58
|
+
const opts = { dataDir, runDir, settings, origin, storeOpenMs, onExit: hook.onExit, ...local };
|
|
56
59
|
const host = await hostWith(at.dir, opts, { secretsDir, guard, build: buildInfoFromEnv(env) });
|
|
57
60
|
const server = await listen(host.app, at.port, at.bind);
|
|
58
61
|
const { log, stop } = drainOn(server, host, deps, at.drainMs);
|
|
59
62
|
const { port } = server.address();
|
|
60
|
-
log.info('listening', { port, bind: at.bind });
|
|
63
|
+
log.info('listening', { port, bind: at.bind, parts: host.parts.join(',') });
|
|
61
64
|
(deps.ready ?? announce)(port, stop);
|
|
62
65
|
hook.arm(stop);
|
|
63
66
|
return { server, host, stop };
|
package/dist/manifest/parts.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export interface NormalizedParts {
|
|
|
8
8
|
}
|
|
9
9
|
export declare const normalizeParts: (parts: Parts) => NormalizedParts;
|
|
10
10
|
export declare const imageParts: (pkg: ExtensionPackage) => ImagePartKind[];
|
|
11
|
+
export declare const HOST_PARTS: readonly ["api", "mcp", "worker"];
|
|
12
|
+
export type HostPartKind = (typeof HOST_PARTS)[number];
|
|
13
|
+
export declare const hostParts: (pkg: ExtensionPackage) => HostPartKind[];
|
|
11
14
|
export declare const entryOf: (pkg: ExtensionPackage, part: ImagePartKind | "cli") => string;
|
|
12
15
|
export declare const secretNames: (pkg: ExtensionPackage) => string[];
|
|
13
16
|
export declare const scopedSecrets: (pkg: ExtensionPackage) => {
|
package/dist/manifest/parts.js
CHANGED
|
@@ -21,6 +21,9 @@ export const imageParts = (pkg) => {
|
|
|
21
21
|
const { code } = normalizeParts(pkg.agentage.parts);
|
|
22
22
|
return IMAGE_PART_KINDS.filter((kind) => code[kind] !== undefined);
|
|
23
23
|
};
|
|
24
|
+
// The parts one host process runs (the daemon's child, the one container); pages and ui wait for phase 2.
|
|
25
|
+
export const HOST_PARTS = ['api', 'mcp', 'worker'];
|
|
26
|
+
export const hostParts = (pkg) => HOST_PARTS.filter((kind) => imageParts(pkg).includes(kind));
|
|
24
27
|
export const entryOf = (pkg, part) => normalizeParts(pkg.agentage.parts).code[part]?.entry ?? `./dist/${part}/index.js`;
|
|
25
28
|
export const secretNames = (pkg) => (pkg.agentage.secrets ?? []).map((s) => (typeof s === 'string' ? s : s.name));
|
|
26
29
|
const scopedOf = (pkg) => (pkg.agentage.secrets ?? []).flatMap((s) => (typeof s === 'string' ? [] : [s]));
|
package/dist/mcp/mcp-app.d.ts
CHANGED
|
@@ -4,5 +4,9 @@ import { type ToolEntry } from './tools.js';
|
|
|
4
4
|
export interface McpAppOptions extends PartAppBase {
|
|
5
5
|
tools: ToolEntry[];
|
|
6
6
|
listing: 'open' | 'token';
|
|
7
|
+
paths?: string[];
|
|
7
8
|
}
|
|
9
|
+
export declare const MCP_PATH = "/mcp";
|
|
10
|
+
export declare const mcpPathOf: (id: string) => string;
|
|
11
|
+
export declare const mountMcp: (app: Express, options: McpAppOptions) => void;
|
|
8
12
|
export declare const createMcpApp: (options: McpAppOptions) => Express;
|
package/dist/mcp/mcp-app.js
CHANGED
|
@@ -10,6 +10,9 @@ 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
|
+
export const MCP_PATH = '/mcp';
|
|
14
|
+
// The endpoint of an extension on a host that runs many: the daemon routes it to its child.
|
|
15
|
+
export const mcpPathOf = (id) => `${MCP_PATH}/${id}`;
|
|
13
16
|
const MCP_HEADERS = ['Mcp-Protocol-Version', 'Mcp-Method', 'Mcp-Name', 'Accept'];
|
|
14
17
|
const MCP_CORS = {
|
|
15
18
|
...PUBLIC_CORS,
|
|
@@ -103,21 +106,18 @@ const methodNotAllowed = (_req, res) => {
|
|
|
103
106
|
.status(405)
|
|
104
107
|
.json({ jsonrpc: '2.0', error: { code: -32000, message: 'Method not allowed.' }, id: null });
|
|
105
108
|
};
|
|
106
|
-
// Stateless Streamable HTTP on SDK v2: POST
|
|
107
|
-
export const
|
|
109
|
+
// Stateless Streamable HTTP on SDK v2: POST only, GET and DELETE (sessions) answer 405.
|
|
110
|
+
export const mountMcp = (app, options) => {
|
|
108
111
|
const identity = { id: options.pkg.agentage.id, version: options.pkg.version };
|
|
109
112
|
const handler = createMcpHandler(serverFactory(identity, options.tools, options.log), {
|
|
110
113
|
legacy: 'stateless',
|
|
111
114
|
onerror: (err) => options.log.warn('mcp request refused', { reason: err.message }),
|
|
112
115
|
});
|
|
113
116
|
const raw = express.raw({ type: () => true, limit: BODY_LIMIT });
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
app.post('/mcp', raw, handle(handler, options));
|
|
120
|
-
app.all('/mcp', methodNotAllowed);
|
|
121
|
-
},
|
|
122
|
-
});
|
|
117
|
+
for (const path of options.paths ?? [MCP_PATH]) {
|
|
118
|
+
app.use(path, cors(MCP_CORS));
|
|
119
|
+
app.post(path, raw, handle(handler, options));
|
|
120
|
+
app.all(path, methodNotAllowed);
|
|
121
|
+
}
|
|
123
122
|
};
|
|
123
|
+
export const createMcpApp = (options) => createPartApp({ ...options, part: 'mcp', mount: (app) => mountMcp(app, options) });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Express } from 'express';
|
|
2
|
+
import { type PartContext } from '../context/context.js';
|
|
3
|
+
import { type HealthCheck } from '../health/health.js';
|
|
4
|
+
import { type ImportModule } from '../manifest/entry.js';
|
|
5
|
+
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
6
|
+
import { type HostPartKind } from '../manifest/parts.js';
|
|
7
|
+
import { type ImagePartKind } from '../manifest/primitives.schema.js';
|
|
8
|
+
import { type PartAppBase } from '../server/app.js';
|
|
9
|
+
import { type Env } from './build-info.js';
|
|
10
|
+
export interface RunnerInput {
|
|
11
|
+
dir: string;
|
|
12
|
+
pkg: ExtensionPackage;
|
|
13
|
+
env: Env;
|
|
14
|
+
ctx: () => PartContext;
|
|
15
|
+
base: PartAppBase;
|
|
16
|
+
openapi: Record<string, unknown> | null;
|
|
17
|
+
importModule?: ImportModule;
|
|
18
|
+
apiAliases?: string[];
|
|
19
|
+
mcpPaths?: string[];
|
|
20
|
+
openListing?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface PartMount {
|
|
23
|
+
mount: (app: Express) => void;
|
|
24
|
+
checks?: Record<string, HealthCheck>;
|
|
25
|
+
start?: () => void;
|
|
26
|
+
stop?: () => void;
|
|
27
|
+
}
|
|
28
|
+
export declare const callCreate: <C>(input: RunnerInput, part: ImagePartKind, ctx: C) => Promise<unknown>;
|
|
29
|
+
export declare const MOUNTS: Record<HostPartKind, (input: RunnerInput) => Promise<PartMount>>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {} from 'express';
|
|
2
|
+
import { generatedOpenapi } from '../api/openapi-doc.js';
|
|
3
|
+
import {} from '../context/context.js';
|
|
4
|
+
import {} from '../health/health.js';
|
|
5
|
+
import { loadCreate } from '../manifest/entry.js';
|
|
6
|
+
import {} from '../manifest/manifest.schema.js';
|
|
7
|
+
import { hasStore } from '../manifest/parts.js';
|
|
8
|
+
import {} from '../manifest/primitives.schema.js';
|
|
9
|
+
import { createSpan } from '../log/span.js';
|
|
10
|
+
import { mountMcp } from '../mcp/mcp-app.js';
|
|
11
|
+
import { createToolRegistry } from '../mcp/tools.js';
|
|
12
|
+
import { mountApiRoutes } from '../server/app.js';
|
|
13
|
+
import { mountApi } from '../server/api-routes.js';
|
|
14
|
+
import { runLog } from '../worker/run-log.js';
|
|
15
|
+
import { memoryRuns, storeRuns } from '../worker/runs.js';
|
|
16
|
+
import { createScheduler } from '../worker/scheduler.js';
|
|
17
|
+
import {} from './build-info.js';
|
|
18
|
+
// ui has no code to run; every other part is its create(ctx).
|
|
19
|
+
export const callCreate = async (input, part, ctx) => (await loadCreate(input.dir, input.pkg, part, input.importModule))(ctx);
|
|
20
|
+
const api = async (input) => {
|
|
21
|
+
const ctx = input.ctx();
|
|
22
|
+
const { router, routes, documents } = await mountApi(ctx, (api) => callCreate(input, 'api', api));
|
|
23
|
+
// Declared routes guard at their own scope, whatever the committed file says.
|
|
24
|
+
const openapi = routes.length > 0 ? generatedOpenapi(input.pkg, routes) : input.openapi;
|
|
25
|
+
const options = { ...input.base, router, routes, openapi, wellKnown: documents };
|
|
26
|
+
return { mount: (app) => mountApiRoutes(app, { ...options, aliases: input.apiAliases }) };
|
|
27
|
+
};
|
|
28
|
+
const mcp = async (input) => {
|
|
29
|
+
const registry = createToolRegistry();
|
|
30
|
+
const ctx = input.ctx();
|
|
31
|
+
await callCreate(input, 'mcp', { ...ctx, tool: registry.tool });
|
|
32
|
+
const token = !input.openListing && ctx.settings['mcp.listing'] === 'token';
|
|
33
|
+
const listing = token ? 'token' : 'open';
|
|
34
|
+
const options = { ...input.base, tools: registry.tools, listing, paths: input.mcpPaths };
|
|
35
|
+
return { mount: (app) => mountMcp(app, options) };
|
|
36
|
+
};
|
|
37
|
+
const worker = async (input) => {
|
|
38
|
+
const ctx = input.ctx();
|
|
39
|
+
const log = runLog(ctx.log);
|
|
40
|
+
const runs = hasStore(input.pkg, 'postgres') ? storeRuns(ctx.store) : memoryRuns();
|
|
41
|
+
const scheduler = createScheduler({ runs, log });
|
|
42
|
+
const span = createSpan(log);
|
|
43
|
+
await callCreate(input, 'worker', { ...ctx, log, span, schedule: scheduler.schedule });
|
|
44
|
+
// The same object ctx.health adds to, so a later registration still shows.
|
|
45
|
+
const checks = Object.assign(input.base.checks ?? {}, scheduler.checks());
|
|
46
|
+
return { mount: () => undefined, checks, start: scheduler.start, stop: scheduler.stop };
|
|
47
|
+
};
|
|
48
|
+
export const MOUNTS = {
|
|
49
|
+
api,
|
|
50
|
+
mcp,
|
|
51
|
+
worker,
|
|
52
|
+
};
|
|
@@ -1,20 +1,7 @@
|
|
|
1
1
|
import { type Express } from 'express';
|
|
2
|
-
import { type PartContext } from '../context/context.js';
|
|
3
|
-
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
4
|
-
import { type ImportModule } from '../manifest/entry.js';
|
|
5
2
|
import { type ImagePartKind } from '../manifest/primitives.schema.js';
|
|
6
|
-
import { type
|
|
7
|
-
|
|
8
|
-
export interface RunnerInput {
|
|
9
|
-
dir: string;
|
|
10
|
-
pkg: ExtensionPackage;
|
|
11
|
-
env: Env;
|
|
12
|
-
ctx: () => PartContext;
|
|
13
|
-
base: PartAppBase;
|
|
14
|
-
openapi: Record<string, unknown> | null;
|
|
15
|
-
importModule?: ImportModule;
|
|
16
|
-
apiAliases?: string[];
|
|
17
|
-
}
|
|
3
|
+
import { type RunnerInput } from './part-mounts.js';
|
|
4
|
+
export { type RunnerInput } from './part-mounts.js';
|
|
18
5
|
export interface Running {
|
|
19
6
|
app: Express;
|
|
20
7
|
stop?: () => void;
|
|
@@ -1,47 +1,16 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
-
import { generatedOpenapi } from '../api/openapi-doc.js';
|
|
3
2
|
import {} from 'express';
|
|
4
|
-
import {} from '../context/context.js';
|
|
5
|
-
import {} from '../manifest/manifest.schema.js';
|
|
6
|
-
import { loadCreate } from '../manifest/entry.js';
|
|
7
|
-
import { hasStore } from '../manifest/parts.js';
|
|
8
|
-
import {} from '../manifest/primitives.schema.js';
|
|
9
|
-
import { createSpan } from '../log/span.js';
|
|
10
|
-
import { createMcpApp } from '../mcp/mcp-app.js';
|
|
11
|
-
import { createToolRegistry } from '../mcp/tools.js';
|
|
12
3
|
import { createPagesApp, platformSources } from '../pages/pages-app.js';
|
|
13
4
|
import {} from '../pages/pages.js';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {} from './build-info.js';
|
|
5
|
+
import {} from '../manifest/primitives.schema.js';
|
|
6
|
+
import { createPartApp } from '../server/app.js';
|
|
17
7
|
import { createUiApp } from '../ui/ui-app.js';
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const ctx = input.ctx();
|
|
25
|
-
const { router, routes, documents } = await mountApi(ctx, (api) => callCreate(input, 'api', api));
|
|
26
|
-
// Declared routes guard at their own scope, whatever the committed file says.
|
|
27
|
-
const openapi = routes.length > 0 ? generatedOpenapi(input.pkg, routes) : input.openapi;
|
|
28
|
-
return {
|
|
29
|
-
app: createApiApp({
|
|
30
|
-
...input.base,
|
|
31
|
-
router,
|
|
32
|
-
routes,
|
|
33
|
-
openapi,
|
|
34
|
-
wellKnown: documents,
|
|
35
|
-
aliases: input.apiAliases,
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
const mcp = async (input) => {
|
|
40
|
-
const registry = createToolRegistry();
|
|
41
|
-
const ctx = input.ctx();
|
|
42
|
-
await callCreate(input, 'mcp', { ...ctx, tool: registry.tool });
|
|
43
|
-
const listing = ctx.settings['mcp.listing'] === 'token' ? 'token' : 'open';
|
|
44
|
-
return { app: createMcpApp({ ...input.base, tools: registry.tools, listing }) };
|
|
8
|
+
import { callCreate, MOUNTS } from './part-mounts.js';
|
|
9
|
+
export {} from './part-mounts.js';
|
|
10
|
+
// One part in its own image: the part's mount on the kit app.
|
|
11
|
+
const own = (part) => async (input) => {
|
|
12
|
+
const { mount } = await MOUNTS[part](input);
|
|
13
|
+
return { app: createPartApp({ ...input.base, part, mount }) };
|
|
45
14
|
};
|
|
46
15
|
const pages = async (input) => {
|
|
47
16
|
const site = (await callCreate(input, 'pages', input.ctx()));
|
|
@@ -55,27 +24,13 @@ const ui = async (input) => ({
|
|
|
55
24
|
}),
|
|
56
25
|
});
|
|
57
26
|
const worker = async (input) => {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const scheduler = createScheduler({ runs, log });
|
|
62
|
-
await callCreate(input, 'worker', {
|
|
63
|
-
...ctx,
|
|
64
|
-
log,
|
|
65
|
-
span: createSpan(log),
|
|
66
|
-
schedule: scheduler.schedule,
|
|
67
|
-
});
|
|
68
|
-
// The same object ctx.health adds to, so a later registration still shows.
|
|
69
|
-
const checks = Object.assign(input.base.checks ?? {}, scheduler.checks());
|
|
70
|
-
scheduler.start();
|
|
71
|
-
return {
|
|
72
|
-
app: createPartApp({ ...input.base, checks, part: 'worker', mount: () => undefined }),
|
|
73
|
-
stop: scheduler.stop,
|
|
74
|
-
};
|
|
27
|
+
const { mount, checks, start, stop } = await MOUNTS.worker(input);
|
|
28
|
+
start?.();
|
|
29
|
+
return { app: createPartApp({ ...input.base, checks, part: 'worker', mount }), stop };
|
|
75
30
|
};
|
|
76
31
|
export const RUNNERS = {
|
|
77
|
-
api,
|
|
78
|
-
mcp,
|
|
32
|
+
api: own('api'),
|
|
33
|
+
mcp: own('mcp'),
|
|
79
34
|
pages,
|
|
80
35
|
ui,
|
|
81
36
|
worker,
|
package/dist/server/app.d.ts
CHANGED
|
@@ -24,6 +24,8 @@ export interface PartAppBase {
|
|
|
24
24
|
instance?: string;
|
|
25
25
|
startedAt?: number;
|
|
26
26
|
guards?: RequestHandler[];
|
|
27
|
+
parts?: ImagePartKind[];
|
|
28
|
+
clockRate?: number;
|
|
27
29
|
}
|
|
28
30
|
export interface PartAppOptions extends PartAppBase {
|
|
29
31
|
part: ImagePartKind;
|
|
@@ -43,4 +45,5 @@ export interface ApiAppOptions extends PartAppBase {
|
|
|
43
45
|
export declare const PUBLIC_CORS: CorsOptions;
|
|
44
46
|
export declare const BODY_LIMIT = "1mb";
|
|
45
47
|
export declare const createPartApp: (options: PartAppOptions) => Express;
|
|
48
|
+
export declare const mountApiRoutes: (app: Express, options: ApiAppOptions) => void;
|
|
46
49
|
export declare const createApiApp: (options: ApiAppOptions) => Express;
|
package/dist/server/app.js
CHANGED
|
@@ -52,6 +52,8 @@ const healthHandler = (options) => createHealthHandler({
|
|
|
52
52
|
log: options.log,
|
|
53
53
|
instance: options.instance,
|
|
54
54
|
startedAt: options.startedAt,
|
|
55
|
+
parts: options.parts,
|
|
56
|
+
clockRate: options.clockRate,
|
|
55
57
|
});
|
|
56
58
|
// The kit app every part image runs: agcid, headers, /health, discovery, the part, the envelope.
|
|
57
59
|
export const createPartApp = (options) => {
|
|
@@ -104,19 +106,17 @@ const routeGuard = (options) => {
|
|
|
104
106
|
next();
|
|
105
107
|
};
|
|
106
108
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
app.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
});
|
|
109
|
+
// The api routes on an app: the part's own (createApiApp) or the host's one app of all parts.
|
|
110
|
+
export const mountApiRoutes = (app, options) => {
|
|
111
|
+
const prefixes = [apiPrefix(options.pkg.agentage.id), ...(options.aliases ?? [])];
|
|
112
|
+
app.use(prefixes, cors(PUBLIC_CORS));
|
|
113
|
+
for (const { name, render } of options.wellKnown ?? [])
|
|
114
|
+
app.get(`/.well-known/${name}`, wellKnownHandler(render));
|
|
115
|
+
const { openapi } = options;
|
|
116
|
+
if (openapi)
|
|
117
|
+
for (const at of prefixes)
|
|
118
|
+
app.get(`${at}/openapi.json`, openapiHandler(openapi));
|
|
119
|
+
const json = express.json({ limit: BODY_LIMIT });
|
|
120
|
+
app.use(prefixes, routeGuard(options), json, options.router);
|
|
121
|
+
};
|
|
122
|
+
export const createApiApp = (options) => createPartApp({ ...options, part: 'api', mount: (app) => mountApiRoutes(app, options) });
|
package/dist/tool/check.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type Finding = {
|
|
|
14
14
|
file?: string;
|
|
15
15
|
line?: number;
|
|
16
16
|
problem: string;
|
|
17
|
+
warning?: true;
|
|
17
18
|
};
|
|
18
19
|
export type CheckProblem = Finding & {
|
|
19
20
|
rule: string;
|
|
@@ -30,6 +31,7 @@ export interface CheckReport {
|
|
|
30
31
|
conforms: boolean;
|
|
31
32
|
rules: string[];
|
|
32
33
|
problems: CheckProblem[];
|
|
34
|
+
warnings?: CheckProblem[];
|
|
33
35
|
skipped: Record<string, string>;
|
|
34
36
|
}
|
|
35
37
|
export declare const NOT_BUILT = "is missing: build the package first (npm run build)";
|
package/dist/tool/check.js
CHANGED
|
@@ -14,7 +14,7 @@ import { exportedPartCode } from './rules/folders.js';
|
|
|
14
14
|
import { sealing } from './rules/sealing.js';
|
|
15
15
|
import { store } from './rules/store.js';
|
|
16
16
|
import { surface } from './rules/surface.js';
|
|
17
|
-
import { KIT_VERSION } from './kit-version.js';
|
|
17
|
+
import { KIT_FLOOR, KIT_VERSION, olderKitMinor } from './kit-version.js';
|
|
18
18
|
import { assertBuilt, exists } from './stage.js';
|
|
19
19
|
const RECIPE = /^(?:dockerfile|containerfile)(?:\..+)?$|^(?:docker-)?compose(?:\.[\w-]+)?\.ya?ml$/i;
|
|
20
20
|
export const NOT_BUILT = 'is missing: build the package first (npm run build)';
|
|
@@ -73,6 +73,16 @@ const specProblem = (name, spec, needed) => {
|
|
|
73
73
|
return [`${name} ${spec || '""'} needs a version range`];
|
|
74
74
|
return semver.subset(spec, needed) ? [] : [`${name} ${spec}, needs ${needed}`];
|
|
75
75
|
};
|
|
76
|
+
// D8: an older minor from the floor up still runs (a warning); below it or above the kit, refused.
|
|
77
|
+
const kitRange = (range) => {
|
|
78
|
+
if (semver.satisfies(KIT_VERSION, range))
|
|
79
|
+
return [];
|
|
80
|
+
const older = olderKitMinor(range);
|
|
81
|
+
if (!older)
|
|
82
|
+
return [{ problem: `kit ${KIT_VERSION} is outside engines.agentage ${range}` }];
|
|
83
|
+
const problem = `engines.agentage ${range} is kit ${older}: kit ${KIT_VERSION} runs it (floor ${KIT_FLOOR}), update the extension`;
|
|
84
|
+
return [{ problem, warning: true }];
|
|
85
|
+
};
|
|
76
86
|
const stack = {
|
|
77
87
|
name: 'stack',
|
|
78
88
|
run: async ({ pkg }) => {
|
|
@@ -87,34 +97,39 @@ const stack = {
|
|
|
87
97
|
});
|
|
88
98
|
if ('@modelcontextprotocol/sdk' in deps)
|
|
89
99
|
found.push('@modelcontextprotocol/sdk is MCP SDK 1: use @modelcontextprotocol/server ^2');
|
|
90
|
-
|
|
91
|
-
found.push(`kit ${KIT_VERSION} is outside engines.agentage ${range}`);
|
|
92
|
-
return found.map((problem) => ({ problem }));
|
|
100
|
+
return [...found.map((problem) => ({ problem })), ...kitRange(range)];
|
|
93
101
|
},
|
|
94
102
|
};
|
|
95
103
|
// The closed list of extension-kit section 7, in its order; build runs it before any image.
|
|
96
104
|
export const RULES = [manifest, entries, surface, stack, store, sealing];
|
|
97
105
|
// A thrown message names its file relative to the package, as every problem line does.
|
|
98
106
|
const runRule = (rule, input) => rule.run(input).catch((err) => [{ problem: messageOf(err).replace(`${input.dir}/`, '') }]);
|
|
107
|
+
const split = (found) => {
|
|
108
|
+
const warnings = found.flatMap(({ warning, ...rest }) => (warning ? [rest] : []));
|
|
109
|
+
const problems = found.filter((finding) => !finding.warning);
|
|
110
|
+
return { problems, warned: warnings.length > 0 ? { warnings } : {} };
|
|
111
|
+
};
|
|
99
112
|
export const check = async (at, options = {}) => {
|
|
100
113
|
const { rules = RULES, run = runCommand } = options;
|
|
101
114
|
const dir = resolve(at);
|
|
102
115
|
const read = readJsonIfExists(join(dir, 'package.json')).catch(() => ({}));
|
|
103
116
|
const pkg = ((await read) ?? {});
|
|
104
|
-
const
|
|
117
|
+
const found = [];
|
|
105
118
|
const skipped = {};
|
|
106
119
|
for (const rule of rules) {
|
|
107
120
|
const result = await runRule(rule, { ...options, dir, pkg, run });
|
|
108
121
|
if ('skipped' in result)
|
|
109
122
|
skipped[rule.name] = result.skipped;
|
|
110
123
|
else
|
|
111
|
-
|
|
112
|
-
if (rule.name === 'manifest' &&
|
|
124
|
+
found.push(...result.map((finding) => ({ rule: rule.name, ...finding })));
|
|
125
|
+
if (rule.name === 'manifest' && found.length > 0)
|
|
113
126
|
break;
|
|
114
127
|
}
|
|
128
|
+
const { problems, warned } = split(found);
|
|
115
129
|
const names = rules.map((rule) => rule.name);
|
|
116
130
|
const conforms = problems.length === 0;
|
|
117
|
-
|
|
131
|
+
const { agentage, version } = pkg;
|
|
132
|
+
return { id: agentage?.id, version, conforms, rules: names, problems, ...warned, skipped };
|
|
118
133
|
};
|
|
119
134
|
// What build runs after the compile and before any image: any problem stops everything.
|
|
120
135
|
export const assertConforms = async (dir, options = {}) => {
|
|
@@ -3,5 +3,5 @@ export interface ContainerParts {
|
|
|
3
3
|
runs: string[];
|
|
4
4
|
skipped: string[];
|
|
5
5
|
}
|
|
6
|
-
export declare const NO_API = "build --container needs an api part: the one image runs
|
|
6
|
+
export declare const NO_API = "build --container needs an api, mcp or worker part: the one image runs the server parts";
|
|
7
7
|
export declare const containerParts: (pkg: ExtensionPackage) => ContainerParts;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {} from '../manifest/manifest.schema.js';
|
|
2
|
-
import { imageParts } from '../manifest/parts.js';
|
|
3
|
-
export const NO_API = 'build --container needs an api part: the one image runs
|
|
4
|
-
// The kit host (host/host-extension.ts)
|
|
2
|
+
import { hostParts, imageParts } from '../manifest/parts.js';
|
|
3
|
+
export const NO_API = 'build --container needs an api, mcp or worker part: the one image runs the server parts';
|
|
4
|
+
// The kit host (host/host-extension.ts) runs every server part; pages and ui come in phase 2.
|
|
5
5
|
export const containerParts = (pkg) => {
|
|
6
|
-
const
|
|
7
|
-
if (
|
|
6
|
+
const runs = hostParts(pkg);
|
|
7
|
+
if (runs.length === 0)
|
|
8
8
|
throw new Error(NO_API);
|
|
9
|
-
return { runs
|
|
9
|
+
return { runs, skipped: imageParts(pkg).filter((kind) => !runs.includes(kind)) };
|
|
10
10
|
};
|
package/dist/tool/format.js
CHANGED
|
@@ -5,10 +5,15 @@ import { plural } from './up/lines.js';
|
|
|
5
5
|
const shortDigest = (digest) => digest.slice(0, 'sha256:'.length + 8);
|
|
6
6
|
const rowsOf = ({ images, container }) => [
|
|
7
7
|
...images.map(({ part, tag, digest }) => ({ label: part, tag, digest })),
|
|
8
|
-
...(container ? [{ label:
|
|
8
|
+
...(container ? [{ label: 'image', ...container }] : []),
|
|
9
9
|
];
|
|
10
|
-
const
|
|
11
|
-
|
|
10
|
+
const partsLine = ({ container }) => {
|
|
11
|
+
if (!container)
|
|
12
|
+
return [];
|
|
13
|
+
const skipped = container.skipped.length > 0 ? container.skipped.join(', ') : 'none';
|
|
14
|
+
return [`runs: ${container.runs.join(', ')}; skipped: ${skipped}`];
|
|
15
|
+
};
|
|
16
|
+
// One line per image (the one image as "image"), the parts it runs and skips, then the record.
|
|
12
17
|
export const buildLines = (result, cwd = process.cwd()) => {
|
|
13
18
|
const rows = rowsOf(result);
|
|
14
19
|
const width = Math.max(...rows.map((row) => row.tag.length)) + 2;
|
|
@@ -16,22 +21,24 @@ export const buildLines = (result, cwd = process.cwd()) => {
|
|
|
16
21
|
const state = row.digest ? `${shortDigest(row.digest)} pushed` : 'built';
|
|
17
22
|
return `${row.label.padEnd(8)}${row.tag.padEnd(width)}${state}`;
|
|
18
23
|
});
|
|
19
|
-
lines.push(...
|
|
24
|
+
lines.push(...partsLine(result));
|
|
20
25
|
if (result.recordFile)
|
|
21
26
|
lines.push(`${'record'.padEnd(8)}${relative(cwd, result.recordFile)}`);
|
|
22
27
|
return lines;
|
|
23
28
|
};
|
|
24
29
|
const where = ({ file, line }) => file ? `${file}${line ? `:${line}` : ''} ` : '';
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
const lineOf = (found) => `${found.rule}: ${where(found)}${found.problem}`;
|
|
31
|
+
export const problemLines = (report) => report.problems.map(lineOf);
|
|
32
|
+
const warningLines = ({ warnings = [] }) => warnings.map((found) => `warning ${lineOf(found)}`);
|
|
33
|
+
// What `agentage extension check` prints (sheet C2): the rules line and PASS, or each problem and FAIL; warnings first.
|
|
27
34
|
export const checkLines = (report) => {
|
|
28
35
|
const { rules, skipped, problems } = report;
|
|
29
36
|
if (report.conforms) {
|
|
30
37
|
const states = rules.map((name) => `${name} ${skipped[name] ? `skipped: ${skipped[name]}` : 'ok'}`);
|
|
31
38
|
const pass = `PASS ${report.id} ${report.version} conforms (${plural(rules.length, 'rule')})`;
|
|
32
|
-
return [states.join(' · '), pass];
|
|
39
|
+
return [states.join(' · '), ...warningLines(report), pass];
|
|
33
40
|
}
|
|
34
41
|
const failed = new Set(problems.map((found) => found.rule)).size;
|
|
35
42
|
const fail = `FAIL ${plural(problems.length, 'problem')} in ${plural(failed, 'rule')}`;
|
|
36
|
-
return [...problemLines(report), fail];
|
|
43
|
+
return [...warningLines(report), ...problemLines(report), fail];
|
|
37
44
|
};
|