@agentage/extension 0.16.0 → 0.18.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.
Files changed (147) hide show
  1. package/dist/api/download.d.ts +14 -0
  2. package/dist/api/download.js +10 -0
  3. package/dist/api/files-registry.d.ts +17 -0
  4. package/dist/api/files-registry.js +10 -0
  5. package/dist/api/files.d.ts +8 -0
  6. package/dist/api/files.js +82 -0
  7. package/dist/api/openapi-doc.js +21 -12
  8. package/dist/api/routes.d.ts +10 -1
  9. package/dist/api/routes.js +15 -2
  10. package/dist/auth/token-check.d.ts +1 -1
  11. package/dist/auth/verify-token.js +9 -9
  12. package/dist/context/test-context.d.ts +5 -1
  13. package/dist/context/test-context.js +2 -1
  14. package/dist/host/daemon/app-files.d.ts +13 -0
  15. package/dist/host/daemon/app-files.js +51 -0
  16. package/dist/host/daemon/app-header.d.ts +3 -0
  17. package/dist/host/daemon/app-header.js +12 -0
  18. package/dist/host/daemon/app-reload.d.ts +10 -0
  19. package/dist/host/daemon/app-reload.js +18 -0
  20. package/dist/host/daemon/child.d.ts +1 -0
  21. package/dist/host/daemon/child.js +7 -4
  22. package/dist/host/daemon/cli-user-watch.d.ts +8 -0
  23. package/dist/host/daemon/cli-user-watch.js +43 -0
  24. package/dist/host/daemon/cli-user.d.ts +2 -0
  25. package/dist/host/daemon/cli-user.js +42 -0
  26. package/dist/host/daemon/daemon.d.ts +1 -0
  27. package/dist/host/daemon/daemon.js +13 -1
  28. package/dist/host/daemon/health-routes.d.ts +2 -0
  29. package/dist/host/daemon/health-routes.js +29 -15
  30. package/dist/host/daemon/limits.d.ts +1 -0
  31. package/dist/host/daemon/limits.js +2 -0
  32. package/dist/host/daemon/routes.js +25 -7
  33. package/dist/host/daemon/seal.d.ts +6 -2
  34. package/dist/host/daemon/seal.js +9 -2
  35. package/dist/host/daemon/shell-events.d.ts +9 -0
  36. package/dist/host/daemon/shell-events.js +36 -0
  37. package/dist/host/daemon/shell-routes.d.ts +28 -0
  38. package/dist/host/daemon/shell-routes.js +63 -0
  39. package/dist/host/daemon/supervisor.d.ts +2 -0
  40. package/dist/host/daemon/supervisor.js +2 -1
  41. package/dist/host/data-lock.js +5 -5
  42. package/dist/host/host-env.js +14 -2
  43. package/dist/host/host-extension.js +4 -3
  44. package/dist/host/host-git-store.d.ts +10 -0
  45. package/dist/host/host-git-store.js +36 -0
  46. package/dist/host/host-migrations.d.ts +1 -1
  47. package/dist/host/host-migrations.js +2 -2
  48. package/dist/host/host-parts.d.ts +2 -2
  49. package/dist/host/host-parts.js +1 -1
  50. package/dist/host/host-url-store.d.ts +4 -2
  51. package/dist/host/host-url-store.js +18 -15
  52. package/dist/host/open-store.d.ts +6 -0
  53. package/dist/host/open-store.js +6 -0
  54. package/dist/index.d.ts +3 -1
  55. package/dist/index.js +3 -1
  56. package/dist/manifest/manifest.schema.d.ts +13 -0
  57. package/dist/manifest/manifest.schema.js +16 -2
  58. package/dist/manifest/parts.d.ts +7 -0
  59. package/dist/manifest/parts.js +5 -0
  60. package/dist/manifest/primitives.schema.js +3 -3
  61. package/dist/mcp/connector.d.ts +4 -0
  62. package/dist/mcp/connector.js +11 -0
  63. package/dist/mcp/mcp-app.d.ts +4 -1
  64. package/dist/mcp/mcp-app.js +28 -18
  65. package/dist/mcp/server.d.ts +6 -3
  66. package/dist/mcp/server.js +70 -18
  67. package/dist/mcp/tools.d.ts +40 -4
  68. package/dist/mcp/tools.js +34 -12
  69. package/dist/runtime/part-mounts.js +12 -6
  70. package/dist/runtime/run-part.js +22 -6
  71. package/dist/server/api-routes.d.ts +5 -2
  72. package/dist/server/api-routes.js +41 -14
  73. package/dist/server/app.d.ts +3 -0
  74. package/dist/server/app.js +11 -1
  75. package/dist/server/send-download.d.ts +3 -0
  76. package/dist/server/send-download.js +29 -0
  77. package/dist/shell/dist/index.html +46 -0
  78. package/dist/shell/dist/shell.css +2 -0
  79. package/dist/shell/dist/shell.js +68 -0
  80. package/dist/shell/dist/vendor/app.js +1 -0
  81. package/dist/shell/dist/vendor/chunk-AOJ3DQEL.js +14 -0
  82. package/dist/shell/dist/vendor/chunk-LW5HXGAJ.js +14 -0
  83. package/dist/shell/dist/vendor/chunk-PQJPUKWH.js +14 -0
  84. package/dist/shell/dist/vendor/chunk-SQE76S5B.js +1 -0
  85. package/dist/shell/dist/vendor/jsx-runtime.js +1 -0
  86. package/dist/shell/dist/vendor/react-dom-client.js +33 -0
  87. package/dist/shell/dist/vendor/react-dom.js +1 -0
  88. package/dist/shell/dist/vendor/react.js +1 -0
  89. package/dist/shell/package.json +5 -0
  90. package/dist/store/git-env.d.ts +11 -0
  91. package/dist/store/git-env.js +44 -0
  92. package/dist/store/store-url.d.ts +1 -1
  93. package/dist/store/store-url.js +2 -0
  94. package/dist/store/store.types.d.ts +3 -0
  95. package/dist/store/store.types.js +1 -1
  96. package/dist/testing/test-server.js +11 -12
  97. package/dist/tool/app-build.d.ts +13 -0
  98. package/dist/tool/app-build.js +126 -0
  99. package/dist/tool/app-load.d.ts +4 -0
  100. package/dist/tool/app-load.js +34 -0
  101. package/dist/tool/build.js +5 -2
  102. package/dist/tool/check.js +4 -2
  103. package/dist/tool/container-recipe.d.ts +9 -2
  104. package/dist/tool/container-recipe.js +14 -9
  105. package/dist/tool/container-stage.js +1 -1
  106. package/dist/tool/index.d.ts +1 -0
  107. package/dist/tool/index.js +1 -0
  108. package/dist/tool/main.d.ts +2 -0
  109. package/dist/tool/main.js +8 -1
  110. package/dist/tool/recipe.d.ts +1 -1
  111. package/dist/tool/recipe.js +16 -6
  112. package/dist/tool/record-extras.js +4 -3
  113. package/dist/tool/rules/folders.js +1 -1
  114. package/dist/tool/rules/sealing.js +4 -0
  115. package/dist/tool/rules/store.js +0 -3
  116. package/dist/tool/rules/surface.js +4 -1
  117. package/dist/tool/stage.js +2 -2
  118. package/dist/tool/up/compose.d.ts +4 -0
  119. package/dist/tool/up/compose.js +41 -3
  120. package/dist/tool/up/gateway.js +16 -3
  121. package/dist/tool/up/secrets.d.ts +1 -0
  122. package/dist/tool/up/secrets.js +13 -1
  123. package/dist/tool/up/up.js +8 -5
  124. package/dist/vendor/app/api.d.ts +9 -0
  125. package/dist/vendor/app/api.js +63 -0
  126. package/dist/vendor/app/app.types.d.ts +65 -0
  127. package/dist/vendor/app/app.types.js +1 -0
  128. package/dist/vendor/app/boundary.d.ts +15 -0
  129. package/dist/vendor/app/boundary.js +17 -0
  130. package/dist/vendor/app/context.d.ts +5 -0
  131. package/dist/vendor/app/context.js +22 -0
  132. package/dist/vendor/app/index.d.ts +7 -0
  133. package/dist/vendor/app/index.js +6 -0
  134. package/dist/vendor/app/region.d.ts +6 -0
  135. package/dist/vendor/app/region.js +14 -0
  136. package/dist/vendor/app/split.d.ts +20 -0
  137. package/dist/vendor/app/split.js +38 -0
  138. package/dist/vendor/app/state-store.d.ts +3 -0
  139. package/dist/vendor/app/state-store.js +35 -0
  140. package/dist/vendor/app/test-host.d.ts +29 -0
  141. package/dist/vendor/app/test-host.js +66 -0
  142. package/dist/vendor/app/theme.css +32 -0
  143. package/package.json +35 -2
  144. package/schemas/extension-discovery.schema.json +1 -1
  145. package/schemas/extension-package.schema.json +28 -1
  146. package/schemas/extension-record.schema.json +1 -1
  147. package/schemas/health.schema.json +1 -1
@@ -0,0 +1,36 @@
1
+ import { constants } from 'node:fs';
2
+ import { access, mkdir, mkdtemp } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import {} from '../log/log.js';
6
+ import {} from '../manifest/manifest.schema.js';
7
+ import { hasStore } from '../manifest/parts.js';
8
+ import { gitAccessOf } from '../store/git-env.js';
9
+ import { readStoreUrl } from '../store/store-url.js';
10
+ import { lockOf, lockWithin } from './host-store.js';
11
+ import {} from './host-url-store.js';
12
+ const NO_QUERY = async () => {
13
+ throw new Error('a git store has no query: use ctx.store.gitRoot');
14
+ };
15
+ const writable = (root) => async () => {
16
+ await access(root, constants.W_OK);
17
+ return 'ok';
18
+ };
19
+ const rootOf = async (dataDir, log) => {
20
+ if (dataDir)
21
+ return dataDir;
22
+ log.warn('no data folder: the git store is in a temp folder and lost on exit');
23
+ return mkdtemp(join(tmpdir(), 'agentage-git-'));
24
+ };
25
+ // G5: a git store is a folder (data/{id}) under the data lock: this process is its single writer.
26
+ export const openGitStore = async (pkg, at, log) => {
27
+ if (!hasStore(pkg, 'git'))
28
+ return undefined;
29
+ const url = at.file ? await readStoreUrl(at.file, 'git') : undefined;
30
+ const gitRoot = await rootOf(at.dataDir, log);
31
+ await mkdir(gitRoot, { recursive: true });
32
+ const close = await lockWithin(gitRoot, at.openMs, lockOf({ dataDir: gitRoot, runDir: at.runDir }));
33
+ log.info('git store opened', { remote: url ? 'set' : 'none' });
34
+ const git = gitAccessOf(gitRoot, url);
35
+ return { kind: 'git', query: NO_QUERY, gitRoot, git, close, probe: writable(gitRoot) };
36
+ };
@@ -4,5 +4,5 @@ import { type Env } from '../runtime/build-info.js';
4
4
  import { type MigrateResult } from '../store/migrations.js';
5
5
  import { type Store } from '../store/store.types.js';
6
6
  export declare const pendingMigrations: (store: Store, dir: string) => Promise<string[]>;
7
- export declare const migrationsCheck: (store: Store, dir: string, log: Log) => HealthCheck;
7
+ export declare const migrationsCheck: (store: Store, dir: string, log: Log, pendingIs?: "unavailable" | "degraded") => HealthCheck;
8
8
  export declare const migrateHost: (env: Env, write?: (line: string) => undefined) => Promise<MigrateResult | undefined>;
@@ -25,7 +25,7 @@ export const pendingMigrations = async (store, dir) => {
25
25
  }
26
26
  };
27
27
  // checks["store:migrations"]: the serving host never migrates; ok once, it stays ok (one image, one set).
28
- export const migrationsCheck = (store, dir, log) => {
28
+ export const migrationsCheck = (store, dir, log, pendingIs = 'unavailable') => {
29
29
  let applied = false;
30
30
  let warned = false;
31
31
  return async () => {
@@ -36,7 +36,7 @@ export const migrationsCheck = (store, dir, log) => {
36
36
  if (!applied && !warned)
37
37
  log.warn('migrations not applied: run the migrate job', { pending: pending.join(', ') });
38
38
  warned ||= !applied;
39
- return applied ? 'ok' : 'unavailable';
39
+ return applied ? 'ok' : pendingIs;
40
40
  };
41
41
  };
42
42
  // `main.js migrate`: the one container as a one-shot job; the URL is never printed.
@@ -4,15 +4,15 @@ import { type Log } from '../log/log.js';
4
4
  import { type ExtensionPackage } from '../manifest/manifest.schema.js';
5
5
  import { type HostPartKind } from '../manifest/parts.js';
6
6
  import { type PartAppBase } from '../server/app.js';
7
- import { type PgliteStore } from '../store/pglite-store.js';
8
7
  import { type HostExtras, type HostOptions } from './host-extension.js';
8
+ import { type HostStore } from './host-url-store.js';
9
9
  export interface Hosting {
10
10
  dir: string;
11
11
  pkg: ExtensionPackage;
12
12
  log: Log;
13
13
  opts: HostOptions;
14
14
  extras: HostExtras;
15
- store: PgliteStore | undefined;
15
+ store: HostStore | undefined;
16
16
  onExit: () => void;
17
17
  build: BuildInfo;
18
18
  }
@@ -11,9 +11,9 @@ import { hostParts } from '../manifest/parts.js';
11
11
  import { mcpPathOf } from '../mcp/mcp-app.js';
12
12
  import { MOUNTS } from '../runtime/part-mounts.js';
13
13
  import { createPartApp } from '../server/app.js';
14
- import {} from '../store/pglite-store.js';
15
14
  import {} from '../health/health.js';
16
15
  import {} from './host-extension.js';
16
+ import {} from './host-url-store.js';
17
17
  import { partChecks } from './part-checks.js';
18
18
  const secretsOf = ({ pkg, opts, extras }, part) => extras.secretsDir
19
19
  ? readSecrets(pkg, part, extras.secretsDir)
@@ -6,16 +6,18 @@ import { type UrlStoreKind } from '../store/store-url.js';
6
6
  import { type Store } from '../store/store.types.js';
7
7
  export interface HostStore extends Store {
8
8
  close(): Promise<void>;
9
- readonly kind?: UrlStoreKind;
9
+ readonly kind?: UrlStoreKind | 'git';
10
+ readonly probe?: HealthCheck;
10
11
  readonly checks?: Record<string, HealthCheck>;
11
12
  }
12
13
  export interface UrlStoreAt {
13
14
  dir: string;
14
15
  file?: string;
15
16
  openMs: number;
17
+ partImage?: boolean;
16
18
  }
17
19
  type Pool = (url: string, log: Log) => PoolStore;
18
- export declare const postgresStore: (url: string, dir: string, log: Log, pool?: Pool) => HostStore;
20
+ export declare const postgresStore: (url: string, at: Pick<UrlStoreAt, "dir" | "partImage">, log: Log, pool?: Pool) => Promise<HostStore>;
19
21
  export declare const openUrlStore: (pkg: ExtensionPackage, at: UrlStoreAt, log: Log) => Promise<HostStore | undefined>;
20
22
  export declare const hostStoreChecks: (store: HostStore | undefined) => Record<string, HealthCheck>;
21
23
  export {};
@@ -1,33 +1,36 @@
1
+ import { join } from 'node:path';
1
2
  import {} from '../health/health.js';
2
3
  import { messageOf } from '../log/log.js';
3
4
  import {} from '../manifest/manifest.schema.js';
4
5
  import { storeOf } from '../manifest/parts.js';
5
6
  import { createClickhouseStore } from '../store/clickhouse-store.js';
7
+ import { sqlFiles } from '../store/migrations.js';
6
8
  import { createStore, storeCheck } from '../store/store.js';
7
9
  import { isUrlStoreKind, readStoreUrl, STORE_URL_FILE_ENV, } from '../store/store-url.js';
8
10
  import {} from '../store/store.types.js';
9
11
  import { migrationsCheck } from './host-migrations.js';
10
12
  const poolOf = (url, log) => createStore({ AGENTAGE_STORE_URL: url }, log);
11
13
  // The serving host never migrates (the migrate job does): /health is 503 until the ledger is current.
12
- export const postgresStore = (url, dir, log, pool = poolOf) => {
14
+ export const postgresStore = async (url, at, log, pool = poolOf) => {
13
15
  const parts = pool(url, log);
14
- return {
15
- kind: 'postgres',
16
- query: parts.query,
17
- close: () => parts.end(),
18
- checks: { 'store:migrations': migrationsCheck(parts, dir, log) },
19
- };
16
+ const store = { kind: 'postgres', query: parts.query, close: () => parts.end() };
17
+ if (at.partImage && (await sqlFiles(join(at.dir, 'migrations'))).length === 0)
18
+ return store;
19
+ const pending = at.partImage ? 'degraded' : 'unavailable';
20
+ return { ...store, checks: { 'store:migrations': migrationsCheck(parts, at.dir, log, pending) } };
20
21
  };
21
22
  const within = (work, ms) => Promise.race([work, new Promise((ok) => setTimeout(() => ok('late'), ms).unref())]);
22
- // The start waits up to openMs for the store; one that is down still starts, /health says 503.
23
- const firstUse = async (store, kind, openMs, log) => {
23
+ // The start waits up to openMs for the store (a part image: not at all); /health says 503 until it opens.
24
+ const firstUse = async (store, kind, at, log) => {
24
25
  const opened = store.query('select 1').then(() => 'ok', (err) => err);
25
- const result = await within(opened, openMs);
26
+ const result = at.partImage ? 'late' : await within(opened, at.openMs);
26
27
  if (result === 'ok')
27
28
  return log.info('store opened', { kind, from: STORE_URL_FILE_ENV });
28
- const reason = result === 'late' ? `not in ${openMs} ms` : messageOf(result);
29
- log.warn('the store did not open: /health says unavailable until it does', { kind, reason });
29
+ if (at.partImage)
30
+ return void opened.then((r) => r !== 'ok' && warnClosed(log, kind, messageOf(r)));
31
+ warnClosed(log, kind, result === 'late' ? `not in ${at.openMs} ms` : messageOf(result));
30
32
  };
33
+ const warnClosed = (log, kind, reason) => log.warn('the store did not open: /health says unavailable until it does', { kind, reason });
31
34
  const kindOf = (pkg, log) => {
32
35
  const kind = storeOf(pkg);
33
36
  if (isUrlStoreKind(kind))
@@ -43,8 +46,8 @@ export const openUrlStore = async (pkg, at, log) => {
43
46
  if (!kind)
44
47
  return undefined;
45
48
  const url = await readStoreUrl(at.file, kind);
46
- const store = kind === 'postgres' ? postgresStore(url, at.dir, log) : createClickhouseStore(url, log);
47
- await firstUse(store, kind, at.openMs, log);
49
+ const store = kind === 'postgres' ? await postgresStore(url, at, log) : createClickhouseStore(url, log);
50
+ await firstUse(store, kind, at, log);
48
51
  return store;
49
52
  };
50
53
  // Calls that overlap share one run: /health asks checks.store and store:<kind> in one probe.
@@ -56,7 +59,7 @@ const shared = (check) => {
56
59
  export const hostStoreChecks = (store) => {
57
60
  if (!store)
58
61
  return {};
59
- const check = shared(storeCheck(store));
62
+ const check = shared(store.probe ?? storeCheck(store));
60
63
  const named = store.kind ? { [`store:${store.kind}`]: check } : {};
61
64
  return { store: check, ...named, ...store.checks };
62
65
  };
@@ -0,0 +1,6 @@
1
+ import { type Log } from '../log/log.js';
2
+ import { type ExtensionPackage } from '../manifest/manifest.schema.js';
3
+ import { type GitStoreAt } from './host-git-store.js';
4
+ import { type HostStore, type UrlStoreAt } from './host-url-store.js';
5
+ export type OpenStoreAt = GitStoreAt & UrlStoreAt;
6
+ export declare const openStore: (pkg: ExtensionPackage, at: OpenStoreAt, log: Log) => Promise<HostStore | undefined>;
@@ -0,0 +1,6 @@
1
+ import {} from '../log/log.js';
2
+ import {} from '../manifest/manifest.schema.js';
3
+ import { openGitStore } from './host-git-store.js';
4
+ import { openUrlStore } from './host-url-store.js';
5
+ // The one opener of the daemon, the one container and the part image: git, else a store URL file.
6
+ export const openStore = async (pkg, at, log) => (await openGitStore(pkg, at, log)) ?? (await openUrlStore(pkg, at, log));
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { type ApiContext, type ParamsOf, type RouteHandler, type RouteMethod, type RouteRegistrar, type RouteRequest, type RouteSpec, } from './api/routes.js';
2
+ export { download, type DownloadAnswer, type DownloadBody, type DownloadOptions, } from './api/download.js';
2
3
  export { pageOf, PageQuerySchema, type Pagination } from './api/page.js';
3
4
  export { type Access, type Caller } from './auth/token-check.js';
4
5
  export { type ArgValue } from './command/args.js';
@@ -17,12 +18,13 @@ export { type HealthBody, type HealthStatus } from './health/health.schema.js';
17
18
  export { type Log, type LogFields } from './log/log.js';
18
19
  export { createEventsClient, EventSchema, parseLine, type Event, type EventsClientOptions, type PostEvent, } from './vendor/logs/index.js';
19
20
  export { type Span, type SpanRecord } from './log/span.js';
20
- export { type McpContext, type ToolHandler, type ToolRegistrar, type ToolSpec, } from './mcp/tools.js';
21
+ export { toolResult, type McpContext, type TextContent, type ToolHandler, type ToolResult, type ToolResultOptions, type ToolRegistrar, type ToolSpec, } from './mcp/tools.js';
21
22
  export { versionPage, type PagesContext, type PagesEntry, type PagesSite } from './pages/pages.js';
22
23
  export { siteFromDir, type SiteFromDirOptions } from './pages/site-from-dir.js';
23
24
  export { type ApiCreate, type ApiHandler, type ApiPart } from './server/part.types.js';
24
25
  export { clickhouseOf, createClickhouseStore, isClickhouseOutage, type ClickhouseOptions, type ClickhouseStore, } from './store/clickhouse-store.js';
25
26
  export { type QueryResult, type Row, type Store } from './store/store.types.js';
27
+ export { type GitAccess } from './store/git-env.js';
26
28
  export { startTestMcp, startTestServer, type TestMcp, type TestMcpOptions, type TestServer, type TestServerOptions, } from './testing/test-server.js';
27
29
  export { type JobOptions } from './worker/job-options.js';
28
30
  export { type JobRun, type RunStatus } from './worker/runs.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export {} from './api/routes.js';
2
+ export { download, } from './api/download.js';
2
3
  export { pageOf, PageQuerySchema } from './api/page.js';
3
4
  export {} from './auth/token-check.js';
4
5
  export {} from './command/args.js';
@@ -18,12 +19,13 @@ export {} from './health/health.schema.js';
18
19
  export {} from './log/log.js';
19
20
  export { createEventsClient, EventSchema, parseLine, } from './vendor/logs/index.js';
20
21
  export {} from './log/span.js';
21
- export {} from './mcp/tools.js';
22
+ export { toolResult, } from './mcp/tools.js';
22
23
  export { versionPage } from './pages/pages.js';
23
24
  export { siteFromDir } from './pages/site-from-dir.js';
24
25
  export {} from './server/part.types.js';
25
26
  export { clickhouseOf, createClickhouseStore, isClickhouseOutage, } from './store/clickhouse-store.js';
26
27
  export {} from './store/store.types.js';
28
+ export {} from './store/git-env.js';
27
29
  export { startTestMcp, startTestServer, } from './testing/test-server.js';
28
30
  export {} from './worker/job-options.js';
29
31
  export {} from './worker/runs.js';
@@ -9,6 +9,7 @@ declare const PartsSchema: z.ZodObject<{
9
9
  ui: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
10
10
  entry: z.ZodOptional<z.ZodString>;
11
11
  }, z.core.$strict>]>>;
12
+ app: z.ZodOptional<z.ZodBoolean>;
12
13
  api: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
13
14
  entry: z.ZodOptional<z.ZodString>;
14
15
  }, z.core.$strict>]>>;
@@ -50,6 +51,11 @@ declare const CommandSchema: z.ZodObject<{
50
51
  description: z.ZodOptional<z.ZodString>;
51
52
  }, z.core.$strict>>>;
52
53
  }, z.core.$strict>;
54
+ declare const AppMetaSchema: z.ZodObject<{
55
+ title: z.ZodString;
56
+ icon: z.ZodOptional<z.ZodString>;
57
+ order: z.ZodOptional<z.ZodInt>;
58
+ }, z.core.$strict>;
53
59
  export declare const PackageSchema: z.ZodObject<{
54
60
  name: z.ZodString;
55
61
  version: z.ZodString;
@@ -65,6 +71,7 @@ export declare const PackageSchema: z.ZodObject<{
65
71
  ui: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
66
72
  entry: z.ZodOptional<z.ZodString>;
67
73
  }, z.core.$strict>]>>;
74
+ app: z.ZodOptional<z.ZodBoolean>;
68
75
  api: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
69
76
  entry: z.ZodOptional<z.ZodString>;
70
77
  }, z.core.$strict>]>>;
@@ -91,6 +98,11 @@ export declare const PackageSchema: z.ZodObject<{
91
98
  }>;
92
99
  }, z.core.$strict>]>>;
93
100
  }, z.core.$strict>;
101
+ app: z.ZodOptional<z.ZodObject<{
102
+ title: z.ZodString;
103
+ icon: z.ZodOptional<z.ZodString>;
104
+ order: z.ZodOptional<z.ZodInt>;
105
+ }, z.core.$strict>>;
94
106
  commands: z.ZodOptional<z.ZodArray<z.ZodObject<{
95
107
  name: z.ZodString;
96
108
  summary: z.ZodString;
@@ -128,6 +140,7 @@ export declare const PackageSchema: z.ZodObject<{
128
140
  }, z.core.$strict>]>>>;
129
141
  }, z.core.$strict>;
130
142
  }, z.core.$loose>;
143
+ export type AppMeta = z.infer<typeof AppMetaSchema>;
131
144
  export type CodePart = z.infer<typeof CodePartSchema>;
132
145
  export type CommandSpec = z.infer<typeof CommandSchema>;
133
146
  export type Parts = z.infer<typeof PartsSchema>;
@@ -7,11 +7,12 @@ const CodePartSchema = z.union([
7
7
  const StorePartSchema = z.union([StoreKindSchema, z.strictObject({ kind: StoreKindSchema })], {
8
8
  error: `one of ${StoreKindSchema.options.join(', ')}`,
9
9
  });
10
- const ROUTED = ['pages', 'ui', 'api', 'mcp'];
10
+ const ROUTED = ['pages', 'ui', 'app', 'api', 'mcp'];
11
11
  const PartsSchema = z
12
12
  .strictObject({
13
13
  pages: CodePartSchema.optional(),
14
14
  ui: CodePartSchema.optional(),
15
+ app: z.boolean().optional(),
15
16
  api: CodePartSchema.optional(),
16
17
  mcp: CodePartSchema.optional(),
17
18
  worker: CodePartSchema.optional(),
@@ -19,7 +20,7 @@ const PartsSchema = z
19
20
  store: StorePartSchema.optional(),
20
21
  })
21
22
  .refine((parts) => ROUTED.some((kind) => isOn(parts[kind])), {
22
- message: 'at least one routed part (pages, ui, api or mcp)',
23
+ message: 'at least one routed part (pages, ui, app, api or mcp)',
23
24
  });
24
25
  const ArgTypeSchema = z.enum(['string', 'integer', 'number', 'boolean']);
25
26
  const CommandSchema = z.strictObject({
@@ -52,9 +53,20 @@ const SecretSchema = z.union([
52
53
  SecretNameSchema,
53
54
  z.strictObject({ name: SecretNameSchema, parts: z.array(SecretPartSchema).min(1) }),
54
55
  ]);
56
+ // The nav row of the app part; icon is a lucide icon name.
57
+ const AppMetaSchema = z.strictObject({
58
+ title: z.string().min(1).max(40),
59
+ icon: z
60
+ .string()
61
+ .max(64)
62
+ .regex(/^[a-z][a-z0-9-]*$/)
63
+ .optional(),
64
+ order: z.int().min(0).max(1000).optional(),
65
+ });
55
66
  const AgentageBaseSchema = z.strictObject({
56
67
  id: ExtensionIdSchema,
57
68
  parts: PartsSchema,
69
+ app: AppMetaSchema.optional(),
58
70
  commands: z.array(CommandSchema).min(1).optional(),
59
71
  settings: z.record(SettingKeySchema, SettingSchema).optional(),
60
72
  secrets: z.array(SecretSchema).optional(),
@@ -98,6 +110,8 @@ function crossFieldRules(manifest, ctx) {
98
110
  const ids = (manifest.secrets ?? []).map((s) => camelName(typeof s === 'string' ? s : s.name));
99
111
  if (new Set(ids).size !== ids.length)
100
112
  issue('secret names must be unique', ['secrets']);
113
+ if (isOn(manifest.parts.app) !== Boolean(manifest.app))
114
+ issue('the app part and agentage.app come together', manifest.app ? ['app'] : ['parts', 'app']);
101
115
  if (manifest.settings?.['mcp.listing'] && !isOn(manifest.parts.mcp)) {
102
116
  issue('mcp.listing needs the mcp part', ['settings', 'mcp.listing']);
103
117
  }
@@ -21,4 +21,11 @@ export declare const unmountedIn: (pkg: ExtensionPackage | undefined, part: Imag
21
21
  export declare const storeOf: (pkg: ExtensionPackage) => StoreKind | undefined;
22
22
  export declare const hasStore: (pkg: ExtensionPackage, kind: StoreKind) => boolean;
23
23
  export declare const migratesStore: (pkg: ExtensionPackage) => boolean;
24
+ export declare const APP_DIR = "dist/app";
25
+ export declare const APP_META_FILE = "app.json";
26
+ export declare const appOf: (pkg: ExtensionPackage) => {
27
+ title: string;
28
+ icon?: string | undefined;
29
+ order?: number | undefined;
30
+ } | undefined;
24
31
  export {};
@@ -40,3 +40,8 @@ export const migratesStore = (pkg) => {
40
40
  const kind = storeOf(pkg);
41
41
  return kind !== undefined && STORE_KINDS[kind].migrations;
42
42
  };
43
+ // dist/app/app.json names the hashed files of the last app build; the host reads it.
44
+ export const APP_DIR = 'dist/app';
45
+ export const APP_META_FILE = 'app.json';
46
+ // The app part: a browser bundle the host serves from dist/app, never an image or a child.
47
+ export const appOf = (pkg) => pkg.agentage.parts.app ? pkg.agentage.app : undefined;
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- // Platform names and cli verbs, plus Windows device names: an id is a folder name on machines.
3
- const RESERVED_IDS = 'auth|www|api|sync|mail|mcp|ui|git|setup|status|update|extension|add|remove|help|con|prn|aux|nul|com[0-9]|lpt[0-9]';
2
+ // Platform names, the daemon's first path segments and cli verbs, plus Windows device names: an id is a folder name on machines.
3
+ const RESERVED_IDS = 'auth|www|api|sync|mail|mcp|ui|app|shell|host|health|git|setup|status|update|extension|add|remove|help|con|prn|aux|nul|com[0-9]|lpt[0-9]';
4
4
  export const ExtensionIdSchema = z
5
5
  .string()
6
6
  .max(32)
@@ -51,7 +51,7 @@ export const STORE_KINDS = {
51
51
  clickhouse: { migrations: false },
52
52
  };
53
53
  // STORE_KINDS[kind].migrations: the api image carries a migrate job. SERVED_KINDS moves with the estate.
54
- export const SERVED_KINDS = ['postgres', 'signoz', 'clickhouse'];
54
+ export const SERVED_KINDS = ['postgres', 'signoz', 'git', 'clickhouse'];
55
55
  export const StoreKindSchema = z.enum(Object.keys(STORE_KINDS));
56
56
  export const FULL_SHA = /^[0-9a-f]{40}$/;
57
57
  export const CommitSchema = z.string().regex(FULL_SHA, { message: 'full 40-hex git sha' });
@@ -0,0 +1,4 @@
1
+ import { type Express } from 'express';
2
+ import { type McpAppOptions } from './mcp-app.js';
3
+ import { type ToolEntry } from './tools.js';
4
+ export declare const mountWithConnector: (app: Express, options: McpAppOptions, connectors: ToolEntry[]) => void;
@@ -0,0 +1,11 @@
1
+ import {} from 'express';
2
+ import { mountMcp } from './mcp-app.js';
3
+ import {} from './tools.js';
4
+ // The connector profile beside the mcp tools: /mcp{rest} becomes /connector{rest}, tools by their own name.
5
+ export const mountWithConnector = (app, options, connectors) => {
6
+ mountMcp(app, options);
7
+ if (connectors.length === 0)
8
+ return;
9
+ const paths = (options.paths ?? ['/mcp']).map((path) => path.replace(/^\/mcp/, '/connector'));
10
+ mountMcp(app, { ...options, tools: connectors, paths, bare: true, instructions: undefined });
11
+ };
@@ -1,11 +1,14 @@
1
1
  import { type Express } from 'express';
2
2
  import { type PartAppBase } from '../server/app.js';
3
- import { type ToolEntry } from './tools.js';
3
+ import { type Instructions, type ToolEntry } from './tools.js';
4
4
  export interface McpAppOptions extends PartAppBase {
5
5
  tools: ToolEntry[];
6
6
  listing: 'open' | 'token';
7
+ instructions?: Instructions;
8
+ bare?: boolean;
7
9
  paths?: string[];
8
10
  }
11
+ export declare const MCP_PATH = "/mcp";
9
12
  export declare const mcpPathOf: (id: string) => string;
10
13
  export declare const mountMcp: (app: Express, options: McpAppOptions) => void;
11
14
  export declare const createMcpApp: (options: McpAppOptions) => Express;
@@ -7,10 +7,10 @@ import { requestScope } from '../agcid/current.js';
7
7
  import { setCaller, strongest } from '../auth/token-check.js';
8
8
  import { fail } from '../envelope/envelope.js';
9
9
  import { declaredType, printable } from '../log/who.js';
10
- import { BODY_LIMIT, createPartApp, PUBLIC_CORS } from '../server/app.js';
11
- import { serverFactory } from './server.js';
12
- import { prefixed } from './tools.js';
13
- const MCP_PATH = '/mcp';
10
+ import { BODY_LIMIT, createPartApp, PUBLIC_CORS, resourceDocAt, } from '../server/app.js';
11
+ import { authInfoOf, serverFactory } from './server.js';
12
+ import { nameOf } from './tools.js';
13
+ export const MCP_PATH = '/mcp';
14
14
  // The endpoint of an extension on a host that runs many: the daemon routes it to its child.
15
15
  export const mcpPathOf = (id) => `${MCP_PATH}/${id}`;
16
16
  const MCP_HEADERS = ['Mcp-Protocol-Version', 'Mcp-Method', 'Mcp-Name', 'Accept'];
@@ -34,30 +34,34 @@ const callAccess = (options, body) => messagesOf(body)
34
34
  .filter((message) => message?.method === 'tools/call')
35
35
  .map((message) => {
36
36
  const id = options.pkg.agentage.id;
37
- const entry = options.tools.find((t) => prefixed(id, t.name) === message?.params?.name);
37
+ const entry = options.tools.find((t) => nameOf(id, t.name, options.bare) === message?.params?.name);
38
38
  return entry?.spec.scope ?? 'read';
39
39
  });
40
+ const OPENING = new Set(['initialize', 'server/discover']);
41
+ const isOpening = (body) => messagesOf(body).some((message) => OPENING.has(String(message?.method)));
42
+ // Instructions made per caller: the opening message reads a bearer when one is sent.
43
+ const openingAccess = (options, body) => typeof options.instructions === 'function' && isOpening(body) ? ['optional'] : [];
40
44
  // Tokens off: calls stay anonymous and a closed listing refuses every tools/list (nothing can verify).
41
- const guard = async (options, req, body) => {
45
+ const guard = async (options, req, body, at) => {
42
46
  const listing = options.listing === 'token' && isListing(body) ? ['read'] : [];
43
- const needed = [...listing, ...callAccess(options, body)];
47
+ const needed = [...listing, ...callAccess(options, body), ...openingAccess(options, body)];
44
48
  if (!options.tokenCheck) {
45
49
  if (listing.length > 0)
46
50
  throw fail('UNAUTHORIZED', 'tools/list needs a token');
47
- return false;
51
+ return null;
48
52
  }
49
53
  if (needed.length === 0)
50
- return false;
51
- const caller = await options.tokenCheck(req.get('authorization'), strongest(needed));
54
+ return null;
55
+ const caller = await options.tokenCheck(req.get('authorization'), strongest(needed), at);
52
56
  setCaller(req, caller);
53
- return caller !== null;
57
+ return caller;
54
58
  };
55
59
  // A tools/call leaves its mcp row and no http row (Q1); initialize names the client (Q14).
56
60
  const markRow = (options, req, res, body) => {
57
61
  const messages = messagesOf(body);
58
62
  const scope = requestScope.getStore();
59
63
  const id = options.pkg.agentage.id;
60
- const known = (m) => options.tools.some((t) => prefixed(id, t.name) === m?.params?.name);
64
+ const known = (m) => options.tools.some((t) => nameOf(id, t.name, options.bare) === m?.params?.name);
61
65
  // An unknown tool never reaches a handler, so it keeps its http row.
62
66
  if (messages.some((m) => m?.method === 'tools/call' && known(m))) {
63
67
  res.locals['toolCall'] = true;
@@ -90,15 +94,17 @@ const send = async (response, res, auth) => {
90
94
  return void res.end();
91
95
  await pipeline(Readable.fromWeb(response.body), res);
92
96
  };
93
- const handle = (handler, options) => async (req, res) => {
97
+ const handle = (handler, options, at) => async (req, res) => {
94
98
  const body = Buffer.isBuffer(req.body) ? req.body : Buffer.alloc(0);
95
99
  const message = parsed(body);
96
100
  // The SDK reads a body again when given none (a BOM, say): it must only run what guard read.
97
101
  if (message === undefined)
98
102
  return void res.status(400).json(PARSE_ERROR);
99
- const auth = await guard(options, req, message);
103
+ const caller = await guard(options, req, message, at);
100
104
  markRow(options, req, res, message);
101
- await send(await handler.fetch(webRequest(req, body), { parsedBody: message }), res, auth);
105
+ const authInfo = authInfoOf(caller, isOpening(message));
106
+ const answer = await handler.fetch(webRequest(req, body), { parsedBody: message, authInfo });
107
+ await send(answer, res, caller !== null);
102
108
  };
103
109
  const methodNotAllowed = (_req, res) => {
104
110
  res.setHeader('Allow', 'POST');
@@ -108,16 +114,20 @@ const methodNotAllowed = (_req, res) => {
108
114
  };
109
115
  // Stateless Streamable HTTP on SDK v2: POST only, GET and DELETE (sessions) answer 405.
110
116
  export const mountMcp = (app, options) => {
111
- const identity = { id: options.pkg.agentage.id, version: options.pkg.version };
112
- const handler = createMcpHandler(serverFactory(identity, options.tools, options.log), {
117
+ const { pkg, bare, resource } = options;
118
+ const identity = { id: pkg.agentage.id, version: pkg.version, bare };
119
+ const factory = serverFactory(identity, options.tools, options.log, options.instructions);
120
+ const handler = createMcpHandler(factory, {
113
121
  legacy: 'stateless',
114
122
  onerror: (err) => options.log.warn('mcp request refused', { reason: err.message }),
115
123
  });
116
124
  const raw = express.raw({ type: () => true, limit: BODY_LIMIT });
117
125
  for (const path of options.paths ?? [MCP_PATH]) {
118
126
  app.use(path, cors(MCP_CORS));
119
- app.post(path, raw, handle(handler, options));
127
+ app.post(path, raw, handle(handler, options, path));
120
128
  app.all(path, methodNotAllowed);
129
+ if (resource)
130
+ resourceDocAt(app, path, resource);
121
131
  }
122
132
  };
123
133
  export const createMcpApp = (options) => createPartApp({ ...options, part: 'mcp', mount: (app) => mountMcp(app, options) });
@@ -1,8 +1,11 @@
1
- import { McpServer } from '@modelcontextprotocol/server';
1
+ import { McpServer, type AuthInfo, type McpRequestContext } from '@modelcontextprotocol/server';
2
+ import { type Caller } from '../auth/token-check.js';
2
3
  import { type Log } from '../log/log.js';
3
- import { type ToolEntry } from './tools.js';
4
+ import { type Instructions, type ToolEntry } from './tools.js';
4
5
  export interface ServerIdentity {
5
6
  id: string;
6
7
  version: string;
8
+ bare?: boolean;
7
9
  }
8
- export declare const serverFactory: (identity: ServerIdentity, tools: ToolEntry[], log: Log) => () => McpServer;
10
+ export declare const authInfoOf: (caller: Caller | null, opening: boolean) => AuthInfo;
11
+ export declare const serverFactory: (identity: ServerIdentity, tools: ToolEntry[], log: Log, instructions?: Instructions) => (ctx?: McpRequestContext) => Promise<McpServer>;