@agentage/extension 0.12.3 → 0.13.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.
Files changed (79) hide show
  1. package/dist/api/openapi-doc.js +2 -1
  2. package/dist/api/routes.js +1 -1
  3. package/dist/context/context.d.ts +1 -0
  4. package/dist/context/context.js +3 -3
  5. package/dist/context/secrets.d.ts +1 -0
  6. package/dist/context/secrets.js +7 -5
  7. package/dist/context/settings.d.ts +4 -0
  8. package/dist/context/settings.js +6 -5
  9. package/dist/discovery/discovery.schema.js +8 -2
  10. package/dist/discovery/openapi.d.ts +2 -1
  11. package/dist/discovery/openapi.js +3 -1
  12. package/dist/host/daemon/child.d.ts +21 -0
  13. package/dist/host/daemon/child.js +92 -0
  14. package/dist/host/daemon/daemon-files.d.ts +19 -0
  15. package/dist/host/daemon/daemon-files.js +23 -0
  16. package/dist/host/daemon/daemon.d.ts +18 -0
  17. package/dist/host/daemon/daemon.js +84 -0
  18. package/dist/host/daemon/guard.d.ts +2 -0
  19. package/dist/host/daemon/guard.js +15 -0
  20. package/dist/host/daemon/installation.d.ts +23 -0
  21. package/dist/host/daemon/installation.js +48 -0
  22. package/dist/host/daemon/installer-call.d.ts +7 -0
  23. package/dist/host/daemon/installer-call.js +22 -0
  24. package/dist/host/daemon/json-file.d.ts +3 -0
  25. package/dist/host/daemon/json-file.js +51 -0
  26. package/dist/host/daemon/lane.d.ts +11 -0
  27. package/dist/host/daemon/lane.js +29 -0
  28. package/dist/host/daemon/ops.d.ts +36 -0
  29. package/dist/host/daemon/ops.js +149 -0
  30. package/dist/host/daemon/proxy.d.ts +5 -0
  31. package/dist/host/daemon/proxy.js +67 -0
  32. package/dist/host/daemon/queue.d.ts +2 -0
  33. package/dist/host/daemon/queue.js +8 -0
  34. package/dist/host/daemon/routes.d.ts +11 -0
  35. package/dist/host/daemon/routes.js +48 -0
  36. package/dist/host/daemon/secret-names.d.ts +1 -0
  37. package/dist/host/daemon/secret-names.js +14 -0
  38. package/dist/host/daemon/setting-values.d.ts +1 -0
  39. package/dist/host/daemon/setting-values.js +26 -0
  40. package/dist/host/daemon/supervisor.d.ts +52 -0
  41. package/dist/host/daemon/supervisor.js +116 -0
  42. package/dist/host/data-lock.d.ts +2 -0
  43. package/dist/host/data-lock.js +81 -0
  44. package/dist/host/host-env.d.ts +17 -0
  45. package/dist/host/host-env.js +36 -0
  46. package/dist/host/host-extension.d.ts +25 -0
  47. package/dist/host/host-extension.js +86 -0
  48. package/dist/host/host-store.d.ts +4 -0
  49. package/dist/host/host-store.js +35 -0
  50. package/dist/host/index.d.ts +3 -0
  51. package/dist/host/index.js +3 -0
  52. package/dist/host/main.d.ts +2 -0
  53. package/dist/host/main.js +10 -0
  54. package/dist/host/serve-host.d.ts +16 -0
  55. package/dist/host/serve-host.js +61 -0
  56. package/dist/runtime/part-runners.d.ts +1 -0
  57. package/dist/runtime/part-runners.js +10 -1
  58. package/dist/runtime/run-part.js +2 -0
  59. package/dist/server/app.d.ts +4 -0
  60. package/dist/server/app.js +28 -18
  61. package/dist/server/request-line.d.ts +1 -1
  62. package/dist/server/request-line.js +4 -4
  63. package/dist/server/serve.js +11 -3
  64. package/dist/store/pglite-store.d.ts +25 -0
  65. package/dist/store/pglite-store.js +59 -0
  66. package/dist/store/test-store.d.ts +2 -3
  67. package/dist/store/test-store.js +3 -38
  68. package/dist/testing/test-server.d.ts +2 -0
  69. package/dist/testing/test-server.js +1 -1
  70. package/dist/tool/record-extras.js +2 -2
  71. package/dist/tool/rules/surface.js +6 -6
  72. package/dist/tool/up/gateway.d.ts +6 -2
  73. package/dist/tool/up/gateway.js +10 -7
  74. package/dist/tool/up/token.js +1 -1
  75. package/dist/tool/up/up.js +2 -2
  76. package/dist/vendor/logs/events-client.js +1 -1
  77. package/package.json +5 -1
  78. package/schemas/extension-discovery.schema.json +1 -1
  79. package/schemas/extension-record.schema.json +1 -1
@@ -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 interface TestStore extends Store {
3
- close(): Promise<void>;
4
- }
3
+ export type TestStore = PgliteStore;
5
4
  export declare const createTestStore: (prepare: (store: Store) => Promise<unknown>) => TestStore;
@@ -1,39 +1,4 @@
1
+ import { createPgliteStore } from './pglite-store.js';
1
2
  import {} from './store.types.js';
2
- const open = async () => {
3
- try {
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 {
@@ -5,7 +5,7 @@ import { scopeOf } from '../auth/token-check.js';
5
5
  import { createContext } from '../context/context.js';
6
6
  import {} from '../discovery/discovery.js';
7
7
  import { WidgetSchema } from '../discovery/discovery.schema.js';
8
- import { OPENAPI_PATH, readOpenapi } from '../discovery/openapi.js';
8
+ import { openapiPath, readOpenapi } from '../discovery/openapi.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';
@@ -66,7 +66,7 @@ export const recordExtras = async (dir, pkg) => {
66
66
  if (code.ui)
67
67
  extras.widgets = await widgetsOf(dir);
68
68
  if (code.api && (await readOpenapi(dir)))
69
- extras.openapi = OPENAPI_PATH;
69
+ extras.openapi = openapiPath(pkg.agentage.id);
70
70
  if (migratesStore(pkg))
71
71
  extras.migrations = (await sqlFiles(join(dir, 'migrations'))).length;
72
72
  return extras;
@@ -1,7 +1,7 @@
1
1
  import { join } from 'node:path';
2
2
  import { generatedOpenapi, schemaOf } from '../../api/openapi-doc.js';
3
3
  import {} from '../../api/routes.js';
4
- import { OPENAPI_FILE, readOpenapi } from '../../discovery/openapi.js';
4
+ import { apiPrefix, OPENAPI_FILE, readOpenapi } from '../../discovery/openapi.js';
5
5
  import { loadCreate } from '../../manifest/entry.js';
6
6
  import {} from '../../manifest/manifest.schema.js';
7
7
  import { normalizeParts } from '../../manifest/parts.js';
@@ -11,17 +11,17 @@ import { prefixed } from '../../mcp/tools.js';
11
11
  import {} from '../check.js';
12
12
  import { registeredRoutes, registeredTools } from '../record-extras.js';
13
13
  const differing = (generated, committed) => [...new Set([...Object.keys(generated), ...Object.keys(committed)])].filter((key) => JSON.stringify(canonical(generated[key])) !== JSON.stringify(canonical(committed[key])));
14
- const routeKeys = ({ path, stack }) => [path].flat().flatMap((one) => {
15
- const at = `/api/v1${String(one).replace(/:(\w+)/g, '{$1}')}`;
14
+ const routeKeys = (prefix, { path, stack }) => [path].flat().flatMap((one) => {
15
+ const at = `${prefix}${String(one).replace(/:(\w+)/g, '{$1}')}`;
16
16
  // router.all names no method, so it has no operation to compare.
17
17
  return stack.flatMap(({ method }) => (method ? [`${method.toUpperCase()} ${at}`] : []));
18
18
  });
19
19
  // Express routes (of a Router or an express() app) as OpenAPI keys; a sub-router hides its routes, so it never matches one.
20
- const servedRoutes = (app) => {
20
+ const servedRoutes = (prefix, app) => {
21
21
  const { stack, router } = (app ?? {});
22
22
  return (stack ?? router?.stack ?? []).flatMap(({ name, route, handle }) => {
23
23
  if (route)
24
- return routeKeys(route);
24
+ return routeKeys(prefix, route);
25
25
  return handle?.stack ? [`${name} sub-router`] : [];
26
26
  });
27
27
  };
@@ -58,7 +58,7 @@ const routeProblems = (pkg, doc, routes, returned) => {
58
58
  return diff.length > 0 ? [`differs from the generated contract (${diff.join(', ')})`] : [];
59
59
  };
60
60
  const routerProblems = (pkg, doc, returned) => doc
61
- ? apiProblems(doc, servedRoutes(returned), pkg.version)
61
+ ? apiProblems(doc, servedRoutes(apiPrefix(pkg.agentage.id), returned), pkg.version)
62
62
  : ['is missing: the api part commits its contract'];
63
63
  const apiSurface = async ({ dir, pkg }) => {
64
64
  const create = await loadCreate(dir, pkg, 'api').catch(() => null);
@@ -10,8 +10,12 @@ export declare const PART_PATHS: {
10
10
  mcp: string;
11
11
  };
12
12
  type RoutedPart = keyof typeof PART_PATHS;
13
- export declare const partPath: (part: RoutedPart, version: string) => string;
14
- export declare const gatewayConfig: (parts: ImagePartKind[], version: string) => {
13
+ export interface PathOf {
14
+ id: string;
15
+ version: string;
16
+ }
17
+ export declare const partPath: (part: RoutedPart, { id, version }: PathOf) => string;
18
+ export declare const gatewayConfig: (parts: ImagePartKind[], of: PathOf) => {
15
19
  http: {
16
20
  middlewares: {
17
21
  'gateway-headers': {
@@ -6,11 +6,11 @@ export const TRAEFIK_IMAGE = 'traefik:v3.7.17@sha256:68ae5fe5b64ca166704b746a9e8
6
6
  // The URL layout of api-standards section 1, as the estate's gateway renders it.
7
7
  const RESERVED = 'PathPrefix(`/api/`) || Path(`/mcp`) || PathPrefix(`/mcp/`) || PathPrefix(`/ui/`) || PathPrefix(`/.well-known/`) || PathPrefix(`/git/`) || Path(`/health`)';
8
8
  // Each routed part's path, in the order `up` prints them; /mcp is exact, the rest are prefixes.
9
- export const PART_PATHS = { pages: '/', ui: '/ui/{version}/', api: '/api/v1/', mcp: '/mcp' };
9
+ export const PART_PATHS = { pages: '/', ui: '/ui/{version}/', api: '/api/{id}/', mcp: '/mcp' };
10
10
  // In this order, so the first present serves /.well-known/ (api-standards section 1).
11
11
  const ROUTED = ['api', 'mcp', 'pages', 'ui'];
12
- export const partPath = (part, version) => PART_PATHS[part].replace('{version}', version);
13
- const ruleOf = (part, version) => part === 'mcp' ? 'Path(`/mcp`)' : `PathPrefix(\`${partPath(part, version)}\`)`;
12
+ export const partPath = (part, { id, version }) => PART_PATHS[part].replace('{version}', version).replace('{id}', id);
13
+ const ruleOf = (part, of) => part === 'mcp' ? 'Path(`/mcp`)' : `PathPrefix(\`${partPath(part, of)}\`)`;
14
14
  const router = (rule, priority, service) => ({
15
15
  rule,
16
16
  priority,
@@ -18,16 +18,19 @@ const router = (rule, priority, service) => ({
18
18
  entryPoints: ['web'],
19
19
  middlewares: ['gateway-headers'],
20
20
  });
21
- const partRouters = (routed, version) => {
21
+ const partRouters = (routed, of) => {
22
22
  const routers = {};
23
23
  for (const part of routed)
24
- routers[part] = router(ruleOf(part, version), part === 'pages' ? 1 : 100, part);
24
+ routers[part] = router(ruleOf(part, of), part === 'pages' ? 1 : 100, part);
25
+ // The old api prefix, as runPart serves it, until phase 4.
26
+ if (routed.includes('api'))
27
+ routers['api-v1'] = router('PathPrefix(`/api/v1/`)', 100, 'api');
25
28
  if (routed[0])
26
29
  routers['well-known'] = router('PathPrefix(`/.well-known/`)', 100, routed[0]);
27
30
  return routers;
28
31
  };
29
32
  // Traefik's file provider: a reserved-prefix miss is Traefik's own 404, like the estate gateway.
30
- export const gatewayConfig = (parts, version) => {
33
+ export const gatewayConfig = (parts, of) => {
31
34
  const routed = ROUTED.filter((part) => parts.includes(part));
32
35
  const services = {
33
36
  'gateway-miss': { loadBalancer: { servers: [{ url: 'http://127.0.0.1:8081' }] } },
@@ -36,7 +39,7 @@ export const gatewayConfig = (parts, version) => {
36
39
  services[part] = { loadBalancer: { servers: [{ url: `http://${part}:${PART_PORT}` }] } };
37
40
  const routers = {
38
41
  reserved: router(RESERVED, 50, 'gateway-miss'),
39
- ...partRouters(routed, version),
42
+ ...partRouters(routed, of),
40
43
  };
41
44
  if (!routed.includes('pages'))
42
45
  routers['host'] = router('PathPrefix(`/`)', 1, 'gateway-miss');
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { TIMEOUTS } from '../timeouts.js';
3
3
  import { DEV_ISSUER } from './dev-issuer-app.js';
4
4
  const AnswerSchema = z.object({ token: z.string().startsWith('aga_') });
5
- // A token from the dev issuer of `up`, for calling /api/v1/ and /mcp by hand or from tests.
5
+ // A token from the dev issuer of `up`, for calling /api/{id}/ and /mcp by hand or from tests.
6
6
  export const token = async (options) => {
7
7
  const issuer = options.issuer ?? DEV_ISSUER;
8
8
  const res = await (options.fetch ?? fetch)(`${issuer}/token`, {
@@ -25,7 +25,7 @@ const renderFiles = async (s, recordFile, tags) => {
25
25
  const gatewayFile = join(s.dir, LOCAL_DIR, 'gateway.yml');
26
26
  const seeds = join(s.dir, 'seeds');
27
27
  const seedsDir = (await exists(seeds)) ? seeds : undefined;
28
- await jsonFile(gatewayFile, gatewayConfig(imageParts(s.pkg), s.pkg.version));
28
+ await jsonFile(gatewayFile, gatewayConfig(imageParts(s.pkg), { id: s.pkg.agentage.id, version: s.pkg.version }));
29
29
  const { pkg, secretFiles, target } = s;
30
30
  const project = target.project;
31
31
  await jsonFile(target.file, composeFile({ pkg, project, tags, recordFile, gatewayFile, seedsDir, secretFiles }));
@@ -53,7 +53,7 @@ const storeStep = async (s) => {
53
53
  };
54
54
  export const routesOf = (pkg) => Object.keys(PART_PATHS)
55
55
  .filter((part) => imageParts(pkg).includes(part))
56
- .map((part) => partPath(part, pkg.version));
56
+ .map((part) => partPath(part, { id: pkg.agentage.id, version: pkg.version }));
57
57
  const partsStep = async (s, commit) => {
58
58
  await compose(s.deps.run, s.target, ['up', '-d', '--remove-orphans'], TIMEOUTS.start);
59
59
  await waitHealthy(s.target, [...imageParts(s.pkg), 'gateway', 'issuer'], s.deps);
@@ -24,7 +24,7 @@ const fitting = (event) => {
24
24
  process.emitWarning(`@agentage/logs: dropped a ${event.kind} row over 900 KB`);
25
25
  return false;
26
26
  };
27
- // Each batch under 1 MB and at most 1000 rows (the ingest wire, C3).
27
+ // Each batch under 1 MB and at most 1000 rows (the ingest wire).
28
28
  export const batchesOf = (events) => {
29
29
  const batches = [];
30
30
  let batch = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentage/extension",
3
- "version": "0.12.3",
3
+ "version": "0.13.0",
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",
@@ -32,6 +32,10 @@
32
32
  "types": "./dist/contracts/index.d.ts",
33
33
  "default": "./dist/contracts/index.js"
34
34
  },
35
+ "./host": {
36
+ "types": "./dist/host/index.d.ts",
37
+ "default": "./dist/host/index.js"
38
+ },
35
39
  "./logs": {
36
40
  "types": "./dist/logs/index.d.ts",
37
41
  "default": "./dist/logs/index.js"
@@ -123,7 +123,7 @@
123
123
  },
124
124
  "openapi": {
125
125
  "type": "string",
126
- "pattern": "^\\/api\\/v[1-9][0-9]*\\/openapi\\.json$"
126
+ "pattern": "^\\/api\\/(?:v[0-9]+|[a-z][a-z0-9-]*)\\/openapi\\.json$"
127
127
  },
128
128
  "tools": {
129
129
  "minItems": 1,
@@ -123,7 +123,7 @@
123
123
  },
124
124
  "openapi": {
125
125
  "type": "string",
126
- "pattern": "^\\/api\\/v[1-9][0-9]*\\/openapi\\.json$"
126
+ "pattern": "^\\/api\\/(?:v[0-9]+|[a-z][a-z0-9-]*)\\/openapi\\.json$"
127
127
  },
128
128
  "tools": {
129
129
  "minItems": 1,