@agentage/extension 0.12.3 → 0.14.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/dist/api/openapi-doc.js +2 -1
- package/dist/api/routes.js +1 -1
- package/dist/context/context.d.ts +1 -0
- package/dist/context/context.js +3 -3
- package/dist/context/secrets.d.ts +1 -0
- package/dist/context/secrets.js +7 -5
- package/dist/context/settings.d.ts +4 -0
- package/dist/context/settings.js +6 -5
- package/dist/discovery/discovery.d.ts +1 -0
- package/dist/discovery/discovery.schema.d.ts +2 -0
- package/dist/discovery/discovery.schema.js +30 -12
- package/dist/discovery/openapi.d.ts +2 -1
- package/dist/discovery/openapi.js +3 -1
- package/dist/host/daemon/add.d.ts +9 -0
- package/dist/host/daemon/add.js +63 -0
- package/dist/host/daemon/child.d.ts +23 -0
- package/dist/host/daemon/child.js +100 -0
- package/dist/host/daemon/daemon-files.d.ts +17 -0
- package/dist/host/daemon/daemon-files.js +27 -0
- 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 +17 -0
- package/dist/host/daemon/daemon.js +106 -0
- package/dist/host/daemon/entries.d.ts +21 -0
- package/dist/host/daemon/entries.js +24 -0
- package/dist/host/daemon/guard.d.ts +2 -0
- package/dist/host/daemon/guard.js +16 -0
- package/dist/host/daemon/installation.d.ts +36 -0
- package/dist/host/daemon/installation.js +92 -0
- package/dist/host/daemon/installer-call.d.ts +21 -0
- package/dist/host/daemon/installer-call.js +48 -0
- package/dist/host/daemon/json-file.d.ts +4 -0
- package/dist/host/daemon/json-file.js +62 -0
- package/dist/host/daemon/lane.d.ts +9 -0
- package/dist/host/daemon/lane.js +24 -0
- package/dist/host/daemon/limits.d.ts +11 -0
- package/dist/host/daemon/limits.js +22 -0
- package/dist/host/daemon/ops.d.ts +12 -0
- package/dist/host/daemon/ops.js +89 -0
- 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 +6 -0
- package/dist/host/daemon/proxy.js +89 -0
- package/dist/host/daemon/queue.d.ts +3 -0
- package/dist/host/daemon/queue.js +27 -0
- package/dist/host/daemon/routes.d.ts +13 -0
- package/dist/host/daemon/routes.js +98 -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 +54 -0
- package/dist/host/daemon/supervisor.js +115 -0
- 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 -0
- package/dist/host/data-lock.js +121 -0
- package/dist/host/host-env.d.ts +18 -0
- package/dist/host/host-env.js +42 -0
- package/dist/host/host-extension.d.ts +29 -0
- package/dist/host/host-extension.js +91 -0
- package/dist/host/host-store.d.ts +11 -0
- package/dist/host/host-store.js +49 -0
- package/dist/host/index.d.ts +7 -0
- package/dist/host/index.js +7 -0
- package/dist/host/main.d.ts +2 -0
- package/dist/host/main.js +10 -0
- package/dist/host/serve-host.d.ts +17 -0
- package/dist/host/serve-host.js +64 -0
- package/dist/runtime/part-runners.d.ts +1 -0
- package/dist/runtime/part-runners.js +10 -1
- package/dist/runtime/run-part.js +2 -0
- package/dist/server/app.d.ts +6 -1
- package/dist/server/app.js +29 -19
- package/dist/server/request-line.d.ts +1 -1
- package/dist/server/request-line.js +4 -4
- package/dist/server/serve.d.ts +3 -0
- package/dist/server/serve.js +17 -4
- package/dist/store/pglite-store.d.ts +25 -0
- package/dist/store/pglite-store.js +59 -0
- package/dist/store/test-store.d.ts +2 -3
- package/dist/store/test-store.js +3 -38
- package/dist/testing/test-server.d.ts +2 -0
- package/dist/testing/test-server.js +1 -1
- 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/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 +12 -5
- package/dist/tool/index.d.ts +2 -0
- package/dist/tool/index.js +2 -0
- package/dist/tool/kit-version.d.ts +1 -0
- package/dist/tool/kit-version.js +16 -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/record-extras.js +2 -2
- package/dist/tool/rules/surface.js +6 -6
- package/dist/tool/stage.d.ts +1 -0
- package/dist/tool/stage.js +1 -1
- package/dist/tool/up/gateway.d.ts +6 -2
- package/dist/tool/up/gateway.js +10 -7
- package/dist/tool/up/local-record.d.ts +1 -0
- package/dist/tool/up/token.js +1 -1
- package/dist/tool/up/up.js +2 -2
- package/dist/vendor/logs/events-client.js +1 -1
- package/package.json +5 -1
- package/schemas/extension-discovery.schema.json +8 -1
- package/schemas/extension-record.schema.json +8 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {} from 'express';
|
|
2
2
|
import { requestScope, sigtermOnce } from '../agcid/current.js';
|
|
3
3
|
import {} from '../log/log.js';
|
|
4
|
-
const
|
|
4
|
+
const MOUNT = /^\/(?:api\/[^/]+|mcp|\.well-known|ui)(?=\/|$)/;
|
|
5
5
|
const ASSET = /\.(m?js|css|map|png|jpe?g|gif|svg|ico|webp|avif|woff2?|ttf)$/i;
|
|
6
6
|
// The matched route template, never the raw URL, so no id or query string reaches the log.
|
|
7
7
|
export const routeOf = (req, res) => {
|
|
@@ -9,7 +9,7 @@ export const routeOf = (req, res) => {
|
|
|
9
9
|
if (typeof known === 'string')
|
|
10
10
|
return known;
|
|
11
11
|
const url = req.originalUrl?.split('?')[0] ?? '';
|
|
12
|
-
const prefix =
|
|
12
|
+
const prefix = MOUNT.exec(url)?.[0] ?? '';
|
|
13
13
|
const path = req.route?.path;
|
|
14
14
|
if (typeof path !== 'string')
|
|
15
15
|
return '(unmatched)';
|
|
@@ -22,7 +22,7 @@ const localOf = (res, key) => {
|
|
|
22
22
|
return typeof value === 'string' ? value : undefined;
|
|
23
23
|
};
|
|
24
24
|
// One http row per request on finish; a ctx.exit() asked for in it shuts the part down after.
|
|
25
|
-
export const requestLine = (log) => (req, res, next) => {
|
|
25
|
+
export const requestLine = (log, onExit = sigtermOnce) => (req, res, next) => {
|
|
26
26
|
const start = performance.now();
|
|
27
27
|
const scope = requestScope.getStore();
|
|
28
28
|
res.on('finish', () => {
|
|
@@ -38,7 +38,7 @@ export const requestLine = (log) => (req, res, next) => {
|
|
|
38
38
|
clientInfo: localOf(res, 'clientInfo'),
|
|
39
39
|
});
|
|
40
40
|
if (scope?.exit)
|
|
41
|
-
|
|
41
|
+
onExit();
|
|
42
42
|
});
|
|
43
43
|
next();
|
|
44
44
|
};
|
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,11 +2,26 @@ 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
|
+
});
|
|
15
|
+
// Open requests are answered; a keep-alive connection is closed once idle, not at its timeout.
|
|
16
|
+
const drain = (server, exit, graceMs) => {
|
|
17
|
+
const idle = setInterval(() => server.closeIdleConnections(), 100).unref();
|
|
18
|
+
server.close((err) => {
|
|
19
|
+
clearInterval(idle);
|
|
20
|
+
exit(err ? 1 : 0);
|
|
21
|
+
});
|
|
22
|
+
server.closeIdleConnections();
|
|
23
|
+
setTimeout(() => exit(1), graceMs).unref();
|
|
24
|
+
};
|
|
10
25
|
// SIGTERM drains; a close error or a drain past the grace period exits 1; a second Ctrl-C at once.
|
|
11
26
|
export const shutdownOn = (server, options) => {
|
|
12
27
|
const exitWith = options.exit ?? ((code) => process.exit(code));
|
|
@@ -24,9 +39,7 @@ export const shutdownOn = (server, options) => {
|
|
|
24
39
|
return;
|
|
25
40
|
stopping = true;
|
|
26
41
|
options.log.info('shutting down');
|
|
27
|
-
server
|
|
28
|
-
server.closeIdleConnections();
|
|
29
|
-
setTimeout(() => exit(1), GRACE_MS).unref();
|
|
42
|
+
drain(server, exit, options.graceMs ?? GRACE_MS);
|
|
30
43
|
};
|
|
31
44
|
for (const signal of options.signals ?? ['SIGTERM', 'SIGINT'])
|
|
32
45
|
process.on(signal, () => stop(signal));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Row, type Store } from './store.types.js';
|
|
2
|
+
interface PGliteLike {
|
|
3
|
+
query<R>(text: string, params?: unknown[]): Promise<{
|
|
4
|
+
rows: R[];
|
|
5
|
+
}>;
|
|
6
|
+
exec(text: string): Promise<{
|
|
7
|
+
rows: Row[];
|
|
8
|
+
}[]>;
|
|
9
|
+
close(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface PgliteStore extends Store {
|
|
12
|
+
close(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export interface StoreAt {
|
|
15
|
+
dataDir?: string;
|
|
16
|
+
from?: string;
|
|
17
|
+
}
|
|
18
|
+
type PGliteModule = {
|
|
19
|
+
PGlite: new (dataDir?: string) => PGliteLike;
|
|
20
|
+
};
|
|
21
|
+
export declare const PGLITE = "@electric-sql/pglite";
|
|
22
|
+
export declare const pgliteMissing: (tried: string[]) => string;
|
|
23
|
+
export declare const loadPglite: (from?: string, kitCopy?: () => Promise<unknown>) => Promise<PGliteModule>;
|
|
24
|
+
export declare const createPgliteStore: (prepare: (store: Store) => Promise<unknown>, at?: StoreAt) => PgliteStore;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import {} from './store.types.js';
|
|
5
|
+
export const PGLITE = '@electric-sql/pglite';
|
|
6
|
+
export const pgliteMissing = (tried) => `${PGLITE} is not installed (looked in ${tried.join(', then ')}): the host brings it, npm install ${PGLITE}`;
|
|
7
|
+
const notFound = (err) => ['ERR_MODULE_NOT_FOUND', 'MODULE_NOT_FOUND'].includes(String(err.code));
|
|
8
|
+
const fromPackage = async (from) => {
|
|
9
|
+
const file = createRequire(join(from, 'package.json')).resolve(PGLITE);
|
|
10
|
+
return (await import(pathToFileURL(file).href));
|
|
11
|
+
};
|
|
12
|
+
// The host's own copy first (the kit's resolution), then the hosted package's; only a missing one is reworded.
|
|
13
|
+
export const loadPglite = async (from, kitCopy = () => import(PGLITE)) => {
|
|
14
|
+
try {
|
|
15
|
+
return (await kitCopy());
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
if (!notFound(err))
|
|
19
|
+
throw err;
|
|
20
|
+
if (!from)
|
|
21
|
+
throw new Error(pgliteMissing(['the kit']), { cause: err });
|
|
22
|
+
return fromPackage(from).catch((again) => {
|
|
23
|
+
if (!notFound(again))
|
|
24
|
+
throw again;
|
|
25
|
+
throw new Error(pgliteMissing(['the kit', from]), { cause: again });
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// Like pg: a parameterless query may hold several statements (migrations), the last one answers.
|
|
30
|
+
const bound = (db) => ({
|
|
31
|
+
query: async (text, params) => {
|
|
32
|
+
if (params && params.length > 0)
|
|
33
|
+
return db.query(text, params);
|
|
34
|
+
const results = await db.exec(text);
|
|
35
|
+
return { rows: (results.at(-1)?.rows ?? []) };
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
const opened = async (prepare, at) => {
|
|
39
|
+
const { PGlite } = await loadPglite(at.from);
|
|
40
|
+
const db = new PGlite(at.dataDir);
|
|
41
|
+
const store = bound(db);
|
|
42
|
+
await prepare(store).catch(async (err) => {
|
|
43
|
+
await db.close();
|
|
44
|
+
throw err;
|
|
45
|
+
});
|
|
46
|
+
return { ...store, db };
|
|
47
|
+
};
|
|
48
|
+
// In-process Postgres (WASM), prepared once on first use; a failed prepare leaves no open database.
|
|
49
|
+
export const createPgliteStore = (prepare, at = {}) => {
|
|
50
|
+
let ready;
|
|
51
|
+
const start = () => opened(prepare, at);
|
|
52
|
+
return {
|
|
53
|
+
query: async (text, params) => (await (ready ??= start())).query(text, params),
|
|
54
|
+
close: async () => {
|
|
55
|
+
if (ready)
|
|
56
|
+
await (await ready).db.close();
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
+
import { type PgliteStore } from './pglite-store.js';
|
|
1
2
|
import { type Store } from './store.types.js';
|
|
2
|
-
export
|
|
3
|
-
close(): Promise<void>;
|
|
4
|
-
}
|
|
3
|
+
export type TestStore = PgliteStore;
|
|
5
4
|
export declare const createTestStore: (prepare: (store: Store) => Promise<unknown>) => TestStore;
|
package/dist/store/test-store.js
CHANGED
|
@@ -1,39 +1,4 @@
|
|
|
1
|
+
import { createPgliteStore } from './pglite-store.js';
|
|
1
2
|
import {} from './store.types.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { PGlite } = (await import('@electric-sql/pglite'));
|
|
5
|
-
return new PGlite();
|
|
6
|
-
}
|
|
7
|
-
catch {
|
|
8
|
-
throw new Error('a test store needs @electric-sql/pglite: npm install -D @electric-sql/pglite');
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
// Like pg: a parameterless query may hold several statements (migrations), the last one answers.
|
|
12
|
-
const bound = (db) => ({
|
|
13
|
-
query: async (text, params) => {
|
|
14
|
-
if (params && params.length > 0)
|
|
15
|
-
return db.query(text, params);
|
|
16
|
-
const results = await db.exec(text);
|
|
17
|
-
return { rows: (results.at(-1)?.rows ?? []) };
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
// In-process Postgres (WASM): a throwaway store of the same kind, prepared once on first use.
|
|
21
|
-
export const createTestStore = (prepare) => {
|
|
22
|
-
let ready;
|
|
23
|
-
const start = async () => {
|
|
24
|
-
const db = await open();
|
|
25
|
-
const store = bound(db);
|
|
26
|
-
await prepare(store);
|
|
27
|
-
return { ...store, db };
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
query: async (text, params) => {
|
|
31
|
-
ready ??= start();
|
|
32
|
-
return (await ready).query(text, params);
|
|
33
|
-
},
|
|
34
|
-
close: async () => {
|
|
35
|
-
if (ready)
|
|
36
|
-
await (await ready).db.close();
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
};
|
|
3
|
+
// A throwaway in-memory store of the same kind, prepared once on first use.
|
|
4
|
+
export const createTestStore = (prepare) => createPgliteStore(prepare);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Express } from 'express';
|
|
1
2
|
import { type ApiContext } from '../api/routes.js';
|
|
2
3
|
import { type Caller } from '../auth/token-check.js';
|
|
3
4
|
import { type PartContext } from '../context/context.js';
|
|
@@ -20,5 +21,6 @@ export interface TestServer {
|
|
|
20
21
|
export interface TestMcp extends TestServer {
|
|
21
22
|
call(name: string, args?: Record<string, unknown>): Promise<unknown>;
|
|
22
23
|
}
|
|
24
|
+
export declare const startOn: (app: Express) => Promise<TestServer>;
|
|
23
25
|
export declare const startTestServer: <C extends PartContext = PartContext>(options: TestServerOptions<C>) => Promise<TestServer>;
|
|
24
26
|
export declare const startTestMcp: (options: TestMcpOptions) => Promise<TestMcp>;
|
|
@@ -22,7 +22,7 @@ const testPackage = (ctx, parts) => ({
|
|
|
22
22
|
engines: { agentage: KIT_VERSION },
|
|
23
23
|
agentage: { id: ctx.extension.id, parts },
|
|
24
24
|
});
|
|
25
|
-
const startOn = async (app) => {
|
|
25
|
+
export const startOn = async (app) => {
|
|
26
26
|
const server = await listen(app, 0, '127.0.0.1');
|
|
27
27
|
const url = `http://127.0.0.1:${server.address().port}`;
|
|
28
28
|
return {
|
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"];
|
|
@@ -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 part: the one image runs only the api part today";
|
|
7
|
+
export declare const containerParts: (pkg: ExtensionPackage) => ContainerParts;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 only the api part today';
|
|
4
|
+
// The kit host (host/host-extension.ts) serves the api part; other image parts come later.
|
|
5
|
+
export const containerParts = (pkg) => {
|
|
6
|
+
const parts = imageParts(pkg);
|
|
7
|
+
if (!parts.includes('api'))
|
|
8
|
+
throw new Error(NO_API);
|
|
9
|
+
return { runs: ['api'], skipped: parts.filter((kind) => kind !== 'api') };
|
|
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
|
+
}>;
|