@agentage/extension 0.13.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/discovery/discovery.d.ts +1 -0
- package/dist/discovery/discovery.schema.d.ts +2 -0
- package/dist/discovery/discovery.schema.js +22 -10
- 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.d.ts +9 -0
- package/dist/host/daemon/add.js +84 -0
- 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 +12 -4
- package/dist/host/daemon/child.js +78 -44
- package/dist/host/daemon/daemon-files.d.ts +6 -5
- package/dist/host/daemon/daemon-files.js +20 -12
- package/dist/host/daemon/daemon-owner.d.ts +1 -0
- package/dist/host/daemon/daemon-owner.js +32 -0
- package/dist/host/daemon/daemon.d.ts +3 -3
- package/dist/host/daemon/daemon.js +72 -35
- package/dist/host/daemon/entries.d.ts +21 -0
- package/dist/host/daemon/entries.js +24 -0
- 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 +17 -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/installation.d.ts +17 -4
- package/dist/host/daemon/installation.js +52 -8
- package/dist/host/daemon/installer-call.d.ts +16 -2
- package/dist/host/daemon/installer-call.js +33 -7
- package/dist/host/daemon/json-file.d.ts +3 -2
- package/dist/host/daemon/json-file.js +21 -10
- package/dist/host/daemon/lane.d.ts +1 -3
- package/dist/host/daemon/lane.js +4 -9
- 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 +15 -0
- package/dist/host/daemon/limits.js +29 -0
- package/dist/host/daemon/ops.d.ts +2 -26
- package/dist/host/daemon/ops.js +46 -103
- package/dist/host/daemon/patch-values.d.ts +6 -0
- package/dist/host/daemon/patch-values.js +39 -0
- package/dist/host/daemon/pending.d.ts +15 -0
- package/dist/host/daemon/pending.js +18 -0
- package/dist/host/daemon/proxy.d.ts +3 -2
- package/dist/host/daemon/proxy.js +54 -24
- package/dist/host/daemon/queue.d.ts +1 -0
- package/dist/host/daemon/queue.js +19 -0
- 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 +3 -9
- package/dist/host/daemon/routes.js +54 -22
- 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/stopping.d.ts +10 -0
- package/dist/host/daemon/stopping.js +28 -0
- package/dist/host/daemon/supervisor.d.ts +19 -11
- package/dist/host/daemon/supervisor.js +39 -47
- package/dist/host/daemon/write-all.d.ts +8 -0
- package/dist/host/daemon/write-all.js +45 -0
- package/dist/host/data-lock.d.ts +3 -1
- package/dist/host/data-lock.js +88 -29
- package/dist/host/host-env.d.ts +3 -1
- package/dist/host/host-env.js +10 -2
- package/dist/host/host-extension.d.ts +8 -0
- package/dist/host/host-extension.js +30 -45
- package/dist/host/host-parts.d.ts +25 -0
- package/dist/host/host-parts.js +75 -0
- package/dist/host/host-store.d.ts +11 -1
- package/dist/host/host-store.js +45 -12
- package/dist/host/index.d.ts +4 -0
- package/dist/host/index.js +4 -0
- 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.d.ts +2 -1
- package/dist/host/serve-host.js +16 -10
- 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 +5 -1
- package/dist/server/app.js +17 -17
- package/dist/server/serve.d.ts +3 -0
- package/dist/server/serve.js +9 -4
- package/dist/tool/build.d.ts +3 -0
- package/dist/tool/build.js +42 -27
- package/dist/tool/capabilities.d.ts +1 -0
- package/dist/tool/capabilities.js +8 -0
- package/dist/tool/check.d.ts +2 -0
- package/dist/tool/check.js +23 -8
- package/dist/tool/container-parts.d.ts +7 -0
- package/dist/tool/container-parts.js +10 -0
- package/dist/tool/container-recipe.d.ts +4 -0
- package/dist/tool/container-recipe.js +55 -0
- package/dist/tool/container-stage.d.ts +3 -0
- package/dist/tool/container-stage.js +51 -0
- package/dist/tool/container.d.ts +73 -0
- package/dist/tool/container.js +28 -0
- package/dist/tool/docker.d.ts +5 -0
- package/dist/tool/docker.js +15 -0
- package/dist/tool/format.js +23 -9
- package/dist/tool/index.d.ts +2 -0
- package/dist/tool/index.js +2 -0
- package/dist/tool/kit-version.d.ts +3 -0
- package/dist/tool/kit-version.js +28 -2
- package/dist/tool/labels.d.ts +1 -1
- package/dist/tool/labels.js +4 -2
- package/dist/tool/main.js +10 -1
- package/dist/tool/stage.d.ts +1 -0
- package/dist/tool/stage.js +1 -1
- package/dist/tool/up/local-record.d.ts +1 -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/extension-discovery.schema.json +8 -1
- package/schemas/extension-record.schema.json +8 -1
- package/schemas/health.schema.json +17 -0
- package/dist/host/daemon/secret-names.d.ts +0 -1
- package/dist/host/daemon/secret-names.js +0 -14
- package/dist/host/daemon/setting-values.d.ts +0 -1
- package/dist/host/daemon/setting-values.js +0 -26
package/dist/server/app.js
CHANGED
|
@@ -52,13 +52,15 @@ 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) => {
|
|
58
60
|
const app = express();
|
|
59
61
|
// The gateway calls parts over a private network; its X-Forwarded-Proto then sets req.protocol.
|
|
60
62
|
app.set('trust proxy', 'loopback, linklocal, uniquelocal');
|
|
61
|
-
app.use(dropCookie, agcidMiddleware, helmet(options.helmet));
|
|
63
|
+
app.use(dropCookie, agcidMiddleware, helmet(options.helmet), ...(options.guards ?? []));
|
|
62
64
|
app.get('/health', healthHandler(options));
|
|
63
65
|
// After /health: it is probed every few seconds and never gets a request line.
|
|
64
66
|
app.use(requestLine(options.log, options.onExit));
|
|
@@ -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/server/serve.d.ts
CHANGED
|
@@ -7,7 +7,10 @@ export interface ServeOptions {
|
|
|
7
7
|
log: Log;
|
|
8
8
|
exit?: (code: number) => void;
|
|
9
9
|
signals?: NodeJS.Signals[];
|
|
10
|
+
graceMs?: number;
|
|
10
11
|
}
|
|
12
|
+
export declare const GRACE_MS = 10000;
|
|
11
13
|
export declare const listen: (app: Express, port: number, host?: string) => Promise<Server>;
|
|
14
|
+
export declare const closeNow: (server: Server) => Promise<void>;
|
|
12
15
|
export declare const shutdownOn: (server: Server, options: ServeOptions) => (() => void);
|
|
13
16
|
export declare const serve: (options: ServeOptions) => Promise<Server>;
|
package/dist/server/serve.js
CHANGED
|
@@ -2,20 +2,25 @@ import {} from 'node:http';
|
|
|
2
2
|
import {} from 'node:net';
|
|
3
3
|
import {} from 'express';
|
|
4
4
|
import {} from '../log/log.js';
|
|
5
|
-
const GRACE_MS = 10_000;
|
|
5
|
+
export const GRACE_MS = 10_000;
|
|
6
6
|
export const listen = (app, port, host) => new Promise((resolve, reject) => {
|
|
7
7
|
const done = (err) => (err ? reject(err) : resolve(server));
|
|
8
8
|
const server = host === undefined ? app.listen(port, done) : app.listen(port, host, done);
|
|
9
9
|
});
|
|
10
|
+
// At once: open and idle connections end now; a drain is shutdownOn.
|
|
11
|
+
export const closeNow = (server) => new Promise((resolve) => {
|
|
12
|
+
server.close(() => resolve());
|
|
13
|
+
server.closeAllConnections();
|
|
14
|
+
});
|
|
10
15
|
// Open requests are answered; a keep-alive connection is closed once idle, not at its timeout.
|
|
11
|
-
const drain = (server, exit) => {
|
|
16
|
+
const drain = (server, exit, graceMs) => {
|
|
12
17
|
const idle = setInterval(() => server.closeIdleConnections(), 100).unref();
|
|
13
18
|
server.close((err) => {
|
|
14
19
|
clearInterval(idle);
|
|
15
20
|
exit(err ? 1 : 0);
|
|
16
21
|
});
|
|
17
22
|
server.closeIdleConnections();
|
|
18
|
-
setTimeout(() => exit(1),
|
|
23
|
+
setTimeout(() => exit(1), graceMs).unref();
|
|
19
24
|
};
|
|
20
25
|
// SIGTERM drains; a close error or a drain past the grace period exits 1; a second Ctrl-C at once.
|
|
21
26
|
export const shutdownOn = (server, options) => {
|
|
@@ -34,7 +39,7 @@ export const shutdownOn = (server, options) => {
|
|
|
34
39
|
return;
|
|
35
40
|
stopping = true;
|
|
36
41
|
options.log.info('shutting down');
|
|
37
|
-
drain(server, exit);
|
|
42
|
+
drain(server, exit, options.graceMs ?? GRACE_MS);
|
|
38
43
|
};
|
|
39
44
|
for (const signal of options.signals ?? ['SIGTERM', 'SIGINT'])
|
|
40
45
|
process.on(signal, () => stop(signal));
|
package/dist/tool/build.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ExtensionRecord } from '../discovery/discovery.schema.js';
|
|
|
3
3
|
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
4
4
|
import { type ImagePartKind } from '../manifest/primitives.schema.js';
|
|
5
5
|
import { type Env } from '../runtime/build-info.js';
|
|
6
|
+
import { type BuiltContainer } from './container.js';
|
|
6
7
|
import { type Docker } from './docker.js';
|
|
7
8
|
import { type Run } from './exec.js';
|
|
8
9
|
export declare const DEFAULT_REGISTRY = "ghcr.io/agentage";
|
|
@@ -10,6 +11,7 @@ export interface BuildOptions {
|
|
|
10
11
|
dir?: string;
|
|
11
12
|
push?: boolean;
|
|
12
13
|
registry?: string;
|
|
14
|
+
container?: boolean;
|
|
13
15
|
env?: Env;
|
|
14
16
|
}
|
|
15
17
|
export interface BuildDeps {
|
|
@@ -29,6 +31,7 @@ export interface BuildResult {
|
|
|
29
31
|
commit: string;
|
|
30
32
|
buildTime: string;
|
|
31
33
|
images: BuiltImage[];
|
|
34
|
+
container?: BuiltContainer;
|
|
32
35
|
recordFile?: string;
|
|
33
36
|
}
|
|
34
37
|
export declare const imageTag: (registry: string, pkg: ExtensionPackage, part: ImagePartKind) => string;
|
package/dist/tool/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { writeFile } from 'node:fs/promises';
|
|
2
2
|
import { join, resolve } from 'node:path';
|
|
3
3
|
import { recordOf, validateRecord } from '../discovery/discovery.js';
|
|
4
4
|
import {} from '../discovery/discovery.schema.js';
|
|
@@ -9,7 +9,9 @@ import { readManifest } from '../manifest/read-manifest.js';
|
|
|
9
9
|
import {} from '../runtime/build-info.js';
|
|
10
10
|
import { resolveBuildInfo } from './build-info.js';
|
|
11
11
|
import { assertConforms } from './check.js';
|
|
12
|
-
import {
|
|
12
|
+
import { containerParts } from './container-parts.js';
|
|
13
|
+
import { buildContainer, CONTAINER_RECORD_FILE } from './container.js';
|
|
14
|
+
import { buildStaged, createDocker, pushByDigest } from './docker.js';
|
|
13
15
|
import { mustRun, runCommand } from './exec.js';
|
|
14
16
|
import { labelsOf } from './labels.js';
|
|
15
17
|
import { recordExtras } from './record-extras.js';
|
|
@@ -24,24 +26,16 @@ const compile = async (dir, pkg, run) => {
|
|
|
24
26
|
};
|
|
25
27
|
const buildImage = async (job, docker, tmpRoot) => {
|
|
26
28
|
const context = await stageContext(job.dir, job.pkg, job.part, tmpRoot);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
IMAGE: job.tag,
|
|
32
|
-
};
|
|
33
|
-
const labels = labelsOf(job.pkg, job.part, job.info);
|
|
34
|
-
await docker.build({ context, tag: job.tag, buildArgs, labels });
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
await rm(context, { recursive: true, force: true });
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
const pushImage = async (job, docker) => {
|
|
41
|
-
const digest = await docker.push(job.tag);
|
|
42
|
-
const repository = job.tag.slice(0, job.tag.lastIndexOf(':'));
|
|
43
|
-
return { part: job.part, tag: job.tag, digest, image: `${repository}@${digest}` };
|
|
29
|
+
const { commit, buildTime } = job.info;
|
|
30
|
+
const buildArgs = { COMMIT_SHA: commit, BUILD_TIME: buildTime, IMAGE: job.tag };
|
|
31
|
+
const labels = labelsOf(job.pkg, job.part, job.info);
|
|
32
|
+
await buildStaged(docker, { context, tag: job.tag, buildArgs, labels });
|
|
44
33
|
};
|
|
34
|
+
const pushImage = async (job, docker) => ({
|
|
35
|
+
part: job.part,
|
|
36
|
+
tag: job.tag,
|
|
37
|
+
...(await pushByDigest(docker, job.tag)),
|
|
38
|
+
});
|
|
45
39
|
// The record from the code and the images by digest; `up` writes the same shape from local digests.
|
|
46
40
|
export const recordFor = async (dir, pkg, info, images) => {
|
|
47
41
|
const byPart = Object.fromEntries(images.map((built) => [built.part, built.image]));
|
|
@@ -51,9 +45,12 @@ const writeRecord = async (dir, record, file = join(dir, 'dist', RECORD_FILE)) =
|
|
|
51
45
|
await writeFile(file, `${JSON.stringify(record, null, 2)}\n`);
|
|
52
46
|
return file;
|
|
53
47
|
};
|
|
48
|
+
const targetOf = (options, deps) => ({
|
|
49
|
+
docker: deps.docker ?? createDocker(deps.run),
|
|
50
|
+
registry: options.registry ?? DEFAULT_REGISTRY,
|
|
51
|
+
});
|
|
54
52
|
const buildParts = async (base, options, deps) => {
|
|
55
|
-
const docker
|
|
56
|
-
const registry = options.registry ?? DEFAULT_REGISTRY;
|
|
53
|
+
const { docker, registry } = targetOf(options, deps);
|
|
57
54
|
const images = [];
|
|
58
55
|
for (const part of imageParts(base.pkg)) {
|
|
59
56
|
const job = { ...base, part, tag: imageTag(registry, base.pkg, part) };
|
|
@@ -62,16 +59,34 @@ const buildParts = async (base, options, deps) => {
|
|
|
62
59
|
}
|
|
63
60
|
return images;
|
|
64
61
|
};
|
|
65
|
-
//
|
|
62
|
+
// --container: one image; with --push also dist/agentage-container.json.
|
|
63
|
+
const containerOf = async (base, parts, opts, deps) => {
|
|
64
|
+
const { docker, registry } = targetOf(opts, deps);
|
|
65
|
+
const job = { ...base, parts, registry, push: opts.push, tmpRoot: deps.tmpRoot };
|
|
66
|
+
const { container, record } = await buildContainer(job, docker);
|
|
67
|
+
if (!record)
|
|
68
|
+
return { images: [], container };
|
|
69
|
+
const file = join(base.dir, 'dist', CONTAINER_RECORD_FILE);
|
|
70
|
+
return { images: [], container, recordFile: await writeRecord(base.dir, record, file) };
|
|
71
|
+
};
|
|
72
|
+
const partImages = async (base, options, deps) => {
|
|
73
|
+
const images = await buildParts(base, options, deps);
|
|
74
|
+
if (!options.push)
|
|
75
|
+
return { images };
|
|
76
|
+
const record = await recordFor(base.dir, base.pkg, base.info, images);
|
|
77
|
+
return { images, recordFile: await writeRecord(base.dir, record) };
|
|
78
|
+
};
|
|
79
|
+
// Validate, compile, check, one image per part (or the one image); --push pushes, writes the record.
|
|
66
80
|
export const build = async (options = {}, deps = { run: runCommand }) => {
|
|
67
81
|
const dir = resolve(options.dir ?? '.');
|
|
68
82
|
const pkg = await readManifest(dir);
|
|
83
|
+
const parts = options.container ? containerParts(pkg) : undefined;
|
|
69
84
|
const info = await resolveBuildInfo(dir, options.env ?? process.env, deps.run);
|
|
70
85
|
await compile(dir, pkg, deps.run);
|
|
71
86
|
await assertConforms(dir, { run: deps.run });
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return {
|
|
87
|
+
const base = { dir, pkg, info };
|
|
88
|
+
const built = parts
|
|
89
|
+
? await containerOf(base, parts, options, deps)
|
|
90
|
+
: await partImages(base, options, deps);
|
|
91
|
+
return { id: pkg.agentage.id, version: pkg.version, ...info, ...built };
|
|
77
92
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const capabilities: readonly ["container", "localOnly", "installDisabled", "updateInstallation", "withFileLock"];
|
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 = {}) => {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
2
|
+
export interface ContainerParts {
|
|
3
|
+
runs: string[];
|
|
4
|
+
skipped: string[];
|
|
5
|
+
}
|
|
6
|
+
export declare const NO_API = "build --container needs an api, mcp or worker part: the one image runs the server parts";
|
|
7
|
+
export declare const containerParts: (pkg: ExtensionPackage) => ContainerParts;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {} from '../manifest/manifest.schema.js';
|
|
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
|
+
export const containerParts = (pkg) => {
|
|
6
|
+
const runs = hostParts(pkg);
|
|
7
|
+
if (runs.length === 0)
|
|
8
|
+
throw new Error(NO_API);
|
|
9
|
+
return { runs, skipped: imageParts(pkg).filter((kind) => !runs.includes(kind)) };
|
|
10
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export const CONTAINER_PORT = 8080;
|
|
2
|
+
// The volume holds the store folder, so its <dir>.lock sibling persists with it.
|
|
3
|
+
const DATA_VOLUME = '/data';
|
|
4
|
+
const STORE_DIR = `${DATA_VOLUME}/store`;
|
|
5
|
+
const HEALTH_PROBE = `fetch('http://127.0.0.1:'+(process.env.PORT||${CONTAINER_PORT})+'/health')` +
|
|
6
|
+
'.then((r) => process.exit(r.status === 200 || r.status === 503 ? 0 : 1), () => process.exit(1))';
|
|
7
|
+
const DEPS = [
|
|
8
|
+
'# syntax=docker/dockerfile:1',
|
|
9
|
+
'# Generated by @agentage/extension build --container. Extension authors never write a Dockerfile.',
|
|
10
|
+
'FROM node:26-alpine AS deps',
|
|
11
|
+
'WORKDIR /app',
|
|
12
|
+
'COPY deps/ ./',
|
|
13
|
+
'RUN npm ci --omit=dev --no-audit --no-fund',
|
|
14
|
+
'',
|
|
15
|
+
];
|
|
16
|
+
// PGlite is an optional peer and a dev dependency of an extension, so npm ci --omit=dev drops it.
|
|
17
|
+
const pgliteStage = (version) => [
|
|
18
|
+
'FROM node:26-alpine AS pglite',
|
|
19
|
+
'WORKDIR /pglite',
|
|
20
|
+
`RUN npm install --no-audit --no-fund --no-package-lock @electric-sql/pglite@${version}`,
|
|
21
|
+
'',
|
|
22
|
+
];
|
|
23
|
+
const runnerEnv = (store) => [
|
|
24
|
+
'FROM node:26-alpine AS runner',
|
|
25
|
+
'ARG COMMIT_SHA',
|
|
26
|
+
'ARG BUILD_TIME',
|
|
27
|
+
'ENV NODE_ENV=production \\',
|
|
28
|
+
` PORT=${CONTAINER_PORT} \\`,
|
|
29
|
+
' AGENTAGE_HOST_BIND=all \\',
|
|
30
|
+
' AGENTAGE_DRAIN_MS=8000 \\',
|
|
31
|
+
...(store ? [` AGENTAGE_DATA_DIR=${STORE_DIR} \\`] : []),
|
|
32
|
+
' COMMIT_SHA=$COMMIT_SHA \\',
|
|
33
|
+
' BUILD_TIME=$BUILD_TIME',
|
|
34
|
+
];
|
|
35
|
+
const runner = (store) => [
|
|
36
|
+
...runnerEnv(store),
|
|
37
|
+
'WORKDIR /app',
|
|
38
|
+
'COPY --from=deps /app/node_modules ./node_modules',
|
|
39
|
+
...(store
|
|
40
|
+
? [
|
|
41
|
+
'COPY --from=pglite /pglite/node_modules/@electric-sql/pglite ./node_modules/@electric-sql/pglite',
|
|
42
|
+
]
|
|
43
|
+
: []),
|
|
44
|
+
'COPY app/ ./',
|
|
45
|
+
...(store
|
|
46
|
+
? [`RUN mkdir -p ${DATA_VOLUME} && chown node:node ${DATA_VOLUME}`, `VOLUME ${DATA_VOLUME}`]
|
|
47
|
+
: []),
|
|
48
|
+
'USER node',
|
|
49
|
+
`EXPOSE ${CONTAINER_PORT}`,
|
|
50
|
+
`HEALTHCHECK --interval=10s --timeout=3s --start-period=15s --retries=3 CMD ["node", "-e", "${HEALTH_PROBE}"]`,
|
|
51
|
+
'CMD ["node", "node_modules/@agentage/extension/dist/host/main.js"]',
|
|
52
|
+
'',
|
|
53
|
+
];
|
|
54
|
+
// The one image of an extension: the kit host in one process; pglite is set for a postgres store.
|
|
55
|
+
export const containerRecipe = ({ pglite }) => [...DEPS, ...(pglite ? pgliteStage(pglite) : []), ...runner(pglite !== undefined)].join('\n');
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
2
|
+
export declare const pgliteVersion: (dir: string, kitCopy?: (from?: string) => string | undefined) => Promise<string>;
|
|
3
|
+
export declare const stageContainer: (dir: string, pkg: ExtensionPackage, tmpRoot?: string) => Promise<string>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { cp, mkdir, mkdtemp, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { basename, dirname, join } from 'node:path';
|
|
4
|
+
import { OPENAPI_FILE } from '../discovery/openapi.js';
|
|
5
|
+
import {} from '../manifest/manifest.schema.js';
|
|
6
|
+
import { hasStore, imageParts, migratesStore } from '../manifest/parts.js';
|
|
7
|
+
import { containerRecipe } from './container-recipe.js';
|
|
8
|
+
import { kitPgliteVersion } from './kit-version.js';
|
|
9
|
+
import { assertBuilt, copyDeps, exists } from './stage.js';
|
|
10
|
+
const PGLITE_KEY = 'node_modules/@electric-sql/pglite';
|
|
11
|
+
// An exact semver, nothing else: the value goes into a RUN line.
|
|
12
|
+
const EXACT_VERSION = /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/;
|
|
13
|
+
// The PGlite the package tests with (its lock), else the exact copy the kit resolves; never a range.
|
|
14
|
+
export const pgliteVersion = async (dir, kitCopy = kitPgliteVersion) => {
|
|
15
|
+
const lock = JSON.parse(await readFile(join(dir, 'package-lock.json'), 'utf8'));
|
|
16
|
+
const version = lock.packages?.[PGLITE_KEY]?.version ?? kitCopy();
|
|
17
|
+
if (version === undefined)
|
|
18
|
+
throw new Error('no PGlite version: npm install -D @electric-sql/pglite in the package');
|
|
19
|
+
if (typeof version !== 'string' || !EXACT_VERSION.test(version))
|
|
20
|
+
throw new Error(`PGlite version is not an exact semver: ${JSON.stringify(version)}`);
|
|
21
|
+
return version;
|
|
22
|
+
};
|
|
23
|
+
// Compiled tests, source maps and earlier build records (dist/agentage-*.json) never ship.
|
|
24
|
+
const shippedFrom = (dir) => (path) => {
|
|
25
|
+
const name = basename(path);
|
|
26
|
+
const record = dirname(path) === join(dir, 'dist') && /^agentage-.*\.json$/.test(name);
|
|
27
|
+
return !record && !/\.test\.|\.map$/.test(name);
|
|
28
|
+
};
|
|
29
|
+
// The one image carries all of dist/, the OpenAPI file and the migrations; seeds never ship.
|
|
30
|
+
const containerPaths = async (dir, pkg) => {
|
|
31
|
+
const paths = ['package.json', 'dist'];
|
|
32
|
+
if (await exists(join(dir, OPENAPI_FILE)))
|
|
33
|
+
paths.push(OPENAPI_FILE);
|
|
34
|
+
if (migratesStore(pkg) && (await exists(join(dir, 'migrations'))))
|
|
35
|
+
paths.push('migrations');
|
|
36
|
+
return paths;
|
|
37
|
+
};
|
|
38
|
+
// A clean build context for the one image: deps/ (npm ci), app/ (the package) and the Dockerfile.
|
|
39
|
+
export const stageContainer = async (dir, pkg, tmpRoot = tmpdir()) => {
|
|
40
|
+
for (const part of imageParts(pkg))
|
|
41
|
+
await assertBuilt(dir, pkg, part);
|
|
42
|
+
const root = await mkdtemp(join(tmpRoot, `agentage-${pkg.agentage.id}-container-`));
|
|
43
|
+
await copyDeps(dir, root, pkg);
|
|
44
|
+
await mkdir(join(root, 'app'));
|
|
45
|
+
const filter = shippedFrom(dir);
|
|
46
|
+
for (const path of await containerPaths(dir, pkg))
|
|
47
|
+
await cp(join(dir, path), join(root, 'app', path), { recursive: true, filter });
|
|
48
|
+
const pglite = hasStore(pkg, 'postgres') ? await pgliteVersion(dir) : undefined;
|
|
49
|
+
await writeFile(join(root, 'Dockerfile'), containerRecipe({ pglite }));
|
|
50
|
+
return root;
|
|
51
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type BuildInfo } from '../discovery/discovery.js';
|
|
2
|
+
import { type ExtensionPackage } from '../manifest/manifest.schema.js';
|
|
3
|
+
import { type ContainerParts } from './container-parts.js';
|
|
4
|
+
import { type Docker } from './docker.js';
|
|
5
|
+
export declare const CONTAINER_RECORD_FILE = "agentage-container.json";
|
|
6
|
+
export interface BuiltContainer extends ContainerParts {
|
|
7
|
+
tag: string;
|
|
8
|
+
digest?: string;
|
|
9
|
+
image?: string;
|
|
10
|
+
}
|
|
11
|
+
interface ContainerJob {
|
|
12
|
+
dir: string;
|
|
13
|
+
pkg: ExtensionPackage;
|
|
14
|
+
info: BuildInfo;
|
|
15
|
+
registry: string;
|
|
16
|
+
parts: ContainerParts;
|
|
17
|
+
push?: boolean;
|
|
18
|
+
tmpRoot?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare const buildContainer: (job: ContainerJob, docker: Docker) => Promise<{
|
|
21
|
+
container: BuiltContainer;
|
|
22
|
+
record?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
container: {
|
|
25
|
+
digest: string;
|
|
26
|
+
image: string;
|
|
27
|
+
tag: string;
|
|
28
|
+
runs: string[];
|
|
29
|
+
skipped: string[];
|
|
30
|
+
};
|
|
31
|
+
record: {
|
|
32
|
+
id: string;
|
|
33
|
+
version: string;
|
|
34
|
+
commit: string;
|
|
35
|
+
buildTime: string;
|
|
36
|
+
parts: {
|
|
37
|
+
pages?: {
|
|
38
|
+
image: string;
|
|
39
|
+
} | undefined;
|
|
40
|
+
ui?: {
|
|
41
|
+
image: string;
|
|
42
|
+
} | undefined;
|
|
43
|
+
api?: {
|
|
44
|
+
image: string;
|
|
45
|
+
} | undefined;
|
|
46
|
+
mcp?: {
|
|
47
|
+
image: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
worker?: {
|
|
50
|
+
image: string;
|
|
51
|
+
} | undefined;
|
|
52
|
+
store?: {
|
|
53
|
+
kind: "postgres" | "signoz" | "git" | "clickhouse";
|
|
54
|
+
migrations?: number | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
};
|
|
57
|
+
secrets?: string[] | undefined;
|
|
58
|
+
secretParts?: Record<string, ("pages" | "api" | "mcp" | "worker")[]> | undefined;
|
|
59
|
+
image?: string | undefined;
|
|
60
|
+
openapi?: string | undefined;
|
|
61
|
+
tools?: {
|
|
62
|
+
name: string;
|
|
63
|
+
scope: string;
|
|
64
|
+
}[] | undefined;
|
|
65
|
+
widgets?: {
|
|
66
|
+
name: string;
|
|
67
|
+
element: string;
|
|
68
|
+
module: string;
|
|
69
|
+
}[] | undefined;
|
|
70
|
+
commands?: string[] | undefined;
|
|
71
|
+
};
|
|
72
|
+
}>;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { recordOf, validateRecord } from '../discovery/discovery.js';
|
|
2
|
+
import {} from '../discovery/discovery.schema.js';
|
|
3
|
+
import {} from '../manifest/manifest.schema.js';
|
|
4
|
+
import {} from './container-parts.js';
|
|
5
|
+
import { stageContainer } from './container-stage.js';
|
|
6
|
+
import { buildStaged, pushByDigest } from './docker.js';
|
|
7
|
+
import { labelsOf } from './labels.js';
|
|
8
|
+
import { recordExtras } from './record-extras.js';
|
|
9
|
+
// Beside the release record, so a container push never replaces what `extension release` reads.
|
|
10
|
+
export const CONTAINER_RECORD_FILE = 'agentage-container.json';
|
|
11
|
+
// The one-image record: the image by digest in place of one image per part.
|
|
12
|
+
const containerRecord = async (job, image) => validateRecord({
|
|
13
|
+
...recordOf(job.pkg, job.info, {}, await recordExtras(job.dir, job.pkg)),
|
|
14
|
+
image,
|
|
15
|
+
});
|
|
16
|
+
// --container: one image; pushed, also its record.
|
|
17
|
+
export const buildContainer = async (job, docker) => {
|
|
18
|
+
const tag = `${job.registry}/${job.pkg.agentage.id}:${job.pkg.version}`;
|
|
19
|
+
const context = await stageContainer(job.dir, job.pkg, job.tmpRoot);
|
|
20
|
+
const buildArgs = { COMMIT_SHA: job.info.commit, BUILD_TIME: job.info.buildTime };
|
|
21
|
+
const labels = labelsOf(job.pkg, undefined, job.info);
|
|
22
|
+
await buildStaged(docker, { context, tag, buildArgs, labels });
|
|
23
|
+
const container = { tag, ...job.parts };
|
|
24
|
+
if (!job.push)
|
|
25
|
+
return { container };
|
|
26
|
+
const pushed = { ...container, ...(await pushByDigest(docker, tag)) };
|
|
27
|
+
return { container: pushed, record: await containerRecord(job, pushed.image) };
|
|
28
|
+
};
|
package/dist/tool/docker.d.ts
CHANGED
|
@@ -12,3 +12,8 @@ export interface Docker {
|
|
|
12
12
|
export declare const buildArgsOf: (options: DockerBuild) => string[];
|
|
13
13
|
export declare const digestOf: (pushOutput: string) => string;
|
|
14
14
|
export declare const createDocker: (run: Run) => Docker;
|
|
15
|
+
export declare const buildStaged: (docker: Docker, options: DockerBuild) => Promise<void>;
|
|
16
|
+
export declare const pushByDigest: (docker: Docker, tag: string) => Promise<{
|
|
17
|
+
digest: string;
|
|
18
|
+
image: string;
|
|
19
|
+
}>;
|
package/dist/tool/docker.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rm } from 'node:fs/promises';
|
|
1
2
|
import { mustRun } from './exec.js';
|
|
2
3
|
import { TIMEOUTS } from './timeouts.js';
|
|
3
4
|
const PLATFORM = 'linux/amd64';
|
|
@@ -26,3 +27,17 @@ export const createDocker = (run) => ({
|
|
|
26
27
|
},
|
|
27
28
|
push: async (tag) => digestOf(await mustRun(run, 'docker', ['push', tag], { echo: true, timeoutMs: TIMEOUTS.push })),
|
|
28
29
|
});
|
|
30
|
+
// Builds a staged context, then removes it, also after a failed build.
|
|
31
|
+
export const buildStaged = async (docker, options) => {
|
|
32
|
+
try {
|
|
33
|
+
await docker.build(options);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
await rm(options.context, { recursive: true, force: true });
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
// The pushed tag by digest: `{repository}@sha256:...`, as the record names an image.
|
|
40
|
+
export const pushByDigest = async (docker, tag) => {
|
|
41
|
+
const digest = await docker.push(tag);
|
|
42
|
+
return { digest, image: `${tag.slice(0, tag.lastIndexOf(':'))}@${digest}` };
|
|
43
|
+
};
|