@agentage/extension 0.15.0 → 0.15.1

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.
@@ -1,5 +1,5 @@
1
1
  export { AGCID_HEADER, isAgcid } from '../agcid/header.js';
2
- export { DiscoveryDocumentSchema, ExtensionRecordSchema, type DiscoveryDocument, type ExtensionRecord, } from '../discovery/discovery.schema.js';
2
+ export { CloudDiscoveryDocumentSchema, DiscoveryDocumentSchema, ExtensionRecordSchema, type DiscoveryDocument, type ExtensionRecord, } from '../discovery/discovery.schema.js';
3
3
  export { ERROR_CODES, type ErrorCode } from '../envelope/codes.js';
4
4
  export { ErrorEnvelopeSchema, OkEnvelopeSchema } from '../envelope/envelope.schema.js';
5
5
  export { type ErrorEnvelope, type OkEnvelope } from '../envelope/envelope.js';
@@ -1,5 +1,5 @@
1
1
  export { AGCID_HEADER, isAgcid } from '../agcid/header.js';
2
- export { DiscoveryDocumentSchema, ExtensionRecordSchema, } from '../discovery/discovery.schema.js';
2
+ export { CloudDiscoveryDocumentSchema, DiscoveryDocumentSchema, ExtensionRecordSchema, } from '../discovery/discovery.schema.js';
3
3
  export { ERROR_CODES } from '../envelope/codes.js';
4
4
  export { ErrorEnvelopeSchema, OkEnvelopeSchema } from '../envelope/envelope.schema.js';
5
5
  export {} from '../envelope/envelope.js';
@@ -1,6 +1,7 @@
1
1
  import { type ExtensionPackage } from '../manifest/manifest.schema.js';
2
+ import { type HostPartKind } from '../manifest/parts.js';
2
3
  import { type ImagePartKind } from '../manifest/primitives.schema.js';
3
- import { type ExtensionRecord } from './discovery.schema.js';
4
+ import { type DiscoveryDocument, type ExtensionRecord } from './discovery.schema.js';
4
5
  export interface BuildInfo {
5
6
  commit: string;
6
7
  buildTime: string;
@@ -21,34 +22,18 @@ export interface RecordExtras {
21
22
  migrations?: number;
22
23
  }
23
24
  export declare const recordOf: (pkg: ExtensionPackage, build: BuildInfo, images: PartImages, extras?: RecordExtras) => ExtensionRecord;
25
+ export type ServedRecord = Omit<ExtensionRecord, 'parts'> & {
26
+ parts: DiscoveryDocument['parts'];
27
+ };
28
+ export declare const hostedRecordOf: (pkg: ExtensionPackage, build: BuildInfo, hosted: readonly HostPartKind[], extras: RecordExtras) => ServedRecord;
24
29
  export declare const validateRecord: (value: unknown) => ExtensionRecord;
25
30
  export declare const loadRecord: (file: string) => Promise<ExtensionRecord | null>;
26
- export declare const discoveryDocument: (record: ExtensionRecord, host: string) => {
27
- parts: {
28
- pages?: {
29
- image: string;
30
- } | undefined;
31
- ui?: {
32
- image: string;
33
- } | undefined;
34
- api?: {
35
- image: string;
36
- } | undefined;
37
- mcp?: {
38
- image: string;
39
- } | undefined;
40
- worker?: {
41
- image: string;
42
- } | undefined;
43
- store?: {
44
- kind: "postgres" | "signoz" | "git" | "clickhouse";
45
- migrations?: number | undefined;
46
- } | undefined;
47
- };
31
+ export declare const discoveryDocument: (record: ServedRecord, host: string) => {
32
+ commands?: string[] | undefined;
48
33
  secrets?: string[] | undefined;
49
- secretParts?: Record<string, ("pages" | "api" | "mcp" | "worker")[]> | undefined;
50
34
  image?: string | undefined;
51
35
  openapi?: string | undefined;
36
+ secretParts?: Record<string, ("pages" | "api" | "mcp" | "worker")[]> | undefined;
52
37
  tools?: {
53
38
  name: string;
54
39
  scope: string;
@@ -58,7 +43,7 @@ export declare const discoveryDocument: (record: ExtensionRecord, host: string)
58
43
  element: string;
59
44
  module: string;
60
45
  }[] | undefined;
61
- commands?: string[] | undefined;
46
+ parts: DiscoveryDocument["parts"];
62
47
  id: string;
63
48
  version: string;
64
49
  commit: string;
@@ -2,7 +2,7 @@ import { formatIssues, readJsonIfExists } from '../manifest/read-manifest.js';
2
2
  import {} from '../manifest/manifest.schema.js';
3
3
  import { normalizeParts, scopedSecrets } from '../manifest/parts.js';
4
4
  import {} from '../manifest/primitives.schema.js';
5
- import { ExtensionRecordSchema } from './discovery.schema.js';
5
+ import { ExtensionRecordSchema, } from './discovery.schema.js';
6
6
  export const DEFAULT_RECORD_FILE = '/run/agentage/agentage-extension.json';
7
7
  const partsOf = (pkg, images, migrations) => {
8
8
  const parts = {};
@@ -34,6 +34,12 @@ export const recordOf = (pkg, build, images, extras = {}) => {
34
34
  record.secretParts = scopedSecrets(pkg);
35
35
  return record;
36
36
  };
37
+ // The kit host never knows its digest: the parts it runs have no image; pages and ui are not listed.
38
+ export const hostedRecordOf = (pkg, build, hosted, extras) => {
39
+ const record = recordOf(pkg, build, {}, extras);
40
+ const bare = Object.fromEntries(hosted.map((kind) => [kind, {}]));
41
+ return { ...record, parts: { ...bare, ...record.parts } };
42
+ };
37
43
  export const validateRecord = (value) => {
38
44
  const result = ExtensionRecordSchema.safeParse(value);
39
45
  if (result.success)
@@ -57,6 +57,51 @@ export declare const ExtensionRecordSchema: z.ZodObject<{
57
57
  commands: z.ZodOptional<z.ZodArray<z.ZodString>>;
58
58
  }, z.core.$strict>;
59
59
  export declare const DiscoveryDocumentSchema: z.ZodObject<{
60
+ parts: z.ZodObject<{
61
+ pages: z.ZodOptional<z.ZodObject<{
62
+ image: z.ZodString;
63
+ }, z.core.$strict>>;
64
+ ui: z.ZodOptional<z.ZodObject<{
65
+ image: z.ZodString;
66
+ }, z.core.$strict>>;
67
+ api: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
68
+ image: z.ZodString;
69
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>]>>;
70
+ mcp: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
71
+ image: z.ZodString;
72
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>]>>;
73
+ worker: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{
74
+ image: z.ZodString;
75
+ }, z.core.$strict>, z.ZodObject<{}, z.core.$strict>]>>;
76
+ store: z.ZodOptional<z.ZodObject<{
77
+ kind: z.ZodEnum<{
78
+ postgres: "postgres";
79
+ signoz: "signoz";
80
+ git: "git";
81
+ clickhouse: "clickhouse";
82
+ }>;
83
+ migrations: z.ZodOptional<z.ZodInt>;
84
+ }, z.core.$strict>>;
85
+ }, z.core.$strict>;
86
+ host: z.ZodString;
87
+ id: z.ZodString;
88
+ version: z.ZodString;
89
+ commit: z.ZodString;
90
+ buildTime: z.ZodISODateTime;
91
+ image: z.ZodOptional<z.ZodString>;
92
+ openapi: z.ZodOptional<z.ZodString>;
93
+ tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
94
+ name: z.ZodString;
95
+ scope: z.ZodString;
96
+ }, z.core.$strict>>>;
97
+ widgets: z.ZodOptional<z.ZodArray<z.ZodObject<{
98
+ name: z.ZodString;
99
+ element: z.ZodString;
100
+ module: z.ZodString;
101
+ }, z.core.$strict>>>;
102
+ commands: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
+ }, z.core.$strict>;
104
+ export declare const CloudDiscoveryDocumentSchema: z.ZodObject<{
60
105
  host: z.ZodString;
61
106
  id: z.ZodString;
62
107
  version: z.ZodString;
@@ -11,15 +11,27 @@ const OneImageRefSchema = z
11
11
  .string()
12
12
  .max(256)
13
13
  .regex(/^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?(\/[a-z0-9][a-z0-9_.-]*)+\/[a-z][a-z0-9-]*@sha256:[0-9a-f]{64}$/);
14
+ const StoreRecordSchema = z.strictObject({
15
+ kind: StoreKindSchema,
16
+ migrations: z.int().min(0).optional(),
17
+ });
14
18
  const PartsRecordSchema = z.strictObject({
15
19
  pages: PartImageSchema.optional(),
16
20
  ui: PartImageSchema.optional(),
17
21
  api: PartImageSchema.optional(),
18
22
  mcp: PartImageSchema.optional(),
19
23
  worker: PartImageSchema.optional(),
20
- store: z
21
- .strictObject({ kind: StoreKindSchema, migrations: z.int().min(0).optional() })
22
- .optional(),
24
+ store: StoreRecordSchema.optional(),
25
+ });
26
+ // A part the kit host runs has no image: the host never knows its own digest.
27
+ const HostedPartSchema = z.strictObject({});
28
+ const ServedPartsSchema = z.strictObject({
29
+ pages: PartImageSchema.optional(),
30
+ ui: PartImageSchema.optional(),
31
+ api: z.union([PartImageSchema, HostedPartSchema]).optional(),
32
+ mcp: z.union([PartImageSchema, HostedPartSchema]).optional(),
33
+ worker: z.union([PartImageSchema, HostedPartSchema]).optional(),
34
+ store: StoreRecordSchema.optional(),
23
35
  });
24
36
  export const OriginSchema = z
25
37
  .string()
@@ -40,7 +52,7 @@ const recordShape = {
40
52
  commit: CommitSchema,
41
53
  buildTime: z.iso.datetime(),
42
54
  parts: PartsRecordSchema,
43
- image: OneImageRefSchema.optional().describe('The one image (build --container). A record has part images or this image: never both, never none.'),
55
+ image: OneImageRefSchema.optional().describe('The one image (build --container). A build record has part images or this image: never both, never none.'),
44
56
  // /api/v{N}: an extension still on a kit before 0.13, read by a newer one; it goes in phase 4.
45
57
  openapi: z
46
58
  .string()
@@ -63,6 +75,17 @@ const FORM_RULE = {
63
75
  message: 'at least one part with an image, or the one image and no part image',
64
76
  path: ['parts'],
65
77
  };
78
+ // Discovery also takes the kit host's form: one or more parts, none with an image, no one image.
79
+ const servedForm = (doc) => {
80
+ const bare = IMAGE_PART_KINDS.filter((kind) => doc.parts[kind] && !doc.parts[kind].image);
81
+ if (!bare.length)
82
+ return oneImageForm(doc);
83
+ return !doc.image && IMAGE_PART_KINDS.every((kind) => doc.parts[kind]?.image === undefined);
84
+ };
85
+ const HOSTED_RULE = {
86
+ message: 'at least one part with an image, the one image, or only parts with no image',
87
+ path: ['parts'],
88
+ };
66
89
  // The api prefix is /api/{id}, or the old /api/v{N}: never another extension's id.
67
90
  const openapiNamesItsExtension = ({ id, openapi }) => !openapi || /^\/api\/v[0-9]+\//.test(openapi) || openapi === `/api/${id}/openapi.json`;
68
91
  const OPENAPI_RULE = { message: 'openapi is /api/{id}/openapi.json', path: ['openapi'] };
@@ -86,6 +109,12 @@ export const ExtensionRecordSchema = z
86
109
  });
87
110
  // What a deployment serves at /.well-known/agentage-extension.json: the record plus its host.
88
111
  export const DiscoveryDocumentSchema = z
112
+ .strictObject({ ...recordShape, parts: ServedPartsSchema, host: OriginSchema })
113
+ .refine(servedForm, HOSTED_RULE)
114
+ .refine(imagesNameTheirExtension, IMAGE_RULE)
115
+ .refine(openapiNamesItsExtension, OPENAPI_RULE);
116
+ // The form the cloud serves: every part by its image, or the one image; never a part with no image.
117
+ export const CloudDiscoveryDocumentSchema = z
89
118
  .strictObject({ ...recordShape, host: OriginSchema })
90
119
  .refine(oneImageForm, FORM_RULE)
91
120
  .refine(imagesNameTheirExtension, IMAGE_RULE)
@@ -0,0 +1,8 @@
1
+ import { type ExtensionPackage } from '../manifest/manifest.schema.js';
2
+ import { type ToolEntry } from '../mcp/tools.js';
3
+ import { type RecordExtras } from './discovery.js';
4
+ export declare const toolRecords: (id: string, tools: Pick<ToolEntry, "name" | "spec">[]) => {
5
+ name: string;
6
+ scope: string;
7
+ }[];
8
+ export declare const migrationsOf: (dir: string, pkg: ExtensionPackage) => Promise<RecordExtras>;
@@ -0,0 +1,10 @@
1
+ import { join } from 'node:path';
2
+ import { scopeOf } from '../auth/token-check.js';
3
+ import {} from '../manifest/manifest.schema.js';
4
+ import { migratesStore } from '../manifest/parts.js';
5
+ import { prefixed } from '../mcp/tools.js';
6
+ import { sqlFiles } from '../store/migrations.js';
7
+ import {} from './discovery.js';
8
+ // Each tool as tools/list names it, with the scope tools/call needs.
9
+ export const toolRecords = (id, tools) => tools.map((tool) => ({ name: prefixed(id, tool.name), scope: scopeOf(id, tool.spec.scope) }));
10
+ export const migrationsOf = async (dir, pkg) => migratesStore(pkg) ? { migrations: (await sqlFiles(join(dir, 'migrations'))).length } : {};
@@ -1,6 +1,7 @@
1
1
  import { existsSync } from 'node:fs';
2
2
  import { rm } from 'node:fs/promises';
3
3
  import { isAbsolute } from 'node:path';
4
+ import { validRange } from 'semver';
4
5
  import { z } from 'zod';
5
6
  import { fail } from '../../envelope/envelope.js';
6
7
  import { parse } from '../../envelope/parse.js';
@@ -13,11 +14,14 @@ import { clearRunDir, dataDirOf } from './daemon-files.js';
13
14
  import { needsSecret } from './start-checks.js';
14
15
  import { startEntry, startFailed } from './supervisor.js';
15
16
  const RESERVED_ID = 'host';
17
+ // The cli's rule for what follows `<id>@`: a version, a range or a dist-tag; never a path, URL or flag.
18
+ const DIST_TAG = /^[A-Za-z][\w.-]*$/;
19
+ const isVersionSpec = (spec) => !/\s/.test(spec) && (validRange(spec) !== null || DIST_TAG.test(spec));
16
20
  // enabled: false records the extension and never starts it (a profile "off" entry).
17
21
  const AddSchema = z.union([
18
22
  z.strictObject({
19
23
  id: ExtensionIdSchema,
20
- version: z.string().min(1).optional(),
24
+ version: z.string().min(1).refine(isVersionSpec, 'a version, a range or a dist-tag').optional(),
21
25
  enabled: z.boolean().optional(),
22
26
  }),
23
27
  z.strictObject({
@@ -6,6 +6,7 @@ import { CLOCK_RATE_ENV, parseClockRate } from '../../worker/clock.js';
6
6
  import { fillRun, makeRun, undoRun } from './child-files.js';
7
7
  import { lastWords } from './last-words.js';
8
8
  import { LIMITS } from './limits.js';
9
+ import { pipeRedacted } from './redact-stream.js';
9
10
  import { permissionFlag, sealFlags, sealOf } from './seal.js';
10
11
  const HOST_MAIN = fileURLToPath(new URL('../main.js', import.meta.url));
11
12
  const STOP_MS = 5_000;
@@ -23,13 +24,11 @@ export const childEnv = (spec, secretsDir, runDir) => ({
23
24
  });
24
25
  export { lastWords } from './last-words.js';
25
26
  const passedEnv = () => Object.fromEntries(PASSED.flatMap((k) => (process.env[k] ? [[k, process.env[k]]] : [])));
26
- const captured = (child) => {
27
+ const captured = (child, secrets) => {
27
28
  let tail = '';
28
- child.stdout?.pipe(process.stdout);
29
- child.stderr?.on('data', (chunk) => {
30
- process.stderr.write(chunk);
31
- tail = (tail + chunk.toString()).slice(-4000);
32
- });
29
+ pipeRedacted(child.stdout, process.stdout, secrets);
30
+ pipeRedacted(child.stderr, process.stderr, secrets);
31
+ child.stderr?.on('data', (chunk) => (tail = (tail + chunk.toString()).slice(-4000)));
33
32
  return () => tail;
34
33
  };
35
34
  // 'exit' can come before the last stderr chunk: wait for the stream end, at most 500 ms.
@@ -99,7 +98,7 @@ const started = async (at, spec, run) => {
99
98
  execArgv,
100
99
  stdio: [...stdio],
101
100
  });
102
- const tail = captured(child);
101
+ const tail = captured(child, spec.secrets);
103
102
  const exited = exitOf(child, tail);
104
103
  const port = await readyOf(child, tail, at.startMs);
105
104
  return { port, pid: child.pid ?? 0, exited, stop: stopOf(child, exited) };
@@ -0,0 +1,4 @@
1
+ import { type Readable, type Writable } from 'node:stream';
2
+ export declare const PENDING_MAX: number;
3
+ export declare const redactedLines: (write: (text: string) => void, secrets: Record<string, string>) => (chunk?: string) => void;
4
+ export declare const pipeRedacted: (from: Readable | null, to: Writable, secrets: Record<string, string>) => void;
@@ -0,0 +1,24 @@
1
+ import {} from 'node:stream';
2
+ import { maskedForms, redact } from './start-checks.js';
3
+ // Past this, a line with no newline is written up to a tail that could hold a split secret.
4
+ export const PENDING_MAX = 64 * 1024;
5
+ // By line, so a value split over two chunks is masked too; a call with no chunk flushes the rest.
6
+ export const redactedLines = (write, secrets) => {
7
+ const keep = Math.max(0, (maskedForms(secrets)[0]?.length ?? 1) - 1);
8
+ let rest = '';
9
+ return (chunk) => {
10
+ const lines = (rest + (chunk ?? '\n')).split('\n');
11
+ rest = lines.pop() ?? '';
12
+ const cut = rest.length > PENDING_MAX ? rest.length - keep : 0;
13
+ const out = `${lines.join('\n')}${lines.length && chunk !== undefined ? '\n' : ''}`;
14
+ if (out || cut)
15
+ write(redact(out + rest.slice(0, cut), secrets));
16
+ rest = rest.slice(cut);
17
+ };
18
+ };
19
+ // A child stream to the daemon's own, masked; its rest is written at the end.
20
+ export const pipeRedacted = (from, to, secrets) => {
21
+ const out = redactedLines((text) => to.write(text), secrets);
22
+ from?.on('data', (chunk) => out(chunk.toString()));
23
+ from?.once('end', () => out());
24
+ };
@@ -32,7 +32,7 @@ export const assertReach = (reads, writes, configDir, id) => {
32
32
  if (star)
33
33
  throw refused(star, 'has a * that Node reads as a wildcard');
34
34
  const configs = [configDir, real(configDir)];
35
- const open = reads.find((grant) => configs.some((config) => exposes(grant, config, id)));
35
+ const open = reads.find((grant) => [grant, real(grant)].some((path) => configs.some((config) => exposes(path, config, id))));
36
36
  if (open)
37
37
  throw refused(open, 'would expose the agentage config folder');
38
38
  };
@@ -3,4 +3,5 @@ export declare const NEEDS_SECRET = "NEEDS_SECRET";
3
3
  export declare const assertSecrets: (pkg: ExtensionPackage, secrets: Record<string, string>) => void;
4
4
  export declare const needsSecret: (err: unknown) => boolean;
5
5
  export declare const healthy: (port: number, ms: number) => Promise<void>;
6
+ export declare const maskedForms: (secrets: Record<string, string>) => string[];
6
7
  export declare const redact: (text: string, secrets: Record<string, string>) => string;
@@ -21,8 +21,9 @@ export const healthy = async (port, ms) => {
21
21
  if (res.status !== 200)
22
22
  throw new Error(`health answered ${res.status}`);
23
23
  };
24
- // A secret value this child was given never reaches error, /health, the list or the log.
25
- export const redact = (text, secrets) => Object.values(secrets)
24
+ // Each value raw and as it shows inside a JSON log row (quotes, backslashes escaped).
25
+ export const maskedForms = (secrets) => [...new Set(Object.values(secrets).flatMap((v) => [v, JSON.stringify(v).slice(1, -1)]))]
26
26
  .filter((value) => value.length >= 4)
27
- .sort((a, b) => b.length - a.length)
28
- .reduce((out, value) => out.split(value).join('***'), text);
27
+ .sort((a, b) => b.length - a.length);
28
+ // A secret value this child was given never reaches error, /health, the list or the log.
29
+ export const redact = (text, secrets) => maskedForms(secrets).reduce((out, value) => out.split(value).join('***'), text);
@@ -4,6 +4,7 @@ import { type HealthBody } from '../health/health.schema.js';
4
4
  import { type Log } from '../log/log.js';
5
5
  import { type ExtensionPackage } from '../manifest/manifest.schema.js';
6
6
  import { type HostPartKind } from '../manifest/parts.js';
7
+ import { type Env } from '../runtime/build-info.js';
7
8
  import { type PartAppBase } from '../server/app.js';
8
9
  export interface HostOptions {
9
10
  dataDir: string;
@@ -29,5 +30,6 @@ export interface HostExtras {
29
30
  guard?: (pkg: ExtensionPackage, log: Log) => Promise<Partial<PartAppBase>>;
30
31
  build?: BuildInfo;
31
32
  }
33
+ export declare const hostBuildInfo: (env: Env, dir: string) => Promise<BuildInfo>;
32
34
  export declare const hostWith: (dir: string, opts: HostOptions, extras: HostExtras) => Promise<HostedExtension>;
33
35
  export declare const hostExtension: (dir: string, opts: HostOptions) => Promise<HostedExtension>;
@@ -1,4 +1,6 @@
1
1
  import { randomBytes } from 'node:crypto';
2
+ import { stat } from 'node:fs/promises';
3
+ import { join } from 'node:path';
2
4
  import {} from 'express';
3
5
  import {} from '../discovery/discovery.js';
4
6
  import { healthBody } from '../health/health.js';
@@ -45,6 +47,8 @@ const hostedOf = (h, hosted, base) => {
45
47
  const stop = () => (stopped ??= close());
46
48
  return { id, version, parts, app, health, stop };
47
49
  };
50
+ // BUILD_TIME of an image, else the installed package's time: the same across restarts.
51
+ export const hostBuildInfo = async (env, dir) => buildInfoFromEnv(env, (await stat(join(dir, 'package.json'))).mtime);
48
52
  // hostExtension with the extras of the entry (dist/host/main.js).
49
53
  export const hostWith = async (dir, opts, extras) => {
50
54
  const pkg = await readManifest(dir);
@@ -53,7 +57,7 @@ export const hostWith = async (dir, opts, extras) => {
53
57
  const at = { dir, dataDir: opts.dataDir, runDir: opts.runDir, openMs };
54
58
  const store = await openHostStore(pkg, at, log);
55
59
  const onExit = once(opts.onExit ?? (() => undefined));
56
- const build = extras.build ?? buildInfoFromEnv({});
60
+ const build = extras.build ?? (await hostBuildInfo({}, dir));
57
61
  const h = { dir, pkg, log, opts, extras, store, onExit, build };
58
62
  try {
59
63
  const base = await baseOf(h);
@@ -2,8 +2,9 @@ import {} from 'express';
2
2
  import { createContext } from '../context/context.js';
3
3
  import { readSecrets, secretsFrom } from '../context/secrets.js';
4
4
  import { settingsOf } from '../context/settings.js';
5
- import {} from '../discovery/discovery.js';
5
+ import { hostedRecordOf } from '../discovery/discovery.js';
6
6
  import { readOpenapi } from '../discovery/openapi.js';
7
+ import { migrationsOf } from '../discovery/served-extras.js';
7
8
  import { createLog } from '../log/log.js';
8
9
  import {} from '../manifest/manifest.schema.js';
9
10
  import { hostParts } from '../manifest/parts.js';
@@ -63,12 +64,18 @@ const mountsOf = async (h, parts, base) => {
63
64
  }
64
65
  return mounts;
65
66
  };
67
+ // The record a part image reads from its build, here from what each part serves.
68
+ const recordOf = async (h, parts, mounts) => {
69
+ const extras = Object.assign(await migrationsOf(h.dir, h.pkg), ...mounts.map((m) => m.record));
70
+ return hostedRecordOf(h.pkg, h.build, parts, extras);
71
+ };
66
72
  // The api at /api/{id}/*, the mcp at /mcp/{id}, the worker jobs; one /health with every check.
67
73
  export const hostPartsOf = async (h, base) => {
68
74
  const parts = hostParts(h.pkg);
69
75
  const mounts = await mountsOf(h, parts, base);
70
76
  const mount = (app) => mounts.forEach((m) => m.mount(app));
71
- const app = createPartApp({ ...base, parts, part: 'api', mount });
77
+ const record = await recordOf(h, parts, mounts);
78
+ const app = createPartApp({ ...base, parts, part: 'api', mount, record });
72
79
  const start = () => mounts.forEach((m) => m.start?.());
73
80
  const stop = () => mounts.forEach((m) => m.stop?.());
74
81
  return { app, parts, start, stop };
@@ -2,11 +2,11 @@ import {} from 'node:http';
2
2
  import {} from 'node:net';
3
3
  import { setTimeout as sleep } from 'node:timers/promises';
4
4
  import { createLog } from '../log/log.js';
5
- import { buildInfoFromEnv } from '../runtime/build-info.js';
5
+ import {} from '../runtime/build-info.js';
6
6
  import { listen, shutdownOn } from '../server/serve.js';
7
7
  import { loopbackPorts } from './daemon/guard.js';
8
8
  import { guardOf, hostEnvOf } from './host-env.js';
9
- import { hostWith } from './host-extension.js';
9
+ import { hostBuildInfo, hostWith } from './host-extension.js';
10
10
  export const ORPHAN_MS = 10_000;
11
11
  // The port to the daemon; its IPC channel closed: drain, and exit within ORPHAN_MS in any case.
12
12
  export const announce = (port, stop, exit = process.exit) => {
@@ -56,7 +56,8 @@ export const serveHost = async (env, deps = {}) => {
56
56
  // C2: on loopback the child checks Host and Origin itself, for its own port and the daemon's.
57
57
  const local = { localOnly: at.bind === '127.0.0.1', localPorts: loopbackPorts(origin) };
58
58
  const opts = { dataDir, runDir, settings, origin, storeOpenMs, onExit: hook.onExit, ...local };
59
- const host = await hostWith(at.dir, opts, { secretsDir, guard, build: buildInfoFromEnv(env) });
59
+ const build = await hostBuildInfo(env, at.dir);
60
+ const host = await hostWith(at.dir, opts, { secretsDir, guard, build });
60
61
  const server = await listen(host.app, at.port, at.bind);
61
62
  const { log, stop } = drainOn(server, host, deps, at.drainMs);
62
63
  const { port } = server.address();
@@ -1,5 +1,6 @@
1
1
  import { type Express } from 'express';
2
2
  import { type PartContext } from '../context/context.js';
3
+ import { type RecordExtras } from '../discovery/discovery.js';
3
4
  import { type HealthCheck } from '../health/health.js';
4
5
  import { type ImportModule } from '../manifest/entry.js';
5
6
  import { type ExtensionPackage } from '../manifest/manifest.schema.js';
@@ -24,6 +25,7 @@ export interface PartMount {
24
25
  checks?: Record<string, HealthCheck>;
25
26
  start?: () => void;
26
27
  stop?: () => void;
28
+ record?: RecordExtras;
27
29
  }
28
30
  export declare const callCreate: <C>(input: RunnerInput, part: ImagePartKind, ctx: C) => Promise<unknown>;
29
31
  export declare const MOUNTS: Record<HostPartKind, (input: RunnerInput) => Promise<PartMount>>;
@@ -1,6 +1,9 @@
1
1
  import {} from 'express';
2
2
  import { generatedOpenapi } from '../api/openapi-doc.js';
3
3
  import {} from '../context/context.js';
4
+ import {} from '../discovery/discovery.js';
5
+ import { openapiPath } from '../discovery/openapi.js';
6
+ import { toolRecords } from '../discovery/served-extras.js';
4
7
  import {} from '../health/health.js';
5
8
  import { loadCreate } from '../manifest/entry.js';
6
9
  import {} from '../manifest/manifest.schema.js';
@@ -23,7 +26,8 @@ const api = async (input) => {
23
26
  // Declared routes guard at their own scope, whatever the committed file says.
24
27
  const openapi = routes.length > 0 ? generatedOpenapi(input.pkg, routes) : input.openapi;
25
28
  const options = { ...input.base, router, routes, openapi, wellKnown: documents };
26
- return { mount: (app) => mountApiRoutes(app, { ...options, aliases: input.apiAliases }) };
29
+ const record = openapi ? { openapi: openapiPath(input.pkg.agentage.id) } : {};
30
+ return { mount: (app) => mountApiRoutes(app, { ...options, aliases: input.apiAliases }), record };
27
31
  };
28
32
  const mcp = async (input) => {
29
33
  const registry = createToolRegistry();
@@ -32,7 +36,8 @@ const mcp = async (input) => {
32
36
  const token = !input.openListing && ctx.settings['mcp.listing'] === 'token';
33
37
  const listing = token ? 'token' : 'open';
34
38
  const options = { ...input.base, tools: registry.tools, listing, paths: input.mcpPaths };
35
- return { mount: (app) => mountMcp(app, options) };
39
+ const tools = toolRecords(input.pkg.agentage.id, registry.tools);
40
+ return { mount: (app) => mountMcp(app, options), record: tools.length ? { tools } : {} };
36
41
  };
37
42
  const worker = async (input) => {
38
43
  const ctx = input.ctx();
@@ -3,8 +3,7 @@ import { type Express, type RequestHandler } from 'express';
3
3
  import { type HelmetOptions } from 'helmet';
4
4
  import { type WellKnownEntry } from '../api/well-known.js';
5
5
  import { type TokenCheck } from '../auth/token-check.js';
6
- import { type BuildInfo } from '../discovery/discovery.js';
7
- import { type ExtensionRecord } from '../discovery/discovery.schema.js';
6
+ import { type BuildInfo, type ServedRecord } from '../discovery/discovery.js';
8
7
  import { type HealthCheck } from '../health/health.js';
9
8
  import { type Log } from '../log/log.js';
10
9
  import { type ExtensionPackage } from '../manifest/manifest.schema.js';
@@ -14,7 +13,7 @@ export interface PartAppBase {
14
13
  pkg: ExtensionPackage;
15
14
  build: BuildInfo;
16
15
  log: Log;
17
- record?: ExtensionRecord | null;
16
+ record?: ServedRecord | null;
18
17
  ownImage?: string;
19
18
  origin?: string;
20
19
  checks?: Record<string, HealthCheck>;
@@ -6,7 +6,6 @@ import { agcidMiddleware } from '../agcid/scope.js';
6
6
  import { routeAccess, sameShape } from '../auth/route-access.js';
7
7
  import { setCaller } from '../auth/token-check.js';
8
8
  import { discoveryDocument, recordOf, } from '../discovery/discovery.js';
9
- import {} from '../discovery/discovery.schema.js';
10
9
  import { apiPrefix } from '../discovery/openapi.js';
11
10
  import { createHealthHandler } from '../health/health.js';
12
11
  import {} from '../log/log.js';
@@ -33,6 +33,7 @@ export interface BuildResult {
33
33
  images: BuiltImage[];
34
34
  container?: BuiltContainer;
35
35
  recordFile?: string;
36
+ warnings?: string[];
36
37
  }
37
38
  export declare const imageTag: (registry: string, pkg: ExtensionPackage, part: ImagePartKind) => string;
38
39
  export declare const recordFor: (dir: string, pkg: ExtensionPackage, info: BuildInfo, images: BuiltImage[]) => Promise<ExtensionRecord>;
@@ -83,10 +83,11 @@ export const build = async (options = {}, deps = { run: runCommand }) => {
83
83
  const parts = options.container ? containerParts(pkg) : undefined;
84
84
  const info = await resolveBuildInfo(dir, options.env ?? process.env, deps.run);
85
85
  await compile(dir, pkg, deps.run);
86
- await assertConforms(dir, { run: deps.run });
86
+ const warnings = await assertConforms(dir, { run: deps.run });
87
87
  const base = { dir, pkg, info };
88
88
  const built = parts
89
89
  ? await containerOf(base, parts, options, deps)
90
90
  : await partImages(base, options, deps);
91
- return { id: pkg.agentage.id, version: pkg.version, ...info, ...built };
91
+ const warned = warnings.length > 0 ? { warnings } : {};
92
+ return { id: pkg.agentage.id, version: pkg.version, ...info, ...built, ...warned };
92
93
  };
@@ -37,4 +37,4 @@ export interface CheckReport {
37
37
  export declare const NOT_BUILT = "is missing: build the package first (npm run build)";
38
38
  export declare const RULES: readonly CheckRule[];
39
39
  export declare const check: (at: string, options?: CheckOptions) => Promise<CheckReport>;
40
- export declare const assertConforms: (dir: string, options?: CheckOptions) => Promise<void>;
40
+ export declare const assertConforms: (dir: string, options?: CheckOptions) => Promise<string[]>;
@@ -9,7 +9,7 @@ import { entryOf, normalizeParts } from '../manifest/parts.js';
9
9
  import {} from '../manifest/primitives.schema.js';
10
10
  import { formatIssues, readJsonIfExists } from '../manifest/read-manifest.js';
11
11
  import { runCommand } from './exec.js';
12
- import { problemLines } from './format.js';
12
+ import { problemLines, warningLines } from './format.js';
13
13
  import { exportedPartCode } from './rules/folders.js';
14
14
  import { sealing } from './rules/sealing.js';
15
15
  import { store } from './rules/store.js';
@@ -137,4 +137,5 @@ export const assertConforms = async (dir, options = {}) => {
137
137
  const lines = problemLines(report).map((line) => `check failed: ${line}`);
138
138
  if (!report.conforms)
139
139
  throw new Error(lines.join('\n'));
140
+ return warningLines(report);
140
141
  };
@@ -2,4 +2,5 @@ import { type BuildResult } from './build.js';
2
2
  import { type CheckReport } from './check.js';
3
3
  export declare const buildLines: (result: BuildResult, cwd?: string) => string[];
4
4
  export declare const problemLines: (report: CheckReport) => string[];
5
+ export declare const warningLines: ({ warnings }: CheckReport) => string[];
5
6
  export declare const checkLines: (report: CheckReport) => string[];
@@ -16,11 +16,13 @@ const partsLine = ({ container }) => {
16
16
  // One line per image (the one image as "image"), the parts it runs and skips, then the record.
17
17
  export const buildLines = (result, cwd = process.cwd()) => {
18
18
  const rows = rowsOf(result);
19
+ const warned = result.warnings ?? [];
19
20
  const width = Math.max(...rows.map((row) => row.tag.length)) + 2;
20
21
  const lines = rows.map((row) => {
21
22
  const state = row.digest ? `${shortDigest(row.digest)} pushed` : 'built';
22
23
  return `${row.label.padEnd(8)}${row.tag.padEnd(width)}${state}`;
23
24
  });
25
+ lines.unshift(...warned);
24
26
  lines.push(...partsLine(result));
25
27
  if (result.recordFile)
26
28
  lines.push(`${'record'.padEnd(8)}${relative(cwd, result.recordFile)}`);
@@ -29,7 +31,7 @@ export const buildLines = (result, cwd = process.cwd()) => {
29
31
  const where = ({ file, line }) => file ? `${file}${line ? `:${line}` : ''} ` : '';
30
32
  const lineOf = (found) => `${found.rule}: ${where(found)}${found.problem}`;
31
33
  export const problemLines = (report) => report.problems.map(lineOf);
32
- const warningLines = ({ warnings = [] }) => warnings.map((found) => `warning ${lineOf(found)}`);
34
+ export const warningLines = ({ warnings = [] }) => warnings.map((found) => `warning ${lineOf(found)}`);
33
35
  // What `agentage extension check` prints (sheet C2): the rules line and PASS, or each problem and FAIL; warnings first.
34
36
  export const checkLines = (report) => {
35
37
  const { rules, skipped, problems } = report;
@@ -1,18 +1,17 @@
1
1
  import { join } from 'node:path';
2
2
  import { z } from 'zod';
3
3
  import { createRouteRegistry } from '../api/routes.js';
4
- import { scopeOf } from '../auth/token-check.js';
5
4
  import { createContext } from '../context/context.js';
6
5
  import {} from '../discovery/discovery.js';
7
6
  import { WidgetSchema } from '../discovery/discovery.schema.js';
8
7
  import { openapiPath, readOpenapi } from '../discovery/openapi.js';
8
+ import { migrationsOf, toolRecords } from '../discovery/served-extras.js';
9
9
  import { createLog } from '../log/log.js';
10
10
  import { loadCreate } from '../manifest/entry.js';
11
11
  import { readJsonIfExists } from '../manifest/read-manifest.js';
12
12
  import {} from '../manifest/manifest.schema.js';
13
- import { migratesStore, normalizeParts } from '../manifest/parts.js';
14
- import { createToolRegistry, prefixed } from '../mcp/tools.js';
15
- import { sqlFiles } from '../store/migrations.js';
13
+ import { normalizeParts } from '../manifest/parts.js';
14
+ import { createToolRegistry } from '../mcp/tools.js';
16
15
  import {} from '../store/store.types.js';
17
16
  const WidgetsSchema = z.array(WidgetSchema).min(1);
18
17
  const noStore = {
@@ -44,11 +43,7 @@ export const registeredRoutes = async (create, pkg) => {
44
43
  };
45
44
  export const toolsOf = async (dir, pkg) => {
46
45
  const tools = await registeredTools(await loadCreate(dir, pkg, 'mcp'), pkg);
47
- const { id } = pkg.agentage;
48
- return tools.map((tool) => ({
49
- name: prefixed(id, tool.name),
50
- scope: scopeOf(id, tool.spec.scope),
51
- }));
46
+ return toolRecords(pkg.agentage.id, tools);
52
47
  };
53
48
  const widgetsOf = async (dir) => {
54
49
  const value = await readJsonIfExists(join(dir, 'dist', 'ui', 'widgets.json'));
@@ -57,7 +52,7 @@ const widgetsOf = async (dir) => {
57
52
  // What the code serves, for the record: tools, widgets and the migration count.
58
53
  export const recordExtras = async (dir, pkg) => {
59
54
  const { code } = normalizeParts(pkg.agentage.parts);
60
- const extras = {};
55
+ const extras = await migrationsOf(dir, pkg);
61
56
  if (code.mcp) {
62
57
  const tools = await toolsOf(dir, pkg);
63
58
  if (tools.length > 0)
@@ -67,7 +62,5 @@ export const recordExtras = async (dir, pkg) => {
67
62
  extras.widgets = await widgetsOf(dir);
68
63
  if (code.api && (await readOpenapi(dir)))
69
64
  extras.openapi = openapiPath(pkg.agentage.id);
70
- if (migratesStore(pkg))
71
- extras.migrations = (await sqlFiles(join(dir, 'migrations'))).length;
72
65
  return extras;
73
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/extension",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "description": "The agentage extension kit: create(ctx) per part (pages, ui, api, mcp, worker, cli), the store, /health, discovery, the envelope, and the build tool with up and token",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -54,46 +54,73 @@
54
54
  "additionalProperties": false
55
55
  },
56
56
  "api": {
57
- "type": "object",
58
- "properties": {
59
- "image": {
60
- "type": "string",
61
- "maxLength": 256,
62
- "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?\\/[a-z0-9][a-z0-9-]*\\/[a-z][a-z0-9-]*-(pages|ui|api|mcp|worker)@sha256:[0-9a-f]{64}$"
57
+ "anyOf": [
58
+ {
59
+ "type": "object",
60
+ "properties": {
61
+ "image": {
62
+ "type": "string",
63
+ "maxLength": 256,
64
+ "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?\\/[a-z0-9][a-z0-9-]*\\/[a-z][a-z0-9-]*-(pages|ui|api|mcp|worker)@sha256:[0-9a-f]{64}$"
65
+ }
66
+ },
67
+ "required": [
68
+ "image"
69
+ ],
70
+ "additionalProperties": false
71
+ },
72
+ {
73
+ "type": "object",
74
+ "properties": {},
75
+ "additionalProperties": false
63
76
  }
64
- },
65
- "required": [
66
- "image"
67
- ],
68
- "additionalProperties": false
77
+ ]
69
78
  },
70
79
  "mcp": {
71
- "type": "object",
72
- "properties": {
73
- "image": {
74
- "type": "string",
75
- "maxLength": 256,
76
- "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?\\/[a-z0-9][a-z0-9-]*\\/[a-z][a-z0-9-]*-(pages|ui|api|mcp|worker)@sha256:[0-9a-f]{64}$"
80
+ "anyOf": [
81
+ {
82
+ "type": "object",
83
+ "properties": {
84
+ "image": {
85
+ "type": "string",
86
+ "maxLength": 256,
87
+ "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?\\/[a-z0-9][a-z0-9-]*\\/[a-z][a-z0-9-]*-(pages|ui|api|mcp|worker)@sha256:[0-9a-f]{64}$"
88
+ }
89
+ },
90
+ "required": [
91
+ "image"
92
+ ],
93
+ "additionalProperties": false
94
+ },
95
+ {
96
+ "type": "object",
97
+ "properties": {},
98
+ "additionalProperties": false
77
99
  }
78
- },
79
- "required": [
80
- "image"
81
- ],
82
- "additionalProperties": false
100
+ ]
83
101
  },
84
102
  "worker": {
85
- "type": "object",
86
- "properties": {
87
- "image": {
88
- "type": "string",
89
- "maxLength": 256,
90
- "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?\\/[a-z0-9][a-z0-9-]*\\/[a-z][a-z0-9-]*-(pages|ui|api|mcp|worker)@sha256:[0-9a-f]{64}$"
103
+ "anyOf": [
104
+ {
105
+ "type": "object",
106
+ "properties": {
107
+ "image": {
108
+ "type": "string",
109
+ "maxLength": 256,
110
+ "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?\\/[a-z0-9][a-z0-9-]*\\/[a-z][a-z0-9-]*-(pages|ui|api|mcp|worker)@sha256:[0-9a-f]{64}$"
111
+ }
112
+ },
113
+ "required": [
114
+ "image"
115
+ ],
116
+ "additionalProperties": false
117
+ },
118
+ {
119
+ "type": "object",
120
+ "properties": {},
121
+ "additionalProperties": false
91
122
  }
92
- },
93
- "required": [
94
- "image"
95
- ],
96
- "additionalProperties": false
123
+ ]
97
124
  },
98
125
  "store": {
99
126
  "type": "object",
@@ -122,7 +149,7 @@
122
149
  "additionalProperties": false
123
150
  },
124
151
  "image": {
125
- "description": "The one image (build --container). A record has part images or this image: never both, never none.",
152
+ "description": "The one image (build --container). A build record has part images or this image: never both, never none.",
126
153
  "type": "string",
127
154
  "maxLength": 256,
128
155
  "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?(\\/[a-z0-9][a-z0-9_.-]*)+\\/[a-z][a-z0-9-]*@sha256:[0-9a-f]{64}$"
@@ -122,7 +122,7 @@
122
122
  "additionalProperties": false
123
123
  },
124
124
  "image": {
125
- "description": "The one image (build --container). A record has part images or this image: never both, never none.",
125
+ "description": "The one image (build --container). A build record has part images or this image: never both, never none.",
126
126
  "type": "string",
127
127
  "maxLength": 256,
128
128
  "pattern": "^[a-z0-9][a-z0-9.-]*(:[0-9]{1,5})?(\\/[a-z0-9][a-z0-9_.-]*)+\\/[a-z][a-z0-9-]*@sha256:[0-9a-f]{64}$"